Remove building with NOCRYPTO option
[minix.git] / crypto / external / bsd / heimdal / dist / lib / hcrypto / libtommath / bn_mp_sub.c
blob71ed43a6b53ccce0485274a2c6df0bec53e65429
1 /* $NetBSD: bn_mp_sub.c,v 1.1.1.2 2014/04/24 12:45:31 pettai Exp $ */
3 #include <tommath.h>
4 #ifdef BN_MP_SUB_C
5 /* LibTomMath, multiple-precision integer library -- Tom St Denis
7 * LibTomMath is a library that provides multiple-precision
8 * integer arithmetic as well as number theoretic functionality.
10 * The library was designed directly after the MPI library by
11 * Michael Fromberger but has been written from scratch with
12 * additional optimizations in place.
14 * The library is free for all purposes without any express
15 * guarantee it works.
17 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
20 /* high level subtraction (handles signs) */
21 int
22 mp_sub (mp_int * a, mp_int * b, mp_int * c)
24 int sa, sb, res;
26 sa = a->sign;
27 sb = b->sign;
29 if (sa != sb) {
30 /* subtract a negative from a positive, OR */
31 /* subtract a positive from a negative. */
32 /* In either case, ADD their magnitudes, */
33 /* and use the sign of the first number. */
34 c->sign = sa;
35 res = s_mp_add (a, b, c);
36 } else {
37 /* subtract a positive from a positive, OR */
38 /* subtract a negative from a negative. */
39 /* First, take the difference between their */
40 /* magnitudes, then... */
41 if (mp_cmp_mag (a, b) != MP_LT) {
42 /* Copy the sign from the first */
43 c->sign = sa;
44 /* The first has a larger or equal magnitude */
45 res = s_mp_sub (a, b, c);
46 } else {
47 /* The result has the *opposite* sign from */
48 /* the first number. */
49 c->sign = (sa == MP_ZPOS) ? MP_NEG : MP_ZPOS;
50 /* The second has a larger magnitude */
51 res = s_mp_sub (b, a, c);
54 return res;
57 #endif
59 /* Source: /cvs/libtom/libtommath/bn_mp_sub.c,v */
60 /* Revision: 1.4 */
61 /* Date: 2006/12/28 01:25:13 */