mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 19:59:17 +00:00
LibCrypto: Add methods to convert OpenSSL BN <-> UnsignedBigInteger
These methods allow to convert between OpenSSL big numbers and ours.
This commit is contained in:
parent
7b38923144
commit
130f890497
Notes:
github-actions[bot]
2025-01-12 00:14:29 +00:00
Author: https://github.com/devgianlu
Commit: 130f890497
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3225
Reviewed-by: https://github.com/alimpfard
Reviewed-by: https://github.com/gmta ✅
3 changed files with 46 additions and 0 deletions
30
Libraries/LibCrypto/OpenSSL.cpp
Normal file
30
Libraries/LibCrypto/OpenSSL.cpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Altomani Gianluca <altomanigianluca@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <LibCrypto/OpenSSL.h>
|
||||
#include <openssl/evp.h>
|
||||
|
||||
namespace Crypto {
|
||||
|
||||
ErrorOr<OpenSSL_BN> unsigned_big_integer_to_openssl_bignum(UnsignedBigInteger const& integer)
|
||||
{
|
||||
auto bn = TRY(OpenSSL_BN::create());
|
||||
auto buf = TRY(ByteBuffer::create_uninitialized(integer.byte_length()));
|
||||
auto integer_size = integer.export_data(buf.bytes());
|
||||
OPENSSL_TRY_PTR(BN_bin2bn(buf.bytes().data(), integer_size, bn.ptr()));
|
||||
return bn;
|
||||
}
|
||||
|
||||
ErrorOr<UnsignedBigInteger> openssl_bignum_to_unsigned_big_integer(OpenSSL_BN const& bn)
|
||||
{
|
||||
auto size = BN_num_bytes(bn.ptr());
|
||||
auto buf = TRY(ByteBuffer::create_uninitialized(size));
|
||||
BN_bn2bin(bn.ptr(), buf.bytes().data());
|
||||
return UnsignedBigInteger::import_data(buf.bytes().data(), size);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue