Skip to content

Commit 022154d

Browse files
authored
Add hash2curve crate (#1286)
1 parent 2164da6 commit 022154d

File tree

36 files changed

+1857
-38
lines changed

36 files changed

+1857
-38
lines changed

.github/workflows/hash2curve.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: hash2curve
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- ".github/workflows/hash2curve.yml"
7+
- "hash2curve/**"
8+
- "Cargo.*"
9+
push:
10+
branches: master
11+
12+
defaults:
13+
run:
14+
working-directory: hash2curve
15+
16+
env:
17+
CARGO_INCREMENTAL: 0
18+
RUSTFLAGS: "-Dwarnings"
19+
RUSTDOCFLAGS: "-Dwarnings"
20+
21+
jobs:
22+
build:
23+
runs-on: ubuntu-latest
24+
strategy:
25+
matrix:
26+
rust:
27+
- 1.85.0 # MSRV
28+
- stable
29+
target:
30+
- thumbv7em-none-eabi
31+
- wasm32-unknown-unknown
32+
steps:
33+
- uses: actions/checkout@v4
34+
- uses: dtolnay/rust-toolchain@master
35+
with:
36+
toolchain: ${{ matrix.rust }}
37+
targets: ${{ matrix.target }}
38+
- run: cargo build --target ${{ matrix.target }} --release
39+
40+
test:
41+
runs-on: ubuntu-latest
42+
strategy:
43+
matrix:
44+
rust:
45+
- 1.85.0 # MSRV
46+
- stable
47+
steps:
48+
- uses: actions/checkout@v4
49+
- uses: dtolnay/rust-toolchain@master
50+
with:
51+
toolchain: ${{ matrix.rust }}
52+
- run: cargo test
53+
54+
doc:
55+
runs-on: ubuntu-latest
56+
steps:
57+
- uses: actions/checkout@v4
58+
- uses: RustCrypto/actions/cargo-cache@master
59+
- uses: dtolnay/rust-toolchain@master
60+
with:
61+
toolchain: stable
62+
- run: cargo doc

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ members = [
55
"bp256",
66
"bp384",
77
"ed448-goldilocks",
8+
"hash2curve",
89
"k256",
910
"p192",
1011
"p224",
@@ -21,5 +22,6 @@ opt-level = 2
2122

2223
[patch.crates-io]
2324
ecdsa = { git = "https://github.com/RustCrypto/signatures.git" }
25+
hash2curve = { path = "hash2curve" }
2426
primefield = { path = "primefield" }
2527
primeorder = { path = "primeorder" }

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and can be easily used for bare-metal or WebAssembly programming.
1717
| [`bign256`] | bign-curve256v1 | [![crates.io](https://img.shields.io/crates/v/bign256.svg)](https://crates.io/crates/bign256) | [![Documentation](https://docs.rs/bign256/badge.svg)](https://docs.rs/bign256) | ![build](https://github.com/RustCrypto/elliptic-curves/workflows/bign256/badge.svg?branch=master&event=push) |
1818
| [`bp256`] | [brainpoolP256r1]/[brainpoolP256t1] | [![crates.io](https://img.shields.io/crates/v/bp256.svg)](https://crates.io/crates/bp256) | [![Documentation](https://docs.rs/bp256/badge.svg)](https://docs.rs/bp256) | ![build](https://github.com/RustCrypto/elliptic-curves/workflows/bp256/badge.svg?branch=master&event=push) |
1919
| [`bp384`] | [brainpoolP384r1]/[brainpoolP384t1] | [![crates.io](https://img.shields.io/crates/v/bp384.svg)](https://crates.io/crates/bp384) | [![Documentation](https://docs.rs/bp384/badge.svg)](https://docs.rs/bp384) | ![build](https://github.com/RustCrypto/elliptic-curves/workflows/bp384/badge.svg?branch=master&event=push) |
20+
| [`hash2curve`] | | [![crates.io](https://img.shields.io/crates/v/hash2curve.svg)](https://crates.io/crates/hash2curve) | [![Documentation](https://docs.rs/hash2curve/badge.svg)](https://docs.rs/hash2curve) | ![build](https://github.com/RustCrypto/elliptic-curves/workflows/hash2curve/badge.svg?branch=master&event=push) |
2021
| [`k256`] | [secp256k1] | [![crates.io](https://img.shields.io/crates/v/k256.svg)](https://crates.io/crates/k256) | [![Documentation](https://docs.rs/k256/badge.svg)](https://docs.rs/k256) | ![build](https://github.com/RustCrypto/elliptic-curves/workflows/k256/badge.svg?branch=master&event=push) |
2122
| [`p192`] | [NIST P-192] | [![crates.io](https://img.shields.io/crates/v/p192.svg)](https://crates.io/crates/p192) | [![Documentation](https://docs.rs/p192/badge.svg)](https://docs.rs/p192) | ![build](https://github.com/RustCrypto/elliptic-curves/workflows/p192/badge.svg?branch=master&event=push) |
2223
| [`p224`] | [NIST P-224] | [![crates.io](https://img.shields.io/crates/v/p224.svg)](https://crates.io/crates/p224) | [![Documentation](https://docs.rs/p224/badge.svg)](https://docs.rs/p224) | ![build](https://github.com/RustCrypto/elliptic-curves/workflows/p224/badge.svg?branch=master&event=push) |
@@ -63,6 +64,7 @@ dual licensed as above, without any additional terms or conditions.
6364
[`bign256`]: ./bign256
6465
[`bp256`]: ./bp256
6566
[`bp384`]: ./bp384
67+
[`hash2curve`]: ./hash2curve
6668
[`k256`]: ./k256
6769
[`p192`]: ./p192
6870
[`p224`]: ./p224

ed448-goldilocks/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ This crate also includes signing and verifying of Ed448 signatures.
1616
"""
1717

1818
[dependencies]
19-
elliptic-curve = { version = "0.14.0-rc.8", features = ["arithmetic", "hash2curve", "pkcs8"] }
19+
elliptic-curve = { version = "0.14.0-rc.8", features = ["arithmetic", "pkcs8"] }
20+
hash2curve = { version = "0.14.0-rc.0" }
2021
rand_core = { version = "0.9", default-features = false }
2122
sha3 = { version = "0.11.0-rc.0", default-features = false }
2223
subtle = { version = "2.6", default-features = false }

ed448-goldilocks/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ It is intended to be portable, fast, and safe.
1717
## Usage
1818

1919
```rust
20-
use ed448_goldilocks::{EdwardsPoint, CompressedEdwardsY, Scalar, elliptic_curve::hash2curve::ExpandMsgXof, sha3::Shake256};
20+
use ed448_goldilocks::{EdwardsPoint, CompressedEdwardsY, Scalar, sha3::Shake256};
2121
use elliptic_curve::Field;
22+
use hash2curve::ExpandMsgXof;
2223
use rand_core::OsRng;
2324

2425
let secret_key = Scalar::TWO;

ed448-goldilocks/src/curve/edwards/extended.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ use elliptic_curve::{
1515
array::{Array, typenum::Unsigned},
1616
consts::{U28, U84},
1717
group::{Group, GroupEncoding, cofactor::CofactorGroup, prime::PrimeGroup},
18-
hash2curve::{ExpandMsg, ExpandMsgXof, Expander, FromOkm},
1918
ops::LinearCombination,
2019
point::NonIdentity,
2120
};
21+
use hash2curve::{ExpandMsg, ExpandMsgXof, Expander, FromOkm};
2222
use rand_core::TryRngCore;
2323
use subtle::{Choice, ConditionallyNegatable, ConditionallySelectable, ConstantTimeEq, CtOption};
2424

ed448-goldilocks/src/decaf/points.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ use elliptic_curve::{
88
array::{Array, typenum::Unsigned},
99
consts::{U32, U56, U84},
1010
group::{GroupEncoding, cofactor::CofactorGroup, prime::PrimeGroup},
11-
hash2curve::{ExpandMsg, Expander, FromOkm},
1211
ops::LinearCombination,
1312
point::NonIdentity,
1413
};
1514

1615
use core::fmt::{Display, Formatter, LowerHex, Result as FmtResult, UpperHex};
16+
use hash2curve::{ExpandMsg, Expander, FromOkm};
1717
use rand_core::{CryptoRng, TryRngCore};
1818
use subtle::{Choice, ConditionallyNegatable, ConditionallySelectable, ConstantTimeEq, CtOption};
1919

@@ -771,7 +771,7 @@ mod test {
771771

772772
#[test]
773773
fn test_hash_to_curve() {
774-
use elliptic_curve::hash2curve::ExpandMsgXof;
774+
use hash2curve::ExpandMsgXof;
775775

776776
let msg = b"Hello, world!";
777777
let point = DecafPoint::hash::<ExpandMsgXof<sha3::Shake256>>(msg, b"test_hash_to_curve");

ed448-goldilocks/src/field/element.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use elliptic_curve::{
1212
NonZero, U448, U704,
1313
consts::{U84, U88},
1414
},
15-
hash2curve::{FromOkm, MapToCurve},
1615
zeroize::DefaultIsZeroes,
1716
};
17+
use hash2curve::{FromOkm, MapToCurve};
1818
use subtle::{Choice, ConditionallyNegatable, ConditionallySelectable, ConstantTimeEq};
1919

2020
#[derive(Clone, Copy, Default)]
@@ -420,10 +420,8 @@ impl FieldElement {
420420
#[cfg(test)]
421421
mod tests {
422422
use super::*;
423-
use elliptic_curve::{
424-
consts::U32,
425-
hash2curve::{ExpandMsg, ExpandMsgXof, Expander},
426-
};
423+
use elliptic_curve::consts::U32;
424+
use hash2curve::{ExpandMsg, ExpandMsgXof, Expander};
427425
use hex_literal::hex;
428426
use sha3::Shake256;
429427

ed448-goldilocks/src/field/scalar.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ use elliptic_curve::{
1111
bigint::{Limb, NonZero, U448, U704, U896, Word, Zero},
1212
consts::{U28, U84, U88, U114},
1313
ff::{Field, helpers},
14-
hash2curve::{ExpandMsg, Expander, FromOkm},
1514
ops::{Invert, Reduce, ReduceNonZero},
1615
scalar::{FromUintUnchecked, IsHigh},
1716
};
17+
use hash2curve::{ExpandMsg, Expander, FromOkm};
1818
use rand_core::{CryptoRng, RngCore, TryRngCore};
1919
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, ConstantTimeGreater, CtOption};
2020

@@ -841,8 +841,8 @@ impl Scalar {
841841
///
842842
/// `len_in_bytes = <Self::Scalar as FromOkm>::Length`
843843
///
844-
/// [`ExpandMsgXmd`]: elliptic_curve::hash2curve::ExpandMsgXmd
845-
/// [`ExpandMsgXof`]: elliptic_curve::hash2curve::ExpandMsgXof
844+
/// [`ExpandMsgXmd`]: hash2curve::ExpandMsgXmd
845+
/// [`ExpandMsgXof`]: hash2curve::ExpandMsgXof
846846
pub fn hash<X>(msg: &[u8], dst: &[u8]) -> Self
847847
where
848848
X: ExpandMsg<U28>,
@@ -1075,8 +1075,7 @@ mod test {
10751075
fn scalar_hash() {
10761076
let msg = b"hello world";
10771077
let dst = b"edwards448_XOF:SHAKE256_ELL2_RO_";
1078-
let res =
1079-
Scalar::hash::<elliptic_curve::hash2curve::ExpandMsgXof<sha3::Shake256>>(msg, dst);
1078+
let res = Scalar::hash::<hash2curve::ExpandMsgXof<sha3::Shake256>>(msg, dst);
10801079
let expected: [u8; 57] = hex_literal::hex!(
10811080
"2d32a08f09b88275cc5f437e625696b18de718ed94559e17e4d64aafd143a8527705132178b5ce7395ea6214735387398a35913656b4951300"
10821081
);

0 commit comments

Comments
 (0)