typo
[openssl.git] / crypto / rsa / rsa_lib.c
index c6b1a5989d988ecc70229b2c0dcbfccb5d7f29f7..bbddd3f0f0bff74f8aa809aa67e7c135dfe96adb 100644 (file)
@@ -81,6 +81,19 @@ void RSA_set_default_method(RSA_METHOD *meth)
 
 RSA_METHOD *RSA_get_default_method(void)
 {
+       if (default_RSA_meth == NULL)
+               {
+#ifdef RSA_NULL
+               default_RSA_meth=RSA_null_method();
+#else
+#ifdef RSAref
+               default_RSA_meth=RSA_PKCS1_RSAref();
+#else
+               default_RSA_meth=RSA_PKCS1_SSLeay();
+#endif
+#endif
+               }
+
        return default_RSA_meth;
 }
 
@@ -103,19 +116,7 @@ RSA *RSA_new_method(RSA_METHOD *meth)
        {
        RSA *ret;
 
-       if (default_RSA_meth == NULL)
-               {
-#ifdef RSA_NULL
-               default_RSA_meth=RSA_null_method();
-#else
-#ifdef RSAref
-               default_RSA_meth=RSA_PKCS1_RSAref();
-#else
-               default_RSA_meth=RSA_PKCS1_SSLeay();
-#endif
-#endif
-               }
-       ret=(RSA *)Malloc(sizeof(RSA));
+       ret=(RSA *)OPENSSL_malloc(sizeof(RSA));
        if (ret == NULL)
                {
                RSAerr(RSA_F_RSA_NEW_METHOD,ERR_R_MALLOC_FAILURE);
@@ -123,7 +124,7 @@ RSA *RSA_new_method(RSA_METHOD *meth)
                }
 
        if (meth == NULL)
-               ret->meth=default_RSA_meth;
+               ret->meth=RSA_get_default_method();
        else
                ret->meth=meth;
 
@@ -146,7 +147,7 @@ RSA *RSA_new_method(RSA_METHOD *meth)
        ret->flags=ret->meth->flags;
        if ((ret->meth->init != NULL) && !ret->meth->init(ret))
                {
-               Free(ret);
+               OPENSSL_free(ret);
                ret=NULL;
                }
        else
@@ -187,8 +188,8 @@ void RSA_free(RSA *r)
        if (r->dmq1 != NULL) BN_clear_free(r->dmq1);
        if (r->iqmp != NULL) BN_clear_free(r->iqmp);
        if (r->blinding != NULL) BN_BLINDING_free(r->blinding);
-       if (r->bignum_data != NULL) Free_locked(r->bignum_data);
-       Free(r);
+       if (r->bignum_data != NULL) OPENSSL_free_locked(r->bignum_data);
+       OPENSSL_free(r);
        }
 
 int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
@@ -269,19 +270,19 @@ int RSA_blinding_on(RSA *rsa, BN_CTX *p_ctx)
        if (rsa->blinding != NULL)
                BN_BLINDING_free(rsa->blinding);
 
-       A= &(ctx->bn[0]);
-       ctx->tos++;
+       BN_CTX_start(ctx);
+       A = BN_CTX_get(ctx);
        if (!BN_rand(A,BN_num_bits(rsa->n)-1,1,0)) goto err;
        if ((Ai=BN_mod_inverse(NULL,A,rsa->n,ctx)) == NULL) goto err;
 
        if (!rsa->meth->bn_mod_exp(A,A,rsa->e,rsa->n,ctx,rsa->_method_mod_n))
            goto err;
        rsa->blinding=BN_BLINDING_new(A,Ai,rsa->n);
-       ctx->tos--;
        rsa->flags|=RSA_FLAG_BLINDING;
        BN_free(Ai);
        ret=1;
 err:
+       BN_CTX_end(ctx);
        if (ctx != p_ctx) BN_CTX_free(ctx);
        return(ret);
        }
@@ -305,7 +306,7 @@ int RSA_memory_lock(RSA *r)
        j=1;
        for (i=0; i<6; i++)
                j+= (*t[i])->top;
-       if ((p=Malloc_locked((off+j)*sizeof(BN_ULONG))) == NULL)
+       if ((p=OPENSSL_malloc_locked((off+j)*sizeof(BN_ULONG))) == NULL)
                {
                RSAerr(RSA_F_MEMORY_LOCK,ERR_R_MALLOC_FAILURE);
                return(0);