switch pow to argon2id
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user