diff options
Diffstat (limited to '')
-rw-r--r-- | src/lib/libcrypto/bn/bn_add.c | 76 |
1 files changed, 4 insertions, 72 deletions
diff --git a/src/lib/libcrypto/bn/bn_add.c b/src/lib/libcrypto/bn/bn_add.c index 86768a312a..81fa60e429 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.26 2023/07/08 12:21:58 beck Exp $ */ | 1 | /* $OpenBSD: bn_add.c,v 1.29 2025/05/25 04:53:05 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 | * |
@@ -60,44 +60,10 @@ | |||
60 | #include <limits.h> | 60 | #include <limits.h> |
61 | #include <stdio.h> | 61 | #include <stdio.h> |
62 | 62 | ||
63 | #include <openssl/err.h> | ||
64 | |||
65 | #include "bn_arch.h" | 63 | #include "bn_arch.h" |
66 | #include "bn_local.h" | 64 | #include "bn_local.h" |
67 | #include "bn_internal.h" | 65 | #include "bn_internal.h" |
68 | 66 | #include "err_local.h" | |
69 | /* | ||
70 | * bn_add_words() computes (carry:r[i]) = a[i] + b[i] + carry, where a and b | ||
71 | * are both arrays of words. Any carry resulting from the addition is returned. | ||
72 | */ | ||
73 | #ifndef HAVE_BN_ADD_WORDS | ||
74 | BN_ULONG | ||
75 | bn_add_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n) | ||
76 | { | ||
77 | BN_ULONG carry = 0; | ||
78 | |||
79 | assert(n >= 0); | ||
80 | if (n <= 0) | ||
81 | return 0; | ||
82 | |||
83 | while (n & ~3) { | ||
84 | bn_qwaddqw(a[3], a[2], a[1], a[0], b[3], b[2], b[1], b[0], | ||
85 | carry, &carry, &r[3], &r[2], &r[1], &r[0]); | ||
86 | a += 4; | ||
87 | b += 4; | ||
88 | r += 4; | ||
89 | n -= 4; | ||
90 | } | ||
91 | while (n) { | ||
92 | bn_addw_addw(a[0], b[0], carry, &carry, &r[0]); | ||
93 | a++; | ||
94 | b++; | ||
95 | r++; | ||
96 | n--; | ||
97 | } | ||
98 | return carry; | ||
99 | } | ||
100 | #endif | ||
101 | 67 | ||
102 | /* | 68 | /* |
103 | * bn_add() computes (carry:r[i]) = a[i] + b[i] + carry, where a and b are both | 69 | * bn_add() computes (carry:r[i]) = a[i] + b[i] + carry, where a and b are both |
@@ -147,40 +113,6 @@ bn_add(BN_ULONG *r, int r_len, const BN_ULONG *a, int a_len, const BN_ULONG *b, | |||
147 | #endif | 113 | #endif |
148 | 114 | ||
149 | /* | 115 | /* |
150 | * bn_sub_words() computes (borrow:r[i]) = a[i] - b[i] - borrow, where a and b | ||
151 | * are both arrays of words. Any borrow resulting from the subtraction is | ||
152 | * returned. | ||
153 | */ | ||
154 | #ifndef HAVE_BN_SUB_WORDS | ||
155 | BN_ULONG | ||
156 | bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n) | ||
157 | { | ||
158 | BN_ULONG borrow = 0; | ||
159 | |||
160 | assert(n >= 0); | ||
161 | if (n <= 0) | ||
162 | return 0; | ||
163 | |||
164 | while (n & ~3) { | ||
165 | bn_qwsubqw(a[3], a[2], a[1], a[0], b[3], b[2], b[1], b[0], | ||
166 | borrow, &borrow, &r[3], &r[2], &r[1], &r[0]); | ||
167 | a += 4; | ||
168 | b += 4; | ||
169 | r += 4; | ||
170 | n -= 4; | ||
171 | } | ||
172 | while (n) { | ||
173 | bn_subw_subw(a[0], b[0], borrow, &borrow, &r[0]); | ||
174 | a++; | ||
175 | b++; | ||
176 | r++; | ||
177 | n--; | ||
178 | } | ||
179 | return borrow; | ||
180 | } | ||
181 | #endif | ||
182 | |||
183 | /* | ||
184 | * bn_sub() computes (borrow:r[i]) = a[i] - b[i] - borrow, where a and b are both | 116 | * bn_sub() computes (borrow:r[i]) = a[i] - b[i] - borrow, where a and b are both |
185 | * arrays of words (r may be the same as a or b). The length of a and b may | 117 | * arrays of words (r may be the same as a or b). The length of a and b may |
186 | * differ, while r must be at least max(a_len, b_len) in length. Any borrow | 118 | * differ, while r must be at least max(a_len, b_len) in length. Any borrow |
@@ -208,7 +140,7 @@ bn_sub(BN_ULONG *r, int r_len, const BN_ULONG *a, int a_len, const BN_ULONG *b, | |||
208 | /* XXX - consider doing four at a time to match bn_sub_words. */ | 140 | /* XXX - consider doing four at a time to match bn_sub_words. */ |
209 | while (diff_len < 0) { | 141 | while (diff_len < 0) { |
210 | /* Compute r[0] = 0 - b[0] - borrow. */ | 142 | /* Compute r[0] = 0 - b[0] - borrow. */ |
211 | bn_subw(0 - b[0], borrow, &borrow, &r[0]); | 143 | bn_subw_subw(0, b[0], borrow, &borrow, &r[0]); |
212 | diff_len++; | 144 | diff_len++; |
213 | b++; | 145 | b++; |
214 | r++; | 146 | r++; |
@@ -217,7 +149,7 @@ bn_sub(BN_ULONG *r, int r_len, const BN_ULONG *a, int a_len, const BN_ULONG *b, | |||
217 | /* XXX - consider doing four at a time to match bn_sub_words. */ | 149 | /* XXX - consider doing four at a time to match bn_sub_words. */ |
218 | while (diff_len > 0) { | 150 | while (diff_len > 0) { |
219 | /* Compute r[0] = a[0] - 0 - borrow. */ | 151 | /* Compute r[0] = a[0] - 0 - borrow. */ |
220 | bn_subw(a[0], borrow, &borrow, &r[0]); | 152 | bn_subw_subw(a[0], 0, borrow, &borrow, &r[0]); |
221 | diff_len--; | 153 | diff_len--; |
222 | a++; | 154 | a++; |
223 | r++; | 155 | r++; |