cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
266 Views
Registered: ‎01-02-2019

Using the AES device key from Linux on ZynqMP

The system is a 2020.1 Linux, 5.4 kernel with the zynqmp-aes kernel module loaded.

We are running a secure boot, authenticated and encrypted.

The AES key is in the eFuse.

The intent is to be able to encrypt a file off system with the same AES key we burned to the eFuse. Then on the board, decrypt the file using the hardware key.

So for instance, right now I have a userland program that lets me test the zynqmp-aes kernel module and just for debug also lets me specify an IV so I can keep it constant.

If I encrypt a small piece of data using a user provided KUP key I can do this

./enc -k key -i iv -p data -c data.enc
./dec -k key -c data.enc -p data.dec
diff data data.dec
<the same>

I can also do the same thing off-board on another workstation using the same key, iv and data and another aes-gcm utility.

So that all works as expected.

Now if I tell the driver to use the AES_DEVICE_KEY I also get consistent results

./enc -k AES_DEVICE_KEY -i iv -p data -c data.enc
./dec -k AES_DEVICE_KEY -c data.enc -p data.dec
diff data data.dec
<the same>


I definitely know the value of the AES_DEVICE_KEY, as again I am running a successful encrypted boot, so generating a boot.bin with the known key. (Also the AES_DEVICE_KEY option is rejected by the linux driver/PMU if I am not running secure boot.)

But if I try to do this with 'key' equal to the AES key burned to the efuse (i.e. the same key we used for the boot header of boot.bin).

./enc -k key -i iv -p data -c data.enc
./dec -k AES_DEVICE_KEY -c data.enc -p data.dec
diff data data.dec

Likewise this fails

./enc -k AES_DEVICE_KEY -i iv -p data -c data.enc
./dec -k key -c data.enc -p data.dec
diff data data.dec
<files differ>

So pretty sure this is just an endian thing with the way the key is being handled by the PMU vs the way it is handled by the CSU on initial boot.

Is my theory correct?

If so, can someone quickly advise how I should swap around the byte order of the AES key I use from the command line so that my examples will work?

Thanks.

2 Replies
Highlighted
Moderator
Moderator
155 Views
Registered: ‎10-30-2017

Hi scott@jumpnowtek.com ,

Please refer to Figure 12-2 of the TRM to see how the keys are controlled. The ROM controls the first mux. The user controls the mux between the Device Key and the User Key.

1.  During the boot process, ROM will start with the BBRAM key. In the most secure applications, the customer should be using the Operational Key. The ROM will use the BBRAM key to decrypt the Operational Key. The ROM then sets the device key mux to point to the Operational Key. As the ROM decrypts the FSBL, it will start with the Operational Key and if key rolling is used, it will use the KUP to hold the decrypted keys from key rolling.


2.  The FSBL then comes up. It will use the Operational Key to start each partition. If key rolling is used, it will used the KUP to hold the decrypted keys from key rolling. The FSBL can never get back to the BBRAM key.


3. When the user application runs, it can do the same thing as the FSBL. It can pick between the Operational Key (which comes from the FSBL boot image) or it can load its own keys using the KUP.

If the Operational Key is NOT used, then in #2 and #3 the customer would be able to pick between the BBRAM key and the KUP. However, this is a less secure way to use the device and is therefore not recommended.

Best Regards,

Srikanth

 

0 Kudos
Highlighted
Visitor
Visitor
94 Views
Registered: ‎08-10-2020

Thank you Srikanth.

I reasked and then answered myself over in the Embedded Linux forum

https://forums.xilinx.com/t5/Embedded-Linux/Using-the-AES-device-key-from-Linux-on-ZynqMP/m-p/1133108

Your answer provides more detail and maybe you want to repost there as well.

I have another question about the aes engine and Linux, maybe you know the answer to that as well

https://forums.xilinx.com/t5/Embedded-Linux/Transaction-size-limitation-with-zynqmp-aes-kernel-module/m-p/1137726

 

0 Kudos