Commit graph

217 commits

Author SHA1 Message Date
stelar7
73ef102b01 LibCrypto: Add Chacha20Poly1305 2023-09-26 13:22:04 +03:30
implicitfield
1b3ad1c721 LibCrypto: Add support for BLAKE2b 2023-09-17 16:49:35 +03:30
kleines Filmröllchen
fb37587efe LibCrypto: Implement a generic 16-bit CRC
This is mostly a 16-bit version of the 8-bit CRC, using the same general
byte-LUT algorithm.
2023-08-12 12:25:26 -06:00
Lucas CHOLLET
3f35ffb648 Userland: Prefer _string over _short_string
As `_string` can't fail anymore (since 3434412), there are no real
benefits to use the short variant in most cases.
2023-08-08 07:37:21 +02:00
Nico Weber
492962502f LibCrypto: Make create_aligned_buffer() static
I ended up not needing this, but there's no reason for this function
to not be static.
2023-07-19 21:26:55 +01:00
Nico Weber
66e210e406 Everywhere: Use nested namespace qualifiers 2023-07-12 10:05:42 +03:30
Timothy Flynn
996c020b0d Everywhere: Remove 'clang-format off' comments that are no longer needed 2023-07-08 10:32:56 +01:00
Timothy Flynn
c911781c21 Everywhere: Remove needless trailing semi-colons after functions
This is a new option in clang-format-16.
2023-07-08 10:32:56 +01:00
Timothy Flynn
aff81d318b Everywhere: Run clang-format
The following command was used to clang-format these files:

    clang-format-16 -i $(find . \
        -not \( -path "./\.*" -prune \) \
        -not \( -path "./Base/*" -prune \) \
        -not \( -path "./Build/*" -prune \) \
        -not \( -path "./Toolchain/*" -prune \) \
        -not \( -path "./Ports/*" -prune \) \
        -type f -name "*.cpp" -o -name "*.h")
2023-07-08 10:32:56 +01:00
Liav A
490856453d Kernel: Move Random.{h,cpp} code to Security subdirectory 2023-06-04 21:32:34 +02:00
Ben Wiederhake
968f2b3eeb LibCrypto: Don't return reference to stack frame in PBKDF
A reference to the current stack frame becomes invalid after returning,
so returning Bytes is pointless.

I don't understand why this wasn't discovered earlier, but it caused
some CI problems for me, so I fixed it.

Don't take this as encouragement to break master! :^)
2023-06-01 21:22:14 +02:00
Daniel Bertalan
12a2f741a7 LibCrypto: Add workaround for false -Warray-bounds warning
When building for AArch64 with UBSan enabled, GCC 13.1 reports a false
"array out of bounds" error on access to offset `1 * sizeof(u64)`.
Changing the order of the stores seems to silence it.
2023-05-28 05:05:09 -06:00
kleines Filmröllchen
70ab4566f3 LibCrypto: Add a checksumming stream wrapper
This generic stream wrapper performs checksum calculations on all data
passed through it for reading or writing, and is therefore convenient
for calculating checksums while performing normal data input/output, as
well as computing streaming checksums on non-seekable streams.
2023-05-18 22:23:15 +02:00
kleines Filmröllchen
daf50ed885 LibCrypto: Add generic 8-bit CRC
The implementation of this is naive enough so it can handle all 8-bit
CRC polynomials, of which there are quite a few. The table generation
and update procedure is MSB first, which is backwards from the LSB first
method of CRC32.
2023-05-18 22:23:15 +02:00
kleines Filmröllchen
4f9c91e34d LibCrypto: Expose checksum type of ChecksumFunction 2023-05-18 22:23:15 +02:00
Ben Wiederhake
ac5cef1b66 LibCrypto+LibTLS: Avoid crashing on invalid input
Fixes #18307.
2023-05-08 06:43:28 +02:00
stelar7
0b70314379 LibCrypto: Store the TBS ASN.1 data on the certificate
This way we dont need to guess the offsets in LibTLS when using it.
2023-05-05 09:36:43 +03:30
stelar7
4043c89310 LibTLS: Change CertificateKeyAlgorithm from enum to struct 2023-04-15 09:03:47 +03:30
Tim Ledbetter
72ea046b68 AK: Add option to the string formatter to use a digit separator
`vformat()` can now accept format specifiers of the form
{:'[numeric-type]}. This will output a number with a comma separator
every 3 digits.

For example:

`dbgln("{:'d}", 9999999);` will output 9,999,999.

Binary, octal and hexadecimal numbers can also use this feature, for
example:

`dbgln("{:'x}", 0xffffffff);` will output ff,fff,fff.
2023-04-11 13:03:30 +02:00
stelar7
371974ed4a LibCrypto: Add PBKDF2 2023-04-09 17:05:18 -06:00
Ben Wiederhake
560133a0c6 Everywhere: Remove unused DeprecatedString includes 2023-04-09 22:00:54 +02:00
stelar7
b1d80b35af LibCrypto: Add ability to rewrite current tag kind
This is used for IMPLICIT tags where the expected kind is overriden
by the encoding instructions.
2023-04-06 09:57:31 +03:30
stelar7
8273fc230c LibCrypto: Add missing ASN1 tag kinds 2023-04-06 09:57:31 +03:30
Fabian Dellwing
8b881eaf02 LibCrypto: Add PEM encoder
This commit adds a new method to create a PEM encoded ASN1 from
its DER variant.
2023-04-03 19:58:47 -06:00
Timothy Flynn
15532df83d AK+Everywhere: Change AK::fill_with_random to accept a Bytes object
Rather than the very C-like API we currently have, accepting a void* and
a length, let's take a Bytes object instead. In almost all existing
cases, the compiler figures out the length.
2023-04-03 15:53:49 +02:00
Timothy Flynn
62b575ad7c LibCrypto: Implement little endian CRC using the slicing-by-8 algorithm
This implements Intel's slicing-by-8 algorithm for CRC checksums (only
little endian CPUs for now, as I don't have a way to test big endian).

The original paper for this algorithm seems to have disappeared, but
Intel's source code is still available as a reference:

    https://sourceforge.net/projects/slicing-by-8/

As well as other implementations for reference:

    https://docs.rs/slice-by-8/latest/src/slice_by_8/algorithm.rs.html

Using the "enwik8" file as a test (100MB uncompressed, commonly used in
benchmarks: https://www.mattmahoney.net/dc/enwik8.zip), decompression
time decreases from:

    4.89s to 3.52s on Serenity (cold)
    1.72s to 1.32s on Serenity (warm)
    1.06s to 0.92s on Linux
2023-03-31 06:56:05 +02:00
Nico Weber
29796f8f5e LibCrypto: Use 8-byte crc32 instruction on arm too
Takes

    % time Build/lagom/gunzip -c \
        /Users/thakis/Downloads/trace_bug.json.gz > /dev/null

from 3.9s to 3.87s.
2023-03-25 21:42:50 +00:00
Nico Weber
0452a8ed4b LibCrypto: Start sometimes hardware-accelerating crc32
Takes

    % time Build/lagom/gunzip -c \
        /Users/thakis/Downloads/trace_bug.json.gz > /dev/null

from 4s to 3.9s on my MBP.
2023-03-25 21:42:50 +00:00
Jelle Raaijmakers
ea9707ec29 LibCrypto: Update entire blocks in SHA*::update()
Instead of going byte by byte, copy entire blocks at once and only check
if we need to update the state once per block. This pretty much
eliminates `::update()` from profiles and measurably improves
performance for utilities like `sha256sum`.
2023-03-24 15:28:10 +00:00
Jelle Raaijmakers
88b0b80aab LibCrypto: Stop shadowing i variable 2023-03-24 15:28:10 +00:00
Fabian Dellwing
06340ca674 LibCrypto: Add multiple PEM parser
This adds a function to parse multiple PEMs out of a single input.
This allows us to load certificates from a cacert.pem file without
need for preprocessing.
2023-03-16 18:54:20 +03:30
Tim Schumacher
ecd1862859 AK: Rename Stream::write_entire_buffer to Stream::write_until_depleted
No functional changes.
2023-03-13 15:16:20 +00:00
Dan Klishch
8f8e31e780 AK+LibCrypto: Delete 64x64 wide multiplication workarounds
Now UFixedBigInt exposes API to do wide multiplications of this kind
efficiently.
2023-03-04 22:10:03 -07:00
Linus Groh
09d40bfbb2 Everywhere: Use _{short_,}string to create Strings from literals 2023-02-25 20:51:49 +01:00
Tim Schumacher
43f98ac6e1 Everywhere: Remove the AK:: qualifier from Stream usages 2023-02-13 00:50:07 +00:00
Timothy Flynn
4a916cd379 Everywhere: Remove needless copies of Error / ErrorOr instances
Either take the underlying objects with release_* methods or move() the
instances around.
2023-02-10 09:08:52 +00:00
Tim Schumacher
a6bcad551d LibCrypto: Use AK::Stream for pretty printing DER 2023-02-08 18:50:53 +00:00
Tim Schumacher
f5fb1396e8 LibCrypto: Use ErrorOr error handling for parsing DER
This replaces a mixture of `Result`, `Optional`, and a custom error enum
with our usual `ErrorOr`-based error handling.
2023-02-08 18:50:53 +00:00
Tim Schumacher
7d70f6d7c8 LibCrypto: Do a simple copy for buffered GHash bytes
Using a Stream to copy over a single span is kind of overkill.
2023-02-08 17:53:19 +00:00
Tim Schumacher
ae64b68717 AK: Deprecate the old AK::Stream
This also removes a few cases where the respective header wasn't
actually required to be included.
2023-01-29 19:16:44 -07:00
Linus Groh
6e7459322d AK: Remove StringBuilder::build() in favor of to_deprecated_string()
Having an alias function that only wraps another one is silly, and
keeping the more obvious name should flush out more uses of deprecated
strings.
No behavior change.
2023-01-27 20:38:49 +00:00
Sam Atkins
b5a3600bc7 LibCrypto: Remove declarations for non-existent methods 2023-01-27 20:33:18 +00:00
Timothy Flynn
f1de4f8872 Everywhere: Convert known short-strings to the infallible String factory
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-20 14:24:12 -05:00
Timothy Flynn
3ad1f250e7 LibCrypto: Define *BigInteger::to_base to convert big integers to String 2023-01-15 01:00:20 +00:00
Timothy Flynn
0ddc2e1f50 LibCrypto+Everywhere: Rename *BigInteger::to_base to to_base_deprecated 2023-01-15 01:00:20 +00:00
Nico Weber
a03d42b098 LibCrypto: Use default Crypto::Hash::Digest comparison operators
They do the same thing we previously laboriously did manually.
No behavior change.
2023-01-06 23:57:46 +01:00
Nico Weber
fafacbb87b LibCrypto: Add equality operators for Crypto::Hash::Digest<> 2023-01-05 10:54:35 +01:00
Nico Weber
c10a02c405 LibCrypto: Add a Formatter for Crypto::Hash::Digest<> 2023-01-05 10:54:35 +01:00
Nico Weber
1fe3ba17c0 LibCrypto: Use nested namespace specifiers in Hash/ 2023-01-05 10:54:35 +01:00
Nico Weber
0a3cc10bb6 Everywhere: Remove some redundant inline keywords
Functions defined inside class bodies (including static functions)
are implicitly inline, no need to type it out.
2023-01-04 20:04:57 +01:00