@@ -8234,10 +8234,17 @@ void wolfSSL_ResourceFree(WOLFSSL* ssl)
8234
8234
{
8235
8235
int i;
8236
8236
for (i = 0; i < WOLFSSL_THREADED_CRYPT_CNT; i++) {
8237
- bufferStatic* buff = &ssl->buffers.encrypt[i].buffer;
8238
-
8239
- ssl->buffers.encrypt[i].stop = 1;
8240
- FreeCiphersSide(&ssl->buffers.encrypt[i].cipher, ssl->heap);
8237
+ ThreadCrypt* encrypt = &ssl->buffers.encrypt[i];
8238
+ bufferStatic* buff = &encrypt->buffer;
8239
+
8240
+ encrypt->stop = 1;
8241
+ FreeCiphersSide(&encrypt->cipher, ssl->heap);
8242
+ #if defined(HAVE_POLY1305) && defined(HAVE_ONE_TIME_AUTH)
8243
+ if (encrypt->auth.poly1305)
8244
+ ForceZero(encrypt->auth.poly1305, sizeof(Poly1305));
8245
+ XFREE(encrypt->auth.poly1305, ssl->heap, DYNAMIC_TYPE_CIPHER);
8246
+ encrypt->auth.poly1305 = NULL;
8247
+ #endif
8241
8248
if (buff->dynamicFlag) {
8242
8249
XFREE(buff->buffer - buff->offset, ssl->heap,
8243
8250
DYNAMIC_TYPE_OUT_BUFFER);
@@ -8248,10 +8255,17 @@ void wolfSSL_ResourceFree(WOLFSSL* ssl)
8248
8255
}
8249
8256
}
8250
8257
for (i = 0; i < WOLFSSL_THREADED_CRYPT_CNT; i++) {
8251
- bufferStatic* buff = &ssl->buffers.decrypt[i].buffer;
8252
-
8253
- ssl->buffers.decrypt[i].stop = 1;
8254
- FreeCiphersSide(&ssl->buffers.decrypt[i].cipher, ssl->heap);
8258
+ ThreadCrypt* decrypt = &ssl->buffers.decrypt[i];
8259
+ bufferStatic* buff = &decrypt->buffer;
8260
+
8261
+ decrypt->stop = 1;
8262
+ FreeCiphersSide(&decrypt->cipher, ssl->heap);
8263
+ #if defined(HAVE_POLY1305) && defined(HAVE_ONE_TIME_AUTH)
8264
+ if (decrypt->auth.poly1305)
8265
+ ForceZero(decrypt->auth.poly1305, sizeof(Poly1305));
8266
+ XFREE(decrypt->auth.poly1305, ssl->heap, DYNAMIC_TYPE_CIPHER);
8267
+ decrypt->auth.poly1305 = NULL;
8268
+ #endif
8255
8269
if (buff->dynamicFlag) {
8256
8270
XFREE(buff->buffer - buff->offset, ssl->heap,
8257
8271
DYNAMIC_TYPE_OUT_BUFFER);
@@ -25295,40 +25309,27 @@ int SendData(WOLFSSL* ssl, const void* data, int sz)
25295
25309
SetKeys(&encrypt->cipher, NULL, &ssl->keys, &ssl->specs,
25296
25310
ssl->options.side, ssl->heap, ssl->devId, ssl->rng,
25297
25311
ssl->options.tls1_3);
25312
+ #ifdef HAVE_ONE_TIME_AUTH
25313
+ if (ssl->specs.bulk_cipher_algorithm == wolfssl_chacha) {
25314
+ ret = SetAuthKeys(&encrypt->auth, &ssl->keys, &ssl->specs,
25315
+ ssl->heap, ssl->devId);
25316
+ if (ret != 0)
25317
+ return ret;
25318
+ }
25319
+ #endif
25320
+
25298
25321
encrypt->init = 1;
25299
25322
}
25323
+
25300
25324
encrypt->buffer.length = sendSz;
25301
25325
encrypt->offset = RECORD_HEADER_SZ;
25302
- if (ssl->options.dtls) {
25303
- encrypt->offset += DTLS_RECORD_EXTRA;
25304
- }
25305
- encrypt->cryptLen = outputSz - encrypt->offset;
25306
- #ifdef HAVE_TRUNCATED_HMAC
25307
- if (ssl->truncated_hmac) {
25308
- encrypt->cryptLen -= min(TRUNCATED_HMAC_SZ,
25309
- ssl->specs.hash_size);
25310
- }
25311
- else
25312
- #endif
25313
- {
25314
- encrypt->cryptLen -= ssl->specs.hash_size;
25315
- }
25316
-
25317
- #if !defined(NO_PUBLIC_GCM_SET_IV) && \
25318
- ((defined(HAVE_FIPS) || defined(HAVE_SELFTEST)) && \
25319
- (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2)))
25320
- XMEMCPY(encrypt->nonce, ssl->keys.aead_enc_imp_IV,
25321
- AESGCM_IMP_IV_SZ);
25322
- XMEMCPY(encrypt->nonce + AESGCM_IMP_IV_SZ, ssl->keys.aead_exp_IV,
25323
- AESGCM_EXP_IV_SZ);
25324
- #endif
25325
- XMEMSET(encrypt->additional, 0, AEAD_AUTH_DATA_SZ);
25326
- WriteSEQ(ssl, CUR_ORDER, encrypt->additional);
25327
- XMEMCPY(encrypt->additional + AEAD_TYPE_OFFSET,
25328
- encrypt->buffer.buffer, 3);
25329
- c16toa(sendSz - encrypt->offset - AESGCM_EXP_IV_SZ -
25330
- ssl->specs.aead_mac_size,
25331
- encrypt->additional + AEAD_LEN_OFFSET);
25326
+ encrypt->buffer.idx = 0;
25327
+ encrypt->cryptLen = sendSz - RECORD_HEADER_SZ;
25328
+
25329
+ BuildTls13Nonce(ssl, encrypt->nonce, ssl->keys.aead_enc_imp_IV,
25330
+ CUR_ORDER);
25331
+ XMEMCPY(encrypt->additional, encrypt->buffer.buffer,
25332
+ encrypt->offset);
25332
25333
25333
25334
#ifdef WOLFSSL_DTLS
25334
25335
if (ssl->options.dtls)
0 commit comments