crypto4xx_sa.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. * associate format.
  19. */
  20. #ifndef __CRYPTO4XX_SA_H__
  21. #define __CRYPTO4XX_SA_H__
  22. #define AES_IV_SIZE 16
  23. /**
  24. * Contents of Dynamic Security Association (SA) with all possible fields
  25. */
  26. union dynamic_sa_contents {
  27. struct {
  28. u32 arc4_state_ptr:1;
  29. u32 arc4_ij_ptr:1;
  30. u32 state_ptr:1;
  31. u32 iv3:1;
  32. u32 iv2:1;
  33. u32 iv1:1;
  34. u32 iv0:1;
  35. u32 seq_num_mask3:1;
  36. u32 seq_num_mask2:1;
  37. u32 seq_num_mask1:1;
  38. u32 seq_num_mask0:1;
  39. u32 seq_num1:1;
  40. u32 seq_num0:1;
  41. u32 spi:1;
  42. u32 outer_size:5;
  43. u32 inner_size:5;
  44. u32 key_size:4;
  45. u32 cmd_size:4;
  46. } bf;
  47. u32 w;
  48. } __attribute__((packed));
  49. #define DIR_OUTBOUND 0
  50. #define DIR_INBOUND 1
  51. #define SA_OP_GROUP_BASIC 0
  52. #define SA_OPCODE_ENCRYPT 0
  53. #define SA_OPCODE_DECRYPT 0
  54. #define SA_OPCODE_HASH 3
  55. #define SA_CIPHER_ALG_DES 0
  56. #define SA_CIPHER_ALG_3DES 1
  57. #define SA_CIPHER_ALG_ARC4 2
  58. #define SA_CIPHER_ALG_AES 3
  59. #define SA_CIPHER_ALG_KASUMI 4
  60. #define SA_CIPHER_ALG_NULL 15
  61. #define SA_HASH_ALG_MD5 0
  62. #define SA_HASH_ALG_SHA1 1
  63. #define SA_HASH_ALG_NULL 15
  64. #define SA_HASH_ALG_SHA1_DIGEST_SIZE 20
  65. #define SA_LOAD_HASH_FROM_SA 0
  66. #define SA_LOAD_HASH_FROM_STATE 2
  67. #define SA_NOT_LOAD_HASH 3
  68. #define SA_LOAD_IV_FROM_SA 0
  69. #define SA_LOAD_IV_FROM_INPUT 1
  70. #define SA_LOAD_IV_FROM_STATE 2
  71. #define SA_LOAD_IV_GEN_IV 3
  72. #define SA_PAD_TYPE_CONSTANT 2
  73. #define SA_PAD_TYPE_ZERO 3
  74. #define SA_PAD_TYPE_TLS 5
  75. #define SA_PAD_TYPE_DTLS 5
  76. #define SA_NOT_SAVE_HASH 0
  77. #define SA_SAVE_HASH 1
  78. #define SA_NOT_SAVE_IV 0
  79. #define SA_SAVE_IV 1
  80. #define SA_HEADER_PROC 1
  81. #define SA_NO_HEADER_PROC 0
  82. union sa_command_0 {
  83. struct {
  84. u32 scatter:1;
  85. u32 gather:1;
  86. u32 save_hash_state:1;
  87. u32 save_iv:1;
  88. u32 load_hash_state:2;
  89. u32 load_iv:2;
  90. u32 digest_len:4;
  91. u32 hdr_proc:1;
  92. u32 extend_pad:1;
  93. u32 stream_cipher_pad:1;
  94. u32 rsv:1;
  95. u32 hash_alg:4;
  96. u32 cipher_alg:4;
  97. u32 pad_type:2;
  98. u32 op_group:2;
  99. u32 dir:1;
  100. u32 opcode:3;
  101. } bf;
  102. u32 w;
  103. } __attribute__((packed));
  104. #define CRYPTO_MODE_ECB 0
  105. #define CRYPTO_MODE_CBC 1
  106. #define CRYPTO_FEEDBACK_MODE_NO_FB 0
  107. #define CRYPTO_FEEDBACK_MODE_64BIT_OFB 0
  108. #define CRYPTO_FEEDBACK_MODE_8BIT_CFB 1
  109. #define CRYPTO_FEEDBACK_MODE_1BIT_CFB 2
  110. #define CRYPTO_FEEDBACK_MODE_128BIT_CFB 3
  111. #define SA_AES_KEY_LEN_128 2
  112. #define SA_AES_KEY_LEN_192 3
  113. #define SA_AES_KEY_LEN_256 4
  114. #define SA_REV2 1
  115. /**
  116. * The follow defines bits sa_command_1
  117. * In Basic hash mode this bit define simple hash or hmac.
  118. * In IPsec mode, this bit define muting control.
  119. */
  120. #define SA_HASH_MODE_HASH 0
  121. #define SA_HASH_MODE_HMAC 1
  122. #define SA_MC_ENABLE 0
  123. #define SA_MC_DISABLE 1
  124. #define SA_NOT_COPY_HDR 0
  125. #define SA_COPY_HDR 1
  126. #define SA_NOT_COPY_PAD 0
  127. #define SA_COPY_PAD 1
  128. #define SA_NOT_COPY_PAYLOAD 0
  129. #define SA_COPY_PAYLOAD 1
  130. #define SA_EXTENDED_SN_OFF 0
  131. #define SA_EXTENDED_SN_ON 1
  132. #define SA_SEQ_MASK_OFF 0
  133. #define SA_SEQ_MASK_ON 1
  134. union sa_command_1 {
  135. struct {
  136. u32 crypto_mode31:1;
  137. u32 save_arc4_state:1;
  138. u32 arc4_stateful:1;
  139. u32 key_len:5;
  140. u32 hash_crypto_offset:8;
  141. u32 sa_rev:2;
  142. u32 byte_offset:1;
  143. u32 hmac_muting:1;
  144. u32 feedback_mode:2;
  145. u32 crypto_mode9_8:2;
  146. u32 extended_seq_num:1;
  147. u32 seq_num_mask:1;
  148. u32 mutable_bit_proc:1;
  149. u32 ip_version:1;
  150. u32 copy_pad:1;
  151. u32 copy_payload:1;
  152. u32 copy_hdr:1;
  153. u32 rsv1:1;
  154. } bf;
  155. u32 w;
  156. } __attribute__((packed));
  157. struct dynamic_sa_ctl {
  158. u32 sa_contents;
  159. union sa_command_0 sa_command_0;
  160. union sa_command_1 sa_command_1;
  161. } __attribute__((packed));
  162. /**
  163. * State Record for Security Association (SA)
  164. */
  165. struct sa_state_record {
  166. u32 save_iv[4];
  167. u32 save_hash_byte_cnt[2];
  168. u32 save_digest[16];
  169. } __attribute__((packed));
  170. /**
  171. * Security Association (SA) for AES128
  172. *
  173. */
  174. struct dynamic_sa_aes128 {
  175. struct dynamic_sa_ctl ctrl;
  176. u32 key[4];
  177. u32 iv[4]; /* for CBC, OFC, and CFB mode */
  178. u32 state_ptr;
  179. u32 reserved;
  180. } __attribute__((packed));
  181. #define SA_AES128_LEN (sizeof(struct dynamic_sa_aes128)/4)
  182. #define SA_AES128_CONTENTS 0x3e000042
  183. /*
  184. * Security Association (SA) for AES192
  185. */
  186. struct dynamic_sa_aes192 {
  187. struct dynamic_sa_ctl ctrl;
  188. u32 key[6];
  189. u32 iv[4]; /* for CBC, OFC, and CFB mode */
  190. u32 state_ptr;
  191. u32 reserved;
  192. } __attribute__((packed));
  193. #define SA_AES192_LEN (sizeof(struct dynamic_sa_aes192)/4)
  194. #define SA_AES192_CONTENTS 0x3e000062
  195. /**
  196. * Security Association (SA) for AES256
  197. */
  198. struct dynamic_sa_aes256 {
  199. struct dynamic_sa_ctl ctrl;
  200. u32 key[8];
  201. u32 iv[4]; /* for CBC, OFC, and CFB mode */
  202. u32 state_ptr;
  203. u32 reserved;
  204. } __attribute__((packed));
  205. #define SA_AES256_LEN (sizeof(struct dynamic_sa_aes256)/4)
  206. #define SA_AES256_CONTENTS 0x3e000082
  207. #define SA_AES_CONTENTS 0x3e000002
  208. /**
  209. * Security Association (SA) for HASH160: HMAC-SHA1
  210. */
  211. struct dynamic_sa_hash160 {
  212. struct dynamic_sa_ctl ctrl;
  213. u32 inner_digest[5];
  214. u32 outer_digest[5];
  215. u32 state_ptr;
  216. u32 reserved;
  217. } __attribute__((packed));
  218. #define SA_HASH160_LEN (sizeof(struct dynamic_sa_hash160)/4)
  219. #define SA_HASH160_CONTENTS 0x2000a502
  220. #endif