diff --git a/wolfcrypt/src/port/autosar/cryif.c b/wolfcrypt/src/port/autosar/cryif.c index 7ba2f01d5..80672e9e9 100644 --- a/wolfcrypt/src/port/autosar/cryif.c +++ b/wolfcrypt/src/port/autosar/cryif.c @@ -1,6 +1,6 @@ /* cryif.c * - * Copyright (C) 2006-2019 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * @@ -47,7 +47,13 @@ void CryIf_Init(const CryIf_ConfigType* in) void CryIf_GetVersionInfo(Std_VersionInfoType* ver) { - (void)ver; + if (ver != NULL) { + ver->vendorID = 0; /* no vendor or module ID */ + ver->moduleID = 0; + ver->sw_major_version = 5; + ver->sw_minor_version = 6; + ver->sw_patch_version = 6; + } } diff --git a/wolfcrypt/src/port/autosar/crypto.c b/wolfcrypt/src/port/autosar/crypto.c index 0b11b65f7..6296b4a1f 100644 --- a/wolfcrypt/src/port/autosar/crypto.c +++ b/wolfcrypt/src/port/autosar/crypto.c @@ -1,6 +1,6 @@ /* crypto.c * - * Copyright (C) 2006-2019 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * @@ -101,38 +101,44 @@ static int GetKey(Crypto_JobType* job, uint32 eId, uint8 **key, uint32 *keySz) } // @TODO sanity checks on setup... uint8 redirectionConfig; - if (eId == job->jobRedirectionInfoRef->inputKeyElementId) { - if (job->jobRedirectionInfoRef->inputKeyId >= MAX_KEYSTORE) { - WOLFSSL_MSG("Bogus input key ID redirection (too large)"); + switch (eid) { + case job->jobRedirectionInfoRef->inputKeyElementId: + if (job->jobRedirectionInfoRef->inputKeyId >= MAX_KEYSTORE) { + WOLFSSL_MSG("Bogus input key ID redirection (too large)"); + ret = -1; + } + else { + i = job->jobRedirectionInfoRef->inputKeyId; + *key = keyStore[i].key; + *keySz = keyStore[i].keyLen; + } + break; + case job->jobRedirectionInfoRef->secondaryInputKeyElementId: + if (job->jobRedirectionInfoRef->secondaryInputKeyId >= MAX_KEYSTORE) { + WOLFSSL_MSG("Bogus input key ID redirection (too large)"); + ret = -1; + } + else { + i = job->jobRedirectionInfoRef->secondaryInputKeyId; + *key = keyStore[i].key; + *keySz = keyStore[i].keyLen; + } + break; + case job->jobRedirectionInfoRef->tertiaryInputKeyElementId: + if (job->jobRedirectionInfoRef->tertiaryInputKeyId >= MAX_KEYSTORE) { + WOLFSSL_MSG("Bogus input key ID redirection (too large)"); + ret = -1; + } + else { + i = job->jobRedirectionInfoRef->tertiaryInputKeyId; + *key = keyStore[i].key; + *keySz = keyStore[i].keyLen; + } + break; + default: + WOLFSSL_MSG("Unknown key element ID"); ret = -1; - } - else { - i = job->jobRedirectionInfoRef->inputKeyId; - *key = keyStore[i].key; - *keySz = keyStore[i].keyLen; - } - } - if (eId == job->jobRedirectionInfoRef->secondaryInputKeyElementId) { - if (job->jobRedirectionInfoRef->secondaryInputKeyId >= MAX_KEYSTORE) { - WOLFSSL_MSG("Bogus input key ID redirection (too large)"); - ret = -1; - } - else { - i = job->jobRedirectionInfoRef->secondaryInputKeyId; - *key = keyStore[i].key; - *keySz = keyStore[i].keyLen; - } - } - if (eId == job->jobRedirectionInfoRef->tertiaryInputKeyElementId) { - if (job->jobRedirectionInfoRef->tertiaryInputKeyId >= MAX_KEYSTORE) { - WOLFSSL_MSG("Bogus input key ID redirection (too large)"); - ret = -1; - } - else { - i = job->jobRedirectionInfoRef->tertiaryInputKeyId; - *key = keyStore[i].key; - *keySz = keyStore[i].keyLen; - } + break; } #else /* find first key of key element type */ @@ -180,8 +186,15 @@ static Aes* NewAesStruct(Crypto_JobType* job) for (i = 0; i < MAX_JOBS; i++) { if (activeJobs[i].inUse == 0) { + int ret; + activeJobs[i].inUse = 1; activeJobs[i].jobId = job->jobId; + ret = wc_AesInit(&activeJobs[i].aes, NULL, INVALID_DEVID); + if (ret != 0) { + WOLFSSL_MSG("Error initializing AES structure"); + return NULL; + } return &activeJobs[i].aes; } } @@ -252,7 +265,7 @@ Std_ReturnType wolfSSL_Crypto_CBC(Crypto_JobType* job) WOLFSSL_MSG("Crypto error setting up AES key"); return E_NOT_OK; } - /* ForceZero(key, keySz); Do not keep raw key in memory */ + ForceZero(key, keySz); } if ((job->jobPrimitiveInputOutput.mode & CRYPTO_OPERATIONMODE_UPDATE) diff --git a/wolfcrypt/src/port/autosar/csm.c b/wolfcrypt/src/port/autosar/csm.c index 449b86993..11efa7b87 100644 --- a/wolfcrypt/src/port/autosar/csm.c +++ b/wolfcrypt/src/port/autosar/csm.c @@ -1,6 +1,6 @@ /* csm.c * - * Copyright (C) 2006-2019 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * @@ -156,18 +156,16 @@ void Csm_Init(const Csm_ConfigType* config) } -/* not yet implemented */ +/* getter function for CSM version info */ void Csm_GetVersionInfo(Std_VersionInfoType* version) { - (void)version; - - /* - version->vendorID = ; //uint16 - version->moduleID = ; //uint16 - version->sw_major_version = ; //uint8 - version->sw_minor_version = ; //uint8 - version->sw_patch_version = ; //uint8 - */ + if (version != NULL) { + version->vendorID = 0; /* no vendor or module ID */ + version->moduleID = 0; + version->sw_major_version = 5; + version->sw_minor_version = 6; + version->sw_patch_version = 6; + } } diff --git a/wolfcrypt/src/port/autosar/include.am b/wolfcrypt/src/port/autosar/include.am index 549199e8d..fe13f7dd4 100644 --- a/wolfcrypt/src/port/autosar/include.am +++ b/wolfcrypt/src/port/autosar/include.am @@ -3,7 +3,7 @@ EXTRA_DIST += wolfcrypt/src/port/autosar/csm.c \ wolfcrypt/src/port/autosar/crypto.c \ wolfcrypt/src/port/autosar/cryif.c \ wolfcrypt/src/port/autosar/README.md \ - wolfcrypt/src/port/autosar/example.c + wolfcrypt/src/port/autosar/test.c if BUILD_AUTOSAR src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/autosar/csm.c @@ -11,13 +11,13 @@ src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/autosar/crypto.c src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/autosar/cryif.c if BUILD_TESTS -check_PROGRAMS += wolfcrypt/src/port/autosar/example.test -noinst_PROGRAMS += wolfcrypt/src/port/autosar/example.test +check_PROGRAMS += wolfcrypt/src/port/autosar/test.test +noinst_PROGRAMS += wolfcrypt/src/port/autosar/test.test -wolfcrypt_src_port_autosar_example_test_SOURCES = \ - wolfcrypt/src/port/autosar/example.c -wolfcrypt_src_port_autosar_example_test_LDADD = \ +wolfcrypt_src_port_autosar_test_test_SOURCES = \ + wolfcrypt/src/port/autosar/test.c +wolfcrypt_src_port_autosar_test_test_LDADD = \ src/libwolfssl.la $(LIB_STATIC_ADD) -wolfcrypt_src_port_autosar_example_test_DEPENDENCIES = src/libwolfssl.la +wolfcrypt_src_port_autosar_test_test_DEPENDENCIES = src/libwolfssl.la endif endif diff --git a/wolfcrypt/src/port/autosar/example.c b/wolfcrypt/src/port/autosar/test.c similarity index 98% rename from wolfcrypt/src/port/autosar/example.c rename to wolfcrypt/src/port/autosar/test.c index 020f7d715..6ee9b2505 100644 --- a/wolfcrypt/src/port/autosar/example.c +++ b/wolfcrypt/src/port/autosar/test.c @@ -1,6 +1,6 @@ -/* example.c +/* test.c * - * Copyright (C) 2006-2019 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * @@ -46,8 +46,8 @@ static int singleshot_test(void) 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53, 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb }; - const uint8 key[] = "0123456789abcdef "; /* align */ - const uint8 iv[] = "1234567890abcdef "; /* align */ + const uint8 key[] = "0123456789abcdef "; + const uint8 iv[] = "1234567890abcdef "; XMEMSET(cipher, 0, BLOCK_SIZE); XMEMSET(plain, 0, BLOCK_SIZE); diff --git a/wolfssl/wolfcrypt/port/autosar/CryIf.h b/wolfssl/wolfcrypt/port/autosar/CryIf.h index f0f3613bc..9a75f4e87 100644 --- a/wolfssl/wolfcrypt/port/autosar/CryIf.h +++ b/wolfssl/wolfcrypt/port/autosar/CryIf.h @@ -1,6 +1,6 @@ /* CryIf.h * - * Copyright (C) 2006-2019 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * diff --git a/wolfssl/wolfcrypt/port/autosar/Crypto.h b/wolfssl/wolfcrypt/port/autosar/Crypto.h index 51d4fac13..f7b41f102 100644 --- a/wolfssl/wolfcrypt/port/autosar/Crypto.h +++ b/wolfssl/wolfcrypt/port/autosar/Crypto.h @@ -1,6 +1,6 @@ /* Crypto.h * - * Copyright (C) 2006-2019 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * diff --git a/wolfssl/wolfcrypt/port/autosar/Csm.h b/wolfssl/wolfcrypt/port/autosar/Csm.h index 653d98ade..513560215 100644 --- a/wolfssl/wolfcrypt/port/autosar/Csm.h +++ b/wolfssl/wolfcrypt/port/autosar/Csm.h @@ -1,6 +1,6 @@ /* csm.h * - * Copyright (C) 2006-2019 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * @@ -83,7 +83,7 @@ typedef enum Crypto_ServiceInfoType { CRYPTO_DECRYPT = 0x04, CRYPTO_RANDOMGENERATE = 0x0B, -#if 0 +#ifdef CSM_UNSUPPORTED_ALGS /* not yet supported */ CRYPTO_HASH = 0x00, CRYPTO_MACGENERATE = 0x01, @@ -107,7 +107,8 @@ typedef enum Crypto_ServiceInfoType { typedef enum Crypto_AlgorithmModeType { CRYPTO_ALGOMODE_NOT_SET = 0x00, CRYPTO_ALGOMODE_CBC = 0x02, -#if 0 + +#ifdef CSM_UNSUPPORTED_ALGS /* not yet supported */ CRYPTO_ALGOMODE_ECB = 0x01, CRYPTO_ALGOMODE_CFB = 0x03,