forked from tuneinsight/lattigo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
polynomial_evaluator_sim.go
40 lines (31 loc) · 1.05 KB
/
polynomial_evaluator_sim.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package he
import (
"github.com/tuneinsight/lattigo/v5/core/rlwe"
)
// SimOperand is a dummy operand that
// only stores its level and scale.
type SimOperand struct {
Level int
Scale rlwe.Scale
}
// SimEvaluator defines a set of method on SimOperands.
type SimEvaluator interface {
MulNew(op0, op1 *SimOperand) *SimOperand
Rescale(op0 *SimOperand)
PolynomialDepth(degree int) int
UpdateLevelAndScaleGiantStep(lead bool, tLevelOld int, tScaleOld, xPowScale rlwe.Scale) (tLevelNew int, tScaleNew rlwe.Scale)
UpdateLevelAndScaleBabyStep(lead bool, tLevelOld int, tScaleOld rlwe.Scale) (tLevelNew int, tScaleNew rlwe.Scale)
}
// SimPowerBasis is a map storing powers of SimOperands indexed by their power.
type SimPowerBasis map[int]*SimOperand
// GenPower populates the target SimPowerBasis with the nth power.
func (d SimPowerBasis) GenPower(params rlwe.ParameterProvider, n int, eval SimEvaluator) {
if n < 2 {
return
}
a, b := SplitDegree(n)
d.GenPower(params, a, eval)
d.GenPower(params, b, eval)
d[n] = eval.MulNew(d[a], d[b])
eval.Rescale(d[n])
}