pybitmessage.pyelliptic package¶
Copyright (C) 2010 Author: Yann GUIBET Contact: <yannguibet@gmail.com>
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
>>> 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 alice.get_ecdh_key(bob.get_pubkey()).encode('hex') >>> print bob.get_ecdh_key(alice.get_pubkey()).encode('hex')
-
check_key
(privkey, pubkey)¶ Check the public key and the private key. The private key is optional (replace by None)
-
decrypt
(data, ciphername='aes-256-cbc')¶ Decrypt data with ECIES method using the local private key
-
static
encrypt
(data, pubkey, ephemcurve=None, ciphername='aes-256-cbc')¶ Encrypt data with ECIES method using the public key of the recipient.
-
get_curve
()¶ Encryption object from curve name
-
get_curve_id
()¶ Currently used curve
-
static
get_curves
()¶ static method, returns the list of all the curves available
-
get_ecdh_key
(pubkey)¶ High level function. Compute public key with the local private key and returns a 512bits shared key
-
get_privkey
()¶ High level function which returns curve(2) + len_of_privkey(2) + privkey
-
get_pubkey
()¶ High level function which returns : curve(2) + len_of_pubkeyX(2) + pubkeyX + len_of_pubkeyY + pubkeyY
-
raw_check_key
(privkey, pubkey_x, pubkey_y, curve=None)¶ Check key validity, key is supplied as binary data
-
static
raw_encrypt
(data, pubkey_x, pubkey_y, curve='sect283r1', ephemcurve=None, ciphername='aes-256-cbc')¶ ECHD encryption, keys supplied in binary data format
-
raw_get_ecdh_key
(pubkey_x, pubkey_y)¶ ECDH key 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
-
-
class
ECCBlind
(curve='secp256k1', pubkey=None)[source]¶ Bases:
object
Class for ECC blind signature functionality
-
F
= None¶
-
Q
= None¶
-
R
= None¶
-
a
= None¶
-
b
= None¶
-
binv
= None¶
-
blind_sign
(m_)¶ Signer blind-signs the request
-
c
= None¶
-
create_signing_request
(R, msg)¶ Requester creates a new signing request
-
static
ec_Ftor
(F, group, ctx)¶ x0 coordinate of F
-
static
ec_gen_keypair
(group, ctx)¶ Generate an ECC keypair
-
static
ec_get_random
(group, ctx)¶ Random point from finite field
-
static
ec_invert
(group, a, ctx)¶ ECC inversion
-
k
= None¶
-
keypair
= None¶
-
m
= None¶
-
m_
= None¶
-
r
= None¶
-
s_
= None¶
-
signature
= None¶
-
signer_init
()¶ Init signer
-
unblind
(s_)¶ Requester unblinds the signature
-
verify
(msg, signature)¶ Verify signature with certifier’s pubkey
-
-
class
Cipher
(key, iv, do, ciphername='aes-256-cbc')[source]¶ Bases:
object
Symmetric 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 += ctx.final()
ctx2 = pyelliptic.Cipher(“secretkey”, iv, 0, ciphername=’aes-256-cfb’) print ctx2.ciphering(ciphertext)
-
ciphering
(input)¶ Do update and final in one method
-
final
()¶ Returning the final value
-
static
gen_IV
(ciphername)¶ Generate random initialization vector
-
static
get_all_cipher
()¶ static method, returns all ciphers available
-
static
get_blocksize
(ciphername)¶ This Method returns cipher blocksize
-
update
(input)¶ Update result with more data
-