public byte[] getExtra() { return getExtra(cryptoAlgorithm, compressionAlgorithm, controlDocument); }
public SplitFileSegmentKeys(int blocksPerSegment, int checkBlocksPerSegment, byte[] splitfileSingleCryptoKey, byte splitfileSingleCryptoAlgorithm) { this.dataBlocks = blocksPerSegment; this.checkBlocks = checkBlocksPerSegment; routingKeys = new byte[NodeCHK.KEY_LENGTH * (dataBlocks + checkBlocks)]; if(splitfileSingleCryptoKey != null) { commonDecryptKey = splitfileSingleCryptoKey; commonExtraBytes = ClientCHK.getExtra(splitfileSingleCryptoAlgorithm, (short)-1, false); decryptKeys = null; extraBytesForKeys = null; } else { commonDecryptKey = null; commonExtraBytes = null; decryptKeys = new byte[ClientCHK.CRYPTO_KEY_LENGTH * (dataBlocks + checkBlocks)]; extraBytesForKeys = new byte[EXTRA_BYTES_LENGTH * (dataBlocks + checkBlocks)]; } }
/** * Write an ultra-compact representation. * @throws IOException If a write failed. */ public void writeRawBinaryKey(DataOutputStream dos) throws IOException { dos.write(getExtra()); dos.write(routingKey); dos.write(cryptoKey); }
/** * @return URI form of this key. */ @Override public FreenetURI getURI() { byte[] extra = getExtra(); return new FreenetURI("CHK", null, routingKey, cryptoKey, extra); }
public static FreenetURI generateRandomCHK(Random rand) { byte[] rkey = new byte[32]; rand.nextBytes(rkey); byte[] ckey = new byte[32]; rand.nextBytes(ckey); byte[] extra = ClientCHK.getExtra(Key.ALGO_AES_CTR_256_SHA256, (short)-1, false); return new FreenetURI("CHK", null, rkey, ckey, extra); }
public void setKey(int i, ClientCHK key) { byte[] r = key.getRoutingKey(); System.arraycopy(r, 0, routingKeys, i * NodeCHK.KEY_LENGTH, NodeCHK.KEY_LENGTH); if(decryptKeys != null) { byte[] c = key.getCryptoKey(); System.arraycopy(c, 0, decryptKeys, i * ClientCHK.CRYPTO_KEY_LENGTH, ClientCHK.CRYPTO_KEY_LENGTH); } if(extraBytesForKeys != null) { byte[] e = key.getExtra(); System.arraycopy(e, 0, extraBytesForKeys, i * EXTRA_BYTES_LENGTH, EXTRA_BYTES_LENGTH); } }
public void readKeys(DataInputStream dis, boolean check) throws IOException { int count = check ? checkBlocks : dataBlocks; int offset = check ? dataBlocks : 0; if(commonDecryptKey != null) { int rkOffset = offset * NodeCHK.KEY_LENGTH; for(int i=0;i<count;i++) { dis.readFully(routingKeys, rkOffset, NodeCHK.KEY_LENGTH); rkOffset += NodeCHK.KEY_LENGTH; } } else { int rkOffset = offset * NodeCHK.KEY_LENGTH; int extraOffset = offset * EXTRA_BYTES_LENGTH; assert(NodeCHK.KEY_LENGTH == ClientCHK.CRYPTO_KEY_LENGTH); for(int i=0;i<count;i++) { ClientCHK key = ClientCHK.readRawBinaryKey(dis); byte[] r = key.getRoutingKey(); System.arraycopy(r, 0, routingKeys, rkOffset, NodeCHK.KEY_LENGTH); byte[] c = key.getCryptoKey(); System.arraycopy(c, 0, decryptKeys, rkOffset, NodeCHK.KEY_LENGTH); rkOffset += NodeCHK.KEY_LENGTH; byte[] e = key.getExtra(); System.arraycopy(e, 0, extraBytesForKeys, extraOffset, EXTRA_BYTES_LENGTH); extraOffset += EXTRA_BYTES_LENGTH; } } }
continue; if(extra == null) extra = key.getExtra(); if(commonExtraBytes != null) { if(!Arrays.equals(commonExtraBytes, extra)) continue;