xref: /OK3568_Linux_fs/kernel/include/uapi/linux/rk_cryptodev.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: ((GPL-2.0+ WITH Linux-syscall-note) OR MIT) */
2 /*
3  * Copyright (C) 2021 Rockchip Electronics Co., Ltd.
4  */
5 
6 #ifndef _UAPI_RK_CRYPTODEV_H
7 #define _UAPI_RK_CRYPTODEV_H
8 
9 #include <linux/types.h>
10 #include <linux/version.h>
11 
12 #ifndef __KERNEL__
13 #define __user
14 #endif
15 
16 /* input of RIOCCRYPT_FD */
17 struct crypt_fd_op {
18 	__u32	ses;		/* session identifier */
19 	__u16	op;		/* COP_ENCRYPT or COP_DECRYPT */
20 	__u16	flags;		/* see COP_FLAG_* */
21 	__u32	len;		/* length of source data */
22 	int	src_fd;		/* source data */
23 	int	dst_fd;		/* pointer to output data */
24 	/* pointer to output data for hash/MAC operations */
25 	__u8	__user *mac;
26 	/* initialization vector for encryption operations */
27 	__u8	__user *iv;
28 };
29 
30 /* input of RIOCAUTHCRYPT_FD */
31 struct crypt_auth_fd_op {
32 	__u32	ses;			/* session identifier */
33 	__u16	op;			/* COP_ENCRYPT or COP_DECRYPT */
34 	__u16	flags;			/* see COP_FLAG_AEAD_* */
35 	__u32	len;			/* length of source data */
36 	__u32	auth_len;		/* length of auth data */
37 	int	auth_fd;		/* authenticated-only data */
38 	int	src_fd;			/* source data */
39 	int	dst_fd;			/* pointer to output data */
40 	__u64	tag;
41 	__u32	tag_len;		/* the length of the tag. Use zero for digest size or max
42 					 * tag.
43 					 */
44 	__u64	iv;			/* initialization vector for encryption operations */
45 	__u32   iv_len;
46 };
47 
48 /* input of RIOCCRYPT_FD_MAP/RIOCCRYPT_FD_UNMAP */
49 struct crypt_fd_map_op {
50 	int	dma_fd;		/* session identifier */
51 	__u32	phys_addr;	/* physics addr */
52 };
53 
54 #define AOP_ENCRYPT	0
55 #define AOP_DECRYPT	1
56 
57 #define COP_FLAG_RSA_PUB	(0 << 8) /* decode as rsa pub key */
58 #define COP_FLAG_RSA_PRIV	(1 << 8) /* decode as rsa priv key */
59 
60 #define RK_RSA_BER_KEY_MAX	8192	/* The key encoded by ber does not exceed 8K Byte */
61 #define RK_RSA_KEY_MAX_BITS	4096
62 #define RK_RSA_KEY_MAX_BYTES	(RK_RSA_KEY_MAX_BITS / 8)
63 
64 /* input of RIOCCRYPT_RSA_CRYPT */
65 struct crypt_rsa_op {
66 	__u16		op;		/* AOP_ENCRYPT/AOP_DECRYPT */
67 	__u16		flags;		/* see COP_FLAG_* */
68 	__u8		reserve[4];
69 	__u64		key;		/* BER coding RSA key */
70 	__u64		in;		/* pointer to input data */
71 	__u64		out;		/* pointer to output data */
72 	__u32		key_len;	/* length of key data */
73 	__u32		in_len;		/* length of input data */
74 	__u32		out_len;	/* length of output data */
75 };
76 
77 #define RIOCCRYPT_FD		_IOWR('r', 104, struct crypt_fd_op)
78 #define RIOCCRYPT_FD_MAP	_IOWR('r', 105, struct crypt_fd_map_op)
79 #define RIOCCRYPT_FD_UNMAP	_IOW('r',  106, struct crypt_fd_map_op)
80 #define RIOCCRYPT_CPU_ACCESS	_IOW('r',  107, struct crypt_fd_map_op)
81 #define RIOCCRYPT_DEV_ACCESS	_IOW('r',  108, struct crypt_fd_map_op)
82 #define RIOCCRYPT_RSA_CRYPT	_IOWR('r', 109, struct crypt_rsa_op)
83 #define RIOCAUTHCRYPT_FD	_IOWR('r', 110, struct crypt_auth_fd_op)
84 
85 #endif
86