Преглед на файлове

Updating code to enable SHA-256 hardware acceleration + But not enabling it really as we do not have HW to test it on

(for the same reason I didn't even try to update SHA-1 code)

Source commit: 8bad4bbff1f80e108d19ae7ddc6f5fe67acc571e
Martin Prikryl преди 6 години
родител
ревизия
77e41af0e8
променени са 2 файла, в които са добавени 30 реда и са изтрити 12 реда
  1. 4 0
      source/putty/ssh.h
  2. 26 12
      source/putty/sshsh256.c

+ 4 - 0
source/putty/ssh.h

@@ -677,6 +677,8 @@ bool ssh2_mac_verify(ssh2_mac *, const void *, int, unsigned long seq);
  * string with a given key in the most obvious way. */
 void mac_simple(const ssh2_macalg *alg, ptrlen key, ptrlen data, void *output);
 
+#endif // !WINSCP_VS
+
 struct ssh_hash {
     const ssh_hashalg *vt;
     BinarySink_DELEGATE_IMPLEMENTATION;
@@ -692,6 +694,8 @@ struct ssh_hashalg {
     const char *text_name;
 };
 
+#ifndef WINSCP_VS
+
 #define ssh_hash_new(alg) ((alg)->new(alg))
 #define ssh_hash_copy(ctx) ((ctx)->vt->copy(ctx))
 #define ssh_hash_final(ctx, out) ((ctx)->vt->final(ctx, out))

+ 26 - 12
source/putty/sshsh256.c

@@ -31,6 +31,7 @@
 #   endif
 #endif
 
+// Should be working (when set to HW_SHA256_NI), but we do not have a HW to test this on
 #undef HW_SHA256
 
 #if defined _FORCE_SOFTWARE_SHA || !defined HW_SHA256
@@ -44,13 +45,13 @@
  * The actual query function that asks if hardware acceleration is
  * available.
  */
-static bool sha256_hw_available(void);
+bool sha256_hw_available(void);
 
 /*
  * The top-level selection function, caching the results of
  * sha256_hw_available() so it only has to run once.
  */
-static bool sha256_hw_available_cached(void)
+/*WINSCP static*/ bool sha256_hw_available_cached(void)
 {
     static bool initialised = false;
     static bool hw_available;
@@ -74,6 +75,10 @@ const ssh_hashalg ssh_sha256 = {
     32, 64, "SHA-256",
 };
 
+#else
+
+bool sha256_hw_available_cached(void);
+
 #endif
 
 /* ----------------------------------------------------------------------
@@ -325,6 +330,8 @@ const ssh_hashalg ssh_sha256_sw = {
 
 #if HW_SHA256 == HW_SHA256_NI
 
+#ifdef WINSCP_VS
+
 /*
  * Set target architecture for Clang and GCC
  */
@@ -357,7 +364,7 @@ const ssh_hashalg ssh_sha256_sw = {
 #define GET_CPU_ID_7(out) __cpuidex(out, 7, 0)
 #endif
 
-static bool sha256_hw_available(void)
+/*WINSCP static*/ bool sha256_hw_available(void)
 {
     unsigned int CPUInfo[4];
     GET_CPU_ID_0(CPUInfo);  
@@ -592,7 +599,7 @@ static sha256_ni *sha256_ni_alloc(void)
     return s;
 }
 
-FUNC_ISA static ssh_hash *sha256_ni_new(const ssh_hashalg *alg)
+FUNC_ISA /*WINSCP static*/ ssh_hash *sha256_ni_new(const ssh_hashalg *alg)
 {
     if (!sha256_hw_available_cached())
         return NULL;
@@ -613,7 +620,7 @@ FUNC_ISA static ssh_hash *sha256_ni_new(const ssh_hashalg *alg)
     return &s->hash;
 }
 
-static ssh_hash *sha256_ni_copy(ssh_hash *hash)
+/*WINSCP static*/ ssh_hash *sha256_ni_copy(ssh_hash *hash)
 {
     sha256_ni *s = container_of(hash, sha256_ni, hash);
     sha256_ni *copy = sha256_ni_alloc();
@@ -628,7 +635,7 @@ static ssh_hash *sha256_ni_copy(ssh_hash *hash)
     return &copy->hash;
 }
 
-static void sha256_ni_free(ssh_hash *hash)
+/*WINSCP static*/ void sha256_ni_free(ssh_hash *hash)
 {
     sha256_ni *s = container_of(hash, sha256_ni, hash);
 
@@ -646,7 +653,7 @@ static void sha256_ni_write(BinarySink *bs, const void *vp, size_t len)
             sha256_ni_block(s->core, s->blk.block);
 }
 
-FUNC_ISA static void sha256_ni_final(ssh_hash *hash, uint8_t *digest)
+FUNC_ISA /*WINSCP static*/ void sha256_ni_final(ssh_hash *hash, uint8_t *digest)
 {
     sha256_ni *s = container_of(hash, sha256_ni, hash);
 
@@ -671,11 +678,22 @@ FUNC_ISA static void sha256_ni_final(ssh_hash *hash, uint8_t *digest)
     sha256_ni_free(hash);
 }
 
+#endif // WINSCP_VS
+
+#ifndef WINSCP_VS
+
+ssh_hash *sha256_ni_new(const ssh_hashalg *alg);
+ssh_hash *sha256_ni_copy(ssh_hash *hash);
+void sha256_ni_final(ssh_hash *hash, uint8_t *digest);
+void sha256_ni_free(ssh_hash *hash);
+
 const ssh_hashalg ssh_sha256_hw = {
     sha256_ni_new, sha256_ni_copy, sha256_ni_final, sha256_ni_free,
     32, 64, "SHA-256",
 };
 
+#endif
+
 /* ----------------------------------------------------------------------
  * Stub functions if we have no hardware-accelerated SHA-256. In this
  * case, sha256_hw_new returns NULL (though it should also never be
@@ -686,8 +704,6 @@ const ssh_hashalg ssh_sha256_hw = {
 
 #elif HW_SHA256 == HW_SHA256_NONE
 
-#ifndef WINSCP_VS
-
 static bool sha256_hw_available(void)
 {
     return false;
@@ -700,7 +716,7 @@ static ssh_hash *sha256_stub_new(const ssh_hashalg *alg)
 
 #define STUB_BODY { unreachable("Should never be called"); }
 
-static ssh_hash *sha256_stub_copy(ssh_hash *hash) STUB_BODY
+static ssh_hash *sha256_stub_copy(ssh_hash *hash) { STUB_BODY; return NULL; }
 static void sha256_stub_free(ssh_hash *hash) STUB_BODY
 static void sha256_stub_final(ssh_hash *hash, uint8_t *digest) STUB_BODY
 
@@ -709,6 +725,4 @@ const ssh_hashalg ssh_sha256_hw = {
     32, 64, "SHA-256",
 };
 
-#endif // !WINSCP_VS
-
 #endif /* HW_SHA256 */