2004-08-25 04:43:43 +02:00
|
|
|
/* TomsFastMath, a fast ISO C bignum library.
|
|
|
|
*
|
|
|
|
* This project is meant to fill in where LibTomMath
|
|
|
|
* falls short. That is speed ;-)
|
|
|
|
*
|
|
|
|
* This project is public domain and free for all purposes.
|
|
|
|
*
|
2005-07-23 12:43:03 +02:00
|
|
|
* Tom St Denis, tomstdenis@gmail.com
|
2004-08-25 04:43:43 +02:00
|
|
|
*/
|
|
|
|
#include <tfm.h>
|
|
|
|
|
|
|
|
/* b = a*a */
|
|
|
|
void fp_sqr(fp_int *A, fp_int *B)
|
|
|
|
{
|
2006-04-06 21:49:03 +02:00
|
|
|
int y;
|
2004-08-25 04:43:43 +02:00
|
|
|
|
2005-10-31 16:32:05 +01:00
|
|
|
/* call generic if we're out of range */
|
|
|
|
if (A->used + A->used > FP_SIZE) {
|
|
|
|
fp_sqr_comba(A, B);
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
2004-08-25 04:43:43 +02:00
|
|
|
y = A->used;
|
2005-07-23 12:43:03 +02:00
|
|
|
#if defined(TFM_SMALL_SET)
|
|
|
|
if (y <= 16) {
|
|
|
|
fp_sqr_comba_small(A,B);
|
2005-11-18 06:16:25 +01:00
|
|
|
return;
|
|
|
|
}
|
2004-09-19 03:31:44 +02:00
|
|
|
#endif
|
2006-04-06 21:49:03 +02:00
|
|
|
#if defined(TFM_SQR20)
|
|
|
|
if (y <= 20) {
|
|
|
|
fp_sqr_comba20(A,B);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if defined(TFM_SQR24)
|
|
|
|
if (y <= 24) {
|
|
|
|
fp_sqr_comba24(A,B);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if defined(TFM_SQR28)
|
|
|
|
if (y <= 28) {
|
|
|
|
fp_sqr_comba28(A,B);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2005-10-31 16:32:05 +01:00
|
|
|
#if defined(TFM_SQR32)
|
2005-11-18 06:16:25 +01:00
|
|
|
if (y <= 32) {
|
2004-08-25 04:43:43 +02:00
|
|
|
fp_sqr_comba32(A,B);
|
2005-11-18 06:16:25 +01:00
|
|
|
return;
|
|
|
|
}
|
2005-10-31 16:32:05 +01:00
|
|
|
#endif
|
|
|
|
#if defined(TFM_SQR48)
|
2005-11-18 06:16:25 +01:00
|
|
|
if (y <= 48) {
|
2005-07-23 12:43:03 +02:00
|
|
|
fp_sqr_comba48(A,B);
|
2005-11-18 06:16:25 +01:00
|
|
|
return;
|
|
|
|
}
|
2005-10-31 16:32:05 +01:00
|
|
|
#endif
|
|
|
|
#if defined(TFM_SQR64)
|
2005-11-18 06:16:25 +01:00
|
|
|
if (y <= 64) {
|
2005-03-02 00:00:09 +01:00
|
|
|
fp_sqr_comba64(A,B);
|
2005-11-18 06:16:25 +01:00
|
|
|
return;
|
2004-08-25 04:43:43 +02:00
|
|
|
}
|
2005-11-18 06:16:25 +01:00
|
|
|
#endif
|
|
|
|
fp_sqr_comba(A, B);
|
2004-08-25 04:43:43 +02:00
|
|
|
}
|
|
|
|
|
2005-07-23 12:43:03 +02:00
|
|
|
|
|
|
|
/* $Source$ */
|
|
|
|
/* $Revision$ */
|
|
|
|
/* $Date$ */
|