provision_compressed-test.cc 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*############################################################################
  2. # Copyright 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 Provision compressed unit tests.
  19. */
  20. #include <cstring>
  21. #include <vector>
  22. #include "epid/common-testhelper/epid_gtest-testhelper.h"
  23. #include "gtest/gtest.h"
  24. #include "epid/common-testhelper/errors-testhelper.h"
  25. #include "epid/common-testhelper/mem_params-testhelper.h"
  26. #include "epid/common-testhelper/prng-testhelper.h"
  27. #include "epid/member/unittests/member-testhelper.h"
  28. extern "C" {
  29. #include "epid/member/api.h"
  30. #include "epid/member/src/context.h"
  31. }
  32. namespace {
  33. EpidStatus ProvisionCompressedAndStart(
  34. MemberCtx* ctx, GroupPubKey const* pub_key,
  35. CompressedPrivKey const* compressed_privkey,
  36. MemberPrecomp const* precomp_str) {
  37. EpidStatus sts;
  38. sts = EpidProvisionCompressed(ctx, pub_key, compressed_privkey, precomp_str);
  39. if (sts != kEpidNoErr) {
  40. return sts;
  41. }
  42. sts = EpidMemberStartup(ctx);
  43. return sts;
  44. }
  45. TEST_F(EpidMemberTest, ProvisionCompressedFailsGivenNullParameters) {
  46. Prng prng;
  47. GroupPubKey pub_key = this->kGrpXKey;
  48. CompressedPrivKey priv_key = this->kGrpXMember9CompressedKey;
  49. // Note: this MemberPrecomp is for the wrong group, however it should not
  50. // be checked in Provision because doing so would negate the performance
  51. // boost of using the precomp.
  52. MemberPrecomp precomp = this->kMemberPrecomp;
  53. MemberParams params = {0};
  54. SetMemberParams(&Prng::Generate, &prng, nullptr, &params);
  55. MemberCtxObj member(&params);
  56. EXPECT_EQ(kEpidBadArgErr,
  57. EpidProvisionCompressed(nullptr, &pub_key, &priv_key, &precomp));
  58. EXPECT_EQ(kEpidBadArgErr,
  59. EpidProvisionCompressed(member, nullptr, &priv_key, &precomp));
  60. EXPECT_EQ(kEpidBadArgErr,
  61. EpidProvisionCompressed(member, &pub_key, nullptr, &precomp));
  62. EXPECT_EQ(kEpidBadArgErr,
  63. EpidProvisionCompressed(nullptr, &pub_key, &priv_key, nullptr));
  64. EXPECT_EQ(kEpidBadArgErr,
  65. EpidProvisionCompressed(member, nullptr, &priv_key, nullptr));
  66. EXPECT_EQ(kEpidBadArgErr,
  67. EpidProvisionCompressed(member, &pub_key, nullptr, nullptr));
  68. }
  69. TEST_F(EpidMemberTest, ProvisionCompressedSucceedsGivenValidParameters) {
  70. Prng prng;
  71. GroupPubKey pub_key = this->kGrpXKey;
  72. CompressedPrivKey priv_key = this->kGrpXMember9CompressedKey;
  73. // Note: this MemberPrecomp is for the wrong group, however it should not
  74. // be checked in Provision because doing so would negate the performance
  75. // boost of using the precomp.
  76. MemberPrecomp precomp = this->kMemberPrecomp;
  77. MemberParams params = {0};
  78. SetMemberParams(&Prng::Generate, &prng, nullptr, &params);
  79. MemberCtxObj member(&params);
  80. EXPECT_EQ(kEpidNoErr,
  81. EpidProvisionCompressed(member, &pub_key, &priv_key, &precomp));
  82. EXPECT_EQ(kEpidNoErr,
  83. EpidProvisionCompressed(member, &pub_key, &priv_key, nullptr));
  84. }
  85. TEST_F(EpidMemberTest, ProvisionCompressedFailsForInvalidGroupPubKey) {
  86. Prng prng;
  87. GroupPubKey pub_key = this->kGrpXKey;
  88. CompressedPrivKey priv_key = this->kGrpXMember9CompressedKey;
  89. // Note: this MemberPrecomp is for the wrong group, however it should not
  90. // be checked in Provision because doing so would negate the performance
  91. // boost of using the precomp.
  92. MemberPrecomp precomp = this->kMemberPrecomp;
  93. MemberParams params = {0};
  94. SetMemberParams(&Prng::Generate, &prng, nullptr, &params);
  95. MemberCtxObj member(&params);
  96. pub_key = this->kGrpXKey;
  97. pub_key.h1.x.data.data[0]++;
  98. EXPECT_EQ(kEpidBadArgErr,
  99. ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp));
  100. EXPECT_EQ(kEpidBadArgErr,
  101. ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr));
  102. pub_key = this->kGrpXKey;
  103. pub_key.h1.y.data.data[0]++;
  104. EXPECT_EQ(kEpidBadArgErr,
  105. ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp));
  106. EXPECT_EQ(kEpidBadArgErr,
  107. ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr));
  108. pub_key = this->kGrpXKey;
  109. pub_key.w.x[0].data.data[0]++;
  110. EXPECT_EQ(kEpidBadArgErr,
  111. ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp));
  112. EXPECT_EQ(kEpidBadArgErr,
  113. ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr));
  114. pub_key = this->kGrpXKey;
  115. pub_key.w.x[1].data.data[0]++;
  116. EXPECT_EQ(kEpidBadArgErr,
  117. ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp));
  118. EXPECT_EQ(kEpidBadArgErr,
  119. ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr));
  120. pub_key = this->kGrpXKey;
  121. pub_key.w.y[0].data.data[0]++;
  122. EXPECT_EQ(kEpidBadArgErr,
  123. ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp));
  124. EXPECT_EQ(kEpidBadArgErr,
  125. ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr));
  126. pub_key = this->kGrpXKey;
  127. pub_key.w.y[1].data.data[0]++;
  128. EXPECT_EQ(kEpidBadArgErr,
  129. ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp));
  130. EXPECT_EQ(kEpidBadArgErr,
  131. ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr));
  132. }
  133. TEST_F(EpidMemberTest, ProvisionCompressedFailsForInvalidPrivateKey) {
  134. Prng prng;
  135. GroupPubKey pub_key = this->kGrpXKey;
  136. CompressedPrivKey priv_key = this->kGrpXMember9CompressedKey;
  137. // Note: this MemberPrecomp is for the wrong group, however it should not
  138. // be checked in Provision because doing so would negate the performance
  139. // boost of using the precomp.
  140. MemberPrecomp precomp = this->kMemberPrecomp;
  141. MemberParams params = {0};
  142. SetMemberParams(&Prng::Generate, &prng, nullptr, &params);
  143. MemberCtxObj member(&params);
  144. priv_key = this->kGrpXMember9CompressedKey;
  145. priv_key.ax.data.data[0]++;
  146. EXPECT_EQ(kEpidBadArgErr,
  147. ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp));
  148. EXPECT_EQ(kEpidBadArgErr,
  149. ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr));
  150. priv_key = this->kGrpXMember9CompressedKey;
  151. priv_key.seed.data[0]++;
  152. EXPECT_EQ(kEpidBadArgErr,
  153. ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp));
  154. EXPECT_EQ(kEpidBadArgErr,
  155. ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr));
  156. }
  157. } // namespace