Skip to content

Commit

Permalink
Depend on secp256k1 for k256
Browse files Browse the repository at this point in the history
  • Loading branch information
DanGould committed Aug 10, 2024
1 parent 891d763 commit 9bee7df
Show file tree
Hide file tree
Showing 11 changed files with 422 additions and 6 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 secp enabled
env:
CARGO_INCREMENTAL: 0
RUSTFLAGS: -D warnings -A dead_code -A unused_imports
run: cargo test --no-default-features --features="secp"

- name: Run cargo test with just X25519 enabled
env:
CARGO_INCREMENTAL: 0
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ p384 = ["dep:p384"]
p256 = ["dep:p256"]
p521 = ["dep:p521"]
k256 = ["dep:k256"]
secp = ["bitcoin", "secp256k1/global-context", "secp256k1/rand-std"]
# Include allocating methods like open() and seal()
alloc = []
# Includes an implementation of `std::error::Error` for `HpkeError`. Also does what `alloc` does.
Expand All @@ -29,6 +30,9 @@ std = []
[dependencies]
aead = "0.5"
aes-gcm = "0.10"
bitcoin = { version = "0.32.0", optional = true }
secp256k1 = { version = "0.29", optional = true }
# bitcoin = { git = "https://github.com/rust-bitcoin/rust-bitcoin", commit = "0d1cab68eee59f79c3ec76cf393438471b68fe69", optional = true }
chacha20poly1305 = "0.10"
generic-array = { version = "0.14", default-features = false }
digest = "0.10"
Expand Down
5 changes: 5 additions & 0 deletions benches/benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ pub fn benches() {
hpke::kdf::HkdfSha256,
hpke::kem::X25519HkdfSha256,
>("Non-NIST[seclevel=128]", &mut c);

#[cfg(feature = "secp")]
bench_ciphersuite::<hpke::aead::AesGcm128, hpke::kdf::HkdfSha256, hpke::kem::SecpK256HkdfSha256>(
"secp", &mut c,
);
}

criterion_main!(benches);
29 changes: 29 additions & 0 deletions src/aead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,35 @@ mod test {
);
}

#[cfg(all(feature = "secp", any(feature = "alloc", feature = "std")))]
mod secp_tests {
use super::*;

test_export_idempotence!(test_export_idempotence_k256, crate::kem::SecpK256HkdfSha256);
test_exportonly_panics!(
test_exportonly_panics_k256_seal,
test_exportonly_panics_k256_open,
crate::kem::SecpK256HkdfSha256
);
test_overflow!(test_overflow_k256, crate::kem::SecpK256HkdfSha256);

test_ctx_correctness!(
test_ctx_correctness_aes128_k256,
AesGcm128,
crate::kem::SecpK256HkdfSha256
);
test_ctx_correctness!(
test_ctx_correctness_aes256_k256,
AesGcm256,
crate::kem::SecpK256HkdfSha256
);
test_ctx_correctness!(
test_ctx_correctness_chacha_k256,
ChaCha20Poly1305,
crate::kem::SecpK256HkdfSha256
);
}

/// Tests that Serialize::write_exact() panics when given a buffer of incorrect length
#[should_panic]
#[test]
Expand Down
3 changes: 3 additions & 0 deletions src/dhkex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@ pub(crate) mod ecdh_nist;

#[cfg(feature = "x25519")]
pub(crate) mod x25519;

#[cfg(feature = "secp")]
pub(crate) mod secp256k1;
Loading

0 comments on commit 9bee7df

Please sign in to comment.