1 /*############################################################################
2 # Copyright 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 /// Tpm2LoadExternal unit tests.
17 /*! \file */
18
19 #include <stdint.h>
20
21 #include "epid/common-testhelper/epid2params_wrapper-testhelper.h"
22 #include "epid/common-testhelper/errors-testhelper.h"
23 #include "epid/common-testhelper/prng-testhelper.h"
24 #include "epid/member/tpm2/unittests/tpm2-testhelper.h"
25 #include "gtest/gtest.h"
26
27 extern "C" {
28 #include "epid/member/tpm2/load_external.h"
29 }
30
31 namespace {
TEST_F(EpidTpm2Test,SetHashAlgFailsIfHashAlgNotSupported)32 TEST_F(EpidTpm2Test, SetHashAlgFailsIfHashAlgNotSupported) {
33 Prng my_prng;
34 Epid2ParamsObj epid2params;
35 FpElemStr f_str = this->kMemberFValue;
36 Tpm2CtxObj ctx(&Prng::Generate, &my_prng, &f_str, epid2params);
37 EXPECT_EQ(kEpidHashAlgorithmNotSupported, Tpm2SetHashAlg(ctx, kSha3_256));
38 EXPECT_EQ(kEpidHashAlgorithmNotSupported, Tpm2SetHashAlg(ctx, kSha3_384));
39 EXPECT_EQ(kEpidHashAlgorithmNotSupported, Tpm2SetHashAlg(ctx, kSha3_512));
40 }
41 //////////////////////////////////////////////////////////////////////////
42 // Tpm2LoadExternal Tests
TEST_F(EpidTpm2Test,LoadExternalFailsGivenNullParameters)43 TEST_F(EpidTpm2Test, LoadExternalFailsGivenNullParameters) {
44 Prng my_prng;
45 Epid2ParamsObj epid2params;
46 FpElemStr f_str = this->kMemberFValue;
47 Tpm2CtxObj ctx(&Prng::Generate, &my_prng, &f_str, epid2params);
48 THROW_ON_EPIDERR(Tpm2SetHashAlg(ctx, kSha256));
49 EXPECT_EQ(kEpidBadArgErr, Tpm2LoadExternal(nullptr, &f_str));
50 EXPECT_EQ(kEpidBadArgErr, Tpm2LoadExternal(ctx, nullptr));
51 }
TEST_F(EpidTpm2Test,LoadExternalCanLoadFValueSha256)52 TEST_F(EpidTpm2Test, LoadExternalCanLoadFValueSha256) {
53 Prng my_prng;
54 Epid2ParamsObj epid2params;
55 FpElemStr f_str = this->kMemberFValue;
56 Tpm2CtxObj ctx(&Prng::Generate, &my_prng, &f_str, epid2params);
57 THROW_ON_EPIDERR(Tpm2SetHashAlg(ctx, kSha256));
58 EXPECT_EQ(kEpidNoErr, Tpm2LoadExternal(ctx, &f_str));
59 }
60 } // namespace
61