verify-test.cc 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  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 Epid11Verify unit tests.
  19. */
  20. #include "epid/common-testhelper/epid_gtest-testhelper.h"
  21. #include "gtest/gtest.h"
  22. extern "C" {
  23. #include "epid/common/src/endian_convert.h"
  24. #include "epid/verifier/1.1/api.h"
  25. }
  26. #include "epid/common-testhelper/1.1/verifier_wrapper-testhelper.h"
  27. #include "epid/common-testhelper/errors-testhelper.h"
  28. #include "epid/verifier/1.1/unittests/verifier-testhelper.h"
  29. namespace {
  30. TEST_F(Epid11VerifierTest, VerifyFailsGivenNullParameters) {
  31. Epid11VerifierCtxObj verifier(this->kPubKeyStr);
  32. auto sig = this->kSigGrpXMember0Sha256RandbaseMsg0;
  33. auto msg = this->kMsg0;
  34. EXPECT_EQ(kEpidBadArgErr,
  35. Epid11Verify(nullptr, (Epid11Signature const*)sig.data(),
  36. sig.size(), msg.data(), msg.size()));
  37. EXPECT_EQ(kEpidBadArgErr, Epid11Verify(verifier, nullptr, sig.size(),
  38. msg.data(), msg.size()));
  39. EXPECT_EQ(kEpidBadArgErr,
  40. Epid11Verify(verifier, (Epid11Signature const*)sig.data(),
  41. sig.size(), nullptr, msg.size()));
  42. }
  43. TEST_F(Epid11VerifierTest, VerifyFailsGivenTooShortSigLen) {
  44. Epid11VerifierCtxObj verifier(this->kPubKeyStr);
  45. auto sig = this->kSigGrpXMember0Sha256RandbaseMsg0;
  46. auto msg = this->kMsg0;
  47. EXPECT_EQ(kEpidBadArgErr,
  48. Epid11Verify(verifier, (Epid11Signature const*)sig.data(), 0,
  49. msg.data(), msg.size()));
  50. EXPECT_EQ(kEpidBadArgErr,
  51. Epid11Verify(verifier, (Epid11Signature const*)sig.data(),
  52. sizeof(Epid11Signature) - sizeof(Epid11NrProof) - 1,
  53. msg.data(), msg.size()));
  54. }
  55. TEST_F(Epid11VerifierTest, VerifyFailsGivenSigLenTooShortForRlCount) {
  56. Epid11VerifierCtxObj verifier(this->kPubKeyStr);
  57. Epid11VerifierSetSigRl(verifier, (Epid11SigRl const*)this->kSigRl.data(),
  58. this->kSigRl.size());
  59. auto sig = this->kSigGrpXMember0Sha256RandbaseMsg0;
  60. auto n2 = ntohl(((Epid11SigRl const*)this->kSigRl.data())->n2.data);
  61. sig.resize(sizeof(Epid11Signature) +
  62. (n2 - 2) * sizeof(((Epid11Signature*)0)->sigma));
  63. auto msg = this->kMsg0;
  64. EXPECT_EQ(kEpidBadArgErr,
  65. Epid11Verify(verifier, (Epid11Signature const*)sig.data(),
  66. sig.size(), msg.data(), msg.size()));
  67. }
  68. TEST_F(Epid11VerifierTest, VerifyFailsGivenSigLenTooLongForRlCount) {
  69. Epid11VerifierCtxObj verifier(this->kPubKeyStr);
  70. Epid11VerifierSetSigRl(verifier, (Epid11SigRl const*)this->kSigRl.data(),
  71. this->kSigRl.size());
  72. auto sig = this->kSigGrpXMember0Sha256RandbaseMsg0;
  73. auto n2 = ntohl(((Epid11SigRl const*)this->kSigRl.data())->n2.data);
  74. sig.resize(sizeof(Epid11Signature) +
  75. n2 * sizeof(((Epid11Signature*)0)->sigma));
  76. auto msg = this->kMsg0;
  77. EXPECT_EQ(kEpidBadArgErr,
  78. Epid11Verify(verifier, (Epid11Signature const*)sig.data(),
  79. sig.size(), msg.data(), msg.size()));
  80. }
  81. #if (SIZE_MAX <= 0xFFFFFFFF) // When size_t value is 32 bit or lower
  82. TEST_F(Epid11VerifierTest, VerifyFailsGivenRlCountTooBig) {
  83. Epid11VerifierCtxObj verifier(this->kPubKeyStr);
  84. Epid11VerifierSetSigRl(verifier, (Epid11SigRl const*)this->kSigRl.data(),
  85. this->kSigRl.size());
  86. auto sig = this->kSigGrpXMember0Sha256RandbaseMsg0;
  87. uint32_t n2 = SIZE_MAX / sizeof(Epid11NrProof) + 1;
  88. uint32_t n2_ = ntohl(n2);
  89. Epid11Signature* sig_struct = (Epid11Signature*)sig.data();
  90. sig_struct->n2 = *(OctStr32*)&n2_;
  91. sig.resize(sizeof(Epid11Signature) + (n2 - 1) * sizeof(Epid11NrProof));
  92. auto msg = this->kMsg0;
  93. EXPECT_EQ(kEpidBadArgErr,
  94. Epid11Verify(verifier, (Epid11Signature const*)sig.data(),
  95. sig.size(), msg.data(), msg.size()));
  96. }
  97. #endif
  98. /////////////////////////////////////////////////////////////////////
  99. //
  100. // 4.1.2 step 1 - We use the following variables T1, T2, R1, R2,
  101. // t1, t2 (elements of G1), R4, t3 (elements of GT),
  102. // B, K, R3, t5 (elements of G3), c, sx, sy, sa, sb,
  103. // salpha, sbeta, nc, nc', nsx, syalpha,
  104. // t4 (256-bit big integers), nd (80-bit big integer),
  105. // and sf (600-bit big integer).
  106. // This Step is not testable
  107. /////////////////////////////////////////////////////////////////////
  108. //
  109. // 4.1.2 step 2 - The verifier reads the verifier pre-computation
  110. // blob (gid, e12, e22, e2w) from its storage.
  111. // Refer to Section 3.4 for the computation of
  112. // these values.
  113. // This Step is not testable
  114. /////////////////////////////////////////////////////////////////////
  115. //
  116. // 4.1.2 step 3 - The verifier verifies gid in the public key,
  117. // PRIV-RL, and SIG-RL (if provided) and the verifier
  118. // pre-computation blob all match.
  119. // This step tested with SetPrivRl, SetSigRl and ReadPrecomp functions tests
  120. /////////////////////////////////////////////////////////////////////
  121. //
  122. // 4.1.2 step 4 - The verifier verifies the signatures of PRIV-RL,
  123. // SIG-RL (if provided), and Group-RL (if provided)
  124. // using IVK.
  125. // This Step is not testable
  126. /////////////////////////////////////////////////////////////////////
  127. //
  128. // 4.1.2 step 5 - If Group-RL is provided as input, the verifier
  129. // verifies that gid has not been revoked, i.e.,
  130. // gid does not match any entry in Group-RL.
  131. TEST_F(Epid11VerifierTest, VerifyRejectsFromGroupRlSingleEntry) {
  132. auto& pub_key = this->kPubKeyStr;
  133. auto& msg = this->kMsg0;
  134. auto& bsn = this->kBsn0;
  135. auto& grp_rl = this->kGrpRlRevokedGrpXSingleEntry;
  136. auto& sig = this->kSigGrpXMember0Sha256Bsn0Msg0;
  137. Epid11VerifierCtxObj verifier(pub_key);
  138. THROW_ON_EPIDERR(Epid11VerifierSetGroupRl(
  139. verifier, (Epid11GroupRl const*)grp_rl.data(), grp_rl.size()));
  140. THROW_ON_EPIDERR(Epid11VerifierSetBasename(verifier, bsn.data(), bsn.size()));
  141. EXPECT_EQ(kEpidSigRevokedInGroupRl,
  142. Epid11Verify(verifier, (Epid11Signature const*)sig.data(),
  143. sig.size(), msg.data(), msg.size()));
  144. }
  145. TEST_F(Epid11VerifierTest, VerifyRejectsFromGroupRlFirstEntry) {
  146. auto& pub_key = this->kPubKeyStr;
  147. auto& msg = this->kMsg0;
  148. auto& bsn = this->kBsn0;
  149. auto& grp_rl = this->kGrpRlRevokedGrpXFirstEntry;
  150. auto& sig = this->kSigGrpXMember0Sha256Bsn0Msg0;
  151. Epid11VerifierCtxObj verifier(pub_key);
  152. THROW_ON_EPIDERR(Epid11VerifierSetGroupRl(
  153. verifier, (Epid11GroupRl const*)grp_rl.data(), grp_rl.size()));
  154. THROW_ON_EPIDERR(Epid11VerifierSetBasename(verifier, bsn.data(), bsn.size()));
  155. EXPECT_EQ(kEpidSigRevokedInGroupRl,
  156. Epid11Verify(verifier, (Epid11Signature const*)sig.data(),
  157. sig.size(), msg.data(), msg.size()));
  158. }
  159. TEST_F(Epid11VerifierTest, VerifyRejectsFromGroupRlMiddleEntry) {
  160. auto& pub_key = this->kPubKeyStr;
  161. auto& msg = this->kMsg0;
  162. auto& bsn = this->kBsn0;
  163. auto& grp_rl = this->kGrpRlRevokedGrpXMiddleEntry;
  164. auto& sig = this->kSigGrpXMember0Sha256Bsn0Msg0;
  165. Epid11VerifierCtxObj verifier(pub_key);
  166. THROW_ON_EPIDERR(Epid11VerifierSetGroupRl(
  167. verifier, (Epid11GroupRl const*)grp_rl.data(), grp_rl.size()));
  168. THROW_ON_EPIDERR(Epid11VerifierSetBasename(verifier, bsn.data(), bsn.size()));
  169. EXPECT_EQ(kEpidSigRevokedInGroupRl,
  170. Epid11Verify(verifier, (Epid11Signature const*)sig.data(),
  171. sig.size(), msg.data(), msg.size()));
  172. }
  173. TEST_F(Epid11VerifierTest, VerifyRejectsFromGroupRlLastEntry) {
  174. auto& pub_key = this->kPubKeyStr;
  175. auto& msg = this->kMsg0;
  176. auto& bsn = this->kBsn0;
  177. auto& grp_rl = this->kGrpRlRevokedGrpXLastEntry;
  178. auto& sig = this->kSigGrpXMember0Sha256Bsn0Msg0;
  179. Epid11VerifierCtxObj verifier(pub_key);
  180. THROW_ON_EPIDERR(Epid11VerifierSetGroupRl(
  181. verifier, (Epid11GroupRl const*)grp_rl.data(), grp_rl.size()));
  182. THROW_ON_EPIDERR(Epid11VerifierSetBasename(verifier, bsn.data(), bsn.size()));
  183. EXPECT_EQ(kEpidSigRevokedInGroupRl,
  184. Epid11Verify(verifier, (Epid11Signature const*)sig.data(),
  185. sig.size(), msg.data(), msg.size()));
  186. }
  187. /////////////////////////////////////////////////////////////////////
  188. //
  189. // 4.1.2 step 6 - If SIG-RL is provided as input, the verifier
  190. // verifies that RLver and n2 values in s match with
  191. // the values in SIG-RL. If SIG-RL is not provided
  192. // as input, but the input signature is a not basic
  193. // signature, the verifier aborts and outputs false.
  194. TEST_F(Epid11VerifierTest, VerifyFailsOnSigRlverNotMatchSigRlRlver) {
  195. // The verifier verifies that RLver in Sigma and in SigRL
  196. // match. If mismatch, abort and output "operation failed".
  197. Epid11VerifierCtxObj verifier(this->kPubKeyStr);
  198. auto msg = this->kMsg0;
  199. auto bsn = this->kBsn0;
  200. auto sig_rl = this->kGrpXSigRlMember0Bsn0Msg0SingleEntry;
  201. auto sig_rl_size = sig_rl.size();
  202. auto sig = this->kSigGrpXMember0Sha256Bsn0Msg0;
  203. Epid11SigRl sig_rl_wrong_ver = *(Epid11SigRl const*)sig_rl.data();
  204. sig_rl_wrong_ver.version.data[0]++;
  205. THROW_ON_EPIDERR(
  206. Epid11VerifierSetSigRl(verifier, &sig_rl_wrong_ver, sig_rl_size));
  207. THROW_ON_EPIDERR(Epid11VerifierSetBasename(verifier, bsn.data(), bsn.size()));
  208. EXPECT_EQ(kEpidErr, Epid11Verify(verifier, (Epid11Signature const*)sig.data(),
  209. sig.size(), msg.data(), msg.size()));
  210. }
  211. TEST_F(Epid11VerifierTest, VerifyFailsOnSigN2NotMatchSigRlN2) {
  212. // The verifier verifies that n2 in Sigma and in SigRL
  213. // match. If mismatch, abort and output "operation failed".
  214. Epid11VerifierCtxObj verifier(this->kPubKeyStr);
  215. auto msg = this->kMsg0;
  216. auto bsn = this->kBsn0;
  217. auto* sig_rl =
  218. (Epid11SigRl const*)this->kGrpXSigRlMember0Bsn0Msg0MiddleEntry.data();
  219. size_t sig_rl_size = this->kGrpXSigRlMember0Bsn0Msg0MiddleEntry.size();
  220. auto sig_raw = this->kSigGrpXMember0Sha256Bsn0Msg0SingleEntry;
  221. Epid11Signature* sig = (Epid11Signature*)sig_raw.data();
  222. sig->rl_ver = sig_rl->version;
  223. THROW_ON_EPIDERR(Epid11VerifierSetSigRl(verifier, sig_rl, sig_rl_size));
  224. THROW_ON_EPIDERR(Epid11VerifierSetBasename(verifier, bsn.data(), bsn.size()));
  225. EXPECT_EQ(kEpidBadArgErr, Epid11Verify(verifier, sig, sig_raw.size(),
  226. msg.data(), msg.size()));
  227. }
  228. TEST_F(Epid11VerifierTest, VerifyFailsSigIsNotBasicAndSigRlIsNotProvided) {
  229. Epid11VerifierCtxObj verifier(this->kPubKeyStr);
  230. auto msg = this->kMsg0;
  231. auto bsn = this->kBsn0;
  232. auto sig = this->kSigGrpXMember0Sha256Bsn0Msg0ThreeEntry;
  233. THROW_ON_EPIDERR(Epid11VerifierSetBasename(verifier, bsn.data(), bsn.size()));
  234. EXPECT_EQ(kEpidBadArgErr,
  235. Epid11Verify(verifier, (Epid11Signature const*)sig.data(),
  236. sig.size(), msg.data(), msg.size()));
  237. }
  238. /////////////////////////////////////////////////////////////////////
  239. //
  240. // 4.1.2 step 7 - The verifier verifies that G3.isIdentity(B) is false.
  241. //
  242. TEST_F(Epid11VerifierTest, VerifyRejectsIdentityB) {
  243. auto& pub_key = this->kPubKeyStr;
  244. Epid11Signature sig = {0};
  245. sig.sigma0 =
  246. *(Epid11BasicSignature*)(this->kSigGrpXMember0Sha256Bsn0Msg0.data());
  247. size_t sig_len = this->kSigGrpXMember0Sha256Bsn0Msg0.size();
  248. auto& msg = this->kMsg0;
  249. auto& bsn = this->kBsn0;
  250. memset(&sig.sigma0.B, 0, sizeof(sig.sigma0.B));
  251. Epid11VerifierCtxObj verifier(pub_key);
  252. THROW_ON_EPIDERR(Epid11VerifierSetBasename(verifier, bsn.data(), bsn.size()));
  253. EXPECT_EQ(kEpidSigInvalid,
  254. Epid11Verify(verifier, &sig, sig_len, msg.data(), msg.size()));
  255. }
  256. /////////////////////////////////////////////////////////////////////
  257. //
  258. // 4.1.2 step 8 - If bsnSize = 0, the verifier verifies G3.inGroup(B) = true.
  259. //
  260. TEST_F(Epid11VerifierTest, VerifyRejectsBNotInG3) {
  261. auto& pub_key = this->kPubKeyStr;
  262. Epid11Signature sig = {0};
  263. sig.sigma0 =
  264. *(Epid11BasicSignature*)(this->kSigGrpXMember0Sha256RandbaseMsg0.data());
  265. size_t sig_len = this->kSigGrpXMember0Sha256RandbaseMsg0.size();
  266. auto& msg = this->kMsg0;
  267. sig.sigma0.B.x.data.data[0] = 0xEE;
  268. Epid11VerifierCtxObj verifier(pub_key);
  269. EXPECT_EQ(kEpidSigInvalid,
  270. Epid11Verify(verifier, &sig, sig_len, msg.data(), msg.size()));
  271. }
  272. /////////////////////////////////////////////////////////////////////
  273. //
  274. // 4.1.2 step 9 - If bsnSize > 0, the verifier verifies B = G3.hash(bsn).
  275. //
  276. TEST_F(Epid11VerifierTest, VerifyRejectsBNotMatchingBasename) {
  277. auto& pub_key = this->kPubKeyStr;
  278. Epid11Signature sig = {0};
  279. sig.sigma0 =
  280. *(Epid11BasicSignature*)(this->kSigGrpXMember0Sha256Bsn0Msg0.data());
  281. size_t sig_len = this->kSigGrpXMember0Sha256Bsn0Msg0.size();
  282. auto msg = this->kMsg0;
  283. auto bsn = this->kBsn0;
  284. bsn.push_back('x');
  285. Epid11VerifierCtxObj verifier(pub_key);
  286. THROW_ON_EPIDERR(Epid11VerifierSetBasename(verifier, bsn.data(), bsn.size()));
  287. EXPECT_EQ(kEpidSigInvalid,
  288. Epid11Verify(verifier, &sig, sig_len, msg.data(), msg.size()));
  289. }
  290. /////////////////////////////////////////////////////////////////////
  291. //
  292. // 4.1.2 step 10 - The verifier verifies G3.inGroup(K) = true.
  293. //
  294. TEST_F(Epid11VerifierTest, VerifyRejectsKNotInG3) {
  295. auto& pub_key = this->kPubKeyStr;
  296. Epid11Signature sig = {0};
  297. sig.sigma0 =
  298. *(Epid11BasicSignature*)(this->kSigGrpXMember0Sha256RandbaseMsg0.data());
  299. size_t sig_len = this->kSigGrpXMember0Sha256RandbaseMsg0.size();
  300. auto& msg = this->kMsg0;
  301. sig.sigma0.K.x.data.data[0] = 0xEE;
  302. Epid11VerifierCtxObj verifier(pub_key);
  303. EXPECT_EQ(kEpidSigInvalid,
  304. Epid11Verify(verifier, &sig, sig_len, msg.data(), msg.size()));
  305. }
  306. /////////////////////////////////////////////////////////////////////
  307. //
  308. // 4.1.2 step 11 - The verifier verifies G1.inGroup(T1) = true.
  309. //
  310. TEST_F(Epid11VerifierTest, VerifyRejectsT1NotInG1) {
  311. auto& pub_key = this->kPubKeyStr;
  312. Epid11Signature sig = {0};
  313. sig.sigma0 =
  314. *(Epid11BasicSignature*)(this->kSigGrpXMember0Sha256RandbaseMsg0.data());
  315. size_t sig_len = this->kSigGrpXMember0Sha256RandbaseMsg0.size();
  316. auto& msg = this->kMsg0;
  317. sig.sigma0.T1.x.data.data[0] = 0xEE;
  318. Epid11VerifierCtxObj verifier(pub_key);
  319. EXPECT_EQ(kEpidSigInvalid,
  320. Epid11Verify(verifier, &sig, sig_len, msg.data(), msg.size()));
  321. }
  322. /////////////////////////////////////////////////////////////////////
  323. //
  324. // 4.1.2 step 12 - The verifier verifies G1.inGroup(T2) = true.
  325. //
  326. TEST_F(Epid11VerifierTest, VerifyRejectsT2NotInG1) {
  327. auto& pub_key = this->kPubKeyStr;
  328. Epid11Signature sig = {0};
  329. sig.sigma0 =
  330. *(Epid11BasicSignature*)(this->kSigGrpXMember0Sha256RandbaseMsg0.data());
  331. size_t sig_len = this->kSigGrpXMember0Sha256RandbaseMsg0.size();
  332. auto& msg = this->kMsg0;
  333. sig.sigma0.T2.x.data.data[0] = 0xEE;
  334. Epid11VerifierCtxObj verifier(pub_key);
  335. EXPECT_EQ(kEpidSigInvalid,
  336. Epid11Verify(verifier, &sig, sig_len, msg.data(), msg.size()));
  337. }
  338. /////////////////////////////////////////////////////////////////////
  339. //
  340. // 4.1.2 step 13 - The verifier verifies sx, sy, sa, sb, salpha, sbeta
  341. // in [0, p-1].
  342. //
  343. TEST_F(Epid11VerifierTest, VerifyRejectsSxNotInFp) {
  344. auto& pub_key = this->kPubKeyStr;
  345. Epid11Signature sig = {0};
  346. sig.sigma0 =
  347. *(Epid11BasicSignature*)(this->kSigGrpXMember0Sha256RandbaseMsg0.data());
  348. size_t sig_len = this->kSigGrpXMember0Sha256RandbaseMsg0.size();
  349. auto& msg = this->kMsg0;
  350. sig.sigma0.sx.data.data[0] = 0xEE;
  351. Epid11VerifierCtxObj verifier(pub_key);
  352. EXPECT_EQ(kEpidSigInvalid,
  353. Epid11Verify(verifier, &sig, sig_len, msg.data(), msg.size()));
  354. }
  355. TEST_F(Epid11VerifierTest, VerifyRejectsSyNotInFp) {
  356. auto& pub_key = this->kPubKeyStr;
  357. Epid11Signature sig = {0};
  358. sig.sigma0 =
  359. *(Epid11BasicSignature*)(this->kSigGrpXMember0Sha256RandbaseMsg0.data());
  360. size_t sig_len = this->kSigGrpXMember0Sha256RandbaseMsg0.size();
  361. auto& msg = this->kMsg0;
  362. sig.sigma0.sy.data.data[0] = 0xEE;
  363. Epid11VerifierCtxObj verifier(pub_key);
  364. EXPECT_EQ(kEpidSigInvalid,
  365. Epid11Verify(verifier, &sig, sig_len, msg.data(), msg.size()));
  366. }
  367. TEST_F(Epid11VerifierTest, VerifyRejectsSaNotInFp) {
  368. auto& pub_key = this->kPubKeyStr;
  369. Epid11Signature sig = {0};
  370. sig.sigma0 =
  371. *(Epid11BasicSignature*)(this->kSigGrpXMember0Sha256RandbaseMsg0.data());
  372. size_t sig_len = this->kSigGrpXMember0Sha256RandbaseMsg0.size();
  373. auto& msg = this->kMsg0;
  374. sig.sigma0.sa.data.data[0] = 0xEE;
  375. Epid11VerifierCtxObj verifier(pub_key);
  376. EXPECT_EQ(kEpidSigInvalid,
  377. Epid11Verify(verifier, &sig, sig_len, msg.data(), msg.size()));
  378. }
  379. TEST_F(Epid11VerifierTest, VerifyRejectsSbNotInFp) {
  380. auto& pub_key = this->kPubKeyStr;
  381. Epid11Signature sig = {0};
  382. sig.sigma0 =
  383. *(Epid11BasicSignature*)(this->kSigGrpXMember0Sha256RandbaseMsg0.data());
  384. size_t sig_len = this->kSigGrpXMember0Sha256RandbaseMsg0.size();
  385. auto& msg = this->kMsg0;
  386. sig.sigma0.sb.data.data[0] = 0xEE;
  387. Epid11VerifierCtxObj verifier(pub_key);
  388. EXPECT_EQ(kEpidSigInvalid,
  389. Epid11Verify(verifier, &sig, sig_len, msg.data(), msg.size()));
  390. }
  391. TEST_F(Epid11VerifierTest, VerifyRejectsSalphaNotInFp) {
  392. auto& pub_key = this->kPubKeyStr;
  393. Epid11Signature sig = {0};
  394. sig.sigma0 =
  395. *(Epid11BasicSignature*)(this->kSigGrpXMember0Sha256RandbaseMsg0.data());
  396. size_t sig_len = this->kSigGrpXMember0Sha256RandbaseMsg0.size();
  397. auto& msg = this->kMsg0;
  398. sig.sigma0.salpha.data.data[0] = 0xEE;
  399. Epid11VerifierCtxObj verifier(pub_key);
  400. EXPECT_EQ(kEpidSigInvalid,
  401. Epid11Verify(verifier, &sig, sig_len, msg.data(), msg.size()));
  402. }
  403. TEST_F(Epid11VerifierTest, VerifyRejectsSbetaNotInFp) {
  404. auto& pub_key = this->kPubKeyStr;
  405. Epid11Signature sig = {0};
  406. sig.sigma0 =
  407. *(Epid11BasicSignature*)(this->kSigGrpXMember0Sha256RandbaseMsg0.data());
  408. size_t sig_len = this->kSigGrpXMember0Sha256RandbaseMsg0.size();
  409. auto& msg = this->kMsg0;
  410. sig.sigma0.sbeta.data.data[0] = 0xEE;
  411. Epid11VerifierCtxObj verifier(pub_key);
  412. EXPECT_EQ(kEpidSigInvalid,
  413. Epid11Verify(verifier, &sig, sig_len, msg.data(), msg.size()));
  414. }
  415. /////////////////////////////////////////////////////////////////////
  416. //
  417. // 4.1.2 step 14 - The verifier verifies that sf is an (at-most) 593-bit
  418. // unsigned integer, in other words, sf < 2^593.
  419. //
  420. TEST_F(Epid11VerifierTest, VerifyRejectsSfMoreThan592Bits) {
  421. auto& pub_key = this->kPubKeyStr;
  422. Epid11Signature sig = {0};
  423. sig.sigma0 =
  424. *(Epid11BasicSignature*)(this->kSigGrpXMember0Sha256RandbaseMsg0.data());
  425. size_t sig_len = this->kSigGrpXMember0Sha256RandbaseMsg0.size();
  426. auto& msg = this->kMsg0;
  427. memset(&sig.sigma0.sf, 0, sizeof(sig.sigma0.sf));
  428. sig.sigma0.sf.data[593 / CHAR_BIT] = 1 << ((593 % CHAR_BIT) - 1);
  429. Epid11VerifierCtxObj verifier(pub_key);
  430. EXPECT_EQ(kEpidSigInvalid,
  431. Epid11Verify(verifier, &sig, sig_len, msg.data(), msg.size()));
  432. }
  433. /////////////////////////////////////////////////////////////////////
  434. //
  435. // 4.1.2 step 15 - The verifier computes nc = (-c) mod p.
  436. // 4.1.2 step 16 - The verifier computes nc' = (-c) mod p'.
  437. // 4.1.2 step 17 - The verifier computes nsx = (-sx) mod p.
  438. // 4.1.2 step 18 - The verifier computes syalpha = (sy + salpha) mod p.
  439. // 4.1.2 step 19 - The verifier computes R1 = G1.multiexp(h1, sa, h2, sb, T2,
  440. // nc).
  441. // 4.1.2 step 20 - The verifier computes R2 = G1.multiexp(h1, salpha, h2,
  442. // sbeta, T2, nsx).
  443. // 4.1.2 step 21 - The verifier computes R3 = G3.multiexp(B, sf, K, nc').
  444. // 4.1.2 step 22 - The verifier computes t1 = G1.multiexp(T1, nsx, g1, c).
  445. // 4.1.2 step 23 - The verifier computes t2 = G1.exp(T1, nc).
  446. // 4.1.2 step 24 - The verifier computes R4 = pairing(t1, g2).
  447. // 4.1.2 step 25 - The verifier computes t3 = pairing(t2, w).
  448. // 4.1.2 step 26 - The verifier computes R4 = GT.mul(R4, t3).
  449. // 4.1.2 step 27 - The verifier compute t3 = GT.multiexp(e12, sf, e22,
  450. // syalpha, e2w, sa).
  451. // 4.1.2 step 28 - The verifier compute R4 = GT.mul(R4, t3).
  452. // 4.1.2 step 29 - The verifier compute t4 = Hash(p || g1 || g2 || g3
  453. // || h1 || h2 || w || B || K
  454. // || T1 || T2 || R1 || R2
  455. // || R3 || R4).
  456. // These steps are not testable
  457. /////////////////////////////////////////////////////////////////////
  458. //
  459. // 4.1.2 step 30 - The verifier verifies c = H(t4 || nd || mSize || m).
  460. // It is not practical to test all inputs to this hash
  461. TEST_F(Epid11VerifierTest, VerifyRejectsSigWithMismatchedMsg) {
  462. auto& pub_key = this->kPubKeyStr;
  463. auto& sig = this->kSigGrpXMember0Sha256RandbaseMsg0;
  464. size_t sig_len = this->kSigGrpXMember0Sha256RandbaseMsg0.size();
  465. auto msg = this->kMsg0;
  466. msg.push_back('x');
  467. Epid11VerifierCtxObj verifier(pub_key);
  468. EXPECT_EQ(kEpidSigInvalid,
  469. Epid11Verify(verifier, (Epid11Signature const*)sig.data(), sig_len,
  470. msg.data(), msg.size()));
  471. }
  472. /////////////////////////////////////////////////////////////////////
  473. //
  474. // 4.1.2 step 31 - For i = 0, ..., n1-1, the verifier computes
  475. // t5 = G3.exp(B, f[i]) and verifies that
  476. // G3.isEqual(t5, K) = false.
  477. //
  478. TEST_F(Epid11VerifierTest, VerifyRejectsSigFromPrivRlSingleEntry) {
  479. auto& pub_key = this->kPubKeyStr;
  480. auto& msg = this->kMsg0;
  481. auto& bsn = this->kBsn0;
  482. auto& priv_rl = this->kGrpXPrivRlSingleEntry;
  483. auto& sig = this->kSigGrpXRevokedPrivKey000Sha256Bsn0Msg0;
  484. Epid11VerifierCtxObj verifier(pub_key);
  485. THROW_ON_EPIDERR(Epid11VerifierSetPrivRl(
  486. verifier, (Epid11PrivRl const*)priv_rl.data(), priv_rl.size()));
  487. THROW_ON_EPIDERR(Epid11VerifierSetBasename(verifier, bsn.data(), bsn.size()));
  488. EXPECT_EQ(kEpidSigRevokedInPrivRl,
  489. Epid11Verify(verifier, (Epid11Signature const*)sig.data(),
  490. sig.size(), msg.data(), msg.size()));
  491. }
  492. TEST_F(Epid11VerifierTest, VerifyRejectsSigFromPrivRlFirstEntry) {
  493. auto& pub_key = this->kPubKeyStr;
  494. auto& msg = this->kMsg0;
  495. auto& bsn = this->kBsn0;
  496. auto& priv_rl = this->kGrpXPrivRl;
  497. auto& sig = this->kSigGrpXRevokedPrivKey000Sha256Bsn0Msg0;
  498. Epid11VerifierCtxObj verifier(pub_key);
  499. THROW_ON_EPIDERR(Epid11VerifierSetPrivRl(
  500. verifier, (Epid11PrivRl const*)priv_rl.data(), priv_rl.size()));
  501. THROW_ON_EPIDERR(Epid11VerifierSetBasename(verifier, bsn.data(), bsn.size()));
  502. EXPECT_EQ(kEpidSigRevokedInPrivRl,
  503. Epid11Verify(verifier, (Epid11Signature const*)sig.data(),
  504. sig.size(), msg.data(), msg.size()));
  505. }
  506. TEST_F(Epid11VerifierTest, VerifyRejectsSigFromPrivRlMiddleEntry) {
  507. auto& pub_key = this->kPubKeyStr;
  508. auto& msg = this->kMsg0;
  509. auto& bsn = this->kBsn0;
  510. auto& priv_rl = this->kGrpXPrivRl;
  511. auto& sig = this->kSigGrpXRevokedPrivKey001Sha256Bsn0Msg0;
  512. Epid11VerifierCtxObj verifier(pub_key);
  513. THROW_ON_EPIDERR(Epid11VerifierSetPrivRl(
  514. verifier, (Epid11PrivRl const*)priv_rl.data(), priv_rl.size()));
  515. THROW_ON_EPIDERR(Epid11VerifierSetBasename(verifier, bsn.data(), bsn.size()));
  516. EXPECT_EQ(kEpidSigRevokedInPrivRl,
  517. Epid11Verify(verifier, (Epid11Signature const*)sig.data(),
  518. sig.size(), msg.data(), msg.size()));
  519. }
  520. TEST_F(Epid11VerifierTest, VerifyRejectsSigFromPrivRlLastEntry) {
  521. auto& pub_key = this->kPubKeyStr;
  522. auto& msg = this->kMsg0;
  523. auto& bsn = this->kBsn0;
  524. auto& priv_rl = this->kGrpXPrivRl;
  525. auto& sig = this->kSigGrpXRevokedPrivKey002Sha256Bsn0Msg0;
  526. Epid11VerifierCtxObj verifier(pub_key);
  527. THROW_ON_EPIDERR(Epid11VerifierSetPrivRl(
  528. verifier, (Epid11PrivRl const*)priv_rl.data(), priv_rl.size()));
  529. THROW_ON_EPIDERR(Epid11VerifierSetBasename(verifier, bsn.data(), bsn.size()));
  530. EXPECT_EQ(kEpidSigRevokedInPrivRl,
  531. Epid11Verify(verifier, (Epid11Signature const*)sig.data(),
  532. sig.size(), msg.data(), msg.size()));
  533. }
  534. TEST_F(Epid11VerifierTest, VerifyRejectsSigUsingCorruptedPrivRlEntry) {
  535. auto& pub_key = this->kPubKeyStr;
  536. auto& msg = this->kMsg0;
  537. auto& bsn = this->kBsn0;
  538. auto& priv_rl = this->kGrpXCorruptedPrivRl;
  539. auto& sig = this->kSigGrpXMember0Sha256Bsn0Msg0;
  540. Epid11VerifierCtxObj verifier(pub_key);
  541. THROW_ON_EPIDERR(Epid11VerifierSetPrivRl(
  542. verifier, (Epid11PrivRl const*)priv_rl.data(), priv_rl.size()));
  543. THROW_ON_EPIDERR(Epid11VerifierSetBasename(verifier, bsn.data(), bsn.size()));
  544. EXPECT_EQ(kEpidSigRevokedInPrivRl,
  545. Epid11Verify(verifier, (Epid11Signature const*)sig.data(),
  546. sig.size(), msg.data(), msg.size()));
  547. }
  548. /////////////////////////////////////////////////////////////////////
  549. //
  550. // 4.1.2 step 32 - For i = 0, ..., n2-1, the verifier verifies
  551. // nr-verify(B, K, B[i], K[i], s[i]) = true.
  552. // The details of nr-verify will be given in the
  553. // next subsection.
  554. TEST_F(Epid11VerifierTest, VerifyRejectsSigFromSigRlSingleEntry) {
  555. auto& msg = this->kMsg0;
  556. auto& bsn = this->kBsn0;
  557. auto& sig_rl = this->kGrpXSigRlMember0Bsn0Msg0SingleEntry;
  558. auto& sig = this->kSigGrpXMember0Sha256Bsn0Msg0SingleEntry;
  559. Epid11VerifierCtxObj verifier(this->kPubKeyStr);
  560. THROW_ON_EPIDERR(Epid11VerifierSetSigRl(
  561. verifier, (Epid11SigRl const*)sig_rl.data(), sig_rl.size()));
  562. THROW_ON_EPIDERR(Epid11VerifierSetBasename(verifier, bsn.data(), bsn.size()));
  563. EXPECT_EQ(kEpidSigRevokedInSigRl,
  564. Epid11Verify(verifier, (Epid11Signature const*)sig.data(),
  565. sig.size(), msg.data(), msg.size()));
  566. }
  567. TEST_F(Epid11VerifierTest, VerifyRejectsSigFromSigRlFirstEntry) {
  568. auto& msg = this->kMsg0;
  569. auto& bsn = this->kBsn0;
  570. auto& sig_rl = this->kGrpXSigRlMember0Bsn0Msg0FirstEntry;
  571. auto& sig = this->kSigGrpXMember0Sha256Bsn0Msg0ThreeEntry;
  572. Epid11VerifierCtxObj verifier(this->kPubKeyStr);
  573. THROW_ON_EPIDERR(Epid11VerifierSetSigRl(
  574. verifier, (Epid11SigRl const*)sig_rl.data(), sig_rl.size()));
  575. THROW_ON_EPIDERR(Epid11VerifierSetBasename(verifier, bsn.data(), bsn.size()));
  576. EXPECT_EQ(kEpidSigRevokedInSigRl,
  577. Epid11Verify(verifier, (Epid11Signature const*)sig.data(),
  578. sig.size(), msg.data(), msg.size()));
  579. }
  580. TEST_F(Epid11VerifierTest, VerifyRejectsSigFromSigRlMiddleEntry) {
  581. auto& msg = this->kMsg0;
  582. auto& bsn = this->kBsn0;
  583. auto& sig_rl = this->kGrpXSigRlMember0Bsn0Msg0MiddleEntry;
  584. auto& sig = this->kSigGrpXMember0Sha256Bsn0Msg0ThreeEntry;
  585. Epid11VerifierCtxObj verifier(this->kPubKeyStr);
  586. THROW_ON_EPIDERR(Epid11VerifierSetSigRl(
  587. verifier, (Epid11SigRl const*)sig_rl.data(), sig_rl.size()));
  588. THROW_ON_EPIDERR(Epid11VerifierSetBasename(verifier, bsn.data(), bsn.size()));
  589. EXPECT_EQ(kEpidSigRevokedInSigRl,
  590. Epid11Verify(verifier, (Epid11Signature const*)sig.data(),
  591. sig.size(), msg.data(), msg.size()));
  592. }
  593. TEST_F(Epid11VerifierTest, VerifyRejectsSigFromSigRlLastEntry) {
  594. auto& msg = this->kMsg0;
  595. auto& bsn = this->kBsn0;
  596. auto& sig_rl = this->kGrpXSigRlMember0Bsn0Msg0LastEntry;
  597. auto& sig = this->kSigGrpXMember0Sha256Bsn0Msg0ThreeEntry;
  598. Epid11VerifierCtxObj verifier(this->kPubKeyStr);
  599. THROW_ON_EPIDERR(Epid11VerifierSetSigRl(
  600. verifier, (Epid11SigRl const*)sig_rl.data(), sig_rl.size()));
  601. THROW_ON_EPIDERR(Epid11VerifierSetBasename(verifier, bsn.data(), bsn.size()));
  602. EXPECT_EQ(kEpidSigRevokedInSigRl,
  603. Epid11Verify(verifier, (Epid11Signature const*)sig.data(),
  604. sig.size(), msg.data(), msg.size()));
  605. }
  606. /////////////////////////////////////////////////////////////////////
  607. //
  608. // 4.1.2 step 33 - If all the above verifications succeed, the
  609. // verifier outputs true. If any of the above
  610. // verifications fails, the verifier immediately
  611. // aborts and outputs false.
  612. TEST_F(Epid11VerifierTest, VerifyAcceptsSigWithBaseNameNoRl) {
  613. auto& pub_key = this->kPubKeyStr;
  614. auto& sig = this->kSigGrpXMember0Sha256Bsn0Msg0;
  615. auto& msg = this->kMsg0;
  616. auto& bsn = this->kBsn0;
  617. Epid11VerifierCtxObj verifier(pub_key);
  618. THROW_ON_EPIDERR(Epid11VerifierSetBasename(verifier, bsn.data(), bsn.size()));
  619. EXPECT_EQ(kEpidSigValid,
  620. Epid11Verify(verifier, (Epid11Signature const*)sig.data(),
  621. sig.size(), msg.data(), msg.size()));
  622. }
  623. TEST_F(Epid11VerifierTest, VerifyAcceptsSigWithBaseNameAllRl) {
  624. auto& pub_key = this->kPubKeyStr;
  625. auto& msg = this->kMsg0;
  626. auto& bsn = this->kBsn0;
  627. auto& grp_rl = this->kGroupRlEmptyBuf;
  628. auto& priv_rl = this->kGrpXPrivRl;
  629. auto& sig_rl = this->kEmptySigRl;
  630. auto& sig = this->kSigGrpXMember0Sha256Bsn0Msg0;
  631. Epid11VerifierCtxObj verifier(pub_key);
  632. THROW_ON_EPIDERR(Epid11VerifierSetGroupRl(
  633. verifier, (Epid11GroupRl const*)grp_rl.data(), grp_rl.size()));
  634. THROW_ON_EPIDERR(Epid11VerifierSetPrivRl(
  635. verifier, (Epid11PrivRl const*)priv_rl.data(), priv_rl.size()));
  636. THROW_ON_EPIDERR(Epid11VerifierSetSigRl(
  637. verifier, (Epid11SigRl const*)sig_rl.data(), sig_rl.size()));
  638. THROW_ON_EPIDERR(Epid11VerifierSetBasename(verifier, bsn.data(), bsn.size()));
  639. EXPECT_EQ(kEpidSigValid,
  640. Epid11Verify(verifier, (Epid11Signature const*)sig.data(),
  641. sig.size(), msg.data(), msg.size()));
  642. }
  643. TEST_F(Epid11VerifierTest, VerifyAcceptsSigWithRandomBaseNameNoRl) {
  644. auto& pub_key = this->kPubKeyStr;
  645. auto& sig = this->kSigGrpXMember0Sha256RandbaseMsg0;
  646. auto& msg = this->kMsg0;
  647. Epid11VerifierCtxObj verifier(pub_key);
  648. EXPECT_EQ(kEpidSigValid,
  649. Epid11Verify(verifier, (Epid11Signature const*)sig.data(),
  650. sig.size(), msg.data(), msg.size()));
  651. }
  652. TEST_F(Epid11VerifierTest, VerifyAcceptsSigWithRandomBaseNameAllRl) {
  653. auto& pub_key = this->kPubKeyStr;
  654. auto& msg = this->kMsg0;
  655. auto& grp_rl = this->kGroupRlEmptyBuf;
  656. auto& priv_rl = this->kGrpXPrivRl;
  657. auto& sig_rl = this->kEmptySigRl;
  658. auto& sig = this->kSigGrpXMember0Sha256RandbaseMsg0;
  659. Epid11VerifierCtxObj verifier(pub_key);
  660. THROW_ON_EPIDERR(Epid11VerifierSetGroupRl(
  661. verifier, (Epid11GroupRl const*)grp_rl.data(), grp_rl.size()));
  662. THROW_ON_EPIDERR(Epid11VerifierSetPrivRl(
  663. verifier, (Epid11PrivRl const*)priv_rl.data(), priv_rl.size()));
  664. THROW_ON_EPIDERR(Epid11VerifierSetSigRl(
  665. verifier, (Epid11SigRl const*)sig_rl.data(), sig_rl.size()));
  666. EXPECT_EQ(kEpidSigValid,
  667. Epid11Verify(verifier, (Epid11Signature const*)sig.data(),
  668. sig.size(), msg.data(), msg.size()));
  669. }
  670. TEST_F(Epid11VerifierTest, VerifyAcceptsSigGivenMsgContainingAllPossibleBytes) {
  671. auto& pub_key = this->kPubKeyStrForMsg0_255;
  672. auto& msg = this->kData_0_255;
  673. auto& grp_rl = this->kGroupRlEmptyBuf;
  674. auto& priv_rl = this->kGrpXPrivRl;
  675. auto& sig = this->kSigGrp01Member0Sha256kBsn0Data_0_255;
  676. Epid11VerifierCtxObj verifier(pub_key);
  677. THROW_ON_EPIDERR(Epid11VerifierSetGroupRl(
  678. verifier, (Epid11GroupRl const*)grp_rl.data(), grp_rl.size()));
  679. THROW_ON_EPIDERR(Epid11VerifierSetPrivRl(
  680. verifier, (Epid11PrivRl const*)priv_rl.data(), priv_rl.size()));
  681. THROW_ON_EPIDERR(Epid11VerifierSetSigRl(
  682. verifier, (Epid11SigRl const*)this->kSigRlForMsg0_255.data(),
  683. this->kSigRlForMsg0_255.size()));
  684. EXPECT_EQ(kEpidSigValid,
  685. Epid11Verify(verifier, (Epid11Signature const*)sig.data(),
  686. sig.size(), msg.data(), msg.size()));
  687. }
  688. } // namespace