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

fp_mod_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 mod 2**d */
00013 void fp_mod_2d(fp_int *a, int b, fp_int *c)
00014 {
00015    int x;
00016 
00017    /* zero if count less than or equal to zero */
00018    if (b <= 0) {
00019       fp_zero(c);
00020       return;
00021    }
00022 
00023    /* get copy of input */
00024    fp_copy(a, c);
00025  
00026    /* if 2**d is larger than we just return */
00027    if (b >= (DIGIT_BIT * a->used)) {
00028       return;
00029    }
00030 
00031   /* zero digits above the last digit of the modulus */
00032   for (x = (b / DIGIT_BIT) + ((b % DIGIT_BIT) == 0 ? 0 : 1); x < c->used; x++) {
00033     c->dp[x] = 0;
00034   }
00035   /* clear the digit that is not completely outside/inside the modulus */
00036   c->dp[b / DIGIT_BIT] &= ~((fp_digit)0) >> (DIGIT_BIT - b);
00037   fp_clamp (c);
00038 }
00039 
00040 /* $Source: /cvs/libtom/tomsfastmath/src/bit/fp_mod_2d.c,v $ */
00041 /* $Revision: 1.1 $ */
00042 /* $Date: 2006/12/31 21:25:53 $ */