sign-test.cc 50 KB

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