summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCrypto/BigInt
AgeCommit message (Collapse)Author
2023-02-25Everywhere: Use _{short_,}string to create Strings from literalsLinus Groh
2023-01-20Everywhere: Convert known short-strings to the infallible String factoryTimothy Flynn
For now, this is limited to strings that are 3 bytes or less. We can use 7 bytes on 64-bit platforms, but we do not yet assume 64-bit for Lagom hosts (e.g. wasm).
2023-01-15LibCrypto: Define *BigInteger::to_base to convert big integers to StringTimothy Flynn
2023-01-15LibCrypto+Everywhere: Rename *BigInteger::to_base to to_base_deprecatedTimothy Flynn
2022-12-09Everywhere: Use C++ concepts instead of requires clausesMoustafa Raafat
2022-12-06Everywhere: Rename to_{string => deprecated_string}() where applicableLinus Groh
This will make it easier to support both string types at the same time while we convert code, and tracking down remaining uses. One big exception is Value::to_string() in LibJS, where the name is dictated by the ToString AO.
2022-12-06AK+Everywhere: Rename String to DeprecatedStringLinus Groh
We have a new, improved string type coming up in AK (OOM aware, no null state), and while it's going to use UTF-8, the name UTF8String is a mouthful - so let's free up the String name by renaming the existing class. Making the old one have an annoying name will hopefully also help with quick adoption :^)
2022-12-03Everywhere: Run clang-formatLinus Groh
2022-11-03AK+LibC+LibCrypto: Move FloatExtractor to AK/FloatingPoint.hDan Klishch
2022-11-02LibCrypto: Add a way to compare UnsignedBigInteger with doubleMoustafa Raafat
This patch also make SignedBigInteger::compare_to_double make use of the new function.
2022-10-22LibCrypto: Add SignedBigInteger::is_positive()Moustafa Raafat
2022-09-15LibCrypto: Fix -0 and 0 non-equalityLucas CHOLLET
SignedBigInteger::operator==(const UnsignedBigInteger&) was rejecting all negative value before testing for equality. It now accepts negative zero and test for a value equality with the UnsignedBigInteger.
2022-09-15LibCrypto: Add SignedBigInteger::negated_value()Lucas CHOLLET
Return the negated value of the current number.
2022-09-14Everywhere: Fix a variety of typosBrian Gianforcaro
Spelling fixes found by `codespell`.
2022-08-26LibCrypto+LibJS: Remove the create_from methods from BigIntegerdavidot
Instead we just use a specific constructor. With this set of constructors using curly braces for constructing is highly recommended. As then it will not do too many implicit conversions which could lead to unexpected loss of data or calling the much slower double constructor. Also to ensure we don't feed (Un)SignedBigInteger infinities we throw RangeError earlier for Durations.
2022-08-26LibCrypto: Add a constructor to (Un)SignedBigInteger taking a doubledavidot
For now this will assume that the double given is exactly representable as an integer, so no NaN, infinity or rounding.
2022-08-26LibCrypto: Make the constructors of (Un)SignedBigInteger templateddavidot
This means it can take any (un)signed word of size at most Word. This means the constructor can be disambiguated if we were to add a double constructor :^). This requires a change in just one test.
2022-08-26LibCrypto: Add a rounding mode to UnsignedBigInteger::to_doubledavidot
This allows using different options for rounding, like IEEE roundTiesToEven, which is the mode that JS requires. Also fix that the last word read from the bigint for the mantissa could be shifted incorrectly leading to incorrect results.
2022-08-24LibCrypto: Implement a (mostly) proper to_double for UnsignedBigIntegerdavidot
SignedBigInteger can immediately use this by just negating the double if the sign bit is set. For simple cases (below 2^53) we can just convert via an u64, however above that we need to extract the top 53 bits and use those as the mantissa. This function currently does not behave exactly as the JS spec specifies however it is much less naive than the previous implementation.
2022-08-24LibCrypto: Make a VERIFY a static_assert since it only uses constantsdavidot
2022-08-24LibCrypto: Add a way to compare a SignedBigInteger with a doubledavidot
This supports any double value (except for NaNs) instead of having to cast the double to some smaller type which doesn't work for very large values.
2022-07-18LibCrypto: Expose UnsignedBigInteger's is_zero() in SignedBigIntegerTimothy Flynn
Note we don't need to check the sign because negative zero became disallowed in b0d6399f60760e25a55ec9e8e95a1ad322b74b22.
2022-07-12Everywhere: Add sv suffix to strings relying on StringView(char const*)sin-ack
Each of these strings would previously rely on StringView's char const* constructor overload, which would call __builtin_strlen on the string. Since we now have operator ""sv, we can replace these with much simpler versions. This opens the door to being able to remove StringView(char const*). No functional changes.
2022-07-12Meta+Userland: Simplify some formatterssin-ack
These are mostly minor mistakes I've encountered while working on the removal of StringView(char const*). The usage of builder.put_string over Format<FormatString>::format is preferrable as it will avoid the indirection altogether when there's no formatting to be done. Similarly, there is no need to do format(builder, "{}", number) when builder.put_u64(number) works equally well. Additionally a few Strings where only constant strings were used are replaced with StringViews.
2022-07-09LibCrypto: Add the [[nodiscard]] qualifier in both BigInteger classesLucas CHOLLET
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2022-03-10Libraries: Use default constructors/destructors in LibCryptoLenny Maiorani
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules "The compiler is more likely to get the default semantics right and you cannot implement these functions better than the compiler."
2022-02-06LibCrypto: Do not allow signed big integers to be negative zeroTimothy Flynn
If a big integer were to become negative zero, set the sign to instead be positive. This prevents odd scenarios where users of signed big ints would falsely think the result of some big int arithmetic is negative.
2022-01-31LibCrypto: Change UnsignedBigInteger parser to use a StringViewTimothy Flynn
SignedBigInteger already accepts a StringView; let's avoid the heap allocation in UnsignedBigInteger.
2022-01-18LibCrypo: Simplify mixed-sign bitwise_orNico Weber
No behavior change.
2022-01-18LibCrypto: Remove some now-unused (and incorrect) methodsNico Weber
Removes the UnsignedBigInteger overloads of SignedBigInteger::binary_{and,or,xor}(). They're now unused, and they also didn't work when *this was negative.
2022-01-18LibCrypto+LibJS: Better bitwise binary_xor binopNico Weber
We went through some trouble to make & and | work right. Reimplement ^ in terms of & and | to make ^ work right as well. This is less fast than a direct implementation, but let's get things working first.
2022-01-18LibCrypto+LibJS: Better bigint bitwise_or binopNico Weber
Similar to the bitwise_and change, but we have to be careful to sign-extend two's complement numbers only up to the highest set bit in the positive number.
2022-01-18LibCrypto+LibJS: Better bigint bitwise_and binopNico Weber
Bitwise and is defined in terms of two's complement, so some converting needs to happen for SignedBigInteger's sign/magnitude representation to work out. UnsignedBigInteger::bitwise_not() is repurposed to convert all high-order zero bits to ones up to a limit, for the two's complement conversion to work. Fixes test262/test/language/expressions/bitwise-and/bigint.js.
2022-01-18LibJS+LibCrypto: Fix SignedBitInteger::bitwise_not and use it in LibJSNico Weber
Bitwise operators are defined on two's complement, but SignedBitInteger uses sign-magnitude. Correctly convert between the two. Let LibJS delegate to SignedBitInteger for bitwise_not, like it does for all other bitwise_ operations on bigints. No behavior change (LibJS is now the only client of SignedBitInteger::bitwise_not()).
2022-01-18LibCrypto: Add Formatter<SignedBigInteger>Nico Weber
Useful for seeing SignedBigInteger values in test failure messages.
2022-01-07Everywhere: Fix spelling mistakesmjz19910
2022-01-07Everywhere: Fix many spelling errorsmjz19910
2021-12-21AK+Everywhere: Replace __builtin bit functionsNick Johnson
In order to reduce our reliance on __builtin_{ffs, clz, ctz, popcount}, this commit removes all calls to these functions and replaces them with the equivalent functions in AK/BuiltinWrappers.h.
2021-11-17AK: Convert AK::Format formatting helpers to returning ErrorOr<void>Andreas Kling
This isn't a complete conversion to ErrorOr<void>, but a good chunk. The end goal here is to propagate buffer allocation failures to the caller, and allow the use of TRY() with formatting functions.
2021-11-16LibCrypto: Fix subtracting two negative `SignedBigInteger`sLinus Groh
Currently, we get the following results -1 - -2 = -1 -2 - -1 = 1 Correct would be: -1 - -2 = 1 -2 - -1 = -1 This was already attempted to be fixed in 7ed8970, but that change was incorrect. This directly translates to LibJS BigInts having the same incorrect behavior - it even was tested.
2021-11-11Everywhere: Pass AK::StringView by valueAndreas Kling
2021-09-07Everywhere: Behaviour => BehaviorAndreas Kling
2021-09-06LibCrypto: Add naive implementation of {Un,}SignedBigInteger::to_doubleIdan Horowitz
2021-07-19LibCrypto: Add operator<= and operator>= to SignedBigIntegerIdan Horowitz
2021-07-12LibCrypto: Add the >= operator to UnsignedBigIntegerIdan Horowitz
2021-07-09LibCrypto: Add missing implementation of SBI::divided_by(USBI)Linus Groh
2021-07-08LibCrypto: Add missing implementation of SBI::multiplied_by(USBI)Linus Groh
This only had a declaration and was creating linker errors when used. Easily fixed!
2021-07-07LibCrypto: Add operator>() to UnsignedBigInteger and SignedBigIntegerLinus Groh
Piggybacking on operator!=() and operator<().
2021-07-01LibCrypto: Replace incorrect operator in SignedBigInteger::bitwise_andGal Horowitz