TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Cryptography questions (key shortening and key verification)

1 点作者 CraftThatBlock超过 7 年前
I&#x27;m currently building a password generator (ignore the details) and I have some questions about what is the best way to do things. I have 2 questions.<p>I&#x27;ve posted the individual questions in comments since it would go over the 2000 character limit.<p>Basically it boils down to 2 simple questions:<p>1) What is the best and simplest way to get a 256 bit key from a 512 bit key.<p>2) What is the best way to verify the 512 bit key is correct?<p>Thank you very much for your time and thoughts.

2 条评论

CraftThatBlock超过 7 年前
1) Getting a shortened key<p>To start off, users enter a master password, which a key is then derived from (with a salt from a server) using scrypt, which a key length of 512 bits (the dkLen could be changed, although I would like to keep it to 512 bits&#x2F;64 bytes for legacy reasons).<p>On the client-side, I would also like to use AES, which requires 256 bits (or 128&#x2F;192) keys. My problem is getting a shorter key that is based on the original key.<p>My current proposal is using PBKDF2 (with HMAC-SHA-256) with a salt from the server (or use the same salt as the master key) to derive a secondary key, which will be recreated every time the user logs in. My problem with this solution is that there is no need for an intensive deriviation, since the original key will already be &quot;secure&quot;, therefor having a low iteration count (or even just 1) would be an option. Which could also just be HMAC-SHA-256(master key, salt).<p>My second solution is simply calculating the SHA-256 of the master key, since using a salt seems overkill for digesting a 512 bits key already. This is simpler since there&#x27;s no need to store a secondary salt (if not using the master salt). I would prefer this solution but I&#x27;m unsure if this is fit for this usage, since the generated hash would be used for AES purposes.<p>The third solution was to simply slice the master key and take the first half, which would be 256 bits. I was also unsure if this would be recommended.
CraftThatBlock超过 7 年前
2) Key signature<p>Since the server side doesn&#x27;t store the key of the user, I would like a way to still be able to tell the user if their password is wrong. I need a way to generate something that can be stored on the server, that the user can sent when generating the initial key, and then can resend when logging in, that the server can reply true&#x2F;false if the master key&#x2F;password is correct.<p>My initial thought was to simply hash the master key and store that. I was going to use SHA-256 but since I might use that to get the AES key, I had to revisit it. Would simply generating a low-entropy&#x2F;length hash from say MD5, and storing that, be a good option? I&#x27;m not worried about collisions, since the chance the user gets a collision for their own password is extremely low.