merge of '0c3129e1443b3c155a4e5e06e008fa40a89776a3'

and 'fe23acdcae4f7bace1f6ceb4823a13271fe37207'
This commit is contained in:
z3d
2011-01-14 12:28:32 +00:00
8 changed files with 2749 additions and 2654 deletions

View File

@@ -16,6 +16,9 @@ import net.i2p.crypto.KeyGenerator;
* A private key is 256byte Integer. The private key represents only the
* exponent, not the primes, which are constant and defined in the crypto spec.
*
* Note that we use short exponents, so all but the last 28.25 bytes are zero.
* See http://www.i2p2.i2p/how_cryptography for details.
*
* @author jrandom
*/
public class PrivateKey extends SimpleDataStructure {
@@ -50,4 +53,24 @@ public class PrivateKey extends SimpleDataStructure {
return KeyGenerator.getPublicKey(this);
}
/**
* We assume the data has enough randomness in it, so use the last 4 bytes for speed.
* Overridden since we use short exponents, so the first 227 bytes are all zero.
* Not that we are storing PrivateKeys in any Sets or Maps anywhere.
*/
@Override
public int hashCode() {
if (_data == null)
return 0;
int rv = _data[KEYSIZE_BYTES - 4];
for (int i = 1; i < 4; i++)
rv ^= (_data[i + (KEYSIZE_BYTES - 4)] << (i*8));
return rv;
}
@Override
public boolean equals(Object obj) {
if ((obj == null) || !(obj instanceof PrivateKey)) return false;
return DataHelper.eq(_data, ((PrivateKey) obj)._data);
}
}

View File

@@ -152,7 +152,9 @@ public class LogManager {
if (_writer != null)
return;
_writer = new LogWriter(this);
Thread t = new I2PThread(_writer, "LogWriter", true);
// NOT an I2PThread, as it contains logging and we end up with problems
Thread t = new Thread(_writer, "LogWriter");
t.setDaemon(true);
t.start();
}