summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCrypto
AgeCommit message (Collapse)Author
2022-03-22LibCrypto: Fix grammar in a couple of commentsLinus Groh
2022-03-20LibCrypto: Move all elliptic curve private methods into .cppMichiel Visser
All the elliptic curve implementations had a long list of private methods which were all stored in a single .cpp file. Now we simply use static methods instead.
2022-03-20LibCrypto+LibTLS: Add SECP256r1 support to LibTLSMichiel Visser
Add the required methods to SECP256r1 to conform to the EllipticCurve virtual base class. Using this updated version of SECP256r1, support in LibTLS is implemented.
2022-03-20LibCrypto+LibTLS: Generalize the elliptic curve interfaceMichiel Visser
These changes generalize the interface with an elliptic curve implementation. This allows LibTLS to support elliptic curves generally without needing the specifics of elliptic curve implementations. This should allow for easier addition of other elliptic curves.
2022-03-18LibCrypto: Implement the SECP256r1 elliptic curveMichiel Visser
This implementation of the secp256r1 elliptic curve uses two techniques to improve the performance of the operations. 1. All coordinates are stored in Jacobian form, (X/Z^2, Y/Z^3, Z), which removes the need for division operations during point addition or doubling. The points are converted at the start of the computation, and converted back at the end. 2. All values are transformed to Montgomery form, to allow for faster modular multiplication using the Montgomery modular multiplication method. This means that all coordinates have to be converted into this form, and back out of this form before returning them.
2022-03-13LibCrypto: Use AK::timing_safe_compare to validate sensitive dataBrian Gianforcaro
Addresses one FIXME in GCM, and another similar issue in EMSA_PSS. We should be using constant time memory comparisons in all of our crypto code.
2022-03-10Libraries: Use default constructors/destructors in LibCryptoLenny Maiorani
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules "The compiler is more likely to get the default semantics right and you cannot implement these functions better than the compiler."
2022-03-09LibCrypto: Add curve X448stelar7
2022-02-26LibCrypto: Simplify and move CRC32 table to cpp fileLenny Maiorani
CRC32 table is generated at compile-time and put into a static variable in the header file. This can be moved to be a function instead of a class, be moved to the `.cpp` file` and generated as an array instead of a class which only implements `operator[]`.
2022-02-23LibTLS: Add signature verification for DHE and ECDHE key exchangeMichiel Visser
This will verify that the signature of the ephemeral key used in the DHE and ECDHE key exchanges is actually generated by the server. This verification is done using the first certificate provided by the server, however the validity of this certificate is not checked here. Instead this code expects the validity to be checked earlier by `TLSv12::handle_certificate`.
2022-02-23LibCrypto: Add EMSA-PKCS1-V1_5 encoder and verificationMichiel Visser
This add an implementation for the EMSA-PKCS1-V1_5-ENCODE function from RFC8017 section 9.2. The verification of this encoding is implemented by simply encoding the message to be verified, and then comparing the two encoded string. The digest info for the different hash function is from RFC8017 section 9.2 notes 1. These byte sequences are actually ASN.1 encoded data, however these are always constant for a specific hash function and can be treated as opaque byte sequences.
2022-02-18LibCrypto: Add curve x25519stelar7
2022-02-16LibCrypto: Exclude class_name() methods from the KernelIdan Horowitz
These are only used by Userland and contain infallible String allocations, so let's just ifdef them out of the Kernel.
2022-02-16LibCrypto: Exclude AESCipher{Block, Key}::to_string() from the KernelIdan Horowitz
These use infallible Strings and are not actually used in the Kernel, so let's just ifdef them out for now.
2022-02-06LibCrypto: Do not allow signed big integers to be negative zeroTimothy Flynn
If a big integer were to become negative zero, set the sign to instead be positive. This prevents odd scenarios where users of signed big ints would falsely think the result of some big int arithmetic is negative.
2022-01-31LibCrypto: Change UnsignedBigInteger parser to use a StringViewTimothy Flynn
SignedBigInteger already accepts a StringView; let's avoid the heap allocation in UnsignedBigInteger.
2022-01-28Userland: Remove a bunch of unnecessary Vector importskleines Filmröllchen
How silly :^)
2022-01-24AK+Userland: Make AK::decode_base64 return ErrorOrSam Atkins
2022-01-24Everywhere: Convert ByteBuffer factory methods from Optional -> ErrorOrSam Atkins
Apologies for the enormous commit, but I don't see a way to split this up nicely. In the vast majority of cases it's a simple change. A few extra places can use TRY instead of manual error checking though. :^)
2022-01-18LibCrypo: Simplify mixed-sign bitwise_orNico Weber
No behavior change.
2022-01-18LibCrypto: Remove some now-unused (and incorrect) methodsNico Weber
Removes the UnsignedBigInteger overloads of SignedBigInteger::binary_{and,or,xor}(). They're now unused, and they also didn't work when *this was negative.
2022-01-18LibCrypto+LibJS: Better bitwise binary_xor binopNico Weber
We went through some trouble to make & and | work right. Reimplement ^ in terms of & and | to make ^ work right as well. This is less fast than a direct implementation, but let's get things working first.
2022-01-18LibCrypto+LibJS: Better bigint bitwise_or binopNico Weber
Similar to the bitwise_and change, but we have to be careful to sign-extend two's complement numbers only up to the highest set bit in the positive number.
2022-01-18LibCrypto+LibJS: Better bigint bitwise_and binopNico Weber
Bitwise and is defined in terms of two's complement, so some converting needs to happen for SignedBigInteger's sign/magnitude representation to work out. UnsignedBigInteger::bitwise_not() is repurposed to convert all high-order zero bits to ones up to a limit, for the two's complement conversion to work. Fixes test262/test/language/expressions/bitwise-and/bigint.js.
2022-01-18LibJS+LibCrypto: Fix SignedBitInteger::bitwise_not and use it in LibJSNico Weber
Bitwise operators are defined on two's complement, but SignedBitInteger uses sign-magnitude. Correctly convert between the two. Let LibJS delegate to SignedBitInteger for bitwise_not, like it does for all other bitwise_ operations on bigints. No behavior change (LibJS is now the only client of SignedBitInteger::bitwise_not()).
2022-01-18LibCrypto: Add Formatter<SignedBigInteger>Nico Weber
Useful for seeing SignedBigInteger values in test failure messages.
2022-01-09LibCrypto: Link against LibCoreDaniel Bertalan
The ASN1 parser calls `LibCore::DateTime::create` and `LibCore::DateTime::now`.
2022-01-07Everywhere: Fix spelling mistakesmjz19910
2022-01-07Everywhere: Fix many spelling errorsmjz19910
2022-01-05LibCrypto: Make `Digest`s able to return `bytes`Michel Hermier
2022-01-05LibCrypto: Mutualize `Digest`sMichel Hermier
2022-01-05LibCrypto: Make `MultiHashDigestVariant` getters `const` and `nodiscard`Michel Hermier
2022-01-05LibCrypto: Remove spurious `;`Michel Hermier
2021-12-24LibCrypto: Remove redundant __builtin_memset() callDaniel Bertalan
This call caused GCC 12's static analyzer to think that we perform an out-of-bounds write to the v_key Vector. This is obviously incorrect, and comes from the fact that GCC doesn't properly track whether we use the inline storage, or the Vector is allocated on the heap. While searching for a workaround, Sam pointed out that this call is redundant as `Vector::resize()` already zeroes out the elements, so we can completely remove it. Co-authored-by: Sam Atkins <atkinssj@serenityos.org>
2021-12-22LibCrypto: Add the BigInteger conceptLinus Groh
This makes it much easier to write (template) functions that accept either a signed or unsigned bigint parameter.
2021-12-21AK+Everywhere: Replace __builtin bit functionsNick Johnson
In order to reduce our reliance on __builtin_{ffs, clz, ctz, popcount}, this commit removes all calls to these functions and replaces them with the equivalent functions in AK/BuiltinWrappers.h.
2021-12-17LibCrypto: Declobber AES header from s-box tablesAlexander Ulmer
2021-12-11Everywhere: Fix -Winconsistent-missing-override warnings from ClangDaniel Bertalan
This option is already enabled when building Lagom, so let's enable it for the main build too. We will no longer be surprised by Lagom Clang CI builds failing while everything compiles locally. Furthermore, the stronger `-Wsuggest-override` warning is enabled in this commit, which enforces the use of the `override` keyword in all classes, not just those which already have some methods marked as `override`. This works with both GCC and Clang.
2021-11-17AK: Convert AK::Format formatting helpers to returning ErrorOr<void>Andreas Kling
This isn't a complete conversion to ErrorOr<void>, but a good chunk. The end goal here is to propagate buffer allocation failures to the caller, and allow the use of TRY() with formatting functions.
2021-11-16LibCrypto: Fix subtracting two negative `SignedBigInteger`sLinus Groh
Currently, we get the following results -1 - -2 = -1 -2 - -1 = 1 Correct would be: -1 - -2 = 1 -2 - -1 = -1 This was already attempted to be fixed in 7ed8970, but that change was incorrect. This directly translates to LibJS BigInts having the same incorrect behavior - it even was tested.
2021-11-11Userland: Include Vector.h in a few places to make HeaderCheck happyAli Mohammad Pur
This header was being transitively pulled in, but that no longer happens after 5f7d008791f9e358638283dc2f0d709a601344ff.
2021-11-11LibCrypto: Pass AK::Bytes by valueAndreas Kling
2021-11-11Everywhere: Pass AK::ReadonlyBytes by valueAndreas Kling
2021-11-11Everywhere: Pass AK::StringView by valueAndreas Kling
2021-11-10AK: Make ByteBuffer::try_* functions return ErrorOr<void>Andreas Kling
Same as Vector, ByteBuffer now also signals allocation failure by returning an ENOMEM Error instead of a bool, allowing us to use the TRY() and MUST() patterns.
2021-11-10Everywhere: Remove unused AK/Bitmap includesBen Wiederhake
2021-10-23AK+Everywhere: Make Base64 decoding fallibleBen Wiederhake
2021-10-06LibCrypto: Add missing header to EMSA_PSS.hBen Wiederhake
2021-09-21Libraries: Use AK::Variant default initialization where appropriateBen Wiederhake
2021-09-16LibCrypto: Use default instead of an empty constructor/destructorBrian Gianforcaro
Default implementations allow for more optimizations. See: https://pvs-studio.com/en/docs/warnings/v832/