switch pow to argon2id

This commit is contained in:
2026-11-22 13:52:29 -05:00
parent 80ad8a62ae
commit 8730b968b5
8 changed files with 41 additions and 16 deletions
+6 -3
View File
@@ -2,8 +2,8 @@ package reports
import (
"crypto/rand"
"crypto/sha256"
"crypto/subtle"
"encoding/binary"
"encoding/hex"
"fmt"
"log"
@@ -11,6 +11,7 @@ import (
"time"
"git.whoswhip.dev/whoswhip/minibin/internal/storage"
"golang.org/x/crypto/argon2"
)
type Challenge struct {
@@ -94,8 +95,10 @@ func (store *ChallengeStore) Verify(id string, result string, nonce int) (client
if !hasLeadingZeroBits(hashBytes, challenge.Difficulty) {
return true, fmt.Errorf("proof-of-work is not complete")
}
input := fmt.Appendf(nil, "%s%d", hex.EncodeToString(challenge.Data), nonce)
localResult := sha256.Sum256(input)
input := []byte(hex.EncodeToString(challenge.Data))
salt := make([]byte, 8)
binary.LittleEndian.PutUint64(salt, uint64(nonce))
localResult := argon2.IDKey(input, salt, 2, 4096, 1, 32)
if subtle.ConstantTimeCompare(localResult[:], hashBytes) != 1 {
return true, fmt.Errorf("results do not match")
}