Changeset 2487bca for core/java


Ignore:
Timestamp:
Nov 30, 2018 3:15:31 PM (20 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
f168918
Parents:
cc4da1b
Message:

Crypto: Change X25519 key classes from Java keys to I2P keys,
in prep for new crypto (Proposal 144)
Add EncType?
Fix PrivateKey? constructor w/ EncType?
Add support to KeyGenerator?

Location:
core/java/src/net/i2p
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/crypto/EncAlgo.java

    rcc4da1b r2487bca  
    1111
    1212    ELGAMAL("ElGamal"),
    13     EC("EC");
     13    EC("EC"),
     14
     15    /** @since 0.9.38 */
     16    ECIES("ECIES");
    1417
    1518    private final String name;
  • core/java/src/net/i2p/crypto/EncType.java

    rcc4da1b r2487bca  
    77import java.util.Map;
    88
     9import static net.i2p.crypto.x25519.spec.X25519Spec.X25519_SPEC;
    910import net.i2p.data.Hash;
    1011import net.i2p.data.SimpleDataStructure;
     
    3738
    3839    /**  Pubkey 132 bytes; privkey 66 bytes; */
    39     EC_P521(3, 132, 66, EncAlgo.EC, "EC/None/NoPadding", ECConstants.P521_SPEC, "0.9.20");
     40    EC_P521(3, 132, 66, EncAlgo.EC, "EC/None/NoPadding", ECConstants.P521_SPEC, "0.9.20"),
     41
     42    /**
     43     *  Pubkey 32 bytes; privkey 32 bytes
     44     *  @since 0.9.38
     45     */
     46    ECIES_X25519(4, 32, 32, EncAlgo.ECIES, "EC/None/NoPadding", X25519_SPEC, "0.9.38");
    4047
    4148
  • core/java/src/net/i2p/crypto/KeyGenerator.java

    rcc4da1b r2487bca  
    3232import java.util.Collection;
    3333
     34import com.southernstorm.noise.crypto.x25519.Curve25519;
     35
    3436import net.i2p.I2PAppContext;
    3537import net.i2p.crypto.eddsa.EdDSAPrivateKey;
     
    174176    }
    175177
    176     /** Convert a PrivateKey to its corresponding PublicKey
     178    /**
     179     * Convert a PrivateKey to its corresponding PublicKey.
     180     * As of 0.9.38, supports EncTypes
     181     *
    177182     * @param priv PrivateKey object
    178183     * @return the corresponding PublicKey object
     
    180185     */
    181186    public static PublicKey getPublicKey(PrivateKey priv) {
    182         BigInteger a = new NativeBigInteger(1, priv.toByteArray());
    183         BigInteger aalpha = CryptoConstants.elgg.modPow(a, CryptoConstants.elgp);
    184         PublicKey pub = new PublicKey();
    185         try {
    186             pub.setData(SigUtil.rectify(aalpha, PublicKey.KEYSIZE_BYTES));
    187         } catch (InvalidKeyException ike) {
    188             throw new IllegalArgumentException(ike);
    189         }
     187        EncType type = priv.getType();
     188        byte[] data;
     189        switch (type) {
     190          case ELGAMAL_2048:
     191            BigInteger a = new NativeBigInteger(1, priv.toByteArray());
     192            BigInteger aalpha = CryptoConstants.elgg.modPow(a, CryptoConstants.elgp);
     193            try {
     194                data = SigUtil.rectify(aalpha, PublicKey.KEYSIZE_BYTES);
     195            } catch (InvalidKeyException ike) {
     196                throw new IllegalArgumentException(ike);
     197            }
     198            break;
     199
     200          case ECIES_X25519:
     201            data = new byte[32];
     202            Curve25519.eval(data, 0, priv.getData(), null);
     203            break;
     204
     205          default:
     206            throw new IllegalArgumentException("Unsupported algorithm");
     207
     208        }
     209        PublicKey pub = new PublicKey(type, data);
    190210        return pub;
    191211    }
  • core/java/src/net/i2p/data/PrivateKey.java

    rcc4da1b r2487bca  
    5454     */
    5555    public PrivateKey(EncType type, byte data[]) {
    56         super(data);
     56        super();
    5757        _type = type;
     58        if (data == null)
     59            throw new IllegalArgumentException("Data must be specified");
     60        _data = data;
    5861    }
    5962
Note: See TracChangeset for help on using the changeset viewer.