Datasheet

ENC424J600/624J600
DS39935C-page 128 2010 Microchip Technology Inc.
15.2.2 SHA-1 HASHING
The module implements the SHA-1 function as
described in the NIST Federal Information Processing
Standard (FIPS) Publication 180-1
. The resulting digest
is 160 bits (20 bytes) in length.
To calculate a SHA-1 digest:
1. Set SHA1MD5 (ECON2<12>). Clear HASHOP
and HASHLST (ECON1<13:12>).
2. Set HASHEN (ECON1<14>).
3. Clear HASHIF (EIR<13>).
4. Use the DMA to transfer exactly 64 bytes to
address 7A00h. This transfer may be split into
multiple transactions if each copy operation is
an integral length of 4 and the net of all transfers
is 64 bytes.
5. Wait for HASHIF to be set.
6. Repeat steps 3 through 5 until fewer than
64 bytes remain.
7. Clear HASHIF.
8. Set HASHLST (ECON1<12>).
9. Use the DMA to transfer the remaining bytes to
address 7A00h.
10. Wait for HASHIF to be set.
11. Use the DMA to transfer the resulting 20-byte
hash from address 7A70h. This 160-bit hash will
be in big-endian byte order.
12. Clear HASHEN.
Like the MD5 hashing case, steps 3, 5, 7 and 10 can be
optimized by replacing them with enforced wait
periods. However, SHA-1 is slightly slower than MD5
so a wait period of at least 4.7
s should be used in
place of step 5 and at least 5.8
s for step 10.
Also, like the MD5 case, step 9 can be split into multiple
DMA copy transactions if step 8 is held off until imme-
diately before the very last DMA copy operation is
performed.
15.2.3 CONTEXT SWITCHING
At each 64-byte boundary, the current output state can
be read from the module. This output state can be
stored in memory elsewhere, then loaded back into the
module at a later time to continue the hash. Using this
feature allows the engine to alternate between
calculating two or more digests simultaneously.
To make use of the context switching capability:
1. Initiate a hash calculation.
2. After hashing an integral number of 64-byte
blocks, wait for the HASHIF flag to be set.
3. Read the current context from the module and
store it elsewhere in memory. The context
includes the Digest/State Out and Length State
Out values, which comprise the 28 bytes starting
at address 7A70h.
4. Once the context has been saved, clear the
HASHEN (ECON1<14>) bit to disable the
module. The module is now available to be used
by other operations.
When the application is ready to resume the previous
calculation, restore the context to the Initialization
Vector/State In and Length State In values, beginning
at 7A40h. Then, set the HASHOP (ECON1<13>) bit to
indicate that a previous state is to be loaded from
memory rather than initializing a new calculation. Once
this bit is set, setting the HASHEN bit allows the hash
operation to proceed as usual.
After the context has been saved, the module may be
used for a different type of hash (MD5 instead of
SHA-1, or vice versa). When loading a context back
into the module, verify that SHA1MD5 (ECON2<12>)
selects the correct hash operation.