Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 80 lines (64 sloc) 1.798 kB
e549ccf added libtommath-0.32
Tom St Denis authored
1 #include <tommath.h>
2 #ifdef BN_MP_MUL_D_C
57354e1 added libtommath-0.12
Tom St Denis authored
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis
4 *
c1da6aa added libtommath-0.25
Tom St Denis authored
5 * LibTomMath is a library that provides multiple-precision
57354e1 added libtommath-0.12
Tom St Denis authored
6 * integer arithmetic as well as number theoretic functionality.
7 *
c1da6aa added libtommath-0.25
Tom St Denis authored
8 * The library was designed directly after the MPI library by
57354e1 added libtommath-0.12
Tom St Denis authored
9 * Michael Fromberger but has been written from scratch with
10 * additional optimizations in place.
11 *
12 * The library is free for all purposes without any express
13 * guarantee it works.
14 *
333aebc added libtommath-0.41
Tom St Denis authored
15 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
57354e1 added libtommath-0.12
Tom St Denis authored
16 */
17
18 /* multiply by a digit */
19 int
20 mp_mul_d (mp_int * a, mp_digit b, mp_int * c)
21 {
c343371 added libtommath-0.27
Tom St Denis authored
22 mp_digit u, *tmpa, *tmpc;
23 mp_word r;
24 int ix, res, olduse;
57354e1 added libtommath-0.12
Tom St Denis authored
25
fd181cc added libtommath-0.17
Tom St Denis authored
26 /* make sure c is big enough to hold a*b */
c343371 added libtommath-0.27
Tom St Denis authored
27 if (c->alloc < a->used + 1) {
28 if ((res = mp_grow (c, a->used + 1)) != MP_OKAY) {
b66471f added libtommath-0.13
Tom St Denis authored
29 return res;
30 }
57354e1 added libtommath-0.12
Tom St Denis authored
31 }
32
fd181cc added libtommath-0.17
Tom St Denis authored
33 /* get the original destinations used count */
b66471f added libtommath-0.13
Tom St Denis authored
34 olduse = c->used;
fd181cc added libtommath-0.17
Tom St Denis authored
35
c343371 added libtommath-0.27
Tom St Denis authored
36 /* set the sign */
49bef06 added libtommath-0.21
Tom St Denis authored
37 c->sign = a->sign;
b66471f added libtommath-0.13
Tom St Denis authored
38
c343371 added libtommath-0.27
Tom St Denis authored
39 /* alias for a->dp [source] */
40 tmpa = a->dp;
b66471f added libtommath-0.13
Tom St Denis authored
41
c343371 added libtommath-0.27
Tom St Denis authored
42 /* alias for c->dp [dest] */
43 tmpc = c->dp;
fd181cc added libtommath-0.17
Tom St Denis authored
44
c343371 added libtommath-0.27
Tom St Denis authored
45 /* zero carry */
46 u = 0;
b66471f added libtommath-0.13
Tom St Denis authored
47
c343371 added libtommath-0.27
Tom St Denis authored
48 /* compute columns */
49 for (ix = 0; ix < a->used; ix++) {
50 /* compute product and carry sum for this term */
51 r = ((mp_word) u) + ((mp_word)*tmpa++) * ((mp_word)b);
fd181cc added libtommath-0.17
Tom St Denis authored
52
c343371 added libtommath-0.27
Tom St Denis authored
53 /* mask off higher bits to get a single digit */
54 *tmpc++ = (mp_digit) (r & ((mp_word) MP_MASK));
fd181cc added libtommath-0.17
Tom St Denis authored
55
c343371 added libtommath-0.27
Tom St Denis authored
56 /* send carry into next iteration */
57 u = (mp_digit) (r >> ((mp_word) DIGIT_BIT));
58 }
fd181cc added libtommath-0.17
Tom St Denis authored
59
3d0fcaa added libtommath-0.34
Tom St Denis authored
60 /* store final carry [if any] and increment ix offset */
c343371 added libtommath-0.27
Tom St Denis authored
61 *tmpc++ = u;
3d0fcaa added libtommath-0.34
Tom St Denis authored
62 ++ix;
c343371 added libtommath-0.27
Tom St Denis authored
63
64 /* now zero digits above the top */
65 while (ix++ < olduse) {
66 *tmpc++ = 0;
57354e1 added libtommath-0.12
Tom St Denis authored
67 }
68
c343371 added libtommath-0.27
Tom St Denis authored
69 /* set used count */
70 c->used = a->used + 1;
71 mp_clamp(c);
72
57354e1 added libtommath-0.12
Tom St Denis authored
73 return MP_OKAY;
74 }
e549ccf added libtommath-0.32
Tom St Denis authored
75 #endif
9294e79 added libtommath-0.36
Tom St Denis authored
76
77 /* $Source$ */
78 /* $Revision$ */
79 /* $Date$ */
Something went wrong with that request. Please try again.