Commit graph

30 commits

Author SHA1 Message Date
Pavel Shliak
8d13115d9a LibCrypto: Clean up #include directives
This change aims to improve the speed of incremental builds.
2024-11-21 14:08:33 +01:00
Timothy Flynn
93712b24bf Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
Andreas Kling
13d7c09125 Libraries: Move to Userland/Libraries/ 2021-01-12 12:17:46 +01:00
Andreas Kling
52b05a08c7 LibCrypto: Reduce use of ByteBuffer in AES code
Use Bytes/ReadonlyBytes more where possible.
2021-01-12 09:34:04 +01:00
Andreas Kling
8e20208dd6 LibTLS+LibCrypto: Replace a whole bunch of ByteBuffers with Spans 2020-12-19 18:29:13 +01:00
Luke
72abf3491b LibCrypto: Require intent parameter in CTR constructor
This was preventing clang from building.
2020-11-29 20:22:56 +01:00
AnotherTest
d3c52cef86 LibCrypto: Implement GCM mode 2020-11-14 10:18:54 +01:00
AnotherTest
b9822d606d LibCrypto: Templatise CTR<T> on the increment function 2020-11-14 10:18:54 +01:00
Ben Wiederhake
1c60ea235e LibCrypto: Do not silently ignore key size mismatch
Before, when the actually passed key was too long, the extra bytes were silently
ignored. This can lead to all sorts of trouble, so ... don't do that.

The original intention was maybe to support non-integer amounts of key bytes.
But that doesn't happen anyway with AES.
2020-08-28 11:36:57 +02:00
asynts
868bd2e43d LibCrypto: Call bytes() explicitly instead of implicitly.
This was a careless mistake.
https://github.com/SerenityOS/serenity/pull/3166#discussion_r471131732
2020-08-17 00:00:14 +02:00
asynts
fc276946fb Refactor: Use ReadonlyBytes instead of const ReadonlyBytes&. 2020-08-15 21:21:18 +02:00
asynts
fff581cd72 AK: Rename span() to bytes() when appropriate.
I originally defined the bytes() method for the String class, because it
made it obvious that it's a span of bytes instead of span of characters.

This commit makes this more consistent by defining a bytes() method when
the type of the span is known to be u8.

Additionaly, the cast operator to Bytes is overloaded for ByteBuffer and
such.
2020-08-15 21:21:18 +02:00
AnotherTest
bc7a149039 LibCrypto+LibTLS+Kernel: Switch the Cipher::Mode interface to use Span
This shaves 2.5 more runtime seconds off 'disasm /bin/id', and makes the
Mode<T> interface a lot more allocation-friendly.
2020-08-11 21:37:10 +02:00
Nico Weber
8d3d0054ed Crypto: Make AES call malloc much less often
ByteBuffer::slice_view() allocates a new ByteBuffer object,
which as a RefPtr and everything.

Nowadays it should probably return a Bytes / Span<u8>, but AES was only
using slice_view() to extract the pointer again.  So just add ady a
range check at the top, and do pointer arithmetic to do the same thing
faster.

Reduces time to run `disasm /bin/id` by a bit under 40%,
from ~8.3s to ~5s (min-of-3 runs).
2020-08-11 16:25:36 +02:00
Brian Gianforcaro
9572c95152 LibTLS + LibCrypto: Suppress unobserved Optoinal<T> return values. 2020-08-05 12:27:15 +02:00
Ben Wiederhake
a296020e03 LibCrypto: Implement and test CTR decryption 2020-07-28 19:10:10 +02:00
Ben Wiederhake
a51cbc2978 LibCrypto: Fix broken CTR mode, implement RFC 3686 Test Vectors 2020-07-28 19:10:10 +02:00
Ben Wiederhake
ef4ce54b02 LibCrypto: Document CTR weirdness in depth 2020-07-28 19:10:10 +02:00
Peter Elliott
2e8cfe5435 LibCrypto: Add CTR cipher mode
Kernel: Changed fortuna implementation to use CTR mode instead of
manually implementing a counter.
2020-06-25 21:05:40 +02:00
Peter Elliott
3de32f0a55 LibCrypto: Add missing <AK/StringView.h> include 2020-06-25 21:05:40 +02:00
AnotherTest
2a241a11bb LibCrypto: Fix some issues preventing compilation w/ clang 10 2020-05-29 20:17:12 +02:00
AnotherTest
d497521d2b LibCrypto: Format all files with clang-format 10 2020-05-29 20:17:12 +02:00
AnotherTest
3b432eed98 LibCrypto: Correct RFC5246 un-padding behaviour
The decrypted data is legally allowed to have any amount of padding, so
long as it is block-aligned, we should not assume that padding bytes
fall inside the same block, or that an entire block cannot be padding.

Fixes #2072
2020-05-03 11:46:40 +02:00
AnotherTest
4d932ce701 LibCrypto: Tweak ::prune_padding() to be more intuitive with loop bounds 2020-05-02 12:24:10 +02:00
AnotherTest
a1e1570552 LibCrypto+LibTLS: Generalise the use of IV length
This is in preparation for the upcoming Galois/Counter mode, which
conventionally has 12 bytes of IV as opposed to CBC's 16 bytes.

...Also fixes a lot of style issues, since the author finally found the
project's clang config file in the repository root :^)
2020-05-02 12:24:10 +02:00
AnotherTest
2247036acf LibTLS: Implement a preliminary version of the TLS protocol
TLS::TLSv12 is a Core::Socket, however, I think splitting that into a
TLS::Socket would probably be beneficial
2020-05-02 12:24:10 +02:00
AnotherTest
f1578d7e9e LibCrypto: Fix issues in the Crypto stack
This commit fixes up the following:
- HMAC should not reuse a single hasher when successively updating
- AES Key should not assume its user key is valid signed char*
- Mode should have a virtual destructor
And adds a RFC5246 padding mode, which is required for TLS
2020-05-02 12:24:10 +02:00
AnotherTest
f2cd004d11 LibCrypto: Implement HMAC 2020-05-02 12:24:10 +02:00
AnotherTest
4f89a377a4 LibCrypto: Move each subsection into its own namespace 2020-05-02 12:24:10 +02:00
AnotherTest
899ca245ae LibCrypto: Implement Cipher and AES_CBC
Also adds a test program to userland
2020-05-02 12:24:10 +02:00