This repository contains a Rust implementation of Shamir's Secret Sharing algorithm, split into two main components:
A reusable Rust library that implements Shamir's Secret Sharing algorithm using Galois Field arithmetic over GF(256).
Key Features:
- Split secrets into multiple shares with configurable thresholds
- Reconstruct secrets from minimum required shares
- Pure Rust implementation with no external dependencies (except rand for randomness)
- Comprehensive documentation and examples
Location: shamir-algorithm/
Documentation: README
A command-line application that demonstrates the usage of the shamir-algorithm library.
Features:
- Interactive command-line interface for secret sharing
- Base64 encoding of shares for easy handling
- Complete example implementation
- Educational demonstrations of the algorithm
Location: ShamirRust/
Documentation: README (in Catalan)
Shamir's Secret Sharing is a cryptographic algorithm that allows a secret to be divided into multiple shares such that:
- The secret can be reconstructed from a minimum threshold of shares
- Fewer than the threshold shares reveal no information about the secret
This is particularly useful in scenarios requiring distributed trust, such as:
- Multi-signature wallets in blockchain
- Secure key management systems
- Distributed access control
- Backup systems with redundancy
Add to your Cargo.toml:
[dependencies]
shamir-algorithm = "0.1.0"git clone https://github.com/yourusername/ShamirRust.git
cd ShamirRust
cargo build --releaseuse shamir_algorithm::ShamirSS;
use std::collections::BTreeMap;
let secret = b"Hello, world!";
let n = 5; // Total shares
let k = 3; // Threshold
// Split the secret
let shares = ShamirSS::split(n, k, secret.to_vec()).unwrap();
// Reconstruct using k shares
let mut parts = BTreeMap::new();
for i in 1..=k {
parts.insert(i, shares[&i].clone());
}
let reconstructed = ShamirSS::join(parts).unwrap();
assert_eq!(reconstructed, secret);MIT License - see LICENSE for details.
Contributions are welcome! Please feel free to submit a Pull Request.
