1 Index: busybox-1.4.2/coreutils/md5_sha1_sum.c
2 ===================================================================
3 --- busybox-1.4.2.orig/coreutils/md5_sha1_sum.c 2007-06-04 13:21:31.536182440 +0200
4 +++ busybox-1.4.2/coreutils/md5_sha1_sum.c 2007-06-04 13:21:37.709243992 +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(filename, O_RDONLY);
41 - bb_perror_msg("%s", filename);
46 - /* figure specific hash algorithims */
47 - if (ENABLE_MD5SUM && hash_algo==HASH_MD5) {
48 - md5_begin(&context.md5);
49 - update = (void (*)(const void*, size_t, void*))md5_hash;
50 - final = (void (*)(void*, void*))md5_end;
52 - } else if (ENABLE_SHA1SUM && hash_algo==HASH_SHA1) {
53 - sha1_begin(&context.sha1);
54 - update = (void (*)(const void*, size_t, void*))sha1_hash;
55 - final = (void (*)(void*, void*))sha1_end;
58 - bb_error_msg_and_die("algorithm not supported");
61 - while (0 < (count = safe_read(src_fd, in_buf, 4096))) {
62 - update(in_buf, count, &context);
66 - final(in_buf, &context);
67 - hash_value = hash_bin_to_hex(in_buf, hash_len);
70 - RELEASE_CONFIG_BUFFER(in_buf);
72 - if (src_fd != STDIN_FILENO) {
79 int md5_sha1_sum_main(int argc, char **argv)
81 int return_value = EXIT_SUCCESS;
82 Index: busybox-1.4.2/include/libbb.h
83 ===================================================================
84 --- busybox-1.4.2.orig/include/libbb.h 2007-06-04 13:21:35.388596784 +0200
85 +++ busybox-1.4.2/include/libbb.h 2007-06-04 13:21:37.709243992 +0200
87 extern const char bb_uuenc_tbl_std[];
88 void bb_uuencode(const unsigned char *s, char *store, const int length, const char *tbl);
90 +typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
91 typedef struct sha1_ctx_t {
95 void md5_begin(md5_ctx_t *ctx);
96 void md5_hash(const void *data, size_t length, md5_ctx_t *ctx);
97 void *md5_end(void *resbuf, md5_ctx_t *ctx);
98 +unsigned char *hash_bin_to_hex(unsigned char *hash_value, unsigned hash_length);
99 +uint8_t *hash_file(const char *filename, hash_algo_t hash_algo);
101 uint32_t *crc32_filltable(int endian);
103 Index: busybox-1.4.2/libbb/Kbuild
104 ===================================================================
105 --- busybox-1.4.2.orig/libbb/Kbuild 2007-06-04 13:21:31.548180616 +0200
106 +++ busybox-1.4.2/libbb/Kbuild 2007-06-04 13:21:37.710243840 +0200
108 lib-y += get_last_path_component.o
109 lib-y += get_line_from_file.o
112 lib-y += herror_msg.o
113 lib-y += herror_msg_and_die.o
114 lib-y += human_readable.o
115 Index: busybox-1.4.2/libbb/hash.c
116 ===================================================================
117 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
118 +++ busybox-1.4.2/libbb/hash.c 2007-06-04 13:21:37.710243840 +0200
121 + * Copyright (C) 2003 Glenn L. McGrath
122 + * Copyright (C) 2003-2004 Erik Andersen
124 + * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
135 +#include "busybox.h"
137 +/* This might be useful elsewhere */
138 +unsigned char *hash_bin_to_hex(unsigned char *hash_value,
139 + unsigned hash_length)
141 + /* xzalloc zero-terminates */
142 + char *hex_value = xzalloc((hash_length * 2) + 1);
143 + bin2hex(hex_value, (char*)hash_value, hash_length);
147 +uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
149 + int src_fd, hash_len, count;
154 + uint8_t *hash_value = NULL;
155 + RESERVE_CONFIG_UBUFFER(in_buf, 4096);
156 + void (*update)(const void*, size_t, void*);
157 + void (*final)(void*, void*);
159 + src_fd = STDIN_FILENO;
160 + if (NOT_LONE_DASH(filename)) {
161 + src_fd = open(filename, O_RDONLY);
163 + bb_perror_msg("%s", filename);
168 + /* figure specific hash algorithims */
169 + if (hash_algo==HASH_MD5) {
170 + md5_begin(&context.md5);
171 + update = (void (*)(const void*, size_t, void*))md5_hash;
172 + final = (void (*)(void*, void*))md5_end;
174 + } else if (hash_algo==HASH_SHA1) {
175 + sha1_begin(&context.sha1);
176 + update = (void (*)(const void*, size_t, void*))sha1_hash;
177 + final = (void (*)(void*, void*))sha1_end;
180 + bb_error_msg_and_die("algorithm not supported");
183 + while (0 < (count = safe_read(src_fd, in_buf, 4096))) {
184 + update(in_buf, count, &context);
188 + final(in_buf, &context);
189 + hash_value = hash_bin_to_hex(in_buf, hash_len);
192 + RELEASE_CONFIG_BUFFER(in_buf);
194 + if (src_fd != STDIN_FILENO) {