|
31 | 31 | /* A * A * R mod N ==> A */
|
32 | 32 | #define CRYPTO_CMD_AARN 0x7
|
33 | 33 |
|
34 |
| -#define STARFIVE_RSA_MAX_KEYSZ 256 |
35 | 34 | #define STARFIVE_RSA_RESET 0x2
|
36 | 35 |
|
37 | 36 | static inline int starfive_pka_wait_done(struct starfive_cryp_ctx *ctx)
|
@@ -74,7 +73,7 @@ static int starfive_rsa_montgomery_form(struct starfive_cryp_ctx *ctx,
|
74 | 73 | {
|
75 | 74 | struct starfive_cryp_dev *cryp = ctx->cryp;
|
76 | 75 | struct starfive_cryp_request_ctx *rctx = ctx->rctx;
|
77 |
| - int count = rctx->total / sizeof(u32) - 1; |
| 76 | + int count = (ALIGN(rctx->total, 4) / 4) - 1; |
78 | 77 | int loop;
|
79 | 78 | u32 temp;
|
80 | 79 | u8 opsize;
|
@@ -251,12 +250,17 @@ static int starfive_rsa_enc_core(struct starfive_cryp_ctx *ctx, int enc)
|
251 | 250 | struct starfive_cryp_dev *cryp = ctx->cryp;
|
252 | 251 | struct starfive_cryp_request_ctx *rctx = ctx->rctx;
|
253 | 252 | struct starfive_rsa_key *key = &ctx->rsa_key;
|
254 |
| - int ret = 0; |
| 253 | + int ret = 0, shift = 0; |
255 | 254 |
|
256 | 255 | writel(STARFIVE_RSA_RESET, cryp->base + STARFIVE_PKA_CACR_OFFSET);
|
257 | 256 |
|
| 257 | + if (!IS_ALIGNED(rctx->total, sizeof(u32))) { |
| 258 | + shift = sizeof(u32) - (rctx->total & 0x3); |
| 259 | + memset(rctx->rsa_data, 0, shift); |
| 260 | + } |
| 261 | + |
258 | 262 | rctx->total = sg_copy_to_buffer(rctx->in_sg, rctx->nents,
|
259 |
| - rctx->rsa_data, rctx->total); |
| 263 | + rctx->rsa_data + shift, rctx->total); |
260 | 264 |
|
261 | 265 | if (enc) {
|
262 | 266 | key->bitlen = key->e_bitlen;
|
|
0 commit comments