Ascon-128、Ascon-128a、Ascon-HASH、Ascon-HASHa的区别
时间: 2023-06-10 17:07:05 浏览: 574
Ascon是一种轻量级的加密算法,主要应用于物联网设备和嵌入式系统中。Ascon算法包括四种变体:Ascon-128、Ascon-128a、Ascon-HASH和Ascon-HASHa,它们之间的区别如下:
1. Ascon-128和Ascon-128a:这两种变体都是用于加密和解密的。它们的区别在于Ascon-128a使用了更紧凑的S盒,从而提高了效率。Ascon-128a还引入了一个专门设计的初始化向量,以提高安全性。
2. Ascon-HASH和Ascon-HASHa:这两种变体都是用于哈希算法。它们的区别在于Ascon-HASHa引入了一个专门的密钥来增强安全性。Ascon-HASHa还使用了更紧凑的S盒,从而提高了效率。
总体来说,Ascon-128和Ascon-128a适用于加密和解密,而Ascon-HASH和Ascon-HASHa适用于哈希算法。Ascon-128a和Ascon-HASHa都引入了一些额外的安全性措施,因此它们比Ascon-128和Ascon-HASH更安全。但是这些安全性措施也会导致一些额外的计算负担,因此在使用时需要权衡效率和安全性。
相关问题
使用数字电路方式安全实现轻量级算法Ascon,支持Ascon-128、Ascon-128a、Ascon-HASH、Ascon-HASHa四种参数配置。
Ascon算法是一种轻量级的加密算法,它可以用于保护物联网设备和其他嵌入式系统中的数据。为了实现数字电路方式安全的Ascon算法,可以采用以下步骤:
1. 设计Ascon算法的电路结构,包括输入接口、输出接口、算法部分和控制逻辑部分。
2. 实现Ascon算法的各个模块,包括S盒、置换、轮函数等。
3. 根据Ascon算法的参数配置,选择合适的电路结构和模块实现方式。
4. 对Ascon算法进行电路级优化,包括逻辑优化、时序优化、功耗优化等。
5. 对Ascon算法进行安全性分析和测试,确保其符合安全标准。
6. 验证Ascon算法的正确性和性能,包括加密速度、功耗、面积等指标。
以上步骤可以保证数字电路方式安全实现轻量级算法Ascon的安全性和可靠性。同时,还需考虑Ascon算法在实际应用中的场景和需求,对其进行相应的优化和改进。
使用数字电路方式安全实现轻量级算法Ascon,支持Ascon-128a、Ascon-HASH、Ascon-HASHa四种参数配置。代码
以下是使用数字电路方式实现Ascon-128a、Ascon-HASH、Ascon-HASHa的代码:
```verilog
module ascon_128a(input clk, input reset, input [127:0] plaintext, input [127:0] key, output reg [127:0] ciphertext);
parameter rounds = 12;
reg [127:0] state [0:5];
reg [127:0] roundkey [0:rounds+1];
always @(posedge clk) begin
if (reset) begin
state <= '{128'h00};
roundkey <= '{128'h00};
end else begin
state[0] <= plaintext ^ roundkey[0];
for (int i = 0; i < rounds; i = i + 1) begin
state <= ascon_permutation(state, roundkey[i+1]);
end
ciphertext <= state[0] ^ roundkey[rounds+1];
end
end
function [127:0] ascon_permutation(input [127:0] state, input [127:0] roundkey);
input [127:0] t;
t = state[0] ^ roundkey;
t = ascon_substitution(t);
t = ascon_shift_rows(t);
t = ascon_mix_columns(t);
t[0:127] = t[0:127] ^ roundkey;
return t;
endfunction
function [127:0] ascon_substitution(input [127:0] state);
input [127:0] t;
t = state;
for (int i = 0; i < 5; i = i + 1) begin
t[i*32+7:i*32] = ascon_sbox(t[i*32+7:i*32]);
end
return t;
endfunction
function [127:0] ascon_shift_rows(input [127:0] state);
input [127:0] t;
t = state;
for (int i = 0; i < 5; i = i + 1) begin
t[i*32+0:i*32+31] = ascon_rotate_left(t[i*32+0:i*32+31], i);
end
return t;
endfunction
function [127:0] ascon_mix_columns(input [127:0] state);
input [127:0] t;
t = state;
for (int i = 0; i < 5; i = i + 1) begin
t[i*32+0:i*32+31] = ascon_mix_column(t[i*32+0:i*32+31], t[((i+1)*32)%160+0:((i+1)*32)%160+31], t[((i+2)*32)%160+0:((i+2)*32)%160+31], t[((i+3)*32)%160+0:((i+3)*32)%160+31]);
end
return t;
endfunction
function [127:0] ascon_sbox(input [7:0] x);
input [7:0] t;
t[0] = x[0] ^ x[4] ^ x[5] ^ x[6] ^ x[7] ^ 0x9e;
t[1] = x[1] ^ x[5] ^ x[6] ^ x[7] ^ x[0] ^ 0x5b;
t[2] = x[2] ^ x[6] ^ x[7] ^ x[0] ^ x[1] ^ 0x5d;
t[3] = x[3] ^ x[7] ^ x[0] ^ x[1] ^ x[2] ^ 0x3e;
t[4] = x[4] ^ x[0] ^ x[1] ^ x[2] ^ x[3] ^ 0x76;
t[5] = x[5] ^ x[1] ^ x[2] ^ x[3] ^ x[4] ^ 0x1f;
t[6] = x[6] ^ x[2] ^ x[3] ^ x[4] ^ x[5] ^ 0x3b;
t[7] = x[7] ^ x[3] ^ x[4] ^ x[5] ^ x[6] ^ 0x4f;
return t;
endfunction
function [127:0] ascon_rotate_left(input [127:0] x, input [3:0] n);
input [127:0] t;
t[0:127] = {x[31:0], x[63:32], x[95:64], x[127:96]};
t[0:127] = {t[31-n:0], t[127-n:32]};
return t;
endfunction
function [127:0] ascon_mix_column(input [31:0] a, input [31:0] b, input [31:0] c, input [31:0] d);
input [31:0] t;
t[0:31] = a[0:7] ^ b[8:15] ^ c[16:23] ^ d[24:31];
t[32:63] = a[8:15] ^ b[16:23] ^ c[24:31] ^ d[0:7];
t[64:95] = a[16:23] ^ b[24:31] ^ c[0:7] ^ d[8:15];
t[96:127] = a[24:31] ^ b[0:7] ^ c[8:15] ^ d[16:23];
return t;
endfunction
always @(*) begin
roundkey[0] = key;
for (int i = 0; i < rounds; i = i + 1) begin
roundkey[i+1] = ascon_round_constant(i) ^ roundkey[i];
roundkey[i+1][0:7] = ascon_sbox(roundkey[i+1][0:7]);
end
roundkey[rounds+1] = ascon_round_constant(rounds) ^ roundkey[rounds];
end
function [127:0] ascon_round_constant(input [3:0] r);
input [127:0] t;
t[0:7] = 0x01;
t[8:15] = 0x82;
t[16:23] = r;
t[24:31] = 0x00;
t[32:39] = 0x40;
t[40:47] = 0x00;
t[48:55] = 0x00;
t[56:63] = 0x00;
t[64:71] = 0x00;
t[72:79] = 0x00;
t[80:87] = 0x00;
t[88:95] = 0x00;
t[96:103] = 0x00;
t[104:111] = 0x00;
t[112:119] = 0x00;
t[120:127] = 0x00;
return t;
endfunction
endmodule
module ascon_hash(input clk, input reset, input [127:0] message, output reg [127:0] hash);
parameter rounds = 12;
reg [127:0] state [0:5];
reg [127:0] roundconstant [0:rounds+1];
reg [127:0] block;
always @(posedge clk) begin
if (reset) begin
state <= '{128'h00};
roundconstant <= '{128'h00};
end else begin
state[0] <= state[0] ^ message;
for (int i = 0; i < rounds; i = i + 1) begin
state <= ascon_permutation(state, roundconstant[i+1]);
end
hash <= state[0];
end
end
always @(*) begin
roundconstant[0] = '{128'h00};
for (int i = 0; i < rounds; i = i + 1) begin
roundconstant[i+1] = ascon_round_constant(i) ^ roundconstant[i];
roundconstant[i+1][0:7] = ascon_sbox(roundconstant[i+1][0:7]);
end
roundconstant[rounds+1] = ascon_round_constant(rounds) ^ roundconstant[rounds];
end
function [127:0] ascon_permutation(input [127:0] state, input [127:0] roundconstant);
input [127:0] t;
t = state[0] ^ roundconstant;
t = ascon_substitution(t);
t = ascon_shift_rows(t);
t = ascon_mix_columns(t);
t[0:127] = t[0:127] ^ roundconstant;
return t;
endfunction
function [127:0] ascon_substitution(input [127:0] state);
input [127:0] t;
t = state;
for (int i = 0; i < 5; i = i + 1) begin
t[i*32+7:i*32] = ascon_sbox(t[i*32+7:i*32]);
end
return t;
endfunction
function [127:0] ascon_shift_rows(input [127:0] state);
input [127:0] t;
t = state;
for (int i = 0; i < 5; i = i + 1) begin
t[i*32+0:i*32+31] = ascon_rotate_left(t[i*32+0:i*32+31], i);
end
return t;
endfunction
function [127:0] ascon_mix_columns(input [127:0] state);
input [127:0] t;
t = state;
for (int i = 0; i < 5; i = i + 1) begin
t[i*32+0:i*32+31] = ascon_mix_column(t[i*32+0:i*32+31], t[((i+1)*32)%160+0:((i+1)*32)%160+31], t[((i+2)*32)%160+0:((i+2)*32)%160+31], t[((i+3)*32)%160+0:((i+3)*32)%160+31]);
end
return t;
endfunction
function [127:0] ascon_sbox(input [7:0] x);
input [7:0] t;
t[0] = x[0] ^ x[4] ^ x[5] ^ x[6] ^ x[7] ^ 0x9e;
t[1] = x[1] ^ x[5] ^ x[6] ^ x[7] ^ x[0] ^ 0x5b;
t[2] = x[2] ^ x[6] ^ x[7] ^ x[0] ^ x[1] ^ 0x5d;
t[3] = x[3] ^ x[7] ^ x[0] ^ x[1] ^ x[2] ^ 0x3e;
t[4] = x[4] ^ x[0] ^ x[1] ^ x[2] ^ x[3] ^ 0x76;
t[5] = x[5] ^ x[1] ^ x[2] ^ x[3] ^ x[4] ^ 0x1f;
t[6] = x[6] ^ x[2] ^ x[3] ^ x[4] ^ x[5] ^ 0x3b;
t[7] = x[7] ^ x[3] ^ x[4] ^ x[5] ^ x[6] ^ 0x4f;
return t;
endfunction
function [127:0] ascon_rotate_left(input [127:0] x, input [3:0] n);
input [127:0] t;
t[0:127] = {x[31:0], x[63:32], x[95:64], x[127:96]};
t[0:127] = {t[31-n:0], t[127-n:32]};
return t;
endfunction
function [127:0] ascon_mix_column(input [31:0] a, input [31:0] b, input [31:0] c, input [31:0] d);
input [31:0] t;
t[0:31] = a[0:7] ^ b[8:15] ^ c[16:23] ^ d[24:31];
t[32:63] = a[8:15] ^ b[16:23] ^ c[24:31] ^ d[0:7];
t[64:95] = a[16:23] ^ b[24:31] ^ c[0:7] ^ d[8:15];
t[96:127] = a[24:31] ^ b[0:7] ^ c[8:15] ^ d[16:23];
return t;
endfunction
function [127:0] ascon_round_constant(input [3:0] r);
input [127:0] t;
t[0:7] = 0x01;
t[8:15] = 0x82;
t[16:23] = r;
t[24:31] = 0x00;
t[32:39] = 0x40;
t[40:47] = 0x00;
t[48:55] = 0x00;
t[56:63] = 0x00;
t[64:71] = 0x00;
t[72:79] = 0x00;
t[80:87] = 0x00;
t[88:95] = 0x00;
t[96:103] = 0x00;
t[104:111] = 0x00;
t[112:119] = 0x00;
t[120:127] = 0x00;
return t;
endfunction
always @(posedge clk) begin
if (reset) begin
block <= '{128'h00};
end else begin
block <= block ^ message;
end
end
endmodule
module ascon_hasha(input clk, input reset, input [127:0] message, output reg [127:0] hash);
parameter rounds = 12;
reg [127:0] state [0:5];
reg [127:0] roundconstant [0:rounds+1];
reg [127:0] block;
reg [127:0] count;
always @(posedge clk) begin
if (reset) begin
state <= '{128'h00};
roundconstant <= '{128'h00};
end else begin
if (count == 0) begin
state[0] <= state[0] ^ block[0:127];
for (int i = 0; i < rounds; i = i + 1) begin
state <= ascon_permutation(state, roundconstant[i+1]);
end
end
count <= count + 1;
if (count == 4) begin
count <= 0;
block <= '{128'h00};
end
hash <= state[0];
end
end
always @(*) begin
roundconstant[0] = '{128'h00};
for (int i = 0; i < rounds; i = i + 1) begin
roundconstant[i+1] = ascon_round_constant(i) ^ roundconstant[i];
roundconstant[i+1][0:7] = ascon_sbox(roundconstant[i+1][0:7]);
end
roundconstant[rounds+1] = ascon_round_constant(rounds) ^ roundconstant[rounds];
end
function [127:0] ascon_permutation(input [127:0] state, input [127:0] roundconstant);
input [127:0] t;
t = state[0] ^ roundconstant;
t = ascon_substitution(t);
t = ascon_shift_rows(t);
t = ascon_mix_columns(t);
t[0:127] = t[0:127] ^ roundconstant;
return t;
endfunction
function [127:0] ascon_substitution(input [127:0] state);
input [127:0] t;
t = state;
for (int i = 0; i < 5; i = i + 1) begin
t[i*32+7:i*32] = ascon_sbox(t[i*32+7:i*32]);
end
return t;
endfunction
function [127:0] ascon_shift_rows(input [127:0] state);
input [127:0] t;
t = state;
for (int i = 0; i < 5; i = i + 1) begin
t[i*32+0:i*32+31] = ascon_rotate_left(t[i*32+0:i*32+31], i);
end
return t;
endfunction
function [127:0] ascon_mix_columns(input
阅读全文