Incease the number of BIGNUMs in a BN_CTX.
Changes between 0.9.6 and 0.9.7 [xx XXX 2000]
+ *) Hide BN_CTX structure details in bn_lcl.h instead of publishing them
+ in <openssl/bn.h>. Also further increase BN_CTX_NUM to 24.
+ [Bodo Moeller]
+
*) Modify EVP_Digest*() routines so they now return values. Although the
internal software routines can never fail additional hardware versions
might.
int flags;
} BIGNUM;
-/* Used for temp variables */
-#define BN_CTX_NUM 20
-#define BN_CTX_NUM_POS 12
-typedef struct bignum_ctx
- {
- int tos;
- BIGNUM bn[BN_CTX_NUM];
- int flags;
- int depth;
- int pos[BN_CTX_NUM_POS];
- int too_many;
- } BN_CTX;
+/* Used for temp variables (declaration hidden in bn_lcl.h) */
+typedef struct bignum_ctx BN_CTX;
typedef struct bn_blinding_st
{
#include <stdio.h>
#include <assert.h>
+
#include "cryptlib.h"
-#include <openssl/bn.h>
+#include "bn_lcl.h"
BN_CTX *BN_CTX_new(void)
void BN_CTX_init(BN_CTX *ctx)
{
+#if 0 /* explicit version */
int i;
ctx->tos = 0;
ctx->flags = 0;
ctx->too_many = 0;
for (i = 0; i < BN_CTX_NUM; i++)
BN_init(&(ctx->bn[i]));
+#else
+ memset(ctx, 0, sizeof *ctx);
+#endif
}
void BN_CTX_free(BN_CTX *ctx)
#endif
+/* Used for temp variables */
+#define BN_CTX_NUM 24
+#define BN_CTX_NUM_POS 12
+struct bignum_ctx
+ {
+ int tos;
+ BIGNUM bn[BN_CTX_NUM];
+ int flags;
+ int depth;
+ int pos[BN_CTX_NUM_POS];
+ int too_many;
+ } /* BN_CTX */;
+
+
/*
* BN_window_bits_for_exponent_size -- macro for sliding window mod_exp functions
*
{
BIGNUM a,b,c,d,e;
int i;
- BN_CTX ctx;
+ BN_CTX *ctx;
- BN_CTX_init(&ctx);
+ ctx = BN_CTX_new();
+ if (ctx == NULL) exit(1);
+
BN_init(&a);
BN_init(&b);
BN_init(&c);
BN_bntest_rand(&b,i-num1,0,0);
a.neg=rand_neg();
b.neg=rand_neg();
- BN_mul(&c,&a,&b,&ctx);
+ BN_mul(&c,&a,&b,ctx);
if (bp != NULL)
{
if (!results)
BN_print(bp,&c);
BIO_puts(bp,"\n");
}
- BN_div(&d,&e,&c,&a,&ctx);
+ BN_div(&d,&e,&c,&a,ctx);
BN_sub(&d,&d,&b);
if(!BN_is_zero(&d) || !BN_is_zero(&e))
{
BN_free(&c);
BN_free(&d);
BN_free(&e);
- BN_CTX_free(&ctx);
+ BN_CTX_free(ctx);
return(1);
}
static int generate_key(DH *dh)
{
int ok=0;
- BN_CTX ctx;
+ BN_CTX *ctx;
BN_MONT_CTX *mont;
BIGNUM *pub_key=NULL,*priv_key=NULL;
- BN_CTX_init(&ctx);
+ ctx = BN_CTX_new();
+ if (ctx == NULL) goto err;
if (dh->priv_key == NULL)
{
{
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;
+ dh->p,ctx)) goto err;
}
mont=(BN_MONT_CTX *)dh->method_mont_p;
if (!ENGINE_get_DH(dh->engine)->bn_mod_exp(dh, pub_key, dh->g,
- priv_key,dh->p,&ctx,mont))
+ priv_key,dh->p,ctx,mont))
goto err;
dh->pub_key=pub_key;
if ((pub_key != NULL) && (dh->pub_key == NULL)) BN_free(pub_key);
if ((priv_key != NULL) && (dh->priv_key == NULL)) BN_free(priv_key);
- BN_CTX_free(&ctx);
+ BN_CTX_free(ctx);
return(ok);
}
static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
{
- BN_CTX ctx;
+ BN_CTX *ctx;
BN_MONT_CTX *mont;
BIGNUM *tmp;
int ret= -1;
- BN_CTX_init(&ctx);
- BN_CTX_start(&ctx);
- tmp = BN_CTX_get(&ctx);
+ ctx = BN_CTX_new();
+ if (ctx == NULL) goto err;
+ BN_CTX_start(ctx);
+ tmp = BN_CTX_get(ctx);
if (dh->priv_key == NULL)
{
{
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;
+ dh->p,ctx)) goto err;
}
mont=(BN_MONT_CTX *)dh->method_mont_p;
if (!ENGINE_get_DH(dh->engine)->bn_mod_exp(dh, tmp, pub_key,
- dh->priv_key,dh->p,&ctx,mont))
+ dh->priv_key,dh->p,ctx,mont))
{
DHerr(DH_F_DH_COMPUTE_KEY,ERR_R_BN_LIB);
goto err;
ret=BN_bn2bin(tmp,key);
err:
- BN_CTX_end(&ctx);
- BN_CTX_free(&ctx);
+ BN_CTX_end(ctx);
+ BN_CTX_free(ctx);
return(ret);
}
BN_init(&r1);
/* BN_mul() cannot accept const BIGNUMs so I use the BN_CTX
* to duplicate what I need. <sigh> */
+ BN_CTX_start(bn_ctx);
if ((temp_bn = BN_CTX_get(bn_ctx)) == NULL) goto err;
if (!BN_copy(temp_bn, iqmp)) goto err;
err:
BN_clear_free(&m1);
BN_clear_free(&r1);
- if (temp_bn)
- bn_ctx->tos--;
+ BN_CTX_end(ctx);
if (!ctx)
BN_CTX_free(bn_ctx);
return(ret);
goto err;
}
/* Prepare the params */
+ BN_CTX_start(ctx);
modulus = BN_CTX_get(ctx);
exponent = BN_CTX_get(ctx);
argument = BN_CTX_get(ctx);
result = BN_CTX_get(ctx);
- if(!modulus || !exponent || !argument || !result)
+ if (!result)
{
ENGINEerr(ENGINE_F_ATALLA_MOD_EXP,ENGINE_R_BN_CTX_FULL);
goto err;
BN_bin2bn((unsigned char *)result->d, numbytes, r);
to_return = 1;
err:
- if(modulus) ctx->tos--;
- if(exponent) ctx->tos--;
- if(argument) ctx->tos--;
- if(result) ctx->tos--;
+ BN_CTX_end(ctx);
return to_return;
}
}
acquired = 1;
/* Prepare the params */
+ BN_CTX_start(ctx);
modulus = BN_CTX_get(ctx);
exponent = BN_CTX_get(ctx);
argument = BN_CTX_get(ctx);
result = BN_CTX_get(ctx);
- if(!modulus || !exponent || !argument || !result)
+ if(!result)
{
ENGINEerr(ENGINE_F_CSWIFT_MOD_EXP,ENGINE_R_BN_CTX_FULL);
goto err;
err:
if(acquired)
release_context(hac);
- if(modulus) ctx->tos--;
- if(exponent) ctx->tos--;
- if(argument) ctx->tos--;
- if(result) ctx->tos--;
+ BN_CTX_end(ctx);
return to_return;
}
}
acquired = 1;
/* Prepare the params */
+ BN_CTX_start(ctx);
rsa_p = BN_CTX_get(ctx);
rsa_q = BN_CTX_get(ctx);
rsa_dmp1 = BN_CTX_get(ctx);
rsa_iqmp = BN_CTX_get(ctx);
argument = BN_CTX_get(ctx);
result = BN_CTX_get(ctx);
- if(!rsa_p || !rsa_q || !rsa_dmp1 || !rsa_dmq1 || !rsa_iqmp ||
- !argument || !result)
+ if(!result)
{
ENGINEerr(ENGINE_F_CSWIFT_MOD_EXP_CRT,ENGINE_R_BN_CTX_FULL);
goto err;
err:
if(acquired)
release_context(hac);
- if(rsa_p) ctx->tos--;
- if(rsa_q) ctx->tos--;
- if(rsa_dmp1) ctx->tos--;
- if(rsa_dmq1) ctx->tos--;
- if(rsa_iqmp) ctx->tos--;
- if(argument) ctx->tos--;
- if(result) ctx->tos--;
+ BN_CTX_end(ctx);
return to_return;
}
}
acquired = 1;
/* Prepare the params */
+ BN_CTX_start(ctx);
dsa_p = BN_CTX_get(ctx);
dsa_q = BN_CTX_get(ctx);
dsa_g = BN_CTX_get(ctx);
dsa_key = BN_CTX_get(ctx);
result = BN_CTX_get(ctx);
- if(!dsa_p || !dsa_q || !dsa_g || !dsa_key || !result)
+ if(!result)
{
ENGINEerr(ENGINE_F_CSWIFT_DSA_SIGN,ENGINE_R_BN_CTX_FULL);
goto err;
err:
if(acquired)
release_context(hac);
- if(dsa_p) ctx->tos--;
- if(dsa_q) ctx->tos--;
- if(dsa_g) ctx->tos--;
- if(dsa_key) ctx->tos--;
- if(result) ctx->tos--;
if(ctx)
+ {
+ BN_CTX_end(ctx);
BN_CTX_free(ctx);
+ }
return to_return;
}
}
acquired = 1;
/* Prepare the params */
+ BN_CTX_start(ctx);
dsa_p = BN_CTX_get(ctx);
dsa_q = BN_CTX_get(ctx);
dsa_g = BN_CTX_get(ctx);
dsa_key = BN_CTX_get(ctx);
argument = BN_CTX_get(ctx);
- if(!dsa_p || !dsa_q || !dsa_g || !dsa_key || !argument)
+ if(!argument)
{
ENGINEerr(ENGINE_F_CSWIFT_DSA_VERIFY,ENGINE_R_BN_CTX_FULL);
goto err;
err:
if(acquired)
release_context(hac);
- if(dsa_p) ctx->tos--;
- if(dsa_q) ctx->tos--;
- if(dsa_g) ctx->tos--;
- if(dsa_key) ctx->tos--;
- if(argument) ctx->tos--;
if(ctx)
+ {
+ BN_CTX_end(ctx);
BN_CTX_free(ctx);
+ }
return to_return;
}