PointEd25519 extends Point { @Override public final Point scalarMultiply(BigInteger integer) { if (integer.equals(BigInteger.ZERO)) { return PointEd25519.O; } Point[] qs = new Point[]{O, O}; Point[] rs = new Point[]{this, this, negateY()}; int[] signedBin = ArrayUtils.toMutualOppositeForm(integer); for (int aSignedBin : signedBin) { qs[0] = qs[0].doubling(); qs[1] = qs[0].add(rs[1 - aSignedBin]).negate(); qs[0] = qs[(aSignedBin ^ (aSignedBin >> 31)) - (aSignedBin >> 31)]; } return qs[0]; } PointEd25519(Coordinate x, Coordinate y, Coordinate z, Coordinate t); static PointEd25519 fromAffine(Coordinate x, Coordinate y); @Override final Point add(Point point); @Override Point doubling(); @Override final Point scalarMultiply(BigInteger integer); @Override Point negateY(); @Override final EncodedPoint encode(); @Override Point negate();  }
@Test public void success_ScalarMultiply_1() { Point point = curve.getBasePoint(); BigInteger integer = new BigInteger("1234"); Point result = point.scalarMultiply(integer); assertThat(result.getAffineX().getInteger(), is(new BigInteger("55556569241314067156494303609322045323771151550641480329783949256943018472903"))); assertThat(result.getAffineY().getInteger(), is(new BigInteger("32784530584814531279135473125766128158866185447326682367874410721387968224179"))); }
@Test public void success_ScalarMultiply_2() { Point point = curve.getBasePoint(); BigInteger integer = new BigInteger("20266806181347897178517736945403300566236311925948585575972021784256181966831"); Point result = point.scalarMultiply(integer); assertThat(result.getAffineX().getInteger(), is(new BigInteger("36568395279531091001405240627702774400329345357946000277861114291457062189012"))); assertThat(result.getAffineY().getInteger(), is(new BigInteger("6892543919216139430465404745243127488161491607535545431263766463424432810420"))); }
@Test public void success_ScalarMultiply_3() { Point point = curve.getBasePoint(); BigInteger integer = new BigInteger("11675954373387894284288004270057647646117187555908725144338394611307421402153"); Point result = point.scalarMultiply(integer); assertThat(result.getAffineX().getInteger(), is(new BigInteger("2550105584539864958223359997109982244652817874690374654323009420113342284222"))); assertThat(result.getAffineY().getInteger(), is(new BigInteger("32100423734119761214020102691557112218747037854384677234614616607240732191696"))); }
@Test public void success_ScalarMultiply_4() { Point point = curve.getBasePoint(); BigInteger integer = new BigInteger("53796438671359824102085853653404738634771041230653645888564199631429825277660"); Point result = point.scalarMultiply(integer); assertThat(result.getAffineX().getInteger(), is(new BigInteger("55567266549953732748489637086272210307507483701392087766383203587162091263037"))); assertThat(result.getAffineY().getInteger(), is(new BigInteger("39648261582079248220577879738713959882783855750578332978656472445048155089907"))); }
@Test public void success_ScalarMultiply_5() { Point point = curve.getBasePoint(); BigInteger integer = new BigInteger("32610704945606948033834599741453719010166132071117736619400925734673110257760"); Point result = point.scalarMultiply(integer); assertThat(result.getAffineX().getInteger(), is(new BigInteger("46453596183992846648371334773013814104200062737923250995844281103986991912429"))); assertThat(result.getAffineY().getInteger(), is(new BigInteger("25430834724210084628427024029388177706947140598135008372913684687859787885119"))); }
@Test public void success_ScalarMultiply_6() { Point point = curve.getBasePoint(); Point result = point.scalarMultiply(BigInteger.ZERO); assertThat(result.getX().getInteger(), is(BigInteger.ZERO)); assertThat(result.getY().getInteger(), is(BigInteger.ONE)); }
@Test public void success_ScalarMultiplyBasePoint_2() { Point doubled = curve.getBasePoint().scalarMultiply(new BigInteger("2")); assertThat(doubled.getAffineX().getInteger(), is(new BigInteger("24727413235106541002554574571675588834622768167397638456726423682521233608206"))); assertThat(doubled.getAffineY().getInteger(), is(new BigInteger("15549675580280190176352668710449542251549572066445060580507079593062643049417"))); }
@Test public void success_ScalarMultiplyBasePoint_7() { Point doubled = curve.getBasePoint().scalarMultiply(new BigInteger("7")); assertThat(doubled.getAffineX().getInteger(), is(new BigInteger("9199134265559022971505535402808359556995554859516252602543778295037484220679"))); assertThat(doubled.getAffineY().getInteger(), is(new BigInteger("22512087849695599276028560866629687720820254811233262850576678203618951717560"))); }
@Test public void success_ScalarMultiplyBasePoint_3() { Point doubled = curve.getBasePoint().scalarMultiply(new BigInteger("3")); assertThat(doubled.getAffineX().getInteger(), is(new BigInteger("46896733464454938657123544595386787789046198280132665686241321779790909858396"))); assertThat(doubled.getAffineY().getInteger(), is(new BigInteger("8324843778533443976490377120369201138301417226297555316741202210403726505172"))); }
@Test public void success_ScalarMultiplyBasePoint_4() { Point doubled = curve.getBasePoint().scalarMultiply(new BigInteger("4")); assertThat(doubled.getAffineX().getInteger(), is(new BigInteger("14582954232372986451776170844943001818709880559417862259286374126315108956272"))); assertThat(doubled.getAffineY().getInteger(), is(new BigInteger("32483318716863467900234833297694612235682047836132991208333042722294373421359"))); }
@Test public void success_ScalarMultiplyBasePoint_8() { Point doubled = curve.getBasePoint().scalarMultiply(new BigInteger("8")); assertThat(doubled.getAffineX().getInteger(), is(new BigInteger("46706390780465557264338673484185971070529246228527338942042475661633188627656"))); assertThat(doubled.getAffineY().getInteger(), is(new BigInteger("15299170165656271974649334809062094114079726227711063015095704409550798436788"))); }
@Test public void success_ScalarMultiplyBasePoint_6() { Point doubled = curve.getBasePoint().scalarMultiply(new BigInteger("6")); assertThat(doubled.getAffineX().getInteger(), is(new BigInteger("34643617590234865996699167120328052565261792237873803846102513686264813449789"))); assertThat(doubled.getAffineY().getInteger(), is(new BigInteger("2399184961499513294557607325187831088545696902880432827228757905043131825908"))); }
@Test public void success_ScalarMultiplyBasePoint_10() { Point doubled = curve.getBasePoint().scalarMultiply(new BigInteger("10")); assertThat(doubled.getAffineX().getInteger(), is(new BigInteger("43500613248243327786121022071801015118933854441360174117148262713429272820047"))); assertThat(doubled.getAffineY().getInteger(), is(new BigInteger("45005105423099817237495816771148012388779685712352441364231470781391834741548"))); }
@Test public void success_ScalarMultiplyBasePoint_11() { Point doubled = curve.getBasePoint().scalarMultiply(new BigInteger("11")); assertThat(doubled.getAffineX().getInteger(), is(new BigInteger("9451145793506787353375160377761530931587019091193333050860601958827395183563"))); assertThat(doubled.getAffineY().getInteger(), is(new BigInteger("20609402718286069808115703540855311742885093522056241285814584245966805874451"))); }
@Test public void success_ScalarMultiplyBasePoint_12() { Point doubled = curve.getBasePoint().scalarMultiply(new BigInteger("12")); assertThat(doubled.getAffineX().getInteger(), is(new BigInteger("32159939716063394567822525359727347405356413309540137282993608327129696604205"))); assertThat(doubled.getAffineY().getInteger(), is(new BigInteger("29147333543209904737197244325450674102993621692520459538942544703173373584633"))); }
@Test public void success_ScalarMultiplyBasePoint_50459379271018302582465998844449622265826330103819895252966304478993432089656() { Point scalard = curve.getBasePoint().scalarMultiply(new BigInteger("50459379271018302582465998844449622265826330103819895252966304478993432089656")); assertThat(scalard.getAffineX().getInteger(), is(new BigInteger("15803359856018908320086002332714894013924030585248052893900291221487236226419"))); assertThat(scalard.getAffineY().getInteger(), is(new BigInteger("25416682171142283067951549518103646638934086440885266225724336361653813092611"))); }