# HMAC SHA256 - fixed vs dynamic key - security and collision impacts

Assume we should apply an hmac sha256 on different messages made of incremental numbers (Ex. 1 to 1 billion). Does it make sense in terms of security to apply a different fixed key for each message?

message 1 key X1

message 2 key X2

...

message n key Xn

Will applying a key for each message impact the collision rate? If yes, will it increase or decrease the collision possibility?

The aim is to generate unique deterministic tokens starting from sequential values as source domain.

• There is uuid for this. There are deterministic modes that prevents the collision. – kelalaka Aug 22 '20 at 7:40

That would not change the expected probability of collision, which remains about $$n(n-1)/2^{257}$$ for $$n$$ values under a model of HMAC-SHA-256 as a PRF. For $$n=2^{40}$$ (over a million million, the UK bilion), that's less than $$2^{-177}$$, the probability of 177 consecutive tails with a fair coin, that is negligible in practice.