Skip to content

Commit

Permalink
Merge pull request #31 from cryspen/jonas/nordic-boards
Browse files Browse the repository at this point in the history
Crates for our Nordic boards
  • Loading branch information
jschneider-bensch authored Nov 6, 2024
2 parents 387f04f + 04916d5 commit 6e645d5
Show file tree
Hide file tree
Showing 23 changed files with 801 additions and 214 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,24 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
board_directory: [libcrux-nrf52840, libcrux-nucleo-l4r5zi]
board_directory: [
libcrux-nucleo-l4r5zi,
libcrux-nrf52840,
libcrux-nrf52810,
libcrux-nrf52832,
libcrux-nrf5340,
]

steps:
- uses: actions/checkout@v4

- uses: dtolnay/rust-toolchain@stable
with:
targets: thumbv7em-none-eabihf,thumbv7em-none-eabi
targets: thumbv7em-none-eabihf,thumbv7em-none-eabi,thumbv8m.main-none-eabihf

- name: Install flip-link
run: cargo install flip-link

- 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.

42 changes: 0 additions & 42 deletions libcrux-nrf52810/src/bin/mldsa.rs

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()
}
Loading

0 comments on commit 6e645d5

Please sign in to comment.