Code Monkey home page Code Monkey logo

sss-rs's Introduction

sss-rs

Build Status

An implementation of a secret sharing scheme in Rust.

wrapped_sharing contains wrapper functions that wrap around the functionality in basic_sharing, which can include using a hash placed at the end to automatically verify if the secret was properly reconstructed, ease of 'compressing' the shares by not requiring an X-value for every Y-value, and sharing/reconstructing to and from memory and files interchangeably.

This implementation uses arithmetic over GF(256), shares using wrapped_sharing use a 64-byte hash placed at the end of the of the secret before sharing that gets shared with it. This way, the reconstruction of the secret can be verified by the hash. This along with a share's corresponding X-value, puts each share at [[1-byte X value]] + [[N-byte Secret]] + [[64-byte hash (optional)]]

Notably, given N required shares to reconstruct, and M shares generated, any X number of shares where N <= X <= M can be used, without the need of specifying how many were required (using more shares however will increase reconstruction time). This goes for both wrapped_sharing and basic_sharing.

Example with the wrapped_sharing API

use wrapped_sharing::{Secret, share};
let shares_required = 3;
let shares_to_create = 3;
let verify = true;
let secret: Vec<u8> = vec![5, 4, 9, 1, 2, 128, 43];
let shares = share(Secret::InMemory(secret), shares_required, shares_to_create, verify).unwrap();
let mut recon = Secret::empty_in_memory();
recon.reconstruct(shares);
assert_eq!(secret, recon.unwrap_vec());

Example with the lower-level basic_sharing API

use basic_sharing::{from_secret, reconstruct_secret};
// While this just uses a single secret sharing function, there are variants for Vec<u8>
let mut rand = SmallRng::seed_from_u64(123u64); // Note that rng is optional, default seeds from entropy
let secret: u8 = 23; // The secret to be split into shares
let shares_required = 3; // The number of shares required to reconstruct the secret
let shares_to_create = 3; // The number of shares to create, can be greater than the required

let shares: Vec<(u8, u8)> = from_secret(secret,
							shares_required,
							shares_to_create,
							Some(rand)).unwrap();
let secret_recon = reconstruct_secret(shares);

assert_eq!(secret, secret_recon);

sss-rs's People

Contributors

bilowik avatar umgefahren avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.