summaryrefslogtreecommitdiffstats
path: root/libtommath/bn_s_mp_sub.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2019-06-13 21:28:11 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2019-06-13 21:28:11 (GMT)
commitdb7fa65dce753b80d5f2a87799aabd481e9144a2 (patch)
tree40a8affd6eb84a709b158e4c1f5e4117e9f18171 /libtommath/bn_s_mp_sub.c
parent233d558b1e7e820960a3db26cd2aedcf036ead9e (diff)
parent505f963287b050bd46871d4659cebc65986ca5ac (diff)
downloadtcl-db7fa65dce753b80d5f2a87799aabd481e9144a2.zip
tcl-db7fa65dce753b80d5f2a87799aabd481e9144a2.tar.gz
tcl-db7fa65dce753b80d5f2a87799aabd481e9144a2.tar.bz2
Merge libtommath
Diffstat (limited to 'libtommath/bn_s_mp_sub.c')
-rw-r--r--libtommath/bn_s_mp_sub.c34
1 files changed, 10 insertions, 24 deletions
diff --git a/libtommath/bn_s_mp_sub.c b/libtommath/bn_s_mp_sub.c
index 88e44dc..5672dab 100644
--- a/libtommath/bn_s_mp_sub.c
+++ b/libtommath/bn_s_mp_sub.c
@@ -1,21 +1,13 @@
#include "tommath_private.h"
#ifdef BN_S_MP_SUB_C
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * SPDX-License-Identifier: Unlicense
- */
+/* LibTomMath, multiple-precision integer library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
/* low level subtraction (assumes |a| > |b|), HAC pp.595 Algorithm 14.9 */
-int s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c)
+mp_err s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c)
{
- int olduse, res, min, max;
+ int olduse, min, max;
+ mp_err err;
/* find sizes */
min = b->used;
@@ -23,8 +15,8 @@ int s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c)
/* init result */
if (c->alloc < max) {
- if ((res = mp_grow(c, max)) != MP_OKAY) {
- return res;
+ if ((err = mp_grow(c, max)) != MP_OKAY) {
+ return err;
}
}
olduse = c->used;
@@ -50,7 +42,7 @@ int s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c)
* if a carry does occur it will propagate all the way to the
* MSB. As a result a single shift is enough to get the carry
*/
- u = *tmpc >> (((size_t)CHAR_BIT * sizeof(mp_digit)) - 1u);
+ u = *tmpc >> (MP_SIZEOF_BITS(mp_digit) - 1u);
/* Clear carry from T[i] */
*tmpc++ &= MP_MASK;
@@ -62,16 +54,14 @@ int s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c)
*tmpc = *tmpa++ - u;
/* U = carry bit of T[i] */
- u = *tmpc >> (((size_t)CHAR_BIT * sizeof(mp_digit)) - 1u);
+ u = *tmpc >> (MP_SIZEOF_BITS(mp_digit) - 1u);
/* Clear carry from T[i] */
*tmpc++ &= MP_MASK;
}
/* clear digits above used (since we may not have grown result above) */
- for (i = c->used; i < olduse; i++) {
- *tmpc++ = 0;
- }
+ MP_ZERO_DIGITS(tmpc, olduse - c->used);
}
mp_clamp(c);
@@ -79,7 +69,3 @@ int s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c)
}
#endif
-
-/* ref: $Format:%D$ */
-/* git commit: $Format:%H$ */
-/* commit time: $Format:%ai$ */