diff --git a/tests/sys_crypto/Makefile.ci b/tests/sys_crypto/Makefile.ci index 6f722e32bd..aa7a5ddab2 100644 --- a/tests/sys_crypto/Makefile.ci +++ b/tests/sys_crypto/Makefile.ci @@ -4,9 +4,14 @@ BOARD_INSUFFICIENT_MEMORY := \ arduino-mega2560 \ arduino-nano \ arduino-uno \ + atmega1284p \ atmega328p \ atmega328p-xplained-mini \ atxmega-a1u-xpro \ + atxmega-a3bu-xplained \ + derfmega128 \ + mega-xplained \ + microduino-corerf \ msb-430 \ msb-430h \ nucleo-f031k6 \ @@ -19,4 +24,5 @@ BOARD_INSUFFICIENT_MEMORY := \ telosb \ waspmote-pro \ z1 \ + zigduino \ # diff --git a/tests/sys_crypto/README.md b/tests/sys_crypto/README.md new file mode 100644 index 0000000000..97f16ef3c9 --- /dev/null +++ b/tests/sys_crypto/README.md @@ -0,0 +1,33 @@ +# Overview + +This test application tests all the components of the crypto module in RIOT. +Specifically these are: + +* ChaCha. Test vectors from [draft-strombergson-chacha-test-vectors-00]. +* Poly1305. Test vectors from [draft-nir-cfrg-chacha20-poly1305-06]. +* ChaCha20-Poly1305. Test vectors from [rfc7539]. +* AES-CBC. Test vectors from [SP 800-38C]. +* AES-CCM. Test vectors from [RFC3610], [SP 800-38C], [Wycheproof]. +* AES-CTR. Test vectors from [SP 800-38C]. +* AES-ECB. Test vectors from [SP 800-38C]. +* AES-OCB. Test vectors from [RFC7253]. + +To build the test application run + +``` +make +``` + +To execute the test run + +``` +make term +``` + +[draft-nir-cfrg-chacha20-poly1305-06]: https://tools.ietf.org/html/draft-nir-cfrg-chacha20-poly1305-06#appendix-A.3 +[draft-strombergson-chacha-test-vectors-00]: https://tools.ietf.org/html/draft-strombergson-chacha-test-vectors-00 +[rfc7539]: https://tools.ietf.org/html/rfc7539#appendix-A +[SP 800-38C]: http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf +[RFC3610]: https://tools.ietf.org/html/rfc3610 +[Wycheproof]: https://github.com/google/wycheproof/blob/master/testvectors/aes_ccm_test.json +[RFC7253]: https://tools.ietf.org/html/rfc7253#appendix-A \ No newline at end of file diff --git a/tests/sys_crypto/app.config.test b/tests/sys_crypto/app.config.test index de98095fab..8420f852d5 100644 --- a/tests/sys_crypto/app.config.test +++ b/tests/sys_crypto/app.config.test @@ -1,7 +1,10 @@ # this file enables modules defined in Kconfig. Do not use this file for # application configuration. This is only needed during migration. -CONFIG_MODULE_CRYPTO_3DES=y +CONFIG_MODULE_CRYPTO=y +CONFIG_MODULE_CRYPTO_AES_128=y +CONFIG_MODULE_CRYPTO_AES_192=y +CONFIG_MODULE_CRYPTO_AES_256=y CONFIG_MODULE_CIPHER_MODES=y CONFIG_MODULE_EMBUNIT=y diff --git a/tests/sys_crypto/main.c b/tests/sys_crypto/main.c index 1ab7debf17..9cf320889e 100644 --- a/tests/sys_crypto/main.c +++ b/tests/sys_crypto/main.c @@ -19,9 +19,6 @@ int main(void) TESTS_RUN(tests_crypto_aes_tests()); TESTS_RUN(tests_crypto_cipher_tests()); TESTS_RUN(tests_crypto_modes_ccm_tests()); - TESTS_RUN(tests_crypto_modes_ccm_tests_128()); - TESTS_RUN(tests_crypto_modes_ccm_tests_192()); - TESTS_RUN(tests_crypto_modes_ccm_tests_256()); TESTS_RUN(tests_crypto_modes_ocb_tests()); TESTS_RUN(tests_crypto_modes_ecb_tests()); TESTS_RUN(tests_crypto_modes_cbc_tests()); diff --git a/tests/sys_crypto/tests-crypto-chacha.c b/tests/sys_crypto/tests-crypto-chacha.c index 0097239613..71de747a71 100644 --- a/tests/sys_crypto/tests-crypto-chacha.c +++ b/tests/sys_crypto/tests-crypto-chacha.c @@ -13,6 +13,13 @@ #include +/* + * Test Vectors for the Stream Cipher ChaCha + * draft-strombergson-chacha-test-vectors-00 + * + * https://tools.ietf.org/html/draft-strombergson-chacha-test-vectors-00 + */ + static const uint8_t TC8_KEY[32] = { 0xc4, 0x6e, 0xc1, 0xb1, 0x8c, 0xe8, 0xa8, 0x78, 0x72, 0x5a, 0x37, 0xe7, 0x80, 0xdf, 0xb7, 0x35, diff --git a/tests/sys_crypto/tests-crypto-chacha20poly1305.c b/tests/sys_crypto/tests-crypto-chacha20poly1305.c index a22cd67d00..c5979c4c00 100644 --- a/tests/sys_crypto/tests-crypto-chacha20poly1305.c +++ b/tests/sys_crypto/tests-crypto-chacha20poly1305.c @@ -15,6 +15,12 @@ #include "crypto/chacha20poly1305.h" +/* + * Example and Test Vector for AEAD_CHACHA20_POLY1305 + * + * https://tools.ietf.org/html/rfc7539#appendix-A + */ + /* ciphertext buffer */ uint8_t ebuf[1024]; /* Plaintext buffer */ diff --git a/tests/sys_crypto/tests-crypto-poly1305.c b/tests/sys_crypto/tests-crypto-poly1305.c index 2ca5a29a45..38351e85a9 100644 --- a/tests/sys_crypto/tests-crypto-poly1305.c +++ b/tests/sys_crypto/tests-crypto-poly1305.c @@ -14,6 +14,12 @@ #include +/* + * Poly1305 Message Authentication Code + * + * https://tools.ietf.org/html/draft-nir-cfrg-chacha20-poly1305-06#appendix-A.3 + */ + static const uint8_t key_1[32] = { 0 }; static const uint8_t msg_1[64] = { 0 }; static const uint8_t tag_1[16] = { 0 }; diff --git a/tests/sys_crypto/tests-crypto.h b/tests/sys_crypto/tests-crypto.h index b316b50d06..eddf2d73ba 100644 --- a/tests/sys_crypto/tests-crypto.h +++ b/tests/sys_crypto/tests-crypto.h @@ -59,9 +59,6 @@ static inline int compare(const uint8_t *a, const uint8_t *b, uint8_t len) Test* tests_crypto_aes_tests(void); Test* tests_crypto_cipher_tests(void); Test* tests_crypto_modes_ccm_tests(void); -Test* tests_crypto_modes_ccm_tests_128(void); -Test* tests_crypto_modes_ccm_tests_192(void); -Test* tests_crypto_modes_ccm_tests_256(void); Test* tests_crypto_modes_ocb_tests(void); Test* tests_crypto_modes_ecb_tests(void); Test* tests_crypto_modes_cbc_tests(void); diff --git a/tests/sys_crypto_aes_ccm/Makefile b/tests/sys_crypto_aes_ccm/Makefile new file mode 100644 index 0000000000..f9438f3de8 --- /dev/null +++ b/tests/sys_crypto_aes_ccm/Makefile @@ -0,0 +1,10 @@ +include ../Makefile.tests_common + +USEMODULE += embunit + +USEMODULE += cipher_modes +USEMODULE += crypto_aes_128 +USEMODULE += crypto_aes_192 +USEMODULE += crypto_aes_256 + +include $(RIOTBASE)/Makefile.include diff --git a/tests/sys_crypto_aes_ccm/Makefile.ci b/tests/sys_crypto_aes_ccm/Makefile.ci new file mode 100644 index 0000000000..aa7a5ddab2 --- /dev/null +++ b/tests/sys_crypto_aes_ccm/Makefile.ci @@ -0,0 +1,28 @@ +BOARD_INSUFFICIENT_MEMORY := \ + arduino-duemilanove \ + arduino-leonardo \ + arduino-mega2560 \ + arduino-nano \ + arduino-uno \ + atmega1284p \ + atmega328p \ + atmega328p-xplained-mini \ + atxmega-a1u-xpro \ + atxmega-a3bu-xplained \ + derfmega128 \ + mega-xplained \ + microduino-corerf \ + msb-430 \ + msb-430h \ + nucleo-f031k6 \ + nucleo-f042k6 \ + nucleo-l011k4 \ + nucleo-l031k6 \ + samd10-xmini \ + stk3200 \ + stm32f030f4-demo \ + telosb \ + waspmote-pro \ + z1 \ + zigduino \ + # diff --git a/tests/sys_crypto_aes_ccm/README.md b/tests/sys_crypto_aes_ccm/README.md new file mode 100644 index 0000000000..c580d81731 --- /dev/null +++ b/tests/sys_crypto_aes_ccm/README.md @@ -0,0 +1,18 @@ +# Overview + +This test application specifically tests the AES CCM implementation for 128, 192 and 256 +bit keys. The test utilizes the [CAVP AES CCM DVTP] test vectors. + +To build the test application run + +``` +make +``` + +To execute the test run + +``` +make term +``` + +[CAVP AES CCM DVTP]: https://csrc.nist.gov/projects/cryptographic-algorithm-validation-program/cavp-testing-block-cipher-modes \ No newline at end of file diff --git a/tests/sys_crypto_aes_ccm/app.config.test b/tests/sys_crypto_aes_ccm/app.config.test new file mode 100644 index 0000000000..8420f852d5 --- /dev/null +++ b/tests/sys_crypto_aes_ccm/app.config.test @@ -0,0 +1,11 @@ +# this file enables modules defined in Kconfig. Do not use this file for +# application configuration. This is only needed during migration. + +CONFIG_MODULE_CRYPTO=y +CONFIG_MODULE_CRYPTO_AES_128=y +CONFIG_MODULE_CRYPTO_AES_192=y +CONFIG_MODULE_CRYPTO_AES_256=y +CONFIG_MODULE_CIPHER_MODES=y + +CONFIG_MODULE_EMBUNIT=y +CONFIG_MODULE_TEST_UTILS_INTERACTIVE_SYNC=y diff --git a/tests/sys_crypto_aes_ccm/main.c b/tests/sys_crypto_aes_ccm/main.c new file mode 100644 index 0000000000..0cb83c9dd3 --- /dev/null +++ b/tests/sys_crypto_aes_ccm/main.c @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2021 Nils Ollrogge + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +#include "tests-crypto.h" + +int main(void) +{ + TESTS_START(); + TESTS_RUN(tests_crypto_modes_ccm_tests_128()); + TESTS_RUN(tests_crypto_modes_ccm_tests_192()); + TESTS_RUN(tests_crypto_modes_ccm_tests_256()); + TESTS_END(); + return 0; +} diff --git a/tests/sys_crypto/tests-crypto-modes-ccm-128.c b/tests/sys_crypto_aes_ccm/tests-crypto-modes-ccm-128.c similarity index 100% rename from tests/sys_crypto/tests-crypto-modes-ccm-128.c rename to tests/sys_crypto_aes_ccm/tests-crypto-modes-ccm-128.c diff --git a/tests/sys_crypto/tests-crypto-modes-ccm-192.c b/tests/sys_crypto_aes_ccm/tests-crypto-modes-ccm-192.c similarity index 100% rename from tests/sys_crypto/tests-crypto-modes-ccm-192.c rename to tests/sys_crypto_aes_ccm/tests-crypto-modes-ccm-192.c diff --git a/tests/sys_crypto/tests-crypto-modes-ccm-256.c b/tests/sys_crypto_aes_ccm/tests-crypto-modes-ccm-256.c similarity index 99% rename from tests/sys_crypto/tests-crypto-modes-ccm-256.c rename to tests/sys_crypto_aes_ccm/tests-crypto-modes-ccm-256.c index da509e1409..9174442a35 100644 --- a/tests/sys_crypto/tests-crypto-modes-ccm-256.c +++ b/tests/sys_crypto_aes_ccm/tests-crypto-modes-ccm-256.c @@ -20,7 +20,7 @@ /** * AES CCM DVTP test vectors (SP 800-38C) for 256 bit keys. * https://csrc.nist.gov/projects/cryptographic-algorithm-validation-program/cavp-testing-block-cipher-modes -*/ + */ static const size_t nonce_and_len_encoding_size = 15; diff --git a/tests/sys_crypto_aes_ccm/tests-crypto.h b/tests/sys_crypto_aes_ccm/tests-crypto.h new file mode 100644 index 0000000000..ef65c1ca3e --- /dev/null +++ b/tests/sys_crypto_aes_ccm/tests-crypto.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2021 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @addtogroup unittests + * @{ + * + * @file + * @brief Unittests for the ``crypto`` module + * + * @author Nils Ollrogge + */ +#ifndef TESTS_CRYPTO_H +#define TESTS_CRYPTO_H + +#include +#include + +#include "embUnit.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static inline int compare(const uint8_t *a, const uint8_t *b, uint8_t len) +{ + int result = 1; + + for (uint8_t i = 0; i < len; ++i) { + result &= a[i] == b[i]; + } + + return result; +} + +Test *tests_crypto_modes_ccm_tests_128(void); +Test *tests_crypto_modes_ccm_tests_192(void); +Test *tests_crypto_modes_ccm_tests_256(void); + +#ifdef __cplusplus +} +#endif + +#endif /* TESTS_CRYPTO_H */ +/** @} */ diff --git a/tests/sys_crypto_aes_ccm/tests/01-run.py b/tests/sys_crypto_aes_ccm/tests/01-run.py new file mode 100755 index 0000000000..aec47345a2 --- /dev/null +++ b/tests/sys_crypto_aes_ccm/tests/01-run.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2019 Freie Universität Berlin +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. + +import sys +from testrunner import run_check_unittests + + +if __name__ == "__main__": + sys.exit(run_check_unittests())