summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCrypto
AgeCommit message (Collapse)Author
2021-06-09LibCrypto: Add hash methods to {Signed, Unsigned}BigIntegerIdan Horowitz
These just use hash the underlying bytes that make up the integer words
2021-05-31AK: Replace ByteBuffer::grow with resize()/ensure_capacity()Gunnar Beutner
Previously ByteBuffer::grow() behaved like Vector<T>::resize(). However the function name was somewhat ambiguous - and so this patch updates ByteBuffer to behave more like Vector<T> by replacing grow() with resize() and adding an ensure_capacity() method. This also lets the user change the buffer's capacity without affecting the size which was not previously possible. Additionally this patch makes the capacity() method public (again).
2021-05-31LibCrypto: Fix bound checks when reading bitmapsBen Wiederhake
This only affects malformed RSA keys. Instead of accepting and continuing with potentially broken pointers (and in ASAN, crashing), we now consider bitmaps malformed, and stop parsing. Found by OSS Fuzz: #31698, long-standing-bug: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=31698 Fun fact: The "if" only exists because of OSS Fuzz. 8cc279ed74dc0b16a187052d2454c26c8c6ecaf2
2021-05-19LibCrypto: Use the new return-from-Variant::visit() mechanismAli Mohammad Pur
And simplify the code _even further_!
2021-05-19LibCrypto: Make GCM movableDexesTTP
2021-05-19LibCrypto: Use AK::Variant in HashManagerDexesTTP
2021-05-19LibCrypto: Use AK::Variant in MultiHashDigestVariantDexesTTP
2021-05-19LibCrypto: Add the SHA-384 hash algorithmDexesTTP
This is a truncated version of SHA-512, so it was fairly trivial.
2021-05-17LibCrypto: Change static constexpr array to function local constexprLenny Maiorani
Problem: - Static variables take memory and can be subject to less optimization (https://serenityos.godbolt.org/z/7EYebr1aa) - This static variable is only used in 1 place. Solution: - Move the variable into the function and make it non-static.
2021-05-17Everywhere: Fix a bunch of typosLinus Groh
2021-05-17LibCrypto: Fix incorrectly constexpr variableLenny Maiorani
Problem: - Clang ToT reports an error because `digest_size` cannot be evaluated at compile-time. Solution: - Change from using the member function to the `static` shadow of the NTTP.
2021-05-14Userland: Replace arc4random() with get_random<u32>()Jean-Baptiste Boric
2021-05-14LibCrypto: Prevent a signed overflow during BigInt Modular PowerDexesTTP
The algorithm isn't explicit about what type this needs to be. But this passes all of the tests, so that's probably fine.
2021-05-14LibCrypto+LibTLS: Avoid unaligned reads and writesAli Mohammad Pur
This adds an `AK::ByteReader` to help with that so we don't duplicate the logic all over the place. No more `*(const u16*)` and `*(const u32*)` for anyone. This should help a little with #7060.
2021-05-14LibCrypto: Do not assume that the passed in IV is as long as a blockAli Mohammad Pur
Just take ReadonlyBytes instead of a raw pointer. Fixes #7072 (tested with the ASAN build fixed by #7060).
2021-05-13LibCrypto: Reduce the UnsignedBigInteger inline size to 32 wordsDexesTTP
We never really needed the 512 words in the first place, and this does reduce the stack allocations in montgomery modular power from 32Kb to a more manageable 2Kb :^) Note that the 32 words size doesn't provide any performance benefits or drawbacks compared to other values. All values seem to have equivalent performances (the tested values were 1, 2, 4, ..., 512). But since the previous value of 512 was definitely too big, let's reduce it for now!
2021-05-13LibCrypto: Add the montgomery modular power algorithmDexesTTP
This algorithm allows for much faster computations of modular powers (around a 5x-10x speedup of the Crypto test). However, it is only valid for odd modulo values, and therefore the old algorithm must be kept for computations involving even modulo values.
2021-05-13LibCrypto: Add a += operation to UnsignedBigIntegerAlgorithmsDexesTTP
This new operation is immediately used in several existing algorithms.
2021-05-13LibCrypto: Add the UnsignedBigInteger::Word aliasDexesTTP
This makes it clearer which variables are operating on words instead of directly operating on raw values.
2021-05-13LibCrypto: Split BigInteger operations into an Algorithms classDexesTTP
Since the operations are already complicated and will become even more so soon, let's split them into their own files. We can also integrate the NumberTheory operations that would better fit there into this class as well. This commit doesn't change behaviors, but moves the allocation of some variables into caller classes.
2021-05-13LibCrypto: Fix an out-of-bounds access in UnsignedBigIntegerDexesTTP
This is working fine for TLS because we have a big enough inline capacity, but in theory we could have crashed at any time even with our 512 words of inline capacity.
2021-05-13LibCrypto: Enable -Wvla for LibCryptoAli Mohammad Pur
Resolves part of #7071.
2021-05-13LibCrypto: Remove all uses of VLAsAli Mohammad Pur
This removes all uses of VLAs with either Vectors with inline capacity for the expected soft upper bound, or the occasional heap allocation.
2021-05-07LibCrypto: Fix a mistake in appendff() conversionAndreas Kling
2021-05-07LibCrypto: Convert StringBuilder::appendf() => AK::FormatAndreas Kling
2021-05-01Everywhere: Turn #if *_DEBUG into dbgln_if/if constexprGunnar Beutner
2021-04-29Everywhere: "indexes" => "indices"Andreas Kling
I've wasted a silly amount of time in the past fretting over which of these words to use. Let's just choose one and use it everywhere. :^)
2021-04-29Everywhere: Use "the SerenityOS developers." in copyright headersLinus Groh
We had some inconsistencies before: - Sometimes "The", sometimes "the" - Sometimes trailing ".", sometimes no trailing "." I picked the most common one (lowecase "the", trailing ".") and applied it to all copyright headers. By using the exact same string everywhere we can ensure nothing gets missed during a global search (and replace), and that these inconsistencies are not spread any further (as copyright headers are commonly copied to new files).
2021-04-25Everywhere: Remove empty line after function body opening curly braceLinus Groh
2021-04-22AK+Userland: Use mpfard@serenityos.org for my copyright headersAli Mohammad Pur
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-21Everywhere: Remove redundant inline keyword with constexprLenny Maiorani
Problem: - `constexpr` functions are additionally decorated with `inline` keyword. This is redundant since `constexpr` implies `inline`. Solution: - Remove redundancies.
2021-04-18LibCrypto: Avoid creating bools from anything except boolsAnotherTest
2021-04-18LibCrypto: Implement UTCTime and GeneralizedTime parsersAnotherTest
2021-04-18LibCrypo: Add an ASN.1/DER pretty-printerAnotherTest
It's much easier to debug things when we can actually *see* them :P
2021-04-18LibCrypto: Allow the user to override the DER read kind and classAnotherTest
This is useful for parsing non-universal types.
2021-04-18LibCrypto: Add the GeneralizedTime ASN.1 typeAnotherTest
2021-04-15Everything: Add `-Wnon-virtual-dtor` flagNicholas-Baron
This flag warns on classes which have `virtual` functions but do not have a `virtual` destructor. This patch adds both the flag and missing destructors. The access level of the destructors was determined by a two rules of thumb: 1. A destructor should have a similar or lower access level to that of a constructor. 2. Having a `private` destructor implicitly deletes the default constructor, which is probably undesirable for "interface" types (classes with only virtual functions and no data). In short, most of the added destructors are `protected`, unless the compiler complained about access.
2021-04-03LibCrypto: Avoid overly big allocs in intermediate ModularPower resultsAnotherTest
If we don't limit the sizes of the intermediate results, they will grow indefinitely, causing each iteration to take longer and longer (in both memcpy time, and algorithm runtime). While calculating the trimmed length is fairly expensive, it's a small cost to pay for uniform iteration times.
2021-03-12Everywhere: Remove klog(), dbg() and purge all LogStream usage :^)Andreas Kling
Good-bye LogStream. Long live AK::Format!
2021-03-08Everywhere: Remove unnecessary whitespace at the end of some lines.Emanuele Torre
2021-03-08LibCrypto: Fail with overflow when bitfield has too many unused bitsAnotherTest
There cannot be more unused bits than the entirety of the input. Found by OSS-Fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=31706#c1
2021-03-04LibCrypto: Use BitmapView instead of Bitmap::wrap()Andreas Kling
2021-02-26Everywhere: Remove a bunch of redundant 'AK::' namespace prefixesLinus Groh
This is basically just for consistency, it's quite strange to see multiple AK container types next to each other, some with and some without the namespace prefix - we're 'using AK::Foo;' a lot and should leverage that. :^)
2021-02-23Everywhere: Rename ASSERT => VERIFYAndreas Kling
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED) Since all of these checks are done in release builds as well, let's rename them to VERIFY to prevent confusion, as everyone is used to assertions being compiled out in release. We can introduce a new ASSERT macro that is specifically for debug checks, but I'm doing this wholesale conversion first since we've accumulated thousands of these already, and it's not immediately obvious which ones are suitable for ASSERT.
2021-02-14LibCrypto: Don't copy the prime test candidatesAnotherTest
This was copying a bunch of bigints for no reason.
2021-02-14LibCrypto: Make a better ASN.1 parserAnotherTest
And use it to parse RSA keys. As a bonus, this one shouldn't be reading out of bounds or messing with the stack (as much) anymore.
2021-02-14LibCrypto: memcmp() all bytes in UnsignedBigInteger::operator==Linus Groh
`length` is only the (trimmed) size of the word vector, so we have to multiply it with the size of each element to ensure all bytes are compared. Fixes #5335.
2021-02-08Everywhere: Replace dbgln<flag>(...) with dbgln_if(flag, ...)AnotherTest
Replacement made by `find Kernel Userland -name '*.h' -o -name '*.cpp' | sed -i -Ee 's/dbgln\b<(\w+)>\(/dbgln_if(\1, /g'`
2021-01-25Everywhere: Debug macros instead of constexpr.asynts
This was done with the following script: find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec sed -i -E 's/dbgln<debug_([a-z_]+)>/dbgln<\U\1_DEBUG>/' {} \; find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec sed -i -E 's/if constexpr \(debug_([a-z0-9_]+)/if constexpr \(\U\1_DEBUG/' {} \;