diff options
author | Mamone Tarsha <maamoun.tk@googlemail.com> | 2021-07-03 14:46:30 +0300 |
---|---|---|
committer | Mamone Tarsha <maamoun.tk@googlemail.com> | 2021-07-03 14:46:30 +0300 |
commit | 7b4463279c7d9e41cf168212e26879755c98428c (patch) | |
tree | 5436b8a1ce61526f19e9981dbce33900216c21b0 | |
parent | d1c8417f680e0a16c31a4bcb882d90b38c81274b (diff) | |
download | nettle-7b4463279c7d9e41cf168212e26879755c98428c.tar.gz |
[AArch64] Fat build support for SHA-256 compress
-rw-r--r-- | arm64/fat/sha256-compress-2.asm | 37 | ||||
-rw-r--r-- | fat-arm64.c | 35 |
2 files changed, 69 insertions, 3 deletions
diff --git a/arm64/fat/sha256-compress-2.asm b/arm64/fat/sha256-compress-2.asm new file mode 100644 index 00000000..67590794 --- /dev/null +++ b/arm64/fat/sha256-compress-2.asm @@ -0,0 +1,37 @@ +C arm64/fat/sha256-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_sha256_compress) picked up by configure + +define(`fat_transform', `$1_arm64') +include_src(`arm64/crypto/sha256-compress.asm') diff --git a/fat-arm64.c b/fat-arm64.c index 914495c8..9bcb208a 100644 --- a/fat-arm64.c +++ b/fat-arm64.c @@ -64,11 +64,15 @@ #ifndef HWCAP_SHA1 #define HWCAP_SHA1 (1 << 5) #endif +#ifndef HWCAP_SHA2 +#define HWCAP_SHA2 (1 << 6) +#endif struct arm64_features { int have_pmull; int have_sha1; + int have_sha2; }; #define MATCH(s, slen, literal, llen) \ @@ -80,6 +84,7 @@ get_arm64_features (struct arm64_features *features) const char *s; features->have_pmull = 0; features->have_sha1 = 0; + features->have_sha2 = 0; s = secure_getenv (ENV_OVERRIDE); if (s) @@ -90,8 +95,10 @@ get_arm64_features (struct arm64_features *features) if (MATCH (s, length, "pmull", 5)) features->have_pmull = 1; - else if (MATCH (s, length, "sha1", 4)) + else if (MATCH (s, length, "sha1", 4)) features->have_sha1 = 1; + else if (MATCH (s, length, "sha2", 4)) + features->have_sha2 = 1; if (!sep) break; s = sep + 1; @@ -104,6 +111,8 @@ get_arm64_features (struct arm64_features *features) = ((hwcap & (HWCAP_ASIMD | HWCAP_PMULL)) == (HWCAP_ASIMD | HWCAP_PMULL)); features->have_sha1 = ((hwcap & (HWCAP_ASIMD | HWCAP_SHA1)) == (HWCAP_ASIMD | HWCAP_SHA1)); + features->have_sha2 + = ((hwcap & (HWCAP_ASIMD | HWCAP_SHA2)) == (HWCAP_ASIMD | HWCAP_SHA2)); #endif } } @@ -122,6 +131,10 @@ 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) + static void CONSTRUCTOR fat_init (void) { @@ -132,9 +145,11 @@ fat_init (void) verbose = getenv (ENV_VERBOSE) != NULL; if (verbose) - fprintf (stderr, "libnettle: cpu features:%s%s\n", + fprintf (stderr, "libnettle: cpu features:%s%s%s\n", features.have_pmull ? " polynomial multiply long instructions (PMULL/PMULL2)" : "", - features.have_sha1 ? " sha1 instructions" : ""); + features.have_sha1 ? " sha1 instructions" : "", + features.have_sha2 ? " sha2 instructions" : ""); + if (features.have_pmull) { if (verbose) @@ -165,6 +180,16 @@ fat_init (void) { nettle_sha1_compress_vec = _nettle_sha1_compress_c; } + if (features.have_sha2) + { + if (verbose) + fprintf (stderr, "libnettle: enabling hardware-accelerated sha256 compress code.\n"); + _nettle_sha256_compress_vec = _nettle_sha256_compress_arm64; + } + else + { + _nettle_sha256_compress_vec = _nettle_sha256_compress_c; + } } #if GCM_TABLE_BITS == 8 @@ -181,3 +206,7 @@ DEFINE_FAT_FUNC(_nettle_gcm_hash, void, 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)) |