| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#include "ed25519.h" |
|
2
|
|
|
|
|
|
|
#include "sha512.h" |
|
3
|
|
|
|
|
|
|
#include "ge.h" |
|
4
|
|
|
|
|
|
|
#include "sc.h" |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1564
|
|
|
|
|
|
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
|
1564
|
|
|
|
|
|
sha512_init(&hash); |
|
15
|
1564
|
|
|
|
|
|
sha512_update(&hash, private_key + 32, 32); |
|
16
|
1564
|
|
|
|
|
|
sha512_update(&hash, message, message_len); |
|
17
|
1564
|
|
|
|
|
|
sha512_final(&hash, r); |
|
18
|
|
|
|
|
|
|
|
|
19
|
1564
|
|
|
|
|
|
sc_reduce(r); |
|
20
|
1564
|
|
|
|
|
|
ge_scalarmult_base(&R, r); |
|
21
|
1564
|
|
|
|
|
|
ge_p3_tobytes(signature, &R); |
|
22
|
|
|
|
|
|
|
|
|
23
|
1564
|
|
|
|
|
|
sha512_init(&hash); |
|
24
|
1564
|
|
|
|
|
|
sha512_update(&hash, signature, 32); |
|
25
|
1564
|
|
|
|
|
|
sha512_update(&hash, public_key, 32); |
|
26
|
1564
|
|
|
|
|
|
sha512_update(&hash, message, message_len); |
|
27
|
1564
|
|
|
|
|
|
sha512_final(&hash, hram); |
|
28
|
|
|
|
|
|
|
|
|
29
|
1564
|
|
|
|
|
|
sc_reduce(hram); |
|
30
|
1564
|
|
|
|
|
|
sc_muladd(signature + 32, hram, private_key, r); |
|
31
|
1564
|
|
|
|
|
|
} |