get_sigsize-test.cc 3.5 KB

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