| 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_importkey_fn *ossl_prov_get_importkey(const OSSL_DISPATCH *fns); |
| 34 | |
| 35 | OSSL_OP_keymgmt_importkey_fn *ossl_prov_get_rsa_importkey(void); |
| 36 | OSSL_OP_keymgmt_importkey_fn *ossl_prov_get_dh_importkey(void); |
| 37 | OSSL_OP_keymgmt_importkey_fn *ossl_prov_get_dsa_importkey(void); |
| 38 | |
| 39 | int ossl_prov_prepare_dh_params(const void *dh, int nid, |
| 40 | ASN1_STRING **pstr, int *pstrtype); |
| 41 | int ossl_prov_dh_pub_to_der(const void *dh, unsigned char **pder); |
| 42 | int ossl_prov_dh_priv_to_der(const void *dh, unsigned char **pder); |
| 43 | |
| 44 | int ossl_prov_prepare_dsa_params(const void *dsa, int nid, |
| 45 | ASN1_STRING **pstr, int *pstrtype); |
| 46 | /* |
| 47 | * Special variant of ossl_prov_prepare_dsa_params() that requires all |
| 48 | * three parameters (P, Q and G) to be set. This is used when serializing |
| 49 | * the public key. |
| 50 | */ |
| 51 | int ossl_prov_prepare_all_dsa_params(const void *dsa, int nid, |
| 52 | ASN1_STRING **pstr, int *pstrtype); |
| 53 | int ossl_prov_dsa_pub_to_der(const void *dsa, unsigned char **pder); |
| 54 | int ossl_prov_dsa_priv_to_der(const void *dsa, unsigned char **pder); |
| 55 | |
| 56 | int ossl_prov_print_labeled_bignum(BIO *out, const char *label, |
| 57 | const BIGNUM *n); |
| 58 | int ossl_prov_print_rsa(BIO *out, RSA *rsa, int priv); |
| 59 | |
| 60 | enum dh_print_type { |
| 61 | dh_print_priv, |
| 62 | dh_print_pub, |
| 63 | dh_print_params |
| 64 | }; |
| 65 | |
| 66 | int ossl_prov_print_dh(BIO *out, DH *dh, enum dh_print_type type); |
| 67 | |
| 68 | enum dsa_print_type { |
| 69 | dsa_print_priv, |
| 70 | dsa_print_pub, |
| 71 | dsa_print_params |
| 72 | }; |
| 73 | |
| 74 | int ossl_prov_print_dsa(BIO *out, DSA *dsa, enum dsa_print_type type); |
| 75 | |
| 76 | int ossl_prov_write_priv_der_from_obj(BIO *out, const void *obj, int obj_nid, |
| 77 | int (*p2s)(const void *obj, int nid, |
| 78 | ASN1_STRING **str, |
| 79 | int *strtype), |
| 80 | int (*k2d)(const void *obj, |
| 81 | unsigned char **pder), |
| 82 | struct pkcs8_encrypt_ctx_st *ctx); |
| 83 | int ossl_prov_write_priv_pem_from_obj(BIO *out, const void *obj, int obj_nid, |
| 84 | int (*p2s)(const void *obj, int nid, |
| 85 | ASN1_STRING **str, |
| 86 | int *strtype), |
| 87 | int (*k2d)(const void *obj, |
| 88 | unsigned char **pder), |
| 89 | struct pkcs8_encrypt_ctx_st *ctx); |
| 90 | int ossl_prov_write_pub_der_from_obj(BIO *out, const void *obj, int obj_nid, |
| 91 | int (*p2s)(const void *obj, int nid, |
| 92 | ASN1_STRING **str, |
| 93 | int *strtype), |
| 94 | int (*k2d)(const void *obj, |
| 95 | unsigned char **pder)); |
| 96 | int ossl_prov_write_pub_pem_from_obj(BIO *out, const void *obj, int obj_nid, |
| 97 | int (*p2s)(const void *obj, int nid, |
| 98 | ASN1_STRING **str, |
| 99 | int *strtype), |
| 100 | int (*k2d)(const void *obj, |
| 101 | unsigned char **pder)); |
| 102 | |