aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2013-01-15 22:19:24 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2013-01-15 22:19:24 +0100
commit970aa6b5bd95e435e537d123ec8be99c3077af1b (patch)
tree690f57187c58d130cda0c54179810a6bfd266cd2
parent8fb3ab528e1a640342c04d996e54f7fa668fdce6 (diff)
downloadbusybox-w32-970aa6b5bd95e435e537d123ec8be99c3077af1b.tar.gz
busybox-w32-970aa6b5bd95e435e537d123ec8be99c3077af1b.tar.bz2
busybox-w32-970aa6b5bd95e435e537d123ec8be99c3077af1b.zip
sha3: cache ctx->bytes_queued
function old new delta sha3_hash 171 155 -16 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--libbb/hash_md5_sha.c22
1 files changed, 11 insertions, 11 deletions
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] = {
977 14, 22, 9, 6, 1 977 14, 22, 9, 6, 1
978}; 978};
979 979
980#define ARCH_IS_64BIT (sizeof(long) >= sizeof(uint64_t))
981
982static void KeccakF(uint64_t *state) 980static void KeccakF(uint64_t *state)
983{ 981{
984 /*static const uint8_t MOD5[10] = { 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 };*/ 982 /*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)
1074 } 1072 }
1075} 1073}
1076 1074
1077#undef ARCH_IS_64BIT
1078
1079void FAST_FUNC sha3_begin(sha3_ctx_t *ctx) 1075void FAST_FUNC sha3_begin(sha3_ctx_t *ctx)
1080{ 1076{
1081 memset(ctx, 0, sizeof(*ctx)); 1077 memset(ctx, 0, sizeof(*ctx));
@@ -1084,16 +1080,17 @@ void FAST_FUNC sha3_begin(sha3_ctx_t *ctx)
1084void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buf, size_t bytes) 1080void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buf, size_t bytes)
1085{ 1081{
1086 const uint8_t *data = buf; 1082 const uint8_t *data = buf;
1083 unsigned bytes_queued = ctx->bytes_queued;
1087 1084
1088 /* If already data in queue, continue queuing first */ 1085 /* If already data in queue, continue queuing first */
1089 while (bytes != 0 && ctx->bytes_queued != 0) { 1086 while (bytes != 0 && bytes_queued != 0) {
1090 uint8_t *buffer = (uint8_t*)ctx->state; 1087 uint8_t *buffer = (uint8_t*)ctx->state;
1091 buffer[ctx->bytes_queued] ^= *data++; 1088 buffer[bytes_queued] ^= *data++;
1092 bytes--; 1089 bytes--;
1093 ctx->bytes_queued++; 1090 bytes_queued++;
1094 if (ctx->bytes_queued == KECCAK_IBLK_BYTES) { 1091 if (bytes_queued == KECCAK_IBLK_BYTES) {
1095 KeccakF(ctx->state); 1092 KeccakF(ctx->state);
1096 ctx->bytes_queued = 0; 1093 bytes_queued = 0;
1097 } 1094 }
1098 } 1095 }
1099 1096
@@ -1113,16 +1110,19 @@ void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buf, size_t bytes)
1113 } while (--count); 1110 } while (--count);
1114 1111
1115 KeccakF(ctx->state); 1112 KeccakF(ctx->state);
1113
1116 bytes -= KECCAK_IBLK_BYTES; 1114 bytes -= KECCAK_IBLK_BYTES;
1117 } 1115 }
1118 1116
1119 /* Queue remaining data bytes */ 1117 /* Queue remaining data bytes */
1120 while (bytes != 0) { 1118 while (bytes != 0) {
1121 uint8_t *buffer = (uint8_t*)ctx->state; 1119 uint8_t *buffer = (uint8_t*)ctx->state;
1122 buffer[ctx->bytes_queued] ^= *data++; 1120 buffer[bytes_queued] ^= *data++;
1123 ctx->bytes_queued++; 1121 bytes_queued++;
1124 bytes--; 1122 bytes--;
1125 } 1123 }
1124
1125 ctx->bytes_queued = bytes_queued;
1126} 1126}
1127 1127
1128void FAST_FUNC sha3_end(sha3_ctx_t *ctx, uint8_t *hashval) 1128void FAST_FUNC sha3_end(sha3_ctx_t *ctx, uint8_t *hashval)