serialize-test.cc 20 KB

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