Commit Graph

88 Commits

Author SHA1 Message Date
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
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
02c53fd1f9 LibCrypto: Add bitwise operations (and/or/xor) 2020-06-07 19:29:40 +02:00
Linus Groh
fbb1d9afe5 LibCrypto: Make ModularFunctions.h compile as part of Lagom
Compiler was complaining about two ambiguous overloads.

Also make some functions "inline" to fix warnings about unused
functions.
2020-06-07 19:29:40 +02:00
Linus Groh
75b4cc13a0 LibCrypto: Fix to_base10() for zero-value BigIntegers
All the magic is happening in a "while != 0" loop, so we ended up with
an empty string for zero-value BigIntegers. Now we just check that
upfront and return early.
2020-06-07 19:29:40 +02:00
AnotherTest
d8208fd37c LibCrypto: Add a simple SignedBigInteger
This patchset adds a simple SignedBigInteger that is entirely defined in
terms of UnsignedBigInteger.

It also adds a NumberTheory::Power function, which is terribly
inefficient, but since the use of exponentiation is very much
discouraged for large inputs, no particular attempts were made
to make it more performant.
2020-06-05 13:29:44 +02:00
AnotherTest
63cc2f58ea LibCrypto: Correctly pad blocks with FinalBlockSize < size < BlockSize
This fixes #2488
2020-06-04 15:58:04 +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
Emanuele Torre
937d0be762 Meta: Add a script check the presence of "#pragma once" in header files
.. and make travis run it.

I renamed check-license-headers.sh to check-style.sh and expanded it so
that it now also checks for the presence of "#pragma once" in .h files.

It also checks the presence of a (single) blank line above and below the
"#pragma once" line.

I also added "#pragma once" to all the files that need it: even the ones
we are not check.
I also added/removed blank lines in order to make the script not fail.

I also ran clang-format on the files I modified.
2020-05-29 07:59:45 +02:00
Andreas Kling
c1dd67e792 LibCrypto+LibTLS: Use AK/Random.h
This makes it possible to build both of these on Linux.
2020-05-27 12:28:17 +02:00