2024-04-07 17:22:42 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2024, stelar7 <dudedbz@gmail.com>
|
2024-12-25 22:40:50 +01:00
|
|
|
* Copyright (c) 2025, Altomani Gianluca <altomanigianluca@gmail.com>
|
2024-04-07 17:22:42 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2024-04-09 01:28:11 +02:00
|
|
|
#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)
|
|
|
|
|
{
|
2024-12-25 22:40:50 +01:00
|
|
|
auto msg = "WellHelloFriendsWellHelloFriendsWellHelloFriendsWellHelloFriends"sv.bytes();
|
2024-04-07 17:22:42 +02:00
|
|
|
|
2024-12-25 22:40:50 +01: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
|
|
|
|
2024-12-25 22:40:50 +01: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
|
|
|
}
|