Skip to content

Commit

Permalink
import blake2b_simd and shorten personalization msg
Browse files Browse the repository at this point in the history
  • Loading branch information
hanyunx committed Apr 27, 2022
1 parent 8e60631 commit bb2bd53
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/threshold-bls-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ rand_chacha = { version = "0.3.1", default-features = false }

bincode = { version = "1.2.1", default-features = false }
serde = { version = "1.0.106", default-features = false }
blake2b_simd = { version = "1.0.0", default-features = false }


# Required for WASM interface
blake2 = { version = "0.10", default-features = false, optional = true }
Expand Down
12 changes: 9 additions & 3 deletions crates/threshold-bls-ffi/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use rand_chacha::ChaChaRng;
use rand_core::{RngCore, SeedableRng};

use blake2b_simd::Params;
use serde::{de::DeserializeOwned, Serialize};
use threshold_bls::{
poly::{Idx as Index, Poly},
Expand Down Expand Up @@ -581,7 +582,12 @@ pub unsafe extern "C" fn destroy_sig(signature: *mut Signature) {
///
/// The seed MUST be at least 32 bytes long
#[no_mangle]
pub unsafe extern "C" fn threshold_keygen(n: usize, t: usize, seed: *const Buffer, keys: *mut *mut Keys) {
pub unsafe extern "C" fn threshold_keygen(
n: usize,
t: usize,
seed: *const Buffer,
keys: *mut *mut Keys,
) {
let seed = <&[u8]>::from(unsafe { &*seed });
let mut rng = get_rng(seed);
let private = Poly::<PrivateKey>::new_from(t - 1, &mut rng);
Expand Down Expand Up @@ -713,13 +719,13 @@ fn from_slice(bytes: &[u8]) -> [u8; 32] {
let mut array = [0; 32];
let hash_result = Params::new()
.hash_length(32)
.personal(b"THRESHOLD BLS_rng") // personalization
.personal(b"BLS_rng") // personalization
.to_state()
.update(bytes) // digest
.finalize()
.as_ref()
.to_vec();
array.copy_from_slice(hash_result);
array.copy_from_slice(&hash_result);
array
}

Expand Down
2 changes: 1 addition & 1 deletion crates/threshold-bls-ffi/src/wasm.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! # BLS12-377 WASM Bindings for Blind Threshold Signatures.
use wasm_bindgen::prelude::*;

use blake2::{Blake2s256, Digest};
use rand_chacha::ChaChaRng;
use rand_core::{RngCore, SeedableRng};
use blake2::{Blake2s256, Digest};

use threshold_bls::{
poly::{Idx as Index, Poly},
Expand Down

0 comments on commit bb2bd53

Please sign in to comment.