aboutsummaryrefslogtreecommitdiff
path: root/lib/std/crypto.zig
diff options
context:
space:
mode:
authorFrank Denis <github@pureftpd.org>2020-08-19 16:21:05 +0200
committerFrank Denis <github@pureftpd.org>2020-08-20 23:02:05 +0200
commit6f9ea9eaef79863ebdc9bf44b2af67ec4caad031 (patch)
tree4a34acd626affbf4e98484a357e6464c92952b2a /lib/std/crypto.zig
parent1a4059ed88740c0289b7fea5735115fa9481a8e5 (diff)
downloadzig-6f9ea9eaef79863ebdc9bf44b2af67ec4caad031.tar.gz
zig-6f9ea9eaef79863ebdc9bf44b2af67ec4caad031.zip
Breaking: sort std/crypto functions into categories
Instead of having all primitives and constructions share the same namespace, they are now organized by category and function family. Types within the same category are expected to share the exact same API.
Diffstat (limited to 'lib/std/crypto.zig')
-rw-r--r--lib/std/crypto.zig129
1 files changed, 71 insertions, 58 deletions
diff --git a/lib/std/crypto.zig b/lib/std/crypto.zig
index edca2bc2ff..2a18bd88c7 100644
--- a/lib/std/crypto.zig
+++ b/lib/std/crypto.zig
@@ -3,60 +3,68 @@
// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
// The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software.
-pub const Md5 = @import("crypto/md5.zig").Md5;
-pub const Sha1 = @import("crypto/sha1.zig").Sha1;
-
-const sha2 = @import("crypto/sha2.zig");
-pub const Sha224 = sha2.Sha224;
-pub const Sha256 = sha2.Sha256;
-pub const Sha384 = sha2.Sha384;
-pub const Sha512 = sha2.Sha512;
-
-const sha3 = @import("crypto/sha3.zig");
-pub const Sha3_224 = sha3.Sha3_224;
-pub const Sha3_256 = sha3.Sha3_256;
-pub const Sha3_384 = sha3.Sha3_384;
-pub const Sha3_512 = sha3.Sha3_512;
-
-pub const gimli = @import("crypto/gimli.zig");
-
-const blake2 = @import("crypto/blake2.zig");
-pub const Blake2s224 = blake2.Blake2s224;
-pub const Blake2s256 = blake2.Blake2s256;
-pub const Blake2b384 = blake2.Blake2b384;
-pub const Blake2b512 = blake2.Blake2b512;
-
-pub const Blake3 = @import("crypto/blake3.zig").Blake3;
-
-const hmac = @import("crypto/hmac.zig");
-pub const HmacMd5 = hmac.HmacMd5;
-pub const HmacSha1 = hmac.HmacSha1;
-pub const HmacSha256 = hmac.HmacSha256;
-pub const HmacBlake2s256 = hmac.HmacBlake2s256;
-
-pub const chacha20 = @import("crypto/chacha20.zig");
-pub const chaCha20IETF = chacha20.chaCha20IETF;
-pub const chaCha20With64BitNonce = chacha20.chaCha20With64BitNonce;
-pub const xChaCha20IETF = chacha20.xChaCha20IETF;
-
-pub const Poly1305 = @import("crypto/poly1305.zig").Poly1305;
-
-const import_aes = @import("crypto/aes.zig");
-pub const AES128 = import_aes.AES128;
-pub const AES256 = import_aes.AES256;
-
-pub const Curve25519 = @import("crypto/25519/curve25519.zig").Curve25519;
-pub const Ed25519 = @import("crypto/25519/ed25519.zig").Ed25519;
-pub const Edwards25519 = @import("crypto/25519/edwards25519.zig").Edwards25519;
-pub const X25519 = @import("crypto/25519/x25519.zig").X25519;
-pub const Ristretto255 = @import("crypto/25519/ristretto255.zig").Ristretto255;
+/// Hash functions.
+pub const hash = struct {
+ pub const Md5 = @import("crypto/md5.zig").Md5;
+ pub const Sha1 = @import("crypto/sha1.zig").Sha1;
+ pub const sha2 = @import("crypto/sha2.zig");
+ pub const sha3 = @import("crypto/sha3.zig");
+ pub const blake2 = @import("crypto/blake2.zig");
+ pub const Blake3 = @import("crypto/blake3.zig").Blake3;
+ pub const Gimli = @import("crypto/gimli.zig").Hash;
+};
+
+/// Authentication (MAC) functions.
+pub const auth = struct {
+ pub const hmac = @import("crypto/hmac.zig");
+};
+
+/// Authenticated Encryption with Associated Data
pub const aead = struct {
- pub const Gimli = gimli.Aead;
+ const chacha20 = @import("crypto/chacha20.zig");
+
+ pub const Gimli = @import("crypto/gimli.zig").Aead;
pub const ChaCha20Poly1305 = chacha20.Chacha20Poly1305;
pub const XChaCha20Poly1305 = chacha20.XChacha20Poly1305;
};
+/// MAC functions requiring single-use secret keys.
+pub const onetimeauth = struct {
+ pub const Poly1305 = @import("crypto/poly1305.zig").Poly1305;
+};
+
+/// Core functions, that should rarely be used directly by applications.
+pub const core = struct {
+ pub const aes = @import("crypto/aes.zig");
+ pub const Gimli = @import("crypto/gimli.zig").State;
+};
+
+/// Elliptic-curve arithmetic.
+pub const ecc = struct {
+ pub const Curve25519 = @import("crypto/25519/curve25519.zig").Curve25519;
+ pub const Edwards25519 = @import("crypto/25519/edwards25519.zig").Edwards25519;
+ pub const Ristretto255 = @import("crypto/25519/ristretto255.zig").Ristretto255;
+};
+
+/// Diffie-Hellman key exchange functions.
+pub const dh = struct {
+ pub const X25519 = @import("crypto/25519/x25519.zig").X25519;
+};
+
+/// Digital signature functions.
+pub const sign = struct {
+ pub const Ed25519 = @import("crypto/25519/ed25519.zig").Ed25519;
+};
+
+/// Stream ciphers. These do not provide any kind of authentication.
+/// Most applications should be using AEAD constructions instead of stream ciphers directly.
+pub const stream = struct {
+ pub const ChaCha20IETF = @import("crypto/chacha20.zig").ChaCha20IETF;
+ pub const XChaCha20IETF = @import("crypto/chacha20.zig").XChaCha20IETF;
+ pub const ChaCha20With64BitNonce = @import("crypto/chacha20.zig").ChaCha20With64BitNonce;
+};
+
const std = @import("std.zig");
pub const randomBytes = std.os.getrandom;
@@ -83,16 +91,21 @@ test "crypto" {
test "issue #4532: no index out of bounds" {
const types = [_]type{
- Md5,
- Sha1,
- Sha224,
- Sha256,
- Sha384,
- Sha512,
- Blake2s224,
- Blake2s256,
- Blake2b384,
- Blake2b512,
+ hash.Md5,
+ hash.Sha1,
+ hash.sha2.Sha224,
+ hash.sha2.Sha256,
+ hash.sha2.Sha384,
+ hash.sha2.Sha512,
+ hash.sha3.Sha3_224,
+ hash.sha3.Sha3_256,
+ hash.sha3.Sha3_384,
+ hash.sha3.Sha3_512,
+ hash.blake2.Blake2s224,
+ hash.blake2.Blake2s256,
+ hash.blake2.Blake2b384,
+ hash.blake2.Blake2b512,
+ hash.Gimli,
};
inline for (types) |Hasher| {