2
$\begingroup$

I want to use MAC as an additional protection of UDP-server from DoS attacks. I prefer to keep MAC as short as possible and I assume 32 bit is good enough for this purpose.

I'm going to make it based on some well-known MAC (e.g. KECCAK Message Authentication Code)
Is it bad idea to use CRC32 of this MAC?
Or it is better to use first 4 bytes of MAC?

$\endgroup$

3 Answers 3

4
$\begingroup$

The common practice is to use the four leftmost bytes of the MAC. I would not use the CRC32 over the MAC. It's not more secure and if you're unlucky it is less secure. Besides that it is an unnecessary operation.

Note that 32 bits doesn't give you much security; I would only use it for realtime integrity / authentication or in case there are other reasons that prevent brute force attacks.

$\endgroup$
3
  • $\begingroup$ What do you mean when speaking about brute force attack? "Generate a lot of messages with random keys and some keys will be correct?" $\endgroup$
    – edo1
    Jul 17, 2017 at 18:57
  • 1
    $\begingroup$ Just create a lot of identical messages and vary the tag. With enough messages you're going to hit a correct tag in the end. Varying the key doesn't make sense. You would get identical tags, and finding the right key is impossible anyway (if the key size is large enough). $\endgroup$
    – Maarten Bodewes
    Jul 17, 2017 at 19:03
  • 1
    $\begingroup$ While I wouldn't recommend the CRC32 over the MAC, it can't be less secure if computed correctly; it it was, that attack on the CRC32-reduced version of the MAC would allow an attack on the MAC. $\endgroup$
    – fgrieu
    Jul 17, 2017 at 20:28
6
$\begingroup$

Don't truncate one-time-macs (e.g. GHash or Poly1305) because a successful forgery reveals part of the key. Poly1305 might be fine, if the receiver ensures nonce uniqueness and you derive the complete Poly1305 key from the nonce (i.e. both the multiplier and the mask).

On the other hand, truncating HMAC or MACs based on CBC-MAC (e.g. CMAC) is fine (I think it even avoids the prefix-weakness of plain CBC-MAC).

I would not consider CRC32, it's unkeyed and I can't think of an easy to build a secure MAC from it (GHash is probably the closest thing to a secure CRC).

I recommend going with a truncated HMAC. It's designed to be a PRF and since truncated PRFs are still PRFs, you can be certain that it has no weaknesses beyond the obvious $2^{-32}$ forgery chance.

$\endgroup$
10
  • 1
    $\begingroup$ KMAC as posted in the question would also be secure. $\endgroup$
    – Maarten Bodewes
    Jul 17, 2017 at 18:40
  • $\begingroup$ @MaartenBodewes KMAC was the keyed keccak mode? (Not a fan of using such a generic name, for such a specific algorithm) $\endgroup$ Jul 17, 2017 at 18:43
  • $\begingroup$ That's the only KMAC that I know of anyways :) $\endgroup$
    – Maarten Bodewes
    Jul 17, 2017 at 18:43
  • 1
    $\begingroup$ @edo1 In that case it's a harmless over-complication. CRC32(KMAC(msg)) offers no advantages over just truncating KMAC(msg) but it doesn't introduce any weaknesses either. $\endgroup$ Jul 17, 2017 at 20:44
  • 2
    $\begingroup$ It's worth noting that network traffic authentication is one of the use cases that SipHash was designed for. $\endgroup$ Jul 17, 2017 at 20:56
0
$\begingroup$

Al least with RNG if you want to short the value of generated number, is a bad idea just taking some bits out of the original number. It happens that the strength of the generator weakens. For instance with a Linear and Congruential Generator if you take just four bits out of the main generator of 32 bits, it will generate a sequence of just 2^4 values that repeats again and again.

The way we fix this issue is by performing a modulus operation of the original value of the generator with a number of the size we want to get. With this approach the strength of the generator is kept.

For your particular case you should: MinimalMAC = MAC%2^32

A possible problem that could arise is to have the tools to perform the modulus operation with large numbers but is you are using libraries such a openSSL, it will give you the functions to do that.

$\endgroup$
3
  • $\begingroup$ So you offer use last 4 bytes instead of first 4 bytes. Why that makes the difference? $\endgroup$
    – edo1
    Jul 30, 2017 at 12:41
  • $\begingroup$ I said taking just the 4 bytes would weak the strength of the algorithm. I mean to resize the full MAC to 32 bits using a modulus operation. $\endgroup$ Jul 31, 2017 at 17:33
  • $\begingroup$ MAC%2^32 is equal to last 4 bytes of MAC (for little-endian) $\endgroup$
    – edo1
    Jul 31, 2017 at 21:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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