Skip to content

Commit

Permalink
apps/examples/security_test: Add examples of GCM mode
Browse files Browse the repository at this point in the history
Add UTC and examples of GCM API
Keys should be generated before encryption/decryption.
Factory key is not available in GCM mode.

1) sl_crypto_test
- Example of sl_gcm_encrypt / sl_gcm_decrypt

2) utc_crypto
- UTC of crypto_gcm_encryption / crypto_gcm_decryption

Signed-off-by: Jaeyong Lee <jaeyong1.lee@samsung.com>
  • Loading branch information
jylee9613 committed Sep 23, 2024
1 parent c79ae2b commit a0eaa87
Show file tree
Hide file tree
Showing 4 changed files with 562 additions and 1 deletion.
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));
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

0 comments on commit a0eaa87

Please sign in to comment.