-
Notifications
You must be signed in to change notification settings - Fork 4
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
fix: add ec pub key validation checks #112
Conversation
hamada147
commented
Nov 15, 2023
- Adding additional validation to public key compress method
Code Coverage
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jesusdiazvico @alexandroszacharakis8 you guys can probably help us on this, can we have a unit test from you guys that checks this validation? (https://www.secg.org/sec1-v2.pdf - section 3.2.2.1)
It can be as simple as providing a valid public key and multiple invalid public key cases so we can test this.
val x = BigInteger.fromByteArray(pubKey.sliceArray(1..32), Sign.POSITIVE) | ||
val y = BigInteger.fromByteArray(pubKey.sliceArray(33..64), Sign.POSITIVE) | ||
val b = BigInteger(7) | ||
val p = BigInteger.parseString("115792089237316195423570985008687907853269984665640564039457584007908834671663", 10) | ||
return if (((y * y - x * x * x - b) mod p) == BigInteger.ZERO) { | ||
Secp256k1.pubKeyCompress(pubKey) | ||
} else { | ||
throw Secp256k1Exception("invalid public key") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be logic that is sharable through the platforms, so probably lets put it into a function and use the same logic everywhere and not repeat it multiple times ;) It will be easier for Helen to review as well.
2153605
to
8eb52b5
Compare
8eb52b5
to
622a550
Compare
🎉 This PR is included in version 1.1.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Signed-off-by: Ahmed Moussa <[email protected]>