-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlwe128_test.go
41 lines (34 loc) · 1.16 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
package main
import (
"fmt"
"math/rand"
"testing"
"time"
"github.com/si-co/vpir-code/lib/client"
"github.com/si-co/vpir-code/lib/database"
"github.com/si-co/vpir-code/lib/server"
"github.com/si-co/vpir-code/lib/utils"
"github.com/stretchr/testify/require"
)
func TestLWE128(t *testing.T) {
dbLen := 1024 * 1024 // dbLen is specified in bits
db := database.CreateRandomBinaryLWEWithLength128(utils.RandomPRG(), dbLen)
p := utils.ParamsWithDatabaseSize128(db.Info.NumRows, db.Info.NumColumns)
retrieveBlocksLWE128(t, db, p, "TestLWE128")
}
func retrieveBlocksLWE128(t *testing.T, db *database.LWE128, params *utils.ParamsLWE, testName string) {
c := client.NewLWE128(utils.RandomPRG(), &db.Info, params)
s := server.NewLWE128(db)
ti := time.Now()
for j := 0; j < 100; j++ {
i := rand.Intn(params.L * params.M)
query, err := c.QueryBytes(i)
require.NoError(t, err)
a, err := s.AnswerBytes(query)
require.NoError(t, err)
res, err := c.ReconstructBytes(a)
require.NoError(t, err)
require.Equal(t, uint32(db.Matrix.Get(utils.VectorToMatrixIndices(i, db.Info.NumColumns))), res)
}
fmt.Printf("Total time %s: %.1fs\n", testName, time.Since(ti).Seconds())
}