Ed25519 { @SuppressWarnings("NarrowingCompoundAssignment") private static XYZ scalarMultWithBase(byte[] a) { byte[] e = new byte[2 * FIELD_LEN]; for (int i = 0; i < FIELD_LEN; i++) { e[2 * i + 0] = (byte) (((a[i] & 0xff) >> 0) & 0xf); e[2 * i + 1] = (byte) (((a[i] & 0xff) >> 4) & 0xf); } int carry = 0; for (int i = 0; i < e.length - 1; i++) { e[i] += carry; carry = e[i] + 8; carry >>= 4; e[i] -= carry << 4; } e[e.length - 1] += carry; PartialXYZT ret = new PartialXYZT(NEUTRAL); XYZT xyzt = new XYZT(); for (int i = 1; i < e.length; i += 2) { CachedXYT t = new CachedXYT(CACHED_NEUTRAL); select(t, i / 2, e[i]); add(ret, XYZT.fromPartialXYZT(xyzt, ret), t); } XYZ xyz = new XYZ(); doubleXYZ(ret, XYZ.fromPartialXYZT(xyz, ret)); doubleXYZ(ret, XYZ.fromPartialXYZT(xyz, ret)); doubleXYZ(ret, XYZ.fromPartialXYZT(xyz, ret)); doubleXYZ(ret, XYZ.fromPartialXYZT(xyz, ret)); for (int i = 0; i < e.length; i += 2) { CachedXYT t = new CachedXYT(CACHED_NEUTRAL); select(t, i / 2, e[i]); add(ret, XYZT.fromPartialXYZT(xyzt, ret), t); } XYZ result = new XYZ(ret); if (!result.isOnCurve()) { throw new IllegalStateException("arithmetic error in scalar multiplication"); } return result; }   static final int SECRET_KEY_LEN; static final int PUBLIC_KEY_LEN; static final int SIGNATURE_LEN; }
@Test public void testScalarMultWithBase() throws Exception { byte[] scalar = Hex.decode("521784c403e6fb32d48e0da85969a82f5952856bde4471a42b3fa56fd8b96c0d"); Ed25519.scalarMultWithBaseToBytes(scalar); }