Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ documentation = "https://docs.rs/shamirsecretsharing"
license = "MIT"
name = "shamirsecretsharing"
repository = "https://github.com/dsprenkels/sss-rs"
version = "0.1.5"
version = "0.1.7"

[badges]
maintenance = {status = "passively-maintained"}
Expand All @@ -18,11 +18,8 @@ travis-ci = {repository = "dsprenkels/sss-rs", branch = "master"}
have_libsodium = []

[dependencies]
rand = "0.8"
xsalsa20poly1305 = "0.6"
rand = "0.8.5"
crypto_secretbox = "0.1"

[dev-dependencies]
chacha20-poly1305-aead = "0.1"

[build-dependencies]
cc = "1.0"
17 changes: 8 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,13 @@ This library supports can generate sets with at most `count` and a `treshold` sh
#![warn(missing_docs)]

extern crate rand;
extern crate xsalsa20poly1305;
extern crate crypto_secretbox;
use hazmat::{KEYSHARE_SIZE, KEY_SIZE};
#[link(name = "sss", kind = "static")]
use std::error;
use std::fmt;
use xsalsa20poly1305::{
aead::{AeadMut, NewAead},
XSalsa20Poly1305, NONCE_SIZE,
use crypto_secretbox::{
aead::{Aead, KeyInit},
XSalsa20Poly1305,
};

/// Custom error types for errors originating from this crate
Expand Down Expand Up @@ -158,9 +157,9 @@ pub fn create_shares(data: &[u8], n: u8, k: u8) -> SSSResult<Vec<Vec<u8>>> {

let key = rand::random::<[u8; KEY_SIZE]>();
let mut shares = hazmat::create_keyshares(&key, n, k)?;
let mut cipher = XSalsa20Poly1305::new(&key.into());
let cipher = XSalsa20Poly1305::new(&key.into());
let ciphertext = cipher
.encrypt(&[0; xsalsa20poly1305::NONCE_SIZE].into(), data)
.encrypt(&[0; XSalsa20Poly1305::NONCE_SIZE].into(), data)
.expect("xsalsa20poly1305 encryption error");
for share in shares.iter_mut() {
share.extend_from_slice(&ciphertext);
Expand Down Expand Up @@ -220,10 +219,10 @@ pub fn combine_shares(shares: &[Vec<u8>]) -> SSSResult<Option<Vec<u8>>> {
let key_vec = hazmat::combine_keyshares(&keyshares)?;
let mut key = [0; KEY_SIZE];
key.copy_from_slice(&key_vec);
let mut cipher = XSalsa20Poly1305::new(&key.into());
let cipher = XSalsa20Poly1305::new(&key.into());
for share in shares.iter() {
let ciphertext = &share[KEYSHARE_SIZE..];
let nonce = [0; NONCE_SIZE];
let nonce = [0; XSalsa20Poly1305::NONCE_SIZE];
if let Ok(plaintext) = cipher.decrypt(&nonce.into(), ciphertext) {
return Ok(Some(plaintext));
}
Expand Down