Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **API change** — all platform-level SecureElement initialization functions now require an additional `void *pArg` parameter ([51aa3f8](https://github.com/STMicroelectronics/STSELib/commit/51aa3f8114d33adfe38da6fd261e4b9a71a1fa9b))
- **Platform AES API change** — all platform AES cryptographic functions now reference keys by secure storage index (`PLAT_UI32 key_idx`) instead of raw key pointer and length (`PLAT_UI8 *pKey, PLAT_UI16 key_length`). Affected functions: `stse_platform_aes_cmac_init`, `stse_platform_aes_cmac_compute`, `stse_platform_aes_cmac_verify`, `stse_platform_aes_cbc_enc`, `stse_platform_aes_cbc_dec`, `stse_platform_aes_ecb_enc`
- **Renamed** `stsafea_open_host_session` to `stsafea_open_host_session_from_idx` — signature updated to accept key indices (`PLAT_UI32 host_MAC_key_idx`, `PLAT_UI32 host_cypher_key_idx`) instead of raw key pointers
- **printf() calls replaced** with `stse_platform_printf()` in all library code to abstract away standard I/O and allow platform-specific implementations for logging and output

### Added

- `stse_platform_store_aes_key()` — new platform function to store an AES key into platform secure storage and retrieve its index
- `stse_platform_delete_aes_key()` — new platform function to delete an AES key from platform secure storage by index
- `stse_platform_printf()` — new platform function for formatted output, replacing all direct calls to `printf()` in the library with this abstraction to allow platform-specific implementations and avoid direct use of standard I/O in library code

### Changed

Expand Down
14 changes: 7 additions & 7 deletions core/stse_frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,25 +164,25 @@ void stse_frame_debug_print(stse_frame_t *pFrame) {
PLAT_UI16 data_index;

if (pFrame->element_count == 0) {
printf("\n\r (EMPTY)");
stse_platform_printf("\n\r (EMPTY)");
return;
}
pCurrent_element = pFrame->first_element;
printf(" (%d-byte) :", pFrame->length);
stse_platform_printf(" (%d-byte) :", pFrame->length);
do {
printf(" { ");
stse_platform_printf(" { ");
if (pCurrent_element->length == 0) {
printf("S ");
stse_platform_printf("S ");
} else {
for (data_index = 0; data_index < pCurrent_element->length; data_index++) {
if (pCurrent_element->pData != NULL) {
printf("0x%02X ", pCurrent_element->pData[data_index]);
stse_platform_printf("0x%02X ", pCurrent_element->pData[data_index]);
} else {
printf("0x00 ");
stse_platform_printf("0x00 ");
}
}
}
printf("}");
stse_platform_printf("}");
pCurrent_element = pCurrent_element->next;
} while (pCurrent_element != NULL);
}
5 changes: 5 additions & 0 deletions core/stse_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ stse_ReturnCode_t stse_platform_crypto_init(void *pArg);
*/
stse_ReturnCode_t stse_platform_generate_random_init(void *pArg);

/*!
* \brief Platform log abstraction
*/
void stse_platform_printf(const char *format, ...);

/*!
* \brief Platform generate random callback function
* \return \ref STSE_OK on success; \ref stse_ReturnCode_t error code otherwise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Following platform files architecture are recommended to simplify the porting of
- @subpage stse_platform_power
- @subpage stse_platform_i2c
- @subpage stse_platform_st1wire
- @subpage stse_platform_log

# Reference Implementations

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# stse_platform_log.c {#stse_platform_log}

The `stse_platform_log.c` file provides string formatting and logging functions for the STSE library, abstracting the platform-specific details of standard output and debugging streams in order to don't be `stdio`-dependent and allow platform-specific implementations for logging and output.

## stse_platform_printf:
- **Purpose**: Provides a platform abstraction for formatted output, replacing all direct calls to `printf()` in the library with this function to allow platform-specific implementations and avoid direct use of standard I/O in library code.
- **Parameters**: Accepts a format string and a variable number of arguments, similar to the standard `printf()` function.
- **Return Value**: return void

## Implementation example:

```c
#include "stselib.h"

#include <stdio.h>
#include <stdarg.h>

void stse_platform_printf(const char *format, ...) {
va_list args;

va_start(args, format);
vprintf(format, args);
va_end(args);
}
```