MCPcopy Index your code
hub / github.com/Bitmessage/PyBitmessage / decrypt

Method decrypt

src/pyelliptic/ecc.py:463–480  ·  view source on GitHub ↗

Decrypt data with ECIES method using the local private key

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

Source from the content-addressed store, hash-verified

461 return ciphertext + mac
462
463 def decrypt(self, data, ciphername='aes-256-cbc'):
464 """
465 Decrypt data with ECIES method using the local private key
466 """
467 blocksize = OpenSSL.get_cipher(ciphername).get_blocksize()
468 iv = data[:blocksize]
469 i = blocksize
470 curve, pubkey_x, pubkey_y, i2 = ECC._decode_pubkey(data[i:])
471 i += i2
472 ciphertext = data[i:len(data)-32]
473 i += len(ciphertext)
474 mac = data[i:]
475 key = sha512(self.raw_get_ecdh_key(pubkey_x, pubkey_y)).digest()
476 key_e, key_m = key[:32], key[32:]
477 if not equals(hmac_sha256(key_m, data[:len(data) - 32]), mac):
478 raise RuntimeError("Fail to verify data")
479 ctx = Cipher(key_e, iv, 0, ciphername)
480 return ctx.ciphering(ciphertext)

Callers 6

processmsgMethod · 0.80
processbroadcastMethod · 0.80
decryptFunction · 0.80
decryptFastFunction · 0.80

Calls 8

raw_get_ecdh_keyMethod · 0.95
cipheringMethod · 0.95
equalsFunction · 0.90
hmac_sha256Function · 0.90
CipherClass · 0.90
get_cipherMethod · 0.80
_decode_pubkeyMethod · 0.80
get_blocksizeMethod · 0.45

Tested by

no test coverage detected