The nrf_crypto Test Example verifies the functionality of the nrf_crypto operations by using known test vectors approved by the National Institute of Standards and Technology (NIST) and others. All available nrf_crypto backends can be tested by modifying the nrf_crypto section in the sdk_config
file, as described in Configuring nrf_crypto frontend and backends.
You can find the source code and the project file of the example in the following folder: <InstallFolder>\examples\crypto\nrf_crypto\test_app
Test the nrf_crypto test example application by performing the following steps:
#0022 Test vector passed: SHA SHA256 message_len=64
*************************************** All Tests Done X test vectors passed 0 test vectors failed ***************************************
Test cases and test vectors can be added to the test suite either by including additional source files or by extending the existing files.
A test case is a function designed to verify parts of the functionality of an nrf_crypto operation. Most nrf_crypto operations, like hash calculations and ECDH, have multiple test cases to be able to cover all features. A typical test case loops over all related test vectors, and logs the verdict of each.
An example of a hash test case in a simplified form is shown in the code block below.
A new test case must be registered to the test_case_data section using Experimental: Section variables. The NRF_SECTION_ITEM_REGISTER
macro below places the variable test_hash in a section named "test_case_data", which is initialized by main.
.c file.A test vector is a set of inputs and expected outputs to verify the functionality provided in a test case. The p_test_vector_name
variable is the only required member in the test_vector structures.
Test vectors are added by registering them for a section defined in the test case code. The test vector is registered in the section "test_vector_hash_data", which is defined in the test case example exec_test_case_hash
. The test vector can reuse the already defined hash test vector structure test_vector_hash_t
, as shown in the code block below.
The test project generates a test log using RTT transport, as described in the Testing section. The new test case exec_test_case_hash
and its test vector will be added to the test log when the test is executed. The additional test log output will look like the lines below.
*************************************** Test case Hash Test Started #00XX Test vector passed: SHA256 test vector example Test case Hash Test Done ***************************************