Find file
Fetching contributors…
Cannot retrieve contributors at this time
110 lines (90 sloc) 5.4 KB
<!--
Copyright 2008-2014 Clipperz Srl - All rights reserved.
This file is part of Clipperz's Javascript Crypto Library.
The Javascript Crypto Library provides web developers with an extensive
and efficient set of cryptographic functions.
For further information about its features and functionalities please
refer to https://clipperz.is
* The Javascript Crypto Library is free software: you can redistribute
it and/or modify it under the terms of the BSD 3-Clause License
as published by the Free Software Foundation.
* You should have received a copy of the BSD 3-Clause License
along with the Javascript Crypto Library in the LICENSE.TXT file.
If not, see <http://www.gnu.org/licenses/>.
-->
<html>
<head>
<script> jslog_config_enabled = true; </script>
<script type="text/javascript" src="../../../../other_libraries/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
<script type='text/javascript' src='../../../../other_libraries/JSON/json2.js'></script>
<script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
<script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
<script type='text/javascript' src='../../../../js/Clipperz/Logging.js'></script>
<script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
<script type='text/javascript' src='../../../../js/Clipperz/DOM.js'></script>
<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/Statistics.js'></script>-->
<script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
<script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
<script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES.js'></script>
<script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script>
<script type='text/javascript' src='../../../../js/Clipperz/Crypto/PRNG.js'></script>
</head>
<body>
<pre id="test">
<script type="text/javascript">
test_PRNG = function() {
var rand1, rand2;
var i,c;
c = 10;
for (i=0; i<c; i++) {
// jslog.debug(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32).toHexString());
}
rand1 = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(1);
is(rand1.byteAtIndex(0) <= 255, true, "getRandomByte returns always a single byte");
rand2 = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(1);
is(rand1.equals(rand2), false, "getRandomByte should almost always return two different values when called into sequence");
rand1 = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32);
rand2 = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32);
is(rand1.equals(rand2), false, "getRandomByte should almost always return two different values when called into sequence");
is(rand1.split(0,1).equals(rand2.split(0,1)), false, "getRandomByte should almost always return two different values when called into sequence");
// is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 1", "Value for random test");
// is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 2", "Value for random test");
// is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 3", "Value for random test");
// is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 4", "Value for random test");
// is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 5", "Value for random test");
// is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 6", "Value for random test");
// is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 7", "Value for random test");
// is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 8", "Value for random test");
// is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 9", "Value for random test");
// is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 10", "Value for random test");
// is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 11", "Value for random test");
// is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 12", "Value for random test");
// is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 13", "Value for random test");
// is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 14", "Value for random test");
//jslog.debug(rand1.toHexString());
//jslog.debug(rand2.toHexString());
SimpleTest.finish();
}
try {
MochiKit.Signal.connect(Clipperz.Crypto.PRNG.defaultRandomGenerator(), 'readyToGenerateRandomBytes', test_PRNG);
Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose();
SimpleTest.waitForExplicitFinish();
} catch (err) {
var s = "test suite failure!\n";
var o = {};
var k = null;
for (k in err) {
// ensure unique keys?!
if (!o[k]) {
s += k + ": " + err[k] + "\n";
o[k] = err[k];
}
}
ok ( false, s );
}
</script>
</pre>
</body>
</html>