Skip to content
Standard libraryZig 0.17.0Official documentation
Sourcestd/crypto.zig

Source line 1

Cryptography.

std.crypto.aead

namespace

Source line 8

Authenticated Encryption with Associated Data

std.crypto.aead.aegis

namespace

Source line 9

std.crypto.aead.aegis.Aegis128L

alias

Source line 14

Alias of std.crypto.aegis.Aegis128L

std.crypto.aead.aegis.Aegis128L_256

alias

Source line 22

Alias of std.crypto.aegis.Aegis128L_256

std.crypto.aead.aegis.Aegis128X2

alias

Source line 13

Alias of std.crypto.aegis.Aegis128X2

std.crypto.aead.aegis.Aegis128X2_256

alias

Source line 21

Alias of std.crypto.aegis.Aegis128X2_256

std.crypto.aead.aegis.Aegis128X4

alias

Source line 12

Alias of std.crypto.aegis.Aegis128X4

std.crypto.aead.aegis.Aegis128X4_256

alias

Source line 20

Alias of std.crypto.aegis.Aegis128X4_256

std.crypto.aead.aegis.Aegis256

alias

Source line 18

Alias of std.crypto.aegis.Aegis256

std.crypto.aead.aegis.Aegis256_256

alias

Source line 26

Alias of std.crypto.aegis.Aegis256_256

std.crypto.aead.aegis.Aegis256X2

alias

Source line 17

Alias of std.crypto.aegis.Aegis256X2

std.crypto.aead.aegis.Aegis256X2_256

alias

Source line 25

Alias of std.crypto.aegis.Aegis256X2_256

std.crypto.aead.aegis.Aegis256X4

alias

Source line 16

Alias of std.crypto.aegis.Aegis256X4

std.crypto.aead.aegis.Aegis256X4_256

alias

Source line 24

Alias of std.crypto.aegis.Aegis256X4_256

std.crypto.aead.aegis.variants

alias

Source line 10

Alias of std.crypto.aegis

std.crypto.aead.aes_ccm

alias

Source line 49

Alias of std.crypto.aes_ccm

std.crypto.aead.aes_gcm

namespace

Source line 29

std.crypto.aead.aes_gcm_siv

namespace

Source line 34

std.crypto.aead.aes_gcm_siv.Aes128GcmSiv

alias

Source line 35

Alias of std.crypto.aes_gcm_siv.Aes128GcmSiv

std.crypto.aead.aes_gcm_siv.Aes256GcmSiv

alias

Source line 36

Alias of std.crypto.aes_gcm_siv.Aes256GcmSiv

std.crypto.aead.aes_gcm.Aes128Gcm

alias

Source line 30

Alias of std.crypto.aes_gcm.Aes128Gcm

std.crypto.aead.aes_gcm.Aes256Gcm

alias

Source line 31

Alias of std.crypto.aes_gcm.Aes256Gcm

std.crypto.aead.aes_ocb

namespace

Source line 44

std.crypto.aead.aes_ocb.Aes128Ocb

alias

Source line 45

Alias of std.crypto.aes_ocb.Aes128Ocb

std.crypto.aead.aes_ocb.Aes256Ocb

alias

Source line 46

Alias of std.crypto.aes_ocb.Aes256Ocb

std.crypto.aead.aes_siv

namespace

Source line 39

std.crypto.aead.aes_siv.Aes128Siv

alias

Source line 40

Alias of std.crypto.aes_siv.Aes128Siv

std.crypto.aead.aes_siv.Aes256Siv

alias

Source line 41

Alias of std.crypto.aes_siv.Aes256Siv

std.crypto.aead.ascon

namespace

Source line 51

std.crypto.aead.ascon.AsconAead128

alias

Source line 52

Alias of std.crypto.ascon.AsconAead128

std.crypto.aead.chacha_poly

namespace

Source line 55

std.crypto.aead.chacha_poly.ChaCha12Poly1305

alias

Source line 57

Alias of std.crypto.chacha20.ChaCha12Poly1305

std.crypto.aead.chacha_poly.ChaCha20Poly1305

alias

Source line 56

Alias of std.crypto.chacha20.ChaCha20Poly1305

std.crypto.aead.chacha_poly.ChaCha8Poly1305

alias

Source line 58

Alias of std.crypto.chacha20.ChaCha8Poly1305

std.crypto.aead.chacha_poly.XChaCha12Poly1305

alias

Source line 60

Alias of std.crypto.chacha20.XChaCha12Poly1305

std.crypto.aead.chacha_poly.XChaCha20Poly1305

alias

Source line 59

Alias of std.crypto.chacha20.XChaCha20Poly1305

std.crypto.aead.chacha_poly.XChaCha8Poly1305

alias

Source line 61

Alias of std.crypto.chacha20.XChaCha8Poly1305

std.crypto.aead.isap

alias

Source line 64

Alias of std.crypto.isap

std.crypto.aead.salsa_poly

namespace

Source line 66

std.crypto.aead.salsa_poly.XSalsa20Poly1305

alias

Source line 67

Alias of std.crypto.salsa20.XSalsa20Poly1305

std.crypto.auth

namespace

Source line 72

Authentication (MAC) functions.

std.crypto.auth.aegis

namespace

Source line 75

std.crypto.auth.aegis.Aegis128LMac

alias

Source line 79

Alias of std.crypto.aegis.Aegis128LMac

std.crypto.auth.aegis.Aegis128LMac_128

alias

Source line 87

Alias of std.crypto.aegis.Aegis128LMac_128

std.crypto.auth.aegis.Aegis128X2Mac

alias

Source line 78

Alias of std.crypto.aegis.Aegis128X2Mac

std.crypto.auth.aegis.Aegis128X2Mac_128

alias

Source line 86

Alias of std.crypto.aegis.Aegis128X2Mac_128

std.crypto.auth.aegis.Aegis128X4Mac

alias

Source line 77

Alias of std.crypto.aegis.Aegis128X4Mac

std.crypto.auth.aegis.Aegis128X4Mac_128

alias

Source line 85

Alias of std.crypto.aegis.Aegis128X4Mac_128

std.crypto.auth.aegis.Aegis256Mac

alias

Source line 83

Alias of std.crypto.aegis.Aegis256Mac

std.crypto.auth.aegis.Aegis256Mac_128

alias

Source line 91

Alias of std.crypto.aegis.Aegis256Mac_128

std.crypto.auth.aegis.Aegis256X2Mac

alias

Source line 82

Alias of std.crypto.aegis.Aegis256X2Mac

std.crypto.auth.aegis.Aegis256X2Mac_128

alias

Source line 90

Alias of std.crypto.aegis.Aegis256X2Mac_128

std.crypto.auth.aegis.Aegis256X4Mac

alias

Source line 81

Alias of std.crypto.aegis.Aegis256X4Mac

std.crypto.auth.aegis.Aegis256X4Mac_128

alias

Source line 89

Alias of std.crypto.aegis.Aegis256X4Mac_128

std.crypto.auth.aegis.variants

alias

Source line 76

Alias of std.crypto.aegis

std.crypto.auth.cbc_mac

alias

Source line 94

Alias of std.crypto.cbc_mac

std.crypto.auth.cmac

alias

Source line 93

Alias of std.crypto.cmac

std.crypto.auth.hmac

alias

Source line 73

Alias of std.crypto.hmac

std.crypto.auth.siphash

alias

Source line 74

Alias of std.crypto.siphash

std.crypto.Certificate

alias

Source line 244

Alias of std.crypto.Certificate

std.crypto.codecs

alias

Source line 239

Encoding and decoding

Alias of std.crypto.codecs

std.crypto.core

namespace

Source line 98

Core functions, that should rarely be used directly by applications.

std.crypto.core.aes

alias

Source line 99

Alias of std.crypto.aes

std.crypto.core.Ascon

alias

Source line 102

Alias of std.crypto.ascon.State

std.crypto.core.keccak

alias

Source line 100

Alias of std.crypto.keccak_p

std.crypto.core.modes

alias

Source line 109

Modes are generic compositions to construct encryption/decryption functions from block ciphers and permutations.

These modes are designed to be building blocks for higher-level constructions, and should generally not be used directly by applications, as they may not provide the expected properties and security guarantees.

Most applications may want to use AEADs instead.

Alias of std.crypto.modes

std.crypto.default_side_channels_mitigations

constant

Source line 265

std.crypto.dh

namespace

Source line 113

Diffie-Hellman key exchange functions.

std.crypto.dh.X25519

alias

Source line 114

Alias of std.crypto.25519.x25519.X25519

std.crypto.ecc

namespace

Source line 125

Elliptic-curve arithmetic.

std.crypto.ecc.Curve25519

alias

Source line 126

Alias of std.crypto.25519.curve25519.Curve25519

std.crypto.ecc.Edwards25519

alias

Source line 127

Alias of std.crypto.25519.edwards25519.Edwards25519

std.crypto.ecc.P256

alias

Source line 128

Alias of std.crypto.pcurves.p256.P256

std.crypto.ecc.P384

alias

Source line 129

Alias of std.crypto.pcurves.p384.P384

std.crypto.ecc.Ristretto255

alias

Source line 130

Alias of std.crypto.25519.ristretto255.Ristretto255

std.crypto.ecc.Secp256k1

alias

Source line 131

Alias of std.crypto.pcurves.secp256k1.Secp256k1

std.crypto.errors

alias

Source line 241

Alias of std.crypto.errors

std.crypto.ff

alias

Source line 236

Finite-field arithmetic.

Alias of std.crypto.ff

std.crypto.hash

namespace

Source line 135

Hash functions.

std.crypto.hash.ascon

namespace

Source line 136

std.crypto.hash.ascon.AsconCxof128

alias

Source line 140

Alias of std.crypto.ascon.AsconCxof128

std.crypto.hash.ascon.AsconHash256

alias

Source line 138

Alias of std.crypto.ascon.AsconHash256

std.crypto.hash.ascon.AsconXof128

alias

Source line 139

Alias of std.crypto.ascon.AsconXof128

std.crypto.hash.ascon.variants

alias

Source line 137

Alias of std.crypto.ascon

std.crypto.hash.blake2

alias

Source line 142

Alias of std.crypto.blake2

std.crypto.hash.Blake3

alias

Source line 143

Alias of std.crypto.blake3.Blake3

std.crypto.hash.composition

alias

Source line 148

Alias of std.crypto.hash_composition

std.crypto.hash.Md5

alias

Source line 144

Alias of std.crypto.md5.Md5

std.crypto.hash.Sha1

alias

Source line 145

Alias of std.crypto.Sha1

std.crypto.hash.sha2

alias

Source line 146

Alias of std.crypto.sha2

std.crypto.hash.sha3

alias

Source line 147

Alias of std.crypto.sha3

std.crypto.kdf

namespace

Source line 152

Key derivation functions.

std.crypto.kdf.hkdf

alias

Source line 153

Alias of std.crypto.hkdf

std.crypto.kem

namespace

Source line 118

Key Encapsulation Mechanisms.

std.crypto.kem.hybrid

alias

Source line 119

Alias of std.crypto.hybrid_kem

std.crypto.kem.kyber_d00

alias

Source line 120

Alias of std.crypto.ml_kem.d00

std.crypto.kem.ml_kem

alias

Source line 121

Alias of std.crypto.ml_kem.nist

std.crypto.nacl

namespace

Source line 227

std.crypto.nacl.Box

alias

Source line 230

Alias of std.crypto.salsa20.Box

std.crypto.nacl.salsa20

alias

Source line 228

Alias of std.crypto.salsa20

std.crypto.nacl.SealedBox

alias

Source line 232

Alias of std.crypto.salsa20.SealedBox

std.crypto.nacl.SecretBox

alias

Source line 231

Alias of std.crypto.salsa20.SecretBox

std.crypto.onetimeauth

namespace

Source line 157

MAC functions requiring single-use secret keys.

std.crypto.onetimeauth.Ghash

alias

Source line 158

Alias of std.crypto.ghash_polyval.Ghash

std.crypto.onetimeauth.Poly1305

alias

Source line 160

Alias of std.crypto.poly1305.Poly1305

std.crypto.onetimeauth.Polyval

alias

Source line 159

Alias of std.crypto.ghash_polyval.Polyval

std.crypto.pwhash

namespace

Source line 179

A password hashing function derives a uniform key from low-entropy input material such as passwords. It is intentionally slow or expensive.

With the standard definition of a key derivation function, if a key space is small, an exhaustive search may be practical. Password hashing functions make exhaustive searches way slower or way more expensive, even when implemented on GPUs and ASICs, by using different, optionally combined strategies:

  • Requiring a lot of computation cycles to complete
  • Requiring a lot of memory to complete
  • Requiring multiple CPU cores to complete
  • Requiring cache-local data to complete in reasonable time
  • Requiring large static tables
  • Avoiding precomputations and time/memory tradeoffs
  • Requiring multi-party computations
  • Combining the input material with random per-entry data (salts), application-specific contexts and keys

Password hashing functions must be used whenever sensitive data has to be directly derived from a password.

std.crypto.pwhash.argon2

alias

Source line 189

Alias of std.crypto.argon2

std.crypto.pwhash.bcrypt

alias

Source line 190

Alias of std.crypto.bcrypt

std.crypto.pwhash.Encoding

container

Source line 180

Fields

phc
crypt

std.crypto.pwhash.Error

error-set

Source line 185

Errors

AllocatorRequired
AuthenticationFailed AuthenticationError
Canceled Cancelable

Caller has requested the async operation to stop.

ContextTooLong ContextTooLongError
IdentityElement IdentityElementError
InvalidEncoding EncodingError
KeyMismatch KeyMismatchError
LockedMemoryLimitExceeded SpawnError

mlockall is enabled, and the memory needed to spawn the thread would exceed the limit.

NoSpaceLeft Error
NonCanonical NonCanonicalError
NotSquare NotSquareError
OutOfMemory SpawnError

Not enough userland memory to spawn the thread.

OutputTooLong OutputTooLongError
PasswordVerificationFailed PasswordVerificationError
SignatureVerificationFailed SignatureVerificationError
SystemResources SpawnError

The kernel cannot allocate sufficient memory to allocate a task structure for the child, or to copy those parts of the caller's context that need to be copied.

ThreadQuotaExceeded SpawnError

A system-imposed limit on the number of threads was encountered. There are a number of limits that may trigger this error:

  • the RLIMIT_NPROC soft resource limit (set via setrlimit(2)), which limits the number of processes and threads for a real user ID, was reached;
  • the kernel's system-wide limit on the number of processes and threads, /proc/sys/kernel/threads-max, was reached (see proc(5));
  • the maximum number of PIDs, /proc/sys/kernel/pid_max, was reached (see proc(5)); or
  • the PID limit (pids.max) imposed by the cgroup "process num‐ ber" (PIDs) controller was reached.
Unexpected SpawnError
UnexpectedSubgroup UnexpectedSubgroupError
WeakParameters WeakParametersError
WeakPublicKey WeakPublicKeyError

std.crypto.pwhash.HasherError

error-set

Source line 186

Errors

AuthenticationFailed AuthenticationError
Canceled Cancelable

Caller has requested the async operation to stop.

ContextTooLong ContextTooLongError
IdentityElement IdentityElementError
InvalidEncoding EncodingError
KeyMismatch KeyMismatchError
LockedMemoryLimitExceeded SpawnError

mlockall is enabled, and the memory needed to spawn the thread would exceed the limit.

NoSpaceLeft Error
NonCanonical NonCanonicalError
NotSquare NotSquareError
OutOfMemory SpawnError

Not enough userland memory to spawn the thread.

OutputTooLong OutputTooLongError
PasswordVerificationFailed PasswordVerificationError
SignatureVerificationFailed SignatureVerificationError
SystemResources SpawnError

The kernel cannot allocate sufficient memory to allocate a task structure for the child, or to copy those parts of the caller's context that need to be copied.

ThreadQuotaExceeded SpawnError

A system-imposed limit on the number of threads was encountered. There are a number of limits that may trigger this error:

  • the RLIMIT_NPROC soft resource limit (set via setrlimit(2)), which limits the number of processes and threads for a real user ID, was reached;
  • the kernel's system-wide limit on the number of processes and threads, /proc/sys/kernel/threads-max, was reached (see proc(5));
  • the maximum number of PIDs, /proc/sys/kernel/pid_max, was reached (see proc(5)); or
  • the PID limit (pids.max) imposed by the cgroup "process num‐ ber" (PIDs) controller was reached.
Unexpected SpawnError
UnexpectedSubgroup UnexpectedSubgroupError
WeakParameters WeakParametersError
WeakPublicKey WeakPublicKeyError

std.crypto.pwhash.KdfError

error-set

Source line 187

Errors

AuthenticationFailed AuthenticationError
Canceled Cancelable

Caller has requested the async operation to stop.

ContextTooLong ContextTooLongError
IdentityElement IdentityElementError
InvalidEncoding EncodingError
KeyMismatch KeyMismatchError
LockedMemoryLimitExceeded SpawnError

mlockall is enabled, and the memory needed to spawn the thread would exceed the limit.

NonCanonical NonCanonicalError
NotSquare NotSquareError
OutOfMemory SpawnError

Not enough userland memory to spawn the thread.

OutputTooLong OutputTooLongError
PasswordVerificationFailed PasswordVerificationError
SignatureVerificationFailed SignatureVerificationError
SystemResources SpawnError

The kernel cannot allocate sufficient memory to allocate a task structure for the child, or to copy those parts of the caller's context that need to be copied.

ThreadQuotaExceeded SpawnError

A system-imposed limit on the number of threads was encountered. There are a number of limits that may trigger this error:

  • the RLIMIT_NPROC soft resource limit (set via setrlimit(2)), which limits the number of processes and threads for a real user ID, was reached;
  • the kernel's system-wide limit on the number of processes and threads, /proc/sys/kernel/threads-max, was reached (see proc(5));
  • the maximum number of PIDs, /proc/sys/kernel/pid_max, was reached (see proc(5)); or
  • the PID limit (pids.max) imposed by the cgroup "process num‐ ber" (PIDs) controller was reached.
Unexpected SpawnError
UnexpectedSubgroup UnexpectedSubgroupError
WeakParameters WeakParametersError
WeakPublicKey WeakPublicKeyError

std.crypto.pwhash.pbkdf2

alias

Source line 192

Alias of std.crypto.pbkdf2.pbkdf2

std.crypto.pwhash.phc_format

alias

Source line 194

Alias of std.crypto.phc_encoding

std.crypto.pwhash.scrypt

alias

Source line 191

Alias of std.crypto.scrypt

std.crypto.secureZero

function

Source line 418

Sets a slice to zeroes. Prevents the store from being optimized out.

pub fn secureZero(comptime T: type, s: []volatile T) void

Parameters

T: type
s: []volatile T

Example usage

test secureZero {
    var a: [8]u8 = @splat(0xFE);
    var b: [8]u8 = @splat(0xFE);

    @memset(&a, 0);
    secureZero(u8, &b);

    try std.testing.expectEqualSlices(u8, &a, &b);
}

std.crypto.SideChannelsMitigations

container

Source line 247

Side-channels mitigations.

Fields

none

No additional side-channel mitigations are applied. This is the fastest mode.

basic

The basic mode protects against most practical attacks, provided that the application or implements proper defenses against brute-force attacks. It offers a good balance between performance and security.

medium

The medium mode offers increased resilience against side-channel attacks, making most attacks unpractical even on shared/low latency environements. This is the default mode.

full

The full mode offers the highest level of protection against side-channel attacks. Note that this doesn't cover all possible attacks (especially power analysis or thread-local attacks such as cachebleed), and that the performance impact is significant.

std.crypto.sign

namespace

Source line 198

Digital signature functions.

std.crypto.sign.ecdsa

alias

Source line 200

Alias of std.crypto.ecdsa

std.crypto.sign.Ed25519

alias

Source line 199

Alias of std.crypto.25519.ed25519.Ed25519

std.crypto.sign.mldsa

alias

Source line 201

Alias of std.crypto.ml_dsa

std.crypto.std

alias

Source line 3

Alias of std

std.crypto.stream

namespace

Source line 206

Stream ciphers. These do not provide any kind of authentication. Most applications should be using AEAD constructions instead of stream ciphers directly.

std.crypto.stream.chacha

namespace

Source line 207

std.crypto.stream.chacha.ChaCha12IETF

alias

Source line 209

Alias of std.crypto.chacha20.ChaCha12IETF

std.crypto.stream.chacha.ChaCha12With64BitNonce

alias

Source line 212

Alias of std.crypto.chacha20.ChaCha12With64BitNonce

std.crypto.stream.chacha.ChaCha20IETF

alias

Source line 208

Alias of std.crypto.chacha20.ChaCha20IETF

std.crypto.stream.chacha.ChaCha20With64BitNonce

alias

Source line 211

Alias of std.crypto.chacha20.ChaCha20With64BitNonce

std.crypto.stream.chacha.ChaCha8IETF

alias

Source line 210

Alias of std.crypto.chacha20.ChaCha8IETF

std.crypto.stream.chacha.ChaCha8With64BitNonce

alias

Source line 213

Alias of std.crypto.chacha20.ChaCha8With64BitNonce

std.crypto.stream.chacha.XChaCha12IETF

alias

Source line 215

Alias of std.crypto.chacha20.XChaCha12IETF

std.crypto.stream.chacha.XChaCha20IETF

alias

Source line 214

Alias of std.crypto.chacha20.XChaCha20IETF

std.crypto.stream.chacha.XChaCha8IETF

alias

Source line 216

Alias of std.crypto.chacha20.XChaCha8IETF

std.crypto.stream.salsa

namespace

Source line 219

std.crypto.stream.salsa.Salsa

alias

Source line 220

Alias of std.crypto.salsa20.Salsa

std.crypto.stream.salsa.Salsa20

alias

Source line 222

Alias of std.crypto.salsa20.Salsa20

std.crypto.stream.salsa.XSalsa

alias

Source line 221

Alias of std.crypto.salsa20.XSalsa

std.crypto.stream.salsa.XSalsa20

alias

Source line 223

Alias of std.crypto.salsa20.XSalsa20

std.crypto.timing_safe

alias

Source line 5

Alias of std.crypto.timing_safe

std.crypto.tls

alias

Source line 243

Alias of std.crypto.tls

Source code

std/crypto.zig

//! Cryptography.

const std = @import("std.zig");

pub const timing_safe = @import("crypto/timing_safe.zig");

/// Authenticated Encryption with Associated Data
pub const aead = struct {
    pub const aegis = struct {
        const variants = @import("crypto/aegis.zig");

        pub const Aegis128X4 = variants.Aegis128X4;
        pub const Aegis128X2 = variants.Aegis128X2;
        pub const Aegis128L = variants.Aegis128L;

        pub const Aegis256X4 = variants.Aegis256X4;
        pub const Aegis256X2 = variants.Aegis256X2;
        pub const Aegis256 = variants.Aegis256;

        pub const Aegis128X4_256 = variants.Aegis128X4_256;
        pub const Aegis128X2_256 = variants.Aegis128X2_256;
        pub const Aegis128L_256 = variants.Aegis128L_256;

        pub const Aegis256X4_256 = variants.Aegis256X4_256;
        pub const Aegis256X2_256 = variants.Aegis256X2_256;
        pub const Aegis256_256 = variants.Aegis256_256;
    };

    pub const aes_gcm = struct {
        pub const Aes128Gcm = @import("crypto/aes_gcm.zig").Aes128Gcm;
        pub const Aes256Gcm = @import("crypto/aes_gcm.zig").Aes256Gcm;
    };

    pub const aes_gcm_siv = struct {
        pub const Aes128GcmSiv = @import("crypto/aes_gcm_siv.zig").Aes128GcmSiv;
        pub const Aes256GcmSiv = @import("crypto/aes_gcm_siv.zig").Aes256GcmSiv;
    };

    pub const aes_siv = struct {
        pub const Aes128Siv = @import("crypto/aes_siv.zig").Aes128Siv;
        pub const Aes256Siv = @import("crypto/aes_siv.zig").Aes256Siv;
    };

    pub const aes_ocb = struct {
        pub const Aes128Ocb = @import("crypto/aes_ocb.zig").Aes128Ocb;
        pub const Aes256Ocb = @import("crypto/aes_ocb.zig").Aes256Ocb;
    };

    pub const aes_ccm = @import("crypto/aes_ccm.zig");

    pub const ascon = struct {
        pub const AsconAead128 = @import("crypto/ascon.zig").AsconAead128;
    };

    pub const chacha_poly = struct {
        pub const ChaCha20Poly1305 = @import("crypto/chacha20.zig").ChaCha20Poly1305;
        pub const ChaCha12Poly1305 = @import("crypto/chacha20.zig").ChaCha12Poly1305;
        pub const ChaCha8Poly1305 = @import("crypto/chacha20.zig").ChaCha8Poly1305;
        pub const XChaCha20Poly1305 = @import("crypto/chacha20.zig").XChaCha20Poly1305;
        pub const XChaCha12Poly1305 = @import("crypto/chacha20.zig").XChaCha12Poly1305;
        pub const XChaCha8Poly1305 = @import("crypto/chacha20.zig").XChaCha8Poly1305;
    };

    pub const isap = @import("crypto/isap.zig");

    pub const salsa_poly = struct {
        pub const XSalsa20Poly1305 = @import("crypto/salsa20.zig").XSalsa20Poly1305;
    };
};

/// Authentication (MAC) functions.
pub const auth = struct {
    pub const hmac = @import("crypto/hmac.zig");
    pub const siphash = @import("crypto/siphash.zig");
    pub const aegis = struct {
        const variants = @import("crypto/aegis.zig");
        pub const Aegis128X4Mac = variants.Aegis128X4Mac;
        pub const Aegis128X2Mac = variants.Aegis128X2Mac;
        pub const Aegis128LMac = variants.Aegis128LMac;

        pub const Aegis256X4Mac = variants.Aegis256X4Mac;
        pub const Aegis256X2Mac = variants.Aegis256X2Mac;
        pub const Aegis256Mac = variants.Aegis256Mac;

        pub const Aegis128X4Mac_128 = variants.Aegis128X4Mac_128;
        pub const Aegis128X2Mac_128 = variants.Aegis128X2Mac_128;
        pub const Aegis128LMac_128 = variants.Aegis128LMac_128;

        pub const Aegis256X4Mac_128 = variants.Aegis256X4Mac_128;
        pub const Aegis256X2Mac_128 = variants.Aegis256X2Mac_128;
        pub const Aegis256Mac_128 = variants.Aegis256Mac_128;
    };
    pub const cmac = @import("crypto/cmac.zig");
    pub const cbc_mac = @import("crypto/cbc_mac.zig");
};

/// Core functions, that should rarely be used directly by applications.
pub const core = struct {
    pub const aes = @import("crypto/aes.zig");
    pub const keccak = @import("crypto/keccak_p.zig");

    pub const Ascon = @import("crypto/ascon.zig").State;

    /// Modes are generic compositions to construct encryption/decryption functions from block ciphers and permutations.
    ///
    /// These modes are designed to be building blocks for higher-level constructions, and should generally not be used directly by applications, as they may not provide the expected properties and security guarantees.
    ///
    /// Most applications may want to use AEADs instead.
    pub const modes = @import("crypto/modes.zig");
};

/// Diffie-Hellman key exchange functions.
pub const dh = struct {
    pub const X25519 = @import("crypto/25519/x25519.zig").X25519;
};

/// Key Encapsulation Mechanisms.
pub const kem = struct {
    pub const hybrid = @import("crypto/hybrid_kem.zig");
    pub const kyber_d00 = @import("crypto/ml_kem.zig").d00;
    pub const ml_kem = @import("crypto/ml_kem.zig").nist;
};

/// 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 P256 = @import("crypto/pcurves/p256.zig").P256;
    pub const P384 = @import("crypto/pcurves/p384.zig").P384;
    pub const Ristretto255 = @import("crypto/25519/ristretto255.zig").Ristretto255;
    pub const Secp256k1 = @import("crypto/pcurves/secp256k1.zig").Secp256k1;
};

/// Hash functions.
pub const hash = struct {
    pub const ascon = struct {
        const variants = @import("crypto/ascon.zig");
        pub const AsconHash256 = variants.AsconHash256;
        pub const AsconXof128 = variants.AsconXof128;
        pub const AsconCxof128 = variants.AsconCxof128;
    };
    pub const blake2 = @import("crypto/blake2.zig");
    pub const Blake3 = @import("crypto/blake3.zig").Blake3;
    pub const Md5 = @import("crypto/md5.zig").Md5;
    pub const Sha1 = @import("crypto/Sha1.zig");
    pub const sha2 = @import("crypto/sha2.zig");
    pub const sha3 = @import("crypto/sha3.zig");
    pub const composition = @import("crypto/hash_composition.zig");
};

/// Key derivation functions.
pub const kdf = struct {
    pub const hkdf = @import("crypto/hkdf.zig");
};

/// MAC functions requiring single-use secret keys.
pub const onetimeauth = struct {
    pub const Ghash = @import("crypto/ghash_polyval.zig").Ghash;
    pub const Polyval = @import("crypto/ghash_polyval.zig").Polyval;
    pub const Poly1305 = @import("crypto/poly1305.zig").Poly1305;
};

/// A password hashing function derives a uniform key from low-entropy input material such as passwords.
/// It is intentionally slow or expensive.
///
/// With the standard definition of a key derivation function, if a key space is small, an exhaustive search may be practical.
/// Password hashing functions make exhaustive searches way slower or way more expensive, even when implemented on GPUs and ASICs, by using different, optionally combined strategies:
///
/// - Requiring a lot of computation cycles to complete
/// - Requiring a lot of memory to complete
/// - Requiring multiple CPU cores to complete
/// - Requiring cache-local data to complete in reasonable time
/// - Requiring large static tables
/// - Avoiding precomputations and time/memory tradeoffs
/// - Requiring multi-party computations
/// - Combining the input material with random per-entry data (salts), application-specific contexts and keys
///
/// Password hashing functions must be used whenever sensitive data has to be directly derived from a password.
pub const pwhash = struct {
    pub const Encoding = enum {
        phc,
        crypt,
    };

    pub const Error = HasherError || error{AllocatorRequired};
    pub const HasherError = KdfError || phc_format.Error;
    pub const KdfError = errors.Error || std.mem.Allocator.Error || std.Thread.SpawnError || std.Io.Cancelable;

    pub const argon2 = @import("crypto/argon2.zig");
    pub const bcrypt = @import("crypto/bcrypt.zig");
    pub const scrypt = @import("crypto/scrypt.zig");
    pub const pbkdf2 = @import("crypto/pbkdf2.zig").pbkdf2;

    pub const phc_format = @import("crypto/phc_encoding.zig");
};

/// Digital signature functions.
pub const sign = struct {
    pub const Ed25519 = @import("crypto/25519/ed25519.zig").Ed25519;
    pub const ecdsa = @import("crypto/ecdsa.zig");
    pub const mldsa = @import("crypto/ml_dsa.zig");
};

/// 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 chacha = struct {
        pub const ChaCha20IETF = @import("crypto/chacha20.zig").ChaCha20IETF;
        pub const ChaCha12IETF = @import("crypto/chacha20.zig").ChaCha12IETF;
        pub const ChaCha8IETF = @import("crypto/chacha20.zig").ChaCha8IETF;
        pub const ChaCha20With64BitNonce = @import("crypto/chacha20.zig").ChaCha20With64BitNonce;
        pub const ChaCha12With64BitNonce = @import("crypto/chacha20.zig").ChaCha12With64BitNonce;
        pub const ChaCha8With64BitNonce = @import("crypto/chacha20.zig").ChaCha8With64BitNonce;
        pub const XChaCha20IETF = @import("crypto/chacha20.zig").XChaCha20IETF;
        pub const XChaCha12IETF = @import("crypto/chacha20.zig").XChaCha12IETF;
        pub const XChaCha8IETF = @import("crypto/chacha20.zig").XChaCha8IETF;
    };

    pub const salsa = struct {
        pub const Salsa = @import("crypto/salsa20.zig").Salsa;
        pub const XSalsa = @import("crypto/salsa20.zig").XSalsa;
        pub const Salsa20 = @import("crypto/salsa20.zig").Salsa20;
        pub const XSalsa20 = @import("crypto/salsa20.zig").XSalsa20;
    };
};

pub const nacl = struct {
    const salsa20 = @import("crypto/salsa20.zig");

    pub const Box = salsa20.Box;
    pub const SecretBox = salsa20.SecretBox;
    pub const SealedBox = salsa20.SealedBox;
};

/// Finite-field arithmetic.
pub const ff = @import("crypto/ff.zig");

/// Encoding and decoding
pub const codecs = @import("crypto/codecs.zig");

pub const errors = @import("crypto/errors.zig");

pub const tls = @import("crypto/tls.zig");
pub const Certificate = @import("crypto/Certificate.zig");

/// Side-channels mitigations.
pub const SideChannelsMitigations = enum {
    /// No additional side-channel mitigations are applied.
    /// This is the fastest mode.
    none,
    /// The `basic` mode protects against most practical attacks, provided that the
    /// application or implements proper defenses against brute-force attacks.
    /// It offers a good balance between performance and security.
    basic,
    /// The `medium` mode offers increased resilience against side-channel attacks,
    /// making most attacks unpractical even on shared/low latency environements.
    /// This is the default mode.
    medium,
    /// The `full` mode offers the highest level of protection against side-channel attacks.
    /// Note that this doesn't cover all possible attacks (especially power analysis or
    /// thread-local attacks such as cachebleed), and that the performance impact is significant.
    full,
};

pub const default_side_channels_mitigations = .medium;

test {
    _ = aead.ascon.AsconAead128;

    _ = aead.aegis.Aegis128L;
    _ = aead.aegis.Aegis256;

    _ = aead.aes_gcm.Aes128Gcm;
    _ = aead.aes_gcm.Aes256Gcm;

    _ = aead.aes_gcm_siv.Aes128GcmSiv;
    _ = aead.aes_gcm_siv.Aes256GcmSiv;

    _ = aead.aes_siv.Aes128Siv;
    _ = aead.aes_siv.Aes256Siv;

    _ = aead.aes_ocb.Aes128Ocb;
    _ = aead.aes_ocb.Aes256Ocb;

    _ = aead.aes_ccm;

    _ = aead.chacha_poly.ChaCha20Poly1305;
    _ = aead.chacha_poly.ChaCha12Poly1305;
    _ = aead.chacha_poly.ChaCha8Poly1305;
    _ = aead.chacha_poly.XChaCha20Poly1305;
    _ = aead.chacha_poly.XChaCha12Poly1305;
    _ = aead.chacha_poly.XChaCha8Poly1305;

    _ = aead.isap;
    _ = aead.salsa_poly.XSalsa20Poly1305;

    _ = auth.hmac;
    _ = auth.cmac;
    _ = auth.cbc_mac;
    _ = auth.siphash;

    _ = core.aes;
    _ = core.Ascon;
    _ = core.modes;

    _ = dh.X25519;

    _ = kem.kyber_d00;
    _ = kem.hybrid;
    _ = kem.kyber_d00;
    _ = kem.ml_kem;

    _ = ecc.Curve25519;
    _ = ecc.Edwards25519;
    _ = ecc.P256;
    _ = ecc.P384;
    _ = ecc.Ristretto255;
    _ = ecc.Secp256k1;

    _ = hash.ascon;
    _ = hash.blake2;
    _ = hash.Blake3;
    _ = hash.Md5;
    _ = hash.Sha1;
    _ = hash.sha2;
    _ = hash.sha3;
    _ = hash.composition;

    _ = kdf.hkdf;

    _ = onetimeauth.Ghash;
    _ = onetimeauth.Poly1305;

    _ = pwhash.Encoding;

    _ = pwhash.Error;
    _ = pwhash.HasherError;
    _ = pwhash.KdfError;

    _ = pwhash.argon2;
    _ = pwhash.bcrypt;
    _ = pwhash.scrypt;
    _ = pwhash.pbkdf2;

    _ = pwhash.phc_format;

    _ = sign.Ed25519;
    _ = sign.ecdsa;
    _ = sign.mldsa;

    _ = stream.chacha.ChaCha20IETF;
    _ = stream.chacha.ChaCha12IETF;
    _ = stream.chacha.ChaCha8IETF;
    _ = stream.chacha.ChaCha20With64BitNonce;
    _ = stream.chacha.ChaCha12With64BitNonce;
    _ = stream.chacha.ChaCha8With64BitNonce;
    _ = stream.chacha.XChaCha20IETF;
    _ = stream.chacha.XChaCha12IETF;
    _ = stream.chacha.XChaCha8IETF;

    _ = stream.salsa.Salsa20;
    _ = stream.salsa.XSalsa20;

    _ = nacl.Box;
    _ = nacl.SecretBox;
    _ = nacl.SealedBox;

    _ = secureZero;
    _ = timing_safe;
    _ = ff;
    _ = errors;
    _ = tls;
    _ = tls.Client;
    _ = Certificate;
    _ = codecs;
}

test "issue #4532: no index out of bounds" {
    const types = [_]type{
        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.Blake2s128,
        hash.blake2.Blake2s224,
        hash.blake2.Blake2s256,
        hash.blake2.Blake2b128,
        hash.blake2.Blake2b256,
        hash.blake2.Blake2b384,
        hash.blake2.Blake2b512,
    };

    inline for (types) |Hasher| {
        var block: [Hasher.block_length]u8 = @splat('#');
        var out1: [Hasher.digest_length]u8 = undefined;
        var out2: [Hasher.digest_length]u8 = undefined;
        const h0 = Hasher.init(.{});
        var h = h0;
        h.update(block[0..]);
        h.final(&out1);
        h = h0;
        h.update(block[0..1]);
        h.update(block[1..]);
        h.final(&out2);

        try std.testing.expectEqual(out1, out2);
    }
}

/// Sets a slice to zeroes.
/// Prevents the store from being optimized out.
pub fn secureZero(comptime T: type, s: []volatile T) void {
    @memset(s, std.mem.zeroes(T));
}

test secureZero {
    var a: [8]u8 = @splat(0xFE);
    var b: [8]u8 = @splat(0xFE);

    @memset(&a, 0);
    secureZero(u8, &b);

    try std.testing.expectEqualSlices(u8, &a, &b);
}