[−][src]Crate shamirsecretsharing
This crate provides bindings to my Shamir secret sharing library.
The main functions to use are create_shares
and combine_shares
.
The hazmat
module is for experts. The functions in the hazmat
module miss some security
guarantees, so do not use them unless you really know what you are doing.
Encapsulated in the SSSResult
, combine_shares
will return an Option<_>
which will be
Some(data)
if the data could be restored. If the data could not be restored, combine_shares
will return Ok(None)
. This means that could mean either of:
- More shares were needed to reach the treshold.
- Shares of different sets (corresponding to different secrets) were supplied or some of the shares were tampered with.
Example
use shamirsecretsharing::*; // Create a some shares over the secret data `[42, 42, 42, ...]` let data = vec![42; DATA_SIZE]; let count = 5; let treshold = 4; let mut shares = create_shares(&data, count, treshold).unwrap(); // Lose a share (for demonstrational purposes) shares.remove(3); // We still have 4 shares, so we should still be able to restore the secret let restored = combine_shares(&shares).unwrap(); assert_eq!(restored, Some(data)); // If we lose another share the secret is lost shares.remove(0); let restored2 = combine_shares(&shares).unwrap(); assert_eq!(restored2, None);
This library supports can generate sets with at most count
and a treshold
shares.
Modules
hazmat | Hazardous materials (key-sharing) |
Enums
SSSError | Custom error types for errors originating from this crate |
Constants
DATA_SIZE | The size of the input data to |
SHARE_SIZE | Regular share size from shares produced by |
Functions
combine_shares | Combine a set of shares and return the original secret |
create_shares | Create a set of shares |