You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2015/12/07 08:30:08 UTC

[6/7] mina-sshd git commit: Re-use buffer in AbstractSession#resizeKey loop

Re-use buffer in AbstractSession#resizeKey loop


Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/7c0f681f
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/7c0f681f
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/7c0f681f

Branch: refs/heads/master
Commit: 7c0f681feaa616dd03bd3cf99ceb51383b3df026
Parents: f135b61
Author: Lyor Goldstein <lg...@vmware.com>
Authored: Mon Dec 7 09:07:06 2015 +0200
Committer: Lyor Goldstein <lg...@vmware.com>
Committed: Mon Dec 7 09:07:06 2015 +0200

----------------------------------------------------------------------
 .../org/apache/sshd/common/session/AbstractSession.java  | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/7c0f681f/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java b/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java
index e60cf85..02af7cf 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java
@@ -1338,16 +1338,19 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
      * initialize the cipher to the needed length.
      *
      * @param e         the key to resize
-     * @param blockSize the cipher block size
+     * @param blockSize the cipher block size (in bytes)
      * @param hash      the hash algorithm
      * @param k         the key exchange k parameter
      * @param h         the key exchange h parameter
-     * @return the resize key
+     * @return the resized key
      * @throws Exception if a problem occur while resizing the key
      */
     protected byte[] resizeKey(byte[] e, int blockSize, Digest hash, byte[] k, byte[] h) throws Exception {
-        while (blockSize > e.length) {
-            Buffer buffer = new ByteArrayBuffer();
+        for (Buffer buffer = null; blockSize > e.length; buffer = BufferUtils.clear(buffer)) {
+            if (buffer == null) {
+                buffer = new ByteArrayBuffer();
+            }
+
             buffer.putMPInt(k);
             buffer.putRawBytes(h);
             buffer.putRawBytes(e);