summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2023-03-01 11:25:25 +0000
committertb <>2023-03-01 11:25:25 +0000
commit2ab231c6d07c8d22decb8b5154666eae3be871d1 (patch)
treed9598d7e7f5ab5de3bfec81a576de8beaf5ff1c9 /src/lib
parente13b694c80b3c7e2586b51415ad087acb44373d9 (diff)
downloadopenbsd-2ab231c6d07c8d22decb8b5154666eae3be871d1.tar.gz
openbsd-2ab231c6d07c8d22decb8b5154666eae3be871d1.tar.bz2
openbsd-2ab231c6d07c8d22decb8b5154666eae3be871d1.zip
Make cipher_method_lib.c compile with LibreSSL
OPENSSL_zalloc() -> calloc(), OPENSSL_free() -> free() and a few assorted cosmetic tweaks to match our style better. ok jsing
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/evp/cipher_method_lib.c44
1 files changed, 29 insertions, 15 deletions
diff --git a/src/lib/libcrypto/evp/cipher_method_lib.c b/src/lib/libcrypto/evp/cipher_method_lib.c
index a0b2830efa..dc37050408 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.6 2023/03/01 11:08:37 tb Exp $ */ 1/* $OpenBSD: cipher_method_lib.c,v 1.7 2023/03/01 11:25: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.
@@ -57,46 +57,52 @@
57 * 57 *
58 */ 58 */
59 59
60#include <string.h> 60#include <stdlib.h>
61 61
62#include <openssl/evp.h> 62#include <openssl/evp.h>
63#include "crypto/evp.h" 63
64#include "evp_local.h" 64#include "evp_local.h"
65 65
66EVP_CIPHER * 66EVP_CIPHER *
67EVP_CIPHER_meth_new(int cipher_type, int block_size, int key_len) 67EVP_CIPHER_meth_new(int cipher_type, int block_size, int key_len)
68{ 68{
69 EVP_CIPHER *cipher = OPENSSL_zalloc(sizeof(EVP_CIPHER)); 69 EVP_CIPHER *cipher;
70
71 if ((cipher = calloc(1, sizeof(*cipher))) == NULL)
72 return NULL;
73
74 cipher->nid = cipher_type;
75 cipher->block_size = block_size;
76 cipher->key_len = key_len;
70 77
71 if (cipher != NULL) {
72 cipher->nid = cipher_type;
73 cipher->block_size = block_size;
74 cipher->key_len = key_len;
75 }
76 return cipher; 78 return cipher;
77} 79}
78 80
79EVP_CIPHER * 81EVP_CIPHER *
80EVP_CIPHER_meth_dup(const EVP_CIPHER *cipher) 82EVP_CIPHER_meth_dup(const EVP_CIPHER *cipher)
81{ 83{
82 EVP_CIPHER *to = EVP_CIPHER_meth_new(cipher->nid, cipher->block_size, 84 EVP_CIPHER *copy;
83 cipher->key_len); 85
86 if ((copy = EVP_CIPHER_meth_new(cipher->nid, cipher->block_size,
87 cipher->key_len)) == NULL)
88 return NULL;
84 89
85 if (to != NULL) 90 *copy = *cipher;
86 memcpy(to, cipher, sizeof(*to)); 91
87 return to; 92 return copy;
88} 93}
89 94
90void 95void
91EVP_CIPHER_meth_free(EVP_CIPHER *cipher) 96EVP_CIPHER_meth_free(EVP_CIPHER *cipher)
92{ 97{
93 OPENSSL_free(cipher); 98 free(cipher);
94} 99}
95 100
96int 101int
97EVP_CIPHER_meth_set_iv_length(EVP_CIPHER *cipher, int iv_len) 102EVP_CIPHER_meth_set_iv_length(EVP_CIPHER *cipher, int iv_len)
98{ 103{
99 cipher->iv_len = iv_len; 104 cipher->iv_len = iv_len;
105
100 return 1; 106 return 1;
101} 107}
102 108
@@ -104,6 +110,7 @@ int
104EVP_CIPHER_meth_set_flags(EVP_CIPHER *cipher, unsigned long flags) 110EVP_CIPHER_meth_set_flags(EVP_CIPHER *cipher, unsigned long flags)
105{ 111{
106 cipher->flags = flags; 112 cipher->flags = flags;
113
107 return 1; 114 return 1;
108} 115}
109 116
@@ -111,6 +118,7 @@ int
111EVP_CIPHER_meth_set_impl_ctx_size(EVP_CIPHER *cipher, int ctx_size) 118EVP_CIPHER_meth_set_impl_ctx_size(EVP_CIPHER *cipher, int ctx_size)
112{ 119{
113 cipher->ctx_size = ctx_size; 120 cipher->ctx_size = ctx_size;
121
114 return 1; 122 return 1;
115} 123}
116 124
@@ -120,6 +128,7 @@ EVP_CIPHER_meth_set_init(EVP_CIPHER *cipher,
120 const unsigned char *iv, int enc)) 128 const unsigned char *iv, int enc))
121{ 129{
122 cipher->init = init; 130 cipher->init = init;
131
123 return 1; 132 return 1;
124} 133}
125 134
@@ -129,6 +138,7 @@ EVP_CIPHER_meth_set_do_cipher(EVP_CIPHER *cipher,
129 const unsigned char *in, size_t inl)) 138 const unsigned char *in, size_t inl))
130{ 139{
131 cipher->do_cipher = do_cipher; 140 cipher->do_cipher = do_cipher;
141
132 return 1; 142 return 1;
133} 143}
134 144
@@ -137,6 +147,7 @@ EVP_CIPHER_meth_set_cleanup(EVP_CIPHER *cipher,
137 int (*cleanup)(EVP_CIPHER_CTX *)) 147 int (*cleanup)(EVP_CIPHER_CTX *))
138{ 148{
139 cipher->cleanup = cleanup; 149 cipher->cleanup = cleanup;
150
140 return 1; 151 return 1;
141} 152}
142 153
@@ -145,6 +156,7 @@ EVP_CIPHER_meth_set_set_asn1_params(EVP_CIPHER *cipher,
145 int (*set_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *)) 156 int (*set_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *))
146{ 157{
147 cipher->set_asn1_parameters = set_asn1_parameters; 158 cipher->set_asn1_parameters = set_asn1_parameters;
159
148 return 1; 160 return 1;
149} 161}
150 162
@@ -153,6 +165,7 @@ EVP_CIPHER_meth_set_get_asn1_params(EVP_CIPHER *cipher,
153 int (*get_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *)) 165 int (*get_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *))
154{ 166{
155 cipher->get_asn1_parameters = get_asn1_parameters; 167 cipher->get_asn1_parameters = get_asn1_parameters;
168
156 return 1; 169 return 1;
157} 170}
158 171
@@ -161,5 +174,6 @@ EVP_CIPHER_meth_set_ctrl(EVP_CIPHER *cipher,
161 int (*ctrl)(EVP_CIPHER_CTX *, int type, int arg, void *ptr)) 174 int (*ctrl)(EVP_CIPHER_CTX *, int type, int arg, void *ptr))
162{ 175{
163 cipher->ctrl = ctrl; 176 cipher->ctrl = ctrl;
177
164 return 1; 178 return 1;
165} 179}