Wessel Nieboer
4 months ago
No known key found for this signature in database
GPG Key ID: 929C8E45E33B5FD2
1 changed files with
2 additions and
4 deletions
-
src/Utils.cpp
|
|
@ -1,5 +1,6 @@ |
|
|
#include "Utils.h" |
|
|
#include "Utils.h" |
|
|
#include <AES.h> |
|
|
#include <AES.h> |
|
|
|
|
|
#include <Crypto.h> |
|
|
#include <SHA256.h> |
|
|
#include <SHA256.h> |
|
|
|
|
|
|
|
|
#ifdef ARDUINO |
|
|
#ifdef ARDUINO |
|
|
@ -81,10 +82,7 @@ int Utils::MACThenDecrypt(const uint8_t* shared_secret, uint8_t* dest, const uin |
|
|
sha.update(src + CIPHER_MAC_SIZE, src_len - CIPHER_MAC_SIZE); |
|
|
sha.update(src + CIPHER_MAC_SIZE, src_len - CIPHER_MAC_SIZE); |
|
|
sha.finalizeHMAC(shared_secret, PUB_KEY_SIZE, hmac, CIPHER_MAC_SIZE); |
|
|
sha.finalizeHMAC(shared_secret, PUB_KEY_SIZE, hmac, CIPHER_MAC_SIZE); |
|
|
} |
|
|
} |
|
|
// constant-time comparison to prevent timing side-channel attacks
|
|
|
if (secure_compare(hmac, src, CIPHER_MAC_SIZE)) { |
|
|
uint8_t diff = 0; |
|
|
|
|
|
for (int i = 0; i < CIPHER_MAC_SIZE; i++) diff |= hmac[i] ^ src[i]; |
|
|
|
|
|
if (diff == 0) { |
|
|
|
|
|
return decrypt(shared_secret, dest, src + CIPHER_MAC_SIZE, src_len - CIPHER_MAC_SIZE); |
|
|
return decrypt(shared_secret, dest, src + CIPHER_MAC_SIZE, src_len - CIPHER_MAC_SIZE); |
|
|
} |
|
|
} |
|
|
return 0; // invalid HMAC
|
|
|
return 0; // invalid HMAC
|
|
|
|