authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2024-08-22 07:54:12+02:00
committergravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2024-08-22 07:54:12+02:00
logb131b6dd3639ff4c449c73978ddc77f51161fd9b
tree08ec1c932a7e4d462e74983cf7607ef3599db147
parent067ae04e0b34bfba9bdb192705731fbf9801e69f

Rename the namespace for ml_kem variants of Kyber to nist


2 files changed, 16 insertions(+), 22 deletions(-)

lib/std/crypto.zig+3-2
......@@ -74,8 +74,9 @@ pub const dh = struct {
7474
7575/// Key Encapsulation Mechanisms.
7676pub const kem = struct {
77 pub const kyber_d00 = @import("crypto/ml_kem.zig").kyber_d00;
78 pub const ml_kem_01 = @import("crypto/ml_kem.zig").ml_kem_01;
77 pub const kyber_d00 = @import("crypto/ml_kem.zig").d00;
78 pub const ml_kem = @import("crypto/ml_kem.zig").nist;
79 pub const ml_kem_01 = @compileError("deprecated: final version of the specification has been published, use ml_kem instead");
7980};
8081
8182/// Elliptic-curve arithmetic.
lib/std/crypto/ml_kem.zig+13-20
......@@ -1,13 +1,8 @@
11//! Implementation of the IND-CCA2 post-quantum secure key encapsulation mechanism (KEM)
22//! ML-KEM (NIST FIPS-203 publication) and CRYSTALS-Kyber (v3.02/"draft00" CFRG draft).
33//!
4//! The Kyber namespace suffix (currently `_d00`) refers to the version currently
5//! implemented, in accordance with the CFRG draft.
6//!
7//! The ML-KEM namespace refers to the FIPS-203 publication.
8//!
9//! Suffixes may not be updated if new versions of the documents only include editorial changes.
10//! The suffixes will be removed once the schemes are finalized.
4//! The namespace `d00` refers to the version currently implemented, in accordance with the CFRG draft.
5//! The `nist` namespace refers to the FIPS-203 publication.
116//!
127//! Quoting from the CFRG I-D:
138//!
......@@ -146,7 +141,7 @@ const Params = struct {
146141 dv: u8,
147142};
148143
149pub const kyber_d00 = struct {
144pub const d00 = struct {
150145 pub const Kyber512 = Kyber(.{
151146 .name = "Kyber512",
152147 .k = 2,
......@@ -172,9 +167,7 @@ pub const kyber_d00 = struct {
172167 });
173168};
174169
175pub const ml_kem_01 = @compileError("deprecated: final version of the specification has been published, use ml_kem instead");
176
177pub const ml_kem = struct {
170pub const nist = struct {
178171 pub const MLKem512 = Kyber(.{
179172 .name = "ML-KEM-512",
180173 .ml_kem = true,
......@@ -204,12 +197,12 @@ pub const ml_kem = struct {
204197};
205198
206199const modes = [_]type{
207 kyber_d00.Kyber512,
208 kyber_d00.Kyber768,
209 kyber_d00.Kyber1024,
210 ml_kem.MLKem512,
211 ml_kem.MLKem768,
212 ml_kem.MLKem1024,
200 d00.Kyber512,
201 d00.Kyber768,
202 d00.Kyber1024,
203 nist.MLKem512,
204 nist.MLKem768,
205 nist.MLKem1024,
213206};
214207const h_length: usize = 32;
215208const inner_seed_length: usize = 32;
......@@ -1725,9 +1718,9 @@ const sha2 = crypto.hash.sha2;
17251718
17261719test "NIST KAT test" {
17271720 inline for (.{
1728 .{ kyber_d00.Kyber512, "e9c2bd37133fcb40772f81559f14b1f58dccd1c816701be9ba6214d43baf4547" },
1729 .{ kyber_d00.Kyber1024, "89248f2f33f7f4f7051729111f3049c409a933ec904aedadf035f30fa5646cd5" },
1730 .{ kyber_d00.Kyber768, "a1e122cad3c24bc51622e4c242d8b8acbcd3f618fee4220400605ca8f9ea02c2" },
1721 .{ d00.Kyber512, "e9c2bd37133fcb40772f81559f14b1f58dccd1c816701be9ba6214d43baf4547" },
1722 .{ d00.Kyber1024, "89248f2f33f7f4f7051729111f3049c409a933ec904aedadf035f30fa5646cd5" },
1723 .{ d00.Kyber768, "a1e122cad3c24bc51622e4c242d8b8acbcd3f618fee4220400605ca8f9ea02c2" },
17311724 }) |modeHash| {
17321725 const mode = modeHash[0];
17331726 var seed: [48]u8 = undefined;