Skip to content

Commit 55d7ed8

Browse files
committed
ML-DSA fixes: small vfy key object, small SHA-3, fix test
Only have the public key in the ML-DSA key object when verify-only. Be able to leave out SHA-3 APIs when only needing SHAKE. Fix ML-DSA testing to only have data for compiled in parameters.
1 parent 980fc51 commit 55d7ed8

3 files changed

Lines changed: 30 additions & 4 deletions

File tree

tests/api/test_mldsa.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24565,6 +24565,7 @@ int test_wc_dilithium_sign_mu_kats(void)
2456524565
* convention, so passing zeroSeed reproduces them byte-for-byte. */
2456624566
static const byte zeroSeed[DILITHIUM_RND_SZ] = { 0 };
2456724567

24568+
#ifndef WOLFSSL_NO_ML_DSA_44
2456824569
/* ML-DSA-44 externalMu: deterministic, tcId 91
2456924570
* Source: kh-fork-fips/wolfACVP/v7.0.0-known/
2457024571
* ML-DSA-sigGen-request.json. Deterministic mode
@@ -25206,7 +25207,9 @@ int test_wc_dilithium_sign_mu_kats(void)
2520625207
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2520725208
0x12, 0x1f, 0x28, 0x39
2520825209
};
25210+
#endif
2520925211

25212+
#ifndef WOLFSSL_NO_ML_DSA_65
2521025213
/* ML-DSA-65 externalMu: deterministic, tcId 121
2521125214
* Source: kh-fork-fips/wolfACVP/v7.0.0-known/
2521225215
* ML-DSA-sigGen-request.json. Deterministic mode
@@ -26143,7 +26146,9 @@ int test_wc_dilithium_sign_mu_kats(void)
2614326146
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,
2614426147
0x0c, 0x10, 0x18, 0x1c, 0x1f
2614526148
};
26149+
#endif
2614626150

26151+
#ifndef WOLFSSL_NO_ML_DSA_87
2614726152
/* ML-DSA-87 externalMu: deterministic, tcId 151
2614826153
* Source: kh-fork-fips/wolfACVP/v7.0.0-known/
2614926154
* ML-DSA-sigGen-request.json. Deterministic mode
@@ -27353,6 +27358,7 @@ int test_wc_dilithium_sign_mu_kats(void)
2735327358
0x00, 0x00, 0x00, 0x01, 0x08, 0x0e, 0x16, 0x1e,
2735427359
0x22, 0x2a, 0x30
2735527360
};
27361+
#endif
2735627362

2735727363

2735827364
ExpectNotNull(key = (dilithium_key*)XMALLOC(sizeof(*key), NULL,
@@ -27423,6 +27429,7 @@ int test_wc_dilithium_verify_mu_kats(void)
2742327429
byte muBuf[DILITHIUM_MU_SZ];
2742427430
int res;
2742527431

27432+
#ifndef WOLFSSL_NO_ML_DSA_44
2742627433
/* ML-DSA-44 externalMu: deterministic, tcId 91
2742727434
* Source: kh-fork-fips/wolfACVP/v7.0.0-known/
2742827435
* ML-DSA-sigGen-request.json. Deterministic mode
@@ -27908,7 +27915,9 @@ int test_wc_dilithium_verify_mu_kats(void)
2790827915
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2790927916
0x12, 0x1f, 0x28, 0x39
2791027917
};
27918+
#endif
2791127919

27920+
#ifndef WOLFSSL_NO_ML_DSA_65
2791227921
/* ML-DSA-65 externalMu: deterministic, tcId 121
2791327922
* Source: kh-fork-fips/wolfACVP/v7.0.0-known/
2791427923
* ML-DSA-sigGen-request.json. Deterministic mode
@@ -28585,7 +28594,9 @@ int test_wc_dilithium_verify_mu_kats(void)
2858528594
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,
2858628595
0x0c, 0x10, 0x18, 0x1c, 0x1f
2858728596
};
28597+
#endif
2858828598

28599+
#ifndef WOLFSSL_NO_ML_DSA_87
2858928600
/* ML-DSA-87 externalMu: deterministic, tcId 151
2859028601
* Source: kh-fork-fips/wolfACVP/v7.0.0-known/
2859128602
* ML-DSA-sigGen-request.json. Deterministic mode
@@ -29507,7 +29518,7 @@ int test_wc_dilithium_verify_mu_kats(void)
2950729518
0x00, 0x00, 0x00, 0x01, 0x08, 0x0e, 0x16, 0x1e,
2950829519
0x22, 0x2a, 0x30
2950929520
};
29510-
29521+
#endif
2951129522

2951229523
ExpectNotNull(key = (dilithium_key*)XMALLOC(sizeof(*key), NULL,
2951329524
DYNAMIC_TYPE_TMP_BUFFER));

wolfcrypt/src/sha3.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,8 @@ static int wc_InitSha3(wc_Sha3* sha3, void* heap, int devId)
11131113
return ret;
11141114
}
11151115

1116+
#if !(defined(WOLFSSL_NOSHA3_224) && defined(WOLFSSL_NOSHA3_256) && \
1117+
defined(WOLFSSL_NOSHA3_384) && defined(WOLFSSL_NOSHA3_512))
11161118
/* Update the SHA-3 hash state with message data.
11171119
*
11181120
* sha3 wc_Sha3 object holding state.
@@ -1243,6 +1245,7 @@ static int wc_Sha3Final(wc_Sha3* sha3, byte* hash, byte p, byte len)
12431245
return InitSha3(sha3); /* reset state */
12441246
}
12451247
#endif
1248+
#endif
12461249

12471250
/* Dispose of any dynamically allocated data from the SHA3-384 operation.
12481251
* (Required for async ops.)
@@ -1342,6 +1345,8 @@ static int wc_Sha3Copy(wc_Sha3* src, wc_Sha3* dst)
13421345
return ret;
13431346
}
13441347

1348+
#if !(defined(WOLFSSL_NOSHA3_224) && defined(WOLFSSL_NOSHA3_256) && \
1349+
defined(WOLFSSL_NOSHA3_384) && defined(WOLFSSL_NOSHA3_512))
13451350
/* Calculate the SHA3-224 hash based on all the message data so far.
13461351
* More message data can be added, after this operation, using the current
13471352
* state.
@@ -1372,7 +1377,9 @@ static int wc_Sha3GetHash(wc_Sha3* sha3, byte* hash, byte p, byte len)
13721377
WC_FREE_VAR_EX(tmpSha3, sha3->heap, DYNAMIC_TYPE_TMP_BUFFER);
13731378
return ret;
13741379
}
1380+
#endif
13751381

1382+
#ifndef WOLFSSL_NOSHA3_224
13761383
/* Initialize the state for a SHA3-224 hash operation.
13771384
*
13781385
* sha3 wc_Sha3 object holding state.
@@ -1443,8 +1450,9 @@ int wc_Sha3_224_Copy(wc_Sha3* src, wc_Sha3* dst)
14431450
{
14441451
return wc_Sha3Copy(src, dst);
14451452
}
1453+
#endif
14461454

1447-
1455+
#ifndef WOLFSSL_NOSHA3_256
14481456
/* Initialize the state for a SHA3-256 hash operation.
14491457
*
14501458
* sha3 wc_Sha3 object holding state.
@@ -1515,8 +1523,9 @@ int wc_Sha3_256_Copy(wc_Sha3* src, wc_Sha3* dst)
15151523
{
15161524
return wc_Sha3Copy(src, dst);
15171525
}
1526+
#endif
15181527

1519-
1528+
#ifndef WOLFSSL_NOSHA3_384
15201529
/* Initialize the state for a SHA3-384 hash operation.
15211530
*
15221531
* sha3 wc_Sha3 object holding state.
@@ -1587,8 +1596,9 @@ int wc_Sha3_384_Copy(wc_Sha3* src, wc_Sha3* dst)
15871596
{
15881597
return wc_Sha3Copy(src, dst);
15891598
}
1599+
#endif
15901600

1591-
1601+
#ifndef WOLFSSL_NOSHA3_512
15921602
/* Initialize the state for a SHA3-512 hash operation.
15931603
*
15941604
* sha3 wc_Sha3 object holding state.
@@ -1659,6 +1669,7 @@ int wc_Sha3_512_Copy(wc_Sha3* src, wc_Sha3* dst)
16591669
{
16601670
return wc_Sha3Copy(src, dst);
16611671
}
1672+
#endif
16621673

16631674
#ifdef WOLFSSL_HASH_FLAGS
16641675
int wc_Sha3_SetFlags(wc_Sha3* sha3, word32 flags)

wolfssl/wolfcrypt/dilithium.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,11 +638,15 @@ struct dilithium_key {
638638
#elif !defined(WOLFSSL_DILITHIUM_ASSIGN_KEY)
639639
#ifdef USE_INTEL_SPEEDUP
640640
byte p[DILITHIUM_MAX_PUB_KEY_SIZE+8];
641+
#if !defined(WOLFSSL_DILITHIUM_VERIFY_ONLY)
641642
byte k[DILITHIUM_MAX_KEY_SIZE+8];
643+
#endif
642644
#else
643645
byte p[DILITHIUM_MAX_PUB_KEY_SIZE];
646+
#if !defined(WOLFSSL_DILITHIUM_VERIFY_ONLY)
644647
byte k[DILITHIUM_MAX_KEY_SIZE];
645648
#endif
649+
#endif
646650
#else
647651
const byte* p;
648652
const byte* k;

0 commit comments

Comments
 (0)