java.lang.Object
net.i2p.crypto.eddsa.EdDSAPublicKey
All Implemented Interfaces:
Serializable, AsymmetricKey, BinaryEncodablePREVIEW, Key, PublicKey, EdDSAKey

public class EdDSAPublicKeyextends Object implements EdDSAKey, PublicKey
An EdDSA public key.

For compatibility with older releases, decoding supports both RFC 8410 and an older draft specification.

See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      Pinned for serialized-form compatibility.
      See Also:
    • A

      private final GroupElement A
      The public key point.
    • Aneg

      private volatile GroupElement Aneg
      The negated public key point, lazily initialized. Volatile for safe publication across verify threads.
    • Abyte

      private final byte[] Abyte
      The encoded public key (Abyte).
    • edDsaSpec

      private final EdDSAParameterSpec edDsaSpec
      Ed dsa spec.
    • OID_OLD

      private static final int OID_OLD
      First object identifier in the 1.3.101.xxx range.
      See Also:
    • OID_ED25519

      private static final int OID_ED25519
      Object identifier for Ed25519.
      See Also:
    • OID_BYTE

      private static final int OID_BYTE
      Offset of the object identifier in the encoded key.
      See Also:
    • IDLEN_BYTE

      private static final int IDLEN_BYTE
      Offset of the identifier length in the encoded key.
      See Also:
  • Constructor Details

  • Method Details

    • getAlgorithm

      public String getAlgorithm()
      The reported algorithm name for all EdDSA keys.
      Specified by:
      getAlgorithm in interface Key
      Returns:
      the JCA algorithm name shared by all EdDSA keys, "EdDSA"
    • getFormat

      public String getFormat()
      The encoding format of the key.
      Specified by:
      getFormat in interface Key
      Returns:
      the JCA key encoding format, always "X.509"
    • getEncoded

      public byte[] getEncoded()
      Returns the public key in its canonical encoding.

      This implements the following specs:

      For keys in older formats, decoding and then re-encoding is sufficient to migrate them to the canonical encoding.

      Relevant spec quotes:

           In the X.509 certificate, the subjectPublicKeyInfo field has the
           SubjectPublicKeyInfo type, which has the following ASN.1 syntax:
      
           SubjectPublicKeyInfo  ::=  SEQUENCE  {
             algorithm         AlgorithmIdentifier,
             subjectPublicKey  BIT STRING
           }
      
           AlgorithmIdentifier  ::=  SEQUENCE  {
             algorithm   OBJECT IDENTIFIER,
             parameters  ANY DEFINED BY algorithm OPTIONAL
           }
      
           For all of the OIDs, the parameters MUST be absent.
      
           id-Ed25519   OBJECT IDENTIFIER ::= { 1 3 101 112 }
      
      Specified by:
      getEncoded in interface Key
      Returns:
      44 bytes for Ed25519, null for other curves
    • decode

      private static byte[] decode(byte[] d) throws InvalidKeySpecException
      Extracts the public key bytes from the provided encoding.

      This will decode data conforming to RFC 8410 or the older draft spec at https://tools.ietf.org/html/draft-josefsson-pkix-eddsa-04.

      Per RFC 8410 section 3, this function WILL accept a parameter value of NULL, as it is required for interoperability with the default Java keystore. Other implementations MUST NOT copy this behaviour from here unless they also need to read keys from the default Java keystore.

      This is really dumb for now. It does not use a general-purpose ASN.1 decoder. See also getEncoded().

      Parameters:
      d - the encoded key bytes from the keystore
      Returns:
      32 bytes for Ed25519, throws for other curves
      Throws:
      InvalidKeySpecException - if the encoding is not a supported EdDSA key spec
    • getParams

      public EdDSAParameterSpec getParams()
      The EdDSA domain parameters for the key.
      Specified by:
      getParams in interface AsymmetricKey
      Specified by:
      getParams in interface EdDSAKey
      Returns:
      the EdDSAParameterSpec naming the curve and hash algorithm
    • getA

      public GroupElement getA()
      The public key point A.
      Returns:
      A as a group element on the curve
    • getNegativeA

      public GroupElement getNegativeA()
      The negated public key point.
      Returns:
      -A, computed on first use and cached
    • getAbyte

      public byte[] getAbyte()
      The encoded public key.
      Returns:
      The public key bytes.
    • hashCode

      public int hashCode()
      Hash code of the public key bytes, for use in hash tables.
      Overrides:
      hashCode in class Object
      Returns:
      whether h code is present
    • equals

      public boolean equals(Object o)
      Whether this key is equal to the given key.
      Overrides:
      equals in class Object
      Returns:
      true if equal