-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdh_test.go
47 lines (39 loc) · 1.2 KB
/
dh_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
package main
// Test suite for the single-server VPIR scheme
import (
"fmt"
"io"
"math/rand"
"testing"
"github.com/cloudflare/circl/group"
"github.com/si-co/vpir-code/lib/client"
"github.com/si-co/vpir-code/lib/database"
"github.com/si-co/vpir-code/lib/monitor"
"github.com/si-co/vpir-code/lib/server"
"github.com/si-co/vpir-code/lib/utils"
"github.com/stretchr/testify/require"
)
func TestDH(t *testing.T) {
dbLen := 1024 * 1024 // dbLen is specified in bits
dbPRG := utils.RandomPRG()
ecg := group.P256
db := database.CreateRandomEllipticWithDigest(dbPRG, dbLen, ecg, true)
prg := utils.RandomPRG()
retrieveBlocksDH(t, prg, db, "Diffie-Hellman")
}
func retrieveBlocksDH(t *testing.T, rnd io.Reader, db *database.Elliptic, testName string) {
c := client.NewDH(rnd, &db.Info)
s := server.NewDH(db)
totalTimer := monitor.NewMonitor()
for j := 0; j < 10; j++ {
i := rand.Intn(db.NumRows * db.NumColumns)
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, db.Entries[i], res)
}
fmt.Printf("Total CPU time %s: %.1fms\n", testName, totalTimer.Record())
}