hash_md5_sha: use common finalization routine for MD5 and sha1/256. -15 bytes

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
This commit is contained in:
Denys Vlasenko
2010-10-18 14:48:30 +02:00
parent b5aa1d95a1
commit c48a5c607d
2 changed files with 110 additions and 103 deletions

View File

@ -1515,35 +1515,14 @@ enum {
};
void FAST_FUNC read_base64(FILE *src_stream, FILE *dst_stream, int flags);
typedef struct sha1_ctx_t {
uint32_t hash[8]; /* 5, +3 elements for sha256 */
uint64_t total64; /* must be directly after hash[] */
uint8_t wbuffer[64]; /* NB: always correctly aligned for uint64_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(sha1_ctx_t *ctx, const void *data, size_t length) FAST_FUNC;
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 hash[8];
uint64_t total64[2]; /* must be directly after hash[] */
uint8_t wbuffer[128]; /* NB: always correctly aligned for uint64_t */
} sha512_ctx_t;
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;
#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;
uint64_t total64;
char wbuffer[64]; /* NB: always correctly aligned for uint64_t */
} md5_ctx_t;
#else
/* libbb/md5prime.c uses a bit different one: */
@ -1556,6 +1535,27 @@ typedef struct md5_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;
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;
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;
uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC;