File Coverage

RIPEMD160.xs
Criterion Covered Total %
statement 29 29 100.0
branch 3 4 75.0
condition n/a
subroutine n/a
pod n/a
total 32 33 96.9


line stmt bran cond sub pod time code
1             /*
2             Perl Extension for the RIPEMD160 Message-Digest Algorithm
3              
4             This module by Christian H. Geuer
5             following example of MD5 module and SHA module.
6              
7             This extension (wrapper code and perl-stuff) may be distributed
8             under the same terms as Perl.
9             */
10              
11             #include "EXTERN.h"
12             #include "perl.h"
13             #include "XSUB.h"
14              
15             #include "wrap_160.h"
16              
17             MODULE = Crypt::RIPEMD160 PACKAGE = Crypt::RIPEMD160 PREFIX = rmd160_
18              
19             PROTOTYPES: DISABLE
20              
21             Crypt::RIPEMD160
22             rmd160_new(packname = "Crypt::RIPEMD160")
23             char * packname
24             CODE:
25             {
26 21           RETVAL = (Crypt__RIPEMD160) safemalloc(sizeof(RIPEMD160_INFO));
27 21           RIPEMD160_init(RETVAL);
28             }
29             OUTPUT:
30             RETVAL
31              
32              
33             void
34             rmd160_DESTROY(ripemd160)
35             Crypt::RIPEMD160 ripemd160
36             CODE:
37             {
38 21           safefree((char *) ripemd160);
39             }
40              
41              
42             void
43             reset(ripemd160)
44             Crypt::RIPEMD160 ripemd160
45             CODE:
46             {
47 17           RIPEMD160_init(ripemd160);
48             }
49              
50             void
51             rmd160_add(ripemd160, ...)
52             Crypt::RIPEMD160 ripemd160
53             CODE:
54             {
55             SV *svdata;
56             STRLEN len;
57             byte *strptr;
58             int i;
59              
60 2011250 100         for (i = 1; i < items; i++) {
61 1005728 50         strptr = (byte *) (SvPV(ST(i), len));
62 1005728           RIPEMD160_update(ripemd160, strptr, len);
63             }
64             }
65              
66             SV *
67             rmd160_digest(ripemd160)
68             Crypt::RIPEMD160 ripemd160
69             CODE:
70             {
71             unsigned char d_str[20];
72              
73 36           RIPEMD160_final(ripemd160);
74              
75 36           d_str[ 0] = (unsigned char) ((ripemd160->MDbuf[0] ) & 0xff);
76 36           d_str[ 1] = (unsigned char) ((ripemd160->MDbuf[0] >> 8) & 0xff);
77 36           d_str[ 2] = (unsigned char) ((ripemd160->MDbuf[0] >> 16) & 0xff);
78 36           d_str[ 3] = (unsigned char) ((ripemd160->MDbuf[0] >> 24) & 0xff);
79 36           d_str[ 4] = (unsigned char) ((ripemd160->MDbuf[1] ) & 0xff);
80 36           d_str[ 5] = (unsigned char) ((ripemd160->MDbuf[1] >> 8) & 0xff);
81 36           d_str[ 6] = (unsigned char) ((ripemd160->MDbuf[1] >> 16) & 0xff);
82 36           d_str[ 7] = (unsigned char) ((ripemd160->MDbuf[1] >> 24) & 0xff);
83 36           d_str[ 8] = (unsigned char) ((ripemd160->MDbuf[2] ) & 0xff);
84 36           d_str[ 9] = (unsigned char) ((ripemd160->MDbuf[2] >> 8) & 0xff);
85 36           d_str[10] = (unsigned char) ((ripemd160->MDbuf[2] >> 16) & 0xff);
86 36           d_str[11] = (unsigned char) ((ripemd160->MDbuf[2] >> 24) & 0xff);
87 36           d_str[12] = (unsigned char) ((ripemd160->MDbuf[3] ) & 0xff);
88 36           d_str[13] = (unsigned char) ((ripemd160->MDbuf[3] >> 8) & 0xff);
89 36           d_str[14] = (unsigned char) ((ripemd160->MDbuf[3] >> 16) & 0xff);
90 36           d_str[15] = (unsigned char) ((ripemd160->MDbuf[3] >> 24) & 0xff);
91 36           d_str[16] = (unsigned char) ((ripemd160->MDbuf[4] ) & 0xff);
92 36           d_str[17] = (unsigned char) ((ripemd160->MDbuf[4] >> 8) & 0xff);
93 36           d_str[18] = (unsigned char) ((ripemd160->MDbuf[4] >> 16) & 0xff);
94 36           d_str[19] = (unsigned char) ((ripemd160->MDbuf[4] >> 24) & 0xff);
95              
96 36           ST(0) = sv_2mortal(newSVpv(d_str, 20));
97             }