context-test.cc 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. /*############################################################################
  2. # Copyright 2016-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 Epid11VerifierCreate unit tests.
  19. */
  20. #include <cstring>
  21. #include "epid/common-testhelper/epid_gtest-testhelper.h"
  22. #include "gtest/gtest.h"
  23. extern "C" {
  24. #include "epid/verifier/1.1/api.h"
  25. #include "epid/verifier/1.1/src/context.h"
  26. }
  27. #include "epid/common-testhelper/1.1/verifier_wrapper-testhelper.h"
  28. #include "epid/common-testhelper/errors-testhelper.h"
  29. #include "epid/verifier/1.1/unittests/verifier-testhelper.h"
  30. bool operator==(Epid11VerifierPrecomp const& lhs,
  31. Epid11VerifierPrecomp const& rhs) {
  32. return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs));
  33. }
  34. namespace {
  35. //////////////////////////////////////////////////////////////////////////
  36. // Epid11VerifierCreate Tests
  37. TEST_F(Epid11VerifierTest, CreateFailsGivenNullPointer) {
  38. Epid11VerifierCtx* ctx = nullptr;
  39. EXPECT_EQ(kEpidBadArgErr,
  40. Epid11VerifierCreate(&this->kPubKeyStr, &this->kVerifierPrecompStr,
  41. nullptr));
  42. Epid11VerifierDelete(&ctx);
  43. EXPECT_EQ(kEpidBadArgErr,
  44. Epid11VerifierCreate(nullptr, &this->kVerifierPrecompStr, &ctx));
  45. Epid11VerifierDelete(&ctx);
  46. }
  47. TEST_F(Epid11VerifierTest, CreateSucceedsGivenNullPrecomp) {
  48. Epid11VerifierCtx* ctx = nullptr;
  49. EXPECT_EQ(kEpidNoErr, Epid11VerifierCreate(&this->kPubKeyStr, nullptr, &ctx));
  50. Epid11VerifierDelete(&ctx);
  51. }
  52. TEST_F(Epid11VerifierTest, CreateSucceedsGivenValidPrecomp) {
  53. Epid11VerifierCtx* ctx = nullptr;
  54. EXPECT_EQ(kEpidNoErr, Epid11VerifierCreate(&this->kPubKeyStr,
  55. &this->kVerifierPrecompStr, &ctx));
  56. Epid11VerifierDelete(&ctx);
  57. }
  58. TEST_F(Epid11VerifierTest, CreateFailsGivenInvalidPubkey) {
  59. Epid11VerifierCtx* ctx = nullptr;
  60. Epid11GroupPubKey pubkey_with_bad_h1 = this->kPubKeyStr;
  61. pubkey_with_bad_h1.h1.x.data.data[31]++; // munge h1 so not in G1
  62. EXPECT_EQ(kEpidBadArgErr,
  63. Epid11VerifierCreate(&pubkey_with_bad_h1, nullptr, &ctx));
  64. Epid11VerifierDelete(&ctx);
  65. Epid11GroupPubKey pubkey_with_bad_h2 = this->kPubKeyStr;
  66. pubkey_with_bad_h2.h2.x.data.data[31]++; // munge h2 so not in G1
  67. EXPECT_EQ(kEpidBadArgErr,
  68. Epid11VerifierCreate(&pubkey_with_bad_h2, nullptr, &ctx));
  69. Epid11VerifierDelete(&ctx);
  70. Epid11GroupPubKey pubkey_with_bad_w = this->kPubKeyStr;
  71. pubkey_with_bad_w.w.x[0].data.data[31]++; // munge w so not in G2
  72. EXPECT_EQ(kEpidBadArgErr,
  73. Epid11VerifierCreate(&pubkey_with_bad_w, nullptr, &ctx));
  74. Epid11VerifierDelete(&ctx);
  75. }
  76. TEST_F(Epid11VerifierTest, CreateFailsGivenBadGroupIdInPrecomp) {
  77. Epid11VerifierCtx* ctx = nullptr;
  78. // tweak GID
  79. auto verifier_precomp = this->kVerifierPrecompStr;
  80. verifier_precomp.gid.data[0] = ~verifier_precomp.gid.data[0];
  81. EXPECT_EQ(kEpidBadArgErr,
  82. Epid11VerifierCreate(&this->kPubKeyStr, &verifier_precomp, &ctx));
  83. }
  84. //////////////////////////////////////////////////////////////////////////
  85. // Epid11VerifierDelete Tests
  86. TEST_F(Epid11VerifierTest, DeleteNullsVerifierCtx) {
  87. Epid11VerifierCtx* ctx = nullptr;
  88. THROW_ON_EPIDERR(Epid11VerifierCreate(&this->kPubKeyStr, nullptr, &ctx));
  89. Epid11VerifierDelete(&ctx);
  90. EXPECT_EQ(nullptr, ctx);
  91. }
  92. TEST_F(Epid11VerifierTest, DeleteWorksGivenNullVerifierCtx) {
  93. Epid11VerifierDelete(nullptr);
  94. Epid11VerifierCtx* ctx = nullptr;
  95. Epid11VerifierDelete(&ctx);
  96. }
  97. //////////////////////////////////////////////////////////////////////////
  98. // Epid11VerifierWritePrecomp
  99. TEST_F(Epid11VerifierTest, WritePrecompFailsGivenNullPointer) {
  100. Epid11VerifierPrecomp precomp;
  101. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  102. Epid11VerifierCtx* ctx = verifier;
  103. EXPECT_EQ(kEpidBadArgErr, Epid11VerifierWritePrecomp(nullptr, &precomp));
  104. EXPECT_EQ(kEpidBadArgErr, Epid11VerifierWritePrecomp(ctx, nullptr));
  105. }
  106. TEST_F(Epid11VerifierTest, WritePrecompSucceedGivenValidArgument) {
  107. Epid11VerifierPrecomp precomp;
  108. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  109. Epid11VerifierCtx* ctx = verifier;
  110. EXPECT_EQ(kEpidNoErr, Epid11VerifierWritePrecomp(ctx, &precomp));
  111. Epid11VerifierPrecomp expected_precomp = this->kVerifierPrecompStr;
  112. EXPECT_EQ(expected_precomp, precomp);
  113. Epid11VerifierCtxObj verifier2(this->kPubKeyStr);
  114. Epid11VerifierCtx* ctx2 = verifier2;
  115. EXPECT_EQ(kEpidNoErr, Epid11VerifierWritePrecomp(ctx2, &precomp));
  116. EXPECT_EQ(expected_precomp, precomp);
  117. }
  118. //////////////////////////////////////////////////////////////////////////
  119. // Epid11VerifierSetPrivRl
  120. TEST_F(Epid11VerifierTest, SetPrivRlFailsGivenNullPointer) {
  121. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  122. Epid11PrivRl prl = {0};
  123. prl.gid = this->kPubKeyStr.gid;
  124. EXPECT_EQ(kEpidBadArgErr,
  125. Epid11VerifierSetPrivRl(nullptr, &prl, sizeof(prl)));
  126. EXPECT_EQ(kEpidBadArgErr,
  127. Epid11VerifierSetPrivRl(verifier, nullptr, sizeof(prl)));
  128. }
  129. TEST_F(Epid11VerifierTest, SetPrivRlFailsGivenZeroSize) {
  130. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  131. Epid11PrivRl prl = {0};
  132. prl.gid = this->kPubKeyStr.gid;
  133. EXPECT_EQ(kEpidBadArgErr, Epid11VerifierSetPrivRl(verifier, &prl, 0));
  134. }
  135. // Size parameter must be at least big enough for n1 == 0 case
  136. TEST_F(Epid11VerifierTest, SetPrivRlFailsGivenTooSmallSize) {
  137. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  138. Epid11PrivRl prl = {0};
  139. prl.gid = this->kPubKeyStr.gid;
  140. EXPECT_EQ(kEpidBadArgErr,
  141. Epid11VerifierSetPrivRl(verifier, &prl,
  142. (sizeof(prl) - sizeof(prl.f)) - 1));
  143. prl.n1 = this->kOctStr32_1;
  144. EXPECT_EQ(kEpidBadArgErr,
  145. Epid11VerifierSetPrivRl(verifier, &prl,
  146. (sizeof(prl) - sizeof(prl.f)) - 1));
  147. }
  148. // Size parameter must be cross-checked with n1 value in priv_rl
  149. TEST_F(Epid11VerifierTest, SetPrivRlFailsGivenN1TooBigForSize) {
  150. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  151. Epid11PrivRl prl = {0};
  152. prl.gid = this->kPubKeyStr.gid;
  153. prl.n1 = this->kOctStr32_1;
  154. EXPECT_EQ(kEpidBadArgErr, Epid11VerifierSetPrivRl(
  155. verifier, &prl, sizeof(prl) - sizeof(prl.f)));
  156. }
  157. TEST_F(Epid11VerifierTest, SetPrivRlFailsGivenN1TooSmallForSize) {
  158. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  159. Epid11PrivRl prl = {0};
  160. prl.gid = this->kPubKeyStr.gid;
  161. EXPECT_EQ(kEpidBadArgErr,
  162. Epid11VerifierSetPrivRl(verifier, &prl, sizeof(prl)));
  163. }
  164. TEST_F(Epid11VerifierTest, SetPrivRlPassesGivenDefaultPrivRl) {
  165. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  166. Epid11PrivRl prl = {0};
  167. prl.gid = this->kPubKeyStr.gid;
  168. EXPECT_EQ(kEpidNoErr, Epid11VerifierSetPrivRl(verifier, &prl,
  169. sizeof(prl) - sizeof(prl.f)));
  170. }
  171. TEST_F(Epid11VerifierTest, SetPrivRlPassesGivenPrivRlWithSingleElement) {
  172. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  173. Epid11PrivRl prl = {0};
  174. prl.gid = this->kPubKeyStr.gid;
  175. prl.n1 = this->kOctStr32_1;
  176. EXPECT_EQ(kEpidNoErr, Epid11VerifierSetPrivRl(verifier, &prl, sizeof(prl)));
  177. }
  178. TEST_F(Epid11VerifierTest, SetPrivRlFailsGivenBadGroupId) {
  179. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  180. Epid11PrivRl prl = {0};
  181. prl.gid = this->kPubKeyStr.gid;
  182. prl.gid.data[0] = ~prl.gid.data[0];
  183. prl.n1 = this->kOctStr32_1;
  184. EXPECT_EQ(kEpidBadArgErr,
  185. Epid11VerifierSetPrivRl(verifier, &prl, sizeof(prl)));
  186. }
  187. TEST_F(Epid11VerifierTest, SetPrivRlFailsGivenOldVersion) {
  188. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  189. Epid11PrivRl prl = {0};
  190. prl.gid = this->kPubKeyStr.gid;
  191. prl.version = this->kOctStr32_1;
  192. EXPECT_EQ(kEpidNoErr, Epid11VerifierSetPrivRl(verifier, &prl,
  193. sizeof(prl) - sizeof(prl.f)));
  194. OctStr32 octstr32_0 = {0x00, 0x00, 0x00, 0x00};
  195. prl.version = octstr32_0;
  196. EXPECT_EQ(kEpidBadArgErr, Epid11VerifierSetPrivRl(
  197. verifier, &prl, sizeof(prl) - sizeof(prl.f)));
  198. }
  199. //////////////////////////////////////////////////////////////////////////
  200. // Epid11VerifierSetSigRl
  201. TEST_F(Epid11VerifierTest, SetSigRlFailsGivenNullPointer) {
  202. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  203. Epid11SigRl* empty_sig_rl = (Epid11SigRl*)this->kEmptySigRl.data();
  204. EXPECT_EQ(kEpidBadArgErr,
  205. Epid11VerifierSetSigRl(nullptr, empty_sig_rl, sizeof(Epid11SigRl)));
  206. EXPECT_EQ(kEpidBadArgErr,
  207. Epid11VerifierSetSigRl(verifier, nullptr, sizeof(Epid11SigRl)));
  208. }
  209. TEST_F(Epid11VerifierTest, SetSigRlFailsGivenZeroSize) {
  210. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  211. Epid11SigRl* empty_sig_rl = (Epid11SigRl*)this->kEmptySigRl.data();
  212. EXPECT_EQ(kEpidBadArgErr, Epid11VerifierSetSigRl(verifier, empty_sig_rl, 0));
  213. }
  214. // Size parameter must be at least big enough for n2 == 0 case
  215. TEST_F(Epid11VerifierTest, SetSigRlFailsGivenTooSmallSize) {
  216. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  217. std::vector<uint8_t> empty_sig_rl_buf(this->kEmptySigRl);
  218. Epid11SigRl* empty_sig_rl = (Epid11SigRl*)empty_sig_rl_buf.data();
  219. EXPECT_EQ(kEpidBadArgErr,
  220. Epid11VerifierSetSigRl(
  221. verifier, empty_sig_rl,
  222. (sizeof(*empty_sig_rl) - sizeof(empty_sig_rl->bk)) - 1));
  223. empty_sig_rl->n2 = this->kOctStr32_1;
  224. EXPECT_EQ(kEpidBadArgErr,
  225. Epid11VerifierSetSigRl(
  226. verifier, empty_sig_rl,
  227. (sizeof(*empty_sig_rl) - sizeof(empty_sig_rl->bk)) - 1));
  228. }
  229. TEST_F(Epid11VerifierTest, SetSigRlFailsGivenN2TooBigForSize) {
  230. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  231. std::vector<uint8_t> empty_sig_rl_buf(this->kEmptySigRl);
  232. Epid11SigRl* empty_sig_rl = (Epid11SigRl*)empty_sig_rl_buf.data();
  233. empty_sig_rl->n2 = this->kOctStr32_1;
  234. EXPECT_EQ(
  235. kEpidBadArgErr,
  236. Epid11VerifierSetSigRl(verifier, empty_sig_rl,
  237. sizeof(*empty_sig_rl) - sizeof(empty_sig_rl->bk)));
  238. }
  239. TEST_F(Epid11VerifierTest, SetSigRlFailsGivenN2TooSmallForSize) {
  240. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  241. std::vector<uint8_t> empty_sig_rl_buf(this->kEmptySigRl);
  242. Epid11SigRl* empty_sig_rl = (Epid11SigRl*)empty_sig_rl_buf.data();
  243. EXPECT_EQ(kEpidBadArgErr, Epid11VerifierSetSigRl(verifier, empty_sig_rl,
  244. sizeof(*empty_sig_rl)));
  245. }
  246. TEST_F(Epid11VerifierTest, SetSigRlWorksGivenSigRlWithNoElements) {
  247. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  248. std::vector<uint8_t> empty_sig_rl_buf(this->kEmptySigRl);
  249. Epid11SigRl* empty_sig_rl = (Epid11SigRl*)empty_sig_rl_buf.data();
  250. size_t sig_rl_size = empty_sig_rl_buf.size() * sizeof(uint8_t);
  251. EXPECT_EQ(kEpidNoErr,
  252. Epid11VerifierSetSigRl(verifier, empty_sig_rl, sig_rl_size));
  253. }
  254. TEST_F(Epid11VerifierTest, SetSigRlWorksGivenSigRlWithOneElement) {
  255. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  256. uint8_t sig_rl_data_n2_one[] = {
  257. // gid
  258. 0x00, 0x00, 0x00, 0x7b,
  259. // rev
  260. 0x00, 0x00, 0x00, 0x7b,
  261. // n2
  262. 0x00, 0x00, 0x00, 0x01,
  263. // bks
  264. // bk1
  265. 0x67, 0x58, 0xb2, 0x9c, 0xad, 0x61, 0x1f, 0xfb, 0x74, 0x23, 0xea, 0x40,
  266. 0xe9, 0x66, 0x26, 0xb0, 0x43, 0xdc, 0x7e, 0xc7, 0x48, 0x88, 0x56, 0x59,
  267. 0xf3, 0x35, 0x9f, 0xdb, 0xfa, 0xa2, 0x49, 0x51, 0x85, 0x35, 0x42, 0x50,
  268. 0x8e, 0x79, 0x79, 0xc0, 0x6c, 0xcc, 0x39, 0x0b, 0xad, 0x3b, 0x39, 0x33,
  269. 0xae, 0xb2, 0xa1, 0xc5, 0x28, 0x6f, 0x48, 0x3a, 0xd2, 0x63, 0x5d, 0xfb,
  270. 0x1b, 0x1f, 0x8a, 0x63, 0x84, 0xdc, 0x2d, 0xad, 0x3b, 0x98, 0x3f, 0xc3,
  271. 0x8e, 0x18, 0xd7, 0xea, 0x18, 0x50, 0x0c, 0x50, 0x42, 0x77, 0xb2, 0x59,
  272. 0xf5, 0xd5, 0x38, 0xc3, 0x8d, 0x57, 0xf4, 0xe7, 0xb8, 0x74, 0x5a, 0x9e,
  273. 0x32, 0x75, 0xd1, 0xb4, 0xb3, 0x64, 0xbc, 0x23, 0xcd, 0x98, 0x29, 0x7a,
  274. 0x77, 0x51, 0xfc, 0x26, 0x81, 0x41, 0x9b, 0xf6, 0x21, 0xad, 0xc1, 0xd9,
  275. 0xab, 0x30, 0x25, 0x8d, 0x0c, 0x3b, 0x62, 0xe2};
  276. Epid11SigRl* sig_rl = reinterpret_cast<Epid11SigRl*>(sig_rl_data_n2_one);
  277. EXPECT_EQ(kEpidNoErr,
  278. Epid11VerifierSetSigRl(verifier, sig_rl, sizeof(*sig_rl)));
  279. }
  280. TEST_F(Epid11VerifierTest, SetSigRlWorksGivenSigRlWithTwoElement) {
  281. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  282. Epid11VerifierCtx* ctx = verifier;
  283. Epid11SigRl const* sig_rl =
  284. reinterpret_cast<Epid11SigRl const*>(this->kSigRl.data());
  285. size_t sig_rl_size = this->kSigRl.size() * sizeof(uint8_t);
  286. EXPECT_EQ(kEpidNoErr, Epid11VerifierSetSigRl(ctx, sig_rl, sig_rl_size));
  287. }
  288. TEST_F(Epid11VerifierTest, SetSigRlFailsGivenBadGroupId) {
  289. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  290. std::vector<uint8_t> empty_sig_rl_buf(this->kEmptySigRl);
  291. Epid11SigRl* empty_sig_rl = (Epid11SigRl*)empty_sig_rl_buf.data();
  292. empty_sig_rl->gid.data[0] = ~empty_sig_rl->gid.data[0];
  293. EXPECT_EQ(
  294. kEpidBadArgErr,
  295. Epid11VerifierSetSigRl(verifier, empty_sig_rl,
  296. sizeof(*empty_sig_rl) - sizeof(empty_sig_rl->bk)));
  297. }
  298. TEST_F(Epid11VerifierTest, SetSigRlFailsGivenOldVersion) {
  299. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  300. std::vector<uint8_t> empty_sig_rl_buf(this->kEmptySigRl);
  301. Epid11SigRl* empty_sig_rl = (Epid11SigRl*)empty_sig_rl_buf.data();
  302. empty_sig_rl->version = this->kOctStr32_1;
  303. EXPECT_EQ(kEpidNoErr, Epid11VerifierSetSigRl(
  304. verifier, empty_sig_rl,
  305. sizeof(*empty_sig_rl) - sizeof(empty_sig_rl->bk)));
  306. OctStr32 octstr32_0 = {0x00, 0x00, 0x00, 0x00};
  307. empty_sig_rl->version = octstr32_0;
  308. EXPECT_EQ(
  309. kEpidBadArgErr,
  310. Epid11VerifierSetSigRl(verifier, empty_sig_rl,
  311. sizeof(*empty_sig_rl) - sizeof(empty_sig_rl->bk)));
  312. }
  313. //////////////////////////////////////////////////////////////////////////
  314. // Epid11VerifierSetGroupRl
  315. TEST_F(Epid11VerifierTest, SetGroupRlFailsGivenNullPointer) {
  316. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  317. std::vector<uint8_t> group_rl(this->kGroupRl3GidBuf);
  318. Epid11GroupRl* grl = (Epid11GroupRl*)group_rl.data();
  319. EXPECT_EQ(kEpidBadArgErr,
  320. Epid11VerifierSetGroupRl(nullptr, grl, group_rl.size()));
  321. EXPECT_EQ(kEpidBadArgErr,
  322. Epid11VerifierSetGroupRl(verifier, nullptr, group_rl.size()));
  323. }
  324. TEST_F(Epid11VerifierTest, SetGroupRlFailsGivenSizeZero) {
  325. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  326. std::vector<uint8_t> group_rl(this->kGroupRl3GidBuf);
  327. Epid11GroupRl* grl = (Epid11GroupRl*)group_rl.data();
  328. EXPECT_EQ(kEpidBadArgErr, Epid11VerifierSetGroupRl(verifier, grl, 0));
  329. }
  330. TEST_F(Epid11VerifierTest, SetGroupRlFailsGivenSizeTooSmall) {
  331. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  332. std::vector<uint8_t> group_rl(this->kGroupRl3GidBuf);
  333. Epid11GroupRl* grl = (Epid11GroupRl*)group_rl.data();
  334. size_t grl_size = group_rl.size() - sizeof(grl->gid[0]);
  335. EXPECT_EQ(kEpidBadArgErr,
  336. Epid11VerifierSetGroupRl(verifier, grl, grl_size - 1));
  337. }
  338. TEST_F(Epid11VerifierTest, SetGroupRlFailsGivenSizeTooLarge) {
  339. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  340. std::vector<uint8_t> group_rl(this->kGroupRl3GidBuf);
  341. Epid11GroupRl* grl = (Epid11GroupRl*)group_rl.data();
  342. size_t grl_size = group_rl.size() - sizeof(grl->gid[0]);
  343. EXPECT_EQ(kEpidBadArgErr,
  344. Epid11VerifierSetGroupRl(verifier, grl, grl_size + 1));
  345. }
  346. TEST_F(Epid11VerifierTest, SetGroupRlFailsGivenN3ZeroAndGroupRLSizeTooBig) {
  347. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  348. std::vector<uint8_t> group_rl_3gid_n0_buf(this->kGroupRl3GidBuf);
  349. group_rl_3gid_n0_buf[7] = 0x00;
  350. Epid11GroupRl* group_rl = (Epid11GroupRl*)group_rl_3gid_n0_buf.data();
  351. EXPECT_EQ(kEpidBadArgErr,
  352. Epid11VerifierSetGroupRl(verifier, group_rl,
  353. group_rl_3gid_n0_buf.size()));
  354. }
  355. TEST_F(Epid11VerifierTest, SetGroupRlFailsGivenN3TooSmall) {
  356. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  357. std::vector<uint8_t> group_rl_3gid_n2_buf(this->kGroupRl3GidBuf);
  358. group_rl_3gid_n2_buf[7] = 0x02;
  359. Epid11GroupRl* group_rl = (Epid11GroupRl*)group_rl_3gid_n2_buf.data();
  360. EXPECT_EQ(kEpidBadArgErr,
  361. Epid11VerifierSetGroupRl(verifier, group_rl,
  362. group_rl_3gid_n2_buf.size()));
  363. }
  364. TEST_F(Epid11VerifierTest, SetGroupRlFailsGivenN3TooLarge) {
  365. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  366. std::vector<uint8_t> group_rl_3gid_n4_buf(this->kGroupRl3GidBuf);
  367. group_rl_3gid_n4_buf[7] = 0x04;
  368. Epid11GroupRl* group_rl = (Epid11GroupRl*)group_rl_3gid_n4_buf.data();
  369. EXPECT_EQ(kEpidBadArgErr,
  370. Epid11VerifierSetGroupRl(verifier, group_rl,
  371. group_rl_3gid_n4_buf.size()));
  372. }
  373. TEST_F(Epid11VerifierTest, SetGroupRlSucceedsGivenEmptyRL) {
  374. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  375. Epid11GroupRl* empty_grl = (Epid11GroupRl*)this->kGroupRlEmptyBuf.data();
  376. size_t grl_size = this->kGroupRlEmptyBuf.size();
  377. EXPECT_EQ(kEpidNoErr,
  378. Epid11VerifierSetGroupRl(verifier, empty_grl, grl_size));
  379. }
  380. TEST_F(Epid11VerifierTest, SetGroupRlSucceedsGivenRLWith3gid) {
  381. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  382. Epid11GroupRl* group_rl = (Epid11GroupRl*)this->kGroupRl3GidBuf.data();
  383. EXPECT_EQ(kEpidNoErr, Epid11VerifierSetGroupRl(verifier, group_rl,
  384. this->kGroupRl3GidBuf.size()));
  385. }
  386. TEST_F(Epid11VerifierTest, SetGroupRlFailsGivenOldVersion) {
  387. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  388. Epid11GroupRl* group_rl = (Epid11GroupRl*)this->kGroupRl3GidBuf.data();
  389. EXPECT_EQ(kEpidNoErr, Epid11VerifierSetGroupRl(verifier, group_rl,
  390. this->kGroupRl3GidBuf.size()));
  391. Epid11GroupRl* empty_grl = (Epid11GroupRl*)this->kGroupRlEmptyBuf.data();
  392. EXPECT_EQ(kEpidBadArgErr,
  393. Epid11VerifierSetGroupRl(verifier, empty_grl,
  394. this->kGroupRlEmptyBuf.size()));
  395. }
  396. //////////////////////////////////////////////////////////////////////////
  397. // Epid11VerifierSetBasename
  398. TEST_F(Epid11VerifierTest, DefaultBasenameIsNull) {
  399. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  400. Epid11VerifierCtx* ctx = verifier;
  401. EXPECT_EQ(nullptr, ctx->basename);
  402. }
  403. TEST_F(Epid11VerifierTest, SetBasenameFailsGivenNullContext) {
  404. auto& basename = this->kBsn0;
  405. EXPECT_EQ(kEpidBadArgErr, Epid11VerifierSetBasename(nullptr, basename.data(),
  406. basename.size()));
  407. }
  408. TEST_F(Epid11VerifierTest, SetBasenameFailsGivenNullBasenameAndNonzeroLength) {
  409. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  410. Epid11VerifierCtx* ctx = verifier;
  411. auto& basename = this->kBsn0;
  412. EXPECT_EQ(kEpidBadArgErr,
  413. Epid11VerifierSetBasename(ctx, nullptr, basename.size()));
  414. }
  415. TEST_F(Epid11VerifierTest, SetBasenameSucceedsGivenValidParameters) {
  416. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  417. Epid11VerifierCtx* ctx = verifier;
  418. auto& basename = this->kBsn0;
  419. EXPECT_EQ(kEpidNoErr,
  420. Epid11VerifierSetBasename(ctx, basename.data(), basename.size()));
  421. EXPECT_EQ(basename.size(), ctx->basename_len);
  422. EXPECT_EQ(0, memcmp(basename.data(), ctx->basename, ctx->basename_len));
  423. EXPECT_NE(nullptr, ctx->basename_hash);
  424. }
  425. TEST_F(Epid11VerifierTest, SetBasenameAcceptsZeroLengthBasename) {
  426. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  427. Epid11VerifierCtx* ctx = verifier;
  428. EXPECT_EQ(kEpidNoErr, Epid11VerifierSetBasename(ctx, "", 0));
  429. EXPECT_EQ((size_t)0, ctx->basename_len);
  430. EXPECT_NE(nullptr, ctx->basename_hash);
  431. }
  432. TEST_F(Epid11VerifierTest, SetBasenameResetsBasenameGivenNullBasename) {
  433. Epid11VerifierCtxObj verifier(this->kPubKeyStr, this->kVerifierPrecompStr);
  434. Epid11VerifierCtx* ctx = verifier;
  435. auto& basename = this->kBsn0;
  436. THROW_ON_EPIDERR(
  437. Epid11VerifierSetBasename(ctx, basename.data(), basename.size()));
  438. THROW_ON_EPIDERR(Epid11VerifierSetBasename(ctx, nullptr, 0));
  439. EXPECT_EQ(nullptr, ctx->basename_hash);
  440. }
  441. TEST_F(Epid11VerifierTest, SetBasenameAcceptsBsnContainingAllPossibleBytes) {
  442. Epid11VerifierCtxObj verifier(this->kPubKeyStrForMsg0_255,
  443. this->kVerifierPrecompStr);
  444. Epid11VerifierCtx* ctx = verifier;
  445. auto& basename = this->kData_0_255;
  446. EXPECT_EQ(kEpidNoErr,
  447. Epid11VerifierSetBasename(ctx, basename.data(), basename.size()));
  448. EXPECT_EQ(basename.size(), ctx->basename_len);
  449. EXPECT_EQ(0, memcmp(basename.data(), ctx->basename, ctx->basename_len));
  450. EXPECT_NE(nullptr, ctx->basename_hash);
  451. }
  452. } // namespace