Skip to content

yetalit/MD5-in-VHDL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

MD5 in VHDL

Implementation of MD5 hash algorithm in VHDL for inputs less than 448 bits with the ability to receive data from digital pins through a custom mechanism.

Data Transfer

Using 3 digital pins, input data can be sent to the FPGA board from an external circuit or a device like Arduino. For example:

const int readPin = 2;         // Pin for sending data
const int pushBitPin = 3;      // Pin for push_bit signal
const int readStartPin = 4;    // Pin for read_start signal

unsigned long delayTime = 200; // 200 microseconds (200000 ns)

byte testData[16]; // 128 bits total (16 bytes)

void setup() {
  // Set pin modes
  pinMode(readPin, OUTPUT);
  pinMode(pushBitPin, OUTPUT);
  pinMode(readStartPin, OUTPUT);
  // Example initialization of test data with 128 bits
  for (int i = 0; i < 16; i++) {
    testData[i] = B10101010;  // Just a sample pattern
  }
}

void loop() {
  for (int i = 127; i >= 0; i--) {
    int byteIndex = i / 8;     // Find the byte index (0-15)
    int bitIndex = i % 8;      // Find the bit index (0-7)
    // Extract the bit from the testData array
    bool bitToSend = (testData[byteIndex] >> (7 - bitIndex)) & 0x01;

    delayMicroseconds(delayTime);  // Wait for 200 microseconds
    // Send the bit to readPin
    digitalWrite(readPin, bitToSend);
    delayMicroseconds(delayTime);  // Wait for 200 microseconds

    // Set push_bit to high to indicate we're pushing the bit
    digitalWrite(pushBitPin, HIGH);
    // Set read_start high only on the last bit (MSB - bit 127)
    if (i == 127) {
      digitalWrite(readStartPin, HIGH);
    }

    // Reset pins to low after sending each bit
    delayMicroseconds(delayTime);  // Wait for 200 microseconds
    digitalWrite(pushBitPin, LOW);
    digitalWrite(readStartPin, LOW);
  }
}

Environment Assumptions

  • User presses a switch (hash_sw) to calculate the hash.
  • Clock speed: 50 MHz
  • Reset & mechanical switches are asserted LOW

Test Bench

You can run the test bench and simulate the circuit using NVC Simulator:

https://github.com/nickg/nvc/releases

Then inside src folder, Run the following commands:

nvc -a Button.vhd DataReceiver.vhd MD5.vhd tb_md5.vhd
nvc -e tb_md5
nvc -r tb_md5

The hash result will be printed on the console.

About

MD5 calculation on FPGA (VHDL)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages