ladybird/Tests/LibCrypto/TestOAEP.cpp

25 lines
765 B
C++
Raw Normal View History

2024-04-07 17:22:42 +02:00
/*
* Copyright (c) 2024, stelar7 <dudedbz@gmail.com>
* Copyright (c) 2025, Altomani Gianluca <altomanigianluca@gmail.com>
2024-04-07 17:22:42 +02:00
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/ByteBuffer.h>
#include <LibCrypto/PK/RSA.h>
2024-04-07 17:22:42 +02:00
#include <LibTest/TestCase.h>
// https://www.inf.pucrs.br/~calazans/graduate/TPVLSI_I/RSA-oaep_spec.pdf
TEST_CASE(test_oaep)
{
auto msg = "WellHelloFriendsWellHelloFriendsWellHelloFriendsWellHelloFriends"sv.bytes();
2024-04-07 17:22:42 +02:00
auto keypair = TRY_OR_FAIL(Crypto::PK::RSA::generate_key_pair(1024));
auto rsa = Crypto::PK::RSA_OAEP_EME(Crypto::Hash::HashKind::SHA1, keypair);
rsa.set_label("LABEL"sv.bytes());
2024-04-07 17:22:42 +02:00
auto enc = TRY_OR_FAIL(rsa.encrypt(msg));
auto dec = TRY_OR_FAIL(rsa.decrypt(enc));
EXPECT_EQ(msg, dec);
2024-04-07 17:22:42 +02:00
}