aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-09-28 00:29:00 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-09-28 00:29:00 +0000
commitfc9975761320f38189e69a6e63666fa86019c550 (patch)
treeade67c96b46c3cbbd869c4ca4b77b462b4db0d81
parentede88e7a5065cac3e03d4d34c83d0dfa414453b4 (diff)
downloadbusybox-w32-fc9975761320f38189e69a6e63666fa86019c550.tar.gz
busybox-w32-fc9975761320f38189e69a6e63666fa86019c550.tar.bz2
busybox-w32-fc9975761320f38189e69a6e63666fa86019c550.zip
Tried to find sha1_crypt - nope... ok, save few bytes in md5_sha1_sum.c
(time to sleep, 02:28 in the morning)... git-svn-id: svn://busybox.net/trunk/busybox@16244 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--coreutils/md5_sha1_sum.c20
-rw-r--r--libbb/sha1.c33
2 files changed, 25 insertions, 28 deletions
diff --git a/coreutils/md5_sha1_sum.c b/coreutils/md5_sha1_sum.c
index 6226e0988..c10fac5d0 100644
--- a/coreutils/md5_sha1_sum.c
+++ b/coreutils/md5_sha1_sum.c
@@ -16,7 +16,7 @@ typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
16 16
17/* This might be useful elsewhere */ 17/* This might be useful elsewhere */
18static unsigned char *hash_bin_to_hex(unsigned char *hash_value, 18static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
19 unsigned char hash_length) 19 unsigned char hash_length)
20{ 20{
21 int x, len, max; 21 int x, len, max;
22 unsigned char *hex_value; 22 unsigned char *hex_value;
@@ -86,11 +86,9 @@ int md5_sha1_sum_main(int argc, char **argv)
86 int return_value = EXIT_SUCCESS; 86 int return_value = EXIT_SUCCESS;
87 uint8_t *hash_value; 87 uint8_t *hash_value;
88 unsigned int flags; 88 unsigned int flags;
89 hash_algo_t hash_algo = ENABLE_MD5SUM ? 89 hash_algo_t hash_algo = ENABLE_MD5SUM
90 (ENABLE_SHA1SUM ? 90 ? (ENABLE_SHA1SUM ? (**argv=='m' ? HASH_MD5 : HASH_SHA1) : HASH_MD5)
91 (**argv=='m' ? HASH_MD5 : HASH_SHA1) 91 : HASH_SHA1;
92 : HASH_MD5)
93 : HASH_SHA1;
94 92
95 if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK) 93 if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK)
96 flags = bb_getopt_ulflags(argc, argv, "scw"); 94 flags = bb_getopt_ulflags(argc, argv, "scw");
@@ -99,10 +97,10 @@ int md5_sha1_sum_main(int argc, char **argv)
99 if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK && !(flags & FLAG_CHECK)) { 97 if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK && !(flags & FLAG_CHECK)) {
100 if (flags & FLAG_SILENT) { 98 if (flags & FLAG_SILENT) {
101 bb_error_msg_and_die 99 bb_error_msg_and_die
102 ("the -s option is meaningful only when verifying checksums"); 100 ("-%c is meaningful only when verifying checksums", 's');
103 } else if (flags & FLAG_WARN) { 101 } else if (flags & FLAG_WARN) {
104 bb_error_msg_and_die 102 bb_error_msg_and_die
105 ("the -w option is meaningful only when verifying checksums"); 103 ("-%c is meaningful only when verifying checksums", 'w');
106 } 104 }
107 } 105 }
108 106
@@ -135,7 +133,7 @@ int md5_sha1_sum_main(int argc, char **argv)
135 filename_ptr = strstr(line, " "); 133 filename_ptr = strstr(line, " ");
136 if (filename_ptr == NULL) { 134 if (filename_ptr == NULL) {
137 if (flags & FLAG_WARN) { 135 if (flags & FLAG_WARN) {
138 bb_error_msg("Invalid format"); 136 bb_error_msg("invalid format");
139 } 137 }
140 count_failed++; 138 count_failed++;
141 return_value = EXIT_FAILURE; 139 return_value = EXIT_FAILURE;
@@ -165,7 +163,7 @@ int md5_sha1_sum_main(int argc, char **argv)
165 count_failed, count_total); 163 count_failed, count_total);
166 } 164 }
167 if (bb_fclose_nonstdin(pre_computed_stream) == EOF) { 165 if (bb_fclose_nonstdin(pre_computed_stream) == EOF) {
168 bb_perror_msg_and_die("Couldnt close file %s", file_ptr); 166 bb_perror_msg_and_die("cannot close file %s", file_ptr);
169 } 167 }
170 } else { 168 } else {
171 while (optind < argc) { 169 while (optind < argc) {
@@ -180,5 +178,5 @@ int md5_sha1_sum_main(int argc, char **argv)
180 } 178 }
181 } 179 }
182 } 180 }
183 return (return_value); 181 return return_value;
184} 182}
diff --git a/libbb/sha1.c b/libbb/sha1.c
index a86218b25..34813e24a 100644
--- a/libbb/sha1.c
+++ b/libbb/sha1.c
@@ -26,27 +26,28 @@
26 26
27#include "libbb.h" 27#include "libbb.h"
28 28
29# define SHA1_BLOCK_SIZE 64 29#define SHA1_BLOCK_SIZE 64
30# define SHA1_DIGEST_SIZE 20 30#define SHA1_DIGEST_SIZE 20
31# define SHA1_HASH_SIZE SHA1_DIGEST_SIZE 31#define SHA1_HASH_SIZE SHA1_DIGEST_SIZE
32# define SHA2_GOOD 0 32#define SHA2_GOOD 0
33# define SHA2_BAD 1 33#define SHA2_BAD 1
34 34
35# define rotl32(x,n) (((x) << n) | ((x) >> (32 - n))) 35#define rotl32(x,n) (((x) << n) | ((x) >> (32 - n)))
36 36
37# define SHA1_MASK (SHA1_BLOCK_SIZE - 1) 37#define SHA1_MASK (SHA1_BLOCK_SIZE - 1)
38 38
39/* reverse byte order in 32-bit words */ 39/* reverse byte order in 32-bit words */
40#define ch(x,y,z) ((z) ^ ((x) & ((y) ^ (z)))) 40#define ch(x,y,z) ((z) ^ ((x) & ((y) ^ (z))))
41#define parity(x,y,z) ((x) ^ (y) ^ (z)) 41#define parity(x,y,z) ((x) ^ (y) ^ (z))
42#define maj(x,y,z) (((x) & (y)) | ((z) & ((x) | (y)))) 42#define maj(x,y,z) (((x) & (y)) | ((z) & ((x) | (y))))
43 43
44/* A normal version as set out in the FIPS. This version uses */ 44/* A normal version as set out in the FIPS. This version uses */
45/* partial loop unrolling and is optimised for the Pentium 4 */ 45/* partial loop unrolling and is optimised for the Pentium 4 */
46# define rnd(f,k) \ 46#define rnd(f,k) \
47 t = a; a = rotl32(a,5) + f(b,c,d) + e + k + w[i]; \ 47 do { \
48 e = d; d = c; c = rotl32(b, 30); b = t 48 t = a; a = rotl32(a,5) + f(b,c,d) + e + k + w[i]; \
49 49 e = d; d = c; c = rotl32(b, 30); b = t; \
50 } while(0)
50 51
51static void sha1_compile(sha1_ctx_t *ctx) 52static void sha1_compile(sha1_ctx_t *ctx)
52{ 53{
@@ -160,7 +161,7 @@ void *sha1_end(void *resbuf, sha1_ctx_t *ctx)
160 ctx->wbuf[cnt++] = 0; 161 ctx->wbuf[cnt++] = 0;
161 162
162 /* assemble the eight byte counter in the buffer in big-endian */ 163 /* assemble the eight byte counter in the buffer in big-endian */
163 /* format */ 164 /* format */
164 165
165 ctx->wbuf[14] = htonl((ctx->count[1] << 3) | (ctx->count[0] >> 29)); 166 ctx->wbuf[14] = htonl((ctx->count[1] << 3) | (ctx->count[0] >> 29));
166 ctx->wbuf[15] = htonl(ctx->count[0] << 3); 167 ctx->wbuf[15] = htonl(ctx->count[0] << 3);
@@ -175,5 +176,3 @@ void *sha1_end(void *resbuf, sha1_ctx_t *ctx)
175 176
176 return resbuf; 177 return resbuf;
177} 178}
178
179