Interface DHState

    • Method Summary

      All Methods Instance Methods Abstract Methods Deprecated Methods 
      Modifier and Type Method Description
      void calculate​(byte[] sharedKey, int offset, DHState publicDH)
      Performs a Diffie-Hellman calculation with this object as the private key.
      void clearKey()
      Clears the key pair.
      DHState clone()
      I2P
      void copyFrom​(DHState other)
      Copies the key values from another DH object of the same type.
      void generateKeyPair()
      Generates a new random keypair.
      String getDHName()
      Gets the Noise protocol name for this Diffie-Hellman algorithm.
      void getEncodedPublicKey​(byte[] key, int offset)
      Gets the public key associated with this object.
      void getPrivateKey​(byte[] key, int offset)
      Gets the private key associated with this object.
      int getPrivateKeyLength()
      Gets the length of private keys for this algorithm.
      void getPublicKey​(byte[] key, int offset)
      Gets the public key associated with this object.
      int getPublicKeyLength()
      Gets the length of public keys for this algorithm.
      int getSharedKeyLength()
      Gets the length of shared keys for this algorithm.
      boolean hasEncodedPublicKey()
      Determine if this object contains an optional encoded public key.
      boolean hasPrivateKey()
      Determine if this object contains a private key.
      boolean hasPublicKey()
      Determine if this object contains a public key.
      boolean isNullPublicKey()
      Determine if the public key in this object is the special null value.
      void setKeys​(byte[] privkey, int privoffset, byte[] pubkey, int puboffset)
      Sets the private and public keys for this object.
      void setPrivateKey​(byte[] key, int offset)
      Deprecated.
      use setKeys()
      void setPublicKey​(byte[] key, int offset)
      Sets the public key for this object.
      void setToNullPublicKey()
      Sets this object to the null public key and clears the private key.
    • Method Detail

      • getDHName

        String getDHName()
        Gets the Noise protocol name for this Diffie-Hellman algorithm.
        Returns:
        The algorithm name.
      • getPublicKeyLength

        int getPublicKeyLength()
        Gets the length of public keys for this algorithm.
        Returns:
        The length of public keys in bytes.
      • getPrivateKeyLength

        int getPrivateKeyLength()
        Gets the length of private keys for this algorithm.
        Returns:
        The length of private keys in bytes.
      • getSharedKeyLength

        int getSharedKeyLength()
        Gets the length of shared keys for this algorithm.
        Returns:
        The length of shared keys in bytes.
      • generateKeyPair

        void generateKeyPair()
        Generates a new random keypair.
      • getPublicKey

        void getPublicKey​(byte[] key,
                          int offset)
        Gets the public key associated with this object.
        Parameters:
        key - The buffer to copy the public key to.
        offset - The first offset in the key buffer to copy to.
      • setPublicKey

        void setPublicKey​(byte[] key,
                          int offset)
        Sets the public key for this object.
        Parameters:
        key - The buffer containing the public key.
        offset - The first offset in the buffer that contains the key. If this object previously held a key pair, then this function will change it into a public key only object.
      • getPrivateKey

        void getPrivateKey​(byte[] key,
                           int offset)
        Gets the private key associated with this object.
        Parameters:
        key - The buffer to copy the private key to.
        offset - The first offset in the key buffer to copy to.
      • setPrivateKey

        @Deprecated
        void setPrivateKey​(byte[] key,
                           int offset)
        Deprecated.
        use setKeys()
        Sets the private key for this object.
        Parameters:
        key - The buffer containing the [rivate key.
        offset - The first offset in the buffer that contains the key. If this object previously held only a public key, then this function will change it into a key pair.
      • setKeys

        void setKeys​(byte[] privkey,
                     int privoffset,
                     byte[] pubkey,
                     int puboffset)
        Sets the private and public keys for this object. I2P for efficiency, since setPrivateKey() calculates the public key and overwrites it. Does NOT check that the two keys match.
        Parameters:
        privkey - The buffer containing the private key.
        privoffset - The first offset in the buffer that contains the key.
        pubkey - The buffer containing the private key.
        puboffset - The first offset in the buffer that contains the key.
        Since:
        0.9.48
      • setToNullPublicKey

        void setToNullPublicKey()
        Sets this object to the null public key and clears the private key.
      • clearKey

        void clearKey()
        Clears the key pair.
      • hasPublicKey

        boolean hasPublicKey()
        Determine if this object contains a public key.
        Returns:
        Returns true if this object contains a public key, or false if the public key has not yet been set.
      • hasPrivateKey

        boolean hasPrivateKey()
        Determine if this object contains a private key.
        Returns:
        Returns true if this object contains a private key, or false if the private key has not yet been set.
      • isNullPublicKey

        boolean isNullPublicKey()
        Determine if the public key in this object is the special null value.
        Returns:
        Returns true if the public key is the special null value, or false otherwise.
      • hasEncodedPublicKey

        boolean hasEncodedPublicKey()
        Determine if this object contains an optional encoded public key.
        Returns:
        Returns true if this object contains an encoded public key, or false if the public key has not yet been set.
        Since:
        0.9.44
      • getEncodedPublicKey

        void getEncodedPublicKey​(byte[] key,
                                 int offset)
        Gets the public key associated with this object.
        Parameters:
        key - The buffer to copy the public key to.
        offset - The first offset in the key buffer to copy to.
        Since:
        0.9.44
      • calculate

        void calculate​(byte[] sharedKey,
                       int offset,
                       DHState publicDH)
        Performs a Diffie-Hellman calculation with this object as the private key.
        Parameters:
        sharedKey - Buffer to put the shared key into.
        offset - Offset of the first byte for the shared key.
        publicDH - Object that contains the public key for the calculation.
        Throws:
        IllegalArgumentException - The publicDH object is not the same type as this object, or one of the objects does not contain a valid key.
      • copyFrom

        void copyFrom​(DHState other)
        Copies the key values from another DH object of the same type.
        Parameters:
        other - The other DH object to copy from
        Throws:
        IllegalStateException - The other DH object does not have the same type as this object.