Change submitted files so that they compile (in particular,

use BN_CTX_start/get/end instead of accessing ctx->tos).

Change indentation to "EAY" style.
This commit is contained in:
Bodo Möller 2000-11-26 19:20:56 +00:00
parent 946cd9a540
commit 1ec0a3862e

View File

@ -49,6 +49,7 @@ void BN_mont_clear_free(BN_MONTGOMERY *mont)
mont->p_inv_b_neg = 0;
}
int BN_to_mont(BIGNUM *x, BN_MONTGOMERY *mont, BN_CTX *ctx)
{
assert(x != NULL);
@ -84,9 +85,10 @@ static BN_ULONG BN_mont_inv(BIGNUM *a, int e, BN_CTX *ctx)
if((x = BN_dup(a)) == NULL) return 0;
if(!BN_mask_bits(x, e)) return 0;
xy = ctx->bn[ctx->tos];
x_sh = ctx->bn[ctx->tos + 1];
ctx->tos += 2;
BN_CTX_start(ctx);
xy = BN_CTX_get(ctx);
x_sh = BN_CTX_get(ctx);
if (x_sh == NULL) goto err;
if (BN_copy(xy, x) == NULL) goto err;
if (!BN_lshift1(x_sh, x)) goto err;
@ -112,17 +114,17 @@ static BN_ULONG BN_mont_inv(BIGNUM *a, int e, BN_CTX *ctx)
#endif
if (x != NULL) BN_clear_free(x);
ctx->tos -= 2;
BN_CTX_end(ctx);
return y;
err:
if (x != NULL) BN_clear_free(x);
ctx->tos -= 2;
BN_CTX_end(ctx);
return 0;
}
int BN_mont_set(BIGNUM *p, BN_MONTGOMERY *mont, BN_CTX *ctx)
{
assert(p != NULL && ctx != NULL);
@ -142,6 +144,7 @@ int BN_mont_set(BIGNUM *p, BN_MONTGOMERY *mont, BN_CTX *ctx)
return 1;
}
static int BN_cpy_mul_word(BIGNUM *ret, BIGNUM *a, BN_ULONG w)
/* ret = a * w */
{
@ -169,9 +172,10 @@ int BN_mont_red(BIGNUM *y, BN_MONTGOMERY *mont, BN_CTX *ctx)
if (BN_is_zero(y)) return 1;
p = mont->p;
up = ctx->bn[ctx->tos];
ctx->tos += 1;
BN_CTX_start(ctx);
up = BN_CTX_get(ctx);
if (up == NULL) goto err;
for (i = 0; i < mont->p_num_bytes; i++)
{
@ -192,13 +196,12 @@ int BN_mont_red(BIGNUM *y, BN_MONTGOMERY *mont, BN_CTX *ctx)
if (!BN_sub(y, y, mont->p)) goto err;
}
ctx->tos -= 1;
BN_CTX_end(ctx);
return 1;
err:
ctx->tos -= 1;
BN_CTX_end(ctx);
return 0;
}
@ -227,9 +230,10 @@ int BN_mont_mod_mul(BIGNUM *r, BIGNUM *x, BIGNUM *y, BN_MONTGOMERY *mont, BN_CTX
xiy = ctx->bn[ctx->tos];
up = ctx->bn[ctx->tos + 1];
ctx->tos += 2;
BN_CTX_start(ctx);
xiy = BN_CTX_get(ctx);
up = BN_CTX_get(ctx);
if (up == NULL) goto err;
if (!BN_zero(r)) goto err;
@ -270,10 +274,10 @@ int BN_mont_mod_mul(BIGNUM *r, BIGNUM *x, BIGNUM *y, BN_MONTGOMERY *mont, BN_CTX
}
ctx->tos -= 2;
BN_CTX_end(ctx);
return 1;
err:
ctx->tos -= 2;
BN_CTX_end(ctx);
return 0;
}