/** * Generates the explicit part of the nonce to be used with the AEAD Cipher. * * <a href="http://tools.ietf.org/html/rfc6655#section-3">RFC6655, Section 3</a> * encourages the use of the session's 16bit epoch value concatenated * with a monotonically increasing 48bit sequence number as the explicit nonce. * * @return the 64-bit explicit nonce constructed from the epoch and sequence number */ private byte[] generateExplicitNonce() { //TODO: re-factor to use simple byte array manipulation instead of using bit-based DatagramWriter DatagramWriter writer = new DatagramWriter(); writer.write(epoch, EPOCH_BITS); writer.writeLong(sequenceNumber, SEQUENCE_NUMBER_BITS); return writer.toByteArray(); }
/** * Encodes this record into its corresponding <em>DTLSCiphertext</em> structure. * * @return a byte array containing the <em>DTLSCiphertext</em> structure */ public synchronized byte[] toByteArray() { DatagramWriter writer = new DatagramWriter(); writer.write(type.getCode(), CONTENT_TYPE_BITS); writer.write(version.getMajor(), VERSION_BITS); writer.write(version.getMinor(), VERSION_BITS); writer.write(epoch, EPOCH_BITS); writer.writeLong(sequenceNumber, SEQUENCE_NUMBER_BITS); length = fragmentBytes.length; writer.write(length, LENGTH_BITS); writer.writeBytes(fragmentBytes); return writer.toByteArray(); }
/** * See <a href="http://tools.ietf.org/html/rfc5246#section-6.2.3.3">RFC * 5246</a>: * * <pre> * additional_data = seq_num + TLSCompressed.type + * TLSCompressed.version + TLSCompressed.length; * </pre> * * where "+" denotes concatenation. * * @return the additional authentication data. */ private byte[] generateAdditionalData(int length) { DatagramWriter writer = new DatagramWriter(); writer.write(epoch, EPOCH_BITS); writer.writeLong(sequenceNumber, SEQUENCE_NUMBER_BITS); writer.write(type.getCode(), CONTENT_TYPE_BITS); writer.write(version.getMajor(), VERSION_BITS); writer.write(version.getMinor(), VERSION_BITS); writer.write(length, LENGTH_BITS); return writer.toByteArray(); }
writer.writeLong(timestamp, 32);