@@ -2188,16 +2188,27 @@ static int Dtls13InitAesCipher(WOLFSSL* ssl, RecordNumberCiphers* cipher,
21882188 XMEMSET (cipher -> aes , 0 , sizeof (* cipher -> aes ));
21892189
21902190 ret = wc_AesInit (cipher -> aes , ssl -> heap , INVALID_DEVID );
2191- if (ret != 0 )
2191+ if (ret != 0 ) {
2192+ XFREE (cipher -> aes , ssl -> heap , DYNAMIC_TYPE_CIPHER );
2193+ cipher -> aes = NULL ;
21922194 return ret ;
2195+ }
2196+
2197+ ret = wc_AesSetKey (cipher -> aes , key , keySize , NULL , AES_ENCRYPTION );
2198+ if (ret != 0 ) {
2199+ wc_AesFree (cipher -> aes );
2200+ XFREE (cipher -> aes , ssl -> heap , DYNAMIC_TYPE_CIPHER );
2201+ cipher -> aes = NULL ;
2202+ }
21932203
2194- return wc_AesSetKey ( cipher -> aes , key , keySize , NULL , AES_ENCRYPTION ) ;
2204+ return ret ;
21952205}
21962206
21972207#ifdef HAVE_CHACHA
21982208static int Dtls13InitChaChaCipher (RecordNumberCiphers * c , byte * key ,
21992209 word16 keySize , void * heap )
22002210{
2211+ int ret ;
22012212 (void )heap ;
22022213
22032214 if (c -> chacha == NULL ) {
@@ -2207,7 +2218,13 @@ static int Dtls13InitChaChaCipher(RecordNumberCiphers* c, byte* key,
22072218 return MEMORY_E ;
22082219 }
22092220
2210- return wc_Chacha_SetKey (c -> chacha , key , keySize );
2221+ ret = wc_Chacha_SetKey (c -> chacha , key , keySize );
2222+ if (ret != 0 ) {
2223+ XFREE (c -> chacha , heap , DYNAMIC_TYPE_CIPHER );
2224+ c -> chacha = NULL ;
2225+ }
2226+
2227+ return ret ;
22112228}
22122229#endif /* HAVE_CHACHA */
22132230
0 commit comments