File Coverage

wrap_160.c
Criterion Covered Total %
statement 37 38 97.3
branch 13 14 92.8
condition n/a
subroutine n/a
pod n/a
total 50 52 96.1


line stmt bran cond sub pod time code
1             #include
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 1002614           void RIPEMD160_update(Crypt__RIPEMD160 ripemd160, const byte *strptr, dword len)
26             {
27             dword i;
28             dword X[16];
29              
30 1002614 50         if (ripemd160->count_lo + len < ripemd160->count_lo) {
31 0           ripemd160->count_hi++;
32             }
33 1002614           ripemd160->count_lo += len;
34              
35 1002614 100         if (ripemd160->local > 0) {
36 986107           i = RIPEMD160_BLOCKSIZE - ripemd160->local;
37 986107 100         if (i > len) {
38 969855           i = len;
39             }
40 986107           memcpy(ripemd160->data + ripemd160->local, strptr, i);
41 986107           len -= i;
42 986107           strptr += i;
43 986107           ripemd160->local += i;
44 986107 100         if (ripemd160->local == RIPEMD160_BLOCKSIZE) {
45 276284 100         for (i = 0; i < 16; i++)
46 260032           X[i] = BYTES_TO_DWORD(ripemd160->data + 4*i);
47 16252           rmd160_compress(ripemd160->MDbuf, X);
48             } else {
49 969855           return;
50             }
51             }
52 34122 100         while (len >= RIPEMD160_BLOCKSIZE) {
53 23171 100         for (i = 0; i < 16; i++) {
54 21808           X[i] = BYTES_TO_DWORD(strptr);
55 21808           strptr += 4;
56             }
57 1363           len -= RIPEMD160_BLOCKSIZE;
58 1363           rmd160_compress(ripemd160->MDbuf, X);
59             }
60 32759           memcpy(ripemd160->data, strptr, len);
61 32759           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           }