Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconstruction of key is not working. #9

Open
jafeelv opened this issue May 6, 2023 · 23 comments · Fixed by #10
Open

Reconstruction of key is not working. #9

jafeelv opened this issue May 6, 2023 · 23 comments · Fixed by #10

Comments

@jafeelv
Copy link

jafeelv commented May 6, 2023

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

@myndcryme
Copy link
Collaborator

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

@jafeelv
Copy link
Author

jafeelv commented May 8, 2023

@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

@myndcryme
Copy link
Collaborator

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.

@jafeelv
Copy link
Author

jafeelv commented May 9, 2023

@myndcryme thank you

@myndcryme
Copy link
Collaborator

@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.

@jafeelv
Copy link
Author

jafeelv commented May 17, 2023

@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?

@myndcryme
Copy link
Collaborator

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

@jafeelv
Copy link
Author

jafeelv commented May 17, 2023

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

@myndcryme
Copy link
Collaborator

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

@jafeelv
Copy link
Author

jafeelv commented May 24, 2023

@myndcryme Sure. Thanks

@myndcryme
Copy link
Collaborator

myndcryme commented May 24, 2023

@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
Copy link
Collaborator

@jafeelv Did it work?

@jafeelv
Copy link
Author

jafeelv commented May 29, 2023

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

@myndcryme
Copy link
Collaborator

myndcryme commented May 29, 2023

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

@jafeelv
Copy link
Author

jafeelv commented May 29, 2023

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

@myndcryme
Copy link
Collaborator

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.

@jafeelv
Copy link
Author

jafeelv commented May 30, 2023

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

@jafeelv
Copy link
Author

jafeelv commented May 30, 2023

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

@jafeelv
Copy link
Author

jafeelv commented May 30, 2023

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

@myndcryme
Copy link
Collaborator

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?).

@jafeelv
Copy link
Author

jafeelv commented May 31, 2023

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

@myndcryme
Copy link
Collaborator

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
Copy link
Collaborator

@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 myndcryme linked a pull request Jun 13, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants