Skip to content

Commit 6fb34f2

Browse files
Add BIP85-DRNG and other key derivations
1 parent 7e3284d commit 6fb34f2

File tree

1 file changed

+57
-3
lines changed

1 file changed

+57
-3
lines changed

bip-0085.mediawiki

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ As HD keychains are essentially derived from initial entropy, this proposal prov
2525

2626
==Definitions==
2727

28+
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.
29+
2830
The terminology related to keychains used in the wild varies widely, for example `seed` has various different meanings. In this document we define the terms
2931

3032
# '''BIP32 root key''' is the root extended private key that is represented as the top root of the keychain in BIP32.
@@ -69,19 +71,41 @@ OUTPUT
6971
* DERIVED KEY=503776919131758bb7de7beb6c0ae24894f4ec042c26032890c29359216e21ba
7072
* DERIVED ENTROPY=70c6e3e8ebee8dc4c0dbba66076819bb8c09672527c4277ca8729532ad711872218f826919f6b67218adde99018a6df9095ab2b58d803b5b93ec9802085a690e
7173
74+
==BIP85-DRNG==
75+
76+
BIP85-DRNG-SHAKE256 is a deterministic random number generator for cryptographic functions that require deterministic outputs, but where the input to that function requires more than the 64 bytes provided by BIP85's HMAC output. BIP85-DRNG-SHAKE256 uses BIP85 to seed a SHAKE256 stream (from the SHA-3 standard). The input must be exactly 64 bytes long (from the BIP85 HMAC output).
77+
78+
RSA key generation is an example of a function that requires orders of magnitude more than 64 bytes of random input. Further, it is not possible to precalculate the amount of random input required until the function has completed.
79+
80+
drng_reader = BIP85DRNG.new(bip85_entropy)
81+
rsa_key = RSA.generate_key(4096, drng_reader.read())
82+
83+
===Test Vectors===
84+
INPUT:
85+
xprv9s21ZrQH143K2LBWUUQRFXhucrQqBpKdRRxNVq2zBqsx8HVqFk2uYo8kmbaLLHRdqtQpUm98uKfu3vca1LqdGhUtyoFnCNkfmXRyPXLjbKb
86+
* MASTER BIP32 ROOT KEY: m/83696968'/0'/0'
87+
88+
OUTPUT
89+
* DERIVED KEY=cca20ccb0e9a90feb0912870c3323b24874b0ca3d8018c4b96d0b97c0e82ded0
90+
* DERIVED ENTROPY=6bea85e51a05e6dbaf2ccee05097758213807997ba936589cef01c8f19c0079f395a0cd045efa3438677f3ef9ad34c9a68506626c5a17e51ed5e177852ee7fdc
91+
92+
* DRNG(80 bytes)=b78b1ee6b345eae6836c2d53d33c64cdaf9a696487be81b03e822dc84b3f1cd883d7559e53d175f243e4c349e822a957bbff9224bc5dde9492ef54e8a439f6bc8c7355b87a925a37ee405a7502991111
93+
7294
==Reference Implementation==
7395

74-
Python library implementation: [https://github.com/ethankosakovsky/bipentropy python-bipentropy]
96+
Python library implementation: [https://github.com/ethankosakovsky/bip85]
7597

7698
===Other Implementations===
7799

78-
Coldcard Firmware: [https://github.com/Coldcard/firmware/pull/39]
100+
* JavaScript library implementation: [https://github.com/hoganri/bip85-js]
101+
102+
* Coldcard Firmware: [https://github.com/Coldcard/firmware/pull/39]
79103
80104
==Applications==
81105

82106
Application number define how entropy will be used post processing. Some basic examples follow:
83107

84-
Derivation path uses the format <code>m/83696968/' + /app_no' + /index'</code> where ''app_no'' path for the application, and `index` in the index.
108+
Derivation path uses the format <code>m/83696968/{app_no}'/{index}'</code> where ''{app_no}'' path for the application, and ''{index}'' in the index.
85109

86110
===BIP39===
87111
Application number: 39'
@@ -231,6 +255,36 @@ INPUT:
231255
OUTPUT
232256
* DERIVED ENTROPY=492db4698cf3b73a5a24998aa3e9d7fa96275d85724a91e71aa2d645442f878555d078fd1f1f67e368976f04137b1f7a0d19232136ca50c44614af72b5582a5c
233257
258+
===RSA===
259+
260+
Application number: 828365'
261+
262+
The derivation path format is: <code>m/83696968'/828365'/{key_bits}'/{key_index}'</code>
263+
264+
The RSA key generator should use BIP85-DRNG as the input RNG function.
265+
266+
===RSA GPG===
267+
268+
Keys allocated for RSA-GPG purposes use the following scheme:
269+
270+
- Main key <code>m/83696968'/828365'/{key_bits}'/{key_index}'</code>
271+
- Sub keys: <code>m/83696968'/828365'/{key_bits}'/{key_index}'/{sub_key}'</code>
272+
273+
- key_index is the parent key for CERTIFY capability
274+
- sub_key <code>0'</code> is used as the ENCRYPTION key
275+
- sub_key <code>1'</code> is used as the AUTHENTICATION key
276+
- sub_key <code>2'</code> is usually used as SIGNATURE key
277+
278+
Note on timestamps:
279+
280+
The resulting RSA key can be used to create a GPG key where the creation date MUST be fixed to unix Epoch timestamp 1231006505 (the Bitcoin genesis block time <code>'2009-01-03 18:05:05'</code> UTC) because the key fingerprint is affected by the creation date (Epoch timestamp 0 was not chosen because of legacy behavior in GNUPG implementations for older keys). Additionally, when importing sub-keys under a key in GNUPG, the system time must be frozen to the same timestamp before importing (e.g. by use of <code>faketime</code>).
281+
282+
Note on GPG key capabilities on smartcard/hardware devices:
283+
284+
GPG capable smart-cards SHOULD be be loaded as follows: The encryption slot SHOULD be loaded with the ENCRYPTION capable key; the authentication slot SHOULD be loaded with the AUTHENTICATION capable key. The signature capable slot SHOULD be loaded with the SIGNATURE capable key.
285+
286+
However, depending on available slots on the smart-card, and preferred policy, the CERTIFY capable key MAY be flagged with CERTIFY and SIGNATURE capabilities and loaded into the SIGNATURE capable slot (for example where the smart-card has only three slots and the CERTIFY capability is required on the same card). In this case, the SIGNATURE capable sub-key would be disregarded because the CERTIFY capable key serves dual purpose.
287+
234288
==Backwards Compatibility==
235289

236290
This specification is not backwards compatible with any other existing specification.

0 commit comments

Comments
 (0)