801d221da62f6451719a478c3dcc160d41ed9bc7
[openssl.git] / providers / implementations / serializers / serializer_local.h
1 /*
2  * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
3  *
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
8  */
9
10 #include <openssl/core.h>
11 #include <openssl/core_numbers.h>
12 #include <openssl/bn.h>
13 #include <openssl/asn1.h>        /* i2d_of_void */
14 #include <openssl/x509.h>        /* X509_SIG */
15 #include <openssl/types.h>
16
17 struct pkcs8_encrypt_ctx_st {
18     /* Set to 1 if intending to encrypt/decrypt, otherwise 0 */
19     int cipher_intent;
20
21     EVP_CIPHER *cipher;
22     int pbe_nid;                 /* For future variation */
23
24     /* Passphrase that was passed by the caller */
25     void *cipher_pass;
26     size_t cipher_pass_length;
27
28     /* This callback is only used of |cipher_pass| is NULL */
29     OSSL_PASSPHRASE_CALLBACK *cb;
30     void *cbarg;
31 };
32
33 OSSL_OP_keymgmt_new_fn *ossl_prov_get_keymgmt_new(const OSSL_DISPATCH *fns);
34 OSSL_OP_keymgmt_free_fn *ossl_prov_get_keymgmt_free(const OSSL_DISPATCH *fns);
35 OSSL_OP_keymgmt_import_fn *ossl_prov_get_keymgmt_import(const OSSL_DISPATCH *fns);
36
37 OSSL_OP_keymgmt_new_fn *ossl_prov_get_keymgmt_rsa_new(void);
38 OSSL_OP_keymgmt_free_fn *ossl_prov_get_keymgmt_rsa_free(void);
39 OSSL_OP_keymgmt_import_fn *ossl_prov_get_keymgmt_rsa_import(void);
40 OSSL_OP_keymgmt_new_fn *ossl_prov_get_keymgmt_dh_new(void);
41 OSSL_OP_keymgmt_free_fn *ossl_prov_get_keymgmt_dh_free(void);
42 OSSL_OP_keymgmt_import_fn *ossl_prov_get_keymgmt_dh_import(void);
43 OSSL_OP_keymgmt_new_fn *ossl_prov_get_keymgmt_dsa_new(void);
44 OSSL_OP_keymgmt_free_fn *ossl_prov_get_keymgmt_dsa_free(void);
45 OSSL_OP_keymgmt_import_fn *ossl_prov_get_keymgmt_dsa_import(void);
46
47 int ossl_prov_prepare_dh_params(const void *dh, int nid,
48                                 ASN1_STRING **pstr, int *pstrtype);
49 int ossl_prov_dh_pub_to_der(const void *dh, unsigned char **pder);
50 int ossl_prov_dh_priv_to_der(const void *dh, unsigned char **pder);
51
52 int ossl_prov_prepare_dsa_params(const void *dsa, int nid,
53                                 ASN1_STRING **pstr, int *pstrtype);
54 /*
55  * Special variant of ossl_prov_prepare_dsa_params() that requires all
56  * three parameters (P, Q and G) to be set.  This is used when serializing
57  * the public key.
58  */
59 int ossl_prov_prepare_all_dsa_params(const void *dsa, int nid,
60                                      ASN1_STRING **pstr, int *pstrtype);
61 int ossl_prov_dsa_pub_to_der(const void *dsa, unsigned char **pder);
62 int ossl_prov_dsa_priv_to_der(const void *dsa, unsigned char **pder);
63
64 int ossl_prov_print_labeled_bignum(BIO *out, const char *label,
65                                    const BIGNUM *bn);
66 int ossl_prov_print_rsa(BIO *out, RSA *rsa, int priv);
67
68 enum dh_print_type {
69     dh_print_priv,
70     dh_print_pub,
71     dh_print_params
72 };
73
74 int ossl_prov_print_dh(BIO *out, DH *dh, enum dh_print_type type);
75
76 enum dsa_print_type {
77     dsa_print_priv,
78     dsa_print_pub,
79     dsa_print_params
80 };
81
82 int ossl_prov_print_dsa(BIO *out, DSA *dsa, enum dsa_print_type type);
83
84 int ossl_prov_write_priv_der_from_obj(BIO *out, const void *obj, int obj_nid,
85                                       int (*p2s)(const void *obj, int nid,
86                                                  ASN1_STRING **str,
87                                                  int *strtype),
88                                       int (*k2d)(const void *obj,
89                                                  unsigned char **pder),
90                                       struct pkcs8_encrypt_ctx_st *ctx);
91 int ossl_prov_write_priv_pem_from_obj(BIO *out, const void *obj, int obj_nid,
92                                       int (*p2s)(const void *obj, int nid,
93                                                  ASN1_STRING **str,
94                                                  int *strtype),
95                                       int (*k2d)(const void *obj,
96                                                  unsigned char **pder),
97                                       struct pkcs8_encrypt_ctx_st *ctx);
98 int ossl_prov_write_pub_der_from_obj(BIO *out, const void *obj, int obj_nid,
99                                      int (*p2s)(const void *obj, int nid,
100                                                 ASN1_STRING **str,
101                                                 int *strtype),
102                                      int (*k2d)(const void *obj,
103                                                 unsigned char **pder));
104 int ossl_prov_write_pub_pem_from_obj(BIO *out, const void *obj, int obj_nid,
105                                      int (*p2s)(const void *obj, int nid,
106                                                 ASN1_STRING **str,
107                                                 int *strtype),
108                                      int (*k2d)(const void *obj,
109                                                 unsigned char **pder));