2 * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (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"
16 EVP_CIPHER *EVP_CIPHER_meth_new(int cipher_type, int block_size, int key_len)
18 EVP_CIPHER *cipher = OPENSSL_zalloc(sizeof(EVP_CIPHER));
21 cipher->nid = cipher_type;
22 cipher->block_size = block_size;
23 cipher->key_len = key_len;
28 EVP_CIPHER *EVP_CIPHER_meth_dup(const EVP_CIPHER *cipher)
30 EVP_CIPHER *to = EVP_CIPHER_meth_new(cipher->nid, cipher->block_size,
34 memcpy(to, cipher, sizeof(*to));
38 void EVP_CIPHER_meth_free(EVP_CIPHER *cipher)
43 int EVP_CIPHER_meth_set_iv_length(EVP_CIPHER *cipher, int iv_len)
45 cipher->iv_len = iv_len;
49 int EVP_CIPHER_meth_set_flags(EVP_CIPHER *cipher, unsigned long flags)
51 cipher->flags = flags;
55 int EVP_CIPHER_meth_set_impl_ctx_size(EVP_CIPHER *cipher, int ctx_size)
57 cipher->ctx_size = ctx_size;
61 int EVP_CIPHER_meth_set_init(EVP_CIPHER *cipher,
62 int (*init) (EVP_CIPHER_CTX *ctx,
63 const unsigned char *key,
64 const unsigned char *iv,
71 int EVP_CIPHER_meth_set_do_cipher(EVP_CIPHER *cipher,
72 int (*do_cipher) (EVP_CIPHER_CTX *ctx,
74 const unsigned char *in,
77 cipher->do_cipher = do_cipher;
81 int EVP_CIPHER_meth_set_cleanup(EVP_CIPHER *cipher,
82 int (*cleanup) (EVP_CIPHER_CTX *))
84 cipher->cleanup = cleanup;
88 int EVP_CIPHER_meth_set_set_asn1_params(EVP_CIPHER *cipher,
89 int (*set_asn1_parameters) (EVP_CIPHER_CTX *,
92 cipher->set_asn1_parameters = set_asn1_parameters;
96 int EVP_CIPHER_meth_set_get_asn1_params(EVP_CIPHER *cipher,
97 int (*get_asn1_parameters) (EVP_CIPHER_CTX *,
100 cipher->get_asn1_parameters = get_asn1_parameters;
104 int EVP_CIPHER_meth_set_ctrl(EVP_CIPHER *cipher,
105 int (*ctrl) (EVP_CIPHER_CTX *, int type,
113 int (*EVP_CIPHER_meth_get_init(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *ctx,
114 const unsigned char *key,
115 const unsigned char *iv,
120 int (*EVP_CIPHER_meth_get_do_cipher(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *ctx,
122 const unsigned char *in,
125 return cipher->do_cipher;
128 int (*EVP_CIPHER_meth_get_cleanup(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *)
130 return cipher->cleanup;
133 int (*EVP_CIPHER_meth_get_set_asn1_params(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *,
136 return cipher->set_asn1_parameters;
139 int (*EVP_CIPHER_meth_get_get_asn1_params(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *,
142 return cipher->get_asn1_parameters;
145 int (*EVP_CIPHER_meth_get_ctrl(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *,