Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/ec/ec_lib.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* | - | ||||||||||||||||||||||||
2 | * Copyright 2001-2018 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 <string.h> | - | ||||||||||||||||||||||||
12 | - | |||||||||||||||||||||||||
13 | #include <openssl/err.h> | - | ||||||||||||||||||||||||
14 | #include <openssl/opensslv.h> | - | ||||||||||||||||||||||||
15 | - | |||||||||||||||||||||||||
16 | #include "ec_lcl.h" | - | ||||||||||||||||||||||||
17 | - | |||||||||||||||||||||||||
18 | /* functions for EC_GROUP objects */ | - | ||||||||||||||||||||||||
19 | - | |||||||||||||||||||||||||
20 | EC_GROUP *EC_GROUP_new(const EC_METHOD *meth) | - | ||||||||||||||||||||||||
21 | { | - | ||||||||||||||||||||||||
22 | EC_GROUP *ret; | - | ||||||||||||||||||||||||
23 | - | |||||||||||||||||||||||||
24 | if (meth == NULL) {
| 0-69938 | ||||||||||||||||||||||||
25 | ECerr(EC_F_EC_GROUP_NEW, EC_R_SLOT_FULL); | - | ||||||||||||||||||||||||
26 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
27 | } | - | ||||||||||||||||||||||||
28 | if (meth->group_init == 0) {
| 0-69938 | ||||||||||||||||||||||||
29 | ECerr(EC_F_EC_GROUP_NEW, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||||||||||||||||||||
30 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
31 | } | - | ||||||||||||||||||||||||
32 | - | |||||||||||||||||||||||||
33 | ret = OPENSSL_zalloc(sizeof(*ret)); | - | ||||||||||||||||||||||||
34 | if (ret == NULL) {
| 0-69938 | ||||||||||||||||||||||||
35 | ECerr(EC_F_EC_GROUP_NEW, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
36 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
37 | } | - | ||||||||||||||||||||||||
38 | - | |||||||||||||||||||||||||
39 | ret->meth = meth; | - | ||||||||||||||||||||||||
40 | if ((ret->meth->flags & EC_FLAGS_CUSTOM_CURVE) == 0) {
| 0-69938 | ||||||||||||||||||||||||
41 | ret->order = BN_new(); | - | ||||||||||||||||||||||||
42 | if (ret->order == NULL)
| 0-69938 | ||||||||||||||||||||||||
43 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
44 | ret->cofactor = BN_new(); | - | ||||||||||||||||||||||||
45 | if (ret->cofactor == NULL)
| 0-69938 | ||||||||||||||||||||||||
46 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
47 | } executed 69938 times by 2 tests: end of block Executed by:
| 69938 | ||||||||||||||||||||||||
48 | ret->asn1_flag = OPENSSL_EC_NAMED_CURVE; | - | ||||||||||||||||||||||||
49 | ret->asn1_form = POINT_CONVERSION_UNCOMPRESSED; | - | ||||||||||||||||||||||||
50 | if (!meth->group_init(ret))
| 0-69938 | ||||||||||||||||||||||||
51 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
52 | return ret; executed 69938 times by 2 tests: return ret; Executed by:
| 69938 | ||||||||||||||||||||||||
53 | - | |||||||||||||||||||||||||
54 | err: | - | ||||||||||||||||||||||||
55 | BN_free(ret->order); | - | ||||||||||||||||||||||||
56 | BN_free(ret->cofactor); | - | ||||||||||||||||||||||||
57 | OPENSSL_free(ret); | - | ||||||||||||||||||||||||
58 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
59 | } | - | ||||||||||||||||||||||||
60 | - | |||||||||||||||||||||||||
61 | void EC_pre_comp_free(EC_GROUP *group) | - | ||||||||||||||||||||||||
62 | { | - | ||||||||||||||||||||||||
63 | switch (group->pre_comp_type) { | - | ||||||||||||||||||||||||
64 | case PCT_none: executed 69933 times by 2 tests: case PCT_none: Executed by:
| 69933 | ||||||||||||||||||||||||
65 | break; executed 69933 times by 2 tests: break; Executed by:
| 69933 | ||||||||||||||||||||||||
66 | case PCT_nistz256: never executed: case PCT_nistz256: | 0 | ||||||||||||||||||||||||
67 | #ifdef ECP_NISTZ256_ASM | - | ||||||||||||||||||||||||
68 | EC_nistz256_pre_comp_free(group->pre_comp.nistz256); | - | ||||||||||||||||||||||||
69 | #endif | - | ||||||||||||||||||||||||
70 | break; never executed: break; | 0 | ||||||||||||||||||||||||
71 | #ifndef OPENSSL_NO_EC_NISTP_64_GCC_128 | - | ||||||||||||||||||||||||
72 | case PCT_nistp224: | - | ||||||||||||||||||||||||
73 | EC_nistp224_pre_comp_free(group->pre_comp.nistp224); | - | ||||||||||||||||||||||||
74 | break; | - | ||||||||||||||||||||||||
75 | case PCT_nistp256: | - | ||||||||||||||||||||||||
76 | EC_nistp256_pre_comp_free(group->pre_comp.nistp256); | - | ||||||||||||||||||||||||
77 | break; | - | ||||||||||||||||||||||||
78 | case PCT_nistp521: | - | ||||||||||||||||||||||||
79 | EC_nistp521_pre_comp_free(group->pre_comp.nistp521); | - | ||||||||||||||||||||||||
80 | break; | - | ||||||||||||||||||||||||
81 | #else | - | ||||||||||||||||||||||||
82 | case PCT_nistp224: never executed: case PCT_nistp224: | 0 | ||||||||||||||||||||||||
83 | case PCT_nistp256: never executed: case PCT_nistp256: | 0 | ||||||||||||||||||||||||
84 | case PCT_nistp521: never executed: case PCT_nistp521: | 0 | ||||||||||||||||||||||||
85 | break; never executed: break; | 0 | ||||||||||||||||||||||||
86 | #endif | - | ||||||||||||||||||||||||
87 | case PCT_ec: executed 51 times by 1 test: case PCT_ec: Executed by:
| 51 | ||||||||||||||||||||||||
88 | EC_ec_pre_comp_free(group->pre_comp.ec); | - | ||||||||||||||||||||||||
89 | break; executed 51 times by 1 test: break; Executed by:
| 51 | ||||||||||||||||||||||||
90 | } | - | ||||||||||||||||||||||||
91 | group->pre_comp.ec = NULL; | - | ||||||||||||||||||||||||
92 | } executed 69984 times by 2 tests: end of block Executed by:
| 69984 | ||||||||||||||||||||||||
93 | - | |||||||||||||||||||||||||
94 | void EC_GROUP_free(EC_GROUP *group) | - | ||||||||||||||||||||||||
95 | { | - | ||||||||||||||||||||||||
96 | if (!group)
| 44578-69232 | ||||||||||||||||||||||||
97 | return; executed 44578 times by 2 tests: return; Executed by:
| 44578 | ||||||||||||||||||||||||
98 | - | |||||||||||||||||||||||||
99 | if (group->meth->group_finish != 0)
| 0-69232 | ||||||||||||||||||||||||
100 | group->meth->group_finish(group); executed 69232 times by 2 tests: group->meth->group_finish(group); Executed by:
| 69232 | ||||||||||||||||||||||||
101 | - | |||||||||||||||||||||||||
102 | EC_pre_comp_free(group); | - | ||||||||||||||||||||||||
103 | BN_MONT_CTX_free(group->mont_data); | - | ||||||||||||||||||||||||
104 | EC_POINT_free(group->generator); | - | ||||||||||||||||||||||||
105 | BN_free(group->order); | - | ||||||||||||||||||||||||
106 | BN_free(group->cofactor); | - | ||||||||||||||||||||||||
107 | OPENSSL_free(group->seed); | - | ||||||||||||||||||||||||
108 | OPENSSL_free(group); | - | ||||||||||||||||||||||||
109 | } executed 69232 times by 2 tests: end of block Executed by:
| 69232 | ||||||||||||||||||||||||
110 | - | |||||||||||||||||||||||||
111 | void EC_GROUP_clear_free(EC_GROUP *group) | - | ||||||||||||||||||||||||
112 | { | - | ||||||||||||||||||||||||
113 | if (!group)
| 706-2751 | ||||||||||||||||||||||||
114 | return; executed 2751 times by 1 test: return; Executed by:
| 2751 | ||||||||||||||||||||||||
115 | - | |||||||||||||||||||||||||
116 | if (group->meth->group_clear_finish != 0)
| 0-706 | ||||||||||||||||||||||||
117 | group->meth->group_clear_finish(group); executed 706 times by 1 test: group->meth->group_clear_finish(group); Executed by:
| 706 | ||||||||||||||||||||||||
118 | else if (group->meth->group_finish != 0)
| 0 | ||||||||||||||||||||||||
119 | group->meth->group_finish(group); never executed: group->meth->group_finish(group); | 0 | ||||||||||||||||||||||||
120 | - | |||||||||||||||||||||||||
121 | EC_pre_comp_free(group); | - | ||||||||||||||||||||||||
122 | BN_MONT_CTX_free(group->mont_data); | - | ||||||||||||||||||||||||
123 | EC_POINT_clear_free(group->generator); | - | ||||||||||||||||||||||||
124 | BN_clear_free(group->order); | - | ||||||||||||||||||||||||
125 | BN_clear_free(group->cofactor); | - | ||||||||||||||||||||||||
126 | OPENSSL_clear_free(group->seed, group->seed_len); | - | ||||||||||||||||||||||||
127 | OPENSSL_clear_free(group, sizeof(*group)); | - | ||||||||||||||||||||||||
128 | } executed 706 times by 1 test: end of block Executed by:
| 706 | ||||||||||||||||||||||||
129 | - | |||||||||||||||||||||||||
130 | int EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src) | - | ||||||||||||||||||||||||
131 | { | - | ||||||||||||||||||||||||
132 | if (dest->meth->group_copy == 0) {
| 0-33939 | ||||||||||||||||||||||||
133 | ECerr(EC_F_EC_GROUP_COPY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||||||||||||||||||||
134 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
135 | } | - | ||||||||||||||||||||||||
136 | if (dest->meth != src->meth) {
| 0-33939 | ||||||||||||||||||||||||
137 | ECerr(EC_F_EC_GROUP_COPY, EC_R_INCOMPATIBLE_OBJECTS); | - | ||||||||||||||||||||||||
138 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
139 | } | - | ||||||||||||||||||||||||
140 | if (dest == src)
| 0-33939 | ||||||||||||||||||||||||
141 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||
142 | - | |||||||||||||||||||||||||
143 | dest->curve_name = src->curve_name; | - | ||||||||||||||||||||||||
144 | - | |||||||||||||||||||||||||
145 | /* Copy precomputed */ | - | ||||||||||||||||||||||||
146 | dest->pre_comp_type = src->pre_comp_type; | - | ||||||||||||||||||||||||
147 | switch (src->pre_comp_type) { | - | ||||||||||||||||||||||||
148 | case PCT_none: executed 33933 times by 2 tests: case PCT_none: Executed by:
| 33933 | ||||||||||||||||||||||||
149 | dest->pre_comp.ec = NULL; | - | ||||||||||||||||||||||||
150 | break; executed 33933 times by 2 tests: break; Executed by:
| 33933 | ||||||||||||||||||||||||
151 | case PCT_nistz256: never executed: case PCT_nistz256: | 0 | ||||||||||||||||||||||||
152 | #ifdef ECP_NISTZ256_ASM | - | ||||||||||||||||||||||||
153 | dest->pre_comp.nistz256 = EC_nistz256_pre_comp_dup(src->pre_comp.nistz256); | - | ||||||||||||||||||||||||
154 | #endif | - | ||||||||||||||||||||||||
155 | break; never executed: break; | 0 | ||||||||||||||||||||||||
156 | #ifndef OPENSSL_NO_EC_NISTP_64_GCC_128 | - | ||||||||||||||||||||||||
157 | case PCT_nistp224: | - | ||||||||||||||||||||||||
158 | dest->pre_comp.nistp224 = EC_nistp224_pre_comp_dup(src->pre_comp.nistp224); | - | ||||||||||||||||||||||||
159 | break; | - | ||||||||||||||||||||||||
160 | case PCT_nistp256: | - | ||||||||||||||||||||||||
161 | dest->pre_comp.nistp256 = EC_nistp256_pre_comp_dup(src->pre_comp.nistp256); | - | ||||||||||||||||||||||||
162 | break; | - | ||||||||||||||||||||||||
163 | case PCT_nistp521: | - | ||||||||||||||||||||||||
164 | dest->pre_comp.nistp521 = EC_nistp521_pre_comp_dup(src->pre_comp.nistp521); | - | ||||||||||||||||||||||||
165 | break; | - | ||||||||||||||||||||||||
166 | #else | - | ||||||||||||||||||||||||
167 | case PCT_nistp224: never executed: case PCT_nistp224: | 0 | ||||||||||||||||||||||||
168 | case PCT_nistp256: never executed: case PCT_nistp256: | 0 | ||||||||||||||||||||||||
169 | case PCT_nistp521: never executed: case PCT_nistp521: | 0 | ||||||||||||||||||||||||
170 | break; never executed: break; | 0 | ||||||||||||||||||||||||
171 | #endif | - | ||||||||||||||||||||||||
172 | case PCT_ec: executed 6 times by 1 test: case PCT_ec: Executed by:
| 6 | ||||||||||||||||||||||||
173 | dest->pre_comp.ec = EC_ec_pre_comp_dup(src->pre_comp.ec); | - | ||||||||||||||||||||||||
174 | break; executed 6 times by 1 test: break; Executed by:
| 6 | ||||||||||||||||||||||||
175 | } | - | ||||||||||||||||||||||||
176 | - | |||||||||||||||||||||||||
177 | if (src->mont_data != NULL) {
| 3-33936 | ||||||||||||||||||||||||
178 | if (dest->mont_data == NULL) {
| 0-33936 | ||||||||||||||||||||||||
179 | dest->mont_data = BN_MONT_CTX_new(); | - | ||||||||||||||||||||||||
180 | if (dest->mont_data == NULL)
| 0-33936 | ||||||||||||||||||||||||
181 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
182 | } executed 33936 times by 2 tests: end of block Executed by:
| 33936 | ||||||||||||||||||||||||
183 | if (!BN_MONT_CTX_copy(dest->mont_data, src->mont_data))
| 0-33936 | ||||||||||||||||||||||||
184 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
185 | } else { executed 33936 times by 2 tests: end of block Executed by:
| 33936 | ||||||||||||||||||||||||
186 | /* src->generator == NULL */ | - | ||||||||||||||||||||||||
187 | BN_MONT_CTX_free(dest->mont_data); | - | ||||||||||||||||||||||||
188 | dest->mont_data = NULL; | - | ||||||||||||||||||||||||
189 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||||||||
190 | - | |||||||||||||||||||||||||
191 | if (src->generator != NULL) {
| 2-33937 | ||||||||||||||||||||||||
192 | if (dest->generator == NULL) {
| 0-33937 | ||||||||||||||||||||||||
193 | dest->generator = EC_POINT_new(dest); | - | ||||||||||||||||||||||||
194 | if (dest->generator == NULL)
| 0-33937 | ||||||||||||||||||||||||
195 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
196 | } executed 33937 times by 2 tests: end of block Executed by:
| 33937 | ||||||||||||||||||||||||
197 | if (!EC_POINT_copy(dest->generator, src->generator))
| 0-33937 | ||||||||||||||||||||||||
198 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
199 | } else { executed 33937 times by 2 tests: end of block Executed by:
| 33937 | ||||||||||||||||||||||||
200 | /* src->generator == NULL */ | - | ||||||||||||||||||||||||
201 | EC_POINT_clear_free(dest->generator); | - | ||||||||||||||||||||||||
202 | dest->generator = NULL; | - | ||||||||||||||||||||||||
203 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
204 | - | |||||||||||||||||||||||||
205 | if ((src->meth->flags & EC_FLAGS_CUSTOM_CURVE) == 0) {
| 0-33939 | ||||||||||||||||||||||||
206 | if (!BN_copy(dest->order, src->order))
| 0-33939 | ||||||||||||||||||||||||
207 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
208 | if (!BN_copy(dest->cofactor, src->cofactor))
| 0-33939 | ||||||||||||||||||||||||
209 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
210 | } executed 33939 times by 2 tests: end of block Executed by:
| 33939 | ||||||||||||||||||||||||
211 | - | |||||||||||||||||||||||||
212 | dest->asn1_flag = src->asn1_flag; | - | ||||||||||||||||||||||||
213 | dest->asn1_form = src->asn1_form; | - | ||||||||||||||||||||||||
214 | - | |||||||||||||||||||||||||
215 | if (src->seed) {
| 9604-24335 | ||||||||||||||||||||||||
216 | OPENSSL_free(dest->seed); | - | ||||||||||||||||||||||||
217 | if ((dest->seed = OPENSSL_malloc(src->seed_len)) == NULL) {
| 0-24335 | ||||||||||||||||||||||||
218 | ECerr(EC_F_EC_GROUP_COPY, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
219 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
220 | } | - | ||||||||||||||||||||||||
221 | if (!memcpy(dest->seed, src->seed, src->seed_len))
| 0-24335 | ||||||||||||||||||||||||
222 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
223 | dest->seed_len = src->seed_len; | - | ||||||||||||||||||||||||
224 | } else { executed 24335 times by 1 test: end of block Executed by:
| 24335 | ||||||||||||||||||||||||
225 | OPENSSL_free(dest->seed); | - | ||||||||||||||||||||||||
226 | dest->seed = NULL; | - | ||||||||||||||||||||||||
227 | dest->seed_len = 0; | - | ||||||||||||||||||||||||
228 | } executed 9604 times by 2 tests: end of block Executed by:
| 9604 | ||||||||||||||||||||||||
229 | - | |||||||||||||||||||||||||
230 | return dest->meth->group_copy(dest, src); executed 33939 times by 2 tests: return dest->meth->group_copy(dest, src); Executed by:
| 33939 | ||||||||||||||||||||||||
231 | } | - | ||||||||||||||||||||||||
232 | - | |||||||||||||||||||||||||
233 | EC_GROUP *EC_GROUP_dup(const EC_GROUP *a) | - | ||||||||||||||||||||||||
234 | { | - | ||||||||||||||||||||||||
235 | EC_GROUP *t = NULL; | - | ||||||||||||||||||||||||
236 | int ok = 0; | - | ||||||||||||||||||||||||
237 | - | |||||||||||||||||||||||||
238 | if (a == NULL)
| 0-33500 | ||||||||||||||||||||||||
239 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
240 | - | |||||||||||||||||||||||||
241 | if ((t = EC_GROUP_new(a->meth)) == NULL)
| 0-33500 | ||||||||||||||||||||||||
242 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
243 | if (!EC_GROUP_copy(t, a))
| 0-33500 | ||||||||||||||||||||||||
244 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
245 | - | |||||||||||||||||||||||||
246 | ok = 1; | - | ||||||||||||||||||||||||
247 | - | |||||||||||||||||||||||||
248 | err: code before this statement executed 33500 times by 2 tests: err: Executed by:
| 33500 | ||||||||||||||||||||||||
249 | if (!ok) {
| 0-33500 | ||||||||||||||||||||||||
250 | EC_GROUP_free(t); | - | ||||||||||||||||||||||||
251 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
252 | } | - | ||||||||||||||||||||||||
253 | return t; executed 33500 times by 2 tests: return t; Executed by:
| 33500 | ||||||||||||||||||||||||
254 | } | - | ||||||||||||||||||||||||
255 | - | |||||||||||||||||||||||||
256 | const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group) | - | ||||||||||||||||||||||||
257 | { | - | ||||||||||||||||||||||||
258 | return group->meth; executed 12520 times by 1 test: return group->meth; Executed by:
| 12520 | ||||||||||||||||||||||||
259 | } | - | ||||||||||||||||||||||||
260 | - | |||||||||||||||||||||||||
261 | int EC_METHOD_get_field_type(const EC_METHOD *meth) | - | ||||||||||||||||||||||||
262 | { | - | ||||||||||||||||||||||||
263 | return meth->field_type; executed 12081 times by 1 test: return meth->field_type; Executed by:
| 12081 | ||||||||||||||||||||||||
264 | } | - | ||||||||||||||||||||||||
265 | - | |||||||||||||||||||||||||
266 | static int ec_precompute_mont_data(EC_GROUP *); | - | ||||||||||||||||||||||||
267 | - | |||||||||||||||||||||||||
268 | int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator, | - | ||||||||||||||||||||||||
269 | const BIGNUM *order, const BIGNUM *cofactor) | - | ||||||||||||||||||||||||
270 | { | - | ||||||||||||||||||||||||
271 | if (generator == NULL) {
| 0-35297 | ||||||||||||||||||||||||
272 | ECerr(EC_F_EC_GROUP_SET_GENERATOR, ERR_R_PASSED_NULL_PARAMETER); | - | ||||||||||||||||||||||||
273 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
274 | } | - | ||||||||||||||||||||||||
275 | - | |||||||||||||||||||||||||
276 | if (group->generator == NULL) {
| 5-35292 | ||||||||||||||||||||||||
277 | group->generator = EC_POINT_new(group); | - | ||||||||||||||||||||||||
278 | if (group->generator == NULL)
| 0-35292 | ||||||||||||||||||||||||
279 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
280 | } executed 35292 times by 2 tests: end of block Executed by:
| 35292 | ||||||||||||||||||||||||
281 | if (!EC_POINT_copy(group->generator, generator))
| 0-35297 | ||||||||||||||||||||||||
282 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
283 | - | |||||||||||||||||||||||||
284 | if (order != NULL) {
| 0-35297 | ||||||||||||||||||||||||
285 | if (!BN_copy(group->order, order))
| 0-35297 | ||||||||||||||||||||||||
286 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
287 | } else executed 35297 times by 2 tests: end of block Executed by:
| 35297 | ||||||||||||||||||||||||
288 | BN_zero(group->order); never executed: (BN_set_word((group->order),0)); | 0 | ||||||||||||||||||||||||
289 | - | |||||||||||||||||||||||||
290 | if (cofactor != NULL) {
| 40-35257 | ||||||||||||||||||||||||
291 | if (!BN_copy(group->cofactor, cofactor))
| 0-35257 | ||||||||||||||||||||||||
292 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
293 | } else executed 35257 times by 2 tests: end of block Executed by:
| 35257 | ||||||||||||||||||||||||
294 | BN_zero(group->cofactor); executed 40 times by 1 test: (BN_set_word((group->cofactor),0)); Executed by:
| 40 | ||||||||||||||||||||||||
295 | - | |||||||||||||||||||||||||
296 | /* | - | ||||||||||||||||||||||||
297 | * Some groups have an order with | - | ||||||||||||||||||||||||
298 | * factors of two, which makes the Montgomery setup fail. | - | ||||||||||||||||||||||||
299 | * |group->mont_data| will be NULL in this case. | - | ||||||||||||||||||||||||
300 | */ | - | ||||||||||||||||||||||||
301 | if (BN_is_odd(group->order)) {
| 132-35165 | ||||||||||||||||||||||||
302 | return ec_precompute_mont_data(group); executed 35165 times by 2 tests: return ec_precompute_mont_data(group); Executed by:
| 35165 | ||||||||||||||||||||||||
303 | } | - | ||||||||||||||||||||||||
304 | - | |||||||||||||||||||||||||
305 | BN_MONT_CTX_free(group->mont_data); | - | ||||||||||||||||||||||||
306 | group->mont_data = NULL; | - | ||||||||||||||||||||||||
307 | return 1; executed 132 times by 1 test: return 1; Executed by:
| 132 | ||||||||||||||||||||||||
308 | } | - | ||||||||||||||||||||||||
309 | - | |||||||||||||||||||||||||
310 | const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group) | - | ||||||||||||||||||||||||
311 | { | - | ||||||||||||||||||||||||
312 | return group->generator; executed 13407 times by 2 tests: return group->generator; Executed by:
| 13407 | ||||||||||||||||||||||||
313 | } | - | ||||||||||||||||||||||||
314 | - | |||||||||||||||||||||||||
315 | BN_MONT_CTX *EC_GROUP_get_mont_data(const EC_GROUP *group) | - | ||||||||||||||||||||||||
316 | { | - | ||||||||||||||||||||||||
317 | return group->mont_data; never executed: return group->mont_data; | 0 | ||||||||||||||||||||||||
318 | } | - | ||||||||||||||||||||||||
319 | - | |||||||||||||||||||||||||
320 | int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx) | - | ||||||||||||||||||||||||
321 | { | - | ||||||||||||||||||||||||
322 | if (group->order == NULL)
| 0-99 | ||||||||||||||||||||||||
323 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
324 | if (!BN_copy(order, group->order))
| 0-99 | ||||||||||||||||||||||||
325 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
326 | - | |||||||||||||||||||||||||
327 | return !BN_is_zero(order); executed 99 times by 1 test: return !BN_is_zero(order); Executed by:
| 99 | ||||||||||||||||||||||||
328 | } | - | ||||||||||||||||||||||||
329 | - | |||||||||||||||||||||||||
330 | const BIGNUM *EC_GROUP_get0_order(const EC_GROUP *group) | - | ||||||||||||||||||||||||
331 | { | - | ||||||||||||||||||||||||
332 | return group->order; executed 14676 times by 2 tests: return group->order; Executed by:
| 14676 | ||||||||||||||||||||||||
333 | } | - | ||||||||||||||||||||||||
334 | - | |||||||||||||||||||||||||
335 | int EC_GROUP_order_bits(const EC_GROUP *group) | - | ||||||||||||||||||||||||
336 | { | - | ||||||||||||||||||||||||
337 | return group->meth->group_order_bits(group); executed 4444 times by 1 test: return group->meth->group_order_bits(group); Executed by:
| 4444 | ||||||||||||||||||||||||
338 | } | - | ||||||||||||||||||||||||
339 | - | |||||||||||||||||||||||||
340 | int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, | - | ||||||||||||||||||||||||
341 | BN_CTX *ctx) | - | ||||||||||||||||||||||||
342 | { | - | ||||||||||||||||||||||||
343 | - | |||||||||||||||||||||||||
344 | if (group->cofactor == NULL)
| 0-421 | ||||||||||||||||||||||||
345 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
346 | if (!BN_copy(cofactor, group->cofactor))
| 0-421 | ||||||||||||||||||||||||
347 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
348 | - | |||||||||||||||||||||||||
349 | return !BN_is_zero(group->cofactor); executed 421 times by 1 test: return !BN_is_zero(group->cofactor); Executed by:
| 421 | ||||||||||||||||||||||||
350 | } | - | ||||||||||||||||||||||||
351 | - | |||||||||||||||||||||||||
352 | const BIGNUM *EC_GROUP_get0_cofactor(const EC_GROUP *group) | - | ||||||||||||||||||||||||
353 | { | - | ||||||||||||||||||||||||
354 | return group->cofactor; executed 12076 times by 1 test: return group->cofactor; Executed by:
| 12076 | ||||||||||||||||||||||||
355 | } | - | ||||||||||||||||||||||||
356 | - | |||||||||||||||||||||||||
357 | void EC_GROUP_set_curve_name(EC_GROUP *group, int nid) | - | ||||||||||||||||||||||||
358 | { | - | ||||||||||||||||||||||||
359 | group->curve_name = nid; | - | ||||||||||||||||||||||||
360 | } executed 35045 times by 1 test: end of block Executed by:
| 35045 | ||||||||||||||||||||||||
361 | - | |||||||||||||||||||||||||
362 | int EC_GROUP_get_curve_name(const EC_GROUP *group) | - | ||||||||||||||||||||||||
363 | { | - | ||||||||||||||||||||||||
364 | return group->curve_name; executed 38680 times by 1 test: return group->curve_name; Executed by:
| 38680 | ||||||||||||||||||||||||
365 | } | - | ||||||||||||||||||||||||
366 | - | |||||||||||||||||||||||||
367 | void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag) | - | ||||||||||||||||||||||||
368 | { | - | ||||||||||||||||||||||||
369 | group->asn1_flag = flag; | - | ||||||||||||||||||||||||
370 | } executed 34077 times by 1 test: end of block Executed by:
| 34077 | ||||||||||||||||||||||||
371 | - | |||||||||||||||||||||||||
372 | int EC_GROUP_get_asn1_flag(const EC_GROUP *group) | - | ||||||||||||||||||||||||
373 | { | - | ||||||||||||||||||||||||
374 | return group->asn1_flag; executed 13625 times by 1 test: return group->asn1_flag; Executed by:
| 13625 | ||||||||||||||||||||||||
375 | } | - | ||||||||||||||||||||||||
376 | - | |||||||||||||||||||||||||
377 | void EC_GROUP_set_point_conversion_form(EC_GROUP *group, | - | ||||||||||||||||||||||||
378 | point_conversion_form_t form) | - | ||||||||||||||||||||||||
379 | { | - | ||||||||||||||||||||||||
380 | group->asn1_form = form; | - | ||||||||||||||||||||||||
381 | } executed 513 times by 1 test: end of block Executed by:
| 513 | ||||||||||||||||||||||||
382 | - | |||||||||||||||||||||||||
383 | point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP | - | ||||||||||||||||||||||||
384 | *group) | - | ||||||||||||||||||||||||
385 | { | - | ||||||||||||||||||||||||
386 | return group->asn1_form; executed 92 times by 1 test: return group->asn1_form; Executed by:
| 92 | ||||||||||||||||||||||||
387 | } | - | ||||||||||||||||||||||||
388 | - | |||||||||||||||||||||||||
389 | size_t EC_GROUP_set_seed(EC_GROUP *group, const unsigned char *p, size_t len) | - | ||||||||||||||||||||||||
390 | { | - | ||||||||||||||||||||||||
391 | OPENSSL_free(group->seed); | - | ||||||||||||||||||||||||
392 | group->seed = NULL; | - | ||||||||||||||||||||||||
393 | group->seed_len = 0; | - | ||||||||||||||||||||||||
394 | - | |||||||||||||||||||||||||
395 | if (!len || !p)
| 0-25552 | ||||||||||||||||||||||||
396 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||
397 | - | |||||||||||||||||||||||||
398 | if ((group->seed = OPENSSL_malloc(len)) == NULL) {
| 0-25552 | ||||||||||||||||||||||||
399 | ECerr(EC_F_EC_GROUP_SET_SEED, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
400 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
401 | } | - | ||||||||||||||||||||||||
402 | memcpy(group->seed, p, len); | - | ||||||||||||||||||||||||
403 | group->seed_len = len; | - | ||||||||||||||||||||||||
404 | - | |||||||||||||||||||||||||
405 | return len; executed 25552 times by 1 test: return len; Executed by:
| 25552 | ||||||||||||||||||||||||
406 | } | - | ||||||||||||||||||||||||
407 | - | |||||||||||||||||||||||||
408 | unsigned char *EC_GROUP_get0_seed(const EC_GROUP *group) | - | ||||||||||||||||||||||||
409 | { | - | ||||||||||||||||||||||||
410 | return group->seed; executed 45 times by 1 test: return group->seed; Executed by:
| 45 | ||||||||||||||||||||||||
411 | } | - | ||||||||||||||||||||||||
412 | - | |||||||||||||||||||||||||
413 | size_t EC_GROUP_get_seed_len(const EC_GROUP *group) | - | ||||||||||||||||||||||||
414 | { | - | ||||||||||||||||||||||||
415 | return group->seed_len; executed 17 times by 1 test: return group->seed_len; Executed by:
| 17 | ||||||||||||||||||||||||
416 | } | - | ||||||||||||||||||||||||
417 | - | |||||||||||||||||||||||||
418 | int EC_GROUP_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, | - | ||||||||||||||||||||||||
419 | const BIGNUM *b, BN_CTX *ctx) | - | ||||||||||||||||||||||||
420 | { | - | ||||||||||||||||||||||||
421 | if (group->meth->group_set_curve == 0) {
| 0-17925 | ||||||||||||||||||||||||
422 | ECerr(EC_F_EC_GROUP_SET_CURVE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||||||||||||||||||||
423 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
424 | } | - | ||||||||||||||||||||||||
425 | return group->meth->group_set_curve(group, p, a, b, ctx); executed 17925 times by 2 tests: return group->meth->group_set_curve(group, p, a, b, ctx); Executed by:
| 17925 | ||||||||||||||||||||||||
426 | } | - | ||||||||||||||||||||||||
427 | - | |||||||||||||||||||||||||
428 | int EC_GROUP_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, | - | ||||||||||||||||||||||||
429 | BN_CTX *ctx) | - | ||||||||||||||||||||||||
430 | { | - | ||||||||||||||||||||||||
431 | if (group->meth->group_get_curve == NULL) {
| 0-158 | ||||||||||||||||||||||||
432 | ECerr(EC_F_EC_GROUP_GET_CURVE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||||||||||||||||||||
433 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
434 | } | - | ||||||||||||||||||||||||
435 | return group->meth->group_get_curve(group, p, a, b, ctx); executed 158 times by 2 tests: return group->meth->group_get_curve(group, p, a, b, ctx); Executed by:
| 158 | ||||||||||||||||||||||||
436 | } | - | ||||||||||||||||||||||||
437 | - | |||||||||||||||||||||||||
438 | #if OPENSSL_API_COMPAT < 0x10200000L | - | ||||||||||||||||||||||||
439 | int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, | - | ||||||||||||||||||||||||
440 | const BIGNUM *b, BN_CTX *ctx) | - | ||||||||||||||||||||||||
441 | { | - | ||||||||||||||||||||||||
442 | return EC_GROUP_set_curve(group, p, a, b, ctx); never executed: return EC_GROUP_set_curve(group, p, a, b, ctx); | 0 | ||||||||||||||||||||||||
443 | } | - | ||||||||||||||||||||||||
444 | - | |||||||||||||||||||||||||
445 | int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, | - | ||||||||||||||||||||||||
446 | BIGNUM *b, BN_CTX *ctx) | - | ||||||||||||||||||||||||
447 | { | - | ||||||||||||||||||||||||
448 | return EC_GROUP_get_curve(group, p, a, b, ctx); never executed: return EC_GROUP_get_curve(group, p, a, b, ctx); | 0 | ||||||||||||||||||||||||
449 | } | - | ||||||||||||||||||||||||
450 | - | |||||||||||||||||||||||||
451 | # ifndef OPENSSL_NO_EC2M | - | ||||||||||||||||||||||||
452 | int EC_GROUP_set_curve_GF2m(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, | - | ||||||||||||||||||||||||
453 | const BIGNUM *b, BN_CTX *ctx) | - | ||||||||||||||||||||||||
454 | { | - | ||||||||||||||||||||||||
455 | return EC_GROUP_set_curve(group, p, a, b, ctx); never executed: return EC_GROUP_set_curve(group, p, a, b, ctx); | 0 | ||||||||||||||||||||||||
456 | } | - | ||||||||||||||||||||||||
457 | - | |||||||||||||||||||||||||
458 | int EC_GROUP_get_curve_GF2m(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, | - | ||||||||||||||||||||||||
459 | BIGNUM *b, BN_CTX *ctx) | - | ||||||||||||||||||||||||
460 | { | - | ||||||||||||||||||||||||
461 | return EC_GROUP_get_curve(group, p, a, b, ctx); never executed: return EC_GROUP_get_curve(group, p, a, b, ctx); | 0 | ||||||||||||||||||||||||
462 | } | - | ||||||||||||||||||||||||
463 | # endif | - | ||||||||||||||||||||||||
464 | #endif | - | ||||||||||||||||||||||||
465 | - | |||||||||||||||||||||||||
466 | int EC_GROUP_get_degree(const EC_GROUP *group) | - | ||||||||||||||||||||||||
467 | { | - | ||||||||||||||||||||||||
468 | if (group->meth->group_get_degree == 0) {
| 0-10931 | ||||||||||||||||||||||||
469 | ECerr(EC_F_EC_GROUP_GET_DEGREE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||||||||||||||||||||
470 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
471 | } | - | ||||||||||||||||||||||||
472 | return group->meth->group_get_degree(group); executed 10931 times by 1 test: return group->meth->group_get_degree(group); Executed by:
| 10931 | ||||||||||||||||||||||||
473 | } | - | ||||||||||||||||||||||||
474 | - | |||||||||||||||||||||||||
475 | int EC_GROUP_check_discriminant(const EC_GROUP *group, BN_CTX *ctx) | - | ||||||||||||||||||||||||
476 | { | - | ||||||||||||||||||||||||
477 | if (group->meth->group_check_discriminant == 0) {
| 0-216 | ||||||||||||||||||||||||
478 | ECerr(EC_F_EC_GROUP_CHECK_DISCRIMINANT, | - | ||||||||||||||||||||||||
479 | ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||||||||||||||||||||
480 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
481 | } | - | ||||||||||||||||||||||||
482 | return group->meth->group_check_discriminant(group, ctx); executed 216 times by 1 test: return group->meth->group_check_discriminant(group, ctx); Executed by:
| 216 | ||||||||||||||||||||||||
483 | } | - | ||||||||||||||||||||||||
484 | - | |||||||||||||||||||||||||
485 | int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx) | - | ||||||||||||||||||||||||
486 | { | - | ||||||||||||||||||||||||
487 | int r = 0; | - | ||||||||||||||||||||||||
488 | BIGNUM *a1, *a2, *a3, *b1, *b2, *b3; | - | ||||||||||||||||||||||||
489 | BN_CTX *ctx_new = NULL; | - | ||||||||||||||||||||||||
490 | - | |||||||||||||||||||||||||
491 | /* compare the field types */ | - | ||||||||||||||||||||||||
492 | if (EC_METHOD_get_field_type(EC_GROUP_method_of(a)) !=
| 0-5992 | ||||||||||||||||||||||||
493 | EC_METHOD_get_field_type(EC_GROUP_method_of(b)))
| 0-5992 | ||||||||||||||||||||||||
494 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||
495 | /* compare the curve name (if present in both) */ | - | ||||||||||||||||||||||||
496 | if (EC_GROUP_get_curve_name(a) && EC_GROUP_get_curve_name(b) &&
| 0-5992 | ||||||||||||||||||||||||
497 | EC_GROUP_get_curve_name(a) != EC_GROUP_get_curve_name(b))
| 0-5991 | ||||||||||||||||||||||||
498 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||
499 | if (a->meth->flags & EC_FLAGS_CUSTOM_CURVE)
| 0-5992 | ||||||||||||||||||||||||
500 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
501 | - | |||||||||||||||||||||||||
502 | if (ctx == NULL)
| 0-5992 | ||||||||||||||||||||||||
503 | ctx_new = ctx = BN_CTX_new(); executed 5992 times by 1 test: ctx_new = ctx = BN_CTX_new(); Executed by:
| 5992 | ||||||||||||||||||||||||
504 | if (ctx == NULL)
| 0-5992 | ||||||||||||||||||||||||
505 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
506 | - | |||||||||||||||||||||||||
507 | BN_CTX_start(ctx); | - | ||||||||||||||||||||||||
508 | a1 = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||
509 | a2 = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||
510 | a3 = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||
511 | b1 = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||
512 | b2 = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||
513 | b3 = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||
514 | if (b3 == NULL) {
| 0-5992 | ||||||||||||||||||||||||
515 | BN_CTX_end(ctx); | - | ||||||||||||||||||||||||
516 | BN_CTX_free(ctx_new); | - | ||||||||||||||||||||||||
517 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
518 | } | - | ||||||||||||||||||||||||
519 | - | |||||||||||||||||||||||||
520 | /* | - | ||||||||||||||||||||||||
521 | * XXX This approach assumes that the external representation of curves | - | ||||||||||||||||||||||||
522 | * over the same field type is the same. | - | ||||||||||||||||||||||||
523 | */ | - | ||||||||||||||||||||||||
524 | if (!a->meth->group_get_curve(a, a1, a2, a3, ctx) ||
| 0-5992 | ||||||||||||||||||||||||
525 | !b->meth->group_get_curve(b, b1, b2, b3, ctx))
| 0-5992 | ||||||||||||||||||||||||
526 | r = 1; never executed: r = 1; | 0 | ||||||||||||||||||||||||
527 | - | |||||||||||||||||||||||||
528 | if (r || BN_cmp(a1, b1) || BN_cmp(a2, b2) || BN_cmp(a3, b3))
| 0-5992 | ||||||||||||||||||||||||
529 | r = 1; never executed: r = 1; | 0 | ||||||||||||||||||||||||
530 | - | |||||||||||||||||||||||||
531 | /* XXX EC_POINT_cmp() assumes that the methods are equal */ | - | ||||||||||||||||||||||||
532 | if (r || EC_POINT_cmp(a, EC_GROUP_get0_generator(a),
| 0-5992 | ||||||||||||||||||||||||
533 | EC_GROUP_get0_generator(b), ctx))
| 0-5992 | ||||||||||||||||||||||||
534 | r = 1; never executed: r = 1; | 0 | ||||||||||||||||||||||||
535 | - | |||||||||||||||||||||||||
536 | if (!r) {
| 0-5992 | ||||||||||||||||||||||||
537 | const BIGNUM *ao, *bo, *ac, *bc; | - | ||||||||||||||||||||||||
538 | /* compare the order and cofactor */ | - | ||||||||||||||||||||||||
539 | ao = EC_GROUP_get0_order(a); | - | ||||||||||||||||||||||||
540 | bo = EC_GROUP_get0_order(b); | - | ||||||||||||||||||||||||
541 | ac = EC_GROUP_get0_cofactor(a); | - | ||||||||||||||||||||||||
542 | bc = EC_GROUP_get0_cofactor(b); | - | ||||||||||||||||||||||||
543 | if (ao == NULL || bo == NULL) {
| 0-5992 | ||||||||||||||||||||||||
544 | BN_CTX_end(ctx); | - | ||||||||||||||||||||||||
545 | BN_CTX_free(ctx_new); | - | ||||||||||||||||||||||||
546 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
547 | } | - | ||||||||||||||||||||||||
548 | if (BN_cmp(ao, bo) || BN_cmp(ac, bc))
| 0-5992 | ||||||||||||||||||||||||
549 | r = 1; never executed: r = 1; | 0 | ||||||||||||||||||||||||
550 | } executed 5992 times by 1 test: end of block Executed by:
| 5992 | ||||||||||||||||||||||||
551 | - | |||||||||||||||||||||||||
552 | BN_CTX_end(ctx); | - | ||||||||||||||||||||||||
553 | BN_CTX_free(ctx_new); | - | ||||||||||||||||||||||||
554 | - | |||||||||||||||||||||||||
555 | return r; executed 5992 times by 1 test: return r; Executed by:
| 5992 | ||||||||||||||||||||||||
556 | } | - | ||||||||||||||||||||||||
557 | - | |||||||||||||||||||||||||
558 | /* functions for EC_POINT objects */ | - | ||||||||||||||||||||||||
559 | - | |||||||||||||||||||||||||
560 | EC_POINT *EC_POINT_new(const EC_GROUP *group) | - | ||||||||||||||||||||||||
561 | { | - | ||||||||||||||||||||||||
562 | EC_POINT *ret; | - | ||||||||||||||||||||||||
563 | - | |||||||||||||||||||||||||
564 | if (group == NULL) {
| 0-175336 | ||||||||||||||||||||||||
565 | ECerr(EC_F_EC_POINT_NEW, ERR_R_PASSED_NULL_PARAMETER); | - | ||||||||||||||||||||||||
566 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
567 | } | - | ||||||||||||||||||||||||
568 | if (group->meth->point_init == NULL) {
| 0-175336 | ||||||||||||||||||||||||
569 | ECerr(EC_F_EC_POINT_NEW, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||||||||||||||||||||
570 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
571 | } | - | ||||||||||||||||||||||||
572 | - | |||||||||||||||||||||||||
573 | ret = OPENSSL_zalloc(sizeof(*ret)); | - | ||||||||||||||||||||||||
574 | if (ret == NULL) {
| 0-175336 | ||||||||||||||||||||||||
575 | ECerr(EC_F_EC_POINT_NEW, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
576 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
577 | } | - | ||||||||||||||||||||||||
578 | - | |||||||||||||||||||||||||
579 | ret->meth = group->meth; | - | ||||||||||||||||||||||||
580 | ret->curve_name = group->curve_name; | - | ||||||||||||||||||||||||
581 | - | |||||||||||||||||||||||||
582 | if (!ret->meth->point_init(ret)) {
| 0-175336 | ||||||||||||||||||||||||
583 | OPENSSL_free(ret); | - | ||||||||||||||||||||||||
584 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
585 | } | - | ||||||||||||||||||||||||
586 | - | |||||||||||||||||||||||||
587 | return ret; executed 175336 times by 2 tests: return ret; Executed by:
| 175336 | ||||||||||||||||||||||||
588 | } | - | ||||||||||||||||||||||||
589 | - | |||||||||||||||||||||||||
590 | void EC_POINT_free(EC_POINT *point) | - | ||||||||||||||||||||||||
591 | { | - | ||||||||||||||||||||||||
592 | if (!point)
| 6352-163636 | ||||||||||||||||||||||||
593 | return; executed 6352 times by 2 tests: return; Executed by:
| 6352 | ||||||||||||||||||||||||
594 | - | |||||||||||||||||||||||||
595 | if (point->meth->point_finish != 0)
| 0-163636 | ||||||||||||||||||||||||
596 | point->meth->point_finish(point); executed 163636 times by 2 tests: point->meth->point_finish(point); Executed by:
| 163636 | ||||||||||||||||||||||||
597 | OPENSSL_free(point); | - | ||||||||||||||||||||||||
598 | } executed 163636 times by 2 tests: end of block Executed by:
| 163636 | ||||||||||||||||||||||||
599 | - | |||||||||||||||||||||||||
600 | void EC_POINT_clear_free(EC_POINT *point) | - | ||||||||||||||||||||||||
601 | { | - | ||||||||||||||||||||||||
602 | if (!point)
| 3724-11700 | ||||||||||||||||||||||||
603 | return; executed 3724 times by 1 test: return; Executed by:
| 3724 | ||||||||||||||||||||||||
604 | - | |||||||||||||||||||||||||
605 | if (point->meth->point_clear_finish != 0)
| 0-11700 | ||||||||||||||||||||||||
606 | point->meth->point_clear_finish(point); executed 11700 times by 2 tests: point->meth->point_clear_finish(point); Executed by:
| 11700 | ||||||||||||||||||||||||
607 | else if (point->meth->point_finish != 0)
| 0 | ||||||||||||||||||||||||
608 | point->meth->point_finish(point); never executed: point->meth->point_finish(point); | 0 | ||||||||||||||||||||||||
609 | OPENSSL_clear_free(point, sizeof(*point)); | - | ||||||||||||||||||||||||
610 | } executed 11700 times by 2 tests: end of block Executed by:
| 11700 | ||||||||||||||||||||||||
611 | - | |||||||||||||||||||||||||
612 | int EC_POINT_copy(EC_POINT *dest, const EC_POINT *src) | - | ||||||||||||||||||||||||
613 | { | - | ||||||||||||||||||||||||
614 | if (dest->meth->point_copy == 0) {
| 0-124373 | ||||||||||||||||||||||||
615 | ECerr(EC_F_EC_POINT_COPY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||||||||||||||||||||
616 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
617 | } | - | ||||||||||||||||||||||||
618 | if (dest->meth != src->meth
| 0-124373 | ||||||||||||||||||||||||
619 | || (dest->curve_name != src->curve_name
| 0-124373 | ||||||||||||||||||||||||
620 | && dest->curve_name != 0
| 0 | ||||||||||||||||||||||||
621 | && src->curve_name != 0)) {
| 0 | ||||||||||||||||||||||||
622 | ECerr(EC_F_EC_POINT_COPY, EC_R_INCOMPATIBLE_OBJECTS); | - | ||||||||||||||||||||||||
623 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
624 | } | - | ||||||||||||||||||||||||
625 | if (dest == src)
| 38995-85378 | ||||||||||||||||||||||||
626 | return 1; executed 38995 times by 1 test: return 1; Executed by:
| 38995 | ||||||||||||||||||||||||
627 | return dest->meth->point_copy(dest, src); executed 85378 times by 2 tests: return dest->meth->point_copy(dest, src); Executed by:
| 85378 | ||||||||||||||||||||||||
628 | } | - | ||||||||||||||||||||||||
629 | - | |||||||||||||||||||||||||
630 | EC_POINT *EC_POINT_dup(const EC_POINT *a, const EC_GROUP *group) | - | ||||||||||||||||||||||||
631 | { | - | ||||||||||||||||||||||||
632 | EC_POINT *t; | - | ||||||||||||||||||||||||
633 | int r; | - | ||||||||||||||||||||||||
634 | - | |||||||||||||||||||||||||
635 | if (a == NULL)
| 0-3 | ||||||||||||||||||||||||
636 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
637 | - | |||||||||||||||||||||||||
638 | t = EC_POINT_new(group); | - | ||||||||||||||||||||||||
639 | if (t == NULL)
| 0-3 | ||||||||||||||||||||||||
640 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
641 | r = EC_POINT_copy(t, a); | - | ||||||||||||||||||||||||
642 | if (!r) {
| 0-3 | ||||||||||||||||||||||||
643 | EC_POINT_free(t); | - | ||||||||||||||||||||||||
644 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
645 | } | - | ||||||||||||||||||||||||
646 | return t; executed 3 times by 1 test: return t; Executed by:
| 3 | ||||||||||||||||||||||||
647 | } | - | ||||||||||||||||||||||||
648 | - | |||||||||||||||||||||||||
649 | const EC_METHOD *EC_POINT_method_of(const EC_POINT *point) | - | ||||||||||||||||||||||||
650 | { | - | ||||||||||||||||||||||||
651 | return point->meth; never executed: return point->meth; | 0 | ||||||||||||||||||||||||
652 | } | - | ||||||||||||||||||||||||
653 | - | |||||||||||||||||||||||||
654 | int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point) | - | ||||||||||||||||||||||||
655 | { | - | ||||||||||||||||||||||||
656 | if (group->meth->point_set_to_infinity == 0) {
| 0-1380 | ||||||||||||||||||||||||
657 | ECerr(EC_F_EC_POINT_SET_TO_INFINITY, | - | ||||||||||||||||||||||||
658 | ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||||||||||||||||||||
659 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
660 | } | - | ||||||||||||||||||||||||
661 | if (group->meth != point->meth) {
| 0-1380 | ||||||||||||||||||||||||
662 | ECerr(EC_F_EC_POINT_SET_TO_INFINITY, EC_R_INCOMPATIBLE_OBJECTS); | - | ||||||||||||||||||||||||
663 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
664 | } | - | ||||||||||||||||||||||||
665 | return group->meth->point_set_to_infinity(group, point); executed 1380 times by 1 test: return group->meth->point_set_to_infinity(group, point); Executed by:
| 1380 | ||||||||||||||||||||||||
666 | } | - | ||||||||||||||||||||||||
667 | - | |||||||||||||||||||||||||
668 | int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *group, | - | ||||||||||||||||||||||||
669 | EC_POINT *point, const BIGNUM *x, | - | ||||||||||||||||||||||||
670 | const BIGNUM *y, const BIGNUM *z, | - | ||||||||||||||||||||||||
671 | BN_CTX *ctx) | - | ||||||||||||||||||||||||
672 | { | - | ||||||||||||||||||||||||
673 | if (group->meth->point_set_Jprojective_coordinates_GFp == 0) {
| 0-47761 | ||||||||||||||||||||||||
674 | ECerr(EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP, | - | ||||||||||||||||||||||||
675 | ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||||||||||||||||||||
676 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
677 | } | - | ||||||||||||||||||||||||
678 | if (!ec_point_is_compat(point, group)) {
| 0-47761 | ||||||||||||||||||||||||
679 | ECerr(EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP, | - | ||||||||||||||||||||||||
680 | EC_R_INCOMPATIBLE_OBJECTS); | - | ||||||||||||||||||||||||
681 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
682 | } | - | ||||||||||||||||||||||||
683 | return group->meth->point_set_Jprojective_coordinates_GFp(group, point, x, executed 47761 times by 2 tests: return group->meth->point_set_Jprojective_coordinates_GFp(group, point, x, y, z, ctx); Executed by:
| 47761 | ||||||||||||||||||||||||
684 | y, z, ctx); executed 47761 times by 2 tests: return group->meth->point_set_Jprojective_coordinates_GFp(group, point, x, y, z, ctx); Executed by:
| 47761 | ||||||||||||||||||||||||
685 | } | - | ||||||||||||||||||||||||
686 | - | |||||||||||||||||||||||||
687 | int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group, | - | ||||||||||||||||||||||||
688 | const EC_POINT *point, BIGNUM *x, | - | ||||||||||||||||||||||||
689 | BIGNUM *y, BIGNUM *z, | - | ||||||||||||||||||||||||
690 | BN_CTX *ctx) | - | ||||||||||||||||||||||||
691 | { | - | ||||||||||||||||||||||||
692 | if (group->meth->point_get_Jprojective_coordinates_GFp == 0) {
| 0-1 | ||||||||||||||||||||||||
693 | ECerr(EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP, | - | ||||||||||||||||||||||||
694 | ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||||||||||||||||||||
695 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
696 | } | - | ||||||||||||||||||||||||
697 | if (!ec_point_is_compat(point, group)) {
| 0-1 | ||||||||||||||||||||||||
698 | ECerr(EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP, | - | ||||||||||||||||||||||||
699 | EC_R_INCOMPATIBLE_OBJECTS); | - | ||||||||||||||||||||||||
700 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
701 | } | - | ||||||||||||||||||||||||
702 | return group->meth->point_get_Jprojective_coordinates_GFp(group, point, x, executed 1 time by 1 test: return group->meth->point_get_Jprojective_coordinates_GFp(group, point, x, y, z, ctx); Executed by:
| 1 | ||||||||||||||||||||||||
703 | y, z, ctx); executed 1 time by 1 test: return group->meth->point_get_Jprojective_coordinates_GFp(group, point, x, y, z, ctx); Executed by:
| 1 | ||||||||||||||||||||||||
704 | } | - | ||||||||||||||||||||||||
705 | - | |||||||||||||||||||||||||
706 | int EC_POINT_set_affine_coordinates(const EC_GROUP *group, EC_POINT *point, | - | ||||||||||||||||||||||||
707 | const BIGNUM *x, const BIGNUM *y, | - | ||||||||||||||||||||||||
708 | BN_CTX *ctx) | - | ||||||||||||||||||||||||
709 | { | - | ||||||||||||||||||||||||
710 | if (group->meth->point_set_affine_coordinates == NULL) {
| 0-128367 | ||||||||||||||||||||||||
711 | ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES, | - | ||||||||||||||||||||||||
712 | ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||||||||||||||||||||
713 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
714 | } | - | ||||||||||||||||||||||||
715 | if (!ec_point_is_compat(point, group)) {
| 0-128367 | ||||||||||||||||||||||||
716 | ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES, EC_R_INCOMPATIBLE_OBJECTS); | - | ||||||||||||||||||||||||
717 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
718 | } | - | ||||||||||||||||||||||||
719 | if (!group->meth->point_set_affine_coordinates(group, point, x, y, ctx))
| 0-128367 | ||||||||||||||||||||||||
720 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
721 | - | |||||||||||||||||||||||||
722 | if (EC_POINT_is_on_curve(group, point, ctx) <= 0) {
| 1011-127356 | ||||||||||||||||||||||||
723 | ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES, EC_R_POINT_IS_NOT_ON_CURVE); | - | ||||||||||||||||||||||||
724 | return 0; executed 1011 times by 1 test: return 0; Executed by:
| 1011 | ||||||||||||||||||||||||
725 | } | - | ||||||||||||||||||||||||
726 | return 1; executed 127356 times by 2 tests: return 1; Executed by:
| 127356 | ||||||||||||||||||||||||
727 | } | - | ||||||||||||||||||||||||
728 | - | |||||||||||||||||||||||||
729 | #if OPENSSL_API_COMPAT < 0x10200000L | - | ||||||||||||||||||||||||
730 | int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, | - | ||||||||||||||||||||||||
731 | EC_POINT *point, const BIGNUM *x, | - | ||||||||||||||||||||||||
732 | const BIGNUM *y, BN_CTX *ctx) | - | ||||||||||||||||||||||||
733 | { | - | ||||||||||||||||||||||||
734 | return EC_POINT_set_affine_coordinates(group, point, x, y, ctx); never executed: return EC_POINT_set_affine_coordinates(group, point, x, y, ctx); | 0 | ||||||||||||||||||||||||
735 | } | - | ||||||||||||||||||||||||
736 | - | |||||||||||||||||||||||||
737 | # ifndef OPENSSL_NO_EC2M | - | ||||||||||||||||||||||||
738 | int EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *group, | - | ||||||||||||||||||||||||
739 | EC_POINT *point, const BIGNUM *x, | - | ||||||||||||||||||||||||
740 | const BIGNUM *y, BN_CTX *ctx) | - | ||||||||||||||||||||||||
741 | { | - | ||||||||||||||||||||||||
742 | return EC_POINT_set_affine_coordinates(group, point, x, y, ctx); never executed: return EC_POINT_set_affine_coordinates(group, point, x, y, ctx); | 0 | ||||||||||||||||||||||||
743 | } | - | ||||||||||||||||||||||||
744 | # endif | - | ||||||||||||||||||||||||
745 | #endif | - | ||||||||||||||||||||||||
746 | - | |||||||||||||||||||||||||
747 | int EC_POINT_get_affine_coordinates(const EC_GROUP *group, | - | ||||||||||||||||||||||||
748 | const EC_POINT *point, BIGNUM *x, BIGNUM *y, | - | ||||||||||||||||||||||||
749 | BN_CTX *ctx) | - | ||||||||||||||||||||||||
750 | { | - | ||||||||||||||||||||||||
751 | if (group->meth->point_get_affine_coordinates == NULL) {
| 0-16573 | ||||||||||||||||||||||||
752 | ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES, | - | ||||||||||||||||||||||||
753 | ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||||||||||||||||||||
754 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
755 | } | - | ||||||||||||||||||||||||
756 | if (!ec_point_is_compat(point, group)) {
| 0-16573 | ||||||||||||||||||||||||
757 | ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES, EC_R_INCOMPATIBLE_OBJECTS); | - | ||||||||||||||||||||||||
758 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
759 | } | - | ||||||||||||||||||||||||
760 | if (EC_POINT_is_at_infinity(group, point)) {
| 93-16480 | ||||||||||||||||||||||||
761 | ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES, EC_R_POINT_AT_INFINITY); | - | ||||||||||||||||||||||||
762 | return 0; executed 93 times by 1 test: return 0; Executed by:
| 93 | ||||||||||||||||||||||||
763 | } | - | ||||||||||||||||||||||||
764 | return group->meth->point_get_affine_coordinates(group, point, x, y, ctx); executed 16480 times by 2 tests: return group->meth->point_get_affine_coordinates(group, point, x, y, ctx); Executed by:
| 16480 | ||||||||||||||||||||||||
765 | } | - | ||||||||||||||||||||||||
766 | - | |||||||||||||||||||||||||
767 | #if OPENSSL_API_COMPAT < 0x10200000L | - | ||||||||||||||||||||||||
768 | int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group, | - | ||||||||||||||||||||||||
769 | const EC_POINT *point, BIGNUM *x, | - | ||||||||||||||||||||||||
770 | BIGNUM *y, BN_CTX *ctx) | - | ||||||||||||||||||||||||
771 | { | - | ||||||||||||||||||||||||
772 | return EC_POINT_get_affine_coordinates(group, point, x, y, ctx); never executed: return EC_POINT_get_affine_coordinates(group, point, x, y, ctx); | 0 | ||||||||||||||||||||||||
773 | } | - | ||||||||||||||||||||||||
774 | - | |||||||||||||||||||||||||
775 | # ifndef OPENSSL_NO_EC2M | - | ||||||||||||||||||||||||
776 | int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *group, | - | ||||||||||||||||||||||||
777 | const EC_POINT *point, BIGNUM *x, | - | ||||||||||||||||||||||||
778 | BIGNUM *y, BN_CTX *ctx) | - | ||||||||||||||||||||||||
779 | { | - | ||||||||||||||||||||||||
780 | return EC_POINT_get_affine_coordinates(group, point, x, y, ctx); never executed: return EC_POINT_get_affine_coordinates(group, point, x, y, ctx); | 0 | ||||||||||||||||||||||||
781 | } | - | ||||||||||||||||||||||||
782 | # endif | - | ||||||||||||||||||||||||
783 | #endif | - | ||||||||||||||||||||||||
784 | - | |||||||||||||||||||||||||
785 | int EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, | - | ||||||||||||||||||||||||
786 | const EC_POINT *b, BN_CTX *ctx) | - | ||||||||||||||||||||||||
787 | { | - | ||||||||||||||||||||||||
788 | if (group->meth->add == 0) {
| 0-108182 | ||||||||||||||||||||||||
789 | ECerr(EC_F_EC_POINT_ADD, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||||||||||||||||||||
790 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
791 | } | - | ||||||||||||||||||||||||
792 | if (!ec_point_is_compat(r, group) || !ec_point_is_compat(a, group)
| 0-108182 | ||||||||||||||||||||||||
793 | || !ec_point_is_compat(b, group)) {
| 0-108182 | ||||||||||||||||||||||||
794 | ECerr(EC_F_EC_POINT_ADD, EC_R_INCOMPATIBLE_OBJECTS); | - | ||||||||||||||||||||||||
795 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
796 | } | - | ||||||||||||||||||||||||
797 | return group->meth->add(group, r, a, b, ctx); executed 108182 times by 2 tests: return group->meth->add(group, r, a, b, ctx); Executed by:
| 108182 | ||||||||||||||||||||||||
798 | } | - | ||||||||||||||||||||||||
799 | - | |||||||||||||||||||||||||
800 | int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, | - | ||||||||||||||||||||||||
801 | BN_CTX *ctx) | - | ||||||||||||||||||||||||
802 | { | - | ||||||||||||||||||||||||
803 | if (group->meth->dbl == 0) {
| 0-202847 | ||||||||||||||||||||||||
804 | ECerr(EC_F_EC_POINT_DBL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||||||||||||||||||||
805 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
806 | } | - | ||||||||||||||||||||||||
807 | if (!ec_point_is_compat(r, group) || !ec_point_is_compat(a, group)) {
| 0-202847 | ||||||||||||||||||||||||
808 | ECerr(EC_F_EC_POINT_DBL, EC_R_INCOMPATIBLE_OBJECTS); | - | ||||||||||||||||||||||||
809 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
810 | } | - | ||||||||||||||||||||||||
811 | return group->meth->dbl(group, r, a, ctx); executed 202847 times by 2 tests: return group->meth->dbl(group, r, a, ctx); Executed by:
| 202847 | ||||||||||||||||||||||||
812 | } | - | ||||||||||||||||||||||||
813 | - | |||||||||||||||||||||||||
814 | int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx) | - | ||||||||||||||||||||||||
815 | { | - | ||||||||||||||||||||||||
816 | if (group->meth->invert == 0) {
| 0-26993 | ||||||||||||||||||||||||
817 | ECerr(EC_F_EC_POINT_INVERT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||||||||||||||||||||
818 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
819 | } | - | ||||||||||||||||||||||||
820 | if (!ec_point_is_compat(a, group)) {
| 0-26993 | ||||||||||||||||||||||||
821 | ECerr(EC_F_EC_POINT_INVERT, EC_R_INCOMPATIBLE_OBJECTS); | - | ||||||||||||||||||||||||
822 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
823 | } | - | ||||||||||||||||||||||||
824 | return group->meth->invert(group, a, ctx); executed 26993 times by 2 tests: return group->meth->invert(group, a, ctx); Executed by:
| 26993 | ||||||||||||||||||||||||
825 | } | - | ||||||||||||||||||||||||
826 | - | |||||||||||||||||||||||||
827 | int EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *point) | - | ||||||||||||||||||||||||
828 | { | - | ||||||||||||||||||||||||
829 | if (group->meth->is_at_infinity == 0) {
| 0-724940 | ||||||||||||||||||||||||
830 | ECerr(EC_F_EC_POINT_IS_AT_INFINITY, | - | ||||||||||||||||||||||||
831 | ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||||||||||||||||||||
832 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
833 | } | - | ||||||||||||||||||||||||
834 | if (!ec_point_is_compat(point, group)) {
| 0-724940 | ||||||||||||||||||||||||
835 | ECerr(EC_F_EC_POINT_IS_AT_INFINITY, EC_R_INCOMPATIBLE_OBJECTS); | - | ||||||||||||||||||||||||
836 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
837 | } | - | ||||||||||||||||||||||||
838 | return group->meth->is_at_infinity(group, point); executed 724940 times by 2 tests: return group->meth->is_at_infinity(group, point); Executed by:
| 724940 | ||||||||||||||||||||||||
839 | } | - | ||||||||||||||||||||||||
840 | - | |||||||||||||||||||||||||
841 | /* | - | ||||||||||||||||||||||||
842 | * Check whether an EC_POINT is on the curve or not. Note that the return | - | ||||||||||||||||||||||||
843 | * value for this function should NOT be treated as a boolean. Return values: | - | ||||||||||||||||||||||||
844 | * 1: The point is on the curve | - | ||||||||||||||||||||||||
845 | * 0: The point is not on the curve | - | ||||||||||||||||||||||||
846 | * -1: An error occurred | - | ||||||||||||||||||||||||
847 | */ | - | ||||||||||||||||||||||||
848 | int EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point, | - | ||||||||||||||||||||||||
849 | BN_CTX *ctx) | - | ||||||||||||||||||||||||
850 | { | - | ||||||||||||||||||||||||
851 | if (group->meth->is_on_curve == 0) {
| 0-128674 | ||||||||||||||||||||||||
852 | ECerr(EC_F_EC_POINT_IS_ON_CURVE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||||||||||||||||||||
853 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
854 | } | - | ||||||||||||||||||||||||
855 | if (!ec_point_is_compat(point, group)) {
| 0-128674 | ||||||||||||||||||||||||
856 | ECerr(EC_F_EC_POINT_IS_ON_CURVE, EC_R_INCOMPATIBLE_OBJECTS); | - | ||||||||||||||||||||||||
857 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
858 | } | - | ||||||||||||||||||||||||
859 | return group->meth->is_on_curve(group, point, ctx); executed 128674 times by 2 tests: return group->meth->is_on_curve(group, point, ctx); Executed by:
| 128674 | ||||||||||||||||||||||||
860 | } | - | ||||||||||||||||||||||||
861 | - | |||||||||||||||||||||||||
862 | int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, | - | ||||||||||||||||||||||||
863 | BN_CTX *ctx) | - | ||||||||||||||||||||||||
864 | { | - | ||||||||||||||||||||||||
865 | if (group->meth->point_cmp == 0) {
| 0-9899 | ||||||||||||||||||||||||
866 | ECerr(EC_F_EC_POINT_CMP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||||||||||||||||||||
867 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
868 | } | - | ||||||||||||||||||||||||
869 | if (!ec_point_is_compat(a, group) || !ec_point_is_compat(b, group)) {
| 0-9899 | ||||||||||||||||||||||||
870 | ECerr(EC_F_EC_POINT_CMP, EC_R_INCOMPATIBLE_OBJECTS); | - | ||||||||||||||||||||||||
871 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
872 | } | - | ||||||||||||||||||||||||
873 | return group->meth->point_cmp(group, a, b, ctx); executed 9899 times by 1 test: return group->meth->point_cmp(group, a, b, ctx); Executed by:
| 9899 | ||||||||||||||||||||||||
874 | } | - | ||||||||||||||||||||||||
875 | - | |||||||||||||||||||||||||
876 | int EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx) | - | ||||||||||||||||||||||||
877 | { | - | ||||||||||||||||||||||||
878 | if (group->meth->make_affine == 0) {
| 0-6230 | ||||||||||||||||||||||||
879 | ECerr(EC_F_EC_POINT_MAKE_AFFINE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||||||||||||||||||||
880 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
881 | } | - | ||||||||||||||||||||||||
882 | if (!ec_point_is_compat(point, group)) {
| 0-6230 | ||||||||||||||||||||||||
883 | ECerr(EC_F_EC_POINT_MAKE_AFFINE, EC_R_INCOMPATIBLE_OBJECTS); | - | ||||||||||||||||||||||||
884 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
885 | } | - | ||||||||||||||||||||||||
886 | return group->meth->make_affine(group, point, ctx); executed 6230 times by 1 test: return group->meth->make_affine(group, point, ctx); Executed by:
| 6230 | ||||||||||||||||||||||||
887 | } | - | ||||||||||||||||||||||||
888 | - | |||||||||||||||||||||||||
889 | int EC_POINTs_make_affine(const EC_GROUP *group, size_t num, | - | ||||||||||||||||||||||||
890 | EC_POINT *points[], BN_CTX *ctx) | - | ||||||||||||||||||||||||
891 | { | - | ||||||||||||||||||||||||
892 | size_t i; | - | ||||||||||||||||||||||||
893 | - | |||||||||||||||||||||||||
894 | if (group->meth->points_make_affine == 0) {
| 0-775 | ||||||||||||||||||||||||
895 | ECerr(EC_F_EC_POINTS_MAKE_AFFINE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||||||||||||||||||||
896 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
897 | } | - | ||||||||||||||||||||||||
898 | for (i = 0; i < num; i++) {
| 775-22692 | ||||||||||||||||||||||||
899 | if (!ec_point_is_compat(points[i], group)) {
| 0-22692 | ||||||||||||||||||||||||
900 | ECerr(EC_F_EC_POINTS_MAKE_AFFINE, EC_R_INCOMPATIBLE_OBJECTS); | - | ||||||||||||||||||||||||
901 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
902 | } | - | ||||||||||||||||||||||||
903 | } executed 22692 times by 2 tests: end of block Executed by:
| 22692 | ||||||||||||||||||||||||
904 | return group->meth->points_make_affine(group, num, points, ctx); executed 775 times by 2 tests: return group->meth->points_make_affine(group, num, points, ctx); Executed by:
| 775 | ||||||||||||||||||||||||
905 | } | - | ||||||||||||||||||||||||
906 | - | |||||||||||||||||||||||||
907 | /* | - | ||||||||||||||||||||||||
908 | * Functions for point multiplication. If group->meth->mul is 0, we use the | - | ||||||||||||||||||||||||
909 | * wNAF-based implementations in ec_mult.c; otherwise we dispatch through | - | ||||||||||||||||||||||||
910 | * methods. | - | ||||||||||||||||||||||||
911 | */ | - | ||||||||||||||||||||||||
912 | - | |||||||||||||||||||||||||
913 | int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, | - | ||||||||||||||||||||||||
914 | size_t num, const EC_POINT *points[], | - | ||||||||||||||||||||||||
915 | const BIGNUM *scalars[], BN_CTX *ctx) | - | ||||||||||||||||||||||||
916 | { | - | ||||||||||||||||||||||||
917 | int ret = 0; | - | ||||||||||||||||||||||||
918 | size_t i = 0; | - | ||||||||||||||||||||||||
919 | BN_CTX *new_ctx = NULL; | - | ||||||||||||||||||||||||
920 | - | |||||||||||||||||||||||||
921 | if ((scalar == NULL) && (num == 0)) {
| 0-3244 | ||||||||||||||||||||||||
922 | return EC_POINT_set_to_infinity(group, r); never executed: return EC_POINT_set_to_infinity(group, r); | 0 | ||||||||||||||||||||||||
923 | } | - | ||||||||||||||||||||||||
924 | - | |||||||||||||||||||||||||
925 | if (!ec_point_is_compat(r, group)) {
| 0-5717 | ||||||||||||||||||||||||
926 | ECerr(EC_F_EC_POINTS_MUL, EC_R_INCOMPATIBLE_OBJECTS); | - | ||||||||||||||||||||||||
927 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
928 | } | - | ||||||||||||||||||||||||
929 | for (i = 0; i < num; i++) {
| 4252-5717 | ||||||||||||||||||||||||
930 | if (!ec_point_is_compat(points[i], group)) {
| 0-4252 | ||||||||||||||||||||||||
931 | ECerr(EC_F_EC_POINTS_MUL, EC_R_INCOMPATIBLE_OBJECTS); | - | ||||||||||||||||||||||||
932 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
933 | } | - | ||||||||||||||||||||||||
934 | } executed 4252 times by 2 tests: end of block Executed by:
| 4252 | ||||||||||||||||||||||||
935 | - | |||||||||||||||||||||||||
936 | if (ctx == NULL && (ctx = new_ctx = BN_CTX_secure_new()) == NULL) {
| 0-5315 | ||||||||||||||||||||||||
937 | ECerr(EC_F_EC_POINTS_MUL, ERR_R_INTERNAL_ERROR); | - | ||||||||||||||||||||||||
938 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
939 | } | - | ||||||||||||||||||||||||
940 | - | |||||||||||||||||||||||||
941 | if (group->meth->mul != NULL)
| 2529-3188 | ||||||||||||||||||||||||
942 | ret = group->meth->mul(group, r, scalar, num, points, scalars, ctx); executed 3188 times by 1 test: ret = group->meth->mul(group, r, scalar, num, points, scalars, ctx); Executed by:
| 3188 | ||||||||||||||||||||||||
943 | else | - | ||||||||||||||||||||||||
944 | /* use default */ | - | ||||||||||||||||||||||||
945 | ret = ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx); executed 2529 times by 2 tests: ret = ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx); Executed by:
| 2529 | ||||||||||||||||||||||||
946 | - | |||||||||||||||||||||||||
947 | BN_CTX_free(new_ctx); | - | ||||||||||||||||||||||||
948 | return ret; executed 5717 times by 2 tests: return ret; Executed by:
| 5717 | ||||||||||||||||||||||||
949 | } | - | ||||||||||||||||||||||||
950 | - | |||||||||||||||||||||||||
951 | int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar, | - | ||||||||||||||||||||||||
952 | const EC_POINT *point, const BIGNUM *p_scalar, BN_CTX *ctx) | - | ||||||||||||||||||||||||
953 | { | - | ||||||||||||||||||||||||
954 | /* just a convenient interface to EC_POINTs_mul() */ | - | ||||||||||||||||||||||||
955 | - | |||||||||||||||||||||||||
956 | const EC_POINT *points[1]; | - | ||||||||||||||||||||||||
957 | const BIGNUM *scalars[1]; | - | ||||||||||||||||||||||||
958 | - | |||||||||||||||||||||||||
959 | points[0] = point; | - | ||||||||||||||||||||||||
960 | scalars[0] = p_scalar; | - | ||||||||||||||||||||||||
961 | - | |||||||||||||||||||||||||
962 | return EC_POINTs_mul(group, r, g_scalar, executed 5317 times by 2 tests: return EC_POINTs_mul(group, r, g_scalar, (point != ((void *)0) && p_scalar != ((void *)0) ), points, scalars, ctx); Executed by:
| 5317 | ||||||||||||||||||||||||
963 | (point != NULL executed 5317 times by 2 tests: return EC_POINTs_mul(group, r, g_scalar, (point != ((void *)0) && p_scalar != ((void *)0) ), points, scalars, ctx); Executed by:
| 5317 | ||||||||||||||||||||||||
964 | && p_scalar != NULL), points, scalars, ctx); executed 5317 times by 2 tests: return EC_POINTs_mul(group, r, g_scalar, (point != ((void *)0) && p_scalar != ((void *)0) ), points, scalars, ctx); Executed by:
| 5317 | ||||||||||||||||||||||||
965 | } | - | ||||||||||||||||||||||||
966 | - | |||||||||||||||||||||||||
967 | int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx) | - | ||||||||||||||||||||||||
968 | { | - | ||||||||||||||||||||||||
969 | if (group->meth->mul == 0)
| 45-53 | ||||||||||||||||||||||||
970 | /* use default */ | - | ||||||||||||||||||||||||
971 | return ec_wNAF_precompute_mult(group, ctx); executed 45 times by 1 test: return ec_wNAF_precompute_mult(group, ctx); Executed by:
| 45 | ||||||||||||||||||||||||
972 | - | |||||||||||||||||||||||||
973 | if (group->meth->precompute_mult != 0)
| 1-52 | ||||||||||||||||||||||||
974 | return group->meth->precompute_mult(group, ctx); executed 1 time by 1 test: return group->meth->precompute_mult(group, ctx); Executed by:
| 1 | ||||||||||||||||||||||||
975 | else | - | ||||||||||||||||||||||||
976 | return 1; /* nothing to do, so report success */ executed 52 times by 1 test: return 1; Executed by:
| 52 | ||||||||||||||||||||||||
977 | } | - | ||||||||||||||||||||||||
978 | - | |||||||||||||||||||||||||
979 | int EC_GROUP_have_precompute_mult(const EC_GROUP *group) | - | ||||||||||||||||||||||||
980 | { | - | ||||||||||||||||||||||||
981 | if (group->meth->mul == 0)
| 0 | ||||||||||||||||||||||||
982 | /* use default */ | - | ||||||||||||||||||||||||
983 | return ec_wNAF_have_precompute_mult(group); never executed: return ec_wNAF_have_precompute_mult(group); | 0 | ||||||||||||||||||||||||
984 | - | |||||||||||||||||||||||||
985 | if (group->meth->have_precompute_mult != 0)
| 0 | ||||||||||||||||||||||||
986 | return group->meth->have_precompute_mult(group); never executed: return group->meth->have_precompute_mult(group); | 0 | ||||||||||||||||||||||||
987 | else | - | ||||||||||||||||||||||||
988 | return 0; /* cannot tell whether precomputation has never executed: return 0; | 0 | ||||||||||||||||||||||||
989 | * been performed */ | - | ||||||||||||||||||||||||
990 | } | - | ||||||||||||||||||||||||
991 | - | |||||||||||||||||||||||||
992 | /* | - | ||||||||||||||||||||||||
993 | * ec_precompute_mont_data sets |group->mont_data| from |group->order| and | - | ||||||||||||||||||||||||
994 | * returns one on success. On error it returns zero. | - | ||||||||||||||||||||||||
995 | */ | - | ||||||||||||||||||||||||
996 | static int ec_precompute_mont_data(EC_GROUP *group) | - | ||||||||||||||||||||||||
997 | { | - | ||||||||||||||||||||||||
998 | BN_CTX *ctx = BN_CTX_new(); | - | ||||||||||||||||||||||||
999 | int ret = 0; | - | ||||||||||||||||||||||||
1000 | - | |||||||||||||||||||||||||
1001 | BN_MONT_CTX_free(group->mont_data); | - | ||||||||||||||||||||||||
1002 | group->mont_data = NULL; | - | ||||||||||||||||||||||||
1003 | - | |||||||||||||||||||||||||
1004 | if (ctx == NULL)
| 0-35165 | ||||||||||||||||||||||||
1005 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
1006 | - | |||||||||||||||||||||||||
1007 | group->mont_data = BN_MONT_CTX_new(); | - | ||||||||||||||||||||||||
1008 | if (group->mont_data == NULL)
| 0-35165 | ||||||||||||||||||||||||
1009 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
1010 | - | |||||||||||||||||||||||||
1011 | if (!BN_MONT_CTX_set(group->mont_data, group->order, ctx)) {
| 0-35165 | ||||||||||||||||||||||||
1012 | BN_MONT_CTX_free(group->mont_data); | - | ||||||||||||||||||||||||
1013 | group->mont_data = NULL; | - | ||||||||||||||||||||||||
1014 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
1015 | } | - | ||||||||||||||||||||||||
1016 | - | |||||||||||||||||||||||||
1017 | ret = 1; | - | ||||||||||||||||||||||||
1018 | - | |||||||||||||||||||||||||
1019 | err: code before this statement executed 35165 times by 2 tests: err: Executed by:
| 35165 | ||||||||||||||||||||||||
1020 | - | |||||||||||||||||||||||||
1021 | BN_CTX_free(ctx); | - | ||||||||||||||||||||||||
1022 | return ret; executed 35165 times by 2 tests: return ret; Executed by:
| 35165 | ||||||||||||||||||||||||
1023 | } | - | ||||||||||||||||||||||||
1024 | - | |||||||||||||||||||||||||
1025 | int EC_KEY_set_ex_data(EC_KEY *key, int idx, void *arg) | - | ||||||||||||||||||||||||
1026 | { | - | ||||||||||||||||||||||||
1027 | return CRYPTO_set_ex_data(&key->ex_data, idx, arg); never executed: return CRYPTO_set_ex_data(&key->ex_data, idx, arg); | 0 | ||||||||||||||||||||||||
1028 | } | - | ||||||||||||||||||||||||
1029 | - | |||||||||||||||||||||||||
1030 | void *EC_KEY_get_ex_data(const EC_KEY *key, int idx) | - | ||||||||||||||||||||||||
1031 | { | - | ||||||||||||||||||||||||
1032 | return CRYPTO_get_ex_data(&key->ex_data, idx); never executed: return CRYPTO_get_ex_data(&key->ex_data, idx); | 0 | ||||||||||||||||||||||||
1033 | } | - | ||||||||||||||||||||||||
1034 | - | |||||||||||||||||||||||||
1035 | int ec_group_simple_order_bits(const EC_GROUP *group) | - | ||||||||||||||||||||||||
1036 | { | - | ||||||||||||||||||||||||
1037 | if (group->order == NULL)
| 0-4444 | ||||||||||||||||||||||||
1038 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
1039 | return BN_num_bits(group->order); executed 4444 times by 1 test: return BN_num_bits(group->order); Executed by:
| 4444 | ||||||||||||||||||||||||
1040 | } | - | ||||||||||||||||||||||||
1041 | - | |||||||||||||||||||||||||
1042 | static int ec_field_inverse_mod_ord(const EC_GROUP *group, BIGNUM *r, | - | ||||||||||||||||||||||||
1043 | const BIGNUM *x, BN_CTX *ctx) | - | ||||||||||||||||||||||||
1044 | { | - | ||||||||||||||||||||||||
1045 | BIGNUM *e = NULL; | - | ||||||||||||||||||||||||
1046 | BN_CTX *new_ctx = NULL; | - | ||||||||||||||||||||||||
1047 | int ret = 0; | - | ||||||||||||||||||||||||
1048 | - | |||||||||||||||||||||||||
1049 | if (group->mont_data == NULL)
| 0-541 | ||||||||||||||||||||||||
1050 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
1051 | - | |||||||||||||||||||||||||
1052 | if (ctx == NULL && (ctx = new_ctx = BN_CTX_secure_new()) == NULL)
| 0-541 | ||||||||||||||||||||||||
1053 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
1054 | - | |||||||||||||||||||||||||
1055 | BN_CTX_start(ctx); | - | ||||||||||||||||||||||||
1056 | if ((e = BN_CTX_get(ctx)) == NULL)
| 0-541 | ||||||||||||||||||||||||
1057 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
1058 | - | |||||||||||||||||||||||||
1059 | /*- | - | ||||||||||||||||||||||||
1060 | * We want inverse in constant time, therefore we utilize the fact | - | ||||||||||||||||||||||||
1061 | * order must be prime and use Fermats Little Theorem instead. | - | ||||||||||||||||||||||||
1062 | */ | - | ||||||||||||||||||||||||
1063 | if (!BN_set_word(e, 2))
| 0-541 | ||||||||||||||||||||||||
1064 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
1065 | if (!BN_sub(e, group->order, e))
| 0-541 | ||||||||||||||||||||||||
1066 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
1067 | /*- | - | ||||||||||||||||||||||||
1068 | * Exponent e is public. | - | ||||||||||||||||||||||||
1069 | * No need for scatter-gather or BN_FLG_CONSTTIME. | - | ||||||||||||||||||||||||
1070 | */ | - | ||||||||||||||||||||||||
1071 | if (!BN_mod_exp_mont(r, x, e, group->order, ctx, group->mont_data))
| 0-541 | ||||||||||||||||||||||||
1072 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
1073 | - | |||||||||||||||||||||||||
1074 | ret = 1; | - | ||||||||||||||||||||||||
1075 | - | |||||||||||||||||||||||||
1076 | err: code before this statement executed 541 times by 2 tests: err: Executed by:
| 541 | ||||||||||||||||||||||||
1077 | if (ctx != NULL)
| 0-541 | ||||||||||||||||||||||||
1078 | BN_CTX_end(ctx); executed 541 times by 2 tests: BN_CTX_end(ctx); Executed by:
| 541 | ||||||||||||||||||||||||
1079 | BN_CTX_free(new_ctx); | - | ||||||||||||||||||||||||
1080 | return ret; executed 541 times by 2 tests: return ret; Executed by:
| 541 | ||||||||||||||||||||||||
1081 | } | - | ||||||||||||||||||||||||
1082 | - | |||||||||||||||||||||||||
1083 | /*- | - | ||||||||||||||||||||||||
1084 | * Default behavior, if group->meth->field_inverse_mod_ord is NULL: | - | ||||||||||||||||||||||||
1085 | * - When group->order is even, this function returns an error. | - | ||||||||||||||||||||||||
1086 | * - When group->order is otherwise composite, the correctness | - | ||||||||||||||||||||||||
1087 | * of the output is not guaranteed. | - | ||||||||||||||||||||||||
1088 | * - When x is outside the range [1, group->order), the correctness | - | ||||||||||||||||||||||||
1089 | * of the output is not guaranteed. | - | ||||||||||||||||||||||||
1090 | * - Otherwise, this function returns the multiplicative inverse in the | - | ||||||||||||||||||||||||
1091 | * range [1, group->order). | - | ||||||||||||||||||||||||
1092 | * | - | ||||||||||||||||||||||||
1093 | * EC_METHODs must implement their own field_inverse_mod_ord for | - | ||||||||||||||||||||||||
1094 | * other functionality. | - | ||||||||||||||||||||||||
1095 | */ | - | ||||||||||||||||||||||||
1096 | int ec_group_do_inverse_ord(const EC_GROUP *group, BIGNUM *res, | - | ||||||||||||||||||||||||
1097 | const BIGNUM *x, BN_CTX *ctx) | - | ||||||||||||||||||||||||
1098 | { | - | ||||||||||||||||||||||||
1099 | if (group->meth->field_inverse_mod_ord != NULL)
| 413-541 | ||||||||||||||||||||||||
1100 | return group->meth->field_inverse_mod_ord(group, res, x, ctx); executed 413 times by 1 test: return group->meth->field_inverse_mod_ord(group, res, x, ctx); Executed by:
| 413 | ||||||||||||||||||||||||
1101 | else | - | ||||||||||||||||||||||||
1102 | return ec_field_inverse_mod_ord(group, res, x, ctx); executed 541 times by 2 tests: return ec_field_inverse_mod_ord(group, res, x, ctx); Executed by:
| 541 | ||||||||||||||||||||||||
1103 | } | - | ||||||||||||||||||||||||
1104 | - | |||||||||||||||||||||||||
1105 | /*- | - | ||||||||||||||||||||||||
1106 | * Coordinate blinding for EC_POINT. | - | ||||||||||||||||||||||||
1107 | * | - | ||||||||||||||||||||||||
1108 | * The underlying EC_METHOD can optionally implement this function: | - | ||||||||||||||||||||||||
1109 | * underlying implementations should return 0 on errors, or 1 on | - | ||||||||||||||||||||||||
1110 | * success. | - | ||||||||||||||||||||||||
1111 | * | - | ||||||||||||||||||||||||
1112 | * This wrapper returns 1 in case the underlying EC_METHOD does not | - | ||||||||||||||||||||||||
1113 | * support coordinate blinding. | - | ||||||||||||||||||||||||
1114 | */ | - | ||||||||||||||||||||||||
1115 | int ec_point_blind_coordinates(const EC_GROUP *group, EC_POINT *p, BN_CTX *ctx) | - | ||||||||||||||||||||||||
1116 | { | - | ||||||||||||||||||||||||
1117 | if (group->meth->blind_coordinates == NULL)
| 2004-2126 | ||||||||||||||||||||||||
1118 | return 1; /* ignore if not implemented */ executed 2126 times by 1 test: return 1; Executed by:
| 2126 | ||||||||||||||||||||||||
1119 | - | |||||||||||||||||||||||||
1120 | return group->meth->blind_coordinates(group, p, ctx); executed 2004 times by 2 tests: return group->meth->blind_coordinates(group, p, ctx); Executed by:
| 2004 | ||||||||||||||||||||||||
1121 | } | - | ||||||||||||||||||||||||
Source code | Switch to Preprocessed file |