net.i2p.router.transport.udp

## Class SSU2Header

- java.lang.Object
- - net.i2p.router.transport.udp.SSU2Header

-     final class SSU2Header
      extends Object

  Encrypt/decrypt headers

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `SSU2Header.Header` A temporary structure returned from trial decrypt, with methods to access the fields.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static byte[]` | `CHACHA_IV_0` 12 bytes of zeros
    `static byte[]` | `HEADER_PROT_DATA` 8 bytes of zeros

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `acceptTrialDecrypt(UDPPacket packet, SSU2Header.Header header)` Copy the header back to the packet.
    `static long` | `decryptDestConnID(DatagramPacket pkt, byte[] key1)` Decrypt bytes 0-7 in header.
    `static void` | `encryptHandshakeHeader(UDPPacket packet, byte[] key1, byte[] key2)` First 64 bytes
    `static void` | `encryptLongHeader(UDPPacket packet, byte[] key1, byte[] key2)` First 32 bytes
    `static void` | `encryptShortHeader(UDPPacket packet, byte[] key1, byte[] key2)` First 16 bytes.
    `static SSU2Header.Header` | `trialDecryptHandshakeHeader(UDPPacket packet, byte[] key1, byte[] key2)` Session Request and Session Created only.
    `static SSU2Header.Header` | `trialDecryptLongHeader(UDPPacket packet, byte[] key1, byte[] key2)` Retry, Token Request, Peer Test only.
    `static SSU2Header.Header` | `trialDecryptShortHeader(UDPPacket packet, byte[] key1, byte[] key2)` Session Confirmed and data phase.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### CHACHA_IV_0

          public static final byte[] CHACHA_IV_0

      12 bytes of zeros

    - #### HEADER_PROT_DATA

          public static final byte[] HEADER_PROT_DATA

      8 bytes of zeros

  - ### Method Detail

    - #### acceptTrialDecrypt

          public static void acceptTrialDecrypt(UDPPacket packet,
                                                SSU2Header.Header header)

      Copy the header back to the packet. Cannot be undone.

    - #### decryptDestConnID

          public static long decryptDestConnID(DatagramPacket pkt,
                                               byte[] key1)

      Decrypt bytes 0-7 in header. Packet is unmodified.
      Parameters:
        `pkt` - must be 8 bytes min
      Returns:
        the destination connection ID
      Throws:
        `IndexOutOfBoundsException` - if too short

    - #### encryptHandshakeHeader

          public static void encryptHandshakeHeader(UDPPacket packet,
                                                    byte[] key1,
                                                    byte[] key2)

      First 64 bytes

    - #### encryptLongHeader

          public static void encryptLongHeader(UDPPacket packet,
                                               byte[] key1,
                                               byte[] key2)

      First 32 bytes

    - #### encryptShortHeader

          public static void encryptShortHeader(UDPPacket packet,
                                                byte[] key1,
                                                byte[] key2)

      First 16 bytes. First 8 bytes uses key1 and the next-to-last 12 bytes as the IV. Next 8 bytes uses key2 and the last 12 bytes as the IV.

    - #### trialDecryptHandshakeHeader

          public static SSU2Header.Header trialDecryptHandshakeHeader(UDPPacket packet,
                                                                      byte[] key1,
                                                                      byte[] key2)

      Session Request and Session Created only. 64 bytes. Packet is unmodified.
      Parameters:
        `packet` - must be 88 bytes min
      Returns:
        64 byte header, null if data too short

    - #### trialDecryptLongHeader

          public static SSU2Header.Header trialDecryptLongHeader(UDPPacket packet,
                                                                 byte[] key1,
                                                                 byte[] key2)

      Retry, Token Request, Peer Test only. 32 bytes. Packet is unmodified.
      Parameters:
        `packet` - must be 56 bytes min
      Returns:
        32 byte header, null if data too short

    - #### trialDecryptShortHeader

          public static SSU2Header.Header trialDecryptShortHeader(UDPPacket packet,
                                                                  byte[] key1,
                                                                  byte[] key2)

      Session Confirmed and data phase. 16 bytes. Packet is unmodified.
      Parameters:
        `packet` - must be 40 bytes min
      Returns:
        16 byte header, null if data too short, must be 40 bytes min