software-based-PUF icon indicating copy to clipboard operation
software-based-PUF copied to clipboard

Reconstruction of key is not working.

Open jafeelv opened this issue 2 years ago • 23 comments

After enrollment, challenge and helper data are generated. But not able to reconstruct the key.

jafeelv avatar May 06 '23 05:05 jafeelv

I have also had failures reconstructing the key but succeed reconstructing the key in the past. IIRC, reconstruction only succeeded when the micro sdcard was formatted with the "official" sd association formatter, found here:

Linux: https://www.sdcard.org/downloads/sd-memory-card-formatter-for-linux/ win/mac: https://www.sdcard.org/downloads/formatter/

It is strongly recommended to use that formatter in the adafruit sd breakout board docs, see here:

https://learn.adafruit.com/adafruit-micro-sd-breakout-board-card-tutorial/formatting-notes

regards,

myndcryme

myndcryme avatar May 08 '23 13:05 myndcryme

@myndcryme Yes, I formatted it with the above-mentioned formatter only. Even though challenger data and helper data are generated and saved in sd card, I wasn't able to reconstruct the key

jafeelv avatar May 08 '23 16:05 jafeelv

Seems like you have done everything correctly so there must be an issue with the code. I have a guess of why it is failing so I'll take a look.

myndcryme avatar May 09 '23 13:05 myndcryme

@myndcryme thank you

jafeelv avatar May 09 '23 16:05 jafeelv

@jafeelv - Reconstruction is working for me, however I am having an issue with the PUF-encrypt step (I'll discuss another time).

Are you seeing "error" in your output when performing reconstruction? What size micro SD are you using? If the card is too large the SDformatting tool above formats it as exFAT which will not work.

myndcryme avatar May 16 '23 22:05 myndcryme

@myndcryme Thanks for the reply. I'm using 16GB MicroSD and not showing "error". But, if there is problem with SDformatting tool or SD card size, will it be able to save helper data and challenger data into SD card?

jafeelv avatar May 17 '23 05:05 jafeelv

16GB formats FAT32 so that is not the problem. Just to be clear, no PUF key is displayed in the terminal, correct?

myndcryme avatar May 17 '23 14:05 myndcryme

@myndcryme no PUF key is displayed.. it shows only "Initializing SD card...initialization done."

jafeelv avatar May 17 '23 17:05 jafeelv

@jafeelv Bear with me, I am still working on identifying the cause but made good progress today.

myndcryme avatar May 22 '23 21:05 myndcryme

@myndcryme Sure. Thanks

jafeelv avatar May 24 '23 06:05 jafeelv

@jafeelv I figure once your sd card is initialized you get nothing more because the SD.open() call is failing. This has been happening to me not in reconstruction, but in puf-encrypt the SD.open() call inside readHelperDatafromMicroSD() fails to open the helper file. I think we are experiencing the same problem.

This has been difficult to pin down because the problem appears to be within one of the SD dependencies, not this puf codebase.

arduino-libraries/SD.h and related libs have some weird bugs. At some point my installation broke and I'm pretty sure it was because platformio auto updated my SD dependencies. I'm not 100% sure, but I think I know the bug responsible, which is currently labeled as an imperfection so I don't expect a fix and a workaround is needed.

I found that inlining both the readHelperDatafromMicroSD() and readSRAMDatafromMicroSD() is a workaround. Don't allow the compiler to optimize the inline away with a simple inline. Add the following before both readHelper and readSRAM function definitions:

inline __attribute__((always_inline))

If it solves your issue then I am certain all installs are broken and I will have to do a pull request.

myndcryme avatar May 24 '23 21:05 myndcryme

@jafeelv Did it work?

myndcryme avatar May 26 '23 16:05 myndcryme

@myndcryme thank you sou much.. It worked.. image PUF Key is generated

jafeelv avatar May 29 '23 06:05 jafeelv

It mostly works... but those preceeding zeros don't look right.

I think the SRAM might not be ready since the function is now inlined and the readSRAM call is too fast. I don't have time to check it myself right now, but can you try adding a 1 second delay between turn_on_sram() function and readSRAMfromMicroSD() - that should give the SRAM time to initialize if that is the problem.

turn_on_sram(); delay(1000); // add this readSRAMfromMicroSD(); turn_off_sram(); readHelperDatafromMicroSD();

Give it a shot and let me know

myndcryme avatar May 29 '23 15:05 myndcryme

@myndcryme I'll try and update.. But some other errors came now from nowhere image image

jafeelv avatar May 29 '23 17:05 jafeelv

The compiler is telling you that you need to install the SD.h dependency - in your case, arduino-libraries/SD.h

https://registry.platformio.org/libraries/arduino-libraries/SD/installation

I don't know how you built and ran the reconstruction code without it being installed.

myndcryme avatar May 29 '23 23:05 myndcryme

@myndcryme I already installed it in platformio. I was able to run the reconstruction code. But after running PUF-encrypt, this happened.

jafeelv avatar May 30 '23 09:05 jafeelv

@myndcryme delay added. but, no changes for zeroes. image

jafeelv avatar May 30 '23 09:05 jafeelv

@myndcryme Update: when I tried running PUF-encrypt, it worked. But PUF-decrypt is not showing any output image

jafeelv avatar May 30 '23 10:05 jafeelv

Did you add the fixes to puf-decrypt? Reconstruction, puf-encrypt, puf-decrypt share much code, thus, behave similarly and all need to be patched.

Also your serial connection is dropping information (bad connection, too fast or some param are incorrect?).

myndcryme avatar May 30 '23 14:05 myndcryme

@myndcryme it's working.. What to do with dropping information in serial connection?

jafeelv avatar May 31 '23 03:05 jafeelv

Glad you got it working. Since it is working, I probably wouldn't worry too much about the terminal emulator dropping a few characters.

myndcryme avatar May 31 '23 16:05 myndcryme

@jafeelv I merged PR#10 that corrects a buffer overrun condition that causes undefined behavior and crashes when calling the function readHelperDatafromMicroSD(). Testing on my system after correcting the buffer overrun I have no need to inline any functions and the SD.h dependency was not to blame. Also, I would not use the delay I proposed adding in the comments above (bad advice).

myndcryme avatar Jun 13 '23 14:06 myndcryme