Browse Source

move definitions of XASM_LINK() from wolfcrypt/src/aes.c, wolfcrypt/src/asm.c, and wolfcrypt/src/cpuid.c, to wolfssl/wolfcrypt/types.h, and use __asm__() instead of asm() if __GNUC__, for compatibility with -std=c99.

Daniel Pouzzner 10 months ago
parent
commit
59a7c0d7e4
4 changed files with 16 additions and 20 deletions
  1. 0 8
      wolfcrypt/src/aes.c
  2. 0 6
      wolfcrypt/src/asm.c
  3. 0 4
      wolfcrypt/src/cpuid.c
  4. 16 2
      wolfssl/wolfcrypt/types.h

+ 0 - 8
wolfcrypt/src/aes.c

@@ -709,14 +709,6 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
         #define AESNI_ALIGN 16
     #endif
 
-    #ifdef _MSC_VER
-        #define XASM_LINK(f)
-    #elif defined(__APPLE__)
-        #define XASM_LINK(f) asm("_" f)
-    #else
-        #define XASM_LINK(f) asm(f)
-    #endif /* _MSC_VER */
-
     static int checkAESNI = 0;
     static int haveAESNI  = 0;
     static word32 intel_flags = 0;

+ 0 - 6
wolfcrypt/src/asm.c

@@ -46,15 +46,9 @@
             __asm__ __volatile__ ("cpuid":\
              "=a" (reg[0]), "=b" (reg[1]), "=c" (reg[2]), "=d" (reg[3]) :\
              "a" (leaf), "c"(sub));
-
-    #define XASM_LINK(f) asm(f)
 #else
-
     #include <intrin.h>
     #define cpuid(a,b,c) __cpuidex((int*)a,b,c)
-
-    #define XASM_LINK(f)
-
 #endif /* _MSC_VER */
 
 #define EAX 0

+ 0 - 4
wolfcrypt/src/cpuid.c

@@ -43,14 +43,10 @@
             __asm__ __volatile__ ("cpuid":\
                 "=a" ((reg)[0]), "=b" ((reg)[1]), "=c" ((reg)[2]), "=d" ((reg)[3]) :\
                 "a" (leaf), "c"(sub));
-
-        #define XASM_LINK(f) asm(f)
     #else
         #include <intrin.h>
 
         #define cpuid(a,b,c) __cpuidex((int*)a,b,c)
-
-        #define XASM_LINK(f)
     #endif /* _MSC_VER */
 
     #define EAX 0

+ 16 - 2
wolfssl/wolfcrypt/types.h

@@ -1180,8 +1180,22 @@ typedef struct w64wrapper {
     /* invalid device id */
     #define INVALID_DEVID    (-2)
 
-    /* AESNI requires alignment and ARMASM gains some performance from it
-     * Xilinx RSA operations require alignment */
+    #ifdef XASM_LINK
+        /* keep user-supplied definition */
+    #elif defined(_MSC_VER)
+        #define XASM_LINK(f)
+    #elif defined(__APPLE__)
+        #define XASM_LINK(f) asm("_" f)
+    #elif defined(__GNUC__)
+        /* use alternate keyword for compatibility with -std=c99 */
+        #define XASM_LINK(f) __asm__(f)
+    #else
+        #define XASM_LINK(f) asm(f)
+    #endif
+
+    /* AESNI requires alignment and ARMASM gains some performance from it.
+     * Xilinx RSA operations require alignment.
+     */
     #if defined(WOLFSSL_AESNI) || defined(WOLFSSL_ARMASM) || \
         defined(USE_INTEL_SPEEDUP) || defined(WOLFSSL_AFALG_XILINX) || \
         defined(WOLFSSL_XILINX)