| 1 |
// Package ecc implements a generic interface for ECDH, ECDSA, and EdDSA. |
| 2 |
package ecc |
| 3 |
|
| 4 |
import ( |
| 5 |
"io" |
| 6 |
"math/big" |
| 7 |
) |
| 8 |
|
| 9 |
type Curve interface { |
| 10 |
GetCurveName() string |
| 11 |
} |
| 12 |
|
| 13 |
type ECDSACurve interface { |
| 14 |
Curve |
| 15 |
MarshalIntegerPoint(x, y *big.Int) []byte |
| 16 |
UnmarshalIntegerPoint([]byte) (x, y *big.Int) |
| 17 |
MarshalIntegerSecret(d *big.Int) []byte |
| 18 |
UnmarshalIntegerSecret(d []byte) *big.Int |
| 19 |
MarshalFieldInteger(d *big.Int) []byte |
| 20 |
UnmarshalFieldInteger(d []byte) *big.Int |
| 21 |
GenerateECDSA(rand io.Reader) (x, y, secret *big.Int, err error) |
| 22 |
Sign(rand io.Reader, x, y, d *big.Int, hash []byte) (r, s *big.Int, err error) |
| 23 |
Verify(x, y *big.Int, hash []byte, r, s *big.Int) bool |
| 24 |
ValidateECDSA(x, y *big.Int, secret []byte) error |
| 25 |
} |
| 26 |
|
| 27 |
type EdDSACurve interface { |
| 28 |
Curve |
| 29 |
MarshalBytePoint(x []byte) []byte |
| 30 |
UnmarshalBytePoint([]byte) (x []byte) |
| 31 |
MarshalByteSecret(d []byte) []byte |
| 32 |
UnmarshalByteSecret(d []byte) []byte |
| 33 |
MarshalSignature(sig []byte) (r, s []byte) |
| 34 |
UnmarshalSignature(r, s []byte) (sig []byte) |
| 35 |
GenerateEdDSA(rand io.Reader) (pub, priv []byte, err error) |
| 36 |
Sign(publicKey, privateKey, message []byte) (sig []byte, err error) |
| 37 |
Verify(publicKey, message, sig []byte) bool |
| 38 |
ValidateEdDSA(publicKey, privateKey []byte) (err error) |
| 39 |
} |
| 40 |
type ECDHCurve interface { |
| 41 |
Curve |
| 42 |
MarshalBytePoint([]byte) (encoded []byte) |
| 43 |
UnmarshalBytePoint(encoded []byte) []byte |
| 44 |
MarshalByteSecret(d []byte) []byte |
| 45 |
UnmarshalByteSecret(d []byte) []byte |
| 46 |
GenerateECDH(rand io.Reader) (point []byte, secret []byte, err error) |
| 47 |
Encaps(rand io.Reader, point []byte) (ephemeral, sharedSecret []byte, err error) |
| 48 |
Decaps(ephemeral, secret []byte) (sharedSecret []byte, err error) |
| 49 |
ValidateECDH(public []byte, secret []byte) error |
| 50 |
} |