mirror of
https://github.com/rwinkhart/rcw.git
synced 2026-08-28 04:46:42 -04:00
Remove Scrypt
This commit is contained in:
+2
-2
@@ -19,7 +19,7 @@ func encryptAES(decBytes []byte, passphrase []byte) []byte {
|
|||||||
io.ReadFull(rand.Reader, salt)
|
io.ReadFull(rand.Reader, salt)
|
||||||
|
|
||||||
// derive key from passphrase using the salt
|
// derive key from passphrase using the salt
|
||||||
key := deriveKeyScrypt(passphrase, salt)
|
key := deriveKey(passphrase, salt)
|
||||||
|
|
||||||
// create AES-256 cipher
|
// create AES-256 cipher
|
||||||
block, _ := aes.NewCipher(key)
|
block, _ := aes.NewCipher(key)
|
||||||
@@ -55,7 +55,7 @@ func decryptAES(encBytes []byte, passphrase []byte) ([]byte, error) {
|
|||||||
ciphertext := encBytes[saltSize+nonceSizeAES:]
|
ciphertext := encBytes[saltSize+nonceSizeAES:]
|
||||||
|
|
||||||
// derive key from passphrase using the salt
|
// derive key from passphrase using the salt
|
||||||
key := deriveKeyScrypt(passphrase, salt)
|
key := deriveKey(passphrase, salt)
|
||||||
|
|
||||||
// create AES-256 cipher
|
// create AES-256 cipher
|
||||||
block, _ := aes.NewCipher(key)
|
block, _ := aes.NewCipher(key)
|
||||||
|
|||||||
+2
-2
@@ -19,7 +19,7 @@ func encryptCha(data []byte, passphrase []byte) []byte {
|
|||||||
io.ReadFull(rand.Reader, salt)
|
io.ReadFull(rand.Reader, salt)
|
||||||
|
|
||||||
// derive key from passphrase using the salt
|
// derive key from passphrase using the salt
|
||||||
key := deriveKeyArgon2(passphrase, salt)
|
key := deriveKey(passphrase, salt)
|
||||||
|
|
||||||
// create ChaCha20-Poly1305 cipher
|
// create ChaCha20-Poly1305 cipher
|
||||||
stream, _ := chacha20poly1305.NewX(key)
|
stream, _ := chacha20poly1305.NewX(key)
|
||||||
@@ -52,7 +52,7 @@ func decryptCha(encryptedData []byte, passphrase []byte) ([]byte, error) {
|
|||||||
ciphertext := encryptedData[saltSize+nonceSizeCha:]
|
ciphertext := encryptedData[saltSize+nonceSizeCha:]
|
||||||
|
|
||||||
// derive key from passphrase using the salt
|
// derive key from passphrase using the salt
|
||||||
key := deriveKeyArgon2(passphrase, salt)
|
key := deriveKey(passphrase, salt)
|
||||||
|
|
||||||
// create ChaCha20-Poly1305 cipher
|
// create ChaCha20-Poly1305 cipher
|
||||||
stream, _ := chacha20poly1305.NewX(key)
|
stream, _ := chacha20poly1305.NewX(key)
|
||||||
|
|||||||
+4
-16
@@ -4,7 +4,6 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"golang.org/x/crypto/argon2"
|
"golang.org/x/crypto/argon2"
|
||||||
"golang.org/x/crypto/scrypt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -12,25 +11,14 @@ const (
|
|||||||
argonTime = 8 // set to pass 1-second test in dev environment
|
argonTime = 8 // set to pass 1-second test in dev environment
|
||||||
argonMemory = 384 * 1024 // 384 MB
|
argonMemory = 384 * 1024 // 384 MB
|
||||||
|
|
||||||
// parameters for Scrypt
|
|
||||||
scryptN = 262144
|
|
||||||
scryptR = 8 // block size, recommended to be 8
|
|
||||||
scryptP = 1 // parallelization factor, recommended to be 1
|
|
||||||
|
|
||||||
// general constants
|
// general constants
|
||||||
keyLen = 32 // 256 bits, key length for both algorithms
|
keyLen = 32 // 256 bits, key length for both algorithms
|
||||||
saltSize = 16 // 128 bits, recommended salt size for both algorithms
|
saltSize = 16 // 128 bits, recommended salt size for both algorithms
|
||||||
)
|
)
|
||||||
|
|
||||||
var threads = uint8(runtime.NumCPU())
|
var argonThreads = uint8(runtime.NumCPU())
|
||||||
|
|
||||||
// DeriveKeyArgon2 derives an encryption key from a passphrase using Argon2.
|
// DeriveKey derives an encryption key from a passphrase using Argon2.
|
||||||
func deriveKeyArgon2(passphrase []byte, salt []byte) []byte {
|
func deriveKey(passphrase []byte, salt []byte) []byte {
|
||||||
return argon2.IDKey(passphrase, salt, argonTime, argonMemory, threads, keyLen)
|
return argon2.IDKey(passphrase, salt, argonTime, argonMemory, argonThreads, keyLen)
|
||||||
}
|
|
||||||
|
|
||||||
// DeriveKeyScrypt derives an encryption key from a passphrase using Scrypt.
|
|
||||||
func deriveKeyScrypt(passphrase []byte, salt []byte) []byte {
|
|
||||||
key, _ := scrypt.Key(passphrase, salt, scryptN, scryptR, scryptP, keyLen)
|
|
||||||
return key
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user