summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels Möller <nisse@lysator.liu.se>2022-07-11 10:41:01 +0200
committerNiels Möller <nisse@lysator.liu.se>2022-07-11 10:41:01 +0200
commitdba9cacc4757df033034978e1959a1564345ae07 (patch)
tree73aca51ab86da8094cce7d254db55b60a4b475e0
parent67a56f3ae0833b49c1c212a95f9bdb49ff4ceabe (diff)
downloadnettle-dba9cacc4757df033034978e1959a1564345ae07.tar.gz
arm64: Implement sha256_compress_n
-rw-r--r--ChangeLog8
-rw-r--r--arm64/crypto/sha256-compress-n.asm (renamed from arm64/crypto/sha256-compress.asm)31
-rw-r--r--arm64/fat/sha256-compress-n-2.asm (renamed from arm64/fat/sha256-compress-2.asm)6
-rw-r--r--fat-arm64.c17
4 files changed, 40 insertions, 22 deletions
diff --git a/ChangeLog b/ChangeLog
index 643c38b4..a2cdefa0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2022-07-11 Niels Möller <nisse@lysator.liu.se>
+
+ * arm64/crypto/sha256-compress-n.asm: New file. replacing...
+ * arm64/crypto/sha256-compress.asm: ...deleted file.
+ * arm64/fat/sha256-compress-n-2.asm: New file. replacing...
+ * arm64/fat/sha256-compress-2.asm: ...deleted file.
+ * fat-arm64.c: Update fat setup.
+
2022-07-05 Niels Möller <nisse@lysator.liu.se>
* md-internal.h (MD_FILL_OR_RETURN): New file, new macro.
diff --git a/arm64/crypto/sha256-compress.asm b/arm64/crypto/sha256-compress-n.asm
index 2bddea05..447dc590 100644
--- a/arm64/crypto/sha256-compress.asm
+++ b/arm64/crypto/sha256-compress-n.asm
@@ -1,4 +1,4 @@
-C arm64/crypto/sha256-compress.asm
+C arm64/crypto/sha256-compress-n.asm
ifelse(`
Copyright (C) 2021 Mamone Tarsha
@@ -37,7 +37,7 @@ C SHA256H2: SHA256 hash update (part 2)
C SHA256SU0: SHA256 schedule update 0
C SHA256SU1: SHA256 schedule update 1
-.file "sha256-compress.asm"
+.file "sha256-compress-n.asm"
.arch armv8-a+crypto
.text
@@ -45,8 +45,9 @@ C SHA256SU1: SHA256 schedule update 1
C Register usage:
define(`STATE', `x0')
-define(`INPUT', `x1')
-define(`K', `x2')
+define(`K', `x1')
+define(`BLOCKS', `x2')
+define(`INPUT', `x3')
define(`MSG0', `v0')
define(`MSG1', `v1')
@@ -59,19 +60,23 @@ define(`TMP', `v7')
define(`STATE0_SAVED', `v16')
define(`STATE1_SAVED', `v17')
-C void
-C _nettle_sha256_compress(uint32_t *state, const uint8_t *input, const uint32_t *k)
+C const uint8_t *
+C _nettle_sha256_compress_n(uint32_t *state, const uint32_t *k,
+C size_t blocks, const uint8_t *input)
+
+PROLOGUE(_nettle_sha256_compress_n)
+ cbz BLOCKS, .Lend
-PROLOGUE(_nettle_sha256_compress)
C Load state
ld1 {STATE0.4s,STATE1.4s},[STATE]
+.Loop:
C Save state
mov STATE0_SAVED.16b,STATE0.16b
mov STATE1_SAVED.16b,STATE1.16b
C Load message
- ld1 {MSG0.16b,MSG1.16b,MSG2.16b,MSG3.16b},[INPUT]
+ ld1 {MSG0.16b,MSG1.16b,MSG2.16b,MSG3.16b},[INPUT],#64
C Reverse for little endian
rev32 MSG0.16b,MSG0.16b
@@ -217,9 +222,13 @@ PROLOGUE(_nettle_sha256_compress)
C Combine state
add STATE0.4s,STATE0.4s,STATE0_SAVED.4s
add STATE1.4s,STATE1.4s,STATE1_SAVED.4s
-
+ subs BLOCKS, BLOCKS, #1
+ sub K, K, #240
+ b.ne .Loop
+
C Store state
st1 {STATE0.4s,STATE1.4s},[STATE]
-
+.Lend:
+ mov x0, INPUT
ret
-EPILOGUE(_nettle_sha256_compress)
+EPILOGUE(_nettle_sha256_compress_n)
diff --git a/arm64/fat/sha256-compress-2.asm b/arm64/fat/sha256-compress-n-2.asm
index 67590794..2f70686e 100644
--- a/arm64/fat/sha256-compress-2.asm
+++ b/arm64/fat/sha256-compress-n-2.asm
@@ -1,4 +1,4 @@
-C arm64/fat/sha256-compress-2.asm
+C arm64/fat/sha256-compress-n-2.asm
ifelse(`
@@ -31,7 +31,7 @@ ifelse(`
not, see http://www.gnu.org/licenses/.
')
-dnl PROLOGUE(_nettle_sha256_compress) picked up by configure
+dnl PROLOGUE(_nettle_sha256_compress_n) picked up by configure
define(`fat_transform', `$1_arm64')
-include_src(`arm64/crypto/sha256-compress.asm')
+include_src(`arm64/crypto/sha256-compress-n.asm')
diff --git a/fat-arm64.c b/fat-arm64.c
index f2b8493d..aec99f66 100644
--- a/fat-arm64.c
+++ b/fat-arm64.c
@@ -178,9 +178,9 @@ DECLARE_FAT_FUNC(nettle_sha1_compress, sha1_compress_func)
DECLARE_FAT_FUNC_VAR(sha1_compress, sha1_compress_func, c)
DECLARE_FAT_FUNC_VAR(sha1_compress, sha1_compress_func, arm64)
-DECLARE_FAT_FUNC(_nettle_sha256_compress, sha256_compress_func)
-DECLARE_FAT_FUNC_VAR(sha256_compress, sha256_compress_func, c)
-DECLARE_FAT_FUNC_VAR(sha256_compress, sha256_compress_func, arm64)
+DECLARE_FAT_FUNC(_nettle_sha256_compress_n, sha256_compress_n_func)
+DECLARE_FAT_FUNC_VAR(sha256_compress_n, sha256_compress_n_func, c)
+DECLARE_FAT_FUNC_VAR(sha256_compress_n, sha256_compress_n_func, arm64)
static void CONSTRUCTOR
fat_init (void)
@@ -250,11 +250,11 @@ fat_init (void)
{
if (verbose)
fprintf (stderr, "libnettle: enabling hardware-accelerated sha256 compress code.\n");
- _nettle_sha256_compress_vec = _nettle_sha256_compress_arm64;
+ _nettle_sha256_compress_n_vec = _nettle_sha256_compress_n_arm64;
}
else
{
- _nettle_sha256_compress_vec = _nettle_sha256_compress_c;
+ _nettle_sha256_compress_n_vec = _nettle_sha256_compress_n_c;
}
}
@@ -297,6 +297,7 @@ DEFINE_FAT_FUNC(nettle_sha1_compress, void,
(uint32_t *state, const uint8_t *input),
(state, input))
-DEFINE_FAT_FUNC(_nettle_sha256_compress, void,
- (uint32_t *state, const uint8_t *input, const uint32_t *k),
- (state, input, k))
+DEFINE_FAT_FUNC(_nettle_sha256_compress_n, const uint8_t *,
+ (uint32_t *state, const uint32_t *k,
+ size_t blocks, const uint8_t *input),
+ (state, k, blocks, input))