ShamirSharedSecret - Reference Documentation
Index of Methods
Constructor
Prototype
ShamirSharedSecret(ByteString prime)
ShamirSharedSecret(Number bits)
Description
Create an instance to generate or reconstruct a shared secret
Arguments
Type |
Name |
Description |
ByteString
|
prime |
The prime to be used |
Number
|
bits |
The number of bits for the randomly generated prime |
Exceptions
Name |
Value |
Description |
GPError |
GPError.ARGUMENTS_MISSING |
Too few arguments in call |
GPError |
GPError.INVALID_ARGUMENTS |
Too many arguments in call |
GPError |
GPError.INVALID_TYPE |
Type of argument is invalid for call |
Example
var prime = new ByteString("e25cb644c99928ff", HEX);
var sss = new ShamirSharedSecret(prime);
addShare()
Prototype
addShare(Number id, ByteString share)
Description
Add the share identified by id.
Arguments
Type |
Name |
Description |
Number
|
id |
The id for the share |
ByteString
|
share |
The share value |
Return
Exceptions
Name |
Value |
Description |
GPError |
GPError.INVALID_ARGUMENTS |
Too many arguments in call |
Example
var share = [
new ByteString("dabd6f8a03d16d54", HEX),
new ByteString("62d50d9144316251", HEX),
new ByteString("cd4961dd4e2a804d", HEX)
];
var sss = new ShamirSharedSecret(prime);
sss.addShare(1, share[0]);
sss.addShare(2, share[1]);
reconstructSecret()
Prototype
ByteString reconstructSecret()
Description
Reconstruct the shared secret from previously added shares.
Return
ByteString
|
The recovered secret |
Exceptions
Name |
Value |
Description |
GPError |
GPError.INVALID_ARGUMENTS |
Too many arguments in call |
Example
var s = sss.reconstructSecret();
// print(s);
var ref = new ByteString("70491B3DF9D84F58", HEX);
assert(s.equals(ref));
getPrime()
Prototype
ByteString getPrime()
Description
Return the prime generated or set in the constructor.
Return
Exceptions
Name |
Value |
Description |
GPError |
GPError.INVALID_ARGUMENTS |
Too many arguments in call |
Example
var sss = new ShamirSharedSecret(64);
var prime = sss.getPrime();
print("Prime " + prime);
trimSecret()
Prototype
ByteString trimSecret(ByteString secret)
Description
Ensure that the secret is smaller than the prime using a modulo operation.
Return
ByteString
|
The trimmed secret |
Exceptions
Name |
Value |
Description |
GPError |
GPError.INVALID_ARGUMENTS |
Too many arguments in call |
Example
var secret = crypto.generateRandom(9);
print("Secret (raw) " + secret);
secret = sss.trimSecret(secret);
print("Secret (trim) " + secret);
createShares()
Prototype
ByteString[] createShares(ByteString secret, Number threshold, Number shares)
Description
Create the shares for a given secret. The numeric value of the secret must be smaller than the prime.
Arguments
Type |
Name |
Description |
ByteString
|
secret |
The secret to split. Must be smaller than the prime |
Number
|
threshold |
The number of shares required to reconstruct |
Number
|
shares |
The total number of shares. |
Return
ByteString[]
|
An array containing the shares |
Exceptions
Name |
Value |
Description |
GPError |
GPError.INVALID_ARGUMENTS |
Too many arguments in call |
Example
var sss = new ShamirSharedSecret(prime);
var shares = sss.createShares(secret, 2, 3);
for (var i = 0; i < shares.length; i++) {
print("Id " + (i + 1) + " : " + shares[i]);
}
© Copyright 2003 - 2024 CardContact Systems GmbH
, Minden, Germany