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 CRYPTO_THREAD_lock_free(cipher->lock);
63 int EVP_CIPHER_upref(EVP_CIPHER *cipher)
67 CRYPTO_UP_REF(&cipher->refcnt, &ref, cipher->lock);
71 int EVP_CIPHER_meth_set_iv_length(EVP_CIPHER *cipher, int iv_len)
73 cipher->iv_len = iv_len;
77 int EVP_CIPHER_meth_set_flags(EVP_CIPHER *cipher, unsigned long flags)
79 cipher->flags = flags;
83 int EVP_CIPHER_meth_set_impl_ctx_size(EVP_CIPHER *cipher, int ctx_size)
85 cipher->ctx_size = ctx_size;
89 int EVP_CIPHER_meth_set_init(EVP_CIPHER *cipher,
90 int (*init) (EVP_CIPHER_CTX *ctx,
91 const unsigned char *key,
92 const unsigned char *iv,
99 int EVP_CIPHER_meth_set_do_cipher(EVP_CIPHER *cipher,
100 int (*do_cipher) (EVP_CIPHER_CTX *ctx,
102 const unsigned char *in,
105 cipher->do_cipher = do_cipher;
109 int EVP_CIPHER_meth_set_cleanup(EVP_CIPHER *cipher,
110 int (*cleanup) (EVP_CIPHER_CTX *))
112 cipher->cleanup = cleanup;
116 int EVP_CIPHER_meth_set_set_asn1_params(EVP_CIPHER *cipher,
117 int (*set_asn1_parameters) (EVP_CIPHER_CTX *,
120 cipher->set_asn1_parameters = set_asn1_parameters;
124 int EVP_CIPHER_meth_set_get_asn1_params(EVP_CIPHER *cipher,
125 int (*get_asn1_parameters) (EVP_CIPHER_CTX *,
128 cipher->get_asn1_parameters = get_asn1_parameters;
132 int EVP_CIPHER_meth_set_ctrl(EVP_CIPHER *cipher,
133 int (*ctrl) (EVP_CIPHER_CTX *, int type,
141 int (*EVP_CIPHER_meth_get_init(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *ctx,
142 const unsigned char *key,
143 const unsigned char *iv,
148 int (*EVP_CIPHER_meth_get_do_cipher(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *ctx,
150 const unsigned char *in,
153 return cipher->do_cipher;
156 int (*EVP_CIPHER_meth_get_cleanup(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *)
158 return cipher->cleanup;
161 int (*EVP_CIPHER_meth_get_set_asn1_params(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *,
164 return cipher->set_asn1_parameters;
167 int (*EVP_CIPHER_meth_get_get_asn1_params(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *,
170 return cipher->get_asn1_parameters;
173 int (*EVP_CIPHER_meth_get_ctrl(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *,