ndn_hmac_verify and ndn_sha256_verify and sign_on_basic_nrf_crypto_vrfy_hmac_sha256_sig functions verify HMAC or SHA256 signature.
Each function first creates a correct HMAC or SHA256 signature over the input, then compares the incoming signature with that correct signature.
The comparison step is coded as:
This invokes memcmp, which returns as soon as finding the first different element.
As a result, these functions are vulnerable to timing attacks because the execution time of these function leaks the information about which is the first byte that differs from the correct signature.
We will abandon sign_on_basic_nrf_crypto_vrfy_hmac_sha256_sig and other security impl under ./app-support/bootstrapping soon.
Commit 2eabccc fixed the issue in ndn_hmac_verify and ndn_sha256_verify.
ndn_hmac_verify
andndn_sha256_verify
andsign_on_basic_nrf_crypto_vrfy_hmac_sha256_sig
functions verify HMAC or SHA256 signature. Each function first creates a correct HMAC or SHA256 signature over the input, then compares the incoming signature with that correct signature. The comparison step is coded as:This invokes
memcmp
, which returns as soon as finding the first different element. As a result, these functions are vulnerable to timing attacks because the execution time of these function leaks the information about which is the first byte that differs from the correct signature.To fix this bug, use a constant-time comparison function.