Skip to content

Commit e6997da

Browse files
committed
Change var name to inited, and only allow one init even when rekeying
1 parent 0b4c09c commit e6997da

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

src/we_aes_ctr.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ typedef struct we_AesCtr
3434
{
3535
/* The wolfSSL AES data object. */
3636
Aes aes;
37-
word32 keyed;
37+
word32 inited;
3838
} we_AesCtr;
3939

4040

@@ -69,12 +69,13 @@ static int we_aes_ctr_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
6969
}
7070

7171
/* Do not reinitialize if already keyed, unless setting a new key */
72-
if ((ret == 1) && ((aes->keyed == 0) || (key != NULL))) {
72+
if ((ret == 1) && (aes->inited == 0)) {
7373
rc = wc_AesInit(&aes->aes, NULL, INVALID_DEVID);
7474
if (rc != 0) {
7575
WOLFENGINE_ERROR_FUNC(WE_LOG_CIPHER, "wc_AesInit", rc);
7676
ret = 0;
7777
}
78+
aes->inited = 1;
7879
}
7980
if ((ret == 1) && (key != NULL)) {
8081
if (tmpIv == NULL) {
@@ -88,7 +89,6 @@ static int we_aes_ctr_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
8889
WOLFENGINE_ERROR_FUNC(WE_LOG_CIPHER, "wc_AesSetKey", rc);
8990
ret = 0;
9091
}
91-
aes->keyed = 1;
9292
}
9393
if ((ret == 1) && (iv != NULL)) {
9494
rc = wc_AesSetIV(&aes->aes, iv);

test/test_cipher.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,11 +603,16 @@ int test_aes_ctr_leftover_data_regression(ENGINE *e, void *data)
603603
* The EVP_CIPHER_CTX remembers any engine it was loaded with, meaning we
604604
* need to reset the ctxs before reuse or the decCtx will still pick up
605605
* wolfEngine */
606+
if (encCtx != NULL)
607+
EVP_CIPHER_CTX_free(encCtx);
608+
if (decCtx != NULL)
609+
EVP_CIPHER_CTX_free(decCtx);
610+
606611
if (err == 0) {
607-
err = EVP_CIPHER_CTX_reset(encCtx) != 1;
612+
err = (encCtx = EVP_CIPHER_CTX_new()) == NULL;
608613
}
609614
if (err == 0) {
610-
err = EVP_CIPHER_CTX_reset(decCtx) != 1;
615+
err = (decCtx = EVP_CIPHER_CTX_new()) == NULL;
611616
}
612617

613618
if (err == 0) {

0 commit comments

Comments
 (0)