From 782469d7886e059206d8fd2a08d7c5df399b23dc Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Wed, 14 Jan 2026 15:50:24 -0500 Subject: [PATCH] finish out the base crypto test suite and include the DES algo; --- tests/crypto/DES_Crypto_Test.cpp | 60 ++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 tests/crypto/DES_Crypto_Test.cpp diff --git a/tests/crypto/DES_Crypto_Test.cpp b/tests/crypto/DES_Crypto_Test.cpp new file mode 100644 index 00000000..228bd96e --- /dev/null +++ b/tests/crypto/DES_Crypto_Test.cpp @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Digital Voice Modem - Test Suite + * GPLv2 Open Source. Use is subject to license terms. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright (C) 2026 Bryan Biedenkapp, N2PLL + * + */ +#include "host/Defines.h" +#include "common/DESCrypto.h" +#include "common/Log.h" +#include "common/Utils.h" + +using namespace crypto; + +#include +#include +#include + +TEST_CASE("DES Crypto Test", "[des][crypto_test]") { + bool failed = false; + + INFO("DES Crypto Test"); + + srand((unsigned int)time(NULL)); + + // key (K) - DES uses 8-byte (64-bit) keys + uint8_t K[8] = + { + 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF + }; + + // message - DES operates on 8-byte blocks + uint8_t message[8] = + { + 0x90, 0x56, 0x00, 0x00, 0x2D, 0x75, 0xE6, 0x8D + }; + + // perform crypto + DES* des = new DES(); + + Utils::dump(2U, "DES_Crypto_Test, Message", message, 8); + + uint8_t* crypted = des->encryptBlock(message, K); + Utils::dump(2U, "DES_Crypto_Test, Encrypted", crypted, 8); + + uint8_t* decrypted = des->decryptBlock(crypted, K); + Utils::dump(2U, "DES_Crypto_Test, Decrypted", decrypted, 8); + + for (uint32_t i = 0; i < 8U; i++) { + if (decrypted[i] != message[i]) { + ::LogError("T", "DES_Crypto_Test, INVALID AT IDX %d", i); + failed = true; + } + } + + delete des; + REQUIRE(failed==false); +}