nx_csbcpb.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __NX_CSBCPB_H__
  3. #define __NX_CSBCPB_H__
  4. struct cop_symcpb_aes_ecb {
  5. u8 key[32];
  6. u8 __rsvd[80];
  7. } __packed;
  8. struct cop_symcpb_aes_cbc {
  9. u8 iv[16];
  10. u8 key[32];
  11. u8 cv[16];
  12. u32 spbc;
  13. u8 __rsvd[44];
  14. } __packed;
  15. struct cop_symcpb_aes_gca {
  16. u8 in_pat[16];
  17. u8 key[32];
  18. u8 out_pat[16];
  19. u32 spbc;
  20. u8 __rsvd[44];
  21. } __packed;
  22. struct cop_symcpb_aes_gcm {
  23. u8 in_pat_or_aad[16];
  24. u8 iv_or_cnt[16];
  25. u64 bit_length_aad;
  26. u64 bit_length_data;
  27. u8 in_s0[16];
  28. u8 key[32];
  29. u8 __rsvd1[16];
  30. u8 out_pat_or_mac[16];
  31. u8 out_s0[16];
  32. u8 out_cnt[16];
  33. u32 spbc;
  34. u8 __rsvd2[12];
  35. } __packed;
  36. struct cop_symcpb_aes_ctr {
  37. u8 iv[16];
  38. u8 key[32];
  39. u8 cv[16];
  40. u32 spbc;
  41. u8 __rsvd2[44];
  42. } __packed;
  43. struct cop_symcpb_aes_cca {
  44. u8 b0[16];
  45. u8 b1[16];
  46. u8 key[16];
  47. u8 out_pat_or_b0[16];
  48. u32 spbc;
  49. u8 __rsvd[44];
  50. } __packed;
  51. struct cop_symcpb_aes_ccm {
  52. u8 in_pat_or_b0[16];
  53. u8 iv_or_ctr[16];
  54. u8 in_s0[16];
  55. u8 key[16];
  56. u8 __rsvd1[48];
  57. u8 out_pat_or_mac[16];
  58. u8 out_s0[16];
  59. u8 out_ctr[16];
  60. u32 spbc;
  61. u8 __rsvd2[12];
  62. } __packed;
  63. struct cop_symcpb_aes_xcbc {
  64. u8 cv[16];
  65. u8 key[16];
  66. u8 __rsvd1[16];
  67. u8 out_cv_mac[16];
  68. u32 spbc;
  69. u8 __rsvd2[44];
  70. } __packed;
  71. struct cop_symcpb_sha256 {
  72. u64 message_bit_length;
  73. u64 __rsvd1;
  74. u8 input_partial_digest[32];
  75. u8 message_digest[32];
  76. u32 spbc;
  77. u8 __rsvd2[44];
  78. } __packed;
  79. struct cop_symcpb_sha512 {
  80. u64 message_bit_length_hi;
  81. u64 message_bit_length_lo;
  82. u8 input_partial_digest[64];
  83. u8 __rsvd1[32];
  84. u8 message_digest[64];
  85. u32 spbc;
  86. u8 __rsvd2[76];
  87. } __packed;
  88. #define NX_FDM_INTERMEDIATE 0x01
  89. #define NX_FDM_CONTINUATION 0x02
  90. #define NX_FDM_ENDE_ENCRYPT 0x80
  91. #define NX_CPB_FDM(c) ((c)->cpb.hdr.fdm)
  92. #define NX_CPB_KS_DS(c) ((c)->cpb.hdr.ks_ds)
  93. #define NX_CPB_KEY_SIZE(c) (NX_CPB_KS_DS(c) >> 4)
  94. #define NX_CPB_SET_KEY_SIZE(c, x) NX_CPB_KS_DS(c) |= ((x) << 4)
  95. #define NX_CPB_SET_DIGEST_SIZE(c, x) NX_CPB_KS_DS(c) |= (x)
  96. struct cop_symcpb_header {
  97. u8 mode;
  98. u8 fdm;
  99. u8 ks_ds;
  100. u8 pad_byte;
  101. u8 __rsvd[12];
  102. } __packed;
  103. struct cop_parameter_block {
  104. struct cop_symcpb_header hdr;
  105. union {
  106. struct cop_symcpb_aes_ecb aes_ecb;
  107. struct cop_symcpb_aes_cbc aes_cbc;
  108. struct cop_symcpb_aes_gca aes_gca;
  109. struct cop_symcpb_aes_gcm aes_gcm;
  110. struct cop_symcpb_aes_cca aes_cca;
  111. struct cop_symcpb_aes_ccm aes_ccm;
  112. struct cop_symcpb_aes_ctr aes_ctr;
  113. struct cop_symcpb_aes_xcbc aes_xcbc;
  114. struct cop_symcpb_sha256 sha256;
  115. struct cop_symcpb_sha512 sha512;
  116. };
  117. } __packed;
  118. #define NX_CSB_VALID_BIT 0x80
  119. /* co-processor status block */
  120. struct cop_status_block {
  121. u8 valid;
  122. u8 crb_seq_number;
  123. u8 completion_code;
  124. u8 completion_extension;
  125. u32 processed_byte_count;
  126. u64 address;
  127. } __packed;
  128. /* Nest accelerator workbook section 4.4 */
  129. struct nx_csbcpb {
  130. unsigned char __rsvd[112];
  131. struct cop_status_block csb;
  132. struct cop_parameter_block cpb;
  133. } __packed;
  134. /* nx_csbcpb related definitions */
  135. #define NX_MODE_AES_ECB 0
  136. #define NX_MODE_AES_CBC 1
  137. #define NX_MODE_AES_GMAC 2
  138. #define NX_MODE_AES_GCA 3
  139. #define NX_MODE_AES_GCM 4
  140. #define NX_MODE_AES_CCA 5
  141. #define NX_MODE_AES_CCM 6
  142. #define NX_MODE_AES_CTR 7
  143. #define NX_MODE_AES_XCBC_MAC 20
  144. #define NX_MODE_SHA 0
  145. #define NX_MODE_SHA_HMAC 1
  146. #define NX_MODE_AES_CBC_HMAC_ETA 8
  147. #define NX_MODE_AES_CBC_HMAC_ATE 9
  148. #define NX_MODE_AES_CBC_HMAC_EAA 10
  149. #define NX_MODE_AES_CTR_HMAC_ETA 12
  150. #define NX_MODE_AES_CTR_HMAC_ATE 13
  151. #define NX_MODE_AES_CTR_HMAC_EAA 14
  152. #define NX_FDM_CI_FULL 0
  153. #define NX_FDM_CI_FIRST 1
  154. #define NX_FDM_CI_LAST 2
  155. #define NX_FDM_CI_MIDDLE 3
  156. #define NX_FDM_PR_NONE 0
  157. #define NX_FDM_PR_PAD 1
  158. #define NX_KS_AES_128 1
  159. #define NX_KS_AES_192 2
  160. #define NX_KS_AES_256 3
  161. #define NX_DS_SHA256 2
  162. #define NX_DS_SHA512 3
  163. #define NX_FC_AES 0
  164. #define NX_FC_SHA 2
  165. #define NX_FC_AES_HMAC 6
  166. #define NX_MAX_FC (NX_FC_AES_HMAC + 1)
  167. #define NX_MAX_MODE (NX_MODE_AES_XCBC_MAC + 1)
  168. #define HCOP_FC_AES NX_FC_AES
  169. #define HCOP_FC_SHA NX_FC_SHA
  170. #define HCOP_FC_AES_HMAC NX_FC_AES_HMAC
  171. /* indices into the array of algorithm properties */
  172. #define NX_PROPS_AES_128 0
  173. #define NX_PROPS_AES_192 1
  174. #define NX_PROPS_AES_256 2
  175. #define NX_PROPS_SHA256 1
  176. #define NX_PROPS_SHA512 2
  177. #endif