talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit c915b6861862a59d97de0e99a4d5c52533df5560
parent ca454566da5e5219f277c0b671335ca22b19cf0d
Author: Paul Mangan <paul@claws-mail.org>
Date:   Fri, 23 May 2008 13:33:40 +0000

2008-05-23 [paul]	3.4.0cvs65

	* src/common/md5.c
	* src/common/md5.h
		add the possibility to check md5 on binary files,
		thanks to Colin

Diffstat:
MChangeLog | 7+++++++
MPATCHSETS | 1+
Mconfigure.ac | 2+-
Msrc/common/md5.c | 47+++++++++++++++++++++++++++++++++++++++++++++--
Msrc/common/md5.h | 3++-
5 files changed, 56 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,10 @@ +2008-05-23 [paul] 3.4.0cvs65 + + * src/common/md5.c + * src/common/md5.h + add the possibility to check md5 on binary files, + thanks to Colin + 2008-05-23 [colin] 3.4.0cvs64 * src/mainwindow.c diff --git a/PATCHSETS b/PATCHSETS @@ -3360,3 +3360,4 @@ ( cvs diff -u -r 1.155.2.85 -r 1.155.2.86 src/Makefile.am; cvs diff -u -r 1.30.2.50 -r 1.30.2.51 src/prefs_toolbar.c; cvs diff -u -r 1.25.2.55 -r 1.25.2.56 src/stock_pixmap.c; cvs diff -u -r 1.18.2.34 -r 1.18.2.35 src/stock_pixmap.h; cvs diff -u -r 1.43.2.99 -r 1.43.2.100 src/toolbar.c; diff -u /dev/null src/pixmaps/delete_btn.xpm; cvs diff -u -r 1.1.2.1 -r 1.1.2.2 src/pixmaps/insert_file.xpm; diff -u /dev/null src/pixmaps/mail_reply_to_list.xpm; ) > 3.4.0cvs62.patchset ( cvs diff -u -r 1.1.4.51 -r 1.1.4.52 src/prefs_filtering_action.c; cvs diff -u -r 1.1.2.13 -r 1.1.2.14 src/gtk/combobox.c; cvs diff -u -r 1.1.2.11 -r 1.1.2.12 src/gtk/combobox.h; ) > 3.4.0cvs63.patchset ( cvs diff -u -r 1.274.2.243 -r 1.274.2.244 src/mainwindow.c; cvs diff -u -r 1.395.2.368 -r 1.395.2.369 src/summaryview.c; ) > 3.4.0cvs64.patchset +( cvs diff -u -r 1.2.2.4 -r 1.2.2.5 src/common/md5.c; cvs diff -u -r 1.1.4.3 -r 1.1.4.4 src/common/md5.h; ) > 3.4.0cvs65.patchset diff --git a/configure.ac b/configure.ac @@ -11,7 +11,7 @@ MINOR_VERSION=4 MICRO_VERSION=0 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=64 +EXTRA_VERSION=65 EXTRA_RELEASE= EXTRA_GTK2_VERSION= diff --git a/src/common/md5.c b/src/common/md5.c @@ -34,8 +34,12 @@ #include <stdlib.h> #include <string.h> #include <assert.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> #include "md5.h" +#include "utils.h" /**************** * Rotate a 32 bit integer by n bytes @@ -328,20 +332,59 @@ md5_final(unsigned char *digest, MD5_CONTEXT *ctx) * string S. hextdigest but be buffer of at lease 33 bytes! */ void -md5_hex_digest(char *hexdigest, const unsigned char *s) +md5_hex_digest_binary(char *hexdigest, const unsigned char *s, size_t len) { int i; MD5_CONTEXT context; unsigned char digest[16]; md5_init(&context); - md5_update(&context, s, strlen(s)); + md5_update(&context, s, len); md5_final(digest, &context); for (i = 0; i < 16; i++) sprintf(hexdigest + 2 * i, "%02x", digest[i]); } +int +md5_hex_digest_file(char *hexdigest, const unsigned char *file) +{ + int READ_BLOCK_SIZE=4096; + int len; + char *buf = malloc(READ_BLOCK_SIZE); /* alloc the first block */ + char *lastp = buf; /* point to the start of the buffer */ + size_t total = 0; /* total length read */ + int num_alloc = 1; /* number of blocks allocated */ + int fd = open(file, O_RDONLY); + + if (fd == -1) { + FILE_OP_ERROR(file, "open"); + return -1; + } + + while ((len = read(fd, lastp, READ_BLOCK_SIZE)) > 0) { /* read one block (which is allocated) */ + total += len; /* update the total length */ + num_alloc++; /* increase number of allocs */ + buf = realloc(buf, READ_BLOCK_SIZE*num_alloc); /* allocate one more block for next read */ + lastp = buf+total; /* point to the end of read stuff to buf */ + } + + close(fd); + md5_hex_digest_binary(hexdigest, buf, total); + free(buf); + // printf("%s %s\n", hexdigest, file); + return 0; +} + +/* + * Creates a MD5 digest in hex fomrat (lowercase letters) from the + * string S. hextdigest but be buffer of at lease 33 bytes! + */ +void +md5_hex_digest(char *hexdigest, const unsigned char *s) +{ + md5_hex_digest_binary(hexdigest, s, strlen(s)); +} /* ** Function: md5_hmac diff --git a/src/common/md5.h b/src/common/md5.h @@ -32,7 +32,8 @@ typedef struct { /* Hmm, should be private */ } MD5_CONTEXT; void md5_hex_digest(char *hexdigest, const unsigned char *s); - +void md5_hex_digest_binary(char *hexdigest, const unsigned char *s, size_t len); +int md5_hex_digest_file(char *hexdigest, const unsigned char *file); void md5_hex_hmac(char *hexdigest, const unsigned char* text, int text_len, const unsigned char* key, int key_len);