| 1 | # Accumulated ML-DSA tests |
| 2 | |
| 3 | This file provides [accumulated](https://words.filippo.io/accumulated/) random |
| 4 | ML-DSA key generation and signature tests at various iteration counts, and |
| 5 | accumulated exhaustive tests for various field operations. |
| 6 | |
| 7 | ## Key generation and signature tests |
| 8 | |
| 9 | The vectors are generated by reading seeds from one instance of SHAKE128, and |
| 10 | writing the derived public key and the deterministic signature of an empty |
| 11 | message to another instance of SHAKE128. |
| 12 | |
| 13 | ``` |
| 14 | s = SHAKE128() |
| 15 | a = SHAKE128() |
| 16 | for i in range(N): |
| 17 | seed = read(s, 32) |
| 18 | public_key = keygen(seed) |
| 19 | write(a, public_key) |
| 20 | signature = sign_deterministic(seed, message="", context="") |
| 21 | write(a, signature) |
| 22 | if not verify(public_key, signature): error |
| 23 | result = read(a, 32) |
| 24 | ``` |
| 25 | |
| 26 | This allows running a number of known-answer tests that would be impractical if |
| 27 | the results had to be stored in full. |
| 28 | |
| 29 | In particular, the 60 million iteration test has a 99.9% chance of hitting any |
| 30 | value in [0, q). Storing that many vectors would require between 225 GB |
| 31 | (ML-DSA-44) and 435 GB (ML-DSA-87). |
| 32 | |
| 33 | 100 iterations is suitable for rapid interactive tests. 10 000 iterations are |
| 34 | suitable for CI. 60 000 000 iterations are suitable for development. |
| 35 | |
| 36 | Using fixed message, context, and signature randomness leads to the same μ for |
| 37 | every test, but doesn't reduce coverage because μ is only hashed with either |
| 38 | the secret key's random K, or w1 which is derived from the random matrix A. |
| 39 | |
| 40 | ### ML-DSA-44 |
| 41 | |
| 42 | - 100 iterations: `d51148e1f9f4fa1a723a6cf42e25f2a99eb5c1b378b3d2dbbd561b1203beeae4` |
| 43 | - 10 000 iterations: `e7fd21f6a59bcba60d65adc44404bb29a7c00e5d8d3ec06a732c00a306a7d143` |
| 44 | - 60 000 000 iterations: `080b48049257f5cd30dee17d6aa393d6c42fe52a29099df84a460ebaf4b02330` |
| 45 | |
| 46 | ### ML-DSA-65 |
| 47 | |
| 48 | - 100 iterations: `8358a1843220194417cadbc2651295cd8fc65125b5a5c1a239a16dc8b57ca199` |
| 49 | - 10 000 iterations: `5ff5e196f0b830c3b10a9eb5358e7c98a3a20136cb677f3ae3b90175c3ace329` |
| 50 | - 60 000 000 iterations: `0af0165db2b180f7a83dbecad1ccb758b9c2d834b7f801fc49dd572a9d4b1e83` |
| 51 | |
| 52 | ### ML-DSA-87 |
| 53 | |
| 54 | - 100 iterations: `8c3ad714777622b8f21ce31bb35f71394f23bc0fcf3c78ace5d608990f3b061b` |
| 55 | - 10 000 iterations: `80a8cf39317f7d0be0e24972c51ac152bd2a3e09bc0c32ce29dd82c4e7385e60` |
| 56 | - 60 000 000 iterations: `011166e9d5032c9bdc5c9bbb5dbb6c86df1c3d9bf3570b65ebae942dd9830057` |
| 57 | |
| 58 | ## Field operation tests |
| 59 | |
| 60 | The vector is generated by writing to a SHAKE128 instance the following |
| 61 | 12 values, as ASCII decimals with an optional leading `-` sign (if negative), |
| 62 | one per line, for each element r in ℤq from 0 to q - 1: |
| 63 | |
| 64 | - r mod± q |
| 65 | - ‖r‖∞ = |r mod± q| |
| 66 | - r1, r0 = Power2Round(r) |
| 67 | - r1 |
| 68 | - r0 mod q |
| 69 | |
| 70 | For ML-DSA-44 (γ₂ = (q - 1) / 88): |
| 71 | - HighBits(r) = UseHint(0, r) |
| 72 | - UseHint(1, r) |
| 73 | - LowBits(r) |
| 74 | - ‖LowBits(r)‖∞ = |LowBits(r)| |
| 75 | |
| 76 | For ML-DSA-65 and ML-DSA-87 (γ₂ = (q - 1) / 32): |
| 77 | - HighBits(r) = UseHint(0, r) |
| 78 | - UseHint(1, r) |
| 79 | - LowBits(r) |
| 80 | - ‖LowBits(r)‖∞ = |LowBits(r)| |
| 81 | |
| 82 | Note that HighBits(r), LowBits(r) = Decompose(r), so Decompose(r) can be tested |
| 83 | by checking its otuputs match those of HighBits(r) and LowBits(r). Similarly, |
| 84 | UseHint(0, r) can be tested by checking it matches HighBits(r). |
| 85 | |
| 86 | ``` |
| 87 | f930663417278156ab05d940294a77210a809c924d8ab63ec72f4526247602c7 |
| 88 | ``` |
| 89 | |
| 90 | See [mldsa-py@4c650a4][mldsa-py-test] and [CL 762940][go-cl-762940] for examples of how to use this vector. |
| 91 | |
| 92 | [mldsa-py-test]: https://github.com/FiloSottile/mldsa-py/commit/4c650a4a9db751a179cf2ec57d5fe01f2bee191c |
| 93 | [go-cl-762940]: https://go.dev/cl/762940 |
| 94 | |
| 95 | For r = 6 010 000, the 12 lines to be hashed are: |
| 96 | |
| 97 | ``` |
| 98 | -2370417 |
| 99 | 2370417 |
| 100 | 734 |
| 101 | 8377489 |
| 102 | 32 |
| 103 | 31 |
| 104 | -84848 |
| 105 | 84848 |
| 106 | 11 |
| 107 | 12 |
| 108 | 248464 |
| 109 | 248464 |
| 110 | ``` |