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 with BIG.mod in Java? #38

Closed
JesusGarciaRodriguez opened this issue Feb 9, 2021 · 2 comments
Closed

Bug with BIG.mod in Java? #38

JesusGarciaRodriguez opened this issue Feb 9, 2021 · 2 comments

Comments

@JesusGarciaRodriguez
Copy link

Hello, I am using the Java version of the library (in particular, selecting only curve BLS461 for compilation) and I am having trouble with modular arithmetic.

The "mod" operation in BIG crashes (infinte loop) when using it on a "negative" BIG. For example, the following test will not finish:

public void test(){
        BIG b=new BIG(1);
        b.sub(new BIG(20));
        b.mod(new BIG(ROM.CURVE_Order));
}

Using debugger, it seems to be stuck in the loop:

            do {
                m.fshl(1);
                ++k;
            } while(comp(this, m) >= 0);

in mod method of (decompiled) class org\miracl\core\BLS12461\BIG.class

I think this falls within normal use, but in any case getting an infinite loop seems like a weird occurence even if something is wrong.

@mcarrickscott
Copy link
Contributor

mcarrickscott commented Feb 9, 2021 via email

@JesusGarciaRodriguez
Copy link
Author

JesusGarciaRodriguez commented Feb 9, 2021

Hello, thank you for the (really!) quick response!
I understand that negative numbers "as is" are not supported, and thought this would probably be a consequence of that. However, I am working on an implementation where we "need" that kind of operation, in the sense of the following example, and that is why we found this.

 If we are considering a modulus p=7, we want 2-5 to give 4 as a result (as -3≡4 (mod 7)). 

This "issue" is easy to get around by ensuring the first element is bigger by adding the modulus p (using BIG.comp to check beforehand) before subtracting. We just wanted to make sure we were not missing anything because of how it crashed.

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