epid_params-testhelper.cc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 Intel(R) EPID 1.1 parameters C++ wrapper implementation.
  19. */
  20. #include <cstring>
  21. #include "epid/common-testhelper/1.1/epid_params-testhelper.h"
  22. #include "epid/common-testhelper/errors-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/bignum_wrapper-testhelper.h"
  26. extern "C" {
  27. #include "epid/common/math/src/ecgroup-internal.h"
  28. #include "epid/common/math/src/finitefield-internal.h"
  29. #include "epid/common/math/src/pairing-internal.h"
  30. }
  31. #ifndef COUNT_OF
  32. #define COUNT_OF(a) (sizeof(a) / sizeof((a)[0]))
  33. #endif // COUNT_OF
  34. Epid11ParamsObj::Epid11ParamsObj() {
  35. // construct Fq finite field
  36. FiniteFieldObj fq(this->q_str_);
  37. // Create G1
  38. // G1 is an elliptic curve group E(Fq).It can be initialized as follows:
  39. // Set G1 = E(Fq).init(p, q, h, a, b, g1.x, g1.y)
  40. G1 = EcGroupObj(&fq, FfElementObj(&fq, a_str_), FfElementObj(&fq, b_str_),
  41. FfElementObj(&fq, g1_str_.x), FfElementObj(&fq, g1_str_.y),
  42. BigNumObj(p_str_), BigNumObj(h_str_));
  43. // construct Fq1 finite field
  44. FiniteFieldObj fq1(this->q1_str_);
  45. // Create G3
  46. // G3 is an elliptic curve group E(Fq) as well (but with different
  47. // parameters).
  48. // It can be initialized as follows:
  49. // Set G3 = Fq.init(p', q', h', a', b', g3.x, g3.y)
  50. G3 =
  51. EcGroupObj(&fq1, FfElementObj(&fq1, a1_str_), FfElementObj(&fq1, b1_str_),
  52. FfElementObj(&fq1, g3_str_.x), FfElementObj(&fq1, g3_str_.y),
  53. BigNumObj(p1_str_), BigNumObj(h1_str_));
  54. // construct Fqd finite field
  55. FiniteFieldObj fqd(fq, this->coeffs_str_, COUNT_OF(this->coeffs_str_));
  56. // Fqk ground element is {-qnr, 0, 0}
  57. FfElementObj neg_qnr(&fq);
  58. THROW_ON_EPIDERR(FfNeg(fq, FfElementObj(&fq, qnr_str), neg_qnr));
  59. Fq3ElemStr ground_element_str = {0};
  60. THROW_ON_EPIDERR(WriteFfElement(fq, neg_qnr, &ground_element_str.a[0],
  61. sizeof(ground_element_str.a[0])));
  62. FfElementObj ground_element(&fqd, ground_element_str);
  63. // construct GT:=Fqk finite field
  64. GT = FiniteFieldObj(fqd, ground_element, 2);
  65. // G2 is an elliptic curve group E(Fqd).It can be initialized as follows:
  66. FfElementObj qnr(&fq, qnr_str);
  67. // twista = (a * qnr * qnr) mod q
  68. FfElementObj twista_fq(&fq, a_str_);
  69. THROW_ON_EPIDERR(FfMul(fq, twista_fq, qnr, twista_fq));
  70. THROW_ON_EPIDERR(FfMul(fq, twista_fq, qnr, twista_fq));
  71. Fq3ElemStr twista_str = {0};
  72. THROW_ON_EPIDERR(
  73. WriteFfElement(fq, twista_fq, &twista_str.a[0], sizeof(twista_str.a[0])));
  74. // twistb = (b * qnr * qnr * qnr) mod q
  75. FfElementObj twistb_fq(&fq, b_str_);
  76. THROW_ON_EPIDERR(FfMul(fq, twistb_fq, qnr, twistb_fq));
  77. THROW_ON_EPIDERR(FfMul(fq, twistb_fq, qnr, twistb_fq));
  78. THROW_ON_EPIDERR(FfMul(fq, twistb_fq, qnr, twistb_fq));
  79. Fq3ElemStr twistb_str = {0};
  80. THROW_ON_EPIDERR(
  81. WriteFfElement(fq, twistb_fq, &twistb_str.a[0], sizeof(twistb_str.a[0])));
  82. // cofactor is 1 for G2
  83. const BigNumStr h2_str_ = {
  84. {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  85. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  86. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}};
  87. // Create G2
  88. // Set G2 = E(Fqd).init(orderG2, param(Fqd), twista, twistb, g2.x, g2.y).
  89. G2 = EcGroupObj(&fqd, FfElementObj(&fqd, twista_str),
  90. FfElementObj(&fqd, twistb_str), FfElementObj(&fqd, g2x_str_),
  91. FfElementObj(&fqd, g2y_str_), BigNumObj(orderG2_str),
  92. BigNumObj(h2_str_));
  93. }
  94. const BigNumStr Epid11ParamsObj::p_str_ = {
  95. {{0x00, 0x00, 0x89, 0x57, 0x3F, 0x17, 0x47, 0x30, 0x8C, 0x43, 0xD5, 0xEE,
  96. 0x41, 0x97, 0x96, 0x19, 0x72, 0xBB, 0x86, 0x88, 0xED, 0x4B, 0xEF, 0x04,
  97. 0xAB, 0xAE, 0xC3, 0x8E, 0xEC, 0x51, 0xC3, 0xD3}}};
  98. const BigNumStr Epid11ParamsObj::q_str_ = {
  99. {{0x09, 0xF9, 0x24, 0xE5, 0xD9, 0xBC, 0x67, 0x7F, 0x81, 0x0D, 0xF0, 0x25,
  100. 0x58, 0xF7, 0x53, 0x13, 0xA9, 0x8A, 0xA6, 0x10, 0x47, 0x65, 0x5D, 0x73,
  101. 0x9E, 0xF1, 0x94, 0xEB, 0x05, 0xB1, 0xA7, 0x11}}};
  102. const std::vector<uint8_t> Epid11ParamsObj::h_str_ = {0x00, 0x00, 0x12, 0x97};
  103. const FqElemStr Epid11ParamsObj::a_str_ = {
  104. {{0x05, 0x53, 0xD7, 0xC8, 0x81, 0xF7, 0x78, 0xC2, 0x2C, 0x37, 0xB6, 0xC0,
  105. 0x16, 0x3E, 0x68, 0x24, 0x3A, 0x84, 0x78, 0x1C, 0x0A, 0xDF, 0x9B, 0xB3,
  106. 0xED, 0x21, 0xC4, 0x46, 0xE5, 0xA7, 0xA3, 0x92}}};
  107. const FqElemStr Epid11ParamsObj::b_str_ = {
  108. {{0x00, 0x3A, 0x2E, 0x39, 0x0E, 0x10, 0xD8, 0xAC, 0x47, 0xCB, 0x29, 0xC8,
  109. 0xF1, 0x2C, 0x7F, 0x11, 0x99, 0x2A, 0x18, 0xB7, 0xEF, 0x73, 0x48, 0xA6,
  110. 0xBE, 0x70, 0xA6, 0x8B, 0x97, 0x34, 0x8A, 0xB1}}};
  111. const BigNumStr Epid11ParamsObj::coeffs_str_[3] = {
  112. {{{0x02, 0x16, 0x7A, 0x61, 0x53, 0xDD, 0xF6, 0xE2, 0x89, 0x15, 0xA0, 0x94,
  113. 0xF1, 0xB5, 0xDC, 0x65, 0x21, 0x15, 0x62, 0xE1, 0x7D, 0xC5, 0x43, 0x89,
  114. 0xEE, 0xB4, 0xEF, 0xC8, 0xA0, 0x8E, 0x34, 0x0F}}},
  115. {{{0x04, 0x82, 0x27, 0xE1, 0xEB, 0x98, 0x64, 0xC2, 0x8D, 0x8F, 0xDD, 0x0E,
  116. 0x82, 0x40, 0xAE, 0xD4, 0x31, 0x63, 0xD6, 0x46, 0x32, 0x16, 0x85, 0x7A,
  117. 0xB7, 0x18, 0x68, 0xB8, 0x17, 0x02, 0x81, 0xA6}}},
  118. {{{0x06, 0x20, 0x76, 0xE8, 0x54, 0x54, 0x53, 0xB4, 0xA9, 0xD8, 0x44, 0x4B,
  119. 0xAA, 0xFB, 0x1C, 0xFD, 0xAE, 0x15, 0xCA, 0x29, 0x79, 0xA6, 0x24, 0xA4,
  120. 0x0A, 0xF6, 0x1E, 0xAC, 0xED, 0xFB, 0x10, 0x41}}}};
  121. const FqElemStr Epid11ParamsObj::qnr_str = {
  122. {0x08, 0x66, 0xA7, 0x67, 0x36, 0x6E, 0x62, 0x71, 0xB7, 0xA6, 0x52, 0x94,
  123. 0x8F, 0xFB, 0x25, 0x9E, 0xE6, 0x4F, 0x25, 0xE5, 0x26, 0x9A, 0x2B, 0x6E,
  124. 0x7E, 0xF8, 0xA6, 0x39, 0xAE, 0x46, 0xAA, 0x24}};
  125. const std::vector<uint8_t> Epid11ParamsObj::orderG2_str = {
  126. 0x00, 0x03, 0xDF, 0xFC, 0xBE, 0x2F, 0x5C, 0x2E, 0x45, 0x49, 0x7A, 0x2A,
  127. 0x91, 0xBA, 0xD1, 0x3E, 0x01, 0xEC, 0x5F, 0xC2, 0x15, 0x14, 0x10, 0xB3,
  128. 0x28, 0x5E, 0x56, 0xCC, 0x26, 0x51, 0x24, 0x93, 0x0E, 0x6C, 0x99, 0x96,
  129. 0x38, 0xE0, 0x7D, 0x68, 0x8C, 0xB7, 0x97, 0x23, 0xF4, 0xAC, 0x4D, 0xBC,
  130. 0x5E, 0x01, 0x15, 0xFF, 0x45, 0x60, 0x08, 0x13, 0xCD, 0x59, 0xD7, 0x73,
  131. 0xB0, 0x0C, 0x20, 0x5E, 0xAB, 0xAA, 0x24, 0x31, 0xE2, 0x2A, 0xA2, 0x53,
  132. 0x8A, 0xF7, 0x86, 0xD5, 0x19, 0x78, 0xC5, 0x55, 0x9C, 0x08, 0xB7, 0xE2,
  133. 0xF4, 0xD0, 0x37, 0x74, 0x93, 0x56, 0x62, 0x7B, 0x95, 0xCC, 0x2C, 0xB0};
  134. const BigNumStr Epid11ParamsObj::p1_str_ = {
  135. {{0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
  136. 0xFF, 0xFF, 0xFF, 0xFF, 0xBC, 0xE6, 0xFA, 0xAD, 0xA7, 0x17, 0x9E, 0x84,
  137. 0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x51}}};
  138. const BigNumStr Epid11ParamsObj::q1_str_ = {
  139. {{0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
  140. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
  141. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}}};
  142. const std::vector<uint8_t> Epid11ParamsObj::h1_str_ = {0x00, 0x00, 0x00, 0x01};
  143. const FqElemStr Epid11ParamsObj::a1_str_ = {
  144. {{0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
  145. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
  146. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC}}};
  147. const FqElemStr Epid11ParamsObj::b1_str_ = {
  148. {{0x5A, 0xC6, 0x35, 0xD8, 0xAA, 0x3A, 0x93, 0xE7, 0xB3, 0xEB, 0xBD, 0x55,
  149. 0x76, 0x98, 0x86, 0xBC, 0x65, 0x1D, 0x06, 0xB0, 0xCC, 0x53, 0xB0, 0xF6,
  150. 0x3B, 0xCE, 0x3C, 0x3E, 0x27, 0xD2, 0x60, 0x4B}}};
  151. const Epid11G1ElemStr Epid11ParamsObj::g1_str_ = {
  152. {{{0x07, 0x78, 0x3B, 0x0D, 0xFE, 0x4A, 0xA3, 0x19, 0x49, 0xB0, 0xCE, 0xAF,
  153. 0x3F, 0x74, 0x0F, 0x32, 0x16, 0x0C, 0x8B, 0x46, 0x94, 0x5B, 0xA5, 0xB0,
  154. 0xE4, 0x8A, 0xDA, 0xD8, 0x88, 0x32, 0x90, 0x53}}},
  155. {{{0x08, 0xF7, 0xA2, 0xAA, 0xBA, 0x62, 0xB3, 0xFE, 0x29, 0x80, 0xC9, 0x5B,
  156. 0x63, 0x53, 0xC8, 0x24, 0x3C, 0x7C, 0x1F, 0x4C, 0xDA, 0xCD, 0xE5, 0x5F,
  157. 0xA2, 0x36, 0x93, 0x04, 0x3C, 0x3A, 0xBC, 0x2E}}}};
  158. const Fq3ElemStr Epid11ParamsObj::g2x_str_ = {
  159. {{{{0x02, 0x10, 0x9A, 0xF4, 0x06, 0x32, 0x30, 0x89, 0xCB, 0x95, 0xE9, 0x55,
  160. 0x0E, 0x9D, 0xAF, 0x0E, 0x98, 0xCD, 0xCA, 0xDC, 0xB1, 0xFF, 0xFC, 0xD1,
  161. 0x45, 0x66, 0xBB, 0x86, 0x46, 0x1E, 0x8C, 0x30}}},
  162. {{{0x04, 0x78, 0x53, 0xE1, 0x3F, 0x96, 0xC5, 0xE4, 0x15, 0x23, 0x7B, 0x1F,
  163. 0x3F, 0x2C, 0xD3, 0x95, 0x40, 0xBC, 0x7A, 0x31, 0x1F, 0x14, 0x38, 0x9E,
  164. 0x1A, 0xA5, 0xD6, 0x63, 0x10, 0x91, 0xE4, 0xD3}}},
  165. {{{0x00, 0xB4, 0x02, 0xBC, 0x47, 0xFA, 0xA6, 0x29, 0x82, 0x0B, 0xB1, 0xD5,
  166. 0xFF, 0xF2, 0xE6, 0xB0, 0xC6, 0xAE, 0xE8, 0x7B, 0x91, 0xD9, 0xEE, 0x66,
  167. 0x07, 0x1F, 0xFD, 0xA2, 0xE7, 0x02, 0x66, 0xDD}}}}};
  168. const Fq3ElemStr Epid11ParamsObj::g2y_str_ = {
  169. {{{{0x05, 0x2E, 0xF8, 0xC6, 0xC1, 0x6A, 0xEF, 0x3C, 0xC1, 0x95, 0xF6, 0x26,
  170. 0xCE, 0x5E, 0x55, 0xD1, 0x64, 0x13, 0x28, 0xB1, 0x18, 0x57, 0xD8, 0x1B,
  171. 0x84, 0xFA, 0xEC, 0x7E, 0x5D, 0x99, 0x06, 0x49}}},
  172. {{{0x05, 0x73, 0x35, 0xA9, 0xA7, 0xF2, 0xA1, 0x92, 0x5F, 0x3E, 0x7C, 0xDF,
  173. 0xAC, 0xFE, 0x0F, 0xF5, 0x08, 0xD0, 0x3C, 0xAE, 0xCD, 0x58, 0x00, 0x5F,
  174. 0xD0, 0x84, 0x7E, 0xEA, 0x63, 0x57, 0xFE, 0xC6}}},
  175. {{{0x01, 0x56, 0xDA, 0xF3, 0x72, 0x61, 0xDA, 0xC6, 0x93, 0xB0, 0xAC, 0xEF,
  176. 0xAA, 0xD4, 0x51, 0x6D, 0xCA, 0x71, 0x1E, 0x06, 0x73, 0xEA, 0x83, 0xB2,
  177. 0xB1, 0x99, 0x4A, 0x4D, 0x4A, 0x0D, 0x35, 0x07}}}}};
  178. const Epid11G3ElemStr Epid11ParamsObj::g3_str_ = {
  179. {{{0x6B, 0x17, 0xD1, 0xF2, 0xE1, 0x2C, 0x42, 0x47, 0xF8, 0xBC, 0xE6, 0xE5,
  180. 0x63, 0xA4, 0x40, 0xF2, 0x77, 0x03, 0x7D, 0x81, 0x2D, 0xEB, 0x33, 0xA0,
  181. 0xF4, 0xA1, 0x39, 0x45, 0xD8, 0x98, 0xC2, 0x96}}},
  182. {{{0x4F, 0xE3, 0x42, 0xE2, 0xFE, 0x1A, 0x7F, 0x9B, 0x8E, 0xE7, 0xEB, 0x4A,
  183. 0x7C, 0x0F, 0x9E, 0x16, 0x2B, 0xCE, 0x33, 0x57, 0x6B, 0x31, 0x5E, 0xCE,
  184. 0xCB, 0xB6, 0x40, 0x68, 0x37, 0xBF, 0x51, 0xF5}}}};