summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2013-07-12 11:50:45 +0200
committerAzul <azul@riseup.net>2013-07-12 11:54:33 +0200
commit933567499fa4c46e42d45de6066064559cfded09 (patch)
treebf16d3d90448c396b8b34002163ea63152b875b2 /src
parent5c8a17447e382f9b9f9f241e293156a94162a1ca (diff)
also prefix our own toString(16) hex values
Diffstat (limited to 'src')
-rw-r--r--src/srp_calculate.js19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/srp_calculate.js b/src/srp_calculate.js
index 93a4568..9196e0c 100644
--- a/src/srp_calculate.js
+++ b/src/srp_calculate.js
@@ -9,7 +9,7 @@ srp.Calculate = function() {
this.A = function(_a) {
a = new BigInteger(_a, 16);
- return g.modPow(a, N).toString(16);
+ return zeroPrefix(g.modPow(a, N).toString(16));
};
// Calculates the X value
@@ -36,7 +36,7 @@ srp.Calculate = function() {
var kgx = k.multiply(g.modPow(x, N));
var aux = a.add(u.multiply(x));
- return B.subtract(kgx).modPow(aux, N).toString(16);
+ return zeroPrefix(B.subtract(kgx).modPow(aux, N).toString(16));
}
this.K = function(_S) {
@@ -68,12 +68,13 @@ srp.Calculate = function() {
{
a = new BigInteger(32, rng);
}
- return a.toString(16);
+ return zeroPrefix(a.toString(16));
};
// some 16 byte random number
this.randomSalt = function() {
- return new BigInteger(64, rng).toString(16);
+ salt = new BigInteger(64, rng);
+ return zeroPrefix(salt.toString(16));
}
function hex2a(hex) {
@@ -86,6 +87,16 @@ srp.Calculate = function() {
return str;
}
+
+ function zeroPrefix(hex) {
+ if (hex.length % 2) {
+ return "0" + hex;
+ } else {
+ return hex;
+ }
+ }
+
+
function removeLeading0(hex) {
if (hex[0] == "0") {
return hex.substr(1);