Changeset 1ad1883


Ignore:
Timestamp:
Jan 12, 2011 1:27:55 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
79bd5f1
Parents:
7289c89
Message:

fix hashCode

File:
1 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/data/PrivateKey.java

    r7289c89 r1ad1883  
    1616 * A private key is 256byte Integer. The private key represents only the
    1717 * exponent, not the primes, which are constant and defined in the crypto spec.
     18 *
     19 * Note that we use short exponents, so all but the last 28.25 bytes are zero.
     20 * See http://www.i2p2.i2p/how_cryptography for details.
    1821 *
    1922 * @author jrandom
     
    5154    }
    5255
     56    /**
     57     * We assume the data has enough randomness in it, so use the last 4 bytes for speed.
     58     * Overridden since we use short exponents, so the first 227 bytes are all zero.
     59     * Not that we are storing PrivateKeys in any Sets or Maps anywhere.
     60     */
     61    @Override
     62    public int hashCode() {
     63        if (_data == null)
     64            return 0;
     65        int rv = _data[KEYSIZE_BYTES - 4];
     66        for (int i = 1; i < 4; i++)
     67            rv ^= (_data[i + (KEYSIZE_BYTES - 4)] << (i*8));
     68        return rv;
     69    }
     70
     71    @Override
     72    public boolean equals(Object obj) {
     73        if ((obj == null) || !(obj instanceof PrivateKey)) return false;
     74        return DataHelper.eq(_data, ((PrivateKey) obj)._data);
     75    }
    5376}
Note: See TracChangeset for help on using the changeset viewer.