From b080dd800d08da351460689cff61d76f4bdeb07a Mon Sep 17 00:00:00 2001 From: Geovane Fedrecheski Date: Fri, 15 Mar 2024 11:34:20 +0100 Subject: [PATCH] chore: remove obsolete cc2538 backend and examples --- Cargo.toml | 3 - crypto/Cargo.toml | 4 - .../lakers-crypto-cc2538/.cargo/config.toml | 2 - crypto/lakers-crypto-cc2538/Cargo.toml | 22 --- crypto/lakers-crypto-cc2538/lib.rs.old | 148 ---------------- crypto/lakers-crypto-cc2538/memory.x | 5 - crypto/lakers-crypto-cc2538/sections_remote.x | 17 -- crypto/lakers-crypto-cc2538/src/lib.rs | 54 ------ crypto/src/lib.rs | 4 - examples/lakers-cc2538/.cargo/config.toml | 4 - examples/lakers-cc2538/Cargo.toml | 25 --- examples/lakers-cc2538/build.rs | 31 ---- examples/lakers-cc2538/flash.sh | 13 -- examples/lakers-cc2538/gdb.sh | 3 - examples/lakers-cc2538/gdb_commands.gdb | 3 - examples/lakers-cc2538/jlink_commands.jlink | 6 - examples/lakers-cc2538/jlink_server.sh | 3 - examples/lakers-cc2538/memory.x | 5 - examples/lakers-cc2538/rtt.sh | 3 - examples/lakers-cc2538/rust-toolchain | 1 - examples/lakers-cc2538/sections_remote.x | 17 -- examples/lakers-cc2538/src/main.rs | 167 ------------------ 22 files changed, 540 deletions(-) delete mode 100644 crypto/lakers-crypto-cc2538/.cargo/config.toml delete mode 100644 crypto/lakers-crypto-cc2538/Cargo.toml delete mode 100644 crypto/lakers-crypto-cc2538/lib.rs.old delete mode 100644 crypto/lakers-crypto-cc2538/memory.x delete mode 100644 crypto/lakers-crypto-cc2538/sections_remote.x delete mode 100644 crypto/lakers-crypto-cc2538/src/lib.rs delete mode 100644 examples/lakers-cc2538/.cargo/config.toml delete mode 100644 examples/lakers-cc2538/Cargo.toml delete mode 100644 examples/lakers-cc2538/build.rs delete mode 100755 examples/lakers-cc2538/flash.sh delete mode 100755 examples/lakers-cc2538/gdb.sh delete mode 100644 examples/lakers-cc2538/gdb_commands.gdb delete mode 100644 examples/lakers-cc2538/jlink_commands.jlink delete mode 100755 examples/lakers-cc2538/jlink_server.sh delete mode 100644 examples/lakers-cc2538/memory.x delete mode 100755 examples/lakers-cc2538/rtt.sh delete mode 100644 examples/lakers-cc2538/rust-toolchain delete mode 100644 examples/lakers-cc2538/sections_remote.x delete mode 100644 examples/lakers-cc2538/src/main.rs diff --git a/Cargo.toml b/Cargo.toml index aee42705..3f4d148a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,14 +5,12 @@ members = [ "ead", "ead/lakers-ead-authz", "crypto", - "crypto/lakers-crypto-cc2538", # "crypto/lakers-crypto-hacspec", "crypto/lakers-crypto-psa", "crypto/lakers-crypto-rustcrypto", "crypto/lakers-crypto-cryptocell310-sys", "examples/coap", "examples/lakers-no_std", - "examples/lakers-cc2538", "lakers-c", "lakers-python", ] @@ -48,7 +46,6 @@ lakers-ead = { package = "lakers-ead", path = "ead/", version = "^0.5.1", defaul lakers-ead-authz = { package = "lakers-ead-authz", path = "ead/lakers-ead-authz/", version = "^0.5.1" } lakers-crypto = { path = "crypto/" } -lakers-crypto-cc2538 = { path = "crypto/lakers-crypto-cc2538/" } lakers-crypto-cryptocell310 = { path = "crypto/lakers-crypto-cryptocell310-sys/" } # lakers-crypto-hacspec = { path = "crypto/lakers-crypto-hacspec/" } lakers-crypto-psa = { path = "crypto/lakers-crypto-psa/" } diff --git a/crypto/Cargo.toml b/crypto/Cargo.toml index 05fbd914..c7b31ff5 100644 --- a/crypto/Cargo.toml +++ b/crypto/Cargo.toml @@ -14,9 +14,6 @@ lakers-shared = { package = "lakers-shared", path = "../shared", default-feature # hacspec # lakers-crypto-hacspec = { workspace = true, optional = true } -# cc2538 hardware accelerated -lakers-crypto-cc2538 = { workspace = true, optional = true } - # psa lakers-crypto-psa = { workspace = true, default-features = false, optional = true } @@ -34,7 +31,6 @@ rstest = "0.11.0" [features] default = [ ] # hacspec = [ "lakers-crypto-hacspec" ] -cc2538 = [ "lakers-crypto-cc2538" ] psa = [ "lakers-crypto-psa" ] psa-baremetal = [ "psa", "lakers-crypto-psa/baremetal" ] cryptocell310 = [ "lakers-crypto-cryptocell310" ] diff --git a/crypto/lakers-crypto-cc2538/.cargo/config.toml b/crypto/lakers-crypto-cc2538/.cargo/config.toml deleted file mode 100644 index 8b96f2fe..00000000 --- a/crypto/lakers-crypto-cc2538/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build] -target = "thumbv7m-none-eabi" # Cortex-M3 diff --git a/crypto/lakers-crypto-cc2538/Cargo.toml b/crypto/lakers-crypto-cc2538/Cargo.toml deleted file mode 100644 index 40f860fc..00000000 --- a/crypto/lakers-crypto-cc2538/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "lakers-crypto-cc2538" -version.workspace = true -edition = "2021" -authors = ["Mališa Vučinić "] -license.workspace = true -description = "EDHOC crypto library cc2538 backend" -repository.workspace = true -readme.workspace = true - -[dependencies] -lakers-shared.workspace = true -hacspec-lib = { version = "0.1.0-beta.1", default-features = false, features = [ "alloc" ] } -cortex-m = { version = "0.7.4" } -cortex-m-rt = { version = "0.7.1" } -cortex-m-semihosting = { version = "0.5.0" } -panic-semihosting = { version = "0.6.0", features = ["exit"] } -cc2538-pac = { version = "0.4.0", features = ["rt"] } -cc2538-hal = "0.2.0" - -# depend on an allocator -static-alloc = { version = "0.2.3", optional = true } diff --git a/crypto/lakers-crypto-cc2538/lib.rs.old b/crypto/lakers-crypto-cc2538/lib.rs.old deleted file mode 100644 index 371eb2ba..00000000 --- a/crypto/lakers-crypto-cc2538/lib.rs.old +++ /dev/null @@ -1,148 +0,0 @@ -#![no_std] - -use edhoc::consts::*; -use edhoc::Accelerator; - -use cc2538_hal::crypto::Crypto; -use cc2538_hal::crypto::ecc::EccCurveInfo; -use cc2538_hal::crypto::ecc::EcPoint; -use cc2538_hal::crypto::aes_engine::ccm::AesCcmInfo; -use cc2538_hal::crypto::aes_engine::keys::{AesKey, AesKeySize, AesKeys}; - -use rtt_target::{rprintln, rtt_init_print}; - -pub struct Cc2538Accelerator<'c> { - crypto: Crypto<'c>, -} - -impl<'c> Cc2538Accelerator<'c> { - pub fn new(crypto: Crypto<'c>) -> Self { - Self { crypto } - } -} - -fn as_u32_be(array: &[u8; 4]) -> u32 { - ((array[0] as u32) << 24) - + ((array[1] as u32) << 16) - + ((array[2] as u32) << 8) - + ((array[3] as u32) << 0) -} - -impl<'c> Accelerator for Cc2538Accelerator<'c> { - fn p256_ecdh( - &mut self, - private_key: &[u8], - public_key: &[u8], - secret: &mut [u8; P256_ELEM_LEN], - ) { - let curve = EccCurveInfo::nist_p_256(); - - // (p+1)/4 calculated offline - let exp: [u32; P256_ELEM_LEN/4] = [ - 0x00000000, 0x00000000, 0x40000000, 0x00000000, 0x00000000, 0x40000000, 0xc0000000, 0x3fffffff]; - - // Point multiplication of CC2538 internally uses the Montgommery ladder algorithm - // which depends on the x coordinate only. Therefore, we can set y to a dummy - // value and disregard the y coordinate of the point multiplication operation - let y: [u32; P256_ELEM_LEN/4] = [0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]; - - let mut private_key_u32_le : [u32; P256_ELEM_LEN / 4] = [0x00; P256_ELEM_LEN / 4]; - for i in 0..private_key_u32_le.len() { - private_key_u32_le[i] = as_u32_be(&[ - private_key[private_key.len() - 4*i - 4], - private_key[private_key.len() - 4*i - 3], - private_key[private_key.len() - 4*i - 2], - private_key[private_key.len() - 4*i - 1]]); - } - - let mut public_key_u32_le : [u32; P256_ELEM_LEN / 4] = [0x00; P256_ELEM_LEN / 4]; - for i in 0..public_key_u32_le.len() { - public_key_u32_le[i] = as_u32_be(&[ - public_key[public_key.len() - 4*i - 4], - public_key[public_key.len() - 4*i - 3], - public_key[public_key.len() - 4*i - 2], - public_key[public_key.len() - 4*i - 1]]); - } - - let point = EcPoint { - x: &public_key_u32_le, - y: &y, - }; - - let mut result = [0u32; 32]; - - self.crypto.ecc_mul(&curve, &private_key_u32_le, &point, &mut result).unwrap(); - - // take only the x coordinate - for i in 0..P256_ELEM_LEN/4 { - let temp = result[i].to_be_bytes(); - for j in 0..temp.len() { - secret[P256_ELEM_LEN - 4*i - 4 + j] = temp[j]; - } - } - } - - fn sha256_digest(&mut self, message: &[u8], output: &mut [u8; SHA256_DIGEST_LEN]) { - self.crypto.sha256(message, output); - } - - fn hkdf_extract( - &mut self, - salt: &[u8], - ikm: [u8; P256_ELEM_LEN], - okm: &mut [u8; P256_ELEM_LEN], - ) { - todo!() - } - - fn hkdf_expand( - &mut self, - prk: [u8; P256_ELEM_LEN], - info: &[u8], - length: usize, - output: &mut [u8], - ) { - todo!() - } - - fn aes_ccm_encrypt( - &mut self, - key: [u8; AES_CCM_KEY_LEN], - iv: [u8; AES_CCM_IV_LEN], - tag_len: usize, - ad: &[u8], - plaintext: &[u8], - ciphertext: &mut [u8], - ) { - // adata needs to be in RAM, which is not the case when executing test vectors - // code below is a hack - assert!(ad.len() < 100); - let mut adata : [u8; 100] = [0; 100]; - let _ = &adata[..ad.len()].copy_from_slice(&ad[..]); - let ad = &adata[..ad.len()]; - - let aes_key = AesKey::Key128(key); - let aes_keys_128 = AesKeys::create( - &[aes_key], - AesKeySize::Key128, - 0, - ); - self.crypto.load_key(&aes_keys_128); - - let ccm_info = AesCcmInfo::new(0, 2, 8).with_added_auth_data(&ad); - - let (mut ct, mut tag_truncated) = ciphertext.split_at_mut(plaintext.len()); - - let mut tag : [u8; 16] = [0x00; 16]; - - self.crypto.ccm_encrypt( - &ccm_info, - &iv, - &plaintext, - &mut ct, - &mut tag, - ); - - tag_truncated.copy_from_slice(&tag[0..tag_truncated.len()]); - } -} diff --git a/crypto/lakers-crypto-cc2538/memory.x b/crypto/lakers-crypto-cc2538/memory.x deleted file mode 100644 index d87827b5..00000000 --- a/crypto/lakers-crypto-cc2538/memory.x +++ /dev/null @@ -1,5 +0,0 @@ -MEMORY -{ - FLASH : ORIGIN = 0x00200000, LENGTH = 512K - RAM : ORIGIN = 0x20000000, LENGTH = 32K -} diff --git a/crypto/lakers-crypto-cc2538/sections_remote.x b/crypto/lakers-crypto-cc2538/sections_remote.x deleted file mode 100644 index 06df9eba..00000000 --- a/crypto/lakers-crypto-cc2538/sections_remote.x +++ /dev/null @@ -1,17 +0,0 @@ -__flash_cca__ = FLASH_CCA; - -SECTIONS -{ - .flash_cca ORIGIN(FLASH) + LENGTH(FLASH) - 44: - { - *(.flash_cca.*); - . = ALIGN(4); - } > FLASH - - .dma_channel_config (NOLOAD): - { - *(.dma_channel_config.*); - . = ALIGN(1024); - } > RAM -} - diff --git a/crypto/lakers-crypto-cc2538/src/lib.rs b/crypto/lakers-crypto-cc2538/src/lib.rs deleted file mode 100644 index e7b93b0f..00000000 --- a/crypto/lakers-crypto-cc2538/src/lib.rs +++ /dev/null @@ -1,54 +0,0 @@ -#![no_std] - -use lakers_shared::*; - -use cc2538_hal::crypto::aes_engine::ccm::AesCcmInfo; -use cc2538_hal::crypto::aes_engine::keys::{AesKey, AesKeySize, AesKeys}; -use cc2538_hal::crypto::ecc::EcPoint; -use cc2538_hal::crypto::ecc::EccCurveInfo; -use cc2538_hal::crypto::Crypto; - -pub fn sha256_digest(message: &BytesMaxBuffer, message_len: usize) -> BytesHashLen { - BytesHashLen::new() -} - -pub fn hkdf_expand( - prk: &BytesHashLen, - info: &BytesMaxInfoBuffer, - info_len: usize, - length: usize, -) -> BytesMaxBuffer { - BytesMaxBuffer::new() -} - -pub fn hkdf_extract(salt: &BytesHashLen, ikm: &BytesP256ElemLen) -> BytesHashLen { - BytesHashLen::new() -} - -pub fn aes_ccm_encrypt_tag_8( - key: &BytesCcmKeyLen, - iv: &BytesCcmIvLen, - ad: &BytesEncStructureLen, - plaintext: &BufferPlaintext3, -) -> BufferCiphertext3 { - BufferCiphertext3::new() -} - -pub fn aes_ccm_decrypt_tag_8( - key: &BytesCcmKeyLen, - iv: &BytesCcmIvLen, - ad: &BytesEncStructureLen, - ciphertext: &BufferCiphertext3, -) -> Result { - Ok(BufferPlaintext3::new()) -} -pub fn p256_ecdh( - private_key: &BytesP256ElemLen, - public_key: &BytesP256ElemLen, -) -> BytesP256ElemLen { - BytesP256ElemLen::new() -} - -pub fn p256_generate_key_pair() -> (BytesP256ElemLen, BytesP256ElemLen) { - (BytesP256ElemLen::new(), BytesP256ElemLen::new()) -} diff --git a/crypto/src/lib.rs b/crypto/src/lib.rs index d8550b6a..34008f2f 100644 --- a/crypto/src/lib.rs +++ b/crypto/src/lib.rs @@ -17,10 +17,6 @@ pub const fn default_crypto() -> Crypto { lakers_crypto_hacspec::Crypto } -// FIXME: Does not work with crypto-as-trait yet -#[cfg(feature = "cc2538")] -pub use lakers_crypto_cc2538::*; - #[cfg(any(feature = "psa", feature = "psa-rust",))] pub type Crypto = lakers_crypto_psa::Crypto; diff --git a/examples/lakers-cc2538/.cargo/config.toml b/examples/lakers-cc2538/.cargo/config.toml deleted file mode 100644 index c424f4b6..00000000 --- a/examples/lakers-cc2538/.cargo/config.toml +++ /dev/null @@ -1,4 +0,0 @@ -[build] -target = "thumbv7m-none-eabi" -rustflags = ["-C", "link-arg=-Tlink.x"] - diff --git a/examples/lakers-cc2538/Cargo.toml b/examples/lakers-cc2538/Cargo.toml deleted file mode 100644 index 754f8f84..00000000 --- a/examples/lakers-cc2538/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -name = "edhoc-cc2538" -version = "0.1.0" -edition = "2021" -authors = ["Mališa Vučinić "] -license.workspace = true -description = "lakers example on CC2538 SoC" - -[dependencies] -lakers = { package = "lakers", path = "../../lib", default-features = false } -lakers-crypto = { path = "../../crypto", default-features = false } -# depend on an allocator -embedded-alloc = "0.5.0" -hexlit = "0.5.3" -cc2538-pac = { version = "0.4.0", features = ["rt"] } -cc2538-hal = "0.2.0" -cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } -cortex-m-rt = { version = "0.7", features = ["device"] } -panic-rtt-target = { version = "0.1.2", features = ["cortex-m"] } -rtt-target = { version = "0.3.1", features = ["cortex-m"] } - -[features] -default = [ "psa" ] -psa = [ "lakers-crypto/psa-baremetal" ] - diff --git a/examples/lakers-cc2538/build.rs b/examples/lakers-cc2538/build.rs deleted file mode 100644 index d534cc3d..00000000 --- a/examples/lakers-cc2538/build.rs +++ /dev/null @@ -1,31 +0,0 @@ -//! This build script copies the `memory.x` file from the crate root into -//! a directory where the linker can always find it at build time. -//! For many projects this is optional, as the linker always searches the -//! project root directory -- wherever `Cargo.toml` is. However, if you -//! are using a workspace or have a more complicated build setup, this -//! build script becomes required. Additionally, by requesting that -//! Cargo re-run the build script whenever `memory.x` is changed, -//! updating `memory.x` ensures a rebuild of the application with the -//! new memory settings. - -use std::env; -use std::fs::File; -use std::io::Write; -use std::path::PathBuf; - -fn main() { - // Put `memory.x` in our output directory and ensure it's - // on the linker search path. - let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); - File::create(out.join("memory.x")) - .unwrap() - .write_all(include_bytes!("memory.x")) - .unwrap(); - println!("cargo:rustc-link-search={}", out.display()); - - // By default, Cargo will re-run a build script whenever - // any file in the project changes. By specifying `memory.x` - // here, we ensure the build script is only re-run when - // `memory.x` is changed. - println!("cargo:rerun-if-changed=memory.x"); -} diff --git a/examples/lakers-cc2538/flash.sh b/examples/lakers-cc2538/flash.sh deleted file mode 100755 index eacef9a8..00000000 --- a/examples/lakers-cc2538/flash.sh +++ /dev/null @@ -1,13 +0,0 @@ -#! /bin/sh - -cargo build --no-default-features --features psa -#cargo build --release - -# First convert the elf to binary. -mkdir -p ./tmp -llvm-objcopy -O binary $1 ./tmp/flash.bin -#arm-none-eabi-objcopy -O binary $1 ./tmp/flash.bin -cp $1 ./tmp/flash - -# Flash the device -JLinkExe -Device cc2538sf53 -Speed 4000 -If JTAG -JTAGConf "-1,-1" -AutoConnect 1 -ExitOnError 1 -CommandFile jlink_commands.jlink diff --git a/examples/lakers-cc2538/gdb.sh b/examples/lakers-cc2538/gdb.sh deleted file mode 100755 index 9ef5d23c..00000000 --- a/examples/lakers-cc2538/gdb.sh +++ /dev/null @@ -1,3 +0,0 @@ -#! /bin/sh - -rust-gdb --tui --command "gdb_commands.gdb" diff --git a/examples/lakers-cc2538/gdb_commands.gdb b/examples/lakers-cc2538/gdb_commands.gdb deleted file mode 100644 index 474c0dc7..00000000 --- a/examples/lakers-cc2538/gdb_commands.gdb +++ /dev/null @@ -1,3 +0,0 @@ -target remote :2331 -file ./tmp/flash -monitor reset diff --git a/examples/lakers-cc2538/jlink_commands.jlink b/examples/lakers-cc2538/jlink_commands.jlink deleted file mode 100644 index 71bd35fa..00000000 --- a/examples/lakers-cc2538/jlink_commands.jlink +++ /dev/null @@ -1,6 +0,0 @@ -h -loadbin ./tmp/flash.bin, 0x00200000 -verifybin ./tmp/flash.bin, 0x00200000 -r -go -q diff --git a/examples/lakers-cc2538/jlink_server.sh b/examples/lakers-cc2538/jlink_server.sh deleted file mode 100755 index 2e7cc050..00000000 --- a/examples/lakers-cc2538/jlink_server.sh +++ /dev/null @@ -1,3 +0,0 @@ -#! /bin/sh - -JLinkGDBServerCL -Device cc2538sf53 -Speed 4000 -If JTAG -JTAGConf "-1,-1" -LocalHostOnly 1 -Silent 1 -Reset 1 -nohalt diff --git a/examples/lakers-cc2538/memory.x b/examples/lakers-cc2538/memory.x deleted file mode 100644 index d87827b5..00000000 --- a/examples/lakers-cc2538/memory.x +++ /dev/null @@ -1,5 +0,0 @@ -MEMORY -{ - FLASH : ORIGIN = 0x00200000, LENGTH = 512K - RAM : ORIGIN = 0x20000000, LENGTH = 32K -} diff --git a/examples/lakers-cc2538/rtt.sh b/examples/lakers-cc2538/rtt.sh deleted file mode 100755 index 607e470e..00000000 --- a/examples/lakers-cc2538/rtt.sh +++ /dev/null @@ -1,3 +0,0 @@ -#! /bin/sh - -JLinkRTTClient diff --git a/examples/lakers-cc2538/rust-toolchain b/examples/lakers-cc2538/rust-toolchain deleted file mode 100644 index bf867e0a..00000000 --- a/examples/lakers-cc2538/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -nightly diff --git a/examples/lakers-cc2538/sections_remote.x b/examples/lakers-cc2538/sections_remote.x deleted file mode 100644 index 06df9eba..00000000 --- a/examples/lakers-cc2538/sections_remote.x +++ /dev/null @@ -1,17 +0,0 @@ -__flash_cca__ = FLASH_CCA; - -SECTIONS -{ - .flash_cca ORIGIN(FLASH) + LENGTH(FLASH) - 44: - { - *(.flash_cca.*); - . = ALIGN(4); - } > FLASH - - .dma_channel_config (NOLOAD): - { - *(.dma_channel_config.*); - . = ALIGN(1024); - } > RAM -} - diff --git a/examples/lakers-cc2538/src/main.rs b/examples/lakers-cc2538/src/main.rs deleted file mode 100644 index 9a7cf81a..00000000 --- a/examples/lakers-cc2538/src/main.rs +++ /dev/null @@ -1,167 +0,0 @@ -#![no_main] -#![no_std] -#![allow(unused)] -#![feature(default_alloc_error_handler)] - -use panic_rtt_target as _; -use rtt_target::{rprintln, rtt_init_print}; - -use cortex_m::asm; -use cortex_m_rt as rt; -use rt::entry; - -use cc2538_hal::crypto::aes_engine::ccm::AesCcmInfo; -use cc2538_hal::crypto::aes_engine::keys::{AesKey, AesKeySize, AesKeys}; - -use cc2538_hal::{crypto::*, sys_ctrl::*}; -use cc2538_pac as pac; - -use hexlit::hex; -use lakers::{EDHOCError, EdhocInitiator, EdhocResponder, EdhocState}; - -extern crate alloc; - -use embedded_alloc::Heap; - -#[global_allocator] -static HEAP: Heap = Heap::empty(); - -extern "C" { - pub fn mbedtls_memory_buffer_alloc_init(buf: *mut c_char, len: usize); -} - -#[entry] -fn main() -> ! { - // Initialize the allocator BEFORE you use it - { - use core::mem::MaybeUninit; - const HEAP_SIZE: usize = 1 << 10; - static mut HEAP_MEM: [MaybeUninit; HEAP_SIZE] = [MaybeUninit::uninit(); HEAP_SIZE]; - unsafe { HEAP.init(HEAP_MEM.as_ptr() as usize, HEAP_SIZE) } - } - - let mut buffer: [c_char; 4096 * 2] = [0; 4096 * 2]; - unsafe { - mbedtls_memory_buffer_alloc_init(buffer.as_mut_ptr(), buffer.len()); - } - - rtt_init_print!(); - - match inner_main() { - Ok(()) => cortex_m::peripheral::SCB::sys_reset(), - Err(e) => panic!("{}", e), - } -} - -fn inner_main() -> Result<(), &'static str> { - const ID_CRED_I: &str = "a104412b"; - const ID_CRED_R: &str = "a104410a"; - const CRED_I: &str = "A2027734322D35302D33312D46462D45462D33372D33322D333908A101A5010202412B2001215820AC75E9ECE3E50BFC8ED60399889522405C47BF16DF96660A41298CB4307F7EB62258206E5DE611388A4B8A8211334AC7D37ECB52A387D257E6DB3C2A93DF21FF3AFFC8"; - const I: &str = "fb13adeb6518cee5f88417660841142e830a81fe334380a953406a1305e8706b"; - const R: &str = "72cc4761dbd4c78f758931aa589d348d1ef874a7e303ede2f140dcf3e6aa4aac"; - const G_I: &str = "ac75e9ece3e50bfc8ed60399889522405c47bf16df96660a41298cb4307f7eb6"; // used - const _G_I_Y_COORD: &str = "6e5de611388a4b8a8211334ac7d37ecb52a387d257e6db3c2a93df21ff3affc8"; // not used - const CRED_R: &str = "A2026008A101A5010202410A2001215820BBC34960526EA4D32E940CAD2A234148DDC21791A12AFBCBAC93622046DD44F02258204519E257236B2A0CE2023F0931F1F386CA7AFDA64FCDE0108C224C51EABF6072"; - const G_R: &str = "bbc34960526ea4d32e940cad2a234148ddc21791a12afbcbac93622046dd44f0"; - const C_R_TV: [u8; 1] = hex!("27"); - - let mut periph = unsafe { pac::Peripherals::steal() }; - - let mut core_periph = cortex_m::Peripherals::take().unwrap(); - core_periph.DCB.enable_trace(); - core_periph.DWT.enable_cycle_counter(); - - // Setup the clock - let mut sys_ctrl = periph.SYS_CTRL.constrain(); - sys_ctrl.set_sys_div(ClockDiv::Clock32Mhz); - sys_ctrl.set_io_div(ClockDiv::Clock32Mhz); - sys_ctrl.enable_radio_in_active_mode(); - sys_ctrl.enable_gpt0_in_active_mode(); - sys_ctrl.enable_aes_in_active_mode(); - sys_ctrl.enable_pka_in_active_mode(); - - let mut sys_ctrl = sys_ctrl.freeze(); - - sys_ctrl.reset_aes(); - sys_ctrl.clear_reset_aes(); - - sys_ctrl.reset_pka(); - sys_ctrl.clear_reset_pka(); - - let crypto = Crypto::new(&mut periph.AES, &mut periph.PKA); - - rprintln!("Hello from CC2538"); - - test_handshake(); - rprintln!("Test test_handshake passed."); - - fn test_handshake() { - let state_initiator: EdhocState = Default::default(); - let mut initiator = EdhocInitiator::new( - state_initiator, - I, - G_R, - ID_CRED_I, - CRED_I, - ID_CRED_R, - CRED_R, - ); - let state_responder: EdhocState = Default::default(); - let mut responder = EdhocResponder::new( - state_responder, - R, - G_I, - ID_CRED_I, - CRED_I, - ID_CRED_R, - CRED_R, - ); - - let (error, message_1) = initiator.prepare_message_1(); // to update the state - assert!(error == EDHOCError::Success); - - let error = responder.process_message_1(&message_1); - assert!(error == EDHOCError::Success); - - let (error, message_2, c_r) = responder.prepare_message_2(); - assert!(error == EDHOCError::Success); - assert!(c_r != 0xff); - let (error, _c_r) = initiator.process_message_2(&message_2); - assert!(error == EDHOCError::Success); - - let (error, message_3, i_prk_out) = initiator.prepare_message_3(); - assert!(error == EDHOCError::Success); - let (error, r_prk_out) = responder.process_message_3(&message_3); - assert!(error == EDHOCError::Success); - - // check that prk_out is equal at initiator and responder side - assert_eq!(i_prk_out, r_prk_out); - - // derive OSCORE secret and salt at both sides and compare - let (error, i_oscore_secret) = initiator.edhoc_exporter(0u8, &[], 16); // label is 0 - assert!(error == EDHOCError::Success); - let (error, i_oscore_salt) = initiator.edhoc_exporter(1u8, &[], 8); // label is 1 - assert!(error == EDHOCError::Success); - - let (error, r_oscore_secret) = responder.edhoc_exporter(0u8, &[], 16); // label is 0 - assert!(error == EDHOCError::Success); - let (error, r_oscore_salt) = responder.edhoc_exporter(1u8, &[], 8); // label is 1 - assert!(error == EDHOCError::Success); - - assert_eq!(i_oscore_secret, r_oscore_secret); - assert_eq!(i_oscore_salt, r_oscore_salt); - } - - loop { - cortex_m::asm::nop(); - } - Ok(()) -} - -use core::ffi::{c_char, c_void}; - -#[no_mangle] -pub extern "C" fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char { - panic!("strstr handler!"); - core::ptr::null_mut() -}