• 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 
17 /*!
18  * \file
19  * \brief native type serialization unit tests.
20  *
21  * \warning to run the tests in this file you must build a non-shared mode.
22  */
23 
24 #ifndef SHARED
25 
26 #include <cstring>
27 #include <vector>
28 
29 #include "epid/common-testhelper/epid_gtest-testhelper.h"
30 #include "epid/member/tiny/unittests/member-testhelper.h"
31 #include "gtest/gtest.h"
32 
33 extern "C" {
34 #include "epid/common/types.h"
35 #include "epid/member/tiny/src/native_types.h"
36 #include "epid/member/tiny/src/serialize.h"
37 #include "epid/member/tiny/src/signbasic.h"
38 }
39 
40 /// compares BasicSignature values
operator ==(BasicSignature const & lhs,BasicSignature const & rhs)41 bool operator==(BasicSignature const& lhs, BasicSignature const& rhs) {
42   return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs));
43 }
44 
operator ==(NativeBasicSignature const & lhs,NativeBasicSignature const & rhs)45 bool operator==(NativeBasicSignature const& lhs,
46                 NativeBasicSignature const& rhs) {
47   return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs));
48 }
49 
operator ==(NativeGroupPubKey const & lhs,NativeGroupPubKey const & rhs)50 bool operator==(NativeGroupPubKey const& lhs, NativeGroupPubKey const& rhs) {
51   return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs));
52 }
53 
operator ==(NativePrivKey const & lhs,NativePrivKey const & rhs)54 bool operator==(NativePrivKey const& lhs, NativePrivKey const& rhs) {
55   return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs));
56 }
57 
operator ==(NativeMembershipCredential const & lhs,NativeMembershipCredential const & rhs)58 bool operator==(NativeMembershipCredential const& lhs,
59                 NativeMembershipCredential const& rhs) {
60   return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs));
61 }
62 
63 namespace {
64 ////////////////////////////////////////////////////////////////////////
65 // BasicSignatureSerialize
66 
TEST(TinySerializeTest,BasicSignatureSerializeWorks)67 TEST(TinySerializeTest, BasicSignatureSerializeWorks) {
68   const NativeBasicSignature serialized_BaseSig = {
69       // B
70       {{0xB315D67E, 0x1924AE56, 0xCF527861, 0xEBB789B6, 0x3F429D2A, 0xB193BF9A,
71         0x6BD8502F, 0x5E73BE39},
72        {0x0BD51968, 0x0F13472D, 0xC96B5096, 0xA9CD4491, 0x4AB668CF, 0x2123D56C,
73         0xF30AF180, 0x0DB43C33}},
74       // K
75       {{0x9C3524E3, 0x4E4CA66B, 0x58731363, 0xB57BC920, 0x1317EBFA, 0xBD71A2D6,
76         0x046B29FE, 0x64B5A803},
77        {0x86A7A14A, 0xDE584912, 0xFEFD476A, 0x8559EF80, 0x34D8E1D2, 0x81F6BF1D,
78         0xE0C42E4B, 0x477FEC10}},
79       // T
80       {{0x444DB42F, 0xB57CFAA0, 0x3FB8C069, 0x3593EC91, 0xB968BBAA, 0x02D2BFBB,
81         0xCF2E5D4A, 0xE57236B5},
82        {0x23C435BE, 0x92D96415, 0x6A552F32, 0x5E071AA9, 0xBBC76EDC, 0xC1C5D18A,
83         0x654CA5AE, 0xB96FEBB0}},
84       // c
85       {0xD03D247B, 0x8C2A93E5, 0xCBB14B7A, 0x85919691, 0xC7009CFC, 0xEFD5278B,
86        0x82D2F470, 0xA2CDE297},
87       // xs
88       {0xEB24D967, 0xDC578F59, 0x58C76405, 0x1958415E, 0xF08890BD, 0xDB47D06A,
89        0x7257B3F5, 0x6346AA98},
90       // sf
91       {0x11B85D46, 0xBEA435F3, 0x11E85329, 0xDD10B17B, 0xC41B1647, 0x268C5DDC,
92        0x4E39F40C, 0x25421795},
93       // sa
94       {0xCDA62A84, 0x3CC19531, 0xDCC526F5, 0x3A248BB8, 0xF973B761, 0x3E009735,
95        0x6FC46BCC, 0x4EBDEDE8},
96       // sb
97       {0x2E0B26CF, 0x6193CD96, 0xED6E97F8, 0xBB9D186E, 0xB37A5227, 0xF82B38E5,
98        0x610CAF48, 0x92A3681B}};
99   BasicSignature result = {0};
100   const BasicSignature expected_BaseSig = {
101       // B
102       {{0x5E, 0x73, 0xBE, 0x39, 0x6B, 0xD8, 0x50, 0x2F, 0xB1, 0x93, 0xBF,
103         0x9A, 0x3F, 0x42, 0x9D, 0x2A, 0xEB, 0xB7, 0x89, 0xB6, 0xCF, 0x52,
104         0x78, 0x61, 0x19, 0x24, 0xAE, 0x56, 0xB3, 0x15, 0xD6, 0x7E},
105        {0x0D, 0xB4, 0x3C, 0x33, 0xF3, 0x0A, 0xF1, 0x80, 0x21, 0x23, 0xD5,
106         0x6C, 0x4A, 0xB6, 0x68, 0xCF, 0xA9, 0xCD, 0x44, 0x91, 0xC9, 0x6B,
107         0x50, 0x96, 0x0F, 0x13, 0x47, 0x2D, 0x0B, 0xD5, 0x19, 0x68}},
108       // K
109       {{0x64, 0xB5, 0xA8, 0x03, 0x04, 0x6B, 0x29, 0xFE, 0xBD, 0x71, 0xA2,
110         0xD6, 0x13, 0x17, 0xEB, 0xFA, 0xB5, 0x7B, 0xC9, 0x20, 0x58, 0x73,
111         0x13, 0x63, 0x4E, 0x4C, 0xA6, 0x6B, 0x9C, 0x35, 0x24, 0xE3},
112        {0x47, 0x7F, 0xEC, 0x10, 0xE0, 0xC4, 0x2E, 0x4B, 0x81, 0xF6, 0xBF,
113         0x1D, 0x34, 0xD8, 0xE1, 0xD2, 0x85, 0x59, 0xEF, 0x80, 0xFE, 0xFD,
114         0x47, 0x6A, 0xDE, 0x58, 0x49, 0x12, 0x86, 0xA7, 0xA1, 0x4A}},
115       // T
116       {{0xE5, 0x72, 0x36, 0xB5, 0xCF, 0x2E, 0x5D, 0x4A, 0x02, 0xD2, 0xBF,
117         0xBB, 0xB9, 0x68, 0xBB, 0xAA, 0x35, 0x93, 0xEC, 0x91, 0x3F, 0xB8,
118         0xC0, 0x69, 0xB5, 0x7C, 0xFA, 0xA0, 0x44, 0x4D, 0xB4, 0x2F},
119        {0xB9, 0x6F, 0xEB, 0xB0, 0x65, 0x4C, 0xA5, 0xAE, 0xC1, 0xC5, 0xD1,
120         0x8A, 0xBB, 0xC7, 0x6E, 0xDC, 0x5E, 0x07, 0x1A, 0xA9, 0x6A, 0x55,
121         0x2F, 0x32, 0x92, 0xD9, 0x64, 0x15, 0x23, 0xC4, 0x35, 0xBE}},
122       // c
123       {0xA2, 0xCD, 0xE2, 0x97, 0x82, 0xD2, 0xF4, 0x70, 0xEF, 0xD5, 0x27,
124        0x8B, 0xC7, 0x00, 0x9C, 0xFC, 0x85, 0x91, 0x96, 0x91, 0xCB, 0xB1,
125        0x4B, 0x7A, 0x8C, 0x2A, 0x93, 0xE5, 0xD0, 0x3D, 0x24, 0x7B},
126       // sx
127       {0x63, 0x46, 0xAA, 0x98, 0x72, 0x57, 0xB3, 0xF5, 0xDB, 0x47, 0xD0,
128        0x6A, 0xF0, 0x88, 0x90, 0xBD, 0x19, 0x58, 0x41, 0x5E, 0x58, 0xC7,
129        0x64, 0x05, 0xDC, 0x57, 0x8F, 0x59, 0xEB, 0x24, 0xD9, 0x67},
130       // sf
131       {0x25, 0x42, 0x17, 0x95, 0x4E, 0x39, 0xF4, 0x0C, 0x26, 0x8C, 0x5D,
132        0xDC, 0xC4, 0x1B, 0x16, 0x47, 0xDD, 0x10, 0xB1, 0x7B, 0x11, 0xE8,
133        0x53, 0x29, 0xBE, 0xA4, 0x35, 0xF3, 0x11, 0xB8, 0x5D, 0x46},
134       // sa
135       {0x4E, 0xBD, 0xED, 0xE8, 0x6F, 0xC4, 0x6B, 0xCC, 0x3E, 0x00, 0x97,
136        0x35, 0xF9, 0x73, 0xB7, 0x61, 0x3A, 0x24, 0x8B, 0xB8, 0xDC, 0xC5,
137        0x26, 0xF5, 0x3C, 0xC1, 0x95, 0x31, 0xCD, 0xA6, 0x2A, 0x84},
138       // sb
139       {0x92, 0xA3, 0x68, 0x1B, 0x61, 0x0C, 0xAF, 0x48, 0xF8, 0x2B, 0x38,
140        0xE5, 0xB3, 0x7A, 0x52, 0x27, 0xBB, 0x9D, 0x18, 0x6E, 0xED, 0x6E,
141        0x97, 0xF8, 0x61, 0x93, 0xCD, 0x96, 0x2E, 0x0B, 0x26, 0xCF}};
142   BasicSignatureSerialize(&result, &serialized_BaseSig);
143   EXPECT_EQ(expected_BaseSig, result);
144 }
145 
146 ////////////////////////////////////////////////////////////////////////
147 // BasicSignatureDeserialize
148 
TEST(TinySerializeTest,BasicSignatureDeserializeWorks)149 TEST(TinySerializeTest, BasicSignatureDeserializeWorks) {
150   const BasicSignature deserialized_BaseSig = {
151       // B
152       {{0x5E, 0x73, 0xBE, 0x39, 0x6B, 0xD8, 0x50, 0x2F, 0xB1, 0x93, 0xBF,
153         0x9A, 0x3F, 0x42, 0x9D, 0x2A, 0xEB, 0xB7, 0x89, 0xB6, 0xCF, 0x52,
154         0x78, 0x61, 0x19, 0x24, 0xAE, 0x56, 0xB3, 0x15, 0xD6, 0x7E},
155        {0x0D, 0xB4, 0x3C, 0x33, 0xF3, 0x0A, 0xF1, 0x80, 0x21, 0x23, 0xD5,
156         0x6C, 0x4A, 0xB6, 0x68, 0xCF, 0xA9, 0xCD, 0x44, 0x91, 0xC9, 0x6B,
157         0x50, 0x96, 0x0F, 0x13, 0x47, 0x2D, 0x0B, 0xD5, 0x19, 0x68}},
158       // K
159       {{0x64, 0xB5, 0xA8, 0x03, 0x04, 0x6B, 0x29, 0xFE, 0xBD, 0x71, 0xA2,
160         0xD6, 0x13, 0x17, 0xEB, 0xFA, 0xB5, 0x7B, 0xC9, 0x20, 0x58, 0x73,
161         0x13, 0x63, 0x4E, 0x4C, 0xA6, 0x6B, 0x9C, 0x35, 0x24, 0xE3},
162        {0x47, 0x7F, 0xEC, 0x10, 0xE0, 0xC4, 0x2E, 0x4B, 0x81, 0xF6, 0xBF,
163         0x1D, 0x34, 0xD8, 0xE1, 0xD2, 0x85, 0x59, 0xEF, 0x80, 0xFE, 0xFD,
164         0x47, 0x6A, 0xDE, 0x58, 0x49, 0x12, 0x86, 0xA7, 0xA1, 0x4A}},
165       // T
166       {{0xE5, 0x72, 0x36, 0xB5, 0xCF, 0x2E, 0x5D, 0x4A, 0x02, 0xD2, 0xBF,
167         0xBB, 0xB9, 0x68, 0xBB, 0xAA, 0x35, 0x93, 0xEC, 0x91, 0x3F, 0xB8,
168         0xC0, 0x69, 0xB5, 0x7C, 0xFA, 0xA0, 0x44, 0x4D, 0xB4, 0x2F},
169        {0xB9, 0x6F, 0xEB, 0xB0, 0x65, 0x4C, 0xA5, 0xAE, 0xC1, 0xC5, 0xD1,
170         0x8A, 0xBB, 0xC7, 0x6E, 0xDC, 0x5E, 0x07, 0x1A, 0xA9, 0x6A, 0x55,
171         0x2F, 0x32, 0x92, 0xD9, 0x64, 0x15, 0x23, 0xC4, 0x35, 0xBE}},
172       // c
173       {0xA2, 0xCD, 0xE2, 0x97, 0x82, 0xD2, 0xF4, 0x70, 0xEF, 0xD5, 0x27,
174        0x8B, 0xC7, 0x00, 0x9C, 0xFC, 0x85, 0x91, 0x96, 0x91, 0xCB, 0xB1,
175        0x4B, 0x7A, 0x8C, 0x2A, 0x93, 0xE5, 0xD0, 0x3D, 0x24, 0x7B},
176       // sx
177       {0x63, 0x46, 0xAA, 0x98, 0x72, 0x57, 0xB3, 0xF5, 0xDB, 0x47, 0xD0,
178        0x6A, 0xF0, 0x88, 0x90, 0xBD, 0x19, 0x58, 0x41, 0x5E, 0x58, 0xC7,
179        0x64, 0x05, 0xDC, 0x57, 0x8F, 0x59, 0xEB, 0x24, 0xD9, 0x67},
180       // sf
181       {0x25, 0x42, 0x17, 0x95, 0x4E, 0x39, 0xF4, 0x0C, 0x26, 0x8C, 0x5D,
182        0xDC, 0xC4, 0x1B, 0x16, 0x47, 0xDD, 0x10, 0xB1, 0x7B, 0x11, 0xE8,
183        0x53, 0x29, 0xBE, 0xA4, 0x35, 0xF3, 0x11, 0xB8, 0x5D, 0x46},
184       // sa
185       {0x4E, 0xBD, 0xED, 0xE8, 0x6F, 0xC4, 0x6B, 0xCC, 0x3E, 0x00, 0x97,
186        0x35, 0xF9, 0x73, 0xB7, 0x61, 0x3A, 0x24, 0x8B, 0xB8, 0xDC, 0xC5,
187        0x26, 0xF5, 0x3C, 0xC1, 0x95, 0x31, 0xCD, 0xA6, 0x2A, 0x84},
188       // sb
189       {0x92, 0xA3, 0x68, 0x1B, 0x61, 0x0C, 0xAF, 0x48, 0xF8, 0x2B, 0x38,
190        0xE5, 0xB3, 0x7A, 0x52, 0x27, 0xBB, 0x9D, 0x18, 0x6E, 0xED, 0x6E,
191        0x97, 0xF8, 0x61, 0x93, 0xCD, 0x96, 0x2E, 0x0B, 0x26, 0xCF}};
192   const NativeBasicSignature expected_BaseSig = {
193       // B
194       {{0xB315D67E, 0x1924AE56, 0xCF527861, 0xEBB789B6, 0x3F429D2A, 0xB193BF9A,
195         0x6BD8502F, 0x5E73BE39},
196        {0x0BD51968, 0x0F13472D, 0xC96B5096, 0xA9CD4491, 0x4AB668CF, 0x2123D56C,
197         0xF30AF180, 0x0DB43C33}},
198       // K
199       {{0x9C3524E3, 0x4E4CA66B, 0x58731363, 0xB57BC920, 0x1317EBFA, 0xBD71A2D6,
200         0x046B29FE, 0x64B5A803},
201        {0x86A7A14A, 0xDE584912, 0xFEFD476A, 0x8559EF80, 0x34D8E1D2, 0x81F6BF1D,
202         0xE0C42E4B, 0x477FEC10}},
203       // T
204       {{0x444DB42F, 0xB57CFAA0, 0x3FB8C069, 0x3593EC91, 0xB968BBAA, 0x02D2BFBB,
205         0xCF2E5D4A, 0xE57236B5},
206        {0x23C435BE, 0x92D96415, 0x6A552F32, 0x5E071AA9, 0xBBC76EDC, 0xC1C5D18A,
207         0x654CA5AE, 0xB96FEBB0}},
208       // c
209       {0xD03D247B, 0x8C2A93E5, 0xCBB14B7A, 0x85919691, 0xC7009CFC, 0xEFD5278B,
210        0x82D2F470, 0xA2CDE297},
211       // xs
212       {0xEB24D967, 0xDC578F59, 0x58C76405, 0x1958415E, 0xF08890BD, 0xDB47D06A,
213        0x7257B3F5, 0x6346AA98},
214       // sf
215       {0x11B85D46, 0xBEA435F3, 0x11E85329, 0xDD10B17B, 0xC41B1647, 0x268C5DDC,
216        0x4E39F40C, 0x25421795},
217       // sa
218       {0xCDA62A84, 0x3CC19531, 0xDCC526F5, 0x3A248BB8, 0xF973B761, 0x3E009735,
219        0x6FC46BCC, 0x4EBDEDE8},
220       // sb
221       {0x2E0B26CF, 0x6193CD96, 0xED6E97F8, 0xBB9D186E, 0xB37A5227, 0xF82B38E5,
222        0x610CAF48, 0x92A3681B}};
223   NativeBasicSignature result = {0};
224   BasicSignatureDeserialize(&result, &deserialized_BaseSig);
225   EXPECT_EQ(expected_BaseSig, result);
226 }
227 
228 //////////////////////////////////////////////////////////////////////////
229 // GroupPubKeySerialize Tests
TEST_F(EpidMemberTest,GroupPubKeySerializeWorks)230 TEST_F(EpidMemberTest, GroupPubKeySerializeWorks) {
231   NativeGroupPubKey const input = {
232       {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
233        0x00, 0x00, 0x00, 0x01},  // group id
234       {{{{0xb580e099, 0x434c62fd, 0x64cee3ce, 0xd06d8f9d, 0x7e27b0cb,
235           0x3d753d61, 0xe21b17eb, 0xb36fff81}}},
236        {{{0x74f459ee, 0xd8693ea1, 0x82457e7f, 0xee3d6642, 0xe94dae9c,
237           0xfdb5b79d, 0xe08859a4, 0x3a075680}}}},  // h1
238       {{{{0xbcdd7fe1, 0x29666163, 0xd55ba704, 0xdc99ed42, 0x5474107b,
239           0xd5dbca1c, 0x63c2518e, 0xd2742e9f}}},
240        {{{0xe78e1084, 0x93a56ecc, 0xde4ceacb, 0xda3f517d, 0xe85b087b,
241           0x48120aa6, 0xe314ac72, 0x765dc06e}}}},  // h2
242       {{{{{0x0728e896, 0x8dcd3688, 0x6a95cac6, 0x788753f6, 0x401ba5b6,
243            0x50719451, 0xe20fca1c, 0xbd195a95}}},
244         {{{0xe2f4b3a1, 0x22d9fde0, 0x0f6c56f5, 0x2414cfd1, 0x15d775f8,
245            0xa6657a68, 0xb86ae7e5, 0xca78115b}}}},
246        {{{{0x57e4f33c, 0x0a3b5896, 0x89c2399c, 0x898846dd, 0x5deef56a,
247            0xbc077230, 0xe8b3c725, 0x9021a7e0}}},
248         {{{0xee1140a9, 0x837d3e31, 0x8e25c6ad, 0xba6bf0da, 0x1f3deaa2,
249            0x5d0a88db, 0x1bb6f705, 0x79516936}}}}}};
250   GroupPubKey const expected = {
251       {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
252        0x00, 0x00, 0x00, 0x01},  // group id
253       {{{{0xb3, 0x6f, 0xff, 0x81, 0xe2, 0x1b, 0x17, 0xeb, 0x3d, 0x75, 0x3d,
254           0x61, 0x7e, 0x27, 0xb0, 0xcb, 0xd0, 0x6d, 0x8f, 0x9d, 0x64, 0xce,
255           0xe3, 0xce, 0x43, 0x4c, 0x62, 0xfd, 0xb5, 0x80, 0xe0, 0x99}}},
256        {{{0x3a, 0x07, 0x56, 0x80, 0xe0, 0x88, 0x59, 0xa4, 0xfd, 0xb5, 0xb7,
257           0x9d, 0xe9, 0x4d, 0xae, 0x9c, 0xee, 0x3d, 0x66, 0x42, 0x82, 0x45,
258           0x7e, 0x7f, 0xd8, 0x69, 0x3e, 0xa1, 0x74, 0xf4, 0x59, 0xee}}}},  // h1
259       {{{{0xd2, 0x74, 0x2e, 0x9f, 0x63, 0xc2, 0x51, 0x8e, 0xd5, 0xdb, 0xca,
260           0x1c, 0x54, 0x74, 0x10, 0x7b, 0xdc, 0x99, 0xed, 0x42, 0xd5, 0x5b,
261           0xa7, 0x04, 0x29, 0x66, 0x61, 0x63, 0xbc, 0xdd, 0x7f, 0xe1}}},
262        {{{0x76, 0x5d, 0xc0, 0x6e, 0xe3, 0x14, 0xac, 0x72, 0x48, 0x12, 0x0a,
263           0xa6, 0xe8, 0x5b, 0x08, 0x7b, 0xda, 0x3f, 0x51, 0x7d, 0xde, 0x4c,
264           0xea, 0xcb, 0x93, 0xa5, 0x6e, 0xcc, 0xe7, 0x8e, 0x10, 0x84}}}},  // h2
265       {{{{{0xbd, 0x19, 0x5a, 0x95, 0xe2, 0x0f, 0xca, 0x1c, 0x50, 0x71, 0x94,
266            0x51, 0x40, 0x1b, 0xa5, 0xb6, 0x78, 0x87, 0x53, 0xf6, 0x6a, 0x95,
267            0xca, 0xc6, 0x8d, 0xcd, 0x36, 0x88, 0x7,  0x28, 0xe8, 0x96}}},
268         {{{0xca, 0x78, 0x11, 0x5b, 0xb8, 0x6a, 0xe7, 0xe5, 0xa6, 0x65, 0x7a,
269            0x68, 0x15, 0xd7, 0x75, 0xf8, 0x24, 0x14, 0xcf, 0xd1, 0x0f, 0x6c,
270            0x56, 0xf5, 0x22, 0xd9, 0xfd, 0xe0, 0xe2, 0xf4, 0xb3, 0xa1}}}},
271        {{{{0x90, 0x21, 0xa7, 0xe0, 0xe8, 0xb3, 0xc7, 0x25, 0xbc, 0x07, 0x72,
272            0x30, 0x5d, 0xee, 0xf5, 0x6a, 0x89, 0x88, 0x46, 0xdd, 0x89, 0xc2,
273            0x39, 0x9c, 0x0a, 0x3b, 0x58, 0x96, 0x57, 0xe4, 0xf3, 0x3c}}},
274         {{{0x79, 0x51, 0x69, 0x36, 0x1b, 0xb6, 0xf7, 0x05, 0x5d, 0x0a, 0x88,
275            0xdb, 0x1f, 0x3d, 0xea, 0xa2, 0xba, 0x6b, 0xf0, 0xda, 0x8e, 0x25,
276            0xc6, 0xad, 0x83, 0x7d, 0x3e, 0x31, 0xee, 0x11, 0x40, 0xa9}}}}}  // w
277   };
278   GroupPubKey actual = {0};
279   GroupPubKeySerialize(&actual, &input);
280   EXPECT_EQ(expected, actual);
281 }
282 
283 //////////////////////////////////////////////////////////////////////////
284 // GroupPubKeyDeserialize Tests
TEST_F(EpidMemberTest,GroupPubKeyDeserializeWorks)285 TEST_F(EpidMemberTest, GroupPubKeyDeserializeWorks) {
286   GroupPubKey const input = {
287       {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
288        0x00, 0x00, 0x00, 0x01},  // group id
289       {{{{0xb3, 0x6f, 0xff, 0x81, 0xe2, 0x1b, 0x17, 0xeb, 0x3d, 0x75, 0x3d,
290           0x61, 0x7e, 0x27, 0xb0, 0xcb, 0xd0, 0x6d, 0x8f, 0x9d, 0x64, 0xce,
291           0xe3, 0xce, 0x43, 0x4c, 0x62, 0xfd, 0xb5, 0x80, 0xe0, 0x99}}},
292        {{{0x3a, 0x07, 0x56, 0x80, 0xe0, 0x88, 0x59, 0xa4, 0xfd, 0xb5, 0xb7,
293           0x9d, 0xe9, 0x4d, 0xae, 0x9c, 0xee, 0x3d, 0x66, 0x42, 0x82, 0x45,
294           0x7e, 0x7f, 0xd8, 0x69, 0x3e, 0xa1, 0x74, 0xf4, 0x59, 0xee}}}},  // h1
295       {{{{0xd2, 0x74, 0x2e, 0x9f, 0x63, 0xc2, 0x51, 0x8e, 0xd5, 0xdb, 0xca,
296           0x1c, 0x54, 0x74, 0x10, 0x7b, 0xdc, 0x99, 0xed, 0x42, 0xd5, 0x5b,
297           0xa7, 0x04, 0x29, 0x66, 0x61, 0x63, 0xbc, 0xdd, 0x7f, 0xe1}}},
298        {{{0x76, 0x5d, 0xc0, 0x6e, 0xe3, 0x14, 0xac, 0x72, 0x48, 0x12, 0x0a,
299           0xa6, 0xe8, 0x5b, 0x08, 0x7b, 0xda, 0x3f, 0x51, 0x7d, 0xde, 0x4c,
300           0xea, 0xcb, 0x93, 0xa5, 0x6e, 0xcc, 0xe7, 0x8e, 0x10, 0x84}}}},  // h2
301       {{{{{0xbd, 0x19, 0x5a, 0x95, 0xe2, 0x0f, 0xca, 0x1c, 0x50, 0x71, 0x94,
302            0x51, 0x40, 0x1b, 0xa5, 0xb6, 0x78, 0x87, 0x53, 0xf6, 0x6a, 0x95,
303            0xca, 0xc6, 0x8d, 0xcd, 0x36, 0x88, 0x7,  0x28, 0xe8, 0x96}}},
304         {{{0xca, 0x78, 0x11, 0x5b, 0xb8, 0x6a, 0xe7, 0xe5, 0xa6, 0x65, 0x7a,
305            0x68, 0x15, 0xd7, 0x75, 0xf8, 0x24, 0x14, 0xcf, 0xd1, 0x0f, 0x6c,
306            0x56, 0xf5, 0x22, 0xd9, 0xfd, 0xe0, 0xe2, 0xf4, 0xb3, 0xa1}}}},
307        {{{{0x90, 0x21, 0xa7, 0xe0, 0xe8, 0xb3, 0xc7, 0x25, 0xbc, 0x07, 0x72,
308            0x30, 0x5d, 0xee, 0xf5, 0x6a, 0x89, 0x88, 0x46, 0xdd, 0x89, 0xc2,
309            0x39, 0x9c, 0x0a, 0x3b, 0x58, 0x96, 0x57, 0xe4, 0xf3, 0x3c}}},
310         {{{0x79, 0x51, 0x69, 0x36, 0x1b, 0xb6, 0xf7, 0x05, 0x5d, 0x0a, 0x88,
311            0xdb, 0x1f, 0x3d, 0xea, 0xa2, 0xba, 0x6b, 0xf0, 0xda, 0x8e, 0x25,
312            0xc6, 0xad, 0x83, 0x7d, 0x3e, 0x31, 0xee, 0x11, 0x40, 0xa9}}}}}  // w
313   };
314   NativeGroupPubKey const expected = {
315       {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
316        0x00, 0x00, 0x00, 0x01},  // group id
317       {{{{0xb580e099, 0x434c62fd, 0x64cee3ce, 0xd06d8f9d, 0x7e27b0cb,
318           0x3d753d61, 0xe21b17eb, 0xb36fff81}}},
319        {{{0x74f459ee, 0xd8693ea1, 0x82457e7f, 0xee3d6642, 0xe94dae9c,
320           0xfdb5b79d, 0xe08859a4, 0x3a075680}}}},  // h1
321       {{{{0xbcdd7fe1, 0x29666163, 0xd55ba704, 0xdc99ed42, 0x5474107b,
322           0xd5dbca1c, 0x63c2518e, 0xd2742e9f}}},
323        {{{0xe78e1084, 0x93a56ecc, 0xde4ceacb, 0xda3f517d, 0xe85b087b,
324           0x48120aa6, 0xe314ac72, 0x765dc06e}}}},  // h2
325       {{{{{0x0728e896, 0x8dcd3688, 0x6a95cac6, 0x788753f6, 0x401ba5b6,
326            0x50719451, 0xe20fca1c, 0xbd195a95}}},
327         {{{0xe2f4b3a1, 0x22d9fde0, 0x0f6c56f5, 0x2414cfd1, 0x15d775f8,
328            0xa6657a68, 0xb86ae7e5, 0xca78115b}}}},
329        {{{{0x57e4f33c, 0x0a3b5896, 0x89c2399c, 0x898846dd, 0x5deef56a,
330            0xbc077230, 0xe8b3c725, 0x9021a7e0}}},
331         {{{0xee1140a9, 0x837d3e31, 0x8e25c6ad, 0xba6bf0da, 0x1f3deaa2,
332            0x5d0a88db, 0x1bb6f705, 0x79516936}}}}}};
333   NativeGroupPubKey actual = {0};
334   GroupPubKeyDeserialize(&actual, &input);
335   EXPECT_EQ(expected, actual);
336 }
337 
338 //////////////////////////////////////////////////////////////////////////
339 // PrivKeyDeserialize Tests
TEST_F(EpidMemberTest,PrivKeyDeserializeWorks)340 TEST_F(EpidMemberTest, PrivKeyDeserializeWorks) {
341   PrivKey const input = {
342       {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
343        0x00, 0x00, 0x00, 0x01},  // group id
344       {{{{0x46, 0xc9, 0x69, 0xee, 0xf4, 0x68, 0xe1, 0x5f, 0xac, 0xbf, 0xdd,
345           0x77, 0xeb, 0x4c, 0xaf, 0x8a, 0x87, 0x68, 0x3f, 0x4e, 0xda, 0xf2,
346           0x96, 0xec, 0x57, 0x08, 0x90, 0xe8, 0x19, 0x62, 0x54, 0xdb}}},
347        {{{0x1e, 0x52, 0x23, 0x16, 0x91, 0xe4, 0xa8, 0x1d, 0x9a, 0x1b, 0x8a,
348           0xad, 0x0a, 0xcf, 0x36, 0x4f, 0xae, 0x43, 0xde, 0x62, 0xff, 0xa6,
349           0x4b, 0xa8, 0x16, 0x24, 0x98, 0x80, 0x82, 0x80, 0x37, 0x77}}}},  // A
350       {0x0a, 0x30, 0xae, 0x43, 0xa1, 0xe0, 0xd7, 0xdf, 0x10, 0x5e, 0xaf,
351        0xd8, 0x5a, 0x61, 0x10, 0x86, 0xd0, 0x9d, 0xb9, 0xe4, 0x46, 0xdd,
352        0xb7, 0x1b, 0x00, 0x14, 0x7c, 0x6b, 0x13, 0x72, 0xc3, 0x77},  // x
353       {0x48, 0x40, 0xb5, 0x6c, 0x6d, 0x47, 0x09, 0x0b, 0x05, 0xd6, 0x43,
354        0x56, 0xe0, 0x7c, 0xc6, 0x8e, 0xa1, 0x65, 0x67, 0xfd, 0xa7, 0x07,
355        0x87, 0x9b, 0x36, 0x2d, 0x41, 0x35, 0x63, 0x61, 0x31, 0xc7}  // f
356   };
357   NativePrivKey const expected = {
358       {
359           {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
360            0x00, 0x00, 0x00, 0x00, 0x01},  // group id
361           {{{{0x196254db, 0x570890e8, 0xdaf296ec, 0x87683f4e, 0xeb4caf8a,
362               0xacbfdd77, 0xf468e15f, 0x46c969ee}}},
363            {{{0x82803777, 0x16249880, 0xffa64ba8, 0xae43de62, 0x0acf364f,
364               0x9a1b8aad, 0x91e4a81d, 0x1e522316}}}},  // A
365           {0x1372c377, 0x00147c6b, 0x46ddb71b, 0xd09db9e4, 0x5a611086,
366            0x105eafd8, 0xa1e0d7df, 0x0a30ae43}  // x
367       },
368       {0x636131c7, 0x362d4135, 0xa707879b, 0xa16567fd, 0xe07cc68e, 0x05d64356,
369        0x6d47090b, 0x4840b56c}  // f
370   };
371   NativePrivKey actual = {0};
372   PrivKeyDeserialize(&actual, &input);
373   EXPECT_EQ(expected, actual);
374 }
375 
376 //////////////////////////////////////////////////////////////////////////
377 // MembershipCredentialDeserialize Tests
TEST_F(EpidMemberTest,MembershipCredentialDeserializeWorks)378 TEST_F(EpidMemberTest, MembershipCredentialDeserializeWorks) {
379   MembershipCredential const input = {
380       {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
381        0x00, 0x00, 0x00, 0x01},  // group id
382       {{{{0x46, 0xc9, 0x69, 0xee, 0xf4, 0x68, 0xe1, 0x5f, 0xac, 0xbf, 0xdd,
383           0x77, 0xeb, 0x4c, 0xaf, 0x8a, 0x87, 0x68, 0x3f, 0x4e, 0xda, 0xf2,
384           0x96, 0xec, 0x57, 0x08, 0x90, 0xe8, 0x19, 0x62, 0x54, 0xdb}}},
385        {{{0x1e, 0x52, 0x23, 0x16, 0x91, 0xe4, 0xa8, 0x1d, 0x9a, 0x1b, 0x8a,
386           0xad, 0x0a, 0xcf, 0x36, 0x4f, 0xae, 0x43, 0xde, 0x62, 0xff, 0xa6,
387           0x4b, 0xa8, 0x16, 0x24, 0x98, 0x80, 0x82, 0x80, 0x37, 0x77}}}},  // A
388       {0x0a, 0x30, 0xae, 0x43, 0xa1, 0xe0, 0xd7, 0xdf, 0x10, 0x5e, 0xaf,
389        0xd8, 0x5a, 0x61, 0x10, 0x86, 0xd0, 0x9d, 0xb9, 0xe4, 0x46, 0xdd,
390        0xb7, 0x1b, 0x00, 0x14, 0x7c, 0x6b, 0x13, 0x72, 0xc3, 0x77}  // x
391   };
392   NativeMembershipCredential const expected = {
393       {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
394        0x00, 0x00, 0x00, 0x01},  // group id
395       {{{{0x196254db, 0x570890e8, 0xdaf296ec, 0x87683f4e, 0xeb4caf8a,
396           0xacbfdd77, 0xf468e15f, 0x46c969ee}}},
397        {{{0x82803777, 0x16249880, 0xffa64ba8, 0xae43de62, 0x0acf364f,
398           0x9a1b8aad, 0x91e4a81d, 0x1e522316}}}},  // A
399       {0x1372c377, 0x00147c6b, 0x46ddb71b, 0xd09db9e4, 0x5a611086, 0x105eafd8,
400        0xa1e0d7df, 0x0a30ae43}  // x
401   };
402   NativeMembershipCredential actual = {0};
403   MembershipCredentialDeserialize(&actual, &input);
404   EXPECT_EQ(expected, actual);
405 }
406 
407 }  // namespace
408 
409 #endif  // SHARED
410