All right. Hello, everyone. I go by Infocalypse. This is my talk, Cracking Chaos, Making, Using, and Breaking Pseudo-Random Number Generators. It is my first time speaking, so in accordance... Great. Nothing like whiskey at noon, right? All right. So we're going to start off with some preliminaries. What is randomness? And it's kind of hard to define. 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. But we are going to discuss some models of it and give some intuitive explainers, right? So we have what most people would consider to be true randomness, which is entropy, right? 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? The idea is that it's non-deterministic. So even if you have the same throw, things might not shake out the same. But for computation, since we're using deterministic machines, we have the random oracle model. So the easiest way to think about the random oracle model is like we have a gnome in a box, right? And this gnome has a book. He's got some, once again, dice in there. And there's a little hole that you can pass notes through. 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, 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. 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. That is the very, very intuitive explanation of this. It is much more rigorous informal definition, but yeah. So and then the weakest definition we have is statistical randomness. And this is what most people will be familiar with if you've ever worked with PRNGs. This is your test suites like Die Hard or Test 201. This is where we're going to be testing, you know, does this look like random, do these look like random numbers? Does this make sense as random data? Statistically. But it is not as strong as an assertion as a random oracle. So we're going to start off with true randomness, right? It's an essential but expensive commodity on computers. We generate it a few different ways. The most common is system entropy. So this is going to be things that are mixed together, like mouse movements or load times. All kinds of fun system processes, usually. And that is what usually powers the randomness used in your OS. So like defrandom, wrandom, that's what seeds it. And historically, that's actually what was outputted. And then for more demanding scenarios, we have hardware random number generators, which is what you can see depicted up there. 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. So why do we care about true randomness? Well, one, statistics. It's the base for how we evaluate random number generators. And two, in the cryptographic case, it gives us some hardness assertions. 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? 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. So that's where we get, like, our whole definition of what n-bit security is. All right. So next up, we're on insecure pseudorandom number generators. This is when we really only care about speed and statistical quality. We don't really care about hardness assertions. So in these cases, the promise of n-bit security, as I just discussed, does not usually hold up. So some examples to kind of ground this are... So we have some CVEs up here. We have the bug in Debian's OpenSSL, where their pseudorandom number generator... Good. Okay. So their pseudorandom number generator was weak, and it was not generating dynamic enough numbers, which made a lot of secrets predictable. 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. It was pretty gnarly. And then another example is Moodle, which is a PHP framework, was using mercen twisters for token generation to reset account passwords. 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. So yeah, those are some examples. So now we're going to start talking about types of insecure pseudorandom number generators. So we will start off with, historically, one of the earliest, which are linear congruential generators. They are extremely simple. They can be fairly fast. They were prolific in early computing. You don't really see too many of them anymore, which is a good thing. 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. So the way they work is we have a little recurrence here. We have X of N plus 1 equals A times X of N plus C Magillo M. So the maximal period on these is typically considered to be M, or about M, rather. 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. So we have the case where the additive is zero, and the modulus is prime. These will give you a near maximal period, but they're pretty slow. So they're not too often used. And then we have the case where the additive is once again zero, and M is a power of two. These are non-maximal periods, usually. Well, not usually. They are always non-maximal periods. But they are fast. Once again, nobody really uses them, because non-maximal periods. 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. These are both maximal period, and they are fast. So linear congruential generators are unfortunately not statistically sufficient. They are easily, easily, easily detectable by spectral test failure. So for people that have used statistical test suites before, you'll probably recognize that name. 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. 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. So how do we break these? Through the same means and reasons why they suck statistically, we're going to break it. 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. So let's walk through this real quick. So given several outputs, you need at least five. You're going to form pseudo-Hankel matrices of that form. 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. 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, D3, and usually that's more than enough to actually nail down the modulus. So once we've got M, we're going to go through the simple case, because there's a bit of complexity with these. We are going to look for the multiplicand A. 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. Otherwise, we get to solve linear Diophantine equations, so it's less fun, but it is doable. We're not going to talk too much about that, though, because I only have so much time. 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. And then all you have to do to find C is just set up that last equation. It's pretty easy to break these. It's very fast. And we will actually see that right now. So we have... this is a linear congruential generator. There's two of them here. We're breaking RANQD1, and then we're visualizing a much weaker one, because it's a lot easier to see the planes. So I know crypto demos are everyone's favorite thing. It's very exciting. But... sorry for the lag there. I wrote this on a much more powerful computer. So in the console there, we can see the outputs. We can see the determinants. We can deduce what the characteristic is. We test if it's co-prime. It is. We're able to pull out A, C, and then we can just invert the seed. And then in our lovely spinning cube, we can see as it spins that sometimes the dots will all line up in those planes. And that's exactly what a Mersogli's theorem would expect and what makes these breakable. So I think that should be enough for that demo. And we are now on to linear feedback shift registers. This is another classic, classic generator. You still find these today. Mostly in embedded. But they make use of bitwise arithmetic for fast pseudorandom bits. Once again, they have multiple forms. We are going to be discussing the Fibonacci form because it is the easiest to explain. And also usually what you see more on the hardware side of things. Depicted up there, you can see a visualization of one. So Fibonacci generators work by selecting inputs, which in the typical nomenclature is called a tap. Corresponding to a binary polynomial. 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. 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. So here's our seed. We have 0, 0, 1, 1, 0, 1, 0, 1. And then we have our feedback polynomial, x to the 7 plus x to the 6 plus 1. The way that the actual generators work is it's flipped. Sorry, questions. There's a question and period at the end. So we're going to have an output bit of 1, which is the last bit. We're going to take the 6th and the 7th, which is actually the 7th and the 8th because of the 1. And we are going to exclusive or them. So 0s or 1 is 1. And we stick that in the beginning. Ta-da. Linear feedback shift register. So they're pretty simple, but they are very fast. They're very efficient. But they are, once again, very weak. They notably fail two tests for distinguishing. Obviously the linearity test, which the LCT also fails. And the binary matrix rank test that is extremely distinguishing with linear feedback shift registers. But with the way you break these, it's an algorithm called BrilleCamp Massey. We won't be diving into it. Once again, I only have so much time. But it's more prudent to just try BrilleCamp Massey. 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. If you get one that's about half the length of the input that you gave it, probably not a linear feedback shift register. So next up we have Mersenne twisters. This is one of the most popular generators out there. It is the default in Python. It is all over the place. It is built off of a laundry list of previous stuff, generalized feedback shift registers. Then you have twisted generalized feedback shift registers, rationalized. And then you have the Mersenne twister, which comes after that. So it's generated by, once again, yet another relation. Sorry, the cursor made that a little ambiguous. So what it's essentially doing is it's manipulating its own internal state to form words through both concatenation and exclusive ORs. And then it performs a matrix multiplication at the end, which comes from the twisted generalized feedback shift register. So they are pretty high quality pseudo random number generators, which is why they're the default everywhere. They have an obscenely long period, at least with Mersenne twister 19937, of 2 to the 19937 minus 1. 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. There with the depiction we can see from the original paper the specification for MT19937. It is very strange. That paper is very strange. 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. But since MT19937 is by far the most prolific, we're going to discuss detecting that one. 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. So if you can test in dimension higher than 623, you'll start to see that Mersenne twister deteriorates in equidistribution. 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, but this has been fixed in newer versions, so it's not a surefire way. So how do we invert Mersenne twister? I mentioned earlier the tempering technique. What it is is basically just a matrix multiplication. It's a type of output whitening to make sure it has the statistical qualities we want. The matrix that we do this with is non-singular, therefore it is invertible. 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. So you can now predict all the future outputs of a Mersenne twister just by doing that. So don't use it in security-sensitive context. Now on to our last insecure generators. We have counter-based PRNGs. These are pretty new, and they take inspiration from block ciphers in counter mode. They typically use deliberately weakened cryptographic primitives and techniques. They are extraordinarily fast as a result of optimizations, and sometimes hardware equipment for it. The most common reference you'll see for these kinds of generators is the Random123 library, which was published by D.E. Shaw. It includes three generators, which are ARS, 3FRY, and PHYLOX. ARS is based off of a weakened AES, 3FRY is weakened 3FISH, and PHYLOX is a completely original product. So these generators have gotten quite popular pretty recently. They're used everywhere. We have them in curand, we just got it in C++ 26. NumPy, Intel's OneAPI, HPC stuff, and there are many, many more. 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. And all of these passed in their official variants. They have obscenely long periods. Once again, it's about 2 to 128, at least per D.E. Shaw's numbers. However, given they use cryptographic primitives, some people make the assumption that they are cryptographic. They are not. They have no cryptanalysis has been done of them, and there is no claims of security made by D.E. Shaw. So keep that in mind if you ever want to use these. We're going to talk about PHYLOX today, because it is what I have by far the most experience with. I am currently doing great battle with Red Hat employees to get it merged into lib standard C++. So yeah, it's fun. Almost there, almost there. So once again, it is a completely original product of random 1, 2, 3. It's their own device. So it's a hybrid Feistel network substitution structure. It has multiple forms. There's multiple 32-bit forms and multiple 64-bit forms. 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. There's not really a state in this, but it's the width of the counter. Once again, all the official variants pass big crush. And this is the most common generator you'll see from random 1, 2, 3 by far. We're going to discuss PHYLOX 4 by 32, 10 specifically in more detail. You can actually see PHYLOX, the implementation there. I know it might be a little grainy, but yeah, that's the main loop of PHYLOX. So this wonderful little graph is my mock-up of how PHYLOX works. So C0, 1, 2, 3, that's our state. It's essentially just, in this case, a 128-bit word broken up into four limbs. Those of you familiar with PHYSTL networks will see that we're swapping C0 and C2 in the very PHYSTL pattern. And then C1 and C3 are substituted. In this case, operations take place over the ring Z2 to the 32Z. And it's multiplied with a unitary value. So you get a uniform output. It's infuriating, actually, to try and break this. But then with our triangles, that's where things kind of deviate. You have the mull-low operation, which is A times B mod 2 to 32. You take the low bits of the 64-bit word that's produced. And then mull-high, which is A times B right shift 32. It's just the high bits of the same operation. So with the triangles pointed up, that is a mull-high operation. With the triangles pointed down, that's a mull-low. And then you see the KSL, KSR, that is the key schedule. It's just an affine transformation. It's a very simple key schedule. If there are weaknesses that can be broken, it probably has to do with that. So we are going to move forward into flaws in detection. There is currently no differentiator for this. There's no way to tell. It's not uniformly random. There is no break. But this doesn't mean it's safe. Once again, this has not been formally cryptanalyzed by anyone, at least to my knowledge. This hasn't been studied. There's no claims of security from the manufacturer and the designers. So it is best to just avoid it in security sensitive context. Use something trusted. However, for your general randomness needs other than that, it's phenomenal. So we are now moving into the second part of the talk. And things get a little more complicated here. This is where we are talking about secure PRNGs or CSPRNGs. And this has to go be special. They call them DRBGs. These give us usually high quality pseudo randomness with additional hardness assertions. So basically what we typically do is we are willing to sacrifice speed in order to gain some kind of cryptographic hardness assertion. Because this is the backbone of the modern cryptographic stack. 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. As we can see, my meme straight out of like 2018 up there. And then on the other side, we have the description of basically how Linux has worked since 2020. Where it will take system entropy, the other thing we talked about earlier, and feed it into cha-cha 20. And historically, and that becomes dev urandom and dev random. Historically they had different behavior and they would just output system entropy. But that had a lot of issues where you could either cause a DOS or you could get predictable random numbers. It just was a bad time, so they swapped over to just cha-cha 20, which is an example of a CSPRNG. We're going to talk about stream ciphers. Real quick. 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. If we just ignore the plain text part of it, ta-da, we have a CSPRNG. We just use the key stream as a pseudo random number. 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. Some examples of this are cha-cha 20, RC4, and Rabbit, which was from the E-stream competition. We're going to talk about cha-cha 20 and RC4. RC4 is a great example of what not to do. So it comes from RSA security. It's Revest cipher 4 or Ron's code 4, depending on who you ask. There's been a lot of issues found with this cipher. There's the second bit bias, which is what we're going to be talking about today. There's been some key schedule weaknesses. Historically it was used in TLS until it wasn't because people were breaking everything that had to do with it. It was specifically disallowed in RFC 7465. If you want to go read that, it is moderately entertaining. 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. But they no longer do that for reasons we're about to get into. So as I mentioned, we're talking about the second byte bias. Here is the initialization step of RC4. We have two pointers, I, J. And we have a generation loop. So some preliminary before this is we have some arbitrary size state S, which is just an array of numbers. It's a permutation, rather, of the list of N numbers. So you increment your pointer I, then J is added with S sub I. And then you swap the values and output Z as the index of S that S of I plus S of J is at. Pretty simple cipher, which is what made it kind of attractive for a lot of people when it first came out. But as with all good things, this thing did not work out well for us. So usually when we do statistical testing and the stuff I've discussed thus far, it's with statistical test suites. 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. 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? The answer is yes. We can do it with greater than a 60% success rate. If I remember correctly, it's about 64. 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. So some of you might be thinking, okay, can we mitigate that? It's just the second number. The answer is yes. Yes, you absolutely can. You can just not output and skip a little bit, and you're good. The real question becomes, should we use a mitigated version of a flawed cipher? And the answer, at least in my opinion, is no, because usually where you find one issue, others follow. That's the basis of cryptanalysis. It's usually a very long trail where you find something and then a whole bunch of issues follow. So what should you use? Sorry, we have another demo of actually detecting the bias in RC4 and showcasing it. So once again, I wrote this on a much more potent computer, so it's going to take a second. There we go. So as you can see, that zero value is spiked well above the expected. Well above the expected. Which lines up with the second bias you would expect from the formal analysis. We did 100,000 streams there. All right. So now we're talking about ChaCha20. This is more of an aside. It is a very modern arc space cypher, which is and rotates or, developed by Daniel Bernstein to succeed his other cypher. It has a strong emphasis on side channel resistance. Best public cryptanalysis, as far as I know, is up to 7 out of 20 rounds. And it is used in TLS. Once again, it's used in Linux's DevUrandom, DevRandom. It's all around a better choice than RC4. Okay. So now we're on to our next variant, which are block cyphers in counter mode. 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. It makes it behave very similarly to a stream cypher. This also inspired the counter base PRNGs we discussed earlier. You can quite see it very directly with 3Fry and ours, which very much literally use the routines of 3Fish and AES. But the big difference here is we're actually using the full blown variants. So we're using secure primitives. There are hardness assertions. There you can see a lovely diagram showcasing counter mode. Now we're going to start talking a little bit about the NIST generators. NIST SP890 alpha. And it discusses all the approved CSPRNGs for use. And they have a generator of this form. It is called counter DRBG. Very creative. And it officially supports AES 128, 192, 256, and still triple DES, which they try to hide as 3DEA. Good job, NIST. So it can really, it really boils down to it's just counter mode. You just get some additional opportunities to inject entropy. And technically the framework itself works for any block cipher. But it's NIST, so they just support the official U.S. ones. So counter DRBG is practically secure. There are no practical breaks on it. However, there are academic breaks, which means there are theoretical breaks that mathematically work. They just are impractical to do in a specific amount of, in a feasible amount of time. It's really only a problem with triple DES, because of course it is. It's triple DES. 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. 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. Now on to yet another NIST generator, hash-based CSPRNGs. These use the outputs of hash functions as random numbers. Up there we can literally see NIST's hash DRBG diagram. These aren't too common. You don't really see these that often. But they are of interest with the standardization of SHA-3. So SHA-3 uses a sponge construction. Which has now two proofs of indifferentiability from random oracle with very minimal assumptions. 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. So it's of note, and I'm really curious to see how that's going to shake out. There hasn't really been too much study on specifically this construction with SHA-3 yet. The NIST publication is quite old. So they only discuss SHA-2 and Merkle-Domgarde constructions. So we'll see how that goes. So these are also secure. There's not really any attacks that apply to them that are specific to this generator. It's just the usual stuff with Merkle-Domgarde constructions, your length extension attacks, all the usual shenaniganry. But they're usually not used too often because of speed. There's not really a good way, other than statistical testing, to assert their quality, their goodness as generators. 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. So, all right. We are on our last category here, which are number-theoretic generators. Now, this is... Nobody uses these for a very good reason. They're incredibly slow. But they are very interesting. So we have some examples here. We have BlumBlumShub, DuallyCDRBG, and the Blum and Cayley generator. And these get their hardness based on usually problems from number theory, similarly to how we do our asymmetric cryptography. So, as you can see, graduate techs in mathematics. Or, sorry, didn't graduate techs in mathematics. Introduction to that thing. But only for people who already know it. So that's kind of the tone we're taking here. Because I am not doing a lecture in abstract algebra. But we're going to start moving. So we're going to talk about BlumBlumShub and DuallyCDRBG. I know. Shocking. Yes, this algorithm is really named BlumBlumShub. It is very funny, but that is really what it's named. So this is based on the hardness, or the presumed hardness, rather, of the quadratic residuosity problem, or the QRP. 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. So typically with this generator, for all this work, you get one bit of output. 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. So I said I wasn't going to give too much of a lecture, but it's kind of necessary for these. 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. Consider the multiplicative group z sub n star. Half of the elements will have an r such that x is equivalent to r squared modulo n. The other half of the elements may have such an element. Determining if they do is presumed hard. So knowing the quadratic residuosity problem and the relation of blum-blum-shub, we're going to relate it to how BBS actually works. 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. This comes from Blum's original paper. Given a quadratic residue x, we are tasked to find the parity bit of the root of x that is also a quadratic residue. 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. It's a very clean construction. 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? So, all right. Here is our last thing. This is the big one. Dual elliptic curve DRBG. A show of hands, who has heard of this one? Okay. Good. So some fun facts about dualistic DRBG. It was developed by the NSA. And it features something called the kleptographic backdoor. So remember that whole thing earlier where I said, the whole cryptographic stack? Yeah, the NSA went straight for the source. Because people don't usually look at these. Ciphers and asymmetric systems are much flashier. But these are what make all of those tick. This primarily is a great lesson on nothing up my sleeve numbers. Which basically says, if you have a random number in there, you should explain it in some way. It should be derivable from some publicly known constant or explainable in some way. Not just, I took a hash of this random string of values and it gave me that and I'm gonna use that now. That's bad. And that's exactly what dualistic DRBG did. To justify their use of the random numbers. So this one we're actually gonna walk through because it's important and it's pretty interesting. 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. Basic elliptic curve definitions. We're gonna define two base points P and Q on the curve. And then here's all the functions of dually C. We have one that just extracts the X coordinate in affine coordinates. We have a truncation function that truncates N bits. Specifically the most significant bits of the generator. We have G sub P of X which just pulls the affine X coordinate of scalar multiplication of X and P. And we have G sub Q of X which truncates the affine output of scalar multiplication of X on Q. A little bit of a mouthful. 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. Had to, had to, had to. Otherwise you're not gonna get your certification. Notably it also mandates that you can only truncate 16 or 17. They give you some ambiguity there. Thanks, NIST. You have to truncate 16 or 17 bits. Once again, if you want that certification, which is essential. So the way dually CDRBG works, it makes some weird assumptions in order to get its security assertions. None of them are too typical other than elliptic curve decisional Diffie-Hellman. But we're not gonna go too deep into that. We're gonna talk about how the algorithm actually works. So we're gonna select a seed F, or sorry, S in Fs of P randomly. We're going to perform V is Gs of P of S to establish the first state. Remember Gs of P is the affine coordinate of scalar multiplication X on P. Then we are going, that becomes our first state. We're going to output a value by calling Gs of Q of V. So we're just gonna multiply state against our other point Q. Pull out the affine coordinate, truncate 16 bits, and that's your output. And then you just repeat. There you can see the outputs of elliptic scale multiplication on elliptic curve, and it looks quite chaotic. So that was the whole idea behind why it would make a good random number generator. Ironically, it really doesn't. But let's start talking about the trick for dually CDRBG. This is where things get a little interesting. So NIST curves all have a cofactor of 1, which means all the points are in the same group. So it's guaranteed there's some scalar value S, such that S times Q is equal to P. 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. So we are going to set up our little equations here. We have SA equals SRQ because A is equal to RQ. We set SRQ is equal to RP because SQ is equal to P. And that's it. You've just backdoored the entire cryptographic stack. You're going to get the next state, so you're not going to get the exact state that it happened on. But you're going to get the next value. So say we do something like you generate an IV that's public. Now the NSA has a state. They're just going to dump it to their cluster farm. They're going to guess those 16 bits because that's trivial to do. And they are now backdoored everything. So sorry, I got a little ahead of myself. Since T is truncated, finding A is hard, right? No, it's 16 bits. So you just guess it, see if the X coordinate is out on the curve equation. Just use Tonelli-Shanks. Because remember, we're over a prime characteristic field. And you have your Y coordinate. So had this entered more common use, it would have broken everything. Thankfully, some people went a little ballistic about it. I remember there's Bruce Schneier. There's a quote saying that the backdoor was quite obvious. Okay, Bruce. The mechanism of why this was allowed to work is, once again, the unexplained points P and Q, right? It's this lack of explanation, these numbers that come from nowhere that enable these kinds of backdoors to exist. And back then, people really weren't auditing that kind of stuff. They trusted NIST. And this showed that that was a big mistake. 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. Because it wasn't a particularly good generator. It wasn't super performant. It had statistical issues. And yet, it still got pushed through. Now, hats off to the NSA. Finding their secret little backdoor value, that scaler that connects Q and P, is hard. It's the discrete log. So good luck finding it. Nobody's found it to date, as far as I know. But yeah, the fact that it still works is not great. It was part of Operation Bull Run or Project Bull Run. So we ended a little earlier than I intended. So I guess we're just gonna do Q and A. As far as all the sources for this, I wrote a paper. It's on GitHub, as well as implemented every generator I discussed here. It's on Python 3. So it should be easy to interpret and understand. Everything's annotated. Unfortunately, the repo is private, because the internet was uncooperative. But I will rectify that as quickly as possible. So yeah, I guess we'll move into Q and A a little early. I will also be at the CPV from 2 to 4.30 today. So right after the talk, I'm gonna head down there, and I'll be there until 4.30 volunteering. Otherwise, you can email me there. That is subscribed to a bunch of GCC mailing lists. If I don't respond, just bump it up in my inbox, and I will eventually see it amidst the swarm. Yeah, yeah, they're gonna go up on GitHub. Sort of, I'm not familiar with the direct relationship beyond the class. They're both presumed hard. 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. It's... good question, actually. I don't... no. No, it's not proven to be hard. It's presumed hard. Oh, boy, I'll do my best. 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. Oh, yeah, messed it up. All right. Thank you. So technically, yes, you can just hash whatever, presuming your hash function is good. And presuming it's once again salted, as you said. The issue with that is you're gonna lose a lot of performance. Hash functions are not super quick. So yeah, you could totally do that, but you're gonna get a pretty severe performance penalty. There are much better ways of doing it, but I understand why you're asking it from our talk yesterday, so... No, you're all good, dude. Yep, finite field of prime characteristic. It's just a NIST curve, so it's like the secp256, like, you can... On B? There is. There is. It's just a general description of the NIST curves. 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. All right. You have one more? Yeah, yeah. So a period with a pseudorandom number generator is essentially the length of values you'll get before it starts to repeat itself. Yep. So you really... a large period is very desirable in these generators. Commerce and Twister goes a little extreme with that, but yeah, it's a very desirable trade. 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. Oh, okay. No, I am familiar, actually. So it's the... that was the winner of the NIST lightweight standard. Yeah, you're fine with that. It's built on the sponge construction. It's been tested. Good to go. So, yes, I did a class on cryptography as an undergrad. It was a grad level class. That's where I got really interested in it. And I've just kind of kept going. But I would definitely say if you want to advance in this field, most of it is in academia. Both fortunately and unfortunately. 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. What's up? You know, UNLV, shout out. Let's see, good crypto programs. Stanford, they got Bono over there . They got UChicago. That's where Bernstein's at. What's up? Yeah, CMU. They have a good crypto program. Basically, it's who you'd expect. Definitely as of right now, far more on the computer science aspect of it. I work with the math, but I am not like a mathematician formally. So not even close. Like I had an algebraic geometer come up to me yesterday, and he was talking about pairing based cryptography. And I could keep up for like, I don't know, we didn't even share names. He just went straight to the point. And I was like, what, like two minutes were good? And then after that, I'm like, okay, whoa, back up. I know how to do it. I don't know what's going on behind that. Yep. 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. Discussion of quantum. The reason, so first of all, I'll discuss the implications of quantum for this. It only breaks our number theoretic generators. Everything else is fine. As far as we know. So yeah, the ones that nobody uses are broken. Great. 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. And so it is as good of random as you're actually going to get. 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. It is interesting, at least in my opinion, in the academic sense exclusively. Yeah, TRNGs. So TRNGs are great. If you can go get one, get one. But they're not super common. There's a website, I forget what it's called. It's got some horrible name, actually. But it's a guide on how to build your own true random number generator at home. If for the extra paranoid, because that's usually who buys true random number generator, so hardware RNGs. Because you never know if the one on Amazon's backdoored. But yeah, I would say get one. They're useful, especially if you have concerns about system entropy. But realistically, it's probably just a good fallback. Because system entropy, as we discussed, especially are you on Linux or Windows or Mac? Okay. I actually don't know what OSX uses. No clue what OSX uses. I would presume they're either copying some of the BSD stuff or Linux. So yeah, it should be okay. I mean, Apple's usually pretty on top of that stuff. So I'd just buy it as a backup. They're good to have. They're cool. But I wouldn't be super concerned if you don't have one. Oh, I don't know specifically about that chip. Oh, okay. You work with them. Okay. Yeah, so cha-cha is actually great on ARM. 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. Great. If you're not on x86, just get bent, I guess. But cha-cha is really good for that. I can't speak to the efficacy of the ARM architectures, TRNGs or any specific chips. 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. I know a lot of the, like, cheaper DMR radios all use LFSRs. It's not great, but... All right. Good to go. Yep. Just as a reminder, I'm going to be in the CPV until 430. 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.