Skip to content

Commit 249c8d9

Browse files
chunkeeyherbertx
authored andcommitted
crypto: crypto4xx - move and refactor dynamic_contents helpers
This patch refactors and moves the dynamic_contents helper functions into the crypto4xx_sa.h header file. * get_dynamic_sa_iv_size is no longer needed, as the cryptoapi provides the required IV size information as well. * refactor the function declarations to use the a pointer to the dynamic_sa_contents union, instead of the crypto4xx_ctx. * rename get_dynamic_sa_offset_key_field to get_dynamic_sa_key_field. It returns the pointer to the key directly. Signed-off-by: Christian Lamparter <chunkeey@googlemail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 453e309 commit 249c8d9

5 files changed

Lines changed: 39 additions & 99 deletions

File tree

‎drivers/crypto/amcc/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
obj-$(CONFIG_CRYPTO_DEV_PPC4XX) += crypto4xx.o
2-
crypto4xx-y := crypto4xx_core.o crypto4xx_alg.o crypto4xx_sa.o
2+
crypto4xx-y := crypto4xx_core.o crypto4xx_alg.o
33
crypto4xx-$(CONFIG_HW_RANDOM_PPC4XX) += crypto4xx_trng.o

‎drivers/crypto/amcc/crypto4xx_alg.c‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
#include <crypto/aes.h>
3030
#include <crypto/sha.h>
3131
#include "crypto4xx_reg_def.h"
32-
#include "crypto4xx_sa.h"
3332
#include "crypto4xx_core.h"
33+
#include "crypto4xx_sa.h"
3434

3535
static void set_dynamic_sa_command_0(struct dynamic_sa_ctl *sa, u32 save_h,
3636
u32 save_iv, u32 ld_h, u32 ld_iv,
@@ -79,8 +79,8 @@ int crypto4xx_encrypt(struct ablkcipher_request *req)
7979
ctx->pd_ctl = 0x1;
8080

8181
return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst,
82-
req->nbytes, req->info,
83-
get_dynamic_sa_iv_size(ctx));
82+
req->nbytes, req->info,
83+
crypto_ablkcipher_ivsize(crypto_ablkcipher_reqtfm(req)));
8484
}
8585

8686
int crypto4xx_decrypt(struct ablkcipher_request *req)
@@ -92,8 +92,8 @@ int crypto4xx_decrypt(struct ablkcipher_request *req)
9292
ctx->pd_ctl = 1;
9393

9494
return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst,
95-
req->nbytes, req->info,
96-
get_dynamic_sa_iv_size(ctx));
95+
req->nbytes, req->info,
96+
crypto_ablkcipher_ivsize(crypto_ablkcipher_reqtfm(req)));
9797
}
9898

9999
/**
@@ -147,15 +147,15 @@ static int crypto4xx_setkey_aes(struct crypto_ablkcipher *cipher,
147147
SA_SEQ_MASK_OFF, SA_MC_ENABLE,
148148
SA_NOT_COPY_PAD, SA_NOT_COPY_PAYLOAD,
149149
SA_NOT_COPY_HDR);
150-
crypto4xx_memcpy_le(ctx->sa_in + get_dynamic_sa_offset_key_field(ctx),
150+
crypto4xx_memcpy_le(get_dynamic_sa_key_field(sa),
151151
key, keylen);
152152
sa->sa_contents.w = SA_AES_CONTENTS | (keylen << 2);
153153
sa->sa_command_1.bf.key_len = keylen >> 3;
154154
ctx->is_hash = 0;
155155
ctx->direction = DIR_INBOUND;
156-
memcpy(ctx->sa_in + get_dynamic_sa_offset_state_ptr_field(ctx),
157-
(void *)&ctx->state_record_dma_addr, 4);
158-
ctx->offset_to_sr_ptr = get_dynamic_sa_offset_state_ptr_field(ctx);
156+
memcpy(sa + get_dynamic_sa_offset_state_ptr_field(sa),
157+
(void *)&ctx->state_record_dma_addr, 4);
158+
ctx->offset_to_sr_ptr = get_dynamic_sa_offset_state_ptr_field(sa);
159159

160160
memcpy(ctx->sa_out, ctx->sa_in, ctx->sa_len * 4);
161161
sa = (struct dynamic_sa_ctl *) ctx->sa_out;
@@ -225,7 +225,7 @@ static int crypto4xx_hash_alg_init(struct crypto_tfm *tfm,
225225
memset(sa_in->inner_digest, 0, sizeof(sa_in->inner_digest));
226226
memset(sa_in->outer_digest, 0, sizeof(sa_in->outer_digest));
227227
sa_in->state_ptr = ctx->state_record_dma_addr;
228-
ctx->offset_to_sr_ptr = get_dynamic_sa_offset_state_ptr_field(ctx);
228+
ctx->offset_to_sr_ptr = get_dynamic_sa_offset_state_ptr_field(sa);
229229

230230
return 0;
231231
}

‎drivers/crypto/amcc/crypto4xx_core.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,6 @@ int crypto4xx_alloc_sa(struct crypto4xx_ctx *ctx, u32 size);
161161
void crypto4xx_free_sa(struct crypto4xx_ctx *ctx);
162162
void crypto4xx_free_ctx(struct crypto4xx_ctx *ctx);
163163
u32 crypto4xx_alloc_state_record(struct crypto4xx_ctx *ctx);
164-
u32 get_dynamic_sa_offset_state_ptr_field(struct crypto4xx_ctx *ctx);
165-
u32 get_dynamic_sa_offset_key_field(struct crypto4xx_ctx *ctx);
166-
u32 get_dynamic_sa_iv_size(struct crypto4xx_ctx *ctx);
167164
void crypto4xx_memcpy_le(unsigned int *dst,
168165
const unsigned char *buf, int len);
169166
u32 crypto4xx_build_pd(struct crypto_async_request *req,

‎drivers/crypto/amcc/crypto4xx_sa.c‎

Lines changed: 0 additions & 85 deletions
This file was deleted.

‎drivers/crypto/amcc/crypto4xx_sa.h‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,32 @@ struct dynamic_sa_hash160 {
240240
#define SA_HASH160_LEN (sizeof(struct dynamic_sa_hash160)/4)
241241
#define SA_HASH160_CONTENTS 0x2000a502
242242

243+
static inline u32
244+
get_dynamic_sa_offset_state_ptr_field(struct dynamic_sa_ctl *cts)
245+
{
246+
u32 offset;
247+
248+
offset = cts->sa_contents.bf.key_size
249+
+ cts->sa_contents.bf.inner_size
250+
+ cts->sa_contents.bf.outer_size
251+
+ cts->sa_contents.bf.spi
252+
+ cts->sa_contents.bf.seq_num0
253+
+ cts->sa_contents.bf.seq_num1
254+
+ cts->sa_contents.bf.seq_num_mask0
255+
+ cts->sa_contents.bf.seq_num_mask1
256+
+ cts->sa_contents.bf.seq_num_mask2
257+
+ cts->sa_contents.bf.seq_num_mask3
258+
+ cts->sa_contents.bf.iv0
259+
+ cts->sa_contents.bf.iv1
260+
+ cts->sa_contents.bf.iv2
261+
+ cts->sa_contents.bf.iv3;
262+
263+
return sizeof(struct dynamic_sa_ctl) + offset * 4;
264+
}
265+
266+
static inline u8 *get_dynamic_sa_key_field(struct dynamic_sa_ctl *cts)
267+
{
268+
return (u8 *) ((unsigned long)cts + sizeof(struct dynamic_sa_ctl));
269+
}
270+
243271
#endif

0 commit comments

Comments
 (0)