@@ -1145,6 +1145,7 @@ esp_check_icv_hmac(const wolfIP_esp_sa * esp_sa, uint8_t * esp_data,
11451145 int rc = 0 ;
11461146 const uint8_t * icv = NULL ;
11471147 byte hash [WC_SHA256_DIGEST_SIZE ];
1148+ memset (hash , 0 , sizeof (hash ));
11481149
11491150 rc = esp_calc_icv_hmac (hash , esp_sa , esp_data , esp_len );
11501151 if (rc ) {
@@ -1357,7 +1358,8 @@ esp_transport_unwrap(struct wolfIP_ip_packet *ip, uint32_t * frame_len)
13571358 }
13581359
13591360 if (err ) {
1360- ESP_LOG ("error: icv check failed\n" );
1361+ ESP_LOG ("error: icv check (auth=%d, icv_len=%d) failed: %d\n" ,
1362+ esp_sa -> auth , esp_sa -> icv_len , err );
13611363 return -1 ;
13621364 }
13631365 }
@@ -1643,15 +1645,22 @@ esp_transport_wrap(struct wolfIP_ip_packet *ip, uint16_t * ip_len)
16431645 }
16441646
16451647 if (esp_sa -> icv_len ) {
1646- uint8_t * icv = NULL ;
16471648 int err = 0 ;
16481649
16491650 switch (esp_sa -> auth ) {
16501651 case ESP_AUTH_MD5_RFC2403 :
16511652 case ESP_AUTH_SHA1_RFC2404 :
16521653 case ESP_AUTH_SHA256_RFC4868 :
1653- icv = ip -> data + icv_offset ;
1654- err = esp_calc_icv_hmac (icv , esp_sa , ip -> data , payload_len );
1654+ {
1655+ uint8_t * icv = NULL ;
1656+ byte hash [WC_SHA256_DIGEST_SIZE ];
1657+ memset (hash , 0 , sizeof (hash ));
1658+ icv = ip -> data + icv_offset ;
1659+ err = esp_calc_icv_hmac (hash , esp_sa , ip -> data , payload_len );
1660+ if (err == 0 ) {
1661+ memcpy (icv , hash , esp_sa -> icv_len );
1662+ }
1663+ }
16551664 break ;
16561665 #if defined(WOLFSSL_AESGCM_STREAM )
16571666 case ESP_AUTH_GCM_RFC4106 :
0 commit comments