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 s_fp_add.c Source File

s_fp_add.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 /* unsigned addition */
00013 void s_fp_add(fp_int *a, fp_int *b, fp_int *c)
00014 {
00015   int      x, y, oldused;
00016   register fp_word  t;
00017 
00018   y       = MAX(a->used, b->used);
00019   oldused = c->used;
00020   c->used = y;
00021  
00022   t = 0;
00023   for (x = 0; x < y; x++) {
00024       t         += ((fp_word)a->dp[x]) + ((fp_word)b->dp[x]);
00025       c->dp[x]   = (fp_digit)t;
00026       t        >>= DIGIT_BIT;
00027   }
00028   if (t != 0 && x < FP_SIZE) {
00029      c->dp[c->used++] = (fp_digit)t;
00030      ++x;
00031   }
00032 
00033   c->used = x;
00034   for (; x < oldused; x++) {
00035      c->dp[x] = 0;
00036   }
00037   fp_clamp(c);
00038 }
00039 
00040 /* $Source: /cvs/libtom/tomsfastmath/src/addsub/s_fp_add.c,v $ */
00041 /* $Revision: 1.1 $ */
00042 /* $Date: 2006/12/31 21:25:53 $ */