[−][src]Function ssss::gen_shares
pub fn gen_shares(
config: &SSSSConfig,
secret: &[u8]
) -> Result<HashMap<u8, Vec<u8>>, Error>
Generate shares based on the num_shares
and threshold
given
in the configuration. Using the default SSSSConfig
will generate 5 shares
of which 3 are required to unlock the secret.
Errors
- This function will generate an error if
secret
is empty or larger thanmax_secret_size
in the configuration. - This function will generate an error if either
num_shares
orthreshold
are 0. - This function will generate an error if
threshold
is greater thannum_shares
Example
// Generate 5 shares from the given secret let secret = "s3(r37".as_bytes(); let mut shares = gen_shares(&SSSSConfig::default(), secret)?; assert_eq!(shares.len(), 5); // Remove a couple shares to show 3 will unlock the secret (4 or 5 shares will as well) let _ = shares.remove(&2); let _ = shares.remove(&5); assert_eq!(shares.len(), 3); let unlocked_secret = unlock(&shares)?; assert_eq!(secret, unlocked_secret); // Remove one more to show 2 shares will not unlock the secret let _ = shares.remove(&1); assert_eq!(shares.len(), 2); let who_knows = unlock(&shares)?; assert_ne!(secret, who_knows);