summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCrypto
AgeCommit message (Collapse)Author
2022-11-03AK+LibC+LibCrypto: Move FloatExtractor to AK/FloatingPoint.hDan Klishch
2022-11-02LibCrypto: Add a way to compare UnsignedBigInteger with doubleMoustafa Raafat
This patch also make SignedBigInteger::compare_to_double make use of the new function.
2022-11-01Everywhere: Mark dependencies of most targets as PRIVATETim Schumacher
Otherwise, we end up propagating those dependencies into targets that link against that library, which creates unnecessary link-time dependencies. Also included are changes to readd now missing dependencies to tools that actually need them.
2022-11-01Everywhere: Explicitly link all binaries against the LibC targetTim Schumacher
Even though the toolchain implicitly links against -lc, it does not know where it should get LibC from except for the sysroot. In the case of Clang this causes it to pick up the LibC stub instead, which might be slightly outdated and feature missing symbols. This is currently not an issue that manifests because we pass through the dependency on LibC and other libraries by accident, which causes CMake to link against the LibC target (instead of just the library), and thus points the linker at the build output directory. Since we are looking to fix that in the upcoming commits, let's make sure that everything will still be able to find the proper LibC first.
2022-10-22LibCrypto: Add SignedBigInteger::is_positive()Moustafa Raafat
2022-09-16Everywhere: Remove a bunch of dead write-only variablesTim Schumacher
LLVM 15 now warns (and thus errors) about this, and there is really no point in keeping them.
2022-09-15LibCrypto: Fix -0 and 0 non-equalityLucas CHOLLET
SignedBigInteger::operator==(const UnsignedBigInteger&) was rejecting all negative value before testing for equality. It now accepts negative zero and test for a value equality with the UnsignedBigInteger.
2022-09-15LibCrypto: Add BigFractionLucas CHOLLET
This new abstraction allows the user to store rational numbers with infinite precision.
2022-09-15LibCrypto: Add SignedBigInteger::negated_value()Lucas CHOLLET
Return the negated value of the current number.
2022-09-14Everywhere: Fix a variety of typosBrian Gianforcaro
Spelling fixes found by `codespell`.
2022-08-26LibCrypto+LibJS: Remove the create_from methods from BigIntegerdavidot
Instead we just use a specific constructor. With this set of constructors using curly braces for constructing is highly recommended. As then it will not do too many implicit conversions which could lead to unexpected loss of data or calling the much slower double constructor. Also to ensure we don't feed (Un)SignedBigInteger infinities we throw RangeError earlier for Durations.
2022-08-26LibCrypto: Add a constructor to (Un)SignedBigInteger taking a doubledavidot
For now this will assume that the double given is exactly representable as an integer, so no NaN, infinity or rounding.
2022-08-26LibCrypto: Make the constructors of (Un)SignedBigInteger templateddavidot
This means it can take any (un)signed word of size at most Word. This means the constructor can be disambiguated if we were to add a double constructor :^). This requires a change in just one test.
2022-08-26LibCrypto: Add a rounding mode to UnsignedBigInteger::to_doubledavidot
This allows using different options for rounding, like IEEE roundTiesToEven, which is the mode that JS requires. Also fix that the last word read from the bigint for the mantissa could be shifted incorrectly leading to incorrect results.
2022-08-24LibCrypto: Implement a (mostly) proper to_double for UnsignedBigIntegerdavidot
SignedBigInteger can immediately use this by just negating the double if the sign bit is set. For simple cases (below 2^53) we can just convert via an u64, however above that we need to extract the top 53 bits and use those as the mantissa. This function currently does not behave exactly as the JS spec specifies however it is much less naive than the previous implementation.
2022-08-24LibCrypto: Make a VERIFY a static_assert since it only uses constantsdavidot
2022-08-24LibCrypto: Add a way to compare a SignedBigInteger with a doubledavidot
This supports any double value (except for NaNs) instead of having to cast the double to some smaller type which doesn't work for very large values.
2022-07-18LibCrypto: Expose UnsignedBigInteger's is_zero() in SignedBigIntegerTimothy Flynn
Note we don't need to check the sign because negative zero became disallowed in b0d6399f60760e25a55ec9e8e95a1ad322b74b22.
2022-07-12Everywhere: Add sv suffix to strings relying on StringView(char const*)sin-ack
Each of these strings would previously rely on StringView's char const* constructor overload, which would call __builtin_strlen on the string. Since we now have operator ""sv, we can replace these with much simpler versions. This opens the door to being able to remove StringView(char const*). No functional changes.
2022-07-12Meta+Userland: Simplify some formatterssin-ack
These are mostly minor mistakes I've encountered while working on the removal of StringView(char const*). The usage of builder.put_string over Format<FormatString>::format is preferrable as it will avoid the indirection altogether when there's no formatting to be done. Similarly, there is no need to do format(builder, "{}", number) when builder.put_u64(number) works equally well. Additionally a few Strings where only constant strings were used are replaced with StringViews.
2022-07-09LibCrypto: Add the [[nodiscard]] qualifier in both BigInteger classesLucas CHOLLET
2022-05-12LibCrypto: Add Ed25519stelar7
2022-05-12LibCrypto: Move Curve25519 related code into separate filestelar7
2022-04-17LibCrypto: Implement custom BitStringView for ASN.1 decoderMichiel Visser
The ASN.1 decoder was originally using AK::BitmapView for decoded BitStrings, however the specification requires that the bits are stored in a byte from the most significant to the least significant. Storing three bits '110' would result in a byte '1100 0000', i.e. 0xC0. However, AK::BitmapView expects the bits to be stored at the bottom like '0000 0110', i.e. 0x06. For the current uses the data was always a multiple of eight bits, resulting in complete bytes, which could directly be interpreted correctly. For the implementation of the key usage extension of certificates the correct implementation of the BitString is required.
2022-04-17LibCrypto: Fix inverted boolean decoded error in ASN.1Michiel Visser
ASN.1 encodes booleans as false is zero and true is non-zero. The decoder currently returned true when the boolean was zero. Since this decoder was barely used it did not cause any problems, however for support of other certificate extensions the correct version is required.
2022-04-17LibTLS: ASN1 parse_utc_time handle pre 2000 yearsMichiel Visser
In this format the year is specified using two digits. In the case that these digits are 50 or more, we should assume that the year is in 1950-1999. If it is 49 or less, the year is 2000-2049. This is specified in RFC5280 section 4.1.2.5.1.
2022-04-13LibCrypto: Add ChaCha20stelar7
2022-04-08LibCrypto: Add Poly1305stelar7
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2022-03-26LibCrypto: Correctly add length to SHA384 and SHA512 hashesMichiel Visser
The SHA384 and SHA512 hashes would produce incorrect results for data where the length % 128 was in the range 112-119. This was because the total number of bits in the hashed values was added at the end as a 64-bit number instead of a 128-bit number. In most cases this would not cause any issues, as this space was padded with zeroes, however in the case that the length % 128 was 112-119, some incorrect data ended up where this 128-bit length value was expected. This change fixes the problems in LibTLS where some websites would result in a DecryptError on handshake.
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.