summaryrefslogtreecommitdiff
path: root/cipher/md4.c
diff options
context:
space:
mode:
Diffstat (limited to 'cipher/md4.c')
-rw-r--r--cipher/md4.c123
1 files changed, 26 insertions, 97 deletions
diff --git a/cipher/md4.c b/cipher/md4.c
index 7bb31a8e..0135e345 100644
--- a/cipher/md4.c
+++ b/cipher/md4.c
@@ -54,7 +54,7 @@
#include <assert.h>
#include "g10lib.h"
#include "memory.h"
-#include "dynload.h"
+#include "cipher.h"
#include "bithelp.h"
@@ -68,15 +68,17 @@ typedef struct {
static void
-md4_init( MD4_CONTEXT *ctx )
+md4_init( void *context )
{
- ctx->A = 0x67452301;
- ctx->B = 0xefcdab89;
- ctx->C = 0x98badcfe;
- ctx->D = 0x10325476;
+ MD4_CONTEXT *ctx = (MD4_CONTEXT *) context;
- ctx->nblocks = 0;
- ctx->count = 0;
+ ctx->A = 0x67452301;
+ ctx->B = 0xefcdab89;
+ ctx->C = 0x98badcfe;
+ ctx->D = 0x10325476;
+
+ ctx->nblocks = 0;
+ ctx->count = 0;
}
#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
@@ -188,8 +190,9 @@ transform( MD4_CONTEXT *ctx, byte *data )
* in the message whose digest is being computed.
*/
static void
-md4_write( MD4_CONTEXT *hd, byte *inbuf, size_t inlen)
+md4_write( void *context, byte *inbuf, size_t inlen)
{
+ MD4_CONTEXT *hd = (MD4_CONTEXT *) context;
if( hd->count == 64 ) { /* flush the buffer */
transform( hd, hd->buf );
_gcry_burn_stack (80+6*sizeof(void*));
@@ -228,8 +231,9 @@ md4_write( MD4_CONTEXT *hd, byte *inbuf, size_t inlen)
*/
static void
-md4_final( MD4_CONTEXT *hd )
+md4_final( void *context )
{
+ MD4_CONTEXT *hd = (MD4_CONTEXT *) context;
u32 t, msb, lsb;
byte *p;
@@ -289,96 +293,21 @@ md4_final( MD4_CONTEXT *hd )
}
static byte *
-md4_read( MD4_CONTEXT *hd )
-{
- return hd->buf;
-}
-
-/****************
- * Return some information about the algorithm. We need algo here to
- * distinguish different flavors of the algorithm.
- * Returns: A pointer to string describing the algorithm or NULL if
- * the ALGO is invalid.
- */
-static const char *
-md4_get_info( int algo, size_t *contextsize,
- byte **r_asnoid, int *r_asnlen, int *r_mdlen,
- void (**r_init)( void *c ),
- void (**r_write)( void *c, byte *buf, size_t nbytes ),
- void (**r_final)( void *c ),
- byte *(**r_read)( void *c )
- )
-{
- static byte asn[18] = /* Object ID is 1.2.840.113549.2.4 */
- { 0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86,0x48,
- 0x86, 0xf7, 0x0d, 0x02, 0x04, 0x05, 0x00, 0x04, 0x10 };
-
- if( algo != 301 )
- return NULL;
-
- *contextsize = sizeof(MD4_CONTEXT);
- *r_asnoid = asn;
- *r_asnlen = DIM(asn);
- *r_mdlen = 16;
- *(void (**)(MD4_CONTEXT *))r_init = md4_init;
- *(void (**)(MD4_CONTEXT *, byte*, size_t))r_write = md4_write;
- *(void (**)(MD4_CONTEXT *))r_final = md4_final;
- *(byte *(**)(MD4_CONTEXT *))r_read = md4_read;
-
- return "MD4";
-}
-
-
-#ifndef IS_MODULE
-static
-#endif
-const char * const gnupgext_version = "MD4 ($Revision$)";
-
-static struct {
- int class;
- int version;
- int value;
- void (*func)(void);
-} func_table[] = {
- { 10, 1, 0, (void(*)(void))md4_get_info },
- { 11, 1, 301 },
-};
-
-
-#ifndef IS_MODULE
-static
-#endif
-void *
-gnupgext_enum_func( int what, int *sequence, int *class, int *vers )
+md4_read (void *context)
{
- void *ret;
- int i = *sequence;
-
- do {
- if( i >= DIM(func_table) || i < 0 )
- return NULL;
- *class = func_table[i].class;
- *vers = func_table[i].version;
- switch( *class ) {
- case 11: case 21: case 31: ret = &func_table[i].value; break;
- default: ret = func_table[i].func; break;
- }
- i++;
- } while( what && what != *class );
-
- *sequence = i;
- return ret;
+ MD4_CONTEXT *hd = (MD4_CONTEXT *) context;
+ return hd->buf;
}
+static byte asn[18] = /* Object ID is 1.2.840.113549.2.4 */
+ { 0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86,0x48,
+ 0x86, 0xf7, 0x0d, 0x02, 0x04, 0x05, 0x00, 0x04, 0x10 };
-
-
-#ifndef IS_MODULE
-void
-_gcry_md4_constructor(void)
-{
- _gcry_register_internal_cipher_extension( gnupgext_version, gnupgext_enum_func );
-}
-#endif
+GcryDigestSpec digest_spec_md4 =
+ {
+ "MD4", GCRY_MD_MD4, asn, DIM (asn), 16,
+ md4_init, md4_write, md4_final, md4_read,
+ sizeof (MD4_CONTEXT)
+ };
/* end of file */