hpke

package
v0.0.0-...-5f74ff4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2025 License: Apache-2.0, BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package hpke implements Hybrid Public Key Encryption (HPKE).

See RFC 9180.

Index

Constants

View Source
const (
	P256WithHKDFSHA256   uint16 = 0x0010
	X25519WithHKDFSHA256 uint16 = 0x0020
)

KEM scheme IDs.

View Source
const (
	AES128GCM        uint16 = 0x0001
	AES256GCM        uint16 = 0x0002
	ChaCha20Poly1305 uint16 = 0x0003
)

HPKE AEAD IDs.

View Source
const (
	HKDFSHA256 uint16 = 0x0001
	HKDFSHA384 uint16 = 0x0002
	HKDFSHA512 uint16 = 0x0003
)

HPKE KDF IDs.

Variables

This section is empty.

Functions

func GenerateKeyPairX25519

func GenerateKeyPairX25519() (publicKey, secretKeyOut []byte, err error)

GenerateKeyPairX25519 generates a random X25519 key pair.

func GetHKDFHash

func GetHKDFHash(kdf uint16) (crypto.Hash, error)

GetHKDFHash returns the crypto.Hash that corresponds to kdf. If kdf is not one the supported KDF IDs, returns an error.

Types

type Context

type Context struct {
	// contains filtered or unexported fields
}

Context holds the HPKE state for a sender or a receiver.

func SetupBaseReceiverX25519

func SetupBaseReceiverX25519(kdfID, aeadID uint16, enc, secretKeyR, info []byte) (context *Context, err error)

SetupBaseReceiverX25519 corresponds to the spec's SetupBaseR(), but only supports X25519.

func SetupBaseSenderX25519

func SetupBaseSenderX25519(kdfID, aeadID uint16, publicKeyR, info []byte, ephemKeygen GenerateKeyPairFunc) (context *Context, enc []byte, err error)

SetupBaseSenderX25519 corresponds to the spec's SetupBaseS(), but only supports X25519.

func SetupPSKReceiverX25519

func SetupPSKReceiverX25519(kdfID, aeadID uint16, enc, secretKeyR, info, psk, pskID []byte) (context *Context, err error)

SetupPSKReceiverX25519 corresponds to the spec's SetupPSKR(), but only supports X25519.

func SetupPSKSenderX25519

func SetupPSKSenderX25519(kdfID, aeadID uint16, publicKeyR, info, psk, pskID []byte, ephemKeygen GenerateKeyPairFunc) (context *Context, enc []byte, err error)

SetupPSKSenderX25519 corresponds to the spec's SetupPSKS(), but only supports X25519.

func (*Context) AEAD

func (c *Context) AEAD() uint16

func (*Context) Export

func (c *Context) Export(exporterContext []byte, length int) []byte

func (*Context) KDF

func (c *Context) KDF() uint16

func (*Context) KEM

func (c *Context) KEM() uint16

func (*Context) Open

func (c *Context) Open(ciphertext, additionalData []byte) ([]byte, error)

func (*Context) Overhead

func (c *Context) Overhead() int

func (*Context) Seal

func (c *Context) Seal(plaintext, additionalData []byte) []byte

type GenerateKeyPairFunc

type GenerateKeyPairFunc func() (public []byte, secret []byte, e error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL