aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorEugene Sandulenko2004-12-22 13:34:28 +0000
committerEugene Sandulenko2004-12-22 13:34:28 +0000
commit7606a53f09a06f33fb5953c55bf3b488d6f5119a (patch)
tree6a3da91b956e20d9d519b6971831b255c2bc7f80 /common
parent2fb8a8e45369b000b9f36d2433425ca48f6d9d13 (diff)
downloadscummvm-rg350-7606a53f09a06f33fb5953c55bf3b488d6f5119a.tar.gz
scummvm-rg350-7606a53f09a06f33fb5953c55bf3b488d6f5119a.tar.bz2
scummvm-rg350-7606a53f09a06f33fb5953c55bf3b488d6f5119a.zip
Now it is possible to count MD5 only for specified amount of bytes from file.
It is useful for MD5'ing hunge files. svn-id: r16259
Diffstat (limited to 'common')
-rw-r--r--common/md5.cpp18
-rw-r--r--common/md5.h2
2 files changed, 17 insertions, 3 deletions
diff --git a/common/md5.cpp b/common/md5.cpp
index 55b2aef79a..7d5037d8c8 100644
--- a/common/md5.cpp
+++ b/common/md5.cpp
@@ -239,12 +239,14 @@ void md5_finish( md5_context *ctx, uint8 digest[16] )
PUT_UINT32( ctx->state[3], digest, 12 );
}
-bool md5_file( const char *name, uint8 digest[16], const char *directory )
+bool md5_file( const char *name, uint8 digest[16], const char *directory, uint32 length )
{
File f;
md5_context ctx;
int i;
unsigned char buf[1000];
+ bool restricted = (length != 0);
+ int readlen;
f.open(name, File::kFileReadMode, directory);
if( ! f.isOpen() )
@@ -253,11 +255,23 @@ bool md5_file( const char *name, uint8 digest[16], const char *directory )
return false;
}
+ if( ! restricted || sizeof( buf ) <= length )
+ readlen = sizeof( buf );
+ else
+ readlen = length;
+
md5_starts( &ctx );
- while( ( i = f.read( buf, sizeof( buf ) ) ) > 0 )
+ while( ( i = f.read( buf, readlen ) ) > 0 )
{
md5_update( &ctx, buf, i );
+
+ length -= i;
+ if( restricted && length == 0 )
+ break;
+
+ if( restricted && sizeof( buf ) > length )
+ readlen = length;
}
md5_finish( &ctx, digest );
diff --git a/common/md5.h b/common/md5.h
index fe83ebda84..4fc453f086 100644
--- a/common/md5.h
+++ b/common/md5.h
@@ -35,6 +35,6 @@ void md5_starts( md5_context *ctx );
void md5_update( md5_context *ctx, const uint8 *input, uint32 length );
void md5_finish( md5_context *ctx, uint8 digest[16] );
-bool md5_file( const char *name, uint8 digest[16], const char *directory = NULL );
+bool md5_file( const char *name, uint8 digest[16], const char *directory = NULL, uint32 length = 0 );
#endif