{"id":13801476,"url":"https://github.com/git-n-pissed/mprsa","last_synced_at":"2025-05-13T11:31:15.705Z","repository":{"id":215170568,"uuid":"586751022","full_name":"git-n-pissed/mprsa","owner":"git-n-pissed","description":"A MicroPython module for working with RSA keys","archived":false,"fork":false,"pushed_at":"2023-01-24T21:09:24.000Z","size":148,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-22T12:33:04.201Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/git-n-pissed.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS"}},"created_at":"2023-01-09T06:18:42.000Z","updated_at":"2023-10-14T10:48:14.000Z","dependencies_parsed_at":"2024-01-07T21:53:02.874Z","dependency_job_id":null,"html_url":"https://github.com/git-n-pissed/mprsa","commit_stats":null,"previous_names":["git-n-pissed/mprsa"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/git-n-pissed%2Fmprsa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/git-n-pissed%2Fmprsa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/git-n-pissed%2Fmprsa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/git-n-pissed%2Fmprsa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/git-n-pissed","download_url":"https://codeload.github.com/git-n-pissed/mprsa/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253932831,"owners_count":21986458,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T00:01:23.226Z","updated_at":"2025-05-13T11:31:11.785Z","avatar_url":"https://github.com/git-n-pissed.png","language":"C","readme":"# Description\r\nThis module is a mash-up of [python-rsa](https://github.com/sybrenstuvel/python-rsa),\r\n[Toms Fast Math](https://github.com/libtom/tomsfastmath) (ported to MicroPython by\r\n[Damiano Mazzella](https://github.com/dmazzella), the author of [ucrypto](https://github.com/dmazzella/ucrypto)),\r\nand [python-asn1](https://github.com/andrivet/python-asn1).\r\nThe goal was to create a MicroPython module that would:\r\n\r\n1. Be simple to use\r\n2. Support loading/exporting RSA keys in common formats/structures\r\n3. Support generation of new keys\r\n4. Support signing/verification with blinding using common hashing algorithms\r\n5. Support encryption/decryption with blinding\r\n\r\n# Supported Key Formats\r\n- ### Private:\r\n  - PKCS#1 DER\r\n  - PKCS#1 PEM\r\n  - PKCS#8 DER\r\n  - PKCS#8 PEM\r\n\r\n- ### Public:\r\n  - PKCS#1 DER\r\n  - PKCS#1 PEM\r\n  - X.509/SPKI DER\r\n  - X.509/SPKI PEM\r\n  \r\nThe OpenSSL commands used to generate supported keys are contained in the docstrings for the\r\nfunctions that operate on those keys.\r\n\r\n# Supported Hashing Algorithms\r\n- SHA-1\r\n- SHA-256\r\n\r\n# How to Build\r\n1. Clone or copy the repo.\r\n2. Copy the contents (not the actual directory) of the `port_modules` directory into the `modules` directory of the\r\n   MicroPython port you are building for.\r\n3. Copy the `user_c_modules` directory (the actual directory) somewhere you can reference it your MicroPython build\r\n   command.  The MicroPython docs recommend placing user C modules outside the MicroPython directory, but I find it\r\n   easier to simply have a `user_c_modules` directory inside the MicroPython directory which contains all the user C\r\n   modules I want to build.  This way you can simply make sure any other user C modules are included in the\r\n   `micropython.cmake` in that directory.\r\n\r\n    ![mprsa user_c_module directory placement](README_images/mprsa_user_c_modules_directory_placement.png)\r\n\r\n4. Run a command similar to this.  This command is based on the `user_c_modules` being placed as shown in the\r\n   directory structure in the picture above.  The command you need to run may change based on your port, board, and\r\n   directory structure:\r\n    ```bash\r\n    make -j8 BOARD=GENERIC_S3 USER_C_MODULES=\"$(pwd)/micropython/user_c_modules/mprsa/micropython.cmake\" -C \"$(pwd)/micropython/ports/esp32\"\r\n    ```\r\n\r\n# Examples\r\n  See [test.py](https://github.com/git-n-pissed/mprsa/blob/master/tests/test.py)\r\n  \r\n# Supported Hardware\r\nHardware which this module has been tested on is listed below with :heavy_check_mark: if it worked, and :x: if it didn't\r\nwork.  If you are willing to try the module out on other hardware and run\r\n[test.py](https://github.com/git-n-pissed/mprsa/blob/master/tests/test.py) to verify it works, that would be appreciated.\r\nMake an issue with your findings and I'll update this\r\n[README.md](https://github.com/git-n-pissed/mprsa/blob/main/README.md), or make a PR which updates this section of the\r\n[README.md](https://github.com/git-n-pissed/mprsa/blob/main/README.md).\r\n\r\n\u003ctable\u003e\r\n  \u003cthead\u003e\r\n    \u003ctr\u003e\r\n      \u003cth nowrap\u003eDevice\u003c/th\u003e\r\n      \u003cth nowrap\u003eWorks\u003c/th\u003e\r\n      \u003cth nowrap\u003eNotes\u003c/th\u003e\r\n    \u003c/tr\u003e\r\n  \u003c/thead\u003e\r\n  \u003ctbody\u003e\r\n    \u003ctr\u003e\r\n      \u003ctd nowrap\u003eESP32\u003c/td\u003e\r\n      \u003ctd\u003e:heavy_check_mark:\u003c/td\u003e\r\n      \u003ctd\u003e\r\n        \u003cul\u003e\r\n          \u003cli\u003eRequires a more aggressive garbage collection threshold than stock.  Tested and working with \u003ccode\u003egc.threshold(1024)\u003c/code\u003e\u003c/li\u003e\r\n        \u003c/ul\u003e\r\n      \u003c/td\u003e\r\n    \u003c/tr\u003e\r\n    \u003ctr\u003e\r\n      \u003ctd nowrap\u003eESP32-S3\u003c/td\u003e\r\n      \u003ctd\u003e:heavy_check_mark:\u003c/td\u003e\r\n      \u003ctd\u003e\u003c/td\u003e\r\n    \u003c/tr\u003e\r\n  \u003c/tbody\u003e\r\n\u003c/table\u003e\r\n\r\n# Known Limitations\r\n- Key Generation Speed\r\n  - Even when using Toms Fast Math, generating a key of any size that can offer real security is slow.  The `gen_key`\r\n    function defaults to the fastest possible options for key generation (i.e. allowing modulus \"n\" to be of slightly\r\n    fewer bits than specified and not requiring \"p\" and \"q\" to be safe primes), but generating a 2048-bit key on an\r\n    ESP32-S3 still takes 3 - 5 minutes.  When a modulus \"n\" of an exact size and/or \"p\" and \"q\" values which are safe\r\n    primes are desired, the time to generate keys increases dramatically.  In the case of 2048-bit keys sometimes 30\r\n    minutes, sometimes an hour or more.\r\n- Key Size\r\n  - Max key size is 2048-bits.  This can likely be increased by tweaking [tfm.h](https://github.com/git-n-pissed/mprsa/blob/main/user_c_modules/mprsa/tfm/tfm_mpi.h), specifically the value of `FP_SIZE`.\r\n\r\n# Licenses\r\nAll the code in this module is copyright under the Apache License, the MIT License, or is public domain.\r\n","funding_links":[],"categories":["Libraries"],"sub_categories":["Communications"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgit-n-pissed%2Fmprsa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgit-n-pissed%2Fmprsa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgit-n-pissed%2Fmprsa/lists"}