Class SSU2Header

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

final class SSU2Header extends Object
Encrypt/decrypt headers
Since:
0.9.54
  • Field Details

    • HEADER_PROT_DATA

      public static final byte[] HEADER_PROT_DATA
      8 bytes of zeros
    • CHACHA_IV_0

      public static final byte[] CHACHA_IV_0
      12 bytes of zeros
  • Method Details

    • 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
    • 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
    • acceptTrialDecrypt

      public static void acceptTrialDecrypt(UDPPacket packet, SSU2Header.Header header)
      Copy the header back to the packet. Cannot be undone.
    • 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.