Skip to content

Commit

Permalink
Fix for CVE-2015-2141. Thanks to Evgeny Sidorov for reporting. Squari…
Browse files Browse the repository at this point in the history
…ng to satisfy Jacobi requirements suggested by JPM.
  • Loading branch information
noloader committed Jun 27, 2015
1 parent cf08f3e commit 9425e16
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion rw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,16 @@ Integer InvertibleRWFunction::CalculateInverse(RandomNumberGenerator &rng, const
DoQuickSanityCheck();
ModularArithmetic modn(m_n);
Integer r, rInv;
do { // do this in a loop for people using small numbers for testing

// do this in a loop for people using small numbers for testing
do {
r.Randomize(rng, Integer::One(), m_n - Integer::One());
// Fix for CVE-2015-2141. Thanks to Evgeny Sidorov for reporting.
// Squaring to satisfy Jacobi requirements suggested by JPM.
r = modn.Square(r);
rInv = modn.MultiplicativeInverse(r);
} while (rInv.IsZero());

Integer re = modn.Square(r);
re = modn.Multiply(re, x); // blind

Expand Down

0 comments on commit 9425e16

Please sign in to comment.