Skip to content

Commit 29c2888

Browse files
authored
Merge pull request #310 from padelsbach/padelsbach/she-misc-fixers
Misc fixes in SHE server
2 parents cf509c9 + 22b85d7 commit 29c2888

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
@@ -788,7 +788,7 @@ static int _ExportRamKey(whServerContext* server, uint16_t magic,
788788
/* set the counter, flags and ram key */
789789
memset(resp.messageTwo, 0, sizeof(resp.messageTwo));
790790
/* set count to 1 */
791-
counter_val = (wh_Utils_htonl(1) << 4);
791+
counter_val = wh_Utils_htonl(1 << 4);
792792
memcpy(resp.messageTwo, &counter_val, sizeof(uint32_t));
793793
keySz = WH_SHE_KEY_SZ;
794794
ret = wh_Server_KeystoreReadKey(
@@ -858,7 +858,7 @@ static int _ExportRamKey(whServerContext* server, uint16_t magic,
858858
if (ret == 0) {
859859
memset(resp.messageFour, 0, sizeof(resp.messageFour));
860860
/* set counter to 1, pad with 1 bit */
861-
counter_val = (wh_Utils_htonl(1) << 4);
861+
counter_val = wh_Utils_htonl(1 << 4);
862862
memcpy(resp.messageFour + WH_SHE_KEY_SZ, &counter_val,
863863
sizeof(uint32_t));
864864
resp.messageFour[WH_SHE_KEY_SZ + 3] |= 0x08;
@@ -1540,12 +1540,15 @@ static int _VerifyMac(whServerContext* server, uint16_t magic,
15401540
ret = wc_AesCmacVerify_ex(server->she->sheCmac, mac, req.macLen,
15411541
message, req.messageLen, tmpKey, keySz,
15421542
NULL, server->devId);
1543-
/* only evaluate if key was found */
15441543
if (ret == 0) {
15451544
resp.status = 0;
15461545
}
15471546
else {
1547+
/* Verify is allowed to fail, per SHE spec.
1548+
Capture status in the response, but return success to ensure
1549+
that the response is sent. */
15481550
resp.status = 1;
1551+
ret = 0;
15491552
}
15501553
}
15511554
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)