diff --git a/core/src/main/java/com/google/bitcoin/crypto/HDKeyDerivation.java b/core/src/main/java/com/google/bitcoin/crypto/HDKeyDerivation.java index df979587..32c03d0d 100644 --- a/core/src/main/java/com/google/bitcoin/crypto/HDKeyDerivation.java +++ b/core/src/main/java/com/google/bitcoin/crypto/HDKeyDerivation.java @@ -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 * 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 IllegalArgumentException if the seed is less than 8 bytes and could be brute forced. */ 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) byte[] i = HDUtils.hmacSha512(MASTER_HMAC_SHA512, seed); // Split I into two 32-byte sequences, Il and Ir.