mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-07 14:54:15 +00:00
HDW: Add some docs and a safety check to HDKeyDerivation.
This commit is contained in:
parent
8769773717
commit
a5d14ba45b
@ -39,11 +39,14 @@ public final class HDKeyDerivation {
|
|||||||
/**
|
/**
|
||||||
* Generates a new deterministic key from the given seed, which can be any arbitrary byte array. However resist
|
* Generates a new deterministic key from the given seed, which can be any arbitrary byte array. However resist
|
||||||
* the temptation to use a string as the seed - any key derived from a password is likely to be weak and easily
|
* the temptation to use a string as the seed - any key derived from a password is likely to be weak and easily
|
||||||
* broken by attackers (this is not theoretical, people have had money stolen that way).
|
* broken by attackers (this is not theoretical, people have had money stolen that way). This method checks
|
||||||
|
* that the given seed is at least 64 bits long.
|
||||||
*
|
*
|
||||||
* @throws HDDerivationException if generated master key is invalid (private key 0 or >= n).
|
* @throws HDDerivationException if generated master key is invalid (private key 0 or >= n).
|
||||||
|
* @throws IllegalArgumentException if the seed is less than 8 bytes and could be brute forced.
|
||||||
*/
|
*/
|
||||||
public static DeterministicKey createMasterPrivateKey(byte[] seed) throws HDDerivationException {
|
public static DeterministicKey createMasterPrivateKey(byte[] seed) throws HDDerivationException {
|
||||||
|
checkArgument(seed.length > 8, "Seed is too short and could be brute forced");
|
||||||
// Calculate I = HMAC-SHA512(key="Bitcoin seed", msg=S)
|
// Calculate I = HMAC-SHA512(key="Bitcoin seed", msg=S)
|
||||||
byte[] i = HDUtils.hmacSha512(MASTER_HMAC_SHA512, seed);
|
byte[] i = HDUtils.hmacSha512(MASTER_HMAC_SHA512, seed);
|
||||||
// Split I into two 32-byte sequences, Il and Ir.
|
// Split I into two 32-byte sequences, Il and Ir.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user