forked from stepchowfun/hashpass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hashpass_diceware.html
230 lines (209 loc) · 7.92 KB
/
hashpass_diceware.html
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<!doctype html>
<html>
<head>
<title>Hashpass + Diceware</title>
<style type="text/css">
html {
margin: 0;
padding: 0;
}
body {
margin: 0;
padding: 0;
width: 332px;
font-family: sans-serif;
font-size: 0.9em;
color: #333;
}
.input {
display: block;
box-sizing: border-box;
width: 300px;
height: 40px;
border: 2px solid #ddd;
border-radius: 2px;
padding: 8px 12px;
margin: 16px;
outline-style: none;
line-height: 20px;
font-family: monospace;
font-size: 1.2em;
color: inherit;
}
.textarea {
display: block;
box-sizing: border-box;
width: 700px;
height: 1200px;
border: 2px solid #ddd;
border-radius: 2px;
padding: 8px 12px;
margin: 16px;
outline-style: none;
line-height: 20px;
font-family: monospace;
font-size: 1.0em;
color: inherit;
}
input:focus {
border-color: #f872ae;
}
input, p {
margin: 16px;
}
.small-top-margin {
margin-top: 4px;
}
.small-bottom-margin {
margin-bottom: 4px;
}
.disabled {
color: #000;
background-color: #eee;
}
.error {
color: #c00;
}
</style>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="sjcl.js"></script>
<script type="text/javascript" src="hashpass_diceware_eff_large_wordlist.js"></script>
<script type="text/javascript">
// The hashing difficulty.
// 2 ^ difficulty rounds of SHA-256 will be computed.
var difficulty = 16;
var transform = function(domain, key) {
// Compute the first 16 base64 characters of iterated-SHA-256(domain + '/' + key, 2 ^ difficulty).
var rounds = Math.pow(2, difficulty);
var bits = domain + '/' + key;
for (var i = 0; i < rounds; i += 1) {
bits = sjcl.hash.sha256.hash(bits);
}
var hash = sjcl.codec.base64.fromBits(bits).slice(0, 16);
return hash;
};
var show_password = function() {
if ($('#showpasswd').get(0).checked) {
$('#keyplaintext').val($('#key').val());
} else {
$('#keyplaintext').val("");
}
}
var update = function() {
var key = $('#key').val();
var domain = $('#domain').val();
var hash = transform(domain, key)
$('#hash').val(hash);
var check = ("S79jGLaGcHEjmfWe" === transform("d", "k"));
if (!check) {
var msg = "Unknown error, cannot compute values, might be a bug in browser's javascript engine?";
$('#hash').val(msg);
$('#diceware').val(msg);
}
};
var param_i = -1;
var max_i = 40;
var already_running = false;
var all_dice_nums = [];
var key_for_diceware_use = "";
var domain_for_diceware_use = "";
var update_diceware = function() {
if (param_i == -1) {
already_running = true;
all_dice_nums = [];
var key = $('#key').val();
key_for_diceware_use = key;
var domain = $('#domain').val();
domain_for_diceware_use = domain;
update();
$('#diceware').val("");
param_i++;
setTimeout(update_diceware, 50);
} else if (param_i < max_i) {
var key = key_for_diceware_use;
var domain = domain_for_diceware_use;
var i = param_i;
key_i = "" + key + i.toString();
passwd_i = transform(domain, key_i);
$('#diceware').get(0).value += "counter = " + i.toString();
if ($('#showpasswd').get(0).checked) {
$('#diceware').get(0).value += ", key = " + key_i;
}
$('#diceware').get(0).value += ", pwd = " + passwd_i;
var num_in_passwd_i = [];
for (var j = 0; j < passwd_i.length; j++) {
current_char = passwd_i.charAt(j);
is_number = ! isNaN(current_char);
if (is_number) {
num_in_passwd_i.push(current_char);
}
}
$('#diceware').get(0).value += ", numbers = " + num_in_passwd_i.toString() + "\n";
var dice_nums = [];
for (var j = 0; j < num_in_passwd_i.length; j++) {
num = parseInt(num_in_passwd_i[j]);
if ((num <= 6) && (num > 0)) {
dice_nums.push(num);
all_dice_nums.push(num);
}
}
param_i++;
setTimeout(update_diceware, 50);
} else {
$('#diceware').get(0).value += "diceware numbers: ";
$('#diceware').get(0).value += all_dice_nums.toString() + "\n";
$('#diceware').get(0).value += "diceware numbers by groups of 5:" + "\n";
var curr_group = "";
var words = [];
var print_curr_group = function(curr_group) {
var key = "x" + curr_group;
if (key in eff_large_wordlist) {
$('#diceware').get(0).value += "" + curr_group + " " + eff_large_wordlist["x" + curr_group] + "\n";
words.push(eff_large_wordlist["x" + curr_group]);
} else {
$('#diceware').get(0).value += "" + curr_group + "\n";
}
};
for (var i = 0; i < all_dice_nums.length; i++) {
if (curr_group.length < 5) {
curr_group += all_dice_nums[i].toString();
} else {
print_curr_group(curr_group);
curr_group = "";
}
}
if (curr_group.length > 0) {
print_curr_group(curr_group);
}
$('#diceware').get(0).value += words.join(" ") + "\n";
param_i = -1;
key_for_diceware_use = "";
domain_for_diceware_use = "";
already_running = false;
}
};
var start_update_diceware = function() {
if (already_running) {
return;
} else {
update_diceware();
}
};
</script>
</head>
<body>
<p class="small-bottom-margin">Show key: <input id="showpasswd" type="checkbox" checked onclick="show_password();" onchange="show_password();" /> </p>
<p class="small-bottom-margin">Domain:</p>
<input id="domain" class="input small-top-margin" type="text"/>
<p class="small-bottom-margin">Key:</p>
<input id="keyplaintext" class="input small-top-margin disabled" type="text" readonly="true"/>
<input id="key" class="input small-top-margin" type="password" onkeydown="show_password();" onkeyup="show_password();" onclick="show_password();" onchange="show_password();"/>
<p class="small-bottom-margin">Hash:</p>
<input id="hash" class="input small-top-margin disabled" type="text" readonly="true"/>
<input type="button" class="input" value="calculate hash" onclick="update();" />
<input type="button" class="input" value="calculate diceware (slow!)" onclick="start_update_diceware();" />
<p class="small-bottom-margin">Diceware data:</p>
<textarea id="diceware" class="textarea small-top-margin disabled" rows="55" cols="100" readonly="true" ></textarea>
<p id="message"> </p>
</body>
</html>