Skip to content

Commit 22b85d7

Browse files
committed
Misc fixes in SHE server
1 parent 52fd0b6 commit 22b85d7

3 files changed

Lines changed: 22 additions & 13 deletions

File tree

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_MlDsaKey_SignCtx(&key, NULL, 0, sig, &localSigSz, msg,
718+
sizeof(msg), 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_MlDsaKey_SignCtx %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_MlDsaKey_VerifyCtx(&key, ml_dsa_44_sig,
849+
sizeof(ml_dsa_44_sig), NULL, 0, test_msg,
850+
sizeof(test_msg), &verified);
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_MlDsaKey_VerifyCtx %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: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4228,15 +4228,17 @@ 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_MlDsaKey_SignCtx(&key, NULL, 0, sig, &sigSz, msg, sizeof(msg),
4232+
rng);
42324233
if (ret != 0) {
42334234
WH_ERROR_PRINT("Failed to sign with ML DSA: %d\n", ret);
42344235
wc_MlDsaKey_Free(&key);
42354236
return ret;
42364237
}
42374238

42384239
/* Verify signature */
4239-
ret = wc_MlDsaKey_Verify(&key, sig, sigSz, msg, sizeof(msg), &verified);
4240+
ret = wc_MlDsaKey_VerifyCtx(&key, sig, sigSz, NULL, 0, msg, sizeof(msg),
4241+
&verified);
42404242
if (ret != 0) {
42414243
WH_ERROR_PRINT("Failed to verify ML DSA signature: %d\n", ret);
42424244
wc_MlDsaKey_Free(&key);
@@ -4250,7 +4252,8 @@ static int whTestCrypto_MlDsaWolfCrypt(whClientContext* ctx, int devId,
42504252
/* Modify signature to ensure verification fails */
42514253
sig[0] ^= 1;
42524254

4253-
ret = wc_MlDsaKey_Verify(&key, sig, sigSz, msg, sizeof(msg), &verified);
4255+
ret = wc_MlDsaKey_VerifyCtx(&key, sig, sigSz, NULL, 0, msg,
4256+
sizeof(msg), &verified);
42544257
if (ret != 0) {
42554258
WH_ERROR_PRINT("Failed to verify modified ML DSA signature: %d\n",
42564259
ret);
@@ -5042,8 +5045,9 @@ int whTestCrypto_MlDsaVerifyOnlyDma(whClientContext* ctx, int devId,
50425045
/* Verify the message signature */
50435046
if (ret == 0) {
50445047
int verifyResult;
5045-
ret = wc_MlDsaKey_Verify(key, ml_dsa_44_sig, sizeof(ml_dsa_44_sig),
5046-
test_msg, sizeof(test_msg), &verifyResult);
5048+
ret = wc_MlDsaKey_VerifyCtx(key, ml_dsa_44_sig, sizeof(ml_dsa_44_sig),
5049+
NULL, 0, test_msg, sizeof(test_msg),
5050+
&verifyResult);
50475051
if (ret != 0) {
50485052
WH_ERROR_PRINT("Signature did not verify\n");
50495053
}

0 commit comments

Comments
 (0)