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

Possible issue in KeyTools #8

Open
AmritKumar opened this issue Feb 5, 2019 · 1 comment
Open

Possible issue in KeyTools #8

AmritKumar opened this issue Feb 5, 2019 · 1 comment

Comments

@AmritKumar
Copy link

AmritKumar commented Feb 5, 2019

PROBLEM: The if condition in the following function (crypto/KeyTools.java) seems incorrect. Comparing the bitLength() of two values should not be the criterion to do a modulo.

private static ECPoint getPublicPointFromPrivate(BigInteger privateKeyPoint) {
        if (privateKeyPoint.bitLength() > CURVE.getN().bitLength()) {
            privateKeyPoint = privateKeyPoint.mod(CURVE.getN());
        }
        return new FixedPointCombMultiplier().multiply(CURVE.getG(), privateKeyPoint);
}

SOLUTION: Instead of comparing the bitLength(), one should compare the actual values. In fact, one could throw an error if the input is larger than CURVE.N. Since this function is used to generate a public key from a private key, one should also do some extra checks on the input such as the input is 1) positive 2) not equal to 0. @nickcen @iantanwx

@iantanwx
Copy link
Contributor

Thanks @AmritKumar. I'll make a PR later.

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