// NewFromHash returns a new Crypter using the prefix in the given hashed key.
516095
func NewFromHash(hashedKey string) (Crypter, error) {
	var f func() Crypter

	if strings.HasPrefix(hashedKey, cryptPrefixes[SHA512]) {
		f = crypts[SHA512]
	} else if strings.HasPrefix(hashedKey, cryptPrefixes[SHA256]) {
		f = crypts[SHA256]
	} else if strings.HasPrefix(hashedKey, cryptPrefixes[MD5]) {
		f = crypts[MD5]
	} else if strings.HasPrefix(hashedKey, cryptPrefixes[APR1]) {
		f = crypts[APR1]
	}

	if f != nil {
		return f(), nil
	}

	return nil, errors.New("Invalid hash")
}
1220353
func New(algo string) (*Hash, error) {
	h := &Hash{algo: algo}

	hf, ok := secureHashes[algo]
	if ok {
		h.Hash = hf()
		h.secure = true
		return h, nil
	}

	hf, ok = insecureHashes[algo]
	if ok {
		h.Hash = hf()
		h.secure = false
		return h, nil
	}

	return nil, errors.New("chash: unsupport hash algorithm " + algo)
}
1329439
func NewAddressPubKeyHash(pkHash []byte, net *chaincfg.Params) (*AddressPubKeyHash, error) {
	return newAddressPubKeyHash(pkHash, net.PubKeyHashAddrID)
}
1174866
func MakeHash(newHash []byte) (Hash, error) {
	nhlen := len(newHash)
	if nhlen != HashSize {
		return Hash{}, fmt.Errorf("invalid hash length of %v, want %v",
			nhlen, HashSize)
	}

	var hash Hash
	copy(hash[:], newHash)

	return hash, nil
}
613818
func New(config *Config) hash.Hash {
	d := &digest{
		param: C.blake2b_param{
			digest_length: 64,
			fanout:        1,
			depth:         1,
		},
	}
	if config != nil {
		if config.Size != 0 {
			d.param.digest_length = C.uint8_t(config.Size)
		}
		if len(config.Key) > 0 {
			// let the C library worry about the exact limit; we just
			// worry about fitting into the variable
			if len(config.Key) > 255 {
				panic("blake2b key too long")
			}
			d.param.key_length = C.uint8_t(len(config.Key))
			d.key = config.Key
		}
		salt := (*[C.BLAKE2B_SALTBYTES]byte)(unsafe.Pointer(&d.param.salt[0]))
		copy(salt[:], config.Salt)
		personal := (*[C.BLAKE2B_SALTBYTES]byte)(unsafe.Pointer(&d.param.personal[0]))
		copy(personal[:], config.Personal)

		if config.Tree != nil {
			d.param.fanout = C.uint8_t(config.Tree.Fanout)
			d.param.depth = C.uint8_t(config.Tree.MaxDepth)
			d.param.leaf_length = C.uint32_t(config.Tree.LeafSize)
			d.param.node_offset = C.uint64_t(config.Tree.NodeOffset)
			d.param.node_depth = C.uint8_t(config.Tree.NodeDepth)
			d.param.inner_length = C.uint8_t(config.Tree.InnerHashSize)

			d.isLastNode = config.Tree.IsLastNode
		}
	}
	d.Reset()
	return d
}
1107437
func nameOfHash(h crypto.Hash) string {
	switch h {
	case crypto.MD5:
		return "MD5"
	case crypto.SHA1:
		return "SHA1"
	case crypto.RIPEMD160:
		return "RIPEMD160"
	case crypto.SHA224:
		return "SHA224"
	case crypto.SHA256:
		return "SHA256"
	case crypto.SHA384:
		return "SHA384"
	case crypto.SHA512:
		return "SHA512"
	}
	return ""
}
323661
func New(c cipher.Block) (hash.Hash, error) {
	if c == nil {
		return nil, errors.New("the cipher.Block must not be nil")
	}
	bs := c.BlockSize()

	var p int
	switch bs {
	default:
		return nil, errors.New("cipher block size not supported")
	case 8:
		p = p64
	case 16:
		p = p128
	case 32:
		p = p256
	case 64:
		p = p512
	case 128:
		p = p1024
	}

	m := &macFunc{
		cipher: c,
		k0:     make([]byte, bs),
		k1:     make([]byte, bs),
		buf:    make([]byte, bs),
	}
	c.Encrypt(m.k0, m.k0)

	v := shift(m.k0, m.k0)
	m.k0[bs-1] ^= byte(subtle.ConstantTimeSelect(v, p, 0))

	v = shift(m.k1, m.k0)
	m.k1[bs-1] ^= byte(subtle.ConstantTimeSelect(v, p, 0))

	return m, nil
}
465933
func NewAddressFromBytes(b []byte) Address {
	h := common.Hash{}
	copy(h[:], b)
	return Address(h)
}
468457
func (t *MultiTreeHasher) CreateHash() string {
	if len(t.nodes) == 0 {
		return ""
	}
	rootHash := treeHash(t.nodes)
	return hex.EncodeToString(rootHash[:])
}
1320027
func payloadHash(payload interface{}) ([]byte, error) {
	hash, err := hashstructure.Hash(payload, nil)
	if err != nil {
		return []byte{}, err
	}

	buf := make([]byte, 8)
	binary.BigEndian.PutUint64(buf, hash)
	return buf, nil
}
712721
func NewHash(name string, m map[string]string) (Vindex, error) {
	return &Hash{name: name}, nil
}
477060
func (bf *Filter) AddHash(hash *chainhash.Hash) {
	bf.mtx.Lock()
	bf.add(hash[:])
	bf.mtx.Unlock()
}
63904
func HashFromBytes(data []byte) (Hash, error) {
	h := Hash{string(data)}
	if !h.IsValid() {
		return Hash{}, errors.WithStack(InvalidHashError{h})
	}
	return h, nil
}
1121533
func (b *GCSBuilder) SetKeyFromHash(keyHash *chainhash.Hash) *GCSBuilder {
	// Do nothing if the builder's already errored out.
	if b.err != nil {
		return b
	}

	return b.SetKey(DeriveKey(keyHash))
}
207813
func New(key [32]byte) *Hash {
	if useAVX2 {
		h := new(poly1305HashAVX2)
		initializeAVX2(&(h.state), &key)
		return &Hash{h, false}
	}
	h := new(poly1305Hash)
	initialize(&(h.state), &key)
	return &Hash{h, false}
}
758006
func New(key []byte) (hash.Hash, error) {
	if len(key) != Size {
		return nil, errKeySize
	}
	h := &digest{size: Size}
	copy(h.key[:], key)
	h.Reset()
	return h, nil
}
696675
func seedHash(block uint64) []byte {
	seed := make([]byte, 32)
	if block < epochLength {
		return seed
	}
	keccak256 := makeHasher(sha3.NewLegacyKeccak256())
	for i := 0; i < int(block/epochLength); i++ {
		keccak256(seed, seed)
	}
	return seed
}