Skip to content

Commit

Permalink
wip: renaming features
Browse files Browse the repository at this point in the history
  • Loading branch information
geonnave committed Oct 3, 2023
1 parent a0f44fe commit 75afa9e
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 53 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ jobs:
strategy:
fail-fast: false
matrix:
crypto: [hacspec, psa]
crypto_backend: [cb-hacspec, cb-psa]
ead: [ead-none, ead-zeroconf]

steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Run unit tests # note that we only add `--package edhoc-hacspec` when testing the hacspec version of the lib
run: cargo test --package edhoc-rs --package edhoc-crypto --package edhoc-ead --no-default-features --features="rust-${{ matrix.crypto }}, ${{ matrix.ead }}" --no-fail-fast
run: cargo test --package edhoc-rs --package edhoc-crypto --package edhoc-ead --no-default-features --features="${{ matrix.crypto_backend }}, ${{ matrix.ead }}" --no-fail-fast


build-edhoc-package:
Expand All @@ -45,7 +45,7 @@ jobs:
strategy:
fail-fast: false
matrix:
crypto: [hacspec, psa, psa-baremetal, cryptocell310]
crypto_backend: [cb-hacspec, cb-psa, cb-psa-baremetal, cb-cryptocell310]
ead: [ead-none, ead-zeroconf]

steps:
Expand All @@ -58,7 +58,7 @@ jobs:
run: sudo apt-get -y update && sudo apt-get -y install gcc-arm-none-eabi

- name: Build
run: cargo build --package edhoc-rs --package edhoc-crypto --package edhoc-ead --no-default-features --features="rust-${{ matrix.crypto }}, ${{ matrix.ead }}" --release
run: cargo build --package edhoc-rs --package edhoc-crypto --package edhoc-ead --no-default-features --features="${{ matrix.crypto_backend }}, ${{ matrix.ead }}" --release


generate-fstar:
Expand All @@ -80,7 +80,7 @@ jobs:

- name: Generate fstar
run: |
docker run --rm -v ${{ github.workspace }}:/edhoc-rs hacspec-v2 bash -c "cd edhoc-rs/ && cargo-hax -C --package edhoc-rs --package edhoc-crypto --package edhoc-ead --no-default-features --features="rust-psa, ead-none" --release \; into fstar"
docker run --rm -v ${{ github.workspace }}:/edhoc-rs hacspec-v2 bash -c "cd edhoc-rs/ && cargo-hax -C --package edhoc-rs --package edhoc-crypto --package edhoc-ead --no-default-features --features="cb-psa, ead-none" --release \; into fstar"
zip -j -r edhoc-rs-fstar.zip $(find . -name *fst)
- name: Upload artifact
Expand All @@ -97,7 +97,7 @@ jobs:
strategy:
fail-fast: false
matrix:
crypto: [psa-baremetal, cryptocell310]
crypto_backend: [cb-psa-baremetal, cb-cryptocell310]

steps:
- name: Checkout repo
Expand All @@ -109,7 +109,7 @@ jobs:
run: sudo apt-get -y update && sudo apt-get -y install gcc-arm-none-eabi

- name: Build static library, generate headers, and zip to file
run: ./build_for_c.sh "rust-${{ matrix.crypto }}"
run: ./build_for_c.sh "${{ matrix.crypto_backend }}"

- name: Upload artifact
uses: actions/upload-artifact@v3
Expand All @@ -125,7 +125,7 @@ jobs:
strategy:
fail-fast: false
matrix:
config: [rust-psa]
crypto_backend: [cb-psa]
ead: [ead-none, ead-zeroconf]

steps:
Expand All @@ -140,7 +140,7 @@ jobs:
run: sudo apt-get -y install qemu-system-arm

- name: Run tests in QEMU
run: cd examples/edhoc-rs-no_std && cargo run --target="thumbv7m-none-eabi" --no-default-features --features="${{ matrix.config }}, ${{ matrix.ead }}" --release
run: cd examples/edhoc-rs-no_std && cargo run --target="thumbv7m-none-eabi" --no-default-features --features="${{ matrix.crypto_backend }}, ${{ matrix.ead }}" --release


build-example-for-cortex-m4:
Expand All @@ -150,7 +150,7 @@ jobs:
strategy:
fail-fast: false
matrix:
crypto: [psa, cryptocell310]
crypto_backend: [cb-psa, cb-cryptocell310]
ead: [ead-none, ead-zeroconf]

steps:
Expand All @@ -163,7 +163,7 @@ jobs:
run: sudo apt-get -y update && sudo apt-get -y install gcc-arm-none-eabi

- name: Build example
run: cd examples/edhoc-rs-no_std && cargo build --target="thumbv7em-none-eabihf" --no-default-features --features="rust-${{ matrix.crypto }}, ${{ matrix.ead }}, rtt" --release
run: cd examples/edhoc-rs-no_std && cargo build --target="thumbv7em-none-eabihf" --no-default-features --features="${{ matrix.crypto_backend }}, ${{ matrix.ead }}, rtt" --release


build-coap-example:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ cd ./examples/edhoc-rs-no_std
cargo build --target="thumbv7em-none-eabihf" --no-default-features --features="hacspec-psa, rtt" --release

# build using the rust version of the lib, and hardware-accelerated crypto
cargo build --target="thumbv7em-none-eabihf" --no-default-features --features="rust-cryptocell310, rtt"
cargo build --target="thumbv7em-none-eabihf" --no-default-features --features="cb-cryptocell310, rtt"
```

To build **and** flash to the board, replace the word `build` with `embed` in the commands above (you may need to `cargo install cargo-embed`).
Expand Down
6 changes: 3 additions & 3 deletions build_for_c.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

cargo_features=$1

if [[ $cargo_features != "rust-cryptocell310" && $cargo_features != "rust-psa-baremetal" ]]; then
echo "Select one of: rust-cryptocell310, rust-psa-baremetal"
echo "Example: ./build_static_lib.sh rust-cryptocell310"
if [[ $cargo_features != "cb-cryptocell310" && $cargo_features != "cb-psa-baremetal" ]]; then
echo "Select one of: cb-cryptocell310, cb-psa-baremetal"
echo "Example: ./build_static_lib.sh cb-cryptocell310"
exit 1
fi

Expand Down
8 changes: 0 additions & 8 deletions consts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,5 @@ authors = ["Mališa Vučinić <[email protected]>"]
license = "BSD"
description = "EDHOC crypto library constants crate"

[dependencies]
hacspec-lib = { version = "0.1.0-beta.1", default-features = false, optional = true }

[build-dependencies]
cbindgen = "0.24.5"

[features]
default = [ ]
hacspec = [ "hacspec-lib/alloc" ]
rust = [ ]
7 changes: 2 additions & 5 deletions crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ edhoc-crypto-cryptocell310 = { path = "./edhoc-crypto-cryptocell310-sys", option
default = [ ]
hacspec = [ "edhoc-crypto-hacspec" ]
cc2538 = [ "edhoc-crypto-cc2538" ]
psa = [ "edhoc-crypto-psa/hacspec" ]
psa = [ "edhoc-crypto-psa" ]
psa-baremetal = [ "psa", "edhoc-crypto-psa/baremetal" ]
psa-rust = [ "edhoc-crypto-psa/rust" ]
psa-rust-baremetal = [ "psa-rust", "edhoc-crypto-psa/baremetal" ]
cryptocell310 = [ "edhoc-crypto-cryptocell310/hacspec" ]
cryptocell310-rust = [ "edhoc-crypto-cryptocell310/rust" ]
cryptocell310 = [ "edhoc-crypto-cryptocell310" ]
5 changes: 0 additions & 5 deletions crypto/edhoc-crypto-cryptocell310-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ links = "nrf_cc310_0.9.13"

[dependencies]
edhoc-consts = { path = "../../consts" }
hacspec-lib = { version = "0.1.0-beta.1", default-features = false, features = [ "alloc" ], optional = true }

[build-dependencies]
bindgen = "0.63.0"

[features]
rust = [ ]
hacspec = [ "hacspec-lib" ]
2 changes: 1 addition & 1 deletion crypto/edhoc-crypto-hacspec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "BSD"
description = "EDHOC crypto library hacspec backend"

[dependencies]
edhoc-consts = { path = "../../consts", default-features = false, features = ["hacspec"] }
edhoc-consts = { path = "../../consts", default-features = false }
hacspec-lib = { version = "0.1.0-beta.1", default-features = false }
hacspec-p256 = { version = "0.1.0" }
hacspec-hkdf = { version = "0.1.0" }
Expand Down
3 changes: 0 additions & 3 deletions crypto/edhoc-crypto-psa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ description = "EDHOC crypto library PSA backend"

[dependencies]
edhoc-consts = { path = "../../consts" }
hacspec-lib = { version = "0.1.0-beta.1", default-features = false, features = [ "alloc" ], optional = true }
psa-crypto = { version = "0.9.2" }

[features]
baremetal = [ "psa-crypto/baremetal" ]
hacspec = [ "hacspec-lib" ]
rust = [ ]
6 changes: 3 additions & 3 deletions examples/c-wrapper-riot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ See [Requirements](#requirements) below.
First, go to the top level directory and generate the headers and static library:

```bash
./build_for_c.sh rust-cryptocell310 # or rust-psa-baremetal
./build_for_c.sh cb-cryptocell310 # or cb-psa-baremetal
```

Then, compile and flash to the board (default is nRF52840), as shown below.

With `rust-cryptocell310`:
With `cb-cryptocell310`:

```bash
make flash term
```

With `rust-psa-baremetal`:
With `cb-psa-baremetal`:

```bash
make flash term EDHOC_CRYPTO=RUST_PSA
Expand Down
2 changes: 1 addition & 1 deletion examples/coap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ version = "0.1.0"
edition = "2021"

[dependencies]
edhoc-rs = { path = "../../lib", features = [ "rust-psa" ] }
edhoc-rs = { path = "../../lib", features = [ "cb-psa" ] }
coap = { version = "0.13" }
coap-lite = { version = "0.11.3" }
2 changes: 1 addition & 1 deletion examples/edhoc-rs-cc2538/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ rtt-target = { version = "0.3.1", features = ["cortex-m"] }

[features]
default = [ "psa" ]
psa = [ "edhoc-rs/rust-psa-baremetal" ]
psa = [ "edhoc-rs/cb-psa-baremetal" ]

4 changes: 2 additions & 2 deletions examples/edhoc-rs-no_std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ rtt-target = { version = "0.3.1", features = ["cortex-m"] }

[features]
default = [ ]
rust-psa = [ "edhoc-rs/rust-psa-baremetal" ]
cb-psa = [ "edhoc-rs/cb-psa-baremetal" ]
rtt = [ ]
rust-cryptocell310 = [ "edhoc-rs/rust-cryptocell310" ]
cb-cryptocell310 = [ "edhoc-rs/cb-cryptocell310" ]
ead-none = [ "edhoc-rs/ead-none" ]
ead-zeroconf = [ "edhoc-rs/ead-zeroconf" ]
6 changes: 3 additions & 3 deletions examples/edhoc-rs-no_std/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ fn main() -> ! {
}

// Memory buffer for mbedtls
#[cfg(any(feature = "hacspec-psa", feature = "rust-psa",))]
#[cfg(any(feature = "hacspec-psa", feature = "cb-psa",))]
let mut buffer: [c_char; 4096 * 2] = [0; 4096 * 2];
#[cfg(any(feature = "hacspec-psa", feature = "rust-psa",))]
#[cfg(any(feature = "hacspec-psa", feature = "cb-psa",))]
unsafe {
mbedtls_memory_buffer_alloc_init(buffer.as_mut_ptr(), buffer.len());
}
Expand Down Expand Up @@ -86,7 +86,7 @@ fn main() -> ! {

// NOTE: application code is not supposed to distinguish between the rust and hacspec implementations
// however, it is valuable to test that the results are correct, so we distinguish it here as an exception.
#[cfg(any(feature = "rust-psa", feature = "rust-cryptocell310",))]
#[cfg(any(feature = "cb-psa", feature = "cb-cryptocell310",))]
assert_eq!(g_xy, g_yx);
#[cfg(any(feature = "hacspec-psa", feature = "hacspec-cryptocell310",))]
assert_eq!(g_xy.to_public_array(), g_yx.to_public_array());
Expand Down
10 changes: 5 additions & 5 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ hex = { version = "0.4.3", default-features = false }

hacspec-lib = { version = "0.1.0-beta.1", default-features = false, optional = true }
edhoc-crypto = { path = "../crypto", default-features = false }
edhoc-consts = { path = "../consts", default-features = false }
edhoc-consts = { path = "../consts" }
edhoc-ead = { path = "../ead", default-features = false }
panic-semihosting = { version = "0.6.0", features = ["exit"], optional = true }

Expand All @@ -21,10 +21,10 @@ cbindgen = "0.24.5"

[features]
default = [ "edhoc-ead/ead-none" ]
rust-hacspec = ["hacspec-lib/std", "edhoc-crypto/hacspec" ]
rust-psa = [ "edhoc-consts/rust", "edhoc-crypto/psa-rust" ]
rust-psa-baremetal = [ "edhoc-crypto/psa-rust-baremetal", "edhoc-consts/rust", "panic-semihosting" ]
rust-cryptocell310 = [ "edhoc-consts/rust", "edhoc-crypto/cryptocell310-rust", "panic-semihosting" ]
cb-hacspec = ["hacspec-lib/std", "edhoc-crypto/hacspec" ]
cb-psa = [ "edhoc-crypto/psa" ]
cb-psa-baremetal = [ "edhoc-crypto/psa-baremetal", "panic-semihosting" ]
cb-cryptocell310 = [ "edhoc-crypto/cryptocell310", "panic-semihosting" ]
ead-none = [ "edhoc-ead/ead-none" ]
ead-zeroconf = [ "edhoc-ead/ead-zeroconf" ]

Expand Down
2 changes: 1 addition & 1 deletion lib/src/c_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::{slice, str};
use edhoc_consts::*;

// Panic handler for cortex-m targets
#[cfg(any(feature = "rust-cryptocell310", feature = "rust-psa-baremetal"))]
#[cfg(any(feature = "cb-cryptocell310", feature = "cb-psa-baremetal"))]
use panic_semihosting as _;

// This function is mainly used to test the C wrapper
Expand Down

0 comments on commit 75afa9e

Please sign in to comment.