Skip to content

Inverse modulo doesn't give the same result as in Java (with BigInteger) #1182

Answered by sipa
PeterMacGonagan asked this question in Q&A
Discussion options

You must be logged in to vote

The X and Y coordinates on the elliptic curves are numbers modulo p = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f. They are referred to as field elements in the libsecp256k1 source code, with type secp256k1_fe.

Points on the curve are referred to as group elements (secp256k1_ge and secp256k1_gej).

Scalars (secp256k1_scalar) are integers modulo the number of points on the curve, n = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141. They're used for private keys, nonces, ...

You can't use scalars for field operations; the modulus will be wrong.

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by real-or-random
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #1180 on December 22, 2022 15:20.