start	end	text
0	540	All right.
540	1560	Hello, everyone.
1800	3400	I go by Infocalypse.
3400	7620	This is my talk, Cracking Chaos, Making, Using, and Breaking Pseudo-Random Number Generators.
7820	10480	It is my first time speaking, so in accordance...
20420	20960	Great.
20960	22500	Nothing like whiskey at noon, right?
23920	24840	All right.
24840	28280	So we're going to start off with some preliminaries.
28800	30280	What is randomness?
30280	31940	And it's kind of hard to define.
33020	38320	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.
38320	42940	But we are going to discuss some models of it and give some intuitive explainers, right?
42940	48260	So we have what most people would consider to be true randomness, which is entropy, right?
48260	57020	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?
58240	61100	The idea is that it's non-deterministic.
61600	65460	So even if you have the same throw, things might not shake out the same.
66480	72860	But for computation, since we're using deterministic machines, we have the random oracle model.
73540	78640	So the easiest way to think about the random oracle model is like we have a gnome in a box, right?
79300	80840	And this gnome has a book.
80840	82920	He's got some, once again, dice in there.
82920	85580	And there's a little hole that you can pass notes through.
85580	98180	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,
98180	103920	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.
104220	110340	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.
110640	113500	That is the very, very intuitive explanation of this.
113500	118020	It is much more rigorous informal definition, but yeah.
119120	122600	So and then the weakest definition we have is statistical randomness.
122600	126840	And this is what most people will be familiar with if you've ever worked with PRNGs.
127140	130120	This is your test suites like Die Hard or Test 201.
130120	135760	This is where we're going to be testing, you know, does this look like random, do these look like random numbers?
135760	137280	Does this make sense as random data?
137340	138220	Statistically.
138600	142680	But it is not as strong as an assertion as a random oracle.
144560	146840	So we're going to start off with true randomness, right?
147160	150600	It's an essential but expensive commodity on computers.
151340	153760	We generate it a few different ways.
153760	155620	The most common is system entropy.
155620	163680	So this is going to be things that are mixed together, like mouse movements or load times.
163980	167060	All kinds of fun system processes, usually.
167820	172680	And that is what usually powers the randomness used in your OS.
172680	175600	So like defrandom, wrandom, that's what seeds it.
175600	177740	And historically, that's actually what was outputted.
178260	185280	And then for more demanding scenarios, we have hardware random number generators, which is what you can see depicted up there.
187200	198200	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.
199540	202760	So why do we care about true randomness?
202980	204760	Well, one, statistics.
204760	207720	It's the base for how we evaluate random number generators.
207720	211740	And two, in the cryptographic case, it gives us some hardness assertions.
211740	218580	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?
218580	229040	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.
230360	235520	So that's where we get, like, our whole definition of what n-bit security is.
237800	238560	All right.
238560	241720	So next up, we're on insecure pseudorandom number generators.
242220	245540	This is when we really only care about speed and statistical quality.
245540	248000	We don't really care about hardness assertions.
248420	253860	So in these cases, the promise of n-bit security, as I just discussed, does not usually hold up.
254240	258500	So some examples to kind of ground this are...
258500	260760	So we have some CVEs up here.
261100	265720	We have the bug in Debian's OpenSSL, where their pseudorandom number generator...
268020	268980	Good.
269020	269720	Okay.
270540	279820	So their pseudorandom number generator was weak, and it was not generating dynamic enough numbers, which made a lot of secrets predictable.
280940	286480	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.
286480	287380	It was pretty gnarly.
287540	295540	And then another example is Moodle, which is a PHP framework, was using mercen twisters for token generation to reset account passwords.
295540	309960	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.
310460	313500	So yeah, those are some examples.
313680	317780	So now we're going to start talking about types of insecure pseudorandom number generators.
318040	324020	So we will start off with, historically, one of the earliest, which are linear congruential generators.
325760	328620	They are extremely simple.
328660	330560	They can be fairly fast.
331240	332940	They were prolific in early computing.
332940	335500	You don't really see too many of them anymore, which is a good thing.
335840	341680	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.
343740	347000	So the way they work is we have a little recurrence here.
347000	352740	We have X of N plus 1 equals A times X of N plus C Magillo M.
353420	358480	So the maximal period on these is typically considered to be M, or about M, rather.
358480	364360	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.
364680	369720	So we have the case where the additive is zero, and the modulus is prime.
370180	373360	These will give you a near maximal period, but they're pretty slow.
374660	377300	So they're not too often used.
377400	382080	And then we have the case where the additive is once again zero, and M is a power of two.
382900	385240	These are non-maximal periods, usually.
385260	386100	Well, not usually.
386100	388100	They are always non-maximal periods.
388440	389880	But they are fast.
390120	392920	Once again, nobody really uses them, because non-maximal periods.
392920	400320	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.
400400	403180	These are both maximal period, and they are fast.
406080	411680	So linear congruential generators are unfortunately not statistically sufficient.
412340	416840	They are easily, easily, easily detectable by spectral test failure.
417340	425060	So for people that have used statistical test suites before, you'll probably recognize that name.
426000	439180	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.
439180	449560	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.
451700	453840	So how do we break these?
455420	460400	Through the same means and reasons why they suck statistically, we're going to break it.
460560	472400	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.
474020	476640	So let's walk through this real quick.
476640	479220	So given several outputs, you need at least five.
479220	482780	You're going to form pseudo-Hankel matrices of that form.
483820	495400	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.
496160	515560	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,
515560	520640	D3, and usually that's more than enough to actually nail down the modulus.
521680	526980	So once we've got M, we're going to go through the simple case, because there's a bit of complexity with these.
527380	529680	We are going to look for the multiplicand A.
530940	542820	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.
543340	549460	Otherwise, we get to solve linear Diophantine equations, so it's less fun, but it is doable.
550020	554440	We're not going to talk too much about that, though, because I only have so much time.
555020	567920	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.
569880	575220	And then all you have to do to find C is just set up that last equation.
575220	577060	It's pretty easy to break these.
577060	578520	It's very fast.
578700	582580	And we will actually see that right now.
582860	588400	So we have... this is a linear congruential generator.
588400	589980	There's two of them here.
589980	595940	We're breaking RANQD1, and then we're visualizing a much weaker one, because it's a lot easier to see the planes.
597060	599980	So I know crypto demos are everyone's favorite thing.
599980	601300	It's very exciting.
605100	606740	But... sorry for the lag there.
606740	609640	I wrote this on a much more powerful computer.
611280	613780	So in the console there, we can see the outputs.
613780	615040	We can see the determinants.
615040	620500	We can deduce what the characteristic is.
620760	622420	We test if it's co-prime.
622420	623260	It is.
623280	627200	We're able to pull out A, C, and then we can just invert the seed.
627200	637020	And then in our lovely spinning cube, we can see as it spins that sometimes the dots will all line up in those planes.
637300	641760	And that's exactly what a Mersogli's theorem would expect and what makes these breakable.
642120	646320	So I think that should be enough for that demo.
646740	649440	And we are now on to linear feedback shift registers.
649440	651200	This is another classic, classic generator.
651200	652540	You still find these today.
653060	654360	Mostly in embedded.
654360	658960	But they make use of bitwise arithmetic for fast pseudorandom bits.
659100	662020	Once again, they have multiple forms.
662020	666940	We are going to be discussing the Fibonacci form because it is the easiest to explain.
667860	671420	And also usually what you see more on the hardware side of things.
671600	675320	Depicted up there, you can see a visualization of one.
677540	683800	So Fibonacci generators work by selecting inputs, which in the typical nomenclature is called a tap.
684920	686400	Corresponding to a binary polynomial.
686840	696740	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.
697940	703900	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.
705060	706020	So here's our seed.
706020	709600	We have 0, 0, 1, 1, 0, 1, 0, 1.
709600	713260	And then we have our feedback polynomial, x to the 7 plus x to the 6 plus 1.
714800	720100	The way that the actual generators work is it's flipped.
720420	721420	Sorry, questions.
721420	723040	There's a question and period at the end.
725940	731740	So we're going to have an output bit of 1, which is the last bit.
732240	737060	We're going to take the 6th and the 7th, which is actually the 7th and the 8th because of the 1.
737720	739780	And we are going to exclusive or them.
739780	741680	So 0s or 1 is 1.
742220	743580	And we stick that in the beginning.
743580	744700	Ta-da.
744700	745900	Linear feedback shift register.
748800	752640	So they're pretty simple, but they are very fast.
752640	753640	They're very efficient.
753640	756280	But they are, once again, very weak.
756380	759640	They notably fail two tests for distinguishing.
759640	762520	Obviously the linearity test, which the LCT also fails.
762540	767920	And the binary matrix rank test that is extremely distinguishing with linear feedback shift registers.
768800	772620	But with the way you break these, it's an algorithm called BrilleCamp Massey.
772620	773680	We won't be diving into it.
773680	775260	Once again, I only have so much time.
775540	778180	But it's more prudent to just try BrilleCamp Massey.
778180	786040	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.
786040	791980	If you get one that's about half the length of the input that you gave it, probably not a linear feedback shift register.
793820	795720	So next up we have Mersenne twisters.
795720	798640	This is one of the most popular generators out there.
798720	800720	It is the default in Python.
800720	802800	It is all over the place.
802920	807520	It is built off of a laundry list of previous stuff, generalized feedback shift registers.
807520	810860	Then you have twisted generalized feedback shift registers, rationalized.
811200	814740	And then you have the Mersenne twister, which comes after that.
814960	818720	So it's generated by, once again, yet another relation.
819420	822320	Sorry, the cursor made that a little ambiguous.
823320	831860	So what it's essentially doing is it's manipulating its own internal state to form words through both concatenation and exclusive ORs.
832300	839060	And then it performs a matrix multiplication at the end, which comes from the twisted generalized feedback shift register.
840980	846620	So they are pretty high quality pseudo random number generators, which is why they're the default everywhere.
847600	856100	They have an obscenely long period, at least with Mersenne twister 19937, of 2 to the 19937 minus 1.
856100	867880	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.
868200	874600	There with the depiction we can see from the original paper the specification for MT19937.
876440	879460	It is very strange.
879460	881040	That paper is very strange.
882780	891780	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.
891780	896820	But since MT19937 is by far the most prolific, we're going to discuss detecting that one.
896820	909780	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.
909780	916840	So if you can test in dimension higher than 623, you'll start to see that Mersenne twister deteriorates in equidistribution.
917960	934100	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,
934100	937420	but this has been fixed in newer versions, so it's not a surefire way.
937980	940720	So how do we invert Mersenne twister?
941300	944260	I mentioned earlier the tempering technique.
944260	946340	What it is is basically just a matrix multiplication.
946340	950600	It's a type of output whitening to make sure it has the statistical qualities we want.
951040	956680	The matrix that we do this with is non-singular, therefore it is invertible.
956740	964500	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.
964500	969880	So you can now predict all the future outputs of a Mersenne twister just by doing that.
970880	974420	So don't use it in security-sensitive context.
976500	980020	Now on to our last insecure generators.
980020	982220	We have counter-based PRNGs.
982220	986680	These are pretty new, and they take inspiration from block ciphers in counter mode.
987300	991300	They typically use deliberately weakened cryptographic primitives and techniques.
991300	999200	They are extraordinarily fast as a result of optimizations, and sometimes hardware equipment for it.
999460	1005440	The most common reference you'll see for these kinds of generators is the Random123 library, which was published by D.E.
1005440	1005910	Shaw.
1006240	1012260	It includes three generators, which are ARS, 3FRY, and PHYLOX.
1012280	1018720	ARS is based off of a weakened AES, 3FRY is weakened 3FISH, and PHYLOX is a completely original product.
1018720	1024660	So these generators have gotten quite popular pretty recently.
1024660	1025530	They're used everywhere.
1026020	1029800	We have them in curand, we just got it in C++ 26.
1030600	1036100	NumPy, Intel's OneAPI, HPC stuff, and there are many, many more.
1036560	1046460	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.
1046460	1049440	And all of these passed in their official variants.
1049780	1051220	They have obscenely long periods.
1051220	1054280	Once again, it's about 2 to 128, at least per D.E.
1054280	1055100	Shaw's numbers.
1055600	1059700	However, given they use cryptographic primitives, some people make the assumption that they are cryptographic.
1059700	1060320	They are not.
1060320	1066160	They have no cryptanalysis has been done of them, and there is no claims of security made by D.E.
1066160	1066700	Shaw.
1066700	1069400	So keep that in mind if you ever want to use these.
1070120	1074900	We're going to talk about PHYLOX today, because it is what I have by far the most experience with.
1074900	1080020	I am currently doing great battle with Red Hat employees to get it merged into lib standard C++.
1080760	1083820	So yeah, it's fun.
1083820	1085180	Almost there, almost there.
1086440	1090600	So once again, it is a completely original product of random 1, 2, 3.
1090600	1092160	It's their own device.
1092340	1096840	So it's a hybrid Feistel network substitution structure.
1096860	1098940	It has multiple forms.
1099260	1102580	There's multiple 32-bit forms and multiple 64-bit forms.
1102580	1110340	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.
1110340	1113100	There's not really a state in this, but it's the width of the counter.
1114380	1117040	Once again, all the official variants pass big crush.
1117100	1121980	And this is the most common generator you'll see from random 1, 2, 3 by far.
1123440	1128640	We're going to discuss PHYLOX 4 by 32, 10 specifically in more detail.
1128640	1133000	You can actually see PHYLOX, the implementation there.
1133000	1139020	I know it might be a little grainy, but yeah, that's the main loop of PHYLOX.
1140460	1147240	So this wonderful little graph is my mock-up of how PHYLOX works.
1147820	1151940	So C0, 1, 2, 3, that's our state.
1152680	1158360	It's essentially just, in this case, a 128-bit word broken up into four limbs.
1159820	1166180	Those of you familiar with PHYSTL networks will see that we're swapping C0 and C2 in the very PHYSTL pattern.
1167400	1170580	And then C1 and C3 are substituted.
1170860	1176020	In this case, operations take place over the ring Z2 to the 32Z.
1176520	1179320	And it's multiplied with a unitary value.
1179380	1182040	So you get a uniform output.
1182040	1184860	It's infuriating, actually, to try and break this.
1186700	1190760	But then with our triangles, that's where things kind of deviate.
1191080	1195580	You have the mull-low operation, which is A times B mod 2 to 32.
1195580	1198680	You take the low bits of the 64-bit word that's produced.
1198920	1201740	And then mull-high, which is A times B right shift 32.
1201740	1203660	It's just the high bits of the same operation.
1203980	1207860	So with the triangles pointed up, that is a mull-high operation.
1207860	1209880	With the triangles pointed down, that's a mull-low.
1209980	1213900	And then you see the KSL, KSR, that is the key schedule.
1213900	1215760	It's just an affine transformation.
1216660	1218780	It's a very simple key schedule.
1219060	1224060	If there are weaknesses that can be broken, it probably has to do with that.
1226520	1230140	So we are going to move forward into flaws in detection.
1231380	1233660	There is currently no differentiator for this.
1233660	1234520	There's no way to tell.
1234520	1235820	It's not uniformly random.
1235820	1236740	There is no break.
1236900	1239020	But this doesn't mean it's safe.
1239020	1242680	Once again, this has not been formally cryptanalyzed by anyone, at least to my knowledge.
1242680	1245100	This hasn't been studied.
1245100	1249580	There's no claims of security from the manufacturer and the designers.
1249940	1253100	So it is best to just avoid it in security sensitive context.
1253100	1254120	Use something trusted.
1254120	1258200	However, for your general randomness needs other than that, it's phenomenal.
1260280	1263400	So we are now moving into the second part of the talk.
1263400	1265000	And things get a little more complicated here.
1265000	1268880	This is where we are talking about secure PRNGs or CSPRNGs.
1268880	1270180	And this has to go be special.
1270180	1271840	They call them DRBGs.
1273700	1279220	These give us usually high quality pseudo randomness with additional hardness assertions.
1279220	1284700	So basically what we typically do is we are willing to sacrifice speed in order to gain some kind of cryptographic hardness assertion.
1284740	1290240	Because this is the backbone of the modern cryptographic stack.
1290840	1299280	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.
1299560	1303660	As we can see, my meme straight out of like 2018 up there.
1304540	1312880	And then on the other side, we have the description of basically how Linux has worked since 2020.
1313180	1318600	Where it will take system entropy, the other thing we talked about earlier, and feed it into cha-cha 20.
1319080	1323600	And historically, and that becomes dev urandom and dev random.
1323600	1326960	Historically they had different behavior and they would just output system entropy.
1326960	1332400	But that had a lot of issues where you could either cause a DOS or you could get predictable random numbers.
1332400	1337120	It just was a bad time, so they swapped over to just cha-cha 20, which is an example of a CSPRNG.
1338780	1340660	We're going to talk about stream ciphers.
1341520	1342540	Real quick.
1342540	1354100	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.
1354100	1357520	If we just ignore the plain text part of it, ta-da, we have a CSPRNG.
1358440	1361860	We just use the key stream as a pseudo random number.
1361960	1370940	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.
1371320	1377060	Some examples of this are cha-cha 20, RC4, and Rabbit, which was from the E-stream competition.
1378480	1381320	We're going to talk about cha-cha 20 and RC4.
1382720	1385980	RC4 is a great example of what not to do.
1387080	1389820	So it comes from RSA security.
1390060	1394480	It's Revest cipher 4 or Ron's code 4, depending on who you ask.
1394480	1396940	There's been a lot of issues found with this cipher.
1397540	1400460	There's the second bit bias, which is what we're going to be talking about today.
1400460	1402220	There's been some key schedule weaknesses.
1402460	1408620	Historically it was used in TLS until it wasn't because people were breaking everything that had to do with it.
1408620	1411980	It was specifically disallowed in RFC 7465.
1411980	1414820	If you want to go read that, it is moderately entertaining.
1416620	1424900	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.
1427000	1430220	But they no longer do that for reasons we're about to get into.
1431140	1433700	So as I mentioned, we're talking about the second byte bias.
1433700	1436680	Here is the initialization step of RC4.
1436680	1438840	We have two pointers, I, J.
1439120	1441200	And we have a generation loop.
1441200	1448320	So some preliminary before this is we have some arbitrary size state S, which is just an array of numbers.
1448320	1451820	It's a permutation, rather, of the list of N numbers.
1452440	1458300	So you increment your pointer I, then J is added with S sub I.
1458680	1467460	And then you swap the values and output Z as the index of S that S of I plus S of J is at.
1468480	1474940	Pretty simple cipher, which is what made it kind of attractive for a lot of people when it first came out.
1477880	1482640	But as with all good things, this thing did not work out well for us.
1482740	1489300	So usually when we do statistical testing and the stuff I've discussed thus far, it's with statistical test suites.
1490980	1501200	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.
1501620	1512840	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?
1513320	1514740	The answer is yes.
1514740	1517000	We can do it with greater than a 60% success rate.
1517000	1518660	If I remember correctly, it's about 64.
1518660	1534180	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.
1535940	1539960	So some of you might be thinking, okay, can we mitigate that?
1539960	1541080	It's just the second number.
1541080	1542120	The answer is yes.
1542120	1542980	Yes, you absolutely can.
1542980	1546160	You can just not output and skip a little bit, and you're good.
1546700	1550900	The real question becomes, should we use a mitigated version of a flawed cipher?
1550900	1556340	And the answer, at least in my opinion, is no, because usually where you find one issue, others follow.
1556340	1558220	That's the basis of cryptanalysis.
1558220	1562980	It's usually a very long trail where you find something and then a whole bunch of issues follow.
1563320	1564820	So what should you use?
1564820	1570560	Sorry, we have another demo of actually detecting the bias in RC4 and showcasing it.
1570860	1576700	So once again, I wrote this on a much more potent computer, so it's going to take a second.
1577440	1578880	There we go.
1578900	1583900	So as you can see, that zero value is spiked well above the expected.
1584280	1585620	Well above the expected.
1585960	1591940	Which lines up with the second bias you would expect from the formal analysis.
1593260	1596020	We did 100,000 streams there.
1598660	1600020	All right.
1600020	1602680	So now we're talking about ChaCha20.
1602680	1604200	This is more of an aside.
1604200	1619800	It is a very modern arc space cypher, which is and rotates or, developed by Daniel Bernstein to succeed his other cypher.
1619920	1623540	It has a strong emphasis on side channel resistance.
1624540	1628920	Best public cryptanalysis, as far as I know, is up to 7 out of 20 rounds.
1628920	1631080	And it is used in TLS.
1631080	1633780	Once again, it's used in Linux's DevUrandom, DevRandom.
1634200	1636740	It's all around a better choice than RC4.
1638140	1639020	Okay.
1639040	1643180	So now we're on to our next variant, which are block cyphers in counter mode.
1644220	1655760	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.
1655760	1658500	It makes it behave very similarly to a stream cypher.
1659140	1662720	This also inspired the counter base PRNGs we discussed earlier.
1662720	1670880	You can quite see it very directly with 3Fry and ours, which very much literally use the routines of 3Fish and AES.
1671900	1675260	But the big difference here is we're actually using the full blown variants.
1675260	1676620	So we're using secure primitives.
1676620	1678080	There are hardness assertions.
1678080	1681850	There you can see a lovely diagram showcasing counter mode.
1684300	1688920	Now we're going to start talking a little bit about the NIST generators.
1689790	1691750	NIST SP890 alpha.
1693100	1698860	And it discusses all the approved CSPRNGs for use.
1698860	1701440	And they have a generator of this form.
1701720	1703920	It is called counter DRBG.
1703920	1704930	Very creative.
1705920	1715880	And it officially supports AES 128, 192, 256, and still triple DES, which they try to hide as 3DEA.
1716280	1717550	Good job, NIST.
1720480	1724780	So it can really, it really boils down to it's just counter mode.
1724780	1727520	You just get some additional opportunities to inject entropy.
1727560	1731280	And technically the framework itself works for any block cipher.
1731280	1735380	But it's NIST, so they just support the official U.S.
1735380	1736300	ones.
1736980	1740080	So counter DRBG is practically secure.
1740080	1741680	There are no practical breaks on it.
1741680	1748380	However, there are academic breaks, which means there are theoretical breaks that mathematically work.
1748380	1753000	They just are impractical to do in a specific amount of, in a feasible amount of time.
1753740	1757640	It's really only a problem with triple DES, because of course it is.
1757640	1758800	It's triple DES.
1759140	1764600	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.
1767280	1782410	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.
1783820	1788880	Now on to yet another NIST generator, hash-based CSPRNGs.
1788880	1792840	These use the outputs of hash functions as random numbers.
1792840	1796230	Up there we can literally see NIST's hash DRBG diagram.
1798060	1799780	These aren't too common.
1799780	1801140	You don't really see these that often.
1801140	1804400	But they are of interest with the standardization of SHA-3.
1804400	1807640	So SHA-3 uses a sponge construction.
1808220	1814640	Which has now two proofs of indifferentiability from random oracle with very minimal assumptions.
1815180	1826520	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.
1828820	1833280	So it's of note, and I'm really curious to see how that's going to shake out.
1833280	1837220	There hasn't really been too much study on specifically this construction with SHA-3 yet.
1837220	1839060	The NIST publication is quite old.
1839060	1842240	So they only discuss SHA-2 and Merkle-Domgarde constructions.
1843600	1845680	So we'll see how that goes.
1847740	1849700	So these are also secure.
1849700	1854140	There's not really any attacks that apply to them that are specific to this generator.
1854140	1860220	It's just the usual stuff with Merkle-Domgarde constructions, your length extension attacks, all the usual shenaniganry.
1860760	1864340	But they're usually not used too often because of speed.
1864340	1871820	There's not really a good way, other than statistical testing, to assert their quality, their goodness as generators.
1872100	1884260	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.
1885980	1887260	So, all right.
1888280	1892880	We are on our last category here, which are number-theoretic generators.
1892880	1894000	Now, this is...
1895260	1897940	Nobody uses these for a very good reason.
1897940	1899680	They're incredibly slow.
1900380	1902420	But they are very interesting.
1902420	1904940	So we have some examples here.
1904940	1908460	We have BlumBlumShub, DuallyCDRBG, and the Blum and Cayley generator.
1909060	1917600	And these get their hardness based on usually problems from number theory, similarly to how we do our asymmetric cryptography.
1918120	1920680	So, as you can see, graduate techs in mathematics.
1920680	1922320	Or, sorry, didn't graduate techs in mathematics.
1922320	1923780	Introduction to that thing.
1923820	1925260	But only for people who already know it.
1925260	1926960	So that's kind of the tone we're taking here.
1927400	1931280	Because I am not doing a lecture in abstract algebra.
1931280	1935000	But we're going to start moving.
1935000	1938400	So we're going to talk about BlumBlumShub and DuallyCDRBG.
1938400	1938900	I know.
1938900	1939760	Shocking.
1940900	1943820	Yes, this algorithm is really named BlumBlumShub.
1944260	1947180	It is very funny, but that is really what it's named.
1948060	1954480	So this is based on the hardness, or the presumed hardness, rather, of the quadratic residuosity problem, or the QRP.
1954620	1970920	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.
1971760	1976120	So typically with this generator, for all this work, you get one bit of output.
1976120	1987320	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.
1989720	1995540	So I said I wasn't going to give too much of a lecture, but it's kind of necessary for these.
1996880	2007240	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.
2007240	2013460	Consider the multiplicative group z sub n star.
2014080	2018940	Half of the elements will have an r such that x is equivalent to r squared modulo n.
2018940	2021210	The other half of the elements may have such an element.
2022640	2025080	Determining if they do is presumed hard.
2027320	2036400	So knowing the quadratic residuosity problem and the relation of blum-blum-shub, we're going to relate it to how BBS actually works.
2036400	2046440	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.
2046440	2049960	This comes from Blum's original paper.
2050500	2056760	Given a quadratic residue x, we are tasked to find the parity bit of the root of x that is also a quadratic residue.
2056760	2063600	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.
2063600	2065840	It's a very clean construction.
2067420	2080940	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?
2082180	2084520	So, all right.
2085300	2088660	Here is our last thing.
2088780	2090200	This is the big one.
2090540	2092540	Dual elliptic curve DRBG.
2092620	2095420	A show of hands, who has heard of this one?
2096260	2097040	Okay.
2097060	2097880	Good.
2098400	2101620	So some fun facts about dualistic DRBG.
2101620	2102960	It was developed by the NSA.
2103740	2106280	And it features something called the kleptographic backdoor.
2107660	2112300	So remember that whole thing earlier where I said, the whole cryptographic stack?
2112300	2114500	Yeah, the NSA went straight for the source.
2114540	2116580	Because people don't usually look at these.
2116580	2119500	Ciphers and asymmetric systems are much flashier.
2119620	2123000	But these are what make all of those tick.
2124660	2130000	This primarily is a great lesson on nothing up my sleeve numbers.
2130020	2134520	Which basically says, if you have a random number in there, you should explain it in some way.
2134520	2139420	It should be derivable from some publicly known constant or explainable in some way.
2139420	2144920	Not just, I took a hash of this random string of values and it gave me that and I'm gonna use that now.
2144920	2145740	That's bad.
2145920	2148640	And that's exactly what dualistic DRBG did.
2148640	2151000	To justify their use of the random numbers.
2152060	2156440	So this one we're actually gonna walk through because it's important and it's pretty interesting.
2157640	2165780	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.
2165900	2167840	Basic elliptic curve definitions.
2167840	2171020	We're gonna define two base points P and Q on the curve.
2171320	2174360	And then here's all the functions of dually C.
2174360	2178120	We have one that just extracts the X coordinate in affine coordinates.
2178600	2182340	We have a truncation function that truncates N bits.
2182600	2185280	Specifically the most significant bits of the generator.
2186220	2193720	We have G sub P of X which just pulls the affine X coordinate of scalar multiplication of X and P.
2193720	2201300	And we have G sub Q of X which truncates the affine output of scalar multiplication of X on Q.
2202740	2204160	A little bit of a mouthful.
2204880	2214060	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.
2214060	2214920	Had to, had to, had to.
2214920	2216720	Otherwise you're not gonna get your certification.
2217340	2222660	Notably it also mandates that you can only truncate 16 or 17.
2222660	2224280	They give you some ambiguity there.
2225200	2226340	Thanks, NIST.
2228720	2230760	You have to truncate 16 or 17 bits.
2230760	2233280	Once again, if you want that certification, which is essential.
2236040	2244620	So the way dually CDRBG works, it makes some weird assumptions in order to get its security assertions.
2244620	2247720	None of them are too typical other than elliptic curve decisional Diffie-Hellman.
2248140	2251600	But we're not gonna go too deep into that.
2251600	2254760	We're gonna talk about how the algorithm actually works.
2254760	2260120	So we're gonna select a seed F, or sorry, S in Fs of P randomly.
2260620	2265660	We're going to perform V is Gs of P of S to establish the first state.
2265660	2271300	Remember Gs of P is the affine coordinate of scalar multiplication X on P.
2272360	2274720	Then we are going, that becomes our first state.
2274720	2278060	We're going to output a value by calling Gs of Q of V.
2278060	2281500	So we're just gonna multiply state against our other point Q.
2281600	2285720	Pull out the affine coordinate, truncate 16 bits, and that's your output.
2286240	2288480	And then you just repeat.
2290620	2297980	There you can see the outputs of elliptic scale multiplication on elliptic curve, and it looks quite chaotic.
2298180	2302880	So that was the whole idea behind why it would make a good random number generator.
2302880	2304720	Ironically, it really doesn't.
2304840	2310360	But let's start talking about the trick for dually CDRBG.
2310360	2312920	This is where things get a little interesting.
2312920	2316860	So NIST curves all have a cofactor of 1, which means all the points are in the same group.
2318260	2324060	So it's guaranteed there's some scalar value S, such that S times Q is equal to P.
2325360	2343700	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.
2345100	2347640	So we are going to set up our little equations here.
2347640	2353000	We have SA equals SRQ because A is equal to RQ.
2353060	2358640	We set SRQ is equal to RP because SQ is equal to P.
2359020	2360480	And that's it.
2360480	2363100	You've just backdoored the entire cryptographic stack.
2363580	2368200	You're going to get the next state, so you're not going to get the exact state that it happened on.
2369040	2370320	But you're going to get the next value.
2370320	2376620	So say we do something like you generate an IV that's public.
2378180	2379920	Now the NSA has a state.
2380040	2382000	They're just going to dump it to their cluster farm.
2382000	2385780	They're going to guess those 16 bits because that's trivial to do.
2386440	2389120	And they are now backdoored everything.
2389120	2391300	So sorry, I got a little ahead of myself.
2391440	2393600	Since T is truncated, finding A is hard, right?
2393880	2395380	No, it's 16 bits.
2395520	2398680	So you just guess it, see if the X coordinate is out on the curve equation.
2398680	2400740	Just use Tonelli-Shanks.
2400740	2404000	Because remember, we're over a prime characteristic field.
2404000	2405520	And you have your Y coordinate.
2407620	2412100	So had this entered more common use, it would have broken everything.
2412440	2417660	Thankfully, some people went a little ballistic about it.
2417660	2419840	I remember there's Bruce Schneier.
2419840	2423240	There's a quote saying that the backdoor was quite obvious.
2423960	2425380	Okay, Bruce.
2428020	2433880	The mechanism of why this was allowed to work is, once again, the unexplained points P and Q, right?
2433880	2441920	It's this lack of explanation, these numbers that come from nowhere that enable these kinds of backdoors to exist.
2442480	2445480	And back then, people really weren't auditing that kind of stuff.
2445480	2446960	They trusted NIST.
2447600	2449660	And this showed that that was a big mistake.
2449660	2458300	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.
2458300	2459560	Because it wasn't a particularly good generator.
2459560	2460960	It wasn't super performant.
2461160	2462520	It had statistical issues.
2462520	2464200	And yet, it still got pushed through.
2466740	2469040	Now, hats off to the NSA.
2469380	2474700	Finding their secret little backdoor value, that scaler that connects Q and P, is hard.
2474700	2475900	It's the discrete log.
2475900	2478060	So good luck finding it.
2478060	2480060	Nobody's found it to date, as far as I know.
2481160	2485280	But yeah, the fact that it still works is not great.
2485300	2488400	It was part of Operation Bull Run or Project Bull Run.
2490520	2493940	So we ended a little earlier than I intended.
2493940	2495880	So I guess we're just gonna do Q and A.
2496180	2500100	As far as all the sources for this, I wrote a paper.
2500100	2503920	It's on GitHub, as well as implemented every generator I discussed here.
2503920	2504920	It's on Python 3.
2505020	2508400	So it should be easy to interpret and understand.
2508980	2510420	Everything's annotated.
2511300	2516700	Unfortunately, the repo is private, because the internet was uncooperative.
2516700	2519160	But I will rectify that as quickly as possible.
2520980	2523880	So yeah, I guess we'll move into Q and A a little early.
2523880	2528420	I will also be at the CPV from 2 to 4.30 today.
2528420	2532840	So right after the talk, I'm gonna head down there, and I'll be there until 4.30 volunteering.
2533680	2536600	Otherwise, you can email me there.
2537560	2540320	That is subscribed to a bunch of GCC mailing lists.
2540320	2546960	If I don't respond, just bump it up in my inbox, and I will eventually see it amidst the swarm.
2558780	2561460	Yeah, yeah, they're gonna go up on GitHub.
2572600	2579260	Sort of, I'm not familiar with the direct relationship beyond the class.
2579260	2580400	They're both presumed hard.
2581140	2590660	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.
2597400	2599280	It's... good question, actually.
2599280	2601780	I don't... no.
2601780	2604260	No, it's not proven to be hard.
2604260	2605380	It's presumed hard.
2611520	2614180	Oh, boy, I'll do my best.
2614180	2619700	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.
2619700	2621020	Oh, yeah, messed it up.
2621020	2621540	All right.
2630770	2631730	Thank you.
2656730	2662430	So technically, yes, you can just hash whatever, presuming your hash function is good.
2663390	2665550	And presuming it's once again salted, as you said.
2665930	2668770	The issue with that is you're gonna lose a lot of performance.
2669510	2671390	Hash functions are not super quick.
2673370	2679150	So yeah, you could totally do that, but you're gonna get a pretty severe performance penalty.
2680490	2685850	There are much better ways of doing it, but I understand why you're asking it from our talk yesterday, so...
2691540	2692600	No, you're all good, dude.
2703260	2705400	Yep, finite field of prime characteristic.
2709340	2713460	It's just a NIST curve, so it's like the secp256, like, you can...
2715240	2716560	On B?
2717320	2718140	There is.
2718140	2718620	There is.
2718620	2720980	It's just a general description of the NIST curves.
2721160	2742020	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.
2748440	2749720	All right.
2750280	2751780	You have one more?
2757400	2758340	Yeah, yeah.
2758340	2764800	So a period with a pseudorandom number generator is essentially the length of values you'll get before it starts to repeat itself.
2765040	2765460	Yep.
2765460	2771280	So you really... a large period is very desirable in these generators.
2771280	2777720	Commerce and Twister goes a little extreme with that, but yeah, it's a very desirable trade.
2794340	2806300	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.
2810440	2811360	Oh, okay.
2811360	2813160	No, I am familiar, actually.
2813160	2816540	So it's the... that was the winner of the NIST lightweight standard.
2816540	2817960	Yeah, you're fine with that.
2817960	2819520	It's built on the sponge construction.
2819520	2820520	It's been tested.
2820660	2821580	Good to go.
2828100	2835780	So, yes, I did a class on cryptography as an undergrad.
2835780	2837480	It was a grad level class.
2838140	2840400	That's where I got really interested in it.
2841340	2843060	And I've just kind of kept going.
2843060	2848440	But I would definitely say if you want to advance in this field, most of it is in academia.
2850420	2852280	Both fortunately and unfortunately.
2852880	2861100	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.
2862120	2863040	What's up?
2866940	2868740	You know, UNLV, shout out.
2870420	2872400	Let's see, good crypto programs.
2872640	2875060	Stanford, they got Bono over there .
2875060	2877020	They got UChicago.
2877020	2878400	That's where Bernstein's at.
2878400	2879140	What's up?
2879920	2880760	Yeah, CMU.
2880760	2882900	They have a good crypto program.
2882920	2884940	Basically, it's who you'd expect.
2892050	2895790	Definitely as of right now, far more on the computer science aspect of it.
2896410	2901430	I work with the math, but I am not like a mathematician formally.
2901430	2902370	So not even close.
2902370	2907630	Like I had an algebraic geometer come up to me yesterday, and he was talking about pairing based cryptography.
2907630	2912650	And I could keep up for like, I don't know, we didn't even share names.
2912650	2914510	He just went straight to the point.
2915670	2917810	And I was like, what, like two minutes were good?
2917810	2920570	And then after that, I'm like, okay, whoa, back up.
2920570	2921530	I know how to do it.
2921530	2923790	I don't know what's going on behind that.
2943230	2944030	Yep.
2945930	2954510	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.
2955270	2956370	Discussion of quantum.
2956370	2960290	The reason, so first of all, I'll discuss the implications of quantum for this.
2960290	2962230	It only breaks our number theoretic generators.
2962230	2963030	Everything else is fine.
2963190	2964530	As far as we know.
2965190	2968030	So yeah, the ones that nobody uses are broken.
2968110	2968690	Great.
2969910	2982510	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.
2982570	2986030	And so it is as good of random as you're actually going to get.
2986790	2999070	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.
2999070	3005750	It is interesting, at least in my opinion, in the academic sense exclusively.
3011080	3012280	Yeah, TRNGs.
3019290	3022770	So TRNGs are great.
3022770	3024990	If you can go get one, get one.
3025470	3027730	But they're not super common.
3027730	3029650	There's a website, I forget what it's called.
3029690	3032470	It's got some horrible name, actually.
3032690	3036990	But it's a guide on how to build your own true random number generator at home.
3037130	3043170	If for the extra paranoid, because that's usually who buys true random number generator, so hardware RNGs.
3044390	3046970	Because you never know if the one on Amazon's backdoored.
3048170	3052090	But yeah, I would say get one.
3052090	3056170	They're useful, especially if you have concerns about system entropy.
3056170	3060930	But realistically, it's probably just a good fallback.
3061170	3068430	Because system entropy, as we discussed, especially are you on Linux or Windows or Mac?
3068430	3068670	Okay.
3068670	3071370	I actually don't know what OSX uses.
3072910	3075030	No clue what OSX uses.
3075030	3082550	I would presume they're either copying some of the BSD stuff or Linux.
3082550	3089800	So yeah, it should be okay.
3089800	3093200	I mean, Apple's usually pretty on top of that stuff.
3093200	3095140	So I'd just buy it as a backup.
3095140	3095760	They're good to have.
3095760	3096380	They're cool.
3096380	3099680	But I wouldn't be super concerned if you don't have one.
3108650	3112790	Oh, I don't know specifically about that chip.
3117890	3118730	Oh, okay.
3118730	3119630	You work with them.
3121090	3121870	Okay.
3127070	3130790	Yeah, so cha-cha is actually great on ARM.
3130950	3142510	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.
3142510	3143130	Great.
3143150	3146210	If you're not on x86, just get bent, I guess.
3147370	3149730	But cha-cha is really good for that.
3149730	3154890	I can't speak to the efficacy of the ARM architectures, TRNGs or any specific chips.
3155810	3166230	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.
3166330	3171890	I know a lot of the, like, cheaper DMR radios all use LFSRs.
3171890	3174690	It's not great, but...
3179710	3180770	All right.
3182270	3183510	Good to go.
3189790	3190430	Yep.
3190430	3192970	Just as a reminder, I'm going to be in the CPV until 430.
3192970	3200190	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.
