• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 2019 The Android Open Source Project
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 #include <gtest/gtest.h>
20 
21 #include "security/ecc/p_256_ecc_pp.h"
22 
23 namespace bluetooth {
24 namespace security {
25 namespace ecc {
26 
27 // Test ECC point validation
TEST(SmpEccValidationTest,test_valid_points)28 TEST(SmpEccValidationTest, test_valid_points) {
29   Point p;
30 
31   // Test data from Bluetooth Core Specification
32   // Version 5.0 | Vol 2, Part G | 7.1.2
33 
34   // Sample 1
35   p.x[7] = 0x20b003d2;
36   p.x[6] = 0xf297be2c;
37   p.x[5] = 0x5e2c83a7;
38   p.x[4] = 0xe9f9a5b9;
39   p.x[3] = 0xeff49111;
40   p.x[2] = 0xacf4fddb;
41   p.x[1] = 0xcc030148;
42   p.x[0] = 0x0e359de6;
43 
44   p.y[7] = 0xdc809c49;
45   p.y[6] = 0x652aeb6d;
46   p.y[5] = 0x63329abf;
47   p.y[4] = 0x5a52155c;
48   p.y[3] = 0x766345c2;
49   p.y[2] = 0x8fed3024;
50   p.y[1] = 0x741c8ed0;
51   p.y[0] = 0x1589d28b;
52 
53   EXPECT_TRUE(ECC_ValidatePoint(p));
54 
55   // Sample 2
56   p.x[7] = 0x2c31a47b;
57   p.x[6] = 0x5779809e;
58   p.x[5] = 0xf44cb5ea;
59   p.x[4] = 0xaf5c3e43;
60   p.x[3] = 0xd5f8faad;
61   p.x[2] = 0x4a8794cb;
62   p.x[1] = 0x987e9b03;
63   p.x[0] = 0x745c78dd;
64 
65   p.y[7] = 0x91951218;
66   p.y[6] = 0x3898dfbe;
67   p.y[5] = 0xcd52e240;
68   p.y[4] = 0x8e43871f;
69   p.y[3] = 0xd0211091;
70   p.y[2] = 0x17bd3ed4;
71   p.y[1] = 0xeaf84377;
72   p.y[0] = 0x43715d4f;
73 
74   EXPECT_TRUE(ECC_ValidatePoint(p));
75 }
76 
TEST(SmpEccValidationTest,test_invalid_points)77 TEST(SmpEccValidationTest, test_invalid_points) {
78   Point p;
79   multiprecision_init(p.x);
80   multiprecision_init(p.y);
81 
82   EXPECT_FALSE(ECC_ValidatePoint(p));
83 
84   // Sample 1
85   p.x[7] = 0x20b003d2;
86   p.x[6] = 0xf297be2c;
87   p.x[5] = 0x5e2c83a7;
88   p.x[4] = 0xe9f9a5b9;
89   p.x[3] = 0xeff49111;
90   p.x[2] = 0xacf4fddb;
91   p.x[1] = 0xcc030148;
92   p.x[0] = 0x0e359de6;
93 
94   EXPECT_FALSE(ECC_ValidatePoint(p));
95 
96   p.y[7] = 0xdc809c49;
97   p.y[6] = 0x652aeb6d;
98   p.y[5] = 0x63329abf;
99   p.y[4] = 0x5a52155c;
100   p.y[3] = 0x766345c2;
101   p.y[2] = 0x8fed3024;
102   p.y[1] = 0x741c8ed0;
103   p.y[0] = 0x1589d28b;
104 
105   p.y[0]--;
106 
107   EXPECT_FALSE(ECC_ValidatePoint(p));
108 }
109 
110 }  // namespace ecc
111 }  // namespace security
112 }  // namespace bluetooth
113