MAGIC - fix Inverse method

This commit is contained in:
Emman 2021-02-10 15:26:20 +08:00
parent 86ccc78778
commit de1c178aed
2 changed files with 8 additions and 8 deletions

View File

@ -194,16 +194,16 @@ func (curve p256Curve) Inverse(k *big.Int) *big.Int {
p256OrdMul(x, x, t) // _fffffffeffffffffffffffffffffffff
sqrs := []uint8{
3, 3, 11, 5, 3, 5, 1,
3, 7, 5, 9, 7, 2, 2,
5, 4, 5, 2, 2, 7, 3,
5, 5, 6, 2, 6, 3, 5,
4, 3, 11, 5, 3, 5, 1,
3, 7, 5, 9, 7, 5, 5,
4, 5, 2, 2, 7, 3, 5,
5, 6, 2, 6, 3, 5,
}
muls := [][]uint64{
_111, _1, _1111, _1111, _101, _10101, _1,
_1, _111, _11, _101, _10101, _11, _1,
_111, _111, _1111, _11, _1, _1, _1,
_111, _111, _10101, _1, _1, _1, _1}
_1, _111, _11, _101, _10101, _10101, _111,
_111, _1111, _11, _1, _1, _1, _111,
_111, _10101, _1, _1, _1, _1}
for i, s := range sqrs {
p256OrdSqr(x, x, int(s))

View File

@ -304,7 +304,7 @@ func Test_Inverse(t *testing.T) {
nm2 := new(big.Int).Sub(n, big.NewInt(2))
nm2a := make([]uint64, 4)
fromBig(nm2a, nm2)
fmt.Printf("%b, %b, %b, %b\n", nm2a[0], nm2a[1], nm2a[2], nm2a[3])
fmt.Printf("%0b, %0b, %b, %b\n", nm2a[0], nm2a[1], nm2a[2], nm2a[3])
xInv1 := fermatInverse(x, n)
fmt.Printf("expect=%s\n", hex.EncodeToString(xInv1.Bytes()))
_ = P256()