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