Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / dropbear / libtommath / bn_mp_mul_2d.c
blobd803bf41114f05609d92e0b2697423d00e87daac
1 #include <tommath.h>
2 #ifdef BN_MP_MUL_2D_C
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis
5 * LibTomMath is a library that provides multiple-precision
6 * integer arithmetic as well as number theoretic functionality.
8 * The library was designed directly after the MPI library by
9 * Michael Fromberger but has been written from scratch with
10 * additional optimizations in place.
12 * The library is free for all purposes without any express
13 * guarantee it works.
15 * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
18 /* shift left by a certain bit count */
19 int mp_mul_2d (mp_int * a, int b, mp_int * c)
21 mp_digit d;
22 int res;
24 /* copy */
25 if (a != c) {
26 if ((res = mp_copy (a, c)) != MP_OKAY) {
27 return res;
31 if (c->alloc < (int)(c->used + b/DIGIT_BIT + 1)) {
32 if ((res = mp_grow (c, c->used + b / DIGIT_BIT + 1)) != MP_OKAY) {
33 return res;
37 /* shift by as many digits in the bit count */
38 if (b >= (int)DIGIT_BIT) {
39 if ((res = mp_lshd (c, b / DIGIT_BIT)) != MP_OKAY) {
40 return res;
44 /* shift any bit count < DIGIT_BIT */
45 d = (mp_digit) (b % DIGIT_BIT);
46 if (d != 0) {
47 register mp_digit *tmpc, shift, mask, r, rr;
48 register int x;
50 /* bitmask for carries */
51 mask = (((mp_digit)1) << d) - 1;
53 /* shift for msbs */
54 shift = DIGIT_BIT - d;
56 /* alias */
57 tmpc = c->dp;
59 /* carry */
60 r = 0;
61 for (x = 0; x < c->used; x++) {
62 /* get the higher bits of the current word */
63 rr = (*tmpc >> shift) & mask;
65 /* shift the current word and OR in the carry */
66 *tmpc = ((*tmpc << d) | r) & MP_MASK;
67 ++tmpc;
69 /* set the carry to the carry bits of the current word */
70 r = rr;
73 /* set final carry */
74 if (r != 0) {
75 c->dp[(c->used)++] = r;
78 mp_clamp (c);
79 return MP_OKAY;
81 #endif
83 /* $Source: /cvs/libtom/libtommath/bn_mp_mul_2d.c,v $ */
84 /* $Revision: 1.3 $ */
85 /* $Date: 2006/03/31 14:18:44 $ */