1
$\begingroup$

I have 256-bit value (call it "{Secret Value}") and I would like to compute HMAC-SHA256 digest of this value to check its integrity, and second requirement is to minimize need of another artifacts for this process.

I have an idea that do not need any other artifact but {Secret Value}:

  1. Compute PBKDF2 key from {Secret Value}, and as a salt use first 64 bits of my {Secret Value}
  2. Key computed in step 1 use as key for HMAC-SHA256 and as value use {Secret Value}

Another option in step 1 is compute another PBKDF2 key for salt value from {Secret Value}.

I need to create this integrity digest to check if {Security Value} comming from user is the same as value I have in database.

Is this approach secure enough?

$\endgroup$
2
$\begingroup$

If you do this like that you won't guarantee the authenticity of your message, only its integrity, as you say you want to... but then if you only need to check integrity, you would be fine with a simpler SHA256.

But FWIW, HMAC is like a wrapper around a secure hash function adding a key, so if you remove the key, you end up with a secure hash function, plus some sequin, if I dare say so.

So, I wouldn't say it is secure per se, unless I knew what problem you are trying to solve, but this way to go will provide you with integrity while using a somewhat more complicated method than usual. (Which is generally not recommended.)

EDIT to address Artegon's comment:
If you really want to use HMAC for your purpose (which is to compare a client value with a value in the server database), you can do so with a challenge-response mechanism, you can use for example the SCRAM one which will use PBKDF2 and HMAC, like you do, but in a way that guarantee that the secret is not leaked and the authenticity of the parties is assured even in case of a MITM.

Otherwise you can devise one which is weak to MITM attack by simply doing the HMAC of the challenge using the secret value as HMAC key... (But you should do so only if you know for sure your channel is secured against MITM attack thanks to public key crypto/a shared secret/etc, otherwise you have to first establish a secure channel, e.g. using your shard secret value to do so... But then you could as well use SCRAM, since it already exists and is good.)

$\endgroup$
  • $\begingroup$ Not sure that SHA256 is enough to stay secret value secure. $\endgroup$ – Artegon Jun 13 '17 at 11:19
  • $\begingroup$ Well, maybe you are mixing integrity and authenticity. Please read this question and its answer and tell me which one you want. $\endgroup$ – Lery Jun 13 '17 at 11:24
  • $\begingroup$ Integrity (I need to check, if value that comes from user input is the same as a value I have in database). $\endgroup$ – Artegon Jun 13 '17 at 11:26
  • $\begingroup$ Then you do not need HMAC. Hopefully that value isn't a password, if it is you want to be using a password hashing function like bcrypt, scrypt, or argon2. $\endgroup$ – SAI Peregrinus Jun 13 '17 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.