/src/openssl/crypto/evp/cmeth_lib.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
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 |
8 | | */ |
9 | | |
10 | | #include <string.h> |
11 | | |
12 | | #include <openssl/evp.h> |
13 | | #include "internal/evp_int.h" |
14 | | #include "evp_locl.h" |
15 | | |
16 | | EVP_CIPHER *EVP_CIPHER_meth_new(int cipher_type, int block_size, int key_len) |
17 | 0 | { |
18 | 0 | EVP_CIPHER *cipher = OPENSSL_zalloc(sizeof(EVP_CIPHER)); |
19 | 0 |
|
20 | 0 | if (cipher != NULL) { |
21 | 0 | cipher->nid = cipher_type; |
22 | 0 | cipher->block_size = block_size; |
23 | 0 | cipher->key_len = key_len; |
24 | 0 | } |
25 | 0 | return cipher; |
26 | 0 | } |
27 | | |
28 | | EVP_CIPHER *EVP_CIPHER_meth_dup(const EVP_CIPHER *cipher) |
29 | 0 | { |
30 | 0 | EVP_CIPHER *to = EVP_CIPHER_meth_new(cipher->nid, cipher->block_size, |
31 | 0 | cipher->key_len); |
32 | 0 |
|
33 | 0 | if (to != NULL) |
34 | 0 | memcpy(to, cipher, sizeof(*to)); |
35 | 0 | return to; |
36 | 0 | } |
37 | | |
38 | | void EVP_CIPHER_meth_free(EVP_CIPHER *cipher) |
39 | 0 | { |
40 | 0 | OPENSSL_free(cipher); |
41 | 0 | } |
42 | | |
43 | | int EVP_CIPHER_meth_set_iv_length(EVP_CIPHER *cipher, int iv_len) |
44 | 0 | { |
45 | 0 | cipher->iv_len = iv_len; |
46 | 0 | return 1; |
47 | 0 | } |
48 | | |
49 | | int EVP_CIPHER_meth_set_flags(EVP_CIPHER *cipher, unsigned long flags) |
50 | 0 | { |
51 | 0 | cipher->flags = flags; |
52 | 0 | return 1; |
53 | 0 | } |
54 | | |
55 | | int EVP_CIPHER_meth_set_impl_ctx_size(EVP_CIPHER *cipher, int ctx_size) |
56 | 0 | { |
57 | 0 | cipher->ctx_size = ctx_size; |
58 | 0 | return 1; |
59 | 0 | } |
60 | | |
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, |
65 | | int enc)) |
66 | 0 | { |
67 | 0 | cipher->init = init; |
68 | 0 | return 1; |
69 | 0 | } |
70 | | |
71 | | int EVP_CIPHER_meth_set_do_cipher(EVP_CIPHER *cipher, |
72 | | int (*do_cipher) (EVP_CIPHER_CTX *ctx, |
73 | | unsigned char *out, |
74 | | const unsigned char *in, |
75 | | size_t inl)) |
76 | 0 | { |
77 | 0 | cipher->do_cipher = do_cipher; |
78 | 0 | return 1; |
79 | 0 | } |
80 | | |
81 | | int EVP_CIPHER_meth_set_cleanup(EVP_CIPHER *cipher, |
82 | | int (*cleanup) (EVP_CIPHER_CTX *)) |
83 | 0 | { |
84 | 0 | cipher->cleanup = cleanup; |
85 | 0 | return 1; |
86 | 0 | } |
87 | | |
88 | | int EVP_CIPHER_meth_set_set_asn1_params(EVP_CIPHER *cipher, |
89 | | int (*set_asn1_parameters) (EVP_CIPHER_CTX *, |
90 | | ASN1_TYPE *)) |
91 | 0 | { |
92 | 0 | cipher->set_asn1_parameters = set_asn1_parameters; |
93 | 0 | return 1; |
94 | 0 | } |
95 | | |
96 | | int EVP_CIPHER_meth_set_get_asn1_params(EVP_CIPHER *cipher, |
97 | | int (*get_asn1_parameters) (EVP_CIPHER_CTX *, |
98 | | ASN1_TYPE *)) |
99 | 0 | { |
100 | 0 | cipher->get_asn1_parameters = get_asn1_parameters; |
101 | 0 | return 1; |
102 | 0 | } |
103 | | |
104 | | int EVP_CIPHER_meth_set_ctrl(EVP_CIPHER *cipher, |
105 | | int (*ctrl) (EVP_CIPHER_CTX *, int type, |
106 | | int arg, void *ptr)) |
107 | 0 | { |
108 | 0 | cipher->ctrl = ctrl; |
109 | 0 | return 1; |
110 | 0 | } |
111 | | |
112 | | |
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, |
116 | | int enc) |
117 | 0 | { |
118 | 0 | return cipher->init; |
119 | 0 | } |
120 | | int (*EVP_CIPHER_meth_get_do_cipher(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *ctx, |
121 | | unsigned char *out, |
122 | | const unsigned char *in, |
123 | | size_t inl) |
124 | 0 | { |
125 | 0 | return cipher->do_cipher; |
126 | 0 | } |
127 | | |
128 | | int (*EVP_CIPHER_meth_get_cleanup(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *) |
129 | 0 | { |
130 | 0 | return cipher->cleanup; |
131 | 0 | } |
132 | | |
133 | | int (*EVP_CIPHER_meth_get_set_asn1_params(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *, |
134 | | ASN1_TYPE *) |
135 | 0 | { |
136 | 0 | return cipher->set_asn1_parameters; |
137 | 0 | } |
138 | | |
139 | | int (*EVP_CIPHER_meth_get_get_asn1_params(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *, |
140 | | ASN1_TYPE *) |
141 | 0 | { |
142 | 0 | return cipher->get_asn1_parameters; |
143 | 0 | } |
144 | | |
145 | | int (*EVP_CIPHER_meth_get_ctrl(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *, |
146 | | int type, int arg, |
147 | | void *ptr) |
148 | 0 | { |
149 | 0 | return cipher->ctrl; |
150 | 0 | } |
151 | | |