Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <stdint.h>
- #ifdef WIN32
- #include <windows.h>
- #include <wincrypt.h>
- #endif
- int libscrypt_salt_gen(uint8_t *rand, size_t len)
- {
- unsigned char buf[len];
- #ifdef WIN32
- static HCRYPTPROV provider;
- if (!CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
- {
- return -1;
- }
- if (!CryptGenRandom(provider, len, buf))
- {
- return -1;
- }
- #endif
- #ifdef UNIX
- int urandom = open("/dev/urandom", O_RDONLY);
- if (urandom < 0)
- {
- return -1;
- }
- ssize_t result = read(urandom, buf, len);
- if (result < 0)
- {
- return -1;
- }
- #endif
- memcpy(rand, buf, len);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement