Amazing this hasn't resulted in bugs. The prototype for all the update
functions takes a size_t argument, not an unsigned int.
Index: md5.c
===================================================================
RCS file: /cvs/src/bin/md5/md5.c,v
retrieving revision 1.84
diff -u -p -r1.84 md5.c
--- md5.c 9 Dec 2015 19:36:17 -0000 1.84
+++ md5.c 28 Jul 2016 03:55:22 -0000
@@ -68,7 +68,7 @@ struct hash_function {
int base64;
void *ctx; /* XXX - only used by digest_file() */
void (*init)(void *);
- void (*update)(void *, const unsigned char *, unsigned int);
+ void (*update)(void *, const unsigned char *, size_t);
void (*final)(unsigned char *, void *);
char * (*end)(void *, char *);
TAILQ_ENTRY(hash_function) tailq;
@@ -81,7 +81,7 @@ struct hash_function {
-1,
NULL,
(void (*)(void *))CKSUM_Init,
- (void (*)(void *, const unsigned char *, unsigned
int))CKSUM_Update,
+ (void (*)(void *, const unsigned char *, size_t))CKSUM_Update,
(void (*)(unsigned char *, void *))CKSUM_Final,
(char *(*)(void *, char *))CKSUM_End
},
@@ -92,7 +92,7 @@ struct hash_function {
0,
NULL,
(void (*)(void *))MD5Init,
- (void (*)(void *, const unsigned char *, unsigned
int))MD5Update,
+ (void (*)(void *, const unsigned char *, size_t))MD5Update,
(void (*)(unsigned char *, void *))MD5Final,
(char *(*)(void *, char *))MD5End
},
@@ -103,7 +103,7 @@ struct hash_function {
0,
NULL,
(void (*)(void *))RMD160Init,
- (void (*)(void *, const unsigned char *, unsigned
int))RMD160Update,
+ (void (*)(void *, const unsigned char *, size_t))RMD160Update,
(void (*)(unsigned char *, void *))RMD160Final,
(char *(*)(void *, char *))RMD160End
},
@@ -114,7 +114,7 @@ struct hash_function {
0,
NULL,
(void (*)(void *))SHA1Init,
- (void (*)(void *, const unsigned char *, unsigned
int))SHA1Update,
+ (void (*)(void *, const unsigned char *, size_t))SHA1Update,
(void (*)(unsigned char *, void *))SHA1Final,
(char *(*)(void *, char *))SHA1End
},
@@ -125,7 +125,7 @@ struct hash_function {
0,
NULL,
(void (*)(void *))SHA224Init,
- (void (*)(void *, const unsigned char *, unsigned
int))SHA224Update,
+ (void (*)(void *, const unsigned char *, size_t))SHA224Update,
(void (*)(unsigned char *, void *))SHA224Final,
(char *(*)(void *, char *))SHA224End
},
@@ -137,7 +137,7 @@ struct hash_function {
0,
NULL,
(void (*)(void *))SHA256Init,
- (void (*)(void *, const unsigned char *, unsigned
int))SHA256Update,
+ (void (*)(void *, const unsigned char *, size_t))SHA256Update,
(void (*)(unsigned char *, void *))SHA256Final,
(char *(*)(void *, char *))SHA256End
},
@@ -149,7 +149,7 @@ struct hash_function {
0,
NULL,
(void (*)(void *))SHA384Init,
- (void (*)(void *, const unsigned char *, unsigned
int))SHA384Update,
+ (void (*)(void *, const unsigned char *, size_t))SHA384Update,
(void (*)(unsigned char *, void *))SHA384Final,
(char *(*)(void *, char *))SHA384End
},
@@ -161,7 +161,7 @@ struct hash_function {
0,
NULL,
(void (*)(void *))SHA512Init,
- (void (*)(void *, const unsigned char *, unsigned
int))SHA512Update,
+ (void (*)(void *, const unsigned char *, size_t))SHA512Update,
(void (*)(unsigned char *, void *))SHA512Final,
(char *(*)(void *, char *))SHA512End
},
@@ -423,7 +423,7 @@ digest_string(char *string, struct hash_
TAILQ_FOREACH(hf, hl, tailq) {
hf->init(&context);
- hf->update(&context, string, (unsigned int)strlen(string));
+ hf->update(&context, string, strlen(string));
digest_end(hf, &context, digest, sizeof(digest),
hf->base64);
digest_printstr(hf, string, digest);
@@ -495,7 +495,7 @@ digest_file(const char *file, struct has
err(1, "stdout: write error");
}
TAILQ_FOREACH(hf, hl, tailq)
- hf->update(hf->ctx, data, (unsigned int)nread);
+ hf->update(hf->ctx, data, nread);
}
if (ferror(fp)) {
warn("%s: read error", file);
@@ -683,7 +683,7 @@ digest_filelist(const char *file, struct
hf->init(&context);
while ((nread = fread(data, 1UL, sizeof(data), fp)) > 0)
- hf->update(&context, data, (unsigned int)nread);
+ hf->update(&context, data, nread);
if (ferror(fp)) {
warn("%s: read error", file);
error = 1;
@@ -743,7 +743,7 @@ digest_time(struct hash_list *hl, int ti
gettimeofday(&start, NULL);
hf->init(&context);
for (i = 0; i < count; i++)
- hf->update(&context, data, TEST_BLOCK_LEN);
+ hf->update(&context, data, (size_t)TEST_BLOCK_LEN);
digest_end(hf, &context, digest, sizeof(digest), hf->base64);
gettimeofday(&stop, NULL);
timersub(&stop, &start, &res);
@@ -782,8 +782,8 @@ digest_test(struct hash_list *hl)
for (i = 0; i < 8; i++) {
hf->init(&context);
- hf->update((void *)&context, test_strings[i],
- (unsigned int)strlen(test_strings[i]));
+ hf->update(&context, test_strings[i],
+ strlen(test_strings[i]));
digest_end(hf, &context, digest, sizeof(digest),
hf->base64);
digest_printstr(hf, test_strings[i], digest);
@@ -793,8 +793,7 @@ digest_test(struct hash_list *hl)
memset(buf, 'a', sizeof(buf));
hf->init(&context);
for (i = 0; i < 1000; i++)
- hf->update(&context, buf,
- (unsigned int)sizeof(buf));
+ hf->update(&context, buf, sizeof(buf));
digest_end(hf, &context, digest, sizeof(digest), hf->base64);
digest_print(hf, "one million 'a' characters",
digest);