mirror of
https://github.com/Cisco-Talos/clamav.git
synced 2025-10-19 18:33:16 +00:00
fix MD5 handling
git-svn: trunk@2704
This commit is contained in:
parent
684fe963f8
commit
2a9e6ac823
8 changed files with 43 additions and 38 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Mon Feb 12 11:44:21 CET 2007 (tk)
|
||||||
|
---------------------------------
|
||||||
|
* libclamav/md5.c: revert problematic cleanup changes and rename functions
|
||||||
|
to prevent possible namespace clashes with other libraries
|
||||||
|
|
||||||
Sun Feb 11 11:19:57 CET 2007 (tk)
|
Sun Feb 11 11:19:57 CET 2007 (tk)
|
||||||
---------------------------------
|
---------------------------------
|
||||||
* freshclam: add option ScriptedUpdates, requested by Luca
|
* freshclam: add option ScriptedUpdates, requested by Luca
|
||||||
|
|
|
@ -298,7 +298,7 @@ int cli_ncore_scanbuff(const char *buffer, unsigned int length, const char **vir
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cli_ncore_scandesc(int desc, cli_ctx *ctx, unsigned short ftype, int *cont, unsigned int *targettab, MD5_CTX *md5ctx)
|
int cli_ncore_scandesc(int desc, cli_ctx *ctx, unsigned short ftype, int *cont, unsigned int *targettab, cli_md5_ctx *md5ctx)
|
||||||
{
|
{
|
||||||
void *streamhandle;
|
void *streamhandle;
|
||||||
void *resulthandle;
|
void *resulthandle;
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
int cli_ncore_scanbuff(const char *buffer, unsigned int length, const char **virname, const struct cl_engine *engine, unsigned short ftype, unsigned int *targettab);
|
int cli_ncore_scanbuff(const char *buffer, unsigned int length, const char **virname, const struct cl_engine *engine, unsigned short ftype, unsigned int *targettab);
|
||||||
|
|
||||||
int cli_ncore_scandesc(int desc, cli_ctx *ctx, unsigned short ftype, int *cont, unsigned int *targettab, MD5_CTX *md5ctx);
|
int cli_ncore_scandesc(int desc, cli_ctx *ctx, unsigned short ftype, int *cont, unsigned int *targettab, cli_md5_ctx *md5ctx);
|
||||||
|
|
||||||
int cli_ncore_load(const char *filename, struct cl_engine **engine, unsigned int *signo, unsigned int options);
|
int cli_ncore_load(const char *filename, struct cl_engine **engine, unsigned int *signo, unsigned int options);
|
||||||
|
|
||||||
|
|
|
@ -282,7 +282,7 @@ int cli_scandesc(int desc, cli_ctx *ctx, unsigned short otfrec, cli_file_t ftype
|
||||||
unsigned int buffersize, length, maxpatlen, shift = 0;
|
unsigned int buffersize, length, maxpatlen, shift = 0;
|
||||||
unsigned long int offset = 0;
|
unsigned long int offset = 0;
|
||||||
struct cli_ac_data gdata, tdata;
|
struct cli_ac_data gdata, tdata;
|
||||||
MD5_CTX md5ctx;
|
cli_md5_ctx md5ctx;
|
||||||
unsigned char digest[16];
|
unsigned char digest[16];
|
||||||
struct cli_md5_node *md5_node;
|
struct cli_md5_node *md5_node;
|
||||||
struct cli_matcher *groot = NULL, *troot = NULL;
|
struct cli_matcher *groot = NULL, *troot = NULL;
|
||||||
|
@ -343,7 +343,7 @@ int cli_scandesc(int desc, cli_ctx *ctx, unsigned short otfrec, cli_file_t ftype
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!ftonly && ctx->engine->md5_hlist)
|
if(!ftonly && ctx->engine->md5_hlist)
|
||||||
MD5_Init(&md5ctx);
|
cli_md5_init(&md5ctx);
|
||||||
|
|
||||||
buff = buffer;
|
buff = buffer;
|
||||||
buff += maxpatlen; /* pointer to read data block */
|
buff += maxpatlen; /* pointer to read data block */
|
||||||
|
@ -400,7 +400,7 @@ int cli_scandesc(int desc, cli_ctx *ctx, unsigned short otfrec, cli_file_t ftype
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ctx->engine->md5_hlist)
|
if(ctx->engine->md5_hlist)
|
||||||
MD5_Update(&md5ctx, buff + shift, bytes);
|
cli_md5_update(&md5ctx, buff + shift, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(bytes + shift == SCANBUFF) {
|
if(bytes + shift == SCANBUFF) {
|
||||||
|
@ -427,7 +427,7 @@ int cli_scandesc(int desc, cli_ctx *ctx, unsigned short otfrec, cli_file_t ftype
|
||||||
cli_ac_freedata(&tdata);
|
cli_ac_freedata(&tdata);
|
||||||
|
|
||||||
if(!ftonly && ctx->engine->md5_hlist) {
|
if(!ftonly && ctx->engine->md5_hlist) {
|
||||||
MD5_Final(digest, &md5ctx);
|
cli_md5_final(digest, &md5ctx);
|
||||||
|
|
||||||
if((md5_node = cli_vermd5(digest, ctx->engine)) && !md5_node->fp) {
|
if((md5_node = cli_vermd5(digest, ctx->engine)) && !md5_node->fp) {
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
|
|
@ -49,16 +49,16 @@
|
||||||
*/
|
*/
|
||||||
#if defined(__i386__) || defined(__x86_64__) || defined(__vax__)
|
#if defined(__i386__) || defined(__x86_64__) || defined(__vax__)
|
||||||
#define SET(n) \
|
#define SET(n) \
|
||||||
(*(const MD5_u32plus *)(&ptr[(n) * 4]))
|
(*(MD5_u32plus *)&ptr[(n) * 4])
|
||||||
#define GET(n) \
|
#define GET(n) \
|
||||||
SET(n)
|
SET(n)
|
||||||
#else
|
#else
|
||||||
#define SET(n) \
|
#define SET(n) \
|
||||||
(ctx->block[(n)] = \
|
(ctx->block[(n)] = \
|
||||||
(const MD5_u32plus)ptr[(n) * 4] | \
|
(MD5_u32plus)ptr[(n) * 4] | \
|
||||||
((const MD5_u32plus)ptr[(n) * 4 + 1] << 8) | \
|
((MD5_u32plus)ptr[(n) * 4 + 1] << 8) | \
|
||||||
((const MD5_u32plus)ptr[(n) * 4 + 2] << 16) | \
|
((MD5_u32plus)ptr[(n) * 4 + 2] << 16) | \
|
||||||
((const MD5_u32plus)ptr[(n) * 4 + 3] << 24))
|
((MD5_u32plus)ptr[(n) * 4 + 3] << 24))
|
||||||
#define GET(n) \
|
#define GET(n) \
|
||||||
(ctx->block[(n)])
|
(ctx->block[(n)])
|
||||||
#endif
|
#endif
|
||||||
|
@ -67,9 +67,9 @@
|
||||||
* This processes one or more 64-byte data blocks, but does NOT update
|
* This processes one or more 64-byte data blocks, but does NOT update
|
||||||
* the bit counters. There are no alignment requirements.
|
* the bit counters. There are no alignment requirements.
|
||||||
*/
|
*/
|
||||||
static const void *body(MD5_CTX *ctx, const void *data, unsigned long size)
|
static void *body(cli_md5_ctx *ctx, void *data, unsigned long size)
|
||||||
{
|
{
|
||||||
const unsigned char *ptr;
|
unsigned char *ptr;
|
||||||
MD5_u32plus a, b, c, d;
|
MD5_u32plus a, b, c, d;
|
||||||
MD5_u32plus saved_a, saved_b, saved_c, saved_d;
|
MD5_u32plus saved_a, saved_b, saved_c, saved_d;
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ static const void *body(MD5_CTX *ctx, const void *data, unsigned long size)
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MD5_Init(MD5_CTX *ctx)
|
void cli_md5_init(cli_md5_ctx *ctx)
|
||||||
{
|
{
|
||||||
ctx->a = 0x67452301;
|
ctx->a = 0x67452301;
|
||||||
ctx->b = 0xefcdab89;
|
ctx->b = 0xefcdab89;
|
||||||
|
@ -185,7 +185,7 @@ void MD5_Init(MD5_CTX *ctx)
|
||||||
ctx->hi = 0;
|
ctx->hi = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size)
|
void cli_md5_update(cli_md5_ctx *ctx, void *data, unsigned long size)
|
||||||
{
|
{
|
||||||
MD5_u32plus saved_lo;
|
MD5_u32plus saved_lo;
|
||||||
unsigned long used, free;
|
unsigned long used, free;
|
||||||
|
@ -206,7 +206,7 @@ void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size)
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&ctx->buffer[used], data, free);
|
memcpy(&ctx->buffer[used], data, free);
|
||||||
data = (const unsigned char *)data + free;
|
data = (unsigned char *)data + free;
|
||||||
size -= free;
|
size -= free;
|
||||||
body(ctx, ctx->buffer, 64);
|
body(ctx, ctx->buffer, 64);
|
||||||
}
|
}
|
||||||
|
@ -219,7 +219,7 @@ void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size)
|
||||||
memcpy(ctx->buffer, data, size);
|
memcpy(ctx->buffer, data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MD5_Final(unsigned char *result, MD5_CTX *ctx)
|
void cli_md5_final(unsigned char *result, cli_md5_ctx *ctx)
|
||||||
{
|
{
|
||||||
unsigned long used, free;
|
unsigned long used, free;
|
||||||
|
|
||||||
|
|
|
@ -19,10 +19,10 @@ typedef struct {
|
||||||
MD5_u32plus a, b, c, d;
|
MD5_u32plus a, b, c, d;
|
||||||
unsigned char buffer[64];
|
unsigned char buffer[64];
|
||||||
MD5_u32plus block[16];
|
MD5_u32plus block[16];
|
||||||
} MD5_CTX;
|
} cli_md5_ctx;
|
||||||
|
|
||||||
extern void MD5_Init(MD5_CTX *ctx);
|
extern void cli_md5_init(cli_md5_ctx *ctx);
|
||||||
extern void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size);
|
extern void cli_md5_update(cli_md5_ctx *ctx, void *data, unsigned long size);
|
||||||
extern void MD5_Final(unsigned char *result, MD5_CTX *ctx);
|
extern void cli_md5_final(unsigned char *result, cli_md5_ctx *ctx);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -234,19 +234,19 @@ unsigned char *cli_md5digest(int desc)
|
||||||
{
|
{
|
||||||
unsigned char *digest;
|
unsigned char *digest;
|
||||||
char buff[FILEBUFF];
|
char buff[FILEBUFF];
|
||||||
MD5_CTX ctx;
|
cli_md5_ctx ctx;
|
||||||
int bytes;
|
int bytes;
|
||||||
|
|
||||||
|
|
||||||
if(!(digest = cli_malloc(16)))
|
if(!(digest = cli_malloc(16)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
MD5_Init(&ctx);
|
cli_md5_init(&ctx);
|
||||||
|
|
||||||
while((bytes = cli_readn(desc, buff, FILEBUFF)))
|
while((bytes = cli_readn(desc, buff, FILEBUFF)))
|
||||||
MD5_Update(&ctx, buff, bytes);
|
cli_md5_update(&ctx, buff, bytes);
|
||||||
|
|
||||||
MD5_Final(digest, &ctx);
|
cli_md5_final(digest, &ctx);
|
||||||
|
|
||||||
return digest;
|
return digest;
|
||||||
}
|
}
|
||||||
|
@ -255,17 +255,17 @@ char *cli_md5stream(FILE *fs, unsigned char *digcpy)
|
||||||
{
|
{
|
||||||
unsigned char digest[16];
|
unsigned char digest[16];
|
||||||
char buff[FILEBUFF];
|
char buff[FILEBUFF];
|
||||||
MD5_CTX ctx;
|
cli_md5_ctx ctx;
|
||||||
char *md5str, *pt;
|
char *md5str, *pt;
|
||||||
int i, bytes;
|
int i, bytes;
|
||||||
|
|
||||||
|
|
||||||
MD5_Init(&ctx);
|
cli_md5_init(&ctx);
|
||||||
|
|
||||||
while((bytes = fread(buff, 1, FILEBUFF, fs)))
|
while((bytes = fread(buff, 1, FILEBUFF, fs)))
|
||||||
MD5_Update(&ctx, buff, bytes);
|
cli_md5_update(&ctx, buff, bytes);
|
||||||
|
|
||||||
MD5_Final(digest, &ctx);
|
cli_md5_final(digest, &ctx);
|
||||||
|
|
||||||
if(!(md5str = (char *) cli_calloc(32 + 1, sizeof(char))))
|
if(!(md5str = (char *) cli_calloc(32 + 1, sizeof(char))))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -303,13 +303,13 @@ static char *cli_md5buff(const char *buffer, unsigned int len, unsigned char *di
|
||||||
{
|
{
|
||||||
unsigned char digest[16];
|
unsigned char digest[16];
|
||||||
char *md5str, *pt;
|
char *md5str, *pt;
|
||||||
MD5_CTX ctx;
|
cli_md5_ctx ctx;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
|
||||||
MD5_Init(&ctx);
|
cli_md5_init(&ctx);
|
||||||
MD5_Update(&ctx, (const unsigned char *) buffer, len);
|
cli_md5_update(&ctx, (const unsigned char *) buffer, len);
|
||||||
MD5_Final(digest, &ctx);
|
cli_md5_final(digest, &ctx);
|
||||||
|
|
||||||
if(dig)
|
if(dig)
|
||||||
memcpy(dig, digest, 16);
|
memcpy(dig, digest, 16);
|
||||||
|
|
|
@ -198,7 +198,7 @@ static unsigned int cli_md5sect(int fd, uint32_t offset, uint32_t size, unsigned
|
||||||
size_t bread, sum = 0;
|
size_t bread, sum = 0;
|
||||||
off_t pos;
|
off_t pos;
|
||||||
char buff[FILEBUFF];
|
char buff[FILEBUFF];
|
||||||
MD5_CTX md5ctx;
|
cli_md5_ctx md5ctx;
|
||||||
|
|
||||||
|
|
||||||
if((pos = lseek(fd, 0, SEEK_CUR)) == -1) {
|
if((pos = lseek(fd, 0, SEEK_CUR)) == -1) {
|
||||||
|
@ -212,19 +212,19 @@ static unsigned int cli_md5sect(int fd, uint32_t offset, uint32_t size, unsigned
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
MD5_Init(&md5ctx);
|
cli_md5_init(&md5ctx);
|
||||||
|
|
||||||
while((bread = cli_readn(fd, buff, FILEBUFF)) > 0) {
|
while((bread = cli_readn(fd, buff, FILEBUFF)) > 0) {
|
||||||
if(sum + bread >= size) {
|
if(sum + bread >= size) {
|
||||||
MD5_Update(&md5ctx, buff, size - sum);
|
cli_md5_update(&md5ctx, buff, size - sum);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
MD5_Update(&md5ctx, buff, bread);
|
cli_md5_update(&md5ctx, buff, bread);
|
||||||
sum += bread;
|
sum += bread;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MD5_Final(digest, &md5ctx);
|
cli_md5_final(digest, &md5ctx);
|
||||||
lseek(fd, pos, SEEK_SET);
|
lseek(fd, pos, SEEK_SET);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue