]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
arm64: Fat build support for SHA1 compress
authorMaamoun TK <maamoun.tk@googlemail.com>
Wed, 30 Jun 2021 18:34:30 +0000 (20:34 +0200)
committerNiels Möller <nisse@lysator.liu.se>
Wed, 30 Jun 2021 18:34:30 +0000 (20:34 +0200)
arm64/fat/sha1-compress-2.asm [new file with mode: 0644]
fat-arm64.c

diff --git a/arm64/fat/sha1-compress-2.asm b/arm64/fat/sha1-compress-2.asm
new file mode 100644 (file)
index 0000000..b53cb63
--- /dev/null
@@ -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')
index 9f81951f33140d726c15c66ef45ea08373acced3..914495c82e57fed248c3a7f40e925b16e2e66e9f 100644 (file)
 #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,9 +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)
     {
       if (verbose)
@@ -142,6 +155,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 +177,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))