The secp256k1 curve uses a prime number of \( 2^{256}-2^{224}+2^{192}+2^{96}-1\) and \(y^2=x^3-3.x+b \pmod p\). The value of \(b\) is 41058363725152142129 ... 5554835256314039467401291L. The base point is \(G\)= (4843956129390645175 ... 47995844080717082404635286L gy = 36134250956749 ... 1877198253568414405109L) and has an order of \(n\) = 11579208921035624876 ... 135760342422259061068512044369L. In this case we enter the value of \(n\) and then use Sage to compute \(n.G\).
Sage: Elliptic Curve Point (P256 - secp256r1) |
Outline
The NIST P256 (secp256r1) curve uses a prime number of:
\(2^{256}-2^{224}+2^{192}+2^{96}-1\)
and:
\(y^2=x^3-3.x+b \pmod p\)
and where \(b\) is:
\(b=41058363725152142129326129780047268409114441015993725554835256314039467401291L \)
The base point is:
G= ( 48439561293906451759052585252797914202762949526041747995844080717082404635286L, 36134250956749795798585127919587881956611106672985015071877198253568414405109L)
and has an order of:
n = 115792089210356248762697446949407573529996955224135760342422259061068512044369L
In this case we enter the value of \(n\) and then use Sage to compute \(n.G\).
Coding
import sys ## Alice's private key a = 1 str=sys.argv[1] a=int(str.split(";")[2]) ###### NIST P256 p256 = 2^256-2^224+2^192+2^96-1 a256 = p256 - 3 b256 = 41058363725152142129326129780047268409114441015993725554835256314039467401291L ## Base point gx = 48439561293906451759052585252797914202762949526041747995844080717082404635286L gy = 36134250956749795798585127919587881956611106672985015071877198253568414405109L ## Curve order n = 115792089210356248762697446949407573529996955224135760342422259061068512044369L FF = GF(p256) EC = EllipticCurve([FF(a256), FF(b256)]) EC.set_order(n) ## Base point G = EC(FF(gx), FF(gy)) ## Alice's public key A = a*G print ("G=",G) print ("a=",a) print ("A=",A)
A sample run for \(1.G\) is:
G= (48439561293906451759052585252797914202762949526041747995844080717082404635286 : 36134250956749795798585127919587881956611106672985015071877198253568414405109 : 1) a= 1 A= (48439561293906451759052585252797914202762949526041747995844080717082404635286 : 36134250956749795798585127919587881956611106672985015071877198253568414405109 : 1)
and for \(10.G\):
G= (48439561293906451759052585252797914202762949526041747995844080717082404635286 : 36134250956749795798585127919587881956611106672985015071877198253568414405109 : 1) a= 10 A= (93611846365601674425599200647886473617443872040541410036779615417472400060991 : 61299672808462629900136024686264045542397545919962042795596947287593974695795 : 1)
and for \(100.G\):
G= (48439561293906451759052585252797914202762949526041747995844080717082404635286 : 36134250956749795798585127919587881956611106672985015071877198253568414405109 : 1) a= 100 A= (33036681201834431806125287315208999535688917902318640770552947863084311454064 : 84945031628206560286385484845876297255374399530307053403754377481469130405780 : 1)
To run within a Windows environment, we can use:
"c:\program files\SageMath 9.3\runtime\bin\bash.exe" -l "/opt/sagemath-9.3/sage" -c "os.chdir('C:\myfolder'); load('1.sage'); %1"