2 * Copyright 2019 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
10 #include <openssl/core_numbers.h>
11 #include <openssl/err.h>
12 #include <openssl/pem.h>
13 #include <openssl/dsa.h>
14 #include <openssl/types.h>
15 #include <openssl/params.h>
17 #include "prov/implementations.h"
18 #include "serializer_local.h"
20 static OSSL_OP_serializer_newctx_fn dsa_pub_newctx
;
21 static OSSL_OP_serializer_freectx_fn dsa_pub_freectx
;
22 static OSSL_OP_serializer_serialize_data_fn dsa_pub_der_data
;
23 static OSSL_OP_serializer_serialize_object_fn dsa_pub_der
;
24 static OSSL_OP_serializer_serialize_data_fn dsa_pub_pem_data
;
25 static OSSL_OP_serializer_serialize_object_fn dsa_pub_pem
;
27 static OSSL_OP_serializer_serialize_data_fn dsa_pub_print_data
;
28 static OSSL_OP_serializer_serialize_object_fn dsa_pub_print
;
30 /* Public key : context */
33 * There's no specific implementation context, so we use the provider context
35 static void *dsa_pub_newctx(void *provctx
)
40 static void dsa_pub_freectx(void *ctx
)
44 /* Public key : DER */
45 static int dsa_pub_der_data(void *ctx
, const OSSL_PARAM params
[], BIO
*out
,
46 OSSL_PASSPHRASE_CALLBACK
*cb
, void *cbarg
)
48 OSSL_OP_keymgmt_importkey_fn
*dsa_importkey
=
49 ossl_prov_get_dsa_importkey();
52 if (dsa_importkey
!= NULL
) {
53 DSA
*dsa
= dsa_importkey(ctx
, params
); /* ctx == provctx */
55 ok
= dsa_pub_der(ctx
, dsa
, out
, cb
, cbarg
);
61 static int dsa_pub_der(void *ctx
, void *dsa
, BIO
*out
,
62 OSSL_PASSPHRASE_CALLBACK
*cb
, void *cbarg
)
65 * TODO(v3.0) implement setting save_parameters, see dsa_pub_encode()
66 * in crypto/dsa/dsa_ameth.c
68 int save_parameters
= 1;
72 ? ossl_prov_write_pub_der_from_obj(out
, dsa
, EVP_PKEY_DSA
,
73 ossl_prov_prepare_all_dsa_params
,
74 ossl_prov_dsa_pub_to_der
)
75 : ossl_prov_write_pub_der_from_obj(out
, dsa
, EVP_PKEY_DSA
,
76 ossl_prov_prepare_dsa_params
,
77 ossl_prov_dsa_pub_to_der
);
81 /* Public key : PEM */
82 static int dsa_pub_pem_data(void *ctx
, const OSSL_PARAM params
[], BIO
*out
,
83 OSSL_PASSPHRASE_CALLBACK
*cb
, void *cbarg
)
85 OSSL_OP_keymgmt_importkey_fn
*dsa_importkey
=
86 ossl_prov_get_dsa_importkey();
89 if (dsa_importkey
!= NULL
) {
90 DSA
*dsa
= dsa_importkey(ctx
, params
); /* ctx == provctx */
92 ok
= dsa_pub_pem(ctx
, dsa
, out
, cb
, cbarg
);
98 static int dsa_pub_pem(void *ctx
, void *dsa
, BIO
*out
,
99 OSSL_PASSPHRASE_CALLBACK
*cb
, void *cbarg
)
101 return ossl_prov_write_pub_pem_from_obj(out
, dsa
, EVP_PKEY_DSA
,
102 ossl_prov_prepare_dsa_params
,
103 ossl_prov_dsa_pub_to_der
);
106 static int dsa_pub_print_data(void *ctx
, const OSSL_PARAM params
[], BIO
*out
,
107 OSSL_PASSPHRASE_CALLBACK
*cb
, void *cbarg
)
109 OSSL_OP_keymgmt_importkey_fn
*dsa_importkey
=
110 ossl_prov_get_dsa_importkey();
113 if (dsa_importkey
!= NULL
) {
114 DSA
*dsa
= dsa_importkey(ctx
, params
); /* ctx == provctx */
116 ok
= dsa_pub_print(ctx
, dsa
, out
, cb
, cbarg
);
122 static int dsa_pub_print(void *ctx
, void *dsa
, BIO
*out
,
123 OSSL_PASSPHRASE_CALLBACK
*cb
, void *cbarg
)
125 return ossl_prov_print_dsa(out
, dsa
, 0);
128 const OSSL_DISPATCH dsa_pub_der_serializer_functions
[] = {
129 { OSSL_FUNC_SERIALIZER_NEWCTX
, (void (*)(void))dsa_pub_newctx
},
130 { OSSL_FUNC_SERIALIZER_FREECTX
, (void (*)(void))dsa_pub_freectx
},
131 { OSSL_FUNC_SERIALIZER_SERIALIZE_DATA
, (void (*)(void))dsa_pub_der_data
},
132 { OSSL_FUNC_SERIALIZER_SERIALIZE_OBJECT
, (void (*)(void))dsa_pub_der
},
136 const OSSL_DISPATCH dsa_pub_pem_serializer_functions
[] = {
137 { OSSL_FUNC_SERIALIZER_NEWCTX
, (void (*)(void))dsa_pub_newctx
},
138 { OSSL_FUNC_SERIALIZER_FREECTX
, (void (*)(void))dsa_pub_freectx
},
139 { OSSL_FUNC_SERIALIZER_SERIALIZE_DATA
, (void (*)(void))dsa_pub_pem_data
},
140 { OSSL_FUNC_SERIALIZER_SERIALIZE_OBJECT
, (void (*)(void))dsa_pub_pem
},
144 const OSSL_DISPATCH dsa_pub_text_serializer_functions
[] = {
145 { OSSL_FUNC_SERIALIZER_NEWCTX
, (void (*)(void))dsa_pub_newctx
},
146 { OSSL_FUNC_SERIALIZER_FREECTX
, (void (*)(void))dsa_pub_freectx
},
147 { OSSL_FUNC_SERIALIZER_SERIALIZE_OBJECT
, (void (*)(void))dsa_pub_print
},
148 { OSSL_FUNC_SERIALIZER_SERIALIZE_DATA
,
149 (void (*)(void))dsa_pub_print_data
},