Implement RedJubjub

Co-authored-by: Sean Bowe <ewillbefull@gmail.com>
This commit is contained in:
Jack Grigg
2018-04-15 15:59:09 -06:00
parent 0f230a70b9
commit 916dbce2df
3 changed files with 146 additions and 0 deletions

View File

@@ -1,3 +1,7 @@
use blake2_rfc::blake2b::Blake2b;
use jubjub::{JubjubEngine, ToUniform};
pub fn swap_bits_u64(x: u64) -> u64
{
let mut tmp = 0;
@@ -7,6 +11,14 @@ pub fn swap_bits_u64(x: u64) -> u64
tmp
}
pub fn hash_to_scalar<E: JubjubEngine>(persona: &[u8], a: &[u8], b: &[u8]) -> E::Fs {
let mut hasher = Blake2b::with_params(64, &[], &[], persona);
hasher.update(a);
hasher.update(b);
let ret = hasher.finalize();
E::Fs::to_uniform(ret.as_ref())
}
#[test]
fn test_swap_bits_u64() {
assert_eq!(swap_bits_u64(17182120934178543809), 0b1000001100011011110000011000111000101111111001001100111001110111);