From 0e18bb97107e945874a6cfa61042ee960f3fd766 Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 23 Nov 2017 00:16:55 +0100 Subject: Analysis script: * dumps diffs between successive hashes, in hex, for full 160 bits of output hash and for the used 96-bit portion * counts how many bits differ * charts the diffusion distribution against theoretical distribution --- analyze.py | 44 +++++++++++++++++++++++++++++++++++++ results-original/multiple.dump.png | Bin 0 -> 111140 bytes results-original/single.dump.png | Bin 0 -> 111872 bytes results-patched/multiple.dump.png | Bin 0 -> 100256 bytes results-patched/single.dump.png | Bin 0 -> 99936 bytes 5 files changed, 44 insertions(+) create mode 100644 analyze.py create mode 100644 results-original/multiple.dump.png create mode 100644 results-original/single.dump.png create mode 100644 results-patched/multiple.dump.png create mode 100644 results-patched/single.dump.png diff --git a/analyze.py b/analyze.py new file mode 100644 index 0000000..75d8686 --- /dev/null +++ b/analyze.py @@ -0,0 +1,44 @@ +import gmpy, numpy, scipy.misc, sys +import matplotlib.pyplot as plot + +input_file = file(sys.argv[1]) + +ideal_hash_diffusion = [int(scipy.misc.comb(160, n)) for n in range(0, 161)] +hash_diffusion = [0] * 161 +ideal_deal_diffusion = [int(scipy.misc.comb(96, n)) for n in range(0, 97)] +deal_diffusion = [0] * 97 + +prev_seed = None +prev_output = 0 +prev_deal = 0 + +for line in input_file: + bits = line.split() + output = int(bits[1], 16) + seed = bits[0][8:48] + deal = output & 0xFFFFFFFFFFFFFFFFFFFFFFFF0000000000000000 + if seed == prev_seed: + results = [output ^ prev_output, deal ^ prev_deal] + results += [gmpy.popcount(l) for l in results] + hash_diffusion[results[2]] += 1 + deal_diffusion[results[3]] += 1 + print '%040x %040x %3d %3d' % tuple(results) + prev_output = output + prev_deal = deal + prev_seed = seed + +ideal_hash_diffusion_normalized = [float(n)/sum(ideal_hash_diffusion) for n in ideal_hash_diffusion] +hash_diffusion_normalized = [float(n)/sum(hash_diffusion) for n in hash_diffusion] +ideal_deal_diffusion_normalized = [float(n)/sum(ideal_deal_diffusion) for n in ideal_deal_diffusion] +deal_diffusion_normalized = [float(n)/sum(deal_diffusion) for n in deal_diffusion] + +figure = plot.figure(figsize=(20,20)) +hash_plot = figure.add_subplot(211, title='Full hash diffusion') +hash_plot.plot(ideal_hash_diffusion_normalized) +hash_plot.plot(hash_diffusion_normalized) +hash_plot.legend(['Ideal', 'Actual']) +deal_plot = figure.add_subplot(212, title='96-bit deal diffusion') +deal_plot.plot(ideal_deal_diffusion_normalized) +deal_plot.plot(deal_diffusion_normalized) +deal_plot.legend(['Ideal', 'Actual']) +figure.savefig(sys.argv[1] + '.png') diff --git a/results-original/multiple.dump.png b/results-original/multiple.dump.png new file mode 100644 index 0000000..f07bcfb Binary files /dev/null and b/results-original/multiple.dump.png differ diff --git a/results-original/single.dump.png b/results-original/single.dump.png new file mode 100644 index 0000000..848a6e2 Binary files /dev/null and b/results-original/single.dump.png differ diff --git a/results-patched/multiple.dump.png b/results-patched/multiple.dump.png new file mode 100644 index 0000000..beb9c68 Binary files /dev/null and b/results-patched/multiple.dump.png differ diff --git a/results-patched/single.dump.png b/results-patched/single.dump.png new file mode 100644 index 0000000..dd8fce1 Binary files /dev/null and b/results-patched/single.dump.png differ -- cgit v1.2.3