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