Skip to content

Commit

Permalink
fix: softsim filename updates (#44)
Browse files Browse the repository at this point in the history
* refactor: change file name of f_cache to ss_cache to easier link to softsim

* refactor: change file name of crypto_port to ss_crypto

* refactor: change file name of profile to ss_profile

this file might be obselete when the next SoftSIM lib is released

* refactor: change file name of provision to ss_provision

* refactor: change file name of heap_port to ss_heap

* refactor: change file name of fs_port to ss_fs
  • Loading branch information
benjaminbruun committed May 23, 2024
1 parent 77651fb commit ac91364
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 74 deletions.
86 changes: 43 additions & 43 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ zephyr_library()

include_directories(include)

zephyr_library_sources(nrf_softsim.c fs_port.c provision.c f_cache.c heap_port.c profile.c crypto_port.c build_asserts.c )
zephyr_library_sources(nrf_softsim.c ss_fs.c ss_provision.c ss_cache.c ss_heap.c ss_profile.c ss_crypto.c build_asserts.c )

zephyr_library_import(crypto ${CMAKE_CURRENT_SOURCE_DIR}/libcrypto.a)
zephyr_library_import(milenage ${CMAKE_CURRENT_SOURCE_DIR}/libmilenage.a)
Expand Down
16 changes: 8 additions & 8 deletions lib/nrf_softsim.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>

#include "profile.h"
#include "crypto_port.h"
#include "ss_profile.h"
#include "ss_crypto.h"
#include <nrf_softsim.h>
#include <nrf_modem_at.h>
#include <nrf_modem_softsim.h>
Expand Down Expand Up @@ -51,7 +51,7 @@ static void softsim_req_task(struct k_work *item);
static void nrf_modem_softsim_req_handler(enum nrf_modem_softsim_cmd req, uint16_t req_id, void *data,
uint16_t data_len);

int onomondo_init(void)
int onomondo_init(void)
{
/**
* Init here?
Expand Down Expand Up @@ -100,7 +100,7 @@ int onomondo_init(void)
int nrf_softsim_init(void) { return onomondo_init(); }

// public provision api
int nrf_softsim_provision(uint8_t *profile_r, size_t len)
int nrf_softsim_provision(uint8_t *profile_r, size_t len)
{
struct ss_profile profile = {0};
decode_profile(len, profile_r, &profile);
Expand All @@ -123,7 +123,7 @@ int nrf_softsim_provision(uint8_t *profile_r, size_t len)
return status;
}

int nrf_softsim_check_provisioned(void)
int nrf_softsim_check_provisioned(void)
{
/* Check first PSA key and also first NVS key. */
return ss_utils_check_key_existence(KEY_ID_KI) && port_check_provisioned();
Expand All @@ -132,7 +132,7 @@ int nrf_softsim_check_provisioned(void)
// still needed?
__weak void nrf_modem_softsim_reset_handler(void) { LOG_DBG("SoftSIM RESET"); }

static void softsim_req_task(struct k_work *item)
static void softsim_req_task(struct k_work *item)
{
int err;
struct softsim_req_node *s_req;
Expand Down Expand Up @@ -219,7 +219,7 @@ static void softsim_req_task(struct k_work *item)
}
}

void nrf_modem_softsim_req_handler(enum nrf_modem_softsim_cmd req, uint16_t req_id, void *data, uint16_t data_len)
void nrf_modem_softsim_req_handler(enum nrf_modem_softsim_cmd req, uint16_t req_id, void *data, uint16_t data_len)
{
struct softsim_req_node *req_node = NULL;

Expand All @@ -243,7 +243,7 @@ void nrf_modem_softsim_req_handler(enum nrf_modem_softsim_cmd req, uint16_t req_
#ifdef CONFIG_SOFTSIM_AUTO_INIT
SYS_INIT(onomondo_init, APPLICATION, 0);

static void ss_on_modem_lib_init(int ret, void *ctx)
static void ss_on_modem_lib_init(int ret, void *ctx)
{
int err;

Expand Down
2 changes: 1 addition & 1 deletion lib/f_cache.c → lib/ss_cache.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <string.h>
#include <zephyr/sys/printk.h>

#include "f_cache.h"
#include "ss_cache.h"

#define SS_MAX_ENTRIES (10)

Expand Down
File renamed without changes.
20 changes: 10 additions & 10 deletions lib/crypto_port.c → lib/ss_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <zephyr/logging/log.h>
#include <zephyr/sys/printk.h>

#include "profile.h"
#include "crypto_port.h"
#include "ss_profile.h"
#include "ss_crypto.h"
#include <onomondo/softsim/log.h>
#include <onomondo/softsim/mem.h>

Expand Down Expand Up @@ -41,7 +41,7 @@ static uint8_t shared_buffer[SHARED_BUFFER_SIZE];
} while (0)

static psa_status_t cipher_operation(psa_cipher_operation_t *operation, const uint8_t *input, size_t input_size,
size_t part_size, uint8_t *output, size_t output_size, size_t *output_len)
size_t part_size, uint8_t *output, size_t output_size, size_t *output_len)
{
psa_status_t status;
size_t bytes_to_write = 0, bytes_written = 0, len = 0;
Expand All @@ -67,7 +67,7 @@ static psa_status_t cipher_operation(psa_cipher_operation_t *operation, const ui
}

int ss_utils_ota_calc_cc(uint8_t *cc, size_t cc_len, uint8_t *key, size_t key_len, enum enc_algorithm alg,
uint8_t *data1, size_t data1_len, uint8_t *data2, size_t data2_len)
uint8_t *data1, size_t data1_len, uint8_t *data2, size_t data2_len)
{
psa_mac_operation_t operation = PSA_MAC_OPERATION_INIT;
enum key_identifier_base slot_id = key_id_to_kmu_slot(key[0]);
Expand Down Expand Up @@ -139,7 +139,7 @@ int ss_utils_ota_calc_cc(uint8_t *cc, size_t cc_len, uint8_t *key, size_t key_le
void ss_utils_3des_decrypt(uint8_t *buffer, size_t buffer_len, const uint8_t *key) { return; }
void ss_utils_3des_encrypt(uint8_t *buffer, size_t buffer_len, const uint8_t *key) { return; }

void ss_utils_aes_decrypt(uint8_t *buffer, size_t buffer_len, const uint8_t *key, size_t key_len)
void ss_utils_aes_decrypt(uint8_t *buffer, size_t buffer_len, const uint8_t *key, size_t key_len)
{
enum key_identifier_base slot_id = key_id_to_kmu_slot(key[0]);
psa_key_handle_t key_handle;
Expand Down Expand Up @@ -182,7 +182,7 @@ void ss_utils_aes_decrypt(uint8_t *buffer, size_t buffer_len, const uint8_t *key
return;
}

void ss_utils_aes_encrypt(uint8_t *buffer, size_t buffer_len, const uint8_t *key, size_t key_len)
void ss_utils_aes_encrypt(uint8_t *buffer, size_t buffer_len, const uint8_t *key, size_t key_len)
{
// Key derived from the fist byte of the KIC/KID key
enum key_identifier_base slot_id = key_id_to_kmu_slot(key[0]);
Expand Down Expand Up @@ -225,7 +225,7 @@ void ss_utils_aes_encrypt(uint8_t *buffer, size_t buffer_len, const uint8_t *key
return;
}

int aes_128_encrypt_block(const uint8_t *key, const uint8_t *in, uint8_t *out)
int aes_128_encrypt_block(const uint8_t *key, const uint8_t *in, uint8_t *out)
{
uint8_t buffer_cpy[AES_BLOCKSIZE];
memcpy(buffer_cpy, in, AES_BLOCKSIZE);
Expand All @@ -235,7 +235,7 @@ int aes_128_encrypt_block(const uint8_t *key, const uint8_t *in, uint8_t *out)
}

int ss_utils_setup_key_helper(size_t key_len, uint8_t key[static key_len], int key_id, psa_key_usage_t usage_flags,
psa_algorithm_t alg, psa_key_type_t key_type)
psa_algorithm_t alg, psa_key_type_t key_type)
{
psa_status_t status;
psa_key_attributes_t key_attributes = PSA_KEY_ATTRIBUTES_INIT;
Expand Down Expand Up @@ -270,7 +270,7 @@ int ss_utils_setup_key_helper(size_t key_len, uint8_t key[static key_len], int k
return 0;
}

int ss_utils_setup_key(size_t key_len, uint8_t key[static key_len], enum key_identifier_base key_id)
int ss_utils_setup_key(size_t key_len, uint8_t key[static key_len], enum key_identifier_base key_id)
{
psa_status_t status;

Expand Down Expand Up @@ -307,7 +307,7 @@ int ss_utils_setup_key(size_t key_len, uint8_t key[static key_len], enum key_ide
return 0;
}

int ss_utils_check_key_existence(enum key_identifier_base key_id)
int ss_utils_check_key_existence(enum key_identifier_base key_id)
{
psa_status_t status;
status = psa_open_key((psa_key_id_t)key_id, &(psa_key_handle_t){0});
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions lib/fs_port.c → lib/ss_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include <zephyr/logging/log.h>
#include <zephyr/storage/flash_map.h>

#include "f_cache.h"
#include "provision.h"
#include "profile.h"
#include "ss_cache.h"
#include "ss_provision.h"
#include "ss_profile.h"
#include <onomondo/softsim/fs_port.h>
#include <onomondo/softsim/list.h>
#include <onomondo/softsim/utils.h>
Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions lib/profile.c → lib/ss_profile.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "profile.h"
#include "ss_profile.h"
#include <string.h>
#include <zephyr/kernel.h>

Expand All @@ -9,7 +9,7 @@ static void ss_hex_string_to_bytes(const uint8_t *hex, size_t hex_len, uint8_t b
* ASSERTions might be a bit agressive but reasoning behind is that this abosoletely
* cannot go wrong in prod.
*/
void decode_profile(size_t len, uint8_t data[static len], struct ss_profile *profile)
void decode_profile(size_t len, uint8_t data[static len], struct ss_profile *profile)
{
*profile = (struct ss_profile){0};

Expand All @@ -19,7 +19,7 @@ void decode_profile(size_t len, uint8_t data[static len], struct ss_profile *pro
size_t pos = 0;
size_t data_end = 0;
size_t data_start = 0;

while (pos < len - 2) {
uint8_t tag = ss_hex_to_uint8((char *)&data[pos]);
uint8_t data_len = ss_hex_to_uint8((char *)&data[pos + 2]);
Expand Down Expand Up @@ -72,7 +72,7 @@ void decode_profile(size_t len, uint8_t data[static len], struct ss_profile *pro
break;
}
}

// for now OPC must live here
memcpy(&profile->A001[KEY_SIZE], profile->OPC, KEY_SIZE);
// when KMU is invoked we pick key based on the tag passed.
Expand Down Expand Up @@ -104,15 +104,15 @@ void decode_profile(size_t len, uint8_t data[static len], struct ss_profile *pro
// profile->A004[header_size + KEY_SIZE + 1] = '6';
}

uint8_t ss_hex_to_uint8(const char *hex)
uint8_t ss_hex_to_uint8(const char *hex)
{
char hex_str[3] = {0};
hex_str[0] = hex[0];
hex_str[1] = hex[1];
return (hex_str[0] % 32 + 9) % 25 * 16 + (hex_str[1] % 32 + 9) % 25;
}

void ss_hex_string_to_bytes(const uint8_t *hex, size_t hex_len, uint8_t bytes[static hex_len / 2])
void ss_hex_string_to_bytes(const uint8_t *hex, size_t hex_len, uint8_t bytes[static hex_len / 2])
{
for (int i = 0; i < hex_len / 2; i++) {
bytes[i] = ss_hex_to_uint8((char *)&hex[i * 2]);
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions lib/provision.c → lib/ss_provision.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include <zephyr/sys/printk.h>

#include "f_cache.h"
#include "provision.h"
#include "ss_cache.h"
#include "ss_provision.h"
#include <onomondo/softsim/mem.h>

char storage_path[] = "";
Expand Down
File renamed without changes.

0 comments on commit ac91364

Please sign in to comment.