1 diff -ruN busybox-1.1.1-old/coreutils/md5_sha1_sum.c busybox-1.1.1-new/coreutils/md5_sha1_sum.c
2 --- busybox-1.1.1-old/coreutils/md5_sha1_sum.c 2006-03-30 00:14:50.000000000 +0200
3 +++ busybox-1.1.1-new/coreutils/md5_sha1_sum.c 2006-03-29 23:46:51.000000000 +0200
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 char hash_length)
19 - unsigned char *hex_value;
21 - max = (hash_length * 2) + 2;
22 - hex_value = xmalloc(max);
23 - for (x = len = 0; x < hash_length; x++) {
24 - len += snprintf((char*)(hex_value + len), max - len, "%02x", hash_value[x]);
29 -static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
31 - int src_fd, hash_len, count;
36 - uint8_t *hash_value = NULL;
37 - RESERVE_CONFIG_UBUFFER(in_buf, 4096);
38 - void (*update)(const void*, size_t, void*);
39 - void (*final)(void*, void*);
41 - if(strcmp(filename, "-") == 0) {
42 - src_fd = STDIN_FILENO;
43 - } else if(0 > (src_fd = open(filename, O_RDONLY))) {
44 - bb_perror_msg("%s", filename);
48 - // figure specific hash algorithims
49 - if(ENABLE_MD5SUM && hash_algo==HASH_MD5) {
50 - md5_begin(&context.md5);
51 - update = (void (*)(const void*, size_t, void*))md5_hash;
52 - final = (void (*)(void*, void*))md5_end;
54 - } else if(ENABLE_SHA1SUM && hash_algo==HASH_SHA1) {
55 - sha1_begin(&context.sha1);
56 - update = (void (*)(const void*, size_t, void*))sha1_hash;
57 - final = (void (*)(void*, void*))sha1_end;
60 - bb_error_msg_and_die("algotithm not supported");
64 - while(0 < (count = read(src_fd, in_buf, sizeof in_buf))) {
65 - update(in_buf, count, &context);
69 - final(in_buf, &context);
70 - hash_value = hash_bin_to_hex(in_buf, hash_len);
73 - RELEASE_CONFIG_BUFFER(in_buf);
75 - if(src_fd != STDIN_FILENO) {
82 /* This could become a common function for md5 as well, by using md5_stream */
83 static int hash_files(int argc, char **argv, hash_algo_t hash_algo)
85 diff -ruN busybox-1.1.1-old/include/libbb.h busybox-1.1.1-new/include/libbb.h
86 --- busybox-1.1.1-old/include/libbb.h 2006-03-30 00:14:50.000000000 +0200
87 +++ busybox-1.1.1-new/include/libbb.h 2006-03-30 00:31:48.000000000 +0200
89 void md5_hash(const void *data, size_t length, md5_ctx_t *ctx);
90 void *md5_end(void *resbuf, md5_ctx_t *ctx);
92 +typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
94 +unsigned char *hash_bin_to_hex(unsigned char *hash_value, unsigned char hash_length);
95 +int hash_fd(int fd, hash_algo_t hash_algo, uint8_t *hash_value);
96 +uint8_t *hash_file(const char *filename, hash_algo_t hash_algo);
98 /* busybox.h will include dmalloc later for us, else include it here. */
99 #if !defined _BB_INTERNAL_H_ && defined DMALLOC
101 diff -ruN busybox-1.1.1-old/libbb/Makefile.in busybox-1.1.1-new/libbb/Makefile.in
102 --- busybox-1.1.1-old/libbb/Makefile.in 2006-03-30 00:14:50.000000000 +0200
103 +++ busybox-1.1.1-new/libbb/Makefile.in 2006-03-29 23:46:51.000000000 +0200
109 bb_asprintf.c ask_confirmation.c change_identity.c chomp.c \
110 compare_string_array.c concat_path_file.c copy_file.c copyfd.c \
111 create_icmp_socket.c create_icmp6_socket.c \
112 diff -ruN busybox-1.1.1-old/libbb/hash.c busybox-1.1.1-new/libbb/hash.c
113 --- busybox-1.1.1-old/libbb/hash.c 1970-01-01 01:00:00.000000000 +0100
114 +++ busybox-1.1.1-new/libbb/hash.c 2006-03-30 00:35:54.000000000 +0200
117 + * Copyright (C) 2003 Glenn L. McGrath
118 + * Copyright (C) 2003-2004 Erik Andersen
120 + * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
131 +#include "busybox.h"
133 +unsigned char *hash_bin_to_hex(unsigned char *hash_value, unsigned char hash_length)
136 + unsigned char *hex_value;
138 + max = (hash_length * 2) + 2;
139 + hex_value = xmalloc(max);
140 + for (x = len = 0; x < hash_length; x++) {
141 + len += snprintf((char*)(hex_value + len), max - len, "%02x", hash_value[x]);
143 + return (hex_value);
146 +int hash_fd(int fd, hash_algo_t hash_algo, uint8_t *hash_value)
148 + int count, result = 0;
153 + RESERVE_CONFIG_UBUFFER(in_buf, 4096);
154 + void (*update)(const void*, size_t, void*) = NULL;
155 + void (*final)(void*, void*) = NULL;
157 + // figure specific hash algorithims
158 + if(hash_algo==HASH_MD5) {
159 + md5_begin(&context.md5);
160 + update = (void (*)(const void*, size_t, void*))md5_hash;
161 + final = (void (*)(void*, void*))md5_end;
162 + } else if(hash_algo==HASH_SHA1) {
163 + sha1_begin(&context.sha1);
164 + update = (void (*)(const void*, size_t, void*))sha1_hash;
165 + final = (void (*)(void*, void*))sha1_end;
169 + while(0 < (count = read(fd, in_buf, sizeof in_buf))) {
170 + update(in_buf, count, &context);
175 + final(hash_value, &context);
178 + RELEASE_CONFIG_BUFFER(in_buf);
183 +uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
185 + int src_fd, hash_len;
186 + RESERVE_CONFIG_UBUFFER(hash_buf, 20);
187 + uint8_t *hash_value = NULL;
189 + if(ENABLE_MD5SUM && hash_algo==HASH_MD5) {
191 + } else if(ENABLE_SHA1SUM && hash_algo==HASH_SHA1) {
194 + bb_error_msg_and_die("algotithm not supported");
197 + if(strcmp(filename, "-") == 0) {
198 + src_fd = STDIN_FILENO;
199 + } else if(0 > (src_fd = open(filename, O_RDONLY))) {
200 + bb_perror_msg("%s", filename);
204 + if(hash_fd(src_fd, hash_algo, hash_buf) > 0) {
205 + hash_value = hash_bin_to_hex(hash_buf, hash_len);
208 + if(src_fd != STDIN_FILENO) {
212 + RELEASE_CONFIG_BUFFER(hash_buf);