@eryx/crypto/camellia Module

JSON

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 - see @eryx/crypto/aes for mode descriptions. CCM is not defined for Camellia in PSA Crypto.

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

local key   = buffer.fromstring("0123456789abcdef")  -- 16-byte / 128-bit
local iv    = buffer.fromstring("0000000000000000")
local plain = buffer.fromstring("Hello, Camellia!")

local ct = camellia.cbc_encrypt(key, iv, plain)
local pt = camellia.cbc_decrypt(key, iv, ct)

Summary

Functions

camellia.encryptCBC(key: buffer, iv: buffer, data: buffer)buffer
camellia.decryptCBC(key: buffer, iv: buffer, data: buffer)buffer
camellia.encryptCTR(key: buffer, iv: buffer, data: buffer)buffer
camellia.decryptCTR(key: buffer, iv: buffer, data: buffer)buffer
camellia.encryptGCM(key: buffer, nonce: buffer, data: buffer, aad: buffer?)(buffer, buffer)
camellia.decryptGCM(key: buffer, nonce: buffer, ct: buffer, tag: buffer, aad: buffer?)buffer

API Reference

Functions

camellia.encryptCBC

Encrypts data with Camellia-CBC (PKCS#7 padding).

camellia.encryptCBC(key: buffer, iv: buffer, data: buffer)buffer

Parameters

key: buffer

Key - 16, 24, or 32 bytes (128/192/256-bit).

iv: buffer

Initialisation vector - 16 bytes.

data: buffer

Plaintext to encrypt.

Returns

buffer

Ciphertext.

camellia.decryptCBC

Decrypts Camellia-CBC ciphertext (strips PKCS#7 padding).

camellia.decryptCBC(key: buffer, iv: buffer, data: buffer)buffer

Parameters

key: buffer

Key - 16, 24, or 32 bytes.

iv: buffer

Initialisation vector - 16 bytes.

data: buffer

Ciphertext to decrypt.

Returns

buffer

Plaintext.

camellia.encryptCTR

Encrypts data with Camellia-CTR (stream cipher; no padding).

camellia.encryptCTR(key: buffer, iv: buffer, data: buffer)buffer

Parameters

key: buffer

Key - 16, 24, or 32 bytes.

iv: buffer

Counter/nonce block - 16 bytes.

data: buffer

Plaintext to encrypt.

Returns

buffer

Ciphertext (same length as input).

camellia.decryptCTR

Decrypts Camellia-CTR ciphertext.

camellia.decryptCTR(key: buffer, iv: buffer, data: buffer)buffer

Parameters

key: buffer

Key - 16, 24, or 32 bytes.

iv: buffer

Counter/nonce block - 16 bytes.

data: buffer

Ciphertext to decrypt.

Returns

buffer

Plaintext (same length as input).

camellia.encryptGCM

Encrypts data with Camellia-GCM (authenticated encryption).

Returns ciphertext and authentication tag separately.

camellia.encryptGCM(key: buffer, nonce: buffer, data: buffer, aad: buffer?)(buffer, buffer)

Parameters

key: buffer

Key - 16, 24, or 32 bytes.

nonce: buffer

Nonce - 12 bytes recommended.

data: buffer

Plaintext to encrypt.

aad: buffer?

Additional authenticated data (optional).

Returns

buffer

Ciphertext.

buffer

16-byte authentication tag.

camellia.decryptGCM

Decrypts Camellia-GCM ciphertext and verifies the authentication tag.

Raises an error if the tag does not match.

camellia.decryptGCM(key: buffer, nonce: buffer, ct: buffer, tag: buffer, aad: buffer?)buffer

Parameters

key: buffer

Key - 16, 24, or 32 bytes.

nonce: buffer

Nonce - must match the value used during encryption.

ct: buffer

Ciphertext.

tag: buffer

16-byte authentication tag.

aad: buffer?

Additional authenticated data (must match encryption).

Returns

buffer

Plaintext.