Key ladder
Vault-SoC. You have the firmware bundle (firmware_bundle.tar) of a secure storage module: bootrom.txt (an internal document), otp.bin (a fuse dump), stage1.enc, stage2.enc. The chain is unlocked through a key hierarchy (key ladder): each stage provides the key of the next one. At the last stage there is /etc/flag.enc.
Task 1 (OTP). otp.bin: 64 words, each of 5 bytes (LE), a 39-bit SECDED codeword: bit 0 is the overall parity, positions 1,2,4,8,16,32 are the Hamming check bits, and the remaining 32 positions (3,5,6,7,9,... in increasing order) are data. Correct single-bit errors. A word with a two-bit error cannot be corrected: do not "correct" it wrongly — for such a ROOT word, the ROM uses the mirror word at offset 0x20 instead. ROOT = words 0x10..0x17 (each 4 bytes big-endian, 32 bytes in total). K1 = HMAC-SHA256(ROOT, "stage1").
Task 2 (stage1). stage1.enc = IV(16) | AES-128-CBC (key K1[:16], PKCS#7). Plaintext: "LDR1" | u16 BE uzunlik | bytecode. If the padding turns out to be wrong, there is an error in the OTP correction.
Task 3 (key ladder). The bytecode is a small VM (registers r0..r3, byte strings; at the start r0 = K1): 01 rd len data (load); 02 rd ra rb (HMAC-SHA256, key = ra, message = rb); 03 rd ra rb (SHA256(ra|rb)); 04 rd ra rb (XOR); 07 rd n (n u16 BE: apply SHA256 n times in succession); FF (end). K2 = r0[:16]. The result of some commands is never used (decoys).
Task 4 (stage2). stage2.enc = counter block(16) | AES-128-CTR (K2, 128-bit BE counter). Plaintext: "S2IM" | u32 BE dtb_ofs, dtb_len, cpio_ofs, cpio_len | .... The DTB is a Flattened Device Tree; the vault-key-salt property of the /secure node is needed (the factory salt in /chosen is a decoy). The cpio is "newc" (070701).
Task 5 (final). K3 = SHA256(K2 | vault-key-salt)[:16]; etc/flag.enc = IV(16) | AES-128-CBC (K3). etc/flag.enc.factory is a decoy file encrypted with a different salt. The flag= inside is the flag.
Flag format: BAYROQ{IOT_KALIT_ZINAPOYA_xxxxxxxxxxxxxxxx} (the last 16 characters are lowercase hex).