|
1 | 1 | package auth
|
2 | 2 |
|
3 | 3 | import "crypto/md5"
|
4 |
| -import "strings" |
5 | 4 |
|
6 | 5 | const itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
7 | 6 |
|
8 |
| -var md5_crypt_swaps = [16]int{12, 6, 0, 13, 7, 1, 14, 8, 2, 15, 9, 3, 5, 10, 4, 11} |
| 7 | +var md5CryptSwaps = [16]int{12, 6, 0, 13, 7, 1, 14, 8, 2, 15, 9, 3, 5, 10, 4, 11} |
9 | 8 |
|
10 |
| -type MD5Entry struct { |
11 |
| - Magic, Salt, Hash []byte |
12 |
| -} |
13 |
| - |
14 |
| -func NewMD5Entry(e string) *MD5Entry { |
15 |
| - parts := strings.SplitN(e, "$", 4) |
16 |
| - if len(parts) != 4 { |
17 |
| - return nil |
18 |
| - } |
19 |
| - return &MD5Entry{ |
20 |
| - Magic: []byte("$" + parts[1] + "$"), |
21 |
| - Salt: []byte(parts[2]), |
22 |
| - Hash: []byte(parts[3]), |
23 |
| - } |
24 |
| -} |
25 |
| - |
26 |
| -/* |
27 |
| - MD5 password crypt implementation |
28 |
| -*/ |
| 9 | +// MD5Crypt is the MD5 password crypt implementation. |
29 | 10 | func MD5Crypt(password, salt, magic []byte) []byte {
|
30 | 11 | d := md5.New()
|
31 | 12 |
|
@@ -79,7 +60,7 @@ func MD5Crypt(password, salt, magic []byte) []byte {
|
79 | 60 | result := make([]byte, 0, 22)
|
80 | 61 | v := uint(0)
|
81 | 62 | bits := uint(0)
|
82 |
| - for _, i := range md5_crypt_swaps { |
| 63 | + for _, i := range md5CryptSwaps { |
83 | 64 | v |= (uint(final[i]) << bits)
|
84 | 65 | for bits = bits + 8; bits > 6; bits -= 6 {
|
85 | 66 | result = append(result, itoa64[v&0x3f])
|
|
0 commit comments