Skip to content

Commit f8cdd52

Browse files
authored
Merge pull request #326 from padelsbach/she-server-compareconst
Use ConstantCompare instead of memcmp in wh_server_she.c
2 parents 52fd0b6 + 2f59a68 commit f8cdd52

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/wh_server_she.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "wolfssl/wolfcrypt/wc_port.h"
4444
#include "wolfssl/wolfcrypt/aes.h"
4545
#include "wolfssl/wolfcrypt/cmac.h"
46+
#include "wolfssl/wolfcrypt/misc.h"
4647
#include "wolfhsm/wh_server_keystore.h"
4748
#endif /* !WOLFHSM_CFG_NO_CRYPTO */
4849

@@ -404,7 +405,7 @@ static int _SecureBootFinish(whServerContext* server, uint16_t magic,
404405
}
405406
if (ret == 0) {
406407
/* compare and set either success or failure */
407-
ret = memcmp(cmacOutput, macDigest, field);
408+
ret = ConstantCompare(cmacOutput, macDigest, field);
408409
if (ret == 0) {
409410
server->she->sbState = WH_SHE_SB_SUCCESS;
410411
resp.status = WH_SHE_ERC_NO_ERROR;
@@ -532,7 +533,7 @@ static int _LoadKey(whServerContext* server, uint16_t magic, uint16_t req_size,
532533
sizeof(cmacInput), tmpKey, WH_SHE_KEY_SZ, NULL, server->devId);
533534
}
534535
/* compare digest to M3 */
535-
if (ret == 0 && memcmp(req.messageThree, cmacOutput, field) != 0) {
536+
if (ret == 0 && ConstantCompare(req.messageThree, cmacOutput, field) != 0) {
536537
ret = WH_SHE_ERC_KEY_UPDATE_ERROR;
537538
}
538539
/* make K1 using AES-MP(authKey | WH_SHE_KEY_UPDATE_ENC_C) */
@@ -585,7 +586,7 @@ static int _LoadKey(whServerContext* server, uint16_t magic, uint16_t req_size,
585586
}
586587
}
587588
/* compare to UID */
588-
else if (ret == 0 && memcmp(req.messageOne, server->she->uid,
589+
else if (ret == 0 && ConstantCompare(req.messageOne, server->she->uid,
589590
sizeof(server->she->uid)) != 0) {
590591
ret = WH_SHE_ERC_KEY_UPDATE_ERROR;
591592
}

0 commit comments

Comments
 (0)