1 // Copyright (c) 2013-2017 The btcsuite developers
2 // Copyright (c) 2015-2021 The Decred developers
3 // Use of this source code is governed by an ISC
4 // license that can be found in the LICENSE file.
5 6 package schnorr
7 8 // ErrorKind identifies a kind of error. It has full support for errors.Is
9 // and errors.As, so the caller can directly check against an error kind when
10 // determining the reason for an error.
11 type ErrorKind string
12 13 const (
14 // ErrInvalidHashLen indicates that the input hash to sign or verify is not
15 // the required length.
16 ErrInvalidHashLen = ErrorKind("ErrInvalidHashLen")
17 18 // ErrPrivateKeyIsZero indicates an attempt was made to sign a message with
19 // a private key that is equal to zero.
20 ErrPrivateKeyIsZero = ErrorKind("ErrPrivateKeyIsZero")
21 22 // ErrSchnorrHashValue indicates that the hash of (R || m) was too large and
23 // so a new nonce should be used.
24 ErrSchnorrHashValue = ErrorKind("ErrSchnorrHashValue")
25 26 // ErrPubKeyNotOnCurve indicates that a point was not on the given elliptic
27 // curve.
28 ErrPubKeyNotOnCurve = ErrorKind("ErrPubKeyNotOnCurve")
29 30 // ErrSigRYIsOdd indicates that the calculated Y value of R was odd.
31 ErrSigRYIsOdd = ErrorKind("ErrSigRYIsOdd")
32 33 // ErrSigRNotOnCurve indicates that the calculated or given point R for some
34 // signature was not on the curve.
35 ErrSigRNotOnCurve = ErrorKind("ErrSigRNotOnCurve")
36 37 // ErrUnequalRValues indicates that the calculated point R for some
38 // signature was not the same as the given R value for the signature.
39 ErrUnequalRValues = ErrorKind("ErrUnequalRValues")
40 41 // ErrSigTooShort is returned when a signature is too short.
42 ErrSigTooShort = ErrorKind("ErrSigTooShort")
43 44 // ErrSigTooLong is returned when a signature is too long.
45 ErrSigTooLong = ErrorKind("ErrSigTooLong")
46 47 // ErrSigRTooBig is returned when a signature has r greater than or equal
48 // to the field prime.
49 ErrSigRTooBig = ErrorKind("ErrSigRTooBig")
50 51 // ErrSigSTooBig is returned when a signature has s greater than or equal
52 // to the group order.
53 ErrSigSTooBig = ErrorKind("ErrSigSTooBig")
54 )
55 56 // Error satisfies the error interface.
57 func (e ErrorKind) Error() string { return string(e) }
58 59 // Error identifies an error related to a schnorr signature.
60 type Error struct {
61 Err error
62 Description string
63 }
64 65 // Error satisfies the error interface.
66 func (e Error) Error() string { return e.Description }
67 68 // Unwrap returns the underlying wrapped error.
69 func (e Error) Unwrap() error { return e.Err }
70 71 func signatureError(kind ErrorKind, desc string) Error {
72 return Error{Err: kind, Description: desc}
73 }
74