Giter Site home page Giter Site logo

shamir's Introduction

Shamir

Coverage Status

Build Status

Shamir is a pure Rust implementation of Shamir's secret sharing.

Install

To install shamir into your application, you need to add it to your cargo.toml:

[dependencies]
shamir = "~1.0"

and you need to include it at the top of oyur main.rs:

extern crate shamir;

use shamir::SecretData;

Usage

extern crate shamir;

use shamir::SecretData;

fn main() {
    let secret_data = SecretData::with_secret("Hello World!", 3);

    let share1 = secret_data.get_share(1);
    let share2 = secret_data.get_share(2);
    let share3 = secret_data.get_share(3);

    let recovered = SecretData::recover_secret(3, vec![share1, share2, share3]).unwrap();

    println!("Recovered {}", recovered);
}

shamir's People

Contributors

chrismacnaughton avatar lucab avatar

Stargazers

Markus Zoppelt avatar  avatar JacobLinCool avatar Shun Kakinoki avatar  avatar Colin Nielsen avatar  avatar Will R avatar Guillaume Bogard avatar Paco avatar dylanhuang avatar  avatar Dylan Perks avatar Justin Tan avatar GuoYunzhe avatar ollcp avatar Praveen Perera avatar  avatar Luis Eduardo Gutiérrez avatar Matthew Remmel avatar Aitor avatar Martin Zlámal avatar Alexander Weber avatar drbh avatar Eduardo Rabelo avatar Glenn 'devalias' Grant avatar Rasmus Schlünsen avatar Håvard Anda Estensen avatar Nicolas Marshall avatar HAOYUatHZ avatar Tyr Chen avatar  avatar Sergey Tolmachev avatar Pawan Dhananjay avatar Max Riveiro avatar  avatar dp avatar wieDasDing avatar Glaxx avatar  avatar Evan avatar Bartłomiej Kamiński avatar Andréy Lesnikóv avatar Miki Oracle avatar Stanko Krtalić avatar Val Packett avatar Will Hipschman avatar Thomas Bahn avatar Michael Greene avatar Sebastian Thiel avatar Greg Chapple avatar Sean Jensen-Grey avatar caojiafeng avatar KokaKiwi avatar Kornelijus avatar Shotaro Yamada avatar Félix Saparelli avatar Connor Jacobsen avatar Steve Klabnik avatar Stephan Sokolow avatar

Watchers

 avatar James Cloos avatar  avatar

shamir's Issues

SECURITY: Threshold value is ignored (all shares are n=3).

There is a pretty serious bug in SecretData::with_secret -- all sharded secrets (no matter the threshold setting) will require three shares to reconstruct the secret. Here's an example:

extern crate shamir;

use shamir::SecretData;

fn try_recover(n: u8, shares: &Vec<Vec<u8>>) -> Option<String> {
    let shares = shares.iter().take(n as usize).cloned().collect::<Vec<_>>();
    SecretData::recover_secret(n, shares)
}

fn main() {
    let secret_data = SecretData::with_secret("Hello World!", 5);

    let shares = vec![
        secret_data.get_share(1),
        secret_data.get_share(2),
        secret_data.get_share(3),
        secret_data.get_share(4),
        secret_data.get_share(5),
    ];

    let recovered = try_recover(5, &shares).unwrap();
    println!("Good recover: {}", recovered);

    let recovered = try_recover(3, &shares).unwrap();
    println!("Bad recover: {}", recovered);
}

The reason for this bug is this line from with_secret:

        let mut rand_container = [0u8, threshold - 1];

This leads to only three coefficients being generated for the polynomial (resulting in an n=3 threshold system). I presume this was meant to be [0u8; threshold - 1] (an array of zeroes of threshold - 1 size) but this won't work in Rust -- instead you should use something like vec![0; threshold - 1].

I'm a also quite a bit worried by the very minimal test-cases (failure to reconstruct isn't checked, and the only threshold tests are for 3 shares -- this bug would've been obvious if there was a test for 2 shares). As it stands, I would humbly suggest that you yank all releases of shamir and make a new release which fixes this problem (or, since it seems this crate is abandoned, just leave it yanked).

/cc @ChrisMacNaughton

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.