James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 1 | /** |
| 2 | * AMCC SoC PPC4xx Crypto Driver |
| 3 | * |
| 4 | * Copyright (c) 2008 Applied Micro Circuits Corporation. |
| 5 | * All rights reserved. James Hsiao <jhsiao@amcc.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * This file defines the security context |
| 18 | * assoicate format. |
| 19 | */ |
| 20 | |
| 21 | #ifndef __CRYPTO4XX_SA_H__ |
| 22 | #define __CRYPTO4XX_SA_H__ |
| 23 | |
| 24 | #define AES_IV_SIZE 16 |
| 25 | |
| 26 | /** |
| 27 | * Contents of Dynamic Security Association (SA) with all possible fields |
| 28 | */ |
| 29 | union dynamic_sa_contents { |
| 30 | struct { |
| 31 | u32 arc4_state_ptr:1; |
| 32 | u32 arc4_ij_ptr:1; |
| 33 | u32 state_ptr:1; |
| 34 | u32 iv3:1; |
| 35 | u32 iv2:1; |
| 36 | u32 iv1:1; |
| 37 | u32 iv0:1; |
| 38 | u32 seq_num_mask3:1; |
| 39 | u32 seq_num_mask2:1; |
| 40 | u32 seq_num_mask1:1; |
| 41 | u32 seq_num_mask0:1; |
| 42 | u32 seq_num1:1; |
| 43 | u32 seq_num0:1; |
| 44 | u32 spi:1; |
| 45 | u32 outer_size:5; |
| 46 | u32 inner_size:5; |
| 47 | u32 key_size:4; |
| 48 | u32 cmd_size:4; |
| 49 | } bf; |
| 50 | u32 w; |
| 51 | } __attribute__((packed)); |
| 52 | |
| 53 | #define DIR_OUTBOUND 0 |
| 54 | #define DIR_INBOUND 1 |
| 55 | #define SA_OP_GROUP_BASIC 0 |
| 56 | #define SA_OPCODE_ENCRYPT 0 |
| 57 | #define SA_OPCODE_DECRYPT 0 |
| 58 | #define SA_OPCODE_HASH 3 |
| 59 | #define SA_CIPHER_ALG_DES 0 |
| 60 | #define SA_CIPHER_ALG_3DES 1 |
| 61 | #define SA_CIPHER_ALG_ARC4 2 |
| 62 | #define SA_CIPHER_ALG_AES 3 |
| 63 | #define SA_CIPHER_ALG_KASUMI 4 |
| 64 | #define SA_CIPHER_ALG_NULL 15 |
| 65 | |
| 66 | #define SA_HASH_ALG_MD5 0 |
| 67 | #define SA_HASH_ALG_SHA1 1 |
| 68 | #define SA_HASH_ALG_NULL 15 |
| 69 | #define SA_HASH_ALG_SHA1_DIGEST_SIZE 20 |
| 70 | |
| 71 | #define SA_LOAD_HASH_FROM_SA 0 |
| 72 | #define SA_LOAD_HASH_FROM_STATE 2 |
| 73 | #define SA_NOT_LOAD_HASH 3 |
| 74 | #define SA_LOAD_IV_FROM_SA 0 |
| 75 | #define SA_LOAD_IV_FROM_INPUT 1 |
| 76 | #define SA_LOAD_IV_FROM_STATE 2 |
| 77 | #define SA_LOAD_IV_GEN_IV 3 |
| 78 | |
| 79 | #define SA_PAD_TYPE_CONSTANT 2 |
| 80 | #define SA_PAD_TYPE_ZERO 3 |
| 81 | #define SA_PAD_TYPE_TLS 5 |
| 82 | #define SA_PAD_TYPE_DTLS 5 |
| 83 | #define SA_NOT_SAVE_HASH 0 |
| 84 | #define SA_SAVE_HASH 1 |
| 85 | #define SA_NOT_SAVE_IV 0 |
| 86 | #define SA_SAVE_IV 1 |
| 87 | #define SA_HEADER_PROC 1 |
| 88 | #define SA_NO_HEADER_PROC 0 |
| 89 | |
| 90 | union sa_command_0 { |
| 91 | struct { |
| 92 | u32 scatter:1; |
| 93 | u32 gather:1; |
| 94 | u32 save_hash_state:1; |
| 95 | u32 save_iv:1; |
| 96 | u32 load_hash_state:2; |
| 97 | u32 load_iv:2; |
| 98 | u32 digest_len:4; |
| 99 | u32 hdr_proc:1; |
| 100 | u32 extend_pad:1; |
| 101 | u32 stream_cipher_pad:1; |
| 102 | u32 rsv:1; |
| 103 | u32 hash_alg:4; |
| 104 | u32 cipher_alg:4; |
| 105 | u32 pad_type:2; |
| 106 | u32 op_group:2; |
| 107 | u32 dir:1; |
| 108 | u32 opcode:3; |
| 109 | } bf; |
| 110 | u32 w; |
| 111 | } __attribute__((packed)); |
| 112 | |
| 113 | #define CRYPTO_MODE_ECB 0 |
| 114 | #define CRYPTO_MODE_CBC 1 |
| 115 | |
| 116 | #define CRYPTO_FEEDBACK_MODE_NO_FB 0 |
| 117 | #define CRYPTO_FEEDBACK_MODE_64BIT_OFB 0 |
| 118 | #define CRYPTO_FEEDBACK_MODE_8BIT_CFB 1 |
| 119 | #define CRYPTO_FEEDBACK_MODE_1BIT_CFB 2 |
| 120 | #define CRYPTO_FEEDBACK_MODE_128BIT_CFB 3 |
| 121 | |
| 122 | #define SA_AES_KEY_LEN_128 2 |
| 123 | #define SA_AES_KEY_LEN_192 3 |
| 124 | #define SA_AES_KEY_LEN_256 4 |
| 125 | |
| 126 | #define SA_REV2 1 |
| 127 | /** |
| 128 | * The follow defines bits sa_command_1 |
| 129 | * In Basic hash mode this bit define simple hash or hmac. |
| 130 | * In IPsec mode, this bit define muting control. |
| 131 | */ |
| 132 | #define SA_HASH_MODE_HASH 0 |
| 133 | #define SA_HASH_MODE_HMAC 1 |
| 134 | #define SA_MC_ENABLE 0 |
| 135 | #define SA_MC_DISABLE 1 |
| 136 | #define SA_NOT_COPY_HDR 0 |
| 137 | #define SA_COPY_HDR 1 |
| 138 | #define SA_NOT_COPY_PAD 0 |
| 139 | #define SA_COPY_PAD 1 |
| 140 | #define SA_NOT_COPY_PAYLOAD 0 |
| 141 | #define SA_COPY_PAYLOAD 1 |
| 142 | #define SA_EXTENDED_SN_OFF 0 |
| 143 | #define SA_EXTENDED_SN_ON 1 |
| 144 | #define SA_SEQ_MASK_OFF 0 |
| 145 | #define SA_SEQ_MASK_ON 1 |
| 146 | |
| 147 | union sa_command_1 { |
| 148 | struct { |
| 149 | u32 crypto_mode31:1; |
| 150 | u32 save_arc4_state:1; |
| 151 | u32 arc4_stateful:1; |
| 152 | u32 key_len:5; |
| 153 | u32 hash_crypto_offset:8; |
| 154 | u32 sa_rev:2; |
| 155 | u32 byte_offset:1; |
| 156 | u32 hmac_muting:1; |
| 157 | u32 feedback_mode:2; |
| 158 | u32 crypto_mode9_8:2; |
| 159 | u32 extended_seq_num:1; |
| 160 | u32 seq_num_mask:1; |
| 161 | u32 mutable_bit_proc:1; |
| 162 | u32 ip_version:1; |
| 163 | u32 copy_pad:1; |
| 164 | u32 copy_payload:1; |
| 165 | u32 copy_hdr:1; |
| 166 | u32 rsv1:1; |
| 167 | } bf; |
| 168 | u32 w; |
| 169 | } __attribute__((packed)); |
| 170 | |
| 171 | struct dynamic_sa_ctl { |
| 172 | u32 sa_contents; |
| 173 | union sa_command_0 sa_command_0; |
| 174 | union sa_command_1 sa_command_1; |
| 175 | } __attribute__((packed)); |
| 176 | |
| 177 | /** |
| 178 | * State Record for Security Association (SA) |
| 179 | */ |
| 180 | struct sa_state_record { |
| 181 | u32 save_iv[4]; |
| 182 | u32 save_hash_byte_cnt[2]; |
| 183 | u32 save_digest[16]; |
| 184 | } __attribute__((packed)); |
| 185 | |
| 186 | /** |
| 187 | * Security Association (SA) for AES128 |
| 188 | * |
| 189 | */ |
| 190 | struct dynamic_sa_aes128 { |
| 191 | struct dynamic_sa_ctl ctrl; |
| 192 | u32 key[4]; |
| 193 | u32 iv[4]; /* for CBC, OFC, and CFB mode */ |
| 194 | u32 state_ptr; |
| 195 | u32 reserved; |
| 196 | } __attribute__((packed)); |
| 197 | |
| 198 | #define SA_AES128_LEN (sizeof(struct dynamic_sa_aes128)/4) |
| 199 | #define SA_AES128_CONTENTS 0x3e000042 |
| 200 | |
| 201 | /* |
| 202 | * Security Association (SA) for AES192 |
| 203 | */ |
| 204 | struct dynamic_sa_aes192 { |
| 205 | struct dynamic_sa_ctl ctrl; |
| 206 | u32 key[6]; |
| 207 | u32 iv[4]; /* for CBC, OFC, and CFB mode */ |
| 208 | u32 state_ptr; |
| 209 | u32 reserved; |
| 210 | } __attribute__((packed)); |
| 211 | |
| 212 | #define SA_AES192_LEN (sizeof(struct dynamic_sa_aes192)/4) |
| 213 | #define SA_AES192_CONTENTS 0x3e000062 |
| 214 | |
| 215 | /** |
| 216 | * Security Association (SA) for AES256 |
| 217 | */ |
| 218 | struct dynamic_sa_aes256 { |
| 219 | struct dynamic_sa_ctl ctrl; |
| 220 | u32 key[8]; |
| 221 | u32 iv[4]; /* for CBC, OFC, and CFB mode */ |
| 222 | u32 state_ptr; |
| 223 | u32 reserved; |
| 224 | } __attribute__((packed)); |
| 225 | |
| 226 | #define SA_AES256_LEN (sizeof(struct dynamic_sa_aes256)/4) |
| 227 | #define SA_AES256_CONTENTS 0x3e000082 |
| 228 | #define SA_AES_CONTENTS 0x3e000002 |
| 229 | |
| 230 | /** |
| 231 | * Security Association (SA) for HASH160: HMAC-SHA1 |
| 232 | */ |
| 233 | struct dynamic_sa_hash160 { |
| 234 | struct dynamic_sa_ctl ctrl; |
| 235 | u32 inner_digest[5]; |
| 236 | u32 outer_digest[5]; |
| 237 | u32 state_ptr; |
| 238 | u32 reserved; |
| 239 | } __attribute__((packed)); |
| 240 | #define SA_HASH160_LEN (sizeof(struct dynamic_sa_hash160)/4) |
| 241 | #define SA_HASH160_CONTENTS 0x2000a502 |
| 242 | |
| 243 | #endif |