# BRCM_VERSION=3
[bcm963xx.git] / userapps / opensource / sshd / libtommath / bn_mp_reduce_setup.c
1 /* LibTomMath, multiple-precision integer library -- Tom St Denis\r
2  *\r
3  * LibTomMath is library that provides for multiple-precision\r
4  * integer arithmetic as well as number theoretic functionality.\r
5  *\r
6  * The library is designed directly after the MPI library by\r
7  * Michael Fromberger but has been written from scratch with\r
8  * additional optimizations in place.\r
9  *\r
10  * The library is free for all purposes without any express\r
11  * guarantee it works.\r
12  *\r
13  * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org\r
14  */\r
15 #include <tommath.h>\r
16 \r
17 /* pre-calculate the value required for Barrett reduction\r
18  * For a given modulus "b" it calulates the value required in "a"\r
19  */\r
20 int\r
21 mp_reduce_setup (mp_int * a, mp_int * b)\r
22 {\r
23   int     res;\r
24   \r
25   if ((res = mp_2expt (a, b->used * 2 * DIGIT_BIT)) != MP_OKAY) {\r
26     return res;\r
27   }\r
28   return mp_div (a, b, a, NULL);\r
29 }\r