From owner-svn-src-projects@freebsd.org Wed Sep 19 07:05:32 2018 Return-Path: Delivered-To: svn-src-projects@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 78F991091B32 for ; Wed, 19 Sep 2018 07:05:32 +0000 (UTC) (envelope-from jkim@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 23A0B74542; Wed, 19 Sep 2018 07:05:32 +0000 (UTC) (envelope-from jkim@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id F39C83AF8; Wed, 19 Sep 2018 07:05:31 +0000 (UTC) (envelope-from jkim@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w8J75VXC071838; Wed, 19 Sep 2018 07:05:31 GMT (envelope-from jkim@FreeBSD.org) Received: (from jkim@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w8J75VFP071837; Wed, 19 Sep 2018 07:05:31 GMT (envelope-from jkim@FreeBSD.org) Message-Id: <201809190705.w8J75VFP071837@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jkim set sender to jkim@FreeBSD.org using -f From: Jung-uk Kim Date: Wed, 19 Sep 2018 07:05:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r338780 - projects/openssl111/lib/libmp X-SVN-Group: projects X-SVN-Commit-Author: jkim X-SVN-Commit-Paths: projects/openssl111/lib/libmp X-SVN-Commit-Revision: 338780 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Sep 2018 07:05:32 -0000 Author: jkim Date: Wed Sep 19 07:05:31 2018 New Revision: 338780 URL: https://svnweb.freebsd.org/changeset/base/338780 Log: Make libmp(3) buildable. Modified: projects/openssl111/lib/libmp/mpasbn.c Modified: projects/openssl111/lib/libmp/mpasbn.c ============================================================================== --- projects/openssl111/lib/libmp/mpasbn.c Wed Sep 19 07:04:15 2018 (r338779) +++ projects/openssl111/lib/libmp/mpasbn.c Wed Sep 19 07:05:31 2018 (r338780) @@ -144,16 +144,18 @@ _dtom(const char *msg, const char *s) void mp_gcd(const MINT *mp1, const MINT *mp2, MINT *rmp) { - BIGNUM b; + BIGNUM *b; BN_CTX *c; + b = NULL; c = BN_CTX_new(); - if (c == NULL) + if (c != NULL) + b = BN_new(); + if (c == NULL || b == NULL) _bnerr("gcd"); - BN_init(&b); - BN_ERRCHECK("gcd", BN_gcd(&b, mp1->bn, mp2->bn, c)); - _moveb("gcd", &b, rmp); - BN_free(&b); + BN_ERRCHECK("gcd", BN_gcd(b, mp1->bn, mp2->bn, c)); + _moveb("gcd", b, rmp); + BN_free(b); BN_CTX_free(c); } @@ -187,12 +189,14 @@ mp_itom(short n) static void _madd(const char *msg, const MINT *mp1, const MINT *mp2, MINT *rmp) { - BIGNUM b; + BIGNUM *b; - BN_init(&b); - BN_ERRCHECK(msg, BN_add(&b, mp1->bn, mp2->bn)); - _moveb(msg, &b, rmp); - BN_free(&b); + b = BN_new(); + if (b == NULL) + _bnerr(msg); + BN_ERRCHECK(msg, BN_add(b, mp1->bn, mp2->bn)); + _moveb(msg, b, rmp); + BN_free(b); } void @@ -229,15 +233,19 @@ static void _mdiv(const char *msg, const MINT *nmp, const MINT *dmp, MINT *qmp, MINT *rmp, BN_CTX *c) { - BIGNUM q, r; + BIGNUM *q, *r; - BN_init(&r); - BN_init(&q); - 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); + q = NULL; + r = BN_new(); + if (r != NULL) + q = BN_new(); + if (r == NULL || q == NULL) + _bnerr(msg); + 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); } void @@ -402,12 +410,14 @@ mp_msqrt(const MINT *nmp, MINT *xmp, MINT *rmp) static void _msub(const char *msg, const MINT *mp1, const MINT *mp2, MINT *rmp) { - BIGNUM b; + BIGNUM *b; - BN_init(&b); - BN_ERRCHECK(msg, BN_sub(&b, mp1->bn, mp2->bn)); - _moveb(msg, &b, rmp); - BN_free(&b); + b = BN_new(); + if (b == NULL) + _bnerr(msg); + BN_ERRCHECK(msg, BN_sub(b, mp1->bn, mp2->bn)); + _moveb(msg, b, rmp); + BN_free(b); } void @@ -481,12 +491,14 @@ mp_mtox(const MINT *mp) static void _mult(const char *msg, const MINT *mp1, const MINT *mp2, MINT *rmp, BN_CTX *c) { - BIGNUM b; + BIGNUM *b; - BN_init(&b); - BN_ERRCHECK(msg, BN_mul(&b, mp1->bn, mp2->bn, c)); - _moveb(msg, &b, rmp); - BN_free(&b); + b = BN_new(); + if (b == NULL) + _bnerr(msg); + BN_ERRCHECK(msg, BN_mul(b, mp1->bn, mp2->bn, c)); + _moveb(msg, b, rmp); + BN_free(b); } void @@ -508,16 +520,18 @@ mp_mult(const MINT *mp1, const MINT *mp2, MINT *rmp) void mp_pow(const MINT *bmp, const MINT *emp, const MINT *mmp, MINT *rmp) { - BIGNUM b; + BIGNUM *b; BN_CTX *c; + b = NULL; c = BN_CTX_new(); - if (c == NULL) + if (c != NULL) + b = BN_new(); + if (c == NULL || b == NULL) _bnerr("pow"); - BN_init(&b); - BN_ERRCHECK("pow", BN_mod_exp(&b, bmp->bn, emp->bn, mmp->bn, c)); - _moveb("pow", &b, rmp); - BN_free(&b); + 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); } @@ -528,18 +542,20 @@ void mp_rpow(const MINT *bmp, short e, MINT *rmp) { MINT *emp; - BIGNUM b; + BIGNUM *b; BN_CTX *c; + b = NULL; c = BN_CTX_new(); - if (c == NULL) + if (c != NULL) + b = BN_new(); + if (c == NULL || b == NULL) _bnerr("rpow"); - BN_init(&b); emp = _itom("rpow", e); - BN_ERRCHECK("rpow", BN_exp(&b, bmp->bn, emp->bn, c)); - _moveb("rpow", &b, rmp); + BN_ERRCHECK("rpow", BN_exp(b, bmp->bn, emp->bn, c)); + _moveb("rpow", b, rmp); _mfree("rpow", emp); - BN_free(&b); + BN_free(b); BN_CTX_free(c); } @@ -551,16 +567,20 @@ _sdiv(const char *msg, const MINT *nmp, short d, MINT BN_CTX *c) { MINT *dmp, *rmp; - BIGNUM q, r; + BIGNUM *q, *r; char *s; - BN_init(&q); - BN_init(&r); + r = NULL; + q = BN_new(); + if (q != NULL) + r = BN_new(); + if (q == NULL || r == NULL) + _bnerr(msg); dmp = _itom(msg, d); rmp = _itom(msg, 0); - BN_ERRCHECK(msg, BN_div(&q, &r, nmp->bn, dmp->bn, c)); - _moveb(msg, &q, qmp); - _moveb(msg, &r, rmp); + BN_ERRCHECK(msg, BN_div(q, r, nmp->bn, dmp->bn, c)); + _moveb(msg, q, qmp); + _moveb(msg, r, rmp); s = _mtox(msg, rmp); errno = 0; *ro = strtol(s, NULL, 16); @@ -569,8 +589,8 @@ _sdiv(const char *msg, const MINT *nmp, short d, MINT free(s); _mfree(msg, dmp); _mfree(msg, rmp); - BN_free(&r); - BN_free(&q); + BN_free(r); + BN_free(q); } void