def consistency_proofs_benchmark(): # Generate states global TREE TREE = MerkleTree('0-th record', encoding=ENCODING, hash_type=HASH_TYPE) STATES = [] for _ in range(1, LENGTH + 3 * ADDITIONAL): #): STATES.append((TREE.rootHash, TREE.length)) TREE.encryptRecord(bytes('%d-th record' % _, encoding=ENCODING)) STATES.append((TREE.rootHash, TREE.length)) # Generate proofs global PROOFS sys.stdout.write('\nConsistency proofs') START = datetime.now() MAX = None MIN = None TOTAL = 0.0 elapsed = [] for _ in range(TREE.length): # print(_) _oldhash = STATES[_][0] _sublength = STATES[_][1] _cycle = datetime.now() _proof = TREE.consistencyProof(oldhash=_oldhash, sublength=_sublength) _elapsed = _time_elapsed(_cycle) # print(_proof) # print(_) if MAX is None: MIN = MAX = _elapsed else: MAX = max(_elapsed, MAX) MIN = min(_elapsed, MIN) PROOFS.append(_proof) TOTAL += _elapsed elapsed.append(_elapsed) mean, stdev = _mean_value(elapsed, precision_2, with_stdev=True) _show_stats(message='Consistency proofs', total=_quantize(TOTAL, precision_2), min=MIN, max=MAX, mean=mean, stdev=stdev)
encoding=tree.encoding, raw_bytes=tree.raw_bytes, security=tree.security ) ) ) __false_consistency_proofs = [] __true_consistency_proofs = [] for (tree, subtree) in trees_and_subtrees: __false_consistency_proofs.append( ( tree, tree.consistencyProof(b'anything except for the right hash') ) ) __true_consistency_proofs.append( ( tree, tree.consistencyProof(subtree.rootHash) ) ) @pytest.mark.parametrize("tree, consistency_proof", __false_consistency_proofs) def test_false_consistency_validateProof(tree, consistency_proof): assert not validateProof(consistency_proof, tree.rootHash) @pytest.mark.parametrize("tree, consistency_proof", __true_consistency_proofs)
old_hash = b'anything else...' # Subtree-detection configuration if bool_2 and bool_3: old_tree_length = first_log_size elif not bool_2 and bool_3: old_tree_length = first_log_size - 1 else: old_tree_length = second_log_size + first_log_size # Update the tree by appending new log tree.encryptFilePerLog(RED_HAT_LINUX_log) # Generate proof for the above configurations consistency_proofs.append( tree.consistencyProof(old_hash=old_hash, sublength=old_tree_length)) # Target-hash configuration if bool_4: target_hashes.append(tree.rootHash()) else: target_hashes.append(b'anything else...') @pytest.mark.parametrize( 'consistency_proof, target_hash, expected', [(consistency_proofs[i], target_hashes[i], expecteds[i]) for i in range(len(consistency_proofs))]) def test_consistency_proof_validation_for_non_empty_tree( consistency_proof, target_hash, expected): assert validateProof(target_hash=target_hash,