jerenkrantz 01/06/04 10:21:56
Modified: crypto apr_md4.c
include apr_md4.h
Log:
Update error handling and add apr_md4 function.
Submitted by: Sander Striker <[EMAIL PROTECTED]>
Reviewed by: Justin Erenkrantz
Revision Changes Path
1.2 +32 -3 apr-util/crypto/apr_md4.c
Index: apr_md4.c
===================================================================
RCS file: /home/cvs/apr-util/crypto/apr_md4.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- apr_md4.c 2001/06/01 22:34:06 1.1
+++ apr_md4.c 2001/06/04 17:21:51 1.2
@@ -150,6 +150,9 @@
*/
APU_DECLARE(apr_status_t) apr_md4_init(apr_md4_ctx_t *context)
{
+ if (!context)
+ return APR_EINVAL;
+
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants. */
@@ -176,6 +179,9 @@
apr_status_t rv;
int is_sb;
+ if (!context)
+ return APR_EINVAL;
+
/* TODO: remove the single-byte-only restriction from this code
*/
rv = apr_xlate_get_sb(xlate, &is_sb);
@@ -191,8 +197,8 @@
#endif /* APR_HAS_XLATE */
/* MD4 block update operation. Continues an MD4 message-digest
- operation, processing another message block, and updating the
- context.
+ * operation, processing another message block, and updating the
+ * context.
*/
APU_DECLARE(apr_status_t) apr_md4_update(apr_md4_ctx_t *context,
const unsigned char *input,
@@ -203,6 +209,9 @@
apr_size_t inbytes_left, outbytes_left;
#endif
+ if (!context)
+ return APR_EINVAL;
+
/* Compute number of bytes mod 64 */
idx = (unsigned int)((context->count[0] >> 3) & 0x3F);
@@ -274,7 +283,7 @@
}
/* MD4 finalization. Ends an MD4 message-digest operation, writing the
- the message digest and zeroizing the context.
+ * the message digest and zeroizing the context.
*/
APU_DECLARE(apr_status_t) apr_md4_final(
unsigned char digest[APR_MD4_DIGESTSIZE],
@@ -283,6 +292,9 @@
unsigned char bits[8];
unsigned int idx, padLen;
+ if (!context)
+ return APR_EINVAL;
+
/* Save number of bits */
Encode(bits, context->count, 8);
@@ -306,6 +318,23 @@
memset(context, 0, sizeof(*context));
return APR_SUCCESS;
+}
+
+/* MD4 computation in one step (init, update, final)
+ */
+APU_DECLARE(apr_status_t) apr_md4(unsigned char digest[APR_MD4_DIGESTSIZE],
+ const unsigned char *input,
+ apr_size_t inputLen)
+{
+ apr_md4_ctx_t ctx;
+ apr_status_t rv;
+
+ apr_md4_init(&ctx);
+
+ if ((rv = apr_md4_update(&ctx, input, inputLen)) != APR_SUCCESS)
+ return rv;
+
+ return apr_md4_final(digest, &ctx);
}
/* MD4 basic transformation. Transforms state based on block. */
1.2 +12 -1 apr-util/include/apr_md4.h
Index: apr_md4.h
===================================================================
RCS file: /home/cvs/apr-util/include/apr_md4.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- apr_md4.h 2001/06/01 22:34:07 1.1
+++ apr_md4.h 2001/06/04 17:21:54 1.2
@@ -135,7 +135,7 @@
* @param context The MD4 content to update.
* @param input next message block to update
* @param inputLen The length of the next message block
- * @deffunc apr_status_t apr_md4_update(apr_md4_ctx_t *context, apr_size_t
char *input, unsigned int inputLen)
+ * @deffunc apr_status_t apr_md4_update(apr_md4_ctx_t *context, const
unsigned char *input, apr_size_t inputLen)
*/
APU_DECLARE(apr_status_t) apr_md4_update(apr_md4_ctx_t *context,
const unsigned char *input,
@@ -151,6 +151,17 @@
APU_DECLARE(apr_status_t) apr_md4_final(
unsigned char digest[APR_MD4_DIGESTSIZE],
apr_md4_ctx_t *context);
+
+/**
+ * MD4 digest computation
+ * @param digest The MD4 digest
+ * @param input message block to use
+ * @param inputLen The length of the message block
+ * @deffunc apr_status_t apr_md4(unsigned char digest[APR_MD4_DIGESTSIZE],
const unsigned char *input, apr_size_t inputLen);
+ */
+APU_DECLARE(apr_status_t) apr_md4(unsigned char digest[APR_MD4_DIGESTSIZE],
+ const unsigned char *input,
+ apr_size_t inputLen);
#ifdef __cplusplus
}