Function ssss::gen_shares

source ·
pub fn gen_shares(config: &SsssConfig, secret: &[u8]) -> Result<Vec<String>>
Expand description

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 than max_secret_size in the configuration.
  • This function will generate an error if either num_shares or threshold are 0.
  • This function will generate an error if threshold is greater than num_shares

Example

// Generate 5 shares from the given secret
let secret = "correct horse battery staple".as_bytes();
let config = SsssConfig::default();

// Generate 5 shares to be distributed, requiring a minimum of 3 later
// to unlock the secret
let mut shares = gen_shares(&config, &secret)?;
assert_eq!(shares.len(), 5);