-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathenc_test.go
91 lines (74 loc) · 1.66 KB
/
enc_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
//
// enc_test.go
//
// Copyright (c) 2019-2023 Markku Rossi
//
// All rights reserved.
//
package circuit
import (
"crypto/aes"
"crypto/rand"
"testing"
"github.com/markkurossi/mpc/ot"
)
func TestEnc(t *testing.T) {
a, _ := ot.NewLabel(rand.Reader)
b, _ := ot.NewLabel(rand.Reader)
c, _ := ot.NewLabel(rand.Reader)
tweak := uint32(42)
var key [32]byte
cipher, err := aes.NewCipher(key[:])
if err != nil {
t.Fatalf("Failed to create cipher: %s", err)
}
var data ot.LabelData
encrypted := encrypt(cipher, a, b, c, tweak, &data)
if err != nil {
t.Fatalf("Encrypt failed: %s", err)
}
plain := decrypt(cipher, a, b, tweak, encrypted, &data)
if !c.Equal(plain) {
t.Fatalf("Encrypt-decrypt failed")
}
}
func BenchmarkEnc(b *testing.B) {
var key [32]byte
cipher, err := aes.NewCipher(key[:])
if err != nil {
b.Fatalf("Failed to create cipher: %s", err)
}
al, err := ot.NewLabel(rand.Reader)
if err != nil {
b.Fatalf("Failed to create label: %s", err)
}
bl, err := ot.NewLabel(rand.Reader)
if err != nil {
b.Fatalf("Failed to create label: %s", err)
}
cl, err := ot.NewLabel(rand.Reader)
if err != nil {
b.Fatalf("Failed to create label: %s", err)
}
b.ResetTimer()
var data ot.LabelData
for i := 0; i < b.N; i++ {
encrypt(cipher, al, bl, cl, uint32(i), &data)
}
}
func BenchmarkEncHalf(b *testing.B) {
var key [32]byte
cipher, err := aes.NewCipher(key[:])
if err != nil {
b.Fatalf("Failed to create cipher: %s", err)
}
xl, err := ot.NewLabel(rand.Reader)
if err != nil {
b.Fatalf("Failed to create label: %s", err)
}
b.ResetTimer()
var data ot.LabelData
for i := 0; i < b.N; i++ {
encryptHalf(cipher, xl, uint32(i), &data)
}
}