// GoGOST -- Pure Go GOST cryptographic functions library
-// Copyright (C) 2015-2019 Sergey Matveev <stargrave@stargrave.org>
+// Copyright (C) 2015-2020 Sergey Matveev <stargrave@stargrave.org>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
package gost3410
import (
- "errors"
+ "fmt"
"math/big"
)
func NewPublicKey(curve *Curve, mode Mode, raw []byte) (*PublicKey, error) {
key := make([]byte, 2*int(mode))
if len(raw) != len(key) {
- return nil, errors.New("Invalid public key length")
+ return nil, fmt.Errorf("gogost/gost3410: len(key) != %d", len(key))
}
for i := 0; i < len(key); i++ {
key[i] = raw[len(raw)-i-1]
func (pub *PublicKey) VerifyDigest(digest, signature []byte) (bool, error) {
if len(signature) != 2*int(pub.Mode) {
- return false, errors.New("Invalid signature length")
+ return false, fmt.Errorf("gogost/gost3410: len(signature) != %d", 2*int(pub.Mode))
}
s := bytes2big(signature[:pub.Mode])
r := bytes2big(signature[pub.Mode:])
- if r.Cmp(zero) <= 0 || r.Cmp(pub.C.Q) >= 0 || s.Cmp(zero) <= 0 || s.Cmp(pub.C.Q) >= 0 {
+ if r.Cmp(zero) <= 0 ||
+ r.Cmp(pub.C.Q) >= 0 ||
+ s.Cmp(zero) <= 0 ||
+ s.Cmp(pub.C.Q) >= 0 {
return false, nil
}
e := bytes2big(digest)