From 3756b55af61e9e14b5f67b7e0eb5914b4cbc2753 Mon Sep 17 00:00:00 2001 From: dam1n19 <d.a.mapstone@soton.ac.uk> Date: Fri, 27 Jan 2023 11:54:51 +0000 Subject: [PATCH] ATO2-24: Added ID Validator IP --- .DS_Store | Bin 6148 -> 8196 bytes hdl/src/sha256_id_validator.sv | 182 +++++++++++++++++++++++++++++++++ 2 files changed, 182 insertions(+) create mode 100644 hdl/src/sha256_id_validator.sv diff --git a/.DS_Store b/.DS_Store index ed5a1627a0488f9e875d5407c85d5a08a9c4e8bb..53434f8e2b2503b1a35cc9227a6ff3c6ae8b9051 100644 GIT binary patch literal 8196 zcmZQzU|@7AO)+F(kYHe7;9!8z0^AH(0Z1N%F(jFwB8njM7#IW?a?%Zhlk;;6pyH#{ zXb6mkz-S1JhQMeDjE2DA3js!mlQ?kH`w-btax?@+LtsRP0H}OWfVAxy9H4Xqga%15 zFfuTJy8w&~3@oq!Vg&UAAZkEbL25u+K{QA!10#q9mIrHPV1#OA1b0Ii7#JA@z(z4L zfVDF)f^7zggS9g-f^BACV1#IAV1(Mt2<@RTLbNk5LbNk5f^7#IIZBL%z-S1dg#f7U z&cdL_kj{|FP=eBbe_FhO0hF<!a=G~~E=f80NuU9P%JWOkweCLRh$^3gSH2(vF*d-+ zya413b_P9$GKOM?WQKf(6oyn3+Zh=4FfcHnsX%tap19AQz6-!^z)*#732s%$?tzwB zEDUK3ISly><(@hD$xy$7iW87O_5Ona$k_~Vb*L`p4hM$^)C^>|`dH5vyS)wUR=D2W ze1t2p$)mb20Aw*ULk2?%Lk^nj)-y0LAiEB#Dyh7<0P2SwNd-BX#U%y?*BF_YSy<WF zIoLV4Ibwq|^2>uu5=%;pof3<pLA;Rs{G22hJ25FNGqpTkK*TveuOu-uFSQ7yBseoA zH7T(uCOk7QCBNJ$zceqU7_1j6!NJMF880AFU2S4uqN8AHU{b52P;F^sprc@7Y*t&# z$sww&Zygk$os*lF-v#m%1H4FQ;DzwvWH$o?1JpMtA<g(D8X<!m&d(p$$@oFi1XLe# zC}YZ^gfSCx7?%YX<>ln(rGslK1_oA!Tu2&a$U$)lgH|j9iY&5glvN5}KidS3btL`B zF2b$?#Z?Rjpy1$S2x4$$aAa^{@MUmi&|}DDNI^{njIwB{fP<l!A(J7Op_CzqA(5ek zAr(#iPeSU4N&3ME2juvRKXyYORGy)S6>=;d>C)Y|e=|51G0Z}aOML2(V>JFaxa`9) z3oXTg<ntLy8HyN^8B!T?G2#!DH;{8ZD3y%j(GVad1ehU;B|!auR|W=L<Npv<qvU7^ zjE2Cl3;{+KmtYqsXj2E94?%rxP=7iBDhcX?gSz94pnf?-A4mzPYY*;@GeRa6!KxV< hAU%0T21rkyk%0lEb>Id9kme{y>wj<*jS?d;1OU#Txtjn0 delta 150 zcmZp1XfcprU|?W$DortDU=UznVBlbY&@5aN6U8R#DT;D}<UwMdIr+&+Ir&K-1sfBW zGc$5d77^5*d{>Zt@;<>YJY~T}c{%xc=^*8s*9rSEZk{4q&A6DIgF}#+0SpAV85kH` g85mf&HYR>&p3E=f39^uZ31TV89Sob}dFC(!0CA5TCjbBd diff --git a/hdl/src/sha256_id_validator.sv b/hdl/src/sha256_id_validator.sv new file mode 100644 index 0000000..a40d1a5 --- /dev/null +++ b/hdl/src/sha256_id_validator.sv @@ -0,0 +1,182 @@ +//----------------------------------------------------------------------------- +// SoC Labs Basic SHA-256 ID Validator +// A joint work commissioned on behalf of SoC Labs, under Arm Academic Access license. +// +// Contributors +// +// David Mapstone (d.a.mapstone@soton.ac.uk) +// +// Copyright 2023, SoC Labs (www.soclabs.org) +//----------------------------------------------------------------------------- +module sha256_id_validator ( + input logic clk, + input logic nrst, + input logic en, + + // Synchronous, localised reset + input logic sync_rst, + + // ID Buffer IN + input logic [5:0] id_in_buf, + input logic id_in_buf_last, + input logic id_in_buf_valid, + output logic id_in_buf_ready, + + // Hash IN + input logic [255:0] hash_in, + input logic [5:0] hash_in_id, + input logic hash_in_last, + input logic hash_in_valid, + output logic hash_in_ready, + + // Hash Out + output logic [255:0] hash_out, + output logic hash_out_err, + output logic hash_out_last, + output logic hash_out_valid, + input logic hash_out_ready, + + // Status Out - Gets updated after every hash + output logic [1:0] status_err, + output logic [9:0] status_packet_count, + input logic status_clear + +); + + logic [1:0] state, next_state; + + logic [255:0] next_hash_out; + logic next_hash_out_err; + logic next_hash_out_last, next_hash_out_valid; + logic next_hash_in_ready, next_id_in_buf_ready; + + logic [255:0] hash_buf; + logic [255:0] next_hash_buf; + + logic [5:0] hash_buf_id, id_buf; + logic [5:0] next_hash_buf_id, next_id_buf; + + // Status + logic [1:0] next_status_err; + logic [9:0] next_status_packet_count; + // Status Error + // bit 1 high - ID Buffer Error - Buffer has skipped and ID + // bit 0 high - Hash ID Error - Packet has been dropped + + // State Machine Sequential Logic + always_ff @(posedge clk, negedge nrst) begin + if ((!nrst) | sync_rst) begin + state <= 1'd0; + hash_out <= 256'd0; + hash_out_err <= 1'b0; + hash_out_last <= 1'b0; + hash_out_valid <= 1'b0; + hash_in_ready <= 1'b0; + id_in_buf_ready <= 1'b0; + hash_buf <= 256'd0; + hash_buf_id <= 6'd0; + id_buf <= 6'd0; + end else if (en == 1'b1) begin + state <= next_state; + hash_out <= next_hash_out; + hash_out_err <= next_hash_out_err; + hash_out_last <= next_hash_out_last; + hash_out_valid <= next_hash_out_valid; + hash_in_ready <= next_hash_in_ready; + id_in_buf_ready <= next_id_in_buf_ready; + hash_buf <= next_hash_buf; + hash_buf_id <= next_hash_buf_id; + id_buf <= id_buf; + end else begin + hash_out_valid <= 1'b0; + hash_in_ready <= 1'b0; + id_in_buf_ready <= 1'b0; + end + end + + always_comb begin + // Default + next_state = state; + next_hash_out = hash_out; + next_hash_out_err = hash_out_err; + next_hash_out_last = hash_out_last; + next_hash_out_valid = hash_out_valid; + next_hash_in_ready = hash_in_ready; + next_id_in_buf_ready = id_in_buf_ready; + next_hash_buf = hash_buf; + next_hash_buf_id = hash_buf_id; + next_id_buf = id_buf; + + // Override + case (state) + 2'd0: begin + next_hash_in_ready = 1'b1; + next_id_in_buf_ready = 1'b1; + next_state = 2'd1; + end + + 2'd1: begin // Set Packet ID from Seed or Increment Value + if (status_clear) begin + next_status_out_err = 2'b0; + end + if (hash_out_valid && !hash_out_ready) begin + // If data out handshake has not been seen, drop ready + next_hash_in_ready = 1'b0; + next_id_in_buf_ready = 1'b0; + end else begin + // Check Hash Input Handshaked + if (hash_in_ready && hash_in_ready) begin + next_hash_in_ready = 1'b0; + next_hash_buf = hash_in; + next_hash_buf_id = hash_in_id; + // Wait for ID Buffer State + next_state = 2'd2; + end + // Check ID Buffer Input Handshaked + if (id_in_buf_ready && id_in_buf_valid) begin + next_id_in_buf_ready = 1'b0; + next_id_buf = id_buf; + // Wait for Hash Input State + next_state = 2'd3; + end + // Check if Both Input Handshaked + if (hash_in_ready && hash_in_ready) && (id_in_buf_ready && id_in_buf_valid) begin + // Do ID's match? + next_hash_out = hash_in; + next_hash_out_valid = 1'b0; + if (!cfg_out_valid && cfg_out_ready) begin + // In case where no valid data and ready is waiting for valid data + // - (will be asserted next cc), guaranteed handshake next cycle + next_id_in_buf_ready = 1'b1; + next_hash_in_ready = 1'b1; + end else begin + next_id_in_buf_ready = 1'b0; + next_hash_in_ready = 1'b0; + end + // ID's don't match + if ((id_in_buf > hash_in_id)||(~id_in_buf[5] & hash_in_id[5])) begin + // If ID Buffer ID > Hash ID - ID Buffer Error + // Pop an additional hash + next_state = 2'd3; + next_hash_out_err = 1'b1; + next_status_err[1] = 1'b1; + end else if ((id_in_buf < hash_in_id)||(id_in_buf[5] & ~hash_in_id[5])) begin + // If ID Buffer ID < Hash ID - Lost Packet Error + // Pop an additional value from the Buffer FIFO + next_state = 2'd2; + next_hash_out_err = 1'b1; + next_status_err[0] = 1'b1; + end else begin + next_hash_out_err = 1'b0; + next_state = 2'd1; + end + end + end + end + + default: begin + next_state = 2'd0; + end + endcase + end +endmodule \ No newline at end of file -- GitLab