Commit babcfc55 authored by Stephane Glondu's avatar Stephane Glondu
Browse files

Start SJCL bindings

parent c6d50c05
......@@ -3,5 +3,6 @@ src/lib/lib.cma
src/web/server.cma
src/tool/tool_js.js
src/tool/belenios_tool.html
src/tool/sjcl.js
src/tool/jsbn.js
src/tool/jsbn2.js
......@@ -67,6 +67,8 @@ let version_rule () =
in
rule "BUILD -> belenios_version.ml" ~deps ~prod builder
let copy_ext_js_rule fname =
copy_rule fname ("ext/booth/js/jscrypto/" ^ fname) ("src/tool/" ^ fname)
let () = dispatch & function
......@@ -104,7 +106,6 @@ let () = dispatch & function
platform_rules "js";
copy_rule "belenios-tool" ("src/tool/tool_cmdline" ^ exe_suffix) "belenios-tool";
copy_rule "jsbn" "ext/booth/js/jscrypto/jsbn.js" "src/tool/jsbn.js";
copy_rule "jsbn2" "ext/booth/js/jscrypto/jsbn2.js" "src/tool/jsbn2.js";
List.iter copy_ext_js_rule ["jsbn.js"; "jsbn2.js"; "sjcl.js"];
| _ -> ()
......@@ -19,8 +19,19 @@
(* <http://www.gnu.org/licenses/>. *)
(**************************************************************************)
let sha256_hex x = assert false
let sha256_b64 x = assert false
let sjcl = Js.Unsafe.variable "sjcl"
let sha256 x =
Js.Unsafe.meth_call sjcl "hash.sha256.hash"
[| Js.string x |> Js.Unsafe.inject |]
let sha256_hex x =
Js.Unsafe.meth_call sjcl "codec.hex.fromBits"
[| sha256 x |] |> Js.to_string
let sha256_b64 x =
Js.Unsafe.meth_call sjcl "codec.base64.fromBits"
[| sha256 x |] |> Js.to_string
let b64_encode_compact x = assert false
......@@ -28,9 +39,23 @@ let derive_cred uuid x = assert false
type rng = unit -> unit
let secure_rng () = assert false
let pseudo_rng x () = assert false
let random_string rng i = assert false
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;
|]
let pseudo_rng x () = ()
let random_string rng n =
let () = rng () in
Js.Unsafe.meth_call sjcl_random "randomWords"
[|
n |> float_of_int |> Js.number_of_float |> Js.Unsafe.inject;
|] |> Js.to_string
module Z = struct
open Js.Unsafe
......
......@@ -3,6 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Belenios Tool</title>
<script src="sjcl.js"></script>
<script src="jsbn.js"></script>
<script src="jsbn2.js"></script>
<script src="tool_js.js"></script>
......
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