1 # Copyright (C) 2006 OpenWrt.org
3 # This is free software, licensed under the GNU General Public License v2.
4 # See /LICENSE for more information.
6 # expose (again) an hash_fd function (used in 911-ipkg.patch)
8 diff -ruN busybox-1.3.1-orig/coreutils/md5_sha1_sum.c busybox-1.3.1-913/coreutils/md5_sha1_sum.c
9 --- busybox-1.3.1-orig/coreutils/md5_sha1_sum.c 2006-12-27 05:54:50.000000000 +0100
10 +++ busybox-1.3.1-913/coreutils/md5_sha1_sum.c 2006-12-28 00:59:35.000000000 +0100
15 -typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
21 -/* This might be useful elsewhere */
22 -static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
23 - unsigned hash_length)
26 - char *hex_value = xmalloc((hash_length * 2) + 2);
27 - while (hash_length--) {
28 - len += sprintf(hex_value + len, "%02x", *hash_value++);
33 -static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
35 - int src_fd, hash_len, count;
40 - uint8_t *hash_value = NULL;
41 - RESERVE_CONFIG_UBUFFER(in_buf, 4096);
42 - void (*update)(const void*, size_t, void*);
43 - void (*final)(void*, void*);
45 - src_fd = STDIN_FILENO;
46 - if (filename[0] != '-' || filename[1]) { /* not "-" */
47 - src_fd = open(filename, O_RDONLY);
49 - bb_perror_msg("%s", filename);
54 - /* figure specific hash algorithims */
55 - if (ENABLE_MD5SUM && hash_algo==HASH_MD5) {
56 - md5_begin(&context.md5);
57 - update = (void (*)(const void*, size_t, void*))md5_hash;
58 - final = (void (*)(void*, void*))md5_end;
60 - } else if (ENABLE_SHA1SUM && hash_algo==HASH_SHA1) {
61 - sha1_begin(&context.sha1);
62 - update = (void (*)(const void*, size_t, void*))sha1_hash;
63 - final = (void (*)(void*, void*))sha1_end;
66 - bb_error_msg_and_die("algorithm not supported");
69 - while (0 < (count = safe_read(src_fd, in_buf, 4096))) {
70 - update(in_buf, count, &context);
74 - final(in_buf, &context);
75 - hash_value = hash_bin_to_hex(in_buf, hash_len);
78 - RELEASE_CONFIG_BUFFER(in_buf);
80 - if (src_fd != STDIN_FILENO) {
87 int md5_sha1_sum_main(int argc, char **argv)
89 int return_value = EXIT_SUCCESS;
90 diff -ruN busybox-1.3.1-orig/include/libbb.h busybox-1.3.1-913/include/libbb.h
91 --- busybox-1.3.1-orig/include/libbb.h 2006-12-27 05:56:18.000000000 +0100
92 +++ busybox-1.3.1-913/include/libbb.h 2006-12-27 23:25:52.000000000 +0100
94 extern const char bb_uuenc_tbl_std[];
95 void bb_uuencode(const unsigned char *s, char *store, const int length, const char *tbl);
97 +typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
99 typedef struct sha1_ctx_t {
103 void md5_hash(const void *data, size_t length, md5_ctx_t *ctx);
104 void *md5_end(void *resbuf, md5_ctx_t *ctx);
106 +unsigned char *hash_bin_to_hex(unsigned char *hash_value, unsigned char hash_length);
107 +int hash_fd(int fd, hash_algo_t hash_algo, uint8_t *hash_value);
108 +uint8_t *hash_file(const char *filename, hash_algo_t hash_algo);
110 uint32_t *crc32_filltable(int endian);
113 diff -ruN busybox-1.3.1-orig/libbb/hash.c busybox-1.3.1-913/libbb/hash.c
114 --- busybox-1.3.1-orig/libbb/hash.c 1970-01-01 01:00:00.000000000 +0100
115 +++ busybox-1.3.1-913/libbb/hash.c 2006-12-28 00:48:52.000000000 +0100
118 + * Copyright (C) 2003 Glenn L. McGrath
119 + * Copyright (C) 2003-2004 Erik Andersen
121 + * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
132 +#include "busybox.h"
134 +unsigned char *hash_bin_to_hex(unsigned char *hash_value, unsigned char hash_length)
137 + char *hex_value = xmalloc((hash_length * 2) + 2);
138 + while (hash_length--) {
139 + len += sprintf(hex_value + len, "%02x", *hash_value++);
144 +int hash_fd(int fd, hash_algo_t hash_algo, uint8_t *hash_value)
146 + int count, result = 0;
151 + RESERVE_CONFIG_UBUFFER(in_buf, 4096);
152 + void (*update)(const void*, size_t, void*) = NULL;
153 + void (*final)(void*, void*) = NULL;
155 + // figure specific hash algorithims
156 + if (hash_algo==HASH_MD5) {
157 + md5_begin(&context.md5);
158 + update = (void (*)(const void*, size_t, void*))md5_hash;
159 + final = (void (*)(void*, void*))md5_end;
160 + } else if (hash_algo==HASH_SHA1) {
161 + sha1_begin(&context.sha1);
162 + update = (void (*)(const void*, size_t, void*))sha1_hash;
163 + final = (void (*)(void*, void*))sha1_end;
167 + while (0 < (count = safe_read(fd, in_buf, sizeof in_buf))) {
168 + update(in_buf, count, &context);
173 + final(hash_value, &context);
176 + RELEASE_CONFIG_BUFFER(in_buf);
181 +uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
183 + int src_fd, hash_len;
184 + RESERVE_CONFIG_UBUFFER(hash_buf, 20);
185 + uint8_t *hash_value = NULL;
187 + if (ENABLE_MD5SUM && hash_algo==HASH_MD5) {
189 + } else if (ENABLE_SHA1SUM && hash_algo==HASH_SHA1) {
192 + bb_error_msg_and_die("algotithm not supported");
195 + src_fd = STDIN_FILENO;
196 + if (filename[0] != '-' || filename[1]) { /* not "-" */
197 + src_fd = open(filename, O_RDONLY);
199 + 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);
216 diff -ruN busybox-1.3.1-orig/libbb/Kbuild busybox-1.3.1-913/libbb/Kbuild
217 --- busybox-1.3.1-orig/libbb/Kbuild 2006-12-27 05:55:04.000000000 +0100
218 +++ busybox-1.3.1-913/libbb/Kbuild 2006-12-27 23:31:20.000000000 +0100
220 lib-y += get_last_path_component.o
221 lib-y += get_line_from_file.o
224 lib-y += herror_msg.o
225 lib-y += herror_msg_and_die.o
226 lib-y += human_readable.o