Changeset 922515df for core


Ignore:
Timestamp:
Nov 30, 2018 5:29:08 PM (18 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
79440f84
Parents:
f168918
Message:

Crypto: Add X25519 keygen support

File:
1 edited

Legend:

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

    rf168918 r922515df  
    1414import java.security.InvalidKeyException;
    1515import java.security.KeyFactory;
    16 import java.security.KeyPair;
    1716import java.security.KeyPairGenerator;
    1817import java.security.MessageDigest;
     
    177176
    178177    /**
     178     *  Supports EncTypes
     179     *  @since 0.9.38
     180     */
     181    public KeyPair generatePKIKeys(EncType type) {
     182        PublicKey pub;
     183        PrivateKey priv;
     184        switch (type) {
     185          case ELGAMAL_2048:
     186            SimpleDataStructure[] keys = generatePKIKeys();
     187            pub = (PublicKey) keys[0];
     188            priv = (PrivateKey) keys[1];
     189            break;
     190
     191          case ECIES_X25519:
     192            byte[] bpriv = new byte[32];
     193            do {
     194                _context.random().nextBytes(bpriv);
     195                // little endian, loop if too small
     196                // worth doing?
     197            } while (bpriv[31] == 0);
     198            byte[] bpub = new byte[32];
     199            Curve25519.eval(bpub, 0, bpriv, null);
     200            pub = new PublicKey(type, bpub);
     201            priv = new PrivateKey(type, bpriv);
     202            break;
     203
     204          default:
     205            throw new IllegalArgumentException("Unsupported algorithm");
     206
     207        }
     208        return new KeyPair(pub, priv);
     209    }
     210
     211    /**
    179212     * Convert a PrivateKey to its corresponding PublicKey.
    180213     * As of 0.9.38, supports EncTypes
     
    255288        if (type == SigType.DSA_SHA1)
    256289            return generateSigningKeys();
    257         KeyPair kp;
     290        java.security.KeyPair kp;
    258291        if (type.getBaseAlgorithm() == SigAlgo.EdDSA) {
    259292            net.i2p.crypto.eddsa.KeyPairGenerator kpg = new net.i2p.crypto.eddsa.KeyPairGenerator();
Note: See TracChangeset for help on using the changeset viewer.