From e6dcfaee158b1d04d3db7162d23b79bd07df9b8a Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Thu, 29 Aug 2019 12:07:30 +0000
Subject: [PATCH] Transport: Move I2PHMac to ssu package Remove Mac interface

---
 build.xml                                     |  4 +-
 core/java/build.xml                           |  1 -
 .../i2p/router/transport/udp}/I2PHMac.java    |  9 +-
 .../transport/udp/SSUHMACGenerator.java       |  4 +-
 .../src/org/bouncycastle/oldcrypto/Mac.java   | 99 -------------------
 .../bouncycastle/oldcrypto/macs/package.html  | 17 ----
 .../org/bouncycastle/oldcrypto/package.html   | 17 ----
 7 files changed, 7 insertions(+), 144 deletions(-)
 rename router/java/src/{org/bouncycastle/oldcrypto/macs => net/i2p/router/transport/udp}/I2PHMac.java (98%)
 delete mode 100644 router/java/src/org/bouncycastle/oldcrypto/Mac.java
 delete mode 100644 router/java/src/org/bouncycastle/oldcrypto/macs/package.html
 delete mode 100644 router/java/src/org/bouncycastle/oldcrypto/package.html

diff --git a/build.xml b/build.xml
index 7986fb74d6..65b2b7120e 100644
--- a/build.xml
+++ b/build.xml
@@ -827,7 +827,7 @@
             windowtitle="I2P Anonymous Network - Java Documentation - Version ${release.number}">
             <group title="Core SDK (i2p.jar)" packages="net.i2p:net.i2p.*:net.i2p.client:net.i2p.client.*:net.i2p.internal:net.i2p.internal.*:freenet.support.CPUInformation:gnu.crypto.*:gnu.getopt:gnu.gettext:com.nettgryppa.security:org.apache.http.conn.ssl:org.apache.http.conn.util:org.apache.http.util:org.json.simple:org.json.simple.*:com.southernstorm.noise.crypto.x25519:com.southernstorm.noise.crypto.chacha20" />
             <group title="Streaming Library" packages="net.i2p.client.streaming:net.i2p.client.streaming.impl" />
-            <group title="Router" packages="net.i2p.router:net.i2p.router.*:net.i2p.data.i2np:net.i2p.data.router:org.cybergarage:org.cybergarage.*:org.freenetproject:org.xlattice.crypto.filters:com.maxmind.*:com.southernstorm.noise.*:org.bouncycastle.oldcrypto:org.bouncycastle.oldcrypto.*" />
+            <group title="Router" packages="net.i2p.router:net.i2p.router.*:net.i2p.data.i2np:net.i2p.data.router:org.cybergarage:org.cybergarage.*:org.freenetproject:org.xlattice.crypto.filters:com.maxmind.*:com.southernstorm.noise.*" />
             <group title="Router Console" packages="net.i2p.router.web:net.i2p.router.web.*:net.i2p.router.update:net.i2p.router.sybil:edu.internet2.ndt:net.i2p.router.news:com.vuze.*" />
             <!-- apps and bridges starting here, alphabetical please -->
             <group title="Addressbook Application" packages="net.i2p.addressbook:net.i2p.router.naming:net.metanotion:net.metanotion.*" />
@@ -920,7 +920,7 @@
             doctitle="I2P Unit Test Javadocs for Release ${release.number} Build ${i2p.build.number}${build.extra}"
             windowtitle="I2P Anonymous Network - Java Documentation - Version ${release.number}">
             <group title="Core SDK" packages="net.i2p:net.i2p.*:net.i2p.client:net.i2p.client.*:net.i2p.internal:net.i2p.internal.*:freenet.support.CPUInformation:gnu.crypto.*:gnu.gettext:org:com.nettgryppa.security:net.metanotion:net.metanotion.*" />
-            <group title="Router" packages="net.i2p.router:net.i2p.router.*:net.i2p.data.i2np:org.cybergarage.*:org.freenetproject:org.xlattice.crypto.filters:org.bouncycastle.oldcrypto:org.bouncycastle.oldcrypto.*" />
+            <group title="Router" packages="net.i2p.router:net.i2p.router.*:net.i2p.data.i2np:org.cybergarage.*:org.freenetproject:org.xlattice.crypto.filters" />
             <sourcepath>
                 <pathelement location="core/java/test/junit" />
                 <pathelement location="router/java/test/junit" />
diff --git a/core/java/build.xml b/core/java/build.xml
index a4e0f735ee..a1d8bde500 100644
--- a/core/java/build.xml
+++ b/core/java/build.xml
@@ -291,7 +291,6 @@
                 <exclude name="freenet/**/*.class" />
                 <exclude name="gnu/**/*.class" />
                 <exclude name="net/metanotion/**/*.class" />
-                <exclude name="org/bouncycastle/**/*.class" />
                 <exclude name="org/xlattice/**/*.class" />
             </fileset>
         </cobertura-instrument>
diff --git a/router/java/src/org/bouncycastle/oldcrypto/macs/I2PHMac.java b/router/java/src/net/i2p/router/transport/udp/I2PHMac.java
similarity index 98%
rename from router/java/src/org/bouncycastle/oldcrypto/macs/I2PHMac.java
rename to router/java/src/net/i2p/router/transport/udp/I2PHMac.java
index 646f8329e1..2ce5fa84e9 100644
--- a/router/java/src/org/bouncycastle/oldcrypto/macs/I2PHMac.java
+++ b/router/java/src/net/i2p/router/transport/udp/I2PHMac.java
@@ -1,4 +1,4 @@
-package org.bouncycastle.oldcrypto.macs;
+package net.i2p.router.transport.udp;
 /*
  * Copyright (c) 2000 - 2004 The Legion Of The Bouncy Castle
  * (http://www.bouncycastle.org)
@@ -33,8 +33,6 @@ import java.util.Arrays;
 
 import net.i2p.util.SimpleByteCache;
 
-import org.bouncycastle.oldcrypto.Mac;
-
 /**
  * HMAC implementation based on RFC2104
  *
@@ -52,9 +50,10 @@ import org.bouncycastle.oldcrypto.Mac;
  *
  * Deprecated - Do not use outside of router or Syndie.
  * Not a public API - Not for external use!
+ *
+ * @since 0.9.43 moved from org.bouncycastle.oldcrypto.macs
  */
-public class I2PHMac
-implements Mac
+class I2PHMac
 {
     private final static int BLOCK_LENGTH = 64;
 
diff --git a/router/java/src/net/i2p/router/transport/udp/SSUHMACGenerator.java b/router/java/src/net/i2p/router/transport/udp/SSUHMACGenerator.java
index cdd8edc5a0..a21a3784d3 100644
--- a/router/java/src/net/i2p/router/transport/udp/SSUHMACGenerator.java
+++ b/router/java/src/net/i2p/router/transport/udp/SSUHMACGenerator.java
@@ -18,11 +18,9 @@ import net.i2p.data.Hash;
 import net.i2p.data.SessionKey;
 import net.i2p.util.SimpleByteCache;
 
-import org.bouncycastle.oldcrypto.macs.I2PHMac;
-
 /**
  * Calculate the HMAC-MD5-128 of a key+message.  All the good stuff occurs
- * in {@link org.bouncycastle.oldcrypto.macs.I2PHMac}
+ * in {@link I2PHMac}
  *
  * Keys are always 32 bytes.
  * This is used only by UDP.
diff --git a/router/java/src/org/bouncycastle/oldcrypto/Mac.java b/router/java/src/org/bouncycastle/oldcrypto/Mac.java
deleted file mode 100644
index a55c19959e..0000000000
--- a/router/java/src/org/bouncycastle/oldcrypto/Mac.java
+++ /dev/null
@@ -1,99 +0,0 @@
-package org.bouncycastle.oldcrypto;
-/*
- * Copyright (c) 2000 - 2004 The Legion Of The Bouncy Castle
- * (http://www.bouncycastle.org)
- *
- * Permission is hereby granted, free of charge, to any person 
- * obtaining a copy of this software and associated 
- * documentation files (the "Software"), to deal in the Software
- * without restriction, including without limitation the rights to 
- * use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following 
- * conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- */
-
-
-/**
- * The base interface for implementations of message authentication codes (MACs).
- *
- * modified by jrandom to use the session key byte array directly
- *
- * Not a public API - Not for external use!
- */
-public interface Mac
-{
-    /**
-     * Initialise the MAC.
-     *
-     * @param key the key required by the MAC.
-     * @throws IllegalArgumentException if the params argument is
-     * inappropriate.
-     */
-    public void init(byte key[])
-        throws IllegalArgumentException;
-
-    /**
-     * Return the name of the algorithm the MAC implements.
-     *
-     * @return the name of the algorithm the MAC implements.
-     */
-    public String getAlgorithmName();
-
-    /**
-     * Return the block size for this cipher (in bytes).
-     *
-     * @return the block size for this cipher in bytes.
-     */
-    public int getMacSize();
-
-    /**
-     * add a single byte to the mac for processing.
-     *
-     * @param in the byte to be processed.
-     * @throws IllegalStateException if the MAC is not initialised.
-     */
-    public void update(byte in)
-        throws IllegalStateException;
-
-    /**
-     * @param in the array containing the input.
-     * @param inOff the index in the array the data begins at.
-     * @param len the length of the input starting at inOff.
-     * @throws IllegalStateException if the MAC is not initialised.
-     */
-    public void update(byte[] in, int inOff, int len)
-        throws IllegalStateException;
-
-    /**
-     * Compute the final statge of the MAC writing the output to the out
-     * parameter.
-     * <p>
-     * doFinal leaves the MAC in the same state it was after the last init.
-     *
-     * @param out the array the MAC is to be output to.
-     * @param outOff the offset into the out buffer the output is to start at.
-     * @throws IllegalStateException if the MAC is not initialised.
-     */
-    public int doFinal(byte[] out, int outOff)
-        throws IllegalStateException;
-
-    /**
-     * Reset the MAC. At the end of resetting the MAC should be in the
-     * in the same state it was after the last init (if there was one).
-     */
-    public void reset();
-}
diff --git a/router/java/src/org/bouncycastle/oldcrypto/macs/package.html b/router/java/src/org/bouncycastle/oldcrypto/macs/package.html
deleted file mode 100644
index 5b57a27104..0000000000
--- a/router/java/src/org/bouncycastle/oldcrypto/macs/package.html
+++ /dev/null
@@ -1,17 +0,0 @@
-<html>
-<body>
-<p>
-This is from some very old version of bouncycastle, part of package org.bouncycastle.crypto.
-Android bundled something similar in pre-Gingerbread, but upgraded to a later, incompatible version
-in Gingerbread. As of Java 1.4 these are in javax.crypto - more or less.
-To avoid having to make two different versions of our Android app, we rename to org.bouncycastle.oldcrypto.
-</p><p>
-Ref: <a href="http://docs.oracle.com/javase/1.5.0/docs/api/javax/crypto/package-summary.html">javax.crypto</a>
-and
-<a href="http://code.google.com/p/android/issues/detail?id=3280">this android issue</a>.
-</p><p>
-Moved from i2p.jar to router.jar as of 0.9.42.
-Not a public API! Not for external use!
-</p>
-</body>
-</html>
diff --git a/router/java/src/org/bouncycastle/oldcrypto/package.html b/router/java/src/org/bouncycastle/oldcrypto/package.html
deleted file mode 100644
index 5b57a27104..0000000000
--- a/router/java/src/org/bouncycastle/oldcrypto/package.html
+++ /dev/null
@@ -1,17 +0,0 @@
-<html>
-<body>
-<p>
-This is from some very old version of bouncycastle, part of package org.bouncycastle.crypto.
-Android bundled something similar in pre-Gingerbread, but upgraded to a later, incompatible version
-in Gingerbread. As of Java 1.4 these are in javax.crypto - more or less.
-To avoid having to make two different versions of our Android app, we rename to org.bouncycastle.oldcrypto.
-</p><p>
-Ref: <a href="http://docs.oracle.com/javase/1.5.0/docs/api/javax/crypto/package-summary.html">javax.crypto</a>
-and
-<a href="http://code.google.com/p/android/issues/detail?id=3280">this android issue</a>.
-</p><p>
-Moved from i2p.jar to router.jar as of 0.9.42.
-Not a public API! Not for external use!
-</p>
-</body>
-</html>
-- 
GitLab