internal

package
v0.0.0-...-8e3605f Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2022 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	K             = 4
	Eta1          = 2
	DU            = 11
	DV            = 5
	PublicKeySize = 32 + K*common.PolySize

	PrivateKeySize = K * common.PolySize

	PlaintextSize  = common.PlaintextSize
	SeedSize       = 32
	CiphertextSize = 1568
)

Variables

This section is empty.

Functions

func NewKeyFromSeed

func NewKeyFromSeed(seed []byte) (*PublicKey, *PrivateKey)

Derives a new Kyber.CPAPKE keypair from the given seed.

func PolyDotHat

func PolyDotHat(p *common.Poly, a, b *Vec)

Sets p to the inner product of a and b using "pointwise" multiplication.

See MulHat() and NTT() for a description of the multiplication. Assumes a and b are in Montgomery form. p will be in Montgomery form, and its coefficients will be bounded in absolute value by 2kq. If a and b are not in Montgomery form, then the action is the same as "pointwise" multiplication followed by multiplying by R⁻¹, the inverse of the Montgomery factor.

Types

type Mat

type Mat [K]Vec

A k by k matrix of polynomials.

func (*Mat) Derive

func (m *Mat) Derive(seed *[32]byte, transpose bool)

Expands the given seed to the corresponding matrix A or its transpose Aᵀ.

func (*Mat) Transpose

func (m *Mat) Transpose()

Tranposes A in place.

type PrivateKey

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

A Kyber.CPAPKE private key.

func (*PrivateKey) DecryptTo

func (sk *PrivateKey) DecryptTo(pt, ct []byte)

Decrypts ciphertext ct meant for private key sk to plaintext pt.

func (*PrivateKey) Equal

func (sk *PrivateKey) Equal(other *PrivateKey) bool

Returns whether sk equals other.

func (*PrivateKey) Pack

func (sk *PrivateKey) Pack(buf []byte)

Packs the private key to buf.

func (*PrivateKey) Unpack

func (sk *PrivateKey) Unpack(buf []byte)

Unpacks the private key from buf.

type PublicKey

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

A Kyber.CPAPKE public key.

func (*PublicKey) EncryptTo

func (pk *PublicKey) EncryptTo(ct, pt, seed []byte)

Encrypts message pt for the public key to ciphertext ct using randomness from seed.

seed has to be of length SeedSize, pt of PlaintextSize and ct of CiphertextSize.

func (*PublicKey) Pack

func (pk *PublicKey) Pack(buf []byte)

Packs the public key to buf.

func (*PublicKey) Unpack

func (pk *PublicKey) Unpack(buf []byte)

Unpacks the public key from buf.

type Vec

type Vec [K]common.Poly

A vector of K polynomials

func (*Vec) Add

func (v *Vec) Add(a, b *Vec)

Sets v to a + b.

func (*Vec) BarrettReduce

func (v *Vec) BarrettReduce()

Almost normalizes coefficients in-place.

Ensures each coefficient is in {0, …, q}.

func (*Vec) CompressTo

func (v *Vec) CompressTo(m []byte, d int)

Writes Compress_q(v, d) to m.

Assumes v is normalized and d is in {3, 4, 5, 10, 11}.

func (*Vec) Decompress

func (v *Vec) Decompress(m []byte, d int)

Set v to Decompress_q(m, 1).

Assumes d is in {3, 4, 5, 10, 11}. v will be normalized.

func (*Vec) DeriveNoise

func (v *Vec) DeriveNoise(seed []byte, nonce uint8, eta int)

Samples v[i] from a centered binomial distribution with given η, seed and nonce+i.

Essentially CBD_η(PRF(seed, nonce+i)) from the specification.

func (*Vec) InvNTT

func (v *Vec) InvNTT()

Applies in-place inverse NTT(). See Poly.InvNTT() for assumptions.

func (*Vec) NTT

func (v *Vec) NTT()

Applies in-place forward NTT(). See Poly.NTT() for assumptions.

func (*Vec) Normalize

func (v *Vec) Normalize()

Normalizes coefficients in-place.

Ensures each coefficient is in {0, …, q-1}.

func (*Vec) Pack

func (v *Vec) Pack(buf []byte)

Packs v into buf, which must be of length K*PolySize.

func (*Vec) Unpack

func (v *Vec) Unpack(buf []byte)

Unpacks v from buf which must be of length K*PolySize.

Jump to

Keyboard shortcuts

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