// HashStr creates a hexadecimal string of the hash of the file at path
// using the specified Hash.
355345
func HashStr(hasher hash.Hash, path string) (string, error) {
	csum, err := Hash(hasher, path)
	if err != nil {
		return "", err
	}
	return fmt.Sprintf("%x", csum), nil
}
1061498
func hashString(input string) string {
	defer loggerHighwayHasher.Reset()
	loggerHighwayHasher.Write([]byte(input))
	checksum := loggerHighwayHasher.Sum(nil)
	return hex.EncodeToString(checksum)
}
1052871
func hashsum(s string, hasher hash.Hash) string {
	hasher.Reset()
	hasher.Write([]byte(s))
	return hex.EncodeToString(hasher.Sum(nil))
}
70206
func HashFS(h hash.Hash, fs FS, gs GetSetter) FS {
	return &hashFS{
		h:  h,
		fs: fs,
		gs: gs,
	}
}
46094
func (h *Hash) UnmarshalText(input []byte) error {
	return hexutil.UnmarshalFixedText("Hash", input, h[:])
}
844522
func Hash(s string) string {
	h := sha1.New()
	h.Write([]byte(s))

	hash := h.Sum(nil)

	return fmt.Sprintf("%x", hash)
}
61390
func Hashf(k []byte, seed uint64) uint64 {
	/*
		_, ok := HashFunctions[Hf2]
		if !ok {
			fmt.Printf("%q not found\n", Hf2)
			panic("hashf")
		}
	*/
	switch Hf2 {
	case "nullhash":
		nh.Reset()
		nh.Write(k)
		h := nh.Sum64()
		return h
	case "nullhashF64ns":
		h := nhf64.Hash64S(k, 0)
		return h
	case "gomap64":
		h := gomap.Hash64(k, uint64(seed))
		return h
	case "gomap32":
		h := gomap.Hash32(k, uint32(seed))
		return uint64(h)
	case "aeshash64":
		h := aeshash.Hash(k, seed)
		return h
	case "adler32":
		a32.Reset()
		a32.Write(k)
		h := a32.Sum32()
		//fmt.Printf("a32 hash=0x%08x\n", h)
		return uint64(h)
	case "sbox":
		h := sbox.Sbox(k, uint32(seed))
		return uint64(h)
	case "CrapWow":
		h := crapwow.CrapWow(k, uint32(seed))
		//fmt.Printf("key=%q, hash=0x%08x\n", string(k), hash)
		return uint64(h)
	case "MaHash8v64":
		h64 := mahash.MaHash8v64(k)
		return h64
	case "j364":
		c, b := jenkins.Jenkins364(k, len(k), uint32(seed), uint32(seed))
		return uint64(b)<<32 | uint64(c)
	case "j332c":
		c, _ := jenkins.Jenkins364(k, len(k), uint32(seed), uint32(seed))
		return uint64(c)
	case "j332b":
		_, b := jenkins.Jenkins364(k, len(k), uint32(seed), uint32(seed))
		return uint64(b)
	case "j232":
		h := jenkins.Hash232(k, uint32(seed))
		return uint64(h)
	case "j264":
		h := jenkins.Hash264(k, seed)
		return h
	case "j264l":
		h := jenkins.Hash264(k, seed)
		return uint64(h & 0xFFFFFFFF)
	case "j264h":
		h := jenkins.Hash264(k, seed)
		return uint64((h >> 32) & 0xFFFFFFFF)
	case "j264xor":
		h := jenkins.Hash264(k, seed)
		return uint64(uint32(h&0xFFFFFFFF) ^ uint32((h>>32)&0xFFFFFFFF))
	case "spooky32":
		return uint64(spooky.Hash32(k, uint32(seed)))
	case "spooky64":
		return spooky.Hash64(k, seed)
	case "spooky128h":
		h, _ := spooky.Hash128(k, seed)
		return h
	case "spooky128l":
		_, l := spooky.Hash128(k, seed)
		return l
	case "spooky128xor":
		h, l := spooky.Hash128(k, seed)
		return h ^ l
	case "murmur332":
		m332.Reset()
		m332.Write(k)
		h := m332.Sum32()
		return uint64(h)
	case "murmur364":
		m364.Reset()
		m364.Write(k)
		h := m364.Sum64()
		return h
	case "siphash64":
		h := siphash.Hash(0, 0, k)
		return h
	case "siphash64pg":
		sipSeedSet(seed)
		a, _ := siphashpg.Siphash(k, seeds, siphashpg.Crounds, siphashpg.Drounds, false)
		return a

	case "FarmHash32":
		h := farm.Fingerprint32(k)
		return uint64(h & 0xFFFFFFFF)
	case "FarmHash64":
		h := farm.Fingerprint64(k)
		return h
	case "FarmHash128-high":
		h, _ := farm.Fingerprint128(k)
		return h
	case "FarmHash128-low":
		_, l := farm.Fingerprint128(k)
		return l
	case "FarmHash128-xor":
		h, l := farm.Fingerprint128(k)
		return h ^ l

	case "MetroHash64-1":
		h := metro.Hash64_1(k, uint32(seed))
		return h
	case "MetroHash64-2":
		h := metro.Hash64_2(k, uint32(seed))
		return h

	case "MetroHash128-1h":
		h, _ := metro.Hash128_1(k, uint32(seed))
		return h
	case "MetroHash128-1l":
		_, l := metro.Hash128_1(k, uint32(seed))
		return l
	case "MetroHash128-1xor":
		h, l := metro.Hash128_1(k, uint32(seed))
		return h ^ l

	case "MetroHash128-2h":
		h, _ := metro.Hash128_2(k, uint32(seed))
		return h
	case "MetroHash128-2l":
		_, l := metro.Hash128_2(k, uint32(seed))
		return l
	case "MetroHash128-2xor":
		h, l := metro.Hash128_2(k, uint32(seed))
		return h ^ l

		/*
			case "siphash64":
				sipSeedSet(seed)
				a, _ := siphash.Siphash(k, seeds, siphash.Crounds, siphash.Drounds, false)
				return a
			case "siphash128a":
				sipSeedSet(seed)
				a, _ := siphash.Siphash(k, seeds, siphash.Crounds, siphash.Drounds, true)
				return a
			case "siphash128b":
				sipSeedSet(seed)
				_, b := siphash.Siphash(k, seeds, siphash.Crounds, siphash.Drounds, true)
				return b
			case "siphash64al":
				sipSeedSet(seed)
				a, _ := siphash.Siphash(k, seeds, siphash.Crounds, siphash.Drounds, false)
				return uint64(a&0xFFFFFFFF)
			case "siphash64ah":
				sipSeedSet(seed)
				a, _ := siphash.Siphash(k, seeds, siphash.Crounds, siphash.Drounds, false)
				return uint64((a>>32)&0xFFFFFFFF)
			case "siphash64bl":
				sipSeedSet(seed)
				_, b := siphash.Siphash(k, seeds, siphash.Crounds, siphash.Drounds, true)
				return uint64(b&0xFFFFFFFF)
			case "siphash64bh":
				sipSeedSet(seed)
				_, b := siphash.Siphash(k, seeds, siphash.Crounds, siphash.Drounds, true)
				return uint64((b>>32)&0xFFFFFFFF)
		*/
	case "keccak224":
		fp28 = fp28[0:0]
		k224.Reset()
		//fmt.Printf("len(k)=%d\n", k)
		k224.Write(k)
		fp28 = k224.Sum(fp28) // crashes 		fp8 = k224.Sum(fp28)
		//fmt.Printf("len(k)=%d, k=%#X, fp=%#x\n", len(k), k, fp28)
		//fmt.Printf("len(fp28)=%d\n", fp28)
		//fmt.Printf("keccak160xor: fp=%v\n", fp)
		return uint64(fp28[0])<<56 | uint64(fp28[1])<<48 | uint64(fp28[2])<<40 | uint64(fp28[3])<<32 | uint64(fp28[4])<<24 | uint64(fp28[5])<<16 | uint64(fp28[6])<<8 | uint64(fp28[7])<<0
	case "keccakpg643":
		fp8 = fp8[0:0]
		k643.Reset()
		k643.Write(k)
		fp8 = k643.Sum(fp8)
		//fmt.Printf("keccak160xor: fp=%v\n", fp)
		return uint64(fp8[0])<<56 | uint64(fp8[1])<<48 | uint64(fp8[2])<<40 | uint64(fp8[3])<<32 | uint64(fp8[4])<<24 | uint64(fp8[5])<<16 | uint64(fp8[6])<<8 | uint64(fp8[7])<<0
	case "keccakpg644":
		fp := make([]byte, 8, 8)
		fp = fp[0:0]
		k644.Reset()
		k644.Write(k)
		fp = k644.Sum(fp)
		//fmt.Printf("keccak160xor: fp=%v\n", fp)
		return uint64(fp[0])<<56 | uint64(fp[1])<<48 | uint64(fp[2])<<40 | uint64(fp[3])<<32 | uint64(fp[4])<<24 | uint64(fp[5])<<16 | uint64(fp[6])<<8 | uint64(fp[7])<<0
	case "keccakpg648":
		fp := make([]byte, 8, 8)
		fp = fp[0:0]
		k648.Reset()
		k648.Write(k)
		fp = k648.Sum(fp)
		//fmt.Printf("keccak160xor: fp=%v\n", fp)
		return uint64(fp[0])<<56 | uint64(fp[1])<<48 | uint64(fp[2])<<40 | uint64(fp[3])<<32 | uint64(fp[4])<<24 | uint64(fp[5])<<16 | uint64(fp[6])<<8 | uint64(fp[7])<<0
	case "keccakpg160":
		fp := make([]byte, 32)
		fp = fp[0:0]
		k160.Reset()
		k160.Write(k)
		fp = k160.Sum(fp)
		//fmt.Printf("keccak160xor: fp=%v\n", fp)
		if false {
			low := fp[0] ^ fp[4] ^ fp[8] ^ fp[12] ^ fp[16]
			med := fp[1] ^ fp[5] ^ fp[9] ^ fp[13] ^ fp[17]
			hii := fp[2] ^ fp[6] ^ fp[10] ^ fp[14] ^ fp[18]
			top := fp[3] ^ fp[7] ^ fp[11] ^ fp[15] ^ fp[19]
			return uint64(uint32(top)<<24 | uint32(hii)<<16 | uint32(med)<<8 | uint32(low))
		} else {
			return uint64(fp[0])<<56 | uint64(fp[1])<<48 | uint64(fp[2])<<40 | uint64(fp[3])<<32 | uint64(fp[4])<<24 | uint64(fp[5])<<16 | uint64(fp[6])<<8 | uint64(fp[7])<<0
		}
	case "skein256xor":
		fp := make([]byte, 32)
		fp = fp[0:0]
		skein256.Reset()
		skein256.Write(k)
		fp = skein256.Sum(fp)
		//fmt.Printf("skein256: fp=%v\n", fp)
		if true {
			low := fp[0] ^ fp[4] ^ fp[8] ^ fp[12] ^ fp[16]
			med := fp[1] ^ fp[5] ^ fp[9] ^ fp[13] ^ fp[17]
			hii := fp[2] ^ fp[6] ^ fp[10] ^ fp[14] ^ fp[18]
			top := fp[3] ^ fp[7] ^ fp[11] ^ fp[15] ^ fp[19]
			return uint64(uint32(top)<<24 | uint32(hii)<<16 | uint32(med)<<8 | uint32(low))
		} else {
			return uint64(uint32(fp[0])<<24 | uint32(fp[1])<<16 | uint32(fp[2])<<8 | uint32(fp[3]))
		}
	case "skein256":
		fp := make([]byte, 32)
		fp = fp[0:0]
		skein256.Reset()
		skein256.Write(k)
		fp = skein256.Sum(fp)
		//fmt.Printf("skein256: fp=%v\n", fp)
		return uint64(fp[0])<<56 | uint64(fp[1])<<48 | uint64(fp[2])<<40 | uint64(fp[3])<<32 | uint64(fp[4])<<24 | uint64(fp[5])<<16 | uint64(fp[6])<<8 | uint64(fp[7])<<0
	case "skein256hi":
		fp := make([]byte, 32)
		fp = fp[0:0]
		skein256.Reset()
		skein256.Write(k)
		fp = skein256.Sum(fp)
		//fmt.Printf("skein256: fp=%v\n", fp)
		return uint64(uint32(fp[28])<<24 | uint32(fp[29])<<16 | uint32(fp[30])<<8 | uint32(fp[31]))
	case "sha1":
		//fp := make([]byte, 20)
		//fp = fp[0:0]
		sha1160.Reset()
		sha1160.Write(k)
		fp20 = fp20[0:0]
		fp20 = sha1160.Sum(fp20)
		if false {
			low := fp20[0] ^ fp20[4] ^ fp20[8] ^ fp20[12] ^ fp20[16]
			med := fp20[1] ^ fp20[5] ^ fp20[9] ^ fp20[13] ^ fp20[17]
			hii := fp20[2] ^ fp20[6] ^ fp20[10] ^ fp20[14] ^ fp20[18]
			top := fp20[3] ^ fp20[7] ^ fp20[11] ^ fp20[15] ^ fp20[19]
			return uint64(uint32(top)<<24 | uint32(hii)<<16 | uint32(med)<<8 | uint32(low))
		} else {
			return uint64(fp20[0])<<56 | uint64(fp20[1])<<48 | uint64(fp20[2])<<40 | uint64(fp20[3])<<32 | uint64(fp20[4])<<24 | uint64(fp20[5])<<16 | uint64(fp20[6])<<8 | uint64(fp20[7])<<0
		}
	default:
		fmt.Printf("hf=%q\n", Hf2)
		panic("hashf")
	}
	return 0
}
132133
func (n *Networks) HashString() string {
	if n == nil {
		return ""
	}
	result := []string{}
	for _, net := range n.Networks {
		result = append(result, net.HashString())
	}
	sort.Strings(result)
	return strings.Join(result, ",")
}
247715
func (body *Body) Hash() (h string) {
	b := body.Buffer()
	// empty buffs should return a empty string
	if b.Len() == 0 {
		h = HashStr("")
	}
	h = HashStr(b.String())
	return
}
424184
func Hash(what []byte) uint64 {
	h := fnv.New64()
	h.Write(what)
	return h.Sum64()
}
992528
func NewCidStr(version uint64, codecType uint64, mhash mh.Multihash) CidStr {
	hashlen := len(mhash)
	// two 8 bytes (max) numbers plus hash
	buf := make([]byte, 2*binary.MaxVarintLen64+hashlen)
	n := binary.PutUvarint(buf, version)
	n += binary.PutUvarint(buf[n:], codecType)
	cn := copy(buf[n:], mhash)
	if cn != hashlen {
		panic("copy hash length is inconsistent")
	}
	return CidStr(buf[:n+hashlen])
}
649476
func HashKey(parts ...string) string {
	hash := sha256.New()
	bio := bufio.NewWriter(hash)

	// Add a full NULL-delimited key sequence segment to our hash.
	for i, part := range parts {
		// Write the separator, except for the first key.
		if i > 0 {
			if _, err := bio.WriteRune('\x00'); err != nil {
				panic(err)
			}
		}

		if _, err := bio.WriteString(part); err != nil {
			panic(err)
		}
	}
	if err := bio.Flush(); err != nil {
		panic(err)
	}

	// Return the hex-encoded hash sum.
	return hex.EncodeToString(hash.Sum(nil))
}
763841
func (f *Filter) hash(data []byte) [2]uint64 {
	v1 := xxhash.Sum64(data)
	var v2 uint64
	if len(data) > 0 {
		b := data[len(data)-1] // We'll put the original byte back.
		data[len(data)-1] = byte(0)
		v2 = xxhash.Sum64(data)
		data[len(data)-1] = b
	}
	return [2]uint64{v1, v2}
}
883193
func (ut *UploadTracker) hashFile(path string) (isolated.HexDigest, error) {
	if result, ok := ut.fileHashCache[path]; ok {
		return result.digest, result.err
	}

	digest, err := ut.doHashFile(path)
	ut.fileHashCache[path] = hashResult{digest, err}
	return digest, err
}
1359313
func HashStr(toHash string) string {
	h := sha1.New()
	io.WriteString(h, toHash)
	hashed := base64.StdEncoding.EncodeToString(h.Sum(nil))
	return hashed
}
453660
func StrToHash(hash string) (crypto.Hash, error) {
	switch hash {
	case "SHA1", "SHA-1":
		return crypto.SHA1, nil
	case "SHA224", "SHA-224":
		return crypto.SHA224, nil
	case "SHA256", "SHA-256":
		return crypto.SHA256, nil
	case "SHA384", "SHA-384":
		return crypto.SHA384, nil
	case "SHA512", "SHA-512":
		return crypto.SHA512, nil
	case "SHA512_224", "SHA512/224", "SHA-512_224", "SHA-512/224":
		return crypto.SHA512_224, nil
	case "SHA512_256", "SHA512/256", "SHA-512_256", "SHA-512/256":
		return crypto.SHA512_256, nil
	}
	return 0, errors.Errorf("no such hash %s", hash)
}
564565
func ParseHexStr(s string) (string, error) {
	var err error
	s, err = uniformHexStrLit(s)
	if err != nil {
		return "", errors.Trace(err)
	}
	bs, err := hex.DecodeString(s[2:])
	if err != nil {
		return "", errors.Trace(err)
	}
	return string(bs), nil
}