Skip to contents

The same container as morie.crypto.hybrid_encrypt (morie 1.4.0), so either arm opens the other's files. Encapsulates under the recipient's ML-KEM-768 public key, derives the wrapping key from HKDF(shared_secret || kem_ct || pk) (the KEM shared secret is what keeps it private), wraps a random 32-byte symmetric key with ChaCha20-Poly1305, then encrypts the payload under that symmetric key. Container format (big-endian lengths): "MORIEHYB" 0x02 || len(kem_ct)[4] || kem_ct || wrap_nonce[12] || wrapped_key[32] || wrap_tag[16] || payload_nonce[12] || aead_ct || payload_tag[16].

Usage

morie_crypto_hybrid_encrypt(plaintext, recipient_pk)

Arguments

plaintext

Raw vector or character string to encrypt.

recipient_pk

Raw vector: recipient's ML-KEM-768 public key (1184 bytes).

Value

Raw vector container.

Examples

kp <- morie_crypto_hybrid_keygen()
ct <- morie_crypto_hybrid_encrypt("hello", kp$pk)
rawToChar(morie_crypto_hybrid_decrypt(ct, kp$sk))
#> [1] "hello"