2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-27 20:49:04 +00:00
bind/bin/tests/entropy_test.c

74 lines
1.9 KiB
C
Raw Normal View History

2000-06-08 23:41:37 +00:00
/*
* Copyright (C) 2000 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#include <isc/entropy.h>
2000-06-09 00:11:39 +00:00
#include <isc/mem.h>
2000-06-08 23:41:37 +00:00
#include <isc/util.h>
#include <isc/string.h>
#include <stdio.h>
static void
2000-06-09 00:11:39 +00:00
hex_dump(char *msg, void *data, unsigned int length) {
2000-06-08 23:41:37 +00:00
unsigned int len;
2000-06-09 00:11:39 +00:00
unsigned char *base;
2000-06-08 23:41:37 +00:00
2000-06-09 00:11:39 +00:00
base = data;
printf("DUMP of %d bytes: %s\n", length, msg);
for (len = 0 ; len < length ; len++) {
2000-06-08 23:41:37 +00:00
if (len % 16 == 0)
printf("\n");
2000-06-09 00:11:39 +00:00
printf("%02x ", base[len]);
2000-06-08 23:41:37 +00:00
}
printf("\n");
}
2000-06-09 00:11:39 +00:00
static void
CHECK(const char *msg, isc_result_t result) {
if (result != ISC_R_SUCCESS) {
printf("FAILURE: %s\n", msg);
exit(1);
}
}
2000-06-08 23:41:37 +00:00
int
main(int argc, char **argv) {
2000-06-09 00:11:39 +00:00
isc_mem_t *mctx;
2000-06-08 23:41:37 +00:00
unsigned char buffer[1024];
2000-06-09 00:11:39 +00:00
isc_entropy_t *ent;
isc_entropysource_t *devrandom;
2000-06-08 23:41:37 +00:00
UNUSED(argc);
UNUSED(argv);
2000-06-09 00:11:39 +00:00
mctx = NULL;
CHECK("isc_mem_create()",
isc_mem_create(0, 0, &mctx));
ent = NULL;
CHECK("isc_entropy_create()",
isc_entropy_create(mctx, &ent));
devrandom = NULL;
CHECK("isc_entropy_createfilesource()",
isc_entropy_createfilesource(ent, "/dev/random",
0, &devrandom));
2000-06-08 23:41:37 +00:00
return (0);
}