Loading crypto/bn/bn_mont2.c +57 −53 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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; Loading @@ -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); Loading @@ -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 */ { Loading Loading @@ -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++) { Loading @@ -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; } Loading Loading @@ -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; Loading Loading @@ -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; } Loading
crypto/bn/bn_mont2.c +57 −53 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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; Loading @@ -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); Loading @@ -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 */ { Loading Loading @@ -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++) { Loading @@ -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; } Loading Loading @@ -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; Loading Loading @@ -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; }