Class Scheme


  • public abstract class Scheme
    extends java.lang.Object
    An implementation of Shamir's Secret Sharing over GF(256) to securely split secrets into N parts, of which any K can be joined to recover the original secret.

    Scheme uses the same GF(256) field polynomial as the Advanced Encryption Standard (AES): 0x11b, or x8 + x4 + x3 + x + 1.

    See Also:
    Shamir's Secret Sharing, The Finite Field GF(256)
    • Constructor Summary

      Constructors 
      Constructor Description
      Scheme()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      byte[] join​(java.util.Map<java.lang.Integer,byte[]> parts)
      Joins the given parts to recover the original secret.
      abstract int k()
      The number of parts the scheme will require to re-create a secret.
      abstract int n()
      The number of parts the scheme will generate when splitting a secret.
      static @NotNull Scheme of​(int n, int k)
      Creates a new Scheme instance.
      java.util.Map<java.lang.Integer,byte[]> split​(byte[] secret)
      Splits the given secret into n parts, of which any k or more can be combined to recover the original secret.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Scheme

        public Scheme()
    • Method Detail

      • of

        @NotNull
        @Contract("_, _ -> new")
        public static @NotNull Scheme of​(int n,
                                         int k)
        Creates a new Scheme instance.
        Parameters:
        n - the number of parts to produce (must be >1)
        k - the threshold of joinable parts (must be <= n)
        Returns:
        an N/K Scheme
      • n

        public abstract int n()
        The number of parts the scheme will generate when splitting a secret.
        Returns:
        N
      • k

        public abstract int k()
        The number of parts the scheme will require to re-create a secret.
        Returns:
        K
      • split

        public java.util.Map<java.lang.Integer,byte[]> split​(byte[] secret)
        Splits the given secret into n parts, of which any k or more can be combined to recover the original secret.
        Parameters:
        secret - the secret to split
        Returns:
        a map of n part IDs and their values
      • join

        @Contract(pure=true)
        public byte[] join​(java.util.Map<java.lang.Integer,byte[]> parts)
        Joins the given parts to recover the original secret.

        N.B.: There is no way to determine whether or not the returned value is actually the original secret. If the parts are incorrect, or are under the threshold value used to split the secret, a random value will be returned.

        Parameters:
        parts - a map of part IDs to part values
        Returns:
        the original secret
        Throws:
        java.lang.IllegalArgumentException - if parts is empty or contains values of varying lengths