#include #include #include #include #include #include #define _PATH_URANDOM "/dev/urandom" int main(void) { rndpoolstat_t rs; int fd, result; long gCriticalEntropyThreshold, gMaxEntropy; u_int32_t entropy; fd = open(_PATH_URANDOM, O_RDONLY, 0644); if (fd < 0) { fprintf(stderr, "Could not open %s: %s\n", _PATH_URANDOM, strerror(errno)); exit(1); } if (ioctl(fd, RNDGETPOOLSTAT, &rs) < 0) { fprintf(stderr, "RNDGETPOOLSTAT failed: %s\n", strerror(errno)); exit(1); } result = ioctl( fd, RNDGETENTCNT, &entropy ); if( result == -1 ) { fprintf(stderr, "Call to ioctl() failed. Exiting.\n"); exit(1); } close(fd); gMaxEntropy = rs.maxentropy; gCriticalEntropyThreshold = rs.threshold; if (gCriticalEntropyThreshold < 2 * SHA1_DIGEST_LENGTH) { gCriticalEntropyThreshold = 2 * SHA1_DIGEST_LENGTH; } printf("Entropy threshold: %ld; available: %ld\n", gCriticalEntropyThreshold, (long)entropy); return 0; }