From 1b8f13fe8a2f111194c2933edbee9915bbb6f8ef Mon Sep 17 00:00:00 2001 From: daxpedda Date: Tue, 27 May 2025 23:55:09 +0200 Subject: [PATCH] Update to `ExpandMsg` changes --- .github/workflows/p256.yml | 4 ++-- .github/workflows/p384.yml | 4 ++-- Cargo.lock | 4 ++-- k256/src/arithmetic/hash2curve.rs | 9 ++++----- p256/Cargo.toml | 2 +- p256/src/arithmetic/hash2curve.rs | 30 +++++++++++++----------------- p256/src/lib.rs | 11 ++++------- p384/Cargo.toml | 2 +- p384/src/arithmetic/hash2curve.rs | 30 +++++++++++++----------------- p384/src/lib.rs | 11 ++++------- p521/Cargo.toml | 2 +- p521/src/arithmetic/hash2curve.rs | 30 +++++++++++++----------------- p521/src/lib.rs | 11 ++++------- 13 files changed, 64 insertions(+), 86 deletions(-) diff --git a/.github/workflows/p256.yml b/.github/workflows/p256.yml index ac4aa4f8b..43dc8e997 100644 --- a/.github/workflows/p256.yml +++ b/.github/workflows/p256.yml @@ -44,12 +44,12 @@ jobs: - run: cargo build --target ${{ matrix.target }} --release --no-default-features --features ecdsa - run: cargo build --target ${{ matrix.target }} --release --no-default-features --features hash2curve - run: cargo build --target ${{ matrix.target }} --release --no-default-features --features jwk + - run: cargo build --target ${{ matrix.target }} --release --no-default-features --features oprf - run: cargo build --target ${{ matrix.target }} --release --no-default-features --features pem - run: cargo build --target ${{ matrix.target }} --release --no-default-features --features pkcs8 - run: cargo build --target ${{ matrix.target }} --release --no-default-features --features serde - run: cargo build --target ${{ matrix.target }} --release --no-default-features --features sha256 - - run: cargo build --target ${{ matrix.target }} --release --no-default-features --features voprf - - run: cargo build --target ${{ matrix.target }} --release --no-default-features --features arithmetic,bits,ecdh,ecdsa,hash2curve,jwk,pem,pkcs8,serde,sha256,voprf + - run: cargo build --target ${{ matrix.target }} --release --no-default-features --features arithmetic,bits,ecdh,ecdsa,hash2curve,jwk,oprf,pem,pkcs8,serde,sha256 benches: runs-on: ubuntu-latest diff --git a/.github/workflows/p384.yml b/.github/workflows/p384.yml index 1e4b201f4..6ea918a3e 100644 --- a/.github/workflows/p384.yml +++ b/.github/workflows/p384.yml @@ -41,12 +41,12 @@ jobs: - run: cargo build --target ${{ matrix.target }} --release --no-default-features --features ecdsa-core - run: cargo build --target ${{ matrix.target }} --release --no-default-features --features hash2curve - run: cargo build --target ${{ matrix.target }} --release --no-default-features --features jwk + - run: cargo build --target ${{ matrix.target }} --release --no-default-features --features oprf - run: cargo build --target ${{ matrix.target }} --release --no-default-features --features pem - run: cargo build --target ${{ matrix.target }} --release --no-default-features --features pkcs8 - run: cargo build --target ${{ matrix.target }} --release --no-default-features --features serde - run: cargo build --target ${{ matrix.target }} --release --no-default-features --features sha384 - - run: cargo build --target ${{ matrix.target }} --release --no-default-features --features voprf - - run: cargo build --target ${{ matrix.target }} --release --no-default-features --features ecdsa-core,hash2curve,jwk,pem,pkcs8,serde,sha384,voprf + - run: cargo build --target ${{ matrix.target }} --release --no-default-features --features ecdsa-core,hash2curve,jwk,oprf,pem,pkcs8,serde,sha384 benches: runs-on: ubuntu-latest diff --git a/Cargo.lock b/Cargo.lock index 79a22bba1..59b8509a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -331,7 +331,7 @@ dependencies = [ [[package]] name = "crypto-common" version = "0.2.0-rc.2" -source = "git+https://github.com/RustCrypto/traits.git#4de33de9409d6534501c3d390a3051618482a419" +source = "git+https://github.com/RustCrypto/traits.git#e728ece19cb5df8d8a7f575c4676a323d449a885" dependencies = [ "hybrid-array", ] @@ -382,7 +382,7 @@ checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" [[package]] name = "elliptic-curve" version = "0.14.0-rc.1" -source = "git+https://github.com/RustCrypto/traits.git#4de33de9409d6534501c3d390a3051618482a419" +source = "git+https://github.com/RustCrypto/traits.git#e728ece19cb5df8d8a7f575c4676a323d449a885" dependencies = [ "base16ct", "base64ct", diff --git a/k256/src/arithmetic/hash2curve.rs b/k256/src/arithmetic/hash2curve.rs index 850a43aa8..af62e4126 100644 --- a/k256/src/arithmetic/hash2curve.rs +++ b/k256/src/arithmetic/hash2curve.rs @@ -355,7 +355,8 @@ mod tests { // in parts let mut u = [FieldElement::default(), FieldElement::default()]; hash2curve::hash_to_field::< - ExpandMsgXmd::K>, + ExpandMsgXmd, + ::K, FieldElement, >(&[test_vector.msg], &[DST], &mut u) .unwrap(); @@ -378,10 +379,8 @@ mod tests { assert_eq!(ap.y.to_bytes().as_slice(), test_vector.p_y); // complete run - let pt = Secp256k1::hash_from_bytes::< - ExpandMsgXmd::K>, - >(&[test_vector.msg], &[DST]) - .unwrap(); + let pt = Secp256k1::hash_from_bytes::>(&[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); diff --git a/p256/Cargo.toml b/p256/Cargo.toml index 14ce56791..de8685d0f 100644 --- a/p256/Cargo.toml +++ b/p256/Cargo.toml @@ -51,12 +51,12 @@ ecdsa = ["arithmetic", "ecdsa-core/signing", "ecdsa-core/verifying", "sha256"] expose-field = ["arithmetic"] hash2curve = ["arithmetic", "elliptic-curve/hash2curve"] jwk = ["elliptic-curve/jwk"] +oprf = ["hash2curve", "elliptic-curve/oprf", "sha2"] pem = ["elliptic-curve/pem", "ecdsa-core/pem", "pkcs8"] pkcs8 = ["ecdsa-core?/pkcs8", "elliptic-curve/pkcs8"] serde = ["ecdsa-core?/serde", "elliptic-curve/serde", "primeorder?/serde", "serdect"] sha256 = ["digest", "sha2"] test-vectors = ["dep:hex-literal"] -voprf = ["hash2curve", "elliptic-curve/voprf", "sha2"] [package.metadata.docs.rs] all-features = true diff --git a/p256/src/arithmetic/hash2curve.rs b/p256/src/arithmetic/hash2curve.rs index 7ff51e496..fc5c249eb 100644 --- a/p256/src/arithmetic/hash2curve.rs +++ b/p256/src/arithmetic/hash2curve.rs @@ -206,7 +206,8 @@ mod tests { // in parts let mut u = [FieldElement::default(), FieldElement::default()]; hash2curve::hash_to_field::< - ExpandMsgXmd::K>, + ExpandMsgXmd, + ::K, FieldElement, >(&[test_vector.msg], &[DST], &mut u) .unwrap(); @@ -239,11 +240,7 @@ mod tests { assert_point_eq!(p, test_vector.p_x, test_vector.p_y); // complete run - let pt = - NistP256::hash_from_bytes::::K>>( - &[test_vector.msg], - &[DST], - ) + let pt = NistP256::hash_from_bytes::>(&[test_vector.msg], &[DST]) .unwrap(); assert_point_eq!(pt, test_vector.p_x, test_vector.p_y); } @@ -286,17 +283,16 @@ mod tests { .to_be_bytes(); for counter in 0_u8..=u8::MAX { - let scalar = - NistP256::hash_to_scalar::::K>>( - &[ - test_vector.seed, - &key_info_len, - test_vector.key_info, - &counter.to_be_bytes(), - ], - &[test_vector.dst], - ) - .unwrap(); + let scalar = NistP256::hash_to_scalar::>( + &[ + 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); diff --git a/p256/src/lib.rs b/p256/src/lib.rs index c27593b22..54fe7e124 100644 --- a/p256/src/lib.rs +++ b/p256/src/lib.rs @@ -171,18 +171,15 @@ impl elliptic_curve::sec1::ValidatePublicKey for NistP256 {} #[cfg(feature = "bits")] pub type ScalarBits = elliptic_curve::scalar::ScalarBits; -#[cfg(feature = "voprf")] -impl elliptic_curve::VoprfParameters for NistP256 { +#[cfg(feature = "oprf")] +impl elliptic_curve::OprfParameters for NistP256 { /// See . - const ID: &'static str = "P256-SHA256"; + const ID: &'static [u8] = b"P256-SHA256"; /// See . type Hash = sha2::Sha256; /// See /// and . - type ExpandMsg = elliptic_curve::hash2curve::ExpandMsgXmd< - sha2::Sha256, - ::K, - >; + type ExpandMsg = elliptic_curve::hash2curve::ExpandMsgXmd; } diff --git a/p384/Cargo.toml b/p384/Cargo.toml index 9cb636984..fb8936c25 100644 --- a/p384/Cargo.toml +++ b/p384/Cargo.toml @@ -55,12 +55,12 @@ ecdsa = ["arithmetic", "ecdsa-core/signing", "ecdsa-core/verifying", "sha384"] expose-field = ["arithmetic"] hash2curve = ["arithmetic", "elliptic-curve/hash2curve"] jwk = ["elliptic-curve/jwk"] +oprf = ["hash2curve", "elliptic-curve/oprf", "sha2"] pem = ["elliptic-curve/pem", "ecdsa-core/pem", "pkcs8"] pkcs8 = ["ecdsa-core/pkcs8", "elliptic-curve/pkcs8"] serde = ["ecdsa-core?/serde", "elliptic-curve/serde", "primeorder?/serde", "serdect"] sha384 = ["digest", "sha2"] test-vectors = ["hex-literal"] -voprf = ["hash2curve", "elliptic-curve/voprf", "sha2"] [package.metadata.docs.rs] all-features = true diff --git a/p384/src/arithmetic/hash2curve.rs b/p384/src/arithmetic/hash2curve.rs index 62054163c..b5af3af70 100644 --- a/p384/src/arithmetic/hash2curve.rs +++ b/p384/src/arithmetic/hash2curve.rs @@ -211,7 +211,8 @@ mod tests { // in parts let mut u = [FieldElement::default(), FieldElement::default()]; hash2curve::hash_to_field::< - ExpandMsgXmd::K>, + ExpandMsgXmd, + ::K, FieldElement, >(&[test_vector.msg], &[DST], &mut u) .unwrap(); @@ -244,11 +245,7 @@ mod tests { assert_point_eq!(p, test_vector.p_x, test_vector.p_y); // complete run - let pt = - NistP384::hash_from_bytes::::K>>( - &[test_vector.msg], - &[DST], - ) + let pt = NistP384::hash_from_bytes::>(&[test_vector.msg], &[DST]) .unwrap(); assert_point_eq!(pt, test_vector.p_x, test_vector.p_y); } @@ -297,17 +294,16 @@ mod tests { .to_be_bytes(); for counter in 0_u8..=u8::MAX { - let scalar = - NistP384::hash_to_scalar::::K>>( - &[ - test_vector.seed, - &key_info_len, - test_vector.key_info, - &counter.to_be_bytes(), - ], - &[test_vector.dst], - ) - .unwrap(); + let scalar = NistP384::hash_to_scalar::>( + &[ + 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); diff --git a/p384/src/lib.rs b/p384/src/lib.rs index 75b6ee1e9..ac14e2bd2 100644 --- a/p384/src/lib.rs +++ b/p384/src/lib.rs @@ -124,18 +124,15 @@ impl elliptic_curve::sec1::ValidatePublicKey for NistP384 {} #[cfg(feature = "bits")] pub type ScalarBits = elliptic_curve::scalar::ScalarBits; -#[cfg(feature = "voprf")] -impl elliptic_curve::VoprfParameters for NistP384 { +#[cfg(feature = "oprf")] +impl elliptic_curve::OprfParameters for NistP384 { /// See . - const ID: &'static str = "P384-SHA384"; + const ID: &'static [u8] = b"P384-SHA384"; /// See . type Hash = sha2::Sha384; /// See /// and . - type ExpandMsg = elliptic_curve::hash2curve::ExpandMsgXmd< - sha2::Sha384, - ::K, - >; + type ExpandMsg = elliptic_curve::hash2curve::ExpandMsgXmd; } diff --git a/p521/Cargo.toml b/p521/Cargo.toml index f4d854f49..884d727fc 100644 --- a/p521/Cargo.toml +++ b/p521/Cargo.toml @@ -51,12 +51,12 @@ expose-field = ["arithmetic"] getrandom = ["rand_core/os_rng"] hash2curve = ["arithmetic", "elliptic-curve/hash2curve"] jwk = ["elliptic-curve/jwk"] +oprf = ["hash2curve", "elliptic-curve/oprf", "dep:sha2"] pem = ["elliptic-curve/pem", "pkcs8"] pkcs8 = ["ecdsa-core?/pkcs8", "elliptic-curve/pkcs8"] serde = ["ecdsa-core?/serde", "elliptic-curve/serde", "primeorder?/serde", "serdect"] sha512 = ["digest", "dep:sha2"] test-vectors = ["dep:hex-literal"] -voprf = ["hash2curve", "elliptic-curve/voprf", "dep:sha2"] [package.metadata.docs.rs] all-features = true diff --git a/p521/src/arithmetic/hash2curve.rs b/p521/src/arithmetic/hash2curve.rs index d5595ef8e..7105e81f8 100644 --- a/p521/src/arithmetic/hash2curve.rs +++ b/p521/src/arithmetic/hash2curve.rs @@ -214,7 +214,8 @@ mod tests { // in parts let mut u = [FieldElement::default(), FieldElement::default()]; hash2curve::hash_to_field::< - ExpandMsgXmd::K>, + ExpandMsgXmd, + ::K, FieldElement, >(&[test_vector.msg], &[DST], &mut u) .unwrap(); @@ -247,11 +248,7 @@ mod tests { assert_point_eq!(p, test_vector.p_x, test_vector.p_y); // complete run - let pt = - NistP521::hash_from_bytes::::K>>( - &[test_vector.msg], - &[DST], - ) + let pt = NistP521::hash_from_bytes::>(&[test_vector.msg], &[DST]) .unwrap(); assert_point_eq!(pt, test_vector.p_x, test_vector.p_y); } @@ -300,17 +297,16 @@ mod tests { .to_be_bytes(); for counter in 0_u8..=u8::MAX { - let scalar = - NistP521::hash_to_scalar::::K>>( - &[ - test_vector.seed, - &key_info_len, - test_vector.key_info, - &counter.to_be_bytes(), - ], - &[test_vector.dst], - ) - .unwrap(); + let scalar = NistP521::hash_to_scalar::>( + &[ + 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); diff --git a/p521/src/lib.rs b/p521/src/lib.rs index e112f873c..3c7fb35bb 100644 --- a/p521/src/lib.rs +++ b/p521/src/lib.rs @@ -114,18 +114,15 @@ pub type PublicKey = elliptic_curve::PublicKey; /// NIST P-521 secret key. pub type SecretKey = elliptic_curve::SecretKey; -#[cfg(feature = "voprf")] -impl elliptic_curve::VoprfParameters for NistP521 { +#[cfg(feature = "oprf")] +impl elliptic_curve::OprfParameters for NistP521 { /// See . - const ID: &'static str = "P521-SHA512"; + const ID: &'static [u8] = b"P521-SHA512"; /// See . type Hash = sha2::Sha512; /// See /// and . - type ExpandMsg = elliptic_curve::hash2curve::ExpandMsgXmd< - sha2::Sha512, - ::K, - >; + type ExpandMsg = elliptic_curve::hash2curve::ExpandMsgXmd; }