Mercurial > dropbear
comparison tomsfastmath/src/mul/fp_mul_2d.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 /* c = a * 2**d */ | |
13 void fp_mul_2d(fp_int *a, int b, fp_int *c) | |
14 { | |
15 fp_digit carry, carrytmp, shift; | |
16 int x; | |
17 | |
18 /* copy it */ | |
19 fp_copy(a, c); | |
20 | |
21 /* handle whole digits */ | |
22 if (b >= DIGIT_BIT) { | |
23 fp_lshd(c, b/DIGIT_BIT); | |
24 } | |
25 b %= DIGIT_BIT; | |
26 | |
27 /* shift the digits */ | |
28 if (b != 0) { | |
29 carry = 0; | |
30 shift = DIGIT_BIT - b; | |
31 for (x = 0; x < c->used; x++) { | |
32 carrytmp = c->dp[x] >> shift; | |
33 c->dp[x] = (c->dp[x] << b) + carry; | |
34 carry = carrytmp; | |
35 } | |
36 /* store last carry if room */ | |
37 if (carry && x < FP_SIZE) { | |
38 c->dp[c->used++] = carry; | |
39 } | |
40 } | |
41 fp_clamp(c); | |
42 } | |
43 | |
44 | |
45 /* $Source$ */ | |
46 /* $Revision$ */ | |
47 /* $Date$ */ |