1 /**
2  * This file is a translation of `openssl/type.h`,
3  * also known as `openssl/ossl_types.h` before v3.0.0.
4  *
5  * Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved.
6  *
7  * Licensed under the Apache License 2.0 (the "License").  You may not use
8  * this file except in compliance with the License.  You can obtain a copy
9  * in the file LICENSE in the source distribution or at
10  * https://www.openssl.org/source/license.html
11  */
12 module deimos.openssl.types;
13 
14 extern(C):
15 @system:
16 nothrow:
17 
18 import deimos.openssl._d_util;
19 
20 public import deimos.openssl.e_os2;
21 
22 struct OSSL_PROVIDER; /* Provider Object */
23 
24 version (NO_ASN1_TYPEDEFS) {
25 alias ASN1_STRING ASN1_INTEGER;
26 alias ASN1_STRING ASN1_ENUMERATED;
27 alias ASN1_STRING ASN1_BIT_STRING;
28 alias ASN1_STRING ASN1_OCTET_STRING;
29 alias ASN1_STRING ASN1_PRINTABLESTRING;
30 alias ASN1_STRING ASN1_T61STRING;
31 alias ASN1_STRING ASN1_IA5STRING;
32 alias ASN1_STRING ASN1_UTCTIME;
33 alias ASN1_STRING ASN1_GENERALIZEDTIME;
34 alias ASN1_STRING ASN1_TIME;
35 alias ASN1_STRING ASN1_GENERALSTRING;
36 alias ASN1_STRING ASN1_UNIVERSALSTRING;
37 alias ASN1_STRING ASN1_BMPSTRING;
38 alias ASN1_STRING ASN1_VISIBLESTRING;
39 alias ASN1_STRING ASN1_UTF8STRING;
40 alias int ASN1_BOOLEAN;
41 alias int ASN1_NULL;
42 } else {
43 import deimos.openssl.asn1;
44 alias asn1_string_st ASN1_INTEGER;
45 alias asn1_string_st ASN1_ENUMERATED;
46 alias asn1_string_st ASN1_BIT_STRING;
47 alias asn1_string_st ASN1_OCTET_STRING;
48 alias asn1_string_st ASN1_PRINTABLESTRING;
49 alias asn1_string_st ASN1_T61STRING;
50 alias asn1_string_st ASN1_IA5STRING;
51 alias asn1_string_st ASN1_GENERALSTRING;
52 alias asn1_string_st ASN1_UNIVERSALSTRING;
53 alias asn1_string_st ASN1_BMPSTRING;
54 alias asn1_string_st ASN1_UTCTIME;
55 alias asn1_string_st ASN1_TIME;
56 alias asn1_string_st ASN1_GENERALIZEDTIME;
57 alias asn1_string_st ASN1_VISIBLESTRING;
58 alias asn1_string_st ASN1_UTF8STRING;
59 alias asn1_string_st ASN1_STRING;
60 alias int ASN1_BOOLEAN;
61 alias int ASN1_NULL;
62 }
63 
64 import deimos.openssl.asn1t;
65 alias ASN1_ITEM_st ASN1_ITEM;
66 
67 struct asn1_pctx_st;
68 alias asn1_pctx_st ASN1_PCTX;
69 
70 static if (OPENSSL_VERSION_AT_LEAST(1, 1, 0))
71 {
72 	struct BIGNUM;
73 	struct BN_CTX;
74 	struct BN_BLINDING;
75 	struct BN_MONT_CTX;
76 	struct BN_RECP_CTX;
77 	struct BN_GENCB;
78 
79 	struct BUF_MEM;
80 
81 	struct EVP_CIPHER;
82 	struct EVP_CIPHER_CTX;
83 	struct EVP_MD;
84 	struct EVP_MD_CTX;
85 	struct EVP_PKEY;
86 
87 	struct EVP_KDF;
88 	struct EVP_KDF_CTX;
89 
90 	// Backward compatible aliases, should not be used
91 	struct bignum_st;
92 	struct bn_mont_ctx_st;
93 	struct bn_recp_ctx_st;
94 	struct bn_gencb_st;
95 	struct buf_mem_st;
96 	struct env_md_ctx_st;
97 	struct evp_pkey_st;
98 	struct env_md_st;
99 	struct evp_cipher_st;
100 }
101 else
102 {
103 	struct bignum_st
104 	{
105 		BN_ULONG* d;	/* Pointer to an array of 'BN_BITS2' bit chunks. */
106 		int top;	/* Index of last used d +1. */
107 		/* The next are internal book keeping for bn_expand. */
108 		int dmax;	/* Size of the d array. */
109 		int neg;	/* one if the number is negative */
110 		int flags;
111 	}
112 
113 	/* Used for montgomery multiplication */
114 	struct bn_mont_ctx_st
115 	{
116 		int ri;		   /* number of bits in R */
117 		BIGNUM RR;	   /* used to convert to montgomery form */
118 		BIGNUM N;	   /* The modulus */
119 		BIGNUM Ni;	   /* R*(1/R mod N) - N*Ni = 1
120 						   * (Ni is only stored for bignum algorithm) */
121 		BN_ULONG[2] n0;/* least significant word(s) of Ni;
122 						  (type changed with 0.9.9, was "BN_ULONG n0;" before) */
123 		int flags;
124 	}
125 
126 	/* Used for reciprocal division/mod functions
127 	 * It cannot be shared between threads
128 	 */
129 	struct bn_recp_ctx_st
130 	{
131 		BIGNUM N;	/* the divisor */
132 		BIGNUM Nr;	/* the reciprocal */
133 		int num_bits;
134 		int shift;
135 		int flags;
136 	}
137 
138 	/* Used for slow "generation" functions. */
139 	struct bn_gencb_st
140 	{
141 		uint ver;	/* To handle binary (in)compatibility */
142 		void* arg;		/* callback-specific data */
143 		union cb_
144 		{
145 			/* if(ver==1) - handles old style callbacks */
146 			ExternC!(void function(int, int, void*)) cb_1;
147 			/* if(ver==2) - new callback style */
148 			ExternC!(int function(int, int, BN_GENCB*)) cb_2;
149 		}
150 		cb_ cb;
151 	}
152 
153 	alias BIGNUM = bignum_st;
154 	struct BN_CTX;
155 	struct BN_BLINDING;
156 	alias BN_MONT_CTX = bn_mont_ctx_st;
157 	alias BN_RECP_CTX = bn_recp_ctx_st;
158 	alias BN_GENCB = bn_gencb_st;
159 
160 	struct buf_mem_st
161 	{
162 		size_t length;	/* current number of bytes */
163 		char* data;
164 		size_t max;	/* size of buffer */
165 	}
166 
167 	alias BUF_MEM = buf_mem_st;
168 
169 
170 	struct env_md_ctx_st
171 	{
172 		const(EVP_MD)* digest;
173 		ENGINE* engine; /* functional reference if 'digest' is ENGINE-provided */
174 		c_ulong flags;
175 		void* md_data;
176 		/* Public key context for sign/verify */
177 		EVP_PKEY_CTX* pctx;
178 		/* Update function: usually copied from EVP_MD */
179 		ExternC!(int function(EVP_MD_CTX* ctx, const(void)* data, size_t count)) update;
180 	}
181 
182 	/* Type needs to be a bit field
183 	 * Sub-type needs to be for variations on the method, as in_, can it do
184 	 * arbitrary encryption.... */
185 	struct evp_pkey_st
186 	{
187 		int type;
188 		int save_type;
189 		int references;
190 		const(EVP_PKEY_ASN1_METHOD)* ameth;
191 		ENGINE* engine;
192 		union pkey_ {
193 			char* ptr;
194 			version(OPENSSL_NO_RSA) {} else {
195 				RSA* rsa;	/* RSA */
196 			}
197 			version(OPENSSL_NO_DSA) {} else {
198 				dsa_st* dsa;	/* DSA */
199 			}
200 			version(OPENSSL_NO_DH) {} else {
201 				dh_st* dh;	/* DH */
202 			}
203 			version(OPENSSL_NO_EC) {} else {
204 				ec_key_st* ec;	/* ECC */
205 			}
206 		}
207 		pkey_ pkey;
208 		int save_parameters;
209 		STACK_OF!(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
210 	}
211 
212 	struct env_md_st
213 	{
214 		int type;
215 		int pkey_type;
216 		int md_size;
217 		c_ulong flags;
218 		ExternC!(int function(EVP_MD_CTX* ctx)) init_;
219 		ExternC!(int function(EVP_MD_CTX* ctx,const(void)* data,size_t count)) update;
220 		ExternC!(int function(EVP_MD_CTX* ctx,ubyte* md)) final_;
221 		ExternC!(int function(EVP_MD_CTX* to,const(EVP_MD_CTX)* from)) copy;
222 		ExternC!(int function(EVP_MD_CTX* ctx)) cleanup;
223 
224 		/* FIXME: prototype these some day */
225 		ExternC!(int function(int type, const(ubyte)* m, uint m_length,
226 			ubyte* sigret, uint* siglen, void* key)) sign;
227 		ExternC!(int function(int type, const(ubyte)* m, uint m_length,
228 			  const(ubyte)* sigbuf, uint siglen,
229 			  void* key)) verify;
230 		int[5] required_pkey_type; /*EVP_PKEY_xxx */
231 		int block_size;
232 		int ctx_size; /* how big does the ctx->md_data need to be */
233 		/* control function */
234 		ExternC!(int function(EVP_MD_CTX* ctx, int cmd, int p1, void* p2)) md_ctrl;
235 	}
236 
237 	struct evp_cipher_st
238 	{
239 		int nid;
240 		int block_size;
241 		int key_len;		/* Default value for variable length ciphers */
242 		int iv_len;
243 		c_ulong flags;	/* Various flags */
244 		ExternC!(int function(EVP_CIPHER_CTX* ctx, const(ubyte)* key,
245 			const(ubyte)* iv, int enc)) init_;	/* init key */
246 		ExternC!(int function(EVP_CIPHER_CTX* ctx, ubyte* out_,
247 			 const(ubyte)* in_, size_t inl)) do_cipher;/* encrypt/decrypt data */
248 		ExternC!(int function(EVP_CIPHER_CTX*)) cleanup; /* cleanup ctx */
249 		int ctx_size;		/* how big ctx->cipher_data needs to be */
250 		ExternC!(int function(EVP_CIPHER_CTX*, ASN1_TYPE*)) set_asn1_parameters; /* Populate a ASN1_TYPE with parameters */
251 		ExternC!(int function(EVP_CIPHER_CTX*, ASN1_TYPE*)) get_asn1_parameters; /* Get parameters from a ASN1_TYPE */
252 		ExternC!(int function(EVP_CIPHER_CTX*, int type, int arg, void* ptr)) ctrl; /* Miscellaneous operations */
253 		void* app_data;		/* Application data */
254 	}
255 
256 	alias EVP_MD = env_md_st;
257 	alias EVP_MD_CTX = env_md_ctx_st;
258 	alias EVP_CIPHER = evp_cipher_st;
259 	alias EVP_CIPHER_CTX = evp_cipher_ctx_st;
260 
261 	alias EVP_PKEY = evp_pkey_st;
262 }
263 
264 struct evp_pkey_asn1_method_st;
265 alias evp_pkey_asn1_method_st EVP_PKEY_ASN1_METHOD;
266 struct evp_pkey_method_st;
267 alias evp_pkey_method_st EVP_PKEY_METHOD;
268 struct evp_pkey_ctx_st;
269 alias evp_pkey_ctx_st EVP_PKEY_CTX;
270 
271 
272 static if (OPENSSL_VERSION_AT_LEAST(3, 0, 0))
273     struct EVP_KEYEXCH;
274 
275 import deimos.openssl.dh;
276 /*struct dh_st;*/
277 alias dh_st DH;
278 /*struct dh_method;*/
279 alias dh_method DH_METHOD;
280 
281 import deimos.openssl.dsa;
282 /*struct dsa_st;*/
283 alias dsa_st DSA;
284 /*struct dsa_method;*/
285 alias dsa_method DSA_METHOD;
286 
287 import deimos.openssl.rsa;
288 private struct rsa_st;
289 alias rsa_st RSA;
290 private struct rsa_meth_st;
291 alias rsa_meth_st RSA_METHOD;
292 
293 import deimos.openssl.rand;
294 alias rand_meth_st RAND_METHOD;
295 
296 struct ecdh_method;
297 alias ecdh_method ECDH_METHOD;
298 struct ecdsa_method;
299 alias ecdsa_method ECDSA_METHOD;
300 
301 import deimos.openssl.x509;
302 import deimos.openssl.x509_vfy;
303 
304 struct ssl_dane_st;
305 alias SSL_DANE = ssl_dane_st;
306 
307 struct x509_st;
308 alias x509_st X509;
309 alias X509_algor_st X509_ALGOR;
310 struct X509_crl_st;
311 alias X509_crl_st X509_CRL;
312 struct x509_crl_method_st;
313 alias x509_crl_method_st X509_CRL_METHOD;
314 struct x509_revoked_st;
315 alias x509_revoked_st X509_REVOKED;
316 struct X509_name_st;
317 alias X509_name_st X509_NAME;
318 struct X509_pubkey_st;
319 alias X509_pubkey_st X509_PUBKEY;
320 struct x509_store_st;
321 alias x509_store_st X509_STORE;
322 struct x509_store_ctx_st;
323 alias x509_store_ctx_st X509_STORE_CTX;
324 struct x509_lookup_st;
325 alias X509_LOOKUP = x509_lookup_st;
326 
327 struct x509_object_st;
328 alias X509_OBJECT = x509_object_st;
329 struct x509_lookup_method_st;
330 alias X509_LOOKUP_METHOD = x509_lookup_method_st;
331 struct X509_VERIFY_PARAM_st;
332 alias X509_VERIFY_PARAM = X509_VERIFY_PARAM_st;
333 
334 struct pkcs8_priv_key_info_st;
335 alias pkcs8_priv_key_info_st PKCS8_PRIV_KEY_INFO;
336 
337 import deimos.openssl.x509v3;
338 alias v3_ext_ctx X509V3_CTX;
339 import deimos.openssl.conf;
340 alias conf_st CONF;
341 
342 struct store_st;
343 alias store_st STORE;
344 struct store_method_st;
345 alias store_method_st STORE_METHOD;
346 
347 struct ui_st;
348 alias ui_st UI;
349 struct ui_method_st;
350 alias ui_method_st UI_METHOD;
351 
352 struct st_ERR_FNS;
353 alias st_ERR_FNS ERR_FNS;
354 
355 struct engine_st;
356 alias engine_st ENGINE;
357 
358 struct X509_POLICY_NODE_st;
359 alias X509_POLICY_NODE_st X509_POLICY_NODE;
360 struct X509_POLICY_LEVEL_st;
361 alias X509_POLICY_LEVEL_st X509_POLICY_LEVEL;
362 struct X509_POLICY_TREE_st;
363 alias X509_POLICY_TREE_st X509_POLICY_TREE;
364 struct X509_POLICY_CACHE_st;
365 alias X509_POLICY_CACHE_st X509_POLICY_CACHE;
366 
367 alias AUTHORITY_KEYID_st AUTHORITY_KEYID;
368 alias DIST_POINT_st DIST_POINT;
369 alias ISSUING_DIST_POINT_st ISSUING_DIST_POINT;
370 alias NAME_CONSTRAINTS_st NAME_CONSTRAINTS;
371 
372   /* If placed in pkcs12.h, we end up with a circular depency with pkcs7.h */
373 mixin template DECLARE_PKCS12_STACK_OF (type) { /* Nothing */ }
374 //#define IMPLEMENT_PKCS12_STACK_OF!(type) /* Nothing */
375 
376 import deimos.openssl.crypto;
377 alias crypto_ex_data_st CRYPTO_EX_DATA;
378 /* Callback types for crypto.h */
379 alias typeof(*(ExternC!(int function(void* parent, void* ptr, CRYPTO_EX_DATA* ad,
380 					int idx, c_long argl, void* argp))).init) CRYPTO_EX_new;
381 alias typeof(*(ExternC!(void function(void* parent, void* ptr, CRYPTO_EX_DATA* ad,
382 					int idx, c_long argl, void* argp))).init) CRYPTO_EX_free;
383 alias typeof(*(ExternC!(int function(CRYPTO_EX_DATA* to, CRYPTO_EX_DATA* from, void* from_d,
384 					int idx, c_long argl, void* argp))).init) CRYPTO_EX_dup;
385 
386 import deimos.openssl.ocsp;
387 struct ocsp_req_ctx_st;
388 alias ocsp_req_ctx_st OCSP_REQ_CTX;
389 /*struct ocsp_response_st;*/
390 alias ocsp_response_st OCSP_RESPONSE;
391 /*struct ocsp_responder_id_st;*/
392 alias ocsp_responder_id_st OCSP_RESPID;
393 
394 struct OSSL_LIB_CTX;
395 
396 struct OSSL_PARAM;