Skip to content
Snippets Groups Projects
Commit 49673382 authored by Ben Adida's avatar Ben Adida
Browse files

reenabled dummy bigint in case where browser is not doing the crypto

parent 9a125083
Branches
Tags
No related merge requests found
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
// A wrapper for java.math.BigInteger with some appropriate extra functions for JSON and // A wrapper for java.math.BigInteger with some appropriate extra functions for JSON and
// generally being a nice JavaScript object. // generally being a nice JavaScript object.
BigInt = Class.extend({ BigIntDummy = Class.extend({
init: function(value, radix) { init: function(value, radix) {
if (radix != 10) if (radix != 10)
throw "in dummy, only radix=10, here radix=" + radix; throw "in dummy, only radix=10, here radix=" + radix;
...@@ -59,71 +59,27 @@ BigInt = Class.extend({ ...@@ -59,71 +59,27 @@ BigInt = Class.extend({
}); });
BigInt.ready_p = false; BigIntDummy.use_applet = false;
BigInt.use_applet = false; BigIntDummy.is_dummy = true;
BigIntDummy.in_browser = false;
BigInt.is_dummy = true; BigIntDummy.fromJSONObject = function(s) {
return new BigIntDummy(s, 10);
BigInt.fromJSONObject = function(s) {
return new BigInt(s, 10);
}; };
BigInt.fromInt = function(i) { BigIntDummy.fromInt = function(i) {
return BigInt.fromJSONObject("" + i); return BigIntDummy.fromJSONObject("" + i);
}; };
// Set up the pointer to the applet if necessary, and some BigIntDummy.ZERO = new BigIntDummy("0",10);
// basic Big Ints that everyone needs (0, 1, 2, and 42) BigIntDummy.ONE = new BigIntDummy("1",10);
BigInt._setup = function() { BigIntDummy.TWO = new BigIntDummy("2",10);
try { BigIntDummy.FORTY_TWO = new BigIntDummy("42",10);
BigInt.ZERO = new BigInt("0",10);
BigInt.ONE = new BigInt("1",10);
BigInt.TWO = new BigInt("2",10);
BigInt.FORTY_TWO = new BigInt("42",10);
BigInt.ready_p = true;
} catch (e) {
// not ready
// count how many times we've tried
if (this.num_invocations == null)
this.num_invocations = 0;
this.num_invocations += 1;
if (this.num_invocations > 5) {
if (BigInt.setup_interval)
window.clearInterval(BigInt.setup_interval);
if (BigInt.setup_fail) {
BigInt.setup_fail();
} else {
alert('bigint failed!');
}
}
return;
}
if (BigInt.setup_interval)
window.clearInterval(BigInt.setup_interval);
if (BigInt.setup_callback) BigIntDummy.ready_p = true;
BigInt.setup_callback();
};
BigInt.setup = function(callback, fail_callback) { BigIntDummy.setup = function(callback, fail_callback) {
if (callback) console.log("using dummy bigint");
BigInt.setup_callback = callback; callback();
if (fail_callback)
BigInt.setup_fail = fail_callback;
BigInt.setup_interval = window.setInterval("BigInt._setup()", 1000);
} }
// .onload instead of .ready, as I don't think the applet is ready until onload.
// FIXME: something wrong here in the first load
$(document).ready(function() {
BigInt.use_applet = false;
});
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
<title>Helios Voting Booth</title> <title>Helios Voting Booth</title>
<link rel="stylesheet" type="text/css" href="css/booth.css" /> <link rel="stylesheet" type="text/css" href="css/booth.css" />
<link rel="stylesheet" type="text/css" href="css/forms.css" /> <link rel="stylesheet" type="text/css" href="css/forms.css" />
<script language="javascript" src="js/jscrypto/class.js"></script>
<script language="javascript" src="js/jscrypto/bigint.dummy.js"></script>
<script language="javascript" src="js/jscrypto/jsbn.js"></script> <script language="javascript" src="js/jscrypto/jsbn.js"></script>
<script language="javascript" src="js/jscrypto/jsbn2.js"></script> <script language="javascript" src="js/jscrypto/jsbn2.js"></script>
<script language="javascript" src="js/jscrypto/sjcl.js"></script> <script language="javascript" src="js/jscrypto/sjcl.js"></script>
...@@ -364,14 +366,6 @@ BOOTH.nojava = function() { ...@@ -364,14 +366,6 @@ BOOTH.nojava = function() {
// because navigator.javaEnabled() still returns true. // because navigator.javaEnabled() still returns true.
// $('#election_div').hide(); // $('#election_div').hide();
// $('#error_div').show(); // $('#error_div').show();
/* var script = document.createElement('script');
script.type = 'text/javascript';
script.src = JSCRYPTO_HOME + '/bigint.dummy.js';
document.getElementsByTagName('head')[0].appendChild(script);
// FIXME: this is a bit unfortunate, can we have a trigger
// for loading this new script?
setTimeout("BigInt.setup(BOOTH.so_lets_go)", 2000); */
USE_SJCL = true; USE_SJCL = true;
sjcl.random.startCollectors(); sjcl.random.startCollectors();
BigInt.setup(BOOTH.so_lets_go); BigInt.setup(BOOTH.so_lets_go);
...@@ -390,6 +384,10 @@ $(document).ready(function() { ...@@ -390,6 +384,10 @@ $(document).ready(function() {
// we do in the browser only if it's asynchronous // we do in the browser only if it's asynchronous
BigInt.in_browser = !BOOTH.synchronous; BigInt.in_browser = !BOOTH.synchronous;
// set up dummy bigint for fast parsing and serialization
if (!BigInt.in_browser)
BigInt = BigIntDummy;
BigInt.setup(BOOTH.so_lets_go, BOOTH.nojava); BigInt.setup(BOOTH.so_lets_go, BOOTH.nojava);
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment