X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=internal%2Fthirdparty.go;fp=internal%2Fthirdparty.go;h=9c1b726ac6ae9bddd81a42bc4e95db5c998cb4c3;hb=be69a4fc0c240c2772a0f0bf0955b39783e4c48a;hp=0000000000000000000000000000000000000000;hpb=ce902a58a32f42801603475c67dd75da86d4502a;p=meta4ra.git diff --git a/internal/thirdparty.go b/internal/thirdparty.go new file mode 100644 index 0000000..9c1b726 --- /dev/null +++ b/internal/thirdparty.go @@ -0,0 +1,95 @@ +//go:build thirdparty + +// meta4ra -- Metalink 4.0 utilities +// Copyright (C) 2021-2024 Sergey Matveev +// +// 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 . + +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" +}