Home

Awesome

Description

This module is a mash-up of python-rsa, Toms Fast Math (ported to MicroPython by Damiano Mazzella, the author of ucrypto), and python-asn1. The goal was to create a MicroPython module that would:

  1. Be simple to use
  2. Support loading/exporting RSA keys in common formats/structures
  3. Support generation of new keys
  4. Support signing/verification with blinding using common hashing algorithms
  5. Support encryption/decryption with blinding

Supported Key Formats

The OpenSSL commands used to generate supported keys are contained in the docstrings for the functions that operate on those keys.

Supported Hashing Algorithms

How to Build

  1. Clone or copy the repo.

  2. Copy the contents (not the actual directory) of the port_modules directory into the modules directory of the MicroPython port you are building for.

  3. Copy the user_c_modules directory (the actual directory) somewhere you can reference it your MicroPython build command. The MicroPython docs recommend placing user C modules outside the MicroPython directory, but I find it easier to simply have a user_c_modules directory inside the MicroPython directory which contains all the user C modules I want to build. This way you can simply make sure any other user C modules are included in the micropython.cmake in that directory.

    mprsa user_c_module directory placement

  4. Run a command similar to this. This command is based on the user_c_modules being placed as shown in the directory structure in the picture above. The command you need to run may change based on your port, board, and directory structure:

    make -j8 BOARD=GENERIC_S3 USER_C_MODULES="$(pwd)/micropython/user_c_modules/mprsa/micropython.cmake" -C "$(pwd)/micropython/ports/esp32"
    

Examples

See test.py

Supported Hardware

Hardware which this module has been tested on is listed below with :heavy_check_mark: if it worked, and :x: if it didn't work. If you are willing to try the module out on other hardware and run test.py to verify it works, that would be appreciated. Make an issue with your findings and I'll update this README.md, or make a PR which updates this section of the README.md.

<table> <thead> <tr> <th nowrap>Device</th> <th nowrap>Works</th> <th nowrap>Notes</th> </tr> </thead> <tbody> <tr> <td nowrap>ESP32</td> <td>:heavy_check_mark:</td> <td> <ul> <li>Requires a more aggressive garbage collection threshold than stock. Tested and working with <code>gc.threshold(1024)</code></li> </ul> </td> </tr> <tr> <td nowrap>ESP32-S3</td> <td>:heavy_check_mark:</td> <td></td> </tr> </tbody> </table>

Known Limitations

Licenses

All the code in this module is copyright under the Apache License, the MIT License, or is public domain.