Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User/dev/kupadhyayula/ntt masking #39

Merged
merged 29 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c5b54c6
Masking files - wip
upadhyayulakiran Nov 6, 2024
a9f51bd
Add redux46 file
upadhyayulakiran Nov 6, 2024
f1b35fc
Masked adder, sub, gs, placeholder for mult reduction
upadhyayulakiran Nov 11, 2024
bae564f
completed redux46 masking module
ekarabu Nov 11, 2024
778b114
removed files from merged branch
Nov 11, 2024
b1a7dab
added a filed missing in compile order
Nov 11, 2024
009dfed
added license header
Nov 11, 2024
06127fc
MICROSOFT AUTOMATED PIPELINE: Stamp 'user/dev/ekarabulut/reduction46_…
ekarabu Nov 11, 2024
8481544
Merge branch 'main' into user/dev/kupadhyayula/ntt_masking
upadhyayulakiran Nov 11, 2024
fc2078f
Merge branch 'user/dev/ekarabulut/reduction46_0' into user/dev/kupadh…
upadhyayulakiran Nov 11, 2024
9898733
Masking WIP
upadhyayulakiran Nov 14, 2024
ac7f883
Merge branch 'main' into user/dev/kupadhyayula/ntt_masking
upadhyayulakiran Nov 14, 2024
efb2f5e
Integrate into mldsa_top, some temp changes to debug long sim times
upadhyayulakiran Nov 15, 2024
7df740e
optimized flip flops for masking logic
Nitsirks Nov 15, 2024
b8b5420
converted array decl format
ekarabu Nov 15, 2024
e7128c6
updated array format of B-sub
ekarabu Nov 15, 2024
f1b5102
Fix hybrid interface, update ctrl to incr twiddle
upadhyayulakiran Nov 16, 2024
cbddbf5
Lint fixes, rand bits
upadhyayulakiran Nov 19, 2024
c0e67f3
Mask rand bits when NTT is not in use
upadhyayulakiran Nov 19, 2024
a37271f
Gate the randomness further to be used in only PWM and INTT masked ops
upadhyayulakiran Nov 19, 2024
f2418a5
stashing clean up
Nitsirks Nov 20, 2024
aaeb31a
adding mask/shuff enable to sequencer opcodes
Nitsirks Nov 20, 2024
451c261
Clean up some commented out code
upadhyayulakiran Nov 20, 2024
7b6fe48
Merge branch 'main' into user/dev/kupadhyayula/ntt_masking
upadhyayulakiran Nov 20, 2024
414ff77
Merge branch 'user/dev/michnorris/abr_seq_fix' into user/dev/kupadhya…
upadhyayulakiran Nov 20, 2024
6e820d3
MICROSOFT AUTOMATED PIPELINE: Stamp 'user/dev/kupadhyayula/ntt_maskin…
upadhyayulakiran Nov 20, 2024
a7571ea
Update filelist, clean up
upadhyayulakiran Nov 20, 2024
ec3d38c
Merge branch 'user/dev/kupadhyayula/ntt_masking' of ssh://github.com/…
upadhyayulakiran Nov 20, 2024
42248d4
MICROSOFT AUTOMATED PIPELINE: Stamp 'user/dev/kupadhyayula/ntt_maskin…
upadhyayulakiran Nov 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflow_metadata/pr_hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
214c0b1444725dc142a4361e20d2d37423221cc10eda63949e445a2a06f3f8f61abeb3d4d18dd6fc0a2618cd920e4a51
61ff2cd5f5fc580fa4d885c8026ab0a4e3bb62ffd6a16b562da228e85b6af89fc13267658403e2388a14cad520c74d34
2 changes: 1 addition & 1 deletion .github/workflow_metadata/pr_timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1731643612
1732130263
6 changes: 6 additions & 0 deletions src/abr_libs/config/abr_libs.vf
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ ${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_sample_buffer.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_ahb_defines_pkg.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_ahb_slv_sif.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_masked_AND.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_delay_masked_shares.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_masked_add_sub_mod_Boolean.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_masked_MUX.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_masked_N_bit_Boolean_sub.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_masked_full_adder.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_masked_A2B_conv.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_masked_N_bit_Boolean_adder.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_masked_B2A_conv.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_masked_N_bit_mult.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_masked_N_bit_mult_two_share.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_adder.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_add_sub_mod.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_masked_N_bit_Arith_adder.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_add_sub_mod.sv
19 changes: 18 additions & 1 deletion src/abr_libs/config/compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ targets:
- $COMPILE_ROOT/rtl/abr_ahb_defines_pkg.sv
- $COMPILE_ROOT/rtl/abr_ahb_slv_sif.sv
- $COMPILE_ROOT/rtl/abr_masked_AND.sv
- $COMPILE_ROOT/rtl/abr_delay_masked_shares.sv
- $COMPILE_ROOT/rtl/abr_masked_add_sub_mod_Boolean.sv
- $COMPILE_ROOT/rtl/abr_masked_MUX.sv
- $COMPILE_ROOT/rtl/abr_masked_N_bit_Boolean_sub.sv
- $COMPILE_ROOT/rtl/abr_masked_full_adder.sv
- $COMPILE_ROOT/rtl/abr_masked_A2B_conv.sv
- $COMPILE_ROOT/rtl/abr_masked_N_bit_Boolean_adder.sv
- $COMPILE_ROOT/rtl/abr_masked_B2A_conv.sv
- $COMPILE_ROOT/rtl/abr_masked_N_bit_mult.sv
- $COMPILE_ROOT/rtl/abr_masked_N_bit_mult_two_share.sv
- $COMPILE_ROOT/rtl/abr_adder.sv
- $COMPILE_ROOT/rtl/abr_add_sub_mod.sv
rtl:
Expand All @@ -45,11 +50,17 @@ targets:
- $COMPILE_ROOT/rtl/abr_ahb_defines_pkg.sv
- $COMPILE_ROOT/rtl/abr_ahb_slv_sif.sv
- $COMPILE_ROOT/rtl/abr_masked_AND.sv
- $COMPILE_ROOT/rtl/abr_delay_masked_shares.sv
- $COMPILE_ROOT/rtl/abr_masked_add_sub_mod_Boolean.sv
- $COMPILE_ROOT/rtl/abr_masked_MUX.sv
- $COMPILE_ROOT/rtl/abr_masked_N_bit_Boolean_sub.sv
- $COMPILE_ROOT/rtl/abr_masked_full_adder.sv
- $COMPILE_ROOT/rtl/abr_masked_A2B_conv.sv
- $COMPILE_ROOT/rtl/abr_masked_N_bit_Boolean_adder.sv
- $COMPILE_ROOT/rtl/abr_masked_N_bit_Arith_adder.sv
- $COMPILE_ROOT/rtl/abr_masked_B2A_conv.sv
- $COMPILE_ROOT/rtl/abr_masked_N_bit_mult.sv
- $COMPILE_ROOT/rtl/abr_masked_N_bit_mult_two_share.sv
- $COMPILE_ROOT/rtl/abr_adder.sv
- $COMPILE_ROOT/rtl/abr_add_sub_mod.sv
---
Expand All @@ -60,20 +71,26 @@ targets:
directories: [$COMPILE_ROOT/rtl]
files:
- $COMPILE_ROOT/rtl/abr_masked_AND.sv
- $COMPILE_ROOT/rtl/abr_delay_masked_shares.sv
- $COMPILE_ROOT/rtl/abr_masked_add_sub_mod_Boolean.sv
- $COMPILE_ROOT/rtl/abr_masked_MUX.sv
- $COMPILE_ROOT/rtl/abr_masked_N_bit_Boolean_sub.sv
- $COMPILE_ROOT/rtl/abr_masked_full_adder.sv
- $COMPILE_ROOT/rtl/abr_masked_A2B_conv.sv
- $COMPILE_ROOT/rtl/abr_masked_N_bit_Boolean_adder.sv
- $COMPILE_ROOT/rtl/abr_masked_B2A_conv.sv
- $COMPILE_ROOT/rtl/abr_masked_N_bit_mult.sv
- $COMPILE_ROOT/rtl/abr_masked_N_bit_mult_two_share.sv
tb:
directories: [$COMPILE_ROOT/tb]
files:
- $COMPILE_ROOT/tb/abr_masked_A2B_conv_tb.sv
- $COMPILE_ROOT/tb/abr_masked_N_bit_Boolean_adder_tb.sv
- $COMPILE_ROOT/tb/abr_masked_B2A_conv_tb.sv
- $COMPILE_ROOT/tb/abr_masked_N_bit_mult_tb.sv
- $COMPILE_ROOT/tb/abr_masked_N_bit_mult_two_share_tb.sv

tops: [abr_masked_N_bit_mult_tb]
tops: [abr_masked_N_bit_mult_two_share_tb]
---
provides: [mldsa_uvm_lib]
schema_version: 2.4.0
Expand Down
8 changes: 7 additions & 1 deletion src/abr_libs/config/masking_tb.vf
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ ${ADAMSBRIDGE_ROOT}/src/abr_libs/tb/abr_masked_A2B_conv_tb.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/tb/abr_masked_N_bit_Boolean_adder_tb.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/tb/abr_masked_B2A_conv_tb.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/tb/abr_masked_N_bit_mult_tb.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/tb/abr_masked_N_bit_mult_two_share_tb.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_masked_AND.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_delay_masked_shares.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_masked_add_sub_mod_Boolean.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_masked_MUX.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_masked_N_bit_Boolean_sub.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_masked_full_adder.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_masked_A2B_conv.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_masked_N_bit_Boolean_adder.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_masked_B2A_conv.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_masked_N_bit_mult.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_masked_N_bit_mult.sv
${ADAMSBRIDGE_ROOT}/src/abr_libs/rtl/abr_masked_N_bit_mult_two_share.sv
71 changes: 71 additions & 0 deletions src/abr_libs/rtl/abr_delay_masked_shares.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//======================================================================
//
// abr_delay_masked_shares
// Buffers the masked shares for the N cycle
//======================================================================

module abr_delay_masked_shares
#(
parameter WIDTH = 46, // Width of the input array
parameter N = 5 // Number of cycles to delay
)
(
input wire clk,
input wire rst_n,
input wire zeroize,
input wire [1:0] input_reg [WIDTH-1:0], // Input signal
output logic [1:0] delayed_reg [WIDTH-1:0] // Delayed output
);

// Create an array of shift registers to store the delayed values
logic [N-1:0][WIDTH-1:0][1:0] shift_reg ;

// Use an always_ff block to implement the shift register
always_ff @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
// Reset all shift register values to 0
for (int j = 0; j < N; j = j + 1) begin
shift_reg[j] <= '0;
end
end
else if (zeroize) begin
// Reset all shift register values to 0
for (int j = 0; j < N; j = j + 1) begin
shift_reg[j] <= '0;
end
end
else begin
// Shift the values through the registers
for (int j = 0; j < N-1; j = j + 1) begin
shift_reg[j+1] <= shift_reg[j];
end

// Load the input values into the first shift register stage
for (int i = 0; i < WIDTH; i = i + 1) begin
shift_reg[0][i] <= input_reg[i];
end
end
end

// Assign the output to the last stage of the shift register
always_comb begin
for (int i = 0; i < WIDTH; i = i + 1) begin
delayed_reg[i] = shift_reg[N-1][i];
end
end

endmodule: abr_delay_masked_shares
34 changes: 13 additions & 21 deletions src/abr_libs/rtl/abr_masked_A2B_conv.sv
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
);

// Internal signals
logic [1:0] carry [WIDTH:0]; // Carry signals for each stage
logic [1:0] sum [WIDTH-1:0]; // Sum signals for each stage
logic [1:0] x_reg [WIDTH-1:0][WIDTH-1:0]; // Pipeline registers for x
logic [1:0] y_reg [WIDTH-1:0][WIDTH-1:0]; // Pipeline registers for y
logic [1:0] sum_reg [WIDTH-1:0][WIDTH-1:0]; // Pipeline registers for sum
logic [WIDTH:0] [1:0] carry; // Carry signals for each stage
logic [WIDTH-1:0] [1:0] sum; // Sum signals for each stage
logic [WIDTH-1:0][WIDTH-1:0][1:0] x_reg; // Pipeline registers for x
logic [WIDTH-1:0][WIDTH-1:0][1:0] y_reg; // Pipeline registers for y
logic [WIDTH-1:0][WIDTH-1:0][1:0] sum_reg; // Pipeline registers for sum
logic [1:0] the_last_sum;

// Initialize the first carry input to 0
Expand All @@ -59,16 +59,12 @@
// Pipeline registers for x and y inputs
always_ff @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
for (int j = 0; j < WIDTH; j = j + 1) begin
x_reg[i][j] <= 2'b00;
y_reg[i][j] <= 2'b00;
end
x_reg[i] <= '0;
y_reg[i] <= '0;
end
else if (zeroize) begin
for (int j = 0; j < WIDTH; j = j + 1) begin
x_reg[i][j] <= 2'b00;
y_reg[i][j] <= 2'b00;
end
x_reg[i] <= '0;
y_reg[i] <= '0;
end
else begin
for (int j = 0; j < WIDTH; j = j + 1) begin
Expand All @@ -87,14 +83,10 @@
// Pipeline registers for sum output
always_ff @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
for (int j = 0; j < WIDTH; j = j + 1) begin
sum_reg[i][j] <= 2'b00;
end
sum_reg[i] <= '0;
end
else if (zeroize) begin
for (int j = 0; j < WIDTH; j = j + 1) begin
sum_reg[i][j] <= 2'b00;
end
sum_reg[i] <= '0;
end
else begin
for (int j = i; j < WIDTH; j = j + 1) begin
Expand All @@ -116,8 +108,8 @@
.clk(clk), // Connect clk to clk
.rst_n(rst_n), // Connect rst_n to rst_n
.zeroize(zeroize), // Connect zeroize to zeroize
.x(x_reg[i][i]), // Connect x to the last stage of the x pipeline
.y(y_reg[i][i]), // Connect y to the last stage of the y pipeline
.x(x_reg[i][i]), // Connect x to the last stage of the x pipeline
.y(y_reg[i][i]), // Connect y to the last stage of the y pipeline
.c_in(carry[i]), // Connect c_in to carry[i]
.rnd(rnd[i]), // Connect rnd to corresponding random bit
.s(sum[i]), // Connect sum to sum[i]
Expand Down
34 changes: 24 additions & 10 deletions src/abr_libs/rtl/abr_masked_B2A_conv.sv
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// outputs A and r.
//
//======================================================================

`define DEBUG_MASKING 1
module abr_masked_B2A_conv #(
parameter WIDTH = 8 // Default width is 8 bits
)(
Expand All @@ -48,6 +48,20 @@
logic unsigned [1:0] x_arith_next [WIDTH-1:0];
wire [WIDTH-1:0] Gamma;
assign Gamma = rnd;
`ifdef DEBUG_MASKING
logic [WIDTH-1:0] actual_input, actual_input0, actual_input1, exp_output, actual_output;
always_comb begin
for (int i = 0; i < WIDTH; i++) begin
actual_input[i] = x_boolean[i][0] ^ x_boolean[i][1];
end
exp_output = actual_input1;
end
always_ff @(posedge clk) begin
actual_input0 <= actual_input;
actual_input1 <= actual_input0;
actual_output <= A2 + x1;
end
`endif

// Register inputs
always_ff @ (posedge clk or negedge rst_n) begin
Expand Down Expand Up @@ -80,16 +94,16 @@
// Combinational logic
always_comb begin

T0 = x0 ^ Gamma_reg; // T = x' ⊕ Γ
T1 = T0 - Gamma_reg; // T = T - Γ
T2 = T1 ^ x0; // T = T ⊕ x'
Gamma_reg2 = Gamma_reg ^ x1; // Γ = Γ ⊕ r
A0 = x0 ^ Gamma_reg2; // A = x' ⊕ Γ
A1 = A0 - Gamma_reg2; // A = A - Γ
A2 = A1 ^ T2; // A = A ⊕ T
T0 = x0 ^ Gamma_reg; // T = x' ⊕ Γ
T1 = T0 - Gamma_reg; // T = T - Γ
T2 = T1 ^ x0; // T = T ⊕ x'
Gamma_reg2 = Gamma_reg ^ x1; // Γ = Γ ⊕ r
A0 = x0 ^ Gamma_reg2; // A = x' ⊕ Γ
A1 = A0 - Gamma_reg2; // A = A - Γ
A2 = A1 ^ T2; // A = A ⊕ T
for (int i = 0; i < WIDTH; i++) begin
x_arith_next[i][0] = A2[i]; // Assign A to the output
x_arith_next[i][1] = x1[i]; // Assign r to the output
x_arith_next[i][0] = A2[i]; // Assign A to the output
x_arith_next[i][1] = x1[i]; // Assign r to the output
end
end

Expand Down
Loading
Loading