feat: add four 90-ring entropy generators with spatial and temporal XOR (FPGA v3)
This commit is contained in:
parent
504b00752a
commit
585e755c66
9 changed files with 389 additions and 217 deletions
|
|
@ -1,17 +1,20 @@
|
|||
// Board-independent STRIX logic: ring bank, source selection, raw capture, frequency
|
||||
// counter and the SPI register interface to the SAMD21.
|
||||
// Board-independent STRIX logic: entropy generators, source selection, raw capture,
|
||||
// frequency counter and the SPI register interface to the SAMD21.
|
||||
//
|
||||
// SPI protocol (mode 0, one transaction per ss_n low period): the first byte is a command,
|
||||
// bit 7 = read (1) or write (0), bits 6:0 = register address. A write stores the following
|
||||
// byte(s) in that register. A read returns the register in every following byte; DATA
|
||||
// advances through the capture buffer with each byte, continuing across transactions.
|
||||
//
|
||||
// Capture sources (6-bit codes): 0x00-0x0F enhanced output of ring i, 0x10-0x1F single
|
||||
// tap of ring i, 0x20-0x2F XOR of the enhanced outputs of rings 0..n-1 for n = 1..16.
|
||||
// All sources are taken after sampling.
|
||||
// Capture sources, for generator g = 0..3:
|
||||
// 0x00+g processed output (spatial XOR, then temporal XOR; capture with decimation = TEMPORAL)
|
||||
// 0x04+g spatial XOR of all rings, every clock
|
||||
// 0x08+g enhanced output of ring RING_SELECT
|
||||
// 0x0C+g single tap of ring RING_SELECT
|
||||
module strix_core #(
|
||||
parameter CAPTURE_ADDR_WIDTH = 15,
|
||||
parameter FREQ_GATE_BITS = 24
|
||||
parameter FREQ_GATE_BITS = 24,
|
||||
parameter RINGS_PER_GEN = 90
|
||||
) (
|
||||
input wire clk,
|
||||
input wire reset,
|
||||
|
|
@ -22,8 +25,8 @@ module strix_core #(
|
|||
output wire capture_done
|
||||
);
|
||||
|
||||
localparam [7:0] VERSION = 8'h02;
|
||||
localparam RINGS = 16;
|
||||
localparam [7:0] VERSION = 8'h03;
|
||||
localparam GENERATORS = 4;
|
||||
|
||||
localparam [6:0] REG_ID0 = 7'h00, // "STRX"
|
||||
REG_ID1 = 7'h01,
|
||||
|
|
@ -31,6 +34,8 @@ module strix_core #(
|
|||
REG_ID3 = 7'h03,
|
||||
REG_VERSION = 7'h04,
|
||||
REG_FREQ_GATE = 7'h05, // read-only: gate is 2^value clk cycles
|
||||
REG_GENERATORS = 7'h06, // read-only
|
||||
REG_RINGS = 7'h07, // read-only: rings per generator
|
||||
REG_SOURCE_A = 7'h08,
|
||||
REG_DECIM_HIGH = 7'h09,
|
||||
REG_DECIM_LOW = 7'h0A,
|
||||
|
|
@ -40,39 +45,44 @@ module strix_core #(
|
|||
// bit 2 frequency busy, bit 3 frequency valid
|
||||
REG_SOURCE_B = 7'h0D,
|
||||
REG_MODE = 7'h0E, // bit 0 pair capture (A and B per sample)
|
||||
REG_RING_COUNT = 7'h0F,
|
||||
REG_DATA = 7'h10,
|
||||
REG_FREQ_SELECT = 7'h11, // ring to measure
|
||||
REG_RING_SELECT = 7'h11, // ring for the characterization sources and frequency
|
||||
REG_FREQ_COUNT3 = 7'h12, // prescaled edge count, most significant byte first
|
||||
REG_FREQ_COUNT2 = 7'h13,
|
||||
REG_FREQ_COUNT1 = 7'h14,
|
||||
REG_FREQ_COUNT0 = 7'h15;
|
||||
REG_FREQ_COUNT0 = 7'h15,
|
||||
REG_GEN_ENABLE = 7'h16, // bit g enables generator g
|
||||
REG_TEMPORAL = 7'h17, // consecutive bits XORed per output bit, 1-8
|
||||
REG_FREQ_GEN = 7'h18; // generator for the frequency measurement
|
||||
|
||||
// Ring bank and source selection
|
||||
// Generators
|
||||
|
||||
wire [RINGS-1:0] enhanced, first_tap, raw_tap;
|
||||
reg [GENERATORS-1:0] gen_enable;
|
||||
reg [3:0] temporal;
|
||||
reg [7:0] ring_select;
|
||||
wire [GENERATORS-1:0] out_bit, spatial_bit, ring_enhanced, ring_tap, ring_raw_tap;
|
||||
|
||||
ring_bank #(.RINGS(RINGS)) bank (
|
||||
.clk(clk), .enable(1'b1),
|
||||
.enhanced(enhanced), .first_tap(first_tap), .raw_tap(raw_tap)
|
||||
);
|
||||
genvar g;
|
||||
generate
|
||||
for (g = 0; g < GENERATORS; g = g + 1) begin : gen
|
||||
entropy_generator #(.RINGS(RINGS_PER_GEN)) generator (
|
||||
.clk(clk), .enable(gen_enable[g]), .temporal(temporal), .ring_select(ring_select),
|
||||
.out_bit(out_bit[g]), .spatial_bit(spatial_bit[g]),
|
||||
.ring_enhanced(ring_enhanced[g]), .ring_tap(ring_tap[g]),
|
||||
.ring_raw_tap(ring_raw_tap[g])
|
||||
);
|
||||
end
|
||||
endgenerate
|
||||
|
||||
reg [RINGS-1:0] xor_prefix_comb, xor_prefix;
|
||||
integer j;
|
||||
always @(*) begin
|
||||
xor_prefix_comb[0] = enhanced[0];
|
||||
for (j = 1; j < RINGS; j = j + 1)
|
||||
xor_prefix_comb[j] = xor_prefix_comb[j-1] ^ enhanced[j];
|
||||
end
|
||||
// Source selection
|
||||
|
||||
reg [5:0] source_a, source_b;
|
||||
reg [3:0] source_a, source_b;
|
||||
reg bit_a, bit_b;
|
||||
wire [63:0] all_sources = {16'd0, xor_prefix, first_tap, enhanced};
|
||||
wire [15:0] all_sources = {ring_tap, ring_enhanced, spatial_bit, out_bit};
|
||||
|
||||
always @(posedge clk) begin
|
||||
xor_prefix <= xor_prefix_comb;
|
||||
bit_a <= all_sources[source_a];
|
||||
bit_b <= all_sources[source_b];
|
||||
bit_a <= all_sources[source_a];
|
||||
bit_b <= all_sources[source_b];
|
||||
end
|
||||
|
||||
// Capture
|
||||
|
|
@ -93,13 +103,13 @@ module strix_core #(
|
|||
|
||||
// Frequency counter
|
||||
|
||||
reg [3:0] freq_select;
|
||||
reg [1:0] freq_gen;
|
||||
reg freq_start;
|
||||
wire freq_busy, freq_valid;
|
||||
wire [31:0] freq_count;
|
||||
|
||||
freq_counter #(.GATE_BITS(FREQ_GATE_BITS)) counter (
|
||||
.clk(clk), .reset(reset), .signal(raw_tap[freq_select]), .start(freq_start),
|
||||
.clk(clk), .reset(reset), .signal(ring_raw_tap[freq_gen]), .start(freq_start),
|
||||
.busy(freq_busy), .valid(freq_valid), .count(freq_count)
|
||||
);
|
||||
|
||||
|
|
@ -134,19 +144,23 @@ module strix_core #(
|
|||
REG_ID3: tx_byte = "X";
|
||||
REG_VERSION: tx_byte = VERSION;
|
||||
REG_FREQ_GATE: tx_byte = FREQ_GATE_BITS;
|
||||
REG_SOURCE_A: tx_byte = {2'd0, source_a};
|
||||
REG_GENERATORS: tx_byte = GENERATORS;
|
||||
REG_RINGS: tx_byte = RINGS_PER_GEN;
|
||||
REG_SOURCE_A: tx_byte = {4'd0, source_a};
|
||||
REG_DECIM_HIGH: tx_byte = decimation[15:8];
|
||||
REG_DECIM_LOW: tx_byte = decimation[7:0];
|
||||
REG_STATUS: tx_byte = {4'd0, freq_valid, freq_busy, capture_done, capture_busy};
|
||||
REG_SOURCE_B: tx_byte = {2'd0, source_b};
|
||||
REG_SOURCE_B: tx_byte = {4'd0, source_b};
|
||||
REG_MODE: tx_byte = {7'd0, pair_mode};
|
||||
REG_RING_COUNT: tx_byte = RINGS;
|
||||
REG_DATA: tx_byte = capture_byte;
|
||||
REG_FREQ_SELECT: tx_byte = {4'd0, freq_select};
|
||||
REG_RING_SELECT: tx_byte = ring_select;
|
||||
REG_FREQ_COUNT3: tx_byte = freq_count[31:24];
|
||||
REG_FREQ_COUNT2: tx_byte = freq_count[23:16];
|
||||
REG_FREQ_COUNT1: tx_byte = freq_count[15:8];
|
||||
REG_FREQ_COUNT0: tx_byte = freq_count[7:0];
|
||||
REG_GEN_ENABLE: tx_byte = {4'd0, gen_enable};
|
||||
REG_TEMPORAL: tx_byte = {4'd0, temporal};
|
||||
REG_FREQ_GEN: tx_byte = {6'd0, freq_gen};
|
||||
default: tx_byte = 8'h00;
|
||||
endcase
|
||||
end
|
||||
|
|
@ -155,11 +169,14 @@ module strix_core #(
|
|||
capture_start <= 1'b0;
|
||||
freq_start <= 1'b0;
|
||||
if (reset) begin
|
||||
source_a <= 6'h00;
|
||||
source_b <= 6'h01;
|
||||
gen_enable <= {GENERATORS{1'b1}};
|
||||
temporal <= 4'd5;
|
||||
ring_select <= 8'd0;
|
||||
source_a <= 4'h0;
|
||||
source_b <= 4'h1;
|
||||
pair_mode <= 1'b0;
|
||||
decimation <= 16'd1;
|
||||
freq_select <= 4'd0;
|
||||
decimation <= 16'd5;
|
||||
freq_gen <= 2'd0;
|
||||
is_read <= 1'b0;
|
||||
reg_addr <= 7'd0;
|
||||
bytes_read <= {CAPTURE_ADDR_WIDTH{1'b0}};
|
||||
|
|
@ -178,12 +195,15 @@ module strix_core #(
|
|||
bytes_read <= bytes_read + 1'b1;
|
||||
end else if (!is_read) begin
|
||||
case (reg_addr)
|
||||
REG_SOURCE_A: source_a <= rx_byte[5:0];
|
||||
REG_SOURCE_B: source_b <= rx_byte[5:0];
|
||||
REG_SOURCE_A: source_a <= rx_byte[3:0];
|
||||
REG_SOURCE_B: source_b <= rx_byte[3:0];
|
||||
REG_MODE: pair_mode <= rx_byte[0];
|
||||
REG_DECIM_HIGH: decimation[15:8] <= rx_byte;
|
||||
REG_DECIM_LOW: decimation[7:0] <= rx_byte;
|
||||
REG_FREQ_SELECT: freq_select <= rx_byte[3:0];
|
||||
REG_RING_SELECT: if (rx_byte < RINGS_PER_GEN) ring_select <= rx_byte;
|
||||
REG_GEN_ENABLE: gen_enable <= rx_byte[GENERATORS-1:0];
|
||||
REG_TEMPORAL: if (rx_byte >= 8'd1 && rx_byte <= 8'd8) temporal <= rx_byte[3:0];
|
||||
REG_FREQ_GEN: freq_gen <= rx_byte[1:0];
|
||||
REG_CONTROL: begin
|
||||
if (rx_byte[0]) capture_start <= 1'b1;
|
||||
if (rx_byte[0] || rx_byte[1]) bytes_read <= {CAPTURE_ADDR_WIDTH{1'b0}};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue