From b8173b603f57dcf918a67f1ec00763ab5f4e1cf8 Mon Sep 17 00:00:00 2001 From: Lauri Kasanen Date: Mon, 14 Jan 2013 05:20:50 +0100 Subject: sha3sum: new applet function old new delta KeccakF - 496 +496 KeccakF_RoundConstants - 192 +192 sha3_hash - 171 +171 sha3_end - 40 +40 hash_file 274 299 +25 KeccakF_RotationConstants - 25 +25 KeccakF_PiLane - 25 +25 packed_usage 29213 29232 +19 sha3_begin - 18 +18 KeccakF_Mod5 - 10 +10 applet_names 2445 2453 +8 applet_main 1420 1424 +4 applet_nameofs 710 712 +2 ------------------------------------------------------------------------------ (add/remove: 8/0 grow/shrink: 9/7 up/down: 1049/-54) Total: ~995 bytes Signed-off-by: Lauri Kasanen Signed-off-by: Denys Vlasenko --- libbb/hash_md5_sha.c | 194 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 194 insertions(+) (limited to 'libbb') diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index a313c2a65..06a2400b5 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -31,6 +31,11 @@ static ALWAYS_INLINE uint64_t rotr64(uint64_t x, unsigned n) return (x >> n) | (x << (64 - n)); } +/* rotl64 only used for sha3 currently */ +static ALWAYS_INLINE uint64_t rotl64(uint64_t x, unsigned n) +{ + return (x << n) | (x >> (64 - n)); +} /* Feed data through a temporary buffer. * The internal buffer remembers previous data until it has 64 @@ -896,3 +901,192 @@ void FAST_FUNC sha512_end(sha512_ctx_t *ctx, void *resbuf) } memcpy(resbuf, ctx->hash, sizeof(ctx->hash)); } + + +/* + * The Keccak sponge function, designed by Guido Bertoni, Joan Daemen, + * Michael Peeters and Gilles Van Assche. For more information, feedback or + * questions, please refer to our website: http://keccak.noekeon.org/ + * + * Implementation by Ronny Van Keer, + * hereby denoted as "the implementer". + * + * To the extent possible under law, the implementer has waived all copyright + * and related or neighboring rights to the source code in this file. + * http://creativecommons.org/publicdomain/zero/1.0/ + * + * Busybox modifications (C) Lauri Kasanen, under the GPLv2. + */ + +enum { + cKeccakR_SizeInBytes = 576 / 8, + cKeccakNumberOfRounds = 24, +}; + +static const uint64_t KeccakF_RoundConstants[cKeccakNumberOfRounds] = { + 0x0000000000000001ULL, + 0x0000000000008082ULL, + 0x800000000000808aULL, + 0x8000000080008000ULL, + 0x000000000000808bULL, + 0x0000000080000001ULL, + 0x8000000080008081ULL, + 0x8000000000008009ULL, + 0x000000000000008aULL, + 0x0000000000000088ULL, + 0x0000000080008009ULL, + 0x000000008000000aULL, + 0x000000008000808bULL, + 0x800000000000008bULL, + 0x8000000000008089ULL, + 0x8000000000008003ULL, + 0x8000000000008002ULL, + 0x8000000000000080ULL, + 0x000000000000800aULL, + 0x800000008000000aULL, + 0x8000000080008081ULL, + 0x8000000000008080ULL, + 0x0000000080000001ULL, + 0x8000000080008008ULL +}; + +static const uint8_t KeccakF_RotationConstants[25] = { + 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 27, 41, 56, 8, 25, 43, 62, + 18, 39, 61, 20, 44 +}; + +static const uint8_t KeccakF_PiLane[25] = { + 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 15, 23, 19, 13, 12, 2, 20, + 14, 22, 9, 6, 1 +}; + +static const uint8_t KeccakF_Mod5[10] = { + 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 +}; + +static void KeccakF(uint64_t *state) +{ + uint8_t x, y; + uint64_t temp; + uint64_t BC[5]; + int round; + + if (BB_BIG_ENDIAN) { + for (x = 0; x < 25; x++) { + state[x] = SWAP_LE64(state[x]); + } + } + + for (round = 0; round < cKeccakNumberOfRounds; ++round) { + /* Theta */ + for (x = 0; x < 5; ++x) { + BC[x] = state[x] ^ state[5 + x] ^ state[10 + x] ^ + state[15 + x] ^ state[20 + x]; + } + for (x = 0; x < 5; ++x) { + temp = BC[KeccakF_Mod5[x + 4]] ^ + rotl64(BC[KeccakF_Mod5[x + 1]], 1); + + for (y = 0; y <= 20; y += 5) { + state[y + x] ^= temp; + } + } + + /* Rho Pi */ + temp = state[1]; + for (x = 0; x < 24; ++x) { + BC[0] = state[KeccakF_PiLane[x]]; + state[KeccakF_PiLane[x]] = + rotl64(temp, KeccakF_RotationConstants[x]); + temp = BC[0]; + } + + /* Chi */ + for (y = 0; y < 25; y += 5) { + BC[0] = state[y + 0]; + BC[1] = state[y + 1]; + BC[2] = state[y + 2]; + BC[3] = state[y + 3]; + BC[4] = state[y + 4]; + for (x = 0; x < 5; ++x) { + state[y + x] = + BC[x] ^ ((~BC[KeccakF_Mod5[x + 1]]) & + BC[KeccakF_Mod5[x + 2]]); + } + } + + /* Iota */ + state[0] ^= KeccakF_RoundConstants[round]; + } + + if (BB_BIG_ENDIAN) { + for (x = 0; x < 25; x++) { + state[x] = SWAP_LE64(state[x]); + } + } +} + +void FAST_FUNC sha3_begin(sha3_ctx_t *ctx) +{ + memset(ctx, 0, sizeof(*ctx)); +} + +void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buf, size_t bytes) +{ + const uint8_t *data = buf; + + /* If already data in queue, continue queuing first */ + while (bytes != 0 && ctx->bytes_queued != 0) { + uint8_t *buffer = (uint8_t*)ctx->state; + buffer[ctx->bytes_queued] ^= *data++; + bytes--; + ctx->bytes_queued++; + if (ctx->bytes_queued == cKeccakR_SizeInBytes) { + KeccakF(ctx->state); + ctx->bytes_queued = 0; + } + } + + /* Absorb complete blocks */ + while (bytes >= cKeccakR_SizeInBytes) { + /* XOR data onto beginning of state[]. + * We try to be efficient - operate on word at a time, not byte. + * Yet safe wrt unaligned access: can't just use "*(long*)data"... + */ + unsigned count = cKeccakR_SizeInBytes / sizeof(long); + long *buffer = (long*)ctx->state; + do { + long v; + move_from_unaligned_long(v, (long*)data); + *buffer++ ^= v; + data += sizeof(long); + } while (--count); + + KeccakF(ctx->state); + bytes -= cKeccakR_SizeInBytes; + } + + /* Queue remaining data bytes */ + while (bytes != 0) { + uint8_t *buffer = (uint8_t*)ctx->state; + buffer[ctx->bytes_queued] ^= *data++; + ctx->bytes_queued++; + bytes--; + } +} + +void FAST_FUNC sha3_end(sha3_ctx_t *ctx, uint8_t *hashval) +{ + /* Padding */ + uint8_t *buffer = (uint8_t*)ctx->state; + /* 0 is the number of bits in last, incomplete byte + * (that is, zero: we never have incomplete bytes): + */ + buffer[ctx->bytes_queued] ^= 1 << 0; + buffer[cKeccakR_SizeInBytes - 1] ^= 0x80; + + KeccakF(ctx->state); + + /* Output */ + memcpy(hashval, ctx->state, 64); +} -- cgit v1.2.3-55-g6feb From 60cb48ca50fcff24aa6c3927f51e4a508fa118f4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 14 Jan 2013 15:57:44 +0100 Subject: whitespace cleanup. no code changes Signed-off-by: Denys Vlasenko --- archival/cpio.c | 30 ++++++------- archival/libarchive/decompress_gunzip.c | 4 +- archival/libarchive/decompress_uncompress.c | 4 +- archival/libarchive/lzo1x_9x.c | 12 +++--- archival/libarchive/lzo1x_c.c | 2 +- archival/libarchive/lzo1x_d.c | 2 +- archival/lzop.c | 8 ++-- coreutils/cal.c | 7 +-- coreutils/mknod.c | 2 +- coreutils/od_bloaty.c | 4 +- coreutils/stat.c | 58 ++++++++++++++----------- coreutils/stty.c | 2 +- coreutils/test.c | 2 +- editors/awk.c | 2 +- editors/diff.c | 2 +- editors/vi.c | 2 +- findutils/grep.c | 2 +- init/init.c | 2 +- libbb/inet_common.c | 4 +- libbb/loop.c | 6 +-- libbb/procps.c | 2 +- libbb/selinux_common.c | 2 +- libpwdgrp/pwd_grp.c | 14 +++--- miscutils/devfsd.c | 26 +++++------ miscutils/hdparm.c | 4 +- miscutils/last_fancy.c | 16 +++---- modutils/rmmod.c | 2 +- networking/brctl.c | 8 ++-- networking/ether-wake.c | 8 ++-- networking/ifenslave.c | 2 +- networking/interface.c | 2 +- networking/libiproute/ipaddress.c | 10 +++-- networking/libiproute/iprule.c | 14 +++--- networking/libiproute/iptunnel.c | 2 +- networking/netstat.c | 2 +- networking/route.c | 4 +- networking/tc.c | 5 ++- networking/traceroute.c | 7 +-- networking/udhcp/dhcpc.c | 2 +- procps/nmeter.c | 2 +- procps/top.c | 2 +- runit/runsv.c | 2 +- runit/svlogd.c | 4 +- selinux/chcon.c | 20 ++++----- selinux/runcon.c | 10 ++--- selinux/sestatus.c | 2 +- selinux/setfiles.c | 19 ++++---- shell/ash.c | 8 ++-- shell/hush.c | 4 +- shell/math.c | 2 +- util-linux/fdisk_osf.c | 5 +-- util-linux/fsck_minix.c | 67 ++++++++++++++--------------- util-linux/getopt.c | 2 +- util-linux/ipcs.c | 2 +- util-linux/volume_id/nilfs.c | 2 +- util-linux/volume_id/ntfs.c | 4 +- util-linux/volume_id/udf.c | 2 +- util-linux/volume_id/unused_msdos.c | 2 +- util-linux/volume_id/unused_silicon_raid.c | 2 +- 59 files changed, 233 insertions(+), 219 deletions(-) (limited to 'libbb') diff --git a/archival/cpio.c b/archival/cpio.c index 98cc18fa0..699c6dbb7 100644 --- a/archival/cpio.c +++ b/archival/cpio.c @@ -253,24 +253,24 @@ static NOINLINE int cpio_o(void) } bytes += printf("070701" - "%08X%08X%08X%08X%08X%08X%08X" - "%08X%08X%08X%08X" /* GNU cpio uses uppercase hex */ + "%08X%08X%08X%08X%08X%08X%08X" + "%08X%08X%08X%08X" /* GNU cpio uses uppercase hex */ /* strlen+1: */ "%08X" /* chksum: */ "00000000" /* (only for "070702" files) */ /* name,NUL: */ "%s%c", - (unsigned)(uint32_t) st.st_ino, - (unsigned)(uint32_t) st.st_mode, - (unsigned)(uint32_t) st.st_uid, - (unsigned)(uint32_t) st.st_gid, - (unsigned)(uint32_t) st.st_nlink, - (unsigned)(uint32_t) st.st_mtime, - (unsigned)(uint32_t) st.st_size, - (unsigned)(uint32_t) major(st.st_dev), - (unsigned)(uint32_t) minor(st.st_dev), - (unsigned)(uint32_t) major(st.st_rdev), - (unsigned)(uint32_t) minor(st.st_rdev), - (unsigned)(strlen(name) + 1), - name, '\0'); + (unsigned)(uint32_t) st.st_ino, + (unsigned)(uint32_t) st.st_mode, + (unsigned)(uint32_t) st.st_uid, + (unsigned)(uint32_t) st.st_gid, + (unsigned)(uint32_t) st.st_nlink, + (unsigned)(uint32_t) st.st_mtime, + (unsigned)(uint32_t) st.st_size, + (unsigned)(uint32_t) major(st.st_dev), + (unsigned)(uint32_t) minor(st.st_dev), + (unsigned)(uint32_t) major(st.st_rdev), + (unsigned)(uint32_t) minor(st.st_rdev), + (unsigned)(strlen(name) + 1), + name, '\0'); bytes = cpio_pad4(bytes); if (st.st_size) { diff --git a/archival/libarchive/decompress_gunzip.c b/archival/libarchive/decompress_gunzip.c index 2d5ab3eb3..4e6b138c3 100644 --- a/archival/libarchive/decompress_gunzip.c +++ b/archival/libarchive/decompress_gunzip.c @@ -293,8 +293,8 @@ static unsigned fill_bitbuffer(STATE_PARAM unsigned bitbuffer, unsigned *current * m: maximum lookup bits, returns actual */ static int huft_build(const unsigned *b, const unsigned n, - const unsigned s, const unsigned short *d, - const unsigned char *e, huft_t **t, unsigned *m) + const unsigned s, const unsigned short *d, + const unsigned char *e, huft_t **t, unsigned *m) { unsigned a; /* counter for codes of length k */ unsigned c[BMAX + 1]; /* bit length count table */ diff --git a/archival/libarchive/decompress_uncompress.c b/archival/libarchive/decompress_uncompress.c index 3826a65ea..53c27080f 100644 --- a/archival/libarchive/decompress_uncompress.c +++ b/archival/libarchive/decompress_uncompress.c @@ -235,8 +235,8 @@ unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd) p = &inbuf[posbits >> 3]; bb_error_msg ("insize:%d posbits:%d inbuf:%02X %02X %02X %02X %02X (%d)", - insize, posbits, p[-1], p[0], p[1], p[2], p[3], - (posbits & 07)); + insize, posbits, p[-1], p[0], p[1], p[2], p[3], + (posbits & 07)); */ bb_error_msg("corrupted data"); goto err; diff --git a/archival/libarchive/lzo1x_9x.c b/archival/libarchive/lzo1x_9x.c index 483205155..897132987 100644 --- a/archival/libarchive/lzo1x_9x.c +++ b/archival/libarchive/lzo1x_9x.c @@ -644,7 +644,7 @@ static int len_of_coded_match(unsigned m_len, unsigned m_off, unsigned lit) static int min_gain(unsigned ahead, unsigned lit1, - unsigned lit2, int l1, int l2, int l3) + unsigned lit2, int l1, int l2, int l3) { int lazy_match_min_gain = 0; @@ -673,7 +673,7 @@ static int min_gain(unsigned ahead, unsigned lit1, #if defined(SWD_BEST_OFF) static void better_match(const lzo_swd_p swd, - unsigned *m_len, unsigned *m_off) + unsigned *m_len, unsigned *m_off) { if (*m_len <= M2_MIN_LEN) return; @@ -914,8 +914,8 @@ int lzo1x_999_compress_level(const uint8_t *in, unsigned in_len, compression_level -= 7; return lzo1x_999_compress_internal(in, in_len, out, out_len, wrkmem, - c[compression_level].good_length, - c[compression_level].max_lazy, - c[compression_level].max_chain, - c[compression_level].use_best_off); + c[compression_level].good_length, + c[compression_level].max_lazy, + c[compression_level].max_chain, + c[compression_level].use_best_off); } diff --git a/archival/libarchive/lzo1x_c.c b/archival/libarchive/lzo1x_c.c index cc86f74b1..8c77072ab 100644 --- a/archival/libarchive/lzo1x_c.c +++ b/archival/libarchive/lzo1x_c.c @@ -15,7 +15,7 @@ The LZO library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License diff --git a/archival/libarchive/lzo1x_d.c b/archival/libarchive/lzo1x_d.c index 348a85510..9bc1270da 100644 --- a/archival/libarchive/lzo1x_d.c +++ b/archival/libarchive/lzo1x_d.c @@ -15,7 +15,7 @@ The LZO library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License diff --git a/archival/lzop.c b/archival/lzop.c index ec4e784ed..56003d421 100644 --- a/archival/lzop.c +++ b/archival/lzop.c @@ -14,7 +14,7 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License @@ -116,7 +116,7 @@ static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len, unsigned nl; unsigned long o_m1_a = 0, o_m1_b = 0, o_m2 = 0, o_m3_a = 0, o_m3_b = 0; -// LZO_UNUSED(wrkmem); +// LZO_UNUSED(wrkmem); *out_len = 0; @@ -346,8 +346,8 @@ static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len, return LZO_E_EOF_NOT_FOUND; eof_found: -// LZO_UNUSED(o_m1_a); LZO_UNUSED(o_m1_b); LZO_UNUSED(o_m2); -// LZO_UNUSED(o_m3_a); LZO_UNUSED(o_m3_b); +// LZO_UNUSED(o_m1_a); LZO_UNUSED(o_m1_b); LZO_UNUSED(o_m2); +// LZO_UNUSED(o_m3_a); LZO_UNUSED(o_m3_b); *out_len = pd(op, out); return (ip == ip_end ? LZO_E_OK : (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); diff --git a/coreutils/cal.c b/coreutils/cal.c index 158b23fbc..0b2307349 100644 --- a/coreutils/cal.c +++ b/coreutils/cal.c @@ -181,10 +181,11 @@ int cal_main(int argc UNUSED_PARAM, char **argv) sprintf(lineout, "%u", year); center(lineout, - (WEEK_LEN * 3 + HEAD_SEP * 2) - + julian * (J_WEEK_LEN * 2 + HEAD_SEP + (WEEK_LEN * 3 + HEAD_SEP * 2) + + julian * (J_WEEK_LEN * 2 + HEAD_SEP - (WEEK_LEN * 3 + HEAD_SEP * 2)), - 0); + 0 + ); puts("\n"); /* two \n's */ for (i = 0; i < 12; i++) { day_array(i + 1, year, days[i]); diff --git a/coreutils/mknod.c b/coreutils/mknod.c index 32d3659ac..aa0450481 100644 --- a/coreutils/mknod.c +++ b/coreutils/mknod.c @@ -59,7 +59,7 @@ int mknod_main(int argc, char **argv) /* Autodetect what the system supports; these macros should * optimize out to two constants. */ dev = makedev(xatoul_range(argv[2], 0, major(UINT_MAX)), - xatoul_range(argv[3], 0, minor(UINT_MAX))); + xatoul_range(argv[3], 0, minor(UINT_MAX))); } } diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c index 2f6650153..b408a8477 100644 --- a/coreutils/od_bloaty.c +++ b/coreutils/od_bloaty.c @@ -1021,12 +1021,12 @@ dump(off_t current_offset, off_t end_offset) l_c_m = get_lcm(); /* Make bytes_to_write the smallest multiple of l_c_m that - is at least as large as n_bytes_read. */ + is at least as large as n_bytes_read. */ bytes_to_write = l_c_m * ((n_bytes_read + l_c_m - 1) / l_c_m); memset(block[idx] + n_bytes_read, 0, bytes_to_write - n_bytes_read); write_block(current_offset, bytes_to_write, - block[idx ^ 1], block[idx]); + block[idx ^ 1], block[idx]); current_offset += n_bytes_read; } diff --git a/coreutils/stat.c b/coreutils/stat.c index e38c8f6b0..c8677ebaa 100644 --- a/coreutils/stat.c +++ b/coreutils/stat.c @@ -591,37 +591,43 @@ static bool do_stat(const char *filename, const char *format) # else if (option_mask32 & OPT_TERSE) { format = (option_mask32 & OPT_SELINUX ? - "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o %C\n": - "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o\n"); + "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o %C\n" + : + "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o\n" + ); } else { if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) { format = (option_mask32 & OPT_SELINUX ? - " File: %N\n" - " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" - "Device: %Dh/%dd\tInode: %-10i Links: %-5h" - " Device type: %t,%T\n" - "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" - " S_Context: %C\n" - "Access: %x\n" "Modify: %y\n" "Change: %z\n": - " File: %N\n" - " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" - "Device: %Dh/%dd\tInode: %-10i Links: %-5h" - " Device type: %t,%T\n" - "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" - "Access: %x\n" "Modify: %y\n" "Change: %z\n"); + " File: %N\n" + " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" + "Device: %Dh/%dd\tInode: %-10i Links: %-5h" + " Device type: %t,%T\n" + "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" + " S_Context: %C\n" + "Access: %x\n" "Modify: %y\n" "Change: %z\n" + : + " File: %N\n" + " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" + "Device: %Dh/%dd\tInode: %-10i Links: %-5h" + " Device type: %t,%T\n" + "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" + "Access: %x\n" "Modify: %y\n" "Change: %z\n" + ); } else { format = (option_mask32 & OPT_SELINUX ? - " File: %N\n" - " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" - "Device: %Dh/%dd\tInode: %-10i Links: %h\n" - "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" - "S_Context: %C\n" - "Access: %x\n" "Modify: %y\n" "Change: %z\n": - " File: %N\n" - " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" - "Device: %Dh/%dd\tInode: %-10i Links: %h\n" - "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" - "Access: %x\n" "Modify: %y\n" "Change: %z\n"); + " File: %N\n" + " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" + "Device: %Dh/%dd\tInode: %-10i Links: %h\n" + "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" + "S_Context: %C\n" + "Access: %x\n" "Modify: %y\n" "Change: %z\n" + : + " File: %N\n" + " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" + "Device: %Dh/%dd\tInode: %-10i Links: %h\n" + "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" + "Access: %x\n" "Modify: %y\n" "Change: %z\n" + ); } } # endif diff --git a/coreutils/stty.c b/coreutils/stty.c index 0668cf7be..96754dd84 100644 --- a/coreutils/stty.c +++ b/coreutils/stty.c @@ -1056,7 +1056,7 @@ static void do_display(const struct termios *mode, int all) } #endif wrapf("%s = %s;", nth_string(control_name, i), - visible(mode->c_cc[control_info[i].offset])); + visible(mode->c_cc[control_info[i].offset])); } #if VEOF == VMIN if ((mode->c_lflag & ICANON) == 0) diff --git a/coreutils/test.c b/coreutils/test.c index 0bc008e7c..4df505a05 100644 --- a/coreutils/test.c +++ b/coreutils/test.c @@ -610,7 +610,7 @@ static int test_eaccess(char *path, int mode) return 0; /* Root can execute any file that has any one of the execute - bits set. */ + * bits set. */ if (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) return 0; } diff --git a/editors/awk.c b/editors/awk.c index 42f6ef866..3224788c0 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -155,7 +155,7 @@ typedef struct tsplitter_s { /* simple token classes */ /* Order and hex values are very important!!! See next_token() */ -#define TC_SEQSTART 1 /* ( */ +#define TC_SEQSTART 1 /* ( */ #define TC_SEQTERM (1 << 1) /* ) */ #define TC_REGEXP (1 << 2) /* /.../ */ #define TC_OUTRDR (1 << 3) /* | > >> */ diff --git a/editors/diff.c b/editors/diff.c index 3a3334640..b08ded3a1 100644 --- a/editors/diff.c +++ b/editors/diff.c @@ -843,7 +843,7 @@ static void diffdir(char *p[2], const char *s_start) * add_to_dirlist will remove it. */ list[i].len = strlen(p[i]); recursive_action(p[i], ACTION_RECURSE | ACTION_FOLLOWLINKS, - add_to_dirlist, skip_dir, &list[i], 0); + add_to_dirlist, skip_dir, &list[i], 0); /* Sort dl alphabetically. * GNU diff does this ignoring any number of trailing dots. * We don't, so for us dotted files almost always are diff --git a/editors/vi.c b/editors/vi.c index e09e0d9c7..b1776c668 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -14,7 +14,7 @@ * add :help command * :map macros * if mark[] values were line numbers rather than pointers - * it would be easier to change the mark when add/delete lines + * it would be easier to change the mark when add/delete lines * More intelligence in refresh() * ":r !cmd" and "!cmd" to filter text through an external command * A true "undo" facility diff --git a/findutils/grep.c b/findutils/grep.c index f14d6e6c1..de4fcf5ad 100644 --- a/findutils/grep.c +++ b/findutils/grep.c @@ -638,7 +638,7 @@ int grep_main(int argc UNUSED_PARAM, char **argv) if (opts & OPT_C) { /* -C unsets prev -A and -B, but following -A or -B - may override it */ + * may override it */ if (!(opts & OPT_A)) /* not overridden */ lines_after = Copt; if (!(opts & OPT_B)) /* not overridden */ diff --git a/init/init.c b/init/init.c index 724894698..b84bdccbc 100644 --- a/init/init.c +++ b/init/init.c @@ -520,7 +520,7 @@ static pid_t run(const struct init_action *a) /* Log the process name and args */ message(L_LOG, "starting pid %d, tty '%s': '%s'", - getpid(), a->terminal, a->command); + getpid(), a->terminal, a->command); /* Now run it. The new program will take over this PID, * so nothing further in init.c should be run. */ diff --git a/libbb/inet_common.c b/libbb/inet_common.c index 7208db9ea..0f4fca1a2 100644 --- a/libbb/inet_common.c +++ b/libbb/inet_common.c @@ -97,7 +97,7 @@ char* FAST_FUNC INET_rresolve(struct sockaddr_in *s_in, int numeric, uint32_t ne if (s_in->sin_family != AF_INET) { #ifdef DEBUG bb_error_msg("rresolve: unsupported address family %d!", - s_in->sin_family); + s_in->sin_family); #endif errno = EAFNOSUPPORT; return NULL; @@ -195,7 +195,7 @@ char* FAST_FUNC INET6_rresolve(struct sockaddr_in6 *sin6, int numeric) if (sin6->sin6_family != AF_INET6) { #ifdef DEBUG bb_error_msg("rresolve: unsupported address family %d!", - sin6->sin6_family); + sin6->sin6_family); #endif errno = EAFNOSUPPORT; return NULL; diff --git a/libbb/loop.c b/libbb/loop.c index b3a520848..823fba079 100644 --- a/libbb/loop.c +++ b/libbb/loop.c @@ -150,9 +150,9 @@ int FAST_FUNC set_loop(char **device, const char *file, unsigned long long offse } /* If this block device already set up right, re-use it. - (Yes this is racy, but associating two loop devices with the same - file isn't pretty either. In general, mounting the same file twice - without using losetup manually is problematic.) + * (Yes this is racy, but associating two loop devices with the same + * file isn't pretty either. In general, mounting the same file twice + * without using losetup manually is problematic.) */ } else if (strcmp(file, (char *)loopinfo.lo_file_name) != 0 diff --git a/libbb/procps.c b/libbb/procps.c index b4557e797..5b68d3431 100644 --- a/libbb/procps.c +++ b/libbb/procps.c @@ -180,7 +180,7 @@ static char *skip_fields(char *str, int count) #if ENABLE_FEATURE_TOPMEM || ENABLE_PMAP int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total, - void (*cb)(struct smaprec *, void *), void *data) + void (*cb)(struct smaprec *, void *), void *data) { FILE *file; struct smaprec currec; diff --git a/libbb/selinux_common.c b/libbb/selinux_common.c index 62910e285..c2585557f 100644 --- a/libbb/selinux_common.c +++ b/libbb/selinux_common.c @@ -10,7 +10,7 @@ #include context_t FAST_FUNC set_security_context_component(security_context_t cur_context, - char *user, char *role, char *type, char *range) + char *user, char *role, char *type, char *range) { context_t con = context_new(cur_context); if (!con) diff --git a/libpwdgrp/pwd_grp.c b/libpwdgrp/pwd_grp.c index edf53f350..2060d7811 100644 --- a/libpwdgrp/pwd_grp.c +++ b/libpwdgrp/pwd_grp.c @@ -300,8 +300,8 @@ struct group *getgrgid(gid_t gid) * to have been created as a reentrant version of the non-standard * functions getspuid. Why getspuid was added, I do not know. */ int getspuid_r(uid_t uid, struct spwd *__restrict resultbuf, - char *__restrict buffer, size_t buflen, - struct spwd **__restrict result) + char *__restrict buffer, size_t buflen, + struct spwd **__restrict result) { int rv; struct passwd *pp; @@ -403,8 +403,8 @@ void endpwent(void) int getpwent_r(struct passwd *__restrict resultbuf, - char *__restrict buffer, size_t buflen, - struct passwd **__restrict result) + char *__restrict buffer, size_t buflen, + struct passwd **__restrict result) { int rv; @@ -451,8 +451,8 @@ void endgrent(void) } int getgrent_r(struct group *__restrict resultbuf, - char *__restrict buffer, size_t buflen, - struct group **__restrict result) + char *__restrict buffer, size_t buflen, + struct group **__restrict result) { int rv; @@ -501,7 +501,7 @@ void endspent(void) } int getspent_r(struct spwd *resultbuf, char *buffer, - size_t buflen, struct spwd **result) + size_t buflen, struct spwd **result) { int rv; diff --git a/miscutils/devfsd.c b/miscutils/devfsd.c index 6493fe4f1..2e87261cf 100644 --- a/miscutils/devfsd.c +++ b/miscutils/devfsd.c @@ -219,7 +219,7 @@ static void action_execute(const struct devfsd_notify_struct *, const struct con const regmatch_t *, unsigned); static void action_modload(const struct devfsd_notify_struct *info, const struct config_entry_struct *entry); static void action_copy(const struct devfsd_notify_struct *, const struct config_entry_struct *, - const regmatch_t *, unsigned); + const regmatch_t *, unsigned); static void action_compat(const struct devfsd_notify_struct *, unsigned); static void free_config(void); static void restore(char *spath, struct stat source_stat, int rootlen); @@ -229,12 +229,12 @@ static void signal_handler(int); static const char *get_variable(const char *, void *); static int make_dir_tree(const char *); static int expand_expression(char *, unsigned, const char *, const char *(*)(const char *, void *), void *, - const char *, const regmatch_t *, unsigned); + const char *, const regmatch_t *, unsigned); static void expand_regexp(char *, size_t, const char *, const char *, const regmatch_t *, unsigned); static const char *expand_variable( char *, unsigned, unsigned *, const char *, const char *(*)(const char *, void *), void *); static const char *get_variable_v2(const char *, const char *(*)(const char *, void *), void *); -static char get_old_ide_name(unsigned , unsigned); +static char get_old_ide_name(unsigned, unsigned); static char *write_old_sd_name(char *, unsigned, unsigned, const char *); /* busybox functions */ @@ -580,9 +580,9 @@ static void process_config_line(const char *line, unsigned long *event_mask) /*This action will pass "/dev/$devname"(i.e. "/dev/" prefixed to the device name) to the module loading facility. In addition, the /etc/modules.devfs configuration file is used.*/ - if (ENABLE_DEVFSD_MODLOAD) + if (ENABLE_DEVFSD_MODLOAD) new->action.what = AC_MODLOAD; - break; + break; case 6: /* EXECUTE */ new->action.what = AC_EXECUTE; num_args -= 3; @@ -750,7 +750,7 @@ static void action_permissions(const struct devfsd_notify_struct *info, } /* End Function action_permissions */ static void action_modload(const struct devfsd_notify_struct *info, - const struct config_entry_struct *entry UNUSED_PARAM) + const struct config_entry_struct *entry UNUSED_PARAM) /* [SUMMARY] Load a module. The devfs change. The config file entry. @@ -771,8 +771,8 @@ static void action_modload(const struct devfsd_notify_struct *info, } /* End Function action_modload */ static void action_execute(const struct devfsd_notify_struct *info, - const struct config_entry_struct *entry, - const regmatch_t *regexpr, unsigned int numexpr) + const struct config_entry_struct *entry, + const regmatch_t *regexpr, unsigned int numexpr) /* [SUMMARY] Execute a programme. The devfs change. The config file entry. @@ -1641,10 +1641,10 @@ st_expr_expand_out: /* Private functions follow */ static const char *expand_variable(char *buffer, unsigned int length, - unsigned int *out_pos, const char *input, - const char *(*func)(const char *variable, + unsigned int *out_pos, const char *input, + const char *(*func)(const char *variable, void *info), - void *info) + void *info) /* [SUMMARY] Expand a variable. The buffer to write to. The length of the output buffer. @@ -1786,8 +1786,8 @@ expand_variable_out: static const char *get_variable_v2(const char *variable, - const char *(*func)(const char *variable, void *info), - void *info) + const char *(*func)(const char *variable, void *info), + void *info) /* [SUMMARY] Get a variable from the environment or . The variable name. A function which will be used to get the variable. If this returns diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c index a97f3e7b5..9c6dbf468 100644 --- a/miscutils/hdparm.c +++ b/miscutils/hdparm.c @@ -1022,8 +1022,8 @@ static void identify(uint16_t *val) } if ((like_std > 3) && (val[CMDS_SUPP_1] & 0x0008)) { /* We print out elsewhere whether the APM feature is enabled or - not. If it's not enabled, let's not repeat the info; just print - nothing here. */ + * not. If it's not enabled, let's not repeat the info; just print + * nothing here. */ printf("\tAdvancedPM level: "); if ((val[ADV_PWR] & 0xFF00) == 0x4000) { uint8_t apm_level = val[ADV_PWR] & 0x00FF; diff --git a/miscutils/last_fancy.c b/miscutils/last_fancy.c index dc09b65fb..f687d7e16 100644 --- a/miscutils/last_fancy.c +++ b/miscutils/last_fancy.c @@ -93,14 +93,14 @@ static void show_entry(struct utmp *ut, int state, time_t dur_secs) } printf(HEADER_FORMAT, - ut->ut_user, - ut->ut_line, - show_wide ? INET6_ADDRSTRLEN : INET_ADDRSTRLEN, - show_wide ? INET6_ADDRSTRLEN : INET_ADDRSTRLEN, - ut->ut_host, - login_time, - logout_str, - duration_str); + ut->ut_user, + ut->ut_line, + show_wide ? INET6_ADDRSTRLEN : INET_ADDRSTRLEN, + show_wide ? INET6_ADDRSTRLEN : INET_ADDRSTRLEN, + ut->ut_host, + login_time, + logout_str, + duration_str); } static int get_ut_type(struct utmp *ut) diff --git a/modutils/rmmod.c b/modutils/rmmod.c index 4a4a91982..f13ff9eb6 100644 --- a/modutils/rmmod.c +++ b/modutils/rmmod.c @@ -60,7 +60,7 @@ int rmmod_main(int argc UNUSED_PARAM, char **argv) filename2modname(bname, modname); if (bb_delete_module(modname, flags)) bb_error_msg_and_die("can't unload '%s': %s", - modname, moderror(errno)); + modname, moderror(errno)); } return EXIT_SUCCESS; diff --git a/networking/brctl.c b/networking/brctl.c index b4f5809df..207b069aa 100644 --- a/networking/brctl.c +++ b/networking/brctl.c @@ -133,9 +133,9 @@ int brctl_main(int argc UNUSED_PARAM, char **argv) enum { ARG_addbr = 0, ARG_delbr, ARG_addif, ARG_delif IF_FEATURE_BRCTL_FANCY(, - ARG_stp, - ARG_setageing, ARG_setfd, ARG_sethello, ARG_setmaxage, - ARG_setpathcost, ARG_setportprio, ARG_setbridgeprio + ARG_stp, + ARG_setageing, ARG_setfd, ARG_sethello, ARG_setmaxage, + ARG_setpathcost, ARG_setportprio, ARG_setbridgeprio ) IF_FEATURE_BRCTL_SHOW(, ARG_show) }; @@ -285,7 +285,7 @@ int brctl_main(int argc UNUSED_PARAM, char **argv) bb_error_msg_and_die(bb_msg_invalid_arg, *argv, "port"); memset(ifidx, 0, sizeof ifidx); arm_ioctl(args, BRCTL_GET_PORT_LIST, (unsigned long)ifidx, - MAX_PORTS); + MAX_PORTS); xioctl(fd, SIOCDEVPRIVATE, &ifr); for (i = 0; i < MAX_PORTS; i++) { if (ifidx[i] == port) { diff --git a/networking/ether-wake.c b/networking/ether-wake.c index a73b0baea..bf09cd529 100644 --- a/networking/ether-wake.c +++ b/networking/ether-wake.c @@ -49,9 +49,9 @@ * Copyright 1999-2003 Donald Becker and Scyld Computing Corporation. * * The author may be reached as becker@scyld, or C/O - * Scyld Computing Corporation - * 914 Bay Ridge Road, Suite 220 - * Annapolis MD 21403 + * Scyld Computing Corporation + * 914 Bay Ridge Road, Suite 220 + * Annapolis MD 21403 * * Notes: * On some systems dropping root capability allows the process to be @@ -113,7 +113,7 @@ void bb_debug_dump_packet(unsigned char *outpack, int pktsize) * Host name * IP address string * MAC address string -*/ + */ static void get_dest_addr(const char *hostid, struct ether_addr *eaddr) { struct ether_addr *eap; diff --git a/networking/ifenslave.c b/networking/ifenslave.c index f7f87bc55..c3be8180b 100644 --- a/networking/ifenslave.c +++ b/networking/ifenslave.c @@ -270,7 +270,7 @@ static int set_if_addr(char *master_ifname, char *slave_ifname) if (res < 0) { ifr.ifr_addr.sa_family = AF_INET; memset(ifr.ifr_addr.sa_data, 0, - sizeof(ifr.ifr_addr.sa_data)); + sizeof(ifr.ifr_addr.sa_data)); } res = set_ifrname_and_do_ioctl(ifra[i].s_ioctl, &ifr, slave_ifname); diff --git a/networking/interface.c b/networking/interface.c index 4b9b9485d..9ae8b3f03 100644 --- a/networking/interface.c +++ b/networking/interface.c @@ -27,7 +27,7 @@ * {1.34} - 19980630 - Arnaldo Carvalho de Melo * - gettext instead of catgets for i18n * 10/1998 - Andi Kleen. Use interface list primitives. - * 20001008 - Bernd Eckenfels, Patch from RH for setting mtu + * 20001008 - Bernd Eckenfels, Patch from RH for setting mtu * (default AF was wrong) */ diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c index b3748e8c5..3fd3f4478 100644 --- a/networking/libiproute/ipaddress.c +++ b/networking/libiproute/ipaddress.c @@ -314,14 +314,16 @@ static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM, if (rta_tb[IFA_BROADCAST]) { printf("brd %s ", rt_addr_n2a(ifa->ifa_family, - RTA_DATA(rta_tb[IFA_BROADCAST]), - abuf, sizeof(abuf))); + RTA_DATA(rta_tb[IFA_BROADCAST]), + abuf, sizeof(abuf)) + ); } if (rta_tb[IFA_ANYCAST]) { printf("any %s ", rt_addr_n2a(ifa->ifa_family, - RTA_DATA(rta_tb[IFA_ANYCAST]), - abuf, sizeof(abuf))); + RTA_DATA(rta_tb[IFA_ANYCAST]), + abuf, sizeof(abuf)) + ); } printf("scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope, b1)); if (ifa->ifa_flags & IFA_F_SECONDARY) { diff --git a/networking/libiproute/iprule.c b/networking/libiproute/iprule.c index dd3265c7c..241a6bf9d 100644 --- a/networking/libiproute/iprule.c +++ b/networking/libiproute/iprule.c @@ -73,15 +73,17 @@ static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM, if (tb[RTA_SRC]) { if (r->rtm_src_len != host_len) { printf("%s/%u", rt_addr_n2a(r->rtm_family, - RTA_DATA(tb[RTA_SRC]), - abuf, sizeof(abuf)), + RTA_DATA(tb[RTA_SRC]), + abuf, sizeof(abuf)), r->rtm_src_len - ); + ); } else { fputs(format_host(r->rtm_family, - RTA_PAYLOAD(tb[RTA_SRC]), - RTA_DATA(tb[RTA_SRC]), - abuf, sizeof(abuf)), stdout); + RTA_PAYLOAD(tb[RTA_SRC]), + RTA_DATA(tb[RTA_SRC]), + abuf, sizeof(abuf)), + stdout + ); } } else if (r->rtm_src_len) { printf("0/%d", r->rtm_src_len); diff --git a/networking/libiproute/iptunnel.c b/networking/libiproute/iptunnel.c index 5942feafc..2b651b926 100644 --- a/networking/libiproute/iptunnel.c +++ b/networking/libiproute/iptunnel.c @@ -438,7 +438,7 @@ static void print_tunnel(struct ip_tunnel_parm *p) printf(" inherit"); if (p->iph.tos & ~1) printf("%c%s ", p->iph.tos & 1 ? '/' : ' ', - rtnl_dsfield_n2a(p->iph.tos & ~1, b1)); + rtnl_dsfield_n2a(p->iph.tos & ~1, b1)); } if (!(p->iph.frag_off & htons(IP_DF))) printf(" nopmtudisc"); diff --git a/networking/netstat.c b/networking/netstat.c index 9c239579f..c0c6ba501 100644 --- a/networking/netstat.c +++ b/networking/netstat.c @@ -187,7 +187,7 @@ static void prg_cache_add(long inode, char *name) for (pnp = prg_hash + hi; (pn = *pnp) != NULL; pnp = &pn->next) { if (pn->inode == inode) { /* Some warning should be appropriate here - as we got multiple processes for one i-node */ + * as we got multiple processes for one i-node */ return; } } diff --git a/networking/route.c b/networking/route.c index 45f2be542..f662031e9 100644 --- a/networking/route.c +++ b/networking/route.c @@ -507,8 +507,8 @@ void FAST_FUNC bb_displayroutes(int noresolve, int netstatfmt) while (1) { int r; r = fscanf(fp, "%63s%lx%lx%X%d%d%d%lx%d%d%d\n", - devname, &d, &g, &flgs, &ref, &use, &metric, &m, - &mtu, &win, &ir); + devname, &d, &g, &flgs, &ref, &use, &metric, &m, + &mtu, &win, &ir); if (r != 11) { if ((r < 0) && feof(fp)) { /* EOF with no (nonspace) chars read. */ break; diff --git a/networking/tc.c b/networking/tc.c index 1574353a5..f968707a9 100644 --- a/networking/tc.c +++ b/networking/tc.c @@ -391,7 +391,7 @@ static int print_class(const struct sockaddr_nl *who UNUSED_PARAM, printf("root "); else if (msg->tcm_parent) { classid = print_tc_classid(filter_qdisc ? - TC_H_MIN(msg->tcm_parent) : msg->tcm_parent); + TC_H_MIN(msg->tcm_parent) : msg->tcm_parent); printf("parent %s ", classid); if (ENABLE_FEATURE_CLEAN_UP) free(classid); @@ -526,7 +526,8 @@ int tc_main(int argc UNUSED_PARAM, char **argv) duparg(*argv, "handle"); /* reject LONG_MIN || LONG_MAX */ /* TODO: for fw - if ((slash = strchr(handle, '/')) != NULL) + slash = strchr(handle, '/'); + if (slash != NULL) *slash = '\0'; */ msg.tcm_handle = get_u32(*argv, "handle"); diff --git a/networking/traceroute.c b/networking/traceroute.c index d197e5410..6b7b2ebdd 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c @@ -290,9 +290,10 @@ #endif -#define OPT_STRING "FIlnrdvxt:i:m:p:q:s:w:z:f:" \ - IF_FEATURE_TRACEROUTE_SOURCE_ROUTE("g:") \ - "4" IF_TRACEROUTE6("6") +#define OPT_STRING \ + "FIlnrdvxt:i:m:p:q:s:w:z:f:" \ + IF_FEATURE_TRACEROUTE_SOURCE_ROUTE("g:") \ + "4" IF_TRACEROUTE6("6") enum { OPT_DONT_FRAGMNT = (1 << 0), /* F */ OPT_USE_ICMP = (1 << 1) * ENABLE_FEATURE_TRACEROUTE_USE_ICMP, /* I */ diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index f72217c84..086228871 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c @@ -1723,7 +1723,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) #endif /* enter bound state */ timeout = lease_seconds / 2; - temp_addr.s_addr = packet.yiaddr; + temp_addr.s_addr = packet.yiaddr; bb_info_msg("Lease of %s obtained, lease time %u", inet_ntoa(temp_addr), (unsigned)lease_seconds); requested_ip = packet.yiaddr; diff --git a/procps/nmeter.c b/procps/nmeter.c index ed5479024..6a3b32743 100644 --- a/procps/nmeter.c +++ b/procps/nmeter.c @@ -271,7 +271,7 @@ static int rdval_loadavg(const char* p, ullong *vec, ...) } // Parses /proc/diskstats -// 1 2 3 4 5 6(rd) 7 8 9 10(wr) 11 12 13 14 +// 1 2 3 4 5 6(rd) 7 8 9 10(wr) 11 12 13 14 // 3 0 hda 51292 14441 841783 926052 25717 79650 843256 3029804 0 148459 3956933 // 3 1 hda1 0 0 0 0 <- ignore if only 4 fields // Linux 3.0 (maybe earlier) started printing full stats for hda1 too. diff --git a/procps/top.c b/procps/top.c index b08444a76..2908bd3e7 100644 --- a/procps/top.c +++ b/procps/top.c @@ -995,7 +995,7 @@ static unsigned handle_input(unsigned scan_mask, unsigned interval) } # if ENABLE_FEATURE_SHOW_THREADS if (c == 'h' - IF_FEATURE_TOPMEM(&& scan_mask != TOPMEM_MASK) + IF_FEATURE_TOPMEM(&& scan_mask != TOPMEM_MASK) ) { scan_mask ^= PSSCAN_TASKS; continue; diff --git a/runit/runsv.c b/runit/runsv.c index ad8d84f74..3e1a3c8e5 100644 --- a/runit/runsv.c +++ b/runit/runsv.c @@ -172,7 +172,7 @@ static void update_status(struct svdir *s) } close(fd); if (rename_or_warn("supervise/pid.new", - s->islog ? "log/supervise/pid" : "log/supervise/pid"+4)) + s->islog ? "log/supervise/pid" : "log/supervise/pid"+4)) return; pidchanged = 0; } diff --git a/runit/svlogd.c b/runit/svlogd.c index b0ba21bb6..b7a0a6e71 100644 --- a/runit/svlogd.c +++ b/runit/svlogd.c @@ -601,12 +601,12 @@ static int buffer_pwrite(int n, char *s, unsigned len) while (fchdir(ld->fddir) == -1) pause2cannot("change directory, want remove old logfile", - ld->name); + ld->name); oldest[0] = 'A'; oldest[1] = oldest[27] = '\0'; while (!(d = opendir("."))) pause2cannot("open directory, want remove old logfile", - ld->name); + ld->name); errno = 0; while ((f = readdir(d))) if ((f->d_name[0] == '@') && (strlen(f->d_name) == 27)) { diff --git a/selinux/chcon.c b/selinux/chcon.c index 88d0cfec6..f947c2c12 100644 --- a/selinux/chcon.c +++ b/selinux/chcon.c @@ -92,7 +92,7 @@ static int FAST_FUNC change_filedir_context( if (specified_context == NULL) { context = set_security_context_component(file_context, - user, role, type, range); + user, role, type, range); if (!context) { bb_error_msg("can't compute security context from %s", file_context); goto skip; @@ -121,15 +121,15 @@ static int FAST_FUNC change_filedir_context( } if ((option_mask32 & OPT_VERBOSE) || ((option_mask32 & OPT_CHANHES) && !fail)) { printf(!fail - ? "context of %s changed to %s\n" - : "can't change context of %s to %s\n", - fname, context_string); + ? "context of %s changed to %s\n" + : "can't change context of %s to %s\n", + fname, context_string); } if (!fail) { rc = TRUE; } else if ((option_mask32 & OPT_QUIET) == 0) { bb_error_msg("can't change context of %s to %s", - fname, context_string); + fname, context_string); } } else if (option_mask32 & OPT_VERBOSE) { printf("context of %s retained as %s\n", fname, context_string); @@ -181,7 +181,7 @@ int chcon_main(int argc UNUSED_PARAM, char **argv) #if ENABLE_FEATURE_CHCON_LONG_OPTIONS if (option_mask32 & OPT_REFERENCE) { /* FIXME: lgetfilecon() should be used when '-h' is specified. - But current implementation follows the original one. */ + * But current implementation follows the original one. */ if (getfilecon(reference_file, &specified_context) < 0) bb_perror_msg_and_die("getfilecon('%s') failed", reference_file); } else @@ -201,10 +201,10 @@ int chcon_main(int argc UNUSED_PARAM, char **argv) fname[fname_len] = '\0'; if (recursive_action(fname, - 1<num_cmds == 0 - IF_HAS_KEYWORDS( && pi->res_word == RES_NONE) + IF_HAS_KEYWORDS(&& pi->res_word == RES_NONE) ) { free_pipe_list(pi); pi = NULL; @@ -4372,7 +4372,7 @@ static struct pipe *parse_stream(char **pstring, debug_printf_parse("dest.o_assignment='%s'\n", assignment_flag[dest.o_assignment]); /* Do we sit outside of any if's, loops or case's? */ if (!HAS_KEYWORDS - IF_HAS_KEYWORDS(|| (ctx.ctx_res_w == RES_NONE && ctx.old_flag == 0)) + IF_HAS_KEYWORDS(|| (ctx.ctx_res_w == RES_NONE && ctx.old_flag == 0)) ) { o_free(&dest); #if !BB_MMU diff --git a/shell/math.c b/shell/math.c index 760645d0f..15c003965 100644 --- a/shell/math.c +++ b/shell/math.c @@ -410,7 +410,7 @@ arith_apply(arith_state_t *math_state, operator op, var_or_num_t *numstack, var_ return "exponent less than 0"; c = 1; while (--right_side_val >= 0) - c *= rez; + c *= rez; rez = c; } else if (right_side_val == 0) diff --git a/util-linux/fdisk_osf.c b/util-linux/fdisk_osf.c index 65e6bd7c4..ff16389bd 100644 --- a/util-linux/fdisk_osf.c +++ b/util-linux/fdisk_osf.c @@ -898,8 +898,7 @@ xbsd_initlabel(struct partition *p) pp->p_fstype = BSD_FS_UNUSED; #else d->d_npartitions = 3; - pp = &d->d_partitions[2]; /* Partition C should be - the whole disk */ + pp = &d->d_partitions[2]; /* Partition C should be the whole disk */ pp->p_offset = 0; pp->p_size = d->d_secperunit; pp->p_fstype = BSD_FS_UNUSED; @@ -935,7 +934,7 @@ xbsd_readlabel(struct partition *p) fdisk_fatal(unable_to_read); memmove(d, &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET], - sizeof(struct xbsd_disklabel)); + sizeof(struct xbsd_disklabel)); if (d->d_magic != BSD_DISKMAGIC || d->d_magic2 != BSD_DISKMAGIC) return 0; diff --git a/util-linux/fsck_minix.c b/util-linux/fsck_minix.c index 1508ecb03..c1d1b2cc3 100644 --- a/util-linux/fsck_minix.c +++ b/util-linux/fsck_minix.c @@ -13,7 +13,7 @@ * 10.11.91 - updated, does checking, no repairs yet. * Sent out to the mailing-list for testing. * - * 14.11.91 - Testing seems to have gone well. Added some + * 14.11.91 - Testing seems to have gone well. Added some * correction-code, and changed some functions. * * 15.11.91 - More correction code. Hopefully it notices most @@ -22,11 +22,10 @@ * 16.11.91 - More corrections (thanks to Mika Jalava). Most * things seem to work now. Yeah, sure. * - * - * 19.04.92 - Had to start over again from this old version, as a + * 19.04.92 - Had to start over again from this old version, as a * kernel bug ate my enhanced fsck in february. * - * 28.02.93 - added support for different directory entry sizes.. + * 28.02.93 - added support for different directory entry sizes.. * * Sat Mar 6 18:59:42 1993, faith@cs.unc.edu: Output namelen with * superblock information @@ -35,31 +34,31 @@ * to that required by fsutil * * Mon Jan 3 11:06:52 1994 - Dr. Wettstein (greg%wind.uucp@plains.nodak.edu) - * Added support for file system valid flag. Also - * added program_version variable and output of - * program name and version number when program - * is executed. + * Added support for file system valid flag. Also + * added program_version variable and output of + * program name and version number when program + * is executed. * - * 30.10.94 - added support for v2 filesystem - * (Andreas Schwab, schwab@issan.informatik.uni-dortmund.de) + * 30.10.94 - added support for v2 filesystem + * (Andreas Schwab, schwab@issan.informatik.uni-dortmund.de) * - * 10.12.94 - added test to prevent checking of mounted fs adapted - * from Theodore Ts'o's (tytso@athena.mit.edu) e2fsck - * program. (Daniel Quinlan, quinlan@yggdrasil.com) + * 10.12.94 - added test to prevent checking of mounted fs adapted + * from Theodore Ts'o's (tytso@athena.mit.edu) e2fsck + * program. (Daniel Quinlan, quinlan@yggdrasil.com) * * 01.07.96 - Fixed the v2 fs stuff to use the right #defines and such - * for modern libcs (janl@math.uio.no, Nicolai Langfeldt) + * for modern libcs (janl@math.uio.no, Nicolai Langfeldt) * * 02.07.96 - Added C bit fiddling routines from rmk@ecs.soton.ac.uk * (Russell King). He made them for ARM. It would seem - * that the ARM is powerful enough to do this in C whereas + * that the ARM is powerful enough to do this in C whereas * i386 and m64k must use assembly to get it fast >:-) - * This should make minix fsck system-independent. - * (janl@math.uio.no, Nicolai Langfeldt) + * This should make minix fsck system-independent. + * (janl@math.uio.no, Nicolai Langfeldt) * * 04.11.96 - Added minor fixes from Andreas Schwab to avoid compiler * warnings. Added mc68k bitops from - * Joerg Dorchain . + * Joerg Dorchain . * * 06.11.96 - Added v2 code submitted by Joerg Dorchain, but written by * Andreas Schwab. @@ -1131,7 +1130,7 @@ static void check_counts(void) continue; } printf("Zone %d: %sin use, counted=%d\n", - i, zone_in_use(i) ? "" : "not ", zone_count[i]); + i, zone_in_use(i) ? "" : "not ", zone_count[i]); } } @@ -1183,7 +1182,7 @@ static void check_counts2(void) continue; } printf("Zone %d: %sin use, counted=%d\n", - i, zone_in_use(i) ? "" : "not ", zone_count[i]); + i, zone_in_use(i) ? "" : "not ", zone_count[i]); } } #endif @@ -1253,7 +1252,7 @@ int fsck_minix_main(int argc UNUSED_PARAM, char **argv) printf("Forcing filesystem check on %s\n", device_name); else if (OPT_repair) printf("Filesystem on %s is dirty, needs checking\n", - device_name); + device_name); read_tables(); @@ -1280,23 +1279,23 @@ int fsck_minix_main(int argc UNUSED_PARAM, char **argv) if (!inode_in_use(i)) free_cnt++; printf("\n%6u inodes used (%u%%)\n", (INODES - free_cnt), - 100 * (INODES - free_cnt) / INODES); + 100 * (INODES - free_cnt) / INODES); for (i = FIRSTZONE, free_cnt = 0; i < ZONES; i++) if (!zone_in_use(i)) free_cnt++; printf("%6u zones used (%u%%)\n\n" - "%6u regular files\n" - "%6u directories\n" - "%6u character device files\n" - "%6u block device files\n" - "%6u links\n" - "%6u symbolic links\n" - "------\n" - "%6u files\n", - (ZONES - free_cnt), 100 * (ZONES - free_cnt) / ZONES, - regular, directory, chardev, blockdev, - links - 2 * directory + 1, symlinks, - total - 2 * directory + 1); + "%6u regular files\n" + "%6u directories\n" + "%6u character device files\n" + "%6u block device files\n" + "%6u links\n" + "%6u symbolic links\n" + "------\n" + "%6u files\n", + (ZONES - free_cnt), 100 * (ZONES - free_cnt) / ZONES, + regular, directory, chardev, blockdev, + links - 2 * directory + 1, symlinks, + total - 2 * directory + 1); } if (changed) { write_tables(); diff --git a/util-linux/getopt.c b/util-linux/getopt.c index d662c813a..1ae0c59db 100644 --- a/util-linux/getopt.c +++ b/util-linux/getopt.c @@ -372,7 +372,7 @@ int getopt_main(int argc, char **argv) if (!argv[1]) { if (compatible) { /* For some reason, the original getopt gave no error - when there were no arguments. */ + * when there were no arguments. */ printf(" --\n"); return 0; } diff --git a/util-linux/ipcs.c b/util-linux/ipcs.c index 8fdaf0b85..2668cafd4 100644 --- a/util-linux/ipcs.c +++ b/util-linux/ipcs.c @@ -152,7 +152,7 @@ static NOINLINE void do_shm(void) if ((shmctl(0, IPC_INFO, (struct shmid_ds *) (void *) &shminfo)) < 0) return; /* glibc 2.1.3 and all earlier libc's have ints as fields - of struct shminfo; glibc 2.1.91 has unsigned long; ach */ + * of struct shminfo; glibc 2.1.91 has unsigned long; ach */ printf("max number of segments = %lu\n" "max seg size (kbytes) = %lu\n" "max total shared memory (pages) = %lu\n" diff --git a/util-linux/volume_id/nilfs.c b/util-linux/volume_id/nilfs.c index ffa86d43c..b88a9e435 100644 --- a/util-linux/volume_id/nilfs.c +++ b/util-linux/volume_id/nilfs.c @@ -86,7 +86,7 @@ int FAST_FUNC volume_id_probe_nilfs(struct volume_id *id /*,uint64_t off*/) // When used it is at 4K from the end of the partition (sb->s_dev_size - NILFS_SB2_OFFSET). volume_id_set_label_string(id, sb->s_volume_name, NILFS_LABEL_SIZE < VOLUME_ID_LABEL_SIZE ? - NILFS_LABEL_SIZE : VOLUME_ID_LABEL_SIZE); + NILFS_LABEL_SIZE : VOLUME_ID_LABEL_SIZE); volume_id_set_uuid(id, sb->s_uuid, UUID_DCE); if (sb->s_rev_level == 2) diff --git a/util-linux/volume_id/ntfs.c b/util-linux/volume_id/ntfs.c index 547f141c9..7b2612f01 100644 --- a/util-linux/volume_id/ntfs.c +++ b/util-linux/volume_id/ntfs.c @@ -132,7 +132,7 @@ int FAST_FUNC volume_id_probe_ntfs(struct volume_id *id /*,uint64_t off*/) dbg("mft record size %i", mft_record_size); buf = volume_id_get_buffer(id, off + mft_off + (MFT_RECORD_VOLUME * mft_record_size), - mft_record_size); + mft_record_size); if (buf == NULL) goto found; @@ -165,7 +165,7 @@ int FAST_FUNC volume_id_probe_ntfs(struct volume_id *id /*,uint64_t off*/) break; dbg("found attribute type 0x%x, len %i, at offset %i", - attr_type, attr_len, attr_off); + attr_type, attr_len, attr_off); // if (attr_type == MFT_RECORD_ATTR_VOLUME_INFO) { // struct volume_info *info; diff --git a/util-linux/volume_id/udf.c b/util-linux/volume_id/udf.c index cd63c8d8a..d3747fb8e 100644 --- a/util-linux/volume_id/udf.c +++ b/util-linux/volume_id/udf.c @@ -109,7 +109,7 @@ nsr: return -1; dbg("vsd: %c%c%c%c%c", - vsd->id[0], vsd->id[1], vsd->id[2], vsd->id[3], vsd->id[4]); + vsd->id[0], vsd->id[1], vsd->id[2], vsd->id[3], vsd->id[4]); if (vsd->id[0] == '\0') return -1; diff --git a/util-linux/volume_id/unused_msdos.c b/util-linux/volume_id/unused_msdos.c index 65fb88501..2e8cb196a 100644 --- a/util-linux/volume_id/unused_msdos.c +++ b/util-linux/volume_id/unused_msdos.c @@ -109,7 +109,7 @@ int FAST_FUNC volume_id_probe_msdos_part_table(struct volume_id *id, uint64_t of extended = off + poff; } else { dbg("found 0x%x data partition at 0x%llx, len 0x%llx", - part[i].sys_ind, (unsigned long long) poff, (unsigned long long) plen); + part[i].sys_ind, (unsigned long long) poff, (unsigned long long) plen); // if (is_raid(part[i].sys_ind)) // volume_id_set_usage_part(p, VOLUME_ID_RAID); diff --git a/util-linux/volume_id/unused_silicon_raid.c b/util-linux/volume_id/unused_silicon_raid.c index d1c439ecf..878b88197 100644 --- a/util-linux/volume_id/unused_silicon_raid.c +++ b/util-linux/volume_id/unused_silicon_raid.c @@ -62,7 +62,7 @@ int FAST_FUNC volume_id_probe_silicon_medley_raid(struct volume_id *id, uint64_t // volume_id_set_usage(id, VOLUME_ID_RAID); // snprintf(id->type_version, sizeof(id->type_version)-1, "%u.%u", -// le16_to_cpu(sil->major_ver), le16_to_cpu(sil->minor_ver)); +// le16_to_cpu(sil->major_ver), le16_to_cpu(sil->minor_ver)); // id->type = "silicon_medley_raid_member"; return 0; -- cgit v1.2.3-55-g6feb From 30a8652fbf16884490cee4a624f039a9ab587269 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Jan 2013 01:12:26 +0100 Subject: sha3: make size/speed optimization decision configurable Signed-off-by: Denys Vlasenko --- libbb/Config.src | 10 +++++++ libbb/hash_md5_sha.c | 77 +++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 68 insertions(+), 19 deletions(-) (limited to 'libbb') diff --git a/libbb/Config.src b/libbb/Config.src index ee1b66a45..19021fed1 100644 --- a/libbb/Config.src +++ b/libbb/Config.src @@ -28,6 +28,16 @@ config MD5_SMALL 2 3.0 5088 3 (smallest) 5.1 4912 +config SHA3_SMALL + int "SHA3: Trade bytes for speed (0:fast, 1:slow)" + default 1 + range 0 1 + help + Trade binary size versus speed for the sha3sum algorithm. + SHA3_SMALL=0 compared to SHA3_SMALL=1 (approximate): + 64-bit x86: +270 bytes of code, 45% faster + 32-bit x86: +450 bytes of code, 75% faster + config FEATURE_FAST_TOP bool "Faster /proc scanning code (+100 bytes)" default y diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index 06a2400b5..643cf205f 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -918,6 +918,16 @@ void FAST_FUNC sha512_end(sha512_ctx_t *ctx, void *resbuf) * Busybox modifications (C) Lauri Kasanen, under the GPLv2. */ +#if CONFIG_SHA3_SMALL < 0 +# define SHA3_SMALL 0 +#elif CONFIG_SHA3_SMALL > 1 +# define SHA3_SMALL 1 +#else +# define SHA3_SMALL CONFIG_SHA3_SMALL +#endif + +#define ARCH_IS_64BIT (sizeof(long) >= sizeof(uint64_t)) + enum { cKeccakR_SizeInBytes = 576 / 8, cKeccakNumberOfRounds = 24, @@ -967,8 +977,6 @@ static const uint8_t KeccakF_Mod5[10] = { static void KeccakF(uint64_t *state) { uint8_t x, y; - uint64_t temp; - uint64_t BC[5]; int round; if (BB_BIG_ENDIAN) { @@ -979,30 +987,61 @@ static void KeccakF(uint64_t *state) for (round = 0; round < cKeccakNumberOfRounds; ++round) { /* Theta */ - for (x = 0; x < 5; ++x) { - BC[x] = state[x] ^ state[5 + x] ^ state[10 + x] ^ - state[15 + x] ^ state[20 + x]; - } - for (x = 0; x < 5; ++x) { - temp = BC[KeccakF_Mod5[x + 4]] ^ - rotl64(BC[KeccakF_Mod5[x + 1]], 1); - - for (y = 0; y <= 20; y += 5) { - state[y + x] ^= temp; + { + uint64_t BC[5]; + for (x = 0; x < 5; ++x) { + BC[x] = state[x] ^ state[5 + x] ^ state[10 + x] ^ + state[15 + x] ^ state[20 + x]; + } + for (x = 0; x < 5; ++x) { + uint64_t temp = BC[KeccakF_Mod5[x + 4]] ^ + rotl64(BC[KeccakF_Mod5[x + 1]], 1); + if (SHA3_SMALL && !ARCH_IS_64BIT) { + for (y = 0; y <= 20; y += 5) + state[y + x] ^= temp; + } else { + /* on 64-bit arch, this is actually smaller too */ + state[0 + x] ^= temp; + state[5 + x] ^= temp; + state[10 + x] ^= temp; + state[15 + x] ^= temp; + state[20 + x] ^= temp; + } } } /* Rho Pi */ - temp = state[1]; - for (x = 0; x < 24; ++x) { - BC[0] = state[KeccakF_PiLane[x]]; - state[KeccakF_PiLane[x]] = - rotl64(temp, KeccakF_RotationConstants[x]); - temp = BC[0]; + if (SHA3_SMALL) { + uint64_t t1 = state[1]; + for (x = 0; x < 24; ++x) { + uint64_t t0 = state[KeccakF_PiLane[x]]; + state[KeccakF_PiLane[x]] = rotl64(t1, KeccakF_RotationConstants[x]); + t1 = t0; + } + } else { + /* Especially large benefit for 32-bit arch: + * 64-bit rotations by non-constant usually are SLOW on those. + * We resort to unrolling here. + * This optimizes out KeccakF_PiLane[] and KeccakF_RotationConstants[], + * but generates 300-500 more bytes of code. + */ + uint64_t t0; + uint64_t t1 = state[1]; +#define RhoPi_twice(x) \ + t0 = state[KeccakF_PiLane[x ]]; state[KeccakF_PiLane[x ]] = rotl64(t1, KeccakF_RotationConstants[x ]); \ + t1 = state[KeccakF_PiLane[x+1]]; state[KeccakF_PiLane[x+1]] = rotl64(t0, KeccakF_RotationConstants[x+1]); + RhoPi_twice(0); RhoPi_twice(2); + RhoPi_twice(4); RhoPi_twice(6); + RhoPi_twice(8); RhoPi_twice(10); + RhoPi_twice(12); RhoPi_twice(14); + RhoPi_twice(16); RhoPi_twice(18); + RhoPi_twice(20); RhoPi_twice(22); +#undef RhoPi_twice } /* Chi */ - for (y = 0; y < 25; y += 5) { + for (y = 0; y <= 20; y += 5) { + uint64_t BC[5]; BC[0] = state[y + 0]; BC[1] = state[y + 1]; BC[2] = state[y + 2]; -- cgit v1.2.3-55-g6feb From 6830ade6aa91dad5afe6abf9d1e4f696f5641bf1 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Jan 2013 13:58:01 +0100 Subject: whitespace fixes. no code changes Signed-off-by: Denys Vlasenko --- console-tools/loadfont.c | 2 +- coreutils/cal.c | 4 ++-- coreutils/chown.c | 4 ++-- coreutils/df.c | 4 ++-- coreutils/sort.c | 2 +- coreutils/sum.c | 4 ++-- editors/sed.c | 2 +- editors/vi.c | 10 +++++----- include/bb_archive.h | 6 +++--- include/grp_.h | 24 ++++++++++++------------ include/libbb.h | 2 +- include/pwd_.h | 24 ++++++++++++------------ include/shadow_.h | 14 +++++++------- libbb/xatonum_template.c | 2 +- miscutils/devfsd.c | 30 +++++++++++++++--------------- miscutils/hdparm.c | 2 +- miscutils/less.c | 6 +++--- miscutils/rx.c | 4 ++-- miscutils/time.c | 2 +- shell/hush.c | 2 +- 20 files changed, 75 insertions(+), 75 deletions(-) (limited to 'libbb') diff --git a/console-tools/loadfont.c b/console-tools/loadfont.c index 9e887f256..032506d6d 100644 --- a/console-tools/loadfont.c +++ b/console-tools/loadfont.c @@ -229,7 +229,7 @@ static void do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize, } /* Note: after PIO_UNIMAPCLR and before PIO_UNIMAP - this printf did not work on many kernels */ + * this printf did not work on many kernels */ advice.advised_hashsize = 0; advice.advised_hashstep = 0; diff --git a/coreutils/cal.c b/coreutils/cal.c index 0b2307349..0d388aa1c 100644 --- a/coreutils/cal.c +++ b/coreutils/cal.c @@ -43,7 +43,7 @@ static const unsigned char days_in_month[] ALIGN1 = { }; static const unsigned char sep1752[] ALIGN1 = { - 1, 2, 14, 15, 16, + 1, 2, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 }; @@ -183,7 +183,7 @@ int cal_main(int argc UNUSED_PARAM, char **argv) center(lineout, (WEEK_LEN * 3 + HEAD_SEP * 2) + julian * (J_WEEK_LEN * 2 + HEAD_SEP - - (WEEK_LEN * 3 + HEAD_SEP * 2)), + - (WEEK_LEN * 3 + HEAD_SEP * 2)), 0 ); puts("\n"); /* two \n's */ diff --git a/coreutils/chown.c b/coreutils/chown.c index bb166d8fe..1a9127622 100644 --- a/coreutils/chown.c +++ b/coreutils/chown.c @@ -126,8 +126,8 @@ int chown_main(int argc UNUSED_PARAM, char **argv) /* This matches coreutils behavior (almost - see below) */ param.chown_func = chown; if (OPT_NODEREF - /* || (OPT_RECURSE && !OPT_TRAVERSE_TOP): */ - IF_DESKTOP( || (opt & (BIT_RECURSE|BIT_TRAVERSE_TOP)) == BIT_RECURSE) + /* || (OPT_RECURSE && !OPT_TRAVERSE_TOP): */ + IF_DESKTOP( || (opt & (BIT_RECURSE|BIT_TRAVERSE_TOP)) == BIT_RECURSE) ) { param.chown_func = lchown; } diff --git a/coreutils/df.c b/coreutils/df.c index 2c72e82a4..5e9a8670f 100644 --- a/coreutils/df.c +++ b/coreutils/df.c @@ -110,8 +110,8 @@ int df_main(int argc UNUSED_PARAM, char **argv) df_disp_hr = xatoul_range(chp, 1, ULONG_MAX); /* disallow 0 */ /* From the manpage of df from coreutils-6.10: - Disk space is shown in 1K blocks by default, unless the environment - variable POSIXLY_CORRECT is set, in which case 512-byte blocks are used. + * Disk space is shown in 1K blocks by default, unless the environment + * variable POSIXLY_CORRECT is set, in which case 512-byte blocks are used. */ if (getenv("POSIXLY_CORRECT")) /* TODO - a new libbb function? */ df_disp_hr = 512; diff --git a/coreutils/sort.c b/coreutils/sort.c index 1df07285c..a1625fc9c 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c @@ -219,7 +219,7 @@ static int compare_keys(const void *xarg, const void *yarg) y = get_key(*(char **)yarg, key, flags); #else /* This curly bracket serves no purpose but to match the nesting - level of the for () loop we're not using */ + * level of the for () loop we're not using */ { x = *(char **)xarg; y = *(char **)yarg; diff --git a/coreutils/sum.c b/coreutils/sum.c index 95110a6da..75f6ef60a 100644 --- a/coreutils/sum.c +++ b/coreutils/sum.c @@ -94,8 +94,8 @@ int sum_main(int argc UNUSED_PARAM, char **argv) n = sum_file("-", type); } else { /* Need to print the name if either - - more than one file given - - doing sysv */ + * - more than one file given + * - doing sysv */ type += (argv[1] || type == SUM_SYSV); n = 1; do { diff --git a/editors/sed.c b/editors/sed.c index 070af611a..f8ca5d351 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -1077,7 +1077,7 @@ static void process_files(void) /* or does this line matches our last address regex */ || (sed_cmd->end_match && old_matched && (regexec(sed_cmd->end_match, - pattern_space, 0, NULL, 0) == 0) + pattern_space, 0, NULL, 0) == 0) ) ); } diff --git a/editors/vi.c b/editors/vi.c index b1776c668..5b5e2b0bf 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -1929,11 +1929,11 @@ static int find_range(char **start, char **stop, char c) dot_end(); // find NL q = dot; } else { - // nothing -- this causes any other values of c to - // represent the one-character range under the - // cursor. this is correct for ' ' and 'l', but - // perhaps no others. - // + // nothing -- this causes any other values of c to + // represent the one-character range under the + // cursor. this is correct for ' ' and 'l', but + // perhaps no others. + // } if (q < p) { t = q; diff --git a/include/bb_archive.h b/include/bb_archive.h index 7bb5615da..a7a2a1135 100644 --- a/include/bb_archive.h +++ b/include/bb_archive.h @@ -220,9 +220,9 @@ IF_DESKTOP(long long) int unpack_xz_stream(transformer_aux_data_t *aux, int src_ char* append_ext(char *filename, const char *expected_ext) FAST_FUNC; int bbunpack(char **argv, - IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_aux_data_t *aux), - char* FAST_FUNC (*make_new_name)(char *filename, const char *expected_ext), - const char *expected_ext + IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_aux_data_t *aux), + char* FAST_FUNC (*make_new_name)(char *filename, const char *expected_ext), + const char *expected_ext ) FAST_FUNC; void check_errors_in_children(int signo); diff --git a/include/grp_.h b/include/grp_.h index 82ad90492..e5075e5a0 100644 --- a/include/grp_.h +++ b/include/grp_.h @@ -64,7 +64,7 @@ extern struct group *fgetgrent(FILE *__stream); /* Write the given entry onto the given stream. */ extern int putgrent(const struct group *__restrict __p, - FILE *__restrict __f); + FILE *__restrict __f); #endif /* Search for an entry with a matching group ID. */ @@ -82,32 +82,32 @@ extern struct group *getgrnam(const char *__name); POSIX people would choose. */ extern int getgrent_r(struct group *__restrict __resultbuf, - char *__restrict __buffer, size_t __buflen, - struct group **__restrict __result); + char *__restrict __buffer, size_t __buflen, + struct group **__restrict __result); /* Search for an entry with a matching group ID. */ extern int getgrgid_r(gid_t __gid, struct group *__restrict __resultbuf, - char *__restrict __buffer, size_t __buflen, - struct group **__restrict __result); + char *__restrict __buffer, size_t __buflen, + struct group **__restrict __result); /* Search for an entry with a matching group name. */ extern int getgrnam_r(const char *__restrict __name, - struct group *__restrict __resultbuf, - char *__restrict __buffer, size_t __buflen, - struct group **__restrict __result); + struct group *__restrict __resultbuf, + char *__restrict __buffer, size_t __buflen, + struct group **__restrict __result); /* Read a group entry from STREAM. This function is not standardized an probably never will. */ extern int fgetgrent_r(FILE *__restrict __stream, - struct group *__restrict __resultbuf, - char *__restrict __buffer, size_t __buflen, - struct group **__restrict __result); + struct group *__restrict __resultbuf, + char *__restrict __buffer, size_t __buflen, + struct group **__restrict __result); /* Store at most *NGROUPS members of the group set for USER into *GROUPS. Also include GROUP. The actual number of groups found is returned in *NGROUPS. Return -1 if the if *NGROUPS is too small. */ extern int getgrouplist(const char *__user, gid_t __group, - gid_t *__groups, int *__ngroups); + gid_t *__groups, int *__ngroups); /* Initialize the group set for the current user by reading the group database and using all groups diff --git a/include/libbb.h b/include/libbb.h index 6ac7d2cab..606db7d0d 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1516,7 +1516,7 @@ struct smaprec { procps_read_smaps(pid, total) #endif int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total, - void (*cb)(struct smaprec *, void *), void *data); + void (*cb)(struct smaprec *, void *), void *data); typedef struct procps_status_t { DIR *dir; diff --git a/include/pwd_.h b/include/pwd_.h index ea158da45..625b6f5a2 100644 --- a/include/pwd_.h +++ b/include/pwd_.h @@ -63,7 +63,7 @@ extern struct passwd *fgetpwent(FILE *__stream); /* Write the given entry onto the given stream. */ extern int putpwent(const struct passwd *__restrict __p, - FILE *__restrict __f); + FILE *__restrict __f); #endif /* Search for an entry with a matching user ID. */ @@ -81,25 +81,25 @@ extern struct passwd *getpwnam(const char *__name); POSIX people would choose. */ extern int getpwent_r(struct passwd *__restrict __resultbuf, - char *__restrict __buffer, size_t __buflen, - struct passwd **__restrict __result); + char *__restrict __buffer, size_t __buflen, + struct passwd **__restrict __result); extern int getpwuid_r(uid_t __uid, - struct passwd *__restrict __resultbuf, - char *__restrict __buffer, size_t __buflen, - struct passwd **__restrict __result); + struct passwd *__restrict __resultbuf, + char *__restrict __buffer, size_t __buflen, + struct passwd **__restrict __result); extern int getpwnam_r(const char *__restrict __name, - struct passwd *__restrict __resultbuf, - char *__restrict __buffer, size_t __buflen, - struct passwd **__restrict __result); + struct passwd *__restrict __resultbuf, + char *__restrict __buffer, size_t __buflen, + struct passwd **__restrict __result); /* Read an entry from STREAM. This function is not standardized and probably never will. */ extern int fgetpwent_r(FILE *__restrict __stream, - struct passwd *__restrict __resultbuf, - char *__restrict __buffer, size_t __buflen, - struct passwd **__restrict __result); + struct passwd *__restrict __resultbuf, + char *__restrict __buffer, size_t __buflen, + struct passwd **__restrict __result); POP_SAVED_FUNCTION_VISIBILITY diff --git a/include/shadow_.h b/include/shadow_.h index 648a62ab3..7babe4f30 100644 --- a/include/shadow_.h +++ b/include/shadow_.h @@ -79,21 +79,21 @@ extern int putspent(const struct spwd *__p, FILE *__stream); /* Reentrant versions of some of the functions above */ extern int getspent_r(struct spwd *__result_buf, char *__buffer, - size_t __buflen, struct spwd **__result); + size_t __buflen, struct spwd **__result); #endif extern int getspnam_r(const char *__name, struct spwd *__result_buf, - char *__buffer, size_t __buflen, - struct spwd **__result); + char *__buffer, size_t __buflen, + struct spwd **__result); #ifdef UNUSED_FOR_NOW extern int sgetspent_r(const char *__string, struct spwd *__result_buf, - char *__buffer, size_t __buflen, - struct spwd **__result); + char *__buffer, size_t __buflen, + struct spwd **__result); extern int fgetspent_r(FILE *__stream, struct spwd *__result_buf, - char *__buffer, size_t __buflen, - struct spwd **__result); + char *__buffer, size_t __buflen, + struct spwd **__result); /* Protect password file against multi writers */ extern int lckpwdf(void); diff --git a/libbb/xatonum_template.c b/libbb/xatonum_template.c index 029f66202..e0471983c 100644 --- a/libbb/xatonum_template.c +++ b/libbb/xatonum_template.c @@ -59,7 +59,7 @@ unsigned type FAST_FUNC xstrtou(_range_sfx)(const char *numstr, int base, } /* Note: trailing space is an error. - It would be easy enough to allow though if desired. */ + * It would be easy enough to allow though if desired. */ if (*e) goto inval; chk_range: diff --git a/miscutils/devfsd.c b/miscutils/devfsd.c index 2e87261cf..24c953bac 100644 --- a/miscutils/devfsd.c +++ b/miscutils/devfsd.c @@ -803,8 +803,8 @@ static void action_execute(const struct devfsd_notify_struct *info, static void action_copy(const struct devfsd_notify_struct *info, - const struct config_entry_struct *entry, - const regmatch_t *regexpr, unsigned int numexpr) + const struct config_entry_struct *entry, + const regmatch_t *regexpr, unsigned int numexpr) /* [SUMMARY] Copy permissions. The devfs change. The config file entry. @@ -1259,11 +1259,11 @@ static int make_dir_tree(const char *path) } /* End Function make_dir_tree */ static int expand_expression(char *output, unsigned int outsize, - const char *input, - const char *(*get_variable_func)(const char *variable, void *info), - void *info, - const char *devname, - const regmatch_t *ex, unsigned int numexp) + const char *input, + const char *(*get_variable_func)(const char *variable, void *info), + void *info, + const char *devname, + const regmatch_t *ex, unsigned int numexp) /* [SUMMARY] Expand environment variables and regular subexpressions in string. The output expanded expression is written here. The size of the output buffer. @@ -1288,8 +1288,8 @@ static int expand_expression(char *output, unsigned int outsize, } /* End Function expand_expression */ static void expand_regexp(char *output, size_t outsize, const char *input, - const char *devname, - const regmatch_t *ex, unsigned int numex) + const char *devname, + const regmatch_t *ex, unsigned int numex) /* [SUMMARY] Expand all occurrences of the regular subexpressions \0 to \9. The output expanded expression is written here. The size of the output buffer. @@ -1385,7 +1385,7 @@ static struct translate_struct translate_table[] = }; const char *get_old_name(const char *devname, unsigned int namelen, - char *buffer, unsigned int major, unsigned int minor) + char *buffer, unsigned int major, unsigned int minor) /* [SUMMARY] Translate a kernel-supplied name into an old name. The device name provided by the kernel. The length of the name. @@ -1423,7 +1423,7 @@ const char *get_old_name(const char *devname, unsigned int namelen, }; for (trans = translate_table; trans->match != NULL; ++trans) { - len = strlen(trans->match); + len = strlen(trans->match); if (strncmp(devname, trans->match, len) == 0) { if (trans->format == NULL) @@ -1549,9 +1549,9 @@ static char *write_old_sd_name(char *buffer, /*EXPERIMENTAL_FUNCTION*/ int st_expr_expand(char *output, unsigned int length, const char *input, - const char *(*get_variable_func)(const char *variable, - void *info), - void *info) + const char *(*get_variable_func)(const char *variable, + void *info), + void *info) /* [SUMMARY] Expand an expression using Borne Shell-like unquoted rules. The output expanded expression is written here. The size of the output buffer. @@ -1643,7 +1643,7 @@ st_expr_expand_out: static const char *expand_variable(char *buffer, unsigned int length, unsigned int *out_pos, const char *input, const char *(*func)(const char *variable, - void *info), + void *info), void *info) /* [SUMMARY] Expand a variable. The buffer to write to. diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c index 9c6dbf468..69726ae72 100644 --- a/miscutils/hdparm.c +++ b/miscutils/hdparm.c @@ -1038,7 +1038,7 @@ static void identify(uint16_t *val) val[ACOUSTIC] & 0x00ff); } } else { - /* ATAPI */ + /* ATAPI */ if (eqpt != CDROM && (val[CAPAB_0] & SWRST_REQ)) printf("\tATA sw reset required\n"); diff --git a/miscutils/less.c b/miscutils/less.c index f0187bf8a..5ce0a1203 100644 --- a/miscutils/less.c +++ b/miscutils/less.c @@ -709,9 +709,9 @@ static void print_found(const char *line) /* buf[] holds quarantined version of str */ /* Each part of the line that matches has the HIGHLIGHT - and NORMAL escape sequences placed around it. - NB: we regex against line, but insert text - from quarantined copy (buf[]) */ + * and NORMAL escape sequences placed around it. + * NB: we regex against line, but insert text + * from quarantined copy (buf[]) */ str = buf; growline = NULL; eflags = 0; diff --git a/miscutils/rx.c b/miscutils/rx.c index af597320c..1dffb593a 100644 --- a/miscutils/rx.c +++ b/miscutils/rx.c @@ -193,8 +193,8 @@ static int receive(/*int read_fd, */int file_fd) } if (cksum_or_crc != expected) { bb_error_msg(do_crc ? "crc error, expected 0x%04x, got 0x%04x" - : "checksum error, expected 0x%02x, got 0x%02x", - expected, cksum_or_crc); + : "checksum error, expected 0x%02x, got 0x%02x", + expected, cksum_or_crc); goto error; } diff --git a/miscutils/time.c b/miscutils/time.c index ffed38632..19b0b44c9 100644 --- a/miscutils/time.c +++ b/miscutils/time.c @@ -70,7 +70,7 @@ static void resuse_end(pid_t pid, resource_t *resp) pid_t caught; /* Ignore signals, but don't ignore the children. When wait3 - returns the child process, set the time the command finished. */ + * returns the child process, set the time the command finished. */ while ((caught = wait3(&resp->waitstatus, 0, &resp->ru)) != pid) { if (caught == -1 && errno != EINTR) { bb_perror_msg("wait"); diff --git a/shell/hush.c b/shell/hush.c index 87807052c..e2dc1e2d0 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -8281,7 +8281,7 @@ static int FAST_FUNC builtin_exit(char **argv) * (if there are _stopped_ jobs, running ones don't count) * # exit * exit - # EEE (then bash exits) + * EEE (then bash exits) * * TODO: we can use G.exiting = -1 as indicator "last cmd was exit" */ -- cgit v1.2.3-55-g6feb From 07a54e21dd08bcd752a23095fdedc904eb7127fb Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Jan 2013 14:47:05 +0100 Subject: sha3: another speedup for SHA3_SMALL=0 case Signed-off-by: Denys Vlasenko --- libbb/hash_md5_sha.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'libbb') diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index 643cf205f..3b1366762 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -1041,16 +1041,31 @@ static void KeccakF(uint64_t *state) /* Chi */ for (y = 0; y <= 20; y += 5) { - uint64_t BC[5]; - BC[0] = state[y + 0]; - BC[1] = state[y + 1]; - BC[2] = state[y + 2]; - BC[3] = state[y + 3]; - BC[4] = state[y + 4]; - for (x = 0; x < 5; ++x) { - state[y + x] = - BC[x] ^ ((~BC[KeccakF_Mod5[x + 1]]) & - BC[KeccakF_Mod5[x + 2]]); + if (SHA3_SMALL) { + uint64_t BC[5]; + BC[0] = state[y + 0]; + BC[1] = state[y + 1]; + BC[2] = state[y + 2]; + BC[3] = state[y + 3]; + BC[4] = state[y + 4]; + for (x = 0; x < 5; ++x) { + state[y + x] = + BC[x] ^ ((~BC[KeccakF_Mod5[x + 1]]) & + BC[KeccakF_Mod5[x + 2]]); + } + } else { + /* 32-bit x86: +50 bytes code, 10% faster */ + uint64_t BC0, BC1, BC2, BC3, BC4; + BC0 = state[y + 0]; + BC1 = state[y + 1]; + BC2 = state[y + 2]; + state[y + 0] = BC0 ^ ((~BC1) & BC2); + BC3 = state[y + 3]; + state[y + 1] = BC1 ^ ((~BC2) & BC3); + BC4 = state[y + 4]; + state[y + 2] = BC2 ^ ((~BC3) & BC4); + state[y + 3] = BC3 ^ ((~BC4) & BC0); + state[y + 4] = BC4 ^ ((~BC0) & BC1); } } -- cgit v1.2.3-55-g6feb From a55df2793660941f42589182537d02ce54eaed66 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Jan 2013 15:22:30 +0100 Subject: sha3: code shrink function old new delta KeccakF 1064 1053 -11 Signed-off-by: Denys Vlasenko --- libbb/hash_md5_sha.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'libbb') diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index 3b1366762..a0eec7789 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -988,24 +988,29 @@ static void KeccakF(uint64_t *state) for (round = 0; round < cKeccakNumberOfRounds; ++round) { /* Theta */ { - uint64_t BC[5]; + uint64_t BC[10]; for (x = 0; x < 5; ++x) { - BC[x] = state[x] ^ state[5 + x] ^ state[10 + x] ^ - state[15 + x] ^ state[20 + x]; + BC[x + 5] = BC[x] = state[x] + ^ state[x + 5] ^ state[x + 10] + ^ state[x + 15] ^ state[x + 20]; } + /* Using 2x5 vector above eliminates the need to use + * [Mod5[x+N]] index trick below to calculate (x+N) % 5, + * and the code is a bit _smaller_. + */ for (x = 0; x < 5; ++x) { - uint64_t temp = BC[KeccakF_Mod5[x + 4]] ^ - rotl64(BC[KeccakF_Mod5[x + 1]], 1); + uint64_t temp = BC[x + 4] ^ rotl64(BC[x + 1], 1); if (SHA3_SMALL && !ARCH_IS_64BIT) { for (y = 0; y <= 20; y += 5) - state[y + x] ^= temp; + state[x + y] ^= temp; } else { - /* on 64-bit arch, this is actually smaller too */ - state[0 + x] ^= temp; - state[5 + x] ^= temp; - state[10 + x] ^= temp; - state[15 + x] ^= temp; - state[20 + x] ^= temp; + /* On 64-bit, this is also smaller, + * not only faster, than loop */ + state[x] ^= temp; + state[x + 5] ^= temp; + state[x + 10] ^= temp; + state[x + 15] ^= temp; + state[x + 20] ^= temp; } } } @@ -1019,7 +1024,7 @@ static void KeccakF(uint64_t *state) t1 = t0; } } else { - /* Especially large benefit for 32-bit arch: + /* Especially large benefit for 32-bit arch (75% faster): * 64-bit rotations by non-constant usually are SLOW on those. * We resort to unrolling here. * This optimizes out KeccakF_PiLane[] and KeccakF_RotationConstants[], -- cgit v1.2.3-55-g6feb From ac4100e103ca2b4e6e782c5814b1f43cef58c00b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Jan 2013 16:27:39 +0100 Subject: sha3: code shrink function old new delta KeccakF 1053 1078 +25 KeccakF_RoundConstants 192 48 -144 Signed-off-by: Denys Vlasenko --- libbb/hash_md5_sha.c | 62 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 26 deletions(-) (limited to 'libbb') diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index a0eec7789..4cd2244a1 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -933,32 +933,40 @@ enum { cKeccakNumberOfRounds = 24, }; -static const uint64_t KeccakF_RoundConstants[cKeccakNumberOfRounds] = { - 0x0000000000000001ULL, - 0x0000000000008082ULL, - 0x800000000000808aULL, - 0x8000000080008000ULL, - 0x000000000000808bULL, - 0x0000000080000001ULL, - 0x8000000080008081ULL, - 0x8000000000008009ULL, - 0x000000000000008aULL, - 0x0000000000000088ULL, - 0x0000000080008009ULL, - 0x000000008000000aULL, - 0x000000008000808bULL, - 0x800000000000008bULL, - 0x8000000000008089ULL, - 0x8000000000008003ULL, - 0x8000000000008002ULL, - 0x8000000000000080ULL, - 0x000000000000800aULL, - 0x800000008000000aULL, - 0x8000000080008081ULL, - 0x8000000000008080ULL, - 0x0000000080000001ULL, - 0x8000000080008008ULL +/* Elements should be 64-bit, but top half is always zero or 0x80000000. + * It is encoded as a separate word below. + * Same is true for 31th bits. + */ +static const uint16_t KeccakF_RoundConstants[cKeccakNumberOfRounds] = { + 0x0001UL, + 0x8082UL, + 0x808aUL, + 0x8000UL, + 0x808bUL, + 0x0001UL, + 0x8081UL, + 0x8009UL, + 0x008aUL, + 0x0088UL, + 0x8009UL, + 0x000aUL, + 0x808bUL, + 0x008bUL, + 0x8089UL, + 0x8003UL, + 0x8002UL, + 0x0080UL, + 0x800aUL, + 0x000aUL, + 0x8081UL, + 0x8080UL, + 0x0001UL, + 0x8008UL }; +/* 0th first - 0011 0011 0000 0111 1101 1101: */ +#define KeccakF_RoundConstantBit63 ((uint32_t)(0x3307dd00)) +/* 0th first - 0001 0110 0011 1000 0001 1011: */ +#define KeccakF_RoundConstantBit31 ((uint32_t)(0x16381b00)) static const uint8_t KeccakF_RotationConstants[25] = { 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 27, 41, 56, 8, 25, 43, 62, @@ -1075,7 +1083,9 @@ static void KeccakF(uint64_t *state) } /* Iota */ - state[0] ^= KeccakF_RoundConstants[round]; + state[0] ^= KeccakF_RoundConstants[round] + | (uint32_t)((KeccakF_RoundConstantBit31 << round) & 0x80000000) + | (uint64_t)((KeccakF_RoundConstantBit63 << round) & 0x80000000) << 32; } if (BB_BIG_ENDIAN) { -- cgit v1.2.3-55-g6feb From 5b7f50f37210706c0f508788991de88244c7b29b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Jan 2013 19:52:30 +0100 Subject: sha3: cosmetic tweaks to various names, comments. No logic changes. Signed-off-by: Denys Vlasenko --- libbb/hash_md5_sha.c | 124 ++++++++++++++++++++++++++------------------------- 1 file changed, 63 insertions(+), 61 deletions(-) (limited to 'libbb') diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index 4cd2244a1..18e426079 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -926,66 +926,67 @@ void FAST_FUNC sha512_end(sha512_ctx_t *ctx, void *resbuf) # define SHA3_SMALL CONFIG_SHA3_SMALL #endif -#define ARCH_IS_64BIT (sizeof(long) >= sizeof(uint64_t)) - enum { - cKeccakR_SizeInBytes = 576 / 8, - cKeccakNumberOfRounds = 24, + KECCAK_IBLK_BYTES = 576 / 8, + KECCAK_NROUNDS = 24, }; /* Elements should be 64-bit, but top half is always zero or 0x80000000. - * It is encoded as a separate word below. - * Same is true for 31th bits. + * We encode 63rd bits in a separate word below. + * Same is true for 31th bits, which lets us use 16-bit table instead of 64-bit. + * The speed penalty is lost in the noise. */ -static const uint16_t KeccakF_RoundConstants[cKeccakNumberOfRounds] = { - 0x0001UL, - 0x8082UL, - 0x808aUL, - 0x8000UL, - 0x808bUL, - 0x0001UL, - 0x8081UL, - 0x8009UL, - 0x008aUL, - 0x0088UL, - 0x8009UL, - 0x000aUL, - 0x808bUL, - 0x008bUL, - 0x8089UL, - 0x8003UL, - 0x8002UL, - 0x0080UL, - 0x800aUL, - 0x000aUL, - 0x8081UL, - 0x8080UL, - 0x0001UL, - 0x8008UL +static const uint16_t KECCAK_IOTA_CONST[KECCAK_NROUNDS] = { + 0x0001U, + 0x8082U, + 0x808aU, + 0x8000U, + 0x808bU, + 0x0001U, + 0x8081U, + 0x8009U, + 0x008aU, + 0x0088U, + 0x8009U, + 0x000aU, + 0x808bU, + 0x008bU, + 0x8089U, + 0x8003U, + 0x8002U, + 0x0080U, + 0x800aU, + 0x000aU, + 0x8081U, + 0x8080U, + 0x0001U, + 0x8008U, }; -/* 0th first - 0011 0011 0000 0111 1101 1101: */ -#define KeccakF_RoundConstantBit63 ((uint32_t)(0x3307dd00)) -/* 0th first - 0001 0110 0011 1000 0001 1011: */ -#define KeccakF_RoundConstantBit31 ((uint32_t)(0x16381b00)) +/* bit from CONST[0] is msb: 0011 0011 0000 0111 1101 1101 */ +#define KECCAK_IOTA_CONST_bit63 ((uint32_t)(0x3307dd00)) +/* bit from CONST[0] is msb: 0001 0110 0011 1000 0001 1011 */ +#define KECCAK_IOTA_CONST_bit31 ((uint32_t)(0x16381b00)) -static const uint8_t KeccakF_RotationConstants[25] = { +static const uint8_t KECCAK_ROT_CONST[25] = { 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44 }; -static const uint8_t KeccakF_PiLane[25] = { +static const uint8_t KECCAK_PI_LANE[25] = { 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1 }; -static const uint8_t KeccakF_Mod5[10] = { +static const uint8_t MOD5[10] = { 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 }; +#define ARCH_IS_64BIT (sizeof(long) >= sizeof(uint64_t)) + static void KeccakF(uint64_t *state) { - uint8_t x, y; - int round; + unsigned x, y; + unsigned round; if (BB_BIG_ENDIAN) { for (x = 0; x < 25; x++) { @@ -993,7 +994,7 @@ static void KeccakF(uint64_t *state) } } - for (round = 0; round < cKeccakNumberOfRounds; ++round) { + for (round = 0; round < KECCAK_NROUNDS; ++round) { /* Theta */ { uint64_t BC[10]; @@ -1003,7 +1004,7 @@ static void KeccakF(uint64_t *state) ^ state[x + 15] ^ state[x + 20]; } /* Using 2x5 vector above eliminates the need to use - * [Mod5[x+N]] index trick below to calculate (x+N) % 5, + * BC[MOD5[x+N]] trick below to fetch BC[(x+N) % 5], * and the code is a bit _smaller_. */ for (x = 0; x < 5; ++x) { @@ -1027,22 +1028,24 @@ static void KeccakF(uint64_t *state) if (SHA3_SMALL) { uint64_t t1 = state[1]; for (x = 0; x < 24; ++x) { - uint64_t t0 = state[KeccakF_PiLane[x]]; - state[KeccakF_PiLane[x]] = rotl64(t1, KeccakF_RotationConstants[x]); + uint64_t t0 = state[KECCAK_PI_LANE[x]]; + state[KECCAK_PI_LANE[x]] = rotl64(t1, KECCAK_ROT_CONST[x]); t1 = t0; } } else { /* Especially large benefit for 32-bit arch (75% faster): * 64-bit rotations by non-constant usually are SLOW on those. * We resort to unrolling here. - * This optimizes out KeccakF_PiLane[] and KeccakF_RotationConstants[], + * This optimizes out KECCAK_PI_LANE[] and KECCAK_ROT_CONST[], * but generates 300-500 more bytes of code. */ uint64_t t0; uint64_t t1 = state[1]; #define RhoPi_twice(x) \ - t0 = state[KeccakF_PiLane[x ]]; state[KeccakF_PiLane[x ]] = rotl64(t1, KeccakF_RotationConstants[x ]); \ - t1 = state[KeccakF_PiLane[x+1]]; state[KeccakF_PiLane[x+1]] = rotl64(t0, KeccakF_RotationConstants[x+1]); + t0 = state[KECCAK_PI_LANE[x ]]; \ + state[KECCAK_PI_LANE[x ]] = rotl64(t1, KECCAK_ROT_CONST[x ]); \ + t1 = state[KECCAK_PI_LANE[x+1]]; \ + state[KECCAK_PI_LANE[x+1]] = rotl64(t0, KECCAK_ROT_CONST[x+1]); RhoPi_twice(0); RhoPi_twice(2); RhoPi_twice(4); RhoPi_twice(6); RhoPi_twice(8); RhoPi_twice(10); @@ -1063,8 +1066,8 @@ static void KeccakF(uint64_t *state) BC[4] = state[y + 4]; for (x = 0; x < 5; ++x) { state[y + x] = - BC[x] ^ ((~BC[KeccakF_Mod5[x + 1]]) & - BC[KeccakF_Mod5[x + 2]]); + BC[x] ^ ((~BC[MOD5[x + 1]]) & + BC[MOD5[x + 2]]); } } else { /* 32-bit x86: +50 bytes code, 10% faster */ @@ -1083,9 +1086,9 @@ static void KeccakF(uint64_t *state) } /* Iota */ - state[0] ^= KeccakF_RoundConstants[round] - | (uint32_t)((KeccakF_RoundConstantBit31 << round) & 0x80000000) - | (uint64_t)((KeccakF_RoundConstantBit63 << round) & 0x80000000) << 32; + state[0] ^= KECCAK_IOTA_CONST[round] + | (uint32_t)((KECCAK_IOTA_CONST_bit31 << round) & 0x80000000) + | (uint64_t)((KECCAK_IOTA_CONST_bit63 << round) & 0x80000000) << 32; } if (BB_BIG_ENDIAN) { @@ -1095,6 +1098,8 @@ static void KeccakF(uint64_t *state) } } +#undef ARCH_IS_64BIT + void FAST_FUNC sha3_begin(sha3_ctx_t *ctx) { memset(ctx, 0, sizeof(*ctx)); @@ -1110,19 +1115,19 @@ void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buf, size_t bytes) buffer[ctx->bytes_queued] ^= *data++; bytes--; ctx->bytes_queued++; - if (ctx->bytes_queued == cKeccakR_SizeInBytes) { + if (ctx->bytes_queued == KECCAK_IBLK_BYTES) { KeccakF(ctx->state); ctx->bytes_queued = 0; } } /* Absorb complete blocks */ - while (bytes >= cKeccakR_SizeInBytes) { + while (bytes >= KECCAK_IBLK_BYTES) { /* XOR data onto beginning of state[]. * We try to be efficient - operate on word at a time, not byte. * Yet safe wrt unaligned access: can't just use "*(long*)data"... */ - unsigned count = cKeccakR_SizeInBytes / sizeof(long); + unsigned count = KECCAK_IBLK_BYTES / sizeof(long); long *buffer = (long*)ctx->state; do { long v; @@ -1132,7 +1137,7 @@ void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buf, size_t bytes) } while (--count); KeccakF(ctx->state); - bytes -= cKeccakR_SizeInBytes; + bytes -= KECCAK_IBLK_BYTES; } /* Queue remaining data bytes */ @@ -1148,11 +1153,8 @@ void FAST_FUNC sha3_end(sha3_ctx_t *ctx, uint8_t *hashval) { /* Padding */ uint8_t *buffer = (uint8_t*)ctx->state; - /* 0 is the number of bits in last, incomplete byte - * (that is, zero: we never have incomplete bytes): - */ - buffer[ctx->bytes_queued] ^= 1 << 0; - buffer[cKeccakR_SizeInBytes - 1] ^= 0x80; + buffer[ctx->bytes_queued] ^= 1; + buffer[KECCAK_IBLK_BYTES - 1] ^= 0x80; KeccakF(ctx->state); -- cgit v1.2.3-55-g6feb From 8e7312e12fb088ba99f4f875903926f2ef9ed235 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Jan 2013 21:50:41 +0100 Subject: sha3: tweak choice of a fast code path for 64-bit Signed-off-by: Denys Vlasenko --- libbb/hash_md5_sha.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'libbb') diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index 18e426079..7ae0b6385 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -1057,7 +1057,7 @@ static void KeccakF(uint64_t *state) /* Chi */ for (y = 0; y <= 20; y += 5) { - if (SHA3_SMALL) { + if (SHA3_SMALL && !ARCH_IS_64BIT) { uint64_t BC[5]; BC[0] = state[y + 0]; BC[1] = state[y + 1]; @@ -1071,6 +1071,7 @@ static void KeccakF(uint64_t *state) } } else { /* 32-bit x86: +50 bytes code, 10% faster */ + /* 64-bit x86: ~same code size, 30% faster */ uint64_t BC0, BC1, BC2, BC3, BC4; BC0 = state[y + 0]; BC1 = state[y + 1]; -- cgit v1.2.3-55-g6feb From 8fb3ab528e1a640342c04d996e54f7fa668fdce6 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Jan 2013 22:07:48 +0100 Subject: sha3: remove two "small code" codepaths: I can't reproduce code size win on them anymore Signed-off-by: Denys Vlasenko --- libbb/hash_md5_sha.c | 61 ++++++++++++++++------------------------------------ 1 file changed, 18 insertions(+), 43 deletions(-) (limited to 'libbb') diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index 7ae0b6385..60f44cc3d 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -977,14 +977,12 @@ static const uint8_t KECCAK_PI_LANE[25] = { 14, 22, 9, 6, 1 }; -static const uint8_t MOD5[10] = { - 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 -}; - #define ARCH_IS_64BIT (sizeof(long) >= sizeof(uint64_t)) static void KeccakF(uint64_t *state) { + /*static const uint8_t MOD5[10] = { 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 };*/ + unsigned x, y; unsigned round; @@ -1009,18 +1007,11 @@ static void KeccakF(uint64_t *state) */ for (x = 0; x < 5; ++x) { uint64_t temp = BC[x + 4] ^ rotl64(BC[x + 1], 1); - if (SHA3_SMALL && !ARCH_IS_64BIT) { - for (y = 0; y <= 20; y += 5) - state[x + y] ^= temp; - } else { - /* On 64-bit, this is also smaller, - * not only faster, than loop */ - state[x] ^= temp; - state[x + 5] ^= temp; - state[x + 10] ^= temp; - state[x + 15] ^= temp; - state[x + 20] ^= temp; - } + state[x] ^= temp; + state[x + 5] ^= temp; + state[x + 10] ^= temp; + state[x + 15] ^= temp; + state[x + 20] ^= temp; } } @@ -1057,33 +1048,17 @@ static void KeccakF(uint64_t *state) /* Chi */ for (y = 0; y <= 20; y += 5) { - if (SHA3_SMALL && !ARCH_IS_64BIT) { - uint64_t BC[5]; - BC[0] = state[y + 0]; - BC[1] = state[y + 1]; - BC[2] = state[y + 2]; - BC[3] = state[y + 3]; - BC[4] = state[y + 4]; - for (x = 0; x < 5; ++x) { - state[y + x] = - BC[x] ^ ((~BC[MOD5[x + 1]]) & - BC[MOD5[x + 2]]); - } - } else { - /* 32-bit x86: +50 bytes code, 10% faster */ - /* 64-bit x86: ~same code size, 30% faster */ - uint64_t BC0, BC1, BC2, BC3, BC4; - BC0 = state[y + 0]; - BC1 = state[y + 1]; - BC2 = state[y + 2]; - state[y + 0] = BC0 ^ ((~BC1) & BC2); - BC3 = state[y + 3]; - state[y + 1] = BC1 ^ ((~BC2) & BC3); - BC4 = state[y + 4]; - state[y + 2] = BC2 ^ ((~BC3) & BC4); - state[y + 3] = BC3 ^ ((~BC4) & BC0); - state[y + 4] = BC4 ^ ((~BC0) & BC1); - } + uint64_t BC0, BC1, BC2, BC3, BC4; + BC0 = state[y + 0]; + BC1 = state[y + 1]; + BC2 = state[y + 2]; + state[y + 0] = BC0 ^ ((~BC1) & BC2); + BC3 = state[y + 3]; + state[y + 1] = BC1 ^ ((~BC2) & BC3); + BC4 = state[y + 4]; + state[y + 2] = BC2 ^ ((~BC3) & BC4); + state[y + 3] = BC3 ^ ((~BC4) & BC0); + state[y + 4] = BC4 ^ ((~BC0) & BC1); } /* Iota */ -- cgit v1.2.3-55-g6feb From 970aa6b5bd95e435e537d123ec8be99c3077af1b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Jan 2013 22:19:24 +0100 Subject: sha3: cache ctx->bytes_queued function old new delta sha3_hash 171 155 -16 Signed-off-by: Denys Vlasenko --- libbb/hash_md5_sha.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'libbb') diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index 60f44cc3d..d143fc651 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -977,8 +977,6 @@ static const uint8_t KECCAK_PI_LANE[25] = { 14, 22, 9, 6, 1 }; -#define ARCH_IS_64BIT (sizeof(long) >= sizeof(uint64_t)) - static void KeccakF(uint64_t *state) { /*static const uint8_t MOD5[10] = { 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 };*/ @@ -1074,8 +1072,6 @@ static void KeccakF(uint64_t *state) } } -#undef ARCH_IS_64BIT - void FAST_FUNC sha3_begin(sha3_ctx_t *ctx) { memset(ctx, 0, sizeof(*ctx)); @@ -1084,16 +1080,17 @@ void FAST_FUNC sha3_begin(sha3_ctx_t *ctx) void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buf, size_t bytes) { const uint8_t *data = buf; + unsigned bytes_queued = ctx->bytes_queued; /* If already data in queue, continue queuing first */ - while (bytes != 0 && ctx->bytes_queued != 0) { + while (bytes != 0 && bytes_queued != 0) { uint8_t *buffer = (uint8_t*)ctx->state; - buffer[ctx->bytes_queued] ^= *data++; + buffer[bytes_queued] ^= *data++; bytes--; - ctx->bytes_queued++; - if (ctx->bytes_queued == KECCAK_IBLK_BYTES) { + bytes_queued++; + if (bytes_queued == KECCAK_IBLK_BYTES) { KeccakF(ctx->state); - ctx->bytes_queued = 0; + bytes_queued = 0; } } @@ -1113,16 +1110,19 @@ void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buf, size_t bytes) } while (--count); KeccakF(ctx->state); + bytes -= KECCAK_IBLK_BYTES; } /* Queue remaining data bytes */ while (bytes != 0) { uint8_t *buffer = (uint8_t*)ctx->state; - buffer[ctx->bytes_queued] ^= *data++; - ctx->bytes_queued++; + buffer[bytes_queued] ^= *data++; + bytes_queued++; bytes--; } + + ctx->bytes_queued = bytes_queued; } void FAST_FUNC sha3_end(sha3_ctx_t *ctx, uint8_t *hashval) -- cgit v1.2.3-55-g6feb From 5368fe541c023130843cea361d779addb936b95c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 16 Jan 2013 02:20:31 +0100 Subject: sha3: rename KeccakF->sha3_process_block76. This brings the naming more in line with other hashes. Pulled most statics and constants into it. Also noticed that two byte arrays are 1 element too big. Signed-off-by: Denys Vlasenko --- libbb/hash_md5_sha.c | 160 ++++++++++++++++++++++++++------------------------- 1 file changed, 81 insertions(+), 79 deletions(-) (limited to 'libbb') diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index d143fc651..15588dcfe 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -190,10 +190,9 @@ static void FAST_FUNC md5_process_block64(md5_ctx_t *ctx) int i; uint32_t temp; -# if BB_BIG_ENDIAN - for (i = 0; i < 16; i++) - words[i] = SWAP_LE32(words[i]); -# endif + if (BB_BIG_ENDIAN) + for (i = 0; i < 16; i++) + words[i] = SWAP_LE32(words[i]); # if MD5_SMALL == 3 pc = C_array; @@ -467,12 +466,13 @@ void FAST_FUNC md5_end(md5_ctx_t *ctx, void *resbuf) common64_end(ctx, /*swap_needed:*/ BB_BIG_ENDIAN); /* The MD5 result is in little endian byte order */ -#if BB_BIG_ENDIAN - ctx->hash[0] = SWAP_LE32(ctx->hash[0]); - ctx->hash[1] = SWAP_LE32(ctx->hash[1]); - ctx->hash[2] = SWAP_LE32(ctx->hash[2]); - ctx->hash[3] = SWAP_LE32(ctx->hash[3]); -#endif + if (BB_BIG_ENDIAN) { + ctx->hash[0] = SWAP_LE32(ctx->hash[0]); + ctx->hash[1] = SWAP_LE32(ctx->hash[1]); + ctx->hash[2] = SWAP_LE32(ctx->hash[2]); + ctx->hash[3] = SWAP_LE32(ctx->hash[3]); + } + memcpy(resbuf, ctx->hash, sizeof(ctx->hash[0]) * 4); } @@ -927,59 +927,61 @@ void FAST_FUNC sha512_end(sha512_ctx_t *ctx, void *resbuf) #endif enum { - KECCAK_IBLK_BYTES = 576 / 8, - KECCAK_NROUNDS = 24, + SHA3_IBLK_BYTES = 72, /* 576 bits / 8 */ }; -/* Elements should be 64-bit, but top half is always zero or 0x80000000. - * We encode 63rd bits in a separate word below. - * Same is true for 31th bits, which lets us use 16-bit table instead of 64-bit. - * The speed penalty is lost in the noise. +/* + * In the crypto literature this function is usually called Keccak-f(). */ -static const uint16_t KECCAK_IOTA_CONST[KECCAK_NROUNDS] = { - 0x0001U, - 0x8082U, - 0x808aU, - 0x8000U, - 0x808bU, - 0x0001U, - 0x8081U, - 0x8009U, - 0x008aU, - 0x0088U, - 0x8009U, - 0x000aU, - 0x808bU, - 0x008bU, - 0x8089U, - 0x8003U, - 0x8002U, - 0x0080U, - 0x800aU, - 0x000aU, - 0x8081U, - 0x8080U, - 0x0001U, - 0x8008U, -}; -/* bit from CONST[0] is msb: 0011 0011 0000 0111 1101 1101 */ -#define KECCAK_IOTA_CONST_bit63 ((uint32_t)(0x3307dd00)) -/* bit from CONST[0] is msb: 0001 0110 0011 1000 0001 1011 */ -#define KECCAK_IOTA_CONST_bit31 ((uint32_t)(0x16381b00)) - -static const uint8_t KECCAK_ROT_CONST[25] = { - 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 27, 41, 56, 8, 25, 43, 62, - 18, 39, 61, 20, 44 -}; - -static const uint8_t KECCAK_PI_LANE[25] = { - 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 15, 23, 19, 13, 12, 2, 20, - 14, 22, 9, 6, 1 -}; - -static void KeccakF(uint64_t *state) +static void sha3_process_block76(uint64_t *state) { - /*static const uint8_t MOD5[10] = { 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 };*/ + enum { NROUNDS = 24 }; + + /* Elements should be 64-bit, but top half is always zero or 0x80000000. + * We encode 63rd bits in a separate word below. + * Same is true for 31th bits, which lets us use 16-bit table instead of 64-bit. + * The speed penalty is lost in the noise. + */ + static const uint16_t IOTA_CONST[NROUNDS] = { + 0x0001, + 0x8082, + 0x808a, + 0x8000, + 0x808b, + 0x0001, + 0x8081, + 0x8009, + 0x008a, + 0x0088, + 0x8009, + 0x000a, + 0x808b, + 0x008b, + 0x8089, + 0x8003, + 0x8002, + 0x0080, + 0x800a, + 0x000a, + 0x8081, + 0x8080, + 0x0001, + 0x8008, + }; + /* bit for CONST[0] is in msb: 0011 0011 0000 0111 1101 1101 */ + const uint32_t IOTA_CONST_bit63 = (uint32_t)(0x3307dd00); + /* bit for CONST[0] is in msb: 0001 0110 0011 1000 0001 1011 */ + const uint32_t IOTA_CONST_bit31 = (uint32_t)(0x16381b00); + + static const uint8_t ROT_CONST[24] = { + 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, + 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44, + }; + static const uint8_t PI_LANE[24] = { + 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, + 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1, + }; + /*static const uint8_t MOD5[10] = { 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, };*/ unsigned x, y; unsigned round; @@ -990,7 +992,7 @@ static void KeccakF(uint64_t *state) } } - for (round = 0; round < KECCAK_NROUNDS; ++round) { + for (round = 0; round < NROUNDS; ++round) { /* Theta */ { uint64_t BC[10]; @@ -1017,24 +1019,24 @@ static void KeccakF(uint64_t *state) if (SHA3_SMALL) { uint64_t t1 = state[1]; for (x = 0; x < 24; ++x) { - uint64_t t0 = state[KECCAK_PI_LANE[x]]; - state[KECCAK_PI_LANE[x]] = rotl64(t1, KECCAK_ROT_CONST[x]); + uint64_t t0 = state[PI_LANE[x]]; + state[PI_LANE[x]] = rotl64(t1, ROT_CONST[x]); t1 = t0; } } else { /* Especially large benefit for 32-bit arch (75% faster): * 64-bit rotations by non-constant usually are SLOW on those. * We resort to unrolling here. - * This optimizes out KECCAK_PI_LANE[] and KECCAK_ROT_CONST[], + * This optimizes out PI_LANE[] and ROT_CONST[], * but generates 300-500 more bytes of code. */ uint64_t t0; uint64_t t1 = state[1]; #define RhoPi_twice(x) \ - t0 = state[KECCAK_PI_LANE[x ]]; \ - state[KECCAK_PI_LANE[x ]] = rotl64(t1, KECCAK_ROT_CONST[x ]); \ - t1 = state[KECCAK_PI_LANE[x+1]]; \ - state[KECCAK_PI_LANE[x+1]] = rotl64(t0, KECCAK_ROT_CONST[x+1]); + t0 = state[PI_LANE[x ]]; \ + state[PI_LANE[x ]] = rotl64(t1, ROT_CONST[x ]); \ + t1 = state[PI_LANE[x+1]]; \ + state[PI_LANE[x+1]] = rotl64(t0, ROT_CONST[x+1]); RhoPi_twice(0); RhoPi_twice(2); RhoPi_twice(4); RhoPi_twice(6); RhoPi_twice(8); RhoPi_twice(10); @@ -1060,9 +1062,9 @@ static void KeccakF(uint64_t *state) } /* Iota */ - state[0] ^= KECCAK_IOTA_CONST[round] - | (uint32_t)((KECCAK_IOTA_CONST_bit31 << round) & 0x80000000) - | (uint64_t)((KECCAK_IOTA_CONST_bit63 << round) & 0x80000000) << 32; + state[0] ^= IOTA_CONST[round] + | (uint32_t)((IOTA_CONST_bit31 << round) & 0x80000000) + | (uint64_t)((IOTA_CONST_bit63 << round) & 0x80000000) << 32; } if (BB_BIG_ENDIAN) { @@ -1088,19 +1090,19 @@ void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buf, size_t bytes) buffer[bytes_queued] ^= *data++; bytes--; bytes_queued++; - if (bytes_queued == KECCAK_IBLK_BYTES) { - KeccakF(ctx->state); + if (bytes_queued == SHA3_IBLK_BYTES) { + sha3_process_block76(ctx->state); bytes_queued = 0; } } /* Absorb complete blocks */ - while (bytes >= KECCAK_IBLK_BYTES) { + while (bytes >= SHA3_IBLK_BYTES) { /* XOR data onto beginning of state[]. * We try to be efficient - operate on word at a time, not byte. * Yet safe wrt unaligned access: can't just use "*(long*)data"... */ - unsigned count = KECCAK_IBLK_BYTES / sizeof(long); + unsigned count = SHA3_IBLK_BYTES / sizeof(long); long *buffer = (long*)ctx->state; do { long v; @@ -1109,9 +1111,9 @@ void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buf, size_t bytes) data += sizeof(long); } while (--count); - KeccakF(ctx->state); + sha3_process_block76(ctx->state); - bytes -= KECCAK_IBLK_BYTES; + bytes -= SHA3_IBLK_BYTES; } /* Queue remaining data bytes */ @@ -1129,10 +1131,10 @@ void FAST_FUNC sha3_end(sha3_ctx_t *ctx, uint8_t *hashval) { /* Padding */ uint8_t *buffer = (uint8_t*)ctx->state; - buffer[ctx->bytes_queued] ^= 1; - buffer[KECCAK_IBLK_BYTES - 1] ^= 0x80; + buffer[ctx->bytes_queued] ^= 1; + buffer[SHA3_IBLK_BYTES - 1] ^= 0x80; - KeccakF(ctx->state); + sha3_process_block76(ctx->state); /* Output */ memcpy(hashval, ctx->state, 64); -- cgit v1.2.3-55-g6feb From e4f0f26bade2560b96ee66e719e464753befa433 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 16 Jan 2013 12:23:23 +0100 Subject: sha3: s/sha3_process_block76/sha3_process_block72/ Signed-off-by: Denys Vlasenko --- libbb/hash_md5_sha.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'libbb') diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index 15588dcfe..d23d4f639 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -933,7 +933,7 @@ enum { /* * In the crypto literature this function is usually called Keccak-f(). */ -static void sha3_process_block76(uint64_t *state) +static void sha3_process_block72(uint64_t *state) { enum { NROUNDS = 24 }; @@ -1091,7 +1091,7 @@ void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buf, size_t bytes) bytes--; bytes_queued++; if (bytes_queued == SHA3_IBLK_BYTES) { - sha3_process_block76(ctx->state); + sha3_process_block72(ctx->state); bytes_queued = 0; } } @@ -1111,7 +1111,7 @@ void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buf, size_t bytes) data += sizeof(long); } while (--count); - sha3_process_block76(ctx->state); + sha3_process_block72(ctx->state); bytes -= SHA3_IBLK_BYTES; } @@ -1134,7 +1134,7 @@ void FAST_FUNC sha3_end(sha3_ctx_t *ctx, uint8_t *hashval) buffer[ctx->bytes_queued] ^= 1; buffer[SHA3_IBLK_BYTES - 1] ^= 0x80; - sha3_process_block76(ctx->state); + sha3_process_block72(ctx->state); /* Output */ memcpy(hashval, ctx->state, 64); -- cgit v1.2.3-55-g6feb From 5d78355d5afcda9a95cb18926317e86f8b14223e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 17 Jan 2013 11:02:21 +0100 Subject: code shrink function old new delta applet_name_compare 36 31 -5 find_applet_by_name 43 25 -18 Signed-off-by: Denys Vlasenko --- libbb/appletlib.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'libbb') diff --git a/libbb/appletlib.c b/libbb/appletlib.c index da13bf36c..67df44690 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -140,10 +140,9 @@ void FAST_FUNC bb_show_usage(void) } #if NUM_APPLETS > 8 -/* NB: any char pointer will work as well, not necessarily applet_names */ -static int applet_name_compare(const void *name, const void *v) +static int applet_name_compare(const void *name, const void *idx) { - int i = (const char *)v - applet_names; + int i = (int)(ptrdiff_t)idx - 1; return strcmp(name, APPLET_NAME(i)); } #endif @@ -152,10 +151,12 @@ int FAST_FUNC find_applet_by_name(const char *name) #if NUM_APPLETS > 8 /* Do a binary search to find the applet entry given the name. */ const char *p; - p = bsearch(name, applet_names, ARRAY_SIZE(applet_main), 1, applet_name_compare); - if (!p) - return -1; - return p - applet_names; + p = bsearch(name, (void*)(ptrdiff_t)1, ARRAY_SIZE(applet_main), 1, applet_name_compare); + /* + * if (!p) return -1; + * ^^^^^^^^^^^^^^^^^^ the code below will do this if p == NULL :) + */ + return (int)(ptrdiff_t)p - 1; #else /* A version which does not pull in bsearch */ int i = 0; @@ -747,8 +748,11 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv) /* Special case. POSIX says "test --help" * should be no different from e.g. "test --foo". */ //TODO: just compare applet_no with APPLET_NO_test - if (!ENABLE_TEST || strcmp(applet_name, "test") != 0) + if (!ENABLE_TEST || strcmp(applet_name, "test") != 0) { + /* If you want "foo --help" to return 0: */ + /*xfunc_error_retval = 0;*/ bb_show_usage(); + } } if (ENABLE_FEATURE_SUID) check_suid(applet_no); -- cgit v1.2.3-55-g6feb From 2cfcc9e9d74447cb770255d1d8cb6f3722df22ba Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 20 Jan 2013 00:38:09 +0100 Subject: sha3: code shrink function old new delta sha3_hash 155 101 -54 Signed-off-by: Denys Vlasenko --- include/libbb.h | 4 +-- libbb/hash_md5_sha.c | 91 ++++++++++++++++++++++++++++++++++------------------ 2 files changed, 61 insertions(+), 34 deletions(-) (limited to 'libbb') diff --git a/include/libbb.h b/include/libbb.h index 606db7d0d..e52006020 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1641,7 +1641,7 @@ typedef struct sha3_ctx_t { unsigned bytes_queued; } sha3_ctx_t; void md5_begin(md5_ctx_t *ctx) FAST_FUNC; -void md5_hash(md5_ctx_t *ctx, const void *data, size_t length) FAST_FUNC; +void md5_hash(md5_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; void md5_end(md5_ctx_t *ctx, void *resbuf) FAST_FUNC; void sha1_begin(sha1_ctx_t *ctx) FAST_FUNC; #define sha1_hash md5_hash @@ -1654,7 +1654,7 @@ void sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; void sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC; void sha3_begin(sha3_ctx_t *ctx) FAST_FUNC; void sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; -void sha3_end(sha3_ctx_t *ctx, uint8_t *resbuf) FAST_FUNC; +void sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC; extern uint32_t *global_crc32_table; uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC; diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index d23d4f639..b4d955e5a 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -56,7 +56,7 @@ static void FAST_FUNC common64_hash(md5_ctx_t *ctx, const void *buffer, size_t l len -= remaining; buffer = (const char *)buffer + remaining; bufpos += remaining; - /* clever way to do "if (bufpos != 64) break; ... ; bufpos = 0;" */ + /* Clever way to do "if (bufpos != N) break; ... ; bufpos = 0;" */ bufpos -= 64; if (bufpos != 0) break; @@ -839,7 +839,7 @@ void FAST_FUNC sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) len -= remaining; buffer = (const char *)buffer + remaining; bufpos += remaining; - /* clever way to do "if (bufpos != 128) break; ... ; bufpos = 0;" */ + /* Clever way to do "if (bufpos != N) break; ... ; bufpos = 0;" */ bufpos -= 128; if (bufpos != 0) break; @@ -1079,63 +1079,90 @@ void FAST_FUNC sha3_begin(sha3_ctx_t *ctx) memset(ctx, 0, sizeof(*ctx)); } -void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buf, size_t bytes) +void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len) { - const uint8_t *data = buf; - unsigned bytes_queued = ctx->bytes_queued; +#if SHA3_SMALL + const uint8_t *data = buffer; + unsigned bufpos = ctx->bytes_queued; + + while (1) { + unsigned remaining = SHA3_IBLK_BYTES - bufpos; + if (remaining > len) + remaining = len; + len -= remaining; + /* XOR data into buffer */ + while (remaining != 0) { + uint8_t *buf = (uint8_t*)ctx->state; + buf[bufpos] ^= *data++; + bufpos++; + remaining--; + } + /* Clever way to do "if (bufpos != N) break; ... ; bufpos = 0;" */ + bufpos -= SHA3_IBLK_BYTES; + if (bufpos != 0) + break; + /* Buffer is filled up, process it */ + sha3_process_block72(ctx->state); + /*bufpos = 0; - already is */ + } + ctx->bytes_queued = bufpos + SHA3_IBLK_BYTES; +#else + /* +50 bytes code size, but a bit faster because of long-sized XORs */ + const uint8_t *data = buffer; + unsigned bufpos = ctx->bytes_queued; /* If already data in queue, continue queuing first */ - while (bytes != 0 && bytes_queued != 0) { - uint8_t *buffer = (uint8_t*)ctx->state; - buffer[bytes_queued] ^= *data++; - bytes--; - bytes_queued++; - if (bytes_queued == SHA3_IBLK_BYTES) { - sha3_process_block72(ctx->state); - bytes_queued = 0; + while (len != 0 && bufpos != 0) { + uint8_t *buf = (uint8_t*)ctx->state; + buf[bufpos] ^= *data++; + len--; + bufpos++; + if (bufpos == SHA3_IBLK_BYTES) { + bufpos = 0; + goto do_block; } } /* Absorb complete blocks */ - while (bytes >= SHA3_IBLK_BYTES) { + while (len >= SHA3_IBLK_BYTES) { /* XOR data onto beginning of state[]. - * We try to be efficient - operate on word at a time, not byte. - * Yet safe wrt unaligned access: can't just use "*(long*)data"... + * We try to be efficient - operate one word at a time, not byte. + * Careful wrt unaligned access: can't just use "*(long*)data"! */ unsigned count = SHA3_IBLK_BYTES / sizeof(long); - long *buffer = (long*)ctx->state; + long *buf = (long*)ctx->state; do { long v; move_from_unaligned_long(v, (long*)data); - *buffer++ ^= v; + *buf++ ^= v; data += sizeof(long); } while (--count); - + len -= SHA3_IBLK_BYTES; + do_block: sha3_process_block72(ctx->state); - - bytes -= SHA3_IBLK_BYTES; } /* Queue remaining data bytes */ - while (bytes != 0) { - uint8_t *buffer = (uint8_t*)ctx->state; - buffer[bytes_queued] ^= *data++; - bytes_queued++; - bytes--; + while (len != 0) { + uint8_t *buf = (uint8_t*)ctx->state; + buf[bufpos] ^= *data++; + bufpos++; + len--; } - ctx->bytes_queued = bytes_queued; + ctx->bytes_queued = bufpos; +#endif } -void FAST_FUNC sha3_end(sha3_ctx_t *ctx, uint8_t *hashval) +void FAST_FUNC sha3_end(sha3_ctx_t *ctx, void *resbuf) { /* Padding */ - uint8_t *buffer = (uint8_t*)ctx->state; - buffer[ctx->bytes_queued] ^= 1; - buffer[SHA3_IBLK_BYTES - 1] ^= 0x80; + uint8_t *buf = (uint8_t*)ctx->state; + buf[ctx->bytes_queued] ^= 1; + buf[SHA3_IBLK_BYTES - 1] ^= 0x80; sha3_process_block72(ctx->state); /* Output */ - memcpy(hashval, ctx->state, 64); + memcpy(resbuf, ctx->state, 64); } -- cgit v1.2.3-55-g6feb