1
0
mirror of http://git.whoc.org.uk/git/password-manager.git synced 2025-10-28 01:47:36 +01:00

Merge branch 'master-wraith' into v1.0.4-work

This commit is contained in:
Graham Eades
2018-11-28 17:40:24 +00:00
22 changed files with 5244 additions and 138 deletions

View File

@@ -67,9 +67,14 @@ MochiKit.Base.update(Clipperz.Crypto.SRP, {
},
'k': function() {
//k = H(N, g)
if (Clipperz.Crypto.SRP._k == null) {
// Clipperz.Crypto.SRP._k = new Clipperz.Crypto.BigInt(this.stringHash(this.n().asString() + this.g().asString()), 16);
Clipperz.Crypto.SRP._k = new Clipperz.Crypto.BigInt("64398bff522814e306a97cb9bfc4364b7eed16a8c17c5208a40a2bad2933c8e", 16);
// This is a fixed hash derived from a hash of N and G
// Following hash for just AES256
// Clipperz.Crypto.SRP._k = new Clipperz.Crypto.BigInt("64398bff522814e306a97cb9bfc4364b7eed16a8c17c5208a40a2bad2933c8e", 16);
// Following hash for dual AES256
Clipperz.Crypto.SRP._k = new Clipperz.Crypto.BigInt("23059873679103356965010473015094804246238452944122574891019568752064785140295", 10);
}
return Clipperz.Crypto.SRP._k;
@@ -138,8 +143,10 @@ Clipperz.Crypto.SRP.Connection.prototype = MochiKit.Base.update(null, {
'a': function () {
if (this._a == null) {
this._a = new Clipperz.Crypto.BigInt(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32).toHexString().substring(2), 16);
// this._a = new Clipperz.Crypto.BigInt("37532428169486597638072888476611365392249575518156687476805936694442691012367", 10);
// this._a = new Clipperz.Crypto.BigInt(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32).toHexString().substring(2), 16);
// Due to the problem with BigInt not handling signed numbers, this must be even.
// Possible generate any number, then bitwise shift right then left.
this._a = new Clipperz.Crypto.BigInt("33361134861037855263467252772741875431812790785257651194773534061185325245730", 10);
}
return this._a;
@@ -191,7 +198,8 @@ Clipperz.Crypto.SRP.Connection.prototype = MochiKit.Base.update(null, {
'x': function () {
if (this._x == null) {
this._x = new Clipperz.Crypto.BigInt(this.stringHash(this.s().asString(16, 64) + this.P()), 16);
// Private key x = H(s, p)
this._x = new Clipperz.Crypto.BigInt(this.stringHash(this.s() + this.P()), 16);
}
return this._x;
@@ -210,6 +218,7 @@ Clipperz.Crypto.SRP.Connection.prototype = MochiKit.Base.update(null, {
//-------------------------------------------------------------------------
'S': function () {
// S = (B - kg^x) ^ (a + ux)
if (this._S == null) {
var bigint;
var srp;
@@ -217,19 +226,43 @@ Clipperz.Crypto.SRP.Connection.prototype = MochiKit.Base.update(null, {
bigint = Clipperz.Crypto.BigInt;
srp = Clipperz.Crypto.SRP;
this._S = bigint.powerModule(
bigint.subtract(
this.B(),
bigint.multiply(
Clipperz.Crypto.SRP.k(),
bigint.powerModule(srp.g(), this.x(), srp.n())
)
),
bigint.add(this.a(), bigint.multiply(this.u(), this.x())),
srp.n()
)
// S can be negative. This breaks as the BigInt Library is unsigned
this._S = bigint.powerModule( bigint.subtract( bigint.multiply(Clipperz.Crypto.SRP.k(),bigint.powerModule(srp.g(), this.x(), srp.n())), this.B()), bigint.add(this.a(), bigint.multiply(this.u(), this.x())),srp.n() );
// var tmp_B = new BigInteger(this.B());
// var tmp_k = new BigInteger(Clipperz.Crypto.SRP.k());
// var tmp_g = new BigInteger(srp.g());
// var tmp_x = new BigInteger(this.x());
// var tmp_a = new BigInteger(this.a());
// var tmp_n = new BigInteger(srp.n());
// var tmp_u = new BigInteger(this.u());
//
// var tmp_S1 = new BigInteger(tmp_B.subtract(tmp_k.multiply(tmp_g.modPow(tmp_x,tmp_n))));
// var tmp_S2 = new BigInteger(tmp_a.add(tmp_u.multiply(tmp_x)));
// var tmp_S = new BigInteger(tmp_S1.modPow(tmp_S2,tmp_n));
// if (tmp_S.isNegative() == true ) {
// tmp_S = tmp_S.add(srp.n());
// }
//console.log("_B", tmp_B.toString());
//console.log("_k", tmp_k.toString());
//console.log("_g", tmp_g.toString());
//console.log("_x", tmp_x.toString());
//console.log("_a", tmp_a.toString());
//console.log("_n", tmp_n.toString());
//console.log("_u", tmp_u.toString());
//console.log("S1", tmp_S1.toString());
//console.log("S2", tmp_S2.toString());
//console.log("S-", tmp_S.toString());
}
//this._S= Clipperz.Crypto.BigInt(tmp_S.toString(),10);
return this._S;
},
@@ -258,9 +291,25 @@ Clipperz.Crypto.SRP.Connection.prototype = MochiKit.Base.update(null, {
this.s().asString() +
this.A().asString() +
this.B().asString() +
this.K()
new Clipperz.Crypto.BigInt(this.K(),16).asString()
);
//console.log("M1", this._M1);
//console.log("g", this.g().asString());
//console.log("s", this.s().asString());
//console.log("a", this.a().asString());
//console.log("A", this.A().asString());
//console.log("B", this.B().asString());
//console.log("S", this.S().asString());
//console.log("k", Clipperz.Crypto.SRP.k().asString());
//console.log("K", this.K());
//console.log("x", this.x().asString());
//console.log("P", this.P());
//console.log("u", this.u());
//console.log("u", this.u().asString());
//console.log("Test", this.stringHash(this.A().asString));
//console.log("N", Clipperz.Crypto.SRP.n().asString());
//console.log("g", Clipperz.Crypto.SRP.g().asString());
//console.log("test", this.A().asString() + this.B().asString());
}
return this._M1;
@@ -283,15 +332,22 @@ Clipperz.Crypto.SRP.Connection.prototype = MochiKit.Base.update(null, {
var result;
var s, x, v;
s = aSalt;
//` s = aSalt;
s = new Clipperz.Crypto.BigInt(aSalt,16);
x = this.stringHash(s.asString() + this.P());
x = this.stringHash(s + this.P());
v = Clipperz.Crypto.SRP.g().powerModule(new Clipperz.Crypto.BigInt(x, 16), Clipperz.Crypto.SRP.n());
result = {};
result['C'] = this.C();
result['s'] = s;
result['s'] = s.asString(16);
result['v'] = v.asString(16);
//console.log("ServerSide C", result['C']);
//console.log("ServerSide s", result['s']);
//console.log("ServerSide v", result['v']);
//console.log("ServerSide P", this.P());
//console.log("ServerSide x", ge.asString());
return result;
},
@@ -334,8 +390,10 @@ Clipperz.Crypto.SRP.Connection.prototype = MochiKit.Base.update(null, {
'stringHash': function(aValue) {
var result;
result = this.hash(new Clipperz.ByteArray(aValue)).toHexString().substring(2);
//result = this.hash(new Clipperz.ByteArray(aValue)).toHexString().substring(2);
//result = Clipperz.Crypto.SHA.sha256( new Clipperz.ByteArray(aValue)).toHexString().substring(2);
result = Clipperz.Crypto.SHA.sha_d256( new Clipperz.ByteArray(aValue)).toHexString().substring(2);
return result;
},

File diff suppressed because it is too large Load Diff

View File

@@ -354,7 +354,8 @@ Clipperz.PM.Proxy.Offline.DataStore.prototype = MochiKit.Base.update(null, {
this.set_C(someParameters.parameters.C);
this.set_b(new Clipperz.Crypto.BigInt(randomBytes, 16));
v = new Clipperz.Crypto.BigInt(this.userData()['v'], 16);
this.set_B((Clipperz.Crypto.SRP.k().multiply(v)).add(Clipperz.Crypto.SRP.g().powerModule(this.b(), Clipperz.Crypto.SRP.n())));
//this.set_B((Clipperz.Crypto.SRP.k().multiply(v)).add(Clipperz.Crypto.SRP.g().powerModule(this.b(), Clipperz.Crypto.SRP.n())));
this.set_B((Clipperz.Crypto.SRP.k().multiply(v)).add(Clipperz.Crypto.SRP.g().powerModule(this.b(), Clipperz.Crypto.SRP.n())).module(Clipperz.Crypto.SRP.n()));
this.set_A(someParameters.parameters.A);
@@ -363,7 +364,7 @@ Clipperz.PM.Proxy.Offline.DataStore.prototype = MochiKit.Base.update(null, {
nextTollRequestType = 'CONNECT';
} else if (someParameters.message == "credentialCheck") {
var v, u, s, S, A, K, M1;
var v, u, s, S, A, K, M1, KK;
var stringHash = function (aValue) {
return Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(aValue)).toHexString().substring(2);
};
@@ -373,9 +374,11 @@ Clipperz.PM.Proxy.Offline.DataStore.prototype = MochiKit.Base.update(null, {
A = new Clipperz.Crypto.BigInt(this.A(), 16);
u = new Clipperz.Crypto.BigInt(Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(A.asString(10) + this.B().asString(10))).toHexString(), 16);
s = new Clipperz.Crypto.BigInt(this.userData()['s'], 16);
S = (A.multiply(v.powerModule(u, Clipperz.Crypto.SRP.n()))).powerModule(this.b(), Clipperz.Crypto.SRP.n());
//S = (A.multiply(v.powerModule(u, Clipperz.Crypto.SRP.n()))).powerModule(this.b(), Clipperz.Crypto.SRP.n());
S = v.powerModule(u, Clipperz.Crypto.SRP.n()).multiply(A).module(Clipperz.Crypto.SRP.n()).powerModule(this.b(), Clipperz.Crypto.SRP.n())
K = stringHash(S.asString(10));
KK = new Clipperz.Crypto.BigInt(K,16);
M1 = stringHash(
"597626870978286801440197562148588907434001483655788865609375806439877501869636875571920406529" +
@@ -383,7 +386,7 @@ Clipperz.PM.Proxy.Offline.DataStore.prototype = MochiKit.Base.update(null, {
s.asString(10) +
A.asString(10) +
this.B().asString(10) +
K
KK.asString(10)
);
if (someParameters.parameters.M1 == M1) {
var M2;
@@ -823,4 +826,4 @@ Clipperz.PM.Proxy.Offline.DataStore.prototype = MochiKit.Base.update(null, {
Clipperz.PM.Proxy.Offline.DataStore['exception'] = {
'ReadOnly': new MochiKit.Base.NamedError("Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly")
};
};