Function sskr_generate

Source
pub fn sskr_generate(
    spec: &SSKRSpec,
    master_secret: &SSKRSecret,
) -> Result<Vec<Vec<SSKRShare>>, SSKRError>
Expand description

Generates SSKR shares for the given Spec and Secret.

This function splits a master secret into multiple shares according to the specified group and member thresholds, using a secure random number generator.

§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.

§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};

// 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)
// First group: 2 of 3 shares needed
// Second group: 3 of 5 shares needed
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
let shares = sskr_generate(&spec, &master_secret).unwrap();

// Verify the structure matches our specification
assert_eq!(shares.len(), 2);           // 2 groups
assert_eq!(shares[0].len(), 3);        // 3 shares in first group
assert_eq!(shares[1].len(), 5);        // 5 shares in second group