• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*############################################################################
2 # Copyright 2017 Intel Corporation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 ############################################################################*/
16 /// Unit tests of serialization implementation.
17 /*! \file */
18 
19 #include <gtest/gtest.h>
20 #include <stdint.h>
21 #include <cstring>
22 #include "epid/member/tiny/math/unittests/cmp-testhelper.h"
23 
24 extern "C" {
25 #include "epid/common/types.h"
26 #include "epid/member/tiny/math/mathtypes.h"
27 #include "epid/member/tiny/math/serialize.h"
28 }
29 
operator ==(OctStr32 const & lhs,OctStr32 const & rhs)30 bool operator==(OctStr32 const& lhs, OctStr32 const& rhs) {
31   return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs));
32 }
33 
operator ==(BigNumStr const & lhs,BigNumStr const & rhs)34 bool operator==(BigNumStr const& lhs, BigNumStr const& rhs) {
35   return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs));
36 }
37 
operator ==(FpElemStr const & lhs,FpElemStr const & rhs)38 bool operator==(FpElemStr const& lhs, FpElemStr const& rhs) {
39   return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs));
40 }
41 
operator ==(FqElemStr const & lhs,FqElemStr const & rhs)42 bool operator==(FqElemStr const& lhs, FqElemStr const& rhs) {
43   return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs));
44 }
45 
operator ==(G1ElemStr const & lhs,G1ElemStr const & rhs)46 bool operator==(G1ElemStr const& lhs, G1ElemStr const& rhs) {
47   return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs));
48 }
49 
operator ==(G2ElemStr const & lhs,G2ElemStr const & rhs)50 bool operator==(G2ElemStr const& lhs, G2ElemStr const& rhs) {
51   return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs));
52 }
53 
operator ==(Fq12ElemStr const & lhs,Fq12ElemStr const & rhs)54 bool operator==(Fq12ElemStr const& lhs, Fq12ElemStr const& rhs) {
55   return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs));
56 }
57 
58 namespace {
59 ////////////////////////////////////////////////////////////////////////
60 // Uint32Serialize
61 
TEST(TinySerializeTest,Uint32SerializeWorks)62 TEST(TinySerializeTest, Uint32SerializeWorks) {
63   OctStr32 octstr = {0};
64   const OctStr32 expected_octstr = {0x01, 0x02, 0x03, 0x04};
65   const uint32_t num = 0x01020304;
66   Uint32Serialize(&octstr, num);
67   EXPECT_EQ(expected_octstr, octstr);
68 }
69 
70 ////////////////////////////////////////////////////////////////////////
71 // Uint32Deserialize
72 
TEST(TinySerializeTest,Uint32DeserializeWorks)73 TEST(TinySerializeTest, Uint32DeserializeWorks) {
74   const OctStr32 octstr = {0x01, 0x02, 0x03, 0x04};
75   uint32_t num = 0;
76   const uint32_t expected_num = 0x01020304;
77   Uint32Deserialize(&num, &octstr);
78   EXPECT_EQ(expected_num, num);
79 }
80 
81 ////////////////////////////////////////////////////////////////////////
82 // VliSerialize
83 
TEST(TinySerializeTest,VliSerializeWorks)84 TEST(TinySerializeTest, VliSerializeWorks) {
85   const VeryLargeInt vli = {0x01020304, 0x05060708, 0x090A0B0C, 0x0D0E0F10,
86                             0x11121314, 0x15161718, 0x191A1B1C, 0x1D1E1F20};
87   BigNumStr serialize_vli = {0};
88   const BigNumStr expected_serialize_vli = {
89       0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17,
90       0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A,
91       0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04};
92   VliSerialize(&serialize_vli, &vli);
93   EXPECT_EQ(expected_serialize_vli, serialize_vli);
94 }
95 
96 ////////////////////////////////////////////////////////////////////////
97 // VliDeserialize
98 
TEST(TinySerializeTest,VliDeserializeWorks)99 TEST(TinySerializeTest, VliDeserializeWorks) {
100   VeryLargeInt vli = {0};
101   const VeryLargeInt expected_vli = {0x01020304, 0x05060708, 0x090A0B0C,
102                                      0x0D0E0F10, 0x11121314, 0x15161718,
103                                      0x191A1B1C, 0x1D1E1F20};
104   const BigNumStr serialize_vli = {
105       0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17,
106       0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A,
107       0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04};
108   VliDeserialize(&vli, &serialize_vli);
109   EXPECT_EQ(expected_vli, vli);
110 }
111 
112 ////////////////////////////////////////////////////////////////////////
113 // FqSerialize
114 
TEST(TinySerializeTest,FqSerializeWorks)115 TEST(TinySerializeTest, FqSerializeWorks) {
116   const FqElem fqelm = {0x01020304, 0x05060708, 0x090A0B0C, 0x0D0E0F10,
117                         0x11121314, 0x15161718, 0x191A1B1C, 0x1D1E1F20};
118   FqElemStr serialize_fqelm = {0};
119   const FqElemStr expected_serialize_fqelm = {
120       0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17,
121       0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A,
122       0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04};
123   FqSerialize(&serialize_fqelm, &fqelm);
124   EXPECT_EQ(expected_serialize_fqelm, serialize_fqelm);
125 }
126 
127 ////////////////////////////////////////////////////////////////////////
128 // FqDeserialize
129 
TEST(TinySerializeTest,FqDeserializeWorks)130 TEST(TinySerializeTest, FqDeserializeWorks) {
131   const FqElemStr serialize_fqelm = {
132       0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17,
133       0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A,
134       0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04};
135   FqElem fqelm = {0};
136   const FqElem expected_fqelm = {0x01020304, 0x05060708, 0x090A0B0C,
137                                  0x0D0E0F10, 0x11121314, 0x15161718,
138                                  0x191A1B1C, 0x1D1E1F20};
139   FqDeserialize(&fqelm, &serialize_fqelm);
140   EXPECT_EQ(expected_fqelm, fqelm);
141 }
142 
143 ////////////////////////////////////////////////////////////////////////
144 // Fq12Serialize
145 
TEST(TinySerializeTest,Fq12SerializeWorks)146 TEST(TinySerializeTest, Fq12SerializeWorks) {
147   const Fq12Elem fq12elm = {
148       {{
149            {0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
150             0x00000000, 0x00000000, 0x00000000},
151            {0x00000200, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
152             0x00000000, 0x00000000, 0x00000000},
153        },
154        {
155            {0x00030000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
156             0x00000000, 0x00000000, 0x00000000},
157            {0x04000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
158             0x00000000, 0x00000000, 0x00000000},
159        },
160        {
161            {0x00000000, 0x00000005, 0x00000000, 0x00000000, 0x00000000,
162             0x00000000, 0x00000000, 0x00000000},
163            {0x00000000, 0x00000600, 0x00000000, 0x00000000, 0x00000000,
164             0x00000000, 0x00000000, 0x00000000},
165        }},
166       {{
167            {0x00000000, 0x00070000, 0x00000000, 0x00000000, 0x00000000,
168             0x00000000, 0x00000000, 0x00000000},
169            {0x00000000, 0x08000000, 0x00000000, 0x00000000, 0x00000000,
170             0x00000000, 0x00000000, 0x00000000},
171        },
172        {
173            {0x00000000, 0x00000000, 0x00000009, 0x00000000, 0x00000000,
174             0x00000000, 0x00000000, 0x00000000},
175            {0x00000000, 0x00000000, 0x00000A00, 0x00000000, 0x00000000,
176             0x00000000, 0x00000000, 0x00000000},
177        },
178        {
179            {0x00000000, 0x00000000, 0x000B0000, 0x00000000, 0x00000000,
180             0x00000000, 0x00000000, 0x00000000},
181            {0x00000000, 0x00000000, 0x0C000000, 0x00000000, 0x00000000,
182             0x00000000, 0x00000000, 0x00000000},
183        }}};
184   Fq12ElemStr serialized_fq12elm = {0};
185   const Fq12ElemStr expected_serialized_fq12elm = {
186       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
187       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
188       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
189       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
190       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
191       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
192 
193       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
194       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
195       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
196       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
197       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
198       0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
199 
200       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
201       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
202       0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00,
203       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
204       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
205       0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00,
206 
207       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
208       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
209       0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
210       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
211       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
212       0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
213 
214       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
215       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
216       0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
217       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
218       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A,
219       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
220 
221       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
222       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B,
223       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
224       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
225       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00,
226       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
227   };
228   Fq12Serialize(&serialized_fq12elm, &fq12elm);
229   EXPECT_EQ(expected_serialized_fq12elm, serialized_fq12elm);
230 }
231 
232 ////////////////////////////////////////////////////////////////////////
233 // Fq12Deserialize
234 
TEST(TinySerializeTest,Fq12DeserializeWorks)235 TEST(TinySerializeTest, Fq12DeserializeWorks) {
236   const Fq12ElemStr serialized_fq12elm = {
237       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
238       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
239       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
240       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
241       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
242       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
243 
244       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
245       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
246       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
247       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
248       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
249       0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
250 
251       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
252       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
253       0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00,
254       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
255       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
256       0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00,
257 
258       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
259       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
260       0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
261       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
262       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
263       0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
264 
265       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
266       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
267       0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
268       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
269       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A,
270       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
271 
272       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
273       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B,
274       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
275       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
276       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00,
277       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
278   };
279   Fq12Elem fq12elm = {0};
280   const Fq12Elem expected_fq12elm = {
281       {{
282            {0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
283             0x00000000, 0x00000000, 0x00000000},
284            {0x00000200, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
285             0x00000000, 0x00000000, 0x00000000},
286        },
287        {
288            {0x00030000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
289             0x00000000, 0x00000000, 0x00000000},
290            {0x04000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
291             0x00000000, 0x00000000, 0x00000000},
292        },
293        {
294            {0x00000000, 0x00000005, 0x00000000, 0x00000000, 0x00000000,
295             0x00000000, 0x00000000, 0x00000000},
296            {0x00000000, 0x00000600, 0x00000000, 0x00000000, 0x00000000,
297             0x00000000, 0x00000000, 0x00000000},
298        }},
299       {{
300            {0x00000000, 0x00070000, 0x00000000, 0x00000000, 0x00000000,
301             0x00000000, 0x00000000, 0x00000000},
302            {0x00000000, 0x08000000, 0x00000000, 0x00000000, 0x00000000,
303             0x00000000, 0x00000000, 0x00000000},
304        },
305        {
306            {0x00000000, 0x00000000, 0x00000009, 0x00000000, 0x00000000,
307             0x00000000, 0x00000000, 0x00000000},
308            {0x00000000, 0x00000000, 0x00000A00, 0x00000000, 0x00000000,
309             0x00000000, 0x00000000, 0x00000000},
310        },
311        {
312            {0x00000000, 0x00000000, 0x000B0000, 0x00000000, 0x00000000,
313             0x00000000, 0x00000000, 0x00000000},
314            {0x00000000, 0x00000000, 0x0C000000, 0x00000000, 0x00000000,
315             0x00000000, 0x00000000, 0x00000000},
316        }}};
317   Fq12Deserialize(&fq12elm, &serialized_fq12elm);
318   EXPECT_EQ(expected_fq12elm, fq12elm);
319 }
320 
321 ////////////////////////////////////////////////////////////////////////
322 // FpSerialize
323 
TEST(TinySerializeTest,FpSerializeWorks)324 TEST(TinySerializeTest, FpSerializeWorks) {
325   const FpElem fpelm = {0x01020304, 0x05060708, 0x090A0B0C, 0x0D0E0F10,
326                         0x11121314, 0x15161718, 0x191A1B1C, 0x1D1E1F20};
327   FpElemStr serialize_fpelm = {0};
328   const FpElemStr expected_serialize_fpelm = {
329       0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17,
330       0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A,
331       0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04};
332   FpSerialize(&serialize_fpelm, &fpelm);
333   EXPECT_EQ(expected_serialize_fpelm, serialize_fpelm);
334 }
335 
336 ////////////////////////////////////////////////////////////////////////
337 // FpDeserialize
338 
TEST(TinySerializeTest,FpDeserializeWorks)339 TEST(TinySerializeTest, FpDeserializeWorks) {
340   const FpElemStr serialize_fpelm = {
341       0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17,
342       0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A,
343       0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04};
344   FpElem fpelm = {0};
345   const FpElem expected_fpelm = {0x01020304, 0x05060708, 0x090A0B0C,
346                                  0x0D0E0F10, 0x11121314, 0x15161718,
347                                  0x191A1B1C, 0x1D1E1F20};
348   FpDeserialize(&fpelm, &serialize_fpelm);
349   EXPECT_EQ(expected_fpelm, fpelm);
350 }
351 
352 ////////////////////////////////////////////////////////////////////////
353 // EFqSerialize
354 
TEST(TinySerializeTest,EFqSerializeWorks)355 TEST(TinySerializeTest, EFqSerializeWorks) {
356   const FqElem fqelm = {0x01020304, 0x05060708, 0x090A0B0C, 0x0D0E0F10,
357                         0x11121314, 0x15161718, 0x191A1B1C, 0x1D1E1F20};
358   const EccPointFq efq_point = {fqelm, fqelm};
359   const FqElemStr serialize_fqelm = {
360       0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17,
361       0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A,
362       0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04};
363   G1ElemStr efq_point_serialize = {0};
364   const G1ElemStr expected_efq_point_serialize = {serialize_fqelm,
365                                                   serialize_fqelm};
366   EFqSerialize(&efq_point_serialize, &efq_point);
367   EXPECT_EQ(expected_efq_point_serialize, efq_point_serialize);
368 }
369 
370 ////////////////////////////////////////////////////////////////////////
371 // EFqDeserialize
372 
TEST(TinySerializeTest,EFqDeserializeWorks)373 TEST(TinySerializeTest, EFqDeserializeWorks) {
374   const FqElemStr serialize_fqelm = {
375       0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17,
376       0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A,
377       0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04};
378   const G1ElemStr serialize_efq_point = {serialize_fqelm, serialize_fqelm};
379   EccPointFq efq_point = {0};
380   const FqElem fqelm = {0x01020304, 0x05060708, 0x090A0B0C, 0x0D0E0F10,
381                         0x11121314, 0x15161718, 0x191A1B1C, 0x1D1E1F20};
382   const EccPointFq expected_efq_point = {fqelm, fqelm};
383   EFqDeserialize(&efq_point, &serialize_efq_point);
384   EXPECT_EQ(expected_efq_point, efq_point);
385 }
386 
387 ////////////////////////////////////////////////////////////////////////
388 // EFq2Serialize
389 
TEST(TinySerializeTest,EFq2SerializeWorks)390 TEST(TinySerializeTest, EFq2SerializeWorks) {
391   const FqElem fqelm = {0x01020304, 0x05060708, 0x090A0B0C, 0x0D0E0F10,
392                         0x11121314, 0x15161718, 0x191A1B1C, 0x1D1E1F20};
393   const EccPointFq2 efq2_point = {{fqelm, fqelm}, {fqelm, fqelm}};
394   const FqElemStr serialize_fqelm = {
395       0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17,
396       0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A,
397       0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04};
398   G2ElemStr efq2_point_serialize = {0};
399   const G2ElemStr expected_efq2_point_serialize = {
400       {serialize_fqelm, serialize_fqelm}, {serialize_fqelm, serialize_fqelm}};
401   EFq2Serialize(&efq2_point_serialize, &efq2_point);
402   EXPECT_EQ(expected_efq2_point_serialize, efq2_point_serialize);
403 }
404 
405 ////////////////////////////////////////////////////////////////////////
406 // EFq2Deserialize
407 
TEST(TinySerializeTest,EFq2DeserializeWorks)408 TEST(TinySerializeTest, EFq2DeserializeWorks) {
409   const FqElemStr serialize_fqelm = {
410       0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17,
411       0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A,
412       0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04};
413   const G2ElemStr serialize_efq2_point = {{serialize_fqelm, serialize_fqelm},
414                                           {serialize_fqelm, serialize_fqelm}};
415   EccPointFq2 efq2_point = {0};
416   const FqElem fqelm = {0x01020304, 0x05060708, 0x090A0B0C, 0x0D0E0F10,
417                         0x11121314, 0x15161718, 0x191A1B1C, 0x1D1E1F20};
418   const EccPointFq2 expected_efq2_point = {{fqelm, fqelm}, {fqelm, fqelm}};
419   EFq2Deserialize(&efq2_point, &serialize_efq2_point);
420   EXPECT_EQ(expected_efq2_point, efq2_point);
421 }
422 
423 }  // namespace
424