Live data from Hacker News

Three mistakes from Dart/Flutter's weak PRNG

zellic.io

81–90 of 93 posts

Re: Three mistakes from Dart/Flutter's weak PRNG

#81
post #10

New languages should make sure the default random() is cryptographically secure, and hide PRNGs behind weakrandom() or repeatablerandom() or something. Safe and slow defaults are better than fast and unsafe.

Or avoid ambiguity and remove the default random(). - randomWeak() - randomSecure()

Or randomInsecure() and randomCryptographic() to avoid any ambiguity around the word 'weak' for non-security minded programmers[0], and to avoid using the substring 'secure' twice[1] in two very different functions.

[0] In my experience, most of them -- who reads documentation these days...? Or programmers using editors like vim (no slight on vim by the way, don't shoot me!) which (generally) won't alert the programmer to the library options, unless it's been set up with a suggestion/completion/intellisense plugin?

[1] randomSecure() vs randomInsecure(), which can look similar at 3:00am on three hours sleep. Naming the functions explicitly differently makes it patently clear which function is cryptographically safe. Also helps when the interpreter/compiler won't understand the context the function is being called in, therefore can't throw warnings or errors to alert the overtired/overworked programmer that they're using insecure random number generation for crypto.

Big brain idea: Perhaps cryptographically-weak/insecure random number generators should be type incompatible by default, requiring an explicit cast to integer/float? Probably overkill, but definitely wards off mistakes and/or misuses by forcing the developer to type cast out, otherwise the compiler simply refuses, then explains why by fatal error at compile time, or by exception thrown.

But then why not make secure random number generators type incompatible by default? Because we're trying to encourage secure-by-default programming, making it slightly harder (but not onerous) to use the equivalent insecure function over secure one. Create a speed bump to prompt the programmer to think about their code, not a road block.

Re: Three mistakes from Dart/Flutter's weak PRNG

#82
post #80
post #74

Earlier quoted context omitted.

Personally, I forgot that Linux only fixed /dev/random in 2020 in kernel 5.6. That's not that long ago in terms of enterprise / LTS kernels. I'm sure this has been a surprising pain point for end-users for a long time, and perhaps still is in some environments. (Yes, I know, you have shared a workaround for a long time prior: https://sockpuppet.org/blog/2014/02/25/safely-generate-rando... . But that sort of presumes…

Right. But the context here is whether languages can make the (very big) decision to default to a CSPRNG, in which case: you make that decision once, for all your users, and when you do, you don't use "/dev/random".

Right!

Re: Three mistakes from Dart/Flutter's weak PRNG

#83

Why did Proton and SelfPrivacy use Random instead of Random.secure? DTD is local host or over SSH due to the unecrypted websocket. Browsers block unsecure WS over HTTPS. The key generated is for tagging multiple instances per IDE not security. Random is instant and is used for runtime collision prevention and performance especially UI, not uniqueness, PRNG is not truly random anyways. Random.secure has a large overhe…

In .NET it's just 'RandomNumberGenerator' from System.Security.Cryptography. 'RNGCryptoServiceProvider' is obsolete.

Re: Three mistakes from Dart/Flutter's weak PRNG

#84
post #72
post #23

Earlier quoted context omitted.

Rust does this. IMO, it's not worth it: It makes working with random numbers very problematic when working on cryptographic use cases.

Too late to edit: I meant non-cryptographic use cases

This makes much more sense

Re: Three mistakes from Dart/Flutter's weak PRNG

#85
post #45

Earlier quoted context omitted.

With any question like this, the path to an answer follows three intermediate questions: 1. Was there a security problem that resulted from the use of this insecure generator? 2. Were the developers who encountered this problem completely unreasonable and in the wrong, or were they simply non-(security)-experts who developed software that happened to have a security vulnerability? 3. If the latter, did the language/t…

That may be, but having the default generator be non-cryptographic has been the conventional design choice in languages since the dawn of time. I would get the willies seeing security-sensitive code using "Random()" even if you told me in your language "Random()" was a CSPRNG.

I don’t think you should have to hold the entire canon of programming history in your head to avoid these types of footguns. Conventional design choices of the past that lead to bugs and security vulnerabilities should be replaced.

Re: Three mistakes from Dart/Flutter's weak PRNG

#86
post #66

Earlier quoted context omitted.

Hah! Thanks for bringing that to my attention. :)

I missed it too (sorry, Matt) --- I wrote my comment in bed half awake (I have a problem) and without glasses (I'm old) I can't see for shit.

I didn't even realize I was replying to you, I feel like we've had this argument 100 times now.

Re: Three mistakes from Dart/Flutter's weak PRNG

#87

Earlier quoted context omitted.

> It's clear just from using the language that it was designed as a more "serious" Javascript replacement What is your usage of Dart? JavaScript is a target platform for Dart. The Dart interop story is the point. It’s a cohesive glue language. First class interop with JavaScript, Java/Kotlin, C++ and Swift/ObjC. Community interop supports go and rust. Maybe I am confused. We are comparing Dart to what again? Yes, Flu…

For clarity, I'll admit that I do not have industry experience with Dart. I have built a medium sized mobile application with it, and have spent a pretty good deal of time digging into Flutter's architecture and reading it's source code. If you are debating the statement I made: "It's clear just from using the language that it was designed as a more 'serious' Javascript replacement", it's simply a fact that the Dart…

> numerous attractive alternatives that are more familiar and popular

There’s React Native. Ionic is stuck in the same limbo that PWA are in and Tauri is obscure. Qt is hardly used in mobile apps and Microsoft’s successors for Xamarin deprecate themselves every few years. What else is there, NativeScript? Kivy? Delphi?

Re: Three mistakes from Dart/Flutter's weak PRNG

#88

Earlier quoted context omitted.

For clarity, I'll admit that I do not have industry experience with Dart. I have built a medium sized mobile application with it, and have spent a pretty good deal of time digging into Flutter's architecture and reading it's source code. If you are debating the statement I made: "It's clear just from using the language that it was designed as a more 'serious' Javascript replacement", it's simply a fact that the Dart…

> numerous attractive alternatives that are more familiar and popular There’s React Native. Ionic is stuck in the same limbo that PWA are in and Tauri is obscure. Qt is hardly used in mobile apps and Microsoft’s successors for Xamarin deprecate themselves every few years. What else is there, NativeScript? Kivy? Delphi?

Dart is really not much different from a PWA/Ionic though: the language requires bindings to use native APIs; it's runtime is not native to any platform (where as most platforms do have native web runtimes); and it's rendering system doesn't support native widgets (in fact, it currently uses Skia which is the same rendering library as Chrome).

Re: Three mistakes from Dart/Flutter's weak PRNG

#89

Earlier quoted context omitted.

The title had me quietly think to myself "Dart was the mistake". So many stack/enviornments are leveling up their languages: ObjC => Swift, Java => Kotlin, Erlang => Elixr, C++ => Rust, Javascript => Typescript Dart feels like one of the befores, not the afters.

Feels is the key to that statement. :-) It’s these “feels” that got USA to its 2024 election outcome.

Are you ok?

Re: Three mistakes from Dart/Flutter's weak PRNG

#90
post #73

Earlier quoted context omitted.

Performance / getting a seed

Why is the default thread_rng from the rand crate a dealbreaker for rust? There are other rngs to choose from rand like `smallrng` that is a small fast unspecified default prng if you don't know what you want even for a prng. If the worst case 300 microseconds of the reseeding ChaCha12 default rng is measurable, then it is your job to make a decision about your random number generator. I don't think rng seeding has a…

Seeding from the clock is perfectly appropriate for games, audio / video processing, ect.

Seeding from an entropy source is critical for encryption, but that can take time depending on how it works.

Post reply on HN