wrap_160.c

filter: Statementstmt 97.3% 37 / 38 Branchbran 92.8% 13 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 96.1% 50 / 52 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« RIPEMD160.xs ↑ Summary rmd160.c »
1 #include <string.h>
2  
3 #include "rmd160.h"
4 #include "wrap_160.h"
5  
6 /*
7 * Indirect memset via a volatile function pointer. The compiler
8 * cannot prove that the pointer still equals memset at call time,
9 * so it must emit the call even when the target memory is about to
10 * go out of scope or be freed.
11 */
12 static void *(* const volatile memset_ptr)(void *, int, size_t) = memset;
13  
14 1428 void secure_memzero(void *ptr, size_t len)
15 {
16 1428 (memset_ptr)(ptr, 0, len);
17 1428 }
18  
19 731 void RIPEMD160_init(Crypt__RIPEMD160 ripemd160)
20 {
21 731 memset(ripemd160, 0, sizeof(RIPEMD160_INFO));
22 731 MDinit(ripemd160->MDbuf);
23 731 }
24  
25 1002625 void RIPEMD160_update(Crypt__RIPEMD160 ripemd160, const byte *strptr, dword len)
26 {
27 dword i;
28 dword X[16];
29  
30 1002625 ▶ if (ripemd160->count_lo + len < ripemd160->count_lo) {
Branch: 1 branch
BranchTrueFalseTotal
if (ripemd160->count_lo + len < ripemd160->count_lo) { 0 1002625 1002625
31 0 ripemd160->count_hi++;
32 }
33 1002625 ripemd160->count_lo += len;
34  
35 1002625 ▶ if (ripemd160->local > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ripemd160->local > 0) { 986118 16507 1002625
36 986118 i = RIPEMD160_BLOCKSIZE - ripemd160->local;
37 986118 ▶ if (i > len) {
Branch: 1 branch
BranchTrueFalseTotal
if (i > len) { 969868 16250 986118
38 969868 i = len;
39 }
40 986118 memcpy(ripemd160->data + ripemd160->local, strptr, i);
41 986118 len -= i;
42 986118 strptr += i;
43 986118 ripemd160->local += i;
44 986118 ▶ if (ripemd160->local == RIPEMD160_BLOCKSIZE) {
Branch: 1 branch
BranchTrueFalseTotal
if (ripemd160->local == RIPEMD160_BLOCKSIZE) { 16250 969868 986118
45 276250 ▶ for (i = 0; i < 16; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < 16; i++) 260000 16250 276250
46 260000 X[i] = BYTES_TO_DWORD(ripemd160->data + 4*i);
47 16250 rmd160_compress(ripemd160->MDbuf, X);
48 } else {
49 969868 return;
50 }
51 }
52 34122 ▶ while (len >= RIPEMD160_BLOCKSIZE) {
Branch: 1 branch
BranchTrueFalseTotal
while (len >= RIPEMD160_BLOCKSIZE) { 1365 32757 34122
53 23205 ▶ for (i = 0; i < 16; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < 16; i++) { 21840 1365 23205
54 21840 X[i] = BYTES_TO_DWORD(strptr);
55 21840 strptr += 4;
56 }
57 1365 len -= RIPEMD160_BLOCKSIZE;
58 1365 rmd160_compress(ripemd160->MDbuf, X);
59 }
60 32757 memcpy(ripemd160->data, strptr, len);
61 32757 ripemd160->local = len;
62 }
63  
64 713 void RIPEMD160_final(Crypt__RIPEMD160 ripemd160)
65 {
66 713 MDfinish(ripemd160->MDbuf,
67 713 ripemd160->data,
68 713 (dword) ripemd160->count_lo,
69 713 (dword) ripemd160->count_hi);
70 713 }
« RIPEMD160.xs ↑ Summary rmd160.c »