PRNG(pseudo random number generator) is added
This commit is contained in:
parent
0523d99b5b
commit
0bd56d0e49
|
@ -78,6 +78,9 @@ extern "C" {
|
|||
#define c_max(x , y) (((x) > (y)) ? (x) : (y))
|
||||
#define c_min(x , y) (((x) < (y)) ? (x) : (y))
|
||||
|
||||
CORE_DECLARE(status_t) core_generate_random_bytes(
|
||||
unsigned char *buf, int length);
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -10,7 +10,7 @@ libcoreunix_la_SOURCES = \
|
|||
|
||||
nodist_libcoreunix_la_SOURCES = \
|
||||
cond.c file.c net_lib.c thread.c errorcodes.c mutex.c rwlock.c \
|
||||
start.c time.c semaphore.c signal.c pkbuf.c
|
||||
start.c time.c semaphore.c signal.c pkbuf.c rand.c
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
-I$(top_srcdir) \
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
#include "core_errno.h"
|
||||
|
||||
#define DEV_RANDOM "/dev/urandom"
|
||||
|
||||
status_t core_generate_random_bytes(unsigned char *buf, int length)
|
||||
{
|
||||
int fd = -1;
|
||||
|
||||
/* On BSD/OS 4.1, /dev/random gives out 8 bytes at a time, then
|
||||
* gives EOF, so reading 'length' bytes may require opening the
|
||||
* device several times. */
|
||||
do {
|
||||
int rc;
|
||||
|
||||
if (fd == -1)
|
||||
if ((fd = open(DEV_RANDOM, O_RDONLY)) == -1)
|
||||
return errno;
|
||||
|
||||
do {
|
||||
rc = read(fd, buf, length);
|
||||
} while (rc == -1 && errno == EINTR);
|
||||
|
||||
if (rc < 0) {
|
||||
int errnum = errno;
|
||||
close(fd);
|
||||
return errnum;
|
||||
}
|
||||
else if (rc == 0) {
|
||||
close(fd);
|
||||
fd = -1; /* force open() again */
|
||||
}
|
||||
else {
|
||||
buf += rc;
|
||||
length -= rc;
|
||||
}
|
||||
} while (length > 0);
|
||||
|
||||
close(fd);
|
||||
|
||||
return CORE_OK;
|
||||
}
|
|
@ -6,7 +6,7 @@ testcore_SOURCES = \
|
|||
abts.c testds.c testfsm.c testnetlib.c testthread.c testtlv.c \
|
||||
testaes.c testfile.c testlock.c testsha.c testtime.c testutil.c \
|
||||
testdir.c testfilecopy.c testmsgq.c testsleep.c testtimer.c \
|
||||
testpkbuf.c \
|
||||
testpkbuf.c testmisc.c \
|
||||
abts.h abts_tests.h testutil.h
|
||||
|
||||
testcore_LDADD = \
|
||||
|
|
|
@ -39,6 +39,7 @@ const struct testlist {
|
|||
{testmsgq},
|
||||
{testsleep},
|
||||
{testpkbuf},
|
||||
{testmisc},
|
||||
};
|
||||
|
||||
#endif /* APR_TEST_INCLUDES */
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
#include "core_lib.h"
|
||||
#include "core_debug.h"
|
||||
|
||||
#include "testutil.h"
|
||||
|
||||
static void misc_test1(abts_case *tc, void *data)
|
||||
{
|
||||
unsigned char c[42];
|
||||
ABTS_INT_EQUAL(tc, CORE_OK, core_generate_random_bytes(c, sizeof c));
|
||||
}
|
||||
|
||||
abts_suite *testmisc(abts_suite *suite)
|
||||
{
|
||||
suite = ADD_SUITE(suite)
|
||||
|
||||
abts_run_test(suite, misc_test1, NULL);
|
||||
|
||||
return suite;
|
||||
}
|
|
@ -73,5 +73,6 @@ abts_suite *testdir(abts_suite *suite);
|
|||
abts_suite *testmsgq(abts_suite *suite);
|
||||
abts_suite *testsleep(abts_suite *suite);
|
||||
abts_suite *testpkbuf(abts_suite *suite);
|
||||
abts_suite *testmisc(abts_suite *suite);
|
||||
|
||||
#endif /* CORE_TEST_INCLUDES */
|
||||
|
|
|
@ -5,9 +5,11 @@ SUBDIRS = freeDiameter
|
|||
noinst_LTLIBRARIES = libs6a.la
|
||||
|
||||
libs6a_la_SOURCES = \
|
||||
milenage.h \
|
||||
s6a_app.h
|
||||
|
||||
nodist_libs6a_la_SOURCES = \
|
||||
milenage.c \
|
||||
s6a_init.c s6a_config.c s6a_fd.c s6a_app.c s6a_dict.c \
|
||||
s6a_hss.c s6a_mme.c
|
||||
|
||||
|
|
|
@ -26,8 +26,6 @@ status_t cellwire_initialize(char *config_path, char *log_path)
|
|||
|
||||
core_initialize();
|
||||
|
||||
srand(time(NULL)*getpid());
|
||||
|
||||
if (config_path)
|
||||
{
|
||||
/* TODO */
|
||||
|
|
Loading…
Reference in New Issue