mirror of
https://git.FreeBSD.org/src.git
synced 2024-11-23 07:31:31 +00:00
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
This commit is contained in:
parent
1dd3ff6658
commit
76f29359f7
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=160805
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user