From: tb Date: Mon, 27 Mar 2023 10:21:23 +0000 (+0000) Subject: Convert BN_copy() with explicit comparison against NULL to bn_copy() X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=58460d4fc2562eb68a54fe7cd6298331de70616a;p=openbsd Convert BN_copy() with explicit comparison against NULL to bn_copy() ok jsing --- diff --git a/lib/libcrypto/bn/bn_div.c b/lib/libcrypto/bn/bn_div.c index 692e6184070..3225fa44249 100644 --- a/lib/libcrypto/bn/bn_div.c +++ b/lib/libcrypto/bn/bn_div.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_div.c,v 1.39 2023/02/16 10:41:03 jsing Exp $ */ +/* $OpenBSD: bn_div.c,v 1.40 2023/03/27 10:21:23 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -264,7 +264,7 @@ BN_div_internal(BIGNUM *quotient, BIGNUM *remainder, const BIGNUM *numerator, if (!no_branch) { if (BN_ucmp(numerator, divisor) < 0) { if (remainder != NULL) { - if (BN_copy(remainder, numerator) == NULL) + if (!bn_copy(remainder, numerator)) goto err; } if (quotient != NULL) diff --git a/lib/libcrypto/bn/bn_exp.c b/lib/libcrypto/bn/bn_exp.c index 9e4497bb069..4944daa48c0 100644 --- a/lib/libcrypto/bn/bn_exp.c +++ b/lib/libcrypto/bn/bn_exp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_exp.c,v 1.41 2023/03/26 19:09:42 tb Exp $ */ +/* $OpenBSD: bn_exp.c,v 1.42 2023/03/27 10:21:23 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -142,12 +142,12 @@ BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) if (rr == NULL || v == NULL) goto err; - if (BN_copy(v, a) == NULL) + if (!bn_copy(v, a)) goto err; bits = BN_num_bits(p); if (BN_is_odd(p)) { - if (BN_copy(rr, a) == NULL) + if (!bn_copy(rr, a)) goto err; } else { if (!BN_one(rr)) diff --git a/lib/libcrypto/bn/bn_gcd.c b/lib/libcrypto/bn/bn_gcd.c index 84c3d858500..138befc8680 100644 --- a/lib/libcrypto/bn/bn_gcd.c +++ b/lib/libcrypto/bn/bn_gcd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_gcd.c,v 1.21 2023/01/21 09:21:11 jsing Exp $ */ +/* $OpenBSD: bn_gcd.c,v 1.22 2023/03/27 10:21:23 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -221,9 +221,9 @@ BN_gcd_no_branch(BIGNUM *in, const BIGNUM *a, const BIGNUM *n, if (!BN_one(X)) goto err; BN_zero(Y); - if (BN_copy(B, a) == NULL) + if (!bn_copy(B, a)) goto err; - if (BN_copy(A, n) == NULL) + if (!bn_copy(A, n)) goto err; A->neg = 0; @@ -337,9 +337,9 @@ BN_gcd(BIGNUM *r, const BIGNUM *in_a, const BIGNUM *in_b, BN_CTX *ctx) if ((b = BN_CTX_get(ctx)) == NULL) goto err; - if (BN_copy(a, in_a) == NULL) + if (!bn_copy(a, in_a)) goto err; - if (BN_copy(b, in_b) == NULL) + if (!bn_copy(b, in_b)) goto err; a->neg = 0; b->neg = 0; @@ -353,7 +353,7 @@ BN_gcd(BIGNUM *r, const BIGNUM *in_a, const BIGNUM *in_b, BN_CTX *ctx) if (t == NULL) goto err; - if (BN_copy(r, t) == NULL) + if (!bn_copy(r, t)) goto err; ret = 1; @@ -419,9 +419,9 @@ BN_mod_inverse_no_branch(BIGNUM *in, const BIGNUM *a, const BIGNUM *n, if (!BN_one(X)) goto err; BN_zero(Y); - if (BN_copy(B, a) == NULL) + if (!bn_copy(B, a)) goto err; - if (BN_copy(A, n) == NULL) + if (!bn_copy(A, n)) goto err; A->neg = 0; @@ -582,9 +582,9 @@ BN_mod_inverse_internal(BIGNUM *in, const BIGNUM *a, const BIGNUM *n, BN_CTX *ct if (!BN_one(X)) goto err; BN_zero(Y); - if (BN_copy(B, a) == NULL) + if (!bn_copy(B, a)) goto err; - if (BN_copy(A, n) == NULL) + if (!bn_copy(A, n)) goto err; A->neg = 0; if (B->neg || (BN_ucmp(B, A) >= 0)) { diff --git a/lib/libcrypto/bn/bn_kron.c b/lib/libcrypto/bn/bn_kron.c index cbd79f04550..f48823acabb 100644 --- a/lib/libcrypto/bn/bn_kron.c +++ b/lib/libcrypto/bn/bn_kron.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_kron.c,v 1.13 2023/03/25 10:51:18 tb Exp $ */ +/* $OpenBSD: bn_kron.c,v 1.14 2023/03/27 10:21:23 tb Exp $ */ /* ==================================================================== * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. * @@ -78,9 +78,9 @@ BN_kronecker(const BIGNUM *A, const BIGNUM *B, BN_CTX *ctx) if ((b = BN_CTX_get(ctx)) == NULL) goto end; - if (BN_copy(a, A) == NULL) + if (!bn_copy(a, A)) goto end; - if (BN_copy(b, B) == NULL) + if (!bn_copy(b, B)) goto end; /* diff --git a/lib/libcrypto/bn/bn_mod.c b/lib/libcrypto/bn/bn_mod.c index 2072dd904fb..868ef5bc5bf 100644 --- a/lib/libcrypto/bn/bn_mod.c +++ b/lib/libcrypto/bn/bn_mod.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_mod.c,v 1.19 2023/02/03 05:15:40 jsing Exp $ */ +/* $OpenBSD: bn_mod.c,v 1.20 2023/03/27 10:21:23 tb Exp $ */ /* Includes code written by Lenka Fibikova * for the OpenSSL project. */ /* ==================================================================== @@ -264,7 +264,7 @@ BN_mod_lshift(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m, BN_CTX *ctx) if (BN_is_negative(m)) { if ((abs_m = BN_CTX_get(ctx)) == NULL) goto err; - if (BN_copy(abs_m, m) == NULL) + if (!bn_copy(abs_m, m)) goto err; BN_set_negative(abs_m, 0); m = abs_m; @@ -288,7 +288,7 @@ BN_mod_lshift_quick(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m) { int max_shift; - if (BN_copy(r, a) == NULL) + if (!bn_copy(r, a)) return 0; while (n > 0) { diff --git a/lib/libcrypto/bn/bn_mont.c b/lib/libcrypto/bn/bn_mont.c index 582c8d4ef8d..b7b2384cffd 100644 --- a/lib/libcrypto/bn/bn_mont.c +++ b/lib/libcrypto/bn/bn_mont.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_mont.c,v 1.53 2023/03/26 19:09:42 tb Exp $ */ +/* $OpenBSD: bn_mont.c,v 1.54 2023/03/27 10:21:23 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -561,7 +561,7 @@ BN_from_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mctx, BN_CTX *ctx) if ((tmp = BN_CTX_get(ctx)) == NULL) goto err; - if (BN_copy(tmp, a) == NULL) + if (!bn_copy(tmp, a)) goto err; if (!bn_montgomery_reduce(r, tmp, mctx)) goto err; diff --git a/lib/libcrypto/ecdsa/ecs_ossl.c b/lib/libcrypto/ecdsa/ecs_ossl.c index 271c8435f8a..25bcb06e887 100644 --- a/lib/libcrypto/ecdsa/ecs_ossl.c +++ b/lib/libcrypto/ecdsa/ecs_ossl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ecs_ossl.c,v 1.29 2023/03/07 09:27:10 jsing Exp $ */ +/* $OpenBSD: ecs_ossl.c,v 1.30 2023/03/27 10:21:23 tb Exp $ */ /* * Written by Nils Larsch for the OpenSSL project */ @@ -322,7 +322,7 @@ ecdsa_do_sign(const unsigned char *dgst, int dgst_len, ckinv = kinv; } else { ckinv = in_kinv; - if (BN_copy(ret->r, in_r) == NULL) { + if (!bn_copy(ret->r, in_r)) { ECDSAerror(ERR_R_MALLOC_FAILURE); goto err; }