diff options
-rw-r--r-- | lib/libmp/mpasbn.c | 61 |
1 files changed, 36 insertions, 25 deletions
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 <openssl/crypto.h> #include <openssl/err.h> -#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 |