Lecture 2B RTL Design Methodology Transition from...

32
Lecture 2B RTL Design Methodology Transition from Pseudocode & Interface to a Corresponding Block Diagram

Transcript of Lecture 2B RTL Design Methodology Transition from...

Page 1: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

Lecture 2B

RTL Design Methodology

Transition from Pseudocode & Interface

to a Corresponding Block Diagram

Page 2: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

Structure of a Typical Digital System

Datapath(Execution

Unit)

Controller(Control

Unit)

Data Inputs

Data Outputs

Control & Status Inputs

Control & Status Outputs

Control Signals

StatusSignals

2

Page 3: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

Hardware Design with RTL VHDL

Pseudocode

Datapath Controller

Blockdiagram

ASMchart

VHDL code VHDL code

Interface

3

Page 4: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

1. Text description2. Interface3. Pseudocode4. Block diagram of the Datapath5. Interface divided into the Datapath and Controller6. ASM chart of the Controller7. RTL VHDL code of the Datapath, Controller, and Top-

level Unit8. Testbench for the Datapath, Controller, and Top-Level

Unit9. Functional simulation and debugging10. Synthesis and post-synthesis simulation11. Implementation and timing simulation12. Experimental testing using FPGA board

Steps of the Design ProcessIntroduced in Class Today

4

Page 5: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

Class Exercise 2CIPHER

Page 6: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

RC6RC6 (Rivest Cipher 6) - symmetric key block cipher

Designers: Ron Rivest, Matt Robshaw, Ray Sidney,and Yiqun Lisa Yin

One of five finalists of the contest for the Advanced Encryption Standard (AES)1997-2000

Candidate algorithm in the following other contests:NESSIE – for European standards (2000-2003)CRYPTREC – for Japanese standards (2000-2003)

6

Page 7: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

Security Margin

Complexity

High

Adequate

Simple Complex

NIST Report: Security

Rijndael

MARSSerpentTwofish

RC6

7

Page 8: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

NIST Report: Software EfficiencyEncryption and Decryption Speed

32-bitprocessors

64-bitprocessors

DSPs

high

medium

low

RC6

RijndaelMars

Twofish

Serpent

RijndaelTwofish

MarsRC6

Serpent

RijndaelTwofish

MarsRC6

Serpent

8

Page 9: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

Efficiency in hardware: FPGA Virtex 1000: Speed

050100150200250300350400450500Throughput [Mbit/s]

Serpent I8

Rijndael Twofish RC6 MarsSerpent I1

431 444414

353

294

177 173

104

149

62

143112

88102

61

Worcester Polytechnic Institute

University of Southern CaliforniaGeorge Mason University

9

Page 10: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

PseudocodeSplit input I into four words, I3, I2, I1, I0, of the size of w bits each

A = I3; B = I2; C = I1; D=I0B = B + S[0]D = D + S[1]

for i = 1 to r do{

T = (B*(2B + 1)) <<< kU = (D*(2D + 1)) <<< kA = ((A ⊕ T) <<< U) + S[2i]C = ((C ⊕ U) <<< T) + S[2i + 1] (A, B, C, D) = (B, C, D, A)

}A = A + S[2r + 2]C = C + S[2r + 3]O = (A, B, C, D)

10

Page 11: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

Notationw: word size, e.g., w=32 (constant)k: log2(w) (constant)A, B, C, D, U, T: w-bit variablesI3, I2, I1, I0: Four w-bit words of the input Ir: number of rounds (constant)O: output of the size of 4w bitsS[j] : 2r+4 round keys stored in two RAMs.

Each key is a w-bit word. The first RAM stores values of S[j=2i], i.e., only round keys with even indices. The second memory stores values of S[j=2i+1], i.e., only round keys with odd indices.

11

Page 12: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

Operations

⊕ : XOR+ : addition modulo 2w

– : subtraction modulo 2w

* : multiplication modulo 2w

X <<< Y : rotation of X to the left by the number of positionsgiven in Y

X >>> Y : rotation of X to the right by the number of positions given in Y

(A, B, C, D) : Concatenation of A, B, C, and D.

12

Page 13: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

Modular Arithmetic

11 + 4 mod 12 = 313

Page 14: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

4w

clk

reset

I

write_I

Sj

DONE

O

CIPHER4w

Write_Sj

w

j m

Circuit Interface

14

Page 15: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

Interface Table

Note:m is a size of index j. It is a minimum integer, such that 2m -1 ³ 2r+3.

15

Page 16: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

Protocol (1)An external circuit first loads all round keys

S[0], S[1], S[2], …, S[2r+2], [2r+3]to the two internal memories of the CIPHER unit.

The first memory stores values of S[j=2i], i.e., only round keys with even indices. The second memory stores values of S[j=2i+1], i.e. only round keys with odd indices.

Loading round keys is performed using inputs: Sj, j, write_Sj, clk.

Then, the external circuits, loads an input block I to the CIPHER unit, using inputs: I, write_I, clk.

After the input block I is loaded to the CIPHER unit, the encryption starts automatically.

16

Page 17: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

Protocol (2)

When the encryption is completed, signal DONE becomes active, and the output O changes to the new value of the ciphertext.

The output O keeps the last value of the ciphertext at the output, until the next encryption is completed. Before the first encryption is completed, this output should be equal to zero.

17

Page 18: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

Assumptions

• 2r+4 clock cycles are used to load round keys to internal RAMs

• one round of the main for loop of the pseudocode executes in one clock cycle

• you can access only one position of each internal memory of round keys per clock cycle

As a result, the encryption of a single input block I should last r+2 clock cycles.

18

Page 19: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

CIPHER:Solutions

Page 20: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

Addition mod 2w XOR

20

Page 21: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

Multiplication mod 2w

21

Page 22: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

Variable Rotation X<<<Y

22

Page 23: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

Datapath – Initialization & Main Loop

23

Page 24: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

Datapath – PostProcessing & Loop Counter

24

Page 25: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

Memories of Round Keys – ContentsCase of m=3 and r=2

25

Page 26: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

Datapath – Memories of Round Keys

26

Page 27: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

Interface with the Division into the Datapath and Controller

27

Page 28: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

Timing Analysis – Key Setup & Encryption

TKeySetup[cycles] = 2r+4

TKeySetup[ns] = (2r+4)∙TCLK

TEncryption(NM)[cycles] = (r+2) ∙NM

TEncryption(NM)[ns] = (r+2) ∙NM∙TCLK

Notation: TCLK – clock period in nsNM – number of encrypted message blocks I

28

Page 29: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

Timing Analysis - Throughput

ThrEncryption(NM)[Gbit/s] =

Notation: TCLK – clock period in nsNM – number of encrypted message blocks Iw – word size

(r+2) ∙NM∙TCLK

4 ∙ w ∙NM =(r+2) ∙TCLK

4 ∙ w

r & w constants, determined by the security analysis of the cipherFor the security equivalent to AES-128, r=20 & w=32

TCLK dependent on w, returned by the FPGA toolsbased on the static timing analysis of the critical path 29

Page 30: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

Timing Analysis – Critical Path

TCLK-min = dR + dlogic-max + tsetup

Critical Path – a path from an output of a register to an input of a register with the maximum value of the delay(denoted as dlogic-max)

dR – delay of a registertsetup – setup time of a register

30

Page 31: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

Setup & Hold Time of a Register

Setup time - the amount of time the data at thesynchronous input must be stable beforethe next active edge of clock

Hold time - the amount of time the data at thesynchronous input must be stable afterthe last active edge of clock 31

Page 32: Lecture 2B RTL Design Methodology Transition from ...ece.gmu.edu/coursewebpages/ECE/ECE545/F17/viewgraphs/ECE545_lecture2B... · RTL Design Methodology Transition from Pseudocode

Datapath – Critical Path

Critical Path marked in red

dR

tsetup

dlogic-max

32