private byte[] toLittleEndian(BigInteger n) {
    byte[] b = new byte[32];
    byte[] nBytes = n.toByteArray();

    if ((nBytes.length > 33) || (nBytes.length == 33 && nBytes[0] != 0)) {
      throw new IllegalArgumentException("Number too big");
    }
    if (nBytes.length == 33) {
      System.arraycopy(nBytes, 1, b, 0, 32);
    } else {
      System.arraycopy(nBytes, 0, b, 32 - nBytes.length, nBytes.length);
    }
    for (int i = 0; i < b.length / 2; i++) {
      byte t = b[i];
      b[i] = b[b.length - i - 1];
      b[b.length - i - 1] = t;
    }
    return b;
  }
1st iteration test in Section 5.2 of RFC 7748. https://tools.ietf.org/html/rfc7748, but with
the MSB set.
java_src/src/test/java/com/google/crypto/tink/internal/Curve25519Test.java