clean up the directory layout of the uci shell api
[openwrt.git] / package / busybox / patches / 501-libbb_hash.patch
1 Index: busybox-1.8.1/coreutils/md5_sha1_sum.c
2 ===================================================================
3 --- busybox-1.8.1.orig/coreutils/md5_sha1_sum.c 2007-11-10 02:40:51.000000000 +0100
4 +++ busybox-1.8.1/coreutils/md5_sha1_sum.c 2007-11-10 17:05:59.957468399 +0100
5 @@ -8,75 +8,10 @@
6
7 #include "libbb.h"
8
9 -typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
10 -
11 #define FLAG_SILENT 1
12 #define FLAG_CHECK 2
13 #define FLAG_WARN 4
14
15 -/* This might be useful elsewhere */
16 -static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
17 - unsigned hash_length)
18 -{
19 - /* xzalloc zero-terminates */
20 - char *hex_value = xzalloc((hash_length * 2) + 1);
21 - bin2hex(hex_value, (char*)hash_value, hash_length);
22 - return hex_value;
23 -}
24 -
25 -static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
26 -{
27 - int src_fd, hash_len, count;
28 - union _ctx_ {
29 - sha1_ctx_t sha1;
30 - md5_ctx_t md5;
31 - } context;
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*);
36 -
37 - src_fd = STDIN_FILENO;
38 - if (NOT_LONE_DASH(filename)) {
39 - src_fd = open_or_warn(filename, O_RDONLY);
40 - if (src_fd < 0) {
41 - return NULL;
42 - }
43 - }
44 -
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;
50 - hash_len = 16;
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;
55 - hash_len = 20;
56 - } else {
57 - bb_error_msg_and_die("algorithm not supported");
58 - }
59 -
60 - while (0 < (count = safe_read(src_fd, in_buf, 4096))) {
61 - update(in_buf, count, &context);
62 - }
63 -
64 - if (count == 0) {
65 - final(in_buf, &context);
66 - hash_value = hash_bin_to_hex(in_buf, hash_len);
67 - }
68 -
69 - RELEASE_CONFIG_BUFFER(in_buf);
70 -
71 - if (src_fd != STDIN_FILENO) {
72 - close(src_fd);
73 - }
74 -
75 - return hash_value;
76 -}
77 -
78 int md5_sha1_sum_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
79 int md5_sha1_sum_main(int argc, char **argv)
80 {
81 Index: busybox-1.8.1/include/libbb.h
82 ===================================================================
83 --- busybox-1.8.1.orig/include/libbb.h 2007-11-10 16:55:07.048261223 +0100
84 +++ busybox-1.8.1/include/libbb.h 2007-11-10 17:04:07.543062264 +0100
85 @@ -1022,6 +1022,7 @@
86 extern const char bb_uuenc_tbl_std[];
87 void bb_uuencode(char *store, const void *s, int length, const char *tbl);
88
89 +typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
90 typedef struct sha1_ctx_t {
91 uint32_t count[2];
92 uint32_t hash[5];
93 @@ -1043,6 +1044,8 @@
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);
99
100 uint32_t *crc32_filltable(uint32_t *tbl256, int endian);
101
102 Index: busybox-1.8.1/libbb/Kbuild
103 ===================================================================
104 --- busybox-1.8.1.orig/libbb/Kbuild 2007-11-10 02:40:52.000000000 +0100
105 +++ busybox-1.8.1/libbb/Kbuild 2007-11-10 17:04:07.547062497 +0100
106 @@ -39,6 +39,7 @@
107 lib-y += get_last_path_component.o
108 lib-y += get_line_from_file.o
109 lib-y += getopt32.o
110 +lib-y += hash.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.8.1/libbb/hash.c
115 ===================================================================
116 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
117 +++ busybox-1.8.1/libbb/hash.c 2007-11-10 17:04:07.551062729 +0100
118 @@ -0,0 +1,81 @@
119 +/*
120 + * Copyright (C) 2003 Glenn L. McGrath
121 + * Copyright (C) 2003-2004 Erik Andersen
122 + *
123 + * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
124 + */
125 +
126 +#include <fcntl.h>
127 +#include <limits.h>
128 +#include <stdio.h>
129 +#include <stdint.h>
130 +#include <stdlib.h>
131 +#include <string.h>
132 +#include <unistd.h>
133 +
134 +#include "busybox.h"
135 +
136 +/* This might be useful elsewhere */
137 +unsigned char *hash_bin_to_hex(unsigned char *hash_value,
138 + unsigned hash_length)
139 +{
140 + /* xzalloc zero-terminates */
141 + char *hex_value = xzalloc((hash_length * 2) + 1);
142 + bin2hex(hex_value, (char*)hash_value, hash_length);
143 + return hex_value;
144 +}
145 +
146 +uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
147 +{
148 + int src_fd, hash_len, count;
149 + union _ctx_ {
150 + sha1_ctx_t sha1;
151 + md5_ctx_t md5;
152 + } context;
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*);
157 +
158 + src_fd = STDIN_FILENO;
159 + if (NOT_LONE_DASH(filename)) {
160 + src_fd = open_or_warn(filename, O_RDONLY);
161 + if (src_fd < 0) {
162 + return NULL;
163 + }
164 + }
165 +
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;
171 + hash_len = 16;
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;
176 + hash_len = 20;
177 + } else {
178 + bb_error_msg_and_die("algorithm not supported");
179 + }
180 +
181 + while (0 < (count = safe_read(src_fd, in_buf, 4096))) {
182 + update(in_buf, count, &context);
183 + }
184 +
185 + if (count == 0) {
186 + final(in_buf, &context);
187 + hash_value = hash_bin_to_hex(in_buf, hash_len);
188 + }
189 +
190 + RELEASE_CONFIG_BUFFER(in_buf);
191 +
192 + if (src_fd != STDIN_FILENO) {
193 + close(src_fd);
194 + }
195 +
196 + return hash_value;
197 +}
198 +
199 +
This page took 0.05169 seconds and 5 git commands to generate.