mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-11 20:16:02 +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
36
Libraries/LibCrypto/BigInt/TommathForward.h
Normal file
36
Libraries/LibCrypto/BigInt/TommathForward.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Altomani Gianluca <altomanigianluca@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
extern "C" {
|
||||
typedef uint64_t mp_digit;
|
||||
typedef int mp_sign;
|
||||
|
||||
// This is a workaround for the fact that Tommath doesn't have a proper
|
||||
// header file. It uses an anonymous struct to define the mp_int struct
|
||||
// which makes it impossible to forward declare.
|
||||
// Declare the mp_int struct with the same layout as the one in tommath.h
|
||||
// and check that the layout is the same while avoiding a conflicting
|
||||
// definition error (BN_H_ is defined in tommath.h).
|
||||
// When importing this file it is important to always do it AFTER tommath.h.
|
||||
|
||||
typedef struct {
|
||||
int used, alloc;
|
||||
mp_sign sign;
|
||||
mp_digit* dp;
|
||||
} mp_int_;
|
||||
|
||||
#ifndef BN_H_
|
||||
typedef mp_int_ mp_int;
|
||||
#else
|
||||
static_assert(sizeof(mp_int_) == sizeof(mp_int));
|
||||
static_assert(offsetof(mp_int_, used) == offsetof(mp_int, used));
|
||||
static_assert(offsetof(mp_int_, alloc) == offsetof(mp_int, alloc));
|
||||
static_assert(offsetof(mp_int_, sign) == offsetof(mp_int, sign));
|
||||
static_assert(offsetof(mp_int_, dp) == offsetof(mp_int, dp));
|
||||
#endif
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue