diff options
Diffstat (limited to 'contrib/wpa_supplicant/md5.c')
-rw-r--r-- | contrib/wpa_supplicant/md5.c | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/contrib/wpa_supplicant/md5.c b/contrib/wpa_supplicant/md5.c index 82388e0..a7db7aa 100644 --- a/contrib/wpa_supplicant/md5.c +++ b/contrib/wpa_supplicant/md5.c @@ -1,6 +1,6 @@ /* * MD5 hash implementation and interface functions - * Copyright (c) 2003-2005, Jouni Malinen <jkmaline@cc.hut.fi> + * Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -12,9 +12,7 @@ * See README and COPYING for more details. */ -#include <stdlib.h> -#include <stdio.h> -#include <string.h> +#include "includes.h" #include "common.h" #include "md5.h" @@ -35,9 +33,8 @@ void hmac_md5_vector(const u8 *key, size_t key_len, size_t num_elem, { u8 k_pad[64]; /* padding - key XORd with ipad/opad */ u8 tk[16]; - int i; const u8 *_addr[6]; - size_t _len[6]; + size_t i, _len[6]; if (num_elem > 5) { /* @@ -64,8 +61,8 @@ void hmac_md5_vector(const u8 *key, size_t key_len, size_t num_elem, * and text is the data being protected */ /* start out by storing key in ipad */ - memset(k_pad, 0, sizeof(k_pad)); - memcpy(k_pad, key, key_len); + os_memset(k_pad, 0, sizeof(k_pad)); + os_memcpy(k_pad, key, key_len); /* XOR key with ipad values */ for (i = 0; i < 64; i++) @@ -80,8 +77,8 @@ void hmac_md5_vector(const u8 *key, size_t key_len, size_t num_elem, } md5_vector(1 + num_elem, _addr, _len, mac); - memset(k_pad, 0, sizeof(k_pad)); - memcpy(k_pad, key, key_len); + os_memset(k_pad, 0, sizeof(k_pad)); + os_memcpy(k_pad, key, key_len); /* XOR key with opad values */ for (i = 0; i < 64; i++) k_pad[i] ^= 0x5c; @@ -110,7 +107,7 @@ void hmac_md5(const u8 *key, size_t key_len, const u8 *data, size_t data_len, } -#ifndef EAP_TLS_FUNCS +#ifdef INTERNAL_MD5 struct MD5Context { u32 buf[4]; @@ -118,12 +115,15 @@ struct MD5Context { u8 in[64]; }; +#ifndef CONFIG_CRYPTO_INTERNAL static void MD5Init(struct MD5Context *context); static void MD5Update(struct MD5Context *context, unsigned char const *buf, - unsigned len); + unsigned len); static void MD5Final(unsigned char digest[16], struct MD5Context *context); +#endif /* CONFIG_CRYPTO_INTERNAL */ static void MD5Transform(u32 buf[4], u32 const in[16]); + typedef struct MD5Context MD5_CTX; @@ -137,7 +137,7 @@ typedef struct MD5Context MD5_CTX; void md5_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac) { MD5_CTX ctx; - int i; + size_t i; MD5Init(&ctx); for (i = 0; i < num_elem; i++) @@ -186,7 +186,7 @@ static void byteReverse(unsigned char *buf, unsigned longs) * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious * initialization constants. */ -static void MD5Init(struct MD5Context *ctx) +void MD5Init(struct MD5Context *ctx) { ctx->buf[0] = 0x67452301; ctx->buf[1] = 0xefcdab89; @@ -201,8 +201,7 @@ static void MD5Init(struct MD5Context *ctx) * Update context to reflect the concatenation of another buffer full * of bytes. */ -static void MD5Update(struct MD5Context *ctx, unsigned char const *buf, - unsigned len) +void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len) { u32 t; @@ -222,10 +221,10 @@ static void MD5Update(struct MD5Context *ctx, unsigned char const *buf, t = 64 - t; if (len < t) { - memcpy(p, buf, len); + os_memcpy(p, buf, len); return; } - memcpy(p, buf, t); + os_memcpy(p, buf, t); byteReverse(ctx->in, 16); MD5Transform(ctx->buf, (u32 *) ctx->in); buf += t; @@ -234,7 +233,7 @@ static void MD5Update(struct MD5Context *ctx, unsigned char const *buf, /* Process data in 64-byte chunks */ while (len >= 64) { - memcpy(ctx->in, buf, 64); + os_memcpy(ctx->in, buf, 64); byteReverse(ctx->in, 16); MD5Transform(ctx->buf, (u32 *) ctx->in); buf += 64; @@ -243,14 +242,14 @@ static void MD5Update(struct MD5Context *ctx, unsigned char const *buf, /* Handle any remaining bytes of data. */ - memcpy(ctx->in, buf, len); + os_memcpy(ctx->in, buf, len); } /* * Final wrapup - pad to 64-byte boundary with the bit pattern * 1 0* (64-bit count of bits processed, MSB-first) */ -static void MD5Final(unsigned char digest[16], struct MD5Context *ctx) +void MD5Final(unsigned char digest[16], struct MD5Context *ctx) { unsigned count; unsigned char *p; @@ -269,15 +268,15 @@ static void MD5Final(unsigned char digest[16], struct MD5Context *ctx) /* Pad out to 56 mod 64 */ if (count < 8) { /* Two lots of padding: Pad the first block to 64 bytes */ - memset(p, 0, count); + os_memset(p, 0, count); byteReverse(ctx->in, 16); MD5Transform(ctx->buf, (u32 *) ctx->in); /* Now fill the next block with 56 bytes */ - memset(ctx->in, 0, 56); + os_memset(ctx->in, 0, 56); } else { /* Pad block to 56 bytes */ - memset(p, 0, count - 8); + os_memset(p, 0, count - 8); } byteReverse(ctx->in, 14); @@ -287,8 +286,8 @@ static void MD5Final(unsigned char digest[16], struct MD5Context *ctx) MD5Transform(ctx->buf, (u32 *) ctx->in); byteReverse((unsigned char *) ctx->buf, 4); - memcpy(digest, ctx->buf, 16); - memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */ + os_memcpy(digest, ctx->buf, 16); + os_memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */ } /* The four core functions - F1 is optimized somewhat */ @@ -392,4 +391,4 @@ static void MD5Transform(u32 buf[4], u32 const in[16]) } /* ===== end - public domain MD5 implementation ===== */ -#endif /* !EAP_TLS_FUNCS */ +#endif /* INTERNAL_MD5 */ |