src/ed25519/sign.c

filter: Statementstmt 100% 22 / 22 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 100% 22 / 22 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« src/ed25519/sc.c ↑ Summary
1 #include <string.h>
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 }
« src/ed25519/sc.c ↑ Summary