Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 11 additions & 8 deletions k256/src/arithmetic/hash2curve.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use elliptic_curve::Field;
use elliptic_curve::array::Array;
use elliptic_curve::bigint::{ArrayEncoding, U256};
use elliptic_curve::consts::{U4, U48};
use elliptic_curve::consts::{U4, U16, U48};
use elliptic_curve::group::cofactor::CofactorGroup;
use elliptic_curve::hash2curve::{
FromOkm, GroupDigest, Isogeny, IsogenyCoefficients, MapToCurve, OsswuMap, OsswuMapParams, Sgn0,
Expand All @@ -14,6 +14,8 @@ use super::FieldElement;

impl GroupDigest for Secp256k1 {
type FieldElement = FieldElement;

type K = U16;
}

impl FromOkm for FieldElement {
Expand Down Expand Up @@ -367,11 +369,10 @@ mod tests {
for test_vector in TEST_VECTORS {
// in parts
let mut u = [FieldElement::default(), FieldElement::default()];
hash2curve::hash_to_field::<ExpandMsgXmd<Sha256>, FieldElement>(
&[test_vector.msg],
&[DST],
&mut u,
)
hash2curve::hash_to_field::<
ExpandMsgXmd<Sha256, <Secp256k1 as GroupDigest>::K>,
FieldElement,
>(&[test_vector.msg], &[DST], &mut u)
.unwrap();
assert_eq!(u[0].to_bytes().as_slice(), test_vector.u_0);
assert_eq!(u[1].to_bytes().as_slice(), test_vector.u_1);
Expand All @@ -392,8 +393,10 @@ mod tests {
assert_eq!(ap.y.to_bytes().as_slice(), test_vector.p_y);

// complete run
let pt = Secp256k1::hash_from_bytes::<ExpandMsgXmd<Sha256>>(&[test_vector.msg], &[DST])
.unwrap();
let pt = Secp256k1::hash_from_bytes::<
ExpandMsgXmd<Sha256, <Secp256k1 as GroupDigest>::K>,
>(&[test_vector.msg], &[DST])
.unwrap();
let apt = pt.to_affine();
assert_eq!(apt.x.to_bytes().as_slice(), test_vector.p_x);
assert_eq!(apt.y.to_bytes().as_slice(), test_vector.p_y);
Expand Down
40 changes: 23 additions & 17 deletions p256/src/arithmetic/hash2curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ use crate::{AffinePoint, FieldBytes, NistP256, ProjectivePoint, Scalar};
use elliptic_curve::{
array::Array,
bigint::{ArrayEncoding, U256},
consts::U48,
consts::{U16, U48},
hash2curve::{FromOkm, GroupDigest, MapToCurve, OsswuMap, OsswuMapParams, Sgn0},
point::DecompressPoint,
subtle::Choice,
};

impl GroupDigest for NistP256 {
type FieldElement = FieldElement;

type K = U16;
}

impl FromOkm for FieldElement {
Expand Down Expand Up @@ -201,11 +203,10 @@ mod tests {
for test_vector in TEST_VECTORS {
// in parts
let mut u = [FieldElement::default(), FieldElement::default()];
hash2curve::hash_to_field::<ExpandMsgXmd<Sha256>, FieldElement>(
&[test_vector.msg],
&[DST],
&mut u,
)
hash2curve::hash_to_field::<
ExpandMsgXmd<Sha256, <NistP256 as GroupDigest>::K>,
FieldElement,
>(&[test_vector.msg], &[DST], &mut u)
.unwrap();

/// Assert that the provided projective point matches the given test vector.
Expand Down Expand Up @@ -236,7 +237,11 @@ mod tests {
assert_point_eq!(p, test_vector.p_x, test_vector.p_y);

// complete run
let pt = NistP256::hash_from_bytes::<ExpandMsgXmd<Sha256>>(&[test_vector.msg], &[DST])
let pt =
NistP256::hash_from_bytes::<ExpandMsgXmd<Sha256, <NistP256 as GroupDigest>::K>>(
&[test_vector.msg],
&[DST],
)
.unwrap();
assert_point_eq!(pt, test_vector.p_x, test_vector.p_y);
}
Expand Down Expand Up @@ -279,16 +284,17 @@ mod tests {
.to_be_bytes();

for counter in 0_u8..=u8::MAX {
let scalar = NistP256::hash_to_scalar::<ExpandMsgXmd<Sha256>>(
&[
test_vector.seed,
&key_info_len,
test_vector.key_info,
&counter.to_be_bytes(),
],
&[test_vector.dst],
)
.unwrap();
let scalar =
NistP256::hash_to_scalar::<ExpandMsgXmd<Sha256, <NistP256 as GroupDigest>::K>>(
&[
test_vector.seed,
&key_info_len,
test_vector.key_info,
&counter.to_be_bytes(),
],
&[test_vector.dst],
)
.unwrap();

if !bool::from(scalar.is_zero()) {
assert_eq!(scalar.to_bytes().as_slice(), test_vector.sk_sm);
Expand Down
40 changes: 23 additions & 17 deletions p384/src/arithmetic/hash2curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{AffinePoint, FieldBytes, NistP384, ProjectivePoint, Scalar};
use elliptic_curve::{
array::Array,
bigint::{ArrayEncoding, U384},
consts::U72,
consts::{U24, U72},
hash2curve::{FromOkm, GroupDigest, MapToCurve, OsswuMap, OsswuMapParams, Sgn0},
ops::Reduce,
point::DecompressPoint,
Expand All @@ -12,6 +12,8 @@ use elliptic_curve::{

impl GroupDigest for NistP384 {
type FieldElement = FieldElement;

type K = U24;
}

impl FromOkm for FieldElement {
Expand Down Expand Up @@ -203,11 +205,10 @@ mod tests {
for test_vector in TEST_VECTORS {
// in parts
let mut u = [FieldElement::default(), FieldElement::default()];
hash2curve::hash_to_field::<ExpandMsgXmd<Sha384>, FieldElement>(
&[test_vector.msg],
&[DST],
&mut u,
)
hash2curve::hash_to_field::<
ExpandMsgXmd<Sha384, <NistP384 as GroupDigest>::K>,
FieldElement,
>(&[test_vector.msg], &[DST], &mut u)
.unwrap();

/// Assert that the provided projective point matches the given test vector.
Expand Down Expand Up @@ -238,7 +239,11 @@ mod tests {
assert_point_eq!(p, test_vector.p_x, test_vector.p_y);

// complete run
let pt = NistP384::hash_from_bytes::<ExpandMsgXmd<Sha384>>(&[test_vector.msg], &[DST])
let pt =
NistP384::hash_from_bytes::<ExpandMsgXmd<Sha384, <NistP384 as GroupDigest>::K>>(
&[test_vector.msg],
&[DST],
)
.unwrap();
assert_point_eq!(pt, test_vector.p_x, test_vector.p_y);
}
Expand Down Expand Up @@ -287,16 +292,17 @@ mod tests {
.to_be_bytes();

for counter in 0_u8..=u8::MAX {
let scalar = NistP384::hash_to_scalar::<ExpandMsgXmd<Sha384>>(
&[
test_vector.seed,
&key_info_len,
test_vector.key_info,
&counter.to_be_bytes(),
],
&[test_vector.dst],
)
.unwrap();
let scalar =
NistP384::hash_to_scalar::<ExpandMsgXmd<Sha384, <NistP384 as GroupDigest>::K>>(
&[
test_vector.seed,
&key_info_len,
test_vector.key_info,
&counter.to_be_bytes(),
],
&[test_vector.dst],
)
.unwrap();

if !bool::from(scalar.is_zero()) {
assert_eq!(scalar.to_bytes().as_slice(), test_vector.sk_sm);
Expand Down
40 changes: 23 additions & 17 deletions p521/src/arithmetic/hash2curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{AffinePoint, NistP521, ProjectivePoint, Scalar};
use elliptic_curve::{
array::Array,
bigint::{ArrayEncoding, U576},
consts::U98,
consts::{U32, U98},
hash2curve::{FromOkm, GroupDigest, MapToCurve, OsswuMap, OsswuMapParams, Sgn0},
ops::Reduce,
point::DecompressPoint,
Expand All @@ -12,6 +12,8 @@ use elliptic_curve::{

impl GroupDigest for NistP521 {
type FieldElement = FieldElement;

type K = U32;
}

impl FromOkm for FieldElement {
Expand Down Expand Up @@ -209,11 +211,10 @@ mod tests {
for test_vector in TEST_VECTORS {
// in parts
let mut u = [FieldElement::default(), FieldElement::default()];
hash2curve::hash_to_field::<ExpandMsgXmd<Sha512>, FieldElement>(
&[test_vector.msg],
&[DST],
&mut u,
)
hash2curve::hash_to_field::<
ExpandMsgXmd<Sha512, <NistP521 as GroupDigest>::K>,
FieldElement,
>(&[test_vector.msg], &[DST], &mut u)
.unwrap();

/// Assert that the provided projective point matches the given test vector.
Expand Down Expand Up @@ -244,7 +245,11 @@ mod tests {
assert_point_eq!(p, test_vector.p_x, test_vector.p_y);

// complete run
let pt = NistP521::hash_from_bytes::<ExpandMsgXmd<Sha512>>(&[test_vector.msg], &[DST])
let pt =
NistP521::hash_from_bytes::<ExpandMsgXmd<Sha512, <NistP521 as GroupDigest>::K>>(
&[test_vector.msg],
&[DST],
)
.unwrap();
assert_point_eq!(pt, test_vector.p_x, test_vector.p_y);
}
Expand Down Expand Up @@ -293,16 +298,17 @@ mod tests {
.to_be_bytes();

for counter in 0_u8..=u8::MAX {
let scalar = NistP521::hash_to_scalar::<ExpandMsgXmd<Sha512>>(
&[
test_vector.seed,
&key_info_len,
test_vector.key_info,
&counter.to_be_bytes(),
],
&[test_vector.dst],
)
.unwrap();
let scalar =
NistP521::hash_to_scalar::<ExpandMsgXmd<Sha512, <NistP521 as GroupDigest>::K>>(
&[
test_vector.seed,
&key_info_len,
test_vector.key_info,
&counter.to_be_bytes(),
],
&[test_vector.dst],
)
.unwrap();

if !bool::from(scalar.is_zero()) {
assert_eq!(scalar.to_bytes().as_slice(), test_vector.sk_sm);
Expand Down