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(m:BigInteger)
{
super();
this.r2 = new BigInteger();
this.q3 = new BigInteger();
BigInteger.ONE.dlShiftTo(2 * m.t,this.r2);
this.mu = this.r2.divide(m);
this.m = m;
}
public function revert(x:BigInteger) : BigInteger
{
return x;
}
public function mulTo(x:BigInteger, y:BigInteger, r:BigInteger) : void
{
x.multiplyTo(y,r);
this.reduce(r);
}
public function sqrTo(x:BigInteger, r:BigInteger) : void
{
x.squareTo(r);
this.reduce(r);
}
public function convert(x:BigInteger) : BigInteger
{
var r:BigInteger = null;
if(x.s < 0 || x.t > 2 * this.m.t)
{
return x.mod(this.m);
}
if(x.compareTo(this.m) < 0)
{
return x;
}
r = new BigInteger();
x.copyTo(r);
this.reduce(r);
return r;
}
public function reduce(lx:BigInteger) : void
{
var x:BigInteger = lx as BigInteger;
x.drShiftTo(this.m.t - 1,this.r2);
if(x.t > this.m.t + 1)
{
x.t = this.m.t + 1;
x.clamp();
}
this.mu.multiplyUpperTo(this.r2,this.m.t + 1,this.q3);
this.m.multiplyLowerTo(this.q3,this.m.t + 1,this.r2);
while(x.compareTo(this.r2) < 0)
{
x.dAddOffset(1,this.m.t + 1);
}
x.subTo(this.r2,x);
while(x.compareTo(this.m) >= 0)
{
x.subTo(this.m,x);
}
}
}
}
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(m:BigInteger)
{
super();
this.m = m;
}
public function convert(x:BigInteger) : BigInteger
{
if(x.s < 0 || x.compareTo(this.m) >= 0)
{
return x.mod(this.m);
}
return x;
}
public function revert(x:BigInteger) : BigInteger
{
return x;
}
public function reduce(x:BigInteger) : void
{
x.divRemTo(this.m,null,x);
}
public function mulTo(x:BigInteger, y:BigInteger, r:BigInteger) : void
{
x.multiplyTo(y,r);
this.reduce(r);
}
public function sqrTo(x:BigInteger, r:BigInteger) : void
{
x.squareTo(r);
this.reduce(r);
}
}
}
@@ -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,92 @@
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(m:BigInteger)
{
super();
this.m = m;
this.mp = m.invDigit();
this.mpl = this.mp & 0x7FFF;
this.mph = this.mp >> 15;
this.um = (1 << BigInteger.DB - 15) - 1;
this.mt2 = 2 * m.t;
}
public function convert(x:BigInteger) : BigInteger
{
var r:BigInteger = new BigInteger();
x.abs().dlShiftTo(this.m.t,r);
r.divRemTo(this.m,null,r);
if(x.s < 0 && r.compareTo(BigInteger.ZERO) > 0)
{
this.m.subTo(r,r);
}
return r;
}
public function revert(x:BigInteger) : BigInteger
{
var r:BigInteger = new BigInteger();
x.copyTo(r);
this.reduce(r);
return r;
}
public function reduce(x:BigInteger) : void
{
var j:int = 0;
var u0:int = 0;
while(x.t <= this.mt2)
{
x.a[x.t++] = 0;
}
for(var i:int = 0; i < this.m.t; i++)
{
j = x.a[i] & 0x7FFF;
u0 = j * this.mpl + ((j * this.mph + (x.a[i] >> 15) * this.mpl & this.um) << 15) & BigInteger.DM;
j = i + this.m.t;
x.a[j] += this.m.am(0,u0,x,i,0,this.m.t);
while(x.a[j] >= BigInteger.DV)
{
x.a[j] -= BigInteger.DV;
++x.a[++j];
}
}
x.clamp();
x.drShiftTo(this.m.t,x);
if(x.compareTo(this.m) >= 0)
{
x.subTo(this.m,x);
}
}
public function sqrTo(x:BigInteger, r:BigInteger) : void
{
x.squareTo(r);
this.reduce(r);
}
public function mulTo(x:BigInteger, y:BigInteger, r:BigInteger) : void
{
x.multiplyTo(y,r);
this.reduce(r);
}
}
}
@@ -0,0 +1,38 @@
package com.hurlant.math
{
use namespace bi_internal;
public class NullReduction implements IReduction
{
public function NullReduction()
{
super();
}
public function revert(x:BigInteger) : BigInteger
{
return x;
}
public function mulTo(x:BigInteger, y:BigInteger, r:BigInteger) : void
{
x.multiplyTo(y,r);
}
public function sqrTo(x:BigInteger, r:BigInteger) : void
{
x.squareTo(r);
}
public function convert(x:BigInteger) : BigInteger
{
return x;
}
public function reduce(x:BigInteger) : void
{
}
}
}
@@ -0,0 +1,5 @@
package com.hurlant.math
{
public namespace bi_internal = "http://crypto.hurlant.com/BigInteger";
}