def test_run_module(self): import sha3 print('Ok imported pysha3, testing some basic operations...') k = sha3.keccak_512() k.update(b"data") print('Test pysha3 operation (keccak_512): {}'.format(k.hexdigest()))
def map_to_point(self, m): h = sha3.keccak_512() h.update(m) hm = h.hexdigest() hint = ZZ("0x" + hm) y0 = self.dp.Fp(hint) exp = ((2 * self.dp.p - 1) / 3) x0 = (y0**2 - 3)**exp return self.dp.E1(x0, y0) * Integer(self.dp.c)
def keccak512(buffer: Bytes) -> Hash64: """ Computes the keccak512 hash of the input `buffer`. Parameters ---------- buffer : Input for the hashing function. Returns ------- hash : `eth1spec.eth_types.Hash32` Output of the hash function. """ return sha3.keccak_512(buffer).digest()
def main(mountpoint, root): pw = ''.join(open(root + ".password").read().split('\n')) print(bcolors.WARNING + "Insert master password to start the mounting operation: " + bcolors.ENDC) masterpassword = getpass() mphashed = sha3.keccak_512(masterpassword.encode('utf_8')).hexdigest() if pw == mphashed: print(bcolors.OKGREEN + "Password accepted, filesystem mounted" + bcolors.ENDC) FUSE(Passthrough(root, mountpoint, masterpassword), mountpoint, nothreads=True, foreground=True) else: print(bcolors.FAIL + "Masterpassword sbagliata" + bcolors.ENDC)
def write_image_body(output_image, inputs, lengths): """ Write body to output image, and the hash of the body to the header of the output image. Arguments: - output_image: output image file -> (file object) - inputs: list of input files -> (list of string) - lengths: list of lengths of each input file -> (list of int) Returns: SHA-3 hash digest (string) """ # Compute Keccak 512 (slight variation on SHA-3) k = sha3.keccak_512() # Write each input file to output image while computing hash in parallel for each, length in zip(inputs, lengths): with open(each, 'rb') as f: # Read 1024 bytes from input file and write to output file # Keep reading until EOF block = f.read(1024) while block: # Write block to output image output_image.write(block) # Update hash computation with the block contents k.update(block) # Read next block block = f.read(1024) # Append some bytes at the end for hash calculation if not multiple # of 64 bytes; pad with 0xFF at the end last_block_size = sum(lengths) % 64 if last_block_size != 0: k.update(b'\xFF' * (64 - last_block_size)) # Seek back to hash position and write hash to output file num_lengths = len(lengths) * 4 output_image.seek(1 + num_lengths) output_image.write(k.digest()) return k.hexdigest()
def sha3_512(x): return hash_words(lambda v: sha3.keccak_512(v).digest(), 64, x)
try: from M2Crypto import * status_import_m2crypto = 'Success' except ImportError as e5: print('**************************') print('Unable to import M2Crypto:\n{}'.format(e5)) print('**************************\n') status_import_m2crypto = 'Error' # Test pysha3 try: import sha3 print('Ok imported pysha3, testing some basic operations...') k = sha3.keccak_512() k.update(b"data") print('Test pysha3 operation (keccak_512): {}'.format(k.hexdigest())) status_import_pysha3 = 'Success' except ImportError as e6: print('**************************') print('Unable to import/operate with pysha3:\n{}'.format(e6)) print('**************************') status_import_pysha3 = 'Error' # Test pycryptodome try: from Crypto.PublicKey import RSA print('Ok imported pycryptodome, testing some basic operations...') secret_code = "Unguessable"
def hash_words(h, sz, x): if isinstance(x, list): x = serialize_hash(x) y = h(x) return deserialize_hash(y) """ def sha3_512(x): return hash_words(lambda v: sha3.sha3_512(v).digest(), 64, x) def sha3_256(x): return hash_words(lambda v: sha3.sha3_256(v).digest(), 32, x) """ sha3_512 = lambda v: sha3.keccak_512(v).digest() sha3_256 = lambda v: sha3.keccak_256(v).digest() print(len(mining_hash + block['nonce'])) s = sha3_512(mining_hash + block['nonce'][::-1]) print(len(s)) print(s, block['mixHash'], block['nonce']) #print(deserialize_hash(block['mixHash'])) print(len(s + block['mixHash'])) hh = sha3_256(s + block['mixHash']) #hh = keccak(keccak(mining_hash+block['nonce']+block['mixHash'])) print("have: ", big_endian_to_int(hh)) print("needed:", 2**256 // block['difficulty']) print("smaller?") print(encode_hex(hh))
def Hint_hash(m): h = keccak_512(m).digest() # return sum(2 ** i * bit(h, i) for i in range(2 * B)) # sum(2 ** i * bit(h, i) for i in range(0, 512)) == int.from_bytes(h, 'little') return int.from_bytes(h, 'little')
def to_hash(m): return keccak_512(m).digest()
def test_hashlib_sha3(self): import hashlib import sha3 self.assertIsNotNone(hashlib.sha3_512()) self.assertIsNotNone(sha3.keccak_512())
try: from M2Crypto import * status_import_m2crypto = 'Success' except ImportError as e5: print('**************************') print('Unable to import M2Crypto:\n{}'.format(e5)) print('**************************\n') status_import_m2crypto = 'Error' # Test pysha3 try: import sha3 print('Ok imported pysha3, testing some basic operations...') k = sha3.keccak_512() k.update(b"data") print('Test pysha3 operation (keccak_512): {}'.format(k.hexdigest())) status_import_pysha3 = 'Success' except ImportError as e6: print('**************************') print('Unable to import/operate with pysha3:\n{}'.format(e6)) print('**************************') status_import_pysha3 = 'Error' # Test pycryptodome try: from Crypto.PublicKey import RSA print('Ok imported pycryptodome, testing some basic operations...') secret_code = "Unguessable"
print(sys.version_info) s = sha3.sha3_512() data_ = b"data" s.update(data_) hexdigest = s.hexdigest() print('sha3_512') print(hexdigest) print() assert ( 'ceca4daf960c2bbfb4a9edaca9b8137a801b65bae377e0f534ef9141c8684c0fedc1768d1afde9766572846c42b935f61177eaf97d355fa8dc2bca3fecfa754d' == hexdigest) s = sha3.keccak_512() s.update(data_) hexdigest = s.hexdigest() print("keccak_512") print(hexdigest) print() assert ( '1065aceeded3a5e4412e2187e919bffeadf815f5bd73d37fe00d384fe29f55f08462fdabe1007b993ce5b8119630e7db93101d9425d6e352e22ffe3dcb56b825' == hexdigest) fd = open("../../report_wolfway.pdf", "rb") s1 = sha3.sha3_512() s2 = sha3.keccak_512() chunk = True while chunk != b'':
import sys import sha3 print(sys.version_info) s = sha3.sha3_512() data_ = b"data" s.update(data_) hexdigest = s.hexdigest() print('sha3_512') print(hexdigest) print() assert ('ceca4daf960c2bbfb4a9edaca9b8137a801b65bae377e0f534ef9141c8684c0fedc1768d1afde9766572846c42b935f61177eaf97d355fa8dc2bca3fecfa754d' == hexdigest) s = sha3.keccak_512() s.update(data_) hexdigest = s.hexdigest() print("keccak_512") print(hexdigest) print() assert ('1065aceeded3a5e4412e2187e919bffeadf815f5bd73d37fe00d384fe29f55f08462fdabe1007b993ce5b8119630e7db93101d9425d6e352e22ffe3dcb56b825' == hexdigest) fd = open("../../report_wolfway.pdf", "rb") s1 = sha3.sha3_512() s2 = sha3.keccak_512() chunk = True while chunk != b'': chunk = fd.read(2 ** 20) s1.update(chunk)
def Hint_hash(m): h = keccak_512(m).digest() return sum(2**i * bit(h, i) for i in range(2 * B))