Coverage Report

Created: 2025-12-31 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl30/providers/implementations/include/prov/ciphercommon.h
Line
Count
Source
1
/*
2
 * Copyright 2019-2024 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/params.h>
11
#include <openssl/core_dispatch.h>
12
#include <openssl/core_names.h>
13
#include <openssl/evp.h>
14
#include "internal/cryptlib.h"
15
#include "crypto/modes.h"
16
17
105k
#define MAXCHUNK ((size_t)1 << 30)
18
160
#define MAXBITCHUNK ((size_t)1 << (sizeof(size_t) * 8 - 4))
19
20
#define GENERIC_BLOCK_SIZE 16
21
12.6M
#define IV_STATE_UNINITIALISED 0 /* initial state is not initialized */
22
16.4M
#define IV_STATE_BUFFERED 1 /* iv has been copied to the iv buffer */
23
3.63M
#define IV_STATE_COPIED 2 /* iv has been copied from the iv buffer */
24
15.0M
#define IV_STATE_FINISHED 3 /* the iv has been used - so don't reuse it */
25
26
#define PROV_CIPHER_FUNC(type, name, args) typedef type(*OSSL_##name##_fn) args
27
28
typedef struct prov_cipher_hw_st PROV_CIPHER_HW;
29
typedef struct prov_cipher_ctx_st PROV_CIPHER_CTX;
30
31
typedef int(PROV_CIPHER_HW_FN)(PROV_CIPHER_CTX *dat, unsigned char *out,
32
    const unsigned char *in, size_t len);
33
34
/* Internal flags that can be queried */
35
133k
#define PROV_CIPHER_FLAG_AEAD 0x0001
36
146k
#define PROV_CIPHER_FLAG_CUSTOM_IV 0x0002
37
4.53k
#define PROV_CIPHER_FLAG_CTS 0x0004
38
4.53k
#define PROV_CIPHER_FLAG_TLS1_MULTIBLOCK 0x0008
39
4.53k
#define PROV_CIPHER_FLAG_RAND_KEY 0x0010
40
/* Internal flags that are only used within the provider */
41
266k
#define PROV_CIPHER_FLAG_VARIABLE_LENGTH 0x0100
42
266k
#define PROV_CIPHER_FLAG_INVERSE_CIPHER 0x0200
43
44
struct prov_cipher_ctx_st {
45
    /* place buffer at the beginning for memory alignment */
46
    /* The original value of the iv */
47
    unsigned char oiv[GENERIC_BLOCK_SIZE];
48
    /* Buffer of partial blocks processed via update calls */
49
    unsigned char buf[GENERIC_BLOCK_SIZE];
50
    unsigned char iv[GENERIC_BLOCK_SIZE];
51
52
    block128_f block;
53
    union {
54
        cbc128_f cbc;
55
        ctr128_f ctr;
56
        ecb128_f ecb;
57
    } stream;
58
59
    unsigned int mode;
60
    size_t keylen; /* key size (in bytes) */
61
    size_t ivlen;
62
    size_t blocksize;
63
    size_t bufsz; /* Number of bytes in buf */
64
    unsigned int cts_mode; /* Use to set the type for CTS modes */
65
    unsigned int pad : 1; /* Whether padding should be used or not */
66
    unsigned int enc : 1; /* Set to 1 for encrypt, or 0 otherwise */
67
    unsigned int iv_set : 1; /* Set when the iv is copied to the iv/oiv buffers */
68
    unsigned int key_set : 1; /* Set when key is set on the context */
69
    unsigned int updated : 1; /* Set to 1 during update for one shot ciphers */
70
    unsigned int variable_keylength : 1;
71
    unsigned int inverse_cipher : 1; /* set to 1 to use inverse cipher */
72
    unsigned int use_bits : 1; /* Set to 0 for cfb1 to use bits instead of bytes */
73
74
    unsigned int tlsversion; /* If TLS padding is in use the TLS version number */
75
    unsigned char *tlsmac; /* tls MAC extracted from the last record */
76
    int alloced; /*
77
                  * Whether the tlsmac data has been allocated or
78
                  * points into the user buffer.
79
                  */
80
    size_t tlsmacsize; /* Size of the TLS MAC */
81
    int removetlspad; /* Whether TLS padding should be removed or not */
82
    size_t removetlsfixed; /*
83
                            * Length of the fixed size data to remove when
84
                            * processing TLS data (equals mac size plus
85
                            * IV size if applicable)
86
                            */
87
88
    /*
89
     * num contains the number of bytes of |iv| which are valid for modes that
90
     * manage partial blocks themselves.
91
     */
92
    unsigned int num;
93
    const PROV_CIPHER_HW *hw; /* hardware specific functions */
94
    const void *ks; /* Pointer to algorithm specific key data */
95
    OSSL_LIB_CTX *libctx;
96
};
97
98
struct prov_cipher_hw_st {
99
    int (*init)(PROV_CIPHER_CTX *dat, const uint8_t *key, size_t keylen);
100
    PROV_CIPHER_HW_FN *cipher;
101
    void (*copyctx)(PROV_CIPHER_CTX *dst, const PROV_CIPHER_CTX *src);
102
};
103
104
void ossl_cipher_generic_reset_ctx(PROV_CIPHER_CTX *ctx);
105
OSSL_FUNC_cipher_encrypt_init_fn ossl_cipher_generic_einit;
106
OSSL_FUNC_cipher_decrypt_init_fn ossl_cipher_generic_dinit;
107
OSSL_FUNC_cipher_update_fn ossl_cipher_generic_block_update;
108
OSSL_FUNC_cipher_final_fn ossl_cipher_generic_block_final;
109
OSSL_FUNC_cipher_update_fn ossl_cipher_generic_stream_update;
110
OSSL_FUNC_cipher_final_fn ossl_cipher_generic_stream_final;
111
OSSL_FUNC_cipher_cipher_fn ossl_cipher_generic_cipher;
112
OSSL_FUNC_cipher_get_ctx_params_fn ossl_cipher_generic_get_ctx_params;
113
OSSL_FUNC_cipher_set_ctx_params_fn ossl_cipher_generic_set_ctx_params;
114
OSSL_FUNC_cipher_gettable_params_fn ossl_cipher_generic_gettable_params;
115
OSSL_FUNC_cipher_gettable_ctx_params_fn ossl_cipher_generic_gettable_ctx_params;
116
OSSL_FUNC_cipher_settable_ctx_params_fn ossl_cipher_generic_settable_ctx_params;
117
OSSL_FUNC_cipher_set_ctx_params_fn ossl_cipher_var_keylen_set_ctx_params;
118
OSSL_FUNC_cipher_settable_ctx_params_fn ossl_cipher_var_keylen_settable_ctx_params;
119
OSSL_FUNC_cipher_gettable_ctx_params_fn ossl_cipher_aead_gettable_ctx_params;
120
OSSL_FUNC_cipher_settable_ctx_params_fn ossl_cipher_aead_settable_ctx_params;
121
122
int ossl_cipher_generic_get_params(OSSL_PARAM params[], unsigned int md,
123
    uint64_t flags,
124
    size_t kbits, size_t blkbits, size_t ivbits);
125
void ossl_cipher_generic_initkey(void *vctx, size_t kbits, size_t blkbits,
126
    size_t ivbits, unsigned int mode,
127
    uint64_t flags,
128
    const PROV_CIPHER_HW *hw, void *provctx);
129
130
#define IMPLEMENT_generic_cipher_func(alg, UCALG, lcmode, UCMODE, flags, kbits,          \
131
    blkbits, ivbits, typ)                                                                \
132
    const OSSL_DISPATCH ossl_##alg##kbits##lcmode##_functions[] = {                      \
133
        { OSSL_FUNC_CIPHER_NEWCTX,                                                       \
134
            (void (*)(void))alg##_##kbits##_##lcmode##_newctx },                         \
135
        { OSSL_FUNC_CIPHER_FREECTX, (void (*)(void))alg##_freectx },                     \
136
        { OSSL_FUNC_CIPHER_DUPCTX, (void (*)(void))alg##_dupctx },                       \
137
        { OSSL_FUNC_CIPHER_ENCRYPT_INIT, (void (*)(void))ossl_cipher_generic_einit },    \
138
        { OSSL_FUNC_CIPHER_DECRYPT_INIT, (void (*)(void))ossl_cipher_generic_dinit },    \
139
        { OSSL_FUNC_CIPHER_UPDATE, (void (*)(void))ossl_cipher_generic_##typ##_update }, \
140
        { OSSL_FUNC_CIPHER_FINAL, (void (*)(void))ossl_cipher_generic_##typ##_final },   \
141
        { OSSL_FUNC_CIPHER_CIPHER, (void (*)(void))ossl_cipher_generic_cipher },         \
142
        { OSSL_FUNC_CIPHER_GET_PARAMS,                                                   \
143
            (void (*)(void))alg##_##kbits##_##lcmode##_get_params },                     \
144
        { OSSL_FUNC_CIPHER_GET_CTX_PARAMS,                                               \
145
            (void (*)(void))ossl_cipher_generic_get_ctx_params },                        \
146
        { OSSL_FUNC_CIPHER_SET_CTX_PARAMS,                                               \
147
            (void (*)(void))ossl_cipher_generic_set_ctx_params },                        \
148
        { OSSL_FUNC_CIPHER_GETTABLE_PARAMS,                                              \
149
            (void (*)(void))ossl_cipher_generic_gettable_params },                       \
150
        { OSSL_FUNC_CIPHER_GETTABLE_CTX_PARAMS,                                          \
151
            (void (*)(void))ossl_cipher_generic_gettable_ctx_params },                   \
152
        { OSSL_FUNC_CIPHER_SETTABLE_CTX_PARAMS,                                          \
153
            (void (*)(void))ossl_cipher_generic_settable_ctx_params },                   \
154
        { 0, NULL }                                                                      \
155
    };
156
157
#define IMPLEMENT_var_keylen_cipher_func(alg, UCALG, lcmode, UCMODE, flags,              \
158
    kbits, blkbits, ivbits, typ)                                                         \
159
    const OSSL_DISPATCH ossl_##alg##kbits##lcmode##_functions[] = {                      \
160
        { OSSL_FUNC_CIPHER_NEWCTX,                                                       \
161
            (void (*)(void))alg##_##kbits##_##lcmode##_newctx },                         \
162
        { OSSL_FUNC_CIPHER_FREECTX, (void (*)(void))alg##_freectx },                     \
163
        { OSSL_FUNC_CIPHER_DUPCTX, (void (*)(void))alg##_dupctx },                       \
164
        { OSSL_FUNC_CIPHER_ENCRYPT_INIT, (void (*)(void))ossl_cipher_generic_einit },    \
165
        { OSSL_FUNC_CIPHER_DECRYPT_INIT, (void (*)(void))ossl_cipher_generic_dinit },    \
166
        { OSSL_FUNC_CIPHER_UPDATE, (void (*)(void))ossl_cipher_generic_##typ##_update }, \
167
        { OSSL_FUNC_CIPHER_FINAL, (void (*)(void))ossl_cipher_generic_##typ##_final },   \
168
        { OSSL_FUNC_CIPHER_CIPHER, (void (*)(void))ossl_cipher_generic_cipher },         \
169
        { OSSL_FUNC_CIPHER_GET_PARAMS,                                                   \
170
            (void (*)(void))alg##_##kbits##_##lcmode##_get_params },                     \
171
        { OSSL_FUNC_CIPHER_GET_CTX_PARAMS,                                               \
172
            (void (*)(void))ossl_cipher_generic_get_ctx_params },                        \
173
        { OSSL_FUNC_CIPHER_SET_CTX_PARAMS,                                               \
174
            (void (*)(void))ossl_cipher_var_keylen_set_ctx_params },                     \
175
        { OSSL_FUNC_CIPHER_GETTABLE_PARAMS,                                              \
176
            (void (*)(void))ossl_cipher_generic_gettable_params },                       \
177
        { OSSL_FUNC_CIPHER_GETTABLE_CTX_PARAMS,                                          \
178
            (void (*)(void))ossl_cipher_generic_gettable_ctx_params },                   \
179
        { OSSL_FUNC_CIPHER_SETTABLE_CTX_PARAMS,                                          \
180
            (void (*)(void))ossl_cipher_var_keylen_settable_ctx_params },                \
181
        { 0, NULL }                                                                      \
182
    };
183
184
#define IMPLEMENT_generic_cipher_genfn(alg, UCALG, lcmode, UCMODE, flags,               \
185
    kbits, blkbits, ivbits, typ)                                                        \
186
    static OSSL_FUNC_cipher_get_params_fn alg##_##kbits##_##lcmode##_get_params;        \
187
    static int alg##_##kbits##_##lcmode##_get_params(OSSL_PARAM params[])               \
188
486k
    {                                                                                   \
189
486k
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
486k
            flags, kbits, blkbits, ivbits);                                             \
191
486k
    }                                                                                   \
cipher_aes.c:aes_256_ecb_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aes.c:aes_192_ecb_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aes.c:aes_128_ecb_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aes.c:aes_256_cbc_get_params
Line
Count
Source
188
120k
    {                                                                                   \
189
120k
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
120k
            flags, kbits, blkbits, ivbits);                                             \
191
120k
    }                                                                                   \
cipher_aes.c:aes_192_cbc_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aes.c:aes_128_cbc_get_params
Line
Count
Source
188
120k
    {                                                                                   \
189
120k
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
120k
            flags, kbits, blkbits, ivbits);                                             \
191
120k
    }                                                                                   \
cipher_aes.c:aes_256_ofb_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aes.c:aes_192_ofb_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aes.c:aes_128_ofb_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aes.c:aes_256_cfb_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aes.c:aes_192_cfb_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aes.c:aes_128_cfb_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aes.c:aes_256_cfb1_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aes.c:aes_192_cfb1_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aes.c:aes_128_cfb1_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aes.c:aes_256_cfb8_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aes.c:aes_192_cfb8_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aes.c:aes_128_cfb8_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aes.c:aes_256_ctr_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aes.c:aes_192_ctr_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aes.c:aes_128_ctr_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aria.c:aria_256_ecb_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aria.c:aria_192_ecb_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aria.c:aria_128_ecb_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aria.c:aria_256_cbc_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aria.c:aria_192_cbc_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aria.c:aria_128_cbc_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aria.c:aria_256_ofb_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aria.c:aria_192_ofb_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aria.c:aria_128_ofb_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aria.c:aria_256_cfb_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aria.c:aria_192_cfb_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aria.c:aria_128_cfb_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aria.c:aria_256_cfb1_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aria.c:aria_192_cfb1_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aria.c:aria_128_cfb1_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aria.c:aria_256_cfb8_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aria.c:aria_192_cfb8_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aria.c:aria_128_cfb8_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aria.c:aria_256_ctr_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aria.c:aria_192_ctr_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_aria.c:aria_128_ctr_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_camellia.c:camellia_256_ecb_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_camellia.c:camellia_192_ecb_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_camellia.c:camellia_128_ecb_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_camellia.c:camellia_256_cbc_get_params
Line
Count
Source
188
120k
    {                                                                                   \
189
120k
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
120k
            flags, kbits, blkbits, ivbits);                                             \
191
120k
    }                                                                                   \
cipher_camellia.c:camellia_192_cbc_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_camellia.c:camellia_128_cbc_get_params
Line
Count
Source
188
120k
    {                                                                                   \
189
120k
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
120k
            flags, kbits, blkbits, ivbits);                                             \
191
120k
    }                                                                                   \
cipher_camellia.c:camellia_256_ofb_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_camellia.c:camellia_192_ofb_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_camellia.c:camellia_128_ofb_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_camellia.c:camellia_256_cfb_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_camellia.c:camellia_192_cfb_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_camellia.c:camellia_128_cfb_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_camellia.c:camellia_256_cfb1_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_camellia.c:camellia_192_cfb1_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_camellia.c:camellia_128_cfb1_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_camellia.c:camellia_256_cfb8_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_camellia.c:camellia_192_cfb8_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_camellia.c:camellia_128_cfb8_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_camellia.c:camellia_256_ctr_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_camellia.c:camellia_192_ctr_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_camellia.c:camellia_128_ctr_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_sm4.c:sm4_128_ecb_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_sm4.c:sm4_128_cbc_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_sm4.c:sm4_128_ctr_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_sm4.c:sm4_128_ofb128_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
cipher_sm4.c:sm4_128_cfb128_get_params
Line
Count
Source
188
64
    {                                                                                   \
189
64
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,         \
190
64
            flags, kbits, blkbits, ivbits);                                             \
191
64
    }                                                                                   \
192
    static OSSL_FUNC_cipher_newctx_fn alg##_##kbits##_##lcmode##_newctx;                \
193
    static void *alg##_##kbits##_##lcmode##_newctx(void *provctx)                       \
194
235k
    {                                                                                   \
195
235k
        PROV_##UCALG##_CTX *ctx = ossl_prov_is_running() ? OPENSSL_zalloc(sizeof(*ctx)) \
196
235k
                                                         : NULL;                        \
197
235k
        if (ctx != NULL) {                                                              \
198
235k
            ossl_cipher_generic_initkey(ctx, kbits, blkbits, ivbits,                    \
199
235k
                EVP_CIPH_##UCMODE##_MODE, flags,                                        \
200
235k
                ossl_prov_cipher_hw_##alg##_##lcmode(kbits),                            \
201
235k
                provctx);                                                               \
202
235k
        }                                                                               \
203
235k
        return ctx;                                                                     \
204
235k
    }
205
206
#define IMPLEMENT_generic_cipher(alg, UCALG, lcmode, UCMODE, flags, kbits,   \
207
    blkbits, ivbits, typ)                                                    \
208
    IMPLEMENT_generic_cipher_genfn(alg, UCALG, lcmode, UCMODE, flags, kbits, \
209
        blkbits, ivbits, typ)                                                \
210
    IMPLEMENT_generic_cipher_func(alg, UCALG, lcmode, UCMODE, flags, kbits,  \
211
        blkbits, ivbits, typ)
212
213
#define IMPLEMENT_var_keylen_cipher(alg, UCALG, lcmode, UCMODE, flags, kbits,  \
214
    blkbits, ivbits, typ)                                                      \
215
    IMPLEMENT_generic_cipher_genfn(alg, UCALG, lcmode, UCMODE, flags, kbits,   \
216
        blkbits, ivbits, typ)                                                  \
217
    IMPLEMENT_var_keylen_cipher_func(alg, UCALG, lcmode, UCMODE, flags, kbits, \
218
        blkbits, ivbits, typ)
219
220
PROV_CIPHER_HW_FN ossl_cipher_hw_generic_cbc;
221
PROV_CIPHER_HW_FN ossl_cipher_hw_generic_ecb;
222
PROV_CIPHER_HW_FN ossl_cipher_hw_generic_ofb128;
223
PROV_CIPHER_HW_FN ossl_cipher_hw_generic_cfb128;
224
PROV_CIPHER_HW_FN ossl_cipher_hw_generic_cfb8;
225
PROV_CIPHER_HW_FN ossl_cipher_hw_generic_cfb1;
226
PROV_CIPHER_HW_FN ossl_cipher_hw_generic_ctr;
227
PROV_CIPHER_HW_FN ossl_cipher_hw_chunked_cbc;
228
PROV_CIPHER_HW_FN ossl_cipher_hw_chunked_cfb8;
229
PROV_CIPHER_HW_FN ossl_cipher_hw_chunked_cfb128;
230
PROV_CIPHER_HW_FN ossl_cipher_hw_chunked_ofb128;
231
#define ossl_cipher_hw_chunked_ecb ossl_cipher_hw_generic_ecb
232
#define ossl_cipher_hw_chunked_ctr ossl_cipher_hw_generic_ctr
233
#define ossl_cipher_hw_chunked_cfb1 ossl_cipher_hw_generic_cfb1
234
235
#define IMPLEMENT_CIPHER_HW_OFB(MODE, NAME, CTX_NAME, KEY_NAME, FUNC_PREFIX) \
236
    static int cipher_hw_##NAME##_##MODE##_cipher(PROV_CIPHER_CTX *ctx,      \
237
        unsigned char *out,                                                  \
238
        const unsigned char *in, size_t len)                                 \
239
    {                                                                        \
240
        int num = ctx->num;                                                  \
241
        KEY_NAME *key = &(((CTX_NAME *)ctx)->ks.ks);                         \
242
                                                                             \
243
        while (len >= MAXCHUNK) {                                            \
244
            FUNC_PREFIX##_encrypt(in, out, MAXCHUNK, key, ctx->iv, &num);    \
245
            len -= MAXCHUNK;                                                 \
246
            in += MAXCHUNK;                                                  \
247
            out += MAXCHUNK;                                                 \
248
        }                                                                    \
249
        if (len > 0) {                                                       \
250
            FUNC_PREFIX##_encrypt(in, out, (long)len, key, ctx->iv, &num);   \
251
        }                                                                    \
252
        ctx->num = num;                                                      \
253
        return 1;                                                            \
254
    }
255
256
#define IMPLEMENT_CIPHER_HW_ECB(MODE, NAME, CTX_NAME, KEY_NAME, FUNC_PREFIX) \
257
    static int cipher_hw_##NAME##_##MODE##_cipher(PROV_CIPHER_CTX *ctx,      \
258
        unsigned char *out,                                                  \
259
        const unsigned char *in, size_t len)                                 \
260
    {                                                                        \
261
        size_t i, bl = ctx->blocksize;                                       \
262
        KEY_NAME *key = &(((CTX_NAME *)ctx)->ks.ks);                         \
263
                                                                             \
264
        if (len < bl)                                                        \
265
            return 1;                                                        \
266
        for (i = 0, len -= bl; i <= len; i += bl)                            \
267
            FUNC_PREFIX##_encrypt(in + i, out + i, key, ctx->enc);           \
268
        return 1;                                                            \
269
    }
270
271
#define IMPLEMENT_CIPHER_HW_CBC(MODE, NAME, CTX_NAME, KEY_NAME, FUNC_PREFIX)   \
272
    static int cipher_hw_##NAME##_##MODE##_cipher(PROV_CIPHER_CTX *ctx,        \
273
        unsigned char *out,                                                    \
274
        const unsigned char *in, size_t len)                                   \
275
    {                                                                          \
276
        KEY_NAME *key = &(((CTX_NAME *)ctx)->ks.ks);                           \
277
                                                                               \
278
        while (len >= MAXCHUNK) {                                              \
279
            FUNC_PREFIX##_encrypt(in, out, MAXCHUNK, key, ctx->iv, ctx->enc);  \
280
            len -= MAXCHUNK;                                                   \
281
            in += MAXCHUNK;                                                    \
282
            out += MAXCHUNK;                                                   \
283
        }                                                                      \
284
        if (len > 0)                                                           \
285
            FUNC_PREFIX##_encrypt(in, out, (long)len, key, ctx->iv, ctx->enc); \
286
        return 1;                                                              \
287
    }
288
289
#define IMPLEMENT_CIPHER_HW_CFB(MODE, NAME, CTX_NAME, KEY_NAME, FUNC_PREFIX) \
290
    static int cipher_hw_##NAME##_##MODE##_cipher(PROV_CIPHER_CTX *ctx,      \
291
        unsigned char *out,                                                  \
292
        const unsigned char *in, size_t len)                                 \
293
    {                                                                        \
294
        size_t chunk = MAXCHUNK;                                             \
295
        KEY_NAME *key = &(((CTX_NAME *)ctx)->ks.ks);                         \
296
        int num = ctx->num;                                                  \
297
                                                                             \
298
        if (len < chunk)                                                     \
299
            chunk = len;                                                     \
300
        while (len > 0 && len >= chunk) {                                    \
301
            FUNC_PREFIX##_encrypt(in, out, (long)chunk, key, ctx->iv, &num,  \
302
                ctx->enc);                                                   \
303
            len -= chunk;                                                    \
304
            in += chunk;                                                     \
305
            out += chunk;                                                    \
306
            if (len < chunk)                                                 \
307
                chunk = len;                                                 \
308
        }                                                                    \
309
        ctx->num = num;                                                      \
310
        return 1;                                                            \
311
    }
312
313
#define IMPLEMENT_CIPHER_HW_COPYCTX(name, CTX_TYPE)                    \
314
    static void name(PROV_CIPHER_CTX *dst, const PROV_CIPHER_CTX *src) \
315
66
    {                                                                  \
316
66
        CTX_TYPE *sctx = (CTX_TYPE *)src;                              \
317
66
        CTX_TYPE *dctx = (CTX_TYPE *)dst;                              \
318
66
                                                                       \
319
66
        *dctx = *sctx;                                                 \
320
66
        dst->ks = &dctx->ks.ks;                                        \
321
66
    }
cipher_aes_hw.c:cipher_hw_aes_copyctx
Line
Count
Source
315
66
    {                                                                  \
316
66
        CTX_TYPE *sctx = (CTX_TYPE *)src;                              \
317
66
        CTX_TYPE *dctx = (CTX_TYPE *)dst;                              \
318
66
                                                                       \
319
66
        *dctx = *sctx;                                                 \
320
66
        dst->ks = &dctx->ks.ks;                                        \
321
66
    }
Unexecuted instantiation: cipher_aria_hw.c:cipher_hw_aria_copyctx
Unexecuted instantiation: cipher_camellia_hw.c:cipher_hw_camellia_copyctx
Unexecuted instantiation: cipher_sm4_hw.c:cipher_hw_sm4_copyctx
322
323
#define CIPHER_DEFAULT_GETTABLE_CTX_PARAMS_START(name)             \
324
    static const OSSL_PARAM name##_known_gettable_ctx_params[] = { \
325
        OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_KEYLEN, NULL),         \
326
        OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_IVLEN, NULL),          \
327
        OSSL_PARAM_uint(OSSL_CIPHER_PARAM_PADDING, NULL),          \
328
        OSSL_PARAM_uint(OSSL_CIPHER_PARAM_NUM, NULL),              \
329
        OSSL_PARAM_octet_string(OSSL_CIPHER_PARAM_IV, NULL, 0),    \
330
        OSSL_PARAM_octet_string(OSSL_CIPHER_PARAM_UPDATED_IV, NULL, 0),
331
332
#define CIPHER_DEFAULT_GETTABLE_CTX_PARAMS_END(name)                     \
333
    OSSL_PARAM_END                                                       \
334
    }                                                                    \
335
    ;                                                                    \
336
    const OSSL_PARAM *name##_gettable_ctx_params(ossl_unused void *cctx, \
337
        ossl_unused void *provctx)                                       \
338
6.39k
    {                                                                    \
339
6.39k
        return name##_known_gettable_ctx_params;                         \
340
6.39k
    }
cipher_aes.c:aes_cbc_cts_gettable_ctx_params
Line
Count
Source
338
192
    {                                                                    \
339
192
        return name##_known_gettable_ctx_params;                         \
340
192
    }
cipher_camellia.c:camellia_cbc_cts_gettable_ctx_params
Line
Count
Source
338
192
    {                                                                    \
339
192
        return name##_known_gettable_ctx_params;                         \
340
192
    }
ossl_tdes_gettable_ctx_params
Line
Count
Source
338
704
    {                                                                    \
339
704
        return name##_known_gettable_ctx_params;                         \
340
704
    }
ossl_cipher_generic_gettable_ctx_params
Line
Count
Source
338
5.30k
    {                                                                    \
339
5.30k
        return name##_known_gettable_ctx_params;                         \
340
5.30k
    }
341
342
#define CIPHER_DEFAULT_SETTABLE_CTX_PARAMS_START(name)             \
343
    static const OSSL_PARAM name##_known_settable_ctx_params[] = { \
344
        OSSL_PARAM_uint(OSSL_CIPHER_PARAM_PADDING, NULL),          \
345
        OSSL_PARAM_uint(OSSL_CIPHER_PARAM_NUM, NULL),
346
#define CIPHER_DEFAULT_SETTABLE_CTX_PARAMS_END(name)                     \
347
    OSSL_PARAM_END                                                       \
348
    }                                                                    \
349
    ;                                                                    \
350
    const OSSL_PARAM *name##_settable_ctx_params(ossl_unused void *cctx, \
351
        ossl_unused void *provctx)                                       \
352
177
    {                                                                    \
353
177
        return name##_known_settable_ctx_params;                         \
354
177
    }
cipher_aes.c:aes_cbc_cts_settable_ctx_params
Line
Count
Source
352
4
    {                                                                    \
353
4
        return name##_known_settable_ctx_params;                         \
354
4
    }
cipher_camellia.c:camellia_cbc_cts_settable_ctx_params
Line
Count
Source
352
4
    {                                                                    \
353
4
        return name##_known_settable_ctx_params;                         \
354
4
    }
ossl_cipher_generic_settable_ctx_params
Line
Count
Source
352
169
    {                                                                    \
353
169
        return name##_known_settable_ctx_params;                         \
354
169
    }
Unexecuted instantiation: ossl_cipher_var_keylen_settable_ctx_params
355
356
int ossl_cipher_generic_initiv(PROV_CIPHER_CTX *ctx, const unsigned char *iv,
357
    size_t ivlen);
358
359
size_t ossl_cipher_fillblock(unsigned char *buf, size_t *buflen,
360
    size_t blocksize,
361
    const unsigned char **in, size_t *inlen);
362
int ossl_cipher_trailingdata(unsigned char *buf, size_t *buflen,
363
    size_t blocksize,
364
    const unsigned char **in, size_t *inlen);