remove sodium as a dep
This commit is contained in:
parent
e376f0e43d
commit
8804884979
|
@ -16,7 +16,6 @@ rand_xorshift = "0.1"
|
||||||
ff = { git = "https://github.com/boltlabs-inc/ff", branch = "master" }
|
ff = { git = "https://github.com/boltlabs-inc/ff", branch = "master" }
|
||||||
pairing = { git = "https://github.com/boltlabs-inc/pairing", branch = "master", features = ["serde"] }
|
pairing = { git = "https://github.com/boltlabs-inc/pairing", branch = "master", features = ["serde"] }
|
||||||
bincode = "0.6.1"
|
bincode = "0.6.1"
|
||||||
sodiumoxide = "0.2.5"
|
|
||||||
libc = "*"
|
libc = "*"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
|
|
@ -15,7 +15,7 @@ use pairing::bls12_381::Bls12;
|
||||||
use ff::PrimeField;
|
use ff::PrimeField;
|
||||||
use cl::{BlindKeyPair, KeyPair, Signature, PublicParams, setup};
|
use cl::{BlindKeyPair, KeyPair, Signature, PublicParams, setup};
|
||||||
use ped92::{CSParams, Commitment, CSMultiParams, CommitmentProof};
|
use ped92::{CSParams, Commitment, CSMultiParams, CommitmentProof};
|
||||||
use util::{hash_pubkey_to_fr, convert_int_to_fr, hash_to_fr, RevokedMessage, hash_to_slice, hash_slice_to_fr};
|
use util::{hash_pubkey_to_fr, convert_int_to_fr, hash_to_fr, RevokedMessage, hash_to_slice};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
@ -144,7 +144,7 @@ impl<E: Engine> ChannelToken<E> {
|
||||||
input.extend(&ser_mpk);
|
input.extend(&ser_mpk);
|
||||||
input.extend(&ser_comParams);
|
input.extend(&ser_comParams);
|
||||||
|
|
||||||
return hash_slice_to_fr::<E>(&input);
|
return hash_to_fr::<E>(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
// add a method to compute hash on chain: SHA256 + RIPEMD160?
|
// add a method to compute hash on chain: SHA256 + RIPEMD160?
|
||||||
|
@ -168,10 +168,6 @@ impl<E: Engine> ChannelState<E> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init() {
|
|
||||||
sodiumoxide::init();
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// keygen - takes as input public parameters and generates a digital signature keypair
|
/// keygen - takes as input public parameters and generates a digital signature keypair
|
||||||
///
|
///
|
||||||
|
|
18
src/lib.rs
18
src/lib.rs
|
@ -25,7 +25,7 @@ extern crate rand;
|
||||||
extern crate rand_core;
|
extern crate rand_core;
|
||||||
|
|
||||||
extern crate bincode;
|
extern crate bincode;
|
||||||
extern crate sodiumoxide;
|
//extern crate sodiumoxide;
|
||||||
extern crate secp256k1;
|
extern crate secp256k1;
|
||||||
extern crate time;
|
extern crate time;
|
||||||
extern crate sha2;
|
extern crate sha2;
|
||||||
|
@ -39,7 +39,7 @@ extern crate libc;
|
||||||
extern crate rand_xorshift;
|
extern crate rand_xorshift;
|
||||||
extern crate core;
|
extern crate core;
|
||||||
|
|
||||||
pub mod sym;
|
//pub mod sym;
|
||||||
pub mod cl;
|
pub mod cl;
|
||||||
pub mod ccs08;
|
pub mod ccs08;
|
||||||
pub mod ped92;
|
pub mod ped92;
|
||||||
|
@ -53,9 +53,9 @@ use std::fmt;
|
||||||
use std::str;
|
use std::str;
|
||||||
use bincode::SizeLimit::Infinite;
|
use bincode::SizeLimit::Infinite;
|
||||||
use bincode::rustc_serialize::{encode, decode};
|
use bincode::rustc_serialize::{encode, decode};
|
||||||
use sodiumoxide::randombytes;
|
//use sodiumoxide::randombytes;
|
||||||
use sodiumoxide::crypto::hash::sha512;
|
//use sodiumoxide::crypto::hash::sha512;
|
||||||
use sha2::Sha512;
|
//use sha2::Sha512;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use ff::{Rand, Field};
|
use ff::{Rand, Field};
|
||||||
|
|
||||||
|
@ -116,14 +116,14 @@ pub mod bidirectional {
|
||||||
use util;
|
use util;
|
||||||
use wallet;
|
use wallet;
|
||||||
use pairing::Engine;
|
use pairing::Engine;
|
||||||
use sodiumoxide;
|
//use sodiumoxide;
|
||||||
use cl;
|
use cl;
|
||||||
// for blind signature
|
// for blind signature
|
||||||
use secp256k1;
|
use secp256k1;
|
||||||
// for on-chain keys
|
// for on-chain keys
|
||||||
use HashMap;
|
use HashMap;
|
||||||
use sodiumoxide::crypto::hash::sha512;
|
//use sodiumoxide::crypto::hash::sha512;
|
||||||
use sha2::Sha512;
|
//use sha2::Sha512;
|
||||||
|
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
use util::{RevokedMessage, hash_to_slice};
|
use util::{RevokedMessage, hash_to_slice};
|
||||||
|
@ -173,7 +173,7 @@ pub mod bidirectional {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init() {
|
pub fn init() {
|
||||||
sodiumoxide::init();
|
//sodiumoxide::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|
55
src/util.rs
55
src/util.rs
|
@ -1,9 +1,10 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
use sodiumoxide::crypto::hash::sha512;
|
//use sodiumoxide::crypto::hash::sha512;
|
||||||
use pairing::Engine;
|
use pairing::Engine;
|
||||||
use ff::{PrimeField};
|
use ff::{PrimeField};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use secp256k1::{Signature, PublicKey};
|
use secp256k1::{Signature, PublicKey};
|
||||||
|
use sha2::{Sha512, Sha256, Digest};
|
||||||
|
|
||||||
pub fn is_vec_fr_equal<E: Engine>(a: &Vec<E::Fr>, b: &Vec<E::Fr>) -> bool {
|
pub fn is_vec_fr_equal<E: Engine>(a: &Vec<E::Fr>, b: &Vec<E::Fr>) -> bool {
|
||||||
(a.len() == b.len()) &&
|
(a.len() == b.len()) &&
|
||||||
|
@ -57,24 +58,23 @@ pub fn fmt_bytes_to_int(bytearray: [u8; 64]) -> String {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hash_to_fr<E: Engine>(byteVec: Vec<u8>) -> E::Fr {
|
pub fn compute_the_hash<E: Engine>(bytes: &Vec<u8>) -> E::Fr {
|
||||||
let sha2_digest = sha512::hash(byteVec.as_slice());
|
let mut hasher = sha2::Sha512::new();
|
||||||
|
hasher.input(&bytes.as_slice());
|
||||||
|
let sha2_digest = hasher.result();
|
||||||
let mut hash_buf: [u8; 64] = [0; 64];
|
let mut hash_buf: [u8; 64] = [0; 64];
|
||||||
hash_buf.copy_from_slice(&sha2_digest[0..64]);
|
hash_buf.copy_from_slice(&sha2_digest[0..64]);
|
||||||
let hexresult = fmt_bytes_to_int(hash_buf);
|
let hexresult = fmt_bytes_to_int(hash_buf);
|
||||||
let result = E::Fr::from_str(&hexresult);
|
return E::Fr::from_str(&hexresult).unwrap();
|
||||||
return result.unwrap();
|
}
|
||||||
|
|
||||||
|
pub fn hash_to_fr<E: Engine>(byteVec: Vec<u8>) -> E::Fr {
|
||||||
|
return compute_the_hash::<E>(&byteVec);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hash_pubkey_to_fr<E: Engine>(wpk: &secp256k1::PublicKey) -> E::Fr {
|
pub fn hash_pubkey_to_fr<E: Engine>(wpk: &secp256k1::PublicKey) -> E::Fr {
|
||||||
let x_slice = wpk.serialize_uncompressed();
|
let x_slice = wpk.serialize_uncompressed();
|
||||||
let sha2_digest = sha512::hash(&x_slice);
|
return compute_the_hash::<E>(&x_slice.to_vec());
|
||||||
|
|
||||||
let mut hash_buf: [u8; 64] = [0; 64];
|
|
||||||
hash_buf.copy_from_slice(&sha2_digest[0..64]);
|
|
||||||
let hexresult = fmt_bytes_to_int(hash_buf);
|
|
||||||
let result = E::Fr::from_str(&hexresult);
|
|
||||||
return result.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn convert_int_to_fr<E: Engine>(value: i64) -> E::Fr {
|
pub fn convert_int_to_fr<E: Engine>(value: i64) -> E::Fr {
|
||||||
|
@ -86,14 +86,16 @@ pub fn convert_int_to_fr<E: Engine>(value: i64) -> E::Fr {
|
||||||
let mut res = E::Fr::zero();
|
let mut res = E::Fr::zero();
|
||||||
let val = E::Fr::from_str(value2.to_string().as_str()).unwrap();
|
let val = E::Fr::from_str(value2.to_string().as_str()).unwrap();
|
||||||
res.sub_assign(&val);
|
res.sub_assign(&val);
|
||||||
// TODO: look at how to do negation
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compute_pub_key_fingerprint(wpk: &secp256k1::PublicKey) -> String {
|
pub fn compute_pub_key_fingerprint(wpk: &secp256k1::PublicKey) -> String {
|
||||||
let x_slice = wpk.serialize();
|
let x_slice = wpk.serialize();
|
||||||
let sha2_digest = sha512::hash(&x_slice);
|
let mut hasher = sha2::Sha512::new();
|
||||||
|
hasher.input(&x_slice.to_vec());
|
||||||
|
let sha2_digest = hasher.result();
|
||||||
|
// let sha2_digest = sha512::hash(&x_slice);
|
||||||
let h = format!("{:x}", HexSlice::new(&sha2_digest[0..16]));
|
let h = format!("{:x}", HexSlice::new(&sha2_digest[0..16]));
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
@ -102,34 +104,19 @@ pub fn hash_buffer_to_fr<'a, E: Engine>(prefix: &'a str, buf: &[u8; 64]) -> E::F
|
||||||
let mut input_buf = Vec::new();
|
let mut input_buf = Vec::new();
|
||||||
input_buf.extend_from_slice(prefix.as_bytes());
|
input_buf.extend_from_slice(prefix.as_bytes());
|
||||||
input_buf.extend_from_slice(buf);
|
input_buf.extend_from_slice(buf);
|
||||||
|
return compute_the_hash::<E>(&input_buf);
|
||||||
let sha2_digest = sha512::hash(&input_buf.as_slice());
|
|
||||||
|
|
||||||
let mut hash_buf: [u8; 64] = [0; 64];
|
|
||||||
hash_buf.copy_from_slice(&sha2_digest[0..64]);
|
|
||||||
let hexresult = fmt_bytes_to_int(hash_buf);
|
|
||||||
let result = E::Fr::from_str(&hexresult);
|
|
||||||
return result.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hash_to_slice(input_buf: &Vec<u8>) -> [u8; 32] {
|
pub fn hash_to_slice(input_buf: &Vec<u8>) -> [u8; 32] {
|
||||||
let sha2_digest = sha512::hash(input_buf.as_slice());
|
let mut hasher = sha2::Sha512::new();
|
||||||
|
hasher.input(&input_buf.as_slice());
|
||||||
|
let sha2_digest = hasher.result();
|
||||||
|
|
||||||
let mut hash_buf: [u8; 32] = [0; 32];
|
let mut hash_buf: [u8; 32] = [0; 32];
|
||||||
hash_buf.copy_from_slice(&sha2_digest[0..32]);
|
hash_buf.copy_from_slice(&sha2_digest[0..32]);
|
||||||
return hash_buf;
|
return hash_buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hash_slice_to_fr<E: Engine>(input_buf: &Vec<u8>) -> E::Fr {
|
|
||||||
let sha2_digest = sha512::hash(input_buf.as_slice());
|
|
||||||
let mut hash_buf: [u8; 64] = [0; 64];
|
|
||||||
hash_buf.copy_from_slice(&sha2_digest[0..64]);
|
|
||||||
let hexresult = fmt_bytes_to_int(hash_buf);
|
|
||||||
let result = E::Fr::from_str(&hexresult);
|
|
||||||
return result.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Serialize, Deserialize)]
|
#[derive(Clone, Serialize, Deserialize)]
|
||||||
pub struct RevokedMessage {
|
pub struct RevokedMessage {
|
||||||
pub msgtype: String,
|
pub msgtype: String,
|
||||||
|
|
Loading…
Reference in New Issue