Coverage Report

Created: 2024-05-15 07:16

/src/openssl/include/crypto/evp.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2015-2018 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/evp.h>
11
#include <openssl/core_numbers.h>
12
#include "internal/refcount.h"
13
14
/*
15
 * Don't free up md_ctx->pctx in EVP_MD_CTX_reset, use the reserved flag
16
 * values in evp.h
17
 */
18
0
#define EVP_MD_CTX_FLAG_KEEP_PKEY_CTX   0x0400
19
20
struct evp_pkey_ctx_st {
21
    /* Actual operation */
22
    int operation;
23
24
    /*
25
     * Library context, Key type name and properties associated
26
     * with this context
27
     */
28
    OPENSSL_CTX *libctx;
29
    const char *keytype;
30
    const char *propquery;
31
32
    /* cached key manager */
33
    EVP_KEYMGMT *keymgmt;
34
35
    union {
36
        struct {
37
            EVP_KEYEXCH *exchange;
38
            void *exchprovctx;
39
        } kex;
40
41
        struct {
42
            EVP_SIGNATURE *signature;
43
            void *sigprovctx;
44
        } sig;
45
46
        struct {
47
            EVP_ASYM_CIPHER *cipher;
48
            void *ciphprovctx;
49
        } ciph;
50
    } op;
51
52
    /* Legacy fields below */
53
54
    /* Method associated with this operation */
55
    const EVP_PKEY_METHOD *pmeth;
56
    /* Engine that implements this method or NULL if builtin */
57
    ENGINE *engine;
58
    /* Key: may be NULL */
59
    EVP_PKEY *pkey;
60
    /* Peer key for key agreement, may be NULL */
61
    EVP_PKEY *peerkey;
62
    /* Algorithm specific data */
63
    void *data;
64
    /* Application specific data */
65
    void *app_data;
66
    /* Keygen callback */
67
    EVP_PKEY_gen_cb *pkey_gencb;
68
    /* implementation specific keygen data */
69
    int *keygen_info;
70
    int keygen_info_count;
71
} /* EVP_PKEY_CTX */ ;
72
73
0
#define EVP_PKEY_FLAG_DYNAMIC   1
74
75
struct evp_pkey_method_st {
76
    int pkey_id;
77
    int flags;
78
    int (*init) (EVP_PKEY_CTX *ctx);
79
    int (*copy) (EVP_PKEY_CTX *dst, const EVP_PKEY_CTX *src);
80
    void (*cleanup) (EVP_PKEY_CTX *ctx);
81
    int (*paramgen_init) (EVP_PKEY_CTX *ctx);
82
    int (*paramgen) (EVP_PKEY_CTX *ctx, EVP_PKEY *pkey);
83
    int (*keygen_init) (EVP_PKEY_CTX *ctx);
84
    int (*keygen) (EVP_PKEY_CTX *ctx, EVP_PKEY *pkey);
85
    int (*sign_init) (EVP_PKEY_CTX *ctx);
86
    int (*sign) (EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
87
                 const unsigned char *tbs, size_t tbslen);
88
    int (*verify_init) (EVP_PKEY_CTX *ctx);
89
    int (*verify) (EVP_PKEY_CTX *ctx,
90
                   const unsigned char *sig, size_t siglen,
91
                   const unsigned char *tbs, size_t tbslen);
92
    int (*verify_recover_init) (EVP_PKEY_CTX *ctx);
93
    int (*verify_recover) (EVP_PKEY_CTX *ctx,
94
                           unsigned char *rout, size_t *routlen,
95
                           const unsigned char *sig, size_t siglen);
96
    int (*signctx_init) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx);
97
    int (*signctx) (EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
98
                    EVP_MD_CTX *mctx);
99
    int (*verifyctx_init) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx);
100
    int (*verifyctx) (EVP_PKEY_CTX *ctx, const unsigned char *sig, int siglen,
101
                      EVP_MD_CTX *mctx);
102
    int (*encrypt_init) (EVP_PKEY_CTX *ctx);
103
    int (*encrypt) (EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
104
                    const unsigned char *in, size_t inlen);
105
    int (*decrypt_init) (EVP_PKEY_CTX *ctx);
106
    int (*decrypt) (EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
107
                    const unsigned char *in, size_t inlen);
108
    int (*derive_init) (EVP_PKEY_CTX *ctx);
109
    int (*derive) (EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen);
110
    int (*ctrl) (EVP_PKEY_CTX *ctx, int type, int p1, void *p2);
111
    int (*ctrl_str) (EVP_PKEY_CTX *ctx, const char *type, const char *value);
112
    int (*digestsign) (EVP_MD_CTX *ctx, unsigned char *sig, size_t *siglen,
113
                       const unsigned char *tbs, size_t tbslen);
114
    int (*digestverify) (EVP_MD_CTX *ctx, const unsigned char *sig,
115
                         size_t siglen, const unsigned char *tbs,
116
                         size_t tbslen);
117
    int (*check) (EVP_PKEY *pkey);
118
    int (*public_check) (EVP_PKEY *pkey);
119
    int (*param_check) (EVP_PKEY *pkey);
120
121
    int (*digest_custom) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx);
122
} /* EVP_PKEY_METHOD */ ;
123
124
DEFINE_STACK_OF_CONST(EVP_PKEY_METHOD)
125
126
void evp_pkey_set_cb_translate(BN_GENCB *cb, EVP_PKEY_CTX *ctx);
127
128
const EVP_PKEY_METHOD *cmac_pkey_method(void);
129
const EVP_PKEY_METHOD *dh_pkey_method(void);
130
const EVP_PKEY_METHOD *dhx_pkey_method(void);
131
const EVP_PKEY_METHOD *dsa_pkey_method(void);
132
const EVP_PKEY_METHOD *ec_pkey_method(void);
133
const EVP_PKEY_METHOD *sm2_pkey_method(void);
134
const EVP_PKEY_METHOD *ecx25519_pkey_method(void);
135
const EVP_PKEY_METHOD *ecx448_pkey_method(void);
136
const EVP_PKEY_METHOD *ed25519_pkey_method(void);
137
const EVP_PKEY_METHOD *ed448_pkey_method(void);
138
const EVP_PKEY_METHOD *hmac_pkey_method(void);
139
const EVP_PKEY_METHOD *rsa_pkey_method(void);
140
const EVP_PKEY_METHOD *rsa_pss_pkey_method(void);
141
const EVP_PKEY_METHOD *scrypt_pkey_method(void);
142
const EVP_PKEY_METHOD *tls1_prf_pkey_method(void);
143
const EVP_PKEY_METHOD *hkdf_pkey_method(void);
144
const EVP_PKEY_METHOD *poly1305_pkey_method(void);
145
const EVP_PKEY_METHOD *siphash_pkey_method(void);
146
147
struct evp_mac_st {
148
    OSSL_PROVIDER *prov;
149
    int name_id;
150
151
    CRYPTO_REF_COUNT refcnt;
152
    CRYPTO_RWLOCK *lock;
153
154
    OSSL_OP_mac_newctx_fn *newctx;
155
    OSSL_OP_mac_dupctx_fn *dupctx;
156
    OSSL_OP_mac_freectx_fn *freectx;
157
    OSSL_OP_mac_size_fn *size;
158
    OSSL_OP_mac_init_fn *init;
159
    OSSL_OP_mac_update_fn *update;
160
    OSSL_OP_mac_final_fn *final;
161
    OSSL_OP_mac_gettable_params_fn *gettable_params;
162
    OSSL_OP_mac_gettable_ctx_params_fn *gettable_ctx_params;
163
    OSSL_OP_mac_settable_ctx_params_fn *settable_ctx_params;
164
    OSSL_OP_mac_get_params_fn *get_params;
165
    OSSL_OP_mac_get_ctx_params_fn *get_ctx_params;
166
    OSSL_OP_mac_set_ctx_params_fn *set_ctx_params;
167
};
168
169
struct evp_kdf_st {
170
    OSSL_PROVIDER *prov;
171
    int name_id;
172
    CRYPTO_REF_COUNT refcnt;
173
    CRYPTO_RWLOCK *lock;
174
175
    OSSL_OP_kdf_newctx_fn *newctx;
176
    OSSL_OP_kdf_dupctx_fn *dupctx;
177
    OSSL_OP_kdf_freectx_fn *freectx;
178
    OSSL_OP_kdf_reset_fn *reset;
179
    OSSL_OP_kdf_derive_fn *derive;
180
    OSSL_OP_kdf_gettable_params_fn *gettable_params;
181
    OSSL_OP_kdf_gettable_ctx_params_fn *gettable_ctx_params;
182
    OSSL_OP_kdf_settable_ctx_params_fn *settable_ctx_params;
183
    OSSL_OP_kdf_get_params_fn *get_params;
184
    OSSL_OP_kdf_get_ctx_params_fn *get_ctx_params;
185
    OSSL_OP_kdf_set_ctx_params_fn *set_ctx_params;
186
};
187
188
struct evp_md_st {
189
    /* nid */
190
    int type;
191
192
    /* Legacy structure members */
193
    /* TODO(3.0): Remove these */
194
    int pkey_type;
195
    int md_size;
196
    unsigned long flags;
197
    int (*init) (EVP_MD_CTX *ctx);
198
    int (*update) (EVP_MD_CTX *ctx, const void *data, size_t count);
199
    int (*final) (EVP_MD_CTX *ctx, unsigned char *md);
200
    int (*copy) (EVP_MD_CTX *to, const EVP_MD_CTX *from);
201
    int (*cleanup) (EVP_MD_CTX *ctx);
202
    int block_size;
203
    int ctx_size;               /* how big does the ctx->md_data need to be */
204
    /* control function */
205
    int (*md_ctrl) (EVP_MD_CTX *ctx, int cmd, int p1, void *p2);
206
207
    /* New structure members */
208
    /* TODO(3.0): Remove above comment when legacy has gone */
209
    int name_id;
210
    OSSL_PROVIDER *prov;
211
    CRYPTO_REF_COUNT refcnt;
212
    CRYPTO_RWLOCK *lock;
213
    OSSL_OP_digest_newctx_fn *newctx;
214
    OSSL_OP_digest_init_fn *dinit;
215
    OSSL_OP_digest_update_fn *dupdate;
216
    OSSL_OP_digest_final_fn *dfinal;
217
    OSSL_OP_digest_digest_fn *digest;
218
    OSSL_OP_digest_freectx_fn *freectx;
219
    OSSL_OP_digest_dupctx_fn *dupctx;
220
    OSSL_OP_digest_get_params_fn *get_params;
221
    OSSL_OP_digest_set_ctx_params_fn *set_ctx_params;
222
    OSSL_OP_digest_get_ctx_params_fn *get_ctx_params;
223
    OSSL_OP_digest_gettable_params_fn *gettable_params;
224
    OSSL_OP_digest_settable_ctx_params_fn *settable_ctx_params;
225
    OSSL_OP_digest_gettable_ctx_params_fn *gettable_ctx_params;
226
227
} /* EVP_MD */ ;
228
229
struct evp_cipher_st {
230
    int nid;
231
232
    int block_size;
233
    /* Default value for variable length ciphers */
234
    int key_len;
235
    int iv_len;
236
237
    /* Legacy structure members */
238
    /* TODO(3.0): Remove these */
239
    /* Various flags */
240
    unsigned long flags;
241
    /* init key */
242
    int (*init) (EVP_CIPHER_CTX *ctx, const unsigned char *key,
243
                 const unsigned char *iv, int enc);
244
    /* encrypt/decrypt data */
245
    int (*do_cipher) (EVP_CIPHER_CTX *ctx, unsigned char *out,
246
                      const unsigned char *in, size_t inl);
247
    /* cleanup ctx */
248
    int (*cleanup) (EVP_CIPHER_CTX *);
249
    /* how big ctx->cipher_data needs to be */
250
    int ctx_size;
251
    /* Populate a ASN1_TYPE with parameters */
252
    int (*set_asn1_parameters) (EVP_CIPHER_CTX *, ASN1_TYPE *);
253
    /* Get parameters from a ASN1_TYPE */
254
    int (*get_asn1_parameters) (EVP_CIPHER_CTX *, ASN1_TYPE *);
255
    /* Miscellaneous operations */
256
    int (*ctrl) (EVP_CIPHER_CTX *, int type, int arg, void *ptr);
257
    /* Application data */
258
    void *app_data;
259
260
    /* New structure members */
261
    /* TODO(3.0): Remove above comment when legacy has gone */
262
    int name_id;
263
    OSSL_PROVIDER *prov;
264
    CRYPTO_REF_COUNT refcnt;
265
    CRYPTO_RWLOCK *lock;
266
    OSSL_OP_cipher_newctx_fn *newctx;
267
    OSSL_OP_cipher_encrypt_init_fn *einit;
268
    OSSL_OP_cipher_decrypt_init_fn *dinit;
269
    OSSL_OP_cipher_update_fn *cupdate;
270
    OSSL_OP_cipher_final_fn *cfinal;
271
    OSSL_OP_cipher_cipher_fn *ccipher;
272
    OSSL_OP_cipher_freectx_fn *freectx;
273
    OSSL_OP_cipher_dupctx_fn *dupctx;
274
    OSSL_OP_cipher_get_params_fn *get_params;
275
    OSSL_OP_cipher_get_ctx_params_fn *get_ctx_params;
276
    OSSL_OP_cipher_set_ctx_params_fn *set_ctx_params;
277
    OSSL_OP_cipher_gettable_params_fn *gettable_params;
278
    OSSL_OP_cipher_gettable_ctx_params_fn *gettable_ctx_params;
279
    OSSL_OP_cipher_settable_ctx_params_fn *settable_ctx_params;
280
} /* EVP_CIPHER */ ;
281
282
/* Macros to code block cipher wrappers */
283
284
/* Wrapper functions for each cipher mode */
285
286
#define EVP_C_DATA(kstruct, ctx) \
287
0
        ((kstruct *)EVP_CIPHER_CTX_get_cipher_data(ctx))
288
289
#define BLOCK_CIPHER_ecb_loop() \
290
0
        size_t i, bl; \
291
0
        bl = EVP_CIPHER_CTX_cipher(ctx)->block_size;    \
292
0
        if (inl < bl) return 1;\
293
0
        inl -= bl; \
294
0
        for (i=0; i <= inl; i+=bl)
295
296
#define BLOCK_CIPHER_func_ecb(cname, cprefix, kstruct, ksched) \
297
0
static int cname##_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) \
298
0
{\
299
0
        BLOCK_CIPHER_ecb_loop() \
300
0
            cprefix##_ecb_encrypt(in + i, out + i, &EVP_C_DATA(kstruct,ctx)->ksched, EVP_CIPHER_CTX_encrypting(ctx)); \
301
0
        return 1;\
302
0
}
Unexecuted instantiation: e_aria.c:aria_128_ecb_cipher
Unexecuted instantiation: e_aria.c:aria_192_ecb_cipher
Unexecuted instantiation: e_aria.c:aria_256_ecb_cipher
Unexecuted instantiation: e_bf.c:bf_ecb_cipher
Unexecuted instantiation: e_cast.c:cast5_ecb_cipher
Unexecuted instantiation: e_rc2.c:rc2_ecb_cipher
Unexecuted instantiation: e_rc5.c:rc5_32_12_16_ecb_cipher
Unexecuted instantiation: e_seed.c:seed_ecb_cipher
Unexecuted instantiation: e_sm4.c:sm4_ecb_cipher
303
304
0
#define EVP_MAXCHUNK ((size_t)1<<(sizeof(long)*8-2))
305
306
#define BLOCK_CIPHER_func_ofb(cname, cprefix, cbits, kstruct, ksched) \
307
0
    static int cname##_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) \
308
0
{\
309
0
        while(inl>=EVP_MAXCHUNK) {\
310
0
            int num = EVP_CIPHER_CTX_num(ctx);\
311
0
            cprefix##_ofb##cbits##_encrypt(in, out, (long)EVP_MAXCHUNK, &EVP_C_DATA(kstruct,ctx)->ksched, EVP_CIPHER_CTX_iv_noconst(ctx), &num); \
312
0
            EVP_CIPHER_CTX_set_num(ctx, num);\
313
0
            inl-=EVP_MAXCHUNK;\
314
0
            in +=EVP_MAXCHUNK;\
315
0
            out+=EVP_MAXCHUNK;\
316
0
        }\
317
0
        if (inl) {\
318
0
            int num = EVP_CIPHER_CTX_num(ctx);\
319
0
            cprefix##_ofb##cbits##_encrypt(in, out, (long)inl, &EVP_C_DATA(kstruct,ctx)->ksched, EVP_CIPHER_CTX_iv_noconst(ctx), &num); \
320
0
            EVP_CIPHER_CTX_set_num(ctx, num);\
321
0
        }\
322
0
        return 1;\
323
0
}
Unexecuted instantiation: e_aria.c:aria_128_ofb_cipher
Unexecuted instantiation: e_aria.c:aria_192_ofb_cipher
Unexecuted instantiation: e_aria.c:aria_256_ofb_cipher
Unexecuted instantiation: e_bf.c:bf_ofb_cipher
Unexecuted instantiation: e_cast.c:cast5_ofb_cipher
Unexecuted instantiation: e_idea.c:idea_ofb_cipher
Unexecuted instantiation: e_rc2.c:rc2_ofb_cipher
Unexecuted instantiation: e_rc5.c:rc5_32_12_16_ofb_cipher
Unexecuted instantiation: e_seed.c:seed_ofb_cipher
Unexecuted instantiation: e_sm4.c:sm4_ofb_cipher
324
325
#define BLOCK_CIPHER_func_cbc(cname, cprefix, kstruct, ksched) \
326
0
static int cname##_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) \
327
0
{\
328
0
        while(inl>=EVP_MAXCHUNK) \
329
0
            {\
330
0
            cprefix##_cbc_encrypt(in, out, (long)EVP_MAXCHUNK, &EVP_C_DATA(kstruct,ctx)->ksched, EVP_CIPHER_CTX_iv_noconst(ctx), EVP_CIPHER_CTX_encrypting(ctx));\
331
0
            inl-=EVP_MAXCHUNK;\
332
0
            in +=EVP_MAXCHUNK;\
333
0
            out+=EVP_MAXCHUNK;\
334
0
            }\
335
0
        if (inl)\
336
0
            cprefix##_cbc_encrypt(in, out, (long)inl, &EVP_C_DATA(kstruct,ctx)->ksched, EVP_CIPHER_CTX_iv_noconst(ctx), EVP_CIPHER_CTX_encrypting(ctx));\
337
0
        return 1;\
338
0
}
Unexecuted instantiation: e_aria.c:aria_128_cbc_cipher
Unexecuted instantiation: e_aria.c:aria_192_cbc_cipher
Unexecuted instantiation: e_aria.c:aria_256_cbc_cipher
Unexecuted instantiation: e_bf.c:bf_cbc_cipher
Unexecuted instantiation: e_cast.c:cast5_cbc_cipher
Unexecuted instantiation: e_idea.c:idea_cbc_cipher
Unexecuted instantiation: e_rc2.c:rc2_cbc_cipher
Unexecuted instantiation: e_rc5.c:rc5_32_12_16_cbc_cipher
Unexecuted instantiation: e_seed.c:seed_cbc_cipher
Unexecuted instantiation: e_sm4.c:sm4_cbc_cipher
339
340
#define BLOCK_CIPHER_func_cfb(cname, cprefix, cbits, kstruct, ksched)  \
341
0
static int cname##_cfb##cbits##_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) \
342
0
{\
343
0
    size_t chunk = EVP_MAXCHUNK;\
344
0
    if (cbits == 1)  chunk >>= 3;\
345
0
    if (inl < chunk) chunk = inl;\
346
0
    while (inl && inl >= chunk)\
347
0
    {\
348
0
        int num = EVP_CIPHER_CTX_num(ctx);\
349
0
        cprefix##_cfb##cbits##_encrypt(in, out, (long) \
350
0
            ((cbits == 1) \
351
0
                && !EVP_CIPHER_CTX_test_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS) \
352
0
                ? chunk*8 : chunk), \
353
0
            &EVP_C_DATA(kstruct, ctx)->ksched, EVP_CIPHER_CTX_iv_noconst(ctx),\
354
0
            &num, EVP_CIPHER_CTX_encrypting(ctx));\
355
0
        EVP_CIPHER_CTX_set_num(ctx, num);\
356
0
        inl -= chunk;\
357
0
        in += chunk;\
358
0
        out += chunk;\
359
0
        if (inl < chunk) chunk = inl;\
360
0
    }\
361
0
    return 1;\
362
0
}
Unexecuted instantiation: e_aria.c:aria_128_cfb128_cipher
Unexecuted instantiation: e_aria.c:aria_192_cfb128_cipher
Unexecuted instantiation: e_aria.c:aria_256_cfb128_cipher
Unexecuted instantiation: e_aria.c:aria_128_cfb1_cipher
Unexecuted instantiation: e_aria.c:aria_192_cfb1_cipher
Unexecuted instantiation: e_aria.c:aria_256_cfb1_cipher
Unexecuted instantiation: e_aria.c:aria_128_cfb8_cipher
Unexecuted instantiation: e_aria.c:aria_192_cfb8_cipher
Unexecuted instantiation: e_aria.c:aria_256_cfb8_cipher
Unexecuted instantiation: e_bf.c:bf_cfb64_cipher
Unexecuted instantiation: e_cast.c:cast5_cfb64_cipher
Unexecuted instantiation: e_idea.c:idea_cfb64_cipher
Unexecuted instantiation: e_rc2.c:rc2_cfb64_cipher
Unexecuted instantiation: e_rc5.c:rc5_32_12_16_cfb64_cipher
Unexecuted instantiation: e_seed.c:seed_cfb128_cipher
Unexecuted instantiation: e_sm4.c:sm4_cfb128_cipher
363
364
#define BLOCK_CIPHER_all_funcs(cname, cprefix, cbits, kstruct, ksched) \
365
        BLOCK_CIPHER_func_cbc(cname, cprefix, kstruct, ksched) \
366
        BLOCK_CIPHER_func_cfb(cname, cprefix, cbits, kstruct, ksched) \
367
        BLOCK_CIPHER_func_ecb(cname, cprefix, kstruct, ksched) \
368
        BLOCK_CIPHER_func_ofb(cname, cprefix, cbits, kstruct, ksched)
369
370
#define BLOCK_CIPHER_def1(cname, nmode, mode, MODE, kstruct, nid, block_size, \
371
                          key_len, iv_len, flags, init_key, cleanup, \
372
                          set_asn1, get_asn1, ctrl) \
373
static const EVP_CIPHER cname##_##mode = { \
374
        nid##_##nmode, block_size, key_len, iv_len, \
375
        flags | EVP_CIPH_##MODE##_MODE, \
376
        init_key, \
377
        cname##_##mode##_cipher, \
378
        cleanup, \
379
        sizeof(kstruct), \
380
        set_asn1, get_asn1,\
381
        ctrl, \
382
        NULL \
383
}; \
384
0
const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; }
Unexecuted instantiation: EVP_aria_128_cbc
Unexecuted instantiation: EVP_aria_128_cfb128
Unexecuted instantiation: EVP_aria_128_ofb
Unexecuted instantiation: EVP_aria_128_ecb
Unexecuted instantiation: EVP_aria_192_cbc
Unexecuted instantiation: EVP_aria_192_cfb128
Unexecuted instantiation: EVP_aria_192_ofb
Unexecuted instantiation: EVP_aria_192_ecb
Unexecuted instantiation: EVP_aria_256_cbc
Unexecuted instantiation: EVP_aria_256_cfb128
Unexecuted instantiation: EVP_aria_256_ofb
Unexecuted instantiation: EVP_aria_256_ecb
Unexecuted instantiation: EVP_aria_128_cfb1
Unexecuted instantiation: EVP_aria_192_cfb1
Unexecuted instantiation: EVP_aria_256_cfb1
Unexecuted instantiation: EVP_aria_128_cfb8
Unexecuted instantiation: EVP_aria_192_cfb8
Unexecuted instantiation: EVP_aria_256_cfb8
Unexecuted instantiation: EVP_bf_cbc
Unexecuted instantiation: EVP_bf_cfb64
Unexecuted instantiation: EVP_bf_ofb
Unexecuted instantiation: EVP_bf_ecb
Unexecuted instantiation: EVP_cast5_cbc
Unexecuted instantiation: EVP_cast5_cfb64
Unexecuted instantiation: EVP_cast5_ofb
Unexecuted instantiation: EVP_cast5_ecb
Unexecuted instantiation: EVP_des_cbc
Unexecuted instantiation: EVP_des_cfb64
Unexecuted instantiation: EVP_des_ofb
Unexecuted instantiation: EVP_des_ecb
Unexecuted instantiation: EVP_des_cfb1
Unexecuted instantiation: EVP_des_cfb8
Unexecuted instantiation: EVP_des_ede_cbc
Unexecuted instantiation: EVP_des_ede_cfb64
Unexecuted instantiation: EVP_des_ede_ofb
Unexecuted instantiation: EVP_des_ede_ecb
Unexecuted instantiation: EVP_des_ede3_cbc
Unexecuted instantiation: EVP_des_ede3_cfb64
Unexecuted instantiation: EVP_des_ede3_ofb
Unexecuted instantiation: EVP_des_ede3_ecb
Unexecuted instantiation: EVP_des_ede3_cfb1
Unexecuted instantiation: EVP_des_ede3_cfb8
Unexecuted instantiation: EVP_idea_cbc
Unexecuted instantiation: EVP_idea_cfb64
Unexecuted instantiation: EVP_idea_ofb
Unexecuted instantiation: EVP_idea_ecb
Unexecuted instantiation: EVP_rc2_cbc
Unexecuted instantiation: EVP_rc2_cfb64
Unexecuted instantiation: EVP_rc2_ofb
Unexecuted instantiation: EVP_rc2_ecb
Unexecuted instantiation: EVP_rc5_32_12_16_cbc
Unexecuted instantiation: EVP_rc5_32_12_16_cfb64
Unexecuted instantiation: EVP_rc5_32_12_16_ofb
Unexecuted instantiation: EVP_rc5_32_12_16_ecb
Unexecuted instantiation: EVP_seed_cbc
Unexecuted instantiation: EVP_seed_cfb128
Unexecuted instantiation: EVP_seed_ofb
Unexecuted instantiation: EVP_seed_ecb
Unexecuted instantiation: EVP_sm4_cbc
Unexecuted instantiation: EVP_sm4_cfb128
Unexecuted instantiation: EVP_sm4_ofb
Unexecuted instantiation: EVP_sm4_ecb
385
386
#define BLOCK_CIPHER_def_cbc(cname, kstruct, nid, block_size, key_len, \
387
                             iv_len, flags, init_key, cleanup, set_asn1, \
388
                             get_asn1, ctrl) \
389
BLOCK_CIPHER_def1(cname, cbc, cbc, CBC, kstruct, nid, block_size, key_len, \
390
                  iv_len, flags, init_key, cleanup, set_asn1, get_asn1, ctrl)
391
392
#define BLOCK_CIPHER_def_cfb(cname, kstruct, nid, key_len, \
393
                             iv_len, cbits, flags, init_key, cleanup, \
394
                             set_asn1, get_asn1, ctrl) \
395
BLOCK_CIPHER_def1(cname, cfb##cbits, cfb##cbits, CFB, kstruct, nid, 1, \
396
                  key_len, iv_len, flags, init_key, cleanup, set_asn1, \
397
                  get_asn1, ctrl)
398
399
#define BLOCK_CIPHER_def_ofb(cname, kstruct, nid, key_len, \
400
                             iv_len, cbits, flags, init_key, cleanup, \
401
                             set_asn1, get_asn1, ctrl) \
402
BLOCK_CIPHER_def1(cname, ofb##cbits, ofb, OFB, kstruct, nid, 1, \
403
                  key_len, iv_len, flags, init_key, cleanup, set_asn1, \
404
                  get_asn1, ctrl)
405
406
#define BLOCK_CIPHER_def_ecb(cname, kstruct, nid, block_size, key_len, \
407
                             flags, init_key, cleanup, set_asn1, \
408
                             get_asn1, ctrl) \
409
BLOCK_CIPHER_def1(cname, ecb, ecb, ECB, kstruct, nid, block_size, key_len, \
410
                  0, flags, init_key, cleanup, set_asn1, get_asn1, ctrl)
411
412
#define BLOCK_CIPHER_defs(cname, kstruct, \
413
                          nid, block_size, key_len, iv_len, cbits, flags, \
414
                          init_key, cleanup, set_asn1, get_asn1, ctrl) \
415
BLOCK_CIPHER_def_cbc(cname, kstruct, nid, block_size, key_len, iv_len, flags, \
416
                     init_key, cleanup, set_asn1, get_asn1, ctrl) \
417
BLOCK_CIPHER_def_cfb(cname, kstruct, nid, key_len, iv_len, cbits, \
418
                     flags, init_key, cleanup, set_asn1, get_asn1, ctrl) \
419
BLOCK_CIPHER_def_ofb(cname, kstruct, nid, key_len, iv_len, cbits, \
420
                     flags, init_key, cleanup, set_asn1, get_asn1, ctrl) \
421
BLOCK_CIPHER_def_ecb(cname, kstruct, nid, block_size, key_len, flags, \
422
                     init_key, cleanup, set_asn1, get_asn1, ctrl)
423
424
/*-
425
#define BLOCK_CIPHER_defs(cname, kstruct, \
426
                                nid, block_size, key_len, iv_len, flags,\
427
                                 init_key, cleanup, set_asn1, get_asn1, ctrl)\
428
static const EVP_CIPHER cname##_cbc = {\
429
        nid##_cbc, block_size, key_len, iv_len, \
430
        flags | EVP_CIPH_CBC_MODE,\
431
        init_key,\
432
        cname##_cbc_cipher,\
433
        cleanup,\
434
        sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
435
                sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
436
        set_asn1, get_asn1,\
437
        ctrl, \
438
        NULL \
439
};\
440
const EVP_CIPHER *EVP_##cname##_cbc(void) { return &cname##_cbc; }\
441
static const EVP_CIPHER cname##_cfb = {\
442
        nid##_cfb64, 1, key_len, iv_len, \
443
        flags | EVP_CIPH_CFB_MODE,\
444
        init_key,\
445
        cname##_cfb_cipher,\
446
        cleanup,\
447
        sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
448
                sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
449
        set_asn1, get_asn1,\
450
        ctrl,\
451
        NULL \
452
};\
453
const EVP_CIPHER *EVP_##cname##_cfb(void) { return &cname##_cfb; }\
454
static const EVP_CIPHER cname##_ofb = {\
455
        nid##_ofb64, 1, key_len, iv_len, \
456
        flags | EVP_CIPH_OFB_MODE,\
457
        init_key,\
458
        cname##_ofb_cipher,\
459
        cleanup,\
460
        sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
461
                sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
462
        set_asn1, get_asn1,\
463
        ctrl,\
464
        NULL \
465
};\
466
const EVP_CIPHER *EVP_##cname##_ofb(void) { return &cname##_ofb; }\
467
static const EVP_CIPHER cname##_ecb = {\
468
        nid##_ecb, block_size, key_len, iv_len, \
469
        flags | EVP_CIPH_ECB_MODE,\
470
        init_key,\
471
        cname##_ecb_cipher,\
472
        cleanup,\
473
        sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
474
                sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
475
        set_asn1, get_asn1,\
476
        ctrl,\
477
        NULL \
478
};\
479
const EVP_CIPHER *EVP_##cname##_ecb(void) { return &cname##_ecb; }
480
*/
481
482
#define IMPLEMENT_BLOCK_CIPHER(cname, ksched, cprefix, kstruct, nid, \
483
                               block_size, key_len, iv_len, cbits, \
484
                               flags, init_key, \
485
                               cleanup, set_asn1, get_asn1, ctrl) \
486
        BLOCK_CIPHER_all_funcs(cname, cprefix, cbits, kstruct, ksched) \
487
        BLOCK_CIPHER_defs(cname, kstruct, nid, block_size, key_len, iv_len, \
488
                          cbits, flags, init_key, cleanup, set_asn1, \
489
                          get_asn1, ctrl)
490
491
#define IMPLEMENT_CFBR(cipher,cprefix,kstruct,ksched,keysize,cbits,iv_len,fl) \
492
        BLOCK_CIPHER_func_cfb(cipher##_##keysize,cprefix,cbits,kstruct,ksched) \
493
        BLOCK_CIPHER_def_cfb(cipher##_##keysize,kstruct, \
494
                             NID_##cipher##_##keysize, keysize/8, iv_len, cbits, \
495
                             (fl)|EVP_CIPH_FLAG_DEFAULT_ASN1, \
496
                             cipher##_init_key, NULL, NULL, NULL, NULL)
497
498
499
# ifndef OPENSSL_NO_EC
500
501
320
#define X25519_KEYLEN        32
502
0
#define X448_KEYLEN          56
503
#define ED25519_KEYLEN       32
504
200
#define ED448_KEYLEN         57
505
506
#define MAX_KEYLEN  ED448_KEYLEN
507
508
typedef struct {
509
    unsigned char pubkey[MAX_KEYLEN];
510
    unsigned char *privkey;
511
} ECX_KEY;
512
513
#endif
514
515
/*
516
 * Type needs to be a bit field Sub-type needs to be for variations on the
517
 * method, as in, can it do arbitrary encryption....
518
 */
519
struct evp_pkey_st {
520
    /* == Legacy attributes == */
521
    int type;
522
    int save_type;
523
    const EVP_PKEY_ASN1_METHOD *ameth;
524
    ENGINE *engine;
525
    ENGINE *pmeth_engine; /* If not NULL public key ENGINE to use */
526
    union {
527
        void *ptr;
528
# ifndef OPENSSL_NO_RSA
529
        struct rsa_st *rsa;     /* RSA */
530
# endif
531
# ifndef OPENSSL_NO_DSA
532
        struct dsa_st *dsa;     /* DSA */
533
# endif
534
# ifndef OPENSSL_NO_DH
535
        struct dh_st *dh;       /* DH */
536
# endif
537
# ifndef OPENSSL_NO_EC
538
        struct ec_key_st *ec;   /* ECC */
539
        ECX_KEY *ecx;           /* X25519, X448, Ed25519, Ed448 */
540
# endif
541
    } pkey;
542
543
    /* == Common attributes == */
544
    CRYPTO_REF_COUNT references;
545
    CRYPTO_RWLOCK *lock;
546
    STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
547
    int save_parameters;
548
549
    /* == Provider attributes == */
550
    /*
551
     * To support transparent export/import between providers that support
552
     * the methods for it, and still not having to do the export/import
553
     * every time a key object is changed, we maintain a cache of imported
554
     * key objects, indexed by keymgmt address.  pkeys[0] is *always* the
555
     * "original" data unless we have a legacy key attached.
556
     */
557
    struct {
558
        EVP_KEYMGMT *keymgmt;
559
        void *keydata;
560
    } pkeys[10];
561
    /*
562
     * If there is a legacy key assigned to this structure, we keep
563
     * a copy of that key's dirty count.
564
     */
565
    size_t dirty_cnt_copy;
566
567
    /* Cache of key object information */
568
    struct {
569
        int bits;
570
        int security_bits;
571
        int size;
572
    } cache;
573
} /* EVP_PKEY */ ;
574
575
#define EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx) \
576
0
    ((ctx)->operation == EVP_PKEY_OP_SIGN \
577
0
     || (ctx)->operation == EVP_PKEY_OP_SIGNCTX \
578
0
     || (ctx)->operation == EVP_PKEY_OP_VERIFY \
579
0
     || (ctx)->operation == EVP_PKEY_OP_VERIFYCTX \
580
0
     || (ctx)->operation == EVP_PKEY_OP_VERIFYRECOVER)
581
582
#define EVP_PKEY_CTX_IS_DERIVE_OP(ctx) \
583
0
    ((ctx)->operation == EVP_PKEY_OP_DERIVE)
584
585
#define EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx) \
586
0
    ((ctx)->operation == EVP_PKEY_OP_ENCRYPT \
587
0
     || (ctx)->operation == EVP_PKEY_OP_DECRYPT)
588
589
void openssl_add_all_ciphers_int(void);
590
void openssl_add_all_digests_int(void);
591
void evp_cleanup_int(void);
592
void evp_app_cleanup_int(void);
593
594
/*
595
 * KEYMGMT utility functions
596
 */
597
void *evp_keymgmt_util_export_to_provider(EVP_PKEY *pk, EVP_KEYMGMT *keymgmt);
598
void evp_keymgmt_util_clear_pkey_cache(EVP_PKEY *pk);
599
void evp_keymgmt_util_cache_pkey(EVP_PKEY *pk, size_t index,
600
                                 EVP_KEYMGMT *keymgmt, void *keydata);
601
void *evp_keymgmt_util_fromdata(EVP_PKEY *target, EVP_KEYMGMT *keymgmt,
602
                                int selection, const OSSL_PARAM params[]);
603
604
605
/*
606
 * KEYMGMT provider interface functions
607
 */
608
void *evp_keymgmt_newdata(const EVP_KEYMGMT *keymgmt);
609
void evp_keymgmt_freedata(const EVP_KEYMGMT *keymgmt, void *keyddata);
610
int evp_keymgmt_get_params(const EVP_KEYMGMT *keymgmt,
611
                           void *keydata, OSSL_PARAM params[]);
612
const OSSL_PARAM *evp_keymgmt_gettable_params(const EVP_KEYMGMT *keymgmt);
613
614
615
int evp_keymgmt_has(const EVP_KEYMGMT *keymgmt, void *keyddata, int selection);
616
int evp_keymgmt_validate(const EVP_KEYMGMT *keymgmt, void *keydata,
617
                         int selection);
618
619
int evp_keymgmt_import(const EVP_KEYMGMT *keymgmt, void *keydata,
620
                       int selection, const OSSL_PARAM params[]);
621
const OSSL_PARAM *evp_keymgmt_import_types(const EVP_KEYMGMT *keymgmt,
622
                                           int selection);
623
int evp_keymgmt_export(const EVP_KEYMGMT *keymgmt, void *keydata,
624
                       int selection, OSSL_CALLBACK *param_cb, void *cbarg);
625
const OSSL_PARAM *evp_keymgmt_export_types(const EVP_KEYMGMT *keymgmt,
626
                                           int selection);
627
628
/* Pulling defines out of C source files */
629
630
#define EVP_RC4_KEY_SIZE 16
631
#ifndef TLS1_1_VERSION
632
0
# define TLS1_1_VERSION   0x0302
633
#endif
634
635
void evp_encode_ctx_set_flags(EVP_ENCODE_CTX *ctx, unsigned int flags);
636
637
/* EVP_ENCODE_CTX flags */
638
/* Don't generate new lines when encoding */
639
0
#define EVP_ENCODE_CTX_NO_NEWLINES          1
640
/* Use the SRP base64 alphabet instead of the standard one */
641
0
#define EVP_ENCODE_CTX_USE_SRP_ALPHABET     2
642
643
const EVP_CIPHER *evp_get_cipherbyname_ex(OPENSSL_CTX *libctx, const char *name);
644
const EVP_MD *evp_get_digestbyname_ex(OPENSSL_CTX *libctx, const char *name);
645