verifybasic-test.cc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. * \file
  18. * \brief Epid11VerifyBasicSig unit tests.
  19. */
  20. #include "epid/common-testhelper/epid_gtest-testhelper.h"
  21. #include "gtest/gtest.h"
  22. extern "C" {
  23. #include "epid/verifier/1.1/api.h"
  24. }
  25. #include "epid/common-testhelper/1.1/verifier_wrapper-testhelper.h"
  26. #include "epid/common-testhelper/errors-testhelper.h"
  27. #include "epid/verifier/1.1/unittests/verifier-testhelper.h"
  28. namespace {
  29. TEST_F(Epid11VerifierTest, VerifyBasicSigFailsGivenNullPtr) {
  30. Epid11VerifierCtxObj verifier(this->kPubKeyStr);
  31. auto const& sig =
  32. (Epid11Signature const*)this->kSigGrpXMember0Sha256RandbaseMsg0.data();
  33. const Epid11BasicSignature basic_sig = sig->sigma0;
  34. auto& msg = this->kMsg0;
  35. EXPECT_EQ(kEpidBadArgErr,
  36. Epid11VerifyBasicSig(nullptr, &basic_sig, msg.data(), msg.size()));
  37. EXPECT_EQ(kEpidBadArgErr,
  38. Epid11VerifyBasicSig(verifier, nullptr, msg.data(), msg.size()));
  39. EXPECT_EQ(kEpidBadArgErr,
  40. Epid11VerifyBasicSig(verifier, &basic_sig, nullptr, msg.size()));
  41. }
  42. TEST_F(Epid11VerifierTest,
  43. VerifyBasicSigCanVerifyValidSignatureWithSHA256AsDefault) {
  44. Epid11VerifierCtxObj verifier(this->kPubKeyStr);
  45. auto const& sig =
  46. (Epid11Signature const*)this->kSigGrpXMember0Sha256RandbaseMsg0.data();
  47. const Epid11BasicSignature basic_sig = sig->sigma0;
  48. auto& msg = this->kMsg0;
  49. EXPECT_EQ(kEpidNoErr,
  50. Epid11VerifyBasicSig(verifier, &basic_sig, msg.data(), msg.size()));
  51. }
  52. TEST_F(Epid11VerifierTest,
  53. VerifyBasicSigDetectsInvalidSignatureGivenMatchingMessage) {
  54. Epid11VerifierCtxObj verifier(this->kPubKeyStr);
  55. auto const& sig =
  56. (Epid11Signature const*)this->kSigGrpXMember0Sha256RandbaseMsg0.data();
  57. const Epid11BasicSignature basic_sig = sig->sigma0;
  58. auto& msg = this->kMsg0;
  59. Epid11BasicSignature corrupted_basic_sig = basic_sig;
  60. corrupted_basic_sig.B.x.data.data[0]++;
  61. EXPECT_NE(kEpidNoErr, Epid11VerifyBasicSig(verifier, &corrupted_basic_sig,
  62. msg.data(), msg.size()));
  63. }
  64. TEST_F(Epid11VerifierTest,
  65. VerifyBasicSigDetectsInvalidSignatureGivenMessageMismatch) {
  66. Epid11VerifierCtxObj verifier(this->kPubKeyStr);
  67. auto const& sig =
  68. (Epid11Signature const*)this->kSigGrpXMember0Sha256RandbaseMsg0.data();
  69. const Epid11BasicSignature basic_sig = sig->sigma0;
  70. auto msg = this->kMsg0;
  71. msg[0]++; // change message for signature verification to fail
  72. EXPECT_EQ(kEpidSigInvalid,
  73. Epid11VerifyBasicSig(verifier, &basic_sig, msg.data(), msg.size()));
  74. }
  75. TEST_F(Epid11VerifierTest, VerifyBasicSigCanVerifyWithBasename) {
  76. Epid11VerifierCtxObj verifier(this->kPubKeyStr);
  77. auto const& sig =
  78. (Epid11Signature const*)this->kSigGrpXMember0Sha256Bsn0Msg0.data();
  79. const Epid11BasicSignature basic_sig = sig->sigma0;
  80. auto& msg = this->kMsg0;
  81. auto& basename = this->kBsn0;
  82. THROW_ON_EPIDERR(
  83. Epid11VerifierSetBasename(verifier, basename.data(), basename.size()));
  84. EXPECT_EQ(kEpidNoErr,
  85. Epid11VerifyBasicSig(verifier, &basic_sig, msg.data(), msg.size()));
  86. }
  87. TEST_F(Epid11VerifierTest,
  88. VerifyBasicSigCanVerifyMsgContainingAllPossibleBytes) {
  89. Epid11VerifierCtxObj verifier(kPubKeyStrForMsg0_255);
  90. auto const& sig = (Epid11Signature const*)this
  91. ->kSigGrp01Member0Sha256kBsn0Data_0_255.data();
  92. const Epid11BasicSignature basic_sig = sig->sigma0;
  93. auto& msg = this->kData_0_255;
  94. EXPECT_EQ(kEpidNoErr,
  95. Epid11VerifyBasicSig(verifier, &basic_sig, msg.data(), msg.size()));
  96. }
  97. } // namespace