Extract INV_EIGHT constant

This commit is contained in:
Thomas Eizinger 2021-05-11 12:21:10 +10:00
parent a73024ccfc
commit 4933d7f1b7
No known key found for this signature in database
GPG Key ID: 651AC83A6C6C8B96

View File

@ -7,6 +7,8 @@ use tiny_keccak::{Hasher, Keccak};
pub const RING_SIZE: usize = 11;
const INV_EIGHT: Scalar = Scalar::from_bits([121, 47, 220, 226, 41, 229, 6, 97, 208, 218, 28, 125, 179, 157, 211, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6]);
pub fn sign(
msg: &[u8],
signing_key: Scalar,
@ -22,7 +24,7 @@ pub fn sign(
I: EdwardsPoint,
) -> Signature {
let D = z * H_p_pk;
let D_inv_8 = D * Scalar::from(8u8).invert();
let D_inv_8 = D * INV_EIGHT;
let prefix = clsag_round_hash_prefix(
ring.as_ref(),
@ -250,3 +252,15 @@ fn hash_to_scalar(elements: &[&[u8]]) -> Scalar {
Scalar::from_bytes_mod_order(hash)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn const_is_inv_eight() {
let inv_eight = Scalar::from(8u8).invert();
assert_eq!(inv_eight, INV_EIGHT);
}
}