diff options
Diffstat (limited to 'drivers/crypto/nx/nx-aes-xcbc.c')
| -rw-r--r-- | drivers/crypto/nx/nx-aes-xcbc.c | 70 |
1 files changed, 44 insertions, 26 deletions
diff --git a/drivers/crypto/nx/nx-aes-xcbc.c b/drivers/crypto/nx/nx-aes-xcbc.c index 8c2faffab4a3..c2f7d4befb55 100644 --- a/drivers/crypto/nx/nx-aes-xcbc.c +++ b/drivers/crypto/nx/nx-aes-xcbc.c | |||
| @@ -42,6 +42,7 @@ static int nx_xcbc_set_key(struct crypto_shash *desc, | |||
| 42 | unsigned int key_len) | 42 | unsigned int key_len) |
| 43 | { | 43 | { |
| 44 | struct nx_crypto_ctx *nx_ctx = crypto_shash_ctx(desc); | 44 | struct nx_crypto_ctx *nx_ctx = crypto_shash_ctx(desc); |
| 45 | struct nx_csbcpb *csbcpb = nx_ctx->csbcpb; | ||
| 45 | 46 | ||
| 46 | switch (key_len) { | 47 | switch (key_len) { |
| 47 | case AES_KEYSIZE_128: | 48 | case AES_KEYSIZE_128: |
| @@ -51,7 +52,7 @@ static int nx_xcbc_set_key(struct crypto_shash *desc, | |||
| 51 | return -EINVAL; | 52 | return -EINVAL; |
| 52 | } | 53 | } |
| 53 | 54 | ||
| 54 | memcpy(nx_ctx->priv.xcbc.key, in_key, key_len); | 55 | memcpy(csbcpb->cpb.aes_xcbc.key, in_key, key_len); |
| 55 | 56 | ||
| 56 | return 0; | 57 | return 0; |
| 57 | } | 58 | } |
| @@ -148,32 +149,29 @@ out: | |||
| 148 | return rc; | 149 | return rc; |
| 149 | } | 150 | } |
| 150 | 151 | ||
| 151 | static int nx_xcbc_init(struct shash_desc *desc) | 152 | static int nx_crypto_ctx_aes_xcbc_init2(struct crypto_tfm *tfm) |
| 152 | { | 153 | { |
| 153 | struct xcbc_state *sctx = shash_desc_ctx(desc); | 154 | struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(tfm); |
| 154 | struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(&desc->tfm->base); | ||
| 155 | struct nx_csbcpb *csbcpb = nx_ctx->csbcpb; | 155 | struct nx_csbcpb *csbcpb = nx_ctx->csbcpb; |
| 156 | struct nx_sg *out_sg; | 156 | int err; |
| 157 | int len; | ||
| 158 | 157 | ||
| 159 | nx_ctx_init(nx_ctx, HCOP_FC_AES); | 158 | err = nx_crypto_ctx_aes_xcbc_init(tfm); |
| 159 | if (err) | ||
| 160 | return err; | ||
| 160 | 161 | ||
| 161 | memset(sctx, 0, sizeof *sctx); | 162 | nx_ctx_init(nx_ctx, HCOP_FC_AES); |
| 162 | 163 | ||
| 163 | NX_CPB_SET_KEY_SIZE(csbcpb, NX_KS_AES_128); | 164 | NX_CPB_SET_KEY_SIZE(csbcpb, NX_KS_AES_128); |
| 164 | csbcpb->cpb.hdr.mode = NX_MODE_AES_XCBC_MAC; | 165 | csbcpb->cpb.hdr.mode = NX_MODE_AES_XCBC_MAC; |
| 165 | 166 | ||
| 166 | memcpy(csbcpb->cpb.aes_xcbc.key, nx_ctx->priv.xcbc.key, AES_BLOCK_SIZE); | 167 | return 0; |
| 167 | memset(nx_ctx->priv.xcbc.key, 0, sizeof *nx_ctx->priv.xcbc.key); | 168 | } |
| 168 | |||
| 169 | len = AES_BLOCK_SIZE; | ||
| 170 | out_sg = nx_build_sg_list(nx_ctx->out_sg, (u8 *)sctx->state, | ||
| 171 | &len, nx_ctx->ap->sglen); | ||
| 172 | 169 | ||
| 173 | if (len != AES_BLOCK_SIZE) | 170 | static int nx_xcbc_init(struct shash_desc *desc) |
| 174 | return -EINVAL; | 171 | { |
| 172 | struct xcbc_state *sctx = shash_desc_ctx(desc); | ||
| 175 | 173 | ||
| 176 | nx_ctx->op.outlen = (nx_ctx->out_sg - out_sg) * sizeof(struct nx_sg); | 174 | memset(sctx, 0, sizeof *sctx); |
| 177 | 175 | ||
| 178 | return 0; | 176 | return 0; |
| 179 | } | 177 | } |
| @@ -186,6 +184,7 @@ static int nx_xcbc_update(struct shash_desc *desc, | |||
| 186 | struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(&desc->tfm->base); | 184 | struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(&desc->tfm->base); |
| 187 | struct nx_csbcpb *csbcpb = nx_ctx->csbcpb; | 185 | struct nx_csbcpb *csbcpb = nx_ctx->csbcpb; |
| 188 | struct nx_sg *in_sg; | 186 | struct nx_sg *in_sg; |
| 187 | struct nx_sg *out_sg; | ||
| 189 | u32 to_process = 0, leftover, total; | 188 | u32 to_process = 0, leftover, total; |
| 190 | unsigned int max_sg_len; | 189 | unsigned int max_sg_len; |
| 191 | unsigned long irq_flags; | 190 | unsigned long irq_flags; |
| @@ -213,6 +212,17 @@ static int nx_xcbc_update(struct shash_desc *desc, | |||
| 213 | max_sg_len = min_t(u64, max_sg_len, | 212 | max_sg_len = min_t(u64, max_sg_len, |
| 214 | nx_ctx->ap->databytelen/NX_PAGE_SIZE); | 213 | nx_ctx->ap->databytelen/NX_PAGE_SIZE); |
| 215 | 214 | ||
| 215 | data_len = AES_BLOCK_SIZE; | ||
| 216 | out_sg = nx_build_sg_list(nx_ctx->out_sg, (u8 *)sctx->state, | ||
| 217 | &len, nx_ctx->ap->sglen); | ||
| 218 | |||
| 219 | if (data_len != AES_BLOCK_SIZE) { | ||
| 220 | rc = -EINVAL; | ||
| 221 | goto out; | ||
| 222 | } | ||
| 223 | |||
| 224 | nx_ctx->op.outlen = (nx_ctx->out_sg - out_sg) * sizeof(struct nx_sg); | ||
| 225 | |||
| 216 | do { | 226 | do { |
| 217 | to_process = total - to_process; | 227 | to_process = total - to_process; |
| 218 | to_process = to_process & ~(AES_BLOCK_SIZE - 1); | 228 | to_process = to_process & ~(AES_BLOCK_SIZE - 1); |
| @@ -235,8 +245,10 @@ static int nx_xcbc_update(struct shash_desc *desc, | |||
| 235 | (u8 *) sctx->buffer, | 245 | (u8 *) sctx->buffer, |
| 236 | &data_len, | 246 | &data_len, |
| 237 | max_sg_len); | 247 | max_sg_len); |
| 238 | if (data_len != sctx->count) | 248 | if (data_len != sctx->count) { |
| 239 | return -EINVAL; | 249 | rc = -EINVAL; |
| 250 | goto out; | ||
| 251 | } | ||
| 240 | } | 252 | } |
| 241 | 253 | ||
| 242 | data_len = to_process - sctx->count; | 254 | data_len = to_process - sctx->count; |
| @@ -245,8 +257,10 @@ static int nx_xcbc_update(struct shash_desc *desc, | |||
| 245 | &data_len, | 257 | &data_len, |
| 246 | max_sg_len); | 258 | max_sg_len); |
| 247 | 259 | ||
| 248 | if (data_len != to_process - sctx->count) | 260 | if (data_len != to_process - sctx->count) { |
| 249 | return -EINVAL; | 261 | rc = -EINVAL; |
| 262 | goto out; | ||
| 263 | } | ||
| 250 | 264 | ||
| 251 | nx_ctx->op.inlen = (nx_ctx->in_sg - in_sg) * | 265 | nx_ctx->op.inlen = (nx_ctx->in_sg - in_sg) * |
| 252 | sizeof(struct nx_sg); | 266 | sizeof(struct nx_sg); |
| @@ -325,15 +339,19 @@ static int nx_xcbc_final(struct shash_desc *desc, u8 *out) | |||
| 325 | in_sg = nx_build_sg_list(nx_ctx->in_sg, (u8 *)sctx->buffer, | 339 | in_sg = nx_build_sg_list(nx_ctx->in_sg, (u8 *)sctx->buffer, |
| 326 | &len, nx_ctx->ap->sglen); | 340 | &len, nx_ctx->ap->sglen); |
| 327 | 341 | ||
| 328 | if (len != sctx->count) | 342 | if (len != sctx->count) { |
| 329 | return -EINVAL; | 343 | rc = -EINVAL; |
| 344 | goto out; | ||
| 345 | } | ||
| 330 | 346 | ||
| 331 | len = AES_BLOCK_SIZE; | 347 | len = AES_BLOCK_SIZE; |
| 332 | out_sg = nx_build_sg_list(nx_ctx->out_sg, out, &len, | 348 | out_sg = nx_build_sg_list(nx_ctx->out_sg, out, &len, |
| 333 | nx_ctx->ap->sglen); | 349 | nx_ctx->ap->sglen); |
| 334 | 350 | ||
| 335 | if (len != AES_BLOCK_SIZE) | 351 | if (len != AES_BLOCK_SIZE) { |
| 336 | return -EINVAL; | 352 | rc = -EINVAL; |
| 353 | goto out; | ||
| 354 | } | ||
| 337 | 355 | ||
| 338 | nx_ctx->op.inlen = (nx_ctx->in_sg - in_sg) * sizeof(struct nx_sg); | 356 | nx_ctx->op.inlen = (nx_ctx->in_sg - in_sg) * sizeof(struct nx_sg); |
| 339 | nx_ctx->op.outlen = (nx_ctx->out_sg - out_sg) * sizeof(struct nx_sg); | 357 | nx_ctx->op.outlen = (nx_ctx->out_sg - out_sg) * sizeof(struct nx_sg); |
| @@ -372,7 +390,7 @@ struct shash_alg nx_shash_aes_xcbc_alg = { | |||
| 372 | .cra_blocksize = AES_BLOCK_SIZE, | 390 | .cra_blocksize = AES_BLOCK_SIZE, |
| 373 | .cra_module = THIS_MODULE, | 391 | .cra_module = THIS_MODULE, |
| 374 | .cra_ctxsize = sizeof(struct nx_crypto_ctx), | 392 | .cra_ctxsize = sizeof(struct nx_crypto_ctx), |
| 375 | .cra_init = nx_crypto_ctx_aes_xcbc_init, | 393 | .cra_init = nx_crypto_ctx_aes_xcbc_init2, |
| 376 | .cra_exit = nx_crypto_ctx_exit, | 394 | .cra_exit = nx_crypto_ctx_exit, |
| 377 | } | 395 | } |
| 378 | }; | 396 | }; |
