]> Cypherpunks.ru repositories - gogost.git/blobdiff - gost3410/public.go
Download link for 5.14.1 release
[gogost.git] / gost3410 / public.go
index ef5926bc336a03705ef44eaceb00f4656cc574bb..a8669cf38075ee436b8c5767122aa0898a25fb4a 100644 (file)
@@ -1,5 +1,5 @@
 // GoGOST -- Pure Go GOST cryptographic functions library
-// Copyright (C) 2015-2023 Sergey Matveev <stargrave@stargrave.org>
+// Copyright (C) 2015-2024 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
@@ -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)
+}