pdb.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. /*
  2. * CAAM Protocol Data Block (PDB) definition header file
  3. *
  4. * Copyright 2008-2016 Freescale Semiconductor, Inc.
  5. *
  6. */
  7. #ifndef CAAM_PDB_H
  8. #define CAAM_PDB_H
  9. #include "compat.h"
  10. /*
  11. * PDB- IPSec ESP Header Modification Options
  12. */
  13. #define PDBHMO_ESP_DECAP_SHIFT 28
  14. #define PDBHMO_ESP_ENCAP_SHIFT 28
  15. /*
  16. * Encap and Decap - Decrement TTL (Hop Limit) - Based on the value of the
  17. * Options Byte IP version (IPvsn) field:
  18. * if IPv4, decrement the inner IP header TTL field (byte 8);
  19. * if IPv6 decrement the inner IP header Hop Limit field (byte 7).
  20. */
  21. #define PDBHMO_ESP_DECAP_DEC_TTL (0x02 << PDBHMO_ESP_DECAP_SHIFT)
  22. #define PDBHMO_ESP_ENCAP_DEC_TTL (0x02 << PDBHMO_ESP_ENCAP_SHIFT)
  23. /*
  24. * Decap - DiffServ Copy - Copy the IPv4 TOS or IPv6 Traffic Class byte
  25. * from the outer IP header to the inner IP header.
  26. */
  27. #define PDBHMO_ESP_DIFFSERV (0x01 << PDBHMO_ESP_DECAP_SHIFT)
  28. /*
  29. * Encap- Copy DF bit -if an IPv4 tunnel mode outer IP header is coming from
  30. * the PDB, copy the DF bit from the inner IP header to the outer IP header.
  31. */
  32. #define PDBHMO_ESP_DFBIT (0x04 << PDBHMO_ESP_ENCAP_SHIFT)
  33. #define PDBNH_ESP_ENCAP_SHIFT 16
  34. #define PDBNH_ESP_ENCAP_MASK (0xff << PDBNH_ESP_ENCAP_SHIFT)
  35. #define PDBHDRLEN_ESP_DECAP_SHIFT 16
  36. #define PDBHDRLEN_MASK (0x0fff << PDBHDRLEN_ESP_DECAP_SHIFT)
  37. #define PDB_NH_OFFSET_SHIFT 8
  38. #define PDB_NH_OFFSET_MASK (0xff << PDB_NH_OFFSET_SHIFT)
  39. /*
  40. * PDB - IPSec ESP Encap/Decap Options
  41. */
  42. #define PDBOPTS_ESP_ARSNONE 0x00 /* no antireplay window */
  43. #define PDBOPTS_ESP_ARS32 0x40 /* 32-entry antireplay window */
  44. #define PDBOPTS_ESP_ARS128 0x80 /* 128-entry antireplay window */
  45. #define PDBOPTS_ESP_ARS64 0xc0 /* 64-entry antireplay window */
  46. #define PDBOPTS_ESP_ARS_MASK 0xc0 /* antireplay window mask */
  47. #define PDBOPTS_ESP_IVSRC 0x20 /* IV comes from internal random gen */
  48. #define PDBOPTS_ESP_ESN 0x10 /* extended sequence included */
  49. #define PDBOPTS_ESP_OUTFMT 0x08 /* output only decapsulation (decap) */
  50. #define PDBOPTS_ESP_IPHDRSRC 0x08 /* IP header comes from PDB (encap) */
  51. #define PDBOPTS_ESP_INCIPHDR 0x04 /* Prepend IP header to output frame */
  52. #define PDBOPTS_ESP_IPVSN 0x02 /* process IPv6 header */
  53. #define PDBOPTS_ESP_AOFL 0x04 /* adjust out frame len (decap, SEC>=5.3)*/
  54. #define PDBOPTS_ESP_TUNNEL 0x01 /* tunnel mode next-header byte */
  55. #define PDBOPTS_ESP_IPV6 0x02 /* ip header version is V6 */
  56. #define PDBOPTS_ESP_DIFFSERV 0x40 /* copy TOS/TC from inner iphdr */
  57. #define PDBOPTS_ESP_UPDATE_CSUM 0x80 /* encap-update ip header checksum */
  58. #define PDBOPTS_ESP_VERIFY_CSUM 0x20 /* decap-validate ip header checksum */
  59. /*
  60. * General IPSec encap/decap PDB definitions
  61. */
  62. /**
  63. * ipsec_encap_cbc - PDB part for IPsec CBC encapsulation
  64. * @iv: 16-byte array initialization vector
  65. */
  66. struct ipsec_encap_cbc {
  67. u8 iv[16];
  68. };
  69. /**
  70. * ipsec_encap_ctr - PDB part for IPsec CTR encapsulation
  71. * @ctr_nonce: 4-byte array nonce
  72. * @ctr_initial: initial count constant
  73. * @iv: initialization vector
  74. */
  75. struct ipsec_encap_ctr {
  76. u8 ctr_nonce[4];
  77. u32 ctr_initial;
  78. u64 iv;
  79. };
  80. /**
  81. * ipsec_encap_ccm - PDB part for IPsec CCM encapsulation
  82. * @salt: 3-byte array salt (lower 24 bits)
  83. * @ccm_opt: CCM algorithm options - MSB-LSB description:
  84. * b0_flags (8b) - CCM B0; use 0x5B for 8-byte ICV, 0x6B for 12-byte ICV,
  85. * 0x7B for 16-byte ICV (cf. RFC4309, RFC3610)
  86. * ctr_flags (8b) - counter flags; constant equal to 0x3
  87. * ctr_initial (16b) - initial count constant
  88. * @iv: initialization vector
  89. */
  90. struct ipsec_encap_ccm {
  91. u8 salt[4];
  92. u32 ccm_opt;
  93. u64 iv;
  94. };
  95. /**
  96. * ipsec_encap_gcm - PDB part for IPsec GCM encapsulation
  97. * @salt: 3-byte array salt (lower 24 bits)
  98. * @rsvd: reserved, do not use
  99. * @iv: initialization vector
  100. */
  101. struct ipsec_encap_gcm {
  102. u8 salt[4];
  103. u32 rsvd1;
  104. u64 iv;
  105. };
  106. /**
  107. * ipsec_encap_pdb - PDB for IPsec encapsulation
  108. * @options: MSB-LSB description
  109. * hmo (header manipulation options) - 4b
  110. * reserved - 4b
  111. * next header - 8b
  112. * next header offset - 8b
  113. * option flags (depend on selected algorithm) - 8b
  114. * @seq_num_ext_hi: (optional) IPsec Extended Sequence Number (ESN)
  115. * @seq_num: IPsec sequence number
  116. * @spi: IPsec SPI (Security Parameters Index)
  117. * @ip_hdr_len: optional IP Header length (in bytes)
  118. * reserved - 16b
  119. * Opt. IP Hdr Len - 16b
  120. * @ip_hdr: optional IP Header content
  121. */
  122. struct ipsec_encap_pdb {
  123. u32 options;
  124. u32 seq_num_ext_hi;
  125. u32 seq_num;
  126. union {
  127. struct ipsec_encap_cbc cbc;
  128. struct ipsec_encap_ctr ctr;
  129. struct ipsec_encap_ccm ccm;
  130. struct ipsec_encap_gcm gcm;
  131. };
  132. u32 spi;
  133. u32 ip_hdr_len;
  134. u32 ip_hdr[0];
  135. };
  136. /**
  137. * ipsec_decap_cbc - PDB part for IPsec CBC decapsulation
  138. * @rsvd: reserved, do not use
  139. */
  140. struct ipsec_decap_cbc {
  141. u32 rsvd[2];
  142. };
  143. /**
  144. * ipsec_decap_ctr - PDB part for IPsec CTR decapsulation
  145. * @ctr_nonce: 4-byte array nonce
  146. * @ctr_initial: initial count constant
  147. */
  148. struct ipsec_decap_ctr {
  149. u8 ctr_nonce[4];
  150. u32 ctr_initial;
  151. };
  152. /**
  153. * ipsec_decap_ccm - PDB part for IPsec CCM decapsulation
  154. * @salt: 3-byte salt (lower 24 bits)
  155. * @ccm_opt: CCM algorithm options - MSB-LSB description:
  156. * b0_flags (8b) - CCM B0; use 0x5B for 8-byte ICV, 0x6B for 12-byte ICV,
  157. * 0x7B for 16-byte ICV (cf. RFC4309, RFC3610)
  158. * ctr_flags (8b) - counter flags; constant equal to 0x3
  159. * ctr_initial (16b) - initial count constant
  160. */
  161. struct ipsec_decap_ccm {
  162. u8 salt[4];
  163. u32 ccm_opt;
  164. };
  165. /**
  166. * ipsec_decap_gcm - PDB part for IPsec GCN decapsulation
  167. * @salt: 4-byte salt
  168. * @rsvd: reserved, do not use
  169. */
  170. struct ipsec_decap_gcm {
  171. u8 salt[4];
  172. u32 resvd;
  173. };
  174. /**
  175. * ipsec_decap_pdb - PDB for IPsec decapsulation
  176. * @options: MSB-LSB description
  177. * hmo (header manipulation options) - 4b
  178. * IP header length - 12b
  179. * next header offset - 8b
  180. * option flags (depend on selected algorithm) - 8b
  181. * @seq_num_ext_hi: (optional) IPsec Extended Sequence Number (ESN)
  182. * @seq_num: IPsec sequence number
  183. * @anti_replay: Anti-replay window; size depends on ARS (option flags)
  184. */
  185. struct ipsec_decap_pdb {
  186. u32 options;
  187. union {
  188. struct ipsec_decap_cbc cbc;
  189. struct ipsec_decap_ctr ctr;
  190. struct ipsec_decap_ccm ccm;
  191. struct ipsec_decap_gcm gcm;
  192. };
  193. u32 seq_num_ext_hi;
  194. u32 seq_num;
  195. __be32 anti_replay[4];
  196. };
  197. /*
  198. * IPSec ESP Datapath Protocol Override Register (DPOVRD)
  199. */
  200. struct ipsec_deco_dpovrd {
  201. #define IPSEC_ENCAP_DECO_DPOVRD_USE 0x80
  202. u8 ovrd_ecn;
  203. u8 ip_hdr_len;
  204. u8 nh_offset;
  205. u8 next_header; /* reserved if decap */
  206. };
  207. /*
  208. * IEEE 802.11i WiFi Protocol Data Block
  209. */
  210. #define WIFI_PDBOPTS_FCS 0x01
  211. #define WIFI_PDBOPTS_AR 0x40
  212. struct wifi_encap_pdb {
  213. u16 mac_hdr_len;
  214. u8 rsvd;
  215. u8 options;
  216. u8 iv_flags;
  217. u8 pri;
  218. u16 pn1;
  219. u32 pn2;
  220. u16 frm_ctrl_mask;
  221. u16 seq_ctrl_mask;
  222. u8 rsvd1[2];
  223. u8 cnst;
  224. u8 key_id;
  225. u8 ctr_flags;
  226. u8 rsvd2;
  227. u16 ctr_init;
  228. };
  229. struct wifi_decap_pdb {
  230. u16 mac_hdr_len;
  231. u8 rsvd;
  232. u8 options;
  233. u8 iv_flags;
  234. u8 pri;
  235. u16 pn1;
  236. u32 pn2;
  237. u16 frm_ctrl_mask;
  238. u16 seq_ctrl_mask;
  239. u8 rsvd1[4];
  240. u8 ctr_flags;
  241. u8 rsvd2;
  242. u16 ctr_init;
  243. };
  244. /*
  245. * IEEE 802.16 WiMAX Protocol Data Block
  246. */
  247. #define WIMAX_PDBOPTS_FCS 0x01
  248. #define WIMAX_PDBOPTS_AR 0x40 /* decap only */
  249. struct wimax_encap_pdb {
  250. u8 rsvd[3];
  251. u8 options;
  252. u32 nonce;
  253. u8 b0_flags;
  254. u8 ctr_flags;
  255. u16 ctr_init;
  256. /* begin DECO writeback region */
  257. u32 pn;
  258. /* end DECO writeback region */
  259. };
  260. struct wimax_decap_pdb {
  261. u8 rsvd[3];
  262. u8 options;
  263. u32 nonce;
  264. u8 iv_flags;
  265. u8 ctr_flags;
  266. u16 ctr_init;
  267. /* begin DECO writeback region */
  268. u32 pn;
  269. u8 rsvd1[2];
  270. u16 antireplay_len;
  271. u64 antireplay_scorecard;
  272. /* end DECO writeback region */
  273. };
  274. /*
  275. * IEEE 801.AE MacSEC Protocol Data Block
  276. */
  277. #define MACSEC_PDBOPTS_FCS 0x01
  278. #define MACSEC_PDBOPTS_AR 0x40 /* used in decap only */
  279. struct macsec_encap_pdb {
  280. u16 aad_len;
  281. u8 rsvd;
  282. u8 options;
  283. u64 sci;
  284. u16 ethertype;
  285. u8 tci_an;
  286. u8 rsvd1;
  287. /* begin DECO writeback region */
  288. u32 pn;
  289. /* end DECO writeback region */
  290. };
  291. struct macsec_decap_pdb {
  292. u16 aad_len;
  293. u8 rsvd;
  294. u8 options;
  295. u64 sci;
  296. u8 rsvd1[3];
  297. /* begin DECO writeback region */
  298. u8 antireplay_len;
  299. u32 pn;
  300. u64 antireplay_scorecard;
  301. /* end DECO writeback region */
  302. };
  303. /*
  304. * SSL/TLS/DTLS Protocol Data Blocks
  305. */
  306. #define TLS_PDBOPTS_ARS32 0x40
  307. #define TLS_PDBOPTS_ARS64 0xc0
  308. #define TLS_PDBOPTS_OUTFMT 0x08
  309. #define TLS_PDBOPTS_IV_WRTBK 0x02 /* 1.1/1.2/DTLS only */
  310. #define TLS_PDBOPTS_EXP_RND_IV 0x01 /* 1.1/1.2/DTLS only */
  311. struct tls_block_encap_pdb {
  312. u8 type;
  313. u8 version[2];
  314. u8 options;
  315. u64 seq_num;
  316. u32 iv[4];
  317. };
  318. struct tls_stream_encap_pdb {
  319. u8 type;
  320. u8 version[2];
  321. u8 options;
  322. u64 seq_num;
  323. u8 i;
  324. u8 j;
  325. u8 rsvd1[2];
  326. };
  327. struct dtls_block_encap_pdb {
  328. u8 type;
  329. u8 version[2];
  330. u8 options;
  331. u16 epoch;
  332. u16 seq_num[3];
  333. u32 iv[4];
  334. };
  335. struct tls_block_decap_pdb {
  336. u8 rsvd[3];
  337. u8 options;
  338. u64 seq_num;
  339. u32 iv[4];
  340. };
  341. struct tls_stream_decap_pdb {
  342. u8 rsvd[3];
  343. u8 options;
  344. u64 seq_num;
  345. u8 i;
  346. u8 j;
  347. u8 rsvd1[2];
  348. };
  349. struct dtls_block_decap_pdb {
  350. u8 rsvd[3];
  351. u8 options;
  352. u16 epoch;
  353. u16 seq_num[3];
  354. u32 iv[4];
  355. u64 antireplay_scorecard;
  356. };
  357. /*
  358. * SRTP Protocol Data Blocks
  359. */
  360. #define SRTP_PDBOPTS_MKI 0x08
  361. #define SRTP_PDBOPTS_AR 0x40
  362. struct srtp_encap_pdb {
  363. u8 x_len;
  364. u8 mki_len;
  365. u8 n_tag;
  366. u8 options;
  367. u32 cnst0;
  368. u8 rsvd[2];
  369. u16 cnst1;
  370. u16 salt[7];
  371. u16 cnst2;
  372. u32 rsvd1;
  373. u32 roc;
  374. u32 opt_mki;
  375. };
  376. struct srtp_decap_pdb {
  377. u8 x_len;
  378. u8 mki_len;
  379. u8 n_tag;
  380. u8 options;
  381. u32 cnst0;
  382. u8 rsvd[2];
  383. u16 cnst1;
  384. u16 salt[7];
  385. u16 cnst2;
  386. u16 rsvd1;
  387. u16 seq_num;
  388. u32 roc;
  389. u64 antireplay_scorecard;
  390. };
  391. /*
  392. * DSA/ECDSA Protocol Data Blocks
  393. * Two of these exist: DSA-SIGN, and DSA-VERIFY. They are similar
  394. * except for the treatment of "w" for verify, "s" for sign,
  395. * and the placement of "a,b".
  396. */
  397. #define DSA_PDB_SGF_SHIFT 24
  398. #define DSA_PDB_SGF_MASK (0xff << DSA_PDB_SGF_SHIFT)
  399. #define DSA_PDB_SGF_Q (0x80 << DSA_PDB_SGF_SHIFT)
  400. #define DSA_PDB_SGF_R (0x40 << DSA_PDB_SGF_SHIFT)
  401. #define DSA_PDB_SGF_G (0x20 << DSA_PDB_SGF_SHIFT)
  402. #define DSA_PDB_SGF_W (0x10 << DSA_PDB_SGF_SHIFT)
  403. #define DSA_PDB_SGF_S (0x10 << DSA_PDB_SGF_SHIFT)
  404. #define DSA_PDB_SGF_F (0x08 << DSA_PDB_SGF_SHIFT)
  405. #define DSA_PDB_SGF_C (0x04 << DSA_PDB_SGF_SHIFT)
  406. #define DSA_PDB_SGF_D (0x02 << DSA_PDB_SGF_SHIFT)
  407. #define DSA_PDB_SGF_AB_SIGN (0x02 << DSA_PDB_SGF_SHIFT)
  408. #define DSA_PDB_SGF_AB_VERIFY (0x01 << DSA_PDB_SGF_SHIFT)
  409. #define DSA_PDB_L_SHIFT 7
  410. #define DSA_PDB_L_MASK (0x3ff << DSA_PDB_L_SHIFT)
  411. #define DSA_PDB_N_MASK 0x7f
  412. struct dsa_sign_pdb {
  413. u32 sgf_ln; /* Use DSA_PDB_ defintions per above */
  414. u8 *q;
  415. u8 *r;
  416. u8 *g; /* or Gx,y */
  417. u8 *s;
  418. u8 *f;
  419. u8 *c;
  420. u8 *d;
  421. u8 *ab; /* ECC only */
  422. u8 *u;
  423. };
  424. struct dsa_verify_pdb {
  425. u32 sgf_ln;
  426. u8 *q;
  427. u8 *r;
  428. u8 *g; /* or Gx,y */
  429. u8 *w; /* or Wx,y */
  430. u8 *f;
  431. u8 *c;
  432. u8 *d;
  433. u8 *tmp; /* temporary data block */
  434. u8 *ab; /* only used if ECC processing */
  435. };
  436. /* RSA Protocol Data Block */
  437. #define RSA_PDB_SGF_SHIFT 28
  438. #define RSA_PDB_E_SHIFT 12
  439. #define RSA_PDB_E_MASK (0xFFF << RSA_PDB_E_SHIFT)
  440. #define RSA_PDB_D_SHIFT 12
  441. #define RSA_PDB_D_MASK (0xFFF << RSA_PDB_D_SHIFT)
  442. #define RSA_PDB_SGF_F (0x8 << RSA_PDB_SGF_SHIFT)
  443. #define RSA_PDB_SGF_G (0x4 << RSA_PDB_SGF_SHIFT)
  444. #define RSA_PRIV_PDB_SGF_F (0x4 << RSA_PDB_SGF_SHIFT)
  445. #define RSA_PRIV_PDB_SGF_G (0x8 << RSA_PDB_SGF_SHIFT)
  446. #define RSA_PRIV_KEY_FRM_1 0
  447. /**
  448. * RSA Encrypt Protocol Data Block
  449. * @sgf: scatter-gather field
  450. * @f_dma: dma address of input data
  451. * @g_dma: dma address of encrypted output data
  452. * @n_dma: dma address of RSA modulus
  453. * @e_dma: dma address of RSA public exponent
  454. * @f_len: length in octets of the input data
  455. */
  456. struct rsa_pub_pdb {
  457. u32 sgf;
  458. dma_addr_t f_dma;
  459. dma_addr_t g_dma;
  460. dma_addr_t n_dma;
  461. dma_addr_t e_dma;
  462. u32 f_len;
  463. } __packed;
  464. /**
  465. * RSA Decrypt PDB - Private Key Form #1
  466. * @sgf: scatter-gather field
  467. * @g_dma: dma address of encrypted input data
  468. * @f_dma: dma address of output data
  469. * @n_dma: dma address of RSA modulus
  470. * @d_dma: dma address of RSA private exponent
  471. */
  472. struct rsa_priv_f1_pdb {
  473. u32 sgf;
  474. dma_addr_t g_dma;
  475. dma_addr_t f_dma;
  476. dma_addr_t n_dma;
  477. dma_addr_t d_dma;
  478. } __packed;
  479. #endif