diff options
| author | beck <> | 2017-01-29 17:49:23 +0000 |
|---|---|---|
| committer | beck <> | 2017-01-29 17:49:23 +0000 |
| commit | d1f47bd292f36094480caa49ada36b99a69c59b0 (patch) | |
| tree | 1a54abba678898ee5270ae4f3404a50ee9a92eea /src/lib/libcrypto/ec/ec_key.c | |
| parent | f8c627888330b75c2eea8a3c27d0efe947a4f9da (diff) | |
| download | openbsd-d1f47bd292f36094480caa49ada36b99a69c59b0.tar.gz openbsd-d1f47bd292f36094480caa49ada36b99a69c59b0.tar.bz2 openbsd-d1f47bd292f36094480caa49ada36b99a69c59b0.zip | |
Send the function codes from the error functions to the bit bucket,
as was done earlier in libssl. Thanks inoguchi@ for noticing
libssl had more reacharounds into this.
ok jsing@ inoguchi@
Diffstat (limited to 'src/lib/libcrypto/ec/ec_key.c')
| -rw-r--r-- | src/lib/libcrypto/ec/ec_key.c | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/src/lib/libcrypto/ec/ec_key.c b/src/lib/libcrypto/ec/ec_key.c index fa962e4d0f..5a23a9823d 100644 --- a/src/lib/libcrypto/ec/ec_key.c +++ b/src/lib/libcrypto/ec/ec_key.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: ec_key.c,v 1.12 2015/09/10 15:56:25 jsing Exp $ */ | 1 | /* $OpenBSD: ec_key.c,v 1.13 2017/01/29 17:49:23 beck Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Written by Nils Larsch for the OpenSSL project. | 3 | * Written by Nils Larsch for the OpenSSL project. |
| 4 | */ | 4 | */ |
| @@ -75,7 +75,7 @@ EC_KEY_new(void) | |||
| 75 | 75 | ||
| 76 | ret = malloc(sizeof(EC_KEY)); | 76 | ret = malloc(sizeof(EC_KEY)); |
| 77 | if (ret == NULL) { | 77 | if (ret == NULL) { |
| 78 | ECerr(EC_F_EC_KEY_NEW, ERR_R_MALLOC_FAILURE); | 78 | ECerror(ERR_R_MALLOC_FAILURE); |
| 79 | return (NULL); | 79 | return (NULL); |
| 80 | } | 80 | } |
| 81 | ret->version = 1; | 81 | ret->version = 1; |
| @@ -133,7 +133,7 @@ EC_KEY_copy(EC_KEY * dest, const EC_KEY * src) | |||
| 133 | EC_EXTRA_DATA *d; | 133 | EC_EXTRA_DATA *d; |
| 134 | 134 | ||
| 135 | if (dest == NULL || src == NULL) { | 135 | if (dest == NULL || src == NULL) { |
| 136 | ECerr(EC_F_EC_KEY_COPY, ERR_R_PASSED_NULL_PARAMETER); | 136 | ECerror(ERR_R_PASSED_NULL_PARAMETER); |
| 137 | return NULL; | 137 | return NULL; |
| 138 | } | 138 | } |
| 139 | /* copy the parameters */ | 139 | /* copy the parameters */ |
| @@ -217,7 +217,7 @@ EC_KEY_generate_key(EC_KEY * eckey) | |||
| 217 | EC_POINT *pub_key = NULL; | 217 | EC_POINT *pub_key = NULL; |
| 218 | 218 | ||
| 219 | if (!eckey || !eckey->group) { | 219 | if (!eckey || !eckey->group) { |
| 220 | ECerr(EC_F_EC_KEY_GENERATE_KEY, ERR_R_PASSED_NULL_PARAMETER); | 220 | ECerror(ERR_R_PASSED_NULL_PARAMETER); |
| 221 | return 0; | 221 | return 0; |
| 222 | } | 222 | } |
| 223 | if ((order = BN_new()) == NULL) | 223 | if ((order = BN_new()) == NULL) |
| @@ -274,11 +274,11 @@ EC_KEY_check_key(const EC_KEY * eckey) | |||
| 274 | EC_POINT *point = NULL; | 274 | EC_POINT *point = NULL; |
| 275 | 275 | ||
| 276 | if (!eckey || !eckey->group || !eckey->pub_key) { | 276 | if (!eckey || !eckey->group || !eckey->pub_key) { |
| 277 | ECerr(EC_F_EC_KEY_CHECK_KEY, ERR_R_PASSED_NULL_PARAMETER); | 277 | ECerror(ERR_R_PASSED_NULL_PARAMETER); |
| 278 | return 0; | 278 | return 0; |
| 279 | } | 279 | } |
| 280 | if (EC_POINT_is_at_infinity(eckey->group, eckey->pub_key) > 0) { | 280 | if (EC_POINT_is_at_infinity(eckey->group, eckey->pub_key) > 0) { |
| 281 | ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_POINT_AT_INFINITY); | 281 | ECerror(EC_R_POINT_AT_INFINITY); |
| 282 | goto err; | 282 | goto err; |
| 283 | } | 283 | } |
| 284 | if ((ctx = BN_CTX_new()) == NULL) | 284 | if ((ctx = BN_CTX_new()) == NULL) |
| @@ -288,21 +288,21 @@ EC_KEY_check_key(const EC_KEY * eckey) | |||
| 288 | 288 | ||
| 289 | /* testing whether the pub_key is on the elliptic curve */ | 289 | /* testing whether the pub_key is on the elliptic curve */ |
| 290 | if (EC_POINT_is_on_curve(eckey->group, eckey->pub_key, ctx) <= 0) { | 290 | if (EC_POINT_is_on_curve(eckey->group, eckey->pub_key, ctx) <= 0) { |
| 291 | ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_POINT_IS_NOT_ON_CURVE); | 291 | ECerror(EC_R_POINT_IS_NOT_ON_CURVE); |
| 292 | goto err; | 292 | goto err; |
| 293 | } | 293 | } |
| 294 | /* testing whether pub_key * order is the point at infinity */ | 294 | /* testing whether pub_key * order is the point at infinity */ |
| 295 | order = &eckey->group->order; | 295 | order = &eckey->group->order; |
| 296 | if (BN_is_zero(order)) { | 296 | if (BN_is_zero(order)) { |
| 297 | ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_INVALID_GROUP_ORDER); | 297 | ECerror(EC_R_INVALID_GROUP_ORDER); |
| 298 | goto err; | 298 | goto err; |
| 299 | } | 299 | } |
| 300 | if (!EC_POINT_mul(eckey->group, point, NULL, eckey->pub_key, order, ctx)) { | 300 | if (!EC_POINT_mul(eckey->group, point, NULL, eckey->pub_key, order, ctx)) { |
| 301 | ECerr(EC_F_EC_KEY_CHECK_KEY, ERR_R_EC_LIB); | 301 | ECerror(ERR_R_EC_LIB); |
| 302 | goto err; | 302 | goto err; |
| 303 | } | 303 | } |
| 304 | if (EC_POINT_is_at_infinity(eckey->group, point) <= 0) { | 304 | if (EC_POINT_is_at_infinity(eckey->group, point) <= 0) { |
| 305 | ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_WRONG_ORDER); | 305 | ECerror(EC_R_WRONG_ORDER); |
| 306 | goto err; | 306 | goto err; |
| 307 | } | 307 | } |
| 308 | /* | 308 | /* |
| @@ -311,17 +311,17 @@ EC_KEY_check_key(const EC_KEY * eckey) | |||
| 311 | */ | 311 | */ |
| 312 | if (eckey->priv_key) { | 312 | if (eckey->priv_key) { |
| 313 | if (BN_cmp(eckey->priv_key, order) >= 0) { | 313 | if (BN_cmp(eckey->priv_key, order) >= 0) { |
| 314 | ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_WRONG_ORDER); | 314 | ECerror(EC_R_WRONG_ORDER); |
| 315 | goto err; | 315 | goto err; |
| 316 | } | 316 | } |
| 317 | if (!EC_POINT_mul(eckey->group, point, eckey->priv_key, | 317 | if (!EC_POINT_mul(eckey->group, point, eckey->priv_key, |
| 318 | NULL, NULL, ctx)) { | 318 | NULL, NULL, ctx)) { |
| 319 | ECerr(EC_F_EC_KEY_CHECK_KEY, ERR_R_EC_LIB); | 319 | ECerror(ERR_R_EC_LIB); |
| 320 | goto err; | 320 | goto err; |
| 321 | } | 321 | } |
| 322 | if (EC_POINT_cmp(eckey->group, point, eckey->pub_key, | 322 | if (EC_POINT_cmp(eckey->group, point, eckey->pub_key, |
| 323 | ctx) != 0) { | 323 | ctx) != 0) { |
| 324 | ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_INVALID_PRIVATE_KEY); | 324 | ECerror(EC_R_INVALID_PRIVATE_KEY); |
| 325 | goto err; | 325 | goto err; |
| 326 | } | 326 | } |
| 327 | } | 327 | } |
| @@ -341,8 +341,7 @@ EC_KEY_set_public_key_affine_coordinates(EC_KEY * key, BIGNUM * x, BIGNUM * y) | |||
| 341 | int ok = 0, tmp_nid, is_char_two = 0; | 341 | int ok = 0, tmp_nid, is_char_two = 0; |
| 342 | 342 | ||
| 343 | if (!key || !key->group || !x || !y) { | 343 | if (!key || !key->group || !x || !y) { |
| 344 | ECerr(EC_F_EC_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES, | 344 | ECerror(ERR_R_PASSED_NULL_PARAMETER); |
| 345 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 346 | return 0; | 345 | return 0; |
| 347 | } | 346 | } |
| 348 | ctx = BN_CTX_new(); | 347 | ctx = BN_CTX_new(); |
| @@ -387,8 +386,7 @@ EC_KEY_set_public_key_affine_coordinates(EC_KEY * key, BIGNUM * x, BIGNUM * y) | |||
| 387 | * out of range. | 386 | * out of range. |
| 388 | */ | 387 | */ |
| 389 | if (BN_cmp(x, tx) || BN_cmp(y, ty)) { | 388 | if (BN_cmp(x, tx) || BN_cmp(y, ty)) { |
| 390 | ECerr(EC_F_EC_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES, | 389 | ECerror(EC_R_COORDINATES_OUT_OF_RANGE); |
| 391 | EC_R_COORDINATES_OUT_OF_RANGE); | ||
| 392 | goto err; | 390 | goto err; |
| 393 | } | 391 | } |
| 394 | if (!EC_KEY_set_public_key(key, point)) | 392 | if (!EC_KEY_set_public_key(key, point)) |
