Package ch.ethz.inf.vs.scandium.util

Examples of ch.ethz.inf.vs.scandium.util.DatagramWriter


 
  // Serialization //////////////////////////////////////////////////

  @Override
  public byte[] fragmentToByteArray() {
    DatagramWriter writer = new DatagramWriter();

    // TODO only true, if the public value encoding is explicit (not in the
    // client's certificate), see
    // http://tools.ietf.org/html/rfc4492#section-5.7
    int length = pointEncoded.length;
    writer.write(length, LENGTH_BITS);
    writer.writeBytes(pointEncoded);

    return writer.toByteArray();
  }
View Full Code Here


   * DTLS v.1.2 specification.
   *
   * @return the encoded byte array
   */
  public 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();
  }
View Full Code Here

  private byte[] generateNonce(byte[] iv) {
    return getNonce(iv, generateExplicitNonce());
  }

  private byte[] getNonce(byte[] implicitNonce, byte[] explicitNonce) {
    DatagramWriter writer = new DatagramWriter();
   
    writer.writeBytes(implicitNonce);
    writer.writeBytes(explicitNonce);
   
    return writer.toByteArray();
  }
View Full Code Here

   * @return the 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();
  }
View Full Code Here

   * 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();
  }
View Full Code Here

       * that encodes l(a) with a itself, and splitting the result into
       * 16-octet blocks, and then padding the last block with zeroes if
       * necessary.
       */

      DatagramWriter writer = new DatagramWriter();
      if (lengthA > 0 && lengthA < first) {
        // 2 bytes (0x0001 ... 0xFEFF)
        writer.writeLong(lengthA, 16);

      } else if (lengthA >= first && lengthA < second) {
        // 2 bytes (0xFFFE) + 4 octets of l(a)
        int field = 0xFFFE;
        writer.write(field, 16);
        writer.writeLong(lengthA, 32);

      } else {
        // 2 bytes (0xFFFF) + 8 octets of l(a)
        int field = 0xFFFF;
        writer.write(field, 16);
        writer.writeLong(lengthA, 64);
      }
      writer.writeBytes(a);

      byte[] aEncoded = writer.toByteArray();
      blocks.addAll(ByteArrayUtils.splitAndPad(aEncoded, BLOCK_SIZE));
    }
    /*
     * After the (optional) additional authentication blocks have been
     * added, we add the message blocks. The message blocks are formed by
View Full Code Here

     */
    int numRounds = (int) (Math.ceil(lengthM / (double) BLOCK_SIZE) + 1);

    // S_i := E( K, A_i ) for i=0, 1, 2, ...
    for (int i = 0; i < numRounds; i++) {
      DatagramWriter writer = new DatagramWriter();

      /*
       * Octet Number  Contents
       * ------------  ---------
       * 0      Flags
       * 1 ... 15-L  Nonce N
       * 16-L ... 15  Counter i
       */

      // Octet Number Contents
      // ------------ ---------
      // 0       Flags
      // 1 ... 15-L   Nonce N
      // 16-L ... 15   Counter i

      int flag = L - 1;

      // write the first byte: Flags
      writer.write(flag, 8);

      // the Nonce N
      writer.writeBytes(nonce);

      // writer the Counter i (L bytes)
      writer.writeLong(i, L * 8);
      byte[] S = writer.toByteArray();

      // S_i := E( K, A_i )
      S_i.add(ByteArrayUtils.truncate(cipher.doFinal(S), BLOCK_SIZE));
    }

View Full Code Here

TOP

Related Classes of ch.ethz.inf.vs.scandium.util.DatagramWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.