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