summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklós Fazekas <mfazekas@szemafor.com>2018-02-06 09:30:05 +0100
committerGitHub <noreply@github.com>2018-02-06 09:30:05 +0100
commit029dd8bb3ec14a99a613414ffcef877e0827f85a (patch)
tree123f359efade4725f393909d73db0428129b5b1c
parentc43fc3ade9337fa6688019b8baf2a2288105b272 (diff)
parent5772d3174780279c3d54cb53eb37149718daa092 (diff)
downloadnet-ssh-029dd8bb3ec14a99a613414ffcef877e0827f85a.tar.gz
Merge pull request #569 from apachelogger/master
improve CTR speed by not mutating the remaining string in a loop
-rw-r--r--lib/net/ssh/transport/ctr.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/net/ssh/transport/ctr.rb b/lib/net/ssh/transport/ctr.rb
index 8b446b5..03d89ca 100644
--- a/lib/net/ssh/transport/ctr.rb
+++ b/lib/net/ssh/transport/ctr.rb
@@ -12,7 +12,7 @@ module Net::SSH::Transport
@counter_len = orig.block_size
orig.encrypt
orig.padding = 0
-
+
singleton_class.send(:alias_method, :_update, :update)
singleton_class.send(:private, :_update)
singleton_class.send(:undef_method, :update)
@@ -50,11 +50,14 @@ module Net::SSH::Transport
encrypted = ""
- while @remaining.bytesize >= block_size
- encrypted += xor!(@remaining.slice!(0, block_size),
+ offset = 0
+ while (@remaining.bytesize - offset) >= block_size
+ encrypted += xor!(@remaining.slice(offset, block_size),
_update(@counter))
increment_counter!
+ offset += block_size
end
+ @remaining = @remaining.slice(offset..-1)
encrypted
end