-
Notifications
You must be signed in to change notification settings - Fork 7
/
x448_test.go
139 lines (121 loc) · 4.38 KB
/
x448_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
128
129
130
131
132
133
134
135
136
137
138
139
package ed448
import (
. "gopkg.in/check.v1"
)
func (s *Ed448Suite) Test_X448LikeEncode(c *C) {
p := &twExtendedPoint{
&bigNumber{
0x018166b1, 0x0fe93d93, 0x00d79a2c, 0x014dd363,
0x0d54c7c7, 0x0b58136d, 0x06d53e0e, 0x07876411,
0x030393c3, 0x0d864d61, 0x03f018f4, 0x0e0189dc,
0x04b616a0, 0x0fee0689, 0x0de20cbd, 0x0bff248f,
},
&bigNumber{
0x0e8b04f9, 0x0a5a7d5c, 0x090933be, 0x0c76ba8f,
0x0a9b1072, 0x06689843, 0x03e8a130, 0x05745a67,
0x0020fc90, 0x01a6873c, 0x03ff7b4a, 0x072948b7,
0x0ce6b98c, 0x00dbdbcc, 0x045a0e2f, 0x02cbc9bd,
},
&bigNumber{
0x0fef77ee, 0x01703001, 0x0777fe03, 0x07642f79,
0x07968111, 0x05f8e5b7, 0x026366dc, 0x0606857a,
0x07d87758, 0x0f4a3da8, 0x012533de, 0x0c0e33e6,
0x033c875b, 0x0d561fec, 0x0b338ed2, 0x0240012b,
},
&bigNumber{
0x0383cb26, 0x044eef8e, 0x08b3f1aa, 0x046532da,
0x01e4444b, 0x09138f3d, 0x0d45f87b, 0x0c3fa83e,
0x0a72d199, 0x0a912d8e, 0x00604749, 0x04fd8baf,
0x0dc1b8a3, 0x003e536e, 0x0eb64292, 0x040c4ef5,
},
}
var out [56]byte
p.x448LikeEncode(out[:])
exp := [56]byte{
0x53, 0x07, 0x1c, 0x11, 0x7e, 0xf5, 0x98, 0x00,
0xb1, 0x2a, 0xb6, 0x67, 0x67, 0x0b, 0x16, 0x55,
0x1f, 0x93, 0x8d, 0xb4, 0x4f, 0x72, 0x4d, 0x50,
0x37, 0x84, 0xad, 0xa3, 0x1b, 0xa2, 0x40, 0xec,
0xf7, 0xc3, 0x84, 0xa6, 0x25, 0x5f, 0x44, 0x35,
0x27, 0x0a, 0x2d, 0xed, 0xf0, 0x84, 0xf5, 0xd0,
0xbf, 0xfe, 0x6c, 0x24, 0x3c, 0xfa, 0x18, 0x81,
}
c.Assert(out, DeepEquals, exp)
}
func (s *Ed448Suite) Test_ConvertFromEdDSATox448(c *C) {
ed := [57]byte{
0xb9, 0x3a, 0x28, 0x62, 0x7c, 0xfa, 0x29, 0xfe,
0xdb, 0x03, 0xc2, 0x1a, 0xac, 0x0f, 0xaa, 0x1e,
0xa0, 0xba, 0x84, 0xc1, 0x0c, 0xef, 0xa0, 0x7c,
0x93, 0x8f, 0x2e, 0x0a, 0xdb, 0xf9, 0x96, 0xf0,
0x2c, 0x8d, 0x00, 0xe3, 0x96, 0x95, 0xdf, 0xb6,
0xa0, 0x63, 0x6c, 0x8b, 0xcb, 0x21, 0x64, 0x5b,
0x06, 0xa8, 0x69, 0xdf, 0xbb, 0xb4, 0x89, 0xef,
0x00,
}
x := fromEdDSATox448(ed[:])
exp := [56]byte{
0x16, 0x3a, 0xf3, 0x02, 0x30, 0xe6, 0x2c, 0xbf,
0x36, 0xfd, 0x8f, 0x47, 0x13, 0xf2, 0x20, 0x4d,
0x78, 0xfa, 0x8f, 0x94, 0xf7, 0x9a, 0xdf, 0xe4,
0xf4, 0x9e, 0xd1, 0x07, 0x5d, 0x12, 0xb3, 0xa7,
0x25, 0xa5, 0xe5, 0xc0, 0x56, 0x4f, 0xaa, 0x64,
0x45, 0x90, 0x0b, 0x4d, 0x16, 0x6b, 0x89, 0xb7,
0x6f, 0x2d, 0xb5, 0xc3, 0x74, 0x41, 0x11, 0x29,
}
c.Assert(x, DeepEquals, exp)
}
func (s *Ed448Suite) Test_X448BasePointScalarMul(c *C) {
sc := [56]byte{
0x0e, 0xb1, 0xc2, 0xba, 0xf3, 0x84, 0xd1, 0x70,
0x85, 0xe0, 0x91, 0xeb, 0xa7, 0x6f, 0x68, 0x1c,
0xc2, 0xdc, 0xd4, 0x47, 0xd8, 0x54, 0x45, 0xa7,
0x1c, 0xdc, 0x67, 0xff, 0x7c, 0xb6, 0x90, 0xe3,
0xdc, 0xd1, 0xbd, 0x03, 0x7b, 0x9a, 0x2b, 0xfc,
0xae, 0x8b, 0xa8, 0x36, 0x24, 0x13, 0x69, 0x8e,
0x84, 0xda, 0x5e, 0x12, 0xe4, 0xdf, 0x4b, 0x70,
}
out := x448BasePointScalarMul(sc[:])
exp := [56]byte{
0x14, 0x2b, 0x20, 0x0d, 0x57, 0xa2, 0x0c, 0x5c,
0x2d, 0xe2, 0x7c, 0x83, 0x99, 0xef, 0x20, 0xb7,
0xe0, 0xb1, 0x75, 0x69, 0xa9, 0x6c, 0x31, 0xba,
0xfd, 0xc3, 0xd2, 0x21, 0x85, 0x24, 0xdf, 0x0e,
0xab, 0xf7, 0x2c, 0x88, 0x4f, 0xe4, 0xa2, 0xf1,
0xeb, 0x3c, 0xd0, 0x70, 0xe9, 0x86, 0x9c, 0x47,
0x8d, 0xd8, 0xc9, 0xfa, 0x56, 0xd5, 0x6c, 0x3b,
}
c.Assert(out, DeepEquals, exp)
}
func (s *Ed448Suite) Test_X448ScalarMul(c *C) {
sc := [56]byte{
0xb4, 0x5b, 0x37, 0x62, 0xa6, 0x52, 0x1f, 0x5f,
0xd7, 0x24, 0x99, 0x31, 0x65, 0x4c, 0xbf, 0x24,
0x25, 0xf5, 0x2d, 0x60, 0x9d, 0x86, 0xa7, 0x51,
0x16, 0xb9, 0x94, 0x32, 0x32, 0x0a, 0x69, 0x0d,
0xa2, 0x69, 0x6f, 0xd4, 0x25, 0x28, 0xd0, 0x1e,
0xcb, 0xc0, 0xb8, 0x25, 0x47, 0x6b, 0xca, 0x28,
0xc0, 0x08, 0x36, 0x85, 0x16, 0xae, 0x2c, 0x91,
}
base := [56]byte{
0x14, 0x2b, 0x20, 0x0d, 0x57, 0xa2, 0x0c, 0x5c,
0x2d, 0xe2, 0x7c, 0x83, 0x99, 0xef, 0x20, 0xb7,
0xe0, 0xb1, 0x75, 0x69, 0xa9, 0x6c, 0x31, 0xba,
0xfd, 0xc3, 0xd2, 0x21, 0x85, 0x24, 0xdf, 0x0e,
0xab, 0xf7, 0x2c, 0x88, 0x4f, 0xe4, 0xa2, 0xf1,
0xeb, 0x3c, 0xd0, 0x70, 0xe9, 0x86, 0x9c, 0x47,
0x8d, 0xd8, 0xc9, 0xfa, 0x56, 0xd5, 0x6c, 0x3b,
}
out, ok := x448ScalarMul(base[:], sc[:])
exp := [56]byte{
0x9f, 0x66, 0x48, 0xd0, 0x23, 0x82, 0xbb, 0x99,
0x2a, 0x1c, 0xf5, 0x78, 0x88, 0x4f, 0x4b, 0x07,
0xc5, 0x3d, 0xe5, 0xe5, 0xb1, 0xcf, 0x28, 0x46,
0x82, 0x75, 0x22, 0xb0, 0x3f, 0x0e, 0xfd, 0x69,
0x98, 0xf5, 0x88, 0x61, 0xde, 0x75, 0x3a, 0x70,
0xe8, 0x3b, 0x1e, 0x28, 0x37, 0xd8, 0xc8, 0xaa,
0xa8, 0x8a, 0x9f, 0x10, 0x9f, 0x85, 0x36, 0x6d,
}
c.Assert(out, DeepEquals, exp)
c.Assert(ok, Equals, true)
}