-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbarrett_test.go
127 lines (105 loc) · 3.77 KB
/
barrett_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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package ed448
import . "gopkg.in/check.v1"
func (s *Ed448Suite) Test_BarrettDeserializeAndReduce(c *C) {
serialized := [64]byte{
0x1d, 0x07, 0xfb, 0x9c, 0x79, 0x80, 0x5f, 0x01,
0x52, 0xc9, 0x09, 0xbf, 0x4c, 0xdb, 0xb1, 0x31,
0x95, 0x31, 0x78, 0xc9, 0xff, 0x4f, 0x34, 0xc7,
0x77, 0x7c, 0x89, 0x4e, 0xe0, 0x8f, 0xca, 0x9f,
0x59, 0x8a, 0x00, 0x37, 0x78, 0x2c, 0xa6, 0x9b,
0xbe, 0x5b, 0xb4, 0x1d, 0x25, 0x6a, 0x83, 0x32,
0x7c, 0xd0, 0xc0, 0x3d, 0xa5, 0x26, 0xf8, 0x77,
0xd3, 0x74, 0x3e, 0x3b, 0x7b, 0x21, 0x70, 0x01,
}
result := scalar{}
barrettDeserializeAndReduce(result[:], serialized[:], &curvePrimeOrder)
c.Assert(result, DeepEquals, scalar{
0x3e3f0106, 0x109e3fb3, 0x2334dede, 0x44759a6a,
0x4f184169, 0x5052b779, 0xe27da003, 0x8a15ee89,
0x39f344af, 0x9ba62c78, 0x1db45bbe, 0x32836a25,
0x3dc0d07c, 0x37f826a5,
})
}
func (s *Ed448Suite) Test_BarrettDeserialize(c *C) {
//This is not reduced
serialized := [fieldBytes]byte{
0xfe, 0x58, 0x5b, 0x65, 0x91, 0x38, 0x65, 0x18,
0x9d, 0xfe, 0x90, 0x33, 0x48, 0xbe, 0xac, 0x47,
0xee, 0x65, 0x09, 0x28, 0xde, 0xe5, 0x04, 0x05,
0xd9, 0xa6, 0xd4, 0x43, 0x54, 0x18, 0xa2, 0xfd,
0xf1, 0xf2, 0x64, 0xee, 0xae, 0xae, 0xc5, 0xe7,
0x68, 0xa4, 0x2e, 0xde, 0x76, 0x60, 0xe6, 0x4a,
0x51, 0x12, 0xb1, 0x35, 0x3d, 0xac, 0x04, 0xc8,
}
result := scalar{}
reduced := barrettDeserialize(result[:], serialized[:], &curvePrimeOrder)
c.Assert(reduced, Equals, false)
c.Assert(result, DeepEquals, scalar{
0x655b58fe, 0x18653891, 0x3390fe9d, 0x47acbe48,
0x280965ee, 0x0504e5de, 0x43d4a6d9, 0xfda21854,
0xee64f2f1, 0xe7c5aeae, 0xde2ea468, 0x4ae66076,
0x35b11251, 0xc804ac3d,
})
//This is already reduced prime-order
serialized = [fieldBytes]byte{
0x25, 0x8a, 0x52, 0x63, 0xd9, 0xf0, 0xfa, 0xad,
0x9d, 0x50, 0x40, 0x8a, 0xf0, 0x76, 0x66, 0xe3,
0x3d, 0xc2, 0x86, 0x1b, 0x01, 0x54, 0x18, 0xb8,
0x1b, 0x3b, 0x76, 0xcd, 0x55, 0x18, 0xa2, 0xfd,
0xf1, 0xf2, 0x64, 0xee, 0xae, 0xae, 0xc5, 0xe7,
0x68, 0xa4, 0x2e, 0xde, 0x76, 0x60, 0xe6, 0x4a,
0x51, 0x12, 0xb1, 0x35, 0x3d, 0xac, 0x04, 0x08,
}
reduced = barrettDeserialize(result[:], serialized[:], &curvePrimeOrder)
c.Assert(reduced, Equals, true)
c.Assert(result, DeepEquals, scalar{
0x63528a25, 0xadfaf0d9, 0x8a40509d, 0xe36676f0,
0x1b86c23d, 0xb8185401, 0xcd763b1b, 0xfda21855,
0xee64f2f1, 0xe7c5aeae, 0xde2ea468, 0x4ae66076,
0x35b11251, 0x0804ac3d,
})
}
func (s *Ed448Suite) Test_BarrettNegate(c *C) {
n := scalar{
0x6c226d73, 0x70edcfc3, 0x44156c47, 0x84f4695,
0xe72606ac, 0x9d0ce5e5, 0xed96d3ba, 0x9ff3fa11,
0x4a15c383, 0xca38a0af, 0xead789b3, 0xb96613ba,
0x48ba4461, 0x34eb2031,
}
notN := scalar{
0x3f35d780, 0xb28af2cf, 0x49b0230d, 0x191d7bdd,
0xc7b02fe4, 0x2741f563, 0x8f33502f, 0x600c05ed,
0xb5ea3c7c, 0x35c75f50, 0x1528764c, 0x4699ec45,
0xb745bb9e, 0x0b14dfce,
}
barrettNegate(n[:], &curvePrimeOrder)
c.Assert(n, DeepEquals, notN)
}
func (s *Ed448Suite) Test_BarrettMac(c *C) {
accum := scalar{
0xc7a99dbd, 0xb92054cc, 0x79b10a3e, 0x38afe6b9,
0x859aa259, 0x007e0791, 0x91958009, 0x1ed45cd0,
0xbbfa381b, 0x1f427b27, 0xb194eb5c, 0x501789df,
0x1616d689, 0x17db93b0,
}
x := scalar{
0x3f35d780, 0xb28af2cf, 0x49b0230d, 0x191d7bdd,
0xc7b02fe4, 0x2741f563, 0x8f33502f, 0x600c05ed,
0xb5ea3c7c, 0x35c75f50, 0x1528764c, 0x4699ec45,
0xb745bb9e, 0x0b14dfce,
}
y := scalar{
0x2efd441f, 0xa8ca47de, 0x88454c7c, 0x5a017e1a,
0xfb3701a9, 0xe0b9be0d, 0xf72947eb, 0x235c0b74,
0x39fdaa66, 0x80783803, 0x1306b28f, 0x02cffb4e,
0x3a114311, 0x22b8f8d1,
}
expected := scalar{
0x908c5c63, 0x21ab566a, 0x936bf39e, 0xa2c8ba5b,
0xf885f518, 0xc1f2945d, 0x5cb06b4a, 0xe86d3f14,
0xdd6bfcd0, 0x74fadd00, 0x4a750a8c, 0x8962c665,
0x18163b75, 0x1de81b1f,
}
barrettMac(accum[:], x[:], y[:], &curvePrimeOrder)
c.Assert(accum, DeepEquals, expected)
}