hkdf: when HMAC key is all zeros, still set a valid key length
[openssl.git] / include / openssl / decoder.h
1 /*
2  * Copyright 2020-2021 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 #ifndef OPENSSL_DECODER_H
11 # define OPENSSL_DECODER_H
12 # pragma once
13
14 # include <openssl/opensslconf.h>
15
16 # ifndef OPENSSL_NO_STDIO
17 #  include <stdio.h>
18 # endif
19 # include <stdarg.h>
20 # include <stddef.h>
21 # include <openssl/decodererr.h>
22 # include <openssl/types.h>
23 # include <openssl/core.h>
24
25 # ifdef __cplusplus
26 extern "C" {
27 # endif
28
29 OSSL_DECODER *OSSL_DECODER_fetch(OSSL_LIB_CTX *libctx, const char *name,
30                                  const char *properties);
31 int OSSL_DECODER_up_ref(OSSL_DECODER *encoder);
32 void OSSL_DECODER_free(OSSL_DECODER *encoder);
33
34 const OSSL_PROVIDER *OSSL_DECODER_get0_provider(const OSSL_DECODER *encoder);
35 const char *OSSL_DECODER_get0_properties(const OSSL_DECODER *encoder);
36 const char *OSSL_DECODER_get0_name(const OSSL_DECODER *decoder);
37 const char *OSSL_DECODER_get0_description(const OSSL_DECODER *decoder);
38 int OSSL_DECODER_is_a(const OSSL_DECODER *encoder, const char *name);
39
40 void OSSL_DECODER_do_all_provided(OSSL_LIB_CTX *libctx,
41                                   void (*fn)(OSSL_DECODER *encoder, void *arg),
42                                   void *arg);
43 int OSSL_DECODER_names_do_all(const OSSL_DECODER *encoder,
44                               void (*fn)(const char *name, void *data),
45                               void *data);
46 const OSSL_PARAM *OSSL_DECODER_gettable_params(OSSL_DECODER *decoder);
47 int OSSL_DECODER_get_params(OSSL_DECODER *decoder, OSSL_PARAM params[]);
48
49 const OSSL_PARAM *OSSL_DECODER_settable_ctx_params(OSSL_DECODER *encoder);
50 OSSL_DECODER_CTX *OSSL_DECODER_CTX_new(void);
51 int OSSL_DECODER_CTX_set_params(OSSL_DECODER_CTX *ctx,
52                                 const OSSL_PARAM params[]);
53 void OSSL_DECODER_CTX_free(OSSL_DECODER_CTX *ctx);
54
55 /* Utilities that help set specific parameters */
56 int OSSL_DECODER_CTX_set_passphrase(OSSL_DECODER_CTX *ctx,
57                                     const unsigned char *kstr, size_t klen);
58 int OSSL_DECODER_CTX_set_pem_password_cb(OSSL_DECODER_CTX *ctx,
59                                          pem_password_cb *cb, void *cbarg);
60 int OSSL_DECODER_CTX_set_passphrase_cb(OSSL_DECODER_CTX *ctx,
61                                        OSSL_PASSPHRASE_CALLBACK *cb,
62                                        void *cbarg);
63 int OSSL_DECODER_CTX_set_passphrase_ui(OSSL_DECODER_CTX *ctx,
64                                        const UI_METHOD *ui_method,
65                                        void *ui_data);
66
67 /*
68  * Utilities to read the object to decode, with the result sent to cb.
69  * These will discover all provided methods
70  */
71
72 int OSSL_DECODER_CTX_set_selection(OSSL_DECODER_CTX *ctx, int selection);
73 int OSSL_DECODER_CTX_set_input_type(OSSL_DECODER_CTX *ctx,
74                                     const char *input_type);
75 int OSSL_DECODER_CTX_set_input_structure(OSSL_DECODER_CTX *ctx,
76                                          const char *input_structure);
77 int OSSL_DECODER_CTX_add_decoder(OSSL_DECODER_CTX *ctx, OSSL_DECODER *decoder);
78 int OSSL_DECODER_CTX_add_extra(OSSL_DECODER_CTX *ctx,
79                                OSSL_LIB_CTX *libctx, const char *propq);
80 int OSSL_DECODER_CTX_get_num_decoders(OSSL_DECODER_CTX *ctx);
81
82 typedef struct ossl_decoder_instance_st OSSL_DECODER_INSTANCE;
83 OSSL_DECODER *
84 OSSL_DECODER_INSTANCE_get_decoder(OSSL_DECODER_INSTANCE *decoder_inst);
85 void *
86 OSSL_DECODER_INSTANCE_get_decoder_ctx(OSSL_DECODER_INSTANCE *decoder_inst);
87 const char *
88 OSSL_DECODER_INSTANCE_get_input_type(OSSL_DECODER_INSTANCE *decoder_inst);
89 const char *
90 OSSL_DECODER_INSTANCE_get_input_structure(OSSL_DECODER_INSTANCE *decoder_inst,
91                                           int *was_set);
92
93 typedef int OSSL_DECODER_CONSTRUCT(OSSL_DECODER_INSTANCE *decoder_inst,
94                                    const OSSL_PARAM *params,
95                                    void *construct_data);
96 typedef void OSSL_DECODER_CLEANUP(void *construct_data);
97
98 int OSSL_DECODER_CTX_set_construct(OSSL_DECODER_CTX *ctx,
99                                    OSSL_DECODER_CONSTRUCT *construct);
100 int OSSL_DECODER_CTX_set_construct_data(OSSL_DECODER_CTX *ctx,
101                                         void *construct_data);
102 int OSSL_DECODER_CTX_set_cleanup(OSSL_DECODER_CTX *ctx,
103                                  OSSL_DECODER_CLEANUP *cleanup);
104 OSSL_DECODER_CONSTRUCT *OSSL_DECODER_CTX_get_construct(OSSL_DECODER_CTX *ctx);
105 void *OSSL_DECODER_CTX_get_construct_data(OSSL_DECODER_CTX *ctx);
106 OSSL_DECODER_CLEANUP *OSSL_DECODER_CTX_get_cleanup(OSSL_DECODER_CTX *ctx);
107
108 int OSSL_DECODER_export(OSSL_DECODER_INSTANCE *decoder_inst,
109                         void *reference, size_t reference_sz,
110                         OSSL_CALLBACK *export_cb, void *export_cbarg);
111
112 int OSSL_DECODER_from_bio(OSSL_DECODER_CTX *ctx, BIO *in);
113 #ifndef OPENSSL_NO_STDIO
114 int OSSL_DECODER_from_fp(OSSL_DECODER_CTX *ctx, FILE *in);
115 #endif
116 int OSSL_DECODER_from_data(OSSL_DECODER_CTX *ctx, const unsigned char **pdata,
117                            size_t *pdata_len);
118
119 /*
120  * Create the OSSL_DECODER_CTX with an associated type.  This will perform
121  * an implicit OSSL_DECODER_fetch(), suitable for the object of that type.
122  */
123 OSSL_DECODER_CTX *
124 OSSL_DECODER_CTX_new_for_pkey(EVP_PKEY **pkey,
125                               const char *input_type,
126                               const char *input_struct,
127                               const char *keytype, int selection,
128                               OSSL_LIB_CTX *libctx, const char *propquery);
129
130 # ifdef __cplusplus
131 }
132 # endif
133 #endif