public I2PTunnelHTTPClientBase(int localPort, boolean ownDest, Logging l, EventDispatcher notifyThis, String handlerName, I2PTunnel tunnel) throws IllegalArgumentException { super(localPort, ownDest, l, notifyThis, handlerName, tunnel); _proxyList = new ArrayList<String>(4); _proxyNonce = new byte[PROXYNONCE_BYTES]; _context.random().nextBytes(_proxyNonce); _nonces = new ConcurrentHashMap<String, NonceInfo>(); }
public void saveSeed() { byte buf[] = new byte[1024]; nextBytes(buf); writeSeed(buf); }
public int writeData(byte[] tgt, int off) { if (ctx != null) ctx.random().nextBytes(tgt, off, sz); else Arrays.fill(tgt, off, off + sz, (byte) 0); return off + sz; } }
private static Hash generateRandomKey() { byte hash[] = new byte[Hash.HASH_LENGTH]; RandomSource.getInstance().nextBytes(hash); return new Hash(hash); }
/** * @param create if true, instantiate the data array and fill it with random data. */ public SessionTag(boolean create) { super(); if (create) { _data = SimpleByteCache.acquire(BYTE_LENGTH); RandomSource.getInstance().nextBytes(_data); _cachedHashCode = SipHash.hashCode(_data); } }
/** 48 char b32 string (30 bytes of entropy) */ public static String randomString() { I2PAppContext ctx = I2PAppContext.getGlobalContext(); // make a random 48 character password (30 * 8 / 5) byte[] rand = new byte[30]; ctx.random().nextBytes(rand); return Base32.encode(rand); }
/** Generate a private 256 bit session key * @return session key */ public SessionKey generateSessionKey() { // 256bit random # as a session key SessionKey key = new SessionKey(); byte data[] = new byte[SessionKey.KEYSIZE_BYTES]; _context.random().nextBytes(data); key.setData(data); return key; }
public UDPFlooder(RouterContext ctx, UDPTransport transport) { _context = ctx; // _log = ctx.logManager().getLog(UDPFlooder.class); _transport = transport; _peers = new ArrayList<PeerState>(4); ctx.random().nextBytes(_floodData); }
/** outgoing - generate a random ID */ public MsgID(I2PAppContext ctx) { super(null); byte[] data = new byte[MY_TOK_LEN]; ctx.random().nextBytes(data); setData(data); setValid(MY_TOK_LEN); }
/** outgoing - generate a random token */ public Token(I2PAppContext ctx) { super(null); byte[] data = new byte[MY_TOK_LEN]; ctx.random().nextBytes(data); setData(data); setValid(MY_TOK_LEN); lastSeen = ctx.clock().now(); }
/** @since 0.9.10 */ public void testClosest() { byte val[] = new byte[Hash.HASH_LENGTH]; for (int i = 0; i < 23; i++) { context.random().nextBytes(val); Hash h = new Hash(val); List<Hash> c = set.getClosest(h, i); assertTrue(c.size() == i); } } }
public DataStructure createDataStructure() throws DataFormatException { byte h[] = new byte[Hash.HASH_LENGTH]; RandomSource.getInstance().nextBytes(h); Hash hash = new Hash(h); DestLookupMessage msg = new DestLookupMessage(hash); return msg; } public DataStructure createStructureToRead() { return new DestLookupMessage(); }
public void testMultiple(){ int size = 1; for(int i = 0; i < 16; i++){ byte[] message = new byte[size]; size*=2; _context.random().nextBytes(message); SHA256Generator.getInstance().calculateHash(message); } }
private void addRandom(int count) { for (int i = 0; i < count; i++) { byte val[] = new byte[Hash.HASH_LENGTH]; context.random().nextBytes(val); Hash h = new Hash(val); // in the highly unlikely chance we randomly generate a hash equal to us assertTrue(set.add(h) || h.equals(usHash)); } }
public void testMultiple(){ int size = 1; for(int i = 0; i < 16; i++){ SessionKey key = _context.keyGenerator().generateSessionKey(); byte[] message = new byte[size]; size*=2; _context.random().nextBytes(message); byte[] output = new byte[32]; _context.hmac().calculate(key, message, 0, message.length, output, 0); } } }
public static void testED2() { I2PAppContext ctx = I2PAppContext.getGlobalContext(); SessionKey key = ctx.keyGenerator().generateSessionKey(); byte iv[] = new byte[16]; byte orig[] = new byte[128]; byte data[] = new byte[128]; ctx.random().nextBytes(iv); ctx.random().nextBytes(orig); CryptixAESEngine aes = new CryptixAESEngine(ctx); aes.encrypt(orig, 0, data, 0, key, iv, data.length); aes.decrypt(data, 0, data, 0, key, iv, data.length); assertTrue(DataHelper.eq(data,orig)); }
public void testED() { I2PAppContext ctx = I2PAppContext.getGlobalContext(); SessionKey key = ctx.keyGenerator().generateSessionKey(); byte iv[] = new byte[16]; byte orig[] = new byte[128]; byte encrypted[] = new byte[128]; byte decrypted[] = new byte[128]; ctx.random().nextBytes(iv); ctx.random().nextBytes(orig); CryptixAESEngine aes = new CryptixAESEngine(ctx); aes.encrypt(orig, 0, encrypted, 0, key, iv, orig.length); aes.decrypt(encrypted, 0, decrypted, 0, key, iv, encrypted.length); assertTrue(DataHelper.eq(decrypted,orig)); }
@SuppressWarnings("deprecation") public void testLong(){ I2PAppContext ctx = new I2PAppContext(); SessionKey key = ctx.keyGenerator().generateSessionKey(); byte iv[] = new byte[16]; RandomSource.getInstance().nextBytes(iv); byte lbuf[] = new byte[1024]; RandomSource.getInstance().nextBytes(lbuf); byte le[] = ctx.aes().safeEncrypt(lbuf, key, iv, 2048); byte ld[] = ctx.aes().safeDecrypt(le, key, iv); assertTrue(DataHelper.eq(ld, lbuf)); }
public void setUp(){ context = I2PAppContext.getGlobalContext(); log = context.logManager().getLog(KBucketSet.class); byte[] us = new byte[Hash.HASH_LENGTH]; context.random().nextBytes(us); usHash = new Hash(us); // We use the default RandomTrimmer so add() will never fail set = new KBucketSet<Hash>(context, usHash, K, B); // tests may be run in any order so prime it addRandom(1000); }
public void testMultiple(){ Object[] keys = KeyGenerator.getInstance().generatePKIKeypair(); byte[] message = new byte[222]; for (int x = 0; x < 25; x++) { _context.random().nextBytes(message); keys = KeyGenerator.getInstance().generatePKIKeypair(); PublicKey pubkey = (PublicKey)keys[0]; PrivateKey privkey = (PrivateKey)keys[1]; byte[] e = _context.elGamalEngine().encrypt(message, pubkey); byte[] d = _context.elGamalEngine().decrypt(e, privkey); assertTrue(DataHelper.eq(d, message)); } }