Unit tests for Advanced Encryption Standard crypto module.
Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.
#include <stdint.h>
#include <stdbool.h>
#include <board.h>
#include <sysclk.h>
#include <aes.h>
#include <string.h>
#include <sleepmgr.h>
#include <unit_test/suite.h>
#include <stdio_serial.h>
#include <conf_test.h>
#include <pmic.h>
Functions | |
int | main (void) |
Set up and run test suite. More... | |
AES interface test functions | |
static void | run_aes_set_and_get_key_test (const struct test_case *test) |
Test AES get and set key value functions. More... | |
static void | run_aes_state_interface_test (const struct test_case *test) |
Test AES state interface functions. More... | |
static void | run_aes_encryption_test (const struct test_case *test) |
Test AES encryption function. More... | |
static void | run_aes_decryption_test (const struct test_case *test) |
Test AES decryption function. More... | |
static void | int_callback_aes (void) |
Callback for AES interrupt. More... | |
static void | run_aes_encrypt_and_decrypt_test (const struct test_case *test) |
Run encryption, then decryption. More... | |
Variables | |
Variables and result data | |
t_key | encryption_key |
Key used for encryption and generation of last subkey. More... | |
t_data | encryption_data |
Data which will be encrypted. More... | |
t_data | pre_encrypted_data |
Data which has been pre-encrypted with above key for comparison. More... | |
t_data | dummy_data |
Dummy data used to fill AES state memory. More... | |
t_key | lastsubkey |
Last subkey used in decryption of above encrypted data, generated from above encryption key. More... | |
volatile bool | aes_is_finished = false |
Callback read finished variable. More... | |
t_data | output_data |
Output data for enc/dec-test. More... | |
Helper functions and macros | |
#define | set_buffer(buffer, value) memset(buffer, value, sizeof(buffer)) |
Set all bytes in buffer to value. More... | |
static bool | compare_data_block (t_data block_1, t_data block_2) |
Compare two data blocks. More... | |
static bool | aes_lastsubkey_generate (t_key key, t_key last_sub_key) |
Generate AES sub key. More... | |
Set all bytes in buffer to value.
Referenced by run_aes_decryption_test(), run_aes_encrypt_and_decrypt_test(), run_aes_encryption_test(), and run_aes_set_and_get_key_test().
Generate AES sub key.
Get AES sub key by encryption of dummy data.
key | Pointer to AES key input. |
last_sub_key | Pointer to AES sub key output. |
References aes_clear_error_flag(), aes_clear_interrupt_flag(), aes_configure(), AES_ENCRYPT, aes_get_key(), aes_is_busy(), aes_is_error(), AES_MANUAL, aes_set_key(), aes_software_reset(), aes_start(), aes_write_inputdata(), AES_XOR_OFF, and dummy_data.
Referenced by run_aes_decryption_test().
Compare two data blocks.
Compares two blocks of equal length to see if they are equal.
block_1 | Pointer to first block. |
block_2 | Pointer to second block. |
References AES_DATA_SIZE.
Referenced by run_aes_decryption_test(), run_aes_encrypt_and_decrypt_test(), run_aes_encryption_test(), and run_aes_set_and_get_key_test().
|
static |
Callback for AES interrupt.
References aes_is_finished, aes_read_outputdata(), and output_data.
Referenced by main().
int main | ( | void | ) |
Set up and run test suite.
References aes_set_callback(), usart_rs232_options::baudrate, board_init(), cpu_irq_enable, DEFINE_TEST_ARRAY, DEFINE_TEST_CASE, DEFINE_TEST_SUITE, int_callback_aes(), pmic_init(), run_aes_decryption_test(), run_aes_encrypt_and_decrypt_test(), run_aes_encryption_test(), run_aes_set_and_get_key_test(), run_aes_state_interface_test(), sleepmgr_init(), stdio_serial_init(), SYSCLK_AES, sysclk_enable_module(), sysclk_init(), SYSCLK_PORT_GEN, test_suite_run(), and usart_serial_options.
|
static |
Test AES decryption function.
This test decrypts the pre-encrypted data and checks whether it is correct.
test | Current test case. |
References aes_configure(), AES_DECRYPT, aes_is_busy(), aes_lastsubkey_generate(), AES_MANUAL, aes_read_outputdata(), aes_set_key(), aes_software_reset(), aes_start(), aes_write_inputdata(), AES_XOR_OFF, compare_data_block(), encryption_data, encryption_key, lastsubkey, pre_encrypted_data, set_buffer, success, and test_assert_true.
Referenced by main().
|
static |
Run encryption, then decryption.
Announce end by interrupt.
This test encrypts a data block, decrypts it, and checks if it's correct with respect to the input data block. Utilizes interrupts to let the software know when a encryption/decryption is done. AUTO mode will be used in this test.
test | Current test case. |
References AES_AUTO, aes_configure(), AES_DECRYPT, AES_ENCRYPT, AES_INTLVL_LO, aes_is_finished, aes_isr_configure(), aes_set_key(), aes_software_reset(), aes_write_inputdata(), AES_XOR_OFF, AES_XOR_ON, compare_data_block(), encryption_data, encryption_key, lastsubkey, output_data, set_buffer, success, and test_assert_true.
Referenced by main().
|
static |
Test AES encryption function.
This test generates an encrypted byte string from a key and input, and compares it to a pre-encrypted value.
test | Current test case. |
References aes_configure(), AES_ENCRYPT, aes_is_busy(), AES_MANUAL, aes_read_outputdata(), aes_set_key(), aes_software_reset(), aes_start(), aes_write_inputdata(), AES_XOR_OFF, compare_data_block(), encryption_data, encryption_key, pre_encrypted_data, set_buffer, success, and test_assert_true.
Referenced by main().
|
static |
Test AES get and set key value functions.
This test sets a key in the AES module, and reads it back with the get function.
test | Current test case. |
References aes_get_key(), aes_set_key(), aes_software_reset(), compare_data_block(), encryption_key, set_buffer, success, and test_assert_true.
Referenced by main().
|
static |
Test AES state interface functions.
This test verifies that the functions used to check the state of the module are working, and that the clear functions work correctly.
test | Current test case |
References aes_clear_error_flag(), aes_clear_interrupt_flag(), aes_configure(), AES_ENCRYPT, aes_is_busy(), aes_is_error(), AES_MANUAL, aes_set_key(), aes_software_reset(), aes_start(), aes_write_inputdata(), AES_XOR_OFF, dummy_data, encryption_key, and test_assert_true.
Referenced by main().
Callback read finished variable.
Referenced by int_callback_aes(), and run_aes_encrypt_and_decrypt_test().
t_data dummy_data |
Dummy data used to fill AES state memory.
Referenced by aes_lastsubkey_generate(), hmc5883l_calibrate(), and run_aes_state_interface_test().
t_data encryption_data |
Data which will be encrypted.
Referenced by run_aes_decryption_test(), run_aes_encrypt_and_decrypt_test(), and run_aes_encryption_test().
t_key encryption_key |
Key used for encryption and generation of last subkey.
Referenced by run_aes_decryption_test(), run_aes_encrypt_and_decrypt_test(), run_aes_encryption_test(), run_aes_set_and_get_key_test(), and run_aes_state_interface_test().
t_key lastsubkey |
Last subkey used in decryption of above encrypted data, generated from above encryption key.
t_data output_data |
Output data for enc/dec-test.
Referenced by int_callback_aes(), and run_aes_encrypt_and_decrypt_test().
t_data pre_encrypted_data |
Data which has been pre-encrypted with above key for comparison.
Referenced by run_aes_decryption_test(), and run_aes_encryption_test().