This package implements R functions and an S3 class to access the NIST the NIST Randomness Beacon, through its REST web service interface.
The NIST service generates full-entropy bit-strings and posts them in blocks
of 512 bits every 60 seconds
^[https://beacon.nist.gov/home]
According to the beacon's documentation, there are five endpoints defined and this package wraps the call to each one in a function:
nrb_get_last()
https://beacon.nist.gov/rest/record/last
nrb_get_next(timestamp)
https://beacon.nist.gov/rest/record/next/<timestamp>
nrb_get_previous(timestamp)
https://beacon.nist.gov/rest/record/previous/<timestamp>
nrb_get_record(timestamp)
https://beacon.nist.gov/rest/record/<timestamp>
nrb_get_start_chain(timestamp)
https://beacon.nist.gov/rest/record/start-chain/<timestamp>
Where timestamp
is in POSIX time format: the number of seconds since midnight
UTC, January 1, 1970. Alternatively a POSIXct
o POSIXlt
value can be used.
The service returns an XML document with several pieces of information:
This package wraps this XML document in the nrb_response
class, which contains all
the values from the beacon's response.
An nrb_response
object contains the properties
version
: The current beacon's versionfrequency
: The beacon's update frequency in secondsurl
: The endpoint calltimeStamp
: The timestamp (UTC) in Unix Time formatseedValue
: The random beacon string for a given timestamppreviousOutputValue
: The hash of the previous beacon's record signaturesignatureValue
: The digital signature of the recordoutputValue
: The hash of the current signaturestatusCode
: The service status code for this recordstatusDesc
: A description of the status codeFor example, to get the record generated on Jan 1, 2015 at 10:00h (UTC), we will use the following code:
library(nistrb) ts <- as.POSIXct("2015-01-01 10:00:00", tz = "UTC") rec <- nrb_get_record(ts) rec
We can also make sure that the record chain is unbroken, getting the previous record from the beacon (Jan 1, 2015 09:59h, UTC):
prev_ts <- as.POSIXct("2015-01-01 09:59:00", tz = "UTC") prev_rec <- nrb_get_record(prev_ts) prev_rec$output == rec$previousOutputValue
or the next record:
next_ts <- as.POSIXct("2015-01-01 10:01:00", tz = "UTC") next_rec <- nrb_get_record(next_ts) rec$output == next_rec$previousOutputValue
We can use the NIST Randomness Beacon as a source of reproducible random seeds that depends on a timestamp, for example:
library(nistrb) # get the number of numeric chars in the seed # more than a bit contrived as examples go gen_seed <- function(timestamp) { rec <- nrb_get_record(timestamp) chrs <- strsplit(rec$seedValue, NULL) sum(sapply(chrs, FUN = function(x) { grepl(pattern = "[0-9]", x = x) })) } ts <- as.POSIXct("2015-07-28 00:00:00", tz = "UTC") gen_seed(ts) ts <- as.POSIXct("2014-12-25 12:00:00", tz = "UTC") gen_seed(ts)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.