Skip to content

Commit

Permalink
fixing PR issues
Browse files Browse the repository at this point in the history
excluding rev info files from license check
updated AES smoke test to include more test cases
updated AES c library to work for more test cases
added AES smoke test to L0 regression
  • Loading branch information
Nitsirks committed Dec 16, 2024
1 parent aef6195 commit ebe1fa6
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/license_header_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ exclude_dir='{uvmf*,.git,cmark,caliptra_reg_html,caliptra_top_reg_html,sha256,sh
exclude_suffix='*.{tcl,txt,js,htm,html,json,vf,yml,woff,rsp,rdl,bashrc,waiver,cfg,hex,rc,exe,pdf,png,hvp,svg,log}'
exclude_regs='*_reg*.{sv,rdl}'
exclude_csr='*_csr*.*'
exclude_file='{sglint_waivers,pr_hash,pr_timestamp,.git,.git-comodules,.gitignore,.gitmodules,spyglass_lint.policy,ascent.ctl,clp_mapfile,readme.md,README.md,SECURITY.md,c_sample.c,test_dilithium5,riscv_rev_info}'
exclude_file='{sglint_waivers,pr_hash,pr_timestamp,.git,.git-comodules,.gitignore,.gitmodules,spyglass_lint.policy,ascent.ctl,clp_mapfile,readme.md,README.md,SECURITY.md,c_sample.c,test_dilithium5,riscv_rev_info,tlul_rev_info,aes_rev_info}'
apache_patn='Licensed under the Apache License\|Apache License, Version 2\.0 (the \"License\")'

# Recursive find through repository with some major exclusions
Expand Down
1 change: 1 addition & 0 deletions src/integration/stimulus/L0_regression.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ contents:
- ../test_suites/smoke_test_ecc/smoke_test_ecc.yml
- ../test_suites/smoke_test_hmac/smoke_test_hmac.yml
- ../test_suites/smoke_test_mldsa/smoke_test_mldsa.yml
- ../test_suites/smoke_test_aes/smoke_test_aes.yml
- ../test_suites/smoke_test_kv/smoke_test_kv.yml
- ../test_suites/smoke_test_sram_ecc/smoke_test_sram_ecc.yml
- ../test_suites/smoke_test_ras/smoke_test_ras.yml
Expand Down
85 changes: 23 additions & 62 deletions src/integration/test_suites/libs/aes/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,54 +156,35 @@ void aes_flow(aes_op_e op, aes_mode_e mode, aes_key_len_e key_len, aes_flow_t ae
}

// Wait for IDLE
aes_wait_idle();
//aes_wait_idle();

if (aes_input.text_len > 0) {
// For Data Block I=0,...,N-1
for (int i = 0; i < num_blocks_text; i++) {

//Check if first block or a partial last block
if ((mode == AES_GCM) && ((i == 0) || ((i == num_blocks_text-1) && (partial_text_len > 0)))) {
//Set num bytes for the last block (could be first also)
num_bytes = ((i == num_blocks_text-1) && (partial_text_len > 0)) ? partial_text_len : 16;

if (mode == AES_GCM) {
//only a partial text
num_bytes = (num_blocks_text == 0) ? partial_text_len : 16;

// Wait for IDLE
aes_wait_idle();

//set CTRL_GCM to GCM_TEXT
lsu_write_32(CLP_AES_REG_CTRL_GCM_SHADOWED, (GCM_TEXT << AES_REG_CTRL_GCM_SHADOWED_PHASE_LOW) |
(num_bytes << AES_REG_CTRL_GCM_SHADOWED_NUM_VALID_BYTES_LOW));
lsu_write_32(CLP_AES_REG_CTRL_GCM_SHADOWED, (GCM_TEXT << AES_REG_CTRL_GCM_SHADOWED_PHASE_LOW) |
(num_bytes << AES_REG_CTRL_GCM_SHADOWED_NUM_VALID_BYTES_LOW));
}

// Write Input Data Block 0.
VPRINTF(LOW, "Write AES Input Data Block %d\n", 0);
for (int j = 0; j < 4; j++) {
lsu_write_32((CLP_AES_REG_DATA_IN_0 + j * 4), aes_input.plaintext[j]);
}

// Wait for INPUT_READY
while((lsu_read_32(CLP_AES_REG_STATUS) & AES_REG_STATUS_INPUT_READY_MASK) == 0);

//If first block was partial, or this block is partial set valid bytes
if ((mode == AES_GCM) && (num_blocks_text <= 1) && (partial_text_len > 0)) {
//If we only had one block, set to 0. Else use partial length
num_bytes = (num_blocks_text == 0) ? 0 : partial_text_len;

aes_wait_idle();
// Wait for IDLE
aes_wait_idle();

//set CTRL_GCM to GCM_TEXT
lsu_write_32(CLP_AES_REG_CTRL_GCM_SHADOWED, (GCM_TEXT << AES_REG_CTRL_GCM_SHADOWED_PHASE_LOW) |
(num_bytes << AES_REG_CTRL_GCM_SHADOWED_NUM_VALID_BYTES_LOW));
lsu_write_32(CLP_AES_REG_CTRL_GCM_SHADOWED, (GCM_TEXT << AES_REG_CTRL_GCM_SHADOWED_PHASE_LOW) |
(num_bytes << AES_REG_CTRL_GCM_SHADOWED_NUM_VALID_BYTES_LOW));
}
//set CTRL_GCM to GCM_TEXT
lsu_write_32(CLP_AES_REG_CTRL_GCM_SHADOWED, (GCM_TEXT << AES_REG_CTRL_GCM_SHADOWED_PHASE_LOW) |
(num_bytes << AES_REG_CTRL_GCM_SHADOWED_NUM_VALID_BYTES_LOW));
lsu_write_32(CLP_AES_REG_CTRL_GCM_SHADOWED, (GCM_TEXT << AES_REG_CTRL_GCM_SHADOWED_PHASE_LOW) |
(num_bytes << AES_REG_CTRL_GCM_SHADOWED_NUM_VALID_BYTES_LOW));
}

VPRINTF(LOW, "Write AES Input Data Block %d\n", 1);
for (int j = 0; j < 4; j++) {
lsu_write_32((CLP_AES_REG_DATA_IN_0 + j * 4), aes_input.plaintext[j + 4]);
}
// Wait for INPUT_READY
while((lsu_read_32(CLP_AES_REG_STATUS) & AES_REG_STATUS_INPUT_READY_MASK) == 0);

// For Data Block I=0,...,N-1
for (int i = 0; i < num_blocks_text; i++) {
// Write Input Data Block.
VPRINTF(LOW, "Write AES Input Data Block %d\n", i);
for (int j = 0; j < 4; j++) {
lsu_write_32((CLP_AES_REG_DATA_IN_0 + j * 4), aes_input.plaintext[j+i*4]);
}

// Wait for OUTPUT_VALID bit
while((lsu_read_32(CLP_AES_REG_STATUS) & AES_REG_STATUS_OUTPUT_VALID_MASK) == 0);
Expand All @@ -229,26 +210,6 @@ void aes_flow(aes_op_e op, aes_mode_e mode, aes_key_len_e key_len, aes_flow_t ae
while(1);
}
}

if ((num_blocks_text > 2) && (i < (num_blocks_text - 2))) {
//If last block is partial, write the valid bytes
if ((mode == AES_GCM) && (i == (num_blocks_text-3)) && (partial_text_len > 0)) {
num_bytes = partial_text_len;

aes_wait_idle();

lsu_write_32(CLP_AES_REG_CTRL_GCM_SHADOWED, (GCM_TEXT << AES_REG_CTRL_GCM_SHADOWED_PHASE_LOW) |
(num_bytes << AES_REG_CTRL_GCM_SHADOWED_NUM_VALID_BYTES_LOW));
lsu_write_32(CLP_AES_REG_CTRL_GCM_SHADOWED, (GCM_TEXT << AES_REG_CTRL_GCM_SHADOWED_PHASE_LOW) |
(num_bytes << AES_REG_CTRL_GCM_SHADOWED_NUM_VALID_BYTES_LOW));
}

// Write Input Data Block I.
VPRINTF(LOW, "Write AES Input Data Block %d\n", i+2);
for (int j = 0; j < 4; j++) {
lsu_write_32((CLP_AES_REG_DATA_IN_0 + j * 4), aes_input.plaintext[j + 4 * (i + 2)]);
}
}
}
}

Expand Down
164 changes: 145 additions & 19 deletions src/integration/test_suites/smoke_test_aes/smoke_test_aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,38 @@ volatile uint32_t intr_count = 0;
volatile caliptra_intr_received_s cptra_intr_rcv = {0};

/*
//CASE1
Cipher = AES-256-GCM
Key = 0000000000000000000000000000000000000000000000000000000000000000
IV = 000000000000000000000000
Plaintext =
Ciphertext =
AAD =
Tag = 530f8afbc74536b9a963b4f1c4cb738b
//CASE2
Cipher = AES-256-GCM
Key = 0000000000000000000000000000000000000000000000000000000000000000
IV = 000000000000000000000000
Plaintext = 00000000000000000000000000000000
Ciphertext = cea7403d4d606b6e074ec5d3baf39d18
AAD =
Tag = d0d1c8a799996bf0265b98b5d48ab919
//CASE3
Cipher = AES-256-GCM
Key = feffe9928665731c6d6a8f9467308308feffe9928665731c6d6a8f9467308308
IV = cafebabefacedbaddecaf888
Plaintext = d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b39
Ciphertext = 522dc1f099567d07f47f37a32a84427d643a8cdcbfe5c0c97598a2bd2555d1aa8cb08e48590dbb3da7b08b1056828838c5f61e6393ba7a0abcc9f662
AAD = feedfacedeadbeeffeedfacedeadbeefabaddad2
Tag = 76fc6ece0f4e1768cddf8853bb2d551b
//CASE4
Cipher = AES-128-GCM
Key = feffe9928665731c6d6a8f9467308308
IV = cafebabefacedbaddecaf888
Plaintext = d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b39
Ciphertext = 42831ec2217774244b7221b784d0d49ce3aa212f2c02a4e035c17e2329aca12e21d514b25466931c7d8f6a5aac84aa051ba30b396a0aac973d58e091
AAD = feedfacedeadbeeffeedfacedeadbeefabaddad2
Tag = 5bc94fbc3221a5db94fae95ae7121a47
*/

void main() {
Expand All @@ -47,41 +72,47 @@ void main() {
aes_mode_e mode = AES_GCM;
aes_key_len_e key_len;

const char key_str[] = "feffe9928665731c6d6a8f9467308308feffe9928665731c6d6a8f9467308308";
const char key_str1[] = "0000000000000000000000000000000000000000000000000000000000000000";
const char key_str2[] = "0000000000000000000000000000000000000000000000000000000000000000";
const char key_str3[] = "feffe9928665731c6d6a8f9467308308feffe9928665731c6d6a8f9467308308";
const char key_str4[] = "feffe9928665731c6d6a8f9467308308";
uint32_t key[8];
uint32_t key_size;
hex_to_uint32_array(key_str, key, &key_size);
key_len = key_size == 8 ? AES_256 :
key_size == 4 ? AES_128 : AES_192;

VPRINTF(LOW, "Key Size: 0x%x\n", key_size);

const char iv_str[] = "cafebabefacedbaddecaf888";
const char iv_str1[] = "000000000000000000000000";
const char iv_str2[] = "000000000000000000000000";
const char iv_str3[] = "cafebabefacedbaddecaf888";
const char iv_str4[] = "cafebabefacedbaddecaf888";
uint32_t iv[4];
uint32_t iv_length;
hex_to_uint32_array(iv_str, iv, &iv_length);

const char plaintext_str[] = "d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b39";
const char plaintext_str1[] = "";
const char plaintext_str2[] = "00000000000000000000000000000000";
const char plaintext_str3[] = "d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b39";
const char plaintext_str4[] = "d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b39";
uint32_t plaintext[32]; //arbitrary length here
uint32_t plaintext_length;
hex_to_uint32_array(plaintext_str, plaintext, &plaintext_length);

const char ciphertext_str[] = "522dc1f099567d07f47f37a32a84427d643a8cdcbfe5c0c97598a2bd2555d1aa8cb08e48590dbb3da7b08b1056828838c5f61e6393ba7a0abcc9f662";

const char ciphertext_str1[] = "";
const char ciphertext_str2[] = "cea7403d4d606b6e074ec5d3baf39d18";
const char ciphertext_str3[] = "522dc1f099567d07f47f37a32a84427d643a8cdcbfe5c0c97598a2bd2555d1aa8cb08e48590dbb3da7b08b1056828838c5f61e6393ba7a0abcc9f662";
const char ciphertext_str4[] = "42831ec2217774244b7221b784d0d49ce3aa212f2c02a4e035c17e2329aca12e21d514b25466931c7d8f6a5aac84aa051ba30b396a0aac973d58e091";
uint32_t ciphertext[32]; //arbitrary length here
uint32_t ciphertext_length;
hex_to_uint32_array(ciphertext_str, ciphertext, &ciphertext_length);

const char aad_str[] = "feedfacedeadbeeffeedfacedeadbeefabaddad2";
const char aad_str1[] = "";
const char aad_str2[] = "";
const char aad_str3[] = "feedfacedeadbeeffeedfacedeadbeefabaddad2";
const char aad_str4[] = "feedfacedeadbeeffeedfacedeadbeefabaddad2";
uint32_t aad[32]; //arbitrary length here
uint32_t aad_length;
if (aad_str != "") {
hex_to_uint32_array(aad_str, aad, &aad_length);
}

const char tag_str[] = "76fc6ece0f4e1768cddf8853bb2d551b";
const char tag_str1[] = "530f8afbc74536b9a963b4f1c4cb738b";
const char tag_str2[] = "d0d1c8a799996bf0265b98b5d48ab919";
const char tag_str3[] = "76fc6ece0f4e1768cddf8853bb2d551b";
const char tag_str4[] = "5bc94fbc3221a5db94fae95ae7121a47";
uint32_t tag[4];
uint32_t tag_length;
hex_to_uint32_array(tag_str, tag, &tag_length);

aes_key_t aes_key;

Expand All @@ -90,6 +121,101 @@ void main() {
VPRINTF(LOW, " AES-GCM smoke test !!\n" );
VPRINTF(LOW, "----------------------------------\n");

//CASE1
VPRINTF(LOW, "Test Case 1\n");
hex_to_uint32_array(key_str1, key, &key_size);
key_len = key_size == 8 ? AES_256 :
key_size == 4 ? AES_128 : AES_192;
hex_to_uint32_array(iv_str1, iv, &iv_length);
hex_to_uint32_array(plaintext_str1, plaintext, &plaintext_length);
hex_to_uint32_array(ciphertext_str1, ciphertext, &ciphertext_length);
hex_to_uint32_array(aad_str1, aad, &aad_length);
hex_to_uint32_array(tag_str1, tag, &tag_length);

aes_key.kv_intf = FALSE;
for (int i = 0; i < 8; i++) {
aes_key.key_share0[i] = key[i];
aes_key.key_share1[i] = 0x00000000;
}

aes_input.key = aes_key;
aes_input.text_len = plaintext_length*4; //convert length to bytes
aes_input.plaintext = plaintext;
aes_input.ciphertext = ciphertext;
aes_input.aad_len = aad_length*4; //convert length to bytes
aes_input.aad = aad;
aes_input.tag = tag;
aes_input.iv = iv;

aes_flow(op, mode, key_len, aes_input);

//CASE2
VPRINTF(LOW, "Test Case 2\n");
hex_to_uint32_array(key_str2, key, &key_size);
key_len = key_size == 8 ? AES_256 :
key_size == 4 ? AES_128 : AES_192;
hex_to_uint32_array(iv_str2, iv, &iv_length);
hex_to_uint32_array(plaintext_str2, plaintext, &plaintext_length);
hex_to_uint32_array(ciphertext_str2, ciphertext, &ciphertext_length);
hex_to_uint32_array(aad_str2, aad, &aad_length);
hex_to_uint32_array(tag_str2, tag, &tag_length);

aes_key.kv_intf = FALSE;
for (int i = 0; i < 8; i++) {
aes_key.key_share0[i] = key[i];
aes_key.key_share1[i] = 0x00000000;
}

aes_input.key = aes_key;
aes_input.text_len = plaintext_length*4; //convert length to bytes
aes_input.plaintext = plaintext;
aes_input.ciphertext = ciphertext;
aes_input.aad_len = aad_length*4; //convert length to bytes
aes_input.aad = aad;
aes_input.tag = tag;
aes_input.iv = iv;

aes_flow(op, mode, key_len, aes_input);

//CASE3
VPRINTF(LOW, "Test Case 3\n");
hex_to_uint32_array(key_str3, key, &key_size);
key_len = key_size == 8 ? AES_256 :
key_size == 4 ? AES_128 : AES_192;
hex_to_uint32_array(iv_str3, iv, &iv_length);
hex_to_uint32_array(plaintext_str3, plaintext, &plaintext_length);
hex_to_uint32_array(ciphertext_str3, ciphertext, &ciphertext_length);
hex_to_uint32_array(aad_str3, aad, &aad_length);
hex_to_uint32_array(tag_str3, tag, &tag_length);

aes_key.kv_intf = FALSE;
for (int i = 0; i < 8; i++) {
aes_key.key_share0[i] = key[i];
aes_key.key_share1[i] = 0x00000000;
}

aes_input.key = aes_key;
aes_input.text_len = plaintext_length*4; //convert length to bytes
aes_input.plaintext = plaintext;
aes_input.ciphertext = ciphertext;
aes_input.aad_len = aad_length*4; //convert length to bytes
aes_input.aad = aad;
aes_input.tag = tag;
aes_input.iv = iv;

aes_flow(op, mode, key_len, aes_input);

//CASE4
VPRINTF(LOW, "Test Case 4\n");
hex_to_uint32_array(key_str4, key, &key_size);
key_len = key_size == 8 ? AES_256 :
key_size == 4 ? AES_128 : AES_192;
hex_to_uint32_array(iv_str4, iv, &iv_length);
hex_to_uint32_array(plaintext_str4, plaintext, &plaintext_length);
hex_to_uint32_array(ciphertext_str4, ciphertext, &ciphertext_length);
hex_to_uint32_array(aad_str4, aad, &aad_length);
hex_to_uint32_array(tag_str4, tag, &tag_length);

aes_key.kv_intf = FALSE;
for (int i = 0; i < 8; i++) {
aes_key.key_share0[i] = key[i];
Expand Down

0 comments on commit ebe1fa6

Please sign in to comment.