#ifdef RSA_NULL
default_RSA_meth=RSA_null_method();
#else
-#if 0 /* was: #ifdef RSAref
+#if 0 /* was: #ifdef RSAref */
default_RSA_meth=RSA_PKCS1_RSAref();
#else
default_RSA_meth=RSA_PKCS1_SSLeay();
return(NULL);
}
- if (engine == NULL)
+ if (engine)
{
- if((ret->engine=ENGINE_get_default_RSA()) == NULL)
- {
- OPENSSL_free(ret);
- return NULL;
- }
+ if(ENGINE_init(engine))
+ ret->engine = engine;
+ else
+ ret->engine = NULL;
}
else
- ret->engine=engine;
+ ret->engine=ENGINE_get_default_RSA();
+
+ if(ret->engine == NULL)
+ {
+ RSAerr(RSA_F_RSA_NEW_METHOD,ERR_LIB_ENGINE);
+ OPENSSL_free(ret);
+ return NULL;
+ }
+
meth = ENGINE_get_RSA(ret->engine);
ret->pad=0;
ret->blinding=NULL;
ret->bignum_data=NULL;
ret->flags=meth->flags;
+ CRYPTO_new_ex_data(rsa_meth,ret,&ret->ex_data);
if ((meth->init != NULL) && !meth->init(ret))
{
+ CRYPTO_free_ex_data(rsa_meth, ret, &ret->ex_data);
OPENSSL_free(ret);
ret=NULL;
}
- else
- CRYPTO_new_ex_data(rsa_meth,ret,&ret->ex_data);
return(ret);
}
}
#endif
- CRYPTO_free_ex_data(rsa_meth,r,&r->ex_data);
-
meth = ENGINE_get_RSA(r->engine);
if (meth->finish != NULL)
meth->finish(r);
ENGINE_finish(r->engine);
+ CRYPTO_free_ex_data(rsa_meth,r,&r->ex_data);
+
if (r->n != NULL) BN_clear_free(r->n);
if (r->e != NULL) BN_clear_free(r->e);
if (r->d != NULL) BN_clear_free(r->d);
OPENSSL_free(r);
}
+int RSA_up(RSA *r)
+ {
+ int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_RSA);
+#ifdef REF_PRINT
+ REF_PRINT("RSA",r);
+#endif
+#ifdef REF_CHECK
+ if (i < 2)
+ {
+ fprintf(stderr, "RSA_up, bad reference count\n");
+ abort();
+ }
+#endif
+ return ((i > 1) ? 1 : 0);
+ }
+
int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
{
- rsa_meth_num++;
- return(CRYPTO_get_ex_new_index(rsa_meth_num-1,
- &rsa_meth,argl,argp,new_func,dup_func,free_func));
+ if(CRYPTO_get_ex_new_index(rsa_meth_num, &rsa_meth, argl, argp,
+ new_func, dup_func, free_func) < 0)
+ return -1;
+ return (rsa_meth_num++);
}
int RSA_set_ex_data(RSA *r, int idx, void *arg)
BN_CTX_start(ctx);
A = BN_CTX_get(ctx);
- if (!BN_rand(A,BN_num_bits(rsa->n)-1,1,0)) goto err;
+ if (!BN_rand_range(A,rsa->n)) goto err;
if ((Ai=BN_mod_inverse(NULL,A,rsa->n,ctx)) == NULL) goto err;
if (!ENGINE_get_RSA(rsa->engine)->bn_mod_exp(A,A,