module PRESENT(res,state,keys); input [63:0]state; input [79:0]keys; output [63:0]res; wire [63:0]res,res1,res2,res3,res4,res5,res6,res7,res8,res9,res10,res11,res12,res13,res14,res15, res16,res17,res18,res19,res20,res21,res22,res23,res24,res25,res26,res27,res28,res29,res30,res31; wire [79:0]keys1,keys2,keys3,keys4,keys5,keys6,keys7,keys8,keys9,keys10,keys11,keys12,keys13,keys14,keys15, keys16,keys17,keys18,keys19,keys20,keys21,keys22,keys23,keys24,keys25,keys26,keys27,keys28,keys29,keys30,keys31; Round U1(res1,state,keys,keys1,5'b00001); Round U2(res2,res1,keys1,keys2,5'b00010); Round U3(res3,res2,keys2,keys3,5'b00011); Round U4(res4,res3,keys3,keys4,5'b00100); Round U5(res5,res4,keys4,keys5,5'b00101); Round U6(res6,res5,keys5,keys6,5'b00110); Round U7(res7,res6,keys6,keys7,5'b00111); Round U8(res8,res7,keys7,keys8,5'b01000); Round U9(res9,res8,keys8,keys9,5'b01001); Round U10(res10,res9,keys9,keys10,5'b01010);请仿照这一小部分代码,实现完整的PRESENT模块,采用随即掩码对中间值密钥进行掩蔽,以提高其安全性。其中随即掩码对输入数据进行掩蔽,然后进行PRESENT加密算法的一轮运算,然后移除随即掩码,每一轮都如此
时间: 2023-06-19 16:10:24 浏览: 120
PRESENT 密码算法代码
5星 · 资源好评率100%
以下是PRESENT模块的完整代码,其中添加了随机掩码以提高安全性:
```
module PRESENT(res, state, key, mask);
input [63:0] state;
input [79:0] key;
input [63:0] mask;
output [63:0] res;
wire [63:0] res1, res2, res3, res4, res5, res6, res7, res8, res9, res10, res11, res12, res13, res14, res15, res16;
wire [79:0] key1, key2, key3, key4, key5, key6, key7, key8, key9, key10, key11, key12, key13, key14, key15, key16;
// Round keys generation
gen_keys(key, key1, key2, key3, key4, key5, key6, key7, key8, key9, key10, key11, key12, key13, key14, key15, key16);
// Random mask
wire [63:0] state_masked = state ^ mask;
// Round 1
Round U1(res1, state_masked, key, key1, 5'b00001);
// Remove mask
wire [63:0] state_unmasked1 = res1 ^ mask;
// Round 2
Round U2(res2, state_unmasked1, key1, key2, 5'b00010);
// Remove mask
wire [63:0] state_unmasked2 = res2 ^ mask;
// Round 3
Round U3(res3, state_unmasked2, key2, key3, 5'b00011);
// Remove mask
wire [63:0] state_unmasked3 = res3 ^ mask;
// Round 4
Round U4(res4, state_unmasked3, key3, key4, 5'b00100);
// Remove mask
wire [63:0] state_unmasked4 = res4 ^ mask;
// Round 5
Round U5(res5, state_unmasked4, key4, key5, 5'b00101);
// Remove mask
wire [63:0] state_unmasked5 = res5 ^ mask;
// Round 6
Round U6(res6, state_unmasked5, key5, key6, 5'b00110);
// Remove mask
wire [63:0] state_unmasked6 = res6 ^ mask;
// Round 7
Round U7(res7, state_unmasked6, key6, key7, 5'b00111);
// Remove mask
wire [63:0] state_unmasked7 = res7 ^ mask;
// Round 8
Round U8(res8, state_unmasked7, key7, key8, 5'b01000);
// Remove mask
wire [63:0] state_unmasked8 = res8 ^ mask;
// Round 9
Round U9(res9, state_unmasked8, key8, key9, 5'b01001);
// Remove mask
wire [63:0] state_unmasked9 = res9 ^ mask;
// Round 10
Round U10(res10, state_unmasked9, key9, key10, 5'b01010);
// Remove mask
wire [63:0] state_unmasked10 = res10 ^ mask;
// Round 11
Round U11(res11, state_unmasked10, key10, key11, 5'b01011);
// Remove mask
wire [63:0] state_unmasked11 = res11 ^ mask;
// Round 12
Round U12(res12, state_unmasked11, key11, key12, 5'b01100);
// Remove mask
wire [63:0] state_unmasked12 = res12 ^ mask;
// Round 13
Round U13(res13, state_unmasked12, key12, key13, 5'b01101);
// Remove mask
wire [63:0] state_unmasked13 = res13 ^ mask;
// Round 14
Round U14(res14, state_unmasked13, key13, key14, 5'b01110);
// Remove mask
wire [63:0] state_unmasked14 = res14 ^ mask;
// Round 15
Round U15(res15, state_unmasked14, key14, key15, 5'b01111);
// Remove mask
wire [63:0] state_unmasked15 = res15 ^ mask;
// Round 16
Round U16(res16, state_unmasked15, key15, key16, 5'b10000);
// Remove mask
res = res16 ^ mask;
endmodule
```
其中的 `mask` 参数为随机掩码,使用 `^` 运算符对输入数据进行掩蔽,然后进行PRESENT加密算法的一轮运算。在每一轮运算结束后,再次使用 `^` 运算符移除随机掩码。
阅读全文