• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ RAND_add函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中RAND_add函数的典型用法代码示例。如果您正苦于以下问题:C++ RAND_add函数的具体用法?C++ RAND_add怎么用?C++ RAND_add使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了RAND_add函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: RandAddSeedPerfmon

void RandAddSeedPerfmon()
{
    RandAddSeed();

    // This can take up to 2 seconds, so only do it every 10 minutes
    static int64 nLastPerfmon;
    if (GetTime() < nLastPerfmon + 10 * 60)
        return;
    nLastPerfmon = GetTime();

#ifdef __WXMSW__
    // Don't need this on Linux, OpenSSL automatically uses /dev/urandom
    // Seed with the entire set of perfmon data
    unsigned char pdata[250000];
    memset(pdata, 0, sizeof(pdata));
    unsigned long nSize = sizeof(pdata);
    long ret = RegQueryValueExA(HKEY_PERFORMANCE_DATA, "Global", NULL, NULL, pdata, &nSize);
    RegCloseKey(HKEY_PERFORMANCE_DATA);
    if (ret == ERROR_SUCCESS)
    {
        RAND_add(pdata, nSize, nSize/100.0);
        memset(pdata, 0, nSize);
        printf("%s RandAddSeed() %d bytes\n", DateTimeStrFormat("%x %H:%M", GetTime()).c_str(), nSize);
    }
#endif
}
开发者ID:semyazza,项目名称:bitcoin,代码行数:26,代码来源:util.cpp


示例2: RandAddSeed

void RandAddSeed()
{
    // Seed with CPU performance counter
    int64 nCounter = GetPerformanceCounter();
    RAND_add(&nCounter, sizeof(nCounter), 1.5);
    memset(&nCounter, 0, sizeof(nCounter));
}
开发者ID:semyazza,项目名称:bitcoin,代码行数:7,代码来源:util.cpp


示例3: RAND_poll

int RAND_poll(void)
{
	unsigned long l;
#ifdef HAVE_GETPID	
	pid_t curr_pid = getpid();
#endif
#ifdef DEVRANDOM
	FILE *fh;
#endif

#ifdef DEVRANDOM
	/* Use a random entropy pool device. Linux, FreeBSD and OpenBSD
	 * have this. Use /dev/urandom if you can as /dev/random may block
	 * if it runs out of random entries.  */

	if ((fh = fopen(DEVRANDOM, "r")) != NULL)
		{
		unsigned char tmpbuf[ENTROPY_NEEDED];
		int n;
		
		setvbuf(fh, NULL, _IONBF, 0);
		n=fread((unsigned char *)tmpbuf,1,ENTROPY_NEEDED,fh);
		fclose(fh);
		RAND_add(tmpbuf,sizeof tmpbuf,n);
		memset(tmpbuf,0,n);
		}
#endif

	/* put in some default random data, we need more than just this */
#ifdef HAVE_GETPID
	l=curr_pid;
	RAND_add(&l,sizeof(l),0);
#endif
#ifdef HAVE_GETUID
	l=getuid();
	RAND_add(&l,sizeof(l),0);
#endif

	l=time(NULL);
	RAND_add(&l,sizeof(l),0);

#ifdef DEVRANDOM
	return 1;
#else
	return 0;
#endif
}
开发者ID:jhbsz,项目名称:actiontec_opensource_mi424wr-rev-acd-56-0-10-14-4,代码行数:47,代码来源:rand_win.c


示例4: seed_something

static int
seed_something(void)
{
#ifndef NO_RANDFILE
    char buf[1024], seedfile[256];

    /* If there is a seed file, load it. But such a file cannot be trusted,
       so use 0 for the entropy estimate */
    if (RAND_file_name(seedfile, sizeof(seedfile))) {
	int fd;
	fd = open(seedfile, O_RDONLY | O_BINARY | O_CLOEXEC);
	if (fd >= 0) {
	    ssize_t ret;
	    rk_cloexec(fd);
	    ret = read(fd, buf, sizeof(buf));
	    if (ret > 0)
		RAND_add(buf, ret, 0.0);
	    close(fd);
	} else
	    seedfile[0] = '\0';
    } else
	seedfile[0] = '\0';
#endif

    /* Calling RAND_status() will try to use /dev/urandom if it exists so
       we do not have to deal with it. */
    if (RAND_status() != 1) {
#if defined(HAVE_RAND_EGD)
	krb5_context context;
	const char *p;

#ifndef OPENSSL_NO_EGD
	/* Try using egd */
	if (!krb5_init_context(&context)) {
	    p = krb5_config_get_string(context, NULL, "libdefaults",
				       "egd_socket", NULL);
	    if (p != NULL)
		RAND_egd_bytes(p, ENTROPY_NEEDED);
	    krb5_free_context(context);
	}
#endif

#else
	/* TODO: Once a Windows CryptoAPI RAND method is defined, we
	   can use that and failover to another method. */
#endif
    }

    if (RAND_status() == 1)	{
#ifndef NO_RANDFILE
	/* Update the seed file */
	if (seedfile[0])
	    RAND_write_file(seedfile);
#endif

	return 0;
    } else
	return -1;
}
开发者ID:Sp1l,项目名称:heimdal,代码行数:59,代码来源:crypto-rand.c


示例5: ossl_rand_add

/*
 *  call-seq:
 *     add(str, entropy) -> self
 *
 */
static VALUE
ossl_rand_add(VALUE self, VALUE str, VALUE entropy)
{
    StringValue(str);
    RAND_add(RSTRING_PTR(str), RSTRING_LEN(str), NUM2DBL(entropy));

    return self;
}
开发者ID:AdamDotCom,项目名称:my-rvm,代码行数:13,代码来源:ossl_rand.c


示例6: rand_add

static int rand_add(lua_State *L)
{
  size_t num;
  const void *buf = luaL_checklstring(L, 1, &num);
  double entropy = luaL_optnumber(L, 2, num);
  RAND_add(buf, (int)num, entropy);
  return 0;
}
开发者ID:dtiedy,项目名称:luaplus51-all,代码行数:8,代码来源:lcrypto.c


示例7: RAND_poll

int RAND_poll(void)
	{
	unsigned long Time=(unsigned long)TINYCLR_SSL_TIME(NULL);

	RAND_add(&Time,sizeof(Time),ENTROPY_NEEDED);

	return 1;
	}
开发者ID:AustinWise,项目名称:Netduino-Micro-Framework,代码行数:8,代码来源:rand_imxs.cpp


示例8: RAND_poll

int RAND_poll(void)
{
    MEMORYSTATUS mst;
# ifndef RAND_WINDOWS_USE_BCRYPT
    HCRYPTPROV hProvider;
# endif
    DWORD w;
    BYTE buf[64];

# ifdef RAND_WINDOWS_USE_BCRYPT
    if (BCryptGenRandom(NULL, buf, (ULONG)sizeof(buf), BCRYPT_USE_SYSTEM_PREFERRED_RNG) == STATUS_SUCCESS) {
        RAND_add(buf, sizeof(buf), sizeof(buf));
    }
# else
    /* poll the CryptoAPI PRNG */
    /* The CryptoAPI returns sizeof(buf) bytes of randomness */
    if (CryptAcquireContextW(&hProvider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) {
        if (CryptGenRandom(hProvider, (DWORD)sizeof(buf), buf) != 0) {
            RAND_add(buf, sizeof(buf), sizeof(buf));
        }
        CryptReleaseContext(hProvider, 0);
    }

    /* poll the Pentium PRG with CryptoAPI */
    if (CryptAcquireContextW(&hProvider, NULL, INTEL_DEF_PROV, PROV_INTEL_SEC, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) {
        if (CryptGenRandom(hProvider, (DWORD)sizeof(buf), buf) != 0) {
            RAND_add(buf, sizeof(buf), sizeof(buf));
        }
        CryptReleaseContext(hProvider, 0);
    }
# endif

    /* timer data */
    readtimer();

    /* memory usage statistics */
    GlobalMemoryStatus(&mst);
    RAND_add(&mst, sizeof(mst), 1);

    /* process ID */
    w = GetCurrentProcessId();
    RAND_add(&w, sizeof(w), 1);

    return (1);
}
开发者ID:2007750219,项目名称:openssl,代码行数:45,代码来源:rand_win.c


示例9: px_add_entropy

int
px_add_entropy(const uint8 *data, unsigned count)
{
	/*
	 * estimate 0 bits
	 */
	RAND_add(data, count, 0);
	return 0;
}
开发者ID:Epictetus,项目名称:postgres,代码行数:9,代码来源:openssl.c


示例10: openssl_random_add

/***
mixes the num bytes at buf into the PRNG state.
@function rand_add
@tparam string seed data to seed random generator
@tparam number entropy the lower bound of an estimate of how much randomness is contained in buf, measured in bytes.
*/
static int openssl_random_add(lua_State*L)
{
  size_t num = 0;
  const void *buf = luaL_checklstring(L, 1, &num);
  double entropy = luaL_optinteger(L, 2, num);

  RAND_add(buf, num, entropy);
  return 0;
}
开发者ID:zhaozg,项目名称:lua-openssl,代码行数:15,代码来源:openssl.c


示例11: RAND_poll

   /*
    * the FAQ indicates we need to provide at least 20 bytes (160 bits) of
    * seed
    */
int RAND_poll(void)
{
    unsigned long l;
    unsigned long tsc;
    int i;

    /*
     * There are several options to gather miscellaneous data but for now we
     * will loop checking the time stamp counter (rdtsc) and the
     * SuperHighResolutionTimer.  Each iteration will collect 8 bytes of data
     * but it is treated as only 1 byte of entropy.  The call to
     * ThreadSwitchWithDelay() will introduce additional variability into the
     * data returned by rdtsc. Applications can argument the seed material
     * by adding additional stuff with RAND_add() and should probably do so.
     */
    l = GetProcessSwitchCount();
    RAND_add(&l, sizeof(l), 1);

    /* need to cast the void* to unsigned long here */
    l = (unsigned long)RunningProcess;
    RAND_add(&l, sizeof(l), 1);

    for (i = 2; i < ENTROPY_NEEDED; i++) {
# ifdef __MWERKS__
        asm {
        rdtsc mov tsc, eax}
# elif defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
        asm volatile ("rdtsc":"=a" (tsc)::"edx");
# endif

        RAND_add(&tsc, sizeof(tsc), 1);

        l = GetSuperHighResolutionTimer();
        RAND_add(&l, sizeof(l), 0);

# if defined(NETWARE_LIBC)
        NXThreadYield();
# else                          /* NETWARE_CLIB */
        ThreadSwitchWithDelay();
# endif
    }

    return 1;
}
开发者ID:DarovskikhAndrei,项目名称:openssl,代码行数:48,代码来源:rand_nw.c


示例12: RAND_poll

int RAND_poll(void)
{
    long pid, iosb[2];
    int status = 0;
    struct {
        short length, code;
        long *buffer;
        int *retlen;
    } item[32], *pitem;
    unsigned char data_buffer[256];
    short total_length = 0;
    struct items_data_st *pitems_data;

    pitems_data = items_data;
    pitem = item;

    /* Setup */
    while (pitems_data->length && (total_length + pitems_data->length <= 256)) {
        pitem->length = pitems_data->length;
        pitem->code = pitems_data->code;
        pitem->buffer = (long *)&data_buffer[total_length];
        pitem->retlen = 0;
        total_length += pitems_data->length;
        pitems_data++;
        pitem ++;
    }
    pitem->length = pitem->code = 0;

    /*
     * Scan through all the processes in the system and add entropy with
     * results from the processes that were possible to look at.
     * However, view the information as only half trustable.
     */
    pid = -1;                   /* search context */
    while ((status = sys$getjpiw(0, &pid, 0, item, iosb, 0, 0))
           != SS$_NOMOREPROC) {
        if (status == SS$_NORMAL) {
            RAND_add((PTR_T) data_buffer, total_length, total_length / 2);
        }
    }
    sys$gettim(iosb);
    RAND_add((PTR_T) iosb, sizeof(iosb), sizeof(iosb) / 2);
    return 1;
}
开发者ID:1564143452,项目名称:kbengine,代码行数:44,代码来源:rand_vms.c


示例13: test_rand_add

static int test_rand_add(void)
{
    char *p;

    if (!TEST_ptr(p = malloc(RAND_ADD_SIZE)))
        return 0;
    RAND_add(p, RAND_ADD_SIZE, RAND_ADD_SIZE);
    free(p);
    return 1;
}
开发者ID:lookfun,项目名称:openssl,代码行数:10,代码来源:drbgtest.c


示例14: sqlcipher_openssl_add_random

static int sqlcipher_openssl_add_random(void *ctx, void *buffer, int length) {
#ifndef SQLCIPHER_OPENSSL_NO_MUTEX_RAND
  sqlite3_mutex_enter(openssl_rand_mutex);
#endif
  RAND_add(buffer, length, 0);
#ifndef SQLCIPHER_OPENSSL_NO_MUTEX_RAND
  sqlite3_mutex_leave(openssl_rand_mutex);
#endif
  return SQLITE_OK;
}
开发者ID:akrav,项目名称:sqlcipher,代码行数:10,代码来源:crypto_openssl.c


示例15: RAND_load_file

int RAND_load_file(const char *file, long bytes)
	{
	/* If bytes >= 0, read up to 'bytes' bytes.
	 * if bytes == -1, read complete file. */

	MS_STATIC unsigned char buf[BUFSIZE];
	struct stat sb;
	int i,ret=0,n;
	FILE *in;

	if (file == NULL) return(0);

	i=stat(file,&sb);
	/* If the state fails, put some crap in anyway */
	RAND_add(&sb,sizeof(sb),0);
	if (i < 0) return(0);
	if (bytes == 0) return(ret);

	in=fopen(file,"rb");
	if (in == NULL) goto err;
	for (;;)
		{
		if (bytes > 0)
			n = (bytes < BUFSIZE)?(int)bytes:BUFSIZE;
		else
			n = BUFSIZE;
		i=fread(buf,1,n,in);
		if (i <= 0) break;
		/* even if n != i, use the full array */
		RAND_add(buf,n,i);
		ret+=i;
		if (bytes > 0)
			{
			bytes-=n;
			if (bytes == 0) break;
			}
		}
	fclose(in);
	memset(buf,0,BUFSIZE);
err:
	return(ret);
	}
开发者ID:ahenroid,项目名称:ptptl-0.2,代码行数:42,代码来源:randfile.c


示例16: assert

void
csprng_engine::mix (
    void* data, std::size_t size, double bitsPerByte)
{
    assert (data != nullptr);
    assert (size != 0);
    assert (bitsPerByte != 0);

    std::lock_guard<std::mutex> lock (mutex_);
    RAND_add (data, size, (size * bitsPerByte) / 8.0);
}
开发者ID:Empresaria,项目名称:rippled,代码行数:11,代码来源:csprng.cpp


示例17: rexec_recv_rng_seed

void
rexec_recv_rng_seed(Buffer *m)
{
	u_char *buf;
	u_int len;

	buf = buffer_get_string_ret(m, &len);
	if (buf != NULL) {
		debug3("rexec_recv_rng_seed: seeding rng with %u bytes", len);
		RAND_add(buf, len, len);
	}
}
开发者ID:lodyagin,项目名称:shiesh,代码行数:12,代码来源:entropy.cpp


示例18: get_random_bytes

unsigned char * get_random_bytes(size_t len) {
	char timeseed[32];
    time_t now = time(NULL);
    size_t b = snprintf(timeseed,32,"%ld",now);
    RAND_add(&timeseed[0],b,2);

	unsigned char *randbytes = malloc(sizeof(unsigned char)*len);
    RAND_bytes(randbytes,len);

    RAND_cleanup();
    return randbytes;
}
开发者ID:nplanel,项目名称:cchs-security-frontend,代码行数:12,代码来源:crypto.c


示例19: ndn_add_entropy

/**
 * Feed some entropy to the random number generator.
 * 
 * @param buf is the source buffer
 * @param size is in bytes
 * @param bits_of_entropy is an estimate; use 0 to make me guess
 */
void
ndn_add_entropy(const void *buf, size_t size, int bits_of_entropy)
{
    int num = size;
    
    if (num < 0 || num != size)
        abort();
    /* Supply a hopefully conservative estimate of entropy. */
    if (bits_of_entropy <= 0)
        bits_of_entropy = (num < 32) ? 1 : num / 32;
    RAND_add((unsigned char *)buf, num, bits_of_entropy * 0.125);
}
开发者ID:cawka,项目名称:ndnd-tlv,代码行数:19,代码来源:ndn_signing.c


示例20: rand_add

static int rand_add(lua_State *L)
{
  size_t num;
  const void *buf = luaL_checklstring(L, 1, &num);
#if CRYPTO_OPENSSL
  double entropy = (double)luaL_optnumber(L, 2, num);
  RAND_add(buf, num, entropy);
#elif CRYPTO_GCRYPT
  gcry_random_add_bytes(buf, num, -1); // unknown quality
#endif
  return 0;
}
开发者ID:hahnakane,项目名称:junkcode,代码行数:12,代码来源:lcrypto.c



注:本文中的RAND_add函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ RAND_bytes函数代码示例发布时间:2022-05-30
下一篇:
C++ RANDOM_LONG函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap