core/crypto/chacha20
chacha20
Types
2Context
Context :: struct {
_state: _chacha20.Context,
_impl: Implementation,
}SourceContext is a ChaCha20 or XChaCha20 instance.
Implementation
Implementation :: enum int {
Portable = 0,
Simd128 = 1,
Simd256 = 2,
}SourceImplementation is a ChaCha20 implementation. Most callers will not need to use this as the package will automatically select the most performant implementation available.
Constants
4DEFAULT_IMPLEMENTATION
DEFAULT_IMPLEMENTATION :: Implementation.Simd256SourceDEFAULT_IMPLEMENTATION is the implementation that will be used by default if possible.
IV_SIZE
IV_SIZE :: IV_SIZESourceIV_SIZE is the ChaCha20 IV size in bytes.
KEY_SIZE
KEY_SIZE :: KEY_SIZESourceKEY_SIZE is the (X)ChaCha20 key size in bytes.
XIV_SIZE
XIV_SIZE :: XIV_SIZESourceXIV_SIZE is the XChaCha20 IV size in bytes.
Procedures
5init
init :: proc(ctx: ^Context, key: []u8, iv: []u8, impl = DEFAULT_IMPLEMENTATION)Sourceinit inititializes a Context for ChaCha20 or XChaCha20 with the provided key and iv.
keystream_bytes
keystream_bytes :: proc(ctx: ^Context, dst: []u8)Sourcekeystream_bytes fills dst with the raw (X)ChaCha20 keystream output.
reset
reset :: proc(ctx: ^Context)Sourcereset sanitizes the Context. The Context must be re-initialized to be used again.
seek
seek :: proc(ctx: ^Context, block_nr: u64)Sourceseek seeks the (X)ChaCha20 stream counter to the specified block.
xor_bytes
xor_bytes :: proc(ctx: ^Context, dst: []u8, src: []u8)Sourcexor_bytes XORs each byte in src with bytes taken from the (X)ChaCha20 keystream, and writes the resulting output to dst. Dst and src MUST alias exactly or not at all.