bn_mp_sqr.c

Go to the documentation of this file.
00001 #include <tommath.h>
00002 #ifdef BN_MP_SQR_C
00003 /* LibTomMath, multiple-precision integer library -- Tom St Denis
00004  *
00005  * LibTomMath is a library that provides multiple-precision
00006  * integer arithmetic as well as number theoretic functionality.
00007  *
00008  * The library was designed directly after the MPI library by
00009  * Michael Fromberger but has been written from scratch with
00010  * additional optimizations in place.
00011  *
00012  * The library is free for all purposes without any express
00013  * guarantee it works.
00014  *
00015  * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
00016  */
00017 
00018 /* computes b = a*a */
00019 int
00020 mp_sqr (mp_int * a, mp_int * b)
00021 {
00022   int     res;
00023 
00024 #ifdef BN_MP_TOOM_SQR_C
00025   /* use Toom-Cook? */
00026   if (a->used >= TOOM_SQR_CUTOFF) {
00027     res = mp_toom_sqr(a, b);
00028   /* Karatsuba? */
00029   } else 
00030 #endif
00031 #ifdef BN_MP_KARATSUBA_SQR_C
00032 if (a->used >= KARATSUBA_SQR_CUTOFF) {
00033     res = mp_karatsuba_sqr (a, b);
00034   } else 
00035 #endif
00036   {
00037 #ifdef BN_FAST_S_MP_SQR_C
00038     /* can we use the fast comba multiplier? */
00039     if ((a->used * 2 + 1) < MP_WARRAY && 
00040          a->used < 
00041          (1 << (sizeof(mp_word) * CHAR_BIT - 2*DIGIT_BIT - 1))) {
00042       res = fast_s_mp_sqr (a, b);
00043     } else
00044 #endif
00045 #ifdef BN_S_MP_SQR_C
00046       res = s_mp_sqr (a, b);
00047 #else
00048       res = MP_VAL;
00049 #endif
00050   }
00051   b->sign = MP_ZPOS;
00052   return res;
00053 }
00054 #endif
00055 
00056 /* $Source: /cvsroot/tcl/libtommath/bn_mp_sqr.c,v $ */
00057 /* $Revision: 1.1.1.3 $ */
00058 /* $Date: 2006/12/01 00:08:11 $ */



Generated on Wed Mar 12 12:18:25 2008 by  doxygen 1.5.1