Skip to content

Commit

Permalink
Merge branch 'main' into jonas/platform-abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
jschneider-bensch committed Nov 6, 2024
2 parents a9ac34f + 6e645d5 commit 899ad5e
Show file tree
Hide file tree
Showing 23 changed files with 797 additions and 172 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ jobs:

- name: Build
working-directory: ${{ matrix.board_directory }}
run: cargo build
run: cargo build --verbose
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,47 @@
# libcrux-iot
An IoT friendly, formally verified, crypto library based on libcrux
An IoT friendly, formally verified, crypto library based on libcrux.

The `libcrux-nrf*/nucleo-l4r5zi` crates are based on the app template found at [https://github.com/knurling-rs/app-template].

## Dependencies

#### 1. `flip-link`:

```console
$ cargo install flip-link
```

#### 2. Install the target resp. toolchain

You need the following target toolchains installed, by board:

| Board | Target toolchain |
|---------------|-----------------------------|
| nRF52810 | `thumbv7em-none-eabi` |
| nRF52832 | `thumbv7em-none-eabihf` |
| nRF52840 | `thumbv7em-none-eabihf` |
| nRF52340 | `thumbv8m.main-none-eabihf` |
| nucleo-L4R5ZI | `thumbv7em-none-eabihf` |

#### 3. `probe-rs`:

``` console
$ # make sure to install v0.2.0 or later
$ cargo install probe-rs --features cli
```

## Running Benchmarks

With the device attached, run
```console
$ cargo rrb mlkem
```
for a crude benchmark of ML-KEM 1024 and

```console
$ cargo rrb mldsa
```
for a crude benchmark of ML-DSA 87.

Other parameter sets are available behind `mldsa44/65` and
`mlkem512/768` features.
11 changes: 11 additions & 0 deletions benchmarks.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

All numbers reported here refer to cycle counts.

| Device | Clock speed |
|---------------------------------|-------------------------------|
| [ESP32-S3] [^1] [^2] | 240 MHz |
| [STM32-L4R5xx] (our Nucleo-144) | 4 MHz (default, up to 120MHz) |
| [ESP32-C6] [^3] | 160 MHz |
| [nRF52840-DK] | 64 MHz |
| [nRF5340-DK] | 128 MHz |
| [nRF52-DK] | |
| - nRF52832 | 64 MHz |
| - nRF52810 | 64 MHz |

## ML-KEM

### ML-KEM 512
Expand Down
25 changes: 25 additions & 0 deletions libcrux-nrf52810/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
runner = ["probe-rs", "run", "--chip", "nRF52810_xxAA", "--log-format", "{s}"]


rustflags = [
"-C", "linker=flip-link",
"-C", "link-arg=-Tlink.x",
"-C", "link-arg=-Tdefmt.x",
# This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x
# See https://github.com/rust-embedded/cortex-m-quickstart/pull/95
"-C", "link-arg=--nmagic",
]

[build]
# TODO(3) Adjust the compilation target.
# (`thumbv6m-*` is compatible with all ARM Cortex-M chips but using the right
# target improves performance)
# target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+
# target = "thumbv7m-none-eabi" # Cortex-M3
target = "thumbv7em-none-eabi" # Cortex-M4 and Cortex-M7 (no FPU)
# target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU)

[alias]
rb = "run --bin"
rrb = "run --release --bin"
1 change: 1 addition & 0 deletions libcrux-nrf52810/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ panic-probe = { version = "0.3", features = ["print-defmt"] }
cortex-m-semihosting = "0.5.0"
libcrux-iot-testutil = { path = "../libcrux-iot-testutil" }
libcrux-testbench = { path = "../libcrux-testbench" }
libcrux-ml-dsa = { path = "../libcrux/libcrux-ml-dsa" }
embassy-nrf = { version = "0.1.0", features = [ "nrf52810", "defmt", ] }
embedded-alloc = "0.6.0"

Expand Down
32 changes: 0 additions & 32 deletions libcrux-nrf52810/README.md

This file was deleted.

14 changes: 14 additions & 0 deletions libcrux-nrf52810/src/bin/mldsa_keygen.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![no_main]
#![no_std]
#![cfg(feature = "mldsa87")]

use libcrux_ml_dsa::ml_dsa_87 as mldsa;
use libcrux_nrf52810 as board; // global logger + panicking-behavior + memory layout

#[cortex_m_rt::entry]
fn main() -> ! {
let randomness_gen = [1u8; 32];
let _keypair = mldsa::generate_key_pair(randomness_gen);

board::exit()
}
254 changes: 254 additions & 0 deletions libcrux-nrf52810/src/bin/mldsa_sign.rs

Large diffs are not rendered by default.

378 changes: 378 additions & 0 deletions libcrux-nrf52810/src/bin/mldsa_verify.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion libcrux-nrf52810/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use embassy_nrf as _; // memory layout

use panic_probe as _;

pub const COREFREQ: u32 = 4_000_000;
pub const COREFREQ: u32 = 64_000_000;

// same panicking *behavior* as `panic-probe` but doesn't print a panic message
// this prevents the panic message being printed *twice* when `defmt::panic` is invoked
Expand Down
26 changes: 26 additions & 0 deletions libcrux-nrf52832/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
# runner = "probe-rs run --chip nRF52840_xxAA"
runner = ["probe-rs", "run", "--chip", "nRF52832_xxAA", "--allow-erase-all", "--log-format", "{s}"]


rustflags = [
"-C", "linker=flip-link",
"-C", "link-arg=-Tlink.x",
"-C", "link-arg=-Tdefmt.x",
# This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x
# See https://github.com/rust-embedded/cortex-m-quickstart/pull/95
"-C", "link-arg=--nmagic",
]

[build]
# TODO(3) Adjust the compilation target.
# (`thumbv6m-*` is compatible with all ARM Cortex-M chips but using the right
# target improves performance)
# target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+
# target = "thumbv7m-none-eabi" # Cortex-M3
# target = "thumbv7em-none-eabi" # Cortex-M4 and Cortex-M7 (no FPU)
target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU)

[alias]
rb = "run --bin"
rrb = "run --release --bin"
32 changes: 0 additions & 32 deletions libcrux-nrf52832/README.md

This file was deleted.

2 changes: 1 addition & 1 deletion libcrux-nrf52832/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use embassy_nrf as _; // memory layout

use panic_probe as _;

pub const COREFREQ: u32 = 4_000_000;
pub const COREFREQ: u32 = 64_000_000;

// same panicking *behavior* as `panic-probe` but doesn't print a panic message
// this prevents the panic message being printed *twice* when `defmt::panic` is invoked
Expand Down
32 changes: 0 additions & 32 deletions libcrux-nrf52840/README.md

This file was deleted.

2 changes: 1 addition & 1 deletion libcrux-nrf52840/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use embassy_nrf as _; // memory layout

use panic_probe as _;

pub const COREFREQ: u32 = 4_000_000;
pub const COREFREQ: u32 = 64_000_000;

// same panicking *behavior* as `panic-probe` but doesn't print a panic message
// this prevents the panic message being printed *twice* when `defmt::panic` is invoked
Expand Down
30 changes: 30 additions & 0 deletions libcrux-nrf5340/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
# runner = "probe-rs run --chip nRF52840_xxAA"
runner = ["probe-rs", "run", "--chip", "nRF5340_xxAA", "--allow-erase-all", "--log-format", "{s}"]


rustflags = [
"-C", "linker=flip-link",
"-C", "link-arg=-Tlink.x",
"-C", "link-arg=-Tdefmt.x",
# This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x
# See https://github.com/rust-embedded/cortex-m-quickstart/pull/95
"-C", "link-arg=--nmagic",
]

[build]
# TODO(3) Adjust the compilation target.
# (`thumbv6m-*` is compatible with all ARM Cortex-M chips but using the right
# target improves performance)
# target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+
# target = "thumbv7m-none-eabi" # Cortex-M3
# target = "thumbv7em-none-eabi" # Cortex-M4 and Cortex-M7 (no FPU)
# target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU)
target = "thumbv8m.main-none-eabihf"

[alias]
rb = "run --bin"
rrb = "run --release --bin"

[env]
DEFMT_LOG = "trace"
3 changes: 2 additions & 1 deletion libcrux-nrf5340/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ debug-assertions = true # <-
incremental = false
opt-level = 'z' # <-
overflow-checks = true # <-

panic = "abort"

# cargo test
[profile.test]
codegen-units = 1
Expand Down
32 changes: 0 additions & 32 deletions libcrux-nrf5340/README.md

This file was deleted.

2 changes: 1 addition & 1 deletion libcrux-nrf5340/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use embassy_nrf as _; // memory layout

use panic_probe as _;

pub const COREFREQ: u32 = 4_000_000;
pub const COREFREQ: u32 = 128_000_000;

// same panicking *behavior* as `panic-probe` but doesn't print a panic message
// this prevents the panic message being printed *twice* when `defmt::panic` is invoked
Expand Down
33 changes: 0 additions & 33 deletions libcrux-nucleo-l4r5zi/README.md

This file was deleted.

Loading

0 comments on commit 899ad5e

Please sign in to comment.