Montgomery reduction: Difference between revisions
Content added Content deleted
(→{{header|Tcl}}: added zkl) |
m (→{{header|zkl}}: tweak) |
||
Line 316: | Line 316: | ||
fcn montgomeryReduce(modulus,T){ |
fcn montgomeryReduce(modulus,T){ |
||
_assert_(modulus.isOdd); |
_assert_(modulus.isOdd); |
||
bits:=modulus.len(2); |
|||
a:=BN(T); // we'll do in place math |
a:=BN(T); // we'll do in place math |
||
do(modulus.len(2)){ // bits needed to hold modulus |
|||
foreach i in (bits){ |
|||
if(a.isOdd) a.add(modulus); |
if(a.isOdd) a.add(modulus); |
||
a.div(2); // a>>=1 |
a.div(2); // a>>=1 |