Return-Path: Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 1335 invoked by uid 500); 4 Jun 2001 17:00:13 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 1030 invoked from network); 4 Jun 2001 17:00:08 -0000 From: "Sander Striker" To: Subject: [PATCH] apr-util md4 Date: Mon, 4 Jun 2001 19:08:40 +0200 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0020_01C0ED29.C3FFB0D0" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N This is a multi-part message in MIME format. ------=_NextPart_000_0020_01C0ED29.C3FFB0D0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hi, I've done a little bit of updating of the md4 code. It adds some trivial error checking. Maybe someone wants to complete this by adding the less trivial error checks? Second it adds a direct md4 computation function: apr_status_t apr_md4(unsigned char digest[APR_MD4_DIGESTSIZE], const unsigned char *input, apr_size_t inputLen); This will return the md4 digest of the given input block. Sander ------=_NextPart_000_0020_01C0ED29.C3FFB0D0 Content-Type: application/octet-stream; name="apr-util-md4.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="apr-util-md4.patch" diff -ru apr-util/crypto/apr_md4.c apr-util-md4/crypto/apr_md4.c=0A= --- apr-util/crypto/apr_md4.c Sat Jun 2 00:34:06 2001=0A= +++ apr-util-md4/crypto/apr_md4.c Mon Jun 4 18:53:29 2001=0A= @@ -150,6 +150,9 @@=0A= */=0A= APU_DECLARE(apr_status_t) apr_md4_init(apr_md4_ctx_t *context)=0A= {=0A= + if (!context)=0A= + return APR_EINVAL;=0A= + =0A= context->count[0] =3D context->count[1] =3D 0;=0A= =0A= /* Load magic initialization constants. */=0A= @@ -176,6 +179,9 @@=0A= apr_status_t rv;=0A= int is_sb;=0A= =0A= + if (!context)=0A= + return APR_EINVAL;=0A= + =0A= /* TODO: remove the single-byte-only restriction from this code=0A= */=0A= rv =3D apr_xlate_get_sb(xlate, &is_sb);=0A= @@ -191,8 +197,8 @@=0A= #endif /* APR_HAS_XLATE */=0A= =0A= /* MD4 block update operation. Continues an MD4 message-digest=0A= - operation, processing another message block, and updating the=0A= - context.=0A= + * operation, processing another message block, and updating the=0A= + * context.=0A= */=0A= APU_DECLARE(apr_status_t) apr_md4_update(apr_md4_ctx_t *context,=0A= const unsigned char *input,=0A= @@ -203,6 +209,9 @@=0A= apr_size_t inbytes_left, outbytes_left;=0A= #endif=0A= =0A= + if (!context)=0A= + return APR_EINVAL;=0A= + =0A= /* Compute number of bytes mod 64 */=0A= idx =3D (unsigned int)((context->count[0] >> 3) & 0x3F);=0A= =0A= @@ -274,7 +283,7 @@=0A= }=0A= =0A= /* MD4 finalization. Ends an MD4 message-digest operation, writing the=0A= - the message digest and zeroizing the context.=0A= + * the message digest and zeroizing the context.=0A= */=0A= APU_DECLARE(apr_status_t) apr_md4_final(=0A= unsigned char = digest[APR_MD4_DIGESTSIZE],=0A= @@ -283,6 +292,9 @@=0A= unsigned char bits[8];=0A= unsigned int idx, padLen;=0A= =0A= + if (!context)=0A= + return APR_EINVAL;=0A= + =0A= /* Save number of bits */=0A= Encode(bits, context->count, 8);=0A= =0A= @@ -306,6 +318,23 @@=0A= memset(context, 0, sizeof(*context));=0A= =0A= return APR_SUCCESS;=0A= +}=0A= +=0A= +/* MD4 computation in one step (init, update, final)=0A= + */=0A= +APU_DECLARE(apr_status_t) apr_md4(unsigned char = digest[APR_MD4_DIGESTSIZE],=0A= + const unsigned char *input,=0A= + apr_size_t inputLen)=0A= +{=0A= + apr_md4_ctx_t ctx;=0A= + apr_status_t rv;=0A= +=0A= + apr_md4_init(&ctx);=0A= +=0A= + if ((rv =3D apr_md4_update(&ctx, input, inputLen)) !=3D APR_SUCCESS)=0A= + return rv;=0A= +=0A= + return apr_md4_final(digest, &ctx);=0A= }=0A= =0A= /* MD4 basic transformation. Transforms state based on block. */=0A= diff -ru apr-util/include/apr_md4.h apr-util-md4/include/apr_md4.h=0A= --- apr-util/include/apr_md4.h Sat Jun 2 00:34:07 2001=0A= +++ apr-util-md4/include/apr_md4.h Mon Jun 4 18:45:13 2001=0A= @@ -135,7 +135,7 @@=0A= * @param context The MD4 content to update.=0A= * @param input next message block to update=0A= * @param inputLen The length of the next message block=0A= - * @deffunc apr_status_t apr_md4_update(apr_md4_ctx_t *context, = apr_size_t char *input, unsigned int inputLen)=0A= + * @deffunc apr_status_t apr_md4_update(apr_md4_ctx_t *context, const = unsigned char *input, apr_size_t inputLen)=0A= */=0A= APU_DECLARE(apr_status_t) apr_md4_update(apr_md4_ctx_t *context,=0A= const unsigned char *input,=0A= @@ -151,6 +151,17 @@=0A= APU_DECLARE(apr_status_t) apr_md4_final(=0A= unsigned char = digest[APR_MD4_DIGESTSIZE],=0A= apr_md4_ctx_t *context);=0A= +=0A= +/**=0A= + * MD4 digest computation=0A= + * @param digest The MD4 digest=0A= + * @param input message block to use=0A= + * @param inputLen The length of the message block=0A= + * @deffunc apr_status_t apr_md4(unsigned char = digest[APR_MD4_DIGESTSIZE], const unsigned char *input, apr_size_t = inputLen);=0A= + */=0A= +APU_DECLARE(apr_status_t) apr_md4(unsigned char = digest[APR_MD4_DIGESTSIZE],=0A= + const unsigned char *input,=0A= + apr_size_t inputLen);=0A= =0A= #ifdef __cplusplus=0A= }=0A= ------=_NextPart_000_0020_01C0ED29.C3FFB0D0--