]> Sergey Matveev's repositories - meta4ra.git/blob - internal/thirdparty.go
*-hashes-detect, *-hash, *-check -stdin/-all-hashes, optional builtins
[meta4ra.git] / internal / thirdparty.go
1 //go:build thirdparty
2
3 // meta4ra -- Metalink 4.0 utilities
4 // Copyright (C) 2021-2024 Sergey Matveev <stargrave@stargrave.org>
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, version 3 of the License.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18 package internal
19
20 import (
21         "hash"
22
23         "github.com/dchest/skein"
24         "go.cypherpunks.ru/gogost/v5/gost34112012256"
25         "go.cypherpunks.ru/gogost/v5/gost34112012512"
26         "golang.org/x/crypto/blake2b"
27         "golang.org/x/crypto/sha3"
28         "lukechampine.com/blake3"
29 )
30
31 func init() {
32         // Those are better than SHA2, prepend them
33         name := "shake256"
34         BuiltinHashes[name] = func() hash.Hash {
35                 return sha3.NewShake256()
36         }
37         HashesDefault = name + ":builtin," + HashesDefault
38
39         name = "shake128"
40         BuiltinHashes[name] = func() hash.Hash {
41                 return sha3.NewShake128()
42         }
43         HashesDefault = name + ":builtin," + HashesDefault
44
45         name = "skein-512"
46         BuiltinHashes[name] = func() hash.Hash {
47                 return skein.NewHash(64)
48         }
49         HashesDefault = name + ":builtin," + HashesDefault
50
51         name = "blake2b-256"
52         BuiltinHashes[name] = func() hash.Hash {
53                 h, err := blake2b.New(32, nil)
54                 if err != nil {
55                         panic(err)
56                 }
57                 return h
58         }
59         HashesDefault = name + ":builtin," + HashesDefault
60
61         name = "blake2b-512"
62         BuiltinHashes[name] = func() hash.Hash {
63                 h, err := blake2b.New(64, nil)
64                 if err != nil {
65                         panic(err)
66                 }
67                 return h
68         }
69         HashesDefault = name + ":builtin," + HashesDefault
70
71         name = "blake3-256"
72         BuiltinHashes[name] = func() hash.Hash {
73                 return blake3.New(32, nil)
74         }
75         HashesDefault = name + ":builtin," + HashesDefault
76
77         // Those are slower than SHA2, append them
78         name = "streebog-512"
79         BuiltinHashes[name] = func() hash.Hash {
80                 return gost34112012512.New()
81         }
82         HashesDefault = HashesDefault + "," + name + ":builtin"
83
84         name = "streebog-256"
85         BuiltinHashes[name] = func() hash.Hash {
86                 return gost34112012256.New()
87         }
88         HashesDefault = HashesDefault + "," + name + ":builtin"
89
90         name = "xxh3-128"
91         BuiltinHashes[name] = func() hash.Hash {
92                 return NewXXH3128()
93         }
94         HashesDefault = HashesDefault + "," + name + ":builtin"
95 }