Skip to content

Commit db8845e

Browse files
committed
align code with ML-DSA
1 parent 302b769 commit db8845e

25 files changed

+4243
-5873
lines changed

README.md

+8-11
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ applications.** :warning:
1313
1414
This repository contains a pure python implementation of both:
1515

16+
1. **ML-DSA** the NIST Module-Lattice-Based Digital Signature Standard following
17+
the [FIPS 204](https://csrc.nist.gov/pubs/fips/204/final) based off the Dilithium
18+
submission to the NIST post-quantum project.
1619
1. **CRYSTALS-Dilithium**: following (at the time of writing) the most recent
1720
[specification](https://pq-crystals.org/dilithium/data/dilithium-specification-round3-20210208.pdf) (v3.1)
18-
2. **ML-DSA** the NIST Module-Lattice-Based Digital Signature Standard following
19-
the [FIPS 204 (Initial Public
20-
Draft)](https://csrc.nist.gov/pubs/fips/204/ipd) based off the Dilithium
21-
submission to the NIST post-quantum project.
2221

2322
**Note**: This project has followed
2423
[`kyber-py`](https://github.com/GiacomoPope/kyber-py) which is a pure-python
@@ -51,11 +50,11 @@ This implementation passes all the KAT vectors for `dilithium` and `ml_dsa`. For
5150

5251
The KAT files were either downloaded or generated:
5352

54-
1. For **Dilithium**, the KAT files were generated from the projects [GitHub
53+
1. For **ML-DSA**, the KAT files were download from the GitHub repository
54+
[usnistgov/ACVP-Server/](https://github.com/usnistgov/ACVP-Server/releases/tag/v1.1.0.35) release 1.1.0.35, and are included in `assets/ML-DSA-*` directories.
55+
2. For **Dilithium**, the KAT files were generated from the projects [GitHub
5556
repository](https://github.com/pq-crystals/dilithium/) and are included in
5657
`assets/PQCsignKAT_*.rsp`
57-
2. For **ML-DSA**, the KAT files were download from the GitHub repository
58-
[post-quantum-cryptography/KAT](https://github.com/post-quantum-cryptography/KAT/tree/main/MLDSA) and are included in `assets/kat_MLDSA_*.rsp`
5958

6059
### Generating KAT files for Dilithium
6160

@@ -220,7 +219,7 @@ For the NIST specification the hint is generated by considering the vectors
220219
$-c\mathbf{t}_0$ and $\mathbf{w} -c\mathbf{s}_1 + -c\mathbf{t}_0$ and each
221220
coefficient of each polynomial within $\mathbf{h}$ is computed by checking if
222221
the top bits will change when the coefficients `r` and `r + z` are added
223-
together. This is computed using algorithm 33 from FIPS 204-ipd:
222+
together. This is computed using algorithm 39 from FIPS 204:
224223

225224
```py
226225
def make_hint(z, r, a, q):
@@ -239,7 +238,7 @@ For the Dilithium optimisation, rather than computing only the high bits of
239238
$\mathbf{w}$ as $\mathbf{w}_1$, for the same cost, one can compute both the high
240239
and low bits denoted $\mathbf{w}_1$ and $\mathbf{w}_0$. Then, the hint can be
241240
constructed from $\mathbf{w}_0$ (and a further call to low bits for
242-
$\mathbf{r}_0$ in line 22 of Algorithm 2 of FIPS 204-ipd can be avoided). Precisely, the hint is generated from the two vectors $\mathbf{w}_0 -c\mathbf{s}_1 + -c\mathbf{t}_0$ and $\mathbf{w}_1$.
241+
$\mathbf{r}_0$ in line 21 of Algorithm 7 of FIPS 204 can be avoided). Precisely, the hint is generated from the two vectors $\mathbf{w}_0 -c\mathbf{s}_1 + -c\mathbf{t}_0$ and $\mathbf{w}_1$.
243242

244243
As the inputs to the hint generation are now used from the decomposition, where
245244
top bits have already been removed, the `make_hint()` function has to check
@@ -362,8 +361,6 @@ lets revisit the ring from the previous example:
362361

363362
### Number Theoretic Transform
364363

365-
**TODO**: More details about the NTT.
366-
367364
We can transform polynomials to NTT form and from NTT form
368365
with `poly.to_ntt()` and `poly.from_ntt()`.
369366

assets/ML-DSA-keyGen-FIPS204/expectedResults.json

+399
Large diffs are not rendered by default.

assets/ML-DSA-keyGen-FIPS204/internalProjection.json

+555
Large diffs are not rendered by default.
+330
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,330 @@
1+
{
2+
"vsId": 42,
3+
"algorithm": "ML-DSA",
4+
"mode": "keyGen",
5+
"revision": "FIPS204",
6+
"isSample": false,
7+
"testGroups": [
8+
{
9+
"tgId": 1,
10+
"testType": "AFT",
11+
"parameterSet": "ML-DSA-44",
12+
"tests": [
13+
{
14+
"tcId": 1,
15+
"seed": "93EF2E6EF1FB08999D142ABE0295482370D3F43BDB254A78E2B0D5168ECA065F"
16+
},
17+
{
18+
"tcId": 2,
19+
"seed": "D6A5D2325B94CA1B993A0151E24AB95B396F415831DC14A08404820AE58A2AD1"
20+
},
21+
{
22+
"tcId": 3,
23+
"seed": "8A5E79B82DC81553BBE821EE367F0ADFA54F59A3E8A71CA626F873F638636DD7"
24+
},
25+
{
26+
"tcId": 4,
27+
"seed": "6137CAB1DBF57A5CFCD0079BA87FAF2C7141EBB92DABBD45FD8B478D24AB8946"
28+
},
29+
{
30+
"tcId": 5,
31+
"seed": "B9E2F48349350D30A5342783C915A608C905E0DA4BEBE2067FB62C714207C62B"
32+
},
33+
{
34+
"tcId": 6,
35+
"seed": "2241FB7005D1B26A1735FFEA5186D08950B4B12CD4FF51BD263C6B8A2A2A18D0"
36+
},
37+
{
38+
"tcId": 7,
39+
"seed": "32BA0BCE82AC978E5932BD14B1AC1A9319BA20412538191E2C7B1E0BD1D01CBE"
40+
},
41+
{
42+
"tcId": 8,
43+
"seed": "0BE86B084CD4B31D855EBDED6DE39326516D4BA6770B76B1D4398FB2C9C75196"
44+
},
45+
{
46+
"tcId": 9,
47+
"seed": "68E203AD881ECE7B354F6A760C87CE3C2F7A62EF1E12C71DC2A965517F0E196D"
48+
},
49+
{
50+
"tcId": 10,
51+
"seed": "F09E23ABE72DF75EE36DC1C952F56564FA4213A987A0656FF758F3991BF4E1B3"
52+
},
53+
{
54+
"tcId": 11,
55+
"seed": "F4476E8F0B3DD9319238639F50C78B3FE1BF404EF184AEA2D9E60D3028FFADF7"
56+
},
57+
{
58+
"tcId": 12,
59+
"seed": "130A45A87F380C72BA709CF5A432BF768E1D875A30C860FF8B74BC56A7C8A042"
60+
},
61+
{
62+
"tcId": 13,
63+
"seed": "3D00709DA8D78B889875F40AAAC1635D2BBAF0BB7F37F6C4ABCB7220A5808F67"
64+
},
65+
{
66+
"tcId": 14,
67+
"seed": "530D229A951CE81973289F186CF9CBB284D9A0A0888EB818D6B9D78648E074D5"
68+
},
69+
{
70+
"tcId": 15,
71+
"seed": "2FAD994FA583FCF6B858B58ABFD4B42FFA64D552ECDCA55878EB62A0BCC17280"
72+
},
73+
{
74+
"tcId": 16,
75+
"seed": "64C00833C31B906FE4F7CABA5D0E2E26A81310F20EDDB3E1913F44B89771C783"
76+
},
77+
{
78+
"tcId": 17,
79+
"seed": "16CBFEFA6448D329CCC9A68DAE478FDFC02D73C0F1DED9F6A87423A52208296E"
80+
},
81+
{
82+
"tcId": 18,
83+
"seed": "EA945C93BA680770398A958B46DB716AC3D58C0AC3AB49DA134DF31504FA510B"
84+
},
85+
{
86+
"tcId": 19,
87+
"seed": "F7AD0FDBD2F83B60C726521BCC0923122D1257181BF03C25516FDE98C709F781"
88+
},
89+
{
90+
"tcId": 20,
91+
"seed": "B0C02139AEF99336D87001D936CF8DFE30459D268074B69720B15BB7939F3D4B"
92+
},
93+
{
94+
"tcId": 21,
95+
"seed": "9E5E467662A57A5A45824B882101553E95DAF19EC097B6310ABE3935C24CF284"
96+
},
97+
{
98+
"tcId": 22,
99+
"seed": "E13C0B6585FE12EB64086B34B49D5E074EBE3A3688EDEEBB26A737C0E5F73F44"
100+
},
101+
{
102+
"tcId": 23,
103+
"seed": "CCA8DE2D58EDCB32ED7EA7F60926658AF64330AFC8398010232F9910DFBD85CC"
104+
},
105+
{
106+
"tcId": 24,
107+
"seed": "7D80938B0E94C0C67513186B04F7E2A5CD3BBF9F3F47EE074B7FD6F74DB4F857"
108+
},
109+
{
110+
"tcId": 25,
111+
"seed": "CD52A8ED3FCAF1F0D0DFB7394D3ADF9DF810203199E62356E56B7217F786B29B"
112+
}
113+
]
114+
},
115+
{
116+
"tgId": 2,
117+
"testType": "AFT",
118+
"parameterSet": "ML-DSA-65",
119+
"tests": [
120+
{
121+
"tcId": 26,
122+
"seed": "70CEFB9AED5B68E018B079DA8284B9D5CAD5499ED9C265FF73588005D85C225C"
123+
},
124+
{
125+
"tcId": 27,
126+
"seed": "4B4B71C5A1BC1074F2167A1D68729CDB9E16ABA3651FF02A0A0F4C883CAAC827"
127+
},
128+
{
129+
"tcId": 28,
130+
"seed": "FB27DBBB4ED8F4F7D2700283C2B092866694246932EEACEE72DB730EFD172576"
131+
},
132+
{
133+
"tcId": 29,
134+
"seed": "334ADAD056F76D74941FD87E5263E449D97C06D748A82018D0C794154C20A870"
135+
},
136+
{
137+
"tcId": 30,
138+
"seed": "06C016CB8566F5B81F8457F56175AE77DD05C35EB37B687EAE89147DD7ED008D"
139+
},
140+
{
141+
"tcId": 31,
142+
"seed": "AF5A2ECF442AF8C0371F89C499ABC337021992F221C1D3A66B551DEC917F1B1A"
143+
},
144+
{
145+
"tcId": 32,
146+
"seed": "D85D7C2928288CD0B90D7269619F8D8B4EB3541F7E084CDE0E39CEFFECE9AF80"
147+
},
148+
{
149+
"tcId": 33,
150+
"seed": "62E511A6731C2FA10DFB5F68A538CCDC1BC578C16E7EFFF458A82627438E78F2"
151+
},
152+
{
153+
"tcId": 34,
154+
"seed": "BC4EF6C46CB18061966CD872D2CB9826B0220173E42F11B451DFF93C0577CDF5"
155+
},
156+
{
157+
"tcId": 35,
158+
"seed": "135DF872744277E90019BD1E904DCBED63741D863E82388B61A2B069E509B25A"
159+
},
160+
{
161+
"tcId": 36,
162+
"seed": "AEF72BA72607B5D3E49C579752BE9CB9FA67A01B2E8B654EE92177BBA596066E"
163+
},
164+
{
165+
"tcId": 37,
166+
"seed": "16759CE55C6741D02EFAFEF5D7521BC0D2B3ADB55088F61F0028656AC970C70E"
167+
},
168+
{
169+
"tcId": 38,
170+
"seed": "1A1520478204D8CA028FB48EFD49367A562F66452E43B305118C85B4444675A8"
171+
},
172+
{
173+
"tcId": 39,
174+
"seed": "C2B63699D7C013E2D0C3A6A5D79CB60122B8C8574694975F4D703D75035DDD6D"
175+
},
176+
{
177+
"tcId": 40,
178+
"seed": "821ACBFE29F941CD0F02D6BDC0112688B212D5C925AC08FAACC248E7510CF88F"
179+
},
180+
{
181+
"tcId": 41,
182+
"seed": "19B20AEC7AED1C129B55D7A5143192A3CF43BB55069017D695581B74006788C5"
183+
},
184+
{
185+
"tcId": 42,
186+
"seed": "12FB6DF663126191038F413001776E0791E024B1129DB3084A1CDB809404B555"
187+
},
188+
{
189+
"tcId": 43,
190+
"seed": "2D6ECBAAE0E5A784B543BE58A0650680AE813A01C7E0C9FE65ECB32A304DD218"
191+
},
192+
{
193+
"tcId": 44,
194+
"seed": "3199830796190C3968520DAD86A85B677558A22257E43459AC684B68CE336DA7"
195+
},
196+
{
197+
"tcId": 45,
198+
"seed": "E788F93DB12EB4DB91993C6636C009D06D503D5331125A2AD635354AF49ED3A5"
199+
},
200+
{
201+
"tcId": 46,
202+
"seed": "03D86B249CF84472E3B78B12110E2C09C7428FAB65D362760D0800914696D411"
203+
},
204+
{
205+
"tcId": 47,
206+
"seed": "B9446E8F78C8B7B2ACD335B10F0B8FE1B34007A1D827EB5517710569E060AFC7"
207+
},
208+
{
209+
"tcId": 48,
210+
"seed": "910E96CAE3F7DF10E0686DCAD2D6CF8E0DD9ED69F3661F0799DF91CD6C494986"
211+
},
212+
{
213+
"tcId": 49,
214+
"seed": "D0632A6EDAFFE0A71E94E62A5135066E6F7ABF8065774A2596B6BA2F7F138BB8"
215+
},
216+
{
217+
"tcId": 50,
218+
"seed": "74C0714236873EE53E7F8F65B1159ACCB1994B4E9D3E8FF194CC87D7116BC0B4"
219+
}
220+
]
221+
},
222+
{
223+
"tgId": 3,
224+
"testType": "AFT",
225+
"parameterSet": "ML-DSA-87",
226+
"tests": [
227+
{
228+
"tcId": 51,
229+
"seed": "38359FBCD79582CFFE609E137EE2EFE8A8DBCBAD18BA92BB433AB4F09B49299D"
230+
},
231+
{
232+
"tcId": 52,
233+
"seed": "29B4987C62218C19C77D695EB904AFFAA1BFEF6A52F138604CDAB1534E66DC10"
234+
},
235+
{
236+
"tcId": 53,
237+
"seed": "9B54B9C91E0201251489E07D1442A42D0BF32189D0C0CA8A2D4871DB25F531FF"
238+
},
239+
{
240+
"tcId": 54,
241+
"seed": "A5B67695D7DBBD6A7B25146E30DC3F577240AED2E4E20158D1E24143698D1178"
242+
},
243+
{
244+
"tcId": 55,
245+
"seed": "1B87631F6ECC4BC8FFD14B2792F3D1691A46C22A26BBC98DEB2554D7FD2522AB"
246+
},
247+
{
248+
"tcId": 56,
249+
"seed": "5C3E3EF0278EA9197F30C4DD9C4C06425C05401253E77DFB3E1D5315CB00915B"
250+
},
251+
{
252+
"tcId": 57,
253+
"seed": "E3B2350AF8A1817D936FB7435C4C0CC758F79FF4696C46E4642670C5A78B30EE"
254+
},
255+
{
256+
"tcId": 58,
257+
"seed": "75E70362235CC7CC4A08053BD887CDCC4E3D88F77E1C7DACAC972A9AF83C0CB2"
258+
},
259+
{
260+
"tcId": 59,
261+
"seed": "45CCECBAFEAC42F2D9166A879175A6D6263C3F7F9B5F39F27A1578C859CECF89"
262+
},
263+
{
264+
"tcId": 60,
265+
"seed": "4A74BED90EF52CF135555B622A50D1A4F5C53D97D3176A1B184CE55380DE6FDA"
266+
},
267+
{
268+
"tcId": 61,
269+
"seed": "779C11F3F4D148FC911E188946C09E67EAA04DF670B6E0B6A96B661FD84E8994"
270+
},
271+
{
272+
"tcId": 62,
273+
"seed": "A94A73CDD32CF203AC75E89A6BE1AA55AEE0F2E45C8923F6D4954C611ACEC3F5"
274+
},
275+
{
276+
"tcId": 63,
277+
"seed": "86CB0744A2F973D562DB3B2C47E234F02C0ED60D2EC27326407492F6A6913BAB"
278+
},
279+
{
280+
"tcId": 64,
281+
"seed": "23BB289CC934CEB1993640DF1015693EA499786882A987414FD320489FB549DB"
282+
},
283+
{
284+
"tcId": 65,
285+
"seed": "F53C24BA9D2E6C4C35249377D1F653B2E8F7ED655292EAAA86A5720F46A9FAF6"
286+
},
287+
{
288+
"tcId": 66,
289+
"seed": "C8D0778FC6359E5FA663FC32E9DD1E53F26671B46C7750DC50CE69617A36D2E1"
290+
},
291+
{
292+
"tcId": 67,
293+
"seed": "B401635BE8E33FA0D248F6F5E6E599741501A0F077AB827926E7DEA4E8A672C3"
294+
},
295+
{
296+
"tcId": 68,
297+
"seed": "BF2846DEA3C6081ACAF75BF64AFAFEDDF8BD15F91767993B2512551457A429ED"
298+
},
299+
{
300+
"tcId": 69,
301+
"seed": "12B78D9B1A0645B5744CA179DC53994C83B561F77E63C32BFA617CA75AEEA7E6"
302+
},
303+
{
304+
"tcId": 70,
305+
"seed": "BE8D7347BCA4E0611DEA6C735700DD86180C4B95CBE7FB27491F00C9445D8A3E"
306+
},
307+
{
308+
"tcId": 71,
309+
"seed": "E4CA0A81DB7A44E5F3DAE5B9770DC89F15F02126C3077642B67B361B7A75A9E4"
310+
},
311+
{
312+
"tcId": 72,
313+
"seed": "7B4BB05212C7AEB83E3C04F8C9FFDE0526EC4E22E29EA84260A89292AF1E4DE4"
314+
},
315+
{
316+
"tcId": 73,
317+
"seed": "31F5D7AB44ACD0072423A8E486EFF6D8E2EC8D9D25040D6209BE64FDD03A7664"
318+
},
319+
{
320+
"tcId": 74,
321+
"seed": "2ACCB6888C3525515F10A2ABEA6D7A3B0CD43AE249F1F7CA93D1DDA58A6C825D"
322+
},
323+
{
324+
"tcId": 75,
325+
"seed": "DFCC13CED6971EB1BF3243CB8EE883FEA9677D1E5DA8F3046CFA4305DFB79127"
326+
}
327+
]
328+
}
329+
]
330+
}

0 commit comments

Comments
 (0)