aboutsummaryrefslogtreecommitdiff
path: root/lib/hcrypto/libtommath/bn_mp_decr.c
diff options
context:
space:
mode:
authorCy Schubert <cy@FreeBSD.org>2023-06-26 22:56:52 +0000
committerCy Schubert <cy@FreeBSD.org>2023-06-26 22:56:52 +0000
commitb6a943f7197af1a5eb6bb028b9b808ec5016e30c (patch)
treecfbb91e940dd89d0e1d46095f43c228d7d079fa0 /lib/hcrypto/libtommath/bn_mp_decr.c
parent6f4e10db3298f6d65e1e646fe52aaafc3682b788 (diff)
downloadsrc-vendor/heimdal.tar.gz
src-vendor/heimdal.zip
Heimdal 7.8.0 does not support OpenSSL 3.0. 7.9.0 will but it hasn't been released yet. We are importing f62e2f278 for its OpenSSL 3.0 support.
Diffstat (limited to 'lib/hcrypto/libtommath/bn_mp_decr.c')
-rw-r--r--lib/hcrypto/libtommath/bn_mp_decr.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/hcrypto/libtommath/bn_mp_decr.c b/lib/hcrypto/libtommath/bn_mp_decr.c
new file mode 100644
index 000000000000..c6a1572c6e3f
--- /dev/null
+++ b/lib/hcrypto/libtommath/bn_mp_decr.c
@@ -0,0 +1,34 @@
+#include "tommath_private.h"
+#ifdef BN_MP_DECR_C
+/* LibTomMath, multiple-precision integer library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
+
+/* Decrement "a" by one like "a--". Changes input! */
+mp_err mp_decr(mp_int *a)
+{
+ if (MP_IS_ZERO(a)) {
+ mp_set(a,1uL);
+ a->sign = MP_NEG;
+ return MP_OKAY;
+ } else if (a->sign == MP_NEG) {
+ mp_err err;
+ a->sign = MP_ZPOS;
+ if ((err = mp_incr(a)) != MP_OKAY) {
+ return err;
+ }
+ /* There is no -0 in LTM */
+ if (!MP_IS_ZERO(a)) {
+ a->sign = MP_NEG;
+ }
+ return MP_OKAY;
+ } else if (a->dp[0] > 1uL) {
+ a->dp[0]--;
+ if (a->dp[0] == 0u) {
+ mp_zero(a);
+ }
+ return MP_OKAY;
+ } else {
+ return mp_sub_d(a, 1uL,a);
+ }
+}
+#endif