diff options
author | jessib <jessib@riseup.net> | 2013-10-14 10:27:08 -0700 |
---|---|---|
committer | jessib <jessib@riseup.net> | 2013-10-14 10:27:08 -0700 |
commit | 8f33d32d40b1e21ae7fb9a92c78a275422af4217 (patch) | |
tree | f4ae8de3d30267443b0a242887d8e583fdb174d1 /src | |
parent | 948898fd93dd90031602a445cfc5dd432ddc7f39 (diff) | |
parent | 4c8e593b7b03abb19b451b6be999f10e0fed5ff4 (diff) |
Merge pull request #4 from azul/bugfix/utf8-in-sha
properly treat utf8 chars in password
Diffstat (limited to 'src')
-rw-r--r-- | src/srp_calculate.js | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/src/srp_calculate.js b/src/srp_calculate.js index a1cbe51..e32def8 100644 --- a/src/srp_calculate.js +++ b/src/srp_calculate.js @@ -50,14 +50,13 @@ srp.Calculate = function() { }; this.hashHex = function(hexString) { - return this.hash(hex2a(hexString)); + return SHA256(hex2a(hexString)); }; this.hash = function(string) { - return SHA256(string); + return SHA256(utf8Encode(string)); }; - this.isInvalidEphemeral = function(a) { return (g.modPow(a, N) == 0); }; @@ -117,4 +116,26 @@ srp.Calculate = function() { } return str; } + + function utf8Encode(string) { + string = string.replace(/\r\n/g,"\n"); + var utftext = ""; + + for (var n = 0; n < string.length; n++) { + var c = string.charCodeAt(n); + if (c < 128) { + utftext += String.fromCharCode(c); + } + else if((c > 127) && (c < 2048)) { + utftext += String.fromCharCode((c >> 6) | 192); + utftext += String.fromCharCode((c & 63) | 128); + } + else { + utftext += String.fromCharCode((c >> 12) | 224); + utftext += String.fromCharCode(((c >> 6) & 63) | 128); + utftext += String.fromCharCode((c & 63) | 128); + } + } + return utftext; + } }; |