2 * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 #include "internal/cryptlib.h"
12 #include <openssl/evp.h>
13 #include <openssl/objects.h>
14 #include <openssl/params.h>
15 #include <openssl/core_names.h>
16 #include <openssl/dh.h>
17 #include "internal/evp_int.h"
18 #include "internal/provider.h"
21 #if !defined(FIPS_MODE)
22 int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX
*c
, ASN1_TYPE
*type
)
25 const EVP_CIPHER
*cipher
= c
->cipher
;
27 if (cipher
->prov
!= NULL
) {
29 * The cipher has come from a provider and won't have the default flags.
30 * Find the implicit form so we can check the flags.
31 * TODO(3.0): This won't work for 3rd party ciphers we know nothing about
32 * We'll need to think of something else for those.
34 cipher
= EVP_get_cipherbynid(cipher
->nid
);
36 EVPerr(EVP_F_EVP_CIPHER_PARAM_TO_ASN1
, ASN1_R_UNSUPPORTED_CIPHER
);
41 if (cipher
->set_asn1_parameters
!= NULL
)
42 ret
= cipher
->set_asn1_parameters(c
, type
);
43 else if (cipher
->flags
& EVP_CIPH_FLAG_DEFAULT_ASN1
) {
44 switch (EVP_CIPHER_mode(cipher
)) {
45 case EVP_CIPH_WRAP_MODE
:
46 if (EVP_CIPHER_nid(cipher
) == NID_id_smime_alg_CMS3DESwrap
)
47 ASN1_TYPE_set(type
, V_ASN1_NULL
, NULL
);
51 case EVP_CIPH_GCM_MODE
:
52 case EVP_CIPH_CCM_MODE
:
53 case EVP_CIPH_XTS_MODE
:
54 case EVP_CIPH_OCB_MODE
:
59 ret
= EVP_CIPHER_set_asn1_iv(c
, type
);
64 EVPerr(EVP_F_EVP_CIPHER_PARAM_TO_ASN1
, ret
== -2 ?
65 ASN1_R_UNSUPPORTED_CIPHER
:
66 EVP_R_CIPHER_PARAMETER_ERROR
);
72 int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX
*c
, ASN1_TYPE
*type
)
75 const EVP_CIPHER
*cipher
= c
->cipher
;
77 if (cipher
->prov
!= NULL
) {
79 * The cipher has come from a provider and won't have the default flags.
80 * Find the implicit form so we can check the flags.
82 cipher
= EVP_get_cipherbynid(cipher
->nid
);
87 if (cipher
->get_asn1_parameters
!= NULL
)
88 ret
= cipher
->get_asn1_parameters(c
, type
);
89 else if (cipher
->flags
& EVP_CIPH_FLAG_DEFAULT_ASN1
) {
90 switch (EVP_CIPHER_mode(cipher
)) {
92 case EVP_CIPH_WRAP_MODE
:
96 case EVP_CIPH_GCM_MODE
:
97 case EVP_CIPH_CCM_MODE
:
98 case EVP_CIPH_XTS_MODE
:
99 case EVP_CIPH_OCB_MODE
:
104 ret
= EVP_CIPHER_get_asn1_iv(c
, type
);
110 EVPerr(EVP_F_EVP_CIPHER_ASN1_TO_PARAM
, ret
== -2 ?
111 EVP_R_UNSUPPORTED_CIPHER
:
112 EVP_R_CIPHER_PARAMETER_ERROR
);
118 int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX
*ctx
, ASN1_TYPE
*type
)
124 unsigned char iv
[EVP_MAX_IV_LENGTH
];
126 l
= EVP_CIPHER_CTX_iv_length(ctx
);
127 if (!ossl_assert(l
<= sizeof(iv
)))
129 i
= ASN1_TYPE_get_octetstring(type
, iv
, l
);
133 if (!EVP_CipherInit_ex(ctx
, NULL
, NULL
, NULL
, iv
, -1))
139 int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX
*c
, ASN1_TYPE
*type
)
145 j
= EVP_CIPHER_CTX_iv_length(c
);
146 OPENSSL_assert(j
<= sizeof(c
->iv
));
147 i
= ASN1_TYPE_set_octetstring(type
, c
->oiv
, j
);
151 #endif /* !defined(FIPS_MODE) */
153 /* Convert the various cipher NIDs and dummies to a proper OID NID */
154 int EVP_CIPHER_type(const EVP_CIPHER
*ctx
)
157 nid
= EVP_CIPHER_nid(ctx
);
172 case NID_aes_128_cfb128
:
173 case NID_aes_128_cfb8
:
174 case NID_aes_128_cfb1
:
176 return NID_aes_128_cfb128
;
178 case NID_aes_192_cfb128
:
179 case NID_aes_192_cfb8
:
180 case NID_aes_192_cfb1
:
182 return NID_aes_192_cfb128
;
184 case NID_aes_256_cfb128
:
185 case NID_aes_256_cfb8
:
186 case NID_aes_256_cfb1
:
188 return NID_aes_256_cfb128
;
194 return NID_des_cfb64
;
196 case NID_des_ede3_cfb64
:
197 case NID_des_ede3_cfb8
:
198 case NID_des_ede3_cfb1
:
200 return NID_des_cfb64
;
207 /* Check it has an OID and it is valid */
208 ASN1_OBJECT
*otmp
= OBJ_nid2obj(nid
);
210 if (OBJ_get0_data(otmp
) == NULL
)
212 ASN1_OBJECT_free(otmp
);
219 int EVP_CIPHER_block_size(const EVP_CIPHER
*cipher
)
221 int ok
, v
= cipher
->block_size
;
222 OSSL_PARAM params
[2] = { OSSL_PARAM_END
, OSSL_PARAM_END
};
224 params
[0] = OSSL_PARAM_construct_int(OSSL_CIPHER_PARAM_BLOCK_SIZE
, &v
);
225 ok
= evp_do_ciph_getparams(cipher
, params
);
227 return ok
!= 0 ? v
: -1;
230 int EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX
*ctx
)
232 return EVP_CIPHER_block_size(ctx
->cipher
);
235 int EVP_CIPHER_impl_ctx_size(const EVP_CIPHER
*e
)
240 int EVP_Cipher(EVP_CIPHER_CTX
*ctx
, unsigned char *out
,
241 const unsigned char *in
, unsigned int inl
)
243 if (ctx
->cipher
->prov
!= NULL
) {
244 size_t outl
= 0; /* ignored */
245 int blocksize
= EVP_CIPHER_CTX_block_size(ctx
);
247 if (ctx
->cipher
->ccipher
!= NULL
)
249 ctx
->cipher
->ccipher(ctx
->provctx
, out
, &outl
,
250 inl
+ (blocksize
== 1 ? 0 : blocksize
),
255 return ctx
->cipher
->do_cipher(ctx
, out
, in
, inl
);
258 const EVP_CIPHER
*EVP_CIPHER_CTX_cipher(const EVP_CIPHER_CTX
*ctx
)
263 int EVP_CIPHER_CTX_encrypting(const EVP_CIPHER_CTX
*ctx
)
268 unsigned long EVP_CIPHER_flags(const EVP_CIPHER
*cipher
)
271 unsigned long v
= cipher
->flags
;
272 OSSL_PARAM params
[2] = { OSSL_PARAM_END
, OSSL_PARAM_END
};
274 params
[0] = OSSL_PARAM_construct_ulong(OSSL_CIPHER_PARAM_FLAGS
, &v
);
275 ok
= evp_do_ciph_getparams(cipher
, params
);
277 return ok
!= 0 ? v
: 0;
280 void *EVP_CIPHER_CTX_get_app_data(const EVP_CIPHER_CTX
*ctx
)
282 return ctx
->app_data
;
285 void EVP_CIPHER_CTX_set_app_data(EVP_CIPHER_CTX
*ctx
, void *data
)
287 ctx
->app_data
= data
;
290 void *EVP_CIPHER_CTX_get_cipher_data(const EVP_CIPHER_CTX
*ctx
)
292 return ctx
->cipher_data
;
295 void *EVP_CIPHER_CTX_set_cipher_data(EVP_CIPHER_CTX
*ctx
, void *cipher_data
)
297 void *old_cipher_data
;
299 old_cipher_data
= ctx
->cipher_data
;
300 ctx
->cipher_data
= cipher_data
;
302 return old_cipher_data
;
305 int EVP_CIPHER_iv_length(const EVP_CIPHER
*cipher
)
307 int ok
, v
= cipher
->iv_len
;
308 OSSL_PARAM params
[2] = { OSSL_PARAM_END
, OSSL_PARAM_END
};
310 params
[0] = OSSL_PARAM_construct_int(OSSL_CIPHER_PARAM_IVLEN
, &v
);
311 ok
= evp_do_ciph_getparams(cipher
, params
);
313 return ok
!= 0 ? v
: -1;
316 int EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX
*ctx
)
318 return EVP_CIPHER_iv_length(ctx
->cipher
);
321 const unsigned char *EVP_CIPHER_CTX_original_iv(const EVP_CIPHER_CTX
*ctx
)
327 * OSSL_PARAM_OCTET_PTR gets us the pointer to the running IV in the provider
329 const unsigned char *EVP_CIPHER_CTX_iv(const EVP_CIPHER_CTX
*ctx
)
332 const unsigned char *v
= ctx
->iv
;
333 OSSL_PARAM params
[2] = { OSSL_PARAM_END
, OSSL_PARAM_END
};
336 OSSL_PARAM_construct_octet_ptr(OSSL_CIPHER_PARAM_IV
, (void **)&v
,
338 ok
= evp_do_ciph_ctx_getparams(ctx
->cipher
, ctx
->provctx
, params
);
340 return ok
!= 0 ? v
: NULL
;
343 unsigned char *EVP_CIPHER_CTX_iv_noconst(EVP_CIPHER_CTX
*ctx
)
346 unsigned char *v
= ctx
->iv
;
347 OSSL_PARAM params
[2] = { OSSL_PARAM_END
, OSSL_PARAM_END
};
350 OSSL_PARAM_construct_octet_ptr(OSSL_CIPHER_PARAM_IV
, (void **)&v
,
352 ok
= evp_do_ciph_ctx_getparams(ctx
->cipher
, ctx
->provctx
, params
);
354 return ok
!= 0 ? v
: NULL
;
357 unsigned char *EVP_CIPHER_CTX_buf_noconst(EVP_CIPHER_CTX
*ctx
)
362 int EVP_CIPHER_CTX_num(const EVP_CIPHER_CTX
*ctx
)
364 int ok
, v
= ctx
->num
;
365 OSSL_PARAM params
[2] = { OSSL_PARAM_END
, OSSL_PARAM_END
};
367 params
[0] = OSSL_PARAM_construct_int(OSSL_CIPHER_PARAM_NUM
, &v
);
368 ok
= evp_do_ciph_ctx_getparams(ctx
->cipher
, ctx
->provctx
, params
);
370 return ok
!= 0 ? v
: -1;
373 int EVP_CIPHER_CTX_set_num(EVP_CIPHER_CTX
*ctx
, int num
)
376 OSSL_PARAM params
[2] = { OSSL_PARAM_END
, OSSL_PARAM_END
};
378 params
[0] = OSSL_PARAM_construct_int(OSSL_CIPHER_PARAM_NUM
, &num
);
379 ok
= evp_do_ciph_ctx_setparams(ctx
->cipher
, ctx
->provctx
, params
);
386 int EVP_CIPHER_key_length(const EVP_CIPHER
*cipher
)
388 int ok
, v
= cipher
->key_len
;
389 OSSL_PARAM params
[2] = { OSSL_PARAM_END
, OSSL_PARAM_END
};
391 params
[0] = OSSL_PARAM_construct_int(OSSL_CIPHER_PARAM_KEYLEN
, &v
);
392 ok
= evp_do_ciph_getparams(cipher
, params
);
394 return ok
!= 0 ? v
: -1;
397 int EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX
*ctx
)
399 int ok
, v
= ctx
->key_len
;
400 OSSL_PARAM params
[2] = { OSSL_PARAM_END
, OSSL_PARAM_END
};
402 params
[0] = OSSL_PARAM_construct_int(OSSL_CIPHER_PARAM_KEYLEN
, &v
);
403 ok
= evp_do_ciph_ctx_getparams(ctx
->cipher
, ctx
->provctx
, params
);
405 return ok
!= 0 ? v
: -1;
408 int EVP_CIPHER_nid(const EVP_CIPHER
*cipher
)
413 int EVP_CIPHER_CTX_nid(const EVP_CIPHER_CTX
*ctx
)
415 return ctx
->cipher
->nid
;
418 const char *EVP_CIPHER_name(const EVP_CIPHER
*cipher
)
420 if (cipher
->prov
!= NULL
)
423 return OBJ_nid2sn(EVP_CIPHER_nid(cipher
));
429 int EVP_CIPHER_mode(const EVP_CIPHER
*cipher
)
431 int ok
, v
= EVP_CIPHER_flags(cipher
) & EVP_CIPH_MODE
;
432 OSSL_PARAM params
[2] = { OSSL_PARAM_END
, OSSL_PARAM_END
};
434 params
[0] = OSSL_PARAM_construct_int(OSSL_CIPHER_PARAM_MODE
, &v
);
435 ok
= evp_do_ciph_getparams(cipher
, params
);
437 return ok
!= 0 ? v
: 0;
440 const char *EVP_MD_name(const EVP_MD
*md
)
442 if (md
->prov
!= NULL
)
445 return OBJ_nid2sn(EVP_MD_nid(md
));
451 int EVP_MD_block_size(const EVP_MD
*md
)
454 EVPerr(EVP_F_EVP_MD_BLOCK_SIZE
, EVP_R_MESSAGE_DIGEST_IS_NULL
);
458 if (md
->prov
!= NULL
&& md
->dblock_size
!= NULL
)
459 return (int)md
->dblock_size();
461 return md
->block_size
;
464 int EVP_MD_type(const EVP_MD
*md
)
469 int EVP_MD_pkey_type(const EVP_MD
*md
)
471 return md
->pkey_type
;
474 int EVP_MD_size(const EVP_MD
*md
)
477 EVPerr(EVP_F_EVP_MD_SIZE
, EVP_R_MESSAGE_DIGEST_IS_NULL
);
481 if (md
->prov
!= NULL
&& md
->size
!= NULL
)
482 return (int)md
->size();
487 unsigned long EVP_MD_flags(const EVP_MD
*md
)
492 EVP_MD
*EVP_MD_meth_new(int md_type
, int pkey_type
)
494 EVP_MD
*md
= OPENSSL_zalloc(sizeof(*md
));
498 md
->pkey_type
= pkey_type
;
499 md
->lock
= CRYPTO_THREAD_lock_new();
500 if (md
->lock
== NULL
) {
509 EVP_MD
*EVP_MD_meth_dup(const EVP_MD
*md
)
511 EVP_MD
*to
= EVP_MD_meth_new(md
->type
, md
->pkey_type
);
514 CRYPTO_RWLOCK
*lock
= to
->lock
;
515 memcpy(to
, md
, sizeof(*to
));
521 int EVP_MD_up_ref(EVP_MD
*md
)
525 CRYPTO_UP_REF(&md
->refcnt
, &ref
, md
->lock
);
529 void EVP_MD_meth_free(EVP_MD
*md
)
534 CRYPTO_DOWN_REF(&md
->refcnt
, &i
, md
->lock
);
537 ossl_provider_free(md
->prov
);
538 OPENSSL_free(md
->name
);
539 CRYPTO_THREAD_lock_free(md
->lock
);
543 int EVP_MD_meth_set_input_blocksize(EVP_MD
*md
, int blocksize
)
545 md
->block_size
= blocksize
;
548 int EVP_MD_meth_set_result_size(EVP_MD
*md
, int resultsize
)
550 md
->md_size
= resultsize
;
553 int EVP_MD_meth_set_app_datasize(EVP_MD
*md
, int datasize
)
555 md
->ctx_size
= datasize
;
558 int EVP_MD_meth_set_flags(EVP_MD
*md
, unsigned long flags
)
563 int EVP_MD_meth_set_init(EVP_MD
*md
, int (*init
)(EVP_MD_CTX
*ctx
))
568 int EVP_MD_meth_set_update(EVP_MD
*md
, int (*update
)(EVP_MD_CTX
*ctx
,
575 int EVP_MD_meth_set_final(EVP_MD
*md
, int (*final
)(EVP_MD_CTX
*ctx
,
581 int EVP_MD_meth_set_copy(EVP_MD
*md
, int (*copy
)(EVP_MD_CTX
*to
,
582 const EVP_MD_CTX
*from
))
587 int EVP_MD_meth_set_cleanup(EVP_MD
*md
, int (*cleanup
)(EVP_MD_CTX
*ctx
))
589 md
->cleanup
= cleanup
;
592 int EVP_MD_meth_set_ctrl(EVP_MD
*md
, int (*ctrl
)(EVP_MD_CTX
*ctx
, int cmd
,
599 int EVP_MD_meth_get_input_blocksize(const EVP_MD
*md
)
601 return md
->block_size
;
603 int EVP_MD_meth_get_result_size(const EVP_MD
*md
)
607 int EVP_MD_meth_get_app_datasize(const EVP_MD
*md
)
611 unsigned long EVP_MD_meth_get_flags(const EVP_MD
*md
)
615 int (*EVP_MD_meth_get_init(const EVP_MD
*md
))(EVP_MD_CTX
*ctx
)
619 int (*EVP_MD_meth_get_update(const EVP_MD
*md
))(EVP_MD_CTX
*ctx
,
625 int (*EVP_MD_meth_get_final(const EVP_MD
*md
))(EVP_MD_CTX
*ctx
,
630 int (*EVP_MD_meth_get_copy(const EVP_MD
*md
))(EVP_MD_CTX
*to
,
631 const EVP_MD_CTX
*from
)
635 int (*EVP_MD_meth_get_cleanup(const EVP_MD
*md
))(EVP_MD_CTX
*ctx
)
639 int (*EVP_MD_meth_get_ctrl(const EVP_MD
*md
))(EVP_MD_CTX
*ctx
, int cmd
,
645 const EVP_MD
*EVP_MD_CTX_md(const EVP_MD_CTX
*ctx
)
649 return ctx
->reqdigest
;
652 EVP_PKEY_CTX
*EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX
*ctx
)
657 #if !defined(FIPS_MODE)
658 /* TODO(3.0): EVP_DigestSign* not yet supported in FIPS module */
659 void EVP_MD_CTX_set_pkey_ctx(EVP_MD_CTX
*ctx
, EVP_PKEY_CTX
*pctx
)
662 * it's reasonable to set NULL pctx (a.k.a clear the ctx->pctx), so
663 * we have to deal with the cleanup job here.
665 if (!EVP_MD_CTX_test_flags(ctx
, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX
))
666 EVP_PKEY_CTX_free(ctx
->pctx
);
671 /* make sure pctx is not freed when destroying EVP_MD_CTX */
672 EVP_MD_CTX_set_flags(ctx
, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX
);
674 EVP_MD_CTX_clear_flags(ctx
, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX
);
677 #endif /* !defined(FIPS_MODE) */
679 void *EVP_MD_CTX_md_data(const EVP_MD_CTX
*ctx
)
684 int (*EVP_MD_CTX_update_fn(EVP_MD_CTX
*ctx
))(EVP_MD_CTX
*ctx
,
685 const void *data
, size_t count
)
690 void EVP_MD_CTX_set_update_fn(EVP_MD_CTX
*ctx
,
691 int (*update
) (EVP_MD_CTX
*ctx
,
692 const void *data
, size_t count
))
694 ctx
->update
= update
;
697 void EVP_MD_CTX_set_flags(EVP_MD_CTX
*ctx
, int flags
)
702 void EVP_MD_CTX_clear_flags(EVP_MD_CTX
*ctx
, int flags
)
704 ctx
->flags
&= ~flags
;
707 int EVP_MD_CTX_test_flags(const EVP_MD_CTX
*ctx
, int flags
)
709 return (ctx
->flags
& flags
);
712 void EVP_CIPHER_CTX_set_flags(EVP_CIPHER_CTX
*ctx
, int flags
)
717 void EVP_CIPHER_CTX_clear_flags(EVP_CIPHER_CTX
*ctx
, int flags
)
719 ctx
->flags
&= ~flags
;
722 int EVP_CIPHER_CTX_test_flags(const EVP_CIPHER_CTX
*ctx
, int flags
)
724 return (ctx
->flags
& flags
);
727 int EVP_str2ctrl(int (*cb
)(void *ctx
, int cmd
, void *buf
, size_t buflen
),
728 void *ctx
, int cmd
, const char *value
)
735 return cb(ctx
, cmd
, (void *)value
, len
);
738 int EVP_hex2ctrl(int (*cb
)(void *ctx
, int cmd
, void *buf
, size_t buflen
),
739 void *ctx
, int cmd
, const char *hex
)
745 bin
= OPENSSL_hexstr2buf(hex
, &binlen
);
748 if (binlen
<= INT_MAX
)
749 rv
= cb(ctx
, cmd
, bin
, binlen
);
755 # ifndef OPENSSL_NO_DH
757 * TODO(3.0): Temporarily unavailable in FIPS mode. This will need to be added
761 # define MAX_PARAMS 10
763 /* Number of the current param */
766 /* Key for the current param */
768 /* Value for the current param */
769 const BIGNUM
*bnparam
;
770 /* Size of the buffer required for the BN */
772 } params
[MAX_PARAMS
];
773 /* Running count of the total size required */
778 static int push_param_bn(PARAMS_TEMPLATE
*tmpl
, const char *key
,
783 sz
= BN_num_bytes(bn
);
786 tmpl
->params
[tmpl
->curr
].key
= key
;
787 tmpl
->params
[tmpl
->curr
].bnparam
= bn
;
788 tmpl
->params
[tmpl
->curr
++].bufsz
= (size_t)sz
;
789 tmpl
->totsz
+= sizeof(OSSL_PARAM
) + (size_t)sz
;
794 static OSSL_PARAM
*param_template_to_param(PARAMS_TEMPLATE
*tmpl
, size_t *sz
)
798 OSSL_PARAM
*param
= NULL
;
799 unsigned char *currbuf
= NULL
;
801 if (tmpl
->totsz
== 0)
804 /* Add some space for the end of OSSL_PARAM marker */
805 tmpl
->totsz
+= sizeof(*param
);
808 buf
= OPENSSL_zalloc(tmpl
->totsz
);
810 buf
= OPENSSL_secure_zalloc(tmpl
->totsz
);
815 currbuf
= (unsigned char *)buf
+ (sizeof(*param
) * (tmpl
->curr
+ 1));
817 for (i
= 0; i
< tmpl
->curr
; i
++) {
818 if (!ossl_assert((currbuf
- (unsigned char *)buf
)
819 + tmpl
->params
[i
].bufsz
<= tmpl
->totsz
))
821 if (BN_bn2nativepad(tmpl
->params
[i
].bnparam
, currbuf
,
822 tmpl
->params
[i
].bufsz
) < 0)
824 param
[i
] = OSSL_PARAM_construct_BN(tmpl
->params
[i
].key
, currbuf
,
825 tmpl
->params
[i
].bufsz
);
826 currbuf
+= tmpl
->params
[i
].bufsz
;
828 param
[i
] = OSSL_PARAM_construct_end();
838 OPENSSL_clear_free(param
, tmpl
->totsz
);
842 static OSSL_PARAM
*evp_pkey_dh_to_param(EVP_PKEY
*pkey
, size_t *sz
)
844 DH
*dh
= pkey
->pkey
.dh
;
845 PARAMS_TEMPLATE tmpl
= {0};
846 const BIGNUM
*p
= DH_get0_p(dh
), *g
= DH_get0_g(dh
), *q
= DH_get0_q(dh
);
847 const BIGNUM
*pub_key
= DH_get0_pub_key(dh
);
848 const BIGNUM
*priv_key
= DH_get0_priv_key(dh
);
850 if (p
== NULL
|| g
== NULL
|| pub_key
== NULL
)
853 if (!push_param_bn(&tmpl
, OSSL_PKEY_PARAM_DH_P
, p
)
854 || !push_param_bn(&tmpl
, OSSL_PKEY_PARAM_DH_G
, g
)
855 || !push_param_bn(&tmpl
, OSSL_PKEY_PARAM_DH_PUB_KEY
, pub_key
))
859 if (!push_param_bn(&tmpl
, OSSL_PKEY_PARAM_DH_Q
, q
))
863 if (priv_key
!= NULL
) {
864 if (!push_param_bn(&tmpl
, OSSL_PKEY_PARAM_DH_PRIV_KEY
, priv_key
))
870 return param_template_to_param(&tmpl
, sz
);
872 # endif /* OPENSSL_NO_DH */
874 OSSL_PARAM
*evp_pkey_to_param(EVP_PKEY
*pkey
, size_t *sz
)
876 switch (pkey
->type
) {
877 # ifndef OPENSSL_NO_DH
879 return evp_pkey_dh_to_param(pkey
, sz
);
886 #endif /* FIPS_MODE */