mirror of
https://github.com/rwinkhart/rcw.git
synced 2026-09-05 16:47:24 -04:00
Optimize salt+nonce appends
This commit is contained in:
+1
-6
@@ -27,12 +27,7 @@ func encryptAES(decBytes, key2, salt2 []byte) []byte {
|
|||||||
ciphertext := aesGCM.Seal(nil, nonce, decBytes, nil)
|
ciphertext := aesGCM.Seal(nil, nonce, decBytes, nil)
|
||||||
|
|
||||||
// format: salt2 + nonce + ciphertext
|
// format: salt2 + nonce + ciphertext
|
||||||
result := make([]byte, 0, saltSize2+nonceSizeAES+len(ciphertext))
|
return append(append(append(make([]byte, 0, saltSize2+nonceSizeAES+len(ciphertext)), salt2...), nonce...), ciphertext...)
|
||||||
result = append(result, salt2...)
|
|
||||||
result = append(result, nonce...)
|
|
||||||
result = append(result, ciphertext...)
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DecryptAES decrypts data using AES256-GCM.
|
// DecryptAES decrypts data using AES256-GCM.
|
||||||
|
|||||||
+1
-6
@@ -22,12 +22,7 @@ func encryptCha(decBytes, key2, salt2 []byte) []byte {
|
|||||||
ciphertext := stream.Seal(nil, nonce, decBytes, nil)
|
ciphertext := stream.Seal(nil, nonce, decBytes, nil)
|
||||||
|
|
||||||
// format: salt2 + nonce + ciphertext
|
// format: salt2 + nonce + ciphertext
|
||||||
result := make([]byte, 0, saltSize2+nonceSizeCha+len(ciphertext))
|
return append(append(append(make([]byte, 0, saltSize2+nonceSizeCha+len(ciphertext)), salt2...), nonce...), ciphertext...)
|
||||||
result = append(result, salt2...)
|
|
||||||
result = append(result, nonce...)
|
|
||||||
result = append(result, ciphertext...)
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DecryptCha decrypts data using ChaCha20-Poly1305.
|
// DecryptCha decrypts data using ChaCha20-Poly1305.
|
||||||
|
|||||||
@@ -28,8 +28,5 @@ func Encrypt(decBytes []byte, passphrase []byte) []byte {
|
|||||||
decBytes = encryptAES(decBytes, key2AES, salt2AES)
|
decBytes = encryptAES(decBytes, key2AES, salt2AES)
|
||||||
decBytes = encryptCha(decBytes, key2Cha, salt2Cha)
|
decBytes = encryptCha(decBytes, key2Cha, salt2Cha)
|
||||||
// format: salt1 + decBytes per algorithm (salt2* + nonce + ciphertext)
|
// format: salt1 + decBytes per algorithm (salt2* + nonce + ciphertext)
|
||||||
encBytes := make([]byte, 0, saltSize1+len(decBytes))
|
return append(append(make([]byte, 0, saltSize1+len(decBytes)), salt1...), decBytes...)
|
||||||
encBytes = append(encBytes, salt1...)
|
|
||||||
encBytes = append(encBytes, decBytes...)
|
|
||||||
return encBytes
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user