Skip to content

Commit 689a82a

Browse files
committed
fix AES-related code, in both crypto and TLS layers, for various uninitialized data and resource leak defects around wc_AesInit() and wc_AesFree():
* followup to #7009 "20231128-misc-fixes" and #7011 "Add missing wc_AesInit calls." * adds WC_DEBUG_CIPHER_LIFECYCLE, which embeds asserts in low-level AES implementations for proper usage of wc_AesInit() and wc_AesFree(). * fixes native CMAC, AES-EAX, and AES-XTS implementations to assure resource release. * adds missing wc_AesXtsInit() API, and adds a new wc_AesXtsSetKey_NoInit(). * fixes misspellings in EVP that unconditionally gated out AES-OFB and AES-XTS. * fixes misspellings in EVP that unconditionally gated out AES-CBC and AES-CFB code in wolfSSL_EVP_CIPHER_CTX_cleanup_cipher(). * openssl compat AES low level cipher API has no counterpart to wc_AesFree(), so these compat APIs will now be gated out in configurations where they would otherwise leak memory or file descriptors (WOLFSSL_AFALG, WOLFSSL_DEVCRYPTO, WOLF_CRYPTO_CB, etc.). A new macro, WC_AESFREE_IS_MANDATORY, is defined in wolfcrypt/aes.h to streamline this dependency. * fixes 40 missing EVP_CIPHER_CTX_cleanup()s and 11 wc_AesFree()s in src/ssl.c, src/ssl_crypto.c, tests/api.c, and wolfcrypt/test/test.c.
1 parent 7753e3d commit 689a82a

16 files changed

Lines changed: 898 additions & 218 deletions

File tree

src/quic.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,7 @@ size_t wolfSSL_quic_get_aead_tag_len(const WOLFSSL_EVP_CIPHER* aead_cipher)
10551055
ret = 0;
10561056
}
10571057

1058+
(void)wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
10581059
#ifdef WOLFSSL_SMALL_STACK
10591060
XFREE(ctx, NULL, DYNAMIC_TYPE_TMP_BUFFER);
10601061
#endif

src/ssl.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29665,6 +29665,8 @@ static int wolfSSL_TicketKeyCb(WOLFSSL* ssl,
2966529665
end:
2966629666

2966729667
(void)wc_HmacFree(&hmacCtx.hmac);
29668+
(void)wolfSSL_EVP_CIPHER_CTX_cleanup(evpCtx);
29669+
2966829670
#ifdef WOLFSSL_SMALL_STACK
2966929671
XFREE(evpCtx, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER);
2967029672
#endif

src/ssl_crypto.c

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,14 +2079,10 @@ WOLFSSL_CMAC_CTX* wolfSSL_CMAC_CTX_new(void)
20792079
ctx = (WOLFSSL_CMAC_CTX*)XMALLOC(sizeof(WOLFSSL_CMAC_CTX), NULL,
20802080
DYNAMIC_TYPE_OPENSSL);
20812081
if (ctx != NULL) {
2082-
/* Allocate memory for wolfSSL CMAC object. */
2083-
ctx->internal = (Cmac*)XMALLOC(sizeof(Cmac), NULL, DYNAMIC_TYPE_CMAC);
2084-
if (ctx->internal == NULL) {
2085-
XFREE(ctx, NULL, DYNAMIC_TYPE_OPENSSL);
2086-
ctx = NULL;
2087-
}
2088-
}
2089-
if (ctx != NULL) {
2082+
/* Memory for wolfSSL CMAC object is allocated in
2083+
* wolfSSL_CMAC_Init().
2084+
*/
2085+
ctx->internal = NULL;
20902086
/* Allocate memory for EVP cipher context object. */
20912087
ctx->cctx = wolfSSL_EVP_CIPHER_CTX_new();
20922088
if (ctx->cctx == NULL) {
@@ -2110,9 +2106,11 @@ void wolfSSL_CMAC_CTX_free(WOLFSSL_CMAC_CTX *ctx)
21102106
if (ctx != NULL) {
21112107
/* Deallocate dynamically allocated fields. */
21122108
if (ctx->internal != NULL) {
2109+
wc_CmacFinal((Cmac*)ctx->internal, NULL, NULL);
21132110
XFREE(ctx->internal, NULL, DYNAMIC_TYPE_CMAC);
21142111
}
21152112
if (ctx->cctx != NULL) {
2113+
wolfSSL_EVP_CIPHER_CTX_cleanup(ctx->cctx);
21162114
wolfSSL_EVP_CIPHER_CTX_free(ctx->cctx);
21172115
}
21182116
/* Deallocate CMAC context object. */
@@ -2167,22 +2165,37 @@ int wolfSSL_CMAC_Init(WOLFSSL_CMAC_CTX* ctx, const void *key, size_t keySz,
21672165
/* Only AES-CBC ciphers are supported. */
21682166
if ((ret == 1) && (cipher != EVP_AES_128_CBC) &&
21692167
(cipher != EVP_AES_192_CBC) && (cipher != EVP_AES_256_CBC)) {
2168+
WOLFSSL_MSG("wolfSSL_CMAC_Init: requested cipher is unsupported");
21702169
ret = 0;
21712170
}
21722171
/* Key length must match cipher. */
21732172
if ((ret == 1) && ((int)keySz != wolfSSL_EVP_Cipher_key_length(cipher))) {
2173+
WOLFSSL_MSG("wolfSSL_CMAC_Init: "
2174+
"supplied key size doesn't match requested cipher");
21742175
ret = 0;
21752176
}
21762177

2178+
if ((ret == 1) && (ctx->internal == NULL)) {
2179+
/* Allocate memory for wolfSSL CMAC object. */
2180+
ctx->internal = (Cmac*)XMALLOC(sizeof(Cmac), NULL, DYNAMIC_TYPE_CMAC);
2181+
if (ctx->internal == NULL)
2182+
ret = 0;
2183+
}
2184+
21772185
/* Initialize the wolfCrypt CMAC object. */
21782186
if ((ret == 1) && (wc_InitCmac((Cmac*)ctx->internal, (const byte*)key,
21792187
(word32)keySz, WC_CMAC_AES, NULL) != 0)) {
2188+
WOLFSSL_MSG("wolfSSL_CMAC_Init: wc_InitCmac() failed");
2189+
XFREE(ctx->internal, NULL, DYNAMIC_TYPE_CMAC);
2190+
ctx->internal = NULL;
21802191
ret = 0;
21812192
}
21822193
if (ret == 1) {
21832194
/* Initialize the EVP cipher context object for encryption. */
21842195
ret = wolfSSL_EVP_CipherInit(ctx->cctx, cipher, (const byte*)key, NULL,
21852196
1);
2197+
if (ret != WOLFSSL_SUCCESS)
2198+
WOLFSSL_MSG("wolfSSL_CMAC_Init: wolfSSL_EVP_CipherInit() failed");
21862199
}
21872200

21882201
WOLFSSL_LEAVE("wolfSSL_CMAC_Init", ret);
@@ -2237,7 +2250,7 @@ int wolfSSL_CMAC_Final(WOLFSSL_CMAC_CTX* ctx, unsigned char* out, size_t* len)
22372250

22382251
WOLFSSL_ENTER("wolfSSL_CMAC_Final");
22392252

2240-
/* Valiudate parameters. */
2253+
/* Validate parameters. */
22412254
if (ctx == NULL) {
22422255
ret = 0;
22432256
}
@@ -2268,6 +2281,9 @@ int wolfSSL_CMAC_Final(WOLFSSL_CMAC_CTX* ctx, unsigned char* out, size_t* len)
22682281
else if (len != NULL) {
22692282
*len = (size_t)len32;
22702283
}
2284+
2285+
XFREE(ctx->internal, NULL, DYNAMIC_TYPE_CMAC);
2286+
ctx->internal = NULL;
22712287
}
22722288

22732289
WOLFSSL_LEAVE("wolfSSL_CMAC_Final", ret);
@@ -2899,7 +2915,7 @@ void wolfSSL_DES_ecb_encrypt(WOLFSSL_DES_cblock* in, WOLFSSL_DES_cblock* out,
28992915

29002916
#ifdef OPENSSL_EXTRA
29012917

2902-
#ifndef NO_AES
2918+
#if !defined(NO_AES) && !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
29032919

29042920
/* Sets the key into the AES key object for encryption or decryption.
29052921
*
@@ -3408,7 +3424,7 @@ size_t wolfSSL_CRYPTO_cts128_decrypt(const unsigned char *in,
34083424
return len;
34093425
}
34103426
#endif /* HAVE_CTS */
3411-
#endif /* NO_AES */
3427+
#endif /* !NO_AES && !WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API */
34123428
#endif /* OPENSSL_EXTRA */
34133429

34143430
/*******************************************************************************

tests/api.c

Lines changed: 71 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5680,7 +5680,7 @@ static int test_wolfSSL_EVP_CIPHER_CTX(void)
56805680
return 0;
56815681
}
56825682

5683-
static WC_INLINE int myTicketEncCbOpenSSL(WOLFSSL* ssl,
5683+
static int myTicketEncCbOpenSSL(WOLFSSL* ssl,
56845684
byte name[WOLFSSL_TICKET_NAME_SZ],
56855685
byte iv[WOLFSSL_TICKET_IV_SZ],
56865686
WOLFSSL_EVP_CIPHER_CTX *ectx,
@@ -15994,6 +15994,10 @@ static int test_wc_AesGcmStream(void)
1599415994
ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
1599515995

1599615996
/* Set key and IV through streaming init API. */
15997+
wc_AesFree(aesEnc);
15998+
wc_AesFree(aesDec);
15999+
ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
16000+
ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
1599716001
ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), iv, AES_IV_SIZE), 0);
1599816002
ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
1599916003
/* Encrypt/decrypt one block and AAD of one block. */
@@ -16007,6 +16011,10 @@ static int test_wc_AesGcmStream(void)
1600716011
ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
1600816012

1600916013
/* Set key and IV through streaming init API. */
16014+
wc_AesFree(aesEnc);
16015+
wc_AesFree(aesDec);
16016+
ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
16017+
ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
1601016018
ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), iv, AES_IV_SIZE), 0);
1601116019
ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
1601216020
/* No data to encrypt/decrypt one byte of AAD. */
@@ -16018,6 +16026,10 @@ static int test_wc_AesGcmStream(void)
1601816026
ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
1601916027

1602016028
/* Set key and IV through streaming init API. */
16029+
wc_AesFree(aesEnc);
16030+
wc_AesFree(aesDec);
16031+
ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
16032+
ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
1602116033
ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), iv, AES_IV_SIZE), 0);
1602216034
ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
1602316035
/* Encrypt/decrypt one byte and no AAD. */
@@ -16030,6 +16042,10 @@ static int test_wc_AesGcmStream(void)
1603016042
ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
1603116043

1603216044
/* Set key and IV through streaming init API. */
16045+
wc_AesFree(aesEnc);
16046+
wc_AesFree(aesDec);
16047+
ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
16048+
ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
1603316049
ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), iv, AES_IV_SIZE), 0);
1603416050
ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
1603516051
/* Encryption AES is one byte at a time */
@@ -16057,6 +16073,9 @@ static int test_wc_AesGcmStream(void)
1605716073
ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
1605816074

1605916075
/* Check streaming encryption can be decrypted with one shot. */
16076+
wc_AesFree(aesDec);
16077+
ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
16078+
ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
1606016079
ExpectIntEQ(wc_AesGcmSetKey(aesDec, key, sizeof(key)), 0);
1606116080
ExpectIntEQ(wc_AesGcmDecrypt(aesDec, plain, out, sizeof(in), iv,
1606216081
AES_IV_SIZE, tag, AES_BLOCK_SIZE, aad, sizeof(aad)), 0);
@@ -17612,7 +17631,6 @@ static int test_wc_AesCbcEncryptDecrypt(void)
1761217631
ExpectIntEQ(wc_AesSetKey(&aes, key32, AES_BLOCK_SIZE * 2, iv,
1761317632
AES_ENCRYPTION), 0);
1761417633
ExpectIntEQ(wc_AesCbcEncrypt(&aes, enc, vector, sizeof(vector)), 0);
17615-
wc_AesFree(&aes);
1761617634

1761717635
/* Re init for decrypt and set flag. */
1761817636
ExpectIntEQ(wc_AesSetKey(&aes, key32, AES_BLOCK_SIZE * 2, iv,
@@ -18154,13 +18172,13 @@ static int test_wc_GmacUpdate(void)
1815418172
XMEMSET(tagOut2, 0, sizeof(tagOut2));
1815518173
XMEMSET(tagOut3, 0, sizeof(tagOut3));
1815618174

18157-
ExpectIntEQ(wc_AesInit(&gmac.aes, NULL, INVALID_DEVID), 0);
18158-
1815918175
#ifdef WOLFSSL_AES_128
18176+
ExpectIntEQ(wc_AesInit(&gmac.aes, NULL, INVALID_DEVID), 0);
1816018177
ExpectIntEQ(wc_GmacSetKey(&gmac, key16, sizeof(key16)), 0);
1816118178
ExpectIntEQ(wc_GmacUpdate(&gmac, iv, sizeof(iv), authIn, sizeof(authIn),
1816218179
tagOut, sizeof(tag1)), 0);
1816318180
ExpectIntEQ(XMEMCMP(tag1, tagOut, sizeof(tag1)), 0);
18181+
wc_AesFree(&gmac.aes);
1816418182
#endif
1816518183

1816618184
#ifdef WOLFSSL_AES_192
@@ -18170,6 +18188,7 @@ static int test_wc_GmacUpdate(void)
1817018188
ExpectIntEQ(wc_GmacUpdate(&gmac, iv2, sizeof(iv2), authIn2, sizeof(authIn2),
1817118189
tagOut2, sizeof(tag2)), 0);
1817218190
ExpectIntEQ(XMEMCMP(tagOut2, tag2, sizeof(tag2)), 0);
18191+
wc_AesFree(&gmac.aes);
1817318192
#endif
1817418193

1817518194
#ifdef WOLFSSL_AES_256
@@ -18179,17 +18198,19 @@ static int test_wc_GmacUpdate(void)
1817918198
ExpectIntEQ(wc_GmacUpdate(&gmac, iv3, sizeof(iv3), authIn3, sizeof(authIn3),
1818018199
tagOut3, sizeof(tag3)), 0);
1818118200
ExpectIntEQ(XMEMCMP(tag3, tagOut3, sizeof(tag3)), 0);
18201+
wc_AesFree(&gmac.aes);
1818218202
#endif
1818318203

1818418204
/* Pass bad args. */
18205+
ExpectIntEQ(wc_AesInit(&gmac.aes, NULL, INVALID_DEVID), 0);
1818518206
ExpectIntEQ(wc_GmacUpdate(NULL, iv3, sizeof(iv3), authIn3, sizeof(authIn3),
1818618207
tagOut3, sizeof(tag3)), BAD_FUNC_ARG);
1818718208
ExpectIntEQ(wc_GmacUpdate(&gmac, iv3, sizeof(iv3), authIn3, sizeof(authIn3),
1818818209
tagOut3, sizeof(tag3) - 5), BAD_FUNC_ARG);
1818918210
ExpectIntEQ(wc_GmacUpdate(&gmac, iv3, sizeof(iv3), authIn3, sizeof(authIn3),
1819018211
tagOut3, sizeof(tag3) + 1), BAD_FUNC_ARG);
18191-
1819218212
wc_AesFree(&gmac.aes);
18213+
1819318214
#endif
1819418215
return EXPECT_RESULT();
1819518216
} /* END test_wc_GmacUpdate */
@@ -42239,7 +42260,8 @@ static int test_wolfSSL_DES_ede3_cbc_encrypt(void)
4223942260
static int test_wolfSSL_AES_encrypt(void)
4224042261
{
4224142262
EXPECT_DECLS;
42242-
#if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AES_ECB)
42263+
#if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AES_ECB) \
42264+
&& !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
4224342265
AES_KEY enc;
4224442266
AES_KEY dec;
4224542267
const byte msg[] = {
@@ -42289,7 +42311,8 @@ static int test_wolfSSL_AES_encrypt(void)
4228942311
static int test_wolfSSL_AES_ecb_encrypt(void)
4229042312
{
4229142313
EXPECT_DECLS;
42292-
#if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AES_ECB)
42314+
#if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AES_ECB) \
42315+
&& !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
4229342316
AES_KEY aes;
4229442317
const byte msg[] =
4229542318
{
@@ -42337,7 +42360,8 @@ static int test_wolfSSL_AES_ecb_encrypt(void)
4233742360
static int test_wolfSSL_AES_cbc_encrypt(void)
4233842361
{
4233942362
EXPECT_DECLS;
42340-
#if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(OPENSSL_EXTRA)
42363+
#if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(OPENSSL_EXTRA) && \
42364+
!defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
4234142365
AES_KEY aes;
4234242366
AES_KEY* aesN = NULL;
4234342367
size_t len = 0;
@@ -42592,7 +42616,8 @@ static int test_wolfSSL_AES_cbc_encrypt(void)
4259242616
static int test_wolfSSL_AES_cfb128_encrypt(void)
4259342617
{
4259442618
EXPECT_DECLS;
42595-
#if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(WOLFSSL_AES_CFB)
42619+
#if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(WOLFSSL_AES_CFB) && \
42620+
!defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
4259642621
AES_KEY aesEnc;
4259742622
AES_KEY aesDec;
4259842623
const byte msg[] = {
@@ -42684,7 +42709,7 @@ static int test_wolfSSL_CRYPTO_cts128(void)
4268442709
{
4268542710
EXPECT_DECLS;
4268642711
#if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(OPENSSL_EXTRA) && \
42687-
defined(HAVE_CTS)
42712+
defined(HAVE_CTS) && !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
4268842713
byte tmp[64]; /* Largest vector size */
4268942714
/* Test vectors taken form RFC3962 Appendix B */
4269042715
const testVector vects[] = {
@@ -46276,7 +46301,8 @@ static int test_wolfSSL_EVP_Cipher_extra(void)
4627646301

4627746302
for (i = 0; test_drive[i]; i++) {
4627846303

46279-
ExpectIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 1)), 0);
46304+
ExpectIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 1)), 0);
46305+
4628046306
init_offset();
4628146307
test_drive_len[i] = 0;
4628246308

@@ -46319,13 +46345,15 @@ static int test_wolfSSL_EVP_Cipher_extra(void)
4631946345
}
4632046346

4632146347
ret = EVP_CipherFinal(evp, outb, &outl);
46348+
4632246349
binary_dump(outb, outl);
4632346350

4632446351
ret = (((test_drive_len[i] % 16) != 0) && (ret == 0)) ||
4632546352
(((test_drive_len[i] % 16) == 0) && (ret == 1));
4632646353
ExpectTrue(ret);
4632746354
}
4632846355

46356+
ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(evp), WOLFSSL_SUCCESS);
4632946357

4633046358
EVP_CIPHER_CTX_free(evp);
4633146359
evp = NULL;
@@ -47818,6 +47846,7 @@ static int test_wolfSSL_EVP_CIPHER_CTX_key_length(void)
4781847846

4781947847
ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
4782047848
ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_key_length(ctx), key_lengths[i]);
47849+
4782147850
ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_key_length(ctx, key_lengths[i]),
4782247851
WOLFSSL_SUCCESS);
4782347852

@@ -54689,6 +54718,36 @@ static int test_wolfssl_EVP_aes_gcm(void)
5468954718
ExpectIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
5469054719

5469154720
/* modify tag*/
54721+
if (i == 0) {
54722+
/* Default uses 96-bits IV length */
54723+
#ifdef WOLFSSL_AES_128
54724+
ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_gcm(), NULL,
54725+
key, iv));
54726+
#elif defined(WOLFSSL_AES_192)
54727+
ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_gcm(), NULL,
54728+
key, iv));
54729+
#elif defined(WOLFSSL_AES_256)
54730+
ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_gcm(), NULL,
54731+
key, iv));
54732+
#endif
54733+
}
54734+
else {
54735+
#ifdef WOLFSSL_AES_128
54736+
ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_gcm(), NULL,
54737+
NULL, NULL));
54738+
#elif defined(WOLFSSL_AES_192)
54739+
ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_gcm(), NULL,
54740+
NULL, NULL));
54741+
#elif defined(WOLFSSL_AES_256)
54742+
ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_gcm(), NULL,
54743+
NULL, NULL));
54744+
#endif
54745+
/* non-default must to set the IV length first */
54746+
ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN,
54747+
ivSz, NULL));
54748+
ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
54749+
54750+
}
5469254751
tag[AES_BLOCK_SIZE-1]+=0xBB;
5469354752
ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
5469454753
ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG,
@@ -54698,6 +54757,7 @@ static int test_wolfssl_EVP_aes_gcm(void)
5469854757
ciphertxtSz));
5469954758
ExpectIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
5470054759
ExpectIntEQ(0, len);
54760+
5470154761
ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]), 1);
5470254762
}
5470354763
#endif /* OPENSSL_EXTRA && !NO_AES && HAVE_AESGCM */

0 commit comments

Comments
 (0)