Package dk.hyperdivision.multisig_hmac
Class DeriveKey
java.lang.Object
dk.hyperdivision.multisig_hmac.IndexKey
dk.hyperdivision.multisig_hmac.DeriveKey
public class DeriveKey extends IndexKey
DeriveKey represents a pair of index + cryptographically random key.
Used for the key management method where a single master seed is stored and
used to derive keys ad hoc.
- Author:
- Amalie Due Jensen
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description static byte[]derivekey(byte[] MasterSeed, int index, String Algorithm)Derives a new sub key from a master seed.static byte[]intToLittleEndian(int index)Converts an integer into a little endian byte arraystatic byte[]SeedGen(int KEYBYTES)Generates a new cryptographically random master seed
-
Constructor Details
-
DeriveKey
public DeriveKey(byte[] MasterSeed, int index, String Algorithm) throws InvalidKeyException, NoSuchAlgorithmExceptionConstructs and initializes a pair of index + a new cryptographically random key- Parameters:
MasterSeed- - master seed used to derive keysindex- - index of the keyAlgorithm- - algorithm used for HMAC- Throws:
InvalidKeyException- - if the given key is inappropriate for initializing this HMACNoSuchAlgorithmException- - if the specified algorithm is not available
-
-
Method Details
-
derivekey
public static byte[] derivekey(byte[] MasterSeed, int index, String Algorithm) throws InvalidKeyException, NoSuchAlgorithmExceptionDerives a new sub key from a master seed. Note that index should be counted from 0. The bitfield used with the signature has as many bits as the largest index, hence in practice you want to keep the indexes low. Keys are derived using a KDF based on HMAC: b[0...BYTES] = HMAC(Key = MasterSeed, data = "derived" || U32LE(index) || 0x00) b[BYTES...] = HMAC(Key = MasterSeed, b[0...BYTES] || 0x01)- Parameters:
MasterSeed- - master seed in bytes of length KEYBYTES used to derive keysindex- - index of the keyAlgorithm- - algorithm used for HMAC- Returns:
- the derived key in bytes of length KEYBYTES
- Throws:
InvalidKeyException- - if the given key is inappropriate for initializing this HMACNoSuchAlgorithmException- - if the specified algorithm is not available
-
SeedGen
public static byte[] SeedGen(int KEYBYTES)Generates a new cryptographically random master seed- Parameters:
KEYBYTES- - length of the master seed- Returns:
- master seed
-
intToLittleEndian
public static byte[] intToLittleEndian(int index)Converts an integer into a little endian byte array- Parameters:
index- - integer which should be converted- Returns:
- little endian byte array
-