Skip to content

Commit

Permalink
make hash2curve module
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Lodder <redmike7@gmail.com>
  • Loading branch information
mikelodder7 committed Jan 7, 2022
1 parent 37bf44a commit ccd8569
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 33 deletions.
4 changes: 2 additions & 2 deletions elliptic-curve/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ zeroize = { version = "1", default-features = false }

# optional dependencies
base64ct = { version = "1", optional = true, default-features = false }
digest_traits = { version = "0.9", optional = true, default-features = false, package = "digest" }
digest = { version = "0.9", optional = true, default-features = false }
ff = { version = "0.11", optional = true, default-features = false }
group = { version = "0.11", optional = true, default-features = false }
hex-literal = { version = "0.3", optional = true }
Expand All @@ -47,7 +47,7 @@ alloc = ["der/alloc", "sec1/alloc", "zeroize/alloc"] # todo: use weak activation
arithmetic = ["ff", "group"]
bits = ["arithmetic", "ff/bits"]
dev = ["arithmetic", "hex-literal", "pem", "pkcs8"]
digest = ["digest_traits", "ff", "group"]
hash2curve = ["digest", "ff", "group"]
ecdh = ["arithmetic"]
hazmat = []
jwk = ["alloc", "base64ct/alloc", "serde", "serde_json", "zeroize/alloc"]
Expand Down
14 changes: 14 additions & 0 deletions elliptic-curve/src/hash2curve.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// Traits for handling hash to curve
mod group_digest;
/// Traits for mapping an isogeny to another curve
/// <https://datatracker.ietf.org/doc/draft-irtf-cfrg-hash-to-curve>
mod isogeny;
/// Traits for mapping field elements to points on the curve
mod map2curve;
/// Optimized simplified Shallue-van de Woestijne-Ulas methods
mod osswu;

pub use group_digest::*;
pub use isogeny::*;
pub use map2curve::*;
pub use osswu::*;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::MapToCurve;
use crate::hash2field::{hash_to_field, ExpandMsg, FromOkm};
use crate::map2curve::MapToCurve;
use group::cofactor::CofactorGroup;

/// Adds hashing arbitrary byte sequences to a valid group element
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion elliptic-curve/src/hash2field/expand_msg.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use digest_traits::{Digest, ExtendableOutputDirty, Update, XofReader};
use digest::{Digest, ExtendableOutputDirty, Update, XofReader};
use generic_array::{ArrayLength, GenericArray};

/// Salt when the DST is too long
Expand Down
10 changes: 8 additions & 2 deletions elliptic-curve/src/hash2field/expand_msg_xmd.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
use super::{Domain, ExpandMsg};
use digest_traits::{
generic_array::{typenum::Unsigned, GenericArray},
use digest::{
generic_array::{
typenum::{IsLess, Unsigned, U256},
GenericArray,
},
BlockInput, Digest,
};

/// Placeholder type for implementing expand_message_xmd based on a hash function
pub struct ExpandMsgXmd<HashT>
where
HashT: Digest + BlockInput,
HashT::OutputSize: IsLess<U256>,
{
b_0: GenericArray<u8, HashT::OutputSize>,
b_vals: GenericArray<u8, HashT::OutputSize>,
Expand All @@ -20,6 +24,7 @@ where
impl<HashT> ExpandMsgXmd<HashT>
where
HashT: Digest + BlockInput,
HashT::OutputSize: IsLess<U256>,
{
fn next(&mut self) -> bool {
if self.index < self.ell {
Expand Down Expand Up @@ -49,6 +54,7 @@ where
impl<HashT> ExpandMsg for ExpandMsgXmd<HashT>
where
HashT: Digest + BlockInput,
HashT::OutputSize: IsLess<U256>,
{
fn expand_message(msg: &[u8], dst: &'static [u8], len_in_bytes: usize) -> Self {
let b_in_bytes = HashT::OutputSize::to_usize();
Expand Down
2 changes: 1 addition & 1 deletion elliptic-curve/src/hash2field/expand_msg_xof.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::ExpandMsg;
use crate::hash2field::Domain;
use digest_traits::{ExtendableOutput, ExtendableOutputDirty, Update, XofReader};
use digest::{ExtendableOutput, ExtendableOutputDirty, Update, XofReader};
use generic_array::typenum::U32;

/// Placeholder type for implementing expand_message_xof based on an extendable output function
Expand Down
32 changes: 7 additions & 25 deletions elliptic-curve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,33 +94,15 @@ pub mod ecdh;
#[cfg(feature = "jwk")]
mod jwk;

/// Optimized simplified Shallue-van de Woestijne-Ulas methods
#[cfg(feature = "digest")]
#[cfg_attr(docsrs, doc(cfg(feature = "digest")))]
pub mod osswu;

/// Traits for computing hash to field as described in
/// <https://datatracker.ietf.org/doc/draft-irtf-cfrg-hash-to-curve>
#[cfg(feature = "digest")]
#[cfg_attr(docsrs, doc(cfg(feature = "digest")))]
/// Traits for hashing to field elements
#[cfg(feature = "hash2curve")]
#[cfg_attr(docsrs, doc(cfg(feature = "hash2curve")))]
pub mod hash2field;

/// Traits for mapping an isogeny to another curve
/// <https://datatracker.ietf.org/doc/draft-irtf-cfrg-hash-to-curve>
#[cfg(feature = "digest")]
#[cfg_attr(docsrs, doc(cfg(feature = "digest")))]
pub mod isogeny;

/// Traits for computing hash to curve as described in
/// <https://datatracker.ietf.org/doc/draft-irtf-cfrg-hash-to-curve>
#[cfg(feature = "digest")]
#[cfg_attr(docsrs, doc(cfg(feature = "digest")))]
pub mod group_digest;

/// Traits for mapping field elements to points on the curve
#[cfg(feature = "digest")]
#[cfg_attr(docsrs, doc(cfg(feature = "digest")))]
pub mod map2curve;
/// Traits for hashing byte sequences to curve points
#[cfg(feature = "hash2curve")]
#[cfg_attr(docsrs, doc(cfg(feature = "hash2curve")))]
pub mod hash2curve;

pub use crate::{
error::{Error, Result},
Expand Down
2 changes: 1 addition & 1 deletion elliptic-curve/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use subtle::CtOption;
use group::Group;

#[cfg(feature = "digest")]
use digest_traits::{BlockInput, Digest, FixedOutput, Reset, Update};
use digest::{BlockInput, Digest, FixedOutput, Reset, Update};

/// Perform an inversion on a field element (i.e. base field element or scalar)
pub trait Invert {
Expand Down

0 comments on commit ccd8569

Please sign in to comment.