Import of old SSLeay release: SSLeay 0.9.1b (unreleased)

This commit is contained in:
Ralf S. Engelschall
1998-12-21 11:00:56 +00:00
parent 58964a4922
commit dfeab0689f
501 changed files with 43472 additions and 4057 deletions

View File

@@ -67,11 +67,11 @@ DH *dh;
{
int ok=0;
unsigned int i;
BN_CTX *ctx=NULL;
BN_CTX ctx;
BN_MONT_CTX *mont;
BIGNUM *pub_key=NULL,*priv_key=NULL;
ctx=BN_CTX_new();
if (ctx == NULL) goto err;
BN_CTX_init(&ctx);
if (dh->priv_key == NULL)
{
@@ -96,7 +96,15 @@ DH *dh;
else
pub_key=dh->pub_key;
if (!BN_mod_exp(pub_key,dh->g,priv_key,dh->p,ctx)) goto err;
if ((dh->method_mont_p == NULL) && (dh->flags & DH_FLAG_CACHE_MONT_P))
{
if ((dh->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
if (!BN_MONT_CTX_set((BN_MONT_CTX *)dh->method_mont_p,
dh->p,&ctx)) goto err;
}
mont=(BN_MONT_CTX *)dh->method_mont_p;
if (!BN_mod_exp_mont(pub_key,dh->g,priv_key,dh->p,&ctx,mont)) goto err;
dh->pub_key=pub_key;
dh->priv_key=priv_key;
@@ -107,7 +115,7 @@ err:
if ((pub_key != NULL) && (dh->pub_key == NULL)) BN_free(pub_key);
if ((priv_key != NULL) && (dh->priv_key == NULL)) BN_free(priv_key);
if (ctx != NULL) BN_CTX_free(ctx);
BN_CTX_free(&ctx);
return(ok);
}
@@ -116,20 +124,28 @@ unsigned char *key;
BIGNUM *pub_key;
DH *dh;
{
BN_CTX *ctx;
BN_CTX ctx;
BN_MONT_CTX *mont;
BIGNUM *tmp;
int ret= -1;
ctx=BN_CTX_new();
if (ctx == NULL) goto err;
tmp=ctx->bn[ctx->tos++];
BN_CTX_init(&ctx);
tmp= &(ctx.bn[ctx.tos++]);
if (dh->priv_key == NULL)
{
DHerr(DH_F_DH_COMPUTE_KEY,DH_R_NO_PRIVATE_VALUE);
goto err;
}
if (!BN_mod_exp(tmp,pub_key,dh->priv_key,dh->p,ctx))
if ((dh->method_mont_p == NULL) && (dh->flags & DH_FLAG_CACHE_MONT_P))
{
if ((dh->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
if (!BN_MONT_CTX_set((BN_MONT_CTX *)dh->method_mont_p,
dh->p,&ctx)) goto err;
}
mont=(BN_MONT_CTX *)dh->method_mont_p;
if (!BN_mod_exp_mont(tmp,pub_key,dh->priv_key,dh->p,&ctx,mont))
{
DHerr(DH_F_DH_COMPUTE_KEY,ERR_R_BN_LIB);
goto err;
@@ -137,6 +153,6 @@ DH *dh;
ret=BN_bn2bin(tmp,key);
err:
if (ctx != NULL) BN_CTX_free(ctx);
BN_CTX_free(&ctx);
return(ret);
}