Investigating Block Cipher Modes with DPA

Hello All,

I am new to using chipwhisperer and wanted to explore more than the tutorials. I was interested in breaking the models like CTR / CFB / OFB etc. So I started with CTR.

The standard models do not seem to work on them and I was wondering on how do I start to attacks these implementations. I am looking forward to create a “methodology” that I can follow to attack these ciphers. I do understand the implementation behind them.

UPDATE: I did view this knowledge base
Investigating Block Cipher Modes with DPA

Is there any way I can compile an individual bootloader, Like i start with CTR, accomplish it and then move forward with breaking CFB.

Hi Matt,

The trick to attacking different encryption modes is figuring out what’s being used as the “plaintext” to the block cipher. If you worked through the manual CPA attack, you know that the leakage model we used these was

sbox[pt ^ keyguess]

The new thing with different cipher modes is that this pt input is being changed. For example, in CFB mode, the leakage would be

sbox[previous_ct ^ keyguess]

Of course, it’ll take a little bit more work to get the previous ciphertext, but that’s definitely available from the ChipWhisperer’s capture results. You should be able to set up some sort of methodology to automatically try each of the modes in an attack.

For your target, are you just looking to compile several XMEGA programs that run each encryption type? The firmware from the knowledge base article is in the ChipWhisperer repo (chipwhisperer\hardware\victims\firmware\simpleserial-aes-modes). You might want to take this code and use it to write something like a bootloader instead.

I understand. I did follow the tutorial. thank you for guiding me on that.
I will check on that and use it as a bootloader. Thank you.

Hello Gdeon,

I learnt about CFB and understood the leakage and I followed the manual CPA attack, however I am not able to recover the last 5 bytes of the key. this was the code that I used, is there something that I should look at?

for tnum in range(0, numtraces):
hyp[tnum] = HW[intermediate(ct[tnum-1][bnum], kguess)]

where CT is the cipher text

Happy to hear that you sorted out most of your problem - nice work.

How long are your traces? Usually, if the target is running software encryption (ie: not an AES peripheral), it’ll calculate one sbox output at a time. If it has to do any work in between these sbox lookups, the whole SubBytes operation could easily take 1000 clock cycles. If you’re capturing very short traces, you might be catching the first 11 SubBytes outputs but not the last 5.

Thank you Gdeon, your support helped. It seems to be the problem with other ciphers as well, I tried with OFB and CBC too. I am taking 3000 samples and 200 traces. Will move the number of traces to 2000 and check if I’m able to crack the keys.

I think the problem isn’t the number of traces - it’s that you’re not capturing the entire SubBytes step. For any XMEGA software 1000 traces should definitely be enough. Instead, try capturing something like 5000 samples in each trace.

Hey,

I changed the traces back to 1500 and the number of samples to 5000 and was able to recover they keys! This feels good! thanks a lot :slight_smile:

Just another question, I was wondering if there is any way to implement my leakage model on the Chipshiwperer analyzer instead of using the script? I want to see the next best guesses (upto 3 best).

You can definitely add this to the analyzer. All of the analyzer’s models are taken from chipwhisperer/analyzer/attacks/models. For example, in AES128_8bit.py, a typical model looks like:

class SBox_output(AESLeakageHelper):
    name = 'HW: AES SBox Output, First Round (Enc)'
    c_model_enum_value = 1
    c_model_enum_name = 'LEAK_HW_SBOXOUT_FIRSTROUND'
    def leakage(self, pt, ct, key, bnum):
        return self.sbox(pt[bnum] ^ key[bnum])

You can copy one of these models and write your own to match them. Don’t forget to add your class to the enc_list array in this file!

You could also do this in Python. If you’re still modifying the tutorial script, you could change these two lines:

maxcpa[kguess] = max(abs(cpaoutput[kguess]))
...
bestguess[bnum] = np.argmax(maxcpa)

I think you can use the numpy function argsort to help you list all 256 guesses in order. Then, you can just print the top 3 guesses (or however many you want).

thank you! I was able to do it. I want to use the UI for looking at the keys and progress. I’m a little lost on how to integrate my models with the analyzer software.

You may want to check: