Coverage Report

Created: 2026-09-12 06:55

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