@@ -199,29 +199,48 @@ def generateKey():
199199 return PrivateKey (curve , b , x , y )
200200
201201
202- class KoblitzCurve :
203- """
204- KoblitzCurve provides a secp256k1 Koblitz curve implementation.
205- """
202+ def fromHex (hx ):
203+ return int (hx , 16 )
206204
207- def __init__ (
208- self , P , N , B , Gx , Gy , BitSize , H , q , byteSize , lambda_ , beta , a1 , b1 , a2 , b2
209- ):
210- self .P = P
211- self .N = N
212- self .B = B
213- self .Gx = Gx
214- self .Gy = Gy
215- self .BitSize = BitSize
216- self .H = H
217- self .q = q
218- self .byteSize = byteSize
219- self .lambda_ = lambda_
220- self .beta = beta
221- self .a1 = a1
222- self .b1 = b1
223- self .a2 = a2
224- self .b2 = b2
205+
206+ class Curve :
207+ def __init__ (self ):
208+ bitSize = 256
209+ p = fromHex ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F" )
210+ self .P = p
211+ self .N = fromHex (
212+ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141"
213+ )
214+ self .B = fromHex (
215+ "0000000000000000000000000000000000000000000000000000000000000007"
216+ )
217+ self .Gx = fromHex (
218+ "79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798"
219+ )
220+ self .Gy = fromHex (
221+ "483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8"
222+ )
223+ self .BitSize = bitSize
224+ self .H = 1
225+ self .q = (p + 1 ) // 4
226+ # Provided for convenience since this gets computed repeatedly.
227+ self .byteSize = bitSize / 8
228+ # Next 6 constants are from Hal Finney's bitcointalk.org post:
229+ # https://bitcointalk.org/index.php?topic=3238.msg45565#msg45565
230+ # May he rest in peace.
231+ #
232+ # They have also been independently derived from the code in the
233+ # EndomorphismVectors function in gensecp256k1.go.
234+ self .lambda_ = fromHex (
235+ "5363AD4CC05C30E0A5261C028812645A122E22EA20816678DF02967C1B23BD72"
236+ )
237+ self .beta = FieldVal .fromHex (
238+ "7AE96A2B657C07106E64479EAC3434E99CF0497512F58995C1396C28719501EE"
239+ )
240+ self .a1 = fromHex ("3086D221A7D46BCDE86C90E49284EB15" )
241+ self .b1 = fromHex ("-E4437ED6010E88286F547FA90ABFE4C3" )
242+ self .a2 = fromHex ("114CA50F7A8E2F3F657C1108D9D44CFD8" )
243+ self .b2 = fromHex ("3086D221A7D46BCDE86C90E49284EB15" )
225244
226245 def scalarBaseMult (self , k ):
227246 """
@@ -983,57 +1002,6 @@ def fieldJacobianToBigAffine(self, x, y, z):
9831002 # Convert the field values for the now affine point to integers.
9841003 return ByteArray (x .bytes ()).int (), ByteArray (y .bytes ()).int ()
9851004
986-
987- def fromHex (hx ):
988- """
989- fromHex converts the passed hex string into an integer. This is only
990- meant for the hard-coded constants so errors in the source code can be
991- detected. It will (and must) only be called for initialization purposes.
992- """
993- return int (hx , 16 )
994-
995-
996- class Curve (KoblitzCurve ):
997- def __init__ (self ):
998- bitSize = 256
999- p = fromHex ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F" )
1000- super ().__init__ (
1001- P = p ,
1002- N = fromHex (
1003- "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141"
1004- ),
1005- B = fromHex (
1006- "0000000000000000000000000000000000000000000000000000000000000007"
1007- ),
1008- Gx = fromHex (
1009- "79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798"
1010- ),
1011- Gy = fromHex (
1012- "483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8"
1013- ),
1014- BitSize = bitSize ,
1015- H = 1 ,
1016- q = (p + 1 ) // 4 ,
1017- # Provided for convenience since this gets computed repeatedly.
1018- byteSize = bitSize / 8 ,
1019- # Next 6 constants are from Hal Finney's bitcointalk.org post:
1020- # https://bitcointalk.org/index.php?topic=3238.msg45565#msg45565
1021- # May he rest in peace.
1022- #
1023- # They have also been independently derived from the code in the
1024- # EndomorphismVectors function in gensecp256k1.go.
1025- lambda_ = fromHex (
1026- "5363AD4CC05C30E0A5261C028812645A122E22EA20816678DF02967C1B23BD72"
1027- ),
1028- beta = FieldVal .fromHex (
1029- "7AE96A2B657C07106E64479EAC3434E99CF0497512F58995C1396C28719501EE"
1030- ),
1031- a1 = fromHex ("3086D221A7D46BCDE86C90E49284EB15" ),
1032- b1 = fromHex ("-E4437ED6010E88286F547FA90ABFE4C3" ),
1033- a2 = fromHex ("114CA50F7A8E2F3F657C1108D9D44CFD8" ),
1034- b2 = fromHex ("3086D221A7D46BCDE86C90E49284EB15" ),
1035- )
1036-
10371005 def bigAffineToField (self , x , y ):
10381006 """
10391007 bigAffineToField takes an affine point (x, y) as integers
0 commit comments