pybitmessage.pyelliptic package

Copyright (C) 2010 Author: Yann GUIBET Contact: <>

Python OpenSSL wrapper. For modern cryptography with ECC, AES, HMAC, Blowfish, …

This is an abandoned package maintained inside of the PyBitmessage.

class ECC(pubkey=None, privkey=None, pubkey_x=None, pubkey_y=None, raw_privkey=None, curve='sect283r1')[source]

Bases: object

Asymmetric encryption with Elliptic Curve Cryptography (ECC) ECDH, ECDSA and ECIES

>>> from binascii import hexlify
>>> import pyelliptic
>>> alice = pyelliptic.ECC() # default curve: sect283r1
>>> bob = pyelliptic.ECC(curve='sect571r1')
>>> ciphertext = alice.encrypt("Hello Bob", bob.get_pubkey())
>>> print(bob.decrypt(ciphertext))
>>> signature = bob.sign("Hello Alice")
>>> # alice's job :
>>> print(pyelliptic.ECC(
>>>     pubkey=bob.get_pubkey()).verify(signature, "Hello Alice"))
>>> # ERROR !!!
>>> try:
>>>     key = alice.get_ecdh_key(bob.get_pubkey())
>>> except:
>>>     print(
            "For ECDH key agreement, the keys must be defined"
            " on the same curve!")
>>> alice = pyelliptic.ECC(curve='sect571r1')
>>> print(hexlify(alice.get_ecdh_key(bob.get_pubkey())))
>>> print(hexlify(bob.get_ecdh_key(alice.get_pubkey())))
static get_curves()

Static method, returns the list of all the curves available


The name of currently used curve


Currently used curve


High level function which returns : curve(2) + len_of_pubkeyX(2) + pubkeyX + len_of_pubkeyY + pubkeyY


High level function which returns curve(2) + len_of_privkey(2) + privkey


High level function. Compute public key with the local private key and returns a 512bits shared key.

raw_get_ecdh_key(pubkey_x, pubkey_y)

ECDH key as binary data

check_key(privkey, pubkey)

Check the public key and the private key. The private key is optional (replace by None).

raw_check_key(privkey, pubkey_x, pubkey_y, curve=None)

Check key validity, key is supplied as binary data

sign(inputb, digest_alg=<_FuncPtr object>)

Sign the input with ECDSA method and returns the signature

verify(sig, inputb, digest_alg=<_FuncPtr object>)

Verify the signature with the input and the local public key. Returns a boolean.

static encrypt(data, pubkey, ephemcurve=None, ciphername='aes-256-cbc')

Encrypt data with ECIES method using the public key of the recipient.

static raw_encrypt(data, pubkey_x, pubkey_y, curve='sect283r1', ephemcurve=None, ciphername='aes-256-cbc')

ECDH encryption, keys supplied in binary data format

decrypt(data, ciphername='aes-256-cbc')

Decrypt data with ECIES method using the local private key

class ECCBlind(curve='secp256k1', pubkey=None, privkey=None, year=2025, month=11, value=255)[source]

Bases: object

Class for ECC blind signature functionality

k = None
R = None
F = None
a = None
b = None
c = None
binv = None
r = None
m = None
m_ = None
s_ = None
signature = None
exp = None
val = None

Random integer within the EC order


ECC inversion


Generate an ECC keypair We’re using compressed keys


x0 coordinate of F


Make a private key into a string


Make a pubkey into a string

d = None
Q = None

Init signer

create_signing_request(R, msg)

Requester creates a new signing request


Signer blind-signs the request


Requester unblinds the signature

verify(msg, signature, value=1)

Verify signature with certifier’s pubkey

class ECCBlindChain(ca=None, chain=None)[source]

Bases: object

# Class for ECC Blind Chain signature functionality

verify(msg, value)

Verify a chain provides supplied message and value

class Cipher(key, iv, do, ciphername='aes-256-cbc')[source]

Bases: object

Main class for encryption

import pyelliptic iv = pyelliptic.Cipher.gen_IV(‘aes-256-cfb’) ctx = pyelliptic.Cipher(“secretkey”, iv, 1, ciphername=’aes-256-cfb’) ciphertext = ctx.update(‘test1’) ciphertext += ctx.update(‘test2’) ciphertext +=

ctx2 = pyelliptic.Cipher(“secretkey”, iv, 0, ciphername=’aes-256-cfb’) print ctx2.ciphering(ciphertext)

static get_all_cipher()

static method, returns all ciphers available

static get_blocksize(ciphername)

This Method returns cipher blocksize

static gen_IV(ciphername)

Generate random initialization vector


Update result with more data


Returning the final value


Do update and final in one method

hmac_sha256(k, m)[source]

Compute the key and the message with HMAC SHA5256

hmac_sha512(k, m)[source]

Compute the key and the message with HMAC SHA512

pbkdf2(password, salt=None, i=10000, keylen=64)[source]

Key derivation function using SHA256