;;;; entropy-linux.scm ;;;; Kon Lovett, Oct '17 (module entropy-linux (;export make-entropy-source-getrandom) (import scheme) (import chicken) (use entropy-source entropy-procedure) ;;; Entropy from getentropy #> #if defined __GLIBC__ && defined __linux__ # define _GNU_SOURCE 1 # include # include # if __GLIBC__ > 2 || __GLIBC_MINOR__ > 24 # include static int linux_getentropy( void *buf, size_t buflen ) { return getentropy( buf, buflen ); } # else /* older glibc */ # include # include static int linux_getentropy( void *buf, size_t buflen ) { if( buflen > 256 ) { errno = EIO; return -1; } return syscall(SYS_getrandom, buf, buflen, 0); } # endif #endif <# (cond-expand (linux (define (make-entropy-source-getrandom) (make-entropy-source/procedure getrandom_u8proc getrandom_f64proc "getrandom" 'getrandom "Entropy from getrandom") ) ) (else (define (make-entropy-source-getrandom) (void) ) ) ) (register-entropy-source! 'getrandom make-entropy-source-getrandom) ) ;module entropy-linux