4 extern const char bb_uuenc_tbl_std[];
5 void bb_uuencode(char *store, const void *s, int length, const char *tbl);
7 +typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
8 typedef struct sha1_ctx_t {
12 void md5_begin(md5_ctx_t *ctx);
13 void md5_hash(const void *data, size_t length, md5_ctx_t *ctx);
14 void *md5_end(void *resbuf, md5_ctx_t *ctx);
15 +unsigned char *hash_bin_to_hex(unsigned char *hash_value, unsigned hash_length);
16 +uint8_t *hash_file(const char *filename, hash_algo_t hash_algo);
18 uint32_t *crc32_filltable(uint32_t *tbl256, int endian);
20 --- a/coreutils/md5_sha1_sum.c
21 +++ b/coreutils/md5_sha1_sum.c
26 -typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
32 -/* This might be useful elsewhere */
33 -static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
34 - unsigned hash_length)
36 - /* xzalloc zero-terminates */
37 - char *hex_value = xzalloc((hash_length * 2) + 1);
38 - bin2hex(hex_value, (char*)hash_value, hash_length);
39 - return (unsigned char *)hex_value;
42 -static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
44 - int src_fd, hash_len, count;
49 - uint8_t *hash_value = NULL;
50 - RESERVE_CONFIG_UBUFFER(in_buf, 4096);
51 - void (*update)(const void*, size_t, void*);
52 - void (*final)(void*, void*);
54 - src_fd = open_or_warn_stdin(filename);
59 - /* figure specific hash algorithims */
60 - if (ENABLE_MD5SUM && hash_algo==HASH_MD5) {
61 - md5_begin(&context.md5);
62 - update = (void (*)(const void*, size_t, void*))md5_hash;
63 - final = (void (*)(void*, void*))md5_end;
65 - } else if (ENABLE_SHA1SUM && hash_algo==HASH_SHA1) {
66 - sha1_begin(&context.sha1);
67 - update = (void (*)(const void*, size_t, void*))sha1_hash;
68 - final = (void (*)(void*, void*))sha1_end;
71 - bb_error_msg_and_die("algorithm not supported");
74 - while (0 < (count = safe_read(src_fd, in_buf, 4096))) {
75 - update(in_buf, count, &context);
79 - final(in_buf, &context);
80 - hash_value = hash_bin_to_hex(in_buf, hash_len);
83 - RELEASE_CONFIG_BUFFER(in_buf);
85 - if (src_fd != STDIN_FILENO) {
92 int md5_sha1_sum_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
93 int md5_sha1_sum_main(int argc ATTRIBUTE_UNUSED, char **argv)
98 lib-y += get_last_path_component.o
99 lib-y += get_line_from_file.o
103 lib-y += herror_msg.o
104 lib-y += herror_msg_and_die.o
109 + * Copyright (C) 2003 Glenn L. McGrath
110 + * Copyright (C) 2003-2004 Erik Andersen
112 + * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
123 +#include "busybox.h"
125 +/* This might be useful elsewhere */
126 +unsigned char *hash_bin_to_hex(unsigned char *hash_value,
127 + unsigned hash_length)
129 + /* xzalloc zero-terminates */
130 + char *hex_value = xzalloc((hash_length * 2) + 1);
131 + bin2hex(hex_value, (char*)hash_value, hash_length);
135 +uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
137 + int src_fd, hash_len, count;
142 + uint8_t *hash_value = NULL;
143 + RESERVE_CONFIG_UBUFFER(in_buf, 4096);
144 + void (*update)(const void*, size_t, void*);
145 + void (*final)(void*, void*);
147 + src_fd = open_or_warn_stdin(filename);
152 + /* figure specific hash algorithims */
153 + if (ENABLE_MD5SUM && hash_algo==HASH_MD5) {
154 + md5_begin(&context.md5);
155 + update = (void (*)(const void*, size_t, void*))md5_hash;
156 + final = (void (*)(void*, void*))md5_end;
158 + } else if (ENABLE_SHA1SUM && hash_algo==HASH_SHA1) {
159 + sha1_begin(&context.sha1);
160 + update = (void (*)(const void*, size_t, void*))sha1_hash;
161 + final = (void (*)(void*, void*))sha1_end;
164 + bb_error_msg_and_die("algorithm not supported");
167 + while (0 < (count = safe_read(src_fd, in_buf, 4096))) {
168 + update(in_buf, count, &context);
172 + final(in_buf, &context);
173 + hash_value = hash_bin_to_hex(in_buf, hash_len);
176 + RELEASE_CONFIG_BUFFER(in_buf);
178 + if (src_fd != STDIN_FILENO) {