sign-test.cc 53 KB

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