mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-06-14 03:01:09 +00:00
fixes
This commit is contained in:
parent
fef78d728f
commit
338186ee5e
@ -1149,7 +1149,7 @@ SWITCH_DECLARE(void) switch_uuid_format(char *buffer, const switch_uuid_t *uuid)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
SWITCH_DECLARE(void) switch_uuid_generate_v4(switch_uuid_t *uuid)
|
SWITCH_DECLARE(switch_status_t) switch_uuid_generate_v4(switch_uuid_t *uuid)
|
||||||
{
|
{
|
||||||
switch_mutex_lock(runtime.uuid_mutex);
|
switch_mutex_lock(runtime.uuid_mutex);
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
|
@ -4873,13 +4873,8 @@ SWITCH_DECLARE(int) switch_rand(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SWITCH_DECLARE(int) switch_getentropy(void *buffer, switch_size_t length)
|
static SWITCH_DECLARE(int) _switch_getentropy(void *buffer, switch_size_t length)
|
||||||
{
|
{
|
||||||
if (!buffer || length > 256) { // Enforce same limit as `getentropy`
|
|
||||||
errno = EIO; // Input/Output error
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
BCRYPT_ALG_HANDLE hAlgorithm = NULL;
|
BCRYPT_ALG_HANDLE hAlgorithm = NULL;
|
||||||
NTSTATUS status = BCryptOpenAlgorithmProvider(&hAlgorithm, BCRYPT_RNG_ALGORITHM, NULL, 0);
|
NTSTATUS status = BCryptOpenAlgorithmProvider(&hAlgorithm, BCRYPT_RNG_ALGORITHM, NULL, 0);
|
||||||
@ -4940,17 +4935,27 @@ SWITCH_DECLARE(int) switch_getentropy(void *buffer, switch_size_t length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SWITCH_DECLARE(int) switch_getentropy(void *buffer, switch_size_t length)
|
||||||
|
{
|
||||||
|
if (!buffer || length > 256) { // Enforce same limit as `getentropy`
|
||||||
|
errno = EIO; // Input/Output error
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return _switch_getentropy(buffer, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
SWITCH_DECLARE(switch_status_t) switch_uuid_generate_v7(switch_uuid_t *uuid) {
|
SWITCH_DECLARE(switch_status_t) switch_uuid_generate_v7(switch_uuid_t *uuid) {
|
||||||
/* random bytes */
|
/* random bytes */
|
||||||
unsigned char *value = uuid->data;
|
unsigned char *value = uuid->data;
|
||||||
|
|
||||||
|
/* current timestamp in ms */
|
||||||
|
switch_time_t timestamp = switch_time_now() / 1000;
|
||||||
|
|
||||||
if (switch_getentropy(value, 16) != 0) {
|
if (switch_getentropy(value, 16) != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* current timestamp in ms */
|
|
||||||
switch_time_t timestamp = switch_time_now() / 1000;
|
|
||||||
|
|
||||||
// timestamp
|
// timestamp
|
||||||
value[0] = (timestamp >> 40) & 0xFF;
|
value[0] = (timestamp >> 40) & 0xFF;
|
||||||
value[1] = (timestamp >> 32) & 0xFF;
|
value[1] = (timestamp >> 32) & 0xFF;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user