aboutsummaryrefslogtreecommitdiff
path: root/internal/crypt/rawEncrypt.go
diff options
context:
space:
mode:
authorishaan <contact@ishaan.cc>2026-07-13 11:09:34 +0530
committerishaan <contact@ishaan.cc>2026-07-13 11:09:34 +0530
commitd433b1af731ff901b9c14a647678471b27fdfe8a (patch)
treeb101b59e89d826386de8bbada4c405a3cfbf6b3f /internal/crypt/rawEncrypt.go
parent388971e7a86be97f6a7412cd1d526016bc4e14ce (diff)
better
Diffstat (limited to 'internal/crypt/rawEncrypt.go')
-rw-r--r--internal/crypt/rawEncrypt.go9
1 files changed, 4 insertions, 5 deletions
diff --git a/internal/crypt/rawEncrypt.go b/internal/crypt/rawEncrypt.go
index f197650..135efdf 100644
--- a/internal/crypt/rawEncrypt.go
+++ b/internal/crypt/rawEncrypt.go
@@ -4,12 +4,11 @@ import (
"fmt"
"strconv"
- "gitlab.com/whiteboardguy/eno/internal/utils"
"golang.org/x/crypto/argon2"
"golang.org/x/crypto/chacha20poly1305"
)
-func EncryptRawBytes(inputBytes []byte, password []byte) ([]byte, error) {
+func EncryptRawBytes(inputBytes []byte, password []byte, authMode AuthMode) ([]byte, error) {
salt, err := NewSalt()
if err != nil {
return nil, fmt.Errorf("encrypt: %w", err)
@@ -20,10 +19,10 @@ func EncryptRawBytes(inputBytes []byte, password []byte) ([]byte, error) {
return nil, fmt.Errorf("encrypt: %w", err)
}
- headers := utils.FileHeaders{Salt: salt, Nonce: nonce}
+ headers := FileHeaders{Salt: salt, Nonce: nonce, Type: File, Parts: 1, Auth: authMode}
key := argon2.IDKey(password, headers.Salt[:], 1, 2*1024*1024, 2, 32)
- utils.TryMlock(key)
+ TryMlock(key)
defer clear(key)
aead, err := chacha20poly1305.New(key)
if err != nil {
@@ -32,7 +31,7 @@ func EncryptRawBytes(inputBytes []byte, password []byte) ([]byte, error) {
encrypted := aead.Seal(nil, headers.Nonce[:], inputBytes, nil)
- headerBytes, err := utils.FileHeadersBytes(headers)
+ headerBytes, err := FileHeadersBytes(headers)
if err != nil {
return nil, fmt.Errorf("encrypt: %w", err)
}