Package dk.hyperdivision.multisig_hmac
Class MultisigHMAC
java.lang.Object
dk.hyperdivision.multisig_hmac.MultisigHMAC
- Direct Known Subclasses:
DerivedMultisigHMAC
public class MultisigHMAC extends Object
Multisig scheme for HMAC authentication. Java implementation
of https://github.com/emilbayes/multisig-hmac.
In this case, each of the component keys are stored. The class
is extended by the class DerivedMultisigHMAC in which a single
master key is stored and used to derive keys ad hoc.
- Version:
- 2.0.0
- Author:
- Amalie Due Jensen
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMultisigHMAC.AlgorithmThe implementation supports SHA256, SHA512, and SHA384 for HMAC -
Field Summary
-
Constructor Summary
Constructors Constructor Description MultisigHMAC(MultisigHMAC.Algorithm alg)Constructs and initializes a new instance of MultisigHMAC and sets the algorithm to be used for subsequent methods -
Method Summary
Modifier and Type Method Description Signaturecombine(List<Signature> signatures)Constructs and initializes a combined signature Only include each signature once, otherwise it will cancel out.Keygenerate(int index)Generates a new cryptographically random keyintgetBYTES()intgetKEYBYTES()StringgetPRIMITIVE()protected static List<Integer>keyIndexes(int bitField)Computes the indexes of the keys (indexes of 1-bits)protected static intleadingZeros(int bitField)Computes the number of leading zerosprotected static intpopCount(int bitField)Computes the number of keys (the number of 1-bits)Signaturesign(Key key, byte[] message)Independently signs message with a keybooleanverify(List<Key> keys, Signature signatures, byte[] message, int threshold)Verifies a signature of message against a list of keysprotected byte[]xorBytes(byte[] a, byte[] b)Xor two byte arrays
-
Field Details
-
Constructor Details
-
MultisigHMAC
Constructs and initializes a new instance of MultisigHMAC and sets the algorithm to be used for subsequent methods- Parameters:
alg- - algorithm used for HMAC
-
-
Method Details
-
getPRIMITIVE
-
getKEYBYTES
public int getKEYBYTES() -
getBYTES
public int getBYTES() -
generate
Generates a new cryptographically random key- Parameters:
index- - index of the key- Returns:
- the key in bytes of length KEYBYTES
-
sign
public Signature sign(Key key, byte[] message) throws NoSuchAlgorithmException, InvalidKeyExceptionIndependently signs message with a key- Parameters:
key- - key which is an instance of Key used for signingmessage- - message which should be signed- Returns:
- sign of data which is an instance of Signature
- Throws:
NoSuchAlgorithmException- - if the specified algorithm is not availableInvalidKeyException- - if the given key is inappropriate for initializing this HMAC
-
combine
Constructs and initializes a combined signature Only include each signature once, otherwise it will cancel out. Signatures can be combined in any order.- Parameters:
signatures- - list of signatures which should be combined- Returns:
- combined signature as an instance of Signature
-
xorBytes
protected byte[] xorBytes(byte[] a, byte[] b)Xor two byte arrays- Parameters:
a- - first byte arrayb- - second byte array- Returns:
- xor'ed byte array
-
verify
public boolean verify(List<Key> keys, Signature signatures, byte[] message, int threshold) throws InvalidKeyException, NoSuchAlgorithmException, IllegalArgumentExceptionVerifies a signature of message against a list of keys- Parameters:
keys- - a list of all keyssignatures- - combined signaturemessage- - message which has been signedthreshold- - minimum number of keys that the list "keys" should contain- Returns:
- verification of the signature (true/false)
- Throws:
InvalidKeyException- - if the given key is inappropriate for initializing this HMACNoSuchAlgorithmException- - if the specified algorithm is not availableIllegalArgumentException
-
keyIndexes
Computes the indexes of the keys (indexes of 1-bits)- Parameters:
bitField- - indexes of keys represented as one integer- Returns:
- indexes of keys in a list
-
popCount
protected static int popCount(int bitField)Computes the number of keys (the number of 1-bits)- Parameters:
bitField- - indexes of keys represented as one integer- Returns:
- number of keys
-
leadingZeros
protected static int leadingZeros(int bitField)Computes the number of leading zeros- Parameters:
bitField- - indexes of keys represented as one integer- Returns:
- number of leading zeros
-