sign-test.cc 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082
  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 Sign unit tests.
  19. */
  20. #include <vector>
  21. #include "epid/common-testhelper/epid_gtest-testhelper.h"
  22. #include "gtest/gtest.h"
  23. extern "C" {
  24. #include "epid/member/api.h"
  25. #include "epid/verifier/api.h"
  26. }
  27. #include "epid/common-testhelper/errors-testhelper.h"
  28. #include "epid/common-testhelper/prng-testhelper.h"
  29. #include "epid/common-testhelper/verifier_wrapper-testhelper.h"
  30. #include "epid/member/tiny/unittests/member-testhelper.h"
  31. namespace {
  32. /// Count of elements in array
  33. #define COUNT_OF(A) (sizeof(A) / sizeof((A)[0]))
  34. /////////////////////////////////////////////////////////////////////////
  35. // Simple error cases
  36. TEST_F(EpidMemberTest, SignFailsGivenNullParameters) {
  37. Prng my_prng;
  38. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  39. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  40. auto& msg = this->kMsg0;
  41. auto& bsn = this->kBsn0;
  42. SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}};
  43. srl.gid = this->kGroupPublicKey.gid;
  44. std::vector<uint8_t> sig(EpidGetSigSize(&srl));
  45. THROW_ON_EPIDERR(
  46. EpidMemberSetSigRl(member, &srl, sizeof(srl) - sizeof(srl.bk)));
  47. EXPECT_EQ(kEpidBadArgErr,
  48. EpidSign(nullptr, msg.data(), msg.size(), bsn.data(), bsn.size(),
  49. (EpidSignature*)sig.data(), sig.size()));
  50. EXPECT_EQ(kEpidBadArgErr, EpidSign(member, msg.data(), msg.size(), bsn.data(),
  51. bsn.size(), nullptr, sig.size()));
  52. EXPECT_EQ(kEpidBadArgErr,
  53. EpidSign(member, nullptr, msg.size(), bsn.data(), bsn.size(),
  54. (EpidSignature*)sig.data(), sig.size()));
  55. EXPECT_EQ(kEpidBadArgErr,
  56. EpidSign(member, msg.data(), msg.size(), nullptr, bsn.size(),
  57. (EpidSignature*)sig.data(), sig.size()));
  58. }
  59. TEST_F(EpidMemberTest, SignFailsGivenNonZeroMessageLenWithNullMessage) {
  60. Prng my_prng;
  61. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  62. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  63. auto& msg = this->kMsg0;
  64. auto& bsn = this->kBsn0;
  65. SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}};
  66. srl.gid = this->kGroupPublicKey.gid;
  67. std::vector<uint8_t> sig(EpidGetSigSize(&srl));
  68. THROW_ON_EPIDERR(
  69. EpidMemberSetSigRl(member, &srl, sizeof(srl) - sizeof(srl.bk)));
  70. EXPECT_EQ(kEpidBadArgErr,
  71. EpidSign(member, nullptr, msg.size(), bsn.data(), bsn.size(),
  72. (EpidSignature*)sig.data(), sig.size()));
  73. }
  74. TEST_F(EpidMemberTest, SignFailsGivenNonZeroBasenameLenWithNullBasename) {
  75. Prng my_prng;
  76. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  77. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  78. auto& msg = this->kMsg0;
  79. auto& bsn = this->kBsn0;
  80. SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}};
  81. srl.gid = this->kGroupPublicKey.gid;
  82. std::vector<uint8_t> sig(EpidGetSigSize(&srl));
  83. THROW_ON_EPIDERR(
  84. EpidMemberSetSigRl(member, &srl, sizeof(srl) - sizeof(srl.bk)));
  85. EXPECT_EQ(kEpidBadArgErr,
  86. EpidSign(member, msg.data(), msg.size(), nullptr, bsn.size(),
  87. (EpidSignature*)sig.data(), sig.size()));
  88. }
  89. TEST_F(EpidMemberTest, SignFailsGivenWrongSigLen) {
  90. Prng my_prng;
  91. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  92. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  93. auto& msg = this->kMsg0;
  94. auto& bsn = this->kBsn0;
  95. SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}};
  96. srl.gid = this->kGroupPublicKey.gid;
  97. THROW_ON_EPIDERR(
  98. EpidMemberSetSigRl(member, &srl, sizeof(srl) - sizeof(srl.bk)));
  99. // signature buffer one byte less than needed
  100. std::vector<uint8_t> sig_small(EpidGetSigSize(&srl) - 1);
  101. EXPECT_EQ(kEpidBadArgErr,
  102. EpidSign(member, msg.data(), msg.size(), bsn.data(), bsn.size(),
  103. (EpidSignature*)sig_small.data(), sig_small.size()));
  104. // signature buffer is one byte - a less than allowed for EpidSignature
  105. std::vector<uint8_t> sig_one(1);
  106. EXPECT_EQ(kEpidBadArgErr,
  107. EpidSign(member, msg.data(), msg.size(), bsn.data(), bsn.size(),
  108. (EpidSignature*)sig_one.data(), sig_one.size()));
  109. }
  110. TEST_F(EpidMemberTest, SignFailsGivenUnregisteredBasename) {
  111. Prng my_prng;
  112. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  113. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  114. auto& msg = this->kMsg0;
  115. auto& bsn = this->kBsn0;
  116. auto& bsn1 = this->kBsn1;
  117. SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}};
  118. srl.gid = this->kGroupPublicKey.gid;
  119. std::vector<uint8_t> sig(EpidGetSigSize(&srl));
  120. THROW_ON_EPIDERR(
  121. EpidMemberSetSigRl(member, &srl, sizeof(srl) - sizeof(srl.bk)));
  122. THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size()));
  123. EXPECT_EQ(kEpidBadArgErr,
  124. EpidSign(member, msg.data(), msg.size(), bsn1.data(), bsn1.size(),
  125. (EpidSignature*)sig.data(), sig.size()));
  126. }
  127. TEST_F(EpidMemberTest, SignsFailsIfNotProvisioned) {
  128. Prng my_prng;
  129. MemberCtxObj member(&Prng::Generate, &my_prng);
  130. auto& msg = this->kMsg0;
  131. std::vector<uint8_t> sig_data(EpidGetSigSize(nullptr));
  132. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  133. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  134. EXPECT_EQ(kEpidOutOfSequenceError,
  135. EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len));
  136. }
  137. /////////////////////////////////////////////////////////////////////////
  138. // Anonymity
  139. TEST_F(EpidMemberTest, SignaturesOfSameMessageAreDifferent) {
  140. Prng my_prng;
  141. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  142. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  143. auto& msg = this->kMsg0;
  144. std::vector<uint8_t> sig1(EpidGetSigSize(nullptr));
  145. std::vector<uint8_t> sig2(EpidGetSigSize(nullptr));
  146. // without signature based revocation list
  147. EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0,
  148. (EpidSignature*)sig1.data(), sig1.size()));
  149. EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0,
  150. (EpidSignature*)sig2.data(), sig2.size()));
  151. EXPECT_TRUE(sig1.size() == sig2.size() &&
  152. 0 != memcmp(sig1.data(), sig2.data(), sig1.size()));
  153. // with signature based revocation list
  154. uint8_t sig_rl_data_n2_one[] = {
  155. // gid
  156. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  157. 0x00, 0x00, 0x00, 0x01,
  158. // version
  159. 0x00, 0x00, 0x00, 0x00,
  160. // n2
  161. 0x0, 0x00, 0x00, 0x01,
  162. // one bk
  163. 0x9c, 0xa5, 0xe5, 0xae, 0x5f, 0xae, 0x51, 0x59, 0x33, 0x35, 0x27, 0xd,
  164. 0x8, 0xb1, 0xbe, 0x5d, 0x69, 0x50, 0x84, 0xc5, 0xfe, 0xe2, 0x87, 0xea,
  165. 0x2e, 0xef, 0xfa, 0xee, 0x67, 0xf2, 0xd8, 0x28, 0x56, 0x43, 0xc6, 0x94,
  166. 0x67, 0xa6, 0x72, 0xf6, 0x41, 0x15, 0x4, 0x58, 0x42, 0x16, 0x88, 0x57,
  167. 0x9d, 0xc7, 0x71, 0xd1, 0xc, 0x84, 0x13, 0xa, 0x90, 0x23, 0x18, 0x8, 0xad,
  168. 0x7d, 0xfe, 0xf5, 0xc8, 0xae, 0xfc, 0x51, 0x40, 0xa7, 0xd1, 0x28, 0xc2,
  169. 0x89, 0xb2, 0x6b, 0x4e, 0xb4, 0xc1, 0x55, 0x87, 0x98, 0xbd, 0x72, 0xf9,
  170. 0xcf, 0xd, 0x40, 0x15, 0xee, 0x32, 0xc, 0xf3, 0x56, 0xc5, 0xc, 0x61, 0x9d,
  171. 0x4f, 0x7a, 0xb5, 0x2b, 0x16, 0xa9, 0xa3, 0x97, 0x38, 0xe2, 0xdd, 0x3a,
  172. 0x33, 0xad, 0xf6, 0x7b, 0x68, 0x8b, 0x68, 0xcf, 0xa3, 0xd3, 0x98, 0x37,
  173. 0xce, 0xec, 0xd1, 0xa8, 0xc, 0x8b};
  174. SigRl* srl1 = reinterpret_cast<SigRl*>(sig_rl_data_n2_one);
  175. size_t srl1_size = sizeof(sig_rl_data_n2_one);
  176. std::vector<uint8_t> sig3(EpidGetSigSize(srl1));
  177. std::vector<uint8_t> sig4(EpidGetSigSize(srl1));
  178. THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl1, srl1_size));
  179. EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0,
  180. (EpidSignature*)sig3.data(), sig3.size()));
  181. EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), nullptr, 0,
  182. (EpidSignature*)sig4.data(), sig4.size()));
  183. EXPECT_TRUE(sig3.size() == sig4.size() &&
  184. 0 != memcmp(sig3.data(), sig4.data(), sig3.size()));
  185. }
  186. TEST_F(EpidMemberTest, SignaturesOfSameMessageWithSameBasenameAreDifferent) {
  187. Prng my_prng;
  188. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  189. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  190. auto& msg = this->kMsg0;
  191. auto& bsn = this->kBsn0;
  192. std::vector<uint8_t> sig1(EpidGetSigSize(nullptr));
  193. std::vector<uint8_t> sig2(EpidGetSigSize(nullptr));
  194. // without signature based revocation list
  195. THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size()));
  196. EXPECT_EQ(kEpidNoErr,
  197. EpidSign(member, msg.data(), msg.size(), bsn.data(), bsn.size(),
  198. (EpidSignature*)sig1.data(), sig1.size()));
  199. EXPECT_EQ(kEpidNoErr,
  200. EpidSign(member, msg.data(), msg.size(), bsn.data(), bsn.size(),
  201. (EpidSignature*)sig2.data(), sig2.size()));
  202. EXPECT_TRUE(sig1.size() == sig2.size() &&
  203. 0 != memcmp(sig1.data(), sig2.data(), sig1.size()));
  204. // with signature based revocation list
  205. uint8_t sig_rl_data_n2_one[] = {
  206. // gid
  207. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  208. 0x00, 0x00, 0x00, 0x01,
  209. // version
  210. 0x00, 0x00, 0x00, 0x00,
  211. // n2
  212. 0x0, 0x00, 0x00, 0x01,
  213. // one bk
  214. 0x9c, 0xa5, 0xe5, 0xae, 0x5f, 0xae, 0x51, 0x59, 0x33, 0x35, 0x27, 0xd,
  215. 0x8, 0xb1, 0xbe, 0x5d, 0x69, 0x50, 0x84, 0xc5, 0xfe, 0xe2, 0x87, 0xea,
  216. 0x2e, 0xef, 0xfa, 0xee, 0x67, 0xf2, 0xd8, 0x28, 0x56, 0x43, 0xc6, 0x94,
  217. 0x67, 0xa6, 0x72, 0xf6, 0x41, 0x15, 0x4, 0x58, 0x42, 0x16, 0x88, 0x57,
  218. 0x9d, 0xc7, 0x71, 0xd1, 0xc, 0x84, 0x13, 0xa, 0x90, 0x23, 0x18, 0x8, 0xad,
  219. 0x7d, 0xfe, 0xf5, 0xc8, 0xae, 0xfc, 0x51, 0x40, 0xa7, 0xd1, 0x28, 0xc2,
  220. 0x89, 0xb2, 0x6b, 0x4e, 0xb4, 0xc1, 0x55, 0x87, 0x98, 0xbd, 0x72, 0xf9,
  221. 0xcf, 0xd, 0x40, 0x15, 0xee, 0x32, 0xc, 0xf3, 0x56, 0xc5, 0xc, 0x61, 0x9d,
  222. 0x4f, 0x7a, 0xb5, 0x2b, 0x16, 0xa9, 0xa3, 0x97, 0x38, 0xe2, 0xdd, 0x3a,
  223. 0x33, 0xad, 0xf6, 0x7b, 0x68, 0x8b, 0x68, 0xcf, 0xa3, 0xd3, 0x98, 0x37,
  224. 0xce, 0xec, 0xd1, 0xa8, 0xc, 0x8b};
  225. SigRl* srl1 = reinterpret_cast<SigRl*>(sig_rl_data_n2_one);
  226. size_t srl1_size = sizeof(sig_rl_data_n2_one);
  227. std::vector<uint8_t> sig3(EpidGetSigSize(srl1));
  228. std::vector<uint8_t> sig4(EpidGetSigSize(srl1));
  229. THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl1, srl1_size));
  230. EXPECT_EQ(kEpidNoErr,
  231. EpidSign(member, msg.data(), msg.size(), bsn.data(), bsn.size(),
  232. (EpidSignature*)sig3.data(), sig3.size()));
  233. EXPECT_EQ(kEpidNoErr,
  234. EpidSign(member, msg.data(), msg.size(), bsn.data(), bsn.size(),
  235. (EpidSignature*)sig4.data(), sig4.size()));
  236. EXPECT_TRUE(sig3.size() == sig4.size() &&
  237. 0 != memcmp(sig3.data(), sig4.data(), sig3.size()));
  238. }
  239. /////////////////////////////////////////////////////////////////////////
  240. // Variable basename
  241. TEST_F(EpidMemberTest, SignsMessageUsingRandomBaseNoSigRl) {
  242. Prng my_prng;
  243. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  244. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  245. auto& msg = this->kMsg0;
  246. std::vector<uint8_t> sig_data(EpidGetSigSize(nullptr));
  247. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  248. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  249. EXPECT_EQ(kEpidNoErr,
  250. EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len));
  251. VerifierCtxObj ctx(this->kGroupPublicKey);
  252. EXPECT_EQ(kEpidSigValid,
  253. EpidVerify(ctx, sig, sig_len, msg.data(), msg.size()));
  254. }
  255. TEST_F(EpidMemberTest, SignsMessageUsingRandomBaseWithSigRl) {
  256. Prng my_prng;
  257. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  258. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  259. auto& msg = this->kMsg0;
  260. SigRl const* srl =
  261. reinterpret_cast<SigRl const*>(this->kSigRl5EntryData.data());
  262. size_t srl_size = this->kSigRl5EntryData.size() * sizeof(uint8_t);
  263. std::vector<uint8_t> sig_data(EpidGetSigSize(srl));
  264. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  265. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  266. THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size));
  267. EXPECT_EQ(kEpidNoErr,
  268. EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len));
  269. VerifierCtxObj ctx(this->kGroupPublicKey);
  270. THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size));
  271. EXPECT_EQ(kEpidSigValid,
  272. EpidVerify(ctx, sig, sig_len, msg.data(), msg.size()));
  273. }
  274. TEST_F(EpidMemberTest, SignsMessageUsingBasenameNoSigRl) {
  275. Prng my_prng;
  276. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  277. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  278. auto& msg = this->kMsg0;
  279. auto& bsn = this->kBsn0;
  280. THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size()));
  281. std::vector<uint8_t> sig_data(EpidGetSigSize(nullptr));
  282. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  283. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  284. EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), bsn.data(),
  285. bsn.size(), sig, sig_len));
  286. // verify basic signature
  287. VerifierCtxObj ctx(this->kGroupPublicKey);
  288. THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size()));
  289. EXPECT_EQ(kEpidSigValid,
  290. EpidVerify(ctx, sig, sig_len, msg.data(), msg.size()));
  291. }
  292. TEST_F(EpidMemberTest, SignsMessageUsingBasenameWithSigRl) {
  293. Prng my_prng;
  294. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  295. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  296. auto& msg = this->kMsg0;
  297. auto& bsn = this->kBsn0;
  298. THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size()));
  299. SigRl const* srl =
  300. reinterpret_cast<SigRl const*>(this->kSigRl5EntryData.data());
  301. size_t srl_size = this->kSigRl5EntryData.size() * sizeof(uint8_t);
  302. std::vector<uint8_t> sig_data(EpidGetSigSize(srl));
  303. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  304. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  305. THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size));
  306. EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), bsn.data(),
  307. bsn.size(), sig, sig_len));
  308. VerifierCtxObj ctx(this->kGroupPublicKey);
  309. THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size()));
  310. THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size));
  311. EXPECT_EQ(kEpidSigValid,
  312. EpidVerify(ctx, sig, sig_len, msg.data(), msg.size()));
  313. }
  314. TEST_F(EpidMemberTest, SignsUsingRandomBaseWithRegisteredBasenamesNoSigRl) {
  315. Prng my_prng;
  316. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  317. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  318. auto& msg = this->kMsg0;
  319. auto& bsn = this->kBsn0;
  320. THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size()));
  321. std::vector<uint8_t> sig_data(EpidGetSigSize(nullptr));
  322. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  323. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  324. EXPECT_EQ(kEpidNoErr,
  325. EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len));
  326. VerifierCtxObj ctx(this->kGroupPublicKey);
  327. EXPECT_EQ(kEpidSigValid,
  328. EpidVerify(ctx, sig, sig_len, msg.data(), msg.size()));
  329. }
  330. TEST_F(EpidMemberTest, SignsUsingRandomBaseWithRegisteredBasenamesWithSigRl) {
  331. Prng my_prng;
  332. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  333. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  334. auto& msg = this->kMsg0;
  335. auto& bsn = this->kBsn0;
  336. THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size()));
  337. SigRl const* srl =
  338. reinterpret_cast<SigRl const*>(this->kSigRl5EntryData.data());
  339. size_t srl_size = this->kSigRl5EntryData.size() * sizeof(uint8_t);
  340. std::vector<uint8_t> sig_data(EpidGetSigSize(srl));
  341. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  342. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  343. THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size));
  344. EXPECT_EQ(kEpidNoErr,
  345. EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len));
  346. VerifierCtxObj ctx(this->kGroupPublicKey);
  347. THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size));
  348. EXPECT_EQ(kEpidSigValid,
  349. EpidVerify(ctx, sig, sig_len, msg.data(), msg.size()));
  350. }
  351. TEST_F(EpidMemberTest, SignsUsingRandomBaseWithoutRegisteredBasenamesNoSigRl) {
  352. Prng my_prng;
  353. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  354. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  355. auto& msg = this->kMsg0;
  356. std::vector<uint8_t> sig_data(EpidGetSigSize(nullptr));
  357. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  358. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  359. EXPECT_EQ(kEpidNoErr,
  360. EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len));
  361. VerifierCtxObj ctx(this->kGroupPublicKey);
  362. EXPECT_EQ(kEpidSigValid,
  363. EpidVerify(ctx, sig, sig_len, msg.data(), msg.size()));
  364. }
  365. TEST_F(EpidMemberTest,
  366. SignsUsingRandomBaseWithoutRegisteredBasenamesWithSigRl) {
  367. Prng my_prng;
  368. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  369. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  370. auto& msg = this->kMsg0;
  371. SigRl const* srl =
  372. reinterpret_cast<SigRl const*>(this->kSigRl5EntryData.data());
  373. size_t srl_size = this->kSigRl5EntryData.size() * sizeof(uint8_t);
  374. std::vector<uint8_t> sig_data(EpidGetSigSize(srl));
  375. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  376. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  377. THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size));
  378. EXPECT_EQ(kEpidNoErr,
  379. EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len));
  380. VerifierCtxObj ctx(this->kGroupPublicKey);
  381. THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size));
  382. EXPECT_EQ(kEpidSigValid,
  383. EpidVerify(ctx, sig, sig_len, msg.data(), msg.size()));
  384. }
  385. #ifndef TPM_TSS
  386. TEST_F(EpidMemberTest, SignsMessageUsingHugeBasenameNoSigRl) {
  387. Prng my_prng;
  388. MemberCtxObj member(this->kGrpXKey, this->kGrpXMember0PrivKey,
  389. &Prng::Generate, &my_prng);
  390. auto& msg = this->kMsg0;
  391. std::vector<uint8_t> bsn(1024 * 1024); // exactly 1 MB
  392. uint8_t c = 0;
  393. for (size_t i = 0; i < bsn.size(); ++i) {
  394. bsn[i] = c++;
  395. }
  396. THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size()));
  397. std::vector<uint8_t> sig_data(EpidGetSigSize(nullptr));
  398. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  399. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  400. EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), bsn.data(),
  401. bsn.size(), sig, sig_len));
  402. // verify basic signature
  403. VerifierCtxObj ctx(this->kGrpXKey);
  404. THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size()));
  405. EXPECT_EQ(kEpidSigValid,
  406. EpidVerify(ctx, sig, sig_len, msg.data(), msg.size()));
  407. }
  408. TEST_F(EpidMemberTest, SignsMessageUsingHugeBasenameWithSigRl) {
  409. Prng my_prng;
  410. MemberCtxObj member(this->kGrpXKey, this->kGrpXMember0PrivKey,
  411. &Prng::Generate, &my_prng);
  412. auto& msg = this->kMsg0;
  413. std::vector<uint8_t> bsn(1024 * 1024); // exactly 1 MB
  414. uint8_t c = 0;
  415. for (size_t i = 0; i < bsn.size(); ++i) {
  416. bsn[i] = c++;
  417. }
  418. THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size()));
  419. SigRl const* srl = reinterpret_cast<SigRl const*>(this->kGrpXSigRl.data());
  420. size_t srl_size = this->kGrpXSigRl.size() * sizeof(this->kGrpXSigRl[0]);
  421. std::vector<uint8_t> sig_data(EpidGetSigSize(srl));
  422. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  423. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  424. THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size));
  425. EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), bsn.data(),
  426. bsn.size(), sig, sig_len));
  427. VerifierCtxObj ctx(this->kGrpXKey);
  428. THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size()));
  429. THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size));
  430. }
  431. TEST_F(EpidMemberTest, SignsMsgUsingBsnContainingAllPossibleBytesNoSigRl) {
  432. Prng my_prng;
  433. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  434. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  435. auto& msg = this->kMsg0;
  436. auto& bsn = this->kData_0_255;
  437. std::vector<uint8_t> sig_data(EpidGetSigSize(nullptr));
  438. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  439. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  440. THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size()));
  441. EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), msg.size(), bsn.data(),
  442. bsn.size(), sig, sig_len));
  443. VerifierCtxObj ctx(this->kGroupPublicKey);
  444. THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size()));
  445. EXPECT_EQ(kEpidSigValid,
  446. EpidVerify(ctx, sig, sig_len, msg.data(), msg.size()));
  447. }
  448. #endif
  449. /////////////////////////////////////////////////////////////////////////
  450. // Variable sigRL
  451. TEST_F(EpidMemberTest, SignsMessageGivenNoSigRl) {
  452. Prng my_prng;
  453. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  454. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  455. auto& msg = this->kMsg0;
  456. size_t sig_len = EpidGetSigSize(nullptr);
  457. std::vector<uint8_t> newsig(sig_len);
  458. EpidSignature* sig = (EpidSignature*)newsig.data();
  459. EXPECT_EQ(kEpidNoErr,
  460. EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len));
  461. // verify signature
  462. VerifierCtxObj ctx(this->kGroupPublicKey);
  463. EXPECT_EQ(kEpidSigValid,
  464. EpidVerify(ctx, sig, sig_len, msg.data(), msg.size()));
  465. }
  466. TEST_F(EpidMemberTest, SignsMessageGivenNoSigRlUsingIKGFData) {
  467. GroupPubKey grp_public_key = *reinterpret_cast<const GroupPubKey*>(
  468. this->kGroupPublicKeyDataIkgf.data());
  469. PrivKey mbr_private_key =
  470. *reinterpret_cast<const PrivKey*>(this->kMemberPrivateKeyDataIkgf.data());
  471. Prng my_prng;
  472. auto& msg = this->kMsg0;
  473. size_t sig_len = EpidGetSigSize(nullptr);
  474. std::vector<uint8_t> newsig(sig_len);
  475. // using ikgf keys
  476. MemberCtxObj member(grp_public_key, mbr_private_key, &Prng::Generate,
  477. &my_prng);
  478. EpidSignature* sig = (EpidSignature*)newsig.data();
  479. EXPECT_EQ(kEpidNoErr,
  480. EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len));
  481. // verify signature
  482. VerifierCtxObj ctx(grp_public_key);
  483. EXPECT_EQ(kEpidSigValid,
  484. EpidVerify(ctx, sig, sig_len, msg.data(), msg.size()));
  485. }
  486. TEST_F(EpidMemberTest, SignsMessageGivenSigRlWithNoEntries) {
  487. Prng my_prng;
  488. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  489. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  490. auto& msg = this->kMsg0;
  491. uint8_t sig_rl_data_n2_zero[] = {
  492. // gid
  493. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  494. 0x00, 0x00, 0x00, 0x01,
  495. // version
  496. 0x00, 0x00, 0x00, 0x00,
  497. // n2
  498. 0x0, 0x00, 0x00, 0x00,
  499. // not bk's
  500. };
  501. SigRl const* srl = reinterpret_cast<SigRl const*>(sig_rl_data_n2_zero);
  502. size_t srl_size = sizeof(sig_rl_data_n2_zero);
  503. std::vector<uint8_t> sig_data(EpidGetSigSize(srl));
  504. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  505. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  506. THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size));
  507. EXPECT_EQ(kEpidNoErr,
  508. EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len));
  509. VerifierCtxObj ctx(this->kGroupPublicKey);
  510. THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size));
  511. EXPECT_EQ(kEpidSigValid,
  512. EpidVerify(ctx, sig, sig_len, msg.data(), msg.size()));
  513. }
  514. TEST_F(EpidMemberTest, SignsMessageGivenSigRlWithNoEntriesUsingIkgfData) {
  515. GroupPubKey grp_public_key = *reinterpret_cast<const GroupPubKey*>(
  516. this->kGroupPublicKeyDataIkgf.data());
  517. PrivKey mbr_private_key =
  518. *reinterpret_cast<const PrivKey*>(this->kMemberPrivateKeyDataIkgf.data());
  519. Prng my_prng;
  520. auto& msg = this->kMsg0;
  521. // using ikgf keys
  522. MemberCtxObj member_ikgf(grp_public_key, mbr_private_key, &Prng::Generate,
  523. &my_prng);
  524. uint8_t sig_rl_data_n2_one_gid0[] = {
  525. #include "epid/common-testhelper/testdata/ikgf/groupa/sigrl_empty.inc"
  526. };
  527. SigRl* srl_ikgf = reinterpret_cast<SigRl*>(sig_rl_data_n2_one_gid0);
  528. size_t srl_size = sizeof(sig_rl_data_n2_one_gid0);
  529. std::vector<uint8_t> sig_data_ikgf(EpidGetSigSize(srl_ikgf));
  530. EpidSignature* sig_ikgf =
  531. reinterpret_cast<EpidSignature*>(sig_data_ikgf.data());
  532. size_t sig_len = sig_data_ikgf.size() * sizeof(uint8_t);
  533. THROW_ON_EPIDERR(EpidMemberSetSigRl(member_ikgf, srl_ikgf, srl_size));
  534. EXPECT_EQ(kEpidNoErr, EpidSign(member_ikgf, msg.data(), msg.size(), nullptr,
  535. 0, sig_ikgf, sig_len));
  536. VerifierCtxObj ctx_ikgf(grp_public_key);
  537. THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx_ikgf, srl_ikgf, srl_size));
  538. EXPECT_EQ(kEpidSigValid,
  539. EpidVerify(ctx_ikgf, sig_ikgf, sig_len, msg.data(), msg.size()));
  540. }
  541. TEST_F(EpidMemberTest, SignsMessageGivenSigRlWithEntries) {
  542. Prng my_prng;
  543. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  544. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  545. auto& msg = this->kMsg0;
  546. uint8_t sig_rl_data_n2_one[] = {
  547. // gid
  548. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  549. 0x00, 0x00, 0x00, 0x01,
  550. // version
  551. 0x00, 0x00, 0x00, 0x00,
  552. // n2
  553. 0x0, 0x00, 0x00, 0x02,
  554. // one bk
  555. 0x9c, 0xa5, 0xe5, 0xae, 0x5f, 0xae, 0x51, 0x59, 0x33, 0x35, 0x27, 0xd,
  556. 0x8, 0xb1, 0xbe, 0x5d, 0x69, 0x50, 0x84, 0xc5, 0xfe, 0xe2, 0x87, 0xea,
  557. 0x2e, 0xef, 0xfa, 0xee, 0x67, 0xf2, 0xd8, 0x28, 0x56, 0x43, 0xc6, 0x94,
  558. 0x67, 0xa6, 0x72, 0xf6, 0x41, 0x15, 0x4, 0x58, 0x42, 0x16, 0x88, 0x57,
  559. 0x9d, 0xc7, 0x71, 0xd1, 0xc, 0x84, 0x13, 0xa, 0x90, 0x23, 0x18, 0x8, 0xad,
  560. 0x7d, 0xfe, 0xf5, 0xc8, 0xae, 0xfc, 0x51, 0x40, 0xa7, 0xd1, 0x28, 0xc2,
  561. 0x89, 0xb2, 0x6b, 0x4e, 0xb4, 0xc1, 0x55, 0x87, 0x98, 0xbd, 0x72, 0xf9,
  562. 0xcf, 0xd, 0x40, 0x15, 0xee, 0x32, 0xc, 0xf3, 0x56, 0xc5, 0xc, 0x61, 0x9d,
  563. 0x4f, 0x7a, 0xb5, 0x2b, 0x16, 0xa9, 0xa3, 0x97, 0x38, 0xe2, 0xdd, 0x3a,
  564. 0x33, 0xad, 0xf6, 0x7b, 0x68, 0x8b, 0x68, 0xcf, 0xa3, 0xd3, 0x98, 0x37,
  565. 0xce, 0xec, 0xd1, 0xa8, 0xc, 0x8b,
  566. 0x71, 0x8a, 0xb5, 0x1, 0x7f, 0x7c, 0x92, 0x9a, 0xa2, 0xc9, 0x81, 0x10,
  567. 0xfe, 0xbf, 0xc, 0x53, 0xa4, 0x43, 0xaf, 0x31, 0x74, 0x12, 0x25, 0x60,
  568. 0x3e, 0xc0, 0x21, 0xe6, 0x63, 0x9a, 0xd2, 0x67, 0x2d, 0xb5, 0xd5, 0x82,
  569. 0xc4, 0x49, 0x29, 0x51, 0x42, 0x8f, 0xe0, 0xe, 0xd1, 0x73, 0x27, 0xf5,
  570. 0x77, 0x16, 0x4, 0x40, 0x8a, 0x0, 0xe, 0x3a, 0x5d, 0x37, 0x42, 0xd3, 0x8,
  571. 0x40, 0xbd, 0x69, 0xf7, 0x5f, 0x74, 0x21, 0x50, 0xf4, 0xce, 0xfe, 0xd9,
  572. 0xdd, 0x97, 0x6c, 0xa8, 0xa5, 0x60, 0x6b, 0xf8, 0x1b, 0xba, 0x2, 0xb2,
  573. 0xca, 0x5, 0x44, 0x9b, 0xb1, 0x5e, 0x3a, 0xa4, 0x35, 0x7a, 0x51, 0xfa,
  574. 0xcf, 0xa4, 0x4, 0xe9, 0xf3, 0xbf, 0x38, 0xd4, 0x24, 0x9, 0x52, 0xf3,
  575. 0x58, 0x3d, 0x9d, 0x4b, 0xb3, 0x37, 0x4b, 0xec, 0x87, 0xe1, 0x64, 0x60,
  576. 0x3c, 0xb6, 0xf7, 0x7b, 0xff, 0x40, 0x11};
  577. SigRl* srl = reinterpret_cast<SigRl*>(sig_rl_data_n2_one);
  578. size_t srl_size = sizeof(sig_rl_data_n2_one);
  579. std::vector<uint8_t> sig_data(EpidGetSigSize(srl));
  580. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  581. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  582. THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size));
  583. EXPECT_EQ(kEpidNoErr,
  584. EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len));
  585. VerifierCtxObj ctx(this->kGroupPublicKey);
  586. THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size));
  587. EXPECT_EQ(kEpidSigValid,
  588. EpidVerify(ctx, sig, sig_len, msg.data(), msg.size()));
  589. }
  590. TEST_F(EpidMemberTest, SignsMessageGivenSigRlWithEntriesUsingIKGFData) {
  591. GroupPubKey grp_public_key = *reinterpret_cast<const GroupPubKey*>(
  592. this->kGroupPublicKeyDataIkgf.data());
  593. PrivKey mbr_private_key =
  594. *reinterpret_cast<const PrivKey*>(this->kMemberPrivateKeyDataIkgf.data());
  595. Prng my_prng;
  596. auto& msg = this->kMsg0;
  597. // using ikgf keys
  598. MemberCtxObj member_ikgf(grp_public_key, mbr_private_key, &Prng::Generate,
  599. &my_prng);
  600. uint8_t sig_rl_data_n2_one_gid0[] = {
  601. // gid
  602. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  603. 0x00, 0x00, 0x00, 0x00,
  604. // version
  605. 0x00, 0x00, 0x00, 0x00,
  606. // n2
  607. 0x0, 0x00, 0x00, 0x02,
  608. // one bk
  609. 0x9c, 0xa5, 0xe5, 0xae, 0x5f, 0xae, 0x51, 0x59, 0x33, 0x35, 0x27, 0xd,
  610. 0x8, 0xb1, 0xbe, 0x5d, 0x69, 0x50, 0x84, 0xc5, 0xfe, 0xe2, 0x87, 0xea,
  611. 0x2e, 0xef, 0xfa, 0xee, 0x67, 0xf2, 0xd8, 0x28, 0x56, 0x43, 0xc6, 0x94,
  612. 0x67, 0xa6, 0x72, 0xf6, 0x41, 0x15, 0x4, 0x58, 0x42, 0x16, 0x88, 0x57,
  613. 0x9d, 0xc7, 0x71, 0xd1, 0xc, 0x84, 0x13, 0xa, 0x90, 0x23, 0x18, 0x8, 0xad,
  614. 0x7d, 0xfe, 0xf5, 0xc8, 0xae, 0xfc, 0x51, 0x40, 0xa7, 0xd1, 0x28, 0xc2,
  615. 0x89, 0xb2, 0x6b, 0x4e, 0xb4, 0xc1, 0x55, 0x87, 0x98, 0xbd, 0x72, 0xf9,
  616. 0xcf, 0xd, 0x40, 0x15, 0xee, 0x32, 0xc, 0xf3, 0x56, 0xc5, 0xc, 0x61, 0x9d,
  617. 0x4f, 0x7a, 0xb5, 0x2b, 0x16, 0xa9, 0xa3, 0x97, 0x38, 0xe2, 0xdd, 0x3a,
  618. 0x33, 0xad, 0xf6, 0x7b, 0x68, 0x8b, 0x68, 0xcf, 0xa3, 0xd3, 0x98, 0x37,
  619. 0xce, 0xec, 0xd1, 0xa8, 0xc, 0x8b,
  620. 0x71, 0x8a, 0xb5, 0x1, 0x7f, 0x7c, 0x92, 0x9a, 0xa2, 0xc9, 0x81, 0x10,
  621. 0xfe, 0xbf, 0xc, 0x53, 0xa4, 0x43, 0xaf, 0x31, 0x74, 0x12, 0x25, 0x60,
  622. 0x3e, 0xc0, 0x21, 0xe6, 0x63, 0x9a, 0xd2, 0x67, 0x2d, 0xb5, 0xd5, 0x82,
  623. 0xc4, 0x49, 0x29, 0x51, 0x42, 0x8f, 0xe0, 0xe, 0xd1, 0x73, 0x27, 0xf5,
  624. 0x77, 0x16, 0x4, 0x40, 0x8a, 0x0, 0xe, 0x3a, 0x5d, 0x37, 0x42, 0xd3, 0x8,
  625. 0x40, 0xbd, 0x69, 0xf7, 0x5f, 0x74, 0x21, 0x50, 0xf4, 0xce, 0xfe, 0xd9,
  626. 0xdd, 0x97, 0x6c, 0xa8, 0xa5, 0x60, 0x6b, 0xf8, 0x1b, 0xba, 0x2, 0xb2,
  627. 0xca, 0x5, 0x44, 0x9b, 0xb1, 0x5e, 0x3a, 0xa4, 0x35, 0x7a, 0x51, 0xfa,
  628. 0xcf, 0xa4, 0x4, 0xe9, 0xf3, 0xbf, 0x38, 0xd4, 0x24, 0x9, 0x52, 0xf3,
  629. 0x58, 0x3d, 0x9d, 0x4b, 0xb3, 0x37, 0x4b, 0xec, 0x87, 0xe1, 0x64, 0x60,
  630. 0x3c, 0xb6, 0xf7, 0x7b, 0xff, 0x40, 0x11};
  631. SigRl* srl_ikgf = reinterpret_cast<SigRl*>(sig_rl_data_n2_one_gid0);
  632. size_t srl_size = sizeof(sig_rl_data_n2_one_gid0);
  633. std::vector<uint8_t> sig_data_ikgf(EpidGetSigSize(srl_ikgf));
  634. EpidSignature* sig_ikgf =
  635. reinterpret_cast<EpidSignature*>(sig_data_ikgf.data());
  636. size_t sig_len = sig_data_ikgf.size() * sizeof(uint8_t);
  637. THROW_ON_EPIDERR(EpidMemberSetSigRl(member_ikgf, srl_ikgf, srl_size));
  638. EXPECT_EQ(kEpidNoErr, EpidSign(member_ikgf, msg.data(), msg.size(), nullptr,
  639. 0, sig_ikgf, sig_len));
  640. VerifierCtxObj ctx_ikgf(grp_public_key);
  641. THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx_ikgf, srl_ikgf, srl_size));
  642. EXPECT_EQ(kEpidSigValid,
  643. EpidVerify(ctx_ikgf, sig_ikgf, sig_len, msg.data(), msg.size()));
  644. }
  645. TEST_F(EpidMemberTest, SignMessageReportsIfMemberRevoked) {
  646. // note: a complete sig + nr proof should still be returned!!
  647. auto& pub_key = this->kGrpXKey;
  648. auto& priv_key = this->kGrpXMember0PrivKey;
  649. auto& msg = this->kMsg0;
  650. Prng my_prng;
  651. MemberCtxObj member(pub_key, priv_key, &Prng::Generate, &my_prng);
  652. const std::vector<uint8_t> kGrpXSigRlMember0Sha512Rndbase0Msg0MiddleEntry = {
  653. #include "epid/common-testhelper/testdata/grp_x/sigrl_member0_sig_sha512_rndbase_msg0_revoked_middle_entry.inc"
  654. };
  655. auto srl = reinterpret_cast<SigRl const*>(
  656. kGrpXSigRlMember0Sha512Rndbase0Msg0MiddleEntry.data());
  657. size_t srl_size = kGrpXSigRlMember0Sha512Rndbase0Msg0MiddleEntry.size();
  658. std::vector<uint8_t> sig_data(EpidGetSigSize(srl));
  659. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  660. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  661. THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size));
  662. EXPECT_EQ(kEpidSigRevokedInSigRl,
  663. EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len));
  664. VerifierCtxObj ctx(pub_key);
  665. THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size));
  666. EXPECT_EQ(kEpidSigRevokedInSigRl,
  667. EpidVerify(ctx, sig, sig_len, msg.data(), msg.size()));
  668. }
  669. TEST_F(EpidMemberTest, SignMessageReportsIfMemberRevokedUsingIKGFData) {
  670. // note: a complete sig + nr proof should still be returned!!
  671. GroupPubKey grp_public_key = *reinterpret_cast<const GroupPubKey*>(
  672. this->kGroupPublicKeyDataIkgf.data());
  673. const PrivKey member_private_key_revoked_by_sig = {
  674. #include "epid/common-testhelper/testdata/ikgf/groupa/sigrevokedmember0/mprivkey.inc"
  675. };
  676. Prng my_prng;
  677. MemberCtxObj member(grp_public_key, member_private_key_revoked_by_sig,
  678. &Prng::Generate, &my_prng);
  679. auto& msg = this->kMsg0;
  680. const std::vector<uint8_t> sig_Rl = {
  681. #include "epid/common-testhelper/testdata/ikgf/groupa/sigrl.inc"
  682. };
  683. auto srl = reinterpret_cast<SigRl const*>(sig_Rl.data());
  684. size_t srl_size = sig_Rl.size();
  685. std::vector<uint8_t> sig_data(EpidGetSigSize(srl));
  686. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  687. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  688. THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size));
  689. EXPECT_EQ(kEpidSigRevokedInSigRl,
  690. EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len));
  691. VerifierCtxObj ctx(grp_public_key);
  692. THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size));
  693. EXPECT_EQ(kEpidSigRevokedInSigRl,
  694. EpidVerify(ctx, sig, sig_len, msg.data(), msg.size()));
  695. }
  696. /////////////////////////////////////////////////////////////////////////
  697. // Variable hash alg
  698. TEST_F(EpidMemberTest, SignsMessageUsingSha256HashAlg) {
  699. Prng my_prng;
  700. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, kSha256,
  701. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  702. auto& msg = this->kMsg0;
  703. std::vector<uint8_t> sig_data(EpidGetSigSize(nullptr));
  704. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  705. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  706. EXPECT_EQ(kEpidNoErr,
  707. EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len));
  708. // verify signature
  709. VerifierCtxObj ctx(this->kGroupPublicKey);
  710. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha256));
  711. EXPECT_EQ(kEpidSigValid,
  712. EpidVerify(ctx, sig, sig_len, msg.data(), msg.size()));
  713. }
  714. TEST_F(EpidMemberTest, DISABLED_SignsMessageUsingSha384HashAlg) {
  715. Prng my_prng;
  716. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, kSha384,
  717. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  718. auto& msg = this->kMsg0;
  719. std::vector<uint8_t> sig_data(EpidGetSigSize(nullptr));
  720. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  721. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  722. EXPECT_EQ(kEpidNoErr,
  723. EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len));
  724. // verify signature
  725. VerifierCtxObj ctx(this->kGroupPublicKey);
  726. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha384));
  727. EXPECT_EQ(kEpidSigValid,
  728. EpidVerify(ctx, sig, sig_len, msg.data(), msg.size()));
  729. }
  730. TEST_F(EpidMemberTest, SignsMessageUsingSha512HashAlg) {
  731. Prng my_prng;
  732. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey, kSha512,
  733. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  734. auto& msg = this->kMsg0;
  735. std::vector<uint8_t> sig_data(EpidGetSigSize(nullptr));
  736. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  737. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  738. EXPECT_EQ(kEpidNoErr,
  739. EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len));
  740. // verify signature
  741. VerifierCtxObj ctx(this->kGroupPublicKey);
  742. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha512));
  743. EXPECT_EQ(kEpidSigValid,
  744. EpidVerify(ctx, sig, sig_len, msg.data(), msg.size()));
  745. }
  746. TEST_F(EpidMemberTest, DISABLED_SignsMessageUsingSha512256HashAlg) {
  747. Prng my_prng;
  748. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  749. kSha512_256, this->kMemberPrecomp, &Prng::Generate,
  750. &my_prng);
  751. auto& msg = this->kMsg0;
  752. std::vector<uint8_t> sig_data(EpidGetSigSize(nullptr));
  753. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  754. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  755. EXPECT_EQ(kEpidNoErr,
  756. EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len));
  757. // verify signature
  758. VerifierCtxObj ctx(this->kGroupPublicKey);
  759. THROW_ON_EPIDERR(EpidVerifierSetHashAlg(ctx, kSha512_256));
  760. EXPECT_EQ(kEpidSigValid,
  761. EpidVerify(ctx, sig, sig_len, msg.data(), msg.size()));
  762. }
  763. /////////////////////////////////////////////////////////////////////////
  764. // Variable precomputed signatures
  765. TEST_F(EpidMemberTest, DISABLED_SignConsumesPrecomputedSignaturesNoSigRl) {
  766. Prng my_prng;
  767. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  768. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  769. THROW_ON_EPIDERR(EpidAddPreSigs(member, 3));
  770. auto& msg = this->kMsg0;
  771. std::vector<uint8_t> sig_data(EpidGetSigSize(nullptr));
  772. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  773. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  774. EXPECT_EQ(kEpidNoErr,
  775. EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len));
  776. EXPECT_EQ((size_t)2, EpidGetNumPreSigs(member));
  777. }
  778. TEST_F(EpidMemberTest, DISABLED_SignConsumesPrecomputedSignaturesWithSigRl) {
  779. Prng my_prng;
  780. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  781. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  782. THROW_ON_EPIDERR(EpidAddPreSigs(member, 3));
  783. auto& msg = this->kMsg0;
  784. SigRl const* srl =
  785. reinterpret_cast<SigRl const*>(this->kSigRl5EntryData.data());
  786. size_t srl_size = this->kSigRl5EntryData.size() * sizeof(uint8_t);
  787. std::vector<uint8_t> sig_data(EpidGetSigSize(srl));
  788. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  789. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  790. THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size));
  791. EXPECT_EQ(kEpidNoErr,
  792. EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len));
  793. EXPECT_EQ((size_t)2, EpidGetNumPreSigs(member));
  794. }
  795. TEST_F(EpidMemberTest, DISABLED_SignsMessageWithPrecomputedSignaturesNoSigRl) {
  796. Prng my_prng;
  797. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  798. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  799. THROW_ON_EPIDERR(EpidAddPreSigs(member, 1));
  800. auto& msg = this->kMsg0;
  801. std::vector<uint8_t> sig_data(EpidGetSigSize(nullptr));
  802. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  803. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  804. EXPECT_EQ(kEpidNoErr,
  805. EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len));
  806. // verify basic signature
  807. VerifierCtxObj ctx(this->kGroupPublicKey);
  808. EXPECT_EQ(kEpidSigValid,
  809. EpidVerify(ctx, sig, sig_len, msg.data(), msg.size()));
  810. }
  811. TEST_F(EpidMemberTest,
  812. DISABLED_SignsMessageWithPrecomputedSignaturesWithSigRl) {
  813. Prng my_prng;
  814. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  815. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  816. THROW_ON_EPIDERR(EpidAddPreSigs(member, 1));
  817. auto& msg = this->kMsg0;
  818. SigRl const* srl =
  819. reinterpret_cast<SigRl const*>(this->kSigRl5EntryData.data());
  820. size_t srl_size = this->kSigRl5EntryData.size() * sizeof(uint8_t);
  821. std::vector<uint8_t> sig_data(EpidGetSigSize(srl));
  822. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  823. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  824. THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size));
  825. EXPECT_EQ(kEpidNoErr,
  826. EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len));
  827. // verify basic signature
  828. VerifierCtxObj ctx(this->kGroupPublicKey);
  829. THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size));
  830. EXPECT_EQ(kEpidSigValid,
  831. EpidVerify(ctx, sig, sig_len, msg.data(), msg.size()));
  832. }
  833. TEST_F(EpidMemberTest, SignsMessageWithoutPrecomputedSignaturesNoSigRl) {
  834. Prng my_prng;
  835. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  836. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  837. auto& msg = this->kMsg0;
  838. std::vector<uint8_t> sig_data(EpidGetSigSize(nullptr));
  839. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  840. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  841. // test sign without precomputed signatures
  842. EXPECT_EQ(kEpidNoErr,
  843. EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len));
  844. // verify basic signature
  845. VerifierCtxObj ctx(this->kGroupPublicKey);
  846. EXPECT_EQ(kEpidSigValid,
  847. EpidVerify(ctx, sig, sig_len, msg.data(), msg.size()));
  848. }
  849. TEST_F(EpidMemberTest, SignsMessageWithoutPrecomputedSignaturesWithSigRl) {
  850. Prng my_prng;
  851. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  852. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  853. auto& msg = this->kMsg0;
  854. SigRl const* srl =
  855. reinterpret_cast<SigRl const*>(this->kSigRl5EntryData.data());
  856. size_t srl_size = this->kSigRl5EntryData.size() * sizeof(uint8_t);
  857. std::vector<uint8_t> sig_data(EpidGetSigSize(srl));
  858. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  859. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  860. THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size));
  861. // test sign without precomputed signatures
  862. EXPECT_EQ(kEpidNoErr,
  863. EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len));
  864. // verify basic signature
  865. VerifierCtxObj ctx(this->kGroupPublicKey);
  866. THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size));
  867. EXPECT_EQ(kEpidSigValid,
  868. EpidVerify(ctx, sig, sig_len, msg.data(), msg.size()));
  869. }
  870. /////////////////////////////////////////////////////////////////////////
  871. // Variable messages
  872. TEST_F(EpidMemberTest, SignsEmptyMessageNoSigRl) {
  873. Prng my_prng;
  874. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  875. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  876. auto& msg = this->kMsg0;
  877. auto& bsn = this->kBsn0;
  878. std::vector<uint8_t> sig_data(EpidGetSigSize(nullptr));
  879. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  880. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  881. THROW_ON_EPIDERR(EpidRegisterBasename(member, bsn.data(), bsn.size()));
  882. EXPECT_EQ(kEpidNoErr, EpidSign(member, msg.data(), 0, bsn.data(), bsn.size(),
  883. sig, sig_len));
  884. VerifierCtxObj ctx(this->kGroupPublicKey);
  885. THROW_ON_EPIDERR(EpidVerifierSetBasename(ctx, bsn.data(), bsn.size()));
  886. EXPECT_EQ(kEpidSigValid, EpidVerify(ctx, sig, sig_len, msg.data(), 0));
  887. }
  888. TEST_F(EpidMemberTest, SignsEmptyMessageWithSigRl) {
  889. Prng my_prng;
  890. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  891. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  892. auto& msg = this->kMsg0;
  893. SigRl const* srl =
  894. reinterpret_cast<SigRl const*>(this->kSigRl5EntryData.data());
  895. size_t srl_size = this->kSigRl5EntryData.size() * sizeof(uint8_t);
  896. std::vector<uint8_t> sig_data(EpidGetSigSize(srl));
  897. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  898. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  899. THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size));
  900. EXPECT_EQ(kEpidNoErr,
  901. EpidSign(member, msg.data(), 0, nullptr, 0, sig, sig_len));
  902. // verify basic signature
  903. VerifierCtxObj ctx(this->kGroupPublicKey);
  904. THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size));
  905. EXPECT_EQ(kEpidSigValid, EpidVerify(ctx, sig, sig_len, msg.data(), 0));
  906. }
  907. TEST_F(EpidMemberTest, SignsShortMessageNoSigRl) {
  908. // check: 1, 13, 128, 256, 512, 1021, 1024 bytes
  909. // 13 and 1021 are primes
  910. Prng my_prng;
  911. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  912. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  913. std::vector<uint8_t> sig_data(EpidGetSigSize(nullptr));
  914. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  915. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  916. VerifierCtxObj ctx(this->kGroupPublicKey);
  917. size_t lengths[] = {1, 13, 128, 256,
  918. 512, 1021, 1024}; // have desired lengths to loop over
  919. std::vector<uint8_t> msg(
  920. lengths[COUNT_OF(lengths) - 1]); // allocate message for max size
  921. for (size_t n = 0; n < msg.size(); n++) {
  922. msg[n] = (uint8_t)n;
  923. }
  924. for (auto length : lengths) {
  925. EXPECT_EQ(kEpidNoErr,
  926. EpidSign(member, msg.data(), length, nullptr, 0, sig, sig_len))
  927. << "EpidSign for message_len: " << length << " failed";
  928. EXPECT_EQ(kEpidSigValid, EpidVerify(ctx, sig, sig_len, msg.data(), length))
  929. << "EpidVerify for message_len: " << length << " failed";
  930. }
  931. }
  932. TEST_F(EpidMemberTest, SignsShortMessageWithSigRl) {
  933. // check: 1, 13, 128, 256, 512, 1021, 1024 bytes
  934. // 13 and 1021 are primes
  935. Prng my_prng;
  936. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  937. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  938. SigRl const* srl =
  939. reinterpret_cast<SigRl const*>(this->kSigRl5EntryData.data());
  940. size_t srl_size = this->kSigRl5EntryData.size() * sizeof(uint8_t);
  941. std::vector<uint8_t> sig_data(EpidGetSigSize(srl));
  942. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  943. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  944. size_t message_len = 0;
  945. VerifierCtxObj ctx(this->kGroupPublicKey);
  946. THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size));
  947. size_t lengths[] = {1, 13, 128, 256,
  948. 512, 1021, 1024}; // have desired lengths to loop over
  949. std::vector<uint8_t> msg(
  950. lengths[COUNT_OF(lengths) - 1]); // allocate message for max size
  951. for (size_t n = 0; n < msg.size(); n++) {
  952. msg.at(n) = (uint8_t)n;
  953. }
  954. THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size));
  955. for (auto length : lengths) {
  956. EXPECT_EQ(kEpidNoErr,
  957. EpidSign(member, msg.data(), length, nullptr, 0, sig, sig_len))
  958. << "EpidSign for message_len: " << message_len << " failed";
  959. EXPECT_EQ(kEpidSigValid, EpidVerify(ctx, sig, sig_len, msg.data(), length))
  960. << "EpidVerify for message_len: " << message_len << " failed";
  961. }
  962. }
  963. TEST_F(EpidMemberTest, SignsLongMessageNoSigRl) {
  964. Prng my_prng;
  965. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  966. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  967. std::vector<uint8_t> sig_data(EpidGetSigSize(nullptr));
  968. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  969. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  970. VerifierCtxObj ctx(this->kGroupPublicKey);
  971. std::vector<uint8_t> msg(1000000); // allocate message for max size
  972. for (size_t n = 0; n < msg.size(); n++) {
  973. msg.at(n) = (uint8_t)n;
  974. }
  975. EXPECT_EQ(kEpidNoErr,
  976. EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len))
  977. << "EpidSign for message_len: " << 1000000 << " failed";
  978. EXPECT_EQ(kEpidSigValid,
  979. EpidVerify(ctx, sig, sig_len, msg.data(), msg.size()))
  980. << "EpidVerify for message_len: " << 1000000 << " failed";
  981. }
  982. TEST_F(EpidMemberTest, SignsLongMessageWithSigRl) {
  983. Prng my_prng;
  984. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  985. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  986. SigRl const* srl =
  987. reinterpret_cast<SigRl const*>(this->kSigRl5EntryData.data());
  988. size_t srl_size = this->kSigRl5EntryData.size() * sizeof(uint8_t);
  989. std::vector<uint8_t> sig_data(EpidGetSigSize(srl));
  990. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  991. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  992. VerifierCtxObj ctx(this->kGroupPublicKey);
  993. THROW_ON_EPIDERR(EpidVerifierSetSigRl(ctx, srl, srl_size));
  994. std::vector<uint8_t> msg(1000000); // allocate message for max size
  995. for (size_t n = 0; n < msg.size(); n++) {
  996. msg.at(n) = (uint8_t)n;
  997. }
  998. THROW_ON_EPIDERR(EpidMemberSetSigRl(member, srl, srl_size));
  999. EXPECT_EQ(kEpidNoErr,
  1000. EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len))
  1001. << "EpidSign for message_len: " << 1000000 << " failed";
  1002. EXPECT_EQ(kEpidSigValid,
  1003. EpidVerify(ctx, sig, sig_len, msg.data(), msg.size()))
  1004. << "EpidVerify for message_len: " << 1000000 << " failed";
  1005. }
  1006. TEST_F(EpidMemberTest, SignsMsgContainingAllPossibleBytesNoSigRl) {
  1007. Prng my_prng;
  1008. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  1009. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  1010. std::vector<uint8_t> sig_data(EpidGetSigSize(nullptr));
  1011. EpidSignature* sig = reinterpret_cast<EpidSignature*>(sig_data.data());
  1012. size_t sig_len = sig_data.size() * sizeof(uint8_t);
  1013. VerifierCtxObj ctx(this->kGroupPublicKey);
  1014. std::vector<uint8_t> msg = this->kData_0_255;
  1015. EXPECT_EQ(kEpidNoErr,
  1016. EpidSign(member, msg.data(), msg.size(), nullptr, 0, sig, sig_len));
  1017. EXPECT_EQ(kEpidSigValid,
  1018. EpidVerify(ctx, sig, sig_len, msg.data(), msg.size()));
  1019. }
  1020. } // namespace