Move hash_data to the crypto module

This commit is contained in:
vrde 2016-03-03 02:02:17 +01:00
parent 2bafabdfe2
commit 1475a3cbb1
4 changed files with 13 additions and 10 deletions

View File

@ -331,7 +331,7 @@ class Bigchain(object):
# Calculate the hash of the new block
block_data = util.serialize(block)
block_hash = util.hash_data(block_data)
block_hash = crypto.hash_data(block_data)
block_signature = crypto.PrivateKey(self.me_private).sign(block_data)
block = {
@ -357,7 +357,7 @@ class Bigchain(object):
"""
# 1. Check if current hash is correct
calculated_hash = util.hash_data(util.serialize(block['block']))
calculated_hash = crypto.hash_data(util.serialize(block['block']))
if calculated_hash != block['id']:
raise exceptions.InvalidHash()

View File

@ -2,6 +2,8 @@
import binascii
import base58
import sha3
import bitcoin
from cryptography.hazmat.backends import default_backend
@ -144,3 +146,10 @@ def generate_key_pair():
return (private_value_base58, public_value_compressed_base58)
def hash_data(data):
"""Hash the provided data using SHA3-256"""
return sha3.sha3_256(data.encode()).hexdigest()

View File

@ -1,4 +1,3 @@
import sha3
import json
import time
@ -7,7 +6,7 @@ from datetime import datetime
import bigchaindb
from bigchaindb import exceptions
from bigchaindb.crypto import PrivateKey, PublicKey
from bigchaindb.crypto import PrivateKey, PublicKey, hash_data
class ProcessGroup(object):
@ -158,10 +157,6 @@ def create_and_sign_tx(private_key, current_owner, new_owner, tx_input, operatio
return sign_tx(tx, private_key)
def hash_data(data):
return sha3.sha3_256(data.encode()).hexdigest()
def check_hash_and_signature(transaction):
# Check hash of the transaction
calculated_hash = hash_data(serialize(transaction['transaction']))

View File

@ -8,8 +8,7 @@ import rethinkdb as r
import bigchaindb
from bigchaindb import util
from bigchaindb import exceptions
from bigchaindb.crypto import PrivateKey, PublicKey, generate_key_pair
from bigchaindb.util import hash_data
from bigchaindb.crypto import PrivateKey, PublicKey, generate_key_pair, hash_data
from bigchaindb.voter import Voter
from bigchaindb.block import Block