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