Skip to content

Commit 30cb25e

Browse files
committed
Fixes from AI review
1 parent b5c5327 commit 30cb25e

50 files changed

Lines changed: 791 additions & 385 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

wolfcrypt/src/port/Espressif/esp32_aes.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -475,15 +475,17 @@ int wc_esp32AesDecrypt(Aes *aes, const byte* in, byte* out)
475475

476476
ESP_LOGV(TAG, "enter wc_esp32AesDecrypt");
477477
/* lock the hw engine */
478-
esp_aes_hw_InUse();
479-
/* load the key into the register */
480-
ret = esp_aes_hw_Set_KeyMode(aes, ESP32_AES_UPDATEKEY_DECRYPT);
481-
if (ret != ESP_OK) {
482-
ESP_LOGE(TAG, "wc_esp32AesDecrypt failed "
483-
"during esp_aes_hw_Set_KeyMode");
484-
/* release hw */
485-
esp_aes_hw_Leave();
486-
ret = BAD_FUNC_ARG;
478+
ret = esp_aes_hw_InUse();
479+
if (ret == ESP_OK) {
480+
/* load the key into the register */
481+
ret = esp_aes_hw_Set_KeyMode(aes, ESP32_AES_UPDATEKEY_DECRYPT);
482+
if (ret != ESP_OK) {
483+
ESP_LOGE(TAG, "wc_esp32AesDecrypt failed "
484+
"during esp_aes_hw_Set_KeyMode");
485+
/* release hw */
486+
esp_aes_hw_Leave();
487+
ret = BAD_FUNC_ARG;
488+
}
487489
}
488490

489491
if (ret == ESP_OK) {
@@ -606,9 +608,9 @@ int wc_esp32AesCbcDecrypt(Aes* aes, byte* out, const byte* in, word32 sz)
606608

607609
offset += WC_AES_BLOCK_SIZE;
608610
} /* while (blocks--) */
609-
esp_aes_hw_Leave();
610611
} /* if Set Mode was successful (ret == ESP_OK) */
611612

613+
esp_aes_hw_Leave();
612614
ESP_LOGV(TAG, "leave wc_esp32AesCbcDecrypt");
613615
return ret;
614616
} /* wc_esp32AesCbcDecrypt */

wolfcrypt/src/port/Espressif/esp32_mp.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2249,6 +2249,9 @@ int esp_mp_mulmod(MATH_INT_T* X, MATH_INT_T* Y, MATH_INT_T* M, MATH_INT_T* Z)
22492249
#ifdef WOLFSSL_DEBUG_ESP_HW_MOD_RSAMAX_BITS
22502250
ESP_LOGW(TAG, "result exceeds max bit length");
22512251
#endif
2252+
if (mulmod_lock_called) {
2253+
esp_mp_hw_unlock();
2254+
}
22522255
return MP_HW_FALLBACK; /* Error: value is not able to be used. */
22532256
}
22542257
WordsForOperand = bits2words(OperandBits);
@@ -2343,7 +2346,7 @@ int esp_mp_mulmod(MATH_INT_T* X, MATH_INT_T* Y, MATH_INT_T* M, MATH_INT_T* Z)
23432346
OperandBits, ESP_HW_MOD_RSAMAX_BITS);
23442347
#endif
23452348
if (mulmod_lock_called) {
2346-
ret = esp_mp_hw_unlock();
2349+
esp_mp_hw_unlock();
23472350
}
23482351
return MP_HW_FALLBACK; /* Error: value is not able to be used. */
23492352
}
@@ -2440,6 +2443,9 @@ int esp_mp_mulmod(MATH_INT_T* X, MATH_INT_T* Y, MATH_INT_T* M, MATH_INT_T* Z)
24402443
ESP_LOGW(TAG, "mp_mulmod OperandBits %d exceeds max bit length %d.",
24412444
OperandBits, ESP_HW_MOD_RSAMAX_BITS);
24422445
#endif
2446+
if (mulmod_lock_called) {
2447+
esp_mp_hw_unlock();
2448+
}
24432449
return MP_HW_FALLBACK; /* Error: value is not able to be used. */
24442450
}
24452451
WordsForOperand = bits2words(OperandBits);

wolfcrypt/src/port/Espressif/esp32_util.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,7 @@ int show_binary(byte* theVar, size_t dataSz) {
10071007
return 0;
10081008
}
10091009

1010+
/* Assume toVar is big enough. */
10101011
int hexToBinary(byte* toVar, const char* fromHexString, size_t szHexString ) {
10111012
int ret = 0;
10121013
/* Calculate the actual binary length of the hex string */
@@ -1018,6 +1019,7 @@ int hexToBinary(byte* toVar, const char* fromHexString, size_t szHexString ) {
10181019
}
10191020
if ((szHexString % 2 != 0)) {
10201021
ESP_LOGE("ssh", "fromHexString length not even!");
1022+
return -1;
10211023
}
10221024

10231025
ESP_LOGW(TAG, "Replacing %d bytes at %x", byteLen, (word32)toVar);

wolfcrypt/src/port/Espressif/esp_sdk_time_lib.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ int set_fixed_default_time(void)
189189
struct tm timeinfo = {
190190
.tm_year = YEAR - 1900, /* years since 1900 */
191191
.tm_mon = MONTH - 1, /* Month, where 0 = Jan */
192-
.tm_mday = DAY - 1, /* Numeric decimal day of the month */
192+
.tm_mday = DAY, /* Numeric decimal day of the month */
193193
.tm_hour = 13,
194194
.tm_min = 1,
195195
.tm_sec = 5
@@ -276,7 +276,7 @@ int set_time_from_string(const char* time_buffer)
276276
char offset[28]; /* large arrays, just in case there's still bad data */
277277
char day_str[28];
278278
char month_str[28];
279-
const char *format = "%3s %3s %d %d:%d:%d %d %s";
279+
const char *format = "%3s %3s %d %d:%d:%d %d %27s";
280280
struct tm this_timeinfo;
281281
struct timeval now;
282282
time_t interim_time;
@@ -304,18 +304,23 @@ int set_time_from_string(const char* time_buffer)
304304
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
305305
};
306306

307-
for (int i = 0; i < 12; i++) {
307+
int i;
308+
for (i = 0; i < 12; i++) {
308309
if (strcmp(month_str, months[i]) == 0) {
309310
this_timeinfo.tm_mon = i;
310311
break;
311312
}
312313
}
314+
if (i == 12) {
315+
return ESP_FAIL;
316+
}
313317

314318
this_timeinfo.tm_mday = day;
315319
this_timeinfo.tm_hour = hour;
316320
this_timeinfo.tm_min = minute;
317321
this_timeinfo.tm_sec = second;
318322
this_timeinfo.tm_year = year - 1900; /* Years since 1900 */
323+
this_timeinfo.tm_isdst = -1;
319324

320325
interim_time = mktime(&this_timeinfo);
321326
now = (struct timeval){ .tv_sec = interim_time };
@@ -397,11 +402,11 @@ int set_time(void)
397402
}
398403
ESP_LOGI(TAG, "sntp_setservername:");
399404
for (i = 0; i < CONFIG_LWIP_SNTP_MAX_SERVERS; i++) {
400-
const char* thisServer = ntpServerList[i];
401-
if (strncmp(thisServer, "\x00", 1) == 0) {
402-
/* just in case we run out of NTP servers */
403-
break;
405+
const char* thisServer;
406+
if (i >= NTP_SERVER_COUNT) {
407+
break;
404408
}
409+
thisServer = ntpServerList[i];
405410
ESP_LOGI(TAG, "%s", thisServer);
406411
sntp_setservername(i, thisServer);
407412
ret = ESP_OK;

wolfcrypt/src/port/Espressif/esp_sdk_wifi_lib.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ static EventGroupHandle_t s_wifi_event_group;
324324

325325

326326
static int s_retry_num = 0;
327+
/* TODO: use event in wc_wifi_show_ip - logging the IP string causes a panic. */
327328
ip_event_got_ip_t* event;
328329

329330

wolfcrypt/src/port/Renesas/renesas_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,12 +440,12 @@ int wc_CryptoCb_CryptInitRenesasCmn(struct WOLFSSL* ssl, void* ctx)
440440
if (cbInfo->internal == NULL) {
441441
return MEMORY_E;
442442
}
443+
ForceZero(cbInfo->internal, internal_sz);
443444
#if defined(WOLFSSL_RENESAS_FSPSM_TLS) ||\
444445
defined(WOLFSSL_RENESAS_TSIP_TLS)
445446
if (ssl)
446447
cbInfo->internal->heap = ssl->heap;
447448
#endif
448-
ForceZero(cbInfo->internal, internal_sz);
449449
}
450450
/* need exclusive control because of static variable */
451451
if ((cmn_hw_lock()) == 0) {

wolfcrypt/src/port/Renesas/renesas_fspsm_rsa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ WOLFSSL_LOCAL int wc_fspsm_RsaSign(const byte* in, word32 inLen, byte* out,
248248
message_hash.data_type =
249249
info->keyflgs_crypt.bits.message_type;/* message 0, hash 1 */
250250
signature.pdata = out;
251-
signature.data_length = (word32*)outLen;
251+
signature.data_length = *outLen;
252252

253253
#if defined(WOLFSSL_RENESAS_RSIP)
254254
message_hash.hash_type = signature.hash_type =

wolfcrypt/src/port/Renesas/renesas_fspsm_sha.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ int wc_Sha512_256Final(wc_Sha512* sha, byte* hash)
785785
}
786786
int wc_Sha512_256GetHash(wc_Sha512* sha, byte* hash)
787787
{
788-
return FSPSM_HashGet(sha, hash, WC_SHA512_224_DIGEST_SIZE);
788+
return FSPSM_HashGet(sha, hash, WC_SHA512_256_DIGEST_SIZE);
789789
}
790790

791791
int wc_Sha512_256Copy(wc_Sha512* src, wc_Sha512* dst)

wolfcrypt/src/port/Renesas/renesas_fspsm_util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ int wc_fspsm_GenerateRandBlock(byte* output, word32 sz)
195195
uint32_t fspbuf[RANDGEN_WORDS];
196196

197197
while (sz > 0) {
198-
word32 len = sizeof(buffer);
198+
word32 len = sizeof(fspbuf);
199199

200200
if (sz < len) {
201201
len = sz;

wolfcrypt/src/port/Renesas/renesas_tsip_aes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ WOLFSSL_LOCAL int tsip_Tls13AesDecrypt(
261261

262262
WOLFSSL_ENTER("tsip_Tls13AesDecrypt");
263263

264-
if ((ssl == NULL) || (input == NULL) || (output == NULL) || (sz == 0) ||
265-
(ssl->RenesasUserCtx == NULL)) {
264+
if ((ssl == NULL) || (input == NULL) || (output == NULL) ||
265+
(sz < TSIP_AES_GCM_AUTH_TAG_SIZE) || (ssl->RenesasUserCtx == NULL)) {
266266
return BAD_FUNC_ARG;
267267
}
268268

0 commit comments

Comments
 (0)