| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2021-03-11 21:27:36 +08:00
										 |  |  |  * Copyright 2006-2021 The OpenSSL Project Authors. All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2006-04-13 07:51:24 +08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-12-06 20:36:05 +08:00
										 |  |  |  * Licensed under the Apache License 2.0 (the "License").  You may not use | 
					
						
							| 
									
										
										
										
											2016-05-18 03:38:09 +08:00
										 |  |  |  * this file except in compliance with the License.  You can obtain a copy | 
					
						
							|  |  |  |  * in the file LICENSE in the source distribution or at | 
					
						
							|  |  |  |  * https://www.openssl.org/source/license.html
 | 
					
						
							| 
									
										
										
										
											2006-04-13 07:51:24 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-30 05:23:39 +08:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2020-02-03 17:05:31 +08:00
										 |  |  |  * DH & DSA low level APIs are deprecated for public use, but still ok for | 
					
						
							| 
									
										
										
										
											2020-01-30 05:23:39 +08:00
										 |  |  |  * internal use. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #include "internal/deprecated.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-13 07:51:24 +08:00
										 |  |  | #include <stdio.h>
 | 
					
						
							| 
									
										
										
										
											2015-05-14 22:56:48 +08:00
										 |  |  | #include "internal/cryptlib.h"
 | 
					
						
							| 
									
										
										
										
											2006-04-13 07:51:24 +08:00
										 |  |  | #include <openssl/asn1t.h>
 | 
					
						
							|  |  |  | #include <openssl/x509.h>
 | 
					
						
							|  |  |  | #include <openssl/evp.h>
 | 
					
						
							| 
									
										
										
										
											2019-09-28 06:45:40 +08:00
										 |  |  | #include "dh_local.h"
 | 
					
						
							| 
									
										
										
										
											2008-03-17 05:05:46 +08:00
										 |  |  | #include <openssl/bn.h>
 | 
					
						
							| 
									
										
										
										
											2016-03-19 02:30:20 +08:00
										 |  |  | #include <openssl/dsa.h>
 | 
					
						
							| 
									
										
										
										
											2013-07-21 04:31:10 +08:00
										 |  |  | #include <openssl/objects.h>
 | 
					
						
							| 
									
										
										
										
											2019-09-28 06:45:33 +08:00
										 |  |  | #include "crypto/evp.h"
 | 
					
						
							| 
									
										
										
										
											2006-04-13 07:51:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* DH pkey context structure */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | typedef struct { | 
					
						
							|  |  |  |     /* Parameter gen parameters */ | 
					
						
							|  |  |  |     int prime_len; | 
					
						
							|  |  |  |     int generator; | 
					
						
							| 
									
										
										
										
											2020-02-06 20:28:36 +08:00
										 |  |  |     int paramgen_type; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     int subprime_len; | 
					
						
							| 
									
										
										
										
											2017-09-21 22:40:15 +08:00
										 |  |  |     int pad; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     /* message digest used for parameter generation */ | 
					
						
							|  |  |  |     const EVP_MD *md; | 
					
						
							| 
									
										
										
										
											2017-05-30 08:19:50 +08:00
										 |  |  |     int param_nid; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     /* Keygen callback info */ | 
					
						
							|  |  |  |     int gentmp[2]; | 
					
						
							|  |  |  |     /* KDF (if any) to use for DH */ | 
					
						
							|  |  |  |     char kdf_type; | 
					
						
							|  |  |  |     /* OID to use for KDF */ | 
					
						
							|  |  |  |     ASN1_OBJECT *kdf_oid; | 
					
						
							|  |  |  |     /* Message digest to use for key derivation */ | 
					
						
							|  |  |  |     const EVP_MD *kdf_md; | 
					
						
							|  |  |  |     /* User key material */ | 
					
						
							|  |  |  |     unsigned char *kdf_ukm; | 
					
						
							|  |  |  |     size_t kdf_ukmlen; | 
					
						
							|  |  |  |     /* KDF output length */ | 
					
						
							|  |  |  |     size_t kdf_outlen; | 
					
						
							|  |  |  | } DH_PKEY_CTX; | 
					
						
							| 
									
										
										
										
											2006-04-13 07:51:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | static int pkey_dh_init(EVP_PKEY_CTX *ctx) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     DH_PKEY_CTX *dctx; | 
					
						
							| 
									
										
										
										
											2015-09-03 21:15:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-03 23:31:16 +08:00
										 |  |  |     if ((dctx = OPENSSL_zalloc(sizeof(*dctx))) == NULL) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |         ERR_raise(ERR_LIB_DH, ERR_R_MALLOC_FAILURE); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 0; | 
					
						
							| 
									
										
										
										
											2018-04-03 23:31:16 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-13 18:32:48 +08:00
										 |  |  |     dctx->prime_len = 2048; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     dctx->subprime_len = -1; | 
					
						
							|  |  |  |     dctx->generator = 2; | 
					
						
							|  |  |  |     dctx->kdf_type = EVP_PKEY_DH_KDF_NONE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ctx->data = dctx; | 
					
						
							|  |  |  |     ctx->keygen_info = dctx->gentmp; | 
					
						
							|  |  |  |     ctx->keygen_info_count = 2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 1; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2006-04-13 07:51:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-05 23:39:16 +08:00
										 |  |  | static void pkey_dh_cleanup(EVP_PKEY_CTX *ctx) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     DH_PKEY_CTX *dctx = ctx->data; | 
					
						
							| 
									
										
										
										
											2020-02-06 20:28:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-05 23:39:16 +08:00
										 |  |  |     if (dctx != NULL) { | 
					
						
							|  |  |  |         OPENSSL_free(dctx->kdf_ukm); | 
					
						
							|  |  |  |         ASN1_OBJECT_free(dctx->kdf_oid); | 
					
						
							|  |  |  |         OPENSSL_free(dctx); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-16 04:51:25 +08:00
										 |  |  | static int pkey_dh_copy(EVP_PKEY_CTX *dst, const EVP_PKEY_CTX *src) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     DH_PKEY_CTX *dctx, *sctx; | 
					
						
							| 
									
										
										
										
											2019-09-17 03:28:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     if (!pkey_dh_init(dst)) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     sctx = src->data; | 
					
						
							|  |  |  |     dctx = dst->data; | 
					
						
							|  |  |  |     dctx->prime_len = sctx->prime_len; | 
					
						
							|  |  |  |     dctx->subprime_len = sctx->subprime_len; | 
					
						
							|  |  |  |     dctx->generator = sctx->generator; | 
					
						
							| 
									
										
										
										
											2020-02-06 20:28:36 +08:00
										 |  |  |     dctx->paramgen_type = sctx->paramgen_type; | 
					
						
							| 
									
										
										
										
											2017-09-21 22:40:15 +08:00
										 |  |  |     dctx->pad = sctx->pad; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     dctx->md = sctx->md; | 
					
						
							| 
									
										
										
										
											2017-05-30 08:19:50 +08:00
										 |  |  |     dctx->param_nid = sctx->param_nid; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     dctx->kdf_type = sctx->kdf_type; | 
					
						
							|  |  |  |     dctx->kdf_oid = OBJ_dup(sctx->kdf_oid); | 
					
						
							| 
									
										
										
										
											2016-05-05 23:39:16 +08:00
										 |  |  |     if (dctx->kdf_oid == NULL) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 0; | 
					
						
							|  |  |  |     dctx->kdf_md = sctx->kdf_md; | 
					
						
							| 
									
										
										
										
											2016-05-05 23:39:16 +08:00
										 |  |  |     if (sctx->kdf_ukm != NULL) { | 
					
						
							| 
									
										
										
											
												Rename some BUF_xxx to OPENSSL_xxx
Rename BUF_{strdup,strlcat,strlcpy,memdup,strndup,strnlen}
to OPENSSL_{strdup,strlcat,strlcpy,memdup,strndup,strnlen}
Add #define's for the old names.
Add CRYPTO_{memdup,strndup}, called by OPENSSL_{memdup,strndup} macros.
Reviewed-by: Tim Hudson <tjh@openssl.org>
											
										 
											2015-12-17 05:12:24 +08:00
										 |  |  |         dctx->kdf_ukm = OPENSSL_memdup(sctx->kdf_ukm, sctx->kdf_ukmlen); | 
					
						
							| 
									
										
										
										
											2016-05-05 23:39:16 +08:00
										 |  |  |         if (dctx->kdf_ukm == NULL) | 
					
						
							|  |  |  |           return 0; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         dctx->kdf_ukmlen = sctx->kdf_ukmlen; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     dctx->kdf_outlen = sctx->kdf_outlen; | 
					
						
							|  |  |  |     return 1; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2006-05-25 07:49:30 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-13 07:51:24 +08:00
										 |  |  | static int pkey_dh_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     DH_PKEY_CTX *dctx = ctx->data; | 
					
						
							|  |  |  |     switch (type) { | 
					
						
							|  |  |  |     case EVP_PKEY_CTRL_DH_PARAMGEN_PRIME_LEN: | 
					
						
							|  |  |  |         if (p1 < 256) | 
					
						
							|  |  |  |             return -2; | 
					
						
							|  |  |  |         dctx->prime_len = p1; | 
					
						
							|  |  |  |         return 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case EVP_PKEY_CTRL_DH_PARAMGEN_SUBPRIME_LEN: | 
					
						
							| 
									
										
										
										
											2020-02-06 20:28:36 +08:00
										 |  |  |         if (dctx->paramgen_type == DH_PARAMGEN_TYPE_GENERATOR) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             return -2; | 
					
						
							|  |  |  |         dctx->subprime_len = p1; | 
					
						
							|  |  |  |         return 1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-21 22:40:15 +08:00
										 |  |  |     case EVP_PKEY_CTRL_DH_PAD: | 
					
						
							|  |  |  |         dctx->pad = p1; | 
					
						
							|  |  |  |         return 1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     case EVP_PKEY_CTRL_DH_PARAMGEN_GENERATOR: | 
					
						
							| 
									
										
										
										
											2020-02-06 20:28:36 +08:00
										 |  |  |         if (dctx->paramgen_type != DH_PARAMGEN_TYPE_GENERATOR) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             return -2; | 
					
						
							|  |  |  |         dctx->generator = p1; | 
					
						
							|  |  |  |         return 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case EVP_PKEY_CTRL_DH_PARAMGEN_TYPE: | 
					
						
							| 
									
										
										
										
											2013-08-01 01:10:16 +08:00
										 |  |  | #ifdef OPENSSL_NO_DSA
 | 
					
						
							| 
									
										
										
										
											2020-02-06 20:28:36 +08:00
										 |  |  |         if (p1 != DH_PARAMGEN_TYPE_GENERATOR) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             return -2; | 
					
						
							| 
									
										
										
										
											2013-08-01 01:10:16 +08:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         if (p1 < 0 || p1 > 2) | 
					
						
							|  |  |  |             return -2; | 
					
						
							| 
									
										
										
										
											2013-08-01 01:10:16 +08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-02-06 20:28:36 +08:00
										 |  |  |         dctx->paramgen_type = p1; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case EVP_PKEY_CTRL_DH_RFC5114: | 
					
						
							| 
									
										
										
										
											2017-05-30 08:19:50 +08:00
										 |  |  |         if (p1 < 1 || p1 > 3 || dctx->param_nid != NID_undef) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             return -2; | 
					
						
							| 
									
										
										
										
											2021-04-15 16:25:17 +08:00
										 |  |  |         dctx->param_nid = p1; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-30 08:19:50 +08:00
										 |  |  |     case EVP_PKEY_CTRL_DH_NID: | 
					
						
							| 
									
										
										
										
											2021-04-15 16:25:17 +08:00
										 |  |  |         if (p1 <= 0 || dctx->param_nid != NID_undef) | 
					
						
							| 
									
										
										
										
											2017-05-30 08:19:50 +08:00
										 |  |  |             return -2; | 
					
						
							|  |  |  |         dctx->param_nid = p1; | 
					
						
							|  |  |  |         return 1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     case EVP_PKEY_CTRL_PEER_KEY: | 
					
						
							|  |  |  |         /* Default behaviour is OK */ | 
					
						
							|  |  |  |         return 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case EVP_PKEY_CTRL_DH_KDF_TYPE: | 
					
						
							|  |  |  |         if (p1 == -2) | 
					
						
							|  |  |  |             return dctx->kdf_type; | 
					
						
							|  |  |  |         if (p1 != EVP_PKEY_DH_KDF_NONE && p1 != EVP_PKEY_DH_KDF_X9_42) | 
					
						
							|  |  |  |             return -2; | 
					
						
							|  |  |  |         dctx->kdf_type = p1; | 
					
						
							|  |  |  |         return 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case EVP_PKEY_CTRL_DH_KDF_MD: | 
					
						
							|  |  |  |         dctx->kdf_md = p2; | 
					
						
							|  |  |  |         return 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case EVP_PKEY_CTRL_GET_DH_KDF_MD: | 
					
						
							|  |  |  |         *(const EVP_MD **)p2 = dctx->kdf_md; | 
					
						
							|  |  |  |         return 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case EVP_PKEY_CTRL_DH_KDF_OUTLEN: | 
					
						
							|  |  |  |         if (p1 <= 0) | 
					
						
							|  |  |  |             return -2; | 
					
						
							|  |  |  |         dctx->kdf_outlen = (size_t)p1; | 
					
						
							|  |  |  |         return 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case EVP_PKEY_CTRL_GET_DH_KDF_OUTLEN: | 
					
						
							|  |  |  |         *(int *)p2 = dctx->kdf_outlen; | 
					
						
							|  |  |  |         return 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case EVP_PKEY_CTRL_DH_KDF_UKM: | 
					
						
							| 
									
										
										
										
											2015-05-01 22:02:07 +08:00
										 |  |  |         OPENSSL_free(dctx->kdf_ukm); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         dctx->kdf_ukm = p2; | 
					
						
							|  |  |  |         if (p2) | 
					
						
							|  |  |  |             dctx->kdf_ukmlen = p1; | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |             dctx->kdf_ukmlen = 0; | 
					
						
							|  |  |  |         return 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case EVP_PKEY_CTRL_GET_DH_KDF_UKM: | 
					
						
							|  |  |  |         *(unsigned char **)p2 = dctx->kdf_ukm; | 
					
						
							|  |  |  |         return dctx->kdf_ukmlen; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case EVP_PKEY_CTRL_DH_KDF_OID: | 
					
						
							| 
									
										
										
										
											2015-03-24 19:52:24 +08:00
										 |  |  |         ASN1_OBJECT_free(dctx->kdf_oid); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         dctx->kdf_oid = p2; | 
					
						
							|  |  |  |         return 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case EVP_PKEY_CTRL_GET_DH_KDF_OID: | 
					
						
							|  |  |  |         *(ASN1_OBJECT **)p2 = dctx->kdf_oid; | 
					
						
							|  |  |  |         return 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |         return -2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-08-01 01:10:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-13 07:51:24 +08:00
										 |  |  | static int pkey_dh_ctrl_str(EVP_PKEY_CTX *ctx, | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |                             const char *type, const char *value) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-05-07 02:56:14 +08:00
										 |  |  |     if (strcmp(type, "dh_paramgen_prime_len") == 0) { | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         int len; | 
					
						
							|  |  |  |         len = atoi(value); | 
					
						
							|  |  |  |         return EVP_PKEY_CTX_set_dh_paramgen_prime_len(ctx, len); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-07 02:56:14 +08:00
										 |  |  |     if (strcmp(type, "dh_rfc5114") == 0) { | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         DH_PKEY_CTX *dctx = ctx->data; | 
					
						
							| 
									
										
										
										
											2021-04-15 16:25:17 +08:00
										 |  |  |         int id; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         id = atoi(value); | 
					
						
							|  |  |  |         if (id < 0 || id > 3) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             return -2; | 
					
						
							| 
									
										
										
										
											2021-04-15 16:25:17 +08:00
										 |  |  |         dctx->param_nid = id; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 1; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-05-30 08:19:50 +08:00
										 |  |  |     if (strcmp(type, "dh_param") == 0) { | 
					
						
							|  |  |  |         DH_PKEY_CTX *dctx = ctx->data; | 
					
						
							|  |  |  |         int nid = OBJ_sn2nid(value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (nid == NID_undef) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |             ERR_raise(ERR_LIB_DH, DH_R_INVALID_PARAMETER_NAME); | 
					
						
							| 
									
										
										
										
											2017-05-30 08:19:50 +08:00
										 |  |  |             return -2; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         dctx->param_nid = nid; | 
					
						
							|  |  |  |         return 1; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-07 02:56:14 +08:00
										 |  |  |     if (strcmp(type, "dh_paramgen_generator") == 0) { | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         int len; | 
					
						
							|  |  |  |         len = atoi(value); | 
					
						
							|  |  |  |         return EVP_PKEY_CTX_set_dh_paramgen_generator(ctx, len); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-07 02:56:14 +08:00
										 |  |  |     if (strcmp(type, "dh_paramgen_subprime_len") == 0) { | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         int len; | 
					
						
							|  |  |  |         len = atoi(value); | 
					
						
							|  |  |  |         return EVP_PKEY_CTX_set_dh_paramgen_subprime_len(ctx, len); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-07 02:56:14 +08:00
										 |  |  |     if (strcmp(type, "dh_paramgen_type") == 0) { | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         int typ; | 
					
						
							|  |  |  |         typ = atoi(value); | 
					
						
							|  |  |  |         return EVP_PKEY_CTX_set_dh_paramgen_type(ctx, typ); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-09-21 22:40:15 +08:00
										 |  |  |     if (strcmp(type, "dh_pad") == 0) { | 
					
						
							|  |  |  |         int pad; | 
					
						
							|  |  |  |         pad = atoi(value); | 
					
						
							|  |  |  |         return EVP_PKEY_CTX_set_dh_pad(ctx, pad); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     return -2; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2006-04-13 07:51:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  | static DH *ffc_params_generate(OSSL_LIB_CTX *libctx, DH_PKEY_CTX *dctx, | 
					
						
							| 
									
										
										
										
											2020-02-06 20:28:36 +08:00
										 |  |  |                                BN_GENCB *pcb) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-02-06 20:28:36 +08:00
										 |  |  |     DH *ret; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     int rv = 0; | 
					
						
							| 
									
										
										
										
											2020-02-06 20:28:36 +08:00
										 |  |  |     int res; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     int prime_len = dctx->prime_len; | 
					
						
							|  |  |  |     int subprime_len = dctx->subprime_len; | 
					
						
							| 
									
										
										
										
											2020-02-06 20:28:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (dctx->paramgen_type > DH_PARAMGEN_TYPE_FIPS_186_4) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return NULL; | 
					
						
							| 
									
										
										
										
											2020-02-06 20:28:36 +08:00
										 |  |  |     ret = DH_new(); | 
					
						
							| 
									
										
										
										
											2015-10-30 19:12:26 +08:00
										 |  |  |     if (ret == NULL) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return NULL; | 
					
						
							| 
									
										
										
										
											2020-02-06 20:28:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     if (subprime_len == -1) { | 
					
						
							|  |  |  |         if (prime_len >= 2048) | 
					
						
							|  |  |  |             subprime_len = 256; | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |             subprime_len = 160; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-06-17 09:33:16 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (dctx->md != NULL) | 
					
						
							| 
									
										
										
											
												Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
											
										 
											2021-05-21 22:58:08 +08:00
										 |  |  |         ossl_ffc_set_digest(&ret->params, EVP_MD_get0_name(dctx->md), NULL); | 
					
						
							| 
									
										
										
										
											2020-06-17 09:33:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-14 04:34:56 +08:00
										 |  |  | # ifndef FIPS_MODULE
 | 
					
						
							| 
									
										
										
										
											2020-02-06 20:28:36 +08:00
										 |  |  |     if (dctx->paramgen_type == DH_PARAMGEN_TYPE_FIPS_186_2) | 
					
						
							| 
									
										
											  
											
												ffc: add _ossl to exported but internal functions
The functions updated are:
    ffc_generate_private_key, ffc_named_group_from_uid,
    ffc_named_group_to_uid, ffc_params_FIPS186_2_gen_verify,
    ffc_params_FIPS186_2_generate, ffc_params_FIPS186_2_validate,
    ffc_params_FIPS186_4_gen_verify, ffc_params_FIPS186_4_generate,
    ffc_params_FIPS186_4_validate, ffc_params_cleanup, ffc_params_cmp,
    ffc_params_copy, ffc_params_enable_flags, ffc_params_flags_from_name,
    ffc_params_flags_to_name, ffc_params_fromdata,
    ffc_params_get0_pqg, ffc_params_get_validate_params,
    ffc_params_init, ffc_params_print, ffc_params_set0_j,
    ffc_params_set0_pqg, ffc_params_set_flags, ffc_params_set_gindex,
    ffc_params_set_h, ffc_params_set_pcounter, ffc_params_set_seed,
    ffc_params_set_validate_params, ffc_params_simple_validate,
    ffc_params_todata, ffc_params_validate_unverifiable_g, ffc_set_digest,
    ffc_set_group_pqg, ffc_validate_private_key, ffc_validate_public_key
    and ffc_validate_public_key_partial.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13041)
											
										 
											2020-09-30 13:07:24 +08:00
										 |  |  |         rv = ossl_ffc_params_FIPS186_2_generate(libctx, &ret->params, | 
					
						
							|  |  |  |                                                 FFC_PARAM_TYPE_DH, | 
					
						
							|  |  |  |                                                 prime_len, subprime_len, &res, | 
					
						
							|  |  |  |                                                 pcb); | 
					
						
							| 
									
										
										
										
											2020-02-06 20:28:36 +08:00
										 |  |  |     else | 
					
						
							|  |  |  | # endif
 | 
					
						
							|  |  |  |     /* For FIPS we always use the DH_PARAMGEN_TYPE_FIPS_186_4 generator */ | 
					
						
							|  |  |  |     if (dctx->paramgen_type >= DH_PARAMGEN_TYPE_FIPS_186_2) | 
					
						
							| 
									
										
											  
											
												ffc: add _ossl to exported but internal functions
The functions updated are:
    ffc_generate_private_key, ffc_named_group_from_uid,
    ffc_named_group_to_uid, ffc_params_FIPS186_2_gen_verify,
    ffc_params_FIPS186_2_generate, ffc_params_FIPS186_2_validate,
    ffc_params_FIPS186_4_gen_verify, ffc_params_FIPS186_4_generate,
    ffc_params_FIPS186_4_validate, ffc_params_cleanup, ffc_params_cmp,
    ffc_params_copy, ffc_params_enable_flags, ffc_params_flags_from_name,
    ffc_params_flags_to_name, ffc_params_fromdata,
    ffc_params_get0_pqg, ffc_params_get_validate_params,
    ffc_params_init, ffc_params_print, ffc_params_set0_j,
    ffc_params_set0_pqg, ffc_params_set_flags, ffc_params_set_gindex,
    ffc_params_set_h, ffc_params_set_pcounter, ffc_params_set_seed,
    ffc_params_set_validate_params, ffc_params_simple_validate,
    ffc_params_todata, ffc_params_validate_unverifiable_g, ffc_set_digest,
    ffc_set_group_pqg, ffc_validate_private_key, ffc_validate_public_key
    and ffc_validate_public_key_partial.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13041)
											
										 
											2020-09-30 13:07:24 +08:00
										 |  |  |         rv = ossl_ffc_params_FIPS186_4_generate(libctx, &ret->params, | 
					
						
							|  |  |  |                                                 FFC_PARAM_TYPE_DH, | 
					
						
							|  |  |  |                                                 prime_len, subprime_len, &res, | 
					
						
							|  |  |  |                                                 pcb); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     if (rv <= 0) { | 
					
						
							| 
									
										
										
										
											2020-02-06 20:28:36 +08:00
										 |  |  |         DH_free(ret); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return ret; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-08-01 01:10:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-06 20:28:36 +08:00
										 |  |  | static int pkey_dh_paramgen(EVP_PKEY_CTX *ctx, | 
					
						
							|  |  |  |                             EVP_PKEY *pkey) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     DH *dh = NULL; | 
					
						
							|  |  |  |     DH_PKEY_CTX *dctx = ctx->data; | 
					
						
							| 
									
										
										
										
											2020-01-31 06:18:46 +08:00
										 |  |  |     BN_GENCB *pcb = NULL; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     int ret; | 
					
						
							| 
									
										
										
										
											2020-01-31 06:18:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /*
 | 
					
						
							|  |  |  |      * Look for a safe prime group for key establishment. Which uses | 
					
						
							|  |  |  |      * either RFC_3526 (modp_XXXX) or RFC_7919 (ffdheXXXX). | 
					
						
							| 
									
										
										
										
											2021-04-15 16:25:17 +08:00
										 |  |  |      * RFC_5114 is also handled here for param_nid = (1..3) | 
					
						
							| 
									
										
										
										
											2020-01-31 06:18:46 +08:00
										 |  |  |      */ | 
					
						
							|  |  |  |     if (dctx->param_nid != NID_undef) { | 
					
						
							| 
									
										
										
										
											2021-04-15 16:25:17 +08:00
										 |  |  |         int type = dctx->param_nid <= 3 ? EVP_PKEY_DHX : EVP_PKEY_DH; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-31 06:18:46 +08:00
										 |  |  |         if ((dh = DH_new_by_nid(dctx->param_nid)) == NULL) | 
					
						
							|  |  |  |             return 0; | 
					
						
							| 
									
										
										
										
											2021-04-15 16:25:17 +08:00
										 |  |  |         EVP_PKEY_assign(pkey, type, dh); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-31 06:18:46 +08:00
										 |  |  |     if (ctx->pkey_gencb != NULL) { | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         pcb = BN_GENCB_new(); | 
					
						
							| 
									
										
										
										
											2015-10-30 19:12:26 +08:00
										 |  |  |         if (pcb == NULL) | 
					
						
							|  |  |  |             return 0; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         evp_pkey_set_cb_translate(pcb, ctx); | 
					
						
							| 
									
										
										
										
											2020-01-31 06:18:46 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-04-14 04:34:56 +08:00
										 |  |  | # ifdef FIPS_MODULE
 | 
					
						
							| 
									
										
										
										
											2020-02-06 20:28:36 +08:00
										 |  |  |     dctx->paramgen_type = DH_PARAMGEN_TYPE_FIPS_186_4; | 
					
						
							| 
									
										
										
										
											2020-04-14 04:34:56 +08:00
										 |  |  | # endif /* FIPS_MODULE */
 | 
					
						
							| 
									
										
										
										
											2020-02-06 20:28:36 +08:00
										 |  |  |     if (dctx->paramgen_type >= DH_PARAMGEN_TYPE_FIPS_186_2) { | 
					
						
							|  |  |  |         dh = ffc_params_generate(NULL, dctx, pcb); | 
					
						
							| 
									
										
										
										
											2015-05-01 09:37:06 +08:00
										 |  |  |         BN_GENCB_free(pcb); | 
					
						
							| 
									
										
										
										
											2020-02-06 20:28:36 +08:00
										 |  |  |         if (dh == NULL) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             return 0; | 
					
						
							|  |  |  |         EVP_PKEY_assign(pkey, EVP_PKEY_DHX, dh); | 
					
						
							|  |  |  |         return 1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     dh = DH_new(); | 
					
						
							| 
									
										
										
										
											2015-10-30 19:12:26 +08:00
										 |  |  |     if (dh == NULL) { | 
					
						
							| 
									
										
										
										
											2015-05-01 09:37:06 +08:00
										 |  |  |         BN_GENCB_free(pcb); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     ret = DH_generate_parameters_ex(dh, | 
					
						
							|  |  |  |                                     dctx->prime_len, dctx->generator, pcb); | 
					
						
							| 
									
										
										
										
											2015-05-01 09:37:06 +08:00
										 |  |  |     BN_GENCB_free(pcb); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     if (ret) | 
					
						
							|  |  |  |         EVP_PKEY_assign_DH(pkey, dh); | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         DH_free(dh); | 
					
						
							|  |  |  |     return ret; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2006-04-13 07:51:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | static int pkey_dh_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-05-30 08:19:50 +08:00
										 |  |  |     DH_PKEY_CTX *dctx = ctx->data; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     DH *dh = NULL; | 
					
						
							| 
									
										
										
										
											2017-05-30 08:19:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-31 06:18:46 +08:00
										 |  |  |     if (ctx->pkey == NULL && dctx->param_nid == NID_undef) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |         ERR_raise(ERR_LIB_DH, DH_R_NO_PARAMETERS_SET); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-01-31 06:18:46 +08:00
										 |  |  |     if (dctx->param_nid != NID_undef) | 
					
						
							| 
									
										
										
										
											2017-05-30 08:19:50 +08:00
										 |  |  |         dh = DH_new_by_nid(dctx->param_nid); | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         dh = DH_new(); | 
					
						
							| 
									
										
										
										
											2015-10-30 19:12:26 +08:00
										 |  |  |     if (dh == NULL) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 0; | 
					
						
							|  |  |  |     EVP_PKEY_assign(pkey, ctx->pmeth->pkey_id, dh); | 
					
						
							|  |  |  |     /* Note: if error return, pkey is freed by parent routine */ | 
					
						
							| 
									
										
										
										
											2017-05-30 08:19:50 +08:00
										 |  |  |     if (ctx->pkey != NULL && !EVP_PKEY_copy_parameters(pkey, ctx->pkey)) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 0; | 
					
						
							|  |  |  |     return DH_generate_key(pkey->pkey.dh); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int pkey_dh_derive(EVP_PKEY_CTX *ctx, unsigned char *key, | 
					
						
							|  |  |  |                           size_t *keylen) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int ret; | 
					
						
							|  |  |  |     DH *dh; | 
					
						
							| 
									
										
										
										
											2021-03-16 00:21:45 +08:00
										 |  |  |     const DH *dhpub; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     DH_PKEY_CTX *dctx = ctx->data; | 
					
						
							| 
									
										
										
										
											2021-03-16 00:21:45 +08:00
										 |  |  |     BIGNUM *dhpubbn; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (ctx->pkey == NULL || ctx->peerkey == NULL) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |         ERR_raise(ERR_LIB_DH, DH_R_KEYS_NOT_SET); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     dh = ctx->pkey->pkey.dh; | 
					
						
							| 
									
										
										
										
											2021-03-16 00:21:45 +08:00
										 |  |  |     dhpub = EVP_PKEY_get0_DH(ctx->peerkey); | 
					
						
							|  |  |  |     if (dhpub == NULL) { | 
					
						
							|  |  |  |         ERR_raise(ERR_LIB_DH, DH_R_KEYS_NOT_SET); | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     dhpubbn = dhpub->pub_key; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     if (dctx->kdf_type == EVP_PKEY_DH_KDF_NONE) { | 
					
						
							|  |  |  |         if (key == NULL) { | 
					
						
							|  |  |  |             *keylen = DH_size(dh); | 
					
						
							|  |  |  |             return 1; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-09-21 22:40:15 +08:00
										 |  |  |         if (dctx->pad) | 
					
						
							| 
									
										
										
										
											2021-03-16 00:21:45 +08:00
										 |  |  |             ret = DH_compute_key_padded(key, dhpubbn, dh); | 
					
						
							| 
									
										
										
										
											2017-09-21 22:40:15 +08:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2021-03-16 00:21:45 +08:00
										 |  |  |             ret = DH_compute_key(key, dhpubbn, dh); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         if (ret < 0) | 
					
						
							|  |  |  |             return ret; | 
					
						
							|  |  |  |         *keylen = ret; | 
					
						
							|  |  |  |         return 1; | 
					
						
							| 
									
										
										
										
											2015-08-04 00:45:26 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     else if (dctx->kdf_type == EVP_PKEY_DH_KDF_X9_42) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         unsigned char *Z = NULL; | 
					
						
							|  |  |  |         size_t Zlen = 0; | 
					
						
							|  |  |  |         if (!dctx->kdf_outlen || !dctx->kdf_oid) | 
					
						
							|  |  |  |             return 0; | 
					
						
							|  |  |  |         if (key == NULL) { | 
					
						
							|  |  |  |             *keylen = dctx->kdf_outlen; | 
					
						
							|  |  |  |             return 1; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (*keylen != dctx->kdf_outlen) | 
					
						
							|  |  |  |             return 0; | 
					
						
							|  |  |  |         ret = 0; | 
					
						
							| 
									
										
										
										
											2021-03-19 12:54:40 +08:00
										 |  |  |         if ((Zlen = DH_size(dh)) <= 0) | 
					
						
							|  |  |  |             return 0; | 
					
						
							|  |  |  |         if ((Z = OPENSSL_malloc(Zlen)) == NULL) { | 
					
						
							|  |  |  |             ERR_raise(ERR_LIB_DH, ERR_R_MALLOC_FAILURE); | 
					
						
							|  |  |  |             return 0; | 
					
						
							| 
									
										
										
										
											2015-03-05 01:49:51 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-03-16 00:21:45 +08:00
										 |  |  |         if (DH_compute_key_padded(Z, dhpubbn, dh) <= 0) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             goto err; | 
					
						
							|  |  |  |         if (!DH_KDF_X9_42(key, *keylen, Z, Zlen, dctx->kdf_oid, | 
					
						
							|  |  |  |                           dctx->kdf_ukm, dctx->kdf_ukmlen, dctx->kdf_md)) | 
					
						
							|  |  |  |             goto err; | 
					
						
							|  |  |  |         *keylen = dctx->kdf_outlen; | 
					
						
							|  |  |  |         ret = 1; | 
					
						
							|  |  |  |  err: | 
					
						
							| 
									
										
										
										
											2015-05-01 05:57:32 +08:00
										 |  |  |         OPENSSL_clear_free(Z, Zlen); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         return ret; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-08-04 00:45:26 +08:00
										 |  |  |     return 0; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-19 21:31:27 +08:00
										 |  |  | static const EVP_PKEY_METHOD dh_pkey_meth = { | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     EVP_PKEY_DH, | 
					
						
							|  |  |  |     0, | 
					
						
							|  |  |  |     pkey_dh_init, | 
					
						
							|  |  |  |     pkey_dh_copy, | 
					
						
							|  |  |  |     pkey_dh_cleanup, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     0, | 
					
						
							|  |  |  |     pkey_dh_paramgen, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     0, | 
					
						
							|  |  |  |     pkey_dh_keygen, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     0, | 
					
						
							|  |  |  |     0, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     0, | 
					
						
							|  |  |  |     0, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     0, 0, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     0, 0, 0, 0, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     0, 0, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     0, 0, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     0, | 
					
						
							|  |  |  |     pkey_dh_derive, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     pkey_dh_ctrl, | 
					
						
							|  |  |  |     pkey_dh_ctrl_str | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												Fix external symbols related to dh keys
Partial fix for #12964
This adds ossl_ names for the following symbols:
dh_new_by_nid_ex, dh_new_ex, dh_generate_ffc_parameters, dh_generate_public_key,
dh_get_named_group_uid_from_size, dh_gen_type_id2name, dh_gen_type_name2id,
dh_cache_named_group, dh_get0_params, dh_get0_nid,
dh_params_fromdata, dh_key_fromdata, dh_params_todata, dh_key_todata,
dh_check_pub_key_partial, dh_check_priv_key, dh_check_pairwise,
dh_get_method, dh_buf2key, dh_key2buf, dh_KDF_X9_42_asn1,
dh_pkey_method, dhx_pkey_method
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14231)
											
										 
											2021-02-18 13:56:53 +08:00
										 |  |  | const EVP_PKEY_METHOD *ossl_dh_pkey_method(void) | 
					
						
							| 
									
										
										
										
											2019-09-19 21:31:27 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     return &dh_pkey_meth; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const EVP_PKEY_METHOD dhx_pkey_meth = { | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     EVP_PKEY_DHX, | 
					
						
							|  |  |  |     0, | 
					
						
							|  |  |  |     pkey_dh_init, | 
					
						
							|  |  |  |     pkey_dh_copy, | 
					
						
							|  |  |  |     pkey_dh_cleanup, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     0, | 
					
						
							|  |  |  |     pkey_dh_paramgen, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     0, | 
					
						
							|  |  |  |     pkey_dh_keygen, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     0, | 
					
						
							|  |  |  |     0, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     0, | 
					
						
							|  |  |  |     0, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     0, 0, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     0, 0, 0, 0, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     0, 0, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     0, 0, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     0, | 
					
						
							|  |  |  |     pkey_dh_derive, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     pkey_dh_ctrl, | 
					
						
							|  |  |  |     pkey_dh_ctrl_str | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2019-09-19 21:31:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
											
												Fix external symbols related to dh keys
Partial fix for #12964
This adds ossl_ names for the following symbols:
dh_new_by_nid_ex, dh_new_ex, dh_generate_ffc_parameters, dh_generate_public_key,
dh_get_named_group_uid_from_size, dh_gen_type_id2name, dh_gen_type_name2id,
dh_cache_named_group, dh_get0_params, dh_get0_nid,
dh_params_fromdata, dh_key_fromdata, dh_params_todata, dh_key_todata,
dh_check_pub_key_partial, dh_check_priv_key, dh_check_pairwise,
dh_get_method, dh_buf2key, dh_key2buf, dh_KDF_X9_42_asn1,
dh_pkey_method, dhx_pkey_method
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14231)
											
										 
											2021-02-18 13:56:53 +08:00
										 |  |  | const EVP_PKEY_METHOD *ossl_dhx_pkey_method(void) | 
					
						
							| 
									
										
										
										
											2019-09-19 21:31:27 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     return &dhx_pkey_meth; | 
					
						
							|  |  |  | } |