X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Flibrte_ipsec%2Fcrypto.h;h=f8fbf8d4f3282b291109da30d507d2984bab8b98;hb=84191ddeb53dcabb2567422ebf4612dea14d2471;hp=61f5c143376da987a1fa6aa1e61e08f20a8b2145;hpb=4d7ea3e1459b7df218534eb802c13f89ff867c54;p=dpdk.git diff --git a/lib/librte_ipsec/crypto.h b/lib/librte_ipsec/crypto.h index 61f5c14337..f8fbf8d4f3 100644 --- a/lib/librte_ipsec/crypto.h +++ b/lib/librte_ipsec/crypto.h @@ -11,6 +11,16 @@ * by ipsec library. */ +/* + * AES-CTR counter block format. + */ + +struct aesctr_cnt_blk { + uint32_t nonce; + uint64_t iv; + uint32_t cnt; +} __attribute__((packed)); + /* * AES-GCM devices have some specific requirements for IV and AAD formats. * Ideally that to be done by the driver itself. @@ -37,10 +47,17 @@ struct aead_gcm_aad { } __attribute__((packed)); struct gcm_esph_iv { - struct esp_hdr esph; + struct rte_esp_hdr esph; uint64_t iv; } __attribute__((packed)); +static inline void +aes_ctr_cnt_blk_fill(struct aesctr_cnt_blk *ctr, uint64_t iv, uint32_t nonce) +{ + ctr->nonce = nonce; + ctr->iv = iv; + ctr->cnt = rte_cpu_to_be_32(1); +} static inline void aead_gcm_iv_fill(struct aead_gcm_iv *gcm, uint64_t iv, uint32_t salt) @@ -76,6 +93,31 @@ gen_iv(uint64_t iv[IPSEC_MAX_IV_QWORD], rte_be64_t sqn) iv[1] = 0; } +/* + * Helper routine to copy IV + * Right now we support only algorithms with IV length equals 0/8/16 bytes. + */ +static inline void +copy_iv(uint64_t dst[IPSEC_MAX_IV_QWORD], + const uint64_t src[IPSEC_MAX_IV_QWORD], uint32_t len) +{ + RTE_BUILD_BUG_ON(IPSEC_MAX_IV_SIZE != 2 * sizeof(uint64_t)); + + switch (len) { + case IPSEC_MAX_IV_SIZE: + dst[1] = src[1]; + /* fallthrough */ + case sizeof(uint64_t): + dst[0] = src[0]; + /* fallthrough */ + case 0: + break; + default: + /* should never happen */ + RTE_ASSERT(NULL); + } +} + /* * from RFC 4303 3.3.2.1.4: * If the ESN option is enabled for the SA, the high-order 32 @@ -120,4 +162,21 @@ remove_sqh(void *picv, uint32_t icv_len) icv[i] = icv[i + 1]; } +/* + * setup crypto ops for LOOKASIDE_NONE (pure crypto) type of devices. + */ +static inline void +lksd_none_cop_prepare(struct rte_crypto_op *cop, + struct rte_cryptodev_sym_session *cs, struct rte_mbuf *mb) +{ + struct rte_crypto_sym_op *sop; + + sop = cop->sym; + cop->type = RTE_CRYPTO_OP_TYPE_SYMMETRIC; + cop->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED; + cop->sess_type = RTE_CRYPTO_OP_WITH_SESSION; + sop->m_src = mb; + __rte_crypto_sym_op_attach_sym_session(sop, cs); +} + #endif /* _CRYPTO_H_ */