]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/dsa/dsa_ameth.c
dsa.h: fix preprocessor indentation
[thirdparty/openssl.git] / crypto / dsa / dsa_ameth.c
CommitLineData
0f113f3e 1/*
d2e9e320 2 * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved.
448be743 3 *
3cdbea65 4 * Licensed under the Apache License 2.0 (the "License"). You may not use
d2e9e320
RS
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
448be743
DSH
8 */
9
10#include <stdio.h>
448be743
DSH
11#include <openssl/x509.h>
12#include <openssl/asn1.h>
1e26a8ba 13#include <openssl/bn.h>
3c27208f 14#include <openssl/cms.h>
4889dadc
MC
15#include <openssl/core_names.h>
16#include "internal/cryptlib.h"
25f2138b
DMSP
17#include "crypto/asn1.h"
18#include "crypto/evp.h"
4889dadc 19#include "internal/param_build.h"
706457b7 20#include "dsa_local.h"
448be743
DSH
21
22static int dsa_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey)
0f113f3e
MC
23{
24 const unsigned char *p, *pm;
25 int pklen, pmlen;
26 int ptype;
ac4e2577
DSH
27 const void *pval;
28 const ASN1_STRING *pstr;
0f113f3e
MC
29 X509_ALGOR *palg;
30 ASN1_INTEGER *public_key = NULL;
31
32 DSA *dsa = NULL;
33
34 if (!X509_PUBKEY_get0_param(NULL, &p, &pklen, &palg, pubkey))
35 return 0;
36 X509_ALGOR_get0(NULL, &ptype, &pval, palg);
37
38 if (ptype == V_ASN1_SEQUENCE) {
39 pstr = pval;
40 pm = pstr->data;
41 pmlen = pstr->length;
42
75ebbd9a 43 if ((dsa = d2i_DSAparams(NULL, &pm, pmlen)) == NULL) {
0f113f3e
MC
44 DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_DECODE_ERROR);
45 goto err;
46 }
47
48 } else if ((ptype == V_ASN1_NULL) || (ptype == V_ASN1_UNDEF)) {
75ebbd9a 49 if ((dsa = DSA_new()) == NULL) {
0f113f3e
MC
50 DSAerr(DSA_F_DSA_PUB_DECODE, ERR_R_MALLOC_FAILURE);
51 goto err;
52 }
53 } else {
54 DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_PARAMETER_ENCODING_ERROR);
55 goto err;
56 }
57
75ebbd9a 58 if ((public_key = d2i_ASN1_INTEGER(NULL, &p, pklen)) == NULL) {
0f113f3e
MC
59 DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_DECODE_ERROR);
60 goto err;
61 }
62
75ebbd9a 63 if ((dsa->pub_key = ASN1_INTEGER_to_BN(public_key, NULL)) == NULL) {
0f113f3e
MC
64 DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_BN_DECODE_ERROR);
65 goto err;
66 }
67
4889dadc 68 dsa->dirty_cnt++;
0f113f3e
MC
69 ASN1_INTEGER_free(public_key);
70 EVP_PKEY_assign_DSA(pkey, dsa);
71 return 1;
72
73 err:
2ace7450 74 ASN1_INTEGER_free(public_key);
d6407083 75 DSA_free(dsa);
0f113f3e
MC
76 return 0;
77
78}
448be743 79
6f81892e 80static int dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
0f113f3e
MC
81{
82 DSA *dsa;
0f113f3e
MC
83 int ptype;
84 unsigned char *penc = NULL;
85 int penclen;
0c7ca403 86 ASN1_STRING *str = NULL;
ea6b07b5 87 ASN1_INTEGER *pubint = NULL;
7760384b 88 ASN1_OBJECT *aobj;
0f113f3e
MC
89
90 dsa = pkey->pkey.dsa;
dc8de3e6
SL
91 if (pkey->save_parameters
92 && dsa->params.p != NULL
93 && dsa->params.q != NULL
94 && dsa->params.g != NULL) {
0f113f3e 95 str = ASN1_STRING_new();
90945fa3 96 if (str == NULL) {
0c7ca403
MC
97 DSAerr(DSA_F_DSA_PUB_ENCODE, ERR_R_MALLOC_FAILURE);
98 goto err;
99 }
0f113f3e
MC
100 str->length = i2d_DSAparams(dsa, &str->data);
101 if (str->length <= 0) {
102 DSAerr(DSA_F_DSA_PUB_ENCODE, ERR_R_MALLOC_FAILURE);
103 goto err;
104 }
0f113f3e
MC
105 ptype = V_ASN1_SEQUENCE;
106 } else
107 ptype = V_ASN1_UNDEF;
108
ea6b07b5 109 pubint = BN_to_ASN1_INTEGER(dsa->pub_key, NULL);
0f113f3e 110
ea6b07b5
DSH
111 if (pubint == NULL) {
112 DSAerr(DSA_F_DSA_PUB_ENCODE, ERR_R_MALLOC_FAILURE);
113 goto err;
114 }
115
116 penclen = i2d_ASN1_INTEGER(pubint, &penc);
117 ASN1_INTEGER_free(pubint);
0f113f3e
MC
118
119 if (penclen <= 0) {
120 DSAerr(DSA_F_DSA_PUB_ENCODE, ERR_R_MALLOC_FAILURE);
121 goto err;
122 }
123
7760384b
PK
124 aobj = OBJ_nid2obj(EVP_PKEY_DSA);
125 if (aobj == NULL)
126 goto err;
127
128 if (X509_PUBKEY_set0_param(pk, aobj, ptype, str, penc, penclen))
0f113f3e
MC
129 return 1;
130
131 err:
b548a1f1 132 OPENSSL_free(penc);
0dfb9398 133 ASN1_STRING_free(str);
0f113f3e
MC
134
135 return 0;
136}
137
138/*
139 * In PKCS#8 DSA: you just get a private key integer and parameters in the
448be743
DSH
140 * AlgorithmIdentifier the pubkey must be recalculated.
141 */
0f113f3e 142
245c6bc3 143static int dsa_priv_decode(EVP_PKEY *pkey, const PKCS8_PRIV_KEY_INFO *p8)
0f113f3e 144{
dfb10af9 145 const unsigned char *p, *pm;
0f113f3e
MC
146 int pklen, pmlen;
147 int ptype;
ac4e2577
DSH
148 const void *pval;
149 const ASN1_STRING *pstr;
245c6bc3 150 const X509_ALGOR *palg;
0f113f3e
MC
151 ASN1_INTEGER *privkey = NULL;
152 BN_CTX *ctx = NULL;
153
0f113f3e
MC
154 DSA *dsa = NULL;
155
ab4a81f6
DSH
156 int ret = 0;
157
0f113f3e
MC
158 if (!PKCS8_pkey_get0(NULL, &p, &pklen, &palg, p8))
159 return 0;
160 X509_ALGOR_get0(NULL, &ptype, &pval, palg);
161
ab4a81f6
DSH
162 if ((privkey = d2i_ASN1_INTEGER(NULL, &p, pklen)) == NULL)
163 goto decerr;
dfb10af9 164 if (privkey->type == V_ASN1_NEG_INTEGER || ptype != V_ASN1_SEQUENCE)
ab4a81f6 165 goto decerr;
0f113f3e
MC
166
167 pstr = pval;
168 pm = pstr->data;
169 pmlen = pstr->length;
75ebbd9a 170 if ((dsa = d2i_DSAparams(NULL, &pm, pmlen)) == NULL)
0f113f3e
MC
171 goto decerr;
172 /* We have parameters now set private key */
74924dcb
RS
173 if ((dsa->priv_key = BN_secure_new()) == NULL
174 || !ASN1_INTEGER_to_BN(privkey, dsa->priv_key)) {
0f113f3e
MC
175 DSAerr(DSA_F_DSA_PRIV_DECODE, DSA_R_BN_ERROR);
176 goto dsaerr;
177 }
178 /* Calculate public key */
75ebbd9a 179 if ((dsa->pub_key = BN_new()) == NULL) {
0f113f3e
MC
180 DSAerr(DSA_F_DSA_PRIV_DECODE, ERR_R_MALLOC_FAILURE);
181 goto dsaerr;
182 }
75ebbd9a 183 if ((ctx = BN_CTX_new()) == NULL) {
0f113f3e
MC
184 DSAerr(DSA_F_DSA_PRIV_DECODE, ERR_R_MALLOC_FAILURE);
185 goto dsaerr;
186 }
187
6364475a 188 BN_set_flags(dsa->priv_key, BN_FLG_CONSTTIME);
dc8de3e6
SL
189 if (!BN_mod_exp(dsa->pub_key, dsa->params.g, dsa->priv_key, dsa->params.p,
190 ctx)) {
0f113f3e
MC
191 DSAerr(DSA_F_DSA_PRIV_DECODE, DSA_R_BN_ERROR);
192 goto dsaerr;
193 }
194
4889dadc 195 dsa->dirty_cnt++;
0f113f3e 196 EVP_PKEY_assign_DSA(pkey, dsa);
0f113f3e 197
ab4a81f6
DSH
198 ret = 1;
199 goto done;
0f113f3e
MC
200
201 decerr:
f6fb7f18 202 DSAerr(DSA_F_DSA_PRIV_DECODE, DSA_R_DECODE_ERROR);
0f113f3e 203 dsaerr:
ab4a81f6
DSH
204 DSA_free(dsa);
205 done:
0f113f3e 206 BN_CTX_free(ctx);
2ace7450 207 ASN1_STRING_clear_free(privkey);
ab4a81f6 208 return ret;
0f113f3e 209}
448be743 210
6f81892e 211static int dsa_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey)
448be743 212{
0f113f3e
MC
213 ASN1_STRING *params = NULL;
214 ASN1_INTEGER *prkey = NULL;
215 unsigned char *dp = NULL;
216 int dplen;
217
12a765a5 218 if (pkey->pkey.dsa == NULL|| pkey->pkey.dsa->priv_key == NULL) {
0f113f3e
MC
219 DSAerr(DSA_F_DSA_PRIV_ENCODE, DSA_R_MISSING_PARAMETERS);
220 goto err;
221 }
222
223 params = ASN1_STRING_new();
224
90945fa3 225 if (params == NULL) {
0f113f3e
MC
226 DSAerr(DSA_F_DSA_PRIV_ENCODE, ERR_R_MALLOC_FAILURE);
227 goto err;
228 }
229
230 params->length = i2d_DSAparams(pkey->pkey.dsa, &params->data);
231 if (params->length <= 0) {
232 DSAerr(DSA_F_DSA_PRIV_ENCODE, ERR_R_MALLOC_FAILURE);
233 goto err;
234 }
235 params->type = V_ASN1_SEQUENCE;
236
237 /* Get private key into integer */
238 prkey = BN_to_ASN1_INTEGER(pkey->pkey.dsa->priv_key, NULL);
239
12a765a5 240 if (prkey == NULL) {
0f113f3e
MC
241 DSAerr(DSA_F_DSA_PRIV_ENCODE, DSA_R_BN_ERROR);
242 goto err;
243 }
244
245 dplen = i2d_ASN1_INTEGER(prkey, &dp);
246
a8ae0891 247 ASN1_STRING_clear_free(prkey);
fa4629b6 248 prkey = NULL;
0f113f3e
MC
249
250 if (!PKCS8_pkey_set0(p8, OBJ_nid2obj(NID_dsa), 0,
251 V_ASN1_SEQUENCE, params, dp, dplen))
252 goto err;
253
254 return 1;
255
256 err:
b548a1f1 257 OPENSSL_free(dp);
0dfb9398 258 ASN1_STRING_free(params);
2ace7450 259 ASN1_STRING_clear_free(prkey);
0f113f3e 260 return 0;
448be743
DSH
261}
262
6f81892e 263static int int_dsa_size(const EVP_PKEY *pkey)
0f113f3e 264{
26a7d938 265 return DSA_size(pkey->pkey.dsa);
0f113f3e 266}
6f81892e
DSH
267
268static int dsa_bits(const EVP_PKEY *pkey)
0f113f3e 269{
5d8d9a8e 270 return DSA_bits(pkey->pkey.dsa);
0f113f3e 271}
6f81892e 272
2514fa79 273static int dsa_security_bits(const EVP_PKEY *pkey)
0f113f3e
MC
274{
275 return DSA_security_bits(pkey->pkey.dsa);
276}
2514fa79 277
6f81892e 278static int dsa_missing_parameters(const EVP_PKEY *pkey)
0f113f3e
MC
279{
280 DSA *dsa;
281 dsa = pkey->pkey.dsa;
dc8de3e6
SL
282 return dsa == NULL
283 || dsa->params.p == NULL
284 || dsa->params.q == NULL
285 || dsa->params.g == NULL;
0f113f3e 286}
6f81892e
DSH
287
288static int dsa_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)
0f113f3e 289{
2986ecdc
DSH
290 if (to->pkey.dsa == NULL) {
291 to->pkey.dsa = DSA_new();
292 if (to->pkey.dsa == NULL)
293 return 0;
294 }
dc8de3e6 295 if (!ffc_params_copy(&to->pkey.dsa->params, &from->pkey.dsa->params))
0f113f3e 296 return 0;
0f113f3e 297
4889dadc 298 to->pkey.dsa->dirty_cnt++;
0f113f3e
MC
299 return 1;
300}
6f81892e
DSH
301
302static int dsa_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b)
0f113f3e 303{
dc8de3e6 304 return ffc_params_cmp(&a->pkey.dsa->params, &b->pkey.dsa->params, 1);
0f113f3e 305}
6f81892e 306
0cb8499b 307static int dsa_pub_cmp(const EVP_PKEY *a, const EVP_PKEY *b)
0f113f3e 308{
dc8de3e6 309 return BN_cmp(b->pkey.dsa->pub_key, a->pkey.dsa->pub_key) == 0;
0f113f3e 310}
0cb8499b 311
6f81892e 312static void int_dsa_free(EVP_PKEY *pkey)
0f113f3e
MC
313{
314 DSA_free(pkey->pkey.dsa);
315}
6f81892e 316
777c47ac 317static int do_dsa_print(BIO *bp, const DSA *x, int off, int ptype)
0f113f3e 318{
0f113f3e 319 int ret = 0;
0f113f3e 320 const char *ktype = NULL;
0f113f3e 321 const BIGNUM *priv_key, *pub_key;
aecf529b 322 int mod_len = 0;
323
dc8de3e6
SL
324 if (x->params.p != NULL)
325 mod_len = DSA_bits(x);
0f113f3e
MC
326
327 if (ptype == 2)
328 priv_key = x->priv_key;
329 else
330 priv_key = NULL;
331
332 if (ptype > 0)
333 pub_key = x->pub_key;
334 else
335 pub_key = NULL;
336
337 if (ptype == 2)
338 ktype = "Private-Key";
339 else if (ptype == 1)
340 ktype = "Public-Key";
341 else
342 ktype = "DSA-Parameters";
343
dc8de3e6 344 if (priv_key != NULL) {
0f113f3e
MC
345 if (!BIO_indent(bp, off, 128))
346 goto err;
dc8de3e6 347 if (BIO_printf(bp, "%s: (%d bit)\n", ktype, mod_len) <= 0)
0f113f3e 348 goto err;
aecf529b 349 } else {
350 if (BIO_printf(bp, "Public-Key: (%d bit)\n", mod_len) <= 0)
351 goto err;
0f113f3e
MC
352 }
353
a773b52a 354 if (!ASN1_bn_print(bp, "priv:", priv_key, NULL, off))
0f113f3e 355 goto err;
a773b52a 356 if (!ASN1_bn_print(bp, "pub: ", pub_key, NULL, off))
0f113f3e 357 goto err;
dc8de3e6 358 if (!ffc_params_print(bp, &x->params, off))
0f113f3e
MC
359 goto err;
360 ret = 1;
361 err:
26a7d938 362 return ret;
0f113f3e 363}
35208f36 364
3e4585c8 365static int dsa_param_decode(EVP_PKEY *pkey,
0f113f3e
MC
366 const unsigned char **pder, int derlen)
367{
368 DSA *dsa;
75ebbd9a
RS
369
370 if ((dsa = d2i_DSAparams(NULL, pder, derlen)) == NULL) {
0f113f3e
MC
371 DSAerr(DSA_F_DSA_PARAM_DECODE, ERR_R_DSA_LIB);
372 return 0;
373 }
4889dadc 374 dsa->dirty_cnt++;
0f113f3e
MC
375 EVP_PKEY_assign_DSA(pkey, dsa);
376 return 1;
377}
3e4585c8
DSH
378
379static int dsa_param_encode(const EVP_PKEY *pkey, unsigned char **pder)
0f113f3e
MC
380{
381 return i2d_DSAparams(pkey->pkey.dsa, pder);
382}
35208f36
DSH
383
384static int dsa_param_print(BIO *bp, const EVP_PKEY *pkey, int indent,
0f113f3e
MC
385 ASN1_PCTX *ctx)
386{
387 return do_dsa_print(bp, pkey->pkey.dsa, indent, 0);
388}
35208f36
DSH
389
390static int dsa_pub_print(BIO *bp, const EVP_PKEY *pkey, int indent,
0f113f3e
MC
391 ASN1_PCTX *ctx)
392{
393 return do_dsa_print(bp, pkey->pkey.dsa, indent, 1);
394}
35208f36
DSH
395
396static int dsa_priv_print(BIO *bp, const EVP_PKEY *pkey, int indent,
0f113f3e
MC
397 ASN1_PCTX *ctx)
398{
399 return do_dsa_print(bp, pkey->pkey.dsa, indent, 2);
400}
35208f36 401
e4263314 402static int old_dsa_priv_decode(EVP_PKEY *pkey,
0f113f3e
MC
403 const unsigned char **pder, int derlen)
404{
405 DSA *dsa;
75ebbd9a
RS
406
407 if ((dsa = d2i_DSAPrivateKey(NULL, pder, derlen)) == NULL) {
0f113f3e
MC
408 DSAerr(DSA_F_OLD_DSA_PRIV_DECODE, ERR_R_DSA_LIB);
409 return 0;
410 }
4889dadc 411 dsa->dirty_cnt++;
0f113f3e
MC
412 EVP_PKEY_assign_DSA(pkey, dsa);
413 return 1;
414}
e4263314
DSH
415
416static int old_dsa_priv_encode(const EVP_PKEY *pkey, unsigned char **pder)
0f113f3e
MC
417{
418 return i2d_DSAPrivateKey(pkey->pkey.dsa, pder);
419}
e4263314 420
fa1ba589 421static int dsa_sig_print(BIO *bp, const X509_ALGOR *sigalg,
0f113f3e
MC
422 const ASN1_STRING *sig, int indent, ASN1_PCTX *pctx)
423{
424 DSA_SIG *dsa_sig;
425 const unsigned char *p;
a773b52a 426
dc8de3e6 427 if (sig == NULL) {
0f113f3e
MC
428 if (BIO_puts(bp, "\n") <= 0)
429 return 0;
430 else
431 return 1;
432 }
433 p = sig->data;
434 dsa_sig = d2i_DSA_SIG(NULL, &p, sig->length);
dc8de3e6 435 if (dsa_sig != NULL) {
0f113f3e 436 int rv = 0;
9267c11b 437 const BIGNUM *r, *s;
706a13f1 438
9267c11b 439 DSA_SIG_get0(dsa_sig, &r, &s);
0f113f3e
MC
440
441 if (BIO_write(bp, "\n", 1) != 1)
442 goto err;
443
706a13f1 444 if (!ASN1_bn_print(bp, "r: ", r, NULL, indent))
0f113f3e 445 goto err;
706a13f1 446 if (!ASN1_bn_print(bp, "s: ", s, NULL, indent))
0f113f3e
MC
447 goto err;
448 rv = 1;
449 err:
0f113f3e
MC
450 DSA_SIG_free(dsa_sig);
451 return rv;
452 }
a4c467c9
DO
453 if (BIO_puts(bp, "\n") <= 0)
454 return 0;
0f113f3e
MC
455 return X509_signature_dump(bp, sig, indent);
456}
fa1ba589 457
492a9e24 458static int dsa_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
0f113f3e
MC
459{
460 switch (op) {
461 case ASN1_PKEY_CTRL_PKCS7_SIGN:
462 if (arg1 == 0) {
463 int snid, hnid;
464 X509_ALGOR *alg1, *alg2;
465 PKCS7_SIGNER_INFO_get0_algs(arg2, NULL, &alg1, &alg2);
466 if (alg1 == NULL || alg1->algorithm == NULL)
467 return -1;
468 hnid = OBJ_obj2nid(alg1->algorithm);
469 if (hnid == NID_undef)
470 return -1;
471 if (!OBJ_find_sigid_by_algs(&snid, hnid, EVP_PKEY_id(pkey)))
472 return -1;
473 X509_ALGOR_set0(alg2, OBJ_nid2obj(snid), V_ASN1_UNDEF, 0);
474 }
475 return 1;
8931b30d 476#ifndef OPENSSL_NO_CMS
0f113f3e
MC
477 case ASN1_PKEY_CTRL_CMS_SIGN:
478 if (arg1 == 0) {
479 int snid, hnid;
480 X509_ALGOR *alg1, *alg2;
481 CMS_SignerInfo_get0_algs(arg2, NULL, NULL, &alg1, &alg2);
482 if (alg1 == NULL || alg1->algorithm == NULL)
483 return -1;
484 hnid = OBJ_obj2nid(alg1->algorithm);
485 if (hnid == NID_undef)
486 return -1;
487 if (!OBJ_find_sigid_by_algs(&snid, hnid, EVP_PKEY_id(pkey)))
488 return -1;
489 X509_ALGOR_set0(alg2, OBJ_nid2obj(snid), V_ASN1_UNDEF, 0);
490 }
491 return 1;
492
493 case ASN1_PKEY_CTRL_CMS_RI_TYPE:
494 *(int *)arg2 = CMS_RECIPINFO_NONE;
495 return 1;
8931b30d 496#endif
492a9e24 497
0f113f3e
MC
498 case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
499 *(int *)arg2 = NID_sha256;
cd4c83b5 500 return 1;
03919683 501
0f113f3e
MC
502 default:
503 return -2;
492a9e24 504
0f113f3e 505 }
492a9e24 506
0f113f3e 507}
492a9e24 508
4889dadc
MC
509static size_t dsa_pkey_dirty_cnt(const EVP_PKEY *pkey)
510{
511 return pkey->pkey.dsa->dirty_cnt;
512}
513
b305452f
RL
514static int dsa_pkey_export_to(const EVP_PKEY *from, void *to_keydata,
515 EVP_KEYMGMT *to_keymgmt)
4889dadc 516{
b305452f 517 DSA *dsa = from->pkey.dsa;
4889dadc
MC
518 OSSL_PARAM_BLD tmpl;
519 const BIGNUM *p = DSA_get0_p(dsa), *g = DSA_get0_g(dsa);
520 const BIGNUM *q = DSA_get0_q(dsa), *pub_key = DSA_get0_pub_key(dsa);
521 const BIGNUM *priv_key = DSA_get0_priv_key(dsa);
522 OSSL_PARAM *params;
b305452f 523 int rv;
4889dadc
MC
524
525 if (p == NULL || q == NULL || g == NULL)
b305452f 526 return 0;
4889dadc
MC
527
528 ossl_param_bld_init(&tmpl);
529 if (!ossl_param_bld_push_BN(&tmpl, OSSL_PKEY_PARAM_FFC_P, p)
530 || !ossl_param_bld_push_BN(&tmpl, OSSL_PKEY_PARAM_FFC_Q, q)
531 || !ossl_param_bld_push_BN(&tmpl, OSSL_PKEY_PARAM_FFC_G, g))
b305452f 532 return 0;
90d3cb57 533 if (!ossl_param_bld_push_BN(&tmpl, OSSL_PKEY_PARAM_PUB_KEY,
b305452f
RL
534 pub_key))
535 return 0;
536 if (priv_key != NULL) {
90d3cb57 537 if (!ossl_param_bld_push_BN(&tmpl, OSSL_PKEY_PARAM_PRIV_KEY,
b305452f
RL
538 priv_key))
539 return 0;
4889dadc
MC
540 }
541
b305452f
RL
542 if ((params = ossl_param_bld_to_param(&tmpl)) == NULL)
543 return 0;
4889dadc
MC
544
545 /* We export, the provider imports */
b305452f
RL
546 rv = evp_keymgmt_import(to_keymgmt, to_keydata, OSSL_KEYMGMT_SELECT_ALL,
547 params);
4889dadc
MC
548
549 ossl_param_bld_free(params);
b305452f
RL
550
551 return rv;
4889dadc
MC
552}
553
448be743
DSH
554/* NB these are sorted in pkey_id order, lowest first */
555
578b5514 556const EVP_PKEY_ASN1_METHOD dsa_asn1_meths[5] = {
0f113f3e
MC
557
558 {
559 EVP_PKEY_DSA2,
560 EVP_PKEY_DSA,
561 ASN1_PKEY_ALIAS},
562
563 {
564 EVP_PKEY_DSA1,
565 EVP_PKEY_DSA,
566 ASN1_PKEY_ALIAS},
567
568 {
569 EVP_PKEY_DSA4,
570 EVP_PKEY_DSA,
571 ASN1_PKEY_ALIAS},
572
573 {
574 EVP_PKEY_DSA3,
575 EVP_PKEY_DSA,
576 ASN1_PKEY_ALIAS},
577
578 {
579 EVP_PKEY_DSA,
580 EVP_PKEY_DSA,
581 0,
582
583 "DSA",
584 "OpenSSL DSA method",
585
586 dsa_pub_decode,
587 dsa_pub_encode,
588 dsa_pub_cmp,
589 dsa_pub_print,
590
591 dsa_priv_decode,
592 dsa_priv_encode,
593 dsa_priv_print,
594
595 int_dsa_size,
596 dsa_bits,
597 dsa_security_bits,
598
599 dsa_param_decode,
600 dsa_param_encode,
601 dsa_missing_parameters,
602 dsa_copy_parameters,
603 dsa_cmp_parameters,
604 dsa_param_print,
605 dsa_sig_print,
606
607 int_dsa_free,
608 dsa_pkey_ctrl,
609 old_dsa_priv_decode,
4889dadc
MC
610 old_dsa_priv_encode,
611
612 NULL, NULL, NULL,
613 NULL, NULL, NULL,
614 NULL, NULL, NULL, NULL,
615
616 dsa_pkey_dirty_cnt,
617 dsa_pkey_export_to
618 }
0f113f3e 619};