Commit graph

99 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
b94307583b LibCrypto: Add user-defined literals to convert numbers to a BigInt
It is much more convenient to define constants with:

    1000_bigint

Than with:

    Crypto::UnsignedBigInteger { 1000 }
2024-11-20 19:04:30 -05:00
Timothy Flynn
e236f1d2ae LibCrypto: Define UnsignedBigInteger::operator<=
We have all comparison operators except less-than-or-equal already.
2024-11-20 19:04:30 -05: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
asynts
843ebbd2c3 Everywhere: Replace a bundle of dbg with dbgln.
These changes are arbitrarily divided into multiple commits to make it
easier to find potentially introduced bugs with git bisect.
2021-01-11 21:49:29 +01:00
asynts
6fa42af567 Everywhere: Replace a bundle of dbg with dbgln.
These changes are arbitrarily divided into multiple commits to make it
easier to find potentially introduced bugs with git bisect.

The modifications in this commit were automatically made using the
following command:

    find . -name '*.h' -exec sed -i -E 's/dbg\(\) << ("[^"{]*");/dbgln\(\1\);/' {} \;
2021-01-11 21:49:29 +01:00
asynts
a410bb8fd5 Everywhere: Replace a bundle of dbg with dbgln.
These changes are arbitrarily divided into multiple commits to make it
easier to find potentially introduced bugs with git bisect.
2021-01-11 21:49:29 +01:00
asynts
938e5c7719 Everywhere: Replace a bundle of dbg with dbgln.
These changes are arbitrarily divided into multiple commits to make it
easier to find potentially introduced bugs with git bisect.Everything:

The modifications in this commit were automatically made using the
following command:

    find . -name '*.cpp' -exec sed -i -E 's/dbg\(\) << ("[^"{]*");/dbgln\(\1\);/' {} \;
2021-01-09 21:11:09 +01:00
Andreas Kling
7ed89703fe LibCrypto+LibJS: Fix broken subtraction of two negative signed bigints
Found by oss-fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=29326
2021-01-07 08:57:37 +01:00
Andreas Kling
d5600e966a LibTLS+LibCrypto: Remove all remaining uses of ByteBuffer::wrap() 2020-12-19 18:29:13 +01:00
Andreas Kling
a8dbfc3398 LibCrypto: Yet more ByteBuffer::wrap() removal. Not much left now! 2020-12-19 18:29:13 +01:00
Andreas Kling
f82b0a78ef LibTLS+LibCrypto: More ByteBuffer -> Span conversion 2020-12-19 18:29:13 +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
740089d24a LibCrypto: Move out 'VerificationConsistency' into its own header file 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
AnotherTest
34f8d55100 LibCrypto: Remove spammy ModPow debug log 2020-10-30 23:42:03 +01:00
Lenny Maiorani
d1fe6a0b53
Everywhere: Redundant inline specifier on constexpr functions (#3807)
Problem:
- `constexpr` functions are decorated with the `inline` specifier
  keyword. This is redundant because `constexpr` functions are
  implicitly `inline`.
- [dcl.constexpr], §7.1.5/2 in the C++11 standard): "constexpr
  functions and constexpr constructors are implicitly inline (7.1.2)".

Solution:
- Remove the redundant `inline` keyword.
2020-10-20 18:08:13 +02:00
Ben Wiederhake
ede5dbd7b3 Meta+LibC through LibHTTP: Make clang-format-10 clean
Why break at LibHTTP? Because "Meta+Libraries" would be insanely large,
and breaking between LibHTTP and LibJS makes the commits roughly evenly large.
2020-09-25 21:18:17 +02: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
10c6f062b3 AK: Add Endian.h header to replace NetworkOrdered.h. 2020-08-25 16:22:14 +02:00
Ben Wiederhake
23a43d10f3 LibCrypto: Don't cause errors when function unused
Any (future) program that includes this header would fail to compile, because the
private symbol 'kind_name' is defined, along with a bunch of code, but unused.

A good way to see this is by #include'ing LibCrypto/ASN1/ASN1.h in an unrelated
.cpp-file, for example Userland/md.cpp.

No other headers seem to have this problem.
2020-08-23 00:53:16 +02:00
Andreas Kling
d62a59d7b8 LibCrypto: Don't include <Libraries/...> 2020-08-17 18:05:35 +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
Andreas Kling
b503f74d25 LibCrypto: Fix MB => MiB build issue 2020-08-16 16:44:09 +02:00
Ben Wiederhake
b7589ff4b6 LibCrypto: Move large functions to cpp file
If they use up so much stack space, contain (sometimes several) loops, and take
a noticable amount of time anyway, then 'inline' is probably going to be ignored
by the compiler anyway.
2020-08-16 16:35:23 +02:00
Ben Wiederhake
bbed5b99fd LibCrypto: Fix random generation and primality tests
It was quite silly that LibCrypto thought that 30! is a prime number! :P
2020-08-16 16:35:23 +02:00
Ben Wiederhake
67b24cb3a6 LibCrypto: Document word order (endianness) of bigint 2020-08-16 16:35:23 +02:00
Ben Wiederhake
d33e3b7d8a LibCrypto: Fix random number generation 2020-08-16 16:35:23 +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
AnotherTest
e54a5b7fb8 LibCrypto: Format the comments in ASN1/PEM.h correctly 2020-08-02 18:57:51 +02:00
AnotherTest
b00ffc860b LibCrypto: Do not trim leading zeros in export_data by default
This fixes the issue with the exported data having a leading zero,
causing RSA::encrypt to trim the block down, and ruining the encryption.

Fixes #2691 :^)
2020-07-31 18:25:20 +02:00
stelar7
dad22c5d5a LibCrypto: Add some checksum algorithms
Namely CRC32 and Adler32
2020-07-30 17:08:19 +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
Ben Wiederhake
708164b0b9 LibCrypto: Already using strong crypto
ModularFunctions::random_number calls into AK::fill_with_random calls (on
Serenity) into arc4random_buf calls into Process::sys calls into
get_good_random_bytes, which is cryptographically secure.
2020-07-28 19:10:10 +02:00
asynts
ed327e7feb LibCrypto: Change the signatures of RSA::import_[XXX]_key to use Span. 2020-07-27 19:58:09 +02:00
asynts
3de4e08b46 LibCrypto: Change the signature of decode_pem to use Span. 2020-07-27 19:58:09 +02:00
asynts
0d782e1dfb LibCrypto: Change the signature of RSA::parse_rsa_key to use Span. 2020-07-27 19:58:09 +02:00
asynts
4709b700bd LibCrypto: Change [XXX]BigInteger::export_data() to use Span. 2020-07-27 19:58:09 +02:00
asynts
68cf22d580 LibCrypto: This method wrote to a const pointer. 2020-07-27 19:58:09 +02:00
Tom
3fdacef07f LibCrypto: Optimize UnsignedBigInteger import_data/export_data
No need to do complicated math to import or export numbers,
just convert the byte stream to words and vice versa.
2020-07-25 12:53:02 +02:00