Merge branch 'md4_cleanup' of git://github.com/krajaratnam/ccache

* 'md4_cleanup' of git://github.com/krajaratnam/ccache:
  use size_t when we refer to memory sizes
  Remove unused 'void mdfour(unsigned char *out, const unsigned char *in, int n)'
  Remove incorrect assumption
  Remove disabled md4 test code
This commit is contained in:
Joel Rosdahl 2010-02-23 22:08:22 +01:00
commit ef8079b953
5 changed files with 12 additions and 109 deletions

View File

@ -56,7 +56,7 @@ int hash_fd(struct mdfour *md, int fd);
int hash_file(struct mdfour *md, const char *fname);
char *hash_result(struct mdfour *md);
void hash_result_as_bytes(struct mdfour *md, unsigned char *out);
void hash_buffer(struct mdfour *md, const char *s, int len);
void hash_buffer(struct mdfour *md, const char *s, size_t len);
void cc_log(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
void fatal(const char *format, ...) ATTR_FORMAT(printf, 1, 2);

4
hash.c
View File

@ -25,7 +25,7 @@
#include <string.h>
#include <unistd.h>
void hash_buffer(struct mdfour *md, const char *s, int len)
void hash_buffer(struct mdfour *md, const char *s, size_t len)
{
mdfour_update(md, (unsigned char *)s, len);
}
@ -51,7 +51,7 @@ void hash_int(struct mdfour *md, int x)
int hash_fd(struct mdfour *md, int fd)
{
char buf[1024];
int n;
size_t n;
while ((n = read(fd, buf, sizeof(buf))) > 0) {
hash_buffer(md, buf, n);

105
mdfour.c
View File

@ -21,10 +21,7 @@
#include <string.h>
/* NOTE: This code makes no attempt to be fast!
It assumes that a int is at least 32 bits long
*/
/* NOTE: This code makes no attempt to be fast! */
static struct mdfour *m;
@ -113,7 +110,7 @@ void mdfour_begin(struct mdfour *md)
}
static void mdfour_tail(const unsigned char *in, int n)
static void mdfour_tail(const unsigned char *in, size_t n)
{
unsigned char buf[128];
uint32_t M[16];
@ -140,7 +137,7 @@ static void mdfour_tail(const unsigned char *in, int n)
}
}
void mdfour_update(struct mdfour *md, const unsigned char *in, int n)
void mdfour_update(struct mdfour *md, const unsigned char *in, size_t n)
{
uint32_t M[16];
@ -152,7 +149,7 @@ void mdfour_update(struct mdfour *md, const unsigned char *in, int n)
}
if (md->tail_len) {
int len = 64 - md->tail_len;
size_t len = 64 - md->tail_len;
if (len > n) len = n;
memcpy(md->tail+md->tail_len, in, len);
md->tail_len += len;
@ -190,97 +187,3 @@ void mdfour_result(struct mdfour *md, unsigned char *out)
copy4(out+8, m->C);
copy4(out+12, m->D);
}
void mdfour(unsigned char *out, const unsigned char *in, int n)
{
struct mdfour md;
mdfour_begin(&md);
mdfour_update(&md, in, n);
mdfour_update(&md, NULL, 0);
mdfour_result(&md, out);
}
#ifdef TEST_MDFOUR
static void file_checksum1(char *fname)
{
int fd, i;
struct mdfour md;
unsigned char buf[1024], sum[16];
unsigned chunk;
fd = open(fname,O_RDONLY|O_BINARY);
if (fd == -1) {
perror("fname");
exit(1);
}
chunk = 1 + random() % (sizeof(buf) - 1);
mdfour_begin(&md);
while (1) {
int n = read(fd, buf, chunk);
if (n >= 0) {
mdfour_update(&md, buf, n);
}
if (n < chunk) break;
}
close(fd);
mdfour_update(&md, NULL, 0);
mdfour_result(&md, sum);
for (i=0;i<16;i++)
printf("%02x", sum[i]);
printf("\n");
}
#if 0
#include "../md4.h"
static void file_checksum2(char *fname)
{
int fd, i;
MDstruct md;
unsigned char buf[64], sum[16];
fd = open(fname,O_RDONLY|O_BINARY);
if (fd == -1) {
perror("fname");
exit(1);
}
MDbegin(&md);
while (1) {
int n = read(fd, buf, sizeof(buf));
if (n <= 0) break;
MDupdate(&md, buf, n*8);
}
if (!md.done) {
MDupdate(&md, buf, 0);
}
close(fd);
memcpy(sum, md.buffer, 16);
for (i=0;i<16;i++)
printf("%02x", sum[i]);
printf("\n");
}
#endif
int main(int argc, char *argv[])
{
file_checksum1(argv[1]);
#if 0
file_checksum2(argv[1]);
#endif
return 0;
}
#endif

View File

@ -22,18 +22,18 @@
#ifndef MDFOUR_H
#define MDFOUR_H
#include <stddef.h>
#include <inttypes.h>
struct mdfour {
uint32_t A, B, C, D;
uint32_t totalN;
size_t totalN;
unsigned char tail[64];
unsigned tail_len;
size_t tail_len;
};
void mdfour_begin(struct mdfour *md);
void mdfour_update(struct mdfour *md, const unsigned char *in, int n);
void mdfour_update(struct mdfour *md, const unsigned char *in, size_t n);
void mdfour_result(struct mdfour *md, unsigned char *out);
void mdfour(unsigned char *out, const unsigned char *in, int n);
#endif

View File

@ -102,7 +102,7 @@ static void build_table(void)
static void pushchar(struct mdfour *hash, unsigned char c)
{
static unsigned char buf[64];
static int len;
static size_t len;
if (c == 0) {
if (len > 0) {