Call fipsas.pl directly for pa-risc targets.
[openssl.git] / crypto / bn / bn_exp.c
index ac590e0f9deb8ba238d5c13bee6fade5c579a8ab..ce31ad0a58a61f74f33fbe12118fedb188ecea3c 100644 (file)
  *
  */
 
+#define OPENSSL_FIPSAPI
 
 #include "cryptlib.h"
 #include "bn_lcl.h"
@@ -134,7 +135,8 @@ int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
                rr = BN_CTX_get(ctx);
        else
                rr = r;
-       if ((v = BN_CTX_get(ctx)) == NULL) goto err;
+       v = BN_CTX_get(ctx);
+       if (rr == NULL || v == NULL) goto err;
 
        if (BN_copy(v,a) == NULL) goto err;
        bits=BN_num_bits(p);
@@ -521,8 +523,7 @@ err:
  * as cache lines are concerned.  The following functions are used to transfer a BIGNUM
  * from/to that table. */
 
-static int MOD_EXP_CTIME_COPY_TO_PREBUF(BIGNUM *b, size_t top,
-                                       unsigned char *buf, int idx, int width)
+static int MOD_EXP_CTIME_COPY_TO_PREBUF(BIGNUM *b, int top, unsigned char *buf, int idx, int width)
        {
        size_t i, j;
 
@@ -542,9 +543,7 @@ static int MOD_EXP_CTIME_COPY_TO_PREBUF(BIGNUM *b, size_t top,
        return 1;
        }
 
-static int MOD_EXP_CTIME_COPY_FROM_PREBUF(BIGNUM *b, size_t top,
-                                         unsigned char *buf, int idx,
-                                         int width)
+static int MOD_EXP_CTIME_COPY_FROM_PREBUF(BIGNUM *b, int top, unsigned char *buf, int idx, int width)
        {
        size_t i, j;
 
@@ -575,14 +574,14 @@ int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
                    const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)
        {
        int i,bits,ret=0,idx,window,wvalue;
-       size_t top;
+       int top;
        BIGNUM *r;
        const BIGNUM *aa;
        BN_MONT_CTX *mont=NULL;
 
        int numPowers;
        unsigned char *powerbufFree=NULL;
-       size_t powerbufLen = 0;
+       int powerbufLen = 0;
        unsigned char *powerbuf=NULL;
        BIGNUM *computeTemp=NULL, *am=NULL;
 
@@ -628,7 +627,7 @@ int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
         */
        numPowers = 1 << window;
        powerbufLen = sizeof(m->d[0])*top*numPowers;
-       if ((powerbufFree=OPENSSL_malloc(powerbufLen+MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH)) == NULL)
+       if ((powerbufFree=(unsigned char*)OPENSSL_malloc(powerbufLen+MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH)) == NULL)
                goto err;
                
        powerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);