]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/evp/cmeth_lib.c
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
= evp_cipher_new();
22 cipher
->nid
= cipher_type
;
23 cipher
->block_size
= block_size
;
24 cipher
->key_len
= key_len
;
29 EVP_CIPHER
*EVP_CIPHER_meth_dup(const EVP_CIPHER
*cipher
)
31 EVP_CIPHER
*to
= NULL
;
34 * Non-legacy EVP_CIPHERs can't be duplicated like this.
35 * Use EVP_CIPHER_up_ref() instead.
37 if (cipher
->prov
!= NULL
)
40 if ((to
= EVP_CIPHER_meth_new(cipher
->nid
, cipher
->block_size
,
41 cipher
->key_len
)) != NULL
) {
42 CRYPTO_RWLOCK
*lock
= to
->lock
;
44 memcpy(to
, cipher
, sizeof(*to
));
50 void EVP_CIPHER_meth_free(EVP_CIPHER
*cipher
)
52 EVP_CIPHER_free(cipher
);
55 int EVP_CIPHER_meth_set_iv_length(EVP_CIPHER
*cipher
, int iv_len
)
57 if (cipher
->iv_len
!= 0)
60 cipher
->iv_len
= iv_len
;
64 int EVP_CIPHER_meth_set_flags(EVP_CIPHER
*cipher
, unsigned long flags
)
66 if (cipher
->flags
!= 0)
69 cipher
->flags
= flags
;
73 int EVP_CIPHER_meth_set_impl_ctx_size(EVP_CIPHER
*cipher
, int ctx_size
)
75 if (cipher
->ctx_size
!= 0)
78 cipher
->ctx_size
= ctx_size
;
82 int EVP_CIPHER_meth_set_init(EVP_CIPHER
*cipher
,
83 int (*init
) (EVP_CIPHER_CTX
*ctx
,
84 const unsigned char *key
,
85 const unsigned char *iv
,
88 if (cipher
->init
!= NULL
)
95 int EVP_CIPHER_meth_set_do_cipher(EVP_CIPHER
*cipher
,
96 int (*do_cipher
) (EVP_CIPHER_CTX
*ctx
,
98 const unsigned char *in
,
101 if (cipher
->do_cipher
!= NULL
)
104 cipher
->do_cipher
= do_cipher
;
108 int EVP_CIPHER_meth_set_cleanup(EVP_CIPHER
*cipher
,
109 int (*cleanup
) (EVP_CIPHER_CTX
*))
111 if (cipher
->cleanup
!= NULL
)
114 cipher
->cleanup
= cleanup
;
118 int EVP_CIPHER_meth_set_set_asn1_params(EVP_CIPHER
*cipher
,
119 int (*set_asn1_parameters
) (EVP_CIPHER_CTX
*,
122 if (cipher
->set_asn1_parameters
!= NULL
)
125 cipher
->set_asn1_parameters
= set_asn1_parameters
;
129 int EVP_CIPHER_meth_set_get_asn1_params(EVP_CIPHER
*cipher
,
130 int (*get_asn1_parameters
) (EVP_CIPHER_CTX
*,
133 if (cipher
->get_asn1_parameters
!= NULL
)
136 cipher
->get_asn1_parameters
= get_asn1_parameters
;
140 int EVP_CIPHER_meth_set_ctrl(EVP_CIPHER
*cipher
,
141 int (*ctrl
) (EVP_CIPHER_CTX
*, int type
,
144 if (cipher
->ctrl
!= NULL
)
152 int (*EVP_CIPHER_meth_get_init(const EVP_CIPHER
*cipher
))(EVP_CIPHER_CTX
*ctx
,
153 const unsigned char *key
,
154 const unsigned char *iv
,
159 int (*EVP_CIPHER_meth_get_do_cipher(const EVP_CIPHER
*cipher
))(EVP_CIPHER_CTX
*ctx
,
161 const unsigned char *in
,
164 return cipher
->do_cipher
;
167 int (*EVP_CIPHER_meth_get_cleanup(const EVP_CIPHER
*cipher
))(EVP_CIPHER_CTX
*)
169 return cipher
->cleanup
;
172 int (*EVP_CIPHER_meth_get_set_asn1_params(const EVP_CIPHER
*cipher
))(EVP_CIPHER_CTX
*,
175 return cipher
->set_asn1_parameters
;
178 int (*EVP_CIPHER_meth_get_get_asn1_params(const EVP_CIPHER
*cipher
))(EVP_CIPHER_CTX
*,
181 return cipher
->get_asn1_parameters
;
184 int (*EVP_CIPHER_meth_get_ctrl(const EVP_CIPHER
*cipher
))(EVP_CIPHER_CTX
*,