// Copyright (c) 2013-2017 The btcsuite developers // Copyright (c) 2015-2021 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. package schnorr // ErrorKind identifies a kind of error. It has full support for errors.Is // and errors.As, so the caller can directly check against an error kind when // determining the reason for an error. type ErrorKind string const ( // ErrInvalidHashLen indicates that the input hash to sign or verify is not // the required length. ErrInvalidHashLen = ErrorKind("ErrInvalidHashLen") // ErrPrivateKeyIsZero indicates an attempt was made to sign a message with // a private key that is equal to zero. ErrPrivateKeyIsZero = ErrorKind("ErrPrivateKeyIsZero") // ErrSchnorrHashValue indicates that the hash of (R || m) was too large and // so a new nonce should be used. ErrSchnorrHashValue = ErrorKind("ErrSchnorrHashValue") // ErrPubKeyNotOnCurve indicates that a point was not on the given elliptic // curve. ErrPubKeyNotOnCurve = ErrorKind("ErrPubKeyNotOnCurve") // ErrSigRYIsOdd indicates that the calculated Y value of R was odd. ErrSigRYIsOdd = ErrorKind("ErrSigRYIsOdd") // ErrSigRNotOnCurve indicates that the calculated or given point R for some // signature was not on the curve. ErrSigRNotOnCurve = ErrorKind("ErrSigRNotOnCurve") // ErrUnequalRValues indicates that the calculated point R for some // signature was not the same as the given R value for the signature. ErrUnequalRValues = ErrorKind("ErrUnequalRValues") // ErrSigTooShort is returned when a signature is too short. ErrSigTooShort = ErrorKind("ErrSigTooShort") // ErrSigTooLong is returned when a signature is too long. ErrSigTooLong = ErrorKind("ErrSigTooLong") // ErrSigRTooBig is returned when a signature has r greater than or equal // to the field prime. ErrSigRTooBig = ErrorKind("ErrSigRTooBig") // ErrSigSTooBig is returned when a signature has s greater than or equal // to the group order. ErrSigSTooBig = ErrorKind("ErrSigSTooBig") ) // Error satisfies the error interface. func (e ErrorKind) Error() string { return string(e) } // Error identifies an error related to a schnorr signature. type Error struct { Err error Description string } // Error satisfies the error interface. func (e Error) Error() string { return e.Description } // Unwrap returns the underlying wrapped error. func (e Error) Unwrap() error { return e.Err } func signatureError(kind ErrorKind, desc string) Error { return Error{Err: kind, Description: desc} }