/* SPDX-License-Identifier: GPL-2.0 */1/*2* CAAM Protocol Data Block (PDB) definition header file3*4* Copyright 2008-2016 Freescale Semiconductor, Inc.5*6*/78#ifndef CAAM_PDB_H9#define CAAM_PDB_H10#include "compat.h"1112/*13* PDB- IPSec ESP Header Modification Options14*/15#define PDBHMO_ESP_DECAP_SHIFT 2816#define PDBHMO_ESP_ENCAP_SHIFT 2817/*18* Encap and Decap - Decrement TTL (Hop Limit) - Based on the value of the19* Options Byte IP version (IPvsn) field:20* if IPv4, decrement the inner IP header TTL field (byte 8);21* if IPv6 decrement the inner IP header Hop Limit field (byte 7).22*/23#define PDBHMO_ESP_DECAP_DEC_TTL (0x02 << PDBHMO_ESP_DECAP_SHIFT)24#define PDBHMO_ESP_ENCAP_DEC_TTL (0x02 << PDBHMO_ESP_ENCAP_SHIFT)25/*26* Decap - DiffServ Copy - Copy the IPv4 TOS or IPv6 Traffic Class byte27* from the outer IP header to the inner IP header.28*/29#define PDBHMO_ESP_DIFFSERV (0x01 << PDBHMO_ESP_DECAP_SHIFT)30/*31* Encap- Copy DF bit -if an IPv4 tunnel mode outer IP header is coming from32* the PDB, copy the DF bit from the inner IP header to the outer IP header.33*/34#define PDBHMO_ESP_DFBIT (0x04 << PDBHMO_ESP_ENCAP_SHIFT)3536#define PDBNH_ESP_ENCAP_SHIFT 1637#define PDBNH_ESP_ENCAP_MASK (0xff << PDBNH_ESP_ENCAP_SHIFT)3839#define PDBHDRLEN_ESP_DECAP_SHIFT 1640#define PDBHDRLEN_MASK (0x0fff << PDBHDRLEN_ESP_DECAP_SHIFT)4142#define PDB_NH_OFFSET_SHIFT 843#define PDB_NH_OFFSET_MASK (0xff << PDB_NH_OFFSET_SHIFT)4445/*46* PDB - IPSec ESP Encap/Decap Options47*/48#define PDBOPTS_ESP_ARSNONE 0x00 /* no antireplay window */49#define PDBOPTS_ESP_ARS32 0x40 /* 32-entry antireplay window */50#define PDBOPTS_ESP_ARS128 0x80 /* 128-entry antireplay window */51#define PDBOPTS_ESP_ARS64 0xc0 /* 64-entry antireplay window */52#define PDBOPTS_ESP_ARS_MASK 0xc0 /* antireplay window mask */53#define PDBOPTS_ESP_IVSRC 0x20 /* IV comes from internal random gen */54#define PDBOPTS_ESP_ESN 0x10 /* extended sequence included */55#define PDBOPTS_ESP_OUTFMT 0x08 /* output only decapsulation (decap) */56#define PDBOPTS_ESP_IPHDRSRC 0x08 /* IP header comes from PDB (encap) */57#define PDBOPTS_ESP_INCIPHDR 0x04 /* Prepend IP header to output frame */58#define PDBOPTS_ESP_IPVSN 0x02 /* process IPv6 header */59#define PDBOPTS_ESP_AOFL 0x04 /* adjust out frame len (decap, SEC>=5.3)*/60#define PDBOPTS_ESP_TUNNEL 0x01 /* tunnel mode next-header byte */61#define PDBOPTS_ESP_IPV6 0x02 /* ip header version is V6 */62#define PDBOPTS_ESP_DIFFSERV 0x40 /* copy TOS/TC from inner iphdr */63#define PDBOPTS_ESP_UPDATE_CSUM 0x80 /* encap-update ip header checksum */64#define PDBOPTS_ESP_VERIFY_CSUM 0x20 /* decap-validate ip header checksum */6566/*67* General IPSec encap/decap PDB definitions68*/6970/**71* ipsec_encap_cbc - PDB part for IPsec CBC encapsulation72* @iv: 16-byte array initialization vector73*/74struct ipsec_encap_cbc {75u8 iv[16];76};7778/**79* ipsec_encap_ctr - PDB part for IPsec CTR encapsulation80* @ctr_nonce: 4-byte array nonce81* @ctr_initial: initial count constant82* @iv: initialization vector83*/84struct ipsec_encap_ctr {85u8 ctr_nonce[4];86u32 ctr_initial;87u64 iv;88};8990/**91* ipsec_encap_ccm - PDB part for IPsec CCM encapsulation92* @salt: 3-byte array salt (lower 24 bits)93* @ccm_opt: CCM algorithm options - MSB-LSB description:94* b0_flags (8b) - CCM B0; use 0x5B for 8-byte ICV, 0x6B for 12-byte ICV,95* 0x7B for 16-byte ICV (cf. RFC4309, RFC3610)96* ctr_flags (8b) - counter flags; constant equal to 0x397* ctr_initial (16b) - initial count constant98* @iv: initialization vector99*/100struct ipsec_encap_ccm {101u8 salt[4];102u32 ccm_opt;103u64 iv;104};105106/**107* ipsec_encap_gcm - PDB part for IPsec GCM encapsulation108* @salt: 3-byte array salt (lower 24 bits)109* @rsvd: reserved, do not use110* @iv: initialization vector111*/112struct ipsec_encap_gcm {113u8 salt[4];114u32 rsvd1;115u64 iv;116};117118/**119* ipsec_encap_pdb - PDB for IPsec encapsulation120* @options: MSB-LSB description121* hmo (header manipulation options) - 4b122* reserved - 4b123* next header - 8b124* next header offset - 8b125* option flags (depend on selected algorithm) - 8b126* @seq_num_ext_hi: (optional) IPsec Extended Sequence Number (ESN)127* @seq_num: IPsec sequence number128* @spi: IPsec SPI (Security Parameters Index)129* @ip_hdr_len: optional IP Header length (in bytes)130* reserved - 16b131* Opt. IP Hdr Len - 16b132* @ip_hdr: optional IP Header content133*/134struct ipsec_encap_pdb {135u32 options;136u32 seq_num_ext_hi;137u32 seq_num;138union {139struct ipsec_encap_cbc cbc;140struct ipsec_encap_ctr ctr;141struct ipsec_encap_ccm ccm;142struct ipsec_encap_gcm gcm;143};144u32 spi;145u32 ip_hdr_len;146u32 ip_hdr[];147};148149/**150* ipsec_decap_cbc - PDB part for IPsec CBC decapsulation151* @rsvd: reserved, do not use152*/153struct ipsec_decap_cbc {154u32 rsvd[2];155};156157/**158* ipsec_decap_ctr - PDB part for IPsec CTR decapsulation159* @ctr_nonce: 4-byte array nonce160* @ctr_initial: initial count constant161*/162struct ipsec_decap_ctr {163u8 ctr_nonce[4];164u32 ctr_initial;165};166167/**168* ipsec_decap_ccm - PDB part for IPsec CCM decapsulation169* @salt: 3-byte salt (lower 24 bits)170* @ccm_opt: CCM algorithm options - MSB-LSB description:171* b0_flags (8b) - CCM B0; use 0x5B for 8-byte ICV, 0x6B for 12-byte ICV,172* 0x7B for 16-byte ICV (cf. RFC4309, RFC3610)173* ctr_flags (8b) - counter flags; constant equal to 0x3174* ctr_initial (16b) - initial count constant175*/176struct ipsec_decap_ccm {177u8 salt[4];178u32 ccm_opt;179};180181/**182* ipsec_decap_gcm - PDB part for IPsec GCN decapsulation183* @salt: 4-byte salt184* @rsvd: reserved, do not use185*/186struct ipsec_decap_gcm {187u8 salt[4];188u32 resvd;189};190191/**192* ipsec_decap_pdb - PDB for IPsec decapsulation193* @options: MSB-LSB description194* hmo (header manipulation options) - 4b195* IP header length - 12b196* next header offset - 8b197* option flags (depend on selected algorithm) - 8b198* @seq_num_ext_hi: (optional) IPsec Extended Sequence Number (ESN)199* @seq_num: IPsec sequence number200* @anti_replay: Anti-replay window; size depends on ARS (option flags)201*/202struct ipsec_decap_pdb {203u32 options;204union {205struct ipsec_decap_cbc cbc;206struct ipsec_decap_ctr ctr;207struct ipsec_decap_ccm ccm;208struct ipsec_decap_gcm gcm;209};210u32 seq_num_ext_hi;211u32 seq_num;212__be32 anti_replay[4];213};214215/*216* IPSec ESP Datapath Protocol Override Register (DPOVRD)217*/218struct ipsec_deco_dpovrd {219#define IPSEC_ENCAP_DECO_DPOVRD_USE 0x80220u8 ovrd_ecn;221u8 ip_hdr_len;222u8 nh_offset;223u8 next_header; /* reserved if decap */224};225226/*227* IEEE 802.11i WiFi Protocol Data Block228*/229#define WIFI_PDBOPTS_FCS 0x01230#define WIFI_PDBOPTS_AR 0x40231232struct wifi_encap_pdb {233u16 mac_hdr_len;234u8 rsvd;235u8 options;236u8 iv_flags;237u8 pri;238u16 pn1;239u32 pn2;240u16 frm_ctrl_mask;241u16 seq_ctrl_mask;242u8 rsvd1[2];243u8 cnst;244u8 key_id;245u8 ctr_flags;246u8 rsvd2;247u16 ctr_init;248};249250struct wifi_decap_pdb {251u16 mac_hdr_len;252u8 rsvd;253u8 options;254u8 iv_flags;255u8 pri;256u16 pn1;257u32 pn2;258u16 frm_ctrl_mask;259u16 seq_ctrl_mask;260u8 rsvd1[4];261u8 ctr_flags;262u8 rsvd2;263u16 ctr_init;264};265266/*267* IEEE 802.16 WiMAX Protocol Data Block268*/269#define WIMAX_PDBOPTS_FCS 0x01270#define WIMAX_PDBOPTS_AR 0x40 /* decap only */271272struct wimax_encap_pdb {273u8 rsvd[3];274u8 options;275u32 nonce;276u8 b0_flags;277u8 ctr_flags;278u16 ctr_init;279/* begin DECO writeback region */280u32 pn;281/* end DECO writeback region */282};283284struct wimax_decap_pdb {285u8 rsvd[3];286u8 options;287u32 nonce;288u8 iv_flags;289u8 ctr_flags;290u16 ctr_init;291/* begin DECO writeback region */292u32 pn;293u8 rsvd1[2];294u16 antireplay_len;295u64 antireplay_scorecard;296/* end DECO writeback region */297};298299/*300* IEEE 801.AE MacSEC Protocol Data Block301*/302#define MACSEC_PDBOPTS_FCS 0x01303#define MACSEC_PDBOPTS_AR 0x40 /* used in decap only */304305struct macsec_encap_pdb {306u16 aad_len;307u8 rsvd;308u8 options;309u64 sci;310u16 ethertype;311u8 tci_an;312u8 rsvd1;313/* begin DECO writeback region */314u32 pn;315/* end DECO writeback region */316};317318struct macsec_decap_pdb {319u16 aad_len;320u8 rsvd;321u8 options;322u64 sci;323u8 rsvd1[3];324/* begin DECO writeback region */325u8 antireplay_len;326u32 pn;327u64 antireplay_scorecard;328/* end DECO writeback region */329};330331/*332* SSL/TLS/DTLS Protocol Data Blocks333*/334335#define TLS_PDBOPTS_ARS32 0x40336#define TLS_PDBOPTS_ARS64 0xc0337#define TLS_PDBOPTS_OUTFMT 0x08338#define TLS_PDBOPTS_IV_WRTBK 0x02 /* 1.1/1.2/DTLS only */339#define TLS_PDBOPTS_EXP_RND_IV 0x01 /* 1.1/1.2/DTLS only */340341struct tls_block_encap_pdb {342u8 type;343u8 version[2];344u8 options;345u64 seq_num;346u32 iv[4];347};348349struct tls_stream_encap_pdb {350u8 type;351u8 version[2];352u8 options;353u64 seq_num;354u8 i;355u8 j;356u8 rsvd1[2];357};358359struct dtls_block_encap_pdb {360u8 type;361u8 version[2];362u8 options;363u16 epoch;364u16 seq_num[3];365u32 iv[4];366};367368struct tls_block_decap_pdb {369u8 rsvd[3];370u8 options;371u64 seq_num;372u32 iv[4];373};374375struct tls_stream_decap_pdb {376u8 rsvd[3];377u8 options;378u64 seq_num;379u8 i;380u8 j;381u8 rsvd1[2];382};383384struct dtls_block_decap_pdb {385u8 rsvd[3];386u8 options;387u16 epoch;388u16 seq_num[3];389u32 iv[4];390u64 antireplay_scorecard;391};392393/*394* SRTP Protocol Data Blocks395*/396#define SRTP_PDBOPTS_MKI 0x08397#define SRTP_PDBOPTS_AR 0x40398399struct srtp_encap_pdb {400u8 x_len;401u8 mki_len;402u8 n_tag;403u8 options;404u32 cnst0;405u8 rsvd[2];406u16 cnst1;407u16 salt[7];408u16 cnst2;409u32 rsvd1;410u32 roc;411u32 opt_mki;412};413414struct srtp_decap_pdb {415u8 x_len;416u8 mki_len;417u8 n_tag;418u8 options;419u32 cnst0;420u8 rsvd[2];421u16 cnst1;422u16 salt[7];423u16 cnst2;424u16 rsvd1;425u16 seq_num;426u32 roc;427u64 antireplay_scorecard;428};429430/*431* DSA/ECDSA Protocol Data Blocks432* Two of these exist: DSA-SIGN, and DSA-VERIFY. They are similar433* except for the treatment of "w" for verify, "s" for sign,434* and the placement of "a,b".435*/436#define DSA_PDB_SGF_SHIFT 24437#define DSA_PDB_SGF_MASK (0xff << DSA_PDB_SGF_SHIFT)438#define DSA_PDB_SGF_Q (0x80 << DSA_PDB_SGF_SHIFT)439#define DSA_PDB_SGF_R (0x40 << DSA_PDB_SGF_SHIFT)440#define DSA_PDB_SGF_G (0x20 << DSA_PDB_SGF_SHIFT)441#define DSA_PDB_SGF_W (0x10 << DSA_PDB_SGF_SHIFT)442#define DSA_PDB_SGF_S (0x10 << DSA_PDB_SGF_SHIFT)443#define DSA_PDB_SGF_F (0x08 << DSA_PDB_SGF_SHIFT)444#define DSA_PDB_SGF_C (0x04 << DSA_PDB_SGF_SHIFT)445#define DSA_PDB_SGF_D (0x02 << DSA_PDB_SGF_SHIFT)446#define DSA_PDB_SGF_AB_SIGN (0x02 << DSA_PDB_SGF_SHIFT)447#define DSA_PDB_SGF_AB_VERIFY (0x01 << DSA_PDB_SGF_SHIFT)448449#define DSA_PDB_L_SHIFT 7450#define DSA_PDB_L_MASK (0x3ff << DSA_PDB_L_SHIFT)451452#define DSA_PDB_N_MASK 0x7f453454struct dsa_sign_pdb {455u32 sgf_ln; /* Use DSA_PDB_ definitions per above */456u8 *q;457u8 *r;458u8 *g; /* or Gx,y */459u8 *s;460u8 *f;461u8 *c;462u8 *d;463u8 *ab; /* ECC only */464u8 *u;465};466467struct dsa_verify_pdb {468u32 sgf_ln;469u8 *q;470u8 *r;471u8 *g; /* or Gx,y */472u8 *w; /* or Wx,y */473u8 *f;474u8 *c;475u8 *d;476u8 *tmp; /* temporary data block */477u8 *ab; /* only used if ECC processing */478};479480/* RSA Protocol Data Block */481#define RSA_PDB_SGF_SHIFT 28482#define RSA_PDB_E_SHIFT 12483#define RSA_PDB_E_MASK (0xFFF << RSA_PDB_E_SHIFT)484#define RSA_PDB_D_SHIFT 12485#define RSA_PDB_D_MASK (0xFFF << RSA_PDB_D_SHIFT)486#define RSA_PDB_Q_SHIFT 12487#define RSA_PDB_Q_MASK (0xFFF << RSA_PDB_Q_SHIFT)488489#define RSA_PDB_SGF_F (0x8 << RSA_PDB_SGF_SHIFT)490#define RSA_PDB_SGF_G (0x4 << RSA_PDB_SGF_SHIFT)491#define RSA_PRIV_PDB_SGF_F (0x4 << RSA_PDB_SGF_SHIFT)492#define RSA_PRIV_PDB_SGF_G (0x8 << RSA_PDB_SGF_SHIFT)493494#define RSA_PRIV_KEY_FRM_1 0495#define RSA_PRIV_KEY_FRM_2 1496#define RSA_PRIV_KEY_FRM_3 2497498/**499* RSA Encrypt Protocol Data Block500* @sgf: scatter-gather field501* @f_dma: dma address of input data502* @g_dma: dma address of encrypted output data503* @n_dma: dma address of RSA modulus504* @e_dma: dma address of RSA public exponent505* @f_len: length in octets of the input data506*/507struct rsa_pub_pdb {508u32 sgf;509dma_addr_t f_dma;510dma_addr_t g_dma;511dma_addr_t n_dma;512dma_addr_t e_dma;513u32 f_len;514};515516#define SIZEOF_RSA_PUB_PDB (2 * sizeof(u32) + 4 * caam_ptr_sz)517518/**519* RSA Decrypt PDB - Private Key Form #1520* @sgf: scatter-gather field521* @g_dma: dma address of encrypted input data522* @f_dma: dma address of output data523* @n_dma: dma address of RSA modulus524* @d_dma: dma address of RSA private exponent525*/526struct rsa_priv_f1_pdb {527u32 sgf;528dma_addr_t g_dma;529dma_addr_t f_dma;530dma_addr_t n_dma;531dma_addr_t d_dma;532};533534#define SIZEOF_RSA_PRIV_F1_PDB (sizeof(u32) + 4 * caam_ptr_sz)535536/**537* RSA Decrypt PDB - Private Key Form #2538* @sgf : scatter-gather field539* @g_dma : dma address of encrypted input data540* @f_dma : dma address of output data541* @d_dma : dma address of RSA private exponent542* @p_dma : dma address of RSA prime factor p of RSA modulus n543* @q_dma : dma address of RSA prime factor q of RSA modulus n544* @tmp1_dma: dma address of temporary buffer. CAAM uses this temporary buffer545* as internal state buffer. It is assumed to be as long as p.546* @tmp2_dma: dma address of temporary buffer. CAAM uses this temporary buffer547* as internal state buffer. It is assumed to be as long as q.548* @p_q_len : length in bytes of first two prime factors of the RSA modulus n549*/550struct rsa_priv_f2_pdb {551u32 sgf;552dma_addr_t g_dma;553dma_addr_t f_dma;554dma_addr_t d_dma;555dma_addr_t p_dma;556dma_addr_t q_dma;557dma_addr_t tmp1_dma;558dma_addr_t tmp2_dma;559u32 p_q_len;560};561562#define SIZEOF_RSA_PRIV_F2_PDB (2 * sizeof(u32) + 7 * caam_ptr_sz)563564/**565* RSA Decrypt PDB - Private Key Form #3566* This is the RSA Chinese Reminder Theorem (CRT) form for two prime factors of567* the RSA modulus.568* @sgf : scatter-gather field569* @g_dma : dma address of encrypted input data570* @f_dma : dma address of output data571* @c_dma : dma address of RSA CRT coefficient572* @p_dma : dma address of RSA prime factor p of RSA modulus n573* @q_dma : dma address of RSA prime factor q of RSA modulus n574* @dp_dma : dma address of RSA CRT exponent of RSA prime factor p575* @dp_dma : dma address of RSA CRT exponent of RSA prime factor q576* @tmp1_dma: dma address of temporary buffer. CAAM uses this temporary buffer577* as internal state buffer. It is assumed to be as long as p.578* @tmp2_dma: dma address of temporary buffer. CAAM uses this temporary buffer579* as internal state buffer. It is assumed to be as long as q.580* @p_q_len : length in bytes of first two prime factors of the RSA modulus n581*/582struct rsa_priv_f3_pdb {583u32 sgf;584dma_addr_t g_dma;585dma_addr_t f_dma;586dma_addr_t c_dma;587dma_addr_t p_dma;588dma_addr_t q_dma;589dma_addr_t dp_dma;590dma_addr_t dq_dma;591dma_addr_t tmp1_dma;592dma_addr_t tmp2_dma;593u32 p_q_len;594};595596#define SIZEOF_RSA_PRIV_F3_PDB (2 * sizeof(u32) + 9 * caam_ptr_sz)597598#endif599600601