summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2015-02-14 06:40:05 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2015-02-14 06:40:05 +0000
commit712e08849c681d0e005e4cccd4b55789919e7449 (patch)
tree20d8f533e4663855beb192e28be52a2d35f65fc6 /lib
parent598c1f067b1131b99c046fce5128f1a1c398edc5 (diff)
Consistently check the return value from BN_CTX_get() on assignment.
This is the same as the previous larger commit, however it would seem the GOST part got missed. ok beck@ doug@
Diffstat (limited to 'lib')
-rw-r--r--lib/libssl/src/crypto/gost/gostr341001.c59
-rw-r--r--lib/libssl/src/crypto/gost/gostr341001_ameth.c8
-rw-r--r--lib/libssl/src/crypto/gost/gostr341001_key.c8
-rw-r--r--lib/libssl/src/crypto/gost/gostr341001_pmeth.c11
4 files changed, 44 insertions, 42 deletions
diff --git a/lib/libssl/src/crypto/gost/gostr341001.c b/lib/libssl/src/crypto/gost/gostr341001.c
index bc553e10833..c6221e4a012 100644
--- a/lib/libssl/src/crypto/gost/gostr341001.c
+++ b/lib/libssl/src/crypto/gost/gostr341001.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gostr341001.c,v 1.3 2015/02/11 03:19:37 doug Exp $ */
+/* $OpenBSD: gostr341001.c,v 1.4 2015/02/14 06:40:04 jsing Exp $ */
/*
* Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
* Copyright (c) 2005-2006 Cryptocom LTD
@@ -168,23 +168,22 @@ gost2001_do_sign(BIGNUM *md, GOST_KEY *eckey)
s = newsig->s;
r = newsig->r;
group = GOST_KEY_get0_group(eckey);
- order = BN_CTX_get(ctx);
- if (order == NULL)
+ if ((order = BN_CTX_get(ctx)) == NULL)
goto err;
if (EC_GROUP_get_order(group, order, ctx) == 0)
goto err;
priv_key = GOST_KEY_get0_private_key(eckey);
- e = BN_CTX_get(ctx);
- if (e == NULL)
+ if ((e = BN_CTX_get(ctx)) == NULL)
goto err;
if (BN_mod(e, md, order, ctx) == 0)
goto err;
if (BN_is_zero(e))
BN_one(e);
- k = BN_CTX_get(ctx);
- X = BN_CTX_get(ctx);
- C = EC_POINT_new(group);
- if (C == NULL)
+ if ((k = BN_CTX_get(ctx)) == NULL)
+ goto err;
+ if ((X = BN_CTX_get(ctx)) == NULL)
+ goto err;
+ if ((C = EC_POINT_new(group)) == NULL)
goto err;
do {
do {
@@ -218,15 +217,13 @@ gost2001_do_sign(BIGNUM *md, GOST_KEY *eckey)
} while (BN_is_zero(r));
/* s = (r*priv_key+k*e) mod order */
if (tmp == NULL) {
- tmp = BN_CTX_get(ctx);
- if (tmp == NULL)
+ if ((tmp = BN_CTX_get(ctx)) == NULL)
goto err;
}
if (BN_mod_mul(tmp, priv_key, r, order, ctx) == 0)
goto err;
if (tmp2 == NULL) {
- tmp2 = BN_CTX_get(ctx);
- if (tmp2 == NULL)
+ if ((tmp2 = BN_CTX_get(ctx)) == NULL)
goto err;
}
if (BN_mod_mul(tmp2, k, e, order, ctx) == 0)
@@ -264,15 +261,21 @@ gost2001_do_verify(BIGNUM *md, ECDSA_SIG *sig, GOST_KEY *ec)
if (ctx == NULL)
goto err;
BN_CTX_start(ctx);
- order = BN_CTX_get(ctx);
- e = BN_CTX_get(ctx);
- z1 = BN_CTX_get(ctx);
- z2 = BN_CTX_get(ctx);
- tmp = BN_CTX_get(ctx);
- X = BN_CTX_get(ctx);
- R = BN_CTX_get(ctx);
- v = BN_CTX_get(ctx);
- if (v == NULL)
+ if ((order = BN_CTX_get(ctx)) == NULL)
+ goto err;
+ if ((e = BN_CTX_get(ctx)) == NULL)
+ goto err;
+ if ((z1 = BN_CTX_get(ctx)) == NULL)
+ goto err;
+ if ((z2 = BN_CTX_get(ctx)) == NULL)
+ goto err;
+ if ((tmp = BN_CTX_get(ctx)) == NULL)
+ goto err;
+ if ((X = BN_CTX_get(ctx)) == NULL)
+ goto err;
+ if ((R = BN_CTX_get(ctx)) == NULL)
+ goto err;
+ if ((v = BN_CTX_get(ctx)) == NULL)
goto err;
if (EC_GROUP_get_order(group, order, ctx) == 0)
@@ -289,8 +292,7 @@ gost2001_do_verify(BIGNUM *md, ECDSA_SIG *sig, GOST_KEY *ec)
goto err;
if (BN_is_zero(e))
BN_one(e);
- v = BN_mod_inverse(v, e, order, ctx);
- if (v == NULL)
+ if ((v = BN_mod_inverse(v, e, order, ctx)) == NULL)
goto err;
if (BN_mod_mul(z1, sig->s, v, order, ctx) == 0)
goto err;
@@ -298,8 +300,7 @@ gost2001_do_verify(BIGNUM *md, ECDSA_SIG *sig, GOST_KEY *ec)
goto err;
if (BN_mod_mul(z2, tmp, v, order, ctx) == 0)
goto err;
- C = EC_POINT_new(group);
- if (C == NULL)
+ if ((C = EC_POINT_new(group)) == NULL)
goto err;
if (EC_POINT_mul(group, C, z1, pub_key, z2, ctx) == 0) {
GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_EC_LIB);
@@ -345,9 +346,9 @@ VKO_compute_key(BIGNUM *X, BIGNUM *Y, const GOST_KEY *pkey, GOST_KEY *priv_key,
if (ctx == NULL)
goto err;
BN_CTX_start(ctx);
- p = BN_CTX_get(ctx);
- order = BN_CTX_get(ctx);
- if (order == NULL)
+ if ((p = BN_CTX_get(ctx)) == NULL)
+ goto err;
+ if ((order = BN_CTX_get(ctx)) == NULL)
goto err;
if (EC_GROUP_get_order(group, order, ctx) == 0)
goto err;
diff --git a/lib/libssl/src/crypto/gost/gostr341001_ameth.c b/lib/libssl/src/crypto/gost/gostr341001_ameth.c
index 45ddd44e42b..3153d2f2eb8 100644
--- a/lib/libssl/src/crypto/gost/gostr341001_ameth.c
+++ b/lib/libssl/src/crypto/gost/gostr341001_ameth.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gostr341001_ameth.c,v 1.8 2015/02/11 04:05:14 beck Exp $ */
+/* $OpenBSD: gostr341001_ameth.c,v 1.9 2015/02/14 06:40:04 jsing Exp $ */
/*
* Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
* Copyright (c) 2005-2006 Cryptocom LTD
@@ -347,9 +347,9 @@ pub_print_gost01(BIO *out, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx)
return 0;
}
BN_CTX_start(ctx);
- X = BN_CTX_get(ctx);
- Y = BN_CTX_get(ctx);
- if (X == NULL || Y == NULL)
+ if ((X = BN_CTX_get(ctx)) == NULL)
+ goto err;
+ if ((Y = BN_CTX_get(ctx)) == NULL)
goto err;
pubkey = GOST_KEY_get0_public_key(pkey->pkey.gost);
group = GOST_KEY_get0_group(pkey->pkey.gost);
diff --git a/lib/libssl/src/crypto/gost/gostr341001_key.c b/lib/libssl/src/crypto/gost/gostr341001_key.c
index f00d361d3f7..dbe360620a8 100644
--- a/lib/libssl/src/crypto/gost/gostr341001_key.c
+++ b/lib/libssl/src/crypto/gost/gostr341001_key.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gostr341001_key.c,v 1.4 2015/02/11 03:19:37 doug Exp $ */
+/* $OpenBSD: gostr341001_key.c,v 1.5 2015/02/14 06:40:04 jsing Exp $ */
/*
* Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
* Copyright (c) 2005-2006 Cryptocom LTD
@@ -198,9 +198,9 @@ GOST_KEY_set_public_key_affine_coordinates(GOST_KEY *key, BIGNUM *x, BIGNUM *y)
if (point == NULL)
goto err;
- tx = BN_CTX_get(ctx);
- ty = BN_CTX_get(ctx);
- if (ty == NULL)
+ if ((tx = BN_CTX_get(ctx)) == NULL)
+ goto err;
+ if ((ty = BN_CTX_get(ctx)) == NULL)
goto err;
if (EC_POINT_set_affine_coordinates_GFp(key->group, point, x, y,
ctx) == 0)
diff --git a/lib/libssl/src/crypto/gost/gostr341001_pmeth.c b/lib/libssl/src/crypto/gost/gostr341001_pmeth.c
index 0157996a40e..a297587c62b 100644
--- a/lib/libssl/src/crypto/gost/gostr341001_pmeth.c
+++ b/lib/libssl/src/crypto/gost/gostr341001_pmeth.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gostr341001_pmeth.c,v 1.10 2015/02/11 04:05:14 beck Exp $ */
+/* $OpenBSD: gostr341001_pmeth.c,v 1.11 2015/02/14 06:40:04 jsing Exp $ */
/*
* Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
* Copyright (c) 2005-2006 Cryptocom LTD
@@ -324,10 +324,11 @@ gost01_VKO_key(EVP_PKEY *pub_key, EVP_PKEY *priv_key, const unsigned char *ukm,
return 0;
BN_CTX_start(ctx);
- UKM = BN_CTX_get(ctx);
- X = BN_CTX_get(ctx);
- Y = BN_CTX_get(ctx);
- if (Y == NULL)
+ if ((UKM = BN_CTX_get(ctx)) == NULL)
+ goto err;
+ if ((X = BN_CTX_get(ctx)) == NULL)
+ goto err;
+ if ((Y = BN_CTX_get(ctx)) == NULL)
goto err;
GOST_le2bn(ukm, 8, UKM);