| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/ec/ec2_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 | - | |||||||||||||||||||
| 13 | #include "ec_lcl.h" | - | ||||||||||||||||||
| 14 | - | |||||||||||||||||||
| 15 | #ifndef OPENSSL_NO_EC2M | - | ||||||||||||||||||
| 16 | - | |||||||||||||||||||
| 17 | /*- | - | ||||||||||||||||||
| 18 | * Calculates and sets the affine coordinates of an EC_POINT from the given | - | ||||||||||||||||||
| 19 | * compressed coordinates. Uses algorithm 2.3.4 of SEC 1. | - | ||||||||||||||||||
| 20 | * Note that the simple implementation only uses affine coordinates. | - | ||||||||||||||||||
| 21 | * | - | ||||||||||||||||||
| 22 | * The method is from the following publication: | - | ||||||||||||||||||
| 23 | * | - | ||||||||||||||||||
| 24 | * Harper, Menezes, Vanstone: | - | ||||||||||||||||||
| 25 | * "Public-Key Cryptosystems with Very Small Key Lengths", | - | ||||||||||||||||||
| 26 | * EUROCRYPT '92, Springer-Verlag LNCS 658, | - | ||||||||||||||||||
| 27 | * published February 1993 | - | ||||||||||||||||||
| 28 | * | - | ||||||||||||||||||
| 29 | * US Patents 6,141,420 and 6,618,483 (Vanstone, Mullin, Agnew) describe | - | ||||||||||||||||||
| 30 | * the same method, but claim no priority date earlier than July 29, 1994 | - | ||||||||||||||||||
| 31 | * (and additionally fail to cite the EUROCRYPT '92 publication as prior art). | - | ||||||||||||||||||
| 32 | */ | - | ||||||||||||||||||
| 33 | int ec_GF2m_simple_set_compressed_coordinates(const EC_GROUP *group, | - | ||||||||||||||||||
| 34 | EC_POINT *point, | - | ||||||||||||||||||
| 35 | const BIGNUM *x_, int y_bit, | - | ||||||||||||||||||
| 36 | BN_CTX *ctx) | - | ||||||||||||||||||
| 37 | { | - | ||||||||||||||||||
| 38 | BN_CTX *new_ctx = NULL; | - | ||||||||||||||||||
| 39 | BIGNUM *tmp, *x, *y, *z; | - | ||||||||||||||||||
| 40 | int ret = 0, z0; | - | ||||||||||||||||||
| 41 | - | |||||||||||||||||||
| 42 | /* clear error queue */ | - | ||||||||||||||||||
| 43 | ERR_clear_error(); | - | ||||||||||||||||||
| 44 | - | |||||||||||||||||||
| 45 | if (ctx == NULL) {
| 0-6045 | ||||||||||||||||||
| 46 | ctx = new_ctx = BN_CTX_new(); | - | ||||||||||||||||||
| 47 | if (ctx == NULL)
| 0 | ||||||||||||||||||
| 48 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 49 | } never executed: end of block | 0 | ||||||||||||||||||
| 50 | - | |||||||||||||||||||
| 51 | y_bit = (y_bit != 0) ? 1 : 0;
| 291-5754 | ||||||||||||||||||
| 52 | - | |||||||||||||||||||
| 53 | BN_CTX_start(ctx); | - | ||||||||||||||||||
| 54 | tmp = BN_CTX_get(ctx); | - | ||||||||||||||||||
| 55 | x = BN_CTX_get(ctx); | - | ||||||||||||||||||
| 56 | y = BN_CTX_get(ctx); | - | ||||||||||||||||||
| 57 | z = BN_CTX_get(ctx); | - | ||||||||||||||||||
| 58 | if (z == NULL)
| 0-6045 | ||||||||||||||||||
| 59 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 60 | - | |||||||||||||||||||
| 61 | if (!BN_GF2m_mod_arr(x, x_, group->poly))
| 0-6045 | ||||||||||||||||||
| 62 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 63 | if (BN_is_zero(x)) {
| 1111-4934 | ||||||||||||||||||
| 64 | if (!BN_GF2m_mod_sqrt_arr(y, group->b, group->poly, ctx))
| 0-1111 | ||||||||||||||||||
| 65 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 66 | } else { executed 1111 times by 1 test: end of blockExecuted by:
| 1111 | ||||||||||||||||||
| 67 | if (!group->meth->field_sqr(group, tmp, x, ctx))
| 0-4934 | ||||||||||||||||||
| 68 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 69 | if (!group->meth->field_div(group, tmp, group->b, tmp, ctx))
| 0-4934 | ||||||||||||||||||
| 70 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 71 | if (!BN_GF2m_add(tmp, group->a, tmp))
| 0-4934 | ||||||||||||||||||
| 72 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 73 | if (!BN_GF2m_add(tmp, x, tmp))
| 0-4934 | ||||||||||||||||||
| 74 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 75 | if (!BN_GF2m_mod_solve_quad_arr(z, tmp, group->poly, ctx)) {
| 2314-2620 | ||||||||||||||||||
| 76 | unsigned long err = ERR_peek_last_error(); | - | ||||||||||||||||||
| 77 | - | |||||||||||||||||||
| 78 | if (ERR_GET_LIB(err) == ERR_LIB_BN
| 0-2314 | ||||||||||||||||||
| 79 | && ERR_GET_REASON(err) == BN_R_NO_SOLUTION) {
| 831-1483 | ||||||||||||||||||
| 80 | ERR_clear_error(); | - | ||||||||||||||||||
| 81 | ECerr(EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES, | - | ||||||||||||||||||
| 82 | EC_R_INVALID_COMPRESSED_POINT); | - | ||||||||||||||||||
| 83 | } else executed 1483 times by 1 test: end of blockExecuted by:
| 1483 | ||||||||||||||||||
| 84 | ECerr(EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES, executed 831 times by 1 test: ERR_put_error(16,(164),(3),__FILE__,85) ;Executed by:
| 831 | ||||||||||||||||||
| 85 | ERR_R_BN_LIB); executed 831 times by 1 test: ERR_put_error(16,(164),(3),__FILE__,85) ;Executed by:
| 831 | ||||||||||||||||||
| 86 | goto err; executed 2314 times by 1 test: goto err;Executed by:
| 2314 | ||||||||||||||||||
| 87 | } | - | ||||||||||||||||||
| 88 | z0 = (BN_is_odd(z)) ? 1 : 0;
| 109-2511 | ||||||||||||||||||
| 89 | if (!group->meth->field_mul(group, y, x, z, ctx))
| 0-2620 | ||||||||||||||||||
| 90 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 91 | if (z0 != y_bit) {
| 218-2402 | ||||||||||||||||||
| 92 | if (!BN_GF2m_add(y, y, x))
| 0-2402 | ||||||||||||||||||
| 93 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 94 | } executed 2402 times by 1 test: end of blockExecuted by:
| 2402 | ||||||||||||||||||
| 95 | } executed 2620 times by 1 test: end of blockExecuted by:
| 2620 | ||||||||||||||||||
| 96 | - | |||||||||||||||||||
| 97 | if (!EC_POINT_set_affine_coordinates(group, point, x, y, ctx))
| 0-3731 | ||||||||||||||||||
| 98 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 99 | - | |||||||||||||||||||
| 100 | ret = 1; | - | ||||||||||||||||||
| 101 | - | |||||||||||||||||||
| 102 | err: code before this statement executed 3731 times by 1 test: err:Executed by:
| 3731 | ||||||||||||||||||
| 103 | BN_CTX_end(ctx); | - | ||||||||||||||||||
| 104 | BN_CTX_free(new_ctx); | - | ||||||||||||||||||
| 105 | return ret; executed 6045 times by 1 test: return ret;Executed by:
| 6045 | ||||||||||||||||||
| 106 | } | - | ||||||||||||||||||
| 107 | - | |||||||||||||||||||
| 108 | /* | - | ||||||||||||||||||
| 109 | * Converts an EC_POINT to an octet string. If buf is NULL, the encoded | - | ||||||||||||||||||
| 110 | * length will be returned. If the length len of buf is smaller than required | - | ||||||||||||||||||
| 111 | * an error will be returned. | - | ||||||||||||||||||
| 112 | */ | - | ||||||||||||||||||
| 113 | size_t ec_GF2m_simple_point2oct(const EC_GROUP *group, const EC_POINT *point, | - | ||||||||||||||||||
| 114 | point_conversion_form_t form, | - | ||||||||||||||||||
| 115 | unsigned char *buf, size_t len, BN_CTX *ctx) | - | ||||||||||||||||||
| 116 | { | - | ||||||||||||||||||
| 117 | size_t ret; | - | ||||||||||||||||||
| 118 | BN_CTX *new_ctx = NULL; | - | ||||||||||||||||||
| 119 | int used_ctx = 0; | - | ||||||||||||||||||
| 120 | BIGNUM *x, *y, *yxi; | - | ||||||||||||||||||
| 121 | size_t field_len, i, skip; | - | ||||||||||||||||||
| 122 | - | |||||||||||||||||||
| 123 | if ((form != POINT_CONVERSION_COMPRESSED)
| 32-169 | ||||||||||||||||||
| 124 | && (form != POINT_CONVERSION_UNCOMPRESSED)
| 3-166 | ||||||||||||||||||
| 125 | && (form != POINT_CONVERSION_HYBRID)) {
| 1-2 | ||||||||||||||||||
| 126 | ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, EC_R_INVALID_FORM); | - | ||||||||||||||||||
| 127 | goto err; executed 1 time by 1 test: goto err;Executed by:
| 1 | ||||||||||||||||||
| 128 | } | - | ||||||||||||||||||
| 129 | - | |||||||||||||||||||
| 130 | if (EC_POINT_is_at_infinity(group, point)) {
| 14-186 | ||||||||||||||||||
| 131 | /* encodes to a single 0 octet */ | - | ||||||||||||||||||
| 132 | if (buf != NULL) {
| 7 | ||||||||||||||||||
| 133 | if (len < 1) {
| 0-7 | ||||||||||||||||||
| 134 | ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, EC_R_BUFFER_TOO_SMALL); | - | ||||||||||||||||||
| 135 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 136 | } | - | ||||||||||||||||||
| 137 | buf[0] = 0; | - | ||||||||||||||||||
| 138 | } executed 7 times by 1 test: end of blockExecuted by:
| 7 | ||||||||||||||||||
| 139 | return 1; executed 14 times by 1 test: return 1;Executed by:
| 14 | ||||||||||||||||||
| 140 | } | - | ||||||||||||||||||
| 141 | - | |||||||||||||||||||
| 142 | /* ret := required output buffer length */ | - | ||||||||||||||||||
| 143 | field_len = (EC_GROUP_get_degree(group) + 7) / 8; | - | ||||||||||||||||||
| 144 | ret = | - | ||||||||||||||||||
| 145 | (form ==
| 32-154 | ||||||||||||||||||
| 146 | POINT_CONVERSION_COMPRESSED) ? 1 + field_len : 1 + 2 * field_len;
| 32-154 | ||||||||||||||||||
| 147 | - | |||||||||||||||||||
| 148 | /* if 'buf' is NULL, just return required length */ | - | ||||||||||||||||||
| 149 | if (buf != NULL) {
| 93 | ||||||||||||||||||
| 150 | if (len < ret) {
| 0-93 | ||||||||||||||||||
| 151 | ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, EC_R_BUFFER_TOO_SMALL); | - | ||||||||||||||||||
| 152 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 153 | } | - | ||||||||||||||||||
| 154 | - | |||||||||||||||||||
| 155 | if (ctx == NULL) {
| 1-92 | ||||||||||||||||||
| 156 | ctx = new_ctx = BN_CTX_new(); | - | ||||||||||||||||||
| 157 | if (ctx == NULL)
| 0-92 | ||||||||||||||||||
| 158 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 159 | } executed 92 times by 1 test: end of blockExecuted by:
| 92 | ||||||||||||||||||
| 160 | - | |||||||||||||||||||
| 161 | BN_CTX_start(ctx); | - | ||||||||||||||||||
| 162 | used_ctx = 1; | - | ||||||||||||||||||
| 163 | x = BN_CTX_get(ctx); | - | ||||||||||||||||||
| 164 | y = BN_CTX_get(ctx); | - | ||||||||||||||||||
| 165 | yxi = BN_CTX_get(ctx); | - | ||||||||||||||||||
| 166 | if (yxi == NULL)
| 0-93 | ||||||||||||||||||
| 167 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 168 | - | |||||||||||||||||||
| 169 | if (!EC_POINT_get_affine_coordinates(group, point, x, y, ctx))
| 0-93 | ||||||||||||||||||
| 170 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 171 | - | |||||||||||||||||||
| 172 | buf[0] = form; | - | ||||||||||||||||||
| 173 | if ((form != POINT_CONVERSION_UNCOMPRESSED) && !BN_is_zero(x)) {
| 1-76 | ||||||||||||||||||
| 174 | if (!group->meth->field_div(group, yxi, y, x, ctx))
| 0-16 | ||||||||||||||||||
| 175 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 176 | if (BN_is_odd(yxi))
| 7-9 | ||||||||||||||||||
| 177 | buf[0]++; executed 7 times by 1 test: buf[0]++;Executed by:
| 7 | ||||||||||||||||||
| 178 | } executed 16 times by 1 test: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 179 | - | |||||||||||||||||||
| 180 | i = 1; | - | ||||||||||||||||||
| 181 | - | |||||||||||||||||||
| 182 | skip = field_len - BN_num_bytes(x); | - | ||||||||||||||||||
| 183 | if (skip > field_len) {
| 0-93 | ||||||||||||||||||
| 184 | ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR); | - | ||||||||||||||||||
| 185 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 186 | } | - | ||||||||||||||||||
| 187 | while (skip > 0) {
| 93-246 | ||||||||||||||||||
| 188 | buf[i++] = 0; | - | ||||||||||||||||||
| 189 | skip--; | - | ||||||||||||||||||
| 190 | } executed 246 times by 1 test: end of blockExecuted by:
| 246 | ||||||||||||||||||
| 191 | skip = BN_bn2bin(x, buf + i); | - | ||||||||||||||||||
| 192 | i += skip; | - | ||||||||||||||||||
| 193 | if (i != 1 + field_len) {
| 0-93 | ||||||||||||||||||
| 194 | ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR); | - | ||||||||||||||||||
| 195 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 196 | } | - | ||||||||||||||||||
| 197 | - | |||||||||||||||||||
| 198 | if (form == POINT_CONVERSION_UNCOMPRESSED
| 17-76 | ||||||||||||||||||
| 199 | || form == POINT_CONVERSION_HYBRID) {
| 1-16 | ||||||||||||||||||
| 200 | skip = field_len - BN_num_bytes(y); | - | ||||||||||||||||||
| 201 | if (skip > field_len) {
| 0-77 | ||||||||||||||||||
| 202 | ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR); | - | ||||||||||||||||||
| 203 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 204 | } | - | ||||||||||||||||||
| 205 | while (skip > 0) {
| 77-94 | ||||||||||||||||||
| 206 | buf[i++] = 0; | - | ||||||||||||||||||
| 207 | skip--; | - | ||||||||||||||||||
| 208 | } executed 94 times by 1 test: end of blockExecuted by:
| 94 | ||||||||||||||||||
| 209 | skip = BN_bn2bin(y, buf + i); | - | ||||||||||||||||||
| 210 | i += skip; | - | ||||||||||||||||||
| 211 | } executed 77 times by 1 test: end of blockExecuted by:
| 77 | ||||||||||||||||||
| 212 | - | |||||||||||||||||||
| 213 | if (i != ret) {
| 0-93 | ||||||||||||||||||
| 214 | ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR); | - | ||||||||||||||||||
| 215 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 216 | } | - | ||||||||||||||||||
| 217 | } executed 93 times by 1 test: end of blockExecuted by:
| 93 | ||||||||||||||||||
| 218 | - | |||||||||||||||||||
| 219 | if (used_ctx)
| 93 | ||||||||||||||||||
| 220 | BN_CTX_end(ctx); executed 93 times by 1 test: BN_CTX_end(ctx);Executed by:
| 93 | ||||||||||||||||||
| 221 | BN_CTX_free(new_ctx); | - | ||||||||||||||||||
| 222 | return ret; executed 186 times by 1 test: return ret;Executed by:
| 186 | ||||||||||||||||||
| 223 | - | |||||||||||||||||||
| 224 | err: | - | ||||||||||||||||||
| 225 | if (used_ctx)
| 0-1 | ||||||||||||||||||
| 226 | BN_CTX_end(ctx); never executed: BN_CTX_end(ctx); | 0 | ||||||||||||||||||
| 227 | BN_CTX_free(new_ctx); | - | ||||||||||||||||||
| 228 | return 0; executed 1 time by 1 test: return 0;Executed by:
| 1 | ||||||||||||||||||
| 229 | } | - | ||||||||||||||||||
| 230 | - | |||||||||||||||||||
| 231 | /* | - | ||||||||||||||||||
| 232 | * Converts an octet string representation to an EC_POINT. Note that the | - | ||||||||||||||||||
| 233 | * simple implementation only uses affine coordinates. | - | ||||||||||||||||||
| 234 | */ | - | ||||||||||||||||||
| 235 | int ec_GF2m_simple_oct2point(const EC_GROUP *group, EC_POINT *point, | - | ||||||||||||||||||
| 236 | const unsigned char *buf, size_t len, | - | ||||||||||||||||||
| 237 | BN_CTX *ctx) | - | ||||||||||||||||||
| 238 | { | - | ||||||||||||||||||
| 239 | point_conversion_form_t form; | - | ||||||||||||||||||
| 240 | int y_bit; | - | ||||||||||||||||||
| 241 | BN_CTX *new_ctx = NULL; | - | ||||||||||||||||||
| 242 | BIGNUM *x, *y, *yxi; | - | ||||||||||||||||||
| 243 | size_t field_len, enc_len; | - | ||||||||||||||||||
| 244 | int ret = 0; | - | ||||||||||||||||||
| 245 | - | |||||||||||||||||||
| 246 | if (len == 0) {
| 80-9189 | ||||||||||||||||||
| 247 | ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_BUFFER_TOO_SMALL); | - | ||||||||||||||||||
| 248 | return 0; executed 80 times by 1 test: return 0;Executed by:
| 80 | ||||||||||||||||||
| 249 | } | - | ||||||||||||||||||
| 250 | form = buf[0]; | - | ||||||||||||||||||
| 251 | y_bit = form & 1; | - | ||||||||||||||||||
| 252 | form = form & ~1U; | - | ||||||||||||||||||
| 253 | if ((form != 0) && (form != POINT_CONVERSION_COMPRESSED)
| 348-8841 | ||||||||||||||||||
| 254 | && (form != POINT_CONVERSION_UNCOMPRESSED)
| 1213-1271 | ||||||||||||||||||
| 255 | && (form != POINT_CONVERSION_HYBRID)) {
| 572-641 | ||||||||||||||||||
| 256 | ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); | - | ||||||||||||||||||
| 257 | return 0; executed 572 times by 1 test: return 0;Executed by:
| 572 | ||||||||||||||||||
| 258 | } | - | ||||||||||||||||||
| 259 | if ((form == 0 || form == POINT_CONVERSION_UNCOMPRESSED) && y_bit) {
| 75-8269 | ||||||||||||||||||
| 260 | ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); | - | ||||||||||||||||||
| 261 | return 0; executed 75 times by 1 test: return 0;Executed by:
| 75 | ||||||||||||||||||
| 262 | } | - | ||||||||||||||||||
| 263 | - | |||||||||||||||||||
| 264 | if (form == 0) {
| 274-8268 | ||||||||||||||||||
| 265 | if (len != 1) {
| 77-197 | ||||||||||||||||||
| 266 | ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); | - | ||||||||||||||||||
| 267 | return 0; executed 77 times by 1 test: return 0;Executed by:
| 77 | ||||||||||||||||||
| 268 | } | - | ||||||||||||||||||
| 269 | - | |||||||||||||||||||
| 270 | return EC_POINT_set_to_infinity(group, point); executed 197 times by 1 test: return EC_POINT_set_to_infinity(group, point);Executed by:
| 197 | ||||||||||||||||||
| 271 | } | - | ||||||||||||||||||
| 272 | - | |||||||||||||||||||
| 273 | field_len = (EC_GROUP_get_degree(group) + 7) / 8; | - | ||||||||||||||||||
| 274 | enc_len = | - | ||||||||||||||||||
| 275 | (form ==
| 1911-6357 | ||||||||||||||||||
| 276 | POINT_CONVERSION_COMPRESSED) ? 1 + field_len : 1 + 2 * field_len;
| 1911-6357 | ||||||||||||||||||
| 277 | - | |||||||||||||||||||
| 278 | if (len != enc_len) {
| 258-8010 | ||||||||||||||||||
| 279 | ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); | - | ||||||||||||||||||
| 280 | return 0; executed 258 times by 1 test: return 0;Executed by:
| 258 | ||||||||||||||||||
| 281 | } | - | ||||||||||||||||||
| 282 | - | |||||||||||||||||||
| 283 | if (ctx == NULL) {
| 1-8009 | ||||||||||||||||||
| 284 | ctx = new_ctx = BN_CTX_new(); | - | ||||||||||||||||||
| 285 | if (ctx == NULL)
| 0-8009 | ||||||||||||||||||
| 286 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 287 | } executed 8009 times by 1 test: end of blockExecuted by:
| 8009 | ||||||||||||||||||
| 288 | - | |||||||||||||||||||
| 289 | BN_CTX_start(ctx); | - | ||||||||||||||||||
| 290 | x = BN_CTX_get(ctx); | - | ||||||||||||||||||
| 291 | y = BN_CTX_get(ctx); | - | ||||||||||||||||||
| 292 | yxi = BN_CTX_get(ctx); | - | ||||||||||||||||||
| 293 | if (yxi == NULL)
| 0-8010 | ||||||||||||||||||
| 294 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 295 | - | |||||||||||||||||||
| 296 | if (!BN_bin2bn(buf + 1, field_len, x))
| 0-8010 | ||||||||||||||||||
| 297 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 298 | if (BN_ucmp(x, group->field) >= 0) {
| 92-7918 | ||||||||||||||||||
| 299 | ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); | - | ||||||||||||||||||
| 300 | goto err; executed 92 times by 1 test: goto err;Executed by:
| 92 | ||||||||||||||||||
| 301 | } | - | ||||||||||||||||||
| 302 | - | |||||||||||||||||||
| 303 | if (form == POINT_CONVERSION_COMPRESSED) {
| 1873-6045 | ||||||||||||||||||
| 304 | if (!EC_POINT_set_compressed_coordinates(group, point, x, y_bit, ctx))
| 2314-3731 | ||||||||||||||||||
| 305 | goto err; executed 2314 times by 1 test: goto err;Executed by:
| 2314 | ||||||||||||||||||
| 306 | } else { executed 3731 times by 1 test: end of blockExecuted by:
| 3731 | ||||||||||||||||||
| 307 | if (!BN_bin2bn(buf + 1 + field_len, field_len, y))
| 0-1873 | ||||||||||||||||||
| 308 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 309 | if (BN_ucmp(y, group->field) >= 0) {
| 73-1800 | ||||||||||||||||||
| 310 | ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); | - | ||||||||||||||||||
| 311 | goto err; executed 73 times by 1 test: goto err;Executed by:
| 73 | ||||||||||||||||||
| 312 | } | - | ||||||||||||||||||
| 313 | if (form == POINT_CONVERSION_HYBRID) {
| 566-1234 | ||||||||||||||||||
| 314 | if (!group->meth->field_div(group, yxi, y, x, ctx))
| 77-489 | ||||||||||||||||||
| 315 | goto err; executed 77 times by 1 test: goto err;Executed by:
| 77 | ||||||||||||||||||
| 316 | if (y_bit != BN_is_odd(yxi)) {
| 98-391 | ||||||||||||||||||
| 317 | ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); | - | ||||||||||||||||||
| 318 | goto err; executed 98 times by 1 test: goto err;Executed by:
| 98 | ||||||||||||||||||
| 319 | } | - | ||||||||||||||||||
| 320 | } executed 391 times by 1 test: end of blockExecuted by:
| 391 | ||||||||||||||||||
| 321 | - | |||||||||||||||||||
| 322 | /* | - | ||||||||||||||||||
| 323 | * EC_POINT_set_affine_coordinates is responsible for checking that | - | ||||||||||||||||||
| 324 | * the point is on the curve. | - | ||||||||||||||||||
| 325 | */ | - | ||||||||||||||||||
| 326 | if (!EC_POINT_set_affine_coordinates(group, point, x, y, ctx))
| 516-1109 | ||||||||||||||||||
| 327 | goto err; executed 516 times by 1 test: goto err;Executed by:
| 516 | ||||||||||||||||||
| 328 | } executed 1109 times by 1 test: end of blockExecuted by:
| 1109 | ||||||||||||||||||
| 329 | - | |||||||||||||||||||
| 330 | ret = 1; | - | ||||||||||||||||||
| 331 | - | |||||||||||||||||||
| 332 | err: code before this statement executed 4840 times by 1 test: err:Executed by:
| 4840 | ||||||||||||||||||
| 333 | BN_CTX_end(ctx); | - | ||||||||||||||||||
| 334 | BN_CTX_free(new_ctx); | - | ||||||||||||||||||
| 335 | return ret; executed 8010 times by 1 test: return ret;Executed by:
| 8010 | ||||||||||||||||||
| 336 | } | - | ||||||||||||||||||
| 337 | #endif | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |