代码拉取完成,页面将自动刷新
/*
* coap_prng.c -- random number generation
*
* Copyright (C) 2020 Olaf Bergmann <bergmann@tzi.org>
*
* This file is part of the CoAP library libcoap. Please see README
* for terms of use.
*/
#include "coap_internal.h"
#ifdef HAVE_GETRANDOM
#include <sys/random.h>
#else /* !HAVE_GETRANDOM */
#include <stdlib.h>
#endif /* !HAVE_GETRANDOM */
static int
coap_prng_default(void *buf, size_t len) {
#ifdef HAVE_GETRANDOM
return getrandom(buf, len, 0);
#else /* !HAVE_GETRANDOM */
unsigned char *dst = (unsigned char *)buf;
while (len--)
*dst++ = rand() & 0xFF;
return 1;
#endif /* !HAVE_GETRANDOM */
}
static coap_rand_func_t rand_func = coap_prng_default;
void
coap_set_prng(coap_rand_func_t rng) {
rand_func = rng;
}
void
coap_prng_init(unsigned long seed) {
#ifdef HAVE_GETRANDOM
/* No seed to seed the random source if getrandom() is used,
* see dtls_prng(). */
(void)seed;
#else /* !HAVE_GETRANDOM */
srand(seed);
#endif /* !HAVE_GETRANDOM */
}
int
coap_prng(void *buf, size_t len) {
if (!rand_func) {
return 0;
}
rand_func(buf, len);
return 1;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。