6 /* see http://crypto.stackexchange.com/a/6215/4697 */
7 void ed25519_add_scalar(unsigned char *public_key, unsigned char *private_key, const unsigned char *scalar) {
8 const unsigned char SC_1[32] = {1}; /* scalar with value 1 */
14 ge_p3 public_key_unpacked;
19 /* copy the scalar and clear highest bit */
20 for (i = 0; i < 31; ++i) {
23 n[31] = scalar[31] & 127;
25 /* private key: a = n + t */
27 sc_muladd(private_key, SC_1, n, private_key);
30 /* public key: A = nB + T */
32 /* if we know the private key we don't need a point addition, which is faster */
33 /* using a "timing attack" you could find out wether or not we know the private
34 key, but this information seems rather useless - if this is important pass
35 public_key and private_key seperately in 2 function calls */
37 ge_scalarmult_base(&A, private_key);
39 /* unpack public key into T */
40 ge_frombytes_negate_vartime(&public_key_unpacked, public_key);
41 fe_neg(public_key_unpacked.X, public_key_unpacked.X); // undo negate
42 fe_neg(public_key_unpacked.T, public_key_unpacked.T); // undo negate
43 ge_p3_to_cached(&T, &public_key_unpacked);
46 ge_scalarmult_base(&nB, n);
49 ge_add(&A_p1p1, &nB, &T);
50 ge_p1p1_to_p3(&A, &A_p1p1);
54 ge_p3_tobytes(public_key, &A);