Improve EVP support for CHACHA20_POLY1305 (#5527)

* Add test case for OpenSSLs capability to init a evp context partially in several calls.
* EVP handling of CHACHA20_POLY1305 improvment
- save key at ctx for Init()s without IV
- reuse stored key for Init()s with new IV, reusing ctx
- free and zero key on ctx clenaup
* Adding type cast to XMALLOC to force compiler compatibility.
* EVP: using same DYNAMIC_TYPE in alloc and free of chacha20_poly1305 key.
Co-authored-by: Stefan Eissing <stefan.eissing@greenbytes.de>
This commit is contained in:
Stefan Eissing
2022-09-01 22:23:42 +02:00
committed by GitHub
parent ba8ffc765d
commit 65ca72c5a2
3 changed files with 45 additions and 2 deletions

View File

@@ -52049,6 +52049,24 @@ static int test_wolfssl_EVP_chacha20_poly1305(void)
AssertIntEQ(outSz, 0);
EVP_CIPHER_CTX_free(ctx);
/* Test partial Inits. CipherInit() allow setting of key and iv
* in separate calls. */
AssertNotNull((ctx = EVP_CIPHER_CTX_new()));
AssertIntEQ(wolfSSL_EVP_CipherInit(ctx, EVP_chacha20_poly1305(),
key, NULL, 1), WOLFSSL_SUCCESS);
AssertIntEQ(wolfSSL_EVP_CipherInit(ctx, NULL, NULL, iv, 1),
WOLFSSL_SUCCESS);
AssertIntEQ(wolfSSL_EVP_CipherUpdate(ctx, NULL, &outSz,
aad, sizeof(aad)), WOLFSSL_SUCCESS);
AssertIntEQ(outSz, sizeof(aad));
AssertIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
sizeof(cipherText)), WOLFSSL_SUCCESS);
AssertIntEQ(outSz, sizeof(cipherText));
AssertIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
WOLFSSL_SUCCESS);
AssertIntEQ(outSz, 0);
EVP_CIPHER_CTX_free(ctx);
printf(resultFmt, passed);
#endif