|
|
@@ -15,17 +15,17 @@ func fpAddRdc(z, x, y *Fp) { |
|
|
|
z[i], carry = bits.Add64(x[i], y[i], carry) |
|
|
|
} |
|
|
|
|
|
|
|
// z = z - p503x2 |
|
|
|
// z = z - pX2 |
|
|
|
carry = 0 |
|
|
|
for i := 0; i < FP_WORDS; i++ { |
|
|
|
z[i], carry = bits.Sub64(z[i], p503x2[i], carry) |
|
|
|
z[i], carry = bits.Sub64(z[i], pX2[i], carry) |
|
|
|
} |
|
|
|
|
|
|
|
// if z<0 add p503x2 back |
|
|
|
// if z<0 add pX2 back |
|
|
|
mask := uint64(0 - carry) |
|
|
|
carry = 0 |
|
|
|
for i := 0; i < FP_WORDS; i++ { |
|
|
|
z[i], carry = bits.Add64(z[i], p503x2[i]&mask, carry) |
|
|
|
z[i], carry = bits.Add64(z[i], pX2[i]&mask, carry) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -33,16 +33,16 @@ func fpAddRdc(z, x, y *Fp) { |
|
|
|
func fpSubRdc(z, x, y *Fp) { |
|
|
|
var borrow uint64 |
|
|
|
|
|
|
|
// z = z - p503x2 |
|
|
|
// z = z - pX2 |
|
|
|
for i := 0; i < FP_WORDS; i++ { |
|
|
|
z[i], borrow = bits.Sub64(x[i], y[i], borrow) |
|
|
|
} |
|
|
|
|
|
|
|
// if z<0 add p503x2 back |
|
|
|
// if z<0 add pX2 back |
|
|
|
mask := uint64(0 - borrow) |
|
|
|
borrow = 0 |
|
|
|
for i := 0; i < FP_WORDS; i++ { |
|
|
|
z[i], borrow = bits.Add64(z[i], p503x2[i]&mask, borrow) |
|
|
|
z[i], borrow = bits.Add64(z[i], pX2[i]&mask, borrow) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -116,7 +116,7 @@ func fpMontRdc(z *Fp, x *FpX2) { |
|
|
|
for i := 0; i < FP_WORDS; i++ { |
|
|
|
for j := 0; j < i; j++ { |
|
|
|
if j < (i - count + 1) { |
|
|
|
hi, lo = bits.Mul64(z[j], p503p1[i-j]) |
|
|
|
hi, lo = bits.Mul64(z[j], p1[i-j]) |
|
|
|
v, carry = bits.Add64(lo, v, 0) |
|
|
|
u, carry = bits.Add64(hi, u, carry) |
|
|
|
t += carry |
|
|
@@ -138,7 +138,7 @@ func fpMontRdc(z *Fp, x *FpX2) { |
|
|
|
} |
|
|
|
for j := i - FP_WORDS + 1; j < FP_WORDS; j++ { |
|
|
|
if j < (FP_WORDS - count) { |
|
|
|
hi, lo = bits.Mul64(z[j], p503p1[i-j]) |
|
|
|
hi, lo = bits.Mul64(z[j], p1[i-j]) |
|
|
|
v, carry = bits.Add64(lo, v, 0) |
|
|
|
u, carry = bits.Add64(hi, u, carry) |
|
|
|
t += carry |