@eryx/crypto/hazmat/camellia Module

Camellia symmetric encryption.

Camellia is an ISO/IEC 18033-3 and NESSIE-approved block cipher with the same block and key sizes as AES (128/192/256-bit keys, 128-bit block). It is a recognised alternative to AES in TLS and IPsec.

Supports CBC, CTR, and GCM modes through a streaming Context API. CBC operates on raw block-aligned data; use @eryx/crypto/hazmat/pkcs7 if you need PKCS#7 padding. CCM is not defined for Camellia in this backend.

local camellia = require("@eryx/crypto/hazmat/camellia")
local pkcs7 = require("@eryx/crypto/hazmat/pkcs7")

local key = buffer.fromstring("0123456789abcdef")
local iv = buffer.fromstring("0000000000000000")
local plain = buffer.fromstring("Hello, Camellia!")

local padded = pkcs7.pad(plain, 16)
local enc = camellia.new(key, "cbc", "encrypt", iv)
local ct = enc:update(padded)
local tail = enc:final()
local ciphertext = buffer.create(buffer.len(ct) + buffer.len(tail))
buffer.copy(ciphertext, 0, ct)
buffer.copy(ciphertext, buffer.len(ct), tail)

local dec = camellia.new(key, "cbc", "decrypt", iv)
local ptChunk = dec:update(ciphertext)
local ptTail = dec:final()
local decrypted = buffer.create(buffer.len(ptChunk) + buffer.len(ptTail))
buffer.copy(decrypted, 0, ptChunk)
buffer.copy(decrypted, buffer.len(ptChunk), ptTail)

local pt = pkcs7.unpad(decrypted, 16)

Summary

Classes

Context:update(data: buffer)buffer
Context:updateAAD(aad: buffer)()
Context:setTag(tag: buffer)()
Context:getTag()buffer
Context:final()buffer
Context:close()()

Functions

camellia.new(key: buffer, mode: Mode, operation: Operation, ivOrNonce: buffer?)Context

API Reference

Classes

Context

Properties

Context:update

Context:update(data: buffer)buffer

Context:updateAAD

Context:updateAAD(aad: buffer)()

Context:setTag

Context:setTag(tag: buffer)()

Context:getTag

Context:getTag()buffer

Context:final

Context:final()buffer

Context:close

Context:close()()

Functions

camellia.new

Creates a streaming Camellia context.

For cbc, pass a 16-byte IV and ensure input is block-aligned. For ctr, pass a 16-byte counter block. For gcm, pass the nonce and use Context.updateAAD, Context.setTag, and Context.getTag as needed.

camellia.new(key: buffer, mode: Mode, operation: Operation, ivOrNonce: buffer?)Context

Parameters

key: buffer

Camellia key - 16, 24, or 32 bytes.

mode: Mode

Camellia mode.

operation: Operation

"encrypt" or "decrypt".

ivOrNonce: buffer?

IV / counter block / nonce depending on mode.

Returns

Streaming Camellia context.

Types

Mode

type Mode = "cbc" | "ctr" | "gcm"

Operation

type Operation = "encrypt" | "decrypt"