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

ECDSASigner unable to generateSignature due to problems with the ECDomainParameters #595

Closed
TheBlackBird808 opened this issue Sep 23, 2019 · 2 comments

Comments

@TheBlackBird808
Copy link

TheBlackBird808 commented Sep 23, 2019

I tried signing a byte[] message with a private key in a project using the web3J library and it runs into an error. The library calls a sign method of its ECKeyPair class, which uses the ECDSASigner of this library, which is the reason I am raising the issue here.

While calling the sign() method of the ECKeyPair object, it creates ECPrivateKeyParameters which are passed to the init() method of the ECDSASigner object. There, it is using it to create ECKeyParameters.

This ECKeyParameters are used in the generateSignature(byte[] var1) method, to retrieve the n and d fields of the ECDomainParamters to calculate the signature. This two values however, are of different lengths, which leads to an ArrayIndexOutOfBoundsException in the HMacDSAKCalculator.init() method, which is trying to calculate the signature.

As I am only passing the EcKeyPair created with a private key to the method of the library and it is forwarding the values to ECDSASigner without interferring, I assume that there must be a issue creating the ECKeyParameters. As I am also only passing the EcKeyPair (and the to be signed message, but it is never used before this issue, so it can't be relevant) and tried different ways of generating the private key for generating them, I also don't know where I am doing something wrong.

Help is really appreciated!
Cheers

@peterdettman
Copy link
Collaborator

It sounds like the private key ('d') was generated incorrectly. It has to be less than the group order from the domain parameters ('n'). You should track down where the key pair was actually created and find out why.

It may be helpful to use the latest release (1.63) since we added validation in the ECPrivateKeyParameters constructor; the error should show up closer to the problem code.

@bcgit
Copy link
Collaborator

bcgit commented Mar 22, 2020

Closing as appears not to be a BC issue.

@bcgit bcgit closed this as completed Mar 22, 2020
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