diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-11-10 13:32:50 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-11-10 13:32:50 +0000 |
commit | 56dceb9b7722193ef53fb1afb981f1289eecb0b0 (patch) | |
tree | 105363bf752df3c53e3d1165c8668af1983d5742 /coreutils | |
parent | c028ec280a71c45ba71bb4712db1968391a440cc (diff) | |
download | busybox-w32-56dceb9b7722193ef53fb1afb981f1289eecb0b0.tar.gz busybox-w32-56dceb9b7722193ef53fb1afb981f1289eecb0b0.tar.bz2 busybox-w32-56dceb9b7722193ef53fb1afb981f1289eecb0b0.zip |
sha256,sha512: new applets. +4.9kb
we will require sha256/512 code for new $5$ and $6$ style
password hashes anyway, they are showing up already
in people's /etc/passwd...
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/Config.in | 12 | ||||
-rw-r--r-- | coreutils/md5_sha1_sum.c | 35 |
2 files changed, 38 insertions, 9 deletions
diff --git a/coreutils/Config.in b/coreutils/Config.in index 8cbc92f1e..b734f8e30 100644 --- a/coreutils/Config.in +++ b/coreutils/Config.in | |||
@@ -509,6 +509,18 @@ config SHA1SUM | |||
509 | help | 509 | help |
510 | Compute and check SHA1 message digest | 510 | Compute and check SHA1 message digest |
511 | 511 | ||
512 | config SHA256SUM | ||
513 | bool "sha256sum" | ||
514 | default n | ||
515 | help | ||
516 | Compute and check SHA256 message digest | ||
517 | |||
518 | config SHA512SUM | ||
519 | bool "sha512sum" | ||
520 | default n | ||
521 | help | ||
522 | Compute and check SHA512 message digest | ||
523 | |||
512 | config SLEEP | 524 | config SLEEP |
513 | bool "sleep" | 525 | bool "sleep" |
514 | default n | 526 | default n |
diff --git a/coreutils/md5_sha1_sum.c b/coreutils/md5_sha1_sum.c index a5681589b..a988b9cbf 100644 --- a/coreutils/md5_sha1_sum.c +++ b/coreutils/md5_sha1_sum.c | |||
@@ -8,7 +8,13 @@ | |||
8 | 8 | ||
9 | #include "libbb.h" | 9 | #include "libbb.h" |
10 | 10 | ||
11 | typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t; | 11 | typedef enum { |
12 | /* 4th letter of applet_name is... */ | ||
13 | HASH_MD5 = 's', /* "md5>s<um" */ | ||
14 | HASH_SHA1 = '1', | ||
15 | HASH_SHA256 = '2', | ||
16 | HASH_SHA512 = '5', | ||
17 | } hash_algo_t; | ||
12 | 18 | ||
13 | #define FLAG_SILENT 1 | 19 | #define FLAG_SILENT 1 |
14 | #define FLAG_CHECK 2 | 20 | #define FLAG_CHECK 2 |
@@ -24,10 +30,12 @@ static unsigned char *hash_bin_to_hex(unsigned char *hash_value, | |||
24 | return (unsigned char *)hex_value; | 30 | return (unsigned char *)hex_value; |
25 | } | 31 | } |
26 | 32 | ||
27 | static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo) | 33 | static uint8_t *hash_file(const char *filename /*, hash_algo_t hash_algo*/) |
28 | { | 34 | { |
29 | int src_fd, hash_len, count; | 35 | int src_fd, hash_len, count; |
30 | union _ctx_ { | 36 | union _ctx_ { |
37 | sha512_ctx_t sha512; | ||
38 | sha256_ctx_t sha256; | ||
31 | sha1_ctx_t sha1; | 39 | sha1_ctx_t sha1; |
32 | md5_ctx_t md5; | 40 | md5_ctx_t md5; |
33 | } context; | 41 | } context; |
@@ -35,6 +43,7 @@ static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo) | |||
35 | RESERVE_CONFIG_UBUFFER(in_buf, 4096); | 43 | RESERVE_CONFIG_UBUFFER(in_buf, 4096); |
36 | void FAST_FUNC (*update)(const void*, size_t, void*); | 44 | void FAST_FUNC (*update)(const void*, size_t, void*); |
37 | void FAST_FUNC (*final)(void*, void*); | 45 | void FAST_FUNC (*final)(void*, void*); |
46 | hash_algo_t hash_algo = applet_name[3]; | ||
38 | 47 | ||
39 | src_fd = open_or_warn_stdin(filename); | 48 | src_fd = open_or_warn_stdin(filename); |
40 | if (src_fd < 0) { | 49 | if (src_fd < 0) { |
@@ -42,16 +51,26 @@ static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo) | |||
42 | } | 51 | } |
43 | 52 | ||
44 | /* figure specific hash algorithims */ | 53 | /* figure specific hash algorithims */ |
45 | if (ENABLE_MD5SUM && hash_algo==HASH_MD5) { | 54 | if (ENABLE_MD5SUM && hash_algo == HASH_MD5) { |
46 | md5_begin(&context.md5); | 55 | md5_begin(&context.md5); |
47 | update = (void*)md5_hash; | 56 | update = (void*)md5_hash; |
48 | final = (void*)md5_end; | 57 | final = (void*)md5_end; |
49 | hash_len = 16; | 58 | hash_len = 16; |
50 | } else if (ENABLE_SHA1SUM && hash_algo==HASH_SHA1) { | 59 | } else if (ENABLE_SHA1SUM && hash_algo == HASH_SHA1) { |
51 | sha1_begin(&context.sha1); | 60 | sha1_begin(&context.sha1); |
52 | update = (void*)sha1_hash; | 61 | update = (void*)sha1_hash; |
53 | final = (void*)sha1_end; | 62 | final = (void*)sha1_end; |
54 | hash_len = 20; | 63 | hash_len = 20; |
64 | } else if (ENABLE_SHA256SUM && hash_algo == HASH_SHA256) { | ||
65 | sha256_begin(&context.sha256); | ||
66 | update = (void*)sha256_hash; | ||
67 | final = (void*)sha256_end; | ||
68 | hash_len = 32; | ||
69 | } else if (ENABLE_SHA512SUM && hash_algo == HASH_SHA512) { | ||
70 | sha512_begin(&context.sha512); | ||
71 | update = (void*)sha512_hash; | ||
72 | final = (void*)sha512_end; | ||
73 | hash_len = 64; | ||
55 | } else { | 74 | } else { |
56 | bb_error_msg_and_die("algorithm not supported"); | 75 | bb_error_msg_and_die("algorithm not supported"); |
57 | } | 76 | } |
@@ -80,9 +99,7 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv) | |||
80 | int return_value = EXIT_SUCCESS; | 99 | int return_value = EXIT_SUCCESS; |
81 | uint8_t *hash_value; | 100 | uint8_t *hash_value; |
82 | unsigned flags; | 101 | unsigned flags; |
83 | hash_algo_t hash_algo = ENABLE_MD5SUM | 102 | /*hash_algo_t hash_algo = applet_name[3];*/ |
84 | ? (ENABLE_SHA1SUM ? (applet_name[0] == 'm' ? HASH_MD5 : HASH_SHA1) : HASH_MD5) | ||
85 | : HASH_SHA1; | ||
86 | 103 | ||
87 | if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK) | 104 | if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK) |
88 | flags = getopt32(argv, "scw"); | 105 | flags = getopt32(argv, "scw"); |
@@ -136,7 +153,7 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv) | |||
136 | *filename_ptr = '\0'; | 153 | *filename_ptr = '\0'; |
137 | filename_ptr += 2; | 154 | filename_ptr += 2; |
138 | 155 | ||
139 | hash_value = hash_file(filename_ptr, hash_algo); | 156 | hash_value = hash_file(filename_ptr /*, hash_algo*/); |
140 | 157 | ||
141 | if (hash_value && (strcmp((char*)hash_value, line) == 0)) { | 158 | if (hash_value && (strcmp((char*)hash_value, line) == 0)) { |
142 | if (!(flags & FLAG_SILENT)) | 159 | if (!(flags & FLAG_SILENT)) |
@@ -162,7 +179,7 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv) | |||
162 | */ | 179 | */ |
163 | } else { | 180 | } else { |
164 | do { | 181 | do { |
165 | hash_value = hash_file(*argv, hash_algo); | 182 | hash_value = hash_file(*argv/*, hash_algo*/); |
166 | if (hash_value == NULL) { | 183 | if (hash_value == NULL) { |
167 | return_value = EXIT_FAILURE; | 184 | return_value = EXIT_FAILURE; |
168 | } else { | 185 | } else { |