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