bsaes-armv7.pl: closest shave. While 0.3 cpb improvement on S4 appears
[openssl.git] / crypto / engine / eng_rsax.c
index 72185d686bf436dcb7e7481501831e76b37758a6..96e63477eedb277e1059731bd47804aa8be1bb9b 100644 (file)
@@ -226,10 +226,13 @@ static int e_rsax_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
 
 
 #ifndef OPENSSL_NO_RSA
-#include <stdint.h>
 
-typedef uint64_t UINT64;
-typedef uint16_t UINT16;
+#ifdef _WIN32
+typedef unsigned __int64 UINT64;
+#else
+typedef unsigned long long UINT64;
+#endif
+typedef unsigned short UINT16;
 
 /* Table t is interleaved in the following manner:
  * The order in memory is t[0][0], t[0][1], ..., t[0][7], t[1][0], ...
@@ -302,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;
        }
 
@@ -464,7 +474,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);