1 #include "ed25519.h"
2 #include "sha512.h"
3 #include "ge.h"
4 #include "sc.h"
5
6
ed25519_sign(unsigned char * signature,const unsigned char * message,size_t message_len,const unsigned char * public_key,const unsigned char * private_key)7 void ed25519_sign(unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key, const unsigned char *private_key) {
8 sha512_context hash;
9 unsigned char az[64];
10 unsigned char hram[64];
11 unsigned char nonce[64];
12 ge_p3 R;
13
14 sha512_init(&hash);
15 sha512_update(&hash, private_key, 32);
16 sha512_final(&hash, az);
17 az[0] &= 248;
18 az[31] &= 63;
19 az[31] |= 64;
20
21 sha512_init(&hash);
22 sha512_update(&hash, az + 32, 32);
23 sha512_update(&hash, message, message_len);
24 sha512_final(&hash, nonce);
25
26 sc_reduce(nonce);
27 ge_scalarmult_base(&R, nonce);
28 ge_p3_tobytes(signature, &R);
29
30 sha512_init(&hash);
31 sha512_update(&hash, signature, 32);
32 sha512_update(&hash, public_key, 32);
33 sha512_update(&hash, message, message_len);
34 sha512_final(&hash, hram);
35
36 sc_reduce(hram);
37 sc_muladd(signature + 32, hram, az, nonce);
38 }
39