1 // GoGOST -- Pure Go GOST cryptographic functions library
2 // Copyright (C) 2015-2023 Sergey Matveev <stargrave@stargrave.org>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, version 3 of the License.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
25 func TestSignerInterface(t *testing.T) {
26 c := CurveIdGostR34102001TestParamSet()
27 prvRaw := make([]byte, c.PointSize())
28 _, err := io.ReadFull(rand.Reader, prvRaw)
32 prv, err := NewPrivateKey(c, prvRaw)
36 var _ crypto.Signer = prv
37 var _ crypto.Signer = &PrivateKeyReverseDigest{prv}
38 var _ crypto.Signer = &PrivateKeyReverseDigestAndSignature{prv}
41 func TestSignerReverseDigest(t *testing.T) {
42 dgst := make([]byte, 32)
43 _, err := io.ReadFull(rand.Reader, dgst)
47 prv0, err := GenPrivateKey(CurveIdGostR34102001TestParamSet(), rand.Reader)
51 pub0 := prv0.Public().(*PublicKey)
52 sign, err := prv0.Sign(rand.Reader, dgst, nil)
56 valid, err := pub0.VerifyDigest(dgst, sign)
63 var _ crypto.PublicKey = pub0
65 prv1 := PrivateKeyReverseDigest{prv0}
66 pub1 := PublicKeyReverseDigest{prv1.Public().(*PublicKey)}
67 sign, err = prv1.Sign(rand.Reader, dgst, nil)
71 valid, err = pub1.VerifyDigest(dgst, sign)
79 prv2 := PrivateKeyReverseDigestAndSignature{prv0}
80 pub2 := PublicKeyReverseDigestAndSignature{prv2.Public().(*PublicKey)}
81 sign, err = prv2.Sign(rand.Reader, dgst, nil)
85 valid, err = pub2.VerifyDigest(dgst, sign)