1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or https://opensource.org/licenses/CDDL-1.0. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 23 */ 24 /* 25 * Copyright 2013 Saso Kiselkov. All rights reserved. 26 */ 27 28 #ifndef _SYS_CRYPTO_COMMON_H 29 #define _SYS_CRYPTO_COMMON_H 30 31 /* 32 * Header file for the common data structures of the cryptographic framework 33 */ 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 #include <sys/zfs_context.h> 40 41 /* Cryptographic Mechanisms */ 42 43 #define CRYPTO_MAX_MECH_NAME 32 44 typedef char crypto_mech_name_t[CRYPTO_MAX_MECH_NAME]; 45 46 typedef uint64_t crypto_mech_type_t; 47 48 typedef struct crypto_mechanism { 49 crypto_mech_type_t cm_type; /* mechanism type */ 50 caddr_t cm_param; /* mech. parameter */ 51 size_t cm_param_len; /* mech. parameter len */ 52 } crypto_mechanism_t; 53 54 /* CK_AES_CCM_PARAMS provides parameters to the CKM_AES_CCM mechanism */ 55 typedef struct CK_AES_CCM_PARAMS { 56 ulong_t ulMACSize; 57 ulong_t ulNonceSize; 58 ulong_t ulAuthDataSize; 59 ulong_t ulDataSize; /* used for plaintext or ciphertext */ 60 uchar_t *nonce; 61 uchar_t *authData; 62 } CK_AES_CCM_PARAMS; 63 64 /* CK_AES_GCM_PARAMS provides parameters to the CKM_AES_GCM mechanism */ 65 typedef struct CK_AES_GCM_PARAMS { 66 uchar_t *pIv; 67 ulong_t ulIvLen; 68 ulong_t ulIvBits; 69 uchar_t *pAAD; 70 ulong_t ulAADLen; 71 ulong_t ulTagBits; 72 } CK_AES_GCM_PARAMS; 73 74 /* 75 * The measurement unit bit flag for a mechanism's minimum or maximum key size. 76 * The unit are mechanism dependent. It can be in bits or in bytes. 77 */ 78 typedef uint32_t crypto_keysize_unit_t; 79 80 81 /* Mechanisms supported out-of-the-box */ 82 #define SUN_CKM_SHA512_HMAC "CKM_SHA512_HMAC" 83 #define SUN_CKM_AES_CCM "CKM_AES_CCM" 84 #define SUN_CKM_AES_GCM "CKM_AES_GCM" 85 86 /* Data arguments of cryptographic operations */ 87 88 typedef enum crypto_data_format { 89 CRYPTO_DATA_RAW = 1, 90 CRYPTO_DATA_UIO, 91 } crypto_data_format_t; 92 93 typedef struct crypto_data { 94 crypto_data_format_t cd_format; /* Format identifier */ 95 off_t cd_offset; /* Offset from the beginning */ 96 size_t cd_length; /* # of bytes in use */ 97 union { 98 /* Raw format */ 99 iovec_t cd_raw; /* Pointer and length */ 100 101 /* uio scatter-gather format */ 102 zfs_uio_t *cd_uio; 103 }; /* Crypto Data Union */ 104 } crypto_data_t; 105 106 /* The keys, and their contents */ 107 108 typedef struct { 109 uint_t ck_length; /* # of bits in ck_data */ 110 void *ck_data; /* ptr to key value */ 111 } crypto_key_t; 112 113 /* 114 * Raw key lengths are expressed in number of bits. 115 * The following macro returns the minimum number of 116 * bytes that can contain the specified number of bits. 117 * Round up without overflowing the integer type. 118 */ 119 #define CRYPTO_BITS2BYTES(n) ((n) == 0 ? 0 : (((n) - 1) >> 3) + 1) 120 #define CRYPTO_BYTES2BITS(n) ((n) << 3) 121 122 /* Providers */ 123 124 typedef uint32_t crypto_provider_id_t; 125 #define KCF_PROVID_INVALID ((uint32_t)-1) 126 127 /* session data structure opaque to the consumer */ 128 typedef void *crypto_session_t; 129 130 #define PROVIDER_OWNS_KEY_SCHEDULE 0x00000001 131 132 /* 133 * Common cryptographic status and error codes. 134 */ 135 #define CRYPTO_SUCCESS 0x00000000 136 #define CRYPTO_HOST_MEMORY 0x00000002 137 #define CRYPTO_FAILED 0x00000004 138 #define CRYPTO_ARGUMENTS_BAD 0x00000005 139 #define CRYPTO_DATA_LEN_RANGE 0x0000000C 140 #define CRYPTO_ENCRYPTED_DATA_LEN_RANGE 0x00000011 141 #define CRYPTO_KEY_SIZE_RANGE 0x00000013 142 #define CRYPTO_KEY_TYPE_INCONSISTENT 0x00000014 143 #define CRYPTO_MECHANISM_INVALID 0x0000001C 144 #define CRYPTO_MECHANISM_PARAM_INVALID 0x0000001D 145 #define CRYPTO_SIGNATURE_INVALID 0x0000002D 146 #define CRYPTO_BUFFER_TOO_SMALL 0x00000042 147 #define CRYPTO_NOT_SUPPORTED 0x00000044 148 149 #define CRYPTO_INVALID_CONTEXT 0x00000047 150 #define CRYPTO_INVALID_MAC 0x00000048 151 #define CRYPTO_MECH_NOT_SUPPORTED 0x00000049 152 #define CRYPTO_INVALID_PROVIDER_ID 0x0000004C 153 #define CRYPTO_BUSY 0x0000004E 154 #define CRYPTO_UNKNOWN_PROVIDER 0x0000004F 155 156 #ifdef __cplusplus 157 } 158 #endif 159 160 #endif /* _SYS_CRYPTO_COMMON_H */ 161