1 | #include "ed25519.h" |
2 | #include "sha512.h" |
3 | #include "ge.h" |
4 | #include "sc.h" |
5 | |
6 | |
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 hram[64]; |
10 | unsigned char r[64]; |
11 | ge_p3 R; |
12 | |
13 | |
14 | sha512_init(md: &hash); |
15 | sha512_update(md: &hash, in: private_key + 32, inlen: 32); |
16 | sha512_update(md: &hash, in: message, inlen: message_len); |
17 | sha512_final(md: &hash, out: r); |
18 | |
19 | sc_reduce(s: r); |
20 | ge_scalarmult_base(h: &R, a: r); |
21 | ge_p3_tobytes(s: signature, h: &R); |
22 | |
23 | sha512_init(md: &hash); |
24 | sha512_update(md: &hash, in: signature, inlen: 32); |
25 | sha512_update(md: &hash, in: public_key, inlen: 32); |
26 | sha512_update(md: &hash, in: message, inlen: message_len); |
27 | sha512_final(md: &hash, out: hram); |
28 | |
29 | sc_reduce(s: hram); |
30 | sc_muladd(s: signature + 32, a: hram, b: private_key, c: r); |
31 | } |
32 | |