Skip to content

Commit 0568843

Browse files
committed
Update to ExpandMsg changes
1 parent 99bbeac commit 0568843

14 files changed

Lines changed: 64 additions & 86 deletions

File tree

.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: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ rfc6979 = { git = "https://github.com/RustCrypto/signatures.git" }
3737
# https://github.com/RustCrypto/traits/pull/1777
3838
# https://github.com/RustCrypto/traits/pull/1845
3939
digest = { git = "https://github.com/RustCrypto/traits.git" }
40-
elliptic-curve = { git = "https://github.com/RustCrypto/traits.git" }
40+
elliptic-curve = { git = "https://github.com/RustCrypto/traits.git", rev = "c268944f51e7aa3b6263e36f78f4e3b9f74a5ec9" }
4141
signature = { git = "https://github.com/RustCrypto/traits.git" }
4242

k256/src/arithmetic/hash2curve.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,8 @@ mod tests {
370370
// in parts
371371
let mut u = [FieldElement::default(), FieldElement::default()];
372372
hash2curve::hash_to_field::<
373-
ExpandMsgXmd<Sha256, <Secp256k1 as GroupDigest>::K>,
373+
ExpandMsgXmd<Sha256>,
374+
<Secp256k1 as GroupDigest>::K,
374375
FieldElement,
375376
>(&[test_vector.msg], &[DST], &mut u)
376377
.unwrap();
@@ -393,10 +394,8 @@ mod tests {
393394
assert_eq!(ap.y.to_bytes().as_slice(), test_vector.p_y);
394395

395396
// complete run
396-
let pt = Secp256k1::hash_from_bytes::<
397-
ExpandMsgXmd<Sha256, <Secp256k1 as GroupDigest>::K>,
398-
>(&[test_vector.msg], &[DST])
399-
.unwrap();
397+
let pt = Secp256k1::hash_from_bytes::<ExpandMsgXmd<Sha256>>(&[test_vector.msg], &[DST])
398+
.unwrap();
400399
let apt = pt.to_affine();
401400
assert_eq!(apt.x.to_bytes().as_slice(), test_vector.p_x);
402401
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
@@ -204,7 +204,8 @@ mod tests {
204204
// in parts
205205
let mut u = [FieldElement::default(), FieldElement::default()];
206206
hash2curve::hash_to_field::<
207-
ExpandMsgXmd<Sha256, <NistP256 as GroupDigest>::K>,
207+
ExpandMsgXmd<Sha256>,
208+
<NistP256 as GroupDigest>::K,
208209
FieldElement,
209210
>(&[test_vector.msg], &[DST], &mut u)
210211
.unwrap();
@@ -237,11 +238,7 @@ mod tests {
237238
assert_point_eq!(p, test_vector.p_x, test_vector.p_y);
238239

239240
// complete run
240-
let pt =
241-
NistP256::hash_from_bytes::<ExpandMsgXmd<Sha256, <NistP256 as GroupDigest>::K>>(
242-
&[test_vector.msg],
243-
&[DST],
244-
)
241+
let pt = NistP256::hash_from_bytes::<ExpandMsgXmd<Sha256>>(&[test_vector.msg], &[DST])
245242
.unwrap();
246243
assert_point_eq!(pt, test_vector.p_x, test_vector.p_y);
247244
}
@@ -284,17 +281,16 @@ mod tests {
284281
.to_be_bytes();
285282

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

299295
if !bool::from(scalar.is_zero()) {
300296
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
@@ -206,7 +206,8 @@ mod tests {
206206
// in parts
207207
let mut u = [FieldElement::default(), FieldElement::default()];
208208
hash2curve::hash_to_field::<
209-
ExpandMsgXmd<Sha384, <NistP384 as GroupDigest>::K>,
209+
ExpandMsgXmd<Sha384>,
210+
<NistP384 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-
NistP384::hash_from_bytes::<ExpandMsgXmd<Sha384, <NistP384 as GroupDigest>::K>>(
244-
&[test_vector.msg],
245-
&[DST],
246-
)
243+
let pt = NistP384::hash_from_bytes::<ExpandMsgXmd<Sha384>>(&[test_vector.msg], &[DST])
247244
.unwrap();
248245
assert_point_eq!(pt, test_vector.p_x, test_vector.p_y);
249246
}
@@ -292,17 +289,16 @@ mod tests {
292289
.to_be_bytes();
293290

294291
for counter in 0_u8..=u8::MAX {
295-
let scalar =
296-
NistP384::hash_to_scalar::<ExpandMsgXmd<Sha384, <NistP384 as GroupDigest>::K>>(
297-
&[
298-
test_vector.seed,
299-
&key_info_len,
300-
test_vector.key_info,
301-
&counter.to_be_bytes(),
302-
],
303-
&[test_vector.dst],
304-
)
305-
.unwrap();
292+
let scalar = NistP384::hash_to_scalar::<ExpandMsgXmd<Sha384>>(
293+
&[
294+
test_vector.seed,
295+
&key_info_len,
296+
test_vector.key_info,
297+
&counter.to_be_bytes(),
298+
],
299+
&[test_vector.dst],
300+
)
301+
.unwrap();
306302

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

0 commit comments

Comments
 (0)