Self Integrity Check for AT32UC3A3128s Firmware

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, 

I am working on AT32UC3A3128s and new to microcontroller programming. These is no bootloader currently. And we are burning HEX file in AVR Micro's memory. It is having 128 KB flash memory.

I wanted to make sure every time it boots, it will do a self integrity check.

1. How can i do that ?

2. I came with approach that in last partition of flash we can keep MD5 or SHA HASH of firmware. Let me know if this is good approach.

3. Before that First of all I have to calculate MD5or SHA HASH of firmware and burn it at this last partition of flash. But How can I write simple program to write 256bit SHA Value at last partition. Can someone help ?

4. After Step3 above, once AVR Micro boots, in existing firmware, it should check it''s own MD5 or SHA HASH and compare it with one stored in last partition. How can I write this program.>?

I am newbie absolute begineer in microcontroller programming, I worked on OS based Embedded Systems.

Thanks,
Amit 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Normally one would use CRC16 or 32 algorithm as it is easier and faster to compute. However, if the chip has hardware to calc the hash then it would be reasonable to use it. I'd suggest the 'usual' technique to to have an application that takes your binary file, calcs the required check then appends the value on the end of the file. Tools like IAR have this built in, with gcc you'll have to do a bit of googling. The technique should be similar for any architecture using gcc. As for running the check on startup, have the check function as the first called in main().

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hash has a lot of software overhead. CRC, either 16 or 32 would seem more reasonable. An important question, however, is what the purpose of this validation is? (Its not commonly done). Are you concerned that the flash contents may have somehow been damaged? Or, are you concerned that someone may have replaced the program with something else?

 

For example Wikipedia, in " MD5" says"

 

The MD5 algorithm is a widely used hash function producing a 128-bit hash value. Although MD5 was initially designed to be used as a cryptographic hash function, it has been found to suffer from extensive vulnerabilities. It can still be used as a checksum to verify data integrity, but only against unintentional corruption.

Jim

 

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Sat. Feb 3, 2018 - 07:46 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks.!

1. How do i find out if the chip has hardware to calculate Hash or not ? The documentation mentions Crypto. (S in the End - AT32UC3A3128s). They also mentioned some stuffs about AES. I understand it is encryption algorithm and not for HASH ...like MD5 or SHA256.

2. Can you tell me how to calculate CRC ?

3. I am using Atmel Studio ? Do you have any idea if that is built in Atmel Studio as well ?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Jim. Yes, we are concerned that the flash contents may have somehow been damaged. hence wanted to implement Self Integrity Check.

I agree. MD5 has vulnerabilities. SHA256 is better approach.

 

1. But How do i find if there is hardware support to calculate SHA256 Checksum. I am not understanding the meaning of "Crypto" functionality in documentation. They mentioned AT32UC3A3128s ... last s is for Crypto.(AES).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not built into AS. But it may be in Atmel Start. CRC is a widely known algorithm. You should be able to find C code readily. Be aware that you can use a variety of "seeds" for CRCn. The seed changes the result. 

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Definitive article on CRCs: http://www.repairfaq.org/filipg/...

 

ka7ehk wrote:
Be aware that you can use a variety of "seeds" (sic?) for CRCn.

I think polynomial is the word you're looking for here?

 

http://www.repairfaq.org/filipg/...

 

Note that the Initial & Final Values are also significant: http://www.repairfaq.org/filipg/...

 

This is why it is meaningless to talk about just "CRC16" or "CRC32" - because there's a whole lot more to defining a specific CRC than just the size of the result!

 

#CRCDefinition

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There is an onboard 32-bit CRC generator but it is not documented very well. http://www.avrfreaks.net/forum/using-msus-crc32-engine


For integrity-checking after a restart you might not need a very fast check so a few lines of C for a 16-bit CRC will do do the job. (a table-driven implementation is faster but uses more memory).
Unfortunately, (as awneil says), there are tens of polynomials out there, each with variations on bit-length, the initial value, what happens to the final value, and the bit-calculation direction.
So, pick one of the 'popular' variants. https://en.wikipedia.org/wiki/Cyclic_redundancy_check#Commonly_used_and_standardized_CRCs


The ASF has crc32_calculate(,,) which calls _crc32_recalculate_bytes_helper(,,) to do the actual work and which is indicative of most crc calculators.

Last Edited: Sat. Feb 3, 2018 - 11:38 PM