6.1. Encryption and Decryption
6.1. Encryption and Decryption
In many cases, applications encrypt only a single message to a recipient's public key. This section provides templates for HPKE APIs that implement stateless "single-shot" encryption and decryption using APIs specified in Sections 5.1.1 and 5.2:
def Seal<MODE>(pkR, info, aad, pt, ...):
enc, ctx = Setup<MODE>S(pkR, info, ...)
ct = ctx.Seal(aad, pt)
return enc, ct
def Open<MODE>(enc, skR, info, aad, ct, ...):
ctx = Setup<MODE>R(enc, skR, info, ...)
return ctx.Open(aad, ct)
The MODE template parameter is one of Base, PSK, Auth, or AuthPSK. The optional parameters indicated by "..." depend on MODE and may be empty. For example, SetupBase() has no additional parameters. SealAuthPSK() and OpenAuthPSK() would be implemented as follows:
def SealAuthPSK(pkR, info, aad, pt, psk, psk_id, skS):
enc, ctx = SetupAuthPSKS(pkR, info, psk, psk_id, skS)
ct = ctx.Seal(aad, pt)
return enc, ct
def OpenAuthPSK(enc, skR, info, aad, ct, psk, psk_id, pkS):
ctx = SetupAuthPSKR(enc, skR, info, psk, psk_id, pkS)
return ctx.Open(aad, ct)