ec/dsa: extract P_OVER_FOUR as a curve specific constant

This actually resolves a possible bug if multiple ecparams were used
(aka different values for P_OVER_FOUR, but only the cached was used).
This commit is contained in:
Daniel Cousens 2014-05-17 12:03:23 +10:00
parent 1e54c521d5
commit 0865f09d20
2 changed files with 8 additions and 8 deletions

View file

@ -343,11 +343,13 @@ ECPointFp.decodeFrom = function (curve, buffer) {
var p = curve.getQ()
// We precalculate (p + 1) / 4 where p is the field order
var P_OVER_FOUR = p.add(BigInteger.ONE).shiftRight(2)
if (!curve.P_OVER_FOUR) {
curve.P_OVER_FOUR = p.add(BigInteger.ONE).shiftRight(2)
}
// Convert x to point
var alpha = x.square().multiply(x).add(SEVEN).mod(p)
var beta = alpha.modPow(P_OVER_FOUR, p)
var beta = alpha.modPow(curve.P_OVER_FOUR, p)
// If beta is even, but y isn't, or vice versa, then convert it,
// otherwise we're done and y == beta.