Skip to content

Commit ad98d80

Browse files
author
zhdllwyc
committed
fmul
1 parent 60027e9 commit ad98d80

File tree

11 files changed

+215
-221
lines changed

11 files changed

+215
-221
lines changed

ot/simplestOT/simplestOT_test.go ot/simot/simot_test.go

+84-38
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
package simplestOT
1+
// Reference: https://eprint.iacr.org/2015/267.pdf (1 out of 2 OT case)
2+
// Sender has 2 messages m0, m1
3+
// Receiver receives mc based on the choice bit c
4+
5+
package simot
26

37
import (
48
"bytes"
@@ -8,15 +12,43 @@ import (
812
"github.com/cloudflare/circl/group"
913
)
1014

11-
const TestBaseOTCount = 100
15+
const testSimOTCount = 100
16+
17+
func simOT(myGroup group.Group, sender *SenderSimOT, receiver *ReceiverSimOT, m0, m1 []byte, choice, index int) error {
18+
// Initialization
19+
A := sender.InitSender(myGroup, m0, m1, index)
20+
21+
// Round 1
22+
// Sender sends A to receiver
23+
B := receiver.Round1Receiver(myGroup, choice, index, A)
24+
25+
// Round 2
26+
// Receiver sends B to sender
27+
e0, e1 := sender.Round2Sender(B)
28+
29+
// Round 3
30+
// Sender sends e0 e1 to receiver
31+
errDec := receiver.Round3Receiver(e0, e1, receiver.c)
32+
if errDec != nil {
33+
return errDec
34+
}
35+
36+
return nil
37+
}
1238

13-
func testNegativeBaseOT(t *testing.T, myGroup group.Group, choice int) {
39+
func testNegativeSimOT(t *testing.T, myGroup group.Group, choice int) {
1440
var sender SenderSimOT
1541
var receiver ReceiverSimOT
1642
m0 := make([]byte, myGroup.Params().ScalarLength)
1743
m1 := make([]byte, myGroup.Params().ScalarLength)
18-
rand.Read(m0)
19-
rand.Read(m1)
44+
_, errRand := rand.Read(m0)
45+
if errRand != nil {
46+
panic(errRand)
47+
}
48+
_, errRand = rand.Read(m1)
49+
if errRand != nil {
50+
panic(errRand)
51+
}
2052

2153
// Initialization
2254
A := sender.InitSender(myGroup, m0, m1, 0)
@@ -32,7 +64,7 @@ func testNegativeBaseOT(t *testing.T, myGroup group.Group, choice int) {
3264
// The receiver will not learn anything about m_{1-c}
3365
errDec := receiver.Round3Receiver(e0, e1, 1-choice)
3466
if errDec == nil {
35-
t.Error("BaseOT decryption failed", errDec)
67+
t.Error("SimOT decryption failed", errDec)
3668
}
3769

3870
if choice == 0 {
@@ -54,23 +86,29 @@ func testNegativeBaseOT(t *testing.T, myGroup group.Group, choice int) {
5486
t.Error("Receiver decryption should fail")
5587
}
5688
}
57-
5889
}
5990

6091
// Input: myGroup, the group we operate in
61-
func testBaseOT(t *testing.T, myGroup group.Group, choice int) {
92+
func testSimOT(t *testing.T, myGroup group.Group, choice int) {
6293
var sender SenderSimOT
6394
var receiver ReceiverSimOT
6495

6596
m0 := make([]byte, myGroup.Params().ScalarLength)
6697
m1 := make([]byte, myGroup.Params().ScalarLength)
67-
rand.Read(m0)
68-
rand.Read(m1)
69-
err := BaseOT(myGroup, &sender, &receiver, m0, m1, choice, 0)
70-
if err != nil {
71-
t.Error("BaseOT failed", err)
98+
_, errRand := rand.Read(m0)
99+
if errRand != nil {
100+
panic(errRand)
101+
}
102+
_, errRand = rand.Read(m1)
103+
if errRand != nil {
104+
panic(errRand)
105+
}
106+
107+
errDec := simOT(myGroup, &sender, &receiver, m0, m1, choice, 0)
108+
if errDec != nil {
109+
t.Error("AES GCM Decryption failed")
72110
}
73-
//Confirm
111+
74112
if choice == 0 {
75113
equal0 := bytes.Compare(sender.m0, receiver.mc)
76114
if equal0 != 0 {
@@ -84,29 +122,41 @@ func testBaseOT(t *testing.T, myGroup group.Group, choice int) {
84122
}
85123
}
86124

87-
func benchmarBaseOT(b *testing.B, myGroup group.Group) {
125+
func benchmarSimOT(b *testing.B, myGroup group.Group) {
88126
var sender SenderSimOT
89127
var receiver ReceiverSimOT
90128
m0 := make([]byte, myGroup.Params().ScalarLength)
91129
m1 := make([]byte, myGroup.Params().ScalarLength)
92-
rand.Read(m0)
93-
rand.Read(m1)
130+
_, errRand := rand.Read(m0)
131+
if errRand != nil {
132+
panic(errRand)
133+
}
134+
_, errRand = rand.Read(m1)
135+
if errRand != nil {
136+
panic(errRand)
137+
}
94138

95139
for iter := 0; iter < b.N; iter++ {
96-
err := BaseOT(myGroup, &sender, &receiver, m0, m1, iter%2, 0)
97-
if err != nil {
98-
b.Error("BaseOT failed")
140+
errDec := simOT(myGroup, &sender, &receiver, m0, m1, iter%2, 0)
141+
if errDec != nil {
142+
b.Error("AES GCM Decryption failed")
99143
}
100144
}
101145
}
102146

103-
func benchmarkBaseOTRound(b *testing.B, myGroup group.Group) {
147+
func benchmarkSimOTRound(b *testing.B, myGroup group.Group) {
104148
var sender SenderSimOT
105149
var receiver ReceiverSimOT
106150
m0 := make([]byte, myGroup.Params().ScalarLength)
107151
m1 := make([]byte, myGroup.Params().ScalarLength)
108-
rand.Read(m0)
109-
rand.Read(m1)
152+
_, errRand := rand.Read(m0)
153+
if errRand != nil {
154+
panic(errRand)
155+
}
156+
_, errRand = rand.Read(m1)
157+
if errRand != nil {
158+
panic(errRand)
159+
}
110160

111161
b.Run("Sender-Initialization", func(b *testing.B) {
112162
for i := 0; i < b.N; i++ {
@@ -127,7 +177,6 @@ func benchmarkBaseOTRound(b *testing.B, myGroup group.Group) {
127177
b.Run("Sender-Round2", func(b *testing.B) {
128178
for i := 0; i < b.N; i++ {
129179
sender.Round2Sender(B)
130-
131180
}
132181
})
133182

@@ -152,34 +201,31 @@ func benchmarkBaseOTRound(b *testing.B, myGroup group.Group) {
152201
if equal0 != 0 {
153202
b.Error("Receiver decryption failed")
154203
}
155-
156204
}
157205

158-
func TestBaseOT(t *testing.T) {
159-
160-
t.Run("BaseOT", func(t *testing.T) {
161-
for i := 0; i < TestBaseOTCount; i++ {
206+
func TestSimOT(t *testing.T) {
207+
t.Run("SimOT", func(t *testing.T) {
208+
for i := 0; i < testSimOTCount; i++ {
162209
currGroup := group.P256
163210
choice := i % 2
164-
testBaseOT(t, currGroup, choice)
211+
testSimOT(t, currGroup, choice)
165212
}
166213
})
167-
t.Run("BaseOTNegative", func(t *testing.T) {
168-
for i := 0; i < TestBaseOTCount; i++ {
214+
t.Run("SimOTNegative", func(t *testing.T) {
215+
for i := 0; i < testSimOTCount; i++ {
169216
currGroup := group.P256
170217
choice := i % 2
171-
testNegativeBaseOT(t, currGroup, choice)
218+
testNegativeSimOT(t, currGroup, choice)
172219
}
173220
})
174-
175221
}
176222

177-
func BenchmarkBaseOT(b *testing.B) {
223+
func BenchmarkSimOT(b *testing.B) {
178224
currGroup := group.P256
179-
benchmarBaseOT(b, currGroup)
225+
benchmarSimOT(b, currGroup)
180226
}
181227

182-
func BenchmarkBaseOTRound(b *testing.B) {
228+
func BenchmarkSimOTRound(b *testing.B) {
183229
currGroup := group.P256
184-
benchmarkBaseOTRound(b, currGroup)
230+
benchmarkSimOTRound(b, currGroup)
185231
}

ot/simplestOT/simplestOTLocal.go ot/simot/simotlocal.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package simplestOT
1+
package simot
22

33
import (
44
"crypto/aes"
@@ -66,7 +66,7 @@ func aesDecGCM(key, ciphertext []byte) ([]byte, error) {
6666

6767
// Input: myGroup, the group we operate in
6868
// Input: m0, m1 the 2 message of the sender
69-
// Input: index, the index of this BaseOT
69+
// Input: index, the index of this SimOT
7070
// Output: A = [a]G, a the sender randomness
7171
func (sender *SenderSimOT) InitSender(myGroup group.Group, m0, m1 []byte, index int) group.Element {
7272
sender.a = myGroup.RandomNonZeroScalar(rand.Reader)
@@ -87,7 +87,7 @@ func (sender *SenderSimOT) InitSender(myGroup group.Group, m0, m1 []byte, index
8787

8888
// Input: myGroup, the group we operate in
8989
// Input: choice, the receiver choice bit
90-
// Input: index, the index of this BaseOT
90+
// Input: index, the index of this SimOT
9191
// Input: A, from sender
9292
// Output: B = [b]G if c == 0, B = A+[b]G if c == 1 (Implementation in constant time). b, the receiver randomness
9393
func (receiver *ReceiverSimOT) Round1Receiver(myGroup group.Group, choice int, index int, A group.Element) group.Element {

ot/simplestOT/simplestOTParty.go ot/simot/simotparty.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package simplestOT
1+
package simot
22

33
import "github.com/cloudflare/circl/group"
44

ot/simplestOT/simplestOT.go

-36
This file was deleted.

0 commit comments

Comments
 (0)