This is an implementation of the Shamir's secret sharing scheme in Scala 3
To run the dealer test (share a secret and reconstruct the secret in several configurations)
Run dealer test: sbt "testOnly *.DealerTest"
The sharing scheme is using polynomials in finite fields, this implementation makes use of an improved way of evaluating polynomials
Given your secret s
as bytes:
- Initiate the sharing scheme for your dealer:
val sharingScheme = ShamirSecretSharingScheme(
Config(
BigInt(s), // Your secret
threshold, // The minium number of shares required to recover the secret
numberOfParticipants, // Total number of participants/shares
bitLen // The bit length of the prime number used to define the finite field (should be larger than the size of the secret)
)
)
val dealer = Dealer(sharingScheme)
- Share your secret with your trusted parties:
val shares = dealer.share(s)
- Later on, reconstruct your secret, given at least
threshold
shares:
val recoveredSecret = dealer.recover(colectedShares)