1 /*- 2 * Copyright (c) 2017 Chelsio Communications, Inc. 3 * All rights reserved. 4 * Written by: John Baldwin <jhb@FreeBSD.org> 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * $FreeBSD$ 28 */ 29 30 #ifndef __T4_CRYPTO_H__ 31 #define __T4_CRYPTO_H__ 32 33 /* From chr_core.h */ 34 #define PAD_ERROR_BIT 1 35 #define CHK_PAD_ERR_BIT(x) (((x) >> PAD_ERROR_BIT) & 1) 36 37 #define MAC_ERROR_BIT 0 38 #define CHK_MAC_ERR_BIT(x) (((x) >> MAC_ERROR_BIT) & 1) 39 #define MAX_SALT 4 40 41 struct _key_ctx { 42 __be32 ctx_hdr; 43 u8 salt[MAX_SALT]; 44 __be64 reserverd; 45 unsigned char key[0]; 46 }; 47 48 struct chcr_wr { 49 struct fw_crypto_lookaside_wr wreq; 50 struct ulp_txpkt ulptx; 51 struct ulptx_idata sc_imm; 52 struct cpl_tx_sec_pdu sec_cpl; 53 struct _key_ctx key_ctx; 54 }; 55 56 /* From chr_algo.h */ 57 58 /* Crypto key context */ 59 #define S_KEY_CONTEXT_CTX_LEN 24 60 #define M_KEY_CONTEXT_CTX_LEN 0xff 61 #define V_KEY_CONTEXT_CTX_LEN(x) ((x) << S_KEY_CONTEXT_CTX_LEN) 62 #define G_KEY_CONTEXT_CTX_LEN(x) \ 63 (((x) >> S_KEY_CONTEXT_CTX_LEN) & M_KEY_CONTEXT_CTX_LEN) 64 65 #define S_KEY_CONTEXT_DUAL_CK 12 66 #define M_KEY_CONTEXT_DUAL_CK 0x1 67 #define V_KEY_CONTEXT_DUAL_CK(x) ((x) << S_KEY_CONTEXT_DUAL_CK) 68 #define G_KEY_CONTEXT_DUAL_CK(x) \ 69 (((x) >> S_KEY_CONTEXT_DUAL_CK) & M_KEY_CONTEXT_DUAL_CK) 70 #define F_KEY_CONTEXT_DUAL_CK V_KEY_CONTEXT_DUAL_CK(1U) 71 72 #define S_KEY_CONTEXT_OPAD_PRESENT 11 73 #define M_KEY_CONTEXT_OPAD_PRESENT 0x1 74 #define V_KEY_CONTEXT_OPAD_PRESENT(x) ((x) << S_KEY_CONTEXT_OPAD_PRESENT) 75 #define G_KEY_CONTEXT_OPAD_PRESENT(x) \ 76 (((x) >> S_KEY_CONTEXT_OPAD_PRESENT) & \ 77 M_KEY_CONTEXT_OPAD_PRESENT) 78 #define F_KEY_CONTEXT_OPAD_PRESENT V_KEY_CONTEXT_OPAD_PRESENT(1U) 79 80 #define S_KEY_CONTEXT_SALT_PRESENT 10 81 #define M_KEY_CONTEXT_SALT_PRESENT 0x1 82 #define V_KEY_CONTEXT_SALT_PRESENT(x) ((x) << S_KEY_CONTEXT_SALT_PRESENT) 83 #define G_KEY_CONTEXT_SALT_PRESENT(x) \ 84 (((x) >> S_KEY_CONTEXT_SALT_PRESENT) & \ 85 M_KEY_CONTEXT_SALT_PRESENT) 86 #define F_KEY_CONTEXT_SALT_PRESENT V_KEY_CONTEXT_SALT_PRESENT(1U) 87 88 #define S_KEY_CONTEXT_CK_SIZE 6 89 #define M_KEY_CONTEXT_CK_SIZE 0xf 90 #define V_KEY_CONTEXT_CK_SIZE(x) ((x) << S_KEY_CONTEXT_CK_SIZE) 91 #define G_KEY_CONTEXT_CK_SIZE(x) \ 92 (((x) >> S_KEY_CONTEXT_CK_SIZE) & M_KEY_CONTEXT_CK_SIZE) 93 94 #define S_KEY_CONTEXT_MK_SIZE 2 95 #define M_KEY_CONTEXT_MK_SIZE 0xf 96 #define V_KEY_CONTEXT_MK_SIZE(x) ((x) << S_KEY_CONTEXT_MK_SIZE) 97 #define G_KEY_CONTEXT_MK_SIZE(x) \ 98 (((x) >> S_KEY_CONTEXT_MK_SIZE) & M_KEY_CONTEXT_MK_SIZE) 99 100 #define S_KEY_CONTEXT_VALID 0 101 #define M_KEY_CONTEXT_VALID 0x1 102 #define V_KEY_CONTEXT_VALID(x) ((x) << S_KEY_CONTEXT_VALID) 103 #define G_KEY_CONTEXT_VALID(x) \ 104 (((x) >> S_KEY_CONTEXT_VALID) & \ 105 M_KEY_CONTEXT_VALID) 106 #define F_KEY_CONTEXT_VALID V_KEY_CONTEXT_VALID(1U) 107 108 #define CHCR_HASH_MAX_DIGEST_SIZE 64 109 110 #define DUMMY_BYTES 16 111 112 #define TRANSHDR_SIZE(kctx_len)\ 113 (sizeof(struct chcr_wr) +\ 114 kctx_len) 115 #define CIPHER_TRANSHDR_SIZE(kctx_len, sge_pairs) \ 116 (TRANSHDR_SIZE((kctx_len)) + (sge_pairs) +\ 117 sizeof(struct cpl_rx_phys_dsgl)) 118 #define HASH_TRANSHDR_SIZE(kctx_len)\ 119 (TRANSHDR_SIZE(kctx_len) + DUMMY_BYTES) 120 121 #define CRYPTO_MAX_IMM_TX_PKT_LEN 256 122 123 struct phys_sge_pairs { 124 __be16 len[8]; 125 __be64 addr[8]; 126 }; 127 128 /* From chr_crypto.h */ 129 #define CHCR_AES_MAX_KEY_LEN (AES_XTS_MAX_KEY) 130 #define CHCR_MAX_CRYPTO_IV_LEN 16 /* AES IV len */ 131 132 #define CHCR_ENCRYPT_OP 0 133 #define CHCR_DECRYPT_OP 1 134 135 #define CHCR_SCMD_PROTO_VERSION_GENERIC 4 136 137 #define CHCR_SCMD_CIPHER_MODE_NOP 0 138 #define CHCR_SCMD_CIPHER_MODE_AES_CBC 1 139 #define CHCR_SCMD_CIPHER_MODE_AES_GCM 2 140 #define CHCR_SCMD_CIPHER_MODE_AES_CTR 3 141 #define CHCR_SCMD_CIPHER_MODE_GENERIC_AES 4 142 #define CHCR_SCMD_CIPHER_MODE_AES_XTS 6 143 #define CHCR_SCMD_CIPHER_MODE_AES_CCM 7 144 145 #define CHCR_SCMD_AUTH_MODE_NOP 0 146 #define CHCR_SCMD_AUTH_MODE_SHA1 1 147 #define CHCR_SCMD_AUTH_MODE_SHA224 2 148 #define CHCR_SCMD_AUTH_MODE_SHA256 3 149 #define CHCR_SCMD_AUTH_MODE_GHASH 4 150 #define CHCR_SCMD_AUTH_MODE_SHA512_224 5 151 #define CHCR_SCMD_AUTH_MODE_SHA512_256 6 152 #define CHCR_SCMD_AUTH_MODE_SHA512_384 7 153 #define CHCR_SCMD_AUTH_MODE_SHA512_512 8 154 #define CHCR_SCMD_AUTH_MODE_CBCMAC 9 155 #define CHCR_SCMD_AUTH_MODE_CMAC 10 156 157 #define CHCR_SCMD_HMAC_CTRL_NOP 0 158 #define CHCR_SCMD_HMAC_CTRL_NO_TRUNC 1 159 #define CHCR_SCMD_HMAC_CTRL_TRUNC_RFC4366 2 160 #define CHCR_SCMD_HMAC_CTRL_IPSEC_96BIT 3 161 #define CHCR_SCMD_HMAC_CTRL_PL1 4 162 #define CHCR_SCMD_HMAC_CTRL_PL2 5 163 #define CHCR_SCMD_HMAC_CTRL_PL3 6 164 #define CHCR_SCMD_HMAC_CTRL_DIV2 7 165 166 /* This are not really mac key size. They are intermediate values 167 * of sha engine and its size 168 */ 169 #define CHCR_KEYCTX_MAC_KEY_SIZE_128 0 170 #define CHCR_KEYCTX_MAC_KEY_SIZE_160 1 171 #define CHCR_KEYCTX_MAC_KEY_SIZE_192 2 172 #define CHCR_KEYCTX_MAC_KEY_SIZE_256 3 173 #define CHCR_KEYCTX_MAC_KEY_SIZE_512 4 174 #define CHCR_KEYCTX_CIPHER_KEY_SIZE_128 0 175 #define CHCR_KEYCTX_CIPHER_KEY_SIZE_192 1 176 #define CHCR_KEYCTX_CIPHER_KEY_SIZE_256 2 177 #define CHCR_KEYCTX_NO_KEY 15 178 179 #define IV_NOP 0 180 #define IV_IMMEDIATE 1 181 #define IV_DSGL 2 182 183 #define CHCR_HASH_MAX_BLOCK_SIZE_64 64 184 #define CHCR_HASH_MAX_BLOCK_SIZE_128 128 185 186 #endif /* !__T4_CRYPTO_H__ */ 187