Skip to content

Commit 343d8e6

Browse files
committed
Misc fixes in SHE server
1 parent 52fd0b6 commit 343d8e6

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

benchmark/bench_modules/wh_bench_mod_mldsa.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,8 @@ static int _benchMlDsaSign(whClientContext* client, whBenchOpContext* ctx,
714714

715715
/* Time only the sign operation */
716716
benchStartRet = wh_Bench_StartOp(ctx, id);
717-
ret = wc_MlDsaKey_Sign(&key, sig, &localSigSz, msg, sizeof(msg), rng);
717+
ret = wc_dilithium_sign_msg(msg, sizeof(msg), sig, &localSigSz, &key,
718+
rng);
718719
benchStopRet = wh_Bench_StopOp(ctx, id);
719720

720721
if (benchStartRet != 0) {
@@ -723,7 +724,7 @@ static int _benchMlDsaSign(whClientContext* client, whBenchOpContext* ctx,
723724
break;
724725
}
725726
if (ret != 0) {
726-
WH_BENCH_PRINTF("Failed to wc_MlDsaKey_Sign %d\n", ret);
727+
WH_BENCH_PRINTF("Failed to wc_dilithium_sign_msg %d\n", ret);
727728
break;
728729
}
729730
if (benchStopRet != 0) {
@@ -844,8 +845,9 @@ static int _benchMlDsaVerify(whClientContext* client, whBenchOpContext* ctx,
844845

845846
/* Time only the verify operation */
846847
benchStartRet = wh_Bench_StartOp(ctx, id);
847-
ret = wc_MlDsaKey_Verify(&key, ml_dsa_44_sig, sizeof(ml_dsa_44_sig),
848-
test_msg, sizeof(test_msg), &verified);
848+
ret = wc_dilithium_verify_msg(ml_dsa_44_sig, sizeof(ml_dsa_44_sig),
849+
test_msg, sizeof(test_msg), &verified,
850+
&key);
849851
benchStopRet = wh_Bench_StopOp(ctx, id);
850852

851853
if (benchStartRet != 0) {
@@ -854,7 +856,7 @@ static int _benchMlDsaVerify(whClientContext* client, whBenchOpContext* ctx,
854856
break;
855857
}
856858
if (ret != 0) {
857-
WH_BENCH_PRINTF("Failed to wc_MlDsaKey_Verify %d\n", ret);
859+
WH_BENCH_PRINTF("Failed to wc_dilithium_verify_msg %d\n", ret);
858860
break;
859861
}
860862
if (benchStopRet != 0) {

src/wh_server_she.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ static int _ExportRamKey(whServerContext* server, uint16_t magic,
787787
/* set the counter, flags and ram key */
788788
memset(resp.messageTwo, 0, sizeof(resp.messageTwo));
789789
/* set count to 1 */
790-
counter_val = (wh_Utils_htonl(1) << 4);
790+
counter_val = wh_Utils_htonl(1 << 4);
791791
memcpy(resp.messageTwo, &counter_val, sizeof(uint32_t));
792792
keySz = WH_SHE_KEY_SZ;
793793
ret = wh_Server_KeystoreReadKey(
@@ -857,7 +857,7 @@ static int _ExportRamKey(whServerContext* server, uint16_t magic,
857857
if (ret == 0) {
858858
memset(resp.messageFour, 0, sizeof(resp.messageFour));
859859
/* set counter to 1, pad with 1 bit */
860-
counter_val = (wh_Utils_htonl(1) << 4);
860+
counter_val = wh_Utils_htonl(1 << 4);
861861
memcpy(resp.messageFour + WH_SHE_KEY_SZ, &counter_val,
862862
sizeof(uint32_t));
863863
resp.messageFour[WH_SHE_KEY_SZ + 3] |= 0x08;
@@ -1539,12 +1539,15 @@ static int _VerifyMac(whServerContext* server, uint16_t magic,
15391539
ret = wc_AesCmacVerify_ex(server->she->sheCmac, mac, req.macLen,
15401540
message, req.messageLen, tmpKey, keySz,
15411541
NULL, server->devId);
1542-
/* only evaluate if key was found */
15431542
if (ret == 0) {
15441543
resp.status = 0;
15451544
}
15461545
else {
1546+
/* Verify is allowed to fail, per SHE spec.
1547+
Capture status in the response, but return success to ensure
1548+
that the response is sent. */
15471549
resp.status = 1;
1550+
ret = 0;
15481551
}
15491552
}
15501553
else {

test/wh_test_crypto.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4228,15 +4228,16 @@ static int whTestCrypto_MlDsaWolfCrypt(whClientContext* ctx, int devId,
42284228
}
42294229

42304230
/* Sign message */
4231-
ret = wc_MlDsaKey_Sign(&key, sig, &sigSz, msg, sizeof(msg), rng);
4231+
ret = wc_dilithium_sign_msg(msg, sizeof(msg), sig, &sigSz, &key, rng);
42324232
if (ret != 0) {
42334233
WH_ERROR_PRINT("Failed to sign with ML DSA: %d\n", ret);
42344234
wc_MlDsaKey_Free(&key);
42354235
return ret;
42364236
}
42374237

42384238
/* Verify signature */
4239-
ret = wc_MlDsaKey_Verify(&key, sig, sigSz, msg, sizeof(msg), &verified);
4239+
ret = wc_dilithium_verify_msg(sig, sigSz, msg, sizeof(msg), &verified,
4240+
&key);
42404241
if (ret != 0) {
42414242
WH_ERROR_PRINT("Failed to verify ML DSA signature: %d\n", ret);
42424243
wc_MlDsaKey_Free(&key);
@@ -4250,7 +4251,8 @@ static int whTestCrypto_MlDsaWolfCrypt(whClientContext* ctx, int devId,
42504251
/* Modify signature to ensure verification fails */
42514252
sig[0] ^= 1;
42524253

4253-
ret = wc_MlDsaKey_Verify(&key, sig, sigSz, msg, sizeof(msg), &verified);
4254+
ret = wc_dilithium_verify_msg(sig, sigSz, msg, sizeof(msg), &verified,
4255+
&key);
42544256
if (ret != 0) {
42554257
WH_ERROR_PRINT("Failed to verify modified ML DSA signature: %d\n",
42564258
ret);
@@ -5042,8 +5044,9 @@ int whTestCrypto_MlDsaVerifyOnlyDma(whClientContext* ctx, int devId,
50425044
/* Verify the message signature */
50435045
if (ret == 0) {
50445046
int verifyResult;
5045-
ret = wc_MlDsaKey_Verify(key, ml_dsa_44_sig, sizeof(ml_dsa_44_sig),
5046-
test_msg, sizeof(test_msg), &verifyResult);
5047+
ret = wc_dilithium_verify_msg(ml_dsa_44_sig, sizeof(ml_dsa_44_sig),
5048+
test_msg, sizeof(test_msg),
5049+
&verifyResult, key);
50475050
if (ret != 0) {
50485051
WH_ERROR_PRINT("Signature did not verify\n");
50495052
}

0 commit comments

Comments
 (0)