Skip to content

Commit

Permalink
Merge pull request #139 from chrysn-pull-requests/more-crypto-trait
Browse files Browse the repository at this point in the history
Crypto trait in the high level interface and EAD
  • Loading branch information
geonnave authored Nov 17, 2023
2 parents 06e6e1f + 31ff6a0 commit dbc44ff
Show file tree
Hide file tree
Showing 19 changed files with 328 additions and 147 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ jobs:
strategy:
fail-fast: false
matrix:
crypto_backend: [crypto-hacspec, crypto-psa]
crypto_backend: [edhoc-crypto/hacspec, edhoc-crypto/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: RUST_BACKTRACE=1 cargo test -p edhoc-rs -p edhoc-consts -p edhoc-ead-zeroconf --no-default-features --features="${{ matrix.crypto_backend }}, ${{ matrix.ead }}" --no-fail-fast -- --test-threads 1
run: RUST_BACKTRACE=1 cargo test -p edhoc-rs -p edhoc-crypto -p edhoc-consts -p edhoc-ead-zeroconf --no-default-features --features="${{ matrix.crypto_backend }}, ${{ matrix.ead }}" --no-fail-fast -- --test-threads 1


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

steps:
Expand Down
1 change: 1 addition & 0 deletions crypto/edhoc-crypto-cryptocell310-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fn convert_array(input: &[u32]) -> [u8; SHA256_DIGEST_LEN] {
output
}

#[derive(Debug)]
pub struct Crypto;

impl CryptoTrait for Crypto {
Expand Down
1 change: 1 addition & 0 deletions crypto/edhoc-crypto-hacspec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type BufferPlaintext3Hacspec = EdhocMessageBufferHacspec;

// Public functions

#[derive(Debug)]
pub struct Crypto;

impl CryptoTrait for Crypto {
Expand Down
1 change: 1 addition & 0 deletions crypto/edhoc-crypto-psa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub extern "C" fn mbedtls_hardware_poll(
0i32
}

#[derive(Debug)]
pub struct Crypto;

impl CryptoTrait for Crypto {
Expand Down
2 changes: 1 addition & 1 deletion crypto/edhoc-crypto-trait/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use edhoc_consts::*;

pub trait Crypto {
pub trait Crypto: core::fmt::Debug {
fn sha256_digest(&mut self, message: &BytesMaxBuffer, message_len: usize) -> BytesHashLen;
fn hkdf_expand(
&mut self,
Expand Down
1 change: 1 addition & 0 deletions ead/edhoc-ead-none/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ description = "EDHOC EAD none (just a placeholder)"

[dependencies]
edhoc-consts = { path = "../../consts" }
edhoc-crypto-trait = { path = "../../crypto/edhoc-crypto-trait" }
14 changes: 12 additions & 2 deletions ead/edhoc-ead-none/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
#![no_std]

use edhoc_consts::*;
use edhoc_crypto_trait::Crypto;

// TODO: the function signatures should not be necessarily the same as the zeroconf version
// find a way to be generic on this part.

// initiator side
pub fn i_prepare_ead_1(_x: &BytesP256ElemLen, _ss: u8) -> Option<EADItem> {
pub fn i_prepare_ead_1(
_crypto: &mut impl Crypto,
_x: &BytesP256ElemLen,
_ss: u8,
) -> Option<EADItem> {
None
}

pub fn i_process_ead_2(
_crypto: &mut impl Crypto,
_ead_2: EADItem,
_cred_v_u8: &[u8],
_h_message_1: &BytesHashLen,
Expand All @@ -23,7 +29,11 @@ pub fn i_prepare_ead_3() -> Option<EADItem> {
}

// responder side
pub fn r_process_ead_1(_ead_1: &EADItem, _message_1: &BufferMessage1) -> Result<(), ()> {
pub fn r_process_ead_1(
_crypto: &mut impl Crypto,
_ead_1: &EADItem,
_message_1: &BufferMessage1,
) -> Result<(), ()> {
Ok(())
}

Expand Down
5 changes: 4 additions & 1 deletion ead/edhoc-ead-zeroconf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ description = "EDHOC EAD zeroconf (draf-lake-authz)"

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

[dev-dependencies]
edhoc-crypto = { path = "../../crypto", default-features = false }

[features]
crypto-psa = [ "edhoc-crypto/psa" ]
crypto-hacspec = ["hacspec-lib/std", "edhoc-crypto/hacspec" ]
Loading

0 comments on commit dbc44ff

Please sign in to comment.