Debian Codegraph @

lib/kcapi-kernel-if.c

raw symbols SCIP
1 /* Kernel crypto API AF_ALG interface code
2 *
3 * Copyright (C) 2015 - 2022, Stephan Mueller <[email protected]>
4 *
5 * License: see COPYING file in root directory
6 *
7 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
8 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
9 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
10 * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
11 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
12 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
13 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
14 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
15 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
16 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
17 * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
18 * DAMAGE.
19 */
20
21 #define _GNU_SOURCEcxx . . $ `lib/kcapi-kernel-if.c:21:9`!
22 #include <stdarg.h>
23 #include <unistd.h>
24 #include <asm/types.h>
25 #include <linux/netlink.h>
26 #include <linux/rtnetlink.h>
27 #include <unistd.h>
28 #include <sys/user.h>
29 #include <sys/eventfd.h>
30 #include <time.h>
31 #include <sys/select.h>
32 #include <sys/utsname.h>
33 #include <sys/prctl.h>
34
35 #include "cryptouser.h"cxx . . $ `<file>/lib/cryptouser.h`/
36 #include "kcapi.h"cxx . . $ `<file>/lib/kcapi.h`/
37 #include "internal.h"cxx . . $ `<file>/lib/internal.h`/
38
39 /************************************************************
40 * Common helper used within the lib and as an API
41 ************************************************************/
42 IMPL_SYMVERcxx . . $ `lib/internal.h:363:10`!(memset_secure, "1.3.1")
43 void impl_memset_securecxx . . $ impl_memset_secure(e37d57925061d5c9).(void *s, int c, size_t n)
44 {
45 memsetcxx . . $ memset(d1de1e4fb215f1c6).(s, c, n);
46 __asm__ __volatile__("" : : "r" (s) : "memory");
47 }
48
49 ORIG_SYMVERcxx . . $ `lib/internal.h:366:10`!(memset_secure, "0.12.0")
50 void orig_memset_securecxx . . $ orig_memset_secure(8f31ca71a920a70f).(void *s, int c, uint32_tcxx . . $ uint32_t# n)
51 {
52 impl_memset_securecxx . . $ impl_memset_secure(e37d57925061d5c9).(s, c, n);
53 }
54
55 /************************************************************
56 * Logging logic
57 ************************************************************/
58 enum kcapi_verbositycxx . . $ kcapi_verbosity# kcapi_verbosity_levelcxx . . $ kcapi_verbosity_level. = KCAPI_LOG_ERRcxx . . $ KCAPI_LOG_ERR.;
59
60 void kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(enum kcapi_verbositycxx . . $ kcapi_verbosity# severity, const char *fmt, ...)
61 {
62 va_listcxx . . $ va_list# args;
63 char msg[128];
64 char sev[16];
65
66 if (severity > kcapi_verbosity_levelcxx . . $ kcapi_verbosity_level.)
67 return;
68
69 memsetcxx . . $ memset(d1de1e4fb215f1c6).(sev, 0, sizeof(sev));
70 memsetcxx . . $ memset(d1de1e4fb215f1c6).(msg, 0, sizeof(msg));
71
72 va_startcxx . . $ `<external>/8105065126723003039/stdarg.h:50:9`!(args, fmt);
73 vsnprintfcxx . . $ vsnprintf(a85eea89d1bd834f).(msg, sizeof(msg) - 1, fmt, args);
74 va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(args);
75
76 switch (severity) {
77 case KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG.:
78 snprintfcxx . . $ snprintf(ea502d73e74c754c).(sev, sizeof(sev), "Debug");
79 break;
80 case KCAPI_LOG_VERBOSEcxx . . $ KCAPI_LOG_VERBOSE.:
81 snprintfcxx . . $ snprintf(ea502d73e74c754c).(sev, sizeof(sev), "Verbose");
82 break;
83 case KCAPI_LOG_WARNcxx . . $ KCAPI_LOG_WARN.:
84 snprintfcxx . . $ snprintf(ea502d73e74c754c).(sev, sizeof(sev), "Warning");
85 break;
86 case KCAPI_LOG_ERRcxx . . $ KCAPI_LOG_ERR.:
87 snprintfcxx . . $ snprintf(ea502d73e74c754c).(sev, sizeof(sev), "Error");
88 break;
89 default:
90 snprintfcxx . . $ snprintf(ea502d73e74c754c).(sev, sizeof(sev), "Unknown");
91 }
92 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "libkcapi - %s: %s\n", sev, msg);
93 }
94
95 /************************************************************
96 * Internal logic
97 ************************************************************/
98
99 int _kcapi_common_acceptcxx . . $ _kcapi_common_accept(cad780c06c088da8).(struct kcapi_handlecxx . . $ kcapi_handle# *handle)
100 {
101 struct kcapi_handle_tfmcxx . . $ kcapi_handle_tfm# *tfm = handle->tfmcxx . . $ kcapi_handle#tfm.;
102 int fd;
103
104 if (*_kcapi_get_opfdcxx . . $ _kcapi_get_opfd(f39930546eae134b).(handle) != -1)
105 return 0;
106
107 fd = acceptcxx . . $ accept(ff9054838cdf4227).(tfm->tfmfdcxx . . $ kcapi_handle_tfm#tfmfd., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0);
108 if (fd == -1) {
109 int errsv;
110
111 errsv = errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
112 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_ERRcxx . . $ KCAPI_LOG_ERR., "AF_ALG: accept failed");
113 return -errsv;
114 }
115 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG., "AF_ALG: accept syscall successful");
116
117 *_kcapi_get_opfdcxx . . $ _kcapi_get_opfd(f39930546eae134b).(handle) = fd;
118
119 return 0;
120 }
121
122 #ifdef __GLIBC__cxx . . $ `<external>/18206667465210621810/features.h:514:9`!
123 static inline size_t kcapi_downcast_intcxx . . $ kcapi_downcast_int(ecdaa1632f49f591).(size_t in)
124 {
125 return in;
126 }
127
128 static inline size_t kcapi_downcast_socklen_tcxx . . $ kcapi_downcast_socklen_t(ecdaa1632f49f591).(size_t in)
129 {
130 return in;
131 }
132 #else
133 static inline int kcapi_downcast_int(size_t in)
134 {
135 if (in > INT_MAX)
136 return INT_MAX;
137 return (int)in;
138 }
139
140 static inline socklen_t kcapi_downcast_socklen_t(size_t in)
141 {
142 return (socklen_t)in;
143 }
144 #endif
145
146 ssize_tcxx . . $ ssize_t# _kcapi_common_send_metacxx . . $ _kcapi_common_send_meta(f4e40828a4f4c91f).(struct kcapi_handlecxx . . $ kcapi_handle# *handle,
147 struct ioveccxx . . $ iovec# *iov, size_t iovlen,
148 unsigned int enc, uint32_tcxx . . $ uint32_t# flags)
149 {
150 struct kcapi_handle_tfmcxx . . $ kcapi_handle_tfm# *tfm = handle->tfmcxx . . $ kcapi_handle#tfm.;
151 ssize_tcxx . . $ ssize_t# ret;
152 char buffer_static[80] = { 0 };
153 char *buffer_p = buffer_static;
154 char *buffer_alloc = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
155
156 /* plaintext / ciphertext data */
157 struct cmsghdrcxx . . $ cmsghdr# *header = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
158 uint32_tcxx . . $ uint32_t# *type = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
159 struct msghdrcxx . . $ msghdr# msg;
160
161 /* IV data */
162 struct af_alg_ivcxx . . $ af_alg_iv# *alg_iv = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
163 size_t iv_msg_size = handle->ciphercxx . . $ kcapi_handle#cipher..ivcxx . . $ kcapi_cipher_data#iv. ?
164 CMSG_SPACEcxx . . $ `<external>/8962547315054503424/socket.h:309:9`!(sizeof(*alg_iv) + tfm->info.ivsize) :
165 0;
166
167 /* AEAD data */
168 uint32_tcxx . . $ uint32_t# *assoclen = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
169 size_t assoc_msg_size = handle->aeadcxx . . $ kcapi_handle#aead..assoclencxx . . $ kcapi_aead_data#assoclen. ?
170 CMSG_SPACEcxx . . $ `<external>/8962547315054503424/socket.h:309:9`!(sizeof(*assoclen)) : 0;
171
172 size_t bufferlen =
173 CMSG_SPACEcxx . . $ `<external>/8962547315054503424/socket.h:309:9`!(sizeof(*type)) + /* Encryption / Decryption */
174 iv_msg_size + /* IV */
175 assoc_msg_size; /* AEAD associated data size */
176
177 ret = _kcapi_common_acceptcxx . . $ _kcapi_common_accept(cad780c06c088da8).(handle);
178 if (ret)
179 return ret;
180
181 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&msg, 0, sizeof(msg));
182
183 /* allocate buffer, if static buffer is too small */
184 if (bufferlen > sizeof(buffer_static)) {
185 buffer_alloc = calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, bufferlen);
186 if (!buffer_alloc)
187 return -ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!;
188 buffer_p = buffer_alloc;
189 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_VERBOSEcxx . . $ KCAPI_LOG_VERBOSE.,
190 "_kcapi_common_send_meta_fd: submission buffer of size %zu allocated",
191 bufferlen);
192 }
193
194 msg.msg_controlcxx . . $ msghdr#msg_control. = buffer_p;
195 msg.msg_iovcxx . . $ msghdr#msg_iov. = iov;
196 msg.msg_iovlencxx . . $ msghdr#msg_iovlen. = kcapi_downcast_intcxx . . $ kcapi_downcast_int(ecdaa1632f49f591).(iovlen);
197 msg.msg_controllencxx . . $ msghdr#msg_controllen. = kcapi_downcast_socklen_tcxx . . $ kcapi_downcast_socklen_t(ecdaa1632f49f591).(bufferlen);
198 /* encrypt/decrypt operation */
199 header = CMSG_FIRSTHDRcxx . . $ `<external>/8962547315054503424/socket.h:304:9`!(&msg);
200 if (!header) {
201 ret = -EFAULTcxx . . $ `<external>/8987895939074593727/errno-base.h:18:9`!;
202 goto out;
203 }
204 header->cmsg_levelcxx . . $ cmsghdr#cmsg_level. = SOL_ALGcxx . . $ `<external>/8962547315054503424/socket.h:167:9`!;
205 header->cmsg_typecxx . . $ cmsghdr#cmsg_type. = ALG_SET_OPcxx . . $ `<external>/7256700519741588701/if_alg.h:51:9`!;
206 header->cmsg_lencxx . . $ cmsghdr#cmsg_len. = CMSG_LENcxx . . $ `<external>/8962547315054503424/socket.h:311:9`!(sizeof(*type));
207 type = (void*)CMSG_DATAcxx . . $ `<external>/8962547315054503424/socket.h:299:10`!(header);
208 *type = enc;
209
210 /* set IV */
211 if (handle->ciphercxx . . $ kcapi_handle#cipher..ivcxx . . $ kcapi_cipher_data#iv.) {
212 header = CMSG_NXTHDRcxx . . $ `<external>/8962547315054503424/socket.h:303:9`!(&msg, header);
213 if (!header) {
214 ret = -EFAULTcxx . . $ `<external>/8987895939074593727/errno-base.h:18:9`!;
215 goto out;
216 }
217 header->cmsg_levelcxx . . $ cmsghdr#cmsg_level. = SOL_ALGcxx . . $ `<external>/8962547315054503424/socket.h:167:9`!;
218 header->cmsg_typecxx . . $ cmsghdr#cmsg_type. = ALG_SET_IVcxx . . $ `<external>/7256700519741588701/if_alg.h:50:9`!;
219 header->cmsg_lencxx . . $ cmsghdr#cmsg_len. = kcapi_downcast_socklen_tcxx . . $ kcapi_downcast_socklen_t(ecdaa1632f49f591).(iv_msg_size);
220 alg_iv = (void*)CMSG_DATAcxx . . $ `<external>/8962547315054503424/socket.h:299:10`!(header);
221 alg_iv->ivlencxx . . $ af_alg_iv#ivlen. = tfm->infocxx . . $ kcapi_handle_tfm#info..ivsizecxx . . $ kcapi_cipher_info#ivsize.;
222 memcpycxx . . $ memcpy(cc817cb175f282d).(alg_iv->ivcxx . . $ af_alg_iv#iv., handle->ciphercxx . . $ kcapi_handle#cipher..ivcxx . . $ kcapi_cipher_data#iv., tfm->infocxx . . $ kcapi_handle_tfm#info..ivsizecxx . . $ kcapi_cipher_info#ivsize.);
223 }
224
225 /* set AEAD information */
226 if (handle->aeadcxx . . $ kcapi_handle#aead..assoclencxx . . $ kcapi_aead_data#assoclen.) {
227 /* Set associated data length */
228 header = CMSG_NXTHDRcxx . . $ `<external>/8962547315054503424/socket.h:303:9`!(&msg, header);
229 if (!header) {
230 ret = -EFAULTcxx . . $ `<external>/8987895939074593727/errno-base.h:18:9`!;
231 goto out;
232 }
233 header->cmsg_levelcxx . . $ cmsghdr#cmsg_level. = SOL_ALGcxx . . $ `<external>/8962547315054503424/socket.h:167:9`!;
234 header->cmsg_typecxx . . $ cmsghdr#cmsg_type. = ALG_SET_AEAD_ASSOCLENcxx . . $ `<external>/7256700519741588701/if_alg.h:52:9`!;
235 header->cmsg_lencxx . . $ cmsghdr#cmsg_len. = CMSG_LENcxx . . $ `<external>/8962547315054503424/socket.h:311:9`!(sizeof(*assoclen));
236 assoclen = (void*)CMSG_DATAcxx . . $ `<external>/8962547315054503424/socket.h:299:10`!(header);
237 *assoclen = (uint32_tcxx . . $ uint32_t#)handle->aeadcxx . . $ kcapi_handle#aead..assoclencxx . . $ kcapi_aead_data#assoclen.;
238 }
239
240 ret = sendmsgcxx . . $ sendmsg(bc65c149164ceef5).(*_kcapi_get_opfdcxx . . $ _kcapi_get_opfd(f39930546eae134b).(handle), &msg, (int)flags);
241 if (ret < 0)
242 ret = -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
243 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG.,
244 "AF_ALG: sendmsg syscall returned %zd", ret);
245
246 out:
247 kcapi_memset_securecxx . . $ kcapi_memset_secure(e37d57925061d5c9).(buffer_p, 0, bufferlen);
248 if (buffer_alloc)
249 freecxx . . $ free(5d22bdacc48458e8).(buffer_alloc);
250 return ret;
251 }
252
253 ssize_tcxx . . $ ssize_t# _kcapi_common_send_datacxx . . $ _kcapi_common_send_data(367dd066ce527de7).(struct kcapi_handlecxx . . $ kcapi_handle# *handle,
254 struct ioveccxx . . $ iovec# *iov, size_t iovlen,
255 uint32_tcxx . . $ uint32_t# flags)
256 {
257 struct msghdrcxx . . $ msghdr# msg;
258 ssize_tcxx . . $ ssize_t# ret;
259
260 ret = _kcapi_common_acceptcxx . . $ _kcapi_common_accept(cad780c06c088da8).(handle);
261 if (ret)
262 return ret;
263
264 msg.msg_namecxx . . $ msghdr#msg_name. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
265 msg.msg_namelencxx . . $ msghdr#msg_namelen. = 0;
266 msg.msg_controlcxx . . $ msghdr#msg_control. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
267 msg.msg_controllencxx . . $ msghdr#msg_controllen. = 0;
268 msg.msg_flagscxx . . $ msghdr#msg_flags. = 0;
269 msg.msg_iovcxx . . $ msghdr#msg_iov. = iov;
270 msg.msg_iovlencxx . . $ msghdr#msg_iovlen. = kcapi_downcast_intcxx . . $ kcapi_downcast_int(ecdaa1632f49f591).(iovlen);
271 ret = sendmsgcxx . . $ sendmsg(bc65c149164ceef5).(*_kcapi_get_opfdcxx . . $ _kcapi_get_opfd(f39930546eae134b).(handle), &msg, (int)flags);
272 if (ret < 0)
273 ret = -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
274 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG., "AF_ALG: sendmsg syscall returned %zd",
275 ret);
276
277 return ret;
278 }
279
280 ssize_tcxx . . $ ssize_t# _kcapi_common_vmsplice_iovcxx . . $ _kcapi_common_vmsplice_iov(367dd066ce527de7).(struct kcapi_handlecxx . . $ kcapi_handle# *handle,
281 struct ioveccxx . . $ iovec# *iov, size_t iovlen,
282 uint32_tcxx . . $ uint32_t# flags)
283 {
284 ssize_tcxx . . $ ssize_t# ret = 0;
285 size_t i, inlen = 0;
286
287 if (iovlen && !iov)
288 return -EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!;
289
290 for (i = 0; i < iovlen; i++)
291 inlen += iov[i].iov_lencxx . . $ iovec#iov_len.;
292
293 /*
294 * The kernel has the following limits for vmsplice / splice:
295 *
296 * 1. At most only 16 pages are allowed to be sent to the kernel -
297 * this is a hard limit in the vmsplice system call.
298 * 2. At most, the entire buffer size must not be larger than the
299 * buffer size of the pipe used for the splice. If desired, this
300 * buffer size can be enlarged with kcapi_set_maxsplicesize().
301 * On the other side, the maximum buffer size can be obtained via
302 * kcapi_get_maxsplicesize().
303 * 3. vmsplice cannot be used for a zero buffer.
304 *
305 * If any of the aforementioned conditions is not satisfied, the
306 * sendmsg() system call is used which copies the data into the
307 * kernel.
308 */
309 handle->processed_sgcxx . . $ kcapi_handle#processed_sg. += iovlen;
310 if (handle->processed_sgcxx . . $ kcapi_handle#processed_sg. > (size_t)handle->flagscxx . . $ kcapi_handle#flags..alg_max_pagescxx . . $ kcapi_flags#alg_max_pages. ||
311 !inlen ||
312 inlen > handle->pipesizecxx . . $ kcapi_handle#pipesize.) {
313 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG.,
314 "AF_ALG: Using fallback of sendmsg instead of splice");
315 return _kcapi_common_send_datacxx . . $ _kcapi_common_send_data(367dd066ce527de7).(handle, iov, iovlen,
316 (flags & SPLICE_F_MOREcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:350:10`!) ?
317 MSG_MOREcxx . . $ `<external>/8962547315054503424/socket.h:244:9`! : 0);
318 }
319
320 ret = _kcapi_common_acceptcxx . . $ _kcapi_common_accept(cad780c06c088da8).(handle);
321 if (ret)
322 return ret;
323
324 ret = vmsplicecxx . . $ vmsplice(b7d9c1fa1828641b).(handle->pipescxx . . $ kcapi_handle#pipes.[1], iov, iovlen, SPLICE_F_GIFTcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:351:10`!|flags);
325 if (ret < 0) {
326 ret = -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
327 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG.,
328 "AF_ALG: vmsplice syscall returned %zd", ret);
329 return ret;
330 }
331 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG., "AF_ALG: vmsplice syscall returned %zd",
332 ret);
333
334 if ((uint32_tcxx . . $ uint32_t#)ret != inlen) {
335 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_ERRcxx . . $ KCAPI_LOG_ERR., "vmsplice: not all data received by kernel (data received: %ld -- data sent: %lu)",
336 (long)ret, (unsigned long)inlen);
337 return -EFAULTcxx . . $ `<external>/8987895939074593727/errno-base.h:18:9`!;
338 }
339
340 ret = splicecxx . . $ splice(7c2a8cca29d0e29f).(handle->pipescxx . . $ kcapi_handle#pipes.[0], NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, *_kcapi_get_opfdcxx . . $ _kcapi_get_opfd(f39930546eae134b).(handle), NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!,
341 (size_t)ret, flags);
342 if (ret < 0)
343 ret = -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
344 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG., "AF_ALG: splice syscall returned %zd",
345 ret);
346
347 return ret;
348 }
349
350 ssize_tcxx . . $ ssize_t# _kcapi_common_vmsplice_chunkcxx . . $ _kcapi_common_vmsplice_chunk(1f8f8f1822879a).(struct kcapi_handlecxx . . $ kcapi_handle# *handle,
351 const uint8_tcxx . . $ uint8_t# *in, size_t inlen,
352 uint32_tcxx . . $ uint32_t# flags)
353 {
354 struct ioveccxx . . $ iovec# iov;
355 ssize_tcxx . . $ ssize_t# processed = 0;
356 ssize_tcxx . . $ ssize_t# ret = 0;
357 uint32_tcxx . . $ uint32_t# sflags = (flags & SPLICE_F_MOREcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:350:10`!) ? MSG_MOREcxx . . $ `<external>/8962547315054503424/socket.h:244:9`! : 0;
358
359 if (inlen > INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!)
360 return -EMSGSIZEcxx . . $ `<external>/17922322188510340118/errno.h:74:9`!;
361
362 if (!inlen)
363 return _kcapi_common_send_datacxx . . $ _kcapi_common_send_data(367dd066ce527de7).(handle, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0, sflags);
364
365 ret = _kcapi_common_acceptcxx . . $ _kcapi_common_accept(cad780c06c088da8).(handle);
366 if (ret)
367 return ret;
368
369 while (inlen) {
370 iov.iov_basecxx . . $ iovec#iov_base. = (void*)(uintptr_tcxx . . $ uintptr_t#)(in + processed);
371 iov.iov_lencxx . . $ iovec#iov_len. = inlen;
372
373 /*
374 * See comment in _kcapi_common_vmsplice_iov for the explanation
375 * of this check.
376 */
377 if ((handle->processed_sgcxx . . $ kcapi_handle#processed_sg.++) > handle->flagscxx . . $ kcapi_handle#flags..alg_max_pagescxx . . $ kcapi_flags#alg_max_pages. ||
378 !inlen ||
379 inlen > handle->pipesizecxx . . $ kcapi_handle#pipesize.) {
380 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG.,
381 "AF_ALG: Using fallback of sendmsg instead of splice");
382 ret = _kcapi_common_send_datacxx . . $ _kcapi_common_send_data(367dd066ce527de7).(handle, &iov, 1, sflags);
383 if (ret < 0)
384 return ret;
385 } else {
386 ret = vmsplicecxx . . $ vmsplice(b7d9c1fa1828641b).(handle->pipescxx . . $ kcapi_handle#pipes.[1], &iov, 1,
387 SPLICE_F_GIFTcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:351:10`!|flags);
388 if (ret < 0) {
389 ret = -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
390 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG.,
391 "AF_ALG: vmsplice syscall returned %zd",
392 ret);
393 return ret;
394 }
395 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG.,
396 "AF_ALG: vmsplice syscall returned %zd",
397 ret);
398
399 ret = splicecxx . . $ splice(7c2a8cca29d0e29f).(handle->pipescxx . . $ kcapi_handle#pipes.[0], NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!,
400 *_kcapi_get_opfdcxx . . $ _kcapi_get_opfd(f39930546eae134b).(handle), NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!,
401 (size_t)ret, flags);
402 if (ret < 0) {
403 ret = -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
404 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG.,
405 "AF_ALG: splice syscall returned %zd",
406 ret);
407 return ret;
408 }
409 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG.,
410 "AF_ALG: splice syscall returned %zd", ret);
411 }
412
413 processed += ret;
414 inlen -= (uint32_tcxx . . $ uint32_t#)ret;
415 }
416
417 return processed;
418 }
419
420 /* Wrapper for io_getevents -- returns < 0 on error, or processed bytes */
421 int _kcapi_aio_read_allcxx . . $ _kcapi_aio_read_all(98d83b17fa6c06b3).(struct kcapi_handlecxx . . $ kcapi_handle# *handle, size_t toread,
422 struct timespeccxx . . $ timespec# *timeout)
423 {
424 if (toread > KCAPI_AIO_CONCURRENTcxx . . $ `lib/internal.h:186:9`!)
425 return -EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!;
426
427 while (toread) {
428 int i;
429 struct io_eventcxx . . $ io_event# events[KCAPI_AIO_CONCURRENTcxx . . $ `lib/internal.h:186:9`!];
430 int rc = io_geteventscxx . . $ io_getevents(4689c31347438dbe).(handle->aiocxx . . $ kcapi_handle#aio..aio_ctxcxx . . $ kcapi_aio#aio_ctx., 1, (long)toread,
431 events, timeout);
432
433 if (rc < 0)
434 return rc;
435
436 for (i = 0; i < rc; i++) {
437 struct iocbcxx . . $ iocb# *cb;
438
439 /*
440 * If one cipher operation fails, so will the entire
441 * AIO operation
442 */
443 if (events[i].rescxx . . $ io_event#res. < 0) {
444 handle->aiocxx . . $ kcapi_handle#aio..iocb_retcxx . . $ kcapi_aio#iocb_ret.[events[i].datacxx . . $ io_event#data.] =
445 events[i].rescxx . . $ io_event#res.;
446 return (int)events[i].rescxx . . $ io_event#res.;
447 }
448
449 cb = (struct iocbcxx . . $ iocb# *)(uintptr_tcxx . . $ uintptr_t#)events[i].objcxx . . $ io_event#obj.;
450
451 /*
452 * Older symmetric AIO implementations used a wrong
453 * return code.
454 */
455 if (events[i].rescxx . . $ io_event#res. > 0) {
456 handle->aiocxx . . $ kcapi_handle#aio..iocb_retcxx . . $ kcapi_aio#iocb_ret.[events[i].datacxx . . $ io_event#data.] =
457 events[i].rescxx . . $ io_event#res.;
458 } else {
459 handle->aiocxx . . $ kcapi_handle#aio..iocb_retcxx . . $ kcapi_aio#iocb_ret.[events[i].datacxx . . $ io_event#data.] =
460 (__s64cxx . . $ __s64#)cb->aio_nbytescxx . . $ iocb#aio_nbytes.;
461 }
462
463 cb->aio_fildescxx . . $ iocb#aio_fildes. = 0;
464 }
465 toread -= (uint32_tcxx . . $ uint32_t#)rc;
466 }
467
468 return 0;
469 }
470
471 int _kcapi_aio_send_iovcxx . . $ _kcapi_aio_send_iov(b8e608a74ce2f87d).(struct kcapi_handlecxx . . $ kcapi_handle# *handle, struct ioveccxx . . $ iovec# *iov,
472 size_t iovlen, int access, unsigned int enc)
473 {
474 ssize_tcxx . . $ ssize_t# ret;
475 size_t len = iov ? iov->iov_lencxx . . $ iovec#iov_len. : 0;
476
477 /*
478 * Using two syscalls with memcpy is faster than four syscalls
479 * without memcpy below the given threshold.
480 */
481 if ((access == KCAPI_ACCESS_HEURISTICcxx . . $ `lib/kcapi.h:44:9`! && len <= (1<<13)) ||
482 access == KCAPI_ACCESS_SENDMSGcxx . . $ `lib/kcapi.h:46:9`!) {
483 ret = _kcapi_common_send_metacxx . . $ _kcapi_common_send_meta(f4e40828a4f4c91f).(handle, iov, iovlen, enc, 0);
484 if (0 > ret)
485 return (int)ret;
486 } else {
487 ret = _kcapi_common_send_metacxx . . $ _kcapi_common_send_meta(f4e40828a4f4c91f).(handle, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0, enc, MSG_MOREcxx . . $ `<external>/8962547315054503424/socket.h:244:9`!);
488 if (0 > ret)
489 return (int)ret;
490 ret = _kcapi_common_vmsplice_iovcxx . . $ _kcapi_common_vmsplice_iov(367dd066ce527de7).(handle, iov, iovlen, 0);
491 if (0 > ret)
492 return (int)ret;
493 }
494
495 return 0;
496 }
497
498 int _kcapi_aio_read_iovcxx . . $ _kcapi_aio_read_iov(b78c7fa11dfbc2b0).(struct kcapi_handlecxx . . $ kcapi_handle# *handle,
499 struct ioveccxx . . $ iovec# *iov, size_t iovlen)
500 {
501 struct iocbcxx . . $ iocb# *cb = handle->aiocxx . . $ kcapi_handle#aio..ciocxx . . $ kcapi_aio#cio.;
502 size_t i;
503 int32_tcxx . . $ int32_t# ret;
504
505 if (iovlen > KCAPI_AIO_CONCURRENTcxx . . $ `lib/internal.h:186:9`!)
506 return -EFAULTcxx . . $ `<external>/8987895939074593727/errno-base.h:18:9`!;
507
508 for (i = 0; i < iovlen; i++) {
509 while (cb->aio_fildescxx . . $ iocb#aio_fildes.) {
510 struct timespeccxx . . $ timespec# timeout;
511
512 timeout.tv_seccxx . . $ timespec#tv_sec. = 0;
513 timeout.tv_nseccxx . . $ timespec#tv_nsec. = 10000;
514 ret = _kcapi_aio_read_allcxx . . $ _kcapi_aio_read_all(98d83b17fa6c06b3).(handle, iovlen, &timeout);
515 if (ret < 0)
516 return ret;
517 }
518
519 memsetcxx . . $ memset(d1de1e4fb215f1c6).(cb, 0, sizeof(*cb));
520 cb->aio_fildescxx . . $ iocb#aio_fildes. = (__u32cxx . . $ __u32#)*_kcapi_get_opfdcxx . . $ _kcapi_get_opfd(f39930546eae134b).(handle);
521 cb->aio_lio_opcodecxx . . $ iocb#aio_lio_opcode. = IOCB_CMD_PREADcxx . . $ IOCB_CMD_PREAD.;
522 cb->aio_bufcxx . . $ iocb#aio_buf. = (unsigned long)iov->iov_basecxx . . $ iovec#iov_base.;
523 cb->aio_offsetcxx . . $ iocb#aio_offset. = 0;
524 cb->aio_datacxx . . $ iocb#aio_data. = i;
525 cb->aio_nbytescxx . . $ iocb#aio_nbytes. = iov->iov_lencxx . . $ iovec#iov_len.;
526 cb->aio_flagscxx . . $ iocb#aio_flags. = IOCB_FLAG_RESFDcxx . . $ `<external>/13099485159790371437/aio_abi.h:56:9`!;
527 cb->aio_resfdcxx . . $ iocb#aio_resfd. = (__u32cxx . . $ __u32#)handle->aiocxx . . $ kcapi_handle#aio..efdcxx . . $ kcapi_aio#efd.;
528
529 handle->aiocxx . . $ kcapi_handle#aio..iocb_retcxx . . $ kcapi_aio#iocb_ret.[i] = AIO_OUTSTANDINGcxx . . $ `lib/internal.h:197:9`!;
530
531 cb++;
532 iov++;
533 }
534
535 ret = io_submitcxx . . $ io_submit(a5040d84332d5fe0).(handle->aiocxx . . $ kcapi_handle#aio..aio_ctxcxx . . $ kcapi_aio#aio_ctx., (long)iovlen, handle->aiocxx . . $ kcapi_handle#aio..cioppcxx . . $ kcapi_aio#ciopp.);
536 if ((uint32_tcxx . . $ uint32_t#)ret != iovlen) {
537 if (ret < 0) {
538 ret = -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
539 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_ERRcxx . . $ KCAPI_LOG_ERR., "io_read Error: %d\n", ret);
540 return ret;
541 } else {
542 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_ERRcxx . . $ KCAPI_LOG_ERR.,
543 "Could not sumbit AIO read\n");
544 return -EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!;
545 }
546 }
547
548 return _kcapi_aio_read_allcxx . . $ _kcapi_aio_read_all(98d83b17fa6c06b3).(handle, iovlen, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
549 }
550
551 ssize_tcxx . . $ ssize_t# _kcapi_common_recv_datacxx . . $ _kcapi_common_recv_data(8a8f5b62e036cb66).(struct kcapi_handlecxx . . $ kcapi_handle# *handle,
552 struct ioveccxx . . $ iovec# *iov, size_t iovlen)
553 {
554 struct msghdrcxx . . $ msghdr# msg;
555 ssize_tcxx . . $ ssize_t# ret;
556
557 ret = _kcapi_common_acceptcxx . . $ _kcapi_common_accept(cad780c06c088da8).(handle);
558 if (ret)
559 return ret;
560
561 msg.msg_namecxx . . $ msghdr#msg_name. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
562 msg.msg_namelencxx . . $ msghdr#msg_namelen. = 0;
563 msg.msg_controlcxx . . $ msghdr#msg_control. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
564 msg.msg_controllencxx . . $ msghdr#msg_controllen. = 0;
565 msg.msg_flagscxx . . $ msghdr#msg_flags. = 0;
566 msg.msg_iovcxx . . $ msghdr#msg_iov. = iov;
567 #ifdef __GLIBC__cxx . . $ `<external>/18206667465210621810/features.h:514:9`!
568 msg.msg_iovlencxx . . $ msghdr#msg_iovlen. = iovlen;
569 #else
570 msg.msg_iovlen = (int)iovlen;
571 #endif
572 ret = recvmsgcxx . . $ recvmsg(616999ca12de9af7).(*_kcapi_get_opfdcxx . . $ _kcapi_get_opfd(f39930546eae134b).(handle), &msg, 0);
573 if (ret < 0)
574 ret = -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
575 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG., "AF_ALG: recvmsg syscall returned %zd",
576 ret);
577
578 /*
579 * As the iovecs are processed and removed from the list in the kernel
580 * we can also reset the list of processed iovecs here.
581 *
582 * Note, if there is an error, the kernel keeps the list unless it is
583 * a "valid" error of EBADMSG indicating an integrity error of the
584 * crypto operation.
585 */
586 if (ret >= 0 || ret == -EBADMSGcxx . . $ `<external>/17922322188510340118/errno.h:57:9`!)
587 handle->processed_sgcxx . . $ kcapi_handle#processed_sg. = 0;
588
589 #if 0
590 /*
591 * Truncated message digests can be identified with this check.
592 */
593 if (msg.msg_flags & MSG_TRUNC) {
594 fprintf(stderr, "recvmsg: processed data was truncated by kernel (only %lu bytes processed)\n", (unsigned long)ret);
595 return -EMSGSIZE;
596 }
597 #endif
598
599 return ret;
600 }
601
602 ssize_tcxx . . $ ssize_t# _kcapi_common_read_datacxx . . $ _kcapi_common_read_data(e37e70272ed35378).(struct kcapi_handlecxx . . $ kcapi_handle# *handle,
603 uint8_tcxx . . $ uint8_t# *out, size_t outlen)
604 {
605 ssize_tcxx . . $ ssize_t# ret;
606 ssize_tcxx . . $ ssize_t# totallen = 0;
607
608 if (outlen > INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!)
609 return -EMSGSIZEcxx . . $ `<external>/17922322188510340118/errno.h:74:9`!;
610
611 ret = _kcapi_common_acceptcxx . . $ _kcapi_common_accept(cad780c06c088da8).(handle);
612 if (ret)
613 return ret;
614
615
616 if (outlen) {
617 do {
618 ret = readcxx . . $ read(7e34d0a36f355389).(*_kcapi_get_opfdcxx . . $ _kcapi_get_opfd(f39930546eae134b).(handle), out, outlen);
619 if (ret > 0) {
620 out += ret;
621 outlen -= (uint32_tcxx . . $ uint32_t#)ret;
622 totallen += ret;
623 }
624 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG.,
625 "AF_ALG: read syscall returned %zd", ret);
626 } while ((ret > 0 || errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`!) && outlen);
627
628 if (ret < 0)
629 return -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
630 }
631
632 return totallen;
633 }
634
635 int _kcapi_common_setkeycxx . . $ _kcapi_common_setkey(4d0e261613a805ee).(struct kcapi_handlecxx . . $ kcapi_handle# *handle,
636 const uint8_tcxx . . $ uint8_t# *key, uint32_tcxx . . $ uint32_t# keylen)
637 {
638 struct kcapi_handle_tfmcxx . . $ kcapi_handle_tfm# *tfm = handle->tfmcxx . . $ kcapi_handle#tfm.;
639 int ret;
640
641 ret = setsockoptcxx . . $ setsockopt(506cc1d0fc70fdf1).(tfm->tfmfdcxx . . $ kcapi_handle_tfm#tfmfd., SOL_ALGcxx . . $ `<external>/8962547315054503424/socket.h:167:9`!, ALG_SET_KEYcxx . . $ `<external>/7256700519741588701/if_alg.h:49:9`!, key, keylen);
642 if (ret < 0)
643 ret = -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
644 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG.,
645 "AF_ALG setkey: setsockopt syscall returned %d", ret);
646
647 return ret;
648 }
649
650 int _kcapi_common_setentropycxx . . $ _kcapi_common_setentropy(4d0e261613a805ee).(struct kcapi_handlecxx . . $ kcapi_handle# *handle,
651 const uint8_tcxx . . $ uint8_t# *ent, uint32_tcxx . . $ uint32_t# entlen)
652 {
653 struct kcapi_handle_tfmcxx . . $ kcapi_handle_tfm# *tfm = handle->tfmcxx . . $ kcapi_handle#tfm.;
654 int ret;
655
656 ret = setsockoptcxx . . $ setsockopt(506cc1d0fc70fdf1).(tfm->tfmfdcxx . . $ kcapi_handle_tfm#tfmfd., SOL_ALGcxx . . $ `<external>/8962547315054503424/socket.h:167:9`!, ALG_SET_DRBG_ENTROPYcxx . . $ `<external>/7256700519741588701/if_alg.h:54:9`!, ent,
657 entlen);
658 if (ret < 0)
659 ret = -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
660 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG.,
661 "AF_ALG setentropy: setsockopt syscall returned %d", ret);
662
663 return ret;
664 }
665
666 static int __kcapi_common_getinfocxx . . $ __kcapi_common_getinfo(c96254a40d307cab).(struct kcapi_handlecxx . . $ kcapi_handle# *handle,
667 const char *ciphername,
668 int drivername)
669 {
670 struct kcapi_handle_tfmcxx . . $ kcapi_handle_tfm# *tfm = handle->tfmcxx . . $ kcapi_handle#tfm.;
671 int ret = -EFAULTcxx . . $ `<external>/8987895939074593727/errno-base.h:18:9`!;
672
673 /* NETLINK_CRYPTO specific */
674 char buf[4096];
675 struct nlmsghdrcxx . . $ nlmsghdr# *res_n = (struct nlmsghdrcxx . . $ nlmsghdr# *)buf;
676 structcxx . . $ __kcapi_common_getinfo(c96254a40d307cab).$anonymous_type_0# {
677 struct nlmsghdrcxx . . $ nlmsghdr# ncxx . . $ __kcapi_common_getinfo(c96254a40d307cab).$anonymous_type_0#n.;
678 struct crypto_user_algcxx . . $ crypto_user_alg# crucxx . . $ __kcapi_common_getinfo(c96254a40d307cab).$anonymous_type_0#cru.;
679 } req;
680 struct crypto_user_algcxx . . $ crypto_user_alg# *cru_res = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
681 unsigned long res_len = 0;
682 struct rtattrcxx . . $ rtattr# *tb[CRYPTOCFGA_MAXcxx . . $ `lib/cryptouser.h:57:9`!+1];
683 struct rtattrcxx . . $ rtattr# *rta;
684
685 /* AF_NETLINK specific */
686 struct sockaddr_nlcxx . . $ sockaddr_nl# nl;
687 int sd = 0;
688 socklen_tcxx . . $ socklen_t# addr_len;
689 struct ioveccxx . . $ iovec# iov;
690 struct msghdrcxx . . $ msghdr# msg;
691
692 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&req, 0, sizeof(req));
693 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&buf, 0, sizeof(buf));
694 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&msg, 0, sizeof(msg));
695
696 req.ncxx . . $ __kcapi_common_getinfo(c96254a40d307cab).$anonymous_type_0#n..nlmsg_lencxx . . $ nlmsghdr#nlmsg_len. = NLMSG_LENGTHcxx . . $ `<external>/10309334508915867907/netlink.h:101:9`!(sizeof(req.cru));
697 req.ncxx . . $ __kcapi_common_getinfo(c96254a40d307cab).$anonymous_type_0#n..nlmsg_flagscxx . . $ nlmsghdr#nlmsg_flags. = NLM_F_REQUESTcxx . . $ `<external>/10309334508915867907/netlink.h:62:9`!;
698 req.ncxx . . $ __kcapi_common_getinfo(c96254a40d307cab).$anonymous_type_0#n..nlmsg_typecxx . . $ nlmsghdr#nlmsg_type. = CRYPTO_MSG_GETALGcxx . . $ CRYPTO_MSG_GETALG.;
699 req.ncxx . . $ __kcapi_common_getinfo(c96254a40d307cab).$anonymous_type_0#n..nlmsg_seqcxx . . $ nlmsghdr#nlmsg_seq. = (__u32cxx . . $ __u32#)timecxx . . $ time(7f38134db6521d23).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
700
701 if (drivername)
702 strncpycxx . . $ strncpy(255158a415b673b0).(req.crucxx . . $ __kcapi_common_getinfo(c96254a40d307cab).$anonymous_type_0#cru..cru_driver_namecxx . . $ crypto_user_alg#cru_driver_name., ciphername,
703 sizeof(req.crucxx . . $ __kcapi_common_getinfo(c96254a40d307cab).$anonymous_type_0#cru..cru_driver_namecxx . . $ crypto_user_alg#cru_driver_name.) - 1);
704 else
705 strncpycxx . . $ strncpy(255158a415b673b0).(req.crucxx . . $ __kcapi_common_getinfo(c96254a40d307cab).$anonymous_type_0#cru..cru_namecxx . . $ crypto_user_alg#cru_name., ciphername, sizeof(req.crucxx . . $ __kcapi_common_getinfo(c96254a40d307cab).$anonymous_type_0#cru..cru_namecxx . . $ crypto_user_alg#cru_name.) - 1);
706
707 /* talk to netlink socket */
708 sd = socketcxx . . $ socket(2326284602b0bb2d).(AF_NETLINKcxx . . $ `<external>/8962547315054503424/socket.h:111:9`!, SOCK_RAWcxx . . $ `<external>/5956532346368192945/socket_type.h:33:9`!, NETLINK_CRYPTOcxx . . $ `<external>/10309334508915867907/netlink.h:30:9`!);
709 if (sd < 0) {
710 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_ERRcxx . . $ KCAPI_LOG_ERR.,
711 "Netlink error: cannot open netlink socket");
712 return -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
713 }
714 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&nl, 0, sizeof(nl));
715 nl.nl_familycxx . . $ sockaddr_nl#nl_family. = AF_NETLINKcxx . . $ `<external>/8962547315054503424/socket.h:111:9`!;
716 if (bindcxx . . $ bind(f39c6c650450bfdd).(sd, (struct sockaddrcxx . . $ sockaddr#*)&nl, sizeof(nl)) < 0) {
717 ret = -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
718 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_ERRcxx . . $ KCAPI_LOG_ERR.,
719 "Netlink error: cannot bind netlink socket");
720 goto out;
721 }
722 /* sanity check that netlink socket was successfully opened */
723 addr_len = sizeof(nl);
724 if (getsocknamecxx . . $ getsockname(ff9054838cdf4227).(sd, (struct sockaddrcxx . . $ sockaddr#*)&nl, &addr_len) < 0) {
725 ret = -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
726 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_ERRcxx . . $ KCAPI_LOG_ERR., "Netlink error: cannot getsockname");
727 goto out;
728 }
729 if (addr_len != sizeof(nl)) {
730 ret = -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
731 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_ERRcxx . . $ KCAPI_LOG_ERR.,
732 "Netlink error: wrong address length %d", addr_len);
733 goto out;
734 }
735 if (nl.nl_familycxx . . $ sockaddr_nl#nl_family. != AF_NETLINKcxx . . $ `<external>/8962547315054503424/socket.h:111:9`!) {
736 ret = -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
737 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_ERRcxx . . $ KCAPI_LOG_ERR.,
738 "Netlink error: wrong address family %d",
739 nl.nl_familycxx . . $ sockaddr_nl#nl_family.);
740 goto out;
741 }
742
743 /* sending data */
744 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&nl, 0, sizeof(nl));
745 nl.nl_familycxx . . $ sockaddr_nl#nl_family. = AF_NETLINKcxx . . $ `<external>/8962547315054503424/socket.h:111:9`!;
746 iov.iov_basecxx . . $ iovec#iov_base. = (void*) &req.ncxx . . $ __kcapi_common_getinfo(c96254a40d307cab).$anonymous_type_0#n.;
747 iov.iov_lencxx . . $ iovec#iov_len. = req.ncxx . . $ __kcapi_common_getinfo(c96254a40d307cab).$anonymous_type_0#n..nlmsg_lencxx . . $ nlmsghdr#nlmsg_len.;
748 msg.msg_namecxx . . $ msghdr#msg_name. = &nl;
749 msg.msg_namelencxx . . $ msghdr#msg_namelen. = sizeof(nl);
750 msg.msg_iovcxx . . $ msghdr#msg_iov. = &iov;
751 msg.msg_iovlencxx . . $ msghdr#msg_iovlen. = 1;
752 if (sendmsgcxx . . $ sendmsg(bc65c149164ceef5).(sd, &msg, 0) < 0) {
753 ret = -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
754 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_ERRcxx . . $ KCAPI_LOG_ERR., "Netlink error: sendmsg failed");
755 goto out;
756 }
757 memsetcxx . . $ memset(d1de1e4fb215f1c6).(buf,0,sizeof(buf));
758 iov.iov_basecxx . . $ iovec#iov_base. = buf;
759 while (1) {
760 ssize_tcxx . . $ ssize_t# rc;
761 iov.iov_lencxx . . $ iovec#iov_len. = sizeof(buf);
762 rc = recvmsgcxx . . $ recvmsg(616999ca12de9af7).(sd, &msg, 0);
763 if (rc < 0) {
764 if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`! || errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EAGAINcxx . . $ `<external>/8987895939074593727/errno-base.h:15:9`!)
765 continue;
766 ret = -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
767 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_ERRcxx . . $ KCAPI_LOG_ERR.,
768 "Netlink error: netlink receive error");
769 goto out;
770 }
771 if (rc == 0) {
772 ret = -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
773 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_ERRcxx . . $ KCAPI_LOG_ERR., "Netlink error: no data");
774 goto out;
775 }
776 if (rc > (ssize_tcxx . . $ ssize_t#)sizeof(buf)) {
777 ret = -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
778 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_ERRcxx . . $ KCAPI_LOG_ERR.,
779 "Netlink error: received too much data");
780 goto out;
781 }
782 break;
783 }
784
785 ret = -EFAULTcxx . . $ `<external>/8987895939074593727/errno-base.h:18:9`!;
786 res_len = res_n->nlmsg_lencxx . . $ nlmsghdr#nlmsg_len.;
787 if (res_n->nlmsg_typecxx . . $ nlmsghdr#nlmsg_type. == NLMSG_ERRORcxx . . $ `<external>/10309334508915867907/netlink.h:113:9`!) {
788 /*
789 * return -EAGAIN -- this error will occur if we received a
790 * driver name, but used it for a generic name. Allow caller
791 * to invoke function again where driver name is looked up
792 */
793 ret = -EAGAINcxx . . $ `<external>/8987895939074593727/errno-base.h:15:9`!;
794 goto out;
795 }
796
797 if (res_n->nlmsg_typecxx . . $ nlmsghdr#nlmsg_type. == CRYPTO_MSG_GETALGcxx . . $ CRYPTO_MSG_GETALG.) {
798 cru_res = NLMSG_DATAcxx . . $ `<external>/10309334508915867907/netlink.h:103:9`!(res_n);
799 if (res_len < NLMSG_SPACEcxx . . $ `<external>/10309334508915867907/netlink.h:102:9`!(sizeof(*cru_res))) {
800 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_ERRcxx . . $ KCAPI_LOG_ERR., "Netlink error: nlmsg len %lu",
801 res_len);
802 goto out;
803 }
804 res_len -= NLMSG_SPACEcxx . . $ `<external>/10309334508915867907/netlink.h:102:9`!(sizeof(*cru_res));
805 }
806
807 /* parse data */
808 if (!cru_res) {
809 ret = -EFAULTcxx . . $ `<external>/8987895939074593727/errno-base.h:18:9`!;
810 goto out;
811 }
812 rta = CR_RTAcxx . . $ `lib/cryptouser.h:36:9`!(cru_res);
813 memsetcxx . . $ memset(d1de1e4fb215f1c6).(tb, 0, sizeof(struct rtattrcxx . . $ rtattr# *) * (CRYPTOCFGA_MAXcxx . . $ `lib/cryptouser.h:57:9`! + 1));
814 while (RTA_OKcxx . . $ `<external>/3545870826357160831/rtnetlink.h:228:9`!(rta, res_len)) {
815 if ((rta->rta_typecxx . . $ rtattr#rta_type. <= CRYPTOCFGA_MAXcxx . . $ `lib/cryptouser.h:57:9`!) && (!tb[rta->rta_typecxx . . $ rtattr#rta_type.]))
816 tb[rta->rta_typecxx . . $ rtattr#rta_type.] = rta;
817 rta = RTA_NEXTcxx . . $ `<external>/3545870826357160831/rtnetlink.h:231:9`!(rta, res_len);
818 }
819 if (res_len) {
820 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_ERRcxx . . $ KCAPI_LOG_ERR., "Netlink error: unprocessed data %lu",
821 res_len);
822 goto out;
823 }
824
825 if (tb[CRYPTOCFGA_REPORT_HASHcxx . . $ CRYPTOCFGA_REPORT_HASH.]) {
826 struct rtattrcxx . . $ rtattr# *rta = tb[CRYPTOCFGA_REPORT_HASHcxx . . $ CRYPTOCFGA_REPORT_HASH.];
827 struct crypto_report_hashcxx . . $ crypto_report_hash# *rsh =
828 (struct crypto_report_hashcxx . . $ crypto_report_hash# *) RTA_DATAcxx . . $ `<external>/3545870826357160831/rtnetlink.h:235:9`!(rta);
829 tfm->infocxx . . $ kcapi_handle_tfm#info..hash_digestsizecxx . . $ kcapi_cipher_info#hash_digestsize. = rsh->digestsizecxx . . $ crypto_report_hash#digestsize.;
830 tfm->infocxx . . $ kcapi_handle_tfm#info..blocksizecxx . . $ kcapi_cipher_info#blocksize. = rsh->blocksizecxx . . $ crypto_report_hash#blocksize.;
831 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG.,
832 "Get cipher info: hash with digestsize %u, blocksize %u",
833 rsh->digestsizecxx . . $ crypto_report_hash#digestsize., rsh->blocksizecxx . . $ crypto_report_hash#blocksize.);
834
835 tfm->infocxx . . $ kcapi_handle_tfm#info..cipher_typecxx . . $ kcapi_cipher_info#cipher_type. = KCAPI_CIPHER_MDcxx . . $ KCAPI_CIPHER_MD.;
836 }
837 if (tb[CRYPTOCFGA_REPORT_BLKCIPHERcxx . . $ CRYPTOCFGA_REPORT_BLKCIPHER.]) {
838 struct rtattrcxx . . $ rtattr# *rta = tb[CRYPTOCFGA_REPORT_BLKCIPHERcxx . . $ CRYPTOCFGA_REPORT_BLKCIPHER.];
839 struct crypto_report_blkciphercxx . . $ crypto_report_blkcipher# *rblk =
840 (struct crypto_report_blkciphercxx . . $ crypto_report_blkcipher# *) RTA_DATAcxx . . $ `<external>/3545870826357160831/rtnetlink.h:235:9`!(rta);
841 tfm->infocxx . . $ kcapi_handle_tfm#info..blocksizecxx . . $ kcapi_cipher_info#blocksize. = rblk->blocksizecxx . . $ crypto_report_blkcipher#blocksize.;
842 tfm->infocxx . . $ kcapi_handle_tfm#info..ivsizecxx . . $ kcapi_cipher_info#ivsize. = rblk->ivsizecxx . . $ crypto_report_blkcipher#ivsize.;
843 tfm->infocxx . . $ kcapi_handle_tfm#info..blk_min_keysizecxx . . $ kcapi_cipher_info#blk_min_keysize. = rblk->min_keysizecxx . . $ crypto_report_blkcipher#min_keysize.;
844 tfm->infocxx . . $ kcapi_handle_tfm#info..blk_max_keysizecxx . . $ kcapi_cipher_info#blk_max_keysize. = rblk->max_keysizecxx . . $ crypto_report_blkcipher#max_keysize.;
845 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG., "Get cipher info: block cipher with blocksize %u, ivsize %u, minimum keysize %u, maximum keysize %u",
846 rblk->blocksizecxx . . $ crypto_report_blkcipher#blocksize., rblk->ivsizecxx . . $ crypto_report_blkcipher#ivsize., rblk->min_keysizecxx . . $ crypto_report_blkcipher#min_keysize.,
847 rblk->max_keysizecxx . . $ crypto_report_blkcipher#max_keysize.);
848
849 tfm->infocxx . . $ kcapi_handle_tfm#info..cipher_typecxx . . $ kcapi_cipher_info#cipher_type. = KCAPI_CIPHER_SKCIPHERcxx . . $ KCAPI_CIPHER_SKCIPHER.;
850 }
851 if (tb[CRYPTOCFGA_REPORT_AEADcxx . . $ CRYPTOCFGA_REPORT_AEAD.]) {
852 struct rtattrcxx . . $ rtattr# *rta = tb[CRYPTOCFGA_REPORT_AEADcxx . . $ CRYPTOCFGA_REPORT_AEAD.];
853 struct crypto_report_aeadcxx . . $ crypto_report_aead# *raead =
854 (struct crypto_report_aeadcxx . . $ crypto_report_aead# *) RTA_DATAcxx . . $ `<external>/3545870826357160831/rtnetlink.h:235:9`!(rta);
855 tfm->infocxx . . $ kcapi_handle_tfm#info..blocksizecxx . . $ kcapi_cipher_info#blocksize. = raead->blocksizecxx . . $ crypto_report_aead#blocksize.;
856 tfm->infocxx . . $ kcapi_handle_tfm#info..ivsizecxx . . $ kcapi_cipher_info#ivsize. = raead->ivsizecxx . . $ crypto_report_aead#ivsize.;
857 tfm->infocxx . . $ kcapi_handle_tfm#info..aead_maxauthsizecxx . . $ kcapi_cipher_info#aead_maxauthsize. = raead->maxauthsizecxx . . $ crypto_report_aead#maxauthsize.;
858 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG., "Get cipher info: AEAD block cipher with blocksize %u, ivsize %u, maximum authentication size %u",
859 raead->blocksizecxx . . $ crypto_report_aead#blocksize., raead->ivsizecxx . . $ crypto_report_aead#ivsize.,
860 raead->maxauthsizecxx . . $ crypto_report_aead#maxauthsize.);
861
862 tfm->infocxx . . $ kcapi_handle_tfm#info..cipher_typecxx . . $ kcapi_cipher_info#cipher_type. = KCAPI_CIPHER_AEADcxx . . $ KCAPI_CIPHER_AEAD.;
863 }
864 if (tb[CRYPTOCFGA_REPORT_RNGcxx . . $ CRYPTOCFGA_REPORT_RNG.]) {
865 struct rtattrcxx . . $ rtattr# *rta = tb[CRYPTOCFGA_REPORT_RNGcxx . . $ CRYPTOCFGA_REPORT_RNG.];
866 struct crypto_report_rngcxx . . $ crypto_report_rng# *rrng =
867 (struct crypto_report_rngcxx . . $ crypto_report_rng# *) RTA_DATAcxx . . $ `<external>/3545870826357160831/rtnetlink.h:235:9`!(rta);
868 tfm->infocxx . . $ kcapi_handle_tfm#info..rng_seedsizecxx . . $ kcapi_cipher_info#rng_seedsize. = rrng->seedsizecxx . . $ crypto_report_rng#seedsize.;
869 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG.,
870 "Get cipher info: RNG cipher with seedsize %u",
871 rrng->seedsizecxx . . $ crypto_report_rng#seedsize.);
872
873 tfm->infocxx . . $ kcapi_handle_tfm#info..cipher_typecxx . . $ kcapi_cipher_info#cipher_type. = KCAPI_CIPHER_RNGcxx . . $ KCAPI_CIPHER_RNG.;
874 }
875 if (tb[CRYPTOCFGA_UNSPECcxx . . $ CRYPTOCFGA_UNSPEC.])
876 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG.,
877 "Get cipher info: unspecified data received");
878 if (tb[CRYPTOCFGA_PRIORITY_VALcxx . . $ CRYPTOCFGA_PRIORITY_VAL.])
879 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG.,
880 "Get cipher info: u32 value received");
881 if (tb[CRYPTOCFGA_REPORT_LARVALcxx . . $ CRYPTOCFGA_REPORT_LARVAL.])
882 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG.,
883 "Get cipher info: larval value received");
884 if (tb[CRYPTOCFGA_REPORT_COMPRESScxx . . $ CRYPTOCFGA_REPORT_COMPRESS.])
885 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG.,
886 "Get cipher info: compression algorithm type received");
887 if (tb[CRYPTOCFGA_REPORT_CIPHERcxx . . $ CRYPTOCFGA_REPORT_CIPHER.])
888 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG.,
889 "Get cipher info: simple cipher algorithm type received");
890 if (tb[CRYPTOCFGA_REPORT_AKCIPHERcxx . . $ CRYPTOCFGA_REPORT_AKCIPHER.]) {
891 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG.,
892 "Get cipher info: asymmetric cipher algorithm type received");
893
894 tfm->infocxx . . $ kcapi_handle_tfm#info..cipher_typecxx . . $ kcapi_cipher_info#cipher_type. = KCAPI_CIPHER_AKCIPHERcxx . . $ KCAPI_CIPHER_AKCIPHER.;
895 }
896 if (tb[CRYPTOCFGA_REPORT_KPPcxx . . $ CRYPTOCFGA_REPORT_KPP.]) {
897 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG.,
898 "Get cipher info: kpp cipher algorithm type received");
899
900 tfm->infocxx . . $ kcapi_handle_tfm#info..cipher_typecxx . . $ kcapi_cipher_info#cipher_type. = KCAPI_CIPHER_KPPcxx . . $ KCAPI_CIPHER_KPP.;
901 }
902 if (tb[CRYPTOCFGA_REPORT_ACOMPcxx . . $ CRYPTOCFGA_REPORT_ACOMP.])
903 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG.,
904 "Get cipher info: asymmetric compression algorithm type received");
905 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_VERBOSEcxx . . $ KCAPI_LOG_VERBOSE.,
906 "Get cipher info: all information for %s received from kernel",
907 ciphername);
908
909 ret = 0;
910
911 out:
912 closecxx . . $ close(7864480464b09eea).(sd);
913 return ret;
914 }
915
916 static int _kcapi_common_getinfocxx . . $ _kcapi_common_getinfo(bb2abbec6f9f0bc9).(struct kcapi_handlecxx . . $ kcapi_handle# *handle,
917 const char *ciphername)
918 {
919 int ret = __kcapi_common_getinfocxx . . $ __kcapi_common_getinfo(c96254a40d307cab).(handle, ciphername, 0);
920 if (ret)
921 return __kcapi_common_getinfocxx . . $ __kcapi_common_getinfo(c96254a40d307cab).(handle, ciphername, 1);
922 return 0;
923 }
924
925 static inline void _kcapi_aio_destroycxx . . $ _kcapi_aio_destroy(aba29416d24fdd59).(struct kcapi_handlecxx . . $ kcapi_handle# *handle)
926 {
927 if (handle->aiocxx . . $ kcapi_handle#aio..efdcxx . . $ kcapi_aio#efd. != -1)
928 closecxx . . $ close(7864480464b09eea).(handle->aiocxx . . $ kcapi_handle#aio..efdcxx . . $ kcapi_aio#efd.);
929 handle->aiocxx . . $ kcapi_handle#aio..efdcxx . . $ kcapi_aio#efd. = -1;
930 if (handle->aiocxx . . $ kcapi_handle#aio..aio_ctxcxx . . $ kcapi_aio#aio_ctx.)
931 io_destroycxx . . $ io_destroy(15f694ef3c96d230).(handle->aiocxx . . $ kcapi_handle#aio..aio_ctxcxx . . $ kcapi_aio#aio_ctx.);
932 handle->aiocxx . . $ kcapi_handle#aio..aio_ctxcxx . . $ kcapi_aio#aio_ctx. = 0;
933 if (handle->aiocxx . . $ kcapi_handle#aio..ciocxx . . $ kcapi_aio#cio.)
934 freecxx . . $ free(5d22bdacc48458e8).(handle->aiocxx . . $ kcapi_handle#aio..ciocxx . . $ kcapi_aio#cio.);
935 handle->aiocxx . . $ kcapi_handle#aio..ciocxx . . $ kcapi_aio#cio. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
936 if (handle->aiocxx . . $ kcapi_handle#aio..cioppcxx . . $ kcapi_aio#ciopp.)
937 freecxx . . $ free(5d22bdacc48458e8).(handle->aiocxx . . $ kcapi_handle#aio..cioppcxx . . $ kcapi_aio#ciopp.);
938 handle->aiocxx . . $ kcapi_handle#aio..cioppcxx . . $ kcapi_aio#ciopp. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
939 if (handle->aiocxx . . $ kcapi_handle#aio..iocb_retcxx . . $ kcapi_aio#iocb_ret.)
940 freecxx . . $ free(5d22bdacc48458e8).(handle->aiocxx . . $ kcapi_handle#aio..iocb_retcxx . . $ kcapi_aio#iocb_ret.);
941 handle->aiocxx . . $ kcapi_handle#aio..iocb_retcxx . . $ kcapi_aio#iocb_ret. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
942 }
943
944 static void _kcapi_handle_destroy_tfmcxx . . $ _kcapi_handle_destroy_tfm(aba29416d24fdd59).(struct kcapi_handlecxx . . $ kcapi_handle# *handle)
945 {
946 struct kcapi_handle_tfmcxx . . $ kcapi_handle_tfm# *tfm;
947 if (!handle || !handle->tfmcxx . . $ kcapi_handle#tfm.)
948 return;
949
950 tfm = handle->tfmcxx . . $ kcapi_handle#tfm.;
951 if (atomic_dec_and_testcxx . . $ atomic_dec_and_test(3e4ce074a99d0a0f).(&tfm->refcntcxx . . $ kcapi_handle_tfm#refcnt.)) {
952 if (tfm->tfmfdcxx . . $ kcapi_handle_tfm#tfmfd. != -1)
953 closecxx . . $ close(7864480464b09eea).(tfm->tfmfdcxx . . $ kcapi_handle_tfm#tfmfd.);
954 kcapi_memset_securecxx . . $ kcapi_memset_secure(e37d57925061d5c9).(tfm, 0, sizeof(*tfm));
955 freecxx . . $ free(5d22bdacc48458e8).(tfm);
956 handle->tfmcxx . . $ kcapi_handle#tfm. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
957 }
958 }
959
960 void _kcapi_handle_destroycxx . . $ _kcapi_handle_destroy(aba29416d24fdd59).(struct kcapi_handlecxx . . $ kcapi_handle# *handle)
961 {
962 if (!handle)
963 return;
964 if (*_kcapi_get_opfdcxx . . $ _kcapi_get_opfd(f39930546eae134b).(handle) != -1)
965 closecxx . . $ close(7864480464b09eea).(*_kcapi_get_opfdcxx . . $ _kcapi_get_opfd(f39930546eae134b).(handle));
966 if (handle->pipescxx . . $ kcapi_handle#pipes.[0] != -1)
967 closecxx . . $ close(7864480464b09eea).(handle->pipescxx . . $ kcapi_handle#pipes.[0]);
968 if (handle->pipescxx . . $ kcapi_handle#pipes.[1] != -1)
969 closecxx . . $ close(7864480464b09eea).(handle->pipescxx . . $ kcapi_handle#pipes.[1]);
970 _kcapi_aio_destroycxx . . $ _kcapi_aio_destroy(aba29416d24fdd59).(handle);
971 _kcapi_handle_destroy_tfmcxx . . $ _kcapi_handle_destroy_tfm(aba29416d24fdd59).(handle);
972 kcapi_memset_securecxx . . $ kcapi_memset_secure(e37d57925061d5c9).(handle, 0, sizeof(struct kcapi_handlecxx . . $ kcapi_handle#));
973 freecxx . . $ free(5d22bdacc48458e8).(handle);
974 }
975
976 static int _kcapi_get_kernvercxx . . $ _kcapi_get_kernver(cad780c06c088da8).(struct kcapi_handlecxx . . $ kcapi_handle# *handle)
977 {
978 struct kcapi_handle_tfmcxx . . $ kcapi_handle_tfm# *tfm = handle->tfmcxx . . $ kcapi_handle#tfm.;
979 struct utsnamecxx . . $ utsname# kernel;
980 char *saveptr = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
981 char *res = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
982
983 if (unamecxx . . $ uname(c69a16225c55e184).(&kernel))
984 return -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
985
986 /* 3.15.0 */
987 res = strtok_rcxx . . $ strtok_r(a42394c85d6397dd).(kernel.releasecxx . . $ utsname#release., ".", &saveptr);
988 if (!res) {
989 printfcxx . . $ printf(581fddd72a8db8fc).("Could not parse kernel version");
990 return -EFAULTcxx . . $ `<external>/8987895939074593727/errno-base.h:18:9`!;
991 }
992 tfm->sysinfocxx . . $ kcapi_handle_tfm#sysinfo..kernel_majcxx . . $ kcapi_sys#kernel_maj. = strtoulcxx . . $ strtoul(31746e8d6ec49860).(res, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 10);
993 res = strtok_rcxx . . $ strtok_r(a42394c85d6397dd).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, ".", &saveptr);
994 if (!res) {
995 printfcxx . . $ printf(581fddd72a8db8fc).("Could not parse kernel version");
996 return -EFAULTcxx . . $ `<external>/8987895939074593727/errno-base.h:18:9`!;
997 }
998 tfm->sysinfocxx . . $ kcapi_handle_tfm#sysinfo..kernel_minorcxx . . $ kcapi_sys#kernel_minor. = strtoulcxx . . $ strtoul(31746e8d6ec49860).(res, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 10);
999 res = strtok_rcxx . . $ strtok_r(a42394c85d6397dd).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, ".", &saveptr);
1000 if (!res) {
1001 printfcxx . . $ printf(581fddd72a8db8fc).("Could not parse kernel version");
1002 return -EFAULTcxx . . $ `<external>/8987895939074593727/errno-base.h:18:9`!;
1003 }
1004 tfm->sysinfocxx . . $ kcapi_handle_tfm#sysinfo..kernel_patchlevelcxx . . $ kcapi_sys#kernel_patchlevel. = strtoulcxx . . $ strtoul(31746e8d6ec49860).(res, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 10);
1005
1006 return 0;
1007 }
1008
1009 /* return true if kernel is greater or equal to given values, otherwise false */
1010 static boolcxx . . $ bool# _kcapi_kernver_gecxx . . $ _kcapi_kernver_ge(5f64b5928f5a999a).(struct kcapi_handlecxx . . $ kcapi_handle# *handle, unsigned int maj,
1011 unsigned int minor, unsigned int patchlevel)
1012 {
1013 struct kcapi_handle_tfmcxx . . $ kcapi_handle_tfm# *tfm = handle->tfmcxx . . $ kcapi_handle#tfm.;
1014
1015 if (maj < tfm->sysinfocxx . . $ kcapi_handle_tfm#sysinfo..kernel_majcxx . . $ kcapi_sys#kernel_maj.)
1016 return truecxx . . $ true.;
1017 if (maj == tfm->sysinfocxx . . $ kcapi_handle_tfm#sysinfo..kernel_majcxx . . $ kcapi_sys#kernel_maj.) {
1018 if (minor < tfm->sysinfocxx . . $ kcapi_handle_tfm#sysinfo..kernel_minorcxx . . $ kcapi_sys#kernel_minor.)
1019 return truecxx . . $ true.;
1020 if (minor == tfm->sysinfocxx . . $ kcapi_handle_tfm#sysinfo..kernel_minorcxx . . $ kcapi_sys#kernel_minor.) {
1021 if (patchlevel <= tfm->sysinfocxx . . $ kcapi_handle_tfm#sysinfo..kernel_patchlevelcxx . . $ kcapi_sys#kernel_patchlevel.)
1022 return truecxx . . $ true.;
1023 }
1024 }
1025 return falsecxx . . $ false.;
1026 }
1027
1028 static int _kcapi_aio_initcxx . . $ _kcapi_aio_init(cad780c06c088da8).(struct kcapi_handlecxx . . $ kcapi_handle# *handle)
1029 {
1030 struct kcapi_handle_tfmcxx . . $ kcapi_handle_tfm# *tfm = handle->tfmcxx . . $ kcapi_handle#tfm.;
1031 uint32_tcxx . . $ uint32_t# i;
1032 int err;
1033
1034 if (tfm->infocxx . . $ kcapi_handle_tfm#info..cipher_typecxx . . $ kcapi_cipher_info#cipher_type. == KCAPI_CIPHER_AEADcxx . . $ KCAPI_CIPHER_AEAD.) {
1035 if (!_kcapi_kernver_gecxx . . $ _kcapi_kernver_ge(5f64b5928f5a999a).(handle, 4, 7, 0)) {
1036 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_VERBOSEcxx . . $ KCAPI_LOG_VERBOSE., "AIO support for AEAD cipher not present on current kernel");
1037 err = -EOPNOTSUPPcxx . . $ `<external>/17922322188510340118/errno.h:79:9`!;
1038 goto err;
1039 }
1040 }
1041 if (tfm->infocxx . . $ kcapi_handle_tfm#info..cipher_typecxx . . $ kcapi_cipher_info#cipher_type. == KCAPI_CIPHER_SKCIPHERcxx . . $ KCAPI_CIPHER_SKCIPHER.) {
1042 if (!_kcapi_kernver_gecxx . . $ _kcapi_kernver_ge(5f64b5928f5a999a).(handle, 4, 1, 0)) {
1043 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_VERBOSEcxx . . $ KCAPI_LOG_VERBOSE., "AIO support for symmetric ciphers not present on current kernel");
1044 err = -EOPNOTSUPPcxx . . $ `<external>/17922322188510340118/errno.h:79:9`!;
1045 goto err;
1046 }
1047 }
1048
1049 handle->aiocxx . . $ kcapi_handle#aio..ciocxx . . $ kcapi_aio#cio. = calloccxx . . $ calloc(63a7bf2941bfcd7a).(KCAPI_AIO_CONCURRENTcxx . . $ `lib/internal.h:186:9`!, sizeof(struct iocbcxx . . $ iocb#));
1050 if (!handle->aiocxx . . $ kcapi_handle#aio..ciocxx . . $ kcapi_aio#cio.) {
1051 err = -ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!;
1052 goto err;
1053 }
1054
1055 handle->aiocxx . . $ kcapi_handle#aio..cioppcxx . . $ kcapi_aio#ciopp. = calloccxx . . $ calloc(63a7bf2941bfcd7a).(KCAPI_AIO_CONCURRENTcxx . . $ `lib/internal.h:186:9`!, sizeof(void *));
1056 if (!handle->aiocxx . . $ kcapi_handle#aio..cioppcxx . . $ kcapi_aio#ciopp.) {
1057 err = -ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!;
1058 goto err;
1059 }
1060
1061 handle->aiocxx . . $ kcapi_handle#aio..iocb_retcxx . . $ kcapi_aio#iocb_ret. = calloccxx . . $ calloc(63a7bf2941bfcd7a).(KCAPI_AIO_CONCURRENTcxx . . $ `lib/internal.h:186:9`!, sizeof(__s64cxx . . $ __s64#));
1062 if (!handle->aiocxx . . $ kcapi_handle#aio..iocb_retcxx . . $ kcapi_aio#iocb_ret.) {
1063 err = -ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!;
1064 goto err;
1065 }
1066
1067 /*
1068 * Set up the pointers to pointers array that is required by
1069 * io_submit. Please do not ask me why the kernel wants this. :-)
1070 */
1071 for (i = 0; i < KCAPI_AIO_CONCURRENTcxx . . $ `lib/internal.h:186:9`!; i++)
1072 *(handle->aiocxx . . $ kcapi_handle#aio..cioppcxx . . $ kcapi_aio#ciopp. + i) = handle->aiocxx . . $ kcapi_handle#aio..ciocxx . . $ kcapi_aio#cio. + i;
1073
1074 handle->aiocxx . . $ kcapi_handle#aio..efdcxx . . $ kcapi_aio#efd. = eventfdcxx . . $ eventfd(1cb9ad283036edc7).(0, EFD_CLOEXECcxx . . $ `<external>/3759516248491290595/eventfd.h:28:9`!);
1075 if (handle->aiocxx . . $ kcapi_handle#aio..efdcxx . . $ kcapi_aio#efd. < 0) {
1076 err = -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
1077 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_ERRcxx . . $ KCAPI_LOG_ERR., "Event FD cannot be initialized: %d\n",
1078 err);
1079 goto err;
1080 }
1081
1082 err = io_setupcxx . . $ io_setup(f49cb1bdefccbb4a).(KCAPI_AIO_CONCURRENTcxx . . $ `lib/internal.h:186:9`!, &handle->aiocxx . . $ kcapi_handle#aio..aio_ctxcxx . . $ kcapi_aio#aio_ctx.);
1083 if (err < 0) {
1084 err = -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
1085 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_ERRcxx . . $ KCAPI_LOG_ERR., "io_setup error %d\n", err);
1086 goto err;
1087 }
1088
1089 handle->aiocxx . . $ kcapi_handle#aio..disablecxx . . $ kcapi_aio#disable. = falsecxx . . $ false.;
1090 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_VERBOSEcxx . . $ KCAPI_LOG_VERBOSE., "asynchronous I/O initialized");
1091
1092 return 0;
1093
1094 err:
1095 _kcapi_aio_destroycxx . . $ _kcapi_aio_destroy(aba29416d24fdd59).(handle);
1096
1097 return err;
1098 }
1099
1100 static void _kcapi_handle_flagscxx . . $ _kcapi_handle_flags(aba29416d24fdd59).(struct kcapi_handlecxx . . $ kcapi_handle# *handle)
1101 {
1102 /* new memory structure for AF_ALG AEAD interface + fixed hashing empty input */
1103 handle->flagscxx . . $ kcapi_handle#flags..ge_v4_9cxx . . $ kcapi_flags#ge_v4_9. = _kcapi_kernver_gecxx . . $ _kcapi_kernver_ge(5f64b5928f5a999a).(handle, 4, 9, 0);
1104
1105 /* older interfaces only processed 16 pages in a row */
1106 handle->flagscxx . . $ kcapi_handle#flags..alg_max_pagescxx . . $ kcapi_flags#alg_max_pages. = ALG_MAX_PAGEScxx . . $ `lib/internal.h:93:9`!;
1107 }
1108
1109 static int _kcapi_handle_alloccxx . . $ _kcapi_handle_alloc(8651dacfa3a789ad).(struct kcapi_handlecxx . . $ kcapi_handle# **caller)
1110 {
1111 struct kcapi_handlecxx . . $ kcapi_handle# *handle = calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(struct kcapi_handlecxx . . $ kcapi_handle#));
1112
1113 if (!handle)
1114 return -ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!;
1115
1116 *_kcapi_get_opfdcxx . . $ _kcapi_get_opfd(f39930546eae134b).(handle) = -1;
1117 handle->pipescxx . . $ kcapi_handle#pipes.[0] = -1;
1118 handle->pipescxx . . $ kcapi_handle#pipes.[1] = -1;
1119 handle->aiocxx . . $ kcapi_handle#aio..efdcxx . . $ kcapi_aio#efd. = -1;
1120 handle->pagesizecxx . . $ kcapi_handle#pagesize. = (unsigned int)sysconfcxx . . $ sysconf(dc1f09c09fbff20f).(_SC_PAGESIZEcxx . . $ `<external>/6393649343499073842/confname.h:134:9`!);
1121
1122 *caller = handle;
1123
1124 return 0;
1125 }
1126
1127 static int _kcapi_handle_init_opcxx . . $ _kcapi_handle_init_op(8327ae3352751b56).(struct kcapi_handlecxx . . $ kcapi_handle# *handle, uint32_tcxx . . $ uint32_t# flags)
1128 {
1129 int ret;
1130
1131 ret = pipecxx . . $ pipe(a5f7824ee4986326).(handle->pipescxx . . $ kcapi_handle#pipes.);
1132 if (ret) {
1133 ret = -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
1134 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_ERRcxx . . $ KCAPI_LOG_ERR.,
1135 "AF_ALG: pipe syscall failed (errno: %d)",
1136 ret);
1137 return ret;
1138 }
1139
1140 /*
1141 * For vmsplice to allow the maximum number of 16 pages, we need to
1142 * increase the pipe buffer by one more page - it seems the kernel
1143 * uses some parts of the pipe for some house-keeping?!
1144 */
1145 ret = kcapi_set_maxsplicesizecxx . . $ kcapi_set_maxsplicesize(8327ae3352751b56).(handle,
1146 handle->pagesizecxx . . $ kcapi_handle#pagesize. * (ALG_MAX_PAGEScxx . . $ `lib/internal.h:93:9`! + 1));
1147 if (ret < 0) {
1148 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_WARNcxx . . $ KCAPI_LOG_WARN.,
1149 "AF_ALG: setting maximum buffer size failed: %d)",
1150 ret);
1151 ret = kcapi_get_maxsplicesizecxx . . $ kcapi_get_maxsplicesize(cad780c06c088da8).(handle);
1152 if (ret < 0)
1153 return ret;
1154
1155 }
1156 ret = 0;
1157 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG., "AF_ALG: pipe syscall passed");
1158
1159 if (flags & KCAPI_INIT_AIOcxx . . $ `lib/kcapi.h:53:9`!) {
1160 ret = _kcapi_aio_initcxx . . $ _kcapi_aio_init(cad780c06c088da8).(handle);
1161
1162 /*
1163 * We complain about kernels without AIO support, but allow
1164 * the allocation nonetheless as we have synchronous fallbacks
1165 * for all AIO implementations. This allows the use of
1166 * libkcapi AIO API even though the kernel does not support it.
1167 * This allows compatibility for applications.
1168 */
1169 if (ret && ret != -EOPNOTSUPPcxx . . $ `<external>/17922322188510340118/errno.h:79:9`!)
1170 return ret;
1171 ret = 0;
1172 } else
1173 handle->aiocxx . . $ kcapi_handle#aio..disablecxx . . $ kcapi_aio#disable. = truecxx . . $ true.;
1174
1175 _kcapi_handle_flagscxx . . $ _kcapi_handle_flags(aba29416d24fdd59).(handle);
1176
1177 return ret;
1178 }
1179
1180 static int _kcapi_handle_init_tfmcxx . . $ _kcapi_handle_init_tfm(74331eb76376022f).(struct kcapi_handlecxx . . $ kcapi_handle# *handle, const char *type,
1181 const char *ciphername)
1182 {
1183 struct kcapi_handle_tfmcxx . . $ kcapi_handle_tfm# *tfm = handle->tfmcxx . . $ kcapi_handle#tfm.;
1184 struct sockaddr_algcxx . . $ sockaddr_alg# sa;
1185 int ret;
1186 char versionbuffer[50];
1187
1188 kcapi_versionstringcxx . . $ kcapi_versionstring(2ae3250752bf8d86).(versionbuffer, sizeof(versionbuffer));
1189 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_VERBOSEcxx . . $ KCAPI_LOG_VERBOSE.,
1190 "%s - initializing cipher operation with kernel",
1191 versionbuffer);
1192
1193 tfm->tfmfdcxx . . $ kcapi_handle_tfm#tfmfd. = -1;
1194 atomic_setcxx . . $ atomic_set(d9e8d0a15ff6fbc8).(1, &tfm->refcntcxx . . $ kcapi_handle_tfm#refcnt.);
1195
1196 ret = _kcapi_get_kernvercxx . . $ _kcapi_get_kernver(cad780c06c088da8).(handle);
1197 if (ret)
1198 return ret;
1199
1200 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&sa, 0, sizeof(sa));
1201 sa.salg_familycxx . . $ sockaddr_alg#salg_family. = AF_ALGcxx . . $ `<external>/8962547315054503424/socket.h:134:9`!;
1202 snprintfcxx . . $ snprintf(ea502d73e74c754c).((char *)sa.salg_typecxx . . $ sockaddr_alg#salg_type., sizeof(sa.salg_typecxx . . $ sockaddr_alg#salg_type.),"%s", type);
1203 snprintfcxx . . $ snprintf(ea502d73e74c754c).((char *)sa.salg_namecxx . . $ sockaddr_alg#salg_name., sizeof(sa.salg_namecxx . . $ sockaddr_alg#salg_name.),"%s", ciphername);
1204
1205 tfm->tfmfdcxx . . $ kcapi_handle_tfm#tfmfd. = socketcxx . . $ socket(2326284602b0bb2d).(AF_ALGcxx . . $ `<external>/8962547315054503424/socket.h:134:9`!, SOCK_SEQPACKETcxx . . $ `<external>/5956532346368192945/socket_type.h:38:9`!, 0);
1206 if (tfm->tfmfdcxx . . $ kcapi_handle_tfm#tfmfd. == -1) {
1207 ret = -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
1208 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_ERRcxx . . $ KCAPI_LOG_ERR.,
1209 "AF_ALG: socket syscall failed (errno: %d)",
1210 ret);
1211 return ret;
1212 }
1213 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG., "AF_ALG: socket syscall passed");
1214
1215 if (bindcxx . . $ bind(f39c6c650450bfdd).(tfm->tfmfdcxx . . $ kcapi_handle_tfm#tfmfd., (struct sockaddrcxx . . $ sockaddr# *)&sa, sizeof(sa)) == -1) {
1216 ret = -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
1217 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_ERRcxx . . $ KCAPI_LOG_ERR., "AF_ALG: bind failed (errno: %d)",
1218 ret);
1219 return ret;
1220 }
1221 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_DEBUGcxx . . $ KCAPI_LOG_DEBUG., "AF_ALG: bind syscall passed");
1222
1223 ret = _kcapi_common_getinfocxx . . $ _kcapi_common_getinfo(bb2abbec6f9f0bc9).(handle, ciphername);
1224 if (ret) {
1225 ret = -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
1226 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_ERRcxx . . $ KCAPI_LOG_ERR., "NETLINK_CRYPTO: cannot obtain cipher information for %s (is required crypto_user.c patch missing? see documentation)",
1227 ciphername);
1228 return ret;
1229 }
1230
1231 return 0;
1232 }
1233
1234 int _kcapi_handle_initcxx . . $ _kcapi_handle_init(db986b7fadb21840).(struct kcapi_handlecxx . . $ kcapi_handle# **caller, const char *type,
1235 const char *ciphername, uint32_tcxx . . $ uint32_t# flags)
1236 {
1237 struct kcapi_handlecxx . . $ kcapi_handle# *handle;
1238 struct kcapi_handle_tfmcxx . . $ kcapi_handle_tfm# *tfm;
1239 int ret;
1240
1241 ret = _kcapi_handle_alloccxx . . $ _kcapi_handle_alloc(8651dacfa3a789ad).(&handle);
1242 if (ret)
1243 return ret;
1244
1245 tfm = calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(struct kcapi_handle_tfmcxx . . $ kcapi_handle_tfm#));
1246 if (!tfm) {
1247 freecxx . . $ free(5d22bdacc48458e8).(handle);
1248 return -ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!;
1249 }
1250
1251 handle->tfmcxx . . $ kcapi_handle#tfm. = tfm;
1252
1253 ret = _kcapi_handle_init_tfmcxx . . $ _kcapi_handle_init_tfm(74331eb76376022f).(handle, type, ciphername);
1254 if (ret)
1255 goto err;
1256
1257 ret = _kcapi_handle_init_opcxx . . $ _kcapi_handle_init_op(8327ae3352751b56).(handle, flags);
1258 if (ret)
1259 goto err;
1260
1261 *caller = handle;
1262
1263 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_VERBOSEcxx . . $ KCAPI_LOG_VERBOSE.,
1264 "communication for %s with kernel initialized",
1265 ciphername);
1266
1267 return 0;
1268
1269 err:
1270 _kcapi_handle_destroycxx . . $ _kcapi_handle_destroy(aba29416d24fdd59).(handle);
1271 return ret;
1272 }
1273
1274 int kcapi_handle_reinitcxx . . $ kcapi_handle_reinit(9b16b5b23042e58d).(struct kcapi_handlecxx . . $ kcapi_handle# **newhandle,
1275 struct kcapi_handlecxx . . $ kcapi_handle# *existing, uint32_tcxx . . $ uint32_t# flags)
1276 {
1277 struct kcapi_handlecxx . . $ kcapi_handle# *handle;
1278 int ret;
1279
1280 ret = _kcapi_handle_alloccxx . . $ _kcapi_handle_alloc(8651dacfa3a789ad).(&handle);
1281 if (ret)
1282 return ret;
1283
1284 if (!existing || !existing->tfmcxx . . $ kcapi_handle#tfm.) {
1285 ret = -EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!;
1286 goto err;
1287 }
1288
1289 atomic_inccxx . . $ atomic_inc(3e4ce074a99d0a0f).(&existing->tfmcxx . . $ kcapi_handle#tfm.->refcntcxx . . $ kcapi_handle_tfm#refcnt.);
1290 handle->tfmcxx . . $ kcapi_handle#tfm. = existing->tfmcxx . . $ kcapi_handle#tfm.;
1291
1292 ret = _kcapi_handle_init_opcxx . . $ _kcapi_handle_init_op(8327ae3352751b56).(handle, flags);
1293 if (ret)
1294 goto err;
1295
1296 *newhandle = handle;
1297
1298 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_VERBOSEcxx . . $ KCAPI_LOG_VERBOSE.,
1299 "new cipher handle from existing handle initialized");
1300
1301 return 0;
1302
1303 err:
1304 _kcapi_handle_destroycxx . . $ _kcapi_handle_destroy(aba29416d24fdd59).(handle);
1305 return ret;
1306 }
1307
1308 ssize_tcxx . . $ ssize_t# _kcapi_cipher_cryptcxx . . $ _kcapi_cipher_crypt(8a744cecfacfebd9).(struct kcapi_handlecxx . . $ kcapi_handle# *handle, const uint8_tcxx . . $ uint8_t# *in,
1309 size_t inlen, uint8_tcxx . . $ uint8_t# *out, size_t outlen,
1310 int access, unsigned int enc)
1311 {
1312 struct ioveccxx . . $ iovec# iov;
1313 ssize_tcxx . . $ ssize_t# ret = 0;
1314
1315 if (outlen > INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!)
1316 return -EMSGSIZEcxx . . $ `<external>/17922322188510340118/errno.h:74:9`!;
1317
1318 /*
1319 * Using two syscalls with memcpy is faster than four syscalls
1320 * without memcpy below the given threshold.
1321 */
1322 if ((access == KCAPI_ACCESS_HEURISTICcxx . . $ `lib/kcapi.h:44:9`! && inlen <= (1<<13)) ||
1323 access == KCAPI_ACCESS_SENDMSGcxx . . $ `lib/kcapi.h:46:9`!) {
1324 iov.iov_basecxx . . $ iovec#iov_base. = (void*)(uintptr_tcxx . . $ uintptr_t#)in;
1325 iov.iov_lencxx . . $ iovec#iov_len. = inlen;
1326 ret = _kcapi_common_send_metacxx . . $ _kcapi_common_send_meta(f4e40828a4f4c91f).(handle, &iov, 1, enc, 0);
1327 if (0 > ret)
1328 return ret;
1329 } else {
1330 ret = _kcapi_common_send_metacxx . . $ _kcapi_common_send_meta(f4e40828a4f4c91f).(handle, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0, enc, MSG_MOREcxx . . $ `<external>/8962547315054503424/socket.h:244:9`!);
1331 if (0 > ret)
1332 return ret;
1333 ret = _kcapi_common_vmsplice_chunkcxx . . $ _kcapi_common_vmsplice_chunk(1f8f8f1822879a).(handle, in, inlen, 0);
1334 if (0 > ret)
1335 return ret;
1336 }
1337
1338 return _kcapi_common_read_datacxx . . $ _kcapi_common_read_data(e37e70272ed35378).(handle, out, outlen);
1339 }
1340
1341 ssize_tcxx . . $ ssize_t# _kcapi_cipher_crypt_chunkcxx . . $ _kcapi_cipher_crypt_chunk(8a744cecfacfebd9).(struct kcapi_handlecxx . . $ kcapi_handle# *handle,
1342 const uint8_tcxx . . $ uint8_t# *in, size_t inlen,
1343 uint8_tcxx . . $ uint8_t# *out, size_t outlen,
1344 int access, unsigned int enc)
1345 {
1346 ssize_tcxx . . $ ssize_t# totallen = 0;
1347 size_t maxprocess = handle->pagesizecxx . . $ kcapi_handle#pagesize. * ALG_MAX_PAGEScxx . . $ `lib/internal.h:93:9`!;
1348 ssize_tcxx . . $ ssize_t# ret;
1349
1350 if (outlen > INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!)
1351 return -EMSGSIZEcxx . . $ `<external>/17922322188510340118/errno.h:74:9`!;
1352
1353 while (inlen && outlen) {
1354 size_t inprocess = inlen;
1355 size_t outprocess = outlen;
1356
1357 /*
1358 * We do not check that sysconf(_SC_PAGESIZE) * ALG_MAX_PAGES is
1359 * a multiple of blocksize, because we assume that this is
1360 * always the case.
1361 */
1362 if (inlen > maxprocess)
1363 inprocess = maxprocess;
1364 if (outlen > maxprocess)
1365 outprocess = maxprocess;
1366
1367 ret = _kcapi_cipher_cryptcxx . . $ _kcapi_cipher_crypt(8a744cecfacfebd9).(handle, in, inprocess, out,
1368 outprocess, access, enc);
1369 if (ret < 0)
1370 return ret;
1371
1372 totallen += (ssize_tcxx . . $ ssize_t#)inprocess;
1373 in += inprocess;
1374 inlen -= inprocess;
1375 out += ret;
1376 outlen -= (uint32_tcxx . . $ uint32_t#)ret;
1377 }
1378
1379 return totallen;
1380 }
1381
1382 ssize_tcxx . . $ ssize_t# _kcapi_cipher_crypt_aiocxx . . $ _kcapi_cipher_crypt_aio(2eaa747523f18d63).(struct kcapi_handlecxx . . $ kcapi_handle# *handle,
1383 struct ioveccxx . . $ iovec# *iniov, struct ioveccxx . . $ iovec# *outiov,
1384 size_t iovlen, int access, unsigned int enc)
1385 {
1386 size_t i, outstanding = 0, processed = 0, inflight = 0;
1387 ssize_tcxx . . $ ssize_t# ret;
1388
1389 if (handle->aiocxx . . $ kcapi_handle#aio..disablecxx . . $ kcapi_aio#disable. == truecxx . . $ true.) {
1390 kcapi_dologcxx . . $ kcapi_dolog(5f46d8f16dd28dce).(KCAPI_LOG_WARNcxx . . $ KCAPI_LOG_WARN., "AIO support disabled\n");
1391 return -EOPNOTSUPPcxx . . $ `<external>/17922322188510340118/errno.h:79:9`!;
1392 }
1393
1394 /* Every IOVEC is processed as its individual cipher operation. */
1395 while (iovlen) {
1396 size_t max_process = KCAPI_AIO_CONCURRENTcxx . . $ `lib/internal.h:186:9`! - inflight;
1397 size_t process = (max_process < iovlen) ?
1398 max_process : iovlen;
1399
1400 ret = _kcapi_aio_send_iovcxx . . $ _kcapi_aio_send_iov(b8e608a74ce2f87d).(handle, iniov, process, access, enc);
1401 if (ret < 0)
1402 return ret;
1403
1404 ret = _kcapi_aio_read_iovcxx . . $ _kcapi_aio_read_iov(b78c7fa11dfbc2b0).(handle, outiov, process);
1405 if (ret < 0)
1406 return ret;
1407
1408 iniov += process;
1409 outiov += process;
1410 iovlen -= process;
1411
1412 inflight = 0;
1413 for (i = 0; i < KCAPI_AIO_CONCURRENTcxx . . $ `lib/internal.h:186:9`!; i++) {
1414 if (handle->aiocxx . . $ kcapi_handle#aio..iocb_retcxx . . $ kcapi_aio#iocb_ret.[i] == AIO_OUTSTANDINGcxx . . $ `lib/internal.h:197:9`!) {
1415 inflight++;
1416 } else if (handle->aiocxx . . $ kcapi_handle#aio..iocb_retcxx . . $ kcapi_aio#iocb_ret.[i] < 0) {
1417 return (int32_tcxx . . $ int32_t#)handle->aiocxx . . $ kcapi_handle#aio..iocb_retcxx . . $ kcapi_aio#iocb_ret.[i];
1418 } else {
1419 if (handle->aiocxx . . $ kcapi_handle#aio..iocb_retcxx . . $ kcapi_aio#iocb_ret.[i] > INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!)
1420 return -EOVERFLOWcxx . . $ `<external>/17922322188510340118/errno.h:59:9`!;
1421
1422 processed += (uint32_tcxx . . $ uint32_t#)handle->aiocxx . . $ kcapi_handle#aio..iocb_retcxx . . $ kcapi_aio#iocb_ret.[i];
1423 if (processed > INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!)
1424 return -EOVERFLOWcxx . . $ `<external>/17922322188510340118/errno.h:59:9`!;
1425 handle->aiocxx . . $ kcapi_handle#aio..iocb_retcxx . . $ kcapi_aio#iocb_ret.[i] = 0;
1426 }
1427 }
1428 }
1429
1430 /*
1431 * If a multi-staged AIO operation shall be designed, the following
1432 * loop needs to be moved to a closing API call. If done so, the
1433 * current function could be invoked multiple times to send more data
1434 * to the kernel before the closing call requires that all outstanding
1435 * requests are to be completed.
1436 *
1437 * If a multi-staged AIO operation is to be implemented, the issue
1438 * is that when submitting a number of requests, the caller is not
1439 * able to detect which particular request is completed. Thus, an
1440 * "open-ended" multi-staged AIO operation could not be implemented.
1441 */
1442 for (i = 0; i < KCAPI_AIO_CONCURRENTcxx . . $ `lib/internal.h:186:9`!; i++) {
1443 if (handle->aiocxx . . $ kcapi_handle#aio..iocb_retcxx . . $ kcapi_aio#iocb_ret.[i] == AIO_OUTSTANDINGcxx . . $ `lib/internal.h:197:9`!)
1444 outstanding++;
1445 }
1446
1447 ret = _kcapi_aio_read_allcxx . . $ _kcapi_aio_read_all(98d83b17fa6c06b3).(handle, outstanding, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
1448 if (ret < 0)
1449 return ret;
1450
1451 for (i = 0; i < KCAPI_AIO_CONCURRENTcxx . . $ `lib/internal.h:186:9`!; i++) {
1452 if (handle->aiocxx . . $ kcapi_handle#aio..iocb_retcxx . . $ kcapi_aio#iocb_ret.[i] == AIO_OUTSTANDINGcxx . . $ `lib/internal.h:197:9`!) {
1453 return -EBADMSGcxx . . $ `<external>/17922322188510340118/errno.h:57:9`!;
1454 } else if (handle->aiocxx . . $ kcapi_handle#aio..iocb_retcxx . . $ kcapi_aio#iocb_ret.[i] < 0) {
1455 return (int32_tcxx . . $ int32_t#)handle->aiocxx . . $ kcapi_handle#aio..iocb_retcxx . . $ kcapi_aio#iocb_ret.[i];
1456 } else {
1457 if (handle->aiocxx . . $ kcapi_handle#aio..iocb_retcxx . . $ kcapi_aio#iocb_ret.[i] > INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!)
1458 return -EOVERFLOWcxx . . $ `<external>/17922322188510340118/errno.h:59:9`!;
1459
1460 processed += (uint32_tcxx . . $ uint32_t#)handle->aiocxx . . $ kcapi_handle#aio..iocb_retcxx . . $ kcapi_aio#iocb_ret.[i];
1461 if (processed > INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!)
1462 return -EOVERFLOWcxx . . $ `<external>/17922322188510340118/errno.h:59:9`!;
1463 handle->aiocxx . . $ kcapi_handle#aio..iocb_retcxx . . $ kcapi_aio#iocb_ret.[i] = 0;
1464 }
1465 }
1466 return (ssize_tcxx . . $ ssize_t#)processed;
1467 }