Expand description
§Shamir’s Secret Sharing Implementation
This module provides an implementation of Shamir’s Secret Sharing (SSS) scheme with verifiable shares. The implementation uses the secp256k1 curve (via k256) for cryptographic operations and supports both basic and verifiable secret sharing.
§Overview
Shamir’s Secret Sharing is a cryptographic algorithm that splits a secret into multiple shares, where a minimum number of shares (threshold) are required to reconstruct the original secret. This implementation includes:
- Basic secret sharing with polynomial-based share generation
- Verifiable secret sharing with cryptographic proofs
- Lagrange interpolation for secret recovery
- Share validation using elliptic curve cryptography
§Security Properties
- The secret is split into n shares, where any k shares (k ≤ n) can reconstruct the secret
- Individual shares reveal no information about the secret
- Verifiable shares include proofs that can be used to validate share authenticity
- All operations are performed in the secp256k1 scalar field
§Usage Example
use spark_cryptography::secret_sharing::{split_secret_with_proofs, recover_secret, validate_share};
use k256::{
elliptic_curve::{PrimeField, generic_array::GenericArray},
Scalar,
};
use rand::{rngs::OsRng, RngCore};
use std::error::Error;
// Generate a secret (32 bytes) and convert to k256::Scalar
let secret_bytes = [1u8; 32];
let generic_array = GenericArray::from_slice(&secret_bytes);
let secret_scalar = Scalar::from_repr_vartime(*generic_array).unwrap();
// Split into 5 shares with threshold of 3
let shares = split_secret_with_proofs(&secret_scalar, 3, 5).unwrap();
// Validate shares
for share in &shares {
validate_share(share).unwrap();
}
// Recover secret using any 3 shares
let recovered = recover_secret(&shares[0..3]).unwrap();
§Implementation Details
The implementation uses:
- k256 for secp256k1 curve operations
- Random number generation via OsRng
- Polynomial evaluation for share generation
- Lagrange interpolation for secret recovery
- Cryptographic proofs for share verification
Structs§
- Polynomial
- Polynomial used for secret sharing
- Secret
Share - Basic secret share structure
- Verifiable
Secret Share - Verifiable secret share with proofs
Traits§
- Lagrange
Interpolatable - Trait for Lagrange interpolation
Functions§
- compute_
lagrange_ coefficients - Computes Lagrange coefficients for interpolation
- from_
bytes_ to_ k256_ scalar - Converts a byte slice to a Scalar
- recover_
secret - Recovers a secret from a set of shares using Lagrange interpolation
- split_
secret - Splits a secret into shares using Shamir’s Secret Sharing
- split_
secret_ with_ proofs - Splits a secret into verifiable shares with cryptographic proofs
- validate_
share - Validates a verifiable share using its cryptographic proofs