-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathrsa_test.go
79 lines (67 loc) · 1.28 KB
/
rsa_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
//
// rsa_test.go
//
// Copyright (c) 2019-2023 Markku Rossi
//
// All rights reserved.
//
package ot
import (
"bytes"
"crypto/rand"
"testing"
)
func benchmark(b *testing.B, keySize int) {
l0, _ := NewLabel(rand.Reader)
l1, _ := NewLabel(rand.Reader)
sender, err := NewSender(keySize)
if err != nil {
b.Fatal(err)
}
receiver, err := NewReceiver(sender.PublicKey())
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
var l0Buf, l1Buf LabelData
for i := 0; i < b.N; i++ {
l0Data := l0.Bytes(&l0Buf)
l1Data := l1.Bytes(&l1Buf)
sXfer, err := sender.NewTransfer(l0Data, l1Data)
if err != nil {
b.Fatal(err)
}
rXfer, err := receiver.NewTransfer(1)
if err != nil {
b.Fatal(err)
}
err = rXfer.ReceiveRandomMessages(sXfer.RandomMessages())
if err != nil {
b.Fatal(err)
}
sXfer.ReceiveV(rXfer.V())
err = rXfer.ReceiveMessages(sXfer.Messages())
if err != nil {
b.Fatal(err)
}
m, bit := rXfer.Message()
var ret int
if bit == 0 {
ret = bytes.Compare(l0Data[:], m)
} else {
ret = bytes.Compare(l1Data[:], m)
}
if ret != 0 {
b.Fatal("Verify failed!\n")
}
}
}
func BenchmarkRSA512(b *testing.B) {
benchmark(b, 512)
}
func BenchmarkRSA1024(b *testing.B) {
benchmark(b, 1024)
}
func BenchmarkRSA2048(b *testing.B) {
benchmark(b, 2048)
}