Skip to content

Commit e17450e

Browse files
nasahlpavogelpi
authored andcommitted
[aes,dv] Recalculate aad/ptx length when splitting message
When performing alert or FI tests, the try_recover() function in the base sequence splits up messages. E.g.: |AAD|AAD|PTX|PTX|TAG| could be split up into |AAD|PTX|PTX|TAG when there is an error injected at the first AAD block. This is problematic as now len(aad) || len(data), which is the data_in of the TAG block, does not match anymore. Hence, the tag comparison fails. This commit now recomputes len(aad) || len(data) at puts it into the correct AES_GCM_TAG item. Signed-off-by: Pascal Nasahl <[email protected]>
1 parent 68a06bd commit e17450e

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

hw/ip/aes/dv/env/seq_lib/aes_base_vseq.sv

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,54 @@ class aes_base_vseq extends cip_base_vseq #(
10301030
end
10311031

10321032
if (cfg_item.mode == AES_GCM && !status.alert_fatal_fault) begin
1033+
// As we are splitting the message, we also need to recalculate the length
1034+
// of the AAD and PTX -> len(aad) || len(data) that is stored in a AES_GCM_TAG
1035+
// block. Image we split the message after the first AAD block:
1036+
// |AAD|AAD|PTX|PTX|TAG|
1037+
// we will land up having:
1038+
// |AAD|PTX|PTX|TAG
1039+
// Hence, recalculate here the new len(aad) || len(data).
1040+
aes_seq_item aes_item_queue_clone[$];
1041+
aes_seq_item data_item_tmp;
1042+
bit [3:0][31:0] len_aad_data_conc;
1043+
bit [3:0][31:0] len_aad_data;
1044+
int aad_len = 0;
1045+
int ptx_len = 0;
1046+
// Get AAD or PTX length of the current data_item.
1047+
if (data_item.item_type == AES_DATA) begin
1048+
ptx_len = data_item.data_len == 0 ? 16 : data_item.data_len;
1049+
end else if (data_item.item_type == AES_GCM_AAD) begin
1050+
aad_len = data_item.data_len == 0 ? 16 : data_item.data_len;
1051+
end
1052+
// Fetch all remaining data items and accumulate the AAD/PTX length.
1053+
while (aes_item_queue.size() > 0) begin
1054+
int data_len;
1055+
data_item_tmp = aes_item_queue.pop_back();
1056+
aes_item_queue_clone.push_front(data_item_tmp);
1057+
data_len = data_item_tmp.data_len == 0 ? 16 : data_item_tmp.data_len;
1058+
if (data_item_tmp.item_type == AES_GCM_AAD) begin
1059+
aad_len += data_len;
1060+
end else if (data_item_tmp.item_type == AES_DATA) begin
1061+
ptx_len += data_len;
1062+
end
1063+
end
1064+
// Resemble len(aad) || len(data).
1065+
len_aad_data_conc = ((aad_len * 8 << 64) | ptx_len * 8);
1066+
len_aad_data = {<<8{len_aad_data_conc}};
1067+
// Put all items back to the aes_item_queue in the correct order.
1068+
while (aes_item_queue_clone.size() > 0) begin
1069+
data_item_tmp = aes_item_queue_clone.pop_back();
1070+
if (data_item_tmp.item_type == AES_GCM_TAG) begin
1071+
// Once we reached the AES_GCM_TAG block, put in the new
1072+
// len(aad) || len(data)
1073+
data_item_tmp.data_in = len_aad_data;
1074+
end
1075+
aes_item_queue.push_front(data_item_tmp);
1076+
end
1077+
aes_item_queue_clone.delete();
1078+
1079+
// After re-calculating len(aad) || len(data) start the AES-GCM operation
1080+
// by putting the block into the GCM_INIT phase.
10331081
set_gcm_phase(GCM_INIT, 16, 1);
10341082
end
10351083

0 commit comments

Comments
 (0)