mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-04 02:20:48 +00:00
get random value on mingw
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@37486 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
23abb52aa3
commit
1c5249ce95
1 changed files with 29 additions and 2 deletions
|
@ -27,7 +27,11 @@
|
||||||
#import "Foundation/NSCoder.h"
|
#import "Foundation/NSCoder.h"
|
||||||
#import "Foundation/NSUUID.h"
|
#import "Foundation/NSUUID.h"
|
||||||
|
|
||||||
|
#if defined(__MINGW32__)
|
||||||
|
#include <wincrypt.h>
|
||||||
|
#else
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
static int uuid_from_string(const char *string, unsigned char *uuid);
|
static int uuid_from_string(const char *string, unsigned char *uuid);
|
||||||
static void string_from_uuid(const unsigned char *uuid, char *string);
|
static void string_from_uuid(const unsigned char *uuid, char *string);
|
||||||
|
@ -256,8 +260,6 @@ static void string_from_uuid(const unsigned char *uuid, char *string)
|
||||||
|
|
||||||
static int random_uuid(unsigned char *uuid)
|
static int random_uuid(unsigned char *uuid)
|
||||||
{
|
{
|
||||||
int devUrandom;
|
|
||||||
ssize_t bytesRead;
|
|
||||||
unsigned char timeByte;
|
unsigned char timeByte;
|
||||||
unsigned char sequenceByte;
|
unsigned char sequenceByte;
|
||||||
|
|
||||||
|
@ -265,6 +267,29 @@ static int random_uuid(unsigned char *uuid)
|
||||||
* consistent with Apple. Other variants suffer from privacy
|
* consistent with Apple. Other variants suffer from privacy
|
||||||
* problems (and are more work...)
|
* problems (and are more work...)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if defined(__MINGW32__)
|
||||||
|
|
||||||
|
HCRYPTPROV hProvider = 0;
|
||||||
|
|
||||||
|
if (!CryptAcquireContextW(&hProvider, 0, 0,
|
||||||
|
PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT))
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!CryptGenRandom(hProvider, kUUIDByteCount, uuid))
|
||||||
|
{
|
||||||
|
CryptReleaseContext(hProvider, 0);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
CryptReleaseContext(hProvider, 0);
|
||||||
|
#else
|
||||||
|
|
||||||
|
int devUrandom;
|
||||||
|
ssize_t bytesRead;
|
||||||
|
|
||||||
devUrandom = open("/dev/urandom", O_RDONLY);
|
devUrandom = open("/dev/urandom", O_RDONLY);
|
||||||
if (devUrandom == -1)
|
if (devUrandom == -1)
|
||||||
{
|
{
|
||||||
|
@ -276,6 +301,8 @@ static int random_uuid(unsigned char *uuid)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* as required by the RFC, bits 48-51 should contain 0b0100 (4)
|
/* as required by the RFC, bits 48-51 should contain 0b0100 (4)
|
||||||
* and bits 64-65 should contain 0b01 (1)
|
* and bits 64-65 should contain 0b01 (1)
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue