Crate shamir_share

Crate shamir_share 

Source
Expand description

A secure and efficient Rust library for Shamir’s Secret Sharing

This library provides a security-first implementation of Shamir’s Secret Sharing scheme with constant-time operations to prevent side-channel attacks. Split sensitive data into multiple shares where only a threshold number is needed for reconstruction.

§Security Features

  • Constant-time GF(2^8) arithmetic - No lookup tables, resistant to cache-timing attacks
  • Cryptographically secure random generation - Uses ChaCha20Rng seeded from OsRng
  • Integrity verification - SHA-256 hash checking with constant-time comparison
  • Memory safety - Written in safe Rust with zero unsafe blocks

§Quick Start

§Basic Usage

use shamir_share::{ShamirShare, FileShareStore, ShareStore};

// Create a scheme with 5 shares and threshold 3
let mut scheme = ShamirShare::builder(5, 3).build().unwrap();

// Split a secret
let secret = b"my secret data";
let shares = scheme.split(secret).unwrap();

// Store shares
let temp_dir = tempfile::tempdir().unwrap();
let mut store = FileShareStore::new(temp_dir.path()).unwrap();
for share in &shares {
    store.store_share(share).unwrap();
}

// Reconstruct from 3 shares
let loaded_shares = vec![
    store.load_share(1).unwrap(),
    store.load_share(2).unwrap(),
    store.load_share(3).unwrap(),
];
let reconstructed = ShamirShare::reconstruct(&loaded_shares).unwrap();
assert_eq!(reconstructed, secret);

§Lazy Share Generation with Dealer

use shamir_share::ShamirShare;

let mut scheme = ShamirShare::builder(10, 5).build().unwrap();
let secret = b"my secret data";

// Generate only the shares you need
let shares: Vec<_> = scheme.dealer(secret).take(5).collect();

// Or use iterator methods for advanced filtering
let even_shares: Vec<_> = scheme.dealer(secret)
    .filter(|share| share.index % 2 == 0)
    .take(5)
    .collect();

let reconstructed = ShamirShare::reconstruct(&shares).unwrap();
assert_eq!(reconstructed, secret);

Re-exports§

pub use hsss::AccessLevel;
pub use hsss::HierarchicalShare;
pub use hsss::Hsss;
pub use hsss::HsssBuilder;

Modules§

hsss
Hierarchical Secret Sharing Scheme (HSSS) implementation
prelude

Structs§

Config
Configuration options for splitting and reconstruction
Dealer
Lazy iterator for generating shares using Shamir’s Secret Sharing
FileShareStore
File system implementation of ShareStore
FiniteField
Galois Field (GF(256)) arithmetic implementation
ShamirShare
Main implementation of Shamir’s Secret Sharing scheme
ShamirShareBuilder
Builder for creating ShamirShare instances with custom configuration
Share
A share in Shamir’s Secret Sharing scheme
ShareView
A lightweight view into share data for reconstruction without allocation

Enums§

ShamirError
Error type for Shamir’s Secret Sharing operations
SplitMode
Processing mode for share operations

Traits§

ShareStore
Trait defining storage operations for Shamir shares

Type Aliases§

Result