Commit 7656da10 authored by Stephane Glondu's avatar Stephane Glondu
Browse files

Initialization of the PRNG using crypto.getRandomValues

parent 1d95bcbd
......@@ -71,6 +71,10 @@ let copy_ext_js_rule dir fname =
let full_name = dir / fname in
copy_rule full_name ("ext/booth/js/jscrypto" / fname) full_name
let copy_platform_js_rule dir fname =
let full_name = dir / fname in
copy_rule full_name ("src/platform/js" / fname) full_name
let () = dispatch & function
| Before_options ->
......@@ -108,5 +112,6 @@ let () = dispatch & function
copy_rule "belenios-tool" ("src/tool/tool_cmdline" ^ exe_suffix) "belenios-tool";
List.iter (copy_ext_js_rule "src/tool") ["jsbn.js"; "jsbn2.js"; "sjcl.js"];
copy_platform_js_rule "src/tool" "random.js";
| _ -> ()
......@@ -69,13 +69,8 @@ type rng = unit -> unit
let sjcl_random = Js.Unsafe.get sjcl "random"
let secure_rng () =
Js.Unsafe.meth_call sjcl_random "addEntropy"
[|
Js.string "91ad862fdddfe6171fa8492414273" |> Js.Unsafe.inject;
256 |> float_of_int |> Js.number_of_float |> Js.Unsafe.inject;
|]
(* PRNG is initialized in random.js *)
let secure_rng () = ()
let pseudo_rng x () = ()
let string_of_hex hex n =
......
function init_prng () {
// Start SJCL built-in collectors
sjcl.random.startCollectors();
// Seed from window.crypto if present
if (window.crypto) {
var bytes = new Uint32Array(4);
window.crypto.getRandomValues(bytes);
sjcl.random.addEntropy(bytes[0], 32);
sjcl.random.addEntropy(bytes[1], 32);
sjcl.random.addEntropy(bytes[2], 32);
sjcl.random.addEntropy(bytes[3], 32);
if (console) {
console.log("PRNG successfully initialized using crypto object");
}
} else {
alert("The random number generator could not be safely initialized. You should use a more modern browser.");
}
}
init_prng();
......@@ -6,6 +6,7 @@
<script src="sjcl.js"></script>
<script src="jsbn.js"></script>
<script src="jsbn2.js"></script>
<script src="random.js"></script>
<script src="tool_js.js"></script>
</head>
<body>
......
sjcl.js
jsbn.js
jsbn2.js
random.js
tool_js.js
belenios-tool.html
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment