Commit Graph

606 Commits

Author SHA1 Message Date
Linus Groh
22308e52cf AK: Add an ArbitrarySizedEnum template
This is an enum-like type that works with arbitrary sized storage > u64,
which is the limit for a regular enum class - which limits it to 64
members when needing bit field behavior.

Co-authored-by: Ali Mohammad Pur <mpfard@serenityos.org>
2022-03-27 18:54:56 +02:00
Michiel Visser
37da5cb3b3 LibCrypto: Correctly add length to SHA384 and SHA512 hashes
The SHA384 and SHA512 hashes would produce incorrect results for data
where the length % 128 was in the range 112-119. This was because the
total number of bits in the hashed values was added at the end as a
64-bit number instead of a 128-bit number. In most cases this would not
cause any issues, as this space was padded with zeroes, however in the
case that the length % 128 was 112-119, some incorrect data ended up
where this 128-bit length value was expected.

This change fixes the problems in LibTLS where some websites would
result in a DecryptError on handshake.
2022-03-26 02:25:23 +04:30
Kenneth Myhra
4a57be824c Userland+Tests: Convert File::read_link() from String to ErrorOr<String>
This converts the return value of File::read_link() from String to
ErrorOr<String>.

The rest of the change is to support the potential of an Error being
returned and subsequent release of the value when no Error is returned.
Unfortunately at this stage none of the places affected can utililize
our TRY() macro.
2022-03-24 11:57:51 +01:00
Brian Gianforcaro
97f622747b Everywhere: Move commonmark.spec.json to /home/anon/Tests 2022-03-20 22:20:59 +01:00
Brian Gianforcaro
67fc81a65a Everywhere: Move cpp-tests under /home/anon/Tests 2022-03-20 22:20:59 +01:00
Michiel Visser
596391a4ee LibCrypto: Add DH exchange for SECP256r1 to TestCurves 2022-03-20 00:51:50 +03:30
Michiel Visser
66d99c83d9 LibCrypto+LibTLS: Add SECP256r1 support to LibTLS
Add the required methods to SECP256r1 to conform to the EllipticCurve
virtual base class. Using this updated version of SECP256r1, support in
LibTLS is implemented.
2022-03-20 00:51:50 +03:30
Michiel Visser
c1b041e761 LibCrypto+LibTLS: Generalize the elliptic curve interface
These changes generalize the interface with an elliptic curve
implementation. This allows LibTLS to support elliptic curves generally
without needing the specifics of elliptic curve implementations.

This should allow for easier addition of other elliptic curves.
2022-03-20 00:51:50 +03:30
Sam Atkins
7e98c8eaf6 AK+Tests: Fix StringUtils::contains() being confused by repeating text
Previously, case-insensitively searching the haystack "Go Go Back" for
the needle "Go Back" would return false:

1. Match the first three characters. "Go ".
2. Notice that 'G' and 'B' don't match.
3. Skip ahead 3 characters, plus 1 for the outer for-loop.
4. Now, the haystack is effectively "o Back", so the match fails.

Reducing the skip by 1 fixes this issue. I'm not 100% convinced this
fixes all cases, but I haven't been able to find any cases where it
doesn't work now. :^)
2022-03-18 23:51:56 +00:00
Michiel Visser
8f7219c6fa LibCrypto: Implement the SECP256r1 elliptic curve
This implementation of the secp256r1 elliptic curve uses two techniques
to improve the performance of the operations.

1. All coordinates are stored in Jacobian form, (X/Z^2, Y/Z^3, Z), which
   removes the need for division operations during point addition or
   doubling. The points are converted at the start of the computation,
   and converted back at the end.

2. All values are transformed to Montgomery form, to allow for faster
   modular multiplication using the Montgomery modular multiplication
   method. This means that all coordinates have to be converted into
   this form, and back out of this form before returning them.
2022-03-18 07:56:47 +03:30
Linus Groh
9422ae9bb2 LibJS: Add infallible variant of VM::push_execution_context()
It makes no sense to require passing a global object and doing a stack
space check in some cases where running out of stack is highly unlikely,
we can't recover from errors, and currently ignore the result anyway.

This is most commonly in constructors and when setting things up, rather
than regular function calls.
2022-03-18 01:12:12 +01:00
Ali Mohammad Pur
8b50009e9b LibTest: Provide detailed per-file JSON output with --per-file
This makes test-js style runners dump out output in the same format as
libjs-test262's per-file output.
2022-03-16 15:44:52 +00:00
Brian Gianforcaro
390666b9fa AK: Add naive implementations of AK::timing_safe_compare
For security critical code we need to have some way of performing
constant time buffer comparisons.
2022-03-13 19:08:58 -07:00
Brian Gianforcaro
02b2f2787a Tests: Rename AK/TestMemMem.cpp to AK/TestMemory.cpp
Rename to create a new generic test group for the AK memory APIs.
2022-03-13 19:08:58 -07:00
Sam Atkins
82605e2dff Tests: Port TestHTMLTokenizer to Core::Stream 2022-03-10 12:04:22 -05:00
Sam Atkins
2b2ddee77c Tests: Port TestCommonmark to Core::Stream
This passes the same number of tests that it did before this change:
> Out of 652 tests, 273 passed and 379 failed.
2022-03-10 12:04:22 -05:00
Sam Atkins
7ff99c3972 Tests: Port test-wasm to Core::Stream 2022-03-10 12:04:22 -05:00
Sam Atkins
aca28f00de Tests: Port test-cpp-preprocessor to Core::Stream 2022-03-10 12:04:22 -05:00
Sam Atkins
5833c55389 Tests: Port test-cpp-parser to Core::Stream 2022-03-10 12:04:22 -05:00
Federico Guerinoni
0aed2f0f86 AK: Add reverse iterator as member 2022-03-09 17:16:28 +01:00
Federico Guerinoni
f34fff852b AK: Implement wrapper for reverse range for loop
Now it is possible to use range for loop in reverse mode for a
container.
```
	for (auto item : in_reverse(vector))
```
2022-03-09 17:16:28 +01:00
Federico Guerinoni
b0e74a3fd3 AK: Implement reverse iterator for Vector class 2022-03-09 17:16:28 +01:00
stelar7
0df7ad7493 LibCrypto: Add curve X448 2022-03-09 13:04:48 +03:30
Daniel Bertalan
ea52ba9fdc LibC: Set saved_str to null in strtok_r if no tokens were found
If we do not do this, the next call to strtok_r will start tokenizing
(and possibly modifying!) the memory pointed to by `saved_ptr`.
2022-03-08 23:30:47 +01:00
Tom
2f0e3da142 AK: Add IPv6Address class
This is the IPv6 counter part to the IPv4Address class and implements
parsing strings into a in6_addr and formatting one as a string. It
supports the address compression scheme as well as IPv4 mapped
addresses.
2022-03-08 23:05:44 +01:00
Tim Schumacher
8ebc749191 Tests: Include limits.h for PATH_MAX in realpath tests 2022-03-08 22:00:28 +01:00
Tim Schumacher
f748586393 Tests: Include limits.h for MB_LEN_MAX in wchar tests 2022-03-08 22:00:28 +01:00
Linus Groh
1422bd45eb LibWeb: Move Window from DOM directory & namespace to HTML
The Window object is part of the HTML spec. :^)
https://html.spec.whatwg.org/multipage/window-object.html
2022-03-08 00:30:30 +01:00
Matthew Olsson
73cf8205b4 LibPDF: Propagate errors in Parser and Document 2022-03-07 10:53:57 +01:00
Andreas Kling
455224d476 AK: Add test for unbounded HashTable capacity leak 2022-03-07 00:08:22 +01:00
Ali Mohammad Pur
4bd01b7fe9 Kernel: Add support for SA_SIGINFO
We currently don't really populate most of the fields, but that can
wait :^)
2022-03-04 20:07:05 +01:00
Peter Ross
34108547b6 AK: Print NaN and infinite numbers in PrintfImplementation 2022-03-02 11:40:37 +01:00
Peter Ross
6c06b70911 LibC: Set PRI[xX]8/PRI[xX]16 macros to x and X
Described in:
  <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/
    inttypes.h.html>

The macros were first added in a7a456002e,
but it is not clear why the PRIx16/32 macros were defined as 'b' & 'w'.
PrintfImplementation was never able to parse these values.
2022-03-02 11:40:37 +01:00
Timur Sultanov
ffbd630ca6 AK: Add tests for integer values formatting in printf 2022-02-28 14:08:24 +01:00
kleines Filmröllchen
98058f7efe AK: Add FixedPoint base 2 logarithm
The log base 2 is implemented using the binary logarithm algorithm
by Clay Turner (see the link in the comment)
2022-02-28 13:59:31 +01:00
kleines Filmröllchen
5d6e3441fe AK: Fix FixedPoint to integral comparisons
Add tests to ensure that the fixed point numbers compare correctly to
integrals
2022-02-28 13:59:31 +01:00
kleines Filmröllchen
5ce7c67e44 Tests: Test DisjointChunks with FixedArray 2022-02-27 00:11:14 +03:30
Andreas Kling
f2663f477f AK: Ignore whitespace while decoding base64
This matches how other implementations behave.

1% progression on ACID3. :^)
2022-02-25 19:54:13 +01:00
Ali Mohammad Pur
bed129a69f LibTest+Spreadsheet: Add some basic spreadsheet runtime behaviour tests
As there's a somewhat active development going on, let's keep the
expected behaviour under tests to make sure nothing blows up :^)
2022-02-23 03:17:12 +03:30
Andreas Kling
8b2499b112 LibWeb: Make document.write() work while document is parsing
This necessitated making HTMLParser ref-counted, and having it register
itself with Document when created. That makes it possible for scripts to
add new input at the current parser insertion point.

There is now a reference cycle between Document and HTMLParser. This
cycle is explicitly broken by calling Document::detach_parser() at the
end of HTMLParser::run().

This is a huge progression on ACID3, from 31% to 49%! :^)
2022-02-21 22:00:28 +01:00
Adam Hodgen
b6eaefa87d LibWeb: Fix 'Comment end state' in HTML Tokenizer
Also, update the expected hash in the LibWeb TestHTMLTokenizer
regression test.

This is due to the "This comment has a few too many dashes." comment
token being updated.
2022-02-21 16:31:45 +01:00
Ali Mohammad Pur
97a333608e LibRegex: Make codegen+optimisation for alternatives much faster
Just a little thinking outside the box, and we can now parse and
optimise a million copies of "a|" chained together in just a second :^)
2022-02-20 11:53:59 +01:00
Ali Mohammad Pur
4be7239626 LibRegex: Make parse_disjunction() consume all disjunctions in one frame
This helps us not blow up when too many disjunctions are chained togther
in the regex we're parsing.
Fixes #12615.
2022-02-20 11:53:59 +01:00
Ali Mohammad Pur
627bbee055 LibRegex: Allow quantifiers after quantifiable assertions
While quantifying assertions is very much meaningless, the specification
allows them with annex B's extended grammar for browsers, so read and
apply the quantifiers.
Fixes #12373.
2022-02-20 11:53:59 +01:00
Peter Ross
5b32b46ebc LibC: Do not write value when scanf assignment value is suppressed
This change has the positive side-effect of causing scanf to *segfault*
when a NULL pointer argument is passed to scanf.
e.g. sscanf(str, "%d", NULL);
2022-02-20 00:13:08 +03:30
Peter Ross
31079a56d7 LibC: Do not include suppressed assignments in scanf return value 2022-02-20 00:13:08 +03:30
stelar7
4daa5622fe LibCrypto: Add curve x25519 2022-02-18 12:34:23 +02:00
Sam Atkins
8260135d4d LibCore+Everywhere: Return ErrorOr from ConfigFile factory methods
I've attempted to handle the errors gracefully where it was clear how to
do so, and simple, but a lot of this was just adding
`release_value_but_fixme_should_propagate_errors()` in places.
2022-02-16 19:49:41 -05:00
Sam Atkins
4d5080388a LibCore+Tests: Add SeekableStream::truncate() 2022-02-16 19:49:41 -05:00
serenitydev
23c72c6728 AK: Fix userland parsing of rounded floating point numbers
Parse JSON floating point literals properly,
No longer throwing a SyntaxError when the decimal portion
of the number exceeds the capacity of u32.

Added tests to AK/TestJSON and LibJS/builtins/JSON/JSON.parse
2022-02-16 07:22:51 -05:00