BN_legendre is no longer needed now that OpenSSL has BN_kronecker.
[openssl.git] / crypto / sha / sha_locl.h
index 6f64e57627570083938dfd1d81a4213ddfe7d90e..2f8aef83f38d263e10726a8af1a00e4078932e09 100644 (file)
 #define HASH_CBLOCK             SHA_CBLOCK
 #define HASH_LBLOCK             SHA_LBLOCK
 #define HASH_MAKE_STRING(c,s)   do {   \
-       unsigned long l               \
-       l=(c)->h0; HOST_l2c(l,(s));     \
-       l=(c)->h1; HOST_l2c(l,(s));     \
-       l=(c)->h2; HOST_l2c(l,(s));     \
-       l=(c)->h3; HOST_l2c(l,(s));     \
-       l=(c)->h4; HOST_l2c(l,(s));     \
+       unsigned long ll;               \
+       ll=(c)->h0; HOST_l2c(ll,(s));   \
+       ll=(c)->h1; HOST_l2c(ll,(s));   \
+       ll=(c)->h2; HOST_l2c(ll,(s));   \
+       ll=(c)->h3; HOST_l2c(ll,(s));   \
+       ll=(c)->h4; HOST_l2c(ll,(s));   \
        } while (0)
 
 #if defined(SHA_0)
 # define HASH_INIT                     SHA1_Init
 # define HASH_BLOCK_HOST_ORDER         sha1_block_host_order
 # define HASH_BLOCK_DATA_ORDER         sha1_block_data_order
-# define Xupdate(a,ix,ia,ib,ic,id)     ( (a)=(ia^ib^ic^id),    \
+# if defined(__MWERKS__) && defined(__MC68K__)
+   /* Metrowerks for Motorola fails otherwise:-( <appro@fy.chalmers.se> */
+#  define Xupdate(a,ix,ia,ib,ic,id)    do { (a)=(ia^ib^ic^id);         \
+                                            ix=(a)=ROTATE((a),1);      \
+                                       } while (0)
+# else
+#  define Xupdate(a,ix,ia,ib,ic,id)    ( (a)=(ia^ib^ic^id),    \
                                          ix=(a)=ROTATE((a),1)  \
                                        )
+# endif
 
 # ifdef SHA1_ASM
 #  if defined(__i386) || defined(_M_IX86) || defined(__INTEL__)
 # error "Either SHA_0 or SHA_1 must be defined."
 #endif
 
-#ifndef FLAT_INC
-#include "../md32_common.h"
-#else
 #include "md32_common.h"
-#endif
 
 #define INIT_DATA_h0 0x67452301UL
 #define INIT_DATA_h1 0xefcdab89UL
@@ -193,18 +196,39 @@ void HASH_INIT (SHA_CTX *c)
        (f)=xa+(e)+K_60_79+ROTATE((a),5)+F_60_79((b),(c),(d)); \
        (b)=ROTATE((b),30);
 
+#ifdef X
+#undef X
+#endif
+#ifndef MD32_XARRAY
+  /*
+   * Originally X was an array. As it's automatic it's natural
+   * to expect RISC compiler to accomodate at least part of it in
+   * the register bank, isn't it? Unfortunately not all compilers
+   * "find" this expectation reasonable:-( On order to make such
+   * compilers generate better code I replace X[] with a bunch of
+   * X0, X1, etc. See the function body below...
+   *                                   <appro@fy.chalmers.se>
+   */
+# define X(i)  XX##i
+#else
+  /*
+   * However! Some compilers (most notably HP C) get overwhelmed by
+   * that many local variables so that we have to have the way to
+   * fall down to the original behavior.
+   */
+# define X(i)  XX[i]
+#endif
+
 #ifndef DONT_IMPLEMENT_BLOCK_HOST_ORDER
 void HASH_BLOCK_HOST_ORDER (SHA_CTX *c, const void *d, int num)
        {
        const SHA_LONG *W=d;
        register unsigned long A,B,C,D,E,T;
-#ifdef SHA_XARRAY
-       SHA_LONG        X[16];
-# define X(i) X[(i)]
+#ifndef MD32_XARRAY
+       unsigned long   XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
+                       XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
 #else
-       unsigned long    X0, X1, X2, X3, X4, X5, X6, X7,
-                        X8, X9,X10,X11,X12,X13,X14,X15;
-# define X(i) X##i
+       SHA_LONG        XX[16];
 #endif
 
        A=c->h0;
@@ -325,13 +349,11 @@ void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, int num)
        {
        const unsigned char *data=p;
        register unsigned long A,B,C,D,E,T,l;
-#ifdef SHA_XARRAY
-       SHA_LONG        X[16];
-# define X(i) X[(i)]
+#ifndef MD32_XARRAY
+       unsigned long   XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
+                       XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
 #else
-       unsigned long    X0, X1, X2, X3, X4, X5, X6, X7,
-                        X8, X9,X10,X11,X12,X13,X14,X15;
-# define X(i) X##i
+       SHA_LONG        XX[16];
 #endif
 
        A=c->h0;