Coder Social home page Coder Social logo

sha1-cpp-verilog's Introduction

Sha1-cpp-Verilog

knu 2021 digital design & lab Project, Sha-1 Algorithm (without padding, only input 512 bits)

Introduce

디지털 설계 및 실험 과목 최종 프로젝트로, Sha1 알고리즘 을 Cpp 및 Verilog로 구현 하였습니다.
※Padding 기능은 제외하였습니다.

Source Code Description

1. C++ Source Code Description

(1) length가 128 (512bit) 인 문자열을 입력으로 받습니다.

(2) 문자열을 하나씩 Char로 parsing하여 16진수로 변환후에 배열 M에 넣습니다.

- M은 32bit형의 배열입니다.

1

(3) 입력 값으로 채울 수 있는 W[0] ~ W[15] 값을 채웁니다. 2

W는 배열마다 1개의 Word 로 되어있습니다. (32bit)
M에서 길이 8의 단위로 가져와 1Word를 만듭니다.
이때 각 숫자의 가중치가 다르기 때문에 shift를 해주어야 합니다.

/*
Ex>
1011_0011-> 0001 0000 0001 0001 _ 0000 0000 0001 0001 입니다.
M의 저장되어 있는 16진수 값들은 32bit로 저장되어 있기에, 가장 앞의 1이라고 하면
0000 0000 0000 0000 _ 0000 0000 0000 0001 형태를 지니고 있습니다.
Left Shift 28 수행하여 0001 0000 0000 0000 _ 0000 0000 0000 0000 로 만들어 줍니다.
*/

가중치에 맞게 Left Shift를 해주고 마지막으로 OR연산을 진행해주어 1개의 Word를 완성시킵니다.

3

(5) 초기 a, b, c, d, e 값을 초기화 해줍니다. 값은 배열 h에 저장해 두었습니다

4

(6) 총 80번의 연산을 진행하면서 최종 a, b, c, d, e 값을 도출합니다. 연산은 기본 SHA1알고리즘을 따르며 연산 20번마다 지정된 k값을 설정해줍니다.

5

(7) 최종적으로 계산된 a, b, c, d, e 값과 초기값을 더해줘서 최종 output을 만들어 냅니다.

6

  • 디버깅 코드까지 포함하여 출력한 결과

2. Verilog Source Code Description

변수 및 벡터 설명

  • Input
    • [511:0] SHA1IN : 512bit의 입력 값
    • CLK : 주기적으로 반복되는 clock (posedge)
    • START : Operation을 시작하는 신호 (1Cycle 유지)
    • nRST : Reset 신호 (negedge), 0이 들어오면 초기화 된다.

  • Output
    • [159:0] SHA1OUT : 160bit의 출력 값
    • DONE : Operation이 끝났음을 알리는 신호 (1Cycle 유지)

  • In sha1 module
    • [31:0] W [79:0] : 32bit의 워드를 저장할 수 있는 벡터 배열
    • [31:0] H [4:0] : 초기 A, B, C, D, E 에 들어가는 값 저장
    • State : START 신호가 들어왔었는지 저장용
    • [7:0] t : rotation shift용 reg
      (1) Input으로 512bit의 SHA1IN을 입력 받습니다

7

(2) 1Word (32bit) 씩 Parsing하여 W[0] ~ W[15]를 채워 넣습니다
8

(3) 이후 지정된 식으로 W[16] ~ W[79] 또한 계산합니다
9

(4) 초기 A, B, C, D, E 값을 설정해줍니다.
10

  • 초기값은 H벡터에 배열형태로 저장되어 있습니다.

11

(5) START 신호가 들어오면 posedge CLK 일때마다 Operation 1개를 실행합니다.
Operation을 수행할 때 마다 F값을 계산해주며 A, B, C, D, E 또한 갱신됩니다.
12

(6) 최종적으로 계산된 A ~ E 값과 초기 A ~ E 값을 각각 더하여서 SHA1OUT 값을 만들어 냅니다.
이때 최종 계산이 끝남과 동시에 DONE 신호를 띄웁니다.

13

Result 14

INPUT (512 bit)
7465737480000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000 0000020

OUTPUT (160 bit)
A94A8FE5 CCB19BA6 1C4C0873 D391E987 982FBBD3

sha1-cpp-verilog's People

Contributors

whipbaek avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.