CtrMode
Mojo struct 🡭
CtrMode
@memory_only
struct CtrMode[C: BlockCipherDecryptable & BlockCipherEncryptable & Deinitable & Movable, SIZE: Int = C.BLOCK_SIZE, BIG_ENDIAN: Bool = True]Counter (CTR) block cipher mode.
NIST SP 800-38A, Section 6.5: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38a.pdf
SIZE is the width in bytes of the incrementing counter field; the
remaining BLOCK_SIZE - SIZE bytes are the fixed nonce, never touched by
the increment. SIZE == BLOCK_SIZE (the default) increments the whole block.
BIG_ENDIAN (default) places the counter in the last SIZE bytes and
increments big-endian (CTR-32BE / AES-GCM style). When False, the counter
occupies the first SIZE bytes and increments little-endian (CTR-32LE).
Aliases
BLOCK_SIZE = C.BLOCK_SIZE
Parameters
- C (
BlockCipherDecryptable & BlockCipherEncryptable & Deinitable & Movable) - SIZE (
Int) - BIG_ENDIAN (
Bool)
Implemented traits
AnyType, BlockCipherDecryptable, BlockCipherEncryptable, Deinitable, Movable
Methods
__init__
fn def __init__(out self, var cipher: C, var ctr: Array[UInt8, C.BLOCK_SIZE])Initialize from a fully-assembled initial counter block.
Args:
- cipher (
C) - ctr (
Array[UInt8, C.BLOCK_SIZE]) - self (
Self)
Returns:
Self
encrypt
fn def encrypt[o: MutOrigin](mut self, data: Span[UInt8, o])Parameters:
- o (
MutOrigin)
Args:
- self (
Self) - data (
Span[UInt8, o])
Raises:
decrypt
fn def decrypt[o: MutOrigin](mut self, data: Span[UInt8, o])Parameters:
- o (
MutOrigin)
Args:
- self (
Self) - data (
Span[UInt8, o])
Raises: