Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of MiniTLS-GPL by
fp_mul_2.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 void fp_mul_2(fp_int * a, fp_int * b) 00013 { 00014 int x, oldused; 00015 00016 oldused = b->used; 00017 b->used = a->used; 00018 00019 { 00020 register fp_digit r, rr, *tmpa, *tmpb; 00021 00022 /* alias for source */ 00023 tmpa = a->dp; 00024 00025 /* alias for dest */ 00026 tmpb = b->dp; 00027 00028 /* carry */ 00029 r = 0; 00030 for (x = 0; x < a->used; x++) { 00031 00032 /* get what will be the *next* carry bit from the 00033 * MSB of the current digit 00034 */ 00035 rr = *tmpa >> ((fp_digit)(DIGIT_BIT - 1)); 00036 00037 /* now shift up this digit, add in the carry [from the previous] */ 00038 *tmpb++ = ((*tmpa++ << ((fp_digit)1)) | r); 00039 00040 /* copy the carry that would be from the source 00041 * digit into the next iteration 00042 */ 00043 r = rr; 00044 } 00045 00046 /* new leading digit? */ 00047 if (r != 0 && b->used != (FP_SIZE-1)) { 00048 /* add a MSB which is always 1 at this point */ 00049 *tmpb = 1; 00050 ++(b->used); 00051 } 00052 00053 /* now zero any excess digits on the destination 00054 * that we didn't write to 00055 */ 00056 tmpb = b->dp + b->used; 00057 for (x = b->used; x < oldused; x++) { 00058 *tmpb++ = 0; 00059 } 00060 } 00061 b->sign = a->sign; 00062 } 00063 00064 00065 /* $Source: /cvs/libtom/tomsfastmath/src/mul/fp_mul_2.c,v $ */ 00066 /* $Revision: 1.1 $ */ 00067 /* $Date: 2006/12/31 21:25:53 $ */
Generated on Tue Jul 12 2022 19:20:10 by
1.7.2
