diff --git a/crypto/lakers-crypto-cryptocell310-sys/src/lib.rs b/crypto/lakers-crypto-cryptocell310-sys/src/lib.rs index 90e5a9c0..d14fe624 100644 --- a/crypto/lakers-crypto-cryptocell310-sys/src/lib.rs +++ b/crypto/lakers-crypto-cryptocell310-sys/src/lib.rs @@ -22,13 +22,6 @@ fn convert_array(input: &[u32]) -> [u8; SHA256_DIGEST_LEN] { pub struct Crypto; impl CryptoTrait for Crypto { - fn supported_suites(&self) -> &EdhocBuffer { - &EdhocBuffer:: { - content: [EDHOCSuite::CipherSuite2 as u8, 0, 0, 0, 0, 0, 0, 0, 0], - len: 1, - } - } - fn sha256_digest(&mut self, message: &BytesMaxBuffer, message_len: usize) -> BytesHashLen { let mut buffer: [u32; 64 / 4] = [0x00; 64 / 4]; diff --git a/crypto/lakers-crypto-rustcrypto/src/lib.rs b/crypto/lakers-crypto-rustcrypto/src/lib.rs index 3497ef2e..c15bdf25 100644 --- a/crypto/lakers-crypto-rustcrypto/src/lib.rs +++ b/crypto/lakers-crypto-rustcrypto/src/lib.rs @@ -3,7 +3,7 @@ use lakers_shared::{ BufferCiphertext3, BufferPlaintext3, BytesCcmIvLen, BytesCcmKeyLen, BytesHashLen, BytesMaxBuffer, BytesMaxInfoBuffer, BytesP256ElemLen, Crypto as CryptoTrait, EDHOCError, - EDHOCSuite, EdhocBuffer, AES_CCM_TAG_LEN, MAX_BUFFER_LEN, MAX_SUITES_LEN, + AES_CCM_TAG_LEN, MAX_BUFFER_LEN, }; use ccm::AeadInPlace; @@ -37,13 +37,6 @@ impl core::fmt::Debug for Crypto } impl CryptoTrait for Crypto { - fn supported_suites(&self) -> &EdhocBuffer { - &EdhocBuffer:: { - content: [EDHOCSuite::CipherSuite2 as u8, 0, 0, 0, 0, 0, 0, 0, 0], - len: 1, - } - } - fn sha256_digest(&mut self, message: &BytesMaxBuffer, message_len: usize) -> BytesHashLen { let mut hasher = sha2::Sha256::new(); hasher.update(&message[..message_len]); diff --git a/lakers-c/src/initiator.rs b/lakers-c/src/initiator.rs index 60b44530..da99a4a3 100644 --- a/lakers-c/src/initiator.rs +++ b/lakers-c/src/initiator.rs @@ -23,7 +23,7 @@ pub struct EdhocInitiator { pub unsafe extern "C" fn initiator_new(initiator: *mut EdhocInitiator) -> i8 { let mut crypto = default_crypto(); let suites_i = - prepare_suites_i(crypto.supported_suites(), EDHOCSuite::CipherSuite2.into()).unwrap(); + prepare_suites_i(&crypto.supported_suites(), EDHOCSuite::CipherSuite2.into()).unwrap(); let (x, g_x) = crypto.p256_generate_key_pair(); let start = InitiatorStart { diff --git a/lakers-python/src/initiator.rs b/lakers-python/src/initiator.rs index 0acd1253..2a4501da 100644 --- a/lakers-python/src/initiator.rs +++ b/lakers-python/src/initiator.rs @@ -18,7 +18,7 @@ impl PyEdhocInitiator { fn new() -> Self { let mut crypto = default_crypto(); let suites_i = - prepare_suites_i(crypto.supported_suites(), EDHOCSuite::CipherSuite2.into()).unwrap(); + prepare_suites_i(&crypto.supported_suites(), EDHOCSuite::CipherSuite2.into()).unwrap(); let (x, g_x) = crypto.p256_generate_key_pair(); Self { diff --git a/lib/src/edhoc.rs b/lib/src/edhoc.rs index 6e0365ad..b20c1db8 100644 --- a/lib/src/edhoc.rs +++ b/lib/src/edhoc.rs @@ -284,7 +284,7 @@ pub fn i_prepare_message_1( ead_1: &Option, // FIXME: make it a list of EADItem ) -> Result<(WaitM2, BufferMessage1), EDHOCError> { // Encode message_1 as a sequence of CBOR encoded data items as specified in Section 5.2.1 - let message_1 = encode_message_1(EDHOC_METHOD, &state.suites_i, &state.g_x, c_i, ead_1)?; + let message_1 = encode_message_1(state.method, &state.suites_i, &state.g_x, c_i, ead_1)?; let mut message_1_buf: BytesMaxBuffer = [0x00; MAX_BUFFER_LEN]; message_1_buf[..message_1.len].copy_from_slice(message_1.as_slice()); diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 26977763..e2dcf172 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -251,7 +251,7 @@ impl EdhocResponderDone { impl<'a, Crypto: CryptoTrait> EdhocInitiator { pub fn new(mut crypto: Crypto, method: EDHOCMethod, selected_suite: EDHOCSuite) -> Self { trace!("Initializing EdhocInitiator"); - let suites_i = prepare_suites_i(crypto.supported_suites(), selected_suite.into()).unwrap(); + let suites_i = prepare_suites_i(&crypto.supported_suites(), selected_suite.into()).unwrap(); let (x, g_x) = crypto.p256_generate_key_pair(); EdhocInitiator { @@ -682,7 +682,11 @@ mod test_authz { }; // ==== initialize edhoc ==== - let mut initiator = EdhocInitiator::new(default_crypto()); + let mut initiator = EdhocInitiator::new( + default_crypto(), + EDHOCMethod::StatStat, + EDHOCSuite::CipherSuite2, + ); let responder = EdhocResponder::new(default_crypto(), R, cred_r); // ==== initialize ead-authz ==== diff --git a/shared/src/crypto.rs b/shared/src/crypto.rs index a9f63d04..2de58232 100644 --- a/shared/src/crypto.rs +++ b/shared/src/crypto.rs @@ -38,7 +38,10 @@ pub fn prepare_suites_i( /// cryptography implementation can be taken out and stored separately. pub trait Crypto: core::fmt::Debug { /// Returns the list of cryptographic suites supported by the backend implementation. - fn supported_suites(&self) -> &EdhocBuffer; + fn supported_suites(&self) -> EdhocBuffer { + EdhocBuffer::::new_from_slice(&[EDHOCSuite::CipherSuite2 as u8]) + .expect("This should never fail, as the slice is of the correct length") + } fn sha256_digest(&mut self, message: &BytesMaxBuffer, message_len: usize) -> BytesHashLen; fn hkdf_expand( &mut self,