get_sigsize-test.cc 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 GetSigSize unit tests.
  19. */
  20. #include "epid/common-testhelper/epid_gtest-testhelper.h"
  21. #include "gtest/gtest.h"
  22. extern "C" {
  23. #include "epid/member/api.h"
  24. }
  25. #include "epid/member/unittests/member-testhelper.h"
  26. namespace {
  27. TEST_F(EpidMemberTest, GetSigSizeReturnsSizeofBasicSigGivenNullPointer) {
  28. size_t sig_size_without_sig_rl = sizeof(EpidSignature) - sizeof(NrProof);
  29. EXPECT_EQ(sig_size_without_sig_rl, EpidGetSigSize(nullptr));
  30. }
  31. TEST_F(EpidMemberTest, GetSigSizeReturnsCorrectValueGivenValidSigRl) {
  32. SigRl srl = {{{0}}, {{0}}, {{0}}, {{{{0}, {0}}, {{0}, {0}}}}};
  33. OctStr32 octstr32_0 = {0x00, 0x00, 0x00, 0x00};
  34. OctStr32 octstr32_1 = {0x00, 0x00, 0x00, 0x01};
  35. OctStr32 octstr32_2 = {0x00, 0x00, 0x00, 0x02};
  36. OctStr32 octstr32_16 = {0x00, 0x00, 0x00, 0x10};
  37. OctStr32 octstr32_256 = {0x00, 0x00, 0x01, 0x00};
  38. OctStr32 octstr32_65536 = {0x00, 0x01, 0x00, 0x00};
  39. OctStr32 octstr32_4294967295 = {0xff, 0xff, 0xff, 0xff};
  40. size_t one_entry_size = sizeof(NrProof);
  41. size_t sig_size_0_entries = sizeof(EpidSignature) - one_entry_size;
  42. size_t sig_size_1_entry = sig_size_0_entries + one_entry_size;
  43. size_t sig_size_2_entries = sig_size_0_entries + 2 * one_entry_size;
  44. size_t sig_size_16_entries = sig_size_0_entries + 16 * one_entry_size;
  45. size_t sig_size_256_entries = sig_size_0_entries + 256 * one_entry_size;
  46. size_t sig_size_65536_entries = sig_size_0_entries + 65536 * one_entry_size;
  47. // no entries
  48. srl.n2 = octstr32_0;
  49. EXPECT_EQ(sig_size_0_entries, EpidGetSigSize(&srl));
  50. // 1 entry
  51. srl.n2 = octstr32_1;
  52. EXPECT_EQ(sig_size_1_entry, EpidGetSigSize(&srl));
  53. // 2 entries
  54. srl.n2 = octstr32_2;
  55. EXPECT_EQ(sig_size_2_entries, EpidGetSigSize(&srl));
  56. // 16 entries
  57. srl.n2 = octstr32_16;
  58. EXPECT_EQ(sig_size_16_entries, EpidGetSigSize(&srl));
  59. // 256 entries
  60. srl.n2 = octstr32_256;
  61. EXPECT_EQ(sig_size_256_entries, EpidGetSigSize(&srl));
  62. // 65536 entries
  63. srl.n2 = octstr32_65536;
  64. EXPECT_EQ(sig_size_65536_entries, EpidGetSigSize(&srl));
  65. // 4294967295 entries
  66. srl.n2 = octstr32_4294967295;
  67. #if (SIZE_MAX <= 0xFFFFFFFF) // When size_t value is 32 bit or lower
  68. EXPECT_EQ(sig_size_0_entries, EpidGetSigSize(&srl));
  69. #else
  70. size_t sig_size_4294967295_entries =
  71. sig_size_0_entries + 4294967295 * one_entry_size;
  72. EXPECT_EQ(sig_size_4294967295_entries, EpidGetSigSize(&srl));
  73. #endif
  74. }
  75. TEST_F(EpidMemberTest,
  76. GetSigSizeReturnsCorrectValueGivenValidSigRlUsingIKGFData) {
  77. const std::vector<uint8_t> sigrl_bin = {
  78. #include "epid/common-testhelper/testdata/ikgf/groupa/sigrl.inc"
  79. };
  80. SigRl const* sig_rl = reinterpret_cast<const SigRl*>(sigrl_bin.data());
  81. size_t sig_size_3_entries =
  82. sizeof(EpidSignature) - sizeof(NrProof) + 3 * sizeof(NrProof);
  83. // 3 entries
  84. EXPECT_EQ(sig_size_3_entries, EpidGetSigSize(sig_rl));
  85. }
  86. } // namespace