ecgroup_wrapper-test.cc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*############################################################################
  2. # Copyright 2016 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 EcGroup C++ wrapper unit tests.
  19. */
  20. #include "gtest/gtest.h"
  21. #include "epid/common-testhelper/errors-testhelper.h"
  22. #include "epid/common-testhelper/bignum_wrapper-testhelper.h"
  23. #include "epid/common-testhelper/ffelement_wrapper-testhelper.h"
  24. #include "epid/common-testhelper/finite_field_wrapper-testhelper.h"
  25. #include "epid/common-testhelper/ecgroup_wrapper-testhelper.h"
  26. #include "epid/common-testhelper/ecpoint_wrapper-testhelper.h"
  27. extern "C" {
  28. #include "epid/common/math/bignum.h"
  29. #include "epid/common/types.h"
  30. }
  31. namespace {
  32. // Use Test Fixture for SetUp and TearDown
  33. class EcGroupObjTest : public ::testing::Test {
  34. public:
  35. static const BigNumStr q_str;
  36. static const FqElemStr b_str;
  37. static const BigNumStr p_str;
  38. static const BigNumStr h1;
  39. static const G1ElemStr g1_str;
  40. };
  41. const BigNumStr EcGroupObjTest::q_str = {
  42. {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2, 0x5E,
  43. 0xEE, 0x71, 0xA4, 0x9F, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x98, 0x0A, 0x82,
  44. 0xD3, 0x29, 0x2D, 0xDB, 0xAE, 0xD3, 0x30, 0x13}}};
  45. const FqElemStr EcGroupObjTest::b_str = {
  46. {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  47. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  48. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}}};
  49. const BigNumStr EcGroupObjTest::p_str = {
  50. {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2, 0x5E,
  51. 0xEE, 0x71, 0xA4, 0x9E, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x99, 0x92, 0x1A,
  52. 0xF6, 0x2D, 0x53, 0x6C, 0xD1, 0x0B, 0x50, 0x0D}}};
  53. const BigNumStr EcGroupObjTest::h1 = {
  54. {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  55. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  56. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}};
  57. const G1ElemStr EcGroupObjTest::g1_str = {
  58. {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  59. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  60. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}},
  61. {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  62. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  63. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}}}};
  64. TEST_F(EcGroupObjTest, ObjDefaultConstructedIsNotNull) {
  65. EcGroupObj group;
  66. EXPECT_NE(nullptr, (EcGroup*)group);
  67. }
  68. TEST_F(EcGroupObjTest, AssignmentCopiesPointer) {
  69. EcGroupObj group1;
  70. EcGroupObj group2;
  71. EXPECT_NE((EcGroup*)group1, (EcGroup*)group2);
  72. group1 = group2;
  73. EXPECT_EQ((EcGroup*)group1, (EcGroup*)group2);
  74. }
  75. TEST_F(EcGroupObjTest, CopyConstructorCopiesPointer) {
  76. EcGroupObj group1;
  77. EcGroupObj group2(group1);
  78. EXPECT_EQ((EcGroup*)group1, (EcGroup*)group2);
  79. }
  80. TEST_F(EcGroupObjTest, ConstructorDoesNotThrow) {
  81. EcGroupObj group1;
  82. FiniteFieldObj fq(this->q_str);
  83. EcGroupObj group2(&fq, FfElementObj(&fq), FfElementObj(&fq, this->b_str),
  84. FfElementObj(&fq, this->g1_str.x),
  85. FfElementObj(&fq, this->g1_str.y), BigNumObj(this->p_str),
  86. BigNumObj(this->h1));
  87. }
  88. TEST_F(EcGroupObjTest, CanCastConstToConstPointer) {
  89. EcGroupObj const group;
  90. EcGroup const* group_ptr = group;
  91. (void)group_ptr;
  92. }
  93. TEST_F(EcGroupObjTest, CanGetConstPointerFromConst) {
  94. EcGroupObj const group;
  95. EcGroup const* group_ptr = group.getc();
  96. (void)group_ptr;
  97. }
  98. /*
  99. The following tests are expected to result in
  100. compile time errors (by design)
  101. */
  102. /*
  103. TEST_F(EcGroupObjTest, CannotCastConstToNonConstPointer) {
  104. EcGroupObj const group;
  105. EcGroup * group_ptr = group;
  106. (void) group_ptr;
  107. }
  108. TEST_F(EcGroupObjTest, CannotGetNonConstPointerFromConst) {
  109. EcGroupObj const group;
  110. EcGroup * group_ptr = group.get();
  111. (void) group_ptr;
  112. }
  113. */
  114. TEST_F(EcGroupObjTest, CanCastNonConstToConstPointer) {
  115. EcGroupObj group;
  116. EcGroup const* group_ptr = group;
  117. (void)group_ptr;
  118. }
  119. TEST_F(EcGroupObjTest, CanGetConstPointerFromNonConst) {
  120. EcGroupObj group;
  121. EcGroup const* group_ptr = group.getc();
  122. (void)group_ptr;
  123. }
  124. TEST_F(EcGroupObjTest, CanCastNonConstToNonConstPointer) {
  125. EcGroupObj group;
  126. EcGroup* group_ptr = group;
  127. (void)group_ptr;
  128. }
  129. TEST_F(EcGroupObjTest, CanGetNonConstPointerFromNonConst) {
  130. EcGroupObj group;
  131. EcGroup* group_ptr = group.get();
  132. (void)group_ptr;
  133. }
  134. } // namespace