2 * Intel IXP4xx NPE-C crypto driver
4 * Copyright (C) 2008 Christian Hohnstaedt <chohnstaedt@innominate.com>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License
8 * as published by the Free Software Foundation.
12 #include <linux/platform_device.h>
13 #include <linux/dma-mapping.h>
14 #include <linux/dmapool.h>
15 #include <linux/crypto.h>
16 #include <linux/kernel.h>
17 #include <linux/rtnetlink.h>
18 #include <linux/interrupt.h>
19 #include <linux/spinlock.h>
20 #include <linux/gfp.h>
21 #include <linux/module.h>
23 #include <crypto/ctr.h>
24 #include <crypto/des.h>
25 #include <crypto/aes.h>
26 #include <crypto/hmac.h>
27 #include <crypto/sha.h>
28 #include <crypto/algapi.h>
29 #include <crypto/internal/aead.h>
30 #include <crypto/authenc.h>
31 #include <crypto/scatterwalk.h>
34 #include <mach/qmgr.h>
38 /* hash: cfgword + 2 * digestlen; crypt: keylen + cfgword */
39 #define NPE_CTX_LEN 80
40 #define AES_BLOCK128 16
42 #define NPE_OP_HASH_VERIFY 0x01
43 #define NPE_OP_CCM_ENABLE 0x04
44 #define NPE_OP_CRYPT_ENABLE 0x08
45 #define NPE_OP_HASH_ENABLE 0x10
46 #define NPE_OP_NOT_IN_PLACE 0x20
47 #define NPE_OP_HMAC_DISABLE 0x40
48 #define NPE_OP_CRYPT_ENCRYPT 0x80
50 #define NPE_OP_CCM_GEN_MIC 0xcc
51 #define NPE_OP_HASH_GEN_ICV 0x50
52 #define NPE_OP_ENC_GEN_KEY 0xc9
54 #define MOD_ECB 0x0000
55 #define MOD_CTR 0x1000
56 #define MOD_CBC_ENC 0x2000
57 #define MOD_CBC_DEC 0x3000
58 #define MOD_CCM_ENC 0x4000
59 #define MOD_CCM_DEC 0x5000
65 #define CIPH_DECR 0x0000
66 #define CIPH_ENCR 0x0400
68 #define MOD_DES 0x0000
69 #define MOD_TDEA2 0x0100
70 #define MOD_3DES 0x0200
71 #define MOD_AES 0x0800
72 #define MOD_AES128 (0x0800 | KEYLEN_128)
73 #define MOD_AES192 (0x0900 | KEYLEN_192)
74 #define MOD_AES256 (0x0a00 | KEYLEN_256)
77 #define NPE_ID 2 /* NPE C */
79 /* Space for registering when the first
80 * NPE_QLEN crypt_ctl are busy */
81 #define NPE_QLEN_TOTAL 64
86 #define CTL_FLAG_UNUSED 0x0000
87 #define CTL_FLAG_USED 0x1000
88 #define CTL_FLAG_PERFORM_ABLK 0x0001
89 #define CTL_FLAG_GEN_ICV 0x0002
90 #define CTL_FLAG_GEN_REVAES 0x0004
91 #define CTL_FLAG_PERFORM_AEAD 0x0008
92 #define CTL_FLAG_MASK 0x000f
94 #define HMAC_PAD_BLOCKLEN SHA1_BLOCK_SIZE
96 #define MD5_DIGEST_SIZE 16
109 struct buffer_desc
*next
;
110 enum dma_data_direction dir
;
115 u8 mode
; /* NPE_OP_* operation mode */
121 u8 mode
; /* NPE_OP_* operation mode */
123 u8 iv
[MAX_IVLEN
]; /* IV for CBC mode or CTR IV for CTR mode */
124 u32 icv_rev_aes
; /* icv or rev aes */
128 u16 auth_offs
; /* Authentication start offset */
129 u16 auth_len
; /* Authentication data length */
130 u16 crypt_offs
; /* Cryption start offset */
131 u16 crypt_len
; /* Cryption data length */
133 u16 auth_len
; /* Authentication data length */
134 u16 auth_offs
; /* Authentication start offset */
135 u16 crypt_len
; /* Cryption data length */
136 u16 crypt_offs
; /* Cryption start offset */
138 u32 aadAddr
; /* Additional Auth Data Addr for CCM mode */
139 u32 crypto_ctx
; /* NPE Crypto Param structure address */
141 /* Used by Host: 4*4 bytes*/
144 struct ablkcipher_request
*ablk_req
;
145 struct aead_request
*aead_req
;
146 struct crypto_tfm
*tfm
;
148 struct buffer_desc
*regist_buf
;
153 struct buffer_desc
*src
;
154 struct buffer_desc
*dst
;
158 struct buffer_desc
*src
;
159 struct buffer_desc
*dst
;
160 struct scatterlist ivlist
;
161 /* used when the hmac is not on one sg entry */
166 struct ix_hash_algo
{
172 unsigned char *npe_ctx
;
173 dma_addr_t npe_ctx_phys
;
179 struct ix_sa_dir encrypt
;
180 struct ix_sa_dir decrypt
;
182 u8 authkey
[MAX_KEYLEN
];
184 u8 enckey
[MAX_KEYLEN
];
186 u8 nonce
[CTR_RFC3686_NONCE_SIZE
];
188 atomic_t configuring
;
189 struct completion completion
;
193 struct crypto_alg crypto
;
194 const struct ix_hash_algo
*hash
;
201 struct ixp_aead_alg
{
202 struct aead_alg crypto
;
203 const struct ix_hash_algo
*hash
;
210 static const struct ix_hash_algo hash_alg_md5
= {
211 .cfgword
= 0xAA010004,
212 .icv
= "\x01\x23\x45\x67\x89\xAB\xCD\xEF"
213 "\xFE\xDC\xBA\x98\x76\x54\x32\x10",
215 static const struct ix_hash_algo hash_alg_sha1
= {
216 .cfgword
= 0x00000005,
217 .icv
= "\x67\x45\x23\x01\xEF\xCD\xAB\x89\x98\xBA"
218 "\xDC\xFE\x10\x32\x54\x76\xC3\xD2\xE1\xF0",
221 static struct npe
*npe_c
;
222 static struct dma_pool
*buffer_pool
= NULL
;
223 static struct dma_pool
*ctx_pool
= NULL
;
225 static struct crypt_ctl
*crypt_virt
= NULL
;
226 static dma_addr_t crypt_phys
;
228 static int support_aes
= 1;
230 #define DRIVER_NAME "ixp4xx_crypto"
232 static struct platform_device
*pdev
;
234 static inline dma_addr_t
crypt_virt2phys(struct crypt_ctl
*virt
)
236 return crypt_phys
+ (virt
- crypt_virt
) * sizeof(struct crypt_ctl
);
239 static inline struct crypt_ctl
*crypt_phys2virt(dma_addr_t phys
)
241 return crypt_virt
+ (phys
- crypt_phys
) / sizeof(struct crypt_ctl
);
244 static inline u32
cipher_cfg_enc(struct crypto_tfm
*tfm
)
246 return container_of(tfm
->__crt_alg
, struct ixp_alg
,crypto
)->cfg_enc
;
249 static inline u32
cipher_cfg_dec(struct crypto_tfm
*tfm
)
251 return container_of(tfm
->__crt_alg
, struct ixp_alg
,crypto
)->cfg_dec
;
254 static inline const struct ix_hash_algo
*ix_hash(struct crypto_tfm
*tfm
)
256 return container_of(tfm
->__crt_alg
, struct ixp_alg
, crypto
)->hash
;
259 static int setup_crypt_desc(void)
261 struct device
*dev
= &pdev
->dev
;
262 BUILD_BUG_ON(sizeof(struct crypt_ctl
) != 64);
263 crypt_virt
= dma_alloc_coherent(dev
,
264 NPE_QLEN
* sizeof(struct crypt_ctl
),
265 &crypt_phys
, GFP_ATOMIC
);
268 memset(crypt_virt
, 0, NPE_QLEN
* sizeof(struct crypt_ctl
));
272 static spinlock_t desc_lock
;
273 static struct crypt_ctl
*get_crypt_desc(void)
279 spin_lock_irqsave(&desc_lock
, flags
);
281 if (unlikely(!crypt_virt
))
283 if (unlikely(!crypt_virt
)) {
284 spin_unlock_irqrestore(&desc_lock
, flags
);
288 if (crypt_virt
[i
].ctl_flags
== CTL_FLAG_UNUSED
) {
289 if (++idx
>= NPE_QLEN
)
291 crypt_virt
[i
].ctl_flags
= CTL_FLAG_USED
;
292 spin_unlock_irqrestore(&desc_lock
, flags
);
293 return crypt_virt
+i
;
295 spin_unlock_irqrestore(&desc_lock
, flags
);
300 static spinlock_t emerg_lock
;
301 static struct crypt_ctl
*get_crypt_desc_emerg(void)
304 static int idx
= NPE_QLEN
;
305 struct crypt_ctl
*desc
;
308 desc
= get_crypt_desc();
311 if (unlikely(!crypt_virt
))
314 spin_lock_irqsave(&emerg_lock
, flags
);
316 if (crypt_virt
[i
].ctl_flags
== CTL_FLAG_UNUSED
) {
317 if (++idx
>= NPE_QLEN_TOTAL
)
319 crypt_virt
[i
].ctl_flags
= CTL_FLAG_USED
;
320 spin_unlock_irqrestore(&emerg_lock
, flags
);
321 return crypt_virt
+i
;
323 spin_unlock_irqrestore(&emerg_lock
, flags
);
328 static void free_buf_chain(struct device
*dev
, struct buffer_desc
*buf
,u32 phys
)
331 struct buffer_desc
*buf1
;
335 phys1
= buf
->phys_next
;
336 dma_unmap_single(dev
, buf
->phys_next
, buf
->buf_len
, buf
->dir
);
337 dma_pool_free(buffer_pool
, buf
, phys
);
343 static struct tasklet_struct crypto_done_tasklet
;
345 static void finish_scattered_hmac(struct crypt_ctl
*crypt
)
347 struct aead_request
*req
= crypt
->data
.aead_req
;
348 struct aead_ctx
*req_ctx
= aead_request_ctx(req
);
349 struct crypto_aead
*tfm
= crypto_aead_reqtfm(req
);
350 int authsize
= crypto_aead_authsize(tfm
);
351 int decryptlen
= req
->assoclen
+ req
->cryptlen
- authsize
;
353 if (req_ctx
->encrypt
) {
354 scatterwalk_map_and_copy(req_ctx
->hmac_virt
,
355 req
->dst
, decryptlen
, authsize
, 1);
357 dma_pool_free(buffer_pool
, req_ctx
->hmac_virt
, crypt
->icv_rev_aes
);
360 static void one_packet(dma_addr_t phys
)
362 struct device
*dev
= &pdev
->dev
;
363 struct crypt_ctl
*crypt
;
367 failed
= phys
& 0x1 ? -EBADMSG
: 0;
369 crypt
= crypt_phys2virt(phys
);
371 switch (crypt
->ctl_flags
& CTL_FLAG_MASK
) {
372 case CTL_FLAG_PERFORM_AEAD
: {
373 struct aead_request
*req
= crypt
->data
.aead_req
;
374 struct aead_ctx
*req_ctx
= aead_request_ctx(req
);
376 free_buf_chain(dev
, req_ctx
->src
, crypt
->src_buf
);
377 free_buf_chain(dev
, req_ctx
->dst
, crypt
->dst_buf
);
378 if (req_ctx
->hmac_virt
) {
379 finish_scattered_hmac(crypt
);
381 req
->base
.complete(&req
->base
, failed
);
384 case CTL_FLAG_PERFORM_ABLK
: {
385 struct ablkcipher_request
*req
= crypt
->data
.ablk_req
;
386 struct ablk_ctx
*req_ctx
= ablkcipher_request_ctx(req
);
389 free_buf_chain(dev
, req_ctx
->dst
, crypt
->dst_buf
);
391 free_buf_chain(dev
, req_ctx
->src
, crypt
->src_buf
);
392 req
->base
.complete(&req
->base
, failed
);
395 case CTL_FLAG_GEN_ICV
:
396 ctx
= crypto_tfm_ctx(crypt
->data
.tfm
);
397 dma_pool_free(ctx_pool
, crypt
->regist_ptr
,
398 crypt
->regist_buf
->phys_addr
);
399 dma_pool_free(buffer_pool
, crypt
->regist_buf
, crypt
->src_buf
);
400 if (atomic_dec_and_test(&ctx
->configuring
))
401 complete(&ctx
->completion
);
403 case CTL_FLAG_GEN_REVAES
:
404 ctx
= crypto_tfm_ctx(crypt
->data
.tfm
);
405 *(u32
*)ctx
->decrypt
.npe_ctx
&= cpu_to_be32(~CIPH_ENCR
);
406 if (atomic_dec_and_test(&ctx
->configuring
))
407 complete(&ctx
->completion
);
412 crypt
->ctl_flags
= CTL_FLAG_UNUSED
;
415 static void irqhandler(void *_unused
)
417 tasklet_schedule(&crypto_done_tasklet
);
420 static void crypto_done_action(unsigned long arg
)
425 dma_addr_t phys
= qmgr_get_entry(RECV_QID
);
430 tasklet_schedule(&crypto_done_tasklet
);
433 static int init_ixp_crypto(struct device
*dev
)
436 u32 msg
[2] = { 0, 0 };
438 if (! ( ~(*IXP4XX_EXP_CFG2
) & (IXP4XX_FEATURE_HASH
|
439 IXP4XX_FEATURE_AES
| IXP4XX_FEATURE_DES
))) {
440 printk(KERN_ERR
"ixp_crypto: No HW crypto available\n");
443 npe_c
= npe_request(NPE_ID
);
447 if (!npe_running(npe_c
)) {
448 ret
= npe_load_firmware(npe_c
, npe_name(npe_c
), dev
);
451 if (npe_recv_message(npe_c
, msg
, "STATUS_MSG"))
454 if (npe_send_message(npe_c
, msg
, "STATUS_MSG"))
457 if (npe_recv_message(npe_c
, msg
, "STATUS_MSG"))
461 switch ((msg
[1]>>16) & 0xff) {
463 printk(KERN_WARNING
"Firmware of %s lacks AES support\n",
472 printk(KERN_ERR
"Firmware of %s lacks crypto support\n",
477 /* buffer_pool will also be used to sometimes store the hmac,
478 * so assure it is large enough
480 BUILD_BUG_ON(SHA1_DIGEST_SIZE
> sizeof(struct buffer_desc
));
481 buffer_pool
= dma_pool_create("buffer", dev
,
482 sizeof(struct buffer_desc
), 32, 0);
487 ctx_pool
= dma_pool_create("context", dev
,
492 ret
= qmgr_request_queue(SEND_QID
, NPE_QLEN_TOTAL
, 0, 0,
493 "ixp_crypto:out", NULL
);
496 ret
= qmgr_request_queue(RECV_QID
, NPE_QLEN
, 0, 0,
497 "ixp_crypto:in", NULL
);
499 qmgr_release_queue(SEND_QID
);
502 qmgr_set_irq(RECV_QID
, QUEUE_IRQ_SRC_NOT_EMPTY
, irqhandler
, NULL
);
503 tasklet_init(&crypto_done_tasklet
, crypto_done_action
, 0);
505 qmgr_enable_irq(RECV_QID
);
509 printk(KERN_ERR
"%s not responding\n", npe_name(npe_c
));
512 dma_pool_destroy(ctx_pool
);
513 dma_pool_destroy(buffer_pool
);
519 static void release_ixp_crypto(struct device
*dev
)
521 qmgr_disable_irq(RECV_QID
);
522 tasklet_kill(&crypto_done_tasklet
);
524 qmgr_release_queue(SEND_QID
);
525 qmgr_release_queue(RECV_QID
);
527 dma_pool_destroy(ctx_pool
);
528 dma_pool_destroy(buffer_pool
);
533 dma_free_coherent(dev
,
534 NPE_QLEN_TOTAL
* sizeof( struct crypt_ctl
),
535 crypt_virt
, crypt_phys
);
539 static void reset_sa_dir(struct ix_sa_dir
*dir
)
541 memset(dir
->npe_ctx
, 0, NPE_CTX_LEN
);
542 dir
->npe_ctx_idx
= 0;
546 static int init_sa_dir(struct ix_sa_dir
*dir
)
548 dir
->npe_ctx
= dma_pool_alloc(ctx_pool
, GFP_KERNEL
, &dir
->npe_ctx_phys
);
556 static void free_sa_dir(struct ix_sa_dir
*dir
)
558 memset(dir
->npe_ctx
, 0, NPE_CTX_LEN
);
559 dma_pool_free(ctx_pool
, dir
->npe_ctx
, dir
->npe_ctx_phys
);
562 static int init_tfm(struct crypto_tfm
*tfm
)
564 struct ixp_ctx
*ctx
= crypto_tfm_ctx(tfm
);
567 atomic_set(&ctx
->configuring
, 0);
568 ret
= init_sa_dir(&ctx
->encrypt
);
571 ret
= init_sa_dir(&ctx
->decrypt
);
573 free_sa_dir(&ctx
->encrypt
);
578 static int init_tfm_ablk(struct crypto_tfm
*tfm
)
580 tfm
->crt_ablkcipher
.reqsize
= sizeof(struct ablk_ctx
);
581 return init_tfm(tfm
);
584 static int init_tfm_aead(struct crypto_aead
*tfm
)
586 crypto_aead_set_reqsize(tfm
, sizeof(struct aead_ctx
));
587 return init_tfm(crypto_aead_tfm(tfm
));
590 static void exit_tfm(struct crypto_tfm
*tfm
)
592 struct ixp_ctx
*ctx
= crypto_tfm_ctx(tfm
);
593 free_sa_dir(&ctx
->encrypt
);
594 free_sa_dir(&ctx
->decrypt
);
597 static void exit_tfm_aead(struct crypto_aead
*tfm
)
599 exit_tfm(crypto_aead_tfm(tfm
));
602 static int register_chain_var(struct crypto_tfm
*tfm
, u8 xpad
, u32 target
,
603 int init_len
, u32 ctx_addr
, const u8
*key
, int key_len
)
605 struct ixp_ctx
*ctx
= crypto_tfm_ctx(tfm
);
606 struct crypt_ctl
*crypt
;
607 struct buffer_desc
*buf
;
610 u32 pad_phys
, buf_phys
;
612 BUILD_BUG_ON(NPE_CTX_LEN
< HMAC_PAD_BLOCKLEN
);
613 pad
= dma_pool_alloc(ctx_pool
, GFP_KERNEL
, &pad_phys
);
616 buf
= dma_pool_alloc(buffer_pool
, GFP_KERNEL
, &buf_phys
);
618 dma_pool_free(ctx_pool
, pad
, pad_phys
);
621 crypt
= get_crypt_desc_emerg();
623 dma_pool_free(ctx_pool
, pad
, pad_phys
);
624 dma_pool_free(buffer_pool
, buf
, buf_phys
);
628 memcpy(pad
, key
, key_len
);
629 memset(pad
+ key_len
, 0, HMAC_PAD_BLOCKLEN
- key_len
);
630 for (i
= 0; i
< HMAC_PAD_BLOCKLEN
; i
++) {
634 crypt
->data
.tfm
= tfm
;
635 crypt
->regist_ptr
= pad
;
636 crypt
->regist_buf
= buf
;
638 crypt
->auth_offs
= 0;
639 crypt
->auth_len
= HMAC_PAD_BLOCKLEN
;
640 crypt
->crypto_ctx
= ctx_addr
;
641 crypt
->src_buf
= buf_phys
;
642 crypt
->icv_rev_aes
= target
;
643 crypt
->mode
= NPE_OP_HASH_GEN_ICV
;
644 crypt
->init_len
= init_len
;
645 crypt
->ctl_flags
|= CTL_FLAG_GEN_ICV
;
648 buf
->buf_len
= HMAC_PAD_BLOCKLEN
;
650 buf
->phys_addr
= pad_phys
;
652 atomic_inc(&ctx
->configuring
);
653 qmgr_put_entry(SEND_QID
, crypt_virt2phys(crypt
));
654 BUG_ON(qmgr_stat_overflow(SEND_QID
));
658 static int setup_auth(struct crypto_tfm
*tfm
, int encrypt
, unsigned authsize
,
659 const u8
*key
, int key_len
, unsigned digest_len
)
661 u32 itarget
, otarget
, npe_ctx_addr
;
662 unsigned char *cinfo
;
663 int init_len
, ret
= 0;
665 struct ix_sa_dir
*dir
;
666 struct ixp_ctx
*ctx
= crypto_tfm_ctx(tfm
);
667 const struct ix_hash_algo
*algo
;
669 dir
= encrypt
? &ctx
->encrypt
: &ctx
->decrypt
;
670 cinfo
= dir
->npe_ctx
+ dir
->npe_ctx_idx
;
673 /* write cfg word to cryptinfo */
674 cfgword
= algo
->cfgword
| ( authsize
<< 6); /* (authsize/4) << 8 */
676 cfgword
^= 0xAA000000; /* change the "byte swap" flags */
678 *(u32
*)cinfo
= cpu_to_be32(cfgword
);
679 cinfo
+= sizeof(cfgword
);
681 /* write ICV to cryptinfo */
682 memcpy(cinfo
, algo
->icv
, digest_len
);
685 itarget
= dir
->npe_ctx_phys
+ dir
->npe_ctx_idx
686 + sizeof(algo
->cfgword
);
687 otarget
= itarget
+ digest_len
;
688 init_len
= cinfo
- (dir
->npe_ctx
+ dir
->npe_ctx_idx
);
689 npe_ctx_addr
= dir
->npe_ctx_phys
+ dir
->npe_ctx_idx
;
691 dir
->npe_ctx_idx
+= init_len
;
692 dir
->npe_mode
|= NPE_OP_HASH_ENABLE
;
695 dir
->npe_mode
|= NPE_OP_HASH_VERIFY
;
697 ret
= register_chain_var(tfm
, HMAC_OPAD_VALUE
, otarget
,
698 init_len
, npe_ctx_addr
, key
, key_len
);
701 return register_chain_var(tfm
, HMAC_IPAD_VALUE
, itarget
,
702 init_len
, npe_ctx_addr
, key
, key_len
);
705 static int gen_rev_aes_key(struct crypto_tfm
*tfm
)
707 struct crypt_ctl
*crypt
;
708 struct ixp_ctx
*ctx
= crypto_tfm_ctx(tfm
);
709 struct ix_sa_dir
*dir
= &ctx
->decrypt
;
711 crypt
= get_crypt_desc_emerg();
715 *(u32
*)dir
->npe_ctx
|= cpu_to_be32(CIPH_ENCR
);
717 crypt
->data
.tfm
= tfm
;
718 crypt
->crypt_offs
= 0;
719 crypt
->crypt_len
= AES_BLOCK128
;
721 crypt
->crypto_ctx
= dir
->npe_ctx_phys
;
722 crypt
->icv_rev_aes
= dir
->npe_ctx_phys
+ sizeof(u32
);
723 crypt
->mode
= NPE_OP_ENC_GEN_KEY
;
724 crypt
->init_len
= dir
->npe_ctx_idx
;
725 crypt
->ctl_flags
|= CTL_FLAG_GEN_REVAES
;
727 atomic_inc(&ctx
->configuring
);
728 qmgr_put_entry(SEND_QID
, crypt_virt2phys(crypt
));
729 BUG_ON(qmgr_stat_overflow(SEND_QID
));
733 static int setup_cipher(struct crypto_tfm
*tfm
, int encrypt
,
734 const u8
*key
, int key_len
)
739 struct ix_sa_dir
*dir
;
740 struct ixp_ctx
*ctx
= crypto_tfm_ctx(tfm
);
741 u32
*flags
= &tfm
->crt_flags
;
743 dir
= encrypt
? &ctx
->encrypt
: &ctx
->decrypt
;
744 cinfo
= dir
->npe_ctx
;
747 cipher_cfg
= cipher_cfg_enc(tfm
);
748 dir
->npe_mode
|= NPE_OP_CRYPT_ENCRYPT
;
750 cipher_cfg
= cipher_cfg_dec(tfm
);
752 if (cipher_cfg
& MOD_AES
) {
754 case 16: keylen_cfg
= MOD_AES128
; break;
755 case 24: keylen_cfg
= MOD_AES192
; break;
756 case 32: keylen_cfg
= MOD_AES256
; break;
758 *flags
|= CRYPTO_TFM_RES_BAD_KEY_LEN
;
761 cipher_cfg
|= keylen_cfg
;
762 } else if (cipher_cfg
& MOD_3DES
) {
763 const u32
*K
= (const u32
*)key
;
764 if (unlikely(!((K
[0] ^ K
[2]) | (K
[1] ^ K
[3])) ||
765 !((K
[2] ^ K
[4]) | (K
[3] ^ K
[5]))))
767 *flags
|= CRYPTO_TFM_RES_BAD_KEY_SCHED
;
771 u32 tmp
[DES_EXPKEY_WORDS
];
772 if (des_ekey(tmp
, key
) == 0) {
773 *flags
|= CRYPTO_TFM_RES_WEAK_KEY
;
776 /* write cfg word to cryptinfo */
777 *(u32
*)cinfo
= cpu_to_be32(cipher_cfg
);
778 cinfo
+= sizeof(cipher_cfg
);
780 /* write cipher key to cryptinfo */
781 memcpy(cinfo
, key
, key_len
);
782 /* NPE wants keylen set to DES3_EDE_KEY_SIZE even for single DES */
783 if (key_len
< DES3_EDE_KEY_SIZE
&& !(cipher_cfg
& MOD_AES
)) {
784 memset(cinfo
+ key_len
, 0, DES3_EDE_KEY_SIZE
-key_len
);
785 key_len
= DES3_EDE_KEY_SIZE
;
787 dir
->npe_ctx_idx
= sizeof(cipher_cfg
) + key_len
;
788 dir
->npe_mode
|= NPE_OP_CRYPT_ENABLE
;
789 if ((cipher_cfg
& MOD_AES
) && !encrypt
) {
790 return gen_rev_aes_key(tfm
);
795 static struct buffer_desc
*chainup_buffers(struct device
*dev
,
796 struct scatterlist
*sg
, unsigned nbytes
,
797 struct buffer_desc
*buf
, gfp_t flags
,
798 enum dma_data_direction dir
)
800 for (; nbytes
> 0; sg
= sg_next(sg
)) {
801 unsigned len
= min(nbytes
, sg
->length
);
802 struct buffer_desc
*next_buf
;
808 next_buf
= dma_pool_alloc(buffer_pool
, flags
, &next_buf_phys
);
813 sg_dma_address(sg
) = dma_map_single(dev
, ptr
, len
, dir
);
814 buf
->next
= next_buf
;
815 buf
->phys_next
= next_buf_phys
;
818 buf
->phys_addr
= sg_dma_address(sg
);
827 static int ablk_setkey(struct crypto_ablkcipher
*tfm
, const u8
*key
,
828 unsigned int key_len
)
830 struct ixp_ctx
*ctx
= crypto_ablkcipher_ctx(tfm
);
831 u32
*flags
= &tfm
->base
.crt_flags
;
834 init_completion(&ctx
->completion
);
835 atomic_inc(&ctx
->configuring
);
837 reset_sa_dir(&ctx
->encrypt
);
838 reset_sa_dir(&ctx
->decrypt
);
840 ctx
->encrypt
.npe_mode
= NPE_OP_HMAC_DISABLE
;
841 ctx
->decrypt
.npe_mode
= NPE_OP_HMAC_DISABLE
;
843 ret
= setup_cipher(&tfm
->base
, 0, key
, key_len
);
846 ret
= setup_cipher(&tfm
->base
, 1, key
, key_len
);
850 if (*flags
& CRYPTO_TFM_RES_WEAK_KEY
) {
851 if (*flags
& CRYPTO_TFM_REQ_WEAK_KEY
) {
854 *flags
&= ~CRYPTO_TFM_RES_WEAK_KEY
;
858 if (!atomic_dec_and_test(&ctx
->configuring
))
859 wait_for_completion(&ctx
->completion
);
863 static int ablk_rfc3686_setkey(struct crypto_ablkcipher
*tfm
, const u8
*key
,
864 unsigned int key_len
)
866 struct ixp_ctx
*ctx
= crypto_ablkcipher_ctx(tfm
);
868 /* the nonce is stored in bytes at end of key */
869 if (key_len
< CTR_RFC3686_NONCE_SIZE
)
872 memcpy(ctx
->nonce
, key
+ (key_len
- CTR_RFC3686_NONCE_SIZE
),
873 CTR_RFC3686_NONCE_SIZE
);
875 key_len
-= CTR_RFC3686_NONCE_SIZE
;
876 return ablk_setkey(tfm
, key
, key_len
);
879 static int ablk_perform(struct ablkcipher_request
*req
, int encrypt
)
881 struct crypto_ablkcipher
*tfm
= crypto_ablkcipher_reqtfm(req
);
882 struct ixp_ctx
*ctx
= crypto_ablkcipher_ctx(tfm
);
883 unsigned ivsize
= crypto_ablkcipher_ivsize(tfm
);
884 struct ix_sa_dir
*dir
;
885 struct crypt_ctl
*crypt
;
886 unsigned int nbytes
= req
->nbytes
;
887 enum dma_data_direction src_direction
= DMA_BIDIRECTIONAL
;
888 struct ablk_ctx
*req_ctx
= ablkcipher_request_ctx(req
);
889 struct buffer_desc src_hook
;
890 struct device
*dev
= &pdev
->dev
;
891 gfp_t flags
= req
->base
.flags
& CRYPTO_TFM_REQ_MAY_SLEEP
?
892 GFP_KERNEL
: GFP_ATOMIC
;
894 if (qmgr_stat_full(SEND_QID
))
896 if (atomic_read(&ctx
->configuring
))
899 dir
= encrypt
? &ctx
->encrypt
: &ctx
->decrypt
;
901 crypt
= get_crypt_desc();
905 crypt
->data
.ablk_req
= req
;
906 crypt
->crypto_ctx
= dir
->npe_ctx_phys
;
907 crypt
->mode
= dir
->npe_mode
;
908 crypt
->init_len
= dir
->npe_ctx_idx
;
910 crypt
->crypt_offs
= 0;
911 crypt
->crypt_len
= nbytes
;
913 BUG_ON(ivsize
&& !req
->info
);
914 memcpy(crypt
->iv
, req
->info
, ivsize
);
915 if (req
->src
!= req
->dst
) {
916 struct buffer_desc dst_hook
;
917 crypt
->mode
|= NPE_OP_NOT_IN_PLACE
;
918 /* This was never tested by Intel
919 * for more than one dst buffer, I think. */
921 if (!chainup_buffers(dev
, req
->dst
, nbytes
, &dst_hook
,
922 flags
, DMA_FROM_DEVICE
))
924 src_direction
= DMA_TO_DEVICE
;
925 req_ctx
->dst
= dst_hook
.next
;
926 crypt
->dst_buf
= dst_hook
.phys_next
;
931 if (!chainup_buffers(dev
, req
->src
, nbytes
, &src_hook
,
932 flags
, src_direction
))
935 req_ctx
->src
= src_hook
.next
;
936 crypt
->src_buf
= src_hook
.phys_next
;
937 crypt
->ctl_flags
|= CTL_FLAG_PERFORM_ABLK
;
938 qmgr_put_entry(SEND_QID
, crypt_virt2phys(crypt
));
939 BUG_ON(qmgr_stat_overflow(SEND_QID
));
943 free_buf_chain(dev
, req_ctx
->src
, crypt
->src_buf
);
945 if (req
->src
!= req
->dst
) {
946 free_buf_chain(dev
, req_ctx
->dst
, crypt
->dst_buf
);
948 crypt
->ctl_flags
= CTL_FLAG_UNUSED
;
952 static int ablk_encrypt(struct ablkcipher_request
*req
)
954 return ablk_perform(req
, 1);
957 static int ablk_decrypt(struct ablkcipher_request
*req
)
959 return ablk_perform(req
, 0);
962 static int ablk_rfc3686_crypt(struct ablkcipher_request
*req
)
964 struct crypto_ablkcipher
*tfm
= crypto_ablkcipher_reqtfm(req
);
965 struct ixp_ctx
*ctx
= crypto_ablkcipher_ctx(tfm
);
966 u8 iv
[CTR_RFC3686_BLOCK_SIZE
];
967 u8
*info
= req
->info
;
970 /* set up counter block */
971 memcpy(iv
, ctx
->nonce
, CTR_RFC3686_NONCE_SIZE
);
972 memcpy(iv
+ CTR_RFC3686_NONCE_SIZE
, info
, CTR_RFC3686_IV_SIZE
);
974 /* initialize counter portion of counter block */
975 *(__be32
*)(iv
+ CTR_RFC3686_NONCE_SIZE
+ CTR_RFC3686_IV_SIZE
) =
979 ret
= ablk_perform(req
, 1);
984 static int aead_perform(struct aead_request
*req
, int encrypt
,
985 int cryptoffset
, int eff_cryptlen
, u8
*iv
)
987 struct crypto_aead
*tfm
= crypto_aead_reqtfm(req
);
988 struct ixp_ctx
*ctx
= crypto_aead_ctx(tfm
);
989 unsigned ivsize
= crypto_aead_ivsize(tfm
);
990 unsigned authsize
= crypto_aead_authsize(tfm
);
991 struct ix_sa_dir
*dir
;
992 struct crypt_ctl
*crypt
;
993 unsigned int cryptlen
;
994 struct buffer_desc
*buf
, src_hook
;
995 struct aead_ctx
*req_ctx
= aead_request_ctx(req
);
996 struct device
*dev
= &pdev
->dev
;
997 gfp_t flags
= req
->base
.flags
& CRYPTO_TFM_REQ_MAY_SLEEP
?
998 GFP_KERNEL
: GFP_ATOMIC
;
999 enum dma_data_direction src_direction
= DMA_BIDIRECTIONAL
;
1000 unsigned int lastlen
;
1002 if (qmgr_stat_full(SEND_QID
))
1004 if (atomic_read(&ctx
->configuring
))
1008 dir
= &ctx
->encrypt
;
1009 cryptlen
= req
->cryptlen
;
1011 dir
= &ctx
->decrypt
;
1012 /* req->cryptlen includes the authsize when decrypting */
1013 cryptlen
= req
->cryptlen
-authsize
;
1014 eff_cryptlen
-= authsize
;
1016 crypt
= get_crypt_desc();
1020 crypt
->data
.aead_req
= req
;
1021 crypt
->crypto_ctx
= dir
->npe_ctx_phys
;
1022 crypt
->mode
= dir
->npe_mode
;
1023 crypt
->init_len
= dir
->npe_ctx_idx
;
1025 crypt
->crypt_offs
= cryptoffset
;
1026 crypt
->crypt_len
= eff_cryptlen
;
1028 crypt
->auth_offs
= 0;
1029 crypt
->auth_len
= req
->assoclen
+ cryptlen
;
1030 BUG_ON(ivsize
&& !req
->iv
);
1031 memcpy(crypt
->iv
, req
->iv
, ivsize
);
1033 buf
= chainup_buffers(dev
, req
->src
, crypt
->auth_len
,
1034 &src_hook
, flags
, src_direction
);
1035 req_ctx
->src
= src_hook
.next
;
1036 crypt
->src_buf
= src_hook
.phys_next
;
1040 lastlen
= buf
->buf_len
;
1041 if (lastlen
>= authsize
)
1042 crypt
->icv_rev_aes
= buf
->phys_addr
+
1043 buf
->buf_len
- authsize
;
1045 req_ctx
->dst
= NULL
;
1047 if (req
->src
!= req
->dst
) {
1048 struct buffer_desc dst_hook
;
1050 crypt
->mode
|= NPE_OP_NOT_IN_PLACE
;
1051 src_direction
= DMA_TO_DEVICE
;
1053 buf
= chainup_buffers(dev
, req
->dst
, crypt
->auth_len
,
1054 &dst_hook
, flags
, DMA_FROM_DEVICE
);
1055 req_ctx
->dst
= dst_hook
.next
;
1056 crypt
->dst_buf
= dst_hook
.phys_next
;
1062 lastlen
= buf
->buf_len
;
1063 if (lastlen
>= authsize
)
1064 crypt
->icv_rev_aes
= buf
->phys_addr
+
1065 buf
->buf_len
- authsize
;
1069 if (unlikely(lastlen
< authsize
)) {
1070 /* The 12 hmac bytes are scattered,
1071 * we need to copy them into a safe buffer */
1072 req_ctx
->hmac_virt
= dma_pool_alloc(buffer_pool
, flags
,
1073 &crypt
->icv_rev_aes
);
1074 if (unlikely(!req_ctx
->hmac_virt
))
1077 scatterwalk_map_and_copy(req_ctx
->hmac_virt
,
1078 req
->src
, cryptlen
, authsize
, 0);
1080 req_ctx
->encrypt
= encrypt
;
1082 req_ctx
->hmac_virt
= NULL
;
1085 crypt
->ctl_flags
|= CTL_FLAG_PERFORM_AEAD
;
1086 qmgr_put_entry(SEND_QID
, crypt_virt2phys(crypt
));
1087 BUG_ON(qmgr_stat_overflow(SEND_QID
));
1088 return -EINPROGRESS
;
1091 free_buf_chain(dev
, req_ctx
->dst
, crypt
->dst_buf
);
1093 free_buf_chain(dev
, req_ctx
->src
, crypt
->src_buf
);
1094 crypt
->ctl_flags
= CTL_FLAG_UNUSED
;
1098 static int aead_setup(struct crypto_aead
*tfm
, unsigned int authsize
)
1100 struct ixp_ctx
*ctx
= crypto_aead_ctx(tfm
);
1101 u32
*flags
= &tfm
->base
.crt_flags
;
1102 unsigned digest_len
= crypto_aead_maxauthsize(tfm
);
1105 if (!ctx
->enckey_len
&& !ctx
->authkey_len
)
1107 init_completion(&ctx
->completion
);
1108 atomic_inc(&ctx
->configuring
);
1110 reset_sa_dir(&ctx
->encrypt
);
1111 reset_sa_dir(&ctx
->decrypt
);
1113 ret
= setup_cipher(&tfm
->base
, 0, ctx
->enckey
, ctx
->enckey_len
);
1116 ret
= setup_cipher(&tfm
->base
, 1, ctx
->enckey
, ctx
->enckey_len
);
1119 ret
= setup_auth(&tfm
->base
, 0, authsize
, ctx
->authkey
,
1120 ctx
->authkey_len
, digest_len
);
1123 ret
= setup_auth(&tfm
->base
, 1, authsize
, ctx
->authkey
,
1124 ctx
->authkey_len
, digest_len
);
1128 if (*flags
& CRYPTO_TFM_RES_WEAK_KEY
) {
1129 if (*flags
& CRYPTO_TFM_REQ_WEAK_KEY
) {
1133 *flags
&= ~CRYPTO_TFM_RES_WEAK_KEY
;
1137 if (!atomic_dec_and_test(&ctx
->configuring
))
1138 wait_for_completion(&ctx
->completion
);
1142 static int aead_setauthsize(struct crypto_aead
*tfm
, unsigned int authsize
)
1144 int max
= crypto_aead_maxauthsize(tfm
) >> 2;
1146 if ((authsize
>>2) < 1 || (authsize
>>2) > max
|| (authsize
& 3))
1148 return aead_setup(tfm
, authsize
);
1151 static int aead_setkey(struct crypto_aead
*tfm
, const u8
*key
,
1152 unsigned int keylen
)
1154 struct ixp_ctx
*ctx
= crypto_aead_ctx(tfm
);
1155 struct crypto_authenc_keys keys
;
1157 if (crypto_authenc_extractkeys(&keys
, key
, keylen
) != 0)
1160 if (keys
.authkeylen
> sizeof(ctx
->authkey
))
1163 if (keys
.enckeylen
> sizeof(ctx
->enckey
))
1166 memcpy(ctx
->authkey
, keys
.authkey
, keys
.authkeylen
);
1167 memcpy(ctx
->enckey
, keys
.enckey
, keys
.enckeylen
);
1168 ctx
->authkey_len
= keys
.authkeylen
;
1169 ctx
->enckey_len
= keys
.enckeylen
;
1171 return aead_setup(tfm
, crypto_aead_authsize(tfm
));
1173 crypto_aead_set_flags(tfm
, CRYPTO_TFM_RES_BAD_KEY_LEN
);
1177 static int aead_encrypt(struct aead_request
*req
)
1179 return aead_perform(req
, 1, req
->assoclen
, req
->cryptlen
, req
->iv
);
1182 static int aead_decrypt(struct aead_request
*req
)
1184 return aead_perform(req
, 0, req
->assoclen
, req
->cryptlen
, req
->iv
);
1187 static struct ixp_alg ixp4xx_algos
[] = {
1190 .cra_name
= "cbc(des)",
1191 .cra_blocksize
= DES_BLOCK_SIZE
,
1192 .cra_u
= { .ablkcipher
= {
1193 .min_keysize
= DES_KEY_SIZE
,
1194 .max_keysize
= DES_KEY_SIZE
,
1195 .ivsize
= DES_BLOCK_SIZE
,
1200 .cfg_enc
= CIPH_ENCR
| MOD_DES
| MOD_CBC_ENC
| KEYLEN_192
,
1201 .cfg_dec
= CIPH_DECR
| MOD_DES
| MOD_CBC_DEC
| KEYLEN_192
,
1205 .cra_name
= "ecb(des)",
1206 .cra_blocksize
= DES_BLOCK_SIZE
,
1207 .cra_u
= { .ablkcipher
= {
1208 .min_keysize
= DES_KEY_SIZE
,
1209 .max_keysize
= DES_KEY_SIZE
,
1213 .cfg_enc
= CIPH_ENCR
| MOD_DES
| MOD_ECB
| KEYLEN_192
,
1214 .cfg_dec
= CIPH_DECR
| MOD_DES
| MOD_ECB
| KEYLEN_192
,
1217 .cra_name
= "cbc(des3_ede)",
1218 .cra_blocksize
= DES3_EDE_BLOCK_SIZE
,
1219 .cra_u
= { .ablkcipher
= {
1220 .min_keysize
= DES3_EDE_KEY_SIZE
,
1221 .max_keysize
= DES3_EDE_KEY_SIZE
,
1222 .ivsize
= DES3_EDE_BLOCK_SIZE
,
1227 .cfg_enc
= CIPH_ENCR
| MOD_3DES
| MOD_CBC_ENC
| KEYLEN_192
,
1228 .cfg_dec
= CIPH_DECR
| MOD_3DES
| MOD_CBC_DEC
| KEYLEN_192
,
1231 .cra_name
= "ecb(des3_ede)",
1232 .cra_blocksize
= DES3_EDE_BLOCK_SIZE
,
1233 .cra_u
= { .ablkcipher
= {
1234 .min_keysize
= DES3_EDE_KEY_SIZE
,
1235 .max_keysize
= DES3_EDE_KEY_SIZE
,
1239 .cfg_enc
= CIPH_ENCR
| MOD_3DES
| MOD_ECB
| KEYLEN_192
,
1240 .cfg_dec
= CIPH_DECR
| MOD_3DES
| MOD_ECB
| KEYLEN_192
,
1243 .cra_name
= "cbc(aes)",
1244 .cra_blocksize
= AES_BLOCK_SIZE
,
1245 .cra_u
= { .ablkcipher
= {
1246 .min_keysize
= AES_MIN_KEY_SIZE
,
1247 .max_keysize
= AES_MAX_KEY_SIZE
,
1248 .ivsize
= AES_BLOCK_SIZE
,
1253 .cfg_enc
= CIPH_ENCR
| MOD_AES
| MOD_CBC_ENC
,
1254 .cfg_dec
= CIPH_DECR
| MOD_AES
| MOD_CBC_DEC
,
1257 .cra_name
= "ecb(aes)",
1258 .cra_blocksize
= AES_BLOCK_SIZE
,
1259 .cra_u
= { .ablkcipher
= {
1260 .min_keysize
= AES_MIN_KEY_SIZE
,
1261 .max_keysize
= AES_MAX_KEY_SIZE
,
1265 .cfg_enc
= CIPH_ENCR
| MOD_AES
| MOD_ECB
,
1266 .cfg_dec
= CIPH_DECR
| MOD_AES
| MOD_ECB
,
1269 .cra_name
= "ctr(aes)",
1270 .cra_blocksize
= AES_BLOCK_SIZE
,
1271 .cra_u
= { .ablkcipher
= {
1272 .min_keysize
= AES_MIN_KEY_SIZE
,
1273 .max_keysize
= AES_MAX_KEY_SIZE
,
1274 .ivsize
= AES_BLOCK_SIZE
,
1279 .cfg_enc
= CIPH_ENCR
| MOD_AES
| MOD_CTR
,
1280 .cfg_dec
= CIPH_ENCR
| MOD_AES
| MOD_CTR
,
1283 .cra_name
= "rfc3686(ctr(aes))",
1284 .cra_blocksize
= AES_BLOCK_SIZE
,
1285 .cra_u
= { .ablkcipher
= {
1286 .min_keysize
= AES_MIN_KEY_SIZE
,
1287 .max_keysize
= AES_MAX_KEY_SIZE
,
1288 .ivsize
= AES_BLOCK_SIZE
,
1290 .setkey
= ablk_rfc3686_setkey
,
1291 .encrypt
= ablk_rfc3686_crypt
,
1292 .decrypt
= ablk_rfc3686_crypt
}
1295 .cfg_enc
= CIPH_ENCR
| MOD_AES
| MOD_CTR
,
1296 .cfg_dec
= CIPH_ENCR
| MOD_AES
| MOD_CTR
,
1299 static struct ixp_aead_alg ixp4xx_aeads
[] = {
1303 .cra_name
= "authenc(hmac(md5),cbc(des))",
1304 .cra_blocksize
= DES_BLOCK_SIZE
,
1306 .ivsize
= DES_BLOCK_SIZE
,
1307 .maxauthsize
= MD5_DIGEST_SIZE
,
1309 .hash
= &hash_alg_md5
,
1310 .cfg_enc
= CIPH_ENCR
| MOD_DES
| MOD_CBC_ENC
| KEYLEN_192
,
1311 .cfg_dec
= CIPH_DECR
| MOD_DES
| MOD_CBC_DEC
| KEYLEN_192
,
1315 .cra_name
= "authenc(hmac(md5),cbc(des3_ede))",
1316 .cra_blocksize
= DES3_EDE_BLOCK_SIZE
,
1318 .ivsize
= DES3_EDE_BLOCK_SIZE
,
1319 .maxauthsize
= MD5_DIGEST_SIZE
,
1321 .hash
= &hash_alg_md5
,
1322 .cfg_enc
= CIPH_ENCR
| MOD_3DES
| MOD_CBC_ENC
| KEYLEN_192
,
1323 .cfg_dec
= CIPH_DECR
| MOD_3DES
| MOD_CBC_DEC
| KEYLEN_192
,
1327 .cra_name
= "authenc(hmac(sha1),cbc(des))",
1328 .cra_blocksize
= DES_BLOCK_SIZE
,
1330 .ivsize
= DES_BLOCK_SIZE
,
1331 .maxauthsize
= SHA1_DIGEST_SIZE
,
1333 .hash
= &hash_alg_sha1
,
1334 .cfg_enc
= CIPH_ENCR
| MOD_DES
| MOD_CBC_ENC
| KEYLEN_192
,
1335 .cfg_dec
= CIPH_DECR
| MOD_DES
| MOD_CBC_DEC
| KEYLEN_192
,
1339 .cra_name
= "authenc(hmac(sha1),cbc(des3_ede))",
1340 .cra_blocksize
= DES3_EDE_BLOCK_SIZE
,
1342 .ivsize
= DES3_EDE_BLOCK_SIZE
,
1343 .maxauthsize
= SHA1_DIGEST_SIZE
,
1345 .hash
= &hash_alg_sha1
,
1346 .cfg_enc
= CIPH_ENCR
| MOD_3DES
| MOD_CBC_ENC
| KEYLEN_192
,
1347 .cfg_dec
= CIPH_DECR
| MOD_3DES
| MOD_CBC_DEC
| KEYLEN_192
,
1351 .cra_name
= "authenc(hmac(md5),cbc(aes))",
1352 .cra_blocksize
= AES_BLOCK_SIZE
,
1354 .ivsize
= AES_BLOCK_SIZE
,
1355 .maxauthsize
= MD5_DIGEST_SIZE
,
1357 .hash
= &hash_alg_md5
,
1358 .cfg_enc
= CIPH_ENCR
| MOD_AES
| MOD_CBC_ENC
,
1359 .cfg_dec
= CIPH_DECR
| MOD_AES
| MOD_CBC_DEC
,
1363 .cra_name
= "authenc(hmac(sha1),cbc(aes))",
1364 .cra_blocksize
= AES_BLOCK_SIZE
,
1366 .ivsize
= AES_BLOCK_SIZE
,
1367 .maxauthsize
= SHA1_DIGEST_SIZE
,
1369 .hash
= &hash_alg_sha1
,
1370 .cfg_enc
= CIPH_ENCR
| MOD_AES
| MOD_CBC_ENC
,
1371 .cfg_dec
= CIPH_DECR
| MOD_AES
| MOD_CBC_DEC
,
1374 #define IXP_POSTFIX "-ixp4xx"
1376 static const struct platform_device_info ixp_dev_info __initdata
= {
1377 .name
= DRIVER_NAME
,
1379 .dma_mask
= DMA_BIT_MASK(32),
1382 static int __init
ixp_module_init(void)
1384 int num
= ARRAY_SIZE(ixp4xx_algos
);
1387 pdev
= platform_device_register_full(&ixp_dev_info
);
1389 return PTR_ERR(pdev
);
1391 spin_lock_init(&desc_lock
);
1392 spin_lock_init(&emerg_lock
);
1394 err
= init_ixp_crypto(&pdev
->dev
);
1396 platform_device_unregister(pdev
);
1399 for (i
=0; i
< num
; i
++) {
1400 struct crypto_alg
*cra
= &ixp4xx_algos
[i
].crypto
;
1402 if (snprintf(cra
->cra_driver_name
, CRYPTO_MAX_ALG_NAME
,
1403 "%s"IXP_POSTFIX
, cra
->cra_name
) >=
1404 CRYPTO_MAX_ALG_NAME
)
1408 if (!support_aes
&& (ixp4xx_algos
[i
].cfg_enc
& MOD_AES
)) {
1413 cra
->cra_type
= &crypto_ablkcipher_type
;
1414 cra
->cra_flags
= CRYPTO_ALG_TYPE_ABLKCIPHER
|
1415 CRYPTO_ALG_KERN_DRIVER_ONLY
|
1417 if (!cra
->cra_ablkcipher
.setkey
)
1418 cra
->cra_ablkcipher
.setkey
= ablk_setkey
;
1419 if (!cra
->cra_ablkcipher
.encrypt
)
1420 cra
->cra_ablkcipher
.encrypt
= ablk_encrypt
;
1421 if (!cra
->cra_ablkcipher
.decrypt
)
1422 cra
->cra_ablkcipher
.decrypt
= ablk_decrypt
;
1423 cra
->cra_init
= init_tfm_ablk
;
1425 cra
->cra_ctxsize
= sizeof(struct ixp_ctx
);
1426 cra
->cra_module
= THIS_MODULE
;
1427 cra
->cra_alignmask
= 3;
1428 cra
->cra_priority
= 300;
1429 cra
->cra_exit
= exit_tfm
;
1430 if (crypto_register_alg(cra
))
1431 printk(KERN_ERR
"Failed to register '%s'\n",
1434 ixp4xx_algos
[i
].registered
= 1;
1437 for (i
= 0; i
< ARRAY_SIZE(ixp4xx_aeads
); i
++) {
1438 struct aead_alg
*cra
= &ixp4xx_aeads
[i
].crypto
;
1440 if (snprintf(cra
->base
.cra_driver_name
, CRYPTO_MAX_ALG_NAME
,
1441 "%s"IXP_POSTFIX
, cra
->base
.cra_name
) >=
1442 CRYPTO_MAX_ALG_NAME
)
1444 if (!support_aes
&& (ixp4xx_algos
[i
].cfg_enc
& MOD_AES
))
1448 cra
->base
.cra_flags
= CRYPTO_ALG_KERN_DRIVER_ONLY
|
1450 cra
->setkey
= aead_setkey
;
1451 cra
->setauthsize
= aead_setauthsize
;
1452 cra
->encrypt
= aead_encrypt
;
1453 cra
->decrypt
= aead_decrypt
;
1454 cra
->init
= init_tfm_aead
;
1455 cra
->exit
= exit_tfm_aead
;
1457 cra
->base
.cra_ctxsize
= sizeof(struct ixp_ctx
);
1458 cra
->base
.cra_module
= THIS_MODULE
;
1459 cra
->base
.cra_alignmask
= 3;
1460 cra
->base
.cra_priority
= 300;
1462 if (crypto_register_aead(cra
))
1463 printk(KERN_ERR
"Failed to register '%s'\n",
1464 cra
->base
.cra_driver_name
);
1466 ixp4xx_aeads
[i
].registered
= 1;
1471 static void __exit
ixp_module_exit(void)
1473 int num
= ARRAY_SIZE(ixp4xx_algos
);
1476 for (i
= 0; i
< ARRAY_SIZE(ixp4xx_aeads
); i
++) {
1477 if (ixp4xx_aeads
[i
].registered
)
1478 crypto_unregister_aead(&ixp4xx_aeads
[i
].crypto
);
1481 for (i
=0; i
< num
; i
++) {
1482 if (ixp4xx_algos
[i
].registered
)
1483 crypto_unregister_alg(&ixp4xx_algos
[i
].crypto
);
1485 release_ixp_crypto(&pdev
->dev
);
1486 platform_device_unregister(pdev
);
1489 module_init(ixp_module_init
);
1490 module_exit(ixp_module_exit
);
1492 MODULE_LICENSE("GPL");
1493 MODULE_AUTHOR("Christian Hohnstaedt <chohnstaedt@innominate.com>");
1494 MODULE_DESCRIPTION("IXP4xx hardware crypto");