Browse Source

core: fix another bunch of 'no real prototype' warnings, add doxygen docs

* fix another bunch of gcc 4.5 'no real prototype' warnings by making the MD5
  functions typesafe (removing this PROTO_LIST stuff)
* refactoring of function definitions to use a proper style, like everybody else
* remove not needed defines for datatypes, delete the then empty header completely
* remove the unneeded include of md5global.h from a few modules
* fix callers of MD5 utility functions which already use a proper type
* adapt format of RSA copyright notices to the common style as well
* add doxygen documentations to all functions and defines
* similar changes have been done in kamailio, but have been not ported to this
  repository yet
Henning Westerholt 14 năm trước cách đây
mục cha
commit
03a4b6fc64
11 tập tin đã thay đổi với 128 bổ sung174 xóa
  1. 1 1
      lib/kcore/strcommon.c
  2. 33 50
      md5.c
  3. 34 8
      md5.h
  4. 0 38
      md5global.h
  5. 36 63
      md5utils.c
  6. 16 3
      md5utils.h
  7. 5 6
      modules/auth/nonce.c
  8. 0 1
      modules/auth/rfc2617.c
  9. 1 1
      modules/topoh/th_mask.c
  10. 2 2
      modules_k/cfgutils/cfgutils.c
  11. 0 1
      modules_s/uac/auth_alg.c

+ 1 - 1
lib/kcore/strcommon.c

@@ -117,7 +117,7 @@ void compute_md5(char *dst, char *src, int src_len)
 	unsigned char digest[16];
 	MD5Init (&context);
   	MD5Update (&context, src, src_len);
-	MD5Final (digest, &context);
+	U_MD5Final (digest, &context);
 	string2hex(digest, 16, dst);
 }
 

+ 33 - 50
md5.c

@@ -30,7 +30,6 @@
 
 
 #include <string.h>
-#include "md5global.h"
 #include "md5.h"
 
 
@@ -57,11 +56,9 @@
 #define S44 21
 /*@} */
 
-static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
-static void Encode PROTO_LIST
-  ((unsigned char *, UINT4 *, unsigned int));
-static void Decode PROTO_LIST
-  ((UINT4 *, unsigned char *, unsigned int));
+static void MD5Transform(unsigned int [4], unsigned char [64]);
+static void Encode(unsigned char *, unsigned int *, unsigned int);
+static void Decode(unsigned int *, unsigned char *, unsigned int);
 
 static unsigned char PADDING[64] = {
   0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -93,22 +90,22 @@ static unsigned char PADDING[64] = {
 
 /*@{ */
 #define FF(a, b, c, d, x, s, ac) { \
- (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) += F ((b), (c), (d)) + (x) + (unsigned int)(ac); \
  (a) = ROTATE_LEFT ((a), (s)); \
  (a) += (b); \
   }
 #define GG(a, b, c, d, x, s, ac) { \
- (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) += G ((b), (c), (d)) + (x) + (unsigned int)(ac); \
  (a) = ROTATE_LEFT ((a), (s)); \
  (a) += (b); \
   }
 #define HH(a, b, c, d, x, s, ac) { \
- (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) += H ((b), (c), (d)) + (x) + (unsigned int)(ac); \
  (a) = ROTATE_LEFT ((a), (s)); \
  (a) += (b); \
   }
 #define II(a, b, c, d, x, s, ac) { \
- (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) += I ((b), (c), (d)) + (x) + (unsigned int)(ac); \
  (a) = ROTATE_LEFT ((a), (s)); \
  (a) += (b); \
   }
@@ -120,8 +117,7 @@ static unsigned char PADDING[64] = {
  * MD5 context initialization. Begins an MD5 operation, writing a new context.
  * \param context initialized context
  */
-void MD5Init (context)
-MD5_CTX *context;
+void MD5Init (MD5_CTX *context)
 {
   context->count[0] = context->count[1] = 0;
   /* Load magic initialization constants.
@@ -142,10 +138,7 @@ MD5_CTX *context;
  * \param input input block
  * \param inputLen length of input block
  */
-void MD5Update (context, input, inputLen)
-MD5_CTX *context;
-unsigned char *input;
-unsigned int inputLen;
+void U_MD5Update (MD5_CTX *context, unsigned char *input, unsigned int inputLen)
 {
   unsigned int i, index, partLen;
 
@@ -153,11 +146,11 @@ unsigned int inputLen;
   index = (unsigned int)((context->count[0] >> 3) & 0x3F);
 
   /* Update number of bits */
-  if ((context->count[0] += ((UINT4)inputLen << 3))
+  if ((context->count[0] += ((unsigned int)inputLen << 3))
 
-   < ((UINT4)inputLen << 3))
+   < ((unsigned int)inputLen << 3))
  context->count[1]++;
-  context->count[1] += ((UINT4)inputLen >> 29);
+  context->count[1] += ((unsigned int)inputLen >> 29);
 
   partLen = 64 - index;
 
@@ -165,7 +158,7 @@ unsigned int inputLen;
 */
   if (inputLen >= partLen) {
  memcpy
-   ((POINTER)&context->buffer[index], (POINTER)input, partLen);
+   ((unsigned char *)&context->buffer[index], (unsigned char *)input, partLen);
  MD5Transform (context->state, context->buffer);
 
  for (i = partLen; i + 63 < inputLen; i += 64)
@@ -178,7 +171,7 @@ unsigned int inputLen;
 
   /* Buffer remaining input */
   memcpy
- ((POINTER)&context->buffer[index], (POINTER)&input[i],
+ ((unsigned char *)&context->buffer[index], (unsigned char *)&input[i],
   inputLen-i);
 }
 
@@ -190,9 +183,7 @@ unsigned int inputLen;
  * \param digest message digest
  * \param context context
  */
-void MD5Final (digest, context)
-unsigned char digest[16];
-MD5_CTX *context;
+void U_MD5Final (unsigned char digest[16], MD5_CTX *context)
 {
   unsigned char bits[8];
   unsigned int index, padLen;
@@ -204,17 +195,17 @@ MD5_CTX *context;
 */
   index = (unsigned int)((context->count[0] >> 3) & 0x3f);
   padLen = (index < 56) ? (56 - index) : (120 - index);
-  MD5Update (context, PADDING, padLen);
+  U_MD5Update (context, PADDING, padLen);
 
   /* Append length (before padding) */
-  MD5Update (context, bits, 8);
+  U_MD5Update (context, bits, 8);
 
   /* Store state in digest */
   Encode (digest, context->state, 16);
 
   /* Zeroize sensitive information.
 */
-  memset ((POINTER)context, 0, sizeof (*context));
+  memset ((unsigned char *)context, 0, sizeof (*context));
 }
 
 /**
@@ -224,11 +215,9 @@ MD5_CTX *context;
  * \param state transformed state
  * \param block block input for transformation
  */
-static void MD5Transform (state, block)
-UINT4 state[4];
-unsigned char block[64];
+static void MD5Transform (unsigned int state[4], unsigned char block[64])
 {
-  UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
+  unsigned int a = state[0], b = state[1], c = state[2], d = state[3], x[16];
 
   Decode (x, block, 64);
 
@@ -311,50 +300,44 @@ unsigned char block[64];
 
   /* Zeroize sensitive information.
 */
-  memset ((POINTER)x, 0, sizeof (x));
+  memset ((unsigned char *)x, 0, sizeof (x));
 }
 
 /**
- * \brief Encodes input (UINT4) into output (unsigned char)
+ * \brief Encodes input (unsigned int) into output (unsigned char)
  * 
- * Encodes input (UINT4) into output (unsigned char). Assumes len is
+ * Encodes input (unsigned int) into output (unsigned char). Assumes len is
  * a multiple of 4.
  * \param output output character
  * \param input integer input
  * \param len length of output
  */
-static void Encode (output, input, len)
-unsigned char *output;
-UINT4 *input;
-unsigned int len;
+static void Encode (unsigned char *output, unsigned int *input, unsigned int len)
 {
   unsigned int i, j;
 
   for (i = 0, j = 0; j < len; i++, j += 4) {
- output[j] = (unsigned char)(input[i] & 0xff);
- output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
- output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
- output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
+    output[j] = (unsigned char)(input[i] & 0xff);
+    output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
+    output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
+    output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
   }
 }
 
 /**
- * \brief Decodes input (unsigned char) into output (UINT4)
+ * \brief Decodes input (unsigned char) into output (unsigned int)
  * 
- * Decodes input (unsigned char) into output (UINT4). Assumes len is
+ * Decodes input (unsigned char) into output (unsigned int). Assumes len is
  * a multiple of 4.
  * \param output output integer
  * \param input input character
  * \param len length of input
  */
-static void Decode (output, input, len)
-UINT4 *output;
-unsigned char *input;
-unsigned int len;
+static void Decode (unsigned int *output, unsigned char *input, unsigned int len)
 {
   unsigned int i, j;
 
   for (i = 0, j = 0; j < len; i++, j += 4)
- output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
-   (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
+    output[i] = ((unsigned int)input[j]) | (((unsigned int)input[j+1]) << 8) |
+      (((unsigned int)input[j+2]) << 16) | (((unsigned int)input[j+3]) << 24);
 }

+ 34 - 8
md5.h

@@ -31,14 +31,12 @@
 #ifndef MD5_H
 #define MD5_H
 
-#include "md5global.h"
-
 /**
  * \brief MD5 context
  */
 typedef struct {
-  UINT4 state[4];                                   /* state (ABCD) */
-  UINT4 count[2];        /* number of bits, modulo 2^64 (lsb first) */
+  unsigned int state[4];                                   /* state (ABCD) */
+  unsigned int count[2];        /* number of bits, modulo 2^64 (lsb first) */
   unsigned char buffer[64];                         /* input buffer */
 } MD5_CTX;
 
@@ -48,7 +46,7 @@ typedef struct {
  * MD5 context initialization. Begins an MD5 operation, writing a new context.
  * \param context initialized context
  */
-void MD5Init PROTO_LIST ((MD5_CTX *));
+void MD5Init (MD5_CTX *context);
 
 /**
  * \brief MD5 block update operation
@@ -60,8 +58,7 @@ void MD5Init PROTO_LIST ((MD5_CTX *));
  * \param input input block
  * \param inputLen length of input block
  */
-void MD5Update PROTO_LIST
-  ((MD5_CTX *, unsigned char *, unsigned int));
+void U_MD5Update (MD5_CTX *context, unsigned char *input, unsigned int inputLen);
 
   /**
  * \brief MD5 finalization
@@ -71,6 +68,35 @@ void MD5Update PROTO_LIST
  * \param digest message digest
  * \param context context
  */
-void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *));
+void U_MD5Final (unsigned char digest[16], MD5_CTX *context);
+
+/*!
+ * \brief Small wrapper around MD5Update
+ *
+ * Small wrapper around MD5Update, because everybody uses this on 'str' types
+ * \param context MD5 context
+ * \param input input block
+ * \param inputLen length of input block
+ * \note please not use this in new code
+ * \todo review and fix all wrong usage
+ */
+static inline void MD5Update (MD5_CTX *context, char *input, unsigned int inputLen)
+{
+	return U_MD5Update(context, (unsigned char *)input, inputLen);
+}
+
+/*!
+ * \brief Small wrapper around MD5Final
+ *
+ * Small wrapper around MD5Final, because everybody uses this on 'str' types
+ * \param digest message digest
+ * \param context MD5 context
+ * \note please not use this in new code
+ * \todo review and fix all wrong usage
+ */
+static inline void MD5Final (char digest[16], MD5_CTX *context)
+{
+	U_MD5Final((unsigned char *)digest, context);
+}
 
 #endif /* MD5_H */

+ 0 - 38
md5global.h

@@ -1,38 +0,0 @@
-/* GLOBAL.H - RSAREF types and constants
- *
- */
-
-
-/* PROTOTYPES should be set to one if and only if the compiler supports
-  function argument prototyping.
-The following makes PROTOTYPES default to 0 if it has not already
-  been defined with C compiler flags.
- */
-#ifndef MD5GLOBAL_H
-#define MD5GLOBAL_H
-
-
-#ifndef PROTOTYPES
-#define PROTOTYPES 0
-#endif
-
-/* POINTER defines a generic pointer type */
-typedef unsigned char *POINTER;
-
-/* UINT2 defines a two byte word */
-typedef unsigned short int UINT2;
-
-/* UINT4 defines a four byte word */
-typedef unsigned int UINT4;
-
-/* PROTO_LIST is defined depending on how PROTOTYPES is defined above.
-If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it
-  returns an empty list.
- */
-#if PROTOTYPES
-#define PROTO_LIST(list) list
-#else
-#define PROTO_LIST(list) ()
-#endif
-
-#endif /* MD5GLOBAL_H */

+ 36 - 63
md5utils.c

@@ -1,94 +1,67 @@
-/* MDDRIVER.C - test driver for MD2, MD4 and MD5
- *
- */
-
-
-
-/* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All
-rights reserved.
-
-RSA Data Security, Inc. makes no representations concerning either
-the merchantability of this software or the suitability of this
-software for any particular purpose. It is provided "as is"
-without express or implied warranty of any kind.
-
-These notices must be retained in any copies of any part of this
-documentation and/or software.
- */
-
 /*
-
-jku: added support to deal with vectors
-
-*/
+ * Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
+ * rights reserved.
+ * 
+ * License to copy and use this software is granted provided that it
+ * is identified as the "RSA Data Security, Inc. MD5 Message-Digest
+ * Algorithm" in all material mentioning or referencing this software
+ * or this function.
+ * 
+ * License is also granted to make and use derivative works provided
+ * that such works are identified as "derived from the RSA Data
+ * Security, Inc. MD5 Message-Digest Algorithm" in all material
+ * mentioning or referencing the derived work.
+ * 
+ * RSA Data Security, Inc. makes no representations concerning either
+ * the merchantability of this software or the suitability of this
+ * software for any particular purpose. It is provided "as is"
+ * without express or implied warranty of any kind.
+ * 
+ * These notices must be retained in any copies of any part of this
+ * documentation and/or software.
+ */
 
 /*!
  * \file
- * \brief SIP-router core :: 
+ * \brief SIP-router core :: md5 hash support
  * \ingroup core
  * Module: \ref core
  */
 
-#define MD 5
-
 #include <stdio.h>
 #include <time.h>
 #include <string.h>
-#include "md5global.h"
 #include "md5.h"
 #include "md5utils.h"
 #include "dprint.h"
 #include "ut.h"
 
 
-/*static void MDString PROTO_LIST ((char *));*/
-
-#define MD_CTX MD5_CTX
-#define MDInit MD5Init
-#define MDUpdate MD5Update
-#define MDFinal MD5Final
-
-
-/* Digests a string array and store the result in dst; assumes
-  32 bytes in dst
- */
+/*!
+  * \brief Calculate a MD5 digests over a string array
+  * 
+  * Calculate a MD5 digests over a string array and stores the result in the
+  * destination char array. This function assumes 32 bytes in the destination
+  * buffer.
+  * \param dst destination
+  * \param src string input array
+  * \param size elements in the input array
+  */
 void MD5StringArray (char *dst, str src[], int size)
 {
-	MD_CTX context;
+	MD5_CTX context;
 	unsigned char digest[16];
  	int i;
 	int len;
 	char *s;
 
-/*
-#	ifdef EXTRA_DEBUG
-	int j;
-	int sum;
-#endif
-*/
-
-	MDInit (&context);
+	MD5Init (&context);
 	for (i=0; i<size; i++) {
 		trim_len( len, s, src[i] );
-/*
-#		ifdef EXTRA_DEBUG
-		fprintf(stderr, "EXTRA_DEBUG: %d. (%d) {", i+1, len);
-		sum=0;
-		for (j=0; j<len; j++) {
-			fprintf( stderr, "%c ", *(s+j));
-			sum+=*(s+j);
-		}
-		for (j=0; j<len; j++) {
-			fprintf( stderr, "%d ", *(s+j));
-			sum+=*(s+j);
-		}
-		fprintf(stderr, " [%d]\n", sum );	
-#		endif
-*/
 		if (len > 0)
-  			MDUpdate (&context, s, len);
+  			MD5Update (&context, s, len);
   }
-  MDFinal (digest, &context);
+  U_MD5Final (digest, &context);
 
   string2hex(digest, 16, dst );
   DBG("DEBUG: MD5 calculated: %.*s\n", MD5_LEN, dst );

+ 16 - 3
md5utils.h

@@ -1,7 +1,4 @@
 /* 
- * $Id$
- *
- *
  * Copyright (C) 2001-2003 FhG Fokus
  *
  * This file is part of ser, a free SIP server.
@@ -26,6 +23,12 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+/*!
+ * \file
+ * \brief SIP-router core :: md5 hash support
+ * \ingroup core
+ * Module: \ref core
+ */
 
 #ifndef _MD5UTILS_H
 #define _MD5UTILS_H
@@ -34,6 +37,16 @@
 
 #define MD5_LEN	32
 
+/*!
+  * \brief Calculate a MD5 digests over a string array
+  * 
+  * Calculate a MD5 digests over a string array and stores the result in the
+  * destination char array. This function assumes 32 bytes in the destination
+  * buffer.
+  * \param dst destination
+  * \param src string input array
+  * \param size elements in the input array
+  */
 void MD5StringArray (char *dst, str src[], int size);
 
 #endif /* _MD5UTILS_H */

+ 5 - 6
modules/auth/nonce.c

@@ -44,7 +44,6 @@
 #include <sys/types.h>
 #include <netinet/in.h>
 #include "../../compiler_opt.h"
-#include "../../md5global.h"
 #include "../../md5.h"
 #include "../../dprint.h"
 #include "../../ut.h"
@@ -118,15 +117,15 @@ inline static int calc_bin_nonce_md5(union bin_nonce* b_nonce, int cfg,
 
 	MD5Init(&ctx);
 	
-	MD5Update(&ctx, &b_nonce->raw[0], 4 + 4);
+	U_MD5Update(&ctx, &b_nonce->raw[0], 4 + 4);
 	if (cfg && msg){
 		/* auth extra checks => 2 md5s */
 		len = 4 + 4 + 16 + 16;
 #if defined USE_NC  || defined USE_OT_NONCE
 		if (b_nonce->n.nid_pf & (NF_VALID_NC_ID | NF_VALID_OT_ID)){
 			/* if extra auth checks enabled, nid & pf are after the 2nd md5 */
-			MD5Update(&ctx, (unsigned char*)&b_nonce->n.nid_i, 
-							nonce_nid_extra_size);
+			U_MD5Update(&ctx, (unsigned char*)&b_nonce->n.nid_i,
+                                                        nonce_nid_extra_size);
 			len+=nonce_nid_extra_size;
 		}
 #endif /* USE_NC || USE_OT_NONCE */
@@ -148,7 +147,7 @@ inline static int calc_bin_nonce_md5(union bin_nonce* b_nonce, int cfg,
 					  get_from(msg)->tag_value.len);
 		}
 		if (cfg & AUTH_CHECK_SRC_IP) {
-			MD5Update(&ctx, msg->rcv.src_ip.u.addr, msg->rcv.src_ip.len);
+			U_MD5Update(&ctx, msg->rcv.src_ip.u.addr, msg->rcv.src_ip.len);
 		}
 		MD5Update(&ctx, secret2->s, secret2->len);
 		MD5Final(&b_nonce->n.md5_2[0], &ctx);
@@ -159,7 +158,7 @@ inline static int calc_bin_nonce_md5(union bin_nonce* b_nonce, int cfg,
 		if (b_nonce->n_small.nid_pf & (NF_VALID_NC_ID | NF_VALID_OT_ID)){
 			/* if extra auth checks are not enabled, nid & pf are after the
 			 *  1st md5 */
-			MD5Update(&ctx, (unsigned char*)&b_nonce->n_small.nid_i,
+			U_MD5Update(&ctx, (unsigned char*)&b_nonce->n_small.nid_i,
 							nonce_nid_extra_size);
 			len+=nonce_nid_extra_size;
 		}

+ 0 - 1
modules/auth/rfc2617.c

@@ -33,7 +33,6 @@
 #include <string.h>
 
 #include "rfc2617.h"
-#include "../../md5global.h"
 #include "../../md5.h"
 #include "../../dprint.h"
 

+ 1 - 1
modules/topoh/th_mask.c

@@ -54,7 +54,7 @@ void th_shuffle(char *in, int size)
 	MD5Init(&ctx);
 	MD5Update(&ctx, _th_key.s, _th_key.len);
 	MD5Update(&ctx, _th_key.s, _th_key.len);
-	MD5Final(md5, &ctx);
+	U_MD5Final(md5, &ctx);
 
 	md5i = (unsigned int*)md5;
 

+ 2 - 2
modules_k/cfgutils/cfgutils.c

@@ -525,11 +525,11 @@ static int MD5File(char *dest, const char *file_name)
 			fclose(input);
 			return -1;
 		}
-		MD5Update(&context, buffer, counter);
+		U_MD5Update(&context, buffer, counter);
 		size -= counter;
 	}
 	fclose(input);
-	MD5Final(hash, &context);
+	U_MD5Final(hash, &context);
 
 	string2hex(hash, 16, dest);
 	LM_DBG("MD5 calculated: %.*s for file %s\n", MD5_LEN, dest, file_name);

+ 0 - 1
modules_s/uac/auth_alg.c

@@ -30,7 +30,6 @@
  */
 
 
-#include "../../md5global.h"
 #include "../../md5.h"
 
 #include "auth_alg.h"