LCOV - code coverage report
Current view: top level - app/test - test_security_proto.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 70 0.0 %
Date: 2024-03-01 20:19:12 Functions: 0 6 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 50 0.0 %

           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                 :            : void
      17                 :          0 : test_sec_alg_list_populate(void)
      18                 :            : {
      19                 :            :         unsigned long i, j, index = 0;
      20                 :            : 
      21         [ #  # ]:          0 :         for (i = 0; i < RTE_DIM(aead_list); i++) {
      22                 :          0 :                 sec_alg_list[index].param1 = &aead_list[i];
      23                 :          0 :                 sec_alg_list[index].param2 = NULL;
      24                 :          0 :                 index++;
      25                 :            :         }
      26                 :            : 
      27         [ #  # ]:          0 :         for (i = 0; i < RTE_DIM(cipher_list); i++) {
      28         [ #  # ]:          0 :                 for (j = 0; j < RTE_DIM(auth_list); j++) {
      29                 :          0 :                         sec_alg_list[index].param1 = &cipher_list[i];
      30                 :          0 :                         sec_alg_list[index].param2 = &auth_list[j];
      31                 :          0 :                         index++;
      32                 :            :                 }
      33                 :            :         }
      34                 :          0 : }
      35                 :            : 
      36                 :            : void
      37                 :          0 : test_sec_auth_only_alg_list_populate(void)
      38                 :            : {
      39                 :            :         unsigned long i, index = 0;
      40                 :            : 
      41         [ #  # ]:          0 :         for (i = 1; i < RTE_DIM(auth_list); i++) {
      42                 :          0 :                 sec_auth_only_alg_list[index].param1 = &auth_list[i];
      43                 :          0 :                 sec_auth_only_alg_list[index].param2 = NULL;
      44                 :          0 :                 index++;
      45                 :            :         }
      46                 :            : 
      47         [ #  # ]:          0 :         for (i = 1; i < RTE_DIM(auth_list); i++) {
      48                 :            :                 /* NULL cipher */
      49                 :          0 :                 sec_auth_only_alg_list[index].param1 = &cipher_list[0];
      50                 :            : 
      51                 :          0 :                 sec_auth_only_alg_list[index].param2 = &auth_list[i];
      52                 :          0 :                 index++;
      53                 :            :         }
      54                 :          0 : }
      55                 :            : 
      56                 :            : int
      57                 :          0 : 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         [ #  # ]:          0 :         while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
      65                 :            :                         RTE_CRYPTO_OP_TYPE_UNDEFINED) {
      66         [ #  # ]:          0 :                 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
      67         [ #  # ]:          0 :                                 crypto_cap->sym.xform_type == aead->type &&
      68         [ #  # ]:          0 :                                 crypto_cap->sym.aead.algo == aead->aead.algo) {
      69                 :          0 :                         sym_cap = &crypto_cap->sym;
      70         [ #  # ]:          0 :                         if (rte_cryptodev_sym_capability_check_aead(sym_cap,
      71                 :          0 :                                         aead->aead.key.length,
      72                 :          0 :                                         aead->aead.digest_length,
      73                 :          0 :                                         aead->aead.aad_length,
      74                 :          0 :                                         aead->aead.iv.length) == 0)
      75                 :            :                                 return 0;
      76                 :            :                 }
      77                 :            :         }
      78                 :            : 
      79                 :            :         return -ENOTSUP;
      80                 :            : }
      81                 :            : 
      82                 :            : int
      83                 :          0 : 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         [ #  # ]:          0 :         while ((cap = &sec_cap->crypto_capabilities[j++])->op !=
      91                 :            :                         RTE_CRYPTO_OP_TYPE_UNDEFINED) {
      92         [ #  # ]:          0 :                 if (cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
      93         [ #  # ]:          0 :                                 cap->sym.xform_type == cipher->type &&
      94         [ #  # ]:          0 :                                 cap->sym.cipher.algo == cipher->cipher.algo) {
      95                 :          0 :                         sym_cap = &cap->sym;
      96         [ #  # ]:          0 :                         if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
      97                 :          0 :                                         cipher->cipher.key.length,
      98                 :          0 :                                         cipher->cipher.iv.length) == 0)
      99                 :            :                                 return 0;
     100                 :            :                 }
     101                 :            :         }
     102                 :            : 
     103                 :            :         return -ENOTSUP;
     104                 :            : }
     105                 :            : 
     106                 :            : int
     107                 :          0 : 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         [ #  # ]:          0 :         while ((cap = &sec_cap->crypto_capabilities[j++])->op !=
     115                 :            :                         RTE_CRYPTO_OP_TYPE_UNDEFINED) {
     116         [ #  # ]:          0 :                 if (cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
     117         [ #  # ]:          0 :                                 cap->sym.xform_type == auth->type &&
     118         [ #  # ]:          0 :                                 cap->sym.auth.algo == auth->auth.algo) {
     119                 :          0 :                         sym_cap = &cap->sym;
     120         [ #  # ]:          0 :                         if (rte_cryptodev_sym_capability_check_auth(sym_cap,
     121                 :          0 :                                         auth->auth.key.length,
     122                 :          0 :                                         auth->auth.digest_length,
     123                 :          0 :                                         auth->auth.iv.length) == 0)
     124                 :            :                                 return 0;
     125                 :            :                 }
     126                 :            :         }
     127                 :            : 
     128                 :            :         return -ENOTSUP;
     129                 :            : }
     130                 :            : 
     131                 :            : void
     132                 :          0 : test_sec_alg_display(const struct crypto_param *param1, const struct crypto_param *param2)
     133                 :            : {
     134         [ #  # ]:          0 :         if (param1->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
     135                 :          0 :                 printf("\t%s [%d]",
     136                 :          0 :                        rte_cryptodev_get_aead_algo_string(param1->alg.aead),
     137                 :          0 :                        param1->key_length * 8);
     138         [ #  # ]:          0 :         } else if (param1->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
     139                 :          0 :                 printf("\t%s",
     140                 :          0 :                        rte_cryptodev_get_auth_algo_string(param1->alg.auth));
     141         [ #  # ]:          0 :                 if (param1->alg.auth != RTE_CRYPTO_AUTH_NULL)
     142                 :          0 :                         printf(" [%dB ICV]", param1->digest_length);
     143                 :            :         } else {
     144                 :          0 :                 printf("\t%s",
     145                 :          0 :                        rte_cryptodev_get_cipher_algo_string(param1->alg.cipher));
     146         [ #  # ]:          0 :                 if (param1->alg.cipher != RTE_CRYPTO_CIPHER_NULL)
     147                 :          0 :                         printf(" [%d]", param1->key_length * 8);
     148                 :          0 :                 printf(" %s",
     149                 :          0 :                        rte_cryptodev_get_auth_algo_string(param2->alg.auth));
     150         [ #  # ]:          0 :                 if (param2->alg.auth != RTE_CRYPTO_AUTH_NULL)
     151                 :          0 :                         printf(" [%dB ICV]", param2->digest_length);
     152                 :            :         }
     153                 :            :         printf("\n");
     154                 :          0 : }

Generated by: LCOV version 1.14