-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhash.go
54 lines (45 loc) · 1 KB
/
hash.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"bufio"
"bytes"
"os"
"regexp"
"strings"
"github.com/openwall/yescrypt-go"
)
type YescryptHash struct {
Hash []byte
Cracked int32
}
func ReadYescryptHashes(filePath string) ([]YescryptHash, error) {
file, err := os.Open(filePath)
if err != nil {
return nil, err
}
defer file.Close()
yescryptRegex := regexp.MustCompile(`^\$y\$[./A-Za-z0-9]+\$[./A-Za-z0-9]{1,86}\$[./A-Za-z0-9]{43}$`)
var hashes []YescryptHash
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
if line == "" {
continue
}
// yescrypt sanity check
if !yescryptRegex.MatchString(line) {
continue
}
hashes = append(hashes, YescryptHash{Hash: []byte(line), Cracked: 0})
}
if err := scanner.Err(); err != nil {
return nil, err
}
return hashes, nil
}
func crackYescrypt(password, fullHash []byte) bool {
generatedHash, err := yescrypt.Hash(password, fullHash)
if err != nil {
return false
}
return bytes.Equal(fullHash, generatedHash)
}