Coverage Report

Created: 2025-12-31 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl34/crypto/evp/cmeth_lib.c
Line
Count
Source
1
/*
2
 * Copyright 2015-2023 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
/*
11
 * EVP _meth_ APIs are deprecated for public use, but still ok for
12
 * internal use.
13
 */
14
#include "internal/deprecated.h"
15
16
#include <string.h>
17
18
#include <openssl/evp.h>
19
#include "crypto/evp.h"
20
#include "internal/provider.h"
21
#include "evp_local.h"
22
23
EVP_CIPHER *EVP_CIPHER_meth_new(int cipher_type, int block_size, int key_len)
24
0
{
25
0
    EVP_CIPHER *cipher = evp_cipher_new();
26
27
0
    if (cipher != NULL) {
28
0
        cipher->nid = cipher_type;
29
0
        cipher->block_size = block_size;
30
0
        cipher->key_len = key_len;
31
0
        cipher->origin = EVP_ORIG_METH;
32
0
    }
33
0
    return cipher;
34
0
}
35
36
EVP_CIPHER *EVP_CIPHER_meth_dup(const EVP_CIPHER *cipher)
37
0
{
38
0
    EVP_CIPHER *to = NULL;
39
40
    /*
41
     * Non-legacy EVP_CIPHERs can't be duplicated like this.
42
     * Use EVP_CIPHER_up_ref() instead.
43
     */
44
0
    if (cipher->prov != NULL)
45
0
        return NULL;
46
47
0
    if ((to = EVP_CIPHER_meth_new(cipher->nid, cipher->block_size,
48
0
             cipher->key_len))
49
0
        != NULL) {
50
0
        CRYPTO_REF_COUNT refcnt = to->refcnt;
51
52
0
        memcpy(to, cipher, sizeof(*to));
53
0
        to->refcnt = refcnt;
54
0
        to->origin = EVP_ORIG_METH;
55
0
    }
56
0
    return to;
57
0
}
58
59
void EVP_CIPHER_meth_free(EVP_CIPHER *cipher)
60
0
{
61
0
    if (cipher == NULL || cipher->origin != EVP_ORIG_METH)
62
0
        return;
63
64
0
    evp_cipher_free_int(cipher);
65
0
}
66
67
int EVP_CIPHER_meth_set_iv_length(EVP_CIPHER *cipher, int iv_len)
68
0
{
69
0
    if (cipher->iv_len != 0)
70
0
        return 0;
71
72
0
    cipher->iv_len = iv_len;
73
0
    return 1;
74
0
}
75
76
int EVP_CIPHER_meth_set_flags(EVP_CIPHER *cipher, unsigned long flags)
77
0
{
78
0
    if (cipher->flags != 0)
79
0
        return 0;
80
81
0
    cipher->flags = flags;
82
0
    return 1;
83
0
}
84
85
int EVP_CIPHER_meth_set_impl_ctx_size(EVP_CIPHER *cipher, int ctx_size)
86
0
{
87
0
    if (cipher->ctx_size != 0)
88
0
        return 0;
89
90
0
    cipher->ctx_size = ctx_size;
91
0
    return 1;
92
0
}
93
94
int EVP_CIPHER_meth_set_init(EVP_CIPHER *cipher,
95
    int (*init)(EVP_CIPHER_CTX *ctx,
96
        const unsigned char *key,
97
        const unsigned char *iv,
98
        int enc))
99
0
{
100
0
    if (cipher->init != NULL)
101
0
        return 0;
102
103
0
    cipher->init = init;
104
0
    return 1;
105
0
}
106
107
int EVP_CIPHER_meth_set_do_cipher(EVP_CIPHER *cipher,
108
    int (*do_cipher)(EVP_CIPHER_CTX *ctx,
109
        unsigned char *out,
110
        const unsigned char *in,
111
        size_t inl))
112
0
{
113
0
    if (cipher->do_cipher != NULL)
114
0
        return 0;
115
116
0
    cipher->do_cipher = do_cipher;
117
0
    return 1;
118
0
}
119
120
int EVP_CIPHER_meth_set_cleanup(EVP_CIPHER *cipher,
121
    int (*cleanup)(EVP_CIPHER_CTX *))
122
0
{
123
0
    if (cipher->cleanup != NULL)
124
0
        return 0;
125
126
0
    cipher->cleanup = cleanup;
127
0
    return 1;
128
0
}
129
130
int EVP_CIPHER_meth_set_set_asn1_params(EVP_CIPHER *cipher,
131
    int (*set_asn1_parameters)(EVP_CIPHER_CTX *,
132
        ASN1_TYPE *))
133
0
{
134
0
    if (cipher->set_asn1_parameters != NULL)
135
0
        return 0;
136
137
0
    cipher->set_asn1_parameters = set_asn1_parameters;
138
0
    return 1;
139
0
}
140
141
int EVP_CIPHER_meth_set_get_asn1_params(EVP_CIPHER *cipher,
142
    int (*get_asn1_parameters)(EVP_CIPHER_CTX *,
143
        ASN1_TYPE *))
144
0
{
145
0
    if (cipher->get_asn1_parameters != NULL)
146
0
        return 0;
147
148
0
    cipher->get_asn1_parameters = get_asn1_parameters;
149
0
    return 1;
150
0
}
151
152
int EVP_CIPHER_meth_set_ctrl(EVP_CIPHER *cipher,
153
    int (*ctrl)(EVP_CIPHER_CTX *, int type,
154
        int arg, void *ptr))
155
0
{
156
0
    if (cipher->ctrl != NULL)
157
0
        return 0;
158
159
0
    cipher->ctrl = ctrl;
160
0
    return 1;
161
0
}
162
163
int (*EVP_CIPHER_meth_get_init(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *ctx,
164
    const unsigned char *key,
165
    const unsigned char *iv,
166
    int enc)
167
0
{
168
0
    return cipher->init;
169
0
}
170
int (*EVP_CIPHER_meth_get_do_cipher(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *ctx,
171
    unsigned char *out,
172
    const unsigned char *in,
173
    size_t inl)
174
0
{
175
0
    return cipher->do_cipher;
176
0
}
177
178
int (*EVP_CIPHER_meth_get_cleanup(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *)
179
0
{
180
0
    return cipher->cleanup;
181
0
}
182
183
int (*EVP_CIPHER_meth_get_set_asn1_params(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *,
184
    ASN1_TYPE *)
185
0
{
186
0
    return cipher->set_asn1_parameters;
187
0
}
188
189
int (*EVP_CIPHER_meth_get_get_asn1_params(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *,
190
    ASN1_TYPE *)
191
0
{
192
0
    return cipher->get_asn1_parameters;
193
0
}
194
195
int (*EVP_CIPHER_meth_get_ctrl(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *,
196
    int type, int arg,
197
    void *ptr)
198
0
{
199
0
    return cipher->ctrl;
200
0
}