# Elliptic Curve ed25519

ed25519 is strategically important as its implementation was highly optimised during its design, for high security. Edwards-curve Digital Signature Algorithm (EdDSA) was also designed to be fast.

In the donna-ed25519 implementation, key functions such as ed25519_mul are laid out explicitly by loop-unrolling:

``````t[0]  =  r0 * s0
t[1]  =  r0 * s1 + r1 * s0;
t[2]  =  r0 * s2 + r1 * s1 + r2 * s0;
t[3]  =  r0 * s3 + r1 * s2 + r2 * s1 + r3 * s0;
t[4]  =  r0 * s4 + r1 * s3 + r2 * s2 + r3 * s1 + r4 * s0;
``````

Note the very obvious patterns here which are triangular in nature. With the very existence of Simple-V's REMAP subsystem it is quite natural to see if triangular remapping can be added and used. It turns out to be quite easy, and there are two possible techniques: Vertical-First and Horizontal-First.

With Vertical-First, the multiply is done first as a scalar item, into a temporary register, followed by an addition of the scalar into the actual target (t0 thru t4)

``````sv.mul temp, *r, *s   # temporary target scalar register
With Horizontal-First it is extremely simple: use `madd` - integer multiply-and-accumulate:
``````sv.madd *t, *r, *s