summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libcrypto/evp/cipher_method_lib.c132
1 files changed, 72 insertions, 60 deletions
diff --git a/src/lib/libcrypto/evp/cipher_method_lib.c b/src/lib/libcrypto/evp/cipher_method_lib.c
index eaf8ceda8e..760e0e8557 100644
--- a/src/lib/libcrypto/evp/cipher_method_lib.c
+++ b/src/lib/libcrypto/evp/cipher_method_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cipher_method_lib.c,v 1.4 2023/03/01 11:06:23 tb Exp $ */ 1/* $OpenBSD: cipher_method_lib.c,v 1.5 2023/03/01 11:07:25 tb Exp $ */
2/* 2/*
3 * Written by Richard Levitte (levitte@openssl.org) for the OpenSSL project 3 * Written by Richard Levitte (levitte@openssl.org) for the OpenSSL project
4 * 2015. 4 * 2015.
@@ -63,98 +63,110 @@
63#include "crypto/evp.h" 63#include "crypto/evp.h"
64#include "evp_local.h" 64#include "evp_local.h"
65 65
66EVP_CIPHER *EVP_CIPHER_meth_new(int cipher_type, int block_size, int key_len) 66EVP_CIPHER *
67EVP_CIPHER_meth_new(int cipher_type, int block_size, int key_len)
67{ 68{
68 EVP_CIPHER *cipher = OPENSSL_zalloc(sizeof(EVP_CIPHER)); 69 EVP_CIPHER *cipher = OPENSSL_zalloc(sizeof(EVP_CIPHER));
69 70
70 if (cipher != NULL) { 71 if (cipher != NULL) {
71 cipher->nid = cipher_type; 72 cipher->nid = cipher_type;
72 cipher->block_size = block_size; 73 cipher->block_size = block_size;
73 cipher->key_len = key_len; 74 cipher->key_len = key_len;
74 } 75 }
75 return cipher; 76 return cipher;
76} 77}
77 78
78EVP_CIPHER *EVP_CIPHER_meth_dup(const EVP_CIPHER *cipher) 79EVP_CIPHER *
80EVP_CIPHER_meth_dup(const EVP_CIPHER *cipher)
79{ 81{
80 EVP_CIPHER *to = EVP_CIPHER_meth_new(cipher->nid, cipher->block_size, 82 EVP_CIPHER *to = EVP_CIPHER_meth_new(cipher->nid, cipher->block_size,
81 cipher->key_len); 83 cipher->key_len);
82 84
83 if (to != NULL) 85 if (to != NULL)
84 memcpy(to, cipher, sizeof(*to)); 86 memcpy(to, cipher, sizeof(*to));
85 return to; 87 return to;
86} 88}
87 89
88void EVP_CIPHER_meth_free(EVP_CIPHER *cipher) 90void
91EVP_CIPHER_meth_free(EVP_CIPHER *cipher)
89{ 92{
90 OPENSSL_free(cipher); 93 OPENSSL_free(cipher);
91} 94}
92 95
93int EVP_CIPHER_meth_set_iv_length(EVP_CIPHER *cipher, int iv_len) 96int
97EVP_CIPHER_meth_set_iv_length(EVP_CIPHER *cipher, int iv_len)
94{ 98{
95 cipher->iv_len = iv_len; 99 cipher->iv_len = iv_len;
96 return 1; 100 return 1;
97} 101}
98 102
99int EVP_CIPHER_meth_set_flags(EVP_CIPHER *cipher, unsigned long flags) 103int
104EVP_CIPHER_meth_set_flags(EVP_CIPHER *cipher, unsigned long flags)
100{ 105{
101 cipher->flags = flags; 106 cipher->flags = flags;
102 return 1; 107 return 1;
103} 108}
104 109
105int EVP_CIPHER_meth_set_impl_ctx_size(EVP_CIPHER *cipher, int ctx_size) 110int
111EVP_CIPHER_meth_set_impl_ctx_size(EVP_CIPHER *cipher, int ctx_size)
106{ 112{
107 cipher->ctx_size = ctx_size; 113 cipher->ctx_size = ctx_size;
108 return 1; 114 return 1;
109} 115}
110 116
111int EVP_CIPHER_meth_set_init(EVP_CIPHER *cipher, 117int
112 int (*init) (EVP_CIPHER_CTX *ctx, 118EVP_CIPHER_meth_set_init(EVP_CIPHER *cipher,
113 const unsigned char *key, 119 int (*init)(EVP_CIPHER_CTX *ctx,
114 const unsigned char *iv, 120 const unsigned char *key,
115 int enc)) 121 const unsigned char *iv,
122 int enc))
116{ 123{
117 cipher->init = init; 124 cipher->init = init;
118 return 1; 125 return 1;
119} 126}
120 127
121int EVP_CIPHER_meth_set_do_cipher(EVP_CIPHER *cipher, 128int
122 int (*do_cipher) (EVP_CIPHER_CTX *ctx, 129EVP_CIPHER_meth_set_do_cipher(EVP_CIPHER *cipher,
123 unsigned char *out, 130 int (*do_cipher)(EVP_CIPHER_CTX *ctx,
124 const unsigned char *in, 131 unsigned char *out,
125 size_t inl)) 132 const unsigned char *in,
133 size_t inl))
126{ 134{
127 cipher->do_cipher = do_cipher; 135 cipher->do_cipher = do_cipher;
128 return 1; 136 return 1;
129} 137}
130 138
131int EVP_CIPHER_meth_set_cleanup(EVP_CIPHER *cipher, 139int
132 int (*cleanup) (EVP_CIPHER_CTX *)) 140EVP_CIPHER_meth_set_cleanup(EVP_CIPHER *cipher,
141 int (*cleanup)(EVP_CIPHER_CTX *))
133{ 142{
134 cipher->cleanup = cleanup; 143 cipher->cleanup = cleanup;
135 return 1; 144 return 1;
136} 145}
137 146
138int EVP_CIPHER_meth_set_set_asn1_params(EVP_CIPHER *cipher, 147int
139 int (*set_asn1_parameters) (EVP_CIPHER_CTX *, 148EVP_CIPHER_meth_set_set_asn1_params(EVP_CIPHER *cipher,
140 ASN1_TYPE *)) 149 int (*set_asn1_parameters)(EVP_CIPHER_CTX *,
150 ASN1_TYPE *))
141{ 151{
142 cipher->set_asn1_parameters = set_asn1_parameters; 152 cipher->set_asn1_parameters = set_asn1_parameters;
143 return 1; 153 return 1;
144} 154}
145 155
146int EVP_CIPHER_meth_set_get_asn1_params(EVP_CIPHER *cipher, 156int
147 int (*get_asn1_parameters) (EVP_CIPHER_CTX *, 157EVP_CIPHER_meth_set_get_asn1_params(EVP_CIPHER *cipher,
148 ASN1_TYPE *)) 158 int (*get_asn1_parameters)(EVP_CIPHER_CTX *,
159 ASN1_TYPE *))
149{ 160{
150 cipher->get_asn1_parameters = get_asn1_parameters; 161 cipher->get_asn1_parameters = get_asn1_parameters;
151 return 1; 162 return 1;
152} 163}
153 164
154int EVP_CIPHER_meth_set_ctrl(EVP_CIPHER *cipher, 165int
155 int (*ctrl) (EVP_CIPHER_CTX *, int type, 166EVP_CIPHER_meth_set_ctrl(EVP_CIPHER *cipher,
156 int arg, void *ptr)) 167 int (*ctrl)(EVP_CIPHER_CTX *, int type,
168 int arg, void *ptr))
157{ 169{
158 cipher->ctrl = ctrl; 170 cipher->ctrl = ctrl;
159 return 1; 171 return 1;
160} 172}