aes_struct.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. /**
  2. * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stdint.h>
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. /** Group: key register */
  12. /** Type of key_0 register
  13. * Key material key_0 configure register
  14. */
  15. typedef union {
  16. struct {
  17. /** key_0 : R/W; bitpos: [31:0]; default: 0;
  18. * This bits stores key_0 that is a part of key material.
  19. */
  20. uint32_t key_0:32;
  21. };
  22. uint32_t val;
  23. } aes_key_0_reg_t;
  24. /** Type of key_1 register
  25. * Key material key_1 configure register
  26. */
  27. typedef union {
  28. struct {
  29. /** key_1 : R/W; bitpos: [31:0]; default: 0;
  30. * This bits stores key_1 that is a part of key material.
  31. */
  32. uint32_t key_1:32;
  33. };
  34. uint32_t val;
  35. } aes_key_1_reg_t;
  36. /** Type of key_2 register
  37. * Key material key_2 configure register
  38. */
  39. typedef union {
  40. struct {
  41. /** key_2 : R/W; bitpos: [31:0]; default: 0;
  42. * This bits stores key_2 that is a part of key material.
  43. */
  44. uint32_t key_2:32;
  45. };
  46. uint32_t val;
  47. } aes_key_2_reg_t;
  48. /** Type of key_3 register
  49. * Key material key_3 configure register
  50. */
  51. typedef union {
  52. struct {
  53. /** key_3 : R/W; bitpos: [31:0]; default: 0;
  54. * This bits stores key_3 that is a part of key material.
  55. */
  56. uint32_t key_3:32;
  57. };
  58. uint32_t val;
  59. } aes_key_3_reg_t;
  60. /** Type of key_4 register
  61. * Key material key_4 configure register
  62. */
  63. typedef union {
  64. struct {
  65. /** key_4 : R/W; bitpos: [31:0]; default: 0;
  66. * This bits stores key_4 that is a part of key material.
  67. */
  68. uint32_t key_4:32;
  69. };
  70. uint32_t val;
  71. } aes_key_4_reg_t;
  72. /** Type of key_5 register
  73. * Key material key_5 configure register
  74. */
  75. typedef union {
  76. struct {
  77. /** key_5 : R/W; bitpos: [31:0]; default: 0;
  78. * This bits stores key_5 that is a part of key material.
  79. */
  80. uint32_t key_5:32;
  81. };
  82. uint32_t val;
  83. } aes_key_5_reg_t;
  84. /** Type of key_6 register
  85. * Key material key_6 configure register
  86. */
  87. typedef union {
  88. struct {
  89. /** key_6 : R/W; bitpos: [31:0]; default: 0;
  90. * This bits stores key_6 that is a part of key material.
  91. */
  92. uint32_t key_6:32;
  93. };
  94. uint32_t val;
  95. } aes_key_6_reg_t;
  96. /** Type of key_7 register
  97. * Key material key_7 configure register
  98. */
  99. typedef union {
  100. struct {
  101. /** key_7 : R/W; bitpos: [31:0]; default: 0;
  102. * This bits stores key_7 that is a part of key material.
  103. */
  104. uint32_t key_7:32;
  105. };
  106. uint32_t val;
  107. } aes_key_7_reg_t;
  108. /** Group: text in register */
  109. /** Type of text_in_0 register
  110. * source text material text_in_0 configure register
  111. */
  112. typedef union {
  113. struct {
  114. /** text_in_0 : R/W; bitpos: [31:0]; default: 0;
  115. * This bits stores text_in_0 that is a part of source text material.
  116. */
  117. uint32_t text_in_0:32;
  118. };
  119. uint32_t val;
  120. } aes_text_in_0_reg_t;
  121. /** Type of text_in_1 register
  122. * source text material text_in_1 configure register
  123. */
  124. typedef union {
  125. struct {
  126. /** text_in_1 : R/W; bitpos: [31:0]; default: 0;
  127. * This bits stores text_in_1 that is a part of source text material.
  128. */
  129. uint32_t text_in_1:32;
  130. };
  131. uint32_t val;
  132. } aes_text_in_1_reg_t;
  133. /** Type of text_in_2 register
  134. * source text material text_in_2 configure register
  135. */
  136. typedef union {
  137. struct {
  138. /** text_in_2 : R/W; bitpos: [31:0]; default: 0;
  139. * This bits stores text_in_2 that is a part of source text material.
  140. */
  141. uint32_t text_in_2:32;
  142. };
  143. uint32_t val;
  144. } aes_text_in_2_reg_t;
  145. /** Type of text_in_3 register
  146. * source text material text_in_3 configure register
  147. */
  148. typedef union {
  149. struct {
  150. /** text_in_3 : R/W; bitpos: [31:0]; default: 0;
  151. * This bits stores text_in_3 that is a part of source text material.
  152. */
  153. uint32_t text_in_3:32;
  154. };
  155. uint32_t val;
  156. } aes_text_in_3_reg_t;
  157. /** Group: text out register */
  158. /** Type of text_out_0 register
  159. * result text material text_out_0 configure register
  160. */
  161. typedef union {
  162. struct {
  163. /** text_out_0 : R/W; bitpos: [31:0]; default: 0;
  164. * This bits stores text_out_0 that is a part of result text material.
  165. */
  166. uint32_t text_out_0:32;
  167. };
  168. uint32_t val;
  169. } aes_text_out_0_reg_t;
  170. /** Type of text_out_1 register
  171. * result text material text_out_1 configure register
  172. */
  173. typedef union {
  174. struct {
  175. /** text_out_1 : R/W; bitpos: [31:0]; default: 0;
  176. * This bits stores text_out_1 that is a part of result text material.
  177. */
  178. uint32_t text_out_1:32;
  179. };
  180. uint32_t val;
  181. } aes_text_out_1_reg_t;
  182. /** Type of text_out_2 register
  183. * result text material text_out_2 configure register
  184. */
  185. typedef union {
  186. struct {
  187. /** text_out_2 : R/W; bitpos: [31:0]; default: 0;
  188. * This bits stores text_out_2 that is a part of result text material.
  189. */
  190. uint32_t text_out_2:32;
  191. };
  192. uint32_t val;
  193. } aes_text_out_2_reg_t;
  194. /** Type of text_out_3 register
  195. * result text material text_out_3 configure register
  196. */
  197. typedef union {
  198. struct {
  199. /** text_out_3 : R/W; bitpos: [31:0]; default: 0;
  200. * This bits stores text_out_3 that is a part of result text material.
  201. */
  202. uint32_t text_out_3:32;
  203. };
  204. uint32_t val;
  205. } aes_text_out_3_reg_t;
  206. /** Group: Configuration register */
  207. /** Type of mode register
  208. * AES Mode register
  209. */
  210. typedef union {
  211. struct {
  212. /** mode : R/W; bitpos: [2:0]; default: 0;
  213. * This bits decides which one operation mode will be used. 3'd0: AES-EN-128, 3'd1:
  214. * AES-EN-192, 3'd2: AES-EN-256, 3'd4: AES-DE-128, 3'd5: AES-DE-192, 3'd6: AES-DE-256.
  215. */
  216. uint32_t mode:3;
  217. uint32_t reserved_3:29;
  218. };
  219. uint32_t val;
  220. } aes_mode_reg_t;
  221. /** Type of endian register
  222. * AES Endian configure register
  223. */
  224. typedef union {
  225. struct {
  226. /** endian : R/W; bitpos: [5:0]; default: 0;
  227. * endian. [1:0] key endian, [3:2] text_in endian or in_stream endian, [5:4] text_out
  228. * endian or out_stream endian
  229. */
  230. uint32_t endian:6;
  231. uint32_t reserved_6:26;
  232. };
  233. uint32_t val;
  234. } aes_endian_reg_t;
  235. /** Type of block_mode register
  236. * AES cipher block mode register
  237. */
  238. typedef union {
  239. struct {
  240. /** block_mode : R/W; bitpos: [2:0]; default: 0;
  241. * Those bits decides which block mode will be used. 0x0: ECB, 0x1: CBC, 0x2: OFB,
  242. * 0x3: CTR, 0x4: CFB-8, 0x5: CFB-128, 0x6: GCM, 0x7: reserved.
  243. */
  244. uint32_t block_mode:3;
  245. uint32_t reserved_3:29;
  246. };
  247. uint32_t val;
  248. } aes_block_mode_reg_t;
  249. /** Type of block_num register
  250. * AES block number register
  251. */
  252. typedef union {
  253. struct {
  254. /** block_num : R/W; bitpos: [31:0]; default: 0;
  255. * Those bits stores the number of Plaintext/ciphertext block.
  256. */
  257. uint32_t block_num:32;
  258. };
  259. uint32_t val;
  260. } aes_block_num_reg_t;
  261. /** Type of inc_sel register
  262. * Standard incrementing function configure register
  263. */
  264. typedef union {
  265. struct {
  266. /** inc_sel : R/W; bitpos: [0]; default: 0;
  267. * This bit decides the standard incrementing function. 0: INC32. 1: INC128.
  268. */
  269. uint32_t inc_sel:1;
  270. uint32_t reserved_1:31;
  271. };
  272. uint32_t val;
  273. } aes_inc_sel_reg_t;
  274. /** Type of aad_block_num register
  275. * Additional Authential Data block number register
  276. */
  277. typedef union {
  278. struct {
  279. /** aad_block_num : R/W; bitpos: [31:0]; default: 0;
  280. * Those bits stores the number of AAD block.
  281. */
  282. uint32_t aad_block_num:32;
  283. };
  284. uint32_t val;
  285. } aes_aad_block_num_reg_t;
  286. /** Type of remainder_bit_num register
  287. * AES remainder bit number register
  288. */
  289. typedef union {
  290. struct {
  291. /** remainder_bit_num : R/W; bitpos: [6:0]; default: 0;
  292. * Those bits stores the number of remainder bit.
  293. */
  294. uint32_t remainder_bit_num:7;
  295. uint32_t reserved_7:25;
  296. };
  297. uint32_t val;
  298. } aes_remainder_bit_num_reg_t;
  299. /** Group: Control/Status register */
  300. /** Type of trigger register
  301. * AES trigger register
  302. */
  303. typedef union {
  304. struct {
  305. /** trigger : WT; bitpos: [0]; default: 0;
  306. * Set this bit to start AES calculation.
  307. */
  308. uint32_t trigger:1;
  309. uint32_t reserved_1:31;
  310. };
  311. uint32_t val;
  312. } aes_trigger_reg_t;
  313. /** Type of state register
  314. * AES state register
  315. */
  316. typedef union {
  317. struct {
  318. /** state : RO; bitpos: [1:0]; default: 0;
  319. * Those bits shows AES status. For typical AES, 0: idle, 1: busy. For DMA-AES, 0:
  320. * idle, 1: busy, 2: calculation_done.
  321. */
  322. uint32_t state:2;
  323. uint32_t reserved_2:30;
  324. };
  325. uint32_t val;
  326. } aes_state_reg_t;
  327. /** Type of dma_enable register
  328. * DMA-AES working mode register
  329. */
  330. typedef union {
  331. struct {
  332. /** dma_enable : R/W; bitpos: [0]; default: 0;
  333. * 1'b0: typical AES working mode, 1'b1: DMA-AES working mode.
  334. */
  335. uint32_t dma_enable:1;
  336. uint32_t reserved_1:31;
  337. };
  338. uint32_t val;
  339. } aes_dma_enable_reg_t;
  340. /** Type of continue register
  341. * AES continue register
  342. */
  343. typedef union {
  344. struct {
  345. /** conti : WT; bitpos: [0]; default: 0;
  346. * Set this bit to continue GCM operation.
  347. */
  348. uint32_t conti:1;
  349. uint32_t reserved_1:31;
  350. };
  351. uint32_t val;
  352. } aes_continue_reg_t;
  353. /** Type of dma_exit register
  354. * AES-DMA exit config
  355. */
  356. typedef union {
  357. struct {
  358. /** dma_exit : WT; bitpos: [0]; default: 0;
  359. * Set this register to leave calculation done stage. Recommend to use it after
  360. * software finishes reading DMA's output buffer.
  361. */
  362. uint32_t dma_exit:1;
  363. uint32_t reserved_1:31;
  364. };
  365. uint32_t val;
  366. } aes_dma_exit_reg_t;
  367. /** Group: memory type */
  368. /** Group: interrupt register */
  369. /** Type of int_clear register
  370. * AES Interrupt clear register
  371. */
  372. typedef union {
  373. struct {
  374. /** int_clear : WT; bitpos: [0]; default: 0;
  375. * Set this bit to clear the AES interrupt.
  376. */
  377. uint32_t int_clear:1;
  378. uint32_t reserved_1:31;
  379. };
  380. uint32_t val;
  381. } aes_int_clear_reg_t;
  382. /** Type of int_ena register
  383. * AES Interrupt enable register
  384. */
  385. typedef union {
  386. struct {
  387. /** int_ena : R/W; bitpos: [0]; default: 0;
  388. * Set this bit to enable interrupt that occurs when DMA-AES calculation is done.
  389. */
  390. uint32_t int_ena:1;
  391. uint32_t reserved_1:31;
  392. };
  393. uint32_t val;
  394. } aes_int_ena_reg_t;
  395. /** Group: Version control register */
  396. /** Type of date register
  397. * AES version control register
  398. */
  399. typedef union {
  400. struct {
  401. /** date : R/W; bitpos: [29:0]; default: 538513936;
  402. * This bits stores the version information of AES.
  403. */
  404. uint32_t date:30;
  405. uint32_t reserved_30:2;
  406. };
  407. uint32_t val;
  408. } aes_date_reg_t;
  409. typedef struct aes_dev_t {
  410. volatile aes_key_0_reg_t key_0;
  411. volatile aes_key_1_reg_t key_1;
  412. volatile aes_key_2_reg_t key_2;
  413. volatile aes_key_3_reg_t key_3;
  414. volatile aes_key_4_reg_t key_4;
  415. volatile aes_key_5_reg_t key_5;
  416. volatile aes_key_6_reg_t key_6;
  417. volatile aes_key_7_reg_t key_7;
  418. volatile aes_text_in_0_reg_t text_in_0;
  419. volatile aes_text_in_1_reg_t text_in_1;
  420. volatile aes_text_in_2_reg_t text_in_2;
  421. volatile aes_text_in_3_reg_t text_in_3;
  422. volatile aes_text_out_0_reg_t text_out_0;
  423. volatile aes_text_out_1_reg_t text_out_1;
  424. volatile aes_text_out_2_reg_t text_out_2;
  425. volatile aes_text_out_3_reg_t text_out_3;
  426. volatile aes_mode_reg_t mode;
  427. volatile aes_endian_reg_t endian;
  428. volatile aes_trigger_reg_t trigger;
  429. volatile aes_state_reg_t state;
  430. volatile uint32_t iv[4];
  431. volatile uint32_t h[4];
  432. volatile uint32_t j0[4];
  433. volatile uint32_t t0[4];
  434. volatile aes_dma_enable_reg_t dma_enable;
  435. volatile aes_block_mode_reg_t block_mode;
  436. volatile aes_block_num_reg_t block_num;
  437. volatile aes_inc_sel_reg_t inc_sel;
  438. volatile aes_aad_block_num_reg_t aad_block_num;
  439. volatile aes_remainder_bit_num_reg_t remainder_bit_num;
  440. volatile aes_continue_reg_t conti;
  441. volatile aes_int_clear_reg_t int_clear;
  442. volatile aes_int_ena_reg_t int_ena;
  443. volatile aes_date_reg_t date;
  444. volatile aes_dma_exit_reg_t dma_exit;
  445. } aes_dev_t;
  446. extern aes_dev_t AES;
  447. #ifndef __cplusplus
  448. _Static_assert(sizeof(aes_dev_t) == 0xbc, "Invalid size of aes_dev_t structure");
  449. #endif
  450. #ifdef __cplusplus
  451. }
  452. #endif