OPENSSL_SYS_WIN32 is important so util/mkdef.pl can detect it
[oweals/openssl.git] / crypto / bn / bn_kron.c
index 20b593e6796f30ea29016474905cb107139e9eeb..49f75594aed019f26e8c36ff543432daadb5a919 100644 (file)
@@ -1,5 +1,3 @@
-/* totally untested */
-
 /* crypto/bn/bn_kron.c */
 /* ====================================================================
  * Copyright (c) 1998-2000 The OpenSSL Project.  All rights reserved.
@@ -65,7 +63,7 @@
 int BN_kronecker(const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
        {
        int i;
-       int ret;
+       int ret = -2; /* avoid 'uninitialized' warning */
        int err = 0;
        BIGNUM *A, *B, *tmp;
        /* In 'tab', only odd-indexed entries are relevant:
@@ -165,7 +163,7 @@ int BN_kronecker(const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
        
                /* Cohen's step 4: */
                /* multiply 'ret' by  $(-1)^{(A-1)(B-1)/4}$ */
-               if (BN_lsw(A) & BN_lsw(B) & 2)
+               if ((A->neg ? ~BN_lsw(A) : BN_lsw(A)) & BN_lsw(B) & 2)
                        ret = -ret;
                
                /* (A, B) := (B mod |A|, |A|) */