]> Sergey Matveev's repositories - meta4ra.git/blobdiff - internal/thirdparty.go
*-hashes-detect, *-hash, *-check -stdin/-all-hashes, optional builtins
[meta4ra.git] / internal / thirdparty.go
diff --git a/internal/thirdparty.go b/internal/thirdparty.go
new file mode 100644 (file)
index 0000000..9c1b726
--- /dev/null
@@ -0,0 +1,95 @@
+//go:build thirdparty
+
+// meta4ra -- Metalink 4.0 utilities
+// Copyright (C) 2021-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
+// the Free Software Foundation, version 3 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+package internal
+
+import (
+       "hash"
+
+       "github.com/dchest/skein"
+       "go.cypherpunks.ru/gogost/v5/gost34112012256"
+       "go.cypherpunks.ru/gogost/v5/gost34112012512"
+       "golang.org/x/crypto/blake2b"
+       "golang.org/x/crypto/sha3"
+       "lukechampine.com/blake3"
+)
+
+func init() {
+       // Those are better than SHA2, prepend them
+       name := "shake256"
+       BuiltinHashes[name] = func() hash.Hash {
+               return sha3.NewShake256()
+       }
+       HashesDefault = name + ":builtin," + HashesDefault
+
+       name = "shake128"
+       BuiltinHashes[name] = func() hash.Hash {
+               return sha3.NewShake128()
+       }
+       HashesDefault = name + ":builtin," + HashesDefault
+
+       name = "skein-512"
+       BuiltinHashes[name] = func() hash.Hash {
+               return skein.NewHash(64)
+       }
+       HashesDefault = name + ":builtin," + HashesDefault
+
+       name = "blake2b-256"
+       BuiltinHashes[name] = func() hash.Hash {
+               h, err := blake2b.New(32, nil)
+               if err != nil {
+                       panic(err)
+               }
+               return h
+       }
+       HashesDefault = name + ":builtin," + HashesDefault
+
+       name = "blake2b-512"
+       BuiltinHashes[name] = func() hash.Hash {
+               h, err := blake2b.New(64, nil)
+               if err != nil {
+                       panic(err)
+               }
+               return h
+       }
+       HashesDefault = name + ":builtin," + HashesDefault
+
+       name = "blake3-256"
+       BuiltinHashes[name] = func() hash.Hash {
+               return blake3.New(32, nil)
+       }
+       HashesDefault = name + ":builtin," + HashesDefault
+
+       // Those are slower than SHA2, append them
+       name = "streebog-512"
+       BuiltinHashes[name] = func() hash.Hash {
+               return gost34112012512.New()
+       }
+       HashesDefault = HashesDefault + "," + name + ":builtin"
+
+       name = "streebog-256"
+       BuiltinHashes[name] = func() hash.Hash {
+               return gost34112012256.New()
+       }
+       HashesDefault = HashesDefault + "," + name + ":builtin"
+
+       name = "xxh3-128"
+       BuiltinHashes[name] = func() hash.Hash {
+               return NewXXH3128()
+       }
+       HashesDefault = HashesDefault + "," + name + ":builtin"
+}