summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ec
diff options
context:
space:
mode:
authorjsing <>2022-11-24 01:30:01 +0000
committerjsing <>2022-11-24 01:30:01 +0000
commit8a7c8abfd4f8805f2a5101e89356e9411d908a0c (patch)
treefaea38f1c86dae9f6d4b143b2aa9f7752ecd0a34 /src/lib/libcrypto/ec
parent095ccaedd0631462c52a1a2d9aa19b35c3e45b12 (diff)
downloadopenbsd-8a7c8abfd4f8805f2a5101e89356e9411d908a0c.tar.gz
openbsd-8a7c8abfd4f8805f2a5101e89356e9411d908a0c.tar.bz2
openbsd-8a7c8abfd4f8805f2a5101e89356e9411d908a0c.zip
Change bn_expand()/bn_wexpand() to indicate failure/success via 0/1.
Currently bn_expand()/bn_wexpand() return a BIGNUM *, however none of the callers use this (and many already treat it as a true/false value). Change these functions to return 0 on failure and 1 on success, revising callers that test against NULL in the process. ok tb@
Diffstat (limited to 'src/lib/libcrypto/ec')
-rw-r--r--src/lib/libcrypto/ec/ec2_smpl.c10
-rw-r--r--src/lib/libcrypto/ec/ecp_nistz256.c4
-rw-r--r--src/lib/libcrypto/ec/ecp_smpl.c18
3 files changed, 16 insertions, 16 deletions
diff --git a/src/lib/libcrypto/ec/ec2_smpl.c b/src/lib/libcrypto/ec/ec2_smpl.c
index b6c06a45a2..b4d7f5db2e 100644
--- a/src/lib/libcrypto/ec/ec2_smpl.c
+++ b/src/lib/libcrypto/ec/ec2_smpl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec2_smpl.c,v 1.26 2022/11/24 01:24:37 jsing Exp $ */ 1/* $OpenBSD: ec2_smpl.c,v 1.27 2022/11/24 01:30:01 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 * 4 *
@@ -186,9 +186,9 @@ ec_GF2m_simple_group_copy(EC_GROUP *dest, const EC_GROUP *src)
186 dest->poly[3] = src->poly[3]; 186 dest->poly[3] = src->poly[3];
187 dest->poly[4] = src->poly[4]; 187 dest->poly[4] = src->poly[4];
188 dest->poly[5] = src->poly[5]; 188 dest->poly[5] = src->poly[5];
189 if (bn_expand(&dest->a, dest->poly[0]) == NULL) 189 if (!bn_expand(&dest->a, dest->poly[0]))
190 return 0; 190 return 0;
191 if (bn_expand(&dest->b, dest->poly[0]) == NULL) 191 if (!bn_expand(&dest->b, dest->poly[0]))
192 return 0; 192 return 0;
193 for (i = dest->a.top; i < dest->a.dmax; i++) 193 for (i = dest->a.top; i < dest->a.dmax; i++)
194 dest->a.d[i] = 0; 194 dest->a.d[i] = 0;
@@ -216,7 +216,7 @@ ec_GF2m_simple_group_set_curve(EC_GROUP *group,
216 /* group->a */ 216 /* group->a */
217 if (!BN_GF2m_mod_arr(&group->a, a, group->poly)) 217 if (!BN_GF2m_mod_arr(&group->a, a, group->poly))
218 goto err; 218 goto err;
219 if (bn_expand(&group->a, group->poly[0]) == NULL) 219 if (!bn_expand(&group->a, group->poly[0]))
220 goto err; 220 goto err;
221 for (i = group->a.top; i < group->a.dmax; i++) 221 for (i = group->a.top; i < group->a.dmax; i++)
222 group->a.d[i] = 0; 222 group->a.d[i] = 0;
@@ -224,7 +224,7 @@ ec_GF2m_simple_group_set_curve(EC_GROUP *group,
224 /* group->b */ 224 /* group->b */
225 if (!BN_GF2m_mod_arr(&group->b, b, group->poly)) 225 if (!BN_GF2m_mod_arr(&group->b, b, group->poly))
226 goto err; 226 goto err;
227 if (bn_expand(&group->b, group->poly[0]) == NULL) 227 if (!bn_expand(&group->b, group->poly[0]))
228 goto err; 228 goto err;
229 for (i = group->b.top; i < group->b.dmax; i++) 229 for (i = group->b.top; i < group->b.dmax; i++)
230 group->b.d[i] = 0; 230 group->b.d[i] = 0;
diff --git a/src/lib/libcrypto/ec/ecp_nistz256.c b/src/lib/libcrypto/ec/ecp_nistz256.c
index e4929b92bb..e3a6cc855a 100644
--- a/src/lib/libcrypto/ec/ecp_nistz256.c
+++ b/src/lib/libcrypto/ec/ecp_nistz256.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_nistz256.c,v 1.12 2022/11/19 07:00:57 tb Exp $ */ 1/* $OpenBSD: ecp_nistz256.c,v 1.13 2022/11/24 01:30:01 jsing Exp $ */
2/* Copyright (c) 2014, Intel Corporation. 2/* Copyright (c) 2014, Intel Corporation.
3 * 3 *
4 * Permission to use, copy, modify, and/or distribute this software for any 4 * Permission to use, copy, modify, and/or distribute this software for any
@@ -310,7 +310,7 @@ is_one(const BIGNUM *z)
310static int 310static int
311ecp_nistz256_set_words(BIGNUM *a, BN_ULONG words[P256_LIMBS]) 311ecp_nistz256_set_words(BIGNUM *a, BN_ULONG words[P256_LIMBS])
312{ 312{
313 if (bn_wexpand(a, P256_LIMBS) == NULL) { 313 if (!bn_wexpand(a, P256_LIMBS)) {
314 ECerror(ERR_R_MALLOC_FAILURE); 314 ECerror(ERR_R_MALLOC_FAILURE);
315 return 0; 315 return 0;
316 } 316 }
diff --git a/src/lib/libcrypto/ec/ecp_smpl.c b/src/lib/libcrypto/ec/ecp_smpl.c
index 55fb46869d..71d403b854 100644
--- a/src/lib/libcrypto/ec/ecp_smpl.c
+++ b/src/lib/libcrypto/ec/ecp_smpl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_smpl.c,v 1.36 2022/11/19 07:29:29 tb Exp $ */ 1/* $OpenBSD: ecp_smpl.c,v 1.37 2022/11/24 01:30:01 jsing Exp $ */
2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de> 2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
3 * for the OpenSSL project. 3 * for the OpenSSL project.
4 * Includes code written by Bodo Moeller for the OpenSSL project. 4 * Includes code written by Bodo Moeller for the OpenSSL project.
@@ -1556,8 +1556,8 @@ ec_GFp_simple_mul_ct(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
1556 */ 1556 */
1557 cardinality_bits = BN_num_bits(cardinality); 1557 cardinality_bits = BN_num_bits(cardinality);
1558 group_top = cardinality->top; 1558 group_top = cardinality->top;
1559 if ((bn_wexpand(k, group_top + 2) == NULL) || 1559 if (!bn_wexpand(k, group_top + 2) ||
1560 (bn_wexpand(lambda, group_top + 2) == NULL)) 1560 !bn_wexpand(lambda, group_top + 2))
1561 goto err; 1561 goto err;
1562 1562
1563 if (!BN_copy(k, scalar)) 1563 if (!BN_copy(k, scalar))
@@ -1588,12 +1588,12 @@ ec_GFp_simple_mul_ct(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
1588 goto err; 1588 goto err;
1589 1589
1590 group_top = group->field.top; 1590 group_top = group->field.top;
1591 if ((bn_wexpand(&s->X, group_top) == NULL) || 1591 if (!bn_wexpand(&s->X, group_top) ||
1592 (bn_wexpand(&s->Y, group_top) == NULL) || 1592 !bn_wexpand(&s->Y, group_top) ||
1593 (bn_wexpand(&s->Z, group_top) == NULL) || 1593 !bn_wexpand(&s->Z, group_top) ||
1594 (bn_wexpand(&r->X, group_top) == NULL) || 1594 !bn_wexpand(&r->X, group_top) ||
1595 (bn_wexpand(&r->Y, group_top) == NULL) || 1595 !bn_wexpand(&r->Y, group_top) ||
1596 (bn_wexpand(&r->Z, group_top) == NULL)) 1596 !bn_wexpand(&r->Z, group_top))
1597 goto err; 1597 goto err;
1598 1598
1599 /* 1599 /*