remove sodium as a dep

This commit is contained in:
J. Ayo Akinyele 2019-10-17 15:48:31 -04:00
parent e376f0e43d
commit 8804884979
4 changed files with 32 additions and 50 deletions

View File

@ -16,7 +16,6 @@ rand_xorshift = "0.1"
ff = { git = "https://github.com/boltlabs-inc/ff", branch = "master" }
pairing = { git = "https://github.com/boltlabs-inc/pairing", branch = "master", features = ["serde"] }
bincode = "0.6.1"
sodiumoxide = "0.2.5"
libc = "*"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

View File

@ -15,7 +15,7 @@ use pairing::bls12_381::Bls12;
use ff::PrimeField;
use cl::{BlindKeyPair, KeyPair, Signature, PublicParams, setup};
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 std::collections::HashMap;
use std::fmt::Display;
@ -144,7 +144,7 @@ impl<E: Engine> ChannelToken<E> {
input.extend(&ser_mpk);
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?
@ -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
///

View File

@ -25,7 +25,7 @@ extern crate rand;
extern crate rand_core;
extern crate bincode;
extern crate sodiumoxide;
//extern crate sodiumoxide;
extern crate secp256k1;
extern crate time;
extern crate sha2;
@ -39,7 +39,7 @@ extern crate libc;
extern crate rand_xorshift;
extern crate core;
pub mod sym;
//pub mod sym;
pub mod cl;
pub mod ccs08;
pub mod ped92;
@ -53,9 +53,9 @@ use std::fmt;
use std::str;
use bincode::SizeLimit::Infinite;
use bincode::rustc_serialize::{encode, decode};
use sodiumoxide::randombytes;
use sodiumoxide::crypto::hash::sha512;
use sha2::Sha512;
//use sodiumoxide::randombytes;
//use sodiumoxide::crypto::hash::sha512;
//use sha2::Sha512;
use std::collections::HashMap;
use ff::{Rand, Field};
@ -116,14 +116,14 @@ pub mod bidirectional {
use util;
use wallet;
use pairing::Engine;
use sodiumoxide;
//use sodiumoxide;
use cl;
// for blind signature
use secp256k1;
// for on-chain keys
use HashMap;
use sodiumoxide::crypto::hash::sha512;
use sha2::Sha512;
//use sodiumoxide::crypto::hash::sha512;
//use sha2::Sha512;
use serde::{Serialize, Deserialize};
use util::{RevokedMessage, hash_to_slice};
@ -173,7 +173,7 @@ pub mod bidirectional {
}
pub fn init() {
sodiumoxide::init();
//sodiumoxide::init();
}
///

View File

@ -1,9 +1,10 @@
use super::*;
use sodiumoxide::crypto::hash::sha512;
//use sodiumoxide::crypto::hash::sha512;
use pairing::Engine;
use ff::{PrimeField};
use rand::Rng;
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 {
(a.len() == b.len()) &&
@ -57,24 +58,23 @@ pub fn fmt_bytes_to_int(bytearray: [u8; 64]) -> String {
return s;
}
pub fn hash_to_fr<E: Engine>(byteVec: Vec<u8>) -> E::Fr {
let sha2_digest = sha512::hash(byteVec.as_slice());
pub fn compute_the_hash<E: Engine>(bytes: &Vec<u8>) -> E::Fr {
let mut hasher = sha2::Sha512::new();
hasher.input(&bytes.as_slice());
let sha2_digest = hasher.result();
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();
return E::Fr::from_str(&hexresult).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 {
let x_slice = wpk.serialize_uncompressed();
let sha2_digest = sha512::hash(&x_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();
return compute_the_hash::<E>(&x_slice.to_vec());
}
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 val = E::Fr::from_str(value2.to_string().as_str()).unwrap();
res.sub_assign(&val);
// TODO: look at how to do negation
return res;
}
}
pub fn compute_pub_key_fingerprint(wpk: &secp256k1::PublicKey) -> String {
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]));
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();
input_buf.extend_from_slice(prefix.as_bytes());
input_buf.extend_from_slice(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();
return compute_the_hash::<E>(&input_buf);
}
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];
hash_buf.copy_from_slice(&sha2_digest[0..32]);
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)]
pub struct RevokedMessage {
pub msgtype: String,