summaryrefslogtreecommitdiffstats
path: root/vendor/golang.org/x/crypto/argon2/blake2b.go
diff options
context:
space:
mode:
authorHarrison Healey <harrisonmhealey@gmail.com>2018-01-16 12:03:31 -0500
committerGitHub <noreply@github.com>2018-01-16 12:03:31 -0500
commit2fa7c464f019f67c5c0494aaf5ac0f5ecc1ee7a7 (patch)
treee08ff912e1924c06939f314168c3362d6f1ec0de /vendor/golang.org/x/crypto/argon2/blake2b.go
parentf5c8a71698d0a7a16c68be220e49fe64bfee7f5c (diff)
downloadchat-2fa7c464f019f67c5c0494aaf5ac0f5ecc1ee7a7.tar.gz
chat-2fa7c464f019f67c5c0494aaf5ac0f5ecc1ee7a7.tar.bz2
chat-2fa7c464f019f67c5c0494aaf5ac0f5ecc1ee7a7.zip
Updated dependencies and added avct/uasurfer (#8089)
* Updated dependencies and added avct/uasurfer * Added uasurfer to NOTICE.txt
Diffstat (limited to 'vendor/golang.org/x/crypto/argon2/blake2b.go')
-rw-r--r--vendor/golang.org/x/crypto/argon2/blake2b.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/vendor/golang.org/x/crypto/argon2/blake2b.go b/vendor/golang.org/x/crypto/argon2/blake2b.go
new file mode 100644
index 000000000..10f46948d
--- /dev/null
+++ b/vendor/golang.org/x/crypto/argon2/blake2b.go
@@ -0,0 +1,53 @@
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package argon2
+
+import (
+ "encoding/binary"
+ "hash"
+
+ "golang.org/x/crypto/blake2b"
+)
+
+// blake2bHash computes an arbitrary long hash value of in
+// and writes the hash to out.
+func blake2bHash(out []byte, in []byte) {
+ var b2 hash.Hash
+ if n := len(out); n < blake2b.Size {
+ b2, _ = blake2b.New(n, nil)
+ } else {
+ b2, _ = blake2b.New512(nil)
+ }
+
+ var buffer [blake2b.Size]byte
+ binary.LittleEndian.PutUint32(buffer[:4], uint32(len(out)))
+ b2.Write(buffer[:4])
+ b2.Write(in)
+
+ if len(out) <= blake2b.Size {
+ b2.Sum(out[:0])
+ return
+ }
+
+ outLen := len(out)
+ b2.Sum(buffer[:0])
+ b2.Reset()
+ copy(out, buffer[:32])
+ out = out[32:]
+ for len(out) > blake2b.Size {
+ b2.Write(buffer[:])
+ b2.Sum(buffer[:0])
+ copy(out, buffer[:32])
+ out = out[32:]
+ b2.Reset()
+ }
+
+ if outLen%blake2b.Size > 0 { // outLen > 64
+ r := ((outLen + 31) / 32) - 2 // ⌈τ /32⌉-2
+ b2, _ = blake2b.New(outLen-32*r, nil)
+ }
+ b2.Write(buffer[:])
+ b2.Sum(out[:0])
+}