diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-10-16 20:45:27 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-10-16 20:45:27 +0200 |
commit | c0683acce88efc1fe15d9a4332428b5a9fdc6c2e (patch) | |
tree | cb0f5bb99b5e5f4490be175238d3a877115bc468 | |
parent | 1a5e11c874a1f53c5205140a9d675b7e6404bbc9 (diff) | |
download | busybox-w32-c0683acce88efc1fe15d9a4332428b5a9fdc6c2e.tar.gz busybox-w32-c0683acce88efc1fe15d9a4332428b5a9fdc6c2e.tar.bz2 busybox-w32-c0683acce88efc1fe15d9a4332428b5a9fdc6c2e.zip |
*: pass md5/shaN context pointer as 1st arg, not last
function old new delta
md5_hash_block 458 459 +1
filter_rename_config 252 250 -2
md5_crypt 591 587 -4
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | archival/dpkg.c | 4 | ||||
-rw-r--r-- | coreutils/md5_sha1_sum.c | 6 | ||||
-rw-r--r-- | include/libbb.h | 12 | ||||
-rw-r--r-- | libbb/md5.c | 12 | ||||
-rw-r--r-- | libbb/pw_encrypt_md5.c | 32 | ||||
-rw-r--r-- | libbb/sha1.c | 8 | ||||
-rw-r--r-- | mailutils/popmaildir.c | 6 |
7 files changed, 40 insertions, 40 deletions
diff --git a/archival/dpkg.c b/archival/dpkg.c index b36c26198..07f01501b 100644 --- a/archival/dpkg.c +++ b/archival/dpkg.c | |||
@@ -1524,8 +1524,8 @@ static char FAST_FUNC filter_rename_config(archive_handle_t *archive_handle) | |||
1524 | buf = xmalloc(4096); | 1524 | buf = xmalloc(4096); |
1525 | md5_begin(&md5); | 1525 | md5_begin(&md5); |
1526 | while ((count = safe_read(fd, buf, 4096)) > 0) | 1526 | while ((count = safe_read(fd, buf, 4096)) > 0) |
1527 | md5_hash(buf, count, &md5); | 1527 | md5_hash(&md5, buf, count); |
1528 | md5_end(buf, &md5); /* using buf as result storage */ | 1528 | md5_end(&md5, buf); /* using buf as result storage */ |
1529 | close(fd); | 1529 | close(fd); |
1530 | 1530 | ||
1531 | md5line = xmalloc(16 * 2 + 2 + strlen(name_ptr) + 1); | 1531 | md5line = xmalloc(16 * 2 + 2 + strlen(name_ptr) + 1); |
diff --git a/coreutils/md5_sha1_sum.c b/coreutils/md5_sha1_sum.c index 5e36d391a..e79210c0d 100644 --- a/coreutils/md5_sha1_sum.c +++ b/coreutils/md5_sha1_sum.c | |||
@@ -43,7 +43,7 @@ static uint8_t *hash_file(const char *filename /*, hash_algo_t hash_algo*/) | |||
43 | } context; | 43 | } context; |
44 | uint8_t *hash_value = NULL; | 44 | uint8_t *hash_value = NULL; |
45 | RESERVE_CONFIG_UBUFFER(in_buf, 4096); | 45 | RESERVE_CONFIG_UBUFFER(in_buf, 4096); |
46 | void FAST_FUNC (*update)(const void*, size_t, void*); | 46 | void FAST_FUNC (*update)(void*, const void*, size_t); |
47 | void FAST_FUNC (*final)(void*, void*); | 47 | void FAST_FUNC (*final)(void*, void*); |
48 | hash_algo_t hash_algo = applet_name[3]; | 48 | hash_algo_t hash_algo = applet_name[3]; |
49 | 49 | ||
@@ -78,11 +78,11 @@ static uint8_t *hash_file(const char *filename /*, hash_algo_t hash_algo*/) | |||
78 | } | 78 | } |
79 | 79 | ||
80 | while (0 < (count = safe_read(src_fd, in_buf, 4096))) { | 80 | while (0 < (count = safe_read(src_fd, in_buf, 4096))) { |
81 | update(in_buf, count, &context); | 81 | update(&context, in_buf, count); |
82 | } | 82 | } |
83 | 83 | ||
84 | if (count == 0) { | 84 | if (count == 0) { |
85 | final(in_buf, &context); | 85 | final(&context, in_buf); |
86 | hash_value = hash_bin_to_hex(in_buf, hash_len); | 86 | hash_value = hash_bin_to_hex(in_buf, hash_len); |
87 | } | 87 | } |
88 | 88 | ||
diff --git a/include/libbb.h b/include/libbb.h index 034016f4a..1031cad8b 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -1519,8 +1519,8 @@ typedef struct sha1_ctx_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; |
1521 | void sha1_begin(sha1_ctx_t *ctx) FAST_FUNC; | 1521 | void sha1_begin(sha1_ctx_t *ctx) FAST_FUNC; |
1522 | void sha1_hash(const void *data, size_t length, sha1_ctx_t *ctx) FAST_FUNC; | 1522 | void sha1_hash(sha1_ctx_t *ctx, const void *data, size_t length) FAST_FUNC; |
1523 | void sha1_end(void *resbuf, sha1_ctx_t *ctx) FAST_FUNC; | 1523 | void sha1_end(sha1_ctx_t *ctx, void *resbuf) FAST_FUNC; |
1524 | typedef struct sha1_ctx_t sha256_ctx_t; | 1524 | typedef struct sha1_ctx_t sha256_ctx_t; |
1525 | void sha256_begin(sha256_ctx_t *ctx) FAST_FUNC; | 1525 | void sha256_begin(sha256_ctx_t *ctx) FAST_FUNC; |
1526 | #define sha256_hash sha1_hash | 1526 | #define sha256_hash sha1_hash |
@@ -1531,8 +1531,8 @@ typedef struct sha512_ctx_t { | |||
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; |
1533 | void sha512_begin(sha512_ctx_t *ctx) FAST_FUNC; | 1533 | void sha512_begin(sha512_ctx_t *ctx) FAST_FUNC; |
1534 | void sha512_hash(const void *buffer, size_t len, sha512_ctx_t *ctx) FAST_FUNC; | 1534 | void sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; |
1535 | void sha512_end(void *resbuf, sha512_ctx_t *ctx) FAST_FUNC; | 1535 | void sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC; |
1536 | #if 1 | 1536 | #if 1 |
1537 | typedef struct md5_ctx_t { | 1537 | typedef struct md5_ctx_t { |
1538 | uint32_t A; | 1538 | uint32_t A; |
@@ -1551,8 +1551,8 @@ typedef struct md5_ctx_t { | |||
1551 | } md5_ctx_t; | 1551 | } md5_ctx_t; |
1552 | #endif | 1552 | #endif |
1553 | void md5_begin(md5_ctx_t *ctx) FAST_FUNC; | 1553 | void md5_begin(md5_ctx_t *ctx) FAST_FUNC; |
1554 | void md5_hash(const void *data, size_t length, md5_ctx_t *ctx) FAST_FUNC; | 1554 | void md5_hash(md5_ctx_t *ctx, const void *data, size_t length) FAST_FUNC; |
1555 | void md5_end(void *resbuf, md5_ctx_t *ctx) FAST_FUNC; | 1555 | void md5_end(md5_ctx_t *ctx, void *resbuf) FAST_FUNC; |
1556 | 1556 | ||
1557 | 1557 | ||
1558 | uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC; | 1558 | uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC; |
diff --git a/libbb/md5.c b/libbb/md5.c index 1f9d59e6e..47f5fc6f8 100644 --- a/libbb/md5.c +++ b/libbb/md5.c | |||
@@ -49,7 +49,7 @@ void FAST_FUNC md5_begin(md5_ctx_t *ctx) | |||
49 | #define rotl32(w, s) (((w) << (s)) | ((w) >> (32 - (s)))) | 49 | #define rotl32(w, s) (((w) << (s)) | ((w) >> (32 - (s)))) |
50 | 50 | ||
51 | /* Hash a single block, 64 bytes long and 4-byte aligned. */ | 51 | /* Hash a single block, 64 bytes long and 4-byte aligned. */ |
52 | static void md5_hash_block(const void *buffer, md5_ctx_t *ctx) | 52 | static void md5_hash_block(md5_ctx_t *ctx, const void *buffer) |
53 | { | 53 | { |
54 | uint32_t correct_words[16]; | 54 | uint32_t correct_words[16]; |
55 | const uint32_t *words = buffer; | 55 | const uint32_t *words = buffer; |
@@ -361,7 +361,7 @@ static void md5_hash_block(const void *buffer, md5_ctx_t *ctx) | |||
361 | * with chunks of data that are 4-byte aligned and a multiple of 64 bytes. | 361 | * with chunks of data that are 4-byte aligned and a multiple of 64 bytes. |
362 | * This function's internal buffer remembers previous data until it has 64 | 362 | * This function's internal buffer remembers previous data until it has 64 |
363 | * bytes worth to pass on. Call md5_end() to flush this buffer. */ | 363 | * bytes worth to pass on. Call md5_end() to flush this buffer. */ |
364 | void FAST_FUNC md5_hash(const void *buffer, size_t len, md5_ctx_t *ctx) | 364 | void FAST_FUNC md5_hash(md5_ctx_t *ctx, const void *buffer, size_t len) |
365 | { | 365 | { |
366 | const char *buf = buffer; | 366 | const char *buf = buffer; |
367 | unsigned buflen = BUFLEN(ctx); | 367 | unsigned buflen = BUFLEN(ctx); |
@@ -385,7 +385,7 @@ void FAST_FUNC md5_hash(const void *buffer, size_t len, md5_ctx_t *ctx) | |||
385 | if (buflen != 0) | 385 | if (buflen != 0) |
386 | break; | 386 | break; |
387 | /* Buffer is filled up, process it. */ | 387 | /* Buffer is filled up, process it. */ |
388 | md5_hash_block(ctx->buffer, ctx); | 388 | md5_hash_block(ctx, ctx->buffer); |
389 | /*buflen = 0; - already is */ | 389 | /*buflen = 0; - already is */ |
390 | } | 390 | } |
391 | } | 391 | } |
@@ -395,7 +395,7 @@ void FAST_FUNC md5_hash(const void *buffer, size_t len, md5_ctx_t *ctx) | |||
395 | * endian byte order, so that a byte-wise output yields to the wanted | 395 | * endian byte order, so that a byte-wise output yields to the wanted |
396 | * ASCII representation of the message digest. | 396 | * ASCII representation of the message digest. |
397 | */ | 397 | */ |
398 | void FAST_FUNC md5_end(void *resbuf, md5_ctx_t *ctx) | 398 | void FAST_FUNC md5_end(md5_ctx_t *ctx, void *resbuf) |
399 | { | 399 | { |
400 | uint64_t total; | 400 | uint64_t total; |
401 | char *buf = ctx->buffer; | 401 | char *buf = ctx->buffer; |
@@ -419,8 +419,8 @@ void FAST_FUNC md5_end(void *resbuf, md5_ctx_t *ctx) | |||
419 | 419 | ||
420 | /* Process last bytes. */ | 420 | /* Process last bytes. */ |
421 | if (buf != ctx->buffer) | 421 | if (buf != ctx->buffer) |
422 | md5_hash_block(ctx->buffer, ctx); | 422 | md5_hash_block(ctx, ctx->buffer); |
423 | md5_hash_block(buf, ctx); | 423 | md5_hash_block(ctx, buf); |
424 | 424 | ||
425 | /* The MD5 result is in little endian byte order. | 425 | /* The MD5 result is in little endian byte order. |
426 | * We (ab)use the fact that A-D are consecutive in memory. | 426 | * We (ab)use the fact that A-D are consecutive in memory. |
diff --git a/libbb/pw_encrypt_md5.c b/libbb/pw_encrypt_md5.c index 58964b567..889e09cab 100644 --- a/libbb/pw_encrypt_md5.c +++ b/libbb/pw_encrypt_md5.c | |||
@@ -92,10 +92,10 @@ md5_crypt(char result[MD5_OUT_BUFSIZE], const unsigned char *pw, const unsigned | |||
92 | /* Hash. the password first, since that is what is most unknown */ | 92 | /* Hash. the password first, since that is what is most unknown */ |
93 | md5_begin(&ctx); | 93 | md5_begin(&ctx); |
94 | pw_len = strlen((char*)pw); | 94 | pw_len = strlen((char*)pw); |
95 | md5_hash(pw, pw_len, &ctx); | 95 | md5_hash(&ctx, pw, pw_len); |
96 | 96 | ||
97 | /* Then the salt including "$1$" */ | 97 | /* Then the salt including "$1$" */ |
98 | md5_hash(salt, sl, &ctx); | 98 | md5_hash(&ctx, salt, sl); |
99 | 99 | ||
100 | /* Copy salt to result; skip "$1$" */ | 100 | /* Copy salt to result; skip "$1$" */ |
101 | memcpy(result, salt, sl); | 101 | memcpy(result, salt, sl); |
@@ -105,19 +105,19 @@ md5_crypt(char result[MD5_OUT_BUFSIZE], const unsigned char *pw, const unsigned | |||
105 | 105 | ||
106 | /* Then just as many characters of the MD5(pw, salt, pw) */ | 106 | /* Then just as many characters of the MD5(pw, salt, pw) */ |
107 | md5_begin(&ctx1); | 107 | md5_begin(&ctx1); |
108 | md5_hash(pw, pw_len, &ctx1); | 108 | md5_hash(&ctx1, pw, pw_len); |
109 | md5_hash(salt, sl, &ctx1); | 109 | md5_hash(&ctx1, salt, sl); |
110 | md5_hash(pw, pw_len, &ctx1); | 110 | md5_hash(&ctx1, pw, pw_len); |
111 | md5_end(final, &ctx1); | 111 | md5_end(&ctx1, final); |
112 | for (pl = pw_len; pl > 0; pl -= 16) | 112 | for (pl = pw_len; pl > 0; pl -= 16) |
113 | md5_hash(final, pl > 16 ? 16 : pl, &ctx); | 113 | md5_hash(&ctx, final, pl > 16 ? 16 : pl); |
114 | 114 | ||
115 | /* Then something really weird... */ | 115 | /* Then something really weird... */ |
116 | memset(final, 0, sizeof(final)); | 116 | memset(final, 0, sizeof(final)); |
117 | for (i = pw_len; i; i >>= 1) { | 117 | for (i = pw_len; i; i >>= 1) { |
118 | md5_hash(((i & 1) ? final : (const unsigned char *) pw), 1, &ctx); | 118 | md5_hash(&ctx, ((i & 1) ? final : (const unsigned char *) pw), 1); |
119 | } | 119 | } |
120 | md5_end(final, &ctx); | 120 | md5_end(&ctx, final); |
121 | 121 | ||
122 | /* And now, just to make sure things don't run too fast. | 122 | /* And now, just to make sure things don't run too fast. |
123 | * On a 60 Mhz Pentium this takes 34 msec, so you would | 123 | * On a 60 Mhz Pentium this takes 34 msec, so you would |
@@ -126,21 +126,21 @@ md5_crypt(char result[MD5_OUT_BUFSIZE], const unsigned char *pw, const unsigned | |||
126 | for (i = 0; i < 1000; i++) { | 126 | for (i = 0; i < 1000; i++) { |
127 | md5_begin(&ctx1); | 127 | md5_begin(&ctx1); |
128 | if (i & 1) | 128 | if (i & 1) |
129 | md5_hash(pw, pw_len, &ctx1); | 129 | md5_hash(&ctx1, pw, pw_len); |
130 | else | 130 | else |
131 | md5_hash(final, 16, &ctx1); | 131 | md5_hash(&ctx1, final, 16); |
132 | 132 | ||
133 | if (i % 3) | 133 | if (i % 3) |
134 | md5_hash(salt, sl, &ctx1); | 134 | md5_hash(&ctx1, salt, sl); |
135 | 135 | ||
136 | if (i % 7) | 136 | if (i % 7) |
137 | md5_hash(pw, pw_len, &ctx1); | 137 | md5_hash(&ctx1, pw, pw_len); |
138 | 138 | ||
139 | if (i & 1) | 139 | if (i & 1) |
140 | md5_hash(final, 16, &ctx1); | 140 | md5_hash(&ctx1, final, 16); |
141 | else | 141 | else |
142 | md5_hash(pw, pw_len, &ctx1); | 142 | md5_hash(&ctx1, pw, pw_len); |
143 | md5_end(final, &ctx1); | 143 | md5_end(&ctx1, final); |
144 | } | 144 | } |
145 | 145 | ||
146 | p = result + sl + 4; /* 12 bytes max (sl is up to 8 bytes) */ | 146 | p = result + sl + 4; /* 12 bytes max (sl is up to 8 bytes) */ |
diff --git a/libbb/sha1.c b/libbb/sha1.c index beeb70cf6..fac23c0ec 100644 --- a/libbb/sha1.c +++ b/libbb/sha1.c | |||
@@ -361,7 +361,7 @@ void FAST_FUNC sha512_begin(sha512_ctx_t *ctx) | |||
361 | 361 | ||
362 | 362 | ||
363 | /* Used also for sha256 */ | 363 | /* Used also for sha256 */ |
364 | void FAST_FUNC sha1_hash(const void *buffer, size_t len, sha1_ctx_t *ctx) | 364 | void FAST_FUNC sha1_hash(sha1_ctx_t *ctx, const void *buffer, size_t len) |
365 | { | 365 | { |
366 | unsigned in_buf = ctx->total64 & 63; | 366 | unsigned in_buf = ctx->total64 & 63; |
367 | unsigned add = 64 - in_buf; | 367 | unsigned add = 64 - in_buf; |
@@ -380,7 +380,7 @@ void FAST_FUNC sha1_hash(const void *buffer, size_t len, sha1_ctx_t *ctx) | |||
380 | memcpy(ctx->wbuffer + in_buf, buffer, len); | 380 | memcpy(ctx->wbuffer + in_buf, buffer, len); |
381 | } | 381 | } |
382 | 382 | ||
383 | void FAST_FUNC sha512_hash(const void *buffer, size_t len, sha512_ctx_t *ctx) | 383 | void FAST_FUNC sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) |
384 | { | 384 | { |
385 | unsigned in_buf = ctx->total64[0] & 127; | 385 | unsigned in_buf = ctx->total64[0] & 127; |
386 | unsigned add = 128 - in_buf; | 386 | unsigned add = 128 - in_buf; |
@@ -406,7 +406,7 @@ void FAST_FUNC sha512_hash(const void *buffer, size_t len, sha512_ctx_t *ctx) | |||
406 | 406 | ||
407 | 407 | ||
408 | /* Used also for sha256 */ | 408 | /* Used also for sha256 */ |
409 | void FAST_FUNC sha1_end(void *resbuf, sha1_ctx_t *ctx) | 409 | void FAST_FUNC sha1_end(sha1_ctx_t *ctx, void *resbuf) |
410 | { | 410 | { |
411 | unsigned pad, in_buf; | 411 | unsigned pad, in_buf; |
412 | 412 | ||
@@ -442,7 +442,7 @@ void FAST_FUNC sha1_end(void *resbuf, sha1_ctx_t *ctx) | |||
442 | memcpy(resbuf, ctx->hash, sizeof(ctx->hash[0]) * in_buf); | 442 | memcpy(resbuf, ctx->hash, sizeof(ctx->hash[0]) * in_buf); |
443 | } | 443 | } |
444 | 444 | ||
445 | void FAST_FUNC sha512_end(void *resbuf, sha512_ctx_t *ctx) | 445 | void FAST_FUNC sha512_end(sha512_ctx_t *ctx, void *resbuf) |
446 | { | 446 | { |
447 | unsigned pad, in_buf; | 447 | unsigned pad, in_buf; |
448 | 448 | ||
diff --git a/mailutils/popmaildir.c b/mailutils/popmaildir.c index f37db03d5..77ec71129 100644 --- a/mailutils/popmaildir.c +++ b/mailutils/popmaildir.c | |||
@@ -109,9 +109,9 @@ int popmaildir_main(int argc UNUSED_PARAM, char **argv) | |||
109 | s[1] = '\0'; | 109 | s[1] = '\0'; |
110 | // get md5 sum of "<stamp>password" string | 110 | // get md5 sum of "<stamp>password" string |
111 | md5_begin(&md5.ctx); | 111 | md5_begin(&md5.ctx); |
112 | md5_hash(buf, strlen(buf), &md5.ctx); | 112 | md5_hash(&md5.ctx, buf, strlen(buf)); |
113 | md5_hash(G.pass, strlen(G.pass), &md5.ctx); | 113 | md5_hash(&md5.ctx, G.pass, strlen(G.pass)); |
114 | md5_end(res, &md5.ctx); | 114 | md5_end(&md5.ctx, res); |
115 | *bin2hex(md5.hex, (char*)res, 16) = '\0'; | 115 | *bin2hex(md5.hex, (char*)res, 16) = '\0'; |
116 | // APOP | 116 | // APOP |
117 | s = xasprintf("%s %s", G.user, md5.hex); | 117 | s = xasprintf("%s %s", G.user, md5.hex); |