Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of GCM AES #6334

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/examples/security_test/seclink/sl_crypto_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ SL_CRYPTO_TEST_POOL("aes_ecb", SL_CRYPTO_TYPE_AES_ECB, sl_handle_crypto_aes_ecb)
SL_CRYPTO_TEST_POOL("aes_cbc", SL_CRYPTO_TYPE_AES_CBC, sl_handle_crypto_aes_cbc)
SL_CRYPTO_TEST_POOL("aes_cfb128", SL_CRYPTO_TYPE_AES_CFB128, sl_handle_crypto_aes_cfb128)
SL_CRYPTO_TEST_POOL("aes_ctr", SL_CRYPTO_TYPE_AES_CTR, sl_handle_crypto_aes_ctr)
SL_CRYPTO_TEST_POOL("gcm_aes", SL_CRYPTO_TYPE_GCM_AES, sl_handle_crypto_gcm_aes)
43 changes: 43 additions & 0 deletions apps/examples/security_test/seclink/sl_crypto_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,44 @@ START_TEST_F(aes_ctr)
}
END_TEST_F

START_TEST_F(gcm_aes)
{
hal_data aes_key = HAL_DATA_INITIALIZER;
hal_data enc = HAL_DATA_INITIALIZER;
hal_data dec = HAL_DATA_INITIALIZER;
HAL_INIT_GCM_PARAM(param);
unsigned char aad[16] = {0,};
unsigned char tag[16] = {0,};
aes_key.data = g_key_128;
aes_key.data_len = 16;
param.cipher = HAL_GCM_AES;
param.iv = (unsigned char *)g_iv;
param.iv_len = 16;
param.aad = aad;
param.aad_len = 16;
param.tag = tag;
param.tag_len = 16;

enc.data = g_plaintext;
enc.data_len = 64;
dec.data = g_ciphertext;
dec.data_len = 64;

ST_EXPECT_EQ(SECLINK_OK, sl_set_key(g_hnd, HAL_KEY_AES_128, ST_AES_ENC_KEY_IDX, &aes_key, NULL));
ST_EXPECT_EQ(SECLINK_OK, sl_gcm_encrypt(g_hnd, &dec, &param, ST_AES_ENC_KEY_IDX, &enc));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @ZhenBei-Sin
I tested with this tesetcode, but I got error while calling sl_gcm_encrypt.

[ RUN        ] gcm_aes repeat: 1
keymgr request cmd(2580) (0) key(32) isempty(1)
hal_result_e : 0
hal_result_e : 255

security level: 0
===========================================================
Assertion details
===========================================================
print_assert_detail: Assertion Failed CPU0 at file: src/seclink/seclink.c line 130 task: sl_test pid: 20
print_assert_detail: Assert location (PC) : 0x0e179d83
check_assert_location: Code asserted in normal thread!

The location if assert is below.
https://github.com/Samsung/TizenRT/blob/master/framework/src/seclink/seclink.c#L129

When sl_gcm_encrypt called, it returns 255, not the defined value in res_table.
Would you please kindly let me know what I set wrong?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jylee9613

In this PR was missing the secure bl32.bin. (This image contains the SE API which support AES GCM mode).
image

Verified SUCCESS gcm_aes.
image

Thank You.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OMG...Thank you for checking:)
I confirmed AES GCM runs properly in AIDual.
I'll also check with TP1x, and let you know the result.

Thank you

sl_test_print_buffer(enc.data, enc.data_len, "GCM-AES plaintext");
sl_test_print_buffer(dec.data, dec.data_len, "GCM-AES ciphertext");
sl_test_print_buffer((char *)g_iv, 16, "IV");
sl_test_print_buffer((char *)aad, 16, "AAD");
sl_test_print_buffer((char *)param.tag, 16, "TAG");

ST_EXPECT_EQ(SECLINK_OK, sl_gcm_decrypt(g_hnd, &dec, &param, ST_AES_ENC_KEY_IDX, &enc));
sl_test_print_buffer(enc.data, enc.data_len, "GCM-AES plaintext (decrypted text)");

ST_EXPECT_EQ(SECLINK_OK, sl_remove_key(g_hnd, HAL_KEY_AES_128, ST_AES_ENC_KEY_IDX));
}
END_TEST_F

void sl_handle_crypto_aes_ecb(sl_options *opt)
{
ST_SET_SMOKE1(sl_crypto, opt->count, 0, "aes test", aes_ecb);
Expand All @@ -229,6 +267,11 @@ void sl_handle_crypto_aes_ctr(sl_options *opt)
ST_SET_SMOKE1(sl_crypto, opt->count, 0, "aes test", aes_ctr);
}

void sl_handle_crypto_gcm_aes(sl_options *opt)
{
ST_SET_SMOKE1(sl_crypto, opt->count, 0, "gcm test", gcm_aes);
}

void sl_handle_crypto(sl_options *opt)
{
ST_TC_SET_GLOBAL(sl_crypto, sl_crypto_global);
Expand Down
Loading