src/ed25519/verify.c

filter: Statementstmt 0.0% 0 / 51 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 57 SCAR 0
CC
0
Cov
0%
CRAP 0
« src/ed25519/sign.c ↑ Summary blib/lib/Net/SSH/Perl/Cipher/AES128_CTR.pm »
1 #include "ed25519.h"
2 #include "sha512.h"
3 #include "ge.h"
4 #include "sc.h"
5  
6 0 static int consttime_equal(const unsigned char *x, const unsigned char *y) {
7 0 unsigned char r = 0;
8  
9 0 r = x[0] ^ y[0];
10 #define F(i) r |= x[i] ^ y[i]
11 0 F(1);
12 0 F(2);
13 0 F(3);
14 0 F(4);
15 0 F(5);
16 0 F(6);
17 0 F(7);
18 0 F(8);
19 0 F(9);
20 0 F(10);
21 0 F(11);
22 0 F(12);
23 0 F(13);
24 0 F(14);
25 0 F(15);
26 0 F(16);
27 0 F(17);
28 0 F(18);
29 0 F(19);
30 0 F(20);
31 0 F(21);
32 0 F(22);
33 0 F(23);
34 0 F(24);
35 0 F(25);
36 0 F(26);
37 0 F(27);
38 0 F(28);
39 0 F(29);
40 0 F(30);
41 0 F(31);
42 #undef F
43  
44 0 return !r;
45 }
46  
47 0 int ed25519_verify(const unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key) {
48 unsigned char h[64];
49 unsigned char checker[32];
50 sha512_context hash;
51 ge_p3 A;
52 ge_p2 R;
53  
54 0 ▶ if (signature[63] & 224) {
Branch: 1 branch
BranchTrueFalseTotal
if (signature[63] & 224) { 0 0 0
55 0 return 0;
56 }
57  
58 0 ▶ if (ge_frombytes_negate_vartime(&A, public_key) != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ge_frombytes_negate_vartime(&A, public_key) != 0) { 0 0 0
59 0 return 0;
60 }
61  
62 0 sha512_init(&hash);
63 0 sha512_update(&hash, signature, 32);
64 0 sha512_update(&hash, public_key, 32);
65 0 sha512_update(&hash, message, message_len);
66 0 sha512_final(&hash, h);
67
68 0 sc_reduce(h);
69 0 ge_double_scalarmult_vartime(&R, h, &A, signature + 32);
70 0 ge_tobytes(checker, &R);
71  
72 0 ▶ if (!consttime_equal(checker, signature)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!consttime_equal(checker, signature)) { 0 0 0
73 0 return 0;
74 }
75  
76 0 return 1;
77 }
« src/ed25519/sign.c ↑ Summary blib/lib/Net/SSH/Perl/Cipher/AES128_CTR.pm »