summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* More ec_point_cmp() turd polishingHEADmastertb2026-02-081-45/+46
| | | | | | | | jsing prefers doing all computations first and comparing at the end. This means we do more work when we fail and no longer (ab)use err as an out label. Also split out one more helper. ok jsing
* Make truncation in ASN1_BIT_STRING_set_bit() explicittb2026-02-081-9/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Instead of relying on i2c_ASN1_BIT_STRING() to determine the "unused" bits on encoding, set them explicitly in abs->flags via a call to asn1_abs_set_unused_bits(). This means ASN1_STRING_FLAGS_BITS_LEFT is now set on a bit string, which was previously explicitly cleared. This also means that the encoding of a non-zero ASN1_BIT_STRING populated by setting the bits individually will now go through the if (a->flags & ASN1_STRING_FLAG_BITS_LEFT) path in i2c_ASN1_BIT_STRING(). The most prominent usage of this function is in X.509 for the keyUsage extension or the CRL reason codes. There's also the NS cert type, TS PKIFailureInfo and general BITLIST config strings. The reason for the truncation logic comes from the DER for NamedBitLists X.690, 11.2.2 below: X.680, 22.7: When a "NamedBitList" is used in defining a bitstring type ASN.1 encoding rules are free to add (or remove) arbitrarily any trailing 0 bits to (or from) values that are being encoded or decoded. Application designers should therefore ensure that different semantics are not associated with such values which differ only in the number of trailing 0 bits. X.690, 11.2.2 Where ITU-T Rec. X.680 | ISO/IEC 8824-1, 22.7, applies, the bitstring shall have all trailing 0 bits removed before it is encoded. Note 1 - In the case where a size constraint has been applied, the abstract value delivered by a decoder to the application will be one of those satisfying the size constraint and differing from the transmitted value only in the number of trailing zero bits. Note 2 - If a bitstring value has no 1 bits, then an encoder shall encode the value with a length of 1 and an initial octet set to 0. ok kenjiro (on an earlier version) jsing
* replace buggy strncmp with strcmp found with clang-tidybcook2026-02-071-2/+2
| | | | | | Found the same fix from davidben in BoringSSL as well (https://boringssl-review.googlesource.com/c/boringssl/+/87927). OpenSSL appears to have accidentally changed the semantics here with the HAS_PREFIX macro, which appears to be incorrect. discussed w/ tb@ & beck@
* Implement s_client starttls protocol sieve.martijn2026-02-012-4/+62
| | | | | OK on previous diff concept sthen@ Suggestions, feedback and OK current diff tb@
* openssl asn1pars: move tmplen next to tmpbuftb2026-01-311-4/+4
|
* openssl asn1pars: avoid a few unnecessary caststb2026-01-311-11/+11
| | | | | | | | If str is a const unsigned char * rather than a char *, we can get away with a single cast and do not need to cast away const either. Reduce the scope of tmpbuf and ctmpbuf (now p) while there. ok kenjiro
* EVP_SealInit.3: fix RETURN VALUES sectiontb2026-01-301-2/+12
| | | | | | | | | While normal calls return 0 for error and npubk for success, there is a case where it returns the usual 1/0 thing. Make that explicit. Prompted by a report by Niels Dossche ok jsing kenjiro
* EVP_OpenInit.3: fix RETURN VALUES sectiontb2026-01-301-6/+4
| | | | | | | This has been incorrectly documented since forever. The function only ever returned 0/1. ok jsing kenjiro
* EVP_SealInit(): clear random key on exittb2026-01-301-2/+4
| | | | ok jsing kenjiro
* EVP_{Open,Seal}Init(): remove redundant EVP_CIPHER_CTX_reset() callstb2026-01-301-5/+1
| | | | | | The subsequent EVP_{Decrypt,Encrypt}Init_ex() calls already do that. pointed out by jsing
* EVP_SealInit(): minor cleanup.tb2026-01-301-11/+25
| | | | | | | | | | | | | | | | | Explicitly compare pointers against NULL, turn the function into single exit, add hint at why npubk <= 0 or pubk == NULL are a success path: The documentation briefly explains that EVP_OpenInit() and EVP_SealInit() is able to initialize the EVP_CIPHER_CTX in two steps exactly like the EVP_CipherInit_ex() API they wrap: the first call with non-NULL cipher (aka type) only sets the cipher on the ctx, then it returns to allow callers to customize the EVP_CIPHER_CTX, and a second call with cipher == NULL skips the initialization and finishes the ctx setup by setting key and iv. Prompted by a report by Niels Dossche. ok jsing kenjiro
* EVP_SealInit: do not return -1 on errortb2026-01-301-2/+2
| | | | | | | | It is documented that EVP_SealInit() returns 0 on error. So -1 is wrong. Reported by Niels Dossche ok jsing kenjiro
* EVP_OpenInit(): minor cleanuptb2026-01-301-9/+16
| | | | | | | | | Explicitly compare pointers against NULL, turn the function into single exit and explain why priv == NULL is a success (hint: muppet API). Prompted by a report by Niels Dossche. ok jsing kenjiro
* Avoid type confusion in the timestamp response parsingtb2026-01-271-1/+3
| | | | | | | | | | A malformed v2 signing cert can lead to a type confusion, and the result is a read from an invalid memory address or NULL, so a crash. Unlike for OpenSSL, v1 signing certs aren't affected since miod fixed this in '14. Reported by Luigino Camastra, fix by Bob Beck, via OpenSSL, CVE 2025-69420. ok jsing
* Avoid type confusion in PKCS#12 parsingtb2026-01-271-3/+9
| | | | | | | | | A type confusion can lead to a 1-byte read at address 0x00-0xff, so a crash. Reported by Luigino Camastra, fix by Bob Beck, via OpenSSL, CVE 2025-22795 ok jsing
* Add NULL pointer check to PKCS12_item_decrypt_d2i()tb2026-01-271-1/+6
| | | | | | | | Avoids a NULL pointer dereference triggerable by a malformed PCKS#12 file. From Luigino Camastra via OpenSSL (CVE-2025-69421) ok jsing
* assembly regress: use make's MACHINE_ARCH rather than handrolling ittb2026-01-251-4/+3
| | | | discussed with jsing
* Fix tyojsing2026-01-251-2/+2
|
* Hook assembly regressjsing2026-01-251-1/+2
|
* Add a regress test that ensures our pure assembly code builds with gccjsing2026-01-251-0/+36
| | | | | | This requires egcc to be installed, if not we'll just skip the test. Discussed with tb@
* Make SHA aarch64 assembly build with gcc.jsing2026-01-253-55/+72
| | | | | | | | | | | | | gcc is extremely fussy about register naming and insists on q and s naming for the ARM CE SHA instructions, even though they're referring to the same register (while LLVM just figures it out). Work around this by mapping registers to their required variant at usage and defining a handful of mappings between v registers and alternate names/views. This is still somewhat ugly, but seems to be one of the cleaner options that will allow portable to enable SHA assembly on platforms that use gcc. ok kenjiro@ tb@
* Tidy instruction separators in SHA assembly.jsing2026-01-247-113/+113
| | | | | Remove unnecessary separators and add a few to macros that call other macros (instead of expecting them to exist).
* unusally -> unusuallytb2026-01-233-30/+30
|
* bn_ffdh: unifdef HAVE_SCAPY_SPECIALtb2026-01-231-7/+1
|
* DH_check: teach this DoS vector about RFC 7919 primestb2026-01-231-1/+6
| | | | ok beck
* bn_ffdh: unifdef HAVE_RFC7919_PRIMEStb2026-01-231-8/+1
|
* bn_const: add RFC 7919 primestb2026-01-232-2/+300
| | | | | | | | There is no intention to expose these via public API or to use them in TLS. For now these will only be used for short-circuiting pointless expensive computations in DH_check(). ok beck
* Scapy special for DH_check()tb2026-01-231-2/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The latest release of Scapy calls DH_check() on all the well-known Diffie-Hellman parameters for RFCs 2409, 3526, and 7919. It does this via pyca/cryptography at startup. Every single time. This is obviously very expensive, due to our 64 MR rounds (which are complete overkill now that we have BPSW). Instead of pondering the ideal number of rounds for BPSW with FFDH, simply skip the check if the parameter matches a well-known prime. These are known to be safe primes, so we can skip those super-expensive and pointless checks without any risk. This is only done for the public dh->p parameter. It could be further optimized, but with the follow-up commit adding the RFC 7919 primes this reduces the startup time to what it was before Scapy 2.7.0: < 1s. Reverting from 64 MR rounds to BN_check_primes rounds, we would still have ~8s startup time without this optimization, which isn't great for an interactive tool. Clearly, it's not entirely our fault, it's also Scapy and cryptography that do something ... suboptimal, but I think we're better off if DH_check() isn't a complete DoS vector. If you're using non-standard parameters with FFDH, you deserve it. We could consider adding a flag for non-well-known p and thus making DH_check() indicate failure for candidate primes larger than, say, 4k. https://github.com/pyca/cryptography/issues/14048 ok beck kenjiro
* bn regress: add test that double checks the RFC 2409 and 3526 primestb2026-01-232-1/+505
| | | | | Also has code to check the RFC 7919 primes and run DH_check() once that knows about these.
* wycheproof regress: wycheproof-testvectors was renamed to wycheprooftb2026-01-221-2/+2
| | | | | Installed packages will update and pkg_add wycheproof-testvectors will continue to work.
* policy test: parital -> partialtb2026-01-221-2/+2
|
* ML-KEM: unstub runMLKEMKeyGenTest()tb2026-01-221-1/+50
| | | | | This adds coverage for MLKEM_private_key_from_seed(), which was previously only minimal teted from our regress.
* ML-KEM: improve the EncapsTesttb2026-01-221-4/+46
| | | | | New testvectors want some more detailed handling, which brings these Wycheproof encapsulation tests about on par with our existing tests.
* ML-KEM: add handler stub for the new KeyGenTesttb2026-01-221-1/+7
|
* ML_KEM: fix broken test: the encapsulated key is eK, not C...tb2026-01-221-2/+2
|
* ML-KEM: don't treat API failure as test failure for invalid test casestb2026-01-221-5/+11
| | | | | An update to the test vectors adds tests which verifies that the API correctly rejects some inputs.
* While almost all the libc locks are taken and released in the sameguenther2026-01-193-1/+85
| | | | | | | | | | libc call, flockfile() and ftrylockfile() can be called when single-threaded and then--while 'holding' the lock--the process can create another thread, resulting in a broken state. Have the f{lock,trylock,unlock}file() APIs *always* do real locking so the exposed state is always consistent. ok dlg@
* Rewrite ec_point_cmp()tb2026-01-181-59/+97
| | | | | | | | This removes some complications due to handling the fast path for affine points and general points at the same time. The result is a bit more code but both paths should be much easier to follow. ok jsing kenjiro
* mlkem: fix mklem_{generate_key,encap}_external_entropy() declarationstb2026-01-181-5/+3
| | | | | | | | | | The prototypes used sized arrays appropriate only for MLKEM768 while the declarations used pointers. For some reason clang doesn't flag this but gcc does. In any case it was wrong. The callers of these functions check that they pass in the correct size. Which is weird but the mlkem directory has an unbelievable amount of mess and bad code. found by/ok jsing
* mlkem: garbage collect the unusd mlkem_{generate_key,encap}()tb2026-01-182-58/+2
| | | | | | | These are flagged by more recent gcc since declarations and definitions don't match (sized array vs pointer). Also an array was checked for NULL. found by/ok jsing
* Provide LIBRESSL_USE_.*_ASSEMBLY defines.jsing2026-01-1717-31/+104
| | | | | | | | | Make life easier for portable by providing LIBRESSL_USE_.*_ASSEMBLY defines, which enable/disable assembly for a specific algorithm. This means that selected platforms can include the assembly files and specify a define, rather than having to try to patch the crypto_arch.h headers. Discussed with tb@
* Replace MD5_ASM with function specific defines.jsing2026-01-175-9/+11
| | | | | Use the same pattern that is now used for most other code - provide HAVE_MD5_BLOCK_DATA_ORDER and use this to selectively enable source code.
* Replace GHASH_ASM with function specific defines.jsing2026-01-1711-22/+41
| | | | | Use the same pattern that is now used for most other code - provide HAVE_* defines for functions and use these to selectively enable source code.
* Mop up unused AES_ASM and RSA_ASM defines.jsing2026-01-177-15/+7
| | | | These have not been used for quite some time.
* Use .section before .rodata to appease gas.jsing2026-01-178-22/+26
| | | | | | gas dislikes bare .rodata - add .section before .rodata to make it happier (LLVM does not care and is happy with either). For consistency, do the same with .text.
* Use local label prefix for loop labels.jsing2026-01-173-9/+9
|
* mlkem_internal.h: formate -> formattb2026-01-161-2/+2
|
* mlkem_internal.h: some very basic copy editingtb2026-01-161-6/+6
|
* mlkem.h: Thie -> This (2x)tb2026-01-161-3/+3
|
* mlkem.c: becuase -> becausetb2026-01-161-2/+2
|