sha: fix thinko in sha512; add FAST_FUNC to sha1/sha256
authorDenis Vlasenko <vda.linux@googlemail.com>
Sun, 15 Mar 2009 02:56:00 +0000 (02:56 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Sun, 15 Mar 2009 02:56:00 +0000 (02:56 -0000)
function                                             old     new   delta
sha512_process_block128                             1334    1336      +2
sha1_hash                                            112     111      -1
sha256_process_block64                               446     440      -6
sha1_process_block64                                 494     484     -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 2/-17)             Total: -15 bytes

include/libbb.h
libbb/sha1.c

index b6eab6f24facfaf012c68262b7a69c5e093e3cf0..bc47ce7ba76100abbe8be89e41e51543c6dd016d 100644 (file)
@@ -1324,7 +1324,7 @@ typedef struct sha1_ctx_t {
        uint32_t hash[8];    /* 5, +3 elements for sha256 */
        uint64_t total64;
        uint8_t wbuffer[64]; /* NB: always correctly aligned for uint64_t */
-       void (*process_block)(struct sha1_ctx_t*);
+       void (*process_block)(struct sha1_ctx_t*) FAST_FUNC;
 } sha1_ctx_t;
 void sha1_begin(sha1_ctx_t *ctx) FAST_FUNC;
 void sha1_hash(const void *data, size_t length, sha1_ctx_t *ctx) FAST_FUNC;
index 8ecf71a9df3f6cf50224503cad406d52c9ce7972..ccc317667e93c61ce9078c6df2e8db4c2c970e35 100644 (file)
@@ -56,7 +56,7 @@ static inline uint64_t hton64(uint64_t v)
 #define SHA1_BLOCK_SIZE  64
 #define SHA1_MASK        (SHA1_BLOCK_SIZE - 1)
 
-static void sha1_process_block64(sha1_ctx_t *ctx)
+static void FAST_FUNC sha1_process_block64(sha1_ctx_t *ctx)
 {
        unsigned i;
        uint32_t w[80], a, b, c, d, e, t;
@@ -203,7 +203,7 @@ static const uint32_t K512_lo[80] = {
 
 /* Process LEN bytes of BUFFER, accumulating context into CTX.
    LEN is rounded _down_ to 64.  */
-static void sha256_process_block64(sha256_ctx_t *ctx)
+static void FAST_FUNC sha256_process_block64(sha256_ctx_t *ctx)
 {
        unsigned t;
        uint32_t W[64];
@@ -266,7 +266,7 @@ static void sha256_process_block64(sha256_ctx_t *ctx)
 }
 /* Process LEN bytes of BUFFER, accumulating context into CTX.
    LEN is rounded _down_ to 128.  */
-static void sha512_process_block128(sha512_ctx_t *ctx)
+static void FAST_FUNC sha512_process_block128(sha512_ctx_t *ctx)
 {
        unsigned t;
        uint64_t W[80];
@@ -278,7 +278,7 @@ static void sha512_process_block128(sha512_ctx_t *ctx)
        uint64_t f = ctx->hash[5];
        uint64_t g = ctx->hash[6];
        uint64_t h = ctx->hash[7];
-       const uint32_t *words = (uint32_t*) ctx->wbuffer;
+       const uint64_t *words = (uint64_t*) ctx->wbuffer;
 
        /* Operators defined in FIPS 180-2:4.1.2.  */
 #define Ch(x, y, z) ((x & y) ^ (~x & z))