// Copyright 2023 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT package hash import ( "encoding/hex" "strings" "code.gitea.io/gitea/modules/log" "golang.org/x/crypto/argon2" ) func init() { Register("argon2", NewArgon2Hasher) } // Argon2Hasher implements PasswordHasher // and uses the Argon2 key derivation function, hybrant variant type Argon2Hasher struct { time uint32 memory uint32 threads uint8 keyLen uint32 } // HashWithSaltBytes a provided password and salt func (hasher *Argon2Hasher) HashWithSaltBytes(password string, salt []byte) string { if hasher == nil { return "" } return hex.EncodeToString(argon2.IDKey([]byte(password), salt, hasher.time, hasher.memory, hasher.threads, hasher.keyLen)) } // NewArgon2Hasher is a factory method to create an Argon2Hasher // The provided config should be either empty or of the form: // "