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 class  MultisigHMAC.Algorithm
    The implementation supports SHA256, SHA512, and SHA384 for HMAC
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected int BYTES  
    protected int KEYBYTES  
    protected String PRIMITIVE  
  • 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
    Signature combine​(List<Signature> signatures)
    Constructs and initializes a combined signature Only include each signature once, otherwise it will cancel out.
    Key generate​(int index)
    Generates a new cryptographically random key
    int getBYTES()  
    int getKEYBYTES()  
    String getPRIMITIVE()  
    protected static List<Integer> keyIndexes​(int bitField)
    Computes the indexes of the keys (indexes of 1-bits)
    protected static int leadingZeros​(int bitField)
    Computes the number of leading zeros
    protected static int popCount​(int bitField)
    Computes the number of keys (the number of 1-bits)
    Signature sign​(Key key, byte[] message)
    Independently signs message with a key
    boolean verify​(List<Key> keys, Signature signatures, byte[] message, int threshold)
    Verifies a signature of message against a list of keys
    protected byte[] xorBytes​(byte[] a, byte[] b)
    Xor two byte arrays

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • MultisigHMAC

      public MultisigHMAC​(MultisigHMAC.Algorithm alg)
      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

      public String getPRIMITIVE()
    • getKEYBYTES

      public int getKEYBYTES()
    • getBYTES

      public int getBYTES()
    • generate

      public Key generate​(int index)
      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, InvalidKeyException
      Independently signs message with a key
      Parameters:
      key - - key which is an instance of Key used for signing
      message - - message which should be signed
      Returns:
      sign of data which is an instance of Signature
      Throws:
      NoSuchAlgorithmException - - if the specified algorithm is not available
      InvalidKeyException - - if the given key is inappropriate for initializing this HMAC
    • combine

      public Signature combine​(List<Signature> signatures)
      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 array
      b - - second byte array
      Returns:
      xor'ed byte array
    • verify

      public boolean verify​(List<Key> keys, Signature signatures, byte[] message, int threshold) throws InvalidKeyException, NoSuchAlgorithmException, IllegalArgumentException
      Verifies a signature of message against a list of keys
      Parameters:
      keys - - a list of all keys
      signatures - - combined signature
      message - - message which has been signed
      threshold - - 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 HMAC
      NoSuchAlgorithmException - - if the specified algorithm is not available
      IllegalArgumentException
    • keyIndexes

      protected static List<Integer> keyIndexes​(int bitField)
      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