sskr_generate_using

Function sskr_generate_using 

Source
pub fn sskr_generate_using(
    spec: &SSKRSpec,
    master_secret: &SSKRSecret,
    rng: &mut impl RandomNumberGenerator,
) -> Result<Vec<Vec<SSKRShare>>, Error>
Expand description

Generates SSKR shares using a custom random number generator.

This function is similar to sskr_generate, but allows specifying a custom random number generator for deterministic testing or other specialized needs.

§Parameters

  • spec - The SSKRSpec instance that defines the group threshold, number of groups, and the member thresholds for each group.
  • master_secret - The SSKRSecret instance to be split into shares.
  • rng - The random number generator to use for generating shares.

§Returns

A result containing a nested vector of SSKRShare instances if successful, or an SSKRError if the operation fails. The outer vector contains one vector per group, and each inner vector contains the shares for that group.

§Errors

Returns an error if:

  • The secret is too short or too long
  • The group threshold is invalid
  • The member thresholds are invalid
  • Any other error in the underlying SSKR implementation

§Example

use bc_components::{SSKRSecret, SSKRSpec, SSKRGroupSpec, sskr_generate_using};
use bc_rand::SecureRandomNumberGenerator;

// Create a master secret from a byte array (must be exactly 16 or 32 bytes)
let master_secret = SSKRSecret::new(b"0123456789abcdef").unwrap(); // Exactly 16 bytes

// Configure a split with 2 groups, requiring both groups (threshold = 2)
let group1 = SSKRGroupSpec::new(2, 3).unwrap();
let group2 = SSKRGroupSpec::new(3, 5).unwrap();
let spec = SSKRSpec::new(2, vec![group1, group2]).unwrap();

// Generate the shares with a custom RNG
let mut rng = SecureRandomNumberGenerator;
let shares = sskr_generate_using(&spec, &master_secret, &mut rng).unwrap();

// Verify the structure
assert_eq!(shares.len(), 2);
assert_eq!(shares[0].len(), 3);
assert_eq!(shares[1].len(), 5);