1 Index: busybox-1.7.2/coreutils/md5_sha1_sum.c
2 ===================================================================
3 --- busybox-1.7.2.orig/coreutils/md5_sha1_sum.c 2007-09-03 13:48:39.000000000 +0200
4 +++ busybox-1.7.2/coreutils/md5_sha1_sum.c 2007-10-04 15:45:02.423570273 +0200
9 -typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
15 -/* This might be useful elsewhere */
16 -static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
17 - unsigned hash_length)
19 - /* xzalloc zero-terminates */
20 - char *hex_value = xzalloc((hash_length * 2) + 1);
21 - bin2hex(hex_value, (char*)hash_value, hash_length);
25 -static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
27 - int src_fd, hash_len, count;
32 - uint8_t *hash_value = NULL;
33 - RESERVE_CONFIG_UBUFFER(in_buf, 4096);
34 - void (*update)(const void*, size_t, void*);
35 - void (*final)(void*, void*);
37 - src_fd = STDIN_FILENO;
38 - if (NOT_LONE_DASH(filename)) {
39 - src_fd = open_or_warn(filename, O_RDONLY);
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);
79 int md5_sha1_sum_main(int argc, char **argv)
81 Index: busybox-1.7.2/include/libbb.h
82 ===================================================================
83 --- busybox-1.7.2.orig/include/libbb.h 2007-10-04 15:20:22.275221430 +0200
84 +++ busybox-1.7.2/include/libbb.h 2007-10-04 15:42:10.585777803 +0200
86 extern const char bb_uuenc_tbl_std[];
87 void bb_uuencode(char *store, const void *s, int length, const char *tbl);
89 +typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
90 typedef struct sha1_ctx_t {
94 void md5_begin(md5_ctx_t *ctx);
95 void md5_hash(const void *data, size_t length, md5_ctx_t *ctx);
96 void *md5_end(void *resbuf, md5_ctx_t *ctx);
97 +unsigned char *hash_bin_to_hex(unsigned char *hash_value, unsigned hash_length);
98 +uint8_t *hash_file(const char *filename, hash_algo_t hash_algo);
100 uint32_t *crc32_filltable(uint32_t *tbl256, int endian);
102 Index: busybox-1.7.2/libbb/Kbuild
103 ===================================================================
104 --- busybox-1.7.2.orig/libbb/Kbuild 2007-09-03 13:48:41.000000000 +0200
105 +++ busybox-1.7.2/libbb/Kbuild 2007-10-04 15:42:10.613779401 +0200
107 lib-y += get_last_path_component.o
108 lib-y += get_line_from_file.o
111 lib-y += herror_msg.o
112 lib-y += herror_msg_and_die.o
113 lib-y += human_readable.o
114 Index: busybox-1.7.2/libbb/hash.c
115 ===================================================================
116 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
117 +++ busybox-1.7.2/libbb/hash.c 2007-10-04 15:45:08.279904000 +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 +/* This might be useful elsewhere */
137 +unsigned char *hash_bin_to_hex(unsigned char *hash_value,
138 + unsigned hash_length)
140 + /* xzalloc zero-terminates */
141 + char *hex_value = xzalloc((hash_length * 2) + 1);
142 + bin2hex(hex_value, (char*)hash_value, hash_length);
146 +uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
148 + int src_fd, hash_len, count;
153 + uint8_t *hash_value = NULL;
154 + RESERVE_CONFIG_UBUFFER(in_buf, 4096);
155 + void (*update)(const void*, size_t, void*);
156 + void (*final)(void*, void*);
158 + src_fd = STDIN_FILENO;
159 + if (NOT_LONE_DASH(filename)) {
160 + src_fd = open_or_warn(filename, O_RDONLY);
166 + /* figure specific hash algorithims */
167 + if (ENABLE_MD5SUM && hash_algo==HASH_MD5) {
168 + md5_begin(&context.md5);
169 + update = (void (*)(const void*, size_t, void*))md5_hash;
170 + final = (void (*)(void*, void*))md5_end;
172 + } else if (ENABLE_SHA1SUM && hash_algo==HASH_SHA1) {
173 + sha1_begin(&context.sha1);
174 + update = (void (*)(const void*, size_t, void*))sha1_hash;
175 + final = (void (*)(void*, void*))sha1_end;
178 + bb_error_msg_and_die("algorithm not supported");
181 + while (0 < (count = safe_read(src_fd, in_buf, 4096))) {
182 + update(in_buf, count, &context);
186 + final(in_buf, &context);
187 + hash_value = hash_bin_to_hex(in_buf, hash_len);
190 + RELEASE_CONFIG_BUFFER(in_buf);
192 + if (src_fd != STDIN_FILENO) {