This patch added fat build support SHA1 compress function using the regular HWCAP features.
--- arm64/fat/sha1-compress-2.asm | 37 +++++++++++++++++++++++++++++++++++++ fat-arm64.c | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 arm64/fat/sha1-compress-2.asm diff --git a/arm64/fat/sha1-compress-2.asm b/arm64/fat/sha1-compress-2.asm new file mode 100644 index 00000000..b53cb63e --- /dev/null +++ b/arm64/fat/sha1-compress-2.asm @@ -0,0 +1,37 @@ +C arm64/fat/sha1-compress-2.asm + + +ifelse(` + Copyright (C) 2021 Mamone Tarsha + + This file is part of GNU Nettle. + + GNU Nettle is free software: you can redistribute it and/or + modify it under the terms of either: + + * the GNU Lesser General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at your + option) any later version. + + or + + * the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at your + option) any later version. + + or both in parallel, as here. + + GNU Nettle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received copies of the GNU General Public License and + the GNU Lesser General Public License along with this program. If + not, see http://www.gnu.org/licenses/. +') + +dnl PROLOGUE(nettle_sha1_compress) picked up by configure + +define(`fat_transform', `_$1_arm64') +include_src(`arm64/crypto/sha1-compress.asm') diff --git a/fat-arm64.c b/fat-arm64.c index 9f81951f..c696e9bb 100644 --- a/fat-arm64.c +++ b/fat-arm64.c @@ -61,10 +61,14 @@ #ifndef HWCAP_PMULL #define HWCAP_PMULL (1 << 4) #endif +#ifndef HWCAP_SHA1 +#define HWCAP_SHA1 (1 << 5) +#endif struct arm64_features { int have_pmull; + int have_sha1; }; #define MATCH(s, slen, literal, llen) \ @@ -75,6 +79,7 @@ get_arm64_features (struct arm64_features *features) { const char *s; features->have_pmull = 0; + features->have_sha1 = 0; s = secure_getenv (ENV_OVERRIDE); if (s) @@ -85,6 +90,8 @@ get_arm64_features (struct arm64_features *features) if (MATCH (s, length, "pmull", 5)) features->have_pmull = 1; + else if (MATCH (s, length, "sha1", 4)) + features->have_sha1 = 1; if (!sep) break; s = sep + 1; @@ -95,6 +102,8 @@ get_arm64_features (struct arm64_features *features) unsigned long hwcap = getauxval(AT_HWCAP); features->have_pmull = ((hwcap & (HWCAP_ASIMD | HWCAP_PMULL)) == (HWCAP_ASIMD | HWCAP_PMULL)); + features->have_sha1 + = ((hwcap & (HWCAP_ASIMD | HWCAP_SHA1)) == (HWCAP_ASIMD | HWCAP_SHA1)); #endif } } @@ -109,6 +118,10 @@ DECLARE_FAT_FUNC_VAR(gcm_hash, gcm_hash_func, c) DECLARE_FAT_FUNC_VAR(gcm_hash, gcm_hash_func, arm64) #endif /* GCM_TABLE_BITS == 8 */ +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) + static void CONSTRUCTOR fat_init (void) { @@ -119,8 +132,9 @@ fat_init (void) verbose = getenv (ENV_VERBOSE) != NULL; if (verbose) - fprintf (stderr, "libnettle: cpu features: %s\n", - features.have_pmull ? "polynomial multiply long instructions (PMULL/PMULL2)" : ""); + fprintf (stderr, "libnettle: cpu features:%s%s\n", + features.have_pmull ? " polynomial multiply long instructions (PMULL/PMULL2)" : "", + features.have_sha1 ? " sha1 instructions" : ""); if (features.have_pmull) { @@ -142,6 +156,16 @@ fat_init (void) _nettle_gcm_hash_vec = _nettle_gcm_hash_c; #endif /* GCM_TABLE_BITS == 8 */ } + if (features.have_sha1) + { + if (verbose) + fprintf (stderr, "libnettle: enabling hardware-accelerated sha1 compress code.\n"); + nettle_sha1_compress_vec = _nettle_sha1_compress_arm64; + } + else + { + nettle_sha1_compress_vec = _nettle_sha1_compress_c; + } } #if GCM_TABLE_BITS == 8 @@ -154,3 +178,7 @@ DEFINE_FAT_FUNC(_nettle_gcm_hash, void, size_t length, const uint8_t *data), (key, x, length, data)) #endif /* GCM_TABLE_BITS == 8 */ + +DEFINE_FAT_FUNC(nettle_sha1_compress, void, + (uint32_t *state, const uint8_t *input), + (state, input)) -- 2.25.1 _______________________________________________ nettle-bugs mailing list nettle-bugs@lists.lysator.liu.se http://lists.lysator.liu.se/mailman/listinfo/nettle-bugs