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