<div><span style="font-family: arial, sans-serif;">Hello or Salaam everyone,</span><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">I have a few questions regarding password hashing in general. And would very much appreciate any advice (just try not to use harsh words, please ;) ) </span><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">Before that, I want to tell you something brief about what I'm doing. Basically I'm building a product that you can call in common terms as a social media website. For starters, you can think that it is meant to be a replacement for facebook/twitter. One that would respect your privacy (centrally). Actually it is much more than that, but that is not relevant here. </span><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">Now this is not an advertisement, I'm not even naming it. I respect the purpose of this mailing list. But I just want to make clear my good intentions, and inform you about "to what end" I might use your valuable suggestions on which you may spend your valuable time.</span><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">Also, I know that it is a huge undertaking. And on that account I tell you that I have spent 7+ best years of my life, entirely dedicated to pressing out the details of how to not repeat the mistakes of the current crop and how to do the right thing. How to make it into a neutral platform from the get go, and how to not make it a means of lot of bad things. </span><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;"><br></span><span style="font-family: arial, sans-serif;">libgcrypt is an important tool, that can help me build such a product (like it has helped other such good intended projects). But Cryptography is not my forte, it might be yours, and that is exactly why I'm writing this email. </span><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;"><br></span></div><div><b><span style="font-family: arial, sans-serif;">I'm working on the login system currently, running FreeBSD 11 / Apache / C CGI</span></b><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;"><br></span></div><div><b><span style="font-family: arial, sans-serif;">Questions, in no particular order (correct me if I'm wrong anywhere): :</span></b><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">- FreeBSD recently replaced the RC4 algorithm with ChaCha20 in arc4random. While the libgcrypt is using SHA1 in its CSPRNG. </span><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">1. Is SHA1 secure in this role? For how long approximately? Are there plans to replace it with another algorithm in future?</span><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">2. How do both of them (arc4random and libgcrypt CSPRNG) compare in critical areas like security and efficiency? </span><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">- I see that (perhaps) Bcrypt is not available as a hash function in libgcrypt. I thought that it was (and is) a corner stone of password security? I don't understand. It is not a new hash function like Argon2, but an old one. I'm currently thinking of storing user passwords as salted bcrypt hash in a DB. </span><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">1. What are the reasons behind it not being there in libgcrypt (if so)? Is it not recommended? </span><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">2. I recently saw this: </span><a href="https://packages.debian.org/stretch/bcrypt"><span style="font-family: arial, sans-serif;">https://packages.debian.org/stretch/bcrypt</span></a><span style="font-family: arial, sans-serif;"> , are all current bcrypt implementations using ECB mode and are considered unsafe?</span><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">3. If it is still considered safe, would it be implemented anytime soon in libgcrypt? On a side not,  I recently saw this: </span><a href="https://www.openwall.com/presentations/Passwords14-Energy-Efficient-Cracking/"><span style="font-family: arial, sans-serif;">https://www.openwall.com/presentations/Passwords14-Energy-Efficient-Cracking/</span></a><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">- I do not yet fully understand the concept of KDFs and HMAC from the common texts (even after reading a few times), </span><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">1. Are they an option for me to use instead of common hashing? I heard a bit about the memory hard scrypt algorithm. </span><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;"><br></span><span style="font-family: arial, sans-serif;">- What is the ideal flow of the authentication system in terms of cryptography? I know there are a lot more steps, but I'm just asking about the broad ones. </span><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">Here is what I have in mind: </span><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">1. Take form data from user, and sanitize it (specially for overflow and malicious code in submitted form). </span><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">2. Make a connection to DB, and check if user exists (if not, then log it, throw error, and exit)</span><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">2.5 Allocate secure memory ? </span><b><span style="font-family: arial, sans-serif;"><-- not sure about this</span></b><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">3. Retrieve Unhashed Salt (before bcrypt) <--</span><b><span style="font-family: arial, sans-serif;"> I'm not sure about this step, should it be hashed salt or unhashed salt</span></b><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">4. Concatenate the Salt with User submitted password and hash it</span><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">5. Compare this hash with the hash in DB (stored salted hash) </span><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">6. explicit_bzero , the string that contained plain password submitted by the form, the string containing salt (retrieved from DB), and the strings containing both hashes ?</span><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">7. generate 2-3 session keys (that only work in combo for one session) using CSPRNG (</span><b><span style="font-family: arial, sans-serif;">should be hashed using SHA-384 perhaps??</span></b><span style="font-family: arial, sans-serif;">) and set cookies for session management</span><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">X. At some point use </span><b><span style="font-family: arial, sans-serif;">mlock</span></b><span style="font-family: arial, sans-serif;"> ? I do not understand what </span><b><span style="font-family: arial, sans-serif;">"preventing the swapping out"</span></b><span style="font-family: arial, sans-serif;"> means here.</span><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">X. At what point do I need to free the secure memory (if used) at the earliest? </span><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">- I see that minimum secure memory allocated is 16384 (This is 16kb? 8bit = 1byte?) in libgcrypt when using </span><code><span style="font-family: arial, sans-serif;">GCRYCTL_INIT_SECMEM;</span></code><span style="font-family: arial, sans-serif;"> </span></div><div><span style="font-family: arial, sans-serif;">1. Is this going to be enough in my case? </span><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">2. If not, how do I arrive at a reasonably efficient and safe size? I mean how do I calculate my secure memory need here?</span><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">- If I use "</span><code><span style="font-family: arial, sans-serif;">GCRYCTL_USE_SECURE_RNDPOOL"</span></code><span style="font-family: arial, sans-serif;"><br></span></div><div><code><span style="font-family: arial, sans-serif;">1. Do I still need </span></code><b><span style="font-family: arial, sans-serif;">gcry_random_bytes_secure </span></b><span style="font-family: arial, sans-serif;">convenience function? Can I just use </span><b><span style="font-family: arial, sans-serif;">gcry_randomize </span></b><span style="font-family: arial, sans-serif;">instead of it, and secure memory will be automatically allocated? </span><span style="font-family: arial, sans-serif;"><br></span></div><div><code><span style="font-family: arial, sans-serif;">2. In the format of gcry_random_bytes_secure and gcry_random_bytes, I do not see a "buf" argument. Then how are these two functions used? I mean, where are the random bytes generated callable from?</span></code><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;"><br></span></div><div><code><span style="font-family: arial, sans-serif;">- For error handling, I hear that libgpg-error is required by the libgcrypt.</span></code><span style="font-family: arial, sans-serif;"><br></span></div><div><code><span style="font-family: arial, sans-serif;">1. Does it requires any additional headers? </span><span style="font-family: arial, sans-serif;"><br></span><span style="font-family: arial, sans-serif;">2. What are the advantages of using the inbuilt error reporting of libgpg-error than normal error reporting in C? This question holds true for memory management as well. </span></code><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;"><br></span></div><div><code><span style="font-family: arial, sans-serif;">- I could really use a simple chart that shows the salt length/password length requirement of different algorithms used in libgcrypt. It is a suggestion. I had hard time arriving at the facts about bcrypt:</span></code><span style="font-family: arial, sans-serif;"><br></span></div><div><code><span style="font-family: arial, sans-serif;">password length min 8, maximum 56 in crypt(3)/FreeBSD, salt size should be </span><b><span style="font-family: arial, sans-serif;">exactly</span></b><span style="font-family: arial, sans-serif;"> 128bit or 16bytes (correct me if I'm wrong)? End result is of variable size? or fixed size? </span></code><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;"><br></span></div><div><code><span style="font-family: arial, sans-serif;">These are most of the questions I have at this point. </span></code><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;">Thank you in advance. Honestly I cannot give you anything in return, but I know that Almighty is a witness to all good deeds, and knows the deepest and slightest of intentions we have when we do good (or bad). If a person does a good thing/deed and expects a reward from only him, know that he is the best to reward, fully capable of doing everything (including calculating a more than generous reward of ones deed. In both this world and hereafter) </span><span style="font-family: arial, sans-serif;"><br></span></div><div><span style="font-family: arial, sans-serif;"><br></span></div><div class="protonmail_signature_block"><div class="protonmail_signature_block-user protonmail_signature_block-empty"><span style="font-family: arial, sans-serif;"><br></span></div><div class="protonmail_signature_block-proton"><span style="font-family: arial, sans-serif;">Sent with </span><a target="_blank" href="https://protonmail.com"><span style="font-family: arial, sans-serif;">ProtonMail</span></a><span style="font-family: arial, sans-serif;"> Secure Email.</span><br></div></div><div><br></div>