Skip to content

Latest commit

 

History

History
143 lines (87 loc) · 3.13 KB

File metadata and controls

143 lines (87 loc) · 3.13 KB

Interface: RecipientContext

Context for decrypting multiple messages and exporting secrets on the recipient side.

RecipientContext instance is obtained from CipherSuite.SetupRecipient.

Contents

Example

let suite!: HPKE.CipherSuite
let privateKey!: HPKE.Key | HPKE.KeyPair

// ... receive encapsulatedSecret from sender
let encapsulatedSecret!: Uint8Array

const ctx: HPKE.RecipientContext = await suite.SetupRecipient(privateKey, encapsulatedSecret)

Methods

Export()

Export(exporterContext, length): Promise<Uint8Array>

Exports a secret using a variable-length pseudorandom function (PRF).

The exported secret is indistinguishable from a uniformly random bitstring of equal length.

Parameters

Parameter Type Description
exporterContext Uint8Array Context for domain separation
length number Desired length of exported secret in bytes

Returns

Promise<Uint8Array>

A Promise that resolves to the exported secret.

Example

let ctx!: HPKE.RecipientContext

// Export a 32-byte secret
const exporterContext: Uint8Array = new TextEncoder().encode('exporter context')
const exported: Uint8Array = await ctx.Export(exporterContext, 32)

// The sender can derive the same secret using the same exporterContext

See

Context.Export


Open()

Open(ciphertext, aad?): Promise<Uint8Array>

Decrypts ciphertext with additional authenticated data.

Applications must ensure that ciphertexts are presented to Open in the exact order they were produced by the sender.

Parameters

Parameter Type Description
ciphertext Uint8Array Ciphertext to decrypt
aad? Uint8Array Additional authenticated data

Returns

Promise<Uint8Array>

A Promise that resolves to the decrypted plaintext.

Example

let ctx!: HPKE.RecipientContext

// Decrypt multiple messages with the same context
let aad1!: Uint8Array | undefined
let ct1!: Uint8Array
const pt1: Uint8Array = await ctx.Open(ct1, aad1)

let aad2!: Uint8Array | undefined
let ct2!: Uint8Array
const pt2: Uint8Array = await ctx.Open(ct2, aad2)

See

Context.Open

Accessors

mode

Get Signature

get mode(): number

See
Returns

number

The mode (0x00 = Base, 0x01 = PSK) for this context.


seq

Get Signature

get seq(): number

Returns

number

The sequence number for this context's next Open, initially zero, increments automatically with each successful Open. The sequence number provides AEAD nonce uniqueness. The maximum supported sequence number in this implementation is 2^53-1.