iPXE
p256_test.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2025 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 /** @file
27  *
28  * NIST P-256 elliptic curve self-tests
29  *
30  */
31 
32 /* Forcibly enable assertions */
33 #undef NDEBUG
34 
35 #include <ipxe/p256.h>
36 #include <ipxe/test.h>
37 #include "elliptic_test.h"
38 
39 /* http://point-at-infinity.org/ecc/nisttv k=1 */
41  SCALAR ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
42  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
43  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ),
45  EXPECTED ( 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47,
46  0xf8, 0xbc, 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2,
47  0x77, 0x03, 0x7d, 0x81, 0x2d, 0xeb, 0x33, 0xa0,
48  0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
49  0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b,
50  0x8e, 0xe7, 0xeb, 0x4a, 0x7c, 0x0f, 0x9e, 0x16,
51  0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31, 0x5e, 0xce,
52  0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5 ) );
53 
54 /* http://point-at-infinity.org/ecc/nisttv k=2 */
56  SCALAR ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
57  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
59  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 ),
60  EXPECTED ( 0x7c, 0xf2, 0x7b, 0x18, 0x8d, 0x03, 0x4f, 0x7e,
61  0x8a, 0x52, 0x38, 0x03, 0x04, 0xb5, 0x1a, 0xc3,
62  0xc0, 0x89, 0x69, 0xe2, 0x77, 0xf2, 0x1b, 0x35,
63  0xa6, 0x0b, 0x48, 0xfc, 0x47, 0x66, 0x99, 0x78,
64  0x07, 0x77, 0x55, 0x10, 0xdb, 0x8e, 0xd0, 0x40,
65  0x29, 0x3d, 0x9a, 0xc6, 0x9f, 0x74, 0x30, 0xdb,
66  0xba, 0x7d, 0xad, 0xe6, 0x3c, 0xe9, 0x82, 0x29,
67  0x9e, 0x04, 0xb7, 0x9d, 0x22, 0x78, 0x73, 0xd1 ) );
68 
69 /* http://point-at-infinity.org/ecc/nisttv k=2 (as base) to k=20 */
71  BASE ( 0x7c, 0xf2, 0x7b, 0x18, 0x8d, 0x03, 0x4f, 0x7e,
72  0x8a, 0x52, 0x38, 0x03, 0x04, 0xb5, 0x1a, 0xc3,
73  0xc0, 0x89, 0x69, 0xe2, 0x77, 0xf2, 0x1b, 0x35,
74  0xa6, 0x0b, 0x48, 0xfc, 0x47, 0x66, 0x99, 0x78,
75  0x07, 0x77, 0x55, 0x10, 0xdb, 0x8e, 0xd0, 0x40,
76  0x29, 0x3d, 0x9a, 0xc6, 0x9f, 0x74, 0x30, 0xdb,
77  0xba, 0x7d, 0xad, 0xe6, 0x3c, 0xe9, 0x82, 0x29,
78  0x9e, 0x04, 0xb7, 0x9d, 0x22, 0x78, 0x73, 0xd1 ),
79  SCALAR ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
80  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
81  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
82  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a ),
83  EXPECTED ( 0x83, 0xa0, 0x1a, 0x93, 0x78, 0x39, 0x5b, 0xab,
84  0x9b, 0xcd, 0x6a, 0x0a, 0xd0, 0x3c, 0xc5, 0x6d,
85  0x56, 0xe6, 0xb1, 0x92, 0x50, 0x46, 0x5a, 0x94,
86  0xa2, 0x34, 0xdc, 0x4c, 0x6b, 0x28, 0xda, 0x9a,
87  0x76, 0xe4, 0x9b, 0x6d, 0xe2, 0xf7, 0x32, 0x34,
88  0xae, 0x6a, 0x5e, 0xb9, 0xd6, 0x12, 0xb7, 0x5c,
89  0x9f, 0x22, 0x02, 0xbb, 0x69, 0x23, 0xf5, 0x4f,
90  0xf8, 0x24, 0x0a, 0xaa, 0x86, 0xf6, 0x40, 0xb8 ) );
91 
92 /* http://point-at-infinity.org/ecc/nisttv k=112233445566778899 */
94  SCALAR ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
95  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
96  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
97  0x01, 0x8e, 0xbb, 0xb9, 0x5e, 0xed, 0x0e, 0x13 ),
98  EXPECTED ( 0x33, 0x91, 0x50, 0x84, 0x4e, 0xc1, 0x52, 0x34,
99  0x80, 0x7f, 0xe8, 0x62, 0xa8, 0x6b, 0xe7, 0x79,
100  0x77, 0xdb, 0xfb, 0x3a, 0xe3, 0xd9, 0x6f, 0x4c,
101  0x22, 0x79, 0x55, 0x13, 0xae, 0xaa, 0xb8, 0x2f,
102  0xb1, 0xc1, 0x4d, 0xdf, 0xdc, 0x8e, 0xc1, 0xb2,
103  0x58, 0x3f, 0x51, 0xe8, 0x5a, 0x5e, 0xb3, 0xa1,
104  0x55, 0x84, 0x0f, 0x20, 0x34, 0x73, 0x0e, 0x9b,
105  0x5a, 0xda, 0x38, 0xb6, 0x74, 0x33, 0x6a, 0x21 ) );
106 
107 /* http://point-at-infinity.org/ecc/nisttv k=<largest> */
109  SCALAR ( 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
110  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
111  0xbc, 0xe6, 0xfa, 0xad, 0xa7, 0x17, 0x9e, 0x84,
112  0xf3, 0xb9, 0xca, 0xc2, 0xfc, 0x63, 0x25, 0x50 ),
113  EXPECTED ( 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47,
114  0xf8, 0xbc, 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2,
115  0x77, 0x03, 0x7d, 0x81, 0x2d, 0xeb, 0x33, 0xa0,
116  0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
117  0xb0, 0x1c, 0xbd, 0x1c, 0x01, 0xe5, 0x80, 0x65,
118  0x71, 0x18, 0x14, 0xb5, 0x83, 0xf0, 0x61, 0xe9,
119  0xd4, 0x31, 0xcc, 0xa9, 0x94, 0xce, 0xa1, 0x31,
120  0x34, 0x49, 0xbf, 0x97, 0xc8, 0x40, 0xae, 0x0a ) );
121 
122 /* Point at infinity */
124  BASE ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
125  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
126  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
127  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
128  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
129  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
130  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
131  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ),
132  SCALAR ( 0x8d, 0x50, 0x48, 0x0c, 0xbe, 0x22, 0x4d, 0x01,
133  0xbc, 0xff, 0x67, 0x8d, 0xad, 0xb1, 0x87, 0x99,
134  0x47, 0xb9, 0x79, 0x02, 0xb0, 0x70, 0x47, 0xf0,
135  0x9f, 0x17, 0x25, 0x7e, 0xcf, 0x0b, 0x3e, 0x73 ),
136  EXPECTED ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
137  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
138  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
139  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
140  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
141  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
142  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
143  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ) );
144 
145 /* Invalid curve point (zero, base_y) */
146 ELLIPTIC_MULTIPLY_TEST ( invalid_zero, &p256_curve,
147  BASE ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
148  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
149  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
150  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
151  0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b,
152  0x8e, 0xe7, 0xeb, 0x4a, 0x7c, 0x0f, 0x9e, 0x16,
153  0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31, 0x5e, 0xce,
154  0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf4 ),
155  SCALAR ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
156  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
157  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
158  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ),
159  EXPECTED_FAIL );
160 
161 /* Invalid curve point (base_x, base_y - 1) */
162 ELLIPTIC_MULTIPLY_TEST ( invalid_one, &p256_curve,
163  BASE ( 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47,
164  0xf8, 0xbc, 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2,
165  0x77, 0x03, 0x7d, 0x81, 0x2d, 0xeb, 0x33, 0xa0,
166  0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
167  0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b,
168  0x8e, 0xe7, 0xeb, 0x4a, 0x7c, 0x0f, 0x9e, 0x16,
169  0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31, 0x5e, 0xce,
170  0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf4 ),
171  SCALAR ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
172  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
173  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
174  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ),
175  EXPECTED_FAIL );
176 
177 /* http://point-at-infinity.org/ecc/nisttv k=2 + k=2 => k=4 */
178 ELLIPTIC_ADD_TEST ( poi_2_2_4, &p256_curve,
179  ADDEND ( 0x7c, 0xf2, 0x7b, 0x18, 0x8d, 0x03, 0x4f, 0x7e,
180  0x8a, 0x52, 0x38, 0x03, 0x04, 0xb5, 0x1a, 0xc3,
181  0xc0, 0x89, 0x69, 0xe2, 0x77, 0xf2, 0x1b, 0x35,
182  0xa6, 0x0b, 0x48, 0xfc, 0x47, 0x66, 0x99, 0x78,
183  0x07, 0x77, 0x55, 0x10, 0xdb, 0x8e, 0xd0, 0x40,
184  0x29, 0x3d, 0x9a, 0xc6, 0x9f, 0x74, 0x30, 0xdb,
185  0xba, 0x7d, 0xad, 0xe6, 0x3c, 0xe9, 0x82, 0x29,
186  0x9e, 0x04, 0xb7, 0x9d, 0x22, 0x78, 0x73, 0xd1 ),
187  AUGEND ( 0x7c, 0xf2, 0x7b, 0x18, 0x8d, 0x03, 0x4f, 0x7e,
188  0x8a, 0x52, 0x38, 0x03, 0x04, 0xb5, 0x1a, 0xc3,
189  0xc0, 0x89, 0x69, 0xe2, 0x77, 0xf2, 0x1b, 0x35,
190  0xa6, 0x0b, 0x48, 0xfc, 0x47, 0x66, 0x99, 0x78,
191  0x07, 0x77, 0x55, 0x10, 0xdb, 0x8e, 0xd0, 0x40,
192  0x29, 0x3d, 0x9a, 0xc6, 0x9f, 0x74, 0x30, 0xdb,
193  0xba, 0x7d, 0xad, 0xe6, 0x3c, 0xe9, 0x82, 0x29,
194  0x9e, 0x04, 0xb7, 0x9d, 0x22, 0x78, 0x73, 0xd1 ),
195  EXPECTED ( 0xe2, 0x53, 0x4a, 0x35, 0x32, 0xd0, 0x8f, 0xbb,
196  0xa0, 0x2d, 0xde, 0x65, 0x9e, 0xe6, 0x2b, 0xd0,
197  0x03, 0x1f, 0xe2, 0xdb, 0x78, 0x55, 0x96, 0xef,
198  0x50, 0x93, 0x02, 0x44, 0x6b, 0x03, 0x08, 0x52,
199  0xe0, 0xf1, 0x57, 0x5a, 0x4c, 0x63, 0x3c, 0xc7,
200  0x19, 0xdf, 0xee, 0x5f, 0xda, 0x86, 0x2d, 0x76,
201  0x4e, 0xfc, 0x96, 0xc3, 0xf3, 0x0e, 0xe0, 0x05,
202  0x5c, 0x42, 0xc2, 0x3f, 0x18, 0x4e, 0xd8, 0xc6 ) );
203 
204 /* http://point-at-infinity.org/ecc/nisttv k=3 + k=5 => k=8 */
205 ELLIPTIC_ADD_TEST ( poi_3_5_8, &p256_curve,
206  ADDEND ( 0x5e, 0xcb, 0xe4, 0xd1, 0xa6, 0x33, 0x0a, 0x44,
207  0xc8, 0xf7, 0xef, 0x95, 0x1d, 0x4b, 0xf1, 0x65,
208  0xe6, 0xc6, 0xb7, 0x21, 0xef, 0xad, 0xa9, 0x85,
209  0xfb, 0x41, 0x66, 0x1b, 0xc6, 0xe7, 0xfd, 0x6c,
210  0x87, 0x34, 0x64, 0x0c, 0x49, 0x98, 0xff, 0x7e,
211  0x37, 0x4b, 0x06, 0xce, 0x1a, 0x64, 0xa2, 0xec,
212  0xd8, 0x2a, 0xb0, 0x36, 0x38, 0x4f, 0xb8, 0x3d,
213  0x9a, 0x79, 0xb1, 0x27, 0xa2, 0x7d, 0x50, 0x32 ),
214  AUGEND ( 0x51, 0x59, 0x0b, 0x7a, 0x51, 0x51, 0x40, 0xd2,
215  0xd7, 0x84, 0xc8, 0x56, 0x08, 0x66, 0x8f, 0xdf,
216  0xef, 0x8c, 0x82, 0xfd, 0x1f, 0x5b, 0xe5, 0x24,
217  0x21, 0x55, 0x4a, 0x0d, 0xc3, 0xd0, 0x33, 0xed,
218  0xe0, 0xc1, 0x7d, 0xa8, 0x90, 0x4a, 0x72, 0x7d,
219  0x8a, 0xe1, 0xbf, 0x36, 0xbf, 0x8a, 0x79, 0x26,
220  0x0d, 0x01, 0x2f, 0x00, 0xd4, 0xd8, 0x08, 0x88,
221  0xd1, 0xd0, 0xbb, 0x44, 0xfd, 0xa1, 0x6d, 0xa4 ),
222  EXPECTED ( 0x62, 0xd9, 0x77, 0x9d, 0xbe, 0xe9, 0xb0, 0x53,
223  0x40, 0x42, 0x74, 0x2d, 0x3a, 0xb5, 0x4c, 0xad,
224  0xc1, 0xd2, 0x38, 0x98, 0x0f, 0xce, 0x97, 0xdb,
225  0xb4, 0xdd, 0x9d, 0xc1, 0xdb, 0x6f, 0xb3, 0x93,
226  0xad, 0x5a, 0xcc, 0xbd, 0x91, 0xe9, 0xd8, 0x24,
227  0x4f, 0xf1, 0x5d, 0x77, 0x11, 0x67, 0xce, 0xe0,
228  0xa2, 0xed, 0x51, 0xf6, 0xbb, 0xe7, 0x6a, 0x78,
229  0xda, 0x54, 0x0a, 0x6a, 0x0f, 0x09, 0x95, 0x7e ) );
230 
231 /* http://point-at-infinity.org/ecc/nisttv k=1 + k=n-1 => infinity */
232 ELLIPTIC_ADD_TEST ( poi_1_n_1, &p256_curve,
233  ADDEND ( 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47,
234  0xf8, 0xbc, 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2,
235  0x77, 0x03, 0x7d, 0x81, 0x2d, 0xeb, 0x33, 0xa0,
236  0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
237  0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b,
238  0x8e, 0xe7, 0xeb, 0x4a, 0x7c, 0x0f, 0x9e, 0x16,
239  0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31, 0x5e, 0xce,
240  0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5 ),
241  AUGEND ( 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47,
242  0xf8, 0xbc, 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2,
243  0x77, 0x03, 0x7d, 0x81, 0x2d, 0xeb, 0x33, 0xa0,
244  0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
245  0xb0, 0x1c, 0xbd, 0x1c, 0x01, 0xe5, 0x80, 0x65,
246  0x71, 0x18, 0x14, 0xb5, 0x83, 0xf0, 0x61, 0xe9,
247  0xd4, 0x31, 0xcc, 0xa9, 0x94, 0xce, 0xa1, 0x31,
248  0x34, 0x49, 0xbf, 0x97, 0xc8, 0x40, 0xae, 0x0a ),
249  EXPECTED ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
250  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
251  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
252  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
253  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
254  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
255  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
256  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ) );
257 
258 /**
259  * Perform P-256 self-test
260  *
261  */
262 static void p256_test_exec ( void ) {
263 
264  /* Curve sanity test */
266 
267  /* Multiplication tests from http://point-at-infinity.org/ecc/nisttv */
268  elliptic_multiply_ok ( &poi_1 );
269  elliptic_multiply_ok ( &poi_2 );
270  elliptic_multiply_ok ( &poi_2_20 );
271  elliptic_multiply_ok ( &poi_mid );
272  elliptic_multiply_ok ( &poi_large );
273 
274  /* Point at infinity */
275  elliptic_multiply_ok ( &infinity );
276 
277  /* Invalid point tests */
278  elliptic_multiply_ok ( &invalid_zero );
279  elliptic_multiply_ok ( &invalid_one );
280 
281  /* Addition tests from http://point-at-infinity.org/ecc/nisttv */
282  elliptic_add_ok ( &poi_2_2_4 );
283  elliptic_add_ok ( &poi_3_5_8 );
284  elliptic_add_ok ( &poi_1_n_1 );
285 }
286 
287 /** P-256 self-test */
288 struct self_test p256_test __self_test = {
289  .name = "p256",
290  .exec = p256_test_exec,
291 };
#define elliptic_curve_ok(curve)
Report an elliptic curve sanity test result.
Self-test infrastructure.
const char * name
Test set name.
Definition: test.h:17
A self-test set.
Definition: test.h:15
#define elliptic_add_ok(test)
Report an elliptic curve point addition test result.
#define ADDEND(...)
Define inline addend point.
Definition: elliptic_test.h:56
#define BASE_GENERATOR
Define base point to be curve's generator.
Definition: elliptic_test.h:50
#define SCALAR(...)
Define inline scalar multiple.
Definition: elliptic_test.h:53
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
struct elliptic_curve p256_curve
#define AUGEND(...)
Define inline augend point.
Definition: elliptic_test.h:59
ELLIPTIC_MULTIPLY_TEST(poi_1, &p256_curve, BASE_GENERATOR, SCALAR(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01), EXPECTED(0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc, 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d, 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96, 0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b, 0x8e, 0xe7, 0xeb, 0x4a, 0x7c, 0x0f, 0x9e, 0x16, 0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31, 0x5e, 0xce, 0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5))
#define EXPECTED_FAIL
Define result as an expected failure.
Definition: elliptic_test.h:65
#define EXPECTED(...)
Define inline expected result point.
Definition: elliptic_test.h:62
NIST P-256 elliptic curve.
#define BASE
Definition: 3c595.h:69
struct self_test p256_test __self_test
P-256 self-test.
Definition: p256_test.c:288
ELLIPTIC_ADD_TEST(poi_2_2_4, &p256_curve, ADDEND(0x7c, 0xf2, 0x7b, 0x18, 0x8d, 0x03, 0x4f, 0x7e, 0x8a, 0x52, 0x38, 0x03, 0x04, 0xb5, 0x1a, 0xc3, 0xc0, 0x89, 0x69, 0xe2, 0x77, 0xf2, 0x1b, 0x35, 0xa6, 0x0b, 0x48, 0xfc, 0x47, 0x66, 0x99, 0x78, 0x07, 0x77, 0x55, 0x10, 0xdb, 0x8e, 0xd0, 0x40, 0x29, 0x3d, 0x9a, 0xc6, 0x9f, 0x74, 0x30, 0xdb, 0xba, 0x7d, 0xad, 0xe6, 0x3c, 0xe9, 0x82, 0x29, 0x9e, 0x04, 0xb7, 0x9d, 0x22, 0x78, 0x73, 0xd1), AUGEND(0x7c, 0xf2, 0x7b, 0x18, 0x8d, 0x03, 0x4f, 0x7e, 0x8a, 0x52, 0x38, 0x03, 0x04, 0xb5, 0x1a, 0xc3, 0xc0, 0x89, 0x69, 0xe2, 0x77, 0xf2, 0x1b, 0x35, 0xa6, 0x0b, 0x48, 0xfc, 0x47, 0x66, 0x99, 0x78, 0x07, 0x77, 0x55, 0x10, 0xdb, 0x8e, 0xd0, 0x40, 0x29, 0x3d, 0x9a, 0xc6, 0x9f, 0x74, 0x30, 0xdb, 0xba, 0x7d, 0xad, 0xe6, 0x3c, 0xe9, 0x82, 0x29, 0x9e, 0x04, 0xb7, 0x9d, 0x22, 0x78, 0x73, 0xd1), EXPECTED(0xe2, 0x53, 0x4a, 0x35, 0x32, 0xd0, 0x8f, 0xbb, 0xa0, 0x2d, 0xde, 0x65, 0x9e, 0xe6, 0x2b, 0xd0, 0x03, 0x1f, 0xe2, 0xdb, 0x78, 0x55, 0x96, 0xef, 0x50, 0x93, 0x02, 0x44, 0x6b, 0x03, 0x08, 0x52, 0xe0, 0xf1, 0x57, 0x5a, 0x4c, 0x63, 0x3c, 0xc7, 0x19, 0xdf, 0xee, 0x5f, 0xda, 0x86, 0x2d, 0x76, 0x4e, 0xfc, 0x96, 0xc3, 0xf3, 0x0e, 0xe0, 0x05, 0x5c, 0x42, 0xc2, 0x3f, 0x18, 0x4e, 0xd8, 0xc6))
static void p256_test_exec(void)
Perform P-256 self-test.
Definition: p256_test.c:262
#define elliptic_multiply_ok(test)
Report an elliptic curve point multiplication test result.