load_external-test.cc 2.3 KB

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