/* Functions to compute MD2 message digest of files or memory blocks.
according to the definition of MD2 in RFC 1319 from April 1992.
- Copyright (C) 1995,1996,1997,1999,2000,2001,2002,2003,2005,2006
+ Copyright (C) 1995,1996,1997,1999,2000,2001,2002,2003,2005,2006,2008
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
#include "md2.h"
+#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
# include "unlocked-io.h"
#endif
-#define BLOCKSIZE 4096
+#define BLOCKSIZE 32768
#if BLOCKSIZE % 64 != 0
# error "invalid BLOCKSIZE"
#endif
}
/* Put result from CTX in first 16 bytes following RESBUF. The result
- must be in little endian byte order.
-
- IMPORTANT: On some systems it is required that RESBUF is correctly
- aligned for a 32 bits value. */
+ must be in little endian byte order. */
void *
md2_read_ctx (const struct md2_ctx *ctx, void *resbuf)
{
}
/* Process the remaining bytes in the internal buffer and the usual
- prolog according to the standard and write the result to RESBUF.
-
- IMPORTANT: On some systems it is required that RESBUF is correctly
- aligned for a 32 bits value. */
+ prolog according to the standard and write the result to RESBUF. */
void *
md2_finish_ctx (struct md2_ctx *ctx, void *resbuf)
{
md2_stream (FILE *stream, void *resblock)
{
struct md2_ctx ctx;
- char buffer[BLOCKSIZE + 72];
size_t sum;
+ char *buffer = malloc (BLOCKSIZE + 72);
+ if (!buffer)
+ return 1;
+
/* Initialize the computation context. */
md2_init_ctx (&ctx);
exit the loop after a partial read due to e.g., EAGAIN
or EWOULDBLOCK. */
if (ferror (stream))
- return 1;
+ {
+ free (buffer);
+ return 1;
+ }
goto process_partial_block;
}
/* Construct result in desired memory. */
md2_finish_ctx (&ctx, resblock);
+ free (buffer);
return 0;
}