1
2
3
4
5
6
7 package elliptic
8
9 import (
10 "crypto/internal/nistec"
11 "math/big"
12 )
13
14 func (c p256Curve) Inverse(k *big.Int) *big.Int {
15 if k.Sign() < 0 {
16
17 k = new(big.Int).Neg(k)
18 }
19 if k.Cmp(c.params.N) >= 0 {
20
21 k = new(big.Int).Mod(k, c.params.N)
22 }
23 scalar := k.FillBytes(make([]byte, 32))
24 inverse, err := nistec.P256OrdInverse(scalar)
25 if err != nil {
26 panic("crypto/elliptic: nistec rejected normalized scalar")
27 }
28 return new(big.Int).SetBytes(inverse)
29 }
30
View as plain text