From ef7b3e0c8bec59abcb6c1259af147bee8169203f Mon Sep 17 00:00:00 2001 From: zzz Date: Tue, 26 Jun 2018 20:29:19 +0000 Subject: [PATCH] Core: misc. minor changes --- .../src/net/i2p/crypto/HMAC256Generator.java | 4 +++- .../src/net/i2p/crypto/SipHashInline.java | 21 +++++++++++++++++++ core/java/src/net/i2p/data/DataHelper.java | 6 ++++-- core/java/src/net/i2p/util/HexDump.java | 13 ++++-------- .../src/net/i2p/util/I2PSSLSocketFactory.java | 1 + core/java/src/net/i2p/util/SystemVersion.java | 2 +- 6 files changed, 34 insertions(+), 13 deletions(-) diff --git a/core/java/src/net/i2p/crypto/HMAC256Generator.java b/core/java/src/net/i2p/crypto/HMAC256Generator.java index bb5b62d15..816d488d1 100644 --- a/core/java/src/net/i2p/crypto/HMAC256Generator.java +++ b/core/java/src/net/i2p/crypto/HMAC256Generator.java @@ -128,10 +128,12 @@ public final class HMAC256Generator extends HMACGenerator { * */ /**** + private static final int LENGTH = 33; + public static void main(String args[]) { I2PAppContext ctx = I2PAppContext.getGlobalContext(); byte[] rand = new byte[32]; - byte[] data = new byte[1500]; + byte[] data = new byte[LENGTH]; Key keyObj = new SecretKeySpec(rand, "HmacSHA256"); SessionKey key = new SessionKey(rand); diff --git a/core/java/src/net/i2p/crypto/SipHashInline.java b/core/java/src/net/i2p/crypto/SipHashInline.java index 90a212ce1..dc92d1d2f 100644 --- a/core/java/src/net/i2p/crypto/SipHashInline.java +++ b/core/java/src/net/i2p/crypto/SipHashInline.java @@ -211,4 +211,25 @@ public final class SipHashInline { // } return v0 ^ v1 ^ v2 ^ v3; } + + /** + * Test vectors from https://www.131002.net/siphash/siphash.pdf + */ +/**** + public static void main(String[] args) { + long k0 = 0x0706050403020100L; + long k1 = 0x0f0e0d0c0b0a0908L; + byte[] data = new byte[15]; + for (int i = 0; i < data.length; i++) { + data[i] = (byte) i; + } + long result = hash24(k0, k1, data); + long expect = 0xa129ca6149be45e5L; + if (result == expect) + System.out.println("PASS"); + else + System.out.println("FAIL expect " + Long.toString(expect, 16) + + " got " + Long.toString(result, 16)); + } +****/ } diff --git a/core/java/src/net/i2p/data/DataHelper.java b/core/java/src/net/i2p/data/DataHelper.java index 7c2cf9a4c..aec75835d 100644 --- a/core/java/src/net/i2p/data/DataHelper.java +++ b/core/java/src/net/i2p/data/DataHelper.java @@ -94,7 +94,9 @@ public class DataHelper { "family", "family.key", "family.sig", // BlockfileNamingService "version", "created", "upgraded", "lists", - "a", "m", "s", "v" + "a", "m", "s", "v", "notes", + // NTCP2 RouterAddress options + "i" }; _propertiesKeyCache = new HashMap(keys.length); for (int i = 0; i < keys.length; i++) { @@ -670,7 +672,7 @@ public class DataHelper { } if (rv < 0) - throw new DataFormatException("fromLong got a negative? " + rv + " numBytes=" + numBytes); + throw new DataFormatException("readLong got a negative? " + rv + " numBytes=" + numBytes); return rv; } diff --git a/core/java/src/net/i2p/util/HexDump.java b/core/java/src/net/i2p/util/HexDump.java index 69adacf7c..cda4b8ad4 100644 --- a/core/java/src/net/i2p/util/HexDump.java +++ b/core/java/src/net/i2p/util/HexDump.java @@ -27,6 +27,7 @@ public class HexDump { private static final int FORMAT_OFFSET_PADDING = 8; private static final int FORMAT_BYTES_PER_ROW = 16; + private static final int OUTPUT_BYTES_PER_ROW = 79; private static final byte[] HEXCHARS = DataHelper.getASCII("0123456789abcdef"); /** @@ -35,14 +36,7 @@ public class HexDump { * @param data Data to be dumped */ public static String dump(byte[] data) { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - - try { - dump(data, 0, data.length, out); - return out.toString("ISO-8859-1"); - } catch (IOException e) { - throw new RuntimeException("no 8859?", e); - } + return dump(data, 0, data.length); } /** @@ -53,7 +47,8 @@ public class HexDump { * @param len Number of bytes of data to be dumped */ public static String dump(byte[] data, int off, int len) { - ByteArrayOutputStream out = new ByteArrayOutputStream(); + int outlen = OUTPUT_BYTES_PER_ROW * (len + FORMAT_BYTES_PER_ROW - 1) / FORMAT_BYTES_PER_ROW; + ByteArrayOutputStream out = new ByteArrayOutputStream(outlen); try { dump(data, off, len, out); diff --git a/core/java/src/net/i2p/util/I2PSSLSocketFactory.java b/core/java/src/net/i2p/util/I2PSSLSocketFactory.java index 1b8342808..9321cd09d 100644 --- a/core/java/src/net/i2p/util/I2PSSLSocketFactory.java +++ b/core/java/src/net/i2p/util/I2PSSLSocketFactory.java @@ -144,6 +144,7 @@ public class I2PSSLSocketFactory { /** * We exclude everything that Java 8 disables by default, plus some others. * ref: http://docs.oracle.com/javase/8/docs/technotes/guides/security/SunProviders.html + * See also: https://developer.android.com/reference/javax/net/ssl/SSLSocket.html * Unmodifiable. * Public for RouterConsoleRunner. * @since 0.9.16 diff --git a/core/java/src/net/i2p/util/SystemVersion.java b/core/java/src/net/i2p/util/SystemVersion.java index cac42d12e..63161c82c 100644 --- a/core/java/src/net/i2p/util/SystemVersion.java +++ b/core/java/src/net/i2p/util/SystemVersion.java @@ -340,12 +340,12 @@ public abstract class SystemVersion { System.out.println("GNU : " + isGNU()); System.out.println("Linux Svc: " + isLinuxService()); System.out.println("Mac : " + isMac()); + System.out.println("Max mem : " + getMaxMemory()); System.out.println("OpenJDK : " + isOpenJDK()); System.out.println("Slow : " + isSlow()); System.out.println("Windows : " + isWindows()); System.out.println("Wrapper : " + hasWrapper()); System.out.println("x86 : " + isX86()); - System.out.println("Max mem : " + getMaxMemory()); } }