2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 06:25:31 +00:00
This commit is contained in:
Michael Graff
2000-06-09 02:00:22 +00:00
parent 58c40ca8bd
commit c6e2d36708
3 changed files with 93 additions and 20 deletions

View File

@@ -49,9 +49,12 @@ CHECK(const char *msg, isc_result_t result) {
int
main(int argc, char **argv) {
isc_mem_t *mctx;
unsigned char buffer[1024];
unsigned char buffer[512];
isc_entropy_t *ent;
isc_entropysource_t *devrandom;
unsigned int returned;
unsigned int flags;
isc_result_t result;
UNUSED(argc);
UNUSED(argv);
@@ -64,10 +67,38 @@ main(int argc, char **argv) {
CHECK("isc_entropy_create()",
isc_entropy_create(mctx, &ent));
isc_entropy_stats(ent, stderr);
devrandom = NULL;
CHECK("isc_entropy_createfilesource()",
isc_entropy_createfilesource(ent, "/dev/random",
0, &devrandom));
fprintf(stderr,
"Reading 32 bytes of GOOD random data only, partial OK\n");
flags = 0;
flags |= ISC_ENTROPY_GOODONLY;
flags |= ISC_ENTROPY_PARTIAL;
result = isc_entropy_getdata(ent, buffer, 32, &returned, flags);
if (result == ISC_R_NOENTROPY) {
fprintf(stderr, "No entropy.\n");
goto out;
}
hex_dump("good data only:", buffer, returned);
CHECK("isc_entropy_getdata()",
isc_entropy_getdata(ent, buffer, 128, NULL, 0));
hex_dump("entropy data", buffer, 128);
out:
isc_entropy_stats(ent, stderr);
isc_entropy_destroysource(&devrandom);
isc_entropy_destroy(&ent);
isc_mem_stats(mctx, stderr);
isc_mem_destroy(&mctx);
return (0);
}