1 diff -ur busybox.old/coreutils/md5_sha1_sum.c busybox.dev/coreutils/md5_sha1_sum.c
2 --- busybox.old/coreutils/md5_sha1_sum.c 2007-01-19 22:23:05.000000000 +0100
3 +++ busybox.dev/coreutils/md5_sha1_sum.c 2007-01-22 13:24:51.000000000 +0100
8 -typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
14 -/* This might be useful elsewhere */
15 -static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
16 - unsigned hash_length)
18 - /* xzalloc zero-terminates */
19 - char *hex_value = xzalloc((hash_length * 2) + 1);
20 - bin2hex(hex_value, (char*)hash_value, hash_length);
24 -static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
26 - int src_fd, hash_len, count;
31 - uint8_t *hash_value = NULL;
32 - RESERVE_CONFIG_UBUFFER(in_buf, 4096);
33 - void (*update)(const void*, size_t, void*);
34 - void (*final)(void*, void*);
36 - src_fd = STDIN_FILENO;
37 - if (NOT_LONE_DASH(filename)) {
38 - src_fd = open(filename, O_RDONLY);
40 - bb_perror_msg("%s", filename);
45 - /* figure specific hash algorithims */
46 - if (ENABLE_MD5SUM && hash_algo==HASH_MD5) {
47 - md5_begin(&context.md5);
48 - update = (void (*)(const void*, size_t, void*))md5_hash;
49 - final = (void (*)(void*, void*))md5_end;
51 - } else if (ENABLE_SHA1SUM && hash_algo==HASH_SHA1) {
52 - sha1_begin(&context.sha1);
53 - update = (void (*)(const void*, size_t, void*))sha1_hash;
54 - final = (void (*)(void*, void*))sha1_end;
57 - bb_error_msg_and_die("algorithm not supported");
60 - while (0 < (count = safe_read(src_fd, in_buf, 4096))) {
61 - update(in_buf, count, &context);
65 - final(in_buf, &context);
66 - hash_value = hash_bin_to_hex(in_buf, hash_len);
69 - RELEASE_CONFIG_BUFFER(in_buf);
71 - if (src_fd != STDIN_FILENO) {
78 int md5_sha1_sum_main(int argc, char **argv)
80 int return_value = EXIT_SUCCESS;
81 diff -ur busybox.old/include/libbb.h busybox.dev/include/libbb.h
82 --- busybox.old/include/libbb.h 2007-01-19 22:23:10.000000000 +0100
83 +++ busybox.dev/include/libbb.h 2007-01-22 13:28:56.000000000 +0100
85 extern const char bb_uuenc_tbl_std[];
86 void bb_uuencode(const unsigned char *s, char *store, const int length, const char *tbl);
88 +typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
89 typedef struct sha1_ctx_t {
93 void md5_begin(md5_ctx_t *ctx);
94 void md5_hash(const void *data, size_t length, md5_ctx_t *ctx);
95 void *md5_end(void *resbuf, md5_ctx_t *ctx);
96 +unsigned char *hash_bin_to_hex(unsigned char *hash_value, unsigned hash_length);
97 +uint8_t *hash_file(const char *filename, hash_algo_t hash_algo);
99 uint32_t *crc32_filltable(int endian);
101 diff -ur busybox.old/libbb/Kbuild busybox.dev/libbb/Kbuild
102 --- busybox.old/libbb/Kbuild 2007-01-19 22:23:06.000000000 +0100
103 +++ busybox.dev/libbb/Kbuild 2007-01-22 13:29:24.000000000 +0100
105 lib-y += get_last_path_component.o
106 lib-y += get_line_from_file.o
109 lib-y += herror_msg.o
110 lib-y += herror_msg_and_die.o
111 lib-y += human_readable.o
112 --- busybox.old/libbb/hash.c 1970-01-01 01:00:00.000000000 +0100
113 +++ busybox.dev/libbb/hash.c 2007-01-22 13:52:41.000000000 +0100
116 + * Copyright (C) 2003 Glenn L. McGrath
117 + * Copyright (C) 2003-2004 Erik Andersen
119 + * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
130 +#include "busybox.h"
132 +/* This might be useful elsewhere */
133 +unsigned char *hash_bin_to_hex(unsigned char *hash_value,
134 + unsigned hash_length)
136 + /* xzalloc zero-terminates */
137 + char *hex_value = xzalloc((hash_length * 2) + 1);
138 + bin2hex(hex_value, (char*)hash_value, hash_length);
142 +uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
144 + int src_fd, hash_len, count;
149 + uint8_t *hash_value = NULL;
150 + RESERVE_CONFIG_UBUFFER(in_buf, 4096);
151 + void (*update)(const void*, size_t, void*);
152 + void (*final)(void*, void*);
154 + src_fd = STDIN_FILENO;
155 + if (NOT_LONE_DASH(filename)) {
156 + src_fd = open(filename, O_RDONLY);
158 + bb_perror_msg("%s", filename);
163 + /* figure specific hash algorithims */
164 + if (hash_algo==HASH_MD5) {
165 + md5_begin(&context.md5);
166 + update = (void (*)(const void*, size_t, void*))md5_hash;
167 + final = (void (*)(void*, void*))md5_end;
169 + } else if (hash_algo==HASH_SHA1) {
170 + sha1_begin(&context.sha1);
171 + update = (void (*)(const void*, size_t, void*))sha1_hash;
172 + final = (void (*)(void*, void*))sha1_end;
175 + bb_error_msg_and_die("algorithm not supported");
178 + while (0 < (count = safe_read(src_fd, in_buf, 4096))) {
179 + update(in_buf, count, &context);
183 + final(in_buf, &context);
184 + hash_value = hash_bin_to_hex(in_buf, hash_len);
187 + RELEASE_CONFIG_BUFFER(in_buf);
189 + if (src_fd != STDIN_FILENO) {