From 502e53cdb2f87d96c553b2aa0186a5f334747933 Mon Sep 17 00:00:00 2001 From: CJ Hare Date: Fri, 11 Oct 2019 09:54:36 +1000 Subject: [PATCH] Removing redundant code (#98) Signed-off-by: Christopher Hare --- .../ecies/ECIESEncryptionEngine.java | 28 +++++-------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/handshake/ecies/ECIESEncryptionEngine.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/handshake/ecies/ECIESEncryptionEngine.java index 88ce02390b..56781f8ab0 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/handshake/ecies/ECIESEncryptionEngine.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/handshake/ecies/ECIESEncryptionEngine.java @@ -81,9 +81,6 @@ public class ECIESEncryptionEngine { private final SECP256K1.PublicKey ephPubKey; private final byte[] iv; - // TODO: This V is possibly redundant. - private final byte[] V = new byte[0]; - private ECIESEncryptionEngine( final CipherParameters pubParam, final CipherParameters privParam, @@ -209,22 +206,16 @@ public class ECIESEncryptionEngine { mac.update(P2, 0, P2.length); } - if (V.length != 0 && P2 != null) { - final byte[] L2 = Pack.intToBigEndian(P2.length * 8); - mac.update(L2, 0, L2.length); - } - if (macData != null) { mac.update(macData, 0, macData.length); } mac.doFinal(T, 0); - // Output the triple (V,C,T). - final byte[] Output = new byte[V.length + len + T.length]; - System.arraycopy(V, 0, Output, 0, V.length); - System.arraycopy(C, 0, Output, V.length, len); - System.arraycopy(T, 0, Output, V.length + len, T.length); + final byte[] Output = new byte[len + T.length]; + System.arraycopy(C, 0, Output, 0, len); + System.arraycopy(T, 0, Output, len, T.length); + return Output; } @@ -271,8 +262,8 @@ public class ECIESEncryptionEngine { // Use IV to initialize cipher. cipher.init(false, new ParametersWithIV(new KeyParameter(K1), iv)); - M = new byte[cipher.getOutputSize(inLen - V.length - mac.getMacSize())]; - len = cipher.processBytes(inEnc, inOff + V.length, inLen - V.length - mac.getMacSize(), M, 0); + M = new byte[cipher.getOutputSize(inLen - mac.getMacSize())]; + len = cipher.processBytes(inEnc, inOff, inLen - mac.getMacSize(), M, 0); len += cipher.doFinal(M, len); // Convert the length of the encoding vector into a byte array. @@ -290,17 +281,12 @@ public class ECIESEncryptionEngine { mac.init(new KeyParameter(K2hash)); mac.update(iv, 0, iv.length); - mac.update(inEnc, inOff + V.length, inLen - V.length - T2.length); + mac.update(inEnc, inOff, inLen - T2.length); if (P2 != null) { mac.update(P2, 0, P2.length); } - if (V.length != 0 && P2 != null) { - final byte[] L2 = Pack.intToBigEndian(P2.length * 8); - mac.update(L2, 0, L2.length); - } - if (commonMac != null) { mac.update(commonMac, 0, commonMac.length); }