summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2023-07-05 17:10:10 +0000
committertb <>2023-07-05 17:10:10 +0000
commit2a76217befc26467e87c42042da9454d58534279 (patch)
treebe7dc4e8b1becfb90622fefb3c36d1fdf7944ecd /src/lib
parentc4bfc0e4179fecf1860de6c28fc5231081bad078 (diff)
downloadopenbsd-2a76217befc26467e87c42042da9454d58534279.tar.gz
openbsd-2a76217befc26467e87c42042da9454d58534279.tar.bz2
openbsd-2a76217befc26467e87c42042da9454d58534279.zip
Mop up last uses of ECDHerror() and ECDSAerror()
ok jsing
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/ec/ec.h7
-rw-r--r--src/lib/libcrypto/ec/ec_err.c7
-rw-r--r--src/lib/libcrypto/ecdh/ecdh.c12
-rw-r--r--src/lib/libcrypto/ecdsa/ecdsa.c32
4 files changed, 33 insertions, 25 deletions
diff --git a/src/lib/libcrypto/ec/ec.h b/src/lib/libcrypto/ec/ec.h
index 6b5d7b4af7..f711d55050 100644
--- a/src/lib/libcrypto/ec/ec.h
+++ b/src/lib/libcrypto/ec/ec.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec.h,v 1.41 2023/04/27 07:10:05 tb Exp $ */ 1/* $OpenBSD: ec.h,v 1.42 2023/07/05 17:10:10 tb Exp $ */
2/* 2/*
3 * Originally written by Bodo Moeller for the OpenSSL project. 3 * Originally written by Bodo Moeller for the OpenSSL project.
4 */ 4 */
@@ -606,6 +606,7 @@ void ERR_load_EC_strings(void);
606/* Reason codes. */ 606/* Reason codes. */
607#define EC_R_ASN1_ERROR 115 607#define EC_R_ASN1_ERROR 115
608#define EC_R_ASN1_UNKNOWN_FIELD 116 608#define EC_R_ASN1_UNKNOWN_FIELD 116
609#define EC_R_BAD_SIGNATURE 166
609#define EC_R_BIGNUM_OUT_OF_RANGE 144 610#define EC_R_BIGNUM_OUT_OF_RANGE 144
610#define EC_R_BUFFER_TOO_SMALL 100 611#define EC_R_BUFFER_TOO_SMALL 100
611#define EC_R_COORDINATES_OUT_OF_RANGE 146 612#define EC_R_COORDINATES_OUT_OF_RANGE 146
@@ -633,10 +634,13 @@ void ERR_load_EC_strings(void);
633#define EC_R_INVALID_PENTANOMIAL_BASIS 132 634#define EC_R_INVALID_PENTANOMIAL_BASIS 132
634#define EC_R_INVALID_PRIVATE_KEY 123 635#define EC_R_INVALID_PRIVATE_KEY 123
635#define EC_R_INVALID_TRINOMIAL_BASIS 137 636#define EC_R_INVALID_TRINOMIAL_BASIS 137
637#define EC_R_KDF_FAILED 167
636#define EC_R_KDF_PARAMETER_ERROR 148 638#define EC_R_KDF_PARAMETER_ERROR 148
639#define EC_R_KEY_TRUNCATION 168
637#define EC_R_KEYS_NOT_SET 140 640#define EC_R_KEYS_NOT_SET 140
638#define EC_R_MISSING_PARAMETERS 124 641#define EC_R_MISSING_PARAMETERS 124
639#define EC_R_MISSING_PRIVATE_KEY 125 642#define EC_R_MISSING_PRIVATE_KEY 125
643#define EC_R_NEED_NEW_SETUP_VALUES 170
640#define EC_R_NOT_A_NIST_PRIME 135 644#define EC_R_NOT_A_NIST_PRIME 135
641#define EC_R_NOT_A_SUPPORTED_NIST_PRIME 136 645#define EC_R_NOT_A_SUPPORTED_NIST_PRIME 136
642#define EC_R_NOT_IMPLEMENTED 126 646#define EC_R_NOT_IMPLEMENTED 126
@@ -647,6 +651,7 @@ void ERR_load_EC_strings(void);
647#define EC_R_PEER_KEY_ERROR 149 651#define EC_R_PEER_KEY_ERROR 149
648#define EC_R_PKPARAMETERS2GROUP_FAILURE 127 652#define EC_R_PKPARAMETERS2GROUP_FAILURE 127
649#define EC_R_POINT_AT_INFINITY 106 653#define EC_R_POINT_AT_INFINITY 106
654#define EC_R_POINT_ARITHMETIC_FAILURE 169
650#define EC_R_POINT_IS_NOT_ON_CURVE 107 655#define EC_R_POINT_IS_NOT_ON_CURVE 107
651#define EC_R_SHARED_INFO_ERROR 150 656#define EC_R_SHARED_INFO_ERROR 150
652#define EC_R_SLOT_FULL 108 657#define EC_R_SLOT_FULL 108
diff --git a/src/lib/libcrypto/ec/ec_err.c b/src/lib/libcrypto/ec/ec_err.c
index be6a284599..d10b8e6f7d 100644
--- a/src/lib/libcrypto/ec/ec_err.c
+++ b/src/lib/libcrypto/ec/ec_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_err.c,v 1.15 2022/11/19 07:00:57 tb Exp $ */ 1/* $OpenBSD: ec_err.c,v 1.16 2023/07/05 17:10:10 tb Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -74,6 +74,7 @@ static ERR_STRING_DATA EC_str_reasons[] =
74{ 74{
75 {ERR_REASON(EC_R_ASN1_ERROR), "asn1 error"}, 75 {ERR_REASON(EC_R_ASN1_ERROR), "asn1 error"},
76 {ERR_REASON(EC_R_ASN1_UNKNOWN_FIELD), "asn1 unknown field"}, 76 {ERR_REASON(EC_R_ASN1_UNKNOWN_FIELD), "asn1 unknown field"},
77 {ERR_REASON(EC_R_BAD_SIGNATURE), "bad signature"},
77 {ERR_REASON(EC_R_BIGNUM_OUT_OF_RANGE), "bignum out of range"}, 78 {ERR_REASON(EC_R_BIGNUM_OUT_OF_RANGE), "bignum out of range"},
78 {ERR_REASON(EC_R_BUFFER_TOO_SMALL), "buffer too small"}, 79 {ERR_REASON(EC_R_BUFFER_TOO_SMALL), "buffer too small"},
79 {ERR_REASON(EC_R_COORDINATES_OUT_OF_RANGE), "coordinates out of range"}, 80 {ERR_REASON(EC_R_COORDINATES_OUT_OF_RANGE), "coordinates out of range"},
@@ -101,10 +102,13 @@ static ERR_STRING_DATA EC_str_reasons[] =
101 {ERR_REASON(EC_R_INVALID_PENTANOMIAL_BASIS), "invalid pentanomial basis"}, 102 {ERR_REASON(EC_R_INVALID_PENTANOMIAL_BASIS), "invalid pentanomial basis"},
102 {ERR_REASON(EC_R_INVALID_PRIVATE_KEY), "invalid private key"}, 103 {ERR_REASON(EC_R_INVALID_PRIVATE_KEY), "invalid private key"},
103 {ERR_REASON(EC_R_INVALID_TRINOMIAL_BASIS), "invalid trinomial basis"}, 104 {ERR_REASON(EC_R_INVALID_TRINOMIAL_BASIS), "invalid trinomial basis"},
105 {ERR_REASON(EC_R_KDF_FAILED), "kdf failed"},
104 {ERR_REASON(EC_R_KDF_PARAMETER_ERROR), "kdf parameter error"}, 106 {ERR_REASON(EC_R_KDF_PARAMETER_ERROR), "kdf parameter error"},
107 {ERR_REASON(EC_R_KEY_TRUNCATION), "key would be truncated"},
105 {ERR_REASON(EC_R_KEYS_NOT_SET), "keys not set"}, 108 {ERR_REASON(EC_R_KEYS_NOT_SET), "keys not set"},
106 {ERR_REASON(EC_R_MISSING_PARAMETERS), "missing parameters"}, 109 {ERR_REASON(EC_R_MISSING_PARAMETERS), "missing parameters"},
107 {ERR_REASON(EC_R_MISSING_PRIVATE_KEY), "missing private key"}, 110 {ERR_REASON(EC_R_MISSING_PRIVATE_KEY), "missing private key"},
111 {ERR_REASON(EC_R_NEED_NEW_SETUP_VALUES), "need new setup values"},
108 {ERR_REASON(EC_R_NOT_A_NIST_PRIME), "not a NIST prime"}, 112 {ERR_REASON(EC_R_NOT_A_NIST_PRIME), "not a NIST prime"},
109 {ERR_REASON(EC_R_NOT_A_SUPPORTED_NIST_PRIME), "not a supported NIST prime"}, 113 {ERR_REASON(EC_R_NOT_A_SUPPORTED_NIST_PRIME), "not a supported NIST prime"},
110 {ERR_REASON(EC_R_NOT_IMPLEMENTED), "not implemented"}, 114 {ERR_REASON(EC_R_NOT_IMPLEMENTED), "not implemented"},
@@ -114,6 +118,7 @@ static ERR_STRING_DATA EC_str_reasons[] =
114 {ERR_REASON(EC_R_PASSED_NULL_PARAMETER), "passed null parameter"}, 118 {ERR_REASON(EC_R_PASSED_NULL_PARAMETER), "passed null parameter"},
115 {ERR_REASON(EC_R_PEER_KEY_ERROR), "peer key error"}, 119 {ERR_REASON(EC_R_PEER_KEY_ERROR), "peer key error"},
116 {ERR_REASON(EC_R_PKPARAMETERS2GROUP_FAILURE), "pkparameters2group failure"}, 120 {ERR_REASON(EC_R_PKPARAMETERS2GROUP_FAILURE), "pkparameters2group failure"},
121 {ERR_REASON(EC_R_POINT_ARITHMETIC_FAILURE), "point arithmetic failure"},
117 {ERR_REASON(EC_R_POINT_AT_INFINITY), "point at infinity"}, 122 {ERR_REASON(EC_R_POINT_AT_INFINITY), "point at infinity"},
118 {ERR_REASON(EC_R_POINT_IS_NOT_ON_CURVE), "point is not on curve"}, 123 {ERR_REASON(EC_R_POINT_IS_NOT_ON_CURVE), "point is not on curve"},
119 {ERR_REASON(EC_R_SHARED_INFO_ERROR), "shared info error"}, 124 {ERR_REASON(EC_R_SHARED_INFO_ERROR), "shared info error"},
diff --git a/src/lib/libcrypto/ecdh/ecdh.c b/src/lib/libcrypto/ecdh/ecdh.c
index d0486777e3..1179564030 100644
--- a/src/lib/libcrypto/ecdh/ecdh.c
+++ b/src/lib/libcrypto/ecdh/ecdh.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecdh.c,v 1.2 2023/07/05 14:39:05 tb Exp $ */ 1/* $OpenBSD: ecdh.c,v 1.3 2023/07/05 17:10:10 tb Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 * 4 *
@@ -187,7 +187,7 @@ ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, EC_KEY *ecdh
187 } 187 }
188 188
189 if ((priv_key = EC_KEY_get0_private_key(ecdh)) == NULL) { 189 if ((priv_key = EC_KEY_get0_private_key(ecdh)) == NULL) {
190 ECDHerror(ECDH_R_NO_PRIVATE_VALUE); 190 ECerror(EC_R_MISSING_PRIVATE_KEY);
191 goto err; 191 goto err;
192 } 192 }
193 193
@@ -204,12 +204,12 @@ ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, EC_KEY *ecdh
204 } 204 }
205 205
206 if (!EC_POINT_mul(group, point, NULL, pub_key, priv_key, ctx)) { 206 if (!EC_POINT_mul(group, point, NULL, pub_key, priv_key, ctx)) {
207 ECDHerror(ECDH_R_POINT_ARITHMETIC_FAILURE); 207 ECerror(EC_R_POINT_ARITHMETIC_FAILURE);
208 goto err; 208 goto err;
209 } 209 }
210 210
211 if (!EC_POINT_get_affine_coordinates(group, point, x, NULL, ctx)) { 211 if (!EC_POINT_get_affine_coordinates(group, point, x, NULL, ctx)) {
212 ECDHerror(ECDH_R_POINT_ARITHMETIC_FAILURE); 212 ECerror(EC_R_POINT_ARITHMETIC_FAILURE);
213 goto err; 213 goto err;
214 } 214 }
215 215
@@ -219,7 +219,7 @@ ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, EC_KEY *ecdh
219 } 219 }
220 if (KDF == NULL && outlen < buflen) { 220 if (KDF == NULL && outlen < buflen) {
221 /* The resulting key would be truncated. */ 221 /* The resulting key would be truncated. */
222 ECDHerror(ECDH_R_KEY_TRUNCATION); 222 ECerror(EC_R_KEY_TRUNCATION);
223 goto err; 223 goto err;
224 } 224 }
225 if ((buf = malloc(buflen)) == NULL) { 225 if ((buf = malloc(buflen)) == NULL) {
@@ -233,7 +233,7 @@ ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, EC_KEY *ecdh
233 233
234 if (KDF != NULL) { 234 if (KDF != NULL) {
235 if (KDF(buf, buflen, out, &outlen) == NULL) { 235 if (KDF(buf, buflen, out, &outlen) == NULL) {
236 ECDHerror(ECDH_R_KDF_FAILED); 236 ECerror(EC_R_KDF_FAILED);
237 goto err; 237 goto err;
238 } 238 }
239 } else { 239 } else {
diff --git a/src/lib/libcrypto/ecdsa/ecdsa.c b/src/lib/libcrypto/ecdsa/ecdsa.c
index 5d6175a787..b9c7ea6381 100644
--- a/src/lib/libcrypto/ecdsa/ecdsa.c
+++ b/src/lib/libcrypto/ecdsa/ecdsa.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecdsa.c,v 1.9 2023/07/05 14:41:18 tb Exp $ */ 1/* $OpenBSD: ecdsa.c,v 1.10 2023/07/05 17:10:10 tb Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2000-2002 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2000-2002 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -315,10 +315,8 @@ ecdsa_sign_setup(EC_KEY *key, BN_CTX *in_ctx, BIGNUM **out_kinv, BIGNUM **out_r)
315 /* Step 11: repeat until r != 0. */ 315 /* Step 11: repeat until r != 0. */
316 do { 316 do {
317 /* Step 3: generate random k. */ 317 /* Step 3: generate random k. */
318 if (!bn_rand_interval(k, BN_value_one(), order)) { 318 if (!bn_rand_interval(k, BN_value_one(), order))
319 ECDSAerror(ECDSA_R_RANDOM_NUMBER_GENERATION_FAILED);
320 goto err; 319 goto err;
321 }
322 320
323 /* 321 /*
324 * We do not want timing information to leak the length of k, 322 * We do not want timing information to leak the length of k,
@@ -436,7 +434,7 @@ ecdsa_compute_s(BIGNUM **out_s, const BIGNUM *e, const BIGNUM *kinv,
436 * can't rely on this being the case. 434 * can't rely on this being the case.
437 */ 435 */
438 if (BN_cmp(r, BN_value_one()) < 0 || BN_cmp(r, order) >= 0) { 436 if (BN_cmp(r, BN_value_one()) < 0 || BN_cmp(r, order) >= 0) {
439 ECDSAerror(ECDSA_R_BAD_SIGNATURE); 437 ECerror(EC_R_BAD_SIGNATURE);
440 goto err; 438 goto err;
441 } 439 }
442 440
@@ -552,7 +550,7 @@ ecdsa_sign_sig(const unsigned char *digest, int digest_len,
552 /* Steps 3-8: calculate kinv and r. */ 550 /* Steps 3-8: calculate kinv and r. */
553 if (!caller_supplied_values) { 551 if (!caller_supplied_values) {
554 if (!ECDSA_sign_setup(key, ctx, &kinv, &r)) { 552 if (!ECDSA_sign_setup(key, ctx, &kinv, &r)) {
555 ECDSAerror(ERR_R_ECDSA_LIB); 553 ECerror(ERR_R_EC_LIB);
556 goto err; 554 goto err;
557 } 555 }
558 } 556 }
@@ -566,7 +564,7 @@ ecdsa_sign_sig(const unsigned char *digest, int digest_len,
566 break; 564 break;
567 565
568 if (caller_supplied_values) { 566 if (caller_supplied_values) {
569 ECDSAerror(ECDSA_R_NEED_NEW_SETUP_VALUES); 567 ECerror(EC_R_NEED_NEW_SETUP_VALUES);
570 goto err; 568 goto err;
571 } 569 }
572 570
@@ -648,15 +646,15 @@ ecdsa_verify_sig(const unsigned char *digest, int digest_len,
648 int ret = -1; 646 int ret = -1;
649 647
650 if (key == NULL || sig == NULL) { 648 if (key == NULL || sig == NULL) {
651 ECDSAerror(ECDSA_R_MISSING_PARAMETERS); 649 ECerror(EC_R_MISSING_PARAMETERS);
652 goto err; 650 goto err;
653 } 651 }
654 if ((group = EC_KEY_get0_group(key)) == NULL) { 652 if ((group = EC_KEY_get0_group(key)) == NULL) {
655 ECDSAerror(ECDSA_R_MISSING_PARAMETERS); 653 ECerror(EC_R_MISSING_PARAMETERS);
656 goto err; 654 goto err;
657 } 655 }
658 if ((pub_key = EC_KEY_get0_public_key(key)) == NULL) { 656 if ((pub_key = EC_KEY_get0_public_key(key)) == NULL) {
659 ECDSAerror(ECDSA_R_MISSING_PARAMETERS); 657 ECerror(EC_R_MISSING_PARAMETERS);
660 goto err; 658 goto err;
661 } 659 }
662 660
@@ -685,12 +683,12 @@ ecdsa_verify_sig(const unsigned char *digest, int digest_len,
685 683
686 /* Step 1: verify that r and s are in the range [1, order). */ 684 /* Step 1: verify that r and s are in the range [1, order). */
687 if (BN_cmp(sig->r, BN_value_one()) < 0 || BN_cmp(sig->r, order) >= 0) { 685 if (BN_cmp(sig->r, BN_value_one()) < 0 || BN_cmp(sig->r, order) >= 0) {
688 ECDSAerror(ECDSA_R_BAD_SIGNATURE); 686 ECerror(EC_R_BAD_SIGNATURE);
689 ret = 0; 687 ret = 0;
690 goto err; 688 goto err;
691 } 689 }
692 if (BN_cmp(sig->s, BN_value_one()) < 0 || BN_cmp(sig->s, order) >= 0) { 690 if (BN_cmp(sig->s, BN_value_one()) < 0 || BN_cmp(sig->s, order) >= 0) {
693 ECDSAerror(ECDSA_R_BAD_SIGNATURE); 691 ECerror(EC_R_BAD_SIGNATURE);
694 ret = 0; 692 ret = 0;
695 goto err; 693 goto err;
696 } 694 }
@@ -759,7 +757,7 @@ ECDSA_do_sign_ex(const unsigned char *digest, int digest_len,
759 const BIGNUM *kinv, const BIGNUM *out_r, EC_KEY *key) 757 const BIGNUM *kinv, const BIGNUM *out_r, EC_KEY *key)
760{ 758{
761 if (key->meth->sign_sig == NULL) { 759 if (key->meth->sign_sig == NULL) {
762 ECDSAerror(EVP_R_METHOD_NOT_SUPPORTED); 760 ECerror(EC_R_NOT_IMPLEMENTED);
763 return 0; 761 return 0;
764 } 762 }
765 return key->meth->sign_sig(digest, digest_len, kinv, out_r, key); 763 return key->meth->sign_sig(digest, digest_len, kinv, out_r, key);
@@ -779,7 +777,7 @@ ECDSA_sign_ex(int type, const unsigned char *digest, int digest_len,
779 const BIGNUM *r, EC_KEY *key) 777 const BIGNUM *r, EC_KEY *key)
780{ 778{
781 if (key->meth->sign == NULL) { 779 if (key->meth->sign == NULL) {
782 ECDSAerror(EVP_R_METHOD_NOT_SUPPORTED); 780 ECerror(EC_R_NOT_IMPLEMENTED);
783 return 0; 781 return 0;
784 } 782 }
785 return key->meth->sign(type, digest, digest_len, signature, 783 return key->meth->sign(type, digest, digest_len, signature,
@@ -791,7 +789,7 @@ ECDSA_sign_setup(EC_KEY *key, BN_CTX *in_ctx, BIGNUM **out_kinv,
791 BIGNUM **out_r) 789 BIGNUM **out_r)
792{ 790{
793 if (key->meth->sign_setup == NULL) { 791 if (key->meth->sign_setup == NULL) {
794 ECDSAerror(EVP_R_METHOD_NOT_SUPPORTED); 792 ECerror(EC_R_NOT_IMPLEMENTED);
795 return 0; 793 return 0;
796 } 794 }
797 return key->meth->sign_setup(key, in_ctx, out_kinv, out_r); 795 return key->meth->sign_setup(key, in_ctx, out_kinv, out_r);
@@ -802,7 +800,7 @@ ECDSA_do_verify(const unsigned char *digest, int digest_len,
802 const ECDSA_SIG *sig, EC_KEY *key) 800 const ECDSA_SIG *sig, EC_KEY *key)
803{ 801{
804 if (key->meth->verify_sig == NULL) { 802 if (key->meth->verify_sig == NULL) {
805 ECDSAerror(EVP_R_METHOD_NOT_SUPPORTED); 803 ECerror(EC_R_NOT_IMPLEMENTED);
806 return 0; 804 return 0;
807 } 805 }
808 return key->meth->verify_sig(digest, digest_len, sig, key); 806 return key->meth->verify_sig(digest, digest_len, sig, key);
@@ -813,7 +811,7 @@ ECDSA_verify(int type, const unsigned char *digest, int digest_len,
813 const unsigned char *sigbuf, int sig_len, EC_KEY *key) 811 const unsigned char *sigbuf, int sig_len, EC_KEY *key)
814{ 812{
815 if (key->meth->verify == NULL) { 813 if (key->meth->verify == NULL) {
816 ECDSAerror(EVP_R_METHOD_NOT_SUPPORTED); 814 ECerror(EC_R_NOT_IMPLEMENTED);
817 return 0; 815 return 0;
818 } 816 }
819 return key->meth->verify(type, digest, digest_len, sigbuf, sig_len, key); 817 return key->meth->verify(type, digest, digest_len, sigbuf, sig_len, key);