Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/we_aes_ctr.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ typedef struct we_AesCtr
{
/* The wolfSSL AES data object. */
Aes aes;
word32 inited;
} we_AesCtr;


Expand Down Expand Up @@ -67,12 +68,14 @@ static int we_aes_ctr_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
ret = 0;
}

if (ret == 1) {
/* Do not reinitialize if already keyed, unless setting a new key */
if ((ret == 1) && (aes->inited == 0)) {
rc = wc_AesInit(&aes->aes, NULL, INVALID_DEVID);
if (rc != 0) {
WOLFENGINE_ERROR_FUNC(WE_LOG_CIPHER, "wc_AesInit", rc);
ret = 0;
}
aes->inited = 1;
}
if ((ret == 1) && (key != NULL)) {
if (tmpIv == NULL) {
Expand All @@ -94,7 +97,7 @@ static int we_aes_ctr_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
ret = -1;
}
else {
/*
/*
* wc_AesSetIV should clear this field, but it doesn't in some
* wolfSSL versions.
*/
Expand Down
21 changes: 20 additions & 1 deletion test/test_cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,26 @@ int test_aes_ctr_leftover_data_regression(ENGINE *e, void *data)
}
}

/* Try the other way, now. Encrypt with wolfEngine, decrypt with wolfSSL. */
/* Try the other way, now. Encrypt with wolfEngine, decrypt with openSSL.
* The EVP_CIPHER_CTX remembers any engine it was loaded with, meaning we
* need to reset the ctxs before reuse or the decCtx will still pick up
* wolfEngine */
if (err == 0) {
if (encCtx != NULL)
EVP_CIPHER_CTX_free(encCtx);
}
if (err == 0) {
if (decCtx != NULL)
EVP_CIPHER_CTX_free(decCtx);
}

if (err == 0) {
err = (encCtx = EVP_CIPHER_CTX_new()) == NULL;
}
if (err == 0) {
err = (decCtx = EVP_CIPHER_CTX_new()) == NULL;
}

if (err == 0) {
err = EVP_CipherInit_ex(encCtx, EVP_aes_128_ctr(), e, key,
NULL, -1) != 1;
Expand Down