ARM Shanghai IoT Team (Internal) / newMiniTLS-GPL

Fork of MiniTLS-GPL by Donatien Garnier

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers fp_mul_2d.c Source File

fp_mul_2d.c

00001 /* TomsFastMath, a fast ISO C bignum library.
00002  * 
00003  * This project is meant to fill in where LibTomMath
00004  * falls short.  That is speed ;-)
00005  *
00006  * This project is public domain and free for all purposes.
00007  * 
00008  * Tom St Denis, tomstdenis@gmail.com
00009  */
00010 #include <tfm.h>
00011 
00012 /* c = a * 2**d */
00013 void fp_mul_2d(fp_int *a, int b, fp_int *c)
00014 {
00015    fp_digit carry, carrytmp, shift;
00016    int x;
00017 
00018    /* copy it */
00019    fp_copy(a, c);
00020 
00021    /* handle whole digits */
00022    if (b >= DIGIT_BIT) {
00023       fp_lshd(c, b/DIGIT_BIT);
00024    }
00025    b %= DIGIT_BIT;
00026 
00027    /* shift the digits */
00028    if (b != 0) {
00029       carry = 0;   
00030       shift = DIGIT_BIT - b;
00031       for (x = 0; x < c->used; x++) {
00032           carrytmp = c->dp[x] >> shift;
00033           c->dp[x] = (c->dp[x] << b) + carry;
00034           carry = carrytmp;
00035       }
00036       /* store last carry if room */
00037       if (carry && x < FP_SIZE) {
00038          c->dp[c->used++] = carry;
00039       }
00040    }
00041    fp_clamp(c);
00042 }
00043 
00044 
00045 /* $Source: /cvs/libtom/tomsfastmath/src/mul/fp_mul_2d.c,v $ */
00046 /* $Revision: 1.1 $ */
00047 /* $Date: 2006/12/31 21:25:53 $ */