Skip to content
This repository was archived by the owner on Aug 3, 2026. It is now read-only.

Commit c3fb0e1

Browse files
committed
fixed the cppcheck blocker
1 parent a631417 commit c3fb0e1

3 files changed

Lines changed: 16 additions & 13 deletions

File tree

src/esp_crypto/crypto_asymmetric.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,7 @@ CryptoResult<std::vector<uint8_t>> ESPCrypto::ecdsaDerToRaw(CryptoSpan<const uin
731731

732732
CryptoResult<std::vector<uint8_t>> ESPCrypto::ecdsaRawToDer(CryptoSpan<const uint8_t> raw) {
733733
return ecdsaRawToDerInternal(raw);
734+
}
734735

735736
CryptoResult<std::vector<uint8_t>>
736737
ESPCrypto::x25519(CryptoSpan<const uint8_t> privateKey, CryptoSpan<const uint8_t> peerPublic) {

src/esp_crypto/crypto_core.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ void resetRuntimeState() {
4141
GlobalRuntimeState &state = runtimeState();
4242
state.nvsInitMap.clear();
4343
#if ESPCRYPTO_ENABLE_NONCE_GUARD
44-
for (auto &record : state.nonceCache) {
45-
record = NonceRecord{};
46-
}
44+
std::fill(state.nonceCache.begin(), state.nonceCache.end(), NonceRecord{});
4745
state.nonceCursor = 0;
4846
#endif
4947
state.bootCounter.store(0, std::memory_order_release);
@@ -68,16 +66,15 @@ bool nonceReused(const std::vector<uint8_t> &key, const std::vector<uint8_t> &iv
6866
}
6967
markRuntimeInitialized();
7068
uint32_t keyHash = fingerprintKey(key);
71-
for (const auto &record : state.nonceCache) {
72-
if (!record.used || record.ivLen != iv.size()) {
73-
continue;
74-
}
75-
if (record.keyHash != keyHash) {
76-
continue;
77-
}
78-
if (memcmp(record.iv.data(), iv.data(), iv.size()) == 0) {
79-
return true;
80-
}
69+
if (std::any_of(
70+
state.nonceCache.begin(),
71+
state.nonceCache.end(),
72+
[&](const NonceRecord &record) {
73+
return record.used && record.ivLen == iv.size() && record.keyHash == keyHash &&
74+
memcmp(record.iv.data(), iv.data(), iv.size()) == 0;
75+
}
76+
)) {
77+
return true;
8178
}
8279
NonceRecord &slot = state.nonceCache[state.nonceCursor % state.nonceCache.size()];
8380
slot.used = true;

src/esp_crypto/crypto_symmetric.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ bool hardwareAesCtr(
210210
const std::vector<uint8_t> &key,
211211
const std::vector<uint8_t> &nonceCounter,
212212
const std::vector<uint8_t> &input,
213+
// cppcheck-suppress constParameterReference
213214
std::vector<uint8_t> &output
214215
) {
215216
#if ESPCRYPTO_AES_ACCEL
@@ -331,7 +332,9 @@ bool hardwareGcmCrypt(
331332
const std::vector<uint8_t> &iv,
332333
const std::vector<uint8_t> &aad,
333334
const std::vector<uint8_t> &input,
335+
// cppcheck-suppress constParameterReference
334336
std::vector<uint8_t> &output,
337+
// cppcheck-suppress constParameterReference
335338
std::vector<uint8_t> &tag
336339
) {
337340
return hardwareGcmCryptSpan(
@@ -351,7 +354,9 @@ bool softwareGcmCrypt(
351354
const std::vector<uint8_t> &iv,
352355
const std::vector<uint8_t> &aad,
353356
const std::vector<uint8_t> &input,
357+
// cppcheck-suppress constParameterReference
354358
std::vector<uint8_t> &output,
359+
// cppcheck-suppress constParameterReference
355360
std::vector<uint8_t> &tag
356361
) {
357362
return softwareGcmCrypt(

0 commit comments

Comments
 (0)