X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=gost3410%2Fpublic.go;h=675431cf816f72bc4448c5916ef1fe3fb564ad9c;hb=c40d1e5634cf6d540d908a57423f4b504e39f186;hp=08e1414000bf6e3d42710b5485e002d74b6e46c7;hpb=c07494bbd559b9d00f391e28cfd070e18afe9900;p=gogost.git diff --git a/gost3410/public.go b/gost3410/public.go index 08e1414..675431c 100644 --- a/gost3410/public.go +++ b/gost3410/public.go @@ -1,5 +1,5 @@ // GoGOST -- Pure Go GOST cryptographic functions library -// Copyright (C) 2015-2019 Sergey Matveev +// Copyright (C) 2015-2020 Sergey Matveev // // 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 @@ -16,7 +16,7 @@ package gost3410 import ( - "errors" + "fmt" "math/big" ) @@ -30,7 +30,7 @@ type PublicKey struct { 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] @@ -54,11 +54,14 @@ func (pub *PublicKey) Raw() []byte { 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)