1 // Copyright (c) 2014 Conformal Systems LLC. 2 // Copyright (c) 2015-2020 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 10 // when determining the reason for an error. 11 type ErrorKind string 12 13 // These constants are used to identify a specific RuleError. 14 const ( 15 // ErrInvalidHashLen indicates that the input hash to sign or verify is not 16 // the required length. 17 ErrInvalidHashLen = ErrorKind("ErrInvalidHashLen") 18 19 // ErrPrivateKeyIsZero indicates an attempt was made to sign a message with 20 // a private key that is equal to zero. 21 ErrPrivateKeyIsZero = ErrorKind("ErrPrivateKeyIsZero") 22 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 27 // ErrPubKeyNotOnCurve indicates that a point was not on the given elliptic 28 // curve. 29 ErrPubKeyNotOnCurve = ErrorKind("ErrPubKeyNotOnCurve") 30 31 // ErrSigRYIsOdd indicates that the calculated Y value of R was odd. 32 ErrSigRYIsOdd = ErrorKind("ErrSigRYIsOdd") 33 34 // ErrSigRNotOnCurve indicates that the calculated or given point R for some 35 // signature was not on the curve. 36 ErrSigRNotOnCurve = ErrorKind("ErrSigRNotOnCurve") 37 38 // ErrUnequalRValues indicates that the calculated point R for some 39 // signature was not the same as the given R value for the signature. 40 ErrUnequalRValues = ErrorKind("ErrUnequalRValues") 41 42 // ErrSigTooShort is returned when a signature that should be a Schnorr 43 // signature is too short. 44 ErrSigTooShort = ErrorKind("ErrSigTooShort") 45 46 // ErrSigTooLong is returned when a signature that should be a Schnorr 47 // signature is too long. 48 ErrSigTooLong = ErrorKind("ErrSigTooLong") 49 50 // ErrSigRTooBig is returned when a signature has r with a value that is 51 // greater than or equal to the prime of the field underlying the group. 52 ErrSigRTooBig = ErrorKind("ErrSigRTooBig") 53 54 // ErrSigSTooBig is returned when a signature has s with a value that is 55 // greater than or equal to the group order. 56 ErrSigSTooBig = ErrorKind("ErrSigSTooBig") 57 ) 58 59 // Error satisfies the error interface and prints human-readable errors. 60 func (e ErrorKind) Error() string { 61 return string(e) 62 } 63 64 // Error identifies an error related to a schnorr signature. It has full 65 // support for errors.Is and errors.As, so the caller can ascertain the 66 // specific reason for the error by checking the underlying error. 67 type Error struct { 68 Err error 69 Description string 70 } 71 72 // Error satisfies the error interface and prints human-readable errors. 73 func (e Error) Error() string { 74 return e.Description 75 } 76 77 // Unwrap returns the underlying wrapped error. 78 func (e Error) Unwrap() error { 79 return e.Err 80 } 81 82 // signatureError creates an Error given a set of arguments. 83 func signatureError(kind ErrorKind, desc string) Error { 84 return Error{Err: kind, Description: desc} 85 } 86