context-test.cc 50 KB

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