2 * Copyright 2015-2016 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
12 #include <openssl/evp.h>
13 #include "internal/evp_int.h"
14 #include "internal/provider.h"
17 EVP_CIPHER *EVP_CIPHER_meth_new(int cipher_type, int block_size, int key_len)
19 EVP_CIPHER *cipher = OPENSSL_zalloc(sizeof(EVP_CIPHER));
22 cipher->nid = cipher_type;
23 cipher->block_size = block_size;
24 cipher->key_len = key_len;
25 cipher->lock = CRYPTO_THREAD_lock_new();
26 if (cipher->lock == NULL) {
35 EVP_CIPHER *EVP_CIPHER_meth_dup(const EVP_CIPHER *cipher)
37 EVP_CIPHER *to = EVP_CIPHER_meth_new(cipher->nid, cipher->block_size,
41 CRYPTO_RWLOCK *lock = to->lock;
43 memcpy(to, cipher, sizeof(*to));
49 void EVP_CIPHER_meth_free(EVP_CIPHER *cipher)
54 CRYPTO_DOWN_REF(&cipher->refcnt, &i, cipher->lock);
57 ossl_provider_free(cipher->prov);
58 OPENSSL_free(cipher->name);
59 CRYPTO_THREAD_lock_free(cipher->lock);
64 int EVP_CIPHER_up_ref(EVP_CIPHER *cipher)
68 CRYPTO_UP_REF(&cipher->refcnt, &ref, cipher->lock);
72 int EVP_CIPHER_meth_set_iv_length(EVP_CIPHER *cipher, int iv_len)
74 cipher->iv_len = iv_len;
78 int EVP_CIPHER_meth_set_flags(EVP_CIPHER *cipher, unsigned long flags)
80 cipher->flags = flags;
84 int EVP_CIPHER_meth_set_impl_ctx_size(EVP_CIPHER *cipher, int ctx_size)
86 cipher->ctx_size = ctx_size;
90 int EVP_CIPHER_meth_set_init(EVP_CIPHER *cipher,
91 int (*init) (EVP_CIPHER_CTX *ctx,
92 const unsigned char *key,
93 const unsigned char *iv,
100 int EVP_CIPHER_meth_set_do_cipher(EVP_CIPHER *cipher,
101 int (*do_cipher) (EVP_CIPHER_CTX *ctx,
103 const unsigned char *in,
106 cipher->do_cipher = do_cipher;
110 int EVP_CIPHER_meth_set_cleanup(EVP_CIPHER *cipher,
111 int (*cleanup) (EVP_CIPHER_CTX *))
113 cipher->cleanup = cleanup;
117 int EVP_CIPHER_meth_set_set_asn1_params(EVP_CIPHER *cipher,
118 int (*set_asn1_parameters) (EVP_CIPHER_CTX *,
121 cipher->set_asn1_parameters = set_asn1_parameters;
125 int EVP_CIPHER_meth_set_get_asn1_params(EVP_CIPHER *cipher,
126 int (*get_asn1_parameters) (EVP_CIPHER_CTX *,
129 cipher->get_asn1_parameters = get_asn1_parameters;
133 int EVP_CIPHER_meth_set_ctrl(EVP_CIPHER *cipher,
134 int (*ctrl) (EVP_CIPHER_CTX *, int type,
142 int (*EVP_CIPHER_meth_get_init(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *ctx,
143 const unsigned char *key,
144 const unsigned char *iv,
149 int (*EVP_CIPHER_meth_get_do_cipher(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *ctx,
151 const unsigned char *in,
154 return cipher->do_cipher;
157 int (*EVP_CIPHER_meth_get_cleanup(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *)
159 return cipher->cleanup;
162 int (*EVP_CIPHER_meth_get_set_asn1_params(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *,
165 return cipher->set_asn1_parameters;
168 int (*EVP_CIPHER_meth_get_get_asn1_params(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *,
171 return cipher->get_asn1_parameters;
174 int (*EVP_CIPHER_meth_get_ctrl(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *,