[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: md2, md2-tests, gc-md2, gc-md2 and some gc fixes
From: |
Ralf Wildenhues |
Subject: |
Re: md2, md2-tests, gc-md2, gc-md2 and some gc fixes |
Date: |
Fri, 28 Oct 2005 14:03:48 +0200 |
User-agent: |
Mutt/1.5.11 |
Hi Simon,
* Simon Josefsson wrote on Fri, Oct 28, 2005 at 11:35:05AM CEST:
> I have installed the patch below, we needed MD2 in GnuTLS.
Code comments, from a glance:
> Index: lib/md2.h
> ===================================================================
> RCS file: lib/md2.h
> diff -N lib/md2.h
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ lib/md2.h 28 Oct 2005 09:32:29 -0000
> @@ -0,0 +1,82 @@
> +/* Declarations of functions and data types used for MD2 sum
> + library functions.
> + Copyright (C) 2000, 2001, 2003, 2005 Free Software Foundation, Inc.
> +
> + This program is free software; you can redistribute it and/or modify it
> + under the terms of the GNU General Public License as published by the
> + Free Software Foundation; either version 2, or (at your option) any
> + later version.
> +
> + This program is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + GNU General Public License for more details.
> +
> + You should have received a copy of the GNU General Public License
> + along with this program; if not, write to the Free Software Foundation,
> + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
> +
> +#ifndef MD2_H
> +# define MD2_H 1
> +
> +# include <stdio.h>
> +# include <stdint.h>
AFAICS you only need stddef.h and stdio.h here.
> +
> +# define MD2_DIGEST_SIZE 16
> +
> +/* Structure to save state of computation between the single steps. */
> +struct md2_ctx
> +{
> + unsigned char chksum[16], X[48], buf[16];
> + size_t curlen;
> +};
> +
> +
> +/* Initialize structure containing state of computation. */
> +extern void md2_init_ctx (struct md2_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. */
> +extern void md2_process_block (const void *buffer, size_t len,
> + struct md2_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. */
> +extern void md2_process_bytes (const void *buffer, size_t len,
> + struct md2_ctx *ctx);
> +
> +/* Process the remaining bytes in the buffer and put result from CTX
> + in first 16 bytes following RESBUF. The result is always in little
> + endian byte order, so that a byte-wise output yields to the wanted
> + ASCII representation of the message digest.
> +
> + IMPORTANT: On some systems it is required that RESBUF be correctly
> + aligned for a 32 bits value. */
> +extern void *md2_finish_ctx (struct md2_ctx *ctx, void *resbuf);
> +
> +
> +/* Put result from CTX in first 16 bytes following RESBUF. The result is
> + always in little endian byte order, so that a byte-wise output yields
> + to the wanted ASCII representation of the message digest.
> +
> + IMPORTANT: On some systems it is required that RESBUF is correctly
> + aligned for a 32 bits value. */
> +extern void *md2_read_ctx (const struct md2_ctx *ctx, void *resbuf);
> +
> +
> +/* Compute MD2 message digest for bytes read from STREAM. The
> + resulting message digest number will be written into the 16 bytes
> + beginning at RESBLOCK. */
> +extern int md2_stream (FILE *stream, void *resblock);
> +
> +/* Compute MD2 message digest for LEN bytes beginning at BUFFER. The
> + result is always in little endian byte order, so that a byte-wise
> + output yields to the wanted ASCII representation of the message
> + digest. */
> +extern void *md2_buffer (const char *buffer, size_t len, void *resblock);
> +
> +#endif
*snip*
> Index: lib/gc-gnulib.c
> ===================================================================
> RCS file: /cvsroot/gnulib/gnulib/lib/gc-gnulib.c,v
> retrieving revision 1.14
> diff -u -p -r1.14 gc-gnulib.c
> --- lib/gc-gnulib.c 21 Oct 2005 13:39:43 -0000 1.14
> +++ lib/gc-gnulib.c 28 Oct 2005 09:32:29 -0000
> @@ -38,6 +38,9 @@
> #include <errno.h>
>
> /* Hashes. */
> +#ifdef GC_USE_MD2
> +# include "md2.h"
> +#endif
> #ifdef GC_USE_MD4
> # include "md4.h"
> #endif
> @@ -537,11 +540,233 @@ gc_cipher_close (gc_cipher_handle handle
>
> /* Hashes. */
>
> +#define MAX_DIGEST_SIZE 20
> +
> +typedef struct _gc_hash_ctx {
> + Gc_hash alg;
> + Gc_hash_mode mode;
> + char hash[MAX_DIGEST_SIZE];
> +#ifdef GC_USE_MD2
> + struct md2_ctx md2Context;
> +#endif
> +#ifdef GC_USE_MD4
> + struct md4_ctx md4Context;
> +#endif
> +#ifdef GC_USE_MD5
> + struct md5_ctx md5Context;
> +#endif
> +#ifdef GC_USE_SHA1
> + struct sha1_ctx sha1Context;
> +#endif
> +} _gc_hash_ctx;
> +
> +Gc_rc
> +gc_hash_open (Gc_hash hash, Gc_hash_mode mode, gc_hash_handle * outhandle)
> +{
> + _gc_hash_ctx *ctx;
> + Gc_rc rc = GC_OK;
> +
> + ctx = calloc (sizeof (*ctx), 1);
Return value not tested against NULL.
> +
> + ctx->alg = hash;
> + ctx->mode = mode;
> +
> + switch (hash)
> + {
> +#ifdef GC_USE_MD2
> + case GC_MD2:
> + md2_init_ctx (&ctx->md2Context);
> + break;
> +#endif
> +
> +#ifdef GC_USE_MD4
> + case GC_MD4:
> + md4_init_ctx (&ctx->md4Context);
> + break;
> +#endif
> +
> +#ifdef GC_USE_MD5
> + case GC_MD5:
> + md5_init_ctx (&ctx->md5Context);
> + break;
> +#endif
> +
> +#ifdef GC_USE_SHA1
> + case GC_SHA1:
> + sha1_init_ctx (&ctx->sha1Context);
> + break;
> +#endif
> +
> + default:
> + rc = GC_INVALID_HASH;
> + break;
> + }
> +
> + switch (mode)
> + {
> + case 0:
> + break;
> +
> + default:
> + rc = GC_INVALID_HASH;
> + break;
> + }
> +
> + if (rc == GC_OK)
> + *outhandle = ctx;
> + else
> + free (ctx);
I wonder whether anyone else thinks it's useful to set
*outhandle = NULL
in the error case (same for the other incarnation of this function).
Surely it's not technically necessary.
> +
> + return rc;
> +}
*snip*
Cheers,
Ralf
- Prev by Date:
md2, md2-tests, gc-md2, gc-md2 and some gc fixes
- Next by Date:
Re: md2, md2-tests, gc-md2, gc-md2 and some gc fixes
- Previous by thread:
md2, md2-tests, gc-md2, gc-md2 and some gc fixes
- Next by thread:
Re: md2, md2-tests, gc-md2, gc-md2 and some gc fixes
- Index(es):