Make CTR mode behaviour consistent with other modes:
[openssl.git] / crypto / engine / eng_rsax.c
index cbe8419a4c0171c50387b53cc5ffce2bb8009301..173aaf8d34ca168474e9e2d839d95ba47a1cc930 100644 (file)
@@ -163,7 +163,6 @@ static int bind_helper(ENGINE *e)
        e_rsax_rsa.rsa_priv_enc = meth1->rsa_priv_enc;
        e_rsax_rsa.rsa_priv_dec = meth1->rsa_priv_dec;
        e_rsax_rsa.bn_mod_exp = meth1->bn_mod_exp;
-       e_rsax_rsa.finish = meth1->finish;
 #endif
        return 1;
        }
@@ -306,10 +305,17 @@ static E_RSAX_MOD_CTX *e_rsax_get_ctx(RSA *rsa, int idx, BIGNUM* m)
 static int e_rsax_rsa_finish(RSA *rsa)
        {
        E_RSAX_MOD_CTX *hptr = RSA_get_ex_data(rsa, rsax_ex_data_idx);
-       if(!hptr) return 0;
-
-       OPENSSL_free(hptr);
-       RSA_set_ex_data(rsa, rsax_ex_data_idx, NULL);
+       if(hptr)
+               {
+               OPENSSL_free(hptr);
+               RSA_set_ex_data(rsa, rsax_ex_data_idx, NULL);
+               }
+       if (rsa->_method_mod_n)
+               BN_MONT_CTX_free(rsa->_method_mod_n);
+       if (rsa->_method_mod_p)
+               BN_MONT_CTX_free(rsa->_method_mod_p);
+       if (rsa->_method_mod_q)
+               BN_MONT_CTX_free(rsa->_method_mod_q);
        return 1;
        }
 
@@ -393,7 +399,6 @@ static int mod_exp_pre_compute_data_512(UINT64 *m, struct mod_ctx_512 *data)
     /* Some tmps */
     UINT64 _t[8];
     int i, j, ret = 0;
-
     /* Init _m with m */
     BN_init(&_m);
     interleaved_array_to_bn_512(&_m, m);
@@ -468,7 +473,7 @@ static int mod_exp_pre_compute_data_512(UINT64 *m, struct mod_ctx_512 *data)
 err:
     /* Cleanup */
        if (ctx != NULL) {
-               BN_CTX_end(ctx); }
+               BN_CTX_end(ctx); BN_CTX_free(ctx); }
     BN_free(&two_768);
     BN_free(&two_640);
     BN_free(&two_128);
@@ -487,7 +492,6 @@ static int e_rsax_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx
        BIGNUM local_dmp1,local_dmq1,local_c,local_r1;
        BIGNUM *dmp1,*dmq1,*c,*pr1;
        int ret=0;
-
        BN_CTX_start(ctx);
        r1 = BN_CTX_get(ctx);
        m1 = BN_CTX_get(ctx);