2 * Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.
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
11 * EVP _meth_ APIs are deprecated for public use, but still ok for
14 #include "internal/deprecated.h"
18 #include <openssl/evp.h>
19 #include "crypto/evp.h"
20 #include "internal/provider.h"
21 #include "evp_local.h"
23 EVP_CIPHER *EVP_CIPHER_meth_new(int cipher_type, int block_size, int key_len)
25 EVP_CIPHER *cipher = evp_cipher_new();
28 cipher->nid = cipher_type;
29 cipher->block_size = block_size;
30 cipher->key_len = key_len;
31 cipher->origin = EVP_ORIG_METH;
36 EVP_CIPHER *EVP_CIPHER_meth_dup(const EVP_CIPHER *cipher)
38 EVP_CIPHER *to = NULL;
41 * Non-legacy EVP_CIPHERs can't be duplicated like this.
42 * Use EVP_CIPHER_up_ref() instead.
44 if (cipher->prov != NULL)
47 if ((to = EVP_CIPHER_meth_new(cipher->nid, cipher->block_size,
48 cipher->key_len)) != NULL) {
49 CRYPTO_RWLOCK *lock = to->lock;
51 memcpy(to, cipher, sizeof(*to));
53 to->origin = EVP_ORIG_METH;
58 void EVP_CIPHER_meth_free(EVP_CIPHER *cipher)
60 if (cipher == NULL || cipher->origin != EVP_ORIG_METH)
63 evp_cipher_free_int(cipher);
66 int EVP_CIPHER_meth_set_iv_length(EVP_CIPHER *cipher, int iv_len)
68 if (cipher->iv_len != 0)
71 cipher->iv_len = iv_len;
75 int EVP_CIPHER_meth_set_flags(EVP_CIPHER *cipher, unsigned long flags)
77 if (cipher->flags != 0)
80 cipher->flags = flags;
84 int EVP_CIPHER_meth_set_impl_ctx_size(EVP_CIPHER *cipher, int ctx_size)
86 if (cipher->ctx_size != 0)
89 cipher->ctx_size = ctx_size;
93 int EVP_CIPHER_meth_set_init(EVP_CIPHER *cipher,
94 int (*init) (EVP_CIPHER_CTX *ctx,
95 const unsigned char *key,
96 const unsigned char *iv,
99 if (cipher->init != NULL)
106 int EVP_CIPHER_meth_set_do_cipher(EVP_CIPHER *cipher,
107 int (*do_cipher) (EVP_CIPHER_CTX *ctx,
109 const unsigned char *in,
112 if (cipher->do_cipher != NULL)
115 cipher->do_cipher = do_cipher;
119 int EVP_CIPHER_meth_set_cleanup(EVP_CIPHER *cipher,
120 int (*cleanup) (EVP_CIPHER_CTX *))
122 if (cipher->cleanup != NULL)
125 cipher->cleanup = cleanup;
129 int EVP_CIPHER_meth_set_set_asn1_params(EVP_CIPHER *cipher,
130 int (*set_asn1_parameters) (EVP_CIPHER_CTX *,
133 if (cipher->set_asn1_parameters != NULL)
136 cipher->set_asn1_parameters = set_asn1_parameters;
140 int EVP_CIPHER_meth_set_get_asn1_params(EVP_CIPHER *cipher,
141 int (*get_asn1_parameters) (EVP_CIPHER_CTX *,
144 if (cipher->get_asn1_parameters != NULL)
147 cipher->get_asn1_parameters = get_asn1_parameters;
151 int EVP_CIPHER_meth_set_ctrl(EVP_CIPHER *cipher,
152 int (*ctrl) (EVP_CIPHER_CTX *, int type,
155 if (cipher->ctrl != NULL)
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,
170 int (*EVP_CIPHER_meth_get_do_cipher(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *ctx,
172 const unsigned char *in,
175 return cipher->do_cipher;
178 int (*EVP_CIPHER_meth_get_cleanup(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *)
180 return cipher->cleanup;
183 int (*EVP_CIPHER_meth_get_set_asn1_params(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *,
186 return cipher->set_asn1_parameters;
189 int (*EVP_CIPHER_meth_get_get_asn1_params(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *,
192 return cipher->get_asn1_parameters;
195 int (*EVP_CIPHER_meth_get_ctrl(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *,