1 From 249c8d98ea339325dca481d5dae93686cd494059 Mon Sep 17 00:00:00 2001
2 From: Christian Lamparter <chunkeey@googlemail.com>
3 Date: Fri, 25 Aug 2017 15:47:20 +0200
4 Subject: [PATCH 07/25] crypto: crypto4xx - move and refactor dynamic_contents
7 This patch refactors and moves the dynamic_contents helper
8 functions into the crypto4xx_sa.h header file.
10 * get_dynamic_sa_iv_size is no longer needed, as the cryptoapi
11 provides the required IV size information as well.
13 * refactor the function declarations to use the a pointer to the
14 dynamic_sa_contents union, instead of the crypto4xx_ctx.
16 * rename get_dynamic_sa_offset_key_field to get_dynamic_sa_key_field.
17 It returns the pointer to the key directly.
19 Signed-off-by: Christian Lamparter <chunkeey@googlemail.com>
20 Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
22 drivers/crypto/amcc/Makefile | 2 +-
23 drivers/crypto/amcc/crypto4xx_alg.c | 20 ++++-----
24 drivers/crypto/amcc/crypto4xx_core.h | 3 --
25 drivers/crypto/amcc/crypto4xx_sa.c | 85 ------------------------------------
26 drivers/crypto/amcc/crypto4xx_sa.h | 28 ++++++++++++
27 5 files changed, 39 insertions(+), 99 deletions(-)
28 delete mode 100644 drivers/crypto/amcc/crypto4xx_sa.c
30 --- a/drivers/crypto/amcc/Makefile
31 +++ b/drivers/crypto/amcc/Makefile
33 obj-$(CONFIG_CRYPTO_DEV_PPC4XX) += crypto4xx.o
34 -crypto4xx-y := crypto4xx_core.o crypto4xx_alg.o crypto4xx_sa.o
35 +crypto4xx-y := crypto4xx_core.o crypto4xx_alg.o
36 crypto4xx-$(CONFIG_HW_RANDOM_PPC4XX) += crypto4xx_trng.o
37 --- a/drivers/crypto/amcc/crypto4xx_alg.c
38 +++ b/drivers/crypto/amcc/crypto4xx_alg.c
40 #include <crypto/aes.h>
41 #include <crypto/sha.h>
42 #include "crypto4xx_reg_def.h"
43 -#include "crypto4xx_sa.h"
44 #include "crypto4xx_core.h"
45 +#include "crypto4xx_sa.h"
47 static void set_dynamic_sa_command_0(struct dynamic_sa_ctl *sa, u32 save_h,
48 u32 save_iv, u32 ld_h, u32 ld_iv,
49 @@ -79,8 +79,8 @@ int crypto4xx_encrypt(struct ablkcipher_
52 return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst,
53 - req->nbytes, req->info,
54 - get_dynamic_sa_iv_size(ctx));
55 + req->nbytes, req->info,
56 + crypto_ablkcipher_ivsize(crypto_ablkcipher_reqtfm(req)));
59 int crypto4xx_decrypt(struct ablkcipher_request *req)
60 @@ -92,8 +92,8 @@ int crypto4xx_decrypt(struct ablkcipher_
63 return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst,
64 - req->nbytes, req->info,
65 - get_dynamic_sa_iv_size(ctx));
66 + req->nbytes, req->info,
67 + crypto_ablkcipher_ivsize(crypto_ablkcipher_reqtfm(req)));
71 @@ -148,15 +148,15 @@ static int crypto4xx_setkey_aes(struct c
72 SA_SEQ_MASK_OFF, SA_MC_ENABLE,
73 SA_NOT_COPY_PAD, SA_NOT_COPY_PAYLOAD,
75 - crypto4xx_memcpy_le(ctx->sa_in + get_dynamic_sa_offset_key_field(ctx),
76 + crypto4xx_memcpy_le(get_dynamic_sa_key_field(sa),
78 sa->sa_contents.w = SA_AES_CONTENTS | (keylen << 2);
79 sa->sa_command_1.bf.key_len = keylen >> 3;
81 ctx->direction = DIR_INBOUND;
82 - memcpy(ctx->sa_in + get_dynamic_sa_offset_state_ptr_field(ctx),
83 - (void *)&ctx->state_record_dma_addr, 4);
84 - ctx->offset_to_sr_ptr = get_dynamic_sa_offset_state_ptr_field(ctx);
85 + memcpy(sa + get_dynamic_sa_offset_state_ptr_field(sa),
86 + (void *)&ctx->state_record_dma_addr, 4);
87 + ctx->offset_to_sr_ptr = get_dynamic_sa_offset_state_ptr_field(sa);
89 memcpy(ctx->sa_out, ctx->sa_in, ctx->sa_len * 4);
90 sa = (struct dynamic_sa_ctl *) ctx->sa_out;
91 @@ -226,7 +226,7 @@ static int crypto4xx_hash_alg_init(struc
92 memset(sa_in->inner_digest, 0, sizeof(sa_in->inner_digest));
93 memset(sa_in->outer_digest, 0, sizeof(sa_in->outer_digest));
94 sa_in->state_ptr = ctx->state_record_dma_addr;
95 - ctx->offset_to_sr_ptr = get_dynamic_sa_offset_state_ptr_field(ctx);
96 + ctx->offset_to_sr_ptr = get_dynamic_sa_offset_state_ptr_field(sa);
100 --- a/drivers/crypto/amcc/crypto4xx_core.h
101 +++ b/drivers/crypto/amcc/crypto4xx_core.h
102 @@ -161,9 +161,6 @@ int crypto4xx_alloc_sa(struct crypto4xx_
103 void crypto4xx_free_sa(struct crypto4xx_ctx *ctx);
104 void crypto4xx_free_ctx(struct crypto4xx_ctx *ctx);
105 u32 crypto4xx_alloc_state_record(struct crypto4xx_ctx *ctx);
106 -u32 get_dynamic_sa_offset_state_ptr_field(struct crypto4xx_ctx *ctx);
107 -u32 get_dynamic_sa_offset_key_field(struct crypto4xx_ctx *ctx);
108 -u32 get_dynamic_sa_iv_size(struct crypto4xx_ctx *ctx);
109 void crypto4xx_memcpy_le(unsigned int *dst,
110 const unsigned char *buf, int len);
111 u32 crypto4xx_build_pd(struct crypto_async_request *req,
112 --- a/drivers/crypto/amcc/crypto4xx_sa.c
116 - * AMCC SoC PPC4xx Crypto Driver
118 - * Copyright (c) 2008 Applied Micro Circuits Corporation.
119 - * All rights reserved. James Hsiao <jhsiao@amcc.com>
121 - * This program is free software; you can redistribute it and/or modify
122 - * it under the terms of the GNU General Public License as published by
123 - * the Free Software Foundation; either version 2 of the License, or
124 - * (at your option) any later version.
126 - * This program is distributed in the hope that it will be useful,
127 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
128 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
129 - * GNU General Public License for more details.
131 - * @file crypto4xx_sa.c
133 - * This file implements the security context
134 - * associate format.
136 -#include <linux/kernel.h>
137 -#include <linux/module.h>
138 -#include <linux/moduleparam.h>
139 -#include <linux/mod_devicetable.h>
140 -#include <linux/interrupt.h>
141 -#include <linux/spinlock_types.h>
142 -#include <linux/highmem.h>
143 -#include <linux/scatterlist.h>
144 -#include <linux/crypto.h>
145 -#include <crypto/algapi.h>
146 -#include <crypto/des.h>
147 -#include "crypto4xx_reg_def.h"
148 -#include "crypto4xx_sa.h"
149 -#include "crypto4xx_core.h"
151 -u32 get_dynamic_sa_offset_state_ptr_field(struct crypto4xx_ctx *ctx)
154 - union dynamic_sa_contents cts;
156 - if (ctx->direction == DIR_INBOUND)
157 - cts.w = ((struct dynamic_sa_ctl *) ctx->sa_in)->sa_contents.w;
159 - cts.w = ((struct dynamic_sa_ctl *) ctx->sa_out)->sa_contents.w;
160 - offset = cts.bf.key_size
161 - + cts.bf.inner_size
162 - + cts.bf.outer_size
166 - + cts.bf.seq_num_mask0
167 - + cts.bf.seq_num_mask1
168 - + cts.bf.seq_num_mask2
169 - + cts.bf.seq_num_mask3
175 - return sizeof(struct dynamic_sa_ctl) + offset * 4;
178 -u32 get_dynamic_sa_iv_size(struct crypto4xx_ctx *ctx)
180 - union dynamic_sa_contents cts;
182 - if (ctx->direction == DIR_INBOUND)
183 - cts.w = ((struct dynamic_sa_ctl *) ctx->sa_in)->sa_contents.w;
185 - cts.w = ((struct dynamic_sa_ctl *) ctx->sa_out)->sa_contents.w;
186 - return (cts.bf.iv0 + cts.bf.iv1 + cts.bf.iv2 + cts.bf.iv3) * 4;
189 -u32 get_dynamic_sa_offset_key_field(struct crypto4xx_ctx *ctx)
191 - union dynamic_sa_contents cts;
193 - if (ctx->direction == DIR_INBOUND)
194 - cts.w = ((struct dynamic_sa_ctl *) ctx->sa_in)->sa_contents.w;
196 - cts.w = ((struct dynamic_sa_ctl *) ctx->sa_out)->sa_contents.w;
198 - return sizeof(struct dynamic_sa_ctl);
200 --- a/drivers/crypto/amcc/crypto4xx_sa.h
201 +++ b/drivers/crypto/amcc/crypto4xx_sa.h
202 @@ -240,4 +240,32 @@ struct dynamic_sa_hash160 {
203 #define SA_HASH160_LEN (sizeof(struct dynamic_sa_hash160)/4)
204 #define SA_HASH160_CONTENTS 0x2000a502
207 +get_dynamic_sa_offset_state_ptr_field(struct dynamic_sa_ctl *cts)
211 + offset = cts->sa_contents.bf.key_size
212 + + cts->sa_contents.bf.inner_size
213 + + cts->sa_contents.bf.outer_size
214 + + cts->sa_contents.bf.spi
215 + + cts->sa_contents.bf.seq_num0
216 + + cts->sa_contents.bf.seq_num1
217 + + cts->sa_contents.bf.seq_num_mask0
218 + + cts->sa_contents.bf.seq_num_mask1
219 + + cts->sa_contents.bf.seq_num_mask2
220 + + cts->sa_contents.bf.seq_num_mask3
221 + + cts->sa_contents.bf.iv0
222 + + cts->sa_contents.bf.iv1
223 + + cts->sa_contents.bf.iv2
224 + + cts->sa_contents.bf.iv3;
226 + return sizeof(struct dynamic_sa_ctl) + offset * 4;
229 +static inline u8 *get_dynamic_sa_key_field(struct dynamic_sa_ctl *cts)
231 + return (u8 *) ((unsigned long)cts + sizeof(struct dynamic_sa_ctl));