summaryrefslogtreecommitdiff
path: root/include/libbb.h
diff options
context:
space:
mode:
authorDenys Vlasenko2010-10-19 02:16:12 +0200
committerDenys Vlasenko2010-10-19 02:16:12 +0200
commit302ad1450e104460abd3aae60b7f40d8a88f43df (patch)
tree0558bb8533889fa16d820e4466d3b72da083b9f6 /include/libbb.h
parentd982da79deb36185c420f94417b57e7b8a4af04c (diff)
downloadbusybox-302ad1450e104460abd3aae60b7f40d8a88f43df.zip
busybox-302ad1450e104460abd3aae60b7f40d8a88f43df.tar.gz
libbb/hash_md5_sha: use common ctx and code for md5 and sha1/256
function old new delta sha256_process_block64 421 433 +12 md5_crypt 578 587 +9 md5_begin 43 50 +7 md5_hash 99 97 -2 sha1_end 85 82 -3 md5_end 36 31 -5 common64_end 93 86 -7 sha1_hash 97 - -97 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'include/libbb.h')
-rw-r--r--include/libbb.h44
1 files changed, 14 insertions, 30 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 3c8764b..01dc33e 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1515,44 +1515,28 @@ enum {
};
void FAST_FUNC read_base64(FILE *src_stream, FILE *dst_stream, int flags);
-#if 1
typedef struct md5_ctx_t {
- char wbuffer[64]; /* NB: always correctly aligned for uint64_t */
- uint64_t total64;
- uint32_t A;
- uint32_t B;
- uint32_t C;
- uint32_t D;
-} md5_ctx_t;
-#else
-/* libbb/md5prime.c uses a bit different one: */
-typedef struct md5_ctx_t {
- uint32_t state[4]; /* state (ABCD) */
- uint32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */
- unsigned char buffer[64]; /* input buffer */
+ uint8_t wbuffer[64]; /* always correctly aligned for uint64_t */
+ void (*process_block)(struct md5_ctx_t*) FAST_FUNC;
+ uint64_t total64; /* must be directly before hash[] */
+ uint32_t hash[8]; /* 4 elements for md5, 5 for sha1, 8 for sha256 */
} md5_ctx_t;
-#endif
+typedef struct md5_ctx_t sha1_ctx_t;
+typedef struct md5_ctx_t sha256_ctx_t;
+typedef struct sha512_ctx_t {
+ uint64_t total64[2]; /* must be directly before hash[] */
+ uint64_t hash[8];
+ uint8_t wbuffer[128]; /* always correctly aligned for uint64_t */
+} sha512_ctx_t;
void md5_begin(md5_ctx_t *ctx) FAST_FUNC;
void md5_hash(md5_ctx_t *ctx, const void *data, size_t length) FAST_FUNC;
void md5_end(md5_ctx_t *ctx, void *resbuf) FAST_FUNC;
-typedef struct sha1_ctx_t {
- uint8_t wbuffer[64]; /* NB: always correctly aligned for uint64_t */
- uint64_t total64; /* must be directly before hash[] */
- uint32_t hash[8]; /* 5, +3 elements for sha256 */
- void (*process_block)(struct sha1_ctx_t*) FAST_FUNC;
-} sha1_ctx_t;
void sha1_begin(sha1_ctx_t *ctx) FAST_FUNC;
-void sha1_hash(sha1_ctx_t *ctx, const void *data, size_t length) FAST_FUNC;
+#define sha1_hash md5_hash
void sha1_end(sha1_ctx_t *ctx, void *resbuf) FAST_FUNC;
-typedef struct sha1_ctx_t sha256_ctx_t;
void sha256_begin(sha256_ctx_t *ctx) FAST_FUNC;
-#define sha256_hash sha1_hash
-#define sha256_end sha1_end
-typedef struct sha512_ctx_t {
- uint64_t total64[2]; /* must be directly before hash[] */
- uint64_t hash[8];
- uint8_t wbuffer[128]; /* NB: always correctly aligned for uint64_t */
-} sha512_ctx_t;
+#define sha256_hash md5_hash
+#define sha256_end sha1_end
void sha512_begin(sha512_ctx_t *ctx) FAST_FUNC;
void sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC;
void sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC;