HIFN 795x driver.
Subsystems (3)
PATCH 1/1 HIFN 795x driver.
Hi.
This is a driver for HIFN 795x crypto accelerator chips.
A short changelog for this release:
* implemented misalignment handling in async hardware
It passed all tests for AES, DES and DES3_EDE except weak test for DES, since hardware can not determine weak keys.
Consider for inclusion.
Thanks.
drivers/crypto/Kconfig +10 -0
@@ -88,4 +88,14 @@ config ZCRYPT_MONOLITHIC that contains all parts of the crypto device driver (ap bus, request router and all the card drivers). +config CRYPTO_DEV_HIFN_795X + tristate "Driver HIFN 795x crypto accelerator chips" + select CRYPTO_ALGAPI + select CRYPTO_ABLKCIPHER + select CRYPTO_BLKCIPHER + help + This option allows you to have support for HIFN 795x crypto adapters. + + + endif # CRYPTO_HW
drivers/crypto/Makefile +1 -0
@@ -1,3 +1,4 @@ obj-$(CONFIG_CRYPTO_DEV_PADLOCK_AES) += padlock-aes.o obj-$(CONFIG_CRYPTO_DEV_PADLOCK_SHA) += padlock-sha.o obj-$(CONFIG_CRYPTO_DEV_GEODE) += geode-aes.o +obj-$(CONFIG_CRYPTO_DEV_HIFN_795X) += hifn_795x.o
drivers/crypto/hifn_795x.c new file +2624 -0
2,624 lines not on this page · raw message
Signature · 1 line
Evgeniy Polyakov
Herbert Xu
maintainerQuoted 3 lines · Evgeniy Polyakov
It passed all tests for AES, DES and
DES3_EDEexcept weak test for DES, since hardware can not determine weak keys.
Patch applied. Thanks Evgeniy!
BTW, we should change it so that the DES algorithm's setkey function uses the same weak-key test as used by the generic DES code.
Oh I had to apply the following fix-up in order for it to build against cryptodev-2.6.
Cheers,
Signature · 5 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--arch/s390/crypto/sha1_s390.c +0 -0
arch/s390/crypto/sha256_s390.c +0 -0
crypto/sha1_generic.c +0 -0
crypto/sha256_generic.c +0 -0
crypto/sha512.c +0 -0
drivers/crypto/hifn_795x.c +1 -3
@@ -1945,11 +1945,10 @@ static int hifn_handle_req(struct ablkcipher_request *req) err =hifn_setup_session (req);if (err == -EAGAIN ) { -struct crypto_ablkcipher *tfm =crypto_ablkcipher_reqtfm (req);unsigned long flags;spin_lock_irqsave (&dev->lock, flags); - err =ablkcipher_enqueue_request (crypto_ablkcipher_alg (tfm), req); + err =ablkcipher_enqueue_request (&dev->queue, req);spin_unlock_irqrestore (&dev->lock, flags); }
@@ -2359,7 +2358,6 @@ static int hifn_alg_alloc(struct hifn_device *dev, struct hifn_alg_template *t) alg->alg.cra_module =THIS_MODULE ; alg->alg.cra_u.ablkcipher = t->ablkcipher; alg->alg.cra_init = hifn_cra_init; - alg->alg.cra_ablkcipher.queue = &dev->queue; alg->dev = dev;
drivers/crypto/padlock-sha.c +0 -0
include/crypto/sha.h +0 -0
include/linux/crypto.h +0 -0
Quoted 6 lines · Herbert Xu
Quoted 3 lines · Evgeniy Polyakov
It passed all tests for AES, DES and
DES3_EDEexcept weak test for DES, since hardware can not determine weak keys.Patch applied. Thanks Evgeniy!
Thanks!
Quoted 3 lines
BTW, we should change it so that the DES algorithm's setkey function uses the same weak-key test as used by the generic DES code.
Attached patch fixes that with following tcrypt output:
[71705.695117] test 5 (64 bit key): [71705.698462] setkey() failed flags=100100 [71705.702499] 015744256a5ed31d [71705.705703] pass
crypto/des.c +5 -4
@@ -634,7 +634,7 @@ static const u32 S8[64] = {* Choice 1 has operated on the key. * */ -static unsigned long ekey (u32 *pe,const u8 *k) +unsigned long des_ekey (u32 *pe,const u8 *k) {/* K&R: long is at least 32 bits */ unsigned long a, b, c, d, w;
@@ -709,6 +709,7 @@ static unsigned long ekey(u32 *pe, const u8 *k)/* Zero if weak key */ return w; } +EXPORT_SYMBOL_GPL (des_ekey);/* * Decryption key expansion
@@ -792,7 +793,7 @@ static int des_setkey(struct crypto_tfm *tfm, const u8 *key,int ret;/* Expand to tmp */ - ret =ekey (tmp, key); + ret =des_ekey (tmp, key);if (unlikely (ret ==0 ) && (*flags &CRYPTO_TFM_REQ_WEAK_KEY )) { *flags |=CRYPTO_TFM_RES_WEAK_KEY ;
@@ -879,9 +880,9 @@ static int des3_ede_setkey(struct crypto_tfm *tfm, const u8 *key,return -EINVAL ; } -ekey (expkey, key); expkey +=DES_EXPKEY_WORDS ; key +=DES_KEY_SIZE ; +des_ekey (expkey, key); expkey +=DES_EXPKEY_WORDS ; key +=DES_KEY_SIZE ;dkey (expkey, key); expkey +=DES_EXPKEY_WORDS ; key +=DES_KEY_SIZE ; -ekey (expkey, key); +des_ekey (expkey, key);return 0 ; }
drivers/crypto/Kconfig +1 -1
@@ -90,9 +90,9 @@ config ZCRYPT_MONOLITHIC config CRYPTO_DEV_HIFN_795X tristate "Driver HIFN 795x crypto accelerator chips" + select DES select CRYPTO_ALGAPI select CRYPTO_ABLKCIPHER - select CRYPTO_BLKCIPHER help This option allows you to have support for HIFN 795x crypto adapters.
drivers/crypto/hifn_795x.c +12 -0
@@ -1915,6 +1915,8 @@ static void hifn_flush(struct hifn_device *dev)spin_unlock_irqrestore (&dev->lock, flags); } +extern unsigned long des_ekey (u32 *pe,const u8 *k); +static int hifn_setkey (struct crypto_ablkcipher *cipher,const u8 *key,unsigned int len) {
@@ -1927,6 +1929,16 @@ static int hifn_setkey(struct crypto_ablkcipher *cipher, const u8 *key,return -1 ; } +if (len ==HIFN_DES_KEY_LENGTH ) { +u32 tmp[32 ]; +int ret =des_ekey (tmp, key); + +if (unlikely (ret ==0 ) && (tfm->crt_flags &CRYPTO_TFM_REQ_WEAK_KEY )) { + tfm->crt_flags |=CRYPTO_TFM_RES_WEAK_KEY ; +return -EINVAL ; + } + } + dev->flags &= ~HIFN_FLAG_OLD_KEY ;memcpy (ctx->key, key, len);
Signature · 1 line
Evgeniy Polyakov
Herbert Xu
maintainerQuoted 2 lines · Evgeniy Polyakov
Attached patch fixes that with following tcrypt output:
That was quick :)
Unfortunately it doesn't apply because des.c has been renamed to des_generic.c in cryptodev-2.6. Could you please fix that up and also move the prototype into a header file, say include/crypto/des.h?
Thanks,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtQuoted 10 lines · Herbert Xu
Quoted 2 lines · Evgeniy Polyakov
Attached patch fixes that with following tcrypt output:
That was quick :)
Unfortunately it doesn't apply because
des.chas been renamed todes_generic.cin cryptodev-2.6. Could you please fix that up and also move the prototype into a header file, sayinclude/crypto/des.h?
Here is DES update.
I will send HIFN river update in the next mail.
crypto/des_generic.c +1 -7
@@ -20,13 +20,7 @@#include <linux/crypto.h> #include <linux/types.h> -#define DES_KEY_SIZE 8 -#define DES_EXPKEY_WORDS 32 -#define DES_BLOCK_SIZE 8 - -#define DES3_EDE_KEY_SIZE (3 * DES_KEY_SIZE) -#define DES3_EDE_EXPKEY_WORDS (3 * DES_EXPKEY_WORDS) -#define DES3_EDE_BLOCK_SIZE DES_BLOCK_SIZE +#include <crypto/des.h> #define ROL (x, r) ((x) = rol32((x), (r)))#define ROR (x, r) ((x) = ror32((x), (r)))
include/crypto/des.h new file +19 -0
@@ -0,0 +1,19 @@ +/* +* DES & Triple DES EDE Cipher Algorithms. +*/ + +#ifndef __CRYPTO_DES_H +#define __CRYPTO_DES_H + +#define DES_KEY_SIZE 8 +#define DES_EXPKEY_WORDS 32 +#define DES_BLOCK_SIZE 8 + +#define DES3_EDE_KEY_SIZE (3 * DES_KEY_SIZE) +#define DES3_EDE_EXPKEY_WORDS (3 * DES_EXPKEY_WORDS) +#define DES3_EDE_BLOCK_SIZE DES_BLOCK_SIZE + + +extern unsigned long des_ekey (u32 *pe,const u8 *k); + +#endif /* __CRYPTO_DES_H */
Signature · 1 line
Evgeniy Polyakov
Quoted 11 lines · Evgeniy Polyakov
Quoted 10 lines · Herbert Xu
Quoted 2 lines · Evgeniy Polyakov
Attached patch fixes that with following tcrypt output:
That was quick :)
Unfortunately it doesn't apply because
des.chas been renamed todes_generic.cin cryptodev-2.6. Could you please fix that up and also move the prototype into a header file, sayinclude/crypto/des.h?
HIFN driver update to use DES weak key checks (exported in this patch).
crypto/des_generic.c renamed from crypto/des.c +6 -11
@@ -20,13 +20,7 @@#include <linux/crypto.h> #include <linux/types.h> -#define DES_KEY_SIZE 8 -#define DES_EXPKEY_WORDS 32 -#define DES_BLOCK_SIZE 8 - -#define DES3_EDE_KEY_SIZE (3 * DES_KEY_SIZE) -#define DES3_EDE_EXPKEY_WORDS (3 * DES_EXPKEY_WORDS) -#define DES3_EDE_BLOCK_SIZE DES_BLOCK_SIZE +#include <crypto/des.h> #define ROL (x, r) ((x) = rol32((x), (r)))#define ROR (x, r) ((x) = ror32((x), (r)))
@@ -634,7 +628,7 @@* Choice 1 has operated on the key. * */ -static unsigned long ekey (u32 *pe,const u8 *k) +unsigned long des_ekey (u32 *pe,const u8 *k) {/* K&R: long is at least 32 bits */ unsigned long a, b, c, d, w;
@@ -709,6 +703,7 @@/* Zero if weak key */ return w; } +EXPORT_SYMBOL_GPL (des_ekey);/* * Decryption key expansion
@@ -792,7 +787,7 @@int ret;/* Expand to tmp */ - ret =ekey (tmp, key); + ret =des_ekey (tmp, key);if (unlikely (ret ==0 ) && (*flags &CRYPTO_TFM_REQ_WEAK_KEY )) { *flags |=CRYPTO_TFM_RES_WEAK_KEY ;
@@ -879,9 +874,9 @@return -EINVAL ; } -ekey (expkey, key); expkey +=DES_EXPKEY_WORDS ; key +=DES_KEY_SIZE ; +des_ekey (expkey, key); expkey +=DES_EXPKEY_WORDS ; key +=DES_KEY_SIZE ;dkey (expkey, key); expkey +=DES_EXPKEY_WORDS ; key +=DES_KEY_SIZE ; -ekey (expkey, key); +des_ekey (expkey, key);return 0 ; }
drivers/crypto/Kconfig +1 -1
@@ -90,9 +90,9 @@ config ZCRYPT_MONOLITHIC config CRYPTO_DEV_HIFN_795X tristate "Driver HIFN 795x crypto accelerator chips" + select DES select CRYPTO_ALGAPI select CRYPTO_ABLKCIPHER - select CRYPTO_BLKCIPHER help This option allows you to have support for HIFN 795x crypto adapters.
drivers/crypto/hifn_795x.c +11 -0
@@ -29,6 +29,7 @@#include <linux/crypto.h> #include <crypto/algapi.h> +#include <crypto/des.h> #include <asm/kmap_types.h>
@@ -1927,6 +1928,16 @@ static int hifn_setkey(struct crypto_ablkcipher *cipher, const u8 *key,return -1 ; } +if (len ==HIFN_DES_KEY_LENGTH ) { +u32 tmp[DES_EXPKEY_WORDS ]; +int ret =des_ekey (tmp, key); + +if (unlikely (ret ==0 ) && (tfm->crt_flags &CRYPTO_TFM_REQ_WEAK_KEY )) { + tfm->crt_flags |=CRYPTO_TFM_RES_WEAK_KEY ; +return -EINVAL ; + } + } + dev->flags &= ~HIFN_FLAG_OLD_KEY ;memcpy (ctx->key, key, len);
Signature · 1 line
Evgeniy Polyakov
Herbert Xu
maintainerQuoted 4 lines · Evgeniy Polyakov
HIFN driver update to use DES weak key checks (exported in this patch).
Signed-off-by Evgeniy Polyakov <[email protected]>
Both patches applied. Thanks a lot!
BTW I fixed the Kconfig to say CRYPTO_DES instead of DES.
Cheers,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtQuoted 9 lines · Herbert Xu
Quoted 4 lines · Evgeniy Polyakov
HIFN driver update to use DES weak key checks (exported in this patch).
Signed-off-by Evgeniy Polyakov <[email protected]>Both patches applied. Thanks a lot!
BTW I fixed the
Kconfigto sayCRYPTO_DESinstead of DES.
Thanks Herbert!
Signature · 1 line
Evgeniy Polyakov