Generating Random Numbers to Use as CryptoCard KT-1 Token AES-192 Keys from PHP
Assuming a public algorithm, block ciphers are effective if and only if there is no way for an attacker to narrow the key space. The key space could be narrowed by either a weakness in the algorithm that allows an attacker to narrow the space by analyzing ciphertext messages; or it could be narrowed by some knowledge of how keys have been chosen. It is important to choose token keys in a way that can't be reproduced by an attacker; and where an attacker has no way to narrow the range of keys that might have been chosen.
PHP provides a built-in rand() function that could be used to create token keys. However, the random numbers from PHP's rand() function are pseudo-random rather than random. PHP source code, including the rand() function, is public. If the PHP code intended to generate random keys using PHP's rand() function is also public, an attack making use of the pseudo-random nature of rand() may be possible.
The standard Unix/Linux device /dev/rand is more reliable for the generation of security-critical keys than PHP's built-in rand() function. (/dev/rand makes use of unpredictable events in the computer system to generate random numbers.)
The random hexadecimal number below (192 bits) has been obtained via /dev/rand using PHP (refreshing this page will cause the value to change). Note that /dev/rand will block when the randomness available has been depleted until more randomness can be obtained (this can be observed by reloading the page several times).
With hyphen separators: 2B-57-EB-A1-63-E8-2C-71-9D-A3-9B-F8-EB-8F-5D-89-99-79-CF-C2-18-0A-24-05
Without hyphen separators: 2B57EBA163E82C719DA39BF8EB8F5D899979CFC2180A2405
The source code for this page (illustrating how to use PHP to get data from /dev/rand) is available here.
In the application for which KT-1 tokens are being evaluated (tokens initialized on a Windows system), the random output of a web page (served by a Unix/Linux system) can be copied and pasted into the Windows token initialization application. (For example, the 192-bit random number above could be copied and pasted into a Windows token initialization application.)
Other obvious methods of generating random keys not involving PHP:
Useful reading and background:
This web page is maintained by David T. Ashley. Local time on this server (at the time the page was served) is $today = date("g:i:s a \o\\n F j, Y."); echo $today; ?>