Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Incorrect results from BigInteger::exponentModulo ==> RSAKey::applyToValue #1431

Closed
1 task done
ianacaburian opened this issue Sep 29, 2024 · 1 comment
Closed
1 task done

Comments

@ianacaburian
Copy link

Detailed steps on how to reproduce the bug

auto base = juce::BigInteger{3};
auto exponent = juce::BigInteger{8};
auto modulus = juce::BigInteger{5};
base.exponentModulo(exponent, modulus);
// Result is 2, should be 1

auto base = juce::BigInteger{static_castjuce::int64(85899345927)};
auto exponent = juce::BigInteger{static_castjuce::int64(85899345926)};
auto modulus = juce::BigInteger{static_castjuce::int64(85899345925)};
base.exponentModulo(exponent, modulus);
// Result is 2, should be 67108864 (0x4000000)

What is the expected behaviour?

  • exponentModulo should be (this * exp) % modulus for cases:
    • getHighestBit() <= 0
    • getHighestBit() > 0 && modulus % 2 != 0

Operating systems

macOS

What versions of the operating systems?

macOS 14.6.1

Architectures

x86_64

Stacktrace

No response

Plug-in formats (if applicable)

No response

Plug-in host applications (DAWs) (if applicable)

No response

Testing on the develop branch

I have not tested against the develop branch

Code of Conduct

  • I agree to follow the Code of Conduct
ianacaburian added a commit to ianacaburian/JUCE that referenced this issue Sep 30, 2024
Changes:
- Removed incorrect mod op on exponent.
- Handled base case for zero exponent.

Tests:
- Tested against modPow by [jsbn](https://github.com/creationix/jsbn)
- Tested 100 runs of random hex strings with lengths 300 - 1000 using [fast-check](https://github.com/dubzzz/fast-check):
 ✓ src/JuceBigInteger.test.ts (1) 1776566ms
   ✓ JuceBigInteger (1) 1776565ms
     ✓ exponentModulo (1) 1776565ms
- Double-checked counter examples on [Omni Calculator](https://www.omnicalculator.com/math/power-modulo):
	- b=x, e=0, m=y
	- b=3, e=8, m=5
	- b=0x1400000007, e=0x1400000006, m=0x1400000005

Source:
- Find the tests in this project: [@ianacaburian/generate-key-file](https://github.com/ianacaburian/generate-key-file/tree/develop)
@reuk
Copy link
Member

reuk commented Oct 1, 2024

Thanks for reporting, a fix has been merged here: 646179c

@reuk reuk closed this as completed Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants