Giter VIP home page Giter VIP logo

adafruit_circuitpython_rsa's Introduction

Introduction

Documentation Status

Discord

Build Status

Code Style: Black

RSA implementation based on Sybren A. Stüvel's python-rsa pure-python RSA implementation.

Dependencies

This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.

Installing from PyPI

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:

pip3 install adafruit-circuitpython-rsa

To install system-wide (this may be required in some cases):

sudo pip3 install adafruit-circuitpython-rsa

To install in a virtual environment in your current project:

mkdir project-name && cd project-name
python3 -m venv .venv
source .venv/bin/activate
pip3 install adafruit-circuitpython-rsa

Usage Example

Examples for this library are avaliable in the examples/ folder.

Documentation

API documentation for this library can be found on Read the Docs.

For information on building library documentation, please check out this guide.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

adafruit_circuitpython_rsa's People

Contributors

brentru avatar dhalbert avatar evaherrada avatar foamyguy avatar kattni avatar ladyada avatar ntoll avatar siddacious avatar sommersoft avatar tannewt avatar tekktrik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_circuitpython_rsa's Issues

pyasn1 not implement currently?

I want to test load/save pem, der format key, but the pyasn1 module looks like not work currently,

from pyasn1.type import univ, namedtype, tag

Traceback (most recent call last):
File "", line 1, in
File "univ.py", line 10, in
File "error.py", line 37, in
TypeError: multiple bases have instance lay-out conflict

May need update due to `adafruit_logging` 4.0.0

This library likely needs updates due to the adafruit_logging library upgrade. New use should be CPython compatible, and it may be worth allowing the CPython logging module to be imported if available.

Some common issues that are now present across libraries:

  • Locations of classes have changed, and some may have been removed.
  • PrintLogger no longer exists; instead, instance a Logger and add a StreamHandler instance with default arguments as the handler.

memory allocation failed.

Which series chip tested ?
I receive below when I import adafruit_rsa on STM32F405RGT6:
import adafruit_rsa

Traceback (most recent call last):
File "", line 1, in
File "/lib/adafruit_rsa/init.py", line 27, in
File "/lib/adafruit_rsa/pkcs1.py", line 31, in
File "/lib/adafruit_hashlib/init.py", line 45, in
MemoryError: memory allocation failed, allocating 2933 bytes

Missing requirement for adafruit_hashlib

After a clean install with pip install adafruit-circuitpython-rsa when you attempt to import the module it raises an exception due to missing hashlib:

>>> import adafruit_rsa
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/timc/.local/lib/python3.10/site-packages/adafruit_rsa/__init__.py", line 19, in <module>
    from adafruit_rsa.pkcs1 import (
  File "/home/timc/.local/lib/python3.10/site-packages/adafruit_rsa/pkcs1.py", line 25, in <module>
    import adafruit_hashlib as hashlib
ModuleNotFoundError: No module named 'adafruit_hashlib'

Doesn't install correctly from pip

I think pip installations of this library do not work properly.

In a test environment I installed with:

❯ pip install adafruit-circuitpython-rsa
Collecting adafruit-circuitpython-rsa
  Downloading adafruit-circuitpython-rsa-1.2.6.tar.gz (49 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 49.7/49.7 KB 7.0 MB/s eta 0:00:00
  Preparing metadata (setup.py) ... done
Requirement already satisfied: Adafruit-Blinka in ./testing_venv/lib/python3.8/site-packages (from adafruit-circuitpython-rsa) (7.1.0)
Requirement already satisfied: Adafruit-PlatformDetect>=3.13.0 in ./testing_venv/lib/python3.8/site-packages (from Adafruit-Blinka->adafruit-circuitpython-rsa) (3.20.1)
Requirement already satisfied: Adafruit-PureIO>=1.1.7 in ./testing_venv/lib/python3.8/site-packages (from Adafruit-Blinka->adafruit-circuitpython-rsa) (1.1.9)
Requirement already satisfied: pyftdi>=0.40.0 in ./testing_venv/lib/python3.8/site-packages (from Adafruit-Blinka->adafruit-circuitpython-rsa) (0.53.3)
Requirement already satisfied: pyusb!=1.2.0,>=1.0.0 in ./testing_venv/lib/python3.8/site-packages (from pyftdi>=0.40.0->Adafruit-Blinka->adafruit-circuitpython-rsa) (1.2.1)
Requirement already satisfied: pyserial>=3.0 in ./testing_venv/lib/python3.8/site-packages (from pyftdi>=0.40.0->Adafruit-Blinka->adafruit-circuitpython-rsa) (3.5)
Using legacy 'setup.py install' for adafruit-circuitpython-rsa, since package 'wheel' is not installed.
Installing collected packages: adafruit-circuitpython-rsa
  Running setup.py install for adafruit-circuitpython-rsa ... done
Successfully installed adafruit-circuitpython-rsa-1.2.6

It completes successfully, but then if I try to use it:

>>> import adafruit_rsa
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'adafruit_rsa'

At least one problem leading to this is py_modules instead of packages here in the setup.py file:

py_modules=["adafruit_rsa"],

AssertionError: Number must be an unsigned integer, not a float

as discussed in #10, the simpletest for this library fails:

on 5.0

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Generating keypair...
Encrypting message...
Traceback (most recent call last):
  File "code.py", line 16, in <module>
  File "/lib/adafruit_rsa/pkcs1.py", line 173, in encrypt
  File "/lib/adafruit_rsa/transform.py", line 181, in int2bytes
AssertionError: Number must be an unsigned integer, not a float.

and on 4.1.2

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Generating keypair...
Encrypting message...
Traceback (most recent call last):
  File "code.py", line 16, in <module>
  File "/lib/adafruit_rsa/pkcs1.py", line 173, in encrypt
  File "/lib/adafruit_rsa/transform.py", line 177, in int2bytes
AssertionError: Number must be an unsigned integer, not a float.```

Update RTD parameter documentation

This library is missing Sphinx docstring documentation for ReadTheDocs for the functions contained within! See other libraries for examples. Here's a basic example of what is needed in the docstring for each function:

...

def some_function(a: float, b: int) -> Tuple[str, str, str]:
    """This is an explanation of the function

    :param float a: An explanation of parameter a
    :param int b: An explanation of parameter b
    """

...

VerificationError: Verification failed

Here are the 3 that are failing because of a VerificationError I suspect test_sign_verify_fail is also failing. All of the following outputs are from rsa_tests.py:

Testing: <function test_sign_verify_sha256 at 0x20002de0>
7064.67: DEBUG - find_p_q(248): Finding p
7069.36: DEBUG - find_p_q(248): Finding q
Traceback (most recent call last):
  File "code.py", line 102, in <module>
  File "code.py", line 49, in test_sign_verify_sha256
  File "/lib/adafruit_rsa/pkcs1.py", line 329, in verify
VerificationError: Verification failed
Testing: <function test_sign_verify_sha384 at 0x20002e30>
6557.27: DEBUG - find_p_q(312): Finding p
6621.99: DEBUG - find_p_q(312): Finding q
Traceback (most recent call last):
  File "code.py", line 106, in <module>
  File "code.py", line 62, in test_sign_verify_sha384
  File "/lib/adafruit_rsa/pkcs1.py", line 329, in verify
VerificationError: Verification failed
Testing: <function test_sign_verify_sha512 at 0x20002e90>
6816.8: DEBUG - find_p_q(376): Finding p
6871.6: DEBUG - find_p_q(376): Finding q
Traceback (most recent call last):
  File "code.py", line 108, in <module>
  File "code.py", line 73, in test_sign_verify_sha512
  File "/lib/adafruit_rsa/pkcs1.py", line 329, in verify
VerificationError: Verification failed

Missing Type Annotations

There are missing type annotations for some functions in this library.

The typing module does not exist on CircuitPython devices so the import needs to be wrapped in try/except to catch the error for missing import. There is an example of how that is done here:

try:
    from typing import List, Tuple
except ImportError:
    pass

Once imported the typing annotations for the argument type(s), and return type(s) can be added to the function signature. Here is an example of a function that has had this done already:

def wrap_text_to_pixels(
    string: str, max_width: int, font=None, indent0: str = "", indent1: str = ""
) -> List[str]:

If you are new to Git or Github we have a guide about contributing to our projects here: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github

There is also a guide that covers our CI utilities and how to run them locally to ensure they will pass in Github Actions here: https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/check-your-code In particular the pages: Sharing docs on ReadTheDocs and Check your code with pre-commit contain the tools to install and commands to run locally to run the checks.

If you are attempting to resolve this issue and need help, you can post a comment on this issue and tag both @FoamyGuy and @kattni or reach out to us on Discord: https://adafru.it/discord in the #circuitpython-dev channel.

The following locations are reported by mypy to be missing type annotations:

  • adafruit_rsa/machine_size.py:30
  • adafruit_rsa/common.py:14
  • adafruit_rsa/common.py:27
  • adafruit_rsa/common.py:36
  • adafruit_rsa/common.py:66
  • adafruit_rsa/common.py:91
  • adafruit_rsa/common.py:115
  • adafruit_rsa/common.py:139
  • adafruit_rsa/common.py:156
  • adafruit_rsa/_compat.py:34
  • adafruit_rsa/_compat.py:43
  • adafruit_rsa/_compat.py:55
  • adafruit_rsa/_compat.py:67
  • adafruit_rsa/_compat.py:83
  • adafruit_rsa/_compat.py:101
  • adafruit_rsa/pem.py:16
  • adafruit_rsa/pem.py:30
  • adafruit_rsa/pem.py:96
  • adafruit_rsa/core.py:19
  • adafruit_rsa/core.py:38
  • adafruit_rsa/core.py:46
  • adafruit_rsa/core.py:64
  • adafruit_rsa/transform.py:23
  • adafruit_rsa/transform.py:38
  • adafruit_rsa/transform.py:106
  • adafruit_rsa/transform.py:131
  • adafruit_rsa/randnum.py:19
  • adafruit_rsa/randnum.py:40
  • adafruit_rsa/randnum.py:53
  • adafruit_rsa/randnum.py:66
  • adafruit_rsa/pkcs1.py:58
  • adafruit_rsa/pkcs1.py:103
  • adafruit_rsa/pkcs1.py:136
  • adafruit_rsa/pkcs1.py:167
  • adafruit_rsa/pkcs1.py:232
  • adafruit_rsa/pkcs1.py:266
  • adafruit_rsa/pkcs1.py:288
  • adafruit_rsa/pkcs1.py:323
  • adafruit_rsa/pkcs1.py:342
  • adafruit_rsa/pkcs1.py:363
  • adafruit_rsa/pkcs1.py:391
  • adafruit_rsa/prime.py:21
  • adafruit_rsa/prime.py:33
  • adafruit_rsa/prime.py:59
  • adafruit_rsa/prime.py:112
  • adafruit_rsa/prime.py:123
  • adafruit_rsa/prime.py:149
  • adafruit_rsa/prime.py:177
  • adafruit_rsa/key.py:48
  • adafruit_rsa/key.py:53
  • adafruit_rsa/key.py:65
  • adafruit_rsa/key.py:91
  • adafruit_rsa/key.py:116
  • adafruit_rsa/key.py:127
  • adafruit_rsa/key.py:144
  • adafruit_rsa/key.py:161
  • adafruit_rsa/key.py:203
  • adafruit_rsa/key.py:213
  • adafruit_rsa/key.py:217
  • adafruit_rsa/key.py:226
  • adafruit_rsa/key.py:233
  • adafruit_rsa/key.py:277
  • adafruit_rsa/key.py:302
  • adafruit_rsa/key.py:321
  • adafruit_rsa/key.py:370
  • adafruit_rsa/key.py:381
  • adafruit_rsa/key.py:397
  • adafruit_rsa/key.py:401
  • adafruit_rsa/key.py:419
  • adafruit_rsa/key.py:427
  • adafruit_rsa/key.py:443
  • adafruit_rsa/key.py:459
  • adafruit_rsa/key.py:557
  • adafruit_rsa/key.py:583
  • adafruit_rsa/key.py:628
  • adafruit_rsa/key.py:661
  • adafruit_rsa/key.py:696
  • adafruit_rsa/key.py:709
  • adafruit_rsa/key.py:737

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.