-
Notifications
You must be signed in to change notification settings - Fork 0
/
hashcalc.html
802 lines (677 loc) · 30.3 KB
/
hashcalc.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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
<html>
<head>
<title>VPN password hash calculator</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>VPN password hash calculator</h1>
<script type="text/javascript">
// Settings
var OrgSalt = "Please replace this value with unique long random string! E.g.: NYLVfq7kKUc9Aj7KtddMs7ECZV3dloBYRN2wTQigMlQfmoyHqu";
var MinLength = 10;
var scryptNLog2 = 17;
// Code starts here
function calculate() {
document.calculator.hash.value = "";
document.calculator.line.value = "";
if(document.calculator.pass.value != document.calculator.pass2.value) {
alert("Both passwords must match.");
return;
}
if(document.calculator.user.value.trim().length < 1) {
alert("Username must NOT be empty.");
return;
}
if(!document.calculator.user.value.trim().match(/^[A-Za-z0-9_\-\.@]+$/g)) {
alert("Username can contain only: \n* letters, \n* digits, \n* characters: _ - . @\n\nUsername cannot contain space character.");
return;
}
var passtocheck = document.calculator.pass.value.trim();
for (var i = 0; i < passtocheck.length; ++i) {
if(passtocheck.charCodeAt(i) < 32 || passtocheck.charCodeAt(i) > 126) {
alert("Password can contain only ASCII characters. \nI.e. letters with diacritical marks (and some other characters) cannot be used.");
return;
}
}
if(document.calculator.pass.value.trim().length < MinLength) {
alert("Password must be at least "+MinLength+" characters long (leading/trailing spaces are removed).");
return;
}
document.calculator.user.readOnly = true;
document.calculator.pass.readOnly = true;
document.calculator.pass2.readOnly = true;
document.calculator.submit.disabled = true;
try {
scrypt(StringToBytesArray(document.calculator.pass.value.trim()+OrgSalt), StringToBytesArray(document.calculator.user.value.trim().toLowerCase()), Math.pow(2, scryptNLog2), 8, 1, 32, function(error, progress, key) {
if (error) {
throw error;
} else if (key) {
var hexkey = "";
for (var i = 0; i < key.length; ++i) {
if(key[i] < 16) hexkey += "0";
hexkey += key[i].toString(16);
}
document.calculator.hash.value = hexkey;
document.calculator.line.value = document.calculator.user.value.trim().toLowerCase()+" "+hexkey;
document.calculator.user.readOnly = false;
document.calculator.pass.readOnly = false;
document.calculator.pass2.readOnly = false;
document.calculator.submit.disabled = false;
} else {
document.calculator.hash.value = Math.floor(progress*100)+"% completed";
}
});
} catch (e) {
document.calculator.hash.value = "";
document.calculator.line.value = "";
document.calculator.user.readOnly = false;
document.calculator.pass.readOnly = false;
document.calculator.pass2.readOnly = false;
document.calculator.submit.disabled = false;
alert("Unexpected error occurred: \n"+e);
}
}
function StringToBytesArray(str) {
bytes = [];
for (var i = 0; i < str.length; ++i) {
bytes = bytes.concat([str.charCodeAt(i)]);
}
return bytes;
}
// Code from https://github.com/ricmoo/scrypt-js/blob/master/scrypt.js BEGINS
//
// The MIT License (MIT)
//
// Copyright (c) 2016 Richard Moore
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
(function(root) {
var MAX_VALUE = 0x7fffffff;
// The SHA256 and PBKDF2 implementation are from scrypt-async-js:
// See: https://github.com/dchest/scrypt-async-js
function SHA256(m) {
var K = [
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b,
0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01,
0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7,
0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152,
0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc,
0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819,
0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08,
0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f,
0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
];
var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372, h3 = 0xa54ff53a;
var h4 = 0x510e527f, h5 = 0x9b05688c, h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
var w = new Array(64);
function blocks(p) {
var off = 0, len = p.length;
while (len >= 64) {
var a = h0, b = h1, c = h2, d = h3, e = h4, f = h5, g = h6, h = h7, u, i, j, t1, t2;
for (i = 0; i < 16; i++) {
j = off + i*4;
w[i] = ((p[j] & 0xff)<<24) | ((p[j+1] & 0xff)<<16) |
((p[j+2] & 0xff)<<8) | (p[j+3] & 0xff);
}
for (i = 16; i < 64; i++) {
u = w[i-2];
t1 = ((u>>>17) | (u<<(32-17))) ^ ((u>>>19) | (u<<(32-19))) ^ (u>>>10);
u = w[i-15];
t2 = ((u>>>7) | (u<<(32-7))) ^ ((u>>>18) | (u<<(32-18))) ^ (u>>>3);
w[i] = (((t1 + w[i-7]) | 0) + ((t2 + w[i-16]) | 0)) | 0;
}
for (i = 0; i < 64; i++) {
t1 = ((((((e>>>6) | (e<<(32-6))) ^ ((e>>>11) | (e<<(32-11))) ^
((e>>>25) | (e<<(32-25)))) + ((e & f) ^ (~e & g))) | 0) +
((h + ((K[i] + w[i]) | 0)) | 0)) | 0;
t2 = ((((a>>>2) | (a<<(32-2))) ^ ((a>>>13) | (a<<(32-13))) ^
((a>>>22) | (a<<(32-22)))) + ((a & b) ^ (a & c) ^ (b & c))) | 0;
h = g;
g = f;
f = e;
e = (d + t1) | 0;
d = c;
c = b;
b = a;
a = (t1 + t2) | 0;
}
h0 = (h0 + a) | 0;
h1 = (h1 + b) | 0;
h2 = (h2 + c) | 0;
h3 = (h3 + d) | 0;
h4 = (h4 + e) | 0;
h5 = (h5 + f) | 0;
h6 = (h6 + g) | 0;
h7 = (h7 + h) | 0;
off += 64;
len -= 64;
}
}
blocks(m);
var i, bytesLeft = m.length % 64,
bitLenHi = (m.length / 0x20000000) | 0,
bitLenLo = m.length << 3,
numZeros = (bytesLeft < 56) ? 56 : 120,
p = m.slice(m.length - bytesLeft, m.length);
p.push(0x80);
for (i = bytesLeft + 1; i < numZeros; i++) { p.push(0); }
p.push((bitLenHi>>>24) & 0xff);
p.push((bitLenHi>>>16) & 0xff);
p.push((bitLenHi>>>8) & 0xff);
p.push((bitLenHi>>>0) & 0xff);
p.push((bitLenLo>>>24) & 0xff);
p.push((bitLenLo>>>16) & 0xff);
p.push((bitLenLo>>>8) & 0xff);
p.push((bitLenLo>>>0) & 0xff);
blocks(p);
return [
(h0>>>24) & 0xff, (h0>>>16) & 0xff, (h0>>>8) & 0xff, (h0>>>0) & 0xff,
(h1>>>24) & 0xff, (h1>>>16) & 0xff, (h1>>>8) & 0xff, (h1>>>0) & 0xff,
(h2>>>24) & 0xff, (h2>>>16) & 0xff, (h2>>>8) & 0xff, (h2>>>0) & 0xff,
(h3>>>24) & 0xff, (h3>>>16) & 0xff, (h3>>>8) & 0xff, (h3>>>0) & 0xff,
(h4>>>24) & 0xff, (h4>>>16) & 0xff, (h4>>>8) & 0xff, (h4>>>0) & 0xff,
(h5>>>24) & 0xff, (h5>>>16) & 0xff, (h5>>>8) & 0xff, (h5>>>0) & 0xff,
(h6>>>24) & 0xff, (h6>>>16) & 0xff, (h6>>>8) & 0xff, (h6>>>0) & 0xff,
(h7>>>24) & 0xff, (h7>>>16) & 0xff, (h7>>>8) & 0xff, (h7>>>0) & 0xff
];
}
function PBKDF2_HMAC_SHA256_OneIter(password, salt, dkLen) {
// compress password if it's longer than hash block length
password = password.length <= 64 ? password : SHA256(password);
var i;
var innerLen = 64 + salt.length + 4;
var inner = new Array(innerLen);
var outerKey = new Array(64);
var dk = [];
// inner = (password ^ ipad) || salt || counter
for (i = 0; i < 64; i++) inner[i] = 0x36;
for (i = 0; i < password.length; i++) inner[i] ^= password[i];
for (i = 0; i < salt.length; i++) inner[64+i] = salt[i];
for (i = innerLen - 4; i < innerLen; i++) inner[i] = 0;
// outerKey = password ^ opad
for (i = 0; i < 64; i++) outerKey[i] = 0x5c;
for (i = 0; i < password.length; i++) outerKey[i] ^= password[i];
// increments counter inside inner
function incrementCounter() {
for (var i = innerLen-1; i >= innerLen-4; i--) {
inner[i]++;
if (inner[i] <= 0xff) return;
inner[i] = 0;
}
}
// output blocks = SHA256(outerKey || SHA256(inner)) ...
while (dkLen >= 32) {
incrementCounter();
dk = dk.concat(SHA256(outerKey.concat(SHA256(inner))));
dkLen -= 32;
}
if (dkLen > 0) {
incrementCounter();
dk = dk.concat(SHA256(outerKey.concat(SHA256(inner))).slice(0, dkLen));
}
return dk;
}
// The following is an adaptation of scryptsy
// See: https://www.npmjs.com/package/scryptsy
function blockmix_salsa8(BY, Yi, r, x, _X) {
var i;
arraycopy(BY, (2 * r - 1) * 16, _X, 0, 16);
for (i = 0; i < 2 * r; i++) {
blockxor(BY, i * 16, _X, 16);
salsa20_8(_X, x);
arraycopy(_X, 0, BY, Yi + (i * 16), 16);
}
for (i = 0; i < r; i++) {
arraycopy(BY, Yi + (i * 2) * 16, BY, (i * 16), 16);
}
for (i = 0; i < r; i++) {
arraycopy(BY, Yi + (i * 2 + 1) * 16, BY, (i + r) * 16, 16);
}
}
function R(a, b) {
return (a << b) | (a >>> (32 - b));
}
function salsa20_8(B, x) {
arraycopy(B, 0, x, 0, 16);
for (var i = 8; i > 0; i -= 2) {
x[ 4] ^= R(x[ 0] + x[12], 7);
x[ 8] ^= R(x[ 4] + x[ 0], 9);
x[12] ^= R(x[ 8] + x[ 4], 13);
x[ 0] ^= R(x[12] + x[ 8], 18);
x[ 9] ^= R(x[ 5] + x[ 1], 7);
x[13] ^= R(x[ 9] + x[ 5], 9);
x[ 1] ^= R(x[13] + x[ 9], 13);
x[ 5] ^= R(x[ 1] + x[13], 18);
x[14] ^= R(x[10] + x[ 6], 7);
x[ 2] ^= R(x[14] + x[10], 9);
x[ 6] ^= R(x[ 2] + x[14], 13);
x[10] ^= R(x[ 6] + x[ 2], 18);
x[ 3] ^= R(x[15] + x[11], 7);
x[ 7] ^= R(x[ 3] + x[15], 9);
x[11] ^= R(x[ 7] + x[ 3], 13);
x[15] ^= R(x[11] + x[ 7], 18);
x[ 1] ^= R(x[ 0] + x[ 3], 7);
x[ 2] ^= R(x[ 1] + x[ 0], 9);
x[ 3] ^= R(x[ 2] + x[ 1], 13);
x[ 0] ^= R(x[ 3] + x[ 2], 18);
x[ 6] ^= R(x[ 5] + x[ 4], 7);
x[ 7] ^= R(x[ 6] + x[ 5], 9);
x[ 4] ^= R(x[ 7] + x[ 6], 13);
x[ 5] ^= R(x[ 4] + x[ 7], 18);
x[11] ^= R(x[10] + x[ 9], 7);
x[ 8] ^= R(x[11] + x[10], 9);
x[ 9] ^= R(x[ 8] + x[11], 13);
x[10] ^= R(x[ 9] + x[ 8], 18);
x[12] ^= R(x[15] + x[14], 7);
x[13] ^= R(x[12] + x[15], 9);
x[14] ^= R(x[13] + x[12], 13);
x[15] ^= R(x[14] + x[13], 18);
}
for (i = 0; i < 16; ++i) {
B[i] += x[i];
}
}
// naive approach... going back to loop unrolling may yield additional performance
function blockxor(S, Si, D, len) {
for (var i = 0; i < len; i++) {
D[i] ^= S[Si + i]
}
}
function arraycopy(src, srcPos, dest, destPos, length) {
while (length--) {
dest[destPos++] = src[srcPos++];
}
}
function checkBufferish(o) {
if (!o || typeof(o.length) !== 'number') {
return false;
}
for (var i = 0; i < o.length; i++) {
if (typeof(o[i]) !== 'number') { return false; }
var v = parseInt(o[i]);
if (v != o[i] || v < 0 || v >= 256) {
return false;
}
}
return true;
}
function ensureInteger(value, name) {
var intValue = parseInt(value);
if (value != intValue) { throw new Error('invalid ' + name); }
return intValue;
}
// N = Cpu cost, r = Memory cost, p = parallelization cost
// callback(error, progress, key)
function scrypt(password, salt, N, r, p, dkLen, callback) {
if (!callback) { throw new Error('missing callback'); }
N = ensureInteger(N, 'N');
r = ensureInteger(r, 'r');
p = ensureInteger(p, 'p');
dkLen = ensureInteger(dkLen, 'dkLen');
if (N === 0 || (N & (N - 1)) !== 0) { throw new Error('N must be power of 2'); }
if (N > MAX_VALUE / 128 / r) { throw new Error('N too large'); }
if (r > MAX_VALUE / 128 / p) { throw new Error('r too large'); }
if (!checkBufferish(password)) {
throw new Error('password must be an array or buffer');
}
password = Array.prototype.slice.call(password);
if (!checkBufferish(salt)) {
throw new Error('salt must be an array or buffer');
}
salt = Array.prototype.slice.call(salt);
var b = PBKDF2_HMAC_SHA256_OneIter(password, salt, p * 128 * r);
var B = new Uint32Array(p * 32 * r)
for (var i = 0; i < B.length; i++) {
var j = i * 4;
B[i] = ((b[j + 3] & 0xff) << 24) |
((b[j + 2] & 0xff) << 16) |
((b[j + 1] & 0xff) << 8) |
((b[j + 0] & 0xff) << 0);
}
var XY = new Uint32Array(64 * r);
var V = new Uint32Array(32 * r * N);
var Yi = 32 * r;
// scratch space
var x = new Uint32Array(16); // salsa20_8
var _X = new Uint32Array(16); // blockmix_salsa8
var totalOps = p * N * 2;
var currentOp = 0;
var lastPercent10 = null;
// Set this to true to abandon the scrypt on the next step
var stop = false;
// State information
var state = 0;
var i0 = 0, i1;
var Bi;
// How many blockmix_salsa8 can we do per step?
var limit = parseInt(1000 / r);
// Trick from scrypt-async; if there is a setImmediate shim in place, use it
var nextTick = (typeof(setImmediate) !== 'undefined') ? setImmediate : setTimeout;
// This is really all I changed; making scryptsy a state machine so we occasionally
// stop and give other evnts on the evnt loop a chance to run. ~RicMoo
var incrementalSMix = function() {
if (stop) {
return callback(new Error('cancelled'), currentOp / totalOps);
}
switch (state) {
case 0:
// for (var i = 0; i < p; i++)...
Bi = i0 * 32 * r;
arraycopy(B, Bi, XY, 0, Yi); // ROMix - 1
state = 1; // Move to ROMix 2
i1 = 0;
// Fall through
case 1:
// Run up to 1000 steps of the first inner smix loop
var steps = N - i1;
if (steps > limit) { steps = limit; }
for (var i = 0; i < steps; i++) { // ROMix - 2
arraycopy(XY, 0, V, (i1 + i) * Yi, Yi) // ROMix - 3
blockmix_salsa8(XY, Yi, r, x, _X); // ROMix - 4
}
// for (var i = 0; i < N; i++)
i1 += steps;
currentOp += steps;
// Call the callback with the progress (optionally stopping us)
var percent10 = parseInt(1000 * currentOp / totalOps);
if (percent10 !== lastPercent10) {
stop = callback(null, currentOp / totalOps);
if (stop) { break; }
lastPercent10 = percent10;
}
if (i1 < N) {
break;
}
i1 = 0; // Move to ROMix 6
state = 2;
// Fall through
case 2:
// Run up to 1000 steps of the second inner smix loop
var steps = N - i1;
if (steps > limit) { steps = limit; }
for (var i = 0; i < steps; i++) { // ROMix - 6
var offset = (2 * r - 1) * 16; // ROMix - 7
var j = XY[offset] & (N - 1);
blockxor(V, j * Yi, XY, Yi); // ROMix - 8 (inner)
blockmix_salsa8(XY, Yi, r, x, _X); // ROMix - 9 (outer)
}
// for (var i = 0; i < N; i++)...
i1 += steps;
currentOp += steps;
// Call the callback with the progress (optionally stopping us)
var percent10 = parseInt(1000 * currentOp / totalOps);
if (percent10 !== lastPercent10) {
stop = callback(null, currentOp / totalOps);
if (stop) { break; }
lastPercent10 = percent10;
}
if (i1 < N) {
break;
}
arraycopy(XY, 0, B, Bi, Yi); // ROMix - 10
// for (var i = 0; i < p; i++)...
i0++;
if (i0 < p) {
state = 0;
break;
}
b = [];
for (var i = 0; i < B.length; i++) {
b.push((B[i] >> 0) & 0xff);
b.push((B[i] >> 8) & 0xff);
b.push((B[i] >> 16) & 0xff);
b.push((B[i] >> 24) & 0xff);
}
var derivedKey = PBKDF2_HMAC_SHA256_OneIter(password, b, dkLen);
// Done; don't break (which would reschedule)
return callback(null, 1.0, derivedKey);
}
// Schedule the next steps
nextTick(incrementalSMix);
}
// Bootstrap the incremental smix
incrementalSMix();
}
// node.js
if (typeof(exports) !== 'undefined') {
module.exports = scrypt;
// RequireJS/AMD
// http://www.requirejs.org/docs/api.html
// https://github.com/amdjs/amdjs-api/wiki/AMD
} else if (typeof(define) === 'function' && define.amd) {
define(scrypt);
// Web Browsers
} else if (root) {
// If there was an existing library "scrypt", make sure it is still available
if (root.scrypt) {
root._scrypt = root.scrypt;
}
root.scrypt = scrypt;
}
})(this);
// Code from https://github.com/ricmoo/scrypt-js/blob/master/scrypt.js ENDS
// Code from https://github.com/YuzuJS/setImmediate/blob/master/setImmediate.js BEGINS
//
// Copyright (c) 2012 Barnesandnoble.com, llc, Donavon West, and Domenic Denicola
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
(function (global, undefined) {
"use strict";
if (global.setImmediate) {
return;
}
var nextHandle = 1; // Spec says greater than zero
var tasksByHandle = {};
var currentlyRunningATask = false;
var doc = global.document;
var registerImmediate;
function setImmediate(callback) {
// Callback can either be a function or a string
if (typeof callback !== "function") {
callback = new Function("" + callback);
}
// Copy function arguments
var args = new Array(arguments.length - 1);
for (var i = 0; i < args.length; i++) {
args[i] = arguments[i + 1];
}
// Store and register the task
var task = { callback: callback, args: args };
tasksByHandle[nextHandle] = task;
registerImmediate(nextHandle);
return nextHandle++;
}
function clearImmediate(handle) {
delete tasksByHandle[handle];
}
function run(task) {
var callback = task.callback;
var args = task.args;
switch (args.length) {
case 0:
callback();
break;
case 1:
callback(args[0]);
break;
case 2:
callback(args[0], args[1]);
break;
case 3:
callback(args[0], args[1], args[2]);
break;
default:
callback.apply(undefined, args);
break;
}
}
function runIfPresent(handle) {
// From the spec: "Wait until any invocations of this algorithm started before this one have completed."
// So if we're currently running a task, we'll need to delay this invocation.
if (currentlyRunningATask) {
// Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a
// "too much recursion" error.
setTimeout(runIfPresent, 0, handle);
} else {
var task = tasksByHandle[handle];
if (task) {
currentlyRunningATask = true;
try {
run(task);
} finally {
clearImmediate(handle);
currentlyRunningATask = false;
}
}
}
}
function installNextTickImplementation() {
registerImmediate = function(handle) {
process.nextTick(function () { runIfPresent(handle); });
};
}
function canUsePostMessage() {
// The test against `importScripts` prevents this implementation from being installed inside a web worker,
// where `global.postMessage` means something completely different and can't be used for this purpose.
if (global.postMessage && !global.importScripts) {
var postMessageIsAsynchronous = true;
var oldOnMessage = global.onmessage;
global.onmessage = function() {
postMessageIsAsynchronous = false;
};
global.postMessage("", "*");
global.onmessage = oldOnMessage;
return postMessageIsAsynchronous;
}
}
function installPostMessageImplementation() {
// Installs an event handler on `global` for the `message` event: see
// * https://developer.mozilla.org/en/DOM/window.postMessage
// * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages
var messagePrefix = "setImmediate$" + Math.random() + "$";
var onGlobalMessage = function(event) {
if (event.source === global &&
typeof event.data === "string" &&
event.data.indexOf(messagePrefix) === 0) {
runIfPresent(+event.data.slice(messagePrefix.length));
}
};
if (global.addEventListener) {
global.addEventListener("message", onGlobalMessage, false);
} else {
global.attachEvent("onmessage", onGlobalMessage);
}
registerImmediate = function(handle) {
global.postMessage(messagePrefix + handle, "*");
};
}
function installMessageChannelImplementation() {
var channel = new MessageChannel();
channel.port1.onmessage = function(event) {
var handle = event.data;
runIfPresent(handle);
};
registerImmediate = function(handle) {
channel.port2.postMessage(handle);
};
}
function installReadyStateChangeImplementation() {
var html = doc.documentElement;
registerImmediate = function(handle) {
// Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
// into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
var script = doc.createElement("script");
script.onreadystatechange = function () {
runIfPresent(handle);
script.onreadystatechange = null;
html.removeChild(script);
script = null;
};
html.appendChild(script);
};
}
function installSetTimeoutImplementation() {
registerImmediate = function(handle) {
setTimeout(runIfPresent, 0, handle);
};
}
// If supported, we should attach to the prototype of global, since that is where setTimeout et al. live.
var attachTo = Object.getPrototypeOf && Object.getPrototypeOf(global);
attachTo = attachTo && attachTo.setTimeout ? attachTo : global;
// Don't get fooled by e.g. browserify environments.
if ({}.toString.call(global.process) === "[object process]") {
// For Node.js before 0.9
installNextTickImplementation();
} else if (canUsePostMessage()) {
// For non-IE10 modern browsers
installPostMessageImplementation();
} else if (global.MessageChannel) {
// For web workers, where supported
installMessageChannelImplementation();
} else if (doc && "onreadystatechange" in doc.createElement("script")) {
// For IE 6–8
installReadyStateChangeImplementation();
} else {
// For older browsers
installSetTimeoutImplementation();
}
attachTo.setImmediate = setImmediate;
attachTo.clearImmediate = clearImmediate;
}(typeof self === "undefined" ? typeof global === "undefined" ? this : global : self));
// Code from https://github.com/YuzuJS/setImmediate/blob/master/setImmediate.js ENDS
if(OrgSalt == "Please replace this value with unique long random string! E.g.: NYLVfq7kKUc9Aj7KtddMs7ECZV3dloBYRN2wTQigMlQfmoyHqu") {
document.write('<p style="color: red; font-weight: bold;">WARNING! Default Organization Salt is used. <br />If you are setting up OpenVPN-auth-scrypt for your OpenVPN instance, please read the <a href="https://github.com/DavisNT/OpenVPN-auth-scrypt/blob/master/README.md" target="_blank">README.md</a> and set OrgSalt to a random value used for your setup! <br />If you are trying to get access to existing VPN and have downloaded this script from GitHub to generate hash for your password, then please contact administrator of the VPN to get the proper script!</p>');
}
</script>
<form name="calculator" action="javascript:calculate()">
Username: <input type="text" name="user" style="width: 100%;"><br /><br />
Password: <input type="password" name="pass" style="width: 100%;"><br /><br />
Confirm password: <input type="password" name="pass2" style="width: 100%;"><br /><br />
Hash: <input type="text" readonly name="hash" style="width: 100%;"><br /><br />
Line: <input type="text" readonly name="line" style="width: 100%;"><br /><br />
<input type="submit" name="submit" value="Calculate" style="width: 100%;">
</form>
<br /><br />
<p align="center" style="font-size: small;">
Copyright © 2018–2019 Dāvis Mošenkovs<br /><br />
<a href="https://github.com/DavisNT/OpenVPN-auth-scrypt" target="_blank">GitHub page</a>
</p>
</body>
</html>