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.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 * b */ 00013 void fp_mul(fp_int *A, fp_int *B, fp_int *C) 00014 { 00015 int y, yy; 00016 00017 /* call generic if we're out of range */ 00018 if (A->used + B->used > FP_SIZE) { 00019 fp_mul_comba(A, B, C); 00020 return ; 00021 } 00022 00023 y = MAX(A->used, B->used); 00024 yy = MIN(A->used, B->used); 00025 /* pick a comba (unrolled 4/8/16/32 x or rolled) based on the size 00026 of the largest input. We also want to avoid doing excess mults if the 00027 inputs are not close to the next power of two. That is, for example, 00028 if say y=17 then we would do (32-17)^2 = 225 unneeded multiplications 00029 */ 00030 00031 #ifdef TFM_MUL3 00032 if (y <= 3) { 00033 fp_mul_comba3(A,B,C); 00034 return; 00035 } 00036 #endif 00037 #ifdef TFM_MUL4 00038 if (y == 4) { 00039 fp_mul_comba4(A,B,C); 00040 return; 00041 } 00042 #endif 00043 #ifdef TFM_MUL6 00044 if (y <= 6) { 00045 fp_mul_comba6(A,B,C); 00046 return; 00047 } 00048 #endif 00049 #ifdef TFM_MUL7 00050 if (y == 7) { 00051 fp_mul_comba7(A,B,C); 00052 return; 00053 } 00054 #endif 00055 #ifdef TFM_MUL8 00056 if (y == 8) { 00057 fp_mul_comba8(A,B,C); 00058 return; 00059 } 00060 #endif 00061 #ifdef TFM_MUL9 00062 if (y == 9) { 00063 fp_mul_comba9(A,B,C); 00064 return; 00065 } 00066 #endif 00067 #ifdef TFM_MUL12 00068 if (y <= 12) { 00069 fp_mul_comba12(A,B,C); 00070 return; 00071 } 00072 #endif 00073 #ifdef TFM_MUL17 00074 if (y <= 17) { 00075 fp_mul_comba17(A,B,C); 00076 return; 00077 } 00078 #endif 00079 00080 #ifdef TFM_SMALL_SET 00081 if (y <= 16) { 00082 fp_mul_comba_small(A,B,C); 00083 return; 00084 } 00085 #endif 00086 #if defined(TFM_MUL20) 00087 if (y <= 20) { 00088 fp_mul_comba20(A,B,C); 00089 return; 00090 } 00091 #endif 00092 #if defined(TFM_MUL24) 00093 if (yy >= 16 && y <= 24) { 00094 fp_mul_comba24(A,B,C); 00095 return; 00096 } 00097 #endif 00098 #if defined(TFM_MUL28) 00099 if (yy >= 20 && y <= 28) { 00100 fp_mul_comba28(A,B,C); 00101 return; 00102 } 00103 #endif 00104 #if defined(TFM_MUL32) 00105 if (yy >= 24 && y <= 32) { 00106 fp_mul_comba32(A,B,C); 00107 return; 00108 } 00109 #endif 00110 #if defined(TFM_MUL48) 00111 if (yy >= 40 && y <= 48) { 00112 fp_mul_comba48(A,B,C); 00113 return; 00114 } 00115 #endif 00116 #if defined(TFM_MUL64) 00117 if (yy >= 56 && y <= 64) { 00118 fp_mul_comba64(A,B,C); 00119 return; 00120 } 00121 #endif 00122 fp_mul_comba(A,B,C); 00123 } 00124 00125 00126 /* $Source: /cvs/libtom/tomsfastmath/src/mul/fp_mul.c,v $ */ 00127 /* $Revision: 1.1 $ */ 00128 /* $Date: 2006/12/31 21:25:53 $ */
Generated on Tue Jul 12 2022 19:20:10 by
1.7.2
