pairing-test.cc 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*############################################################################
  2. # Copyright 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. /// Unit tests of pairing implementation.
  17. /*! \file */
  18. #include <gtest/gtest.h>
  19. #include "epid/member/tiny/math/unittests/cmp-testhelper.h"
  20. extern "C" {
  21. #include "epid/member/tiny/math/mathtypes.h"
  22. #include "epid/member/tiny/math/pairing.h"
  23. }
  24. namespace {
  25. ////////////////////////////////////////////////////////////////////////
  26. // PairingCompute
  27. TEST(TinyPairingTest, PairingComputeWorks) {
  28. const EccPointFq a = {{0xf67c8483, 0xbaceaf8d, 0xfcaa5567, 0x8ac94411,
  29. 0x7d91c375, 0x0fcaa603, 0x210f0997, 0xd7e2f937},
  30. {0x0f93424b, 0x88e246d6, 0x4859033f, 0x3ff08258,
  31. 0xf613c944, 0xaf6cd00a, 0x9f0d2673, 0x04b7a6ff}};
  32. const EccPointFq2 b = {{{0xa3c3fd4c, 0xad5323dc, 0x3770e217, 0x91a68d51,
  33. 0xdcfbda35, 0x6fb2b5c1, 0xbc72b09c, 0x3f4cb52d},
  34. {0xb6f87404, 0xb8fb89d1, 0xb0c1d7f9, 0x49dff54f,
  35. 0x7fb08a69, 0x5e8ef4ce, 0xcb35f350, 0x90fa4fa2}},
  36. {{0xc801fb5b, 0xfbbd005f, 0x1620b9cc, 0x444c5486,
  37. 0x083e43a1, 0x80f44b97, 0x62f3175a, 0xefc66005},
  38. {0xeb618b01, 0x448994a3, 0x3aca949c, 0xdfba9b6f,
  39. 0x35140ec9, 0xa2aa865a, 0xe20470eb, 0xc16e2b46}}};
  40. const Fq12Elem expected = {
  41. {{{0x50ab7bc6, 0xd28d33ca, 0xa7de4ce1, 0x162996ed, 0xad5ee231, 0x4fc0a501,
  42. 0x468be932, 0xba101ff6},
  43. {0x14d36207, 0x34c44c84, 0xdfa22b9e, 0x1f4d1fc0, 0xcb0454f2, 0xc4077c42,
  44. 0xebde30b6, 0x15eb79f4}},
  45. {{0xf91d7519, 0xc456caad, 0xb908d0d3, 0x31b0be8c, 0x1c0def81, 0x80e14649,
  46. 0x4657b6e7, 0xf18b84d1},
  47. {0xec73b557, 0xf8acbc05, 0x2e5f0a7e, 0xf485e0eb, 0x6fd516b6, 0xb7190100,
  48. 0xc1fa4e50, 0x3fee7c43}},
  49. {{0xb3ebe0e5, 0xc572866a, 0xa10be392, 0x2d6f653d, 0x138bb1b6, 0x87cf70ba,
  50. 0xbbef8650, 0xe3b31829},
  51. {0x4ba31303, 0x8d1afe6e, 0xe7138780, 0x36a08173, 0xcdc3182a, 0x1ecb0486,
  52. 0xd5a961a5, 0xda0e5787}}},
  53. {{{0x0b13b454, 0xa62f5fbf, 0xa4bed641, 0xd3632805, 0xe8010941, 0x72cebb51,
  54. 0x8aaa0095, 0x669e804d},
  55. {0xe49b7149, 0x8fc69d31, 0x956d88ab, 0x265c926b, 0x3bb2f1d4, 0xbfc206ea,
  56. 0x6f29d6da, 0x5b5065dc}},
  57. {{0x0ff0848e, 0x1f3fdf5c, 0xb3533098, 0x1a434003, 0xc80d2a60, 0x4ac6aa4a,
  58. 0xc99fbca8, 0xe0ce978f},
  59. {0x3357d172, 0xf5f8a018, 0x5908b3da, 0xe540395c, 0xb654a226, 0x89cef58e,
  60. 0x47786d9f, 0x5a5d41d2}},
  61. {{0x788a3989, 0x49a5f719, 0x5a0042e3, 0x92f94303, 0x1bd0e6c8, 0x81c5ac15,
  62. 0xe8a05ec8, 0xbbba6ced},
  63. {0x6d17dc8e, 0xaf351b75, 0xba6e2c36, 0x2a04ea26, 0x421e1737, 0x16fd0bfe,
  64. 0x4bb33376, 0x32aebf4d}}}};
  65. PairingState ps;
  66. PairingInit(&ps);
  67. Fq12Elem res = {0};
  68. PairingCompute(&res, &a, &b, &ps);
  69. EXPECT_EQ(expected, res);
  70. }
  71. } // namespace