-
Notifications
You must be signed in to change notification settings - Fork 6
/
debug-helper.py
100 lines (86 loc) · 3.09 KB
/
debug-helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#! /usr/bin/env python
# debug-helper.py - generate test data for the Fortuna implementation in Go
# Copyright (C) 2013 Jochen Voss <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This script uses the "Python Cryptography Toolkit" from
# https://www.dlitz.net/software/pycrypto/ to generate reference data
# for inclusion in "generator_test.go"
import sys
import time
from Crypto.Random.Fortuna.FortunaGenerator import AESGenerator
from Crypto.Random.Fortuna.FortunaAccumulator import FortunaAccumulator
######################################################################
# part 1: test data for AESGenerator
rng = AESGenerator()
rng.reseed("\1\2\3\4")
sys.stdout.write("\tcorrect := []byte{")
for i, x in enumerate(rng.pseudo_random_data(100)):
if i % 15 == 0:
sys.stdout.write("\n\t\t")
else:
sys.stdout.write(" ")
sys.stdout.write("%d,"%ord(x))
sys.stdout.write("\n\t}\n")
sys.stdout.write("\tcorrect = []byte{")
for i, x in enumerate(rng.pseudo_random_data((1<<20) + 100)[-100:]):
if i % 15 == 0:
sys.stdout.write("\n\t\t")
else:
sys.stdout.write(" ")
sys.stdout.write("%d,"%ord(x))
sys.stdout.write("\n\t}\n")
rng.reseed("\5")
sys.stdout.write("\tcorrect = []byte{")
for i, x in enumerate(rng.pseudo_random_data(100)):
if i % 15 == 0:
sys.stdout.write("\n\t\t")
else:
sys.stdout.write(" ")
sys.stdout.write("%d,"%ord(x))
sys.stdout.write("\n\t}\n\n\n")
######################################################################
# part 2: test data for FortunaAccumulator
acc = FortunaAccumulator()
acc.add_random_event(0, 0, "\0"*32)
acc.add_random_event(0, 0, "\0"*32)
for i in range(1000):
acc.add_random_event(1, i%32, "\1\2")
sys.stdout.write("\tcorrect := []byte{")
for i, x in enumerate(acc.random_data(100)):
if i % 15 == 0:
sys.stdout.write("\n\t\t")
else:
sys.stdout.write(" ")
sys.stdout.write("%d,"%ord(x))
sys.stdout.write("\n\t}\n")
acc.add_random_event(0, 0, "\0"*32)
acc.add_random_event(0, 0, "\0"*32)
sys.stdout.write("\tcorrect = []byte{")
for i, x in enumerate(acc.random_data(100)):
if i % 15 == 0:
sys.stdout.write("\n\t\t")
else:
sys.stdout.write(" ")
sys.stdout.write("%d,"%ord(x))
sys.stdout.write("\n\t}\n")
time.sleep(0.2)
sys.stdout.write("\tcorrect = []byte{")
for i, x in enumerate(acc.random_data(100)):
if i % 15 == 0:
sys.stdout.write("\n\t\t")
else:
sys.stdout.write(" ")
sys.stdout.write("%d,"%ord(x))
sys.stdout.write("\n\t}\n")