Unit tests for Non Volatile Memory controller driver.
Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
#include <stdint.h>
#include <stdbool.h>
#include <board.h>
#include <sysclk.h>
#include <string.h>
#include <unit_test/suite.h>
#include <stdio_serial.h>
#include <conf_test.h>
#include <sleepmgr.h>
#include <des.h>
Functions | |
int | main (void) |
Run DES driver unit tests. More... | |
Unit test functions | |
static void | run_des_encryption_and_decryption_test (const struct test_case *test) |
Run DES encryption and decryption in series. More... | |
static void | run_3des_encryption_and_decryption_test (const struct test_case *test) |
Run 3DES encryption and decryption in series. More... | |
static void | run_des_encryption (const struct test_case *test) |
Run DES encryption with known result. More... | |
static void | run_des_decryption (const struct test_case *test) |
Run DES decryption with known result. More... | |
static void | run_3des_encryption (const struct test_case *test) |
Run 3DES encryption with known result. More... | |
static void | run_3des_decryption (const struct test_case *test) |
Run 3DES decryption with known result. More... | |
static void | run_des_cbc_encryption_test (const struct test_case *test) |
Run DES CBC encryption on three data blocks, with known result. More... | |
static void | run_des_cbc_decryption_test (const struct test_case *test) |
Run DES CBC decryption on three data blocks, with known result. More... | |
static void | run_3des_cbc_encryption_test (const struct test_case *test) |
Run 3DES CBC encryption on three data blocks, with known result. More... | |
static void | run_3des_cbc_decryption_test (const struct test_case *test) |
Run 3DES CBC decryption on three data blocks, with known result. More... | |
Variables | |
Variables and expected results | |
uint8_t | data [DES_BLOCK_LENGTH] |
Data which will be encrypted. More... | |
uint8_t | data_cbc [DES_BLOCK_LENGTH *DES_CHAIN_BLOCK_COUNT] |
Data which will be encrypted with CBC. More... | |
uint8_t | pre_des_encrypted_data [DES_BLOCK_LENGTH] |
Pre-DES-encrypted result of the original data. More... | |
uint8_t | pre_3des_encrypted_data [DES_BLOCK_LENGTH] |
Pre-3DES-encrypted result of the original data. More... | |
uint8_t | pre_des_cbc_encrypted_data [DES_BLOCK_LENGTH *DES_CHAIN_BLOCK_COUNT] |
Pre CBC-DES-encrypted result of data_cbc. More... | |
uint8_t | pre_3des_cbc_encrypted_data [DES_BLOCK_LENGTH *DES_CHAIN_BLOCK_COUNT] |
Pre CBC-3DES-encrypted result of data_cbc. More... | |
uint8_t | init [DES_BLOCK_LENGTH] |
Initialization vector used for starting CBC. More... | |
uint8_t | keys [DES_BLOCK_LENGTH *DES_KEY_COUNT] |
Keys used for the 3DES-encryption. Only first key for DES. 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 (const uint8_t *block_1, const uint8_t *block_2, uint8_t block_size) |
Compare two data blocks of given size. More... | |
Set all bytes in buffer to value.
Referenced by run_3des_cbc_decryption_test(), run_3des_cbc_encryption_test(), run_3des_decryption(), run_3des_encryption(), run_3des_encryption_and_decryption_test(), run_des_cbc_decryption_test(), run_des_cbc_encryption_test(), run_des_decryption(), run_des_encryption(), and run_des_encryption_and_decryption_test().
|
static |
Compare two data blocks of given size.
block_1 | Pointer to first block. |
block_2 | Pointer to second block. |
block_size | Size of blocks to compare. |
Referenced by run_3des_cbc_decryption_test(), run_3des_cbc_encryption_test(), run_3des_decryption(), run_3des_encryption(), run_3des_encryption_and_decryption_test(), run_des_cbc_decryption_test(), run_des_cbc_encryption_test(), run_des_decryption(), run_des_encryption(), and run_des_encryption_and_decryption_test().
int main | ( | void | ) |
Run DES driver unit tests.
References usart_rs232_options::baudrate, board_init(), DEFINE_TEST_ARRAY, DEFINE_TEST_CASE, DEFINE_TEST_SUITE, run_3des_cbc_decryption_test(), run_3des_cbc_encryption_test(), run_3des_decryption(), run_3des_encryption(), run_3des_encryption_and_decryption_test(), run_des_cbc_decryption_test(), run_des_cbc_encryption_test(), run_des_decryption(), run_des_encryption(), run_des_encryption_and_decryption_test(), sleepmgr_init(), stdio_serial_init(), sysclk_init(), test_suite_run(), and usart_serial_options.
|
static |
Run 3DES CBC decryption on three data blocks, with known result.
test | Current test case. |
References compare_data_block(), data_cbc, DES_BLOCK_LENGTH, des_cbc_decrypt(), init, keys, pre_3des_cbc_encrypted_data, set_buffer, success, and test_assert_true.
Referenced by main().
|
static |
Run 3DES CBC encryption on three data blocks, with known result.
test | Current test case. |
References compare_data_block(), data_cbc, DES_BLOCK_LENGTH, des_cbc_encrypt(), init, keys, pre_3des_cbc_encrypted_data, set_buffer, success, and test_assert_true.
Referenced by main().
|
static |
Run 3DES decryption with known result.
test | Current test case. |
References compare_data_block(), data, des_3des_decrypt(), DES_BLOCK_LENGTH, keys, pre_3des_encrypted_data, set_buffer, success, and test_assert_true.
Referenced by main().
|
static |
Run 3DES encryption with known result.
test | Current test case. |
References compare_data_block(), data, des_3des_encrypt(), DES_BLOCK_LENGTH, keys, pre_3des_encrypted_data, set_buffer, success, and test_assert_true.
Referenced by main().
|
static |
Run 3DES encryption and decryption in series.
test | Current test case. |
References compare_data_block(), data, des_3des_decrypt(), des_3des_encrypt(), DES_BLOCK_LENGTH, keys, set_buffer, success, and test_assert_true.
Referenced by main().
|
static |
Run DES CBC decryption on three data blocks, with known result.
test | Current test case. |
References compare_data_block(), data_cbc, DES_BLOCK_LENGTH, des_cbc_decrypt(), init, keys, pre_des_cbc_encrypted_data, set_buffer, success, and test_assert_true.
Referenced by main().
|
static |
Run DES CBC encryption on three data blocks, with known result.
test | Current test case. |
References compare_data_block(), data_cbc, DES_BLOCK_LENGTH, des_cbc_encrypt(), init, keys, pre_des_cbc_encrypted_data, set_buffer, success, and test_assert_true.
Referenced by main().
|
static |
Run DES decryption with known result.
test | Current test case. |
References compare_data_block(), data, DES_BLOCK_LENGTH, des_decrypt(), keys, pre_des_encrypted_data, set_buffer, success, and test_assert_true.
Referenced by main().
|
static |
Run DES encryption with known result.
test | Current test case. |
References compare_data_block(), data, DES_BLOCK_LENGTH, des_encrypt(), keys, pre_des_encrypted_data, set_buffer, success, and test_assert_true.
Referenced by main().
|
static |
Run DES encryption and decryption in series.
test | Current test case. |
References compare_data_block(), data, DES_BLOCK_LENGTH, des_decrypt(), des_encrypt(), keys, set_buffer, success, and test_assert_true.
Referenced by main().
uint8_t data[DES_BLOCK_LENGTH] |
Data which will be encrypted.
uint8_t data_cbc[DES_BLOCK_LENGTH *DES_CHAIN_BLOCK_COUNT] |
Data which will be encrypted with CBC.
Referenced by run_3des_cbc_decryption_test(), run_3des_cbc_encryption_test(), run_des_cbc_decryption_test(), and run_des_cbc_encryption_test().
uint8_t init[DES_BLOCK_LENGTH] |
Initialization vector used for starting CBC.
uint8_t keys[DES_BLOCK_LENGTH *DES_KEY_COUNT] |
Keys used for the 3DES-encryption. Only first key for DES.
uint8_t pre_3des_cbc_encrypted_data[DES_BLOCK_LENGTH *DES_CHAIN_BLOCK_COUNT] |
Pre CBC-3DES-encrypted result of data_cbc.
Referenced by run_3des_cbc_decryption_test(), and run_3des_cbc_encryption_test().
uint8_t pre_3des_encrypted_data[DES_BLOCK_LENGTH] |
Pre-3DES-encrypted result of the original data.
Referenced by run_3des_decryption(), and run_3des_encryption().
uint8_t pre_des_cbc_encrypted_data[DES_BLOCK_LENGTH *DES_CHAIN_BLOCK_COUNT] |
Pre CBC-DES-encrypted result of data_cbc.
Referenced by run_des_cbc_decryption_test(), and run_des_cbc_encryption_test().
uint8_t pre_des_encrypted_data[DES_BLOCK_LENGTH] |
Pre-DES-encrypted result of the original data.
Referenced by run_des_decryption(), and run_des_encryption().