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 tag. */ 42 __u64 iv; /* initialization vector for encryption operations */ 43 __u32 iv_len; 44 }; 45 46 /* input of RIOCCRYPT_FD_MAP/RIOCCRYPT_FD_UNMAP */ 47 struct crypt_fd_map_op { 48 int dma_fd; /* session identifier */ 49 __u32 phys_addr; /* physics addr */ 50 }; 51 52 #define AOP_ENCRYPT 0 53 #define AOP_DECRYPT 1 54 55 #define COP_FLAG_RSA_PUB (0 << 8) /* decode as rsa pub key */ 56 #define COP_FLAG_RSA_PRIV (1 << 8) /* decode as rsa priv key */ 57 58 #define RK_RSA_BER_KEY_MAX 8192 /* The key encoded by ber does not exceed 8K Byte */ 59 #define RK_RSA_KEY_MAX_BITS 4096 60 #define RK_RSA_KEY_MAX_BYTES (RK_RSA_KEY_MAX_BITS / 8) 61 62 /* input of RIOCCRYPT_RSA_CRYPT */ 63 struct crypt_rsa_op { 64 __u16 op; /* AOP_ENCRYPT/AOP_DECRYPT */ 65 __u16 flags; /* see COP_FLAG_* */ 66 __u8 reserve[4]; 67 __u64 key; /* BER coding RSA key */ 68 __u64 in; /* pointer to input data */ 69 __u64 out; /* pointer to output data */ 70 __u32 key_len; /* length of key data */ 71 __u32 in_len; /* length of input data */ 72 __u32 out_len; /* length of output data */ 73 }; 74 75 #define RIOCCRYPT_FD _IOWR('r', 104, struct crypt_fd_op) 76 #define RIOCCRYPT_FD_MAP _IOWR('r', 105, struct crypt_fd_map_op) 77 #define RIOCCRYPT_FD_UNMAP _IOW('r', 106, struct crypt_fd_map_op) 78 #define RIOCCRYPT_CPU_ACCESS _IOW('r', 107, struct crypt_fd_map_op) 79 #define RIOCCRYPT_DEV_ACCESS _IOW('r', 108, struct crypt_fd_map_op) 80 #define RIOCCRYPT_RSA_CRYPT _IOWR('r', 109, struct crypt_rsa_op) 81 #define RIOCAUTHCRYPT_FD _IOWR('r', 110, struct crypt_auth_fd_op) 82 83 #endif 84