// IdentifyHasher returns the hasher used in the encoded password.
434758
func IdentifyHasher(encoded string) string {
	size := len(encoded)

	if size == 32 && !strings.Contains(encoded, "$") {
		return UnsaltedMD5Hasher
	}

	if size == 37 && strings.HasPrefix(encoded, "md5$$") {
		return UnsaltedMD5Hasher
	}

	if size == 46 && strings.HasPrefix(encoded, "sha1$$") {
		return UnsaltedSHA1Hasher
	}

	return strings.SplitN(encoded, "$", 2)[0]
}
479448
func (ks *KeyStore) SignHash(address *Address, hash []byte) (signature []byte, _ error) {
	return ks.keystore.SignHash(accounts.Account{Address: address.address}, common.CopyBytes(hash))
}
46036
func hash(key uint64) uint64 {
	key ^= key >> 33
	key *= 0xff51afd7ed558ccd
	key ^= key >> 33
	key *= 0xc4ceb9fe1a85ec53
	key ^= key >> 33
	return key
}
233426
func verifyPasswordWithHashers(password, hashedPassword string, hashers []PasswordHasher) (bool, bool) {
	// Even though good hashers will disallow blank passwords, let's be explicit that ALL BLANK PASSWORDS ARE INVALID.  Full stop.
	if password == "" {
		return false, false
	}

	valid, stale := false, false

	for idx, hasher := range hashers {
		if hasher.VerifyPassword(password, hashedPassword) {
			valid = true
			if idx > 0 {
				stale = true
			}
			break
		}
	}

	return valid, stale
}
778681
func hashPassword(password string) string {
	h := sha1.New()
	io.WriteString(h, password)
	return fmt.Sprintf("% x", h.Sum(nil))
}
460757
func IsHasherImplemented(hasher string) bool {
	switch hasher {
	case
		Argon2Hasher,
		BCryptHasher,
		BCryptSHA256Hasher,
		PBKDF2SHA1Hasher,
		PBKDF2SHA256Hasher:
		return true
	}

	return false
}
418011
func OptServerClusterHasher(h Hasher) ServerOption {
	return func(s *Server) error {
		s.cluster.Hasher = h
		return nil
	}
}
305642
func (state *UserState) HashPassword(username, password string) string {
	switch state.passwordAlgorithm {
	case "sha256":
		return string(hashSha256(state.cookieSecret, username, password))
	case "bcrypt", "bcrypt+":
		return string(hashBcrypt(password))
	}
	// Only valid password algorithms should be allowed to set
	return ""
}
212019
func PasswordHash(username, password string) string {
	hash := md5.Sum([]byte(strings.ToLower(username) + password))
	return fmt.Sprintf("%x", hash)
}
787892
func (h BcryptPasswordHasher) VerifyPassword(password, hashedPassword string) bool {
	err := bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(password))
	return err == nil
}
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 ""
}
542198
func (ctx *Context) hash(password []byte, salt []byte) ([]byte, error) {

	if len(password) == 0 {
		return nil, ErrPassword
	}
	if len(salt) == 0 {
		return nil, ErrSalt
	}

	hash := make([]byte, ctx.HashLen)

	// optional secret
	secret := (*C.uint8_t)(nil)
	if len(ctx.Secret) > 0 {
		secret = (*C.uint8_t)(&ctx.Secret[0])
	}

	// optional associated data
	associatedData := (*C.uint8_t)(nil)
	if len(ctx.AssociatedData) > 0 {
		associatedData = (*C.uint8_t)(&ctx.AssociatedData[0])
	}

	// optional flags
	flags := FlagDefault
	if ctx.Flags != 0 {
		flags = ctx.Flags
	}

	// ensure version has a default
	version := VersionDefault
	if ctx.Version != 0 {
		version = ctx.Version
	}

	// wrapper to overcome go pointer passing limitations
	result := C.argon2_wrapper(
		(*C.uint8_t)(&hash[0]), C.uint32_t(ctx.HashLen),
		(*C.uint8_t)(&password[0]), C.uint32_t(len(password)),
		(*C.uint8_t)(&salt[0]), C.uint32_t(len(salt)),
		secret, C.uint32_t(len(ctx.Secret)),
		associatedData, C.uint32_t(len(ctx.AssociatedData)),
		C.uint32_t(ctx.Iterations),
		C.uint32_t(ctx.Memory),
		C.uint32_t(ctx.Parallelism),
		C.uint32_t(ctx.Parallelism),
		C.uint32_t(version),
		nil, nil,
		C.uint32_t(flags),
		C.argon2_type(ctx.Mode))

	if result != C.ARGON2_OK {
		return nil, Error(result)
	}

	return hash, nil
}
985956
func PasswordMatch(hashed, password string) bool {
	err := bcrypt.CompareHashAndPassword([]byte(hashed), []byte(password))
	return err == nil
}
1220796
func HashIdToHash(id byte) (h crypto.Hash, ok bool) {
	for _, m := range hashToHashIdMapping {
		if m.id == id {
			return m.hash, true
		}
	}
	return 0, false
}
71555
func SecretHash(sec *v1.Secret) (string, error) {
	encoded, err := encodeSecret(sec)
	if err != nil {
		return "", err
	}
	h, err := encodeHash(hash(encoded))
	if err != nil {
		return "", err
	}
	return h, nil
}
234747
func HashE(v interface{}) (uint32, error) {
	if h, ok := v.(iseq.Hashable); ok {
		return h.Hash(), nil
	}

	switch v := v.(type) {
	case bool, int, int8, int32, int64:
		return murmur3.HashUInt64(uint64(reflect.ValueOf(v).Int())), nil
	case uint, uint8, uint32, uint64:
		return murmur3.HashUInt64(uint64(reflect.ValueOf(v).Uint())), nil
	case float32, float64:
		return murmur3.HashUInt64(math.Float64bits(reflect.ValueOf(v).Float())), nil
	case nil:
		return murmur3.HashUInt64(0), nil
	case string:
		return murmur3.HashString(v), nil
	case complex64, complex128:
		return HashComplex128(v.(complex128)), nil
	}
	return 0, errors.New("don't know how to hash")
}
627379
func hashAuth(u, p string) string {
	var a = fmt.Sprintf("%s:%s", u, p)
	return base64.StdEncoding.EncodeToString([]byte(a))
}