app/crypto-perf: support AES-CCM
authorPablo de Lara <pablo.de.lara.guarch@intel.com>
Thu, 21 Sep 2017 13:11:16 +0000 (14:11 +0100)
committerPablo de Lara <pablo.de.lara.guarch@intel.com>
Thu, 12 Oct 2017 14:15:10 +0000 (15:15 +0100)
According to the API, AES-CCM has special requirements
when setting IV and AAD fields.
The L2fwd-crypto app is updated to set the nonce (IV)
and AAD in the right positions in these two fields
(1 byte after start of IV field and 18 bytes after start
of AAD).

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
app/test-crypto-perf/cperf_ops.c
app/test-crypto-perf/cperf_test_common.c

index f76dbdd..bc6b24f 100644 (file)
@@ -363,6 +363,7 @@ cperf_set_ops_aead(struct rte_crypto_op **ops,
                uint16_t iv_offset)
 {
        uint16_t i;
+       /* AAD is placed after the IV */
        uint16_t aad_offset = iv_offset +
                        RTE_ALIGN_CEIL(test_vector->aead_iv.length, 16);
 
@@ -433,13 +434,26 @@ cperf_set_ops_aead(struct rte_crypto_op **ops,
                        uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ops[i],
                                        uint8_t *, iv_offset);
 
-                       memcpy(iv_ptr, test_vector->aead_iv.data,
+                       /*
+                        * If doing AES-CCM, nonce is copied one byte
+                        * after the start of IV field, and AAD is copied
+                        * 18 bytes after the start of the AAD field.
+                        */
+                       if (options->aead_algo == RTE_CRYPTO_AEAD_AES_CCM) {
+                               memcpy(iv_ptr + 1, test_vector->aead_iv.data,
                                        test_vector->aead_iv.length);
 
-                       /* Copy AAD after the IV */
-                       memcpy(ops[i]->sym->aead.aad.data,
-                               test_vector->aad.data,
-                               test_vector->aad.length);
+                               memcpy(ops[i]->sym->aead.aad.data + 18,
+                                       test_vector->aad.data,
+                                       test_vector->aad.length);
+                       } else {
+                               memcpy(iv_ptr, test_vector->aead_iv.data,
+                                       test_vector->aead_iv.length);
+
+                               memcpy(ops[i]->sym->aead.aad.data,
+                                       test_vector->aad.data,
+                                       test_vector->aad.length);
+                       }
                }
        }
 
index 7ba2087..46e4a46 100644 (file)
@@ -156,11 +156,27 @@ cperf_alloc_common_memory(const struct cperf_options *options,
        /* Calculate the object size */
        uint16_t crypto_op_size = sizeof(struct rte_crypto_op) +
                sizeof(struct rte_crypto_sym_op);
-       uint16_t crypto_op_private_size = extra_op_priv_size +
-                               test_vector->cipher_iv.length +
-                               test_vector->auth_iv.length +
-                               test_vector->aead_iv.length +
-                               options->aead_aad_sz;
+       uint16_t crypto_op_private_size;
+       /*
+        * If doing AES-CCM, IV field needs to be 16 bytes long,
+        * and AAD field needs to be long enough to have 18 bytes,
+        * plus the length of the AAD, and all rounded to a
+        * multiple of 16 bytes.
+        */
+       if (options->aead_algo == RTE_CRYPTO_AEAD_AES_CCM) {
+               crypto_op_private_size = extra_op_priv_size +
+                       test_vector->cipher_iv.length +
+                       test_vector->auth_iv.length +
+                       RTE_ALIGN_CEIL(test_vector->aead_iv.length, 16) +
+                       RTE_ALIGN_CEIL(options->aead_aad_sz + 18, 16);
+       } else {
+               crypto_op_private_size = extra_op_priv_size +
+                       test_vector->cipher_iv.length +
+                       test_vector->auth_iv.length +
+                       test_vector->aead_iv.length +
+                       options->aead_aad_sz;
+       }
+
        uint16_t crypto_op_total_size = crypto_op_size +
                                crypto_op_private_size;
        uint16_t crypto_op_total_size_padded =