Changeset 2487bca
- Timestamp:
- Nov 30, 2018 3:15:31 PM (2 years ago)
- Branches:
- master
- Children:
- f168918
- Parents:
- cc4da1b
- Files:
-
- 3 added
- 2 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
core/java/src/net/i2p/crypto/EncAlgo.java
rcc4da1b r2487bca 11 11 12 12 ELGAMAL("ElGamal"), 13 EC("EC"); 13 EC("EC"), 14 15 /** @since 0.9.38 */ 16 ECIES("ECIES"); 14 17 15 18 private final String name; -
core/java/src/net/i2p/crypto/EncType.java
rcc4da1b r2487bca 7 7 import java.util.Map; 8 8 9 import static net.i2p.crypto.x25519.spec.X25519Spec.X25519_SPEC; 9 10 import net.i2p.data.Hash; 10 11 import net.i2p.data.SimpleDataStructure; … … 37 38 38 39 /** 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"); 40 47 41 48 -
core/java/src/net/i2p/crypto/KeyGenerator.java
rcc4da1b r2487bca 32 32 import java.util.Collection; 33 33 34 import com.southernstorm.noise.crypto.x25519.Curve25519; 35 34 36 import net.i2p.I2PAppContext; 35 37 import net.i2p.crypto.eddsa.EdDSAPrivateKey; … … 174 176 } 175 177 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 * 177 182 * @param priv PrivateKey object 178 183 * @return the corresponding PublicKey object … … 180 185 */ 181 186 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); 190 210 return pub; 191 211 } -
core/java/src/net/i2p/data/PrivateKey.java
rcc4da1b r2487bca 54 54 */ 55 55 public PrivateKey(EncType type, byte data[]) { 56 super( data);56 super(); 57 57 _type = type; 58 if (data == null) 59 throw new IllegalArgumentException("Data must be specified"); 60 _data = data; 58 61 } 59 62 -
router/java/src/com/southernstorm/noise/protocol/Curve25519DHState.java
rcc4da1b r2487bca 23 23 package com.southernstorm.noise.protocol; 24 24 25 import java.security.KeyPair;26 25 import java.util.Arrays; 27 26 28 27 import com.southernstorm.noise.crypto.x25519.Curve25519; 29 28 29 import net.i2p.crypto.KeyPair; 30 30 import net.i2p.router.transport.crypto.X25519KeyFactory; 31 31 … … 79 79 public void generateKeyPair() { 80 80 KeyPair kp = _xdh.getKeys(); 81 System.arraycopy(kp.getPrivate().get Encoded(), 0, privateKey, 0, 32);82 System.arraycopy(kp.getPublic().get Encoded(), 0, publicKey, 0, 32);81 System.arraycopy(kp.getPrivate().getData(), 0, privateKey, 0, 32); 82 System.arraycopy(kp.getPublic().getData(), 0, publicKey, 0, 32); 83 83 mode = 0x03; 84 84 } -
router/java/src/net/i2p/router/transport/crypto/X25519KeyFactory.java
rcc4da1b r2487bca 1 1 package net.i2p.router.transport.crypto; 2 2 3 import java.security.KeyPair;4 3 import java.util.concurrent.LinkedBlockingQueue; 5 4 … … 7 6 8 7 import net.i2p.I2PAppContext; 8 import net.i2p.crypto.EncType; 9 import net.i2p.crypto.KeyPair; 10 import net.i2p.data.PrivateKey; 11 import net.i2p.data.PublicKey; 9 12 import net.i2p.util.I2PThread; 10 13 import net.i2p.util.Log; … … 134 137 byte[] pub = new byte[32]; 135 138 Curve25519.eval(pub, 0, priv, null); 136 KeyPair rv = new KeyPair(new X25519PublicKey(pub), new X25519PrivateKey(priv));139 KeyPair rv = new KeyPair(new PublicKey(EncType.ECIES_X25519, pub), new PrivateKey(EncType.ECIES_X25519, priv)); 137 140 long end = System.currentTimeMillis(); 138 141 long diff = end - start; -
router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java
rcc4da1b r2487bca 9 9 import java.nio.channels.ServerSocketChannel; 10 10 import java.nio.channels.SocketChannel; 11 import java.security.KeyPair;12 11 import java.text.DecimalFormat; 13 12 import java.text.NumberFormat; … … 28 27 import java.util.concurrent.ConcurrentHashMap; 29 28 29 import net.i2p.crypto.EncType; 30 import net.i2p.crypto.KeyPair; 30 31 import net.i2p.crypto.SigType; 31 32 import net.i2p.data.Base64; … … 33 34 import net.i2p.data.DataHelper; 34 35 import net.i2p.data.Hash; 36 import net.i2p.data.PublicKey; 37 import net.i2p.data.PrivateKey; 35 38 import net.i2p.data.router.RouterAddress; 36 39 import net.i2p.data.router.RouterIdentity; … … 49 52 import net.i2p.router.transport.crypto.DHSessionKeyBuilder; 50 53 import net.i2p.router.transport.crypto.X25519KeyFactory; 51 import net.i2p.router.transport.crypto.X25519PublicKey;52 import net.i2p.router.transport.crypto.X25519PrivateKey;53 54 import net.i2p.router.util.DecayingHashSet; 54 55 import net.i2p.router.util.DecayingBloomFilter; … … 258 259 if (priv == null || priv.length != NTCP2_KEY_LEN) { 259 260 KeyPair keys = xdh.getKeys(); 260 _ntcp2StaticPrivkey = keys.getPrivate().get Encoded();261 _ntcp2StaticPubkey = keys.getPublic().get Encoded();261 _ntcp2StaticPrivkey = keys.getPrivate().getData(); 262 _ntcp2StaticPubkey = keys.getPublic().getData(); 262 263 shouldSave = true; 263 264 } else { 264 265 _ntcp2StaticPrivkey = priv; 265 _ntcp2StaticPubkey = (new X25519PrivateKey(priv)).toPublic().getEncoded();266 _ntcp2StaticPubkey = (new PrivateKey(EncType.ECIES_X25519, priv)).toPublic().getData(); 266 267 } 267 268 if (!shouldSave) {
Note: See TracChangeset
for help on using the changeset viewer.