Authenticated Encryption with Associated Data (AEAD) implementation interface.
This implementation interface defines the contract for additional AEAD implementations to be usable with CipherSuite. While this module provides built-in AEAD implementations based on Web Cryptography, this interface is exported to allow custom AEAD implementations that may not rely on Web Cryptography (e.g., using native bindings, alternative crypto libraries, or specialized hardware).
Custom AEAD implementations must conform to this interface to be compatible with CipherSuite and its APIs.
import * as HPKE from 'hpke'
// Using a built-in AEAD
const suite = new HPKE.CipherSuite(
HPKE.KEM_DHKEM_P256_HKDF_SHA256,
HPKE.KDF_HKDF_SHA256,
HPKE.AEAD_AES_128_GCM,
)
// Creating and using a custom AEAD implementation
const customAEAD: HPKE.AEADFactory = (): HPKE.AEAD => ({
id: 0x9999,
type: 'AEAD',
name: 'Custom-AEAD',
Nk: 16,
Nn: 12,
Nt: 16,
async Seal(key, nonce, aad, pt) {
// perform AEAD
let ciphertext!: Uint8Array
return ciphertext
},
async Open(key, nonce, aad, ct) {
// perform AEAD
let plaintext!: Uint8Array
return plaintext
},
})
const customSuite = new HPKE.CipherSuite(
HPKE.KEM_DHKEM_P256_HKDF_SHA256,
HPKE.KDF_HKDF_SHA256,
customAEAD,
)HPKE AEAD Encryption Algorithm
Open(
key,nonce,aad,ct):Promise<Uint8Array>
Decrypts and verifies ciphertext with associated data.
| Parameter | Type | Description |
|---|---|---|
key |
Uint8Array |
The decryption key of Nk bytes |
nonce |
Uint8Array |
The nonce of Nn bytes |
aad |
Uint8Array |
Additional authenticated data |
ct |
Uint8Array |
Ciphertext with authentication tag appended |
Promise<Uint8Array>
A promise resolving to the decrypted plaintext
Seal(
key,nonce,aad,pt):Promise<Uint8Array>
Encrypts and authenticates plaintext with associated data.
| Parameter | Type | Description |
|---|---|---|
key |
Uint8Array |
The encryption key of Nk bytes |
nonce |
Uint8Array |
The nonce of Nn bytes |
aad |
Uint8Array |
Additional authenticated data |
pt |
Uint8Array |
Plaintext to encrypt |
Promise<Uint8Array>
A promise resolving to the ciphertext with authentication tag appended
readonlyid:number
AEAD algorithm identifier
readonlyname:string
Human-readable name of the AEAD algorithm
readonlyNk:number
Length in bytes of a key for this AEAD
readonlyNn:number
Length in bytes of a nonce for this AEAD
readonlyNt:number
Length in bytes of the authentication tag for this AEAD
readonlytype:"AEAD"
Type discriminator, always 'AEAD'