forked from tuneinsight/lattigo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
46 lines (39 loc) · 1.57 KB
/
utils.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
41
42
43
44
45
46
package dckks
import (
"math"
"math/bits"
"github.com/jzhchu/lattigo/ckks"
"github.com/jzhchu/lattigo/ring"
"github.com/jzhchu/lattigo/rlwe"
)
// GetMinimumLevelForBootstrapping takes the security parameter lambda, the ciphertext scale, the number of parties and the moduli chain
// and returns the minimum level at which the collective refresh can be called with a security of at least 128-bits.
// It returns 3 parameters :
// minLevel : the minimum level at which the collective refresh must be called to ensure correctness
// logBound : the bit length of the masks to be sampled to mask the plaintext and ensure 128-bits of statistical indistinguishability
// ok : a boolean flag, which is set to false if no such instance exist
func GetMinimumLevelForBootstrapping(lambda int, scale rlwe.Scale, nParties int, moduli []uint64) (minLevel int, logBound uint, ok bool) {
logBound = uint(lambda + int(math.Ceil(math.Log2(scale.Float64()))))
maxBound := int(logBound) + bits.Len64(uint64(nParties))
minLevel = -1
logQ := 0
for i := 0; logQ < maxBound; i++ {
if i >= len(moduli) {
return 0, 0, false
}
logQ += bits.Len64(moduli[i])
minLevel++
}
if len(moduli) < minLevel {
return 0, 0, false
}
return minLevel, logBound, true
}
// NewAdditiveShareBigint instantiates a new additive share struct composed of "n" big.Int elements
func NewAdditiveShareBigint(params ckks.Parameters, logSlots int) *rlwe.AdditiveShareBigint {
dslots := 1 << logSlots
if params.RingType() == ring.Standard {
dslots *= 2
}
return rlwe.NewAdditiveShareBigint(params.Parameters, dslots)
}