Skip to content

Commit

Permalink
Merge branch 'main' into multicore
Browse files Browse the repository at this point in the history
  • Loading branch information
CPerezz authored Jan 4, 2024
2 parents 87c9c61 + 534da5b commit 8b8ab37
Show file tree
Hide file tree
Showing 7 changed files with 318 additions and 91 deletions.
28 changes: 24 additions & 4 deletions src/hash_to_curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use pasta_curves::arithmetic::CurveExt;
use static_assertions::const_assert;
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};

use crate::ff_ext::Legendre;
use crate::{
ff_ext::Legendre,
secp256k1::{iso_map_secp256k1, IsoSecp256k1, Secp256k1},
};

/// Hashes over a message and writes the output to all of `buf`.
/// Modified from https://github.com/zcash/pasta_curves/blob/7e3fc6a4919f6462a32b79dd226cb2587b7961eb/src/hashtocurve.rs#L11.
Expand Down Expand Up @@ -87,7 +90,7 @@ fn hash_to_field<F: FromUniformBytes<64>>(

// Implementation of <https://datatracker.ietf.org/doc/html/rfc9380#name-simplified-swu-method>
#[allow(clippy::too_many_arguments)]
pub(crate) fn simple_svdw_map_to_curve<C>(u: C::Base, z: C::Base) -> C
pub(crate) fn sswu_map_to_curve<C>(u: C::Base, z: C::Base) -> C
where
C: CurveExt,
{
Expand Down Expand Up @@ -151,8 +154,9 @@ where
C::new_jacobian(x, y, one).unwrap()
}

// Implementation of <https://datatracker.ietf.org/doc/html/rfc9380#name-simplified-swu-method>
#[allow(clippy::type_complexity)]
pub(crate) fn simple_svdw_hash_to_curve<'a, C>(
pub(crate) fn sswu_hash_to_curve<'a, C>(
curve_id: &'static str,
domain_prefix: &'a str,
z: C::Base,
Expand All @@ -165,14 +169,30 @@ where
let mut us = [C::Base::ZERO; 2];
hash_to_field("SSWU", curve_id, domain_prefix, message, &mut us);

let [q0, q1]: [C; 2] = us.map(|u| simple_svdw_map_to_curve(u, z));
let [q0, q1]: [C; 2] = us.map(|u| sswu_map_to_curve::<C>(u, z));

let r = q0 + &q1;
debug_assert!(bool::from(r.is_on_curve()));
r
})
}

// Implementation of <https://datatracker.ietf.org/doc/html/rfc9380#name-simplified-swu-for-ab-0>
#[allow(clippy::type_complexity)]
pub(crate) fn sswu_hash_to_curve_secp256k1<'a>(
_curve_id: &'static str,
domain_prefix: &'a str,
) -> Box<dyn Fn(&[u8]) -> Secp256k1 + 'a> {
Box::new(move |message| {
let rp = IsoSecp256k1::hash_to_curve(domain_prefix)(message);

let r = iso_map_secp256k1(rp);

debug_assert!(bool::from(r.is_on_curve()));
r
})
}

#[allow(clippy::too_many_arguments)]
pub(crate) fn svdw_map_to_curve<C>(
u: C::Base,
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub mod secp256k1;
pub mod secp256r1;
pub mod secq256k1;

pub mod utils;

#[macro_use]
mod derive;

Expand Down
Loading

0 comments on commit 8b8ab37

Please sign in to comment.