context-test.cc 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074
  1. /*############################################################################
  2. # Copyright 2016 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 VerifierCreate unit tests.
  19. */
  20. #include <vector>
  21. #include <cstring>
  22. #include "gtest/gtest.h"
  23. extern "C" {
  24. #include "epid/verifier/api.h"
  25. #include "epid/verifier/src/context.h"
  26. #include "epid/common/src/endian_convert.h"
  27. }
  28. #include "epid/verifier/unittests/verifier-testhelper.h"
  29. #include "epid/common-testhelper/verifier_wrapper-testhelper.h"
  30. #include "epid/common-testhelper/errors-testhelper.h"
  31. bool operator==(VerifierPrecomp const& lhs, VerifierPrecomp const& rhs) {
  32. return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs));
  33. }
  34. bool operator==(OctStr32 const& lhs, OctStr32 const& rhs) {
  35. return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs));
  36. }
  37. namespace {
  38. //////////////////////////////////////////////////////////////////////////
  39. // EpidVerifierCreate Tests
  40. TEST_F(EpidVerifierTest, CreateFailsGivenNullPointer) {
  41. VerifierCtx* ctx = nullptr;
  42. EXPECT_EQ(kEpidBadArgErr,
  43. EpidVerifierCreate(&this->kPubKeyStr, &this->kVerifierPrecompStr,
  44. nullptr));
  45. EpidVerifierDelete(&ctx);
  46. EXPECT_EQ(kEpidBadArgErr,
  47. EpidVerifierCreate(nullptr, &this->kVerifierPrecompStr, &ctx));
  48. EpidVerifierDelete(&ctx);
  49. }
  50. TEST_F(EpidVerifierTest, CreateSucceedsGivenNullPrecomp) {
  51. VerifierCtx* ctx = nullptr;
  52. EXPECT_EQ(kEpidNoErr, EpidVerifierCreate(&this->kPubKeyStr, nullptr, &ctx));
  53. EpidVerifierDelete(&ctx);
  54. }
  55. TEST_F(EpidVerifierTest, CreateSucceedsGivenNullPrecompUsingIkgfData) {
  56. VerifierCtx* ctx = nullptr;
  57. EXPECT_EQ(kEpidNoErr,
  58. EpidVerifierCreate(&this->kPubKeyIkgfStr, nullptr, &ctx));
  59. EpidVerifierDelete(&ctx);
  60. }
  61. TEST_F(EpidVerifierTest, CreateFailsGivenInvalidPubkey) {
  62. VerifierCtx* ctx = nullptr;
  63. GroupPubKey pubkey_with_bad_h1 = this->kPubKeyStr;
  64. pubkey_with_bad_h1.h1.x.data.data[31]++; // munge h1 so not in G1
  65. EXPECT_EQ(kEpidBadArgErr,
  66. EpidVerifierCreate(&pubkey_with_bad_h1, nullptr, &ctx));
  67. EpidVerifierDelete(&ctx);
  68. GroupPubKey pubkey_with_bad_h2 = this->kPubKeyStr;
  69. pubkey_with_bad_h2.h2.x.data.data[31]++; // munge h2 so not in G1
  70. EXPECT_EQ(kEpidBadArgErr,
  71. EpidVerifierCreate(&pubkey_with_bad_h2, nullptr, &ctx));
  72. EpidVerifierDelete(&ctx);
  73. GroupPubKey pubkey_with_bad_w = this->kPubKeyStr;
  74. pubkey_with_bad_w.w.x[0].data.data[31]++; // munge w so not in G2
  75. EXPECT_EQ(kEpidBadArgErr,
  76. EpidVerifierCreate(&pubkey_with_bad_w, nullptr, &ctx));
  77. EpidVerifierDelete(&ctx);
  78. }
  79. TEST_F(EpidVerifierTest, CreateFailsGivenBadGroupIdInPrecomp) {
  80. VerifierCtx* ctx = nullptr;
  81. // tweak GID
  82. auto verifier_precomp = this->kVerifierPrecompStr;
  83. verifier_precomp.gid.data[0] = ~verifier_precomp.gid.data[0];
  84. EXPECT_EQ(kEpidBadArgErr,
  85. EpidVerifierCreate(&this->kPubKeyStr, &verifier_precomp, &ctx));
  86. }
  87. //////////////////////////////////////////////////////////////////////////
  88. // EpidVerifierDelete Tests
  89. TEST_F(EpidVerifierTest, DeleteNullsVerifierCtx) {
  90. VerifierCtx* ctx = nullptr;
  91. EpidVerifierCreate(&this->kPubKeyStr, nullptr, &ctx);
  92. EpidVerifierDelete(&ctx);
  93. EXPECT_EQ(nullptr, ctx);
  94. }
  95. TEST_F(EpidVerifierTest, DeleteWorksGivenNullVerifierCtx) {
  96. EpidVerifierDelete(nullptr);
  97. VerifierCtx* ctx = nullptr;
  98. EpidVerifierDelete(&ctx);
  99. }
  100. //////////////////////////////////////////////////////////////////////////
  101. // EpidVerifierWritePrecomp
  102. TEST_F(EpidVerifierTest, WritePrecompFailsGivenNullPointer) {
  103. VerifierPrecomp precomp;
  104. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  105. VerifierCtx* ctx = verifier;
  106. EXPECT_EQ(kEpidBadArgErr, EpidVerifierWritePrecomp(nullptr, &precomp));
  107. EXPECT_EQ(kEpidBadArgErr, EpidVerifierWritePrecomp(ctx, nullptr));
  108. }
  109. TEST_F(EpidVerifierTest, WritePrecompSucceedGivenValidArgument) {
  110. VerifierPrecomp precomp;
  111. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  112. VerifierCtx* ctx = verifier;
  113. EXPECT_EQ(kEpidNoErr, EpidVerifierWritePrecomp(ctx, &precomp));
  114. VerifierPrecomp expected_precomp = this->kVerifierPrecompStr;
  115. EXPECT_EQ(expected_precomp, precomp);
  116. VerifierCtxObj verifier2(this->kPubKeyStr);
  117. VerifierCtx* ctx2 = verifier2;
  118. EXPECT_EQ(kEpidNoErr, EpidVerifierWritePrecomp(ctx2, &precomp));
  119. EXPECT_EQ(expected_precomp, precomp);
  120. }
  121. //////////////////////////////////////////////////////////////////////////
  122. // EpidVerifierSetPrivRl
  123. TEST_F(EpidVerifierTest, SetPrivRlFailsGivenNullPointer) {
  124. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  125. PrivRl prl = {{0}, {0}, {0}, {0}};
  126. prl.gid = this->kPubKeyStr.gid;
  127. EXPECT_EQ(kEpidBadArgErr, EpidVerifierSetPrivRl(nullptr, &prl, sizeof(prl)));
  128. EXPECT_EQ(kEpidBadArgErr,
  129. EpidVerifierSetPrivRl(verifier, nullptr, sizeof(prl)));
  130. }
  131. TEST_F(EpidVerifierTest, SetPrivRlFailsGivenZeroSize) {
  132. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  133. PrivRl prl = {{0}, {0}, {0}, {0}};
  134. prl.gid = this->kPubKeyStr.gid;
  135. EXPECT_EQ(kEpidBadArgErr, EpidVerifierSetPrivRl(verifier, &prl, 0));
  136. }
  137. // Size parameter must be at least big enough for n1 == 0 case
  138. TEST_F(EpidVerifierTest, SetPrivRlFailsGivenTooSmallSize) {
  139. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  140. PrivRl prl = {{0}, {0}, {0}, {0}};
  141. prl.gid = this->kPubKeyStr.gid;
  142. EXPECT_EQ(
  143. kEpidBadArgErr,
  144. EpidVerifierSetPrivRl(verifier, &prl, (sizeof(prl) - sizeof(prl.f)) - 1));
  145. prl.n1 = this->kOctStr32_1;
  146. EXPECT_EQ(
  147. kEpidBadArgErr,
  148. EpidVerifierSetPrivRl(verifier, &prl, (sizeof(prl) - sizeof(prl.f)) - 1));
  149. }
  150. // Size parameter must be cross-checked with n1 value in priv_rl
  151. TEST_F(EpidVerifierTest, SetPrivRlFailsGivenN1TooBigForSize) {
  152. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  153. PrivRl prl = {{0}, {0}, {0}, {0}};
  154. prl.gid = this->kPubKeyStr.gid;
  155. prl.n1 = this->kOctStr32_1;
  156. EXPECT_EQ(kEpidBadArgErr,
  157. EpidVerifierSetPrivRl(verifier, &prl, sizeof(prl) - sizeof(prl.f)));
  158. }
  159. TEST_F(EpidVerifierTest, SetPrivRlFailsGivenN1TooSmallForSize) {
  160. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  161. PrivRl prl = {{0}, {0}, {0}, {0}};
  162. prl.gid = this->kPubKeyStr.gid;
  163. EXPECT_EQ(kEpidBadArgErr, EpidVerifierSetPrivRl(verifier, &prl, sizeof(prl)));
  164. }
  165. TEST_F(EpidVerifierTest, SetPrivRlPassesGivenDefaultPrivRl) {
  166. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  167. PrivRl prl = {{0}, {0}, {0}, {0}};
  168. prl.gid = this->kPubKeyStr.gid;
  169. EXPECT_EQ(kEpidNoErr,
  170. EpidVerifierSetPrivRl(verifier, &prl, sizeof(prl) - sizeof(prl.f)));
  171. }
  172. TEST_F(EpidVerifierTest, SetPrivRlPassesGivenDefaultPrivRlUsingIkgfData) {
  173. VerifierCtxObj verifier(this->kPubKeyIkgfStr, this->kVerifierPrecompIkgfStr);
  174. PrivRl prl = {{0}, {0}, {0}, {0}};
  175. prl.gid = this->kPubKeyIkgfStr.gid;
  176. EXPECT_EQ(kEpidNoErr,
  177. EpidVerifierSetPrivRl(verifier, &prl, sizeof(prl) - sizeof(prl.f)));
  178. }
  179. TEST_F(EpidVerifierTest, SetPrivRlPassesGivenEmptyPrivRlUsingIkgfData) {
  180. VerifierCtxObj verifier(this->kPubKeyIkgfStr, this->kVerifierPrecompIkgfStr);
  181. uint8_t priv_rl_data_n1_zero_ikgf[] = {
  182. #include "epid/common-testhelper/testdata/ikgf/groupa/privrl_empty.inc"
  183. };
  184. PrivRl* priv_rl = reinterpret_cast<PrivRl*>(priv_rl_data_n1_zero_ikgf);
  185. size_t priv_rl_size = sizeof(priv_rl_data_n1_zero_ikgf);
  186. EXPECT_EQ(kEpidNoErr, EpidVerifierSetPrivRl(verifier, priv_rl, priv_rl_size));
  187. }
  188. TEST_F(EpidVerifierTest, SetPrivRlPassesGivenPrivRlWithSingleElement) {
  189. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  190. PrivRl prl = {{0}, {0}, {0}, {0}};
  191. prl.gid = this->kPubKeyStr.gid;
  192. prl.n1 = this->kOctStr32_1;
  193. EXPECT_EQ(kEpidNoErr, EpidVerifierSetPrivRl(verifier, &prl, sizeof(prl)));
  194. }
  195. TEST_F(EpidVerifierTest, SetPrivRlFailsGivenBadGroupId) {
  196. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  197. PrivRl prl = {{0}, {0}, {0}, {0}};
  198. prl.gid = this->kPubKeyStr.gid;
  199. prl.gid.data[0] = ~prl.gid.data[0];
  200. prl.n1 = this->kOctStr32_1;
  201. EXPECT_EQ(kEpidBadArgErr, EpidVerifierSetPrivRl(verifier, &prl, sizeof(prl)));
  202. }
  203. TEST_F(EpidVerifierTest,
  204. SetPrivRlFailsGivenEmptyPrivRlFromDifferentGroupUsingIkgfData) {
  205. VerifierCtxObj verifier(this->kPubKeyRevGroupIkgfStr);
  206. auto& priv_rl = this->kEmptyPrivRlIkgf;
  207. EXPECT_EQ(kEpidBadArgErr,
  208. EpidVerifierSetPrivRl(verifier, (PrivRl const*)priv_rl.data(),
  209. priv_rl.size()));
  210. }
  211. TEST_F(EpidVerifierTest, SetPrivRlFailsGivenOldVersion) {
  212. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  213. PrivRl prl = {{0}, {0}, {0}, {0}};
  214. prl.gid = this->kPubKeyStr.gid;
  215. prl.version = this->kOctStr32_1;
  216. EXPECT_EQ(kEpidNoErr,
  217. EpidVerifierSetPrivRl(verifier, &prl, sizeof(prl) - sizeof(prl.f)));
  218. OctStr32 octstr32_0 = {0x00, 0x00, 0x00, 0x00};
  219. prl.version = octstr32_0;
  220. EXPECT_EQ(kEpidBadArgErr,
  221. EpidVerifierSetPrivRl(verifier, &prl, sizeof(prl) - sizeof(prl.f)));
  222. }
  223. //////////////////////////////////////////////////////////////////////////
  224. // EpidVerifierSetSigRl
  225. TEST_F(EpidVerifierTest, SetSigRlFailsGivenNullPointer) {
  226. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  227. SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}};
  228. srl.gid = this->kPubKeyStr.gid;
  229. EXPECT_EQ(kEpidBadArgErr, EpidVerifierSetSigRl(nullptr, &srl, sizeof(SigRl)));
  230. EXPECT_EQ(kEpidBadArgErr,
  231. EpidVerifierSetSigRl(verifier, nullptr, sizeof(SigRl)));
  232. }
  233. TEST_F(EpidVerifierTest, SetSigRlFailsGivenZeroSize) {
  234. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  235. SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}};
  236. srl.gid = this->kPubKeyStr.gid;
  237. EXPECT_EQ(kEpidBadArgErr, EpidVerifierSetSigRl(verifier, &srl, 0));
  238. }
  239. // Size parameter must be at least big enough for n2 == 0 case
  240. TEST_F(EpidVerifierTest, SetSigRlFailsGivenTooSmallSize) {
  241. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  242. SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}};
  243. srl.gid = this->kPubKeyStr.gid;
  244. EXPECT_EQ(
  245. kEpidBadArgErr,
  246. EpidVerifierSetSigRl(verifier, &srl, (sizeof(srl) - sizeof(srl.bk)) - 1));
  247. srl.n2 = this->kOctStr32_1;
  248. EXPECT_EQ(
  249. kEpidBadArgErr,
  250. EpidVerifierSetSigRl(verifier, &srl, (sizeof(srl) - sizeof(srl.bk)) - 1));
  251. }
  252. TEST_F(EpidVerifierTest, SetSigRlFailsGivenN2TooBigForSize) {
  253. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  254. SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}};
  255. srl.gid = this->kPubKeyStr.gid;
  256. srl.n2 = this->kOctStr32_1;
  257. EXPECT_EQ(kEpidBadArgErr,
  258. EpidVerifierSetSigRl(verifier, &srl, sizeof(srl) - sizeof(srl.bk)));
  259. }
  260. TEST_F(EpidVerifierTest, SetSigRlFailsGivenN2TooSmallForSize) {
  261. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  262. SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}};
  263. srl.gid = this->kPubKeyStr.gid;
  264. EXPECT_EQ(kEpidBadArgErr, EpidVerifierSetSigRl(verifier, &srl, sizeof(srl)));
  265. }
  266. TEST_F(EpidVerifierTest, SetSigRlWorksGivenDefaultSigRl) {
  267. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  268. VerifierCtx* ctx = verifier;
  269. SigRl const* sig_rl =
  270. reinterpret_cast<SigRl const*>(this->kGrp01SigRl.data());
  271. size_t sig_rl_size = this->kGrp01SigRl.size();
  272. EXPECT_EQ(kEpidNoErr, EpidVerifierSetSigRl(ctx, sig_rl, sig_rl_size));
  273. }
  274. TEST_F(EpidVerifierTest, SetSigRlWorksGivenDefaultSigRlUsingIkgfData) {
  275. VerifierCtxObj verifier(this->kPubKeyIkgfStr, this->kVerifierPrecompIkgfStr);
  276. VerifierCtx* ctx = verifier;
  277. SigRl const* sig_rl = reinterpret_cast<SigRl const*>(this->kSigRlIkgf.data());
  278. size_t sig_rl_size = this->kSigRlIkgf.size();
  279. EXPECT_EQ(kEpidNoErr, EpidVerifierSetSigRl(ctx, sig_rl, sig_rl_size));
  280. }
  281. TEST_F(EpidVerifierTest, SetSigRlWorksGivenSigRlWithNoElements) {
  282. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  283. uint8_t sig_rl_data_n2_zero[] = {
  284. // gid
  285. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  286. 0x00, 0x00, 0x00, 0x2A,
  287. // version
  288. 0x00, 0x00, 0x00, 0x00,
  289. // n2
  290. 0x0, 0x00, 0x00, 0x00,
  291. // not bk's
  292. };
  293. SigRl* sig_rl = reinterpret_cast<SigRl*>(sig_rl_data_n2_zero);
  294. size_t sig_rl_size = sizeof(sig_rl_data_n2_zero);
  295. EXPECT_EQ(kEpidNoErr, EpidVerifierSetSigRl(verifier, sig_rl, sig_rl_size));
  296. }
  297. TEST_F(EpidVerifierTest, SetSigRlWorksGivenSigRlWithNoElementsUsingIkgfData) {
  298. VerifierCtxObj verifier(this->kPubKeyIkgfStr, this->kVerifierPrecompIkgfStr);
  299. auto& sig_rl = this->kEmptySigRlIkgf;
  300. EXPECT_EQ(kEpidNoErr,
  301. EpidVerifierSetSigRl(verifier, (SigRl const*)sig_rl.data(),
  302. sig_rl.size()));
  303. }
  304. TEST_F(EpidVerifierTest, SetSigRlWorksGivenSigRlWithOneElement) {
  305. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  306. uint8_t sig_rl_data_n2_one[] = {
  307. // gid
  308. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  309. 0x00, 0x00, 0x00, 0x2A,
  310. // version
  311. 0x00, 0x00, 0x00, 0x00,
  312. // n2
  313. 0x0, 0x00, 0x00, 0x01,
  314. // one bk
  315. 0x9c, 0xa5, 0xe5, 0xae, 0x5f, 0xae, 0x51, 0x59, 0x33, 0x35, 0x27, 0xd,
  316. 0x8, 0xb1, 0xbe, 0x5d, 0x69, 0x50, 0x84, 0xc5, 0xfe, 0xe2, 0x87, 0xea,
  317. 0x2e, 0xef, 0xfa, 0xee, 0x67, 0xf2, 0xd8, 0x28, 0x56, 0x43, 0xc6, 0x94,
  318. 0x67, 0xa6, 0x72, 0xf6, 0x41, 0x15, 0x4, 0x58, 0x42, 0x16, 0x88, 0x57,
  319. 0x9d, 0xc7, 0x71, 0xd1, 0xc, 0x84, 0x13, 0xa, 0x90, 0x23, 0x18, 0x8, 0xad,
  320. 0x7d, 0xfe, 0xf5, 0xc8, 0xae, 0xfc, 0x51, 0x40, 0xa7, 0xd1, 0x28, 0xc2,
  321. 0x89, 0xb2, 0x6b, 0x4e, 0xb4, 0xc1, 0x55, 0x87, 0x98, 0xbd, 0x72, 0xf9,
  322. 0xcf, 0xd, 0x40, 0x15, 0xee, 0x32, 0xc, 0xf3, 0x56, 0xc5, 0xc, 0x61, 0x9d,
  323. 0x4f, 0x7a, 0xb5, 0x2b, 0x16, 0xa9, 0xa3, 0x97, 0x38, 0xe2, 0xdd, 0x3a,
  324. 0x33, 0xad, 0xf6, 0x7b, 0x68, 0x8b, 0x68, 0xcf, 0xa3, 0xd3, 0x98, 0x37,
  325. 0xce, 0xec, 0xd1, 0xa8, 0xc, 0x8b};
  326. SigRl* sig_rl = reinterpret_cast<SigRl*>(sig_rl_data_n2_one);
  327. size_t sig_rl_size = sizeof(sig_rl_data_n2_one);
  328. EXPECT_EQ(kEpidNoErr, EpidVerifierSetSigRl(verifier, sig_rl, sig_rl_size));
  329. }
  330. TEST_F(EpidVerifierTest, SetSigRlFailsGivenBadGroupId) {
  331. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  332. SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}};
  333. srl.gid = this->kPubKeyStr.gid;
  334. srl.gid.data[0] = ~srl.gid.data[0];
  335. EXPECT_EQ(kEpidBadArgErr,
  336. EpidVerifierSetSigRl(verifier, &srl, sizeof(srl) - sizeof(srl.bk)));
  337. }
  338. TEST_F(EpidVerifierTest,
  339. SetPrivRlFailsGivenEmptySigRlFromDifferentGroupUsingIkgfData) {
  340. VerifierCtxObj verifier(this->kPubKeyRevGroupIkgfStr);
  341. auto& sig_rl = this->kEmptySigRlIkgf;
  342. EXPECT_EQ(kEpidBadArgErr,
  343. EpidVerifierSetSigRl(verifier, (SigRl const*)sig_rl.data(),
  344. sig_rl.size()));
  345. }
  346. TEST_F(EpidVerifierTest, SetSigRlFailsGivenOldVersion) {
  347. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  348. SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}};
  349. srl.gid = this->kPubKeyStr.gid;
  350. srl.version = this->kOctStr32_1;
  351. EXPECT_EQ(kEpidNoErr,
  352. EpidVerifierSetSigRl(verifier, &srl, sizeof(srl) - sizeof(srl.bk)));
  353. OctStr32 octstr32_0 = {0x00, 0x00, 0x00, 0x00};
  354. srl.version = octstr32_0;
  355. EXPECT_EQ(kEpidBadArgErr,
  356. EpidVerifierSetSigRl(verifier, &srl, sizeof(srl) - sizeof(srl.bk)));
  357. }
  358. //////////////////////////////////////////////////////////////////////////
  359. // EpidVerifierSetGroupRl
  360. TEST_F(EpidVerifierTest, SetGroupRlFailsGivenNullPointer) {
  361. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  362. GroupRl grl = {{0}, {0}, {0}};
  363. EXPECT_EQ(kEpidBadArgErr, EpidVerifierSetGroupRl(nullptr, &grl, sizeof(grl)));
  364. EXPECT_EQ(kEpidBadArgErr,
  365. EpidVerifierSetGroupRl(verifier, nullptr, sizeof(grl)));
  366. }
  367. TEST_F(EpidVerifierTest, SetGroupRlFailsGivenSizeZero) {
  368. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  369. GroupRl grl = {{0}, {0}, {0}};
  370. size_t grl_size = 0;
  371. EXPECT_EQ(kEpidBadArgErr, EpidVerifierSetGroupRl(verifier, &grl, grl_size));
  372. }
  373. TEST_F(EpidVerifierTest, SetGroupRlFailsGivenSizeTooSmall) {
  374. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  375. GroupRl grl = {{0}, {0}, {0}};
  376. size_t grl_size = sizeof(grl) - sizeof(grl.gid[0]);
  377. EXPECT_EQ(kEpidBadArgErr,
  378. EpidVerifierSetGroupRl(verifier, &grl, grl_size - 1));
  379. }
  380. TEST_F(EpidVerifierTest, SetGroupRlFailsGivenSizeTooLarge) {
  381. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  382. GroupRl grl = {{0}, {0}, {0}};
  383. size_t grl_size = sizeof(grl) - sizeof(grl.gid[0]);
  384. EXPECT_EQ(kEpidBadArgErr,
  385. EpidVerifierSetGroupRl(verifier, &grl, grl_size + 1));
  386. }
  387. TEST_F(EpidVerifierTest, SetGroupRlFailsGivenN3ZeroAndGroupRLSizeTooBig) {
  388. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  389. GroupRl* group_rl = (GroupRl*)this->kGroupRl3GidN0Buf.data();
  390. EXPECT_EQ(kEpidBadArgErr,
  391. EpidVerifierSetGroupRl(verifier, group_rl,
  392. this->kGroupRl3GidN0Buf.size()));
  393. }
  394. TEST_F(EpidVerifierTest, SetGroupRlFailsGivenN3TooSmall) {
  395. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  396. GroupRl* group_rl = (GroupRl*)this->kGroupRl3GidN2Buf.data();
  397. EXPECT_EQ(kEpidBadArgErr,
  398. EpidVerifierSetGroupRl(verifier, group_rl,
  399. this->kGroupRl3GidN2Buf.size()));
  400. }
  401. TEST_F(EpidVerifierTest, SetGroupRlFailsGivenN3TooLarge) {
  402. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  403. GroupRl* group_rl = (GroupRl*)this->kGroupRl3GidN4Buf.data();
  404. EXPECT_EQ(kEpidBadArgErr,
  405. EpidVerifierSetGroupRl(verifier, group_rl,
  406. this->kGroupRl3GidN4Buf.size()));
  407. }
  408. TEST_F(EpidVerifierTest, SetGroupRlSucceedsGivenEmptyRL) {
  409. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  410. GroupRl* empty_grl = (GroupRl*)this->kGroupRlEmptyBuf.data();
  411. size_t grl_size = this->kGroupRlEmptyBuf.size();
  412. EXPECT_EQ(kEpidNoErr, EpidVerifierSetGroupRl(verifier, empty_grl, grl_size));
  413. }
  414. TEST_F(EpidVerifierTest, SetGroupRlSucceedsGivenDefaultGroupRLUsingIkgfData) {
  415. VerifierCtxObj verifier(this->kPubKeyIkgfStr, this->kVerifierPrecompIkgfStr);
  416. GroupRl* empty_grl = (GroupRl*)this->kGroupRlEmptyBuf.data();
  417. size_t grl_size = this->kGroupRlEmptyBuf.size();
  418. EXPECT_EQ(kEpidNoErr, EpidVerifierSetGroupRl(verifier, empty_grl, grl_size));
  419. }
  420. TEST_F(EpidVerifierTest, SetGroupRlSucceedsGivenRLWith3gid) {
  421. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  422. GroupRl* group_rl = (GroupRl*)this->kGroupRl3GidBuf.data();
  423. EXPECT_EQ(kEpidNoErr, EpidVerifierSetGroupRl(verifier, group_rl,
  424. this->kGroupRl3GidBuf.size()));
  425. }
  426. TEST_F(EpidVerifierTest, SetGroupRlFailsGivenOldVersion) {
  427. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  428. GroupRl* group_rl = (GroupRl*)this->kGroupRl3GidBuf.data();
  429. EXPECT_EQ(kEpidNoErr, EpidVerifierSetGroupRl(verifier, group_rl,
  430. this->kGroupRl3GidBuf.size()));
  431. GroupRl* empty_grl = (GroupRl*)this->kGroupRlEmptyBuf.data();
  432. EXPECT_EQ(kEpidBadArgErr,
  433. EpidVerifierSetGroupRl(verifier, empty_grl,
  434. this->kGroupRlEmptyBuf.size()));
  435. }
  436. //////////////////////////////////////////////////////////////////////////
  437. // EpidVerifierSetVerifierRl
  438. TEST_F(EpidVerifierTest, SetVerifierRlFailsGivenNullPointer) {
  439. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  440. VerifierRl ver_rl = {{0}, {{0}, {0}}, {0}, {0}, {{{0}, {0}}}};
  441. ver_rl.gid = this->kPubKeyStr.gid;
  442. EXPECT_EQ(kEpidBadArgErr,
  443. EpidVerifierSetVerifierRl(nullptr, &ver_rl, sizeof(ver_rl)));
  444. EXPECT_EQ(kEpidBadArgErr,
  445. EpidVerifierSetVerifierRl(verifier, nullptr, sizeof(ver_rl)));
  446. }
  447. TEST_F(EpidVerifierTest, SetVerifierRlFailsGivenMismatchedBasename) {
  448. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  449. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha256));
  450. std::vector<uint8_t> wrong_bsn = this->kBasename1;
  451. wrong_bsn[wrong_bsn.size() - 1] ^= 1;
  452. VerifierCtx* ctx(verifier);
  453. size_t res_ver_rl_size = this->kGrp01VerRl.size();
  454. THROW_ON_EPIDERR(
  455. EpidVerifierSetBasename(ctx, wrong_bsn.data(), wrong_bsn.size()));
  456. EXPECT_EQ(
  457. kEpidBadArgErr,
  458. EpidVerifierSetVerifierRl(
  459. ctx, (VerifierRl const*)this->kGrp01VerRl.data(), res_ver_rl_size));
  460. }
  461. TEST_F(EpidVerifierTest, SerVerifierRlFailsGivenRandomBase) {
  462. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  463. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha256));
  464. VerifierCtx* ctx(verifier);
  465. size_t res_ver_rl_size = this->kGrp01VerRl.size();
  466. THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, nullptr, 0));
  467. EXPECT_EQ(
  468. kEpidInconsistentBasenameSetErr,
  469. EpidVerifierSetVerifierRl(
  470. ctx, (VerifierRl const*)this->kGrp01VerRl.data(), res_ver_rl_size));
  471. }
  472. TEST_F(EpidVerifierTest, SetVerifierRlFailsGivenSizeZero) {
  473. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  474. VerifierRl ver_rl = {{0}, {{0}, {0}}, {0}, {0}, {{{0}, {0}}}};
  475. ver_rl.gid = this->kPubKeyStr.gid;
  476. EXPECT_EQ(kEpidBadArgErr, EpidVerifierSetVerifierRl(verifier, &ver_rl, 0));
  477. }
  478. // Size parameter must be at least equal to minimum value for n4 == 0 case
  479. TEST_F(EpidVerifierTest, SetVerifierRlFailsGivenSizeTooSmall) {
  480. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  481. VerifierRl ver_rl = {{0}, {{0}, {0}}, {0}, {0}, {{{0}, {0}}}};
  482. ver_rl.gid = this->kPubKeyStr.gid;
  483. EXPECT_EQ(kEpidBadArgErr,
  484. EpidVerifierSetVerifierRl(
  485. verifier, &ver_rl, sizeof(ver_rl) - sizeof(ver_rl.K[0]) - 1));
  486. ver_rl.n4 = this->kOctStr32_1;
  487. EXPECT_EQ(kEpidBadArgErr,
  488. EpidVerifierSetVerifierRl(
  489. verifier, &ver_rl, sizeof(ver_rl) - sizeof(ver_rl.K[0]) - 1));
  490. }
  491. TEST_F(EpidVerifierTest, SetVerifierRlFailsGivenN4TooBigForSize) {
  492. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  493. VerifierRl ver_rl = {{0}, {{0}, {0}}, {0}, {0}, {{{0}, {0}}}};
  494. ver_rl.gid = this->kPubKeyStr.gid;
  495. ver_rl.n4 = this->kOctStr32_1;
  496. EXPECT_EQ(kEpidBadArgErr,
  497. EpidVerifierSetVerifierRl(verifier, &ver_rl,
  498. sizeof(ver_rl) - sizeof(ver_rl.K[0])));
  499. }
  500. TEST_F(EpidVerifierTest, SetVerifierRlFailsGivenN4TooSmallForSize) {
  501. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  502. VerifierRl ver_rl = {{0}, {{0}, {0}}, {0}, {0}, {{{0}, {0}}}};
  503. ver_rl.gid = this->kPubKeyStr.gid;
  504. EXPECT_EQ(kEpidBadArgErr,
  505. EpidVerifierSetVerifierRl(verifier, &ver_rl, sizeof(ver_rl)));
  506. }
  507. TEST_F(EpidVerifierTest, SetVerifierRlWorksGivenDefaultVerifierRl) {
  508. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  509. VerifierRl const* ver_rl_ptr =
  510. reinterpret_cast<VerifierRl const*>(this->kGrp01VerRl.data());
  511. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha256));
  512. THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, this->kBasename.data(),
  513. this->kBasename.size()));
  514. EXPECT_EQ(kEpidNoErr, EpidVerifierSetVerifierRl(verifier, ver_rl_ptr,
  515. this->kGrp01VerRl.size()));
  516. }
  517. TEST_F(EpidVerifierTest, SetVerifierRlCopiesGivenValidVerifierRl) {
  518. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  519. VerifierCtx* ctx(verifier);
  520. VerifierRl* ver_rl_ptr = (VerifierRl*)(this->kGrp01VerRl.data());
  521. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha256));
  522. THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, this->kBasename.data(),
  523. this->kBasename.size()));
  524. EXPECT_EQ(kEpidNoErr,
  525. EpidVerifierSetVerifierRl(
  526. ctx, ver_rl_ptr, this->kGrp01VerRl.size() * sizeof(uint8_t)));
  527. EXPECT_NE(ver_rl_ptr, ctx->verifier_rl);
  528. }
  529. TEST_F(EpidVerifierTest, SetVerifierRlWorksGivenVerifierRlWithNoElements) {
  530. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  531. VerifierRl* ver_rl_ptr = (VerifierRl*)(this->kEmptyGrp01VerRl.data());
  532. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha256));
  533. THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, this->kBasename1.data(),
  534. this->kBasename1.size()));
  535. EXPECT_EQ(kEpidNoErr,
  536. EpidVerifierSetVerifierRl(verifier, ver_rl_ptr,
  537. this->kEmptyGrp01VerRl.size()));
  538. }
  539. TEST_F(EpidVerifierTest, SetVerifierRlWorksGivenVerifierRlWithOneElement) {
  540. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  541. uint8_t ver_rl_data_n4_one[] = {
  542. // gid
  543. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  544. 0x00, 0x00, 0x00, 0x2A,
  545. // B
  546. 0x41, 0x63, 0xfd, 0x06, 0xb8, 0xb1, 0xa6, 0x32, 0xa5, 0xe3, 0xeb, 0xc4,
  547. 0x40, 0x11, 0x37, 0xc0, 0x62, 0x0d, 0xe1, 0xca, 0xe9, 0x79, 0xad, 0xff,
  548. 0x1d, 0x13, 0xb3, 0xda, 0xa0, 0x10, 0x8a, 0xa8, 0x30, 0x72, 0xa4, 0xe8,
  549. 0x27, 0xb5, 0xad, 0xdb, 0xac, 0x89, 0xd8, 0x37, 0x79, 0xd9, 0x8c, 0xd0,
  550. 0xb3, 0xef, 0x94, 0x17, 0x4f, 0x05, 0x53, 0x4c, 0x4d, 0xf0, 0x77, 0xf7,
  551. 0xb6, 0xaf, 0xb8, 0xfa,
  552. // version
  553. 0x00, 0x00, 0x00, 0x00,
  554. // n4
  555. 0x00, 0x00, 0x00, 0x01,
  556. // k's
  557. 0xdc, 0x41, 0x24, 0xe7, 0xb8, 0xf2, 0x6d, 0xc4, 0x01, 0xf9, 0x5d, 0xf8,
  558. 0xd9, 0x23, 0x32, 0x29, 0x0a, 0xe1, 0xf6, 0xdc, 0xa1, 0xef, 0x52, 0xf7,
  559. 0x3a, 0x3c, 0xe6, 0x7e, 0x3d, 0x0e, 0xe8, 0x86, 0xa9, 0x58, 0xf4, 0xfe,
  560. 0xfa, 0x8b, 0xe4, 0x1c, 0xad, 0x58, 0x5b, 0x1c, 0xc7, 0x54, 0xee, 0x7e,
  561. 0xe7, 0x12, 0x6a, 0x4b, 0x01, 0x63, 0xb4, 0xdb, 0x6e, 0xe7, 0x7a, 0xe9,
  562. 0x62, 0xa5, 0xb4, 0xe3,
  563. };
  564. VerifierRl* ver_rl_ptr = reinterpret_cast<VerifierRl*>(ver_rl_data_n4_one);
  565. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha256));
  566. THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, this->kBasename.data(),
  567. this->kBasename.size()));
  568. EXPECT_EQ(kEpidNoErr, EpidVerifierSetVerifierRl(verifier, ver_rl_ptr,
  569. sizeof(ver_rl_data_n4_one)));
  570. }
  571. TEST_F(EpidVerifierTest, CanSetVerifierRlTwice) {
  572. VerifierCtxObj verifier(this->kGrpXKey);
  573. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha256));
  574. THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, this->kBsn0.data(),
  575. this->kBsn0.size()));
  576. EXPECT_EQ(kEpidNoErr,
  577. EpidVerifierSetVerifierRl(
  578. verifier, reinterpret_cast<VerifierRl const*>(
  579. this->kGrpXBsn0VerRlSingleEntry.data()),
  580. this->kGrpXBsn0VerRlSingleEntry.size()));
  581. EXPECT_EQ(kEpidNoErr, EpidVerifierSetVerifierRl(
  582. verifier, reinterpret_cast<VerifierRl const*>(
  583. this->kGrpXBsn0Sha256VerRl.data()),
  584. this->kGrpXBsn0Sha256VerRl.size()));
  585. }
  586. TEST_F(EpidVerifierTest, SetVerifierRlFailsGivenBadGroupId) {
  587. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  588. VerifierRl ver_rl = {{0}, {{0}, {0}}, {0}, {0}, {{{0}, {0}}}};
  589. ver_rl.gid = this->kPubKeyStr.gid;
  590. VerifierRl* valid_ver_rl = (VerifierRl*)(this->kEmptyGrp01VerRl.data());
  591. ver_rl.B = valid_ver_rl->B;
  592. ver_rl.gid.data[0] = ~ver_rl.gid.data[0];
  593. EXPECT_EQ(kEpidBadArgErr,
  594. EpidVerifierSetVerifierRl(verifier, &ver_rl,
  595. sizeof(ver_rl) - sizeof(ver_rl.K[0])));
  596. }
  597. TEST_F(EpidVerifierTest, SetVerifierRlFailsGivenOldVersion) {
  598. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  599. VerifierRl ver_rl = {{0}, {{0}, {0}}, {0}, {0}, {{{0}, {0}}}};
  600. VerifierRl* valid_ver_rl = (VerifierRl*)(this->kEmptyGrp01VerRl.data());
  601. ver_rl.B = valid_ver_rl->B;
  602. ver_rl.gid = this->kPubKeyStr.gid;
  603. ver_rl.version = this->kOctStr32_1;
  604. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha256));
  605. THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, this->kBasename1.data(),
  606. this->kBasename1.size()));
  607. EXPECT_EQ(kEpidNoErr,
  608. EpidVerifierSetVerifierRl(verifier, &ver_rl,
  609. sizeof(ver_rl) - sizeof(ver_rl.K[0])));
  610. OctStr32 octstr32_0 = {0x00, 0x00, 0x00, 0x00};
  611. ver_rl.version = octstr32_0;
  612. EXPECT_EQ(kEpidBadArgErr,
  613. EpidVerifierSetVerifierRl(verifier, &ver_rl,
  614. sizeof(ver_rl) - sizeof(ver_rl.K[0])));
  615. }
  616. //////////////////////////////////////////////////////////////////////////
  617. // EpidGetVerifierRlSize
  618. TEST_F(EpidVerifierTest, GetVerifierRlSizeReturnsZeroGivenNoContext) {
  619. EXPECT_EQ((size_t)0, EpidGetVerifierRlSize(nullptr));
  620. }
  621. TEST_F(EpidVerifierTest, GetVerifierRlSizeReturnsZeroGivenRandomBase) {
  622. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  623. EXPECT_EQ((size_t)0, EpidGetVerifierRlSize(verifier));
  624. }
  625. TEST_F(EpidVerifierTest, GetVerifierRlSizeReturnsSizeOfEmptyOnNoVerRlSet) {
  626. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  627. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha256));
  628. THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, this->kBasename1.data(),
  629. this->kBasename1.size()));
  630. EXPECT_EQ(sizeof(VerifierRl) - sizeof(((VerifierRl*)0)->K[0]),
  631. EpidGetVerifierRlSize(verifier));
  632. }
  633. TEST_F(EpidVerifierTest, GetVerifierRlSizeWorksForEmptyVerifierRl) {
  634. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  635. VerifierRl* ver_rl_ptr = (VerifierRl*)(this->kEmptyGrp01VerRl.data());
  636. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha256));
  637. THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, this->kBasename1.data(),
  638. this->kBasename1.size()));
  639. THROW_ON_EPIDERR(EpidVerifierSetVerifierRl(verifier, ver_rl_ptr,
  640. this->kEmptyGrp01VerRl.size()));
  641. EXPECT_EQ(this->kEmptyGrp01VerRl.size(), EpidGetVerifierRlSize(verifier));
  642. }
  643. TEST_F(EpidVerifierTest, GetVerifierRlSizeWorksForShortVerifierRl) {
  644. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  645. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha256));
  646. THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, this->kBasename.data(),
  647. this->kBasename.size()));
  648. THROW_ON_EPIDERR(EpidVerifierSetVerifierRl(
  649. verifier, (VerifierRl*)this->kGrp01VerRlOneEntry.data(),
  650. this->kGrp01VerRlOneEntry.size()));
  651. EXPECT_EQ(this->kGrp01VerRlOneEntry.size(), EpidGetVerifierRlSize(verifier));
  652. }
  653. TEST_F(EpidVerifierTest, GetVerifierRlSizeWorksForLongVerifierRl) {
  654. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  655. std::vector<uint8_t> ver_rl_data_long = {
  656. // gid
  657. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  658. 0x00, 0x00, 0x00, 0x2A,
  659. // B
  660. 0x41, 0x63, 0xfd, 0x06, 0xb8, 0xb1, 0xa6, 0x32, 0xa5, 0xe3, 0xeb, 0xc4,
  661. 0x40, 0x11, 0x37, 0xc0, 0x62, 0x0d, 0xe1, 0xca, 0xe9, 0x79, 0xad, 0xff,
  662. 0x1d, 0x13, 0xb3, 0xda, 0xa0, 0x10, 0x8a, 0xa8, 0x30, 0x72, 0xa4, 0xe8,
  663. 0x27, 0xb5, 0xad, 0xdb, 0xac, 0x89, 0xd8, 0x37, 0x79, 0xd9, 0x8c, 0xd0,
  664. 0xb3, 0xef, 0x94, 0x17, 0x4f, 0x05, 0x53, 0x4c, 0x4d, 0xf0, 0x77, 0xf7,
  665. 0xb6, 0xaf, 0xb8, 0xfa,
  666. // version
  667. 0x00, 0x00, 0x00, 0x32,
  668. // n4
  669. 0x00, 0x00, 0x00, 0x32};
  670. const std::vector<uint8_t> entry = {
  671. 0xdc, 0x41, 0x24, 0xe7, 0xb8, 0xf2, 0x6d, 0xc4, 0x01, 0xf9, 0x5d,
  672. 0xf8, 0xd9, 0x23, 0x32, 0x29, 0x0a, 0xe1, 0xf6, 0xdc, 0xa1, 0xef,
  673. 0x52, 0xf7, 0x3a, 0x3c, 0xe6, 0x7e, 0x3d, 0x0e, 0xe8, 0x86, 0xa9,
  674. 0x58, 0xf4, 0xfe, 0xfa, 0x8b, 0xe4, 0x1c, 0xad, 0x58, 0x5b, 0x1c,
  675. 0xc7, 0x54, 0xee, 0x7e, 0xe7, 0x12, 0x6a, 0x4b, 0x01, 0x63, 0xb4,
  676. 0xdb, 0x6e, 0xe7, 0x7a, 0xe9, 0x62, 0xa5, 0xb4, 0xe3};
  677. for (uint32_t i = 0; i < ntohl(((VerifierRl*)ver_rl_data_long.data())->n4);
  678. ++i) {
  679. for (auto it : entry) {
  680. ver_rl_data_long.push_back(it);
  681. }
  682. }
  683. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha256));
  684. THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, this->kBasename.data(),
  685. this->kBasename.size()));
  686. THROW_ON_EPIDERR(EpidVerifierSetVerifierRl(
  687. verifier, (VerifierRl*)ver_rl_data_long.data(), ver_rl_data_long.size()));
  688. EXPECT_EQ(ver_rl_data_long.size(), EpidGetVerifierRlSize(verifier));
  689. }
  690. //////////////////////////////////////////////////////////////////////////
  691. // EpidWriteVerifierRl
  692. TEST_F(EpidVerifierTest, WriteVerifierRlFailsGivenNullPointer) {
  693. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  694. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha256));
  695. THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, this->kBasename.data(),
  696. this->kBasename.size()));
  697. VerifierCtx* ctx(verifier);
  698. VerifierRl res_ver_rl = {0};
  699. size_t res_ver_rl_size = this->kGrp01VerRl.size();
  700. THROW_ON_EPIDERR(EpidVerifierSetVerifierRl(
  701. ctx, (VerifierRl const*)this->kGrp01VerRl.data(), res_ver_rl_size));
  702. EXPECT_EQ(kEpidBadArgErr,
  703. EpidWriteVerifierRl(nullptr, &res_ver_rl, res_ver_rl_size));
  704. EXPECT_EQ(kEpidBadArgErr, EpidWriteVerifierRl(ctx, nullptr, res_ver_rl_size));
  705. }
  706. TEST_F(EpidVerifierTest, WriteVerifierRlFailsGivenInvalidSize) {
  707. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  708. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha256));
  709. THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, this->kBasename.data(),
  710. this->kBasename.size()));
  711. VerifierCtx* ctx(verifier);
  712. VerifierRl res_ver_rl = {0};
  713. size_t res_ver_rl_size = this->kGrp01VerRl.size();
  714. THROW_ON_EPIDERR(EpidVerifierSetVerifierRl(
  715. ctx, (VerifierRl const*)this->kGrp01VerRl.data(), res_ver_rl_size));
  716. EXPECT_EQ(kEpidBadArgErr,
  717. EpidWriteVerifierRl(ctx, &res_ver_rl, res_ver_rl_size - 1));
  718. EXPECT_EQ(kEpidBadArgErr,
  719. EpidWriteVerifierRl(ctx, &res_ver_rl, res_ver_rl_size + 1));
  720. }
  721. TEST_F(EpidVerifierTest, WriteVerifierRlWorksForEmptyVerifierRl) {
  722. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  723. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha256));
  724. THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, this->kBasename1.data(),
  725. this->kBasename1.size()));
  726. VerifierCtx* ctx(verifier);
  727. size_t res_ver_rl_size = sizeof(VerifierRl) - sizeof(((VerifierRl*)0)->K[0]);
  728. std::vector<uint8_t> expected_ver_rl_buf = this->kEmptyGrp01VerRl;
  729. std::vector<uint8_t> res_ver_rl_buf(res_ver_rl_size);
  730. VerifierRl* res_ver_rl = (VerifierRl*)res_ver_rl_buf.data();
  731. THROW_ON_EPIDERR(EpidVerifierSetVerifierRl(
  732. ctx, (VerifierRl*)this->kEmptyGrp01VerRl.data(), res_ver_rl_size));
  733. EXPECT_EQ(kEpidNoErr, EpidWriteVerifierRl(ctx, res_ver_rl, res_ver_rl_size));
  734. EXPECT_EQ(expected_ver_rl_buf, res_ver_rl_buf);
  735. }
  736. TEST_F(EpidVerifierTest, WriteVerifierRlCanSerializeDefaultVerifierRl) {
  737. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  738. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha256));
  739. THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, this->kBasename1.data(),
  740. this->kBasename1.size()));
  741. VerifierCtx* ctx(verifier);
  742. size_t res_ver_rl_size = sizeof(VerifierRl) - sizeof(((VerifierRl*)0)->K[0]);
  743. std::vector<uint8_t> empty_verifier_rl_buf(res_ver_rl_size);
  744. std::vector<uint8_t> res_ver_rl_buf(res_ver_rl_size);
  745. VerifierRl* empty_verifier_rl = (VerifierRl*)empty_verifier_rl_buf.data();
  746. VerifierRl* res_ver_rl = (VerifierRl*)res_ver_rl_buf.data();
  747. empty_verifier_rl->gid = ctx->pub_key->gid;
  748. empty_verifier_rl->B =
  749. ((EpidSignature const*)this->kSigGrp01Member0Sha256Basename1Test1NoSigRl
  750. .data())
  751. ->sigma0.B;
  752. empty_verifier_rl->n4 = {0};
  753. empty_verifier_rl->version = {0};
  754. EXPECT_EQ(kEpidNoErr, EpidWriteVerifierRl(ctx, res_ver_rl, res_ver_rl_size));
  755. EXPECT_EQ(empty_verifier_rl_buf, res_ver_rl_buf);
  756. }
  757. TEST_F(EpidVerifierTest, WriteVerifierRlWorksForNonEmptyVerifierRl) {
  758. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  759. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha256));
  760. THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, this->kBasename.data(),
  761. this->kBasename.size()));
  762. VerifierCtx* ctx(verifier);
  763. auto expected_ver_rl = this->kGrp01VerRl;
  764. std::vector<uint8_t> resultant_ver_rl_buf(this->kGrp01VerRl.size());
  765. VerifierRl* resultant_ver_rl = (VerifierRl*)resultant_ver_rl_buf.data();
  766. THROW_ON_EPIDERR(EpidVerifierSetVerifierRl(
  767. ctx, (VerifierRl const*)this->kGrp01VerRl.data(),
  768. this->kGrp01VerRl.size()));
  769. EXPECT_EQ(kEpidNoErr, EpidWriteVerifierRl(ctx, resultant_ver_rl,
  770. resultant_ver_rl_buf.size()));
  771. EXPECT_EQ(expected_ver_rl, resultant_ver_rl_buf);
  772. }
  773. //////////////////////////////////////////////////////////////////////////
  774. // EpidBlacklistSig
  775. TEST_F(EpidVerifierTest, BlacklistSigFailsGivenNullPointer) {
  776. VerifierCtxObj verifier(this->kGrpXKey);
  777. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha256));
  778. auto sig = this->kSigGrpXMember0Sha256Bsn0Msg0;
  779. auto msg = this->kMsg0;
  780. auto bsn = this->kBsn0;
  781. THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, bsn.data(), bsn.size()));
  782. EXPECT_EQ(kEpidBadArgErr,
  783. EpidBlacklistSig(nullptr, (EpidSignature*)sig.data(), sig.size(),
  784. msg.data(), msg.size()));
  785. EXPECT_EQ(kEpidBadArgErr, EpidBlacklistSig(verifier, nullptr, sig.size(),
  786. msg.data(), msg.size()));
  787. EXPECT_EQ(kEpidBadArgErr,
  788. EpidBlacklistSig(verifier, (EpidSignature*)sig.data(), sig.size(),
  789. nullptr, 1));
  790. }
  791. TEST_F(EpidVerifierTest, BlacklistSigFailsGivenInvalidSignatureLength) {
  792. VerifierCtxObj verifier(this->kGrpXKey);
  793. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha256));
  794. auto sig = this->kSigGrpXMember0Sha256Bsn0Msg0;
  795. auto msg = this->kMsg0;
  796. auto bsn = this->kBsn0;
  797. THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, bsn.data(), bsn.size()));
  798. EXPECT_EQ(kEpidBadArgErr,
  799. EpidBlacklistSig(verifier, (EpidSignature*)sig.data(), 0,
  800. msg.data(), msg.size()));
  801. EXPECT_EQ(kEpidBadArgErr,
  802. EpidBlacklistSig(verifier, (EpidSignature*)sig.data(),
  803. sig.size() - 1, msg.data(), msg.size()));
  804. EXPECT_EQ(kEpidBadArgErr,
  805. EpidBlacklistSig(verifier, (EpidSignature*)sig.data(),
  806. sig.size() + 1, msg.data(), msg.size()));
  807. }
  808. TEST_F(EpidVerifierTest, BlacklistSigFailsGivenSigFromDiffGroup) {
  809. VerifierCtxObj verifier(this->kGrpXKey);
  810. auto sig = this->kSigGrp01Member0Sha256Basename1Test1NoSigRl;
  811. auto msg = this->kTest1;
  812. auto bsn = this->kBasename1;
  813. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha256));
  814. THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, bsn.data(), bsn.size()));
  815. EXPECT_EQ(kEpidBadArgErr,
  816. EpidBlacklistSig(verifier, (EpidSignature*)sig.data(), sig.size(),
  817. msg.data(), msg.size()));
  818. }
  819. TEST_F(EpidVerifierTest, BlacklistSigFailsGivenSigFromDiffBasename) {
  820. VerifierCtxObj verifier(this->kGrpXKey);
  821. auto sig = this->kSigGrpXMember0Sha256Bsn0Msg0;
  822. auto msg = this->kMsg0;
  823. auto bsn = this->kBasename1;
  824. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha256));
  825. THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, bsn.data(), bsn.size()));
  826. EXPECT_EQ(kEpidSigInvalid,
  827. EpidBlacklistSig(verifier, (EpidSignature*)sig.data(), sig.size(),
  828. msg.data(), msg.size()));
  829. }
  830. TEST_F(EpidVerifierTest, BlacklistSigFailsGivenSigWithDiffHashAlg) {
  831. VerifierCtxObj verifier(this->kGrpXKey);
  832. auto sig = this->kSigGrpXMember0Sha256Bsn0Msg0;
  833. auto msg = this->kMsg0;
  834. auto bsn = this->kBsn0;
  835. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha384));
  836. THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, bsn.data(), bsn.size()));
  837. EXPECT_EQ(kEpidSigInvalid,
  838. EpidBlacklistSig(verifier, (EpidSignature*)sig.data(), sig.size(),
  839. msg.data(), msg.size()));
  840. }
  841. TEST_F(EpidVerifierTest, BlacklistSigFailsOnSigAlreadyInVerRl) {
  842. VerifierCtxObj verifier(this->kGrpXKey);
  843. auto sig = this->kSigGrpXVerRevokedMember0Sha256Bsn0Msg0;
  844. auto msg = this->kMsg0;
  845. auto bsn = this->kBsn0;
  846. auto ver_rl = this->kGrpXBsn0VerRlSingleEntry;
  847. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha256));
  848. THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, bsn.data(), bsn.size()));
  849. THROW_ON_EPIDERR(EpidVerifierSetVerifierRl(
  850. verifier, (VerifierRl*)ver_rl.data(), ver_rl.size()));
  851. EXPECT_EQ(kEpidSigRevokedInVerifierRl,
  852. EpidBlacklistSig(verifier, (EpidSignature*)sig.data(), sig.size(),
  853. msg.data(), msg.size()));
  854. }
  855. TEST_F(EpidVerifierTest, BlacklistSigFailsOnSigRevokedInSigRl) {
  856. VerifierCtxObj verifier(this->kGrpXKey);
  857. auto sig = this->kSigGrpXMember0Sha256Bsn0Msg0SingleEntrySigRl;
  858. auto msg = this->kMsg0;
  859. auto bsn = this->kBsn0;
  860. auto sig_rl = this->kGrpXSigRlMember0Sha256Bsn0Msg0OnlyEntry;
  861. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha256));
  862. THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, bsn.data(), bsn.size()));
  863. THROW_ON_EPIDERR(
  864. EpidVerifierSetSigRl(verifier, (SigRl*)sig_rl.data(), sig_rl.size()));
  865. EXPECT_EQ(kEpidSigRevokedInSigRl,
  866. EpidBlacklistSig(verifier, (EpidSignature*)sig.data(), sig.size(),
  867. msg.data(), msg.size()));
  868. }
  869. TEST_F(EpidVerifierTest, BlacklistSigFailsOnSigRevokedInPrivRl) {
  870. VerifierCtxObj verifier(this->kGrpXKey);
  871. auto sig = this->kSigGrpXRevokedPrivKey000Sha256Bsn0Msg0;
  872. auto msg = this->kMsg0;
  873. auto bsn = this->kBsn0;
  874. auto priv_rl = this->kGrpXPrivRl;
  875. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha256));
  876. THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, bsn.data(), bsn.size()));
  877. THROW_ON_EPIDERR(
  878. EpidVerifierSetPrivRl(verifier, (PrivRl*)priv_rl.data(), priv_rl.size()));
  879. EXPECT_EQ(kEpidSigRevokedInPrivRl,
  880. EpidBlacklistSig(verifier, (EpidSignature*)sig.data(), sig.size(),
  881. msg.data(), msg.size()));
  882. }
  883. TEST_F(EpidVerifierTest, BlacklistSigWorksForValidSigGivenEmptyBlacklist) {
  884. VerifierCtxObj verifier(this->kGrpXKey);
  885. auto sig = this->kSigGrpXMember0Sha256Bsn0Msg0;
  886. auto msg = this->kMsg0;
  887. auto bsn = this->kBsn0;
  888. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha256));
  889. THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, bsn.data(), bsn.size()));
  890. EXPECT_EQ(kEpidNoErr, EpidBlacklistSig(verifier, (EpidSignature*)sig.data(),
  891. sig.size(), msg.data(), msg.size()));
  892. std::vector<uint8_t> ver_rl_vec(EpidGetVerifierRlSize(verifier));
  893. VerifierRl* ver_rl = (VerifierRl*)ver_rl_vec.data();
  894. size_t ver_rl_size = ver_rl_vec.size();
  895. THROW_ON_EPIDERR(EpidWriteVerifierRl(verifier, ver_rl, ver_rl_size));
  896. OctStr32 n4_expected = {0x00, 0x00, 0x00, 0x01};
  897. OctStr32 rlver_expected = {0x00, 0x00, 0x00, 0x01};
  898. EXPECT_EQ(n4_expected, ver_rl->n4);
  899. EXPECT_EQ(rlver_expected, ver_rl->version);
  900. // missing K checks here
  901. }
  902. TEST_F(EpidVerifierTest,
  903. MultipleBlacklistFollowedBySerializeIncrementsRlVersionByOne) {
  904. VerifierCtxObj verifier(this->kGrpXKey);
  905. auto sig = this->kSigGrpXMember0Sha256Bsn0Msg0;
  906. auto msg = this->kMsg0;
  907. auto bsn = this->kBsn0;
  908. auto sig2 = this->kSigGrpXMember1Sha256Bsn0Msg0;
  909. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(verifier, kSha256));
  910. THROW_ON_EPIDERR(EpidVerifierSetBasename(verifier, bsn.data(), bsn.size()));
  911. EXPECT_EQ(kEpidNoErr, EpidBlacklistSig(verifier, (EpidSignature*)sig.data(),
  912. sig.size(), msg.data(), msg.size()));
  913. EXPECT_EQ(kEpidNoErr, EpidBlacklistSig(verifier, (EpidSignature*)sig2.data(),
  914. sig2.size(), msg.data(), msg.size()));
  915. std::vector<uint8_t> ver_rl_vec(EpidGetVerifierRlSize(verifier));
  916. VerifierRl* ver_rl = (VerifierRl*)ver_rl_vec.data();
  917. size_t ver_rl_size = ver_rl_vec.size();
  918. THROW_ON_EPIDERR(EpidWriteVerifierRl(verifier, ver_rl, ver_rl_size));
  919. OctStr32 n4_expected = {0x00, 0x00, 0x00, 0x02};
  920. OctStr32 rlver_expected = {0x00, 0x00, 0x00, 0x01};
  921. EXPECT_EQ(n4_expected, ver_rl->n4);
  922. EXPECT_EQ(rlver_expected, ver_rl->version);
  923. // missing K checks
  924. }
  925. //////////////////////////////////////////////////////////////////////////
  926. // EpidVerifierSetHashAlg
  927. TEST_F(EpidVerifierTest, SetHashAlgFailsGivenNullPointer) {
  928. EXPECT_EQ(kEpidBadArgErr, EpidVerifierSetHashAlg(nullptr, kSha256));
  929. }
  930. TEST_F(EpidVerifierTest, SetHashAlgCanSetValidAlgoritm) {
  931. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  932. EXPECT_EQ(kEpidNoErr, EpidVerifierSetHashAlg(verifier, kSha256));
  933. EXPECT_EQ(kEpidNoErr, EpidVerifierSetHashAlg(verifier, kSha384));
  934. EXPECT_EQ(kEpidNoErr, EpidVerifierSetHashAlg(verifier, kSha512));
  935. // DE2089 - SHA-512/256 Hash Alg is not supported by EpidMemberSetHashAlg
  936. // EXPECT_EQ(kEpidNoErr, EpidVerifierSetHashAlg(verifier, kSha512_256));
  937. }
  938. TEST_F(EpidVerifierTest, SetHashAlgCanFailForNonSupportedAlgoritms) {
  939. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  940. EXPECT_EQ(kEpidBadArgErr, EpidVerifierSetHashAlg(verifier, kSha3_256));
  941. EXPECT_EQ(kEpidBadArgErr, EpidVerifierSetHashAlg(verifier, kSha3_384));
  942. EXPECT_EQ(kEpidBadArgErr, EpidVerifierSetHashAlg(verifier, kSha3_512));
  943. EXPECT_EQ(kEpidBadArgErr, EpidVerifierSetHashAlg(verifier, (HashAlg)-1));
  944. }
  945. TEST_F(EpidVerifierTest, DefaultHashAlgIsSha512) {
  946. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  947. VerifierCtx* ctx = verifier;
  948. EXPECT_EQ(kSha512, ctx->hash_alg);
  949. }
  950. //////////////////////////////////////////////////////////////////////////
  951. // EpidVerifierSetBasename
  952. TEST_F(EpidVerifierTest, DefaultBasenameIsNull) {
  953. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  954. VerifierCtx* ctx = verifier;
  955. EXPECT_EQ(nullptr, ctx->basename_hash);
  956. }
  957. TEST_F(EpidVerifierTest, SetBasenameFailsGivenNullContext) {
  958. auto& basename = this->kBasename1;
  959. EXPECT_EQ(kEpidBadArgErr,
  960. EpidVerifierSetBasename(nullptr, basename.data(), basename.size()));
  961. }
  962. TEST_F(EpidVerifierTest, SetBasenameFailsGivenNullBasenameAndNonzeroLength) {
  963. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  964. VerifierCtx* ctx = verifier;
  965. auto& basename = this->kBasename1;
  966. EXPECT_EQ(kEpidBadArgErr,
  967. EpidVerifierSetBasename(ctx, nullptr, basename.size()));
  968. }
  969. TEST_F(EpidVerifierTest, SetBasenameSucceedsGivenValidParameters) {
  970. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  971. VerifierCtx* ctx = verifier;
  972. auto& basename = this->kBasename1;
  973. EXPECT_EQ(kEpidNoErr,
  974. EpidVerifierSetBasename(ctx, basename.data(), basename.size()));
  975. }
  976. TEST_F(EpidVerifierTest, SetBasenameAcceptsZeroLengthBasename) {
  977. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  978. VerifierCtx* ctx = verifier;
  979. EXPECT_EQ(kEpidNoErr, EpidVerifierSetBasename(ctx, "", 0));
  980. }
  981. TEST_F(EpidVerifierTest, SetBasenameResetsBasenameGivenNullBasename) {
  982. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  983. VerifierCtx* ctx = verifier;
  984. auto& basename = this->kBasename1;
  985. THROW_ON_EPIDERR(
  986. EpidVerifierSetBasename(ctx, basename.data(), basename.size()));
  987. THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, nullptr, 0));
  988. EXPECT_EQ(nullptr, ctx->basename_hash);
  989. }
  990. TEST_F(EpidVerifierTest, SetBasenameResetsVerifierBlacklist) {
  991. VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  992. VerifierCtx* ctx = verifier;
  993. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha256));
  994. THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, this->kBasename.data(),
  995. this->kBasename.size()));
  996. auto& basename = this->kBasename;
  997. VerifierRl const* ver_rl_ptr =
  998. reinterpret_cast<VerifierRl const*>(this->kGrp01VerRl.data());
  999. THROW_ON_EPIDERR(EpidVerifierSetVerifierRl(verifier, ver_rl_ptr,
  1000. this->kGrp01VerRl.size()));
  1001. THROW_ON_EPIDERR(
  1002. EpidVerifierSetBasename(ctx, basename.data(), basename.size()));
  1003. EXPECT_EQ(nullptr, ctx->verifier_rl);
  1004. }
  1005. } // namespace