U-boot AES decrypt performance


I want to keep my initrd in secret by AES encryption (128 bits key is ok). But the problem is u-boot aes command takes about 150seconds to decrypt 35MB initrd file.

Do you have any experience or idea to decrease the decryption time to reasonable time?
Thank you.

hello nvl1109,

could you please share the commands you’re used.
please share the steps in details that we can reproduce the issue locally to dig this further.

Hi Jerry and all,

Thanks for quick response.

Here are steps:
Compile time:
Enable AES command in u-boot:
Add these two lines into configs/p3450-0002_defconfig


Run time (because the performance of AES encode & decode are same, so can demo by encoding) in u-boot shell:
Please download key.bin and initrd.enc from my ggdrive and put them into sdcard/emmc of Jetson, assumed you put them into first partition, md5sum of initrd.enc is 14d0ac37ac863ce24e5c1d67f12859ff: uboot_enc - Google Drive

Step to decrypt initrd.enc in u-boot:

setenv encaddr 86000000
setenv keyaddr 85f80000
setenv ivaddr 85f80040
# Set IV and Key to all zero
mw.b $ivaddr 0 0x40
mw.b $keyaddr 0 0x40
# Load keyfile
fatload mmc 0:1 $keyaddr key.bin
# Load initrd.enc file
fatload mmc 0:1 $encaddr initrd.enc
# Start decryption
aes.128 dec $keyaddr $ivaddr $encaddr $ramdisk_addr_r 0x2300030
# Verify the result
md.b $ramdisk_addr_r 30 # Must show: This is firstline
md.b 88300000 30  # Must show: This is last line. Thank you

When I run these commands, the decrypted file looks like not completed. The head of decrypted file is ok, but tail is not decrypted.
Then I try to modify the sysboot.c in u-boot source code, to do add decryption into load command. The decrypted result is correct, but the decryption takes about 150 seconds.

To check the file is decrypted correctly, md5sum of original file is a58979c5ef66a2eda34383b990c691e3
Head and tail of original file:

$ hd initrd | head -n 3
00000000  54 68 69 73 20 69 73 20  66 69 72 73 74 6c 69 6e  |This is firstlin|
00000010  65 0a 75 30 03 9b cc 4c  18 cd 9c c8 52 dc 3b f6  |e.u0...L....R.;.|
00000020  8a 40 8e 28 83 5f 9a da  11 30 8b 5c 8c 3b 5c 9e  |.@.(._...0.\.;\.|

$ hd initrd | tail -n 3
02300010  43 fe 54 68 69 73 20 69  73 20 6c 61 73 74 20 6c  |C.This is last l|
02300020  69 6e 65 2e 20 54 68 61  6e 6b 20 79 6f 75 0a 2e  |ine. Thank you..|

Size of original file and encrypted file are 36700208 bytes (same for both)

hello nvl1109,

please also share the JetPack release version you’re working with,
you may check release tag for details. for example, $ cat /etc/nv_tegra_release

I’m using JP 4.4, L4T 32.4.3.

hello nvl1109,

FYI, the AES perf is pretty good with ARMv8 CE (Crypto Extention). please refer to the sample, crypto « arm64 « arch - kernel/git/stable/linux.git - Linux kernel stable tree
in that case,
you’ll need to port the code into U-Boot. because the CPU clock rate is low when running in u-boot. however, we cannot guarantee how much benefit you can get with the CE enhancement.

since AES decryption isn’t simple, and security isn’t free.
please either port more efficient/HW-assisted code to your U-Boot source, or, you should do a simpler sign/verify of the initrd in U-Boot.
please decide which approach is better depends-on your security model.