F-1723 F-1724 F-1725 F-2908 F-2910 F-2911 F-3461 F-3683 F-3684 F-3891 F-4605 F-4606 F-4607: fix CAAM, Renesas, SGX, and UEFI examples issues

pull/594/head
Emma Stensland 2026-07-06 15:00:46 -06:00 committed by Paul Adelsbach
parent 9ac1bcbc4e
commit 1cedd247eb
9 changed files with 48 additions and 32 deletions

View File

@ -91,7 +91,7 @@ size_t _REL_sizeof_sysheap = SIZEOF_HEAP;
void main(void)
{
byte ret;
int ret;
R_SYSTEM_ClockInit();
R_SYSTEM_TimerInit();

View File

@ -108,18 +108,19 @@ static int load_rsa_private_key(RsaKey* pRsaKey)
static int sign_with_rsa_key(RsaKey* pRsaKey, WC_RNG* rng, const char* msg)
{
int ret;
/* Hash message to b signed */
if (hash_msg(msg, hash) != 0 ) {
ret = hash_msg(msg, hash);
if (ret != 0 ) {
goto sign_end;
}
printf("Signing hash of message\n");
/* RSA-PSS sign */
ret = wc_RsaPSS_Sign(hash, sizeof(hash), pSignature, sizeof(pSignature),
WC_HASH_TYPE_SHA256, WC_MGF1SHA256, pRsaKey, rng);
if (ret <= 0) {
printf(" RSA private encryption failed with error %d\n");
printf(" RSA private encryption failed with error %d\n", ret);
goto sign_end;
}
@ -135,7 +136,8 @@ static int verify_with_rsa_public_key(RsaKey* pRsaKey, const char* msg)
byte pDecrypted[RSA_KEY_SIZE/8];
byte* pt;
/* Hash message to be signed. */
if (hash_msg(msg, hash) != 0) {
ret = hash_msg(msg, hash);
if (ret != 0) {
goto verify_end;
}

View File

@ -336,7 +336,7 @@ int enc_wolfSSL_Cleanup(void)
/* free up all WOLFSSL_CTX's */
for (id = 0; id < MAX_WOLFSSL_CTX; id++)
RemoveCTX(id);
wolfSSL_Cleanup();
return wolfSSL_Cleanup();
}
void printf(const char *fmt, ...)
@ -349,16 +349,6 @@ void printf(const char *fmt, ...)
ocall_print_string(buf);
}
int sprintf(char* buf, const char *fmt, ...)
{
va_list ap;
int ret;
va_start(ap, fmt);
ret = vsnprintf(buf, BUFSIZ, fmt, ap);
va_end(ap);
return ret;
}
double current_time(void)
{
double curr;

View File

@ -27,7 +27,6 @@ extern "C" {
#endif
void printf(const char *fmt, ...);
int sprintf(char* buf, const char *fmt, ...);
double current_time(void);
#if defined(__cplusplus)

View File

@ -93,7 +93,11 @@ static int createSignature(ecc_key* key, byte* sigOut, word32* sigOutSz,
int ret;
WC_RNG rng;
wc_InitRng(&rng);
ret = wc_InitRng(&rng);
if (ret != 0) {
printf("wc_InitRng failed with error %d\n", ret);
return ret;
}
ret = wc_ecc_sign_hash(msg, msgSz, sigOut, sigOutSz, &rng, key);
if (ret != 0) {
printf("sign hash failed with error %d\n", ret);
@ -164,7 +168,12 @@ int main(int argc, char** argv)
printf("Could not initialize wolfSSL library!\n");
return -1;
}
wc_InitRng(&rng);
ret = wc_InitRng(&rng);
if (ret != 0) {
printf("wc_InitRng failed with error %d\n", ret);
wolfCrypt_Cleanup();
return -1;
}
XMEMSET(sig, 0, sigSz);
ret = createEccKey(&rng, &hardKey, 32, WOLFSSL_CAAM_DEVID);

View File

@ -97,7 +97,12 @@ int main(int argc, char** argv)
return -1;
}
wc_InitRng(&rng);
ret = wc_InitRng(&rng);
if (ret != 0) {
printf("wc_InitRng failed with error %d\n", ret);
wolfCrypt_Cleanup();
return -1;
}
ret = createEccKey(&rng, &hwKey, WOLFSSL_CAAM_DEVID);
if (ret != 0) {

View File

@ -158,6 +158,9 @@ int main(int argc, char** argv)
TestAesCbc(&enc, &dec);
wc_AesFree(&enc);
wc_AesFree(&dec);
wc_SECO_CloseHSM();
wolfCrypt_Cleanup();
return 0;

View File

@ -83,16 +83,16 @@ unsigned int calculateBufferSize(const char* msg, va_list args)
while (*p) {
if (*p == '%' && *(p + 1)) {
p++; // Move past '%'
if (*p == 's' || *p == 'a') { // Handle strings
p++; /* Move past '%' */
if (*p == 's' || *p == 'a') { /* Handle strings */
char* str = va_arg(args_copy, char*);
if (str) {
size += XSTRLEN(str); // Add the length of the string
size += XSTRLEN(str); /* Add the length of the string */
}
} else if (*p == 'd' || *p == 'u' || *p == 'x') {
va_arg(args_copy, int); // Skip integers
va_arg(args_copy, int); /* Skip integers */
} else if (*p == 'f') {
va_arg(args_copy, double); // Skip doubles
va_arg(args_copy, double); /* Skip doubles */
}
}
p++;
@ -527,7 +527,7 @@ FILE* fopen(const char* filename, const char* mode)
parseAndReplace(filename, temp, "/", "\\");
uefi_printf_wolfssl("Filename After: %s\n", filename);
//parseAndReplace(filename, temp, "./", "\\");
/* parseAndReplace(filename, temp, "./", "\\"); */
#else
temp = (char*)filename;
#endif
@ -628,6 +628,7 @@ int fclose(FILE* stream)
int ret = -1;
(void)stream;
EFI_FILE_HANDLE* fPtr = NULL;
EFI_STATUS status;
uefi_printf_debug("Inside custom fclose\n");
if (stream == NULL) {
@ -636,7 +637,8 @@ int fclose(FILE* stream)
}
fPtr = (EFI_FILE_HANDLE*)stream;
uefi_call_wrapper((*fPtr)->Close, 1, *fPtr);
status = uefi_call_wrapper((*fPtr)->Close, 1, *fPtr);
ret = EFI_ERROR(status) ? -1 : 0;
XFREE(fPtr, NULL, DYNAMIC_TYPE_TMP_BUFFER);
@ -1043,7 +1045,7 @@ size_t fwrite(const void* ptr, size_t size, size_t count, FILE* stream)
{
size_t ret = 0; /* Number of items successfully written */
EFI_FILE_HANDLE* fPtr = NULL;
//UINTN totalBytes = count * size * 8; /* Total bytes to write */
/* UINTN totalBytes = count * size * 8; -- Total bytes to write */
EFI_STATUS status;
uefi_printf_debug("Inside custom fwrite\n");
@ -1335,7 +1337,7 @@ unsigned long long current_time(int reset)
/* Convert to total seconds */
unsigned long long total_seconds =
//(days_since_epoch * 86400) + // Uncomment to return epoch time
/* (days_since_epoch * 86400) + -- Uncomment to return epoch time */
(time_uefi.Hour * 3600) +
(time_uefi.Minute * 60) +
time_uefi.Second;

View File

@ -13,10 +13,16 @@
#define uefi_printf(_f_, ...) Print(L##_f_, ##__VA_ARGS__)
void char8_to_char16(const char* str8, wchar_t* str16)
void char8_to_char16(const char* str8, wchar_t* str16, size_t cap)
{
size_t i;
size_t size_str8 = strlen(str8);
if (cap == 0) {
return;
}
if (size_str8 > cap - 1) {
size_str8 = cap - 1;
}
for (i = 0; i < size_str8; ++i) {
str16[i] = (wchar_t)str8[i];
}
@ -26,7 +32,7 @@ void char8_to_char16(const char* str8, wchar_t* str16)
void logging_cb(const int logLevel, const char *const logMessage)
{
wchar_t str16[STR_SIZE];
char8_to_char16(logMessage, str16);
char8_to_char16(logMessage, str16, STR_SIZE);
uefi_printf("%s", str16);
}