Changeset fd23b23 for core/java


Ignore:
Timestamp:
Dec 11, 2018 12:19:46 PM (19 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
2746ed5
Parents:
a63d2dc
Message:

Crypto: HMAC-SHA256 cleanup
Add byte[] key method to reduce object churn in NTCP2
Un-deprecate in context

Location:
core/java/src/net/i2p
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/I2PAppContext.java

    ra63d2dc rfd23b23  
    747747    }
    748748
    749     /** @deprecated used only by syndie */
    750     @Deprecated
     749    /**
     750     * Un-deprecated in 0.9.38
     751     */
    751752    public HMAC256Generator hmac256() {
    752753        if (!_hmac256Initialized)
  • core/java/src/net/i2p/crypto/HMAC256Generator.java

    ra63d2dc rfd23b23  
    55import java.security.MessageDigest;
    66import java.security.NoSuchAlgorithmException;
     7import javax.crypto.Mac;
    78import javax.crypto.spec.SecretKeySpec;
    89
     
    2021 * As of 0.9.12, uses javax.crypto.Mac.
    2122 *
    22  * Deprecated, used only by Syndie.
     23 * Warning - used by Syndie, don't break it.
    2324 */
    2425public final class HMAC256Generator extends HMACGenerator {
     
    3435     */
    3536    @Override
     37    @Deprecated
    3638    protected I2PHMac acquire() {
    3739        throw new UnsupportedOperationException();
     
    4749     */
    4850    @Override
     51    @Deprecated
    4952    public Hash calculate(SessionKey key, byte data[]) {
    5053        throw new UnsupportedOperationException();
     
    6164    @Override
    6265    public void calculate(SessionKey key, byte data[], int offset, int length, byte target[], int targetOffset) {
     66        calculate(key.getData(), data, offset, length, target, targetOffset);
     67    }
     68   
     69    /**
     70     *  Calculate the HMAC of the data with the given key.
     71     *  Outputs 32 bytes to target starting at targetOffset.
     72     *
     73     *  @param key 32 bytes
     74     *  @throws UnsupportedOperationException if the JVM does not support it
     75     *  @throws IllegalArgumentException for bad key or target too small
     76     *  @since 0.9.38
     77     */
     78    public void calculate(byte[] key, byte data[], int offset, int length, byte target[], int targetOffset) {
    6379        try {
    64             javax.crypto.Mac mac = javax.crypto.Mac.getInstance("HmacSHA256");
    65             Key keyObj = new SecretKeySpec(key.getData(), "HmacSHA256");
     80            Mac mac = Mac.getInstance("HmacSHA256");
     81            Key keyObj = new SecretKeySpec(key, "HmacSHA256");
    6682            mac.init(keyObj);
    6783            mac.update(data, offset, length);
Note: See TracChangeset for help on using the changeset viewer.