blob: 752547d1e6cc00e41b50fe35052b6aab16584f63 [file] [log] [blame]
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00001/* crypto/evp/p_lib.c */
Ralf S. Engelschall58964a41998-12-21 10:56:39 +00002/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00003 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
Bodo Möller4d94ae02002-02-13 18:21:51 +000061#include <openssl/bn.h>
62#include <openssl/err.h>
Bodo Möllerec577821999-04-23 22:13:45 +000063#include <openssl/objects.h>
64#include <openssl/evp.h>
65#include <openssl/asn1_mac.h>
66#include <openssl/x509.h>
Nils Larsch3eeaab42005-07-16 12:37:36 +000067#ifndef OPENSSL_NO_RSA
Geoff Thorpe60a938c2004-04-19 18:09:28 +000068#include <openssl/rsa.h>
Nils Larsch3eeaab42005-07-16 12:37:36 +000069#endif
70#ifndef OPENSSL_NO_DSA
Geoff Thorpe60a938c2004-04-19 18:09:28 +000071#include <openssl/dsa.h>
Nils Larsch3eeaab42005-07-16 12:37:36 +000072#endif
73#ifndef OPENSSL_NO_DH
Geoff Thorpe60a938c2004-04-19 18:09:28 +000074#include <openssl/dh.h>
Nils Larsch3eeaab42005-07-16 12:37:36 +000075#endif
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000076
Dr. Stephen Henson18e377b2006-03-22 17:59:49 +000077#include "asn1_locl.h"
78
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000079static void EVP_PKEY_free_it(EVP_PKEY *x);
Ben Lauriebb2297a2001-08-03 18:48:35 +000080
Ulf Möller6b691a51999-04-19 21:31:43 +000081int EVP_PKEY_bits(EVP_PKEY *pkey)
Ralf S. Engelschall58964a41998-12-21 10:56:39 +000082 {
Dr. Stephen Henson6f818922006-03-20 17:56:05 +000083 if (pkey && pkey->ameth && pkey->ameth->pkey_bits)
84 return pkey->ameth->pkey_bits(pkey);
85 return 0;
Ralf S. Engelschall58964a41998-12-21 10:56:39 +000086 }
87
Ulf Möller6b691a51999-04-19 21:31:43 +000088int EVP_PKEY_size(EVP_PKEY *pkey)
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000089 {
Dr. Stephen Henson6f818922006-03-20 17:56:05 +000090 if (pkey && pkey->ameth && pkey->ameth->pkey_size)
91 return pkey->ameth->pkey_size(pkey);
92 return 0;
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000093 }
94
Ulf Möller6b691a51999-04-19 21:31:43 +000095int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode)
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000096 {
Richard Levittecf1b7d92001-02-19 16:06:34 +000097#ifndef OPENSSL_NO_DSA
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000098 if (pkey->type == EVP_PKEY_DSA)
99 {
Richard Levittebc8a9f12000-11-06 21:12:21 +0000100 int ret=pkey->save_parameters;
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000101
102 if (mode >= 0)
103 pkey->save_parameters=mode;
104 return(ret);
105 }
106#endif
Bodo Möller5488bb62002-08-12 08:47:41 +0000107#ifndef OPENSSL_NO_EC
108 if (pkey->type == EVP_PKEY_EC)
Bodo Möller4d94ae02002-02-13 18:21:51 +0000109 {
110 int ret = pkey->save_parameters;
111
112 if (mode >= 0)
113 pkey->save_parameters = mode;
114 return(ret);
115 }
116#endif
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000117 return(0);
118 }
119
Richard Levittea8b72842003-04-07 10:09:44 +0000120int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000121 {
122 if (to->type != from->type)
123 {
124 EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_DIFFERENT_KEY_TYPES);
Ralf S. Engelschall58964a41998-12-21 10:56:39 +0000125 goto err;
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000126 }
127
128 if (EVP_PKEY_missing_parameters(from))
129 {
Ulf Möller657e60f2000-02-03 23:23:24 +0000130 EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_MISSING_PARAMETERS);
Ralf S. Engelschall58964a41998-12-21 10:56:39 +0000131 goto err;
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000132 }
Dr. Stephen Henson6f818922006-03-20 17:56:05 +0000133 if (from->ameth && from->ameth->param_copy)
134 return from->ameth->param_copy(to, from);
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000135err:
Dr. Stephen Henson6f818922006-03-20 17:56:05 +0000136 return 0;
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000137 }
138
Richard Levitteaf0f0f32003-04-06 15:31:18 +0000139int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey)
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000140 {
Dr. Stephen Henson6f818922006-03-20 17:56:05 +0000141 if (pkey->ameth && pkey->ameth->param_missing)
142 return pkey->ameth->param_missing(pkey);
143 return 0;
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000144 }
145
Richard Levitteaf0f0f32003-04-06 15:31:18 +0000146int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b)
Ralf S. Engelschall58964a41998-12-21 10:56:39 +0000147 {
Dr. Stephen Henson6f818922006-03-20 17:56:05 +0000148 if (a->type != b->type)
149 return -1;
150 if (a->ameth && a->ameth->param_cmp)
151 return a->ameth->param_cmp(a, b);
Dr. Stephen Hensonb4634352006-04-28 12:27:37 +0000152 return -2;
Ralf S. Engelschall58964a41998-12-21 10:56:39 +0000153 }
154
Richard Levitteaf0f0f32003-04-06 15:31:18 +0000155int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b)
Richard Levittee6526fb2003-04-03 22:27:24 +0000156 {
157 if (a->type != b->type)
158 return -1;
159
Richard Levitte7b365902003-04-07 10:15:32 +0000160 if (EVP_PKEY_cmp_parameters(a, b) == 0)
161 return 0;
Richard Levittea8b72842003-04-07 10:09:44 +0000162
Dr. Stephen Henson6f818922006-03-20 17:56:05 +0000163 if (a->ameth && a->ameth->pub_cmp)
164 return a->ameth->pub_cmp(a, b);
Richard Levittee6526fb2003-04-03 22:27:24 +0000165
Dr. Stephen Henson6f818922006-03-20 17:56:05 +0000166 return -2;
Richard Levittee6526fb2003-04-03 22:27:24 +0000167 }
168
Ulf Möller6b691a51999-04-19 21:31:43 +0000169EVP_PKEY *EVP_PKEY_new(void)
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000170 {
171 EVP_PKEY *ret;
172
Richard Levitte26a3a482000-06-01 22:19:21 +0000173 ret=(EVP_PKEY *)OPENSSL_malloc(sizeof(EVP_PKEY));
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000174 if (ret == NULL)
175 {
176 EVPerr(EVP_F_EVP_PKEY_NEW,ERR_R_MALLOC_FAILURE);
177 return(NULL);
178 }
179 ret->type=EVP_PKEY_NONE;
180 ret->references=1;
Dr. Stephen Henson6f818922006-03-20 17:56:05 +0000181 ret->ameth=NULL;
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000182 ret->pkey.ptr=NULL;
183 ret->attributes=NULL;
184 ret->save_parameters=1;
185 return(ret);
186 }
187
Dr. Stephen Henson732a40e2006-04-05 13:04:02 +0000188int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key)
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000189 {
Dr. Stephen Henson6f818922006-03-20 17:56:05 +0000190 const EVP_PKEY_ASN1_METHOD *ameth;
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000191 if (pkey == NULL) return(0);
192 if (pkey->pkey.ptr != NULL)
193 EVP_PKEY_free_it(pkey);
Dr. Stephen Henson18e377b2006-03-22 17:59:49 +0000194 ameth = EVP_PKEY_asn1_find(type);
Dr. Stephen Henson6f818922006-03-20 17:56:05 +0000195 pkey->ameth = ameth;
196 pkey->type = ameth->pkey_id;
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000197 pkey->save_type=type;
198 pkey->pkey.ptr=key;
Bodo Möller7f5b6f02000-01-14 18:41:28 +0000199 return(key != NULL);
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000200 }
201
Dr. Stephen Hensondb98bbc2006-03-24 13:46:58 +0000202void *EVP_PKEY_get0(EVP_PKEY *pkey)
203 {
204 return pkey->pkey.ptr;
205 }
206
Richard Levittecf1b7d92001-02-19 16:06:34 +0000207#ifndef OPENSSL_NO_RSA
Dr. Stephen Hensonc7cb16a2000-02-26 01:55:33 +0000208int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key)
Dr. Stephen Henson52664f51999-11-21 22:28:31 +0000209{
Dr. Stephen Henson6d3724d1999-11-23 18:50:28 +0000210 int ret = EVP_PKEY_assign_RSA(pkey, key);
Geoff Thorpe78435362001-08-25 17:28:23 +0000211 if(ret)
Bodo Möller6ac4e8b2001-09-03 13:40:07 +0000212 RSA_up_ref(key);
Dr. Stephen Henson6d3724d1999-11-23 18:50:28 +0000213 return ret;
Dr. Stephen Henson52664f51999-11-21 22:28:31 +0000214}
215
Dr. Stephen Hensonc7cb16a2000-02-26 01:55:33 +0000216RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey)
Dr. Stephen Hensonf769ce31999-10-25 02:00:09 +0000217 {
218 if(pkey->type != EVP_PKEY_RSA) {
Dr. Stephen Hensonc7cb16a2000-02-26 01:55:33 +0000219 EVPerr(EVP_F_EVP_PKEY_GET1_RSA, EVP_R_EXPECTING_AN_RSA_KEY);
Dr. Stephen Hensonf769ce31999-10-25 02:00:09 +0000220 return NULL;
221 }
Bodo Möller6ac4e8b2001-09-03 13:40:07 +0000222 RSA_up_ref(pkey->pkey.rsa);
Dr. Stephen Hensonf769ce31999-10-25 02:00:09 +0000223 return pkey->pkey.rsa;
224}
225#endif
226
Richard Levittecf1b7d92001-02-19 16:06:34 +0000227#ifndef OPENSSL_NO_DSA
Dr. Stephen Hensonc7cb16a2000-02-26 01:55:33 +0000228int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key)
Dr. Stephen Henson52664f51999-11-21 22:28:31 +0000229{
Dr. Stephen Henson6d3724d1999-11-23 18:50:28 +0000230 int ret = EVP_PKEY_assign_DSA(pkey, key);
Geoff Thorpe78435362001-08-25 17:28:23 +0000231 if(ret)
Bodo Möller6ac4e8b2001-09-03 13:40:07 +0000232 DSA_up_ref(key);
Dr. Stephen Henson6d3724d1999-11-23 18:50:28 +0000233 return ret;
Dr. Stephen Henson52664f51999-11-21 22:28:31 +0000234}
235
Dr. Stephen Hensonc7cb16a2000-02-26 01:55:33 +0000236DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey)
Dr. Stephen Hensonf769ce31999-10-25 02:00:09 +0000237 {
238 if(pkey->type != EVP_PKEY_DSA) {
Dr. Stephen Hensonc7cb16a2000-02-26 01:55:33 +0000239 EVPerr(EVP_F_EVP_PKEY_GET1_DSA, EVP_R_EXPECTING_A_DSA_KEY);
Dr. Stephen Hensonf769ce31999-10-25 02:00:09 +0000240 return NULL;
241 }
Bodo Möller6ac4e8b2001-09-03 13:40:07 +0000242 DSA_up_ref(pkey->pkey.dsa);
Dr. Stephen Hensonf769ce31999-10-25 02:00:09 +0000243 return pkey->pkey.dsa;
244}
245#endif
246
Bodo Möller14a7cfb2002-08-07 10:49:54 +0000247#ifndef OPENSSL_NO_EC
Bodo Möller4d94ae02002-02-13 18:21:51 +0000248
Bodo Möller14a7cfb2002-08-07 10:49:54 +0000249int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, EC_KEY *key)
Bodo Möller4d94ae02002-02-13 18:21:51 +0000250{
Bodo Möller14a7cfb2002-08-07 10:49:54 +0000251 int ret = EVP_PKEY_assign_EC_KEY(pkey,key);
Nils Larsch9dd84052005-05-16 10:11:04 +0000252 if (ret)
253 EC_KEY_up_ref(key);
254 return ret;
Bodo Möller4d94ae02002-02-13 18:21:51 +0000255}
256
Bodo Möller14a7cfb2002-08-07 10:49:54 +0000257EC_KEY *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey)
Bodo Möller4d94ae02002-02-13 18:21:51 +0000258{
Bodo Möller14a7cfb2002-08-07 10:49:54 +0000259 if (pkey->type != EVP_PKEY_EC)
Bodo Möller4d94ae02002-02-13 18:21:51 +0000260 {
Bodo Möller14a7cfb2002-08-07 10:49:54 +0000261 EVPerr(EVP_F_EVP_PKEY_GET1_EC_KEY, EVP_R_EXPECTING_A_EC_KEY);
Bodo Möller4d94ae02002-02-13 18:21:51 +0000262 return NULL;
263 }
Nils Larsch9dd84052005-05-16 10:11:04 +0000264 EC_KEY_up_ref(pkey->pkey.ec);
265 return pkey->pkey.ec;
Bodo Möller4d94ae02002-02-13 18:21:51 +0000266}
267#endif
268
269
Richard Levittecf1b7d92001-02-19 16:06:34 +0000270#ifndef OPENSSL_NO_DH
Dr. Stephen Henson52664f51999-11-21 22:28:31 +0000271
Dr. Stephen Hensonc7cb16a2000-02-26 01:55:33 +0000272int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key)
Dr. Stephen Henson52664f51999-11-21 22:28:31 +0000273{
Dr. Stephen Henson6d3724d1999-11-23 18:50:28 +0000274 int ret = EVP_PKEY_assign_DH(pkey, key);
Geoff Thorpe78435362001-08-25 17:28:23 +0000275 if(ret)
Geoff Thorpee815d302001-09-05 17:02:35 +0000276 DH_up_ref(key);
Dr. Stephen Henson6d3724d1999-11-23 18:50:28 +0000277 return ret;
Dr. Stephen Henson52664f51999-11-21 22:28:31 +0000278}
279
Dr. Stephen Hensonc7cb16a2000-02-26 01:55:33 +0000280DH *EVP_PKEY_get1_DH(EVP_PKEY *pkey)
Dr. Stephen Hensonf769ce31999-10-25 02:00:09 +0000281 {
282 if(pkey->type != EVP_PKEY_DH) {
Dr. Stephen Hensonc7cb16a2000-02-26 01:55:33 +0000283 EVPerr(EVP_F_EVP_PKEY_GET1_DH, EVP_R_EXPECTING_A_DH_KEY);
Dr. Stephen Hensonf769ce31999-10-25 02:00:09 +0000284 return NULL;
285 }
Geoff Thorpee815d302001-09-05 17:02:35 +0000286 DH_up_ref(pkey->pkey.dh);
Dr. Stephen Hensonf769ce31999-10-25 02:00:09 +0000287 return pkey->pkey.dh;
288}
289#endif
290
Ulf Möller6b691a51999-04-19 21:31:43 +0000291int EVP_PKEY_type(int type)
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000292 {
Dr. Stephen Henson6f818922006-03-20 17:56:05 +0000293 const EVP_PKEY_ASN1_METHOD *ameth;
Dr. Stephen Henson18e377b2006-03-22 17:59:49 +0000294 ameth = EVP_PKEY_asn1_find(type);
Dr. Stephen Henson6f818922006-03-20 17:56:05 +0000295 if (ameth)
296 return ameth->pkey_id;
297 return NID_undef;
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000298 }
299
Dr. Stephen Henson7f57b072006-05-11 21:33:00 +0000300int EVP_PKEY_id(const EVP_PKEY *pkey)
301 {
302 return pkey->type;
303 }
304
305int EVP_PKEY_base_id(const EVP_PKEY *pkey)
306 {
307 return EVP_PKEY_type(pkey->type);
308 }
309
Ulf Möller6b691a51999-04-19 21:31:43 +0000310void EVP_PKEY_free(EVP_PKEY *x)
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000311 {
312 int i;
313
314 if (x == NULL) return;
315
316 i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_EVP_PKEY);
Ralf S. Engelschall58964a41998-12-21 10:56:39 +0000317#ifdef REF_PRINT
318 REF_PRINT("EVP_PKEY",x);
319#endif
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000320 if (i > 0) return;
321#ifdef REF_CHECK
322 if (i < 0)
323 {
324 fprintf(stderr,"EVP_PKEY_free, bad reference count\n");
325 abort();
326 }
327#endif
328 EVP_PKEY_free_it(x);
Dr. Stephen Hensonb6995ad2005-05-15 00:54:45 +0000329 if (x->attributes)
330 sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free);
Richard Levitte26a3a482000-06-01 22:19:21 +0000331 OPENSSL_free(x);
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000332 }
333
Ulf Möller6b691a51999-04-19 21:31:43 +0000334static void EVP_PKEY_free_it(EVP_PKEY *x)
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000335 {
Dr. Stephen Henson6f818922006-03-20 17:56:05 +0000336 if (x->ameth && x->ameth->pkey_free)
337 x->ameth->pkey_free(x);
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000338 }
339
Dr. Stephen Henson35208f32006-03-22 13:09:35 +0000340static int unsup_alg(BIO *out, const EVP_PKEY *pkey, int indent,
341 const char *kstr)
342 {
343 BIO_indent(out, indent, 128);
344 BIO_printf(out, "%s %s, algorithm, unsupported\n",
345 OBJ_nid2ln(pkey->type), kstr);
346 return 1;
347 }
348
349int EVP_PKEY_print_public(BIO *out, const EVP_PKEY *pkey,
350 int indent, ASN1_PCTX *pctx)
351 {
352 if (pkey->ameth && pkey->ameth->pub_print)
353 return pkey->ameth->pub_print(out, pkey, indent, pctx);
354
355 return unsup_alg(out, pkey, indent, "Public Key");
356 }
357
358int EVP_PKEY_print_private(BIO *out, const EVP_PKEY *pkey,
359 int indent, ASN1_PCTX *pctx)
360 {
361 if (pkey->ameth && pkey->ameth->priv_print)
362 return pkey->ameth->priv_print(out, pkey, indent, pctx);
363
364 return unsup_alg(out, pkey, indent, "Private Key");
365 }
366
367int EVP_PKEY_print_params(BIO *out, const EVP_PKEY *pkey,
368 int indent, ASN1_PCTX *pctx)
369 {
370 if (pkey->ameth && pkey->ameth->param_print)
371 return pkey->ameth->param_print(out, pkey, indent, pctx);
372 return unsup_alg(out, pkey, indent, "Parameters");
373 }
Dr. Stephen Henson03919682006-05-07 17:09:39 +0000374
375int EVP_PKEY_get_default_digest_nid(EVP_PKEY *pkey, int *pnid)
376 {
377 if (!pkey->ameth || !pkey->ameth->pkey_ctrl)
378 return -2;
379 return pkey->ameth->pkey_ctrl(pkey, ASN1_PKEY_CTRL_DEFAULT_MD_NID,
380 0, pnid);
381 }
382