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 (
"encoding/binary"
"fmt"
"hash"
"sync"
)
const KeyLength = 32
......@@ -96,27 +95,17 @@ func (e *Encryption) Reset() {
// split up input into keylength segments and encrypt sequentially
func (e *Encryption) transform(in, out []byte) error {
inLength := len(in)
wg := sync.WaitGroup{}
wg.Add((inLength-1)/e.keyLen + 1)
for i := 0; i < inLength; i += e.keyLen {
errs := make(chan error, 1)
l := min(e.keyLen, inLength-i)
go func(i int, x, y []byte) {
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
err := e.Transcrypt(e.index, in[i:i+l], out[i:i+l])
if err != nil {
close((errs))
return err
}
e.index++
}
// pad the rest if out is longer
pad(out[inLength:])
wg.Wait()
return nil
}
......
......@@ -130,6 +130,9 @@ func TestEncryptionAndDecryption(t *testing.T) {
{4096},
{4097},
{15000},
{256 * 1024},
// {256 * 1024 * 2}, // TODO: fix - incorrect join
// {256 * 1024 * 3}, // TODO: fix - deadlock
}
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