0
\$\begingroup\$

I have an activation system with a unique password per activation operation. If the system goes down or is not working correctly and I need to reset it to a operational state I could design a hard reset key combination so that the system recovers. Nonetheless I would need the password to be different each time the system recovers (this was the original explanation, and is wrong) process an activation operation.(correct)

I would like to know if, during a hard reset operation, a microcontroller is capable of changing a variable, store it and use it after the hard reset operation.

The thing is that the new password should be also known by another device that is not connected to that microcontroller.

In a normal operation both devices are synced with their passwords so, maybe, if the microcontroller detects a hard reset, can the current activation password be saved in non-volatile memory before resetting and use it after reset?

\$\endgroup\$
  • 1
    \$\begingroup\$ This depends on the MCU, but most have non-volatile memory you can use and combined with a random-number generator you can create essentially random passwords. You should also be able to tell during a restart what the cause of the reset was, and read the nv-memory appropriately. \$\endgroup\$ – Ron Beyer Apr 1 at 15:26
  • \$\begingroup\$ @RonBeyer How would you tell what caused the restart? \$\endgroup\$ – DKNguyen Apr 1 at 15:33
  • \$\begingroup\$ Thanks for your answer. I forgot to mention that this new password should also be known by another device that is not connected to the microcontroller. I will add this to the question. \$\endgroup\$ – LazyTurtle Apr 1 at 15:34
  • 2
    \$\begingroup\$ @DKNguyen Depending on the MCU, it will set a register that you can tell if it was a watch-dog time out, a brown-out, or some other event. This usually only works if you don't lose power completely. For example in the PIC32MX, you do this by reading the RCON register. \$\endgroup\$ – Ron Beyer Apr 1 at 15:37
  • 1
    \$\begingroup\$ If you are using the MCU to do its own "reset", you can do anything you want before the reset event, then reset. If it is something external that cuts the power, this is more difficult. How many times you can do this again depends on the MCU and the flash type. Some flashes have 10,000 write-cycles, some have less. Some MCU's have memory that can be programmed per-bit, and some only per-page. Some have bit-level writes and page-level clears,etc. It would help a lot if you identified the MCU and reset procedure. \$\endgroup\$ – Ron Beyer Apr 1 at 15:50
0
\$\begingroup\$

if the microcontroller detects a hard reset, can the current activation password be saved in non-volatile memory before resetting and use it after reset?

Yes. The MCU won't detect the reset until after it has occurred, but provided the password was saved before the event causing the reset it will work.

However there is a chance that the saved password is corrupt (if there was a random power failure during saving or the MCU 'malfunctioned') so you should also write a checksum or CRC code to verify that the saved password is valid.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ If the password store in the non-volatile memory is done during normal operation, do I need to write a CRC or checksum for verification? Can the malfunctioning of the microcontroller corrupt a previously stored variable in non-volatile memory? \$\endgroup\$ – LazyTurtle Apr 2 at 7:21
  • \$\begingroup\$ It is always a good idea to checksum critical data. Power might glitch or cut out at any time, or the MCU might 'go wild' and start doing random stuff (which might include jumping into your EEPROM write routine). Saving data to EEPROM can take over 100ms, so it is quite vulnerable. If your device needs to be resistant to hacking then protecting it from power glitches is a must! blackhat.com/docs/eu-15/materials/… \$\endgroup\$ – Bruce Abbott Apr 2 at 21:42
  • \$\begingroup\$ Thank you for the detailed information \$\endgroup\$ – LazyTurtle Apr 7 at 14:25
0
\$\begingroup\$

I don't really understand that you are trying to achieve. Because on the 1st part you are telling that this "activation password" should be different each reset. And on the last part you are telling you need to save it.

Still this is heavily dependant on the MCU model. But on the most generic case if you ever need to save your password, you should save it in EEPROM/Non-volatile memory right away once it's set (recommended to store along with some sort of checksum/hash value to ensure consistency).

Next thing depends on what do you call a "hard reset". If this is an MCU hardware reset pin, you can read reset reason register on almost every MCU model and check if it was a "external reset" reason. Based on that you can recover or generate a new "activation password".

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Thank you for your answer. Yes, sorry, I was trying to explain that the password use in every activation operation must be different. If the password hasn´t been used, it could be stored in the nonvolatile memory once it has been generated so then there would not be a problem when resetting the system. The password would be stored before system fail or malfunction. \$\endgroup\$ – LazyTurtle Apr 2 at 7:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.