{ "info": { "author": "Alex Moneger", "author_email": "alexmgr+github@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "# tinyec\nA tiny library to perform arithmetic operations on elliptic curves in pure python. No dependencies.\n\n**This is not a library suitable for production.** It is useful for security professionals to understand the inner workings of EC, and be able to play with pre-defined curves.\n\n## installation\n`pip install tinyec`\n\n## usage\nThere are 2 main classes:\n* Curve(), which describes an elliptic curve in a finite field\n* Point(), which describes a point belonging to an EC\n\n**Warning** Calculation on points outside the curve are allowed. They will only raise a warning.\n\n### working on existing curves\nExample use on the NIST routine samples => https://www.nsa.gov/ia/_files/nist-routines.pdf:\n```python\n>>> import tinyec.ec as ec\n>>> import tinyec.registry as reg\n>>> c = reg.get_curve(\"secp192r1\")\n>>> s = ec.Point(c, 0xd458e7d127ae671b0c330266d246769353a012073e97acf8, 0x325930500d851f336bddc050cf7fb11b5673a1645086df3b)\n>>> t = ec.Point(c, 0xf22c4395213e9ebe67ddecdd87fdbd01be16fb059b9753a4, 0x264424096af2b3597796db48f8dfb41fa9cecc97691a9c79)\n>>> r = s + t\n>>> r\n(1787070900316344022479363585363935252075532448940096815760, 1583034776780933252095415958625802984888372377603917916747) on secp192r1 => y^2 = x^3 + 6277101735386680763835789423207666416083908700390324961276x + 2455155546008943817740293915197451784769108058161191238065 \n(mod 6277101735386680763835789423207666416083908700390324961279)\n>>> hex(r.x)\n'0x48e1e4096b9b8e5ca9d0f1f077b8abf58e843894de4d0290L'\n>>> hex(r.y)\n'0x408fa77c797cd7dbfb16aa48a3648d3d63c94117d7b6aa4bL'\n>>> r = s - t\n>>> r\n(6193438478050209507979672067809269724375390027440522152494, 226636415264149817017346905052752138772359775362461041003) on secp192r1 => y^2 = x^3 + 6277101735386680763835789423207666416083908700390324961276x + 2455155546008943817740293915197451784769108058161191238065 (\nmod 6277101735386680763835789423207666416083908700390324961279)\n>>> hex(r.x)\n'0xfc9683cc5abfb4fe0cc8cc3bc9f61eabc4688f11e9f64a2eL'\n>>> hex(r.y)\n'0x93e31d00fb78269732b1bd2a73c23cdd31745d0523d816bL'\n>>> r = 2 * s\n>>> r\n(1195895923065450997501505402941681398272052708885411031394, 340030206158745947396451508065335698335058477174385838543) on secp192r1 => y^2 = x^3 + 6277101735386680763835789423207666416083908700390324961276x + 2455155546008943817740293915197451784769108058161191238065 (\nmod 6277101735386680763835789423207666416083908700390324961279)\n>>> hex(r.x)\n'0x30c5bc6b8c7da25354b373dc14dd8a0eba42d25a3f6e6962L'\n>>> hex(r.y)\n'0xdde14bc4249a721c407aedbf011e2ddbbcb2968c9d889cfL'\n>>> d = 0xa78a236d60baec0c5dd41b33a542463a8255391af64c74ee\n>>> r = d * s\n>>> hex(r.x)\n'0x1faee4205a4f669d2d0a8f25e3bcec9a62a6952965bf6d31L'\n>>> hex(r.y)\n'0x5ff2cdfa508a2581892367087c696f179e7a4d7e8260fb06L'\n>>> e = 0xc4be3d53ec3089e71e4de8ceab7cce889bc393cd85b972bc\n>>> r = d * s + e * t\n>>> r\n(39786866609245082371772779541859439402855864496422607838, 547967566579883709478937502153554894699060378424501614148) on secp192r1 => y^2 = x^3 + 6277101735386680763835789423207666416083908700390324961276x + 2455155546008943817740293915197451784769108058161191238065 (mo\nd 6277101735386680763835789423207666416083908700390324961279)\n>>> hex(r.x)\n'0x19f64eed8fa9b72b7dfea82c17c9bfa60ecb9e1778b5bdeL'\n>>> hex(r.y)\n'0x16590c5fcd8655fa4ced33fb800e2a7e3c61f35d83503644L'\n```\n\n### working on custom curves\nIf needed, you can also work on your own curves. Here we take a a prime field 97, with a generator point (1, 2), an order 5 and a cofactor of 1:\n```python\n>>> import tinyec.ec as ec\n>>> field = ec.SubGroup(97, (1, 2), 5, 1)\n>>> curve = ec.Curve(2, 3, field)\ntinyec/ec.py:115: UserWarning: Point (1, 2) is not on curve \"undefined\" => y^2 = x^3 + 2x + 3 (mod 97)\n warnings.warn(\"Point (%d, %d) is not on curve %s\" % (self.x, self.y, self.curve))\n>>> # Warning is generated because the generator point does not belong to the curve\n>>> p1 = ec.Point(curve, -5, 3)\n>>> p1.on_curve\nFalse\n>>> p2 = ec.Point(curve, 22, 5)\n>>> p2.on_curve\nTrue\n>>> print(p1 + p2)\n(18, 42) off \"undefined\" => y^2 = x^3 + 2x + 3 (mod 97)\n```", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/alexmgr/tinyec/archive/v0.3.1.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/alexmgr/tinyec", "keywords": "elliptic,curves,crypto,tls,ssl,ecdhe,diffie-hellman", "license": "GPLv3", "maintainer": null, "maintainer_email": null, "name": "tinyec", "package_url": "https://pypi.org/project/tinyec/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/tinyec/", "project_urls": { "Download": "https://github.com/alexmgr/tinyec/archive/v0.3.1.tar.gz", "Homepage": "https://github.com/alexmgr/tinyec" }, "release_url": "https://pypi.org/project/tinyec/0.3.1/", "requires_dist": null, "requires_python": null, "summary": "A tiny library to perform arithmetic operations on elliptic curves in pure python", "version": "0.3.1" }, "last_serial": 1728803, "releases": { "0.1": [], "0.3": [ { "comment_text": "", "digests": { "md5": "8c5581ead9293825485c3c242f4b4bce", "sha256": "c3084809ed3bfe2694f25d1fdeed6ca7cce9486fafe184d8d6cb994779b8e742" }, "downloads": -1, "filename": "tinyec-0.3.tar.gz", "has_sig": false, "md5_digest": "8c5581ead9293825485c3c242f4b4bce", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8020, "upload_time": "2015-09-18T21:58:48", "url": "https://files.pythonhosted.org/packages/a2/81/cfde42bddf1ed8249a8dc7bedda50bcae1abb4d2f1f2a1e4e089bc88e3c2/tinyec-0.3.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "ce477748495e06e180dace2ee2471774", "sha256": "419ddfd55fca95e6e721db03c5d725a1c94eace2428dabebad85cb5210cf12ea" }, "downloads": -1, "filename": "tinyec-0.3.1.tar.gz", "has_sig": false, "md5_digest": "ce477748495e06e180dace2ee2471774", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23912, "upload_time": "2015-09-18T22:19:26", "url": "https://files.pythonhosted.org/packages/c2/00/977e7339ae19b42ae10e1219e5b13c0f54ef703e019be5d3e0b6bf5b90fe/tinyec-0.3.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "ce477748495e06e180dace2ee2471774", "sha256": "419ddfd55fca95e6e721db03c5d725a1c94eace2428dabebad85cb5210cf12ea" }, "downloads": -1, "filename": "tinyec-0.3.1.tar.gz", "has_sig": false, "md5_digest": "ce477748495e06e180dace2ee2471774", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23912, "upload_time": "2015-09-18T22:19:26", "url": "https://files.pythonhosted.org/packages/c2/00/977e7339ae19b42ae10e1219e5b13c0f54ef703e019be5d3e0b6bf5b90fe/tinyec-0.3.1.tar.gz" } ] }