|
|
@ -283,38 +283,12 @@ function curveFpFromBigInteger(x) { |
|
|
|
return new ECFieldElementFp(this.q, x); |
|
|
|
} |
|
|
|
|
|
|
|
// for now, work with hex strings because they're easier in JS
|
|
|
|
function curveFpDecodePointHex(s) { |
|
|
|
switch(parseInt(s.substr(0,2), 16)) { // first byte
|
|
|
|
case 0: |
|
|
|
return this.infinity; |
|
|
|
case 2: |
|
|
|
case 3: |
|
|
|
// point compression not supported yet
|
|
|
|
return null; |
|
|
|
case 4: |
|
|
|
case 6: |
|
|
|
case 7: |
|
|
|
var len = (s.length - 2) / 2; |
|
|
|
var xHex = s.substr(2, len); |
|
|
|
var yHex = s.substr(len+2, len); |
|
|
|
|
|
|
|
return new ECPointFp(this, |
|
|
|
this.fromBigInteger(new BigInteger(xHex, 16)), |
|
|
|
this.fromBigInteger(new BigInteger(yHex, 16))); |
|
|
|
|
|
|
|
default: // unsupported
|
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ECCurveFp.prototype.getQ = curveFpGetQ; |
|
|
|
ECCurveFp.prototype.getA = curveFpGetA; |
|
|
|
ECCurveFp.prototype.getB = curveFpGetB; |
|
|
|
ECCurveFp.prototype.equals = curveFpEquals; |
|
|
|
ECCurveFp.prototype.getInfinity = curveFpGetInfinity; |
|
|
|
ECCurveFp.prototype.fromBigInteger = curveFpFromBigInteger; |
|
|
|
ECCurveFp.prototype.decodePointHex = curveFpDecodePointHex; |
|
|
|
|
|
|
|
// prepends 0 if bytes < len
|
|
|
|
// cuts off start if bytes > len
|
|
|
|