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]

Implementation details

Functions

According to the beacon's documentation, there are five endpoints defined and this package wraps the call to each one in a function:

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.

Class

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

For 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

Example of use

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)


jmcastagnetto/nistrb documentation built on May 19, 2019, 1:52 p.m.