Are there algorithms that enable the creation of a non periodical, theoretically unlimited, sequence of numbers based on an alphanumeric secret key? The idea is to produce always the same unique sequence from a secret alphanumeric key, where the sequence doesn't leak information about the used key, and looks random enough from a cryptographic stance. If the key changes just one bit, the pattern is completely different. Is there a known secure way to produce this?
There are quite a few options here as you can basically use any algorithm with a single key input and configurable amount of output:
- a DRBG (or CSPRNG) such as Hash_DRBG or CTR_DRBG;
- a stream cipher or block cipher in streaming mode such as Salsa20 or AES in counter mode;
- a KBKDF such as HKDF;
- a XOF such as SHAKE256 (SHA-3).
In principle a DRBG - deterministic random bit generator - may seem to be the best option. A DRBG basically turns a seed into a stream of random bytes. It may however request reseeding, which may be a problem. To resolve this, just keep feeding it the same value or zero bytes at the same point in the stream and you should be OK. Furthermore, the DRBG needs to be well defined; some programming API's make changes in the algorithm without notification. This may mean that there are few implementations available - if any, as most of them are simply designed to return unpredictable random numbers. Note that a DRBG is also known as a CSPRNG - a Cryptographically Secure Pseudo Random Number Generator or sometimes just as a PRNG.
A stream cipher takes a symmetric key (and possibly an IV) and turns it into a pseudo random key stream consisting of a virtually unlimited amount bytes. This is completely deterministic and doesn't require reseeding. Note that this key stream was created for encryption rather than randomness. One of the weird properties of counter (CTR or SIC) mode encryption is that it never repeats a block, which distinguishes it from a random stream of bytes. The chance of randomly creating e.g. two identical 128 bit blocks is however infinitely small, so that should not pose a problem.
A KBKDF - Key Based Key Derivation Function - such as HKDF generally can be seen to have an extract and expand phase. First during extraction the entropy in your initial key is put into the state. This state is then used to generate a virtually unlimited amount of bytes. This is called the expansion phase. Problem with this approach is that most of the KDF's expect the output size to be defined in advance.
A XOF - eXtendable-Output Function - can be used by using the key as input for the XOF and defining the random stream as output of the XOF. This is probably the easiest function to use. The input doesn't have to be a particular size and the function was defined to stream out information. The main known XOF's, SHAKE128 and SHAKE256 are however part of the SHA-3 specification and may not be available for all runtimes.
To use your alphanumeric key you first need to convert it into a key that is acceptable to the function that you decide to use. First of all, you'd convert it to binary using character encoding such as ASCII (or UTF-8, which amounts to the same thing).
You may need to use a KDF or hash to generate a key of the right size, in case your DRBG or cipher expects a key of a specific size. In general the leftmost bytes of a hash would also suffice.
In general all of the above are one-way functions so you cannot convert them back to your alphanumeric key apart from brute forcing the alphanumeric key. They all use deterministic (and therefore repeatable) algorithms to generate streams of bytes.
The XOF functions seems to be the main contenders as they are designed for streaming and accepts any size of input data.
AES in counter mode + hash as KDF to create the key - is a very good contender if simply for the reason that it is almost universally available, it's definitely impossible to retrieve the secret key and the output is likely good enough.