/src/openssl/crypto/ec/ec_cvt.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved |
4 | | * |
5 | | * Licensed under the OpenSSL license (the "License"). You may not use |
6 | | * this file except in compliance with the License. You can obtain a copy |
7 | | * in the file LICENSE in the source distribution or at |
8 | | * https://www.openssl.org/source/license.html |
9 | | */ |
10 | | |
11 | | #include <openssl/err.h> |
12 | | #include "ec_lcl.h" |
13 | | |
14 | | EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, |
15 | | const BIGNUM *b, BN_CTX *ctx) |
16 | 0 | { |
17 | 0 | const EC_METHOD *meth; |
18 | 0 | EC_GROUP *ret; |
19 | 0 |
|
20 | 0 | #if defined(OPENSSL_BN_ASM_MONT) |
21 | 0 | /* |
22 | 0 | * This might appear controversial, but the fact is that generic |
23 | 0 | * prime method was observed to deliver better performance even |
24 | 0 | * for NIST primes on a range of platforms, e.g.: 60%-15% |
25 | 0 | * improvement on IA-64, ~25% on ARM, 30%-90% on P4, 20%-25% |
26 | 0 | * in 32-bit build and 35%--12% in 64-bit build on Core2... |
27 | 0 | * Coefficients are relative to optimized bn_nist.c for most |
28 | 0 | * intensive ECDSA verify and ECDH operations for 192- and 521- |
29 | 0 | * bit keys respectively. Choice of these boundary values is |
30 | 0 | * arguable, because the dependency of improvement coefficient |
31 | 0 | * from key length is not a "monotone" curve. For example while |
32 | 0 | * 571-bit result is 23% on ARM, 384-bit one is -1%. But it's |
33 | 0 | * generally faster, sometimes "respectfully" faster, sometimes |
34 | 0 | * "tolerably" slower... What effectively happens is that loop |
35 | 0 | * with bn_mul_add_words is put against bn_mul_mont, and the |
36 | 0 | * latter "wins" on short vectors. Correct solution should be |
37 | 0 | * implementing dedicated NxN multiplication subroutines for |
38 | 0 | * small N. But till it materializes, let's stick to generic |
39 | 0 | * prime method... |
40 | 0 | * <appro> |
41 | 0 | */ |
42 | 0 | meth = EC_GFp_mont_method(); |
43 | | #else |
44 | | if (BN_nist_mod_func(p)) |
45 | | meth = EC_GFp_nist_method(); |
46 | | else |
47 | | meth = EC_GFp_mont_method(); |
48 | | #endif |
49 | |
|
50 | 0 | ret = EC_GROUP_new(meth); |
51 | 0 | if (ret == NULL) |
52 | 0 | return NULL; |
53 | 0 | |
54 | 0 | if (!EC_GROUP_set_curve(ret, p, a, b, ctx)) { |
55 | 0 | EC_GROUP_clear_free(ret); |
56 | 0 | return NULL; |
57 | 0 | } |
58 | 0 | |
59 | 0 | return ret; |
60 | 0 | } |
61 | | |
62 | | #ifndef OPENSSL_NO_EC2M |
63 | | EC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a, |
64 | | const BIGNUM *b, BN_CTX *ctx) |
65 | 0 | { |
66 | 0 | const EC_METHOD *meth; |
67 | 0 | EC_GROUP *ret; |
68 | 0 |
|
69 | 0 | meth = EC_GF2m_simple_method(); |
70 | 0 |
|
71 | 0 | ret = EC_GROUP_new(meth); |
72 | 0 | if (ret == NULL) |
73 | 0 | return NULL; |
74 | 0 | |
75 | 0 | if (!EC_GROUP_set_curve(ret, p, a, b, ctx)) { |
76 | 0 | EC_GROUP_clear_free(ret); |
77 | 0 | return NULL; |
78 | 0 | } |
79 | 0 | |
80 | 0 | return ret; |
81 | 0 | } |
82 | | #endif |