Add ARMv8 CE sha1/sha256 support
Subsystems (2)
v2 cover Add ARMv8 CE sha1/sha256 support
This series adds support for the SHA-1 and SHA-256 Secure Hash Algorithm for CPUs that have support of the ARM v8 Crypto Extensions. It Improves speed of integrity & signature checking procedures.
V2:
- Add cover letter & sha256 support.
- Kconfig default 'y' only if SHA1 and SHA256 selected
Loic Poulain (5):
lib: sha1: Add support for hardware specific sha1_process
sha1: Fix digest state size/type
armv8 SHA-1 using ARMv8 Crypto Extensions:
lib: sha256: Add support for hardware specific sha256_process armv8 SHA-256 using ARMv8 Crypto Extensions
arch/arm/cpu/armv8/Kconfig | 15 ++++ arch/arm/cpu/armv8/Makefile | 2 + arch/arm/cpu/armv8/sha1_ce_core.S | 132 +++++++++++++++++++++++++++++++++++ arch/arm/cpu/armv8/sha1_ce_glue.c | 21 ++++++ arch/arm/cpu/armv8/sha256_ce_core.S | 134 ++++++++++++++++++++++++++++++++++++ arch/arm/cpu/armv8/sha256_ce_glue.c | 21 ++++++ include/u-boot/sha1.h | 2 +- lib/sha1.c | 26 +++++-- lib/sha256.c | 26 +++++-- 9 files changed, 364 insertions(+), 15 deletions(-) create mode 100644 arch/arm/cpu/armv8/sha1_ce_core.S create mode 100644 arch/arm/cpu/armv8/sha1_ce_glue.c create mode 100644 arch/arm/cpu/armv8/sha256_ce_core.S create mode 100644 arch/arm/cpu/armv8/sha256_ce_glue.c
Signature · 1 line
2.7.4
PATCH v2 1/5 lib: sha1: Add support for hardware specific sha1_process
Mark sha1_process as weak to allow hardware specific implementation. Add parameter to support for multiple blocks processing.
--- lib/sha1.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
lib/sha1.c +19 -7
@@ -25,6 +25,8 @@#include <watchdog.h> #include <u-boot/sha1.h> +#include <linux/compiler_attributes.h> +const uint8_t sha1_der_prefix[SHA1_DER_LEN ] = {0x30 ,0x21 ,0x30 ,0x09 ,0x06 ,0x05 ,0x2b ,0x0e ,0x03 ,0x02 ,0x1a ,0x05 ,0x00 ,0x04 ,0x14
@@ -65,7 +67,7 @@ void sha1_starts (sha1_context * ctx) ctx->state[4 ] =0xC3D2E1F0 ; } -static void sha1_process (sha1_context *ctx,const unsigned char data[64 ]) +static void __maybe_unused sha1_process_one (sha1_context *ctx,const unsigned char data[64 ]) {unsigned long temp,W [16 ],A ,B ,C ,D ,E ;
@@ -219,6 +221,18 @@ static void sha1_process(sha1_context *ctx, const unsigned char data[64]) ctx->state[4 ] +=E ; } +__weak void sha1_process (sha1_context *ctx,const unsigned char *data, +unsigned int blocks) +{ +if (!blocks) +return ; + +while (blocks--) { +sha1_process_one (ctx, data); + data +=64 ; + } +} +/* * SHA-1 process buffer */
@@ -242,17 +256,15 @@ void sha1_update(sha1_context *ctx, const unsigned char *input,if (left && ilen >= fill) {memcpy ((void *) (ctx->buffer + left), (void *) input, fill); -sha1_process (ctx, ctx->buffer); +sha1_process (ctx, ctx->buffer,1 ); input += fill; ilen -= fill; left =0 ; } -while (ilen >=64 ) { -sha1_process (ctx, input); - input +=64 ; - ilen -=64 ; - } +sha1_process (ctx, input, ilen /64 ); + input += ilen /64 *64 ; + ilen = ilen %64 ;if (ilen >0 ) {memcpy ((void *) (ctx->buffer + left), (void *) input, ilen);
Signature · 1 line
2.7.4
Re: [PATCH v2 1/5] lib: sha1: Add support for hardware specific sha1_process
Quoted 4 lines · Loic Poulain
Mark
sha1_processas weak to allow hardware specific implementation. Add parameter to support for multiple blocks processing.Signed-off-by Loic Poulain <[email protected]>
Applied to u-boot/next, thanks!
Signature · 1 line
Tom
PATCH v2 2/5 sha1: Fix digest state size/type
In reply to Loic Poulainsha1 digest size is 5*32-bit => 160-bit. Using 64-bit unsigned long does not cause issue with the current sha1 implementation, but could be problematic for vectorized access.
--- include/u-boot/sha1.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/u-boot/sha1.h +1 -1
@@ -30,7 +30,7 @@ extern const uint8_t sha1_der_prefix[];typedef struct {unsigned long total[2 ];/*!< number of bytes processed */ -unsigned long state[5 ];/*!< intermediate digest state */ +uint32_t state[5 ];/*!< intermediate digest state */ unsigned char buffer[64 ];/*!< data block being processed */ }sha1_context ;
Signature · 1 line
2.7.4
Re: [PATCH v2 2/5] sha1: Fix digest state size/type
Quoted 5 lines · Loic Poulain
sha1 digest size is 5*32-bit => 160-bit. Using 64-bit unsigned long does not cause issue with the current sha1 implementation, but could be problematic for vectorized access.
Signed-off-by Loic Poulain <[email protected]>
Applied to u-boot/next, thanks!
Signature · 1 line
Tom
PATCH v2 3/5 armv8 SHA-1 using ARMv8 Crypto Extensions:
In reply to Loic PoulainThis patch adds support for the SHA-1 Secure Hash Algorithm for CPUs that have support for the SHA-1 part of the ARM v8 Crypto Extensions.
It greatly improves sha-1 based operations, about 10x faster on iMX8M evk board. ~12ms vs ~165ms for a 20MiB kernel sha-1 verification.
asm implementation is a simplified version of the Linux version (from Ard Biesheuvel).
--- arch/arm/cpu/armv8/Kconfig | 11 ++++ arch/arm/cpu/armv8/Makefile | 1 + arch/arm/cpu/armv8/sha1_ce_core.S | 132 ++++++++++++++++++++++++++++++++++++++ arch/arm/cpu/armv8/sha1_ce_glue.c | 21 ++++++ 4 files changed, 165 insertions(+) create mode 100644 arch/arm/cpu/armv8/sha1_ce_core.S create mode 100644 arch/arm/cpu/armv8/sha1_ce_glue.c
arch/arm/cpu/armv8/Kconfig +11 -0
@@ -171,4 +171,15 @@ config ARMV8_SECURE_BASE endif +menuconfig ARMV8_CRYPTO + bool "ARM64 Accelerated Cryptographic Algorithms" + +if ARMV8_CRYPTO + +config ARMV8_CE_SHA1 + bool "SHA-1 digest algorithm (ARMv8 Crypto Extensions)" + default y if SHA1 + +endif + endif
arch/arm/cpu/armv8/Makefile +1 -0
@@ -44,3 +44,4 @@ obj-$(CONFIG_TARGET_HIKEY) += hisilicon/ obj-$(CONFIG_ARMV8_PSCI) += psci.o obj-$(CONFIG_TARGET_BCMNS3) += bcmns3/ obj-$(CONFIG_XEN) += xen/ +obj-$(CONFIG_ARMV8_CE_SHA1) += sha1_ce_glue.o sha1_ce_core.o
arch/arm/cpu/armv8/sha1_ce_core.S new file +132 -0
132 lines not on this page · raw message
arch/arm/cpu/armv8/sha1_ce_glue.c new file +21 -0
@@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* sha1_ce_glue.c - SHA-1 secure hash using ARMv8 Crypto Extensions +* +* Copyright (C) 2022 Linaro Ltd <[email protected]> +*/ + +#include <common.h> +#include <u-boot/sha1.h> + +extern void sha1_armv8_ce_process (uint32_t state[5 ],uint8_t const *src, +uint32_t blocks); + +void sha1_process (sha1_context *ctx,const unsigned char *data, +unsigned int blocks) +{ +if (!blocks) +return ; + +sha1_armv8_ce_process (ctx->state, data, blocks); +}
Signature · 1 line
2.7.4
Re: [PATCH v2 3/5] armv8 SHA-1 using ARMv8 Crypto Extensions:
Quoted 10 lines · Loic Poulain
This patch adds support for the SHA-1 Secure Hash Algorithm for CPUs that have support for the SHA-1 part of the ARM v8 Crypto Extensions.
It greatly improves sha-1 based operations, about 10x faster on iMX8M evk board. ~12ms vs ~165ms for a 20MiB kernel sha-1 verification.
asm implementation is a simplified version of the Linux version (from Ard Biesheuvel).
Signed-off-by Loic Poulain <[email protected]>
Applied to u-boot/next, thanks!
Signature · 1 line
Tom
PATCH v2 4/5 lib: sha256: Add support for hardware specific sha256_process
In reply to Loic PoulainMark sha256_process as weak to allow hardware specific implementation. Add parameter for supporting multiple blocks processing.
--- lib/sha256.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
lib/sha256.c +19 -7
@@ -14,6 +14,8 @@#include <watchdog.h> #include <u-boot/sha256.h> +#include <linux/compiler_attributes.h> +const uint8_t sha256_der_prefix[SHA256_DER_LEN ] = {0x30 ,0x31 ,0x30 ,0x0d ,0x06 ,0x09 ,0x60 ,0x86 ,0x48 ,0x01 ,0x65 ,0x03 ,0x04 ,0x02 ,0x01 ,0x05 ,
@@ -55,7 +57,7 @@ void sha256_starts(sha256_context * ctx) ctx->state[7 ] =0x5BE0CD19 ; } -static void sha256_process (sha256_context *ctx,const uint8_t data[64 ]) +static void sha256_process_one (sha256_context *ctx,const uint8_t data[64 ]) {uint32_t temp1, temp2;uint32_t W [64 ];
@@ -186,6 +188,18 @@ static void sha256_process(sha256_context *ctx, const uint8_t data[64]) ctx->state[7 ] +=H ; } +__weak void sha256_process (sha256_context *ctx,const unsigned char *data, +unsigned int blocks) +{ +if (!blocks) +return ; + +while (blocks--) { +sha256_process_one (ctx, data); + data +=64 ; + } +} +void sha256_update (sha256_context *ctx,const uint8_t *input,uint32_t length) {uint32_t left, fill;
@@ -204,17 +218,15 @@ void sha256_update(sha256_context *ctx, const uint8_t *input, uint32_t length)if (left && length >= fill) {memcpy ((void *) (ctx->buffer + left), (void *) input, fill); -sha256_process (ctx, ctx->buffer); +sha256_process (ctx, ctx->buffer,1 ); length -= fill; input += fill; left =0 ; } -while (length >=64 ) { -sha256_process (ctx, input); - length -=64 ; - input +=64 ; - } +sha256_process (ctx, input, length /64 ); + input += length /64 *64 ; + length = length %64 ;if (length)memcpy ((void *) (ctx->buffer + left), (void *) input, length);
Signature · 1 line
2.7.4
Re: [PATCH v2 4/5] lib: sha256: Add support for hardware specific sha256_process
Quoted 4 lines · Loic Poulain
Mark
sha256_processas weak to allow hardware specific implementation. Add parameter for supporting multiple blocks processing.Signed-off-by Loic Poulain <[email protected]>
Applied to u-boot/next, thanks!
Signature · 1 line
Tom
Re: [PATCH v2 4/5] lib: sha256: Add support for hardware specific sha256_process
In reply to Loic PoulainHi Loic,
Quoted 73 lines · Loic Poulain
Mark
sha256_processas weak to allow hardware specific implementation. Add parameter for supporting multiple blocks processing.Signed-off-by Loic Poulain <[email protected]>--- lib/sha256.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)lib/sha256.c +19
-8@@ -14,6 +14,8 @@#include <watchdog.h> #include <u-boot/sha256.h> +#include <linux/compiler_attributes.h> +const uint8_t sha256_der_prefix[SHA256_DER_LEN ] = {0x30 ,0x31 ,0x30 ,0x0d ,0x06 ,0x09 ,0x60 ,0x86 ,0x48 ,0x01 ,0x65 ,0x03 ,0x04 ,0x02 ,0x01 ,0x05 ,@@ -55,7 +57,7 @@ void sha256_starts(sha256_context * ctx) ctx->state[7 ] =0x5BE0CD19 ; } -static void sha256_process (sha256_context *ctx,const uint8_t data[64 ]) +static void sha256_process_one (sha256_context *ctx,const uint8_t data[64 ]) {uint32_t temp1, temp2;uint32_t W [64 ];@@ -186,6 +188,18 @@ static void sha256_process(sha256_context *ctx, const uint8_t data[64]) ctx->state[7 ] +=H ; } +__weak void sha256_process (sha256_context *ctx,const unsigned char *data, +unsigned int blocks) +{ +if (!blocks) +return ; + +while (blocks--) { +sha256_process_one (ctx, data); + data +=64 ; + } +} +void sha256_update (sha256_context *ctx,const uint8_t *input,uint32_t length) {uint32_t left, fill;@@ -204,17 +218,15 @@ void sha256_update(sha256_context *ctx, const uint8_t *input, uint32_t length)if (left && length >= fill) {memcpy ((void *) (ctx->buffer + left), (void *) input, fill); -sha256_process (ctx, ctx->buffer); +sha256_process (ctx, ctx->buffer,1 ); length -= fill; input += fill; left =0 ; } -while (length >=64 ) { -sha256_process (ctx, input); - length -=64 ; - input +=64 ; - } +sha256_process (ctx, input, length /64 ); + input += length /64 *64 ; + length = length %64 ;if (length)memcpy ((void *) (ctx->buffer + left), (void *) input, length); --
Quoted 2 lines
2.7.4
I just came across this patch as it broke minnowmax.
This should be using driver model, not weak functions. Please can you take a look?
Regards,
Simon
Re: [PATCH v2 4/5] lib: sha256: Add support for hardware specific sha256_process
Hi Simon,
Quoted 79 lines · Simon Glass
Hi Loic,
Quoted 23 lines · Loic Poulain
Mark
sha256_processas weak to allow hardware specific implementation. Add parameter for supporting multiple blocks processing.Signed-off-by Loic Poulain <[email protected]>--- lib/sha256.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)lib/sha256.c +2
-0@@ -14,6 +14,8 @@#include <watchdog.h> #include <u-boot/sha256.h> +#include <linux/compiler_attributes.h> +const uint8_t sha256_der_prefix[SHA256_DER_LEN ] = {0x30 ,0x31 ,0x30 ,0x0d ,0x06 ,0x09 ,0x60 ,0x86 ,0x48 ,0x01 ,0x65 ,0x03 ,0x04 ,0x02 ,0x01 ,0x05 ,lib/sha256.c void sha256_starts(sha256_context * ctx) · line 60
Quoted 5 lines
lib/sha256.c +1
-1@@ -55,7 +57,7 @@ void sha256_starts(sha256_context * ctx) ctx->state[7 ] =0x5BE0CD19 ; } -static void sha256_process (sha256_context *ctx,const uint8_t data[64 ]) +static void sha256_process_one(sha256_context *ctx, const uint8_tdata[64])
lib/sha256.c static void sha256_process(sha256_context *ctx,
Quoted 4 lines
lib/sha256.c +0
-0{uint32_t temp1, temp2;uint32_t W [64 ];@@ -186,6 +188,18 @@ static void sha256_process(sha256_context *ctx,const
uint8_tdata[64])lib/sha256.c static void sha256_process(sha256_context *ctx, const uint8_t data[64])
Quoted 4 lines
lib/sha256.c +1
-0ctx->state[7 ] +=H ; } +__weak void sha256_process(sha256_context *ctx, const unsigned char*data,
lib/sha256.c static void sha256_process(sha256_context *ctx, const uint8_t data[64])
Quoted 12 lines
lib/sha256.c +11
-0+ unsigned int blocks) +{ +if (!blocks) +return ; + +while (blocks--) { +sha256_process_one (ctx, data); + data +=64 ; + } +} + void sha256_update(sha256_context *ctx, const uint8_t *input, uint32_tlength)
lib/sha256.c void sha256_update(sha256_context *ctx, const
Quoted 3 lines
lib/sha256.c +0
-0{uint32_t left, fill;@@ -204,17 +218,15 @@ void sha256_update(sha256_context *ctx, const
uint8_t*input,uint32_tlength)lib/sha256.c void sha256_update(sha256_context *ctx, const · line 219
Quoted 3 lines
lib/sha256.c +0
-0if (left && length >= fill) { memcpy((void *) (ctx->buffer + left), (void *) input,fill);
Quoted 16 lines
lib/sha256.c +4
-6-sha256_process (ctx, ctx->buffer); +sha256_process (ctx, ctx->buffer,1 ); length -= fill; input += fill; left =0 ; } -while (length >=64 ) { -sha256_process (ctx, input); - length -=64 ; - input +=64 ; - } +sha256_process (ctx, input, length /64 ); + input += length /64 *64 ; + length = length %64 ;
Quoted 8 lines
lib/sha256.c void sha256_update(sha256_context *ctx, const · line 231
Quoted 2 lines
lib/sha256.c +0
-0if (length) memcpy((void *) (ctx->buffer + left), (void *) input,length);
Quoted 3 lines
lib/sha256.c +0
-1--2.7.4
I just came across this patch as it broke minnowmax.
Ok, is it a build time or runtime break?
Quoted 3 lines
This should be using driver model, not weak functions. Please can you take a look?
Yes I can look at it in the next few days. I have used weak function because it’s an architecture feature offered by armv8 instructions, It’s not strictly speaking an internal device/IP.
Regards,
Loic
Quoted 1 line
Re: [PATCH v2 4/5] lib: sha256: Add support for hardware specific sha256_process
Hi Loic,
Quoted 87 lines · Loic Poulain
Hi Simon,
Quoted 74 lines · Simon Glass
Hi Loic,
Quoted 70 lines · Loic Poulain
Mark
sha256_processas weak to allow hardware specific implementation. Add parameter for supporting multiple blocks processing.Signed-off-by Loic Poulain <[email protected]>--- lib/sha256.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)lib/sha256.c +19
-7@@ -14,6 +14,8 @@#include <watchdog.h> #include <u-boot/sha256.h> +#include <linux/compiler_attributes.h> +const uint8_t sha256_der_prefix[SHA256_DER_LEN ] = {0x30 ,0x31 ,0x30 ,0x0d ,0x06 ,0x09 ,0x60 ,0x86 ,0x48 ,0x01 ,0x65 ,0x03 ,0x04 ,0x02 ,0x01 ,0x05 ,@@ -55,7 +57,7 @@ void sha256_starts(sha256_context * ctx) ctx->state[7 ] =0x5BE0CD19 ; } -static void sha256_process (sha256_context *ctx,const uint8_t data[64 ]) +static void sha256_process_one (sha256_context *ctx,const uint8_t data[64 ]) {uint32_t temp1, temp2;uint32_t W [64 ];@@ -186,6 +188,18 @@ static void sha256_process(sha256_context *ctx, const uint8_t data[64]) ctx->state[7 ] +=H ; } +__weak void sha256_process (sha256_context *ctx,const unsigned char *data, +unsigned int blocks) +{ +if (!blocks) +return ; + +while (blocks--) { +sha256_process_one (ctx, data); + data +=64 ; + } +} +void sha256_update (sha256_context *ctx,const uint8_t *input,uint32_t length) {uint32_t left, fill;@@ -204,17 +218,15 @@ void sha256_update(sha256_context *ctx, const uint8_t *input, uint32_t length)if (left && length >= fill) {memcpy ((void *) (ctx->buffer + left), (void *) input, fill); -sha256_process (ctx, ctx->buffer); +sha256_process (ctx, ctx->buffer,1 ); length -= fill; input += fill; left =0 ; } -while (length >=64 ) { -sha256_process (ctx, input); - length -=64 ; - input +=64 ; - } +sha256_process (ctx, input, length /64 ); + input += length /64 *64 ; + length = length %64 ;Quoted 7 lines
Quoted 5 lines
lib/sha256.c +0
-1if (length)memcpy ((void *) (ctx->buffer + left), (void *) input, length); --2.7.4
I just came across this patch as it broke minnowmax.
Quoted 1 line
Ok, is it a build time or runtime break?
Build, but you need the binary blobs to see it :-(
Quoted 8 lines
Quoted 5 lines
This should be using driver model, not weak functions. Please can you take a look?
Yes I can look at it in the next few days. I have used weak function because it’s an architecture feature offered by armv8 instructions, It’s not strictly speaking an internal device/IP.
Thanks.
Right, same as hardware-accelerated hashing hardware in my book.
See hash.c which has become a mess. We have been trying to make do with a list of algos, but given all the updates I think needs a new UCLASS_HASH with the same operations as in hash.h
Regards,
Simon
Re: [PATCH v2 4/5] lib: sha256: Add support for hardware specific sha256_process
Hi Simon,
Quoted 21 lines · Simon Glass
Hi Loic,
Quoted 17 lines · Loic Poulain
Hi Simon,
Quoted 13 lines · Simon Glass
Hi Loic,
Quoted 9 lines · Loic Poulain
Mark
sha256_processas weak to allow hardware specific implementation. Add parameter for supporting multiple blocks processing.Signed-off-by Loic Poulain <[email protected]>--- lib/sha256.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
[...]
Quoted 44 lines
Quoted 44 lines
Quoted 42 lines
Quoted 38 lines
lib/sha256.c +16
-7+__weak void sha256_process (sha256_context *ctx,const unsigned char *data, +unsigned int blocks) +{ +if (!blocks) +return ; + +while (blocks--) { +sha256_process_one (ctx, data); + data +=64 ; + } +} +void sha256_update (sha256_context *ctx,const uint8_t *input,uint32_t length) {uint32_t left, fill;@@ -204,17 +218,15 @@ void sha256_update(sha256_context *ctx, const uint8_t *input, uint32_t length)if (left && length >= fill) {memcpy ((void *) (ctx->buffer + left), (void *) input, fill); -sha256_process (ctx, ctx->buffer); +sha256_process (ctx, ctx->buffer,1 ); length -= fill; input += fill; left =0 ; } -while (length >=64 ) { -sha256_process (ctx, input); - length -=64 ; - input +=64 ; - } +sha256_process (ctx, input, length /64 ); + input += length /64 *64 ; + length = length %64 ;if (length)memcpy ((void *) (ctx->buffer + left), (void *) input, length); --Quoted 2 lines
2.7.4
I just came across this patch as it broke minnowmax.
Quoted 6 lines
Quoted 1 line
Ok, is it a build time or runtime break?
Build, but you need the binary blobs to see it :-(
Quoted 3 lines
Quoted 3 lines
This should be using driver model, not weak functions. Please can you take a look?
Just tested the minnowmax build (b69026c91f2e; minnowmax_defconfig; gcc-11.3.0), and I've not observed any issue (but I had to fake some of the binary blobs...). Could you share the build problem/error you encountered? As you mentioned it, Is the error specifically related to _weak function linking? Would like to have a simple and quick fix before trying to move on to a more proper DM based solution.
Thanks,
Loic
Quoted 14 lines
Quoted 3 lines
Yes I can look at it in the next few days. I have used weak function because it’s an architecture feature offered by armv8 instructions, It’s not strictly speaking an internal device/IP.
Thanks.
Right, same as hardware-accelerated hashing hardware in my book.
See
hash.cwhich has become a mess. We have been trying to make do with a list of algos, but given all the updates I think needs a newUCLASS_HASHwith the same operations as inhash.hRegards,
Simon
Re: [PATCH v2 4/5] lib: sha256: Add support for hardware specific sha256_process
Hi Loic,
Quoted 72 lines · Loic Poulain
Hi Simon,
Quoted 21 lines · Simon Glass
Hi Loic,
Quoted 17 lines · Loic Poulain
Hi Simon,
Quoted 13 lines · Simon Glass
Hi Loic,
Quoted 9 lines · Loic Poulain
Mark
sha256_processas weak to allow hardware specific implementation. Add parameter for supporting multiple blocks processing.Signed-off-by Loic Poulain <[email protected]>--- lib/sha256.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)[...]
Quoted 46 lines
Quoted 45 lines
Quoted 35 lines
Quoted 35 lines
lib/sha256.c +16
-6+__weak void sha256_process (sha256_context *ctx,const unsigned char *data, +unsigned int blocks) +{ +if (!blocks) +return ; + +while (blocks--) { +sha256_process_one (ctx, data); + data +=64 ; + } +} +void sha256_update (sha256_context *ctx,const uint8_t *input,uint32_t length) {uint32_t left, fill;@@ -204,17 +218,15 @@ void sha256_update(sha256_context *ctx, const uint8_t *input, uint32_t length)if (left && length >= fill) {memcpy ((void *) (ctx->buffer + left), (void *) input, fill); -sha256_process (ctx, ctx->buffer); +sha256_process (ctx, ctx->buffer,1 ); length -= fill; input += fill; left =0 ; } -while (length >=64 ) { -sha256_process (ctx, input); - length -=64 ; - input +=64 ; - } +sha256_process (ctx, input, length /64 ); + input += length /64 *64 ; + length = length %64 ;Quoted 7 lines
Quoted 5 lines
lib/sha256.c +0
-1if (length)memcpy ((void *) (ctx->buffer + left), (void *) input, length); --2.7.4
I just came across this patch as it broke minnowmax.
Ok, is it a build time or runtime break?
Quoted 8 lines
Quoted 4 lines
Build, but you need the binary blobs to see it :-(
Quoted 3 lines
Quoted 3 lines
This should be using driver model, not weak functions. Please can you take a look?
Just tested the minnowmax build (
b69026c91f2e;minnowmax_defconfig; gcc-11.3.0), and I've not observed any issue (but I had to fake some of the binary blobs...). Could you share the build problem/error you
Unfortunately you need the blobs!
Quoted 3 lines
encountered? As you mentioned it, Is the error specifically related to
_weakfunction linking? Would like to have a simple and quick fix before trying to move on to a more proper DM based solution.
It is just because of the code size increase, I believe. I am planning to dig into it a bit as Bin Meng asked for more info as to why I sent a revert for his patch moving U-Boot.
Regards,
Simon
Quoted 19 lines
Thanks,
LoicQuoted 14 lines
Quoted 3 lines
Yes I can look at it in the next few days. I have used weak function because it’s an architecture feature offered by armv8 instructions, It’s not strictly speaking an internal device/IP.
Thanks.
Right, same as hardware-accelerated hashing hardware in my book.
See
hash.cwhich has become a mess. We have been trying to make do with a list of algos, but given all the updates I think needs a newUCLASS_HASHwith the same operations as inhash.hRegards,
Simon
Re: [PATCH v2 4/5] lib: sha256: Add support for hardware specific sha256_process
Quoted 86 lines · Simon Glass
Hi Loic,
Quoted 72 lines · Loic Poulain
Hi Simon,
Quoted 21 lines · Simon Glass
Hi Loic,
Quoted 17 lines · Loic Poulain
Hi Simon,
Quoted 13 lines · Simon Glass
Hi Loic,
Quoted 9 lines · Loic Poulain
Mark
sha256_processas weak to allow hardware specific implementation. Add parameter for supporting multiple blocks processing.Signed-off-by Loic Poulain <[email protected]>--- lib/sha256.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)[...]
Quoted 46 lines
Quoted 45 lines
Quoted 35 lines
Quoted 35 lines
lib/sha256.c +16
-6+__weak void sha256_process (sha256_context *ctx,const unsigned char *data, +unsigned int blocks) +{ +if (!blocks) +return ; + +while (blocks--) { +sha256_process_one (ctx, data); + data +=64 ; + } +} +void sha256_update (sha256_context *ctx,const uint8_t *input,uint32_t length) {uint32_t left, fill;@@ -204,17 +218,15 @@ void sha256_update(sha256_context *ctx, const uint8_t *input, uint32_t length)if (left && length >= fill) {memcpy ((void *) (ctx->buffer + left), (void *) input, fill); -sha256_process (ctx, ctx->buffer); +sha256_process (ctx, ctx->buffer,1 ); length -= fill; input += fill; left =0 ; } -while (length >=64 ) { -sha256_process (ctx, input); - length -=64 ; - input +=64 ; - } +sha256_process (ctx, input, length /64 ); + input += length /64 *64 ; + length = length %64 ;Quoted 7 lines
Quoted 5 lines
lib/sha256.c +0
-1if (length)memcpy ((void *) (ctx->buffer + left), (void *) input, length); --2.7.4
I just came across this patch as it broke minnowmax.
Ok, is it a build time or runtime break?
Quoted 8 lines
Quoted 4 lines
Build, but you need the binary blobs to see it :-(
Quoted 3 lines
Quoted 3 lines
This should be using driver model, not weak functions. Please can you take a look?
Just tested the minnowmax build (
b69026c91f2e;minnowmax_defconfig; gcc-11.3.0), and I've not observed any issue (but I had to fake some of the binary blobs...). Could you share the build problem/error youUnfortunately you need the blobs!
Quoted 7 lines
Quoted 3 lines
encountered? As you mentioned it, Is the error specifically related to
_weakfunction linking? Would like to have a simple and quick fix before trying to move on to a more proper DM based solution.It is just because of the code size increase, I believe. I am planning to dig into it a bit as Bin Meng asked for more info as to why I sent a revert for his patch moving U-Boot.
That honestly makes more sense, having stared at the commit in question. Perhaps Minnow needs LTO enabled.
Signature · 1 line
Tom
Re: [PATCH v2 4/5] lib: sha256: Add support for hardware specific sha256_process
Hi Tom,
Quoted 92 lines · Tom Rini
Quoted 90 lines · Simon Glass
Hi Loic,
Quoted 72 lines · Loic Poulain
Hi Simon,
Quoted 21 lines · Simon Glass
Hi Loic,
Quoted 17 lines · Loic Poulain
Hi Simon,
Quoted 13 lines · Simon Glass
Hi Loic,
Quoted 9 lines · Loic Poulain
Mark
sha256_processas weak to allow hardware specific implementation. Add parameter for supporting multiple blocks processing.Signed-off-by Loic Poulain <[email protected]>--- lib/sha256.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)[...]
Quoted 46 lines
Quoted 45 lines
Quoted 35 lines
Quoted 35 lines
(quoted diff) +16
-6+__weak void sha256_process(sha256_context *ctx, const unsigned char *data, + unsigned int blocks) +{ + if (!blocks) + return; + + while (blocks--) { + sha256_process_one(ctx, data); + data += 64; + } +} + void sha256_update(sha256_context *ctx, const uint8_t *input, uint32_t length) { uint32_t left, fill;@@ -204,17 +218,15 @@ void sha256_update(sha256_context *ctx, const uint8_t *input, uint32_t length) if (left && length >= fill) { memcpy((void *) (ctx->buffer + left), (void *) input, fill); - sha256_process(ctx, ctx->buffer); + sha256_process(ctx, ctx->buffer, 1); length -= fill; input += fill; left = 0; } - while (length >= 64) { - sha256_process(ctx, input); - length -= 64; - input += 64; - } + sha256_process(ctx, input, length / 64); + input += length / 64 * 64; + length = length % 64;Quoted 7 lines
Quoted 5 lines
(quoted diff) +0
-1if (length) memcpy((void *) (ctx->buffer + left), (void *) input, length); --2.7.4
I just came across this patch as it broke minnowmax.
Ok, is it a build time or runtime break?
Quoted 8 lines
Quoted 4 lines
Build, but you need the binary blobs to see it :-(
Quoted 3 lines
Quoted 3 lines
This should be using driver model, not weak functions. Please can you take a look?
Just tested the minnowmax build (
b69026c91f2e;minnowmax_defconfig; gcc-11.3.0), and I've not observed any issue (but I had to fake some of the binary blobs...). Could you share the build problem/error youUnfortunately you need the blobs!
Quoted 3 lines
encountered? As you mentioned it, Is the error specifically related to
_weakfunction linking? Would like to have a simple and quick fix before trying to move on to a more proper DM based solution.
Quoted 6 lines
Quoted 3 lines
It is just because of the code size increase, I believe. I am planning to dig into it a bit as Bin Meng asked for more info as to why I sent a revert for his patch moving U-Boot.
That honestly makes more sense, having stared at the commit in question. Perhaps Minnow needs LTO enabled.
Yes, that would likely help. But Bin's point is that it should be possible to move the text base.
Anyway, the point of this thread is that this needs to be done as drivers rather than weak functions. Unfortunately hash.c has grown a few appendages...this is yet another.
Regards,
Simon
Re: [PATCH v2 4/5] lib: sha256: Add support for hardware specific sha256_process
Quoted 99 lines · Simon Glass
Hi Tom,
Quoted 96 lines · Tom Rini
Quoted 93 lines · Simon Glass
Hi Loic,
Quoted 72 lines · Loic Poulain
Hi Simon,
Quoted 21 lines · Simon Glass
Hi Loic,
Quoted 17 lines · Loic Poulain
Hi Simon,
Quoted 13 lines · Simon Glass
Hi Loic,
Quoted 9 lines · Loic Poulain
Mark
sha256_processas weak to allow hardware specific implementation. Add parameter for supporting multiple blocks processing.Signed-off-by Loic Poulain <[email protected]>--- lib/sha256.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)[...]
Quoted 46 lines
Quoted 45 lines
Quoted 35 lines
Quoted 35 lines
(quoted diff) +16
-6+__weak void sha256_process(sha256_context *ctx, const unsigned char *data, + unsigned int blocks) +{ + if (!blocks) + return; + + while (blocks--) { + sha256_process_one(ctx, data); + data += 64; + } +} + void sha256_update(sha256_context *ctx, const uint8_t *input, uint32_t length) { uint32_t left, fill;@@ -204,17 +218,15 @@ void sha256_update(sha256_context *ctx, const uint8_t *input, uint32_t length) if (left && length >= fill) { memcpy((void *) (ctx->buffer + left), (void *) input, fill); - sha256_process(ctx, ctx->buffer); + sha256_process(ctx, ctx->buffer, 1); length -= fill; input += fill; left = 0; } - while (length >= 64) { - sha256_process(ctx, input); - length -= 64; - input += 64; - } + sha256_process(ctx, input, length / 64); + input += length / 64 * 64; + length = length % 64;Quoted 7 lines
Quoted 5 lines
(quoted diff) +0
-1if (length) memcpy((void *) (ctx->buffer + left), (void *) input, length); --2.7.4
I just came across this patch as it broke minnowmax.
Ok, is it a build time or runtime break?
Quoted 8 lines
Quoted 4 lines
Build, but you need the binary blobs to see it :-(
Quoted 3 lines
Quoted 3 lines
This should be using driver model, not weak functions. Please can you take a look?
Just tested the minnowmax build (
b69026c91f2e;minnowmax_defconfig; gcc-11.3.0), and I've not observed any issue (but I had to fake some of the binary blobs...). Could you share the build problem/error youUnfortunately you need the blobs!
Quoted 3 lines
encountered? As you mentioned it, Is the error specifically related to
_weakfunction linking? Would like to have a simple and quick fix before trying to move on to a more proper DM based solution.It is just because of the code size increase, I believe. I am planning to dig into it a bit as Bin Meng asked for more info as to why I sent a revert for his patch moving U-Boot.
Quoted 5 lines
Quoted 2 lines
That honestly makes more sense, having stared at the commit in question. Perhaps Minnow needs LTO enabled.
Yes, that would likely help. But Bin's point is that it should be possible to move the text base.
I suspect that might just be more fall-out of the size problem and possibly some hard coded assumptions in the blobs?
Quoted 3 lines
Anyway, the point of this thread is that this needs to be done as drivers rather than weak functions. Unfortunately
hash.chas grown a few appendages...this is yet another.
I don't know, it seems fine, especially since we aren't really talking about a "hash driver" but rather introducing some performance sensitive code.
Signature · 1 line
Tom
PATCH v2 5/5 armv8 SHA-256 using ARMv8 Crypto Extensions
In reply to Loic PoulainThis patch adds support for the SHA-256 Secure Hash Algorithm for CPUs that have support for the SHA-256 part of the ARM v8 Crypto Extensions.
It greatly improves sha-256 based operations, about 17x faster on iMX8M evk board. ~12ms vs ~208ms for a 20MiB kernel sha-256 verification.
asm implementation is a simplified version of the Linux version (from Ard Biesheuvel).
--- arch/arm/cpu/armv8/Kconfig | 4 ++ arch/arm/cpu/armv8/Makefile | 1 + arch/arm/cpu/armv8/sha256_ce_core.S | 134 ++++++++++++++++++++++++++++++++++++ arch/arm/cpu/armv8/sha256_ce_glue.c | 21 ++++++ 4 files changed, 160 insertions(+) create mode 100644 arch/arm/cpu/armv8/sha256_ce_core.S create mode 100644 arch/arm/cpu/armv8/sha256_ce_glue.c
arch/arm/cpu/armv8/Kconfig +4 -0
@@ -180,6 +180,10 @@ config ARMV8_CE_SHA1 bool "SHA-1 digest algorithm (ARMv8 Crypto Extensions)" default y if SHA1 +config ARMV8_CE_SHA256 + bool "SHA-256 digest algorithm (ARMv8 Crypto Extensions)" + default y if SHA256 + endif endif
arch/arm/cpu/armv8/Makefile +1 -0
@@ -45,3 +45,4 @@ obj-$(CONFIG_ARMV8_PSCI) += psci.o obj-$(CONFIG_TARGET_BCMNS3) += bcmns3/ obj-$(CONFIG_XEN) += xen/ obj-$(CONFIG_ARMV8_CE_SHA1) += sha1_ce_glue.o sha1_ce_core.o +obj-$(CONFIG_ARMV8_CE_SHA256) += sha256_ce_glue.o sha256_ce_core.o
arch/arm/cpu/armv8/sha256_ce_core.S new file +134 -0
134 lines not on this page · raw message
arch/arm/cpu/armv8/sha256_ce_glue.c new file +21 -0
@@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* sha256_ce_glue.c - SHA-256 secure hash using ARMv8 Crypto Extensions +* +* Copyright (C) 2022 Linaro Ltd <[email protected]> +*/ + +#include <common.h> +#include <u-boot/sha256.h> + +extern void sha256_armv8_ce_process (uint32_t state[8 ],uint8_t const *src, +uint32_t blocks); + +void sha256_process (sha256_context *ctx,const unsigned char *data, +unsigned int blocks) +{ +if (!blocks) +return ; + +sha256_armv8_ce_process (ctx->state, data, blocks); +}
Signature · 1 line
2.7.4
PATCH 1/1 qemu_arm64: Enable CONFIG_ARMV8_CRYPTO support
Now that we can make use of CPU features for sha1/sha256, enable in QEMU so that we get some test coverage.
--- configs/qemu_arm64_defconfig | 1 + 1 file changed, 1 insertion(+)
configs/qemu_arm64_defconfig +1 -0
@@ -8,6 +8,7 @@ CONFIG_ENV_SECT_SIZE=0x40000 CONFIG_DEFAULT_DEVICE_TREE="qemu-arm64" CONFIG_DEBUG_UART_BASE=0x9000000 CONFIG_DEBUG_UART_CLOCK=0 +CONFIG_ARMV8_CRYPTO=y CONFIG_SYS_LOAD_ADDR=0x40200000 CONFIG_ENV_ADDR=0x4000000 CONFIG_DEBUG_UART=y
Signature · 1 line
2.25.1
Re: [PATCH] qemu_arm64: Enable CONFIG_ARMV8_CRYPTO support
Quoted 6 lines · Tom Rini
Now that we can make use of CPU features for sha1/sha256, enable in QEMU so that we get some test coverage.
Cc Loic Poulain <[email protected]>Cc Tuomas Tynkkynen <[email protected]>Signed-off-by Tom Rini <[email protected]>
Applied to u-boot/next, thanks!
Signature · 1 line
Tom
Re: [PATCH v2 5/5] armv8 SHA-256 using ARMv8 Crypto Extensions
In reply to Loic PoulainQuoted 10 lines · Loic Poulain
This patch adds support for the SHA-256 Secure Hash Algorithm for CPUs that have support for the SHA-256 part of the ARM v8 Crypto Extensions.
It greatly improves sha-256 based operations, about 17x faster on iMX8M evk board. ~12ms vs ~208ms for a 20MiB kernel sha-256 verification.
asm implementation is a simplified version of the Linux version (from Ard Biesheuvel).
Signed-off-by Loic Poulain <[email protected]>
Applied to u-boot/next, thanks!
Signature · 1 line
Tom
Hi Folks,
Any comments on this series? Anyone else to CC?
Thanks,
Loic
Quoted 34 lines · Loic Poulain
This series adds support for the SHA-1 and SHA-256 Secure Hash Algorithm for CPUs that have support of the ARM v8 Crypto Extensions. It Improves speed of integrity & signature checking procedures.
V2:
- Add cover letter & sha256 support.
-Kconfigdefault 'y' only if SHA1 and SHA256 selectedLoic Poulain (5):
lib: sha1: Add support for hardware specificsha1_process
sha1: Fix digest state size/type
armv8 SHA-1 using ARMv8 Crypto Extensions:
lib: sha256: Add support for hardware specificsha256_processarmv8 SHA-256 using ARMv8 Crypto Extensionsarch/arm/cpu/armv8/Kconfig | 15 ++++ arch/arm/cpu/armv8/Makefile | 2 + arch/arm/cpu/armv8/sha1_ce_core.S | 132 +++++++++++++++++++++++++++++++++++ arch/arm/cpu/armv8/sha1_ce_glue.c | 21 ++++++ arch/arm/cpu/armv8/sha256_ce_core.S | 134 ++++++++++++++++++++++++++++++++++++ arch/arm/cpu/armv8/sha256_ce_glue.c | 21 ++++++ include/u-boot/sha1.h | 2 +- lib/sha1.c | 26 +++++-- lib/sha256.c | 26 +++++-- 9 files changed, 364 insertions(+), 15 deletions(-) create mode 100644 arch/arm/cpu/armv8/sha1_ce_core.S create mode 100644 arch/arm/cpu/armv8/sha1_ce_glue.c create mode 100644 arch/arm/cpu/armv8/sha256_ce_core.S create mode 100644 arch/arm/cpu/armv8/sha256_ce_glue.c--
2.7.4
Quoted 3 lines · Loic Poulain
Hi Folks,
Any comments on this series? Anyone else to CC?
I will likely pick this up for next soon, thanks.
Signature · 1 line
Tom