automatically load ipv6 module
[openwrt.git] / package / busybox / patches / 913-libbb_hash.patch
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
5 @@ -8,76 +8,10 @@
6
7 #include "busybox.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(filename, O_RDONLY);
40 - if (src_fd < 0) {
41 - bb_perror_msg("%s", filename);
42 - return NULL;
43 - }
44 - }
45 -
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;
51 - hash_len = 16;
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;
56 - hash_len = 20;
57 - } else {
58 - bb_error_msg_and_die("algorithm not supported");
59 - }
60 -
61 - while (0 < (count = safe_read(src_fd, in_buf, 4096))) {
62 - update(in_buf, count, &context);
63 - }
64 -
65 - if (count == 0) {
66 - final(in_buf, &context);
67 - hash_value = hash_bin_to_hex(in_buf, hash_len);
68 - }
69 -
70 - RELEASE_CONFIG_BUFFER(in_buf);
71 -
72 - if (src_fd != STDIN_FILENO) {
73 - close(src_fd);
74 - }
75 -
76 - return hash_value;
77 -}
78 -
79 int md5_sha1_sum_main(int argc, char **argv)
80 {
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
86 @@ -641,6 +641,7 @@
87 extern const char bb_uuenc_tbl_std[];
88 void bb_uuencode(const unsigned char *s, char *store, const int length, const char *tbl);
89
90 +typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
91 typedef struct sha1_ctx_t {
92 uint32_t count[2];
93 uint32_t hash[5];
94 @@ -662,6 +663,8 @@
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);
100
101 uint32_t *crc32_filltable(int endian);
102
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
107 @@ -37,6 +37,7 @@
108 lib-y += get_last_path_component.o
109 lib-y += get_line_from_file.o
110 lib-y += getopt32.o
111 +lib-y += hash.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
119 @@ -0,0 +1,82 @@
120 +/*
121 + * Copyright (C) 2003 Glenn L. McGrath
122 + * Copyright (C) 2003-2004 Erik Andersen
123 + *
124 + * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
125 + */
126 +
127 +#include <fcntl.h>
128 +#include <limits.h>
129 +#include <stdio.h>
130 +#include <stdint.h>
131 +#include <stdlib.h>
132 +#include <string.h>
133 +#include <unistd.h>
134 +
135 +#include "busybox.h"
136 +
137 +/* This might be useful elsewhere */
138 +unsigned char *hash_bin_to_hex(unsigned char *hash_value,
139 + unsigned hash_length)
140 +{
141 + /* xzalloc zero-terminates */
142 + char *hex_value = xzalloc((hash_length * 2) + 1);
143 + bin2hex(hex_value, (char*)hash_value, hash_length);
144 + return hex_value;
145 +}
146 +
147 +uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
148 +{
149 + int src_fd, hash_len, count;
150 + union _ctx_ {
151 + sha1_ctx_t sha1;
152 + md5_ctx_t md5;
153 + } context;
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*);
158 +
159 + src_fd = STDIN_FILENO;
160 + if (NOT_LONE_DASH(filename)) {
161 + src_fd = open(filename, O_RDONLY);
162 + if (src_fd < 0) {
163 + bb_perror_msg("%s", filename);
164 + return NULL;
165 + }
166 + }
167 +
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;
173 + hash_len = 16;
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;
178 + hash_len = 20;
179 + } else {
180 + bb_error_msg_and_die("algorithm not supported");
181 + }
182 +
183 + while (0 < (count = safe_read(src_fd, in_buf, 4096))) {
184 + update(in_buf, count, &context);
185 + }
186 +
187 + if (count == 0) {
188 + final(in_buf, &context);
189 + hash_value = hash_bin_to_hex(in_buf, hash_len);
190 + }
191 +
192 + RELEASE_CONFIG_BUFFER(in_buf);
193 +
194 + if (src_fd != STDIN_FILENO) {
195 + close(src_fd);
196 + }
197 +
198 + return hash_value;
199 +}
200 +
201 +
This page took 0.067015 seconds and 5 git commands to generate.