From a255a60944eefcf5d4a18e843ccacad058e4c19a Mon Sep 17 00:00:00 2001 From: zzz Date: Sun, 3 May 2020 11:06:46 +0000 Subject: [PATCH] Crypto: Don't start YK thread in app context --- core/java/src/net/i2p/crypto/ElGamalEngine.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/java/src/net/i2p/crypto/ElGamalEngine.java b/core/java/src/net/i2p/crypto/ElGamalEngine.java index 499976e4d3..33930a06db 100644 --- a/core/java/src/net/i2p/crypto/ElGamalEngine.java +++ b/core/java/src/net/i2p/crypto/ElGamalEngine.java @@ -40,6 +40,7 @@ import net.i2p.data.PublicKey; import net.i2p.util.Log; import net.i2p.util.NativeBigInteger; import net.i2p.util.SimpleByteCache; +import net.i2p.util.SystemVersion; /** * Wrapper for ElGamal encryption/signature schemes. @@ -49,6 +50,8 @@ import net.i2p.util.SimpleByteCache; * making up the SHA256 of the data, then the data itself. The random byte and * the SHA256 hash is stripped on decrypt so the original data is returned. * + * Not recommended for new applications. + * * @author thecrypto, jrandom */ @@ -68,6 +71,7 @@ public final class ElGamalEngine { * application context. This constructor should only be used by the * appropriate application context itself. * + * Starts the YK precalc thread if context is RouterContext or Android. */ public ElGamalEngine(I2PAppContext context) { context.statManager().createRateStat("crypto.elGamal.encrypt", @@ -79,7 +83,12 @@ public final class ElGamalEngine { _context = context; _log = context.logManager().getLog(ElGamalEngine.class); _ykgen = new YKGenerator(context); - _ykgen.start(); + // Don't start the precalc thread for external applications, + // benchmarks, or unit tests. + // YKgen still works, it just won't precalc. + // Known external users are Bote and Syndie. + if (context.isRouterContext() || SystemVersion.isAndroid()) + _ykgen.start(); } /**