Branch data Line data Source code
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 : : static uint8_t cleartext_pattern[TEST_SEC_CLEARTEXT_MAX_LEN]; 17 : : 18 : : void 19 : 0 : test_sec_alg_list_populate(void) 20 : : { 21 : : unsigned long i, j, index = 0; 22 : : 23 [ # # ]: 0 : for (i = 0; i < RTE_DIM(aead_list); i++) { 24 : 0 : sec_alg_list[index].param1 = &aead_list[i]; 25 : 0 : sec_alg_list[index].param2 = NULL; 26 : 0 : index++; 27 : : } 28 : : 29 [ # # ]: 0 : for (i = 0; i < RTE_DIM(cipher_list); i++) { 30 [ # # ]: 0 : for (j = 0; j < RTE_DIM(auth_list); j++) { 31 : 0 : sec_alg_list[index].param1 = &cipher_list[i]; 32 : 0 : sec_alg_list[index].param2 = &auth_list[j]; 33 : 0 : index++; 34 : : } 35 : : } 36 : 0 : } 37 : : 38 : : void 39 : 0 : test_sec_auth_only_alg_list_populate(void) 40 : : { 41 : : unsigned long i, index = 0; 42 : : 43 [ # # ]: 0 : for (i = 1; i < RTE_DIM(auth_list); i++) { 44 : 0 : sec_auth_only_alg_list[index].param1 = &auth_list[i]; 45 : 0 : sec_auth_only_alg_list[index].param2 = NULL; 46 : 0 : index++; 47 : : } 48 : : 49 [ # # ]: 0 : for (i = 1; i < RTE_DIM(auth_list); i++) { 50 : : /* NULL cipher */ 51 : 0 : sec_auth_only_alg_list[index].param1 = &cipher_list[0]; 52 : : 53 : 0 : sec_auth_only_alg_list[index].param2 = &auth_list[i]; 54 : 0 : index++; 55 : : } 56 : 0 : } 57 : : 58 : : int 59 : 0 : test_sec_crypto_caps_aead_verify(const struct rte_security_capability *sec_cap, 60 : : struct rte_crypto_sym_xform *aead) 61 : : { 62 : : const struct rte_cryptodev_symmetric_capability *sym_cap; 63 : : const struct rte_cryptodev_capabilities *crypto_cap; 64 : : int j = 0; 65 : : 66 [ # # ]: 0 : while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 67 : : RTE_CRYPTO_OP_TYPE_UNDEFINED) { 68 [ # # ]: 0 : if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 69 [ # # ]: 0 : crypto_cap->sym.xform_type == aead->type && 70 [ # # ]: 0 : crypto_cap->sym.aead.algo == aead->aead.algo) { 71 : 0 : sym_cap = &crypto_cap->sym; 72 [ # # ]: 0 : if (rte_cryptodev_sym_capability_check_aead(sym_cap, 73 : 0 : aead->aead.key.length, 74 : 0 : aead->aead.digest_length, 75 : 0 : aead->aead.aad_length, 76 : 0 : aead->aead.iv.length) == 0) 77 : : return 0; 78 : : } 79 : : } 80 : : 81 : : return -ENOTSUP; 82 : : } 83 : : 84 : : int 85 : 0 : test_sec_crypto_caps_cipher_verify(const struct rte_security_capability *sec_cap, 86 : : struct rte_crypto_sym_xform *cipher) 87 : : { 88 : : const struct rte_cryptodev_symmetric_capability *sym_cap; 89 : : const struct rte_cryptodev_capabilities *cap; 90 : : int j = 0; 91 : : 92 [ # # ]: 0 : while ((cap = &sec_cap->crypto_capabilities[j++])->op != 93 : : RTE_CRYPTO_OP_TYPE_UNDEFINED) { 94 [ # # ]: 0 : if (cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 95 [ # # ]: 0 : cap->sym.xform_type == cipher->type && 96 [ # # ]: 0 : cap->sym.cipher.algo == cipher->cipher.algo) { 97 : 0 : sym_cap = &cap->sym; 98 [ # # ]: 0 : if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 99 : 0 : cipher->cipher.key.length, 100 : 0 : cipher->cipher.iv.length) == 0) 101 : : return 0; 102 : : } 103 : : } 104 : : 105 : : return -ENOTSUP; 106 : : } 107 : : 108 : : int 109 : 0 : test_sec_crypto_caps_auth_verify(const struct rte_security_capability *sec_cap, 110 : : struct rte_crypto_sym_xform *auth) 111 : : { 112 : : const struct rte_cryptodev_symmetric_capability *sym_cap; 113 : : const struct rte_cryptodev_capabilities *cap; 114 : : int j = 0; 115 : : 116 [ # # ]: 0 : while ((cap = &sec_cap->crypto_capabilities[j++])->op != 117 : : RTE_CRYPTO_OP_TYPE_UNDEFINED) { 118 [ # # ]: 0 : if (cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 119 [ # # ]: 0 : cap->sym.xform_type == auth->type && 120 [ # # ]: 0 : cap->sym.auth.algo == auth->auth.algo) { 121 : 0 : sym_cap = &cap->sym; 122 [ # # ]: 0 : if (rte_cryptodev_sym_capability_check_auth(sym_cap, 123 : 0 : auth->auth.key.length, 124 : 0 : auth->auth.digest_length, 125 : 0 : auth->auth.iv.length) == 0) 126 : : return 0; 127 : : } 128 : : } 129 : : 130 : : return -ENOTSUP; 131 : : } 132 : : 133 : : void 134 : 0 : test_sec_alg_display(const struct crypto_param *param1, const struct crypto_param *param2) 135 : : { 136 [ # # ]: 0 : if (param1->type == RTE_CRYPTO_SYM_XFORM_AEAD) { 137 : 0 : printf("\t%s [%d]", 138 : 0 : rte_cryptodev_get_aead_algo_string(param1->alg.aead), 139 : 0 : param1->key_length * 8); 140 [ # # ]: 0 : } else if (param1->type == RTE_CRYPTO_SYM_XFORM_AUTH) { 141 : 0 : printf("\t%s", 142 : 0 : rte_cryptodev_get_auth_algo_string(param1->alg.auth)); 143 [ # # ]: 0 : if (param1->alg.auth != RTE_CRYPTO_AUTH_NULL) 144 : 0 : printf(" [%dB ICV]", param1->digest_length); 145 : : } else { 146 : 0 : printf("\t%s", 147 : 0 : rte_cryptodev_get_cipher_algo_string(param1->alg.cipher)); 148 [ # # ]: 0 : if (param1->alg.cipher != RTE_CRYPTO_CIPHER_NULL) 149 : 0 : printf(" [%d]", param1->key_length * 8); 150 : 0 : printf(" %s", 151 : 0 : rte_cryptodev_get_auth_algo_string(param2->alg.auth)); 152 [ # # ]: 0 : if (param2->alg.auth != RTE_CRYPTO_AUTH_NULL) 153 : 0 : printf(" [%dB ICV]", param2->digest_length); 154 : : } 155 : : printf("\n"); 156 : 0 : } 157 : : 158 : : void 159 : 3 : test_sec_proto_pattern_generate(void) 160 : : { 161 : : unsigned int i; 162 : : 163 [ + + ]: 52227 : for (i = 0; i < TEST_SEC_CLEARTEXT_MAX_LEN; i++) 164 : 52224 : cleartext_pattern[i] = (i + 1) & 0xff; 165 : 3 : } 166 : : 167 : : void 168 : 0 : test_sec_proto_pattern_set(uint8_t *buf, int len) 169 : : { 170 [ # # ]: 0 : rte_memcpy(buf, cleartext_pattern, len); 171 : 0 : }