ecgroup_wrapper-test.cc 5.1 KB

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