- All Implemented Interfaces:
Serializable, Comparable<SigType>, java.lang.constant.Constable
Defines the properties for various signature types that I2P supports or may someday support.
All Signatures, SigningPublicKeys, and SigningPrivateKeys have a type. Note that a SigType specifies both an algorithm and parameters, so that we may change primes or curves for a given algorithm.
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E>Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionDSA_SHA1 is the default.Pubkey 64 bytes; privkey 32 bytes; hash 32 bytes; sig 64 bytes.Pubkey 96 bytes; privkey 48 bytes; hash 48 bytes; sig 96 bytes.Pubkey 132 bytes; privkey 66 bytes; hash 64 bytes; sig 132 bytes.Pubkey 32 bytes; privkey 32 bytes; hash 64 bytes; sig 64 bytesPrehash version (double hashing, for offline use such as su3, not for use on the network) Pubkey 32 bytes; privkey 32 bytes; hash 64 bytes; sig 64 bytes.Blinded version of EdDSA, use for encrypted LS2 Pubkey 32 bytes; privkey 32 bytes; hash 64 bytes; sig 64 bytes.Pubkey 256 bytes; privkey 512 bytes; hash 32 bytes; sig 256 bytes.Pubkey 384 bytes; privkey 768 bytes; hash 48 bytes; sig 384 bytes.Pubkey 512 bytes; privkey 1024 bytes; hash 64 bytes; sig 512 bytes.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final StringName of the signature algorithm for display.private final SigAlgoThe underlying algorithm family.private static final SigType[]The types indexed by their code.private final intThe two byte signature type code.private final StringName of the digest algorithm used.private MessageDigestPristine digest fordigestName, created once and cloned per call.private final intLength of the hash signed, in bytes.private final booleanTrue if the implementation is available.private final StringThe object identifier of the algorithm, if any.private final AlgorithmParameterSpecParameters of the algorithm, if any.private final intLength of the private key, in bytes.private final intLength of the public key, in bytes.private final intLength of the signature, in bytes.private final StringVersion that introduced this type.Constructor Summary
Method Summary
Modifier and TypeMethodDescriptionprivate static MessageDigestcreateDigestInstance(String name) Provider lookup for a digest by name.The standard name used for the Java crypto factories.The standard base algorithm name used for the Java crypto factories.static SigTypegetByCode(int code) Signature type by code.intgetCode()The unique identifier for this type.A private, unshared MessageDigest instance for this signature type, in its initial state.private MessageDigestThe pristine digest prototype for this type, created on first use.Create a Hash instance for this signature type.intThe length of the hash, in bytes.getOID()The object identifier assigned to the signature algorithm.The elliptic curve ECParameterSpec for ECDSA; DSAParameterSpec for DSA.intThe length of the private key, in bytes.intThe length of the public key, in bytes.intThe length of the signature, in bytes.The router version in which this type was first supported.booleanChecks if this signature type is available in the JVM.static booleanisAvailable(int code) Checks if the signature type with the given code is available.static booleanisAvailable(String stype) Checks if the signature type with the given name or number is available.static SigTypeparseSigType(String stype) Convenience for user apps.static SigTypeReturns the enum constant of this class with the specified name.static SigType[]values()Returns an array containing the constants of this enum class, in the order they are declared.private booleanChecks whether the implementation loads.
Enum Constant Details
DSA_SHA1
DSA_SHA1 is the default. Pubkey 128 bytes; privkey 20 bytes; hash 20 bytes; sig 40 bytes.ECDSA_SHA256_P256
Pubkey 64 bytes; privkey 32 bytes; hash 32 bytes; sig 64 bytes.ECDSA_SHA384_P384
Pubkey 96 bytes; privkey 48 bytes; hash 48 bytes; sig 96 bytes.ECDSA_SHA512_P521
Pubkey 132 bytes; privkey 66 bytes; hash 64 bytes; sig 132 bytes.RSA_SHA256_2048
Pubkey 256 bytes; privkey 512 bytes; hash 32 bytes; sig 256 bytes.RSA_SHA384_3072
Pubkey 384 bytes; privkey 768 bytes; hash 48 bytes; sig 384 bytes.RSA_SHA512_4096
Pubkey 512 bytes; privkey 1024 bytes; hash 64 bytes; sig 512 bytes.EdDSA_SHA512_Ed25519
Pubkey 32 bytes; privkey 32 bytes; hash 64 bytes; sig 64 bytesDue to bugs in previous versions, minimum version is 0.9.17.
EdDSA_SHA512_Ed25519ph
Prehash version (double hashing, for offline use such as su3, not for use on the network) Pubkey 32 bytes; privkey 32 bytes; hash 64 bytes; sig 64 bytes.RedDSA_SHA512_Ed25519
Blinded version of EdDSA, use for encrypted LS2 Pubkey 32 bytes; privkey 32 bytes; hash 64 bytes; sig 64 bytes.
Field Details
code
private final int codeThe two byte signature type code.pubkeyLen
private final int pubkeyLenLength of the public key, in bytes.privkeyLen
private final int privkeyLenLength of the private key, in bytes.hashLen
private final int hashLenLength of the hash signed, in bytes.sigLen
private final int sigLenLength of the signature, in bytes.base
The underlying algorithm family.digestName
Name of the digest algorithm used.algoName
Name of the signature algorithm for display.oid
The object identifier of the algorithm, if any.since
Version that introduced this type.params
Parameters of the algorithm, if any.isAvail
private final boolean isAvailTrue if the implementation is available.digestProto
Pristine digest fordigestName, created once and cloned per call. Never handed out and never fed data, so any clone of it is a fully independent digest in its initial state. Lazily created bygetDigestPrototype()so that an unavailable algorithm still leaves the enum constant constructible.BY_CODE
The types indexed by their code.
Constructor Details
SigType
private SigType(int cod, int pubLen, int privLen, int hLen, int sLen, SigAlgo baseAlgo, String mdName, String aName, AlgorithmParameterSpec pSpec, String oid, String supportedSince) Creates a signature type with its parameters.- Parameters:
cod- the two byte signature type codepubLen- length of the public key, in bytesprivLen- length of the private key, in byteshLen- length of the hash signed, in bytessLen- length of the signature, in bytesbaseAlgo- the underlying algorithm familymdName- name of the digest algorithm usedaName- name of the signature algorithm for displaypSpec- parameters of the algorithm, null if noneoid- the object identifier of the algorithm, null if nonesupportedSince- version that introduced this type
Method Details
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
getCode
public int getCode()The unique identifier for this type.- Returns:
- the code carried in the RouterIdentity
getPubkeyLen
public int getPubkeyLen()The length of the public key, in bytes.- Returns:
- the public key size
getPrivkeyLen
public int getPrivkeyLen()The length of the private key, in bytes.- Returns:
- the private key size
getHashLen
public int getHashLen()The length of the hash, in bytes.- Returns:
- the digest size
getSigLen
public int getSigLen()The length of the signature, in bytes.- Returns:
- the signature size
getBaseAlgorithm
The standard base algorithm name used for the Java crypto factories.- Returns:
- the key family, one of DSA, EC, RSA or EdDSA
getAlgorithmName
The standard name used for the Java crypto factories.- Returns:
- the JCA signature algorithm name, e.g. SHA256withECDSA
getParams
The elliptic curve ECParameterSpec for ECDSA; DSAParameterSpec for DSA.- Returns:
- the domain parameters this signature type was created with, an ECParameterSpec for ECDSA or a DSAParameterSpec for DSA
- Throws:
InvalidParameterSpecException- if the algorithm is not available on this JVM.
getDigestInstance
A private, unshared MessageDigest instance for this signature type, in its initial state.A MessageDigest is stateful and not thread safe, so the prototype is never returned directly; it is cloned on every call. Cloning skips the JCA provider lookup (algorithm string hashing plus provider list scanning) that
MessageDigest.getInstance(String)performs, and the clone shares no state with the prototype or with any other clone.- Returns:
- a new digest instance owned by the caller
- Throws:
UnsupportedOperationException- if not supported
getDigestPrototype
The pristine digest prototype for this type, created on first use.- Returns:
- the prototype, which callers must not use or modify
- Throws:
UnsupportedOperationException- if not supported
createDigestInstance
Provider lookup for a digest by name. Called at most once per SigType.- Parameters:
name- the JCA digest name- Returns:
- a new digest instance
- Throws:
UnsupportedOperationException- if not supported
getHashInstance
Create a Hash instance for this signature type.- Returns:
- the hash instance
- Throws:
UnsupportedOperationException- if not supported
getSupportedSince
The router version in which this type was first supported.- Returns:
- the supported since
getOID
The object identifier assigned to the signature algorithm.- Returns:
- the dotted decimal OID, null if none is assigned
isAvailable
public boolean isAvailable()Checks if this signature type is available in the JVM.- Returns:
- true if supported in this JVM
x_isAvailable
private boolean x_isAvailable()Checks whether the implementation loads.- Returns:
- true if the signatures can be verified
isAvailable
public static boolean isAvailable(int code) Checks if the signature type with the given code is available.- Parameters:
code- the signature type code to look up- Returns:
- true if supported in this JVM
isAvailable
Checks if the signature type with the given name or number is available.- Parameters:
stype- number or name- Returns:
- true if supported in this JVM
getByCode
Signature type by code.- Parameters:
code- the signature type code to look up- Returns:
- Null if not supported.
parseSigType