Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import os,fcntl,struct
- """
- cat > test.c <<DEL
- #include <stdio.h>
- #include <linux/random.h>
- main() { printf("%u\n",RNDADDENTROPY);}
- DEL
- gcc test.c -o a.out; ./a.out
- """
- RNDADDENTROPY = 1074287107
- entropy_dev = '/proc/sys/kernel/random/entropy_avail'
- def write_rand(block_size,bc,entropy_ratio):
- fd = os.open("/dev/random", os.O_WRONLY)
- fakefd = os.open("/dev/urandom", os.O_RDONLY)
- fmt = 'ii%is' % (block_size)
- rnd = os.read(fakefd,block_size)
- os.close(fakefd)
- this = struct.pack(fmt, entropy_ratio * len(rnd), len(rnd), rnd)
- #refeeding the same block, nooooooo
- for _ in xrange(bc):
- fcntl.ioctl(fd, RNDADDENTROPY, this)
- os.close(fd)
- def read(s):
- f = open(s,'r')
- rv = f.read()
- f.close()
- return rv
- expect = 512
- try:
- before = int(read(entropy_dev))
- while True:
- write_rand(512,10,1)
- after = int(read(entropy_dev))
- print after
- if after>=expect: break
- print 'Entropy was %s, now %s' % (before,after)
- print 'Your crypto karma just dropped below zero, Bruce Schneier hates you.'
- except Exception, e:
- print e
- print 'You probably forgot to sudo'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement