diff options
| author | Rutger Broekhoff | 2023-12-29 21:31:53 +0100 |
|---|---|---|
| committer | Rutger Broekhoff | 2023-12-29 21:31:53 +0100 |
| commit | 404aeae4545d2426c089a5f8d5e82dae56f5212b (patch) | |
| tree | 2d84e00af272b39fc04f3795ae06bc48970e57b5 /vendor/github.com/minio/md5-simd/md5.go | |
| parent | 209d8b0187ed025dec9ac149ebcced3462877bff (diff) | |
| download | gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.tar.gz gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.zip | |
Make Nix builds work
Diffstat (limited to 'vendor/github.com/minio/md5-simd/md5.go')
| -rw-r--r-- | vendor/github.com/minio/md5-simd/md5.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/vendor/github.com/minio/md5-simd/md5.go b/vendor/github.com/minio/md5-simd/md5.go new file mode 100644 index 0000000..11b0cb9 --- /dev/null +++ b/vendor/github.com/minio/md5-simd/md5.go | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | package md5simd | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "crypto/md5" | ||
| 5 | "hash" | ||
| 6 | "sync" | ||
| 7 | ) | ||
| 8 | |||
| 9 | const ( | ||
| 10 | // The blocksize of MD5 in bytes. | ||
| 11 | BlockSize = 64 | ||
| 12 | |||
| 13 | // The size of an MD5 checksum in bytes. | ||
| 14 | Size = 16 | ||
| 15 | |||
| 16 | // internalBlockSize is the internal block size. | ||
| 17 | internalBlockSize = 32 << 10 | ||
| 18 | ) | ||
| 19 | |||
| 20 | type Server interface { | ||
| 21 | NewHash() Hasher | ||
| 22 | Close() | ||
| 23 | } | ||
| 24 | |||
| 25 | type Hasher interface { | ||
| 26 | hash.Hash | ||
| 27 | Close() | ||
| 28 | } | ||
| 29 | |||
| 30 | // StdlibHasher returns a Hasher that uses the stdlib for hashing. | ||
| 31 | // Used hashers are stored in a pool for fast reuse. | ||
| 32 | func StdlibHasher() Hasher { | ||
| 33 | return &md5Wrapper{Hash: md5Pool.New().(hash.Hash)} | ||
| 34 | } | ||
| 35 | |||
| 36 | // md5Wrapper is a wrapper around the builtin hasher. | ||
| 37 | type md5Wrapper struct { | ||
| 38 | hash.Hash | ||
| 39 | } | ||
| 40 | |||
| 41 | var md5Pool = sync.Pool{New: func() interface{} { | ||
| 42 | return md5.New() | ||
| 43 | }} | ||
| 44 | |||
| 45 | // fallbackServer - Fallback when no assembly is available. | ||
| 46 | type fallbackServer struct { | ||
| 47 | } | ||
| 48 | |||
| 49 | // NewHash -- return regular Golang md5 hashing from crypto | ||
| 50 | func (s *fallbackServer) NewHash() Hasher { | ||
| 51 | return &md5Wrapper{Hash: md5Pool.New().(hash.Hash)} | ||
| 52 | } | ||
| 53 | |||
| 54 | func (s *fallbackServer) Close() { | ||
| 55 | } | ||
| 56 | |||
| 57 | func (m *md5Wrapper) Close() { | ||
| 58 | if m.Hash != nil { | ||
| 59 | m.Reset() | ||
| 60 | md5Pool.Put(m.Hash) | ||
| 61 | m.Hash = nil | ||
| 62 | } | ||
| 63 | } | ||