feat: new merge method for 2 digest with a domain separator
Signed-off-by: 0xKanekiKen <100861945+0xKanekiKen@users.noreply.github.com>
This commit is contained in:
parent
f51d6b78aa
commit
bc6191b3fa
1 changed files with 22 additions and 0 deletions
|
@ -294,6 +294,28 @@ impl Rpo256 {
|
||||||
<Self as ElementHasher>::hash_elements(elements)
|
<Self as ElementHasher>::hash_elements(elements)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DOMAIN IDENTIFIER
|
||||||
|
// --------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/// Returns a hash of two digests and a domain separator.
|
||||||
|
pub fn merge_in_domain(values: &[RpoDigest; 2], domain: Felt) -> RpoDigest {
|
||||||
|
// initialize the state by copying the digest elements into the rate portion of the state
|
||||||
|
// (8 total elements), and set the capacity elements to 0.
|
||||||
|
let mut state = [ZERO; STATE_WIDTH];
|
||||||
|
let it = RpoDigest::digests_as_elements(values.iter());
|
||||||
|
for (i, v) in it.enumerate() {
|
||||||
|
state[RATE_RANGE.start + i] = *v;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set the second capacity element to the domain value. The first capacity element is used
|
||||||
|
// for padding purposes.
|
||||||
|
state[CAPACITY_RANGE.start + 1] = domain;
|
||||||
|
|
||||||
|
// apply the RPO permutation and return the first four elements of the state
|
||||||
|
Self::apply_permutation(&mut state);
|
||||||
|
RpoDigest::new(state[DIGEST_RANGE].try_into().unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
// RESCUE PERMUTATION
|
// RESCUE PERMUTATION
|
||||||
// --------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue