summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/dh
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/dh')
-rw-r--r--src/lib/libcrypto/dh/dh_ameth.c30
-rw-r--r--src/lib/libcrypto/dh/dh_err.c27
-rw-r--r--src/lib/libcrypto/dh/dh_gen.c6
-rw-r--r--src/lib/libcrypto/dh/dh_key.c12
-rw-r--r--src/lib/libcrypto/dh/dh_lib.c8
-rw-r--r--src/lib/libcrypto/dh/dh_pmeth.c6
-rw-r--r--src/lib/libcrypto/dh/dh_prn.c4
7 files changed, 38 insertions, 55 deletions
diff --git a/src/lib/libcrypto/dh/dh_ameth.c b/src/lib/libcrypto/dh/dh_ameth.c
index 24c8bb25ec..0402092a4f 100644
--- a/src/lib/libcrypto/dh/dh_ameth.c
+++ b/src/lib/libcrypto/dh/dh_ameth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh_ameth.c,v 1.13 2015/01/08 01:44:29 doug Exp $ */ 1/* $OpenBSD: dh_ameth.c,v 1.14 2017/01/29 17:49:22 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -89,7 +89,7 @@ dh_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey)
89 X509_ALGOR_get0(NULL, &ptype, &pval, palg); 89 X509_ALGOR_get0(NULL, &ptype, &pval, palg);
90 90
91 if (ptype != V_ASN1_SEQUENCE) { 91 if (ptype != V_ASN1_SEQUENCE) {
92 DHerr(DH_F_DH_PUB_DECODE, DH_R_PARAMETER_ENCODING_ERROR); 92 DHerror(DH_R_PARAMETER_ENCODING_ERROR);
93 goto err; 93 goto err;
94 } 94 }
95 95
@@ -98,18 +98,18 @@ dh_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey)
98 pmlen = pstr->length; 98 pmlen = pstr->length;
99 99
100 if (!(dh = d2i_DHparams(NULL, &pm, pmlen))) { 100 if (!(dh = d2i_DHparams(NULL, &pm, pmlen))) {
101 DHerr(DH_F_DH_PUB_DECODE, DH_R_DECODE_ERROR); 101 DHerror(DH_R_DECODE_ERROR);
102 goto err; 102 goto err;
103 } 103 }
104 104
105 if (!(public_key=d2i_ASN1_INTEGER(NULL, &p, pklen))) { 105 if (!(public_key=d2i_ASN1_INTEGER(NULL, &p, pklen))) {
106 DHerr(DH_F_DH_PUB_DECODE, DH_R_DECODE_ERROR); 106 DHerror(DH_R_DECODE_ERROR);
107 goto err; 107 goto err;
108 } 108 }
109 109
110 /* We have parameters now set public key */ 110 /* We have parameters now set public key */
111 if (!(dh->pub_key = ASN1_INTEGER_to_BN(public_key, NULL))) { 111 if (!(dh->pub_key = ASN1_INTEGER_to_BN(public_key, NULL))) {
112 DHerr(DH_F_DH_PUB_DECODE, DH_R_BN_DECODE_ERROR); 112 DHerror(DH_R_BN_DECODE_ERROR);
113 goto err; 113 goto err;
114 } 114 }
115 115
@@ -138,13 +138,13 @@ dh_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
138 138
139 str = ASN1_STRING_new(); 139 str = ASN1_STRING_new();
140 if (str == NULL) { 140 if (str == NULL) {
141 DHerr(DH_F_DH_PUB_ENCODE, ERR_R_MALLOC_FAILURE); 141 DHerror(ERR_R_MALLOC_FAILURE);
142 goto err; 142 goto err;
143 } 143 }
144 144
145 str->length = i2d_DHparams(dh, &str->data); 145 str->length = i2d_DHparams(dh, &str->data);
146 if (str->length <= 0) { 146 if (str->length <= 0) {
147 DHerr(DH_F_DH_PUB_ENCODE, ERR_R_MALLOC_FAILURE); 147 DHerror(ERR_R_MALLOC_FAILURE);
148 goto err; 148 goto err;
149 } 149 }
150 ptype = V_ASN1_SEQUENCE; 150 ptype = V_ASN1_SEQUENCE;
@@ -158,7 +158,7 @@ dh_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
158 ASN1_INTEGER_free(pub_key); 158 ASN1_INTEGER_free(pub_key);
159 159
160 if (penclen <= 0) { 160 if (penclen <= 0) {
161 DHerr(DH_F_DH_PUB_ENCODE, ERR_R_MALLOC_FAILURE); 161 DHerror(ERR_R_MALLOC_FAILURE);
162 goto err; 162 goto err;
163 } 163 }
164 164
@@ -209,7 +209,7 @@ dh_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8)
209 goto decerr; 209 goto decerr;
210 /* We have parameters now set private key */ 210 /* We have parameters now set private key */
211 if (!(dh->priv_key = ASN1_INTEGER_to_BN(privkey, NULL))) { 211 if (!(dh->priv_key = ASN1_INTEGER_to_BN(privkey, NULL))) {
212 DHerr(DH_F_DH_PRIV_DECODE, DH_R_BN_ERROR); 212 DHerror(DH_R_BN_ERROR);
213 goto dherr; 213 goto dherr;
214 } 214 }
215 /* Calculate public key */ 215 /* Calculate public key */
@@ -223,7 +223,7 @@ dh_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8)
223 return 1; 223 return 1;
224 224
225decerr: 225decerr:
226 DHerr(DH_F_DH_PRIV_DECODE, EVP_R_DECODE_ERROR); 226 DHerror(EVP_R_DECODE_ERROR);
227dherr: 227dherr:
228 DH_free(dh); 228 DH_free(dh);
229 return 0; 229 return 0;
@@ -240,13 +240,13 @@ dh_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey)
240 params = ASN1_STRING_new(); 240 params = ASN1_STRING_new();
241 241
242 if (!params) { 242 if (!params) {
243 DHerr(DH_F_DH_PRIV_ENCODE, ERR_R_MALLOC_FAILURE); 243 DHerror(ERR_R_MALLOC_FAILURE);
244 goto err; 244 goto err;
245 } 245 }
246 246
247 params->length = i2d_DHparams(pkey->pkey.dh, &params->data); 247 params->length = i2d_DHparams(pkey->pkey.dh, &params->data);
248 if (params->length <= 0) { 248 if (params->length <= 0) {
249 DHerr(DH_F_DH_PRIV_ENCODE,ERR_R_MALLOC_FAILURE); 249 DHerror(ERR_R_MALLOC_FAILURE);
250 goto err; 250 goto err;
251 } 251 }
252 params->type = V_ASN1_SEQUENCE; 252 params->type = V_ASN1_SEQUENCE;
@@ -255,7 +255,7 @@ dh_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey)
255 prkey = BN_to_ASN1_INTEGER(pkey->pkey.dh->priv_key, NULL); 255 prkey = BN_to_ASN1_INTEGER(pkey->pkey.dh->priv_key, NULL);
256 256
257 if (!prkey) { 257 if (!prkey) {
258 DHerr(DH_F_DH_PRIV_ENCODE, DH_R_BN_ERROR); 258 DHerror(DH_R_BN_ERROR);
259 goto err; 259 goto err;
260 } 260 }
261 261
@@ -294,7 +294,7 @@ dh_param_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen)
294 DH *dh; 294 DH *dh;
295 295
296 if (!(dh = d2i_DHparams(NULL, pder, derlen))) { 296 if (!(dh = d2i_DHparams(NULL, pder, derlen))) {
297 DHerr(DH_F_DH_PARAM_DECODE, ERR_R_DH_LIB); 297 DHerror(ERR_R_DH_LIB);
298 return 0; 298 return 0;
299 } 299 }
300 EVP_PKEY_assign_DH(pkey, dh); 300 EVP_PKEY_assign_DH(pkey, dh);
@@ -374,7 +374,7 @@ do_dh_print(BIO *bp, const DH *x, int indent, ASN1_PCTX *ctx, int ptype)
374 ret = 1; 374 ret = 1;
375 if (0) { 375 if (0) {
376err: 376err:
377 DHerr(DH_F_DO_DH_PRINT,reason); 377 DHerror(reason);
378 } 378 }
379 free(m); 379 free(m);
380 return(ret); 380 return(ret);
diff --git a/src/lib/libcrypto/dh/dh_err.c b/src/lib/libcrypto/dh/dh_err.c
index 3774ba3c45..497f88436e 100644
--- a/src/lib/libcrypto/dh/dh_err.c
+++ b/src/lib/libcrypto/dh/dh_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh_err.c,v 1.15 2014/07/10 22:45:56 jsing Exp $ */ 1/* $OpenBSD: dh_err.c,v 1.16 2017/01/29 17:49:22 beck 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 *
@@ -71,27 +71,10 @@
71#define ERR_FUNC(func) ERR_PACK(ERR_LIB_DH,func,0) 71#define ERR_FUNC(func) ERR_PACK(ERR_LIB_DH,func,0)
72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_DH,0,reason) 72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_DH,0,reason)
73 73
74static ERR_STRING_DATA DH_str_functs[]= 74static ERR_STRING_DATA DH_str_functs[]= {
75 { 75 {ERR_FUNC(0xfff), "CRYPTO_internal"},
76{ERR_FUNC(DH_F_COMPUTE_KEY), "COMPUTE_KEY"}, 76 {0, NULL}
77{ERR_FUNC(DH_F_DHPARAMS_PRINT_FP), "DHparams_print_fp"}, 77};
78{ERR_FUNC(DH_F_DH_BUILTIN_GENPARAMS), "DH_BUILTIN_GENPARAMS"},
79{ERR_FUNC(DH_F_DH_COMPUTE_KEY), "DH_compute_key"},
80{ERR_FUNC(DH_F_DH_GENERATE_KEY), "DH_generate_key"},
81{ERR_FUNC(DH_F_DH_GENERATE_PARAMETERS_EX), "DH_generate_parameters_ex"},
82{ERR_FUNC(DH_F_DH_NEW_METHOD), "DH_new_method"},
83{ERR_FUNC(DH_F_DH_PARAM_DECODE), "DH_PARAM_DECODE"},
84{ERR_FUNC(DH_F_DH_PRIV_DECODE), "DH_PRIV_DECODE"},
85{ERR_FUNC(DH_F_DH_PRIV_ENCODE), "DH_PRIV_ENCODE"},
86{ERR_FUNC(DH_F_DH_PUB_DECODE), "DH_PUB_DECODE"},
87{ERR_FUNC(DH_F_DH_PUB_ENCODE), "DH_PUB_ENCODE"},
88{ERR_FUNC(DH_F_DO_DH_PRINT), "DO_DH_PRINT"},
89{ERR_FUNC(DH_F_GENERATE_KEY), "GENERATE_KEY"},
90{ERR_FUNC(DH_F_GENERATE_PARAMETERS), "GENERATE_PARAMETERS"},
91{ERR_FUNC(DH_F_PKEY_DH_DERIVE), "PKEY_DH_DERIVE"},
92{ERR_FUNC(DH_F_PKEY_DH_KEYGEN), "PKEY_DH_KEYGEN"},
93{0,NULL}
94 };
95 78
96static ERR_STRING_DATA DH_str_reasons[]= 79static ERR_STRING_DATA DH_str_reasons[]=
97 { 80 {
diff --git a/src/lib/libcrypto/dh/dh_gen.c b/src/lib/libcrypto/dh/dh_gen.c
index de566802d3..99394113ee 100644
--- a/src/lib/libcrypto/dh/dh_gen.c
+++ b/src/lib/libcrypto/dh/dh_gen.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh_gen.c,v 1.15 2015/02/09 15:49:22 jsing Exp $ */ 1/* $OpenBSD: dh_gen.c,v 1.16 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -127,7 +127,7 @@ dh_builtin_genparams(DH *ret, int prime_len, int generator, BN_GENCB *cb)
127 goto err; 127 goto err;
128 128
129 if (generator <= 1) { 129 if (generator <= 1) {
130 DHerr(DH_F_DH_BUILTIN_GENPARAMS, DH_R_BAD_GENERATOR); 130 DHerror(DH_R_BAD_GENERATOR);
131 goto err; 131 goto err;
132 } 132 }
133 if (generator == DH_GENERATOR_2) { 133 if (generator == DH_GENERATOR_2) {
@@ -167,7 +167,7 @@ dh_builtin_genparams(DH *ret, int prime_len, int generator, BN_GENCB *cb)
167 ok = 1; 167 ok = 1;
168err: 168err:
169 if (ok == -1) { 169 if (ok == -1) {
170 DHerr(DH_F_DH_BUILTIN_GENPARAMS, ERR_R_BN_LIB); 170 DHerror(ERR_R_BN_LIB);
171 ok = 0; 171 ok = 0;
172 } 172 }
173 173
diff --git a/src/lib/libcrypto/dh/dh_key.c b/src/lib/libcrypto/dh/dh_key.c
index 5b365cdd06..63d38771c3 100644
--- a/src/lib/libcrypto/dh/dh_key.c
+++ b/src/lib/libcrypto/dh/dh_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh_key.c,v 1.26 2017/01/21 09:38:58 beck Exp $ */ 1/* $OpenBSD: dh_key.c,v 1.27 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -165,7 +165,7 @@ generate_key(DH *dh)
165 ok = 1; 165 ok = 1;
166err: 166err:
167 if (ok != 1) 167 if (ok != 1)
168 DHerr(DH_F_GENERATE_KEY, ERR_R_BN_LIB); 168 DHerror(ERR_R_BN_LIB);
169 169
170 if (pub_key != NULL && dh->pub_key == NULL) 170 if (pub_key != NULL && dh->pub_key == NULL)
171 BN_free(pub_key); 171 BN_free(pub_key);
@@ -185,7 +185,7 @@ compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
185 int check_result; 185 int check_result;
186 186
187 if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) { 187 if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) {
188 DHerr(DH_F_COMPUTE_KEY, DH_R_MODULUS_TOO_LARGE); 188 DHerror(DH_R_MODULUS_TOO_LARGE);
189 goto err; 189 goto err;
190 } 190 }
191 191
@@ -197,7 +197,7 @@ compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
197 goto err; 197 goto err;
198 198
199 if (dh->priv_key == NULL) { 199 if (dh->priv_key == NULL) {
200 DHerr(DH_F_COMPUTE_KEY, DH_R_NO_PRIVATE_VALUE); 200 DHerror(DH_R_NO_PRIVATE_VALUE);
201 goto err; 201 goto err;
202 } 202 }
203 203
@@ -212,13 +212,13 @@ compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
212 } 212 }
213 213
214 if (!DH_check_pub_key(dh, pub_key, &check_result) || check_result) { 214 if (!DH_check_pub_key(dh, pub_key, &check_result) || check_result) {
215 DHerr(DH_F_COMPUTE_KEY, DH_R_INVALID_PUBKEY); 215 DHerror(DH_R_INVALID_PUBKEY);
216 goto err; 216 goto err;
217 } 217 }
218 218
219 if (!dh->meth->bn_mod_exp(dh, tmp, pub_key, dh->priv_key, dh->p, ctx, 219 if (!dh->meth->bn_mod_exp(dh, tmp, pub_key, dh->priv_key, dh->p, ctx,
220 mont)) { 220 mont)) {
221 DHerr(DH_F_COMPUTE_KEY, ERR_R_BN_LIB); 221 DHerror(ERR_R_BN_LIB);
222 goto err; 222 goto err;
223 } 223 }
224 224
diff --git a/src/lib/libcrypto/dh/dh_lib.c b/src/lib/libcrypto/dh/dh_lib.c
index defe1c74b4..d45dc17168 100644
--- a/src/lib/libcrypto/dh/dh_lib.c
+++ b/src/lib/libcrypto/dh/dh_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh_lib.c,v 1.21 2015/02/11 03:19:37 doug Exp $ */ 1/* $OpenBSD: dh_lib.c,v 1.22 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -121,7 +121,7 @@ DH_new_method(ENGINE *engine)
121 121
122 ret = malloc(sizeof(DH)); 122 ret = malloc(sizeof(DH));
123 if (ret == NULL) { 123 if (ret == NULL) {
124 DHerr(DH_F_DH_NEW_METHOD, ERR_R_MALLOC_FAILURE); 124 DHerror(ERR_R_MALLOC_FAILURE);
125 return NULL; 125 return NULL;
126 } 126 }
127 127
@@ -129,7 +129,7 @@ DH_new_method(ENGINE *engine)
129#ifndef OPENSSL_NO_ENGINE 129#ifndef OPENSSL_NO_ENGINE
130 if (engine) { 130 if (engine) {
131 if (!ENGINE_init(engine)) { 131 if (!ENGINE_init(engine)) {
132 DHerr(DH_F_DH_NEW_METHOD, ERR_R_ENGINE_LIB); 132 DHerror(ERR_R_ENGINE_LIB);
133 free(ret); 133 free(ret);
134 return NULL; 134 return NULL;
135 } 135 }
@@ -139,7 +139,7 @@ DH_new_method(ENGINE *engine)
139 if(ret->engine) { 139 if(ret->engine) {
140 ret->meth = ENGINE_get_DH(ret->engine); 140 ret->meth = ENGINE_get_DH(ret->engine);
141 if (!ret->meth) { 141 if (!ret->meth) {
142 DHerr(DH_F_DH_NEW_METHOD, ERR_R_ENGINE_LIB); 142 DHerror(ERR_R_ENGINE_LIB);
143 ENGINE_finish(ret->engine); 143 ENGINE_finish(ret->engine);
144 free(ret); 144 free(ret);
145 return NULL; 145 return NULL;
diff --git a/src/lib/libcrypto/dh/dh_pmeth.c b/src/lib/libcrypto/dh/dh_pmeth.c
index 6d750eb30d..24d16ff5d3 100644
--- a/src/lib/libcrypto/dh/dh_pmeth.c
+++ b/src/lib/libcrypto/dh/dh_pmeth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh_pmeth.c,v 1.9 2014/07/11 08:44:48 jsing Exp $ */ 1/* $OpenBSD: dh_pmeth.c,v 1.10 2017/01/29 17:49:22 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -215,7 +215,7 @@ pkey_dh_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
215 DH *dh = NULL; 215 DH *dh = NULL;
216 216
217 if (ctx->pkey == NULL) { 217 if (ctx->pkey == NULL) {
218 DHerr(DH_F_PKEY_DH_KEYGEN, DH_R_NO_PARAMETERS_SET); 218 DHerror(DH_R_NO_PARAMETERS_SET);
219 return 0; 219 return 0;
220 } 220 }
221 dh = DH_new(); 221 dh = DH_new();
@@ -234,7 +234,7 @@ pkey_dh_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen)
234 int ret; 234 int ret;
235 235
236 if (!ctx->pkey || !ctx->peerkey) { 236 if (!ctx->pkey || !ctx->peerkey) {
237 DHerr(DH_F_PKEY_DH_DERIVE, DH_R_KEYS_NOT_SET); 237 DHerror(DH_R_KEYS_NOT_SET);
238 return 0; 238 return 0;
239 } 239 }
240 ret = DH_compute_key(key, ctx->peerkey->pkey.dh->pub_key, 240 ret = DH_compute_key(key, ctx->peerkey->pkey.dh->pub_key,
diff --git a/src/lib/libcrypto/dh/dh_prn.c b/src/lib/libcrypto/dh/dh_prn.c
index 73d0476e21..56a96f8631 100644
--- a/src/lib/libcrypto/dh/dh_prn.c
+++ b/src/lib/libcrypto/dh/dh_prn.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh_prn.c,v 1.5 2014/07/11 08:44:48 jsing Exp $ */ 1/* $OpenBSD: dh_prn.c,v 1.6 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -69,7 +69,7 @@ DHparams_print_fp(FILE *fp, const DH *x)
69 int ret; 69 int ret;
70 70
71 if ((b = BIO_new(BIO_s_file())) == NULL) { 71 if ((b = BIO_new(BIO_s_file())) == NULL) {
72 DHerr(DH_F_DHPARAMS_PRINT_FP, ERR_R_BUF_LIB); 72 DHerror(ERR_R_BUF_LIB);
73 return 0; 73 return 0;
74 } 74 }
75 BIO_set_fp(b,fp,BIO_NOCLOSE); 75 BIO_set_fp(b,fp,BIO_NOCLOSE);