2

I need your advice on following scheme of exchange protocol between remote lock and key. I'm planning to use following algorithm:

  1. Key generates unique value that never repeats (in reality it's just counter that increments every time the button is pressed), let's call it "NONCE1".

  2. Key sends a request to the lock which consists of NONCE1 and H1 = MD5(NONCE1 + KEY1). Second part is used only for "signing" the request, attacker wouldn't be able to generate valid request if he doesn't know KEY1.

  3. Lock checks if H1 = MD5(NONCE1 + KEY1), this is used to check if incoming request is coming from the key (or at least from the one who is aware of the value of KEY1). Additional steps that were not described previously is:

    • Lock checks if NONCE1 of the previous key request less than NONCE1 received just now. This part prevents acting on previously processed requests, attacker who has such request won't be able to go any further. I'm trying to leave him in the situation where old requests are not accepted by the lock, and new requests couldn't be generated because he can't reproduce it without KEY1.

    • Lock sets NONCE1(previous request) = NONCE1(current request)

  4. Lock generates completely unique value that never repeats, let's call it "NONCE2".

  5. Lock sends a response to the key which consists of H2 = MD5(NONCE2 + KEY2). NONCE2 - is counter based (in order to completely exclude possible collisions), so in order to hide it's "counter - based nature" from an attacker, MD5(NONCE2 + KEY2) is used here.

  6. Key does H3 = MD5(H2 + KEY3) and sends it back to the lock

  7. Lock checks if H3 = MD5(H2 + KEY3) and acts on that

What could be possible vulnerabilities? Is it safe enough to use MD5 in this particular case?

I've added some additional "substeps" to clarify it a little bit

Accepted suggestion / solution is following:

  • Get rid of steps 1 - 3
  • Replace MD5 with HMAC-XXX
Ruslan
  • 23
  • 3
  • 1
    Use HMAC not a silly ad-hoc MAC. – CodesInChaos Jan 29 '16 at 09:05
  • salt1/2/3 - yes it's secret keys known only by key and the lock and they never transferred in between. Nonce1 / Nonce2 / Nonce3 - would be correct names for them just for better understanding? 2) How HMAC would possibly improve security in this case?
  • – Ruslan Jan 29 '16 at 09:10
  • Your MAC $H(M+K)$ relies on the collision resistance of the hash, which is broken for MD5. $H(K+M)$ would be even worse. HMAC does not rely on collision resistance and is explicitly designed to be used as a MAC. So using HMAC is essential for such a protocol. – CodesInChaos Jan 29 '16 at 09:35
  • I'm more or less understand what your point is, but I think that the collision resistance it's not actually what it relies on, because even if you find another string that gives you same hash it won't give you anything? That's why I especially mentioned about MD5 in this very special case, where critical part of it - is ability to find an original message using it's hash, which is I think for MD5 is not that easy. If you know the value of H2, would it be relatively easy to fake (generate) H3? – Ruslan Jan 29 '16 at 09:45