diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2011-01-04 19:55:06 +0700 |
---|---|---|
committer | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2011-01-04 19:55:06 +0700 |
commit | 3f357a9c754805c4c38793749927aeda82797735 (patch) | |
tree | 65bb50517515714b6baaa4d5d2debed1e716bc83 /libbb | |
parent | 47a20f7daf954c90bbc77d2c108cb366171c650f (diff) | |
parent | 776509544123c68bbc128c0fdb2f699062d294cf (diff) | |
download | busybox-w32-3f357a9c754805c4c38793749927aeda82797735.tar.gz busybox-w32-3f357a9c754805c4c38793749927aeda82797735.tar.bz2 busybox-w32-3f357a9c754805c4c38793749927aeda82797735.zip |
Merge commit 'e4dcba1c103dc28e927e004791e331aaf604383d^'
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/Config.src | 11 | ||||
-rw-r--r-- | libbb/crc32.c | 24 | ||||
-rw-r--r-- | libbb/hash_md5_sha.c | 105 | ||||
-rw-r--r-- | libbb/human_readable.c | 4 | ||||
-rw-r--r-- | libbb/parse_config.c | 14 | ||||
-rw-r--r-- | libbb/process_escape_sequence.c | 78 |
6 files changed, 136 insertions, 100 deletions
diff --git a/libbb/Config.src b/libbb/Config.src index 74dc9c549..f6c7a11ea 100644 --- a/libbb/Config.src +++ b/libbb/Config.src | |||
@@ -43,6 +43,17 @@ config FEATURE_ETC_NETWORKS | |||
43 | a rarely used feature which allows you to use names | 43 | a rarely used feature which allows you to use names |
44 | instead of IP/mask pairs in route command. | 44 | instead of IP/mask pairs in route command. |
45 | 45 | ||
46 | config FEATURE_USE_TERMIOS | ||
47 | bool "Use termios to manipulate the screen" | ||
48 | default y | ||
49 | depends on MORE || TOP || POWERTOP | ||
50 | help | ||
51 | This option allows utilities such as 'more' and 'top' to determine | ||
52 | the size of the screen. If you leave this disabled, your utilities | ||
53 | that display things on the screen will be especially primitive and | ||
54 | will be unable to determine the current screen size, and will be | ||
55 | unable to move the cursor. | ||
56 | |||
46 | config FEATURE_EDITING | 57 | config FEATURE_EDITING |
47 | bool "Command line editing" | 58 | bool "Command line editing" |
48 | default y | 59 | default y |
diff --git a/libbb/crc32.c b/libbb/crc32.c index 520b1ffb9..c63bf0772 100644 --- a/libbb/crc32.c +++ b/libbb/crc32.c | |||
@@ -18,6 +18,8 @@ | |||
18 | 18 | ||
19 | #include "libbb.h" | 19 | #include "libbb.h" |
20 | 20 | ||
21 | uint32_t *global_crc32_table; | ||
22 | |||
21 | uint32_t* FAST_FUNC crc32_filltable(uint32_t *crc_table, int endian) | 23 | uint32_t* FAST_FUNC crc32_filltable(uint32_t *crc_table, int endian) |
22 | { | 24 | { |
23 | uint32_t polynomial = endian ? 0x04c11db7 : 0xedb88320; | 25 | uint32_t polynomial = endian ? 0x04c11db7 : 0xedb88320; |
@@ -40,3 +42,25 @@ uint32_t* FAST_FUNC crc32_filltable(uint32_t *crc_table, int endian) | |||
40 | 42 | ||
41 | return crc_table - 256; | 43 | return crc_table - 256; |
42 | } | 44 | } |
45 | |||
46 | uint32_t FAST_FUNC crc32_block_endian1(uint32_t val, const void *buf, unsigned len, uint32_t *crc_table) | ||
47 | { | ||
48 | const void *end = (uint8_t*)buf + len; | ||
49 | |||
50 | while (buf != end) { | ||
51 | val = (val << 8) ^ crc_table[(val >> 24) ^ *(uint8_t*)buf]; | ||
52 | buf = (uint8_t*)buf + 1; | ||
53 | } | ||
54 | return val; | ||
55 | } | ||
56 | |||
57 | uint32_t FAST_FUNC crc32_block_endian0(uint32_t val, const void *buf, unsigned len, uint32_t *crc_table) | ||
58 | { | ||
59 | const void *end = (uint8_t*)buf + len; | ||
60 | |||
61 | while (buf != end) { | ||
62 | val = crc_table[(uint8_t)val ^ *(uint8_t*)buf] ^ (val >> 8); | ||
63 | buf = (uint8_t*)buf + 1; | ||
64 | } | ||
65 | return val; | ||
66 | } | ||
diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index aeacddef8..e427f6080 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c | |||
@@ -473,20 +473,13 @@ void FAST_FUNC md5_end(md5_ctx_t *ctx, void *resbuf) | |||
473 | 473 | ||
474 | 474 | ||
475 | /* | 475 | /* |
476 | * Based on shasum from http://www.netsw.org/crypto/hash/ | 476 | * SHA1 part is: |
477 | * Majorly hacked up to use Dr Brian Gladman's sha1 code | 477 | * Copyright 2007 Rob Landley <rob@landley.net> |
478 | * | 478 | * |
479 | * Copyright (C) 2002 Dr Brian Gladman <brg@gladman.me.uk>, Worcester, UK. | 479 | * Based on the public domain SHA-1 in C by Steve Reid <steve@edmweb.com> |
480 | * Copyright (C) 2003 Glenn L. McGrath | 480 | * from http://www.mirrors.wiretapped.net/security/cryptography/hashes/sha1/ |
481 | * Copyright (C) 2003 Erik Andersen | ||
482 | * | ||
483 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. | ||
484 | * | ||
485 | * --------------------------------------------------------------------------- | ||
486 | * Issue Date: 10/11/2002 | ||
487 | * | 481 | * |
488 | * This is a byte oriented version of SHA1 that operates on arrays of bytes | 482 | * Licensed under GPLv2, see file LICENSE in this source tree. |
489 | * stored in memory. It runs at 22 cycles per byte on a Pentium P4 processor | ||
490 | * | 483 | * |
491 | * --------------------------------------------------------------------------- | 484 | * --------------------------------------------------------------------------- |
492 | * | 485 | * |
@@ -503,16 +496,18 @@ void FAST_FUNC md5_end(md5_ctx_t *ctx, void *resbuf) | |||
503 | 496 | ||
504 | static void FAST_FUNC sha1_process_block64(sha1_ctx_t *ctx) | 497 | static void FAST_FUNC sha1_process_block64(sha1_ctx_t *ctx) |
505 | { | 498 | { |
506 | unsigned t; | 499 | static const uint32_t rconsts[] = { |
507 | uint32_t W[80], a, b, c, d, e; | 500 | 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6 |
508 | const uint32_t *words = (uint32_t*) ctx->wbuffer; | 501 | }; |
502 | int i, j; | ||
503 | int cnt; | ||
504 | uint32_t W[16+16]; | ||
505 | uint32_t a, b, c, d, e; | ||
509 | 506 | ||
510 | for (t = 0; t < 16; ++t) | 507 | /* On-stack work buffer frees up one register in the main loop |
511 | W[t] = SWAP_BE32(words[t]); | 508 | * which otherwise will be needed to hold ctx pointer */ |
512 | for (/*t = 16*/; t < 80; ++t) { | 509 | for (i = 0; i < 16; i++) |
513 | uint32_t T = W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16]; | 510 | W[i] = W[i+16] = SWAP_BE32(((uint32_t*)ctx->wbuffer)[i]); |
514 | W[t] = rotl32(T, 1); | ||
515 | } | ||
516 | 511 | ||
517 | a = ctx->hash[0]; | 512 | a = ctx->hash[0]; |
518 | b = ctx->hash[1]; | 513 | b = ctx->hash[1]; |
@@ -520,39 +515,41 @@ static void FAST_FUNC sha1_process_block64(sha1_ctx_t *ctx) | |||
520 | d = ctx->hash[3]; | 515 | d = ctx->hash[3]; |
521 | e = ctx->hash[4]; | 516 | e = ctx->hash[4]; |
522 | 517 | ||
523 | #undef ch | 518 | /* 4 rounds of 20 operations each */ |
524 | #undef parity | 519 | cnt = 0; |
525 | #undef maj | 520 | for (i = 0; i < 4; i++) { |
526 | #undef rnd | 521 | j = 19; |
527 | #define ch(x,y,z) ((z) ^ ((x) & ((y) ^ (z)))) | 522 | do { |
528 | #define parity(x,y,z) ((x) ^ (y) ^ (z)) | 523 | uint32_t work; |
529 | #define maj(x,y,z) (((x) & (y)) | ((z) & ((x) | (y)))) | 524 | |
530 | /* A normal version as set out in the FIPS. */ | 525 | work = c ^ d; |
531 | #define rnd(f,k) \ | 526 | if (i == 0) { |
532 | do { \ | 527 | work = (work & b) ^ d; |
533 | uint32_t T = a; \ | 528 | if (j <= 3) |
534 | a = rotl32(a, 5) + f(b, c, d) + e + k + W[t]; \ | 529 | goto ge16; |
535 | e = d; \ | 530 | /* Used to do SWAP_BE32 here, but this |
536 | d = c; \ | 531 | * requires ctx (see comment above) */ |
537 | c = rotl32(b, 30); \ | 532 | work += W[cnt]; |
538 | b = T; \ | 533 | } else { |
539 | } while (0) | 534 | if (i == 2) |
540 | 535 | work = ((b | c) & d) | (b & c); | |
541 | for (t = 0; t < 20; ++t) | 536 | else /* i = 1 or 3 */ |
542 | rnd(ch, 0x5a827999); | 537 | work ^= b; |
543 | 538 | ge16: | |
544 | for (/*t = 20*/; t < 40; ++t) | 539 | W[cnt] = W[cnt+16] = rotl32(W[cnt+13] ^ W[cnt+8] ^ W[cnt+2] ^ W[cnt], 1); |
545 | rnd(parity, 0x6ed9eba1); | 540 | work += W[cnt]; |
546 | 541 | } | |
547 | for (/*t = 40*/; t < 60; ++t) | 542 | work += e + rotl32(a, 5) + rconsts[i]; |
548 | rnd(maj, 0x8f1bbcdc); | 543 | |
549 | 544 | /* Rotate by one for next time */ | |
550 | for (/*t = 60*/; t < 80; ++t) | 545 | e = d; |
551 | rnd(parity, 0xca62c1d6); | 546 | d = c; |
552 | #undef ch | 547 | c = /* b = */ rotl32(b, 30); |
553 | #undef parity | 548 | b = a; |
554 | #undef maj | 549 | a = work; |
555 | #undef rnd | 550 | cnt = (cnt + 1) & 15; |
551 | } while (--j >= 0); | ||
552 | } | ||
556 | 553 | ||
557 | ctx->hash[0] += a; | 554 | ctx->hash[0] += a; |
558 | ctx->hash[1] += b; | 555 | ctx->hash[1] += b; |
diff --git a/libbb/human_readable.c b/libbb/human_readable.c index 22dc5d23f..50cbe41bb 100644 --- a/libbb/human_readable.c +++ b/libbb/human_readable.c | |||
@@ -94,7 +94,7 @@ const char* FAST_FUNC make_human_readable_str(unsigned long long val, | |||
94 | 94 | ||
95 | /* Convert unsigned long long value into compact 5-char representation. | 95 | /* Convert unsigned long long value into compact 5-char representation. |
96 | * String is not terminated (buf[5] is untouched) */ | 96 | * String is not terminated (buf[5] is untouched) */ |
97 | void FAST_FUNC smart_ulltoa5(unsigned long long ul, char buf[6], const char *scale) | 97 | void FAST_FUNC smart_ulltoa5(unsigned long long ul, char buf[5], const char *scale) |
98 | { | 98 | { |
99 | const char *fmt; | 99 | const char *fmt; |
100 | char c; | 100 | char c; |
@@ -150,7 +150,7 @@ void FAST_FUNC smart_ulltoa5(unsigned long long ul, char buf[6], const char *sca | |||
150 | /* Convert unsigned long long value into compact 4-char | 150 | /* Convert unsigned long long value into compact 4-char |
151 | * representation. Examples: "1234", "1.2k", " 27M", "123T" | 151 | * representation. Examples: "1234", "1.2k", " 27M", "123T" |
152 | * String is not terminated (buf[4] is untouched) */ | 152 | * String is not terminated (buf[4] is untouched) */ |
153 | void FAST_FUNC smart_ulltoa4(unsigned long long ul, char buf[5], const char *scale) | 153 | void FAST_FUNC smart_ulltoa4(unsigned long long ul, char buf[4], const char *scale) |
154 | { | 154 | { |
155 | const char *fmt; | 155 | const char *fmt; |
156 | char c; | 156 | char c; |
diff --git a/libbb/parse_config.c b/libbb/parse_config.c index 3fff9f212..9dbfaf5d7 100644 --- a/libbb/parse_config.c +++ b/libbb/parse_config.c | |||
@@ -187,19 +187,7 @@ again: | |||
187 | 187 | ||
188 | #if 0 /* unused so far */ | 188 | #if 0 /* unused so far */ |
189 | if (flags & PARSE_ESCAPE) { | 189 | if (flags & PARSE_ESCAPE) { |
190 | const char *from; | 190 | strcpy_and_process_escape_sequences(tokens[t], tokens[t]); |
191 | char *to; | ||
192 | |||
193 | from = to = tokens[t]; | ||
194 | while (*from) { | ||
195 | if (*from == '\\') { | ||
196 | from++; | ||
197 | *to++ = bb_process_escape_sequence(&from); | ||
198 | } else { | ||
199 | *to++ = *from++; | ||
200 | } | ||
201 | } | ||
202 | *to = '\0'; | ||
203 | } | 191 | } |
204 | #endif | 192 | #endif |
205 | /* Skip possible delimiters */ | 193 | /* Skip possible delimiters */ |
diff --git a/libbb/process_escape_sequence.c b/libbb/process_escape_sequence.c index 82cbe10dc..346ecfa1e 100644 --- a/libbb/process_escape_sequence.c +++ b/libbb/process_escape_sequence.c | |||
@@ -18,52 +18,42 @@ | |||
18 | 18 | ||
19 | char FAST_FUNC bb_process_escape_sequence(const char **ptr) | 19 | char FAST_FUNC bb_process_escape_sequence(const char **ptr) |
20 | { | 20 | { |
21 | /* bash builtin "echo -e '\ec'" interprets \e as ESC, | ||
22 | * but coreutils "/bin/echo -e '\ec'" does not. | ||
23 | * manpages tend to support coreutils way. | ||
24 | * Update: coreutils added support for \e on 28 Oct 2009. */ | ||
25 | static const char charmap[] ALIGN1 = { | ||
26 | 'a', 'b', 'e', 'f', 'n', 'r', 't', 'v', '\\', 0, | ||
27 | '\a', '\b', 27, '\f', '\n', '\r', '\t', '\v', '\\', '\\' }; | ||
28 | |||
29 | const char *p; | ||
30 | const char *q; | 21 | const char *q; |
31 | unsigned num_digits; | 22 | unsigned num_digits; |
32 | unsigned r; | ||
33 | unsigned n; | 23 | unsigned n; |
34 | unsigned d; | ||
35 | unsigned base; | 24 | unsigned base; |
36 | 25 | ||
37 | num_digits = n = 0; | 26 | num_digits = n = 0; |
38 | base = 8; | 27 | base = 8; |
39 | q = *ptr; | 28 | q = *ptr; |
40 | 29 | ||
41 | #ifdef WANT_HEX_ESCAPES | 30 | if (WANT_HEX_ESCAPES && *q == 'x') { |
42 | if (*q == 'x') { | ||
43 | ++q; | 31 | ++q; |
44 | base = 16; | 32 | base = 16; |
45 | ++num_digits; | 33 | ++num_digits; |
46 | } | 34 | } |
47 | #endif | ||
48 | 35 | ||
49 | /* bash requires leading 0 in octal escapes: | 36 | /* bash requires leading 0 in octal escapes: |
50 | * \02 works, \2 does not (prints \ and 2). | 37 | * \02 works, \2 does not (prints \ and 2). |
51 | * We treat \2 as a valid octal escape sequence. */ | 38 | * We treat \2 as a valid octal escape sequence. */ |
52 | do { | 39 | do { |
53 | d = (unsigned char)(*q) - '0'; | 40 | unsigned r; |
54 | #ifdef WANT_HEX_ESCAPES | 41 | #if !WANT_HEX_ESCAPES |
55 | if (d >= 10) { | 42 | unsigned d = (unsigned char)(*q) - '0'; |
56 | d = (unsigned char)(_tolower(*q)) - 'a' + 10; | 43 | #else |
57 | } | 44 | unsigned d = (unsigned char)_tolower(*q) - '0'; |
45 | if (d >= 10) | ||
46 | d += ('0' - 'a' + 10); | ||
58 | #endif | 47 | #endif |
59 | |||
60 | if (d >= base) { | 48 | if (d >= base) { |
61 | #ifdef WANT_HEX_ESCAPES | 49 | if (WANT_HEX_ESCAPES && base == 16) { |
62 | if ((base == 16) && (!--num_digits)) { | 50 | --num_digits; |
63 | /* return '\\'; */ | 51 | if (num_digits == 0) { |
64 | --q; | 52 | /* \x<bad_char>: return '\', |
53 | * leave ptr pointing to x */ | ||
54 | return '\\'; | ||
55 | } | ||
65 | } | 56 | } |
66 | #endif | ||
67 | break; | 57 | break; |
68 | } | 58 | } |
69 | 59 | ||
@@ -76,21 +66,47 @@ char FAST_FUNC bb_process_escape_sequence(const char **ptr) | |||
76 | ++q; | 66 | ++q; |
77 | } while (++num_digits < 3); | 67 | } while (++num_digits < 3); |
78 | 68 | ||
79 | if (num_digits == 0) { /* mnemonic escape sequence? */ | 69 | if (num_digits == 0) { |
80 | p = charmap; | 70 | /* Not octal or hex escape sequence. |
71 | * Is it one-letter one? */ | ||
72 | |||
73 | /* bash builtin "echo -e '\ec'" interprets \e as ESC, | ||
74 | * but coreutils "/bin/echo -e '\ec'" does not. | ||
75 | * Manpages tend to support coreutils way. | ||
76 | * Update: coreutils added support for \e on 28 Oct 2009. */ | ||
77 | static const char charmap[] ALIGN1 = { | ||
78 | 'a', 'b', 'e', 'f', 'n', 'r', 't', 'v', '\\', '\0', | ||
79 | '\a', '\b', 27, '\f', '\n', '\r', '\t', '\v', '\\', '\\', | ||
80 | }; | ||
81 | const char *p = charmap; | ||
81 | do { | 82 | do { |
82 | if (*p == *q) { | 83 | if (*p == *q) { |
83 | q++; | 84 | q++; |
84 | break; | 85 | break; |
85 | } | 86 | } |
86 | } while (*++p); | 87 | } while (*++p != '\0'); |
87 | /* p points to found escape char or NUL, | 88 | /* p points to found escape char or NUL, |
88 | * advance it and find what it translates to */ | 89 | * advance it and find what it translates to. |
89 | p += sizeof(charmap) / 2; | 90 | * Note that \NUL and unrecognized sequence \z return '\' |
90 | n = *p; | 91 | * and leave ptr pointing to NUL or z. */ |
92 | n = p[sizeof(charmap) / 2]; | ||
91 | } | 93 | } |
92 | 94 | ||
93 | *ptr = q; | 95 | *ptr = q; |
94 | 96 | ||
95 | return (char) n; | 97 | return (char) n; |
96 | } | 98 | } |
99 | |||
100 | char* FAST_FUNC strcpy_and_process_escape_sequences(char *dst, const char *src) | ||
101 | { | ||
102 | while (1) { | ||
103 | char c, c1; | ||
104 | c = c1 = *src++; | ||
105 | if (c1 == '\\') | ||
106 | c1 = bb_process_escape_sequence(&src); | ||
107 | *dst = c1; | ||
108 | if (c == '\0') | ||
109 | return dst; | ||
110 | dst++; | ||
111 | } | ||
112 | } | ||