Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
crypto
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
crypto
Commits
d25222ea
Commit
d25222ea
authored
Apr 6, 2022
by
Jono Wenger
Browse files
Options
Downloads
Patches
Plain Diff
Remove error from file transfer EncryptPart
parent
c2483697
No related branches found
No related tags found
2 merge requests
!65
Updates for Channel Support
,
!37
Restructure
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
fileTransfer/crypt.go
+10
-6
10 additions, 6 deletions
fileTransfer/crypt.go
with
10 additions
and
6 deletions
fileTransfer/crypt.go
+
10
−
6
View file @
d25222ea
...
@@ -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
{
p
anic
(
err
)
jww
.
FATAL
.
P
anic
(
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
{
p
anic
(
err
)
jww
.
FATAL
.
P
anic
(
err
)
}
}
cipher
.
XORKeyStream
(
filePartBytes
,
ciphertext
)
cipher
.
XORKeyStream
(
filePartBytes
,
ciphertext
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment