-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlwe128_test.go
62 lines (48 loc) · 1.2 KB
/
lwe128_test.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
package database
import (
"fmt"
"testing"
"time"
"github.com/si-co/vpir-code/lib/matrix"
"github.com/si-co/vpir-code/lib/utils"
)
func TestLWE(t *testing.T) {
rows, columns := 2048, 2048
fmt.Println(rows, columns)
b := make([]byte, rows*columns/8+1)
rnd := utils.RandomPRG()
if _, err := rnd.Read(b); err != nil {
panic("insufficient randomness")
}
fmt.Println("randomness generation ok")
m := matrix.NewBytes(rows, columns)
for i := 0; i < m.Len(); i++ {
val := (b[i/8] >> (i % 8)) & 1
if val >= plaintextModulus {
panic("Plaintext value too large")
}
m.SetData(i, val)
}
fmt.Println("db generation ok")
db := &LWE128{
Matrix: m,
Info: Info{
NumRows: rows,
NumColumns: columns,
BlockSize: blockSizeLWE,
},
}
fmt.Println("create random matrix A")
rm := matrix.NewRandom128(
utils.NewPRG(utils.ParamsDefault128().SeedA),
utils.ParamsDefault128().N,
rows)
fmt.Println("done with create random matrix A")
fmt.Println("start digest computation BinaryMul")
ti := time.Now()
d := matrix.BinaryMul128(rm, db.Matrix)
fmt.Println("done with digest computation in time:", time.Since(ti).Seconds())
db.Auth = &Auth{
Digest: matrix.Matrix128ToBytes(d),
}
}