Fix WIN32 build by disabling bn* calls.
[oweals/openssl.git] / crypto / bn / bn_nist.c
index bf8930fd3f32f700903d84f06a931f039bcc8af1..a5e07acd851a8d77b35f7af5418117bcbd1b6093 100644 (file)
@@ -306,29 +306,25 @@ const BIGNUM *BN_get0_nist_prime_521(void)
        }
 
 
-static void nist_cp_bn_0(BN_ULONG *buf, const BN_ULONG *a, int top, int max)
+static void nist_cp_bn_0(BN_ULONG *dst, const BN_ULONG *src, int top, int max)
        {
        int i;
-       BN_ULONG *_tmp1 = (buf);
-       const BN_ULONG *_tmp2 = (a);
 
 #ifdef BN_DEBUG
        OPENSSL_assert(top <= max);
 #endif
-       for (i = (top); i != 0; i--)
-               *_tmp1++ = *_tmp2++;
-       for (i = (max) - (top); i != 0; i--)
-               *_tmp1++ = (BN_ULONG) 0;
+       for (i = 0; i < top; i++)
+               dst[i] = src[i];
+       for (; i < max; i++)
+               dst[i] = 0;
        }
 
-static void nist_cp_bn(BN_ULONG *buf, const BN_ULONG *a, int top)
+static void nist_cp_bn(BN_ULONG *dst, const BN_ULONG *src, int top)
        { 
        int i;
-       BN_ULONG *_tmp1 = (buf);
-       const BN_ULONG *_tmp2 = (a);
 
-       for (i = (top); i != 0; i--)
-               *_tmp1++ = *_tmp2++;
+       for (i = 0; i < top; i++)
+               dst[i] = src[i];
        }
 
 #if BN_BITS2 == 64
@@ -1112,9 +1108,20 @@ int BN_nist_mod_521(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
        /* ... and right shift */
        for (val=t_d[0],i=0; i<BN_NIST_521_TOP-1; i++)
                {
+#if 0
+               /*
+                * MSC ARM compiler [version 2013, presumably even earlier,
+                * much earlier] miscompiles this code, but not one in
+                * #else section. See RT#3541.
+                */
                tmp = val>>BN_NIST_521_RSHIFT;
                val = t_d[i+1];
                t_d[i] = (tmp | val<<BN_NIST_521_LSHIFT) & BN_MASK2;
+#else
+               t_d[i] = ( val>>BN_NIST_521_RSHIFT |
+                         (tmp=t_d[i+1])<<BN_NIST_521_LSHIFT ) & BN_MASK2;
+               val=tmp;
+#endif
                }
        t_d[i] = val>>BN_NIST_521_RSHIFT;
        /* lower 521 bits */