#include <string.h>
-void md4_calc (unsigned char *, const unsigned char *, unsigned int);
+void fr_md4_calc (unsigned char *, const unsigned char *, unsigned int);
/* The below was retrieved from
* http://www.openbsd.org/cgi-bin/cvsweb/src/include/md4.h?rev=1.12
#define MD4_DIGEST_LENGTH 16
#define MD4_DIGEST_STRING_LENGTH (MD4_DIGEST_LENGTH * 2 + 1)
-typedef struct MD4Context {
+typedef struct FR_MD4Context {
uint32_t state[4]; /* state */
uint32_t count[2]; /* number of bits, mod 2^64 */
uint8_t buffer[MD4_BLOCK_LENGTH]; /* input buffer */
-} MD4_CTX;
+} FR_MD4_CTX;
/*#include <sys/cdefs.h>*/
/*__BEGIN_DECLS*/
-void MD4Init(MD4_CTX *);
-void MD4Update(MD4_CTX *, const uint8_t *, size_t)
+void fr_MD4Init(FR_MD4_CTX *);
+void fr_MD4Update(FR_MD4_CTX *, const uint8_t *, size_t)
/* __attribute__((__bounded__(__string__,2,3)))*/;
-void MD4Final(uint8_t [MD4_DIGEST_LENGTH], MD4_CTX *)
+void fr_MD4Final(uint8_t [MD4_DIGEST_LENGTH], FR_MD4_CTX *)
/* __attribute__((__bounded__(__minbytes__,1,MD4_DIGEST_LENGTH)))*/;
-void MD4Transform(uint32_t [4], const uint8_t [MD4_BLOCK_LENGTH])
+void fr_MD4Transform(uint32_t [4], const uint8_t [MD4_BLOCK_LENGTH])
/* __attribute__((__bounded__(__minbytes__,1,4)))
__attribute__((__bounded__(__minbytes__,2,MD4_BLOCK_LENGTH)))*/;
-/*char *MD4End(MD4_CTX *, char [MD4_DIGEST_STRING_LENGTH])
- __attribute__((__bounded__(__minbytes__,2,MD4_DIGEST_STRING_LENGTH)));
-char *MD4File(char *, char [MD4_DIGEST_STRING_LENGTH])
- __attribute__((__bounded__(__minbytes__,2,MD4_DIGEST_STRING_LENGTH)));
-char *MD4Data(const uint8_t *, size_t, char [MD4_DIGEST_STRING_LENGTH])
- __attribute__((__bounded__(__string__,1,2)))
- __attribute__((__bounded__(__minbytes__,3,MD4_DIGEST_STRING_LENGTH)));*/
/*__END_DECLS*/
#endif /* _LRAD_MD4_H */
*/
#include "../include/md4.h"
-void md4_calc(output, input, inlen)
+void fr_md4_calc(output, input, inlen)
unsigned char *output;
const unsigned char *input; /* input block */
unsigned int inlen; /* length of input block */
{
- MD4_CTX context;
+ FR_MD4_CTX context;
- MD4Init(&context);
- MD4Update(&context, input, inlen);
- MD4Final(output, &context);
+ fr_MD4Init(&context);
+ fr_MD4Update(&context, input, inlen);
+ fr_MD4Final(output, &context);
}
/* The below was retrieved from
* with every copy.
*
* To compute the message digest of a chunk of bytes, declare an
- * MD4Context structure, pass it to MD4Init, call MD4Update as
- * needed on buffers full of bytes, and then call MD4Final, which
+ * MD4Context structure, pass it to fr_MD4Init, call fr_MD4Update as
+ * needed on buffers full of bytes, and then call fr_MD4Final, which
* will fill a supplied 16-byte array with the digest.
*/
* Set bit count to 0 and buffer to mysterious initialization constants.
*/
void
-MD4Init(MD4_CTX *ctx)
+fr_MD4Init(FR_MD4_CTX *ctx)
{
ctx->count[0] = 0;
ctx->count[1] = 0;
* of bytes.
*/
void
-MD4Update(MD4_CTX *ctx, const unsigned char *buf, size_t len)
+fr_MD4Update(FR_MD4_CTX *ctx, const unsigned char *buf, size_t len)
{
uint32_t count;
}
memcpy(p, buf, count);
htole32_16((uint32_t *)ctx->buffer);
- MD4Transform(ctx->state, ctx->buffer);
+ fr_MD4Transform(ctx->state, ctx->buffer);
buf += count;
len -= count;
}
while (len >= MD4_BLOCK_LENGTH) {
memcpy(ctx->buffer, buf, MD4_BLOCK_LENGTH);
htole32_16((uint32_t *)ctx->buffer);
- MD4Transform(ctx->state, ctx->buffer);
+ fr_MD4Transform(ctx->state, ctx->buffer);
buf += MD4_BLOCK_LENGTH;
len -= MD4_BLOCK_LENGTH;
}
* 1 0* (64-bit count of bits processed, MSB-first)
*/
void
-MD4Final(unsigned char digest[MD4_DIGEST_LENGTH], MD4_CTX *ctx)
+fr_MD4Final(unsigned char digest[MD4_DIGEST_LENGTH], FR_MD4_CTX *ctx)
{
uint32_t count;
unsigned char *p;
/* Two lots of padding: Pad the first block to 64 bytes */
memset(p, 0, count);
htole32_16((uint32_t *)ctx->buffer);
- MD4Transform(ctx->state, ctx->buffer);
+ fr_MD4Transform(ctx->state, ctx->buffer);
/* Now fill the next block with 56 bytes */
memset(ctx->buffer, 0, 56);
((uint32_t *)ctx->buffer)[14] = ctx->count[0];
((uint32_t *)ctx->buffer)[15] = ctx->count[1];
- MD4Transform(ctx->state, ctx->buffer);
+ fr_MD4Transform(ctx->state, ctx->buffer);
htole32_4(ctx->state);
memcpy(digest, ctx->state, MD4_DIGEST_LENGTH);
memset(ctx, 0, sizeof(*ctx)); /* in case it's sensitive */
/*
* The core of the MD4 algorithm, this alters an existing MD4 hash to
- * reflect the addition of 16 longwords of new data. MD4Update blocks
+ * reflect the addition of 16 longwords of new data. fr_MD4Update blocks
* the data and converts bytes into longwords for this routine.
*/
void
-MD4Transform(uint32_t buf[4], const unsigned char inc[MD4_BLOCK_LENGTH])
+fr_MD4Transform(uint32_t buf[4], const unsigned char inc[MD4_BLOCK_LENGTH])
{
uint32_t a, b, c, d;
const uint32_t *in = (const uint32_t *)inc;
static void calc_md4_digest(char * buffer, const char * challenge, int challen, const char * password){
char buf[1024];
int i;
- MD4_CTX Context;
+ FR_MD4_CTX Context;
memset(buf, 0, 1024);
memset(buf, 0x36, 64);
for(i=0; i<64 && password[i]; i++) buf[i]^=password[i];
memcpy(buf+64, challenge, challen);
- MD4Init(&Context);
- MD4Update(&Context,buf,64+challen);
+ fr_MD4Init(&Context);
+ fr_MD4Update(&Context,buf,64+challen);
memset(buf, 0x5c, 64);
for(i=0; i<64 && password[i]; i++) buf[i]^=password[i];
- MD4Final(buf+64,&Context);
- MD4Init(&Context);
- MD4Update(&Context,buf,64+16);
- MD4Final(buffer,&Context);
+ fr_MD4Final(buf+64,&Context);
+ fr_MD4Init(&Context);
+ fr_MD4Update(&Context,buf,64+16);
+ fr_MD4Final(buffer,&Context);
}
static void calc_sha1_digest(char * buffer, const char * challenge, int challen, const char * password){
/*
* Get the NT Password hash.
*/
- md4_calc(ntpwdhash, unicode, password->length * 2);
+ fr_md4_calc(ntpwdhash, unicode, password->length * 2);
} else { /* MUST be NT-Password */
if (password->length == 32) {
eapleap_free(&reply);
return NULL;
}
- md4_calc(ntpwdhashhash, ntpwdhash, 16);
+ fr_md4_calc(ntpwdhashhash, ntpwdhash, 16);
/*
* Calculate our response, to authenticate ourselves
}
/* Encrypt Unicode password to a 16-byte MD4 hash */
- md4_calc(szHash, szUnicodePass, (nPasswordLen<<1) );
+ fr_md4_calc(szHash, szUnicodePass, (nPasswordLen<<1) );
}
* here minimizes work for later.
*/
if (password && (password->attribute == PW_NT_PASSWORD)) {
- md4_calc(nthashhash, password->vp_strvalue, 16);
+ fr_md4_calc(nthashhash, password->vp_strvalue, 16);
} else {
memset(nthashhash, 0, 16);
}
}
/* Encrypt Unicode password to a 16-byte MD4 hash */
- md4_calc(szHash, szUnicodePass, (nPasswordLen<<1) );
+ fr_md4_calc(szHash, szUnicodePass, (nPasswordLen<<1) );
}