What happened when I get a None

I wrote a self-made ECC code for experiments, and I have tested its correctness in my PC by a gcc compiler , then I put them into the simleserial-base project, like this


if the code is correctly executed, I should get a [0x00, 0x15, 0x00…], but when I send ‘pt’ to the board,I get nothing

Sorry about that I know little about embed programming!

The target board is STM32-F303, what happened here? How can I find this bug?

Thank you!

Hi,

If you get None back, it means you didn’t get any serial data back from the target. My guess is that either get_pt is never being called at all or EccPoint_multi is crashing. If you move the trigger_high() call back before your Ecc call, then do the following in Python:

import time
scope.arm()
time.sleep(0.1)
target.simpleserial_write('p', bytearray([0]*16))
time.sleep(0.1)
print(scope.capture())

do you see False printed? If not, it means your firmware isn’t reaching get_pt. Otherwise, I’d guess EccPoint_multi is crashing.

Unfortunately, a PC and an embedded device are very different, so C code that runs fine on one may not run on the other.

Alex

Thank you for your reply!

I have seen the print “False”, so, I guess it is crashing.

But now I have another question, what reasons will lead a crashing? I wrote this code all in C code, without any asm about platform. And after days of try, I can’t find a solution for that, I guess maybe there is a problem like stackoverflow, is it reasonable?

Thanks a lot for your help!

Looking for your reply!

Actually, one other thought I had is that you might not be waiting enough time between sending the message that starts the encryption and reading the result. Public key crypto in general is quite expensive, so I’d say try giving it like 30 seconds for the point mul to finish.

If it is crashing, it’s hard to say in general why that might be. Embedded devices have far less memory, so you might be overrunning the stack, or, if you’re using any dynamic memory allocation, running out of RAM.

If you’ve got a debugger for your microcontroller, that’s definitely the best way to work through stuff like this. If not, we do have an in progress update for ChipWhisperer that lets you use it as a debugger: GitHub - newaetech/chipwhisperer at mpsse (docs at chipwhisperer/debugging.rst at mpsse · newaetech/chipwhisperer · GitHub).

Alex

Hi Alex,

Thanks for your help! I have figured it out. Finally, I found if I make more variables become global or static, I can avoid an overflow, now it has been running correctly!

As for the mpsse branch, it is amazing, but it is not easier for me to use it, I plan to learn it in some days!

Luffy

Yeah, that sounds like a stack issue. I’ve run into the same thing on a different microcontroller. Good to hear that you got that resolved quickly, as that sort of thing can be very tricky to debug.

Alex