get_sigsize-test.cc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*############################################################################
  2. # Copyright 2016 Intel Corporation
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################*/
  16. /*!
  17. * \file
  18. * \brief GetSigSize unit tests.
  19. */
  20. #include "gtest/gtest.h"
  21. extern "C" {
  22. #include "epid/member/api.h"
  23. }
  24. #include "epid/member/unittests/member-testhelper.h"
  25. namespace {
  26. TEST_F(EpidMemberTest, GetSigSizeReturnsSizeofBasicSigGivenNullPointer) {
  27. size_t sig_size_without_sig_rl = sizeof(EpidSignature) - sizeof(NrProof);
  28. EXPECT_EQ(sig_size_without_sig_rl, EpidGetSigSize(nullptr));
  29. }
  30. TEST_F(EpidMemberTest, GetSigSizeReturnsCorrectValueGivenValidSigRl) {
  31. SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}};
  32. OctStr32 octstr32_0 = {0x00, 0x00, 0x00, 0x00};
  33. OctStr32 octstr32_1 = {0x00, 0x00, 0x00, 0x01};
  34. OctStr32 octstr32_2 = {0x00, 0x00, 0x00, 0x02};
  35. OctStr32 octstr32_16 = {0x00, 0x00, 0x00, 0x10};
  36. OctStr32 octstr32_256 = {0x00, 0x00, 0x01, 0x00};
  37. OctStr32 octstr32_65536 = {0x00, 0x01, 0x00, 0x00};
  38. OctStr32 octstr32_4294967295 = {0xff, 0xff, 0xff, 0xff};
  39. size_t one_entry_size = sizeof(NrProof);
  40. size_t sig_size_0_entries = sizeof(EpidSignature) - one_entry_size;
  41. size_t sig_size_1_entry = sig_size_0_entries + one_entry_size;
  42. size_t sig_size_2_entries = sig_size_0_entries + 2 * one_entry_size;
  43. size_t sig_size_16_entries = sig_size_0_entries + 16 * one_entry_size;
  44. size_t sig_size_256_entries = sig_size_0_entries + 256 * one_entry_size;
  45. size_t sig_size_65536_entries = sig_size_0_entries + 65536 * one_entry_size;
  46. // no entries
  47. srl.n2 = octstr32_0;
  48. EXPECT_EQ(sig_size_0_entries, EpidGetSigSize(&srl));
  49. // 1 entry
  50. srl.n2 = octstr32_1;
  51. EXPECT_EQ(sig_size_1_entry, EpidGetSigSize(&srl));
  52. // 2 entries
  53. srl.n2 = octstr32_2;
  54. EXPECT_EQ(sig_size_2_entries, EpidGetSigSize(&srl));
  55. // 16 entries
  56. srl.n2 = octstr32_16;
  57. EXPECT_EQ(sig_size_16_entries, EpidGetSigSize(&srl));
  58. // 256 entries
  59. srl.n2 = octstr32_256;
  60. EXPECT_EQ(sig_size_256_entries, EpidGetSigSize(&srl));
  61. // 65536 entries
  62. srl.n2 = octstr32_65536;
  63. EXPECT_EQ(sig_size_65536_entries, EpidGetSigSize(&srl));
  64. // 4294967295 entries
  65. srl.n2 = octstr32_4294967295;
  66. #if (SIZE_MAX <= 0xFFFFFFFF) // When size_t value is 32 bit or lower
  67. EXPECT_EQ(sig_size_0_entries, EpidGetSigSize(&srl));
  68. #else
  69. size_t sig_size_4294967295_entries =
  70. sig_size_0_entries + 4294967295 * one_entry_size;
  71. EXPECT_EQ(sig_size_4294967295_entries, EpidGetSigSize(&srl));
  72. #endif
  73. }
  74. TEST_F(EpidMemberTest,
  75. GetSigSizeReturnsCorrectValueGivenValidSigRlUsingIKGFData) {
  76. const std::vector<uint8_t> sigrl_bin = {
  77. #include "epid/common-testhelper/testdata/ikgf/groupa/sigrl.inc"
  78. };
  79. SigRl const* sig_rl = reinterpret_cast<const SigRl*>(sigrl_bin.data());
  80. size_t sig_size_3_entries =
  81. sizeof(EpidSignature) - sizeof(NrProof) + 3 * sizeof(NrProof);
  82. // 3 entries
  83. EXPECT_EQ(sig_size_3_entries, EpidGetSigSize(sig_rl));
  84. }
  85. } // namespace