Skip to content

Commit

Permalink
Impld secp256k1 DHKEX; doesn't work with serde for some reason
Browse files Browse the repository at this point in the history
  • Loading branch information
rozbb committed Oct 30, 2023
1 parent 57fce26 commit 232540f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ jobs:
toolchain: ${{ matrix.toolchain }}
override: true

- name: Run cargo test with just K256 and serde enabled
env:
CARGO_INCREMENTAL: 0
RUSTFLAGS: -D warnings -A dead_code -A unused_imports
run: cargo test --no-default-features --features="k256,serde_impls"

- name: Run cargo test with just X25519 enabled
env:
CARGO_INCREMENTAL: 0
Expand Down
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ default = ["alloc", "p256", "x25519"]
x25519 = ["dep:x25519-dalek"]
p384 = ["dep:p384"]
p256 = ["dep:p256"]
k256 = ["dep:k256"]
# Include serde Serialize/Deserialize impls for all relevant types
serde_impls = ["serde", "generic-array/serde"]
serde_impls = ["dep:serde", "generic-array/serde", "x25519-dalek?/serde", "p256?/serde", "p384?/serde", "k256?/serde", "p256?/pkcs8", "p384?/pkcs8", "k256?/pkcs8"]
# Include allocating methods like open() and seal()
alloc = []
# Includes an implementation of `std::error::Error` for `HpkeError`. Also does what `alloc` does.
Expand All @@ -36,6 +37,7 @@ digest = "0.10"
hkdf = "0.12"
hmac = "0.12"
rand_core = { version = "0.6", default-features = false }
k256 = { version = "0.13", default-features = false, features = ["arithmetic", "ecdh"], optional = true}
p256 = { version = "0.13", default-features = false, features = ["arithmetic", "ecdh"], optional = true}
p384 = { version = "0.13", default-features = false, features = ["arithmetic", "ecdh"], optional = true}
sha2 = { version = "0.10", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion src/dhkex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub trait DhKeyExchange {
) -> (Self::PrivateKey, Self::PublicKey);
}

#[cfg(any(feature = "p256", feature = "p384"))]
#[cfg(any(feature = "p256", feature = "p384", feature = "k256"))]
pub(crate) mod ecdh_nistp;

#[cfg(feature = "x25519")]
Expand Down
11 changes: 11 additions & 0 deletions src/dhkex/ecdh_nistp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,17 @@ nistp_dhkex!(
0xFF // RFC 9180 §7.1.3: The `bitmask` in DeriveKeyPair to be 0xFF for P-384
);

#[cfg(feature = "k256")]
nistp_dhkex!(
"K-256",
DhK256,
k256,
typenum::U65,
typenum::U32,
typenum::U32,
0xFF
);

#[cfg(test)]
mod tests {
use crate::{dhkex::DhKeyExchange, test_util::dhkex_gen_keypair, Deserializable, Serializable};
Expand Down

0 comments on commit 232540f

Please sign in to comment.