Skip to content

Commit

Permalink
dhkem: add no_std + refactor tests
Browse files Browse the repository at this point in the history
Adds `no_std` support to `dhkem`, which involved moving `std`-dependent
tests from `lib/` to the `tests/` directory, which links them in a
separate crate that can access `std`.

Also adds `default-features = false` to each of the elliptic curve
crate dependencies.

Finally, adds a CI check that the crate can link on a `no_std` target.
  • Loading branch information
tarcieri committed Aug 7, 2024
1 parent 2900ae9 commit ccecffa
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 185 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/dhkem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ jobs:
with:
working-directory: ${{ github.workflow }}

no_std:
needs: set-msrv
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- ${{needs.set-msrv.outputs.msrv}}
- stable
target:
- thumbv7em-none-eabi
- wasm32-unknown-unknown
steps:
- uses: actions/checkout@v4
- uses: RustCrypto/actions/cargo-cache@master
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
targets: ${{ matrix.target }}
- run: cargo build --no-default-features --target ${{ matrix.target }}

test:
needs: set-msrv
runs-on: ubuntu-latest
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/ml-kem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ jobs:
with:
msrv: 1.74.0

minimal-versions:
# temporarily disabled as requested by Tony (https://github.com/RustCrypto/KEMs/pull/15#pullrequestreview-2006378802)
if: false
uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master
with:
working-directory: ${{ github.workflow }}

no_std:
needs: set-msrv
runs-on: ubuntu-latest
Expand All @@ -43,13 +50,6 @@ jobs:
targets: ${{ matrix.target }}
- run: cargo build --no-default-features --target ${{ matrix.target }}

minimal-versions:
# temporarily disabled as requested by Tony (https://github.com/RustCrypto/KEMs/pull/15#pullrequestreview-2006378802)
if: false
uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master
with:
working-directory: ${{ github.workflow }}

test:
needs: set-msrv
runs-on: ubuntu-latest
Expand Down
137 changes: 0 additions & 137 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions dhkem/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ readme = "README.md"
[dependencies]
kem = "0.3.0-pre.0"
rand_core = "0.6.4"
x25519 = { version = "2.0.1", package = "x25519-dalek", optional = true }
elliptic-curve = { version = "0.13.8", optional = true }
bign256 = { version = "0.13.1", optional = true }
k256 = { version = "0.13.3", optional = true }
p192 = { version = "0.13.0", optional = true }
p224 = { version = "0.13.2", optional = true }
p256 = { version = "0.13.2", optional = true }
p384 = { version = "0.13.0", optional = true }
p521 = { version = "0.13.3", optional = true }
sm2 = { version = "0.13.3", optional = true }
zeroize = { version = "1.8.1", optional = true }
x25519 = { version = "2.0.1", package = "x25519-dalek", optional = true, default-features = false }
elliptic-curve = { version = "0.13.8", optional = true, default-features = false }
bign256 = { version = "0.13.1", optional = true, default-features = false, features = ["arithmetic"] }
k256 = { version = "0.13.3", optional = true, default-features = false, features = ["arithmetic"] }
p192 = { version = "0.13.0", optional = true, default-features = false, features = ["arithmetic"] }
p224 = { version = "0.13.2", optional = true, default-features = false, features = ["arithmetic"] }
p256 = { version = "0.13.2", optional = true, default-features = false, features = ["arithmetic"] }
p384 = { version = "0.13.0", optional = true, default-features = false, features = ["arithmetic"] }
p521 = { version = "0.13.3", optional = true, default-features = false, features = ["arithmetic"] }
sm2 = { version = "0.13.3", optional = true, default-features = false, features = ["arithmetic"] }
zeroize = { version = "1.8.1", optional = true, default-features = false }

[features]
default = ["zeroize"]
Expand Down
8 changes: 5 additions & 3 deletions dhkem/src/arithmetic.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use crate::{DhDecapsulator, DhEncapsulator, DhKem};
use elliptic_curve::ecdh::{EphemeralSecret, SharedSecret};
use elliptic_curve::{CurveArithmetic, PublicKey};
use core::marker::PhantomData;
use elliptic_curve::{
ecdh::{EphemeralSecret, SharedSecret},
CurveArithmetic, PublicKey,
};
use kem::{Decapsulate, Encapsulate};
use rand_core::CryptoRngCore;
use std::marker::PhantomData;

pub struct ArithmeticKem<C: CurveArithmetic>(PhantomData<C>);

Expand Down
Loading

0 comments on commit ccecffa

Please sign in to comment.