core/crypto/aes
aes
Types
4Context_CTR
Context_CTR :: struct {
_impl: Context_Impl,
_buffer: [BLOCK_SIZE]u8,
_off: int,
_ctr_hi: u64,
_ctr_lo: u64,
_is_initialized: bool,
}SourceContext_CTR is a keyed AES-CTR instance.
Context_ECB
Context_ECB :: struct {
_impl: Context_Impl,
_is_initialized: bool,
}SourceContext_ECB is a keyed AES-ECB instance.
WARNING: Using ECB mode is strongly discouraged unless it is being used to implement higher level constructs.
Context_GCM
Context_GCM :: struct {
_impl: Context_Impl,
_is_initialized: bool,
}SourceContext_GCM is a keyed AES-GCM instance.
Implementation
Implementation :: enum int {
Portable = 0,
Hardware = 1,
}SourceImplementation is an AES implementation. Most callers will not need to use this as the package will automatically select the most performant implementation available (See is_hardware_accelerated()).
Constants
9BLOCK_SIZE
BLOCK_SIZE :: BLOCK_SIZESourceBLOCK_SIZE is the AES block size in bytes.
CTR_IV_SIZE
CTR_IV_SIZE :: 16SourceCTR_IV_SIZE is the size of the CTR mode IV in bytes.
DEFAULT_IMPLEMENTATION
DEFAULT_IMPLEMENTATION :: Implementation.HardwareSourceDEFAULT_IMPLEMENTATION is the implementation that will be used by default if possible.
GCM_IV_SIZE
GCM_IV_SIZE :: 12SourceGCM_IV_SIZE is the default size of the GCM IV in bytes.
GCM_IV_SIZE_MAX
GCM_IV_SIZE_MAX :: 0x2000000000000000SourceGCM_IV_SIZE_MAX is the maximum size of the GCM IV in bytes.
GCM_TAG_SIZE
GCM_TAG_SIZE :: GHASH_TAG_SIZESourceGCM_TAG_SIZE is the size of a GCM tag in bytes.
KEY_SIZE_128
KEY_SIZE_128 :: KEY_SIZE_128SourceKEY_SIZE_128 is the AES-128 key size in bytes.
KEY_SIZE_192
KEY_SIZE_192 :: KEY_SIZE_192SourceKEY_SIZE_192 is the AES-192 key size in bytes.
KEY_SIZE_256
KEY_SIZE_256 :: KEY_SIZE_256SourceKEY_SIZE_256 is the AES-256 key size in bytes.
Procedures
14decrypt_ecb
decrypt_ecb :: proc(ctx: ^Context_ECB, dst: []u8, src: []u8)Sourcedecrypt_ecb decrypts the BLOCK_SIZE buffer src, and writes the result to dst.
encrypt_ecb
encrypt_ecb :: proc(ctx: ^Context_ECB, dst: []u8, src: []u8)Sourceencrypt_ecb encrypts the BLOCK_SIZE buffer src, and writes the result to dst.
init_ctr
init_ctr :: proc(ctx: ^Context_CTR, key: []u8, iv: []u8, impl = DEFAULT_IMPLEMENTATION)Sourceinit_ctr initializes a Context_CTR with the provided key and IV.
init_ecb
init_ecb :: proc(ctx: ^Context_ECB, key: []u8, impl = DEFAULT_IMPLEMENTATION)Sourceinit_ecb initializes a Context_ECB with the provided key.
init_gcm
init_gcm :: proc(ctx: ^Context_GCM, key: []u8, impl = DEFAULT_IMPLEMENTATION)Sourceinit_gcm initializes a Context_GCM with the provided key.
is_hardware_accelerated
is_hardware_accelerated :: proc() -> (bool)Sourceis_hardware_accelerated returns true if and only if (⟺) hardware accelerated AES is supported.
keystream_bytes_ctr
keystream_bytes_ctr :: proc(ctx: ^Context_CTR, dst: []u8)Sourcekeystream_bytes_ctr fills dst with the raw AES-CTR keystream output.
open_gcm
open_gcm :: proc(
ctx: ^Context_GCM,
dst: []u8,
iv: []u8,
aad: []u8,
ciphertext: []u8,
tag: []u8,
) -> (bool)Sourceopen_gcm authenticates the aad and ciphertext, and decrypts the ciphertext, with the provided Context_GCM, iv, and tag, and stores the output in dst, returning true if and only if (⟺) the authentication was successful. If authentication fails, the destination buffer will be zeroed.
dst and plaintext MUST alias exactly or not at all.
reset_ctr
reset_ctr :: proc(ctx: ^Context_CTR)Sourcereset_ctr sanitizes the Context_CTR. The Context_CTR must be re-initialized to be used again.
reset_ecb
reset_ecb :: proc(ctx: ^Context_ECB)Sourcereset_ecb sanitizes the Context_ECB. The Context_ECB must be re-initialized to be used again.
reset_gcm
reset_gcm :: proc(ctx: ^Context_GCM)Sourcereset_gcm sanitizes the Context_GCM. The Context_GCM must be re-initialized to be used again.
seal_gcm
seal_gcm :: proc(
ctx: ^Context_GCM,
dst: []u8,
tag: []u8,
iv: []u8,
aad: []u8,
plaintext: []u8,
)Sourceseal_gcm encrypts the plaintext and authenticates the aad and ciphertext, with the provided Context_GCM and iv, stores the output in dst and tag.
dst and plaintext MUST alias exactly or not at all.
xor_bytes_ctr
xor_bytes_ctr :: proc(ctx: ^Context_CTR, dst: []u8, src: []u8)Sourcexor_bytes_ctr XORs each byte in src with bytes taken from the AES-CTR keystream, and writes the resulting output to dst. dst and src MUST alias exactly or not at all.
zero_explicit
zero_explicit :: proc(data: rawptr, len: int) -> (rawptr)Source