comparison tomsfastmath/src/mul/fp_mul_2.c @ 643:a362b62d38b2 dropbear-tfm

Add tomsfastmath from git rev bfa4582842bc3bab42e4be4aed5703437049502a with Makefile.in renamed
author Matt Johnston <matt@ucc.asn.au>
date Wed, 23 Nov 2011 18:10:20 +0700
parents
children
comparison
equal deleted inserted replaced
642:33fd2f3499d2 643:a362b62d38b2
1 /* TomsFastMath, a fast ISO C bignum library.
2 *
3 * This project is meant to fill in where LibTomMath
4 * falls short. That is speed ;-)
5 *
6 * This project is public domain and free for all purposes.
7 *
8 * Tom St Denis, [email protected]
9 */
10 #include <tfm.h>
11
12 void fp_mul_2(fp_int * a, fp_int * b)
13 {
14 int x, oldused;
15
16 oldused = b->used;
17 b->used = a->used;
18
19 {
20 register fp_digit r, rr, *tmpa, *tmpb;
21
22 /* alias for source */
23 tmpa = a->dp;
24
25 /* alias for dest */
26 tmpb = b->dp;
27
28 /* carry */
29 r = 0;
30 for (x = 0; x < a->used; x++) {
31
32 /* get what will be the *next* carry bit from the
33 * MSB of the current digit
34 */
35 rr = *tmpa >> ((fp_digit)(DIGIT_BIT - 1));
36
37 /* now shift up this digit, add in the carry [from the previous] */
38 *tmpb++ = ((*tmpa++ << ((fp_digit)1)) | r);
39
40 /* copy the carry that would be from the source
41 * digit into the next iteration
42 */
43 r = rr;
44 }
45
46 /* new leading digit? */
47 if (r != 0 && b->used != (FP_SIZE-1)) {
48 /* add a MSB which is always 1 at this point */
49 *tmpb = 1;
50 ++(b->used);
51 }
52
53 /* now zero any excess digits on the destination
54 * that we didn't write to
55 */
56 tmpb = b->dp + b->used;
57 for (x = b->used; x < oldused; x++) {
58 *tmpb++ = 0;
59 }
60 }
61 b->sign = a->sign;
62 }
63
64
65 /* $Source$ */
66 /* $Revision$ */
67 /* $Date$ */