java.lang.Object
net.i2p.data.SimpleDataStructure
net.i2p.data.Signature
- All Implemented Interfaces:
DataStructure
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 Summary
Fields inherited from class SimpleDataStructure
_dataConstructor Summary
ConstructorsConstructorDescriptionCreates a new Signature with the default DSA-SHA1 type.Signature(byte[] data) Creates a new Signature from byte data with default type.Unknown type not allowed as we won't know the length to read in the data.Should we allow an unknown type here?Method Summary
All MethodsMethods inherited from class SimpleDataStructure
calculateHash, fromBase64, fromByteArray, getData, read, readBytes, setData, toBase64, toByteArray, writeBytesModifier and TypeMethodDescriptionSHA256 hash of the byte array, or null if data is null.voidfromBase64(String data) Data from the base64 string.voidfromByteArray(byte[] data) Does the same thing asSimpleDataStructure.setData(byte[])but null not allowed.byte[]getData()Data reference (not a copy).protected intread(InputStream in, byte[] target) Repeated reads until the buffer is full or IOException is thrown.voidreadBytes(InputStream in) Data read from the stream.voidsetData(byte[] data) The byte array data, or null.toBase64()Renders the structure into modified base 64 notation.byte[]Same thing as getData().voidwriteBytes(OutputStream out) Writes the data to the output stream.
Field Details
DEF_TYPE
Type assumed when a signature gives none.SIGNATURE_BYTES
public static final int SIGNATURE_BYTESDefault signature length in bytes._type
The algorithm this signature was made with.
Constructor Details
Signature
public Signature()Creates a new Signature with the default DSA-SHA1 type.Signature
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
Should we allow an unknown type here?- Parameters:
type- non-nulldata- the signature data
Method Details
length
public int length()Signature length in bytes, determined by the signature type.- Specified by:
lengthin classSimpleDataStructure- Returns:
- the legal length of the byte array
getType
toString
Signature as Base64 for debugging.- Overrides:
toStringin classSimpleDataStructure
hashCode
public int hashCode()Hash code combining the type and data.- Overrides:
hashCodein classSimpleDataStructure- Returns:
- the hash code
equals
Compares this signature with another object for equality.- Overrides:
equalsin classSimpleDataStructure- Parameters:
obj- the object to compare- Returns:
- true if the data arrays are equal