All Implemented Interfaces:
DataStructure

public class Signatureextends SimpleDataStructure
Cryptographic signature implementation for I2P data structures and identity verification.

Signature provides digital signature capabilities with support for multiple algorithms:

  • Default Algorithm: DSA-SHA1 (40 bytes: 20-byte R + 20-byte S)
  • Modern Algorithms: ECDSA-P256, EdDSA-Ed25519 with variable lengths
  • Algorithm Support: Extensible design for future signature types
  • Verification: Used throughout I2P for identity and data integrity

Signature Structure:

  • DSA-SHA1: 40 bytes total (R: 20 bytes, S: 20 bytes)
  • ECDSA-P256: Variable length (typically 64-72 bytes)
  • EdDSA-Ed25519: 64 bytes (fixed length)
  • Type Information: Embedded in signature data for verification

Supported Algorithms:

  • DSA-SHA1: Legacy algorithm, 1024-bit keys
  • ECDSA-P256: Modern algorithm, 256-bit elliptic curve
  • EdDSA-Ed25519: Modern algorithm, 25519 elliptic curve
  • RSA: Supported but discouraged due to performance issues

Usage:

  • Identity Verification: Proves ownership of Destination
  • Data Integrity: Ensures data hasn't been tampered with
  • NetDb Entries: Signs RouterInfo and LeaseSet structures
  • Messages: Authenticates I2NP messages and I2CP communications

Security Considerations:

  • Algorithm Selection: Prefer modern algorithms (Ed25519, ECDSA-P256)
  • Key Management: Protect private signing keys
  • Verification: Always verify signatures before trusting data
  • Performance: RSA signatures are slow and may be used for DoS

Evolution:

  • Pre-0.9.8: Only DSA-SHA1 supported (40 bytes fixed)
  • Post-0.9.8: Arbitrary length and type support via SigType
  • Current: Multiple algorithms with automatic type detection
  • Field Details

    • DEF_TYPE

      private static final SigType DEF_TYPE
      Type assumed when a signature gives none.
    • SIGNATURE_BYTES

      public static final int SIGNATURE_BYTES
      Default signature length in bytes.
    • _type

      private final SigType _type
      The algorithm this signature was made with.
  • Constructor Details

    • Signature

      public Signature()
      Creates a new Signature with the default DSA-SHA1 type.
    • Signature

      public Signature(SigType type)
      Unknown type not allowed as we won't know the length to read in the data.
      Parameters:
      type - non-null
    • Signature

      public Signature(byte[] data)
      Creates a new Signature from byte data with default type.
      Parameters:
      data - the signature bytes, in the encoded form used by the default signature type
    • Signature

      public Signature(SigType type, byte[] data)
      Should we allow an unknown type here?
      Parameters:
      type - non-null
      data - the signature data
  • Method Details

    • length

      public int length()
      Signature length in bytes, determined by the signature type.
      Specified by:
      length in class SimpleDataStructure
      Returns:
      the legal length of the byte array
    • getType

      public SigType getType()
      Gets the signature type.
      Returns:
      non-null
    • toString

      public String toString()
      Signature as Base64 for debugging.
      Overrides:
      toString in class SimpleDataStructure
    • hashCode

      public int hashCode()
      Hash code combining the type and data.
      Overrides:
      hashCode in class SimpleDataStructure
      Returns:
      the hash code
    • equals

      public boolean equals(Object obj)
      Compares this signature with another object for equality.
      Overrides:
      equals in class SimpleDataStructure
      Parameters:
      obj - the object to compare
      Returns:
      true if the data arrays are equal