]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/evp/cmeth_lib.c
2 * Copyright 2015-2020 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
));
57 void EVP_CIPHER_meth_free(EVP_CIPHER
*cipher
)
59 if (cipher
== NULL
|| cipher
->origin
!= EVP_ORIG_METH
)
62 evp_cipher_free_int(cipher
);
65 int EVP_CIPHER_meth_set_iv_length(EVP_CIPHER
*cipher
, int iv_len
)
67 if (cipher
->iv_len
!= 0)
70 cipher
->iv_len
= iv_len
;
74 int EVP_CIPHER_meth_set_flags(EVP_CIPHER
*cipher
, unsigned long flags
)
76 if (cipher
->flags
!= 0)
79 cipher
->flags
= flags
;
83 int EVP_CIPHER_meth_set_impl_ctx_size(EVP_CIPHER
*cipher
, int ctx_size
)
85 if (cipher
->ctx_size
!= 0)
88 cipher
->ctx_size
= ctx_size
;
92 int EVP_CIPHER_meth_set_init(EVP_CIPHER
*cipher
,
93 int (*init
) (EVP_CIPHER_CTX
*ctx
,
94 const unsigned char *key
,
95 const unsigned char *iv
,
98 if (cipher
->init
!= NULL
)
105 int EVP_CIPHER_meth_set_do_cipher(EVP_CIPHER
*cipher
,
106 int (*do_cipher
) (EVP_CIPHER_CTX
*ctx
,
108 const unsigned char *in
,
111 if (cipher
->do_cipher
!= NULL
)
114 cipher
->do_cipher
= do_cipher
;
118 int EVP_CIPHER_meth_set_cleanup(EVP_CIPHER
*cipher
,
119 int (*cleanup
) (EVP_CIPHER_CTX
*))
121 if (cipher
->cleanup
!= NULL
)
124 cipher
->cleanup
= cleanup
;
128 int EVP_CIPHER_meth_set_set_asn1_params(EVP_CIPHER
*cipher
,
129 int (*set_asn1_parameters
) (EVP_CIPHER_CTX
*,
132 if (cipher
->set_asn1_parameters
!= NULL
)
135 cipher
->set_asn1_parameters
= set_asn1_parameters
;
139 int EVP_CIPHER_meth_set_get_asn1_params(EVP_CIPHER
*cipher
,
140 int (*get_asn1_parameters
) (EVP_CIPHER_CTX
*,
143 if (cipher
->get_asn1_parameters
!= NULL
)
146 cipher
->get_asn1_parameters
= get_asn1_parameters
;
150 int EVP_CIPHER_meth_set_ctrl(EVP_CIPHER
*cipher
,
151 int (*ctrl
) (EVP_CIPHER_CTX
*, int type
,
154 if (cipher
->ctrl
!= NULL
)
162 int (*EVP_CIPHER_meth_get_init(const EVP_CIPHER
*cipher
))(EVP_CIPHER_CTX
*ctx
,
163 const unsigned char *key
,
164 const unsigned char *iv
,
169 int (*EVP_CIPHER_meth_get_do_cipher(const EVP_CIPHER
*cipher
))(EVP_CIPHER_CTX
*ctx
,
171 const unsigned char *in
,
174 return cipher
->do_cipher
;
177 int (*EVP_CIPHER_meth_get_cleanup(const EVP_CIPHER
*cipher
))(EVP_CIPHER_CTX
*)
179 return cipher
->cleanup
;
182 int (*EVP_CIPHER_meth_get_set_asn1_params(const EVP_CIPHER
*cipher
))(EVP_CIPHER_CTX
*,
185 return cipher
->set_asn1_parameters
;
188 int (*EVP_CIPHER_meth_get_get_asn1_params(const EVP_CIPHER
*cipher
))(EVP_CIPHER_CTX
*,
191 return cipher
->get_asn1_parameters
;
194 int (*EVP_CIPHER_meth_get_ctrl(const EVP_CIPHER
*cipher
))(EVP_CIPHER_CTX
*,