1 /******************************************************************************
3 ** FILE NAME : ifxmips_des.c
5 ** MODULES : DEU Module
7 ** DATE : September 8, 2009
8 ** AUTHOR : Mohammad Firdaus
9 ** DESCRIPTION : Data Encryption Unit Driver for DES Algorithm
10 ** COPYRIGHT : Copyright (c) 2009
11 ** Infineon Technologies AG
12 ** Am Campeon 1-12, 85579 Neubiberg, Germany
14 ** This program is free software; you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License as published by
16 ** the Free Software Foundation; either version 2 of the License, or
17 ** (at your option) any later version.
20 ** $Date $Author $Comment
21 ** 08 Sept 2009 Mohammad Firdaus Initial UEIP release
22 *******************************************************************************/
25 \defgroup IFX_DEU IFX_DEU_DRIVERS
33 \brief DES encryption DEU driver file
37 \defgroup IFX_DES_FUNCTIONS IFX_DES_FUNCTIONS
39 \brief IFX DES Encryption functions
42 /* Project Header Files */
43 #include <linux/version.h>
44 #include <linux/module.h>
45 #include <linux/init.h>
46 #include <linux/types.h>
47 #include <linux/errno.h>
48 #include <linux/crypto.h>
49 #include <linux/interrupt.h>
50 #include <linux/delay.h>
51 #include <asm/byteorder.h>
52 #include <crypto/algapi.h>
53 #include "ifxmips_deu.h"
55 #if defined(CONFIG_DANUBE)
56 #include "ifxmips_deu_danube.h"
57 extern int ifx_danube_pre_1_4;
58 #elif defined(CONFIG_AR9)
59 #include "ifxmips_deu_ar9.h"
60 #elif defined(CONFIG_VR9) || defined(CONFIG_AR10)
61 #include "ifxmips_deu_vr9.h"
63 #error "Unkown platform"
66 /* DMA specific header and variables */
69 #define CRTCL_SECT_INIT
70 #define CRTCL_SECT_START
71 #define CRTCL_SECT_END
74 #define CRTCL_SECT_INIT spin_lock_init(&des_lock)
75 #define CRTCL_SECT_START spin_lock_irqsave(&des_lock, flag)
76 #define CRTCL_SECT_END spin_unlock_irqrestore(&des_lock, flag)
79 /* Preprocessor declerations */
81 extern char debug_level;
82 #define DPRINTF(level, format, args...) if (level < debug_level) printk(KERN_INFO "[%s %s %d]: " format, __FILE__, __func__, __LINE__, ##args);
84 #define DPRINTF(level, format, args...)
86 #define DES_3DES_START IFX_DES_CON
87 #define DES_KEY_SIZE 8
88 #define DES_EXPKEY_WORDS 32
89 #define DES_BLOCK_SIZE 8
90 #define DES3_EDE_KEY_SIZE (3 * DES_KEY_SIZE)
91 #define DES3_EDE_EXPKEY_WORDS (3 * DES_EXPKEY_WORDS)
92 #define DES3_EDE_BLOCK_SIZE DES_BLOCK_SIZE
94 /* Function Declaration to prevent warning messages */
95 void des_chip_init (void);
96 u32 endian_swap(u32 input);
97 u32 input_swap(u32 input);
98 int aes_memory_allocate(int value);
99 int des_memory_allocate(int value);
100 void memory_release(u32 *buffer);
101 u32* memory_alignment(const u8 *arg, u32 *buff_alloc, int in_out, int nbytes);
102 void aes_dma_memory_copy(u32 *outcopy, u32 *out_dma, u8 *out_arg, int nbytes);
103 void des_dma_memory_copy(u32 *outcopy, u32 *out_dma, u8 *out_arg, int nbytes);
105 void ifx_deu_des (void *ctx_arg, u8 *out_arg, const u8 *in_arg,
106 u8 *iv_arg, u32 nbytes, int encdec, int mode);
111 u8 iv[DES_BLOCK_SIZE];
112 u32 expkey[DES3_EDE_EXPKEY_WORDS];
115 extern int disable_multiblock;
116 extern int disable_deudma;
119 /*! \fn int des_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
120 * \ingroup IFX_DES_FUNCTIONS
121 * \brief sets DES key
122 * \param tfm linux crypto algo transform
123 * \param key input key
124 * \param keylen key length
126 int des_setkey(struct crypto_tfm *tfm, const u8 *key,
129 struct des_ctx *dctx = crypto_tfm_ctx(tfm);
131 //printk("setkey in %s\n", __FILE__);
133 dctx->controlr_M = 0; // des
134 dctx->key_length = keylen;
136 memcpy ((u8 *) (dctx->expkey), key, keylen);
142 /*! \fn void ifx_deu_des(void *ctx_arg, u8 *out_arg, const u8 *in_arg, u8 *iv_arg, u32 nbytes, int encdec, int mode)
143 * \ingroup IFX_DES_FUNCTIONS
144 * \brief main interface to DES hardware
145 * \param ctx_arg crypto algo context
146 * \param out_arg output bytestream
147 * \param in_arg input bytestream
148 * \param iv_arg initialization vector
149 * \param nbytes length of bytestream
150 * \param encdec 1 for encrypt; 0 for decrypt
151 * \param mode operation mode such as ebc, cbc
154 void ifx_deu_des (void *ctx_arg, u8 *out_arg, const u8 *in_arg,
155 u8 *iv_arg, u32 nbytes, int encdec, int mode)
157 volatile struct des_t *des = (struct des_t *) DES_3DES_START;
158 struct des_ctx *dctx = ctx_arg;
159 u32 *key = dctx->expkey;
167 des->controlr.M = dctx->controlr_M;
168 if (dctx->controlr_M == 0) // des
170 des->K1HR = DEU_ENDIAN_SWAP(*((u32 *) key + 0));
171 des->K1LR = DEU_ENDIAN_SWAP(*((u32 *) key + 1));
175 /* Hardware Section */
176 switch (dctx->key_length) {
178 des->K3HR = DEU_ENDIAN_SWAP(*((u32 *) key + 4));
179 des->K3LR = DEU_ENDIAN_SWAP(*((u32 *) key + 5));
183 des->K2HR = DEU_ENDIAN_SWAP(*((u32 *) key + 2));
184 des->K2LR = DEU_ENDIAN_SWAP(*((u32 *) key + 3));
188 des->K1HR = DEU_ENDIAN_SWAP(*((u32 *) key + 0));
189 des->K1LR = DEU_ENDIAN_SWAP(*((u32 *) key + 1));
198 des->controlr.E_D = !encdec; //encryption
199 des->controlr.O = mode; //0 ECB 1 CBC 2 OFB 3 CFB 4 CTR hexdump(prin,sizeof(*des));
202 des->IVHR = DEU_ENDIAN_SWAP(*(u32 *) iv_arg);
203 des->IVLR = DEU_ENDIAN_SWAP(*((u32 *) iv_arg + 1));
206 nblocks = nbytes / 4;
208 for (i = 0; i < nblocks; i += 2) {
209 /* wait for busy bit to clear */
211 /*--- Workaround ----------------------------------------------------
212 do a dummy read to the busy flag because it is not raised early
213 enough in CFB/OFB 3DES modes */
215 printk ("ihr: %x\n", (*((u32 *) in_arg + i)));
216 printk ("ilr: %x\n", (*((u32 *) in_arg + 1 + i)));
218 des->IHR = INPUT_ENDIAN_SWAP(*((u32 *) in_arg + i));
219 des->ILR = INPUT_ENDIAN_SWAP(*((u32 *) in_arg + 1 + i)); /* start crypto */
221 while (des->controlr.BUS) {
222 // this will not take long
225 *((u32 *) out_arg + 0 + i) = des->OHR;
226 *((u32 *) out_arg + 1 + i) = des->OLR;
233 *(u32 *) iv_arg = DEU_ENDIAN_SWAP(des->IVHR);
234 *((u32 *) iv_arg + 1) = DEU_ENDIAN_SWAP(des->IVLR);
240 //definitions from linux/include/crypto.h:
241 //#define CRYPTO_TFM_MODE_ECB 0x00000001
242 //#define CRYPTO_TFM_MODE_CBC 0x00000002
243 //#define CRYPTO_TFM_MODE_CFB 0x00000004
244 //#define CRYPTO_TFM_MODE_CTR 0x00000008
245 //#define CRYPTO_TFM_MODE_OFB 0x00000010 // not even defined
246 //but hardware definition: 0 ECB 1 CBC 2 OFB 3 CFB 4 CTR
248 /*! \fn void ifx_deu_des(void *ctx_arg, u8 *out_arg, const u8 *in_arg, u8 *iv_arg, u32 nbytes, int encdec, int mode)
249 * \ingroup IFX_DES_FUNCTIONS
250 * \brief main interface to DES hardware
251 * \param ctx_arg crypto algo context
252 * \param out_arg output bytestream
253 * \param in_arg input bytestream
254 * \param iv_arg initialization vector
255 * \param nbytes length of bytestream
256 * \param encdec 1 for encrypt; 0 for decrypt
257 * \param mode operation mode such as ebc, cbc
262 /*! \fn void ifx_deu_des_ecb (void *ctx, uint8_t *dst, const uint8_t *src, uint8_t *iv, size_t nbytes, int encdec, int inplace)
263 * \ingroup IFX_DES_FUNCTIONS
264 * \brief sets DES hardware to ECB mode
265 * \param ctx crypto algo context
266 * \param dst output bytestream
267 * \param src input bytestream
268 * \param iv initialization vector
269 * \param nbytes length of bytestream
270 * \param encdec 1 for encrypt; 0 for decrypt
271 * \param inplace not used
274 void ifx_deu_des_ecb (void *ctx, uint8_t *dst, const uint8_t *src,
275 uint8_t *iv, size_t nbytes, int encdec, int inplace)
277 ifx_deu_des (ctx, dst, src, NULL, nbytes, encdec, 0);
280 /*! \fn void ifx_deu_des_cbc (void *ctx, uint8_t *dst, const uint8_t *src, uint8_t *iv, size_t nbytes, int encdec, int inplace)
281 * \ingroup IFX_DES_FUNCTIONS
282 * \brief sets DES hardware to CBC mode
283 * \param ctx crypto algo context
284 * \param dst output bytestream
285 * \param src input bytestream
286 * \param iv initialization vector
287 * \param nbytes length of bytestream
288 * \param encdec 1 for encrypt; 0 for decrypt
289 * \param inplace not used
291 void ifx_deu_des_cbc (void *ctx, uint8_t *dst, const uint8_t *src,
292 uint8_t *iv, size_t nbytes, int encdec, int inplace)
294 ifx_deu_des (ctx, dst, src, iv, nbytes, encdec, 1);
297 /*! \fn void ifx_deu_des_ofb (void *ctx, uint8_t *dst, const uint8_t *src, uint8_t *iv, size_t nbytes, int encdec, int inplace)
298 * \ingroup IFX_DES_FUNCTIONS
299 * \brief sets DES hardware to OFB mode
300 * \param ctx crypto algo context
301 * \param dst output bytestream
302 * \param src input bytestream
303 * \param iv initialization vector
304 * \param nbytes length of bytestream
305 * \param encdec 1 for encrypt; 0 for decrypt
306 * \param inplace not used
308 void ifx_deu_des_ofb (void *ctx, uint8_t *dst, const uint8_t *src,
309 uint8_t *iv, size_t nbytes, int encdec, int inplace)
311 ifx_deu_des (ctx, dst, src, iv, nbytes, encdec, 2);
314 /*! \fn void ifx_deu_des_cfb (void *ctx, uint8_t *dst, const uint8_t *src, uint8_t *iv, size_t nbytes, int encdec, int inplace)
315 \ingroup IFX_DES_FUNCTIONS
316 \brief sets DES hardware to CFB mode
317 \param ctx crypto algo context
318 \param dst output bytestream
319 \param src input bytestream
320 \param iv initialization vector
321 \param nbytes length of bytestream
322 \param encdec 1 for encrypt; 0 for decrypt
323 \param inplace not used
325 void ifx_deu_des_cfb (void *ctx, uint8_t *dst, const uint8_t *src,
326 uint8_t *iv, size_t nbytes, int encdec, int inplace)
328 ifx_deu_des (ctx, dst, src, iv, nbytes, encdec, 3);
331 /*! \fn void ifx_deu_des_ctr (void *ctx, uint8_t *dst, const uint8_t *src, uint8_t *iv, size_t nbytes, int encdec, int inplace)
332 * \ingroup IFX_DES_FUNCTIONS
333 * \brief sets DES hardware to CTR mode
334 * \param ctx crypto algo context
335 * \param dst output bytestream
336 * \param src input bytestream
337 * \param iv initialization vector
338 * \param nbytes length of bytestream
339 * \param encdec 1 for encrypt; 0 for decrypt
340 * \param inplace not used
342 void ifx_deu_des_ctr (void *ctx, uint8_t *dst, const uint8_t *src,
343 uint8_t *iv, size_t nbytes, int encdec, int inplace)
345 ifx_deu_des (ctx, dst, src, iv, nbytes, encdec, 4);
348 /*! \fn void des_encrypt (struct crypto_tfm *tfm, uint8_t *out, const uint8_t *in)
349 * \ingroup IFX_DES_FUNCTIONS
350 * \brief encrypt DES_BLOCK_SIZE of data
351 * \param tfm linux crypto algo transform
352 * \param out output bytestream
353 * \param in input bytestream
355 void des_encrypt (struct crypto_tfm *tfm, uint8_t * out, const uint8_t * in)
357 struct des_ctx *ctx = crypto_tfm_ctx(tfm);
358 ifx_deu_des (ctx, out, in, NULL, DES_BLOCK_SIZE,
359 CRYPTO_DIR_ENCRYPT, 0);
363 /*! \fn void des_decrypt (struct crypto_tfm *tfm, uint8_t *out, const uint8_t *in)
364 * \ingroup IFX_DES_FUNCTIONS
365 * \brief encrypt DES_BLOCK_SIZE of data
366 * \param tfm linux crypto algo transform
367 * \param out output bytestream
368 * \param in input bytestream
370 void des_decrypt (struct crypto_tfm *tfm, uint8_t * out, const uint8_t * in)
372 struct des_ctx *ctx = crypto_tfm_ctx(tfm);
373 ifx_deu_des (ctx, out, in, NULL, DES_BLOCK_SIZE,
374 CRYPTO_DIR_DECRYPT, 0);
380 * For DES-EDE3, there is no known need to reject weak or
381 * complementation keys. Any weakness is obviated by the use of
384 * However, if the first two or last two independent 64-bit keys are
385 * equal (k1 == k2 or k2 == k3), then the DES3 operation is simply the
386 * same as DES. Implementers MUST reject keys that exhibit this
391 /*! \fn int des3_ede_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
392 * \ingroup IFX_DES_FUNCTIONS
393 * \brief sets 3DES key
394 * \param tfm linux crypto algo transform
395 * \param key input key
396 * \param keylen key length
398 int des3_ede_setkey(struct crypto_tfm *tfm, const u8 *key,
401 struct des_ctx *dctx = crypto_tfm_ctx(tfm);
403 //printk("setkey in %s\n", __FILE__);
405 dctx->controlr_M = keylen / 8 + 1; // 3DES EDE1 / EDE2 / EDE3 Mode
406 dctx->key_length = keylen;
408 memcpy ((u8 *) (dctx->expkey), key, keylen);
414 * \brief DES function mappings
416 struct crypto_alg ifxdeu_des_alg = {
418 .cra_driver_name = "ifxdeu-des",
419 .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
420 .cra_blocksize = DES_BLOCK_SIZE,
421 .cra_ctxsize = sizeof(struct des_ctx),
422 .cra_module = THIS_MODULE,
424 .cra_list = LIST_HEAD_INIT(ifxdeu_des_alg.cra_list),
425 .cra_u = { .cipher = {
426 .cia_min_keysize = DES_KEY_SIZE,
427 .cia_max_keysize = DES_KEY_SIZE,
428 .cia_setkey = des_setkey,
429 .cia_encrypt = des_encrypt,
430 .cia_decrypt = des_decrypt } }
434 * \brief DES function mappings
436 struct crypto_alg ifxdeu_des3_ede_alg = {
437 .cra_name = "des3_ede",
438 .cra_driver_name = "ifxdeu-des3_ede",
439 .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
440 .cra_blocksize = DES_BLOCK_SIZE,
441 .cra_ctxsize = sizeof(struct des_ctx),
442 .cra_module = THIS_MODULE,
444 .cra_list = LIST_HEAD_INIT(ifxdeu_des3_ede_alg.cra_list),
445 .cra_u = { .cipher = {
446 .cia_min_keysize = DES_KEY_SIZE,
447 .cia_max_keysize = DES_KEY_SIZE,
448 .cia_setkey = des3_ede_setkey,
449 .cia_encrypt = des_encrypt,
450 .cia_decrypt = des_decrypt } }
453 /*! \fn int ecb_des_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes)
454 * \ingroup IFX_DES_FUNCTIONS
455 * \brief ECB DES encrypt using linux crypto blkcipher
456 * \param desc blkcipher descriptor
457 * \param dst output scatterlist
458 * \param src input scatterlist
459 * \param nbytes data size in bytes
461 int ecb_des_encrypt(struct blkcipher_desc *desc,
462 struct scatterlist *dst, struct scatterlist *src,
465 struct des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
466 struct blkcipher_walk walk;
469 blkcipher_walk_init(&walk, dst, src, nbytes);
470 err = blkcipher_walk_virt(desc, &walk);
472 while ((nbytes = walk.nbytes)) {
473 nbytes -= (nbytes % DES_BLOCK_SIZE);
474 ifx_deu_des_ecb(ctx, walk.dst.virt.addr, walk.src.virt.addr,
475 NULL, nbytes, CRYPTO_DIR_ENCRYPT, 0);
476 nbytes &= DES_BLOCK_SIZE - 1;
477 err = blkcipher_walk_done(desc, &walk, nbytes);
483 /*! \fn int ecb_des_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes)
484 * \ingroup IFX_DES_FUNCTIONS
485 * \brief ECB DES decrypt using linux crypto blkcipher
486 * \param desc blkcipher descriptor
487 * \param dst output scatterlist
488 * \param src input scatterlist
489 * \param nbytes data size in bytes
492 int ecb_des_decrypt(struct blkcipher_desc *desc,
493 struct scatterlist *dst, struct scatterlist *src,
496 struct des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
497 struct blkcipher_walk walk;
501 blkcipher_walk_init(&walk, dst, src, nbytes);
502 err = blkcipher_walk_virt(desc, &walk);
504 while ((nbytes = walk.nbytes)) {
505 nbytes -= (nbytes % DES_BLOCK_SIZE);
506 ifx_deu_des_ecb(ctx, walk.dst.virt.addr, walk.src.virt.addr,
507 NULL, nbytes, CRYPTO_DIR_DECRYPT, 0);
508 nbytes &= DES_BLOCK_SIZE - 1;
509 err = blkcipher_walk_done(desc, &walk, nbytes);
516 * \brief DES function mappings
518 struct crypto_alg ifxdeu_ecb_des_alg = {
519 .cra_name = "ecb(des)",
520 .cra_driver_name = "ifxdeu-ecb(des)",
521 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
522 .cra_blocksize = DES_BLOCK_SIZE,
523 .cra_ctxsize = sizeof(struct des_ctx),
524 .cra_type = &crypto_blkcipher_type,
525 .cra_module = THIS_MODULE,
526 .cra_list = LIST_HEAD_INIT(ifxdeu_ecb_des_alg.cra_list),
529 .min_keysize = DES_KEY_SIZE,
530 .max_keysize = DES_KEY_SIZE,
531 .setkey = des_setkey,
532 .encrypt = ecb_des_encrypt,
533 .decrypt = ecb_des_decrypt,
539 * \brief DES function mappings
541 struct crypto_alg ifxdeu_ecb_des3_ede_alg = {
542 .cra_name = "ecb(des3_ede)",
543 .cra_driver_name = "ifxdeu-ecb(des3_ede)",
544 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
545 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
546 .cra_ctxsize = sizeof(struct des_ctx),
547 .cra_type = &crypto_blkcipher_type,
548 .cra_module = THIS_MODULE,
549 .cra_list = LIST_HEAD_INIT(ifxdeu_ecb_des3_ede_alg.cra_list),
552 .min_keysize = DES3_EDE_KEY_SIZE,
553 .max_keysize = DES3_EDE_KEY_SIZE,
554 .setkey = des3_ede_setkey,
555 .encrypt = ecb_des_encrypt,
556 .decrypt = ecb_des_decrypt,
561 /*! \fn int cbc_des_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes)
562 * \ingroup IFX_DES_FUNCTIONS
563 * \brief CBC DES encrypt using linux crypto blkcipher
564 * \param desc blkcipher descriptor
565 * \param dst output scatterlist
566 * \param src input scatterlist
567 * \param nbytes data size in bytes
570 int cbc_des_encrypt(struct blkcipher_desc *desc,
571 struct scatterlist *dst, struct scatterlist *src,
574 struct des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
575 struct blkcipher_walk walk;
579 blkcipher_walk_init(&walk, dst, src, nbytes);
580 err = blkcipher_walk_virt(desc, &walk);
582 while ((nbytes = walk.nbytes)) {
584 nbytes -= (nbytes % DES_BLOCK_SIZE);
585 ifx_deu_des_cbc(ctx, walk.dst.virt.addr, walk.src.virt.addr,
586 iv, nbytes, CRYPTO_DIR_ENCRYPT, 0);
587 nbytes &= DES_BLOCK_SIZE - 1;
588 err = blkcipher_walk_done(desc, &walk, nbytes);
594 /*! \fn int cbc_des_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes)
595 * \ingroup IFX_DES_FUNCTIONS
596 * \brief CBC DES decrypt using linux crypto blkcipher
597 * \param desc blkcipher descriptor
598 * \param dst output scatterlist
599 * \param src input scatterlist
600 * \param nbytes data size in bytes
603 int cbc_des_decrypt(struct blkcipher_desc *desc,
604 struct scatterlist *dst, struct scatterlist *src,
607 struct des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
608 struct blkcipher_walk walk;
612 blkcipher_walk_init(&walk, dst, src, nbytes);
613 err = blkcipher_walk_virt(desc, &walk);
615 while ((nbytes = walk.nbytes)) {
617 nbytes -= (nbytes % DES_BLOCK_SIZE);
618 ifx_deu_des_cbc(ctx, walk.dst.virt.addr, walk.src.virt.addr,
619 iv, nbytes, CRYPTO_DIR_DECRYPT, 0);
620 nbytes &= DES_BLOCK_SIZE - 1;
621 err = blkcipher_walk_done(desc, &walk, nbytes);
628 * \brief DES function mappings
630 struct crypto_alg ifxdeu_cbc_des_alg = {
631 .cra_name = "cbc(des)",
632 .cra_driver_name = "ifxdeu-cbc(des)",
633 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
634 .cra_blocksize = DES_BLOCK_SIZE,
635 .cra_ctxsize = sizeof(struct des_ctx),
636 .cra_type = &crypto_blkcipher_type,
637 .cra_module = THIS_MODULE,
638 .cra_list = LIST_HEAD_INIT(ifxdeu_cbc_des_alg.cra_list),
641 .min_keysize = DES_KEY_SIZE,
642 .max_keysize = DES_KEY_SIZE,
643 .ivsize = DES_BLOCK_SIZE,
644 .setkey = des_setkey,
645 .encrypt = cbc_des_encrypt,
646 .decrypt = cbc_des_decrypt,
652 * \brief DES function mappings
654 struct crypto_alg ifxdeu_cbc_des3_ede_alg = {
655 .cra_name = "cbc(des3_ede)",
656 .cra_driver_name = "ifxdeu-cbc(des3_ede)",
657 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
658 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
659 .cra_ctxsize = sizeof(struct des_ctx),
660 .cra_type = &crypto_blkcipher_type,
661 .cra_module = THIS_MODULE,
662 .cra_list = LIST_HEAD_INIT(ifxdeu_cbc_des3_ede_alg.cra_list),
665 .min_keysize = DES3_EDE_KEY_SIZE,
666 .max_keysize = DES3_EDE_KEY_SIZE,
667 .ivsize = DES_BLOCK_SIZE,
668 .setkey = des3_ede_setkey,
669 .encrypt = cbc_des_encrypt,
670 .decrypt = cbc_des_decrypt,
675 /*! \fn int __init ifxdeu_init_des (void)
676 * \ingroup IFX_DES_FUNCTIONS
677 * \brief initialize des driver
679 int __init ifxdeu_init_des (void)
684 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20))
685 if (!disable_multiblock) {
686 ifxdeu_des_alg.cra_u.cipher.cia_max_nbytes = DES_BLOCK_SIZE; //(size_t)-1;
687 ifxdeu_des_alg.cra_u.cipher.cia_req_align = 16;
688 ifxdeu_des_alg.cra_u.cipher.cia_ecb = ifx_deu_des_ecb;
689 ifxdeu_des_alg.cra_u.cipher.cia_cbc = ifx_deu_des_cbc;
690 ifxdeu_des_alg.cra_u.cipher.cia_cfb = ifx_deu_des_cfb;
691 ifxdeu_des_alg.cra_u.cipher.cia_ofb = ifx_deu_des_ofb;
695 ret = crypto_register_alg(&ifxdeu_des_alg);
699 ret = crypto_register_alg(&ifxdeu_ecb_des_alg);
703 ret = crypto_register_alg(&ifxdeu_cbc_des_alg);
707 ret = crypto_register_alg(&ifxdeu_des3_ede_alg);
711 ret = crypto_register_alg(&ifxdeu_ecb_des3_ede_alg);
713 goto ecb_des3_ede_err;
715 ret = crypto_register_alg(&ifxdeu_cbc_des3_ede_alg);
717 goto cbc_des3_ede_err;
724 printk (KERN_NOTICE "IFX DEU DES initialized%s%s.\n", disable_multiblock ? "" : " (multiblock)", disable_deudma ? "" : " (DMA)");
728 crypto_unregister_alg(&ifxdeu_des_alg);
729 printk(KERN_ERR "IFX des initialization failed!\n");
732 crypto_unregister_alg(&ifxdeu_ecb_des_alg);
733 printk (KERN_ERR "IFX ecb_des initialization failed!\n");
736 crypto_unregister_alg(&ifxdeu_cbc_des_alg);
737 printk (KERN_ERR "IFX cbc_des initialization failed!\n");
740 crypto_unregister_alg(&ifxdeu_des3_ede_alg);
741 printk(KERN_ERR "IFX des3_ede initialization failed!\n");
744 crypto_unregister_alg(&ifxdeu_ecb_des3_ede_alg);
745 printk (KERN_ERR "IFX ecb_des3_ede initialization failed!\n");
748 crypto_unregister_alg(&ifxdeu_cbc_des3_ede_alg);
749 printk (KERN_ERR "IFX cbc_des3_ede initialization failed!\n");
754 /*! \fn void __exit ifxdeu_fini_des (void)
755 * \ingroup IFX_DES_FUNCTIONS
756 * \brief unregister des driver
758 void __exit ifxdeu_fini_des (void)
760 crypto_unregister_alg (&ifxdeu_des_alg);
761 crypto_unregister_alg (&ifxdeu_ecb_des_alg);
762 crypto_unregister_alg (&ifxdeu_cbc_des_alg);
763 crypto_unregister_alg (&ifxdeu_des3_ede_alg);
764 crypto_unregister_alg (&ifxdeu_ecb_des3_ede_alg);
765 crypto_unregister_alg (&ifxdeu_cbc_des3_ede_alg);