Package com.codahale.shamir
Class Scheme
- java.lang.Object
-
- com.codahale.shamir.Scheme
-
public abstract class Scheme extends java.lang.ObjectAn implementation of Shamir's Secret Sharing overGF(256)to securely split secrets intoNparts, of which anyKcan be joined to recover the original secret.Schemeuses the same GF(256) field polynomial as the Advanced Encryption Standard (AES):0x11b, orx8 +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 intk()The number of parts the scheme will require to re-create a secret.abstract intn()The number of parts the scheme will generate when splitting a secret.static @NotNull Schemeof(int n, int k)Creates a newSchemeinstance.java.util.Map<java.lang.Integer,byte[]>split(byte[] secret)Splits the given secret intonparts, of which anykor more can be combined to recover the original secret.
-
-
-
Method Detail
-
of
@NotNull @Contract("_, _ -> new") public static @NotNull Scheme of(int n, int k)Creates a newSchemeinstance.- Parameters:
n- the number of parts to produce (must be>1)k- the threshold of joinable parts (must be<= n)- Returns:
- an
N/KScheme
-
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 intonparts, of which anykor more can be combined to recover the original secret.- Parameters:
secret- the secret to split- Returns:
- a map of
npart 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- ifpartsis empty or contains values of varying lengths
-
-