diff --git a/wolfcrypt/src/port/autosar/cryif.c b/wolfcrypt/src/port/autosar/cryif.c index 80672e9e9..0bd767b4b 100644 --- a/wolfcrypt/src/port/autosar/cryif.c +++ b/wolfcrypt/src/port/autosar/cryif.c @@ -28,6 +28,7 @@ #endif #include +#include #include #include #include @@ -50,9 +51,9 @@ void CryIf_GetVersionInfo(Std_VersionInfoType* 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; + ver->sw_major_version = (LIBWOLFSSL_VERSION_HEX >> 24) & 0xFFF; + ver->sw_minor_version = (LIBWOLFSSL_VERSION_HEX >> 12) & 0xFFF; + ver->sw_patch_version = (LIBWOLFSSL_VERSION_HEX) & 0xFFF; } } diff --git a/wolfcrypt/src/port/autosar/crypto.c b/wolfcrypt/src/port/autosar/crypto.c index 6296b4a1f..e124b3ca5 100644 --- a/wolfcrypt/src/port/autosar/crypto.c +++ b/wolfcrypt/src/port/autosar/crypto.c @@ -100,7 +100,7 @@ static int GetKey(Crypto_JobType* job, uint32 eId, uint8 **key, uint32 *keySz) return -1; } - // @TODO sanity checks on setup... uint8 redirectionConfig; + /* @TODO sanity checks on setup... uint8 redirectionConfig; */ switch (eid) { case job->jobRedirectionInfoRef->inputKeyElementId: if (job->jobRedirectionInfoRef->inputKeyId >= MAX_KEYSTORE) { @@ -331,11 +331,13 @@ Std_ReturnType wolfSSL_Crypto(Crypto_JobType* job) return ret; } +static WC_RNG rng; +static wolfSSL_Mutex rngMutex; +static volatile byte rngInit = 0; /* returns E_OK on success */ Std_ReturnType wolfSSL_Crypto_RNG(Crypto_JobType* job) { - WC_RNG rng; int ret; uint8 *out = job->jobPrimitiveInputOutput.outputPtr; @@ -346,10 +348,31 @@ Std_ReturnType wolfSSL_Crypto_RNG(Crypto_JobType* job) return E_NOT_OK; } - ret = wc_InitRng_ex(&rng, NULL, 0); - if (ret != 0) { - WOLFSSL_MSG("Error initializing RNG"); - return E_NOT_OK; + if (rngInit == 1) { + if (wc_LockMutex(&rngMutex) != 0) { + WOLFSSL_MSG("Error locking RNG mutex"); + return E_NOT_OK; + } + } + + if (rngInit == 0) { + if (wc_InitMutex(&rngMutex) != 0) { + WOLFSSL_MSG("Error initializing RNG mutex"); + return E_NOT_OK; + } + + if (wc_LockMutex(&rngMutex) != 0) { + WOLFSSL_MSG("Error locking RNG mutex"); + return E_NOT_OK; + } + + ret = wc_InitRng_ex(&rng, NULL, 0); + if (ret != 0) { + WOLFSSL_MSG("Error initializing RNG"); + wc_UnLockMutex(&rngMutex); + return E_NOT_OK; + } + rngInit = 1; } ret = wc_RNG_GenerateBlock(&rng, out, *outSz); @@ -359,14 +382,16 @@ Std_ReturnType wolfSSL_Crypto_RNG(Crypto_JobType* job) if (ret != 0) { WOLFSSL_MSG("Error free'ing RNG"); } + rngInit = 0; + wc_UnLockMutex(&rngMutex); return E_NOT_OK; } - ret = wc_FreeRng(&rng); - if (ret != 0) { - WOLFSSL_MSG("Error free'ing RNG"); + if (wc_UnLockMutex(&rngMutex) != 0) { + WOLFSSL_MSG("Error unlocking RNG mutex"); return E_NOT_OK; } + return E_OK; } diff --git a/wolfcrypt/src/port/autosar/csm.c b/wolfcrypt/src/port/autosar/csm.c index 11efa7b87..f5df124b9 100644 --- a/wolfcrypt/src/port/autosar/csm.c +++ b/wolfcrypt/src/port/autosar/csm.c @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -162,9 +163,9 @@ void Csm_GetVersionInfo(Std_VersionInfoType* version) 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; + version->sw_major_version = (LIBWOLFSSL_VERSION_HEX >> 24) & 0xFFF; + version->sw_minor_version = (LIBWOLFSSL_VERSION_HEX >> 12) & 0xFFF; + version->sw_patch_version = (LIBWOLFSSL_VERSION_HEX) & 0xFFF; } } diff --git a/wolfcrypt/src/port/autosar/test.c b/wolfcrypt/src/port/autosar/test.c index 6ee9b2505..4c311f189 100644 --- a/wolfcrypt/src/port/autosar/test.c +++ b/wolfcrypt/src/port/autosar/test.c @@ -121,8 +121,8 @@ static int update_test(void) 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74, 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20 }; - 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);