From 1c5fda515f96c27d4e3b732d887f418453f1cb14 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Wed, 8 Mar 2006 13:16:18 +0000 Subject: Import of libtommath 0.35 From ltm-0.35.tar.bz2 SHA1 of 3f193dbae9351e92d02530994fa18236f7fde01c --HG-- branch : libtommath-orig extra : convert_revision : 2b4b13ac88b2a81e5c86ba868c92c6a452630e02 --- bn_mp_abs.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 bn_mp_abs.c (limited to 'bn_mp_abs.c') diff --git a/bn_mp_abs.c b/bn_mp_abs.c new file mode 100644 index 0000000..34f810f --- /dev/null +++ b/bn_mp_abs.c @@ -0,0 +1,39 @@ +#include +#ifdef BN_MP_ABS_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, tomstdenis@iahu.ca, http://math.libtomcrypt.org + */ + +/* b = |a| + * + * Simple function copies the input and fixes the sign to positive + */ +int +mp_abs (mp_int * a, mp_int * b) +{ + int res; + + /* copy a to b */ + if (a != b) { + if ((res = mp_copy (a, b)) != MP_OKAY) { + return res; + } + } + + /* force the sign of b to positive */ + b->sign = MP_ZPOS; + + return MP_OKAY; +} +#endif -- cgit v1.2.3