Commit 424d909b authored by Janoš Guljaš's avatar Janoš Guljaš Committed by GitHub

remove meaningless code from encryption transform method (#598)

parent ff3994b3
...@@ -21,7 +21,6 @@ import ( ...@@ -21,7 +21,6 @@ import (
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"hash" "hash"
"sync"
) )
const KeyLength = 32 const KeyLength = 32
...@@ -96,27 +95,17 @@ func (e *Encryption) Reset() { ...@@ -96,27 +95,17 @@ func (e *Encryption) Reset() {
// split up input into keylength segments and encrypt sequentially // split up input into keylength segments and encrypt sequentially
func (e *Encryption) transform(in, out []byte) error { func (e *Encryption) transform(in, out []byte) error {
inLength := len(in) inLength := len(in)
wg := sync.WaitGroup{}
wg.Add((inLength-1)/e.keyLen + 1)
for i := 0; i < inLength; i += e.keyLen { for i := 0; i < inLength; i += e.keyLen {
errs := make(chan error, 1)
l := min(e.keyLen, inLength-i) l := min(e.keyLen, inLength-i)
go func(i int, x, y []byte) { err := e.Transcrypt(e.index, in[i:i+l], out[i:i+l])
defer wg.Done()
err := e.Transcrypt(i, x, y)
errs <- err
}(e.index, in[i:i+l], out[i:i+l])
e.index++
err := <-errs
if err != nil { if err != nil {
close((errs))
return err return err
} }
e.index++
} }
// pad the rest if out is longer // pad the rest if out is longer
pad(out[inLength:]) pad(out[inLength:])
wg.Wait()
return nil return nil
} }
......
...@@ -130,6 +130,9 @@ func TestEncryptionAndDecryption(t *testing.T) { ...@@ -130,6 +130,9 @@ func TestEncryptionAndDecryption(t *testing.T) {
{4096}, {4096},
{4097}, {4097},
{15000}, {15000},
{256 * 1024},
// {256 * 1024 * 2}, // TODO: fix - incorrect join
// {256 * 1024 * 3}, // TODO: fix - deadlock
} }
for _, tt := range tests { for _, tt := range tests {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment