summaryrefslogtreecommitdiffstats
path: root/libtommath/bn_mp_get_long.c
diff options
context:
space:
mode:
authorgahr <gahr@gahr.ch>2016-03-13 17:23:31 (GMT)
committergahr <gahr@gahr.ch>2016-03-13 17:23:31 (GMT)
commit8377ed833a9566731442ef744b419425638d5040 (patch)
treed6711e0d2ce406178c1d54c9db8a541b792b6b0b /libtommath/bn_mp_get_long.c
parent48a3d3e4dca22efb2981fd8eb9b505b19438a704 (diff)
downloadtcl-8377ed833a9566731442ef744b419425638d5040.zip
tcl-8377ed833a9566731442ef744b419425638d5040.tar.gz
tcl-8377ed833a9566731442ef744b419425638d5040.tar.bz2
[e6f27aa56f] Add files I missed in my previous commit
Diffstat (limited to 'libtommath/bn_mp_get_long.c')
-rw-r--r--libtommath/bn_mp_get_long.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/libtommath/bn_mp_get_long.c b/libtommath/bn_mp_get_long.c
new file mode 100644
index 0000000..7c3d0fe
--- /dev/null
+++ b/libtommath/bn_mp_get_long.c
@@ -0,0 +1,41 @@
+#include <tommath_private.h>
+#ifdef BN_MP_GET_LONG_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.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tstdenis82@gmail.com, http://libtom.org
+ */
+
+/* get the lower unsigned long of an mp_int, platform dependent */
+unsigned long mp_get_long(mp_int * a)
+{
+ int i;
+ unsigned long res;
+
+ if (a->used == 0) {
+ return 0;
+ }
+
+ /* get number of digits of the lsb we have to read */
+ i = MIN(a->used,(int)(((sizeof(unsigned long) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1;
+
+ /* get most significant digit of result */
+ res = DIGIT(a,i);
+
+#if (ULONG_MAX != 0xffffffffuL) || (DIGIT_BIT < 32)
+ while (--i >= 0) {
+ res = (res << DIGIT_BIT) | DIGIT(a,i);
+ }
+#endif
+ return res;
+}
+#endif