presig-test.cc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 ComputePreSig unit tests.
  19. */
  20. #include <algorithm>
  21. #include <cstring>
  22. #include <limits>
  23. #include <vector>
  24. #include "epid/common-testhelper/epid_gtest-testhelper.h"
  25. #include "gtest/gtest.h"
  26. extern "C" {
  27. #include "epid/member/api.h"
  28. }
  29. #include "epid/common-testhelper/errors-testhelper.h"
  30. #include "epid/common-testhelper/prng-testhelper.h"
  31. #include "epid/member/tiny/unittests/member-testhelper.h"
  32. /// Count of elements in array
  33. #define COUNT_OF(A) (sizeof(A) / sizeof((A)[0]))
  34. namespace {
  35. ///////////////////////////////////////////////////////////////////////
  36. // EpidAddPreSigs
  37. TEST_F(EpidMemberTest, DISABLED_AddPreSigsFailsGivenNullPointer) {
  38. Prng my_prng;
  39. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  40. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  41. EXPECT_EQ(kEpidBadArgErr, EpidAddPreSigs(nullptr, 1));
  42. }
  43. TEST_F(EpidMemberTest, DISABLED_AddPreSigsFailsGivenHugeNumberOfPreSigs) {
  44. Prng my_prng;
  45. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  46. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  47. // number_presigs = 0x80..01 of size equal to sizeof(size_t)
  48. EXPECT_NE(kEpidNoErr, EpidAddPreSigs(member, (SIZE_MAX >> 1) + 2));
  49. }
  50. TEST_F(EpidMemberTest,
  51. DISABLED_AddPreSigsComputesSpecifiedNumberOfPresigsIfInputPresigsNull) {
  52. Prng my_prng;
  53. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  54. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  55. ASSERT_EQ(kEpidNoErr, EpidAddPreSigs(member, 2));
  56. ASSERT_EQ(kEpidNoErr, EpidAddPreSigs(member, 1));
  57. // request to generate 0 pre-computed signatures do nothing
  58. ASSERT_EQ(kEpidNoErr, EpidAddPreSigs(member, 0));
  59. EXPECT_EQ((size_t)3, EpidGetNumPreSigs(member));
  60. }
  61. TEST_F(EpidMemberTest,
  62. DISABLED_AddPreSigsAddsCorrectNumberOfPresigsGivenValidInput) {
  63. Prng my_prng;
  64. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  65. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  66. const size_t presigs1_added = 2;
  67. const size_t presigs2_added = 3;
  68. // add
  69. ASSERT_EQ(kEpidNoErr, EpidAddPreSigs(member, presigs1_added));
  70. // extend
  71. ASSERT_EQ(kEpidNoErr, EpidAddPreSigs(member, presigs2_added));
  72. // add empty pre-computed signatures array does not affect internal pool
  73. ASSERT_EQ(kEpidNoErr, EpidAddPreSigs(member, 0));
  74. EXPECT_EQ(presigs1_added + presigs2_added, EpidGetNumPreSigs(member));
  75. }
  76. ///////////////////////////////////////////////////////////////////////
  77. // EpidGetNumPreSigs
  78. TEST_F(EpidMemberTest, DISABLED_GetNumPreSigsReturnsZeroGivenNullptr) {
  79. EXPECT_EQ((size_t)0, EpidGetNumPreSigs(nullptr));
  80. }
  81. TEST_F(EpidMemberTest, DISABLED_NumPreSigsForNewleyCreatedContextIsZero) {
  82. Prng my_prng;
  83. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  84. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  85. EXPECT_EQ((size_t)0, EpidGetNumPreSigs(member));
  86. }
  87. TEST_F(EpidMemberTest, DISABLED_GetNumPreSigsReturnsNumberOfAddedPresigs) {
  88. Prng my_prng;
  89. MemberCtxObj member(this->kGroupPublicKey, this->kMemberPrivateKey,
  90. this->kMemberPrecomp, &Prng::Generate, &my_prng);
  91. const size_t presigs_added = 5;
  92. THROW_ON_EPIDERR(EpidAddPreSigs(member, presigs_added));
  93. EXPECT_EQ(presigs_added, EpidGetNumPreSigs(member));
  94. }
  95. } // namespace