mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-13 04:21:54 +00:00
LibCrypto: Replace {Unsigned,Signed}BigInteger impl with LibTomMath
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Build Dev Container Image / build (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Build Dev Container Image / build (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Replace the implementation of maths in `UnsignedBigInteger` and `SignedBigInteger` with LibTomMath. This gives benefits in terms of less code to maintain, correctness and speed. These changes also remove now-unsued methods and improve the error propagation for functions allocating lots of memory. Additionally, the new implementation is always trimmed and won't have dangling zeros when exporting it.
This commit is contained in:
parent
915c6fdcf8
commit
4b3715ccba
Notes:
github-actions[bot]
2025-05-23 09:58:22 +00:00
Author: https://github.com/devgianlu
Commit: 4b3715ccba
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4507
Reviewed-by: https://github.com/gmta ✅
25 changed files with 556 additions and 1973 deletions
|
@ -116,10 +116,9 @@ ErrorOr<String> base64_url_uint_encode(::Crypto::UnsignedBigInteger integer)
|
|||
// value. Zero is represented as BASE64URL(single zero-valued
|
||||
// octet), which is "AA".
|
||||
|
||||
auto bytes = TRY(ByteBuffer::create_uninitialized(integer.trimmed_byte_length()));
|
||||
auto bytes = TRY(ByteBuffer::create_uninitialized(integer.byte_length()));
|
||||
|
||||
bool const remove_leading_zeroes = true;
|
||||
auto data_size = integer.export_data(bytes.span(), remove_leading_zeroes);
|
||||
auto data_size = integer.export_data(bytes.span());
|
||||
|
||||
auto data_slice_be = bytes.bytes().slice(bytes.size() - data_size, data_size);
|
||||
|
||||
|
@ -1057,12 +1056,12 @@ WebIDL::ExceptionOr<GC::Ref<CryptoKey>> RSAOAEP::import_key(Web::Crypto::Algorit
|
|||
// 6. Set the publicExponent attribute of algorithm to the BigInteger representation of the RSA public exponent.
|
||||
TRY(key->handle().visit(
|
||||
[&](::Crypto::PK::RSAPublicKey<> const& public_key) -> WebIDL::ExceptionOr<void> {
|
||||
algorithm->set_modulus_length(public_key.modulus().trimmed_byte_length() * 8);
|
||||
algorithm->set_modulus_length(public_key.modulus().byte_length() * 8);
|
||||
TRY(algorithm->set_public_exponent(public_key.public_exponent()));
|
||||
return {};
|
||||
},
|
||||
[&](::Crypto::PK::RSAPrivateKey<> const& private_key) -> WebIDL::ExceptionOr<void> {
|
||||
algorithm->set_modulus_length(private_key.modulus().trimmed_byte_length() * 8);
|
||||
algorithm->set_modulus_length(private_key.modulus().byte_length() * 8);
|
||||
TRY(algorithm->set_public_exponent(private_key.public_exponent()));
|
||||
return {};
|
||||
},
|
||||
|
@ -1635,12 +1634,12 @@ WebIDL::ExceptionOr<GC::Ref<CryptoKey>> RSAPSS::import_key(AlgorithmParams const
|
|||
// 6. Set the publicExponent attribute of algorithm to the BigInteger representation of the RSA public exponent.
|
||||
TRY(key->handle().visit(
|
||||
[&](::Crypto::PK::RSAPublicKey<> const& public_key) -> WebIDL::ExceptionOr<void> {
|
||||
algorithm->set_modulus_length(public_key.modulus().trimmed_byte_length() * 8);
|
||||
algorithm->set_modulus_length(public_key.modulus().byte_length() * 8);
|
||||
TRY(algorithm->set_public_exponent(public_key.public_exponent()));
|
||||
return {};
|
||||
},
|
||||
[&](::Crypto::PK::RSAPrivateKey<> const& private_key) -> WebIDL::ExceptionOr<void> {
|
||||
algorithm->set_modulus_length(private_key.modulus().trimmed_byte_length() * 8);
|
||||
algorithm->set_modulus_length(private_key.modulus().byte_length() * 8);
|
||||
TRY(algorithm->set_public_exponent(private_key.public_exponent()));
|
||||
return {};
|
||||
},
|
||||
|
@ -2206,12 +2205,12 @@ WebIDL::ExceptionOr<GC::Ref<CryptoKey>> RSASSAPKCS1::import_key(AlgorithmParams
|
|||
// 6. Set the publicExponent attribute of algorithm to the BigInteger representation of the RSA public exponent.
|
||||
TRY(key->handle().visit(
|
||||
[&](::Crypto::PK::RSAPublicKey<> const& public_key) -> WebIDL::ExceptionOr<void> {
|
||||
algorithm->set_modulus_length(public_key.modulus().trimmed_byte_length() * 8);
|
||||
algorithm->set_modulus_length(public_key.modulus().byte_length() * 8);
|
||||
TRY(algorithm->set_public_exponent(public_key.public_exponent()));
|
||||
return {};
|
||||
},
|
||||
[&](::Crypto::PK::RSAPrivateKey<> const& private_key) -> WebIDL::ExceptionOr<void> {
|
||||
algorithm->set_modulus_length(private_key.modulus().trimmed_byte_length() * 8);
|
||||
algorithm->set_modulus_length(private_key.modulus().byte_length() * 8);
|
||||
TRY(algorithm->set_public_exponent(private_key.public_exponent()));
|
||||
return {};
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue