]> Cypherpunks.ru repositories - gogost.git/commitdiff
Example 34.10-2012-256 signing/verifying
authorSergey Matveev <stargrave@stargrave.org>
Fri, 24 Jul 2020 11:51:52 +0000 (14:51 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 24 Jul 2020 11:58:09 +0000 (14:58 +0300)
README
www.texi

diff --git a/README b/README
index 68317a60c86902f6d0df13fc1124c0789daed488..5d32fa068fd5a1b5f2d4e5d5e0b6c52bb562aa90 100644 (file)
--- a/README
+++ b/README
@@ -32,6 +32,31 @@ Known problems:
 * intermediate calculation values are not zeroed
 * 34.10 is not time constant and slow
 
+Example 34.10-2012-256 keypair generation, signing and verifying:
+
+    import (
+        "crypto/rand"
+        "io"
+        "go.cypherpunks.ru/gogost/v4/gost3410"
+        "go.cypherpunks.ru/gogost/v4/gost34112012256"
+    )
+    func main() {
+        data := []byte("data to be signed")
+        hasher := gost34112012256.New()
+        _, err := hasher.Write(data)
+        dgst := hasher.Sum(nil)
+        curve := gost3410.CurveIdtc26gost34102012256paramSetB()
+        prvRaw := make([]byte, int(gost3410.Mode2001))
+        _, err = io.ReadFull(rand.Reader, prvRaw)
+        prv, err := gost3410.NewPrivateKey(curve, gost3410.Mode2001, prvRaw)
+        pub, err := prv.PublicKey()
+        pubRaw := pub.Raw()
+        sign, err := prv.Sign(rand.Reader, dgst, nil)
+        pub, err = gost3410.NewPublicKey(curve, gost3410.Mode2001, pubRaw)
+        isValid, err := pub.VerifyDigest(dgst, sign)
+        if !isValid { panic("signature is invalid") }
+    }
+
 GoGOST is free software: see the file COPYING for copying conditions.
 
 GoGOST'es home page is: http://www.gogost.cypherpunks.ru/
index 541f8967dbaf9d5d96cd91391b9df796458751bf..94bf7161663b9b54c0e3c9a84448f5cfeea687a0 100644 (file)
--- a/www.texi
+++ b/www.texi
@@ -59,6 +59,33 @@ Currently supported algorithms are:
 Probably you could be interested in
 @url{//www.gostls13.cypherpunks.ru/, Go's support of GOST TLS 1.3}.
 
+Example 34.10-2012-256 keypair generation, signing and verifying:
+
+@verbatim
+import (
+    "crypto/rand"
+    "io"
+    "go.cypherpunks.ru/gogost/v4/gost3410"
+    "go.cypherpunks.ru/gogost/v4/gost34112012256"
+)
+func main() {
+    data := []byte("data to be signed")
+    hasher := gost34112012256.New()
+    _, err := hasher.Write(data)
+    dgst := hasher.Sum(nil)
+    curve := gost3410.CurveIdtc26gost34102012256paramSetB()
+    prvRaw := make([]byte, int(gost3410.Mode2001))
+    _, err = io.ReadFull(rand.Reader, prvRaw)
+    prv, err := gost3410.NewPrivateKey(curve, gost3410.Mode2001, prvRaw)
+    pub, err := prv.PublicKey()
+    pubRaw := pub.Raw()
+    sign, err := prv.Sign(rand.Reader, dgst, nil)
+    pub, err = gost3410.NewPublicKey(curve, gost3410.Mode2001, pubRaw)
+    isValid, err := pub.VerifyDigest(dgst, sign)
+    if !isValid { panic("signature is invalid") }
+}
+@end verbatim
+
 Please send questions, bug reports and patches to
 @url{https://lists.cypherpunks.ru/mailman/listinfo/gost, gost}
 mailing list. Announcements also go to this mailing list.