• Stars
    star
    141
  • Rank 258,443 (Top 6 %)
  • Language
    Python
  • Created over 12 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Tools for utilizing the ANU Quantum Random Number Generator

Tools for utilizing the ANU Quantum Random Numbers Server

https://api.travis-ci.org/lmacken/quantumrandom.png?branch=develop https://coveralls.io/repos/lmacken/quantumrandom/badge.png?branch=develop

This project provides tools for interacting with The ANU Quantum Random Number Generator (qrng.anu.edu.au). It communicates with their JSON API and provides a qrandom command-line tool, a Python API, and a Linux /dev/qrandom character device.

quantumrandom works on Python 2 and 3.

Note

As of version 1.7, quantumrandom now uses SSL/TLS by default.

Installing

pip install quantumrandom

Command-line tool

$ qrandom --int --min 5 --max 15
7
$ qrandom --binary
���I�%��e(�1��c��Ee�4�������j�Կ��=�^H�c�u
oq��G��Z�^���fK�0_��h��s�b��AE=�rR~���(�^Q�)4��{c�������X{f��a�Bk�N%#W
+a�a̙�IB�,S�!ꀔd�2H~�X�Z����R��.f
...
$ qrandom --hex
1dc59fde43b5045120453186d45653dd455bd8e6fc7d8c591f0018fa9261ab2835eb210e8
e267cf35a54c02ce2a93b3ec448c4c7aa84fdedb61c7b0d87c9e7acf8e9fdadc8d68bcaa5a
...
$ qrandom --binary | dd of=data
^C1752+0 records in
1752+0 records out
897024 bytes (897 kB) copied, 77.7588 s, 11.5 kB/s

Creating /dev/qrandom

quantumrandom comes equipped with a multi-threaded character device in userspace. When read from, this device fires up a bunch of threads to fetch data. Not only can you utilize this as a rng, but you can also feed this data back into your system's entropy pool.

In order to build it's dependencies, you'll need the following packages installed: svn, gcc-c++, fuse-devel, gccxml, libattr-devel. On Fedora 17 and newer, you'll also need the kernel-modules-extra package installed for the cuse module.

Note

The /dev/qrandom character device currently only supports Python2

pip install ctypeslib==dev hg+https://cusepy.googlecode.com/hg
sudo modprobe cuse
sudo chmod 666 /dev/cuse
qrandom-dev
sudo chmod 666 /dev/qrandom

By default it will use 3 threads, which can be changed by passing '-t #' into the qrandom-dev.

Testing the randomness for FIPS 140-2 compliance

$ cat /dev/qrandom | rngtest --blockcount=1000
rngtest: bits received from input: 20000032
rngtest: FIPS 140-2 successes: 1000
rngtest: FIPS 140-2 failures: 0
rngtest: FIPS 140-2(2001-10-10) Monobit: 0
rngtest: FIPS 140-2(2001-10-10) Poker: 0
rngtest: FIPS 140-2(2001-10-10) Runs: 0
rngtest: FIPS 140-2(2001-10-10) Long run: 0
rngtest: FIPS 140-2(2001-10-10) Continuous run: 0
rngtest: input channel speed: (min=17.696; avg=386.711; max=4882812.500)Kibits/s
rngtest: FIPS tests speed: (min=10.949; avg=94.538; max=161.640)Mibits/s
rngtest: Program run time: 50708319 microseconds

You can utilize the rngtest tool in pipe mode to ensure that all of your data is FIPS 140-2 compliant:

$ cat /dev/qrandom | rngtest --pipe

Adding entropy to the Linux random number generator

sudo rngd --rng-device=/dev/qrandom --random-device=/dev/random --foreground

Monitoring your available entropy levels

watch -n 1 cat /proc/sys/kernel/random/entropy_avail

Python API

The quantumrandom Python module contains a low-level get_data function, which is modelled after the ANU Quantum Random Number Generator's JSON API. It returns variable-length lists of either uint16 or hex16 data.

>>> quantumrandom.get_data()
[26646]
>>> quantumrandom.get_data(data_type='uint16', array_length=5)
[42796, 32457, 9242, 11316, 21078]
>>> quantumrandom.get_data(data_type='hex16', array_length=5, block_size=2)
['f1d5', '0eb3', '1119', '7cfd', '64ce']

Valid data_type values are uint16 and hex16, and the array_length and block_size cannot be larger than 1024. If for some reason the API call is not successful, or the incorrect amount of data is returned from the server, this function will raise an exception.

Based on this get_data function, quantumrandom also provides a bunch of higher-level helper functions that make easy to perform a variety of tasks.

>>> quantumrandom.randint(0, 20)
5
>>> quantumrandom.hex()[:10]
'8272613343'
>>> quantumrandom.binary()[0]
'\xa5'
>>> len(quantumrandom.binary())
10000
>>> quantumrandom.uint16()
numpy.array([24094, 13944, 22109, 22908, 34878, 33797, 47221, 21485, 37930, ...], dtype=numpy.uint16)
>>> quantumrandom.uint16().data[:10]
'\x87\x7fY.\xcc\xab\xea\r\x1c`'

More Repositories

1

pyrasite

Inject code into running Python processes
Python
2,787
star
2

pyrasite-gui

A graphical interface for monitoring and interacting with running Python processes
Python
252
star
3

liveusb-creator

A cross-platform tool for easily installing Fedora on to USB flash drives and SD cards.
Python
140
star
4

photobooth.py

A photobooth script that automatically snaps a photo, applies a watermark, uploads to a remote server, generates a QRCode, shortens the URL, ouputs an HTML template, and displays it your web browser.
Python
66
star
5

unicards

♠ A Python module for converting strings into unicode playing cards ♣
Python
48
star
6

openshift-quickstarter

Deploy 22 different frameworks & applications to the OpenShift Express Cloud with a single command.
Python
36
star
7

ansible-hacker-playbook

An ansible playbook that sets up a tricked-out zsh & vim environment
24
star
8

binance-chain-python

Binance chain SDK in Python
Python
23
star
9

plow

Chia Plot Mover
Python
22
star
10

tbgrep

Extracts Python Tracebacks from text
Python
21
star
11

tamefox

Puts Firefox/Chromium (or any program) to sleep when it does not have focus.
Python
14
star
12

pyramid-openshift-quickstart

Pyramid + SQLALchemy quickstart repository for OpenShift Express
Python
10
star
13

bfgminer-ansible

Deploy ASIC/FPGA/GPU miners with ansible
7
star
14

gnome-shell-extension-fedmsg

A GNOME Shell extension for configuring Fedmsg desktop notifications
JavaScript
7
star
15

irssi-libnotify

An irssi script that uses libnotify to alert user to hilighted messages
Perl
6
star
16

scrutiny

Real-time source code auditing for Fedora
Python
6
star
17

turbogears2-openshift-quickstart

TurboGears2 quickstart for Red Hat's OpenShift Express Cloud
Python
6
star
18

covidmon

A tool to monitor and visualize COVID-19 case status across many locations
Python
5
star
19

fedmsg-koji-consumer

A basic Fedmsg consumer that listens to the Fedora Build System
Python
5
star
20

suricata-ansible

An ansible playbook for deploying the Suricata intrustion detection system
5
star
21

pyblosxom-openshift-quickstart

A PyBlosxom blog quickstart for Red Hat's OpenShift Express
Python
4
star
22

moksha

A real-time web application framework
JavaScript
4
star
23

tempi

Add tempo metadata (BPM) to your music collection using The Echo Nest
Python
3
star
24

leafy-miracle

An interactive graph visualization of Fedora packages, written in Python using Pyramid, SQLAlchemy, ToscaWidgets2, and the InfoVis Toolkit.
Python
3
star
25

joy.py

A simple Python joystick interface used to map buttons to mouse clicks.
Python
3
star
26

pong.bas

A pong-like game written in QuickBASIC
Visual Basic
2
star
27

selinux-overlord

A Python script that uses func perform basic SELinux monitoring and management of your minions.
Python
2
star
28

dancer-example

Perl Dancer framework quickstart repo
CSS
2
star
29

ticker.py

Python
2
star
30

battleship.asm

A very simplified version of the game "Battleship", written in MIPS assembly
Assembly
2
star
31

nethack-demigod-bot

An IRC bot that runs on your Nethack server that notifies the channel of deaths in realtime, provides top ten high scores, and random fortunes.
Perl
2
star
32

django-example

Django git repository for OpenShift
Python
2
star
33

reviewboard-example

Example install of Reviewboard for OpenShift
Shell
1
star
34

flotbonnie

A tool generates flot graphs from bonnie++ filesystem benchmark output
JavaScript
1
star
35

aimbot

An AOL Instant Messenger bot written in Perl using Net::OSCAR. It handles group management and mass messaging.
Perl
1
star
36

filebrowse.pl

A Gtk2 filebrowser written in Perl. Created by "Team Perl" at the 2nd Red Bull Programming Competition at RIT (2003). This program was created in 12 hours, and hasn't been touched since. It's still pretty cool.
Perl
1
star