@samitouri / QOSamiQemu / commits / fe68cc8e0b

bsd-user: Add FreeBSD cryptodev ioctl definitions

Add os-ioctl-cryptodev.h with /dev/crypto ioctl definitions including CIOCGSESSION, CIOCCRYPT, and related cryptographic device control ioctls. Signed-off-by: Stacey Son <sson@FreeBSD.org> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com> Signed-off-by: Warner Losh <imp@bsdimp.com>

Stacey Son committed Mar 13, 2026 at 22:12 UTC fe68cc8e0b5e1f51a07537caf06498f84302ff3c
1 file changed +84
bsd-user/freebsd/os-ioctl-cryptodev.h new
+84
@@ -0,0 +1,84 @@
1 +/*
2 + * FreeBSD cryptodev definitions for ioctl(2) emulation
3 + *
4 + * Copyright (c) 2014 Stacey D. Son
5 + *
6 + * SPDX-License-Identifier: GPL-2.0-or-later
7 + */
8 +#ifndef BSD_USER_FREEBSD_OS_IOCTL_CRYPTODEV_H
9 +#define BSD_USER_FREEBSD_OS_IOCTL_CRYPTODEV_H
10 +
11 +/* see opencrypto/cryptodev.h */
12 +
13 +struct target_session_op {
14 + u_int32_t cipher;
15 + u_int32_t mac;
16 +
17 + u_int32_t keylen;
18 + abi_ulong key;
19 + int32_t mackeylen;
20 + abi_ulong mackey;
21 +
22 + u_int32_t ses;
23 +};
24 +
25 +
26 +struct target_session2_op {
27 + u_int32_t cipher;
28 + u_int32_t mac;
29 +
30 + u_int32_t keylen;
31 + abi_ulong key;
32 + int32_t mackeylen;
33 + abi_ulong mackey;
34 +
35 + u_int32_t ses;
36 + int32_t crid;
37 + abi_int ivlen;
38 + abi_int maclen;
39 + abi_int pad[2];
40 +};
41 +
42 +struct target_crypt_op {
43 + uint32_t ses;
44 + uint16_t op; /* i.e. COP_ENCRYPT */
45 +#define TARGET_COP_ENCRYPT 1
46 +#define TARGET_COP_DECRYPT 2
47 + uint16_t flags;
48 +#define TARGET_COP_F_CIPHER_FIRST 0x0001 /* Cipher before MAC. */
49 +#define TARGET_COP_F_BATCH 0x0008 /* Batch op if possible */
50 + abi_uint len;
51 + abi_ulong src; /* become iov[] inside kernel */
52 + abi_ulong dst;
53 + abi_ulong mac; /* must be big enough for chosen MAC */
54 + abi_ulong iv;
55 +};
56 +
57 +/* op and flags the same as crypt_op */
58 +struct target_crypt_aead {
59 + uint32_t ses;
60 + uint16_t op; /* i.e. COP_ENCRYPT */
61 + uint16_t flags;
62 + abi_uint len;
63 + abi_uint aadlen;
64 + abi_uint ivlen;
65 + abi_ulong src; /* become iov[] inside kernel */
66 + abi_ulong dst;
67 + abi_ulong aad; /* additional authenticated data */
68 + abi_ulong tag; /* must fit for chosen TAG length */
69 + abi_ulong iv;
70 +};
71 +
72 +struct target_crypt_find_op {
73 + abi_int crid;
74 + char name[32];
75 +};
76 +
77 +#define TARGET_CIOCGSESSION TARGET_IOWR('c', 101, struct target_session_op)
78 +#define TARGET_CIOCFSESSION TARGET_IOW('c', 102, u_int32_t)
79 +#define TARGET_CIOCCRYPT TARGET_IOWR('c', 103, struct target_crypt_op)
80 +#define TARGET_CIOCGSESSION2 TARGET_IOWR('c', 106, struct target_session2_op)
81 +#define TARGET_CIOCFINDDEV TARGET_IOWR('c', 108, struct target_crypt_find_op)
82 +#define TARGET_CIOCCRYPTAEAD TARGET_IOWR('c', 109, struct target_crypt_aead)
83 +
84 +#endif /* BSD_USER_FREEBSD_OS_IOCTL_CRYPTODEV_H */