Class Elligator2

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

class Elligator2 extends Object
Elligator2 for X25519 keys. 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.
Since:
0.9.44
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    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.
    byte[]
    Use for on-the-wire.
    protected static byte[]
    encode(PublicKey point, boolean alternative)
    Use for unit tests.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • 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
    • encode

      protected static byte[] encode(PublicKey point, boolean alternative)
      Use for unit tests. Don't use for on-the-wire; use one-arg version. Output will look like 254 random bits. High two bits of rv[31] will be zero. From javascript version documentation: The algorithm can return two different values for a single x coordinate if it's not 0. Which one to return is determined by y coordinate. Since Curve25519 doesn't use y due to optimizations, you should specify a Boolean value as the second argument of the function. It should be unpredictable, because it's recoverable from the representative.
      Returns:
      "representative", little endian 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
    • 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