From 4c53d48b0df6754d03a2f0cfa5e1ac36410062c5 Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 20 Jun 2013 17:28:55 +0200 Subject: fix bug wrt zero padding of hashes --- src/srp_session.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/srp_session.js b/src/srp_session.js index b1b6014..f895f4a 100644 --- a/src/srp_session.js +++ b/src/srp_session.js @@ -121,11 +121,15 @@ srp.Session = function(login, password) { hexString += Astr; hexString += Bstr; hexString += K - M = SHA256(hex2a(hexString)); + M = removeLeading0(SHA256(hex2a(hexString))); //M2 = H(A, M, K) - M2 = SHA256(hex2a(Astr + M + K)); + M2 = removeLeading0(SHA256(hex2a(Astr + M + K))); }; + this.getS = function() { + return S; + } + this.getM = function() { return M; } @@ -161,8 +165,19 @@ srp.Session = function(login, password) { return retstring; }; + function removeLeading0(hex) { + if (hex[0] == "0") { + return hex.substr(1); + } else { + return hex; + } + } + function hex2a(hex) { var str = ''; + if(hex.length % 2) { + hex = "0" + hex; + } for (var i = 0; i < hex.length; i += 2) str += String.fromCharCode(parseInt(hex.substr(i, 2), 16)); return str; -- cgit v1.2.3