Re: [PATCH v5 2/2] crypto: stm32 - Support for STM32 CRYP crypto module
Just a gentle ping ... or have I missed out on a reply? On 13/11/17 11:30, Fabien DESSENNE wrote: > Hi Herbert, > > Can you check if this patchset (removed the AEAD part as you suggested + > libkcapi test OK as suggested by Corentin) can be applied now? > > BR > > Fabien > > > On 07/11/17 15:40, Fabien DESSENNE wrote: >> On 22/10/17 09:26, Corentin Labbe wrote: >>> On Thu, Oct 19, 2017 at 05:10:30PM +0200, Fabien Dessenne wrote: This module registers block cipher algorithms that make use of the STMicroelectronics STM32 crypto "CRYP1" hardware. The following algorithms are supported: - aes: ecb, cbc, ctr - des: ecb, cbc - tdes: ecb, cbc Signed-off-by: Fabien Dessenne--- drivers/crypto/stm32/Kconfig |9 + drivers/crypto/stm32/Makefile |3 +- drivers/crypto/stm32/stm32-cryp.c | 1172 + 3 files changed, 1183 insertions(+), 1 deletion(-) create mode 100644 drivers/crypto/stm32/stm32-cryp.c diff --git a/drivers/crypto/stm32/Kconfig b/drivers/crypto/stm32/Kconfig +static void stm32_cryp_irq_write_block(struct stm32_cryp *cryp) +{ + unsigned int i, j; + u32 *src; + u8 d8[4]; + + src = sg_virt(cryp->in_sg) + _walked_in; + + for (i = 0; i < cryp->hw_blocksize / sizeof(u32); i++) { + if (likely(cryp->total_in >= sizeof(u32))) { + /* Write a full u32 */ + stm32_cryp_write(cryp, CRYP_DIN, *src); >>> Hello >>> >>> Try also to test your driver with userspace via AF_ALG (libkcapi is a good >>> start). >>> It should probably crash here. >>> I have do the same on my first sunxi-ss driver and you should use kmap(). >>> >>> Regards >> Hi Corentin, >> >> Thank you for suggesting to test from userspace through the AF_ALG >> socket with libkcapi. >> This increases my test coverage. >> >> I ran the miscellaneous tests (kcapi-enc-test(large).sh + test.sh) and >> could not observe any crash. >> Note that I had already fixed some 'memory crashes' while testing with >> testmgr / tcrypt while testing from the kernel. >> >> So it looks like the proposed implementation is fine. >> >> BR >> >> Fabien
Re: [PATCH v5 2/2] crypto: stm32 - Support for STM32 CRYP crypto module
Hi Herbert, Can you check if this patchset (removed the AEAD part as you suggested + libkcapi test OK as suggested by Corentin) can be applied now? BR Fabien On 07/11/17 15:40, Fabien DESSENNE wrote: > > On 22/10/17 09:26, Corentin Labbe wrote: >> On Thu, Oct 19, 2017 at 05:10:30PM +0200, Fabien Dessenne wrote: >>> This module registers block cipher algorithms that make use of the >>> STMicroelectronics STM32 crypto "CRYP1" hardware. >>> The following algorithms are supported: >>> - aes: ecb, cbc, ctr >>> - des: ecb, cbc >>> - tdes: ecb, cbc >>> >>> Signed-off-by: Fabien Dessenne>>> --- >>>drivers/crypto/stm32/Kconfig |9 + >>>drivers/crypto/stm32/Makefile |3 +- >>>drivers/crypto/stm32/stm32-cryp.c | 1172 >>> + >>>3 files changed, 1183 insertions(+), 1 deletion(-) >>>create mode 100644 drivers/crypto/stm32/stm32-cryp.c >>> >>> diff --git a/drivers/crypto/stm32/Kconfig b/drivers/crypto/stm32/Kconfig >>> +static void stm32_cryp_irq_write_block(struct stm32_cryp *cryp) >>> +{ >>> + unsigned int i, j; >>> + u32 *src; >>> + u8 d8[4]; >>> + >>> + src = sg_virt(cryp->in_sg) + _walked_in; >>> + >>> + for (i = 0; i < cryp->hw_blocksize / sizeof(u32); i++) { >>> + if (likely(cryp->total_in >= sizeof(u32))) { >>> + /* Write a full u32 */ >>> + stm32_cryp_write(cryp, CRYP_DIN, *src); >> Hello >> >> Try also to test your driver with userspace via AF_ALG (libkcapi is a good >> start). >> It should probably crash here. >> I have do the same on my first sunxi-ss driver and you should use kmap(). >> >> Regards > Hi Corentin, > > Thank you for suggesting to test from userspace through the AF_ALG > socket with libkcapi. > This increases my test coverage. > > I ran the miscellaneous tests (kcapi-enc-test(large).sh + test.sh) and > could not observe any crash. > Note that I had already fixed some 'memory crashes' while testing with > testmgr / tcrypt while testing from the kernel. > > So it looks like the proposed implementation is fine. > > BR > > Fabien
Re: [PATCH v5 2/2] crypto: stm32 - Support for STM32 CRYP crypto module
On 22/10/17 09:26, Corentin Labbe wrote: > On Thu, Oct 19, 2017 at 05:10:30PM +0200, Fabien Dessenne wrote: >> This module registers block cipher algorithms that make use of the >> STMicroelectronics STM32 crypto "CRYP1" hardware. >> The following algorithms are supported: >> - aes: ecb, cbc, ctr >> - des: ecb, cbc >> - tdes: ecb, cbc >> >> Signed-off-by: Fabien Dessenne>> --- >> drivers/crypto/stm32/Kconfig |9 + >> drivers/crypto/stm32/Makefile |3 +- >> drivers/crypto/stm32/stm32-cryp.c | 1172 >> + >> 3 files changed, 1183 insertions(+), 1 deletion(-) >> create mode 100644 drivers/crypto/stm32/stm32-cryp.c >> >> diff --git a/drivers/crypto/stm32/Kconfig b/drivers/crypto/stm32/Kconfig >> +static void stm32_cryp_irq_write_block(struct stm32_cryp *cryp) >> +{ >> +unsigned int i, j; >> +u32 *src; >> +u8 d8[4]; >> + >> +src = sg_virt(cryp->in_sg) + _walked_in; >> + >> +for (i = 0; i < cryp->hw_blocksize / sizeof(u32); i++) { >> +if (likely(cryp->total_in >= sizeof(u32))) { >> +/* Write a full u32 */ >> +stm32_cryp_write(cryp, CRYP_DIN, *src); > Hello > > Try also to test your driver with userspace via AF_ALG (libkcapi is a good > start). > It should probably crash here. > I have do the same on my first sunxi-ss driver and you should use kmap(). > > Regards Hi Corentin, Thank you for suggesting to test from userspace through the AF_ALG socket with libkcapi. This increases my test coverage. I ran the miscellaneous tests (kcapi-enc-test(large).sh + test.sh) and could not observe any crash. Note that I had already fixed some 'memory crashes' while testing with testmgr / tcrypt while testing from the kernel. So it looks like the proposed implementation is fine. BR Fabien
Re: [PATCH v5 2/2] crypto: stm32 - Support for STM32 CRYP crypto module
On Thu, Oct 19, 2017 at 05:10:30PM +0200, Fabien Dessenne wrote: > This module registers block cipher algorithms that make use of the > STMicroelectronics STM32 crypto "CRYP1" hardware. > The following algorithms are supported: > - aes: ecb, cbc, ctr > - des: ecb, cbc > - tdes: ecb, cbc > > Signed-off-by: Fabien Dessenne> --- > drivers/crypto/stm32/Kconfig |9 + > drivers/crypto/stm32/Makefile |3 +- > drivers/crypto/stm32/stm32-cryp.c | 1172 > + > 3 files changed, 1183 insertions(+), 1 deletion(-) > create mode 100644 drivers/crypto/stm32/stm32-cryp.c > > diff --git a/drivers/crypto/stm32/Kconfig b/drivers/crypto/stm32/Kconfig > +static void stm32_cryp_irq_write_block(struct stm32_cryp *cryp) > +{ > + unsigned int i, j; > + u32 *src; > + u8 d8[4]; > + > + src = sg_virt(cryp->in_sg) + _walked_in; > + > + for (i = 0; i < cryp->hw_blocksize / sizeof(u32); i++) { > + if (likely(cryp->total_in >= sizeof(u32))) { > + /* Write a full u32 */ > + stm32_cryp_write(cryp, CRYP_DIN, *src); Hello Try also to test your driver with userspace via AF_ALG (libkcapi is a good start). It should probably crash here. I have do the same on my first sunxi-ss driver and you should use kmap(). Regards
[PATCH v5 2/2] crypto: stm32 - Support for STM32 CRYP crypto module
This module registers block cipher algorithms that make use of the STMicroelectronics STM32 crypto "CRYP1" hardware. The following algorithms are supported: - aes: ecb, cbc, ctr - des: ecb, cbc - tdes: ecb, cbc Signed-off-by: Fabien Dessenne--- drivers/crypto/stm32/Kconfig |9 + drivers/crypto/stm32/Makefile |3 +- drivers/crypto/stm32/stm32-cryp.c | 1172 + 3 files changed, 1183 insertions(+), 1 deletion(-) create mode 100644 drivers/crypto/stm32/stm32-cryp.c diff --git a/drivers/crypto/stm32/Kconfig b/drivers/crypto/stm32/Kconfig index 602332e..61ef00b 100644 --- a/drivers/crypto/stm32/Kconfig +++ b/drivers/crypto/stm32/Kconfig @@ -18,3 +18,12 @@ config HASH_DEV_STM32 help This enables support for the HASH hw accelerator which can be found on STMicroelectronics STM32 SOC. + +config CRYP_DEV_STM32 + tristate "Support for STM32 cryp accelerators" + depends on ARCH_STM32 + select CRYPTO_HASH + select CRYPTO_ENGINE + help + This enables support for the CRYP (AES/DES/TDES) hw accelerator which + can be found on STMicroelectronics STM32 SOC. diff --git a/drivers/crypto/stm32/Makefile b/drivers/crypto/stm32/Makefile index 73cd56c..2c19fc1 100644 --- a/drivers/crypto/stm32/Makefile +++ b/drivers/crypto/stm32/Makefile @@ -1,2 +1,3 @@ obj-$(CONFIG_CRC_DEV_STM32) += stm32_crc32.o -obj-$(CONFIG_HASH_DEV_STM32) += stm32-hash.o \ No newline at end of file +obj-$(CONFIG_HASH_DEV_STM32) += stm32-hash.o +obj-$(CONFIG_CRYP_DEV_STM32) += stm32-cryp.o diff --git a/drivers/crypto/stm32/stm32-cryp.c b/drivers/crypto/stm32/stm32-cryp.c new file mode 100644 index 000..4597559 --- /dev/null +++ b/drivers/crypto/stm32/stm32-cryp.c @@ -0,0 +1,1172 @@ +/* + * Copyright (C) STMicroelectronics SA 2017 + * Author: Fabien Dessenne + * License terms: GNU General Public License (GPL), version 2 + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#define DRIVER_NAME "stm32-cryp" + +/* Bit [0] encrypt / decrypt */ +#define FLG_ENCRYPT BIT(0) +/* Bit [8..1] algo & operation mode */ +#define FLG_AES BIT(1) +#define FLG_DES BIT(2) +#define FLG_TDESBIT(3) +#define FLG_ECB BIT(4) +#define FLG_CBC BIT(5) +#define FLG_CTR BIT(6) +/* Mode mask = bits [15..0] */ +#define FLG_MODE_MASK GENMASK(15, 0) + +/* Registers */ +#define CRYP_CR 0x +#define CRYP_SR 0x0004 +#define CRYP_DIN0x0008 +#define CRYP_DOUT 0x000C +#define CRYP_DMACR 0x0010 +#define CRYP_IMSCR 0x0014 +#define CRYP_RISR 0x0018 +#define CRYP_MISR 0x001C +#define CRYP_K0LR 0x0020 +#define CRYP_K0RR 0x0024 +#define CRYP_K1LR 0x0028 +#define CRYP_K1RR 0x002C +#define CRYP_K2LR 0x0030 +#define CRYP_K2RR 0x0034 +#define CRYP_K3LR 0x0038 +#define CRYP_K3RR 0x003C +#define CRYP_IV0LR 0x0040 +#define CRYP_IV0RR 0x0044 +#define CRYP_IV1LR 0x0048 +#define CRYP_IV1RR 0x004C + +/* Registers values */ +#define CR_DEC_NOT_ENC 0x0004 +#define CR_TDES_ECB 0x +#define CR_TDES_CBC 0x0008 +#define CR_DES_ECB 0x0010 +#define CR_DES_CBC 0x0018 +#define CR_AES_ECB 0x0020 +#define CR_AES_CBC 0x0028 +#define CR_AES_CTR 0x0030 +#define CR_AES_KP 0x0038 +#define CR_AES_UNKNOWN 0x +#define CR_ALGO_MASK0x00080038 +#define CR_DATA32 0x +#define CR_DATA16 0x0040 +#define CR_DATA80x0080 +#define CR_DATA10x00C0 +#define CR_KEY128 0x +#define CR_KEY192 0x0100 +#define CR_KEY256 0x0200 +#define CR_FFLUSH 0x4000 +#define CR_CRYPEN 0x8000 + +#define SR_BUSY 0x0010 +#define SR_OFNE 0x0004 + +#define IMSCR_INBIT(0) +#define IMSCR_OUT BIT(1) + +#define MISR_IN BIT(0) +#define MISR_OUTBIT(1) + +/* Misc */ +#define AES_BLOCK_32(AES_BLOCK_SIZE / sizeof(u32)) +#define _walked_in (cryp->in_walk.offset - cryp->in_sg->offset) +#define _walked_out (cryp->out_walk.offset - cryp->out_sg->offset) + +struct stm32_cryp_ctx { + struct stm32_cryp *cryp; + int