| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Cryptographic API. |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 5 | 6 | * |
|---|
| 6 | 7 | * Copyright (c) 2012 Eukréa Electromatique - ATMEL |
|---|
| 7 | 8 | * Author: Nicolas Royer <nicolas@eukrea.com> |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 10 | | - * it under the terms of the GNU General Public License version 2 as published |
|---|
| 11 | | - * by the Free Software Foundation. |
|---|
| 12 | 9 | * |
|---|
| 13 | 10 | * Some ideas are from omap-aes.c drivers. |
|---|
| 14 | 11 | */ |
|---|
| .. | .. |
|---|
| 24 | 21 | #include <linux/platform_device.h> |
|---|
| 25 | 22 | |
|---|
| 26 | 23 | #include <linux/device.h> |
|---|
| 24 | +#include <linux/dmaengine.h> |
|---|
| 27 | 25 | #include <linux/init.h> |
|---|
| 28 | 26 | #include <linux/errno.h> |
|---|
| 29 | 27 | #include <linux/interrupt.h> |
|---|
| .. | .. |
|---|
| 33 | 31 | #include <linux/of_device.h> |
|---|
| 34 | 32 | #include <linux/delay.h> |
|---|
| 35 | 33 | #include <linux/crypto.h> |
|---|
| 36 | | -#include <linux/cryptohash.h> |
|---|
| 37 | 34 | #include <crypto/scatterwalk.h> |
|---|
| 38 | 35 | #include <crypto/algapi.h> |
|---|
| 39 | | -#include <crypto/des.h> |
|---|
| 40 | | -#include <crypto/hash.h> |
|---|
| 41 | | -#include <crypto/internal/hash.h> |
|---|
| 42 | | -#include <linux/platform_data/crypto-atmel.h> |
|---|
| 36 | +#include <crypto/internal/des.h> |
|---|
| 37 | +#include <crypto/internal/skcipher.h> |
|---|
| 43 | 38 | #include "atmel-tdes-regs.h" |
|---|
| 44 | 39 | |
|---|
| 45 | | -/* TDES flags */ |
|---|
| 46 | | -#define TDES_FLAGS_MODE_MASK 0x00ff |
|---|
| 47 | | -#define TDES_FLAGS_ENCRYPT BIT(0) |
|---|
| 48 | | -#define TDES_FLAGS_CBC BIT(1) |
|---|
| 49 | | -#define TDES_FLAGS_CFB BIT(2) |
|---|
| 50 | | -#define TDES_FLAGS_CFB8 BIT(3) |
|---|
| 51 | | -#define TDES_FLAGS_CFB16 BIT(4) |
|---|
| 52 | | -#define TDES_FLAGS_CFB32 BIT(5) |
|---|
| 53 | | -#define TDES_FLAGS_CFB64 BIT(6) |
|---|
| 54 | | -#define TDES_FLAGS_OFB BIT(7) |
|---|
| 40 | +#define ATMEL_TDES_PRIORITY 300 |
|---|
| 55 | 41 | |
|---|
| 56 | | -#define TDES_FLAGS_INIT BIT(16) |
|---|
| 57 | | -#define TDES_FLAGS_FAST BIT(17) |
|---|
| 58 | | -#define TDES_FLAGS_BUSY BIT(18) |
|---|
| 59 | | -#define TDES_FLAGS_DMA BIT(19) |
|---|
| 42 | +/* TDES flags */ |
|---|
| 43 | +/* Reserve bits [17:16], [13:12], [2:0] for AES Mode Register */ |
|---|
| 44 | +#define TDES_FLAGS_ENCRYPT TDES_MR_CYPHER_ENC |
|---|
| 45 | +#define TDES_FLAGS_OPMODE_MASK (TDES_MR_OPMOD_MASK | TDES_MR_CFBS_MASK) |
|---|
| 46 | +#define TDES_FLAGS_ECB TDES_MR_OPMOD_ECB |
|---|
| 47 | +#define TDES_FLAGS_CBC TDES_MR_OPMOD_CBC |
|---|
| 48 | +#define TDES_FLAGS_OFB TDES_MR_OPMOD_OFB |
|---|
| 49 | +#define TDES_FLAGS_CFB64 (TDES_MR_OPMOD_CFB | TDES_MR_CFBS_64b) |
|---|
| 50 | +#define TDES_FLAGS_CFB32 (TDES_MR_OPMOD_CFB | TDES_MR_CFBS_32b) |
|---|
| 51 | +#define TDES_FLAGS_CFB16 (TDES_MR_OPMOD_CFB | TDES_MR_CFBS_16b) |
|---|
| 52 | +#define TDES_FLAGS_CFB8 (TDES_MR_OPMOD_CFB | TDES_MR_CFBS_8b) |
|---|
| 53 | + |
|---|
| 54 | +#define TDES_FLAGS_MODE_MASK (TDES_FLAGS_OPMODE_MASK | TDES_FLAGS_ENCRYPT) |
|---|
| 55 | + |
|---|
| 56 | +#define TDES_FLAGS_INIT BIT(3) |
|---|
| 57 | +#define TDES_FLAGS_FAST BIT(4) |
|---|
| 58 | +#define TDES_FLAGS_BUSY BIT(5) |
|---|
| 59 | +#define TDES_FLAGS_DMA BIT(6) |
|---|
| 60 | 60 | |
|---|
| 61 | 61 | #define ATMEL_TDES_QUEUE_LENGTH 50 |
|---|
| 62 | 62 | |
|---|
| .. | .. |
|---|
| 75 | 75 | struct atmel_tdes_dev *dd; |
|---|
| 76 | 76 | |
|---|
| 77 | 77 | int keylen; |
|---|
| 78 | | - u32 key[3*DES_KEY_SIZE / sizeof(u32)]; |
|---|
| 78 | + u32 key[DES3_EDE_KEY_SIZE / sizeof(u32)]; |
|---|
| 79 | 79 | unsigned long flags; |
|---|
| 80 | 80 | |
|---|
| 81 | 81 | u16 block_size; |
|---|
| .. | .. |
|---|
| 83 | 83 | |
|---|
| 84 | 84 | struct atmel_tdes_reqctx { |
|---|
| 85 | 85 | unsigned long mode; |
|---|
| 86 | + u8 lastc[DES_BLOCK_SIZE]; |
|---|
| 86 | 87 | }; |
|---|
| 87 | 88 | |
|---|
| 88 | 89 | struct atmel_tdes_dma { |
|---|
| .. | .. |
|---|
| 101 | 102 | int irq; |
|---|
| 102 | 103 | |
|---|
| 103 | 104 | unsigned long flags; |
|---|
| 104 | | - int err; |
|---|
| 105 | 105 | |
|---|
| 106 | 106 | spinlock_t lock; |
|---|
| 107 | 107 | struct crypto_queue queue; |
|---|
| .. | .. |
|---|
| 109 | 109 | struct tasklet_struct done_task; |
|---|
| 110 | 110 | struct tasklet_struct queue_task; |
|---|
| 111 | 111 | |
|---|
| 112 | | - struct ablkcipher_request *req; |
|---|
| 112 | + struct skcipher_request *req; |
|---|
| 113 | 113 | size_t total; |
|---|
| 114 | 114 | |
|---|
| 115 | 115 | struct scatterlist *in_sg; |
|---|
| .. | .. |
|---|
| 190 | 190 | } |
|---|
| 191 | 191 | |
|---|
| 192 | 192 | static void atmel_tdes_write_n(struct atmel_tdes_dev *dd, u32 offset, |
|---|
| 193 | | - u32 *value, int count) |
|---|
| 193 | + const u32 *value, int count) |
|---|
| 194 | 194 | { |
|---|
| 195 | 195 | for (; count--; value++, offset += 4) |
|---|
| 196 | 196 | atmel_tdes_write(dd, offset, *value); |
|---|
| .. | .. |
|---|
| 227 | 227 | if (!(dd->flags & TDES_FLAGS_INIT)) { |
|---|
| 228 | 228 | atmel_tdes_write(dd, TDES_CR, TDES_CR_SWRST); |
|---|
| 229 | 229 | dd->flags |= TDES_FLAGS_INIT; |
|---|
| 230 | | - dd->err = 0; |
|---|
| 231 | 230 | } |
|---|
| 232 | 231 | |
|---|
| 233 | 232 | return 0; |
|---|
| .. | .. |
|---|
| 238 | 237 | return atmel_tdes_read(dd, TDES_HW_VERSION) & 0x00000fff; |
|---|
| 239 | 238 | } |
|---|
| 240 | 239 | |
|---|
| 241 | | -static void atmel_tdes_hw_version_init(struct atmel_tdes_dev *dd) |
|---|
| 240 | +static int atmel_tdes_hw_version_init(struct atmel_tdes_dev *dd) |
|---|
| 242 | 241 | { |
|---|
| 243 | | - atmel_tdes_hw_init(dd); |
|---|
| 242 | + int err; |
|---|
| 243 | + |
|---|
| 244 | + err = atmel_tdes_hw_init(dd); |
|---|
| 245 | + if (err) |
|---|
| 246 | + return err; |
|---|
| 244 | 247 | |
|---|
| 245 | 248 | dd->hw_version = atmel_tdes_get_version(dd); |
|---|
| 246 | 249 | |
|---|
| .. | .. |
|---|
| 248 | 251 | "version: 0x%x\n", dd->hw_version); |
|---|
| 249 | 252 | |
|---|
| 250 | 253 | clk_disable_unprepare(dd->iclk); |
|---|
| 254 | + |
|---|
| 255 | + return 0; |
|---|
| 251 | 256 | } |
|---|
| 252 | 257 | |
|---|
| 253 | 258 | static void atmel_tdes_dma_callback(void *data) |
|---|
| .. | .. |
|---|
| 261 | 266 | static int atmel_tdes_write_ctrl(struct atmel_tdes_dev *dd) |
|---|
| 262 | 267 | { |
|---|
| 263 | 268 | int err; |
|---|
| 264 | | - u32 valcr = 0, valmr = TDES_MR_SMOD_PDC; |
|---|
| 269 | + u32 valmr = TDES_MR_SMOD_PDC; |
|---|
| 265 | 270 | |
|---|
| 266 | 271 | err = atmel_tdes_hw_init(dd); |
|---|
| 267 | 272 | |
|---|
| .. | .. |
|---|
| 283 | 288 | valmr |= TDES_MR_TDESMOD_DES; |
|---|
| 284 | 289 | } |
|---|
| 285 | 290 | |
|---|
| 286 | | - if (dd->flags & TDES_FLAGS_CBC) { |
|---|
| 287 | | - valmr |= TDES_MR_OPMOD_CBC; |
|---|
| 288 | | - } else if (dd->flags & TDES_FLAGS_CFB) { |
|---|
| 289 | | - valmr |= TDES_MR_OPMOD_CFB; |
|---|
| 291 | + valmr |= dd->flags & TDES_FLAGS_MODE_MASK; |
|---|
| 290 | 292 | |
|---|
| 291 | | - if (dd->flags & TDES_FLAGS_CFB8) |
|---|
| 292 | | - valmr |= TDES_MR_CFBS_8b; |
|---|
| 293 | | - else if (dd->flags & TDES_FLAGS_CFB16) |
|---|
| 294 | | - valmr |= TDES_MR_CFBS_16b; |
|---|
| 295 | | - else if (dd->flags & TDES_FLAGS_CFB32) |
|---|
| 296 | | - valmr |= TDES_MR_CFBS_32b; |
|---|
| 297 | | - else if (dd->flags & TDES_FLAGS_CFB64) |
|---|
| 298 | | - valmr |= TDES_MR_CFBS_64b; |
|---|
| 299 | | - } else if (dd->flags & TDES_FLAGS_OFB) { |
|---|
| 300 | | - valmr |= TDES_MR_OPMOD_OFB; |
|---|
| 301 | | - } |
|---|
| 302 | | - |
|---|
| 303 | | - if ((dd->flags & TDES_FLAGS_ENCRYPT) || (dd->flags & TDES_FLAGS_OFB)) |
|---|
| 304 | | - valmr |= TDES_MR_CYPHER_ENC; |
|---|
| 305 | | - |
|---|
| 306 | | - atmel_tdes_write(dd, TDES_CR, valcr); |
|---|
| 307 | 293 | atmel_tdes_write(dd, TDES_MR, valmr); |
|---|
| 308 | 294 | |
|---|
| 309 | 295 | atmel_tdes_write_n(dd, TDES_KEY1W1R, dd->ctx->key, |
|---|
| 310 | 296 | dd->ctx->keylen >> 2); |
|---|
| 311 | 297 | |
|---|
| 312 | | - if (((dd->flags & TDES_FLAGS_CBC) || (dd->flags & TDES_FLAGS_CFB) || |
|---|
| 313 | | - (dd->flags & TDES_FLAGS_OFB)) && dd->req->info) { |
|---|
| 314 | | - atmel_tdes_write_n(dd, TDES_IV1R, dd->req->info, 2); |
|---|
| 315 | | - } |
|---|
| 298 | + if (dd->req->iv && (valmr & TDES_MR_OPMOD_MASK) != TDES_MR_OPMOD_ECB) |
|---|
| 299 | + atmel_tdes_write_n(dd, TDES_IV1R, (void *)dd->req->iv, 2); |
|---|
| 316 | 300 | |
|---|
| 317 | 301 | return 0; |
|---|
| 318 | 302 | } |
|---|
| .. | .. |
|---|
| 398 | 382 | free_page((unsigned long)dd->buf_in); |
|---|
| 399 | 383 | } |
|---|
| 400 | 384 | |
|---|
| 401 | | -static int atmel_tdes_crypt_pdc(struct crypto_tfm *tfm, dma_addr_t dma_addr_in, |
|---|
| 402 | | - dma_addr_t dma_addr_out, int length) |
|---|
| 385 | +static int atmel_tdes_crypt_pdc(struct atmel_tdes_dev *dd, |
|---|
| 386 | + dma_addr_t dma_addr_in, |
|---|
| 387 | + dma_addr_t dma_addr_out, int length) |
|---|
| 403 | 388 | { |
|---|
| 404 | | - struct atmel_tdes_ctx *ctx = crypto_tfm_ctx(tfm); |
|---|
| 405 | | - struct atmel_tdes_dev *dd = ctx->dd; |
|---|
| 389 | + struct atmel_tdes_reqctx *rctx = skcipher_request_ctx(dd->req); |
|---|
| 406 | 390 | int len32; |
|---|
| 407 | 391 | |
|---|
| 408 | 392 | dd->dma_size = length; |
|---|
| .. | .. |
|---|
| 412 | 396 | DMA_TO_DEVICE); |
|---|
| 413 | 397 | } |
|---|
| 414 | 398 | |
|---|
| 415 | | - if ((dd->flags & TDES_FLAGS_CFB) && (dd->flags & TDES_FLAGS_CFB8)) |
|---|
| 399 | + switch (rctx->mode & TDES_FLAGS_OPMODE_MASK) { |
|---|
| 400 | + case TDES_FLAGS_CFB8: |
|---|
| 416 | 401 | len32 = DIV_ROUND_UP(length, sizeof(u8)); |
|---|
| 417 | | - else if ((dd->flags & TDES_FLAGS_CFB) && (dd->flags & TDES_FLAGS_CFB16)) |
|---|
| 402 | + break; |
|---|
| 403 | + |
|---|
| 404 | + case TDES_FLAGS_CFB16: |
|---|
| 418 | 405 | len32 = DIV_ROUND_UP(length, sizeof(u16)); |
|---|
| 419 | | - else |
|---|
| 406 | + break; |
|---|
| 407 | + |
|---|
| 408 | + default: |
|---|
| 420 | 409 | len32 = DIV_ROUND_UP(length, sizeof(u32)); |
|---|
| 410 | + break; |
|---|
| 411 | + } |
|---|
| 421 | 412 | |
|---|
| 422 | 413 | atmel_tdes_write(dd, TDES_PTCR, TDES_PTCR_TXTDIS|TDES_PTCR_RXTDIS); |
|---|
| 423 | 414 | atmel_tdes_write(dd, TDES_TPR, dma_addr_in); |
|---|
| .. | .. |
|---|
| 434 | 425 | return 0; |
|---|
| 435 | 426 | } |
|---|
| 436 | 427 | |
|---|
| 437 | | -static int atmel_tdes_crypt_dma(struct crypto_tfm *tfm, dma_addr_t dma_addr_in, |
|---|
| 438 | | - dma_addr_t dma_addr_out, int length) |
|---|
| 428 | +static int atmel_tdes_crypt_dma(struct atmel_tdes_dev *dd, |
|---|
| 429 | + dma_addr_t dma_addr_in, |
|---|
| 430 | + dma_addr_t dma_addr_out, int length) |
|---|
| 439 | 431 | { |
|---|
| 440 | | - struct atmel_tdes_ctx *ctx = crypto_tfm_ctx(tfm); |
|---|
| 441 | | - struct atmel_tdes_dev *dd = ctx->dd; |
|---|
| 432 | + struct atmel_tdes_reqctx *rctx = skcipher_request_ctx(dd->req); |
|---|
| 442 | 433 | struct scatterlist sg[2]; |
|---|
| 443 | 434 | struct dma_async_tx_descriptor *in_desc, *out_desc; |
|---|
| 435 | + enum dma_slave_buswidth addr_width; |
|---|
| 444 | 436 | |
|---|
| 445 | 437 | dd->dma_size = length; |
|---|
| 446 | 438 | |
|---|
| .. | .. |
|---|
| 449 | 441 | DMA_TO_DEVICE); |
|---|
| 450 | 442 | } |
|---|
| 451 | 443 | |
|---|
| 452 | | - if (dd->flags & TDES_FLAGS_CFB8) { |
|---|
| 453 | | - dd->dma_lch_in.dma_conf.dst_addr_width = |
|---|
| 454 | | - DMA_SLAVE_BUSWIDTH_1_BYTE; |
|---|
| 455 | | - dd->dma_lch_out.dma_conf.src_addr_width = |
|---|
| 456 | | - DMA_SLAVE_BUSWIDTH_1_BYTE; |
|---|
| 457 | | - } else if (dd->flags & TDES_FLAGS_CFB16) { |
|---|
| 458 | | - dd->dma_lch_in.dma_conf.dst_addr_width = |
|---|
| 459 | | - DMA_SLAVE_BUSWIDTH_2_BYTES; |
|---|
| 460 | | - dd->dma_lch_out.dma_conf.src_addr_width = |
|---|
| 461 | | - DMA_SLAVE_BUSWIDTH_2_BYTES; |
|---|
| 462 | | - } else { |
|---|
| 463 | | - dd->dma_lch_in.dma_conf.dst_addr_width = |
|---|
| 464 | | - DMA_SLAVE_BUSWIDTH_4_BYTES; |
|---|
| 465 | | - dd->dma_lch_out.dma_conf.src_addr_width = |
|---|
| 466 | | - DMA_SLAVE_BUSWIDTH_4_BYTES; |
|---|
| 444 | + switch (rctx->mode & TDES_FLAGS_OPMODE_MASK) { |
|---|
| 445 | + case TDES_FLAGS_CFB8: |
|---|
| 446 | + addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; |
|---|
| 447 | + break; |
|---|
| 448 | + |
|---|
| 449 | + case TDES_FLAGS_CFB16: |
|---|
| 450 | + addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES; |
|---|
| 451 | + break; |
|---|
| 452 | + |
|---|
| 453 | + default: |
|---|
| 454 | + addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; |
|---|
| 455 | + break; |
|---|
| 467 | 456 | } |
|---|
| 457 | + |
|---|
| 458 | + dd->dma_lch_in.dma_conf.dst_addr_width = addr_width; |
|---|
| 459 | + dd->dma_lch_out.dma_conf.src_addr_width = addr_width; |
|---|
| 468 | 460 | |
|---|
| 469 | 461 | dmaengine_slave_config(dd->dma_lch_in.chan, &dd->dma_lch_in.dma_conf); |
|---|
| 470 | 462 | dmaengine_slave_config(dd->dma_lch_out.chan, &dd->dma_lch_out.dma_conf); |
|---|
| .. | .. |
|---|
| 505 | 497 | |
|---|
| 506 | 498 | static int atmel_tdes_crypt_start(struct atmel_tdes_dev *dd) |
|---|
| 507 | 499 | { |
|---|
| 508 | | - struct crypto_tfm *tfm = crypto_ablkcipher_tfm( |
|---|
| 509 | | - crypto_ablkcipher_reqtfm(dd->req)); |
|---|
| 510 | 500 | int err, fast = 0, in, out; |
|---|
| 511 | 501 | size_t count; |
|---|
| 512 | 502 | dma_addr_t addr_in, addr_out; |
|---|
| .. | .. |
|---|
| 562 | 552 | dd->total -= count; |
|---|
| 563 | 553 | |
|---|
| 564 | 554 | if (dd->caps.has_dma) |
|---|
| 565 | | - err = atmel_tdes_crypt_dma(tfm, addr_in, addr_out, count); |
|---|
| 555 | + err = atmel_tdes_crypt_dma(dd, addr_in, addr_out, count); |
|---|
| 566 | 556 | else |
|---|
| 567 | | - err = atmel_tdes_crypt_pdc(tfm, addr_in, addr_out, count); |
|---|
| 557 | + err = atmel_tdes_crypt_pdc(dd, addr_in, addr_out, count); |
|---|
| 568 | 558 | |
|---|
| 569 | 559 | if (err && (dd->flags & TDES_FLAGS_FAST)) { |
|---|
| 570 | 560 | dma_unmap_sg(dd->dev, dd->in_sg, 1, DMA_TO_DEVICE); |
|---|
| .. | .. |
|---|
| 574 | 564 | return err; |
|---|
| 575 | 565 | } |
|---|
| 576 | 566 | |
|---|
| 567 | +static void |
|---|
| 568 | +atmel_tdes_set_iv_as_last_ciphertext_block(struct atmel_tdes_dev *dd) |
|---|
| 569 | +{ |
|---|
| 570 | + struct skcipher_request *req = dd->req; |
|---|
| 571 | + struct atmel_tdes_reqctx *rctx = skcipher_request_ctx(req); |
|---|
| 572 | + struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req); |
|---|
| 573 | + unsigned int ivsize = crypto_skcipher_ivsize(skcipher); |
|---|
| 574 | + |
|---|
| 575 | + if (req->cryptlen < ivsize) |
|---|
| 576 | + return; |
|---|
| 577 | + |
|---|
| 578 | + if (rctx->mode & TDES_FLAGS_ENCRYPT) { |
|---|
| 579 | + scatterwalk_map_and_copy(req->iv, req->dst, |
|---|
| 580 | + req->cryptlen - ivsize, ivsize, 0); |
|---|
| 581 | + } else { |
|---|
| 582 | + if (req->src == req->dst) |
|---|
| 583 | + memcpy(req->iv, rctx->lastc, ivsize); |
|---|
| 584 | + else |
|---|
| 585 | + scatterwalk_map_and_copy(req->iv, req->src, |
|---|
| 586 | + req->cryptlen - ivsize, |
|---|
| 587 | + ivsize, 0); |
|---|
| 588 | + } |
|---|
| 589 | +} |
|---|
| 590 | + |
|---|
| 577 | 591 | static void atmel_tdes_finish_req(struct atmel_tdes_dev *dd, int err) |
|---|
| 578 | 592 | { |
|---|
| 579 | | - struct ablkcipher_request *req = dd->req; |
|---|
| 593 | + struct skcipher_request *req = dd->req; |
|---|
| 594 | + struct atmel_tdes_reqctx *rctx = skcipher_request_ctx(req); |
|---|
| 580 | 595 | |
|---|
| 581 | 596 | clk_disable_unprepare(dd->iclk); |
|---|
| 582 | 597 | |
|---|
| 583 | 598 | dd->flags &= ~TDES_FLAGS_BUSY; |
|---|
| 584 | 599 | |
|---|
| 600 | + if (!err && (rctx->mode & TDES_FLAGS_OPMODE_MASK) != TDES_FLAGS_ECB) |
|---|
| 601 | + atmel_tdes_set_iv_as_last_ciphertext_block(dd); |
|---|
| 602 | + |
|---|
| 585 | 603 | req->base.complete(&req->base, err); |
|---|
| 586 | 604 | } |
|---|
| 587 | 605 | |
|---|
| 588 | 606 | static int atmel_tdes_handle_queue(struct atmel_tdes_dev *dd, |
|---|
| 589 | | - struct ablkcipher_request *req) |
|---|
| 607 | + struct skcipher_request *req) |
|---|
| 590 | 608 | { |
|---|
| 591 | 609 | struct crypto_async_request *async_req, *backlog; |
|---|
| 592 | 610 | struct atmel_tdes_ctx *ctx; |
|---|
| .. | .. |
|---|
| 596 | 614 | |
|---|
| 597 | 615 | spin_lock_irqsave(&dd->lock, flags); |
|---|
| 598 | 616 | if (req) |
|---|
| 599 | | - ret = ablkcipher_enqueue_request(&dd->queue, req); |
|---|
| 617 | + ret = crypto_enqueue_request(&dd->queue, &req->base); |
|---|
| 600 | 618 | if (dd->flags & TDES_FLAGS_BUSY) { |
|---|
| 601 | 619 | spin_unlock_irqrestore(&dd->lock, flags); |
|---|
| 602 | 620 | return ret; |
|---|
| .. | .. |
|---|
| 613 | 631 | if (backlog) |
|---|
| 614 | 632 | backlog->complete(backlog, -EINPROGRESS); |
|---|
| 615 | 633 | |
|---|
| 616 | | - req = ablkcipher_request_cast(async_req); |
|---|
| 634 | + req = skcipher_request_cast(async_req); |
|---|
| 617 | 635 | |
|---|
| 618 | 636 | /* assign new request to device */ |
|---|
| 619 | 637 | dd->req = req; |
|---|
| 620 | | - dd->total = req->nbytes; |
|---|
| 638 | + dd->total = req->cryptlen; |
|---|
| 621 | 639 | dd->in_offset = 0; |
|---|
| 622 | 640 | dd->in_sg = req->src; |
|---|
| 623 | 641 | dd->out_offset = 0; |
|---|
| 624 | 642 | dd->out_sg = req->dst; |
|---|
| 625 | 643 | |
|---|
| 626 | | - rctx = ablkcipher_request_ctx(req); |
|---|
| 627 | | - ctx = crypto_ablkcipher_ctx(crypto_ablkcipher_reqtfm(req)); |
|---|
| 644 | + rctx = skcipher_request_ctx(req); |
|---|
| 645 | + ctx = crypto_skcipher_ctx(crypto_skcipher_reqtfm(req)); |
|---|
| 628 | 646 | rctx->mode &= TDES_FLAGS_MODE_MASK; |
|---|
| 629 | 647 | dd->flags = (dd->flags & ~TDES_FLAGS_MODE_MASK) | rctx->mode; |
|---|
| 630 | 648 | dd->ctx = ctx; |
|---|
| .. | .. |
|---|
| 668 | 686 | return err; |
|---|
| 669 | 687 | } |
|---|
| 670 | 688 | |
|---|
| 671 | | -static int atmel_tdes_crypt(struct ablkcipher_request *req, unsigned long mode) |
|---|
| 689 | +static int atmel_tdes_crypt(struct skcipher_request *req, unsigned long mode) |
|---|
| 672 | 690 | { |
|---|
| 673 | | - struct atmel_tdes_ctx *ctx = crypto_ablkcipher_ctx( |
|---|
| 674 | | - crypto_ablkcipher_reqtfm(req)); |
|---|
| 675 | | - struct atmel_tdes_reqctx *rctx = ablkcipher_request_ctx(req); |
|---|
| 691 | + struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req); |
|---|
| 692 | + struct atmel_tdes_ctx *ctx = crypto_skcipher_ctx(skcipher); |
|---|
| 693 | + struct atmel_tdes_reqctx *rctx = skcipher_request_ctx(req); |
|---|
| 676 | 694 | |
|---|
| 677 | | - if (mode & TDES_FLAGS_CFB8) { |
|---|
| 678 | | - if (!IS_ALIGNED(req->nbytes, CFB8_BLOCK_SIZE)) { |
|---|
| 695 | + switch (mode & TDES_FLAGS_OPMODE_MASK) { |
|---|
| 696 | + case TDES_FLAGS_CFB8: |
|---|
| 697 | + if (!IS_ALIGNED(req->cryptlen, CFB8_BLOCK_SIZE)) { |
|---|
| 679 | 698 | pr_err("request size is not exact amount of CFB8 blocks\n"); |
|---|
| 680 | 699 | return -EINVAL; |
|---|
| 681 | 700 | } |
|---|
| 682 | 701 | ctx->block_size = CFB8_BLOCK_SIZE; |
|---|
| 683 | | - } else if (mode & TDES_FLAGS_CFB16) { |
|---|
| 684 | | - if (!IS_ALIGNED(req->nbytes, CFB16_BLOCK_SIZE)) { |
|---|
| 702 | + break; |
|---|
| 703 | + |
|---|
| 704 | + case TDES_FLAGS_CFB16: |
|---|
| 705 | + if (!IS_ALIGNED(req->cryptlen, CFB16_BLOCK_SIZE)) { |
|---|
| 685 | 706 | pr_err("request size is not exact amount of CFB16 blocks\n"); |
|---|
| 686 | 707 | return -EINVAL; |
|---|
| 687 | 708 | } |
|---|
| 688 | 709 | ctx->block_size = CFB16_BLOCK_SIZE; |
|---|
| 689 | | - } else if (mode & TDES_FLAGS_CFB32) { |
|---|
| 690 | | - if (!IS_ALIGNED(req->nbytes, CFB32_BLOCK_SIZE)) { |
|---|
| 710 | + break; |
|---|
| 711 | + |
|---|
| 712 | + case TDES_FLAGS_CFB32: |
|---|
| 713 | + if (!IS_ALIGNED(req->cryptlen, CFB32_BLOCK_SIZE)) { |
|---|
| 691 | 714 | pr_err("request size is not exact amount of CFB32 blocks\n"); |
|---|
| 692 | 715 | return -EINVAL; |
|---|
| 693 | 716 | } |
|---|
| 694 | 717 | ctx->block_size = CFB32_BLOCK_SIZE; |
|---|
| 695 | | - } else { |
|---|
| 696 | | - if (!IS_ALIGNED(req->nbytes, DES_BLOCK_SIZE)) { |
|---|
| 718 | + break; |
|---|
| 719 | + |
|---|
| 720 | + default: |
|---|
| 721 | + if (!IS_ALIGNED(req->cryptlen, DES_BLOCK_SIZE)) { |
|---|
| 697 | 722 | pr_err("request size is not exact amount of DES blocks\n"); |
|---|
| 698 | 723 | return -EINVAL; |
|---|
| 699 | 724 | } |
|---|
| 700 | 725 | ctx->block_size = DES_BLOCK_SIZE; |
|---|
| 726 | + break; |
|---|
| 701 | 727 | } |
|---|
| 702 | 728 | |
|---|
| 703 | 729 | rctx->mode = mode; |
|---|
| 704 | 730 | |
|---|
| 731 | + if ((mode & TDES_FLAGS_OPMODE_MASK) != TDES_FLAGS_ECB && |
|---|
| 732 | + !(mode & TDES_FLAGS_ENCRYPT) && req->src == req->dst) { |
|---|
| 733 | + unsigned int ivsize = crypto_skcipher_ivsize(skcipher); |
|---|
| 734 | + |
|---|
| 735 | + if (req->cryptlen >= ivsize) |
|---|
| 736 | + scatterwalk_map_and_copy(rctx->lastc, req->src, |
|---|
| 737 | + req->cryptlen - ivsize, |
|---|
| 738 | + ivsize, 0); |
|---|
| 739 | + } |
|---|
| 740 | + |
|---|
| 705 | 741 | return atmel_tdes_handle_queue(ctx->dd, req); |
|---|
| 706 | 742 | } |
|---|
| 707 | 743 | |
|---|
| 708 | | -static bool atmel_tdes_filter(struct dma_chan *chan, void *slave) |
|---|
| 744 | +static int atmel_tdes_dma_init(struct atmel_tdes_dev *dd) |
|---|
| 709 | 745 | { |
|---|
| 710 | | - struct at_dma_slave *sl = slave; |
|---|
| 711 | | - |
|---|
| 712 | | - if (sl && sl->dma_dev == chan->device->dev) { |
|---|
| 713 | | - chan->private = sl; |
|---|
| 714 | | - return true; |
|---|
| 715 | | - } else { |
|---|
| 716 | | - return false; |
|---|
| 717 | | - } |
|---|
| 718 | | -} |
|---|
| 719 | | - |
|---|
| 720 | | -static int atmel_tdes_dma_init(struct atmel_tdes_dev *dd, |
|---|
| 721 | | - struct crypto_platform_data *pdata) |
|---|
| 722 | | -{ |
|---|
| 723 | | - dma_cap_mask_t mask; |
|---|
| 724 | | - |
|---|
| 725 | | - dma_cap_zero(mask); |
|---|
| 726 | | - dma_cap_set(DMA_SLAVE, mask); |
|---|
| 746 | + int ret; |
|---|
| 727 | 747 | |
|---|
| 728 | 748 | /* Try to grab 2 DMA channels */ |
|---|
| 729 | | - dd->dma_lch_in.chan = dma_request_slave_channel_compat(mask, |
|---|
| 730 | | - atmel_tdes_filter, &pdata->dma_slave->rxdata, dd->dev, "tx"); |
|---|
| 731 | | - if (!dd->dma_lch_in.chan) |
|---|
| 749 | + dd->dma_lch_in.chan = dma_request_chan(dd->dev, "tx"); |
|---|
| 750 | + if (IS_ERR(dd->dma_lch_in.chan)) { |
|---|
| 751 | + ret = PTR_ERR(dd->dma_lch_in.chan); |
|---|
| 732 | 752 | goto err_dma_in; |
|---|
| 753 | + } |
|---|
| 733 | 754 | |
|---|
| 734 | | - dd->dma_lch_in.dma_conf.direction = DMA_MEM_TO_DEV; |
|---|
| 735 | 755 | dd->dma_lch_in.dma_conf.dst_addr = dd->phys_base + |
|---|
| 736 | 756 | TDES_IDATA1R; |
|---|
| 737 | 757 | dd->dma_lch_in.dma_conf.src_maxburst = 1; |
|---|
| .. | .. |
|---|
| 742 | 762 | DMA_SLAVE_BUSWIDTH_4_BYTES; |
|---|
| 743 | 763 | dd->dma_lch_in.dma_conf.device_fc = false; |
|---|
| 744 | 764 | |
|---|
| 745 | | - dd->dma_lch_out.chan = dma_request_slave_channel_compat(mask, |
|---|
| 746 | | - atmel_tdes_filter, &pdata->dma_slave->txdata, dd->dev, "rx"); |
|---|
| 747 | | - if (!dd->dma_lch_out.chan) |
|---|
| 765 | + dd->dma_lch_out.chan = dma_request_chan(dd->dev, "rx"); |
|---|
| 766 | + if (IS_ERR(dd->dma_lch_out.chan)) { |
|---|
| 767 | + ret = PTR_ERR(dd->dma_lch_out.chan); |
|---|
| 748 | 768 | goto err_dma_out; |
|---|
| 769 | + } |
|---|
| 749 | 770 | |
|---|
| 750 | | - dd->dma_lch_out.dma_conf.direction = DMA_DEV_TO_MEM; |
|---|
| 751 | 771 | dd->dma_lch_out.dma_conf.src_addr = dd->phys_base + |
|---|
| 752 | 772 | TDES_ODATA1R; |
|---|
| 753 | 773 | dd->dma_lch_out.dma_conf.src_maxburst = 1; |
|---|
| .. | .. |
|---|
| 763 | 783 | err_dma_out: |
|---|
| 764 | 784 | dma_release_channel(dd->dma_lch_in.chan); |
|---|
| 765 | 785 | err_dma_in: |
|---|
| 766 | | - dev_warn(dd->dev, "no DMA channel available\n"); |
|---|
| 767 | | - return -ENODEV; |
|---|
| 786 | + dev_err(dd->dev, "no DMA channel available\n"); |
|---|
| 787 | + return ret; |
|---|
| 768 | 788 | } |
|---|
| 769 | 789 | |
|---|
| 770 | 790 | static void atmel_tdes_dma_cleanup(struct atmel_tdes_dev *dd) |
|---|
| .. | .. |
|---|
| 773 | 793 | dma_release_channel(dd->dma_lch_out.chan); |
|---|
| 774 | 794 | } |
|---|
| 775 | 795 | |
|---|
| 776 | | -static int atmel_des_setkey(struct crypto_ablkcipher *tfm, const u8 *key, |
|---|
| 796 | +static int atmel_des_setkey(struct crypto_skcipher *tfm, const u8 *key, |
|---|
| 777 | 797 | unsigned int keylen) |
|---|
| 778 | 798 | { |
|---|
| 779 | | - u32 tmp[DES_EXPKEY_WORDS]; |
|---|
| 799 | + struct atmel_tdes_ctx *ctx = crypto_skcipher_ctx(tfm); |
|---|
| 780 | 800 | int err; |
|---|
| 781 | | - struct crypto_tfm *ctfm = crypto_ablkcipher_tfm(tfm); |
|---|
| 782 | 801 | |
|---|
| 783 | | - struct atmel_tdes_ctx *ctx = crypto_ablkcipher_ctx(tfm); |
|---|
| 784 | | - |
|---|
| 785 | | - if (keylen != DES_KEY_SIZE) { |
|---|
| 786 | | - crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN); |
|---|
| 787 | | - return -EINVAL; |
|---|
| 788 | | - } |
|---|
| 789 | | - |
|---|
| 790 | | - err = des_ekey(tmp, key); |
|---|
| 791 | | - if (err == 0 && (ctfm->crt_flags & CRYPTO_TFM_REQ_WEAK_KEY)) { |
|---|
| 792 | | - ctfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY; |
|---|
| 793 | | - return -EINVAL; |
|---|
| 794 | | - } |
|---|
| 802 | + err = verify_skcipher_des_key(tfm, key); |
|---|
| 803 | + if (err) |
|---|
| 804 | + return err; |
|---|
| 795 | 805 | |
|---|
| 796 | 806 | memcpy(ctx->key, key, keylen); |
|---|
| 797 | 807 | ctx->keylen = keylen; |
|---|
| .. | .. |
|---|
| 799 | 809 | return 0; |
|---|
| 800 | 810 | } |
|---|
| 801 | 811 | |
|---|
| 802 | | -static int atmel_tdes_setkey(struct crypto_ablkcipher *tfm, const u8 *key, |
|---|
| 812 | +static int atmel_tdes_setkey(struct crypto_skcipher *tfm, const u8 *key, |
|---|
| 803 | 813 | unsigned int keylen) |
|---|
| 804 | 814 | { |
|---|
| 805 | | - struct atmel_tdes_ctx *ctx = crypto_ablkcipher_ctx(tfm); |
|---|
| 806 | | - const char *alg_name; |
|---|
| 815 | + struct atmel_tdes_ctx *ctx = crypto_skcipher_ctx(tfm); |
|---|
| 816 | + int err; |
|---|
| 807 | 817 | |
|---|
| 808 | | - alg_name = crypto_tfm_alg_name(crypto_ablkcipher_tfm(tfm)); |
|---|
| 809 | | - |
|---|
| 810 | | - /* |
|---|
| 811 | | - * HW bug in cfb 3-keys mode. |
|---|
| 812 | | - */ |
|---|
| 813 | | - if (!ctx->dd->caps.has_cfb_3keys && strstr(alg_name, "cfb") |
|---|
| 814 | | - && (keylen != 2*DES_KEY_SIZE)) { |
|---|
| 815 | | - crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN); |
|---|
| 816 | | - return -EINVAL; |
|---|
| 817 | | - } else if ((keylen != 2*DES_KEY_SIZE) && (keylen != 3*DES_KEY_SIZE)) { |
|---|
| 818 | | - crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN); |
|---|
| 819 | | - return -EINVAL; |
|---|
| 820 | | - } |
|---|
| 818 | + err = verify_skcipher_des3_key(tfm, key); |
|---|
| 819 | + if (err) |
|---|
| 820 | + return err; |
|---|
| 821 | 821 | |
|---|
| 822 | 822 | memcpy(ctx->key, key, keylen); |
|---|
| 823 | 823 | ctx->keylen = keylen; |
|---|
| .. | .. |
|---|
| 825 | 825 | return 0; |
|---|
| 826 | 826 | } |
|---|
| 827 | 827 | |
|---|
| 828 | | -static int atmel_tdes_ecb_encrypt(struct ablkcipher_request *req) |
|---|
| 828 | +static int atmel_tdes_ecb_encrypt(struct skcipher_request *req) |
|---|
| 829 | 829 | { |
|---|
| 830 | | - return atmel_tdes_crypt(req, TDES_FLAGS_ENCRYPT); |
|---|
| 830 | + return atmel_tdes_crypt(req, TDES_FLAGS_ECB | TDES_FLAGS_ENCRYPT); |
|---|
| 831 | 831 | } |
|---|
| 832 | 832 | |
|---|
| 833 | | -static int atmel_tdes_ecb_decrypt(struct ablkcipher_request *req) |
|---|
| 833 | +static int atmel_tdes_ecb_decrypt(struct skcipher_request *req) |
|---|
| 834 | 834 | { |
|---|
| 835 | | - return atmel_tdes_crypt(req, 0); |
|---|
| 835 | + return atmel_tdes_crypt(req, TDES_FLAGS_ECB); |
|---|
| 836 | 836 | } |
|---|
| 837 | 837 | |
|---|
| 838 | | -static int atmel_tdes_cbc_encrypt(struct ablkcipher_request *req) |
|---|
| 838 | +static int atmel_tdes_cbc_encrypt(struct skcipher_request *req) |
|---|
| 839 | 839 | { |
|---|
| 840 | | - return atmel_tdes_crypt(req, TDES_FLAGS_ENCRYPT | TDES_FLAGS_CBC); |
|---|
| 840 | + return atmel_tdes_crypt(req, TDES_FLAGS_CBC | TDES_FLAGS_ENCRYPT); |
|---|
| 841 | 841 | } |
|---|
| 842 | 842 | |
|---|
| 843 | | -static int atmel_tdes_cbc_decrypt(struct ablkcipher_request *req) |
|---|
| 843 | +static int atmel_tdes_cbc_decrypt(struct skcipher_request *req) |
|---|
| 844 | 844 | { |
|---|
| 845 | 845 | return atmel_tdes_crypt(req, TDES_FLAGS_CBC); |
|---|
| 846 | 846 | } |
|---|
| 847 | | -static int atmel_tdes_cfb_encrypt(struct ablkcipher_request *req) |
|---|
| 847 | +static int atmel_tdes_cfb_encrypt(struct skcipher_request *req) |
|---|
| 848 | 848 | { |
|---|
| 849 | | - return atmel_tdes_crypt(req, TDES_FLAGS_ENCRYPT | TDES_FLAGS_CFB); |
|---|
| 849 | + return atmel_tdes_crypt(req, TDES_FLAGS_CFB64 | TDES_FLAGS_ENCRYPT); |
|---|
| 850 | 850 | } |
|---|
| 851 | 851 | |
|---|
| 852 | | -static int atmel_tdes_cfb_decrypt(struct ablkcipher_request *req) |
|---|
| 852 | +static int atmel_tdes_cfb_decrypt(struct skcipher_request *req) |
|---|
| 853 | 853 | { |
|---|
| 854 | | - return atmel_tdes_crypt(req, TDES_FLAGS_CFB); |
|---|
| 854 | + return atmel_tdes_crypt(req, TDES_FLAGS_CFB64); |
|---|
| 855 | 855 | } |
|---|
| 856 | 856 | |
|---|
| 857 | | -static int atmel_tdes_cfb8_encrypt(struct ablkcipher_request *req) |
|---|
| 857 | +static int atmel_tdes_cfb8_encrypt(struct skcipher_request *req) |
|---|
| 858 | 858 | { |
|---|
| 859 | | - return atmel_tdes_crypt(req, TDES_FLAGS_ENCRYPT | TDES_FLAGS_CFB | |
|---|
| 860 | | - TDES_FLAGS_CFB8); |
|---|
| 859 | + return atmel_tdes_crypt(req, TDES_FLAGS_CFB8 | TDES_FLAGS_ENCRYPT); |
|---|
| 861 | 860 | } |
|---|
| 862 | 861 | |
|---|
| 863 | | -static int atmel_tdes_cfb8_decrypt(struct ablkcipher_request *req) |
|---|
| 862 | +static int atmel_tdes_cfb8_decrypt(struct skcipher_request *req) |
|---|
| 864 | 863 | { |
|---|
| 865 | | - return atmel_tdes_crypt(req, TDES_FLAGS_CFB | TDES_FLAGS_CFB8); |
|---|
| 864 | + return atmel_tdes_crypt(req, TDES_FLAGS_CFB8); |
|---|
| 866 | 865 | } |
|---|
| 867 | 866 | |
|---|
| 868 | | -static int atmel_tdes_cfb16_encrypt(struct ablkcipher_request *req) |
|---|
| 867 | +static int atmel_tdes_cfb16_encrypt(struct skcipher_request *req) |
|---|
| 869 | 868 | { |
|---|
| 870 | | - return atmel_tdes_crypt(req, TDES_FLAGS_ENCRYPT | TDES_FLAGS_CFB | |
|---|
| 871 | | - TDES_FLAGS_CFB16); |
|---|
| 869 | + return atmel_tdes_crypt(req, TDES_FLAGS_CFB16 | TDES_FLAGS_ENCRYPT); |
|---|
| 872 | 870 | } |
|---|
| 873 | 871 | |
|---|
| 874 | | -static int atmel_tdes_cfb16_decrypt(struct ablkcipher_request *req) |
|---|
| 872 | +static int atmel_tdes_cfb16_decrypt(struct skcipher_request *req) |
|---|
| 875 | 873 | { |
|---|
| 876 | | - return atmel_tdes_crypt(req, TDES_FLAGS_CFB | TDES_FLAGS_CFB16); |
|---|
| 874 | + return atmel_tdes_crypt(req, TDES_FLAGS_CFB16); |
|---|
| 877 | 875 | } |
|---|
| 878 | 876 | |
|---|
| 879 | | -static int atmel_tdes_cfb32_encrypt(struct ablkcipher_request *req) |
|---|
| 877 | +static int atmel_tdes_cfb32_encrypt(struct skcipher_request *req) |
|---|
| 880 | 878 | { |
|---|
| 881 | | - return atmel_tdes_crypt(req, TDES_FLAGS_ENCRYPT | TDES_FLAGS_CFB | |
|---|
| 882 | | - TDES_FLAGS_CFB32); |
|---|
| 879 | + return atmel_tdes_crypt(req, TDES_FLAGS_CFB32 | TDES_FLAGS_ENCRYPT); |
|---|
| 883 | 880 | } |
|---|
| 884 | 881 | |
|---|
| 885 | | -static int atmel_tdes_cfb32_decrypt(struct ablkcipher_request *req) |
|---|
| 882 | +static int atmel_tdes_cfb32_decrypt(struct skcipher_request *req) |
|---|
| 886 | 883 | { |
|---|
| 887 | | - return atmel_tdes_crypt(req, TDES_FLAGS_CFB | TDES_FLAGS_CFB32); |
|---|
| 884 | + return atmel_tdes_crypt(req, TDES_FLAGS_CFB32); |
|---|
| 888 | 885 | } |
|---|
| 889 | 886 | |
|---|
| 890 | | -static int atmel_tdes_ofb_encrypt(struct ablkcipher_request *req) |
|---|
| 887 | +static int atmel_tdes_ofb_encrypt(struct skcipher_request *req) |
|---|
| 891 | 888 | { |
|---|
| 892 | | - return atmel_tdes_crypt(req, TDES_FLAGS_ENCRYPT | TDES_FLAGS_OFB); |
|---|
| 889 | + return atmel_tdes_crypt(req, TDES_FLAGS_OFB | TDES_FLAGS_ENCRYPT); |
|---|
| 893 | 890 | } |
|---|
| 894 | 891 | |
|---|
| 895 | | -static int atmel_tdes_ofb_decrypt(struct ablkcipher_request *req) |
|---|
| 892 | +static int atmel_tdes_ofb_decrypt(struct skcipher_request *req) |
|---|
| 896 | 893 | { |
|---|
| 897 | 894 | return atmel_tdes_crypt(req, TDES_FLAGS_OFB); |
|---|
| 898 | 895 | } |
|---|
| 899 | 896 | |
|---|
| 900 | | -static int atmel_tdes_cra_init(struct crypto_tfm *tfm) |
|---|
| 897 | +static int atmel_tdes_init_tfm(struct crypto_skcipher *tfm) |
|---|
| 901 | 898 | { |
|---|
| 902 | | - struct atmel_tdes_ctx *ctx = crypto_tfm_ctx(tfm); |
|---|
| 899 | + struct atmel_tdes_ctx *ctx = crypto_skcipher_ctx(tfm); |
|---|
| 903 | 900 | struct atmel_tdes_dev *dd; |
|---|
| 904 | 901 | |
|---|
| 905 | | - tfm->crt_ablkcipher.reqsize = sizeof(struct atmel_tdes_reqctx); |
|---|
| 902 | + crypto_skcipher_set_reqsize(tfm, sizeof(struct atmel_tdes_reqctx)); |
|---|
| 906 | 903 | |
|---|
| 907 | 904 | dd = atmel_tdes_find_dev(ctx); |
|---|
| 908 | 905 | if (!dd) |
|---|
| .. | .. |
|---|
| 911 | 908 | return 0; |
|---|
| 912 | 909 | } |
|---|
| 913 | 910 | |
|---|
| 914 | | -static struct crypto_alg tdes_algs[] = { |
|---|
| 911 | +static void atmel_tdes_skcipher_alg_init(struct skcipher_alg *alg) |
|---|
| 915 | 912 | { |
|---|
| 916 | | - .cra_name = "ecb(des)", |
|---|
| 917 | | - .cra_driver_name = "atmel-ecb-des", |
|---|
| 918 | | - .cra_priority = 100, |
|---|
| 919 | | - .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, |
|---|
| 920 | | - .cra_blocksize = DES_BLOCK_SIZE, |
|---|
| 921 | | - .cra_ctxsize = sizeof(struct atmel_tdes_ctx), |
|---|
| 922 | | - .cra_alignmask = 0x7, |
|---|
| 923 | | - .cra_type = &crypto_ablkcipher_type, |
|---|
| 924 | | - .cra_module = THIS_MODULE, |
|---|
| 925 | | - .cra_init = atmel_tdes_cra_init, |
|---|
| 926 | | - .cra_u.ablkcipher = { |
|---|
| 927 | | - .min_keysize = DES_KEY_SIZE, |
|---|
| 928 | | - .max_keysize = DES_KEY_SIZE, |
|---|
| 929 | | - .setkey = atmel_des_setkey, |
|---|
| 930 | | - .encrypt = atmel_tdes_ecb_encrypt, |
|---|
| 931 | | - .decrypt = atmel_tdes_ecb_decrypt, |
|---|
| 932 | | - } |
|---|
| 913 | + alg->base.cra_priority = ATMEL_TDES_PRIORITY; |
|---|
| 914 | + alg->base.cra_flags = CRYPTO_ALG_ASYNC; |
|---|
| 915 | + alg->base.cra_ctxsize = sizeof(struct atmel_tdes_ctx); |
|---|
| 916 | + alg->base.cra_module = THIS_MODULE; |
|---|
| 917 | + |
|---|
| 918 | + alg->init = atmel_tdes_init_tfm; |
|---|
| 919 | +} |
|---|
| 920 | + |
|---|
| 921 | +static struct skcipher_alg tdes_algs[] = { |
|---|
| 922 | +{ |
|---|
| 923 | + .base.cra_name = "ecb(des)", |
|---|
| 924 | + .base.cra_driver_name = "atmel-ecb-des", |
|---|
| 925 | + .base.cra_blocksize = DES_BLOCK_SIZE, |
|---|
| 926 | + .base.cra_alignmask = 0x7, |
|---|
| 927 | + |
|---|
| 928 | + .min_keysize = DES_KEY_SIZE, |
|---|
| 929 | + .max_keysize = DES_KEY_SIZE, |
|---|
| 930 | + .setkey = atmel_des_setkey, |
|---|
| 931 | + .encrypt = atmel_tdes_ecb_encrypt, |
|---|
| 932 | + .decrypt = atmel_tdes_ecb_decrypt, |
|---|
| 933 | 933 | }, |
|---|
| 934 | 934 | { |
|---|
| 935 | | - .cra_name = "cbc(des)", |
|---|
| 936 | | - .cra_driver_name = "atmel-cbc-des", |
|---|
| 937 | | - .cra_priority = 100, |
|---|
| 938 | | - .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, |
|---|
| 939 | | - .cra_blocksize = DES_BLOCK_SIZE, |
|---|
| 940 | | - .cra_ctxsize = sizeof(struct atmel_tdes_ctx), |
|---|
| 941 | | - .cra_alignmask = 0x7, |
|---|
| 942 | | - .cra_type = &crypto_ablkcipher_type, |
|---|
| 943 | | - .cra_module = THIS_MODULE, |
|---|
| 944 | | - .cra_init = atmel_tdes_cra_init, |
|---|
| 945 | | - .cra_u.ablkcipher = { |
|---|
| 946 | | - .min_keysize = DES_KEY_SIZE, |
|---|
| 947 | | - .max_keysize = DES_KEY_SIZE, |
|---|
| 948 | | - .ivsize = DES_BLOCK_SIZE, |
|---|
| 949 | | - .setkey = atmel_des_setkey, |
|---|
| 950 | | - .encrypt = atmel_tdes_cbc_encrypt, |
|---|
| 951 | | - .decrypt = atmel_tdes_cbc_decrypt, |
|---|
| 952 | | - } |
|---|
| 935 | + .base.cra_name = "cbc(des)", |
|---|
| 936 | + .base.cra_driver_name = "atmel-cbc-des", |
|---|
| 937 | + .base.cra_blocksize = DES_BLOCK_SIZE, |
|---|
| 938 | + .base.cra_alignmask = 0x7, |
|---|
| 939 | + |
|---|
| 940 | + .min_keysize = DES_KEY_SIZE, |
|---|
| 941 | + .max_keysize = DES_KEY_SIZE, |
|---|
| 942 | + .ivsize = DES_BLOCK_SIZE, |
|---|
| 943 | + .setkey = atmel_des_setkey, |
|---|
| 944 | + .encrypt = atmel_tdes_cbc_encrypt, |
|---|
| 945 | + .decrypt = atmel_tdes_cbc_decrypt, |
|---|
| 953 | 946 | }, |
|---|
| 954 | 947 | { |
|---|
| 955 | | - .cra_name = "cfb(des)", |
|---|
| 956 | | - .cra_driver_name = "atmel-cfb-des", |
|---|
| 957 | | - .cra_priority = 100, |
|---|
| 958 | | - .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, |
|---|
| 959 | | - .cra_blocksize = DES_BLOCK_SIZE, |
|---|
| 960 | | - .cra_ctxsize = sizeof(struct atmel_tdes_ctx), |
|---|
| 961 | | - .cra_alignmask = 0x7, |
|---|
| 962 | | - .cra_type = &crypto_ablkcipher_type, |
|---|
| 963 | | - .cra_module = THIS_MODULE, |
|---|
| 964 | | - .cra_init = atmel_tdes_cra_init, |
|---|
| 965 | | - .cra_u.ablkcipher = { |
|---|
| 966 | | - .min_keysize = DES_KEY_SIZE, |
|---|
| 967 | | - .max_keysize = DES_KEY_SIZE, |
|---|
| 968 | | - .ivsize = DES_BLOCK_SIZE, |
|---|
| 969 | | - .setkey = atmel_des_setkey, |
|---|
| 970 | | - .encrypt = atmel_tdes_cfb_encrypt, |
|---|
| 971 | | - .decrypt = atmel_tdes_cfb_decrypt, |
|---|
| 972 | | - } |
|---|
| 948 | + .base.cra_name = "cfb(des)", |
|---|
| 949 | + .base.cra_driver_name = "atmel-cfb-des", |
|---|
| 950 | + .base.cra_blocksize = DES_BLOCK_SIZE, |
|---|
| 951 | + .base.cra_alignmask = 0x7, |
|---|
| 952 | + |
|---|
| 953 | + .min_keysize = DES_KEY_SIZE, |
|---|
| 954 | + .max_keysize = DES_KEY_SIZE, |
|---|
| 955 | + .ivsize = DES_BLOCK_SIZE, |
|---|
| 956 | + .setkey = atmel_des_setkey, |
|---|
| 957 | + .encrypt = atmel_tdes_cfb_encrypt, |
|---|
| 958 | + .decrypt = atmel_tdes_cfb_decrypt, |
|---|
| 973 | 959 | }, |
|---|
| 974 | 960 | { |
|---|
| 975 | | - .cra_name = "cfb8(des)", |
|---|
| 976 | | - .cra_driver_name = "atmel-cfb8-des", |
|---|
| 977 | | - .cra_priority = 100, |
|---|
| 978 | | - .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, |
|---|
| 979 | | - .cra_blocksize = CFB8_BLOCK_SIZE, |
|---|
| 980 | | - .cra_ctxsize = sizeof(struct atmel_tdes_ctx), |
|---|
| 981 | | - .cra_alignmask = 0, |
|---|
| 982 | | - .cra_type = &crypto_ablkcipher_type, |
|---|
| 983 | | - .cra_module = THIS_MODULE, |
|---|
| 984 | | - .cra_init = atmel_tdes_cra_init, |
|---|
| 985 | | - .cra_u.ablkcipher = { |
|---|
| 986 | | - .min_keysize = DES_KEY_SIZE, |
|---|
| 987 | | - .max_keysize = DES_KEY_SIZE, |
|---|
| 988 | | - .ivsize = DES_BLOCK_SIZE, |
|---|
| 989 | | - .setkey = atmel_des_setkey, |
|---|
| 990 | | - .encrypt = atmel_tdes_cfb8_encrypt, |
|---|
| 991 | | - .decrypt = atmel_tdes_cfb8_decrypt, |
|---|
| 992 | | - } |
|---|
| 961 | + .base.cra_name = "cfb8(des)", |
|---|
| 962 | + .base.cra_driver_name = "atmel-cfb8-des", |
|---|
| 963 | + .base.cra_blocksize = CFB8_BLOCK_SIZE, |
|---|
| 964 | + .base.cra_alignmask = 0, |
|---|
| 965 | + |
|---|
| 966 | + .min_keysize = DES_KEY_SIZE, |
|---|
| 967 | + .max_keysize = DES_KEY_SIZE, |
|---|
| 968 | + .ivsize = DES_BLOCK_SIZE, |
|---|
| 969 | + .setkey = atmel_des_setkey, |
|---|
| 970 | + .encrypt = atmel_tdes_cfb8_encrypt, |
|---|
| 971 | + .decrypt = atmel_tdes_cfb8_decrypt, |
|---|
| 993 | 972 | }, |
|---|
| 994 | 973 | { |
|---|
| 995 | | - .cra_name = "cfb16(des)", |
|---|
| 996 | | - .cra_driver_name = "atmel-cfb16-des", |
|---|
| 997 | | - .cra_priority = 100, |
|---|
| 998 | | - .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, |
|---|
| 999 | | - .cra_blocksize = CFB16_BLOCK_SIZE, |
|---|
| 1000 | | - .cra_ctxsize = sizeof(struct atmel_tdes_ctx), |
|---|
| 1001 | | - .cra_alignmask = 0x1, |
|---|
| 1002 | | - .cra_type = &crypto_ablkcipher_type, |
|---|
| 1003 | | - .cra_module = THIS_MODULE, |
|---|
| 1004 | | - .cra_init = atmel_tdes_cra_init, |
|---|
| 1005 | | - .cra_u.ablkcipher = { |
|---|
| 1006 | | - .min_keysize = DES_KEY_SIZE, |
|---|
| 1007 | | - .max_keysize = DES_KEY_SIZE, |
|---|
| 1008 | | - .ivsize = DES_BLOCK_SIZE, |
|---|
| 1009 | | - .setkey = atmel_des_setkey, |
|---|
| 1010 | | - .encrypt = atmel_tdes_cfb16_encrypt, |
|---|
| 1011 | | - .decrypt = atmel_tdes_cfb16_decrypt, |
|---|
| 1012 | | - } |
|---|
| 974 | + .base.cra_name = "cfb16(des)", |
|---|
| 975 | + .base.cra_driver_name = "atmel-cfb16-des", |
|---|
| 976 | + .base.cra_blocksize = CFB16_BLOCK_SIZE, |
|---|
| 977 | + .base.cra_alignmask = 0x1, |
|---|
| 978 | + |
|---|
| 979 | + .min_keysize = DES_KEY_SIZE, |
|---|
| 980 | + .max_keysize = DES_KEY_SIZE, |
|---|
| 981 | + .ivsize = DES_BLOCK_SIZE, |
|---|
| 982 | + .setkey = atmel_des_setkey, |
|---|
| 983 | + .encrypt = atmel_tdes_cfb16_encrypt, |
|---|
| 984 | + .decrypt = atmel_tdes_cfb16_decrypt, |
|---|
| 1013 | 985 | }, |
|---|
| 1014 | 986 | { |
|---|
| 1015 | | - .cra_name = "cfb32(des)", |
|---|
| 1016 | | - .cra_driver_name = "atmel-cfb32-des", |
|---|
| 1017 | | - .cra_priority = 100, |
|---|
| 1018 | | - .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, |
|---|
| 1019 | | - .cra_blocksize = CFB32_BLOCK_SIZE, |
|---|
| 1020 | | - .cra_ctxsize = sizeof(struct atmel_tdes_ctx), |
|---|
| 1021 | | - .cra_alignmask = 0x3, |
|---|
| 1022 | | - .cra_type = &crypto_ablkcipher_type, |
|---|
| 1023 | | - .cra_module = THIS_MODULE, |
|---|
| 1024 | | - .cra_init = atmel_tdes_cra_init, |
|---|
| 1025 | | - .cra_u.ablkcipher = { |
|---|
| 1026 | | - .min_keysize = DES_KEY_SIZE, |
|---|
| 1027 | | - .max_keysize = DES_KEY_SIZE, |
|---|
| 1028 | | - .ivsize = DES_BLOCK_SIZE, |
|---|
| 1029 | | - .setkey = atmel_des_setkey, |
|---|
| 1030 | | - .encrypt = atmel_tdes_cfb32_encrypt, |
|---|
| 1031 | | - .decrypt = atmel_tdes_cfb32_decrypt, |
|---|
| 1032 | | - } |
|---|
| 987 | + .base.cra_name = "cfb32(des)", |
|---|
| 988 | + .base.cra_driver_name = "atmel-cfb32-des", |
|---|
| 989 | + .base.cra_blocksize = CFB32_BLOCK_SIZE, |
|---|
| 990 | + .base.cra_alignmask = 0x3, |
|---|
| 991 | + |
|---|
| 992 | + .min_keysize = DES_KEY_SIZE, |
|---|
| 993 | + .max_keysize = DES_KEY_SIZE, |
|---|
| 994 | + .ivsize = DES_BLOCK_SIZE, |
|---|
| 995 | + .setkey = atmel_des_setkey, |
|---|
| 996 | + .encrypt = atmel_tdes_cfb32_encrypt, |
|---|
| 997 | + .decrypt = atmel_tdes_cfb32_decrypt, |
|---|
| 1033 | 998 | }, |
|---|
| 1034 | 999 | { |
|---|
| 1035 | | - .cra_name = "ofb(des)", |
|---|
| 1036 | | - .cra_driver_name = "atmel-ofb-des", |
|---|
| 1037 | | - .cra_priority = 100, |
|---|
| 1038 | | - .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, |
|---|
| 1039 | | - .cra_blocksize = DES_BLOCK_SIZE, |
|---|
| 1040 | | - .cra_ctxsize = sizeof(struct atmel_tdes_ctx), |
|---|
| 1041 | | - .cra_alignmask = 0x7, |
|---|
| 1042 | | - .cra_type = &crypto_ablkcipher_type, |
|---|
| 1043 | | - .cra_module = THIS_MODULE, |
|---|
| 1044 | | - .cra_init = atmel_tdes_cra_init, |
|---|
| 1045 | | - .cra_u.ablkcipher = { |
|---|
| 1046 | | - .min_keysize = DES_KEY_SIZE, |
|---|
| 1047 | | - .max_keysize = DES_KEY_SIZE, |
|---|
| 1048 | | - .ivsize = DES_BLOCK_SIZE, |
|---|
| 1049 | | - .setkey = atmel_des_setkey, |
|---|
| 1050 | | - .encrypt = atmel_tdes_ofb_encrypt, |
|---|
| 1051 | | - .decrypt = atmel_tdes_ofb_decrypt, |
|---|
| 1052 | | - } |
|---|
| 1000 | + .base.cra_name = "ofb(des)", |
|---|
| 1001 | + .base.cra_driver_name = "atmel-ofb-des", |
|---|
| 1002 | + .base.cra_blocksize = DES_BLOCK_SIZE, |
|---|
| 1003 | + .base.cra_alignmask = 0x7, |
|---|
| 1004 | + |
|---|
| 1005 | + .min_keysize = DES_KEY_SIZE, |
|---|
| 1006 | + .max_keysize = DES_KEY_SIZE, |
|---|
| 1007 | + .ivsize = DES_BLOCK_SIZE, |
|---|
| 1008 | + .setkey = atmel_des_setkey, |
|---|
| 1009 | + .encrypt = atmel_tdes_ofb_encrypt, |
|---|
| 1010 | + .decrypt = atmel_tdes_ofb_decrypt, |
|---|
| 1053 | 1011 | }, |
|---|
| 1054 | 1012 | { |
|---|
| 1055 | | - .cra_name = "ecb(des3_ede)", |
|---|
| 1056 | | - .cra_driver_name = "atmel-ecb-tdes", |
|---|
| 1057 | | - .cra_priority = 100, |
|---|
| 1058 | | - .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, |
|---|
| 1059 | | - .cra_blocksize = DES_BLOCK_SIZE, |
|---|
| 1060 | | - .cra_ctxsize = sizeof(struct atmel_tdes_ctx), |
|---|
| 1061 | | - .cra_alignmask = 0x7, |
|---|
| 1062 | | - .cra_type = &crypto_ablkcipher_type, |
|---|
| 1063 | | - .cra_module = THIS_MODULE, |
|---|
| 1064 | | - .cra_init = atmel_tdes_cra_init, |
|---|
| 1065 | | - .cra_u.ablkcipher = { |
|---|
| 1066 | | - .min_keysize = 2 * DES_KEY_SIZE, |
|---|
| 1067 | | - .max_keysize = 3 * DES_KEY_SIZE, |
|---|
| 1068 | | - .setkey = atmel_tdes_setkey, |
|---|
| 1069 | | - .encrypt = atmel_tdes_ecb_encrypt, |
|---|
| 1070 | | - .decrypt = atmel_tdes_ecb_decrypt, |
|---|
| 1071 | | - } |
|---|
| 1013 | + .base.cra_name = "ecb(des3_ede)", |
|---|
| 1014 | + .base.cra_driver_name = "atmel-ecb-tdes", |
|---|
| 1015 | + .base.cra_blocksize = DES_BLOCK_SIZE, |
|---|
| 1016 | + .base.cra_alignmask = 0x7, |
|---|
| 1017 | + |
|---|
| 1018 | + .min_keysize = DES3_EDE_KEY_SIZE, |
|---|
| 1019 | + .max_keysize = DES3_EDE_KEY_SIZE, |
|---|
| 1020 | + .setkey = atmel_tdes_setkey, |
|---|
| 1021 | + .encrypt = atmel_tdes_ecb_encrypt, |
|---|
| 1022 | + .decrypt = atmel_tdes_ecb_decrypt, |
|---|
| 1072 | 1023 | }, |
|---|
| 1073 | 1024 | { |
|---|
| 1074 | | - .cra_name = "cbc(des3_ede)", |
|---|
| 1075 | | - .cra_driver_name = "atmel-cbc-tdes", |
|---|
| 1076 | | - .cra_priority = 100, |
|---|
| 1077 | | - .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, |
|---|
| 1078 | | - .cra_blocksize = DES_BLOCK_SIZE, |
|---|
| 1079 | | - .cra_ctxsize = sizeof(struct atmel_tdes_ctx), |
|---|
| 1080 | | - .cra_alignmask = 0x7, |
|---|
| 1081 | | - .cra_type = &crypto_ablkcipher_type, |
|---|
| 1082 | | - .cra_module = THIS_MODULE, |
|---|
| 1083 | | - .cra_init = atmel_tdes_cra_init, |
|---|
| 1084 | | - .cra_u.ablkcipher = { |
|---|
| 1085 | | - .min_keysize = 2*DES_KEY_SIZE, |
|---|
| 1086 | | - .max_keysize = 3*DES_KEY_SIZE, |
|---|
| 1087 | | - .ivsize = DES_BLOCK_SIZE, |
|---|
| 1088 | | - .setkey = atmel_tdes_setkey, |
|---|
| 1089 | | - .encrypt = atmel_tdes_cbc_encrypt, |
|---|
| 1090 | | - .decrypt = atmel_tdes_cbc_decrypt, |
|---|
| 1091 | | - } |
|---|
| 1025 | + .base.cra_name = "cbc(des3_ede)", |
|---|
| 1026 | + .base.cra_driver_name = "atmel-cbc-tdes", |
|---|
| 1027 | + .base.cra_blocksize = DES_BLOCK_SIZE, |
|---|
| 1028 | + .base.cra_alignmask = 0x7, |
|---|
| 1029 | + |
|---|
| 1030 | + .min_keysize = DES3_EDE_KEY_SIZE, |
|---|
| 1031 | + .max_keysize = DES3_EDE_KEY_SIZE, |
|---|
| 1032 | + .setkey = atmel_tdes_setkey, |
|---|
| 1033 | + .encrypt = atmel_tdes_cbc_encrypt, |
|---|
| 1034 | + .decrypt = atmel_tdes_cbc_decrypt, |
|---|
| 1035 | + .ivsize = DES_BLOCK_SIZE, |
|---|
| 1092 | 1036 | }, |
|---|
| 1093 | 1037 | { |
|---|
| 1094 | | - .cra_name = "cfb(des3_ede)", |
|---|
| 1095 | | - .cra_driver_name = "atmel-cfb-tdes", |
|---|
| 1096 | | - .cra_priority = 100, |
|---|
| 1097 | | - .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, |
|---|
| 1098 | | - .cra_blocksize = DES_BLOCK_SIZE, |
|---|
| 1099 | | - .cra_ctxsize = sizeof(struct atmel_tdes_ctx), |
|---|
| 1100 | | - .cra_alignmask = 0x7, |
|---|
| 1101 | | - .cra_type = &crypto_ablkcipher_type, |
|---|
| 1102 | | - .cra_module = THIS_MODULE, |
|---|
| 1103 | | - .cra_init = atmel_tdes_cra_init, |
|---|
| 1104 | | - .cra_u.ablkcipher = { |
|---|
| 1105 | | - .min_keysize = 2*DES_KEY_SIZE, |
|---|
| 1106 | | - .max_keysize = 2*DES_KEY_SIZE, |
|---|
| 1107 | | - .ivsize = DES_BLOCK_SIZE, |
|---|
| 1108 | | - .setkey = atmel_tdes_setkey, |
|---|
| 1109 | | - .encrypt = atmel_tdes_cfb_encrypt, |
|---|
| 1110 | | - .decrypt = atmel_tdes_cfb_decrypt, |
|---|
| 1111 | | - } |
|---|
| 1112 | | -}, |
|---|
| 1113 | | -{ |
|---|
| 1114 | | - .cra_name = "cfb8(des3_ede)", |
|---|
| 1115 | | - .cra_driver_name = "atmel-cfb8-tdes", |
|---|
| 1116 | | - .cra_priority = 100, |
|---|
| 1117 | | - .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, |
|---|
| 1118 | | - .cra_blocksize = CFB8_BLOCK_SIZE, |
|---|
| 1119 | | - .cra_ctxsize = sizeof(struct atmel_tdes_ctx), |
|---|
| 1120 | | - .cra_alignmask = 0, |
|---|
| 1121 | | - .cra_type = &crypto_ablkcipher_type, |
|---|
| 1122 | | - .cra_module = THIS_MODULE, |
|---|
| 1123 | | - .cra_init = atmel_tdes_cra_init, |
|---|
| 1124 | | - .cra_u.ablkcipher = { |
|---|
| 1125 | | - .min_keysize = 2*DES_KEY_SIZE, |
|---|
| 1126 | | - .max_keysize = 2*DES_KEY_SIZE, |
|---|
| 1127 | | - .ivsize = DES_BLOCK_SIZE, |
|---|
| 1128 | | - .setkey = atmel_tdes_setkey, |
|---|
| 1129 | | - .encrypt = atmel_tdes_cfb8_encrypt, |
|---|
| 1130 | | - .decrypt = atmel_tdes_cfb8_decrypt, |
|---|
| 1131 | | - } |
|---|
| 1132 | | -}, |
|---|
| 1133 | | -{ |
|---|
| 1134 | | - .cra_name = "cfb16(des3_ede)", |
|---|
| 1135 | | - .cra_driver_name = "atmel-cfb16-tdes", |
|---|
| 1136 | | - .cra_priority = 100, |
|---|
| 1137 | | - .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, |
|---|
| 1138 | | - .cra_blocksize = CFB16_BLOCK_SIZE, |
|---|
| 1139 | | - .cra_ctxsize = sizeof(struct atmel_tdes_ctx), |
|---|
| 1140 | | - .cra_alignmask = 0x1, |
|---|
| 1141 | | - .cra_type = &crypto_ablkcipher_type, |
|---|
| 1142 | | - .cra_module = THIS_MODULE, |
|---|
| 1143 | | - .cra_init = atmel_tdes_cra_init, |
|---|
| 1144 | | - .cra_u.ablkcipher = { |
|---|
| 1145 | | - .min_keysize = 2*DES_KEY_SIZE, |
|---|
| 1146 | | - .max_keysize = 2*DES_KEY_SIZE, |
|---|
| 1147 | | - .ivsize = DES_BLOCK_SIZE, |
|---|
| 1148 | | - .setkey = atmel_tdes_setkey, |
|---|
| 1149 | | - .encrypt = atmel_tdes_cfb16_encrypt, |
|---|
| 1150 | | - .decrypt = atmel_tdes_cfb16_decrypt, |
|---|
| 1151 | | - } |
|---|
| 1152 | | -}, |
|---|
| 1153 | | -{ |
|---|
| 1154 | | - .cra_name = "cfb32(des3_ede)", |
|---|
| 1155 | | - .cra_driver_name = "atmel-cfb32-tdes", |
|---|
| 1156 | | - .cra_priority = 100, |
|---|
| 1157 | | - .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, |
|---|
| 1158 | | - .cra_blocksize = CFB32_BLOCK_SIZE, |
|---|
| 1159 | | - .cra_ctxsize = sizeof(struct atmel_tdes_ctx), |
|---|
| 1160 | | - .cra_alignmask = 0x3, |
|---|
| 1161 | | - .cra_type = &crypto_ablkcipher_type, |
|---|
| 1162 | | - .cra_module = THIS_MODULE, |
|---|
| 1163 | | - .cra_init = atmel_tdes_cra_init, |
|---|
| 1164 | | - .cra_u.ablkcipher = { |
|---|
| 1165 | | - .min_keysize = 2*DES_KEY_SIZE, |
|---|
| 1166 | | - .max_keysize = 2*DES_KEY_SIZE, |
|---|
| 1167 | | - .ivsize = DES_BLOCK_SIZE, |
|---|
| 1168 | | - .setkey = atmel_tdes_setkey, |
|---|
| 1169 | | - .encrypt = atmel_tdes_cfb32_encrypt, |
|---|
| 1170 | | - .decrypt = atmel_tdes_cfb32_decrypt, |
|---|
| 1171 | | - } |
|---|
| 1172 | | -}, |
|---|
| 1173 | | -{ |
|---|
| 1174 | | - .cra_name = "ofb(des3_ede)", |
|---|
| 1175 | | - .cra_driver_name = "atmel-ofb-tdes", |
|---|
| 1176 | | - .cra_priority = 100, |
|---|
| 1177 | | - .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, |
|---|
| 1178 | | - .cra_blocksize = DES_BLOCK_SIZE, |
|---|
| 1179 | | - .cra_ctxsize = sizeof(struct atmel_tdes_ctx), |
|---|
| 1180 | | - .cra_alignmask = 0x7, |
|---|
| 1181 | | - .cra_type = &crypto_ablkcipher_type, |
|---|
| 1182 | | - .cra_module = THIS_MODULE, |
|---|
| 1183 | | - .cra_init = atmel_tdes_cra_init, |
|---|
| 1184 | | - .cra_u.ablkcipher = { |
|---|
| 1185 | | - .min_keysize = 2*DES_KEY_SIZE, |
|---|
| 1186 | | - .max_keysize = 3*DES_KEY_SIZE, |
|---|
| 1187 | | - .ivsize = DES_BLOCK_SIZE, |
|---|
| 1188 | | - .setkey = atmel_tdes_setkey, |
|---|
| 1189 | | - .encrypt = atmel_tdes_ofb_encrypt, |
|---|
| 1190 | | - .decrypt = atmel_tdes_ofb_decrypt, |
|---|
| 1191 | | - } |
|---|
| 1038 | + .base.cra_name = "ofb(des3_ede)", |
|---|
| 1039 | + .base.cra_driver_name = "atmel-ofb-tdes", |
|---|
| 1040 | + .base.cra_blocksize = DES_BLOCK_SIZE, |
|---|
| 1041 | + .base.cra_alignmask = 0x7, |
|---|
| 1042 | + |
|---|
| 1043 | + .min_keysize = DES3_EDE_KEY_SIZE, |
|---|
| 1044 | + .max_keysize = DES3_EDE_KEY_SIZE, |
|---|
| 1045 | + .setkey = atmel_tdes_setkey, |
|---|
| 1046 | + .encrypt = atmel_tdes_ofb_encrypt, |
|---|
| 1047 | + .decrypt = atmel_tdes_ofb_decrypt, |
|---|
| 1048 | + .ivsize = DES_BLOCK_SIZE, |
|---|
| 1192 | 1049 | }, |
|---|
| 1193 | 1050 | }; |
|---|
| 1194 | 1051 | |
|---|
| .. | .. |
|---|
| 1208 | 1065 | err = atmel_tdes_crypt_pdc_stop(dd); |
|---|
| 1209 | 1066 | else |
|---|
| 1210 | 1067 | err = atmel_tdes_crypt_dma_stop(dd); |
|---|
| 1211 | | - |
|---|
| 1212 | | - err = dd->err ? : err; |
|---|
| 1213 | 1068 | |
|---|
| 1214 | 1069 | if (dd->total && !err) { |
|---|
| 1215 | 1070 | if (dd->flags & TDES_FLAGS_FAST) { |
|---|
| .. | .. |
|---|
| 1251 | 1106 | int i; |
|---|
| 1252 | 1107 | |
|---|
| 1253 | 1108 | for (i = 0; i < ARRAY_SIZE(tdes_algs); i++) |
|---|
| 1254 | | - crypto_unregister_alg(&tdes_algs[i]); |
|---|
| 1109 | + crypto_unregister_skcipher(&tdes_algs[i]); |
|---|
| 1255 | 1110 | } |
|---|
| 1256 | 1111 | |
|---|
| 1257 | 1112 | static int atmel_tdes_register_algs(struct atmel_tdes_dev *dd) |
|---|
| .. | .. |
|---|
| 1259 | 1114 | int err, i, j; |
|---|
| 1260 | 1115 | |
|---|
| 1261 | 1116 | for (i = 0; i < ARRAY_SIZE(tdes_algs); i++) { |
|---|
| 1262 | | - err = crypto_register_alg(&tdes_algs[i]); |
|---|
| 1117 | + atmel_tdes_skcipher_alg_init(&tdes_algs[i]); |
|---|
| 1118 | + |
|---|
| 1119 | + err = crypto_register_skcipher(&tdes_algs[i]); |
|---|
| 1263 | 1120 | if (err) |
|---|
| 1264 | 1121 | goto err_tdes_algs; |
|---|
| 1265 | 1122 | } |
|---|
| .. | .. |
|---|
| 1268 | 1125 | |
|---|
| 1269 | 1126 | err_tdes_algs: |
|---|
| 1270 | 1127 | for (j = 0; j < i; j++) |
|---|
| 1271 | | - crypto_unregister_alg(&tdes_algs[j]); |
|---|
| 1128 | + crypto_unregister_skcipher(&tdes_algs[j]); |
|---|
| 1272 | 1129 | |
|---|
| 1273 | 1130 | return err; |
|---|
| 1274 | 1131 | } |
|---|
| .. | .. |
|---|
| 1300 | 1157 | { /* sentinel */ } |
|---|
| 1301 | 1158 | }; |
|---|
| 1302 | 1159 | MODULE_DEVICE_TABLE(of, atmel_tdes_dt_ids); |
|---|
| 1303 | | - |
|---|
| 1304 | | -static struct crypto_platform_data *atmel_tdes_of_init(struct platform_device *pdev) |
|---|
| 1305 | | -{ |
|---|
| 1306 | | - struct device_node *np = pdev->dev.of_node; |
|---|
| 1307 | | - struct crypto_platform_data *pdata; |
|---|
| 1308 | | - |
|---|
| 1309 | | - if (!np) { |
|---|
| 1310 | | - dev_err(&pdev->dev, "device node not found\n"); |
|---|
| 1311 | | - return ERR_PTR(-EINVAL); |
|---|
| 1312 | | - } |
|---|
| 1313 | | - |
|---|
| 1314 | | - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
|---|
| 1315 | | - if (!pdata) |
|---|
| 1316 | | - return ERR_PTR(-ENOMEM); |
|---|
| 1317 | | - |
|---|
| 1318 | | - pdata->dma_slave = devm_kzalloc(&pdev->dev, |
|---|
| 1319 | | - sizeof(*(pdata->dma_slave)), |
|---|
| 1320 | | - GFP_KERNEL); |
|---|
| 1321 | | - if (!pdata->dma_slave) |
|---|
| 1322 | | - return ERR_PTR(-ENOMEM); |
|---|
| 1323 | | - |
|---|
| 1324 | | - return pdata; |
|---|
| 1325 | | -} |
|---|
| 1326 | | -#else /* CONFIG_OF */ |
|---|
| 1327 | | -static inline struct crypto_platform_data *atmel_tdes_of_init(struct platform_device *pdev) |
|---|
| 1328 | | -{ |
|---|
| 1329 | | - return ERR_PTR(-EINVAL); |
|---|
| 1330 | | -} |
|---|
| 1331 | 1160 | #endif |
|---|
| 1332 | 1161 | |
|---|
| 1333 | 1162 | static int atmel_tdes_probe(struct platform_device *pdev) |
|---|
| 1334 | 1163 | { |
|---|
| 1335 | 1164 | struct atmel_tdes_dev *tdes_dd; |
|---|
| 1336 | | - struct crypto_platform_data *pdata; |
|---|
| 1337 | 1165 | struct device *dev = &pdev->dev; |
|---|
| 1338 | 1166 | struct resource *tdes_res; |
|---|
| 1339 | 1167 | int err; |
|---|
| 1340 | 1168 | |
|---|
| 1341 | 1169 | tdes_dd = devm_kmalloc(&pdev->dev, sizeof(*tdes_dd), GFP_KERNEL); |
|---|
| 1342 | | - if (tdes_dd == NULL) { |
|---|
| 1343 | | - err = -ENOMEM; |
|---|
| 1344 | | - goto tdes_dd_err; |
|---|
| 1345 | | - } |
|---|
| 1170 | + if (!tdes_dd) |
|---|
| 1171 | + return -ENOMEM; |
|---|
| 1346 | 1172 | |
|---|
| 1347 | 1173 | tdes_dd->dev = dev; |
|---|
| 1348 | 1174 | |
|---|
| .. | .. |
|---|
| 1363 | 1189 | if (!tdes_res) { |
|---|
| 1364 | 1190 | dev_err(dev, "no MEM resource info\n"); |
|---|
| 1365 | 1191 | err = -ENODEV; |
|---|
| 1366 | | - goto res_err; |
|---|
| 1192 | + goto err_tasklet_kill; |
|---|
| 1367 | 1193 | } |
|---|
| 1368 | 1194 | tdes_dd->phys_base = tdes_res->start; |
|---|
| 1369 | 1195 | |
|---|
| 1370 | 1196 | /* Get the IRQ */ |
|---|
| 1371 | 1197 | tdes_dd->irq = platform_get_irq(pdev, 0); |
|---|
| 1372 | 1198 | if (tdes_dd->irq < 0) { |
|---|
| 1373 | | - dev_err(dev, "no IRQ resource info\n"); |
|---|
| 1374 | 1199 | err = tdes_dd->irq; |
|---|
| 1375 | | - goto res_err; |
|---|
| 1200 | + goto err_tasklet_kill; |
|---|
| 1376 | 1201 | } |
|---|
| 1377 | 1202 | |
|---|
| 1378 | 1203 | err = devm_request_irq(&pdev->dev, tdes_dd->irq, atmel_tdes_irq, |
|---|
| 1379 | 1204 | IRQF_SHARED, "atmel-tdes", tdes_dd); |
|---|
| 1380 | 1205 | if (err) { |
|---|
| 1381 | 1206 | dev_err(dev, "unable to request tdes irq.\n"); |
|---|
| 1382 | | - goto res_err; |
|---|
| 1207 | + goto err_tasklet_kill; |
|---|
| 1383 | 1208 | } |
|---|
| 1384 | 1209 | |
|---|
| 1385 | 1210 | /* Initializing the clock */ |
|---|
| .. | .. |
|---|
| 1387 | 1212 | if (IS_ERR(tdes_dd->iclk)) { |
|---|
| 1388 | 1213 | dev_err(dev, "clock initialization failed.\n"); |
|---|
| 1389 | 1214 | err = PTR_ERR(tdes_dd->iclk); |
|---|
| 1390 | | - goto res_err; |
|---|
| 1215 | + goto err_tasklet_kill; |
|---|
| 1391 | 1216 | } |
|---|
| 1392 | 1217 | |
|---|
| 1393 | 1218 | tdes_dd->io_base = devm_ioremap_resource(&pdev->dev, tdes_res); |
|---|
| 1394 | 1219 | if (IS_ERR(tdes_dd->io_base)) { |
|---|
| 1395 | 1220 | dev_err(dev, "can't ioremap\n"); |
|---|
| 1396 | 1221 | err = PTR_ERR(tdes_dd->io_base); |
|---|
| 1397 | | - goto res_err; |
|---|
| 1222 | + goto err_tasklet_kill; |
|---|
| 1398 | 1223 | } |
|---|
| 1399 | 1224 | |
|---|
| 1400 | | - atmel_tdes_hw_version_init(tdes_dd); |
|---|
| 1225 | + err = atmel_tdes_hw_version_init(tdes_dd); |
|---|
| 1226 | + if (err) |
|---|
| 1227 | + goto err_tasklet_kill; |
|---|
| 1401 | 1228 | |
|---|
| 1402 | 1229 | atmel_tdes_get_cap(tdes_dd); |
|---|
| 1403 | 1230 | |
|---|
| 1404 | 1231 | err = atmel_tdes_buff_init(tdes_dd); |
|---|
| 1405 | 1232 | if (err) |
|---|
| 1406 | | - goto err_tdes_buff; |
|---|
| 1233 | + goto err_tasklet_kill; |
|---|
| 1407 | 1234 | |
|---|
| 1408 | 1235 | if (tdes_dd->caps.has_dma) { |
|---|
| 1409 | | - pdata = pdev->dev.platform_data; |
|---|
| 1410 | | - if (!pdata) { |
|---|
| 1411 | | - pdata = atmel_tdes_of_init(pdev); |
|---|
| 1412 | | - if (IS_ERR(pdata)) { |
|---|
| 1413 | | - dev_err(&pdev->dev, "platform data not available\n"); |
|---|
| 1414 | | - err = PTR_ERR(pdata); |
|---|
| 1415 | | - goto err_pdata; |
|---|
| 1416 | | - } |
|---|
| 1417 | | - } |
|---|
| 1418 | | - if (!pdata->dma_slave) { |
|---|
| 1419 | | - err = -ENXIO; |
|---|
| 1420 | | - goto err_pdata; |
|---|
| 1421 | | - } |
|---|
| 1422 | | - err = atmel_tdes_dma_init(tdes_dd, pdata); |
|---|
| 1236 | + err = atmel_tdes_dma_init(tdes_dd); |
|---|
| 1423 | 1237 | if (err) |
|---|
| 1424 | | - goto err_tdes_dma; |
|---|
| 1238 | + goto err_buff_cleanup; |
|---|
| 1425 | 1239 | |
|---|
| 1426 | 1240 | dev_info(dev, "using %s, %s for DMA transfers\n", |
|---|
| 1427 | 1241 | dma_chan_name(tdes_dd->dma_lch_in.chan), |
|---|
| .. | .. |
|---|
| 1446 | 1260 | spin_unlock(&atmel_tdes.lock); |
|---|
| 1447 | 1261 | if (tdes_dd->caps.has_dma) |
|---|
| 1448 | 1262 | atmel_tdes_dma_cleanup(tdes_dd); |
|---|
| 1449 | | -err_tdes_dma: |
|---|
| 1450 | | -err_pdata: |
|---|
| 1263 | +err_buff_cleanup: |
|---|
| 1451 | 1264 | atmel_tdes_buff_cleanup(tdes_dd); |
|---|
| 1452 | | -err_tdes_buff: |
|---|
| 1453 | | -res_err: |
|---|
| 1265 | +err_tasklet_kill: |
|---|
| 1454 | 1266 | tasklet_kill(&tdes_dd->done_task); |
|---|
| 1455 | 1267 | tasklet_kill(&tdes_dd->queue_task); |
|---|
| 1456 | | -tdes_dd_err: |
|---|
| 1457 | | - dev_err(dev, "initialization failed.\n"); |
|---|
| 1458 | 1268 | |
|---|
| 1459 | 1269 | return err; |
|---|
| 1460 | 1270 | } |
|---|