I wonder if there is any scheme or algorithm to generate HMACs that verify with multiple keys.

Suppose I have the secret keys K1, K2 and K3 and I have a message M1. Is the following possible?

  • Generate an HMAC1 with M1 that can be verified with K1 and K2 but not with K3

  • Generate a HMAC2 with M1 that can be verified with K2 and K3 but no longer with K1

  • Generate an HMAC3 with M1 that that can be verified with only K1 but not with K2 and K3

That is, to be able to authenticate a message to an arbitrary set of N keys. Maybe not with HMAC but with some other type of MAC algorithm.

I am analyzing if it is possible to issue OTPs (a truncated HMAC) against a series of devices (each one knows its key but not the key of the other devices) that authenticates a user only in an arbitrary subset of these devices.


  • 4
    $\begingroup$ "Generate an HMAC1 with M1 that can be verified with K1 and K2 but not with K3" - is there a reason that the obvious approach of 'HMAC(K1, M1) || HMAC(K2, M1)' is not acceptable? $\endgroup$
    – poncho
    Apr 17, 2023 at 1:39
  • $\begingroup$ Would be tricky to compress it further I guess. A hash over the authentication tags won't work if you can only calculate one of the tags. $\endgroup$
    – Maarten Bodewes
    Apr 17, 2023 at 13:23
  • $\begingroup$ Hi @poncho, thanks for answering. How would you compress the HMAC(K1, M1) || HMAC(K2, M1) structure into a 6 to 8 digit OTP? Assuming you are a device that only knows K1, how would you validate that OTP? $\endgroup$ Apr 17, 2023 at 13:44
  • $\begingroup$ @MaartenBodewes Yes, the idea is to issue OTPs to authenticate users in an arbirtary set of devices. The devices should be able to validate it only by knowing a key (their own). $\endgroup$ Apr 17, 2023 at 13:54


Your Answer

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

Browse other questions tagged or ask your own question.