More work on split key protocol.

This commit is contained in:
Stefan Thomas 2011-09-03 19:36:45 +01:00
parent 77debc1d4f
commit 50b13d2941
4 changed files with 153 additions and 36 deletions

View file

@ -65,6 +65,14 @@ Bitcoin.Paillier = (function () {
return c.modPow(f, this.nSq);
};
Paillier.PublicKey.prototype.rerandomize = function (c, r) {
if (!r) {
var coprimeBitLength = this.n.bitLength() - Math.floor(Math.random()*10);
r = new BigInteger(coprimeBitLength, 1, rng);
}
return c.multiply(r.modPow(this.n, this.nSq)).mod(this.nSq);
};
Paillier.PrivateKey = function (n,g,l,m,nSq) {
this.l = l;
this.m = m;
@ -73,12 +81,8 @@ Bitcoin.Paillier = (function () {
this.pub = new Paillier.PublicKey(n,g,this.nSq);
};
Paillier.PrivateKey.prototype.encrypt = function (m) {
return this.pub.encrypt(m);
};
Paillier.PrivateKey.prototype.decrypt = function (c) {
return c.modPow(this.l, this.nSq).mod(this.nSq).subtract(BigInteger.ONE)
return c.modPow(this.l, this.nSq).subtract(BigInteger.ONE)
.divide(this.n).multiply(this.m).mod(this.n);
};
@ -93,5 +97,16 @@ Bitcoin.Paillier = (function () {
return rn.modPow(e, this.n);
};
function createProxyMethod(name) {
return function () {
return this.pub[name].apply(this.pub,
Array.prototype.slice.apply(arguments));
};
};
var a = ["add", "addCrypt", "multiply", "rerandomize", "encrypt"];
for (var i = 0, l = a.length; i < l; i++) {
Paillier.PrivateKey.prototype[a[i]] = createProxyMethod(a[i]);
}
return Paillier;
})();