// makeHA1 returns the HA1 hash, where
//
//     HA1 = H(A1) = H(username:realm:password)
//
// and H is one of MD5 or SHA256.
327305
func makeHA1(realm, username, password string, algorithm digestAlgorithm) string {
	A1 := fmt.Sprintf("%s:%s:%s", username, realm, password)
	return hash([]byte(A1), algorithm)
}
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 ""
}
823395
func H(data string) string {
	digest := md5.New()
	digest.Write([]byte(data))
	return fmt.Sprintf("%x", digest.Sum(nil))
}
1168406
func MakeFileSha256Func(baseDir string) function.Function {
	return makeFileHashFunction(baseDir, sha256.New, hex.EncodeToString)
}
37320
func MakeHash(s string) string {
	const IEEE = 0xedb88320
	var IEEETable = crc32.MakeTable(IEEE)
	hash := fmt.Sprintf("%x", crc32.Checksum([]byte(s), IEEETable))
	return hash
}
1140673
func stringHash(s string) string {
	return fmt.Sprintf("%x", md5.Sum([]byte(s)))
}
147405
func MakePassword(h Hasher, cleartext string) string {
	return h.Encode(cleartext, h.Salt())
}
849924
func Sha1(data []byte) string {
	sha1 := sha1.New()
	sha1.Write(data)
	return hex.EncodeToString(sha1.Sum(nil))
}
1209425
func MakeHashFromStr(newHash string) (Hash, error) {
	// Return error if hash string is of incorrect length.
	if len(newHash) != HashSize*2 {
		return Hash{}, fmt.Errorf("invalid hash string length of %v, "+
			"want %v", len(newHash), HashSize*2)
	}

	hash, err := hex.DecodeString(newHash)
	if err != nil {
		return Hash{}, err
	}

	return MakeHash(hash)
}
544079
func (c *CommitResult) GetSHA() string {
	if c == nil || c.SHA == nil {
		return ""
	}
	return *c.SHA
}
146502
func (h *DBHeader) ValidateSha256(hash [32]byte) error {
	sha := h.GetSha256()
	if !reflect.DeepEqual(sha, hash) {
		return errors.New("Sha256 of header mismatching")
	}
	return nil
}
117397
func Sha1(q string) string {
	g := sha1.New()
	g.Write([]byte(q))
	return fmt.Sprintf("%x", g.Sum(nil))
}
320642
func MakePassword(password string, salt string, positions ...uint) string {
	length := len(positions)
	if length < 1 {
		return Hash(salt + password)
	}
	saltLength := len(salt)
	if saltLength < length {
		return Hash(salt + password)
	}
	saltChars := saltLength / length
	hashedPassword := Hash(password)
	maxIndex := len(hashedPassword) - 1
	saltMaxIndex := saltLength - 1
	var result string
	var lastPos int
	for k, pos := range positions {
		end := int(pos)
		start := lastPos
		if start > end {
			start, end = end, start
		}
		if start > maxIndex {
			continue
		}
		lastPos = end
		saltStart := k * saltChars
		saltEnd := saltStart + saltChars
		if end > maxIndex {
			result += hashedPassword[start:] + salt[saltStart:saltEnd]
			continue
		}
		result += hashedPassword[start:end] + salt[saltStart:saltEnd]
		if k == length-1 {
			if end <= maxIndex {
				result += hashedPassword[end:]
			}
			if saltEnd <= saltMaxIndex {
				result += salt[saltEnd:]
			}
		}
	}
	return Hash(result)
}
651676
func deriveHash_1(object []int) uint64 {
	if object == nil {
		return 0
	}
	h := uint64(17)
	for i := 0; i < len(object); i++ {
		h = 31*h + uint64(object[i])
	}
	return h
}
889354
func (auth *Auth) MakePassword(cleartext string) string {
	return MakePassword(auth.users.Hasher(), cleartext)
}
1070488
func (c *CommitFile) GetSHA() string {
	if c == nil || c.SHA == nil {
		return ""
	}
	return *c.SHA
}
1143194
func Sha1(c interface{}, version int) []byte {
	sum := sha1.Sum(Dump(c, version))
	return sum[:]
}