| Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Cipher algorithms supported by the CESA: DES, 3DES and AES. |
| 3 | * |
| 4 | * Author: Boris Brezillon <boris.brezillon@free-electrons.com> |
| 5 | * Author: Arnaud Ebalard <arno@natisbad.org> |
| 6 | * |
| 7 | * This work is based on an initial version written by |
| 8 | * Sebastian Andrzej Siewior < sebastian at breakpoint dot cc > |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License version 2 as published |
| 12 | * by the Free Software Foundation. |
| 13 | */ |
| 14 | |
| 15 | #include <crypto/aes.h> |
| Boris BREZILLON | 7b3aaaa | 2015-06-18 15:46:22 +0200 | [diff] [blame] | 16 | #include <crypto/des.h> |
| Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 17 | |
| 18 | #include "cesa.h" |
| 19 | |
| Boris BREZILLON | 7b3aaaa | 2015-06-18 15:46:22 +0200 | [diff] [blame] | 20 | struct mv_cesa_des_ctx { |
| 21 | struct mv_cesa_ctx base; |
| 22 | u8 key[DES_KEY_SIZE]; |
| 23 | }; |
| 24 | |
| Arnaud Ebalard | 4ada483 | 2015-06-18 15:46:23 +0200 | [diff] [blame] | 25 | struct mv_cesa_des3_ctx { |
| 26 | struct mv_cesa_ctx base; |
| 27 | u8 key[DES3_EDE_KEY_SIZE]; |
| 28 | }; |
| 29 | |
| Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 30 | struct mv_cesa_aes_ctx { |
| 31 | struct mv_cesa_ctx base; |
| 32 | struct crypto_aes_ctx aes; |
| 33 | }; |
| 34 | |
| Boris BREZILLON | db509a4 | 2015-06-18 15:46:21 +0200 | [diff] [blame] | 35 | struct mv_cesa_ablkcipher_dma_iter { |
| 36 | struct mv_cesa_dma_iter base; |
| 37 | struct mv_cesa_sg_dma_iter src; |
| 38 | struct mv_cesa_sg_dma_iter dst; |
| 39 | }; |
| 40 | |
| 41 | static inline void |
| 42 | mv_cesa_ablkcipher_req_iter_init(struct mv_cesa_ablkcipher_dma_iter *iter, |
| 43 | struct ablkcipher_request *req) |
| 44 | { |
| 45 | mv_cesa_req_dma_iter_init(&iter->base, req->nbytes); |
| 46 | mv_cesa_sg_dma_iter_init(&iter->src, req->src, DMA_TO_DEVICE); |
| 47 | mv_cesa_sg_dma_iter_init(&iter->dst, req->dst, DMA_FROM_DEVICE); |
| 48 | } |
| 49 | |
| 50 | static inline bool |
| 51 | mv_cesa_ablkcipher_req_iter_next_op(struct mv_cesa_ablkcipher_dma_iter *iter) |
| 52 | { |
| 53 | iter->src.op_offset = 0; |
| 54 | iter->dst.op_offset = 0; |
| 55 | |
| 56 | return mv_cesa_req_dma_iter_next_op(&iter->base); |
| 57 | } |
| 58 | |
| 59 | static inline void |
| 60 | mv_cesa_ablkcipher_dma_cleanup(struct ablkcipher_request *req) |
| 61 | { |
| 62 | struct mv_cesa_ablkcipher_req *creq = ablkcipher_request_ctx(req); |
| 63 | |
| 64 | if (req->dst != req->src) { |
| 65 | dma_unmap_sg(cesa_dev->dev, req->dst, creq->dst_nents, |
| 66 | DMA_FROM_DEVICE); |
| 67 | dma_unmap_sg(cesa_dev->dev, req->src, creq->src_nents, |
| 68 | DMA_TO_DEVICE); |
| 69 | } else { |
| 70 | dma_unmap_sg(cesa_dev->dev, req->src, creq->src_nents, |
| 71 | DMA_BIDIRECTIONAL); |
| 72 | } |
| 73 | mv_cesa_dma_cleanup(&creq->req.dma); |
| 74 | } |
| 75 | |
| 76 | static inline void mv_cesa_ablkcipher_cleanup(struct ablkcipher_request *req) |
| 77 | { |
| 78 | struct mv_cesa_ablkcipher_req *creq = ablkcipher_request_ctx(req); |
| 79 | |
| 80 | if (creq->req.base.type == CESA_DMA_REQ) |
| 81 | mv_cesa_ablkcipher_dma_cleanup(req); |
| 82 | } |
| 83 | |
| Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 84 | static void mv_cesa_ablkcipher_std_step(struct ablkcipher_request *req) |
| 85 | { |
| 86 | struct mv_cesa_ablkcipher_req *creq = ablkcipher_request_ctx(req); |
| 87 | struct mv_cesa_ablkcipher_std_req *sreq = &creq->req.std; |
| 88 | struct mv_cesa_engine *engine = sreq->base.engine; |
| 89 | size_t len = min_t(size_t, req->nbytes - sreq->offset, |
| 90 | CESA_SA_SRAM_PAYLOAD_SIZE); |
| 91 | |
| 92 | len = sg_pcopy_to_buffer(req->src, creq->src_nents, |
| 93 | engine->sram + CESA_SA_DATA_SRAM_OFFSET, |
| 94 | len, sreq->offset); |
| 95 | |
| 96 | sreq->size = len; |
| 97 | mv_cesa_set_crypt_op_len(&sreq->op, len); |
| 98 | |
| 99 | /* FIXME: only update enc_len field */ |
| 100 | if (!sreq->skip_ctx) { |
| Russell King | 0f3304d | 2015-10-18 18:31:15 +0100 | [diff] [blame] | 101 | memcpy_toio(engine->sram, &sreq->op, sizeof(sreq->op)); |
| Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 102 | sreq->skip_ctx = true; |
| 103 | } else { |
| Russell King | 0f3304d | 2015-10-18 18:31:15 +0100 | [diff] [blame] | 104 | memcpy_toio(engine->sram, &sreq->op, sizeof(sreq->op.desc)); |
| Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | mv_cesa_set_int_mask(engine, CESA_SA_INT_ACCEL0_DONE); |
| Russell King | b150856 | 2015-10-18 18:31:00 +0100 | [diff] [blame] | 108 | writel_relaxed(CESA_SA_CFG_PARA_DIS, engine->regs + CESA_SA_CFG); |
| Romain Perier | f628308 | 2016-06-21 10:08:32 +0200 | [diff] [blame] | 109 | BUG_ON(readl(engine->regs + CESA_SA_CMD) & |
| 110 | CESA_SA_CMD_EN_CESA_SA_ACCL0); |
| Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 111 | writel(CESA_SA_CMD_EN_CESA_SA_ACCL0, engine->regs + CESA_SA_CMD); |
| 112 | } |
| 113 | |
| 114 | static int mv_cesa_ablkcipher_std_process(struct ablkcipher_request *req, |
| 115 | u32 status) |
| 116 | { |
| 117 | struct mv_cesa_ablkcipher_req *creq = ablkcipher_request_ctx(req); |
| 118 | struct mv_cesa_ablkcipher_std_req *sreq = &creq->req.std; |
| 119 | struct mv_cesa_engine *engine = sreq->base.engine; |
| 120 | size_t len; |
| Romain Perier | bac8e80 | 2016-06-21 10:08:34 +0200 | [diff] [blame^] | 121 | unsigned int ivsize; |
| Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 122 | |
| 123 | len = sg_pcopy_from_buffer(req->dst, creq->dst_nents, |
| 124 | engine->sram + CESA_SA_DATA_SRAM_OFFSET, |
| 125 | sreq->size, sreq->offset); |
| 126 | |
| 127 | sreq->offset += len; |
| 128 | if (sreq->offset < req->nbytes) |
| 129 | return -EINPROGRESS; |
| 130 | |
| Romain Perier | bac8e80 | 2016-06-21 10:08:34 +0200 | [diff] [blame^] | 131 | ivsize = crypto_ablkcipher_ivsize(crypto_ablkcipher_reqtfm(req)); |
| 132 | memcpy_fromio(req->info, |
| 133 | engine->sram + CESA_SA_CRYPT_IV_SRAM_OFFSET, ivsize); |
| 134 | |
| Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | static int mv_cesa_ablkcipher_process(struct crypto_async_request *req, |
| 139 | u32 status) |
| 140 | { |
| 141 | struct ablkcipher_request *ablkreq = ablkcipher_request_cast(req); |
| 142 | struct mv_cesa_ablkcipher_req *creq = ablkcipher_request_ctx(ablkreq); |
| Romain Perier | bac8e80 | 2016-06-21 10:08:34 +0200 | [diff] [blame^] | 143 | struct mv_cesa_tdma_req *dreq; |
| 144 | unsigned int ivsize; |
| Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 145 | int ret; |
| 146 | |
| Romain Perier | bac8e80 | 2016-06-21 10:08:34 +0200 | [diff] [blame^] | 147 | if (creq->req.base.type == CESA_STD_REQ) |
| 148 | return mv_cesa_ablkcipher_std_process(ablkreq, status); |
| Boris BREZILLON | db509a4 | 2015-06-18 15:46:21 +0200 | [diff] [blame] | 149 | |
| Romain Perier | bac8e80 | 2016-06-21 10:08:34 +0200 | [diff] [blame^] | 150 | ret = mv_cesa_dma_process(&creq->req.dma, status); |
| Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 151 | if (ret) |
| 152 | return ret; |
| 153 | |
| Romain Perier | bac8e80 | 2016-06-21 10:08:34 +0200 | [diff] [blame^] | 154 | dreq = &creq->req.dma; |
| 155 | ivsize = crypto_ablkcipher_ivsize(crypto_ablkcipher_reqtfm(ablkreq)); |
| 156 | memcpy_fromio(ablkreq->info, dreq->chain.last->data, ivsize); |
| Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 157 | |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | static void mv_cesa_ablkcipher_step(struct crypto_async_request *req) |
| 162 | { |
| 163 | struct ablkcipher_request *ablkreq = ablkcipher_request_cast(req); |
| Boris BREZILLON | db509a4 | 2015-06-18 15:46:21 +0200 | [diff] [blame] | 164 | struct mv_cesa_ablkcipher_req *creq = ablkcipher_request_ctx(ablkreq); |
| Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 165 | |
| Boris BREZILLON | db509a4 | 2015-06-18 15:46:21 +0200 | [diff] [blame] | 166 | if (creq->req.base.type == CESA_DMA_REQ) |
| 167 | mv_cesa_dma_step(&creq->req.dma); |
| 168 | else |
| 169 | mv_cesa_ablkcipher_std_step(ablkreq); |
| 170 | } |
| 171 | |
| 172 | static inline void |
| 173 | mv_cesa_ablkcipher_dma_prepare(struct ablkcipher_request *req) |
| 174 | { |
| 175 | struct mv_cesa_ablkcipher_req *creq = ablkcipher_request_ctx(req); |
| 176 | struct mv_cesa_tdma_req *dreq = &creq->req.dma; |
| 177 | |
| 178 | mv_cesa_dma_prepare(dreq, dreq->base.engine); |
| Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | static inline void |
| 182 | mv_cesa_ablkcipher_std_prepare(struct ablkcipher_request *req) |
| 183 | { |
| 184 | struct mv_cesa_ablkcipher_req *creq = ablkcipher_request_ctx(req); |
| 185 | struct mv_cesa_ablkcipher_std_req *sreq = &creq->req.std; |
| 186 | struct mv_cesa_engine *engine = sreq->base.engine; |
| 187 | |
| 188 | sreq->size = 0; |
| 189 | sreq->offset = 0; |
| 190 | mv_cesa_adjust_op(engine, &sreq->op); |
| Russell King | 0f3304d | 2015-10-18 18:31:15 +0100 | [diff] [blame] | 191 | memcpy_toio(engine->sram, &sreq->op, sizeof(sreq->op)); |
| Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | static inline void mv_cesa_ablkcipher_prepare(struct crypto_async_request *req, |
| 195 | struct mv_cesa_engine *engine) |
| 196 | { |
| 197 | struct ablkcipher_request *ablkreq = ablkcipher_request_cast(req); |
| 198 | struct mv_cesa_ablkcipher_req *creq = ablkcipher_request_ctx(ablkreq); |
| Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 199 | creq->req.base.engine = engine; |
| 200 | |
| Boris BREZILLON | db509a4 | 2015-06-18 15:46:21 +0200 | [diff] [blame] | 201 | if (creq->req.base.type == CESA_DMA_REQ) |
| 202 | mv_cesa_ablkcipher_dma_prepare(ablkreq); |
| 203 | else |
| 204 | mv_cesa_ablkcipher_std_prepare(ablkreq); |
| Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | static inline void |
| 208 | mv_cesa_ablkcipher_req_cleanup(struct crypto_async_request *req) |
| 209 | { |
| Boris BREZILLON | db509a4 | 2015-06-18 15:46:21 +0200 | [diff] [blame] | 210 | struct ablkcipher_request *ablkreq = ablkcipher_request_cast(req); |
| 211 | |
| 212 | mv_cesa_ablkcipher_cleanup(ablkreq); |
| Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | static const struct mv_cesa_req_ops mv_cesa_ablkcipher_req_ops = { |
| 216 | .step = mv_cesa_ablkcipher_step, |
| 217 | .process = mv_cesa_ablkcipher_process, |
| 218 | .prepare = mv_cesa_ablkcipher_prepare, |
| 219 | .cleanup = mv_cesa_ablkcipher_req_cleanup, |
| 220 | }; |
| 221 | |
| 222 | static int mv_cesa_ablkcipher_cra_init(struct crypto_tfm *tfm) |
| 223 | { |
| 224 | struct mv_cesa_aes_ctx *ctx = crypto_tfm_ctx(tfm); |
| 225 | |
| 226 | ctx->base.ops = &mv_cesa_ablkcipher_req_ops; |
| 227 | |
| 228 | tfm->crt_ablkcipher.reqsize = sizeof(struct mv_cesa_ablkcipher_req); |
| 229 | |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | static int mv_cesa_aes_setkey(struct crypto_ablkcipher *cipher, const u8 *key, |
| 234 | unsigned int len) |
| 235 | { |
| 236 | struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher); |
| 237 | struct mv_cesa_aes_ctx *ctx = crypto_tfm_ctx(tfm); |
| 238 | int remaining; |
| 239 | int offset; |
| 240 | int ret; |
| 241 | int i; |
| 242 | |
| 243 | ret = crypto_aes_expand_key(&ctx->aes, key, len); |
| 244 | if (ret) { |
| 245 | crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN); |
| 246 | return ret; |
| 247 | } |
| 248 | |
| 249 | remaining = (ctx->aes.key_length - 16) / 4; |
| 250 | offset = ctx->aes.key_length + 24 - remaining; |
| 251 | for (i = 0; i < remaining; i++) |
| 252 | ctx->aes.key_dec[4 + i] = |
| 253 | cpu_to_le32(ctx->aes.key_enc[offset + i]); |
| 254 | |
| 255 | return 0; |
| 256 | } |
| 257 | |
| Boris BREZILLON | 7b3aaaa | 2015-06-18 15:46:22 +0200 | [diff] [blame] | 258 | static int mv_cesa_des_setkey(struct crypto_ablkcipher *cipher, const u8 *key, |
| 259 | unsigned int len) |
| 260 | { |
| 261 | struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher); |
| 262 | struct mv_cesa_des_ctx *ctx = crypto_tfm_ctx(tfm); |
| 263 | u32 tmp[DES_EXPKEY_WORDS]; |
| 264 | int ret; |
| 265 | |
| 266 | if (len != DES_KEY_SIZE) { |
| 267 | crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN); |
| 268 | return -EINVAL; |
| 269 | } |
| 270 | |
| 271 | ret = des_ekey(tmp, key); |
| 272 | if (!ret && (tfm->crt_flags & CRYPTO_TFM_REQ_WEAK_KEY)) { |
| 273 | tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY; |
| 274 | return -EINVAL; |
| 275 | } |
| 276 | |
| 277 | memcpy(ctx->key, key, DES_KEY_SIZE); |
| 278 | |
| 279 | return 0; |
| 280 | } |
| 281 | |
| Arnaud Ebalard | 4ada483 | 2015-06-18 15:46:23 +0200 | [diff] [blame] | 282 | static int mv_cesa_des3_ede_setkey(struct crypto_ablkcipher *cipher, |
| 283 | const u8 *key, unsigned int len) |
| 284 | { |
| 285 | struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher); |
| 286 | struct mv_cesa_des_ctx *ctx = crypto_tfm_ctx(tfm); |
| 287 | |
| 288 | if (len != DES3_EDE_KEY_SIZE) { |
| 289 | crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN); |
| 290 | return -EINVAL; |
| 291 | } |
| 292 | |
| 293 | memcpy(ctx->key, key, DES3_EDE_KEY_SIZE); |
| 294 | |
| 295 | return 0; |
| 296 | } |
| 297 | |
| Boris BREZILLON | db509a4 | 2015-06-18 15:46:21 +0200 | [diff] [blame] | 298 | static int mv_cesa_ablkcipher_dma_req_init(struct ablkcipher_request *req, |
| 299 | const struct mv_cesa_op_ctx *op_templ) |
| 300 | { |
| 301 | struct mv_cesa_ablkcipher_req *creq = ablkcipher_request_ctx(req); |
| 302 | gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ? |
| 303 | GFP_KERNEL : GFP_ATOMIC; |
| 304 | struct mv_cesa_tdma_req *dreq = &creq->req.dma; |
| 305 | struct mv_cesa_ablkcipher_dma_iter iter; |
| 306 | struct mv_cesa_tdma_chain chain; |
| 307 | bool skip_ctx = false; |
| 308 | int ret; |
| Romain Perier | bac8e80 | 2016-06-21 10:08:34 +0200 | [diff] [blame^] | 309 | unsigned int ivsize; |
| Boris BREZILLON | db509a4 | 2015-06-18 15:46:21 +0200 | [diff] [blame] | 310 | |
| 311 | dreq->base.type = CESA_DMA_REQ; |
| 312 | dreq->chain.first = NULL; |
| 313 | dreq->chain.last = NULL; |
| 314 | |
| 315 | if (req->src != req->dst) { |
| 316 | ret = dma_map_sg(cesa_dev->dev, req->src, creq->src_nents, |
| 317 | DMA_TO_DEVICE); |
| 318 | if (!ret) |
| 319 | return -ENOMEM; |
| 320 | |
| 321 | ret = dma_map_sg(cesa_dev->dev, req->dst, creq->dst_nents, |
| 322 | DMA_FROM_DEVICE); |
| 323 | if (!ret) { |
| 324 | ret = -ENOMEM; |
| 325 | goto err_unmap_src; |
| 326 | } |
| 327 | } else { |
| 328 | ret = dma_map_sg(cesa_dev->dev, req->src, creq->src_nents, |
| 329 | DMA_BIDIRECTIONAL); |
| 330 | if (!ret) |
| 331 | return -ENOMEM; |
| 332 | } |
| 333 | |
| 334 | mv_cesa_tdma_desc_iter_init(&chain); |
| 335 | mv_cesa_ablkcipher_req_iter_init(&iter, req); |
| 336 | |
| 337 | do { |
| 338 | struct mv_cesa_op_ctx *op; |
| 339 | |
| 340 | op = mv_cesa_dma_add_op(&chain, op_templ, skip_ctx, flags); |
| 341 | if (IS_ERR(op)) { |
| 342 | ret = PTR_ERR(op); |
| 343 | goto err_free_tdma; |
| 344 | } |
| 345 | skip_ctx = true; |
| 346 | |
| 347 | mv_cesa_set_crypt_op_len(op, iter.base.op_len); |
| 348 | |
| 349 | /* Add input transfers */ |
| 350 | ret = mv_cesa_dma_add_op_transfers(&chain, &iter.base, |
| 351 | &iter.src, flags); |
| 352 | if (ret) |
| 353 | goto err_free_tdma; |
| 354 | |
| 355 | /* Add dummy desc to launch the crypto operation */ |
| 356 | ret = mv_cesa_dma_add_dummy_launch(&chain, flags); |
| 357 | if (ret) |
| 358 | goto err_free_tdma; |
| 359 | |
| 360 | /* Add output transfers */ |
| 361 | ret = mv_cesa_dma_add_op_transfers(&chain, &iter.base, |
| 362 | &iter.dst, flags); |
| 363 | if (ret) |
| 364 | goto err_free_tdma; |
| 365 | |
| 366 | } while (mv_cesa_ablkcipher_req_iter_next_op(&iter)); |
| 367 | |
| Romain Perier | bac8e80 | 2016-06-21 10:08:34 +0200 | [diff] [blame^] | 368 | /* Add output data for IV */ |
| 369 | ivsize = crypto_ablkcipher_ivsize(crypto_ablkcipher_reqtfm(req)); |
| 370 | ret = mv_cesa_dma_add_iv_op(&chain, CESA_SA_CRYPT_IV_SRAM_OFFSET, |
| 371 | ivsize, CESA_TDMA_SRC_IN_SRAM, flags); |
| 372 | |
| 373 | if (ret) |
| 374 | goto err_free_tdma; |
| 375 | |
| Boris BREZILLON | db509a4 | 2015-06-18 15:46:21 +0200 | [diff] [blame] | 376 | dreq->chain = chain; |
| 377 | |
| 378 | return 0; |
| 379 | |
| 380 | err_free_tdma: |
| 381 | mv_cesa_dma_cleanup(dreq); |
| 382 | if (req->dst != req->src) |
| 383 | dma_unmap_sg(cesa_dev->dev, req->dst, creq->dst_nents, |
| 384 | DMA_FROM_DEVICE); |
| 385 | |
| 386 | err_unmap_src: |
| 387 | dma_unmap_sg(cesa_dev->dev, req->src, creq->src_nents, |
| 388 | req->dst != req->src ? DMA_TO_DEVICE : DMA_BIDIRECTIONAL); |
| 389 | |
| 390 | return ret; |
| 391 | } |
| 392 | |
| Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 393 | static inline int |
| 394 | mv_cesa_ablkcipher_std_req_init(struct ablkcipher_request *req, |
| 395 | const struct mv_cesa_op_ctx *op_templ) |
| 396 | { |
| 397 | struct mv_cesa_ablkcipher_req *creq = ablkcipher_request_ctx(req); |
| 398 | struct mv_cesa_ablkcipher_std_req *sreq = &creq->req.std; |
| 399 | |
| 400 | sreq->base.type = CESA_STD_REQ; |
| 401 | sreq->op = *op_templ; |
| 402 | sreq->skip_ctx = false; |
| 403 | |
| 404 | return 0; |
| 405 | } |
| 406 | |
| 407 | static int mv_cesa_ablkcipher_req_init(struct ablkcipher_request *req, |
| 408 | struct mv_cesa_op_ctx *tmpl) |
| 409 | { |
| 410 | struct mv_cesa_ablkcipher_req *creq = ablkcipher_request_ctx(req); |
| 411 | struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req); |
| 412 | unsigned int blksize = crypto_ablkcipher_blocksize(tfm); |
| Boris BREZILLON | db509a4 | 2015-06-18 15:46:21 +0200 | [diff] [blame] | 413 | int ret; |
| Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 414 | |
| 415 | if (!IS_ALIGNED(req->nbytes, blksize)) |
| 416 | return -EINVAL; |
| 417 | |
| 418 | creq->src_nents = sg_nents_for_len(req->src, req->nbytes); |
| LABBE Corentin | c22dafb | 2015-11-04 21:13:33 +0100 | [diff] [blame] | 419 | if (creq->src_nents < 0) { |
| 420 | dev_err(cesa_dev->dev, "Invalid number of src SG"); |
| 421 | return creq->src_nents; |
| 422 | } |
| Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 423 | creq->dst_nents = sg_nents_for_len(req->dst, req->nbytes); |
| LABBE Corentin | c22dafb | 2015-11-04 21:13:33 +0100 | [diff] [blame] | 424 | if (creq->dst_nents < 0) { |
| 425 | dev_err(cesa_dev->dev, "Invalid number of dst SG"); |
| 426 | return creq->dst_nents; |
| 427 | } |
| Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 428 | |
| 429 | mv_cesa_update_op_cfg(tmpl, CESA_SA_DESC_CFG_OP_CRYPT_ONLY, |
| 430 | CESA_SA_DESC_CFG_OP_MSK); |
| 431 | |
| Boris BREZILLON | db509a4 | 2015-06-18 15:46:21 +0200 | [diff] [blame] | 432 | /* TODO: add a threshold for DMA usage */ |
| 433 | if (cesa_dev->caps->has_tdma) |
| 434 | ret = mv_cesa_ablkcipher_dma_req_init(req, tmpl); |
| 435 | else |
| 436 | ret = mv_cesa_ablkcipher_std_req_init(req, tmpl); |
| 437 | |
| 438 | return ret; |
| Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 439 | } |
| 440 | |
| Boris BREZILLON | 7b3aaaa | 2015-06-18 15:46:22 +0200 | [diff] [blame] | 441 | static int mv_cesa_des_op(struct ablkcipher_request *req, |
| 442 | struct mv_cesa_op_ctx *tmpl) |
| 443 | { |
| 444 | struct mv_cesa_des_ctx *ctx = crypto_tfm_ctx(req->base.tfm); |
| 445 | int ret; |
| 446 | |
| 447 | mv_cesa_update_op_cfg(tmpl, CESA_SA_DESC_CFG_CRYPTM_DES, |
| 448 | CESA_SA_DESC_CFG_CRYPTM_MSK); |
| 449 | |
| 450 | memcpy(tmpl->ctx.blkcipher.key, ctx->key, DES_KEY_SIZE); |
| 451 | |
| 452 | ret = mv_cesa_ablkcipher_req_init(req, tmpl); |
| 453 | if (ret) |
| 454 | return ret; |
| 455 | |
| 456 | ret = mv_cesa_queue_req(&req->base); |
| Thomas Petazzoni | cfcd227 | 2015-09-18 17:25:36 +0200 | [diff] [blame] | 457 | if (mv_cesa_req_needs_cleanup(&req->base, ret)) |
| Boris BREZILLON | 7b3aaaa | 2015-06-18 15:46:22 +0200 | [diff] [blame] | 458 | mv_cesa_ablkcipher_cleanup(req); |
| 459 | |
| 460 | return ret; |
| 461 | } |
| 462 | |
| 463 | static int mv_cesa_ecb_des_encrypt(struct ablkcipher_request *req) |
| 464 | { |
| 465 | struct mv_cesa_op_ctx tmpl; |
| 466 | |
| 467 | mv_cesa_set_op_cfg(&tmpl, |
| 468 | CESA_SA_DESC_CFG_CRYPTCM_ECB | |
| 469 | CESA_SA_DESC_CFG_DIR_ENC); |
| 470 | |
| 471 | return mv_cesa_des_op(req, &tmpl); |
| 472 | } |
| 473 | |
| 474 | static int mv_cesa_ecb_des_decrypt(struct ablkcipher_request *req) |
| 475 | { |
| 476 | struct mv_cesa_op_ctx tmpl; |
| 477 | |
| 478 | mv_cesa_set_op_cfg(&tmpl, |
| 479 | CESA_SA_DESC_CFG_CRYPTCM_ECB | |
| 480 | CESA_SA_DESC_CFG_DIR_DEC); |
| 481 | |
| 482 | return mv_cesa_des_op(req, &tmpl); |
| 483 | } |
| 484 | |
| 485 | struct crypto_alg mv_cesa_ecb_des_alg = { |
| 486 | .cra_name = "ecb(des)", |
| 487 | .cra_driver_name = "mv-ecb-des", |
| 488 | .cra_priority = 300, |
| 489 | .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | |
| 490 | CRYPTO_ALG_KERN_DRIVER_ONLY | CRYPTO_ALG_ASYNC, |
| 491 | .cra_blocksize = DES_BLOCK_SIZE, |
| 492 | .cra_ctxsize = sizeof(struct mv_cesa_des_ctx), |
| 493 | .cra_alignmask = 0, |
| 494 | .cra_type = &crypto_ablkcipher_type, |
| 495 | .cra_module = THIS_MODULE, |
| 496 | .cra_init = mv_cesa_ablkcipher_cra_init, |
| 497 | .cra_u = { |
| 498 | .ablkcipher = { |
| 499 | .min_keysize = DES_KEY_SIZE, |
| 500 | .max_keysize = DES_KEY_SIZE, |
| 501 | .setkey = mv_cesa_des_setkey, |
| 502 | .encrypt = mv_cesa_ecb_des_encrypt, |
| 503 | .decrypt = mv_cesa_ecb_des_decrypt, |
| 504 | }, |
| 505 | }, |
| 506 | }; |
| 507 | |
| 508 | static int mv_cesa_cbc_des_op(struct ablkcipher_request *req, |
| 509 | struct mv_cesa_op_ctx *tmpl) |
| 510 | { |
| 511 | mv_cesa_update_op_cfg(tmpl, CESA_SA_DESC_CFG_CRYPTCM_CBC, |
| 512 | CESA_SA_DESC_CFG_CRYPTCM_MSK); |
| 513 | |
| 514 | memcpy(tmpl->ctx.blkcipher.iv, req->info, DES_BLOCK_SIZE); |
| 515 | |
| 516 | return mv_cesa_des_op(req, tmpl); |
| 517 | } |
| 518 | |
| 519 | static int mv_cesa_cbc_des_encrypt(struct ablkcipher_request *req) |
| 520 | { |
| 521 | struct mv_cesa_op_ctx tmpl; |
| 522 | |
| 523 | mv_cesa_set_op_cfg(&tmpl, CESA_SA_DESC_CFG_DIR_ENC); |
| 524 | |
| 525 | return mv_cesa_cbc_des_op(req, &tmpl); |
| 526 | } |
| 527 | |
| 528 | static int mv_cesa_cbc_des_decrypt(struct ablkcipher_request *req) |
| 529 | { |
| 530 | struct mv_cesa_op_ctx tmpl; |
| 531 | |
| 532 | mv_cesa_set_op_cfg(&tmpl, CESA_SA_DESC_CFG_DIR_DEC); |
| 533 | |
| 534 | return mv_cesa_cbc_des_op(req, &tmpl); |
| 535 | } |
| 536 | |
| 537 | struct crypto_alg mv_cesa_cbc_des_alg = { |
| 538 | .cra_name = "cbc(des)", |
| 539 | .cra_driver_name = "mv-cbc-des", |
| 540 | .cra_priority = 300, |
| 541 | .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | |
| 542 | CRYPTO_ALG_KERN_DRIVER_ONLY | CRYPTO_ALG_ASYNC, |
| 543 | .cra_blocksize = DES_BLOCK_SIZE, |
| 544 | .cra_ctxsize = sizeof(struct mv_cesa_des_ctx), |
| 545 | .cra_alignmask = 0, |
| 546 | .cra_type = &crypto_ablkcipher_type, |
| 547 | .cra_module = THIS_MODULE, |
| 548 | .cra_init = mv_cesa_ablkcipher_cra_init, |
| 549 | .cra_u = { |
| 550 | .ablkcipher = { |
| 551 | .min_keysize = DES_KEY_SIZE, |
| 552 | .max_keysize = DES_KEY_SIZE, |
| 553 | .ivsize = DES_BLOCK_SIZE, |
| 554 | .setkey = mv_cesa_des_setkey, |
| 555 | .encrypt = mv_cesa_cbc_des_encrypt, |
| 556 | .decrypt = mv_cesa_cbc_des_decrypt, |
| 557 | }, |
| 558 | }, |
| 559 | }; |
| 560 | |
| Arnaud Ebalard | 4ada483 | 2015-06-18 15:46:23 +0200 | [diff] [blame] | 561 | static int mv_cesa_des3_op(struct ablkcipher_request *req, |
| 562 | struct mv_cesa_op_ctx *tmpl) |
| 563 | { |
| 564 | struct mv_cesa_des3_ctx *ctx = crypto_tfm_ctx(req->base.tfm); |
| 565 | int ret; |
| 566 | |
| 567 | mv_cesa_update_op_cfg(tmpl, CESA_SA_DESC_CFG_CRYPTM_3DES, |
| 568 | CESA_SA_DESC_CFG_CRYPTM_MSK); |
| 569 | |
| 570 | memcpy(tmpl->ctx.blkcipher.key, ctx->key, DES3_EDE_KEY_SIZE); |
| 571 | |
| 572 | ret = mv_cesa_ablkcipher_req_init(req, tmpl); |
| 573 | if (ret) |
| 574 | return ret; |
| 575 | |
| 576 | ret = mv_cesa_queue_req(&req->base); |
| Thomas Petazzoni | cfcd227 | 2015-09-18 17:25:36 +0200 | [diff] [blame] | 577 | if (mv_cesa_req_needs_cleanup(&req->base, ret)) |
| Arnaud Ebalard | 4ada483 | 2015-06-18 15:46:23 +0200 | [diff] [blame] | 578 | mv_cesa_ablkcipher_cleanup(req); |
| 579 | |
| 580 | return ret; |
| 581 | } |
| 582 | |
| 583 | static int mv_cesa_ecb_des3_ede_encrypt(struct ablkcipher_request *req) |
| 584 | { |
| 585 | struct mv_cesa_op_ctx tmpl; |
| 586 | |
| 587 | mv_cesa_set_op_cfg(&tmpl, |
| 588 | CESA_SA_DESC_CFG_CRYPTCM_ECB | |
| 589 | CESA_SA_DESC_CFG_3DES_EDE | |
| 590 | CESA_SA_DESC_CFG_DIR_ENC); |
| 591 | |
| 592 | return mv_cesa_des3_op(req, &tmpl); |
| 593 | } |
| 594 | |
| 595 | static int mv_cesa_ecb_des3_ede_decrypt(struct ablkcipher_request *req) |
| 596 | { |
| 597 | struct mv_cesa_op_ctx tmpl; |
| 598 | |
| 599 | mv_cesa_set_op_cfg(&tmpl, |
| 600 | CESA_SA_DESC_CFG_CRYPTCM_ECB | |
| 601 | CESA_SA_DESC_CFG_3DES_EDE | |
| 602 | CESA_SA_DESC_CFG_DIR_DEC); |
| 603 | |
| 604 | return mv_cesa_des3_op(req, &tmpl); |
| 605 | } |
| 606 | |
| 607 | struct crypto_alg mv_cesa_ecb_des3_ede_alg = { |
| 608 | .cra_name = "ecb(des3_ede)", |
| 609 | .cra_driver_name = "mv-ecb-des3-ede", |
| 610 | .cra_priority = 300, |
| 611 | .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | |
| 612 | CRYPTO_ALG_KERN_DRIVER_ONLY | CRYPTO_ALG_ASYNC, |
| 613 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 614 | .cra_ctxsize = sizeof(struct mv_cesa_des3_ctx), |
| 615 | .cra_alignmask = 0, |
| 616 | .cra_type = &crypto_ablkcipher_type, |
| 617 | .cra_module = THIS_MODULE, |
| 618 | .cra_init = mv_cesa_ablkcipher_cra_init, |
| 619 | .cra_u = { |
| 620 | .ablkcipher = { |
| 621 | .min_keysize = DES3_EDE_KEY_SIZE, |
| 622 | .max_keysize = DES3_EDE_KEY_SIZE, |
| 623 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 624 | .setkey = mv_cesa_des3_ede_setkey, |
| 625 | .encrypt = mv_cesa_ecb_des3_ede_encrypt, |
| 626 | .decrypt = mv_cesa_ecb_des3_ede_decrypt, |
| 627 | }, |
| 628 | }, |
| 629 | }; |
| 630 | |
| 631 | static int mv_cesa_cbc_des3_op(struct ablkcipher_request *req, |
| 632 | struct mv_cesa_op_ctx *tmpl) |
| 633 | { |
| 634 | memcpy(tmpl->ctx.blkcipher.iv, req->info, DES3_EDE_BLOCK_SIZE); |
| 635 | |
| 636 | return mv_cesa_des3_op(req, tmpl); |
| 637 | } |
| 638 | |
| 639 | static int mv_cesa_cbc_des3_ede_encrypt(struct ablkcipher_request *req) |
| 640 | { |
| 641 | struct mv_cesa_op_ctx tmpl; |
| 642 | |
| 643 | mv_cesa_set_op_cfg(&tmpl, |
| 644 | CESA_SA_DESC_CFG_CRYPTCM_CBC | |
| 645 | CESA_SA_DESC_CFG_3DES_EDE | |
| 646 | CESA_SA_DESC_CFG_DIR_ENC); |
| 647 | |
| 648 | return mv_cesa_cbc_des3_op(req, &tmpl); |
| 649 | } |
| 650 | |
| 651 | static int mv_cesa_cbc_des3_ede_decrypt(struct ablkcipher_request *req) |
| 652 | { |
| 653 | struct mv_cesa_op_ctx tmpl; |
| 654 | |
| 655 | mv_cesa_set_op_cfg(&tmpl, |
| 656 | CESA_SA_DESC_CFG_CRYPTCM_CBC | |
| 657 | CESA_SA_DESC_CFG_3DES_EDE | |
| 658 | CESA_SA_DESC_CFG_DIR_DEC); |
| 659 | |
| 660 | return mv_cesa_cbc_des3_op(req, &tmpl); |
| 661 | } |
| 662 | |
| 663 | struct crypto_alg mv_cesa_cbc_des3_ede_alg = { |
| 664 | .cra_name = "cbc(des3_ede)", |
| 665 | .cra_driver_name = "mv-cbc-des3-ede", |
| 666 | .cra_priority = 300, |
| 667 | .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | |
| 668 | CRYPTO_ALG_KERN_DRIVER_ONLY | CRYPTO_ALG_ASYNC, |
| 669 | .cra_blocksize = DES3_EDE_BLOCK_SIZE, |
| 670 | .cra_ctxsize = sizeof(struct mv_cesa_des3_ctx), |
| 671 | .cra_alignmask = 0, |
| 672 | .cra_type = &crypto_ablkcipher_type, |
| 673 | .cra_module = THIS_MODULE, |
| 674 | .cra_init = mv_cesa_ablkcipher_cra_init, |
| 675 | .cra_u = { |
| 676 | .ablkcipher = { |
| 677 | .min_keysize = DES3_EDE_KEY_SIZE, |
| 678 | .max_keysize = DES3_EDE_KEY_SIZE, |
| 679 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 680 | .setkey = mv_cesa_des3_ede_setkey, |
| 681 | .encrypt = mv_cesa_cbc_des3_ede_encrypt, |
| 682 | .decrypt = mv_cesa_cbc_des3_ede_decrypt, |
| 683 | }, |
| 684 | }, |
| 685 | }; |
| 686 | |
| Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 687 | static int mv_cesa_aes_op(struct ablkcipher_request *req, |
| 688 | struct mv_cesa_op_ctx *tmpl) |
| 689 | { |
| 690 | struct mv_cesa_aes_ctx *ctx = crypto_tfm_ctx(req->base.tfm); |
| 691 | int ret, i; |
| 692 | u32 *key; |
| 693 | u32 cfg; |
| 694 | |
| 695 | cfg = CESA_SA_DESC_CFG_CRYPTM_AES; |
| 696 | |
| 697 | if (mv_cesa_get_op_cfg(tmpl) & CESA_SA_DESC_CFG_DIR_DEC) |
| 698 | key = ctx->aes.key_dec; |
| 699 | else |
| 700 | key = ctx->aes.key_enc; |
| 701 | |
| 702 | for (i = 0; i < ctx->aes.key_length / sizeof(u32); i++) |
| 703 | tmpl->ctx.blkcipher.key[i] = cpu_to_le32(key[i]); |
| 704 | |
| 705 | if (ctx->aes.key_length == 24) |
| 706 | cfg |= CESA_SA_DESC_CFG_AES_LEN_192; |
| 707 | else if (ctx->aes.key_length == 32) |
| 708 | cfg |= CESA_SA_DESC_CFG_AES_LEN_256; |
| 709 | |
| 710 | mv_cesa_update_op_cfg(tmpl, cfg, |
| 711 | CESA_SA_DESC_CFG_CRYPTM_MSK | |
| 712 | CESA_SA_DESC_CFG_AES_LEN_MSK); |
| 713 | |
| 714 | ret = mv_cesa_ablkcipher_req_init(req, tmpl); |
| 715 | if (ret) |
| 716 | return ret; |
| 717 | |
| Boris BREZILLON | db509a4 | 2015-06-18 15:46:21 +0200 | [diff] [blame] | 718 | ret = mv_cesa_queue_req(&req->base); |
| Thomas Petazzoni | cfcd227 | 2015-09-18 17:25:36 +0200 | [diff] [blame] | 719 | if (mv_cesa_req_needs_cleanup(&req->base, ret)) |
| Boris BREZILLON | db509a4 | 2015-06-18 15:46:21 +0200 | [diff] [blame] | 720 | mv_cesa_ablkcipher_cleanup(req); |
| 721 | |
| 722 | return ret; |
| Boris BREZILLON | f63601f | 2015-06-18 15:46:20 +0200 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | static int mv_cesa_ecb_aes_encrypt(struct ablkcipher_request *req) |
| 726 | { |
| 727 | struct mv_cesa_op_ctx tmpl; |
| 728 | |
| 729 | mv_cesa_set_op_cfg(&tmpl, |
| 730 | CESA_SA_DESC_CFG_CRYPTCM_ECB | |
| 731 | CESA_SA_DESC_CFG_DIR_ENC); |
| 732 | |
| 733 | return mv_cesa_aes_op(req, &tmpl); |
| 734 | } |
| 735 | |
| 736 | static int mv_cesa_ecb_aes_decrypt(struct ablkcipher_request *req) |
| 737 | { |
| 738 | struct mv_cesa_op_ctx tmpl; |
| 739 | |
| 740 | mv_cesa_set_op_cfg(&tmpl, |
| 741 | CESA_SA_DESC_CFG_CRYPTCM_ECB | |
| 742 | CESA_SA_DESC_CFG_DIR_DEC); |
| 743 | |
| 744 | return mv_cesa_aes_op(req, &tmpl); |
| 745 | } |
| 746 | |
| 747 | struct crypto_alg mv_cesa_ecb_aes_alg = { |
| 748 | .cra_name = "ecb(aes)", |
| 749 | .cra_driver_name = "mv-ecb-aes", |
| 750 | .cra_priority = 300, |
| 751 | .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | |
| 752 | CRYPTO_ALG_KERN_DRIVER_ONLY | CRYPTO_ALG_ASYNC, |
| 753 | .cra_blocksize = AES_BLOCK_SIZE, |
| 754 | .cra_ctxsize = sizeof(struct mv_cesa_aes_ctx), |
| 755 | .cra_alignmask = 0, |
| 756 | .cra_type = &crypto_ablkcipher_type, |
| 757 | .cra_module = THIS_MODULE, |
| 758 | .cra_init = mv_cesa_ablkcipher_cra_init, |
| 759 | .cra_u = { |
| 760 | .ablkcipher = { |
| 761 | .min_keysize = AES_MIN_KEY_SIZE, |
| 762 | .max_keysize = AES_MAX_KEY_SIZE, |
| 763 | .setkey = mv_cesa_aes_setkey, |
| 764 | .encrypt = mv_cesa_ecb_aes_encrypt, |
| 765 | .decrypt = mv_cesa_ecb_aes_decrypt, |
| 766 | }, |
| 767 | }, |
| 768 | }; |
| 769 | |
| 770 | static int mv_cesa_cbc_aes_op(struct ablkcipher_request *req, |
| 771 | struct mv_cesa_op_ctx *tmpl) |
| 772 | { |
| 773 | mv_cesa_update_op_cfg(tmpl, CESA_SA_DESC_CFG_CRYPTCM_CBC, |
| 774 | CESA_SA_DESC_CFG_CRYPTCM_MSK); |
| 775 | memcpy(tmpl->ctx.blkcipher.iv, req->info, AES_BLOCK_SIZE); |
| 776 | |
| 777 | return mv_cesa_aes_op(req, tmpl); |
| 778 | } |
| 779 | |
| 780 | static int mv_cesa_cbc_aes_encrypt(struct ablkcipher_request *req) |
| 781 | { |
| 782 | struct mv_cesa_op_ctx tmpl; |
| 783 | |
| 784 | mv_cesa_set_op_cfg(&tmpl, CESA_SA_DESC_CFG_DIR_ENC); |
| 785 | |
| 786 | return mv_cesa_cbc_aes_op(req, &tmpl); |
| 787 | } |
| 788 | |
| 789 | static int mv_cesa_cbc_aes_decrypt(struct ablkcipher_request *req) |
| 790 | { |
| 791 | struct mv_cesa_op_ctx tmpl; |
| 792 | |
| 793 | mv_cesa_set_op_cfg(&tmpl, CESA_SA_DESC_CFG_DIR_DEC); |
| 794 | |
| 795 | return mv_cesa_cbc_aes_op(req, &tmpl); |
| 796 | } |
| 797 | |
| 798 | struct crypto_alg mv_cesa_cbc_aes_alg = { |
| 799 | .cra_name = "cbc(aes)", |
| 800 | .cra_driver_name = "mv-cbc-aes", |
| 801 | .cra_priority = 300, |
| 802 | .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | |
| 803 | CRYPTO_ALG_KERN_DRIVER_ONLY | CRYPTO_ALG_ASYNC, |
| 804 | .cra_blocksize = AES_BLOCK_SIZE, |
| 805 | .cra_ctxsize = sizeof(struct mv_cesa_aes_ctx), |
| 806 | .cra_alignmask = 0, |
| 807 | .cra_type = &crypto_ablkcipher_type, |
| 808 | .cra_module = THIS_MODULE, |
| 809 | .cra_init = mv_cesa_ablkcipher_cra_init, |
| 810 | .cra_u = { |
| 811 | .ablkcipher = { |
| 812 | .min_keysize = AES_MIN_KEY_SIZE, |
| 813 | .max_keysize = AES_MAX_KEY_SIZE, |
| 814 | .ivsize = AES_BLOCK_SIZE, |
| 815 | .setkey = mv_cesa_aes_setkey, |
| 816 | .encrypt = mv_cesa_cbc_aes_encrypt, |
| 817 | .decrypt = mv_cesa_cbc_aes_decrypt, |
| 818 | }, |
| 819 | }, |
| 820 | }; |