diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-11-10 09:51:15 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-11-10 09:51:15 +0000 |
commit | 0a009c3c6b9b6d43575dcdda46076e7a87522426 (patch) | |
tree | f111064e68756234a789ad423ee579d98fe67b37 | |
parent | 4cfa5a27aaefc4c3c7a931c1808ea58f7c84bf94 (diff) | |
download | busybox-w32-0a009c3c6b9b6d43575dcdda46076e7a87522426.tar.gz busybox-w32-0a009c3c6b9b6d43575dcdda46076e7a87522426.tar.bz2 busybox-w32-0a009c3c6b9b6d43575dcdda46076e7a87522426.zip |
libbb: constify some data in sha1. gcc is clever enough to do it itself,
thus no actual code changes. Also some pointless beautifuing crept in.
-rw-r--r-- | libbb/sha1.c | 35 |
1 files changed, 13 insertions, 22 deletions
diff --git a/libbb/sha1.c b/libbb/sha1.c index cc7edd8a7..44ea4eb47 100644 --- a/libbb/sha1.c +++ b/libbb/sha1.c | |||
@@ -21,14 +21,11 @@ | |||
21 | #define SHA1_BLOCK_SIZE 64 | 21 | #define SHA1_BLOCK_SIZE 64 |
22 | #define SHA1_DIGEST_SIZE 20 | 22 | #define SHA1_DIGEST_SIZE 20 |
23 | #define SHA1_HASH_SIZE SHA1_DIGEST_SIZE | 23 | #define SHA1_HASH_SIZE SHA1_DIGEST_SIZE |
24 | #define SHA2_GOOD 0 | 24 | #define SHA1_MASK (SHA1_BLOCK_SIZE - 1) |
25 | #define SHA2_BAD 1 | ||
26 | 25 | ||
27 | #define rotl32(x,n) (((x) << n) | ((x) >> (32 - n))) | 26 | #define rotl32(x,n) (((x) << n) | ((x) >> (32 - n))) |
28 | 27 | ||
29 | #define SHA1_MASK (SHA1_BLOCK_SIZE - 1) | 28 | /* Reverse byte order in 32-bit words */ |
30 | |||
31 | /* reverse byte order in 32-bit words */ | ||
32 | #define ch(x,y,z) ((z) ^ ((x) & ((y) ^ (z)))) | 29 | #define ch(x,y,z) ((z) ^ ((x) & ((y) ^ (z)))) |
33 | #define parity(x,y,z) ((x) ^ (y) ^ (z)) | 30 | #define parity(x,y,z) ((x) ^ (y) ^ (z)) |
34 | #define maj(x,y,z) (((x) & (y)) | ((z) & ((x) | (y)))) | 31 | #define maj(x,y,z) (((x) & (y)) | ((z) & ((x) | (y)))) |
@@ -60,21 +57,17 @@ static void sha1_compile(sha1_ctx_t *ctx) | |||
60 | d = ctx->hash[3]; | 57 | d = ctx->hash[3]; |
61 | e = ctx->hash[4]; | 58 | e = ctx->hash[4]; |
62 | 59 | ||
63 | for (i = 0; i < 20; ++i) { | 60 | for (i = 0; i < 20; ++i) |
64 | rnd(ch, 0x5a827999); | 61 | rnd(ch, 0x5a827999); |
65 | } | ||
66 | 62 | ||
67 | for (i = 20; i < 40; ++i) { | 63 | for (i = 20; i < 40; ++i) |
68 | rnd(parity, 0x6ed9eba1); | 64 | rnd(parity, 0x6ed9eba1); |
69 | } | ||
70 | 65 | ||
71 | for (i = 40; i < 60; ++i) { | 66 | for (i = 40; i < 60; ++i) |
72 | rnd(maj, 0x8f1bbcdc); | 67 | rnd(maj, 0x8f1bbcdc); |
73 | } | ||
74 | 68 | ||
75 | for (i = 60; i < 80; ++i) { | 69 | for (i = 60; i < 80; ++i) |
76 | rnd(parity, 0xca62c1d6); | 70 | rnd(parity, 0xca62c1d6); |
77 | } | ||
78 | 71 | ||
79 | ctx->hash[0] += a; | 72 | ctx->hash[0] += a; |
80 | ctx->hash[1] += b; | 73 | ctx->hash[1] += b; |
@@ -102,7 +95,7 @@ void FAST_FUNC sha1_hash(const void *data, size_t length, sha1_ctx_t *ctx) | |||
102 | const unsigned char *sp = data; | 95 | const unsigned char *sp = data; |
103 | 96 | ||
104 | if ((ctx->count[0] += length) < length) | 97 | if ((ctx->count[0] += length) < length) |
105 | ++(ctx->count[1]); | 98 | ctx->count[1]++; |
106 | 99 | ||
107 | while (length >= freeb) { /* tranfer whole blocks while possible */ | 100 | while (length >= freeb) { /* tranfer whole blocks while possible */ |
108 | memcpy(((unsigned char *) ctx->wbuf) + pos, sp, freeb); | 101 | memcpy(((unsigned char *) ctx->wbuf) + pos, sp, freeb); |
@@ -120,11 +113,11 @@ void* FAST_FUNC sha1_end(void *resbuf, sha1_ctx_t *ctx) | |||
120 | { | 113 | { |
121 | /* SHA1 Final padding and digest calculation */ | 114 | /* SHA1 Final padding and digest calculation */ |
122 | #if BB_BIG_ENDIAN | 115 | #if BB_BIG_ENDIAN |
123 | static uint32_t mask[4] = { 0x00000000, 0xff000000, 0xffff0000, 0xffffff00 }; | 116 | static const uint32_t mask[4] = { 0x00000000, 0xff000000, 0xffff0000, 0xffffff00 }; |
124 | static uint32_t bits[4] = { 0x80000000, 0x00800000, 0x00008000, 0x00000080 }; | 117 | static const uint32_t bits[4] = { 0x80000000, 0x00800000, 0x00008000, 0x00000080 }; |
125 | #else | 118 | #else |
126 | static uint32_t mask[4] = { 0x00000000, 0x000000ff, 0x0000ffff, 0x00ffffff }; | 119 | static const uint32_t mask[4] = { 0x00000000, 0x000000ff, 0x0000ffff, 0x00ffffff }; |
127 | static uint32_t bits[4] = { 0x00000080, 0x00008000, 0x00800000, 0x80000000 }; | 120 | static const uint32_t bits[4] = { 0x00000080, 0x00008000, 0x00800000, 0x80000000 }; |
128 | #endif | 121 | #endif |
129 | 122 | ||
130 | uint8_t *hval = resbuf; | 123 | uint8_t *hval = resbuf; |
@@ -146,15 +139,14 @@ void* FAST_FUNC sha1_end(void *resbuf, sha1_ctx_t *ctx) | |||
146 | ctx->wbuf[15] = 0; | 139 | ctx->wbuf[15] = 0; |
147 | sha1_compile(ctx); | 140 | sha1_compile(ctx); |
148 | cnt = 0; | 141 | cnt = 0; |
149 | } else /* compute a word index for the empty buffer positions */ | 142 | } else /* compute a word index for the empty buffer positions */ |
150 | cnt = (cnt >> 2) + 1; | 143 | cnt = (cnt >> 2) + 1; |
151 | 144 | ||
152 | while (cnt < 14) /* and zero pad all but last two positions */ | 145 | while (cnt < 14) /* and zero pad all but last two positions */ |
153 | ctx->wbuf[cnt++] = 0; | 146 | ctx->wbuf[cnt++] = 0; |
154 | 147 | ||
155 | /* assemble the eight byte counter in the buffer in big-endian */ | 148 | /* assemble the eight byte counter in the buffer in big-endian */ |
156 | /* format */ | 149 | /* format */ |
157 | |||
158 | ctx->wbuf[14] = htonl((ctx->count[1] << 3) | (ctx->count[0] >> 29)); | 150 | ctx->wbuf[14] = htonl((ctx->count[1] << 3) | (ctx->count[0] >> 29)); |
159 | ctx->wbuf[15] = htonl(ctx->count[0] << 3); | 151 | ctx->wbuf[15] = htonl(ctx->count[0] << 3); |
160 | 152 | ||
@@ -162,7 +154,6 @@ void* FAST_FUNC sha1_end(void *resbuf, sha1_ctx_t *ctx) | |||
162 | 154 | ||
163 | /* extract the hash value as bytes in case the hash buffer is */ | 155 | /* extract the hash value as bytes in case the hash buffer is */ |
164 | /* misaligned for 32-bit words */ | 156 | /* misaligned for 32-bit words */ |
165 | |||
166 | for (i = 0; i < SHA1_DIGEST_SIZE; ++i) | 157 | for (i = 0; i < SHA1_DIGEST_SIZE; ++i) |
167 | hval[i] = (unsigned char) (ctx->hash[i >> 2] >> 8 * (~i & 3)); | 158 | hval[i] = (unsigned char) (ctx->hash[i >> 2] >> 8 * (~i & 3)); |
168 | 159 | ||