diff options
author | Eric Andersen <andersen@codepoet.org> | 2004-01-30 22:31:58 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2004-01-30 22:31:58 +0000 |
commit | ad84a516bb825f987d7d5c2e05270449fb408c04 (patch) | |
tree | ca56b3554dd00a21764d5b96de6176d3e9851062 | |
parent | ab26cc3d8aec8267aaa1319a3f2cfa11c6bf41d2 (diff) | |
download | busybox-w32-ad84a516bb825f987d7d5c2e05270449fb408c04.tar.gz busybox-w32-ad84a516bb825f987d7d5c2e05270449fb408c04.tar.bz2 busybox-w32-ad84a516bb825f987d7d5c2e05270449fb408c04.zip |
Use proper C99 types throughout. So not use silly typedefs.
-rw-r--r-- | libbb/hash_fd.c | 91 |
1 files changed, 44 insertions, 47 deletions
diff --git a/libbb/hash_fd.c b/libbb/hash_fd.c index 58394522f..e79d6d6f6 100644 --- a/libbb/hash_fd.c +++ b/libbb/hash_fd.c | |||
@@ -106,13 +106,13 @@ | |||
106 | e = d; d = c; c = rotl32(b, 30); b = t | 106 | e = d; d = c; c = rotl32(b, 30); b = t |
107 | 107 | ||
108 | /* type to hold the SHA1 context */ | 108 | /* type to hold the SHA1 context */ |
109 | typedef struct sha1_ctx_s { | 109 | struct sha1_ctx_t { |
110 | uint32_t count[2]; | 110 | uint32_t count[2]; |
111 | uint32_t hash[5]; | 111 | uint32_t hash[5]; |
112 | uint32_t wbuf[16]; | 112 | uint32_t wbuf[16]; |
113 | } sha1_ctx_t; | 113 | }; |
114 | 114 | ||
115 | static void sha1_compile(sha1_ctx_t *ctx) | 115 | static void sha1_compile(struct sha1_ctx_t *ctx) |
116 | { | 116 | { |
117 | uint32_t w[80], i, a, b, c, d, e, t; | 117 | uint32_t w[80], i, a, b, c, d, e, t; |
118 | 118 | ||
@@ -154,7 +154,7 @@ static void sha1_compile(sha1_ctx_t *ctx) | |||
154 | ctx->hash[4] += e; | 154 | ctx->hash[4] += e; |
155 | } | 155 | } |
156 | 156 | ||
157 | static void sha1_begin(sha1_ctx_t *ctx) | 157 | static void sha1_begin(struct sha1_ctx_t *ctx) |
158 | { | 158 | { |
159 | ctx->count[0] = ctx->count[1] = 0; | 159 | ctx->count[0] = ctx->count[1] = 0; |
160 | ctx->hash[0] = 0x67452301; | 160 | ctx->hash[0] = 0x67452301; |
@@ -168,7 +168,7 @@ static void sha1_begin(sha1_ctx_t *ctx) | |||
168 | /* hash_compile function as required. */ | 168 | /* hash_compile function as required. */ |
169 | static void sha1_hash(const void *data, size_t len, void *ctx_v) | 169 | static void sha1_hash(const void *data, size_t len, void *ctx_v) |
170 | { | 170 | { |
171 | sha1_ctx_t *ctx = (sha1_ctx_t *) ctx_v; | 171 | struct sha1_ctx_t *ctx = (struct sha1_ctx_t *) ctx_v; |
172 | uint32_t pos = (uint32_t) (ctx->count[0] & SHA1_MASK); | 172 | uint32_t pos = (uint32_t) (ctx->count[0] & SHA1_MASK); |
173 | uint32_t freeb = SHA1_BLOCK_SIZE - pos; | 173 | uint32_t freeb = SHA1_BLOCK_SIZE - pos; |
174 | const unsigned char *sp = data; | 174 | const unsigned char *sp = data; |
@@ -197,7 +197,7 @@ static uint32_t mask[4] = { 0x00000000, 0xff000000, 0xffff0000, 0xffffff00 }; | |||
197 | static uint32_t bits[4] = { 0x80000000, 0x00800000, 0x00008000, 0x00000080 }; | 197 | static uint32_t bits[4] = { 0x80000000, 0x00800000, 0x00008000, 0x00000080 }; |
198 | # endif /* __BYTE_ORDER */ | 198 | # endif /* __BYTE_ORDER */ |
199 | 199 | ||
200 | void sha1_end(unsigned char hval[], sha1_ctx_t *ctx) | 200 | void sha1_end(unsigned char hval[], struct sha1_ctx_t *ctx) |
201 | { | 201 | { |
202 | uint32_t i, cnt = (uint32_t) (ctx->count[0] & SHA1_MASK); | 202 | uint32_t i, cnt = (uint32_t) (ctx->count[0] & SHA1_MASK); |
203 | 203 | ||
@@ -288,24 +288,21 @@ void sha1_end(unsigned char hval[], sha1_ctx_t *ctx) | |||
288 | static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ }; | 288 | static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ }; |
289 | # endif /* MD5SUM_SIZE_VS_SPEED == 0 */ | 289 | # endif /* MD5SUM_SIZE_VS_SPEED == 0 */ |
290 | 290 | ||
291 | typedef u_int32_t md5_uint32; | ||
292 | |||
293 | /* Structure to save state of computation between the single steps. */ | 291 | /* Structure to save state of computation between the single steps. */ |
294 | typedef struct md5_ctx_s { | 292 | struct md5_ctx_t { |
295 | md5_uint32 A; | 293 | uint32_t A; |
296 | md5_uint32 B; | 294 | uint32_t B; |
297 | md5_uint32 C; | 295 | uint32_t C; |
298 | md5_uint32 D; | 296 | uint32_t D; |
299 | 297 | uint32_t total[2]; | |
300 | md5_uint32 total[2]; | 298 | uint32_t buflen; |
301 | md5_uint32 buflen; | ||
302 | char buffer[128]; | 299 | char buffer[128]; |
303 | } md5_ctx_t; | 300 | }; |
304 | 301 | ||
305 | /* Initialize structure containing state of computation. | 302 | /* Initialize structure containing state of computation. |
306 | * (RFC 1321, 3.3: Step 3) | 303 | * (RFC 1321, 3.3: Step 3) |
307 | */ | 304 | */ |
308 | static void md5_begin(md5_ctx_t *ctx) | 305 | static void md5_begin(struct md5_ctx_t *ctx) |
309 | { | 306 | { |
310 | ctx->A = 0x67452301; | 307 | ctx->A = 0x67452301; |
311 | ctx->B = 0xefcdab89; | 308 | ctx->B = 0xefcdab89; |
@@ -331,15 +328,15 @@ static void md5_begin(md5_ctx_t *ctx) | |||
331 | * starting at BUFFER. | 328 | * starting at BUFFER. |
332 | * It is necessary that LEN is a multiple of 64!!! | 329 | * It is necessary that LEN is a multiple of 64!!! |
333 | */ | 330 | */ |
334 | static void md5_hash_block(const void *buffer, size_t len, md5_ctx_t *ctx) | 331 | static void md5_hash_block(const void *buffer, size_t len, struct md5_ctx_t *ctx) |
335 | { | 332 | { |
336 | md5_uint32 correct_words[16]; | 333 | uint32_t correct_words[16]; |
337 | const md5_uint32 *words = buffer; | 334 | const uint32_t *words = buffer; |
338 | size_t nwords = len / sizeof(md5_uint32); | 335 | size_t nwords = len / sizeof(uint32_t); |
339 | const md5_uint32 *endp = words + nwords; | 336 | const uint32_t *endp = words + nwords; |
340 | 337 | ||
341 | # if MD5SUM_SIZE_VS_SPEED > 0 | 338 | # if MD5SUM_SIZE_VS_SPEED > 0 |
342 | static const md5_uint32 C_array[] = { | 339 | static const uint32_t C_array[] = { |
343 | /* round 1 */ | 340 | /* round 1 */ |
344 | 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, | 341 | 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, |
345 | 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, | 342 | 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, |
@@ -381,10 +378,10 @@ static void md5_hash_block(const void *buffer, size_t len, md5_ctx_t *ctx) | |||
381 | # endif /* MD5SUM_SIZE_VS_SPEED > 1 */ | 378 | # endif /* MD5SUM_SIZE_VS_SPEED > 1 */ |
382 | # endif | 379 | # endif |
383 | 380 | ||
384 | md5_uint32 A = ctx->A; | 381 | uint32_t A = ctx->A; |
385 | md5_uint32 B = ctx->B; | 382 | uint32_t B = ctx->B; |
386 | md5_uint32 C = ctx->C; | 383 | uint32_t C = ctx->C; |
387 | md5_uint32 D = ctx->D; | 384 | uint32_t D = ctx->D; |
388 | 385 | ||
389 | /* First increment the byte count. RFC 1321 specifies the possible | 386 | /* First increment the byte count. RFC 1321 specifies the possible |
390 | length of the file up to 2^64 bits. Here we only compute the | 387 | length of the file up to 2^64 bits. Here we only compute the |
@@ -396,20 +393,20 @@ static void md5_hash_block(const void *buffer, size_t len, md5_ctx_t *ctx) | |||
396 | /* Process all bytes in the buffer with 64 bytes in each round of | 393 | /* Process all bytes in the buffer with 64 bytes in each round of |
397 | the loop. */ | 394 | the loop. */ |
398 | while (words < endp) { | 395 | while (words < endp) { |
399 | md5_uint32 *cwp = correct_words; | 396 | uint32_t *cwp = correct_words; |
400 | md5_uint32 A_save = A; | 397 | uint32_t A_save = A; |
401 | md5_uint32 B_save = B; | 398 | uint32_t B_save = B; |
402 | md5_uint32 C_save = C; | 399 | uint32_t C_save = C; |
403 | md5_uint32 D_save = D; | 400 | uint32_t D_save = D; |
404 | 401 | ||
405 | # if MD5SUM_SIZE_VS_SPEED > 1 | 402 | # if MD5SUM_SIZE_VS_SPEED > 1 |
406 | # define CYCLIC(w, s) (w = (w << s) | (w >> (32 - s))) | 403 | # define CYCLIC(w, s) (w = (w << s) | (w >> (32 - s))) |
407 | 404 | ||
408 | const md5_uint32 *pc; | 405 | const uint32_t *pc; |
409 | const char *pp; | 406 | const char *pp; |
410 | const char *ps; | 407 | const char *ps; |
411 | int i; | 408 | int i; |
412 | md5_uint32 temp; | 409 | uint32_t temp; |
413 | 410 | ||
414 | for (i = 0; i < 16; i++) { | 411 | for (i = 0; i < 16; i++) { |
415 | cwp[i] = SWAP(words[i]); | 412 | cwp[i] = SWAP(words[i]); |
@@ -523,7 +520,7 @@ static void md5_hash_block(const void *buffer, size_t len, md5_ctx_t *ctx) | |||
523 | */ | 520 | */ |
524 | 521 | ||
525 | # if MD5SUM_SIZE_VS_SPEED == 1 | 522 | # if MD5SUM_SIZE_VS_SPEED == 1 |
526 | const md5_uint32 *pc; | 523 | const uint32_t *pc; |
527 | const char *pp; | 524 | const char *pp; |
528 | int i; | 525 | int i; |
529 | # endif /* MD5SUM_SIZE_VS_SPEED */ | 526 | # endif /* MD5SUM_SIZE_VS_SPEED */ |
@@ -672,7 +669,7 @@ static void md5_hash_block(const void *buffer, size_t len, md5_ctx_t *ctx) | |||
672 | * It is NOT required that LEN is a multiple of 64. | 669 | * It is NOT required that LEN is a multiple of 64. |
673 | */ | 670 | */ |
674 | 671 | ||
675 | static void md5_hash_bytes(const void *buffer, size_t len, md5_ctx_t *ctx) | 672 | static void md5_hash_bytes(const void *buffer, size_t len, struct md5_ctx_t *ctx) |
676 | { | 673 | { |
677 | /* When we already have some bits in our internal buffer concatenate | 674 | /* When we already have some bits in our internal buffer concatenate |
678 | both inputs first. */ | 675 | both inputs first. */ |
@@ -726,10 +723,10 @@ static void md5_hash(const void *buffer, size_t length, void *md5_ctx) | |||
726 | * IMPORTANT: On some systems it is required that RESBUF is correctly | 723 | * IMPORTANT: On some systems it is required that RESBUF is correctly |
727 | * aligned for a 32 bits value. | 724 | * aligned for a 32 bits value. |
728 | */ | 725 | */ |
729 | static void *md5_end(void *resbuf, md5_ctx_t *ctx) | 726 | static void *md5_end(void *resbuf, struct md5_ctx_t *ctx) |
730 | { | 727 | { |
731 | /* Take yet unprocessed bytes into account. */ | 728 | /* Take yet unprocessed bytes into account. */ |
732 | md5_uint32 bytes = ctx->buflen; | 729 | uint32_t bytes = ctx->buflen; |
733 | size_t pad; | 730 | size_t pad; |
734 | 731 | ||
735 | /* Now count remaining bytes. */ | 732 | /* Now count remaining bytes. */ |
@@ -746,8 +743,8 @@ static void *md5_end(void *resbuf, md5_ctx_t *ctx) | |||
746 | # endif /* MD5SUM_SIZE_VS_SPEED > 0 */ | 743 | # endif /* MD5SUM_SIZE_VS_SPEED > 0 */ |
747 | 744 | ||
748 | /* Put the 64-bit file length in *bits* at the end of the buffer. */ | 745 | /* Put the 64-bit file length in *bits* at the end of the buffer. */ |
749 | *(md5_uint32 *) & ctx->buffer[bytes + pad] = SWAP(ctx->total[0] << 3); | 746 | *(uint32_t *) & ctx->buffer[bytes + pad] = SWAP(ctx->total[0] << 3); |
750 | *(md5_uint32 *) & ctx->buffer[bytes + pad + 4] = | 747 | *(uint32_t *) & ctx->buffer[bytes + pad + 4] = |
751 | SWAP(((ctx->total[1] << 3) | (ctx->total[0] >> 29))); | 748 | SWAP(((ctx->total[1] << 3) | (ctx->total[0] >> 29))); |
752 | 749 | ||
753 | /* Process last bytes. */ | 750 | /* Process last bytes. */ |
@@ -760,10 +757,10 @@ static void *md5_end(void *resbuf, md5_ctx_t *ctx) | |||
760 | * IMPORTANT: On some systems it is required that RESBUF is correctly | 757 | * IMPORTANT: On some systems it is required that RESBUF is correctly |
761 | * aligned for a 32 bits value. | 758 | * aligned for a 32 bits value. |
762 | */ | 759 | */ |
763 | ((md5_uint32 *) resbuf)[0] = SWAP(ctx->A); | 760 | ((uint32_t *) resbuf)[0] = SWAP(ctx->A); |
764 | ((md5_uint32 *) resbuf)[1] = SWAP(ctx->B); | 761 | ((uint32_t *) resbuf)[1] = SWAP(ctx->B); |
765 | ((md5_uint32 *) resbuf)[2] = SWAP(ctx->C); | 762 | ((uint32_t *) resbuf)[2] = SWAP(ctx->C); |
766 | ((md5_uint32 *) resbuf)[3] = SWAP(ctx->D); | 763 | ((uint32_t *) resbuf)[3] = SWAP(ctx->D); |
767 | 764 | ||
768 | return resbuf; | 765 | return resbuf; |
769 | } | 766 | } |
@@ -784,10 +781,10 @@ extern int hash_fd(int src_fd, const size_t size, const uint8_t hash_algo, | |||
784 | void *cx = NULL; | 781 | void *cx = NULL; |
785 | 782 | ||
786 | #ifdef CONFIG_SHA1SUM | 783 | #ifdef CONFIG_SHA1SUM |
787 | sha1_ctx_t sha1_cx; | 784 | struct sha1_ctx_t sha1_cx; |
788 | #endif | 785 | #endif |
789 | #ifdef CONFIG_MD5SUM | 786 | #ifdef CONFIG_MD5SUM |
790 | md5_ctx_t md5_cx; | 787 | struct md5_ctx_t md5_cx; |
791 | #endif | 788 | #endif |
792 | 789 | ||
793 | 790 | ||