Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/ec/ecp_oct.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* | - | ||||||||||||||||||
2 | * Copyright 2011-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 <openssl/err.h> | - | ||||||||||||||||||
12 | #include <openssl/symhacks.h> | - | ||||||||||||||||||
13 | - | |||||||||||||||||||
14 | #include "ec_lcl.h" | - | ||||||||||||||||||
15 | - | |||||||||||||||||||
16 | int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *group, | - | ||||||||||||||||||
17 | EC_POINT *point, | - | ||||||||||||||||||
18 | const BIGNUM *x_, int y_bit, | - | ||||||||||||||||||
19 | BN_CTX *ctx) | - | ||||||||||||||||||
20 | { | - | ||||||||||||||||||
21 | BN_CTX *new_ctx = NULL; | - | ||||||||||||||||||
22 | BIGNUM *tmp1, *tmp2, *x, *y; | - | ||||||||||||||||||
23 | int ret = 0; | - | ||||||||||||||||||
24 | - | |||||||||||||||||||
25 | /* clear error queue */ | - | ||||||||||||||||||
26 | ERR_clear_error(); | - | ||||||||||||||||||
27 | - | |||||||||||||||||||
28 | if (ctx == NULL) {
| 0-4526 | ||||||||||||||||||
29 | ctx = new_ctx = BN_CTX_new(); | - | ||||||||||||||||||
30 | if (ctx == NULL)
| 0 | ||||||||||||||||||
31 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
32 | } never executed: end of block | 0 | ||||||||||||||||||
33 | - | |||||||||||||||||||
34 | y_bit = (y_bit != 0); | - | ||||||||||||||||||
35 | - | |||||||||||||||||||
36 | BN_CTX_start(ctx); | - | ||||||||||||||||||
37 | tmp1 = BN_CTX_get(ctx); | - | ||||||||||||||||||
38 | tmp2 = BN_CTX_get(ctx); | - | ||||||||||||||||||
39 | x = BN_CTX_get(ctx); | - | ||||||||||||||||||
40 | y = BN_CTX_get(ctx); | - | ||||||||||||||||||
41 | if (y == NULL)
| 0-4526 | ||||||||||||||||||
42 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
43 | - | |||||||||||||||||||
44 | /*- | - | ||||||||||||||||||
45 | * Recover y. We have a Weierstrass equation | - | ||||||||||||||||||
46 | * y^2 = x^3 + a*x + b, | - | ||||||||||||||||||
47 | * so y is one of the square roots of x^3 + a*x + b. | - | ||||||||||||||||||
48 | */ | - | ||||||||||||||||||
49 | - | |||||||||||||||||||
50 | /* tmp1 := x^3 */ | - | ||||||||||||||||||
51 | if (!BN_nnmod(x, x_, group->field, ctx))
| 0-4526 | ||||||||||||||||||
52 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
53 | if (group->meth->field_decode == 0) {
| 0-4526 | ||||||||||||||||||
54 | /* field_{sqr,mul} work on standard representation */ | - | ||||||||||||||||||
55 | if (!group->meth->field_sqr(group, tmp2, x_, ctx))
| 0 | ||||||||||||||||||
56 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
57 | if (!group->meth->field_mul(group, tmp1, tmp2, x_, ctx))
| 0 | ||||||||||||||||||
58 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
59 | } else { never executed: end of block | 0 | ||||||||||||||||||
60 | if (!BN_mod_sqr(tmp2, x_, group->field, ctx))
| 0-4526 | ||||||||||||||||||
61 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
62 | if (!BN_mod_mul(tmp1, tmp2, x_, group->field, ctx))
| 0-4526 | ||||||||||||||||||
63 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
64 | } executed 4526 times by 1 test: end of block Executed by:
| 4526 | ||||||||||||||||||
65 | - | |||||||||||||||||||
66 | /* tmp1 := tmp1 + a*x */ | - | ||||||||||||||||||
67 | if (group->a_is_minus3) {
| 787-3739 | ||||||||||||||||||
68 | if (!BN_mod_lshift1_quick(tmp2, x, group->field))
| 0-3739 | ||||||||||||||||||
69 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
70 | if (!BN_mod_add_quick(tmp2, tmp2, x, group->field))
| 0-3739 | ||||||||||||||||||
71 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
72 | if (!BN_mod_sub_quick(tmp1, tmp1, tmp2, group->field))
| 0-3739 | ||||||||||||||||||
73 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
74 | } else { executed 3739 times by 1 test: end of block Executed by:
| 3739 | ||||||||||||||||||
75 | if (group->meth->field_decode) {
| 0-787 | ||||||||||||||||||
76 | if (!group->meth->field_decode(group, tmp2, group->a, ctx))
| 0-787 | ||||||||||||||||||
77 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
78 | if (!BN_mod_mul(tmp2, tmp2, x, group->field, ctx))
| 0-787 | ||||||||||||||||||
79 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
80 | } else { executed 787 times by 1 test: end of block Executed by:
| 787 | ||||||||||||||||||
81 | /* field_mul works on standard representation */ | - | ||||||||||||||||||
82 | if (!group->meth->field_mul(group, tmp2, group->a, x, ctx))
| 0 | ||||||||||||||||||
83 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
84 | } never executed: end of block | 0 | ||||||||||||||||||
85 | - | |||||||||||||||||||
86 | if (!BN_mod_add_quick(tmp1, tmp1, tmp2, group->field))
| 0-787 | ||||||||||||||||||
87 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
88 | } executed 787 times by 1 test: end of block Executed by:
| 787 | ||||||||||||||||||
89 | - | |||||||||||||||||||
90 | /* tmp1 := tmp1 + b */ | - | ||||||||||||||||||
91 | if (group->meth->field_decode) {
| 0-4526 | ||||||||||||||||||
92 | if (!group->meth->field_decode(group, tmp2, group->b, ctx))
| 0-4526 | ||||||||||||||||||
93 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
94 | if (!BN_mod_add_quick(tmp1, tmp1, tmp2, group->field))
| 0-4526 | ||||||||||||||||||
95 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
96 | } else { executed 4526 times by 1 test: end of block Executed by:
| 4526 | ||||||||||||||||||
97 | if (!BN_mod_add_quick(tmp1, tmp1, group->b, group->field))
| 0 | ||||||||||||||||||
98 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
99 | } never executed: end of block | 0 | ||||||||||||||||||
100 | - | |||||||||||||||||||
101 | if (!BN_mod_sqrt(y, tmp1, group->field, ctx)) {
| 1279-3247 | ||||||||||||||||||
102 | unsigned long err = ERR_peek_last_error(); | - | ||||||||||||||||||
103 | - | |||||||||||||||||||
104 | if (ERR_GET_LIB(err) == ERR_LIB_BN
| 0-1279 | ||||||||||||||||||
105 | && ERR_GET_REASON(err) == BN_R_NOT_A_SQUARE) {
| 14-1265 | ||||||||||||||||||
106 | ERR_clear_error(); | - | ||||||||||||||||||
107 | ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, | - | ||||||||||||||||||
108 | EC_R_INVALID_COMPRESSED_POINT); | - | ||||||||||||||||||
109 | } else executed 1265 times by 1 test: end of block Executed by:
| 1265 | ||||||||||||||||||
110 | ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, executed 14 times by 1 test: ERR_put_error(16,(169),(3),__FILE__,111) ; Executed by:
| 14 | ||||||||||||||||||
111 | ERR_R_BN_LIB); executed 14 times by 1 test: ERR_put_error(16,(169),(3),__FILE__,111) ; Executed by:
| 14 | ||||||||||||||||||
112 | goto err; executed 1279 times by 1 test: goto err; Executed by:
| 1279 | ||||||||||||||||||
113 | } | - | ||||||||||||||||||
114 | - | |||||||||||||||||||
115 | if (y_bit != BN_is_odd(y)) {
| 1477-1770 | ||||||||||||||||||
116 | if (BN_is_zero(y)) {
| 0-1477 | ||||||||||||||||||
117 | int kron; | - | ||||||||||||||||||
118 | - | |||||||||||||||||||
119 | kron = BN_kronecker(x, group->field, ctx); | - | ||||||||||||||||||
120 | if (kron == -2)
| 0 | ||||||||||||||||||
121 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
122 | - | |||||||||||||||||||
123 | if (kron == 1)
| 0 | ||||||||||||||||||
124 | ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, never executed: ERR_put_error(16,(169),(109),__FILE__,125) ; | 0 | ||||||||||||||||||
125 | EC_R_INVALID_COMPRESSION_BIT); never executed: ERR_put_error(16,(169),(109),__FILE__,125) ; | 0 | ||||||||||||||||||
126 | else | - | ||||||||||||||||||
127 | /* | - | ||||||||||||||||||
128 | * BN_mod_sqrt() should have caught this error (not a square) | - | ||||||||||||||||||
129 | */ | - | ||||||||||||||||||
130 | ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, never executed: ERR_put_error(16,(169),(110),__FILE__,131) ; | 0 | ||||||||||||||||||
131 | EC_R_INVALID_COMPRESSED_POINT); never executed: ERR_put_error(16,(169),(110),__FILE__,131) ; | 0 | ||||||||||||||||||
132 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
133 | } | - | ||||||||||||||||||
134 | if (!BN_usub(y, group->field, y))
| 0-1477 | ||||||||||||||||||
135 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
136 | } executed 1477 times by 1 test: end of block Executed by:
| 1477 | ||||||||||||||||||
137 | if (y_bit != BN_is_odd(y)) {
| 0-3247 | ||||||||||||||||||
138 | ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, | - | ||||||||||||||||||
139 | ERR_R_INTERNAL_ERROR); | - | ||||||||||||||||||
140 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
141 | } | - | ||||||||||||||||||
142 | - | |||||||||||||||||||
143 | if (!EC_POINT_set_affine_coordinates(group, point, x, y, ctx))
| 0-3247 | ||||||||||||||||||
144 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
145 | - | |||||||||||||||||||
146 | ret = 1; | - | ||||||||||||||||||
147 | - | |||||||||||||||||||
148 | err: code before this statement executed 3247 times by 1 test: err: Executed by:
| 3247 | ||||||||||||||||||
149 | BN_CTX_end(ctx); | - | ||||||||||||||||||
150 | BN_CTX_free(new_ctx); | - | ||||||||||||||||||
151 | return ret; executed 4526 times by 1 test: return ret; Executed by:
| 4526 | ||||||||||||||||||
152 | } | - | ||||||||||||||||||
153 | - | |||||||||||||||||||
154 | size_t ec_GFp_simple_point2oct(const EC_GROUP *group, const EC_POINT *point, | - | ||||||||||||||||||
155 | point_conversion_form_t form, | - | ||||||||||||||||||
156 | unsigned char *buf, size_t len, BN_CTX *ctx) | - | ||||||||||||||||||
157 | { | - | ||||||||||||||||||
158 | size_t ret; | - | ||||||||||||||||||
159 | BN_CTX *new_ctx = NULL; | - | ||||||||||||||||||
160 | int used_ctx = 0; | - | ||||||||||||||||||
161 | BIGNUM *x, *y; | - | ||||||||||||||||||
162 | size_t field_len, i, skip; | - | ||||||||||||||||||
163 | - | |||||||||||||||||||
164 | if ((form != POINT_CONVERSION_COMPRESSED)
| 217-41437 | ||||||||||||||||||
165 | && (form != POINT_CONVERSION_UNCOMPRESSED)
| 12-41425 | ||||||||||||||||||
166 | && (form != POINT_CONVERSION_HYBRID)) {
| 1-11 | ||||||||||||||||||
167 | ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, EC_R_INVALID_FORM); | - | ||||||||||||||||||
168 | goto err; executed 1 time by 1 test: goto err; Executed by:
| 1 | ||||||||||||||||||
169 | } | - | ||||||||||||||||||
170 | - | |||||||||||||||||||
171 | if (EC_POINT_is_at_infinity(group, point)) {
| 28-41625 | ||||||||||||||||||
172 | /* encodes to a single 0 octet */ | - | ||||||||||||||||||
173 | if (buf != NULL) {
| 14 | ||||||||||||||||||
174 | if (len < 1) {
| 0-14 | ||||||||||||||||||
175 | ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, EC_R_BUFFER_TOO_SMALL); | - | ||||||||||||||||||
176 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
177 | } | - | ||||||||||||||||||
178 | buf[0] = 0; | - | ||||||||||||||||||
179 | } executed 14 times by 1 test: end of block Executed by:
| 14 | ||||||||||||||||||
180 | return 1; executed 28 times by 1 test: return 1; Executed by:
| 28 | ||||||||||||||||||
181 | } | - | ||||||||||||||||||
182 | - | |||||||||||||||||||
183 | /* ret := required output buffer length */ | - | ||||||||||||||||||
184 | field_len = BN_num_bytes(group->field); | - | ||||||||||||||||||
185 | ret = | - | ||||||||||||||||||
186 | (form ==
| 217-41408 | ||||||||||||||||||
187 | POINT_CONVERSION_COMPRESSED) ? 1 + field_len : 1 + 2 * field_len;
| 217-41408 | ||||||||||||||||||
188 | - | |||||||||||||||||||
189 | /* if 'buf' is NULL, just return required length */ | - | ||||||||||||||||||
190 | if (buf != NULL) {
| 14268-27357 | ||||||||||||||||||
191 | if (len < ret) {
| 0-14268 | ||||||||||||||||||
192 | ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, EC_R_BUFFER_TOO_SMALL); | - | ||||||||||||||||||
193 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
194 | } | - | ||||||||||||||||||
195 | - | |||||||||||||||||||
196 | if (ctx == NULL) {
| 48-14220 | ||||||||||||||||||
197 | ctx = new_ctx = BN_CTX_new(); | - | ||||||||||||||||||
198 | if (ctx == NULL)
| 0-14220 | ||||||||||||||||||
199 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
200 | } executed 14220 times by 1 test: end of block Executed by:
| 14220 | ||||||||||||||||||
201 | - | |||||||||||||||||||
202 | BN_CTX_start(ctx); | - | ||||||||||||||||||
203 | used_ctx = 1; | - | ||||||||||||||||||
204 | x = BN_CTX_get(ctx); | - | ||||||||||||||||||
205 | y = BN_CTX_get(ctx); | - | ||||||||||||||||||
206 | if (y == NULL)
| 0-14268 | ||||||||||||||||||
207 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
208 | - | |||||||||||||||||||
209 | if (!EC_POINT_get_affine_coordinates(group, point, x, y, ctx))
| 0-14268 | ||||||||||||||||||
210 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
211 | - | |||||||||||||||||||
212 | if ((form == POINT_CONVERSION_COMPRESSED
| 109-14159 | ||||||||||||||||||
213 | || form == POINT_CONVERSION_HYBRID) && BN_is_odd(y))
| 6-14153 | ||||||||||||||||||
214 | buf[0] = form + 1; executed 12 times by 1 test: buf[0] = form + 1; Executed by:
| 12 | ||||||||||||||||||
215 | else | - | ||||||||||||||||||
216 | buf[0] = form; executed 14256 times by 1 test: buf[0] = form; Executed by:
| 14256 | ||||||||||||||||||
217 | - | |||||||||||||||||||
218 | i = 1; | - | ||||||||||||||||||
219 | - | |||||||||||||||||||
220 | skip = field_len - BN_num_bytes(x); | - | ||||||||||||||||||
221 | if (skip > field_len) {
| 0-14268 | ||||||||||||||||||
222 | ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR); | - | ||||||||||||||||||
223 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
224 | } | - | ||||||||||||||||||
225 | while (skip > 0) {
| 736-14268 | ||||||||||||||||||
226 | buf[i++] = 0; | - | ||||||||||||||||||
227 | skip--; | - | ||||||||||||||||||
228 | } executed 736 times by 1 test: end of block Executed by:
| 736 | ||||||||||||||||||
229 | skip = BN_bn2bin(x, buf + i); | - | ||||||||||||||||||
230 | i += skip; | - | ||||||||||||||||||
231 | if (i != 1 + field_len) {
| 0-14268 | ||||||||||||||||||
232 | ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR); | - | ||||||||||||||||||
233 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
234 | } | - | ||||||||||||||||||
235 | - | |||||||||||||||||||
236 | if (form == POINT_CONVERSION_UNCOMPRESSED
| 115-14153 | ||||||||||||||||||
237 | || form == POINT_CONVERSION_HYBRID) {
| 6-109 | ||||||||||||||||||
238 | skip = field_len - BN_num_bytes(y); | - | ||||||||||||||||||
239 | if (skip > field_len) {
| 0-14159 | ||||||||||||||||||
240 | ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR); | - | ||||||||||||||||||
241 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
242 | } | - | ||||||||||||||||||
243 | while (skip > 0) {
| 339-14159 | ||||||||||||||||||
244 | buf[i++] = 0; | - | ||||||||||||||||||
245 | skip--; | - | ||||||||||||||||||
246 | } executed 339 times by 1 test: end of block Executed by:
| 339 | ||||||||||||||||||
247 | skip = BN_bn2bin(y, buf + i); | - | ||||||||||||||||||
248 | i += skip; | - | ||||||||||||||||||
249 | } executed 14159 times by 1 test: end of block Executed by:
| 14159 | ||||||||||||||||||
250 | - | |||||||||||||||||||
251 | if (i != ret) {
| 0-14268 | ||||||||||||||||||
252 | ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR); | - | ||||||||||||||||||
253 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
254 | } | - | ||||||||||||||||||
255 | } executed 14268 times by 1 test: end of block Executed by:
| 14268 | ||||||||||||||||||
256 | - | |||||||||||||||||||
257 | if (used_ctx)
| 14268-27357 | ||||||||||||||||||
258 | BN_CTX_end(ctx); executed 14268 times by 1 test: BN_CTX_end(ctx); Executed by:
| 14268 | ||||||||||||||||||
259 | BN_CTX_free(new_ctx); | - | ||||||||||||||||||
260 | return ret; executed 41625 times by 1 test: return ret; Executed by:
| 41625 | ||||||||||||||||||
261 | - | |||||||||||||||||||
262 | err: | - | ||||||||||||||||||
263 | if (used_ctx)
| 0-1 | ||||||||||||||||||
264 | BN_CTX_end(ctx); never executed: BN_CTX_end(ctx); | 0 | ||||||||||||||||||
265 | BN_CTX_free(new_ctx); | - | ||||||||||||||||||
266 | return 0; executed 1 time by 1 test: return 0; Executed by:
| 1 | ||||||||||||||||||
267 | } | - | ||||||||||||||||||
268 | - | |||||||||||||||||||
269 | int ec_GFp_simple_oct2point(const EC_GROUP *group, EC_POINT *point, | - | ||||||||||||||||||
270 | const unsigned char *buf, size_t len, BN_CTX *ctx) | - | ||||||||||||||||||
271 | { | - | ||||||||||||||||||
272 | point_conversion_form_t form; | - | ||||||||||||||||||
273 | int y_bit; | - | ||||||||||||||||||
274 | BN_CTX *new_ctx = NULL; | - | ||||||||||||||||||
275 | BIGNUM *x, *y; | - | ||||||||||||||||||
276 | size_t field_len, enc_len; | - | ||||||||||||||||||
277 | int ret = 0; | - | ||||||||||||||||||
278 | - | |||||||||||||||||||
279 | if (len == 0) {
| 276-24879 | ||||||||||||||||||
280 | ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_BUFFER_TOO_SMALL); | - | ||||||||||||||||||
281 | return 0; executed 276 times by 1 test: return 0; Executed by:
| 276 | ||||||||||||||||||
282 | } | - | ||||||||||||||||||
283 | form = buf[0]; | - | ||||||||||||||||||
284 | y_bit = form & 1; | - | ||||||||||||||||||
285 | form = form & ~1U; | - | ||||||||||||||||||
286 | if ((form != 0) && (form != POINT_CONVERSION_COMPRESSED)
| 462-24417 | ||||||||||||||||||
287 | && (form != POINT_CONVERSION_UNCOMPRESSED)
| 551-19008 | ||||||||||||||||||
288 | && (form != POINT_CONVERSION_HYBRID)) {
| 250-301 | ||||||||||||||||||
289 | ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); | - | ||||||||||||||||||
290 | return 0; executed 250 times by 1 test: return 0; Executed by:
| 250 | ||||||||||||||||||
291 | } | - | ||||||||||||||||||
292 | if ((form == 0 || form == POINT_CONVERSION_UNCOMPRESSED) && y_bit) {
| 74-24167 | ||||||||||||||||||
293 | ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); | - | ||||||||||||||||||
294 | return 0; executed 74 times by 1 test: return 0; Executed by:
| 74 | ||||||||||||||||||
295 | } | - | ||||||||||||||||||
296 | - | |||||||||||||||||||
297 | if (form == 0) {
| 393-24162 | ||||||||||||||||||
298 | if (len != 1) {
| 80-313 | ||||||||||||||||||
299 | ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); | - | ||||||||||||||||||
300 | return 0; executed 80 times by 1 test: return 0; Executed by:
| 80 | ||||||||||||||||||
301 | } | - | ||||||||||||||||||
302 | - | |||||||||||||||||||
303 | return EC_POINT_set_to_infinity(group, point); executed 313 times by 1 test: return EC_POINT_set_to_infinity(group, point); Executed by:
| 313 | ||||||||||||||||||
304 | } | - | ||||||||||||||||||
305 | - | |||||||||||||||||||
306 | field_len = BN_num_bytes(group->field); | - | ||||||||||||||||||
307 | enc_len = | - | ||||||||||||||||||
308 | (form ==
| 4858-19304 | ||||||||||||||||||
309 | POINT_CONVERSION_COMPRESSED) ? 1 + field_len : 1 + 2 * field_len;
| 4858-19304 | ||||||||||||||||||
310 | - | |||||||||||||||||||
311 | if (len != enc_len) {
| 360-23802 | ||||||||||||||||||
312 | ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); | - | ||||||||||||||||||
313 | return 0; executed 360 times by 1 test: return 0; Executed by:
| 360 | ||||||||||||||||||
314 | } | - | ||||||||||||||||||
315 | - | |||||||||||||||||||
316 | if (ctx == NULL) {
| 3-23799 | ||||||||||||||||||
317 | ctx = new_ctx = BN_CTX_new(); | - | ||||||||||||||||||
318 | if (ctx == NULL)
| 0-23799 | ||||||||||||||||||
319 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
320 | } executed 23799 times by 1 test: end of block Executed by:
| 23799 | ||||||||||||||||||
321 | - | |||||||||||||||||||
322 | BN_CTX_start(ctx); | - | ||||||||||||||||||
323 | x = BN_CTX_get(ctx); | - | ||||||||||||||||||
324 | y = BN_CTX_get(ctx); | - | ||||||||||||||||||
325 | if (y == NULL)
| 0-23802 | ||||||||||||||||||
326 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
327 | - | |||||||||||||||||||
328 | if (!BN_bin2bn(buf + 1, field_len, x))
| 0-23802 | ||||||||||||||||||
329 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
330 | if (BN_ucmp(x, group->field) >= 0) {
| 91-23711 | ||||||||||||||||||
331 | ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); | - | ||||||||||||||||||
332 | goto err; executed 91 times by 1 test: goto err; Executed by:
| 91 | ||||||||||||||||||
333 | } | - | ||||||||||||||||||
334 | - | |||||||||||||||||||
335 | if (form == POINT_CONVERSION_COMPRESSED) {
| 4520-19191 | ||||||||||||||||||
336 | if (!EC_POINT_set_compressed_coordinates(group, point, x, y_bit, ctx))
| 1279-3241 | ||||||||||||||||||
337 | goto err; executed 1279 times by 1 test: goto err; Executed by:
| 1279 | ||||||||||||||||||
338 | } else { executed 3241 times by 1 test: end of block Executed by:
| 3241 | ||||||||||||||||||
339 | if (!BN_bin2bn(buf + 1 + field_len, field_len, y))
| 0-19191 | ||||||||||||||||||
340 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
341 | if (BN_ucmp(y, group->field) >= 0) {
| 84-19107 | ||||||||||||||||||
342 | ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); | - | ||||||||||||||||||
343 | goto err; executed 84 times by 1 test: goto err; Executed by:
| 84 | ||||||||||||||||||
344 | } | - | ||||||||||||||||||
345 | if (form == POINT_CONVERSION_HYBRID) {
| 173-18934 | ||||||||||||||||||
346 | if (y_bit != BN_is_odd(y)) {
| 73-100 | ||||||||||||||||||
347 | ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); | - | ||||||||||||||||||
348 | goto err; executed 73 times by 1 test: goto err; Executed by:
| 73 | ||||||||||||||||||
349 | } | - | ||||||||||||||||||
350 | } executed 100 times by 1 test: end of block Executed by:
| 100 | ||||||||||||||||||
351 | - | |||||||||||||||||||
352 | /* | - | ||||||||||||||||||
353 | * EC_POINT_set_affine_coordinates is responsible for checking that | - | ||||||||||||||||||
354 | * the point is on the curve. | - | ||||||||||||||||||
355 | */ | - | ||||||||||||||||||
356 | if (!EC_POINT_set_affine_coordinates(group, point, x, y, ctx))
| 479-18555 | ||||||||||||||||||
357 | goto err; executed 479 times by 1 test: goto err; Executed by:
| 479 | ||||||||||||||||||
358 | } executed 18555 times by 1 test: end of block Executed by:
| 18555 | ||||||||||||||||||
359 | - | |||||||||||||||||||
360 | ret = 1; | - | ||||||||||||||||||
361 | - | |||||||||||||||||||
362 | err: code before this statement executed 21796 times by 1 test: err: Executed by:
| 21796 | ||||||||||||||||||
363 | BN_CTX_end(ctx); | - | ||||||||||||||||||
364 | BN_CTX_free(new_ctx); | - | ||||||||||||||||||
365 | return ret; executed 23802 times by 1 test: return ret; Executed by:
| 23802 | ||||||||||||||||||
366 | } | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |