本文整理汇总了C++中RAND_get_rand_method函数的典型用法代码示例。如果您正苦于以下问题:C++ RAND_get_rand_method函数的具体用法?C++ RAND_get_rand_method怎么用?C++ RAND_get_rand_method使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RAND_get_rand_method函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RAND_add
void RAND_add(const void *buf, int num, double randomness)
{
const RAND_METHOD *meth = RAND_get_rand_method();
if (meth->add != NULL)
meth->add(buf, num, randomness);
}
示例2: RAND_status
int RAND_status(void)
{
const RAND_METHOD *meth = RAND_get_rand_method();
if (meth && meth->status)
return meth->status();
return 0;
}
示例3: init_openssl_rand
/*
* OpenSSL random should re-feeded occasionally. From /dev/urandom
* preferably.
*/
static void
init_openssl_rand(void)
{
if (RAND_get_rand_method() == NULL)
RAND_set_rand_method(RAND_SSLeay());
openssl_random_init = 1;
}
示例4: RAND_bytes
int RAND_bytes(unsigned char *buf, int num)
{
const RAND_METHOD *meth = RAND_get_rand_method();
memset(buf, 0, num);
if (meth && meth->bytes)
return meth->bytes(buf,num);
return(-1);
}
示例5: RAND_cleanup
void RAND_cleanup(void)
{
const RAND_METHOD *meth = RAND_get_rand_method();
if (meth && meth->cleanup)
meth->cleanup();
RAND_set_rand_method(NULL);
}
示例6: RAND_seed
void RAND_seed(const void *buf, int num)
{
const RAND_METHOD *meth = RAND_get_rand_method();
if (meth->seed != NULL)
meth->seed(buf, num);
}
示例7: verify_rng
void verify_rng()
{
auto* rm = RAND_get_rand_method();
int random_value = 0;
int rc = RAND_bytes((uint8_t*) &random_value, sizeof(random_value));
assert(rc == 0 || rc == 1);
}
示例8: RAND_pseudo_bytes
int RAND_pseudo_bytes(unsigned char *buf, int num)
{
const RAND_METHOD *meth = RAND_get_rand_method();
if (meth && meth->pseudorand)
return meth->pseudorand(buf, num);
return (-1);
}
示例9: RAND_add
void RAND_add(const void *buf, int num, long entropy)
#endif
{
const RAND_METHOD *meth = RAND_get_rand_method();
if (meth && meth->add)
meth->add(buf,num,entropy);
}
示例10: RAND_bytes
int RAND_bytes(unsigned char *buf, int num)
{
const RAND_METHOD *meth = RAND_get_rand_method();
if (meth->bytes != NULL)
return meth->bytes(buf, num);
RANDerr(RAND_F_RAND_BYTES, RAND_R_FUNC_NOT_IMPLEMENTED);
return -1;
}
示例11: RAND_cleanup
void RAND_cleanup(void)
{
const RAND_METHOD *meth = RAND_get_rand_method();
if (meth && meth->cleanup)
meth->cleanup();
#ifndef OPERA_SMALL_VERSION
RAND_set_rand_method(NULL);
#endif // !OPERA_SMALL_VERSION
}
示例12: init_rand
static bool
init_rand ()
{
#define BUFSZ 40
unsigned char foo[BUFSZ];
RAND_get_rand_method() ->bytes (foo, BUFSZ);
#undef BUFSZ
return true;
}
示例13: __shadow_plugin_init__
/* called after g_module_check_init(), after shadow searches for __shadow_plugin_init__ */
void __shadow_plugin_init__(ShadowFunctionTable* shadowlibFuncs) {
/* save the shadow functions we will use */
scallion.shadowlibFuncs = shadowlibFuncs;
/* tell shadow which functions it should call to manage nodes */
shadowlibFuncs->registerPlugin(&_scallion_new, &_scallion_free, &_scallion_notify);
shadowlibFuncs->log(SHADOW_LOG_LEVEL_INFO, __FUNCTION__, "finished registering scallion plug-in state");
/* setup openssl locks */
#define OPENSSL_THREAD_DEFINES
#include <openssl/opensslconf.h>
#if defined(OPENSSL_THREADS)
/* thread support enabled */
/* make sure openssl uses Shadow's random sources and make crypto thread-safe */
const RAND_METHOD* shadowRandomMethod = NULL;
CRYPTO_lock_func shadowLockFunc = NULL;
CRYPTO_id_func shadowIdFunc = NULL;
int nLocks = CRYPTO_num_locks();
gboolean success = shadowlibFuncs->cryptoSetup(nLocks, (gpointer*)&shadowLockFunc,
(gpointer*)&shadowIdFunc, (gconstpointer*)&shadowRandomMethod);
if(!success) {
/* ok, lets see if we can get shadow function pointers through LD_PRELOAD */
shadowRandomMethod = RAND_get_rand_method();
shadowLockFunc = CRYPTO_get_locking_callback();
shadowIdFunc = CRYPTO_get_id_callback();
}
CRYPTO_set_locking_callback(shadowLockFunc);
CRYPTO_set_id_callback(shadowIdFunc);
RAND_set_rand_method(shadowRandomMethod);
shadowlibFuncs->log(SHADOW_LOG_LEVEL_INFO, __FUNCTION__, "finished initializing crypto thread state");
#else
/* no thread support */
shadowlibFuncs->log(SHADOW_LOG_LEVEL_CRITICAL, __FUNCTION__, "please rebuild openssl with threading support. expect segfaults.");
#endif
/* setup libevent locks */
#ifdef EVTHREAD_USE_PTHREADS_IMPLEMENTED
if(evthread_use_pthreads()) {
shadowlibFuncs->log(SHADOW_LOG_LEVEL_CRITICAL, __FUNCTION__, "error in evthread_use_pthreads()");
}
shadowlibFuncs->log(SHADOW_LOG_LEVEL_MESSAGE, __FUNCTION__, "finished initializing event thread state evthread_use_pthreads()");
#else
shadowlibFuncs->log(SHADOW_LOG_LEVEL_CRITICAL, __FUNCTION__, "please rebuild libevent with threading support, or link with event_pthread. expect segfaults.");
#endif
}
示例14: RAND_priv_bytes
/*
* This function is not part of RAND_METHOD, so if we're not using
* the default method, then just call RAND_bytes(). Otherwise make
* sure we're instantiated and use the private DRBG.
*/
int RAND_priv_bytes(unsigned char *buf, int num)
{
const RAND_METHOD *meth = RAND_get_rand_method();
if (meth != RAND_OpenSSL())
return RAND_bytes(buf, num);
if (priv_drbg.state == DRBG_UNINITIALISED
&& RAND_DRBG_instantiate(&priv_drbg, NULL, 0) == 0)
return 0;
return RAND_DRBG_generate(&priv_drbg, buf, num, 0, NULL, 0);
}
示例15: init_openssl_rand
/*
* OpenSSL random should re-feeded occasionally. From /dev/urandom
* preferably.
*/
static void
init_openssl_rand(void)
{
if (RAND_get_rand_method() == NULL)
{
#ifdef HAVE_RAND_OPENSSL
RAND_set_rand_method(RAND_OpenSSL());
#else
RAND_set_rand_method(RAND_SSLeay());
#endif
}
openssl_random_init = 1;
}