diff options
author | Jacek Antonelli | 2008-08-15 23:44:50 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:50 -0500 |
commit | 89fe5dab825a62a0e3fd8d248cbc91c65eb2a426 (patch) | |
tree | bcff14b7888d04a2fec799c59369f6095224bd08 /linden/indra/llmath/llmd5.cpp | |
parent | Second Life viewer sources 1.13.3.2 (diff) | |
download | meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.zip meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.gz meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.bz2 meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.xz |
Second Life viewer sources 1.14.0.0
Diffstat (limited to 'linden/indra/llmath/llmd5.cpp')
-rw-r--r-- | linden/indra/llmath/llmd5.cpp | 71 |
1 files changed, 24 insertions, 47 deletions
diff --git a/linden/indra/llmath/llmd5.cpp b/linden/indra/llmath/llmd5.cpp index 19174af..267381c 100644 --- a/linden/indra/llmath/llmd5.cpp +++ b/linden/indra/llmath/llmd5.cpp | |||
@@ -122,10 +122,18 @@ void LLMD5::update (const uint1 *input, const uint4 input_length) { | |||
122 | // Transform as many times as possible. | 122 | // Transform as many times as possible. |
123 | if (input_length >= buffer_space) { // ie. we have enough to fill the buffer | 123 | if (input_length >= buffer_space) { // ie. we have enough to fill the buffer |
124 | // fill the rest of the buffer and transform | 124 | // fill the rest of the buffer and transform |
125 | memcpy (buffer + buffer_index, input, buffer_space); | 125 | memcpy( /* Flawfinder: ignore */ |
126 | buffer + buffer_index, | ||
127 | input, | ||
128 | buffer_space); | ||
126 | transform (buffer); | 129 | transform (buffer); |
127 | 130 | ||
128 | // now, transform each 64-byte piece of the input, bypassing the buffer | 131 | // now, transform each 64-byte piece of the input, bypassing the buffer |
132 | if (input == NULL || input_length == 0){ | ||
133 | std::cerr << "LLMD5::update: Invalid input!" << std::endl; | ||
134 | return; | ||
135 | } | ||
136 | |||
129 | for (input_index = buffer_space; input_index + 63 < input_length; | 137 | for (input_index = buffer_space; input_index + 63 < input_length; |
130 | input_index += 64) | 138 | input_index += 64) |
131 | transform (input+input_index); | 139 | transform (input+input_index); |
@@ -137,7 +145,7 @@ void LLMD5::update (const uint1 *input, const uint4 input_length) { | |||
137 | 145 | ||
138 | 146 | ||
139 | // and here we do the buffering: | 147 | // and here we do the buffering: |
140 | memcpy(buffer+buffer_index, input+input_index, input_length-input_index); | 148 | memcpy(buffer+buffer_index, input+input_index, input_length-input_index); /* Flawfinder: ignore */ |
141 | } | 149 | } |
142 | 150 | ||
143 | 151 | ||
@@ -145,9 +153,9 @@ void LLMD5::update (const uint1 *input, const uint4 input_length) { | |||
145 | // MD5 update for files. | 153 | // MD5 update for files. |
146 | // Like above, except that it works on files (and uses above as a primitive.) | 154 | // Like above, except that it works on files (and uses above as a primitive.) |
147 | 155 | ||
148 | void LLMD5::update(FILE *file){ | 156 | void LLMD5::update(FILE* file){ |
149 | 157 | ||
150 | unsigned char buffer[1024]; | 158 | unsigned char buffer[1024]; /* Flawfinder: ignore */ |
151 | int len; | 159 | int len; |
152 | 160 | ||
153 | while ( (len=(int)fread(buffer, 1, 1024, file)) ) | 161 | while ( (len=(int)fread(buffer, 1, 1024, file)) ) |
@@ -167,11 +175,11 @@ void LLMD5::update(FILE *file){ | |||
167 | 175 | ||
168 | void LLMD5::update(std::istream& stream){ | 176 | void LLMD5::update(std::istream& stream){ |
169 | 177 | ||
170 | unsigned char buffer[1024]; | 178 | unsigned char buffer[1024]; /* Flawfinder: ignore */ |
171 | int len; | 179 | int len; |
172 | 180 | ||
173 | while (stream.good()){ | 181 | while (stream.good()){ |
174 | stream.read( (char*)buffer, 1024); // note that return value of read is unusable. | 182 | stream.read( (char*)buffer, 1024); /* Flawfinder: ignore */ // note that return value of read is unusable. |
175 | len=stream.gcount(); | 183 | len=stream.gcount(); |
176 | update(buffer, len); | 184 | update(buffer, len); |
177 | } | 185 | } |
@@ -182,35 +190,13 @@ void LLMD5::update(std::istream& stream){ | |||
182 | 190 | ||
183 | 191 | ||
184 | 192 | ||
185 | |||
186 | // MD5 update for ifstreams. | ||
187 | // Like update for files; see above. | ||
188 | |||
189 | void LLMD5::update(llifstream& stream){ | ||
190 | |||
191 | unsigned char buffer[1024]; | ||
192 | int len; | ||
193 | |||
194 | while (stream.good()){ | ||
195 | stream.read( (char*)buffer, 1024); // note that return value of read is unusable. | ||
196 | len=stream.gcount(); | ||
197 | update(buffer, len); | ||
198 | } | ||
199 | |||
200 | } | ||
201 | |||
202 | |||
203 | |||
204 | |||
205 | |||
206 | |||
207 | // MD5 finalization. Ends an MD5 message-digest operation, writing the | 193 | // MD5 finalization. Ends an MD5 message-digest operation, writing the |
208 | // the message digest and zeroizing the context. | 194 | // the message digest and zeroizing the context. |
209 | 195 | ||
210 | 196 | ||
211 | void LLMD5::finalize (){ | 197 | void LLMD5::finalize (){ |
212 | 198 | ||
213 | unsigned char bits[8]; | 199 | unsigned char bits[8]; /* Flawfinder: ignore */ |
214 | unsigned int index, padLen; | 200 | unsigned int index, padLen; |
215 | static uint1 PADDING[64]={ | 201 | static uint1 PADDING[64]={ |
216 | 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 202 | 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
@@ -264,25 +250,16 @@ LLMD5::LLMD5(std::istream& stream){ | |||
264 | finalize(); | 250 | finalize(); |
265 | } | 251 | } |
266 | 252 | ||
267 | |||
268 | |||
269 | LLMD5::LLMD5(llifstream& stream) | ||
270 | { | ||
271 | init(); // must called by all constructors | ||
272 | update (stream); | ||
273 | finalize(); | ||
274 | } | ||
275 | |||
276 | // Digest a string of the format ("%s:%i" % (s, number)) | 253 | // Digest a string of the format ("%s:%i" % (s, number)) |
277 | LLMD5::LLMD5(const unsigned char *string, const unsigned int number) | 254 | LLMD5::LLMD5(const unsigned char *string, const unsigned int number) |
278 | { | 255 | { |
279 | const char *colon = ":"; | 256 | const char *colon = ":"; |
280 | char tbuf[16]; | 257 | char tbuf[16]; /* Flawfinder: ignore */ |
281 | init(); | 258 | init(); |
282 | update(string, (U32)strlen((const char *) string)); | 259 | update(string, (U32)strlen((const char *) string)); /* Flawfinder: ignore */ |
283 | update((const unsigned char *) colon, (U32)strlen(colon)); | 260 | update((const unsigned char *) colon, (U32)strlen(colon)); /* Flawfinder: ignore */ |
284 | sprintf(tbuf, "%i", number); | 261 | snprintf(tbuf, sizeof(tbuf), "%i", number); /* Flawfinder: ignore */ |
285 | update((const unsigned char *) tbuf, (U32)strlen(tbuf)); | 262 | update((const unsigned char *) tbuf, (U32)strlen(tbuf)); /* Flawfinder: ignore */ |
286 | finalize(); | 263 | finalize(); |
287 | } | 264 | } |
288 | 265 | ||
@@ -290,7 +267,7 @@ LLMD5::LLMD5(const unsigned char *string, const unsigned int number) | |||
290 | LLMD5::LLMD5(const unsigned char *s) | 267 | LLMD5::LLMD5(const unsigned char *s) |
291 | { | 268 | { |
292 | init(); | 269 | init(); |
293 | update(s, (U32)strlen((const char *) s)); | 270 | update(s, (U32)strlen((const char *) s)); /* Flawfinder: ignore */ |
294 | finalize(); | 271 | finalize(); |
295 | } | 272 | } |
296 | 273 | ||
@@ -304,7 +281,7 @@ void LLMD5::raw_digest(unsigned char *s) | |||
304 | return; | 281 | return; |
305 | } | 282 | } |
306 | 283 | ||
307 | memcpy(s, digest, 16); | 284 | memcpy(s, digest, 16); /* Flawfinder: ignore */ |
308 | return; | 285 | return; |
309 | } | 286 | } |
310 | 287 | ||
@@ -324,7 +301,7 @@ void LLMD5::hex_digest(char *s) | |||
324 | 301 | ||
325 | for (i=0; i<16; i++) | 302 | for (i=0; i<16; i++) |
326 | { | 303 | { |
327 | sprintf(s+i*2, "%02x", digest[i]); | 304 | sprintf(s+i*2, "%02x", digest[i]); /* Flawfinder: ignore */ |
328 | } | 305 | } |
329 | 306 | ||
330 | s[32]='\0'; | 307 | s[32]='\0'; |
@@ -338,7 +315,7 @@ void LLMD5::hex_digest(char *s) | |||
338 | 315 | ||
339 | std::ostream& operator<<(std::ostream &stream, LLMD5 context) | 316 | std::ostream& operator<<(std::ostream &stream, LLMD5 context) |
340 | { | 317 | { |
341 | char s[33]; | 318 | char s[33]; /* Flawfinder: ignore */ |
342 | context.hex_digest(s); | 319 | context.hex_digest(s); |
343 | stream << s; | 320 | stream << s; |
344 | return stream; | 321 | return stream; |