2 # expose (again) an hash_fd function (used 911-ipkg.patch)
4 diff -ruN busybox-1.1.1-old/coreutils/md5_sha1_sum.c busybox-1.1.1-new/coreutils/md5_sha1_sum.c
5 --- busybox-1.1.1-old/coreutils/md5_sha1_sum.c 2006-03-30 00:14:50.000000000 +0200
6 +++ busybox-1.1.1-new/coreutils/md5_sha1_sum.c 2006-03-29 23:46:51.000000000 +0200
11 -typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
17 -/* This might be useful elsewhere */
18 -static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
19 - unsigned char hash_length)
22 - unsigned char *hex_value;
24 - max = (hash_length * 2) + 2;
25 - hex_value = xmalloc(max);
26 - for (x = len = 0; x < hash_length; x++) {
27 - len += snprintf((char*)(hex_value + len), max - len, "%02x", hash_value[x]);
32 -static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
34 - int src_fd, hash_len, count;
39 - uint8_t *hash_value = NULL;
40 - RESERVE_CONFIG_UBUFFER(in_buf, 4096);
41 - void (*update)(const void*, size_t, void*);
42 - void (*final)(void*, void*);
44 - if(strcmp(filename, "-") == 0) {
45 - src_fd = STDIN_FILENO;
46 - } else if(0 > (src_fd = open(filename, O_RDONLY))) {
47 - bb_perror_msg("%s", filename);
51 - // figure specific hash algorithims
52 - if(ENABLE_MD5SUM && hash_algo==HASH_MD5) {
53 - md5_begin(&context.md5);
54 - update = (void (*)(const void*, size_t, void*))md5_hash;
55 - final = (void (*)(void*, void*))md5_end;
57 - } else if(ENABLE_SHA1SUM && hash_algo==HASH_SHA1) {
58 - sha1_begin(&context.sha1);
59 - update = (void (*)(const void*, size_t, void*))sha1_hash;
60 - final = (void (*)(void*, void*))sha1_end;
63 - bb_error_msg_and_die("algotithm not supported");
67 - while(0 < (count = read(src_fd, in_buf, sizeof in_buf))) {
68 - update(in_buf, count, &context);
72 - final(in_buf, &context);
73 - hash_value = hash_bin_to_hex(in_buf, hash_len);
76 - RELEASE_CONFIG_BUFFER(in_buf);
78 - if(src_fd != STDIN_FILENO) {
85 /* This could become a common function for md5 as well, by using md5_stream */
86 static int hash_files(int argc, char **argv, hash_algo_t hash_algo)
88 diff -ruN busybox-1.1.1-old/include/libbb.h busybox-1.1.1-new/include/libbb.h
89 --- busybox-1.1.1-old/include/libbb.h 2006-03-30 00:14:50.000000000 +0200
90 +++ busybox-1.1.1-new/include/libbb.h 2006-03-30 00:31:48.000000000 +0200
92 void md5_hash(const void *data, size_t length, md5_ctx_t *ctx);
93 void *md5_end(void *resbuf, md5_ctx_t *ctx);
95 +typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
97 +unsigned char *hash_bin_to_hex(unsigned char *hash_value, unsigned char hash_length);
98 +int hash_fd(int fd, hash_algo_t hash_algo, uint8_t *hash_value);
99 +uint8_t *hash_file(const char *filename, hash_algo_t hash_algo);
101 /* busybox.h will include dmalloc later for us, else include it here. */
102 #if !defined _BB_INTERNAL_H_ && defined DMALLOC
104 diff -ruN busybox-1.1.1-old/libbb/Makefile.in busybox-1.1.1-new/libbb/Makefile.in
105 --- busybox-1.1.1-old/libbb/Makefile.in 2006-03-30 00:14:50.000000000 +0200
106 +++ busybox-1.1.1-new/libbb/Makefile.in 2006-03-29 23:46:51.000000000 +0200
112 bb_asprintf.c ask_confirmation.c change_identity.c chomp.c \
113 compare_string_array.c concat_path_file.c copy_file.c copyfd.c \
114 create_icmp_socket.c create_icmp6_socket.c \
115 diff -ruN busybox-1.1.1-old/libbb/hash.c busybox-1.1.1-new/libbb/hash.c
116 --- busybox-1.1.1-old/libbb/hash.c 1970-01-01 01:00:00.000000000 +0100
117 +++ busybox-1.1.1-new/libbb/hash.c 2006-03-30 00:35:54.000000000 +0200
120 + * Copyright (C) 2003 Glenn L. McGrath
121 + * Copyright (C) 2003-2004 Erik Andersen
123 + * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
134 +#include "busybox.h"
136 +unsigned char *hash_bin_to_hex(unsigned char *hash_value, unsigned char hash_length)
139 + unsigned char *hex_value;
141 + max = (hash_length * 2) + 2;
142 + hex_value = xmalloc(max);
143 + for (x = len = 0; x < hash_length; x++) {
144 + len += snprintf((char*)(hex_value + len), max - len, "%02x", hash_value[x]);
146 + return (hex_value);
149 +int hash_fd(int fd, hash_algo_t hash_algo, uint8_t *hash_value)
151 + int count, result = 0;
156 + RESERVE_CONFIG_UBUFFER(in_buf, 4096);
157 + void (*update)(const void*, size_t, void*) = NULL;
158 + void (*final)(void*, void*) = NULL;
160 + // figure specific hash algorithims
161 + if(hash_algo==HASH_MD5) {
162 + md5_begin(&context.md5);
163 + update = (void (*)(const void*, size_t, void*))md5_hash;
164 + final = (void (*)(void*, void*))md5_end;
165 + } else if(hash_algo==HASH_SHA1) {
166 + sha1_begin(&context.sha1);
167 + update = (void (*)(const void*, size_t, void*))sha1_hash;
168 + final = (void (*)(void*, void*))sha1_end;
172 + while(0 < (count = read(fd, in_buf, sizeof in_buf))) {
173 + update(in_buf, count, &context);
178 + final(hash_value, &context);
181 + RELEASE_CONFIG_BUFFER(in_buf);
186 +uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
188 + int src_fd, hash_len;
189 + RESERVE_CONFIG_UBUFFER(hash_buf, 20);
190 + uint8_t *hash_value = NULL;
192 + if(ENABLE_MD5SUM && hash_algo==HASH_MD5) {
194 + } else if(ENABLE_SHA1SUM && hash_algo==HASH_SHA1) {
197 + bb_error_msg_and_die("algotithm not supported");
200 + if(strcmp(filename, "-") == 0) {
201 + src_fd = STDIN_FILENO;
202 + } else if(0 > (src_fd = open(filename, O_RDONLY))) {
203 + bb_perror_msg("%s", filename);
207 + if(hash_fd(src_fd, hash_algo, hash_buf) > 0) {
208 + hash_value = hash_bin_to_hex(hash_buf, hash_len);
211 + if(src_fd != STDIN_FILENO) {
215 + RELEASE_CONFIG_BUFFER(hash_buf);