idnits 2.17.00 (12 Aug 2021) /tmp/idnits38101/draft-eastlake-randomness3-00.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** The abstract seems to contain references ([RFC4086]), which it shouldn't. Please replace those with straight textual mentions of the documents in question. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (5 November 2013) is 3112 days in the past. Is this intentional? Checking references for intended status: Best Current Practice ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) == Unused Reference: 'SP800-90A' is defined on line 2019, but no explicit reference was found in the text == Unused Reference: 'SP800-90B' is defined on line 2024, but no explicit reference was found in the text == Unused Reference: 'SP800-90C' is defined on line 2028, but no explicit reference was found in the text -- Obsolete informational reference (is this intentional?): RFC 5246 (Obsoleted by RFC 8446) Summary: 1 error (**), 0 flaws (~~), 4 warnings (==), 2 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 1 Network Working Group Donald E. Eastlake, 3rd 2 INTERNET-DRAFT Huawei 3 Intended status: Best Current Practice Steve Crocker 4 Obsoletes: 4086 Shinkuro 5 Charlie Kaufman 6 Microsoft 7 Jeffrey I. Schiller 8 MIT 9 Expires: 4 May 2014 5 November 2013 11 Randomness Requirements for Security 12 14 Abstract 16 Security systems are built on strong cryptographic algorithms that 17 foil pattern analysis attempts. However, the security of these 18 systems is dependent on generating secret quantities for passwords, 19 cryptographic keys, and similar values. The use of pseudo-random 20 processes to generate secret quantities can result in pseudo- 21 security. For example, the sophisticated attacker of these security 22 systems may find it easier to reproduce the environment that produced 23 the secret quantities, searching a resulting small set of 24 possibilities, than to locate the quantities in the whole of the 25 potential number space. 27 Choosing random quantities to foil a resourceful and motivated 28 adversary can be surprisingly difficult. This document points out 29 many pitfalls in using poor entropy sources or traditional pseudo- 30 random number generation techniques for generating such quantities. 31 It recommends the use of multiple sources with a strong mixing 32 function, so that no single source need be fully trusted, and 33 provides techniques for extending a random seed to a larger quantity 34 of pseudo-random material in a cryptographically secure way. And it 35 gives examples of how large such quantities need to be for some 36 applications. This document obsoletes RFC 4086. 38 Status of This Document 40 This Internet-Draft is submitted to IETF in full conformance with the 41 provisions of BCP 78 and BCP 79. This document is intended to be a 42 Best Current Practice. Comments should be sent to the authors. 43 Distribution is unlimited. 45 Internet-Drafts are working documents of the Internet Engineering 46 Task Force (IETF), its areas, and its working groups. Note that 47 other groups may also distribute working documents as Internet- 48 Drafts. 50 Internet-Drafts are draft documents valid for a maximum of six months 51 and may be updated, replaced, or obsoleted by other documents at any 52 time. It is inappropriate to use Internet-Drafts as reference 53 material or to cite them other than as "work in progress." 55 The list of current Internet-Drafts can be accessed at 56 http://www.ietf.org/1id-abstracts.html. The list of Internet-Draft 57 Shadow Directories can be accessed at 58 http://www.ietf.org/shadow.html. 60 Acknowledgements 62 The following other persons (in alphabetic order) have also 63 contributed substantially to this document: 65 tbd 67 Special thanks to Paul Hoffman and John Kelsey for their extensive 68 comments on [RFC4086] and to Peter Gutmann, who has permitted the 69 incorporation of material from his paper "Software Generation of 70 Practically Strong Random Numbers". 72 The following persons (in alphabetic order) contributed to RFC 1750 73 and/or [RFC4086] the predecessors of this document. [RFC4086] 74 obsoleted RFC 1750. 76 David M. Balenson, Steve Bellovin, Daniel Brown, Don T. Davis, 77 Carl Ellison, Peter Gutmann, Neil Haller, Tony Hansen, Sandy 78 Harris, Paul Hoffman, Scott Hollenback, Marc Horowitz, Russ 79 Housley, Christian Huitema, Charlie Kaufman, John Kelsey, Steve 80 Kent, Hal Murray, Mats Naslund, Richard Pitkin, Damir Rajnovic, 81 Tim Redmond, and Doug Tygar. 83 1. Introduction and Overview...............................5 84 2. General Requirements....................................6 86 3. Entropy Sources.........................................9 87 3.1 Volume Required........................................9 88 3.2 Existing Hardware Can Be Used For Randomness..........10 89 3.2.1 Using Existing Sound/Video Input....................10 90 3.2.2 Using Existing Disk Drives..........................10 91 3.2.3 On Chip Random Sources..............................11 92 3.3 Ring Oscillator Sources...............................11 93 3.4 Problems with Clocks and Serial Numbers...............12 94 3.5 Timing and Value of External Events...................13 95 3.6 Non-Hardware Sources of Randomness....................14 97 4. De-skewing.............................................15 98 4.1 Using Stream Parity to De-Skew........................15 99 4.2 Using Transition Mappings to De-Skew..................16 100 4.3 Using FFT to De-Skew..................................17 101 4.4 Using Compression to De-Skew..........................18 103 5. Mixing.................................................19 104 5.1 A Trivial Mixing Function.............................19 105 5.2 Stronger Mixing Functions.............................20 106 5.3 Using S-Boxes for Mixing..............................22 107 5.4 Diffie-Hellman as a Mixing Function...................22 108 5.5 Using a Mixing Function to Stretch Random Bits........22 109 5.6 Other Factors in Choosing a Mixing Function...........23 111 6. Pseudo Random Number Generators........................24 112 6.1 Some Bad Ideas........................................24 113 6.1.1 The Fallacy of Complex Manipulation.................24 114 6.1.2 The Fallacy of Selection from a Large Database......25 115 6.1.3. Traditional Pseudo-Random Sequences................25 116 6.2 Cryptographically Strong Sequences....................27 117 6.2.1 OFB and CTR Sequences...............................28 118 6.2.2 The Blum Blum Shub Sequence Generator...............29 119 6.3 Entropy Pool Techniques...............................30 121 7. Randomness Generation Examples and Standards...........32 122 7.1 Randomness Generators.................................32 123 7.1.1 US DoD Recommendations for Password Generation......32 124 7.1.2 The /dev/random Device..............................33 125 7.1.3 Windows CryptGenRandom..............................34 126 7.2 Generators Assuming a Source of Entropy...............35 127 7.2.1 X9.82 Pseudo-Random Number Generation...............35 128 7.2.1.1 Notation..........................................35 129 7.1.2.2 Initializing the Generator........................36 130 7.1.2.5 Generating Random Bits............................36 131 7.2.2 X9.17 Key Generation................................36 132 7.2.3 DSS Pseudo-Random Number Generation.................37 134 8. Examples of Randomness Required........................39 135 8.1 Password Generation..................................39 136 8.2 A Very High Security Cryptographic Key................40 137 8.2.1 Effort per Key Trial................................40 138 8.2.2 Meet in the Middle Attacks..........................41 139 8.2.3 Other Considerations................................42 141 9. Conclusion.............................................43 143 10. Security Considerations...............................44 144 11. IANA Considerations...................................44 146 Informative References....................................45 147 Appendix A: Changes from [RFC4086]........................51 149 Author's Addresses........................................52 151 1. Introduction and Overview 153 Cryptography is coming into wider use and is continuing to spread, 154 although there is a long way to go until it becomes ubiquitous. 155 Systems like SIDR, SSH [RFC4251], TLS [RFC5246], IP Security 156 [RFC4301], S/MIME, DNS Security [DNSSEC], Kerberos, etc. are maturing 157 and becoming a part of the network landscape [SIDR, MAIL*]. 159 These systems provide substantial protection against snooping and 160 spoofing. However, there is a potential flaw. At the heart of all 161 cryptographic systems is the generation of secret, unguessable (i.e., 162 random) numbers. 164 Facilities for generating such random numbers, that is, the 165 availability of truly unpredictable sources, is spotty and in some 166 cases the quality is questionable. And even when the quality is, in 167 theory, excellent, there is always the risk that the facilities may 168 have been corrupted by and adversary. For example, there have been 169 indications that nation states have corrupted hardware random number 170 generators. 172 This is open wound in the design of cryptographic systems and 173 software. For the developer who wants to build a key or password 174 generation procedure that runs on a wide range of systems, this can 175 be a real problem. 177 It is important to keep in mind that the requirement is for data that 178 an adversary has a very low probability of guessing or determining. 179 This can easily fail if pseudo-random data is used which only meets 180 traditional statistical tests for randomness or which is based on 181 limited range sources, such as clocks. Sometimes such pseudo-random 182 quantities are determinable by an adversary searching through an 183 embarrassingly small space of possibilities. 185 This Best Current Practice describes techniques for producing random 186 quantities that will be resistant to such attack. It recommends that 187 systems combine inputs from a number of potentially good randomness 188 sources, including hardware based random number sources. And it gives 189 some estimates of the number of random bits required for sample 190 applications. 192 2. General Requirements 194 A commonly encountered randomness requirement today is the user 195 password. This is usually a simple character string. Obviously, if a 196 password can be guessed, it does not provide security. (For re-usable 197 passwords, it is desirable that users be able to remember the 198 password. This may make it advisable to use pronounceable character 199 strings or phrases composed on ordinary words. But this only affects 200 the format of the password information, not the requirement that the 201 password be very hard to guess.) 203 Many other requirements come from the cryptographic arena. 204 Cryptographic techniques can be used to provide a variety of services 205 including confidentiality and authentication. Such services are based 206 on quantities, traditionally called "keys", that are unknown to and 207 unguessable by an adversary. 209 There are even TCP/IP protocol uses for randomness in picking initial 210 sequence numbers [RFC6528]. 212 In some cases, such as the use of symmetric encryption with the one 213 time pads or an algorithm like the US Advanced Encryption Standard 214 [AES], the parties who wish to communicate confidentially and/or with 215 authentication must all know the same secret key. In other cases, 216 using what are called asymmetric or "public key" cryptographic 217 techniques, keys come in pairs. One key of the pair is private and 218 must be kept secret by one party, the other is public and can be 219 published to the world. It is computationally infeasible to determine 220 the private key from the public key and knowledge of the public is of 221 no help to an adversary [ASYMMETRIC]. [SCHNEIER, FERGUSON, KAUFMAN] 223 The frequency and volume of the requirement for random quantities 224 differs greatly for different cryptographic systems. Using pure RSA, 225 random quantities are required only when a new key pair is generated; 226 thereafter any number of messages can be signed without a further 227 need for randomness. The public key Digital Signature Algorithm 228 devised by the US National Institute of Standards and Technology 229 (NIST) requires good random numbers for each signature [DSS]. Such 230 algorithms, with a high requirement for good randomness generation, 231 should be avoided and some believe that this weakness in DSA was 232 introduced to make it easier to break based on the use of poor random 233 numbers. Encrypting with a one time pad, in principle the strongest 234 possible encryption technique, requires a volume of randomness equal 235 to all the messages to be processed and, in fact, in the [VENONA] 236 project, old messages encrypted with poor quality or re-used "one 237 time" pads have been broken. [SCHNEIER, FERGUSON, KAUFMAN] 239 In most of these cases, an adversary can try to determine a "secret" 240 key by trial and error. (This is possible as long as the key is 241 enough smaller than the message that the correct key can be uniquely 242 identified.) The probability of an adversary succeeding at this must 243 be made acceptably low, depending on the particular application. The 244 size of the space the adversary must search is related to the amount 245 of key "information" present in an information theoretic sense 246 [SHANNON]. This depends on the number of different secret values 247 possible and the probability of each value as follows: 249 ----- 250 \ 251 Bits-of-information = \ - p * log ( p ) 252 / i 2 i 253 / 254 ----- 256 where i counts from 1 to the number of possible secret values and p 257 sub i is the probability of the value numbered i. (Since p sub i is 258 less than one, the log will be negative so each term in the sum will 259 be non-negative.) 261 If there are 2^n different values of equal probability, then n bits 262 of information are present and an adversary would, on the average, 263 have to try half of the values, or 2^(n-1) , before guessing the 264 secret quantity. If the probability of different values is unequal, 265 then there is less information present and fewer guesses will, on 266 average, be required by an adversary. In particular, any values that 267 the adversary can know are impossible, or are of low probability, can 268 be initially ignored by an adversary, who will search through the 269 more probable values first. 271 For example, consider a cryptographic system that uses 128 bit keys. 272 If these 128 bit keys are derived by using a fixed pseudo-random 273 number generator that is seeded with an 8 bit seed, then an adversary 274 needs to search through only 256 keys (by running the pseudo-random 275 number generator with every possible seed), not the 2^128 keys that 276 may at first appear to be the case. Only 8 bits of "information" are 277 in these 128 bit keys. 279 While the above analysis is correct on average, it can be misleading 280 in some cases for cryptographic analysis where what is really 281 important is the work factor for an adversary. For example, assume 282 that there was a pseudo-random number generator generating 128 bit 283 keys, as in the previous paragraph, but that it generated 0 half of 284 the time and a random selection from the remaining 2**128 - 1 values 285 the rest of the time. The Shannon equation above says that there are 286 64 bits of information in one of these key values but an adversary, 287 by simply trying the values 0, can break the security of half of the 288 uses, albeit a random half. Thus for cryptographic purposes, it is 289 also useful to look at other measures, such as min-entropy, defined 290 as 291 Min-entropy = - log ( maximum ( p ) ) 292 i 294 where i is as above. Using this equation, we get 1 bit of min- 295 entropy for our new hypothetical distribution as opposed to 64 bits 296 of classical Shannon entropy. 298 A continuous spectrum of entropies, sometimes called Renyi entropy, 299 have been defined, specified by a parameter r. When r = 1, it is 300 Shannon entropy, and with r = infinity, it is min-entropy. When r = 301 0, it is just log (n) where n is the number of non-zero 302 probabilities. Renyi entropy is a non-increasing function of r, so 303 min-entropy is always the most conservative measure of entropy and 304 usually the best to use for cryptographic evaluation. [LUBY] 306 Statistically tested randomness in the traditional sense is NOT the 307 same as the unpredictability required for security use. 309 For example, use of a widely available constant sequence, such as 310 that from the CRC tables, is very weak against an adversary. Once 311 they learn of or guess it, they can easily break all security, future 312 and past, based on the sequence. [CRC] As another example, using AES 313 to encrypt successive integers such as 1, 2, 3 ... with a known key 314 will also produce output that has excellent statistical randomness 315 properties but is also predictable. On the other hand, taking 316 successive rolls of a six-sided die and encoding the resulting values 317 in ASCII would produce statistically poor output with a substantial 318 unpredictable component. So you should keep in mind that passing or 319 failing statistical tests doesn't tell you that something is 320 unpredictable or predictable. 322 3. Entropy Sources 324 Entropy sources tend to be implementation dependent. Once one has 325 gathered sufficient entropy it can be used as the seed to produce the 326 required amount of cryptographically strong pseudo-randomness, as 327 described in Sections 6 and 7, after being de-skewed and/or mixed if 328 necessary as described in Sections 4 and 5. 330 Is there any hope for true strong portable randomness in the future? 331 There might be. In theory, all that's needed is a physical source of 332 unpredictable numbers. 334 A thermal noise (sometimes called Johnson noise in integrated 335 circuits) or radioactive decay source and a fast, free-running 336 oscillator should do the trick directly [GIFFORD]. This is a trivial 337 amount of hardware, and could easily be included as a standard part 338 of a computer system's architecture. Most audio (or video) input 339 devices are useable [TURBID]. Furthermore, any system with a 340 spinning disk or ring oscillator and a stable (crystal) time source 341 or the like has an adequate source of randomness ([DAVIS] and Section 342 3.3). All that's needed is the common perception among computer 343 vendors that this small additional hardware and the software to 344 access it is necessary and useful. 346 ANSI X9 is currently developing a standard that includes a part 347 devoted to entropy sources. See [X9.82 - Part 2]. 349 3.1 Volume Required 351 How much unpredictability is needed? Is it possible to quantify the 352 requirement in, say, number of random bits per second? 354 The answer is not very much is needed. For AES, the key can be 128 355 bits and, as we show in an example in Section 8, even the highest 356 security system is unlikely to require strong keying material of much 357 over 200 bits. If a series of keys are needed, they can be generated 358 from a strong random seed (starting value) using a cryptographically 359 strong sequence as explained in Section 6.2. A few hundred random 360 bits generated at start up or once a day would be enough using such 361 techniques. Even if the random bits are generated as slowly as one 362 per second and it is not possible to overlap the generation process, 363 it should be tolerable in most high security applications to wait 200 364 seconds occasionally. 366 These numbers are trivial to achieve. It could be done by a person 367 repeatedly tossing a coin. Almost any hardware-based process is 368 likely to be much faster. 370 3.2 Existing Hardware Can Be Used For Randomness 372 As described below, many computers come with hardware that can, with 373 care, be used to generate truly random quantities. 375 3.2.1 Using Existing Sound/Video Input 377 Many computers are built with inputs that digitize some real world 378 analog source, such as sound from a microphone or video input from a 379 camera. Under appropriate circumstances, such input can provide 380 reasonably high quality random bits. The "input" from a sound 381 digitizer with no source plugged in or a camera with the lens cap on, 382 if the system has enough gain to detect anything, is essentially 383 thermal noise. This method is very hardware and implementation 384 dependent. 386 For example, on some UNIX based systems, one can read from the 387 /dev/audio device with nothing plugged into the microphone jack or 388 the microphone receiving only low-level background noise. Such data 389 is essentially random noise although it should not be trusted without 390 some checking in case of hardware failure. It will, in any case, 391 need to be de-skewed as described elsewhere. 393 Combining this with compression to de-skew (see Section 4) one can, 394 in UNIXese, generate a huge amount of medium quality random data by 395 doing 397 cat /dev/audio | compress - >random-bits-file 399 A detailed examination of this type of randomness source appears in 400 [TURBID]. 402 3.2.2 Using Existing Disk Drives 404 Disk drives have small random fluctuations in their rotational speed 405 due to chaotic air turbulence [DAVIS, Jakobsson]. By adding low 406 level disk seek time instrumentation to a system, a series of 407 measurements can be obtained that include this randomness. Such data 408 is usually highly correlated so that significant processing is 409 needed, such as described in 5.2 below. Nevertheless experimentation 410 over 15 years ago showed that, with such processing, even slow disk 411 drives on the slower computers of that day could easily produce 100 412 bits a minute or more of excellent random data. 414 Every increase in processor speed, which increases the resolution 415 with which disk motion can be timed, or increase in the rate of disk 416 seeks, increases the rate of random bit generation possible with this 417 technique. At the time of [RFC4086] (2005) and using modern hardware, 418 a more typical rate of random bit production would be in excess of 419 10,000 bits a second. This technique is used in many operating system 420 library random number generators. 422 Note: the inclusion of cache memories in disk controllers has little 423 effect on this technique if very short seek times, which represent 424 cache hits, are simply ignored. 426 It is important to ensure you are using a true spinning disk drive. 427 Many modern computers come equipped with Solid State Disk Drives 428 (SSDs) which have no moving parts. With no moving parts there is no 429 spinning disk to provide the random fluctuations. 431 3.2.3 On Chip Random Sources 433 Some modern processors contain an on-chip hardware random number 434 generators. For example newer Intel processors include a "rdrand" 435 instruction that provides random data. 437 Because exactly how this randomness is derived is not always 438 disclosed by the hardware manufacturer, it should not be relied upon 439 as the sole source of entropy for sensitive applications. 441 In theory on-chip generators can provide a high speed source of 442 entropy. As such they are ideal for situations where cryptographic 443 strength is not essential, for example choosing TCP starting segment 444 numbers and similar protocol nonces. 446 3.3 Ring Oscillator Sources 448 If an integrated circuit is being designed or field programmed, an 449 odd number of gates can be connected in series to produce a free- 450 running ring oscillator. By sampling a point in the ring at a fixed 451 frequency, say one determined by a stable crystal oscillator, some 452 amount of entropy can be extracted due to variations in the free- 453 running oscillator timing. It is possible to increase the rate of 454 entropy by xor'ing sampled values from a few ring oscillators with 455 relatively prime lengths. It is sometimes recommended that an odd 456 number of rings be used so that, even if the rings somehow become 457 synchronously locked to each other, there will still be sampled bit 458 transitions. Another possibility source to sample is the output of a 459 noisy diode. 461 Sampled bits from such sources will have to be heavily de-skewed, as 462 disk rotation timings must be (see Section 4). An engineering study 463 would be needed to determine the amount of entropy being produced 464 depending on the particular design. In any case, these can be good 465 sources whose cost is a trivial amount of hardware by modern 466 standards. 468 As an example, IEEE Std. 802.11-2012 suggests that the circuit below 469 be considered, with due attention in the design to isolation of the 470 rings from each other and from clocked circuits to avoid undesired 471 synchronization, etc., and extensive post processing. [IEEE802.11] 473 |\ |\ |\ 474 +-->| >0-->| >0-- 19 total --| >0--+-------+ 475 | |/ |/ |/ | | 476 | | | 477 +----------------------------------+ V 478 +-----+ 479 |\ |\ |\ | | output 480 +-->| >0-->| >0-- 23 total --| >0--+--->| XOR |------> 481 | |/ |/ |/ | | | 482 | | +-----+ 483 +----------------------------------+ ^ ^ 484 | | 485 |\ |\ |\ | | 486 +-->| >0-->| >0-- 29 total --| >0--+------+ | 487 | |/ |/ |/ | | 488 | | | 489 +----------------------------------+ | 490 | 491 other randomness if available--------------+ 493 3.4 Problems with Clocks and Serial Numbers 495 Computer clocks, or similar operating system or hardware values, 496 provide significantly fewer real bits of unpredictability than might 497 appear from their specifications. 499 Tests have been done on clocks on numerous systems and it was found 500 that their behavior can vary widely and in unexpected ways. One 501 version of an operating system running on one set of hardware may 502 actually provide, say, microsecond resolution in a clock while a 503 different configuration of the "same" system may always provide the 504 same lower bits and only count in the upper bits at much lower 505 resolution. This means that successive reads on the clock may produce 506 identical values even if enough time has passed that the value 507 "should" change based on the nominal clock resolution. There are also 508 cases where frequently reading a clock can produce artificial 509 sequential values because of extra code that checks for the clock 510 being unchanged between two reads and increases it by one! Designing 511 portable application code to generate unpredictable numbers based on 512 such system clocks is particularly challenging because the system 513 designer does not always know the properties of the system clocks 514 that the code will execute on. 516 Use of hardware serial numbers such as an Ethernet MAC addresses may 517 also provide fewer bits of uniqueness than one would guess. Such 518 quantities are usually heavily structured and subfields may have only 519 a limited range of possible values or values easily guessable based 520 on approximate date of manufacture or other data. For example, it is 521 likely that a company that manufactures both computers and Ethernet 522 adapters will, at least internally, use its own adapters, which 523 significantly limits the range of built-in addresses due to the use 524 of their OUI (Organizationally Unique Identifier [RFC7042]) as upper 525 bits of the MAC address. 527 Problems such as those described above related to clocks and serial 528 numbers make code to produce unpredictable quantities difficult if 529 the code is to be ported across a variety of computer platforms and 530 systems. 532 3.5 Timing and Value of External Events 534 It is possible to measure the timing and content of mouse movement, 535 keystrokes, and similar user events. This is a reasonable source of 536 unguessable data with some qualifications. On some machines, inputs 537 such as key strokes are buffered. Even though the user's inter- 538 keystroke timing may have sufficient variation and unpredictability, 539 there might not be an easy way to access that variation. Another 540 problem is that no standard method exists to sample timing details. 541 This makes it hard to build standard software intended for 542 distribution to a large range of machines based on this technique. 544 The amount of mouse movement or the keys actually hit are usually 545 easier to access than timings but may yield less unpredictability as 546 the user may provide highly repetitive input. 548 Other external events, such as network packet arrival times and 549 lengths, can also be used, but only with care. In particular, the 550 possibility of manipulation of such network traffic measurements by 551 an adversary and the lack of history at system start up must be 552 carefully considered. If this input is subject to manipulation, it 553 must not be trusted as a source of entropy. 555 Indeed, almost any external sensor, such as raw radio reception or 556 temperature sensing in appropriately equipped computers, can be used 557 in principle. But in each case careful consideration must be given to 558 how much such data is subject to adversarial manipulation and to how 559 much entropy it can actually provide. 561 The above techniques are quite powerful against any attackers having 562 no access to the quantities being measured. For example, they would 563 be powerful against offline attackers who had no access to your 564 environment and were trying to crack your random seed after the fact. 565 In all cases, the more accurately you can measure the timing or value 566 of an external sensor, the more rapidly you can generate bits. 568 3.6 Non-Hardware Sources of Randomness 570 The best single source of input entropy would be a hardware 571 randomness such as ring oscillators, disk drive timing, thermal 572 noise, or radioactive decay. However, there are other possibilities 573 which can be used instead or can be mixed with hardware randomness. 574 These include system clocks, system or input/output buffers, 575 user/system/hardware/network serial numbers and/or addresses and 576 timing, and user input. Unfortunately, each limited these non- 577 hardware sources can produce very limited or predictable values under 578 some circumstances. 580 Some of the sources listed above would be quite strong on multi-user 581 systems where, in essence, each user of the system is a source of 582 randomness. However, on a small single user or embedded system, 583 especially at start up, it might be possible for an adversary to 584 assemble a similar configuration. This could give the adversary 585 inputs to the mixing process that were sufficiently correlated to 586 those used originally as to make exhaustive search practical. 588 The use of multiple random inputs with a strong mixing function is 589 recommended and can overcome weakness in any particular input. The 590 timing and content of requested "random" user keystrokes can yield 591 hundreds of random bits but conservative assumptions need to be made. 592 For example, assuming at most a few bits of randomness if the inter- 593 keystroke interval is unique in the sequence up to that point and a 594 similar assumption if the key hit is unique but assuming that no bits 595 of randomness are present in the initial key value or if the timing 596 or key value duplicate previous values. The results of mixing these 597 timings and characters typed could be further combined with clock 598 values and other inputs. 600 This strategy may make practical portable code to produce good random 601 numbers for security even if some of the inputs are weak on some of 602 the target systems. However, it may still fail against a high grade 603 attack on small, single user or embedded systems, especially if the 604 adversary has ever been able to observe the generation process in the 605 past. A hardware based random source is still preferable. 607 4. De-skewing 609 Is there any specific requirement on the shape of the distribution of 610 quantities gathered for the entropy to produce the random numbers? 611 The good news is the distribution need not be uniform. All that is 612 needed is a conservative estimate of how non-uniform it is to bound 613 performance. Simple techniques to de-skew a bit stream are given 614 below and stronger cryptographic techniques are described in Section 615 5.2 below. 617 4.1 Using Stream Parity to De-Skew 619 As a simple but not particularly practical example, consider taking a 620 sufficiently long string of bits and map the string to "zero" or 621 "one". The mapping will not yield a perfectly uniform distribution, 622 but it can be as close as desired. One mapping that serves the 623 purpose is to take the parity of the string. This has the advantages 624 that it is robust across all degrees of skew up to the estimated 625 maximum skew and is absolutely trivial to implement in hardware. 627 The following analysis gives the number of bits that must be sampled: 629 Suppose the ratio of ones to zeros is ( 0.5 + E ) to ( 0.5 - E ), 630 where E is between 0 and 0.5 and is a measure of the "eccentricity" 631 of the distribution. Consider the distribution of the parity function 632 of N bit samples. The probabilities that the parity will be one or 633 zero will be the sum of the odd or even terms in the binomial 634 expansion of (p + q)^N, where p = 0.5 + E, the probability of a one, 635 and q = 0.5 - E, the probability of a zero. 637 These sums can be computed easily as 639 N N 640 1/2 * ( ( p + q ) + ( p - q ) ) 641 and 642 N N 643 1/2 * ( ( p + q ) - ( p - q ) ). 645 (Which one corresponds to the probability the parity will be 1 646 depends on whether N is odd or even.) 648 Since p + q = 1 and p - q = 2e, these expressions reduce to 650 N 651 1/2 * [1 + (2E) ] 652 and 653 N 654 1/2 * [1 - (2E) ]. 656 Neither of these will ever be exactly 0.5 unless E is zero, but we 657 can bring them arbitrarily close to 0.5. If we want the probabilities 658 to be within some delta d of 0.5, i.e. then 660 N 661 ( 0.5 + ( 0.5 * (2E) ) ) < 0.5 + d. 663 Solving for N yields N > log(2d)/log(2E). (Note that 2E is less than 664 1, so its log is negative. Division by a negative number reverses the 665 sense of an inequality.) 667 The following table gives the length of the string that must be 668 sampled for various degrees of skew in order to come within 0.001 of 669 a 50/50 distribution. 671 +---------+--------+-------+ 672 | Prob(1) | E | N | 673 +---------+--------+-------+ 674 | 0.5 | 0.00 | 1 | 675 | 0.6 | 0.10 | 4 | 676 | 0.7 | 0.20 | 7 | 677 | 0.8 | 0.30 | 13 | 678 | 0.9 | 0.40 | 28 | 679 | 0.95 | 0.45 | 59 | 680 | 0.99 | 0.49 | 308 | 681 +---------+--------+-------+ 683 The last entry shows that even if the distribution is skewed 99% in 684 favor of ones, the parity of a string of 308 samples will be within 685 0.001 of a 50/50 distribution. But, as we shall see in section 6.1.2, 686 there are much stronger techniques that extract more of the available 687 entropy. 689 4.2 Using Transition Mappings to De-Skew 691 Another technique, originally due to von Neumann [VON NEUMANN], is to 692 examine a bit stream as a sequence of non-overlapping pairs. You 693 could then discard any 00 or 11 pairs found, interpret 01 as a 0 and 694 10 as a 1. Assume the probability of a 1 is 0.5+E and the probability 695 of a 0 is 0.5-E where E is the eccentricity of the source and 696 described in the previous section. Then the probability of each pair 697 is as follows: 699 +------+-----------------------------------------+ 700 | pair | probability | 701 +------+-----------------------------------------+ 702 | 00 | (0.5 - E)^2 = 0.25 - E + E^2 | 703 | 01 | (0.5 - E)*(0.5 + E) = 0.25 - E^2 | 704 | 10 | (0.5 + E)*(0.5 - E) = 0.25 - E^2 | 705 | 11 | (0.5 + E)^2 = 0.25 + E + E^2 | 706 +------+-----------------------------------------+ 708 This technique will completely eliminate any bias but at the expense 709 of taking an indeterminate number of input bits for any particular 710 desired number of output bits. The probability of any particular pair 711 being discarded is 0.5 + 2E^2 so the expected number of input bits to 712 produce X output bits is X/(0.25 - E^2). 714 This technique assumes that the bits are from a stream where each bit 715 has the same probability of being a 0 or 1 as any other bit in the 716 stream and that bits are not correlated, i.e., that the bits are 717 identical independent distributions. If alternate bits were from two 718 correlated sources, for example, the above analysis breaks down. 720 The above technique also provides another illustration of how a 721 simple statistical analysis can mislead if one is not always on the 722 lookout for patterns that could be exploited by an adversary. If the 723 algorithm were mis-read slightly so that overlapping successive bits 724 pairs were used instead of non-overlapping pairs, the statistical 725 analysis given is the same; however, instead of providing an unbiased 726 uncorrelated series of random 1s and 0s, it instead produces a 727 totally predictable sequence of exactly alternating 1s and 0s. 729 4.3 Using FFT to De-Skew 731 When real world data consists of strongly correlated bits, it may 732 still contain useful amounts of entropy. This entropy can be 733 extracted through use of various transforms, the most powerful of 734 which are described in section 5.2 below. 736 Using the Fourier transform of the data or its optimized variant, the 737 FFT, is an technique interesting primarily for theoretical reasons. 738 It can be show that this will discard strong correlations. If 739 adequate data is processed and remaining correlations decay, spectral 740 lines approaching statistical independence and normally distributed 741 randomness can be produced [BRILLINGER]. 743 4.4 Using Compression to De-Skew 745 Reversible compression techniques also provide a crude method of de- 746 skewing a skewed bit stream. This follows directly from the 747 definition of reversible compression and Shannon's formula in Section 748 2 above for the amount of information in a sequence. Since the 749 compression is reversible, the same amount of information must be 750 present in the shorter output than was present in the longer input. 751 By the Shannon information equation, this is only possible if, on 752 average, the probabilities of the different shorter sequences are 753 more uniformly distributed than were the probabilities of the longer 754 sequences. Therefore the shorter sequences must be de-skewed relative 755 to the input. 757 However, many compression techniques add a somewhat predictable 758 preface to their output stream and may insert such a sequence again 759 periodically in their output or otherwise introduce subtle patterns 760 of their own. They should be considered only a rough technique 761 compared with those described in Section 5.2. At a minimum, the 762 beginning of the compressed sequence should be skipped and only later 763 bits used for applications requiring roughly random bits. 765 5. Mixing 767 What is the best overall strategy for meeting the requirement for 768 unguessable random numbers? It is to obtain input from a number of 769 uncorrelated sources including hardware and to mix them with a strong 770 mixing function. Such a function will preserve the entropy present in 771 any of the sources even if other quantities being combined happen to 772 be fixed or easily guessable (low entropy). This is advisable even 773 with a theoretically good hardware source, as hardware can also fail 774 or the implementation of the hardware could have been corrupted by an 775 adversary with sufficient resources, for example a nation state. 777 Once you have used good sources, such as some of those listed in 778 Section 3, and mixed them as described in this section, you have a 779 strong seed. This can then be used to produce large quantities of 780 cryptographically strong material as described in Sections 6 and 7. 782 A strong mixing function is one which combines inputs and produces an 783 output where each output bit is a different complex non-linear 784 function of all the input bits. On average, changing any input bit 785 will change about half the output bits. But because the relationship 786 is complex and non-linear, no particular output bit is guaranteed to 787 change when any particular input bit is changed. 789 Consider the problem of converting a stream of bits that is skewed 790 towards 0 or 1 or which has a somewhat predictable pattern to a 791 shorter stream that is more random, as discussed in Section 4 above. 792 This is simply another case where a strong mixing function is 793 desired, mixing the input bits to produce a smaller number of output 794 bits. The technique given in Section 4.1 of using the parity of a 795 number of bits is simply the result of successively Exclusive Or'ing 796 them which is examined as a trivial mixing function immediately 797 below. Use of stronger mixing functions to extract more of the 798 randomness in a stream of skewed bits is examined in Section 5.2. See 799 also [NASLUND]. 801 5.1 A Trivial Mixing Function 803 A trivial example for single bit inputs described only for expository 804 purposes is the Exclusive Or function, which is equivalent to 805 addition without carry, as show in the table below. This is a 806 degenerate case in which the one output bit always changes for a 807 change in either input bit. But, despite its simplicity, it provides 808 a useful illustration. 810 +-----------+-----------+----------+ 811 | input 1 | input 2 | output | 812 +-----------+-----------+----------+ 813 | 0 | 0 | 0 | 814 | 0 | 1 | 1 | 815 | 1 | 0 | 1 | 816 | 1 | 1 | 0 | 817 +-----------+-----------+----------+ 819 If inputs 1 and 2 are uncorrelated and combined in this fashion then 820 the output will be an even better (less skewed) random bit than the 821 inputs. If we assume an "eccentricity" E as defined in Section 4.1, 822 then the output eccentricity relates to the input eccentricity as 823 follows: 825 E = 2 * E * E 826 output input 1 input 2 828 Since E is never greater than 1/2, the eccentricity is always 829 improved except in the case where at least one input is a totally 830 skewed constant. This is illustrated in the following table where the 831 top and left side values are the two input eccentricities and the 832 entries are the output eccentricity: 834 +--------+--------+--------+--------+--------+--------+--------+ 835 | E | 0.00 | 0.10 | 0.20 | 0.30 | 0.40 | 0.50 | 836 +--------+--------+--------+--------+--------+--------+--------+ 837 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 838 | 0.10 | 0.00 | 0.02 | 0.04 | 0.06 | 0.08 | 0.10 | 839 | 0.20 | 0.00 | 0.04 | 0.08 | 0.12 | 0.16 | 0.20 | 840 | 0.30 | 0.00 | 0.06 | 0.12 | 0.18 | 0.24 | 0.30 | 841 | 0.40 | 0.00 | 0.08 | 0.16 | 0.24 | 0.32 | 0.40 | 842 | 0.50 | 0.00 | 0.10 | 0.20 | 0.30 | 0.40 | 0.50 | 843 +--------+--------+--------+--------+--------+--------+--------+ 845 However, keep in mind that the above calculations assume that the 846 inputs are not correlated. If the inputs were, say, the parity of the 847 number of minutes from midnight on two clocks accurate to a few 848 seconds, then each might appear random if sampled at random intervals 849 much longer than a minute. Yet if they were both sampled and combined 850 with xor, the result would be zero most of the time. 852 5.2 Stronger Mixing Functions 854 The US Government Advanced Encryption Standard [AES] is an example of 855 a strong mixing function for multiple bit quantities. It takes up to 856 384 bits of input (128 bits of "data" and 256 bits of "key") and 857 produces 128 bits of output each of which is dependent on a complex 858 non-linear function of all input bits. Other encryption functions 859 with this characteristic can also be used by considering them to mix 860 all of their key and data input bits. 862 Another good family of mixing functions are hashing functions such as 863 The US Government Secure Hash Standards [SHS] and newly selected 864 [KECCAK] series. These functions all take a practically unlimited 865 amount of input and produce a relatively short fixed length output 866 mixing all the input bits. (Previous RFCs on this topic also listed 867 the MD* series algorithms such as MD4 and MD5 [RFC1321] but their use 868 and the use of SHA-1 (or SHA-0) is no longer encouraged [RFC6151] 869 [RFC6194].) 871 Although the message digest functions are designed for variable 872 amounts of input, AES and other encryption functions can also be used 873 to combine any number of inputs. If 128 bits of output is adequate, 874 the inputs can be packed into a 128-bit data quantity and successive 875 AES keys, padding with zeros if needed, which are then used to 876 successively encrypt using AES in Electronic Codebook Mode. Or the 877 input could be packed into one 128-bit key and multiple data blocks 878 and a CBC-MAC calculated [MODES]. 880 If more than 128 bits of output are needed and you want to employ 881 AES, use more complex mixing. But keep in mind that it is absolutely 882 impossible to get more bits of "randomness" out than are put in. For 883 example, if inputs are packed into three quantities, A, B, and C, use 884 AES to encrypt A with B as a key and then with C as a key to produce 885 the 1st part of the output, then encrypt B with C and then A for more 886 output and, if necessary, encrypt C with A and then B for yet more 887 output. Still more output can be produced by reversing the order of 888 the keys given above to stretch things. The same can be done with the 889 hash functions by hashing various subsets of the input data or 890 different copies of the input data with different prefixes and/or 891 suffixes to produce multiple outputs. 893 An example of using a strong mixing function would be to reconsider 894 the case of a string of 308 bits each of which is biased 99% towards 895 zero. The parity technique given in Section 4.1 above reduced this to 896 one bit with only a 1/1000 deviance from being equally likely a zero 897 or one. But, applying the equation for information given in Section 898 2, this 308 bit skewed sequence has over 5 bits of information in it. 899 Thus hashing it with SHA-1 and taking the bottom 5 bits of the result 900 would yield 5 unbiased random bits as opposed to the single bit given 901 by calculating the parity of the string. Alternatively, for some 902 applications, you could use the entire hash output to retain almost 903 all of the 5+ bits of entropy in a 160 bit quantity. 905 5.3 Using S-Boxes for Mixing 907 Many block encryption functions, including AES, incorporate modules 908 known as S-Boxes (substitution boxes). These produce a smaller number 909 of outputs from a larger number of inputs through a complex non- 910 linear mixing function that would have the effect of concentrating 911 limited entropy in the inputs into the output. 913 S-Boxes sometimes incorporate bent Boolean functions (functions of an 914 even number of bits producing one output bit with maximum non- 915 linearity). Looking at the output for all input pairs differing in 916 any particular bit position, exactly half the outputs are different. 917 An S-Box in which each output bit is produced by a bent function such 918 that any linear combination of these functions is also a bent 919 function is called a "perfect S-Box". 921 S-boxes and various repeated application or cascades of such boxes 922 can be used for mixing. [SBOX] 924 5.4 Diffie-Hellman as a Mixing Function 926 Diffie-Hellman exponential key exchange is a technique that yields a 927 shared secret between two parties that can be made computationally 928 infeasible for a third party to determine even if they can observe 929 all the messages between the two communicating parties. This shared 930 secret is a mixture of initial quantities generated by each of the 931 parties [D-H]. 933 If these initial quantities are random and uncorrelated, then the 934 shared secret combines their entropy, but, of course, cannot produce 935 more randomness than the size of the shared secret generated. 937 While this is true if the Diffie-Hellman computation is performed 938 privately, an adversary that can observe either of the public keys 939 and knows the modulus being used need only search through the space 940 of the other secret key in order to be able to calculate the shared 941 secret [D-H]. So, conservatively, it would be best to consider public 942 Diffie-Hellman to produce a quantity whose guessability corresponds 943 to the worst of the two inputs. Because of this and the fact that 944 Diffie-Hellman is computationally intensive, its use as a mixing 945 function is not recommended. 947 5.5 Using a Mixing Function to Stretch Random Bits 949 While it is not necessary for a mixing function to produce the same 950 or fewer bits than its inputs, mixing bits cannot "stretch" the 951 amount of random unpredictability present in the inputs. Thus four 952 inputs of 32 bits each where there is 12 bits worth of 953 unpredictability (such as 4,096 equally probable values) in each 954 input cannot produce more than 4*12 or 48 bits worth of unpredictable 955 output. The output can be expanded to hundreds or thousands of bits 956 by, for example, mixing with successive integers, but the clever 957 adversary's search space is still 2^48 possibilities. Mixing to fewer 958 bits than are input will tend to strengthen the randomness of the 959 output. 961 The last table in Section 5.1 shows that mixing a random bit with a 962 constant bit with Exclusive Or will produce a random bit. While this 963 is true, it does not provide a way to "stretch" one random bit into 964 more than one. If, for example, a random bit is mixed with a 0 and 965 then with a 1, this produces a two-bit sequence but it will always be 966 either 01 or 10. Since there are only two possible values, there is 967 still only the one bit of original randomness. 969 5.6 Other Factors in Choosing a Mixing Function 971 For local use, AES and the SHA* family [SHS] (except for SHA-0 and 972 SHA-1 [RFC6194]) have the advantages that they have been widely 973 studied and tested for flaws and are widely documented and 974 implemented, with hardware and software implementations available all 975 over the world including open source code. The SHA* family for *>1 976 [RFC6234] tend to require more CPU cycles than AES. (The previous 977 version of this RFC suggested use of members of the MD* family of 978 hashes and SHA-1 but this is no longer encouraged [RFC1321] [RFC3174] 979 [RFC6150] [RFC6151] [RFC6194].) 981 Where input lengths are unpredictable, hash algorithms are more 982 convenient to use than block encryption algorithms since they are 983 generally designed to accept variable length inputs. Block encryption 984 algorithms generally require an additional padding algorithm to 985 accommodate inputs that are not an even multiple of the block size. 987 As of the time of this document, the authors know of no patent claims 988 to the basic AES, SHA*, MD*, or Keccak algorithms other than patents 989 for which an irrevocable royalty free world-wide license has been 990 granted. There may be patents of which the authors are unaware or 991 patents on implementations or uses or other relevant patents issued 992 or to be issued. 994 6. Pseudo Random Number Generators 996 When you have a seed with sufficient entropy, from input as described 997 in Section 3 possibly de-skewed and mixed as described in Sections 4 998 and 5, you can algorithmically extend that seed to produce a large 999 number of cryptographically strong random quantities. Such algorithms 1000 are platform independent and can operate in the same fashion on any 1001 computer. To be secure, their input(s) and internal workings must be 1002 protected from adversarial observation. 1004 The design of such pseudo random number generation algorithms, like 1005 the design of symmetric encryption algorithms, is not a task for 1006 amateurs. Section 6.1 below lists a number of bad ideas that failed 1007 algorithms have used. If you are interested in what works, you can 1008 skip 6.1 and just read from 6.2 including Section 7 below which 1009 describes and gives references for some standard pseudo random number 1010 generation algorithms. See Section 7 and [X9.82 - Part 3]. 1012 6.1 Some Bad Ideas 1014 The subsections below describe a number of idea that might seem 1015 reasonable but which lead to insecure pseudo random number 1016 generation. 1018 6.1.1 The Fallacy of Complex Manipulation 1020 One strategy that may give a misleading appearance of 1021 unpredictability is to take a very complex algorithm (or an excellent 1022 traditional pseudo-random number generator with good statistical 1023 properties) and calculate a cryptographic key by starting with 1024 limited data such as the computer system clock value as the seed. An 1025 adversary who knew roughly when the generator was started would have 1026 a relatively small number of seed values to test as they would know 1027 likely values of the system clock. Large numbers of pseudo-random 1028 bits could be generated but the search space an adversary would need 1029 to check could be quite small. 1031 Thus very strong and/or complex manipulation of data will not help if 1032 the adversary can learn what the manipulation is and there is not 1033 enough entropy in the starting seed value. They can usually use the 1034 limited number of results stemming from a limited number of seed 1035 values to defeat security. 1037 Another serious strategy error is to assume that a very complex 1038 pseudo-random number generation algorithm will produce strong random 1039 numbers when there has been no theory behind or analysis of the 1040 algorithm. There is a excellent example of this fallacy right near 1041 the beginning of Chapter 3 in [KNUTH] where the author describes a 1042 complex algorithm. It was intended that the machine language program 1043 corresponding to the algorithm would be so complicated that a person 1044 trying to read the code without comments wouldn't know what the 1045 program was doing. Unfortunately, actual use of this algorithm showed 1046 that it almost immediately converged to a single repeated value in 1047 one case and a small cycle of values in another case. 1049 Not only does complex manipulation not help you if you have a limited 1050 range of seeds but blindly chosen complex manipulation can destroy 1051 the entropy in a good seed! 1053 6.1.2 The Fallacy of Selection from a Large Database 1055 Another strategy that can give a misleading appearance of 1056 unpredictability is selection of a quantity randomly from a database 1057 and assume that its strength is related to the total number of bits 1058 in the database. For example, typical USENET servers process many 1059 megabytes of information per day [USENET]. Assume a random quantity 1060 was selected by fetching 32 bytes of data from a random starting 1061 point in this data. This does not yield 32*8 = 256 bits worth of 1062 unguessability. Even after allowing that much of the data is human 1063 language and probably has no more than 2 or 3 bits of information per 1064 byte, it doesn't yield 32*2 = 64 bits of unguessability. For an 1065 adversary with access to the same Usenet database the unguessability 1066 rests only on the starting point of the selection. That is perhaps a 1067 little over a couple of dozen bits of unguessability. 1069 The same argument applies to selecting sequences from the data on a 1070 publicly available CD/DVD recording or any other large public 1071 database. If the adversary has access to the same database, this 1072 "selection from a large volume of data" step buys little. However, 1073 if a selection can be made from data to which the adversary has no 1074 access, such as system buffers on an active multi-user system, it may 1075 be of help. 1077 6.1.3. Traditional Pseudo-Random Sequences 1079 This section talks about traditional sources of deterministic of 1080 "pseudo-random" numbers. These typically start with a "seed" quantity 1081 and use simple numeric or logical operations to produce a sequence of 1082 values. Note that none of the techniques discussed in this section is 1083 suitable for cryptographic use. They are presented for general 1084 information. 1086 [KNUTH] has a classic exposition on pseudo-random numbers. 1087 Applications he mentions are simulation of natural phenomena, 1088 sampling, numerical analysis, testing computer programs, decision 1089 making, and games. None of these have the same characteristics as the 1090 sort of security uses we are talking about. Only in the last two 1091 could there be an adversary trying to find the random quantity. 1092 However, in these cases, the adversary normally has only a single 1093 chance to use a guessed value. In guessing passwords or attempting to 1094 break an encryption scheme, the adversary normally has many, perhaps 1095 unlimited, chances at guessing the correct value. Sometimes they can 1096 store the message they are trying to break and repeatedly attack it. 1097 They are also assumed to be aided by a computer. 1099 For testing the "randomness" of numbers, Knuth suggests a variety of 1100 measures including statistical and spectral. These tests check things 1101 like autocorrelation between different parts of a "random" sequence 1102 or distribution of its values. But they could be met by a constant 1103 stored random sequence, such as the "random" sequence printed in the 1104 CRC Standard Mathematical Tables [CRC]. Despite meeting all the tests 1105 suggested by Knuth, that sequence is unsuitable for cryptographic use 1106 as adversaries must be assumed to have copies of all common published 1107 "random" sequences and will able to spot the source and predict 1108 future values. 1110 A typical pseudo-random number generation technique, known as a 1111 linear congruence pseudo-random number generator, is modular 1112 arithmetic where the value numbered N+1 is calculated from the value 1113 numbered N by 1115 V = ( V * a + b )(Mod c) 1116 N+1 N 1118 The above technique has a strong relationship to linear shift 1119 register pseudo-random number generators, which are well understood 1120 cryptographically [SHIFT]. In such generators bits are introduced at 1121 one end of a shift register as the Exclusive Or (binary sum without 1122 carry) of bits from selected fixed taps into the register. For 1123 example: 1125 +----+ +----+ +----+ +----+ 1126 | B | <-- | B | <-- | B | <-- . . . . . . <-- | B | <-+ 1127 | 0 | | 1 | | 2 | | n | | 1128 +----+ +----+ +----+ +----+ | 1129 | | | | 1130 | | V +-----+ 1131 | V +----------------> | | 1132 V +-----------------------------> | XOR | 1133 +---------------------------------------------------> | | 1134 +-----+ 1136 V = ( ( V * 2 ) + B .xor. B ... )(Mod 2^n) 1137 N+1 N 0 2 1139 The goodness of traditional pseudo-random number generator algorithms 1140 is measured by statistical tests on such sequences. Carefully chosen 1141 values a, b, c, and initial V or the placement of shift register taps 1142 in the above simple processes can produce excellent statistics. 1144 These sequences may be adequate in simulations (Monte Carlo 1145 experiments) as long as the sequence is orthogonal to the structure 1146 of the space being explored. Even there, subtle patterns may cause 1147 problems. However, such sequences are clearly bad for use in security 1148 applications. They are fully predictable if the initial state is 1149 known. Depending on the form of the pseudo-random number generator, 1150 the sequence may be determinable from observation of a short portion 1151 of the sequence [SCHNEIER, STERN]. For example, with the generators 1152 above, one can determine V(n+1) given knowledge of V(n). In fact, it 1153 has been shown that with these techniques, even if only one bit of 1154 the pseudo-random values are released, the seed can be determined 1155 from short sequences. 1157 Not only have linear congruent generators been broken, but techniques 1158 are known for breaking all polynomial congruent generators. 1159 [KRAWCZYK] 1161 6.2 Cryptographically Strong Sequences 1163 In cases where a series of random quantities must be generated, an 1164 adversary may learn some values in the sequence. In general, they 1165 should not be able to predict other values from the ones that they 1166 know. 1168 The correct technique is to start with a strong random seed, take 1169 cryptographically strong steps from that seed [FERGUSON, SCHNEIER], 1170 and do not reveal the complete state of the generator in the sequence 1171 elements. If each value in the sequence can be calculated in a fixed 1172 way from the previous value, then when any value is compromised, all 1173 future values can be determined. This would be the case, for example, 1174 if each value were a constant function of the previously used values, 1175 even if the function were a very strong, non-invertible message 1176 digest function. 1178 (It should be noted that if your technique for generating a sequence 1179 of key values is fast enough, it can trivially be used as the basis 1180 for a confidentiality system. If two parties use the same sequence 1181 generating technique and start with the same seed material, they will 1182 generate identical sequences. These could, for example, be xor'ed at 1183 one end with data being send, encrypting it, and xor'ed with this 1184 data as received, decrypting it due to the reversible properties of 1185 the xor operation. This is commonly referred to as a simple stream 1186 cipher.) 1188 6.2.1 OFB and CTR Sequences 1190 One way to achieve a strong sequence is to have the values be 1191 produced by taking a seed value and hashing the quantities produced 1192 by concatenating the seed with successive integers or the like and 1193 then mask the values obtained so as to limit the amount of generator 1194 state available to the adversary. 1196 It may also be possible to use an "encryption" algorithm with a 1197 random key and seed value to encrypt successive integers as in 1198 counter (CTR) mode encryption. Alternatively, you can feedback all of 1199 the output value from encryption into the value to be encrypted for 1200 the next iteration. This is a particular example of output feedback 1201 mode (OFB). [MODES] 1203 An example is shown below where shifting and masking are used to 1204 combine part of the output feedback with part of the old input. This 1205 type of partial feedback should be avoided for reasons described 1206 below. 1208 +---------------+ 1209 | V | 1210 | | n |--+ 1211 +--+------------+ | 1212 | | +---------+ 1213 shift| +---> | | +-----+ 1214 +--+ | Encrypt | <--- | Key | 1215 | +-------- | | +-----+ 1216 | | +---------+ 1217 V V 1218 +------------+--+ 1219 | V | | 1220 | n+1 | 1221 +---------------+ 1223 Note that if a shift of one is used, this is the same as the shift 1224 register technique described in Section 3 above but with the 1225 important difference that the feedback is determined by a complex 1226 non-linear function of all bits rather than a simple linear or 1227 polynomial combination of output from a few bit position taps. 1229 It has been shown by Donald W. Davies that this sort of shifted 1230 partial output feedback significantly weakens an algorithm compared 1231 with feeding all of the output bits back as input. In particular, for 1232 [DES], repeated encrypting a full 64 bit quantity will give an 1233 expected repeat in about 2^63 iterations. Feeding back anything less 1234 than 64 (and more than 0) bits will give an expected repeat in 1235 between 2^31 and 2^32 iterations! 1237 To predict values of a sequence from others when the sequence was 1238 generated by these techniques is equivalent to breaking the 1239 cryptosystem or inverting the "non-invertible" hashing involved with 1240 only partial information available. The less information revealed 1241 each iteration, the harder it will be for an adversary to predict the 1242 sequence. Thus it is best to use only one bit from each value. It has 1243 been shown that in some cases this makes it impossible to break a 1244 system even when the cryptographic system is invertible and can be 1245 broken if all of each generated value was revealed. 1247 6.2.2 The Blum Blum Shub Sequence Generator 1249 Currently the generator that has the strongest public proof of 1250 strength is called the Blum Blum Shub generator after its inventors 1251 [BBS]. It is also very simple and is based on quadratic residues. 1252 Its only disadvantage is that it is computationally intensive 1253 compared with the traditional techniques give in 6.1.3 above. This is 1254 not a major draw back if it is used for moderately infrequent 1255 purposes, such as generating session keys. 1257 Simply choose two large prime numbers, say p and q, which both have 1258 the property that you get a remainder of 3 if you divide them by 4. 1259 Let n = p * q. Then you choose a random number x relatively prime to 1260 n. The initial seed for the generator and the method for calculating 1261 subsequent values are then 1263 2 1264 s = ( x )(Mod n) 1265 0 1267 2 1268 s = ( s )(Mod n) 1269 i+1 i 1271 You must be careful to use only a few bits from the bottom of each s. 1272 It is always safe to use only the lowest order bit. If you use no 1273 more than the 1274 log ( log ( s ) ) 1275 2 2 i 1276 low order bits, then predicting any additional bits from a sequence 1277 generated in this manner is provable as hard as factoring n. As long 1278 as the initial x is secret, you can even make n public if you want. 1280 An interesting characteristic of this generator is that you can 1281 directly calculate any of the s values. In particular 1283 i 1284 ( ( 2 )(Mod (( p - 1 ) * ( q - 1 )) ) ) 1285 s = ( s )(Mod n) 1286 i 0 1288 This means that in applications where many keys are generated in this 1289 fashion, it is not necessary to save them all. Each key can be 1290 effectively indexed and recovered from that small index and the 1291 initial s and n. 1293 6.3 Entropy Pool Techniques 1295 Many modern pseudo-random number sources, such as those describe in 1296 Sections 7.1.2 and 7.1.3, utilize the technique of maintaining a 1297 "pool" of bits and providing operations for strongly mixing input 1298 with some randomness into the pool and extracting pseudo random bits 1299 from the pool. This is illustrated in the figure below. 1301 +--------+ +------+ +---------+ 1302 --->| Mix In |--->| POOL |--->| Extract |---> 1303 | Bits | | | | Bits | 1304 +--------+ +------+ +---------+ 1305 ^ V 1306 | | 1307 +-----------+ 1309 Bits to be feed into the pool can be any of the various hardware, 1310 environmental, or user input sources discussed above. It is also 1311 common to save the state of the pool on system shut down and restore 1312 it on re-starting, if stable storage is available. 1314 Care must be taken that enough entropy has been added to the pool to 1315 support particular output uses desired. See [RSA BULL1] for similar 1316 suggestions. 1318 7. Randomness Generation Examples and Standards 1320 Several public standards and widely deployed examples are in place 1321 for the generation of keys or other cryptographically random 1322 quantities. Some, in section 7.1 below, include an entropy source. 1323 Others, described in section 7.2, provide the pseudo-random number 1324 strong sequence generator but assume the input of a random seed or 1325 input from a source of entropy. 1327 7.1 Randomness Generators 1329 Three standards are described below. The two older standards use 1330 DES, with its 64-bit block and key size limit, but any equally strong 1331 or stronger mixing function could be substituted [DES]. The third is 1332 a more modern and stronger standard based on SHA-1 [SHS]. Lastly the 1333 widely deployed modern UNIX and Windows random number generators are 1334 described. 1336 7.1.1 US DoD Recommendations for Password Generation 1338 The United States Department of Defense has recommendations for 1339 password generation [DoD]. They suggest using the US Data Encryption 1340 Standard [DES] in Output Feedback Mode [MODES] as follows: 1342 use an initialization vector determined from 1343 the system clock, 1344 system ID, 1345 user ID, and 1346 date and time; 1347 use a key determined from 1348 system interrupt registers, 1349 system status registers, and 1350 system counters; and, 1351 as plain text, use an external randomly generated 64 bit 1352 quantity such as the ASCII bytes for 8 characters typed in by a 1353 system administrator. 1355 The password can then be calculated from the 64 bit "cipher text" 1356 generated by DES in 64-bit Output Feedback Mode. As many bits as are 1357 needed can be taken from these 64 bits and expanded into a 1358 pronounceable word, phrase, or other format if a human being needs to 1359 remember the password. 1361 7.1.2 The /dev/random Device 1363 Several versions of the UNIX operating system provide a kernel- 1364 resident random number generator. In some cases, these generators 1365 make use of events captured by the Kernel during normal system 1366 operation. 1368 For example, on some versions of Linux, the generator consists of a 1369 random pool of 512 bytes represented as 128 words of 4-bytes each. 1370 When an event occurs, such as a disk drive interrupt, the time of the 1371 event is XORed into the pool and the pool is stirred via a primitive 1372 polynomial of degree 128. The pool itself is treated as a ring 1373 buffer, with new data being XORed (after stirring with the 1374 polynomial) across the entire pool. 1376 Each call that adds entropy to the pool estimates the amount of 1377 likely true entropy the input contains. The pool itself contains a 1378 accumulator that estimates the total over all entropy of the pool. 1380 Input events come from several sources as listed below. 1381 Unfortunately, for server machines without human operators, the first 1382 and third are not available and entropy may be added slowly in that 1383 case. 1385 1. Keyboard interrupts. The time of the interrupt as well as the scan 1386 code are added to the pool. This in effect adds entropy from the 1387 human operator by measuring inter-keystroke arrival times. 1389 2. Disk completion and other interrupts. A system being used by a 1390 person will likely have a hard to predict pattern of disk 1391 accesses. (But not all disk drivers support capturing this timing 1392 information with sufficient accuracy to be useful.) 1394 3. Mouse motion. The timing as well as mouse position is added in. 1396 When random bytes are required, the pool is hashed with SHA-1 [SHS] 1397 to yield the returned bytes of randomness. If more bytes are required 1398 than the output of SHA-1 (20 bytes), then the hashed output is 1399 stirred back into the pool and a new hash performed to obtain the 1400 next 20 bytes. As bytes are removed from the pool, the estimate of 1401 entropy is similarly decremented. 1403 To ensure a reasonable random pool upon system startup, the standard 1404 startup and shutdown scripts save the pool to a disk file at shutdown 1405 and read this file at system startup. 1407 There are two user-exported interfaces. /dev/random returns bytes 1408 from the pool, but blocks when the estimated entropy drops to zero. 1409 As entropy is added to the pool from events, more data becomes 1410 available via /dev/random. Random data obtained from such a 1411 /dev/random device is suitable for key generation for long-term keys, 1412 if enough random bits are in the pool or are added in a reasonable 1413 amount of time. 1415 /dev/urandom works like /dev/random, however it provides data even 1416 when the entropy estimate for the random pool drops to zero. This may 1417 be adequate for session keys or for other key generation tasks where 1418 blocking while waiting for more random bits is not acceptable. The 1419 risk of continuing to take data even when the pool's entropy estimate 1420 is small in that past output may be computable from current output 1421 provided an attacker can reverse SHA-1. Given that SHA-1 is designed 1422 to be non-invertible, this is a reasonable risk. 1424 To obtain random numbers under Linux, Solaris, or other UNIX systems 1425 equipped with code as described above, all an application needs to do 1426 is open either /dev/random or /dev/urandom and read the desired 1427 number of bytes. 1429 (The Linux Random device was written by Theodore Ts'o. It was based 1430 loosely on the random number generator in PGP 2.X and PGP 3.0 (aka 1431 PGP 5.0). [PGP]) 1433 7.1.3 Windows CryptGenRandom 1435 Microsoft's recommendation to users of the widely deployed Windows 1436 operating system is generally to use the CryptGenRandom pseudo-random 1437 number generation call with the CryptAPI cryptographic service 1438 provider. This takes a handle to a cryptographic service provider 1439 library, a pointer to a buffer by which the caller can provide 1440 entropy and into which the generated pseudo-randomness is returned, 1441 and an indication of how many octets of randomness are desired. 1443 The Windows CryptAPI cryptographic service provider stores a seed 1444 state variable with every user. When CryptGenRandom is called, this 1445 is combined with any randomness provided in the call and various 1446 system and user data such as the process ID, thread ID, system clock, 1447 system time, system counter, memory status, free disk clusters, and 1448 hashed user environment block. This data is all feed to SHA-1 and the 1449 output used to seed an RC4 key stream. That key stream is used to 1450 produce the pseudo-random data requested and to update the user's 1451 seed state variable. 1453 Users of Windows ".NET" will probably find it easier to use the 1454 RNGCryptoServiceProvider.GetBytes method interface. 1456 For further information, see [WSC]. 1458 7.2 Generators Assuming a Source of Entropy 1460 The pseudo-random number generators described in the following three 1461 sections all assume that a seed value with sufficient entropy is 1462 provided to them. They then generate a strong sequence (see Section 1463 6.2) from that seed. 1465 7.2.1 X9.82 Pseudo-Random Number Generation 1467 The ANSI X9F1 committee is in the final stages of creating a standard 1468 for random number generation covering both true randomness generators 1469 and pseudo-random number generators. It includes a number of pseudo- 1470 random number generators based on hash functions one of which will 1471 probably be based on HMAC SHA hash constructs [RFC2104]. The draft 1472 version of this generated is as described below omitting a number of 1473 optional features [X9.82]. 1475 In the description in the subsections below, the HMAC hash construct 1476 is simply referred to as HMAC but, of course, in an particular use, a 1477 particular standard SHA function must be selected. Generally 1478 speaking, if the strength of the pseudo-random values to be generated 1479 is to be N bits, the SHA function chosen must be one generating N or 1480 more bits of output and a source of at least N bits of input entropy 1481 will be required. The same hash function must be used throughout an 1482 instantiation of this generator. 1484 7.2.1.1 Notation 1486 In the following sections the notation give below is used: 1488 hash_length is the output size of the underlying hash function in 1489 use. 1491 input_entropy is the input bit string that provides entropy to the 1492 generator. 1494 K is a bit string of size hash_length that is part of the state of 1495 the generator and is updated at least once each time random 1496 bits are generated. 1498 V is a bit string of size hash_length and is part of the state of 1499 the generator that is updated each time hash_length bits of 1500 output are generated. 1502 | represents concatenation 1504 7.1.2.2 Initializing the Generator 1506 Set V to all zero bytes except that the low order bit of each byte is 1507 set to one. 1509 Set K to all zero bytes. 1511 K = HMAC ( K, V | 0x00 | input_entropy ) 1513 V = HMAC ( K, V ) 1515 K = HMAC ( K, V | 0x01 | input_entropy ) 1517 V = HMAC ( K, V ) 1519 Note: all SHA algorithms produce an integral number of bytes of the 1520 length of K and V will be an integral number of bytes. 1522 7.1.2.5 Generating Random Bits 1524 When output is called for simply set 1526 V = HMAC ( K, V ) 1528 and use leading bits from V. If more bits are needed than the length 1529 of V, set "temp" to a null bit string and then repeatedly perform 1531 V = HMAC ( K, V ) 1532 temp = temp | V 1534 stopping as soon a temp is equal to or longer than the number of 1535 random bits called for and use the called for number of leading bits 1536 from temp. The definition of the algorithm prohibits calling from 1537 more than 2**35 bits. 1539 7.2.2 X9.17 Key Generation 1541 The American National Standards Institute has specified a method for 1542 generating a sequence of keys as follows [X9.17]: 1544 s is the initial 64 bit seed 1545 0 1547 g is the sequence of generated 64 bit key quantities 1548 n 1550 k is a random key reserved for generating this key sequence 1552 t is the time at which a key is generated to as fine a resolution 1553 as is available (up to 64 bits). 1555 DES ( K, Q ) is the DES encryption of quantity Q with key K 1557 g = DES ( k, DES ( k, t ) .xor. s ) 1558 n n 1560 s = DES ( k, DES ( k, t ) .xor. g ) 1561 n+1 n 1563 If g sub n is to be used as a DES key, then every eighth bit should 1564 be adjusted for parity for that use but the entire 64 bit unmodified 1565 g should be used in calculating the next s. 1567 7.2.3 DSS Pseudo-Random Number Generation 1569 Appendix 3 of the NIST Digital Signature Standard [DSS] provides a 1570 method of producing a sequence of pseudo-random 160 bit quantities 1571 for use as private keys or the like. This has been modified by Change 1572 Notice 1 [DSS CN1] to produce the following algorithm for generating 1573 general purpose pseudorandom numbers: 1575 t = 0x 67452301 EFCDAB89 98BADCFE 10325476 C3D2E1F0 1577 XKEY = initial seed 1578 0 1580 For j = 0 to ... 1582 XVAL = ( XKEY + optional user input ) (Mod 2^512) 1583 j 1585 X = G( t, XVAL ) 1586 j 1588 XKEY = ( 1 + XKEY + X ) (Mod 2^512) 1589 j+1 j j 1591 The quantities X thus produced are the pseudo-random sequence of 160 1592 bit values. Two functions can be used for "G" above. Each produces 1593 a 160-bit value and takes two arguments, the first argument a 160-bit 1594 value and the second a 512 bit value. 1596 The first is based on SHA-1 and works by setting the 5 linking 1597 variables, denoted H with subscripts in the SHA-1 specification, to 1598 the first argument divided into fifths. Then steps (a) through (e) of 1599 section 7 of the NIST SHA-1 specification are run over the second 1600 argument as if it were a 512-bit data block. The values of the 1601 linking variable after those steps are then concatenated to produce 1602 the output of G. [SHS] 1604 As an alternative second method, NIST also defined an alternate G 1605 function based on multiple applications of the DES encryption 1606 function [DSS]. 1608 8. Examples of Randomness Required 1610 Below are two examples showing rough calculations of needed 1611 randomness for security. The first is for moderate security passwords 1612 while the second assumes a need for a very high security 1613 cryptographic key. 1615 In addition [ORMAN] and [RSA BULL13] provide information on the 1616 public key lengths that should be used for exchanging symmetric keys. 1618 8.1 Password Generation 1620 Assume that user passwords change once a year and it is desired that 1621 the probability that an adversary could guess the password for a 1622 particular account be less than one in a thousand. Further assume 1623 that sending a password to the system is the only way to try a 1624 password. Then the crucial question is how often an adversary can try 1625 possibilities. Assume that delays have been introduced into a system 1626 so that, at most, an adversary can make one password try every six 1627 seconds. That's 600 per hour or about 15,000 per day or about 1628 5,000,000 tries in a year. Assuming any sort of monitoring, it is 1629 unlikely someone could actually try continuously for a year. In fact, 1630 even if log files are only checked monthly, 500,000 tries is more 1631 plausible before the attack is noticed and steps taken to change 1632 passwords and make it harder to try more passwords. 1634 To have a one in a thousand chance of guessing the password in 1635 500,000 tries implies a universe of at least 500,000,000 passwords or 1636 about 2^29. Thus 29 bits of randomness are needed. This can probably 1637 be achieved using the US DoD recommended inputs for password 1638 generation as it has 8 inputs which probably average over 5 bits of 1639 randomness each (see section 7.1). Using a list of 1000 words, the 1640 password could be expressed as a three-word phrase (1,000,000,000 1641 possibilities) or, using case insensitive letters and digits, six 1642 would suffice ((26+10)^6 = 2,176,782,336 possibilities). 1644 For a higher security password, the number of bits required goes up. 1645 To decrease the probability by 1,000 requires increasing the universe 1646 of passwords by the same factor which adds about 10 bits. Thus to 1647 have only a one in a million chance of a password being guessed under 1648 the above scenario would require 39 bits of randomness and a password 1649 that was a four-word phrase from a 1000 word list or eight 1650 letters/digits. To go to a one in 10^9 chance, 49 bits of randomness 1651 are needed implying a five word phrase or ten letter/digit password. 1653 In a real system, of course, there are also other factors. For 1654 example, the larger and harder to remember passwords are, the more 1655 likely users are to write them down resulting in an additional risk 1656 of compromise. 1658 8.2 A Very High Security Cryptographic Key 1660 Assume that a very high security key is needed for symmetric 1661 encryption / decryption between two parties. Assume an adversary can 1662 observe communications and knows the algorithm being used. Within the 1663 field of random possibilities, the adversary can try key values in 1664 hopes of finding the one in use. Assume further that brute force 1665 trial of keys is the best the adversary can do. 1667 8.2.1 Effort per Key Trial 1669 How much effort will it take to try each key? For very high security 1670 applications it is best to assume a low value of effort. Even if it 1671 would clearly take tens of thousands of computer cycles or more to 1672 try a single key, there may be some pattern that enables huge blocks 1673 of key values to be tested with much less effort per key. Thus it is 1674 probably best to assume no more than a couple hundred cycles per key. 1675 (There is no clear lower bound on this as computers operate in 1676 parallel on a number of bits and a poor encryption algorithm could 1677 allow many keys or even groups of keys to be tested in parallel. 1678 However, we need to assume some value and can reasonably hope that a 1679 strong algorithm has been chosen for our hypothetical high security 1680 task.) 1682 If the adversary can command a highly parallel processor or a large 1683 network of work stations, 10^13 cycles per second is probably a 1684 minimum assumption for availability today. Looking forward a few 1685 years, there should be at least an order of magnitude improvement. 1686 Thus assuming 10^13 keys could be checked per second or 3.6*10^15 per 1687 hour or 6*10^17 per week or 2.4*10^18 per month is reasonable. This 1688 implies a need for a minimum of 74 bits of randomness in keys to be 1689 sure they cannot be found in a month. Even then it is possible that, 1690 a few years from now, a highly determined and resourceful adversary 1691 could break the key in 2 weeks (on average they need try only half 1692 the keys). 1694 These questions are considered in detail in "Minimal Key Lengths for 1695 Symmetric Ciphers to Provide Adequate Commercial Security: A Report 1696 by an Ad Hoc Group of Cryptographers and Computer Scientists" 1697 [KeyStudy] which was sponsored by the Business Software Alliance. It 1698 concluded that a reasonable key length in 1995 for very high security 1699 is in the range of 75 to 90 bits and, since the cost of cryptography 1700 does not vary much with they key size, recommends 90 bits. To update 1701 these recommendations, just add 2/3 of a bit per year for Moore's law 1703 [MOORE]. Thus, in the year 2013, this translates to a determination 1704 that a reasonable key length is in the 87 to 102 bit range. In fact, 1705 today, it is increasingly common to use keys longer than 102 bits, 1706 such as 128-bit (or longer) keys with AES. 1708 8.2.2 Meet in the Middle Attacks 1710 If chosen or known plain text and the resulting encrypted text are 1711 available, a "meet in the middle" attack is possible if the structure 1712 of the encryption algorithm allows it. (In a known plain text attack, 1713 the adversary knows all or part of the messages being encrypted, 1714 possibly some standard header or trailer fields. In a chosen plain 1715 text attack, the adversary can force some chosen plain text to be 1716 encrypted, possibly by "leaking" an exciting text that would then be 1717 sent by the adversary over an encrypted channel.) 1719 An oversimplified explanation of the meet in the middle attack is as 1720 follows: the adversary can half-encrypt the known or chosen plain 1721 text with all possible first half-keys, sort the output, then half- 1722 decrypt the encoded text with all the second half-keys. If a match is 1723 found, the full key can be assembled from the halves and used to 1724 decrypt other parts of the message or other messages. At its best, 1725 this type of attack can halve the exponent of the work required by 1726 the adversary while adding a very large but roughly constant factor 1727 of effort. Thus, if this attack can be mounted, a doubling of the 1728 amount of randomness in the very strong key to a minimum of 204 bits 1729 (102*2) is required for the year 2013 based on the [KeyStudy] 1730 analysis. 1732 This amount of randomness is well beyond the limit of that in the 1733 inputs recommended by the US DoD for password generation and could 1734 require user typing timing, hardware random number generation, and/or 1735 other sources. 1737 The meet in the middle attack assumes that the cryptographic 1738 algorithm can be decomposed in this way. Hopefully no modern 1739 algorithm has this weakness but there may be cases where we are not 1740 sure of that or even of what algorithm a key will be used with. Even 1741 if a basic algorithm is not subject to a meet in the middle attack, 1742 an attempt to produce a stronger algorithm by applying the basic 1743 algorithm twice (or two different algorithms sequentially) with 1744 different keys will gain less added security than would be expected. 1745 Such a composite algorithm would be subject to a meet in the middle 1746 attack. 1748 Enormous resources may be required to mount a meet in the middle 1749 attack but they are probably within the range of the national 1750 security services of a major nation. Essentially all nations spy on 1751 other nations traffic. 1753 8.2.3 Other Considerations 1755 [KeyStudy] also considers the possibilities of special purpose code 1756 breaking hardware and having an adequate safety margin. 1758 It should be noted that key length calculations such at those above 1759 are controversial and depend on various assumptions about the 1760 cryptographic algorithms in use. In some cases, a professional with a 1761 deep knowledge of code breaking techniques and of the strength of the 1762 algorithm in use could be satisfied with less than half of the 204 1763 bit key size derived above. 1765 For further examples of conservative design principles see 1766 [FERGUSON]. 1768 9. Conclusion 1770 Generation of unguessable "random" secret quantities for security use 1771 is an essential but difficult task. 1773 Hardware techniques to produce the needed entropy are relatively 1774 simple. In particular, the volume and quality needed is not high and 1775 existing computer hardware can be used. However, in an era when the 1776 integrity of hardware design can be corrupted by nation states, 1777 special purpose built in hardware random number generation should not 1778 be trusted as the sole source of randomness. 1780 Widely available computational techniques are available to process 1781 random quantities from multiple sources, including low quality 1782 sources, so as to produce a smaller quantity of higher quality keying 1783 material. A variety of hardware, user, and software sources should be 1784 used. 1786 Once a sufficient quantity of high quality seed key material (a 1787 couple of hundred bits) is available, computational techniques are 1788 available to produce cryptographically strong sequences of 1789 computationally unpredictable quantities from this seed material. 1791 10. Security Considerations 1793 The entirety of this document concerns techniques and recommendations 1794 for generating unguessable "random" quantities for use as passwords, 1795 cryptographic keys, initialization vectors, sequence numbers, and 1796 similar security uses. See earlier sections of this document. 1798 11. IANA Considerations 1800 This document requires no IANA actions. RFC Editor: Please delete 1801 this section before publication. 1803 Informative References 1805 [AES] - "Specification of the Advanced Encryption Standard (AES)", 1806 United States of America, US National Institute of Standards 1807 and Technology, FIPS 197, November 2001. 1809 [ASYMMETRIC] - "Secure Communications and Asymmetric Cryptosystems", 1810 edited by Gustavus J. Simmons, AAAS Selected Symposium 69, 1811 Westview Press, Inc. 1813 [BBS] - "A Simple Unpredictable Pseudo-Random Number Generator", SIAM 1814 Journal on Computing, v. 15, n. 2, 1986, L. Blum, M. Blum, & M. 1815 Shub. 1817 [BRILLINGER] - "Time Series: Data Analysis and Theory", Holden-Day, 1818 1981, David Brillinger. 1820 [CRC] - "C.R.C. Standard Mathematical Tables", Chemical Rubber 1821 Publishing Company. 1823 [DAVIS] - "Cryptographic Randomness from Air Turbulence in Disk 1824 Drives", Advances in Cryptology - Crypto '94, Springer-Verlag 1825 Lecture Notes in Computer Science #839, 1984, Don Davis, Ross 1826 Ihaka, and Philip Fenstermacher. 1828 [DES] 1829 - "Data Encryption Standard", US National Institute of 1830 Standards and Technology, FIPS 46-3, October 1999. 1831 - "Data Encryption Algorithm", American National Standards 1832 Institute, ANSI X3.92-1981. 1833 (See also FIPS 112, Password Usage, which includes FORTRAN code 1834 for performing DES.) 1836 [D-H] - RFC 2631, "Diffie-Hellman Key Agreement Method", Eric 1837 Rescrola, June 1999. 1839 [DNSSEC] 1840 - Arends, R., Austein, R., Larson, M., Massey, D., and S. Rose, 1841 "DNS Security Introduction and Requirements", RFC 4033, 1842 March 2005. 1843 - Arends, R., Austein, R., Larson, M., Massey, D., and S. Rose, 1844 "Resource Records for the DNS Security Extensions", RFC 1845 4034, March 2005. 1846 - Arends, R., Austein, R., Larson, M., Massey, D., and S. Rose, 1847 "Protocol Modifications for the DNS Security Extensions", 1848 RFC 4035, March 2005. 1850 [DoD] - "Password Management Guideline", United States of America, 1851 Department of Defense, Computer Security Center, CSC- 1852 STD-002-85. 1854 (See also FIPS 112, Password Usage, which incorporates CSC- 1855 STD-002-85 as one of its appendices.) 1857 [DSS] - "Digital Signature Standard (DSS)", US National Institute of 1858 Standards and Technology, FIPS 186-2, January 2000. 1860 [DSS CN1] - "Digital Signature Standard Change Notice 1", US National 1861 Institute of Standards and Technology, FIPS 186-2 Change Notice 1862 1, 5 October 2001. 1864 [FERGUSON] - "Practical Cryptography", Niels Ferguson and Bruce 1865 Schneier, Wiley Publishing Inc., ISBN 047122894X, April 2003. 1867 [GIFFORD] - "Natural Random Number", MIT/LCS/TM-371, David K. 1868 Gifford, September 1988. 1870 [IEEE802.11] - IEEE Std 802.11-2012, "Wireless LAN Medium Access 1871 Control (MAC) and physical layer (PHY) Specifications", 29 1872 March 2012. 1874 [Jakobsson] - M. Jakobsson, E. Shriver, B. K. Hillyer, and A. Juels, 1875 "A practical secure random bit generator", Proceedings of the 1876 Fifth ACM Conference on Computer and Communications Security, 1877 1998. See also 1878 http://citeseer.ist.psu.edu/article/jakobsson98practical.html. 1880 [KAUFMAN] - "Network Security: Private Communication in a Public 1881 World", Charlie Kaufman, Radia Perlman, and Mike Speciner, 1882 Prentis Hall PTR, ISBN 0-13-046019-2, 2nd Edition 2002. 1884 [KECCAK] - 1885 http://csrc.nist.gov/groups/ST/hash/sha-3/winner_sha-3.html 1886 http://keccak.noekeon.org 1888 [KeyStudy] - "Minimal Key Lengths for Symmetric Ciphers to Provide 1889 Adequate Commercial Security: A Report by an Ad Hoc Group of 1890 Cryptographers and Computer Scientists", M. Blaze, W. Diffie, 1891 R. Rivest, B. Schneier, T. Shimomura, E. Thompson, and M. 1892 Weiner, January 1996, . 1894 [KNUTH] - "The Art of Computer Programming", Volume 2: Seminumerical 1895 Algorithms, Chapter 3: Random Numbers, Donald E. Knuth, Addison 1896 Wesley Publishing Company, 3rd Edition November 1997. 1898 [KRAWCZYK] - "How to Predict Congruential Generators", H. Krawczyk, 1899 Journal of Algorithms, V. 13, N. 4, December 1992. 1901 [LUBY] - "Pseudorandomness and Cryptographic Applications", Michael 1902 Luby, Princeton University Press, ISBN 0691025460, 8 January 1903 1996. 1905 [PGP] 1906 - RFC 2440, "OpenPGP Message Format", J. Callas, L. 1907 Donnerhacke, H. Finney, R. Thayer, November 1998. 1908 - RFC 3156, "MIME Security with OpenPGP" M. Elkins, D. Del 1909 Torto, R. Levien, T. Roessler, August 2001. 1911 [MAIL S/MIME] 1912 - RFC 2632, "S/MIME Version 3 Certificate Handling", B. 1913 Ramsdell, Ed., June 1999. 1914 - RFC 2633, "S/MIME Version 3 Message Specification", B. 1915 Ramsdell, Ed., June 1999. 1916 - RFC 2634, "Enhanced Security Services for S/MIME" P. Hoffman, 1917 Ed., June 1999. 1919 [MODES] 1920 - "DES Modes of Operation", US National Institute of Standards 1921 and Technology, FIPS 81, December 1980. 1922 - "Data Encryption Algorithm - Modes of Operation", American 1923 National Standards Institute, ANSI X3.106-1983. 1925 [MOORE] - Moore's Law: the exponential increase in the logic density 1926 of silicon circuits. Originally formulated by Gordon Moore in 1927 1964 as a doubling every year starting in 1962, in the late 1928 1970s the rate fell to a doubling every 18 months and has 1929 remained there through the date of this document. See "The New 1930 Hacker's Dictionary", Third Edition, MIT Press, ISBN 1931 0-262-18178-9, Eric S. Raymond, 1996. 1933 [NASLUND] - "Extraction of Optimally Unbiased Bits from a Biased 1934 Source", M. Naslund and A. Russell, IEEE Transactions on 1935 Information Theory. 46(3), May 2000. 1936 1938 [ORMAN] - "Determining Strengths For Public Keys Used For Exchanging 1939 Symmetric Keys", RFC 3766, Hilarie Orman, Paul Hoffman, April 1940 2004. 1942 [RFC1321] - "The MD5 Message-Digest Algorithm", RFC1321, April 1992, 1943 R. Rivest 1945 [RFC2104] - Krawczyk, H., Bellare, M., and R. Canetti, "HMAC: Keyed- 1946 Hashing for Message Authentication", RFC 2104, February 1997. 1948 [RFC3174] - RFC 3174, "US Secure Hash Algorithm 1 (SHA1)", D. 1949 Eastlake, P. Jones, September 2001. 1951 [RFC4086] - "Randomness Requirements for Security", D. Eastlake, S. 1952 Crocker, J. Schiller, June 2005. (Obsoleted by this document.) 1954 [RFC4251] - Ylonen, T. and C. Lonvick, Ed., "The Secure Shell (SSH) 1955 Protocol Architecture", RFC 4251, January 2006. 1957 [RFC4301] - Kent, S. and K. Seo, "Security Architecture for the 1958 Internet Protocol", RFC 4301, December 2005. 1960 [RFC5246] - Dierks, T. and E. Rescorla, "The Transport Layer 1961 Security (TLS) Protocol Version 1.2", RFC 5246, August 2008. 1963 [RFC6150] - Turner, S. and L. Chen, "MD4 to Historic Status", 1964 RFC 6150, March 2011. 1966 [RFC6151] - Turner, S. and L. Chen, "Updated Security Considerations 1967 for the MD5 Message-Digest and the HMAC-MD5 Algorithms", RFC 1968 6151, March 2011. 1970 [RFC6194] - Polk, T., Chen, L., Turner, S., and P. Hoffman, "Security 1971 Considerations for the SHA-0 and SHA-1 Message-Digest 1972 Algorithms", RFC 6194, March 2011. 1974 [RFC6234] - Eastlake 3rd, D. and T. Hansen, "US Secure Hash 1975 Algorithms (SHA and SHA-based HMAC and HKDF)", RFC 6234, May 1976 2011. 1978 [RFC6528] - Gont, F. and S. Bellovin, "Defending against Sequence 1979 Number Attacks", RFC 6528, February 2012. 1981 [RFC7042] - Eastlake 3rd, D. and J. Abley, "IANA Considerations and 1982 IETF Protocol and Documentation Usage for IEEE 802 Parameters", 1983 BCP 141, RFC 7042, October 2013. 1985 [RSA BULL1] - "Suggestions for Random Number Generation in Software", 1986 RSA Laboratories Bulletin #1, January 1996. 1988 [RSA BULL13] - "A Cost-Based Security Analysis of Symmetric and 1989 Asymmetric Key Lengths", RSA Laboratories Bulletin #13, Robert 1990 Silverman, April 2000 (revised November 2001). 1992 [SBOX] 1993 - "Practical s-box design", S. Mister, C. Adams, Selected Areas 1994 in Cryptography, 1996. 1995 - "Perfect Non-linear S-boxes", K. Nyberg, Advances in 1996 Cryptography - Eurocrypt '91 Proceedings, Springer-Verland, 1997 1991. 1999 [SCHNEIER] - "Applied Cryptography: Protocols, Algorithms, and Source 2000 Code in C", Bruce Schneier, 2nd Edition, John Wiley & Sons, 2001 1996. 2003 [SHANNON] - "The Mathematical Theory of Communication", University of 2004 Illinois Press, 1963, Claude E. Shannon. (originally from: 2006 Bell System Technical Journal, July and October 1948) 2008 [SHIFT] 2009 - "Shift Register Sequences", Solomon W. Golomb, Aegean Park 2010 Press, Revised Edition 1982. 2011 - "Cryptanalysis of Shift-Register Generated Stream Cypher 2012 Systems", Wayne G. Barker, Aegean Park Press, 1984. 2014 [SHS] - "Secure Hash Standard", US National Institute of Science and 2015 Technology, FIPS 180-4, March 2012. 2017 [SIDR] - 2019 [SP800-90A] - "Recommendation for Random Number Generation Using 2020 Deterministic Random Bit Generators", US National Institute of 2021 Standards and Technology, Special Publication 800-90A, January 2022 2012. 2024 [SP800-90B] - "Recommendation for the Entropy Sources Used for Random 2025 Bit Generation", US National Institute of Standards and 2026 Technology, DRAFT Special Publication 800-90B, August 2012. 2028 [SP800-90C] - "Recommendation for Random Bit Generator (RBG) 2029 Construction", US National Institute of Standards and 2030 Technology, DRAFT Special Publication 800-90C, August 2012. 2032 [STERN] - "Secret Linear Congruential Generators are not 2033 Cryptographically Secure", J. Stern, Proceedings of IEEE STOC, 2034 1987. 2036 [TURBID] - "High Entropy Symbol Generator", John S. Denker, 2037 , 2003. 2039 [USENET] 2040 - RFC 977, "Network News Transfer Protocol", B. Kantor, P. 2041 Lapsley, February 1986. 2042 - RFC 2980, "Common NNTP Extensions", S. Barber, October 2043 2000. 2045 [VENONA] - 2047 [VON NEUMANN] - "Various techniques used in connection with random 2048 digits", von Neumann's Collected Works, Vol. 5, Pergamon Press, 2049 1963, J. von Neumann. 2051 [WSC] - "Writing Secure Code, Second Edition", Michael Howard, David. 2052 C. LeBlanc, Microsoft Press, ISBN 0735617228, December 2002. 2054 [X9.17] - "American National Standard for Financial Institution Key 2055 Management (Wholesale)", American Bankers Association, 1985. 2057 [X9.82] - "Random Number Generation", American National Standards 2058 Institute, ANSI X9F1, work in progress. 2060 Appendix A: Changes from [RFC4086] 2062 1. Deleted changes from RFC 1750. See [RFC4086] if you are 2063 interested. 2065 2. Eliminate any appearance of recommending MD* algorithms or SHA-0 2066 or SHA-1 or DES. 2068 3. Update many RFC and other references such as 802.11i-2004 -> 2069 802.11-2012, ... 2071 4. Add references such as [SIDR], ... 2073 5. Update based on the revelations released by Edward J. Snowden. 2074 Basically, these point to a much higher probability of nation 2075 state sponsored corruption of hardware random number generators 2076 or deterministic pseudo-random number generator standards. The 2077 lesson is never trust one source of randomness. 2079 6. Add references to NIST SP800-90A, SP800-90B, and SP800-90C. 2081 X. Substantial editorial changes 2083 Author's Addresses 2085 Donald E. Eastlake 3rd 2086 Huawei Technologies 2087 155 Beaver Street 2088 Milford, MA 01757 USA 2090 Telephone: +1 508-333-2270 2091 EMail: d3e3e3@gmail.com 2093 Steve Crocker 2094 Shinkuro 2096 EMail: steve@stevecrocker.com 2098 Charlie Kaufman 2099 Microsoft 2101 Email: charliek@microsoft.com> 2103 Jeffrey I. Schiller 2104 MIT, Room E17-110A 2105 77 Massachusetts Avenue 2106 Cambridge, MA 02139-4307 USA 2108 Telephone: +1 617-910-0259 2109 E-mail: jis@mit.edu 2111 Copyright and IPR Provisions 2113 Copyright (c) 2013 IETF Trust and the persons identified as the 2114 document authors. All rights reserved. 2116 This document is subject to BCP 78 and the IETF Trust's Legal 2117 Provisions Relating to IETF Documents 2118 (http://trustee.ietf.org/license-info) in effect on the date of 2119 publication of this document. Please review these documents 2120 carefully, as they describe your rights and restrictions with respect 2121 to this document. Code Components extracted from this document must 2122 include Simplified BSD License text as described in Section 4.e of 2123 the Trust Legal Provisions and are provided without warranty as 2124 described in the Simplified BSD License. The definitive version of 2125 an IETF Document is that published by, or under the auspices of, the 2126 IETF. Versions of IETF Documents that are published by third parties, 2127 including those that are translated into other languages, should not 2128 be considered to be definitive versions of IETF Documents. The 2129 definitive version of these Legal Provisions is that published by, or 2130 under the auspices of, the IETF. Versions of these Legal Provisions 2131 that are published by third parties, including those that are 2132 translated into other languages, should not be considered to be 2133 definitive versions of these Legal Provisions. For the avoidance of 2134 doubt, each Contributor to the IETF Standards Process licenses each 2135 Contribution that he or she makes as part of the IETF Standards 2136 Process to the IETF Trust pursuant to the provisions of RFC 5378. No 2137 language to the contrary, or terms, conditions or rights that differ 2138 from or are inconsistent with the rights and licenses granted under 2139 RFC 5378, shall have any effect and shall be null and void, whether 2140 published or posted by such Contributor, or included with or in such 2141 Contribution.