Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(C) 2021 Marvell. 3 : : */ 4 : : #ifndef __CNXK_IPSEC_H__ 5 : : #define __CNXK_IPSEC_H__ 6 : : 7 : : #include <rte_security.h> 8 : : #include <rte_security_driver.h> 9 : : 10 : : #include "roc_cpt.h" 11 : : #include "roc_ie_on.h" 12 : : #include "roc_ie_ot.h" 13 : : #include "roc_ie_ow.h" 14 : : #include "roc_model.h" 15 : : 16 : : extern struct rte_security_ops cnxk_sec_ops; 17 : : 18 : : struct cnxk_cpt_inst_tmpl { 19 : : uint64_t w2; 20 : : uint64_t w4; 21 : : uint64_t w7; 22 : : }; 23 : : 24 : : static inline int 25 : 0 : ipsec_xform_cipher_verify(struct rte_crypto_sym_xform *crypto_xform) 26 : : { 27 [ # # ]: 0 : if (crypto_xform->cipher.algo == RTE_CRYPTO_CIPHER_NULL) 28 : : return 0; 29 : : 30 [ # # ]: 0 : if (crypto_xform->cipher.algo == RTE_CRYPTO_CIPHER_DES_CBC && 31 [ # # ]: 0 : crypto_xform->cipher.key.length == 8) 32 : : return 0; 33 : : 34 [ # # ]: 0 : if (crypto_xform->cipher.algo == RTE_CRYPTO_CIPHER_AES_CBC || 35 : : crypto_xform->cipher.algo == RTE_CRYPTO_CIPHER_AES_CTR) { 36 [ # # ]: 0 : switch (crypto_xform->cipher.key.length) { 37 : : case 16: 38 : : case 24: 39 : : case 32: 40 : : break; 41 : : default: 42 : : return -ENOTSUP; 43 : : } 44 : 0 : return 0; 45 : : } 46 : : 47 [ # # ]: 0 : if (crypto_xform->cipher.algo == RTE_CRYPTO_CIPHER_3DES_CBC && 48 [ # # ]: 0 : crypto_xform->cipher.key.length == 24) 49 : 0 : return 0; 50 : : 51 : : return -ENOTSUP; 52 : : } 53 : : 54 : : static inline int 55 : 0 : ipsec_xform_auth_verify(struct rte_crypto_sym_xform *crypto_xform) 56 : : { 57 : 0 : uint16_t keylen = crypto_xform->auth.key.length; 58 : : 59 [ # # ]: 0 : if (crypto_xform->auth.algo == RTE_CRYPTO_AUTH_NULL) 60 : : return 0; 61 : : 62 [ # # ]: 0 : if (crypto_xform->auth.algo == RTE_CRYPTO_AUTH_MD5_HMAC) { 63 [ # # ]: 0 : if (keylen == 16) 64 : : return 0; 65 : : } 66 : : 67 : : if (crypto_xform->auth.algo == RTE_CRYPTO_AUTH_SHA1_HMAC) { 68 [ # # ]: 0 : if (keylen >= 20 && keylen <= 64) 69 : : return 0; 70 : : } else if (crypto_xform->auth.algo == RTE_CRYPTO_AUTH_SHA256_HMAC) { 71 [ # # ]: 0 : if (keylen >= 32 && keylen <= 64) 72 : : return 0; 73 : : } else if (crypto_xform->auth.algo == RTE_CRYPTO_AUTH_SHA384_HMAC) { 74 [ # # ]: 0 : if (keylen == 48) 75 : : return 0; 76 : : } else if (crypto_xform->auth.algo == RTE_CRYPTO_AUTH_SHA512_HMAC) { 77 [ # # ]: 0 : if (keylen == 64) 78 : : return 0; 79 : : } else if (crypto_xform->auth.algo == RTE_CRYPTO_AUTH_AES_GMAC) { 80 [ # # ]: 0 : if (keylen >= 16 && keylen <= 32) 81 : : return 0; 82 : : } 83 : : 84 [ # # # # ]: 0 : if (crypto_xform->auth.algo == RTE_CRYPTO_AUTH_AES_XCBC_MAC && 85 : : keylen == ROC_CPT_AES_XCBC_KEY_LENGTH) 86 : 0 : return 0; 87 : : 88 : : return -ENOTSUP; 89 : : } 90 : : 91 : : static inline int 92 : 0 : ipsec_xform_aead_verify(struct rte_security_ipsec_xform *ipsec_xform, 93 : : struct rte_crypto_sym_xform *crypto_xform) 94 : : { 95 [ # # ]: 0 : if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS && 96 [ # # ]: 0 : crypto_xform->aead.op != RTE_CRYPTO_AEAD_OP_ENCRYPT) 97 : : return -EINVAL; 98 : : 99 [ # # ]: 0 : if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS && 100 [ # # ]: 0 : crypto_xform->aead.op != RTE_CRYPTO_AEAD_OP_DECRYPT) 101 : : return -EINVAL; 102 : : 103 [ # # ]: 0 : if (crypto_xform->aead.algo == RTE_CRYPTO_AEAD_AES_GCM || 104 : : crypto_xform->aead.algo == RTE_CRYPTO_AEAD_AES_CCM) { 105 [ # # ]: 0 : switch (crypto_xform->aead.key.length) { 106 : : case 16: 107 : : case 24: 108 : : case 32: 109 : : break; 110 : : default: 111 : : return -EINVAL; 112 : : } 113 : 0 : return 0; 114 : : } 115 : : 116 : : return -ENOTSUP; 117 : : } 118 : : 119 : : static inline int 120 : 0 : cnxk_ipsec_xform_verify(struct rte_security_ipsec_xform *ipsec_xform, 121 : : struct rte_crypto_sym_xform *crypto_xform) 122 : : { 123 : : struct rte_crypto_sym_xform *auth_xform, *cipher_xform; 124 : : int ret; 125 : : 126 [ # # ]: 0 : if ((ipsec_xform->direction != RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && 127 : : (ipsec_xform->direction != RTE_SECURITY_IPSEC_SA_DIR_EGRESS)) 128 : : return -EINVAL; 129 : : 130 [ # # ]: 0 : if ((ipsec_xform->proto != RTE_SECURITY_IPSEC_SA_PROTO_ESP) && 131 : : (ipsec_xform->proto != RTE_SECURITY_IPSEC_SA_PROTO_AH)) 132 : : return -EINVAL; 133 : : 134 [ # # ]: 0 : if ((ipsec_xform->mode != RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT) && 135 : : (ipsec_xform->mode != RTE_SECURITY_IPSEC_SA_MODE_TUNNEL)) 136 : : return -EINVAL; 137 : : 138 [ # # ]: 0 : if ((ipsec_xform->mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL) && 139 [ # # # # ]: 0 : (ipsec_xform->tunnel.type != RTE_SECURITY_IPSEC_TUNNEL_IPV4) && 140 : : (ipsec_xform->tunnel.type != RTE_SECURITY_IPSEC_TUNNEL_IPV6)) 141 : : return -EINVAL; 142 : : 143 [ # # ]: 0 : if (crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AEAD) 144 : 0 : return ipsec_xform_aead_verify(ipsec_xform, crypto_xform); 145 : : 146 [ # # ]: 0 : if (ipsec_xform->proto == RTE_SECURITY_IPSEC_SA_PROTO_AH) { 147 [ # # ]: 0 : if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) { 148 : : /* Ingress */ 149 : : auth_xform = crypto_xform; 150 : 0 : cipher_xform = crypto_xform->next; 151 : : 152 [ # # ]: 0 : if (crypto_xform->type != RTE_CRYPTO_SYM_XFORM_AUTH) 153 : : return -EINVAL; 154 : : 155 [ # # # # ]: 0 : if ((cipher_xform != NULL) && ((cipher_xform->type != 156 : 0 : RTE_CRYPTO_SYM_XFORM_CIPHER) || 157 [ # # ]: 0 : (cipher_xform->cipher.algo != 158 : : RTE_CRYPTO_CIPHER_NULL))) 159 : : return -EINVAL; 160 : : } else { 161 : : /* Egress */ 162 [ # # ]: 0 : if (crypto_xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) { 163 : : cipher_xform = crypto_xform; 164 : 0 : auth_xform = crypto_xform->next; 165 : : 166 [ # # ]: 0 : if (auth_xform == NULL || 167 [ # # ]: 0 : cipher_xform->cipher.algo != 168 : : RTE_CRYPTO_CIPHER_NULL) 169 : : return -EINVAL; 170 [ # # ]: 0 : } else if (crypto_xform->type == 171 : : RTE_CRYPTO_SYM_XFORM_AUTH) 172 : : auth_xform = crypto_xform; 173 : : else 174 : : return -EINVAL; 175 : : } 176 : : } else { 177 [ # # ]: 0 : if (crypto_xform->next == NULL) 178 : : return -EINVAL; 179 : : 180 [ # # ]: 0 : if (ipsec_xform->direction == 181 : : RTE_SECURITY_IPSEC_SA_DIR_INGRESS) { 182 : : /* Ingress */ 183 [ # # ]: 0 : if (crypto_xform->type != RTE_CRYPTO_SYM_XFORM_AUTH || 184 [ # # ]: 0 : crypto_xform->next->type != 185 : : RTE_CRYPTO_SYM_XFORM_CIPHER) 186 : : return -EINVAL; 187 : : auth_xform = crypto_xform; 188 : : cipher_xform = crypto_xform->next; 189 : : } else { 190 : : /* Egress */ 191 [ # # ]: 0 : if (crypto_xform->type != RTE_CRYPTO_SYM_XFORM_CIPHER || 192 [ # # ]: 0 : crypto_xform->next->type != 193 : : RTE_CRYPTO_SYM_XFORM_AUTH) 194 : : return -EINVAL; 195 : : cipher_xform = crypto_xform; 196 : : auth_xform = crypto_xform->next; 197 : : } 198 : : 199 : 0 : ret = ipsec_xform_cipher_verify(cipher_xform); 200 [ # # ]: 0 : if (ret) 201 : : return ret; 202 : : } 203 : : 204 : 0 : return ipsec_xform_auth_verify(auth_xform); 205 : : } 206 : : #endif /* __CNXK_IPSEC_H__ */