1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(C) 2023 Marvell. 3 */ 4 5 #include <rte_cryptodev.h> 6 #include <rte_security.h> 7 8 #include "test_security_proto.h" 9 10 struct crypto_param_comb sec_alg_list[RTE_DIM(aead_list) + 11 (RTE_DIM(cipher_list) * 12 RTE_DIM(auth_list))]; 13 14 struct crypto_param_comb sec_auth_only_alg_list[2 * (RTE_DIM(auth_list) - 1)]; 15 16 void 17 test_sec_alg_list_populate(void) 18 { 19 unsigned long i, j, index = 0; 20 21 for (i = 0; i < RTE_DIM(aead_list); i++) { 22 sec_alg_list[index].param1 = &aead_list[i]; 23 sec_alg_list[index].param2 = NULL; 24 index++; 25 } 26 27 for (i = 0; i < RTE_DIM(cipher_list); i++) { 28 for (j = 0; j < RTE_DIM(auth_list); j++) { 29 sec_alg_list[index].param1 = &cipher_list[i]; 30 sec_alg_list[index].param2 = &auth_list[j]; 31 index++; 32 } 33 } 34 } 35 36 void 37 test_sec_auth_only_alg_list_populate(void) 38 { 39 unsigned long i, index = 0; 40 41 for (i = 1; i < RTE_DIM(auth_list); i++) { 42 sec_auth_only_alg_list[index].param1 = &auth_list[i]; 43 sec_auth_only_alg_list[index].param2 = NULL; 44 index++; 45 } 46 47 for (i = 1; i < RTE_DIM(auth_list); i++) { 48 /* NULL cipher */ 49 sec_auth_only_alg_list[index].param1 = &cipher_list[0]; 50 51 sec_auth_only_alg_list[index].param2 = &auth_list[i]; 52 index++; 53 } 54 } 55 56 int 57 test_sec_crypto_caps_aead_verify(const struct rte_security_capability *sec_cap, 58 struct rte_crypto_sym_xform *aead) 59 { 60 const struct rte_cryptodev_symmetric_capability *sym_cap; 61 const struct rte_cryptodev_capabilities *crypto_cap; 62 int j = 0; 63 64 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 65 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 66 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 67 crypto_cap->sym.xform_type == aead->type && 68 crypto_cap->sym.aead.algo == aead->aead.algo) { 69 sym_cap = &crypto_cap->sym; 70 if (rte_cryptodev_sym_capability_check_aead(sym_cap, 71 aead->aead.key.length, 72 aead->aead.digest_length, 73 aead->aead.aad_length, 74 aead->aead.iv.length) == 0) 75 return 0; 76 } 77 } 78 79 return -ENOTSUP; 80 } 81 82 int 83 test_sec_crypto_caps_cipher_verify(const struct rte_security_capability *sec_cap, 84 struct rte_crypto_sym_xform *cipher) 85 { 86 const struct rte_cryptodev_symmetric_capability *sym_cap; 87 const struct rte_cryptodev_capabilities *cap; 88 int j = 0; 89 90 while ((cap = &sec_cap->crypto_capabilities[j++])->op != 91 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 92 if (cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 93 cap->sym.xform_type == cipher->type && 94 cap->sym.cipher.algo == cipher->cipher.algo) { 95 sym_cap = &cap->sym; 96 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 97 cipher->cipher.key.length, 98 cipher->cipher.iv.length) == 0) 99 return 0; 100 } 101 } 102 103 return -ENOTSUP; 104 } 105 106 int 107 test_sec_crypto_caps_auth_verify(const struct rte_security_capability *sec_cap, 108 struct rte_crypto_sym_xform *auth) 109 { 110 const struct rte_cryptodev_symmetric_capability *sym_cap; 111 const struct rte_cryptodev_capabilities *cap; 112 int j = 0; 113 114 while ((cap = &sec_cap->crypto_capabilities[j++])->op != 115 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 116 if (cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 117 cap->sym.xform_type == auth->type && 118 cap->sym.auth.algo == auth->auth.algo) { 119 sym_cap = &cap->sym; 120 if (rte_cryptodev_sym_capability_check_auth(sym_cap, 121 auth->auth.key.length, 122 auth->auth.digest_length, 123 auth->auth.iv.length) == 0) 124 return 0; 125 } 126 } 127 128 return -ENOTSUP; 129 } 130 131 void 132 test_sec_alg_display(const struct crypto_param *param1, const struct crypto_param *param2) 133 { 134 if (param1->type == RTE_CRYPTO_SYM_XFORM_AEAD) { 135 printf("\t%s [%d]", 136 rte_cryptodev_get_aead_algo_string(param1->alg.aead), 137 param1->key_length * 8); 138 } else if (param1->type == RTE_CRYPTO_SYM_XFORM_AUTH) { 139 printf("\t%s", 140 rte_cryptodev_get_auth_algo_string(param1->alg.auth)); 141 if (param1->alg.auth != RTE_CRYPTO_AUTH_NULL) 142 printf(" [%dB ICV]", param1->digest_length); 143 } else { 144 printf("\t%s", 145 rte_cryptodev_get_cipher_algo_string(param1->alg.cipher)); 146 if (param1->alg.cipher != RTE_CRYPTO_CIPHER_NULL) 147 printf(" [%d]", param1->key_length * 8); 148 printf(" %s", 149 rte_cryptodev_get_auth_algo_string(param2->alg.auth)); 150 if (param2->alg.auth != RTE_CRYPTO_AUTH_NULL) 151 printf(" [%dB ICV]", param2->digest_length); 152 } 153 printf("\n"); 154 } 155