Simplified random byte stream generation code to use SSL RAND_bytes() and also eliminated two more compiler warnings.

This commit is contained in:
Bryan Everly 2015-05-05 12:33:44 -04:00
parent 6485e94395
commit 9865854f3c
4 changed files with 10 additions and 33 deletions

View File

@ -93,7 +93,11 @@ static gboolean tsmf_gstreamer_seek_data(GstAppSrc *src, guint64 offset, gpointe
return TRUE;
}
#ifdef __OpenBSD__
static inline GstClockTime tsmf_gstreamer_timestamp_ms_to_gst(UINT64 ms_timestamp)
#else
static inline const GstClockTime tsmf_gstreamer_timestamp_ms_to_gst(UINT64 ms_timestamp)
#endif
{
/*
* Convert Microsoft 100ns timestamps to Gstreamer 1ns units.

View File

@ -175,7 +175,7 @@ BOOL autodetect_send_bandwidth_measure_payload(rdpContext* context, UINT16 paylo
return FALSE;
}
BCryptGenRandom(NULL, buffer, payloadLength, 0L);
RAND_bytes(buffer, payloadLength);
Stream_Write(s, buffer, payloadLength);
bResult = rdp_send_message_channel_pdu(context->rdp, s, SEC_AUTODETECT_REQ);
@ -227,7 +227,7 @@ static BOOL autodetect_send_bandwidth_measure_stop(rdpContext* context, UINT16 p
return FALSE;
}
BCryptGenRandom(NULL, buffer, payloadLength, 0L);
RAND_bytes(buffer, payloadLength);
Stream_Write(s, buffer, payloadLength);
}
}

View File

@ -68,36 +68,6 @@ NTSTATUS BCryptFinishHash(BCRYPT_HASH_HANDLE hHash, PUCHAR pbOutput, ULONG cbOut
NTSTATUS BCryptGenRandom(BCRYPT_ALG_HANDLE hAlgorithm, PUCHAR pbBuffer, ULONG cbBuffer, ULONG dwFlags)
{
/* Since rand() and arc4random() generate 32-bit values, we will take one byte */
/* from each value returned to fill the buffer 8-bits at a time. We cannot */
/* guarantee that we will get long-aligned buffer sizes passed into us. */
ULONG i=0;
ULONG random_long = 0L;
UCHAR random_byte = 0x00;
/* Test for zero length buffer. This is an error condition as we cannot null- */
/* terminate the buffer in that case. */
if (cbBuffer == 0)
{
return -1;
}
/* Loop through the buffer for the number of bytes specified, filling it up. */
for (i=0 ; i< cbBuffer ; i++)
{
#ifdef __OpenBSD__
random_long = arc4random();
#else
random_long = rand();
#endif
/* Grab just one byte from the 32-bit value. */
random_byte = ((UCHAR *)(&random_long))[0];
/* Copy it to the buffer, advancing the buffer. */
*pbBuffer = random_byte;
pbBuffer++;
}
return 0;
}

View File

@ -584,7 +584,10 @@ DWORD GetCurrentThreadId(VOID)
{
pthread_t tid;
tid = pthread_self();
return (DWORD) tid;
/* Since pthread_t can be 64-bits on some systems, take just the lower */
/* 32-bits of it for the thread ID returned by this function. */
return (DWORD) (tid && 0xffffffff);
}
DWORD ResumeThread(HANDLE hThread)