Skip to content

Commit

Permalink
feat: Add Permute GLWE/FourierGLWE ops
Browse files Browse the repository at this point in the history
  • Loading branch information
sp301415 committed Oct 8, 2024
1 parent 39eb9b9 commit eb5a8f3
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 0 deletions.
47 changes: 47 additions & 0 deletions mktfhe/fourier_glwe_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,50 @@ func (e *Evaluator[T]) FourierPolyMulSubFourierGLWEAssign(ct0 FourierGLWECiphert
e.PolyEvaluator.MulSubFourierPolyAssign(ct0.Value[i], fp, ctOut.Value[i])
}
}

// PermuteGLWEAssign computes ctOut = ct0(X^d).
//
// ct0 and ctOut should not overlap. For inplace permutation,
// use [*Evaluator.PermuteFourierGLWEInPlace].
//
// Panics when d is not odd.
// This is because the permutation is not bijective when d is even.
func (e *Evaluator[T]) PermuteFourierGLWEAssign(ct0 FourierGLWECiphertext[T], d int, ctOut FourierGLWECiphertext[T]) {
for i := 0; i < e.Parameters.GLWERank()+1; i++ {
e.PolyEvaluator.PermuteFourierPolyAssign(ct0.Value[i], d, ctOut.Value[i])
}
}

// PermuteGLWEInPlace computes ct0 = ct0(X^d).
//
// Panics when d is not odd.
// This is because the permutation is not bijective when d is even.
func (e *Evaluator[T]) PermuteFourierGLWEInPlace(ct0 FourierGLWECiphertext[T], d int) {
for i := 0; i < e.Parameters.GLWERank()+1; i++ {
e.PolyEvaluator.PermuteFourierPolyInPlace(ct0.Value[i], d)
}
}

// PermuteAddGLWEAssign computes ctOut += ct0(X^d).
//
// ct0 and ctOut should not overlap.
//
// Panics when d is not odd.
// This is because the permutation is not bijective when d is even.
func (e *Evaluator[T]) PermuteAddFourierGLWEAssign(ct0 FourierGLWECiphertext[T], d int, ctOut FourierGLWECiphertext[T]) {
for i := 0; i < e.Parameters.GLWERank()+1; i++ {
e.PolyEvaluator.PermuteAddFourierPolyAssign(ct0.Value[i], d, ctOut.Value[i])
}
}

// PermuteSubGLWEAssign computes ctOut -= ct0(X^d).
//
// ct0 and ctOut should not overlap.
//
// Panics when d is not odd.
// This is because the permutation is not bijective when d is even.
func (e *Evaluator[T]) PermuteSubFourierGLWEAssign(ct0 FourierGLWECiphertext[T], d int, ctOut FourierGLWECiphertext[T]) {
for i := 0; i < e.Parameters.GLWERank()+1; i++ {
e.PolyEvaluator.PermuteSubFourierPolyAssign(ct0.Value[i], d, ctOut.Value[i])
}
}
47 changes: 47 additions & 0 deletions mktfhe/glwe_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,50 @@ func (e *Evaluator[T]) MonomialMulSubGLWEAssign(ct0 GLWECiphertext[T], d int, ct
e.BaseSingleKeyEvaluator.PolyEvaluator.MonomialMulSubPolyAssign(ct0.Value[i], d, ctOut.Value[i])
}
}

// PermuteGLWEAssign computes ctOut = ct0(X^d).
//
// ct0 and ctOut should not overlap. For inplace permutation,
// use [*Evaluator.PermuteGLWEInPlace].
//
// Panics when d is not odd.
// This is because the permutation is not bijective when d is even.
func (e *Evaluator[T]) PermuteGLWEAssign(ct0 GLWECiphertext[T], d int, ctOut GLWECiphertext[T]) {
for i := 0; i < e.Parameters.GLWERank()+1; i++ {
e.PolyEvaluator.PermutePolyAssign(ct0.Value[i], d, ctOut.Value[i])
}
}

// PermuteGLWEInPlace computes ct0 = ct0(X^d).
//
// Panics when d is not odd.
// This is because the permutation is not bijective when d is even.
func (e *Evaluator[T]) PermuteGLWEInPlace(ct0 GLWECiphertext[T], d int) {
for i := 0; i < e.Parameters.GLWERank()+1; i++ {
e.PolyEvaluator.PermutePolyInPlace(ct0.Value[i], d)
}
}

// PermuteAddGLWEAssign computes ctOut += ct0(X^d).
//
// ct0 and ctOut should not overlap.
//
// Panics when d is not odd.
// This is because the permutation is not bijective when d is even.
func (e *Evaluator[T]) PermuteAddGLWEAssign(ct0 GLWECiphertext[T], d int, ctOut GLWECiphertext[T]) {
for i := 0; i < e.Parameters.GLWERank()+1; i++ {
e.PolyEvaluator.PermuteAddPolyAssign(ct0.Value[i], d, ctOut.Value[i])
}
}

// PermuteSubGLWEAssign computes ctOut -= ct0(X^d).
//
// ct0 and ctOut should not overlap.
//
// Panics when d is not odd.
// This is because the permutation is not bijective when d is even.
func (e *Evaluator[T]) PermuteSubGLWEAssign(ct0 GLWECiphertext[T], d int, ctOut GLWECiphertext[T]) {
for i := 0; i < e.Parameters.GLWERank()+1; i++ {
e.PolyEvaluator.PermuteSubPolyAssign(ct0.Value[i], d, ctOut.Value[i])
}
}
47 changes: 47 additions & 0 deletions tfhe/fourier_glwe_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,50 @@ func (e *Evaluator[T]) FourierPolyMulSubFourierGLWEAssign(ct0 FourierGLWECiphert
e.PolyEvaluator.MulSubFourierPolyAssign(ct0.Value[i], fp, ctOut.Value[i])
}
}

// PermuteGLWEAssign computes ctOut = ct0(X^d).
//
// ct0 and ctOut should not overlap. For inplace permutation,
// use [*Evaluator.PermuteFourierGLWEInPlace].
//
// Panics when d is not odd.
// This is because the permutation is not bijective when d is even.
func (e *Evaluator[T]) PermuteFourierGLWEAssign(ct0 FourierGLWECiphertext[T], d int, ctOut FourierGLWECiphertext[T]) {
for i := 0; i < e.Parameters.glweRank+1; i++ {
e.PolyEvaluator.PermuteFourierPolyAssign(ct0.Value[i], d, ctOut.Value[i])
}
}

// PermuteGLWEInPlace computes ct0 = ct0(X^d).
//
// Panics when d is not odd.
// This is because the permutation is not bijective when d is even.
func (e *Evaluator[T]) PermuteFourierGLWEInPlace(ct0 FourierGLWECiphertext[T], d int) {
for i := 0; i < e.Parameters.glweRank+1; i++ {
e.PolyEvaluator.PermuteFourierPolyInPlace(ct0.Value[i], d)
}
}

// PermuteAddGLWEAssign computes ctOut += ct0(X^d).
//
// ct0 and ctOut should not overlap.
//
// Panics when d is not odd.
// This is because the permutation is not bijective when d is even.
func (e *Evaluator[T]) PermuteAddFourierGLWEAssign(ct0 FourierGLWECiphertext[T], d int, ctOut FourierGLWECiphertext[T]) {
for i := 0; i < e.Parameters.glweRank+1; i++ {
e.PolyEvaluator.PermuteAddFourierPolyAssign(ct0.Value[i], d, ctOut.Value[i])
}
}

// PermuteSubGLWEAssign computes ctOut -= ct0(X^d).
//
// ct0 and ctOut should not overlap.
//
// Panics when d is not odd.
// This is because the permutation is not bijective when d is even.
func (e *Evaluator[T]) PermuteSubFourierGLWEAssign(ct0 FourierGLWECiphertext[T], d int, ctOut FourierGLWECiphertext[T]) {
for i := 0; i < e.Parameters.glweRank+1; i++ {
e.PolyEvaluator.PermuteSubFourierPolyAssign(ct0.Value[i], d, ctOut.Value[i])
}
}
12 changes: 12 additions & 0 deletions tfhe/glwe_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,19 @@ func (e *Evaluator[T]) PermuteGLWE(ct0 GLWECiphertext[T], d int) GLWECiphertext[
//
// ct0 and ctOut should not overlap. For inplace permutation,
// use [*Evaluator.PermuteGLWEInPlace].
//
// Panics when d is not odd.
// This is because the permutation is not bijective when d is even.
func (e *Evaluator[T]) PermuteGLWEAssign(ct0 GLWECiphertext[T], d int, ctOut GLWECiphertext[T]) {
for i := 0; i < e.Parameters.glweRank+1; i++ {
e.PolyEvaluator.PermutePolyAssign(ct0.Value[i], d, ctOut.Value[i])
}
}

// PermuteGLWEInPlace computes ct0 = ct0(X^d).
//
// Panics when d is not odd.
// This is because the permutation is not bijective when d is even.
func (e *Evaluator[T]) PermuteGLWEInPlace(ct0 GLWECiphertext[T], d int) {
for i := 0; i < e.Parameters.glweRank+1; i++ {
e.PolyEvaluator.PermutePolyInPlace(ct0.Value[i], d)
Expand All @@ -229,6 +235,9 @@ func (e *Evaluator[T]) PermuteGLWEInPlace(ct0 GLWECiphertext[T], d int) {
// PermuteAddGLWEAssign computes ctOut += ct0(X^d).
//
// ct0 and ctOut should not overlap.
//
// Panics when d is not odd.
// This is because the permutation is not bijective when d is even.
func (e *Evaluator[T]) PermuteAddGLWEAssign(ct0 GLWECiphertext[T], d int, ctOut GLWECiphertext[T]) {
for i := 0; i < e.Parameters.glweRank+1; i++ {
e.PolyEvaluator.PermuteAddPolyAssign(ct0.Value[i], d, ctOut.Value[i])
Expand All @@ -238,6 +247,9 @@ func (e *Evaluator[T]) PermuteAddGLWEAssign(ct0 GLWECiphertext[T], d int, ctOut
// PermuteSubGLWEAssign computes ctOut -= ct0(X^d).
//
// ct0 and ctOut should not overlap.
//
// Panics when d is not odd.
// This is because the permutation is not bijective when d is even.
func (e *Evaluator[T]) PermuteSubGLWEAssign(ct0 GLWECiphertext[T], d int, ctOut GLWECiphertext[T]) {
for i := 0; i < e.Parameters.glweRank+1; i++ {
e.PolyEvaluator.PermuteSubPolyAssign(ct0.Value[i], d, ctOut.Value[i])
Expand Down

0 comments on commit eb5a8f3

Please sign in to comment.