5

I need to select a function that will be used as a key derivation function (KDF) and pseudorandom function (PRF) in contexts that I haven't anticipated. It will run on very low-end devices (think potato-powered IoT sensor with a bulk cost of a fraction of a cent). It will also run on higher-end devices that have the luxury of a hardware AES accelerator (costing a larger fraction of a cent), sometimes specifically an AES-CMAC accelerator. As a consequence, the key derivation function must be based on AES and should be based on AES-CMAC. Since this is for low-end devices, efficiency is a concern: we want to keep down CPU cycles, power consumption, RAM usage and code size.

I don't have any strict compliance or interoperability requirements. However, it's likely that some products using this KDF will want to obtain certifications such as FIPS. And it would be nice if the KDF was easy to implement on existing crypto APIs such as PKCS#11.

The obvious candidate is SP 800-108 KDF in counter mode. In a nutshell, output block $i$ is $$ \mathrm{out}[i] = \mathrm{CMAC}_{K}(i \mathop\Vert \mathrm{info}) $$ But it has a number of downsides:

  • This requires a secret master key $K$ of exactly 128 bits. That's perfectly fine where $K$ is a master key that's generated for the sake of this key derivation function. But it isn't suitable, for example, to derive material from an ECDH shared secret.

  • If the secrecy of $K$ is compromised, this breaks the security of the KDF — if you know $K$, you can create collisions in the output. This is fine when this construction is used with HMAC or KMAC but not with CMAC. SP 800-108r1 offers a countermeasure:

    $$ \mathrm{out}[i] = \mathrm{CMAC}_{K}(i \mathop\Vert \mathrm{info} \mathop\Vert K') \qquad \text{where } K' = \mathrm{CMAC}_{K}(\mathrm{info}) $$ But it isn't completely clear to me what the security properties of this construction are with respect to a party that knows $K$.

  • It processes the whole input for each output block, which is inefficient in terms of both CPU cycles and RAM usage.

Is there a key derivation function that meets the following requirements? If not, what comes closest?

  • Requires only AES-CMAC (or at the very least only AES) as a cryptographic building block.
  • Takes two inputs secret and info of arbitrary length up to a reasonable bound.
  • Can produce at least a few kilobytes of output, incrementally.
  • Can be implemented in $O(1)$ memory with respect to the length of the inputs, even when emitting output blocks incrementally.
  • Has good security properties. I'm not sure what the formal security properties should be, but they should cover the case where two parties know the “secret” input and can select part of the non-secret input, and predictability or collisions in the output are a concern. Basically, I'd like to have the same security properties as a hash-based KDF, because it's likely that people will take existing protocols built for a hash-based KDF and they'll substitute my KDF because AES is more efficient on their device.
  • Has been studied by cryptographers. I'm reluctantly selecting my own because the world doesn't seem to have settled on one, but I don't want to completely roll my own.

1 Answers1

-1

It seems to me that your requirements are such that you can't solve the problem as it appears to be stated.

  • You only have AES.
  • You have no AES key.

And that's an issue. Without a key, then AES is just some function that emits pseudorandom, but guessable numbers.

However, you also have this secret ECDH key. If you had a hash function, you could turn that into a short secret key. But you don't have that. Wellllllll, if you did..... Maybe that's your answer?

Okay, okay, you can't add the extra code. Fine. We can't solve your problem that way. Let's look at other solutions. Here's the best one I can think of:

How did you get the ECDH key on that device? Where did it come from? Can you also send over another 128 bits as an AES key? If you can, you can then use CMAC and Alice is your auntie.

Given your constraints as you have described them, I think your easiest solution is to provision the device with an ECDH key and a CMAC key. If you do that, the problem has a solution. If you don't do that, then you need to do find some solution like adding in a hash function for a KDF.

Do I understand your situation properly?

Jon Callas
  • 2,371
  • 15
  • 15