From 455dd3e3e4320a90dc3d3140ce73996b3649a10a Mon Sep 17 00:00:00 2001 From: daxpedda Date: Sat, 15 Jan 2022 00:32:45 +0100 Subject: [PATCH] Implement `VoprfParameters` for `NistP256` and `NistP384` (#506) --- .github/workflows/p256.yml | 3 ++- .github/workflows/p384.yml | 3 ++- Cargo.lock | 5 +++-- p256/Cargo.toml | 3 ++- p256/src/lib.rs | 10 ++++++++++ p384/Cargo.toml | 3 ++- p384/src/lib.rs | 10 ++++++++++ 7 files changed, 31 insertions(+), 6 deletions(-) diff --git a/.github/workflows/p256.yml b/.github/workflows/p256.yml index f06695e2..2551e8bb 100644 --- a/.github/workflows/p256.yml +++ b/.github/workflows/p256.yml @@ -46,7 +46,8 @@ jobs: - 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 arithmetic,bits,ecdh,ecdsa,jwk,pem,pkcs8,serde,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,jwk,pem,pkcs8,serde,sha256,voprf test: runs-on: ubuntu-latest diff --git a/.github/workflows/p384.yml b/.github/workflows/p384.yml index e23851a6..eed83cf5 100644 --- a/.github/workflows/p384.yml +++ b/.github/workflows/p384.yml @@ -45,7 +45,8 @@ jobs: - 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 ecdsa,jwk,pem,pkcs8,serde,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,jwk,pem,pkcs8,serde,sha384,voprf test: runs-on: ubuntu-latest diff --git a/Cargo.lock b/Cargo.lock index 3aa49bae..467b74b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -328,13 +328,14 @@ checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" [[package]] name = "elliptic-curve" -version = "0.11.6" +version = "0.11.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "decb3a27ea454a5f23f96eb182af0671c12694d64ecc33dada74edd1301f6cfc" +checksum = "5fcbfdf46fd1157b49be0c2170bab2784ca19233b35c2dc772d60247b72f2071" dependencies = [ "base64ct", "crypto-bigint", "der", + "digest", "ff", "generic-array", "group", diff --git a/p256/Cargo.toml b/p256/Cargo.toml index ca770b6c..05ef1c8c 100644 --- a/p256/Cargo.toml +++ b/p256/Cargo.toml @@ -17,7 +17,7 @@ edition = "2021" rust-version = "1.56" [dependencies] -elliptic-curve = { version = "0.11.6", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "0.11.7", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "0.2", default-features = false } # optional dependencies @@ -46,6 +46,7 @@ serde = ["ecdsa-core/serde", "elliptic-curve/serde", "sec1/serde"] sha256 = ["digest", "sha2"] std = ["ecdsa-core/std", "elliptic-curve/std"] # TODO: use weak activation for `ecdsa-core/std` when available test-vectors = ["hex-literal"] +voprf = ["elliptic-curve/voprf", "sha2"] [package.metadata.docs.rs] all-features = true diff --git a/p256/src/lib.rs b/p256/src/lib.rs index 0bd59b2f..e81764f5 100644 --- a/p256/src/lib.rs +++ b/p256/src/lib.rs @@ -150,3 +150,13 @@ impl elliptic_curve::sec1::ValidatePublicKey for NistP256 {} #[cfg(feature = "bits")] #[cfg_attr(docsrs, doc(cfg(feature = "bits")))] pub type ScalarBits = elliptic_curve::ScalarBits; + +#[cfg(feature = "voprf")] +#[cfg_attr(docsrs, doc(cfg(feature = "voprf")))] +impl elliptic_curve::VoprfParameters for NistP256 { + /// See . + const ID: u16 = 0x0003; + + /// See . + type Hash = sha2::Sha256; +} diff --git a/p384/Cargo.toml b/p384/Cargo.toml index 1b3616cc..2bd80c01 100644 --- a/p384/Cargo.toml +++ b/p384/Cargo.toml @@ -14,7 +14,7 @@ rust-version = "1.56" [dependencies] ecdsa = { version = "0.13", optional = true, default-features = false, features = ["der"] } -elliptic-curve = { version = "0.11", default-features = false, features = ["hazmat", "sec1"] } +elliptic-curve = { version = "0.11.7", default-features = false, features = ["hazmat", "sec1"] } sec1 = { version = "0.2", default-features = false } sha2 = { version = "0.9", optional = true, default-features = false } @@ -30,6 +30,7 @@ pkcs8 = ["elliptic-curve/pkcs8"] serde = ["ecdsa/serde", "elliptic-curve/serde", "sec1/serde"] sha384 = ["ecdsa/digest", "ecdsa/hazmat", "sha2"] std = ["elliptic-curve/std"] +voprf = ["elliptic-curve/voprf", "sha2"] [package.metadata.docs.rs] all-features = true diff --git a/p384/src/lib.rs b/p384/src/lib.rs index 0c074cb9..1cb5b643 100644 --- a/p384/src/lib.rs +++ b/p384/src/lib.rs @@ -106,3 +106,13 @@ pub type ScalarCore = elliptic_curve::ScalarCore; pub type SecretKey = elliptic_curve::SecretKey; impl elliptic_curve::sec1::ValidatePublicKey for NistP384 {} + +#[cfg(feature = "voprf")] +#[cfg_attr(docsrs, doc(cfg(feature = "voprf")))] +impl elliptic_curve::VoprfParameters for NistP384 { + /// See . + const ID: u16 = 0x0004; + + /// See . + type Hash = sha2::Sha384; +}