Brought up to date with the private repository (feea4c7)

This commit is contained in:
S committed 2026-10-14 20:57:33 +03:00
1 parent 1aa738d692
commit 1b1df1ae48
7925 files changed
+2617237 -20

No files matched your search

@@ -0,0 +1,83 @@
package com.hurlant.math
{
use namespace bi_internal;
internal class BarrettReduction implements IReduction
{
private var m:BigInteger;
private var r2:BigInteger;
private var q3:BigInteger;
private var mu:BigInteger;
public function BarrettReduction(param1:BigInteger)
{
super();
r2 = new BigInteger();
q3 = new BigInteger();
BigInteger.ONE.dlShiftTo(2 * param1.t,r2);
mu = r2.divide(param1);
this.m = param1;
}
public function revert(param1:BigInteger) : BigInteger
{
return param1;
}
public function mulTo(param1:BigInteger, param2:BigInteger, param3:BigInteger) : void
{
param1.multiplyTo(param2,param3);
reduce(param3);
}
public function sqrTo(param1:BigInteger, param2:BigInteger) : void
{
param1.squareTo(param2);
reduce(param2);
}
public function convert(param1:BigInteger) : BigInteger
{
var _loc2_:BigInteger = null;
if(param1.s < 0 || param1.t > 2 * m.t)
{
return param1.mod(m);
}
if(param1.compareTo(m) < 0)
{
return param1;
}
_loc2_ = new BigInteger();
param1.copyTo(_loc2_);
reduce(_loc2_);
return _loc2_;
}
public function reduce(param1:BigInteger) : void
{
var _loc2_:BigInteger = param1 as BigInteger;
_loc2_.drShiftTo(m.t - 1,r2);
if(_loc2_.t > m.t + 1)
{
_loc2_.t = m.t + 1;
_loc2_.clamp();
}
mu.multiplyUpperTo(r2,m.t + 1,q3);
m.multiplyLowerTo(q3,m.t + 1,r2);
while(_loc2_.compareTo(r2) < 0)
{
_loc2_.dAddOffset(1,m.t + 1);
}
_loc2_.subTo(r2,_loc2_);
while(_loc2_.compareTo(m) >= 0)
{
_loc2_.subTo(m,_loc2_);
}
}
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,48 @@
package com.hurlant.math
{
use namespace bi_internal;
internal class ClassicReduction implements IReduction
{
private var m:BigInteger;
public function ClassicReduction(param1:BigInteger)
{
super();
this.m = param1;
}
public function convert(param1:BigInteger) : BigInteger
{
if(param1.s < 0 || param1.compareTo(m) >= 0)
{
return param1.mod(m);
}
return param1;
}
public function revert(param1:BigInteger) : BigInteger
{
return param1;
}
public function reduce(param1:BigInteger) : void
{
param1.divRemTo(m,null,param1);
}
public function mulTo(param1:BigInteger, param2:BigInteger, param3:BigInteger) : void
{
param1.multiplyTo(param2,param3);
reduce(param3);
}
public function sqrTo(param1:BigInteger, param2:BigInteger) : void
{
param1.squareTo(param2);
reduce(param2);
}
}
}
@@ -0,0 +1,17 @@
package com.hurlant.math
{
internal interface IReduction
{
function convert(param1:BigInteger) : BigInteger;
function revert(param1:BigInteger) : BigInteger;
function reduce(param1:BigInteger) : void;
function mulTo(param1:BigInteger, param2:BigInteger, param3:BigInteger) : void;
function sqrTo(param1:BigInteger, param2:BigInteger) : void;
}
}
@@ -0,0 +1,97 @@
package com.hurlant.math
{
use namespace bi_internal;
internal class MontgomeryReduction implements IReduction
{
private var m:BigInteger;
private var mp:int;
private var mpl:int;
private var mph:int;
private var um:int;
private var mt2:int;
public function MontgomeryReduction(param1:BigInteger)
{
super();
this.m = param1;
mp = param1.invDigit();
mpl = mp & 0x7FFF;
mph = mp >> 15;
um = 32767;
mt2 = 2 * param1.t;
}
public function convert(param1:BigInteger) : BigInteger
{
var _loc2_:BigInteger = new BigInteger();
param1.abs().dlShiftTo(m.t,_loc2_);
_loc2_.divRemTo(m,null,_loc2_);
if(param1.s < 0 && _loc2_.compareTo(BigInteger.ZERO) > 0)
{
m.subTo(_loc2_,_loc2_);
}
return _loc2_;
}
public function revert(param1:BigInteger) : BigInteger
{
var _loc2_:BigInteger = new BigInteger();
param1.copyTo(_loc2_);
reduce(_loc2_);
return _loc2_;
}
public function reduce(param1:BigInteger) : void
{
var _loc2_:int = 0;
var _loc3_:int = 0;
var _loc4_:int = 0;
while(param1.t <= mt2)
{
param1.a[param1.t++] = 0;
}
_loc2_ = 0;
while(_loc2_ < m.t)
{
_loc3_ = param1.a[_loc2_] & 0x7FFF;
_loc4_ = _loc3_ * mpl + ((_loc3_ * mph + (param1.a[_loc2_] >> 15) * mpl & um) << 15) & 0x3FFFFFFF;
_loc3_ = _loc2_ + m.t;
param1.a[_loc3_] += m.am(0,_loc4_,param1,_loc2_,0,m.t);
while(param1.a[_loc3_] >= 1073741824)
{
var _loc6_:int = _loc3_;
var _loc5_:Number = param1.a[_loc6_] - 1073741824;
param1.a[_loc6_] = _loc5_;
param1.a[++_loc3_]++;
}
_loc2_++;
}
param1.clamp();
param1.drShiftTo(m.t,param1);
if(param1.compareTo(m) >= 0)
{
param1.subTo(m,param1);
}
}
public function sqrTo(param1:BigInteger, param2:BigInteger) : void
{
param1.squareTo(param2);
reduce(param2);
}
public function mulTo(param1:BigInteger, param2:BigInteger, param3:BigInteger) : void
{
param1.multiplyTo(param2,param3);
reduce(param3);
}
}
}
@@ -0,0 +1,38 @@
package com.hurlant.math
{
use namespace bi_internal;
public class NullReduction implements IReduction
{
public function NullReduction()
{
super();
}
public function revert(param1:BigInteger) : BigInteger
{
return param1;
}
public function mulTo(param1:BigInteger, param2:BigInteger, param3:BigInteger) : void
{
param1.multiplyTo(param2,param3);
}
public function sqrTo(param1:BigInteger, param2:BigInteger) : void
{
param1.squareTo(param2);
}
public function convert(param1:BigInteger) : BigInteger
{
return param1;
}
public function reduce(param1:BigInteger) : void
{
}
}
}
@@ -0,0 +1,5 @@
package com.hurlant.math
{
public namespace bi_internal = "http://crypto.hurlant.com/BigInteger";
}