wp_hcores_md5a.pdf

White Paper
MD5A Hash Function
Introduction
The Altera® MD5 hash function implements the RSAMD5 message-digest algorithm, and is optimized for Altera
FLEX® 10KE and APEX™ 20K devices.
The MD5 algorithm generates a 128-bit message-digest, or hash function, of an arbitrary length input, and is used for
digital signature applications.
The core supports the MD5 algorithm, except for the following exceptions:
„
„
The maximum number of bits in the input message is limited to 232
The resolution of the input message is in bytes, not bits
A test case generator is included with the core, which converts a text file into a simulation file for the core.
Ports and Parameters
The MD5 core is fixed function, and therefore has no parameters.
Table 1 shows the input signals.
Table 1 Input Signals
Signal Name
Description
SYSCLK
SYSCLK is the main system clock.
RESET
The core is asynchronously reset when the RESET signal is
asserted high.
DATIN[8..1]
Input bytes are written into the core using this bus, when the
DSIN input is set high and the core has asserted the RDYIN
output. A total of 64 bytes are written into the core during an
input cycle, except for the last block in the message, when the
number of remaining bytes may be less than 64.
DSIN
The DSIN input strobes the DATIN[] bus into the core.
LASTBYTE
The LASTBYTE signal is asserted high for one clock cycle with
the last byte in a message.
WP-MD5A-1.0
Date: June 2002
1
Altera Corporation
MD5A Hash Function
Table 2 shows the output signals.
Table 2 Output Signals
Signal Name
Description
RDYIN
RDYIN is asserted high by the core when it is ready to receive
data. No data is read in unless DSIN is high as well.
HA[32..1], HB[32..1], HC[32..1], HD[32..1]
This bus contains the output hash from the core. The MD5
specification describes the output as being the A, B, C, and D
words, starting with the least significant byte. The output is split
into these four busses, so that the user can more readily adapt
to the endian of their system.
Compiling the Core
The core is optimized for Altera FLEX 10KE and APEX 20K devices. It must be compiled into a device that
supports dual port RAM. For best results, the core should be compiled with Global Logic Synthesis set to fast, or
with a synthesis style that supports carry chains.
In a 10K50S-1, the core requires 1592 LEs and 8 EABs, with an fMAX of 42 MHz.
In a 20K60E-1, the core requires 1717 LEs and 8 ESBs, with an fMAX of 54 MHz.
The system performance of the core can be calculated as follows:
Performance (Mbits/s) = 128 bits × (fMAX / 277 clocks_per_hash).
At 54 MHz, this translates to:
Performance = 128 × (54/277) = 25 Mbits/s.
Testing the Core
Utilities
Two utilities are included with the MD5 core.
The first is the utility from the original C reference code written by Ron Rivest, the developer of the MD5 algorithm.
The source code is widely available on the web. A compiled version, MD5.EXE, is included with the core. This
program can be used as a reference, to generate the MD5 hash functions of predefined sequences, or files.
The second utility, HASHAA.EXE, generates test cases for the SHA-1 and MD5 hashing algorithm cores, and is a
reference for the SHA-1 hashing algorithm. MD5 test case generation is provided by this utility, rather than the MD5
reference code, so that the MD5 reference code is not modified. The SHA-1 reference code was developed from the
SHA-1 FIPs publication.
2
Altera Corporation
MD5A Hash Function
Example Test – Standard Sequence
The MD5 utility can perform a hash on a standard set of test sequences, or a file.
Running a standard set of tests:
MD5 –X
One of the series of tests is the MD5 hash of “abc”, which is “900150983cd24fb0d6963f7d28e17f72”.
Running the HASHAA.EXE utility with the option 1 creates the test case for this.
HASHAA 1
From the simulator window, in Inputs/Outputs option (File menu), select the vector file MD5AA.VEC, and start
the simulation.
The result of simulating the testcase is:
HA = “98500190”
HB = “B04FD23C”
HC = “7D3F96D6”
HD = “727FE128”
Upon inspection, this is the other endian of the reference code (based on 32 bit words).
Example Test – File
Create a file, TEST.TXT, containing (in capitals):
HELLO WORLD
Running a test on this file:
MD5 TEST.TXT
This creates an MD5 hash of “6053C2BDD024B95D9B8E66971FE0166F”.
Running the HASHAA.EXE utility, pointing to TEST.TXT, creates the test case for this.
HASHAA TEST.TXT
From the simulator window, in Inputs/Outputs option (File menu), select the vector file MD5AA.VEC, and start
the simulation.
3
Altera Corporation
MD5A Hash Function
The result of simulating the testcase is:
HA = “6053C2BD”
HB = “D034B95D”
HC = “9B8E6697”
HD = “1FE0166F”
Upon inspection, this is the other endian of the reference code (based on 32 bit words).
Appendix A - Top Level Wrapper
An unencrypted top level wrapper, TOP_LEVEL_MD5AA.TDF is provided, to make it easier to instantiate the
core. The source code of the wrapper is as follows:
FUNCTION md5aa (sysclk, reset, datin[8..1], dsin, lastbyte)
RETURNS (rdyin, ha[32..1], hb[32..1], hc[32..1], hd[32..1]);
subdesign top_level_md5aa
(
sysclk, reset : INPUT;
datin[8..1] : INPUT;
dsin, lastbyte : INPUT;
rdyin : OUTPUT;
ha[32..1], hb[32..1], hc[32..1], hd[32..1] : OUTPUT;
)
BEGIN
(rdyin, ha[32..1], hb[32..1], hc[32..1], hd[32..1]) = md5aa (sysclk, reset,
datin[8..1], dsin, lastbyte);
END;
101 Innovation Drive
San Jose, CA 95134
(408) 544-7000
http://www.altera.com
Copyright © 2002 Altera Corporation. All rights reserved. Altera, The Programmable Solutions Company, the stylized Altera logo, specific device
designations, and all other words and logos that are identified as trademarks and/or service marks are, unless noted otherwise, the trademarks and
service marks of Altera Corporation in the U.S. and other countries. All other product or service names are the property of their respective holders.
Altera products are protected under numerous U.S. and foreign patents and pending applications, mask work rights, and copyrights. Altera warrants
performance of its semiconductor products to current specifications in accordance with Altera's standard warranty, but reserves the right to make
changes to any products and services at any time without notice. Altera assumes no responsibility or liability arising out of the application or use of any
information, product, or service described herein except as expressly agreed to in writing by Altera Corporation. Altera customers are advised to obtain
the latest version of device specifications before relying on any published information and before placing orders for products or services.
4