Skip to contents

Produces a ciphertext and the 32-byte shared secret it carries. Only the public key is needed, which is the point: the sender never holds anything the recipient has to trust them with.

Usage

kem_encapsulate(key, m = NULL)

Arguments

key

A key or public key from kem_keygen() / kem_public_key().

m

Optional raw vector of 32 bytes of encapsulation randomness. Supplying it makes the operation reproducible, which is what the standard's test vectors need; the default draws from the operating system's CSPRNG. Reusing it across encapsulations to the same key reuses the shared secret, so supply it only deliberately.

Value

A list of class bricklayer_kem_capsule: ciphertext and shared (both hex), and level.

Examples

key <- kem_keygen(512)
a <- kem_encapsulate(key)
nchar(a$ciphertext) / 2 == kem_sizes(512)[["ciphertext"]]
#> [1] TRUE

# two encapsulations to one key give different secrets
b <- kem_encapsulate(key)
identical(a$shared, b$shared)
#> [1] FALSE

# both decapsulate correctly
identical(kem_decapsulate(key, a$ciphertext), a$shared)
#> [1] TRUE
identical(kem_decapsulate(key, b$ciphertext), b$shared)
#> [1] TRUE