|
|
@ -4,7 +4,6 @@ import (
|
|
|
|
"crypto/aes"
|
|
|
|
"crypto/aes"
|
|
|
|
"crypto/cipher"
|
|
|
|
"crypto/cipher"
|
|
|
|
"crypto/rand"
|
|
|
|
"crypto/rand"
|
|
|
|
"crypto/sha512"
|
|
|
|
|
|
|
|
"errors"
|
|
|
|
"errors"
|
|
|
|
"flag"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
@ -15,6 +14,7 @@ import (
|
|
|
|
"syscall"
|
|
|
|
"syscall"
|
|
|
|
"math"
|
|
|
|
"math"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"golang.org/x/crypto/scrypt"
|
|
|
|
"golang.org/x/crypto/ssh/terminal"
|
|
|
|
"golang.org/x/crypto/ssh/terminal"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
@ -27,6 +27,10 @@ func check(err error) {
|
|
|
|
const saltChunkName = "saLt"
|
|
|
|
const saltChunkName = "saLt"
|
|
|
|
const chunkName = "crPt"
|
|
|
|
const chunkName = "crPt"
|
|
|
|
const chunkSize = 0x100000
|
|
|
|
const chunkSize = 0x100000
|
|
|
|
|
|
|
|
const scrN = 32768
|
|
|
|
|
|
|
|
const scrR = 8
|
|
|
|
|
|
|
|
const scrP = 1
|
|
|
|
|
|
|
|
const scrKeyLength = 32
|
|
|
|
|
|
|
|
|
|
|
|
var inputFile string
|
|
|
|
var inputFile string
|
|
|
|
var outputFile string
|
|
|
|
var outputFile string
|
|
|
@ -131,16 +135,17 @@ func readPassword(passwordSalt *[]byte) ([]byte, []byte) {
|
|
|
|
fmt.Print("Password: ")
|
|
|
|
fmt.Print("Password: ")
|
|
|
|
bytePw, err := terminal.ReadPassword(int(syscall.Stdin))
|
|
|
|
bytePw, err := terminal.ReadPassword(int(syscall.Stdin))
|
|
|
|
check(err)
|
|
|
|
check(err)
|
|
|
|
hash := sha512.New512_256()
|
|
|
|
|
|
|
|
if passwordSalt != nil {
|
|
|
|
if passwordSalt != nil {
|
|
|
|
hash.Write(append(*passwordSalt, bytePw...))
|
|
|
|
key, err := scrypt.Key(bytePw, *passwordSalt, scrN, scrR, scrP, scrKeyLength)
|
|
|
|
return hash.Sum(nil), *passwordSalt
|
|
|
|
check(err)
|
|
|
|
|
|
|
|
return key, *passwordSalt
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
salt := make([]byte, 32)
|
|
|
|
salt := make([]byte, 32)
|
|
|
|
_, err = io.ReadFull(rand.Reader, salt)
|
|
|
|
_, err = io.ReadFull(rand.Reader, salt)
|
|
|
|
check(err)
|
|
|
|
check(err)
|
|
|
|
hash.Write(append(salt, bytePw...))
|
|
|
|
key, err := scrypt.Key(bytePw, salt, scrN, scrR, scrP, scrKeyLength)
|
|
|
|
return hash.Sum(nil), salt
|
|
|
|
check(err)
|
|
|
|
|
|
|
|
return key, salt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|