All posts

Argon2id: the heaviest way to turn a password into a key

LNote is a notes app that never uploads your notes. They sit on the phone, encrypted, and open only with a password. That means the whole app’s safety comes down to one password, and it’s the part we spent the longest on: how do you turn something a person memorizes into a proper encryption key?

A password isn’t a key

To lock data with AES-256 you need a 32-byte key, and it has to be truly random. Passwords people pick aren’t. They come in every length, and however clever they look, they rarely stray far from words, dates, and familiar patterns.

So there’s a step in between that turns the password into a key, usually called a key derivation function (KDF). The obvious move is to run the password through a hash like SHA-256 and use the 32 bytes that come out. Right length, one line of code.

The problem is that SHA-256 is fast.

Why fast is bad here

SHA-256 was made to check quickly that a file hasn’t changed. Speed is the point, and a single modern graphics card runs billions of them a second.

Picture someone copying the encrypted file off a phone. They take a list of common passwords, hash each one, and see whether the resulting key opens the file. At billions of tries a second, most passwords don’t last. For a user who knows the password, the difference between 0.001 seconds and half a second is nothing. For someone guessing, it’s everything.

Heavy on purpose

Argon2id makes this step slow and heavy on purpose. A user runs it once to unlock and waits a moment. Someone guessing pays that cost again on every try.

Slowing things down isn’t a new idea. PBKDF2 has long repeated a hash hundreds of thousands of times to burn time. But repetition alone only goes so far. Graphics cards and custom chips are very good at running thousands of copies of the same calculation side by side, and you can always buy more of them.

What Argon2id adds is memory. With LNote’s settings, each run grabs 64 MiB and keeps reading back and forth across it. Try to save memory and the amount of computation shoots up. At 64 MiB a guess, a thousand parallel guesses need 64 GB. Compute is easy to scale; fast memory isn’t nearly as cheap. It takes away the resource an attacker can add most cheaply.

We like to explain it as a safe where every click of the dial means lifting a heavy weight. If you know the combination you lift it once. If you’re trying every combination, you’re lifting it hundreds of millions of times.

A different salt on every device

However heavy each run is, one gap remains. Someone could compute results for a few million common passwords once, keep them in a table, and use that table against everyone.

That’s what a salt is for: a random value mixed in with the password. LNote creates a fresh 16-byte salt when you first set up the app and stores it on the device. It doesn’t need to be secret. Because it differs per device, two people using the same “summer2026!” get completely different keys on their phones. Precomputed tables stop working, and an attacker has to start the heavy work over for each device.

Why the “id”

Argon2 won the Password Hashing Competition in 2015 and became a standard as RFC 9106 in 2021. It comes in three flavors ending in d, i, and id, which is confusing at first.

The difference is the order in which it reads memory. Argon2d picks its reads based on the password. It’s the strongest against brute force on graphics cards, but it can leak information to side-channel attacks that watch timing or cache behavior. Argon2i reads in an order unrelated to the password, so it resists side channels but is a bit weaker against graphics cards.

Argon2id does the first part the i way and the rest the d way. If you have no reason to defend against one kind of attack over the other, which is most apps, this is the one to use, and it’s what RFC 9106 recommends by default. We didn’t need to deliberate.

The values in LNote

With Argon2id you choose the memory size, the number of passes, and the parallelism. LNote uses 64 MiB, 3 passes, and a parallelism of 4, with a 16-byte salt and a 32-byte output to match AES-256.

We didn’t invent those numbers. RFC 9106 gives two recommended settings. The first uses 2 GiB of memory, which no phone app should grab just to unlock, so we took the second one, meant for memory-constrained environments, as is.

The first rule for the implementation was not to write the algorithm ourselves. Crypto code that’s wrong by a single character still runs and looks fine. We took the reference C implementation published by Argon2’s authors, used the same code on iOS and Android, and ran the known-answer examples from the RFC and the reference implementation on both platforms to make sure not a single byte differed.

Next was the screen. Churning through 64 MiB on the thread that draws the UI would freeze the app, so the work runs on its own thread, with a single queue so mashing the button doesn’t stack up calculations. Password and key bytes get overwritten with zeros as soon as we’re done with them. We can’t claim that copies left deep inside the operating system or the JavaScript engine are fully gone, though, and our internal docs say so.

What it still can’t stop

All Argon2id does is slow down guessing. It doesn’t prevent it.

If a password can be guessed in a handful of tries, like “1234”, it doesn’t matter how heavy each try is. That’s why LNote requires at least 12 characters. And if you forget your password, there’s no getting it back. There’s no copy on a server and the key comes only from the password. It’s inconvenient, but there was no way around it if the app was going to be safe.

An unlocked phone is also outside Argon2id’s reach. Someone looking at an open screen, or a malicious app capturing it, has to be handled some other way. That’s why LNote covers its content when you leave the app, locks after three minutes untouched, and blocks screenshots on Android.

If you’re building something that locks data behind a password, think of Argon2id before you reach for a single hash. Your users will barely notice. The people guessing will.

Want notes that stay offline, for your eyes only? → See LNote

References