-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!: Move crypto operations into a trait.
This is incomplete in two aspects: * it only adjusts the hacspec and psa crypto backends, and * it still goes through the edhoc-crypto crate to create import-based dispatch. It also does not do a full cargo-fmt, because this allows the delta of this commit to be small.
- Loading branch information
Showing
12 changed files
with
165 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "edhoc-crypto-trait" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
edhoc-consts = { path = "../../consts", default-features = false } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//! Cryptography trait back-end for the edhoc-crypto crate | ||
#![no_std] | ||
|
||
use edhoc_consts::*; | ||
|
||
pub trait Crypto { | ||
fn sha256_digest(message: &BytesMaxBuffer, message_len: usize) -> BytesHashLen; | ||
fn hkdf_expand( | ||
prk: &BytesHashLen, | ||
info: &BytesMaxInfoBuffer, | ||
info_len: usize, | ||
length: usize, | ||
) -> BytesMaxBuffer; | ||
fn hkdf_extract(salt: &BytesHashLen, ikm: &BytesP256ElemLen) -> BytesHashLen; | ||
fn aes_ccm_encrypt_tag_8( | ||
key: &BytesCcmKeyLen, | ||
iv: &BytesCcmIvLen, | ||
ad: &BytesEncStructureLen, | ||
plaintext: &BufferPlaintext3, | ||
) -> BufferCiphertext3; | ||
fn aes_ccm_decrypt_tag_8( | ||
key: &BytesCcmKeyLen, | ||
iv: &BytesCcmIvLen, | ||
ad: &BytesEncStructureLen, | ||
ciphertext: &BufferCiphertext3, | ||
) -> Result<BufferPlaintext3, EDHOCError>; | ||
fn p256_ecdh(private_key: &BytesP256ElemLen, public_key: &BytesP256ElemLen) | ||
-> BytesP256ElemLen; | ||
fn get_random_byte() -> u8; | ||
fn p256_generate_key_pair() -> (BytesP256ElemLen, BytesP256ElemLen); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,35 @@ | ||
//! Cryptography dispatch for the edhoc-rs crate | ||
//! | ||
//! This crate is used by edhoc-rs to decide which cryptographic back-end to use. Its presence | ||
//! avoids the need for all edhoc-rs types to be generic over a back-end, which would then be | ||
//! provided by the user at initialization time. On the long run, its type may turn into a | ||
//! default associated type. | ||
#![no_std] | ||
|
||
/// Convenience re-export | ||
pub use edhoc_crypto_trait::Crypto as CryptoTrait; | ||
|
||
#[cfg(feature = "hacspec")] | ||
pub use edhoc_crypto_hacspec::*; | ||
pub type Crypto = edhoc_crypto_hacspec::Crypto; | ||
|
||
// FIXME: Does not work with crypto-as-trait yet | ||
#[cfg(feature = "cc2538")] | ||
pub use edhoc_crypto_cc2538::*; | ||
|
||
#[cfg(any(feature = "psa", feature = "psa-rust",))] | ||
pub use edhoc_crypto_psa::*; | ||
pub type Crypto = edhoc_crypto_psa::Crypto; | ||
|
||
// FIXME: Does not work with crypto-as-trait yet | ||
#[cfg(any(feature = "cryptocell310", feature = "cryptocell310-rust"))] | ||
pub use edhoc_crypto_cryptocell310::*; | ||
|
||
/// See test_implements_crypto | ||
#[allow(dead_code)] | ||
fn test_helper<T: CryptoTrait>() {} | ||
|
||
/// Ensure at build time that whichever type as selected for Crypto actually implements the Crypto | ||
/// trait, and that one is actually defined. | ||
#[allow(dead_code)] | ||
fn test_implements_crypto() { | ||
test_helper::<Crypto>() | ||
} |
Oops, something went wrong.