Skip to content
Snippets Groups Projects
Commit d25222ea authored by Jono Wenger's avatar Jono Wenger
Browse files

Remove error from file transfer EncryptPart

parent c2483697
No related branches found
No related tags found
2 merge requests!65Updates for Channel Support,!37Restructure
...@@ -16,6 +16,7 @@ package fileTransfer ...@@ -16,6 +16,7 @@ package fileTransfer
import ( import (
"github.com/pkg/errors" "github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/primitives/format" "gitlab.com/elixxir/primitives/format"
"golang.org/x/crypto/chacha20" "golang.org/x/crypto/chacha20"
) )
...@@ -29,7 +30,8 @@ const ( ...@@ -29,7 +30,8 @@ const (
// part key is generated from the transfer key and the fingerprint number. A // part key is generated from the transfer key and the fingerprint number. A
// random nonce is generated as padding for the ciphertext and used as part of // random nonce is generated as padding for the ciphertext and used as part of
// the encryption. // the encryption.
func EncryptPart(transferKey TransferKey, partBytes []byte, fpNum uint16, fp format.Fingerprint) (ciphertext, mac []byte, err error) { func EncryptPart(transferKey TransferKey, partBytes []byte, fpNum uint16,
fp format.Fingerprint) (ciphertext, mac []byte) {
// Generate the part key and redefine as array // Generate the part key and redefine as array
partKey := getPartKey(transferKey, fpNum) partKey := getPartKey(transferKey, fpNum)
...@@ -39,9 +41,10 @@ func EncryptPart(transferKey TransferKey, partBytes []byte, fpNum uint16, fp for ...@@ -39,9 +41,10 @@ func EncryptPart(transferKey TransferKey, partBytes []byte, fpNum uint16, fp for
ciphertext = make([]byte, ciphertextLen) ciphertext = make([]byte, ciphertextLen)
// ChaCha20 encrypt file part bytes // ChaCha20 encrypt file part bytes
cipher, err := chacha20.NewUnauthenticatedCipher(partKey[:], fp[:chacha20.NonceSizeX]) cipher, err := chacha20.NewUnauthenticatedCipher(
partKey[:], fp[:chacha20.NonceSizeX])
if err != nil { if err != nil {
panic(err) jww.FATAL.Panic(err)
} }
cipher.XORKeyStream(ciphertext, partBytes) cipher.XORKeyStream(ciphertext, partBytes)
...@@ -49,7 +52,7 @@ func EncryptPart(transferKey TransferKey, partBytes []byte, fpNum uint16, fp for ...@@ -49,7 +52,7 @@ func EncryptPart(transferKey TransferKey, partBytes []byte, fpNum uint16, fp for
mac = createPartMAC(fp[:], partBytes, partKey) mac = createPartMAC(fp[:], partBytes, partKey)
// The nonce and ciphertext are returned separately // The nonce and ciphertext are returned separately
return ciphertext, mac, nil return ciphertext, mac
} }
// DecryptPart decrypts an individual file part. The part key and nonce are used // DecryptPart decrypts an individual file part. The part key and nonce are used
...@@ -64,9 +67,10 @@ func DecryptPart(transferKey TransferKey, ciphertext, mac []byte, ...@@ -64,9 +67,10 @@ func DecryptPart(transferKey TransferKey, ciphertext, mac []byte,
filePartBytes = make([]byte, len(ciphertext)) filePartBytes = make([]byte, len(ciphertext))
// ChaCha20 encrypt file part bytes // ChaCha20 encrypt file part bytes
cipher, err := chacha20.NewUnauthenticatedCipher(partKey[:], fp[:chacha20.NonceSizeX]) cipher, err := chacha20.NewUnauthenticatedCipher(
partKey[:], fp[:chacha20.NonceSizeX])
if err != nil { if err != nil {
panic(err) jww.FATAL.Panic(err)
} }
cipher.XORKeyStream(filePartBytes, ciphertext) cipher.XORKeyStream(filePartBytes, ciphertext)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment