From 3dde0787a8b69e456d63b4e8b2a4cf09fa647d97 Mon Sep 17 00:00:00 2001 From: Jari Nippula Date: Wed, 27 Mar 2024 16:30:46 +0200 Subject: [PATCH] systemcmd/tests: crypto: ed25519 signing test --- src/systemcmds/tests/test_crypto.cpp | 45 +++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/src/systemcmds/tests/test_crypto.cpp b/src/systemcmds/tests/test_crypto.cpp index dd5e60d31714..ee4634ea5610 100644 --- a/src/systemcmds/tests/test_crypto.cpp +++ b/src/systemcmds/tests/test_crypto.cpp @@ -88,6 +88,8 @@ static uint32_t rsa_sig[] = { 0x9303ebe0, 0x8414b231, 0xbeec5418, 0x088cc7bb, 0x5e345fe3, 0xb7c954a3, 0x54d08308, 0xcaae3c41, }; +static const uint8_t ed25519_test_key_index = 100; + class CryptoTest : public UnitTest { public: @@ -96,6 +98,8 @@ class CryptoTest : public UnitTest bool test_aes(); bool test_chacha(); bool test_rsa_sign(); + bool test_ed25519_key_gen(); + bool test_ed25519_sign(); private: void color_output(void *buf, size_t sz); @@ -335,11 +339,50 @@ bool CryptoTest::test_rsa_sign() return ret; } +bool CryptoTest::test_ed25519_key_gen() +{ + bool ret = true; + + PX4Crypto crypto; + + if (!crypto.open(CRYPTO_ED25519)) { + ERROUT("Crypto open failed"); + } + + ret = crypto.generate_keypair(32, ed25519_test_key_index, false); + + crypto.close(); + + return ret; +} + +bool CryptoTest::test_ed25519_sign() +{ + bool ret = true; + uint8_t signature[64] = {0xde, 0xad, 0xbe, 0xef}; + + PX4Crypto crypto; + + if (!crypto.open(CRYPTO_ED25519)) { + ERROUT("Crypto open failed"); + } + + ret = crypto.sign(ed25519_test_key_index, signature, (const uint8_t *)test_input, sizeof(test_input)); + + if (!ret) { + return ret; + } + + return crypto.signature_check(ed25519_test_key_index, signature, (const uint8_t *)test_input, sizeof(test_input)); +} + bool CryptoTest::run_tests() { ut_run_test(test_aes); ut_run_test(test_chacha); - // ut_run_test(test_rsa_sign); + ut_run_test(test_ed25519_key_gen); + ut_run_test(test_ed25519_sign); + ut_run_test(test_rsa_sign); return (_tests_failed == 0); }