From 26af0bae3b9466a6744abe25582e67886b13edb9 Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 28 Jul 2006 23:00:16 +0000 Subject: Do not put BN_CTX structures on the stack, but instead allocate them runtime using BN_CTX_new(). This is done since in OpenSSL 0.9.7e we can only allocate BN_CTX on the stack by including an internal OpenSSL header file, and in OpenSSL 0.9.8 BN_CTX is entirely opaque, so having it on the stack is not possible at all. This is done as preparation for OpenSSL 0.9.8b import. Tested on: amd64 i386 ia64 Tested with: src/tools/regression/lib/libmp --- lib/libmp/mpasbn.c | 61 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 25 deletions(-) (limited to 'lib/libmp') diff --git a/lib/libmp/mpasbn.c b/lib/libmp/mpasbn.c index 726e2f1..0775dba 100644 --- a/lib/libmp/mpasbn.c +++ b/lib/libmp/mpasbn.c @@ -82,7 +82,6 @@ __FBSDID("$FreeBSD$"); #include #include -#include "openssl/crypto/bn/bn_lcl.h" #include "mp.h" #define MPERR(s) do { warn s; abort(); } while (0) @@ -143,14 +142,16 @@ void gcd(const MINT *mp1, const MINT *mp2, MINT *rmp) { BIGNUM b; - BN_CTX c; + BN_CTX *c; - BN_CTX_init(&c); + c = BN_CTX_new(); + if (c == NULL) + _bnerr("gcd"); BN_init(&b); - BN_ERRCHECK("gcd", BN_gcd(&b, mp1->bn, mp2->bn, &c)); + BN_ERRCHECK("gcd", BN_gcd(&b, mp1->bn, mp2->bn, c)); _moveb("gcd", &b, rmp); BN_free(&b); - BN_CTX_free(&c); + BN_CTX_free(c); } /* @@ -225,17 +226,19 @@ static void _mdiv(const char *msg, const MINT *nmp, const MINT *dmp, MINT *qmp, MINT *rmp) { BIGNUM q, r; - BN_CTX c; + BN_CTX *c; - BN_CTX_init(&c); + c = BN_CTX_new(); + if (c == NULL) + _bnerr(msg); BN_init(&r); BN_init(&q); - BN_ERRCHECK(msg, BN_div(&q, &r, nmp->bn, dmp->bn, &c)); + BN_ERRCHECK(msg, BN_div(&q, &r, nmp->bn, dmp->bn, c)); _moveb(msg, &q, qmp); _moveb(msg, &r, rmp); BN_free(&q); BN_free(&r); - BN_CTX_free(&c); + BN_CTX_free(c); } void @@ -470,14 +473,16 @@ static void _mult(const char *msg, const MINT *mp1, const MINT *mp2, MINT *rmp) { BIGNUM b; - BN_CTX c; + BN_CTX *c; - BN_CTX_init(&c); + c = BN_CTX_new(); + if (c == NULL) + _bnerr(msg); BN_init(&b); - BN_ERRCHECK(msg, BN_mul(&b, mp1->bn, mp2->bn, &c)); + BN_ERRCHECK(msg, BN_mul(&b, mp1->bn, mp2->bn, c)); _moveb(msg, &b, rmp); BN_free(&b); - BN_CTX_free(&c); + BN_CTX_free(c); } void @@ -495,14 +500,16 @@ void pow(const MINT *bmp, const MINT *emp, const MINT *mmp, MINT *rmp) { BIGNUM b; - BN_CTX c; + BN_CTX *c; - BN_CTX_init(&c); + c = BN_CTX_new(); + if (c == NULL) + _bnerr("pow"); BN_init(&b); - BN_ERRCHECK("pow", BN_mod_exp(&b, bmp->bn, emp->bn, mmp->bn, &c)); + BN_ERRCHECK("pow", BN_mod_exp(&b, bmp->bn, emp->bn, mmp->bn, c)); _moveb("pow", &b, rmp); BN_free(&b); - BN_CTX_free(&c); + BN_CTX_free(c); } /* @@ -513,16 +520,18 @@ rpow(const MINT *bmp, short e, MINT *rmp) { MINT *emp; BIGNUM b; - BN_CTX c; + BN_CTX *c; - BN_CTX_init(&c); + c = BN_CTX_new(); + if (c == NULL) + _bnerr("rpow"); BN_init(&b); emp = _itom("rpow", e); - BN_ERRCHECK("rpow", BN_exp(&b, bmp->bn, emp->bn, &c)); + BN_ERRCHECK("rpow", BN_exp(&b, bmp->bn, emp->bn, c)); _moveb("rpow", &b, rmp); _mfree("rpow", emp); BN_free(&b); - BN_CTX_free(&c); + BN_CTX_free(c); } /* @@ -533,15 +542,17 @@ _sdiv(const char *msg, const MINT *nmp, short d, MINT *qmp, short *ro) { MINT *dmp, *rmp; BIGNUM q, r; - BN_CTX c; + BN_CTX *c; char *s; - BN_CTX_init(&c); + c = BN_CTX_new(); + if (c == NULL) + _bnerr(msg); BN_init(&q); BN_init(&r); dmp = _itom(msg, d); rmp = _itom(msg, 0); - BN_ERRCHECK(msg, BN_div(&q, &r, nmp->bn, dmp->bn, &c)); + BN_ERRCHECK(msg, BN_div(&q, &r, nmp->bn, dmp->bn, c)); _moveb(msg, &q, qmp); _moveb(msg, &r, rmp); s = _mtox(msg, rmp); @@ -554,7 +565,7 @@ _sdiv(const char *msg, const MINT *nmp, short d, MINT *qmp, short *ro) _mfree(msg, rmp); BN_free(&r); BN_free(&q); - BN_CTX_free(&c); + BN_CTX_free(c); } void -- cgit v1.1