1 00:00:00,000 --> 00:00:00,540 All right. 2 00:00:00,540 --> 00:00:01,560 Hello, everyone. 3 00:00:01,800 --> 00:00:03,400 I go by Infocalypse. 4 00:00:03,400 --> 00:00:07,620 This is my talk, Cracking Chaos, Making, Using, and Breaking Pseudo-Random Number Generators. 5 00:00:07,820 --> 00:00:10,480 It is my first time speaking, so in accordance... 6 00:00:20,420 --> 00:00:20,960 Great. 7 00:00:20,960 --> 00:00:22,500 Nothing like whiskey at noon, right? 8 00:00:23,920 --> 00:00:24,840 All right. 9 00:00:24,840 --> 00:00:28,280 So we're going to start off with some preliminaries. 10 00:00:28,800 --> 00:00:30,280 What is randomness? 11 00:00:30,280 --> 00:00:31,940 And it's kind of hard to define. 12 00:00:33,020 --> 00:00:38,320 So there's a whole lot of debate over this in the physics community, so I am not even going to try because that is not what I do. 13 00:00:38,320 --> 00:00:42,940 But we are going to discuss some models of it and give some intuitive explainers, right? 14 00:00:42,940 --> 00:00:48,260 So we have what most people would consider to be true randomness, which is entropy, right? 15 00:00:48,260 --> 00:00:57,020 So if you're out at this casino playing some craps, rolling dice, we can all pretty much intuit that that is some kind of random behavior, right? 16 00:00:58,240 --> 00:01:01,100 The idea is that it's non-deterministic. 17 00:01:01,600 --> 00:01:05,460 So even if you have the same throw, things might not shake out the same. 18 00:01:06,480 --> 00:01:12,860 But for computation, since we're using deterministic machines, we have the random oracle model. 19 00:01:13,540 --> 00:01:18,640 So the easiest way to think about the random oracle model is like we have a gnome in a box, right? 20 00:01:19,300 --> 00:01:20,840 And this gnome has a book. 21 00:01:20,840 --> 00:01:22,920 He's got some, once again, dice in there. 22 00:01:22,920 --> 00:01:25,580 And there's a little hole that you can pass notes through. 23 00:01:25,580 --> 00:01:38,180 So you write something down on a note, you pass it through the box, give it to the gnome, gnome sees it, he's going to write down what was on the note, roll some dice, give you out a number, and then you're going to do that again, write a different note, 24 00:01:38,180 --> 00:01:43,920 pass it in the box, he's going to repeat the process, write down the number, or write down the note, generate a number, give it back out. 25 00:01:44,220 --> 00:01:50,340 But if you give him the first thing you wrote down again, what's going to end up happening is he's just going to look in his book and give you the same number. 26 00:01:50,640 --> 00:01:53,500 That is the very, very intuitive explanation of this. 27 00:01:53,500 --> 00:01:58,020 It is much more rigorous informal definition, but yeah. 28 00:01:59,120 --> 00:02:02,600 So and then the weakest definition we have is statistical randomness. 29 00:02:02,600 --> 00:02:06,840 And this is what most people will be familiar with if you've ever worked with PRNGs. 30 00:02:07,140 --> 00:02:10,120 This is your test suites like Die Hard or Test 201. 31 00:02:10,120 --> 00:02:15,760 This is where we're going to be testing, you know, does this look like random, do these look like random numbers? 32 00:02:15,760 --> 00:02:17,280 Does this make sense as random data? 33 00:02:17,340 --> 00:02:18,220 Statistically. 34 00:02:18,600 --> 00:02:22,680 But it is not as strong as an assertion as a random oracle. 35 00:02:24,560 --> 00:02:26,840 So we're going to start off with true randomness, right? 36 00:02:27,160 --> 00:02:30,600 It's an essential but expensive commodity on computers. 37 00:02:31,340 --> 00:02:33,760 We generate it a few different ways. 38 00:02:33,760 --> 00:02:35,620 The most common is system entropy. 39 00:02:35,620 --> 00:02:43,680 So this is going to be things that are mixed together, like mouse movements or load times. 40 00:02:43,980 --> 00:02:47,060 All kinds of fun system processes, usually. 41 00:02:47,820 --> 00:02:52,680 And that is what usually powers the randomness used in your OS. 42 00:02:52,680 --> 00:02:55,600 So like defrandom, wrandom, that's what seeds it. 43 00:02:55,600 --> 00:02:57,740 And historically, that's actually what was outputted. 44 00:02:58,260 --> 00:03:05,280 And then for more demanding scenarios, we have hardware random number generators, which is what you can see depicted up there. 45 00:03:07,200 --> 00:03:18,200 Essentially, they are little additions you can make to your machine that allow you to more efficiently sample randomness, usually from some kind of temperature or pressure or whatever it may be. 46 00:03:19,540 --> 00:03:22,760 So why do we care about true randomness? 47 00:03:22,980 --> 00:03:24,760 Well, one, statistics. 48 00:03:24,760 --> 00:03:27,720 It's the base for how we evaluate random number generators. 49 00:03:27,720 --> 00:03:31,740 And two, in the cryptographic case, it gives us some hardness assertions. 50 00:03:31,740 --> 00:03:38,580 If we have a random bit string, there's no more efficient way to guess it than brute force, because there's no underlying pattern, right? 51 00:03:38,580 --> 00:03:49,040 So if we have, say, 128-bit length bit string, you're expected to find the value in 2 to the 127 iterations, which is just not feasible if it's a truly random bit string. 52 00:03:50,360 --> 00:03:55,520 So that's where we get, like, our whole definition of what n-bit security is. 53 00:03:57,800 --> 00:03:58,560 All right. 54 00:03:58,560 --> 00:04:01,720 So next up, we're on insecure pseudorandom number generators. 55 00:04:02,220 --> 00:04:05,540 This is when we really only care about speed and statistical quality. 56 00:04:05,540 --> 00:04:08,000 We don't really care about hardness assertions. 57 00:04:08,420 --> 00:04:13,860 So in these cases, the promise of n-bit security, as I just discussed, does not usually hold up. 58 00:04:14,240 --> 00:04:18,500 So some examples to kind of ground this are... 59 00:04:18,500 --> 00:04:20,760 So we have some CVEs up here. 60 00:04:21,100 --> 00:04:25,720 We have the bug in Debian's OpenSSL, where their pseudorandom number generator... 61 00:04:28,020 --> 00:04:28,980 Good. 62 00:04:29,020 --> 00:04:29,720 Okay. 63 00:04:30,540 --> 00:04:39,820 So their pseudorandom number generator was weak, and it was not generating dynamic enough numbers, which made a lot of secrets predictable. 64 00:04:40,940 --> 00:04:46,480 So there's actually a whole CWE that classifies this, which is why they're both rated as 7.5s, but it was pretty severe. 65 00:04:46,480 --> 00:04:47,380 It was pretty gnarly. 66 00:04:47,540 --> 00:04:55,540 And then another example is Moodle, which is a PHP framework, was using mercen twisters for token generation to reset account passwords. 67 00:04:55,540 --> 00:05:09,960 So since mercen twisters are invertible, ta-da, I can just go ask to reset some arbitrary account, invert the generator, and now I know what's coming next, and so I know all the account generation codes going forward. 68 00:05:10,460 --> 00:05:13,500 So yeah, those are some examples. 69 00:05:13,680 --> 00:05:17,780 So now we're going to start talking about types of insecure pseudorandom number generators. 70 00:05:18,040 --> 00:05:24,020 So we will start off with, historically, one of the earliest, which are linear congruential generators. 71 00:05:25,760 --> 00:05:28,620 They are extremely simple. 72 00:05:28,660 --> 00:05:30,560 They can be fairly fast. 73 00:05:31,240 --> 00:05:32,940 They were prolific in early computing. 74 00:05:32,940 --> 00:05:35,500 You don't really see too many of them anymore, which is a good thing. 75 00:05:35,840 --> 00:05:41,680 But if you are going to find one, it's typically going to be on some kind of legacy system, because these are old generators. 76 00:05:43,740 --> 00:05:47,000 So the way they work is we have a little recurrence here. 77 00:05:47,000 --> 00:05:52,740 We have X of N plus 1 equals A times X of N plus C Magillo M. 78 00:05:53,420 --> 00:05:58,480 So the maximal period on these is typically considered to be M, or about M, rather. 79 00:05:58,480 --> 00:06:04,360 So we have three forms of them that we'll be briefly discussing, and one we're going to be going into a bit more detail on, because it's interesting. 80 00:06:04,680 --> 00:06:09,720 So we have the case where the additive is zero, and the modulus is prime. 81 00:06:10,180 --> 00:06:13,360 These will give you a near maximal period, but they're pretty slow. 82 00:06:14,660 --> 00:06:17,300 So they're not too often used. 83 00:06:17,400 --> 00:06:22,080 And then we have the case where the additive is once again zero, and M is a power of two. 84 00:06:22,900 --> 00:06:25,240 These are non-maximal periods, usually. 85 00:06:25,260 --> 00:06:26,100 Well, not usually. 86 00:06:26,100 --> 00:06:28,100 They are always non-maximal periods. 87 00:06:28,440 --> 00:06:29,880 But they are fast. 88 00:06:30,120 --> 00:06:32,920 Once again, nobody really uses them, because non-maximal periods. 89 00:06:32,920 --> 00:06:40,320 And the next case, which is the one we're going to be discussing more deeply, is when the additive is not equal to zero, and M is a power of two. 90 00:06:40,400 --> 00:06:43,180 These are both maximal period, and they are fast. 91 00:06:46,080 --> 00:06:51,680 So linear congruential generators are unfortunately not statistically sufficient. 92 00:06:52,340 --> 00:06:56,840 They are easily, easily, easily detectable by spectral test failure. 93 00:06:57,340 --> 00:07:05,060 So for people that have used statistical test suites before, you'll probably recognize that name. 94 00:07:06,000 --> 00:07:19,180 And they also follow something called Marsaglia's theorem from George Marsaglia, which states that when you plot the outputs from a linear congruential generator in higher dimensions, so as we can see there, it's three dimensions, they lie in planes or hyperplanes. 95 00:07:19,180 --> 00:07:29,560 So from that picture there, you can clearly see those are outputs from a linear congruential generator, pretty weak one, and so the planes are quite distinct. 96 00:07:31,700 --> 00:07:33,840 So how do we break these? 97 00:07:35,420 --> 00:07:40,400 Through the same means and reasons why they suck statistically, we're going to break it. 98 00:07:40,560 --> 00:07:52,400 So we're going to walk through the general approach, and then we will showcase both a of numerical recipes, and then also a visualization in 3D of Marsaglia's theorem. 99 00:07:54,020 --> 00:07:56,640 So let's walk through this real quick. 100 00:07:56,640 --> 00:07:59,220 So given several outputs, you need at least five. 101 00:07:59,220 --> 00:08:02,780 You're going to form pseudo-Hankel matrices of that form. 102 00:08:03,820 --> 00:08:15,400 And you're going to calculate the determinant of these matrices and enumerate the greatest common divisor of them, which will give you a multiple of the modulus or the modulus itself, if you're really lucky. 103 00:08:16,160 --> 00:08:35,560 You can usually deduce what the modulus is just knowing the types of these generators, but if you can't, try and get at least one more output, do it again, same operation, except D2 with D3, and then take the GCD of the results in value of D1, D2, and D2, 104 00:08:35,560 --> 00:08:40,640 D3, and usually that's more than enough to actually nail down the modulus. 105 00:08:41,680 --> 00:08:46,980 So once we've got M, we're going to go through the simple case, because there's a bit of complexity with these. 106 00:08:47,380 --> 00:08:49,680 We are going to look for the multiplicand A. 107 00:08:50,940 --> 00:09:02,820 So what you want is the difference of the second output and the first output, and M to be coprime, because that gives us an easy, nice formulation for the multiplicand. 108 00:09:03,340 --> 00:09:09,460 Otherwise, we get to solve linear Diophantine equations, so it's less fun, but it is doable. 109 00:09:10,020 --> 00:09:14,440 We're not going to talk too much about that, though, because I only have so much time. 110 00:09:15,020 --> 00:09:27,920 So given the simpler case, we're just going to enumerate A according to that equation given right there, product of O3 minus O2 times the inverse of O2 minus O1 modulo M. 111 00:09:29,880 --> 00:09:35,220 And then all you have to do to find C is just set up that last equation. 112 00:09:35,220 --> 00:09:37,060 It's pretty easy to break these. 113 00:09:37,060 --> 00:09:38,520 It's very fast. 114 00:09:38,700 --> 00:09:42,580 And we will actually see that right now. 115 00:09:42,860 --> 00:09:48,400 So we have... this is a linear congruential generator. 116 00:09:48,400 --> 00:09:49,980 There's two of them here. 117 00:09:49,980 --> 00:09:55,940 We're breaking RANQD1, and then we're visualizing a much weaker one, because it's a lot easier to see the planes. 118 00:09:57,060 --> 00:09:59,980 So I know crypto demos are everyone's favorite thing. 119 00:09:59,980 --> 00:10:01,300 It's very exciting. 120 00:10:05,100 --> 00:10:06,740 But... sorry for the lag there. 121 00:10:06,740 --> 00:10:09,640 I wrote this on a much more powerful computer. 122 00:10:11,280 --> 00:10:13,780 So in the console there, we can see the outputs. 123 00:10:13,780 --> 00:10:15,040 We can see the determinants. 124 00:10:15,040 --> 00:10:20,500 We can deduce what the characteristic is. 125 00:10:20,760 --> 00:10:22,420 We test if it's co-prime. 126 00:10:22,420 --> 00:10:23,260 It is. 127 00:10:23,280 --> 00:10:27,200 We're able to pull out A, C, and then we can just invert the seed. 128 00:10:27,200 --> 00:10:37,020 And then in our lovely spinning cube, we can see as it spins that sometimes the dots will all line up in those planes. 129 00:10:37,300 --> 00:10:41,760 And that's exactly what a Mersogli's theorem would expect and what makes these breakable. 130 00:10:42,120 --> 00:10:46,320 So I think that should be enough for that demo. 131 00:10:46,740 --> 00:10:49,440 And we are now on to linear feedback shift registers. 132 00:10:49,440 --> 00:10:51,200 This is another classic, classic generator. 133 00:10:51,200 --> 00:10:52,540 You still find these today. 134 00:10:53,060 --> 00:10:54,360 Mostly in embedded. 135 00:10:54,360 --> 00:10:58,960 But they make use of bitwise arithmetic for fast pseudorandom bits. 136 00:10:59,100 --> 00:11:02,020 Once again, they have multiple forms. 137 00:11:02,020 --> 00:11:06,940 We are going to be discussing the Fibonacci form because it is the easiest to explain. 138 00:11:07,860 --> 00:11:11,420 And also usually what you see more on the hardware side of things. 139 00:11:11,600 --> 00:11:15,320 Depicted up there, you can see a visualization of one. 140 00:11:17,540 --> 00:11:23,800 So Fibonacci generators work by selecting inputs, which in the typical nomenclature is called a tap. 141 00:11:24,920 --> 00:11:26,400 Corresponding to a binary polynomial. 142 00:11:26,840 --> 00:11:36,740 If it's polynomial in the given field, which is usually a length of register, the period will be maximal, equal to 2 to the n minus 1, where n is the degree of the feedback polynomial. 143 00:11:37,940 --> 00:11:43,900 So we're going to actually just kind of walk through an iteration of one because once you see it, you go, oh, that's really easy. 144 00:11:45,060 --> 00:11:46,020 So here's our seed. 145 00:11:46,020 --> 00:11:49,600 We have 0, 0, 1, 1, 0, 1, 0, 1. 146 00:11:49,600 --> 00:11:53,260 And then we have our feedback polynomial, x to the 7 plus x to the 6 plus 1. 147 00:11:54,800 --> 00:12:00,100 The way that the actual generators work is it's flipped. 148 00:12:00,420 --> 00:12:01,420 Sorry, questions. 149 00:12:01,420 --> 00:12:03,040 There's a question and period at the end. 150 00:12:05,940 --> 00:12:11,740 So we're going to have an output bit of 1, which is the last bit. 151 00:12:12,240 --> 00:12:17,060 We're going to take the 6th and the 7th, which is actually the 7th and the 8th because of the 1. 152 00:12:17,720 --> 00:12:19,780 And we are going to exclusive or them. 153 00:12:19,780 --> 00:12:21,680 So 0s or 1 is 1. 154 00:12:22,220 --> 00:12:23,580 And we stick that in the beginning. 155 00:12:23,580 --> 00:12:24,700 Ta-da. 156 00:12:24,700 --> 00:12:25,900 Linear feedback shift register. 157 00:12:28,800 --> 00:12:32,640 So they're pretty simple, but they are very fast. 158 00:12:32,640 --> 00:12:33,640 They're very efficient. 159 00:12:33,640 --> 00:12:36,280 But they are, once again, very weak. 160 00:12:36,380 --> 00:12:39,640 They notably fail two tests for distinguishing. 161 00:12:39,640 --> 00:12:42,520 Obviously the linearity test, which the LCT also fails. 162 00:12:42,540 --> 00:12:47,920 And the binary matrix rank test that is extremely distinguishing with linear feedback shift registers. 163 00:12:48,800 --> 00:12:52,620 But with the way you break these, it's an algorithm called BrilleCamp Massey. 164 00:12:52,620 --> 00:12:53,680 We won't be diving into it. 165 00:12:53,680 --> 00:12:55,260 Once again, I only have so much time. 166 00:12:55,540 --> 00:12:58,180 But it's more prudent to just try BrilleCamp Massey. 167 00:12:58,180 --> 00:13:06,040 If you get a short linear feedback shift register as a result of BrilleCamp Massey, congrats, it was a linear feedback shift register and you just inverted it. 168 00:13:06,040 --> 00:13:11,980 If you get one that's about half the length of the input that you gave it, probably not a linear feedback shift register. 169 00:13:13,820 --> 00:13:15,720 So next up we have Mersenne twisters. 170 00:13:15,720 --> 00:13:18,640 This is one of the most popular generators out there. 171 00:13:18,720 --> 00:13:20,720 It is the default in Python. 172 00:13:20,720 --> 00:13:22,800 It is all over the place. 173 00:13:22,920 --> 00:13:27,520 It is built off of a laundry list of previous stuff, generalized feedback shift registers. 174 00:13:27,520 --> 00:13:30,860 Then you have twisted generalized feedback shift registers, rationalized. 175 00:13:31,200 --> 00:13:34,740 And then you have the Mersenne twister, which comes after that. 176 00:13:34,960 --> 00:13:38,720 So it's generated by, once again, yet another relation. 177 00:13:39,420 --> 00:13:42,320 Sorry, the cursor made that a little ambiguous. 178 00:13:43,320 --> 00:13:51,860 So what it's essentially doing is it's manipulating its own internal state to form words through both concatenation and exclusive ORs. 179 00:13:52,300 --> 00:13:59,060 And then it performs a matrix multiplication at the end, which comes from the twisted generalized feedback shift register. 180 00:14:00,980 --> 00:14:06,620 So they are pretty high quality pseudo random number generators, which is why they're the default everywhere. 181 00:14:07,600 --> 00:14:16,100 They have an obscenely long period, at least with Mersenne twister 19937, of 2 to the 19937 minus 1. 182 00:14:16,100 --> 00:14:27,880 They have a state width of 624 32-bit words, and it is equidistributed up to 624 dimensions after tempering, which is the final part of the Mersenne twister algorithm. 183 00:14:28,200 --> 00:14:34,600 There with the depiction we can see from the original paper the specification for MT19937. 184 00:14:36,440 --> 00:14:39,460 It is very strange. 185 00:14:39,460 --> 00:14:41,040 That paper is very strange. 186 00:14:42,780 --> 00:14:51,780 So the thing with Mersenne twister is it's a lot harder to detect than the previous algorithms, because there's multiple, multiple different variants. 187 00:14:51,780 --> 00:14:56,820 But since MT19937 is by far the most prolific, we're going to discuss detecting that one. 188 00:14:56,820 --> 00:15:09,780 It fails two statistical tests, notably in the test U01 big crush suite, which both have to do with equidistribution in very, very high dimensions, which is what Mersenne twister fails at. 189 00:15:09,780 --> 00:15:16,840 So if you can test in dimension higher than 623, you'll start to see that Mersenne twister deteriorates in equidistribution. 190 00:15:17,960 --> 00:15:34,100 In the older versions, there was also a pretty infamous warm-up period where if you had a really low Hamming weight, so not a lot of 1s in your seed, it would take a pretty good while to spin it up to get a correct number or a statistically correct number of 1s for randomness, 191 00:15:34,100 --> 00:15:37,420 but this has been fixed in newer versions, so it's not a surefire way. 192 00:15:37,980 --> 00:15:40,720 So how do we invert Mersenne twister? 193 00:15:41,300 --> 00:15:44,260 I mentioned earlier the tempering technique. 194 00:15:44,260 --> 00:15:46,340 What it is is basically just a matrix multiplication. 195 00:15:46,340 --> 00:15:50,600 It's a type of output whitening to make sure it has the statistical qualities we want. 196 00:15:51,040 --> 00:15:56,680 The matrix that we do this with is non-singular, therefore it is invertible. 197 00:15:56,740 --> 00:16:04,500 So we just invert the tempering matrix, which is public, apply it to outputs, we collect 624 of them, and now we've cloned state. 198 00:16:04,500 --> 00:16:09,880 So you can now predict all the future outputs of a Mersenne twister just by doing that. 199 00:16:10,880 --> 00:16:14,420 So don't use it in security-sensitive context. 200 00:16:16,500 --> 00:16:20,020 Now on to our last insecure generators. 201 00:16:20,020 --> 00:16:22,220 We have counter-based PRNGs. 202 00:16:22,220 --> 00:16:26,680 These are pretty new, and they take inspiration from block ciphers in counter mode. 203 00:16:27,300 --> 00:16:31,300 They typically use deliberately weakened cryptographic primitives and techniques. 204 00:16:31,300 --> 00:16:39,200 They are extraordinarily fast as a result of optimizations, and sometimes hardware equipment for it. 205 00:16:39,460 --> 00:16:45,440 The most common reference you'll see for these kinds of generators is the Random123 library, which was published by D.E. 206 00:16:45,440 --> 00:16:45,910 Shaw. 207 00:16:46,240 --> 00:16:52,260 It includes three generators, which are ARS, 3FRY, and PHYLOX. 208 00:16:52,280 --> 00:16:58,720 ARS is based off of a weakened AES, 3FRY is weakened 3FISH, and PHYLOX is a completely original product. 209 00:16:58,720 --> 00:17:04,660 So these generators have gotten quite popular pretty recently. 210 00:17:04,660 --> 00:17:05,530 They're used everywhere. 211 00:17:06,020 --> 00:17:09,800 We have them in curand, we just got it in C++ 26. 212 00:17:10,600 --> 00:17:16,100 NumPy, Intel's OneAPI, HPC stuff, and there are many, many more. 213 00:17:16,560 --> 00:17:26,460 These are pretty notable because they all passed the most stringent, or usually most agreed upon to be the most stringent test we have for statistical tests, which is TestU01's big crush. 214 00:17:26,460 --> 00:17:29,440 And all of these passed in their official variants. 215 00:17:29,780 --> 00:17:31,220 They have obscenely long periods. 216 00:17:31,220 --> 00:17:34,280 Once again, it's about 2 to 128, at least per D.E. 217 00:17:34,280 --> 00:17:35,100 Shaw's numbers. 218 00:17:35,600 --> 00:17:39,700 However, given they use cryptographic primitives, some people make the assumption that they are cryptographic. 219 00:17:39,700 --> 00:17:40,320 They are not. 220 00:17:40,320 --> 00:17:46,160 They have no cryptanalysis has been done of them, and there is no claims of security made by D.E. 221 00:17:46,160 --> 00:17:46,700 Shaw. 222 00:17:46,700 --> 00:17:49,400 So keep that in mind if you ever want to use these. 223 00:17:50,120 --> 00:17:54,900 We're going to talk about PHYLOX today, because it is what I have by far the most experience with. 224 00:17:54,900 --> 00:18:00,020 I am currently doing great battle with Red Hat employees to get it merged into lib standard C++. 225 00:18:00,760 --> 00:18:03,820 So yeah, it's fun. 226 00:18:03,820 --> 00:18:05,180 Almost there, almost there. 227 00:18:06,440 --> 00:18:10,600 So once again, it is a completely original product of random 1, 2, 3. 228 00:18:10,600 --> 00:18:12,160 It's their own device. 229 00:18:12,340 --> 00:18:16,840 So it's a hybrid Feistel network substitution structure. 230 00:18:16,860 --> 00:18:18,940 It has multiple forms. 231 00:18:19,260 --> 00:18:22,580 There's multiple 32-bit forms and multiple 64-bit forms. 232 00:18:22,580 --> 00:18:30,340 And then the 2 you see in the front or the 4 you see in the front has to do with the internal state counter. 233 00:18:30,340 --> 00:18:33,100 There's not really a state in this, but it's the width of the counter. 234 00:18:34,380 --> 00:18:37,040 Once again, all the official variants pass big crush. 235 00:18:37,100 --> 00:18:41,980 And this is the most common generator you'll see from random 1, 2, 3 by far. 236 00:18:43,440 --> 00:18:48,640 We're going to discuss PHYLOX 4 by 32, 10 specifically in more detail. 237 00:18:48,640 --> 00:18:53,000 You can actually see PHYLOX, the implementation there. 238 00:18:53,000 --> 00:18:59,020 I know it might be a little grainy, but yeah, that's the main loop of PHYLOX. 239 00:19:00,460 --> 00:19:07,240 So this wonderful little graph is my mock-up of how PHYLOX works. 240 00:19:07,820 --> 00:19:11,940 So C0, 1, 2, 3, that's our state. 241 00:19:12,680 --> 00:19:18,360 It's essentially just, in this case, a 128-bit word broken up into four limbs. 242 00:19:19,820 --> 00:19:26,180 Those of you familiar with PHYSTL networks will see that we're swapping C0 and C2 in the very PHYSTL pattern. 243 00:19:27,400 --> 00:19:30,580 And then C1 and C3 are substituted. 244 00:19:30,860 --> 00:19:36,020 In this case, operations take place over the ring Z2 to the 32Z. 245 00:19:36,520 --> 00:19:39,320 And it's multiplied with a unitary value. 246 00:19:39,380 --> 00:19:42,040 So you get a uniform output. 247 00:19:42,040 --> 00:19:44,860 It's infuriating, actually, to try and break this. 248 00:19:46,700 --> 00:19:50,760 But then with our triangles, that's where things kind of deviate. 249 00:19:51,080 --> 00:19:55,580 You have the mull-low operation, which is A times B mod 2 to 32. 250 00:19:55,580 --> 00:19:58,680 You take the low bits of the 64-bit word that's produced. 251 00:19:58,920 --> 00:20:01,740 And then mull-high, which is A times B right shift 32. 252 00:20:01,740 --> 00:20:03,660 It's just the high bits of the same operation. 253 00:20:03,980 --> 00:20:07,860 So with the triangles pointed up, that is a mull-high operation. 254 00:20:07,860 --> 00:20:09,880 With the triangles pointed down, that's a mull-low. 255 00:20:09,980 --> 00:20:13,900 And then you see the KSL, KSR, that is the key schedule. 256 00:20:13,900 --> 00:20:15,760 It's just an affine transformation. 257 00:20:16,660 --> 00:20:18,780 It's a very simple key schedule. 258 00:20:19,060 --> 00:20:24,060 If there are weaknesses that can be broken, it probably has to do with that. 259 00:20:26,520 --> 00:20:30,140 So we are going to move forward into flaws in detection. 260 00:20:31,380 --> 00:20:33,660 There is currently no differentiator for this. 261 00:20:33,660 --> 00:20:34,520 There's no way to tell. 262 00:20:34,520 --> 00:20:35,820 It's not uniformly random. 263 00:20:35,820 --> 00:20:36,740 There is no break. 264 00:20:36,900 --> 00:20:39,020 But this doesn't mean it's safe. 265 00:20:39,020 --> 00:20:42,680 Once again, this has not been formally cryptanalyzed by anyone, at least to my knowledge. 266 00:20:42,680 --> 00:20:45,100 This hasn't been studied. 267 00:20:45,100 --> 00:20:49,580 There's no claims of security from the manufacturer and the designers. 268 00:20:49,940 --> 00:20:53,100 So it is best to just avoid it in security sensitive context. 269 00:20:53,100 --> 00:20:54,120 Use something trusted. 270 00:20:54,120 --> 00:20:58,200 However, for your general randomness needs other than that, it's phenomenal. 271 00:21:00,280 --> 00:21:03,400 So we are now moving into the second part of the talk. 272 00:21:03,400 --> 00:21:05,000 And things get a little more complicated here. 273 00:21:05,000 --> 00:21:08,880 This is where we are talking about secure PRNGs or CSPRNGs. 274 00:21:08,880 --> 00:21:10,180 And this has to go be special. 275 00:21:10,180 --> 00:21:11,840 They call them DRBGs. 276 00:21:13,700 --> 00:21:19,220 These give us usually high quality pseudo randomness with additional hardness assertions. 277 00:21:19,220 --> 00:21:24,700 So basically what we typically do is we are willing to sacrifice speed in order to gain some kind of cryptographic hardness assertion. 278 00:21:24,740 --> 00:21:30,240 Because this is the backbone of the modern cryptographic stack. 279 00:21:30,840 --> 00:21:39,280 So all these algorithms are explicitly designed to be hard to invert or otherwise predict in order to keep that promise of end bit security that we talked about earlier. 280 00:21:39,560 --> 00:21:43,660 As we can see, my meme straight out of like 2018 up there. 281 00:21:44,540 --> 00:21:52,880 And then on the other side, we have the description of basically how Linux has worked since 2020. 282 00:21:53,180 --> 00:21:58,600 Where it will take system entropy, the other thing we talked about earlier, and feed it into cha-cha 20. 283 00:21:59,080 --> 00:22:03,600 And historically, and that becomes dev urandom and dev random. 284 00:22:03,600 --> 00:22:06,960 Historically they had different behavior and they would just output system entropy. 285 00:22:06,960 --> 00:22:12,400 But that had a lot of issues where you could either cause a DOS or you could get predictable random numbers. 286 00:22:12,400 --> 00:22:17,120 It just was a bad time, so they swapped over to just cha-cha 20, which is an example of a CSPRNG. 287 00:22:18,780 --> 00:22:20,660 We're going to talk about stream ciphers. 288 00:22:21,520 --> 00:22:22,540 Real quick. 289 00:22:22,540 --> 00:22:34,100 So these, it's a little weird seeing like symmetric crypto in a talk, but it's because basically all stream cipher is, is a cryptographically hard random number generator that you XOR the output of with your plain text. 290 00:22:34,100 --> 00:22:37,520 If we just ignore the plain text part of it, ta-da, we have a CSPRNG. 291 00:22:38,440 --> 00:22:41,860 We just use the key stream as a pseudo random number. 292 00:22:41,960 --> 00:22:50,940 If the key stream is predictable, the data isn't secure, so if you believe in stream ciphers, you believe in using them as CSPRNGs, the good news, they're usually really fast. 293 00:22:51,320 --> 00:22:57,060 Some examples of this are cha-cha 20, RC4, and Rabbit, which was from the E-stream competition. 294 00:22:58,480 --> 00:23:01,320 We're going to talk about cha-cha 20 and RC4. 295 00:23:02,720 --> 00:23:05,980 RC4 is a great example of what not to do. 296 00:23:07,080 --> 00:23:09,820 So it comes from RSA security. 297 00:23:10,060 --> 00:23:14,480 It's Revest cipher 4 or Ron's code 4, depending on who you ask. 298 00:23:14,480 --> 00:23:16,940 There's been a lot of issues found with this cipher. 299 00:23:17,540 --> 00:23:20,460 There's the second bit bias, which is what we're going to be talking about today. 300 00:23:20,460 --> 00:23:22,220 There's been some key schedule weaknesses. 301 00:23:22,460 --> 00:23:28,620 Historically it was used in TLS until it wasn't because people were breaking everything that had to do with it. 302 00:23:28,620 --> 00:23:31,980 It was specifically disallowed in RFC 7465. 303 00:23:31,980 --> 00:23:34,820 If you want to go read that, it is moderately entertaining. 304 00:23:36,620 --> 00:23:44,900 It's also historically been used as a CSPRNG in multiple systems, if I remember correctly, the BSD family used to use it as ARC4. 305 00:23:47,000 --> 00:23:50,220 But they no longer do that for reasons we're about to get into. 306 00:23:51,140 --> 00:23:53,700 So as I mentioned, we're talking about the second byte bias. 307 00:23:53,700 --> 00:23:56,680 Here is the initialization step of RC4. 308 00:23:56,680 --> 00:23:58,840 We have two pointers, I, J. 309 00:23:59,120 --> 00:24:01,200 And we have a generation loop. 310 00:24:01,200 --> 00:24:08,320 So some preliminary before this is we have some arbitrary size state S, which is just an array of numbers. 311 00:24:08,320 --> 00:24:11,820 It's a permutation, rather, of the list of N numbers. 312 00:24:12,440 --> 00:24:18,300 So you increment your pointer I, then J is added with S sub I. 313 00:24:18,680 --> 00:24:27,460 And then you swap the values and output Z as the index of S that S of I plus S of J is at. 314 00:24:28,480 --> 00:24:34,940 Pretty simple cipher, which is what made it kind of attractive for a lot of people when it first came out. 315 00:24:37,880 --> 00:24:42,640 But as with all good things, this thing did not work out well for us. 316 00:24:42,740 --> 00:24:49,300 So usually when we do statistical testing and the stuff I've discussed thus far, it's with statistical test suites. 317 00:24:50,980 --> 00:25:01,200 This passes pretty well for those, because what they do is they take large quantities of numbers over a very long period of time, and they perform tests on that. 318 00:25:01,620 --> 00:25:12,840 So what we're now going to talk about is polynomial sampling, which basically says if we have a whole bunch of streams and we're just looking at the early parts, can we distinguish this from true random quickly in polynomial time? 319 00:25:13,320 --> 00:25:14,740 The answer is yes. 320 00:25:14,740 --> 00:25:17,000 We can do it with greater than a 60% success rate. 321 00:25:17,000 --> 00:25:18,660 If I remember correctly, it's about 64. 322 00:25:18,660 --> 00:25:34,180 And what this is, is with RC4, there is a non-trivial increase in the probability the second byte will be zero, which is a statistical distinguisher, which is not good for random numbers. 323 00:25:35,940 --> 00:25:39,960 So some of you might be thinking, okay, can we mitigate that? 324 00:25:39,960 --> 00:25:41,080 It's just the second number. 325 00:25:41,080 --> 00:25:42,120 The answer is yes. 326 00:25:42,120 --> 00:25:42,980 Yes, you absolutely can. 327 00:25:42,980 --> 00:25:46,160 You can just not output and skip a little bit, and you're good. 328 00:25:46,700 --> 00:25:50,900 The real question becomes, should we use a mitigated version of a flawed cipher? 329 00:25:50,900 --> 00:25:56,340 And the answer, at least in my opinion, is no, because usually where you find one issue, others follow. 330 00:25:56,340 --> 00:25:58,220 That's the basis of cryptanalysis. 331 00:25:58,220 --> 00:26:02,980 It's usually a very long trail where you find something and then a whole bunch of issues follow. 332 00:26:03,320 --> 00:26:04,820 So what should you use? 333 00:26:04,820 --> 00:26:10,560 Sorry, we have another demo of actually detecting the bias in RC4 and showcasing it. 334 00:26:10,860 --> 00:26:16,700 So once again, I wrote this on a much more potent computer, so it's going to take a second. 335 00:26:17,440 --> 00:26:18,880 There we go. 336 00:26:18,900 --> 00:26:23,900 So as you can see, that zero value is spiked well above the expected. 337 00:26:24,280 --> 00:26:25,620 Well above the expected. 338 00:26:25,960 --> 00:26:31,940 Which lines up with the second bias you would expect from the formal analysis. 339 00:26:33,260 --> 00:26:36,020 We did 100,000 streams there. 340 00:26:38,660 --> 00:26:40,020 All right. 341 00:26:40,020 --> 00:26:42,680 So now we're talking about ChaCha20. 342 00:26:42,680 --> 00:26:44,200 This is more of an aside. 343 00:26:44,200 --> 00:26:59,800 It is a very modern arc space cypher, which is and rotates or, developed by Daniel Bernstein to succeed his other cypher. 344 00:26:59,920 --> 00:27:03,540 It has a strong emphasis on side channel resistance. 345 00:27:04,540 --> 00:27:08,920 Best public cryptanalysis, as far as I know, is up to 7 out of 20 rounds. 346 00:27:08,920 --> 00:27:11,080 And it is used in TLS. 347 00:27:11,080 --> 00:27:13,780 Once again, it's used in Linux's DevUrandom, DevRandom. 348 00:27:14,200 --> 00:27:16,740 It's all around a better choice than RC4. 349 00:27:18,140 --> 00:27:19,020 Okay. 350 00:27:19,040 --> 00:27:23,180 So now we're on to our next variant, which are block cyphers in counter mode. 351 00:27:24,220 --> 00:27:35,760 This is a mode of operation for block cyphers where you're given a counter as your plain text instead of your actual data you're trying to encrypt and the output becomes zored with the actual plain text to create the cypher text. 352 00:27:35,760 --> 00:27:38,500 It makes it behave very similarly to a stream cypher. 353 00:27:39,140 --> 00:27:42,720 This also inspired the counter base PRNGs we discussed earlier. 354 00:27:42,720 --> 00:27:50,880 You can quite see it very directly with 3Fry and ours, which very much literally use the routines of 3Fish and AES. 355 00:27:51,900 --> 00:27:55,260 But the big difference here is we're actually using the full blown variants. 356 00:27:55,260 --> 00:27:56,620 So we're using secure primitives. 357 00:27:56,620 --> 00:27:58,080 There are hardness assertions. 358 00:27:58,080 --> 00:28:01,850 There you can see a lovely diagram showcasing counter mode. 359 00:28:04,300 --> 00:28:08,920 Now we're going to start talking a little bit about the NIST generators. 360 00:28:09,790 --> 00:28:11,750 NIST SP890 alpha. 361 00:28:13,100 --> 00:28:18,860 And it discusses all the approved CSPRNGs for use. 362 00:28:18,860 --> 00:28:21,440 And they have a generator of this form. 363 00:28:21,720 --> 00:28:23,920 It is called counter DRBG. 364 00:28:23,920 --> 00:28:24,930 Very creative. 365 00:28:25,920 --> 00:28:35,880 And it officially supports AES 128, 192, 256, and still triple DES, which they try to hide as 3DEA. 366 00:28:36,280 --> 00:28:37,550 Good job, NIST. 367 00:28:40,480 --> 00:28:44,780 So it can really, it really boils down to it's just counter mode. 368 00:28:44,780 --> 00:28:47,520 You just get some additional opportunities to inject entropy. 369 00:28:47,560 --> 00:28:51,280 And technically the framework itself works for any block cipher. 370 00:28:51,280 --> 00:28:55,380 But it's NIST, so they just support the official U.S. 371 00:28:55,380 --> 00:28:56,300 ones. 372 00:28:56,980 --> 00:29:00,080 So counter DRBG is practically secure. 373 00:29:00,080 --> 00:29:01,680 There are no practical breaks on it. 374 00:29:01,680 --> 00:29:08,380 However, there are academic breaks, which means there are theoretical breaks that mathematically work. 375 00:29:08,380 --> 00:29:13,000 They just are impractical to do in a specific amount of, in a feasible amount of time. 376 00:29:13,740 --> 00:29:17,640 It's really only a problem with triple DES, because of course it is. 377 00:29:17,640 --> 00:29:18,800 It's triple DES. 378 00:29:19,140 --> 00:29:24,600 Because of that really small block size, but it's really not an issue when you use AES, which is what you should be doing. 379 00:29:27,280 --> 00:29:42,410 As far as these forms of generators, Bruce Schneier and Ferguson developed one called Fortuna, which is what the BSD family now uses, which is typically considered a superior example to the NIST generator, but NIST is going to NIST. 380 00:29:43,820 --> 00:29:48,880 Now on to yet another NIST generator, hash-based CSPRNGs. 381 00:29:48,880 --> 00:29:52,840 These use the outputs of hash functions as random numbers. 382 00:29:52,840 --> 00:29:56,230 Up there we can literally see NIST's hash DRBG diagram. 383 00:29:58,060 --> 00:29:59,780 These aren't too common. 384 00:29:59,780 --> 00:30:01,140 You don't really see these that often. 385 00:30:01,140 --> 00:30:04,400 But they are of interest with the standardization of SHA-3. 386 00:30:04,400 --> 00:30:07,640 So SHA-3 uses a sponge construction. 387 00:30:08,220 --> 00:30:14,640 Which has now two proofs of indifferentiability from random oracle with very minimal assumptions. 388 00:30:15,180 --> 00:30:26,520 So what this means is that this, in theory, might be one of our best generators for random numbers, not performance-wise, but statistic quality and mathematically. 389 00:30:28,820 --> 00:30:33,280 So it's of note, and I'm really curious to see how that's going to shake out. 390 00:30:33,280 --> 00:30:37,220 There hasn't really been too much study on specifically this construction with SHA-3 yet. 391 00:30:37,220 --> 00:30:39,060 The NIST publication is quite old. 392 00:30:39,060 --> 00:30:42,240 So they only discuss SHA-2 and Merkle-Domgarde constructions. 393 00:30:43,600 --> 00:30:45,680 So we'll see how that goes. 394 00:30:47,740 --> 00:30:49,700 So these are also secure. 395 00:30:49,700 --> 00:30:54,140 There's not really any attacks that apply to them that are specific to this generator. 396 00:30:54,140 --> 00:31:00,220 It's just the usual stuff with Merkle-Domgarde constructions, your length extension attacks, all the usual shenaniganry. 397 00:31:00,760 --> 00:31:04,340 But they're usually not used too often because of speed. 398 00:31:04,340 --> 00:31:11,820 There's not really a good way, other than statistical testing, to assert their quality, their goodness as generators. 399 00:31:12,100 --> 00:31:24,260 But once again, since SHA-3 has been proven indifferentiable in both the classic and the quantum context as of like a month and a half ago, it's going to be really interesting to see how this develops. 400 00:31:25,980 --> 00:31:27,260 So, all right. 401 00:31:28,280 --> 00:31:32,880 We are on our last category here, which are number-theoretic generators. 402 00:31:32,880 --> 00:31:34,000 Now, this is... 403 00:31:35,260 --> 00:31:37,940 Nobody uses these for a very good reason. 404 00:31:37,940 --> 00:31:39,680 They're incredibly slow. 405 00:31:40,380 --> 00:31:42,420 But they are very interesting. 406 00:31:42,420 --> 00:31:44,940 So we have some examples here. 407 00:31:44,940 --> 00:31:48,460 We have BlumBlumShub, DuallyCDRBG, and the Blum and Cayley generator. 408 00:31:49,060 --> 00:31:57,600 And these get their hardness based on usually problems from number theory, similarly to how we do our asymmetric cryptography. 409 00:31:58,120 --> 00:32:00,680 So, as you can see, graduate techs in mathematics. 410 00:32:00,680 --> 00:32:02,320 Or, sorry, didn't graduate techs in mathematics. 411 00:32:02,320 --> 00:32:03,780 Introduction to that thing. 412 00:32:03,820 --> 00:32:05,260 But only for people who already know it. 413 00:32:05,260 --> 00:32:06,960 So that's kind of the tone we're taking here. 414 00:32:07,400 --> 00:32:11,280 Because I am not doing a lecture in abstract algebra. 415 00:32:11,280 --> 00:32:15,000 But we're going to start moving. 416 00:32:15,000 --> 00:32:18,400 So we're going to talk about BlumBlumShub and DuallyCDRBG. 417 00:32:18,400 --> 00:32:18,900 I know. 418 00:32:18,900 --> 00:32:19,760 Shocking. 419 00:32:20,900 --> 00:32:23,820 Yes, this algorithm is really named BlumBlumShub. 420 00:32:24,260 --> 00:32:27,180 It is very funny, but that is really what it's named. 421 00:32:28,060 --> 00:32:34,480 So this is based on the hardness, or the presumed hardness, rather, of the quadratic residuosity problem, or the QRP. 422 00:32:34,620 --> 00:32:50,920 It is, once again, a recurrence, x of n plus 1 equals x of n squared modulo n, where n is a large semi-prime comprised of two prime factors known as Blum primes, which just means that they are equivalent mod 4 to 3. 423 00:32:51,760 --> 00:32:56,120 So typically with this generator, for all this work, you get one bit of output. 424 00:32:56,120 --> 00:33:07,320 It's called a hardcore predicate, which is just a generic function that takes an n-length bit string and maps it to one bit in a matter such that it's hard to reverse or gain information about the original bit string. 425 00:33:09,720 --> 00:33:15,540 So I said I wasn't going to give too much of a lecture, but it's kind of necessary for these. 426 00:33:16,880 --> 00:33:27,240 So we're going to talk about the underlying problem of this, which is a quadratic residuosity problem, which is given a large semi-prime, just any semi-prime n, with large prime factors PQ. 427 00:33:27,240 --> 00:33:33,460 Consider the multiplicative group z sub n star. 428 00:33:34,080 --> 00:33:38,940 Half of the elements will have an r such that x is equivalent to r squared modulo n. 429 00:33:38,940 --> 00:33:41,210 The other half of the elements may have such an element. 430 00:33:42,640 --> 00:33:45,080 Determining if they do is presumed hard. 431 00:33:47,320 --> 00:33:56,400 So knowing the quadratic residuosity problem and the relation of blum-blum-shub, we're going to relate it to how BBS actually works. 432 00:33:56,400 --> 00:34:06,440 So given P is equivalent to Q is equivalent to 3 modulo 4, any given quadratic residue will have four square roots, exactly one of which is also a quadratic residue. 433 00:34:06,440 --> 00:34:09,960 This comes from Blum's original paper. 434 00:34:10,500 --> 00:34:16,760 Given a quadratic residue x, we are tasked to find the parity bit of the root of x that is also a quadratic residue. 435 00:34:16,760 --> 00:34:23,600 So even if you're able to solve for the roots, you must determine which one is the quadratic residue, which is precisely the quadratic residuosity problem. 436 00:34:23,600 --> 00:34:25,840 It's a very clean construction. 437 00:34:27,420 --> 00:34:40,940 If you believe me on this, once you get to this point, then you get hardness can be shown to be equivalent to factoring, sorry, which should relate it more to RSA for those that are a bit like, what's going on here? 438 00:34:42,180 --> 00:34:44,520 So, all right. 439 00:34:45,300 --> 00:34:48,660 Here is our last thing. 440 00:34:48,780 --> 00:34:50,200 This is the big one. 441 00:34:50,540 --> 00:34:52,540 Dual elliptic curve DRBG. 442 00:34:52,620 --> 00:34:55,420 A show of hands, who has heard of this one? 443 00:34:56,260 --> 00:34:57,040 Okay. 444 00:34:57,060 --> 00:34:57,880 Good. 445 00:34:58,400 --> 00:35:01,620 So some fun facts about dualistic DRBG. 446 00:35:01,620 --> 00:35:02,960 It was developed by the NSA. 447 00:35:03,740 --> 00:35:06,280 And it features something called the kleptographic backdoor. 448 00:35:07,660 --> 00:35:12,300 So remember that whole thing earlier where I said, the whole cryptographic stack? 449 00:35:12,300 --> 00:35:14,500 Yeah, the NSA went straight for the source. 450 00:35:14,540 --> 00:35:16,580 Because people don't usually look at these. 451 00:35:16,580 --> 00:35:19,500 Ciphers and asymmetric systems are much flashier. 452 00:35:19,620 --> 00:35:23,000 But these are what make all of those tick. 453 00:35:24,660 --> 00:35:30,000 This primarily is a great lesson on nothing up my sleeve numbers. 454 00:35:30,020 --> 00:35:34,520 Which basically says, if you have a random number in there, you should explain it in some way. 455 00:35:34,520 --> 00:35:39,420 It should be derivable from some publicly known constant or explainable in some way. 456 00:35:39,420 --> 00:35:44,920 Not just, I took a hash of this random string of values and it gave me that and I'm gonna use that now. 457 00:35:44,920 --> 00:35:45,740 That's bad. 458 00:35:45,920 --> 00:35:48,640 And that's exactly what dualistic DRBG did. 459 00:35:48,640 --> 00:35:51,000 To justify their use of the random numbers. 460 00:35:52,060 --> 00:35:56,440 So this one we're actually gonna walk through because it's important and it's pretty interesting. 461 00:35:57,640 --> 00:36:05,780 So let E be an elliptic curve of the form Y squared equals X cubed minus 3X plus B over a field of prime characteristic P. 462 00:36:05,900 --> 00:36:07,840 Basic elliptic curve definitions. 463 00:36:07,840 --> 00:36:11,020 We're gonna define two base points P and Q on the curve. 464 00:36:11,320 --> 00:36:14,360 And then here's all the functions of dually C. 465 00:36:14,360 --> 00:36:18,120 We have one that just extracts the X coordinate in affine coordinates. 466 00:36:18,600 --> 00:36:22,340 We have a truncation function that truncates N bits. 467 00:36:22,600 --> 00:36:25,280 Specifically the most significant bits of the generator. 468 00:36:26,220 --> 00:36:33,720 We have G sub P of X which just pulls the affine X coordinate of scalar multiplication of X and P. 469 00:36:33,720 --> 00:36:41,300 And we have G sub Q of X which truncates the affine output of scalar multiplication of X on Q. 470 00:36:42,740 --> 00:36:44,160 A little bit of a mouthful. 471 00:36:44,880 --> 00:36:54,060 By the standard, it additionally mandated use of one of the NIST curves if you wanted to get your FIPS certification and you had to use the specified base points P and Q. 472 00:36:54,060 --> 00:36:54,920 Had to, had to, had to. 473 00:36:54,920 --> 00:36:56,720 Otherwise you're not gonna get your certification. 474 00:36:57,340 --> 00:37:02,660 Notably it also mandates that you can only truncate 16 or 17. 475 00:37:02,660 --> 00:37:04,280 They give you some ambiguity there. 476 00:37:05,200 --> 00:37:06,340 Thanks, NIST. 477 00:37:08,720 --> 00:37:10,760 You have to truncate 16 or 17 bits. 478 00:37:10,760 --> 00:37:13,280 Once again, if you want that certification, which is essential. 479 00:37:16,040 --> 00:37:24,620 So the way dually CDRBG works, it makes some weird assumptions in order to get its security assertions. 480 00:37:24,620 --> 00:37:27,720 None of them are too typical other than elliptic curve decisional Diffie-Hellman. 481 00:37:28,140 --> 00:37:31,600 But we're not gonna go too deep into that. 482 00:37:31,600 --> 00:37:34,760 We're gonna talk about how the algorithm actually works. 483 00:37:34,760 --> 00:37:40,120 So we're gonna select a seed F, or sorry, S in Fs of P randomly. 484 00:37:40,620 --> 00:37:45,660 We're going to perform V is Gs of P of S to establish the first state. 485 00:37:45,660 --> 00:37:51,300 Remember Gs of P is the affine coordinate of scalar multiplication X on P. 486 00:37:52,360 --> 00:37:54,720 Then we are going, that becomes our first state. 487 00:37:54,720 --> 00:37:58,060 We're going to output a value by calling Gs of Q of V. 488 00:37:58,060 --> 00:38:01,500 So we're just gonna multiply state against our other point Q. 489 00:38:01,600 --> 00:38:05,720 Pull out the affine coordinate, truncate 16 bits, and that's your output. 490 00:38:06,240 --> 00:38:08,480 And then you just repeat. 491 00:38:10,620 --> 00:38:17,980 There you can see the outputs of elliptic scale multiplication on elliptic curve, and it looks quite chaotic. 492 00:38:18,180 --> 00:38:22,880 So that was the whole idea behind why it would make a good random number generator. 493 00:38:22,880 --> 00:38:24,720 Ironically, it really doesn't. 494 00:38:24,840 --> 00:38:30,360 But let's start talking about the trick for dually CDRBG. 495 00:38:30,360 --> 00:38:32,920 This is where things get a little interesting. 496 00:38:32,920 --> 00:38:36,860 So NIST curves all have a cofactor of 1, which means all the points are in the same group. 497 00:38:38,260 --> 00:38:44,060 So it's guaranteed there's some scalar value S, such that S times Q is equal to P. 498 00:38:45,360 --> 00:39:03,700 So if we are given a single output, so like a nonce or IV, you know, not to upset the English out there, and the base point that it was derived from A, which is once again public information, there must exist some scalar R such that A is equivalent to RQ. 499 00:39:05,100 --> 00:39:07,640 So we are going to set up our little equations here. 500 00:39:07,640 --> 00:39:13,000 We have SA equals SRQ because A is equal to RQ. 501 00:39:13,060 --> 00:39:18,640 We set SRQ is equal to RP because SQ is equal to P. 502 00:39:19,020 --> 00:39:20,480 And that's it. 503 00:39:20,480 --> 00:39:23,100 You've just backdoored the entire cryptographic stack. 504 00:39:23,580 --> 00:39:28,200 You're going to get the next state, so you're not going to get the exact state that it happened on. 505 00:39:29,040 --> 00:39:30,320 But you're going to get the next value. 506 00:39:30,320 --> 00:39:36,620 So say we do something like you generate an IV that's public. 507 00:39:38,180 --> 00:39:39,920 Now the NSA has a state. 508 00:39:40,040 --> 00:39:42,000 They're just going to dump it to their cluster farm. 509 00:39:42,000 --> 00:39:45,780 They're going to guess those 16 bits because that's trivial to do. 510 00:39:46,440 --> 00:39:49,120 And they are now backdoored everything. 511 00:39:49,120 --> 00:39:51,300 So sorry, I got a little ahead of myself. 512 00:39:51,440 --> 00:39:53,600 Since T is truncated, finding A is hard, right? 513 00:39:53,880 --> 00:39:55,380 No, it's 16 bits. 514 00:39:55,520 --> 00:39:58,680 So you just guess it, see if the X coordinate is out on the curve equation. 515 00:39:58,680 --> 00:40:00,740 Just use Tonelli-Shanks. 516 00:40:00,740 --> 00:40:04,000 Because remember, we're over a prime characteristic field. 517 00:40:04,000 --> 00:40:05,520 And you have your Y coordinate. 518 00:40:07,620 --> 00:40:12,100 So had this entered more common use, it would have broken everything. 519 00:40:12,440 --> 00:40:17,660 Thankfully, some people went a little ballistic about it. 520 00:40:17,660 --> 00:40:19,840 I remember there's Bruce Schneier. 521 00:40:19,840 --> 00:40:23,240 There's a quote saying that the backdoor was quite obvious. 522 00:40:23,960 --> 00:40:25,380 Okay, Bruce. 523 00:40:28,020 --> 00:40:33,880 The mechanism of why this was allowed to work is, once again, the unexplained points P and Q, right? 524 00:40:33,880 --> 00:40:41,920 It's this lack of explanation, these numbers that come from nowhere that enable these kinds of backdoors to exist. 525 00:40:42,480 --> 00:40:45,480 And back then, people really weren't auditing that kind of stuff. 526 00:40:45,480 --> 00:40:46,960 They trusted NIST. 527 00:40:47,600 --> 00:40:49,660 And this showed that that was a big mistake. 528 00:40:49,660 --> 00:40:58,300 Because the NSA had just hijacked and worked their way into NIST, pushed this through, and a lot of people were kind of confused about it. 529 00:40:58,300 --> 00:40:59,560 Because it wasn't a particularly good generator. 530 00:40:59,560 --> 00:41:00,960 It wasn't super performant. 531 00:41:01,160 --> 00:41:02,520 It had statistical issues. 532 00:41:02,520 --> 00:41:04,200 And yet, it still got pushed through. 533 00:41:06,740 --> 00:41:09,040 Now, hats off to the NSA. 534 00:41:09,380 --> 00:41:14,700 Finding their secret little backdoor value, that scaler that connects Q and P, is hard. 535 00:41:14,700 --> 00:41:15,900 It's the discrete log. 536 00:41:15,900 --> 00:41:18,060 So good luck finding it. 537 00:41:18,060 --> 00:41:20,060 Nobody's found it to date, as far as I know. 538 00:41:21,160 --> 00:41:25,280 But yeah, the fact that it still works is not great. 539 00:41:25,300 --> 00:41:28,400 It was part of Operation Bull Run or Project Bull Run. 540 00:41:30,520 --> 00:41:33,940 So we ended a little earlier than I intended. 541 00:41:33,940 --> 00:41:35,880 So I guess we're just gonna do Q and A. 542 00:41:36,180 --> 00:41:40,100 As far as all the sources for this, I wrote a paper. 543 00:41:40,100 --> 00:41:43,920 It's on GitHub, as well as implemented every generator I discussed here. 544 00:41:43,920 --> 00:41:44,920 It's on Python 3. 545 00:41:45,020 --> 00:41:48,400 So it should be easy to interpret and understand. 546 00:41:48,980 --> 00:41:50,420 Everything's annotated. 547 00:41:51,300 --> 00:41:56,700 Unfortunately, the repo is private, because the internet was uncooperative. 548 00:41:56,700 --> 00:41:59,160 But I will rectify that as quickly as possible. 549 00:42:00,980 --> 00:42:03,880 So yeah, I guess we'll move into Q and A a little early. 550 00:42:03,880 --> 00:42:08,420 I will also be at the CPV from 2 to 4.30 today. 551 00:42:08,420 --> 00:42:12,840 So right after the talk, I'm gonna head down there, and I'll be there until 4.30 volunteering. 552 00:42:13,680 --> 00:42:16,600 Otherwise, you can email me there. 553 00:42:17,560 --> 00:42:20,320 That is subscribed to a bunch of GCC mailing lists. 554 00:42:20,320 --> 00:42:26,960 If I don't respond, just bump it up in my inbox, and I will eventually see it amidst the swarm. 555 00:42:38,780 --> 00:42:41,460 Yeah, yeah, they're gonna go up on GitHub. 556 00:42:52,600 --> 00:42:59,260 Sort of, I'm not familiar with the direct relationship beyond the class. 557 00:42:59,260 --> 00:43:00,400 They're both presumed hard. 558 00:43:01,140 --> 00:43:10,660 The fact that QRP can be shown, at least with this construction, can be shown to be equivalent to factoring does imply that the relationship is there. 559 00:43:17,400 --> 00:43:19,280 It's... good question, actually. 560 00:43:19,280 --> 00:43:21,780 I don't... no. 561 00:43:21,780 --> 00:43:24,260 No, it's not proven to be hard. 562 00:43:24,260 --> 00:43:25,380 It's presumed hard. 563 00:43:31,520 --> 00:43:34,180 Oh, boy, I'll do my best. 564 00:43:34,180 --> 00:43:39,700 Blum-blum-shub, blum-blum-shub, blum-blum-shub, blum-blum-shub, blum-blum-shub, blum-blum-shub, blub-blum-shub, blub-blub-shub, blub-blub-shub. 565 00:43:39,700 --> 00:43:41,020 Oh, yeah, messed it up. 566 00:43:41,020 --> 00:43:41,540 All right. 567 00:43:50,770 --> 00:43:51,730 Thank you. 568 00:44:16,730 --> 00:44:22,430 So technically, yes, you can just hash whatever, presuming your hash function is good. 569 00:44:23,390 --> 00:44:25,550 And presuming it's once again salted, as you said. 570 00:44:25,930 --> 00:44:28,770 The issue with that is you're gonna lose a lot of performance. 571 00:44:29,510 --> 00:44:31,390 Hash functions are not super quick. 572 00:44:33,370 --> 00:44:39,150 So yeah, you could totally do that, but you're gonna get a pretty severe performance penalty. 573 00:44:40,490 --> 00:44:45,850 There are much better ways of doing it, but I understand why you're asking it from our talk yesterday, so... 574 00:44:51,540 --> 00:44:52,600 No, you're all good, dude. 575 00:45:03,260 --> 00:45:05,400 Yep, finite field of prime characteristic. 576 00:45:09,340 --> 00:45:13,460 It's just a NIST curve, so it's like the secp256, like, you can... 577 00:45:15,240 --> 00:45:16,560 On B? 578 00:45:17,320 --> 00:45:18,140 There is. 579 00:45:18,140 --> 00:45:18,620 There is. 580 00:45:18,620 --> 00:45:20,980 It's just a general description of the NIST curves. 581 00:45:21,160 --> 00:45:42,020 So if you go to the revoked version of SP890 alpha, you can actually see a specification precisely for dually CDRBG, and then you can go check the NIST specifications for their elliptic curves, and you can see exactly what parameters you would have used to actually implement dually CDRBG. 582 00:45:48,440 --> 00:45:49,720 All right. 583 00:45:50,280 --> 00:45:51,780 You have one more? 584 00:45:57,400 --> 00:45:58,340 Yeah, yeah. 585 00:45:58,340 --> 00:46:04,800 So a period with a pseudorandom number generator is essentially the length of values you'll get before it starts to repeat itself. 586 00:46:05,040 --> 00:46:05,460 Yep. 587 00:46:05,460 --> 00:46:11,280 So you really... a large period is very desirable in these generators. 588 00:46:11,280 --> 00:46:17,720 Commerce and Twister goes a little extreme with that, but yeah, it's a very desirable trade. 589 00:46:34,340 --> 00:46:46,300 So I don't know the specifics of that hash function, but if it is a good hash function, meaning it is pre-image resistant and collision resistant, then it should be good enough to use as a CSPRNG. 590 00:46:50,440 --> 00:46:51,360 Oh, okay. 591 00:46:51,360 --> 00:46:53,160 No, I am familiar, actually. 592 00:46:53,160 --> 00:46:56,540 So it's the... that was the winner of the NIST lightweight standard. 593 00:46:56,540 --> 00:46:57,960 Yeah, you're fine with that. 594 00:46:57,960 --> 00:46:59,520 It's built on the sponge construction. 595 00:46:59,520 --> 00:47:00,520 It's been tested. 596 00:47:00,660 --> 00:47:01,580 Good to go. 597 00:47:08,100 --> 00:47:15,780 So, yes, I did a class on cryptography as an undergrad. 598 00:47:15,780 --> 00:47:17,480 It was a grad level class. 599 00:47:18,140 --> 00:47:20,400 That's where I got really interested in it. 600 00:47:21,340 --> 00:47:23,060 And I've just kind of kept going. 601 00:47:23,060 --> 00:47:28,440 But I would definitely say if you want to advance in this field, most of it is in academia. 602 00:47:30,420 --> 00:47:32,280 Both fortunately and unfortunately. 603 00:47:32,880 --> 00:47:41,100 So, yes, I would definitely recommend if you want to go be a professional cryptographer, at least on the theory side of the house, definitely go to school. 604 00:47:42,120 --> 00:47:43,040 What's up? 605 00:47:46,940 --> 00:47:48,740 You know, UNLV, shout out. 606 00:47:50,420 --> 00:47:52,400 Let's see, good crypto programs. 607 00:47:52,640 --> 00:47:55,060 Stanford, they got Bono over there . 608 00:47:55,060 --> 00:47:57,020 They got UChicago. 609 00:47:57,020 --> 00:47:58,400 That's where Bernstein's at. 610 00:47:58,400 --> 00:47:59,140 What's up? 611 00:47:59,920 --> 00:48:00,760 Yeah, CMU. 612 00:48:00,760 --> 00:48:02,900 They have a good crypto program. 613 00:48:02,920 --> 00:48:04,940 Basically, it's who you'd expect. 614 00:48:12,050 --> 00:48:15,790 Definitely as of right now, far more on the computer science aspect of it. 615 00:48:16,410 --> 00:48:21,430 I work with the math, but I am not like a mathematician formally. 616 00:48:21,430 --> 00:48:22,370 So not even close. 617 00:48:22,370 --> 00:48:27,630 Like I had an algebraic geometer come up to me yesterday, and he was talking about pairing based cryptography. 618 00:48:27,630 --> 00:48:32,650 And I could keep up for like, I don't know, we didn't even share names. 619 00:48:32,650 --> 00:48:34,510 He just went straight to the point. 620 00:48:35,670 --> 00:48:37,810 And I was like, what, like two minutes were good? 621 00:48:37,810 --> 00:48:40,570 And then after that, I'm like, okay, whoa, back up. 622 00:48:40,570 --> 00:48:41,530 I know how to do it. 623 00:48:41,530 --> 00:48:43,790 I don't know what's going on behind that. 624 00:49:03,230 --> 00:49:04,030 Yep. 625 00:49:05,930 --> 00:49:14,510 So that actually brings me to a point that actually got cut, because in my practice runs of the talk, it took the full 50 minutes that they were like, you should use. 626 00:49:15,270 --> 00:49:16,370 Discussion of quantum. 627 00:49:16,370 --> 00:49:20,290 The reason, so first of all, I'll discuss the implications of quantum for this. 628 00:49:20,290 --> 00:49:22,230 It only breaks our number theoretic generators. 629 00:49:22,230 --> 00:49:23,030 Everything else is fine. 630 00:49:23,190 --> 00:49:24,530 As far as we know. 631 00:49:25,190 --> 00:49:28,030 So yeah, the ones that nobody uses are broken. 632 00:49:28,110 --> 00:49:28,690 Great. 633 00:49:29,910 --> 00:49:42,510 But so the application of quantum randomness is the whole idea is that is the, depending on, once again, your interpretation of physics, that is the source of randomness. 634 00:49:42,570 --> 00:49:46,030 And so it is as good of random as you're actually going to get. 635 00:49:46,790 --> 00:49:59,070 Downside is it's super expensive and there's no practical reason to spend that much compute just to get a random number when we already have a ton of systems that are very well equipped to do it for you much more cheaply. 636 00:49:59,070 --> 00:50:05,750 It is interesting, at least in my opinion, in the academic sense exclusively. 637 00:50:11,080 --> 00:50:12,280 Yeah, TRNGs. 638 00:50:19,290 --> 00:50:22,770 So TRNGs are great. 639 00:50:22,770 --> 00:50:24,990 If you can go get one, get one. 640 00:50:25,470 --> 00:50:27,730 But they're not super common. 641 00:50:27,730 --> 00:50:29,650 There's a website, I forget what it's called. 642 00:50:29,690 --> 00:50:32,470 It's got some horrible name, actually. 643 00:50:32,690 --> 00:50:36,990 But it's a guide on how to build your own true random number generator at home. 644 00:50:37,130 --> 00:50:43,170 If for the extra paranoid, because that's usually who buys true random number generator, so hardware RNGs. 645 00:50:44,390 --> 00:50:46,970 Because you never know if the one on Amazon's backdoored. 646 00:50:48,170 --> 00:50:52,090 But yeah, I would say get one. 647 00:50:52,090 --> 00:50:56,170 They're useful, especially if you have concerns about system entropy. 648 00:50:56,170 --> 00:51:00,930 But realistically, it's probably just a good fallback. 649 00:51:01,170 --> 00:51:08,430 Because system entropy, as we discussed, especially are you on Linux or Windows or Mac? 650 00:51:08,430 --> 00:51:08,670 Okay. 651 00:51:08,670 --> 00:51:11,370 I actually don't know what OSX uses. 652 00:51:12,910 --> 00:51:15,030 No clue what OSX uses. 653 00:51:15,030 --> 00:51:22,550 I would presume they're either copying some of the BSD stuff or Linux. 654 00:51:22,550 --> 00:51:29,800 So yeah, it should be okay. 655 00:51:29,800 --> 00:51:33,200 I mean, Apple's usually pretty on top of that stuff. 656 00:51:33,200 --> 00:51:35,140 So I'd just buy it as a backup. 657 00:51:35,140 --> 00:51:35,760 They're good to have. 658 00:51:35,760 --> 00:51:36,380 They're cool. 659 00:51:36,380 --> 00:51:39,680 But I wouldn't be super concerned if you don't have one. 660 00:51:48,650 --> 00:51:52,790 Oh, I don't know specifically about that chip. 661 00:51:57,890 --> 00:51:58,730 Oh, okay. 662 00:51:58,730 --> 00:51:59,630 You work with them. 663 00:52:01,090 --> 00:52:01,870 Okay. 664 00:52:07,070 --> 00:52:10,790 Yeah, so cha-cha is actually great on ARM. 665 00:52:10,950 --> 00:52:22,510 Because specifically you don't have to deal like the most other, the common one is people do weird stuff like, oh, we're just going to use the ASNI instructions and that's my random number generator. 666 00:52:22,510 --> 00:52:23,130 Great. 667 00:52:23,150 --> 00:52:26,210 If you're not on x86, just get bent, I guess. 668 00:52:27,370 --> 00:52:29,730 But cha-cha is really good for that. 669 00:52:29,730 --> 00:52:34,890 I can't speak to the efficacy of the ARM architectures, TRNGs or any specific chips. 670 00:52:35,810 --> 00:52:46,230 It would be careful because there are a lot of LFSRs sliding around, especially in cheaper stuff, because they're just dirt simple and they're really easy. 671 00:52:46,330 --> 00:52:51,890 I know a lot of the, like, cheaper DMR radios all use LFSRs. 672 00:52:51,890 --> 00:52:54,690 It's not great, but... 673 00:52:59,710 --> 00:53:00,770 All right. 674 00:53:02,270 --> 00:53:03,510 Good to go. 675 00:53:09,790 --> 00:53:10,430 Yep. 676 00:53:10,430 --> 00:53:12,970 Just as a reminder, I'm going to be in the CPV until 430. 677 00:53:12,970 --> 00:53:20,190 So if you want to go ask a question in private or whatever it may be or you just want to talk crypto, I will be there for a few hours.