authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2020-11-02 22:40:13+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-11-05 17:20:25-05:00
log73aef46f7dd0b34b8b9f4248e592b58eeb219dd4
tree1bea8a605fa5716026070d43d883a48bd6a97c8b
parent4417206230913e3a2caab7df910a878a39bce0d0

std.crypto: namespace constructions a bit more

With the simple rule that whenever we have or will have 2 similar functions, they should be in their own namespace. Some of these new namespaces currently contain a single function. This is to prepare for reduced-round versions that are likely to be added later.

2 files changed, 31 insertions(+), 19 deletions(-)

lib/std/crypto.zig+24-12
...@@ -6,18 +6,26 @@...@@ -6,18 +6,26 @@
66
7/// Authenticated Encryption with Associated Data7/// Authenticated Encryption with Associated Data
8pub const aead = struct {8pub const aead = struct {
9 pub const Aegis128L = @import("crypto/aegis.zig").Aegis128L;9 pub const aegis = struct {
10 pub const Aegis256 = @import("crypto/aegis.zig").Aegis256;10 pub const Aegis128L = @import("crypto/aegis.zig").Aegis128L;
11 pub const Aegis256 = @import("crypto/aegis.zig").Aegis256;
12 };
1113
12 pub const Aes128Gcm = @import("crypto/aes_gcm.zig").Aes128Gcm;14 pub const aes_gcm = struct {
13 pub const Aes256Gcm = @import("crypto/aes_gcm.zig").Aes256Gcm;15 pub const Aes128Gcm = @import("crypto/aes_gcm.zig").Aes128Gcm;
16 pub const Aes256Gcm = @import("crypto/aes_gcm.zig").Aes256Gcm;
17 };
1418
15 pub const Gimli = @import("crypto/gimli.zig").Aead;19 pub const Gimli = @import("crypto/gimli.zig").Aead;
1620
17 pub const ChaCha20Poly1305 = @import("crypto/chacha20.zig").Chacha20Poly1305;21 pub const chacha_poly = struct {
18 pub const XChaCha20Poly1305 = @import("crypto/chacha20.zig").XChacha20Poly1305;22 pub const ChaCha20Poly1305 = @import("crypto/chacha20.zig").Chacha20Poly1305;
23 pub const XChaCha20Poly1305 = @import("crypto/chacha20.zig").XChacha20Poly1305;
24 };
1925
20 pub const XSalsa20Poly1305 = @import("crypto/salsa20.zig").XSalsa20Poly1305;26 pub const salsa_poly = struct {
27 pub const XSalsa20Poly1305 = @import("crypto/salsa20.zig").XSalsa20Poly1305;
28 };
21};29};
2230
23/// Authentication (MAC) functions.31/// Authentication (MAC) functions.
...@@ -102,12 +110,16 @@ pub const sign = struct {...@@ -102,12 +110,16 @@ pub const sign = struct {
102/// Stream ciphers. These do not provide any kind of authentication.110/// Stream ciphers. These do not provide any kind of authentication.
103/// Most applications should be using AEAD constructions instead of stream ciphers directly.111/// Most applications should be using AEAD constructions instead of stream ciphers directly.
104pub const stream = struct {112pub const stream = struct {
105 pub const ChaCha20IETF = @import("crypto/chacha20.zig").ChaCha20IETF;113 pub const chacha = struct {
106 pub const ChaCha20With64BitNonce = @import("crypto/chacha20.zig").ChaCha20With64BitNonce;114 pub const ChaCha20IETF = @import("crypto/chacha20.zig").ChaCha20IETF;
107 pub const XChaCha20IETF = @import("crypto/chacha20.zig").XChaCha20IETF;115 pub const ChaCha20With64BitNonce = @import("crypto/chacha20.zig").ChaCha20With64BitNonce;
116 pub const XChaCha20IETF = @import("crypto/chacha20.zig").XChaCha20IETF;
117 };
108118
109 pub const Salsa20 = @import("crypto/salsa20.zig").Salsa20;119 pub const salsa = struct {
110 pub const XSalsa20 = @import("crypto/salsa20.zig").XSalsa20;120 pub const Salsa20 = @import("crypto/salsa20.zig").Salsa20;
121 pub const XSalsa20 = @import("crypto/salsa20.zig").XSalsa20;
122 };
111};123};
112124
113pub const nacl = struct {125pub const nacl = struct {
lib/std/crypto/benchmark.zig+7-7
...@@ -200,14 +200,14 @@ pub fn benchmarkBatchSignatureVerification(comptime Signature: anytype, comptime...@@ -200,14 +200,14 @@ pub fn benchmarkBatchSignatureVerification(comptime Signature: anytype, comptime
200}200}
201201
202const aeads = [_]Crypto{202const aeads = [_]Crypto{
203 Crypto{ .ty = crypto.aead.ChaCha20Poly1305, .name = "chacha20Poly1305" },203 Crypto{ .ty = crypto.aead.chacha_poly.ChaCha20Poly1305, .name = "chacha20Poly1305" },
204 Crypto{ .ty = crypto.aead.XChaCha20Poly1305, .name = "xchacha20Poly1305" },204 Crypto{ .ty = crypto.aead.chacha_poly.XChaCha20Poly1305, .name = "xchacha20Poly1305" },
205 Crypto{ .ty = crypto.aead.XSalsa20Poly1305, .name = "xsalsa20Poly1305" },205 Crypto{ .ty = crypto.aead.salsa_poly.XSalsa20Poly1305, .name = "xsalsa20Poly1305" },
206 Crypto{ .ty = crypto.aead.Gimli, .name = "gimli-aead" },206 Crypto{ .ty = crypto.aead.Gimli, .name = "gimli-aead" },
207 Crypto{ .ty = crypto.aead.Aegis128L, .name = "aegis-128l" },207 Crypto{ .ty = crypto.aead.aegis.Aegis128L, .name = "aegis-128l" },
208 Crypto{ .ty = crypto.aead.Aegis256, .name = "aegis-256" },208 Crypto{ .ty = crypto.aead.aegis.Aegis256, .name = "aegis-256" },
209 Crypto{ .ty = crypto.aead.Aes128Gcm, .name = "aes128-gcm" },209 Crypto{ .ty = crypto.aead.aes_gcm.Aes128Gcm, .name = "aes128-gcm" },
210 Crypto{ .ty = crypto.aead.Aes256Gcm, .name = "aes256-gcm" },210 Crypto{ .ty = crypto.aead.aes_gcm.Aes256Gcm, .name = "aes256-gcm" },
211};211};
212212
213pub fn benchmarkAead(comptime Aead: anytype, comptime bytes: comptime_int) !u64 {213pub fn benchmarkAead(comptime Aead: anytype, comptime bytes: comptime_int) !u64 {