(How) Can we use HOTP for file encryption? I recently went through the list of available KeePass plug-ins and noticed one that advertises support for HOTP as a means to derive the database key.

Now I trust the developer of this plug-in who is Dominik Reichl, who also signs the KeePass releases, so I doubt this is some sort of KeePass-only feature that won't actually increase file security.

How can we use HOTP to as a factor to derive a key suitable for file encryption?



This is especially puzzling as it claims support for any HOTP client that complies to RFC 4226, which advises to compute the shared-keyed HMAC of a counter and then convert this into a decimal number and I really don't understand how one could leverage this number into a good source for the key.
I had only a quick read through the source, and I am not particularly fluent in C#, so I may have gotten something wrong. That said the process appears to be:


Generate a random encryption key, encrypt the database with it.
Generate (up to six) HOTP tokens, derive a key from those, use that to encrypt the database key.
To read:


Ask for the HOTP tokens, derive the key, check that it matches.
Decrypt the database key, so it can be read.
Generate new HOTP tokens, use those to re-encrypt the database key for  next access.



So by hashing several HOTP tokens you get enough entropy for a strong key – up to ~160 bits if you use the full six tokens with eight decimals each. Additional computational entropy may be added by the iterated hashing process.

By always encrypting the key with a new set of tokens you ensure they are only used once.

The HOTP secret is stored in encrypted form, so it can only be used to derive tokens when a set of matching tokens has been received.