]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/encode_decode/encoder_local.h
CORE: Define provider-native abstract objects
[thirdparty/openssl.git] / crypto / encode_decode / encoder_local.h
CommitLineData
ece9304c
RL
1/*
2 * Copyright 2019-2020 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_dispatch.h>
11#include <openssl/types.h>
12#include <openssl/safestack.h>
13#include <openssl/encoder.h>
14#include <openssl/decoder.h>
15#include "internal/cryptlib.h"
16#include "internal/refcount.h"
17
18struct ossl_serdes_base_st {
19 OSSL_PROVIDER *prov;
20 int id;
21 const char *propdef;
22
23 CRYPTO_REF_COUNT refcnt;
24 CRYPTO_RWLOCK *lock;
25};
26
27struct ossl_encoder_st {
28 struct ossl_serdes_base_st base;
29 OSSL_FUNC_encoder_newctx_fn *newctx;
30 OSSL_FUNC_encoder_freectx_fn *freectx;
31 OSSL_FUNC_encoder_set_ctx_params_fn *set_ctx_params;
32 OSSL_FUNC_encoder_settable_ctx_params_fn *settable_ctx_params;
33 OSSL_FUNC_encoder_encode_data_fn *encode_data;
34 OSSL_FUNC_encoder_encode_object_fn *encode_object;
35};
36
37struct ossl_decoder_st {
38 struct ossl_serdes_base_st base;
39 OSSL_FUNC_decoder_newctx_fn *newctx;
40 OSSL_FUNC_decoder_freectx_fn *freectx;
41 OSSL_FUNC_decoder_get_params_fn *get_params;
42 OSSL_FUNC_decoder_gettable_params_fn *gettable_params;
43 OSSL_FUNC_decoder_set_ctx_params_fn *set_ctx_params;
44 OSSL_FUNC_decoder_settable_ctx_params_fn *settable_ctx_params;
45 OSSL_FUNC_decoder_decode_fn *decode;
46 OSSL_FUNC_decoder_export_object_fn *export_object;
47};
48
49struct ossl_encoder_ctx_st {
50 OSSL_ENCODER *encoder;
51 void *serctx;
52
53 int selection;
54
55 /*-
56 * Output / encoding data, used by OSSL_ENCODER_to_{bio,fp}
57 *
58 * |object| is the libcrypto object to handle.
59 * |do_output| performs the actual encoding.
60 *
61 * |do_output| must have intimate knowledge of |object|.
62 */
63 const void *object;
64 int (*do_output)(OSSL_ENCODER_CTX *ctx, BIO *out);
65
66 /* For any function that needs a passphrase reader */
67 const UI_METHOD *ui_method;
68 void *ui_data;
69 /*
70 * if caller used OSSL_ENCODER_CTX_set_passphrase_cb(), we need
71 * intermediary storage.
72 */
73 UI_METHOD *allocated_ui_method;
74};
75
76struct ossl_decoder_instance_st {
77 OSSL_DECODER *decoder; /* Never NULL */
78 void *deserctx; /* Never NULL */
79 const char *input_type; /* Never NULL */
80};
81
82DEFINE_STACK_OF(OSSL_DECODER_INSTANCE)
83
84struct ossl_decoder_ctx_st {
85 /*
86 * The caller may know the input type of the data they pass. If not,
87 * this will remain NULL and the decoding functionality will start
88 * with trying to decode with any desencoder in |decoder_insts|,
89 * regardless of their respective input type.
90 */
91 const char *start_input_type;
92
93 /*
94 * Decoders that are components of any current decoding path.
95 */
96 STACK_OF(OSSL_DECODER_INSTANCE) *decoder_insts;
97
98 /*
99 * The constructors of a decoding, and its caller argument.
100 */
101 OSSL_DECODER_CONSTRUCT *construct;
102 OSSL_DECODER_CLEANUP *cleanup;
103 void *construct_data;
104
105 /* For any function that needs a passphrase reader */
106 OSSL_PASSPHRASE_CALLBACK *passphrase_cb;
107 const UI_METHOD *ui_method;
108 void *ui_data;
109 /*
110 * if caller used OSSL_ENCODER_CTX_set_pem_password_cb(), we need
111 * intermediary storage.
112 */
113 UI_METHOD *allocated_ui_method;
114 /*
115 * Because the same input may pass through more than one decoder,
116 * we cache any passphrase passed to us. The desrializing processor
117 * must clear this at the end of a run.
118 */
119 unsigned char *cached_passphrase;
120 size_t cached_passphrase_len;
121
122 /*
123 * Flag section. Keep these together
124 */
125
126 /*
127 * The passphrase was passed to us by the user. In that case, it
128 * should only be freed when freeing this context.
129 */
130 unsigned int flag_user_passphrase:1;
131};
132
133/* Passphrase callbacks, found in serdes_pass.c */
134
135/*
136 * Encoders typically want to get an outgoing passphrase, while
137 * decoders typically want to get en incoming passphrase.
138 */
139OSSL_PASSPHRASE_CALLBACK ossl_encoder_passphrase_out_cb;
140OSSL_PASSPHRASE_CALLBACK ossl_decoder_passphrase_in_cb;