]> git.droids-corp.org - dpdk.git/commitdiff
common/cnxk: swap ZUC-256 key
authorAnkur Dwivedi <adwivedi@marvell.com>
Fri, 3 Jun 2022 07:13:06 +0000 (12:43 +0530)
committerAkhil Goyal <gakhil@marvell.com>
Tue, 21 Jun 2022 18:04:49 +0000 (20:04 +0200)
The microcode expects zuc-256 key to be in reverse of what is
provided by dpdk test app. This patch swaps the zuc-256 key.

Signed-off-by: Ankur Dwivedi <adwivedi@marvell.com>
Reviewed-by: Jerin Jacob <jerinj@marvell.com>
drivers/common/cnxk/roc_se.c
drivers/common/cnxk/roc_se.h

index ffe537af302dd8d5e91d6b6bacaa13e28d775d47..3f0821e4005fb828e05d4d7b35186a6b43ed02f0 100644 (file)
@@ -283,6 +283,8 @@ roc_se_auth_key_set(struct roc_se_ctx *se_ctx, roc_se_auth_type type,
                                return ret;
                        se_ctx->pdcp_alg_type = ROC_SE_PDCP_ALG_TYPE_ZUC;
                        memcpy(ci_key, key, key_len);
+                       if (key_len == 32)
+                               roc_se_zuc_bytes_swap(ci_key, key_len);
                        cpt_pdcp_update_zuc_const(zuc_const, key_len, mac_len);
                        se_ctx->fc_type = ROC_SE_PDCP;
                        se_ctx->zsk_flags = 0x1;
@@ -459,9 +461,10 @@ roc_se_ciph_key_set(struct roc_se_ctx *se_ctx, roc_se_cipher_type type,
                zs_ctx->zuc.otk_ctx.w0.s.alg_type = ROC_SE_PDCP_ALG_TYPE_ZUC;
                se_ctx->pdcp_alg_type = ROC_SE_PDCP_ALG_TYPE_ZUC;
                memcpy(ci_key, key, key_len);
-               if (key_len == 32)
+               if (key_len == 32) {
+                       roc_se_zuc_bytes_swap(ci_key, key_len);
                        memcpy(zuc_const, zuc_key256, 16);
-               else
+               else
                        memcpy(zuc_const, zuc_key128, 32);
 
                se_ctx->zsk_flags = 0;
index a1d476a86de7bce33cb7fd0c2b94ba4b6abaac28..c565ec1b741405873820ce92ec4dcb7977831ef0 100644 (file)
@@ -301,6 +301,27 @@ struct roc_se_ctx {
        uint8_t *auth_key;
 };
 
+static inline void
+roc_se_zuc_bytes_swap(uint8_t *arr, int len)
+{
+       int start, end;
+       uint8_t tmp;
+
+       if (len <= 0)
+               return;
+
+       start = 0;
+       end = len - 1;
+
+       while (start < end) {
+               tmp = arr[start];
+               arr[start] = arr[end];
+               arr[end] = tmp;
+               start++;
+               end--;
+       }
+}
+
 int __roc_api roc_se_auth_key_set(struct roc_se_ctx *se_ctx,
                                  roc_se_auth_type type, const uint8_t *key,
                                  uint16_t key_len, uint16_t mac_len);
@@ -310,4 +331,5 @@ int __roc_api roc_se_ciph_key_set(struct roc_se_ctx *se_ctx,
                                  uint16_t key_len, uint8_t *salt);
 
 void __roc_api roc_se_ctx_swap(struct roc_se_ctx *se_ctx);
+
 #endif /* __ROC_SE_H__ */