getrandom-tss-test.cc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. /// TPM Context unit tests.
  17. /*! \file */
  18. #include <limits.h>
  19. #include <stdint.h>
  20. #include "gtest/gtest.h"
  21. #include "epid/common-testhelper/epid2params_wrapper-testhelper.h"
  22. #include "epid/member/tpm2/unittests/tpm2-testhelper.h"
  23. extern "C" {
  24. #include "epid/member/tpm2/context.h"
  25. #include "epid/member/tpm2/getrandom.h"
  26. }
  27. namespace {
  28. TEST_F(EpidTpm2Test, GetRandomOnTssReturnsDifferentBufs) {
  29. Epid2ParamsObj epid2params;
  30. Tpm2CtxObj tss(nullptr, nullptr, nullptr, epid2params);
  31. size_t length = 10;
  32. std::vector<uint8_t> buf1(length, (uint8_t)0);
  33. std::vector<uint8_t> buf2(length, (uint8_t)0);
  34. EXPECT_EQ(kEpidNoErr, Tpm2GetRandom(tss, length * CHAR_BIT, buf1.data()));
  35. EXPECT_EQ(kEpidNoErr, Tpm2GetRandom(tss, length * CHAR_BIT, buf2.data()));
  36. EXPECT_NE(buf1, buf2);
  37. }
  38. } // namespace