Skip to main content

Blowcurve Encryption Library

Repository: https://www.github.com/origamizyt/blowcurve

Simple library for Blowfish / ECC encryption and digital signatures.

Installation

This library is available on PyPI.

pip install blowcurve

Or you could also install from source code.

python setup.py install

Usage

The Blowcurve class in package root provides all usage. You can initialize it without any parameters to generate random keys: (In fact, this is the only way to create instances.)

>>> from blowcurve import Blowcurve
>>> bc1 = Blowcurve()
>>> bc2 = Blowcurve()

The export method allows you to export the key as DER hex string:

>>> bc1.export()
'3059301306072a8648ce3d020106082a8648ce3d030107034200041c873634bf4b14d555800e33482971ca55e5780e8c109c817adf185919060e414857851ee2bdff18cd76510b80c79f3b11380810e2be9a876765722ed9c7f465'

The load method performs ecdh key exchange with remote services:

>>> bc1.load(bc2.export())
>>> bc2.load(bc1.export())

No error means key exchange was successful.

After key exchange, the sign and encrypt methods are enabled:

>>> signature = bc1.sign(b'data')
>>> bc2.verify(b'data', signature)
True
>>> data = b'mymessage'
>>> bc2.decrypt(bc1.encrypt(data))
b'message'

If no remote key was provided, a MissingRemoteKey exception will be raised:

>>> Blowcurve().encrypt(b'')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "__init__.py", line 41, in encrypt
    ephemeral, key = self._pair.ephemeral()
  File "keys.py", line 94, in ephemeral
    raise MissingRemoteKey
blowcurve.keys.MissingRemoteKey: remote key not loaded yet.
>>> Blowcurve().verify(b'', b'')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "__init__.py", line 38, in verify
    return self._pair.verify(data, signature)
  File "keys.py", line 109, in verify
    raise MissingRemoteKey
blowcurve.keys.MissingRemoteKey: remote key not loaded yet.

The keys module has API for basic signing and ecdh.

>>> from blowcurve.keys import ECKeys
>>> k1 = ECKeys()
>>> k2 = ECKeys()
>>> k1.load(k2.export())
>>> k2.load(k1.export())
>>> k1.secret() == k2.secret()
True
>>> k2.verify(b'data', k1.sign(b'data'))
True

The crypt module has API for encryption and padding.

>>> from blowcurve import crypt
>>> crypt.pkcs5_pad(b'data', 8)
b'data\x04\x04\x04\x04'
>>> crypt.pkcs5_pad(b'mymessage', 16)
b'mymessage\x07\x07\x07\x07\x07\x07\x07'
>>> crypt.pkcs5_unpad(b'data\x04\x04\x04\x04')
b'data'
>>> crypt.pkcs5_unpad(b'incorrect\x01\x02\x03')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "crypt.py", line 41, in pkcs5_unpad
    raise IncorrectPadding
blowcurve.crypt.IncorrectPadding: incorrect padding
>>> data = crypt.encrypt(b'mykey', b'hello, world!')
>>> crypt.decrypt(b'mykey', data)
b'hello, world!'
>>> crypt.decrypt(b'other', data)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "crypt.py", line 71, in decrypt
    return pkcs5_unpad(cipher.decrypt(data))
  File "crypt.py", line 41, in pkcs5_unpad
    raise IncorrectPadding
blowcurve.crypt.IncorrectPadding: incorrect padding

The cause of the exception above is because the incorrect key results in incorrect decrypted data, therefore causing an incorrect padding. (There is chance that this exception won't occur, but the result will still be malformed.)

Testing

The test.py file contains unittest test cases:

$ python -m unittest --verbose blowcurve.test
testEncrypt (blowcurve.test.BlowcurveTestCase) ... ok
testSign (blowcurve.test.BlowcurveTestCase) ... ok
testEncrypt (blowcurve.test.CryptTestCase) ... ok
testPad (blowcurve.test.CryptTestCase) ... ok
testNoRemoteKey (blowcurve.test.KeysTestCase) ... ok
testSecret (blowcurve.test.KeysTestCase) ... ok
testSign (blowcurve.test.KeysTestCase) ... ok

----------------------------------------------------------------------
Ran 7 tests in 0.179s

OK

Metadata

Release files for blowcurve 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for blowcurve 1.0.0
File Size Uploaded
blowcurve-1.0.0.tar.gz 6.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for blowcurve 1.0.0
File Interpreter ABI Platform
blowcurve-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.7 kB

Release files / blowcurve-1.0.0.tar.gz

Download URL blowcurve-1.0.0.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
51c74ed61ab14d2fd2bcf3079cdb6f2932d6f8ff08540ed32211b228d6c6b4f6
BLAKE2b-256 checksum
How to use checksums
886a4997ec317676e6b89d8aada7dd7cf35ae3b34d4588aa2f90793467c58d87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.24.0 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

Release files / blowcurve-1.0.0-py3-none-any.whl

Download URL blowcurve-1.0.0-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
299dc80155f2fa1222aa0c2f3fdd06db77d5e252245aa0b8edd73a53af75b00a
BLAKE2b-256 checksum
How to use checksums
fe901bc7df2b4c0446619b485b590d5a9af4764f5e6875948661bf085491b9b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.24.0 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page