code: function(r, x) {
    var r1 = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
    var r2 = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
    var r3 = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
    var r4 = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
    curve25519_addmodp(r1, x,x);								// r1 = 2x
    curve25519_invmodp(r2, r1, 1);							// r2 = (2x)^((p-5)/8) =: v
    curve25519_sqrmodp(r3, r2);								// r3 = v^2
    curve25519_mulmodp(r4, r1, r3);							// r4 = 2xv^2 =: i
    curve25519_submodp(r, r4, curve25519_one());				//  r = i-1
    curve25519_mulmodp(r1, r2, r);							// r1 = v(i-1)
    curve25519_mulmodp(r, x, r1);								//  r = xv(i-1)
  }
docs: ****
  BloodyRookie: Finding a square root mod p of x if we already know it exists and p congruent 3 mod 8.
  Using x^((p-1)/2) congruent 1 mod p and 2^((p-1)/2) congruent -1 mod p
  because of Eulers criterium we see that when we set v=(2x)^((p-5)/8) then
  i:=2xv^2 is a square root of -1 and thus r=+xv(i-1) and r=-xv(i-1) are the square roots of x.