diff options
Diffstat (limited to '')
-rw-r--r-- | src/md5.cpp | 47 |
1 files changed, 34 insertions, 13 deletions
diff --git a/src/md5.cpp b/src/md5.cpp index 14b244a..8d7b7c9 100644 --- a/src/md5.cpp +++ b/src/md5.cpp | |||
@@ -9,6 +9,8 @@ | |||
9 | #include <stdlib.h> | 9 | #include <stdlib.h> |
10 | #include <string.h> | 10 | #include <string.h> |
11 | #include "md5.h" | 11 | #include "md5.h" |
12 | #include "bu/stream.h" | ||
13 | |||
12 | 14 | ||
13 | // This performs a wrapping bitwise shift, kinda' fun! | 15 | // This performs a wrapping bitwise shift, kinda' fun! |
14 | 16 | ||
@@ -84,11 +86,39 @@ void Bu::Md5::addData( const void *sVData, int iSize ) | |||
84 | 86 | ||
85 | Bu::FString Bu::Md5::getResult() | 87 | Bu::FString Bu::Md5::getResult() |
86 | { | 88 | { |
89 | long lsum[4]; | ||
90 | compCap( lsum ); | ||
91 | return Bu::FString( (const char *)lsum, 4*4 ); | ||
92 | } | ||
93 | |||
94 | void Bu::Md5::writeResult( Bu::Stream &sOut ) | ||
95 | { | ||
96 | long lsum[4]; | ||
97 | compCap( lsum ); | ||
98 | sOut.write( lsum, 4*4 ); | ||
99 | } | ||
100 | |||
101 | Bu::FString Bu::Md5::getHexResult() | ||
102 | { | ||
87 | static const char hex_tab[] = {"0123456789abcdef"}; | 103 | static const char hex_tab[] = {"0123456789abcdef"}; |
88 | char str[33]; | 104 | char str[33]; |
89 | 105 | ||
90 | long lsum[4]; | 106 | long lsum[4]; |
91 | memcpy( lsum, sum, 4*4 ); | 107 | compCap( lsum ); |
108 | |||
109 | int k = 0; | ||
110 | for( int i = 0; i < 16; i++ ) | ||
111 | { | ||
112 | str[k++] = hex_tab[(lsum[i>>2] >> ((i%4)*8+4)) & 0xF]; | ||
113 | str[k++] = hex_tab[(lsum[i>>2] >> ((i%4)*8 )) & 0xF]; | ||
114 | } | ||
115 | |||
116 | return Bu::FString( str, 32 ); | ||
117 | } | ||
118 | |||
119 | void Bu::Md5::compCap( long *sumout ) | ||
120 | { | ||
121 | memcpy( sumout, sum, 4*4 ); | ||
92 | long lbuf[16]; | 122 | long lbuf[16]; |
93 | memcpy( lbuf, inbuf, 4*16 ); | 123 | memcpy( lbuf, inbuf, 4*16 ); |
94 | 124 | ||
@@ -96,25 +126,16 @@ Bu::FString Bu::Md5::getResult() | |||
96 | uint64_t iBits = iBytes*8; | 126 | uint64_t iBits = iBytes*8; |
97 | if( iBytes > 0 && iFill>>2 >= 14 ) | 127 | if( iBytes > 0 && iFill>>2 >= 14 ) |
98 | { | 128 | { |
99 | compBlock( lbuf, lsum ); | 129 | compBlock( lbuf, sumout ); |
100 | memset( lbuf, 0, 4*16 ); | 130 | memset( lbuf, 0, 4*16 ); |
101 | memcpy( lbuf+14, &iBits, 8 ); | 131 | memcpy( lbuf+14, &iBits, 8 ); |
102 | compBlock( lbuf, lsum ); | 132 | compBlock( lbuf, sumout ); |
103 | } | 133 | } |
104 | else | 134 | else |
105 | { | 135 | { |
106 | memcpy( lbuf+14, &iBits, 8 ); | 136 | memcpy( lbuf+14, &iBits, 8 ); |
107 | compBlock( lbuf, lsum ); | 137 | compBlock( lbuf, sumout ); |
108 | } | 138 | } |
109 | |||
110 | int k = 0; | ||
111 | for( int i = 0; i < 16; i++ ) | ||
112 | { | ||
113 | str[k++] = hex_tab[(lsum[i>>2] >> ((i%4)*8+4)) & 0xF]; | ||
114 | str[k++] = hex_tab[(lsum[i>>2] >> ((i%4)*8 )) & 0xF]; | ||
115 | } | ||
116 | |||
117 | return Bu::FString( str, 32 ); | ||
118 | } | 139 | } |
119 | 140 | ||
120 | void Bu::Md5::compBlock( long *x, long *lsum ) | 141 | void Bu::Md5::compBlock( long *x, long *lsum ) |