Skip to content

Commit

Permalink
feat: Revamp mktfhe parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
sp301415 committed Nov 23, 2024
1 parent 8819a71 commit 4a9cb23
Show file tree
Hide file tree
Showing 27 changed files with 718 additions and 370 deletions.
2 changes: 1 addition & 1 deletion mktfhe/binary_decryptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type BinaryDecryptor[T tfhe.TorusInt] struct {
// NewBinaryDecryptor allocates an empty BinaryDecryptor.
func NewBinaryDecryptor[T tfhe.TorusInt](params Parameters[T], sk map[int]tfhe.SecretKey[T]) *BinaryDecryptor[T] {
return &BinaryDecryptor[T]{
BinaryEncoder: tfhe.NewBinaryEncoder(params.Parameters),
BinaryEncoder: tfhe.NewBinaryEncoder(params.singleKeyParameters),
Parameters: params,
BaseDecryptor: NewDecryptor(params, sk),
}
Expand Down
4 changes: 2 additions & 2 deletions mktfhe/binary_encryptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type BinaryEncryptor[T tfhe.TorusInt] struct {
// NewBinaryEncryptor allocates an empty BinaryEncryptor.
func NewBinaryEncryptor[T tfhe.TorusInt](params Parameters[T], idx int, crsSeed []byte) *BinaryEncryptor[T] {
return &BinaryEncryptor[T]{
BinaryEncoder: tfhe.NewBinaryEncoder(params.Parameters),
BinaryEncoder: tfhe.NewBinaryEncoder(params.singleKeyParameters),
Parameters: params,
BaseEncryptor: NewEncryptor(params, idx, crsSeed),
}
Expand All @@ -26,7 +26,7 @@ func NewBinaryEncryptor[T tfhe.TorusInt](params Parameters[T], idx int, crsSeed
// NewBinaryEncryptorWithKey allocates an empty 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.Parameters),
BinaryEncoder: tfhe.NewBinaryEncoder(params.singleKeyParameters),
Parameters: params,
BaseEncryptor: NewEncryptorWithKey(params, idx, crsSeed, sk),
}
Expand Down
2 changes: 1 addition & 1 deletion mktfhe/binary_encryptor_public.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type BinaryPublicEncryptor[T tfhe.TorusInt] struct {
// NewBinaryPublicEncryptor allocates a new BinaryPublicEncryptor.
func NewBinaryPublicEncryptor[T tfhe.TorusInt](params Parameters[T], idx int, pk tfhe.PublicKey[T]) *BinaryPublicEncryptor[T] {
return &BinaryPublicEncryptor[T]{
BinaryEncoder: tfhe.NewBinaryEncoder(params.Parameters),
BinaryEncoder: tfhe.NewBinaryEncoder(params.singleKeyParameters),
Parameters: params,
BaseEncryptor: NewPublicEncryptor(params, idx, pk),
}
Expand Down
30 changes: 15 additions & 15 deletions mktfhe/binary_evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ type BinaryEvaluator[T tfhe.TorusInt] struct {
// NewBinaryEvaluator allocates an empty 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.NewLookUpTable(params.Parameters)
vec.Fill(signLUT.Value, 1<<(params.LogQ()-3))
signLUT := tfhe.NewLookUpTableCustom[T](params.polyDegree)
vec.Fill(signLUT.Value, 1<<(params.logQ-3))

return &BinaryEvaluator[T]{
BinaryEncoder: tfhe.NewBinaryEncoder(params.Parameters),
BinaryEncoder: tfhe.NewBinaryEncoder(params.singleKeyParameters),
Parameters: params,
BaseEvaluator: NewEvaluator(params, evk),
signLUT: signLUT,
Expand Down Expand Up @@ -73,7 +73,7 @@ func (e *BinaryEvaluator[T]) ANDAssign(ct0, ct1, ctOut LWECiphertext[T]) {
for i := 0; i < e.Parameters.DefaultLWEDimension()+1; i++ {
ctOut.Value[i] = ct0.Value[i] + ct1.Value[i]
}
ctOut.Value[0] -= 1 << (e.Parameters.LogQ() - 3)
ctOut.Value[0] -= 1 << (e.Parameters.logQ - 3)

e.BaseEvaluator.BootstrapLUTAssign(ctOut, e.signLUT, ctOut)
}
Expand All @@ -92,7 +92,7 @@ func (e *BinaryEvaluator[T]) ANDParallelAssign(ct0, ct1, ctOut LWECiphertext[T])
for i := 0; i < e.Parameters.DefaultLWEDimension()+1; i++ {
ctOut.Value[i] = ct0.Value[i] + ct1.Value[i]
}
ctOut.Value[0] -= 1 << (e.Parameters.LogQ() - 3)
ctOut.Value[0] -= 1 << (e.Parameters.logQ - 3)

e.BaseEvaluator.BootstrapLUTParallelAssign(ctOut, e.signLUT, ctOut)
}
Expand All @@ -111,7 +111,7 @@ func (e *BinaryEvaluator[T]) NANDAssign(ct0, ct1, ctOut LWECiphertext[T]) {
for i := 0; i < e.Parameters.DefaultLWEDimension()+1; i++ {
ctOut.Value[i] = -ct0.Value[i] - ct1.Value[i]
}
ctOut.Value[0] += 1 << (e.Parameters.LogQ() - 3)
ctOut.Value[0] += 1 << (e.Parameters.logQ - 3)

e.BaseEvaluator.BootstrapLUTAssign(ctOut, e.signLUT, ctOut)
}
Expand All @@ -130,7 +130,7 @@ func (e *BinaryEvaluator[T]) NANDParallelAssign(ct0, ct1, ctOut LWECiphertext[T]
for i := 0; i < e.Parameters.DefaultLWEDimension()+1; i++ {
ctOut.Value[i] = -ct0.Value[i] - ct1.Value[i]
}
ctOut.Value[0] += 1 << (e.Parameters.LogQ() - 3)
ctOut.Value[0] += 1 << (e.Parameters.logQ - 3)

e.BaseEvaluator.BootstrapLUTParallelAssign(ctOut, e.signLUT, ctOut)
}
Expand All @@ -149,7 +149,7 @@ func (e *BinaryEvaluator[T]) ORAssign(ct0, ct1, ctOut LWECiphertext[T]) {
for i := 0; i < e.Parameters.DefaultLWEDimension()+1; i++ {
ctOut.Value[i] = ct0.Value[i] + ct1.Value[i]
}
ctOut.Value[0] += 1 << (e.Parameters.LogQ() - 3)
ctOut.Value[0] += 1 << (e.Parameters.logQ - 3)

e.BaseEvaluator.BootstrapLUTAssign(ctOut, e.signLUT, ctOut)
}
Expand All @@ -168,7 +168,7 @@ func (e *BinaryEvaluator[T]) ORParallelAssign(ct0, ct1, ctOut LWECiphertext[T])
for i := 0; i < e.Parameters.DefaultLWEDimension()+1; i++ {
ctOut.Value[i] = ct0.Value[i] + ct1.Value[i]
}
ctOut.Value[0] += 1 << (e.Parameters.LogQ() - 3)
ctOut.Value[0] += 1 << (e.Parameters.logQ - 3)

e.BaseEvaluator.BootstrapLUTParallelAssign(ctOut, e.signLUT, ctOut)
}
Expand All @@ -187,7 +187,7 @@ func (e *BinaryEvaluator[T]) NORAssign(ct0, ct1, ctOut LWECiphertext[T]) {
for i := 0; i < e.Parameters.DefaultLWEDimension()+1; i++ {
ctOut.Value[i] = -ct0.Value[i] - ct1.Value[i]
}
ctOut.Value[0] -= 1 << (e.Parameters.LogQ() - 3)
ctOut.Value[0] -= 1 << (e.Parameters.logQ - 3)

e.BaseEvaluator.BootstrapLUTAssign(ctOut, e.signLUT, ctOut)
}
Expand All @@ -206,7 +206,7 @@ func (e *BinaryEvaluator[T]) NORParallelAssign(ct0, ct1, ctOut LWECiphertext[T])
for i := 0; i < e.Parameters.DefaultLWEDimension()+1; i++ {
ctOut.Value[i] = -ct0.Value[i] - ct1.Value[i]
}
ctOut.Value[0] -= 1 << (e.Parameters.LogQ() - 3)
ctOut.Value[0] -= 1 << (e.Parameters.logQ - 3)

e.BaseEvaluator.BootstrapLUTParallelAssign(ctOut, e.signLUT, ctOut)
}
Expand All @@ -225,7 +225,7 @@ func (e *BinaryEvaluator[T]) XORAssign(ct0, ct1, ctOut LWECiphertext[T]) {
for i := 0; i < e.Parameters.DefaultLWEDimension()+1; i++ {
ctOut.Value[i] = 2 * (ct0.Value[i] + ct1.Value[i])
}
ctOut.Value[0] += 1 << (e.Parameters.LogQ() - 3)
ctOut.Value[0] += 1 << (e.Parameters.logQ - 3)

e.BaseEvaluator.BootstrapLUTAssign(ctOut, e.signLUT, ctOut)
}
Expand All @@ -244,7 +244,7 @@ func (e *BinaryEvaluator[T]) XORParallelAssign(ct0, ct1, ctOut LWECiphertext[T])
for i := 0; i < e.Parameters.DefaultLWEDimension()+1; i++ {
ctOut.Value[i] = 2 * (ct0.Value[i] + ct1.Value[i])
}
ctOut.Value[0] += 1 << (e.Parameters.LogQ() - 3)
ctOut.Value[0] += 1 << (e.Parameters.logQ - 3)

e.BaseEvaluator.BootstrapLUTParallelAssign(ctOut, e.signLUT, ctOut)
}
Expand All @@ -263,7 +263,7 @@ func (e *BinaryEvaluator[T]) XNORAssign(ct0, ct1, ctOut LWECiphertext[T]) {
for i := 0; i < e.Parameters.DefaultLWEDimension()+1; i++ {
ctOut.Value[i] = 2 * (-ct0.Value[i] - ct1.Value[i])
}
ctOut.Value[0] -= 1 << (e.Parameters.LogQ() - 3)
ctOut.Value[0] -= 1 << (e.Parameters.logQ - 3)

e.BaseEvaluator.BootstrapLUTAssign(ctOut, e.signLUT, ctOut)
}
Expand All @@ -282,7 +282,7 @@ func (e *BinaryEvaluator[T]) XNORParallelAssign(ct0, ct1, ctOut LWECiphertext[T]
for i := 0; i < e.Parameters.DefaultLWEDimension()+1; i++ {
ctOut.Value[i] = 2 * (-ct0.Value[i] - ct1.Value[i])
}
ctOut.Value[0] -= 1 << (e.Parameters.LogQ() - 3)
ctOut.Value[0] -= 1 << (e.Parameters.logQ - 3)

e.BaseEvaluator.BootstrapLUTParallelAssign(ctOut, e.signLUT, ctOut)
}
22 changes: 11 additions & 11 deletions mktfhe/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (e *Evaluator[T]) BootstrapLUT(ct LWECiphertext[T], lut tfhe.LookUpTable[T]

// BootstrapLUTAssign bootstraps LWE ciphertext with respect to given LUT and writes it to ctOut.
func (e *Evaluator[T]) BootstrapLUTAssign(ct LWECiphertext[T], lut tfhe.LookUpTable[T], ctOut LWECiphertext[T]) {
switch e.Parameters.BootstrapOrder() {
switch e.Parameters.bootstrapOrder {
case tfhe.OrderKeySwitchBlindRotate:
e.KeySwitchForBootstrapAssign(ct, e.buffer.ctKeySwitchForBootstrap)
e.BlindRotateAssign(e.buffer.ctKeySwitchForBootstrap, lut, e.buffer.ctRotate)
Expand Down Expand Up @@ -61,7 +61,7 @@ func (e *Evaluator[T]) BootstrapLUTParallel(ct LWECiphertext[T], lut tfhe.LookUp

// BootstrapLUTParallelAssign bootstraps LWE ciphertext with respect to given LUT and writes it to ctOut in parallel.
func (e *Evaluator[T]) BootstrapLUTParallelAssign(ct LWECiphertext[T], lut tfhe.LookUpTable[T], ctOut LWECiphertext[T]) {
switch e.Parameters.BootstrapOrder() {
switch e.Parameters.bootstrapOrder {
case tfhe.OrderKeySwitchBlindRotate:
e.KeySwitchForBootstrapAssign(ct, e.buffer.ctKeySwitchForBootstrap)
e.BlindRotateParallelAssign(e.buffer.ctKeySwitchForBootstrap, lut, e.buffer.ctRotate)
Expand Down Expand Up @@ -89,7 +89,7 @@ func (e *Evaluator[T]) BlindRotateAssign(ct LWECiphertext[T], lut tfhe.LookUpTab
for i, ok := range e.PartyBitMap {
if ok {
e.buffer.ctRotateInputs[i].Value[0] = 0
vec.CopyAssign(ct.Value[1+i*e.Parameters.SingleKeyLWEDimension():1+(i+1)*e.Parameters.SingleKeyLWEDimension()], e.buffer.ctRotateInputs[i].Value[1:])
vec.CopyAssign(ct.Value[1+i*e.Parameters.singleLWEDimension:1+(i+1)*e.Parameters.singleLWEDimension], e.buffer.ctRotateInputs[i].Value[1:])
for j := 0; j < e.Parameters.accumulatorParameters.Level(); j++ {
e.SingleKeyEvaluators[i].BlindRotateAssign(e.buffer.ctRotateInputs[i], e.buffer.gadgetLUTs[j], e.buffer.ctAccs[i])
e.SingleKeyEvaluators[i].ToFourierGLWECiphertextAssign(e.buffer.ctAccs[i], e.buffer.ctFourierAccs[i].Value[j])
Expand Down Expand Up @@ -119,7 +119,7 @@ func (e *Evaluator[T]) BlindRotateParallelAssign(ct LWECiphertext[T], lut tfhe.L
wg.Add(1)
go func(i int) {
e.buffer.ctRotateInputs[i].Value[0] = 0
vec.CopyAssign(ct.Value[1+i*e.Parameters.SingleKeyLWEDimension():1+(i+1)*e.Parameters.SingleKeyLWEDimension()], e.buffer.ctRotateInputs[i].Value[1:])
vec.CopyAssign(ct.Value[1+i*e.Parameters.singleLWEDimension:1+(i+1)*e.Parameters.singleLWEDimension], e.buffer.ctRotateInputs[i].Value[1:])
for j := 0; j < e.Parameters.accumulatorParameters.Level(); j++ {
e.SingleKeyEvaluators[i].BlindRotateAssign(e.buffer.ctRotateInputs[i], e.buffer.gadgetLUTs[j], e.buffer.ctAccs[i])
e.SingleKeyEvaluators[i].ToFourierGLWECiphertextAssign(e.buffer.ctAccs[i], e.buffer.ctFourierAccs[i].Value[j])
Expand All @@ -141,7 +141,7 @@ func (e *Evaluator[T]) BlindRotateParallelAssign(ct LWECiphertext[T], lut tfhe.L
// Input ciphertext should be of length GLWEDimension + 1.
// Output ciphertext will be of length LWEDimension + 1.
func (e *Evaluator[T]) KeySwitchForBootstrap(ct LWECiphertext[T]) LWECiphertext[T] {
ctOut := NewLWECiphertextCustom[T](e.Parameters.SingleKeyLWEDimension())
ctOut := NewLWECiphertextCustom[T](e.Parameters.singleLWEDimension)
e.KeySwitchForBootstrapAssign(ct, ctOut)
return ctOut
}
Expand All @@ -150,18 +150,18 @@ func (e *Evaluator[T]) KeySwitchForBootstrap(ct LWECiphertext[T]) LWECiphertext[
// Input ciphertext should be of length GLWEDimension + 1.
// Output ciphertext should be of length LWEDimension + 1.
func (e *Evaluator[T]) KeySwitchForBootstrapAssign(ct, ctOut LWECiphertext[T]) {
scalarDecomposed := e.Decomposer.ScalarDecomposedBuffer(e.Parameters.KeySwitchParameters())
scalarDecomposed := e.Decomposer.ScalarDecomposedBuffer(e.Parameters.keySwitchParameters)

ctOut.Value[0] = ct.Value[0]

for i, ok := range e.PartyBitMap {
ctMask := ct.Value[1+i*e.Parameters.SingleKeyGLWEDimension() : 1+(i+1)*e.Parameters.SingleKeyGLWEDimension()]
ctOutMask := ctOut.Value[1+i*e.Parameters.SingleKeyLWEDimension() : 1+(i+1)*e.Parameters.SingleKeyLWEDimension()]
ctMask := ct.Value[1+i*e.Parameters.singleGLWEDimension : 1+(i+1)*e.Parameters.singleGLWEDimension]
ctOutMask := ctOut.Value[1+i*e.Parameters.singleLWEDimension : 1+(i+1)*e.Parameters.singleLWEDimension]
if ok {
vec.CopyAssign(ctMask, ctOutMask)
for j, jj := e.Parameters.SingleKeyLWEDimension(), 0; j < e.Parameters.SingleKeyGLWEDimension(); j, jj = j+1, jj+1 {
e.SingleKeyEvaluators[i].Decomposer.DecomposeScalarAssign(ctMask[j], e.Parameters.KeySwitchParameters(), scalarDecomposed)
for k := 0; k < e.Parameters.KeySwitchParameters().Level(); k++ {
for j, jj := e.Parameters.singleLWEDimension, 0; j < e.Parameters.singleGLWEDimension; j, jj = j+1, jj+1 {
e.SingleKeyEvaluators[i].Decomposer.DecomposeScalarAssign(ctMask[j], e.Parameters.keySwitchParameters, scalarDecomposed)
for k := 0; k < e.Parameters.keySwitchParameters.Level(); k++ {
vec.ScalarMulAddAssign(e.EvaluationKeys[i].KeySwitchKey.Value[jj].Value[k].Value[1:], scalarDecomposed[k], ctOutMask)
ctOut.Value[0] += scalarDecomposed[k] * e.EvaluationKeys[i].KeySwitchKey.Value[jj].Value[k].Value[0]
}
Expand Down
8 changes: 4 additions & 4 deletions mktfhe/bootstrap_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ type EvaluationKey[T tfhe.TorusInt] struct {
// NewEvaluationKey allocates an empty EvaluationKey.
func NewEvaluationKey[T tfhe.TorusInt](params Parameters[T]) EvaluationKey[T] {
return EvaluationKey[T]{
EvaluationKey: tfhe.NewEvaluationKey(params.Parameters),
CRSPublicKey: tfhe.NewFourierGLevCiphertext(params.Parameters, params.relinKeyParameters),
EvaluationKey: tfhe.NewEvaluationKey(params.singleKeyParameters),
CRSPublicKey: tfhe.NewFourierGLevCiphertext(params.singleKeyParameters, params.relinKeyParameters),
RelinKey: NewFourierUniEncryption(params, params.relinKeyParameters),
}
}

// NewEvaluationKeyCustom allocates an empty EvaluationKey with custom parameters.
func NewEvaluationKeyCustom[T tfhe.TorusInt](lweDimension, polyDegree int, bootstrapParams, keyswitchParams, relinParams tfhe.GadgetParameters[T]) EvaluationKey[T] {
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, bootstrapParams, keyswitchParams),
EvaluationKey: tfhe.NewEvaluationKeyCustom(lweDimension, 1, polyDegree, blindRotateParams, keySwitchParams),
CRSPublicKey: tfhe.NewFourierGLevCiphertextCustom(1, polyDegree, relinParams),
RelinKey: NewFourierUniEncryptionCustom(polyDegree, relinParams),
}
Expand Down
2 changes: 1 addition & 1 deletion mktfhe/bootstrap_keygen.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (e *Encryptor[T]) GenKeySwitchKeyForBootstrapParallel() tfhe.LWEKeySwitchKe

// GenCRSPublicKey samples a new public key from the common reference string.
func (e *Encryptor[T]) GenCRSPublicKey() tfhe.FourierGLevCiphertext[T] {
pk := tfhe.NewFourierGLevCiphertext(e.Parameters.Parameters, e.Parameters.relinKeyParameters)
pk := tfhe.NewFourierGLevCiphertext(e.Parameters.singleKeyParameters, e.Parameters.relinKeyParameters)
for i := 0; i < e.Parameters.relinKeyParameters.Level(); i++ {
e.buffer.ctGLWESingle.Value[1].CopyFrom(e.CRS[i])

Expand Down
18 changes: 9 additions & 9 deletions mktfhe/decryptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ func NewDecryptor[T tfhe.TorusInt](params Parameters[T], sk map[int]tfhe.SecretK
singleKeys := make([]tfhe.SecretKey[T], len(sk))
partyBitMap := make([]bool, params.PartyCount())
for i := range sk {
singleEncs[i] = tfhe.NewEncryptorWithKey(params.Parameters, sk[i])
singleEncs[i] = tfhe.NewEncryptorWithKey(params.singleKeyParameters, sk[i])
singleKeys[i] = sk[i]
partyBitMap[i] = true
}

return &Decryptor[T]{
Encoder: tfhe.NewEncoder(params.Parameters),
Encoder: tfhe.NewEncoder(params.singleKeyParameters),
GLWETransformer: NewGLWETransformer(params),
SingleKeyDecryptors: singleEncs,

Expand All @@ -80,18 +80,18 @@ func NewDecryptor[T tfhe.TorusInt](params Parameters[T], sk map[int]tfhe.SecretK
// newDecryptionBuffer allocates an empty decryptionBuffer.
func newDecryptionBuffer[T tfhe.TorusInt](params Parameters[T]) decryptionBuffer[T] {
return decryptionBuffer[T]{
ptGLWE: tfhe.NewGLWEPlaintext(params.Parameters),
ptGLWE: tfhe.NewGLWEPlaintext(params.singleKeyParameters),
ctGLWE: NewGLWECiphertext(params),

ctLWESingle: tfhe.NewLWECiphertext(params.Parameters),
ctGLWESingle: tfhe.NewGLWECiphertext(params.Parameters),
ctLWESingle: tfhe.NewLWECiphertext(params.singleKeyParameters),
ctGLWESingle: tfhe.NewGLWECiphertext(params.singleKeyParameters),
}
}

// AddSecretKey adds a secret key to this Decryptor.
// If a secret key of a given index already exists, it is overwritten.
func (d *Decryptor[T]) AddSecretKey(idx int, sk tfhe.SecretKey[T]) {
d.SingleKeyDecryptors[idx] = tfhe.NewEncryptorWithKey(d.Parameters.Parameters, sk)
d.SingleKeyDecryptors[idx] = tfhe.NewEncryptorWithKey(d.Parameters.singleKeyParameters, sk)
d.SecretKeys[idx] = sk
d.PartyBitMap[idx] = true
}
Expand Down Expand Up @@ -130,7 +130,7 @@ func (d *Decryptor[T]) DecryptLWEPlaintext(ct LWECiphertext[T]) tfhe.LWEPlaintex
pt := ct.Value[0]
for i, ok := range d.PartyBitMap {
if ok {
ctMask := ct.Value[1+i*d.Parameters.SingleKeyDefaultLWEDimension() : 1+(i+1)*d.Parameters.SingleKeyDefaultLWEDimension()]
ctMask := ct.Value[1+i*d.Parameters.SingleDefaultLWEDimension() : 1+(i+1)*d.Parameters.SingleDefaultLWEDimension()]
pt += vec.Dot(ctMask, d.SingleKeyDecryptors[i].DefaultLWESecretKey().Value)
}
}
Expand All @@ -151,7 +151,7 @@ func (d *Decryptor[T]) DecryptGLWEAssign(ct GLWECiphertext[T], messagesOut []int

// DecryptGLWEPlaintext decrypts GLWE ciphertext to GLWE plaintext.
func (d *Decryptor[T]) DecryptGLWEPlaintext(ct GLWECiphertext[T]) tfhe.GLWEPlaintext[T] {
pt := tfhe.NewGLWEPlaintext(d.Parameters.Parameters)
pt := tfhe.NewGLWEPlaintext(d.Parameters.singleKeyParameters)
d.DecryptGLWEPlaintextAssign(ct, pt)
return pt
}
Expand Down Expand Up @@ -180,7 +180,7 @@ func (d *Decryptor[T]) DecryptFourierGLWEAssign(ct FourierGLWECiphertext[T], mes

// DecryptFourierGLWEPlaintext decrypts FourierGLWE ciphertext to GLWE plaintext.
func (d *Decryptor[T]) DecryptFourierGLWEPlaintext(ct FourierGLWECiphertext[T]) tfhe.GLWEPlaintext[T] {
ptOut := tfhe.NewGLWEPlaintext(d.Parameters.Parameters)
ptOut := tfhe.NewGLWEPlaintext(d.Parameters.singleKeyParameters)
d.DecryptFourierGLWEPlaintextAssign(ct, ptOut)
return ptOut
}
Expand Down
18 changes: 9 additions & 9 deletions mktfhe/encryptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ func NewEncryptor[T tfhe.TorusInt](params Parameters[T], idx int, crsSeed []byte
s.SamplePolyAssign(crs[i])
}

enc := tfhe.NewEncryptor(params.Parameters)
enc := tfhe.NewEncryptor(params.singleKeyParameters)

return &Encryptor[T]{
Encoder: tfhe.NewEncoder(params.Parameters),
Encoder: tfhe.NewEncoder(params.singleKeyParameters),
GLWETransformer: NewGLWETransformer(params),
SingleKeyEncryptor: enc,

Expand Down Expand Up @@ -96,9 +96,9 @@ func NewEncryptorWithKey[T tfhe.TorusInt](params Parameters[T], idx int, crsSeed
}

return &Encryptor[T]{
Encoder: tfhe.NewEncoder(params.Parameters),
Encoder: tfhe.NewEncoder(params.singleKeyParameters),
GLWETransformer: NewGLWETransformer(params),
SingleKeyEncryptor: tfhe.NewEncryptorWithKey(params.Parameters, sk),
SingleKeyEncryptor: tfhe.NewEncryptorWithKey(params.singleKeyParameters, sk),

Parameters: params,
Index: idx,
Expand All @@ -114,14 +114,14 @@ func NewEncryptorWithKey[T tfhe.TorusInt](params Parameters[T], idx int, crsSeed
// newEncryptionBuffer allocates an empty encryptionBuffer.
func newEncryptionBuffer[T tfhe.TorusInt](params Parameters[T]) encryptionBuffer[T] {
return encryptionBuffer[T]{
ptGLWE: tfhe.NewGLWEPlaintext(params.Parameters),
ptGLWE: tfhe.NewGLWEPlaintext(params.singleKeyParameters),
ctGLWE: NewGLWECiphertext(params),

auxKey: tfhe.NewGLWESecretKey(params.Parameters),
auxFourierKey: tfhe.NewFourierGLWESecretKey(params.Parameters),
auxKey: tfhe.NewGLWESecretKey(params.singleKeyParameters),
auxFourierKey: tfhe.NewFourierGLWESecretKey(params.singleKeyParameters),

ctLWESingle: tfhe.NewLWECiphertext(params.Parameters),
ctGLWESingle: tfhe.NewGLWECiphertext(params.Parameters),
ctLWESingle: tfhe.NewLWECiphertext(params.singleKeyParameters),
ctGLWESingle: tfhe.NewGLWECiphertext(params.singleKeyParameters),
}
}

Expand Down
Loading

0 comments on commit 4a9cb23

Please sign in to comment.