Lines Matching full:curve

174 class Curve(object):  class
196 def __init__(self, curve, x, y): argument
197 self.curve = curve
199 self.x = (x % curve.p)
203 self.y = (y % curve.p)
206 # Check that the point is indeed on the curve
208 if (pow(y, 2, curve.p) != ((pow(x, 3, curve.p) + (curve.a * x) + curve.b ) % curve.p)):
209 raise Exception("Error: point is not on curve!")
216 curve = self.curve
217 # Check that we are on the same curve
218 if Q.curve != curve:
219 raise Exception("Point add error: two point don't have the same curve")
222 return Point(self.curve, self.x, self.y)
228 if (((y1 + y2) % curve.p) == 0):
230 return Point(self.curve, None, None)
233 L = ((3*pow(x1, 2, curve.p) + curve.a) * modinv(2*y1, curve.p)) % curve.p
236 L = ((y2 - y1) * modinv((x2 - x1) % curve.p, curve.p)) % curve.p
237 resx = (pow(L, 2, curve.p) - x1 - x2) % curve.p
238 resy = ((L * (x1 - resx)) - y1) % curve.p
240 return Point(self.curve, resx, resy)
244 return Point(self.curve, None, None)
246 return Point(self.curve, self.x, -self.y)
254 Q = Point(P.curve, None, None)
275 def __init__(self, curve, x): argument
276 self.curve = curve
280 def __init__(self, curve, Y): argument
282 if Y.curve != curve:
283 raise Exception("Error: curve and point curve differ in public key!")
284 self.curve = curve
294 curve = privkey.curve
295 q = curve.q
296 gx = curve.gx
297 gy = curve.gy
298 G = Point(curve, gx, gy)
300 return PubKey(curve, privkey.x * G)
302 return PubKey(curve, modinv(privkey.x, q) * G)
304 def genKeyPair(curve, is_eckcdsa=False): argument
305 p = curve.p
306 q = curve.q
307 gx = curve.gx
308 gy = curve.gy
309 G = Point(curve, gx, gy)
316 privkey = PrivKey(curve, x)
493 # Get important parameters from the curve
494 p = privkey.curve.p
495 q = privkey.curve.q
496 gx = privkey.curve.gx
497 gy = privkey.curve.gy
498 G = Point(privkey.curve, gx, gy)
539 # Get important parameters from the curve
540 p = pubkey.curve.p
541 q = pubkey.curve.q
542 gx = pubkey.curve.gx
543 gy = pubkey.curve.gy
545 G = Point(pubkey.curve, gx, gy)
570 def eckcdsa_genKeyPair(curve): argument
571 return genKeyPair(curve, True)
589 # Get important parameters from the curve
590 p = privkey.curve.p
591 q = privkey.curve.q
592 gx = privkey.curve.gx
593 gy = privkey.curve.gy
594 G = Point(privkey.curve, gx, gy)
645 # Get important parameters from the curve
646 p = pubkey.curve.p
647 q = pubkey.curve.q
648 gx = pubkey.curve.gx
649 gy = pubkey.curve.gy
650 G = Point(pubkey.curve, gx, gy)
697 # Get important parameters from the curve
698 p = privkey.curve.p
699 q = privkey.curve.q
700 gx = privkey.curve.gx
701 gy = privkey.curve.gy
702 G = Point(privkey.curve, gx, gy)
724 # *| I 1. Reject the signature if r is not a valid point on the curve.
733 # Get important parameters from the curve
734 p = pubkey.curve.p
735 q = pubkey.curve.q
736 gx = pubkey.curve.gx
737 gy = pubkey.curve.gy
738 G = Point(pubkey.curve, gx, gy)
746 # Check r is on the curve
747 W = Point(pubkey.curve, stringtoint(wx), stringtoint(wy))
791 # Get important parameters from the curve
792 p = privkey.curve.p
793 q = privkey.curve.q
794 gx = privkey.curve.gx
795 gy = privkey.curve.gy
796 G = Point(privkey.curve, gx, gy)
835 # Get important parameters from the curve
836 p = pubkey.curve.p
837 q = pubkey.curve.q
838 gx = pubkey.curve.gx
839 gy = pubkey.curve.gy
840 G = Point(pubkey.curve, gx, gy)
879 # Get important parameters from the curve
880 p = privkey.curve.p
881 q = privkey.curve.q
882 gx = privkey.curve.gx
883 gy = privkey.curve.gy
884 G = Point(privkey.curve, gx, gy)
919 # Get important parameters from the curve
920 p = pubkey.curve.p
921 q = pubkey.curve.q
922 gx = pubkey.curve.gx
923 gy = pubkey.curve.gy
924 G = Point(pubkey.curve, gx, gy)
963 # Get important parameters from the curve
964 p = privkey.curve.p
965 q = privkey.curve.q
966 gx = privkey.curve.gx
967 gy = privkey.curve.gy
968 G = Point(privkey.curve, gx, gy)
1007 # Get important parameters from the curve
1008 p = pubkey.curve.p
1009 q = pubkey.curve.q
1010 gx = pubkey.curve.gx
1011 gy = pubkey.curve.gy
1012 G = Point(pubkey.curve, gx, gy)
1066 def gen_self_test(curve, hashfunc, sig_alg_sign, sig_alg_verify, sig_alg_genkeypair, num, hashfunc_… argument
1075 keypair = sig_alg_genkeypair(curve)
1082 … test_name = sig_alg_name + "_" + hashfunc_name + "_" + curve.name.upper() + "_" + str(test_num)
1092 out_vectors += "#ifdef WITH_CURVE_"+curve.name.upper()+"\n"
1097 out_vectors += "\tconst u8 k_buf[] = "+bigint_to_C_array(k, getbytelen(curve.q))
1103 out_vectors += "\t.ec_str_p = &"+curve.name+"_str_params,\n"
1114 out_vectors += "#endif /* WITH_CURVE_"+curve.name+" */\n"
1122 out_name += "#ifdef WITH_CURVE_"+curve.name.upper()+"/* For "+test_name+" */\n"
1126 out_name += "#endif /* WITH_CURVE_"+curve.name+" for "+test_name+" */\n"
1141 out_vectors += "#ifdef WITH_CURVE_"+curve.name.upper()+"\n"
1146 out_vectors += "\tconst u8 k_buf[] = "+bigint_to_C_array(k, getbytelen(curve.q))
1152 out_vectors += "\t.ec_str_p = &"+curve.name+"_str_params,\n"
1163 out_vectors += "#endif /* WITH_CURVE_"+curve.name+" */\n"
1169 out_name += "#ifdef WITH_CURVE_"+curve.name.upper()+"/* For "+test_name+" */\n"
1173 out_name += "#endif /* WITH_CURVE_"+curve.name+" for "+test_name+" */\n"
1180 def gen_self_tests(curve, num): argument
1184 …vectors = [[ gen_self_test(curve, hashf, sign, verify, genkp, num, hash_name, sig_alg_name, total_…
1243 # regarding an EC curve, but since the ASN.1 structure is quite
1272 # Get curve (sequence)
1273 (check, size_Curve, Curve) = extract_DER_sequence(ECParameters[size_ECPVer+size_FieldID:])
1276 # Get A in curve
1277 (check, size_A, A) = extract_DER_octetstring(Curve)
1280 # Get B in curve
1281 (check, size_B, B) = extract_DER_octetstring(Curve[size_A:])
1427 ### Curve helpers
1447 Take as input some elliptic curve parameters and generate the
1474 # Compute the number of points on the curve
1627 print("In order to add a curve, there are two ways:")
1628 print("Adding a user defined curve with explicit parameters:")
1631 print("\t> name: name of the curve in the form of a string")
1632 print("\t> prime: prime number representing the curve prime field")
1634 print("\t> cofactor: cofactor of the curve")
1635 print("\t> a: 'a' coefficient of the short Weierstrass equation of the curve")
1636 print("\t> b: 'b' coefficient of the short Weierstrass equation of the curve")
1639 print("\t> oid: optional OID of the curve")
1642 print("\t1) These elements are verified to indeed satisfy the curve equation.")
1644 …print("\t3) The script automatically generates all the necessary files for the curve to be include…
1645 …print("\tYou will find the new curve definition in the usual 'lib_ecc_config.h' file (one can acti…
1647 print("Adding a user defined curve through RFC3279 ASN.1 parameters:")
1650 print("\t> ECfile: the DER or PEM encoded file containing the curve parameters (see RFC3279)")
1655 … called \"prime\" curves are supported. Then, one can extract an explicit curve representation in …
1662 …print("\t*A specific named user define curve can be removed with the --remove toggle: in this case…
1663 print("\tlocate which named curve must be deleted.")
1668 …print("\tIn this case, X test vectors will be generated for *each* (curve, sign algorithm, hash al…
1682 Get elliptic curve parameters from command line
1752 print("--remove option expects a curve name provided with --name")
1756 … everything related to user defined "+name.replace("user_defined_", "")+" curve. Enter y to confir…
1758 print("NOT removing curve "+name.replace("user_defined_", "")+" (cancelled).")
1761 print("Removing user defined curve "+name.replace("user_defined_", "")+" ...")
1763 print("Error: you must provide a curve name with --remove")
1775 print("Error: curve name "+name+" does not seem to be present in the sources!")
1780 print("Warning: curve name "+name+" self tests do not seem to be present ...")
1825 print("Error: option ECfile needs a curve name!")
1849 …print("Error: missing "+err_string+" in explicit curve definition (name, prime, a, b, gx, gy, orde…
1865 # Check that the provided generator is on the curve
1867 …print("Error: the given parameters (prime, a, b, gx, gy) do not verify the elliptic curve equation…
1901 # Add the curve mapping
1906 # Add the new curve type in the enum
1913 # Add the new curve define in the config
1918 # Add the new curve meson option in the meson.options file
1927 # Create curve
1928 c = Curve(a, b, prime, order, cofactor, gx, gy, cofactor * order, name, oid)
1938 magic = "ADD curve test case here"
1946 magic = "ADD curve test vectors header here"