X-Git-Url: http://www.git.cypherpunks.ru/?p=gogost.git;a=blobdiff_plain;f=gost3410%2Fpublic.go;fp=gost3410%2Fpublic.go;h=a1bf539c2ae52abf5a64de05cf27eb0e7bfa6b79;hp=ef5926bc336a03705ef44eaceb00f4656cc574bb;hb=b7f69d1826caacffd042ca8660aba41d0945de0f;hpb=e077d5f903e233fbefed0815be21be5f8f482017 diff --git a/gost3410/public.go b/gost3410/public.go index ef5926b..a1bf539 100644 --- a/gost3410/public.go +++ b/gost3410/public.go @@ -22,7 +22,7 @@ import ( ) type PublicKey struct { - C *Curve + C *Curve X, Y *big.Int } @@ -149,3 +149,43 @@ func (our *PublicKey) Equal(theirKey crypto.PublicKey) bool { } return our.X.Cmp(their.X) == 0 && our.Y.Cmp(their.Y) == 0 && our.C.Equal(their.C) } + +type PublicKeyReverseDigest struct { + Pub *PublicKey +} + +func (pub PublicKeyReverseDigest) VerifyDigest( + digest, signature []byte, +) (bool, error) { + dgst := make([]byte, len(digest)) + for i := 0; i < len(digest); i++ { + dgst[i] = digest[len(digest)-i-1] + } + return pub.Pub.VerifyDigest(dgst, signature) +} + +func (pub PublicKeyReverseDigest) Equal(theirKey crypto.PublicKey) bool { + return pub.Pub.Equal(theirKey) +} + +type PublicKeyReverseDigestAndSignature struct { + Pub *PublicKey +} + +func (pub PublicKeyReverseDigestAndSignature) VerifyDigest( + digest, signature []byte, +) (bool, error) { + dgst := make([]byte, len(digest)) + for i := 0; i < len(digest); i++ { + dgst[i] = digest[len(digest)-i-1] + } + sign := make([]byte, len(signature)) + for i := 0; i < len(signature); i++ { + sign[i] = signature[len(signature)-i-1] + } + return pub.Pub.VerifyDigest(dgst, sign) +} + +func (pub PublicKeyReverseDigestAndSignature) Equal(theirKey crypto.PublicKey) bool { + return pub.Pub.Equal(theirKey) +}