Download presentation
Presentation is loading. Please wait.
1
MD5 In MD5, St shift constants are defined as:
parameter byte S[0:63] = '{ 'd7, 8'd12, 8'd17, 8'd22, 8'd7, 8'd12, 8'd17, 8'd22, 8'd7, 8'd12, 8'd17, 8'd22, 8'd7, 8'd12, 8'd17, 8'd22, 'd5, 8'd9, 8'd14, 8'd20, 8'd5, 8'd9, 8'd14, 8'd20, 8'd5, 8'd9, 8'd14, 8'd20, 8'd5, 8'd9, 8'd14, 8'd20, 'd4, 8'd11, 8'd16, 8'd23, 8'd4, 8'd11, 8'd16, 8'd23, 8'd4, 8'd11, 8'd16, 8'd23, 8'd4, 8'd11, 8'd16, 8'd23, 'd6, 8'd10, 8'd15, 8'd21, 8'd6, 8'd10, 8'd15, 8'd21, 8'd6, 8'd10, 8'd15, 8'd21, 8'd6, 8'd10, 8'd15, 8'd21 }; However, only 16 values are unique, which are repeated. Can alternatively use: parameter byte S[0:15] = '{ 'd7, 8'd12, 8'd17, 8'd22, 'd5, 8'd9, 8'd14, 8'd20, 'd4, 8'd11, 8'd16, 8'd23, 'd6, 8'd10, 8'd15, 8'd21 }; Then access the S constant array like this: function logic [31:0] get_S(input logic [5:0] t); logic [3:0] i; i = {t[5:4], t[1:0]}; get_S = S[i]; endfunction
2
MD5 Going further … parameter byte S[0:15] = '{ 'd7, 8'd12, 8'd17, 8'd22, 'd5, 8'd9, 8'd14, 8'd20, 'd4, 8'd11, 8'd16, 8'd23, 'd6, 8'd10, 8'd15, 8'd21 }; function logic [31:0] get_S(input logic [5:0] t); logic [3:0] i; i = {t[5:4], t[1:0]}; get_S = S[i]; endfunction function logic [31:0] md5_op(input logic[31:0] a, b, c, d, w, input logic[5:0] t); logic [31:0] t1, t2; t1 = a + md5_f(t) + md5_k(t) + w; t2 = b + ((t1 << get_S(t))|(t1 >> (32-get_S(t)))); md5_op = {d, t2, b, c); endfunction
3
MD5 Alternatively … function logic [31:0] rotate_S(input logic [31:0] x, input logic [5:0] t); logic [3:0] i; i = {t[5:4], t[1:0]}; case (i) : rotate_S = {x[24:0], x[31:25]}; // leftrotate S[t] = : rotate_S = {x[19:0], x[31:20]}; // leftrotate S[t] = default: rotate_S = {x[10:0], x[31:11]}; // leftrotate S[t] = endcase endfunction function logic [31:0] md5_op(input logic[31:0] a, b, c, d, w, input logic[5:0] t); logic [31:0] t1, t2; t1 = a + md5_f(t) + md5_k(t) + w; t2 = b + rotate_S(t1, t); md5_op = {d, t2, b, c); endfunction
4
SHA-256 In each hash round, “maj” and “ch” are defined as follows:
maj = (A and B) xor (A and C) xor (B and C) ch = (E and F) xor ((not E) and G) The xor can be replaced by or to simplify: maj = (A and B) or (A and C) or (B and C) ch = (E and F) or ((not E) and G) May not make a difference since logic synthesis should be able to simplify anyway.
5
Hints for Pipelining SHA-256
Each SHA-256 round, compute: S0 = (A rightrotate 2) xor (A rightrotate 13) xor (A rightrotate 22) maj = (A and B) xor (A and C) xor (B and C) t2 = S0 + maj S1 = (E rightrotate 6) xor (E rightrotate 11) xor (E rightrotate 25) ch = (E and F) xor ((not E) and G) t1 = H + S1 + ch + Kt + Wt (A, B, C, D, E, F, G, H) = (t1 + t2, A, B, C, D + t1, E, F, G)
6
Hints for Pipelining SHA-256
This means: A[2] = t1[1] + t2[1] = (H[1] + S1(E[1]) + ch(E[1], F[1], G[1]) + K[1] + W[1]) + (S0(A[1]) + maj(A[1], B[1], C[1]) B[2] = A[1] C[2] = B[1] D[2] = C[1] E[2] = D[1] + t1[1] = D[1] + (H[1] + S1(E[1]) + ch(E[1], F[1], G[1]) + K[1] + W[1]) F[2] = E[1] G[2] = F[1] H[2] = G[1]
7
Hints for Pipelining SHA-256
Can rewrite as follows B[2] = A[1] = t1[0] + t2[0] = (H[0] + S1(E[0]) + ch(E[0], F[0], G[0]) + K[0] + W[0]) + (S0(A[0]) + maj(A[0], B[0], C[0]) … F[2] = E[1] = D[0] + t1[0] = D[0] + (H[0] + S1(E[0]) + ch(E[0], F[0], G[0]) + K[0] + W[0]) Can pre-compute portion of these equations the cycle before.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.