entropy_test.c revision 9403a56228ea64101e082720fd276a8bda16cfe1
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews/*
7d32c065c7bb56f281651ae3dd2888f32ce4f1d9Bob Halley * Copyright (C) 2000 Internet Software Consortium.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews *
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Permission to use, copy, modify, and distribute this software for any
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * purpose with or without fee is hereby granted, provided that the above
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * copyright notice and this permission notice appear in all copies.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews *
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * SOFTWARE.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
f6407f9a0b890bebbfd5f738d9c4aef3d3315fe9Michael Graff#include <isc/entropy.h>
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff#include <isc/mem.h>
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff#include <isc/util.h>
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff#include <isc/string.h>
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews#include <stdio.h>
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff
f6407f9a0b890bebbfd5f738d9c4aef3d3315fe9Michael Graffstatic void
3761c433912beabe43abeed2c3513b6201c59f64Mark Andrewshex_dump(char *msg, void *data, unsigned int length) {
822f6cdabb1edd44472c7a758b5cae71376fa9beBrian Wellington unsigned int len;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews unsigned char *base;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff base = data;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews printf("DUMP of %d bytes: %s\n", length, msg);
973a19342597823f111fce6a8cd5adfd0e2e7c0dMark Andrews for (len = 0 ; len < length ; len++) {
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff if (len % 16 == 0)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews printf("\n");
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews printf("%02x ", base[len]);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews printf("\n");
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews}
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrewsstatic void
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark AndrewsCHECK(const char *msg, isc_result_t result) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (result != ISC_R_SUCCESS) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson printf("FAILURE: %s\n", msg);
c1e7aff941dbf40090fec49300e728ad017d4f0cMark Andrews exit(1);
4fd3e3482c7e4ce01e2cf28f13e0152c8e50d746Mark Andrews }
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson}
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsint
eb6bd543c7d072efdca509eb17f8f301c1467b53Mark Andrewsmain(int argc, char **argv) {
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff isc_mem_t *mctx;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff unsigned char buffer[1024];
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews isc_entropy_t *ent;
eb6bd543c7d072efdca509eb17f8f301c1467b53Mark Andrews isc_entropysource_t *devrandom;
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson UNUSED(argc);
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson UNUSED(argv);
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson mctx = NULL;
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson CHECK("isc_mem_create()",
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson isc_mem_create(0, 0, &mctx));
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson ent = NULL;
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson CHECK("isc_entropy_create()",
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson isc_entropy_create(mctx, &ent));
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson devrandom = NULL;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff CHECK("isc_entropy_createfilesource()",
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff isc_entropy_createfilesource(ent, "/dev/random",
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews 0, &devrandom));
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (0);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews