-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlwe.go
68 lines (54 loc) · 1.36 KB
/
lwe.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package utils
import (
"crypto/aes"
"math"
)
// WARNING: DO NOT USE THESE KEYS IN PRODUCTION!
var SeedMatrixA = [aes.BlockSize]byte{19, 177, 222, 148, 155, 239, 159, 227, 155, 99, 246, 214, 220, 162, 30, 66}
type ParamsLWE struct {
P uint32 // plaintext modulus
N int // lattice/secret dimension
Sigma float64 // Error parameter
L int // number of rows of database
M int // number of columns of database
B uint32 // bound used in reconstruction
SeedA *PRGKey // matrix used to generate digest
BytesMod int // bytes of the modulo
}
func ParamsDefault() *ParamsLWE {
return &ParamsLWE{
P: 2,
N: 1100,
Sigma: 6.4,
SeedA: GetDefaultSeedMatrixA(),
BytesMod: 4,
}
}
func ParamsWithDatabaseSize(rows, columns int) *ParamsLWE {
p := ParamsDefault()
p.L = rows
p.M = columns
p.B = computeB(rows, p.Sigma)
return p
}
func GetDefaultSeedMatrixA() *PRGKey {
key := PRGKey(SeedMatrixA)
return &key
}
func ParamsDefault128() *ParamsLWE {
p := ParamsDefault()
p.N = 4800
p.BytesMod = 16
return p
}
func ParamsWithDatabaseSize128(rows, columns int) *ParamsLWE {
p := ParamsDefault128()
p.L = rows
p.M = columns
p.B = computeB(rows, p.Sigma)
return p
}
func computeB(rows int, sigma float64) uint32 {
// rows is equal to sqrt(dbSize), 12 is ~ sqrt(128)
return uint32(rows * 12 * int(math.Ceil(sigma)))
}