Update from 1.0.0-stable.
[openssl.git] / crypto / bn / bn_exp.c
index 8f8c694481911cdc8a71115bdc0ef65abfa555bc..d9b6c737fc82f5f5f8c4bc9a5d7ba23ee8627c73 100644 (file)
@@ -122,9 +122,9 @@ int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
        int i,bits,ret=0;
        BIGNUM *v,*rr;
 
-       if (BN_get_flags(p, BN_FLG_EXP_CONSTTIME) != 0)
+       if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0)
                {
-               /* BN_FLG_EXP_CONSTTIME only supported by BN_mod_exp_mont() */
+               /* BN_FLG_CONSTTIME only supported by BN_mod_exp_mont() */
                BNerr(BN_F_BN_EXP,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
                return -1;
                }
@@ -134,7 +134,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);
@@ -213,7 +214,7 @@ int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
        if (BN_is_odd(m))
                {
 #  ifdef MONT_EXP_WORD
-               if (a->top == 1 && !a->neg && (BN_get_flags(p, BN_FLG_EXP_CONSTTIME) == 0))
+               if (a->top == 1 && !a->neg && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0))
                        {
                        BN_ULONG A = a->d[0];
                        ret=BN_mod_exp_mont_word(r,A,p,m,ctx,NULL);
@@ -245,9 +246,9 @@ int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
        BIGNUM *val[TABLE_SIZE];
        BN_RECP_CTX recp;
 
-       if (BN_get_flags(p, BN_FLG_EXP_CONSTTIME) != 0)
+       if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0)
                {
-               /* BN_FLG_EXP_CONSTTIME only supported by BN_mod_exp_mont() */
+               /* BN_FLG_CONSTTIME only supported by BN_mod_exp_mont() */
                BNerr(BN_F_BN_MOD_EXP_RECP,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
                return -1;
                }
@@ -379,7 +380,7 @@ int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
        BIGNUM *val[TABLE_SIZE];
        BN_MONT_CTX *mont=NULL;
 
-       if (BN_get_flags(p, BN_FLG_EXP_CONSTTIME) != 0)
+       if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0)
                {
                return BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont);
                }
@@ -745,9 +746,9 @@ int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,
 #define BN_TO_MONTGOMERY_WORD(r, w, mont) \
                (BN_set_word(r, (w)) && BN_to_montgomery(r, r, (mont), ctx))
 
-       if (BN_get_flags(p, BN_FLG_EXP_CONSTTIME) != 0)
+       if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0)
                {
-               /* BN_FLG_EXP_CONSTTIME only supported by BN_mod_exp_mont() */
+               /* BN_FLG_CONSTTIME only supported by BN_mod_exp_mont() */
                BNerr(BN_F_BN_MOD_EXP_MONT_WORD,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
                return -1;
                }
@@ -881,9 +882,9 @@ int BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
        /* Table of variables obtained from 'ctx' */
        BIGNUM *val[TABLE_SIZE];
 
-       if (BN_get_flags(p, BN_FLG_EXP_CONSTTIME) != 0)
+       if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0)
                {
-               /* BN_FLG_EXP_CONSTTIME only supported by BN_mod_exp_mont() */
+               /* BN_FLG_CONSTTIME only supported by BN_mod_exp_mont() */
                BNerr(BN_F_BN_MOD_EXP_SIMPLE,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
                return -1;
                }