-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
Add a Math.inv function that inverse a number in Z/nZ #4839
Conversation
🦋 Changeset detectedLatest commit: f683c96 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Some ressources:
All these are based on the Euclidean algorithm, and Bezout's identity. To find |
…ost significantly less
This reverts commit 32fbe53.
This is my current understanding:
What we're providing with this function is the modular multiplicative inverse of an The multiplicative inverse of
If the |
} | ||
|
||
function testInvModP256(uint256 seed) public { | ||
uint256 p = 0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff; // prime |
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.
Wow now I get why the rumors of a backdoor in secp256r1, this is a weird number
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.
LGTM
This is a very common function use in finite fields such as the ones that power ECDSA curves.
PR Checklist
npx changeset add
)