1/*	$NetBSD$	*/
2
3#include <tommath.h>
4#ifdef BN_MP_SQR_C
5/* LibTomMath, multiple-precision integer library -- Tom St Denis
6 *
7 * LibTomMath is a library that provides multiple-precision
8 * integer arithmetic as well as number theoretic functionality.
9 *
10 * The library was designed directly after the MPI library by
11 * Michael Fromberger but has been written from scratch with
12 * additional optimizations in place.
13 *
14 * The library is free for all purposes without any express
15 * guarantee it works.
16 *
17 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
18 */
19
20/* computes b = a*a */
21int
22mp_sqr (mp_int * a, mp_int * b)
23{
24  int     res;
25
26#ifdef BN_MP_TOOM_SQR_C
27  /* use Toom-Cook? */
28  if (a->used >= TOOM_SQR_CUTOFF) {
29    res = mp_toom_sqr(a, b);
30  /* Karatsuba? */
31  } else
32#endif
33#ifdef BN_MP_KARATSUBA_SQR_C
34if (a->used >= KARATSUBA_SQR_CUTOFF) {
35    res = mp_karatsuba_sqr (a, b);
36  } else
37#endif
38  {
39#ifdef BN_FAST_S_MP_SQR_C
40    /* can we use the fast comba multiplier? */
41    if ((a->used * 2 + 1) < MP_WARRAY &&
42         a->used <
43         (1 << (sizeof(mp_word) * CHAR_BIT - 2*DIGIT_BIT - 1))) {
44      res = fast_s_mp_sqr (a, b);
45    } else
46#endif
47#ifdef BN_S_MP_SQR_C
48      res = s_mp_sqr (a, b);
49#else
50      res = MP_VAL;
51#endif
52  }
53  b->sign = MP_ZPOS;
54  return res;
55}
56#endif
57
58/* Source: /cvs/libtom/libtommath/bn_mp_sqr.c,v */
59/* Revision: 1.4 */
60/* Date: 2006/12/28 01:25:13 */
61