aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-10-17 01:35:16 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2010-10-17 01:35:16 +0200
commita971a192e8af4279fb384be9ff0f0e8387b229cb (patch)
tree1946ade9ce19e7c7b2912d31f70bebcf87b54321
parent446c2349b608fc4e25ac5846f4491bfa389330a6 (diff)
downloadbusybox-w32-a971a192e8af4279fb384be9ff0f0e8387b229cb.tar.gz
busybox-w32-a971a192e8af4279fb384be9ff0f0e8387b229cb.tar.bz2
busybox-w32-a971a192e8af4279fb384be9ff0f0e8387b229cb.zip
shaN: code shrink
function old new delta init512_lo 32 40 +8 init256 32 40 +8 sha256_begin 42 28 -14 sha512_begin 81 53 -28 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/2 up/down: 16/-42) Total: -26 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/libbb.h4
-rw-r--r--libbb/sha1.c15
2 files changed, 12 insertions, 7 deletions
diff --git a/include/libbb.h b/include/libbb.h
index f406fc6f1..d05b2d48a 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1514,7 +1514,7 @@ void FAST_FUNC read_base64(FILE *src_stream, FILE *dst_stream, int flags);
1514 1514
1515typedef struct sha1_ctx_t { 1515typedef struct sha1_ctx_t {
1516 uint32_t hash[8]; /* 5, +3 elements for sha256 */ 1516 uint32_t hash[8]; /* 5, +3 elements for sha256 */
1517 uint64_t total64; 1517 uint64_t total64; /* must be directly after hash[] */
1518 uint8_t wbuffer[64]; /* NB: always correctly aligned for uint64_t */ 1518 uint8_t wbuffer[64]; /* NB: always correctly aligned for uint64_t */
1519 void (*process_block)(struct sha1_ctx_t*) FAST_FUNC; 1519 void (*process_block)(struct sha1_ctx_t*) FAST_FUNC;
1520} sha1_ctx_t; 1520} sha1_ctx_t;
@@ -1527,7 +1527,7 @@ void sha256_begin(sha256_ctx_t *ctx) FAST_FUNC;
1527#define sha256_end sha1_end 1527#define sha256_end sha1_end
1528typedef struct sha512_ctx_t { 1528typedef struct sha512_ctx_t {
1529 uint64_t hash[8]; 1529 uint64_t hash[8];
1530 uint64_t total64[2]; 1530 uint64_t total64[2]; /* must be directly after hash[] */
1531 uint8_t wbuffer[128]; /* NB: always correctly aligned for uint64_t */ 1531 uint8_t wbuffer[128]; /* NB: always correctly aligned for uint64_t */
1532} sha512_ctx_t; 1532} sha512_ctx_t;
1533void sha512_begin(sha512_ctx_t *ctx) FAST_FUNC; 1533void sha512_begin(sha512_ctx_t *ctx) FAST_FUNC;
diff --git a/libbb/sha1.c b/libbb/sha1.c
index 6d2f88457..70efd581b 100644
--- a/libbb/sha1.c
+++ b/libbb/sha1.c
@@ -329,7 +329,9 @@ static const uint32_t init256[] = {
329 0x510e527f, 329 0x510e527f,
330 0x9b05688c, 330 0x9b05688c,
331 0x1f83d9ab, 331 0x1f83d9ab,
332 0x5be0cd19 332 0x5be0cd19,
333 0,
334 0,
333}; 335};
334static const uint32_t init512_lo[] = { 336static const uint32_t init512_lo[] = {
335 0xf3bcc908, 337 0xf3bcc908,
@@ -339,7 +341,9 @@ static const uint32_t init512_lo[] = {
339 0xade682d1, 341 0xade682d1,
340 0x2b3e6c1f, 342 0x2b3e6c1f,
341 0xfb41bd6b, 343 0xfb41bd6b,
342 0x137e2179 344 0x137e2179,
345 0,
346 0,
343}; 347};
344 348
345/* Initialize structure containing state of computation. 349/* Initialize structure containing state of computation.
@@ -347,7 +351,7 @@ static const uint32_t init512_lo[] = {
347void FAST_FUNC sha256_begin(sha256_ctx_t *ctx) 351void FAST_FUNC sha256_begin(sha256_ctx_t *ctx)
348{ 352{
349 memcpy(ctx->hash, init256, sizeof(init256)); 353 memcpy(ctx->hash, init256, sizeof(init256));
350 ctx->total64 = 0; 354 /*ctx->total64 = 0; - done by extending init256 with two 32-bit zeros */
351 ctx->process_block = sha256_process_block64; 355 ctx->process_block = sha256_process_block64;
352} 356}
353 357
@@ -356,9 +360,10 @@ void FAST_FUNC sha256_begin(sha256_ctx_t *ctx)
356void FAST_FUNC sha512_begin(sha512_ctx_t *ctx) 360void FAST_FUNC sha512_begin(sha512_ctx_t *ctx)
357{ 361{
358 int i; 362 int i;
359 for (i = 0; i < 8; i++) 363 /* Two extra iterations zero out ctx->total64[] */
364 for (i = 0; i < 8+2; i++)
360 ctx->hash[i] = ((uint64_t)(init256[i]) << 32) + init512_lo[i]; 365 ctx->hash[i] = ((uint64_t)(init256[i]) << 32) + init512_lo[i];
361 ctx->total64[0] = ctx->total64[1] = 0; 366 /*ctx->total64[0] = ctx->total64[1] = 0; - already done */
362} 367}
363 368
364 369