Skip to content

Commit

Permalink
docs: Organize docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sp301415 committed Jan 19, 2025
1 parent b58b568 commit 70377d7
Show file tree
Hide file tree
Showing 33 changed files with 103 additions and 112 deletions.
4 changes: 2 additions & 2 deletions math/csprng/binary_sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type BinarySampler[T num.Integer] struct {
baseSampler *UniformSampler[uint64]
}

// NewBinarySampler allocates an empty BinarySampler.
// NewBinarySampler creates a new BinarySampler.
//
// Panics when read from crypto/rand or blake2b initialization fails.
func NewBinarySampler[T num.Integer]() *BinarySampler[T] {
Expand All @@ -20,7 +20,7 @@ func NewBinarySampler[T num.Integer]() *BinarySampler[T] {
}
}

// NewBinarySamplerWithSeed allocates an empty BinarySampler, with user supplied seed.
// NewBinarySamplerWithSeed creates a new BinarySampler, with user supplied seed.
//
// Panics when blake2b initialization fails.
func NewBinarySamplerWithSeed[T num.Integer](seed []byte) *BinarySampler[T] {
Expand Down
4 changes: 2 additions & 2 deletions math/csprng/gaussian_sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type GaussianSampler[T num.Integer] struct {
baseSampler *UniformSampler[uint32]
}

// NewGaussianSampler allocates an empty GaussianSampler.
// NewGaussianSampler creates a new GaussianSampler.
//
// Panics when read from crypto/rand or blake2b initialization fails.
func NewGaussianSampler[T num.Integer]() *GaussianSampler[T] {
Expand All @@ -21,7 +21,7 @@ func NewGaussianSampler[T num.Integer]() *GaussianSampler[T] {
}
}

// NewGaussianSamplerWithSeed allocates an empty GaussianSampler, with user supplied seed.
// NewGaussianSamplerWithSeed creates a new GaussianSampler, with user supplied seed.
//
// Panics when blake2b initialization fails.
func NewGaussianSamplerWithSeed[T num.Integer](seed []byte, stdDev float64) *GaussianSampler[T] {
Expand Down
4 changes: 2 additions & 2 deletions math/csprng/uniform_sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type UniformSampler[T num.Integer] struct {
maxT T
}

// NewUniformSampler allocates an empty UniformSampler.
// NewUniformSampler creates a new UniformSampler.
//
// Panics when read from crypto/rand or blake2b initialization fails.
func NewUniformSampler[T num.Integer]() *UniformSampler[T] {
Expand All @@ -34,7 +34,7 @@ func NewUniformSampler[T num.Integer]() *UniformSampler[T] {
return NewUniformSamplerWithSeed[T](seed)
}

// NewUniformSamplerWithSeed allocates an empty UniformSampler, with user supplied seed.
// NewUniformSamplerWithSeed creates a new UniformSampler, with user supplied seed.
//
// Panics when blake2b initialization fails.
func NewUniformSamplerWithSeed[T num.Integer](seed []byte) *UniformSampler[T] {
Expand Down
2 changes: 1 addition & 1 deletion math/poly/poly.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewPoly[T num.Integer](N int) Poly[T] {
return Poly[T]{Coeffs: make([]T, N)}
}

// From allocates an empty polynomial from given coefficient slice.
// From creates a new polynomial from given coefficient slice.
// The given slice is copied, and extended to degree N.
func From[T num.Integer](coeffs []T, N int) Poly[T] {
p := NewPoly[T](N)
Expand Down
11 changes: 5 additions & 6 deletions math/poly/poly_evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ type Evaluator[T num.Integer] struct {
// Equivalent to BitReverse([-1, 3, 7, ..., 2N-3]).
twMonoIdx []int

// buffer is the buffer values for this Evaluator.
buffer evaluationBuffer[T]
}

// evaluationBuffer contains buffer values for Evaluator.
// evaluationBuffer is a buffer for Evaluator.
type evaluationBuffer[T num.Integer] struct {
// pOut is the intermediate output polynomial for InPlace operations.
pOut Poly[T]
Expand All @@ -78,7 +77,7 @@ type evaluationBuffer[T num.Integer] struct {
fpShortSplit []FourierPoly
}

// NewEvaluator allocates an empty Evaluator with degree N.
// NewEvaluator creates a new Evaluator with degree N.
//
// Panics when N is not a power of two, or when N is smaller than MinDegree or larger than MaxDegree.
func NewEvaluator[T num.Integer](N int) *Evaluator[T] {
Expand Down Expand Up @@ -165,7 +164,7 @@ func splitParametersShort[T num.Integer](N int) (splitBits T, splitCount int) {
return
}

// newFourierBuffer allocates an empty fourierBuffer.
// newFourierBuffer creates a new fourierBuffer.
func newFourierBuffer[T num.Integer](N int) evaluationBuffer[T] {
_, splitCount := splitParametersShort[T](N)

Expand Down Expand Up @@ -207,12 +206,12 @@ func (e *Evaluator[T]) Degree() int {
return e.degree
}

// NewPoly allocates an empty polynomial with the same degree as the evaluator.
// NewPoly creates a new polynomial with the same degree as the evaluator.
func (e *Evaluator[T]) NewPoly() Poly[T] {
return Poly[T]{Coeffs: make([]T, e.degree)}
}

// NewFourierPoly allocates an empty fourier polynomial with the same degree as the evaluator.
// NewFourierPoly creates a new fourier polynomial with the same degree as the evaluator.
func (e *Evaluator[T]) NewFourierPoly() FourierPoly {
return FourierPoly{Coeffs: make([]float64, e.degree)}
}
2 changes: 1 addition & 1 deletion mktfhe/binary_decryptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type BinaryDecryptor[T tfhe.TorusInt] struct {
BaseDecryptor *Decryptor[T]
}

// NewBinaryDecryptor allocates an empty BinaryDecryptor.
// NewBinaryDecryptor creates a new BinaryDecryptor.
func NewBinaryDecryptor[T tfhe.TorusInt](params Parameters[T], sk map[int]tfhe.SecretKey[T]) *BinaryDecryptor[T] {
return &BinaryDecryptor[T]{
BinaryEncoder: tfhe.NewBinaryEncoder(params.singleKeyParameters),
Expand Down
4 changes: 2 additions & 2 deletions mktfhe/binary_encryptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type BinaryEncryptor[T tfhe.TorusInt] struct {
BaseEncryptor *Encryptor[T]
}

// NewBinaryEncryptor allocates an empty BinaryEncryptor.
// NewBinaryEncryptor creates a new BinaryEncryptor.
func NewBinaryEncryptor[T tfhe.TorusInt](params Parameters[T], idx int, crsSeed []byte) *BinaryEncryptor[T] {
return &BinaryEncryptor[T]{
BinaryEncoder: tfhe.NewBinaryEncoder(params.singleKeyParameters),
Expand All @@ -23,7 +23,7 @@ func NewBinaryEncryptor[T tfhe.TorusInt](params Parameters[T], idx int, crsSeed
}
}

// NewBinaryEncryptorWithKey allocates an empty BinaryEncryptor with a given key.
// NewBinaryEncryptorWithKey creates a new BinaryEncryptor with a given key.
func NewBinaryEncryptorWithKey[T tfhe.TorusInt](params Parameters[T], idx int, crsSeed []byte, sk tfhe.SecretKey[T]) *BinaryEncryptor[T] {
return &BinaryEncryptor[T]{
BinaryEncoder: tfhe.NewBinaryEncoder(params.singleKeyParameters),
Expand Down
2 changes: 1 addition & 1 deletion mktfhe/binary_evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type BinaryEvaluator[T tfhe.TorusInt] struct {
signLUT tfhe.LookUpTable[T]
}

// NewBinaryEvaluator allocates an empty BinaryEvaluator based on parameters.
// NewBinaryEvaluator creates a new BinaryEvaluator based on parameters.
// This does not copy evaluation keys, since they are large.
func NewBinaryEvaluator[T tfhe.TorusInt](params Parameters[T], evk map[int]EvaluationKey[T]) *BinaryEvaluator[T] {
signLUT := tfhe.NewLookUpTableCustom[T](params.PolyDegree())
Expand Down
4 changes: 2 additions & 2 deletions mktfhe/bootstrap_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type EvaluationKey[T tfhe.TorusInt] struct {
RelinKey FourierUniEncryption[T]
}

// NewEvaluationKey allocates an empty EvaluationKey.
// NewEvaluationKey creates a new EvaluationKey.
func NewEvaluationKey[T tfhe.TorusInt](params Parameters[T]) EvaluationKey[T] {
return EvaluationKey[T]{
EvaluationKey: tfhe.NewEvaluationKey(params.singleKeyParameters),
Expand All @@ -21,7 +21,7 @@ func NewEvaluationKey[T tfhe.TorusInt](params Parameters[T]) EvaluationKey[T] {
}
}

// NewEvaluationKeyCustom allocates an empty EvaluationKey with custom parameters.
// NewEvaluationKeyCustom creates a new EvaluationKey with custom parameters.
func NewEvaluationKeyCustom[T tfhe.TorusInt](lweDimension, polyDegree int, blindRotateParams, keySwitchParams, relinParams tfhe.GadgetParameters[T]) EvaluationKey[T] {
return EvaluationKey[T]{
EvaluationKey: tfhe.NewEvaluationKeyCustom(lweDimension, 1, polyDegree, blindRotateParams, keySwitchParams),
Expand Down
5 changes: 2 additions & 3 deletions mktfhe/decryptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type Decryptor[T tfhe.TorusInt] struct {
// If a secret key of a given index does not exist, it is empty.
SecretKeys []tfhe.SecretKey[T]

// buffer is a buffer for this Decryptor.
buffer decryptionBuffer[T]
}

Expand All @@ -51,7 +50,7 @@ type decryptionBuffer[T tfhe.TorusInt] struct {
ctGLWESingle tfhe.GLWECiphertext[T]
}

// NewDecryptor allocates an empty Decryptor.
// NewDecryptor creates a new Decryptor.
// Only indices between 0 and params.PartyCount is valid for sk.
func NewDecryptor[T tfhe.TorusInt](params Parameters[T], sk map[int]tfhe.SecretKey[T]) *Decryptor[T] {
singleEncs := make([]*tfhe.Encryptor[T], len(sk))
Expand All @@ -77,7 +76,7 @@ func NewDecryptor[T tfhe.TorusInt](params Parameters[T], sk map[int]tfhe.SecretK
}
}

// newDecryptionBuffer allocates an empty decryptionBuffer.
// newDecryptionBuffer creates a new decryptionBuffer.
func newDecryptionBuffer[T tfhe.TorusInt](params Parameters[T]) decryptionBuffer[T] {
return decryptionBuffer[T]{
ptGLWE: tfhe.NewGLWEPlaintext(params.singleKeyParameters),
Expand Down
7 changes: 3 additions & 4 deletions mktfhe/encryptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ type Encryptor[T tfhe.TorusInt] struct {
// This is shared with SingleKeyEncryptor.
SecretKey tfhe.SecretKey[T]

// buffer is a buffer for this Encryptor.
buffer encryptionBuffer[T]
}

Expand All @@ -49,7 +48,7 @@ type encryptionBuffer[T tfhe.TorusInt] struct {
ctGLWESingle tfhe.GLWECiphertext[T]
}

// NewEncryptor allocates an empty Encryptor.
// NewEncryptor creates a new Encryptor.
func NewEncryptor[T tfhe.TorusInt](params Parameters[T], idx int, crsSeed []byte) *Encryptor[T] {
if idx > params.partyCount {
panic("index larger than PartyCount")
Expand Down Expand Up @@ -80,7 +79,7 @@ func NewEncryptor[T tfhe.TorusInt](params Parameters[T], idx int, crsSeed []byte
}
}

// NewEncryptorWithKey allocates an empty Encryptor with a given key.
// NewEncryptorWithKey creates a new Encryptor with a given key.
//
// Panics if the index is larger than PartyCount.
func NewEncryptorWithKey[T tfhe.TorusInt](params Parameters[T], idx int, crsSeed []byte, sk tfhe.SecretKey[T]) *Encryptor[T] {
Expand Down Expand Up @@ -111,7 +110,7 @@ func NewEncryptorWithKey[T tfhe.TorusInt](params Parameters[T], idx int, crsSeed
}
}

// newEncryptionBuffer allocates an empty encryptionBuffer.
// newEncryptionBuffer creates a new encryptionBuffer.
func newEncryptionBuffer[T tfhe.TorusInt](params Parameters[T]) encryptionBuffer[T] {
return encryptionBuffer[T]{
ptGLWE: tfhe.NewGLWEPlaintext(params.singleKeyParameters),
Expand Down
3 changes: 1 addition & 2 deletions mktfhe/encryptor_public.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ type PublicEncryptor[T tfhe.TorusInt] struct {
// This is shared with SingleKeyPublicEncryptor.
PublicKey tfhe.PublicKey[T]

// buffer is a buffer for this PublicEncryptor.
buffer publicEncryptionBuffer[T]
}

Expand All @@ -39,7 +38,7 @@ type publicEncryptionBuffer[T tfhe.TorusInt] struct {
ctGLWESingle tfhe.GLWECiphertext[T]
}

// NewPublicEncryptor allocates an empty PublicEncryptor.
// NewPublicEncryptor creates a new PublicEncryptor.
func NewPublicEncryptor[T tfhe.TorusInt](params Parameters[T], idx int, publicKey tfhe.PublicKey[T]) *PublicEncryptor[T] {
if idx > params.partyCount {
panic("index larger than PartyCount")
Expand Down
5 changes: 2 additions & 3 deletions mktfhe/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ type Evaluator[T tfhe.TorusInt] struct {
// If an evaluation key does not exist for given index, it is empty.
EvaluationKeys []EvaluationKey[T]

// buffer is a buffer for this Evaluator.
buffer evaluationBuffer[T]
}

Expand Down Expand Up @@ -78,7 +77,7 @@ type evaluationBuffer[T tfhe.TorusInt] struct {
lut tfhe.LookUpTable[T]
}

// NewEvaluator allocates an empty Evaluator.
// NewEvaluator creates a new Evaluator.
// Only indices between 0 and params.PartyCount is valid for evk.
func NewEvaluator[T tfhe.TorusInt](params Parameters[T], evk map[int]EvaluationKey[T]) *Evaluator[T] {
singleEvals := make([]*tfhe.Evaluator[T], params.partyCount)
Expand Down Expand Up @@ -115,7 +114,7 @@ func NewEvaluator[T tfhe.TorusInt](params Parameters[T], evk map[int]EvaluationK
}
}

// newEvaluationBuffer allocates an empty evaluationBuffer.
// newEvaluationBuffer creates a new evaluationBuffer.
func newEvaluationBuffer[T tfhe.TorusInt](params Parameters[T]) evaluationBuffer[T] {
ctRelin := NewGLWECiphertext(params)
ctRelinTransposed := make([]tfhe.GLWECiphertext[T], params.GLWERank()+1)
Expand Down
8 changes: 4 additions & 4 deletions mktfhe/fourier_glwe.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type FourierGLWECiphertext[T tfhe.TorusInt] struct {
Value []poly.FourierPoly
}

// NewFourierGLWECiphertext allocates an empty Fourier GLWE ciphertext.
// NewFourierGLWECiphertext creates a new Fourier GLWE ciphertext.
func NewFourierGLWECiphertext[T tfhe.TorusInt](params Parameters[T]) FourierGLWECiphertext[T] {
ct := make([]poly.FourierPoly, params.GLWERank()+1)
for i := 0; i < params.GLWERank()+1; i++ {
Expand All @@ -20,7 +20,7 @@ func NewFourierGLWECiphertext[T tfhe.TorusInt](params Parameters[T]) FourierGLWE
return FourierGLWECiphertext[T]{Value: ct}
}

// NewFourierGLWECiphertextCustom allocates an empty Fourier GLWE ciphertext with given dimension and polyDegree
// NewFourierGLWECiphertextCustom creates a new Fourier GLWE ciphertext with given dimension and polyDegree
func NewFourierGLWECiphertextCustom[T tfhe.TorusInt](glweRank, polyDegree int) FourierGLWECiphertext[T] {
ct := make([]poly.FourierPoly, glweRank+1)
for i := 0; i < glweRank+1; i++ {
Expand Down Expand Up @@ -74,7 +74,7 @@ type FourierUniEncryption[T tfhe.TorusInt] struct {
Value []tfhe.FourierGLevCiphertext[T]
}

// NewFourierUniEncryption allocates an empty Fourier UniEncryption.
// NewFourierUniEncryption creates a new Fourier UniEncryption.
func NewFourierUniEncryption[T tfhe.TorusInt](params Parameters[T], gadgetParams tfhe.GadgetParameters[T]) FourierUniEncryption[T] {
return FourierUniEncryption[T]{
GadgetParameters: gadgetParams,
Expand All @@ -85,7 +85,7 @@ func NewFourierUniEncryption[T tfhe.TorusInt](params Parameters[T], gadgetParams
}
}

// NewFourierUniEncryptionCustom allocates an empty FourierUniEncryption with given polyDegree and partyCount.
// NewFourierUniEncryptionCustom creates a new FourierUniEncryption with given polyDegree and partyCount.
func NewFourierUniEncryptionCustom[T tfhe.TorusInt](polyDegree int, gadgetParams tfhe.GadgetParameters[T]) FourierUniEncryption[T] {
return FourierUniEncryption[T]{
GadgetParameters: gadgetParams,
Expand Down
2 changes: 1 addition & 1 deletion mktfhe/fourier_glwe_conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type GLWETransformer[T tfhe.TorusInt] struct {
PolyEvaluator *poly.Evaluator[T]
}

// NewGLWETransformer allocates an empty GLWE transformer with given parameters.
// NewGLWETransformer creates a new GLWE transformer with given parameters.
func NewGLWETransformer[T tfhe.TorusInt](params Parameters[T]) *GLWETransformer[T] {
return &GLWETransformer[T]{
Parameters: params,
Expand Down
8 changes: 4 additions & 4 deletions mktfhe/glwe.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type GLWECiphertext[T tfhe.TorusInt] struct {
Value []poly.Poly[T]
}

// NewGLWECiphertext allocates an empty GLWE ciphertext.
// NewGLWECiphertext creates a new GLWE ciphertext.
func NewGLWECiphertext[T tfhe.TorusInt](params Parameters[T]) GLWECiphertext[T] {
ct := make([]poly.Poly[T], params.GLWERank()+1)
for i := 0; i < params.GLWERank()+1; i++ {
Expand All @@ -22,7 +22,7 @@ func NewGLWECiphertext[T tfhe.TorusInt](params Parameters[T]) GLWECiphertext[T]
return GLWECiphertext[T]{Value: ct}
}

// NewGLWECiphertextCustom allocates an empty GLWE ciphertext with given dimension and partyCount.
// NewGLWECiphertextCustom creates a new GLWE ciphertext with given dimension and partyCount.
func NewGLWECiphertextCustom[T tfhe.TorusInt](glweRank, polyDegree int) GLWECiphertext[T] {
ct := make([]poly.Poly[T], glweRank+1)
for i := 0; i < glweRank+1; i++ {
Expand Down Expand Up @@ -101,7 +101,7 @@ type UniEncryption[T tfhe.TorusInt] struct {
Value []tfhe.GLevCiphertext[T]
}

// NewUniEncryption allocates an empty UniEncryption.
// NewUniEncryption creates a new UniEncryption.
func NewUniEncryption[T tfhe.TorusInt](params Parameters[T], gadgetParams tfhe.GadgetParameters[T]) UniEncryption[T] {
return UniEncryption[T]{
GadgetParameters: gadgetParams,
Expand All @@ -112,7 +112,7 @@ func NewUniEncryption[T tfhe.TorusInt](params Parameters[T], gadgetParams tfhe.G
}
}

// NewUniEncryptionCustom allocates an empty UniEncryption with given polyDegree and partyCount.
// NewUniEncryptionCustom creates a new UniEncryption with given polyDegree and partyCount.
func NewUniEncryptionCustom[T tfhe.TorusInt](polyDegree int, gadgetParams tfhe.GadgetParameters[T]) UniEncryption[T] {
return UniEncryption[T]{
GadgetParameters: gadgetParams,
Expand Down
4 changes: 2 additions & 2 deletions mktfhe/lwe.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ type LWECiphertext[T tfhe.TorusInt] struct {
Value []T
}

// NewLWECiphertext allocates an empty LWE ciphertext.
// NewLWECiphertext creates a new LWE ciphertext.
func NewLWECiphertext[T tfhe.TorusInt](params Parameters[T]) LWECiphertext[T] {
return LWECiphertext[T]{Value: make([]T, params.DefaultLWEDimension()+1)}
}

// NewLWECiphertextCustom allocates an empty LWE ciphertext with given dimension.
// NewLWECiphertextCustom creates a new LWE ciphertext with given dimension.
func NewLWECiphertextCustom[T tfhe.TorusInt](lweDimension int) LWECiphertext[T] {
return LWECiphertext[T]{Value: make([]T, lweDimension+1)}
}
Expand Down
2 changes: 1 addition & 1 deletion tfhe/binary_evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type BinaryEvaluator[T TorusInt] struct {
signLUT LookUpTable[T]
}

// NewBinaryEvaluator allocates an empty BinaryEvaluator based on parameters.
// NewBinaryEvaluator creates a new BinaryEvaluator based on parameters.
// This does not copy evaluation keys, since they are large.
func NewBinaryEvaluator[T TorusInt](params Parameters[T], evk EvaluationKey[T]) *BinaryEvaluator[T] {
signLUT := NewLookUpTable(params)
Expand Down
Loading

0 comments on commit 70377d7

Please sign in to comment.