summaryrefslogtreecommitdiffstats
path: root/libtommath/bn_mp_reduce_setup.c
blob: 70e193af05d8311804e729de36b5c2de8b556567 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <tommath_private.h>
#ifdef BN_MP_REDUCE_SETUP_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis
 *
 * LibTomMath is a library that provides multiple-precision
 * integer arithmetic as well as number theoretic functionality.
 *
 * The library was designed directly after the MPI library by
 * Michael Fromberger but has been written from scratch with
 * additional optimizations in place.
 *
 * The library is free for all purposes without any express
 * guarantee it works.
 *
 * Tom St Denis, tstdenis82@gmail.com, http://libtom.org
 */

/* pre-calculate the value required for Barrett reduction
 * For a given modulus "b" it calulates the value required in "a"
 */
int mp_reduce_setup(mp_int *a, const mp_int *b)
{
   int     res;

   if ((res = mp_2expt(a, b->used * 2 * DIGIT_BIT)) != MP_OKAY) {
      return res;
   }
   return mp_div(a, b, a, NULL);
}
#endif

/* ref:         $Format:%D$ */
/* git commit:  $Format:%H$ */
/* commit time: $Format:%ai$ */
span class="hl kwa">proc normal {x y} {return [expr $x+$y]} proc indented {x y} {return [expr $x+$y]} # # Should be able to handle proc declarations within namespaces, # even if they have explicit namespace paths. # namespace eval buried { proc inside {args} {return "inside: $args"} namespace export pub_* proc pub_one {args} {return "one: $args"} proc pub_two {args} {return "two: $args"} } proc buried::within {args} {return "within: $args"} namespace eval buried { namespace eval under { proc neath {args} {return "neath: $args"} } namespace eval ::buried { proc relative {args} {return "relative: $args"} proc ::top {args} {return "top: $args"} proc ::buried::explicit {args} {return "explicit: $args"} } } # With proper hooks, we should be able to support other commands # that create procedures proc buried::myproc {name body args} { ::proc $name $body $args } namespace eval ::buried { proc mycmd1 args {return "mycmd"} myproc mycmd2 args {return "mycmd"} } ::buried::myproc mycmd3 args {return "another"} proc {buried::my proc} {name body args} { ::proc $name $body $args } namespace eval ::buried { proc mycmd4 args {return "mycmd"} {my proc} mycmd5 args {return "mycmd"} } {::buried::my proc} mycmd6 args {return "another"} # A correctly functioning [auto_import] won't choke when a child # namespace [namespace import]s from its parent. # namespace eval ::parent::child { namespace import ::parent::* } proc ::parent::child::test {} {}