Skip to content

Commit b339cda

Browse files
committed
---
yaml --- r: 311698 b: refs/heads/main c: e62dd01 h: refs/heads/main
1 parent 9f4fec9 commit b339cda

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1994,4 +1994,4 @@ refs/tags/2.14.0-96.0.dev: 1eee24e50fc3028754d9a8e98852b949c04da4e4
19941994
refs/tags/2.14.0-97.0.dev: ba9c1636e87fbdcc02b8bc4a584455c32f8378b4
19951995
refs/tags/2.14.0-98.0.dev: f2d370c93582bbf4da42b5dd4c906d6145b01ea9
19961996
refs/tags/2.14.0-99.0.dev: e722f62b48fb382534efc1f20735def68848006f
1997-
refs/heads/main: 8515d74332968cd0aa27d175fbdcd77120a36b90
1997+
refs/heads/main: e62dd0157e2b0725cb464c34b4622a02aaa954fd

trunk/runtime/lib/bigint_patch.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,7 +2628,8 @@ class _BigIntMontgomeryReduction implements _BigIntReduction {
26282628
}
26292629

26302630
_BigIntImpl _revert(Uint32List xDigits, int xUsed) {
2631-
var resultDigits = _newDigits(2 * _normModulusUsed);
2631+
// Reserve enough digits for modulus squaring and accumulator carry.
2632+
var resultDigits = _newDigits(2 * _normModulusUsed + 2);
26322633
var i = xUsed + (xUsed & 1);
26332634
while (--i >= 0) {
26342635
resultDigits[i] = xDigits[i];
@@ -2640,8 +2641,8 @@ class _BigIntMontgomeryReduction implements _BigIntReduction {
26402641
// x = x/R mod _modulus.
26412642
// Returns xUsed.
26422643
int _reduce(Uint32List xDigits, int xUsed) {
2643-
while (xUsed < 2 * _normModulusUsed) {
2644-
// Pad x so _mulAdd has enough room later.
2644+
while (xUsed < 2 * _normModulusUsed + 2) {
2645+
// Pad x so _mulAdd has enough room later for a possible carry.
26452646
xDigits[xUsed++] = 0;
26462647
}
26472648
var i = 0;

trunk/tests/corelib_2/bigint_test.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,29 @@ testBigintModPow() {
484484
e = BigInt.parse("123456789012345678901234567890");
485485
m = BigInt.parse("123456789012345678901234567899");
486486
Expect.equals(BigInt.parse("40128068573873018143207285483"), x.modPow(e, m));
487+
x = BigInt.parse(
488+
"142223781135477974841804437037182877109549636480215350570761436386728140"
489+
"00321219503871352719175100865184619168128345594681547640115731246638");
490+
e = BigInt.parse(
491+
"688057170495263083245752731085731160016625265771524738691797062279575950"
492+
"919479651156310413084174304361991240273181430924411258203766946639349880"
493+
"404106504114953688890200429043051936362182997575167191584461538746041795"
494+
"019663740246921124383173799957296515067912829778249931473903780958741032"
495+
"64534184571632120755");
496+
m = BigInt.parse(
497+
"144173682842817587002196172066264549138375068078359231382946906898412792"
498+
"452632726597279520229873489736777248181678202636100459215718497240474064"
499+
"366927544074501134727745837254834206456400508719134610847814227274992298"
500+
"238973375146473350157304285346424982280927848339601514720098577525635486"
501+
"320547905945936448443");
502+
Expect.equals(
503+
BigInt.parse(
504+
"41228476947144730491819644448449646627743926889389391986712371102685"
505+
"14984467753960109321610008533258676279344318597060690521027646613453"
506+
"25674994677820913027869835916005689276806408148698486814119894325284"
507+
"18918299321385420296108046942018595594076729397423805685944237555128"
508+
"652606412065971965116137839721723231"),
509+
x.modPow(e, m));
487510
}
488511

489512
testBigintModInverse() {

0 commit comments

Comments
 (0)