summaryrefslogtreecommitdiffstats
path: root/libtommath/bn_mp_signed_rsh.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_mp_signed_rsh.c
parent233d558b1e7e820960a3db26cd2aedcf036ead9e (diff)
parent505f963287b050bd46871d4659cebc65986ca5ac (diff)
downloadtcl-db7fa65dce753b80d5f2a87799aabd481e9144a2.zip
tcl-db7fa65dce753b80d5f2a87799aabd481e9144a2.tar.gz
tcl-db7fa65dce753b80d5f2a87799aabd481e9144a2.tar.bz2
Merge libtommath
Diffstat (limited to 'libtommath/bn_mp_signed_rsh.c')
-rw-r--r--libtommath/bn_mp_signed_rsh.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/libtommath/bn_mp_signed_rsh.c b/libtommath/bn_mp_signed_rsh.c
new file mode 100644
index 0000000..8d8d841
--- /dev/null
+++ b/libtommath/bn_mp_signed_rsh.c
@@ -0,0 +1,22 @@
+#include "tommath_private.h"
+#ifdef BN_MP_SIGNED_RSH_C
+/* LibTomMath, multiple-precision integer library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
+
+/* shift right by a certain bit count with sign extension */
+mp_err mp_signed_rsh(const mp_int *a, int b, mp_int *c)
+{
+ mp_err res;
+ if (a->sign == MP_ZPOS) {
+ return mp_div_2d(a, b, c, NULL);
+ }
+
+ res = mp_add_d(a, 1uL, c);
+ if (res != MP_OKAY) {
+ return res;
+ }
+
+ res = mp_div_2d(c, b, c, NULL);
+ return (res == MP_OKAY) ? mp_sub_d(c, 1uL, c) : res;
+}
+#endif