switch pow to argon2id
This commit is contained in:
@@ -60,7 +60,7 @@ func LoadConfig() (Config, error) {
|
||||
expiries = append(expiries, expiry)
|
||||
}
|
||||
|
||||
powDifficultySetting := envOrDefault("MINIBIN_POW_DIFFICULTY", "18")
|
||||
powDifficultySetting := envOrDefault("MINIBIN_POW_DIFFICULTY", "10")
|
||||
powDifficulty, err := strconv.Atoi(powDifficultySetting)
|
||||
if err != nil {
|
||||
return Config{}, fmt.Errorf("failed to parse MINIBIN_POW_DIFFICULTY")
|
||||
@@ -71,8 +71,6 @@ func LoadConfig() (Config, error) {
|
||||
return Config{}, fmt.Errorf("no valid report options set")
|
||||
}
|
||||
|
||||
log.Println(len(reportOptions))
|
||||
|
||||
return Config{
|
||||
UploadDir: envOrDefault("MINIBIN_UPLOAD_DIR", "uploads"),
|
||||
MaxPasteBytes: maxPasteKiB * 1024,
|
||||
|
||||
@@ -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