Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Akshay Saraswat | acbb1eb | 2013-03-20 21:00:56 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Header file for Advanced Crypto Engine - SFR definitions |
| 4 | * |
| 5 | * Copyright (c) 2012 Samsung Electronics |
Akshay Saraswat | acbb1eb | 2013-03-20 21:00:56 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef __ACE_SHA_H |
| 9 | #define __ACE_SHA_H |
| 10 | |
Tom Rini | 03de305 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 11 | #include <linux/types.h> |
| 12 | |
Akshay Saraswat | acbb1eb | 2013-03-20 21:00:56 +0000 | [diff] [blame] | 13 | struct exynos_ace_sfr { |
| 14 | unsigned int fc_intstat; /* base + 0 */ |
| 15 | unsigned int fc_intenset; |
| 16 | unsigned int fc_intenclr; |
| 17 | unsigned int fc_intpend; |
| 18 | unsigned int fc_fifostat; |
| 19 | unsigned int fc_fifoctrl; |
| 20 | unsigned int fc_global; |
| 21 | unsigned int res1; |
| 22 | unsigned int fc_brdmas; |
| 23 | unsigned int fc_brdmal; |
| 24 | unsigned int fc_brdmac; |
| 25 | unsigned int res2; |
| 26 | unsigned int fc_btdmas; |
| 27 | unsigned int fc_btdmal; |
| 28 | unsigned int fc_btdmac; |
| 29 | unsigned int res3; |
| 30 | unsigned int fc_hrdmas; |
| 31 | unsigned int fc_hrdmal; |
| 32 | unsigned int fc_hrdmac; |
| 33 | unsigned int res4; |
| 34 | unsigned int fc_pkdmas; |
| 35 | unsigned int fc_pkdmal; |
| 36 | unsigned int fc_pkdmac; |
| 37 | unsigned int fc_pkdmao; |
| 38 | unsigned char res5[0x1a0]; |
| 39 | |
| 40 | unsigned int aes_control; /* base + 0x200 */ |
| 41 | unsigned int aes_status; |
| 42 | unsigned char res6[0x8]; |
| 43 | unsigned int aes_in[4]; |
| 44 | unsigned int aes_out[4]; |
| 45 | unsigned int aes_iv[4]; |
| 46 | unsigned int aes_cnt[4]; |
| 47 | unsigned char res7[0x30]; |
| 48 | unsigned int aes_key[8]; |
| 49 | unsigned char res8[0x60]; |
| 50 | |
| 51 | unsigned int tdes_control; /* base + 0x300 */ |
| 52 | unsigned int tdes_status; |
| 53 | unsigned char res9[0x8]; |
| 54 | unsigned int tdes_key[6]; |
| 55 | unsigned int tdes_iv[2]; |
| 56 | unsigned int tdes_in[2]; |
| 57 | unsigned int tdes_out[2]; |
| 58 | unsigned char res10[0xc0]; |
| 59 | |
| 60 | unsigned int hash_control; /* base + 0x400 */ |
| 61 | unsigned int hash_control2; |
| 62 | unsigned int hash_fifo_mode; |
| 63 | unsigned int hash_byteswap; |
| 64 | unsigned int hash_status; |
| 65 | unsigned char res11[0xc]; |
| 66 | unsigned int hash_msgsize_low; |
| 67 | unsigned int hash_msgsize_high; |
| 68 | unsigned int hash_prelen_low; |
| 69 | unsigned int hash_prelen_high; |
| 70 | unsigned int hash_in[16]; |
| 71 | unsigned int hash_key_in[16]; |
| 72 | unsigned int hash_iv[8]; |
| 73 | unsigned char res12[0x30]; |
| 74 | unsigned int hash_result[8]; |
| 75 | unsigned char res13[0x20]; |
Przemyslaw Marczak | 0bd9372 | 2014-03-25 10:58:21 +0100 | [diff] [blame] | 76 | unsigned int hash_seed[5]; |
| 77 | unsigned char res14[12]; |
| 78 | unsigned int hash_prng[5]; |
| 79 | unsigned char res15[0x18c]; |
Akshay Saraswat | acbb1eb | 2013-03-20 21:00:56 +0000 | [diff] [blame] | 80 | |
| 81 | unsigned int pka_sfr[5]; /* base + 0x700 */ |
| 82 | }; |
| 83 | |
| 84 | /* ACE_FC_INT */ |
| 85 | #define ACE_FC_PKDMA (1 << 0) |
| 86 | #define ACE_FC_HRDMA (1 << 1) |
| 87 | #define ACE_FC_BTDMA (1 << 2) |
| 88 | #define ACE_FC_BRDMA (1 << 3) |
| 89 | #define ACE_FC_PRNG_ERROR (1 << 4) |
| 90 | #define ACE_FC_MSG_DONE (1 << 5) |
| 91 | #define ACE_FC_PRNG_DONE (1 << 6) |
| 92 | #define ACE_FC_PARTIAL_DONE (1 << 7) |
| 93 | |
| 94 | /* ACE_FC_FIFOSTAT */ |
| 95 | #define ACE_FC_PKFIFO_EMPTY (1 << 0) |
| 96 | #define ACE_FC_PKFIFO_FULL (1 << 1) |
| 97 | #define ACE_FC_HRFIFO_EMPTY (1 << 2) |
| 98 | #define ACE_FC_HRFIFO_FULL (1 << 3) |
| 99 | #define ACE_FC_BTFIFO_EMPTY (1 << 4) |
| 100 | #define ACE_FC_BTFIFO_FULL (1 << 5) |
| 101 | #define ACE_FC_BRFIFO_EMPTY (1 << 6) |
| 102 | #define ACE_FC_BRFIFO_FULL (1 << 7) |
| 103 | |
| 104 | /* ACE_FC_FIFOCTRL */ |
| 105 | #define ACE_FC_SELHASH_MASK (3 << 0) |
| 106 | #define ACE_FC_SELHASH_EXOUT (0 << 0) /* independent source */ |
| 107 | #define ACE_FC_SELHASH_BCIN (1 << 0) /* blk cipher input */ |
| 108 | #define ACE_FC_SELHASH_BCOUT (2 << 0) /* blk cipher output */ |
| 109 | #define ACE_FC_SELBC_MASK (1 << 2) |
| 110 | #define ACE_FC_SELBC_AES (0 << 2) |
| 111 | #define ACE_FC_SELBC_DES (1 << 2) |
| 112 | |
| 113 | /* ACE_FC_GLOBAL */ |
| 114 | #define ACE_FC_SSS_RESET (1 << 0) |
| 115 | #define ACE_FC_DMA_RESET (1 << 1) |
| 116 | #define ACE_FC_AES_RESET (1 << 2) |
| 117 | #define ACE_FC_DES_RESET (1 << 3) |
| 118 | #define ACE_FC_HASH_RESET (1 << 4) |
| 119 | #define ACE_FC_AXI_ENDIAN_MASK (3 << 6) |
| 120 | #define ACE_FC_AXI_ENDIAN_LE (0 << 6) |
| 121 | #define ACE_FC_AXI_ENDIAN_BIBE (1 << 6) |
| 122 | #define ACE_FC_AXI_ENDIAN_WIBE (2 << 6) |
| 123 | |
| 124 | /* Feed control - BRDMA control */ |
| 125 | #define ACE_FC_BRDMACFLUSH_OFF (0 << 0) |
| 126 | #define ACE_FC_BRDMACFLUSH_ON (1 << 0) |
| 127 | #define ACE_FC_BRDMACSWAP_ON (1 << 1) |
| 128 | #define ACE_FC_BRDMACARPROT_MASK (0x7 << 2) |
| 129 | #define ACE_FC_BRDMACARPROT_OFS 2 |
| 130 | #define ACE_FC_BRDMACARCACHE_MASK (0xf << 5) |
| 131 | #define ACE_FC_BRDMACARCACHE_OFS 5 |
| 132 | |
| 133 | /* Feed control - BTDMA control */ |
| 134 | #define ACE_FC_BTDMACFLUSH_OFF (0 << 0) |
| 135 | #define ACE_FC_BTDMACFLUSH_ON (1 << 0) |
| 136 | #define ACE_FC_BTDMACSWAP_ON (1 << 1) |
| 137 | #define ACE_FC_BTDMACAWPROT_MASK (0x7 << 2) |
| 138 | #define ACE_FC_BTDMACAWPROT_OFS 2 |
| 139 | #define ACE_FC_BTDMACAWCACHE_MASK (0xf << 5) |
| 140 | #define ACE_FC_BTDMACAWCACHE_OFS 5 |
| 141 | |
| 142 | /* Feed control - HRDMA control */ |
| 143 | #define ACE_FC_HRDMACFLUSH_OFF (0 << 0) |
| 144 | #define ACE_FC_HRDMACFLUSH_ON (1 << 0) |
| 145 | #define ACE_FC_HRDMACSWAP_ON (1 << 1) |
| 146 | #define ACE_FC_HRDMACARPROT_MASK (0x7 << 2) |
| 147 | #define ACE_FC_HRDMACARPROT_OFS 2 |
| 148 | #define ACE_FC_HRDMACARCACHE_MASK (0xf << 5) |
| 149 | #define ACE_FC_HRDMACARCACHE_OFS 5 |
| 150 | |
| 151 | /* Feed control - PKDMA control */ |
| 152 | #define ACE_FC_PKDMACBYTESWAP_ON (1 << 3) |
| 153 | #define ACE_FC_PKDMACDESEND_ON (1 << 2) |
| 154 | #define ACE_FC_PKDMACTRANSMIT_ON (1 << 1) |
| 155 | #define ACE_FC_PKDMACFLUSH_ON (1 << 0) |
| 156 | |
| 157 | /* Feed control - PKDMA offset */ |
| 158 | #define ACE_FC_SRAMOFFSET_MASK 0xfff |
| 159 | |
| 160 | /* AES control */ |
| 161 | #define ACE_AES_MODE_MASK (1 << 0) |
| 162 | #define ACE_AES_MODE_ENC (0 << 0) |
| 163 | #define ACE_AES_MODE_DEC (1 << 0) |
| 164 | #define ACE_AES_OPERMODE_MASK (3 << 1) |
| 165 | #define ACE_AES_OPERMODE_ECB (0 << 1) |
| 166 | #define ACE_AES_OPERMODE_CBC (1 << 1) |
| 167 | #define ACE_AES_OPERMODE_CTR (2 << 1) |
| 168 | #define ACE_AES_FIFO_MASK (1 << 3) |
| 169 | #define ACE_AES_FIFO_OFF (0 << 3) /* CPU mode */ |
| 170 | #define ACE_AES_FIFO_ON (1 << 3) /* FIFO mode */ |
| 171 | #define ACE_AES_KEYSIZE_MASK (3 << 4) |
| 172 | #define ACE_AES_KEYSIZE_128 (0 << 4) |
| 173 | #define ACE_AES_KEYSIZE_192 (1 << 4) |
| 174 | #define ACE_AES_KEYSIZE_256 (2 << 4) |
| 175 | #define ACE_AES_KEYCNGMODE_MASK (1 << 6) |
| 176 | #define ACE_AES_KEYCNGMODE_OFF (0 << 6) |
| 177 | #define ACE_AES_KEYCNGMODE_ON (1 << 6) |
| 178 | #define ACE_AES_SWAP_MASK (0x1f << 7) |
| 179 | #define ACE_AES_SWAPKEY_OFF (0 << 7) |
| 180 | #define ACE_AES_SWAPKEY_ON (1 << 7) |
| 181 | #define ACE_AES_SWAPCNT_OFF (0 << 8) |
| 182 | #define ACE_AES_SWAPCNT_ON (1 << 8) |
| 183 | #define ACE_AES_SWAPIV_OFF (0 << 9) |
| 184 | #define ACE_AES_SWAPIV_ON (1 << 9) |
| 185 | #define ACE_AES_SWAPDO_OFF (0 << 10) |
| 186 | #define ACE_AES_SWAPDO_ON (1 << 10) |
| 187 | #define ACE_AES_SWAPDI_OFF (0 << 11) |
| 188 | #define ACE_AES_SWAPDI_ON (1 << 11) |
| 189 | #define ACE_AES_COUNTERSIZE_MASK (3 << 12) |
| 190 | #define ACE_AES_COUNTERSIZE_128 (0 << 12) |
| 191 | #define ACE_AES_COUNTERSIZE_64 (1 << 12) |
| 192 | #define ACE_AES_COUNTERSIZE_32 (2 << 12) |
| 193 | #define ACE_AES_COUNTERSIZE_16 (3 << 12) |
| 194 | |
| 195 | /* AES status */ |
| 196 | #define ACE_AES_OUTRDY_MASK (1 << 0) |
| 197 | #define ACE_AES_OUTRDY_OFF (0 << 0) |
| 198 | #define ACE_AES_OUTRDY_ON (1 << 0) |
| 199 | #define ACE_AES_INRDY_MASK (1 << 1) |
| 200 | #define ACE_AES_INRDY_OFF (0 << 1) |
| 201 | #define ACE_AES_INRDY_ON (1 << 1) |
| 202 | #define ACE_AES_BUSY_MASK (1 << 2) |
| 203 | #define ACE_AES_BUSY_OFF (0 << 2) |
| 204 | #define ACE_AES_BUSY_ON (1 << 2) |
| 205 | |
| 206 | /* TDES control */ |
| 207 | #define ACE_TDES_MODE_MASK (1 << 0) |
| 208 | #define ACE_TDES_MODE_ENC (0 << 0) |
| 209 | #define ACE_TDES_MODE_DEC (1 << 0) |
| 210 | #define ACE_TDES_OPERMODE_MASK (1 << 1) |
| 211 | #define ACE_TDES_OPERMODE_ECB (0 << 1) |
| 212 | #define ACE_TDES_OPERMODE_CBC (1 << 1) |
| 213 | #define ACE_TDES_SEL_MASK (3 << 3) |
| 214 | #define ACE_TDES_SEL_DES (0 << 3) |
| 215 | #define ACE_TDES_SEL_TDESEDE (1 << 3) /* TDES EDE mode */ |
| 216 | #define ACE_TDES_SEL_TDESEEE (3 << 3) /* TDES EEE mode */ |
| 217 | #define ACE_TDES_FIFO_MASK (1 << 5) |
| 218 | #define ACE_TDES_FIFO_OFF (0 << 5) /* CPU mode */ |
| 219 | #define ACE_TDES_FIFO_ON (1 << 5) /* FIFO mode */ |
| 220 | #define ACE_TDES_SWAP_MASK (0xf << 6) |
| 221 | #define ACE_TDES_SWAPKEY_OFF (0 << 6) |
| 222 | #define ACE_TDES_SWAPKEY_ON (1 << 6) |
| 223 | #define ACE_TDES_SWAPIV_OFF (0 << 7) |
| 224 | #define ACE_TDES_SWAPIV_ON (1 << 7) |
| 225 | #define ACE_TDES_SWAPDO_OFF (0 << 8) |
| 226 | #define ACE_TDES_SWAPDO_ON (1 << 8) |
| 227 | #define ACE_TDES_SWAPDI_OFF (0 << 9) |
| 228 | #define ACE_TDES_SWAPDI_ON (1 << 9) |
| 229 | |
| 230 | /* TDES status */ |
| 231 | #define ACE_TDES_OUTRDY_MASK (1 << 0) |
| 232 | #define ACE_TDES_OUTRDY_OFF (0 << 0) |
| 233 | #define ACE_TDES_OUTRDY_ON (1 << 0) |
| 234 | #define ACE_TDES_INRDY_MASK (1 << 1) |
| 235 | #define ACE_TDES_INRDY_OFF (0 << 1) |
| 236 | #define ACE_TDES_INRDY_ON (1 << 1) |
| 237 | #define ACE_TDES_BUSY_MASK (1 << 2) |
| 238 | #define ACE_TDES_BUSY_OFF (0 << 2) |
| 239 | #define ACE_TDES_BUSY_ON (1 << 2) |
| 240 | |
| 241 | /* Hash control */ |
| 242 | #define ACE_HASH_ENGSEL_MASK (0xf << 0) |
| 243 | #define ACE_HASH_ENGSEL_SHA1HASH (0x0 << 0) |
| 244 | #define ACE_HASH_ENGSEL_SHA1HMAC (0x1 << 0) |
| 245 | #define ACE_HASH_ENGSEL_SHA1HMACIN (0x1 << 0) |
| 246 | #define ACE_HASH_ENGSEL_SHA1HMACOUT (0x9 << 0) |
| 247 | #define ACE_HASH_ENGSEL_MD5HASH (0x2 << 0) |
| 248 | #define ACE_HASH_ENGSEL_MD5HMAC (0x3 << 0) |
| 249 | #define ACE_HASH_ENGSEL_MD5HMACIN (0x3 << 0) |
| 250 | #define ACE_HASH_ENGSEL_MD5HMACOUT (0xb << 0) |
| 251 | #define ACE_HASH_ENGSEL_SHA256HASH (0x4 << 0) |
| 252 | #define ACE_HASH_ENGSEL_SHA256HMAC (0x5 << 0) |
| 253 | #define ACE_HASH_ENGSEL_PRNG (0x8 << 0) |
| 254 | #define ACE_HASH_STARTBIT_ON (1 << 4) |
| 255 | #define ACE_HASH_USERIV_EN (1 << 5) |
| 256 | #define ACE_HASH_PAUSE_ON (1 << 0) |
| 257 | |
| 258 | /* Hash control - FIFO mode */ |
| 259 | #define ACE_HASH_FIFO_MASK (1 << 0) |
| 260 | #define ACE_HASH_FIFO_OFF (0 << 0) |
| 261 | #define ACE_HASH_FIFO_ON (1 << 0) |
| 262 | |
| 263 | /* Hash control - byte swap */ |
| 264 | #define ACE_HASH_SWAP_MASK (0xf << 0) |
| 265 | #define ACE_HASH_SWAPKEY_OFF (0 << 0) |
| 266 | #define ACE_HASH_SWAPKEY_ON (1 << 0) |
| 267 | #define ACE_HASH_SWAPIV_OFF (0 << 1) |
| 268 | #define ACE_HASH_SWAPIV_ON (1 << 1) |
| 269 | #define ACE_HASH_SWAPDO_OFF (0 << 2) |
| 270 | #define ACE_HASH_SWAPDO_ON (1 << 2) |
| 271 | #define ACE_HASH_SWAPDI_OFF (0 << 3) |
| 272 | #define ACE_HASH_SWAPDI_ON (1 << 3) |
| 273 | |
| 274 | /* Hash status */ |
| 275 | #define ACE_HASH_BUFRDY_MASK (1 << 0) |
| 276 | #define ACE_HASH_BUFRDY_OFF (0 << 0) |
| 277 | #define ACE_HASH_BUFRDY_ON (1 << 0) |
| 278 | #define ACE_HASH_SEEDSETTING_MASK (1 << 1) |
| 279 | #define ACE_HASH_SEEDSETTING_OFF (0 << 1) |
| 280 | #define ACE_HASH_SEEDSETTING_ON (1 << 1) |
| 281 | #define ACE_HASH_PRNGBUSY_MASK (1 << 2) |
| 282 | #define ACE_HASH_PRNGBUSY_OFF (0 << 2) |
| 283 | #define ACE_HASH_PRNGBUSY_ON (1 << 2) |
| 284 | #define ACE_HASH_PARTIALDONE_MASK (1 << 4) |
| 285 | #define ACE_HASH_PARTIALDONE_OFF (0 << 4) |
| 286 | #define ACE_HASH_PARTIALDONE_ON (1 << 4) |
| 287 | #define ACE_HASH_PRNGDONE_MASK (1 << 5) |
| 288 | #define ACE_HASH_PRNGDONE_OFF (0 << 5) |
| 289 | #define ACE_HASH_PRNGDONE_ON (1 << 5) |
| 290 | #define ACE_HASH_MSGDONE_MASK (1 << 6) |
| 291 | #define ACE_HASH_MSGDONE_OFF (0 << 6) |
| 292 | #define ACE_HASH_MSGDONE_ON (1 << 6) |
| 293 | #define ACE_HASH_PRNGERROR_MASK (1 << 7) |
| 294 | #define ACE_HASH_PRNGERROR_OFF (0 << 7) |
| 295 | #define ACE_HASH_PRNGERROR_ON (1 << 7) |
Przemyslaw Marczak | 0bd9372 | 2014-03-25 10:58:21 +0100 | [diff] [blame] | 296 | #define ACE_HASH_PRNG_REG_NUM 5 |
Akshay Saraswat | acbb1eb | 2013-03-20 21:00:56 +0000 | [diff] [blame] | 297 | |
| 298 | #define ACE_SHA_TYPE_SHA1 1 |
| 299 | #define ACE_SHA_TYPE_SHA256 2 |
| 300 | |
| 301 | /** |
| 302 | * Computes hash value of input pbuf using ACE |
| 303 | * |
| 304 | * @param in_addr A pointer to the input buffer |
| 305 | * @param bufleni Byte length of input buffer |
| 306 | * @param out_addr A pointer to the output buffer. When complete |
| 307 | * 32 bytes are copied to pout[0]...pout[31]. Thus, a user |
| 308 | * should allocate at least 32 bytes at pOut in advance. |
| 309 | * @param hash_type SHA1 or SHA256 |
| 310 | * |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 311 | * Return: 0 on Success, -1 on Failure (Timeout) |
Akshay Saraswat | acbb1eb | 2013-03-20 21:00:56 +0000 | [diff] [blame] | 312 | */ |
| 313 | int ace_sha_hash_digest(const uchar * in_addr, uint buflen, |
| 314 | uchar * out_addr, uint hash_type); |
| 315 | #endif |