Skip to content

Commit 6bc0aa5

Browse files
committed
fix client printouts
1 parent eb85f18 commit 6bc0aa5

1 file changed

Lines changed: 62 additions & 42 deletions

File tree

src/wh_client_crypto.c

Lines changed: 62 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,9 @@ int wh_Client_RngGenerate(whClientContext* ctx, uint8_t* out, uint32_t size)
214214
req->sz = chunk_size;
215215

216216
#ifdef DEBUG_CRYPTOCB_VERBOSE
217-
printf("[client] RNG: size:%u reqsz:%u remaining:%u\n", chunk_size,
218-
req_len, size);
217+
printf("[client] RNG: size:%u reqsz:%u remaining:%u\n",
218+
(unsigned int)chunk_size, (unsigned int)req_len,
219+
(unsigned int)size);
219220
printf("[client] RNG: req:%p\n", req);
220221
#endif
221222

@@ -241,8 +242,8 @@ int wh_Client_RngGenerate(whClientContext* ctx, uint8_t* out, uint32_t size)
241242
}
242243
size -= res->sz;
243244
#ifdef DEBUG_CRYPTOCB_VERBOSE
244-
printf("[client] out size:%u remaining:%u\n", res->sz,
245-
size);
245+
printf("[client] out size:%u remaining:%u\n",
246+
(unsigned int)res->sz, (unsigned int)size);
246247
wh_Utils_Hexdump("[client] res_out: \n", out - res->sz,
247248
res->sz);
248249
#endif
@@ -494,7 +495,8 @@ int wh_Client_AesEcb(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
494495
#ifdef DEBUG_CRYPTOCB_VERBOSE
495496
printf("[client] %s: enc:%d keylen:%d ivsz:%d insz:%d reqsz:%u "
496497
"blocks:%u \n",
497-
__func__, enc, key_len, iv_len, len, req_len, blocks);
498+
__func__, enc, (int)key_len, (int)iv_len, (int)len,
499+
(unsigned int)req_len, (unsigned int)blocks);
498500
#endif
499501

500502
if (req_len > WOLFHSM_CFG_COMM_DATA_LEN) {
@@ -541,7 +543,8 @@ int wh_Client_AesEcb(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
541543
/* Response packet */
542544
uint8_t* res_out = (uint8_t*)(res + 1);
543545
#ifdef DEBUG_CRYPTOCB_VERBOSE
544-
printf("[client] out size:%d res_len:%d\n", res->sz, res_len);
546+
printf("[client] out size:%d res_len:%d\n", (int)res->sz,
547+
(int)res_len);
545548
wh_Utils_Hexdump("[client] res_out: \n", out, res->sz);
546549
#endif
547550
/* copy the response res_out */
@@ -603,7 +606,9 @@ int wh_Client_AesCbc(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
603606
#ifdef DEBUG_CRYPTOCB_VERBOSE
604607
printf("[client] %s: enc:%d keylen:%d ivsz:%d insz:%d reqsz:%u "
605608
"blocks:%u lastoffset:%u\n",
606-
__func__, enc, key_len, iv_len, len, req_len, blocks, last_offset);
609+
__func__, enc, (int)key_len, (int)iv_len, (int)len,
610+
(unsigned int)req_len, (unsigned int)blocks,
611+
(unsigned int)last_offset);
607612
#endif
608613

609614
if (req_len > WOLFHSM_CFG_COMM_DATA_LEN) {
@@ -657,7 +662,8 @@ int wh_Client_AesCbc(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
657662
/* Response packet */
658663
uint8_t* res_out = (uint8_t*)(res + 1);
659664
#ifdef DEBUG_CRYPTOCB_VERBOSE
660-
printf("[client] out size:%d res_len:%d\n", res->sz, res_len);
665+
printf("[client] out size:%d res_len:%d\n", (int)res->sz,
666+
(int)res_len);
661667
wh_Utils_Hexdump("[client] res_out: \n", out, res->sz);
662668
#endif
663669
/* copy the response res_out */
@@ -723,7 +729,8 @@ int wh_Client_AesGcm(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
723729
#ifdef DEBUG_CRYPTOCB_VERBOSE
724730
printf("[client] AESGCM: enc:%d keylen:%d ivsz:%d insz:%d authinsz:%d "
725731
"authtagsz:%d reqsz:%u\n",
726-
enc, key_len, iv_len, len, authin_len, tag_len, req_len);
732+
enc, (int)key_len, (int)iv_len, (int)len, (int)authin_len,
733+
(int)tag_len, (unsigned int)req_len);
727734
printf("[client] AESGCM: req:%p in:%p key:%p iv:%p authin:%p tag:%p\n", req,
728735
req_in, req_key, req_iv, req_authin, req_tag);
729736
#endif
@@ -796,8 +803,8 @@ int wh_Client_AesGcm(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
796803
uint8_t* res_tag = res_out + res->sz;
797804

798805
#ifdef DEBUG_CRYPTOCB_VERBOSE
799-
printf("[client] out size:%d datasz:%d tag_len:%d\n", res->sz,
800-
res_len, res->authTagSz);
806+
printf("[client] out size:%d datasz:%d tag_len:%d\n",
807+
(int)res->sz, (int)res_len, (int)res->authTagSz);
801808
wh_Utils_Hexdump("[client] res_out: \n", res_out, res->sz);
802809
if (enc != 0 && res->authTagSz > 0) {
803810
wh_Utils_Hexdump("[client] res_tag: \n", res_tag,
@@ -815,7 +822,7 @@ int wh_Client_AesGcm(whClientContext* ctx, Aes* aes, int enc, const uint8_t* in,
815822
memcpy(enc_tag, res_tag, res->authTagSz);
816823
#ifdef DEBUG_CRYPTOCB_VERBOSE
817824
printf("[client] res tag_len:%d exp tag_len:%u",
818-
res->authTagSz, tag_len);
825+
(int)res->authTagSz, (unsigned int)tag_len);
819826
wh_Utils_Hexdump("[client] enc authtag: ", enc_tag,
820827
res->authTagSz);
821828
#endif
@@ -1175,8 +1182,8 @@ static int _EccMakeKey(whClientContext* ctx, int size, int curveId,
11751182
ret = wh_Client_SendRequest(ctx, group, action, req_len,
11761183
(uint8_t*)dataPtr);
11771184
#ifdef DEBUG_CRYPTOCB_VERBOSE
1178-
printf("[client] %s Req sent:size:%u, ret:%d\n", __func__, req->sz,
1179-
ret);
1185+
printf("[client] %s Req sent:size:%u, ret:%d\n", __func__,
1186+
(unsigned int)req->sz, ret);
11801187
#endif
11811188
if (ret == WH_ERROR_OK) {
11821189
/* Response Message */
@@ -1193,7 +1200,8 @@ static int _EccMakeKey(whClientContext* ctx, int size, int curveId,
11931200
(uint8_t**)&res);
11941201
#ifdef DEBUG_CRYPTOCB_VERBOSE
11951202
printf("[client] %s Res recv:keyid:%u, len:%u, ret:%d\n",
1196-
__func__, res->keyId, res->len, ret);
1203+
__func__, (unsigned int)res->keyId,
1204+
(unsigned int)res->len, ret);
11971205
#endif
11981206
/* wolfCrypt allows positive error codes on success in some
11991207
* scenarios */
@@ -1339,7 +1347,8 @@ int wh_Client_EccSharedSecret(whClientContext* ctx, ecc_key* priv_key,
13391347
(uint8_t*)dataPtr);
13401348
#ifdef DEBUG_CRYPTOCB_VERBOSE
13411349
printf("[client] %s req sent. priv:%u pub:%u\n", __func__,
1342-
req->privateKeyId, req->publicKeyId);
1350+
(unsigned int)req->privateKeyId,
1351+
(unsigned int)req->publicKeyId);
13431352
#endif
13441353
if (ret == WH_ERROR_OK) {
13451354
/* Server will evict. Reset our flags */
@@ -1637,7 +1646,8 @@ int wh_Client_EccVerify(whClientContext* ctx, ecc_key* key, const uint8_t* sig,
16371646
#ifdef DEBUG_CRYPTOCB_VERBOSE
16381647
printf("[client] EccVerify req: key_id=%x, sig_len=%u, "
16391648
"hash_len=%u, options=%u\n",
1640-
key_id, sig_len, hash_len, options);
1649+
key_id, (unsigned int)sig_len, (unsigned int)hash_len,
1650+
(unsigned int)options);
16411651
wh_Utils_Hexdump("[client] EccVerify req:", (uint8_t*)req, req_len);
16421652
if ((sig != NULL) && (sig_len > 0)) {
16431653
wh_Utils_Hexdump("[client] EccVerify sig:", sig, sig_len);
@@ -1883,8 +1893,8 @@ static int _Curve25519MakeKey(whClientContext* ctx, uint16_t size,
18831893
ret =
18841894
wh_Client_SendRequest(ctx, group, action, data_len, (uint8_t*)dataPtr);
18851895
#ifdef DEBUG_CRYPTOCB_VERBOSE
1886-
printf("[client] Curve25519 KeyGen Req sent:size:%u, ret:%d\n", req->sz,
1887-
ret);
1896+
printf("[client] Curve25519 KeyGen Req sent:size:%u, ret:%d\n",
1897+
(unsigned int)req->sz, ret);
18881898
#endif
18891899
if (ret == 0) {
18901900
do {
@@ -1903,7 +1913,7 @@ static int _Curve25519MakeKey(whClientContext* ctx, uint16_t size,
19031913
#ifdef DEBUG_CRYPTOCB_VERBOSE
19041914
printf("[client] Curve25519 KeyGen Res recv:keyid:%u, len:%u, "
19051915
"ret:%d\n",
1906-
res->keyId, res->len, ret);
1916+
(unsigned int)res->keyId, (unsigned int)res->len, ret);
19071917
#endif
19081918
/* Key is cached on server or is ephemeral */
19091919
key_id = (whKeyId)(res->keyId);
@@ -2042,7 +2052,8 @@ int wh_Client_Curve25519SharedSecret(whClientContext* ctx,
20422052
(uint8_t*)dataPtr);
20432053
#ifdef DEBUG_CRYPTOCB_VERBOSE
20442054
printf("[client] %s req sent. priv:%u pub:%u\n", __func__,
2045-
req->privateKeyId, req->publicKeyId);
2055+
(unsigned int)req->privateKeyId,
2056+
(unsigned int)req->publicKeyId);
20462057
#endif
20472058
if (ret == WH_ERROR_OK) {
20482059
whMessageCrypto_Curve25519Response* res = NULL;
@@ -2238,8 +2249,8 @@ static int _RsaMakeKey(whClientContext* ctx, uint32_t size, uint32_t e,
22382249
/* Send Request */
22392250
ret = wh_Client_SendRequest(ctx, group, action, req_len, dataPtr);
22402251
#ifdef DEBUG_CRYPTOCB_VERBOSE
2241-
printf("RSA KeyGen Req sent:size:%u, e:%u, ret:%d\n", req->size, req->e,
2242-
ret);
2252+
printf("RSA KeyGen Req sent:size:%u, e:%u, ret:%d\n",
2253+
(unsigned int)req->size, (unsigned int)req->e, ret);
22432254
#endif
22442255
if (ret == 0) {
22452256
uint16_t res_len = 0;
@@ -2249,7 +2260,8 @@ static int _RsaMakeKey(whClientContext* ctx, uint32_t size, uint32_t e,
22492260
} while (ret == WH_ERROR_NOTREADY);
22502261

22512262
#ifdef DEBUG_CRYPTOCB_VERBOSE
2252-
printf("RSA KeyGen Res recv: ret:%d, res_len: %u\n", ret, res_len);
2263+
printf("RSA KeyGen Res recv: ret:%d, res_len: %u\n", ret,
2264+
(unsigned int)res_len);
22532265
#endif
22542266

22552267
if (ret == WH_ERROR_OK) {
@@ -2641,8 +2653,9 @@ static int _HkdfMakeKey(whClientContext* ctx, int hashType, whKeyId keyIdIn,
26412653
#ifdef DEBUG_CRYPTOCB_VERBOSE
26422654
printf("HKDF Req sent: hashType:%d inKeySz:%u saltSz:%u infoSz:%u outSz:%u "
26432655
"ret:%d\n",
2644-
req->hashType, req->inKeySz, req->saltSz, req->infoSz, req->outSz,
2645-
ret);
2656+
(int)req->hashType, (unsigned int)req->inKeySz,
2657+
(unsigned int)req->saltSz, (unsigned int)req->infoSz,
2658+
(unsigned int)req->outSz, ret);
26462659
#endif
26472660

26482661
if (ret == 0) {
@@ -2653,7 +2666,8 @@ static int _HkdfMakeKey(whClientContext* ctx, int hashType, whKeyId keyIdIn,
26532666
} while (ret == WH_ERROR_NOTREADY);
26542667

26552668
#ifdef DEBUG_CRYPTOCB_VERBOSE
2656-
printf("HKDF Res recv: ret:%d, res_len: %u\n", ret, res_len);
2669+
printf("HKDF Res recv: ret:%d, res_len: %u\n", ret,
2670+
(unsigned int)res_len);
26572671
#endif
26582672

26592673
if (ret == WH_ERROR_OK) {
@@ -2679,7 +2693,7 @@ static int _HkdfMakeKey(whClientContext* ctx, int hashType, whKeyId keyIdIn,
26792693

26802694
#ifdef DEBUG_CRYPTOCB_VERBOSE
26812695
printf("[client] %s Set key_id:%x with flags:%x outSz:%u\n",
2682-
__func__, key_id, flags, res->outSz);
2696+
__func__, key_id, flags, (unsigned int)res->outSz);
26832697
#endif
26842698
}
26852699
else {
@@ -2788,7 +2802,7 @@ int wh_Client_Cmac(whClientContext* ctx, Cmac* cmac, CmacType type,
27882802
#ifdef DEBUG_CRYPTOCB_VERBOSE
27892803
printf("[client] cmac key:%p key_len:%d in:%p in_len:%d out:%p out_len:%d "
27902804
"keyId:%x\n",
2791-
key, keyLen, in, inLen, outMac, mac_len, key_id);
2805+
key, (int)keyLen, in, (int)inLen, outMac, (int)mac_len, key_id);
27922806
#endif
27932807

27942808

@@ -3092,8 +3106,9 @@ static int _xferSha256BlockAndUpdateDigest(whClientContext* ctx,
30923106
wh_Utils_Hexdump(" [client] resumeHash: ", req->resumeState.hash,
30933107
(isLastBlock) ? req->lastBlockLen
30943108
: WC_SHA256_BLOCK_SIZE);
3095-
printf(" [client] hiLen: %u, loLen: %u\n", req->resumeState.hiLen,
3096-
req->resumeState.loLen);
3109+
printf(" [client] hiLen: %u, loLen: %u\n",
3110+
(unsigned int)req->resumeState.hiLen,
3111+
(unsigned int)req->resumeState.loLen);
30973112
}
30983113
printf(" [client] ret = %d\n", ret);
30993114
#endif /* DEBUG_CRYPTOCB_VERBOSE */
@@ -3110,7 +3125,7 @@ static int _xferSha256BlockAndUpdateDigest(whClientContext* ctx,
31103125
/* wolfCrypt allows positive error codes on success in some scenarios */
31113126
if (ret >= 0) {
31123127
#ifdef DEBUG_CRYPTOCB_VERBOSE
3113-
printf("[client] ERROR Client SHA256 Res recv: ret=%d", ret);
3128+
printf("[client] Client SHA256 Res recv: ret=%d", ret);
31143129
#endif /* DEBUG_CRYPTOCB_VERBOSE */
31153130
/* Store the received intermediate hash in the sha256
31163131
* context and indicate the field is now valid and
@@ -3245,7 +3260,8 @@ int wh_Client_Sha256Dma(whClientContext* ctx, wc_Sha256* sha, const uint8_t* in,
32453260
* wc_CryptoCb_Sha256Hash(sha256, data, len, NULL) */
32463261
if ((ret == WH_ERROR_OK) && (in != NULL)) {
32473262
#ifdef DEBUG_CRYPTOCB_VERBOSE
3248-
printf("[client] SHA256 DMA UPDATE: inAddr=%p, inSz=%u\n", in, inLen);
3263+
printf("[client] SHA256 DMA UPDATE: inAddr=%p, inSz=%u\n", in,
3264+
(unsigned int)inLen);
32493265
#endif
32503266

32513267
ret = wh_Client_SendRequest(
@@ -3399,7 +3415,7 @@ static int _xferSha224BlockAndUpdateDigest(whClientContext* ctx,
33993415
/* wolfCrypt allows positive error codes on success in some scenarios */
34003416
if (ret >= 0) {
34013417
#ifdef DEBUG_CRYPTOCB_VERBOSE
3402-
printf("[client] ERROR Client SHA224 Res recv: ret=%d", ret);
3418+
printf("[client] Client SHA224 Res recv: ret=%d", ret);
34033419
#endif /* DEBUG_CRYPTOCB_VERBOSE */
34043420
/* Store the received intermediate hash in the sha224
34053421
* context and indicate the field is now valid and
@@ -3512,7 +3528,8 @@ int wh_Client_Sha224Dma(whClientContext* ctx, wc_Sha224* sha, const uint8_t* in,
35123528
req->output.addr = (uint64_t)(uintptr_t)out;
35133529
req->output.sz = WC_SHA224_DIGEST_SIZE; /* not needed, but YOLO */
35143530
#ifdef DEBUG_CRYPTOCB_VERBOSE
3515-
printf("[client] SHA224 DMA UPDATE: inAddr=%p, inSz=%u\n", in, inLen);
3531+
printf("[client] SHA224 DMA UPDATE: inAddr=%p, inSz=%u\n", in,
3532+
(unsigned int)inLen);
35163533
#endif
35173534
ret = wh_Client_SendRequest(
35183535
ctx, group, WC_ALGO_TYPE_HASH,
@@ -3655,7 +3672,7 @@ static int _xferSha384BlockAndUpdateDigest(whClientContext* ctx,
36553672
/* wolfCrypt allows positive error codes on success in some scenarios */
36563673
if (ret >= 0) {
36573674
#ifdef DEBUG_CRYPTOCB_VERBOSE
3658-
printf("[client] ERROR Client SHA384 Res recv: ret=%d", ret);
3675+
printf("[client] Client SHA384 Res recv: ret=%d", ret);
36593676
#endif /* DEBUG_CRYPTOCB_VERBOSE */
36603677
/* Store the received intermediate hash in the sha384
36613678
* context and indicate the field is now valid and
@@ -3766,7 +3783,8 @@ int wh_Client_Sha384Dma(whClientContext* ctx, wc_Sha384* sha, const uint8_t* in,
37663783
req->output.addr = (uint64_t)(uintptr_t)out;
37673784
req->output.sz = WC_SHA384_DIGEST_SIZE; /* not needed, but YOLO */
37683785
#ifdef DEBUG_CRYPTOCB_VERBOSE
3769-
printf("[client] SHA384 DMA UPDATE: inAddr=%p, inSz=%u\n", in, inLen);
3786+
printf("[client] SHA384 DMA UPDATE: inAddr=%p, inSz=%u\n", in,
3787+
(unsigned int)inLen);
37703788
#endif
37713789
ret = wh_Client_SendRequest(
37723790
ctx, group, WC_ALGO_TYPE_HASH,
@@ -3910,7 +3928,7 @@ static int _xferSha512BlockAndUpdateDigest(whClientContext* ctx,
39103928
/* wolfCrypt allows positive error codes on success in some scenarios */
39113929
if (ret >= 0) {
39123930
#ifdef DEBUG_CRYPTOCB_VERBOSE
3913-
printf("[client] ERROR Client SHA512 Res recv: ret=%d", ret);
3931+
printf("[client] Client SHA512 Res recv: ret=%d", ret);
39143932
printf("[client] hashType: %d\n", sha512->hashType);
39153933
#endif /* DEBUG_CRYPTOCB_VERBOSE */
39163934
/* Store the received intermediate hash in the sha512
@@ -4032,7 +4050,8 @@ int wh_Client_Sha512Dma(whClientContext* ctx, wc_Sha512* sha, const uint8_t* in,
40324050
req->output.addr = (uint64_t)(uintptr_t)out;
40334051
req->output.sz = WC_SHA512_DIGEST_SIZE; /* not needed, but YOLO */
40344052
#ifdef DEBUG_CRYPTOCB_VERBOSE
4035-
printf("[client] SHA512 DMA UPDATE: inAddr=%p, inSz=%u\n", in, inLen);
4053+
printf("[client] SHA512 DMA UPDATE: inAddr=%p, inSz=%u\n", in,
4054+
(unsigned int)inLen);
40364055
#endif
40374056
ret = wh_Client_SendRequest(
40384057
ctx, group, WC_ALGO_TYPE_HASH,
@@ -4246,8 +4265,8 @@ static int _MlDsaMakeKey(whClientContext* ctx, int size, int level,
42464265
ret = wh_Client_SendRequest(ctx, group, action, req_len,
42474266
(uint8_t*)dataPtr);
42484267
#ifdef DEBUG_CRYPTOCB_VERBOSE
4249-
printf("[client] %s Req sent:size:%u, ret:%d\n", __func__, req->sz,
4250-
ret);
4268+
printf("[client] %s Req sent:size:%u, ret:%d\n", __func__,
4269+
(unsigned int)req->sz, ret);
42514270
#endif
42524271
if (ret == 0) {
42534272
uint16_t res_len;
@@ -4267,7 +4286,8 @@ static int _MlDsaMakeKey(whClientContext* ctx, int size, int level,
42674286
#ifdef DEBUG_CRYPTOCB_VERBOSE
42684287
printf(
42694288
"[client] %s Res recv:keyid:%u, len:%u, ret:%d\n",
4270-
__func__, res->keyId, res->len, ret);
4289+
__func__, (unsigned int)res->keyId,
4290+
(unsigned int)res->len, ret);
42714291
#endif
42724292
/* Key is cached on server or is ephemeral */
42734293
key_id = (whKeyId)(res->keyId);

0 commit comments

Comments
 (0)