1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2021 Marvell.
4 #ifndef __CNXK_IPSEC_H__
5 #define __CNXK_IPSEC_H__
7 #include <rte_security.h>
8 #include <rte_security_driver.h>
12 extern struct rte_security_ops cnxk_sec_ops;
14 struct cnxk_cpt_inst_tmpl {
21 ipsec_xform_cipher_verify(struct rte_crypto_sym_xform *crypto_xform)
23 if (crypto_xform->cipher.algo == RTE_CRYPTO_CIPHER_AES_CBC) {
24 switch (crypto_xform->cipher.key.length) {
39 ipsec_xform_auth_verify(struct rte_crypto_sym_xform *crypto_xform)
41 uint16_t keylen = crypto_xform->auth.key.length;
43 if (crypto_xform->auth.algo == RTE_CRYPTO_AUTH_SHA1_HMAC) {
44 if (keylen >= 20 && keylen <= 64)
46 } else if (roc_model_is_cn9k() &&
47 (crypto_xform->auth.algo == RTE_CRYPTO_AUTH_SHA256_HMAC)) {
48 if (keylen >= 32 && keylen <= 64)
56 ipsec_xform_aead_verify(struct rte_security_ipsec_xform *ipsec_xform,
57 struct rte_crypto_sym_xform *crypto_xform)
59 if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS &&
60 crypto_xform->aead.op != RTE_CRYPTO_AEAD_OP_ENCRYPT)
63 if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS &&
64 crypto_xform->aead.op != RTE_CRYPTO_AEAD_OP_DECRYPT)
67 if (crypto_xform->aead.algo == RTE_CRYPTO_AEAD_AES_GCM) {
68 switch (crypto_xform->aead.key.length) {
83 cnxk_ipsec_xform_verify(struct rte_security_ipsec_xform *ipsec_xform,
84 struct rte_crypto_sym_xform *crypto_xform)
86 struct rte_crypto_sym_xform *auth_xform, *cipher_xform;
89 if ((ipsec_xform->direction != RTE_SECURITY_IPSEC_SA_DIR_INGRESS) &&
90 (ipsec_xform->direction != RTE_SECURITY_IPSEC_SA_DIR_EGRESS))
93 if ((ipsec_xform->proto != RTE_SECURITY_IPSEC_SA_PROTO_ESP) &&
94 (ipsec_xform->proto != RTE_SECURITY_IPSEC_SA_PROTO_AH))
97 if ((ipsec_xform->mode != RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT) &&
98 (ipsec_xform->mode != RTE_SECURITY_IPSEC_SA_MODE_TUNNEL))
101 if ((ipsec_xform->mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL) &&
102 (ipsec_xform->tunnel.type != RTE_SECURITY_IPSEC_TUNNEL_IPV4) &&
103 (ipsec_xform->tunnel.type != RTE_SECURITY_IPSEC_TUNNEL_IPV6))
106 if (crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AEAD)
107 return ipsec_xform_aead_verify(ipsec_xform, crypto_xform);
109 if (crypto_xform->next == NULL)
112 if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) {
114 if (crypto_xform->type != RTE_CRYPTO_SYM_XFORM_AUTH ||
115 crypto_xform->next->type != RTE_CRYPTO_SYM_XFORM_CIPHER)
117 auth_xform = crypto_xform;
118 cipher_xform = crypto_xform->next;
121 if (crypto_xform->type != RTE_CRYPTO_SYM_XFORM_CIPHER ||
122 crypto_xform->next->type != RTE_CRYPTO_SYM_XFORM_AUTH)
124 cipher_xform = crypto_xform;
125 auth_xform = crypto_xform->next;
128 ret = ipsec_xform_cipher_verify(cipher_xform);
132 return ipsec_xform_auth_verify(auth_xform);
134 #endif /* __CNXK_IPSEC_H__ */