Skip to content

Commit 2f59a68

Browse files
committed
Use ConstantCompare instead of memcmp in wh_server_she.c
1 parent 7f9702f commit 2f59a68

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

@@ -385,7 +386,7 @@ static int _SecureBootFinish(whServerContext* server, uint16_t magic,
385386
}
386387
if (ret == 0) {
387388
/* compare and set either success or failure */
388-
ret = memcmp(cmacOutput, macDigest, field);
389+
ret = ConstantCompare(cmacOutput, macDigest, field);
389390
if (ret == 0) {
390391
server->she->sbState = WH_SHE_SB_SUCCESS;
391392
resp.status = WH_SHE_ERC_NO_ERROR;
@@ -503,7 +504,7 @@ static int _LoadKey(whServerContext* server, uint16_t magic, uint16_t req_size,
503504
sizeof(cmacInput), tmpKey, WH_SHE_KEY_SZ, NULL, server->devId);
504505
}
505506
/* compare digest to M3 */
506-
if (ret == 0 && memcmp(req.messageThree, cmacOutput, field) != 0) {
507+
if (ret == 0 && ConstantCompare(req.messageThree, cmacOutput, field) != 0) {
507508
ret = WH_SHE_ERC_KEY_UPDATE_ERROR;
508509
}
509510
/* make K1 using AES-MP(authKey | WH_SHE_KEY_UPDATE_ENC_C) */
@@ -556,7 +557,7 @@ static int _LoadKey(whServerContext* server, uint16_t magic, uint16_t req_size,
556557
}
557558
}
558559
/* compare to UID */
559-
else if (ret == 0 && memcmp(req.messageOne, server->she->uid,
560+
else if (ret == 0 && ConstantCompare(req.messageOne, server->she->uid,
560561
sizeof(server->she->uid)) != 0) {
561562
ret = WH_SHE_ERC_KEY_UPDATE_ERROR;
562563
}

0 commit comments

Comments
 (0)