mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-18 17:36:57 +00:00
commit
e8095071d9
@ -26,6 +26,7 @@ if(WITH_TWEETNACL)
|
|||||||
tweetnacl/src/tweetnacl.c
|
tweetnacl/src/tweetnacl.c
|
||||||
)
|
)
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
|
list(APPEND TWEETNACL_SOURCES tweetnacl/contrib/randombytes/winrandom.c)
|
||||||
else()
|
else()
|
||||||
list(APPEND TWEETNACL_SOURCES tweetnacl/contrib/randombytes/devurandom.c)
|
list(APPEND TWEETNACL_SOURCES tweetnacl/contrib/randombytes/devurandom.c)
|
||||||
endif()
|
endif()
|
||||||
|
@ -608,6 +608,7 @@ EXTRA_DIST = \
|
|||||||
MAINTAINERS \
|
MAINTAINERS \
|
||||||
src/libzmq.pc.cmake.in \
|
src/libzmq.pc.cmake.in \
|
||||||
src/libzmq.vers \
|
src/libzmq.vers \
|
||||||
|
tweetnacl \
|
||||||
tools/curve_keygen.cpp
|
tools/curve_keygen.cpp
|
||||||
|
|
||||||
MAINTAINERCLEANFILES = \
|
MAINTAINERCLEANFILES = \
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
/*
|
|
||||||
randombytes/devurandom.h version 20080713
|
|
||||||
D. J. Bernstein
|
|
||||||
Public domain.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef randombytes_devurandom_H
|
|
||||||
#define randombytes_devurandom_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern void randombytes(unsigned char *,unsigned long long);
|
|
||||||
extern int randombytes_close(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef randombytes_implementation
|
|
||||||
#define randombytes_implementation "devurandom"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,5 +1,21 @@
|
|||||||
|
/*
|
||||||
|
randombytes/randombytes.h version 20080713
|
||||||
|
D. J. Bernstein
|
||||||
|
Public domain.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef randombytes_H
|
#ifndef randombytes_H
|
||||||
#define randombytes_H
|
#define randombytes_H
|
||||||
#include "devurandom.h"
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern void randombytes(unsigned char *,unsigned long long);
|
||||||
|
extern int randombytes_close(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
43
tweetnacl/contrib/randombytes/winrandom.c
Normal file
43
tweetnacl/contrib/randombytes/winrandom.c
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#include <windows.h>
|
||||||
|
#include <WinCrypt.h>
|
||||||
|
|
||||||
|
#define NCP ((HCRYPTPROV) 0)
|
||||||
|
|
||||||
|
HCRYPTPROV hProvider = NCP;
|
||||||
|
|
||||||
|
void randombytes(unsigned char *x,unsigned long long xlen)
|
||||||
|
{
|
||||||
|
unsigned i;
|
||||||
|
BOOL ret;
|
||||||
|
|
||||||
|
if (hProvider == NCP) {
|
||||||
|
for(;;) {
|
||||||
|
ret = CryptAcquireContext(&hProvider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT);
|
||||||
|
if (ret != FALSE) break;
|
||||||
|
Sleep(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (xlen > 0) {
|
||||||
|
if (xlen < 1048576) i = (unsigned) xlen; else i = 1048576;
|
||||||
|
|
||||||
|
ret = CryptGenRandom(hProvider, i, x);
|
||||||
|
if (ret != FALSE) {
|
||||||
|
Sleep(1);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
x += i;
|
||||||
|
xlen -= i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int randombytes_close(void)
|
||||||
|
{
|
||||||
|
int rc = -1;
|
||||||
|
if((hProvider != NCP) && (CryptReleaseContext(hProvider, 0) != FALSE)) {
|
||||||
|
hProvider = NCP;
|
||||||
|
rc = 0;
|
||||||
|
}
|
||||||
|
return rc;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user