forked from Anonymous-000/RingCT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Basic_test.go
113 lines (95 loc) · 2.68 KB
/
Basic_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"fmt"
"github.com/dedis/lago/bigint"
"github.com/dedis/lago/polynomial"
"github.com/dedis/lago/ring"
"testing"
)
func setTestSettings() {
d := uint32(64)
n := uint32(32)
m := uint32(64)
w := uint32(56)
//q := bigint.NewIntFromString("8865920799731713") // polynomial.GenerateNTTParams(d, q) never return, may due to factorization
//q := bigint.NewIntFromString("2147221513") // Not NTT friendly (N != 1 mod 2*d)
//q := bigint.NewIntFromString("257") // Fermat number (F3)
q := bigint.NewIntFromString("65537") // Fermat number (F4) (no big performance difference with F3)
SetSettings(d, n, m, w, 64, *q, 8, 1, false)
}
func TestHash(t *testing.T) {
setTestSettings()
r1 := new(ring.Ring)
r1.N = settings.d
r1.Q = settings.q
r1.Poly, _ = polynomial.NewPolynomial(settings.d, settings.q, nil)
r2 := new(ring.Ring)
r2, err := ring.CopyRing(r1)
if err != nil {
t.Errorf("Error: [TestHash] %s", err)
return
}
msg := make([]byte, 2)
msg[0] = 'M'
msg[1] = 'G'
Hash(msg, r1)
Hash(msg, r2)
cor1 := r1.Poly.GetCoefficients()
cor2 := r1.Poly.GetCoefficients()
for i := range cor1 {
if !cor1[i].EqualTo(&cor2[i]) {
t.Errorf("FAIL: [TestHash] Hashed values are not same: cor1[%v]: %v, cor2[%v]: %v.", i, cor1[i], i, cor2[i])
return
}
}
}
func TestMint(t *testing.T) {
setTestSettings()
amt := uint64(5)
coeffs := make([]bigint.Int, settings.d)
coeffs[0].SetInt(int64(1))
v := settings.precision + settings.m
bits, _ := ConvertIntToRingBits(amt, settings.d, settings.precision, settings.q, settings.nttParams)
G, _ := SamMat(v, 0)
B, r, mbits, _ := Mint(G, amt)
y, _ := ring.CopyRing(&G.ringvectors[0].rings[0])
_ = y.Poly.SetCoefficients(coeffs)
if !Open(G, B, bits, r, y) {
t.Errorf("FAIL: [TestMint] Open failed.")
return
}
if !mbits.RingMatIsEqual(bits) {
t.Errorf("FAIL: [TestMint] randoms are different.")
return
}
}
func TestGenerateDelta(t *testing.T) {
setTestSettings()
v := MakeDeltaMatrix(7, 2, 3)
for i := range v {
fmt.Printf("--- delta_%v ---\n", i)
v[i].ShowMatrix(settings.d)
}
}
func TestMakePij(t *testing.T) {
setTestSettings()
r := new(ring.Ring)
r.N = settings.d
r.Q = settings.q
r.Poly, _ = polynomial.NewPolynomial(settings.d, settings.q, settings.nttParams)
coeffs := make([]bigint.Int, settings.d)
a := make([]ring.Ring, 3)
delta := make([]ring.Ring, 3)
for i := range a {
coeffs[0].SetInt(int64(i + 1))
tmpring, _ := ring.CopyRing(r)
_ = tmpring.Poly.SetCoefficients(coeffs)
a[i] = *tmpring
coeffs[0].SetInt(int64(i + 2))
tmpring2, _ := ring.CopyRing(r)
_ = tmpring2.Poly.SetCoefficients(coeffs)
delta[i] = *tmpring2
}
piv := MakePij(a, delta)
ShowRingVector(piv, settings.d)
}