Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "mpi.h" |
michael@0 | 6 | #include "mplogic.h" |
michael@0 | 7 | #include "mpprime.h" |
michael@0 | 8 | #include "ecl.h" |
michael@0 | 9 | #include "ecl-curve.h" |
michael@0 | 10 | #include "ecp.h" |
michael@0 | 11 | #include <stdio.h> |
michael@0 | 12 | #include <strings.h> |
michael@0 | 13 | #include <assert.h> |
michael@0 | 14 | |
michael@0 | 15 | #include <time.h> |
michael@0 | 16 | #include <sys/time.h> |
michael@0 | 17 | #include <sys/resource.h> |
michael@0 | 18 | |
michael@0 | 19 | /* Time k repetitions of operation op. */ |
michael@0 | 20 | #define M_TimeOperation(op, k) { \ |
michael@0 | 21 | double dStart, dNow, dUserTime; \ |
michael@0 | 22 | struct rusage ru; \ |
michael@0 | 23 | int i; \ |
michael@0 | 24 | getrusage(RUSAGE_SELF, &ru); \ |
michael@0 | 25 | dStart = (double)ru.ru_utime.tv_sec+(double)ru.ru_utime.tv_usec*0.000001; \ |
michael@0 | 26 | for (i = 0; i < k; i++) { \ |
michael@0 | 27 | { op; } \ |
michael@0 | 28 | }; \ |
michael@0 | 29 | getrusage(RUSAGE_SELF, &ru); \ |
michael@0 | 30 | dNow = (double)ru.ru_utime.tv_sec+(double)ru.ru_utime.tv_usec*0.000001; \ |
michael@0 | 31 | dUserTime = dNow-dStart; \ |
michael@0 | 32 | if (dUserTime) printf(" %-45s k: %6i, t: %6.2f sec\n", #op, k, dUserTime); \ |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | /* Test curve using generic field arithmetic. */ |
michael@0 | 36 | #define ECTEST_GENERIC_GFP(name_c, name) \ |
michael@0 | 37 | printf("Testing %s using generic implementation...\n", name_c); \ |
michael@0 | 38 | params = EC_GetNamedCurveParams(name); \ |
michael@0 | 39 | if (params == NULL) { \ |
michael@0 | 40 | printf(" Error: could not construct params.\n"); \ |
michael@0 | 41 | res = MP_NO; \ |
michael@0 | 42 | goto CLEANUP; \ |
michael@0 | 43 | } \ |
michael@0 | 44 | ECGroup_free(group); \ |
michael@0 | 45 | group = ECGroup_fromHex(params); \ |
michael@0 | 46 | if (group == NULL) { \ |
michael@0 | 47 | printf(" Error: could not construct group.\n"); \ |
michael@0 | 48 | res = MP_NO; \ |
michael@0 | 49 | goto CLEANUP; \ |
michael@0 | 50 | } \ |
michael@0 | 51 | MP_CHECKOK( ectest_curve_GFp(group, ectestPrint, ectestTime, 1) ); \ |
michael@0 | 52 | printf("... okay.\n"); |
michael@0 | 53 | |
michael@0 | 54 | /* Test curve using specific field arithmetic. */ |
michael@0 | 55 | #define ECTEST_NAMED_GFP(name_c, name) \ |
michael@0 | 56 | printf("Testing %s using specific implementation...\n", name_c); \ |
michael@0 | 57 | ECGroup_free(group); \ |
michael@0 | 58 | group = ECGroup_fromName(name); \ |
michael@0 | 59 | if (group == NULL) { \ |
michael@0 | 60 | printf(" Warning: could not construct group.\n"); \ |
michael@0 | 61 | printf("... failed; continuing with remaining tests.\n"); \ |
michael@0 | 62 | } else { \ |
michael@0 | 63 | MP_CHECKOK( ectest_curve_GFp(group, ectestPrint, ectestTime, 0) ); \ |
michael@0 | 64 | printf("... okay.\n"); \ |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | /* Performs basic tests of elliptic curve cryptography over prime fields. |
michael@0 | 68 | * If tests fail, then it prints an error message, aborts, and returns an |
michael@0 | 69 | * error code. Otherwise, returns 0. */ |
michael@0 | 70 | int |
michael@0 | 71 | ectest_curve_GFp(ECGroup *group, int ectestPrint, int ectestTime, |
michael@0 | 72 | int generic) |
michael@0 | 73 | { |
michael@0 | 74 | |
michael@0 | 75 | mp_int one, order_1, gx, gy, rx, ry, n; |
michael@0 | 76 | int size; |
michael@0 | 77 | mp_err res; |
michael@0 | 78 | char s[1000]; |
michael@0 | 79 | |
michael@0 | 80 | /* initialize values */ |
michael@0 | 81 | MP_CHECKOK(mp_init(&one)); |
michael@0 | 82 | MP_CHECKOK(mp_init(&order_1)); |
michael@0 | 83 | MP_CHECKOK(mp_init(&gx)); |
michael@0 | 84 | MP_CHECKOK(mp_init(&gy)); |
michael@0 | 85 | MP_CHECKOK(mp_init(&rx)); |
michael@0 | 86 | MP_CHECKOK(mp_init(&ry)); |
michael@0 | 87 | MP_CHECKOK(mp_init(&n)); |
michael@0 | 88 | |
michael@0 | 89 | MP_CHECKOK(mp_set_int(&one, 1)); |
michael@0 | 90 | MP_CHECKOK(mp_sub(&group->order, &one, &order_1)); |
michael@0 | 91 | |
michael@0 | 92 | /* encode base point */ |
michael@0 | 93 | if (group->meth->field_dec) { |
michael@0 | 94 | MP_CHECKOK(group->meth->field_dec(&group->genx, &gx, group->meth)); |
michael@0 | 95 | MP_CHECKOK(group->meth->field_dec(&group->geny, &gy, group->meth)); |
michael@0 | 96 | } else { |
michael@0 | 97 | MP_CHECKOK(mp_copy(&group->genx, &gx)); |
michael@0 | 98 | MP_CHECKOK(mp_copy(&group->geny, &gy)); |
michael@0 | 99 | } |
michael@0 | 100 | if (ectestPrint) { |
michael@0 | 101 | /* output base point */ |
michael@0 | 102 | printf(" base point P:\n"); |
michael@0 | 103 | MP_CHECKOK(mp_toradix(&gx, s, 16)); |
michael@0 | 104 | printf(" %s\n", s); |
michael@0 | 105 | MP_CHECKOK(mp_toradix(&gy, s, 16)); |
michael@0 | 106 | printf(" %s\n", s); |
michael@0 | 107 | if (group->meth->field_enc) { |
michael@0 | 108 | printf(" base point P (encoded):\n"); |
michael@0 | 109 | MP_CHECKOK(mp_toradix(&group->genx, s, 16)); |
michael@0 | 110 | printf(" %s\n", s); |
michael@0 | 111 | MP_CHECKOK(mp_toradix(&group->geny, s, 16)); |
michael@0 | 112 | printf(" %s\n", s); |
michael@0 | 113 | } |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | #ifdef ECL_ENABLE_GFP_PT_MUL_AFF |
michael@0 | 117 | /* multiply base point by order - 1 and check for negative of base |
michael@0 | 118 | * point */ |
michael@0 | 119 | MP_CHECKOK(ec_GFp_pt_mul_aff |
michael@0 | 120 | (&order_1, &group->genx, &group->geny, &rx, &ry, group)); |
michael@0 | 121 | if (ectestPrint) { |
michael@0 | 122 | printf(" (order-1)*P (affine):\n"); |
michael@0 | 123 | MP_CHECKOK(mp_toradix(&rx, s, 16)); |
michael@0 | 124 | printf(" %s\n", s); |
michael@0 | 125 | MP_CHECKOK(mp_toradix(&ry, s, 16)); |
michael@0 | 126 | printf(" %s\n", s); |
michael@0 | 127 | } |
michael@0 | 128 | MP_CHECKOK(group->meth->field_neg(&ry, &ry, group->meth)); |
michael@0 | 129 | if ((mp_cmp(&rx, &group->genx) != 0) |
michael@0 | 130 | || (mp_cmp(&ry, &group->geny) != 0)) { |
michael@0 | 131 | printf(" Error: invalid result (expected (- base point)).\n"); |
michael@0 | 132 | res = MP_NO; |
michael@0 | 133 | goto CLEANUP; |
michael@0 | 134 | } |
michael@0 | 135 | #endif |
michael@0 | 136 | |
michael@0 | 137 | #ifdef ECL_ENABLE_GFP_PT_MUL_AFF |
michael@0 | 138 | /* multiply base point by order - 1 and check for negative of base |
michael@0 | 139 | * point */ |
michael@0 | 140 | MP_CHECKOK(ec_GFp_pt_mul_jac |
michael@0 | 141 | (&order_1, &group->genx, &group->geny, &rx, &ry, group)); |
michael@0 | 142 | if (ectestPrint) { |
michael@0 | 143 | printf(" (order-1)*P (jacobian):\n"); |
michael@0 | 144 | MP_CHECKOK(mp_toradix(&rx, s, 16)); |
michael@0 | 145 | printf(" %s\n", s); |
michael@0 | 146 | MP_CHECKOK(mp_toradix(&ry, s, 16)); |
michael@0 | 147 | printf(" %s\n", s); |
michael@0 | 148 | } |
michael@0 | 149 | MP_CHECKOK(group->meth->field_neg(&ry, &ry, group->meth)); |
michael@0 | 150 | if ((mp_cmp(&rx, &group->genx) != 0) |
michael@0 | 151 | || (mp_cmp(&ry, &group->geny) != 0)) { |
michael@0 | 152 | printf(" Error: invalid result (expected (- base point)).\n"); |
michael@0 | 153 | res = MP_NO; |
michael@0 | 154 | goto CLEANUP; |
michael@0 | 155 | } |
michael@0 | 156 | #endif |
michael@0 | 157 | |
michael@0 | 158 | /* multiply base point by order - 1 and check for negative of base |
michael@0 | 159 | * point */ |
michael@0 | 160 | MP_CHECKOK(ECPoint_mul(group, &order_1, NULL, NULL, &rx, &ry)); |
michael@0 | 161 | if (ectestPrint) { |
michael@0 | 162 | printf(" (order-1)*P (ECPoint_mul):\n"); |
michael@0 | 163 | MP_CHECKOK(mp_toradix(&rx, s, 16)); |
michael@0 | 164 | printf(" %s\n", s); |
michael@0 | 165 | MP_CHECKOK(mp_toradix(&ry, s, 16)); |
michael@0 | 166 | printf(" %s\n", s); |
michael@0 | 167 | } |
michael@0 | 168 | MP_CHECKOK(mp_submod(&group->meth->irr, &ry, &group->meth->irr, &ry)); |
michael@0 | 169 | if ((mp_cmp(&rx, &gx) != 0) || (mp_cmp(&ry, &gy) != 0)) { |
michael@0 | 170 | printf(" Error: invalid result (expected (- base point)).\n"); |
michael@0 | 171 | res = MP_NO; |
michael@0 | 172 | goto CLEANUP; |
michael@0 | 173 | } |
michael@0 | 174 | |
michael@0 | 175 | /* multiply base point by order - 1 and check for negative of base |
michael@0 | 176 | * point */ |
michael@0 | 177 | MP_CHECKOK(ECPoint_mul(group, &order_1, &gx, &gy, &rx, &ry)); |
michael@0 | 178 | if (ectestPrint) { |
michael@0 | 179 | printf(" (order-1)*P (ECPoint_mul):\n"); |
michael@0 | 180 | MP_CHECKOK(mp_toradix(&rx, s, 16)); |
michael@0 | 181 | printf(" %s\n", s); |
michael@0 | 182 | MP_CHECKOK(mp_toradix(&ry, s, 16)); |
michael@0 | 183 | printf(" %s\n", s); |
michael@0 | 184 | } |
michael@0 | 185 | MP_CHECKOK(mp_submod(&group->meth->irr, &ry, &group->meth->irr, &ry)); |
michael@0 | 186 | if ((mp_cmp(&rx, &gx) != 0) || (mp_cmp(&ry, &gy) != 0)) { |
michael@0 | 187 | printf(" Error: invalid result (expected (- base point)).\n"); |
michael@0 | 188 | res = MP_NO; |
michael@0 | 189 | goto CLEANUP; |
michael@0 | 190 | } |
michael@0 | 191 | |
michael@0 | 192 | #ifdef ECL_ENABLE_GFP_PT_MUL_AFF |
michael@0 | 193 | /* multiply base point by order and check for point at infinity */ |
michael@0 | 194 | MP_CHECKOK(ec_GFp_pt_mul_aff |
michael@0 | 195 | (&group->order, &group->genx, &group->geny, &rx, &ry, |
michael@0 | 196 | group)); |
michael@0 | 197 | if (ectestPrint) { |
michael@0 | 198 | printf(" (order)*P (affine):\n"); |
michael@0 | 199 | MP_CHECKOK(mp_toradix(&rx, s, 16)); |
michael@0 | 200 | printf(" %s\n", s); |
michael@0 | 201 | MP_CHECKOK(mp_toradix(&ry, s, 16)); |
michael@0 | 202 | printf(" %s\n", s); |
michael@0 | 203 | } |
michael@0 | 204 | if (ec_GFp_pt_is_inf_aff(&rx, &ry) != MP_YES) { |
michael@0 | 205 | printf(" Error: invalid result (expected point at infinity).\n"); |
michael@0 | 206 | res = MP_NO; |
michael@0 | 207 | goto CLEANUP; |
michael@0 | 208 | } |
michael@0 | 209 | #endif |
michael@0 | 210 | |
michael@0 | 211 | #ifdef ECL_ENABLE_GFP_PT_MUL_JAC |
michael@0 | 212 | /* multiply base point by order and check for point at infinity */ |
michael@0 | 213 | MP_CHECKOK(ec_GFp_pt_mul_jac |
michael@0 | 214 | (&group->order, &group->genx, &group->geny, &rx, &ry, |
michael@0 | 215 | group)); |
michael@0 | 216 | if (ectestPrint) { |
michael@0 | 217 | printf(" (order)*P (jacobian):\n"); |
michael@0 | 218 | MP_CHECKOK(mp_toradix(&rx, s, 16)); |
michael@0 | 219 | printf(" %s\n", s); |
michael@0 | 220 | MP_CHECKOK(mp_toradix(&ry, s, 16)); |
michael@0 | 221 | printf(" %s\n", s); |
michael@0 | 222 | } |
michael@0 | 223 | if (ec_GFp_pt_is_inf_aff(&rx, &ry) != MP_YES) { |
michael@0 | 224 | printf(" Error: invalid result (expected point at infinity).\n"); |
michael@0 | 225 | res = MP_NO; |
michael@0 | 226 | goto CLEANUP; |
michael@0 | 227 | } |
michael@0 | 228 | #endif |
michael@0 | 229 | |
michael@0 | 230 | /* multiply base point by order and check for point at infinity */ |
michael@0 | 231 | MP_CHECKOK(ECPoint_mul(group, &group->order, NULL, NULL, &rx, &ry)); |
michael@0 | 232 | if (ectestPrint) { |
michael@0 | 233 | printf(" (order)*P (ECPoint_mul):\n"); |
michael@0 | 234 | MP_CHECKOK(mp_toradix(&rx, s, 16)); |
michael@0 | 235 | printf(" %s\n", s); |
michael@0 | 236 | MP_CHECKOK(mp_toradix(&ry, s, 16)); |
michael@0 | 237 | printf(" %s\n", s); |
michael@0 | 238 | } |
michael@0 | 239 | if (ec_GFp_pt_is_inf_aff(&rx, &ry) != MP_YES) { |
michael@0 | 240 | printf(" Error: invalid result (expected point at infinity).\n"); |
michael@0 | 241 | res = MP_NO; |
michael@0 | 242 | goto CLEANUP; |
michael@0 | 243 | } |
michael@0 | 244 | |
michael@0 | 245 | /* multiply base point by order and check for point at infinity */ |
michael@0 | 246 | MP_CHECKOK(ECPoint_mul(group, &group->order, &gx, &gy, &rx, &ry)); |
michael@0 | 247 | if (ectestPrint) { |
michael@0 | 248 | printf(" (order)*P (ECPoint_mul):\n"); |
michael@0 | 249 | MP_CHECKOK(mp_toradix(&rx, s, 16)); |
michael@0 | 250 | printf(" %s\n", s); |
michael@0 | 251 | MP_CHECKOK(mp_toradix(&ry, s, 16)); |
michael@0 | 252 | printf(" %s\n", s); |
michael@0 | 253 | } |
michael@0 | 254 | if (ec_GFp_pt_is_inf_aff(&rx, &ry) != MP_YES) { |
michael@0 | 255 | printf(" Error: invalid result (expected point at infinity).\n"); |
michael@0 | 256 | res = MP_NO; |
michael@0 | 257 | goto CLEANUP; |
michael@0 | 258 | } |
michael@0 | 259 | |
michael@0 | 260 | /* check that (order-1)P + (order-1)P + P == (order-1)P */ |
michael@0 | 261 | MP_CHECKOK(ECPoints_mul |
michael@0 | 262 | (group, &order_1, &order_1, &gx, &gy, &rx, &ry)); |
michael@0 | 263 | MP_CHECKOK(ECPoints_mul(group, &one, &one, &rx, &ry, &rx, &ry)); |
michael@0 | 264 | if (ectestPrint) { |
michael@0 | 265 | printf |
michael@0 | 266 | (" (order-1)*P + (order-1)*P + P == (order-1)*P (ECPoints_mul):\n"); |
michael@0 | 267 | MP_CHECKOK(mp_toradix(&rx, s, 16)); |
michael@0 | 268 | printf(" %s\n", s); |
michael@0 | 269 | MP_CHECKOK(mp_toradix(&ry, s, 16)); |
michael@0 | 270 | printf(" %s\n", s); |
michael@0 | 271 | } |
michael@0 | 272 | MP_CHECKOK(mp_submod(&group->meth->irr, &ry, &group->meth->irr, &ry)); |
michael@0 | 273 | if ((mp_cmp(&rx, &gx) != 0) || (mp_cmp(&ry, &gy) != 0)) { |
michael@0 | 274 | printf(" Error: invalid result (expected (- base point)).\n"); |
michael@0 | 275 | res = MP_NO; |
michael@0 | 276 | goto CLEANUP; |
michael@0 | 277 | } |
michael@0 | 278 | |
michael@0 | 279 | /* test validate_point function */ |
michael@0 | 280 | if (ECPoint_validate(group, &gx, &gy) != MP_YES) { |
michael@0 | 281 | printf(" Error: validate point on base point failed.\n"); |
michael@0 | 282 | res = MP_NO; |
michael@0 | 283 | goto CLEANUP; |
michael@0 | 284 | } |
michael@0 | 285 | MP_CHECKOK(mp_add_d(&gy, 1, &ry)); |
michael@0 | 286 | if (ECPoint_validate(group, &gx, &ry) != MP_NO) { |
michael@0 | 287 | printf(" Error: validate point on invalid point passed.\n"); |
michael@0 | 288 | res = MP_NO; |
michael@0 | 289 | goto CLEANUP; |
michael@0 | 290 | } |
michael@0 | 291 | |
michael@0 | 292 | if (ectestTime) { |
michael@0 | 293 | /* compute random scalar */ |
michael@0 | 294 | size = mpl_significant_bits(&group->meth->irr); |
michael@0 | 295 | if (size < MP_OKAY) { |
michael@0 | 296 | goto CLEANUP; |
michael@0 | 297 | } |
michael@0 | 298 | MP_CHECKOK(mpp_random_size(&n, (size + ECL_BITS - 1) / ECL_BITS)); |
michael@0 | 299 | MP_CHECKOK(group->meth->field_mod(&n, &n, group->meth)); |
michael@0 | 300 | /* timed test */ |
michael@0 | 301 | if (generic) { |
michael@0 | 302 | #ifdef ECL_ENABLE_GFP_PT_MUL_AFF |
michael@0 | 303 | M_TimeOperation(MP_CHECKOK |
michael@0 | 304 | (ec_GFp_pt_mul_aff |
michael@0 | 305 | (&n, &group->genx, &group->geny, &rx, &ry, |
michael@0 | 306 | group)), 100); |
michael@0 | 307 | #endif |
michael@0 | 308 | M_TimeOperation(MP_CHECKOK |
michael@0 | 309 | (ECPoint_mul(group, &n, NULL, NULL, &rx, &ry)), |
michael@0 | 310 | 100); |
michael@0 | 311 | M_TimeOperation(MP_CHECKOK |
michael@0 | 312 | (ECPoints_mul |
michael@0 | 313 | (group, &n, &n, &gx, &gy, &rx, &ry)), 100); |
michael@0 | 314 | } else { |
michael@0 | 315 | M_TimeOperation(MP_CHECKOK |
michael@0 | 316 | (ECPoint_mul(group, &n, NULL, NULL, &rx, &ry)), |
michael@0 | 317 | 100); |
michael@0 | 318 | M_TimeOperation(MP_CHECKOK |
michael@0 | 319 | (ECPoint_mul(group, &n, &gx, &gy, &rx, &ry)), |
michael@0 | 320 | 100); |
michael@0 | 321 | M_TimeOperation(MP_CHECKOK |
michael@0 | 322 | (ECPoints_mul |
michael@0 | 323 | (group, &n, &n, &gx, &gy, &rx, &ry)), 100); |
michael@0 | 324 | } |
michael@0 | 325 | } |
michael@0 | 326 | |
michael@0 | 327 | CLEANUP: |
michael@0 | 328 | mp_clear(&one); |
michael@0 | 329 | mp_clear(&order_1); |
michael@0 | 330 | mp_clear(&gx); |
michael@0 | 331 | mp_clear(&gy); |
michael@0 | 332 | mp_clear(&rx); |
michael@0 | 333 | mp_clear(&ry); |
michael@0 | 334 | mp_clear(&n); |
michael@0 | 335 | if (res != MP_OKAY) { |
michael@0 | 336 | printf(" Error: exiting with error value %i\n", res); |
michael@0 | 337 | } |
michael@0 | 338 | return res; |
michael@0 | 339 | } |
michael@0 | 340 | |
michael@0 | 341 | /* Prints help information. */ |
michael@0 | 342 | void |
michael@0 | 343 | printUsage() |
michael@0 | 344 | { |
michael@0 | 345 | printf("Usage: ecp_test [--print] [--time]\n"); |
michael@0 | 346 | printf |
michael@0 | 347 | (" --print Print out results of each point arithmetic test.\n"); |
michael@0 | 348 | printf |
michael@0 | 349 | (" --time Benchmark point operations and print results.\n"); |
michael@0 | 350 | } |
michael@0 | 351 | |
michael@0 | 352 | /* Performs tests of elliptic curve cryptography over prime fields If |
michael@0 | 353 | * tests fail, then it prints an error message, aborts, and returns an |
michael@0 | 354 | * error code. Otherwise, returns 0. */ |
michael@0 | 355 | int |
michael@0 | 356 | main(int argv, char **argc) |
michael@0 | 357 | { |
michael@0 | 358 | |
michael@0 | 359 | int ectestTime = 0; |
michael@0 | 360 | int ectestPrint = 0; |
michael@0 | 361 | int i; |
michael@0 | 362 | ECGroup *group = NULL; |
michael@0 | 363 | ECCurveParams *params = NULL; |
michael@0 | 364 | mp_err res; |
michael@0 | 365 | |
michael@0 | 366 | /* read command-line arguments */ |
michael@0 | 367 | for (i = 1; i < argv; i++) { |
michael@0 | 368 | if ((strcasecmp(argc[i], "time") == 0) |
michael@0 | 369 | || (strcasecmp(argc[i], "-time") == 0) |
michael@0 | 370 | || (strcasecmp(argc[i], "--time") == 0)) { |
michael@0 | 371 | ectestTime = 1; |
michael@0 | 372 | } else if ((strcasecmp(argc[i], "print") == 0) |
michael@0 | 373 | || (strcasecmp(argc[i], "-print") == 0) |
michael@0 | 374 | || (strcasecmp(argc[i], "--print") == 0)) { |
michael@0 | 375 | ectestPrint = 1; |
michael@0 | 376 | } else { |
michael@0 | 377 | printUsage(); |
michael@0 | 378 | return 0; |
michael@0 | 379 | } |
michael@0 | 380 | } |
michael@0 | 381 | |
michael@0 | 382 | /* generic arithmetic tests */ |
michael@0 | 383 | ECTEST_GENERIC_GFP("SECP-160R1", ECCurve_SECG_PRIME_160R1); |
michael@0 | 384 | |
michael@0 | 385 | /* specific arithmetic tests */ |
michael@0 | 386 | ECTEST_NAMED_GFP("NIST-P192", ECCurve_NIST_P192); |
michael@0 | 387 | ECTEST_NAMED_GFP("NIST-P224", ECCurve_NIST_P224); |
michael@0 | 388 | ECTEST_NAMED_GFP("NIST-P256", ECCurve_NIST_P256); |
michael@0 | 389 | ECTEST_NAMED_GFP("NIST-P384", ECCurve_NIST_P384); |
michael@0 | 390 | ECTEST_NAMED_GFP("NIST-P521", ECCurve_NIST_P521); |
michael@0 | 391 | ECTEST_NAMED_GFP("ANSI X9.62 PRIME192v1", ECCurve_X9_62_PRIME_192V1); |
michael@0 | 392 | ECTEST_NAMED_GFP("ANSI X9.62 PRIME192v2", ECCurve_X9_62_PRIME_192V2); |
michael@0 | 393 | ECTEST_NAMED_GFP("ANSI X9.62 PRIME192v3", ECCurve_X9_62_PRIME_192V3); |
michael@0 | 394 | ECTEST_NAMED_GFP("ANSI X9.62 PRIME239v1", ECCurve_X9_62_PRIME_239V1); |
michael@0 | 395 | ECTEST_NAMED_GFP("ANSI X9.62 PRIME239v2", ECCurve_X9_62_PRIME_239V2); |
michael@0 | 396 | ECTEST_NAMED_GFP("ANSI X9.62 PRIME239v3", ECCurve_X9_62_PRIME_239V3); |
michael@0 | 397 | ECTEST_NAMED_GFP("ANSI X9.62 PRIME256v1", ECCurve_X9_62_PRIME_256V1); |
michael@0 | 398 | ECTEST_NAMED_GFP("SECP-112R1", ECCurve_SECG_PRIME_112R1); |
michael@0 | 399 | ECTEST_NAMED_GFP("SECP-112R2", ECCurve_SECG_PRIME_112R2); |
michael@0 | 400 | ECTEST_NAMED_GFP("SECP-128R1", ECCurve_SECG_PRIME_128R1); |
michael@0 | 401 | ECTEST_NAMED_GFP("SECP-128R2", ECCurve_SECG_PRIME_128R2); |
michael@0 | 402 | ECTEST_NAMED_GFP("SECP-160K1", ECCurve_SECG_PRIME_160K1); |
michael@0 | 403 | ECTEST_NAMED_GFP("SECP-160R1", ECCurve_SECG_PRIME_160R1); |
michael@0 | 404 | ECTEST_NAMED_GFP("SECP-160R2", ECCurve_SECG_PRIME_160R2); |
michael@0 | 405 | ECTEST_NAMED_GFP("SECP-192K1", ECCurve_SECG_PRIME_192K1); |
michael@0 | 406 | ECTEST_NAMED_GFP("SECP-192R1", ECCurve_SECG_PRIME_192R1); |
michael@0 | 407 | ECTEST_NAMED_GFP("SECP-224K1", ECCurve_SECG_PRIME_224K1); |
michael@0 | 408 | ECTEST_NAMED_GFP("SECP-224R1", ECCurve_SECG_PRIME_224R1); |
michael@0 | 409 | ECTEST_NAMED_GFP("SECP-256K1", ECCurve_SECG_PRIME_256K1); |
michael@0 | 410 | ECTEST_NAMED_GFP("SECP-256R1", ECCurve_SECG_PRIME_256R1); |
michael@0 | 411 | ECTEST_NAMED_GFP("SECP-384R1", ECCurve_SECG_PRIME_384R1); |
michael@0 | 412 | ECTEST_NAMED_GFP("SECP-521R1", ECCurve_SECG_PRIME_521R1); |
michael@0 | 413 | ECTEST_NAMED_GFP("WTLS-6 (112)", ECCurve_WTLS_6); |
michael@0 | 414 | ECTEST_NAMED_GFP("WTLS-7 (160)", ECCurve_WTLS_7); |
michael@0 | 415 | ECTEST_NAMED_GFP("WTLS-8 (112)", ECCurve_WTLS_8); |
michael@0 | 416 | ECTEST_NAMED_GFP("WTLS-9 (160)", ECCurve_WTLS_9); |
michael@0 | 417 | ECTEST_NAMED_GFP("WTLS-12 (224)", ECCurve_WTLS_12); |
michael@0 | 418 | |
michael@0 | 419 | CLEANUP: |
michael@0 | 420 | EC_FreeCurveParams(params); |
michael@0 | 421 | ECGroup_free(group); |
michael@0 | 422 | if (res != MP_OKAY) { |
michael@0 | 423 | printf("Error: exiting with error value %i\n", res); |
michael@0 | 424 | } |
michael@0 | 425 | return res; |
michael@0 | 426 | } |