White spaces.
git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@220 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
		| @@ -50,22 +50,11 @@ | |||||||
| #define S43 15 | #define S43 15 | ||||||
| #define S44 21 | #define S44 21 | ||||||
|  |  | ||||||
| static void MD5Transform PROTO_LIST( ( UINT4[4], | static void MD5Transform PROTO_LIST((UINT4[4], unsigned char[64])); | ||||||
|                                        unsigned char[64] ) ); | static void Encode PROTO_LIST((unsigned char *, UINT4 *, unsigned int)); | ||||||
| static void Encode PROTO_LIST( ( unsigned char *, | static void Decode PROTO_LIST((UINT4 *, unsigned char *, unsigned int)); | ||||||
|                                  UINT4 *, | static void MD5_memcpy PROTO_LIST((POINTER, POINTER, unsigned int)); | ||||||
|                                  unsigned int ) ); | static void MD5_memset PROTO_LIST((POINTER, int, unsigned int)); | ||||||
|  |  | ||||||
| static void Decode PROTO_LIST( ( UINT4 *, |  | ||||||
|                                  unsigned char *, |  | ||||||
|                                  unsigned int ) ); |  | ||||||
|  |  | ||||||
| static void MD5_memcpy PROTO_LIST( ( POINTER, |  | ||||||
|                                      POINTER, |  | ||||||
|                                      unsigned int ) ); |  | ||||||
| static void MD5_memset PROTO_LIST( ( POINTER, |  | ||||||
|                                      int, |  | ||||||
|                                      unsigned int ) ); |  | ||||||
|  |  | ||||||
| static unsigned char PADDING[64] = { | 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, |     0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||||
| @@ -118,14 +107,10 @@ static unsigned char PADDING[64] = { | |||||||
|    MD5 initialization. Begins an MD5 operation, writing a new context.  |    MD5 initialization. Begins an MD5 operation, writing a new context.  | ||||||
|  */ |  */ | ||||||
| void | void | ||||||
| MD5Init( context ) | MD5Init(MD5_CTX * context) | ||||||
|      MD5_CTX *context;          /* context */ |  | ||||||
| { | { | ||||||
|     context->count[0] = context->count[1] = 0; |     context->count[0] = context->count[1] = 0; | ||||||
|  |     /* Load magic initialization constants. */ | ||||||
|     /* |  | ||||||
|        Load magic initialization constants. |  | ||||||
|      */ |  | ||||||
|     context->state[0] = 0x67452301; |     context->state[0] = 0x67452301; | ||||||
|     context->state[1] = 0xefcdab89; |     context->state[1] = 0xefcdab89; | ||||||
|     context->state[2] = 0x98badcfe; |     context->state[2] = 0x98badcfe; | ||||||
| @@ -139,114 +124,72 @@ MD5Init( context ) | |||||||
|  */ |  */ | ||||||
|  |  | ||||||
| void | void | ||||||
| MD5Update( context, | MD5Update(MD5_CTX *context, unsigned char *input, unsigned int inputLen) | ||||||
|            input, |  | ||||||
|            inputLen ) |  | ||||||
|      MD5_CTX *context;          /* context */ |  | ||||||
|      unsigned char *input;      /* input block */ |  | ||||||
|      unsigned int inputLen;     /* length of input block */ |  | ||||||
| { | { | ||||||
|     unsigned int i, | 	unsigned int i; | ||||||
|       index, | 	unsigned int index; | ||||||
|       partLen; | 	unsigned int partLen; | ||||||
|  |  | ||||||
|     /* | 	/* Compute number of bytes mod 64 */ | ||||||
|        Compute number of bytes mod 64  | 	index = (unsigned int)((context->count[0] >> 3) & 0x3F); | ||||||
|      */ |  | ||||||
|     index = ( unsigned int )( ( context->count[0] >> 3 ) & 0x3F ); |  | ||||||
|  |  | ||||||
|     /* | 	/* Update number of bits */ | ||||||
|        Update number of bits  | 	if ((context->count[0] += ((UINT4)inputLen << 3)) < ((UINT4)inputLen << 3)) { | ||||||
|      */ | 		context->count[1]++; | ||||||
|     if( ( context->count[0] += | 	} | ||||||
|           ( ( UINT4 ) inputLen << 3 ) ) < ( ( UINT4 ) inputLen << 3 ) ) | 	context->count[1] += ((UINT4)inputLen >> 29); | ||||||
|         context->count[1]++; | 	partLen = 64 - index; | ||||||
|  |  | ||||||
|     context->count[1] += ( ( UINT4 ) inputLen >> 29 ); | 	/* Transform as many times as possible. */ | ||||||
|  | 	if (inputLen >= partLen) { | ||||||
|     partLen = 64 - index; | 		MD5_memcpy((POINTER)&context->buffer[index], (POINTER)input, partLen); | ||||||
|  | 		MD5Transform(context->state, context->buffer); | ||||||
|     /* | 		for (i = partLen; i + 63 < inputLen; i += 64) { | ||||||
|        Transform as many times as possible. | 			MD5Transform(context->state, &input[i]); | ||||||
|      */ | 		} | ||||||
|     if( inputLen >= partLen ) { | 		index = 0; | ||||||
|  | 	} else { | ||||||
|         MD5_memcpy | 		i = 0; | ||||||
|             ( ( POINTER ) & context->buffer[index], ( POINTER ) input, | 	} | ||||||
|               partLen ); |  | ||||||
|         MD5Transform( context->state, context->buffer ); |  | ||||||
|  |  | ||||||
|         for( i = partLen; i + 63 < inputLen; i += 64 ) |  | ||||||
|             MD5Transform( context->state, &input[i] ); |  | ||||||
|  |  | ||||||
|         index = 0; |  | ||||||
|     } else |  | ||||||
|         i = 0; |  | ||||||
|  |  | ||||||
|     /* |  | ||||||
|        Buffer remaining input  |  | ||||||
|      */ |  | ||||||
|     MD5_memcpy |  | ||||||
|         ( ( POINTER ) & context->buffer[index], ( POINTER ) & input[i], |  | ||||||
|           inputLen - i ); |  | ||||||
|  |  | ||||||
|  | 	/* Buffer remaining input */ | ||||||
|  | 	MD5_memcpy((POINTER)&context->buffer[index], (POINTER)&input[i], inputLen - i); | ||||||
| } | } | ||||||
|  |  | ||||||
| /* | /* | ||||||
|    MD5 finalization. Ends an MD5 message-digest operation, writing the |    MD5 finalization. Ends an MD5 message-digest operation, writing the | ||||||
|    the message digest and zeroizing the context. |    the message digest and zeroizing the context. | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
| void | void | ||||||
| MD5Final( digest, | MD5Final(unsigned char digest[16], MD5_CTX *context) | ||||||
|           context ) |  | ||||||
|      unsigned char digest[16];  /* message digest */ |  | ||||||
|      MD5_CTX *context;          /* context */ |  | ||||||
| { | { | ||||||
|  |  | ||||||
|     unsigned char bits[8]; |     unsigned char bits[8]; | ||||||
|     unsigned int index, |     unsigned int index; | ||||||
|       padLen; |     unsigned int padLen; | ||||||
|  |  | ||||||
|     /* |     /* Save number of bits */ | ||||||
|        Save number of bits  |     Encode(bits, context->count, 8); | ||||||
|      */ |  | ||||||
|     Encode( bits, context->count, 8 ); |  | ||||||
|  |  | ||||||
|     /* |     /* Pad out to 56 mod 64. */ | ||||||
|        Pad out to 56 mod 64. |     index = (unsigned int)((context->count[0] >> 3) & 0x3f); | ||||||
|      */ |     padLen = (index < 56) ? (56 - index) : (120 - index); | ||||||
|     index = ( unsigned int )( ( context->count[0] >> 3 ) & 0x3f ); |     MD5Update(context, PADDING, padLen); | ||||||
|  |  | ||||||
|     padLen = ( index < 56 ) ? ( 56 - index ) : ( 120 - index ); |     /* Append length (before padding) */ | ||||||
|  |     MD5Update(context, bits, 8); | ||||||
|  |  | ||||||
|     MD5Update( context, PADDING, padLen ); |     /* Store state in digest */ | ||||||
|  |     Encode(digest, context->state, 16); | ||||||
|     /* |  | ||||||
|        Append length (before padding)  |  | ||||||
|      */ |  | ||||||
|     MD5Update( context, bits, 8 ); |  | ||||||
|  |  | ||||||
|     /* |  | ||||||
|        Store state in digest  |  | ||||||
|      */ |  | ||||||
|     Encode( digest, context->state, 16 ); |  | ||||||
|  |  | ||||||
|     /* |  | ||||||
|        Zeroize sensitive information. |  | ||||||
|      */ |  | ||||||
|     MD5_memset( ( POINTER ) context, 0, sizeof( *context ) ); |  | ||||||
|  |  | ||||||
|  |     /* Zeroize sensitive information. */ | ||||||
|  |     MD5_memset((POINTER)context, 0, sizeof(*context)); | ||||||
| } | } | ||||||
|  |  | ||||||
| /* | /* | ||||||
|    MD5 basic transformation. Transforms state based on block.  |    MD5 basic transformation. Transforms state based on block.  | ||||||
|  */ |  */ | ||||||
| static void | static void | ||||||
| MD5Transform( state, | MD5Transform(UINT4 state[4], unsigned char block[64]) | ||||||
|               block ) |  | ||||||
|      UINT4 state[4]; |  | ||||||
|      unsigned char block[64]; |  | ||||||
| { | { | ||||||
|     UINT4 a = state[0], |     UINT4 a = state[0], | ||||||
|       b = state[1], |       b = state[1], | ||||||
| @@ -353,23 +296,16 @@ MD5Transform( state, | |||||||
|    a multiple of 4. |    a multiple of 4. | ||||||
|  */ |  */ | ||||||
| static void | static void | ||||||
| Encode( output, | Encode(unsigned char *output, UINT4 *input, unsigned int len) | ||||||
|         input, |  | ||||||
|         len ) |  | ||||||
|      unsigned char *output; |  | ||||||
|      UINT4 *input; |  | ||||||
|      unsigned int len; |  | ||||||
| { | { | ||||||
|     unsigned int i, | 	unsigned int i; | ||||||
|       j; | 	unsigned int j; | ||||||
|  | 	for (i = 0, j = 0; j < len; ++i, j += 4) { | ||||||
|     for( i = 0, j = 0; j < len; i++, j += 4 ) { | 		output[j+0] = (unsigned char)((input[i] >>  0) & 0xff); | ||||||
|         output[j] = ( unsigned char )( input[i] & 0xff ); | 		output[j+1] = (unsigned char)((input[i] >>  8) & 0xff); | ||||||
|         output[j + 1] = ( unsigned char )( ( input[i] >> 8 ) & 0xff ); | 		output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); | ||||||
|         output[j + 2] = ( unsigned char )( ( input[i] >> 16 ) & 0xff ); | 		output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); | ||||||
|         output[j + 3] = ( unsigned char )( ( input[i] >> 24 ) & 0xff ); | 	} | ||||||
|     } |  | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /* | /* | ||||||
| @@ -378,55 +314,40 @@ Encode( output, | |||||||
|  */ |  */ | ||||||
|  |  | ||||||
| static void | static void | ||||||
| Decode( output, | Decode(UINT4 *output, unsigned char *input, unsigned int len) | ||||||
|         input, |  | ||||||
|         len ) |  | ||||||
|      UINT4 *output; |  | ||||||
|      unsigned char *input; |  | ||||||
|      unsigned int len; |  | ||||||
| { | { | ||||||
|     unsigned int i, | 	unsigned int i; | ||||||
|       j; | 	unsigned int j; | ||||||
|  | 	for (i = 0, j = 0; j < len; ++i, j += 4) { | ||||||
|     for( i = 0, j = 0; j < len; i++, j += 4 ) | 		output[i] = | ||||||
|         output[i] = | 			(((UINT4)input[j+0]) <<  0) | | ||||||
|             ( ( UINT4 ) input[j] ) | ( ( ( UINT4 ) input[j + 1] ) << 8 ) | | 			(((UINT4)input[j+1]) <<  8) | | ||||||
|             ( ( ( UINT4 ) input[j + 2] ) << 16 ) | | 			(((UINT4)input[j+2]) << 16) | | ||||||
|             ( ( ( UINT4 ) input[j + 3] ) << 24 ); | 			(((UINT4)input[j+3]) << 24); | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| /* | /* | ||||||
|    Note: Replace "for loop" with standard memcpy if possible. |    Note: Replace for loop with standard memcpy if possible. | ||||||
|  */ |  */ | ||||||
| static void | static void | ||||||
| MD5_memcpy( output, | MD5_memcpy(POINTER  output, POINTER  input, unsigned int len) | ||||||
|             input, |  | ||||||
|             len ) |  | ||||||
|      POINTER output; |  | ||||||
|      POINTER input; |  | ||||||
|      unsigned int len; |  | ||||||
| { | { | ||||||
|     unsigned int i; | 	unsigned int i; | ||||||
|  | 	for (i = 0; i < len; ++i) { | ||||||
|     for( i = 0; i < len; i++ ) | 		output[i] = input[i]; | ||||||
|         output[i] = input[i]; | 	} | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /* | /* | ||||||
|    Note: Replace "for loop" with standard memset if possible. |    Note: Replace for loop with standard memset if possible. | ||||||
|  */ |  */ | ||||||
| static void | static void | ||||||
| MD5_memset( output, | MD5_memset(POINTER output, int value, unsigned int len) | ||||||
|             value, |  | ||||||
|             len ) |  | ||||||
|      POINTER output; |  | ||||||
|      int value; |  | ||||||
|      unsigned int len; |  | ||||||
| { | { | ||||||
|     unsigned int i; | 	unsigned int i; | ||||||
|  | 	for (i = 0; i < len; ++i) { | ||||||
|     for( i = 0; i < len; i++ ) | 		((char *)output)[i] = (char)value; | ||||||
|         ( ( char * )output )[i] = ( char )value; | 	} | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -33,17 +33,16 @@ | |||||||
|    This sample implementation generates a random node ID |    This sample implementation generates a random node ID | ||||||
|  */ |  */ | ||||||
| void | void | ||||||
| get_ieee_node_identifier( uuid_node_t * node ) | get_ieee_node_identifier(uuid_node_t *node) | ||||||
| { | { | ||||||
|     char seed[16]; |     char seed[16]; | ||||||
|     static int inited = 0; |     static int inited = 0; | ||||||
|     static uuid_node_t saved_node; |     static uuid_node_t saved_node; | ||||||
|  |  | ||||||
|     if( !inited ) { |     if (!inited) { | ||||||
|         get_random_info( seed ); |         get_random_info(seed); | ||||||
|         seed[0] |= 0x80; |         seed[0] |= 0x80; | ||||||
|         memcpy( &saved_node, seed, sizeof( uuid_node_t ) ); |         memcpy(&saved_node, seed, sizeof (uuid_node_t)); | ||||||
|  |  | ||||||
|         inited = 1; |         inited = 1; | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
| @@ -124,11 +123,12 @@ get_random_info( char seed[16] ) | |||||||
|     MD5Update( &c, &r, sizeof( randomness ) ); |     MD5Update( &c, &r, sizeof( randomness ) ); | ||||||
|     MD5Final( seed, &c ); |     MD5Final( seed, &c ); | ||||||
| }; | }; | ||||||
| #else |  | ||||||
|  | #else /* _WINDOWS_ */ | ||||||
|  |  | ||||||
| /*-----------------------------------------------------------------------------*/ | /*-----------------------------------------------------------------------------*/ | ||||||
| void | void | ||||||
| get_system_time( uuid_time_t * uuid_time ) | get_system_time(uuid_time_t *uuid_time) | ||||||
| { | { | ||||||
|     struct timeval tp; |     struct timeval tp; | ||||||
|  |  | ||||||
| @@ -145,7 +145,7 @@ get_system_time( uuid_time_t * uuid_time ) | |||||||
|  |  | ||||||
| /*-----------------------------------------------------------------------------*/ | /*-----------------------------------------------------------------------------*/ | ||||||
| void | void | ||||||
| get_random_info( char seed[16] ) | get_random_info(char seed[16]) | ||||||
| { | { | ||||||
|     MD5_CTX c; |     MD5_CTX c; | ||||||
|     typedef struct { |     typedef struct { | ||||||
| @@ -163,4 +163,5 @@ get_random_info( char seed[16] ) | |||||||
|     MD5Final( seed, &c ); |     MD5Final( seed, &c ); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| #endif | #endif /* _WINDOWS_ */ | ||||||
|  |  | ||||||
|   | |||||||
| @@ -53,7 +53,7 @@ static unsigned16 true_random( void ); | |||||||
|    uuid_create -- generator a UUID  |    uuid_create -- generator a UUID  | ||||||
|  */ |  */ | ||||||
| int | int | ||||||
| uuid_create( uuid_upnp * uid ) | uuid_create(uuid_upnp *uid) | ||||||
| { | { | ||||||
|     uuid_time_t timestamp; |     uuid_time_t timestamp; | ||||||
|     uuid_time_t last_time; |     uuid_time_t last_time; | ||||||
| @@ -70,17 +70,17 @@ uuid_create( uuid_upnp * uid ) | |||||||
|     /* |     /* | ||||||
|        get current time  |        get current time  | ||||||
|      */ |      */ | ||||||
|     get_current_time( ×tamp ); |     get_current_time(×tamp); | ||||||
|  |  | ||||||
|     /* |     /* | ||||||
|        get node ID  |        get node ID  | ||||||
|      */ |      */ | ||||||
|     get_ieee_node_identifier( &node ); |     get_ieee_node_identifier(&node); | ||||||
|  |  | ||||||
|     /* |     /* | ||||||
|        get saved state from NV storage  |        get saved state from NV storage  | ||||||
|      */ |      */ | ||||||
|     f = read_state( &clockseq, &last_time, &last_node ); |     f = read_state(&clockseq, &last_time, &last_node); | ||||||
|  |  | ||||||
|     /* |     /* | ||||||
|        if no NV state, or if clock went backwards, or node ID changed |        if no NV state, or if clock went backwards, or node ID changed | ||||||
| @@ -95,12 +95,12 @@ uuid_create( uuid_upnp * uid ) | |||||||
|     /* |     /* | ||||||
|        stuff fields into the UUID  |        stuff fields into the UUID  | ||||||
|      */ |      */ | ||||||
|     format_uuid_v1( uid, clockseq, timestamp, node ); |     format_uuid_v1(uid, clockseq, timestamp, node); | ||||||
|  |  | ||||||
|     /* |     /* | ||||||
|        save the state for next time  |        save the state for next time  | ||||||
|      */ |      */ | ||||||
|     write_state( clockseq, timestamp, node ); |     write_state(clockseq, timestamp, node); | ||||||
|  |  | ||||||
|     UUIDUnlock(); |     UUIDUnlock(); | ||||||
|     return 1; |     return 1; | ||||||
| @@ -108,15 +108,21 @@ uuid_create( uuid_upnp * uid ) | |||||||
|  |  | ||||||
| /*-----------------------------------------------------------------------------*/ | /*-----------------------------------------------------------------------------*/ | ||||||
| void | void | ||||||
| uuid_unpack( uuid_upnp * u, | uuid_unpack(uuid_upnp *u, char *out) | ||||||
|              char *out ) |  | ||||||
| { | { | ||||||
|     sprintf( out, | 	sprintf(out, | ||||||
|              "%8.8x-%4.4x-%4.4x-%2.2x%2.2x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x", | 		"%8.8x-%4.4x-%4.4x-%2.2x%2.2x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x", | ||||||
|              ( unsigned int )u->time_low, u->time_mid, | 		(unsigned int)u->time_low, | ||||||
|              u->time_hi_and_version, u->clock_seq_hi_and_reserved, | 		u->time_mid, | ||||||
|              u->clock_seq_low, u->node[0], u->node[1], u->node[2], | 		u->time_hi_and_version, | ||||||
|              u->node[3], u->node[4], u->node[5] ); | 		u->clock_seq_hi_and_reserved, | ||||||
|  | 		u->clock_seq_low, | ||||||
|  | 		u->node[0], | ||||||
|  | 		u->node[1], | ||||||
|  | 		u->node[2], | ||||||
|  | 		u->node[3], | ||||||
|  | 		u->node[4], | ||||||
|  | 		u->node[5]); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| /*-----------------------------------------------------------------------------*/ | /*-----------------------------------------------------------------------------*/ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Marcelo Roberto Jimenez
					Marcelo Roberto Jimenez