Bob gets the IV ciphertext and algorithm, loads the identical key into memory from his copy, and then there is a very similar looking API, creates decipherIV, and calling update and final on the decipher object. And this will get back the original plaintext that Alice wanted to share with Bob.
So we talked about the key. What value can we use as the key? We might be tempted to use a human memorable password as the key itself, because it's easy to remember. But this is a problem. We mentioned before that we have a large space of options to store the key, right? With 256 bits. If Eve the attacker can assume that Alice is using a human memorable password as the key, then Eve doesn't really have to try all combinations within that really big space of options. She instead can limit herself to a much narrower set of human memorable passwords.
So this is why we don't want to use a human memorable password as the key. So what can we use if we still want to rely on something which we remember as the basis of our security and our key? For this, we can use something which we call a key derivation function, or KDF for short. A KDF is similar to a hash function, which you might be familiar with from checking the integrity of files. It is a deterministic one-way function, and you give it the human memorable password and it expands it. The output is something that will provide a much stronger, longer key, which we can use for our encryption. Unlike a normal hash function, the KDF is meant to be purposefully slow, which is not something you see often when we design things to be slow on purpose.
The reason we do this is because the fact that this function is slow won't slow down Alice, because she only has to execute this function once for the password that she remembers, but it will slow down Eve. What Eve might try to do is download the list of, let's say, the 10,000 most commonly used passwords from the internet, and then in order to derive the key from them on every iteration on that list of 10,000 options, she will need to run this expensive KDF function. This is going to slow down Eve, the attacker. This sounds good. We understand the value of the KDF. But if you think about it, there's still a part missing because what Eve can do is not go to the internet and just download a list of the 10,000 most commonly used passwords. She can download a list of pre-computed values when those common passwords are passed through some well-known KDF that she can assume that is used in the encryption. And if this is the case, if this is possible, then the KDF is not slowing her down at all, and it's just making life more complicated for Alice and Bob.
So this is why crucially in a real-world scenario with a KDF, there is a second parameter, not just the password, but another random value, which we call the salt value. So even if Eve has access to our salt, in order to try these well-known passwords, she will have to pay the cost of running the function for each iteration with the salt value. And this is what is making sure that the KDF is really slowing her down and preventing her from brute forcing our password. So let's see how this is done in Node.js. We can take a look at the s-script KDF, which is a well-known KDF, secure crypt. It's available inside the Crypto module. And you can see we're taking the password, generating random bytes as the salt, passing those to the s-script function, and we get back a key which we can use. Another notable mention here, we have two other KDFs baked into the Crypto module.
Comments