| 1 |
|
| /* |
| 2 |
|
| Perl Extension for the RIPEMD160 Message-Digest Algorithm |
| 3 |
|
| |
| 4 |
|
| This module by Christian H. Geuer <christian.geuer@crypto.gun.de> |
| 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 = RIPEMD160 PACKAGE = RIPEMD160 |
| 18 |
|
| |
| 19 |
|
| PROTOTYPES: DISABLE |
| 20 |
|
| |
| 21 |
|
| RIPEMD160 |
| 22 |
|
| new(packname = "RIPEMD160") |
| 23 |
|
| char * packname |
| 24 |
|
| CODE: |
| 25 |
|
| { |
| 26 |
21 |
| RETVAL = (RIPEMD160) safemalloc(sizeof(RIPEMD160_INFO)); |
| 27 |
21 |
| RIPEMD160_init(RETVAL); |
| 28 |
|
| } |
| 29 |
|
| OUTPUT: |
| 30 |
|
| RETVAL |
| 31 |
|
| |
| 32 |
|
| |
| 33 |
|
| void |
| 34 |
|
| DESTROY(ripemd160) |
| 35 |
|
| RIPEMD160 ripemd160 |
| 36 |
|
| CODE: |
| 37 |
|
| { |
| 38 |
21 |
| safefree((char *) ripemd160); |
| 39 |
|
| } |
| 40 |
|
| |
| 41 |
|
| |
| 42 |
|
| void |
| 43 |
|
| reset(ripemd160) |
| 44 |
|
| RIPEMD160 ripemd160 |
| 45 |
|
| CODE: |
| 46 |
|
| { |
| 47 |
20 |
| RIPEMD160_init(ripemd160); |
| 48 |
|
| } |
| 49 |
|
| |
| 50 |
|
| void |
| 51 |
|
| add(ripemd160, ...) |
| 52 |
|
| RIPEMD160 ripemd160 |
| 53 |
|
| CODE: |
| 54 |
|
| { |
| 55 |
|
| SV *svdata; |
| 56 |
|
| STRLEN len; |
| 57 |
|
| byte *strptr; |
| 58 |
|
| int i; |
| 59 |
|
| |
| 60 |
14995 |
▶ | for (i = 1; i < items; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 1; i < items; i++) { |
7643 |
7352 |
14995 |
|
| 61 |
7643 |
| strptr = (byte *) (SvPV(ST(i), len)); |
| 62 |
7643 |
| RIPEMD160_update(ripemd160, strptr, len); |
| 63 |
|
| } |
| 64 |
|
| } |
| 65 |
|
| |
| 66 |
|
| SV * |
| 67 |
|
| digest(ripemd160) |
| 68 |
|
| RIPEMD160 ripemd160 |
| 69 |
|
| CODE: |
| 70 |
|
| { |
| 71 |
|
| unsigned char d_str[20]; |
| 72 |
|
| |
| 73 |
39 |
| RIPEMD160_final(ripemd160); |
| 74 |
|
| #if (PERL_BYTEORDER == 1234) |
| 75 |
|
| /* Little Endian (1234) */ |
| 76 |
|
| d_str[ 0] = (unsigned char) ((ripemd160->MDbuf[0] ) & 0xff); |
| 77 |
|
| d_str[ 1] = (unsigned char) ((ripemd160->MDbuf[0] >> 8) & 0xff); |
| 78 |
|
| d_str[ 2] = (unsigned char) ((ripemd160->MDbuf[0] >> 16) & 0xff); |
| 79 |
|
| d_str[ 3] = (unsigned char) ((ripemd160->MDbuf[0] >> 24) & 0xff); |
| 80 |
|
| d_str[ 4] = (unsigned char) ((ripemd160->MDbuf[1] ) & 0xff); |
| 81 |
|
| d_str[ 5] = (unsigned char) ((ripemd160->MDbuf[1] >> 8) & 0xff); |
| 82 |
|
| d_str[ 6] = (unsigned char) ((ripemd160->MDbuf[1] >> 16) & 0xff); |
| 83 |
|
| d_str[ 7] = (unsigned char) ((ripemd160->MDbuf[1] >> 24) & 0xff); |
| 84 |
|
| d_str[ 8] = (unsigned char) ((ripemd160->MDbuf[2] ) & 0xff); |
| 85 |
|
| d_str[ 9] = (unsigned char) ((ripemd160->MDbuf[2] >> 8) & 0xff); |
| 86 |
|
| d_str[10] = (unsigned char) ((ripemd160->MDbuf[2] >> 16) & 0xff); |
| 87 |
|
| d_str[11] = (unsigned char) ((ripemd160->MDbuf[2] >> 24) & 0xff); |
| 88 |
|
| d_str[12] = (unsigned char) ((ripemd160->MDbuf[3] ) & 0xff); |
| 89 |
|
| d_str[13] = (unsigned char) ((ripemd160->MDbuf[3] >> 8) & 0xff); |
| 90 |
|
| d_str[14] = (unsigned char) ((ripemd160->MDbuf[3] >> 16) & 0xff); |
| 91 |
|
| d_str[15] = (unsigned char) ((ripemd160->MDbuf[3] >> 24) & 0xff); |
| 92 |
|
| d_str[16] = (unsigned char) ((ripemd160->MDbuf[4] ) & 0xff); |
| 93 |
|
| d_str[17] = (unsigned char) ((ripemd160->MDbuf[4] >> 8) & 0xff); |
| 94 |
|
| d_str[18] = (unsigned char) ((ripemd160->MDbuf[4] >> 16) & 0xff); |
| 95 |
|
| d_str[19] = (unsigned char) ((ripemd160->MDbuf[4] >> 24) & 0xff); |
| 96 |
|
| #else |
| 97 |
|
| /* Big Endian (4321) */ |
| 98 |
39 |
| d_str[ 0] = (unsigned char) ((ripemd160->MDbuf[0] >> 24) & 0xff); |
| 99 |
39 |
| d_str[ 1] = (unsigned char) ((ripemd160->MDbuf[0] >> 16) & 0xff); |
| 100 |
39 |
| d_str[ 2] = (unsigned char) ((ripemd160->MDbuf[0] >> 8) & 0xff); |
| 101 |
39 |
| d_str[ 3] = (unsigned char) ((ripemd160->MDbuf[0] ) & 0xff); |
| 102 |
39 |
| d_str[ 4] = (unsigned char) ((ripemd160->MDbuf[1] >> 24) & 0xff); |
| 103 |
39 |
| d_str[ 5] = (unsigned char) ((ripemd160->MDbuf[1] >> 16) & 0xff); |
| 104 |
39 |
| d_str[ 6] = (unsigned char) ((ripemd160->MDbuf[1] >> 8) & 0xff); |
| 105 |
39 |
| d_str[ 7] = (unsigned char) ((ripemd160->MDbuf[1] ) & 0xff); |
| 106 |
39 |
| d_str[ 8] = (unsigned char) ((ripemd160->MDbuf[2] >> 24) & 0xff); |
| 107 |
39 |
| d_str[ 9] = (unsigned char) ((ripemd160->MDbuf[2] >> 16) & 0xff); |
| 108 |
39 |
| d_str[10] = (unsigned char) ((ripemd160->MDbuf[2] >> 8) & 0xff); |
| 109 |
39 |
| d_str[11] = (unsigned char) ((ripemd160->MDbuf[2] ) & 0xff); |
| 110 |
39 |
| d_str[12] = (unsigned char) ((ripemd160->MDbuf[3] >> 24) & 0xff); |
| 111 |
39 |
| d_str[13] = (unsigned char) ((ripemd160->MDbuf[3] >> 16) & 0xff); |
| 112 |
39 |
| d_str[14] = (unsigned char) ((ripemd160->MDbuf[3] >> 8) & 0xff); |
| 113 |
39 |
| d_str[15] = (unsigned char) ((ripemd160->MDbuf[3] ) & 0xff); |
| 114 |
39 |
| d_str[16] = (unsigned char) ((ripemd160->MDbuf[4] >> 24) & 0xff); |
| 115 |
39 |
| d_str[17] = (unsigned char) ((ripemd160->MDbuf[4] >> 16) & 0xff); |
| 116 |
39 |
| d_str[18] = (unsigned char) ((ripemd160->MDbuf[4] >> 8) & 0xff); |
| 117 |
39 |
| d_str[19] = (unsigned char) ((ripemd160->MDbuf[4] ) & 0xff); |
| 118 |
|
| #endif |
| 119 |
|
| |
| 120 |
39 |
| ST(0) = sv_2mortal(newSVpv(d_str, 20)); |
| 121 |
|
| } |