]>
Commit | Line | Data |
---|---|---|
5fe736e5 | 1 | /* |
4333b89f | 2 | * Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved. |
5fe736e5 | 3 | * |
48f4ad77 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
aa6bb135 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 | |
5fe736e5 DSH |
8 | */ |
9 | ||
80ce21fe F |
10 | #ifndef OSSL_CRYPTO_ASN1_H |
11 | # define OSSL_CRYPTO_ASN1_H | |
12 | # pragma once | |
13 | ||
14 | # include <openssl/asn1.h> | |
924663c3 | 15 | |
5fe736e5 DSH |
16 | /* Internal ASN1 structures and functions: not for application use */ |
17 | ||
18 | /* ASN1 public key method structure */ | |
19 | ||
acb90ba8 RL |
20 | #include <openssl/core.h> |
21 | ||
5fe736e5 DSH |
22 | struct evp_pkey_asn1_method_st { |
23 | int pkey_id; | |
24 | int pkey_base_id; | |
25 | unsigned long pkey_flags; | |
26 | char *pem_str; | |
27 | char *info; | |
7674e923 | 28 | int (*pub_decode) (EVP_PKEY *pk, const X509_PUBKEY *pub); |
5fe736e5 DSH |
29 | int (*pub_encode) (X509_PUBKEY *pub, const EVP_PKEY *pk); |
30 | int (*pub_cmp) (const EVP_PKEY *a, const EVP_PKEY *b); | |
31 | int (*pub_print) (BIO *out, const EVP_PKEY *pkey, int indent, | |
32 | ASN1_PCTX *pctx); | |
245c6bc3 | 33 | int (*priv_decode) (EVP_PKEY *pk, const PKCS8_PRIV_KEY_INFO *p8inf); |
5fe736e5 DSH |
34 | int (*priv_encode) (PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk); |
35 | int (*priv_print) (BIO *out, const EVP_PKEY *pkey, int indent, | |
36 | ASN1_PCTX *pctx); | |
37 | int (*pkey_size) (const EVP_PKEY *pk); | |
38 | int (*pkey_bits) (const EVP_PKEY *pk); | |
39 | int (*pkey_security_bits) (const EVP_PKEY *pk); | |
40 | int (*param_decode) (EVP_PKEY *pkey, | |
41 | const unsigned char **pder, int derlen); | |
42 | int (*param_encode) (const EVP_PKEY *pkey, unsigned char **pder); | |
43 | int (*param_missing) (const EVP_PKEY *pk); | |
44 | int (*param_copy) (EVP_PKEY *to, const EVP_PKEY *from); | |
45 | int (*param_cmp) (const EVP_PKEY *a, const EVP_PKEY *b); | |
46 | int (*param_print) (BIO *out, const EVP_PKEY *pkey, int indent, | |
47 | ASN1_PCTX *pctx); | |
48 | int (*sig_print) (BIO *out, | |
49 | const X509_ALGOR *sigalg, const ASN1_STRING *sig, | |
50 | int indent, ASN1_PCTX *pctx); | |
51 | void (*pkey_free) (EVP_PKEY *pkey); | |
52 | int (*pkey_ctrl) (EVP_PKEY *pkey, int op, long arg1, void *arg2); | |
53 | /* Legacy functions for old PEM */ | |
54 | int (*old_priv_decode) (EVP_PKEY *pkey, | |
55 | const unsigned char **pder, int derlen); | |
56 | int (*old_priv_encode) (const EVP_PKEY *pkey, unsigned char **pder); | |
57 | /* Custom ASN1 signature verification */ | |
ded346fa DDO |
58 | int (*item_verify) (EVP_MD_CTX *ctx, const ASN1_ITEM *it, const void *data, |
59 | const X509_ALGOR *a, const ASN1_BIT_STRING *sig, | |
60 | EVP_PKEY *pkey); | |
61 | int (*item_sign) (EVP_MD_CTX *ctx, const ASN1_ITEM *it, const void *data, | |
5fe736e5 DSH |
62 | X509_ALGOR *alg1, X509_ALGOR *alg2, |
63 | ASN1_BIT_STRING *sig); | |
786dd2c2 DSH |
64 | int (*siginf_set) (X509_SIG_INFO *siginf, const X509_ALGOR *alg, |
65 | const ASN1_STRING *sig); | |
2aee35d3 PY |
66 | /* Check */ |
67 | int (*pkey_check) (const EVP_PKEY *pk); | |
b0004708 PY |
68 | int (*pkey_public_check) (const EVP_PKEY *pk); |
69 | int (*pkey_param_check) (const EVP_PKEY *pk); | |
a08802ce MC |
70 | /* Get/set raw private/public key data */ |
71 | int (*set_priv_key) (EVP_PKEY *pk, const unsigned char *priv, size_t len); | |
72 | int (*set_pub_key) (EVP_PKEY *pk, const unsigned char *pub, size_t len); | |
0d124b0a MC |
73 | int (*get_priv_key) (const EVP_PKEY *pk, unsigned char *priv, size_t *len); |
74 | int (*get_pub_key) (const EVP_PKEY *pk, unsigned char *pub, size_t *len); | |
70a1f7b4 RL |
75 | |
76 | /* | |
77 | * TODO: Make sure these functions are defined for key types that are | |
78 | * implemented in providers. | |
79 | */ | |
acb90ba8 | 80 | /* Exports and imports to / from providers */ |
70a1f7b4 | 81 | size_t (*dirty_cnt) (const EVP_PKEY *pk); |
b305452f | 82 | int (*export_to) (const EVP_PKEY *pk, void *to_keydata, |
b4250010 | 83 | EVP_KEYMGMT *to_keymgmt, OSSL_LIB_CTX *libctx, |
76e23fc5 | 84 | const char *propq); |
acb90ba8 | 85 | OSSL_CALLBACK *import_from; |
472a88b7 | 86 | |
d8652be0 | 87 | int (*priv_decode_ex) (EVP_PKEY *pk, |
472a88b7 | 88 | const PKCS8_PRIV_KEY_INFO *p8inf, |
b4250010 | 89 | OSSL_LIB_CTX *libctx, |
472a88b7 | 90 | const char *propq); |
5fe736e5 | 91 | } /* EVP_PKEY_ASN1_METHOD */ ; |
2e430277 | 92 | |
a8eba56e | 93 | DEFINE_STACK_OF_CONST(EVP_PKEY_ASN1_METHOD) |
4a1f3f27 | 94 | |
df2ee0e2 BL |
95 | extern const EVP_PKEY_ASN1_METHOD dh_asn1_meth; |
96 | extern const EVP_PKEY_ASN1_METHOD dhx_asn1_meth; | |
578b5514 | 97 | extern const EVP_PKEY_ASN1_METHOD dsa_asn1_meths[5]; |
df2ee0e2 | 98 | extern const EVP_PKEY_ASN1_METHOD eckey_asn1_meth; |
262bd85f | 99 | extern const EVP_PKEY_ASN1_METHOD ecx25519_asn1_meth; |
13735cfe | 100 | extern const EVP_PKEY_ASN1_METHOD ecx448_asn1_meth; |
a13727e5 | 101 | extern const EVP_PKEY_ASN1_METHOD ed25519_asn1_meth; |
13735cfe | 102 | extern const EVP_PKEY_ASN1_METHOD ed448_asn1_meth; |
ddb634fe | 103 | extern const EVP_PKEY_ASN1_METHOD sm2_asn1_meth; |
52ad5b60 | 104 | |
578b5514 | 105 | extern const EVP_PKEY_ASN1_METHOD rsa_asn1_meths[2]; |
4e8ba747 | 106 | extern const EVP_PKEY_ASN1_METHOD rsa_pss_asn1_meth; |
df2ee0e2 | 107 | |
2e430277 DSH |
108 | /* |
109 | * These are used internally in the ASN1_OBJECT to keep track of whether the | |
110 | * names and data need to be free()ed | |
111 | */ | |
112 | # define ASN1_OBJECT_FLAG_DYNAMIC 0x01/* internal use */ | |
113 | # define ASN1_OBJECT_FLAG_CRITICAL 0x02/* critical x509v3 object id */ | |
114 | # define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04/* internal use */ | |
115 | # define ASN1_OBJECT_FLAG_DYNAMIC_DATA 0x08/* internal use */ | |
116 | struct asn1_object_st { | |
117 | const char *sn, *ln; | |
118 | int nid; | |
119 | int length; | |
120 | const unsigned char *data; /* data remains const after init */ | |
121 | int flags; /* Should we free this one */ | |
122 | }; | |
2743e38c DSH |
123 | |
124 | /* ASN1 print context structure */ | |
125 | ||
126 | struct asn1_pctx_st { | |
127 | unsigned long flags; | |
128 | unsigned long nm_flags; | |
129 | unsigned long cert_flags; | |
130 | unsigned long oid_flags; | |
131 | unsigned long str_flags; | |
132 | } /* ASN1_PCTX */ ; | |
924663c3 JZ |
133 | |
134 | /* ASN1 type functions */ | |
135 | ||
136 | int asn1_type_set_octetstring_int(ASN1_TYPE *a, long num, | |
137 | unsigned char *data, int len); | |
138 | int asn1_type_get_octetstring_int(const ASN1_TYPE *a, long *num, | |
139 | unsigned char *data, int max_len); | |
0b3a4ef2 MC |
140 | |
141 | int x509_algor_new_from_md(X509_ALGOR **palg, const EVP_MD *md); | |
142 | const EVP_MD *x509_algor_get_md(X509_ALGOR *alg); | |
143 | X509_ALGOR *x509_algor_mgf1_decode(X509_ALGOR *alg); | |
9ab7fe48 | 144 | int x509_algor_md_to_mgf1(X509_ALGOR **palg, const EVP_MD *mgf1md); |
63162e3d | 145 | int asn1_time_print_ex(BIO *bp, const ASN1_TIME *tm); |
80ce21fe F |
146 | |
147 | #endif /* ndef OSSL_CRYPTO_ASN1_H */ |