From 999b414b31004b54163f2d2106dbc80d180f4929 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 2 Jul 2024 13:27:50 +0200 Subject: [PATCH] Refactor --- src/g1.rs | 4 ++-- src/g2.rs | 6 +++--- src/lib.rs | 2 ++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/g1.rs b/src/g1.rs index 1a85fd9..32f83f8 100644 --- a/src/g1.rs +++ b/src/g1.rs @@ -32,7 +32,7 @@ use pairing::group::{ use rand_core::RngCore; use subtle::{Choice, CtOption}; -use crate::{affine, Affine, Error, Scalar}; +use crate::{affine, Affine, Error, Scalar, RANDOM_DOMAIN_SEPERATOR}; type CompressedSize = U49; type UncompressedSize = U97; @@ -492,7 +492,7 @@ impl Group for G1Projective { fn random(mut rng: impl RngCore) -> Self { let mut buf = [0u8; 64]; rng.fill_bytes(&mut buf); - Self::hash_to_curve(buf, b"randrandrandrandrandrandrandrand") + Self::hash_to_curve(buf, RANDOM_DOMAIN_SEPERATOR) } #[inline] diff --git a/src/g2.rs b/src/g2.rs index f002874..985d32a 100644 --- a/src/g2.rs +++ b/src/g2.rs @@ -28,10 +28,10 @@ use pairing::group::{ prime::{PrimeCurve, PrimeGroup}, Curve, Group, GroupEncoding, UncompressedEncoding, }; +use rand_core::RngCore; use subtle::{Choice, CtOption}; -use crate::{affine, Affine, Error, Scalar}; -use rand_core::RngCore; +use crate::{affine, Affine, Error, Scalar, RANDOM_DOMAIN_SEPERATOR}; type CompressedSize = U97; type UncompressedSize = U193; @@ -491,7 +491,7 @@ impl Group for G2Projective { fn random(mut rng: impl RngCore) -> Self { let mut buf = [0u8; 64]; rng.fill_bytes(&mut buf); - Self::hash_to_curve(buf, b"randrandrandrandrandrandrandrand") + Self::hash_to_curve(buf, RANDOM_DOMAIN_SEPERATOR) } #[inline] diff --git a/src/lib.rs b/src/lib.rs index 04c1da0..e681373 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -221,3 +221,5 @@ mod test { assert_eq!(check, pp); } } + +pub(crate) const RANDOM_DOMAIN_SEPERATOR: &[u8; 32] = b"randrandrandrandrandrandrandrand";