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 1387           void secure_memzero(void *ptr, size_t len)
15             {
16 1387           (memset_ptr)(ptr, 0, len);
17 1387           }
18              
19 708           void RIPEMD160_init(Crypt__RIPEMD160 ripemd160)
20             {
21 708           memset(ripemd160, 0, sizeof(RIPEMD160_INFO));
22 708           MDinit(ripemd160->MDbuf);
23 708           }
24              
25 1002587           void RIPEMD160_update(Crypt__RIPEMD160 ripemd160, const byte *strptr, dword len)
26             {
27             dword i;
28             dword X[16];
29              
30 1002587 50         if (ripemd160->count_lo + len < ripemd160->count_lo) {
31 0           ripemd160->count_hi++;
32             }
33 1002587           ripemd160->count_lo += len;
34              
35 1002587 100         if (ripemd160->local > 0) {
36 986100           i = RIPEMD160_BLOCKSIZE - ripemd160->local;
37 986100 100         if (i > len) {
38 969853           i = len;
39             }
40 986100           memcpy(ripemd160->data + ripemd160->local, strptr, i);
41 986100           len -= i;
42 986100           strptr += i;
43 986100           ripemd160->local += i;
44 986100 100         if (ripemd160->local == RIPEMD160_BLOCKSIZE) {
45 276199 100         for (i = 0; i < 16; i++)
46 259952           X[i] = BYTES_TO_DWORD(ripemd160->data + 4*i);
47 16247           rmd160_compress(ripemd160->MDbuf, X);
48             } else {
49 969853           return;
50             }
51             }
52 34094 100         while (len >= RIPEMD160_BLOCKSIZE) {
53 23120 100         for (i = 0; i < 16; i++) {
54 21760           X[i] = BYTES_TO_DWORD(strptr);
55 21760           strptr += 4;
56             }
57 1360           len -= RIPEMD160_BLOCKSIZE;
58 1360           rmd160_compress(ripemd160->MDbuf, X);
59             }
60 32734           memcpy(ripemd160->data, strptr, len);
61 32734           ripemd160->local = len;
62             }
63              
64 695           void RIPEMD160_final(Crypt__RIPEMD160 ripemd160)
65             {
66 695           MDfinish(ripemd160->MDbuf,
67 695           ripemd160->data,
68 695           (dword) ripemd160->count_lo,
69 695           (dword) ripemd160->count_hi);
70 695           }