summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjsing <>2023-01-20 04:49:48 +0000
committerjsing <>2023-01-20 04:49:48 +0000
commit6755d56a2d732b6b9e526bb5b2865841c022b076 (patch)
tree52d015bb71db1fa502680496b1c866c41d233fcb /src
parent90f4af0d940f27130b3c3dcc3b0e33de49e9a863 (diff)
downloadopenbsd-6755d56a2d732b6b9e526bb5b2865841c022b076.tar.gz
openbsd-6755d56a2d732b6b9e526bb5b2865841c022b076.tar.bz2
openbsd-6755d56a2d732b6b9e526bb5b2865841c022b076.zip
Reorder functions for easier maintenance.
No functional change.
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/bn/bn_add.c60
1 files changed, 30 insertions, 30 deletions
diff --git a/src/lib/libcrypto/bn/bn_add.c b/src/lib/libcrypto/bn/bn_add.c
index aec7f1ee9a..3352e0e1d5 100644
--- a/src/lib/libcrypto/bn/bn_add.c
+++ b/src/lib/libcrypto/bn/bn_add.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_add.c,v 1.16 2022/11/26 16:08:51 tb Exp $ */ 1/* $OpenBSD: bn_add.c,v 1.17 2023/01/20 04:49:48 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -63,35 +63,6 @@
63#include "bn_local.h" 63#include "bn_local.h"
64 64
65int 65int
66BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
67{
68 int ret, r_neg;
69
70
71 if (a->neg == b->neg) {
72 r_neg = a->neg;
73 ret = BN_uadd(r, a, b);
74 } else {
75 int cmp = BN_ucmp(a, b);
76
77 if (cmp > 0) {
78 r_neg = a->neg;
79 ret = BN_usub(r, a, b);
80 } else if (cmp < 0) {
81 r_neg = b->neg;
82 ret = BN_usub(r, b, a);
83 } else {
84 r_neg = 0;
85 BN_zero(r);
86 ret = 1;
87 }
88 }
89
90 r->neg = r_neg;
91 return ret;
92}
93
94int
95BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) 66BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
96{ 67{
97 int max, min, dif; 68 int max, min, dif;
@@ -183,6 +154,35 @@ BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
183} 154}
184 155
185int 156int
157BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
158{
159 int ret, r_neg;
160
161
162 if (a->neg == b->neg) {
163 r_neg = a->neg;
164 ret = BN_uadd(r, a, b);
165 } else {
166 int cmp = BN_ucmp(a, b);
167
168 if (cmp > 0) {
169 r_neg = a->neg;
170 ret = BN_usub(r, a, b);
171 } else if (cmp < 0) {
172 r_neg = b->neg;
173 ret = BN_usub(r, b, a);
174 } else {
175 r_neg = 0;
176 BN_zero(r);
177 ret = 1;
178 }
179 }
180
181 r->neg = r_neg;
182 return ret;
183}
184
185int
186BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) 186BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
187{ 187{
188 int ret, r_neg; 188 int ret, r_neg;