Skip to content

Commit 9074ef9

Browse files
authored
Update to ExpandMsg changes (#1203)
1 parent 222b1c2 commit 9074ef9

File tree

13 files changed

+64
-86
lines changed

13 files changed

+64
-86
lines changed

.github/workflows/p256.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ jobs:
4444
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features ecdsa
4545
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features hash2curve
4646
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features jwk
47+
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features oprf
4748
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features pem
4849
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features pkcs8
4950
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features serde
5051
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features sha256
51-
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features voprf
52-
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features arithmetic,bits,ecdh,ecdsa,hash2curve,jwk,pem,pkcs8,serde,sha256,voprf
52+
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features arithmetic,bits,ecdh,ecdsa,hash2curve,jwk,oprf,pem,pkcs8,serde,sha256
5353

5454
benches:
5555
runs-on: ubuntu-latest

.github/workflows/p384.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ jobs:
4141
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features ecdsa-core
4242
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features hash2curve
4343
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features jwk
44+
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features oprf
4445
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features pem
4546
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features pkcs8
4647
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features serde
4748
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features sha384
48-
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features voprf
49-
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features ecdsa-core,hash2curve,jwk,pem,pkcs8,serde,sha384,voprf
49+
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features ecdsa-core,hash2curve,jwk,oprf,pem,pkcs8,serde,sha384
5050

5151
benches:
5252
runs-on: ubuntu-latest

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

k256/src/arithmetic/hash2curve.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,8 @@ mod tests {
355355
// in parts
356356
let mut u = [FieldElement::default(), FieldElement::default()];
357357
hash2curve::hash_to_field::<
358-
ExpandMsgXmd<Sha256, <Secp256k1 as GroupDigest>::K>,
358+
ExpandMsgXmd<Sha256>,
359+
<Secp256k1 as GroupDigest>::K,
359360
FieldElement,
360361
>(&[test_vector.msg], &[DST], &mut u)
361362
.unwrap();
@@ -378,10 +379,8 @@ mod tests {
378379
assert_eq!(ap.y.to_bytes().as_slice(), test_vector.p_y);
379380

380381
// complete run
381-
let pt = Secp256k1::hash_from_bytes::<
382-
ExpandMsgXmd<Sha256, <Secp256k1 as GroupDigest>::K>,
383-
>(&[test_vector.msg], &[DST])
384-
.unwrap();
382+
let pt = Secp256k1::hash_from_bytes::<ExpandMsgXmd<Sha256>>(&[test_vector.msg], &[DST])
383+
.unwrap();
385384
let apt = pt.to_affine();
386385
assert_eq!(apt.x.to_bytes().as_slice(), test_vector.p_x);
387386
assert_eq!(apt.y.to_bytes().as_slice(), test_vector.p_y);

p256/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ ecdsa = ["arithmetic", "ecdsa-core/signing", "ecdsa-core/verifying", "sha256"]
5151
expose-field = ["arithmetic"]
5252
hash2curve = ["arithmetic", "elliptic-curve/hash2curve"]
5353
jwk = ["elliptic-curve/jwk"]
54+
oprf = ["hash2curve", "elliptic-curve/oprf", "sha2"]
5455
pem = ["elliptic-curve/pem", "ecdsa-core/pem", "pkcs8"]
5556
pkcs8 = ["ecdsa-core?/pkcs8", "elliptic-curve/pkcs8"]
5657
serde = ["ecdsa-core?/serde", "elliptic-curve/serde", "primeorder?/serde", "serdect"]
5758
sha256 = ["digest", "sha2"]
5859
test-vectors = ["dep:hex-literal"]
59-
voprf = ["hash2curve", "elliptic-curve/voprf", "sha2"]
6060

6161
[package.metadata.docs.rs]
6262
all-features = true

p256/src/arithmetic/hash2curve.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ mod tests {
206206
// in parts
207207
let mut u = [FieldElement::default(), FieldElement::default()];
208208
hash2curve::hash_to_field::<
209-
ExpandMsgXmd<Sha256, <NistP256 as GroupDigest>::K>,
209+
ExpandMsgXmd<Sha256>,
210+
<NistP256 as GroupDigest>::K,
210211
FieldElement,
211212
>(&[test_vector.msg], &[DST], &mut u)
212213
.unwrap();
@@ -239,11 +240,7 @@ mod tests {
239240
assert_point_eq!(p, test_vector.p_x, test_vector.p_y);
240241

241242
// complete run
242-
let pt =
243-
NistP256::hash_from_bytes::<ExpandMsgXmd<Sha256, <NistP256 as GroupDigest>::K>>(
244-
&[test_vector.msg],
245-
&[DST],
246-
)
243+
let pt = NistP256::hash_from_bytes::<ExpandMsgXmd<Sha256>>(&[test_vector.msg], &[DST])
247244
.unwrap();
248245
assert_point_eq!(pt, test_vector.p_x, test_vector.p_y);
249246
}
@@ -286,17 +283,16 @@ mod tests {
286283
.to_be_bytes();
287284

288285
for counter in 0_u8..=u8::MAX {
289-
let scalar =
290-
NistP256::hash_to_scalar::<ExpandMsgXmd<Sha256, <NistP256 as GroupDigest>::K>>(
291-
&[
292-
test_vector.seed,
293-
&key_info_len,
294-
test_vector.key_info,
295-
&counter.to_be_bytes(),
296-
],
297-
&[test_vector.dst],
298-
)
299-
.unwrap();
286+
let scalar = NistP256::hash_to_scalar::<ExpandMsgXmd<Sha256>>(
287+
&[
288+
test_vector.seed,
289+
&key_info_len,
290+
test_vector.key_info,
291+
&counter.to_be_bytes(),
292+
],
293+
&[test_vector.dst],
294+
)
295+
.unwrap();
300296

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

p256/src/lib.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,15 @@ impl elliptic_curve::sec1::ValidatePublicKey for NistP256 {}
171171
#[cfg(feature = "bits")]
172172
pub type ScalarBits = elliptic_curve::scalar::ScalarBits<NistP256>;
173173

174-
#[cfg(feature = "voprf")]
175-
impl elliptic_curve::VoprfParameters for NistP256 {
174+
#[cfg(feature = "oprf")]
175+
impl elliptic_curve::OprfParameters for NistP256 {
176176
/// See <https://www.rfc-editor.org/rfc/rfc9497.html#section-4.3-1>.
177-
const ID: &'static str = "P256-SHA256";
177+
const ID: &'static [u8] = b"P256-SHA256";
178178

179179
/// See <https://www.rfc-editor.org/rfc/rfc9497.html#section-4.3-2.4>.
180180
type Hash = sha2::Sha256;
181181

182182
/// See <https://www.rfc-editor.org/rfc/rfc9497.html#section-4.3-2.2.2.10>
183183
/// and <https://www.rfc-editor.org/rfc/rfc9497.html#section-4.3-2.2.2.12>.
184-
type ExpandMsg = elliptic_curve::hash2curve::ExpandMsgXmd<
185-
sha2::Sha256,
186-
<Self as elliptic_curve::hash2curve::GroupDigest>::K,
187-
>;
184+
type ExpandMsg = elliptic_curve::hash2curve::ExpandMsgXmd<sha2::Sha256>;
188185
}

p384/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ ecdsa = ["arithmetic", "ecdsa-core/signing", "ecdsa-core/verifying", "sha384"]
5555
expose-field = ["arithmetic"]
5656
hash2curve = ["arithmetic", "elliptic-curve/hash2curve"]
5757
jwk = ["elliptic-curve/jwk"]
58+
oprf = ["hash2curve", "elliptic-curve/oprf", "sha2"]
5859
pem = ["elliptic-curve/pem", "ecdsa-core/pem", "pkcs8"]
5960
pkcs8 = ["ecdsa-core/pkcs8", "elliptic-curve/pkcs8"]
6061
serde = ["ecdsa-core?/serde", "elliptic-curve/serde", "primeorder?/serde", "serdect"]
6162
sha384 = ["digest", "sha2"]
6263
test-vectors = ["hex-literal"]
63-
voprf = ["hash2curve", "elliptic-curve/voprf", "sha2"]
6464

6565
[package.metadata.docs.rs]
6666
all-features = true

p384/src/arithmetic/hash2curve.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ mod tests {
211211
// in parts
212212
let mut u = [FieldElement::default(), FieldElement::default()];
213213
hash2curve::hash_to_field::<
214-
ExpandMsgXmd<Sha384, <NistP384 as GroupDigest>::K>,
214+
ExpandMsgXmd<Sha384>,
215+
<NistP384 as GroupDigest>::K,
215216
FieldElement,
216217
>(&[test_vector.msg], &[DST], &mut u)
217218
.unwrap();
@@ -244,11 +245,7 @@ mod tests {
244245
assert_point_eq!(p, test_vector.p_x, test_vector.p_y);
245246

246247
// complete run
247-
let pt =
248-
NistP384::hash_from_bytes::<ExpandMsgXmd<Sha384, <NistP384 as GroupDigest>::K>>(
249-
&[test_vector.msg],
250-
&[DST],
251-
)
248+
let pt = NistP384::hash_from_bytes::<ExpandMsgXmd<Sha384>>(&[test_vector.msg], &[DST])
252249
.unwrap();
253250
assert_point_eq!(pt, test_vector.p_x, test_vector.p_y);
254251
}
@@ -297,17 +294,16 @@ mod tests {
297294
.to_be_bytes();
298295

299296
for counter in 0_u8..=u8::MAX {
300-
let scalar =
301-
NistP384::hash_to_scalar::<ExpandMsgXmd<Sha384, <NistP384 as GroupDigest>::K>>(
302-
&[
303-
test_vector.seed,
304-
&key_info_len,
305-
test_vector.key_info,
306-
&counter.to_be_bytes(),
307-
],
308-
&[test_vector.dst],
309-
)
310-
.unwrap();
297+
let scalar = NistP384::hash_to_scalar::<ExpandMsgXmd<Sha384>>(
298+
&[
299+
test_vector.seed,
300+
&key_info_len,
301+
test_vector.key_info,
302+
&counter.to_be_bytes(),
303+
],
304+
&[test_vector.dst],
305+
)
306+
.unwrap();
311307

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

p384/src/lib.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,15 @@ impl elliptic_curve::sec1::ValidatePublicKey for NistP384 {}
124124
#[cfg(feature = "bits")]
125125
pub type ScalarBits = elliptic_curve::scalar::ScalarBits<NistP384>;
126126

127-
#[cfg(feature = "voprf")]
128-
impl elliptic_curve::VoprfParameters for NistP384 {
127+
#[cfg(feature = "oprf")]
128+
impl elliptic_curve::OprfParameters for NistP384 {
129129
/// See <https://www.rfc-editor.org/rfc/rfc9497.html#section-4.4-1>.
130-
const ID: &'static str = "P384-SHA384";
130+
const ID: &'static [u8] = b"P384-SHA384";
131131

132132
/// See <https://www.rfc-editor.org/rfc/rfc9497.html#section-4.4-2.4>.
133133
type Hash = sha2::Sha384;
134134

135135
/// See <https://www.rfc-editor.org/rfc/rfc9497.html#section-4.4-2.2.2.10>
136136
/// and <https://www.rfc-editor.org/rfc/rfc9497.html#section-4.4-2.2.2.12>.
137-
type ExpandMsg = elliptic_curve::hash2curve::ExpandMsgXmd<
138-
sha2::Sha384,
139-
<Self as elliptic_curve::hash2curve::GroupDigest>::K,
140-
>;
137+
type ExpandMsg = elliptic_curve::hash2curve::ExpandMsgXmd<sha2::Sha384>;
141138
}

0 commit comments

Comments
 (0)