diff --git a/src/keys.c b/src/keys.c index 19ec9f797..deb62ed43 100644 --- a/src/keys.c +++ b/src/keys.c @@ -2909,6 +2909,15 @@ static int SetKeys(Ciphers* enc, Ciphers* dec, Keys* keys, CipherSpecs* specs, return MEMORY_E; } + if (enc) { + if (wc_HmacInit(enc->hmac, heap, devId) != 0) { + WOLFSSL_MSG("HmacInit failed in SetKeys"); + XFREE(enc->hmac, heap, DYNAMIC_TYPE_CIPHER); + enc->hmac = NULL; + return ASYNC_INIT_E; + } + } + if (dec && dec->hmac == NULL) { dec->hmac = (Hmac*)XMALLOC(sizeof(Hmac), heap, DYNAMIC_TYPE_CIPHER); @@ -2916,15 +2925,11 @@ static int SetKeys(Ciphers* enc, Ciphers* dec, Keys* keys, CipherSpecs* specs, return MEMORY_E; } - if (enc) { - if (wc_HmacInit(enc->hmac, heap, devId) != 0) { - WOLFSSL_MSG("HmacInit failed in SetKeys"); - return ASYNC_INIT_E; - } - } if (dec) { if (wc_HmacInit(dec->hmac, heap, devId) != 0) { WOLFSSL_MSG("HmacInit failed in SetKeys"); + XFREE(dec->hmac, heap, DYNAMIC_TYPE_CIPHER); + dec->hmac = NULL; return ASYNC_INIT_E; } } diff --git a/src/tls13.c b/src/tls13.c index d5b37f93d..9835e8638 100644 --- a/src/tls13.c +++ b/src/tls13.c @@ -1545,7 +1545,7 @@ static WC_INLINE void BuildTls13Nonce(WOLFSSL* ssl, byte* nonce, const byte* iv, } #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) -/* Encrypt with ChaCha20 and create authenication tag with Poly1305. +/* Encrypt with ChaCha20 and create authentication tag with Poly1305. * * ssl The SSL/TLS object. * output The buffer to write encrypted data and authentication tag into. @@ -1600,7 +1600,7 @@ static int ChaCha20Poly1305_Encrypt(WOLFSSL* ssl, byte* output, #endif #ifdef HAVE_NULL_CIPHER -/* Create authenication tag and copy data over input. +/* Create authentication tag and copy data over input. * * ssl The SSL/TLS object. * output The buffer to copy data into. @@ -1826,7 +1826,7 @@ static int EncryptTls13(WOLFSSL* ssl, byte* output, const byte* input, } #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) -/* Decrypt with ChaCha20 and check authenication tag with Poly1305. +/* Decrypt with ChaCha20 and check authentication tag with Poly1305. * * ssl The SSL/TLS object. * output The buffer to write decrypted data into. @@ -7191,12 +7191,14 @@ int DoTls13HandShakeMsgType(WOLFSSL* ssl, byte* input, word32* inOutIdx, return ret; } #ifdef WOLFSSL_EARLY_DATA - if ((ret = SetKeysSide(ssl, DECRYPT_SIDE_ONLY)) != 0) - return ret; - #else + if (ssl->earlyData != no_early_data) { + if ((ret = SetKeysSide(ssl, DECRYPT_SIDE_ONLY)) != 0) + return ret; + } + else + #endif if ((ret = SetKeysSide(ssl, ENCRYPT_AND_DECRYPT_SIDE)) != 0) return ret; - #endif } if (type == finished) {