summaryrefslogtreecommitdiffstats
path: root/internal
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2025-10-07 08:31:39 -0700
committerRose Hogenson <rosehogenson@posteo.net>2025-10-07 08:41:15 -0700
commitbcc1c2d9dd7fefa538647c0d4e9e621511f1fde6 (patch)
tree64bd8f2b15dd3a737ae8d2db683641474acaff3f /internal
parent65b1ed1ff56e4d795c67d4d0b31634decec7767b (diff)
downloadroseh.moe-bcc1c2d9dd7fefa538647c0d4e9e621511f1fde6.tar.zst
Bring back pbkdf2
Diffstat (limited to 'internal')
-rw-r--r--internal/hole/hole.go25
-rw-r--r--internal/hole/wordlist.txt (renamed from internal/wordlist/wordlist.txt)0
-rw-r--r--internal/pwhash/pwhash.go18
-rw-r--r--internal/wordlist/wordlist.go11
4 files changed, 43 insertions, 11 deletions
diff --git a/internal/hole/hole.go b/internal/hole/hole.go
new file mode 100644
index 0000000..4824459
--- /dev/null
+++ b/internal/hole/hole.go
@@ -0,0 +1,25 @@
+package hole
+
+import (
+ "crypto/rand"
+ _ "embed"
+ "encoding/binary"
+ "strings"
+)
+
+var (
+ //go:embed wordlist.txt
+ wordListString string
+ wordList = strings.Split(strings.TrimSuffix(wordListString, "\n"), "\n")
+)
+
+func New() string {
+ const nWords = 10
+ buf := make([]byte, 2*nWords)
+ rand.Read(buf)
+ words := make([]string, nWords)
+ for i := range words {
+ words[i] = wordList[binary.NativeEndian.Uint16(buf[2*i:])&0x1fff]
+ }
+ return strings.Join(words, "-")
+}
diff --git a/internal/wordlist/wordlist.txt b/internal/hole/wordlist.txt
index 5e304ce..5e304ce 100644
--- a/internal/wordlist/wordlist.txt
+++ b/internal/hole/wordlist.txt
diff --git a/internal/pwhash/pwhash.go b/internal/pwhash/pwhash.go
new file mode 100644
index 0000000..576d052
--- /dev/null
+++ b/internal/pwhash/pwhash.go
@@ -0,0 +1,18 @@
+package pwhash
+
+import (
+ "crypto/pbkdf2"
+ "crypto/sha512"
+)
+
+const SaltSize = 8
+
+const defaultIter = 12059332 // from tools/finditer
+
+func HashIter(password string, salt []byte, iter int) ([]byte, error) {
+ return pbkdf2.Key(sha512.New, password, salt, iter, 32)
+}
+
+func Hash(password string, salt []byte) ([]byte, error) {
+ return HashIter(password, salt, defaultIter)
+}
diff --git a/internal/wordlist/wordlist.go b/internal/wordlist/wordlist.go
deleted file mode 100644
index de929bc..0000000
--- a/internal/wordlist/wordlist.go
+++ /dev/null
@@ -1,11 +0,0 @@
-package wordlist
-
-import (
- _ "embed"
- "strings"
-)
-
-//go:embed wordlist.txt
-var wordList string
-
-var Words = strings.Split(strings.TrimSuffix(wordList, "\n"), "\n")