mirror of
https://github.com/arnaucube/mimc-rs.git
synced 2026-02-06 19:16:45 +01:00
add padding in constants generation
This commit is contained in:
@@ -5,6 +5,8 @@ authors = ["arnaucube <root@arnaucube.com>"]
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
description = "MIMC7 hash implementation"
|
description = "MIMC7 hash implementation"
|
||||||
|
repository = "https://github.com/arnaucube/mimc-rs"
|
||||||
|
readme = "README.md"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
num = "0.2.0"
|
num = "0.2.0"
|
||||||
|
|||||||
@@ -64,15 +64,22 @@ pub fn get_constants(r: &BigInt, seed: &str, n_rounds: i64) -> Vec<BigInt> {
|
|||||||
|
|
||||||
let mut c = BigInt::from_bytes_be(Sign::Plus, &h);
|
let mut c = BigInt::from_bytes_be(Sign::Plus, &h);
|
||||||
for _ in 1..n_rounds {
|
for _ in 1..n_rounds {
|
||||||
|
let (_, c_bytes) = c.to_bytes_be();
|
||||||
|
let mut c_bytes32: [u8;32] = [0;32];
|
||||||
|
let diff = c_bytes32.len() - c_bytes.len();
|
||||||
|
c_bytes32[diff..].copy_from_slice(&c_bytes[..]);
|
||||||
|
|
||||||
let mut keccak = Keccak::new_keccak256();
|
let mut keccak = Keccak::new_keccak256();
|
||||||
let mut h = [0u8; 32];
|
let mut h = [0u8; 32];
|
||||||
let (_, c_bytes) = c.to_bytes_be();
|
|
||||||
keccak.update(&c_bytes[..]);
|
keccak.update(&c_bytes[..]);
|
||||||
keccak.finalize(&mut h);
|
keccak.finalize(&mut h);
|
||||||
c = BigInt::from_bytes_be(Sign::Plus, &h);
|
c = BigInt::from_bytes_be(Sign::Plus, &h);
|
||||||
|
|
||||||
let n = modulus(&c, &r);
|
let n = modulus(&c, &r);
|
||||||
cts.push(n);
|
cts.push(n);
|
||||||
}
|
}
|
||||||
|
// let l = cts.len();
|
||||||
|
// cts[l-1] = Zero::zero();
|
||||||
cts
|
cts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user