encryption

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package encryption defines generic interfaces for encryption schemes, including key generation, encryption/decryption, and homomorphic variants.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidKey = errs.New("invalid key")
)

Functions

This section is empty.

Types

type AEADBasedHybridScheme

type AEADBasedHybridScheme[
	SK PrivateKey[SK],
	PK PublicKey[PK],
	M ~[]byte,
	C interface {
		~[]byte
		base.Equatable[C]
	},
	U Capsule,
	KG KeyGenerator[SK, PK],
	KM KEM[PK, U],
	DM DEM[U],
	ENC HybridEncrypter[PK, M, C, U],
	DEC HybridDecrypter[M, C],
] interface {
	HybridScheme[SK, PK, M, C, U, KG, KM, DM, ENC, DEC]
	AEAD(*SymmetricKey) (cipher.AEAD, error)
}

type Capsule

type Capsule any

type Ciphertext

type Ciphertext[C any] base.Equatable[C]

type DEM

type DEM[C Capsule] interface {
	Decapsulate(capsule C) (*SymmetricKey, error)
	IsAuthenticated() bool
}

type DEMOption

type DEMOption[
	DM DEM[C], C Capsule,
] = func(DM) error

type Decrypter

type Decrypter[M Plaintext, C Ciphertext[C]] interface {
	Decrypt(ciphertext C) (plaintext M, err error)
}

type DecrypterOption

type DecrypterOption[
	DEC Decrypter[M, C], M Plaintext, C Ciphertext[C],
] = func(DEC) error

type Encrypter

type Encrypter[PK PublicKey[PK], M Plaintext, C Ciphertext[C], X any] interface {
	Encrypt(plaintext M, receiver PK, prng io.Reader) (ciphertext C, nonceOrCapsuleEtc X, err error)
}

type EncrypterOption

type EncrypterOption[
	ENC Encrypter[PK, M, C, X], PK PublicKey[PK], M Plaintext, C Ciphertext[C], X any,
] = func(ENC) error

type ExtendedKeyGenerator

type ExtendedKeyGenerator[SK PrivateKey[SK], PK PublicKey[PK]] interface {
	KeyGenerator[SK, PK]
	GenerateWithSeed(ikm []byte) (SK, PK, error)
}

type GroupHomomorphicScheme

type GroupHomomorphicScheme[
	SK PrivateKey[SK], PK PublicKey[PK],
	M HomomorphicPlaintext[M, MV], MV algebra.GroupElement[MV],
	C ShiftTypeCiphertext[C, CV, M, PK, N, S], CV algebra.GroupElement[CV],
	N interface {
		Nonce
		algebra.HomomorphicLike[N, NV]
	}, NV algebra.GroupElement[NV],
	KG KeyGenerator[SK, PK], ENC LinearlyRandomisedEncrypter[PK, M, C, N], DEC Decrypter[M, C], S algebra.NatLike[S],
] HomomorphicScheme[SK, PK, M, MV, C, CV, N, NV, KG, ENC, DEC, S]

type HomomorphicCiphertext

type HomomorphicCiphertext[C Ciphertext[C], CV algebra.MonoidElement[CV], S algebra.NatLike[S]] interface {
	Ciphertext[C]
	algebra.HomomorphicLike[C, CV]
	algebra.Actable[C, S]
}

type HomomorphicPlaintext

type HomomorphicPlaintext[M Plaintext, MV algebra.SemiGroupElement[MV]] interface {
	Plaintext
	algebra.HomomorphicLike[M, MV]
}

type HomomorphicScheme

type HomomorphicScheme[
	SK PrivateKey[SK], PK PublicKey[PK],
	M HomomorphicPlaintext[M, MV], MV algebra.SemiGroupElement[MV],
	C HomomorphicCiphertext[C, CV, S], CV algebra.MonoidElement[CV],
	N interface {
		Nonce
		algebra.HomomorphicLike[N, NV]
	}, NV algebra.SemiGroupElement[NV],
	KG KeyGenerator[SK, PK], ENC Encrypter[PK, M, C, N], DEC Decrypter[M, C], S algebra.NatLike[S],
] Scheme[SK, PK, M, C, N, KG, ENC, DEC]

type HybridDecrypter

type HybridDecrypter[
	M Plaintext,
	C Ciphertext[C],
] interface {
	Decrypter[M, C]
	Open(ciphertext C, aad []byte) (M, error)
}

type HybridEncrypter

type HybridEncrypter[
	PK PublicKey[PK],
	M Plaintext,
	C Ciphertext[C],
	U Capsule,
] interface {
	Encrypter[PK, M, C, U]
	Seal(plaintext M, receiver PK, aad []byte, prng io.Reader) (C, U, error)
}

type HybridScheme

type HybridScheme[
	SK PrivateKey[SK],
	PK PublicKey[PK],
	M Plaintext,
	C Ciphertext[C],
	U Capsule,
	KG KeyGenerator[SK, PK],
	KM KEM[PK, U],
	DM DEM[U],
	ENC HybridEncrypter[PK, M, C, U],
	DEC HybridDecrypter[M, C],
] interface {
	Scheme[SK, PK, M, C, U, KG, ENC, DEC]
	KEM(...KEMOption[KM, PK, U]) (KM, error)
	DEM(SK, ...DEMOption[DM, U]) (DM, error)
}

type KEM

type KEM[PK PublicKey[PK], C Capsule] interface {
	Encapsulate(receiver PK, prng io.Reader) (*SymmetricKey, C, error)
	IsAuthenticated() bool
}

type KEMOption

type KEMOption[
	KM KEM[PK, C], PK PublicKey[PK], C Capsule,
] = func(KM) error

type KeyGenerator

type KeyGenerator[SK PrivateKey[SK], PK PublicKey[PK]] interface {
	Generate(prng io.Reader) (SK, PK, error)
}

type KeyGeneratorOption

type KeyGeneratorOption[
	KG KeyGenerator[SK, PK], SK PrivateKey[SK], PK PublicKey[PK],
] = func(KG) error

type LinearlyRandomisedEncrypter

type LinearlyRandomisedEncrypter[PK PublicKey[PK], M Plaintext, C ReRandomisableCiphertext[C, N, PK], N interface {
	Nonce
	algebra.Operand[N]
}] interface {
	Encrypter[PK, M, C, N]
	EncryptWithNonce(plaintext M, receiver PK, nonce N) (ciphertext C, err error)
}

type LinearlyRandomisedSelfEncrypter

type LinearlyRandomisedSelfEncrypter[SK PrivateKey[SK], PK PublicKey[PK], M Plaintext, C ReRandomisableCiphertext[C, N, PK], N interface {
	Nonce
	algebra.Operand[N]
}] interface {
	SelfEncrypter[SK, M, C, N]
	SelfEncryptWithNonce(plaintext M, nonce N) (ciphertext C, err error)
}

type Name

type Name string

type Nonce

type Nonce any

type Plaintext

type Plaintext any

type PrivateKey

type PrivateKey[SK any] base.Equatable[SK]

type PublicKey

type PublicKey[PK any] interface {
	base.Clonable[PK]
	base.Hashable[PK]
}

type ReRandomisableCiphertext

type ReRandomisableCiphertext[C Ciphertext[C], N interface {
	Nonce
	algebra.Operand[N]
}, PK PublicKey[PK]] interface {
	Ciphertext[C]
	ReRandomise(PK, io.Reader) (C, N, error)
	ReRandomiseWithNonce(PK, N) (C, error)
}

type Scheme

type Scheme[
	SK PrivateKey[SK], PK PublicKey[PK], M Plaintext, C Ciphertext[C], N Nonce,
	KG KeyGenerator[SK, PK], ENC Encrypter[PK, M, C, N], DEC Decrypter[M, C],
] interface {
	Name() Name
	Keygen(...KeyGeneratorOption[KG, SK, PK]) (KG, error)
	Encrypter(...EncrypterOption[ENC, PK, M, C, N]) (ENC, error)
	Decrypter(SK, ...DecrypterOption[DEC, M, C]) (DEC, error)
}

type SelfEncrypter

type SelfEncrypter[SK PrivateKey[SK], M Plaintext, C Ciphertext[C], X any] interface {
	PrivateKey() SK
	SelfEncrypt(plaintext M, prng io.Reader) (ciphertext C, nonceOrCapsuleEtc X, err error)
}

type ShiftTypeCiphertext

type ShiftTypeCiphertext[
	C Ciphertext[C], CV algebra.GroupElement[CV],
	M Plaintext, PK PublicKey[PK], N interface {
		Nonce
		algebra.Operand[N]
	}, S algebra.NatLike[S],
] interface {
	HomomorphicCiphertext[C, CV, S]
	ReRandomisableCiphertext[C, N, PK]
	Shift(PK, M) (C, error)
}

type SymmetricKey

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

func NewSymmetricKey

func NewSymmetricKey(v []byte) (*SymmetricKey, error)

func (*SymmetricKey) Bytes

func (k *SymmetricKey) Bytes() []byte

func (*SymmetricKey) Clone

func (k *SymmetricKey) Clone() *SymmetricKey

func (*SymmetricKey) Equal

func (k *SymmetricKey) Equal(other *SymmetricKey) bool

Directories

Path Synopsis
Package hpke implements Hybrid Public Key Encryption as specified in RFC 9180.
Package hpke implements Hybrid Public Key Encryption as specified in RFC 9180.
Package paillier implements the Paillier cryptosystem, an additive homomorphic public-key encryption scheme.
Package paillier implements the Paillier cryptosystem, an additive homomorphic public-key encryption scheme.

Jump to

Keyboard shortcuts

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