From 1dd3744c4f9930d1916a1709933fdb2555dd565b Mon Sep 17 00:00:00 2001 From: Xavier DMello Date: Wed, 3 Jul 2024 18:28:53 -0700 Subject: [PATCH 1/3] arrr --- Cargo.toml | 8 +++++++- src/g2.rs | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 8c5fc6ce..056da627 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ edition = "2021" rustdoc-args = [ "--html-in-header", "katex-header.html" ] [dependencies] +sha2 = "0.9.9" sp1_precompiles = { git = "https://github.com/succinctlabs/sp1.git", package = "sp1-precompiles" } [dev-dependencies] @@ -67,10 +68,15 @@ default-features = false optional = true [features] -default = ["groups", "pairings", "alloc", "bits"] +default = ["groups", "pairings", "alloc", "bits", "experimental"] bits = ["ff/bits"] groups = ["group"] pairings = ["groups", "pairing"] alloc = ["group/alloc"] experimental = ["digest"] nightly = ["subtle/nightly"] + +[patch.crates-io] +sha2-v0-9-9 = { git = "https://github.com/sp1-patches/RustCrypto-hashes", package = "sha2", branch = "patch-sha2-v0.9.9" } +sha2-v0-10-8 = { git = "https://github.com/sp1-patches/RustCrypto-hashes", package = "sha2", branch = "patch-sha2-v0.10.8" } +tiny-keccak = { git = "https://github.com/sp1-patches/tiny-keccak", branch = "patch-v2.0.2" } \ No newline at end of file diff --git a/src/g2.rs b/src/g2.rs index 68415ea8..1bd543a9 100644 --- a/src/g2.rs +++ b/src/g2.rs @@ -10,6 +10,8 @@ use group::{ }; use rand_core::RngCore; use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption}; +use crate::hash_to_curve::{ExpandMsgXmd, HashToCurve}; +use sha2; #[cfg(feature = "alloc")] use group::WnafGroup; @@ -37,6 +39,9 @@ impl Default for G2Affine { G2Affine::identity() } } +const DST: &[u8] = b"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_"; + + #[cfg(feature = "zeroize")] impl zeroize::DefaultIsZeroes for G2Affine {} @@ -664,6 +669,11 @@ impl G2Projective { z: Fp2::zero(), } } + + /// Hash a message to the curve + pub fn hash_to_curve_g2(msg: &[u8]) -> G2Projective { + >>::hash_to_curve(msg, DST) + } /// Returns a fixed generator of the group. See [`notes::design`](notes/design/index.html#fixed-generators) /// for how this generator is chosen. From f5921d60e85159e7a6b368746d638ffa7eb08028 Mon Sep 17 00:00:00 2001 From: Xavier DMello Date: Wed, 3 Jul 2024 19:03:48 -0700 Subject: [PATCH 2/3] dsadsa --- src/g1.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/g1.rs b/src/g1.rs index bb28e290..df27c93f 100644 --- a/src/g1.rs +++ b/src/g1.rs @@ -4,15 +4,15 @@ use core::borrow::Borrow; use core::fmt; use core::iter::Sum; use core::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign}; +#[cfg(feature = "alloc")] +use group::WnafGroup; use group::{ prime::{PrimeCurve, PrimeCurveAffine, PrimeGroup}, Curve, Group, GroupEncoding, UncompressedEncoding, }; use rand_core::RngCore; -use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption}; use sp1_precompiles::bls12381::decompress_pubkey; -#[cfg(feature = "alloc")] -use group::WnafGroup; +use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption}; use crate::fp::Fp; use crate::Scalar; From 47dc6d09343e1d5e98e364a99e3bd3017326be35 Mon Sep 17 00:00:00 2001 From: Xavier DMello Date: Fri, 5 Jul 2024 12:48:40 -0700 Subject: [PATCH 3/3] g2 --- src/g2.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/g2.rs b/src/g2.rs index 1bd543a9..22b34759 100644 --- a/src/g2.rs +++ b/src/g2.rs @@ -1,5 +1,6 @@ //! This module provides an implementation of the $\mathbb{G}_2$ group of BLS12-381. +use crate::hash_to_curve::{ExpandMsgXmd, HashToCurve}; use core::borrow::Borrow; use core::fmt; use core::iter::Sum; @@ -9,9 +10,8 @@ use group::{ Curve, Group, GroupEncoding, UncompressedEncoding, }; use rand_core::RngCore; -use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption}; -use crate::hash_to_curve::{ExpandMsgXmd, HashToCurve}; use sha2; +use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption}; #[cfg(feature = "alloc")] use group::WnafGroup; @@ -39,9 +39,7 @@ impl Default for G2Affine { G2Affine::identity() } } -const DST: &[u8] = b"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_"; - - +const DST: &[u8] = b"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_"; #[cfg(feature = "zeroize")] impl zeroize::DefaultIsZeroes for G2Affine {} @@ -669,7 +667,7 @@ impl G2Projective { z: Fp2::zero(), } } - + /// Hash a message to the curve pub fn hash_to_curve_g2(msg: &[u8]) -> G2Projective { >>::hash_to_curve(msg, DST)