From fbd4a60a4ad5149e33d09072d9e42e0642c74579 Mon Sep 17 00:00:00 2001 From: maru Date: Fri, 19 Apr 2024 12:48:14 -0400 Subject: [PATCH] Add mutex to deriveArgon2IDKey --- api/account/common.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/api/account/common.go b/api/account/common.go index 6be1f54..1dd98ad 100644 --- a/api/account/common.go +++ b/api/account/common.go @@ -2,6 +2,7 @@ package account import ( "regexp" + "sync" "golang.org/x/crypto/argon2" ) @@ -21,8 +22,14 @@ const ( TokenSize = 32 ) -var isValidUsername = regexp.MustCompile(`^\w{1,16}$`).MatchString +var ( + isValidUsername = regexp.MustCompile(`^\w{1,16}$`).MatchString + argonMtx sync.Mutex +) func deriveArgon2IDKey(password, salt []byte) []byte { + argonMtx.Lock() + defer argonMtx.Unlock() + return argon2.IDKey(password, salt, ArgonTime, ArgonMemory, ArgonThreads, ArgonKeySize) }