ace_sha.h 11 KB

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