Remove building with NOCRYPTO option
[minix.git] / crypto / external / bsd / heimdal / dist / lib / hcrypto / libtommath / bn_mp_and.c
blob6ff51e0053a83ea9e436a0f9a279176fcd34a87f
1 /* $NetBSD: bn_mp_and.c,v 1.1.1.2 2014/04/24 12:45:31 pettai Exp $ */
3 #include <tommath.h>
4 #ifdef BN_MP_AND_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 /* AND two ints together */
21 int
22 mp_and (mp_int * a, mp_int * b, mp_int * c)
24 int res, ix, px;
25 mp_int t, *x;
27 if (a->used > b->used) {
28 if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
29 return res;
31 px = b->used;
32 x = b;
33 } else {
34 if ((res = mp_init_copy (&t, b)) != MP_OKAY) {
35 return res;
37 px = a->used;
38 x = a;
41 for (ix = 0; ix < px; ix++) {
42 t.dp[ix] &= x->dp[ix];
45 /* zero digits above the last from the smallest mp_int */
46 for (; ix < t.used; ix++) {
47 t.dp[ix] = 0;
50 mp_clamp (&t);
51 mp_exch (c, &t);
52 mp_clear (&t);
53 return MP_OKAY;
55 #endif
57 /* Source: /cvs/libtom/libtommath/bn_mp_and.c,v */
58 /* Revision: 1.4 */
59 /* Date: 2006/12/28 01:25:13 */