net.i2p.router.crypto.ratchet

## Class Elligator2

- java.lang.Object
- - net.i2p.router.crypto.ratchet.Elligator2

-     class Elligator2
      extends Object

  Elligator2 encoding and decoding for X25519 public keys to provide cryptographically indistinguishable representations Ported from the Jan. 13, 2016 C version at https://github.com/Kleshni/Elligator-2 Note: That code was completely rewritten May 8, 2017 and is now much more complex. No apparent license.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Elligator2(I2PAppContext ctx)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static PublicKey` | `decode(AtomicBoolean alternative, byte[] representative)` From javascript version documentation: Returns an array with the point and the second argument of the corresponding call to the `encode` function.
    `static PublicKey` | `decode(byte[] representative)` From javascript version documentation: Returns an array with the point and the second argument of the corresponding call to the `encode` function.
    `byte[]` | `encode(PublicKey point)` Use for on-the-wire.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Elligator2

          public Elligator2(I2PAppContext ctx)

  - ### Method Detail

    - #### decode

          public static PublicKey decode(AtomicBoolean alternative,
                                         byte[] representative)

      From javascript version documentation: Returns an array with the point and the second argument of the corresponding call to the `encode` function. It's also able to return null if the representative is invalid (there are only 10 invalid representatives).
      Parameters:
        `alternative` - out parameter, or null if you don't care
        `representative` - the encoded data, little endian, 32 bytes; WILL BE MODIFIED by masking byte 31
      Returns:
        x or null on failure

    - #### decode

          public static PublicKey decode(byte[] representative)

      From javascript version documentation: Returns an array with the point and the second argument of the corresponding call to the `encode` function. It's also able to return null if the representative is invalid (there are only 10 invalid representatives).
      Parameters:
        `representative` - the encoded data, little endian, 32 bytes WILL BE MODIFIED by masking byte 31
      Returns:
        x or null on failure

    - #### encode

          public byte[] encode(PublicKey point)

      Use for on-the-wire. Don't use for unit tests as output will be randomized based on the 'alternative' and the high bits. There are eight possible encodings for any point. Output will look like 256 random bits.
      Returns:
        "representative", little endian or null on failure