decompress_privkey-test.cc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 DecompressPrivKey unit tests.
  19. */
  20. #include <cstring>
  21. #include "epid/common-testhelper/epid_gtest-testhelper.h"
  22. #include "gtest/gtest.h"
  23. extern "C" {
  24. #include "epid/member/api.h"
  25. }
  26. #include "epid/member/tiny/unittests/member-testhelper.h"
  27. bool operator==(PrivKey const& lhs, PrivKey const& rhs) {
  28. return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs));
  29. }
  30. namespace {
  31. TEST_F(EpidMemberTest, DISABLED_DecompressPrivKeyFailsGivenNullParameters) {
  32. auto const& pub_key = this->kGrpXKey;
  33. auto const& compressed_privkey = this->kGrpXMember9CompressedKey;
  34. PrivKey priv_key = {};
  35. EXPECT_EQ(kEpidBadArgErr,
  36. EpidDecompressPrivKey(nullptr, &compressed_privkey, &priv_key));
  37. EXPECT_EQ(kEpidBadArgErr,
  38. EpidDecompressPrivKey(&pub_key, nullptr, &priv_key));
  39. EXPECT_EQ(kEpidBadArgErr,
  40. EpidDecompressPrivKey(&pub_key, &compressed_privkey, nullptr));
  41. }
  42. TEST_F(EpidMemberTest, DISABLED_CanDecompressPrivKeyGivenValidCompressedKey) {
  43. auto const& pub_key = this->kGrpXKey;
  44. auto const& compressed_privkey = this->kGrpXMember9CompressedKey;
  45. auto const& expected_decompressed_key = this->kGrpXMember9PrivKey;
  46. PrivKey priv_key = {};
  47. EXPECT_EQ(kEpidNoErr,
  48. EpidDecompressPrivKey(&pub_key, &compressed_privkey, &priv_key));
  49. EXPECT_EQ(expected_decompressed_key, priv_key);
  50. }
  51. TEST_F(EpidMemberTest, DISABLED_DecompressPrivKeyFailsGivenKeysMissmatch) {
  52. auto const& pub_key = this->kGrpYKey;
  53. auto const& compressed_privkey = this->kGrpXMember9CompressedKey;
  54. PrivKey priv_key = {};
  55. EXPECT_EQ(kEpidBadArgErr,
  56. EpidDecompressPrivKey(&pub_key, &compressed_privkey, &priv_key));
  57. }
  58. TEST_F(EpidMemberTest, DISABLED_DecompressPrivKeyFailsGivenInvalidGroupKey) {
  59. // Test for cases when h1 or w of group public key are invalid.
  60. // Note h2 of group public key is not used for key decompression.
  61. auto const& compressed_privkey = this->kGrpXMember9CompressedKey;
  62. PrivKey priv_key = {};
  63. auto pub_key_h1 = this->kGrpXKey;
  64. pub_key_h1.h1.x.data.data[0]++;
  65. EXPECT_EQ(kEpidBadArgErr,
  66. EpidDecompressPrivKey(&pub_key_h1, &compressed_privkey, &priv_key));
  67. auto pub_key_w = this->kGrpXKey;
  68. pub_key_w.w.x[0].data.data[0]++;
  69. EXPECT_EQ(kEpidBadArgErr,
  70. EpidDecompressPrivKey(&pub_key_w, &compressed_privkey, &priv_key));
  71. }
  72. TEST_F(EpidMemberTest,
  73. DISABLED_DecompressPrivKeyFailsGivenInvalidCompressedKey) {
  74. auto const& pub_key = this->kGrpXKey;
  75. PrivKey priv_key = {};
  76. auto compressed_privkey_ax = this->kGrpXMember9CompressedKey;
  77. compressed_privkey_ax.ax.data.data[0]++;
  78. EXPECT_EQ(kEpidBadArgErr,
  79. EpidDecompressPrivKey(&pub_key, &compressed_privkey_ax, &priv_key));
  80. auto compressed_privkey_seed = this->kGrpXMember9CompressedKey;
  81. compressed_privkey_seed.seed.data[0]++;
  82. EXPECT_EQ(kEpidBadArgErr, EpidDecompressPrivKey(
  83. &pub_key, &compressed_privkey_seed, &priv_key));
  84. }
  85. } // namespace