Add a CRC module to mbedtls and baremetal config
Add a new CRC module along with some tests for it.
The table and the CRC function body is generated using pycrc v0.9.2.
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 2ea77e7..0a3415e 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -94,6 +94,7 @@
add_test_suite(cipher cipher.null)
add_test_suite(cipher cipher.padding)
add_test_suite(cmac)
+add_test_suite(crc)
add_test_suite(ctr_drbg)
add_test_suite(debug)
add_test_suite(des)
diff --git a/tests/suites/test_suite_crc.data b/tests/suites/test_suite_crc.data
new file mode 100644
index 0000000..aa4c686
--- /dev/null
+++ b/tests/suites/test_suite_crc.data
@@ -0,0 +1,44 @@
+CRC-16 1 byte of 0x00
+compute_crc:"00":0
+
+CRC-16 8 bytes of 0x00
+compute_crc:"0000000000000000":0
+
+CRC-16 16 bytes of 0x00
+compute_crc:"00000000000000000000000000000000":0
+
+CRC-16 32 bytes of 0x00
+compute_crc:"0000000000000000000000000000000000000000000000000000000000000000":0
+
+CRC-16 1 byte of 0xFF
+compute_crc:"FF":16448
+
+CRC-16 8 bytes of 0xFF
+compute_crc:"FFFFFFFFFFFFFFFF":33857
+
+CRC-16 16 bytes of 0xFF
+compute_crc:"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF":28736
+
+CRC-16 32 bytes of 0xFF
+compute_crc:"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF":41985
+
+CRC-16 1 byte of 0x01
+compute_crc:"01":49345
+
+CRC-16 8 bytes incrementing
+compute_crc:"0123456789abcdef":62374
+
+CRC-16 16 bytes incrementing
+compute_crc:"0123456789abcdef0123456789abcdef":44783
+
+CRC-16 32 bytes incrementing
+compute_crc:"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef":44749
+
+CRC-16 64 bytes incrementing
+compute_crc:"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef":53063
+
+CRC-16 ascii 1 to 9 incrementing
+compute_crc:"313233343536373839":47933
+
+CRC-16 512 bytes of random data
+compute_crc:"66870a93e17d4a5dd6ef84476dff6e2aa7d2ebd391cf4c54affff479a98a81360909f32eafbea98f4a3e4737de4c588d11c356860333ad7f4c334fb7dfce77cb04fafb50991f9b2e7957312a1b9dbcbebaf03f4eb9443938279f9b6c01e2b8c6022ee58f5840c7e86962830ca088174dc1b9912b64bde42877343c0b979b8ea376e4bf994a7ff6c629d5ba936958cc9f55db1c98151b16f7d918ff84f85b45e3ee49e7d166baac4dec81a174b3e496446a92c00d0859c2402f0110964effbdae9a6a3243530996029f4a428f1626837e55d32660cf6a2d4263c9fe23841d01b9410a9530bf9b1561fa83f6c42447d310bc991352ee9863b83b890b5aa0ea0bbf":49505
diff --git a/tests/suites/test_suite_crc.function b/tests/suites/test_suite_crc.function
new file mode 100644
index 0000000..8d09958
--- /dev/null
+++ b/tests/suites/test_suite_crc.function
@@ -0,0 +1,26 @@
+/* BEGIN_HEADER */
+#include "mbedtls/crc.h"
+/* END_HEADER */
+
+/* BEGIN_DEPENDENCIES
+ * depends_on:MBEDTLS_CRC_C
+ * END_DEPENDENCIES
+ */
+
+/* BEGIN_CASE */
+void compute_crc( data_t *input, unsigned int crc )
+{
+ uint16_t result = mbedtls_crc_update( 0, input->x, input->len );
+ uint32_t len = input->len;
+ TEST_ASSERT( crc == result );
+
+ result = 0;
+ while( len > 0 )
+ {
+ uint8_t cur_len = ( len > 8 ? 8 : len );
+ result = mbedtls_crc_update( result, &input->x[ input->len - len ], cur_len );
+ len -= cur_len;
+ }
+ TEST_ASSERT( crc == result );
+}
+/* END_CASE */