S5L8720/Hardware - SHA1

S5L8720 SHA-1 Hardware
Base Address: 0x38000000

Programming Guide
As there is no real documentation of the hardware (The Samsung S3C6400X seams to use a very similar SHA-1 generator, but not the same), this is based on what iBoot does and on a lot of trial-and-error.

How it works
Basically it is like a hardware version of a SHA-1 algorithm. The hardware processes data in 512Bit (64 Bytes) chunks (Just like a software algorithm).

It does NO pre-processing (appending a '1' Bit to the data, pad the data so that the length mod 512 is 448, and append the bit-length of the data as a 64-bit big-endian integer).

This has to be done in software.

Calculating the SHA-1 of a message

 * 1) Prepare the message as usual. See Wikipedia on SHA
 * 2) Switch on the clock for the SHA-1 generator
 * 3) Reset the generator. To do this set bit 0 of reset register and clear it afterwards (iBoot waits until the hash is ready before resetting it)
 * 4) Clear (Write 0) to the Configuration Register (Not sure if this is needed as it already reads 0 after resetting, but iBoot does it)
 * 5) Clear register 0x80 and 0x10 (Also not sure why, as they also read 0)
 * 6) Write 64 bytes of the message to the data input registers starting at the lowest
 * 7) If this were the the first 64 bytes clear bit 3 in the Configuration register, else set it
 * 8) Set bit 1 (Start Hash) of the Configuration register and wait until bit 0 (Hash Busy) is cleared
 * 9) If more data to hash go to point 6
 * 10) Read the calculated hash of the Output SHA-1 Hash registers
 * 11) Switch off the clock

Configuration Register
All other bits are unknown or not used

Reset Register
All other bits are unknown or not used

Hash Out / IV In
Read: Outputs the hash in little-endian Write: Set the initialization vectors

Data Input
Read: Read what was previously written there (like normal RAM) Write: The current 64 byte data chunk to calculate the hash of. (little-endian)