mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Fix MD5 32-bit alignment bug.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@2335 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
9213dcaa2f
commit
7db4e6e2ca
@ -1,3 +1,8 @@
|
|||||||
|
2000-05-15 Dave Peticolas <peticola@cs.ucdavis.edu>
|
||||||
|
|
||||||
|
* src/engine/guid/md5.c (md5_process_bytes): fix 32-bit alignment
|
||||||
|
bug.
|
||||||
|
|
||||||
2000-05-14 Dave Peticolas <peticola@cs.ucdavis.edu>
|
2000-05-14 Dave Peticolas <peticola@cs.ucdavis.edu>
|
||||||
|
|
||||||
* src/guile/guile-util.c: added several interface functions to
|
* src/guile/guile-util.c: added several interface functions to
|
||||||
|
@ -208,12 +208,16 @@ md5_process_bytes (buffer, len, ctx)
|
|||||||
size_t len;
|
size_t len;
|
||||||
struct md5_ctx *ctx;
|
struct md5_ctx *ctx;
|
||||||
{
|
{
|
||||||
|
#define NUM_MD5_WORDS 1024
|
||||||
|
size_t add = 0;
|
||||||
|
|
||||||
/* When we already have some bits in our internal buffer concatenate
|
/* When we already have some bits in our internal buffer concatenate
|
||||||
both inputs first. */
|
both inputs first. */
|
||||||
if (ctx->buflen != 0)
|
if (ctx->buflen != 0)
|
||||||
{
|
{
|
||||||
size_t left_over = ctx->buflen;
|
size_t left_over = ctx->buflen;
|
||||||
size_t add = 128 - left_over > len ? len : 128 - left_over;
|
|
||||||
|
add = 128 - left_over > len ? len : 128 - left_over;
|
||||||
|
|
||||||
memcpy (&ctx->buffer[left_over], buffer, add);
|
memcpy (&ctx->buffer[left_over], buffer, add);
|
||||||
ctx->buflen += add;
|
ctx->buflen += add;
|
||||||
@ -234,8 +238,29 @@ md5_process_bytes (buffer, len, ctx)
|
|||||||
/* Process available complete blocks. */
|
/* Process available complete blocks. */
|
||||||
if (len > 64)
|
if (len > 64)
|
||||||
{
|
{
|
||||||
md5_process_block (buffer, len & ~63, ctx);
|
if ((add & 3) == 0) /* buffer is still 32-bit aligned */
|
||||||
buffer = (const char *) buffer + (len & ~63);
|
{
|
||||||
|
md5_process_block (buffer, len & ~63, ctx);
|
||||||
|
buffer = (const char *) buffer + (len & ~63);
|
||||||
|
}
|
||||||
|
else /* buffer is not 32-bit aligned */
|
||||||
|
{
|
||||||
|
md5_uint32 md5_buffer[NUM_MD5_WORDS];
|
||||||
|
size_t num_bytes;
|
||||||
|
size_t buf_bytes;
|
||||||
|
|
||||||
|
num_bytes = len & ~63;
|
||||||
|
while (num_bytes > 0)
|
||||||
|
{
|
||||||
|
buf_bytes = (num_bytes < sizeof(md5_buffer)) ?
|
||||||
|
num_bytes : sizeof(md5_buffer);
|
||||||
|
memcpy (md5_buffer, buffer, buf_bytes);
|
||||||
|
md5_process_block (md5_buffer, buf_bytes, ctx);
|
||||||
|
num_bytes -= buf_bytes;
|
||||||
|
buffer = (const char *) buffer + buf_bytes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
len &= 63;
|
len &= 63;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* md5.h - Declaration of functions and data types used for MD5 sum
|
/* md5.h - Declaration of functions and data types used for MD5 sum
|
||||||
computing library functions.
|
computing library functions.
|
||||||
Copyright (C) 1995, 1996, 1999 Free Software Foundation, Inc.
|
Copyright (C) 1995, 1996 Free Software Foundation, Inc.
|
||||||
NOTE: The canonical source of this file is maintained with the GNU C
|
NOTE: The canonical source of this file is maintained with the GNU C
|
||||||
Library. Bugs can be reported to bug-glibc@prep.ai.mit.edu.
|
Library. Bugs can be reported to bug-glibc@prep.ai.mit.edu.
|
||||||
|
|
||||||
@ -99,17 +99,26 @@ struct md5_ctx
|
|||||||
(RFC 1321, 3.3: Step 3) */
|
(RFC 1321, 3.3: Step 3) */
|
||||||
extern void md5_init_ctx __P ((struct md5_ctx *ctx));
|
extern void md5_init_ctx __P ((struct md5_ctx *ctx));
|
||||||
|
|
||||||
/* Starting with the result of former calls of this function (or the
|
|
||||||
initialization function update the context for the next LEN bytes
|
|
||||||
starting at BUFFER.
|
|
||||||
It is necessary that LEN is a multiple of 64!!! */
|
|
||||||
extern void md5_process_block __P ((const void *buffer, size_t len,
|
|
||||||
struct md5_ctx *ctx));
|
|
||||||
|
|
||||||
/* Starting with the result of former calls of this function (or the
|
/* Starting with the result of former calls of this function (or the
|
||||||
initialization function update the context for the next LEN bytes
|
initialization function update the context for the next LEN bytes
|
||||||
starting at BUFFER.
|
starting at BUFFER.
|
||||||
It is NOT required that LEN is a multiple of 64. */
|
|
||||||
|
It is necessary that LEN is a multiple of 64!!!
|
||||||
|
|
||||||
|
IMPORTANT: On some systems it is required that buffer be 32-bit
|
||||||
|
aligned. */
|
||||||
|
extern void md5_process_block __P ((const void *buffer, size_t len,
|
||||||
|
struct md5_ctx *ctx));
|
||||||
|
|
||||||
|
/* Starting with the result of former calls of this function (or the
|
||||||
|
initialization function) update the context for the next LEN bytes
|
||||||
|
starting at BUFFER.
|
||||||
|
|
||||||
|
It is NOT required that LEN is a multiple of 64.
|
||||||
|
|
||||||
|
IMPORTANT: On some systems it is required that buffer be 32-bit
|
||||||
|
aligned. */
|
||||||
extern void md5_process_bytes __P ((const void *buffer, size_t len,
|
extern void md5_process_bytes __P ((const void *buffer, size_t len,
|
||||||
struct md5_ctx *ctx));
|
struct md5_ctx *ctx));
|
||||||
|
|
||||||
@ -127,20 +136,27 @@ extern void *md5_finish_ctx __P ((struct md5_ctx *ctx, void *resbuf));
|
|||||||
always in little endian byte order, so that a byte-wise output yields
|
always in little endian byte order, so that a byte-wise output yields
|
||||||
to the wanted ASCII representation of the message digest.
|
to the wanted ASCII representation of the message digest.
|
||||||
|
|
||||||
IMPORTANT: On some systems it is required that RESBUF is correctly
|
IMPORTANT: On some systems it is required that RESBUF be correctly
|
||||||
aligned for a 32 bits value. */
|
aligned for a 32 bits value. */
|
||||||
extern void *md5_read_ctx __P ((const struct md5_ctx *ctx, void *resbuf));
|
extern void *md5_read_ctx __P ((const struct md5_ctx *ctx, void *resbuf));
|
||||||
|
|
||||||
|
|
||||||
/* Compute MD5 message digest for bytes read from STREAM. The
|
/* Compute MD5 message digest for bytes read from STREAM. The
|
||||||
resulting message digest number will be written into the 16 bytes
|
resulting message digest number will be written into the 16 bytes
|
||||||
beginning at RESBLOCK. */
|
beginning at RESBLOCK.
|
||||||
|
|
||||||
|
IMPORTANT: On some systems it is required that resblock be 32-bit
|
||||||
|
aligned. */
|
||||||
extern int md5_stream __P ((FILE *stream, void *resblock));
|
extern int md5_stream __P ((FILE *stream, void *resblock));
|
||||||
|
|
||||||
|
|
||||||
/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
|
/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
|
||||||
result is always in little endian byte order, so that a byte-wise
|
result is always in little endian byte order, so that a byte-wise
|
||||||
output yields to the wanted ASCII representation of the message
|
output yields to the wanted ASCII representation of the message
|
||||||
digest. */
|
digest.
|
||||||
|
|
||||||
|
IMPORTANT: On some systems it is required that buffer and resblock
|
||||||
|
be correctly 32-bit aligned. */
|
||||||
extern void *md5_buffer __P ((const char *buffer, size_t len, void *resblock));
|
extern void *md5_buffer __P ((const char *buffer, size_t len, void *resblock));
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user