diff --git a/crypto/openssl/CHANGES.md b/crypto/openssl/CHANGES.md index a26bdbdd0ad0..f464b2320e9c 100644 --- a/crypto/openssl/CHANGES.md +++ b/crypto/openssl/CHANGES.md @@ -1,19917 +1,19926 @@ OpenSSL CHANGES =============== This is a high-level summary of the most important changes. For a full list of changes, see the [git commit log][log] and pick the appropriate release branch. [log]: https://github.com/openssl/openssl/commits/ OpenSSL Releases ---------------- - [OpenSSL 3.0](#openssl-30) - [OpenSSL 1.1.1](#openssl-111) - [OpenSSL 1.1.0](#openssl-110) - [OpenSSL 1.0.2](#openssl-102) - [OpenSSL 1.0.1](#openssl-101) - [OpenSSL 1.0.0](#openssl-100) - [OpenSSL 0.9.x](#openssl-09x) OpenSSL 3.0 ----------- For OpenSSL 3.0 a [Migration guide][] has been added, so the CHANGES entries listed here are only a brief description. The migration guide contains more detailed information related to new features, breaking changes, and mappings for the large list of deprecated functions. [Migration guide]: https://github.com/openssl/openssl/tree/master/doc/man7/migration_guide.pod +### Changes between 3.0.11 and 3.0.12 [24 Oct 2023] + + * Fix incorrect key and IV resizing issues when calling EVP_EncryptInit_ex2(), + EVP_DecryptInit_ex2() or EVP_CipherInit_ex2() with OSSL_PARAM parameters + that alter the key or IV length ([CVE-2023-5363]). + + *Paul Dale* + ### Changes between 3.0.10 and 3.0.11 [19 Sep 2023] * Fix POLY1305 MAC implementation corrupting XMM registers on Windows. The POLY1305 MAC (message authentication code) implementation in OpenSSL does not save the contents of non-volatile XMM registers on Windows 64 platform when calculating the MAC of data larger than 64 bytes. Before returning to the caller all the XMM registers are set to zero rather than restoring their previous content. The vulnerable code is used only on newer x86_64 processors supporting the AVX512-IFMA instructions. The consequences of this kind of internal application state corruption can be various - from no consequences, if the calling application does not depend on the contents of non-volatile XMM registers at all, to the worst consequences, where the attacker could get complete control of the application process. However given the contents of the registers are just zeroized so the attacker cannot put arbitrary values inside, the most likely consequence, if any, would be an incorrect result of some application dependent calculations or a crash leading to a denial of service. ([CVE-2023-4807]) *Bernd Edlinger* ### Changes between 3.0.9 and 3.0.10 [1 Aug 2023] * Fix excessive time spent checking DH q parameter value. The function DH_check() performs various checks on DH parameters. After fixing CVE-2023-3446 it was discovered that a large q parameter value can also trigger an overly long computation during some of these checks. A correct q value, if present, cannot be larger than the modulus p parameter, thus it is unnecessary to perform these checks if q is larger than p. If DH_check() is called with such q parameter value, DH_CHECK_INVALID_Q_VALUE return flag is set and the computationally intensive checks are skipped. ([CVE-2023-3817]) *Tomáš Mráz* * Fix DH_check() excessive time with over sized modulus. The function DH_check() performs various checks on DH parameters. One of those checks confirms that the modulus ("p" parameter) is not too large. Trying to use a very large modulus is slow and OpenSSL will not normally use a modulus which is over 10,000 bits in length. However the DH_check() function checks numerous aspects of the key or parameters that have been supplied. Some of those checks use the supplied modulus value even if it has already been found to be too large. A new limit has been added to DH_check of 32,768 bits. Supplying a key/parameters with a modulus over this size will simply cause DH_check() to fail. ([CVE-2023-3446]) *Matt Caswell* * Do not ignore empty associated data entries with AES-SIV. The AES-SIV algorithm allows for authentication of multiple associated data entries along with the encryption. To authenticate empty data the application has to call `EVP_EncryptUpdate()` (or `EVP_CipherUpdate()`) with NULL pointer as the output buffer and 0 as the input buffer length. The AES-SIV implementation in OpenSSL just returns success for such call instead of performing the associated data authentication operation. The empty data thus will not be authenticated. ([CVE-2023-2975]) Thanks to Juerg Wullschleger (Google) for discovering the issue. The fix changes the authentication tag value and the ciphertext for applications that use empty associated data entries with AES-SIV. To decrypt data encrypted with previous versions of OpenSSL the application has to skip calls to `EVP_DecryptUpdate()` for empty associated data entries. *Tomáš Mráz* ### Changes between 3.0.8 and 3.0.9 [30 May 2023] * Mitigate for the time it takes for `OBJ_obj2txt` to translate gigantic OBJECT IDENTIFIER sub-identifiers to canonical numeric text form. OBJ_obj2txt() would translate any size OBJECT IDENTIFIER to canonical numeric text form. For gigantic sub-identifiers, this would take a very long time, the time complexity being O(n^2) where n is the size of that sub-identifier. ([CVE-2023-2650]) To mitigitate this, `OBJ_obj2txt()` will only translate an OBJECT IDENTIFIER to canonical numeric text form if the size of that OBJECT IDENTIFIER is 586 bytes or less, and fail otherwise. The basis for this restriction is [RFC 2578 (STD 58), section 3.5]. OBJECT IDENTIFIER values, which stipulates that OBJECT IDENTIFIERS may have at most 128 sub-identifiers, and that the maximum value that each sub- identifier may have is 2^32-1 (4294967295 decimal). For each byte of every sub-identifier, only the 7 lower bits are part of the value, so the maximum amount of bytes that an OBJECT IDENTIFIER with these restrictions may occupy is 32 * 128 / 7, which is approximately 586 bytes. *Richard Levitte* * Fixed buffer overread in AES-XTS decryption on ARM 64 bit platforms which happens if the buffer size is 4 mod 5 in 16 byte AES blocks. This can trigger a crash of an application using AES-XTS decryption if the memory just after the buffer being decrypted is not mapped. Thanks to Anton Romanov (Amazon) for discovering the issue. ([CVE-2023-1255]) *Nevine Ebeid* * Reworked the Fix for the Timing Oracle in RSA Decryption ([CVE-2022-4304]). The previous fix for this timing side channel turned out to cause a severe 2-3x performance regression in the typical use case compared to 3.0.7. The new fix uses existing constant time code paths, and restores the previous performance level while fully eliminating all existing timing side channels. The fix was developed by Bernd Edlinger with testing support by Hubert Kario. *Bernd Edlinger* * Corrected documentation of X509_VERIFY_PARAM_add0_policy() to mention that it does not enable policy checking. Thanks to David Benjamin for discovering this issue. ([CVE-2023-0466]) *Tomáš Mráz* * Fixed an issue where invalid certificate policies in leaf certificates are silently ignored by OpenSSL and other certificate policy checks are skipped for that certificate. A malicious CA could use this to deliberately assert invalid certificate policies in order to circumvent policy checking on the certificate altogether. ([CVE-2023-0465]) *Matt Caswell* * Limited the number of nodes created in a policy tree to mitigate against CVE-2023-0464. The default limit is set to 1000 nodes, which should be sufficient for most installations. If required, the limit can be adjusted by setting the OPENSSL_POLICY_TREE_NODES_MAX build time define to a desired maximum number of nodes or zero to allow unlimited growth. ([CVE-2023-0464]) *Paul Dale* ### Changes between 3.0.7 and 3.0.8 [7 Feb 2023] * Fixed NULL dereference during PKCS7 data verification. A NULL pointer can be dereferenced when signatures are being verified on PKCS7 signed or signedAndEnveloped data. In case the hash algorithm used for the signature is known to the OpenSSL library but the implementation of the hash algorithm is not available the digest initialization will fail. There is a missing check for the return value from the initialization function which later leads to invalid usage of the digest API most likely leading to a crash. ([CVE-2023-0401]) PKCS7 data is processed by the SMIME library calls and also by the time stamp (TS) library calls. The TLS implementation in OpenSSL does not call these functions however third party applications would be affected if they call these functions to verify signatures on untrusted data. *Tomáš Mráz* * Fixed X.400 address type confusion in X.509 GeneralName. There is a type confusion vulnerability relating to X.400 address processing inside an X.509 GeneralName. X.400 addresses were parsed as an ASN1_STRING but the public structure definition for GENERAL_NAME incorrectly specified the type of the x400Address field as ASN1_TYPE. This field is subsequently interpreted by the OpenSSL function GENERAL_NAME_cmp as an ASN1_TYPE rather than an ASN1_STRING. When CRL checking is enabled (i.e. the application sets the X509_V_FLAG_CRL_CHECK flag), this vulnerability may allow an attacker to pass arbitrary pointers to a memcmp call, enabling them to read memory contents or enact a denial of service. ([CVE-2023-0286]) *Hugo Landau* * Fixed NULL dereference validating DSA public key. An invalid pointer dereference on read can be triggered when an application tries to check a malformed DSA public key by the EVP_PKEY_public_check() function. This will most likely lead to an application crash. This function can be called on public keys supplied from untrusted sources which could allow an attacker to cause a denial of service attack. The TLS implementation in OpenSSL does not call this function but applications might call the function if there are additional security requirements imposed by standards such as FIPS 140-3. ([CVE-2023-0217]) *Shane Lontis, Tomáš Mráz* * Fixed Invalid pointer dereference in d2i_PKCS7 functions. An invalid pointer dereference on read can be triggered when an application tries to load malformed PKCS7 data with the d2i_PKCS7(), d2i_PKCS7_bio() or d2i_PKCS7_fp() functions. The result of the dereference is an application crash which could lead to a denial of service attack. The TLS implementation in OpenSSL does not call this function however third party applications might call these functions on untrusted data. ([CVE-2023-0216]) *Tomáš Mráz* * Fixed Use-after-free following BIO_new_NDEF. The public API function BIO_new_NDEF is a helper function used for streaming ASN.1 data via a BIO. It is primarily used internally to OpenSSL to support the SMIME, CMS and PKCS7 streaming capabilities, but may also be called directly by end user applications. The function receives a BIO from the caller, prepends a new BIO_f_asn1 filter BIO onto the front of it to form a BIO chain, and then returns the new head of the BIO chain to the caller. Under certain conditions, for example if a CMS recipient public key is invalid, the new filter BIO is freed and the function returns a NULL result indicating a failure. However, in this case, the BIO chain is not properly cleaned up and the BIO passed by the caller still retains internal pointers to the previously freed filter BIO. If the caller then goes on to call BIO_pop() on the BIO then a use-after-free will occur. This will most likely result in a crash. ([CVE-2023-0215]) *Viktor Dukhovni, Matt Caswell* * Fixed Double free after calling PEM_read_bio_ex. The function PEM_read_bio_ex() reads a PEM file from a BIO and parses and decodes the "name" (e.g. "CERTIFICATE"), any header data and the payload data. If the function succeeds then the "name_out", "header" and "data" arguments are populated with pointers to buffers containing the relevant decoded data. The caller is responsible for freeing those buffers. It is possible to construct a PEM file that results in 0 bytes of payload data. In this case PEM_read_bio_ex() will return a failure code but will populate the header argument with a pointer to a buffer that has already been freed. If the caller also frees this buffer then a double free will occur. This will most likely lead to a crash. The functions PEM_read_bio() and PEM_read() are simple wrappers around PEM_read_bio_ex() and therefore these functions are also directly affected. These functions are also called indirectly by a number of other OpenSSL functions including PEM_X509_INFO_read_bio_ex() and SSL_CTX_use_serverinfo_file() which are also vulnerable. Some OpenSSL internal uses of these functions are not vulnerable because the caller does not free the header argument if PEM_read_bio_ex() returns a failure code. ([CVE-2022-4450]) *Kurt Roeckx, Matt Caswell* * Fixed Timing Oracle in RSA Decryption. A timing based side channel exists in the OpenSSL RSA Decryption implementation which could be sufficient to recover a plaintext across a network in a Bleichenbacher style attack. To achieve a successful decryption an attacker would have to be able to send a very large number of trial messages for decryption. The vulnerability affects all RSA padding modes: PKCS#1 v1.5, RSA-OEAP and RSASVE. ([CVE-2022-4304]) *Dmitry Belyavsky, Hubert Kario* * Fixed X.509 Name Constraints Read Buffer Overflow. A read buffer overrun can be triggered in X.509 certificate verification, specifically in name constraint checking. The read buffer overrun might result in a crash which could lead to a denial of service attack. In a TLS client, this can be triggered by connecting to a malicious server. In a TLS server, this can be triggered if the server requests client authentication and a malicious client connects. ([CVE-2022-4203]) *Viktor Dukhovni* * Fixed X.509 Policy Constraints Double Locking security issue. If an X.509 certificate contains a malformed policy constraint and policy processing is enabled, then a write lock will be taken twice recursively. On some operating systems (most widely: Windows) this results in a denial of service when the affected process hangs. Policy processing being enabled on a publicly facing server is not considered to be a common setup. ([CVE-2022-3996]) *Paul Dale* * Our provider implementations of `OSSL_FUNC_KEYMGMT_EXPORT` and `OSSL_FUNC_KEYMGMT_GET_PARAMS` for EC and SM2 keys now honor `OSSL_PKEY_PARAM_EC_POINT_CONVERSION_FORMAT` as set (and default to `POINT_CONVERSION_UNCOMPRESSED`) when exporting `OSSL_PKEY_PARAM_PUB_KEY`, instead of unconditionally using `POINT_CONVERSION_COMPRESSED` as in previous 3.x releases. For symmetry, our implementation of `EVP_PKEY_ASN1_METHOD->export_to` for legacy EC and SM2 keys is also changed similarly to honor the equivalent conversion format flag as specified in the underlying `EC_KEY` object being exported to a provider, when this function is called through `EVP_PKEY_export()`. *Nicola Tuveri* ### Changes between 3.0.6 and 3.0.7 [1 Nov 2022] * Fixed two buffer overflows in punycode decoding functions. A buffer overrun can be triggered in X.509 certificate verification, specifically in name constraint checking. Note that this occurs after certificate chain signature verification and requires either a CA to have signed the malicious certificate or for the application to continue certificate verification despite failure to construct a path to a trusted issuer. In a TLS client, this can be triggered by connecting to a malicious server. In a TLS server, this can be triggered if the server requests client authentication and a malicious client connects. An attacker can craft a malicious email address to overflow an arbitrary number of bytes containing the `.` character (decimal 46) on the stack. This buffer overflow could result in a crash (causing a denial of service). ([CVE-2022-3786]) An attacker can craft a malicious email address to overflow four attacker-controlled bytes on the stack. This buffer overflow could result in a crash (causing a denial of service) or potentially remote code execution depending on stack layout for any given platform/compiler. ([CVE-2022-3602]) *Paul Dale* * Removed all references to invalid OSSL_PKEY_PARAM_RSA names for CRT parameters in OpenSSL code. Applications should not use the names OSSL_PKEY_PARAM_RSA_FACTOR, OSSL_PKEY_PARAM_RSA_EXPONENT and OSSL_PKEY_PARAM_RSA_COEFFICIENT. Use the numbered names such as OSSL_PKEY_PARAM_RSA_FACTOR1 instead. Using these invalid names may cause algorithms to use slower methods that ignore the CRT parameters. *Shane Lontis* * Fixed a regression introduced in 3.0.6 version raising errors on some stack operations. *Tomáš Mráz* * Fixed a regression introduced in 3.0.6 version not refreshing the certificate data to be signed before signing the certificate. *Gibeom Gwon* * Added RIPEMD160 to the default provider. *Paul Dale* * Ensured that the key share group sent or accepted for the key exchange is allowed for the protocol version. *Matt Caswell* ### Changes between 3.0.5 and 3.0.6 [11 Oct 2022] * OpenSSL supports creating a custom cipher via the legacy EVP_CIPHER_meth_new() function and associated function calls. This function was deprecated in OpenSSL 3.0 and application authors are instead encouraged to use the new provider mechanism in order to implement custom ciphers. OpenSSL versions 3.0.0 to 3.0.5 incorrectly handle legacy custom ciphers passed to the EVP_EncryptInit_ex2(), EVP_DecryptInit_ex2() and EVP_CipherInit_ex2() functions (as well as other similarly named encryption and decryption initialisation functions). Instead of using the custom cipher directly it incorrectly tries to fetch an equivalent cipher from the available providers. An equivalent cipher is found based on the NID passed to EVP_CIPHER_meth_new(). This NID is supposed to represent the unique NID for a given cipher. However it is possible for an application to incorrectly pass NID_undef as this value in the call to EVP_CIPHER_meth_new(). When NID_undef is used in this way the OpenSSL encryption/decryption initialisation function will match the NULL cipher as being equivalent and will fetch this from the available providers. This will succeed if the default provider has been loaded (or if a third party provider has been loaded that offers this cipher). Using the NULL cipher means that the plaintext is emitted as the ciphertext. Applications are only affected by this issue if they call EVP_CIPHER_meth_new() using NID_undef and subsequently use it in a call to an encryption/decryption initialisation function. Applications that only use SSL/TLS are not impacted by this issue. ([CVE-2022-3358]) *Matt Caswell* * Fix LLVM vs Apple LLVM version numbering confusion that caused build failures on MacOS 10.11 *Richard Levitte* * Fixed the linux-mips64 Configure target which was missing the SIXTY_FOUR_BIT bn_ops flag. This was causing heap corruption on that platform. *Adam Joseph* * Fix handling of a ticket key callback that returns 0 in TLSv1.3 to not send a ticket *Matt Caswell* * Correctly handle a retransmitted ClientHello in DTLS *Matt Caswell* * Fixed detection of ktls support in cross-compile environment on Linux *Tomas Mraz* * Fixed some regressions and test failures when running the 3.0.0 FIPS provider against 3.0.x *Paul Dale* * Fixed SSL_pending() and SSL_has_pending() with DTLS which were failing to report correct results in some cases *Matt Caswell* * Fix UWP builds by defining VirtualLock *Charles Milette* * For known safe primes use the minimum key length according to RFC 7919. Longer private key sizes unnecessarily raise the cycles needed to compute the shared secret without any increase of the real security. This fixes a regression from 1.1.1 where these shorter keys were generated for the known safe primes. *Tomas Mraz* * Added the loongarch64 target *Shi Pujin* * Fixed EC ASM flag passing. Flags for ASM implementations of EC curves were only passed to the FIPS provider and not to the default or legacy provider. *Juergen Christ* * Fixed reported performance degradation on aarch64. Restored the implementation prior to commit 2621751 ("aes/asm/aesv8-armx.pl: avoid 32-bit lane assignment in CTR mode") for 64bit targets only, since it is reportedly 2-17% slower and the silicon errata only affects 32bit targets. The new algorithm is still used for 32 bit targets. *Bernd Edlinger* * Added a missing header for memcmp that caused compilation failure on some platforms *Gregor Jasny* ### Changes between 3.0.4 and 3.0.5 [5 Jul 2022] * The OpenSSL 3.0.4 release introduced a serious bug in the RSA implementation for X86_64 CPUs supporting the AVX512IFMA instructions. This issue makes the RSA implementation with 2048 bit private keys incorrect on such machines and memory corruption will happen during the computation. As a consequence of the memory corruption an attacker may be able to trigger a remote code execution on the machine performing the computation. SSL/TLS servers or other servers using 2048 bit RSA private keys running on machines supporting AVX512IFMA instructions of the X86_64 architecture are affected by this issue. ([CVE-2022-2274]) *Xi Ruoyao* * AES OCB mode for 32-bit x86 platforms using the AES-NI assembly optimised implementation would not encrypt the entirety of the data under some circumstances. This could reveal sixteen bytes of data that was preexisting in the memory that wasn't written. In the special case of "in place" encryption, sixteen bytes of the plaintext would be revealed. Since OpenSSL does not support OCB based cipher suites for TLS and DTLS, they are both unaffected. ([CVE-2022-2097]) *Alex Chernyakhovsky, David Benjamin, Alejandro Sedeño* ### Changes between 3.0.3 and 3.0.4 [21 Jun 2022] * In addition to the c_rehash shell command injection identified in CVE-2022-1292, further bugs where the c_rehash script does not properly sanitise shell metacharacters to prevent command injection have been fixed. When the CVE-2022-1292 was fixed it was not discovered that there are other places in the script where the file names of certificates being hashed were possibly passed to a command executed through the shell. This script is distributed by some operating systems in a manner where it is automatically executed. On such operating systems, an attacker could execute arbitrary commands with the privileges of the script. Use of the c_rehash script is considered obsolete and should be replaced by the OpenSSL rehash command line tool. (CVE-2022-2068) *Daniel Fiala, Tomáš Mráz* * Case insensitive string comparison no longer uses locales. It has instead been directly implemented. *Paul Dale* ### Changes between 3.0.2 and 3.0.3 [3 May 2022] * Case insensitive string comparison is reimplemented via new locale-agnostic comparison functions OPENSSL_str[n]casecmp always using the POSIX locale for comparison. The previous implementation had problems when the Turkish locale was used. *Dmitry Belyavskiy* * Fixed a bug in the c_rehash script which was not properly sanitising shell metacharacters to prevent command injection. This script is distributed by some operating systems in a manner where it is automatically executed. On such operating systems, an attacker could execute arbitrary commands with the privileges of the script. Use of the c_rehash script is considered obsolete and should be replaced by the OpenSSL rehash command line tool. (CVE-2022-1292) *Tomáš Mráz* * Fixed a bug in the function `OCSP_basic_verify` that verifies the signer certificate on an OCSP response. The bug caused the function in the case where the (non-default) flag OCSP_NOCHECKS is used to return a postivie response (meaning a successful verification) even in the case where the response signing certificate fails to verify. It is anticipated that most users of `OCSP_basic_verify` will not use the OCSP_NOCHECKS flag. In this case the `OCSP_basic_verify` function will return a negative value (indicating a fatal error) in the case of a certificate verification failure. The normal expected return value in this case would be 0. This issue also impacts the command line OpenSSL "ocsp" application. When verifying an ocsp response with the "-no_cert_checks" option the command line application will report that the verification is successful even though it has in fact failed. In this case the incorrect successful response will also be accompanied by error messages showing the failure and contradicting the apparently successful result. ([CVE-2022-1343]) *Matt Caswell* * Fixed a bug where the RC4-MD5 ciphersuite incorrectly used the AAD data as the MAC key. This made the MAC key trivially predictable. An attacker could exploit this issue by performing a man-in-the-middle attack to modify data being sent from one endpoint to an OpenSSL 3.0 recipient such that the modified data would still pass the MAC integrity check. Note that data sent from an OpenSSL 3.0 endpoint to a non-OpenSSL 3.0 endpoint will always be rejected by the recipient and the connection will fail at that point. Many application protocols require data to be sent from the client to the server first. Therefore, in such a case, only an OpenSSL 3.0 server would be impacted when talking to a non-OpenSSL 3.0 client. If both endpoints are OpenSSL 3.0 then the attacker could modify data being sent in both directions. In this case both clients and servers could be affected, regardless of the application protocol. Note that in the absence of an attacker this bug means that an OpenSSL 3.0 endpoint communicating with a non-OpenSSL 3.0 endpoint will fail to complete the handshake when using this ciphersuite. The confidentiality of data is not impacted by this issue, i.e. an attacker cannot decrypt data that has been encrypted using this ciphersuite - they can only modify it. In order for this attack to work both endpoints must legitimately negotiate the RC4-MD5 ciphersuite. This ciphersuite is not compiled by default in OpenSSL 3.0, and is not available within the default provider or the default ciphersuite list. This ciphersuite will never be used if TLSv1.3 has been negotiated. In order for an OpenSSL 3.0 endpoint to use this ciphersuite the following must have occurred: 1) OpenSSL must have been compiled with the (non-default) compile time option enable-weak-ssl-ciphers 2) OpenSSL must have had the legacy provider explicitly loaded (either through application code or via configuration) 3) The ciphersuite must have been explicitly added to the ciphersuite list 4) The libssl security level must have been set to 0 (default is 1) 5) A version of SSL/TLS below TLSv1.3 must have been negotiated 6) Both endpoints must negotiate the RC4-MD5 ciphersuite in preference to any others that both endpoints have in common (CVE-2022-1434) *Matt Caswell* * Fix a bug in the OPENSSL_LH_flush() function that breaks reuse of the memory occuppied by the removed hash table entries. This function is used when decoding certificates or keys. If a long lived process periodically decodes certificates or keys its memory usage will expand without bounds and the process might be terminated by the operating system causing a denial of service. Also traversing the empty hash table entries will take increasingly more time. Typically such long lived processes might be TLS clients or TLS servers configured to accept client certificate authentication. (CVE-2022-1473) *Hugo Landau, Aliaksei Levin* * The functions `OPENSSL_LH_stats` and `OPENSSL_LH_stats_bio` now only report the `num_items`, `num_nodes` and `num_alloc_nodes` statistics. All other statistics are no longer supported. For compatibility, these statistics are still listed in the output but are now always reported as zero. *Hugo Landau* ### Changes between 3.0.1 and 3.0.2 [15 Mar 2022] * Fixed a bug in the BN_mod_sqrt() function that can cause it to loop forever for non-prime moduli. Internally this function is used when parsing certificates that contain elliptic curve public keys in compressed form or explicit elliptic curve parameters with a base point encoded in compressed form. It is possible to trigger the infinite loop by crafting a certificate that has invalid explicit curve parameters. Since certificate parsing happens prior to verification of the certificate signature, any process that parses an externally supplied certificate may thus be subject to a denial of service attack. The infinite loop can also be reached when parsing crafted private keys as they can contain explicit elliptic curve parameters. Thus vulnerable situations include: - TLS clients consuming server certificates - TLS servers consuming client certificates - Hosting providers taking certificates or private keys from customers - Certificate authorities parsing certification requests from subscribers - Anything else which parses ASN.1 elliptic curve parameters Also any other applications that use the BN_mod_sqrt() where the attacker can control the parameter values are vulnerable to this DoS issue. ([CVE-2022-0778]) *Tomáš Mráz* * Add ciphersuites based on DHE_PSK (RFC 4279) and ECDHE_PSK (RFC 5489) to the list of ciphersuites providing Perfect Forward Secrecy as required by SECLEVEL >= 3. *Dmitry Belyavskiy, Nicola Tuveri* * Made the AES constant time code for no-asm configurations optional due to the resulting 95% performance degradation. The AES constant time code can be enabled, for no assembly builds, with: ./config no-asm -DOPENSSL_AES_CONST_TIME *Paul Dale* * Fixed PEM_write_bio_PKCS8PrivateKey() to make it possible to use empty passphrase strings. *Darshan Sen* * The negative return value handling of the certificate verification callback was reverted. The replacement is to set the verification retry state with the SSL_set_retry_verify() function. *Tomáš Mráz* ### Changes between 3.0.0 and 3.0.1 [14 Dec 2021] * Fixed invalid handling of X509_verify_cert() internal errors in libssl Internally libssl in OpenSSL calls X509_verify_cert() on the client side to verify a certificate supplied by a server. That function may return a negative return value to indicate an internal error (for example out of memory). Such a negative return value is mishandled by OpenSSL and will cause an IO function (such as SSL_connect() or SSL_do_handshake()) to not indicate success and a subsequent call to SSL_get_error() to return the value SSL_ERROR_WANT_RETRY_VERIFY. This return value is only supposed to be returned by OpenSSL if the application has previously called SSL_CTX_set_cert_verify_callback(). Since most applications do not do this the SSL_ERROR_WANT_RETRY_VERIFY return value from SSL_get_error() will be totally unexpected and applications may not behave correctly as a result. The exact behaviour will depend on the application but it could result in crashes, infinite loops or other similar incorrect responses. This issue is made more serious in combination with a separate bug in OpenSSL 3.0 that will cause X509_verify_cert() to indicate an internal error when processing a certificate chain. This will occur where a certificate does not include the Subject Alternative Name extension but where a Certificate Authority has enforced name constraints. This issue can occur even with valid chains. ([CVE-2021-4044]) *Matt Caswell* * Corrected a few file name and file reference bugs in the build, installation and setup scripts, which lead to installation verification failures. Slightly enhanced the installation verification script. *Richard Levitte* * Fixed EVP_PKEY_eq() to make it possible to use it with strictly private keys. *Richard Levitte* * Fixed PVK encoder to properly query for the passphrase. *Tomáš Mráz* * Multiple fixes in the OSSL_HTTP API functions. *David von Oheimb* * Allow sign extension in OSSL_PARAM_allocate_from_text() for the OSSL_PARAM_INTEGER data type and return error on negative numbers used with the OSSL_PARAM_UNSIGNED_INTEGER data type. Make OSSL_PARAM_BLD_push_BN{,_pad}() return an error on negative numbers. *Richard Levitte* * Allow copying uninitialized digest contexts with EVP_MD_CTX_copy_ex. *Tomáš Mráz* * Fixed detection of ARMv7 and ARM64 CPU features on FreeBSD. *Allan Jude* * Multiple threading fixes. *Matt Caswell* * Added NULL digest implementation to keep compatibility with 1.1.1 version. *Tomáš Mráz* * Allow fetching an operation from the provider that owns an unexportable key as a fallback if that is still allowed by the property query. *Richard Levitte* ### Changes between 1.1.1 and 3.0.0 [7 sep 2021] * TLS_MAX_VERSION, DTLS_MAX_VERSION and DTLS_MIN_VERSION constants are now deprecated. *Matt Caswell* * The `OPENSSL_s390xcap` environment variable can be used to set bits in the S390X capability vector to zero. This simplifies testing of different code paths on S390X architecture. *Patrick Steuer* * Encrypting more than 2^64 TLS records with AES-GCM is disallowed as per FIPS 140-2 IG A.5 "Key/IV Pair Uniqueness Requirements from SP 800-38D". The communication will fail at this point. *Paul Dale* * The EC_GROUP_clear_free() function is deprecated as there is nothing confidential in EC_GROUP data. *Nicola Tuveri* * The byte order mark (BOM) character is ignored if encountered at the beginning of a PEM-formatted file. *Dmitry Belyavskiy* * Added CMS support for the Russian GOST algorithms. *Dmitry Belyavskiy* * Due to move of the implementation of cryptographic operations to the providers, validation of various operation parameters can be postponed until the actual operation is executed where previously it happened immediately when an operation parameter was set. For example when setting an unsupported curve with EVP_PKEY_CTX_set_ec_paramgen_curve_nid() this function call will not fail but later keygen operations with the EVP_PKEY_CTX will fail. *OpenSSL team members and many third party contributors* * The EVP_get_cipherbyname() function will return NULL for algorithms such as "AES-128-SIV", "AES-128-CBC-CTS" and "CAMELLIA-128-CBC-CTS" which were previously only accessible via low level interfaces. Use EVP_CIPHER_fetch() instead to retrieve these algorithms from a provider. *Shane Lontis* * On build targets where the multilib postfix is set in the build configuration the libdir directory was changing based on whether the lib directory with the multilib postfix exists on the system or not. This unpredictable behavior was removed and eventual multilib postfix is now always added to the default libdir. Use `--libdir=lib` to override the libdir if adding the postfix is undesirable. *Jan Lána* * The triple DES key wrap functionality now conforms to RFC 3217 but is no longer interoperable with OpenSSL 1.1.1. *Paul Dale* * The ERR_GET_FUNC() function was removed. With the loss of meaningful function codes, this function can only cause problems for calling applications. *Paul Dale* * Add a configurable flag to output date formats as ISO 8601. Does not change the default date format. *William Edmisten* * Version of MSVC earlier than 1300 could get link warnings, which could be suppressed if the undocumented -DI_CAN_LIVE_WITH_LNK4049 was set. Support for this flag has been removed. *Rich Salz* * Rework and make DEBUG macros consistent. Remove unused -DCONF_DEBUG, -DBN_CTX_DEBUG, and REF_PRINT. Add a new tracing category and use it for printing reference counts. Rename -DDEBUG_UNUSED to -DUNUSED_RESULT_DEBUG Fix BN_DEBUG_RAND so it compiles and, when set, force DEBUG_RAND to be set also. Rename engine_debug_ref to be ENGINE_REF_PRINT also for consistency. *Rich Salz* * The signatures of the functions to get and set options on SSL and SSL_CTX objects changed from "unsigned long" to "uint64_t" type. Some source code changes may be required. *Rich Salz* * The public definitions of conf_method_st and conf_st have been deprecated. They will be made opaque in a future release. *Rich Salz and Tomáš Mráz* * Client-initiated renegotiation is disabled by default. To allow it, use the -client_renegotiation option, the SSL_OP_ALLOW_CLIENT_RENEGOTIATION flag, or the "ClientRenegotiation" config parameter as appropriate. *Rich Salz* * Add "abspath" and "includedir" pragma's to config files, to prevent, or modify relative pathname inclusion. *Rich Salz* * OpenSSL includes a cryptographic module that is intended to be FIPS 140-2 validated. Please consult the README-FIPS and README-PROVIDERS files, as well as the migration guide. *OpenSSL team members and many third party contributors* * For the key types DH and DHX the allowed settable parameters are now different. *Shane Lontis* * The openssl commands that read keys, certificates, and CRLs now automatically detect the PEM or DER format of the input files. *David von Oheimb, Richard Levitte, and Tomáš Mráz* * Added enhanced PKCS#12 APIs which accept a library context. *Jon Spillett* * The default manual page suffix ($MANSUFFIX) has been changed to "ossl" *Matt Caswell* * Added support for Kernel TLS (KTLS). *Boris Pismenny, John Baldwin and Andrew Gallatin* * Support for RFC 5746 secure renegotiation is now required by default for SSL or TLS connections to succeed. *Benjamin Kaduk* * The signature of the `copy` functional parameter of the EVP_PKEY_meth_set_copy() function has changed so its `src` argument is now `const EVP_PKEY_CTX *` instead of `EVP_PKEY_CTX *`. Similarly the signature of the `pub_decode` functional parameter of the EVP_PKEY_asn1_set_public() function has changed so its `pub` argument is now `const X509_PUBKEY *` instead of `X509_PUBKEY *`. *David von Oheimb* * The error return values from some control calls (ctrl) have changed. *Paul Dale* * A public key check is now performed during EVP_PKEY_derive_set_peer(). *Shane Lontis* * Many functions in the EVP_ namespace that are getters of values from implementations or contexts were renamed to include get or get0 in their names. Old names are provided as macro aliases for compatibility and are not deprecated. *Tomáš Mráz* * The EVP_PKEY_CTRL_PKCS7_ENCRYPT, EVP_PKEY_CTRL_PKCS7_DECRYPT, EVP_PKEY_CTRL_PKCS7_SIGN, EVP_PKEY_CTRL_CMS_ENCRYPT, EVP_PKEY_CTRL_CMS_DECRYPT, and EVP_PKEY_CTRL_CMS_SIGN control operations are deprecated. *Tomáš Mráz* * The EVP_PKEY_public_check() and EVP_PKEY_param_check() functions now work for more key types. * The output from the command line applications may have minor changes. *Paul Dale* * The output from numerous "printing" may have minor changes. *David von Oheimb* * Windows thread synchronization uses read/write primitives (SRWLock) when supported by the OS, otherwise CriticalSection continues to be used. *Vincent Drake* * Add filter BIO BIO_f_readbuffer() that allows BIO_tell() and BIO_seek() to work on read only BIO source/sinks that do not support these functions. This allows piping or redirection of a file BIO using stdin to be buffered into memory. This is used internally in OSSL_DECODER_from_bio(). *Shane Lontis* * OSSL_STORE_INFO_get_type() may now return an additional value. In 1.1.1 this function would return one of the values OSSL_STORE_INFO_NAME, OSSL_STORE_INFO_PKEY, OSSL_STORE_INFO_PARAMS, OSSL_STORE_INFO_CERT or OSSL_STORE_INFO_CRL. Decoded public keys would previously have been reported as type OSSL_STORE_INFO_PKEY in 1.1.1. In 3.0 decoded public keys are now reported as having the new type OSSL_STORE_INFO_PUBKEY. Applications using this function should be amended to handle the changed return value. *Richard Levitte* * Improved adherence to Enhanced Security Services (ESS, RFC 2634 and RFC 5035) for the TSP and CMS Advanced Electronic Signatures (CAdES) implementations. As required by RFC 5035 check both ESSCertID and ESSCertIDv2 if both present. Correct the semantics of checking the validation chain in case ESSCertID{,v2} contains more than one certificate identifier: This means that all certificates referenced there MUST be part of the validation chain. *David von Oheimb* * The implementation of older EVP ciphers related to CAST, IDEA, SEED, RC2, RC4, RC5, DESX and DES have been moved to the legacy provider. *Matt Caswell* * The implementation of the EVP digests MD2, MD4, MDC2, WHIRLPOOL and RIPEMD-160 have been moved to the legacy provider. *Matt Caswell* * The deprecated function EVP_PKEY_get0() now returns NULL being called for a provided key. *Dmitry Belyavskiy* * The deprecated functions EVP_PKEY_get0_RSA(), EVP_PKEY_get0_DSA(), EVP_PKEY_get0_EC_KEY(), EVP_PKEY_get0_DH(), EVP_PKEY_get0_hmac(), EVP_PKEY_get0_poly1305() and EVP_PKEY_get0_siphash() as well as the similarly named "get1" functions behave differently in OpenSSL 3.0. *Matt Caswell* * A number of functions handling low-level keys or engines were deprecated including EVP_PKEY_set1_engine(), EVP_PKEY_get0_engine(), EVP_PKEY_assign(), EVP_PKEY_get0(), EVP_PKEY_get0_hmac(), EVP_PKEY_get0_poly1305() and EVP_PKEY_get0_siphash(). *Matt Caswell* * PKCS#5 PBKDF1 key derivation has been moved from PKCS5_PBE_keyivgen() into the legacy crypto provider as an EVP_KDF. Applications requiring this KDF will need to load the legacy crypto provider. This includes these PBE algorithms which use this KDF: - NID_pbeWithMD2AndDES_CBC - NID_pbeWithMD5AndDES_CBC - NID_pbeWithSHA1AndRC2_CBC - NID_pbeWithMD2AndRC2_CBC - NID_pbeWithMD5AndRC2_CBC - NID_pbeWithSHA1AndDES_CBC *Jon Spillett* * Deprecated obsolete BIO_set_callback(), BIO_get_callback(), and BIO_debug_callback() functions. *Tomáš Mráz* * Deprecated obsolete EVP_PKEY_CTX_get0_dh_kdf_ukm() and EVP_PKEY_CTX_get0_ecdh_kdf_ukm() functions. *Tomáš Mráz* * The RAND_METHOD APIs have been deprecated. *Paul Dale* * The SRP APIs have been deprecated. *Matt Caswell* * Add a compile time option to prevent the caching of provider fetched algorithms. This is enabled by including the no-cached-fetch option at configuration time. *Paul Dale* * pkcs12 now uses defaults of PBKDF2, AES and SHA-256, with a MAC iteration count of PKCS12_DEFAULT_ITER. *Tomáš Mráz and Sahana Prasad* * The openssl speed command does not use low-level API calls anymore. *Tomáš Mráz* * Parallel dual-prime 1024-bit modular exponentiation for AVX512_IFMA capable processors. *Ilya Albrekht, Sergey Kirillov, Andrey Matyukov (Intel Corp)* * Combining the Configure options no-ec and no-dh no longer disables TLSv1.3. *Matt Caswell* * Implemented support for fully "pluggable" TLSv1.3 groups. This means that providers may supply their own group implementations (using either the "key exchange" or the "key encapsulation" methods) which will automatically be detected and used by libssl. *Matt Caswell, Nicola Tuveri* * The undocumented function X509_certificate_type() has been deprecated; *Rich Salz* * Deprecated the obsolete BN_pseudo_rand() and BN_pseudo_rand_range(). *Tomáš Mráz* * Removed RSA padding mode for SSLv23 (which was only used for SSLv2). This includes the functions RSA_padding_check_SSLv23() and RSA_padding_add_SSLv23() and the `-ssl` option in the deprecated `rsautl` command. *Rich Salz* * Deprecated the obsolete X9.31 RSA key generation related functions. * While a callback function set via `SSL_CTX_set_cert_verify_callback()` is not allowed to return a value > 1, this is no more taken as failure. *Viktor Dukhovni and David von Oheimb* * Deprecated the obsolete X9.31 RSA key generation related functions BN_X931_generate_Xpq(), BN_X931_derive_prime_ex(), and BN_X931_generate_prime_ex(). *Tomáš Mráz* * The default key generation method for the regular 2-prime RSA keys was changed to the FIPS 186-4 B.3.6 method. *Shane Lontis* * Deprecated the BN_is_prime_ex() and BN_is_prime_fasttest_ex() functions. *Kurt Roeckx* * Deprecated EVP_MD_CTX_set_update_fn() and EVP_MD_CTX_update_fn(). *Rich Salz* * Deprecated the type OCSP_REQ_CTX and the functions OCSP_REQ_CTX_*() and replaced with OSSL_HTTP_REQ_CTX and the functions OSSL_HTTP_REQ_CTX_*(). *Rich Salz, Richard Levitte, and David von Oheimb* * Deprecated `X509_http_nbio()` and `X509_CRL_http_nbio()`. *David von Oheimb* * Deprecated `OCSP_parse_url()`. *David von Oheimb* * Validation of SM2 keys has been separated from the validation of regular EC keys. *Nicola Tuveri* * Behavior of the `pkey` app is changed, when using the `-check` or `-pubcheck` switches: a validation failure triggers an early exit, returning a failure exit status to the parent process. *Nicola Tuveri* * Changed behavior of SSL_CTX_set_ciphersuites() and SSL_set_ciphersuites() to ignore unknown ciphers. *Otto Hollmann* * The `-cipher-commands` and `-digest-commands` options of the command line utility `list` have been deprecated. Instead use the `-cipher-algorithms` and `-digest-algorithms` options. *Dmitry Belyavskiy* * Added convenience functions for generating asymmetric key pairs: The 'quick' one-shot (yet somewhat limited) function L and macros for the most common cases: and L. *David von Oheimb* * All of the low level EC_KEY functions have been deprecated. *Shane Lontis, Paul Dale, Richard Levitte, and Tomáš Mráz* * Deprecated all the libcrypto and libssl error string loading functions. *Richard Levitte* * The functions SSL_CTX_set_tmp_dh_callback and SSL_set_tmp_dh_callback, as well as the macros SSL_CTX_set_tmp_dh() and SSL_set_tmp_dh() have been deprecated. *Matt Caswell* * The `-crypt` option to the `passwd` command line tool has been removed. *Paul Dale* * The -C option to the `x509`, `dhparam`, `dsaparam`, and `ecparam` commands were removed. *Rich Salz* * Add support for AES Key Wrap inverse ciphers to the EVP layer. *Shane Lontis* * Deprecated EVP_PKEY_set1_tls_encodedpoint() and EVP_PKEY_get1_tls_encodedpoint(). *Matt Caswell* * The security callback, which can be customised by application code, supports the security operation SSL_SECOP_TMP_DH. One location of the "other" parameter was incorrectly passing a DH object. It now passed an EVP_PKEY in all cases. *Matt Caswell* * Add PKCS7_get_octet_string() and PKCS7_type_is_other() to the public interface. Their functionality remains unchanged. *Jordan Montgomery* * Added new option for 'openssl list', '-providers', which will display the list of loaded providers, their names, version and status. It optionally displays their gettable parameters. *Paul Dale* * Removed EVP_PKEY_set_alias_type(). *Richard Levitte* * Deprecated `EVP_PKEY_CTX_set_rsa_keygen_pubexp()` and introduced `EVP_PKEY_CTX_set1_rsa_keygen_pubexp()`, which is now preferred. *Jeremy Walch* * Changed all "STACK" functions to be macros instead of inline functions. Macro parameters are still checked for type safety at compile time via helper inline functions. *Matt Caswell* * Remove the RAND_DRBG API *Paul Dale and Matthias St. Pierre* * Allow `SSL_set1_host()` and `SSL_add1_host()` to take IP literal addresses as well as actual hostnames. *David Woodhouse* * The 'MinProtocol' and 'MaxProtocol' configuration commands now silently ignore TLS protocol version bounds when configuring DTLS-based contexts, and conversely, silently ignore DTLS protocol version bounds when configuring TLS-based contexts. The commands can be repeated to set bounds of both types. The same applies with the corresponding "min_protocol" and "max_protocol" command-line switches, in case some application uses both TLS and DTLS. SSL_CTX instances that are created for a fixed protocol version (e.g. `TLSv1_server_method()`) also silently ignore version bounds. Previously attempts to apply bounds to these protocol versions would result in an error. Now only the "version-flexible" SSL_CTX instances are subject to limits in configuration files in command-line options. *Viktor Dukhovni* * Deprecated the `ENGINE` API. Engines should be replaced with providers going forward. *Paul Dale* * Reworked the recorded ERR codes to make better space for system errors. To distinguish them, the macro `ERR_SYSTEM_ERROR()` indicates if the given code is a system error (true) or an OpenSSL error (false). *Richard Levitte* * Reworked the test perl framework to better allow parallel testing. *Nicola Tuveri and David von Oheimb* * Added ciphertext stealing algorithms AES-128-CBC-CTS, AES-192-CBC-CTS and AES-256-CBC-CTS to the providers. CS1, CS2 and CS3 variants are supported. *Shane Lontis* * 'Configure' has been changed to figure out the configuration target if none is given on the command line. Consequently, the 'config' script is now only a mere wrapper. All documentation is changed to only mention 'Configure'. *Rich Salz and Richard Levitte* * Added a library context `OSSL_LIB_CTX` that applications as well as other libraries can use to form a separate context within which libcrypto operations are performed. *Richard Levitte* * Added various `_ex` functions to the OpenSSL API that support using a non-default `OSSL_LIB_CTX`. *OpenSSL team* * Handshake now fails if Extended Master Secret extension is dropped on renegotiation. *Tomáš Mráz* * Dropped interactive mode from the `openssl` program. *Richard Levitte* * Deprecated `EVP_PKEY_cmp()` and `EVP_PKEY_cmp_parameters()`. *David von Oheimb and Shane Lontis* * Deprecated `EC_METHOD_get_field_type()`. *Billy Bob Brumley* * Deprecated EC_GFp_simple_method(), EC_GFp_mont_method(), EC_GF2m_simple_method(), EC_GFp_nist_method(), EC_GFp_nistp224_method() EC_GFp_nistp256_method(), and EC_GFp_nistp521_method(). *Billy Bob Brumley* * Deprecated EC_GROUP_new(), EC_GROUP_method_of(), and EC_POINT_method_of(). *Billy Bob Brumley* * Add CAdES-BES signature verification support, mostly derived from ESSCertIDv2 TS (RFC 5816) contribution by Marek Klein. *Filipe Raimundo da Silva* * Add CAdES-BES signature scheme and attributes support (RFC 5126) to CMS API. *Antonio Iacono* * Added the AuthEnvelopedData content type structure (RFC 5083) with AES-GCM parameter (RFC 5084) for the Cryptographic Message Syntax (CMS). *Jakub Zelenka* * Deprecated EC_POINT_make_affine() and EC_POINTs_make_affine(). *Billy Bob Brumley* * Deprecated EC_GROUP_precompute_mult(), EC_GROUP_have_precompute_mult(), and EC_KEY_precompute_mult(). *Billy Bob Brumley* * Deprecated EC_POINTs_mul(). *Billy Bob Brumley* * Removed FIPS_mode() and FIPS_mode_set(). *Shane Lontis* * The SSL option SSL_OP_IGNORE_UNEXPECTED_EOF is introduced. *Dmitry Belyavskiy* * Deprecated EC_POINT_set_Jprojective_coordinates_GFp() and EC_POINT_get_Jprojective_coordinates_GFp(). *Billy Bob Brumley* * Added OSSL_PARAM_BLD to the public interface. This allows OSSL_PARAM arrays to be more easily constructed via a series of utility functions. Create a parameter builder using OSSL_PARAM_BLD_new(), add parameters using the various push functions and finally convert to a passable OSSL_PARAM array using OSSL_PARAM_BLD_to_param(). *Paul Dale* * The security strength of SHA1 and MD5 based signatures in TLS has been reduced. *Kurt Roeckx* * Added EVP_PKEY_set_type_by_keymgmt(), to initialise an EVP_PKEY to contain a provider side internal key. *Richard Levitte* * ASN1_verify(), ASN1_digest() and ASN1_sign() have been deprecated. *Richard Levitte* * Project text documents not yet having a proper file name extension (`HACKING`, `LICENSE`, `NOTES*`, `README*`, `VERSION`) have been renamed to `*.md` as far as reasonable, else `*.txt`, for better use with file managers. *David von Oheimb* * The main project documents (README, NEWS, CHANGES, INSTALL, SUPPORT) have been converted to Markdown with the goal to produce documents which not only look pretty when viewed online in the browser, but remain well readable inside a plain text editor. To achieve this goal, a 'minimalistic' Markdown style has been applied which avoids formatting elements that interfere too much with the reading flow in the text file. For example, it * avoids [ATX headings][] and uses [setext headings][] instead (which works for `

` and `

` headings only). * avoids [inline links][] and uses [reference links][] instead. * avoids [fenced code blocks][] and uses [indented code blocks][] instead. [ATX headings]: https://github.github.com/gfm/#atx-headings [setext headings]: https://github.github.com/gfm/#setext-headings [inline links]: https://github.github.com/gfm/#inline-link [reference links]: https://github.github.com/gfm/#reference-link [fenced code blocks]: https://github.github.com/gfm/#fenced-code-blocks [indented code blocks]: https://github.github.com/gfm/#indented-code-blocks *Matthias St. Pierre* * The test suite is changed to preserve results of each test recipe. A new directory test-runs/ with subdirectories named like the test recipes are created in the build tree for this purpose. *Richard Levitte* * Added an implementation of CMP and CRMF (RFC 4210, RFC 4211 RFC 6712). This adds `crypto/cmp/`, `crpyto/crmf/`, `apps/cmp.c`, and `test/cmp_*`. See L and L as starting points. *David von Oheimb, Martin Peylo* * Generalized the HTTP client code from `crypto/ocsp/` into `crpyto/http/`. It supports arbitrary request and response content types, GET redirection, TLS, connections via HTTP(S) proxies, connections and exchange via user-defined BIOs (allowing implicit connections), persistent connections, and timeout checks. See L etc. for details. The legacy OCSP-focused (and only partly documented) API is retained for backward compatibility, while most of it is deprecated. *David von Oheimb* * Added `util/check-format.pl`, a tool for checking adherence to the OpenSSL coding style . The checks performed are incomplete and yield some false positives. Still the tool should be useful for detecting most typical glitches. *David von Oheimb* * `BIO_do_connect()` and `BIO_do_handshake()` have been extended: If domain name resolution yields multiple IP addresses all of them are tried after `connect()` failures. *David von Oheimb* * All of the low level RSA functions have been deprecated. *Paul Dale* * X509 certificates signed using SHA1 are no longer allowed at security level 1 and above. *Kurt Roeckx* * The command line utilities dhparam, dsa, gendsa and dsaparam have been modified to use PKEY APIs. These commands are now in maintenance mode and no new features will be added to them. *Paul Dale* * The command line utility rsautl has been deprecated. *Paul Dale* * The command line utilities genrsa and rsa have been modified to use PKEY APIs. They now write PKCS#8 keys by default. These commands are now in maintenance mode and no new features will be added to them. *Paul Dale* * All of the low level DH functions have been deprecated. *Paul Dale and Matt Caswell* * All of the low level DSA functions have been deprecated. *Paul Dale* * Reworked the treatment of EC EVP_PKEYs with the SM2 curve to automatically become EVP_PKEY_SM2 rather than EVP_PKEY_EC. *Richard Levitte* * Deprecated low level ECDH and ECDSA functions. *Paul Dale* * Deprecated EVP_PKEY_decrypt_old() and EVP_PKEY_encrypt_old(). *Richard Levitte* * Enhanced the documentation of EVP_PKEY_get_size(), EVP_PKEY_get_bits() and EVP_PKEY_get_security_bits(). Especially EVP_PKEY_get_size() needed a new formulation to include all the things it can be used for, as well as words of caution. *Richard Levitte* * The SSL_CTX_set_tlsext_ticket_key_cb(3) function has been deprecated. *Paul Dale* * All of the low level HMAC functions have been deprecated. *Paul Dale and David von Oheimb* * Over two thousand fixes were made to the documentation, including: - Common options (such as -rand/-writerand, TLS version control, etc) were refactored and point to newly-enhanced descriptions in openssl.pod. - Added style conformance for all options (with help from Richard Levitte), documented all reported missing options, added a CI build to check that all options are documented and that no unimplemented options are documented. - Documented some internals, such as all use of environment variables. - Addressed all internal broken L<> references. *Rich Salz* * All of the low level CMAC functions have been deprecated. *Paul Dale* * The low-level MD2, MD4, MD5, MDC2, RIPEMD160 and Whirlpool digest functions have been deprecated. *Paul Dale and David von Oheimb* * Corrected the documentation of the return values from the `EVP_DigestSign*` set of functions. The documentation mentioned negative values for some errors, but this was never the case, so the mention of negative values was removed. Code that followed the documentation and thereby check with something like `EVP_DigestSignInit(...) <= 0` will continue to work undisturbed. *Richard Levitte* * All of the low level cipher functions have been deprecated. *Matt Caswell and Paul Dale* * Removed include/openssl/opensslconf.h.in and replaced it with include/openssl/configuration.h.in, which differs in not including . A short header include/openssl/opensslconf.h was added to include both. This allows internal hacks where one might need to modify the set of configured macros, for example this if deprecated symbols are still supposed to be available internally: #include #undef OPENSSL_NO_DEPRECATED #define OPENSSL_SUPPRESS_DEPRECATED #include This should not be used by applications that use the exported symbols, as that will lead to linking errors. *Richard Levitte* * Fixed an overflow bug in the x64_64 Montgomery squaring procedure used in exponentiation with 512-bit moduli. No EC algorithms are affected. Analysis suggests that attacks against 2-prime RSA1024, 3-prime RSA1536, and DSA1024 as a result of this defect would be very difficult to perform and are not believed likely. Attacks against DH512 are considered just feasible. However, for an attack the target would have to re-use the DH512 private key, which is not recommended anyway. Also applications directly using the low-level API BN_mod_exp may be affected if they use BN_FLG_CONSTTIME. ([CVE-2019-1551]) *Andy Polyakov* * Most memory-debug features have been deprecated, and the functionality replaced with no-ops. *Rich Salz* * Added documentation for the STACK API. *Rich Salz* * Introduced a new method type and API, OSSL_ENCODER, to represent generic encoders. These do the same sort of job that PEM writers and d2i functions do, but with support for methods supplied by providers, and the possibility for providers to support other formats as well. *Richard Levitte* * Introduced a new method type and API, OSSL_DECODER, to represent generic decoders. These do the same sort of job that PEM readers and i2d functions do, but with support for methods supplied by providers, and the possibility for providers to support other formats as well. *Richard Levitte* * Added a .pragma directive to the syntax of configuration files, to allow varying behavior in a supported and predictable manner. Currently added pragma: .pragma dollarid:on This allows dollar signs to be a keyword character unless it's followed by a opening brace or parenthesis. This is useful for platforms where dollar signs are commonly used in names, such as volume names and system directory names on VMS. *Richard Levitte* * Added functionality to create an EVP_PKEY from user data. *Richard Levitte* * Change the interpretation of the '--api' configuration option to mean that this is a desired API compatibility level with no further meaning. The previous interpretation, that this would also mean to remove all deprecated symbols up to and including the given version, no requires that 'no-deprecated' is also used in the configuration. When building applications, the desired API compatibility level can be set with the OPENSSL_API_COMPAT macro like before. For API compatibility version below 3.0, the old style numerical value is valid as before, such as -DOPENSSL_API_COMPAT=0x10100000L. For version 3.0 and on, the value is expected to be the decimal value calculated from the major and minor version like this: MAJOR * 10000 + MINOR * 100 Examples: -DOPENSSL_API_COMPAT=30000 For 3.0 -DOPENSSL_API_COMPAT=30200 For 3.2 To hide declarations that are deprecated up to and including the given API compatibility level, -DOPENSSL_NO_DEPRECATED must be given when building the application as well. *Richard Levitte* * Added the X509_LOOKUP_METHOD called X509_LOOKUP_store, to allow access to certificate and CRL stores via URIs and OSSL_STORE loaders. This adds the following functions: - X509_LOOKUP_store() - X509_STORE_load_file() - X509_STORE_load_path() - X509_STORE_load_store() - SSL_add_store_cert_subjects_to_stack() - SSL_CTX_set_default_verify_store() - SSL_CTX_load_verify_file() - SSL_CTX_load_verify_dir() - SSL_CTX_load_verify_store() *Richard Levitte* * Added a new method to gather entropy on VMS, based on SYS$GET_ENTROPY. The presence of this system service is determined at run-time. *Richard Levitte* * Added functionality to create an EVP_PKEY context based on data for methods from providers. This takes an algorithm name and a property query string and simply stores them, with the intent that any operation that uses this context will use those strings to fetch the needed methods implicitly, thereby making the port of application written for pre-3.0 OpenSSL easier. *Richard Levitte* * The undocumented function NCONF_WIN32() has been deprecated; for conversion details see the HISTORY section of doc/man5/config.pod *Rich Salz* * Introduced the new functions EVP_DigestSignInit_ex() and EVP_DigestVerifyInit_ex(). The macros EVP_DigestSignUpdate() and EVP_DigestVerifyUpdate() have been converted to functions. See the man pages for further details. *Matt Caswell* * Over two thousand fixes were made to the documentation, including: adding missing command flags, better style conformance, documentation of internals, etc. *Rich Salz, Richard Levitte* * s390x assembly pack: add hardware-support for P-256, P-384, P-521, X25519, X448, Ed25519 and Ed448. *Patrick Steuer* * Print all values for a PKCS#12 attribute with 'openssl pkcs12', not just the first value. *Jon Spillett* * Deprecated the public definition of `ERR_STATE` as well as the function `ERR_get_state()`. This is done in preparation of making `ERR_STATE` an opaque type. *Richard Levitte* * Added ERR functionality to give callers access to the stored function names that have replaced the older function code based functions. New functions are ERR_peek_error_func(), ERR_peek_last_error_func(), ERR_peek_error_data(), ERR_peek_last_error_data(), ERR_get_error_all(), ERR_peek_error_all() and ERR_peek_last_error_all(). Deprecate ERR functions ERR_get_error_line(), ERR_get_error_line_data(), ERR_peek_error_line_data(), ERR_peek_last_error_line_data() and ERR_func_error_string(). *Richard Levitte* * Extended testing to be verbose for failing tests only. The make variables VERBOSE_FAILURE or VF can be used to enable this: $ make VF=1 test # Unix $ mms /macro=(VF=1) test ! OpenVMS $ nmake VF=1 test # Windows *Richard Levitte* * Added the `-copy_extensions` option to the `x509` command for use with `-req` and `-x509toreq`. When given with the `copy` or `copyall` argument, all extensions in the request are copied to the certificate or vice versa. *David von Oheimb*, *Kirill Stefanenkov * * Added the `-copy_extensions` option to the `req` command for use with `-x509`. When given with the `copy` or `copyall` argument, all extensions in the certification request are copied to the certificate. *David von Oheimb* * The `x509`, `req`, and `ca` commands now make sure that X.509v3 certificates they generate are by default RFC 5280 compliant in the following sense: There is a subjectKeyIdentifier extension with a hash value of the public key and for not self-signed certs there is an authorityKeyIdentifier extension with a keyIdentifier field or issuer information identifying the signing key. This is done unless some configuration overrides the new default behavior, such as `subjectKeyIdentifier = none` and `authorityKeyIdentifier = none`. *David von Oheimb* * Added several checks to `X509_verify_cert()` according to requirements in RFC 5280 in case `X509_V_FLAG_X509_STRICT` is set (which may be done by using the CLI option `-x509_strict`): * The basicConstraints of CA certificates must be marked critical. * CA certificates must explicitly include the keyUsage extension. * If a pathlenConstraint is given the key usage keyCertSign must be allowed. * The issuer name of any certificate must not be empty. * The subject name of CA certs, certs with keyUsage crlSign, and certs without subjectAlternativeName must not be empty. * If a subjectAlternativeName extension is given it must not be empty. * The signatureAlgorithm field and the cert signature must be consistent. * Any given authorityKeyIdentifier and any given subjectKeyIdentifier must not be marked critical. * The authorityKeyIdentifier must be given for X.509v3 certs unless they are self-signed. * The subjectKeyIdentifier must be given for all X.509v3 CA certs. *David von Oheimb* * Certificate verification using `X509_verify_cert()` meanwhile rejects EC keys with explicit curve parameters (specifiedCurve) as required by RFC 5480. *Tomáš Mráz* * For built-in EC curves, ensure an EC_GROUP built from the curve name is used even when parsing explicit parameters, when loading a encoded key or calling `EC_GROUP_new_from_ecpkparameters()`/ `EC_GROUP_new_from_ecparameters()`. This prevents bypass of security hardening and performance gains, especially for curves with specialized EC_METHODs. By default, if a key encoded with explicit parameters is loaded and later encoded, the output is still encoded with explicit parameters, even if internally a "named" EC_GROUP is used for computation. *Nicola Tuveri* * Compute ECC cofactors if not provided during EC_GROUP construction. Before this change, EC_GROUP_set_generator would accept order and/or cofactor as NULL. After this change, only the cofactor parameter can be NULL. It also does some minimal sanity checks on the passed order. ([CVE-2019-1547]) *Billy Bob Brumley* * Fixed a padding oracle in PKCS7_dataDecode and CMS_decrypt_set1_pkey. An attack is simple, if the first CMS_recipientInfo is valid but the second CMS_recipientInfo is chosen ciphertext. If the second recipientInfo decodes to PKCS #1 v1.5 form plaintext, the correct encryption key will be replaced by garbage, and the message cannot be decoded, but if the RSA decryption fails, the correct encryption key is used and the recipient will not notice the attack. As a work around for this potential attack the length of the decrypted key must be equal to the cipher default key length, in case the certifiate is not given and all recipientInfo are tried out. The old behaviour can be re-enabled in the CMS code by setting the CMS_DEBUG_DECRYPT flag. *Bernd Edlinger* * Early start up entropy quality from the DEVRANDOM seed source has been improved for older Linux systems. The RAND subsystem will wait for /dev/random to be producing output before seeding from /dev/urandom. The seeded state is stored for future library initialisations using a system global shared memory segment. The shared memory identifier can be configured by defining OPENSSL_RAND_SEED_DEVRANDOM_SHM_ID to the desired value. The default identifier is 114. *Paul Dale* * Revised BN_generate_prime_ex to not avoid factors 2..17863 in p-1 when primes for RSA keys are computed. Since we previously always generated primes == 2 (mod 3) for RSA keys, the 2-prime and 3-prime RSA modules were easy to distinguish, since `N = p*q = 1 (mod 3)`, but `N = p*q*r = 2 (mod 3)`. Therefore fingerprinting 2-prime vs. 3-prime RSA keys was possible by computing N mod 3. This avoids possible fingerprinting of newly generated RSA modules. *Bernd Edlinger* * Correct the extended master secret constant on EBCDIC systems. Without this fix TLS connections between an EBCDIC system and a non-EBCDIC system that negotiate EMS will fail. Unfortunately this also means that TLS connections between EBCDIC systems with this fix, and EBCDIC systems without this fix will fail if they negotiate EMS. *Matt Caswell* * Changed the library initialisation so that the config file is now loaded by default. This was already the case for libssl. It now occurs for both libcrypto and libssl. Use the OPENSSL_INIT_NO_LOAD_CONFIG option to `OPENSSL_init_crypto()` to suppress automatic loading of a config file. *Matt Caswell* * Introduced new error raising macros, `ERR_raise()` and `ERR_raise_data()`, where the former acts as a replacement for `ERR_put_error()`, and the latter replaces the combination `ERR_put_error()` + `ERR_add_error_data()`. `ERR_raise_data()` adds more flexibility by taking a format string and an arbitrary number of arguments following it, to be processed with `BIO_snprintf()`. *Richard Levitte* * Introduced a new function, `OSSL_PROVIDER_available()`, which can be used to check if a named provider is loaded and available. When called, it will also activate all fallback providers if such are still present. *Richard Levitte* * Enforce a minimum DH modulus size of 512 bits. *Bernd Edlinger* * Changed DH parameters to generate the order q subgroup instead of 2q. Previously generated DH parameters are still accepted by DH_check but DH_generate_key works around that by clearing bit 0 of the private key for those. This avoids leaking bit 0 of the private key. *Bernd Edlinger* * Significantly reduce secure memory usage by the randomness pools. *Paul Dale* * `{CRYPTO,OPENSSL}_mem_debug_{push,pop}` are now no-ops and have been deprecated. *Rich Salz* * A new type, EVP_KEYEXCH, has been introduced to represent key exchange algorithms. An implementation of a key exchange algorithm can be obtained by using the function EVP_KEYEXCH_fetch(). An EVP_KEYEXCH algorithm can be used in a call to EVP_PKEY_derive_init_ex() which works in a similar way to the older EVP_PKEY_derive_init() function. See the man pages for the new functions for further details. *Matt Caswell* * The EVP_PKEY_CTX_set_dh_pad() macro has now been converted to a function. *Matt Caswell* * Removed the function names from error messages and deprecated the xxx_F_xxx define's. *Richard Levitte* * Removed NextStep support and the macro OPENSSL_UNISTD *Rich Salz* * Removed DES_check_key. Also removed OPENSSL_IMPLEMENT_GLOBAL, OPENSSL_GLOBAL_REF, OPENSSL_DECLARE_GLOBAL. Also removed "export var as function" capability; we do not export variables, only functions. *Rich Salz* * RC5_32_set_key has been changed to return an int type, with 0 indicating an error and 1 indicating success. In previous versions of OpenSSL this was a void type. If a key was set longer than the maximum possible this would crash. *Matt Caswell* * Support SM2 signing and verification schemes with X509 certificate. *Paul Yang* * Use SHA256 as the default digest for TS query in the `ts` app. *Tomáš Mráz* * Change PBKDF2 to conform to SP800-132 instead of the older PKCS5 RFC2898. *Shane Lontis* * Default cipher lists/suites are now available via a function, the #defines are deprecated. *Todd Short* * Add target VC-WIN32-UWP, VC-WIN64A-UWP, VC-WIN32-ARM-UWP and VC-WIN64-ARM-UWP in Windows OneCore target for making building libraries for Windows Store apps easier. Also, the "no-uplink" option has been added. *Kenji Mouri* * Join the directories crypto/x509 and crypto/x509v3 *Richard Levitte* * Added command 'openssl kdf' that uses the EVP_KDF API. *Shane Lontis* * Added command 'openssl mac' that uses the EVP_MAC API. *Shane Lontis* * Added OPENSSL_info() to get diverse built-in OpenSSL data, such as default directories. Also added the command 'openssl info' for scripting purposes. *Richard Levitte* * The functions AES_ige_encrypt() and AES_bi_ige_encrypt() have been deprecated. *Matt Caswell* * Add prediction resistance to the DRBG reseeding process. *Paul Dale* * Limit the number of blocks in a data unit for AES-XTS to 2^20 as mandated by IEEE Std 1619-2018. *Paul Dale* * Added newline escaping functionality to a filename when using openssl dgst. This output format is to replicate the output format found in the `*sum` checksum programs. This aims to preserve backward compatibility. *Matt Eaton, Richard Levitte, and Paul Dale* * Removed the heartbeat message in DTLS feature, as it has very little usage and doesn't seem to fulfill a valuable purpose. The configuration option is now deprecated. *Richard Levitte* * Changed the output of 'openssl {digestname} < file' to display the digest name in its output. *Richard Levitte* * Added a new generic trace API which provides support for enabling instrumentation through trace output. *Richard Levitte & Matthias St. Pierre* * Added build tests for C++. These are generated files that only do one thing, to include one public OpenSSL head file each. This tests that the public header files can be usefully included in a C++ application. This test isn't enabled by default. It can be enabled with the option 'enable-buildtest-c++'. *Richard Levitte* * Added KB KDF (EVP_KDF_KB) to EVP_KDF. *Robbie Harwood* * Added SSH KDF (EVP_KDF_SSHKDF) and KRB5 KDF (EVP_KDF_KRB5KDF) to EVP_KDF. *Simo Sorce* * Added Single Step KDF (EVP_KDF_SS), X963 KDF, and X942 KDF to EVP_KDF. *Shane Lontis* * Added KMAC to EVP_MAC. *Shane Lontis* * Added property based algorithm implementation selection framework to the core. *Paul Dale* * Added SCA hardening for modular field inversion in EC_GROUP through a new dedicated field_inv() pointer in EC_METHOD. This also addresses a leakage affecting conversions from projective to affine coordinates. *Billy Bob Brumley, Nicola Tuveri* * Added EVP_KDF, an EVP layer KDF API, to simplify adding KDF and PRF implementations. This includes an EVP_PKEY to EVP_KDF bridge for those algorithms that were already supported through the EVP_PKEY API (scrypt, TLS1 PRF and HKDF). The low-level KDF functions for PBKDF2 and scrypt are now wrappers that call EVP_KDF. *David Makepeace* * Build devcrypto engine as a dynamic engine. *Eneas U de Queiroz* * Add keyed BLAKE2 to EVP_MAC. *Antoine Salon* * Fix a bug in the computation of the endpoint-pair shared secret used by DTLS over SCTP. This breaks interoperability with older versions of OpenSSL like OpenSSL 1.1.0 and OpenSSL 1.0.2. There is a runtime switch SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG (off by default) enabling interoperability with such broken implementations. However, enabling this switch breaks interoperability with correct implementations. * Fix a use after free bug in d2i_X509_PUBKEY when overwriting a re-used X509_PUBKEY object if the second PUBKEY is malformed. *Bernd Edlinger* * Move strictness check from EVP_PKEY_asn1_new() to EVP_PKEY_asn1_add0(). *Richard Levitte* * Changed the license to the Apache License v2.0. *Richard Levitte* * Switch to a new version scheme using three numbers MAJOR.MINOR.PATCH. - Major releases (indicated by incrementing the MAJOR release number) may introduce incompatible API/ABI changes. - Minor releases (indicated by incrementing the MINOR release number) may introduce new features but retain API/ABI compatibility. - Patch releases (indicated by incrementing the PATCH number) are intended for bug fixes and other improvements of existing features only (like improving performance or adding documentation) and retain API/ABI compatibility. *Richard Levitte* * Add support for RFC5297 SIV mode (siv128), including AES-SIV. *Todd Short* * Remove the 'dist' target and add a tarball building script. The 'dist' target has fallen out of use, and it shouldn't be necessary to configure just to create a source distribution. *Richard Levitte* * Recreate the OS390-Unix config target. It no longer relies on a special script like it did for OpenSSL pre-1.1.0. *Richard Levitte* * Instead of having the source directories listed in Configure, add a 'build.info' keyword SUBDIRS to indicate what sub-directories to look into. *Richard Levitte* * Add GMAC to EVP_MAC. *Paul Dale* * Ported the HMAC, CMAC and SipHash EVP_PKEY_METHODs to EVP_MAC. *Richard Levitte* * Added EVP_MAC, an EVP layer MAC API, to simplify adding MAC implementations. This includes a generic EVP_PKEY to EVP_MAC bridge, to facilitate the continued use of MACs through raw private keys in functionality such as `EVP_DigestSign*` and `EVP_DigestVerify*`. *Richard Levitte* * Deprecate ECDH_KDF_X9_62(). *Antoine Salon* * Added EVP_PKEY_ECDH_KDF_X9_63 and ecdh_KDF_X9_63() as replacements for the EVP_PKEY_ECDH_KDF_X9_62 KDF type and ECDH_KDF_X9_62(). The old names are retained for backwards compatibility. *Antoine Salon* * AES-XTS mode now enforces that its two keys are different to mitigate the attacked described in "Efficient Instantiations of Tweakable Blockciphers and Refinements to Modes OCB and PMAC" by Phillip Rogaway. Details of this attack can be obtained from: *Paul Dale* * Rename the object files, i.e. give them other names than in previous versions. Their names now include the name of the final product, as well as its type mnemonic (bin, lib, shlib). *Richard Levitte* * Added new option for 'openssl list', '-objects', which will display the list of built in objects, i.e. OIDs with names. *Richard Levitte* * Added the options `-crl_lastupdate` and `-crl_nextupdate` to `openssl ca`, allowing the `lastUpdate` and `nextUpdate` fields in the generated CRL to be set explicitly. *Chris Novakovic* * Added support for Linux Kernel TLS data-path. The Linux Kernel data-path improves application performance by removing data copies and providing applications with zero-copy system calls such as sendfile and splice. *Boris Pismenny* * The SSL option SSL_OP_CLEANSE_PLAINTEXT is introduced. *Martin Elshuber* * `PKCS12_parse` now maintains the order of the parsed certificates when outputting them via `*ca` (rather than reversing it). *David von Oheimb* * Deprecated pthread fork support methods. *Randall S. Becker* * Added support for FFDHE key exchange in TLS 1.3. *Raja Ashok* * Added a new concept for OpenSSL plugability: providers. This functionality is designed to replace the ENGINE API and ENGINE implementations, and to be much more dynamic, allowing provider authors to introduce new algorithms among other things, as long as there's an API that supports the algorithm type. With this concept comes a new core API for interaction between libcrypto and provider implementations. Public libcrypto functions that want to use providers do so through this core API. The main documentation for this core API is found in doc/man7/provider.pod, doc/man7/provider-base.pod, and they in turn refer to other manuals describing the API specific for supported algorithm types (also called operations). *The OpenSSL team* OpenSSL 1.1.1 ------------- ### Changes between 1.1.1l and 1.1.1m [xx XXX xxxx] * Avoid loading of a dynamic engine twice. *Bernd Edlinger* * Prioritise DANE TLSA issuer certs over peer certs *Viktor Dukhovni* * Fixed random API for MacOS prior to 10.12 These MacOS versions don't support the CommonCrypto APIs *Lenny Primak* ### Changes between 1.1.1k and 1.1.1l [24 Aug 2021] * Fixed an SM2 Decryption Buffer Overflow. In order to decrypt SM2 encrypted data an application is expected to call the API function EVP_PKEY_decrypt(). Typically an application will call this function twice. The first time, on entry, the "out" parameter can be NULL and, on exit, the "outlen" parameter is populated with the buffer size required to hold the decrypted plaintext. The application can then allocate a sufficiently sized buffer and call EVP_PKEY_decrypt() again, but this time passing a non-NULL value for the "out" parameter. A bug in the implementation of the SM2 decryption code means that the calculation of the buffer size required to hold the plaintext returned by the first call to EVP_PKEY_decrypt() can be smaller than the actual size required by the second call. This can lead to a buffer overflow when EVP_PKEY_decrypt() is called by the application a second time with a buffer that is too small. A malicious attacker who is able present SM2 content for decryption to an application could cause attacker chosen data to overflow the buffer by up to a maximum of 62 bytes altering the contents of other data held after the buffer, possibly changing application behaviour or causing the application to crash. The location of the buffer is application dependent but is typically heap allocated. ([CVE-2021-3711]) *Matt Caswell* * Fixed various read buffer overruns processing ASN.1 strings ASN.1 strings are represented internally within OpenSSL as an ASN1_STRING structure which contains a buffer holding the string data and a field holding the buffer length. This contrasts with normal C strings which are repesented as a buffer for the string data which is terminated with a NUL (0) byte. Although not a strict requirement, ASN.1 strings that are parsed using OpenSSL's own "d2i" functions (and other similar parsing functions) as well as any string whose value has been set with the ASN1_STRING_set() function will additionally NUL terminate the byte array in the ASN1_STRING structure. However, it is possible for applications to directly construct valid ASN1_STRING structures which do not NUL terminate the byte array by directly setting the "data" and "length" fields in the ASN1_STRING array. This can also happen by using the ASN1_STRING_set0() function. Numerous OpenSSL functions that print ASN.1 data have been found to assume that the ASN1_STRING byte array will be NUL terminated, even though this is not guaranteed for strings that have been directly constructed. Where an application requests an ASN.1 structure to be printed, and where that ASN.1 structure contains ASN1_STRINGs that have been directly constructed by the application without NUL terminating the "data" field, then a read buffer overrun can occur. The same thing can also occur during name constraints processing of certificates (for example if a certificate has been directly constructed by the application instead of loading it via the OpenSSL parsing functions, and the certificate contains non NUL terminated ASN1_STRING structures). It can also occur in the X509_get1_email(), X509_REQ_get1_email() and X509_get1_ocsp() functions. If a malicious actor can cause an application to directly construct an ASN1_STRING and then process it through one of the affected OpenSSL functions then this issue could be hit. This might result in a crash (causing a Denial of Service attack). It could also result in the disclosure of private memory contents (such as private keys, or sensitive plaintext). ([CVE-2021-3712]) *Matt Caswell* ### Changes between 1.1.1j and 1.1.1k [25 Mar 2021] * Fixed a problem with verifying a certificate chain when using the X509_V_FLAG_X509_STRICT flag. This flag enables additional security checks of the certificates present in a certificate chain. It is not set by default. Starting from OpenSSL version 1.1.1h a check to disallow certificates in the chain that have explicitly encoded elliptic curve parameters was added as an additional strict check. An error in the implementation of this check meant that the result of a previous check to confirm that certificates in the chain are valid CA certificates was overwritten. This effectively bypasses the check that non-CA certificates must not be able to issue other certificates. If a "purpose" has been configured then there is a subsequent opportunity for checks that the certificate is a valid CA. All of the named "purpose" values implemented in libcrypto perform this check. Therefore, where a purpose is set the certificate chain will still be rejected even when the strict flag has been used. A purpose is set by default in libssl client and server certificate verification routines, but it can be overridden or removed by an application. In order to be affected, an application must explicitly set the X509_V_FLAG_X509_STRICT verification flag and either not set a purpose for the certificate verification or, in the case of TLS client or server applications, override the default purpose. ([CVE-2021-3450]) *Tomáš Mráz* * Fixed an issue where an OpenSSL TLS server may crash if sent a maliciously crafted renegotiation ClientHello message from a client. If a TLSv1.2 renegotiation ClientHello omits the signature_algorithms extension (where it was present in the initial ClientHello), but includes a signature_algorithms_cert extension then a NULL pointer dereference will result, leading to a crash and a denial of service attack. A server is only vulnerable if it has TLSv1.2 and renegotiation enabled (which is the default configuration). OpenSSL TLS clients are not impacted by this issue. ([CVE-2021-3449]) *Peter Kästle and Samuel Sapalski* ### Changes between 1.1.1i and 1.1.1j [16 Feb 2021] * Fixed the X509_issuer_and_serial_hash() function. It attempts to create a unique hash value based on the issuer and serial number data contained within an X509 certificate. However it was failing to correctly handle any errors that may occur while parsing the issuer field (which might occur if the issuer field is maliciously constructed). This may subsequently result in a NULL pointer deref and a crash leading to a potential denial of service attack. ([CVE-2021-23841]) *Matt Caswell* * Fixed the RSA_padding_check_SSLv23() function and the RSA_SSLV23_PADDING padding mode to correctly check for rollback attacks. This is considered a bug in OpenSSL 1.1.1 because it does not support SSLv2. In 1.0.2 this is CVE-2021-23839. *Matt Caswell* Fixed the EVP_CipherUpdate, EVP_EncryptUpdate and EVP_DecryptUpdate functions. Previously they could overflow the output length argument in some cases where the input length is close to the maximum permissable length for an integer on the platform. In such cases the return value from the function call would be 1 (indicating success), but the output length value would be negative. This could cause applications to behave incorrectly or crash. ([CVE-2021-23840]) *Matt Caswell* * Fixed SRP_Calc_client_key so that it runs in constant time. The previous implementation called BN_mod_exp without setting BN_FLG_CONSTTIME. This could be exploited in a side channel attack to recover the password. Since the attack is local host only this is outside of the current OpenSSL threat model and therefore no CVE is assigned. Thanks to Mohammed Sabt and Daniel De Almeida Braga for reporting this issue. *Matt Caswell* ### Changes between 1.1.1h and 1.1.1i [8 Dec 2020] * Fixed NULL pointer deref in the GENERAL_NAME_cmp function This function could crash if both GENERAL_NAMEs contain an EDIPARTYNAME. If an attacker can control both items being compared then this could lead to a possible denial of service attack. OpenSSL itself uses the GENERAL_NAME_cmp function for two purposes: 1) Comparing CRL distribution point names between an available CRL and a CRL distribution point embedded in an X509 certificate 2) When verifying that a timestamp response token signer matches the timestamp authority name (exposed via the API functions TS_RESP_verify_response and TS_RESP_verify_token) ([CVE-2020-1971]) *Matt Caswell* ### Changes between 1.1.1g and 1.1.1h [22 Sep 2020] * Certificates with explicit curve parameters are now disallowed in verification chains if the X509_V_FLAG_X509_STRICT flag is used. *Tomáš Mráz* * The 'MinProtocol' and 'MaxProtocol' configuration commands now silently ignore TLS protocol version bounds when configuring DTLS-based contexts, and conversely, silently ignore DTLS protocol version bounds when configuring TLS-based contexts. The commands can be repeated to set bounds of both types. The same applies with the corresponding "min_protocol" and "max_protocol" command-line switches, in case some application uses both TLS and DTLS. SSL_CTX instances that are created for a fixed protocol version (e.g. TLSv1_server_method()) also silently ignore version bounds. Previously attempts to apply bounds to these protocol versions would result in an error. Now only the "version-flexible" SSL_CTX instances are subject to limits in configuration files in command-line options. *Viktor Dukhovni* * Handshake now fails if Extended Master Secret extension is dropped on renegotiation. *Tomáš Mráz* * The Oracle Developer Studio compiler will start reporting deprecated APIs ### Changes between 1.1.1f and 1.1.1g [21 Apr 2020] * Fixed segmentation fault in SSL_check_chain() Server or client applications that call the SSL_check_chain() function during or after a TLS 1.3 handshake may crash due to a NULL pointer dereference as a result of incorrect handling of the "signature_algorithms_cert" TLS extension. The crash occurs if an invalid or unrecognised signature algorithm is received from the peer. This could be exploited by a malicious peer in a Denial of Service attack. ([CVE-2020-1967]) *Benjamin Kaduk* * Added AES consttime code for no-asm configurations an optional constant time support for AES was added when building openssl for no-asm. Enable with: ./config no-asm -DOPENSSL_AES_CONST_TIME Disable with: ./config no-asm -DOPENSSL_NO_AES_CONST_TIME At this time this feature is by default disabled. It will be enabled by default in 3.0. *Bernd Edlinger* ### Changes between 1.1.1e and 1.1.1f [31 Mar 2020] * Revert the change of EOF detection while reading in libssl to avoid regressions in applications depending on the current way of reporting the EOF. As the existing method is not fully accurate the change to reporting the EOF via SSL_ERROR_SSL is kept on the current development branch and will be present in the 3.0 release. *Tomáš Mráz* * Revised BN_generate_prime_ex to not avoid factors 3..17863 in p-1 when primes for RSA keys are computed. Since we previously always generated primes == 2 (mod 3) for RSA keys, the 2-prime and 3-prime RSA modules were easy to distinguish, since N = p*q = 1 (mod 3), but N = p*q*r = 2 (mod 3). Therefore fingerprinting 2-prime vs. 3-prime RSA keys was possible by computing N mod 3. This avoids possible fingerprinting of newly generated RSA modules. *Bernd Edlinger* ### Changes between 1.1.1d and 1.1.1e [17 Mar 2020] * Properly detect EOF while reading in libssl. Previously if we hit an EOF while reading in libssl then we would report an error back to the application (SSL_ERROR_SYSCALL) but errno would be 0. We now add an error to the stack (which means we instead return SSL_ERROR_SSL) and therefore give a hint as to what went wrong. *Matt Caswell* * Check that ed25519 and ed448 are allowed by the security level. Previously signature algorithms not using an MD were not being checked that they were allowed by the security level. *Kurt Roeckx* * Fixed SSL_get_servername() behaviour. The behaviour of SSL_get_servername() was not quite right. The behaviour was not consistent between resumption and normal handshakes, and also not quite consistent with historical behaviour. The behaviour in various scenarios has been clarified and it has been updated to make it match historical behaviour as closely as possible. *Matt Caswell* * *[VMS only]* The header files that the VMS compilers include automatically, `__DECC_INCLUDE_PROLOGUE.H` and `__DECC_INCLUDE_EPILOGUE.H`, use pragmas that the C++ compiler doesn't understand. This is a shortcoming in the compiler, but can be worked around with `__cplusplus` guards. C++ applications that use OpenSSL libraries must be compiled using the qualifier `/NAMES=(AS_IS,SHORTENED)` to be able to use all the OpenSSL functions. Otherwise, only functions with symbols of less than 31 characters can be used, as the linker will not be able to successfully resolve symbols with longer names. *Richard Levitte* * Added a new method to gather entropy on VMS, based on SYS$GET_ENTROPY. The presence of this system service is determined at run-time. *Richard Levitte* * Print all values for a PKCS#12 attribute with 'openssl pkcs12', not just the first value. *Jon Spillett* ### Changes between 1.1.1c and 1.1.1d [10 Sep 2019] * Fixed a fork protection issue. OpenSSL 1.1.1 introduced a rewritten random number generator (RNG). This was intended to include protection in the event of a fork() system call in order to ensure that the parent and child processes did not share the same RNG state. However this protection was not being used in the default case. A partial mitigation for this issue is that the output from a high precision timer is mixed into the RNG state so the likelihood of a parent and child process sharing state is significantly reduced. If an application already calls OPENSSL_init_crypto() explicitly using OPENSSL_INIT_ATFORK then this problem does not occur at all. ([CVE-2019-1549]) *Matthias St. Pierre* * For built-in EC curves, ensure an EC_GROUP built from the curve name is used even when parsing explicit parameters, when loading a encoded key or calling `EC_GROUP_new_from_ecpkparameters()`/ `EC_GROUP_new_from_ecparameters()`. This prevents bypass of security hardening and performance gains, especially for curves with specialized EC_METHODs. By default, if a key encoded with explicit parameters is loaded and later encoded, the output is still encoded with explicit parameters, even if internally a "named" EC_GROUP is used for computation. *Nicola Tuveri* * Compute ECC cofactors if not provided during EC_GROUP construction. Before this change, EC_GROUP_set_generator would accept order and/or cofactor as NULL. After this change, only the cofactor parameter can be NULL. It also does some minimal sanity checks on the passed order. ([CVE-2019-1547]) *Billy Bob Brumley* * Fixed a padding oracle in PKCS7_dataDecode and CMS_decrypt_set1_pkey. An attack is simple, if the first CMS_recipientInfo is valid but the second CMS_recipientInfo is chosen ciphertext. If the second recipientInfo decodes to PKCS #1 v1.5 form plaintext, the correct encryption key will be replaced by garbage, and the message cannot be decoded, but if the RSA decryption fails, the correct encryption key is used and the recipient will not notice the attack. As a work around for this potential attack the length of the decrypted key must be equal to the cipher default key length, in case the certifiate is not given and all recipientInfo are tried out. The old behaviour can be re-enabled in the CMS code by setting the CMS_DEBUG_DECRYPT flag. ([CVE-2019-1563]) *Bernd Edlinger* * Early start up entropy quality from the DEVRANDOM seed source has been improved for older Linux systems. The RAND subsystem will wait for /dev/random to be producing output before seeding from /dev/urandom. The seeded state is stored for future library initialisations using a system global shared memory segment. The shared memory identifier can be configured by defining OPENSSL_RAND_SEED_DEVRANDOM_SHM_ID to the desired value. The default identifier is 114. *Paul Dale* * Correct the extended master secret constant on EBCDIC systems. Without this fix TLS connections between an EBCDIC system and a non-EBCDIC system that negotiate EMS will fail. Unfortunately this also means that TLS connections between EBCDIC systems with this fix, and EBCDIC systems without this fix will fail if they negotiate EMS. *Matt Caswell* * Use Windows installation paths in the mingw builds Mingw isn't a POSIX environment per se, which means that Windows paths should be used for installation. ([CVE-2019-1552]) *Richard Levitte* * Changed DH_check to accept parameters with order q and 2q subgroups. With order 2q subgroups the bit 0 of the private key is not secret but DH_generate_key works around that by clearing bit 0 of the private key for those. This avoids leaking bit 0 of the private key. *Bernd Edlinger* * Significantly reduce secure memory usage by the randomness pools. *Paul Dale* * Revert the DEVRANDOM_WAIT feature for Linux systems The DEVRANDOM_WAIT feature added a select() call to wait for the /dev/random device to become readable before reading from the /dev/urandom device. It turned out that this change had negative side effects on performance which were not acceptable. After some discussion it was decided to revert this feature and leave it up to the OS resp. the platform maintainer to ensure a proper initialization during early boot time. *Matthias St. Pierre* ### Changes between 1.1.1b and 1.1.1c [28 May 2019] * Add build tests for C++. These are generated files that only do one thing, to include one public OpenSSL head file each. This tests that the public header files can be usefully included in a C++ application. This test isn't enabled by default. It can be enabled with the option 'enable-buildtest-c++'. *Richard Levitte* * Enable SHA3 pre-hashing for ECDSA and DSA. *Patrick Steuer* * Change the default RSA, DSA and DH size to 2048 bit instead of 1024. This changes the size when using the `genpkey` command when no size is given. It fixes an omission in earlier changes that changed all RSA, DSA and DH generation commands to use 2048 bits by default. *Kurt Roeckx* * Reorganize the manual pages to consistently have RETURN VALUES, EXAMPLES, SEE ALSO and HISTORY come in that order, and adjust util/fix-doc-nits accordingly. *Paul Yang, Joshua Lock* * Add the missing accessor EVP_PKEY_get0_engine() *Matt Caswell* * Have commands like `s_client` and `s_server` output the signature scheme along with other cipher suite parameters when debugging. *Lorinczy Zsigmond* * Make OPENSSL_config() error agnostic again. *Richard Levitte* * Do the error handling in RSA decryption constant time. *Bernd Edlinger* * Prevent over long nonces in ChaCha20-Poly1305. ChaCha20-Poly1305 is an AEAD cipher, and requires a unique nonce input for every encryption operation. RFC 7539 specifies that the nonce value (IV) should be 96 bits (12 bytes). OpenSSL allows a variable nonce length and front pads the nonce with 0 bytes if it is less than 12 bytes. However it also incorrectly allows a nonce to be set of up to 16 bytes. In this case only the last 12 bytes are significant and any additional leading bytes are ignored. It is a requirement of using this cipher that nonce values are unique. Messages encrypted using a reused nonce value are susceptible to serious confidentiality and integrity attacks. If an application changes the default nonce length to be longer than 12 bytes and then makes a change to the leading bytes of the nonce expecting the new value to be a new unique nonce then such an application could inadvertently encrypt messages with a reused nonce. Additionally the ignored bytes in a long nonce are not covered by the integrity guarantee of this cipher. Any application that relies on the integrity of these ignored leading bytes of a long nonce may be further affected. Any OpenSSL internal use of this cipher, including in SSL/TLS, is safe because no such use sets such a long nonce value. However user applications that use this cipher directly and set a non-default nonce length to be longer than 12 bytes may be vulnerable. This issue was reported to OpenSSL on 16th of March 2019 by Joran Dirk Greef of Ronomon. ([CVE-2019-1543]) *Matt Caswell* * Add DEVRANDOM_WAIT feature for Linux systems On older Linux systems where the getrandom() system call is not available, OpenSSL normally uses the /dev/urandom device for seeding its CSPRNG. Contrary to getrandom(), the /dev/urandom device will not block during early boot when the kernel CSPRNG has not been seeded yet. To mitigate this known weakness, use select() to wait for /dev/random to become readable before reading from /dev/urandom. * Ensure that SM2 only uses SM3 as digest algorithm *Paul Yang* ### Changes between 1.1.1a and 1.1.1b [26 Feb 2019] * Change the info callback signals for the start and end of a post-handshake message exchange in TLSv1.3. In 1.1.1/1.1.1a we used SSL_CB_HANDSHAKE_START and SSL_CB_HANDSHAKE_DONE. Experience has shown that many applications get confused by this and assume that a TLSv1.2 renegotiation has started. This can break KeyUpdate handling. Instead we no longer signal the start and end of a post handshake message exchange (although the messages themselves are still signalled). This could break some applications that were expecting the old signals. However without this KeyUpdate is not usable for many applications. *Matt Caswell* ### Changes between 1.1.1 and 1.1.1a [20 Nov 2018] * Timing vulnerability in DSA signature generation The OpenSSL DSA signature algorithm has been shown to be vulnerable to a timing side channel attack. An attacker could use variations in the signing algorithm to recover the private key. This issue was reported to OpenSSL on 16th October 2018 by Samuel Weiser. ([CVE-2018-0734]) *Paul Dale* * Timing vulnerability in ECDSA signature generation The OpenSSL ECDSA signature algorithm has been shown to be vulnerable to a timing side channel attack. An attacker could use variations in the signing algorithm to recover the private key. This issue was reported to OpenSSL on 25th October 2018 by Samuel Weiser. ([CVE-2018-0735]) *Paul Dale* * Fixed the issue that RAND_add()/RAND_seed() silently discards random input if its length exceeds 4096 bytes. The limit has been raised to a buffer size of two gigabytes and the error handling improved. This issue was reported to OpenSSL by Dr. Falko Strenzke. It has been categorized as a normal bug, not a security issue, because the DRBG reseeds automatically and is fully functional even without additional randomness provided by the application. ### Changes between 1.1.0i and 1.1.1 [11 Sep 2018] * Add a new ClientHello callback. Provides a callback interface that gives the application the ability to adjust the nascent SSL object at the earliest stage of ClientHello processing, immediately after extensions have been collected but before they have been processed. In particular, this callback can adjust the supported TLS versions in response to the contents of the ClientHello *Benjamin Kaduk* * Add SM2 base algorithm support. *Jack Lloyd* * s390x assembly pack: add (improved) hardware-support for the following cryptographic primitives: sha3, shake, aes-gcm, aes-ccm, aes-ctr, aes-ofb, aes-cfb/cfb8, aes-ecb. *Patrick Steuer* * Make EVP_PKEY_asn1_new() a bit stricter about its input. A NULL pem_str parameter is no longer accepted, as it leads to a corrupt table. NULL pem_str is reserved for alias entries only. *Richard Levitte* * Use the new ec_scalar_mul_ladder scaffold to implement a specialized ladder step for prime curves. The new implementation is based on formulae from differential addition-and-doubling in homogeneous projective coordinates from Izu-Takagi "A fast parallel elliptic curve multiplication resistant against side channel attacks" and Brier-Joye "Weierstrass Elliptic Curves and Side-Channel Attacks" Eq. (8) for y-coordinate recovery, modified to work in projective coordinates. *Billy Bob Brumley, Nicola Tuveri* * Change generating and checking of primes so that the error rate of not being prime depends on the intended use based on the size of the input. For larger primes this will result in more rounds of Miller-Rabin. The maximal error rate for primes with more than 1080 bits is lowered to 2^-128. *Kurt Roeckx, Annie Yousar* * Increase the number of Miller-Rabin rounds for DSA key generating to 64. *Kurt Roeckx* * The 'tsget' script is renamed to 'tsget.pl', to avoid confusion when moving between systems, and to avoid confusion when a Windows build is done with mingw vs with MSVC. For POSIX installs, there's still a symlink or copy named 'tsget' to avoid that confusion as well. *Richard Levitte* * Revert blinding in ECDSA sign and instead make problematic addition length-invariant. Switch even to fixed-length Montgomery multiplication. *Andy Polyakov* * Use the new ec_scalar_mul_ladder scaffold to implement a specialized ladder step for binary curves. The new implementation is based on formulae from differential addition-and-doubling in mixed Lopez-Dahab projective coordinates, modified to independently blind the operands. *Billy Bob Brumley, Sohaib ul Hassan, Nicola Tuveri* * Add a scaffold to optionally enhance the Montgomery ladder implementation for `ec_scalar_mul_ladder` (formerly `ec_mul_consttime`) allowing EC_METHODs to implement their own specialized "ladder step", to take advantage of more favorable coordinate systems or more efficient differential addition-and-doubling algorithms. *Billy Bob Brumley, Sohaib ul Hassan, Nicola Tuveri* * Modified the random device based seed sources to keep the relevant file descriptors open rather than reopening them on each access. This allows such sources to operate in a chroot() jail without the associated device nodes being available. This behaviour can be controlled using RAND_keep_random_devices_open(). *Paul Dale* * Numerous side-channel attack mitigations have been applied. This may have performance impacts for some algorithms for the benefit of improved security. Specific changes are noted in this change log by their respective authors. *Matt Caswell* * AIX shared library support overhaul. Switch to AIX "natural" way of handling shared libraries, which means collecting shared objects of different versions and bitnesses in one common archive. This allows to mitigate conflict between 1.0 and 1.1 side-by-side installations. It doesn't affect the way 3rd party applications are linked, only how multi-version installation is managed. *Andy Polyakov* * Make ec_group_do_inverse_ord() more robust and available to other EC cryptosystems, so that irrespective of BN_FLG_CONSTTIME, SCA mitigations are applied to the fallback BN_mod_inverse(). When using this function rather than BN_mod_inverse() directly, new EC cryptosystem implementations are then safer-by-default. *Billy Bob Brumley* * Add coordinate blinding for EC_POINT and implement projective coordinate blinding for generic prime curves as a countermeasure to chosen point SCA attacks. *Sohaib ul Hassan, Nicola Tuveri, Billy Bob Brumley* * Add blinding to ECDSA and DSA signatures to protect against side channel attacks discovered by Keegan Ryan (NCC Group). *Matt Caswell* * Enforce checking in the `pkeyutl` command to ensure that the input length does not exceed the maximum supported digest length when performing a sign, verify or verifyrecover operation. *Matt Caswell* * SSL_MODE_AUTO_RETRY is enabled by default. Applications that use blocking I/O in combination with something like select() or poll() will hang. This can be turned off again using SSL_CTX_clear_mode(). Many applications do not properly handle non-application data records, and TLS 1.3 sends more of such records. Setting SSL_MODE_AUTO_RETRY works around the problems in those applications, but can also break some. It's recommended to read the manpages about SSL_read(), SSL_write(), SSL_get_error(), SSL_shutdown(), SSL_CTX_set_mode() and SSL_CTX_set_read_ahead() again. *Kurt Roeckx* * When unlocking a pass phrase protected PEM file or PKCS#8 container, we now allow empty (zero character) pass phrases. *Richard Levitte* * Apply blinding to binary field modular inversion and remove patent pending (OPENSSL_SUN_GF2M_DIV) BN_GF2m_mod_div implementation. *Billy Bob Brumley* * Deprecate ec2_mult.c and unify scalar multiplication code paths for binary and prime elliptic curves. *Billy Bob Brumley* * Remove ECDSA nonce padding: EC_POINT_mul is now responsible for constant time fixed point multiplication. *Billy Bob Brumley* * Revise elliptic curve scalar multiplication with timing attack defenses: ec_wNAF_mul redirects to a constant time implementation when computing fixed point and variable point multiplication (which in OpenSSL are mostly used with secret scalars in keygen, sign, ECDH derive operations). *Billy Bob Brumley, Nicola Tuveri, Cesar Pereida García, Sohaib ul Hassan* * Updated CONTRIBUTING *Rich Salz* * Updated DRBG / RAND to request nonce and additional low entropy randomness from the system. *Matthias St. Pierre* * Updated 'openssl rehash' to use OpenSSL consistent default. *Richard Levitte* * Moved the load of the ssl_conf module to libcrypto, which helps loading engines that libssl uses before libssl is initialised. *Matt Caswell* * Added EVP_PKEY_sign() and EVP_PKEY_verify() for EdDSA *Matt Caswell* * Fixed X509_NAME_ENTRY_set to get multi-valued RDNs right in all cases. *Ingo Schwarze, Rich Salz* * Added output of accepting IP address and port for 'openssl s_server' *Richard Levitte* * Added a new API for TLSv1.3 ciphersuites: SSL_CTX_set_ciphersuites() SSL_set_ciphersuites() *Matt Caswell* * Memory allocation failures consistently add an error to the error stack. *Rich Salz* * Don't use OPENSSL_ENGINES and OPENSSL_CONF environment values in libcrypto when run as setuid/setgid. *Bernd Edlinger* * Load any config file by default when libssl is used. *Matt Caswell* * Added new public header file and documentation for the RAND_DRBG API. See manual page RAND_DRBG(7) for an overview. *Matthias St. Pierre* * QNX support removed (cannot find contributors to get their approval for the license change). *Rich Salz* * TLSv1.3 replay protection for early data has been implemented. See the SSL_read_early_data() man page for further details. *Matt Caswell* * Separated TLSv1.3 ciphersuite configuration out from TLSv1.2 ciphersuite configuration. TLSv1.3 ciphersuites are not compatible with TLSv1.2 and below. Similarly TLSv1.2 ciphersuites are not compatible with TLSv1.3. In order to avoid issues where legacy TLSv1.2 ciphersuite configuration would otherwise inadvertently disable all TLSv1.3 ciphersuites the configuration has been separated out. See the ciphers man page or the SSL_CTX_set_ciphersuites() man page for more information. *Matt Caswell* * On POSIX (BSD, Linux, ...) systems the ocsp(1) command running in responder mode now supports the new "-multi" option, which spawns the specified number of child processes to handle OCSP requests. The "-timeout" option now also limits the OCSP responder's patience to wait to receive the full client request on a newly accepted connection. Child processes are respawned as needed, and the CA index file is automatically reloaded when changed. This makes it possible to run the "ocsp" responder as a long-running service, making the OpenSSL CA somewhat more feature-complete. In this mode, most diagnostic messages logged after entering the event loop are logged via syslog(3) rather than written to stderr. *Viktor Dukhovni* * Added support for X448 and Ed448. Heavily based on original work by Mike Hamburg. *Matt Caswell* * Extend OSSL_STORE with capabilities to search and to narrow the set of objects loaded. This adds the functions OSSL_STORE_expect() and OSSL_STORE_find() as well as needed tools to construct searches and get the search data out of them. *Richard Levitte* * Support for TLSv1.3 added. Note that users upgrading from an earlier version of OpenSSL should review their configuration settings to ensure that they are still appropriate for TLSv1.3. For further information see: *Matt Caswell* * Grand redesign of the OpenSSL random generator The default RAND method now utilizes an AES-CTR DRBG according to NIST standard SP 800-90Ar1. The new random generator is essentially a port of the default random generator from the OpenSSL FIPS 2.0 object module. It is a hybrid deterministic random bit generator using an AES-CTR bit stream and which seeds and reseeds itself automatically using trusted system entropy sources. Some of its new features are: - Support for multiple DRBG instances with seed chaining. - The default RAND method makes use of a DRBG. - There is a public and private DRBG instance. - The DRBG instances are fork-safe. - Keep all global DRBG instances on the secure heap if it is enabled. - The public and private DRBG instance are per thread for lock free operation *Paul Dale, Benjamin Kaduk, Kurt Roeckx, Rich Salz, Matthias St. Pierre* * Changed Configure so it only says what it does and doesn't dump so much data. Instead, ./configdata.pm should be used as a script to display all sorts of configuration data. *Richard Levitte* * Added processing of "make variables" to Configure. *Richard Levitte* * Added SHA512/224 and SHA512/256 algorithm support. *Paul Dale* * The last traces of Netware support, first removed in 1.1.0, have now been removed. *Rich Salz* * Get rid of Makefile.shared, and in the process, make the processing of certain files (rc.obj, or the .def/.map/.opt files produced from the ordinal files) more visible and hopefully easier to trace and debug (or make silent). *Richard Levitte* * Make it possible to have environment variable assignments as arguments to config / Configure. *Richard Levitte* * Add multi-prime RSA (RFC 8017) support. *Paul Yang* * Add SM3 implemented according to GB/T 32905-2016 *Jack Lloyd ,* *Ronald Tse ,* *Erick Borsboom * * Add 'Maximum Fragment Length' TLS extension negotiation and support as documented in RFC6066. Based on a patch from Tomasz Moń *Filipe Raimundo da Silva* * Add SM4 implemented according to GB/T 32907-2016. *Jack Lloyd ,* *Ronald Tse ,* *Erick Borsboom * * Reimplement -newreq-nodes and ERR_error_string_n; the original author does not agree with the license change. *Rich Salz* * Add ARIA AEAD TLS support. *Jon Spillett* * Some macro definitions to support VS6 have been removed. Visual Studio 6 has not worked since 1.1.0 *Rich Salz* * Add ERR_clear_last_mark(), to allow callers to clear the last mark without clearing the errors. *Richard Levitte* * Add "atfork" functions. If building on a system that without pthreads, see doc/man3/OPENSSL_fork_prepare.pod for application requirements. The RAND facility now uses/requires this. *Rich Salz* * Add SHA3. *Andy Polyakov* * The UI API becomes a permanent and integral part of libcrypto, i.e. not possible to disable entirely. However, it's still possible to disable the console reading UI method, UI_OpenSSL() (use UI_null() as a fallback). To disable, configure with 'no-ui-console'. 'no-ui' is still possible to use as an alias. Check at compile time with the macro OPENSSL_NO_UI_CONSOLE. The macro OPENSSL_NO_UI is still possible to check and is an alias for OPENSSL_NO_UI_CONSOLE. *Richard Levitte* * Add a STORE module, which implements a uniform and URI based reader of stores that can contain keys, certificates, CRLs and numerous other objects. The main API is loosely based on a few stdio functions, and includes OSSL_STORE_open, OSSL_STORE_load, OSSL_STORE_eof, OSSL_STORE_error and OSSL_STORE_close. The implementation uses backends called "loaders" to implement arbitrary URI schemes. There is one built in "loader" for the 'file' scheme. *Richard Levitte* * Add devcrypto engine. This has been implemented against cryptodev-linux, then adjusted to work on FreeBSD 8.4 as well. Enable by configuring with 'enable-devcryptoeng'. This is done by default on BSD implementations, as cryptodev.h is assumed to exist on all of them. *Richard Levitte* * Module names can prefixed with OSSL_ or OPENSSL_. This affects util/mkerr.pl, which is adapted to allow those prefixes, leading to error code calls like this: OSSL_FOOerr(OSSL_FOO_F_SOMETHING, OSSL_FOO_R_WHATEVER); With this change, we claim the namespaces OSSL and OPENSSL in a manner that can be encoded in C. For the foreseeable future, this will only affect new modules. *Richard Levitte and Tim Hudson* * Removed BSD cryptodev engine. *Rich Salz* * Add a build target 'build_all_generated', to build all generated files and only that. This can be used to prepare everything that requires things like perl for a system that lacks perl and then move everything to that system and do the rest of the build there. *Richard Levitte* * In the UI interface, make it possible to duplicate the user data. This can be used by engines that need to retain the data for a longer time than just the call where this user data is passed. *Richard Levitte* * Ignore the '-named_curve auto' value for compatibility of applications with OpenSSL 1.0.2. *Tomáš Mráz * * Fragmented SSL/TLS alerts are no longer accepted. An alert message is 2 bytes long. In theory it is permissible in SSLv3 - TLSv1.2 to fragment such alerts across multiple records (some of which could be empty). In practice it make no sense to send an empty alert record, or to fragment one. TLSv1.3 prohibits this altogether and other libraries (BoringSSL, NSS) do not support this at all. Supporting it adds significant complexity to the record layer, and its removal is unlikely to cause interoperability issues. *Matt Caswell* * Add the ASN.1 types INT32, UINT32, INT64, UINT64 and variants prefixed with Z. These are meant to replace LONG and ZLONG and to be size safe. The use of LONG and ZLONG is discouraged and scheduled for deprecation in OpenSSL 1.2.0. *Richard Levitte* * Add the 'z' and 'j' modifiers to BIO_printf() et al formatting string, 'z' is to be used for [s]size_t, and 'j' - with [u]int64_t. *Richard Levitte, Andy Polyakov* * Add EC_KEY_get0_engine(), which does for EC_KEY what RSA_get0_engine() does for RSA, etc. *Richard Levitte* * Have 'config' recognise 64-bit mingw and choose 'mingw64' as the target platform rather than 'mingw'. *Richard Levitte* * The functions X509_STORE_add_cert and X509_STORE_add_crl return success if they are asked to add an object which already exists in the store. This change cascades to other functions which load certificates and CRLs. *Paul Dale* * x86_64 assembly pack: annotate code with DWARF CFI directives to facilitate stack unwinding even from assembly subroutines. *Andy Polyakov* * Remove VAX C specific definitions of OPENSSL_EXPORT, OPENSSL_EXTERN. Also remove OPENSSL_GLOBAL entirely, as it became a no-op. *Richard Levitte* * Remove the VMS-specific reimplementation of gmtime from crypto/o_times.c. VMS C's RTL has a fully up to date gmtime() and gmtime_r() since V7.1, which is the minimum version we support. *Richard Levitte* * Certificate time validation (X509_cmp_time) enforces stricter compliance with RFC 5280. Fractional seconds and timezone offsets are no longer allowed. *Emilia Käsper* * Add support for ARIA *Paul Dale* * s_client will now send the Server Name Indication (SNI) extension by default unless the new "-noservername" option is used. The server name is based on the host provided to the "-connect" option unless overridden by using "-servername". *Matt Caswell* * Add support for SipHash *Todd Short* * OpenSSL now fails if it receives an unrecognised record type in TLS1.0 or TLS1.1. Previously this only happened in SSLv3 and TLS1.2. This is to prevent issues where no progress is being made and the peer continually sends unrecognised record types, using up resources processing them. *Matt Caswell* * 'openssl passwd' can now produce SHA256 and SHA512 based output, using the algorithm defined in *Richard Levitte* * Heartbeat support has been removed; the ABI is changed for now. *Richard Levitte, Rich Salz* * Support for SSL_OP_NO_ENCRYPT_THEN_MAC in SSL_CONF_cmd. *Emilia Käsper* * The RSA "null" method, which was partially supported to avoid patent issues, has been replaced to always returns NULL. *Rich Salz* OpenSSL 1.1.0 ------------- ### Changes between 1.1.0k and 1.1.0l [10 Sep 2019] * For built-in EC curves, ensure an EC_GROUP built from the curve name is used even when parsing explicit parameters, when loading a encoded key or calling `EC_GROUP_new_from_ecpkparameters()`/ `EC_GROUP_new_from_ecparameters()`. This prevents bypass of security hardening and performance gains, especially for curves with specialized EC_METHODs. By default, if a key encoded with explicit parameters is loaded and later encoded, the output is still encoded with explicit parameters, even if internally a "named" EC_GROUP is used for computation. *Nicola Tuveri* * Compute ECC cofactors if not provided during EC_GROUP construction. Before this change, EC_GROUP_set_generator would accept order and/or cofactor as NULL. After this change, only the cofactor parameter can be NULL. It also does some minimal sanity checks on the passed order. ([CVE-2019-1547]) *Billy Bob Brumley* * Fixed a padding oracle in PKCS7_dataDecode and CMS_decrypt_set1_pkey. An attack is simple, if the first CMS_recipientInfo is valid but the second CMS_recipientInfo is chosen ciphertext. If the second recipientInfo decodes to PKCS #1 v1.5 form plaintext, the correct encryption key will be replaced by garbage, and the message cannot be decoded, but if the RSA decryption fails, the correct encryption key is used and the recipient will not notice the attack. As a work around for this potential attack the length of the decrypted key must be equal to the cipher default key length, in case the certifiate is not given and all recipientInfo are tried out. The old behaviour can be re-enabled in the CMS code by setting the CMS_DEBUG_DECRYPT flag. ([CVE-2019-1563]) *Bernd Edlinger* * Use Windows installation paths in the mingw builds Mingw isn't a POSIX environment per se, which means that Windows paths should be used for installation. ([CVE-2019-1552]) *Richard Levitte* ### Changes between 1.1.0j and 1.1.0k [28 May 2019] * Change the default RSA, DSA and DH size to 2048 bit instead of 1024. This changes the size when using the `genpkey` command when no size is given. It fixes an omission in earlier changes that changed all RSA, DSA and DH generation commands to use 2048 bits by default. *Kurt Roeckx* * Prevent over long nonces in ChaCha20-Poly1305. ChaCha20-Poly1305 is an AEAD cipher, and requires a unique nonce input for every encryption operation. RFC 7539 specifies that the nonce value (IV) should be 96 bits (12 bytes). OpenSSL allows a variable nonce length and front pads the nonce with 0 bytes if it is less than 12 bytes. However it also incorrectly allows a nonce to be set of up to 16 bytes. In this case only the last 12 bytes are significant and any additional leading bytes are ignored. It is a requirement of using this cipher that nonce values are unique. Messages encrypted using a reused nonce value are susceptible to serious confidentiality and integrity attacks. If an application changes the default nonce length to be longer than 12 bytes and then makes a change to the leading bytes of the nonce expecting the new value to be a new unique nonce then such an application could inadvertently encrypt messages with a reused nonce. Additionally the ignored bytes in a long nonce are not covered by the integrity guarantee of this cipher. Any application that relies on the integrity of these ignored leading bytes of a long nonce may be further affected. Any OpenSSL internal use of this cipher, including in SSL/TLS, is safe because no such use sets such a long nonce value. However user applications that use this cipher directly and set a non-default nonce length to be longer than 12 bytes may be vulnerable. This issue was reported to OpenSSL on 16th of March 2019 by Joran Dirk Greef of Ronomon. ([CVE-2019-1543]) *Matt Caswell* * Added SCA hardening for modular field inversion in EC_GROUP through a new dedicated field_inv() pointer in EC_METHOD. This also addresses a leakage affecting conversions from projective to affine coordinates. *Billy Bob Brumley, Nicola Tuveri* * Fix a use after free bug in d2i_X509_PUBKEY when overwriting a re-used X509_PUBKEY object if the second PUBKEY is malformed. *Bernd Edlinger* * Move strictness check from EVP_PKEY_asn1_new() to EVP_PKEY_asn1_add0(). *Richard Levitte* * Remove the 'dist' target and add a tarball building script. The 'dist' target has fallen out of use, and it shouldn't be necessary to configure just to create a source distribution. *Richard Levitte* ### Changes between 1.1.0i and 1.1.0j [20 Nov 2018] * Timing vulnerability in DSA signature generation The OpenSSL DSA signature algorithm has been shown to be vulnerable to a timing side channel attack. An attacker could use variations in the signing algorithm to recover the private key. This issue was reported to OpenSSL on 16th October 2018 by Samuel Weiser. ([CVE-2018-0734]) *Paul Dale* * Timing vulnerability in ECDSA signature generation The OpenSSL ECDSA signature algorithm has been shown to be vulnerable to a timing side channel attack. An attacker could use variations in the signing algorithm to recover the private key. This issue was reported to OpenSSL on 25th October 2018 by Samuel Weiser. ([CVE-2018-0735]) *Paul Dale* * Add coordinate blinding for EC_POINT and implement projective coordinate blinding for generic prime curves as a countermeasure to chosen point SCA attacks. *Sohaib ul Hassan, Nicola Tuveri, Billy Bob Brumley* ### Changes between 1.1.0h and 1.1.0i [14 Aug 2018] * Client DoS due to large DH parameter During key agreement in a TLS handshake using a DH(E) based ciphersuite a malicious server can send a very large prime value to the client. This will cause the client to spend an unreasonably long period of time generating a key for this prime resulting in a hang until the client has finished. This could be exploited in a Denial Of Service attack. This issue was reported to OpenSSL on 5th June 2018 by Guido Vranken ([CVE-2018-0732]) *Guido Vranken* * Cache timing vulnerability in RSA Key Generation The OpenSSL RSA Key generation algorithm has been shown to be vulnerable to a cache timing side channel attack. An attacker with sufficient access to mount cache timing attacks during the RSA key generation process could recover the private key. This issue was reported to OpenSSL on 4th April 2018 by Alejandro Cabrera Aldaya, Billy Brumley, Cesar Pereida Garcia and Luis Manuel Alvarez Tapia. ([CVE-2018-0737]) *Billy Brumley* * Make EVP_PKEY_asn1_new() a bit stricter about its input. A NULL pem_str parameter is no longer accepted, as it leads to a corrupt table. NULL pem_str is reserved for alias entries only. *Richard Levitte* * Revert blinding in ECDSA sign and instead make problematic addition length-invariant. Switch even to fixed-length Montgomery multiplication. *Andy Polyakov* * Change generating and checking of primes so that the error rate of not being prime depends on the intended use based on the size of the input. For larger primes this will result in more rounds of Miller-Rabin. The maximal error rate for primes with more than 1080 bits is lowered to 2^-128. *Kurt Roeckx, Annie Yousar* * Increase the number of Miller-Rabin rounds for DSA key generating to 64. *Kurt Roeckx* * Add blinding to ECDSA and DSA signatures to protect against side channel attacks discovered by Keegan Ryan (NCC Group). *Matt Caswell* * When unlocking a pass phrase protected PEM file or PKCS#8 container, we now allow empty (zero character) pass phrases. *Richard Levitte* * Certificate time validation (X509_cmp_time) enforces stricter compliance with RFC 5280. Fractional seconds and timezone offsets are no longer allowed. *Emilia Käsper* * Fixed a text canonicalisation bug in CMS Where a CMS detached signature is used with text content the text goes through a canonicalisation process first prior to signing or verifying a signature. This process strips trailing space at the end of lines, converts line terminators to CRLF and removes additional trailing line terminators at the end of a file. A bug in the canonicalisation process meant that some characters, such as form-feed, were incorrectly treated as whitespace and removed. This is contrary to the specification (RFC5485). This fix could mean that detached text data signed with an earlier version of OpenSSL 1.1.0 may fail to verify using the fixed version, or text data signed with a fixed OpenSSL may fail to verify with an earlier version of OpenSSL 1.1.0. A workaround is to only verify the canonicalised text data and use the "-binary" flag (for the "cms" command line application) or set the SMIME_BINARY/PKCS7_BINARY/CMS_BINARY flags (if using CMS_verify()). *Matt Caswell* ### Changes between 1.1.0g and 1.1.0h [27 Mar 2018] * Constructed ASN.1 types with a recursive definition could exceed the stack Constructed ASN.1 types with a recursive definition (such as can be found in PKCS7) could eventually exceed the stack given malicious input with excessive recursion. This could result in a Denial Of Service attack. There are no such structures used within SSL/TLS that come from untrusted sources so this is considered safe. This issue was reported to OpenSSL on 4th January 2018 by the OSS-fuzz project. ([CVE-2018-0739]) *Matt Caswell* * Incorrect CRYPTO_memcmp on HP-UX PA-RISC Because of an implementation bug the PA-RISC CRYPTO_memcmp function is effectively reduced to only comparing the least significant bit of each byte. This allows an attacker to forge messages that would be considered as authenticated in an amount of tries lower than that guaranteed by the security claims of the scheme. The module can only be compiled by the HP-UX assembler, so that only HP-UX PA-RISC targets are affected. This issue was reported to OpenSSL on 2nd March 2018 by Peter Waltenberg (IBM). ([CVE-2018-0733]) *Andy Polyakov* * Add a build target 'build_all_generated', to build all generated files and only that. This can be used to prepare everything that requires things like perl for a system that lacks perl and then move everything to that system and do the rest of the build there. *Richard Levitte* * Backport SSL_OP_NO_RENGOTIATION OpenSSL 1.0.2 and below had the ability to disable renegotiation using the (undocumented) SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS flag. Due to the opacity changes this is no longer possible in 1.1.0. Therefore the new SSL_OP_NO_RENEGOTIATION option from 1.1.1-dev has been backported to 1.1.0 to provide equivalent functionality. Note that if an application built against 1.1.0h headers (or above) is run using an older version of 1.1.0 (prior to 1.1.0h) then the option will be accepted but nothing will happen, i.e. renegotiation will not be prevented. *Matt Caswell* * Removed the OS390-Unix config target. It relied on a script that doesn't exist. *Rich Salz* * rsaz_1024_mul_avx2 overflow bug on x86_64 There is an overflow bug in the AVX2 Montgomery multiplication procedure used in exponentiation with 1024-bit moduli. No EC algorithms are affected. Analysis suggests that attacks against RSA and DSA as a result of this defect would be very difficult to perform and are not believed likely. Attacks against DH1024 are considered just feasible, because most of the work necessary to deduce information about a private key may be performed offline. The amount of resources required for such an attack would be significant. However, for an attack on TLS to be meaningful, the server would have to share the DH1024 private key among multiple clients, which is no longer an option since CVE-2016-0701. This only affects processors that support the AVX2 but not ADX extensions like Intel Haswell (4th generation). This issue was reported to OpenSSL by David Benjamin (Google). The issue was originally found via the OSS-Fuzz project. ([CVE-2017-3738]) *Andy Polyakov* ### Changes between 1.1.0f and 1.1.0g [2 Nov 2017] * bn_sqrx8x_internal carry bug on x86_64 There is a carry propagating bug in the x86_64 Montgomery squaring procedure. No EC algorithms are affected. Analysis suggests that attacks against RSA and DSA as a result of this defect would be very difficult to perform and are not believed likely. Attacks against DH are considered just feasible (although very difficult) because most of the work necessary to deduce information about a private key may be performed offline. The amount of resources required for such an attack would be very significant and likely only accessible to a limited number of attackers. An attacker would additionally need online access to an unpatched system using the target private key in a scenario with persistent DH parameters and a private key that is shared between multiple clients. This only affects processors that support the BMI1, BMI2 and ADX extensions like Intel Broadwell (5th generation) and later or AMD Ryzen. This issue was reported to OpenSSL by the OSS-Fuzz project. ([CVE-2017-3736]) *Andy Polyakov* * Malformed X.509 IPAddressFamily could cause OOB read If an X.509 certificate has a malformed IPAddressFamily extension, OpenSSL could do a one-byte buffer overread. The most likely result would be an erroneous display of the certificate in text format. This issue was reported to OpenSSL by the OSS-Fuzz project. ([CVE-2017-3735]) *Rich Salz* ### Changes between 1.1.0e and 1.1.0f [25 May 2017] * Have 'config' recognise 64-bit mingw and choose 'mingw64' as the target platform rather than 'mingw'. *Richard Levitte* * Remove the VMS-specific reimplementation of gmtime from crypto/o_times.c. VMS C's RTL has a fully up to date gmtime() and gmtime_r() since V7.1, which is the minimum version we support. *Richard Levitte* ### Changes between 1.1.0d and 1.1.0e [16 Feb 2017] * Encrypt-Then-Mac renegotiation crash During a renegotiation handshake if the Encrypt-Then-Mac extension is negotiated where it was not in the original handshake (or vice-versa) then this can cause OpenSSL to crash (dependant on ciphersuite). Both clients and servers are affected. This issue was reported to OpenSSL by Joe Orton (Red Hat). ([CVE-2017-3733]) *Matt Caswell* ### Changes between 1.1.0c and 1.1.0d [26 Jan 2017] * Truncated packet could crash via OOB read If one side of an SSL/TLS path is running on a 32-bit host and a specific cipher is being used, then a truncated packet can cause that host to perform an out-of-bounds read, usually resulting in a crash. This issue was reported to OpenSSL by Robert Święcki of Google. ([CVE-2017-3731]) *Andy Polyakov* * Bad (EC)DHE parameters cause a client crash If a malicious server supplies bad parameters for a DHE or ECDHE key exchange then this can result in the client attempting to dereference a NULL pointer leading to a client crash. This could be exploited in a Denial of Service attack. This issue was reported to OpenSSL by Guido Vranken. ([CVE-2017-3730]) *Matt Caswell* * BN_mod_exp may produce incorrect results on x86_64 There is a carry propagating bug in the x86_64 Montgomery squaring procedure. No EC algorithms are affected. Analysis suggests that attacks against RSA and DSA as a result of this defect would be very difficult to perform and are not believed likely. Attacks against DH are considered just feasible (although very difficult) because most of the work necessary to deduce information about a private key may be performed offline. The amount of resources required for such an attack would be very significant and likely only accessible to a limited number of attackers. An attacker would additionally need online access to an unpatched system using the target private key in a scenario with persistent DH parameters and a private key that is shared between multiple clients. For example this can occur by default in OpenSSL DHE based SSL/TLS ciphersuites. Note: This issue is very similar to CVE-2015-3193 but must be treated as a separate problem. This issue was reported to OpenSSL by the OSS-Fuzz project. ([CVE-2017-3732]) *Andy Polyakov* ### Changes between 1.1.0b and 1.1.0c [10 Nov 2016] * ChaCha20/Poly1305 heap-buffer-overflow TLS connections using `*-CHACHA20-POLY1305` ciphersuites are susceptible to a DoS attack by corrupting larger payloads. This can result in an OpenSSL crash. This issue is not considered to be exploitable beyond a DoS. This issue was reported to OpenSSL by Robert Święcki (Google Security Team) ([CVE-2016-7054]) *Richard Levitte* * CMS Null dereference Applications parsing invalid CMS structures can crash with a NULL pointer dereference. This is caused by a bug in the handling of the ASN.1 CHOICE type in OpenSSL 1.1.0 which can result in a NULL value being passed to the structure callback if an attempt is made to free certain invalid encodings. Only CHOICE structures using a callback which do not handle NULL value are affected. This issue was reported to OpenSSL by Tyler Nighswander of ForAllSecure. ([CVE-2016-7053]) *Stephen Henson* * Montgomery multiplication may produce incorrect results There is a carry propagating bug in the Broadwell-specific Montgomery multiplication procedure that handles input lengths divisible by, but longer than 256 bits. Analysis suggests that attacks against RSA, DSA and DH private keys are impossible. This is because the subroutine in question is not used in operations with the private key itself and an input of the attacker's direct choice. Otherwise the bug can manifest itself as transient authentication and key negotiation failures or reproducible erroneous outcome of public-key operations with specially crafted input. Among EC algorithms only Brainpool P-512 curves are affected and one presumably can attack ECDH key negotiation. Impact was not analyzed in detail, because pre-requisites for attack are considered unlikely. Namely multiple clients have to choose the curve in question and the server has to share the private key among them, neither of which is default behaviour. Even then only clients that chose the curve will be affected. This issue was publicly reported as transient failures and was not initially recognized as a security issue. Thanks to Richard Morgan for providing reproducible case. ([CVE-2016-7055]) *Andy Polyakov* * Removed automatic addition of RPATH in shared libraries and executables, as this was a remainder from OpenSSL 1.0.x and isn't needed any more. *Richard Levitte* ### Changes between 1.1.0a and 1.1.0b [26 Sep 2016] * Fix Use After Free for large message sizes The patch applied to address CVE-2016-6307 resulted in an issue where if a message larger than approx 16k is received then the underlying buffer to store the incoming message is reallocated and moved. Unfortunately a dangling pointer to the old location is left which results in an attempt to write to the previously freed location. This is likely to result in a crash, however it could potentially lead to execution of arbitrary code. This issue only affects OpenSSL 1.1.0a. This issue was reported to OpenSSL by Robert Święcki. ([CVE-2016-6309]) *Matt Caswell* ### Changes between 1.1.0 and 1.1.0a [22 Sep 2016] * OCSP Status Request extension unbounded memory growth A malicious client can send an excessively large OCSP Status Request extension. If that client continually requests renegotiation, sending a large OCSP Status Request extension each time, then there will be unbounded memory growth on the server. This will eventually lead to a Denial Of Service attack through memory exhaustion. Servers with a default configuration are vulnerable even if they do not support OCSP. Builds using the "no-ocsp" build time option are not affected. This issue was reported to OpenSSL by Shi Lei (Gear Team, Qihoo 360 Inc.) ([CVE-2016-6304]) *Matt Caswell* * SSL_peek() hang on empty record OpenSSL 1.1.0 SSL/TLS will hang during a call to SSL_peek() if the peer sends an empty record. This could be exploited by a malicious peer in a Denial Of Service attack. This issue was reported to OpenSSL by Alex Gaynor. ([CVE-2016-6305]) *Matt Caswell* * Excessive allocation of memory in tls_get_message_header() and dtls1_preprocess_fragment() A (D)TLS message includes 3 bytes for its length in the header for the message. This would allow for messages up to 16Mb in length. Messages of this length are excessive and OpenSSL includes a check to ensure that a peer is sending reasonably sized messages in order to avoid too much memory being consumed to service a connection. A flaw in the logic of version 1.1.0 means that memory for the message is allocated too early, prior to the excessive message length check. Due to way memory is allocated in OpenSSL this could mean an attacker could force up to 21Mb to be allocated to service a connection. This could lead to a Denial of Service through memory exhaustion. However, the excessive message length check still takes place, and this would cause the connection to immediately fail. Assuming that the application calls SSL_free() on the failed connection in a timely manner then the 21Mb of allocated memory will then be immediately freed again. Therefore the excessive memory allocation will be transitory in nature. This then means that there is only a security impact if: 1) The application does not call SSL_free() in a timely manner in the event that the connection fails or 2) The application is working in a constrained environment where there is very little free memory or 3) The attacker initiates multiple connection attempts such that there are multiple connections in a state where memory has been allocated for the connection; SSL_free() has not yet been called; and there is insufficient memory to service the multiple requests. Except in the instance of (1) above any Denial Of Service is likely to be transitory because as soon as the connection fails the memory is subsequently freed again in the SSL_free() call. However there is an increased risk during this period of application crashes due to the lack of memory - which would then mean a more serious Denial of Service. This issue was reported to OpenSSL by Shi Lei (Gear Team, Qihoo 360 Inc.) (CVE-2016-6307 and CVE-2016-6308) *Matt Caswell* * solaris-x86-cc, i.e. 32-bit configuration with vendor compiler, had to be removed. Primary reason is that vendor assembler can't assemble our modules with -KPIC flag. As result it, assembly support, was not even available as option. But its lack means lack of side-channel resistant code, which is incompatible with security by todays standards. Fortunately gcc is readily available prepackaged option, which we firmly point at... *Andy Polyakov* ### Changes between 1.0.2h and 1.1.0 [25 Aug 2016] * Windows command-line tool supports UTF-8 opt-in option for arguments and console input. Setting OPENSSL_WIN32_UTF8 environment variable (to any value) allows Windows user to access PKCS#12 file generated with Windows CryptoAPI and protected with non-ASCII password, as well as files generated under UTF-8 locale on Linux also protected with non-ASCII password. *Andy Polyakov* * To mitigate the SWEET32 attack ([CVE-2016-2183]), 3DES cipher suites have been disabled by default and removed from DEFAULT, just like RC4. See the RC4 item below to re-enable both. *Rich Salz* * The method for finding the storage location for the Windows RAND seed file has changed. First we check %RANDFILE%. If that is not set then we check the directories %HOME%, %USERPROFILE% and %SYSTEMROOT% in that order. If all else fails we fall back to C:\. *Matt Caswell* * The EVP_EncryptUpdate() function has had its return type changed from void to int. A return of 0 indicates and error while a return of 1 indicates success. *Matt Caswell* * The flags RSA_FLAG_NO_CONSTTIME, DSA_FLAG_NO_EXP_CONSTTIME and DH_FLAG_NO_EXP_CONSTTIME which previously provided the ability to switch off the constant time implementation for RSA, DSA and DH have been made no-ops and deprecated. *Matt Caswell* * Windows RAND implementation was simplified to only get entropy by calling CryptGenRandom(). Various other RAND-related tickets were also closed. *Joseph Wylie Yandle, Rich Salz* * The stack and lhash API's were renamed to start with `OPENSSL_SK_` and `OPENSSL_LH_`, respectively. The old names are available with API compatibility. They new names are now completely documented. *Rich Salz* * Unify TYPE_up_ref(obj) methods signature. SSL_CTX_up_ref(), SSL_up_ref(), X509_up_ref(), EVP_PKEY_up_ref(), X509_CRL_up_ref(), X509_OBJECT_up_ref_count() methods are now returning an int (instead of void) like all others TYPE_up_ref() methods. So now these methods also check the return value of CRYPTO_atomic_add(), and the validity of object reference counter. *fdasilvayy@gmail.com* * With Windows Visual Studio builds, the .pdb files are installed alongside the installed libraries and executables. For a static library installation, ossl_static.pdb is the associate compiler generated .pdb file to be used when linking programs. *Richard Levitte* * Remove openssl.spec. Packaging files belong with the packagers. *Richard Levitte* * Automatic Darwin/OSX configuration has had a refresh, it will now recognise x86_64 architectures automatically. You can still decide to build for a different bitness with the environment variable KERNEL_BITS (can be 32 or 64), for example: KERNEL_BITS=32 ./config *Richard Levitte* * Change default algorithms in pkcs8 utility to use PKCS#5 v2.0, 256 bit AES and HMAC with SHA256. *Steve Henson* * Remove support for MIPS o32 ABI on IRIX (and IRIX only). *Andy Polyakov* * Triple-DES ciphers have been moved from HIGH to MEDIUM. *Rich Salz* * To enable users to have their own config files and build file templates, Configure looks in the directory indicated by the environment variable OPENSSL_LOCAL_CONFIG_DIR as well as the in-source Configurations/ directory. On VMS, OPENSSL_LOCAL_CONFIG_DIR is expected to be a logical name and is used as is. *Richard Levitte* * The following datatypes were made opaque: X509_OBJECT, X509_STORE_CTX, X509_STORE, X509_LOOKUP, and X509_LOOKUP_METHOD. The unused type X509_CERT_FILE_CTX was removed. *Rich Salz* * "shared" builds are now the default. To create only static libraries use the "no-shared" Configure option. *Matt Caswell* * Remove the no-aes, no-hmac, no-rsa, no-sha and no-md5 Configure options. All of these option have not worked for some while and are fundamental algorithms. *Matt Caswell* * Make various cleanup routines no-ops and mark them as deprecated. Most global cleanup functions are no longer required because they are handled via auto-deinit (see OPENSSL_init_crypto and OPENSSL_init_ssl man pages). Explicitly de-initing can cause problems (e.g. where a library that uses OpenSSL de-inits, but an application is still using it). The affected functions are CONF_modules_free(), ENGINE_cleanup(), OBJ_cleanup(), EVP_cleanup(), BIO_sock_cleanup(), CRYPTO_cleanup_all_ex_data(), RAND_cleanup(), SSL_COMP_free_compression_methods(), ERR_free_strings() and COMP_zlib_cleanup(). *Matt Caswell* * --strict-warnings no longer enables runtime debugging options such as REF_DEBUG. Instead, debug options are automatically enabled with '--debug' builds. *Andy Polyakov, Emilia Käsper* * Made DH and DH_METHOD opaque. The structures for managing DH objects have been moved out of the public header files. New functions for managing these have been added. *Matt Caswell* * Made RSA and RSA_METHOD opaque. The structures for managing RSA objects have been moved out of the public header files. New functions for managing these have been added. *Richard Levitte* * Made DSA and DSA_METHOD opaque. The structures for managing DSA objects have been moved out of the public header files. New functions for managing these have been added. *Matt Caswell* * Made BIO and BIO_METHOD opaque. The structures for managing BIOs have been moved out of the public header files. New functions for managing these have been added. *Matt Caswell* * Removed no-rijndael as a config option. Rijndael is an old name for AES. *Matt Caswell* * Removed the mk1mf build scripts. *Richard Levitte* * Headers are now wrapped, if necessary, with OPENSSL_NO_xxx, so it is always safe to #include a header now. *Rich Salz* * Removed the aged BC-32 config and all its supporting scripts *Richard Levitte* * Removed support for Ultrix, Netware, and OS/2. *Rich Salz* * Add support for HKDF. *Alessandro Ghedini* * Add support for blake2b and blake2s *Bill Cox* * Added support for "pipelining". Ciphers that have the EVP_CIPH_FLAG_PIPELINE flag set have a capability to process multiple encryptions/decryptions simultaneously. There are currently no built-in ciphers with this property but the expectation is that engines will be able to offer it to significantly improve throughput. Support has been extended into libssl so that multiple records for a single connection can be processed in one go (for >=TLS 1.1). *Matt Caswell* * Added the AFALG engine. This is an async capable engine which is able to offload work to the Linux kernel. In this initial version it only supports AES128-CBC. The kernel must be version 4.1.0 or greater. *Catriona Lucey* * OpenSSL now uses a new threading API. It is no longer necessary to set locking callbacks to use OpenSSL in a multi-threaded environment. There are two supported threading models: pthreads and windows threads. It is also possible to configure OpenSSL at compile time for "no-threads". The old threading API should no longer be used. The functions have been replaced with "no-op" compatibility macros. *Alessandro Ghedini, Matt Caswell* * Modify behavior of ALPN to invoke callback after SNI/servername callback, such that updates to the SSL_CTX affect ALPN. *Todd Short* * Add SSL_CIPHER queries for authentication and key-exchange. *Todd Short* * Changes to the DEFAULT cipherlist: - Prefer (EC)DHE handshakes over plain RSA. - Prefer AEAD ciphers over legacy ciphers. - Prefer ECDSA over RSA when both certificates are available. - Prefer TLSv1.2 ciphers/PRF. - Remove DSS, SEED, IDEA, CAMELLIA, and AES-CCM from the default cipherlist. *Emilia Käsper* * Change the ECC default curve list to be this, in order: x25519, secp256r1, secp521r1, secp384r1. *Rich Salz* * RC4 based libssl ciphersuites are now classed as "weak" ciphers and are disabled by default. They can be re-enabled using the enable-weak-ssl-ciphers option to Configure. *Matt Caswell* * If the server has ALPN configured, but supports no protocols that the client advertises, send a fatal "no_application_protocol" alert. This behaviour is SHALL in RFC 7301, though it isn't universally implemented by other servers. *Emilia Käsper* * Add X25519 support. Add ASN.1 and EVP_PKEY methods for X25519. This includes support for public and private key encoding using the format documented in draft-ietf-curdle-pkix-02. The corresponding EVP_PKEY method supports key generation and key derivation. TLS support complies with draft-ietf-tls-rfc4492bis-08 and uses X25519(29). *Steve Henson* * Deprecate SRP_VBASE_get_by_user. SRP_VBASE_get_by_user had inconsistent memory management behaviour. In order to fix an unavoidable memory leak ([CVE-2016-0798]), SRP_VBASE_get_by_user was changed to ignore the "fake user" SRP seed, even if the seed is configured. Users should use SRP_VBASE_get1_by_user instead. Note that in SRP_VBASE_get1_by_user, caller must free the returned value. Note also that even though configuring the SRP seed attempts to hide invalid usernames by continuing the handshake with fake credentials, this behaviour is not constant time and no strong guarantees are made that the handshake is indistinguishable from that of a valid user. *Emilia Käsper* * Configuration change; it's now possible to build dynamic engines without having to build shared libraries and vice versa. This only applies to the engines in `engines/`, those in `crypto/engine/` will always be built into libcrypto (i.e. "static"). Building dynamic engines is enabled by default; to disable, use the configuration option "disable-dynamic-engine". The only requirements for building dynamic engines are the presence of the DSO module and building with position independent code, so they will also automatically be disabled if configuring with "disable-dso" or "disable-pic". The macros OPENSSL_NO_STATIC_ENGINE and OPENSSL_NO_DYNAMIC_ENGINE are also taken away from openssl/opensslconf.h, as they are irrelevant. *Richard Levitte* * Configuration change; if there is a known flag to compile position independent code, it will always be applied on the libcrypto and libssl object files, and never on the application object files. This means other libraries that use routines from libcrypto / libssl can be made into shared libraries regardless of how OpenSSL was configured. If this isn't desirable, the configuration options "disable-pic" or "no-pic" can be used to disable the use of PIC. This will also disable building shared libraries and dynamic engines. *Richard Levitte* * Removed JPAKE code. It was experimental and has no wide use. *Rich Salz* * The INSTALL_PREFIX Makefile variable has been renamed to DESTDIR. That makes for less confusion on what this variable is for. Also, the configuration option --install_prefix is removed. *Richard Levitte* * Heartbeat for TLS has been removed and is disabled by default for DTLS; configure with enable-heartbeats. Code that uses the old #define's might need to be updated. *Emilia Käsper, Rich Salz* * Rename REF_CHECK to REF_DEBUG. *Rich Salz* * New "unified" build system The "unified" build system is aimed to be a common system for all platforms we support. With it comes new support for VMS. This system builds supports building in a different directory tree than the source tree. It produces one Makefile (for unix family or lookalikes), or one descrip.mms (for VMS). The source of information to make the Makefile / descrip.mms is small files called 'build.info', holding the necessary information for each directory with source to compile, and a template in Configurations, like unix-Makefile.tmpl or descrip.mms.tmpl. With this change, the library names were also renamed on Windows and on VMS. They now have names that are closer to the standard on Unix, and include the major version number, and in certain cases, the architecture they are built for. See "Notes on shared libraries" in INSTALL. We rely heavily on the perl module Text::Template. *Richard Levitte* * Added support for auto-initialisation and de-initialisation of the library. OpenSSL no longer requires explicit init or deinit routines to be called, except in certain circumstances. See the OPENSSL_init_crypto() and OPENSSL_init_ssl() man pages for further information. *Matt Caswell* * The arguments to the DTLSv1_listen function have changed. Specifically the "peer" argument is now expected to be a BIO_ADDR object. * Rewrite of BIO networking library. The BIO library lacked consistent support of IPv6, and adding it required some more extensive modifications. This introduces the BIO_ADDR and BIO_ADDRINFO types, which hold all types of addresses and chains of address information. It also introduces a new API, with functions like BIO_socket, BIO_connect, BIO_listen, BIO_lookup and a rewrite of BIO_accept. The source/sink BIOs BIO_s_connect, BIO_s_accept and BIO_s_datagram have been adapted accordingly. *Richard Levitte* * RSA_padding_check_PKCS1_type_1 now accepts inputs with and without the leading 0-byte. *Emilia Käsper* * CRIME protection: disable compression by default, even if OpenSSL is compiled with zlib enabled. Applications can still enable compression by calling SSL_CTX_clear_options(ctx, SSL_OP_NO_COMPRESSION), or by using the SSL_CONF library to configure compression. *Emilia Käsper* * The signature of the session callback configured with SSL_CTX_sess_set_get_cb was changed. The read-only input buffer was explicitly marked as `const unsigned char*` instead of `unsigned char*`. *Emilia Käsper* * Always DPURIFY. Remove the use of uninitialized memory in the RNG, and other conditional uses of DPURIFY. This makes -DPURIFY a no-op. *Emilia Käsper* * Removed many obsolete configuration items, including DES_PTR, DES_RISC1, DES_RISC2, DES_INT MD2_CHAR, MD2_INT, MD2_LONG BF_PTR, BF_PTR2 IDEA_SHORT, IDEA_LONG RC2_SHORT, RC2_LONG, RC4_LONG, RC4_CHUNK, RC4_INDEX *Rich Salz, with advice from Andy Polyakov* * Many BN internals have been moved to an internal header file. *Rich Salz with help from Andy Polyakov* * Configuration and writing out the results from it has changed. Files such as Makefile include/openssl/opensslconf.h and are now produced through general templates, such as Makefile.in and crypto/opensslconf.h.in and some help from the perl module Text::Template. Also, the center of configuration information is no longer Makefile. Instead, Configure produces a perl module in configdata.pm which holds most of the config data (in the hash table %config), the target data that comes from the target configuration in one of the `Configurations/*.conf` files (in %target). *Richard Levitte* * To clarify their intended purposes, the Configure options --prefix and --openssldir change their semantics, and become more straightforward and less interdependent. --prefix shall be used exclusively to give the location INSTALLTOP where programs, scripts, libraries, include files and manuals are going to be installed. The default is now /usr/local. --openssldir shall be used exclusively to give the default location OPENSSLDIR where certificates, private keys, CRLs are managed. This is also where the default openssl.cnf gets installed. If the directory given with this option is a relative path, the values of both the --prefix value and the --openssldir value will be combined to become OPENSSLDIR. The default for --openssldir is INSTALLTOP/ssl. Anyone who uses --openssldir to specify where OpenSSL is to be installed MUST change to use --prefix instead. *Richard Levitte* * The GOST engine was out of date and therefore it has been removed. An up to date GOST engine is now being maintained in an external repository. See: . Libssl still retains support for GOST ciphersuites (these are only activated if a GOST engine is present). *Matt Caswell* * EGD is no longer supported by default; use enable-egd when configuring. *Ben Kaduk and Rich Salz* * The distribution now has Makefile.in files, which are used to create Makefile's when Configure is run. *Configure must be run before trying to build now.* *Rich Salz* * The return value for SSL_CIPHER_description() for error conditions has changed. *Rich Salz* * Support for RFC6698/RFC7671 DANE TLSA peer authentication. Obtaining and performing DNSSEC validation of TLSA records is the application's responsibility. The application provides the TLSA records of its choice to OpenSSL, and these are then used to authenticate the peer. The TLSA records need not even come from DNS. They can, for example, be used to implement local end-entity certificate or trust-anchor "pinning", where the "pin" data takes the form of TLSA records, which can augment or replace verification based on the usual WebPKI public certification authorities. *Viktor Dukhovni* * Revert default OPENSSL_NO_DEPRECATED setting. Instead OpenSSL continues to support deprecated interfaces in default builds. However, applications are strongly advised to compile their source files with -DOPENSSL_API_COMPAT=0x10100000L, which hides the declarations of all interfaces deprecated in 0.9.8, 1.0.0 or the 1.1.0 releases. In environments in which all applications have been ported to not use any deprecated interfaces OpenSSL's Configure script should be used with the --api=1.1.0 option to entirely remove support for the deprecated features from the library and unconditionally disable them in the installed headers. Essentially the same effect can be achieved with the "no-deprecated" argument to Configure, except that this will always restrict the build to just the latest API, rather than a fixed API version. As applications are ported to future revisions of the API, they should update their compile-time OPENSSL_API_COMPAT define accordingly, but in most cases should be able to continue to compile with later releases. The OPENSSL_API_COMPAT versions for 1.0.0, and 0.9.8 are 0x10000000L and 0x00908000L, respectively. However those versions did not support the OPENSSL_API_COMPAT feature, and so applications are not typically tested for explicit support of just the undeprecated features of either release. *Viktor Dukhovni* * Add support for setting the minimum and maximum supported protocol. It can bet set via the SSL_set_min_proto_version() and SSL_set_max_proto_version(), or via the SSL_CONF's MinProtocol and MaxProtocol. It's recommended to use the new APIs to disable protocols instead of disabling individual protocols using SSL_set_options() or SSL_CONF's Protocol. This change also removes support for disabling TLS 1.2 in the OpenSSL TLS client at compile time by defining OPENSSL_NO_TLS1_2_CLIENT. *Kurt Roeckx* * Support for ChaCha20 and Poly1305 added to libcrypto and libssl. *Andy Polyakov* * New EC_KEY_METHOD, this replaces the older ECDSA_METHOD and ECDH_METHOD and integrates ECDSA and ECDH functionality into EC. Implementations can now redirect key generation and no longer need to convert to or from ECDSA_SIG format. Note: the ecdsa.h and ecdh.h headers are now no longer needed and just include the ec.h header file instead. *Steve Henson* * Remove support for all 40 and 56 bit ciphers. This includes all the export ciphers who are no longer supported and drops support the ephemeral RSA key exchange. The LOW ciphers currently doesn't have any ciphers in it. *Kurt Roeckx* * Made EVP_MD_CTX, EVP_MD, EVP_CIPHER_CTX, EVP_CIPHER and HMAC_CTX opaque. For HMAC_CTX, the following constructors and destructors were added: HMAC_CTX *HMAC_CTX_new(void); void HMAC_CTX_free(HMAC_CTX *ctx); For EVP_MD and EVP_CIPHER, complete APIs to create, fill and destroy such methods has been added. See EVP_MD_meth_new(3) and EVP_CIPHER_meth_new(3) for documentation. Additional changes: 1) `EVP_MD_CTX_cleanup()`, `EVP_CIPHER_CTX_cleanup()` and `HMAC_CTX_cleanup()` were removed. `HMAC_CTX_reset()` and `EVP_MD_CTX_reset()` should be called instead to reinitialise an already created structure. 2) For consistency with the majority of our object creators and destructors, `EVP_MD_CTX_(create|destroy)` were renamed to `EVP_MD_CTX_(new|free)`. The old names are retained as macros for deprecated builds. *Richard Levitte* * Added ASYNC support. Libcrypto now includes the async sub-library to enable cryptographic operations to be performed asynchronously as long as an asynchronous capable engine is used. See the ASYNC_start_job() man page for further details. Libssl has also had this capability integrated with the introduction of the new mode SSL_MODE_ASYNC and associated error SSL_ERROR_WANT_ASYNC. See the SSL_CTX_set_mode() and SSL_get_error() man pages. This work was developed in partnership with Intel Corp. *Matt Caswell* * SSL_{CTX_}set_ecdh_auto() has been removed and ECDH is support is always enabled now. If you want to disable the support you should exclude it using the list of supported ciphers. This also means that the "-no_ecdhe" option has been removed from s_server. *Kurt Roeckx* * SSL_{CTX}_set_tmp_ecdh() which can set 1 EC curve now internally calls SSL_{CTX_}set1_curves() which can set a list. *Kurt Roeckx* * Remove support for SSL_{CTX_}set_tmp_ecdh_callback(). You should set the curve you want to support using SSL_{CTX_}set1_curves(). *Kurt Roeckx* * State machine rewrite. The state machine code has been significantly refactored in order to remove much duplication of code and solve issues with the old code (see [ssl/statem/README.md](ssl/statem/README.md) for further details). This change does have some associated API changes. Notably the SSL_state() function has been removed and replaced by SSL_get_state which now returns an "OSSL_HANDSHAKE_STATE" instead of an int. SSL_set_state() has been removed altogether. The previous handshake states defined in ssl.h and ssl3.h have also been removed. *Matt Caswell* * All instances of the string "ssleay" in the public API were replaced with OpenSSL (case-matching; e.g., OPENSSL_VERSION for #define's) Some error codes related to internal RSA_eay API's were renamed. *Rich Salz* * The demo files in crypto/threads were moved to demo/threads. *Rich Salz* * Removed obsolete engines: 4758cca, aep, atalla, cswift, nuron, gmp, sureware and ubsec. *Matt Caswell, Rich Salz* * New ASN.1 embed macro. New ASN.1 macro ASN1_EMBED. This is the same as ASN1_SIMPLE except the structure is not allocated: it is part of the parent. That is instead of FOO *x; it must be: FOO x; This reduces memory fragmentation and make it impossible to accidentally set a mandatory field to NULL. This currently only works for some fields specifically a SEQUENCE, CHOICE, or ASN1_STRING type which is part of a parent SEQUENCE. Since it is equivalent to ASN1_SIMPLE it cannot be tagged, OPTIONAL, SET OF or SEQUENCE OF. *Steve Henson* * Remove EVP_CHECK_DES_KEY, a compile-time option that never compiled. *Emilia Käsper* * Removed DES and RC4 ciphersuites from DEFAULT. Also removed RC2 although in 1.0.2 EXPORT was already removed and the only RC2 ciphersuite is also an EXPORT one. COMPLEMENTOFDEFAULT has been updated accordingly to add DES and RC4 ciphersuites. *Matt Caswell* * Rewrite EVP_DecodeUpdate (base64 decoding) to fix several bugs. This changes the decoding behaviour for some invalid messages, though the change is mostly in the more lenient direction, and legacy behaviour is preserved as much as possible. *Emilia Käsper* * Fix no-stdio build. *David Woodhouse and also* *Ivan Nestlerode * * New testing framework The testing framework has been largely rewritten and is now using perl and the perl modules Test::Harness and an extended variant of Test::More called OpenSSL::Test to do its work. All test scripts in test/ have been rewritten into test recipes, and all direct calls to executables in test/Makefile have become individual recipes using the simplified testing OpenSSL::Test::Simple. For documentation on our testing modules, do: perldoc test/testlib/OpenSSL/Test/Simple.pm perldoc test/testlib/OpenSSL/Test.pm *Richard Levitte* * Revamped memory debug; only -DCRYPTO_MDEBUG and -DCRYPTO_MDEBUG_ABORT are used; the latter aborts on memory leaks (usually checked on exit). Some undocumented "set malloc, etc., hooks" functions were removed and others were changed. All are now documented. *Rich Salz* * In DSA_generate_parameters_ex, if the provided seed is too short, return an error *Rich Salz and Ismo Puustinen * * Rewrite PSK to support ECDHE_PSK, DHE_PSK and RSA_PSK. Add ciphersuites from RFC4279, RFC4785, RFC5487, RFC5489. Thanks to Christian J. Dietrich and Giuseppe D'Angelo for the original RSA_PSK patch. *Steve Henson* * Dropped support for the SSL3_FLAGS_DELAY_CLIENT_FINISHED flag. This SSLeay era flag was never set throughout the codebase (only read). Also removed SSL3_FLAGS_POP_BUFFER which was only used if SSL3_FLAGS_DELAY_CLIENT_FINISHED was also set. *Matt Caswell* * Changed the default name options in the "ca", "crl", "req" and "x509" to be "oneline" instead of "compat". *Richard Levitte* * Remove SSL_OP_TLS_BLOCK_PADDING_BUG. This is SSLeay legacy, we're not aware of clients that still exhibit this bug, and the workaround hasn't been working properly for a while. *Emilia Käsper* * The return type of BIO_number_read() and BIO_number_written() as well as the corresponding num_read and num_write members in the BIO structure has changed from unsigned long to uint64_t. On platforms where an unsigned long is 32 bits (e.g. Windows) these counters could overflow if >4Gb is transferred. *Matt Caswell* * Given the pervasive nature of TLS extensions it is inadvisable to run OpenSSL without support for them. It also means that maintaining the OPENSSL_NO_TLSEXT option within the code is very invasive (and probably not well tested). Therefore the OPENSSL_NO_TLSEXT option has been removed. *Matt Caswell* * Removed support for the two export grade static DH ciphersuites EXP-DH-RSA-DES-CBC-SHA and EXP-DH-DSS-DES-CBC-SHA. These two ciphersuites were newly added (along with a number of other static DH ciphersuites) to 1.0.2. However the two export ones have *never* worked since they were introduced. It seems strange in any case to be adding new export ciphersuites, and given "logjam" it also does not seem correct to fix them. *Matt Caswell* * Version negotiation has been rewritten. In particular SSLv23_method(), SSLv23_client_method() and SSLv23_server_method() have been deprecated, and turned into macros which simply call the new preferred function names TLS_method(), TLS_client_method() and TLS_server_method(). All new code should use the new names instead. Also as part of this change the ssl23.h header file has been removed. *Matt Caswell* * Support for Kerberos ciphersuites in TLS (RFC2712) has been removed. This code and the associated standard is no longer considered fit-for-purpose. *Matt Caswell* * RT2547 was closed. When generating a private key, try to make the output file readable only by the owner. This behavior change might be noticeable when interacting with other software. * Documented all exdata functions. Added CRYPTO_free_ex_index. Added a test. *Rich Salz* * Added HTTP GET support to the ocsp command. *Rich Salz* * Changed default digest for the dgst and enc commands from MD5 to sha256 *Rich Salz* * RAND_pseudo_bytes has been deprecated. Users should use RAND_bytes instead. *Matt Caswell* * Added support for TLS extended master secret from draft-ietf-tls-session-hash-03.txt. Thanks for Alfredo Pironti for an initial patch which was a great help during development. *Steve Henson* * All libssl internal structures have been removed from the public header files, and the OPENSSL_NO_SSL_INTERN option has been removed (since it is now redundant). Users should not attempt to access internal structures directly. Instead they should use the provided API functions. *Matt Caswell* * config has been changed so that by default OPENSSL_NO_DEPRECATED is used. Access to deprecated functions can be re-enabled by running config with "enable-deprecated". In addition applications wishing to use deprecated functions must define OPENSSL_USE_DEPRECATED. Note that this new behaviour will, by default, disable some transitive includes that previously existed in the header files (e.g. ec.h will no longer, by default, include bn.h) *Matt Caswell* * Added support for OCB mode. OpenSSL has been granted a patent license compatible with the OpenSSL license for use of OCB. Details are available at . Support for OCB can be removed by calling config with no-ocb. *Matt Caswell* * SSLv2 support has been removed. It still supports receiving a SSLv2 compatible client hello. *Kurt Roeckx* * Increased the minimal RSA keysize from 256 to 512 bits [Rich Salz], done while fixing the error code for the key-too-small case. *Annie Yousar * * CA.sh has been removed; use CA.pl instead. *Rich Salz* * Removed old DES API. *Rich Salz* * Remove various unsupported platforms: Sony NEWS4 BEOS and BEOS_R5 NeXT SUNOS MPE/iX Sinix/ReliantUNIX RM400 DGUX NCR Tandem Cray 16-bit platforms such as WIN16 *Rich Salz* * Clean up OPENSSL_NO_xxx #define's - Use setbuf() and remove OPENSSL_NO_SETVBUF_IONBF - Rename OPENSSL_SYSNAME_xxx to OPENSSL_SYS_xxx - OPENSSL_NO_EC{DH,DSA} merged into OPENSSL_NO_EC - OPENSSL_NO_RIPEMD160, OPENSSL_NO_RIPEMD merged into OPENSSL_NO_RMD160 - OPENSSL_NO_FP_API merged into OPENSSL_NO_STDIO - Remove OPENSSL_NO_BIO OPENSSL_NO_BUFFER OPENSSL_NO_CHAIN_VERIFY OPENSSL_NO_EVP OPENSSL_NO_FIPS_ERR OPENSSL_NO_HASH_COMP OPENSSL_NO_LHASH OPENSSL_NO_OBJECT OPENSSL_NO_SPEED OPENSSL_NO_STACK OPENSSL_NO_X509 OPENSSL_NO_X509_VERIFY - Remove MS_STATIC; it's a relic from platforms <32 bits. *Rich Salz* * Cleaned up dead code Remove all but one '#ifdef undef' which is to be looked at. *Rich Salz* * Clean up calling of xxx_free routines. Just like free(), fix most of the xxx_free routines to accept NULL. Remove the non-null checks from callers. Save much code. *Rich Salz* * Add secure heap for storage of private keys (when possible). Add BIO_s_secmem(), CBIGNUM, etc. Contributed by Akamai Technologies under our Corporate CLA. *Rich Salz* * Experimental support for a new, fast, unbiased prime candidate generator, bn_probable_prime_dh_coprime(). Not currently used by any prime generator. *Felix Laurie von Massenbach * * New output format NSS in the sess_id command line tool. This allows exporting the session id and the master key in NSS keylog format. *Martin Kaiser * * Harmonize version and its documentation. -f flag is used to display compilation flags. *mancha * * Fix eckey_priv_encode so it immediately returns an error upon a failure in i2d_ECPrivateKey. Thanks to Ted Unangst for feedback on this issue. *mancha * * Fix some double frees. These are not thought to be exploitable. *mancha * * A missing bounds check in the handling of the TLS heartbeat extension can be used to reveal up to 64k of memory to a connected client or server. Thanks for Neel Mehta of Google Security for discovering this bug and to Adam Langley and Bodo Moeller for preparing the fix ([CVE-2014-0160]) *Adam Langley, Bodo Moeller* * Fix for the attack described in the paper "Recovering OpenSSL ECDSA Nonces Using the FLUSH+RELOAD Cache Side-channel Attack" by Yuval Yarom and Naomi Benger. Details can be obtained from: Thanks to Yuval Yarom and Naomi Benger for discovering this flaw and to Yuval Yarom for supplying a fix ([CVE-2014-0076]) *Yuval Yarom and Naomi Benger* * Use algorithm specific chains in SSL_CTX_use_certificate_chain_file(): this fixes a limitation in previous versions of OpenSSL. *Steve Henson* * Experimental encrypt-then-mac support. Experimental support for encrypt then mac from draft-gutmann-tls-encrypt-then-mac-02.txt To enable it set the appropriate extension number (0x42 for the test server) using e.g. -DTLSEXT_TYPE_encrypt_then_mac=0x42 For non-compliant peers (i.e. just about everything) this should have no effect. WARNING: EXPERIMENTAL, SUBJECT TO CHANGE. *Steve Henson* * Add EVP support for key wrapping algorithms, to avoid problems with existing code the flag EVP_CIPHER_CTX_WRAP_ALLOW has to be set in the EVP_CIPHER_CTX or an error is returned. Add AES and DES3 wrap algorithms and include tests cases. *Steve Henson* * Extend CMS code to support RSA-PSS signatures and RSA-OAEP for enveloped data. *Steve Henson* * Extended RSA OAEP support via EVP_PKEY API. Options to specify digest, MGF1 digest and OAEP label. *Steve Henson* * Make openssl verify return errors. *Chris Palmer and Ben Laurie* * New function ASN1_TIME_diff to calculate the difference between two ASN1_TIME structures or one structure and the current time. *Steve Henson* * Update fips_test_suite to support multiple command line options. New test to induce all self test errors in sequence and check expected failures. *Steve Henson* * Add FIPS_{rsa,dsa,ecdsa}_{sign,verify} functions which digest and sign or verify all in one operation. *Steve Henson* * Add fips_algvs: a multicall fips utility incorporating all the algorithm test programs and fips_test_suite. Includes functionality to parse the minimal script output of fipsalgest.pl directly. *Steve Henson* * Add authorisation parameter to FIPS_module_mode_set(). *Steve Henson* * Add FIPS selftest for ECDH algorithm using P-224 and B-233 curves. *Steve Henson* * Use separate DRBG fields for internal and external flags. New function FIPS_drbg_health_check() to perform on demand health checking. Add generation tests to fips_test_suite with reduced health check interval to demonstrate periodic health checking. Add "nodh" option to fips_test_suite to skip very slow DH test. *Steve Henson* * New function FIPS_get_cipherbynid() to lookup FIPS supported ciphers based on NID. *Steve Henson* * More extensive health check for DRBG checking many more failure modes. New function FIPS_selftest_drbg_all() to handle every possible DRBG combination: call this in fips_test_suite. *Steve Henson* * Add support for canonical generation of DSA parameter 'g'. See FIPS 186-3 A.2.3. * Add support for HMAC DRBG from SP800-90. Update DRBG algorithm test and POST to handle HMAC cases. *Steve Henson* * Add functions FIPS_module_version() and FIPS_module_version_text() to return numerical and string versions of the FIPS module number. *Steve Henson* * Rename FIPS_mode_set and FIPS_mode to FIPS_module_mode_set and FIPS_module_mode. FIPS_mode and FIPS_mode_set will be implemented outside the validated module in the FIPS capable OpenSSL. *Steve Henson* * Minor change to DRBG entropy callback semantics. In some cases there is no multiple of the block length between min_len and max_len. Allow the callback to return more than max_len bytes of entropy but discard any extra: it is the callback's responsibility to ensure that the extra data discarded does not impact the requested amount of entropy. *Steve Henson* * Add PRNG security strength checks to RSA, DSA and ECDSA using information in FIPS186-3, SP800-57 and SP800-131A. *Steve Henson* * CCM support via EVP. Interface is very similar to GCM case except we must supply all data in one chunk (i.e. no update, final) and the message length must be supplied if AAD is used. Add algorithm test support. *Steve Henson* * Initial version of POST overhaul. Add POST callback to allow the status of POST to be monitored and/or failures induced. Modify fips_test_suite to use callback. Always run all selftests even if one fails. *Steve Henson* * XTS support including algorithm test driver in the fips_gcmtest program. Note: this does increase the maximum key length from 32 to 64 bytes but there should be no binary compatibility issues as existing applications will never use XTS mode. *Steve Henson* * Extensive reorganisation of FIPS PRNG behaviour. Remove all dependencies to OpenSSL RAND code and replace with a tiny FIPS RAND API which also performs algorithm blocking for unapproved PRNG types. Also do not set PRNG type in FIPS_mode_set(): leave this to the application. Add default OpenSSL DRBG handling: sets up FIPS PRNG and seeds with the standard OpenSSL PRNG: set additional data to a date time vector. *Steve Henson* * Rename old X9.31 PRNG functions of the form `FIPS_rand*` to `FIPS_x931*`. This shouldn't present any incompatibility problems because applications shouldn't be using these directly and any that are will need to rethink anyway as the X9.31 PRNG is now deprecated by FIPS 140-2 *Steve Henson* * Extensive self tests and health checking required by SP800-90 DRBG. Remove strength parameter from FIPS_drbg_instantiate and always instantiate at maximum supported strength. *Steve Henson* * Add ECDH code to fips module and fips_ecdhvs for primitives only testing. *Steve Henson* * New algorithm test program fips_dhvs to handle DH primitives only testing. *Steve Henson* * New function DH_compute_key_padded() to compute a DH key and pad with leading zeroes if needed: this complies with SP800-56A et al. *Steve Henson* * Initial implementation of SP800-90 DRBGs for Hash and CTR. Not used by anything, incomplete, subject to change and largely untested at present. *Steve Henson* * Modify fipscanisteronly build option to only build the necessary object files by filtering FIPS_EX_OBJ through a perl script in crypto/Makefile. *Steve Henson* * Add experimental option FIPSSYMS to give all symbols in fipscanister.o and FIPS or fips prefix. This will avoid conflicts with future versions of OpenSSL. Add perl script util/fipsas.pl to preprocess assembly language source files and rename any affected symbols. *Steve Henson* * Add selftest checks and algorithm block of non-fips algorithms in FIPS mode. Remove DES2 from selftests. *Steve Henson* * Add ECDSA code to fips module. Add tiny fips_ecdsa_check to just return internal method without any ENGINE dependencies. Add new tiny fips sign and verify functions. *Steve Henson* * New build option no-ec2m to disable characteristic 2 code. *Steve Henson* * New build option "fipscanisteronly". This only builds fipscanister.o and (currently) associated fips utilities. Uses the file Makefile.fips instead of Makefile.org as the prototype. *Steve Henson* * Add some FIPS mode restrictions to GCM. Add internal IV generator. Update fips_gcmtest to use IV generator. *Steve Henson* * Initial, experimental EVP support for AES-GCM. AAD can be input by setting output buffer to NULL. The `*Final` function must be called although it will not retrieve any additional data. The tag can be set or retrieved with a ctrl. The IV length is by default 12 bytes (96 bits) but can be set to an alternative value. If the IV length exceeds the maximum IV length (currently 16 bytes) it cannot be set before the key. *Steve Henson* * New flag in ciphers: EVP_CIPH_FLAG_CUSTOM_CIPHER. This means the underlying do_cipher function handles all cipher semantics itself including padding and finalisation. This is useful if (for example) an ENGINE cipher handles block padding itself. The behaviour of do_cipher is subtly changed if this flag is set: the return value is the number of characters written to the output buffer (zero is no longer an error code) or a negative error code. Also if the input buffer is NULL and length 0 finalisation should be performed. *Steve Henson* * If a candidate issuer certificate is already part of the constructed path ignore it: new debug notification X509_V_ERR_PATH_LOOP for this case. *Steve Henson* * Improve forward-security support: add functions void SSL_CTX_set_not_resumable_session_callback( SSL_CTX *ctx, int (*cb)(SSL *ssl, int is_forward_secure)) void SSL_set_not_resumable_session_callback( SSL *ssl, int (*cb)(SSL *ssl, int is_forward_secure)) for use by SSL/TLS servers; the callback function will be called whenever a new session is created, and gets to decide whether the session may be cached to make it resumable (return 0) or not (return 1). (As by the SSL/TLS protocol specifications, the session_id sent by the server will be empty to indicate that the session is not resumable; also, the server will not generate RFC 4507 (RFC 5077) session tickets.) A simple reasonable callback implementation is to return is_forward_secure. This parameter will be set to 1 or 0 depending on the ciphersuite selected by the SSL/TLS server library, indicating whether it can provide forward security. *Emilia Käsper (Google)* * New -verify_name option in command line utilities to set verification parameters by name. *Steve Henson* * Initial CMAC implementation. WARNING: EXPERIMENTAL, API MAY CHANGE. Add CMAC pkey methods. *Steve Henson* * Experimental renegotiation in s_server -www mode. If the client browses /reneg connection is renegotiated. If /renegcert it is renegotiated requesting a certificate. *Steve Henson* * Add an "external" session cache for debugging purposes to s_server. This should help trace issues which normally are only apparent in deployed multi-process servers. *Steve Henson* * Extensive audit of libcrypto with DEBUG_UNUSED. Fix many cases where return value is ignored. NB. The functions RAND_add(), RAND_seed(), BIO_set_cipher() and some obscure PEM functions were changed so they can now return an error. The RAND changes required a change to the RAND_METHOD structure. *Steve Henson* * New macro `__owur` for "OpenSSL Warn Unused Result". This makes use of a gcc attribute to warn if the result of a function is ignored. This is enable if DEBUG_UNUSED is set. Add to several functions in evp.h whose return value is often ignored. *Steve Henson* * New -noct, -requestct, -requirect and -ctlogfile options for s_client. These allow SCTs (signed certificate timestamps) to be requested and validated when establishing a connection. *Rob Percival * OpenSSL 1.0.2 ------------- ### Changes between 1.0.2s and 1.0.2t [10 Sep 2019] * For built-in EC curves, ensure an EC_GROUP built from the curve name is used even when parsing explicit parameters, when loading a encoded key or calling `EC_GROUP_new_from_ecpkparameters()`/ `EC_GROUP_new_from_ecparameters()`. This prevents bypass of security hardening and performance gains, especially for curves with specialized EC_METHODs. By default, if a key encoded with explicit parameters is loaded and later encoded, the output is still encoded with explicit parameters, even if internally a "named" EC_GROUP is used for computation. *Nicola Tuveri* * Compute ECC cofactors if not provided during EC_GROUP construction. Before this change, EC_GROUP_set_generator would accept order and/or cofactor as NULL. After this change, only the cofactor parameter can be NULL. It also does some minimal sanity checks on the passed order. ([CVE-2019-1547]) *Billy Bob Brumley* * Fixed a padding oracle in PKCS7_dataDecode and CMS_decrypt_set1_pkey. An attack is simple, if the first CMS_recipientInfo is valid but the second CMS_recipientInfo is chosen ciphertext. If the second recipientInfo decodes to PKCS #1 v1.5 form plaintext, the correct encryption key will be replaced by garbage, and the message cannot be decoded, but if the RSA decryption fails, the correct encryption key is used and the recipient will not notice the attack. As a work around for this potential attack the length of the decrypted key must be equal to the cipher default key length, in case the certifiate is not given and all recipientInfo are tried out. The old behaviour can be re-enabled in the CMS code by setting the CMS_DEBUG_DECRYPT flag. ([CVE-2019-1563]) *Bernd Edlinger* * Document issue with installation paths in diverse Windows builds '/usr/local/ssl' is an unsafe prefix for location to install OpenSSL binaries and run-time config file. ([CVE-2019-1552]) *Richard Levitte* ### Changes between 1.0.2r and 1.0.2s [28 May 2019] * Change the default RSA, DSA and DH size to 2048 bit instead of 1024. This changes the size when using the `genpkey` command when no size is given. It fixes an omission in earlier changes that changed all RSA, DSA and DH generation commands to use 2048 bits by default. *Kurt Roeckx* * Add FIPS support for Android Arm 64-bit Support for Android Arm 64-bit was added to the OpenSSL FIPS Object Module in Version 2.0.10. For some reason, the corresponding target 'android64-aarch64' was missing OpenSSL 1.0.2, whence it could not be built with FIPS support on Android Arm 64-bit. This omission has been fixed. *Matthias St. Pierre* ### Changes between 1.0.2q and 1.0.2r [26 Feb 2019] * 0-byte record padding oracle If an application encounters a fatal protocol error and then calls SSL_shutdown() twice (once to send a close_notify, and once to receive one) then OpenSSL can respond differently to the calling application if a 0 byte record is received with invalid padding compared to if a 0 byte record is received with an invalid MAC. If the application then behaves differently based on that in a way that is detectable to the remote peer, then this amounts to a padding oracle that could be used to decrypt data. In order for this to be exploitable "non-stitched" ciphersuites must be in use. Stitched ciphersuites are optimised implementations of certain commonly used ciphersuites. Also the application must call SSL_shutdown() twice even if a protocol error has occurred (applications should not do this but some do anyway). This issue was discovered by Juraj Somorovsky, Robert Merget and Nimrod Aviram, with additional investigation by Steven Collison and Andrew Hourselt. It was reported to OpenSSL on 10th December 2018. ([CVE-2019-1559]) *Matt Caswell* * Move strictness check from EVP_PKEY_asn1_new() to EVP_PKEY_asn1_add0(). *Richard Levitte* ### Changes between 1.0.2p and 1.0.2q [20 Nov 2018] * Microarchitecture timing vulnerability in ECC scalar multiplication OpenSSL ECC scalar multiplication, used in e.g. ECDSA and ECDH, has been shown to be vulnerable to a microarchitecture timing side channel attack. An attacker with sufficient access to mount local timing attacks during ECDSA signature generation could recover the private key. This issue was reported to OpenSSL on 26th October 2018 by Alejandro Cabrera Aldaya, Billy Brumley, Sohaib ul Hassan, Cesar Pereida Garcia and Nicola Tuveri. ([CVE-2018-5407]) *Billy Brumley* * Timing vulnerability in DSA signature generation The OpenSSL DSA signature algorithm has been shown to be vulnerable to a timing side channel attack. An attacker could use variations in the signing algorithm to recover the private key. This issue was reported to OpenSSL on 16th October 2018 by Samuel Weiser. ([CVE-2018-0734]) *Paul Dale* * Resolve a compatibility issue in EC_GROUP handling with the FIPS Object Module, accidentally introduced while backporting security fixes from the development branch and hindering the use of ECC in FIPS mode. *Nicola Tuveri* ### Changes between 1.0.2o and 1.0.2p [14 Aug 2018] * Client DoS due to large DH parameter During key agreement in a TLS handshake using a DH(E) based ciphersuite a malicious server can send a very large prime value to the client. This will cause the client to spend an unreasonably long period of time generating a key for this prime resulting in a hang until the client has finished. This could be exploited in a Denial Of Service attack. This issue was reported to OpenSSL on 5th June 2018 by Guido Vranken ([CVE-2018-0732]) *Guido Vranken* * Cache timing vulnerability in RSA Key Generation The OpenSSL RSA Key generation algorithm has been shown to be vulnerable to a cache timing side channel attack. An attacker with sufficient access to mount cache timing attacks during the RSA key generation process could recover the private key. This issue was reported to OpenSSL on 4th April 2018 by Alejandro Cabrera Aldaya, Billy Brumley, Cesar Pereida Garcia and Luis Manuel Alvarez Tapia. ([CVE-2018-0737]) *Billy Brumley* * Make EVP_PKEY_asn1_new() a bit stricter about its input. A NULL pem_str parameter is no longer accepted, as it leads to a corrupt table. NULL pem_str is reserved for alias entries only. *Richard Levitte* * Revert blinding in ECDSA sign and instead make problematic addition length-invariant. Switch even to fixed-length Montgomery multiplication. *Andy Polyakov* * Change generating and checking of primes so that the error rate of not being prime depends on the intended use based on the size of the input. For larger primes this will result in more rounds of Miller-Rabin. The maximal error rate for primes with more than 1080 bits is lowered to 2^-128. *Kurt Roeckx, Annie Yousar* * Increase the number of Miller-Rabin rounds for DSA key generating to 64. *Kurt Roeckx* * Add blinding to ECDSA and DSA signatures to protect against side channel attacks discovered by Keegan Ryan (NCC Group). *Matt Caswell* * When unlocking a pass phrase protected PEM file or PKCS#8 container, we now allow empty (zero character) pass phrases. *Richard Levitte* * Certificate time validation (X509_cmp_time) enforces stricter compliance with RFC 5280. Fractional seconds and timezone offsets are no longer allowed. *Emilia Käsper* ### Changes between 1.0.2n and 1.0.2o [27 Mar 2018] * Constructed ASN.1 types with a recursive definition could exceed the stack Constructed ASN.1 types with a recursive definition (such as can be found in PKCS7) could eventually exceed the stack given malicious input with excessive recursion. This could result in a Denial Of Service attack. There are no such structures used within SSL/TLS that come from untrusted sources so this is considered safe. This issue was reported to OpenSSL on 4th January 2018 by the OSS-fuzz project. ([CVE-2018-0739]) *Matt Caswell* ### Changes between 1.0.2m and 1.0.2n [7 Dec 2017] * Read/write after SSL object in error state OpenSSL 1.0.2 (starting from version 1.0.2b) introduced an "error state" mechanism. The intent was that if a fatal error occurred during a handshake then OpenSSL would move into the error state and would immediately fail if you attempted to continue the handshake. This works as designed for the explicit handshake functions (SSL_do_handshake(), SSL_accept() and SSL_connect()), however due to a bug it does not work correctly if SSL_read() or SSL_write() is called directly. In that scenario, if the handshake fails then a fatal error will be returned in the initial function call. If SSL_read()/SSL_write() is subsequently called by the application for the same SSL object then it will succeed and the data is passed without being decrypted/encrypted directly from the SSL/TLS record layer. In order to exploit this issue an application bug would have to be present that resulted in a call to SSL_read()/SSL_write() being issued after having already received a fatal error. This issue was reported to OpenSSL by David Benjamin (Google). ([CVE-2017-3737]) *Matt Caswell* * rsaz_1024_mul_avx2 overflow bug on x86_64 There is an overflow bug in the AVX2 Montgomery multiplication procedure used in exponentiation with 1024-bit moduli. No EC algorithms are affected. Analysis suggests that attacks against RSA and DSA as a result of this defect would be very difficult to perform and are not believed likely. Attacks against DH1024 are considered just feasible, because most of the work necessary to deduce information about a private key may be performed offline. The amount of resources required for such an attack would be significant. However, for an attack on TLS to be meaningful, the server would have to share the DH1024 private key among multiple clients, which is no longer an option since CVE-2016-0701. This only affects processors that support the AVX2 but not ADX extensions like Intel Haswell (4th generation). This issue was reported to OpenSSL by David Benjamin (Google). The issue was originally found via the OSS-Fuzz project. ([CVE-2017-3738]) *Andy Polyakov* ### Changes between 1.0.2l and 1.0.2m [2 Nov 2017] * bn_sqrx8x_internal carry bug on x86_64 There is a carry propagating bug in the x86_64 Montgomery squaring procedure. No EC algorithms are affected. Analysis suggests that attacks against RSA and DSA as a result of this defect would be very difficult to perform and are not believed likely. Attacks against DH are considered just feasible (although very difficult) because most of the work necessary to deduce information about a private key may be performed offline. The amount of resources required for such an attack would be very significant and likely only accessible to a limited number of attackers. An attacker would additionally need online access to an unpatched system using the target private key in a scenario with persistent DH parameters and a private key that is shared between multiple clients. This only affects processors that support the BMI1, BMI2 and ADX extensions like Intel Broadwell (5th generation) and later or AMD Ryzen. This issue was reported to OpenSSL by the OSS-Fuzz project. ([CVE-2017-3736]) *Andy Polyakov* * Malformed X.509 IPAddressFamily could cause OOB read If an X.509 certificate has a malformed IPAddressFamily extension, OpenSSL could do a one-byte buffer overread. The most likely result would be an erroneous display of the certificate in text format. This issue was reported to OpenSSL by the OSS-Fuzz project. *Rich Salz* ### Changes between 1.0.2k and 1.0.2l [25 May 2017] * Have 'config' recognise 64-bit mingw and choose 'mingw64' as the target platform rather than 'mingw'. *Richard Levitte* ### Changes between 1.0.2j and 1.0.2k [26 Jan 2017] * Truncated packet could crash via OOB read If one side of an SSL/TLS path is running on a 32-bit host and a specific cipher is being used, then a truncated packet can cause that host to perform an out-of-bounds read, usually resulting in a crash. This issue was reported to OpenSSL by Robert Święcki of Google. ([CVE-2017-3731]) *Andy Polyakov* * BN_mod_exp may produce incorrect results on x86_64 There is a carry propagating bug in the x86_64 Montgomery squaring procedure. No EC algorithms are affected. Analysis suggests that attacks against RSA and DSA as a result of this defect would be very difficult to perform and are not believed likely. Attacks against DH are considered just feasible (although very difficult) because most of the work necessary to deduce information about a private key may be performed offline. The amount of resources required for such an attack would be very significant and likely only accessible to a limited number of attackers. An attacker would additionally need online access to an unpatched system using the target private key in a scenario with persistent DH parameters and a private key that is shared between multiple clients. For example this can occur by default in OpenSSL DHE based SSL/TLS ciphersuites. Note: This issue is very similar to CVE-2015-3193 but must be treated as a separate problem. This issue was reported to OpenSSL by the OSS-Fuzz project. ([CVE-2017-3732]) *Andy Polyakov* * Montgomery multiplication may produce incorrect results There is a carry propagating bug in the Broadwell-specific Montgomery multiplication procedure that handles input lengths divisible by, but longer than 256 bits. Analysis suggests that attacks against RSA, DSA and DH private keys are impossible. This is because the subroutine in question is not used in operations with the private key itself and an input of the attacker's direct choice. Otherwise the bug can manifest itself as transient authentication and key negotiation failures or reproducible erroneous outcome of public-key operations with specially crafted input. Among EC algorithms only Brainpool P-512 curves are affected and one presumably can attack ECDH key negotiation. Impact was not analyzed in detail, because pre-requisites for attack are considered unlikely. Namely multiple clients have to choose the curve in question and the server has to share the private key among them, neither of which is default behaviour. Even then only clients that chose the curve will be affected. This issue was publicly reported as transient failures and was not initially recognized as a security issue. Thanks to Richard Morgan for providing reproducible case. ([CVE-2016-7055]) *Andy Polyakov* * OpenSSL now fails if it receives an unrecognised record type in TLS1.0 or TLS1.1. Previously this only happened in SSLv3 and TLS1.2. This is to prevent issues where no progress is being made and the peer continually sends unrecognised record types, using up resources processing them. *Matt Caswell* ### Changes between 1.0.2i and 1.0.2j [26 Sep 2016] * Missing CRL sanity check A bug fix which included a CRL sanity check was added to OpenSSL 1.1.0 but was omitted from OpenSSL 1.0.2i. As a result any attempt to use CRLs in OpenSSL 1.0.2i will crash with a null pointer exception. This issue only affects the OpenSSL 1.0.2i ([CVE-2016-7052]) *Matt Caswell* ### Changes between 1.0.2h and 1.0.2i [22 Sep 2016] * OCSP Status Request extension unbounded memory growth A malicious client can send an excessively large OCSP Status Request extension. If that client continually requests renegotiation, sending a large OCSP Status Request extension each time, then there will be unbounded memory growth on the server. This will eventually lead to a Denial Of Service attack through memory exhaustion. Servers with a default configuration are vulnerable even if they do not support OCSP. Builds using the "no-ocsp" build time option are not affected. This issue was reported to OpenSSL by Shi Lei (Gear Team, Qihoo 360 Inc.) ([CVE-2016-6304]) *Matt Caswell* * In order to mitigate the SWEET32 attack, the DES ciphers were moved from HIGH to MEDIUM. This issue was reported to OpenSSL Karthikeyan Bhargavan and Gaetan Leurent (INRIA) ([CVE-2016-2183]) *Rich Salz* * OOB write in MDC2_Update() An overflow can occur in MDC2_Update() either if called directly or through the EVP_DigestUpdate() function using MDC2. If an attacker is able to supply very large amounts of input data after a previous call to EVP_EncryptUpdate() with a partial block then a length check can overflow resulting in a heap corruption. The amount of data needed is comparable to SIZE_MAX which is impractical on most platforms. This issue was reported to OpenSSL by Shi Lei (Gear Team, Qihoo 360 Inc.) ([CVE-2016-6303]) *Stephen Henson* * Malformed SHA512 ticket DoS If a server uses SHA512 for TLS session ticket HMAC it is vulnerable to a DoS attack where a malformed ticket will result in an OOB read which will ultimately crash. The use of SHA512 in TLS session tickets is comparatively rare as it requires a custom server callback and ticket lookup mechanism. This issue was reported to OpenSSL by Shi Lei (Gear Team, Qihoo 360 Inc.) ([CVE-2016-6302]) *Stephen Henson* * OOB write in BN_bn2dec() The function BN_bn2dec() does not check the return value of BN_div_word(). This can cause an OOB write if an application uses this function with an overly large BIGNUM. This could be a problem if an overly large certificate or CRL is printed out from an untrusted source. TLS is not affected because record limits will reject an oversized certificate before it is parsed. This issue was reported to OpenSSL by Shi Lei (Gear Team, Qihoo 360 Inc.) ([CVE-2016-2182]) *Stephen Henson* * OOB read in TS_OBJ_print_bio() The function TS_OBJ_print_bio() misuses OBJ_obj2txt(): the return value is the total length the OID text representation would use and not the amount of data written. This will result in OOB reads when large OIDs are presented. This issue was reported to OpenSSL by Shi Lei (Gear Team, Qihoo 360 Inc.) ([CVE-2016-2180]) *Stephen Henson* * Pointer arithmetic undefined behaviour Avoid some undefined pointer arithmetic A common idiom in the codebase is to check limits in the following manner: "p + len > limit" Where "p" points to some malloc'd data of SIZE bytes and limit == p + SIZE "len" here could be from some externally supplied data (e.g. from a TLS message). The rules of C pointer arithmetic are such that "p + len" is only well defined where len <= SIZE. Therefore the above idiom is actually undefined behaviour. For example this could cause problems if some malloc implementation provides an address for "p" such that "p + len" actually overflows for values of len that are too big and therefore p + len < limit. This issue was reported to OpenSSL by Guido Vranken ([CVE-2016-2177]) *Matt Caswell* * Constant time flag not preserved in DSA signing Operations in the DSA signing algorithm should run in constant time in order to avoid side channel attacks. A flaw in the OpenSSL DSA implementation means that a non-constant time codepath is followed for certain operations. This has been demonstrated through a cache-timing attack to be sufficient for an attacker to recover the private DSA key. This issue was reported by César Pereida (Aalto University), Billy Brumley (Tampere University of Technology), and Yuval Yarom (The University of Adelaide and NICTA). ([CVE-2016-2178]) *César Pereida* * DTLS buffered message DoS In a DTLS connection where handshake messages are delivered out-of-order those messages that OpenSSL is not yet ready to process will be buffered for later use. Under certain circumstances, a flaw in the logic means that those messages do not get removed from the buffer even though the handshake has been completed. An attacker could force up to approx. 15 messages to remain in the buffer when they are no longer required. These messages will be cleared when the DTLS connection is closed. The default maximum size for a message is 100k. Therefore the attacker could force an additional 1500k to be consumed per connection. By opening many simulataneous connections an attacker could cause a DoS attack through memory exhaustion. This issue was reported to OpenSSL by Quan Luo. ([CVE-2016-2179]) *Matt Caswell* * DTLS replay protection DoS A flaw in the DTLS replay attack protection mechanism means that records that arrive for future epochs update the replay protection "window" before the MAC for the record has been validated. This could be exploited by an attacker by sending a record for the next epoch (which does not have to decrypt or have a valid MAC), with a very large sequence number. This means that all subsequent legitimate packets are dropped causing a denial of service for a specific DTLS connection. This issue was reported to OpenSSL by the OCAP audit team. ([CVE-2016-2181]) *Matt Caswell* * Certificate message OOB reads In OpenSSL 1.0.2 and earlier some missing message length checks can result in OOB reads of up to 2 bytes beyond an allocated buffer. There is a theoretical DoS risk but this has not been observed in practice on common platforms. The messages affected are client certificate, client certificate request and server certificate. As a result the attack can only be performed against a client or a server which enables client authentication. This issue was reported to OpenSSL by Shi Lei (Gear Team, Qihoo 360 Inc.) ([CVE-2016-6306]) *Stephen Henson* ### Changes between 1.0.2g and 1.0.2h [3 May 2016] * Prevent padding oracle in AES-NI CBC MAC check A MITM attacker can use a padding oracle attack to decrypt traffic when the connection uses an AES CBC cipher and the server support AES-NI. This issue was introduced as part of the fix for Lucky 13 padding attack ([CVE-2013-0169]). The padding check was rewritten to be in constant time by making sure that always the same bytes are read and compared against either the MAC or padding bytes. But it no longer checked that there was enough data to have both the MAC and padding bytes. This issue was reported by Juraj Somorovsky using TLS-Attacker. *Kurt Roeckx* * Fix EVP_EncodeUpdate overflow An overflow can occur in the EVP_EncodeUpdate() function which is used for Base64 encoding of binary data. If an attacker is able to supply very large amounts of input data then a length check can overflow resulting in a heap corruption. Internally to OpenSSL the EVP_EncodeUpdate() function is primarily used by the `PEM_write_bio*` family of functions. These are mainly used within the OpenSSL command line applications, so any application which processes data from an untrusted source and outputs it as a PEM file should be considered vulnerable to this issue. User applications that call these APIs directly with large amounts of untrusted data may also be vulnerable. This issue was reported by Guido Vranken. ([CVE-2016-2105]) *Matt Caswell* * Fix EVP_EncryptUpdate overflow An overflow can occur in the EVP_EncryptUpdate() function. If an attacker is able to supply very large amounts of input data after a previous call to EVP_EncryptUpdate() with a partial block then a length check can overflow resulting in a heap corruption. Following an analysis of all OpenSSL internal usage of the EVP_EncryptUpdate() function all usage is one of two forms. The first form is where the EVP_EncryptUpdate() call is known to be the first called function after an EVP_EncryptInit(), and therefore that specific call must be safe. The second form is where the length passed to EVP_EncryptUpdate() can be seen from the code to be some small value and therefore there is no possibility of an overflow. Since all instances are one of these two forms, it is believed that there can be no overflows in internal code due to this problem. It should be noted that EVP_DecryptUpdate() can call EVP_EncryptUpdate() in certain code paths. Also EVP_CipherUpdate() is a synonym for EVP_EncryptUpdate(). All instances of these calls have also been analysed too and it is believed there are no instances in internal usage where an overflow could occur. This issue was reported by Guido Vranken. ([CVE-2016-2106]) *Matt Caswell* * Prevent ASN.1 BIO excessive memory allocation When ASN.1 data is read from a BIO using functions such as d2i_CMS_bio() a short invalid encoding can cause allocation of large amounts of memory potentially consuming excessive resources or exhausting memory. Any application parsing untrusted data through d2i BIO functions is affected. The memory based functions such as d2i_X509() are *not* affected. Since the memory based functions are used by the TLS library, TLS applications are not affected. This issue was reported by Brian Carpenter. ([CVE-2016-2109]) *Stephen Henson* * EBCDIC overread ASN1 Strings that are over 1024 bytes can cause an overread in applications using the X509_NAME_oneline() function on EBCDIC systems. This could result in arbitrary stack data being returned in the buffer. This issue was reported by Guido Vranken. ([CVE-2016-2176]) *Matt Caswell* * Modify behavior of ALPN to invoke callback after SNI/servername callback, such that updates to the SSL_CTX affect ALPN. *Todd Short* * Remove LOW from the DEFAULT cipher list. This removes singles DES from the default. *Kurt Roeckx* * Only remove the SSLv2 methods with the no-ssl2-method option. When the methods are enabled and ssl2 is disabled the methods return NULL. *Kurt Roeckx* ### Changes between 1.0.2f and 1.0.2g [1 Mar 2016] * Disable weak ciphers in SSLv3 and up in default builds of OpenSSL. Builds that are not configured with "enable-weak-ssl-ciphers" will not provide any "EXPORT" or "LOW" strength ciphers. *Viktor Dukhovni* * Disable SSLv2 default build, default negotiation and weak ciphers. SSLv2 is by default disabled at build-time. Builds that are not configured with "enable-ssl2" will not support SSLv2. Even if "enable-ssl2" is used, users who want to negotiate SSLv2 via the version-flexible SSLv23_method() will need to explicitly call either of: SSL_CTX_clear_options(ctx, SSL_OP_NO_SSLv2); or SSL_clear_options(ssl, SSL_OP_NO_SSLv2); as appropriate. Even if either of those is used, or the application explicitly uses the version-specific SSLv2_method() or its client and server variants, SSLv2 ciphers vulnerable to exhaustive search key recovery have been removed. Specifically, the SSLv2 40-bit EXPORT ciphers, and SSLv2 56-bit DES are no longer available. ([CVE-2016-0800]) *Viktor Dukhovni* * Fix a double-free in DSA code A double free bug was discovered when OpenSSL parses malformed DSA private keys and could lead to a DoS attack or memory corruption for applications that receive DSA private keys from untrusted sources. This scenario is considered rare. This issue was reported to OpenSSL by Adam Langley(Google/BoringSSL) using libFuzzer. ([CVE-2016-0705]) *Stephen Henson* * Disable SRP fake user seed to address a server memory leak. Add a new method SRP_VBASE_get1_by_user that handles the seed properly. SRP_VBASE_get_by_user had inconsistent memory management behaviour. In order to fix an unavoidable memory leak, SRP_VBASE_get_by_user was changed to ignore the "fake user" SRP seed, even if the seed is configured. Users should use SRP_VBASE_get1_by_user instead. Note that in SRP_VBASE_get1_by_user, caller must free the returned value. Note also that even though configuring the SRP seed attempts to hide invalid usernames by continuing the handshake with fake credentials, this behaviour is not constant time and no strong guarantees are made that the handshake is indistinguishable from that of a valid user. ([CVE-2016-0798]) *Emilia Käsper* * Fix BN_hex2bn/BN_dec2bn NULL pointer deref/heap corruption In the BN_hex2bn function the number of hex digits is calculated using an int value `i`. Later `bn_expand` is called with a value of `i * 4`. For large values of `i` this can result in `bn_expand` not allocating any memory because `i * 4` is negative. This can leave the internal BIGNUM data field as NULL leading to a subsequent NULL ptr deref. For very large values of `i`, the calculation `i * 4` could be a positive value smaller than `i`. In this case memory is allocated to the internal BIGNUM data field, but it is insufficiently sized leading to heap corruption. A similar issue exists in BN_dec2bn. This could have security consequences if BN_hex2bn/BN_dec2bn is ever called by user applications with very large untrusted hex/dec data. This is anticipated to be a rare occurrence. All OpenSSL internal usage of these functions use data that is not expected to be untrusted, e.g. config file data or application command line arguments. If user developed applications generate config file data based on untrusted data then it is possible that this could also lead to security consequences. This is also anticipated to be rare. This issue was reported to OpenSSL by Guido Vranken. ([CVE-2016-0797]) *Matt Caswell* * Fix memory issues in `BIO_*printf` functions The internal `fmtstr` function used in processing a "%s" format string in the `BIO_*printf` functions could overflow while calculating the length of a string and cause an OOB read when printing very long strings. Additionally the internal `doapr_outch` function can attempt to write to an OOB memory location (at an offset from the NULL pointer) in the event of a memory allocation failure. In 1.0.2 and below this could be caused where the size of a buffer to be allocated is greater than INT_MAX. E.g. this could be in processing a very long "%s" format string. Memory leaks can also occur. The first issue may mask the second issue dependent on compiler behaviour. These problems could enable attacks where large amounts of untrusted data is passed to the `BIO_*printf` functions. If applications use these functions in this way then they could be vulnerable. OpenSSL itself uses these functions when printing out human-readable dumps of ASN.1 data. Therefore applications that print this data could be vulnerable if the data is from untrusted sources. OpenSSL command line applications could also be vulnerable where they print out ASN.1 data, or if untrusted data is passed as command line arguments. Libssl is not considered directly vulnerable. Additionally certificates etc received via remote connections via libssl are also unlikely to be able to trigger these issues because of message size limits enforced within libssl. This issue was reported to OpenSSL Guido Vranken. ([CVE-2016-0799]) *Matt Caswell* * Side channel attack on modular exponentiation A side-channel attack was found which makes use of cache-bank conflicts on the Intel Sandy-Bridge microarchitecture which could lead to the recovery of RSA keys. The ability to exploit this issue is limited as it relies on an attacker who has control of code in a thread running on the same hyper-threaded core as the victim thread which is performing decryptions. This issue was reported to OpenSSL by Yuval Yarom, The University of Adelaide and NICTA, Daniel Genkin, Technion and Tel Aviv University, and Nadia Heninger, University of Pennsylvania with more information at . ([CVE-2016-0702]) *Andy Polyakov* * Change the `req` command to generate a 2048-bit RSA/DSA key by default, if no keysize is specified with default_bits. This fixes an omission in an earlier change that changed all RSA/DSA key generation commands to use 2048 bits by default. *Emilia Käsper* ### Changes between 1.0.2e and 1.0.2f [28 Jan 2016] * DH small subgroups Historically OpenSSL only ever generated DH parameters based on "safe" primes. More recently (in version 1.0.2) support was provided for generating X9.42 style parameter files such as those required for RFC 5114 support. The primes used in such files may not be "safe". Where an application is using DH configured with parameters based on primes that are not "safe" then an attacker could use this fact to find a peer's private DH exponent. This attack requires that the attacker complete multiple handshakes in which the peer uses the same private DH exponent. For example this could be used to discover a TLS server's private DH exponent if it's reusing the private DH exponent or it's using a static DH ciphersuite. OpenSSL provides the option SSL_OP_SINGLE_DH_USE for ephemeral DH (DHE) in TLS. It is not on by default. If the option is not set then the server reuses the same private DH exponent for the life of the server process and would be vulnerable to this attack. It is believed that many popular applications do set this option and would therefore not be at risk. The fix for this issue adds an additional check where a "q" parameter is available (as is the case in X9.42 based parameters). This detects the only known attack, and is the only possible defense for static DH ciphersuites. This could have some performance impact. Additionally the SSL_OP_SINGLE_DH_USE option has been switched on by default and cannot be disabled. This could have some performance impact. This issue was reported to OpenSSL by Antonio Sanso (Adobe). ([CVE-2016-0701]) *Matt Caswell* * SSLv2 doesn't block disabled ciphers A malicious client can negotiate SSLv2 ciphers that have been disabled on the server and complete SSLv2 handshakes even if all SSLv2 ciphers have been disabled, provided that the SSLv2 protocol was not also disabled via SSL_OP_NO_SSLv2. This issue was reported to OpenSSL on 26th December 2015 by Nimrod Aviram and Sebastian Schinzel. ([CVE-2015-3197]) *Viktor Dukhovni* ### Changes between 1.0.2d and 1.0.2e [3 Dec 2015] * BN_mod_exp may produce incorrect results on x86_64 There is a carry propagating bug in the x86_64 Montgomery squaring procedure. No EC algorithms are affected. Analysis suggests that attacks against RSA and DSA as a result of this defect would be very difficult to perform and are not believed likely. Attacks against DH are considered just feasible (although very difficult) because most of the work necessary to deduce information about a private key may be performed offline. The amount of resources required for such an attack would be very significant and likely only accessible to a limited number of attackers. An attacker would additionally need online access to an unpatched system using the target private key in a scenario with persistent DH parameters and a private key that is shared between multiple clients. For example this can occur by default in OpenSSL DHE based SSL/TLS ciphersuites. This issue was reported to OpenSSL by Hanno Böck. ([CVE-2015-3193]) *Andy Polyakov* * Certificate verify crash with missing PSS parameter The signature verification routines will crash with a NULL pointer dereference if presented with an ASN.1 signature using the RSA PSS algorithm and absent mask generation function parameter. Since these routines are used to verify certificate signature algorithms this can be used to crash any certificate verification operation and exploited in a DoS attack. Any application which performs certificate verification is vulnerable including OpenSSL clients and servers which enable client authentication. This issue was reported to OpenSSL by Loïc Jonas Etienne (Qnective AG). ([CVE-2015-3194]) *Stephen Henson* * X509_ATTRIBUTE memory leak When presented with a malformed X509_ATTRIBUTE structure OpenSSL will leak memory. This structure is used by the PKCS#7 and CMS routines so any application which reads PKCS#7 or CMS data from untrusted sources is affected. SSL/TLS is not affected. This issue was reported to OpenSSL by Adam Langley (Google/BoringSSL) using libFuzzer. ([CVE-2015-3195]) *Stephen Henson* * Rewrite EVP_DecodeUpdate (base64 decoding) to fix several bugs. This changes the decoding behaviour for some invalid messages, though the change is mostly in the more lenient direction, and legacy behaviour is preserved as much as possible. *Emilia Käsper* * In DSA_generate_parameters_ex, if the provided seed is too short, return an error *Rich Salz and Ismo Puustinen * ### Changes between 1.0.2c and 1.0.2d [9 Jul 2015] * Alternate chains certificate forgery During certificate verification, OpenSSL will attempt to find an alternative certificate chain if the first attempt to build such a chain fails. An error in the implementation of this logic can mean that an attacker could cause certain checks on untrusted certificates to be bypassed, such as the CA flag, enabling them to use a valid leaf certificate to act as a CA and "issue" an invalid certificate. This issue was reported to OpenSSL by Adam Langley/David Benjamin (Google/BoringSSL). *Matt Caswell* ### Changes between 1.0.2b and 1.0.2c [12 Jun 2015] * Fix HMAC ABI incompatibility. The previous version introduced an ABI incompatibility in the handling of HMAC. The previous ABI has now been restored. *Matt Caswell* ### Changes between 1.0.2a and 1.0.2b [11 Jun 2015] * Malformed ECParameters causes infinite loop When processing an ECParameters structure OpenSSL enters an infinite loop if the curve specified is over a specially malformed binary polynomial field. This can be used to perform denial of service against any system which processes public keys, certificate requests or certificates. This includes TLS clients and TLS servers with client authentication enabled. This issue was reported to OpenSSL by Joseph Barr-Pixton. ([CVE-2015-1788]) *Andy Polyakov* * Exploitable out-of-bounds read in X509_cmp_time X509_cmp_time does not properly check the length of the ASN1_TIME string and can read a few bytes out of bounds. In addition, X509_cmp_time accepts an arbitrary number of fractional seconds in the time string. An attacker can use this to craft malformed certificates and CRLs of various sizes and potentially cause a segmentation fault, resulting in a DoS on applications that verify certificates or CRLs. TLS clients that verify CRLs are affected. TLS clients and servers with client authentication enabled may be affected if they use custom verification callbacks. This issue was reported to OpenSSL by Robert Swiecki (Google), and independently by Hanno Böck. ([CVE-2015-1789]) *Emilia Käsper* * PKCS7 crash with missing EnvelopedContent The PKCS#7 parsing code does not handle missing inner EncryptedContent correctly. An attacker can craft malformed ASN.1-encoded PKCS#7 blobs with missing content and trigger a NULL pointer dereference on parsing. Applications that decrypt PKCS#7 data or otherwise parse PKCS#7 structures from untrusted sources are affected. OpenSSL clients and servers are not affected. This issue was reported to OpenSSL by Michal Zalewski (Google). ([CVE-2015-1790]) *Emilia Käsper* * CMS verify infinite loop with unknown hash function When verifying a signedData message the CMS code can enter an infinite loop if presented with an unknown hash function OID. This can be used to perform denial of service against any system which verifies signedData messages using the CMS code. This issue was reported to OpenSSL by Johannes Bauer. ([CVE-2015-1792]) *Stephen Henson* * Race condition handling NewSessionTicket If a NewSessionTicket is received by a multi-threaded client when attempting to reuse a previous ticket then a race condition can occur potentially leading to a double free of the ticket data. ([CVE-2015-1791]) *Matt Caswell* * Only support 256-bit or stronger elliptic curves with the 'ecdh_auto' setting (server) or by default (client). Of supported curves, prefer P-256 (both). *Emilia Kasper* ### Changes between 1.0.2 and 1.0.2a [19 Mar 2015] * ClientHello sigalgs DoS fix If a client connects to an OpenSSL 1.0.2 server and renegotiates with an invalid signature algorithms extension a NULL pointer dereference will occur. This can be exploited in a DoS attack against the server. This issue was was reported to OpenSSL by David Ramos of Stanford University. ([CVE-2015-0291]) *Stephen Henson and Matt Caswell* * Multiblock corrupted pointer fix OpenSSL 1.0.2 introduced the "multiblock" performance improvement. This feature only applies on 64 bit x86 architecture platforms that support AES NI instructions. A defect in the implementation of "multiblock" can cause OpenSSL's internal write buffer to become incorrectly set to NULL when using non-blocking IO. Typically, when the user application is using a socket BIO for writing, this will only result in a failed connection. However if some other BIO is used then it is likely that a segmentation fault will be triggered, thus enabling a potential DoS attack. This issue was reported to OpenSSL by Daniel Danner and Rainer Mueller. ([CVE-2015-0290]) *Matt Caswell* * Segmentation fault in DTLSv1_listen fix The DTLSv1_listen function is intended to be stateless and processes the initial ClientHello from many peers. It is common for user code to loop over the call to DTLSv1_listen until a valid ClientHello is received with an associated cookie. A defect in the implementation of DTLSv1_listen means that state is preserved in the SSL object from one invocation to the next that can lead to a segmentation fault. Errors processing the initial ClientHello can trigger this scenario. An example of such an error could be that a DTLS1.0 only client is attempting to connect to a DTLS1.2 only server. This issue was reported to OpenSSL by Per Allansson. ([CVE-2015-0207]) *Matt Caswell* * Segmentation fault in ASN1_TYPE_cmp fix The function ASN1_TYPE_cmp will crash with an invalid read if an attempt is made to compare ASN.1 boolean types. Since ASN1_TYPE_cmp is used to check certificate signature algorithm consistency this can be used to crash any certificate verification operation and exploited in a DoS attack. Any application which performs certificate verification is vulnerable including OpenSSL clients and servers which enable client authentication. ([CVE-2015-0286]) *Stephen Henson* * Segmentation fault for invalid PSS parameters fix The signature verification routines will crash with a NULL pointer dereference if presented with an ASN.1 signature using the RSA PSS algorithm and invalid parameters. Since these routines are used to verify certificate signature algorithms this can be used to crash any certificate verification operation and exploited in a DoS attack. Any application which performs certificate verification is vulnerable including OpenSSL clients and servers which enable client authentication. This issue was was reported to OpenSSL by Brian Carpenter. ([CVE-2015-0208]) *Stephen Henson* * ASN.1 structure reuse memory corruption fix Reusing a structure in ASN.1 parsing may allow an attacker to cause memory corruption via an invalid write. Such reuse is and has been strongly discouraged and is believed to be rare. Applications that parse structures containing CHOICE or ANY DEFINED BY components may be affected. Certificate parsing (d2i_X509 and related functions) are however not affected. OpenSSL clients and servers are not affected. ([CVE-2015-0287]) *Stephen Henson* * PKCS7 NULL pointer dereferences fix The PKCS#7 parsing code does not handle missing outer ContentInfo correctly. An attacker can craft malformed ASN.1-encoded PKCS#7 blobs with missing content and trigger a NULL pointer dereference on parsing. Applications that verify PKCS#7 signatures, decrypt PKCS#7 data or otherwise parse PKCS#7 structures from untrusted sources are affected. OpenSSL clients and servers are not affected. This issue was reported to OpenSSL by Michal Zalewski (Google). ([CVE-2015-0289]) *Emilia Käsper* * DoS via reachable assert in SSLv2 servers fix A malicious client can trigger an OPENSSL_assert (i.e., an abort) in servers that both support SSLv2 and enable export cipher suites by sending a specially crafted SSLv2 CLIENT-MASTER-KEY message. This issue was discovered by Sean Burford (Google) and Emilia Käsper (OpenSSL development team). ([CVE-2015-0293]) *Emilia Käsper* * Empty CKE with client auth and DHE fix If client auth is used then a server can seg fault in the event of a DHE ciphersuite being selected and a zero length ClientKeyExchange message being sent by the client. This could be exploited in a DoS attack. ([CVE-2015-1787]) *Matt Caswell* * Handshake with unseeded PRNG fix Under certain conditions an OpenSSL 1.0.2 client can complete a handshake with an unseeded PRNG. The conditions are: - The client is on a platform where the PRNG has not been seeded automatically, and the user has not seeded manually - A protocol specific client method version has been used (i.e. not SSL_client_methodv23) - A ciphersuite is used that does not require additional random data from the PRNG beyond the initial ClientHello client random (e.g. PSK-RC4-SHA). If the handshake succeeds then the client random that has been used will have been generated from a PRNG with insufficient entropy and therefore the output may be predictable. For example using the following command with an unseeded openssl will succeed on an unpatched platform: openssl s_client -psk 1a2b3c4d -tls1_2 -cipher PSK-RC4-SHA ([CVE-2015-0285]) *Matt Caswell* * Use After Free following d2i_ECPrivatekey error fix A malformed EC private key file consumed via the d2i_ECPrivateKey function could cause a use after free condition. This, in turn, could cause a double free in several private key parsing functions (such as d2i_PrivateKey or EVP_PKCS82PKEY) and could lead to a DoS attack or memory corruption for applications that receive EC private keys from untrusted sources. This scenario is considered rare. This issue was discovered by the BoringSSL project and fixed in their commit 517073cd4b. ([CVE-2015-0209]) *Matt Caswell* * X509_to_X509_REQ NULL pointer deref fix The function X509_to_X509_REQ will crash with a NULL pointer dereference if the certificate key is invalid. This function is rarely used in practice. This issue was discovered by Brian Carpenter. ([CVE-2015-0288]) *Stephen Henson* * Removed the export ciphers from the DEFAULT ciphers *Kurt Roeckx* ### Changes between 1.0.1l and 1.0.2 [22 Jan 2015] * Facilitate "universal" ARM builds targeting range of ARM ISAs, e.g. ARMv5 through ARMv8, as opposite to "locking" it to single one. So far those who have to target multiple platforms would compromise and argue that binary targeting say ARMv5 would still execute on ARMv8. "Universal" build resolves this compromise by providing near-optimal performance even on newer platforms. *Andy Polyakov* * Accelerated NIST P-256 elliptic curve implementation for x86_64 (other platforms pending). *Shay Gueron & Vlad Krasnov (Intel Corp), Andy Polyakov* * Add support for the SignedCertificateTimestampList certificate and OCSP response extensions from RFC6962. *Rob Stradling* * Fix ec_GFp_simple_points_make_affine (thus, EC_POINTs_mul etc.) for corner cases. (Certain input points at infinity could lead to bogus results, with non-infinity inputs mapped to infinity too.) *Bodo Moeller* * Initial support for PowerISA 2.0.7, first implemented in POWER8. This covers AES, SHA256/512 and GHASH. "Initial" means that most common cases are optimized and there still is room for further improvements. Vector Permutation AES for Altivec is also added. *Andy Polyakov* * Add support for little-endian ppc64 Linux target. *Marcelo Cerri (IBM)* * Initial support for AMRv8 ISA crypto extensions. This covers AES, SHA1, SHA256 and GHASH. "Initial" means that most common cases are optimized and there still is room for further improvements. Both 32- and 64-bit modes are supported. *Andy Polyakov, Ard Biesheuvel (Linaro)* * Improved ARMv7 NEON support. *Andy Polyakov* * Support for SPARC Architecture 2011 crypto extensions, first implemented in SPARC T4. This covers AES, DES, Camellia, SHA1, SHA256/512, MD5, GHASH and modular exponentiation. *Andy Polyakov, David Miller* * Accelerated modular exponentiation for Intel processors, a.k.a. RSAZ. *Shay Gueron & Vlad Krasnov (Intel Corp)* * Support for new and upcoming Intel processors, including AVX2, BMI and SHA ISA extensions. This includes additional "stitched" implementations, AESNI-SHA256 and GCM, and multi-buffer support for TLS encrypt. This work was sponsored by Intel Corp. *Andy Polyakov* * Support for DTLS 1.2. This adds two sets of DTLS methods: DTLS_*_method() supports both DTLS 1.2 and 1.0 and should use whatever version the peer supports and DTLSv1_2_*_method() which supports DTLS 1.2 only. *Steve Henson* * Use algorithm specific chains in SSL_CTX_use_certificate_chain_file(): this fixes a limitation in previous versions of OpenSSL. *Steve Henson* * Extended RSA OAEP support via EVP_PKEY API. Options to specify digest, MGF1 digest and OAEP label. *Steve Henson* * Add EVP support for key wrapping algorithms, to avoid problems with existing code the flag EVP_CIPHER_CTX_WRAP_ALLOW has to be set in the EVP_CIPHER_CTX or an error is returned. Add AES and DES3 wrap algorithms and include tests cases. *Steve Henson* * Add functions to allocate and set the fields of an ECDSA_METHOD structure. *Douglas E. Engert, Steve Henson* * New functions OPENSSL_gmtime_diff and ASN1_TIME_diff to find the difference in days and seconds between two tm or ASN1_TIME structures. *Steve Henson* * Add -rev test option to s_server to just reverse order of characters received by client and send back to server. Also prints an abbreviated summary of the connection parameters. *Steve Henson* * New option -brief for s_client and s_server to print out a brief summary of connection parameters. *Steve Henson* * Add callbacks for arbitrary TLS extensions. *Trevor Perrin and Ben Laurie* * New option -crl_download in several openssl utilities to download CRLs from CRLDP extension in certificates. *Steve Henson* * New options -CRL and -CRLform for s_client and s_server for CRLs. *Steve Henson* * New function X509_CRL_diff to generate a delta CRL from the difference of two full CRLs. Add support to "crl" utility. *Steve Henson* * New functions to set lookup_crls function and to retrieve X509_STORE from X509_STORE_CTX. *Steve Henson* * Print out deprecated issuer and subject unique ID fields in certificates. *Steve Henson* * Extend OCSP I/O functions so they can be used for simple general purpose HTTP as well as OCSP. New wrapper function which can be used to download CRLs using the OCSP API. *Steve Henson* * Delegate command line handling in s_client/s_server to SSL_CONF APIs. *Steve Henson* * `SSL_CONF*` functions. These provide a common framework for application configuration using configuration files or command lines. *Steve Henson* * SSL/TLS tracing code. This parses out SSL/TLS records using the message callback and prints the results. Needs compile time option "enable-ssl-trace". New options to s_client and s_server to enable tracing. *Steve Henson* * New ctrl and macro to retrieve supported points extensions. Print out extension in s_server and s_client. *Steve Henson* * New functions to retrieve certificate signature and signature OID NID. *Steve Henson* * Add functions to retrieve and manipulate the raw cipherlist sent by a client to OpenSSL. *Steve Henson* * New Suite B modes for TLS code. These use and enforce the requirements of RFC6460: restrict ciphersuites, only permit Suite B algorithms and only use Suite B curves. The Suite B modes can be set by using the strings "SUITEB128", "SUITEB192" or "SUITEB128ONLY" for the cipherstring. *Steve Henson* * New chain verification flags for Suite B levels of security. Check algorithms are acceptable when flags are set in X509_verify_cert. *Steve Henson* * Make tls1_check_chain return a set of flags indicating checks passed by a certificate chain. Add additional tests to handle client certificates: checks for matching certificate type and issuer name comparison. *Steve Henson* * If an attempt is made to use a signature algorithm not in the peer preference list abort the handshake. If client has no suitable signature algorithms in response to a certificate request do not use the certificate. *Steve Henson* * If server EC tmp key is not in client preference list abort handshake. *Steve Henson* * Add support for certificate stores in CERT structure. This makes it possible to have different stores per SSL structure or one store in the parent SSL_CTX. Include distinct stores for certificate chain verification and chain building. New ctrl SSL_CTRL_BUILD_CERT_CHAIN to build and store a certificate chain in CERT structure: returning an error if the chain cannot be built: this will allow applications to test if a chain is correctly configured. Note: if the CERT based stores are not set then the parent SSL_CTX store is used to retain compatibility with existing behaviour. *Steve Henson* * New function ssl_set_client_disabled to set a ciphersuite disabled mask based on the current session, check mask when sending client hello and checking the requested ciphersuite. *Steve Henson* * New ctrls to retrieve and set certificate types in a certificate request message. Print out received values in s_client. If certificate types is not set with custom values set sensible values based on supported signature algorithms. *Steve Henson* * Support for distinct client and server supported signature algorithms. *Steve Henson* * Add certificate callback. If set this is called whenever a certificate is required by client or server. An application can decide which certificate chain to present based on arbitrary criteria: for example supported signature algorithms. Add very simple example to s_server. This fixes many of the problems and restrictions of the existing client certificate callback: for example you can now clear an existing certificate and specify the whole chain. *Steve Henson* * Add new "valid_flags" field to CERT_PKEY structure which determines what the certificate can be used for (if anything). Set valid_flags field in new tls1_check_chain function. Simplify ssl_set_cert_masks which used to have similar checks in it. Add new "cert_flags" field to CERT structure and include a "strict mode". This enforces some TLS certificate requirements (such as only permitting certificate signature algorithms contained in the supported algorithms extension) which some implementations ignore: this option should be used with caution as it could cause interoperability issues. *Steve Henson* * Update and tidy signature algorithm extension processing. Work out shared signature algorithms based on preferences and peer algorithms and print them out in s_client and s_server. Abort handshake if no shared signature algorithms. *Steve Henson* * Add new functions to allow customised supported signature algorithms for SSL and SSL_CTX structures. Add options to s_client and s_server to support them. *Steve Henson* * New function SSL_certs_clear() to delete all references to certificates from an SSL structure. Before this once a certificate had been added it couldn't be removed. *Steve Henson* * Integrate hostname, email address and IP address checking with certificate verification. New verify options supporting checking in openssl utility. *Steve Henson* * Fixes and wildcard matching support to hostname and email checking functions. Add manual page. *Florian Weimer (Red Hat Product Security Team)* * New functions to check a hostname email or IP address against a certificate. Add options x509 utility to print results of checks against a certificate. *Steve Henson* * Fix OCSP checking. *Rob Stradling and Ben Laurie* * Initial experimental support for explicitly trusted non-root CAs. OpenSSL still tries to build a complete chain to a root but if an intermediate CA has a trust setting included that is used. The first setting is used: whether to trust (e.g., -addtrust option to the x509 utility) or reject. *Steve Henson* * Add -trusted_first option which attempts to find certificates in the trusted store even if an untrusted chain is also supplied. *Steve Henson* * MIPS assembly pack updates: support for MIPS32r2 and SmartMIPS ASE, platform support for Linux and Android. *Andy Polyakov* * Support for linux-x32, ILP32 environment in x86_64 framework. *Andy Polyakov* * Experimental multi-implementation support for FIPS capable OpenSSL. When in FIPS mode the approved implementations are used as normal, when not in FIPS mode the internal unapproved versions are used instead. This means that the FIPS capable OpenSSL isn't forced to use the (often lower performance) FIPS implementations outside FIPS mode. *Steve Henson* * Transparently support X9.42 DH parameters when calling PEM_read_bio_DHparameters. This means existing applications can handle the new parameter format automatically. *Steve Henson* * Initial experimental support for X9.42 DH parameter format: mainly to support use of 'q' parameter for RFC5114 parameters. *Steve Henson* * Add DH parameters from RFC5114 including test data to dhtest. *Steve Henson* * Support for automatic EC temporary key parameter selection. If enabled the most preferred EC parameters are automatically used instead of hardcoded fixed parameters. Now a server just has to call: SSL_CTX_set_ecdh_auto(ctx, 1) and the server will automatically support ECDH and use the most appropriate parameters. *Steve Henson* * Enhance and tidy EC curve and point format TLS extension code. Use static structures instead of allocation if default values are used. New ctrls to set curves we wish to support and to retrieve shared curves. Print out shared curves in s_server. New options to s_server and s_client to set list of supported curves. *Steve Henson* * New ctrls to retrieve supported signature algorithms and supported curve values as an array of NIDs. Extend openssl utility to print out received values. *Steve Henson* * Add new APIs EC_curve_nist2nid and EC_curve_nid2nist which convert between NIDs and the more common NIST names such as "P-256". Enhance ecparam utility and ECC method to recognise the NIST names for curves. *Steve Henson* * Enhance SSL/TLS certificate chain handling to support different chains for each certificate instead of one chain in the parent SSL_CTX. *Steve Henson* * Support for fixed DH ciphersuite client authentication: where both server and client use DH certificates with common parameters. *Steve Henson* * Support for fixed DH ciphersuites: those requiring DH server certificates. *Steve Henson* * New function i2d_re_X509_tbs for re-encoding the TBS portion of the certificate. Note: Related 1.0.2-beta specific macros X509_get_cert_info, X509_CINF_set_modified, X509_CINF_get_issuer, X509_CINF_get_extensions and X509_CINF_get_signature were reverted post internal team review. OpenSSL 1.0.1 ------------- ### Changes between 1.0.1t and 1.0.1u [22 Sep 2016] * OCSP Status Request extension unbounded memory growth A malicious client can send an excessively large OCSP Status Request extension. If that client continually requests renegotiation, sending a large OCSP Status Request extension each time, then there will be unbounded memory growth on the server. This will eventually lead to a Denial Of Service attack through memory exhaustion. Servers with a default configuration are vulnerable even if they do not support OCSP. Builds using the "no-ocsp" build time option are not affected. This issue was reported to OpenSSL by Shi Lei (Gear Team, Qihoo 360 Inc.) ([CVE-2016-6304]) *Matt Caswell* * In order to mitigate the SWEET32 attack, the DES ciphers were moved from HIGH to MEDIUM. This issue was reported to OpenSSL Karthikeyan Bhargavan and Gaetan Leurent (INRIA) ([CVE-2016-2183]) *Rich Salz* * OOB write in MDC2_Update() An overflow can occur in MDC2_Update() either if called directly or through the EVP_DigestUpdate() function using MDC2. If an attacker is able to supply very large amounts of input data after a previous call to EVP_EncryptUpdate() with a partial block then a length check can overflow resulting in a heap corruption. The amount of data needed is comparable to SIZE_MAX which is impractical on most platforms. This issue was reported to OpenSSL by Shi Lei (Gear Team, Qihoo 360 Inc.) ([CVE-2016-6303]) *Stephen Henson* * Malformed SHA512 ticket DoS If a server uses SHA512 for TLS session ticket HMAC it is vulnerable to a DoS attack where a malformed ticket will result in an OOB read which will ultimately crash. The use of SHA512 in TLS session tickets is comparatively rare as it requires a custom server callback and ticket lookup mechanism. This issue was reported to OpenSSL by Shi Lei (Gear Team, Qihoo 360 Inc.) ([CVE-2016-6302]) *Stephen Henson* * OOB write in BN_bn2dec() The function BN_bn2dec() does not check the return value of BN_div_word(). This can cause an OOB write if an application uses this function with an overly large BIGNUM. This could be a problem if an overly large certificate or CRL is printed out from an untrusted source. TLS is not affected because record limits will reject an oversized certificate before it is parsed. This issue was reported to OpenSSL by Shi Lei (Gear Team, Qihoo 360 Inc.) ([CVE-2016-2182]) *Stephen Henson* * OOB read in TS_OBJ_print_bio() The function TS_OBJ_print_bio() misuses OBJ_obj2txt(): the return value is the total length the OID text representation would use and not the amount of data written. This will result in OOB reads when large OIDs are presented. This issue was reported to OpenSSL by Shi Lei (Gear Team, Qihoo 360 Inc.) ([CVE-2016-2180]) *Stephen Henson* * Pointer arithmetic undefined behaviour Avoid some undefined pointer arithmetic A common idiom in the codebase is to check limits in the following manner: "p + len > limit" Where "p" points to some malloc'd data of SIZE bytes and limit == p + SIZE "len" here could be from some externally supplied data (e.g. from a TLS message). The rules of C pointer arithmetic are such that "p + len" is only well defined where len <= SIZE. Therefore the above idiom is actually undefined behaviour. For example this could cause problems if some malloc implementation provides an address for "p" such that "p + len" actually overflows for values of len that are too big and therefore p + len < limit. This issue was reported to OpenSSL by Guido Vranken ([CVE-2016-2177]) *Matt Caswell* * Constant time flag not preserved in DSA signing Operations in the DSA signing algorithm should run in constant time in order to avoid side channel attacks. A flaw in the OpenSSL DSA implementation means that a non-constant time codepath is followed for certain operations. This has been demonstrated through a cache-timing attack to be sufficient for an attacker to recover the private DSA key. This issue was reported by César Pereida (Aalto University), Billy Brumley (Tampere University of Technology), and Yuval Yarom (The University of Adelaide and NICTA). ([CVE-2016-2178]) *César Pereida* * DTLS buffered message DoS In a DTLS connection where handshake messages are delivered out-of-order those messages that OpenSSL is not yet ready to process will be buffered for later use. Under certain circumstances, a flaw in the logic means that those messages do not get removed from the buffer even though the handshake has been completed. An attacker could force up to approx. 15 messages to remain in the buffer when they are no longer required. These messages will be cleared when the DTLS connection is closed. The default maximum size for a message is 100k. Therefore the attacker could force an additional 1500k to be consumed per connection. By opening many simulataneous connections an attacker could cause a DoS attack through memory exhaustion. This issue was reported to OpenSSL by Quan Luo. ([CVE-2016-2179]) *Matt Caswell* * DTLS replay protection DoS A flaw in the DTLS replay attack protection mechanism means that records that arrive for future epochs update the replay protection "window" before the MAC for the record has been validated. This could be exploited by an attacker by sending a record for the next epoch (which does not have to decrypt or have a valid MAC), with a very large sequence number. This means that all subsequent legitimate packets are dropped causing a denial of service for a specific DTLS connection. This issue was reported to OpenSSL by the OCAP audit team. ([CVE-2016-2181]) *Matt Caswell* * Certificate message OOB reads In OpenSSL 1.0.2 and earlier some missing message length checks can result in OOB reads of up to 2 bytes beyond an allocated buffer. There is a theoretical DoS risk but this has not been observed in practice on common platforms. The messages affected are client certificate, client certificate request and server certificate. As a result the attack can only be performed against a client or a server which enables client authentication. This issue was reported to OpenSSL by Shi Lei (Gear Team, Qihoo 360 Inc.) ([CVE-2016-6306]) *Stephen Henson* ### Changes between 1.0.1s and 1.0.1t [3 May 2016] * Prevent padding oracle in AES-NI CBC MAC check A MITM attacker can use a padding oracle attack to decrypt traffic when the connection uses an AES CBC cipher and the server support AES-NI. This issue was introduced as part of the fix for Lucky 13 padding attack ([CVE-2013-0169]). The padding check was rewritten to be in constant time by making sure that always the same bytes are read and compared against either the MAC or padding bytes. But it no longer checked that there was enough data to have both the MAC and padding bytes. This issue was reported by Juraj Somorovsky using TLS-Attacker. ([CVE-2016-2107]) *Kurt Roeckx* * Fix EVP_EncodeUpdate overflow An overflow can occur in the EVP_EncodeUpdate() function which is used for Base64 encoding of binary data. If an attacker is able to supply very large amounts of input data then a length check can overflow resulting in a heap corruption. Internally to OpenSSL the EVP_EncodeUpdate() function is primarly used by the `PEM_write_bio*` family of functions. These are mainly used within the OpenSSL command line applications, so any application which processes data from an untrusted source and outputs it as a PEM file should be considered vulnerable to this issue. User applications that call these APIs directly with large amounts of untrusted data may also be vulnerable. This issue was reported by Guido Vranken. ([CVE-2016-2105]) *Matt Caswell* * Fix EVP_EncryptUpdate overflow An overflow can occur in the EVP_EncryptUpdate() function. If an attacker is able to supply very large amounts of input data after a previous call to EVP_EncryptUpdate() with a partial block then a length check can overflow resulting in a heap corruption. Following an analysis of all OpenSSL internal usage of the EVP_EncryptUpdate() function all usage is one of two forms. The first form is where the EVP_EncryptUpdate() call is known to be the first called function after an EVP_EncryptInit(), and therefore that specific call must be safe. The second form is where the length passed to EVP_EncryptUpdate() can be seen from the code to be some small value and therefore there is no possibility of an overflow. Since all instances are one of these two forms, it is believed that there can be no overflows in internal code due to this problem. It should be noted that EVP_DecryptUpdate() can call EVP_EncryptUpdate() in certain code paths. Also EVP_CipherUpdate() is a synonym for EVP_EncryptUpdate(). All instances of these calls have also been analysed too and it is believed there are no instances in internal usage where an overflow could occur. This issue was reported by Guido Vranken. ([CVE-2016-2106]) *Matt Caswell* * Prevent ASN.1 BIO excessive memory allocation When ASN.1 data is read from a BIO using functions such as d2i_CMS_bio() a short invalid encoding can casuse allocation of large amounts of memory potentially consuming excessive resources or exhausting memory. Any application parsing untrusted data through d2i BIO functions is affected. The memory based functions such as d2i_X509() are *not* affected. Since the memory based functions are used by the TLS library, TLS applications are not affected. This issue was reported by Brian Carpenter. ([CVE-2016-2109]) *Stephen Henson* * EBCDIC overread ASN1 Strings that are over 1024 bytes can cause an overread in applications using the X509_NAME_oneline() function on EBCDIC systems. This could result in arbitrary stack data being returned in the buffer. This issue was reported by Guido Vranken. ([CVE-2016-2176]) *Matt Caswell* * Modify behavior of ALPN to invoke callback after SNI/servername callback, such that updates to the SSL_CTX affect ALPN. *Todd Short* * Remove LOW from the DEFAULT cipher list. This removes singles DES from the default. *Kurt Roeckx* * Only remove the SSLv2 methods with the no-ssl2-method option. When the methods are enabled and ssl2 is disabled the methods return NULL. *Kurt Roeckx* ### Changes between 1.0.1r and 1.0.1s [1 Mar 2016] * Disable weak ciphers in SSLv3 and up in default builds of OpenSSL. Builds that are not configured with "enable-weak-ssl-ciphers" will not provide any "EXPORT" or "LOW" strength ciphers. *Viktor Dukhovni* * Disable SSLv2 default build, default negotiation and weak ciphers. SSLv2 is by default disabled at build-time. Builds that are not configured with "enable-ssl2" will not support SSLv2. Even if "enable-ssl2" is used, users who want to negotiate SSLv2 via the version-flexible SSLv23_method() will need to explicitly call either of: SSL_CTX_clear_options(ctx, SSL_OP_NO_SSLv2); or SSL_clear_options(ssl, SSL_OP_NO_SSLv2); as appropriate. Even if either of those is used, or the application explicitly uses the version-specific SSLv2_method() or its client and server variants, SSLv2 ciphers vulnerable to exhaustive search key recovery have been removed. Specifically, the SSLv2 40-bit EXPORT ciphers, and SSLv2 56-bit DES are no longer available. ([CVE-2016-0800]) *Viktor Dukhovni* * Fix a double-free in DSA code A double free bug was discovered when OpenSSL parses malformed DSA private keys and could lead to a DoS attack or memory corruption for applications that receive DSA private keys from untrusted sources. This scenario is considered rare. This issue was reported to OpenSSL by Adam Langley(Google/BoringSSL) using libFuzzer. ([CVE-2016-0705]) *Stephen Henson* * Disable SRP fake user seed to address a server memory leak. Add a new method SRP_VBASE_get1_by_user that handles the seed properly. SRP_VBASE_get_by_user had inconsistent memory management behaviour. In order to fix an unavoidable memory leak, SRP_VBASE_get_by_user was changed to ignore the "fake user" SRP seed, even if the seed is configured. Users should use SRP_VBASE_get1_by_user instead. Note that in SRP_VBASE_get1_by_user, caller must free the returned value. Note also that even though configuring the SRP seed attempts to hide invalid usernames by continuing the handshake with fake credentials, this behaviour is not constant time and no strong guarantees are made that the handshake is indistinguishable from that of a valid user. ([CVE-2016-0798]) *Emilia Käsper* * Fix BN_hex2bn/BN_dec2bn NULL pointer deref/heap corruption In the BN_hex2bn function the number of hex digits is calculated using an int value `i`. Later `bn_expand` is called with a value of `i * 4`. For large values of `i` this can result in `bn_expand` not allocating any memory because `i * 4` is negative. This can leave the internal BIGNUM data field as NULL leading to a subsequent NULL ptr deref. For very large values of `i`, the calculation `i * 4` could be a positive value smaller than `i`. In this case memory is allocated to the internal BIGNUM data field, but it is insufficiently sized leading to heap corruption. A similar issue exists in BN_dec2bn. This could have security consequences if BN_hex2bn/BN_dec2bn is ever called by user applications with very large untrusted hex/dec data. This is anticipated to be a rare occurrence. All OpenSSL internal usage of these functions use data that is not expected to be untrusted, e.g. config file data or application command line arguments. If user developed applications generate config file data based on untrusted data then it is possible that this could also lead to security consequences. This is also anticipated to be rare. This issue was reported to OpenSSL by Guido Vranken. ([CVE-2016-0797]) *Matt Caswell* * Fix memory issues in `BIO_*printf` functions The internal `fmtstr` function used in processing a "%s" format string in the `BIO_*printf` functions could overflow while calculating the length of a string and cause an OOB read when printing very long strings. Additionally the internal `doapr_outch` function can attempt to write to an OOB memory location (at an offset from the NULL pointer) in the event of a memory allocation failure. In 1.0.2 and below this could be caused where the size of a buffer to be allocated is greater than INT_MAX. E.g. this could be in processing a very long "%s" format string. Memory leaks can also occur. The first issue may mask the second issue dependent on compiler behaviour. These problems could enable attacks where large amounts of untrusted data is passed to the `BIO_*printf` functions. If applications use these functions in this way then they could be vulnerable. OpenSSL itself uses these functions when printing out human-readable dumps of ASN.1 data. Therefore applications that print this data could be vulnerable if the data is from untrusted sources. OpenSSL command line applications could also be vulnerable where they print out ASN.1 data, or if untrusted data is passed as command line arguments. Libssl is not considered directly vulnerable. Additionally certificates etc received via remote connections via libssl are also unlikely to be able to trigger these issues because of message size limits enforced within libssl. This issue was reported to OpenSSL Guido Vranken. ([CVE-2016-0799]) *Matt Caswell* * Side channel attack on modular exponentiation A side-channel attack was found which makes use of cache-bank conflicts on the Intel Sandy-Bridge microarchitecture which could lead to the recovery of RSA keys. The ability to exploit this issue is limited as it relies on an attacker who has control of code in a thread running on the same hyper-threaded core as the victim thread which is performing decryptions. This issue was reported to OpenSSL by Yuval Yarom, The University of Adelaide and NICTA, Daniel Genkin, Technion and Tel Aviv University, and Nadia Heninger, University of Pennsylvania with more information at . ([CVE-2016-0702]) *Andy Polyakov* * Change the req command to generate a 2048-bit RSA/DSA key by default, if no keysize is specified with default_bits. This fixes an omission in an earlier change that changed all RSA/DSA key generation commands to use 2048 bits by default. *Emilia Käsper* ### Changes between 1.0.1q and 1.0.1r [28 Jan 2016] * Protection for DH small subgroup attacks As a precautionary measure the SSL_OP_SINGLE_DH_USE option has been switched on by default and cannot be disabled. This could have some performance impact. *Matt Caswell* * SSLv2 doesn't block disabled ciphers A malicious client can negotiate SSLv2 ciphers that have been disabled on the server and complete SSLv2 handshakes even if all SSLv2 ciphers have been disabled, provided that the SSLv2 protocol was not also disabled via SSL_OP_NO_SSLv2. This issue was reported to OpenSSL on 26th December 2015 by Nimrod Aviram and Sebastian Schinzel. ([CVE-2015-3197]) *Viktor Dukhovni* * Reject DH handshakes with parameters shorter than 1024 bits. *Kurt Roeckx* ### Changes between 1.0.1p and 1.0.1q [3 Dec 2015] * Certificate verify crash with missing PSS parameter The signature verification routines will crash with a NULL pointer dereference if presented with an ASN.1 signature using the RSA PSS algorithm and absent mask generation function parameter. Since these routines are used to verify certificate signature algorithms this can be used to crash any certificate verification operation and exploited in a DoS attack. Any application which performs certificate verification is vulnerable including OpenSSL clients and servers which enable client authentication. This issue was reported to OpenSSL by Loïc Jonas Etienne (Qnective AG). ([CVE-2015-3194]) *Stephen Henson* * X509_ATTRIBUTE memory leak When presented with a malformed X509_ATTRIBUTE structure OpenSSL will leak memory. This structure is used by the PKCS#7 and CMS routines so any application which reads PKCS#7 or CMS data from untrusted sources is affected. SSL/TLS is not affected. This issue was reported to OpenSSL by Adam Langley (Google/BoringSSL) using libFuzzer. ([CVE-2015-3195]) *Stephen Henson* * Rewrite EVP_DecodeUpdate (base64 decoding) to fix several bugs. This changes the decoding behaviour for some invalid messages, though the change is mostly in the more lenient direction, and legacy behaviour is preserved as much as possible. *Emilia Käsper* * In DSA_generate_parameters_ex, if the provided seed is too short, use a random seed, as already documented. *Rich Salz and Ismo Puustinen * ### Changes between 1.0.1o and 1.0.1p [9 Jul 2015] * Alternate chains certificate forgery During certificate verfification, OpenSSL will attempt to find an alternative certificate chain if the first attempt to build such a chain fails. An error in the implementation of this logic can mean that an attacker could cause certain checks on untrusted certificates to be bypassed, such as the CA flag, enabling them to use a valid leaf certificate to act as a CA and "issue" an invalid certificate. This issue was reported to OpenSSL by Adam Langley/David Benjamin (Google/BoringSSL). ([CVE-2015-1793]) *Matt Caswell* * Race condition handling PSK identify hint If PSK identity hints are received by a multi-threaded client then the values are wrongly updated in the parent SSL_CTX structure. This can result in a race condition potentially leading to a double free of the identify hint data. ([CVE-2015-3196]) *Stephen Henson* ### Changes between 1.0.1n and 1.0.1o [12 Jun 2015] * Fix HMAC ABI incompatibility. The previous version introduced an ABI incompatibility in the handling of HMAC. The previous ABI has now been restored. ### Changes between 1.0.1m and 1.0.1n [11 Jun 2015] * Malformed ECParameters causes infinite loop When processing an ECParameters structure OpenSSL enters an infinite loop if the curve specified is over a specially malformed binary polynomial field. This can be used to perform denial of service against any system which processes public keys, certificate requests or certificates. This includes TLS clients and TLS servers with client authentication enabled. This issue was reported to OpenSSL by Joseph Barr-Pixton. ([CVE-2015-1788]) *Andy Polyakov* * Exploitable out-of-bounds read in X509_cmp_time X509_cmp_time does not properly check the length of the ASN1_TIME string and can read a few bytes out of bounds. In addition, X509_cmp_time accepts an arbitrary number of fractional seconds in the time string. An attacker can use this to craft malformed certificates and CRLs of various sizes and potentially cause a segmentation fault, resulting in a DoS on applications that verify certificates or CRLs. TLS clients that verify CRLs are affected. TLS clients and servers with client authentication enabled may be affected if they use custom verification callbacks. This issue was reported to OpenSSL by Robert Swiecki (Google), and independently by Hanno Böck. ([CVE-2015-1789]) *Emilia Käsper* * PKCS7 crash with missing EnvelopedContent The PKCS#7 parsing code does not handle missing inner EncryptedContent correctly. An attacker can craft malformed ASN.1-encoded PKCS#7 blobs with missing content and trigger a NULL pointer dereference on parsing. Applications that decrypt PKCS#7 data or otherwise parse PKCS#7 structures from untrusted sources are affected. OpenSSL clients and servers are not affected. This issue was reported to OpenSSL by Michal Zalewski (Google). ([CVE-2015-1790]) *Emilia Käsper* * CMS verify infinite loop with unknown hash function When verifying a signedData message the CMS code can enter an infinite loop if presented with an unknown hash function OID. This can be used to perform denial of service against any system which verifies signedData messages using the CMS code. This issue was reported to OpenSSL by Johannes Bauer. ([CVE-2015-1792]) *Stephen Henson* * Race condition handling NewSessionTicket If a NewSessionTicket is received by a multi-threaded client when attempting to reuse a previous ticket then a race condition can occur potentially leading to a double free of the ticket data. ([CVE-2015-1791]) *Matt Caswell* * Reject DH handshakes with parameters shorter than 768 bits. *Kurt Roeckx and Emilia Kasper* * dhparam: generate 2048-bit parameters by default. *Kurt Roeckx and Emilia Kasper* ### Changes between 1.0.1l and 1.0.1m [19 Mar 2015] * Segmentation fault in ASN1_TYPE_cmp fix The function ASN1_TYPE_cmp will crash with an invalid read if an attempt is made to compare ASN.1 boolean types. Since ASN1_TYPE_cmp is used to check certificate signature algorithm consistency this can be used to crash any certificate verification operation and exploited in a DoS attack. Any application which performs certificate verification is vulnerable including OpenSSL clients and servers which enable client authentication. ([CVE-2015-0286]) *Stephen Henson* * ASN.1 structure reuse memory corruption fix Reusing a structure in ASN.1 parsing may allow an attacker to cause memory corruption via an invalid write. Such reuse is and has been strongly discouraged and is believed to be rare. Applications that parse structures containing CHOICE or ANY DEFINED BY components may be affected. Certificate parsing (d2i_X509 and related functions) are however not affected. OpenSSL clients and servers are not affected. ([CVE-2015-0287]) *Stephen Henson* * PKCS7 NULL pointer dereferences fix The PKCS#7 parsing code does not handle missing outer ContentInfo correctly. An attacker can craft malformed ASN.1-encoded PKCS#7 blobs with missing content and trigger a NULL pointer dereference on parsing. Applications that verify PKCS#7 signatures, decrypt PKCS#7 data or otherwise parse PKCS#7 structures from untrusted sources are affected. OpenSSL clients and servers are not affected. This issue was reported to OpenSSL by Michal Zalewski (Google). ([CVE-2015-0289]) *Emilia Käsper* * DoS via reachable assert in SSLv2 servers fix A malicious client can trigger an OPENSSL_assert (i.e., an abort) in servers that both support SSLv2 and enable export cipher suites by sending a specially crafted SSLv2 CLIENT-MASTER-KEY message. This issue was discovered by Sean Burford (Google) and Emilia Käsper (OpenSSL development team). ([CVE-2015-0293]) *Emilia Käsper* * Use After Free following d2i_ECPrivatekey error fix A malformed EC private key file consumed via the d2i_ECPrivateKey function could cause a use after free condition. This, in turn, could cause a double free in several private key parsing functions (such as d2i_PrivateKey or EVP_PKCS82PKEY) and could lead to a DoS attack or memory corruption for applications that receive EC private keys from untrusted sources. This scenario is considered rare. This issue was discovered by the BoringSSL project and fixed in their commit 517073cd4b. ([CVE-2015-0209]) *Matt Caswell* * X509_to_X509_REQ NULL pointer deref fix The function X509_to_X509_REQ will crash with a NULL pointer dereference if the certificate key is invalid. This function is rarely used in practice. This issue was discovered by Brian Carpenter. ([CVE-2015-0288]) *Stephen Henson* * Removed the export ciphers from the DEFAULT ciphers *Kurt Roeckx* ### Changes between 1.0.1k and 1.0.1l [15 Jan 2015] * Build fixes for the Windows and OpenVMS platforms *Matt Caswell and Richard Levitte* ### Changes between 1.0.1j and 1.0.1k [8 Jan 2015] * Fix DTLS segmentation fault in dtls1_get_record. A carefully crafted DTLS message can cause a segmentation fault in OpenSSL due to a NULL pointer dereference. This could lead to a Denial Of Service attack. Thanks to Markus Stenberg of Cisco Systems, Inc. for reporting this issue. ([CVE-2014-3571]) *Steve Henson* * Fix DTLS memory leak in dtls1_buffer_record. A memory leak can occur in the dtls1_buffer_record function under certain conditions. In particular this could occur if an attacker sent repeated DTLS records with the same sequence number but for the next epoch. The memory leak could be exploited by an attacker in a Denial of Service attack through memory exhaustion. Thanks to Chris Mueller for reporting this issue. ([CVE-2015-0206]) *Matt Caswell* * Fix issue where no-ssl3 configuration sets method to NULL. When openssl is built with the no-ssl3 option and a SSL v3 ClientHello is received the ssl method would be set to NULL which could later result in a NULL pointer dereference. Thanks to Frank Schmirler for reporting this issue. ([CVE-2014-3569]) *Kurt Roeckx* * Abort handshake if server key exchange message is omitted for ephemeral ECDH ciphersuites. Thanks to Karthikeyan Bhargavan of the PROSECCO team at INRIA for reporting this issue. ([CVE-2014-3572]) *Steve Henson* * Remove non-export ephemeral RSA code on client and server. This code violated the TLS standard by allowing the use of temporary RSA keys in non-export ciphersuites and could be used by a server to effectively downgrade the RSA key length used to a value smaller than the server certificate. Thanks for Karthikeyan Bhargavan of the PROSECCO team at INRIA or reporting this issue. ([CVE-2015-0204]) *Steve Henson* * Fixed issue where DH client certificates are accepted without verification. An OpenSSL server will accept a DH certificate for client authentication without the certificate verify message. This effectively allows a client to authenticate without the use of a private key. This only affects servers which trust a client certificate authority which issues certificates containing DH keys: these are extremely rare and hardly ever encountered. Thanks for Karthikeyan Bhargavan of the PROSECCO team at INRIA or reporting this issue. ([CVE-2015-0205]) *Steve Henson* * Ensure that the session ID context of an SSL is updated when its SSL_CTX is updated via SSL_set_SSL_CTX. The session ID context is typically set from the parent SSL_CTX, and can vary with the CTX. *Adam Langley* * Fix various certificate fingerprint issues. By using non-DER or invalid encodings outside the signed portion of a certificate the fingerprint can be changed without breaking the signature. Although no details of the signed portion of the certificate can be changed this can cause problems with some applications: e.g. those using the certificate fingerprint for blacklists. 1. Reject signatures with non zero unused bits. If the BIT STRING containing the signature has non zero unused bits reject the signature. All current signature algorithms require zero unused bits. 2. Check certificate algorithm consistency. Check the AlgorithmIdentifier inside TBS matches the one in the certificate signature. NB: this will result in signature failure errors for some broken certificates. Thanks to Konrad Kraszewski from Google for reporting this issue. 3. Check DSA/ECDSA signatures use DER. Re-encode DSA/ECDSA signatures and compare with the original received signature. Return an error if there is a mismatch. This will reject various cases including garbage after signature (thanks to Antti Karjalainen and Tuomo Untinen from the Codenomicon CROSS program for discovering this case) and use of BER or invalid ASN.1 INTEGERs (negative or with leading zeroes). Further analysis was conducted and fixes were developed by Stephen Henson of the OpenSSL core team. ([CVE-2014-8275]) *Steve Henson* * Correct Bignum squaring. Bignum squaring (BN_sqr) may produce incorrect results on some platforms, including x86_64. This bug occurs at random with a very low probability, and is not known to be exploitable in any way, though its exact impact is difficult to determine. Thanks to Pieter Wuille (Blockstream) who reported this issue and also suggested an initial fix. Further analysis was conducted by the OpenSSL development team and Adam Langley of Google. The final fix was developed by Andy Polyakov of the OpenSSL core team. ([CVE-2014-3570]) *Andy Polyakov* * Do not resume sessions on the server if the negotiated protocol version does not match the session's version. Resuming with a different version, while not strictly forbidden by the RFC, is of questionable sanity and breaks all known clients. *David Benjamin, Emilia Käsper* * Tighten handling of the ChangeCipherSpec (CCS) message: reject early CCS messages during renegotiation. (Note that because renegotiation is encrypted, this early CCS was not exploitable.) *Emilia Käsper* * Tighten client-side session ticket handling during renegotiation: ensure that the client only accepts a session ticket if the server sends the extension anew in the ServerHello. Previously, a TLS client would reuse the old extension state and thus accept a session ticket if one was announced in the initial ServerHello. Similarly, ensure that the client requires a session ticket if one was advertised in the ServerHello. Previously, a TLS client would ignore a missing NewSessionTicket message. *Emilia Käsper* ### Changes between 1.0.1i and 1.0.1j [15 Oct 2014] * SRTP Memory Leak. A flaw in the DTLS SRTP extension parsing code allows an attacker, who sends a carefully crafted handshake message, to cause OpenSSL to fail to free up to 64k of memory causing a memory leak. This could be exploited in a Denial Of Service attack. This issue affects OpenSSL 1.0.1 server implementations for both SSL/TLS and DTLS regardless of whether SRTP is used or configured. Implementations of OpenSSL that have been compiled with OPENSSL_NO_SRTP defined are not affected. The fix was developed by the OpenSSL team. ([CVE-2014-3513]) *OpenSSL team* * Session Ticket Memory Leak. When an OpenSSL SSL/TLS/DTLS server receives a session ticket the integrity of that ticket is first verified. In the event of a session ticket integrity check failing, OpenSSL will fail to free memory causing a memory leak. By sending a large number of invalid session tickets an attacker could exploit this issue in a Denial Of Service attack. ([CVE-2014-3567]) *Steve Henson* * Build option no-ssl3 is incomplete. When OpenSSL is configured with "no-ssl3" as a build option, servers could accept and complete a SSL 3.0 handshake, and clients could be configured to send them. ([CVE-2014-3568]) *Akamai and the OpenSSL team* * Add support for TLS_FALLBACK_SCSV. Client applications doing fallback retries should call SSL_set_mode(s, SSL_MODE_SEND_FALLBACK_SCSV). ([CVE-2014-3566]) *Adam Langley, Bodo Moeller* * Add additional DigestInfo checks. Re-encode DigestInto in DER and check against the original when verifying RSA signature: this will reject any improperly encoded DigestInfo structures. Note: this is a precautionary measure and no attacks are currently known. *Steve Henson* ### Changes between 1.0.1h and 1.0.1i [6 Aug 2014] * Fix SRP buffer overrun vulnerability. Invalid parameters passed to the SRP code can be overrun an internal buffer. Add sanity check that g, A, B < N to SRP code. Thanks to Sean Devlin and Watson Ladd of Cryptography Services, NCC Group for discovering this issue. ([CVE-2014-3512]) *Steve Henson* * A flaw in the OpenSSL SSL/TLS server code causes the server to negotiate TLS 1.0 instead of higher protocol versions when the ClientHello message is badly fragmented. This allows a man-in-the-middle attacker to force a downgrade to TLS 1.0 even if both the server and the client support a higher protocol version, by modifying the client's TLS records. Thanks to David Benjamin and Adam Langley (Google) for discovering and researching this issue. ([CVE-2014-3511]) *David Benjamin* * OpenSSL DTLS clients enabling anonymous (EC)DH ciphersuites are subject to a denial of service attack. A malicious server can crash the client with a null pointer dereference (read) by specifying an anonymous (EC)DH ciphersuite and sending carefully crafted handshake messages. Thanks to Felix Gröbert (Google) for discovering and researching this issue. ([CVE-2014-3510]) *Emilia Käsper* * By sending carefully crafted DTLS packets an attacker could cause openssl to leak memory. This can be exploited through a Denial of Service attack. Thanks to Adam Langley for discovering and researching this issue. ([CVE-2014-3507]) *Adam Langley* * An attacker can force openssl to consume large amounts of memory whilst processing DTLS handshake messages. This can be exploited through a Denial of Service attack. Thanks to Adam Langley for discovering and researching this issue. ([CVE-2014-3506]) *Adam Langley* * An attacker can force an error condition which causes openssl to crash whilst processing DTLS packets due to memory being freed twice. This can be exploited through a Denial of Service attack. Thanks to Adam Langley and Wan-Teh Chang for discovering and researching this issue. ([CVE-2014-3505]) *Adam Langley* * If a multithreaded client connects to a malicious server using a resumed session and the server sends an ec point format extension it could write up to 255 bytes to freed memory. Thanks to Gabor Tyukasz (LogMeIn Inc) for discovering and researching this issue. ([CVE-2014-3509]) *Gabor Tyukasz* * A malicious server can crash an OpenSSL client with a null pointer dereference (read) by specifying an SRP ciphersuite even though it was not properly negotiated with the client. This can be exploited through a Denial of Service attack. Thanks to Joonas Kuorilehto and Riku Hietamäki (Codenomicon) for discovering and researching this issue. ([CVE-2014-5139]) *Steve Henson* * A flaw in OBJ_obj2txt may cause pretty printing functions such as X509_name_oneline, X509_name_print_ex et al. to leak some information from the stack. Applications may be affected if they echo pretty printing output to the attacker. Thanks to Ivan Fratric (Google) for discovering this issue. ([CVE-2014-3508]) *Emilia Käsper, and Steve Henson* * Fix ec_GFp_simple_points_make_affine (thus, EC_POINTs_mul etc.) for corner cases. (Certain input points at infinity could lead to bogus results, with non-infinity inputs mapped to infinity too.) *Bodo Moeller* ### Changes between 1.0.1g and 1.0.1h [5 Jun 2014] * Fix for SSL/TLS MITM flaw. An attacker using a carefully crafted handshake can force the use of weak keying material in OpenSSL SSL/TLS clients and servers. Thanks to KIKUCHI Masashi (Lepidum Co. Ltd.) for discovering and researching this issue. ([CVE-2014-0224]) *KIKUCHI Masashi, Steve Henson* * Fix DTLS recursion flaw. By sending an invalid DTLS handshake to an OpenSSL DTLS client the code can be made to recurse eventually crashing in a DoS attack. Thanks to Imre Rad (Search-Lab Ltd.) for discovering this issue. ([CVE-2014-0221]) *Imre Rad, Steve Henson* * Fix DTLS invalid fragment vulnerability. A buffer overrun attack can be triggered by sending invalid DTLS fragments to an OpenSSL DTLS client or server. This is potentially exploitable to run arbitrary code on a vulnerable client or server. Thanks to Jüri Aedla for reporting this issue. ([CVE-2014-0195]) *Jüri Aedla, Steve Henson* * Fix bug in TLS code where clients enable anonymous ECDH ciphersuites are subject to a denial of service attack. Thanks to Felix Gröbert and Ivan Fratric at Google for discovering this issue. ([CVE-2014-3470]) *Felix Gröbert, Ivan Fratric, Steve Henson* * Harmonize version and its documentation. -f flag is used to display compilation flags. *mancha * * Fix eckey_priv_encode so it immediately returns an error upon a failure in i2d_ECPrivateKey. *mancha * * Fix some double frees. These are not thought to be exploitable. *mancha * ### Changes between 1.0.1f and 1.0.1g [7 Apr 2014] * A missing bounds check in the handling of the TLS heartbeat extension can be used to reveal up to 64k of memory to a connected client or server. Thanks for Neel Mehta of Google Security for discovering this bug and to Adam Langley and Bodo Moeller for preparing the fix ([CVE-2014-0160]) *Adam Langley, Bodo Moeller* * Fix for the attack described in the paper "Recovering OpenSSL ECDSA Nonces Using the FLUSH+RELOAD Cache Side-channel Attack" by Yuval Yarom and Naomi Benger. Details can be obtained from: Thanks to Yuval Yarom and Naomi Benger for discovering this flaw and to Yuval Yarom for supplying a fix ([CVE-2014-0076]) *Yuval Yarom and Naomi Benger* * TLS pad extension: draft-agl-tls-padding-03 Workaround for the "TLS hang bug" (see FAQ and PR#2771): if the TLS client Hello record length value would otherwise be > 255 and less that 512 pad with a dummy extension containing zeroes so it is at least 512 bytes long. *Adam Langley, Steve Henson* ### Changes between 1.0.1e and 1.0.1f [6 Jan 2014] * Fix for TLS record tampering bug. A carefully crafted invalid handshake could crash OpenSSL with a NULL pointer exception. Thanks to Anton Johansson for reporting this issues. ([CVE-2013-4353]) * Keep original DTLS digest and encryption contexts in retransmission structures so we can use the previous session parameters if they need to be resent. ([CVE-2013-6450]) *Steve Henson* * Add option SSL_OP_SAFARI_ECDHE_ECDSA_BUG (part of SSL_OP_ALL) which avoids preferring ECDHE-ECDSA ciphers when the client appears to be Safari on OS X. Safari on OS X 10.8..10.8.3 advertises support for several ECDHE-ECDSA ciphers, but fails to negotiate them. The bug is fixed in OS X 10.8.4, but Apple have ruled out both hot fixing 10.8..10.8.3 and forcing users to upgrade to 10.8.4 or newer. *Rob Stradling, Adam Langley* ### Changes between 1.0.1d and 1.0.1e [11 Feb 2013] * Correct fix for CVE-2013-0169. The original didn't work on AES-NI supporting platforms or when small records were transferred. *Andy Polyakov, Steve Henson* ### Changes between 1.0.1c and 1.0.1d [5 Feb 2013] * Make the decoding of SSLv3, TLS and DTLS CBC records constant time. This addresses the flaw in CBC record processing discovered by Nadhem Alfardan and Kenny Paterson. Details of this attack can be found at: Thanks go to Nadhem Alfardan and Kenny Paterson of the Information Security Group at Royal Holloway, University of London (www.isg.rhul.ac.uk) for discovering this flaw and Adam Langley and Emilia Käsper for the initial patch. ([CVE-2013-0169]) *Emilia Käsper, Adam Langley, Ben Laurie, Andy Polyakov, Steve Henson* * Fix flaw in AESNI handling of TLS 1.2 and 1.1 records for CBC mode ciphersuites which can be exploited in a denial of service attack. Thanks go to and to Adam Langley for discovering and detecting this bug and to Wolfgang Ettlinger for independently discovering this issue. ([CVE-2012-2686]) *Adam Langley* * Return an error when checking OCSP signatures when key is NULL. This fixes a DoS attack. ([CVE-2013-0166]) *Steve Henson* * Make openssl verify return errors. *Chris Palmer and Ben Laurie* * Call OCSP Stapling callback after ciphersuite has been chosen, so the right response is stapled. Also change SSL_get_certificate() so it returns the certificate actually sent. See . *Rob Stradling * * Fix possible deadlock when decoding public keys. *Steve Henson* * Don't use TLS 1.0 record version number in initial client hello if renegotiating. *Steve Henson* ### Changes between 1.0.1b and 1.0.1c [10 May 2012] * Sanity check record length before skipping explicit IV in TLS 1.2, 1.1 and DTLS to fix DoS attack. Thanks to Codenomicon for discovering this issue using Fuzz-o-Matic fuzzing as a service testing platform. ([CVE-2012-2333]) *Steve Henson* * Initialise tkeylen properly when encrypting CMS messages. Thanks to Solar Designer of Openwall for reporting this issue. *Steve Henson* * In FIPS mode don't try to use composite ciphers as they are not approved. *Steve Henson* ### Changes between 1.0.1a and 1.0.1b [26 Apr 2012] * OpenSSL 1.0.0 sets SSL_OP_ALL to 0x80000FFFL and OpenSSL 1.0.1 and 1.0.1a set SSL_OP_NO_TLSv1_1 to 0x00000400L which would unfortunately mean any application compiled against OpenSSL 1.0.0 headers setting SSL_OP_ALL would also set SSL_OP_NO_TLSv1_1, unintentionally disabling TLS 1.1 also. Fix this by changing the value of SSL_OP_NO_TLSv1_1 to 0x10000000L Any application which was previously compiled against OpenSSL 1.0.1 or 1.0.1a headers and which cares about SSL_OP_NO_TLSv1_1 will need to be recompiled as a result. Letting be results in inability to disable specifically TLS 1.1 and in client context, in unlike event, limit maximum offered version to TLS 1.0 [see below]. *Steve Henson* * In order to ensure interoperability SSL_OP_NO_protocolX does not disable just protocol X, but all protocols above X *if* there are protocols *below* X still enabled. In more practical terms it means that if application wants to disable TLS1.0 in favor of TLS1.1 and above, it's not sufficient to pass `SSL_OP_NO_TLSv1`, one has to pass `SSL_OP_NO_TLSv1|SSL_OP_NO_SSLv3|SSL_OP_NO_SSLv2`. This applies to client side. *Andy Polyakov* ### Changes between 1.0.1 and 1.0.1a [19 Apr 2012] * Check for potentially exploitable overflows in asn1_d2i_read_bio BUF_mem_grow and BUF_mem_grow_clean. Refuse attempts to shrink buffer in CRYPTO_realloc_clean. Thanks to Tavis Ormandy, Google Security Team, for discovering this issue and to Adam Langley for fixing it. ([CVE-2012-2110]) *Adam Langley (Google), Tavis Ormandy, Google Security Team* * Don't allow TLS 1.2 SHA-256 ciphersuites in TLS 1.0, 1.1 connections. *Adam Langley* * Workarounds for some broken servers that "hang" if a client hello record length exceeds 255 bytes. 1. Do not use record version number > TLS 1.0 in initial client hello: some (but not all) hanging servers will now work. 2. If we set OPENSSL_MAX_TLS1_2_CIPHER_LENGTH this will truncate the number of ciphers sent in the client hello. This should be set to an even number, such as 50, for example by passing: -DOPENSSL_MAX_TLS1_2_CIPHER_LENGTH=50 to config or Configure. Most broken servers should now work. 3. If all else fails setting OPENSSL_NO_TLS1_2_CLIENT will disable TLS 1.2 client support entirely. *Steve Henson* * Fix SEGV in Vector Permutation AES module observed in OpenSSH. *Andy Polyakov* ### Changes between 1.0.0h and 1.0.1 [14 Mar 2012] * Add compatibility with old MDC2 signatures which use an ASN1 OCTET STRING form instead of a DigestInfo. *Steve Henson* * The format used for MDC2 RSA signatures is inconsistent between EVP and the RSA_sign/RSA_verify functions. This was made more apparent when OpenSSL used RSA_sign/RSA_verify for some RSA signatures in particular those which went through EVP_PKEY_METHOD in 1.0.0 and later. Detect the correct format in RSA_verify so both forms transparently work. *Steve Henson* * Some servers which support TLS 1.0 can choke if we initially indicate support for TLS 1.2 and later renegotiate using TLS 1.0 in the RSA encrypted premaster secret. As a workaround use the maximum permitted client version in client hello, this should keep such servers happy and still work with previous versions of OpenSSL. *Steve Henson* * Add support for TLS/DTLS heartbeats. *Robin Seggelmann * * Add support for SCTP. *Robin Seggelmann * * Improved PRNG seeding for VOS. *Paul Green * * Extensive assembler packs updates, most notably: - x86[_64]: AES-NI, PCLMULQDQ, RDRAND support; - x86[_64]: SSSE3 support (SHA1, vector-permutation AES); - x86_64: bit-sliced AES implementation; - ARM: NEON support, contemporary platforms optimizations; - s390x: z196 support; - `*`: GHASH and GF(2^m) multiplication implementations; *Andy Polyakov* * Make TLS-SRP code conformant with RFC 5054 API cleanup (removal of unnecessary code) *Peter Sylvester * * Add TLS key material exporter from RFC 5705. *Eric Rescorla* * Add DTLS-SRTP negotiation from RFC 5764. *Eric Rescorla* * Add Next Protocol Negotiation, . Can be disabled with a no-npn flag to config or Configure. Code donated by Google. *Adam Langley and Ben Laurie* * Add optional 64-bit optimized implementations of elliptic curves NIST-P224, NIST-P256, NIST-P521, with constant-time single point multiplication on typical inputs. Compiler support for the nonstandard type `__uint128_t` is required to use this (present in gcc 4.4 and later, for 64-bit builds). Code made available under Apache License version 2.0. Specify "enable-ec_nistp_64_gcc_128" on the Configure (or config) command line to include this in your build of OpenSSL, and run "make depend" (or "make update"). This enables the following EC_METHODs: EC_GFp_nistp224_method() EC_GFp_nistp256_method() EC_GFp_nistp521_method() EC_GROUP_new_by_curve_name() will automatically use these (while EC_GROUP_new_curve_GFp() currently prefers the more flexible implementations). *Emilia Käsper, Adam Langley, Bodo Moeller (Google)* * Use type ossl_ssize_t instead of ssize_t which isn't available on all platforms. Move ssize_t definition from e_os.h to the public header file e_os2.h as it now appears in public header file cms.h *Steve Henson* * New -sigopt option to the ca, req and x509 utilities. Additional signature parameters can be passed using this option and in particular PSS. *Steve Henson* * Add RSA PSS signing function. This will generate and set the appropriate AlgorithmIdentifiers for PSS based on those in the corresponding EVP_MD_CTX structure. No application support yet. *Steve Henson* * Support for companion algorithm specific ASN1 signing routines. New function ASN1_item_sign_ctx() signs a pre-initialised EVP_MD_CTX structure and sets AlgorithmIdentifiers based on the appropriate parameters. *Steve Henson* * Add new algorithm specific ASN1 verification initialisation function to EVP_PKEY_ASN1_METHOD: this is not in EVP_PKEY_METHOD since the ASN1 handling will be the same no matter what EVP_PKEY_METHOD is used. Add a PSS handler to support verification of PSS signatures: checked against a number of sample certificates. *Steve Henson* * Add signature printing for PSS. Add PSS OIDs. *Steve Henson, Martin Kaiser * * Add algorithm specific signature printing. An individual ASN1 method can now print out signatures instead of the standard hex dump. More complex signatures (e.g. PSS) can print out more meaningful information. Include DSA version that prints out the signature parameters r, s. *Steve Henson* * Password based recipient info support for CMS library: implementing RFC3211. *Steve Henson* * Split password based encryption into PBES2 and PBKDF2 functions. This neatly separates the code into cipher and PBE sections and is required for some algorithms that split PBES2 into separate pieces (such as password based CMS). *Steve Henson* * Session-handling fixes: - Fix handling of connections that are resuming with a session ID, but also support Session Tickets. - Fix a bug that suppressed issuing of a new ticket if the client presented a ticket with an expired session. - Try to set the ticket lifetime hint to something reasonable. - Make tickets shorter by excluding irrelevant information. - On the client side, don't ignore renewed tickets. *Adam Langley, Bodo Moeller (Google)* * Fix PSK session representation. *Bodo Moeller* * Add RC4-MD5 and AESNI-SHA1 "stitched" implementations. This work was sponsored by Intel. *Andy Polyakov* * Add GCM support to TLS library. Some custom code is needed to split the IV between the fixed (from PRF) and explicit (from TLS record) portions. This adds all GCM ciphersuites supported by RFC5288 and RFC5289. Generalise some `AES*` cipherstrings to include GCM and add a special AESGCM string for GCM only. *Steve Henson* * Expand range of ctrls for AES GCM. Permit setting invocation field on decrypt and retrieval of invocation field only on encrypt. *Steve Henson* * Add HMAC ECC ciphersuites from RFC5289. Include SHA384 PRF support. As required by RFC5289 these ciphersuites cannot be used if for versions of TLS earlier than 1.2. *Steve Henson* * For FIPS capable OpenSSL interpret a NULL default public key method as unset and return the appropriate default but do *not* set the default. This means we can return the appropriate method in applications that switch between FIPS and non-FIPS modes. *Steve Henson* * Redirect HMAC and CMAC operations to FIPS module in FIPS mode. If an ENGINE is used then we cannot handle that in the FIPS module so we keep original code iff non-FIPS operations are allowed. *Steve Henson* * Add -attime option to openssl utilities. *Peter Eckersley , Ben Laurie and Steve Henson* * Redirect DSA and DH operations to FIPS module in FIPS mode. *Steve Henson* * Redirect ECDSA and ECDH operations to FIPS module in FIPS mode. Also use FIPS EC methods unconditionally for now. *Steve Henson* * New build option no-ec2m to disable characteristic 2 code. *Steve Henson* * Backport libcrypto audit of return value checking from 1.1.0-dev; not all cases can be covered as some introduce binary incompatibilities. *Steve Henson* * Redirect RSA operations to FIPS module including keygen, encrypt, decrypt, sign and verify. Block use of non FIPS RSA methods. *Steve Henson* * Add similar low-level API blocking to ciphers. *Steve Henson* * low-level digest APIs are not approved in FIPS mode: any attempt to use these will cause a fatal error. Applications that *really* want to use them can use the `private_*` version instead. *Steve Henson* * Redirect cipher operations to FIPS module for FIPS builds. *Steve Henson* * Redirect digest operations to FIPS module for FIPS builds. *Steve Henson* * Update build system to add "fips" flag which will link in fipscanister.o for static and shared library builds embedding a signature if needed. *Steve Henson* * Output TLS supported curves in preference order instead of numerical order. This is currently hardcoded for the highest order curves first. This should be configurable so applications can judge speed vs strength. *Steve Henson* * Add TLS v1.2 server support for client authentication. *Steve Henson* * Add support for FIPS mode in ssl library: disable SSLv3, non-FIPS ciphers and enable MD5. *Steve Henson* * Functions FIPS_mode_set() and FIPS_mode() which call the underlying FIPS modules versions. *Steve Henson* * Add TLS v1.2 client side support for client authentication. Keep cache of handshake records longer as we don't know the hash algorithm to use until after the certificate request message is received. *Steve Henson* * Initial TLS v1.2 client support. Add a default signature algorithms extension including all the algorithms we support. Parse new signature format in client key exchange. Relax some ECC signing restrictions for TLS v1.2 as indicated in RFC5246. *Steve Henson* * Add server support for TLS v1.2 signature algorithms extension. Switch to new signature format when needed using client digest preference. All server ciphersuites should now work correctly in TLS v1.2. No client support yet and no support for client certificates. *Steve Henson* * Initial TLS v1.2 support. Add new SHA256 digest to ssl code, switch to SHA256 for PRF when using TLS v1.2 and later. Add new SHA256 based ciphersuites. At present only RSA key exchange ciphersuites work with TLS v1.2. Add new option for TLS v1.2 replacing the old and obsolete SSL_OP_PKCS1_CHECK flags with SSL_OP_NO_TLSv1_2. New TLSv1.2 methods and version checking. *Steve Henson* * New option OPENSSL_NO_SSL_INTERN. If an application can be compiled with this defined it will not be affected by any changes to ssl internal structures. Add several utility functions to allow openssl application to work with OPENSSL_NO_SSL_INTERN defined. *Steve Henson* * A long standing patch to add support for SRP from EdelWeb (Peter Sylvester and Christophe Renou) was integrated. *Christophe Renou , Peter Sylvester , Tom Wu , and Ben Laurie* * Add functions to copy EVP_PKEY_METHOD and retrieve flags and id. *Steve Henson* * Permit abbreviated handshakes when renegotiating using the function SSL_renegotiate_abbreviated(). *Robin Seggelmann * * Add call to ENGINE_register_all_complete() to ENGINE_load_builtin_engines(), so some implementations get used automatically instead of needing explicit application support. *Steve Henson* * Add support for TLS key exporter as described in RFC5705. *Robin Seggelmann , Steve Henson* * Initial TLSv1.1 support. Since TLSv1.1 is very similar to TLS v1.0 only a few changes are required: Add SSL_OP_NO_TLSv1_1 flag. Add TLSv1_1 methods. Update version checking logic to handle version 1.1. Add explicit IV handling (ported from DTLS code). Add command line options to s_client/s_server. *Steve Henson* OpenSSL 1.0.0 ------------- ### Changes between 1.0.0s and 1.0.0t [3 Dec 2015] * X509_ATTRIBUTE memory leak When presented with a malformed X509_ATTRIBUTE structure OpenSSL will leak memory. This structure is used by the PKCS#7 and CMS routines so any application which reads PKCS#7 or CMS data from untrusted sources is affected. SSL/TLS is not affected. This issue was reported to OpenSSL by Adam Langley (Google/BoringSSL) using libFuzzer. ([CVE-2015-3195]) *Stephen Henson* * Race condition handling PSK identify hint If PSK identity hints are received by a multi-threaded client then the values are wrongly updated in the parent SSL_CTX structure. This can result in a race condition potentially leading to a double free of the identify hint data. ([CVE-2015-3196]) *Stephen Henson* ### Changes between 1.0.0r and 1.0.0s [11 Jun 2015] * Malformed ECParameters causes infinite loop When processing an ECParameters structure OpenSSL enters an infinite loop if the curve specified is over a specially malformed binary polynomial field. This can be used to perform denial of service against any system which processes public keys, certificate requests or certificates. This includes TLS clients and TLS servers with client authentication enabled. This issue was reported to OpenSSL by Joseph Barr-Pixton. ([CVE-2015-1788]) *Andy Polyakov* * Exploitable out-of-bounds read in X509_cmp_time X509_cmp_time does not properly check the length of the ASN1_TIME string and can read a few bytes out of bounds. In addition, X509_cmp_time accepts an arbitrary number of fractional seconds in the time string. An attacker can use this to craft malformed certificates and CRLs of various sizes and potentially cause a segmentation fault, resulting in a DoS on applications that verify certificates or CRLs. TLS clients that verify CRLs are affected. TLS clients and servers with client authentication enabled may be affected if they use custom verification callbacks. This issue was reported to OpenSSL by Robert Swiecki (Google), and independently by Hanno Böck. ([CVE-2015-1789]) *Emilia Käsper* * PKCS7 crash with missing EnvelopedContent The PKCS#7 parsing code does not handle missing inner EncryptedContent correctly. An attacker can craft malformed ASN.1-encoded PKCS#7 blobs with missing content and trigger a NULL pointer dereference on parsing. Applications that decrypt PKCS#7 data or otherwise parse PKCS#7 structures from untrusted sources are affected. OpenSSL clients and servers are not affected. This issue was reported to OpenSSL by Michal Zalewski (Google). ([CVE-2015-1790]) *Emilia Käsper* * CMS verify infinite loop with unknown hash function When verifying a signedData message the CMS code can enter an infinite loop if presented with an unknown hash function OID. This can be used to perform denial of service against any system which verifies signedData messages using the CMS code. This issue was reported to OpenSSL by Johannes Bauer. ([CVE-2015-1792]) *Stephen Henson* * Race condition handling NewSessionTicket If a NewSessionTicket is received by a multi-threaded client when attempting to reuse a previous ticket then a race condition can occur potentially leading to a double free of the ticket data. ([CVE-2015-1791]) *Matt Caswell* ### Changes between 1.0.0q and 1.0.0r [19 Mar 2015] * Segmentation fault in ASN1_TYPE_cmp fix The function ASN1_TYPE_cmp will crash with an invalid read if an attempt is made to compare ASN.1 boolean types. Since ASN1_TYPE_cmp is used to check certificate signature algorithm consistency this can be used to crash any certificate verification operation and exploited in a DoS attack. Any application which performs certificate verification is vulnerable including OpenSSL clients and servers which enable client authentication. ([CVE-2015-0286]) *Stephen Henson* * ASN.1 structure reuse memory corruption fix Reusing a structure in ASN.1 parsing may allow an attacker to cause memory corruption via an invalid write. Such reuse is and has been strongly discouraged and is believed to be rare. Applications that parse structures containing CHOICE or ANY DEFINED BY components may be affected. Certificate parsing (d2i_X509 and related functions) are however not affected. OpenSSL clients and servers are not affected. ([CVE-2015-0287]) *Stephen Henson* * PKCS7 NULL pointer dereferences fix The PKCS#7 parsing code does not handle missing outer ContentInfo correctly. An attacker can craft malformed ASN.1-encoded PKCS#7 blobs with missing content and trigger a NULL pointer dereference on parsing. Applications that verify PKCS#7 signatures, decrypt PKCS#7 data or otherwise parse PKCS#7 structures from untrusted sources are affected. OpenSSL clients and servers are not affected. This issue was reported to OpenSSL by Michal Zalewski (Google). ([CVE-2015-0289]) *Emilia Käsper* * DoS via reachable assert in SSLv2 servers fix A malicious client can trigger an OPENSSL_assert (i.e., an abort) in servers that both support SSLv2 and enable export cipher suites by sending a specially crafted SSLv2 CLIENT-MASTER-KEY message. This issue was discovered by Sean Burford (Google) and Emilia Käsper (OpenSSL development team). ([CVE-2015-0293]) *Emilia Käsper* * Use After Free following d2i_ECPrivatekey error fix A malformed EC private key file consumed via the d2i_ECPrivateKey function could cause a use after free condition. This, in turn, could cause a double free in several private key parsing functions (such as d2i_PrivateKey or EVP_PKCS82PKEY) and could lead to a DoS attack or memory corruption for applications that receive EC private keys from untrusted sources. This scenario is considered rare. This issue was discovered by the BoringSSL project and fixed in their commit 517073cd4b. ([CVE-2015-0209]) *Matt Caswell* * X509_to_X509_REQ NULL pointer deref fix The function X509_to_X509_REQ will crash with a NULL pointer dereference if the certificate key is invalid. This function is rarely used in practice. This issue was discovered by Brian Carpenter. ([CVE-2015-0288]) *Stephen Henson* * Removed the export ciphers from the DEFAULT ciphers *Kurt Roeckx* ### Changes between 1.0.0p and 1.0.0q [15 Jan 2015] * Build fixes for the Windows and OpenVMS platforms *Matt Caswell and Richard Levitte* ### Changes between 1.0.0o and 1.0.0p [8 Jan 2015] * Fix DTLS segmentation fault in dtls1_get_record. A carefully crafted DTLS message can cause a segmentation fault in OpenSSL due to a NULL pointer dereference. This could lead to a Denial Of Service attack. Thanks to Markus Stenberg of Cisco Systems, Inc. for reporting this issue. ([CVE-2014-3571]) *Steve Henson* * Fix DTLS memory leak in dtls1_buffer_record. A memory leak can occur in the dtls1_buffer_record function under certain conditions. In particular this could occur if an attacker sent repeated DTLS records with the same sequence number but for the next epoch. The memory leak could be exploited by an attacker in a Denial of Service attack through memory exhaustion. Thanks to Chris Mueller for reporting this issue. ([CVE-2015-0206]) *Matt Caswell* * Fix issue where no-ssl3 configuration sets method to NULL. When openssl is built with the no-ssl3 option and a SSL v3 ClientHello is received the ssl method would be set to NULL which could later result in a NULL pointer dereference. Thanks to Frank Schmirler for reporting this issue. ([CVE-2014-3569]) *Kurt Roeckx* * Abort handshake if server key exchange message is omitted for ephemeral ECDH ciphersuites. Thanks to Karthikeyan Bhargavan of the PROSECCO team at INRIA for reporting this issue. ([CVE-2014-3572]) *Steve Henson* * Remove non-export ephemeral RSA code on client and server. This code violated the TLS standard by allowing the use of temporary RSA keys in non-export ciphersuites and could be used by a server to effectively downgrade the RSA key length used to a value smaller than the server certificate. Thanks for Karthikeyan Bhargavan of the PROSECCO team at INRIA or reporting this issue. ([CVE-2015-0204]) *Steve Henson* * Fixed issue where DH client certificates are accepted without verification. An OpenSSL server will accept a DH certificate for client authentication without the certificate verify message. This effectively allows a client to authenticate without the use of a private key. This only affects servers which trust a client certificate authority which issues certificates containing DH keys: these are extremely rare and hardly ever encountered. Thanks for Karthikeyan Bhargavan of the PROSECCO team at INRIA or reporting this issue. ([CVE-2015-0205]) *Steve Henson* * Correct Bignum squaring. Bignum squaring (BN_sqr) may produce incorrect results on some platforms, including x86_64. This bug occurs at random with a very low probability, and is not known to be exploitable in any way, though its exact impact is difficult to determine. Thanks to Pieter Wuille (Blockstream) who reported this issue and also suggested an initial fix. Further analysis was conducted by the OpenSSL development team and Adam Langley of Google. The final fix was developed by Andy Polyakov of the OpenSSL core team. ([CVE-2014-3570]) *Andy Polyakov* * Fix various certificate fingerprint issues. By using non-DER or invalid encodings outside the signed portion of a certificate the fingerprint can be changed without breaking the signature. Although no details of the signed portion of the certificate can be changed this can cause problems with some applications: e.g. those using the certificate fingerprint for blacklists. 1. Reject signatures with non zero unused bits. If the BIT STRING containing the signature has non zero unused bits reject the signature. All current signature algorithms require zero unused bits. 2. Check certificate algorithm consistency. Check the AlgorithmIdentifier inside TBS matches the one in the certificate signature. NB: this will result in signature failure errors for some broken certificates. Thanks to Konrad Kraszewski from Google for reporting this issue. 3. Check DSA/ECDSA signatures use DER. Reencode DSA/ECDSA signatures and compare with the original received signature. Return an error if there is a mismatch. This will reject various cases including garbage after signature (thanks to Antti Karjalainen and Tuomo Untinen from the Codenomicon CROSS program for discovering this case) and use of BER or invalid ASN.1 INTEGERs (negative or with leading zeroes). Further analysis was conducted and fixes were developed by Stephen Henson of the OpenSSL core team. ([CVE-2014-8275]) *Steve Henson* ### Changes between 1.0.0n and 1.0.0o [15 Oct 2014] * Session Ticket Memory Leak. When an OpenSSL SSL/TLS/DTLS server receives a session ticket the integrity of that ticket is first verified. In the event of a session ticket integrity check failing, OpenSSL will fail to free memory causing a memory leak. By sending a large number of invalid session tickets an attacker could exploit this issue in a Denial Of Service attack. ([CVE-2014-3567]) *Steve Henson* * Build option no-ssl3 is incomplete. When OpenSSL is configured with "no-ssl3" as a build option, servers could accept and complete a SSL 3.0 handshake, and clients could be configured to send them. ([CVE-2014-3568]) *Akamai and the OpenSSL team* * Add support for TLS_FALLBACK_SCSV. Client applications doing fallback retries should call SSL_set_mode(s, SSL_MODE_SEND_FALLBACK_SCSV). ([CVE-2014-3566]) *Adam Langley, Bodo Moeller* * Add additional DigestInfo checks. Reencode DigestInto in DER and check against the original when verifying RSA signature: this will reject any improperly encoded DigestInfo structures. Note: this is a precautionary measure and no attacks are currently known. *Steve Henson* ### Changes between 1.0.0m and 1.0.0n [6 Aug 2014] * OpenSSL DTLS clients enabling anonymous (EC)DH ciphersuites are subject to a denial of service attack. A malicious server can crash the client with a null pointer dereference (read) by specifying an anonymous (EC)DH ciphersuite and sending carefully crafted handshake messages. Thanks to Felix Gröbert (Google) for discovering and researching this issue. ([CVE-2014-3510]) *Emilia Käsper* * By sending carefully crafted DTLS packets an attacker could cause openssl to leak memory. This can be exploited through a Denial of Service attack. Thanks to Adam Langley for discovering and researching this issue. ([CVE-2014-3507]) *Adam Langley* * An attacker can force openssl to consume large amounts of memory whilst processing DTLS handshake messages. This can be exploited through a Denial of Service attack. Thanks to Adam Langley for discovering and researching this issue. ([CVE-2014-3506]) *Adam Langley* * An attacker can force an error condition which causes openssl to crash whilst processing DTLS packets due to memory being freed twice. This can be exploited through a Denial of Service attack. Thanks to Adam Langley and Wan-Teh Chang for discovering and researching this issue. ([CVE-2014-3505]) *Adam Langley* * If a multithreaded client connects to a malicious server using a resumed session and the server sends an ec point format extension it could write up to 255 bytes to freed memory. Thanks to Gabor Tyukasz (LogMeIn Inc) for discovering and researching this issue. ([CVE-2014-3509]) *Gabor Tyukasz* * A flaw in OBJ_obj2txt may cause pretty printing functions such as X509_name_oneline, X509_name_print_ex et al. to leak some information from the stack. Applications may be affected if they echo pretty printing output to the attacker. Thanks to Ivan Fratric (Google) for discovering this issue. ([CVE-2014-3508]) *Emilia Käsper, and Steve Henson* * Fix ec_GFp_simple_points_make_affine (thus, EC_POINTs_mul etc.) for corner cases. (Certain input points at infinity could lead to bogus results, with non-infinity inputs mapped to infinity too.) *Bodo Moeller* ### Changes between 1.0.0l and 1.0.0m [5 Jun 2014] * Fix for SSL/TLS MITM flaw. An attacker using a carefully crafted handshake can force the use of weak keying material in OpenSSL SSL/TLS clients and servers. Thanks to KIKUCHI Masashi (Lepidum Co. Ltd.) for discovering and researching this issue. ([CVE-2014-0224]) *KIKUCHI Masashi, Steve Henson* * Fix DTLS recursion flaw. By sending an invalid DTLS handshake to an OpenSSL DTLS client the code can be made to recurse eventually crashing in a DoS attack. Thanks to Imre Rad (Search-Lab Ltd.) for discovering this issue. ([CVE-2014-0221]) *Imre Rad, Steve Henson* * Fix DTLS invalid fragment vulnerability. A buffer overrun attack can be triggered by sending invalid DTLS fragments to an OpenSSL DTLS client or server. This is potentially exploitable to run arbitrary code on a vulnerable client or server. Thanks to Jüri Aedla for reporting this issue. ([CVE-2014-0195]) *Jüri Aedla, Steve Henson* * Fix bug in TLS code where clients enable anonymous ECDH ciphersuites are subject to a denial of service attack. Thanks to Felix Gröbert and Ivan Fratric at Google for discovering this issue. ([CVE-2014-3470]) *Felix Gröbert, Ivan Fratric, Steve Henson* * Harmonize version and its documentation. -f flag is used to display compilation flags. *mancha * * Fix eckey_priv_encode so it immediately returns an error upon a failure in i2d_ECPrivateKey. *mancha * * Fix some double frees. These are not thought to be exploitable. *mancha * * Fix for the attack described in the paper "Recovering OpenSSL ECDSA Nonces Using the FLUSH+RELOAD Cache Side-channel Attack" by Yuval Yarom and Naomi Benger. Details can be obtained from: Thanks to Yuval Yarom and Naomi Benger for discovering this flaw and to Yuval Yarom for supplying a fix ([CVE-2014-0076]) *Yuval Yarom and Naomi Benger* ### Changes between 1.0.0k and 1.0.0l [6 Jan 2014] * Keep original DTLS digest and encryption contexts in retransmission structures so we can use the previous session parameters if they need to be resent. ([CVE-2013-6450]) *Steve Henson* * Add option SSL_OP_SAFARI_ECDHE_ECDSA_BUG (part of SSL_OP_ALL) which avoids preferring ECDHE-ECDSA ciphers when the client appears to be Safari on OS X. Safari on OS X 10.8..10.8.3 advertises support for several ECDHE-ECDSA ciphers, but fails to negotiate them. The bug is fixed in OS X 10.8.4, but Apple have ruled out both hot fixing 10.8..10.8.3 and forcing users to upgrade to 10.8.4 or newer. *Rob Stradling, Adam Langley* ### Changes between 1.0.0j and 1.0.0k [5 Feb 2013] * Make the decoding of SSLv3, TLS and DTLS CBC records constant time. This addresses the flaw in CBC record processing discovered by Nadhem Alfardan and Kenny Paterson. Details of this attack can be found at: Thanks go to Nadhem Alfardan and Kenny Paterson of the Information Security Group at Royal Holloway, University of London (www.isg.rhul.ac.uk) for discovering this flaw and Adam Langley and Emilia Käsper for the initial patch. ([CVE-2013-0169]) *Emilia Käsper, Adam Langley, Ben Laurie, Andy Polyakov, Steve Henson* * Return an error when checking OCSP signatures when key is NULL. This fixes a DoS attack. ([CVE-2013-0166]) *Steve Henson* * Call OCSP Stapling callback after ciphersuite has been chosen, so the right response is stapled. Also change SSL_get_certificate() so it returns the certificate actually sent. See . (This is a backport) *Rob Stradling * * Fix possible deadlock when decoding public keys. *Steve Henson* ### Changes between 1.0.0i and 1.0.0j [10 May 2012] [NB: OpenSSL 1.0.0i and later 1.0.0 patch levels were released after OpenSSL 1.0.1.] * Sanity check record length before skipping explicit IV in DTLS to fix DoS attack. Thanks to Codenomicon for discovering this issue using Fuzz-o-Matic fuzzing as a service testing platform. ([CVE-2012-2333]) *Steve Henson* * Initialise tkeylen properly when encrypting CMS messages. Thanks to Solar Designer of Openwall for reporting this issue. *Steve Henson* ### Changes between 1.0.0h and 1.0.0i [19 Apr 2012] * Check for potentially exploitable overflows in asn1_d2i_read_bio BUF_mem_grow and BUF_mem_grow_clean. Refuse attempts to shrink buffer in CRYPTO_realloc_clean. Thanks to Tavis Ormandy, Google Security Team, for discovering this issue and to Adam Langley for fixing it. ([CVE-2012-2110]) *Adam Langley (Google), Tavis Ormandy, Google Security Team* ### Changes between 1.0.0g and 1.0.0h [12 Mar 2012] * Fix MMA (Bleichenbacher's attack on PKCS #1 v1.5 RSA padding) weakness in CMS and PKCS7 code. When RSA decryption fails use a random key for content decryption and always return the same error. Note: this attack needs on average 2^20 messages so it only affects automated senders. The old behaviour can be re-enabled in the CMS code by setting the CMS_DEBUG_DECRYPT flag: this is useful for debugging and testing where an MMA defence is not necessary. Thanks to Ivan Nestlerode for discovering this issue. ([CVE-2012-0884]) *Steve Henson* * Fix CVE-2011-4619: make sure we really are receiving a client hello before rejecting multiple SGC restarts. Thanks to Ivan Nestlerode for discovering this bug. *Steve Henson* ### Changes between 1.0.0f and 1.0.0g [18 Jan 2012] * Fix for DTLS DoS issue introduced by fix for CVE-2011-4109. Thanks to Antonio Martin, Enterprise Secure Access Research and Development, Cisco Systems, Inc. for discovering this bug and preparing a fix. ([CVE-2012-0050]) *Antonio Martin* ### Changes between 1.0.0e and 1.0.0f [4 Jan 2012] * Nadhem Alfardan and Kenny Paterson have discovered an extension of the Vaudenay padding oracle attack on CBC mode encryption which enables an efficient plaintext recovery attack against the OpenSSL implementation of DTLS. Their attack exploits timing differences arising during decryption processing. A research paper describing this attack can be found at: Thanks go to Nadhem Alfardan and Kenny Paterson of the Information Security Group at Royal Holloway, University of London (www.isg.rhul.ac.uk) for discovering this flaw and to Robin Seggelmann and Michael Tuexen for preparing the fix. ([CVE-2011-4108]) *Robin Seggelmann, Michael Tuexen* * Clear bytes used for block padding of SSL 3.0 records. ([CVE-2011-4576]) *Adam Langley (Google)* * Only allow one SGC handshake restart for SSL/TLS. Thanks to George Kadianakis for discovering this issue and Adam Langley for preparing the fix. ([CVE-2011-4619]) *Adam Langley (Google)* * Check parameters are not NULL in GOST ENGINE. ([CVE-2012-0027]) *Andrey Kulikov * * Prevent malformed RFC3779 data triggering an assertion failure. Thanks to Andrew Chi, BBN Technologies, for discovering the flaw and Rob Austein for fixing it. ([CVE-2011-4577]) *Rob Austein * * Improved PRNG seeding for VOS. *Paul Green * * Fix ssl_ciph.c set-up race. *Adam Langley (Google)* * Fix spurious failures in ecdsatest.c. *Emilia Käsper (Google)* * Fix the BIO_f_buffer() implementation (which was mixing different interpretations of the `..._len` fields). *Adam Langley (Google)* * Fix handling of BN_BLINDING: now BN_BLINDING_invert_ex (rather than BN_BLINDING_invert_ex) calls BN_BLINDING_update, ensuring that concurrent threads won't reuse the same blinding coefficients. This also avoids the need to obtain the CRYPTO_LOCK_RSA_BLINDING lock to call BN_BLINDING_invert_ex, and avoids one use of BN_BLINDING_update for each BN_BLINDING structure (previously, the last update always remained unused). *Emilia Käsper (Google)* * In ssl3_clear, preserve s3->init_extra along with s3->rbuf. *Bob Buckholz (Google)* ### Changes between 1.0.0d and 1.0.0e [6 Sep 2011] * Fix bug where CRLs with nextUpdate in the past are sometimes accepted by initialising X509_STORE_CTX properly. ([CVE-2011-3207]) *Kaspar Brand * * Fix SSL memory handling for (EC)DH ciphersuites, in particular for multi-threaded use of ECDH. ([CVE-2011-3210]) *Adam Langley (Google)* * Fix x509_name_ex_d2i memory leak on bad inputs. *Bodo Moeller* * Remove hard coded ecdsaWithSHA1 signature tests in ssl code and check signature public key algorithm by using OID xref utilities instead. Before this you could only use some ECC ciphersuites with SHA1 only. *Steve Henson* * Add protection against ECDSA timing attacks as mentioned in the paper by Billy Bob Brumley and Nicola Tuveri, see: *Billy Bob Brumley and Nicola Tuveri* ### Changes between 1.0.0c and 1.0.0d [8 Feb 2011] * Fix parsing of OCSP stapling ClientHello extension. CVE-2011-0014 *Neel Mehta, Adam Langley, Bodo Moeller (Google)* * Fix bug in string printing code: if *any* escaping is enabled we must escape the escape character (backslash) or the resulting string is ambiguous. *Steve Henson* ### Changes between 1.0.0b and 1.0.0c [2 Dec 2010] * Disable code workaround for ancient and obsolete Netscape browsers and servers: an attacker can use it in a ciphersuite downgrade attack. Thanks to Martin Rex for discovering this bug. CVE-2010-4180 *Steve Henson* * Fixed J-PAKE implementation error, originally discovered by Sebastien Martini, further info and confirmation from Stefan Arentz and Feng Hao. Note that this fix is a security fix. CVE-2010-4252 *Ben Laurie* ### Changes between 1.0.0a and 1.0.0b [16 Nov 2010] * Fix extension code to avoid race conditions which can result in a buffer overrun vulnerability: resumed sessions must not be modified as they can be shared by multiple threads. CVE-2010-3864 *Steve Henson* * Fix WIN32 build system to correctly link an ENGINE directory into a DLL. *Steve Henson* ### Changes between 1.0.0 and 1.0.0a [01 Jun 2010] * Check return value of int_rsa_verify in pkey_rsa_verifyrecover ([CVE-2010-1633]) *Steve Henson, Peter-Michael Hager * ### Changes between 0.9.8n and 1.0.0 [29 Mar 2010] * Add "missing" function EVP_CIPHER_CTX_copy(). This copies a cipher context. The operation can be customised via the ctrl mechanism in case ENGINEs want to include additional functionality. *Steve Henson* * Tolerate yet another broken PKCS#8 key format: private key value negative. *Steve Henson* * Add new -subject_hash_old and -issuer_hash_old options to x509 utility to output hashes compatible with older versions of OpenSSL. *Willy Weisz * * Fix compression algorithm handling: if resuming a session use the compression algorithm of the resumed session instead of determining it from client hello again. Don't allow server to change algorithm. *Steve Henson* * Add load_crls() function to commands tidying load_certs() too. Add option to verify utility to allow additional CRLs to be included. *Steve Henson* * Update OCSP request code to permit adding custom headers to the request: some responders need this. *Steve Henson* * The function EVP_PKEY_sign() returns <=0 on error: check return code correctly. *Julia Lawall * * Update verify callback code in `apps/s_cb.c` and `apps/verify.c`, it needlessly dereferenced structures, used obsolete functions and didn't handle all updated verify codes correctly. *Steve Henson* * Disable MD2 in the default configuration. *Steve Henson* * In BIO_pop() and BIO_push() use the ctrl argument (which was NULL) to indicate the initial BIO being pushed or popped. This makes it possible to determine whether the BIO is the one explicitly called or as a result of the ctrl being passed down the chain. Fix BIO_pop() and SSL BIOs so it handles reference counts correctly and doesn't zero out the I/O bio when it is not being explicitly popped. WARNING: applications which included workarounds for the old buggy behaviour will need to be modified or they could free up already freed BIOs. *Steve Henson* * Extend the uni2asc/asc2uni => OPENSSL_uni2asc/OPENSSL_asc2uni renaming to all platforms (within the 0.9.8 branch, this was done conditionally on Netware platforms to avoid a name clash). *Guenter * * Add ECDHE and PSK support to DTLS. *Michael Tuexen * * Add CHECKED_STACK_OF macro to safestack.h, otherwise safestack can't be used on C++. *Steve Henson* * Add "missing" function EVP_MD_flags() (without this the only way to retrieve a digest flags is by accessing the structure directly. Update `EVP_MD_do_all*()` and `EVP_CIPHER_do_all*()` to include the name a digest or cipher is registered as in the "from" argument. Print out all registered digests in the dgst usage message instead of manually attempting to work them out. *Steve Henson* * If no SSLv2 ciphers are used don't use an SSLv2 compatible client hello: this allows the use of compression and extensions. Change default cipher string to remove SSLv2 ciphersuites. This effectively avoids ancient SSLv2 by default unless an application cipher string requests it. *Steve Henson* * Alter match criteria in PKCS12_parse(). It used to try to use local key ids to find matching certificates and keys but some PKCS#12 files don't follow the (somewhat unwritten) rules and this strategy fails. Now just gather all certificates together and the first private key then look for the first certificate that matches the key. *Steve Henson* * Support use of registered digest and cipher names for dgst and cipher commands instead of having to add each one as a special case. So now you can do: openssl sha256 foo as well as: openssl dgst -sha256 foo and this works for ENGINE based algorithms too. *Steve Henson* * Update Gost ENGINE to support parameter files. *Victor B. Wagner * * Support GeneralizedTime in ca utility. *Oliver Martin , Steve Henson* * Enhance the hash format used for certificate directory links. The new form uses the canonical encoding (meaning equivalent names will work even if they aren't identical) and uses SHA1 instead of MD5. This form is incompatible with the older format and as a result c_rehash should be used to rebuild symbolic links. *Steve Henson* * Make PKCS#8 the default write format for private keys, replacing the traditional format. This form is standardised, more secure and doesn't include an implicit MD5 dependency. *Steve Henson* * Add a $gcc_devteam_warn option to Configure. The idea is that any code committed to OpenSSL should pass this lot as a minimum. *Steve Henson* * Add session ticket override functionality for use by EAP-FAST. *Jouni Malinen * * Modify HMAC functions to return a value. Since these can be implemented in an ENGINE errors can occur. *Steve Henson* * Type-checked OBJ_bsearch_ex. *Ben Laurie* * Type-checked OBJ_bsearch. Also some constification necessitated by type-checking. Still to come: TXT_DB, bsearch(?), OBJ_bsearch_ex, qsort, CRYPTO_EX_DATA, ASN1_VALUE, ASN1_STRING, CONF_VALUE. *Ben Laurie* * New function OPENSSL_gmtime_adj() to add a specific number of days and seconds to a tm structure directly, instead of going through OS specific date routines. This avoids any issues with OS routines such as the year 2038 bug. New `*_adj()` functions for ASN1 time structures and X509_time_adj_ex() to cover the extended range. The existing X509_time_adj() is still usable and will no longer have any date issues. *Steve Henson* * Delta CRL support. New use deltas option which will attempt to locate and search any appropriate delta CRLs available. This work was sponsored by Google. *Steve Henson* * Support for CRLs partitioned by reason code. Reorganise CRL processing code and add additional score elements. Validate alternate CRL paths as part of the CRL checking and indicate a new error "CRL path validation error" in this case. Applications wanting additional details can use the verify callback and check the new "parent" field. If this is not NULL CRL path validation is taking place. Existing applications won't see this because it requires extended CRL support which is off by default. This work was sponsored by Google. *Steve Henson* * Support for freshest CRL extension. This work was sponsored by Google. *Steve Henson* * Initial indirect CRL support. Currently only supported in the CRLs passed directly and not via lookup. Process certificate issuer CRL entry extension and lookup CRL entries by bother issuer name and serial number. Check and process CRL issuer entry in IDP extension. This work was sponsored by Google. *Steve Henson* * Add support for distinct certificate and CRL paths. The CRL issuer certificate is validated separately in this case. Only enabled if an extended CRL support flag is set: this flag will enable additional CRL functionality in future. This work was sponsored by Google. *Steve Henson* * Add support for policy mappings extension. This work was sponsored by Google. *Steve Henson* * Fixes to pathlength constraint, self issued certificate handling, policy processing to align with RFC3280 and PKITS tests. This work was sponsored by Google. *Steve Henson* * Support for name constraints certificate extension. DN, email, DNS and URI types are currently supported. This work was sponsored by Google. *Steve Henson* * To cater for systems that provide a pointer-based thread ID rather than numeric, deprecate the current numeric thread ID mechanism and replace it with a structure and associated callback type. This mechanism allows a numeric "hash" to be extracted from a thread ID in either case, and on platforms where pointers are larger than 'long', mixing is done to help ensure the numeric 'hash' is usable even if it can't be guaranteed unique. The default mechanism is to use "&errno" as a pointer-based thread ID to distinguish between threads. Applications that want to provide their own thread IDs should now use CRYPTO_THREADID_set_callback() to register a callback that will call either CRYPTO_THREADID_set_numeric() or CRYPTO_THREADID_set_pointer(). Note that ERR_remove_state() is now deprecated, because it is tied to the assumption that thread IDs are numeric. ERR_remove_state(0) to free the current thread's error state should be replaced by ERR_remove_thread_state(NULL). (This new approach replaces the functions CRYPTO_set_idptr_callback(), CRYPTO_get_idptr_callback(), and CRYPTO_thread_idptr() that existed in OpenSSL 0.9.9-dev between June 2006 and August 2008. Also, if an application was previously providing a numeric thread callback that was inappropriate for distinguishing threads, then uniqueness might have been obtained with &errno that happened immediately in the intermediate development versions of OpenSSL; this is no longer the case, the numeric thread callback will now override the automatic use of &errno.) *Geoff Thorpe, with help from Bodo Moeller* * Initial support for different CRL issuing certificates. This covers a simple case where the self issued certificates in the chain exist and the real CRL issuer is higher in the existing chain. This work was sponsored by Google. *Steve Henson* * Removed effectively defunct crypto/store from the build. *Ben Laurie* * Revamp of STACK to provide stronger type-checking. Still to come: TXT_DB, bsearch(?), OBJ_bsearch, qsort, CRYPTO_EX_DATA, ASN1_VALUE, ASN1_STRING, CONF_VALUE. *Ben Laurie* * Add a new SSL_MODE_RELEASE_BUFFERS mode flag to release unused buffer RAM on SSL connections. This option can save about 34k per idle SSL. *Nick Mathewson* * Revamp of LHASH to provide stronger type-checking. Still to come: STACK, TXT_DB, bsearch, qsort. *Ben Laurie* * Initial support for Cryptographic Message Syntax (aka CMS) based on RFC3850, RFC3851 and RFC3852. New cms directory and cms utility, support for data, signedData, compressedData, digestedData and encryptedData, envelopedData types included. Scripts to check against RFC4134 examples draft and interop and consistency checks of many content types and variants. *Steve Henson* * Add options to enc utility to support use of zlib compression BIO. *Steve Henson* * Extend mk1mf to support importing of options and assembly language files from Configure script, currently only included in VC-WIN32. The assembly language rules can now optionally generate the source files from the associated perl scripts. *Steve Henson* * Implement remaining functionality needed to support GOST ciphersuites. Interop testing has been performed using CryptoPro implementations. *Victor B. Wagner * * s390x assembler pack. *Andy Polyakov* * ARMv4 assembler pack. ARMv4 refers to v4 and later ISA, not CPU "family." *Andy Polyakov* * Implement Opaque PRF Input TLS extension as specified in draft-rescorla-tls-opaque-prf-input-00.txt. Since this is not an official specification yet and no extension type assignment by IANA exists, this extension (for now) will have to be explicitly enabled when building OpenSSL by providing the extension number to use. For example, specify an option -DTLSEXT_TYPE_opaque_prf_input=0x9527 to the "config" or "Configure" script to enable the extension, assuming extension number 0x9527 (which is a completely arbitrary and unofficial assignment based on the MD5 hash of the Internet Draft). Note that by doing so, you potentially lose interoperability with other TLS implementations since these might be using the same extension number for other purposes. SSL_set_tlsext_opaque_prf_input(ssl, src, len) is used to set the opaque PRF input value to use in the handshake. This will create an internal copy of the length-'len' string at 'src', and will return non-zero for success. To get more control and flexibility, provide a callback function by using SSL_CTX_set_tlsext_opaque_prf_input_callback(ctx, cb) SSL_CTX_set_tlsext_opaque_prf_input_callback_arg(ctx, arg) where int (*cb)(SSL *, void *peerinput, size_t len, void *arg); void *arg; Callback function 'cb' will be called in handshakes, and is expected to use SSL_set_tlsext_opaque_prf_input() as appropriate. Argument 'arg' is for application purposes (the value as given to SSL_CTX_set_tlsext_opaque_prf_input_callback_arg() will directly be provided to the callback function). The callback function has to return non-zero to report success: usually 1 to use opaque PRF input just if possible, or 2 to enforce use of the opaque PRF input. In the latter case, the library will abort the handshake if opaque PRF input is not successfully negotiated. Arguments 'peerinput' and 'len' given to the callback function will always be NULL and 0 in the case of a client. A server will see the client's opaque PRF input through these variables if available (NULL and 0 otherwise). Note that if the server provides an opaque PRF input, the length must be the same as the length of the client's opaque PRF input. Note that the callback function will only be called when creating a new session (session resumption can resume whatever was previously negotiated), and will not be called in SSL 2.0 handshakes; thus, SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2) or SSL_set_options(ssl, SSL_OP_NO_SSLv2) is especially recommended for applications that need to enforce opaque PRF input. *Bodo Moeller* * Update ssl code to support digests other than SHA1+MD5 for handshake MAC. *Victor B. Wagner * * Add RFC4507 support to OpenSSL. This includes the corrections in RFC4507bis. The encrypted ticket format is an encrypted encoded SSL_SESSION structure, that way new session features are automatically supported. If a client application caches session in an SSL_SESSION structure support is transparent because tickets are now stored in the encoded SSL_SESSION. The SSL_CTX structure automatically generates keys for ticket protection in servers so again support should be possible with no application modification. If a client or server wishes to disable RFC4507 support then the option SSL_OP_NO_TICKET can be set. Add a TLS extension debugging callback to allow the contents of any client or server extensions to be examined. This work was sponsored by Google. *Steve Henson* * Final changes to avoid use of pointer pointer casts in OpenSSL. OpenSSL should now compile cleanly on gcc 4.2 *Peter Hartley , Steve Henson* * Update SSL library to use new EVP_PKEY MAC API. Include generic MAC support including streaming MAC support: this is required for GOST ciphersuite support. *Victor B. Wagner , Steve Henson* * Add option -stream to use PKCS#7 streaming in smime utility. New function i2d_PKCS7_bio_stream() and PEM_write_PKCS7_bio_stream() to output in BER and PEM format. *Steve Henson* * Experimental support for use of HMAC via EVP_PKEY interface. This allows HMAC to be handled via the `EVP_DigestSign*()` interface. The EVP_PKEY "key" in this case is the HMAC key, potentially allowing ENGINE support for HMAC keys which are unextractable. New -mac and -macopt options to dgst utility. *Steve Henson* * New option -sigopt to dgst utility. Update dgst to use `EVP_Digest{Sign,Verify}*`. These two changes make it possible to use alternative signing parameters such as X9.31 or PSS in the dgst utility. *Steve Henson* * Change ssl_cipher_apply_rule(), the internal function that does the work each time a ciphersuite string requests enabling ("foo+bar"), moving ("+foo+bar"), disabling ("-foo+bar", or removing ("!foo+bar") a class of ciphersuites: Now it maintains the order of disabled ciphersuites such that those ciphersuites that most recently went from enabled to disabled not only stay in order with respect to each other, but also have higher priority than other disabled ciphersuites the next time ciphersuites are enabled again. This means that you can now say, e.g., "PSK:-PSK:HIGH" to enable the same ciphersuites as with "HIGH" alone, but in a specific order where the PSK ciphersuites come first (since they are the most recently disabled ciphersuites when "HIGH" is parsed). Also, change ssl_create_cipher_list() (using this new functionality) such that between otherwise identical ciphersuites, ephemeral ECDH is preferred over ephemeral DH in the default order. *Bodo Moeller* * Change ssl_create_cipher_list() so that it automatically arranges the ciphersuites in reasonable order before starting to process the rule string. Thus, the definition for "DEFAULT" (SSL_DEFAULT_CIPHER_LIST) now is just "ALL:!aNULL:!eNULL", but remains equivalent to `"AES:ALL:!aNULL:!eNULL:+aECDH:+kRSA:+RC4:@STRENGTH"`. This makes it much easier to arrive at a reasonable default order in applications for which anonymous ciphers are OK (meaning that you can't actually use DEFAULT). *Bodo Moeller; suggested by Victor Duchovni* * Split the SSL/TLS algorithm mask (as used for ciphersuite string processing) into multiple integers instead of setting "SSL_MKEY_MASK" bits, "SSL_AUTH_MASK" bits, "SSL_ENC_MASK", "SSL_MAC_MASK", and "SSL_SSL_MASK" bits all in a single integer. (These masks as well as the individual bit definitions are hidden away into the non-exported interface ssl/ssl_locl.h, so this change to the definition of the SSL_CIPHER structure shouldn't affect applications.) This give us more bits for each of these categories, so there is no longer a need to coagulate AES128 and AES256 into a single algorithm bit, and to coagulate Camellia128 and Camellia256 into a single algorithm bit, which has led to all kinds of kludges. Thus, among other things, the kludge introduced in 0.9.7m and 0.9.8e for masking out AES256 independently of AES128 or masking out Camellia256 independently of AES256 is not needed here in 0.9.9. With the change, we also introduce new ciphersuite aliases that so far were missing: "AES128", "AES256", "CAMELLIA128", and "CAMELLIA256". *Bodo Moeller* * Add support for dsa-with-SHA224 and dsa-with-SHA256. Use the leftmost N bytes of the signature input if the input is larger than the prime q (with N being the size in bytes of q). *Nils Larsch* * Very *very* experimental PKCS#7 streaming encoder support. Nothing uses it yet and it is largely untested. *Steve Henson* * Add support for the ecdsa-with-SHA224/256/384/512 signature types. *Nils Larsch* * Initial incomplete changes to avoid need for function casts in OpenSSL some compilers (gcc 4.2 and later) reject their use. Safestack is reimplemented. Update ASN1 to avoid use of legacy functions. *Steve Henson* * Win32/64 targets are linked with Winsock2. *Andy Polyakov* * Add an X509_CRL_METHOD structure to allow CRL processing to be redirected to external functions. This can be used to increase CRL handling efficiency especially when CRLs are very large by (for example) storing the CRL revoked certificates in a database. *Steve Henson* * Overhaul of by_dir code. Add support for dynamic loading of CRLs so new CRLs added to a directory can be used. New command line option -verify_return_error to s_client and s_server. This causes real errors to be returned by the verify callback instead of carrying on no matter what. This reflects the way a "real world" verify callback would behave. *Steve Henson* * GOST engine, supporting several GOST algorithms and public key formats. Kindly donated by Cryptocom. *Cryptocom* * Partial support for Issuing Distribution Point CRL extension. CRLs partitioned by DP are handled but no indirect CRL or reason partitioning (yet). Complete overhaul of CRL handling: now the most suitable CRL is selected via a scoring technique which handles IDP and AKID in CRLs. *Steve Henson* * New X509_STORE_CTX callbacks lookup_crls() and lookup_certs() which will ultimately be used for all verify operations: this will remove the X509_STORE dependency on certificate verification and allow alternative lookup methods. X509_STORE based implementations of these two callbacks. *Steve Henson* * Allow multiple CRLs to exist in an X509_STORE with matching issuer names. Modify get_crl() to find a valid (unexpired) CRL if possible. *Steve Henson* * New function X509_CRL_match() to check if two CRLs are identical. Normally this would be called X509_CRL_cmp() but that name is already used by a function that just compares CRL issuer names. Cache several CRL extensions in X509_CRL structure and cache CRLDP in X509. *Steve Henson* * Store a "canonical" representation of X509_NAME structure (ASN1 Name) this maps equivalent X509_NAME structures into a consistent structure. Name comparison can then be performed rapidly using memcmp(). *Steve Henson* * Non-blocking OCSP request processing. Add -timeout option to ocsp utility. *Steve Henson* * Allow digests to supply their own micalg string for S/MIME type using the ctrl EVP_MD_CTRL_MICALG. *Steve Henson* * During PKCS7 signing pass the PKCS7 SignerInfo structure to the EVP_PKEY_METHOD before and after signing via the EVP_PKEY_CTRL_PKCS7_SIGN ctrl. It can then customise the structure before and/or after signing if necessary. *Steve Henson* * New function OBJ_add_sigid() to allow application defined signature OIDs to be added to OpenSSLs internal tables. New function OBJ_sigid_free() to free up any added signature OIDs. *Steve Henson* * New functions EVP_CIPHER_do_all(), EVP_CIPHER_do_all_sorted(), EVP_MD_do_all() and EVP_MD_do_all_sorted() to enumerate internal digest and cipher tables. New options added to openssl utility: list-message-digest-algorithms and list-cipher-algorithms. *Steve Henson* * Change the array representation of binary polynomials: the list of degrees of non-zero coefficients is now terminated with -1. Previously it was terminated with 0, which was also part of the value; thus, the array representation was not applicable to polynomials where t^0 has coefficient zero. This change makes the array representation useful in a more general context. *Douglas Stebila* * Various modifications and fixes to SSL/TLS cipher string handling. For ECC, the code now distinguishes between fixed ECDH with RSA certificates on the one hand and with ECDSA certificates on the other hand, since these are separate ciphersuites. The unused code for Fortezza ciphersuites has been removed. For consistency with EDH, ephemeral ECDH is now called "EECDH" (not "ECDHE"). For consistency with the code for DH certificates, use of ECDH certificates is now considered ECDH authentication, not RSA or ECDSA authentication (the latter is merely the CA's signing algorithm and not actively used in the protocol). The temporary ciphersuite alias "ECCdraft" is no longer available, and ECC ciphersuites are no longer excluded from "ALL" and "DEFAULT". The following aliases now exist for RFC 4492 ciphersuites, most of these by analogy with the DH case: kECDHr - ECDH cert, signed with RSA kECDHe - ECDH cert, signed with ECDSA kECDH - ECDH cert (signed with either RSA or ECDSA) kEECDH - ephemeral ECDH ECDH - ECDH cert or ephemeral ECDH aECDH - ECDH cert aECDSA - ECDSA cert ECDSA - ECDSA cert AECDH - anonymous ECDH EECDH - non-anonymous ephemeral ECDH (equivalent to "kEECDH:-AECDH") *Bodo Moeller* * Add additional S/MIME capabilities for AES and GOST ciphers if supported. Use correct micalg parameters depending on digest(s) in signed message. *Steve Henson* * Add engine support for EVP_PKEY_ASN1_METHOD. Add functions to process an ENGINE asn1 method. Support ENGINE lookups in the ASN1 code. *Steve Henson* * Initial engine support for EVP_PKEY_METHOD. New functions to permit an engine to register a method. Add ENGINE lookups for methods and functional reference processing. *Steve Henson* * New functions `EVP_Digest{Sign,Verify)*`. These are enhanced versions of `EVP_{Sign,Verify}*` which allow an application to customise the signature process. *Steve Henson* * New -resign option to smime utility. This adds one or more signers to an existing PKCS#7 signedData structure. Also -md option to use an alternative message digest algorithm for signing. *Steve Henson* * Tidy up PKCS#7 routines and add new functions to make it easier to create PKCS7 structures containing multiple signers. Update smime application to support multiple signers. *Steve Henson* * New -macalg option to pkcs12 utility to allow setting of an alternative digest MAC. *Steve Henson* * Initial support for PKCS#5 v2.0 PRFs other than default SHA1 HMAC. Reorganize PBE internals to lookup from a static table using NIDs, add support for HMAC PBE OID translation. Add a EVP_CIPHER ctrl: EVP_CTRL_PBE_PRF_NID this allows a cipher to specify an alternative PRF which will be automatically used with PBES2. *Steve Henson* * Replace the algorithm specific calls to generate keys in "req" with the new API. *Steve Henson* * Update PKCS#7 enveloped data routines to use new API. This is now supported by any public key method supporting the encrypt operation. A ctrl is added to allow the public key algorithm to examine or modify the PKCS#7 RecipientInfo structure if it needs to: for RSA this is a no op. *Steve Henson* * Add a ctrl to asn1 method to allow a public key algorithm to express a default digest type to use. In most cases this will be SHA1 but some algorithms (such as GOST) need to specify an alternative digest. The return value indicates how strong the preference is 1 means optional and 2 is mandatory (that is it is the only supported type). Modify ASN1_item_sign() to accept a NULL digest argument to indicate it should use the default md. Update openssl utilities to use the default digest type for signing if it is not explicitly indicated. *Steve Henson* * Use OID cross reference table in ASN1_sign() and ASN1_verify(). New EVP_MD flag EVP_MD_FLAG_PKEY_METHOD_SIGNATURE. This uses the relevant signing method from the key type. This effectively removes the link between digests and public key types. *Steve Henson* * Add an OID cross reference table and utility functions. Its purpose is to translate between signature OIDs such as SHA1WithrsaEncryption and SHA1, rsaEncryption. This will allow some of the algorithm specific hackery needed to use the correct OID to be removed. *Steve Henson* * Remove algorithm specific dependencies when setting PKCS7_SIGNER_INFO structures for PKCS7_sign(). They are now set up by the relevant public key ASN1 method. *Steve Henson* * Add provisional EC pkey method with support for ECDSA and ECDH. *Steve Henson* * Add support for key derivation (agreement) in the API, DH method and pkeyutl. *Steve Henson* * Add DSA pkey method and DH pkey methods, extend DH ASN1 method to support public and private key formats. As a side effect these add additional command line functionality not previously available: DSA signatures can be generated and verified using pkeyutl and DH key support and generation in pkey, genpkey. *Steve Henson* * BeOS support. *Oliver Tappe * * New make target "install_html_docs" installs HTML renditions of the manual pages. *Oliver Tappe * * New utility "genpkey" this is analogous to "genrsa" etc except it can generate keys for any algorithm. Extend and update EVP_PKEY_METHOD to support key and parameter generation and add initial key generation functionality for RSA. *Steve Henson* * Add functions for main EVP_PKEY_method operations. The undocumented functions `EVP_PKEY_{encrypt,decrypt}` have been renamed to `EVP_PKEY_{encrypt,decrypt}_old`. *Steve Henson* * Initial definitions for EVP_PKEY_METHOD. This will be a high level public key API, doesn't do much yet. *Steve Henson* * New function EVP_PKEY_asn1_get0_info() to retrieve information about public key algorithms. New option to openssl utility: "list-public-key-algorithms" to print out info. *Steve Henson* * Implement the Supported Elliptic Curves Extension for ECC ciphersuites from draft-ietf-tls-ecc-12.txt. *Douglas Stebila* * Don't free up OIDs in OBJ_cleanup() if they are in use by EVP_MD or EVP_CIPHER structures to avoid later problems in EVP_cleanup(). *Steve Henson* * New utilities pkey and pkeyparam. These are similar to algorithm specific utilities such as rsa, dsa, dsaparam etc except they process any key type. *Steve Henson* * Transfer public key printing routines to EVP_PKEY_ASN1_METHOD. New functions EVP_PKEY_print_public(), EVP_PKEY_print_private(), EVP_PKEY_print_param() to print public key data from an EVP_PKEY structure. *Steve Henson* * Initial support for pluggable public key ASN1. De-spaghettify the public key ASN1 handling. Move public and private key ASN1 handling to a new EVP_PKEY_ASN1_METHOD structure. Relocate algorithm specific handling to a single module within the relevant algorithm directory. Add functions to allow (near) opaque processing of public and private key structures. *Steve Henson* * Implement the Supported Point Formats Extension for ECC ciphersuites from draft-ietf-tls-ecc-12.txt. *Douglas Stebila* * Add initial support for RFC 4279 PSK TLS ciphersuites. Add members for the psk identity [hint] and the psk callback functions to the SSL_SESSION, SSL and SSL_CTX structure. New ciphersuites: PSK-RC4-SHA, PSK-3DES-EDE-CBC-SHA, PSK-AES128-CBC-SHA, PSK-AES256-CBC-SHA New functions: SSL_CTX_use_psk_identity_hint SSL_get_psk_identity_hint SSL_get_psk_identity SSL_use_psk_identity_hint *Mika Kousa and Pasi Eronen of Nokia Corporation* * Add RFC 3161 compliant time stamp request creation, response generation and response verification functionality. *Zoltán Glózik , The OpenTSA Project* * Add initial support for TLS extensions, specifically for the server_name extension so far. The SSL_SESSION, SSL_CTX, and SSL data structures now have new members for a host name. The SSL data structure has an additional member `SSL_CTX *initial_ctx` so that new sessions can be stored in that context to allow for session resumption, even after the SSL has been switched to a new SSL_CTX in reaction to a client's server_name extension. New functions (subject to change): SSL_get_servername() SSL_get_servername_type() SSL_set_SSL_CTX() New CTRL codes and macros (subject to change): SSL_CTRL_SET_TLSEXT_SERVERNAME_CB - SSL_CTX_set_tlsext_servername_callback() SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG - SSL_CTX_set_tlsext_servername_arg() SSL_CTRL_SET_TLSEXT_HOSTNAME - SSL_set_tlsext_host_name() openssl s_client has a new '-servername ...' option. openssl s_server has new options '-servername_host ...', '-cert2 ...', '-key2 ...', '-servername_fatal' (subject to change). This allows testing the HostName extension for a specific single host name ('-cert' and '-key' remain fallbacks for handshakes without HostName negotiation). If the unrecognized_name alert has to be sent, this by default is a warning; it becomes fatal with the '-servername_fatal' option. *Peter Sylvester, Remy Allais, Christophe Renou* * Whirlpool hash implementation is added. *Andy Polyakov* * BIGNUM code on 64-bit SPARCv9 targets is switched from bn(64,64) to bn(64,32). Because of instruction set limitations it doesn't have any negative impact on performance. This was done mostly in order to make it possible to share assembler modules, such as bn_mul_mont implementations, between 32- and 64-bit builds without hassle. *Andy Polyakov* * Move code previously exiled into file crypto/ec/ec2_smpt.c to ec2_smpl.c, and no longer require the OPENSSL_EC_BIN_PT_COMP macro. *Bodo Moeller* * New candidate for BIGNUM assembler implementation, bn_mul_mont, dedicated Montgomery multiplication procedure, is introduced. BN_MONT_CTX is modified to allow bn_mul_mont to reach for higher "64-bit" performance on certain 32-bit targets. *Andy Polyakov* * New option SSL_OP_NO_COMP to disable use of compression selectively in SSL structures. New SSL ctrl to set maximum send fragment size. Save memory by setting the I/O buffer sizes dynamically instead of using the maximum available value. *Steve Henson* * New option -V for 'openssl ciphers'. This prints the ciphersuite code in addition to the text details. *Bodo Moeller* * Very, very preliminary EXPERIMENTAL support for printing of general ASN1 structures. This currently produces rather ugly output and doesn't handle several customised structures at all. *Steve Henson* * Integrated support for PVK file format and some related formats such as MS PUBLICKEYBLOB and PRIVATEKEYBLOB. Command line switches to support these in the 'rsa' and 'dsa' utilities. *Steve Henson* * Support for PKCS#1 RSAPublicKey format on rsa utility command line. *Steve Henson* * Remove the ancient ASN1_METHOD code. This was only ever used in one place for the (very old) "NETSCAPE" format certificates which are now handled using new ASN1 code equivalents. *Steve Henson* * Let the TLSv1_method() etc. functions return a 'const' SSL_METHOD pointer and make the SSL_METHOD parameter in SSL_CTX_new, SSL_CTX_set_ssl_version and SSL_set_ssl_method 'const'. *Nils Larsch* * Modify CRL distribution points extension code to print out previously unsupported fields. Enhance extension setting code to allow setting of all fields. *Steve Henson* * Add print and set support for Issuing Distribution Point CRL extension. *Steve Henson* * Change 'Configure' script to enable Camellia by default. *NTT* OpenSSL 0.9.x ------------- ### Changes between 0.9.8m and 0.9.8n [24 Mar 2010] * When rejecting SSL/TLS records due to an incorrect version number, never update s->server with a new major version number. As of - OpenSSL 0.9.8m if 'short' is a 16-bit type, - OpenSSL 0.9.8f if 'short' is longer than 16 bits, the previous behavior could result in a read attempt at NULL when receiving specific incorrect SSL/TLS records once record payload protection is active. ([CVE-2010-0740]) *Bodo Moeller, Adam Langley * * Fix for CVE-2010-0433 where some kerberos enabled versions of OpenSSL could be crashed if the relevant tables were not present (e.g. chrooted). *Tomas Hoger * ### Changes between 0.9.8l and 0.9.8m [25 Feb 2010] * Always check bn_wexpand() return values for failure. ([CVE-2009-3245]) *Martin Olsson, Neel Mehta* * Fix X509_STORE locking: Every 'objs' access requires a lock (to accommodate for stack sorting, always a write lock!). *Bodo Moeller* * On some versions of WIN32 Heap32Next is very slow. This can cause excessive delays in the RAND_poll(): over a minute. As a workaround include a time check in the inner Heap32Next loop too. *Steve Henson* * The code that handled flushing of data in SSL/TLS originally used the BIO_CTRL_INFO ctrl to see if any data was pending first. This caused the problem outlined in PR#1949. The fix suggested there however can trigger problems with buggy BIO_CTRL_WPENDING (e.g. some versions of Apache). So instead simplify the code to flush unconditionally. This should be fine since flushing with no data to flush is a no op. *Steve Henson* * Handle TLS versions 2.0 and later properly and correctly use the highest version of TLS/SSL supported. Although TLS >= 2.0 is some way off ancient servers have a habit of sticking around for a while... *Steve Henson* * Modify compression code so it frees up structures without using the ex_data callbacks. This works around a problem where some applications call CRYPTO_cleanup_all_ex_data() before application exit (e.g. when restarting) then use compression (e.g. SSL with compression) later. This results in significant per-connection memory leaks and has caused some security issues including CVE-2008-1678 and CVE-2009-4355. *Steve Henson* * Constify crypto/cast (i.e., ): a CAST_KEY doesn't change when encrypting or decrypting. *Bodo Moeller* * Add option SSL_OP_LEGACY_SERVER_CONNECT which will allow clients to connect and renegotiate with servers which do not support RI. Until RI is more widely deployed this option is enabled by default. *Steve Henson* * Add "missing" ssl ctrls to clear options and mode. *Steve Henson* * If client attempts to renegotiate and doesn't support RI respond with a no_renegotiation alert as required by RFC5746. Some renegotiating TLS clients will continue a connection gracefully when they receive the alert. Unfortunately OpenSSL mishandled this alert and would hang waiting for a server hello which it will never receive. Now we treat a received no_renegotiation alert as a fatal error. This is because applications requesting a renegotiation might well expect it to succeed and would have no code in place to handle the server denying it so the only safe thing to do is to terminate the connection. *Steve Henson* * Add ctrl macro SSL_get_secure_renegotiation_support() which returns 1 if peer supports secure renegotiation and 0 otherwise. Print out peer renegotiation support in s_client/s_server. *Steve Henson* * Replace the highly broken and deprecated SPKAC certification method with the updated NID creation version. This should correctly handle UTF8. *Steve Henson* * Implement RFC5746. Re-enable renegotiation but require the extension as needed. Unfortunately, SSL3_FLAGS_ALLOW_UNSAFE_LEGACY_RENEGOTIATION turns out to be a bad idea. It has been replaced by SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION which can be set with SSL_CTX_set_options(). This is really not recommended unless you know what you are doing. *Eric Rescorla , Ben Laurie, Steve Henson* * Fixes to stateless session resumption handling. Use initial_ctx when issuing and attempting to decrypt tickets in case it has changed during servername handling. Use a non-zero length session ID when attempting stateless session resumption: this makes it possible to determine if a resumption has occurred immediately after receiving server hello (several places in OpenSSL subtly assume this) instead of later in the handshake. *Steve Henson* * The functions ENGINE_ctrl(), OPENSSL_isservice(), CMS_get1_RecipientRequest() and RAND_bytes() can return <=0 on error fixes for a few places where the return code is not checked correctly. *Julia Lawall * * Add --strict-warnings option to Configure script to include devteam warnings in other configurations. *Steve Henson* * Add support for --libdir option and LIBDIR variable in makefiles. This makes it possible to install openssl libraries in locations which have names other than "lib", for example "/usr/lib64" which some systems need. *Steve Henson, based on patch from Jeremy Utley* * Don't allow the use of leading 0x80 in OIDs. This is a violation of X690 8.9.12 and can produce some misleading textual output of OIDs. *Steve Henson, reported by Dan Kaminsky* * Delete MD2 from algorithm tables. This follows the recommendation in several standards that it is not used in new applications due to several cryptographic weaknesses. For binary compatibility reasons the MD2 API is still compiled in by default. *Steve Henson* * Add compression id to {d2i,i2d}_SSL_SESSION so it is correctly saved and restored. *Steve Henson* * Rename uni2asc and asc2uni functions to OPENSSL_uni2asc and OPENSSL_asc2uni conditionally on Netware platforms to avoid a name clash. *Guenter * * Fix the server certificate chain building code to use X509_verify_cert(), it used to have an ad-hoc builder which was unable to cope with anything other than a simple chain. *David Woodhouse , Steve Henson* * Don't check self signed certificate signatures in X509_verify_cert() by default (a flag can override this): it just wastes time without adding any security. As a useful side effect self signed root CAs with non-FIPS digests are now usable in FIPS mode. *Steve Henson* * In dtls1_process_out_of_seq_message() the check if the current message is already buffered was missing. For every new message was memory allocated, allowing an attacker to perform an denial of service attack with sending out of seq handshake messages until there is no memory left. Additionally every future message was buffered, even if the sequence number made no sense and would be part of another handshake. So only messages with sequence numbers less than 10 in advance will be buffered. ([CVE-2009-1378]) *Robin Seggelmann, discovered by Daniel Mentz* * Records are buffered if they arrive with a future epoch to be processed after finishing the corresponding handshake. There is currently no limitation to this buffer allowing an attacker to perform a DOS attack with sending records with future epochs until there is no memory left. This patch adds the pqueue_size() function to determine the size of a buffer and limits the record buffer to 100 entries. ([CVE-2009-1377]) *Robin Seggelmann, discovered by Daniel Mentz* * Keep a copy of frag->msg_header.frag_len so it can be used after the parent structure is freed. ([CVE-2009-1379]) *Daniel Mentz* * Handle non-blocking I/O properly in SSL_shutdown() call. *Darryl Miles * * Add `2.5.4.*` OIDs *Ilya O. * ### Changes between 0.9.8k and 0.9.8l [5 Nov 2009] * Disable renegotiation completely - this fixes a severe security problem ([CVE-2009-3555]) at the cost of breaking all renegotiation. Renegotiation can be re-enabled by setting SSL3_FLAGS_ALLOW_UNSAFE_LEGACY_RENEGOTIATION in s3->flags at run-time. This is really not recommended unless you know what you're doing. *Ben Laurie* ### Changes between 0.9.8j and 0.9.8k [25 Mar 2009] * Don't set val to NULL when freeing up structures, it is freed up by underlying code. If `sizeof(void *) > sizeof(long)` this can result in zeroing past the valid field. ([CVE-2009-0789]) *Paolo Ganci * * Fix bug where return value of CMS_SignerInfo_verify_content() was not checked correctly. This would allow some invalid signed attributes to appear to verify correctly. ([CVE-2009-0591]) *Ivan Nestlerode * * Reject UniversalString and BMPString types with invalid lengths. This prevents a crash in ASN1_STRING_print_ex() which assumes the strings have a legal length. ([CVE-2009-0590]) *Steve Henson* * Set S/MIME signing as the default purpose rather than setting it unconditionally. This allows applications to override it at the store level. *Steve Henson* * Permit restricted recursion of ASN1 strings. This is needed in practice to handle some structures. *Steve Henson* * Improve efficiency of mem_gets: don't search whole buffer each time for a '\n' *Jeremy Shapiro * * New -hex option for openssl rand. *Matthieu Herrb* * Print out UTF8String and NumericString when parsing ASN1. *Steve Henson* * Support NumericString type for name components. *Steve Henson* * Allow CC in the environment to override the automatically chosen compiler. Note that nothing is done to ensure flags work with the chosen compiler. *Ben Laurie* ### Changes between 0.9.8i and 0.9.8j [07 Jan 2009] * Properly check EVP_VerifyFinal() and similar return values ([CVE-2008-5077]). *Ben Laurie, Bodo Moeller, Google Security Team* * Enable TLS extensions by default. *Ben Laurie* * Allow the CHIL engine to be loaded, whether the application is multithreaded or not. (This does not release the developer from the obligation to set up the dynamic locking callbacks.) *Sander Temme * * Use correct exit code if there is an error in dgst command. *Steve Henson; problem pointed out by Roland Dirlewanger* * Tweak Configure so that you need to say "experimental-jpake" to enable JPAKE, and need to use -DOPENSSL_EXPERIMENTAL_JPAKE in applications. *Bodo Moeller* * Add experimental JPAKE support, including demo authentication in s_client and s_server. *Ben Laurie* * Set the comparison function in v3_addr_canonize(). *Rob Austein * * Add support for XMPP STARTTLS in s_client. *Philip Paeps * * Change the server-side SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG behavior to ensure that even with this option, only ciphersuites in the server's preference list will be accepted. (Note that the option applies only when resuming a session, so the earlier behavior was just about the algorithm choice for symmetric cryptography.) *Bodo Moeller* ### Changes between 0.9.8h and 0.9.8i [15 Sep 2008] * Fix NULL pointer dereference if a DTLS server received ChangeCipherSpec as first record ([CVE-2009-1386]). *PR #1679* * Fix a state transition in s3_srvr.c and d1_srvr.c (was using SSL3_ST_CW_CLNT_HELLO_B, should be `..._ST_SW_SRVR_...`). *Nagendra Modadugu* * The fix in 0.9.8c that supposedly got rid of unsafe double-checked locking was incomplete for RSA blinding, addressing just one layer of what turns out to have been doubly unsafe triple-checked locking. So now fix this for real by retiring the MONT_HELPER macro in crypto/rsa/rsa_eay.c. *Bodo Moeller; problem pointed out by Marius Schilder* * Various precautionary measures: - Avoid size_t integer overflow in HASH_UPDATE (md32_common.h). - Avoid a buffer overflow in d2i_SSL_SESSION() (ssl_asn1.c). (NB: This would require knowledge of the secret session ticket key to exploit, in which case you'd be SOL either way.) - Change bn_nist.c so that it will properly handle input BIGNUMs outside the expected range. - Enforce the 'num' check in BN_div() (bn_div.c) for non-BN_DEBUG builds. *Neel Mehta, Bodo Moeller* * Allow engines to be "soft loaded" - i.e. optionally don't die if the load fails. Useful for distros. *Ben Laurie and the FreeBSD team* * Add support for Local Machine Keyset attribute in PKCS#12 files. *Steve Henson* * Fix BN_GF2m_mod_arr() top-bit cleanup code. *Huang Ying* * Expand ENGINE to support engine supplied SSL client certificate functions. This work was sponsored by Logica. *Steve Henson* * Add CryptoAPI ENGINE to support use of RSA and DSA keys held in Windows keystores. Support for SSL/TLS client authentication too. Not compiled unless enable-capieng specified to Configure. This work was sponsored by Logica. *Steve Henson* * Fix bug in X509_ATTRIBUTE creation: don't set attribute using ASN1_TYPE_set1 if MBSTRING flag set. This bug would crash certain attribute creation routines such as certificate requests and PKCS#12 files. *Steve Henson* ### Changes between 0.9.8g and 0.9.8h [28 May 2008] * Fix flaw if 'Server Key exchange message' is omitted from a TLS handshake which could lead to a client crash as found using the Codenomicon TLS test suite ([CVE-2008-1672]) *Steve Henson, Mark Cox* * Fix double free in TLS server name extensions which could lead to a remote crash found by Codenomicon TLS test suite ([CVE-2008-0891]) *Joe Orton* * Clear error queue in SSL_CTX_use_certificate_chain_file() Clear the error queue to ensure that error entries left from older function calls do not interfere with the correct operation. *Lutz Jaenicke, Erik de Castro Lopo* * Remove root CA certificates of commercial CAs: The OpenSSL project does not recommend any specific CA and does not have any policy with respect to including or excluding any CA. Therefore it does not make any sense to ship an arbitrary selection of root CA certificates with the OpenSSL software. *Lutz Jaenicke* * RSA OAEP patches to fix two separate invalid memory reads. The first one involves inputs when 'lzero' is greater than 'SHA_DIGEST_LENGTH' (it would read about SHA_DIGEST_LENGTH bytes before the beginning of from). The second one involves inputs where the 'db' section contains nothing but zeroes (there is a one-byte invalid read after the end of 'db'). *Ivan Nestlerode * * Partial backport from 0.9.9-dev: Introduce bn_mul_mont (dedicated Montgomery multiplication procedure) as a candidate for BIGNUM assembler implementation. While 0.9.9-dev uses assembler for various architectures, only x86_64 is available by default here in the 0.9.8 branch, and 32-bit x86 is available through a compile-time setting. To try the 32-bit x86 assembler implementation, use Configure option "enable-montasm" (which exists only for this backport). As "enable-montasm" for 32-bit x86 disclaims code stability anyway, in this constellation we activate additional code backported from 0.9.9-dev for further performance improvements, namely BN_from_montgomery_word. (To enable this otherwise, e.g. x86_64, try `-DMONT_FROM_WORD___NON_DEFAULT_0_9_8_BUILD`.) *Andy Polyakov (backport partially by Bodo Moeller)* * Add TLS session ticket callback. This allows an application to set TLS ticket cipher and HMAC keys rather than relying on hardcoded fixed values. This is useful for key rollover for example where several key sets may exist with different names. *Steve Henson* * Reverse ENGINE-internal logic for caching default ENGINE handles. This was broken until now in 0.9.8 releases, such that the only way a registered ENGINE could be used (assuming it initialises successfully on the host) was to explicitly set it as the default for the relevant algorithms. This is in contradiction with 0.9.7 behaviour and the documentation. With this fix, when an ENGINE is registered into a given algorithm's table of implementations, the 'uptodate' flag is reset so that auto-discovery will be used next time a new context for that algorithm attempts to select an implementation. *Ian Lister (tweaked by Geoff Thorpe)* * Backport of CMS code to OpenSSL 0.9.8. This differs from the 0.9.9 implementation in the following ways: Lack of EVP_PKEY_ASN1_METHOD means algorithm parameters have to be hard coded. Lack of BER streaming support means one pass streaming processing is only supported if data is detached: setting the streaming flag is ignored for embedded content. CMS support is disabled by default and must be explicitly enabled with the enable-cms configuration option. *Steve Henson* * Update the GMP engine glue to do direct copies between BIGNUM and mpz_t when openssl and GMP use the same limb size. Otherwise the existing "conversion via a text string export" trick is still used. *Paul Sheer * * Zlib compression BIO. This is a filter BIO which compressed and uncompresses any data passed through it. *Steve Henson* * Add AES_wrap_key() and AES_unwrap_key() functions to implement RFC3394 compatible AES key wrapping. *Steve Henson* * Add utility functions to handle ASN1 structures. ASN1_STRING_set0(): sets string data without copying. X509_ALGOR_set0() and X509_ALGOR_get0(): set and retrieve X509_ALGOR (AlgorithmIdentifier) data. Attribute function X509at_get0_data_by_OBJ(): retrieves data from an X509_ATTRIBUTE structure optionally checking it occurs only once. ASN1_TYPE_set1(): set and ASN1_TYPE structure copying supplied data. *Steve Henson* * Fix BN flag handling in RSA_eay_mod_exp() and BN_MONT_CTX_set() to get the expected BN_FLG_CONSTTIME behavior. *Bodo Moeller (Google)* * Netware support: - fixed wrong usage of ioctlsocket() when build for LIBC BSD sockets - fixed do_tests.pl to run the test suite with CLIB builds too (CLIB_OPT) - added some more tests to do_tests.pl - fixed RunningProcess usage so that it works with newer LIBC NDKs too - removed usage of BN_LLONG for CLIB builds to avoid runtime dependency - added new Configure targets netware-clib-bsdsock, netware-clib-gcc, netware-clib-bsdsock-gcc, netware-libc-bsdsock-gcc - various changes to netware.pl to enable gcc-cross builds on Win32 platform - changed crypto/bio/b_sock.c to work with macro functions (CLIB BSD) - various changes to fix missing prototype warnings - fixed x86nasm.pl to create correct asm files for NASM COFF output - added AES, WHIRLPOOL and CPUID assembler code to build files - added missing AES assembler make rules to mk1mf.pl - fixed order of includes in `apps/ocsp.c` so that `e_os.h` settings apply *Guenter Knauf * * Implement certificate status request TLS extension defined in RFC3546. A client can set the appropriate parameters and receive the encoded OCSP response via a callback. A server can query the supplied parameters and set the encoded OCSP response in the callback. Add simplified examples to s_client and s_server. *Steve Henson* ### Changes between 0.9.8f and 0.9.8g [19 Oct 2007] * Fix various bugs: + Binary incompatibility of ssl_ctx_st structure + DTLS interoperation with non-compliant servers + Don't call get_session_cb() without proposed session + Fix ia64 assembler code *Andy Polyakov, Steve Henson* ### Changes between 0.9.8e and 0.9.8f [11 Oct 2007] * DTLS Handshake overhaul. There were longstanding issues with OpenSSL DTLS implementation, which were making it impossible for RFC 4347 compliant client to communicate with OpenSSL server. Unfortunately just fixing these incompatibilities would "cut off" pre-0.9.8f clients. To allow for hassle free upgrade post-0.9.8e server keeps tolerating non RFC compliant syntax. The opposite is not true, 0.9.8f client can not communicate with earlier server. This update even addresses CVE-2007-4995. *Andy Polyakov* * Changes to avoid need for function casts in OpenSSL: some compilers (gcc 4.2 and later) reject their use. *Kurt Roeckx , Peter Hartley , Steve Henson* * Add RFC4507 support to OpenSSL. This includes the corrections in RFC4507bis. The encrypted ticket format is an encrypted encoded SSL_SESSION structure, that way new session features are automatically supported. If a client application caches session in an SSL_SESSION structure support is transparent because tickets are now stored in the encoded SSL_SESSION. The SSL_CTX structure automatically generates keys for ticket protection in servers so again support should be possible with no application modification. If a client or server wishes to disable RFC4507 support then the option SSL_OP_NO_TICKET can be set. Add a TLS extension debugging callback to allow the contents of any client or server extensions to be examined. This work was sponsored by Google. *Steve Henson* * Add initial support for TLS extensions, specifically for the server_name extension so far. The SSL_SESSION, SSL_CTX, and SSL data structures now have new members for a host name. The SSL data structure has an additional member `SSL_CTX *initial_ctx` so that new sessions can be stored in that context to allow for session resumption, even after the SSL has been switched to a new SSL_CTX in reaction to a client's server_name extension. New functions (subject to change): SSL_get_servername() SSL_get_servername_type() SSL_set_SSL_CTX() New CTRL codes and macros (subject to change): SSL_CTRL_SET_TLSEXT_SERVERNAME_CB - SSL_CTX_set_tlsext_servername_callback() SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG - SSL_CTX_set_tlsext_servername_arg() SSL_CTRL_SET_TLSEXT_HOSTNAME - SSL_set_tlsext_host_name() openssl s_client has a new '-servername ...' option. openssl s_server has new options '-servername_host ...', '-cert2 ...', '-key2 ...', '-servername_fatal' (subject to change). This allows testing the HostName extension for a specific single host name ('-cert' and '-key' remain fallbacks for handshakes without HostName negotiation). If the unrecognized_name alert has to be sent, this by default is a warning; it becomes fatal with the '-servername_fatal' option. *Peter Sylvester, Remy Allais, Christophe Renou, Steve Henson* * Add AES and SSE2 assembly language support to VC++ build. *Steve Henson* * Mitigate attack on final subtraction in Montgomery reduction. *Andy Polyakov* * Fix crypto/ec/ec_mult.c to work properly with scalars of value 0 (which previously caused an internal error). *Bodo Moeller* * Squeeze another 10% out of IGE mode when in != out. *Ben Laurie* * AES IGE mode speedup. *Dean Gaudet (Google)* * Add the Korean symmetric 128-bit cipher SEED (see ) and add SEED ciphersuites from RFC 4162: TLS_RSA_WITH_SEED_CBC_SHA = "SEED-SHA" TLS_DHE_DSS_WITH_SEED_CBC_SHA = "DHE-DSS-SEED-SHA" TLS_DHE_RSA_WITH_SEED_CBC_SHA = "DHE-RSA-SEED-SHA" TLS_DH_anon_WITH_SEED_CBC_SHA = "ADH-SEED-SHA" To minimize changes between patchlevels in the OpenSSL 0.9.8 series, SEED remains excluded from compilation unless OpenSSL is configured with 'enable-seed'. *KISA, Bodo Moeller* * Mitigate branch prediction attacks, which can be practical if a single processor is shared, allowing a spy process to extract information. For detailed background information, see (O. Aciicmez, S. Gueron, J.-P. Seifert, "New Branch Prediction Vulnerabilities in OpenSSL and Necessary Software Countermeasures"). The core of the change are new versions BN_div_no_branch() and BN_mod_inverse_no_branch() of BN_div() and BN_mod_inverse(), respectively, which are slower, but avoid the security-relevant conditional branches. These are automatically called by BN_div() and BN_mod_inverse() if the flag BN_FLG_CONSTTIME is set for one of the input BIGNUMs. Also, BN_is_bit_set() has been changed to remove a conditional branch. BN_FLG_CONSTTIME is the new name for the previous BN_FLG_EXP_CONSTTIME flag, since it now affects more than just modular exponentiation. (Since OpenSSL 0.9.7h, setting this flag in the exponent causes BN_mod_exp_mont() to use the alternative implementation in BN_mod_exp_mont_consttime().) The old name remains as a deprecated alias. Similarly, RSA_FLAG_NO_EXP_CONSTTIME is replaced by a more general RSA_FLAG_NO_CONSTTIME flag since the RSA implementation now uses constant-time implementations for more than just exponentiation. Here too the old name is kept as a deprecated alias. BN_BLINDING_new() will now use BN_dup() for the modulus so that the BN_BLINDING structure gets an independent copy of the modulus. This means that the previous `BIGNUM *m` argument to BN_BLINDING_new() and to BN_BLINDING_create_param() now essentially becomes `const BIGNUM *m`, although we can't actually change this in the header file before 0.9.9. It allows RSA_setup_blinding() to use BN_with_flags() on the modulus to enable BN_FLG_CONSTTIME. *Matthew D Wood (Intel Corp)* * In the SSL/TLS server implementation, be strict about session ID context matching (which matters if an application uses a single external cache for different purposes). Previously, out-of-context reuse was forbidden only if SSL_VERIFY_PEER was set. This did ensure strict client verification, but meant that, with applications using a single external cache for quite different requirements, clients could circumvent ciphersuite restrictions for a given session ID context by starting a session in a different context. *Bodo Moeller* * Include "!eNULL" in SSL_DEFAULT_CIPHER_LIST to make sure that a ciphersuite string such as "DEFAULT:RSA" cannot enable authentication-only ciphersuites. *Bodo Moeller* * Update the SSL_get_shared_ciphers() fix CVE-2006-3738 which was not complete and could lead to a possible single byte overflow ([CVE-2007-5135]) [Ben Laurie] ### Changes between 0.9.8d and 0.9.8e [23 Feb 2007] * Since AES128 and AES256 (and similarly Camellia128 and Camellia256) share a single mask bit in the logic of ssl/ssl_ciph.c, the code for masking out disabled ciphers needs a kludge to work properly if AES128 is available and AES256 isn't (or if Camellia128 is available and Camellia256 isn't). *Victor Duchovni* * Fix the BIT STRING encoding generated by crypto/ec/ec_asn1.c (within i2d_ECPrivateKey, i2d_ECPKParameters, i2d_ECParameters): When a point or a seed is encoded in a BIT STRING, we need to prevent the removal of trailing zero bits to get the proper DER encoding. (By default, crypto/asn1/a_bitstr.c assumes the case of a NamedBitList, for which trailing 0 bits need to be removed.) *Bodo Moeller* * Have SSL/TLS server implementation tolerate "mismatched" record protocol version while receiving ClientHello even if the ClientHello is fragmented. (The server can't insist on the particular protocol version it has chosen before the ServerHello message has informed the client about his choice.) *Bodo Moeller* * Add RFC 3779 support. *Rob Austein for ARIN, Ben Laurie* * Load error codes if they are not already present instead of using a static variable. This allows them to be cleanly unloaded and reloaded. Improve header file function name parsing. *Steve Henson* * extend SMTP and IMAP protocol emulation in s_client to use EHLO or CAPABILITY handshake as required by RFCs. *Goetz Babin-Ebell* ### Changes between 0.9.8c and 0.9.8d [28 Sep 2006] * Introduce limits to prevent malicious keys being able to cause a denial of service. ([CVE-2006-2940]) *Steve Henson, Bodo Moeller* * Fix ASN.1 parsing of certain invalid structures that can result in a denial of service. ([CVE-2006-2937]) [Steve Henson] * Fix buffer overflow in SSL_get_shared_ciphers() function. ([CVE-2006-3738]) [Tavis Ormandy and Will Drewry, Google Security Team] * Fix SSL client code which could crash if connecting to a malicious SSLv2 server. ([CVE-2006-4343]) *Tavis Ormandy and Will Drewry, Google Security Team* * Since 0.9.8b, ciphersuite strings naming explicit ciphersuites match only those. Before that, "AES256-SHA" would be interpreted as a pattern and match "AES128-SHA" too (since AES128-SHA got the same strength classification in 0.9.7h) as we currently only have a single AES bit in the ciphersuite description bitmap. That change, however, also applied to ciphersuite strings such as "RC4-MD5" that intentionally matched multiple ciphersuites -- namely, SSL 2.0 ciphersuites in addition to the more common ones from SSL 3.0/TLS 1.0. So we change the selection algorithm again: Naming an explicit ciphersuite selects this one ciphersuite, and any other similar ciphersuite (same bitmap) from *other* protocol versions. Thus, "RC4-MD5" again will properly select both the SSL 2.0 ciphersuite and the SSL 3.0/TLS 1.0 ciphersuite. Since SSL 2.0 does not have any ciphersuites for which the 128/256 bit distinction would be relevant, this works for now. The proper fix will be to use different bits for AES128 and AES256, which would have avoided the problems from the beginning; however, bits are scarce, so we can only do this in a new release (not just a patchlevel) when we can change the SSL_CIPHER definition to split the single 'unsigned long mask' bitmap into multiple values to extend the available space. *Bodo Moeller* ### Changes between 0.9.8b and 0.9.8c [05 Sep 2006] * Avoid PKCS #1 v1.5 signature attack discovered by Daniel Bleichenbacher ([CVE-2006-4339]) [Ben Laurie and Google Security Team] * Add AES IGE and biIGE modes. *Ben Laurie* * Change the Unix randomness entropy gathering to use poll() when possible instead of select(), since the latter has some undesirable limitations. *Darryl Miles via Richard Levitte and Bodo Moeller* * Disable "ECCdraft" ciphersuites more thoroughly. Now special treatment in ssl/ssl_ciph.s makes sure that these ciphersuites cannot be implicitly activated as part of, e.g., the "AES" alias. However, please upgrade to OpenSSL 0.9.9[-dev] for non-experimental use of the ECC ciphersuites to get TLS extension support, which is required for curve and point format negotiation to avoid potential handshake problems. *Bodo Moeller* * Disable rogue ciphersuites: - SSLv2 0x08 0x00 0x80 ("RC4-64-MD5") - SSLv3/TLSv1 0x00 0x61 ("EXP1024-RC2-CBC-MD5") - SSLv3/TLSv1 0x00 0x60 ("EXP1024-RC4-MD5") The latter two were purportedly from draft-ietf-tls-56-bit-ciphersuites-0[01].txt, but do not really appear there. Also deactivate the remaining ciphersuites from draft-ietf-tls-56-bit-ciphersuites-01.txt. These are just as unofficial, and the ID has long expired. *Bodo Moeller* * Fix RSA blinding Heisenbug (problems sometimes occurred on dual-core machines) and other potential thread-safety issues. *Bodo Moeller* * Add the symmetric cipher Camellia (128-bit, 192-bit, 256-bit key versions), which is now available for royalty-free use (see ). Also, add Camellia TLS ciphersuites from RFC 4132. To minimize changes between patchlevels in the OpenSSL 0.9.8 series, Camellia remains excluded from compilation unless OpenSSL is configured with 'enable-camellia'. *NTT* * Disable the padding bug check when compression is in use. The padding bug check assumes the first packet is of even length, this is not necessarily true if compression is enabled and can result in false positives causing handshake failure. The actual bug test is ancient code so it is hoped that implementations will either have fixed it by now or any which still have the bug do not support compression. *Steve Henson* ### Changes between 0.9.8a and 0.9.8b [04 May 2006] * When applying a cipher rule check to see if string match is an explicit cipher suite and only match that one cipher suite if it is. *Steve Henson* * Link in manifests for VC++ if needed. *Austin Ziegler * * Update support for ECC-based TLS ciphersuites according to draft-ietf-tls-ecc-12.txt with proposed changes (but without TLS extensions, which are supported starting with the 0.9.9 branch, not in the OpenSSL 0.9.8 branch). *Douglas Stebila* * New functions EVP_CIPHER_CTX_new() and EVP_CIPHER_CTX_free() to support opaque EVP_CIPHER_CTX handling. *Steve Henson* * Fixes and enhancements to zlib compression code. We now only use "zlib1.dll" and use the default `__cdecl` calling convention on Win32 to conform with the standards mentioned here: Static zlib linking now works on Windows and the new --with-zlib-include --with-zlib-lib options to Configure can be used to supply the location of the headers and library. Gracefully handle case where zlib library can't be loaded. *Steve Henson* * Several fixes and enhancements to the OID generation code. The old code sometimes allowed invalid OIDs (1.X for X >= 40 for example), couldn't handle numbers larger than ULONG_MAX, truncated printing and had a non standard OBJ_obj2txt() behaviour. *Steve Henson* * Add support for building of engines under engine/ as shared libraries under VC++ build system. *Steve Henson* * Corrected the numerous bugs in the Win32 path splitter in DSO. Hopefully, we will not see any false combination of paths any more. *Richard Levitte* ### Changes between 0.9.8 and 0.9.8a [11 Oct 2005] * Remove the functionality of SSL_OP_MSIE_SSLV2_RSA_PADDING (part of SSL_OP_ALL). This option used to disable the countermeasure against man-in-the-middle protocol-version rollback in the SSL 2.0 server implementation, which is a bad idea. ([CVE-2005-2969]) *Bodo Moeller; problem pointed out by Yutaka Oiwa (Research Center for Information Security, National Institute of Advanced Industrial Science and Technology [AIST], Japan)* * Add two function to clear and return the verify parameter flags. *Steve Henson* * Keep cipherlists sorted in the source instead of sorting them at runtime, thus removing the need for a lock. *Nils Larsch* * Avoid some small subgroup attacks in Diffie-Hellman. *Nick Mathewson and Ben Laurie* * Add functions for well-known primes. *Nick Mathewson* * Extended Windows CE support. *Satoshi Nakamura and Andy Polyakov* * Initialize SSL_METHOD structures at compile time instead of during runtime, thus removing the need for a lock. *Steve Henson* * Make PKCS7_decrypt() work even if no certificate is supplied by attempting to decrypt each encrypted key in turn. Add support to smime utility. *Steve Henson* ### Changes between 0.9.7h and 0.9.8 [05 Jul 2005] [NB: OpenSSL 0.9.7i and later 0.9.7 patch levels were released after OpenSSL 0.9.8.] * Add libcrypto.pc and libssl.pc for those who feel they need them. *Richard Levitte* * Change CA.sh and CA.pl so they don't bundle the CSR and the private key into the same file any more. *Richard Levitte* * Add initial support for Win64, both IA64 and AMD64/x64 flavors. *Andy Polyakov* * Add -utf8 command line and config file option to 'ca'. *Stefan and Geoff Thorpe* * Add attribute functions to EVP_PKEY structure. Modify PKCS12_create() to recognize a CSP name attribute and use it. Make -CSP option work again in pkcs12 utility. *Steve Henson* * Add new functionality to the bn blinding code: - automatic re-creation of the BN_BLINDING parameters after a fixed number of uses (currently 32) - add new function for parameter creation - introduce flags to control the update behaviour of the BN_BLINDING parameters - hide BN_BLINDING structure Add a second BN_BLINDING slot to the RSA structure to improve performance when a single RSA object is shared among several threads. *Nils Larsch* * Add support for DTLS. *Nagendra Modadugu and Ben Laurie* * Add support for DER encoded private keys (SSL_FILETYPE_ASN1) to SSL_CTX_use_PrivateKey_file() and SSL_use_PrivateKey_file() *Walter Goulet* * Remove buggy and incomplete DH cert support from ssl/ssl_rsa.c and ssl/s3_both.c *Nils Larsch* * Use SHA-1 instead of MD5 as the default digest algorithm for the `apps/openssl` commands. *Nils Larsch* * Compile clean with "-Wall -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Werror". Currently DEBUG_SAFESTACK must also be set. *Ben Laurie* * Change ./Configure so that certain algorithms can be disabled by default. The new counterpiece to "no-xxx" is "enable-xxx". The patented RC5 and MDC2 algorithms will now be disabled unless "enable-rc5" and "enable-mdc2", respectively, are specified. (IDEA remains enabled despite being patented. This is because IDEA is frequently required for interoperability, and there is no license fee for non-commercial use. As before, "no-idea" can be used to avoid this algorithm.) *Bodo Moeller* * Add processing of proxy certificates (see RFC 3820). This work was sponsored by KTH (The Royal Institute of Technology in Stockholm) and EGEE (Enabling Grids for E-science in Europe). *Richard Levitte* * RC4 performance overhaul on modern architectures/implementations, such as Intel P4, IA-64 and AMD64. *Andy Polyakov* * New utility extract-section.pl. This can be used specify an alternative section number in a pod file instead of having to treat each file as a separate case in Makefile. This can be done by adding two lines to the pod file: =for comment openssl_section:XXX The blank line is mandatory. *Steve Henson* * New arguments -certform, -keyform and -pass for s_client and s_server to allow alternative format key and certificate files and passphrase sources. *Steve Henson* * New structure X509_VERIFY_PARAM which combines current verify parameters, update associated structures and add various utility functions. Add new policy related verify parameters, include policy checking in standard verify code. Enhance 'smime' application with extra parameters to support policy checking and print out. *Steve Henson* * Add a new engine to support VIA PadLock ACE extensions in the VIA C3 Nehemiah processors. These extensions support AES encryption in hardware as well as RNG (though RNG support is currently disabled). *Michal Ludvig , with help from Andy Polyakov* * Deprecate `BN_[get|set]_params()` functions (they were ignored internally). *Geoff Thorpe* * New FIPS 180-2 algorithms, SHA-224/-256/-384/-512 are implemented. *Andy Polyakov and a number of other people* * Improved PowerPC platform support. Most notably BIGNUM assembler implementation contributed by IBM. *Suresh Chari, Peter Waltenberg, Andy Polyakov* * The new 'RSA_generate_key_ex' function now takes a BIGNUM for the public exponent rather than 'unsigned long'. There is a corresponding change to the new 'rsa_keygen' element of the RSA_METHOD structure. *Jelte Jansen, Geoff Thorpe* * Functionality for creating the initial serial number file is now moved from CA.pl to the 'ca' utility with a new option -create_serial. (Before OpenSSL 0.9.7e, CA.pl used to initialize the serial number file to 1, which is bound to cause problems. To avoid the problems while respecting compatibility between different 0.9.7 patchlevels, 0.9.7e employed 'openssl x509 -next_serial' in CA.pl for serial number initialization. With the new release 0.9.8, we can fix the problem directly in the 'ca' utility.) *Steve Henson* * Reduced header interdependencies by declaring more opaque objects in ossl_typ.h. As a consequence, including some headers (eg. engine.h) will give fewer recursive includes, which could break lazy source code - so this change is covered by the OPENSSL_NO_DEPRECATED symbol. As always, developers should define this symbol when building and using openssl to ensure they track the recommended behaviour, interfaces, [etc], but backwards-compatible behaviour prevails when this isn't defined. *Geoff Thorpe* * New function X509_POLICY_NODE_print() which prints out policy nodes. *Steve Henson* * Add new EVP function EVP_CIPHER_CTX_rand_key and associated functionality. This will generate a random key of the appropriate length based on the cipher context. The EVP_CIPHER can provide its own random key generation routine to support keys of a specific form. This is used in the des and 3des routines to generate a key of the correct parity. Update S/MIME code to use new functions and hence generate correct parity DES keys. Add EVP_CHECK_DES_KEY #define to return an error if the key is not valid (weak or incorrect parity). *Steve Henson* * Add a local set of CRLs that can be used by X509_verify_cert() as well as looking them up. This is useful when the verified structure may contain CRLs, for example PKCS#7 signedData. Modify PKCS7_verify() to use any CRLs present unless the new PKCS7_NO_CRL flag is asserted. *Steve Henson* * Extend ASN1 oid configuration module. It now additionally accepts the syntax: shortName = some long name, 1.2.3.4 *Steve Henson* * Reimplemented the BN_CTX implementation. There is now no more static limitation on the number of variables it can handle nor the depth of the "stack" handling for BN_CTX_start()/BN_CTX_end() pairs. The stack information can now expand as required, and rather than having a single static array of bignums, BN_CTX now uses a linked-list of such arrays allowing it to expand on demand whilst maintaining the usefulness of BN_CTX's "bundling". *Geoff Thorpe* * Add a missing BN_CTX parameter to the 'rsa_mod_exp' callback in RSA_METHOD to allow all RSA operations to function using a single BN_CTX. *Geoff Thorpe* * Preliminary support for certificate policy evaluation and checking. This is initially intended to pass the tests outlined in "Conformance Testing of Relying Party Client Certificate Path Processing Logic" v1.07. *Steve Henson* * bn_dup_expand() has been deprecated, it was introduced in 0.9.7 and remained unused and not that useful. A variety of other little bignum tweaks and fixes have also been made continuing on from the audit (see below). *Geoff Thorpe* * Constify all or almost all d2i, c2i, s2i and r2i functions, along with associated ASN1, EVP and SSL functions and old ASN1 macros. *Richard Levitte* * BN_zero() only needs to set 'top' and 'neg' to zero for correct results, and this should never fail. So the return value from the use of BN_set_word() (which can fail due to needless expansion) is now deprecated; if OPENSSL_NO_DEPRECATED is defined, BN_zero() is a void macro. *Geoff Thorpe* * BN_CTX_get() should return zero-valued bignums, providing the same initialised value as BN_new(). *Geoff Thorpe, suggested by Ulf Möller* * Support for inhibitAnyPolicy certificate extension. *Steve Henson* * An audit of the BIGNUM code is underway, for which debugging code is enabled when BN_DEBUG is defined. This makes stricter enforcements on what is considered valid when processing BIGNUMs, and causes execution to assert() when a problem is discovered. If BN_DEBUG_RAND is defined, further steps are taken to deliberately pollute unused data in BIGNUM structures to try and expose faulty code further on. For now, openssl will (in its default mode of operation) continue to tolerate the inconsistent forms that it has tolerated in the past, but authors and packagers should consider trying openssl and their own applications when compiled with these debugging symbols defined. It will help highlight potential bugs in their own code, and will improve the test coverage for OpenSSL itself. At some point, these tighter rules will become openssl's default to improve maintainability, though the assert()s and other overheads will remain only in debugging configurations. See bn.h for more details. *Geoff Thorpe, Nils Larsch, Ulf Möller* * BN_CTX_init() has been deprecated, as BN_CTX is an opaque structure that can only be obtained through BN_CTX_new() (which implicitly initialises it). The presence of this function only made it possible to overwrite an existing structure (and cause memory leaks). *Geoff Thorpe* * Because of the callback-based approach for implementing LHASH as a template type, lh_insert() adds opaque objects to hash-tables and lh_doall() or lh_doall_arg() are typically used with a destructor callback to clean up those corresponding objects before destroying the hash table (and losing the object pointers). So some over-zealous constifications in LHASH have been relaxed so that lh_insert() does not take (nor store) the objects as "const" and the `lh_doall[_arg]` callback wrappers are not prototyped to have "const" restrictions on the object pointers they are given (and so aren't required to cast them away any more). *Geoff Thorpe* * The tmdiff.h API was so ugly and minimal that our own timing utility (speed) prefers to use its own implementation. The two implementations haven't been consolidated as yet (volunteers?) but the tmdiff API has had its object type properly exposed (MS_TM) instead of casting to/from `char *`. This may still change yet if someone realises MS_TM and `ms_time_***` aren't necessarily the greatest nomenclatures - but this is what was used internally to the implementation so I've used that for now. *Geoff Thorpe* * Ensure that deprecated functions do not get compiled when OPENSSL_NO_DEPRECATED is defined. Some "openssl" subcommands and a few of the self-tests were still using deprecated key-generation functions so these have been updated also. *Geoff Thorpe* * Reorganise PKCS#7 code to separate the digest location functionality into PKCS7_find_digest(), digest addition into PKCS7_bio_add_digest(). New function PKCS7_set_digest() to set the digest type for PKCS#7 digestedData type. Add additional code to correctly generate the digestedData type and add support for this type in PKCS7 initialization functions. *Steve Henson* * New function PKCS7_set0_type_other() this initializes a PKCS7 structure of type "other". *Steve Henson* * Fix prime generation loop in crypto/bn/bn_prime.pl by making sure the loop does correctly stop and breaking ("division by zero") modulus operations are not performed. The (pre-generated) prime table crypto/bn/bn_prime.h was already correct, but it could not be re-generated on some platforms because of the "division by zero" situation in the script. *Ralf S. Engelschall* * Update support for ECC-based TLS ciphersuites according to draft-ietf-tls-ecc-03.txt: the KDF1 key derivation function with SHA-1 now is only used for "small" curves (where the representation of a field element takes up to 24 bytes); for larger curves, the field element resulting from ECDH is directly used as premaster secret. *Douglas Stebila (Sun Microsystems Laboratories)* * Add code for kP+lQ timings to crypto/ec/ectest.c, and add SEC2 curve secp160r1 to the tests. *Douglas Stebila (Sun Microsystems Laboratories)* * Add the possibility to load symbols globally with DSO. *Götz Babin-Ebell via Richard Levitte* * Add the functions ERR_set_mark() and ERR_pop_to_mark() for better control of the error stack. *Richard Levitte* * Add support for STORE in ENGINE. *Richard Levitte* * Add the STORE type. The intention is to provide a common interface to certificate and key stores, be they simple file-based stores, or HSM-type store, or LDAP stores, or... NOTE: The code is currently UNTESTED and isn't really used anywhere. *Richard Levitte* * Add a generic structure called OPENSSL_ITEM. This can be used to pass a list of arguments to any function as well as provide a way for a function to pass data back to the caller. *Richard Levitte* * Add the functions BUF_strndup() and BUF_memdup(). BUF_strndup() works like BUF_strdup() but can be used to duplicate a portion of a string. The copy gets NUL-terminated. BUF_memdup() duplicates a memory area. *Richard Levitte* * Add the function sk_find_ex() which works like sk_find(), but will return an index to an element even if an exact match couldn't be found. The index is guaranteed to point at the element where the searched-for key would be inserted to preserve sorting order. *Richard Levitte* * Add the function OBJ_bsearch_ex() which works like OBJ_bsearch() but takes an extra flags argument for optional functionality. Currently, the following flags are defined: OBJ_BSEARCH_VALUE_ON_NOMATCH This one gets OBJ_bsearch_ex() to return a pointer to the first element where the comparing function returns a negative or zero number. OBJ_BSEARCH_FIRST_VALUE_ON_MATCH This one gets OBJ_bsearch_ex() to return a pointer to the first element where the comparing function returns zero. This is useful if there are more than one element where the comparing function returns zero. *Richard Levitte* * Make it possible to create self-signed certificates with 'openssl ca' in such a way that the self-signed certificate becomes part of the CA database and uses the same mechanisms for serial number generation as all other certificate signing. The new flag '-selfsign' enables this functionality. Adapt CA.sh and CA.pl.in. *Richard Levitte* * Add functionality to check the public key of a certificate request against a given private. This is useful to check that a certificate request can be signed by that key (self-signing). *Richard Levitte* * Make it possible to have multiple active certificates with the same subject in the CA index file. This is done only if the keyword 'unique_subject' is set to 'no' in the main CA section (default if 'CA_default') of the configuration file. The value is saved with the database itself in a separate index attribute file, named like the index file with '.attr' appended to the name. *Richard Levitte* * Generate multi-valued AVAs using '+' notation in config files for req and dirName. *Steve Henson* * Support for nameConstraints certificate extension. *Steve Henson* * Support for policyConstraints certificate extension. *Steve Henson* * Support for policyMappings certificate extension. *Steve Henson* * Make sure the default DSA_METHOD implementation only uses its dsa_mod_exp() and/or bn_mod_exp() handlers if they are non-NULL, and change its own handlers to be NULL so as to remove unnecessary indirection. This lets alternative implementations fallback to the default implementation more easily. *Geoff Thorpe* * Support for directoryName in GeneralName related extensions in config files. *Steve Henson* * Make it possible to link applications using Makefile.shared. Make that possible even when linking against static libraries! *Richard Levitte* * Support for single pass processing for S/MIME signing. This now means that S/MIME signing can be done from a pipe, in addition cleartext signing (multipart/signed type) is effectively streaming and the signed data does not need to be all held in memory. This is done with a new flag PKCS7_STREAM. When this flag is set PKCS7_sign() only initializes the PKCS7 structure and the actual signing is done after the data is output (and digests calculated) in SMIME_write_PKCS7(). *Steve Henson* * Add full support for -rpath/-R, both in shared libraries and applications, at least on the platforms where it's known how to do it. *Richard Levitte* * In crypto/ec/ec_mult.c, implement fast point multiplication with precomputation, based on wNAF splitting: EC_GROUP_precompute_mult() will now compute a table of multiples of the generator that makes subsequent invocations of EC_POINTs_mul() or EC_POINT_mul() faster (notably in the case of a single point multiplication, scalar * generator). *Nils Larsch, Bodo Moeller* * IPv6 support for certificate extensions. The various extensions which use the IP:a.b.c.d can now take IPv6 addresses using the formats of RFC1884 2.2 . IPv6 addresses are now also displayed correctly. *Steve Henson* * Added an ENGINE that implements RSA by performing private key exponentiations with the GMP library. The conversions to and from GMP's mpz_t format aren't optimised nor are any montgomery forms cached, and on x86 it appears OpenSSL's own performance has caught up. However there are likely to be other architectures where GMP could provide a boost. This ENGINE is not built in by default, but it can be specified at Configure time and should be accompanied by the necessary linker additions, eg; ./config -DOPENSSL_USE_GMP -lgmp *Geoff Thorpe* * "openssl engine" will not display ENGINE/DSO load failure errors when testing availability of engines with "-t" - the old behaviour is produced by increasing the feature's verbosity with "-tt". *Geoff Thorpe* * ECDSA routines: under certain error conditions uninitialized BN objects could be freed. Solution: make sure initialization is performed early enough. (Reported and fix supplied by Nils Larsch via PR#459) *Lutz Jaenicke* * Key-generation can now be implemented in RSA_METHOD, DSA_METHOD and DH_METHOD (eg. by ENGINE implementations) to override the normal software implementations. For DSA and DH, parameter generation can also be overridden by providing the appropriate method callbacks. *Geoff Thorpe* * Change the "progress" mechanism used in key-generation and primality testing to functions that take a new BN_GENCB pointer in place of callback/argument pairs. The new API functions have `_ex` postfixes and the older functions are reimplemented as wrappers for the new ones. The OPENSSL_NO_DEPRECATED symbol can be used to hide declarations of the old functions to help (graceful) attempts to migrate to the new functions. Also, the new key-generation API functions operate on a caller-supplied key-structure and return success/failure rather than returning a key or NULL - this is to help make "keygen" another member function of RSA_METHOD etc. Example for using the new callback interface: int (*my_callback)(int a, int b, BN_GENCB *cb) = ...; void *my_arg = ...; BN_GENCB my_cb; BN_GENCB_set(&my_cb, my_callback, my_arg); return BN_is_prime_ex(some_bignum, BN_prime_checks, NULL, &cb); /* For the meaning of a, b in calls to my_callback(), see the * documentation of the function that calls the callback. * cb will point to my_cb; my_arg can be retrieved as cb->arg. * my_callback should return 1 if it wants BN_is_prime_ex() * to continue, or 0 to stop. */ *Geoff Thorpe* * Change the ZLIB compression method to be stateful, and make it available to TLS with the number defined in draft-ietf-tls-compression-04.txt. *Richard Levitte* * Add the ASN.1 structures and functions for CertificatePair, which is defined as follows (according to X.509_4thEditionDraftV6.pdf): CertificatePair ::= SEQUENCE { forward [0] Certificate OPTIONAL, reverse [1] Certificate OPTIONAL, -- at least one of the pair shall be present -- } Also implement the PEM functions to read and write certificate pairs, and defined the PEM tag as "CERTIFICATE PAIR". This needed to be defined, mostly for the sake of the LDAP attribute crossCertificatePair, but may prove useful elsewhere as well. *Richard Levitte* * Make it possible to inhibit symlinking of shared libraries in Makefile.shared, for Cygwin's sake. *Richard Levitte* * Extend the BIGNUM API by creating a function void BN_set_negative(BIGNUM *a, int neg); and a macro that behave like int BN_is_negative(const BIGNUM *a); to avoid the need to access 'a->neg' directly in applications. *Nils Larsch* * Implement fast modular reduction for pseudo-Mersenne primes used in NIST curves (crypto/bn/bn_nist.c, crypto/ec/ecp_nist.c). EC_GROUP_new_curve_GFp() will now automatically use this if applicable. *Nils Larsch * * Add new lock type (CRYPTO_LOCK_BN). *Bodo Moeller* * Change the ENGINE framework to automatically load engines dynamically from specific directories unless they could be found to already be built in or loaded. Move all the current engines except for the cryptodev one to a new directory engines/. The engines in engines/ are built as shared libraries if the "shared" options was given to ./Configure or ./config. Otherwise, they are inserted in libcrypto.a. /usr/local/ssl/engines is the default directory for dynamic engines, but that can be overridden at configure time through the usual use of --prefix and/or --openssldir, and at run time with the environment variable OPENSSL_ENGINES. *Geoff Thorpe and Richard Levitte* * Add Makefile.shared, a helper makefile to build shared libraries. Adapt Makefile.org. *Richard Levitte* * Add version info to Win32 DLLs. *Peter 'Luna' Runestig" * * Add new 'medium level' PKCS#12 API. Certificates and keys can be added using this API to created arbitrary PKCS#12 files while avoiding the low-level API. New options to PKCS12_create(), key or cert can be NULL and will then be omitted from the output file. The encryption algorithm NIDs can be set to -1 for no encryption, the mac iteration count can be set to 0 to omit the mac. Enhance pkcs12 utility by making the -nokeys and -nocerts options work when creating a PKCS#12 file. New option -nomac to omit the mac, NONE can be set for an encryption algorithm. New code is modified to use the enhanced PKCS12_create() instead of the low-level API. *Steve Henson* * Extend ASN1 encoder to support indefinite length constructed encoding. This can output sequences tags and octet strings in this form. Modify pk7_asn1.c to support indefinite length encoding. This is experimental and needs additional code to be useful, such as an ASN1 bio and some enhanced streaming PKCS#7 code. Extend template encode functionality so that tagging is passed down to the template encoder. *Steve Henson* * Let 'openssl req' fail if an argument to '-newkey' is not recognized instead of using RSA as a default. *Bodo Moeller* * Add support for ECC-based ciphersuites from draft-ietf-tls-ecc-01.txt. As these are not official, they are not included in "ALL"; the "ECCdraft" ciphersuite group alias can be used to select them. *Vipul Gupta and Sumit Gupta (Sun Microsystems Laboratories)* * Add ECDH engine support. *Nils Gura and Douglas Stebila (Sun Microsystems Laboratories)* * Add ECDH in new directory crypto/ecdh/. *Douglas Stebila (Sun Microsystems Laboratories)* * Let BN_rand_range() abort with an error after 100 iterations without success (which indicates a broken PRNG). *Bodo Moeller* * Change BN_mod_sqrt() so that it verifies that the input value is really the square of the return value. (Previously, BN_mod_sqrt would show GIGO behaviour.) *Bodo Moeller* * Add named elliptic curves over binary fields from X9.62, SECG, and WAP/WTLS; add OIDs that were still missing. *Sheueling Chang Shantz and Douglas Stebila (Sun Microsystems Laboratories)* * Extend the EC library for elliptic curves over binary fields (new files ec2_smpl.c, ec2_smpt.c, ec2_mult.c in crypto/ec/). New EC_METHOD: EC_GF2m_simple_method New API functions: EC_GROUP_new_curve_GF2m EC_GROUP_set_curve_GF2m EC_GROUP_get_curve_GF2m EC_POINT_set_affine_coordinates_GF2m EC_POINT_get_affine_coordinates_GF2m EC_POINT_set_compressed_coordinates_GF2m Point compression for binary fields is disabled by default for patent reasons (compile with OPENSSL_EC_BIN_PT_COMP defined to enable it). As binary polynomials are represented as BIGNUMs, various members of the EC_GROUP and EC_POINT data structures can be shared between the implementations for prime fields and binary fields; the above `..._GF2m functions` (except for EX_GROUP_new_curve_GF2m) are essentially identical to their `..._GFp` counterparts. (For simplicity, the `..._GFp` prefix has been dropped from various internal method names.) An internal 'field_div' method (similar to 'field_mul' and 'field_sqr') has been added; this is used only for binary fields. *Sheueling Chang Shantz and Douglas Stebila (Sun Microsystems Laboratories)* * Optionally dispatch EC_POINT_mul(), EC_POINT_precompute_mult() through methods ('mul', 'precompute_mult'). The generic implementations (now internally called 'ec_wNAF_mul' and 'ec_wNAF_precomputed_mult') remain the default if these methods are undefined. *Sheueling Chang Shantz and Douglas Stebila (Sun Microsystems Laboratories)* * New function EC_GROUP_get_degree, which is defined through EC_METHOD. For curves over prime fields, this returns the bit length of the modulus. *Sheueling Chang Shantz and Douglas Stebila (Sun Microsystems Laboratories)* * New functions EC_GROUP_dup, EC_POINT_dup. (These simply call ..._new and ..._copy). *Sheueling Chang Shantz and Douglas Stebila (Sun Microsystems Laboratories)* * Add binary polynomial arithmetic software in crypto/bn/bn_gf2m.c. Polynomials are represented as BIGNUMs (where the sign bit is not used) in the following functions [macros]: BN_GF2m_add BN_GF2m_sub [= BN_GF2m_add] BN_GF2m_mod [wrapper for BN_GF2m_mod_arr] BN_GF2m_mod_mul [wrapper for BN_GF2m_mod_mul_arr] BN_GF2m_mod_sqr [wrapper for BN_GF2m_mod_sqr_arr] BN_GF2m_mod_inv BN_GF2m_mod_exp [wrapper for BN_GF2m_mod_exp_arr] BN_GF2m_mod_sqrt [wrapper for BN_GF2m_mod_sqrt_arr] BN_GF2m_mod_solve_quad [wrapper for BN_GF2m_mod_solve_quad_arr] BN_GF2m_cmp [= BN_ucmp] (Note that only the 'mod' functions are actually for fields GF(2^m). BN_GF2m_add() is misnomer, but this is for the sake of consistency.) For some functions, an the irreducible polynomial defining a field can be given as an 'unsigned int[]' with strictly decreasing elements giving the indices of those bits that are set; i.e., p[] represents the polynomial f(t) = t^p[0] + t^p[1] + ... + t^p[k] where p[0] > p[1] > ... > p[k] = 0. This applies to the following functions: BN_GF2m_mod_arr BN_GF2m_mod_mul_arr BN_GF2m_mod_sqr_arr BN_GF2m_mod_inv_arr [wrapper for BN_GF2m_mod_inv] BN_GF2m_mod_div_arr [wrapper for BN_GF2m_mod_div] BN_GF2m_mod_exp_arr BN_GF2m_mod_sqrt_arr BN_GF2m_mod_solve_quad_arr BN_GF2m_poly2arr BN_GF2m_arr2poly Conversion can be performed by the following functions: BN_GF2m_poly2arr BN_GF2m_arr2poly bntest.c has additional tests for binary polynomial arithmetic. Two implementations for BN_GF2m_mod_div() are available. The default algorithm simply uses BN_GF2m_mod_inv() and BN_GF2m_mod_mul(). The alternative algorithm is compiled in only if OPENSSL_SUN_GF2M_DIV is defined (patent pending; read the copyright notice in crypto/bn/bn_gf2m.c before enabling it). *Sheueling Chang Shantz and Douglas Stebila (Sun Microsystems Laboratories)* * Add new error code 'ERR_R_DISABLED' that can be used when some functionality is disabled at compile-time. *Douglas Stebila * * Change default behaviour of 'openssl asn1parse' so that more information is visible when viewing, e.g., a certificate: Modify asn1_parse2 (crypto/asn1/asn1_par.c) so that in non-'dump' mode the content of non-printable OCTET STRINGs is output in a style similar to INTEGERs, but with '[HEX DUMP]' prepended to avoid the appearance of a printable string. *Nils Larsch * * Add 'asn1_flag' and 'asn1_form' member to EC_GROUP with access functions EC_GROUP_set_asn1_flag() EC_GROUP_get_asn1_flag() EC_GROUP_set_point_conversion_form() EC_GROUP_get_point_conversion_form() These control ASN1 encoding details: - Curves (i.e., groups) are encoded explicitly unless asn1_flag has been set to OPENSSL_EC_NAMED_CURVE. - Points are encoded in uncompressed form by default; options for asn1_for are as for point2oct, namely POINT_CONVERSION_COMPRESSED POINT_CONVERSION_UNCOMPRESSED POINT_CONVERSION_HYBRID Also add 'seed' and 'seed_len' members to EC_GROUP with access functions EC_GROUP_set_seed() EC_GROUP_get0_seed() EC_GROUP_get_seed_len() This is used only for ASN1 purposes (so far). *Nils Larsch * * Add 'field_type' member to EC_METHOD, which holds the NID of the appropriate field type OID. The new function EC_METHOD_get_field_type() returns this value. *Nils Larsch * * Add functions EC_POINT_point2bn() EC_POINT_bn2point() EC_POINT_point2hex() EC_POINT_hex2point() providing useful interfaces to EC_POINT_point2oct() and EC_POINT_oct2point(). *Nils Larsch * * Change internals of the EC library so that the functions EC_GROUP_set_generator() EC_GROUP_get_generator() EC_GROUP_get_order() EC_GROUP_get_cofactor() are implemented directly in crypto/ec/ec_lib.c and not dispatched to methods, which would lead to unnecessary code duplication when adding different types of curves. *Nils Larsch with input by Bodo Moeller* * Implement compute_wNAF (crypto/ec/ec_mult.c) without BIGNUM arithmetic, and such that modified wNAFs are generated (which avoid length expansion in many cases). *Bodo Moeller* * Add a function EC_GROUP_check_discriminant() (defined via EC_METHOD) that verifies that the curve discriminant is non-zero. Add a function EC_GROUP_check() that makes some sanity tests on a EC_GROUP, its generator and order. This includes EC_GROUP_check_discriminant(). *Nils Larsch * * Add ECDSA in new directory crypto/ecdsa/. Add applications 'openssl ecparam' and 'openssl ecdsa' (these are based on 'openssl dsaparam' and 'openssl dsa'). ECDSA support is also included in various other files across the library. Most notably, - 'openssl req' now has a '-newkey ecdsa:file' option; - EVP_PKCS82PKEY (crypto/evp/evp_pkey.c) now can handle ECDSA; - X509_PUBKEY_get (crypto/asn1/x_pubkey.c) and d2i_PublicKey (crypto/asn1/d2i_pu.c) have been modified to make them suitable for ECDSA where domain parameters must be extracted before the specific public key; - ECDSA engine support has been added. *Nils Larsch * * Include some named elliptic curves, and add OIDs from X9.62, SECG, and WAP/WTLS. Each curve can be obtained from the new function EC_GROUP_new_by_curve_name(), and the list of available named curves can be obtained with EC_get_builtin_curves(). Also add a 'curve_name' member to EC_GROUP objects, which can be accessed via EC_GROUP_set_curve_name() EC_GROUP_get_curve_name() *Nils Larsch * * Include "!eNULL" in SSL_DEFAULT_CIPHER_LIST to make sure that a ciphersuite string such as "DEFAULT:RSA" cannot enable authentication-only ciphersuites. *Bodo Moeller* * Since AES128 and AES256 share a single mask bit in the logic of ssl/ssl_ciph.c, the code for masking out disabled ciphers needs a kludge to work properly if AES128 is available and AES256 isn't. *Victor Duchovni* * Expand security boundary to match 1.1.1 module. *Steve Henson* * Remove redundant features: hash file source, editing of test vectors modify fipsld to use external fips_premain.c signature. *Steve Henson* * New perl script mkfipsscr.pl to create shell scripts or batch files to run algorithm test programs. *Steve Henson* * Make algorithm test programs more tolerant of whitespace. *Steve Henson* * Have SSL/TLS server implementation tolerate "mismatched" record protocol version while receiving ClientHello even if the ClientHello is fragmented. (The server can't insist on the particular protocol version it has chosen before the ServerHello message has informed the client about his choice.) *Bodo Moeller* * Load error codes if they are not already present instead of using a static variable. This allows them to be cleanly unloaded and reloaded. *Steve Henson* ### Changes between 0.9.7k and 0.9.7l [28 Sep 2006] * Introduce limits to prevent malicious keys being able to cause a denial of service. ([CVE-2006-2940]) *Steve Henson, Bodo Moeller* * Fix ASN.1 parsing of certain invalid structures that can result in a denial of service. ([CVE-2006-2937]) [Steve Henson] * Fix buffer overflow in SSL_get_shared_ciphers() function. ([CVE-2006-3738]) [Tavis Ormandy and Will Drewry, Google Security Team] * Fix SSL client code which could crash if connecting to a malicious SSLv2 server. ([CVE-2006-4343]) *Tavis Ormandy and Will Drewry, Google Security Team* * Change ciphersuite string processing so that an explicit ciphersuite selects this one ciphersuite (so that "AES256-SHA" will no longer include "AES128-SHA"), and any other similar ciphersuite (same bitmap) from *other* protocol versions (so that "RC4-MD5" will still include both the SSL 2.0 ciphersuite and the SSL 3.0/TLS 1.0 ciphersuite). This is a backport combining changes from 0.9.8b and 0.9.8d. *Bodo Moeller* ### Changes between 0.9.7j and 0.9.7k [05 Sep 2006] * Avoid PKCS #1 v1.5 signature attack discovered by Daniel Bleichenbacher ([CVE-2006-4339]) [Ben Laurie and Google Security Team] * Change the Unix randomness entropy gathering to use poll() when possible instead of select(), since the latter has some undesirable limitations. *Darryl Miles via Richard Levitte and Bodo Moeller* * Disable rogue ciphersuites: - SSLv2 0x08 0x00 0x80 ("RC4-64-MD5") - SSLv3/TLSv1 0x00 0x61 ("EXP1024-RC2-CBC-MD5") - SSLv3/TLSv1 0x00 0x60 ("EXP1024-RC4-MD5") The latter two were purportedly from draft-ietf-tls-56-bit-ciphersuites-0[01].txt, but do not really appear there. Also deactivate the remaining ciphersuites from draft-ietf-tls-56-bit-ciphersuites-01.txt. These are just as unofficial, and the ID has long expired. *Bodo Moeller* * Fix RSA blinding Heisenbug (problems sometimes occurred on dual-core machines) and other potential thread-safety issues. *Bodo Moeller* ### Changes between 0.9.7i and 0.9.7j [04 May 2006] * Adapt fipsld and the build system to link against the validated FIPS module in FIPS mode. *Steve Henson* * Fixes for VC++ 2005 build under Windows. *Steve Henson* * Add new Windows build target VC-32-GMAKE for VC++. This uses GNU make from a Windows bash shell such as MSYS. It is autodetected from the "config" script when run from a VC++ environment. Modify standard VC++ build to use fipscanister.o from the GNU make build. *Steve Henson* ### Changes between 0.9.7h and 0.9.7i [14 Oct 2005] * Wrapped the definition of EVP_MAX_MD_SIZE in a #ifdef OPENSSL_FIPS. The value now differs depending on if you build for FIPS or not. BEWARE! A program linked with a shared FIPSed libcrypto can't be safely run with a non-FIPSed libcrypto, as it may crash because of the difference induced by this change. *Andy Polyakov* ### Changes between 0.9.7g and 0.9.7h [11 Oct 2005] * Remove the functionality of SSL_OP_MSIE_SSLV2_RSA_PADDING (part of SSL_OP_ALL). This option used to disable the countermeasure against man-in-the-middle protocol-version rollback in the SSL 2.0 server implementation, which is a bad idea. ([CVE-2005-2969]) *Bodo Moeller; problem pointed out by Yutaka Oiwa (Research Center for Information Security, National Institute of Advanced Industrial Science and Technology [AIST, Japan)]* * Minimal support for X9.31 signatures and PSS padding modes. This is mainly for FIPS compliance and not fully integrated at this stage. *Steve Henson* * For DSA signing, unless DSA_FLAG_NO_EXP_CONSTTIME is set, perform the exponentiation using a fixed-length exponent. (Otherwise, the information leaked through timing could expose the secret key after many signatures; cf. Bleichenbacher's attack on DSA with biased k.) *Bodo Moeller* * Make a new fixed-window mod_exp implementation the default for RSA, DSA, and DH private-key operations so that the sequence of squares and multiplies and the memory access pattern are independent of the particular secret key. This will mitigate cache-timing and potential related attacks. BN_mod_exp_mont_consttime() is the new exponentiation implementation, and this is automatically used by BN_mod_exp_mont() if the new flag BN_FLG_EXP_CONSTTIME is set for the exponent. RSA, DSA, and DH will use this BN flag for private exponents unless the flag RSA_FLAG_NO_EXP_CONSTTIME, DSA_FLAG_NO_EXP_CONSTTIME, or DH_FLAG_NO_EXP_CONSTTIME, respectively, is set. *Matthew D Wood (Intel Corp), with some changes by Bodo Moeller* * Change the client implementation for SSLv23_method() and SSLv23_client_method() so that is uses the SSL 3.0/TLS 1.0 Client Hello message format if the SSL_OP_NO_SSLv2 option is set. (Previously, the SSL 2.0 backwards compatible Client Hello message format would be used even with SSL_OP_NO_SSLv2.) *Bodo Moeller* * Add support for smime-type MIME parameter in S/MIME messages which some clients need. *Steve Henson* * New function BN_MONT_CTX_set_locked() to set montgomery parameters in a threadsafe manner. Modify rsa code to use new function and add calls to dsa and dh code (which had race conditions before). *Steve Henson* * Include the fixed error library code in the C error file definitions instead of fixing them up at runtime. This keeps the error code structures constant. *Steve Henson* ### Changes between 0.9.7f and 0.9.7g [11 Apr 2005] [NB: OpenSSL 0.9.7h and later 0.9.7 patch levels were released after OpenSSL 0.9.8.] * Fixes for newer kerberos headers. NB: the casts are needed because the 'length' field is signed on one version and unsigned on another with no (?) obvious way to tell the difference, without these VC++ complains. Also the "definition" of FAR (blank) is no longer included nor is the error ENOMEM. KRB5_PRIVATE has to be set to 1 to pick up some needed definitions. *Steve Henson* * Undo Cygwin change. *Ulf Möller* * Added support for proxy certificates according to RFC 3820. Because they may be a security thread to unaware applications, they must be explicitly allowed in run-time. See docs/HOWTO/proxy_certificates.txt for further information. *Richard Levitte* ### Changes between 0.9.7e and 0.9.7f [22 Mar 2005] * Use (SSL_RANDOM_VALUE - 4) bytes of pseudo random data when generating server and client random values. Previously (SSL_RANDOM_VALUE - sizeof(time_t)) would be used which would result in less random data when sizeof(time_t) > 4 (some 64 bit platforms). This change has negligible security impact because: 1. Server and client random values still have 24 bytes of pseudo random data. 2. Server and client random values are sent in the clear in the initial handshake. 3. The master secret is derived using the premaster secret (48 bytes in size for static RSA ciphersuites) as well as client server and random values. The OpenSSL team would like to thank the UK NISCC for bringing this issue to our attention. *Stephen Henson, reported by UK NISCC* * Use Windows randomness collection on Cygwin. *Ulf Möller* * Fix hang in EGD/PRNGD query when communication socket is closed prematurely by EGD/PRNGD. *Darren Tucker via Lutz Jänicke, resolves #1014* * Prompt for pass phrases when appropriate for PKCS12 input format. *Steve Henson* * Back-port of selected performance improvements from development branch, as well as improved support for PowerPC platforms. *Andy Polyakov* * Add lots of checks for memory allocation failure, error codes to indicate failure and freeing up memory if a failure occurs. *Nauticus Networks SSL Team , Steve Henson* * Add new -passin argument to dgst. *Steve Henson* * Perform some character comparisons of different types in X509_NAME_cmp: this is needed for some certificates that re-encode DNs into UTF8Strings (in violation of RFC3280) and can't or won't issue name rollover certificates. *Steve Henson* * Make an explicit check during certificate validation to see that the CA setting in each certificate on the chain is correct. As a side effect always do the following basic checks on extensions, not just when there's an associated purpose to the check: - if there is an unhandled critical extension (unless the user has chosen to ignore this fault) - if the path length has been exceeded (if one is set at all) - that certain extensions fit the associated purpose (if one has been given) *Richard Levitte* ### Changes between 0.9.7d and 0.9.7e [25 Oct 2004] * Avoid a race condition when CRLs are checked in a multi threaded environment. This would happen due to the reordering of the revoked entries during signature checking and serial number lookup. Now the encoding is cached and the serial number sort performed under a lock. Add new STACK function sk_is_sorted(). *Steve Henson* * Add Delta CRL to the extension code. *Steve Henson* * Various fixes to s3_pkt.c so alerts are sent properly. *David Holmes * * Reduce the chances of duplicate issuer name and serial numbers (in violation of RFC3280) using the OpenSSL certificate creation utilities. This is done by creating a random 64 bit value for the initial serial number when a serial number file is created or when a self signed certificate is created using 'openssl req -x509'. The initial serial number file is created using 'openssl x509 -next_serial' in CA.pl rather than being initialized to 1. *Steve Henson* ### Changes between 0.9.7c and 0.9.7d [17 Mar 2004] * Fix null-pointer assignment in do_change_cipher_spec() revealed by using the Codenomicon TLS Test Tool ([CVE-2004-0079]) *Joe Orton, Steve Henson* * Fix flaw in SSL/TLS handshaking when using Kerberos ciphersuites ([CVE-2004-0112]) *Joe Orton, Steve Henson* * Make it possible to have multiple active certificates with the same subject in the CA index file. This is done only if the keyword 'unique_subject' is set to 'no' in the main CA section (default if 'CA_default') of the configuration file. The value is saved with the database itself in a separate index attribute file, named like the index file with '.attr' appended to the name. *Richard Levitte* * X509 verify fixes. Disable broken certificate workarounds when X509_V_FLAGS_X509_STRICT is set. Check CRL issuer has cRLSign set if keyUsage extension present. Don't accept CRLs with unhandled critical extensions: since verify currently doesn't process CRL extensions this rejects a CRL with *any* critical extensions. Add new verify error codes for these cases. *Steve Henson* * When creating an OCSP nonce use an OCTET STRING inside the extnValue. A clarification of RFC2560 will require the use of OCTET STRINGs and some implementations cannot handle the current raw format. Since OpenSSL copies and compares OCSP nonces as opaque blobs without any attempt at parsing them this should not create any compatibility issues. *Steve Henson* * New md flag EVP_MD_CTX_FLAG_REUSE this allows md_data to be reused when calling EVP_MD_CTX_copy_ex() to avoid calling OPENSSL_malloc(). Without this HMAC (and other) operations are several times slower than OpenSSL < 0.9.7. *Steve Henson* * Print out GeneralizedTime and UTCTime in ASN1_STRING_print_ex(). *Peter Sylvester * * Use the correct content when signing type "other". *Steve Henson* ### Changes between 0.9.7b and 0.9.7c [30 Sep 2003] * Fix various bugs revealed by running the NISCC test suite: Stop out of bounds reads in the ASN1 code when presented with invalid tags (CVE-2003-0543 and CVE-2003-0544). Free up ASN1_TYPE correctly if ANY type is invalid ([CVE-2003-0545]). If verify callback ignores invalid public key errors don't try to check certificate signature with the NULL public key. *Steve Henson* * New -ignore_err option in ocsp application to stop the server exiting on the first error in a request. *Steve Henson* * In ssl3_accept() (ssl/s3_srvr.c) only accept a client certificate if the server requested one: as stated in TLS 1.0 and SSL 3.0 specifications. *Steve Henson* * In ssl3_get_client_hello() (ssl/s3_srvr.c), tolerate additional extra data after the compression methods not only for TLS 1.0 but also for SSL 3.0 (as required by the specification). *Bodo Moeller; problem pointed out by Matthias Loepfe* * Change X509_certificate_type() to mark the key as exported/exportable when it's 512 *bits* long, not 512 bytes. *Richard Levitte* * Change AES_cbc_encrypt() so it outputs exact multiple of blocks during encryption. *Richard Levitte* * Various fixes to base64 BIO and non blocking I/O. On write flushes were not handled properly if the BIO retried. On read data was not being buffered properly and had various logic bugs. This also affects blocking I/O when the data being decoded is a certain size. *Steve Henson* * Various S/MIME bugfixes and compatibility changes: output correct application/pkcs7 MIME type if PKCS7_NOOLDMIMETYPE is set. Tolerate some broken signatures. Output CR+LF for EOL if PKCS7_CRLFEOL is set (this makes opening of files as .eml work). Correctly handle very long lines in MIME parser. *Steve Henson* ### Changes between 0.9.7a and 0.9.7b [10 Apr 2003] * Countermeasure against the Klima-Pokorny-Rosa extension of Bleichbacher's attack on PKCS #1 v1.5 padding: treat a protocol version number mismatch like a decryption error in ssl3_get_client_key_exchange (ssl/s3_srvr.c). *Bodo Moeller* * Turn on RSA blinding by default in the default implementation to avoid a timing attack. Applications that don't want it can call RSA_blinding_off() or use the new flag RSA_FLAG_NO_BLINDING. They would be ill-advised to do so in most cases. *Ben Laurie, Steve Henson, Geoff Thorpe, Bodo Moeller* * Change RSA blinding code so that it works when the PRNG is not seeded (in this case, the secret RSA exponent is abused as an unpredictable seed -- if it is not unpredictable, there is no point in blinding anyway). Make RSA blinding thread-safe by remembering the creator's thread ID in rsa->blinding and having all other threads use local one-time blinding factors (this requires more computation than sharing rsa->blinding, but avoids excessive locking; and if an RSA object is not shared between threads, blinding will still be very fast). *Bodo Moeller* * Fixed a typo bug that would cause ENGINE_set_default() to set an ENGINE as defaults for all supported algorithms irrespective of the 'flags' parameter. 'flags' is now honoured, so applications should make sure they are passing it correctly. *Geoff Thorpe* * Target "mingw" now allows native Windows code to be generated in the Cygwin environment as well as with the MinGW compiler. *Ulf Moeller* ### Changes between 0.9.7 and 0.9.7a [19 Feb 2003] * In ssl3_get_record (ssl/s3_pkt.c), minimize information leaked via timing by performing a MAC computation even if incorrect block cipher padding has been found. This is a countermeasure against active attacks where the attacker has to distinguish between bad padding and a MAC verification error. ([CVE-2003-0078]) *Bodo Moeller; problem pointed out by Brice Canvel (EPFL), Alain Hiltgen (UBS), Serge Vaudenay (EPFL), and Martin Vuagnoux (EPFL, Ilion)* * Make the no-err option work as intended. The intention with no-err is not to have the whole error stack handling routines removed from libcrypto, it's only intended to remove all the function name and reason texts, thereby removing some of the footprint that may not be interesting if those errors aren't displayed anyway. NOTE: it's still possible for any application or module to have its own set of error texts inserted. The routines are there, just not used by default when no-err is given. *Richard Levitte* * Add support for FreeBSD on IA64. *dirk.meyer@dinoex.sub.org via Richard Levitte, resolves #454* * Adjust DES_cbc_cksum() so it returns the same value as the MIT Kerberos function mit_des_cbc_cksum(). Before this change, the value returned by DES_cbc_cksum() was like the one from mit_des_cbc_cksum(), except the bytes were swapped. *Kevin Greaney and Richard Levitte* * Allow an application to disable the automatic SSL chain building. Before this a rather primitive chain build was always performed in ssl3_output_cert_chain(): an application had no way to send the correct chain if the automatic operation produced an incorrect result. Now the chain builder is disabled if either: 1. Extra certificates are added via SSL_CTX_add_extra_chain_cert(). 2. The mode flag SSL_MODE_NO_AUTO_CHAIN is set. The reasoning behind this is that an application would not want the auto chain building to take place if extra chain certificates are present and it might also want a means of sending no additional certificates (for example the chain has two certificates and the root is omitted). *Steve Henson* * Add the possibility to build without the ENGINE framework. *Steven Reddie via Richard Levitte* * Under Win32 gmtime() can return NULL: check return value in OPENSSL_gmtime(). Add error code for case where gmtime() fails. *Steve Henson* * DSA routines: under certain error conditions uninitialized BN objects could be freed. Solution: make sure initialization is performed early enough. (Reported and fix supplied by Ivan D Nestlerode , Nils Larsch via PR#459) *Lutz Jaenicke* * Another fix for SSLv2 session ID handling: the session ID was incorrectly checked on reconnect on the client side, therefore session resumption could still fail with a "ssl session id is different" error. This behaviour is masked when SSL_OP_ALL is used due to SSL_OP_MICROSOFT_SESS_ID_BUG being set. Behaviour observed by Crispin Flowerday as followup to PR #377. *Lutz Jaenicke* * IA-32 assembler support enhancements: unified ELF targets, support for SCO/Caldera platforms, fix for Cygwin shared build. *Andy Polyakov* * Add support for FreeBSD on sparc64. As a consequence, support for FreeBSD on non-x86 processors is separate from x86 processors on the config script, much like the NetBSD support. *Richard Levitte & Kris Kennaway * ### Changes between 0.9.6h and 0.9.7 [31 Dec 2002] [NB: OpenSSL 0.9.6i and later 0.9.6 patch levels were released after OpenSSL 0.9.7.] * Fix session ID handling in SSLv2 client code: the SERVER FINISHED code (06) was taken as the first octet of the session ID and the last octet was ignored consequently. As a result SSLv2 client side session caching could not have worked due to the session ID mismatch between client and server. Behaviour observed by Crispin Flowerday as PR #377. *Lutz Jaenicke* * Change the declaration of needed Kerberos libraries to use EX_LIBS instead of the special (and badly supported) LIBKRB5. LIBKRB5 is removed entirely. *Richard Levitte* * The hw_ncipher.c engine requires dynamic locks. Unfortunately, it seems that in spite of existing for more than a year, many application author have done nothing to provide the necessary callbacks, which means that this particular engine will not work properly anywhere. This is a very unfortunate situation which forces us, in the name of usability, to give the hw_ncipher.c a static lock, which is part of libcrypto. NOTE: This is for the 0.9.7 series ONLY. This hack will never appear in 0.9.8 or later. We EXPECT application authors to have dealt properly with this when 0.9.8 is released (unless we actually make such changes in the libcrypto locking code that changes will have to be made anyway). *Richard Levitte* * In asn1_d2i_read_bio() repeatedly call BIO_read() until all content octets have been read, EOF or an error occurs. Without this change some truncated ASN1 structures will not produce an error. *Steve Henson* * Disable Heimdal support, since it hasn't been fully implemented. Still give the possibility to force the use of Heimdal, but with warnings and a request that patches get sent to openssl-dev. *Richard Levitte* * Add the VC-CE target, introduce the WINCE sysname, and add INSTALL.WCE and appropriate conditionals to make it build. *Steven Reddie via Richard Levitte* * Change the DLL names for Cygwin to cygcrypto-x.y.z.dll and cygssl-x.y.z.dll, where x, y and z are the major, minor and edit numbers of the version. *Corinna Vinschen and Richard Levitte* * Introduce safe string copy and catenation functions (BUF_strlcpy() and BUF_strlcat()). *Ben Laurie (CHATS) and Richard Levitte* * Avoid using fixed-size buffers for one-line DNs. *Ben Laurie (CHATS)* * Add BUF_MEM_grow_clean() to avoid information leakage when resizing buffers containing secrets, and use where appropriate. *Ben Laurie (CHATS)* * Avoid using fixed size buffers for configuration file location. *Ben Laurie (CHATS)* * Avoid filename truncation for various CA files. *Ben Laurie (CHATS)* * Use sizeof in preference to magic numbers. *Ben Laurie (CHATS)* * Avoid filename truncation in cert requests. *Ben Laurie (CHATS)* * Add assertions to check for (supposedly impossible) buffer overflows. *Ben Laurie (CHATS)* * Don't cache truncated DNS entries in the local cache (this could potentially lead to a spoofing attack). *Ben Laurie (CHATS)* * Fix various buffers to be large enough for hex/decimal representations in a platform independent manner. *Ben Laurie (CHATS)* * Add CRYPTO_realloc_clean() to avoid information leakage when resizing buffers containing secrets, and use where appropriate. *Ben Laurie (CHATS)* * Add BIO_indent() to avoid much slightly worrying code to do indents. *Ben Laurie (CHATS)* * Convert sprintf()/BIO_puts() to BIO_printf(). *Ben Laurie (CHATS)* * buffer_gets() could terminate with the buffer only half full. Fixed. *Ben Laurie (CHATS)* * Add assertions to prevent user-supplied crypto functions from overflowing internal buffers by having large block sizes, etc. *Ben Laurie (CHATS)* * New OPENSSL_assert() macro (similar to assert(), but enabled unconditionally). *Ben Laurie (CHATS)* * Eliminate unused copy of key in RC4. *Ben Laurie (CHATS)* * Eliminate unused and incorrectly sized buffers for IV in pem.h. *Ben Laurie (CHATS)* * Fix off-by-one error in EGD path. *Ben Laurie (CHATS)* * If RANDFILE path is too long, ignore instead of truncating. *Ben Laurie (CHATS)* * Eliminate unused and incorrectly sized X.509 structure CBCParameter. *Ben Laurie (CHATS)* * Eliminate unused and dangerous function knumber(). *Ben Laurie (CHATS)* * Eliminate unused and dangerous structure, KSSL_ERR. *Ben Laurie (CHATS)* * Protect against overlong session ID context length in an encoded session object. Since these are local, this does not appear to be exploitable. *Ben Laurie (CHATS)* * Change from security patch (see 0.9.6e below) that did not affect the 0.9.6 release series: Remote buffer overflow in SSL3 protocol - an attacker could supply an oversized master key in Kerberos-enabled versions. ([CVE-2002-0657]) *Ben Laurie (CHATS)* * Change the SSL kerb5 codes to match RFC 2712. *Richard Levitte* * Make -nameopt work fully for req and add -reqopt switch. *Michael Bell , Steve Henson* * The "block size" for block ciphers in CFB and OFB mode should be 1. *Steve Henson, reported by Yngve Nysaeter Pettersen * * Make sure tests can be performed even if the corresponding algorithms have been removed entirely. This was also the last step to make OpenSSL compilable with DJGPP under all reasonable conditions. *Richard Levitte, Doug Kaufman * * Add cipher selection rules COMPLEMENTOFALL and COMPLEMENTOFDEFAULT to allow version independent disabling of normally unselected ciphers, which may be activated as a side-effect of selecting a single cipher. (E.g., cipher list string "RSA" enables ciphersuites that are left out of "ALL" because they do not provide symmetric encryption. "RSA:!COMPLEMEMENTOFALL" avoids these unsafe ciphersuites.) *Lutz Jaenicke, Bodo Moeller* * Add appropriate support for separate platform-dependent build directories. The recommended way to make a platform-dependent build directory is the following (tested on Linux), maybe with some local tweaks: # Place yourself outside of the OpenSSL source tree. In # this example, the environment variable OPENSSL_SOURCE # is assumed to contain the absolute OpenSSL source directory. mkdir -p objtree/"`uname -s`-`uname -r`-`uname -m`" cd objtree/"`uname -s`-`uname -r`-`uname -m`" (cd $OPENSSL_SOURCE; find . -type f) | while read F; do mkdir -p `dirname $F` ln -s $OPENSSL_SOURCE/$F $F done To be absolutely sure not to disturb the source tree, a "make clean" is a good thing. If it isn't successful, don't worry about it, it probably means the source directory is very clean. *Richard Levitte* * Make sure any ENGINE control commands make local copies of string pointers passed to them whenever necessary. Otherwise it is possible the caller may have overwritten (or deallocated) the original string data when a later ENGINE operation tries to use the stored values. *Götz Babin-Ebell * * Improve diagnostics in file reading and command-line digests. *Ben Laurie aided and abetted by Solar Designer * * Add AES modes CFB and OFB to the object database. Correct an error in AES-CFB decryption. *Richard Levitte* * Remove most calls to EVP_CIPHER_CTX_cleanup() in evp_enc.c, this allows existing EVP_CIPHER_CTX structures to be reused after calling `EVP_*Final()`. This behaviour is used by encryption BIOs and some applications. This has the side effect that applications must explicitly clean up cipher contexts with EVP_CIPHER_CTX_cleanup() or they will leak memory. *Steve Henson* * Check the values of dna and dnb in bn_mul_recursive before calling bn_mul_comba (a non zero value means the a or b arrays do not contain n2 elements) and fallback to bn_mul_normal if either is not zero. *Steve Henson* * Fix escaping of non-ASCII characters when using the -subj option of the "openssl req" command line tool. (Robert Joop ) *Lutz Jaenicke* * Make object definitions compliant to LDAP (RFC2256): SN is the short form for "surname", serialNumber has no short form. Use "mail" as the short name for "rfc822Mailbox" according to RFC2798; therefore remove "mail" short name for "internet 7". The OID for unique identifiers in X509 certificates is x500UniqueIdentifier, not uniqueIdentifier. Some more OID additions. (Michael Bell ) *Lutz Jaenicke* * Add an "init" command to the ENGINE config module and auto initialize ENGINEs. Without any "init" command the ENGINE will be initialized after all ctrl commands have been executed on it. If init=1 the ENGINE is initialized at that point (ctrls before that point are run on the uninitialized ENGINE and after on the initialized one). If init=0 then the ENGINE will not be initialized at all. *Steve Henson* * Fix the 'app_verify_callback' interface so that the user-defined argument is actually passed to the callback: In the SSL_CTX_set_cert_verify_callback() prototype, the callback declaration has been changed from int (*cb)() into int (*cb)(X509_STORE_CTX *,void *); in ssl_verify_cert_chain (ssl/ssl_cert.c), the call i=s->ctx->app_verify_callback(&ctx) has been changed into i=s->ctx->app_verify_callback(&ctx, s->ctx->app_verify_arg). To update applications using SSL_CTX_set_cert_verify_callback(), a dummy argument can be added to their callback functions. *D. K. Smetters * * Added the '4758cca' ENGINE to support IBM 4758 cards. *Maurice Gittens , touchups by Geoff Thorpe* * Add and OPENSSL_LOAD_CONF define which will cause OpenSSL_add_all_algorithms() to load the openssl.cnf config file. This allows older applications to transparently support certain OpenSSL features: such as crypto acceleration and dynamic ENGINE loading. Two new functions OPENSSL_add_all_algorithms_noconf() which will never load the config file and OPENSSL_add_all_algorithms_conf() which will always load it have also been added. *Steve Henson* * Add the OFB, CFB and CTR (all with 128 bit feedback) to AES. Adjust NIDs and EVP layer. *Stephen Sprunk and Richard Levitte* * Config modules support in openssl utility. Most commands now load modules from the config file, though in a few (such as version) this isn't done because it couldn't be used for anything. In the case of ca and req the config file used is the same as the utility itself: that is the -config command line option can be used to specify an alternative file. *Steve Henson* * Move default behaviour from OPENSSL_config(). If appname is NULL use "openssl_conf" if filename is NULL use default openssl config file. *Steve Henson* * Add an argument to OPENSSL_config() to allow the use of an alternative config section name. Add a new flag to tolerate a missing config file and move code to CONF_modules_load_file(). *Steve Henson* * Support for crypto accelerator cards from Accelerated Encryption Processing, www.aep.ie. (Use engine 'aep') The support was copied from 0.9.6c [engine] and adapted/corrected to work with the new engine framework. *AEP Inc. and Richard Levitte* * Support for SureWare crypto accelerator cards from Baltimore Technologies. (Use engine 'sureware') The support was copied from 0.9.6c [engine] and adapted to work with the new engine framework. *Richard Levitte* * Have the CHIL engine fork-safe (as defined by nCipher) and actually make the newer ENGINE framework commands for the CHIL engine work. *Toomas Kiisk and Richard Levitte* * Make it possible to produce shared libraries on ReliantUNIX. *Robert Dahlem via Richard Levitte* * Add the configuration target debug-linux-ppro. Make 'openssl rsa' use the general key loading routines implemented in `apps.c`, and make those routines able to handle the key format FORMAT_NETSCAPE and the variant FORMAT_IISSGC. *Toomas Kiisk via Richard Levitte* * Fix a crashbug and a logic bug in hwcrhk_load_pubkey(). *Toomas Kiisk via Richard Levitte* * Add -keyform to rsautl, and document -engine. *Richard Levitte, inspired by Toomas Kiisk * * Change BIO_new_file (crypto/bio/bss_file.c) to use new BIO_R_NO_SUCH_FILE error code rather than the generic ERR_R_SYS_LIB error code if fopen() fails with ENOENT. *Ben Laurie* * Add new functions ERR_peek_last_error ERR_peek_last_error_line ERR_peek_last_error_line_data. These are similar to ERR_peek_error ERR_peek_error_line ERR_peek_error_line_data, but report on the latest error recorded rather than the first one still in the error queue. *Ben Laurie, Bodo Moeller* * default_algorithms option in ENGINE config module. This allows things like: default_algorithms = ALL default_algorithms = RSA, DSA, RAND, CIPHERS, DIGESTS *Steve Henson* * Preliminary ENGINE config module. *Steve Henson* * New experimental application configuration code. *Steve Henson* * Change the AES code to follow the same name structure as all other symmetric ciphers, and behave the same way. Move everything to the directory crypto/aes, thereby obsoleting crypto/rijndael. *Stephen Sprunk and Richard Levitte* * SECURITY: remove unsafe setjmp/signal interaction from ui_openssl.c. *Ben Laurie and Theo de Raadt* * Add option to output public keys in req command. *Massimiliano Pala madwolf@openca.org* * Use wNAFs in EC_POINTs_mul() for improved efficiency (up to about 10% better than before for P-192 and P-224). *Bodo Moeller* * New functions/macros SSL_CTX_set_msg_callback(ctx, cb) SSL_CTX_set_msg_callback_arg(ctx, arg) SSL_set_msg_callback(ssl, cb) SSL_set_msg_callback_arg(ssl, arg) to request calling a callback function void cb(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg) whenever a protocol message has been completely received (write_p == 0) or sent (write_p == 1). Here 'version' is the protocol version according to which the SSL library interprets the current protocol message (SSL2_VERSION, SSL3_VERSION, or TLS1_VERSION). 'content_type' is 0 in the case of SSL 2.0, or the content type as defined in the SSL 3.0/TLS 1.0 protocol specification (change_cipher_spec(20), alert(21), handshake(22)). 'buf' and 'len' point to the actual message, 'ssl' to the SSL object, and 'arg' is the application-defined value set by SSL[_CTX]_set_msg_callback_arg(). 'openssl s_client' and 'openssl s_server' have new '-msg' options to enable a callback that displays all protocol messages. *Bodo Moeller* * Change the shared library support so shared libraries are built as soon as the corresponding static library is finished, and thereby get openssl and the test programs linked against the shared library. This still only happens when the keyword "shard" has been given to the configuration scripts. NOTE: shared library support is still an experimental thing, and backward binary compatibility is still not guaranteed. *"Maciej W. Rozycki" and Richard Levitte* * Add support for Subject Information Access extension. *Peter Sylvester * * Make BUF_MEM_grow() behaviour more consistent: Initialise to zero additional bytes when new memory had to be allocated, not just when reusing an existing buffer. *Bodo Moeller* * New command line and configuration option 'utf8' for the req command. This allows field values to be specified as UTF8 strings. *Steve Henson* * Add -multi and -mr options to "openssl speed" - giving multiple parallel runs for the former and machine-readable output for the latter. *Ben Laurie* * Add '-noemailDN' option to 'openssl ca'. This prevents inclusion of the e-mail address in the DN (i.e., it will go into a certificate extension only). The new configuration file option 'email_in_dn = no' has the same effect. *Massimiliano Pala madwolf@openca.org* * Change all functions with names starting with `des_` to be starting with `DES_` instead. Add wrappers that are compatible with libdes, but are named `_ossl_old_des_*`. Finally, add macros that map the `des_*` symbols to the corresponding `_ossl_old_des_*` if libdes compatibility is desired. If OpenSSL 0.9.6c compatibility is desired, the `des_*` symbols will be mapped to `DES_*`, with one exception. Since we provide two compatibility mappings, the user needs to define the macro OPENSSL_DES_LIBDES_COMPATIBILITY if libdes compatibility is desired. The default (i.e., when that macro isn't defined) is OpenSSL 0.9.6c compatibility. There are also macros that enable and disable the support of old des functions altogether. Those are OPENSSL_ENABLE_OLD_DES_SUPPORT and OPENSSL_DISABLE_OLD_DES_SUPPORT. If none or both of those are defined, the default will apply: to support the old des routines. In either case, one must include openssl/des.h to get the correct definitions. Do not try to just include openssl/des_old.h, that won't work. NOTE: This is a major break of an old API into a new one. Software authors are encouraged to switch to the `DES_` style functions. Some time in the future, des_old.h and the libdes compatibility functions will be disable (i.e. OPENSSL_DISABLE_OLD_DES_SUPPORT will be the default), and then completely removed. *Richard Levitte* * Test for certificates which contain unsupported critical extensions. If such a certificate is found during a verify operation it is rejected by default: this behaviour can be overridden by either handling the new error X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION or by setting the verify flag X509_V_FLAG_IGNORE_CRITICAL. A new function X509_supported_extension() has also been added which returns 1 if a particular extension is supported. *Steve Henson* * Modify the behaviour of EVP cipher functions in similar way to digests to retain compatibility with existing code. *Steve Henson* * Modify the behaviour of EVP_DigestInit() and EVP_DigestFinal() to retain compatibility with existing code. In particular the 'ctx' parameter does not have to be to be initialized before the call to EVP_DigestInit() and it is tidied up after a call to EVP_DigestFinal(). New function EVP_DigestFinal_ex() which does not tidy up the ctx. Similarly function EVP_MD_CTX_copy() changed to not require the destination to be initialized valid and new function EVP_MD_CTX_copy_ex() added which requires the destination to be valid. Modify all the OpenSSL digest calls to use EVP_DigestInit_ex(), EVP_DigestFinal_ex() and EVP_MD_CTX_copy_ex(). *Steve Henson* * Change ssl3_get_message (ssl/s3_both.c) and the functions using it so that complete 'Handshake' protocol structures are kept in memory instead of overwriting 'msg_type' and 'length' with 'body' data. *Bodo Moeller* * Add an implementation of SSL_add_dir_cert_subjects_to_stack for Win32. *Massimo Santin via Richard Levitte* * Major restructuring to the underlying ENGINE code. This includes reduction of linker bloat, separation of pure "ENGINE" manipulation (initialisation, etc) from functionality dealing with implementations of specific crypto interfaces. This change also introduces integrated support for symmetric ciphers and digest implementations - so ENGINEs can now accelerate these by providing EVP_CIPHER and EVP_MD implementations of their own. This is detailed in [crypto/engine/README.md](crypto/engine/README.md) as it couldn't be adequately described here. However, there are a few API changes worth noting - some RSA, DSA, DH, and RAND functions that were changed in the original introduction of ENGINE code have now reverted back - the hooking from this code to ENGINE is now a good deal more passive and at run-time, operations deal directly with RSA_METHODs, DSA_METHODs (etc) as they did before, rather than dereferencing through an ENGINE pointer any more. Also, the ENGINE functions dealing with `BN_MOD_EXP[_CRT]` handlers have been removed - they were not being used by the framework as there is no concept of a BIGNUM_METHOD and they could not be generalised to the new 'ENGINE_TABLE' mechanism that underlies the new code. Similarly, ENGINE_cpy() has been removed as it cannot be consistently defined in the new code. *Geoff Thorpe* * Change ASN1_GENERALIZEDTIME_check() to allow fractional seconds. *Steve Henson* * Change mkdef.pl to sort symbols that get the same entry number, and make sure the automatically generated functions `ERR_load_*` become part of libeay.num as well. *Richard Levitte* * New function SSL_renegotiate_pending(). This returns true once renegotiation has been requested (either SSL_renegotiate() call or HelloRequest/ClientHello received from the peer) and becomes false once a handshake has been completed. (For servers, SSL_renegotiate() followed by SSL_do_handshake() sends a HelloRequest, but does not ensure that a handshake takes place. SSL_renegotiate_pending() is useful for checking if the client has followed the request.) *Bodo Moeller* * New SSL option SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION. By default, clients may request session resumption even during renegotiation (if session ID contexts permit); with this option, session resumption is possible only in the first handshake. SSL_OP_ALL is now 0x00000FFFL instead of 0x000FFFFFL. This makes more bits available for options that should not be part of SSL_OP_ALL (such as SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION). *Bodo Moeller* * Add some demos for certificate and certificate request creation. *Steve Henson* * Make maximum certificate chain size accepted from the peer application settable (`SSL*_get/set_max_cert_list()`), as proposed by "Douglas E. Engert" . *Lutz Jaenicke* * Add support for shared libraries for Unixware-7 (Boyd Lynn Gerber ). *Lutz Jaenicke* * Add a "destroy" handler to ENGINEs that allows structural cleanup to be done prior to destruction. Use this to unload error strings from ENGINEs that load their own error strings. NB: This adds two new API functions to "get" and "set" this destroy handler in an ENGINE. *Geoff Thorpe* * Alter all existing ENGINE implementations (except "openssl" and "openbsd") to dynamically instantiate their own error strings. This makes them more flexible to be built both as statically-linked ENGINEs and self-contained shared-libraries loadable via the "dynamic" ENGINE. Also, add stub code to each that makes building them as self-contained shared-libraries easier (see [README-Engine.md](README-Engine.md)). *Geoff Thorpe* * Add a "dynamic" ENGINE that provides a mechanism for binding ENGINE implementations into applications that are completely implemented in self-contained shared-libraries. The "dynamic" ENGINE exposes control commands that can be used to configure what shared-library to load and to control aspects of the way it is handled. Also, made an update to the [README-Engine.md](README-Engine.md) file that brings its information up-to-date and provides some information and instructions on the "dynamic" ENGINE (ie. how to use it, how to build "dynamic"-loadable ENGINEs, etc). *Geoff Thorpe* * Make it possible to unload ranges of ERR strings with a new "ERR_unload_strings" function. *Geoff Thorpe* * Add a copy() function to EVP_MD. *Ben Laurie* * Make EVP_MD routines take a context pointer instead of just the md_data void pointer. *Ben Laurie* * Add flags to EVP_MD and EVP_MD_CTX. EVP_MD_FLAG_ONESHOT indicates that the digest can only process a single chunk of data (typically because it is provided by a piece of hardware). EVP_MD_CTX_FLAG_ONESHOT indicates that the application is only going to provide a single chunk of data, and hence the framework needn't accumulate the data for oneshot drivers. *Ben Laurie* * As with "ERR", make it possible to replace the underlying "ex_data" functions. This change also alters the storage and management of global ex_data state - it's now all inside ex_data.c and all "class" code (eg. RSA, BIO, SSL_CTX, etc) no longer stores its own STACKS and per-class index counters. The API functions that use this state have been changed to take a "class_index" rather than pointers to the class's local STACK and counter, and there is now an API function to dynamically create new classes. This centralisation allows us to (a) plug a lot of the thread-safety problems that existed, and (b) makes it possible to clean up all allocated state using "CRYPTO_cleanup_all_ex_data()". W.r.t. (b) such data would previously have always leaked in application code and workarounds were in place to make the memory debugging turn a blind eye to it. Application code that doesn't use this new function will still leak as before, but their memory debugging output will announce it now rather than letting it slide. Besides the addition of CRYPTO_cleanup_all_ex_data(), another API change induced by the "ex_data" overhaul is that X509_STORE_CTX_init() now has a return value to indicate success or failure. *Geoff Thorpe* * Make it possible to replace the underlying "ERR" functions such that the global state (2 LHASH tables and 2 locks) is only used by the "default" implementation. This change also adds two functions to "get" and "set" the implementation prior to it being automatically set the first time any other ERR function takes place. Ie. an application can call "get", pass the return value to a module it has just loaded, and that module can call its own "set" function using that value. This means the module's "ERR" operations will use (and modify) the error state in the application and not in its own statically linked copy of OpenSSL code. *Geoff Thorpe* * Give DH, DSA, and RSA types their own `*_up_ref()` function to increment reference counts. This performs normal REF_PRINT/REF_CHECK macros on the operation, and provides a more encapsulated way for external code (crypto/evp/ and ssl/) to do this. Also changed the evp and ssl code to use these functions rather than manually incrementing the counts. Also rename "DSO_up()" function to more descriptive "DSO_up_ref()". *Geoff Thorpe* * Add EVP test program. *Ben Laurie* * Add symmetric cipher support to ENGINE. Expect the API to change! *Ben Laurie* * New CRL functions: X509_CRL_set_version(), X509_CRL_set_issuer_name() X509_CRL_set_lastUpdate(), X509_CRL_set_nextUpdate(), X509_CRL_sort(), X509_REVOKED_set_serialNumber(), and X509_REVOKED_set_revocationDate(). These allow a CRL to be built without having to access X509_CRL fields directly. Modify 'ca' application to use new functions. *Steve Henson* * Move SSL_OP_TLS_ROLLBACK_BUG out of the SSL_OP_ALL list of recommended bug workarounds. Rollback attack detection is a security feature. The problem will only arise on OpenSSL servers when TLSv1 is not available (sslv3_server_method() or SSL_OP_NO_TLSv1). Software authors not wanting to support TLSv1 will have special reasons for their choice and can explicitly enable this option. *Bodo Moeller, Lutz Jaenicke* * Rationalise EVP so it can be extended: don't include a union of cipher/digest structures, add init/cleanup functions for EVP_MD_CTX (similar to those existing for EVP_CIPHER_CTX). Usage example: EVP_MD_CTX md; EVP_MD_CTX_init(&md); /* new function call */ EVP_DigestInit(&md, EVP_sha1()); EVP_DigestUpdate(&md, in, len); EVP_DigestFinal(&md, out, NULL); EVP_MD_CTX_cleanup(&md); /* new function call */ *Ben Laurie* * Make DES key schedule conform to the usual scheme, as well as correcting its structure. This means that calls to DES functions now have to pass a pointer to a des_key_schedule instead of a plain des_key_schedule (which was actually always a pointer anyway): E.g., des_key_schedule ks; des_set_key_checked(..., &ks); des_ncbc_encrypt(..., &ks, ...); (Note that a later change renames 'des_...' into 'DES_...'.) *Ben Laurie* * Initial reduction of linker bloat: the use of some functions, such as PEM causes large amounts of unused functions to be linked in due to poor organisation. For example pem_all.c contains every PEM function which has a knock on effect of linking in large amounts of (unused) ASN1 code. Grouping together similar functions and splitting unrelated functions prevents this. *Steve Henson* * Cleanup of EVP macros. *Ben Laurie* * Change historical references to `{NID,SN,LN}_des_ede` and ede3 to add the correct `_ecb suffix`. *Ben Laurie* * Add initial OCSP responder support to ocsp application. The revocation information is handled using the text based index use by the ca application. The responder can either handle requests generated internally, supplied in files (for example via a CGI script) or using an internal minimal server. *Steve Henson* * Add configuration choices to get zlib compression for TLS. *Richard Levitte* * Changes to Kerberos SSL for RFC 2712 compliance: 1. Implemented real KerberosWrapper, instead of just using KRB5 AP_REQ message. [Thanks to Simon Wilkinson ] 2. Implemented optional authenticator field of KerberosWrapper. Added openssl-style ASN.1 macros for Kerberos ticket, ap_req, and authenticator structs; see crypto/krb5/. Generalized Kerberos calls to support multiple Kerberos libraries. *Vern Staats , Jeffrey Altman via Richard Levitte* * Cause 'openssl speed' to use fully hard-coded DSA keys as it already does with RSA. testdsa.h now has 'priv_key/pub_key' values for each of the key sizes rather than having just parameters (and 'speed' generating keys each time). *Geoff Thorpe* * Speed up EVP routines. Before: crypt pe 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes s-cbc 4408.85k 5560.51k 5778.46k 5862.20k 5825.16k s-cbc 4389.55k 5571.17k 5792.23k 5846.91k 5832.11k s-cbc 4394.32k 5575.92k 5807.44k 5848.37k 5841.30k crypt s-cbc 3482.66k 5069.49k 5496.39k 5614.16k 5639.28k s-cbc 3480.74k 5068.76k 5510.34k 5609.87k 5635.52k s-cbc 3483.72k 5067.62k 5504.60k 5708.01k 5724.80k After: crypt s-cbc 4660.16k 5650.19k 5807.19k 5827.13k 5783.32k crypt s-cbc 3624.96k 5258.21k 5530.91k 5624.30k 5628.26k *Ben Laurie* * Added the OS2-EMX target. *"Brian Havard" and Richard Levitte* * Rewrite commands to use `NCONF` routines instead of the old `CONF`. New functions to support `NCONF` routines in extension code. New function `CONF_set_nconf()` to allow functions which take an `NCONF` to also handle the old `LHASH` structure: this means that the old `CONF` compatible routines can be retained (in particular w.rt. extensions) without having to duplicate the code. New function `X509V3_add_ext_nconf_sk()` to add extensions to a stack. *Steve Henson* * Enhance the general user interface with mechanisms for inner control and with possibilities to have yes/no kind of prompts. *Richard Levitte* * Change all calls to low-level digest routines in the library and applications to use EVP. Add missing calls to HMAC_cleanup() and don't assume HMAC_CTX can be copied using memcpy(). *Verdon Walker , Steve Henson* * Add the possibility to control engines through control names but with arbitrary arguments instead of just a string. Change the key loaders to take a UI_METHOD instead of a callback function pointer. NOTE: this breaks binary compatibility with earlier versions of OpenSSL [engine]. Adapt the nCipher code for these new conditions and add a card insertion callback. *Richard Levitte* * Enhance the general user interface with mechanisms to better support dialog box interfaces, application-defined prompts, the possibility to use defaults (for example default passwords from somewhere else) and interrupts/cancellations. *Richard Levitte* * Tidy up PKCS#12 attribute handling. Add support for the CSP name attribute in PKCS#12 files, add new -CSP option to pkcs12 utility. *Steve Henson* * Fix a memory leak in 'sk_dup()' in the case reallocation fails. (Also tidy up some unnecessarily weird code in 'sk_new()'). *Geoff, reported by Diego Tartara * * Change the key loading routines for ENGINEs to use the same kind callback (pem_password_cb) as all other routines that need this kind of callback. *Richard Levitte* * Increase ENTROPY_NEEDED to 32 bytes, as Rijndael can operate with 256 bit (=32 byte) keys. Of course seeding with more entropy bytes than this minimum value is recommended. *Lutz Jaenicke* * New random seeder for OpenVMS, using the system process statistics that are easily reachable. *Richard Levitte* * Windows apparently can't transparently handle global variables defined in DLLs. Initialisations such as: const ASN1_ITEM *it = &ASN1_INTEGER_it; won't compile. This is used by the any applications that need to declare their own ASN1 modules. This was fixed by adding the option EXPORT_VAR_AS_FN to all Win32 platforms, although this isn't strictly needed for static libraries under Win32. *Steve Henson* * New functions X509_PURPOSE_set() and X509_TRUST_set() to handle setting of purpose and trust fields. New X509_STORE trust and purpose functions and tidy up setting in other SSL functions. *Steve Henson* * Add copies of X509_STORE_CTX fields and callbacks to X509_STORE structure. These are inherited by X509_STORE_CTX when it is initialised. This allows various defaults to be set in the X509_STORE structure (such as flags for CRL checking and custom purpose or trust settings) for functions which only use X509_STORE_CTX internally such as S/MIME. Modify X509_STORE_CTX_purpose_inherit() so it only sets purposes and trust settings if they are not set in X509_STORE. This allows X509_STORE purposes and trust (in S/MIME for example) to override any set by default. Add command line options for CRL checking to smime, s_client and s_server applications. *Steve Henson* * Initial CRL based revocation checking. If the CRL checking flag(s) are set then the CRL is looked up in the X509_STORE structure and its validity and signature checked, then if the certificate is found in the CRL the verify fails with a revoked error. Various new CRL related callbacks added to X509_STORE_CTX structure. Command line options added to 'verify' application to support this. This needs some additional work, such as being able to handle multiple CRLs with different times, extension based lookup (rather than just by subject name) and ultimately more complete V2 CRL extension handling. *Steve Henson* * Add a general user interface API (crypto/ui/). This is designed to replace things like des_read_password and friends (backward compatibility functions using this new API are provided). The purpose is to remove prompting functions from the DES code section as well as provide for prompting through dialog boxes in a window system and the like. *Richard Levitte* * Add "ex_data" support to ENGINE so implementations can add state at a per-structure level rather than having to store it globally. *Geoff* * Make it possible for ENGINE structures to be copied when retrieved by ENGINE_by_id() if the ENGINE specifies a new flag: ENGINE_FLAGS_BY_ID_COPY. This causes the "original" ENGINE structure to act like a template, analogous to the RSA vs. RSA_METHOD type of separation. Because of this operational state can be localised to each ENGINE structure, despite the fact they all share the same "methods". New ENGINE structures returned in this case have no functional references and the return value is the single structural reference. This matches the single structural reference returned by ENGINE_by_id() normally, when it is incremented on the pre-existing ENGINE structure. *Geoff* * Fix ASN1 decoder when decoding type ANY and V_ASN1_OTHER: since this needs to match any other type at all we need to manually clear the tag cache. *Steve Henson* * Changes to the "openssl engine" utility to include; - verbosity levels ('-v', '-vv', and '-vvv') that provide information about an ENGINE's available control commands. - executing control commands from command line arguments using the '-pre' and '-post' switches. '-post' is only used if '-t' is specified and the ENGINE is successfully initialised. The syntax for the individual commands are colon-separated, for example; openssl engine chil -pre FORK_CHECK:0 -pre SO_PATH:/lib/test.so *Geoff* * New dynamic control command support for ENGINEs. ENGINEs can now declare their own commands (numbers), names (strings), descriptions, and input types for run-time discovery by calling applications. A subset of these commands are implicitly classed as "executable" depending on their input type, and only these can be invoked through the new string-based API function ENGINE_ctrl_cmd_string(). (Eg. this can be based on user input, config files, etc). The distinction is that "executable" commands cannot return anything other than a boolean result and can only support numeric or string input, whereas some discoverable commands may only be for direct use through ENGINE_ctrl(), eg. supporting the exchange of binary data, function pointers, or other custom uses. The "executable" commands are to support parameterisations of ENGINE behaviour that can be unambiguously defined by ENGINEs and used consistently across any OpenSSL-based application. Commands have been added to all the existing hardware-supporting ENGINEs, noticeably "SO_PATH" to allow control over shared-library paths without source code alterations. *Geoff* * Changed all ENGINE implementations to dynamically allocate their ENGINEs rather than declaring them statically. Apart from this being necessary with the removal of the ENGINE_FLAGS_MALLOCED distinction, this also allows the implementations to compile without using the internal engine_int.h header. *Geoff* * Minor adjustment to "rand" code. RAND_get_rand_method() now returns a 'const' value. Any code that should be able to modify a RAND_METHOD should already have non-const pointers to it (ie. they should only modify their own ones). *Geoff* * Made a variety of little tweaks to the ENGINE code. - "atalla" and "ubsec" string definitions were moved from header files to C code. "nuron" string definitions were placed in variables rather than hard-coded - allowing parameterisation of these values later on via ctrl() commands. - Removed unused "#if 0"'d code. - Fixed engine list iteration code so it uses ENGINE_free() to release structural references. - Constified the RAND_METHOD element of ENGINE structures. - Constified various get/set functions as appropriate and added missing functions (including a catch-all ENGINE_cpy that duplicates all ENGINE values onto a new ENGINE except reference counts/state). - Removed NULL parameter checks in get/set functions. Setting a method or function to NULL is a way of cancelling out a previously set value. Passing a NULL ENGINE parameter is just plain stupid anyway and doesn't justify the extra error symbols and code. - Deprecate the ENGINE_FLAGS_MALLOCED define and move the area for flags from engine_int.h to engine.h. - Changed prototypes for ENGINE handler functions (init(), finish(), ctrl(), key-load functions, etc) to take an (ENGINE*) parameter. *Geoff* * Implement binary inversion algorithm for BN_mod_inverse in addition to the algorithm using long division. The binary algorithm can be used only if the modulus is odd. On 32-bit systems, it is faster only for relatively small moduli (roughly 20-30% for 128-bit moduli, roughly 5-15% for 256-bit moduli), so we use it only for moduli up to 450 bits. In 64-bit environments, the binary algorithm appears to be advantageous for much longer moduli; here we use it for moduli up to 2048 bits. *Bodo Moeller* * Rewrite CHOICE field setting in ASN1_item_ex_d2i(). The old code could not support the combine flag in choice fields. *Steve Henson* * Add a 'copy_extensions' option to the 'ca' utility. This copies extensions from a certificate request to the certificate. *Steve Henson* * Allow multiple 'certopt' and 'nameopt' options to be separated by commas. Add 'namopt' and 'certopt' options to the 'ca' config file: this allows the display of the certificate about to be signed to be customised, to allow certain fields to be included or excluded and extension details. The old system didn't display multicharacter strings properly, omitted fields not in the policy and couldn't display additional details such as extensions. *Steve Henson* * Function EC_POINTs_mul for multiple scalar multiplication of an arbitrary number of elliptic curve points \sum scalars[i]*points[i], optionally including the generator defined for the EC_GROUP: scalar*generator + \sum scalars[i]*points[i]. EC_POINT_mul is a simple wrapper function for the typical case that the point list has just one item (besides the optional generator). *Bodo Moeller* * First EC_METHODs for curves over GF(p): EC_GFp_simple_method() uses the basic BN_mod_mul and BN_mod_sqr operations and provides various method functions that can also operate with faster implementations of modular arithmetic. EC_GFp_mont_method() reuses most functions that are part of EC_GFp_simple_method, but uses Montgomery arithmetic. *Bodo Moeller; point addition and point doubling implementation directly derived from source code provided by Lenka Fibikova * * Framework for elliptic curves (crypto/ec/ec.h, crypto/ec/ec_lcl.h, crypto/ec/ec_lib.c): Curves are EC_GROUP objects (with an optional group generator) based on EC_METHODs that are built into the library. Points are EC_POINT objects based on EC_GROUP objects. Most of the framework would be able to handle curves over arbitrary finite fields, but as there are no obvious types for fields other than GF(p), some functions are limited to that for now. *Bodo Moeller* * Add the -HTTP option to s_server. It is similar to -WWW, but requires that the file contains a complete HTTP response. *Richard Levitte* * Add the ec directory to mkdef.pl and mkfiles.pl. In mkdef.pl change the def and num file printf format specifier from "%-40sXXX" to "%-39s XXX". The latter will always guarantee a space after the field while the former will cause them to run together if the field is 40 of more characters long. *Steve Henson* * Constify the cipher and digest 'method' functions and structures and modify related functions to take constant EVP_MD and EVP_CIPHER pointers. *Steve Henson* * Hide BN_CTX structure details in bn_lcl.h instead of publishing them in . Also further increase BN_CTX_NUM to 32. *Bodo Moeller* * Modify `EVP_Digest*()` routines so they now return values. Although the internal software routines can never fail additional hardware versions might. *Steve Henson* * Clean up crypto/err/err.h and change some error codes to avoid conflicts: Previously ERR_R_FATAL was too small and coincided with ERR_LIB_PKCS7 (= ERR_R_PKCS7_LIB); it is now 64 instead of 32. ASN1 error codes ERR_R_NESTED_ASN1_ERROR ... ERR_R_MISSING_ASN1_EOS were 4 .. 9, conflicting with ERR_LIB_RSA (= ERR_R_RSA_LIB) ... ERR_LIB_PEM (= ERR_R_PEM_LIB). They are now 58 .. 63 (i.e., just below ERR_R_FATAL). Add new error code 'ERR_R_INTERNAL_ERROR'. *Bodo Moeller* * Don't overuse locks in crypto/err/err.c: For data retrieval, CRYPTO_r_lock suffices. *Bodo Moeller* * New option '-subj arg' for 'openssl req' and 'openssl ca'. This sets the subject name for a new request or supersedes the subject name in a given request. Formats that can be parsed are 'CN=Some Name, OU=myOU, C=IT' and 'CN=Some Name/OU=myOU/C=IT'. Add options '-batch' and '-verbose' to 'openssl req'. *Massimiliano Pala * * Introduce the possibility to access global variables through functions on platform were that's the best way to handle exporting global variables in shared libraries. To enable this functionality, one must configure with "EXPORT_VAR_AS_FN" or defined the C macro "OPENSSL_EXPORT_VAR_AS_FUNCTION" in crypto/opensslconf.h (the latter is normally done by Configure or something similar). To implement a global variable, use the macro OPENSSL_IMPLEMENT_GLOBAL in the source file (foo.c) like this: OPENSSL_IMPLEMENT_GLOBAL(int,foo)=1; OPENSSL_IMPLEMENT_GLOBAL(double,bar); To declare a global variable, use the macros OPENSSL_DECLARE_GLOBAL and OPENSSL_GLOBAL_REF in the header file (foo.h) like this: OPENSSL_DECLARE_GLOBAL(int,foo); #define foo OPENSSL_GLOBAL_REF(foo) OPENSSL_DECLARE_GLOBAL(double,bar); #define bar OPENSSL_GLOBAL_REF(bar) The #defines are very important, and therefore so is including the header file everywhere where the defined globals are used. The macro OPENSSL_EXPORT_VAR_AS_FUNCTION also affects the definition of ASN.1 items, but that structure is a bit different. The largest change is in util/mkdef.pl which has been enhanced with better and easier to understand logic to choose which symbols should go into the Windows .def files as well as a number of fixes and code cleanup (among others, algorithm keywords are now sorted lexicographically to avoid constant rewrites). *Richard Levitte* * In BN_div() keep a copy of the sign of 'num' before writing the result to 'rm' because if rm==num the value will be overwritten and produce the wrong result if 'num' is negative: this caused problems with BN_mod() and BN_nnmod(). *Steve Henson* * Function OCSP_request_verify(). This checks the signature on an OCSP request and verifies the signer certificate. The signer certificate is just checked for a generic purpose and OCSP request trust settings. *Steve Henson* * Add OCSP_check_validity() function to check the validity of OCSP responses. OCSP responses are prepared in real time and may only be a few seconds old. Simply checking that the current time lies between thisUpdate and nextUpdate max reject otherwise valid responses caused by either OCSP responder or client clock inaccuracy. Instead we allow thisUpdate and nextUpdate to fall within a certain period of the current time. The age of the response can also optionally be checked. Two new options -validity_period and -status_age added to ocsp utility. *Steve Henson* * If signature or public key algorithm is unrecognized print out its OID rather that just UNKNOWN. *Steve Henson* * Change OCSP_cert_to_id() to tolerate a NULL subject certificate and OCSP_cert_id_new() a NULL serialNumber. This allows a partial certificate ID to be generated from the issuer certificate alone which can then be passed to OCSP_id_issuer_cmp(). *Steve Henson* * New compilation option ASN1_ITEM_FUNCTIONS. This causes the new ASN1 modules to export functions returning ASN1_ITEM pointers instead of the ASN1_ITEM structures themselves. This adds several new macros which allow the underlying ASN1 function/structure to be accessed transparently. As a result code should not use ASN1_ITEM references directly (such as &X509_it) but instead use the relevant macros (such as ASN1_ITEM_rptr(X509)). This option is to allow use of the new ASN1 code on platforms where exporting structures is problematical (for example in shared libraries) but exporting functions returning pointers to structures is not. *Steve Henson* * Add support for overriding the generation of SSL/TLS session IDs. These callbacks can be registered either in an SSL_CTX or per SSL. The purpose of this is to allow applications to control, if they wish, the arbitrary values chosen for use as session IDs, particularly as it can be useful for session caching in multiple-server environments. A command-line switch for testing this (and any client code that wishes to use such a feature) has been added to "s_server". *Geoff Thorpe, Lutz Jaenicke* * Modify mkdef.pl to recognise and parse preprocessor conditionals of the form `#if defined(...) || defined(...) || ...` and `#if !defined(...) && !defined(...) && ...`. This also avoids the growing number of special cases it was previously handling. *Richard Levitte* * Make all configuration macros available for application by making sure they are available in opensslconf.h, by giving them names starting with `OPENSSL_` to avoid conflicts with other packages and by making sure e_os2.h will cover all platform-specific cases together with opensslconf.h. Additionally, it is now possible to define configuration/platform- specific names (called "system identities"). In the C code, these are prefixed with `OPENSSL_SYSNAME_`. e_os2.h will create another macro with the name beginning with `OPENSSL_SYS_`, which is determined from `OPENSSL_SYSNAME_*` or compiler-specific macros depending on what is available. *Richard Levitte* * New option -set_serial to 'req' and 'x509' this allows the serial number to use to be specified on the command line. Previously self signed certificates were hard coded with serial number 0 and the CA options of 'x509' had to use a serial number in a file which was auto incremented. *Steve Henson* * New options to 'ca' utility to support V2 CRL entry extensions. Currently CRL reason, invalidity date and hold instruction are supported. Add new CRL extensions to V3 code and some new objects. *Steve Henson* * New function EVP_CIPHER_CTX_set_padding() this is used to disable standard block padding (aka PKCS#5 padding) in the EVP API, which was previously mandatory. This means that the data is not padded in any way and so the total length much be a multiple of the block size, otherwise an error occurs. *Steve Henson* * Initial (incomplete) OCSP SSL support. *Steve Henson* * New function OCSP_parse_url(). This splits up a URL into its host, port and path components: primarily to parse OCSP URLs. New -url option to ocsp utility. *Steve Henson* * New nonce behavior. The return value of OCSP_check_nonce() now reflects the various checks performed. Applications can decide whether to tolerate certain situations such as an absent nonce in a response when one was present in a request: the ocsp application just prints out a warning. New function OCSP_add1_basic_nonce() this is to allow responders to include a nonce in a response even if the request is nonce-less. *Steve Henson* * Disable stdin buffering in `load_cert()` (`apps/apps.c`) so that no certs are skipped when using openssl x509 multiple times on a single input file, e.g. `(openssl x509 -out cert1; openssl x509 -out cert2) * * New OCSP verify flag OCSP_TRUSTOTHER. When set the "other" certificates passed by the function are trusted implicitly. If any of them signed the response then it is assumed to be valid and is not verified. *Steve Henson* * In PKCS7_set_type() initialise content_type in PKCS7_ENC_CONTENT to data. This was previously part of the PKCS7 ASN1 code. This was causing problems with OpenSSL created PKCS#12 and PKCS#7 structures. *Steve Henson, reported by Kenneth R. Robinette * * Add CRYPTO_push_info() and CRYPTO_pop_info() calls to new ASN1 routines: without these tracing memory leaks is very painful. Fix leaks in PKCS12 and PKCS7 routines. *Steve Henson* * Make X509_time_adj() cope with the new behaviour of ASN1_TIME_new(). Previously it initialised the 'type' argument to V_ASN1_UTCTIME which effectively meant GeneralizedTime would never be used. Now it is initialised to -1 but X509_time_adj() now has to check the value and use ASN1_TIME_set() if the value is not V_ASN1_UTCTIME or V_ASN1_GENERALIZEDTIME, without this it always uses GeneralizedTime. *Steve Henson, reported by Kenneth R. Robinette * * Fixes to BN_to_ASN1_INTEGER when bn is zero. This would previously result in a zero length in the ASN1_INTEGER structure which was not consistent with the structure when d2i_ASN1_INTEGER() was used and would cause ASN1_INTEGER_cmp() to fail. Enhance s2i_ASN1_INTEGER() to cope with hex and negative integers. Fix bug in i2a_ASN1_INTEGER() where it did not print out a minus for negative ASN1_INTEGER. *Steve Henson* * Add summary printout to ocsp utility. The various functions which convert status values to strings have been renamed to: OCSP_response_status_str(), OCSP_cert_status_str() and OCSP_crl_reason_str() and are no longer static. New options to verify nonce values and to disable verification. OCSP response printout format cleaned up. *Steve Henson* * Add additional OCSP certificate checks. These are those specified in RFC2560. This consists of two separate checks: the CA of the certificate being checked must either be the OCSP signer certificate or the issuer of the OCSP signer certificate. In the latter case the OCSP signer certificate must contain the OCSP signing extended key usage. This check is performed by attempting to match the OCSP signer or the OCSP signer CA to the issuerNameHash and issuerKeyHash in the OCSP_CERTID structures of the response. *Steve Henson* * Initial OCSP certificate verification added to OCSP_basic_verify() and related routines. This uses the standard OpenSSL certificate verify routines to perform initial checks (just CA validity) and to obtain the certificate chain. Then additional checks will be performed on the chain. Currently the root CA is checked to see if it is explicitly trusted for OCSP signing. This is used to set a root CA as a global signing root: that is any certificate that chains to that CA is an acceptable OCSP signing certificate. *Steve Henson* * New '-extfile ...' option to 'openssl ca' for reading X.509v3 extensions from a separate configuration file. As when reading extensions from the main configuration file, the '-extensions ...' option may be used for specifying the section to use. *Massimiliano Pala * * New OCSP utility. Allows OCSP requests to be generated or read. The request can be sent to a responder and the output parsed, outputted or printed in text form. Not complete yet: still needs to check the OCSP response validity. *Steve Henson* * New subcommands for 'openssl ca': `openssl ca -status ` prints the status of the cert with the given serial number (according to the index file). `openssl ca -updatedb` updates the expiry status of certificates in the index file. *Massimiliano Pala * * New '-newreq-nodes' command option to CA.pl. This is like '-newreq', but calls 'openssl req' with the '-nodes' option so that the resulting key is not encrypted. *Damien Miller * * New configuration for the GNU Hurd. *Jonathan Bartlett via Richard Levitte* * Initial code to implement OCSP basic response verify. This is currently incomplete. Currently just finds the signer's certificate and verifies the signature on the response. *Steve Henson* * New SSLeay_version code SSLEAY_DIR to determine the compiled-in value of OPENSSLDIR. This is available via the new '-d' option to 'openssl version', and is also included in 'openssl version -a'. *Bodo Moeller* * Allowing defining memory allocation callbacks that will be given file name and line number information in additional arguments (a `const char*` and an int). The basic functionality remains, as well as the original possibility to just replace malloc(), realloc() and free() by functions that do not know about these additional arguments. To register and find out the current settings for extended allocation functions, the following functions are provided: CRYPTO_set_mem_ex_functions CRYPTO_set_locked_mem_ex_functions CRYPTO_get_mem_ex_functions CRYPTO_get_locked_mem_ex_functions These work the same way as CRYPTO_set_mem_functions and friends. `CRYPTO_get_[locked_]mem_functions` now writes 0 where such an extended allocation function is enabled. Similarly, `CRYPTO_get_[locked_]mem_ex_functions` writes 0 where a conventional allocation function is enabled. *Richard Levitte, Bodo Moeller* * Finish off removing the remaining LHASH function pointer casts. There should no longer be any prototype-casting required when using the LHASH abstraction, and any casts that remain are "bugs". See the callback types and macros at the head of lhash.h for details (and "OBJ_cleanup" in crypto/objects/obj_dat.c as an example). *Geoff Thorpe* * Add automatic query of EGD sockets in RAND_poll() for the unix variant. If /dev/[u]random devices are not available or do not return enough entropy, EGD style sockets (served by EGD or PRNGD) will automatically be queried. The locations /var/run/egd-pool, /dev/egd-pool, /etc/egd-pool, and /etc/entropy will be queried once each in this sequence, querying stops when enough entropy was collected without querying more sockets. *Lutz Jaenicke* * Change the Unix RAND_poll() variant to be able to poll several random devices, as specified by DEVRANDOM, until a sufficient amount of data has been collected. We spend at most 10 ms on each file (select timeout) and read in non-blocking mode. DEVRANDOM now defaults to the list "/dev/urandom", "/dev/random", "/dev/srandom" (previously it was just the string "/dev/urandom"), so on typical platforms the 10 ms delay will never occur. Also separate out the Unix variant to its own file, rand_unix.c. For VMS, there's a currently-empty rand_vms.c. *Richard Levitte* * Move OCSP client related routines to ocsp_cl.c. These provide utility functions which an application needing to issue a request to an OCSP responder and analyse the response will typically need: as opposed to those which an OCSP responder itself would need which will be added later. OCSP_request_sign() signs an OCSP request with an API similar to PKCS7_sign(). OCSP_response_status() returns status of OCSP response. OCSP_response_get1_basic() extracts basic response from response. OCSP_resp_find_status(): finds and extracts status information from an OCSP_CERTID structure (which will be created when the request structure is built). These are built from lower level functions which work on OCSP_SINGLERESP structures but won't normally be used unless the application wishes to examine extensions in the OCSP response for example. Replace nonce routines with a pair of functions. OCSP_request_add1_nonce() adds a nonce value and optionally generates a random value. OCSP_check_nonce() checks the validity of the nonce in an OCSP response. *Steve Henson* * Change function OCSP_request_add() to OCSP_request_add0_id(). This doesn't copy the supplied OCSP_CERTID and avoids the need to free up the newly created id. Change return type to OCSP_ONEREQ to return the internal OCSP_ONEREQ structure. This can then be used to add extensions to the request. Deleted OCSP_request_new(), since most of its functionality is now in OCSP_REQUEST_new() (and the case insensitive name clash) apart from the ability to set the request name which will be added elsewhere. *Steve Henson* * Update OCSP API. Remove obsolete extensions argument from various functions. Extensions are now handled using the new OCSP extension code. New simple OCSP HTTP function which can be used to send requests and parse the response. *Steve Henson* * Fix the PKCS#7 (S/MIME) code to work with new ASN1. Two new ASN1_ITEM structures help with sign and verify. PKCS7_ATTR_SIGN uses the special reorder version of SET OF to sort the attributes and reorder them to match the encoded order. This resolves a long standing problem: a verify on a PKCS7 structure just after signing it used to fail because the attribute order did not match the encoded order. PKCS7_ATTR_VERIFY does not reorder the attributes: it uses the received order. This is necessary to tolerate some broken software that does not order SET OF. This is handled by encoding as a SEQUENCE OF but using implicit tagging (with UNIVERSAL class) to produce the required SET OF. *Steve Henson* * Have mk1mf.pl generate the macros OPENSSL_BUILD_SHLIBCRYPTO and OPENSSL_BUILD_SHLIBSSL and use them appropriately in the header files to get correct declarations of the ASN.1 item variables. *Richard Levitte* * Rewrite of PKCS#12 code to use new ASN1 functionality. Replace many PKCS#12 macros with real functions. Fix two unrelated ASN1 bugs: asn1_check_tlen() would sometimes attempt to use 'ctx' when it was NULL and ASN1_TYPE was not dereferenced properly in asn1_ex_c2i(). New ASN1 macro: DECLARE_ASN1_ITEM() which just declares the relevant ASN1_ITEM and no wrapper functions. *Steve Henson* * New functions or ASN1_item_d2i_fp() and ASN1_item_d2i_bio(). These replace the old function pointer based I/O routines. Change most of the `*_d2i_bio()` and `*_d2i_fp()` functions to use these. *Steve Henson* * Enhance mkdef.pl to be more accepting about spacing in C preprocessor lines, recognize more "algorithms" that can be deselected, and make it complain about algorithm deselection that isn't recognised. *Richard Levitte* * New ASN1 functions to handle dup, sign, verify, digest, pack and unpack operations in terms of ASN1_ITEM. Modify existing wrappers to use new functions. Add NO_ASN1_OLD which can be set to remove some old style ASN1 functions: this can be used to determine if old code will still work when these eventually go away. *Steve Henson* * New extension functions for OCSP structures, these follow the same conventions as certificates and CRLs. *Steve Henson* * New function X509V3_add1_i2d(). This automatically encodes and adds an extension. Its behaviour can be customised with various flags to append, replace or delete. Various wrappers added for certificates and CRLs. *Steve Henson* * Fix to avoid calling the underlying ASN1 print routine when an extension cannot be parsed. Correct a typo in the OCSP_SERVICELOC extension. Tidy up print OCSP format. *Steve Henson* * Make mkdef.pl parse some of the ASN1 macros and add appropriate entries for variables. *Steve Henson* * Add functionality to `apps/openssl.c` for detecting locking problems: As the program is single-threaded, all we have to do is register a locking callback using an array for storing which locks are currently held by the program. *Bodo Moeller* * Use a lock around the call to CRYPTO_get_ex_new_index() in SSL_get_ex_data_X509_STORE_idx(), which is used in ssl_verify_cert_chain() and thus can be called at any time during TLS/SSL handshakes so that thread-safety is essential. Unfortunately, the ex_data design is not at all suited for multi-threaded use, so it probably should be abolished. *Bodo Moeller* * Added Broadcom "ubsec" ENGINE to OpenSSL. *Broadcom, tweaked and integrated by Geoff Thorpe* * Move common extension printing code to new function X509V3_print_extensions(). Reorganise OCSP print routines and implement some needed OCSP ASN1 functions. Add OCSP extensions. *Steve Henson* * New function X509_signature_print() to remove duplication in some print routines. *Steve Henson* * Add a special meaning when SET OF and SEQUENCE OF flags are both set (this was treated exactly the same as SET OF previously). This is used to reorder the STACK representing the structure to match the encoding. This will be used to get round a problem where a PKCS7 structure which was signed could not be verified because the STACK order did not reflect the encoded order. *Steve Henson* * Reimplement the OCSP ASN1 module using the new code. *Steve Henson* * Update the X509V3 code to permit the use of an ASN1_ITEM structure for its ASN1 operations. The old style function pointers still exist for now but they will eventually go away. *Steve Henson* * Merge in replacement ASN1 code from the ASN1 branch. This almost completely replaces the old ASN1 functionality with a table driven encoder and decoder which interprets an ASN1_ITEM structure describing the ASN1 module. Compatibility with the existing ASN1 API (i2d,d2i) is largely maintained. Almost all of the old asn1_mac.h macro based ASN1 has also been converted to the new form. *Steve Henson* * Change BN_mod_exp_recp so that negative moduli are tolerated (the sign is ignored). Similarly, ignore the sign in BN_MONT_CTX_set so that BN_mod_exp_mont and BN_mod_exp_mont_word work for negative moduli. *Bodo Moeller* * Fix BN_uadd and BN_usub: Always return non-negative results instead of not touching the result's sign bit. *Bodo Moeller* * BN_div bugfix: If the result is 0, the sign (res->neg) must not be set. *Bodo Moeller* * Changed the LHASH code to use prototypes for callbacks, and created macros to declare and implement thin (optionally static) functions that provide type-safety and avoid function pointer casting for the type-specific callbacks. *Geoff Thorpe* * Added Kerberos Cipher Suites to be used with TLS, as written in RFC 2712. *Veers Staats , Jeffrey Altman , via Richard Levitte* * Reformat the FAQ so the different questions and answers can be divided in sections depending on the subject. *Richard Levitte* * Have the zlib compression code load ZLIB.DLL dynamically under Windows. *Richard Levitte* * New function BN_mod_sqrt for computing square roots modulo a prime (using the probabilistic Tonelli-Shanks algorithm unless p == 3 (mod 4) or p == 5 (mod 8), which are cases that can be handled deterministically). *Lenka Fibikova , Bodo Moeller* * Make BN_mod_inverse faster by explicitly handling small quotients in the Euclid loop. (Speed gain about 20% for small moduli [256 or 512 bits], about 30% for larger ones [1024 or 2048 bits].) *Bodo Moeller* * New function BN_kronecker. *Bodo Moeller* * Fix BN_gcd so that it works on negative inputs; the result is positive unless both parameters are zero. Previously something reasonably close to an infinite loop was possible because numbers could be growing instead of shrinking in the implementation of Euclid's algorithm. *Bodo Moeller* * Fix BN_is_word() and BN_is_one() macros to take into account the sign of the number in question. Fix BN_is_word(a,w) to work correctly for w == 0. The old BN_is_word(a,w) macro is now called BN_abs_is_word(a,w) because its test if the absolute value of 'a' equals 'w'. Note that BN_abs_is_word does *not* handle w == 0 reliably; it exists mostly for use in the implementations of BN_is_zero(), BN_is_one(), and BN_is_word(). *Bodo Moeller* * New function BN_swap. *Bodo Moeller* * Use BN_nnmod instead of BN_mod in crypto/bn/bn_exp.c so that the exponentiation functions are more likely to produce reasonable results on negative inputs. *Bodo Moeller* * Change BN_mod_mul so that the result is always non-negative. Previously, it could be negative if one of the factors was negative; I don't think anyone really wanted that behaviour. *Bodo Moeller* * Move `BN_mod_...` functions into new file `crypto/bn/bn_mod.c` (except for exponentiation, which stays in `crypto/bn/bn_exp.c`, and `BN_mod_mul_reciprocal`, which stays in `crypto/bn/bn_recp.c`) and add new functions: BN_nnmod BN_mod_sqr BN_mod_add BN_mod_add_quick BN_mod_sub BN_mod_sub_quick BN_mod_lshift1 BN_mod_lshift1_quick BN_mod_lshift BN_mod_lshift_quick These functions always generate non-negative results. `BN_nnmod` otherwise is `like BN_mod` (if `BN_mod` computes a remainder `r` such that `|m| < r < 0`, `BN_nnmod` will output `rem + |m|` instead). `BN_mod_XXX_quick(r, a, [b,] m)` generates the same result as `BN_mod_XXX(r, a, [b,] m, ctx)`, but requires that `a` [and `b`] be reduced modulo `m`. *Lenka Fibikova , Bodo Moeller* * In 'openssl passwd', verify passwords read from the terminal unless the '-salt' option is used (which usually means that verification would just waste user's time since the resulting hash is going to be compared with some given password hash) or the new '-noverify' option is used. This is an incompatible change, but it does not affect non-interactive use of 'openssl passwd' (passwords on the command line, '-stdin' option, '-in ...' option) and thus should not cause any problems. *Bodo Moeller* * Remove all references to RSAref, since there's no more need for it. *Richard Levitte* * Make DSO load along a path given through an environment variable (SHLIB_PATH) with shl_load(). *Richard Levitte* * Constify the ENGINE code as a result of BIGNUM constification. Also constify the RSA code and most things related to it. In a few places, most notable in the depth of the ASN.1 code, ugly casts back to non-const were required (to be solved at a later time) *Richard Levitte* * Make it so the openssl application has all engines loaded by default. *Richard Levitte* * Constify the BIGNUM routines a little more. *Richard Levitte* * Add the following functions: ENGINE_load_cswift() ENGINE_load_chil() ENGINE_load_atalla() ENGINE_load_nuron() ENGINE_load_builtin_engines() That way, an application can itself choose if external engines that are built-in in OpenSSL shall ever be used or not. The benefit is that applications won't have to be linked with libdl or other dso libraries unless it's really needed. Changed 'openssl engine' to load all engines on demand. Changed the engine header files to avoid the duplication of some declarations (they differed!). *Richard Levitte* * 'openssl engine' can now list capabilities. *Richard Levitte* * Better error reporting in 'openssl engine'. *Richard Levitte* * Never call load_dh_param(NULL) in s_server. *Bodo Moeller* * Add engine application. It can currently list engines by name and identity, and test if they are actually available. *Richard Levitte* * Improve RPM specification file by forcing symbolic linking and making sure the installed documentation is also owned by root.root. *Damien Miller * * Give the OpenSSL applications more possibilities to make use of keys (public as well as private) handled by engines. *Richard Levitte* * Add OCSP code that comes from CertCo. *Richard Levitte* * Add VMS support for the Rijndael code. *Richard Levitte* * Added untested support for Nuron crypto accelerator. *Ben Laurie* * Add support for external cryptographic devices. This code was previously distributed separately as the "engine" branch. *Geoff Thorpe, Richard Levitte* * Rework the filename-translation in the DSO code. It is now possible to have far greater control over how a "name" is turned into a filename depending on the operating environment and any oddities about the different shared library filenames on each system. *Geoff Thorpe* * Support threads on FreeBSD-elf in Configure. *Richard Levitte* * Fix for SHA1 assembly problem with MASM: it produces warnings about corrupt line number information when assembling with debugging information. This is caused by the overlapping of two sections. *Bernd Matthes , Steve Henson* * NCONF changes. NCONF_get_number() has no error checking at all. As a replacement, NCONF_get_number_e() is defined (`_e` for "error checking") and is promoted strongly. The old NCONF_get_number is kept around for binary backward compatibility. Make it possible for methods to load from something other than a BIO, by providing a function pointer that is given a name instead of a BIO. For example, this could be used to load configuration data from an LDAP server. *Richard Levitte* * Fix for non blocking accept BIOs. Added new I/O special reason BIO_RR_ACCEPT to cover this case. Previously use of accept BIOs with non blocking I/O was not possible because no retry code was implemented. Also added new SSL code SSL_WANT_ACCEPT to cover this case. *Steve Henson* * Added the beginnings of Rijndael support. *Ben Laurie* * Fix for bug in DirectoryString mask setting. Add support for X509_NAME_print_ex() in 'req' and X509_print_ex() function to allow certificate printing to more controllable, additional 'certopt' option to 'x509' to allow new printing options to be set. *Steve Henson* * Clean old EAY MD5 hack from e_os.h. *Richard Levitte* ### Changes between 0.9.6l and 0.9.6m [17 Mar 2004] * Fix null-pointer assignment in do_change_cipher_spec() revealed by using the Codenomicon TLS Test Tool ([CVE-2004-0079]) *Joe Orton, Steve Henson* ### Changes between 0.9.6k and 0.9.6l [04 Nov 2003] * Fix additional bug revealed by the NISCC test suite: Stop bug triggering large recursion when presented with certain ASN.1 tags ([CVE-2003-0851]) *Steve Henson* ### Changes between 0.9.6j and 0.9.6k [30 Sep 2003] * Fix various bugs revealed by running the NISCC test suite: Stop out of bounds reads in the ASN1 code when presented with invalid tags (CVE-2003-0543 and CVE-2003-0544). If verify callback ignores invalid public key errors don't try to check certificate signature with the NULL public key. *Steve Henson* * In ssl3_accept() (ssl/s3_srvr.c) only accept a client certificate if the server requested one: as stated in TLS 1.0 and SSL 3.0 specifications. *Steve Henson* * In ssl3_get_client_hello() (ssl/s3_srvr.c), tolerate additional extra data after the compression methods not only for TLS 1.0 but also for SSL 3.0 (as required by the specification). *Bodo Moeller; problem pointed out by Matthias Loepfe* * Change X509_certificate_type() to mark the key as exported/exportable when it's 512 *bits* long, not 512 bytes. *Richard Levitte* ### Changes between 0.9.6i and 0.9.6j [10 Apr 2003] * Countermeasure against the Klima-Pokorny-Rosa extension of Bleichbacher's attack on PKCS #1 v1.5 padding: treat a protocol version number mismatch like a decryption error in ssl3_get_client_key_exchange (ssl/s3_srvr.c). *Bodo Moeller* * Turn on RSA blinding by default in the default implementation to avoid a timing attack. Applications that don't want it can call RSA_blinding_off() or use the new flag RSA_FLAG_NO_BLINDING. They would be ill-advised to do so in most cases. *Ben Laurie, Steve Henson, Geoff Thorpe, Bodo Moeller* * Change RSA blinding code so that it works when the PRNG is not seeded (in this case, the secret RSA exponent is abused as an unpredictable seed -- if it is not unpredictable, there is no point in blinding anyway). Make RSA blinding thread-safe by remembering the creator's thread ID in rsa->blinding and having all other threads use local one-time blinding factors (this requires more computation than sharing rsa->blinding, but avoids excessive locking; and if an RSA object is not shared between threads, blinding will still be very fast). *Bodo Moeller* ### Changes between 0.9.6h and 0.9.6i [19 Feb 2003] * In ssl3_get_record (ssl/s3_pkt.c), minimize information leaked via timing by performing a MAC computation even if incorrect block cipher padding has been found. This is a countermeasure against active attacks where the attacker has to distinguish between bad padding and a MAC verification error. ([CVE-2003-0078]) *Bodo Moeller; problem pointed out by Brice Canvel (EPFL), Alain Hiltgen (UBS), Serge Vaudenay (EPFL), and Martin Vuagnoux (EPFL, Ilion)* ### Changes between 0.9.6g and 0.9.6h [5 Dec 2002] * New function OPENSSL_cleanse(), which is used to cleanse a section of memory from its contents. This is done with a counter that will place alternating values in each byte. This can be used to solve two issues: 1) the removal of calls to memset() by highly optimizing compilers, and 2) cleansing with other values than 0, since those can be read through on certain media, for example a swap space on disk. *Geoff Thorpe* * Bugfix: client side session caching did not work with external caching, because the session->cipher setting was not restored when reloading from the external cache. This problem was masked, when SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG (part of SSL_OP_ALL) was set. (Found by Steve Haslam .) *Lutz Jaenicke* * Fix client_certificate (ssl/s2_clnt.c): The permissible total length of the REQUEST-CERTIFICATE message is 18 .. 34, not 17 .. 33. *Zeev Lieber * * Undo an undocumented change introduced in 0.9.6e which caused repeated calls to OpenSSL_add_all_ciphers() and OpenSSL_add_all_digests() to be ignored, even after calling EVP_cleanup(). *Richard Levitte* * Change the default configuration reader to deal with last line not being properly terminated. *Richard Levitte* * Change X509_NAME_cmp() so it applies the special rules on handling DN values that are of type PrintableString, as well as RDNs of type emailAddress where the value has the type ia5String. *stefank@valicert.com via Richard Levitte* * Add a SSL_SESS_CACHE_NO_INTERNAL_STORE flag to take over half the job SSL_SESS_CACHE_NO_INTERNAL_LOOKUP was inconsistently doing, define a new flag (SSL_SESS_CACHE_NO_INTERNAL) to be the bitwise-OR of the two for use by the majority of applications wanting this behaviour, and update the docs. The documented behaviour and actual behaviour were inconsistent and had been changing anyway, so this is more a bug-fix than a behavioural change. *Geoff Thorpe, diagnosed by Nadav Har'El* * Don't impose a 16-byte length minimum on session IDs in ssl/s3_clnt.c (the SSL 3.0 and TLS 1.0 specifications allow any length up to 32 bytes). *Bodo Moeller* * Fix initialization code race conditions in SSLv23_method(), SSLv23_client_method(), SSLv23_server_method(), SSLv2_method(), SSLv2_client_method(), SSLv2_server_method(), SSLv3_method(), SSLv3_client_method(), SSLv3_server_method(), TLSv1_method(), TLSv1_client_method(), TLSv1_server_method(), ssl2_get_cipher_by_char(), ssl3_get_cipher_by_char(). *Patrick McCormick , Bodo Moeller* * Reorder cleanup sequence in SSL_CTX_free(): only remove the ex_data after the cached sessions are flushed, as the remove_cb() might use ex_data contents. Bug found by Sam Varshavchik (see [openssl.org #212]). *Geoff Thorpe, Lutz Jaenicke* * Fix typo in OBJ_txt2obj which incorrectly passed the content length, instead of the encoding length to d2i_ASN1_OBJECT. *Steve Henson* ### Changes between 0.9.6f and 0.9.6g [9 Aug 2002] * [In 0.9.6g-engine release:] Fix crypto/engine/vendor_defns/cswift.h for WIN32 (use `_stdcall`). *Lynn Gazis * ### Changes between 0.9.6e and 0.9.6f [8 Aug 2002] * Fix ASN1 checks. Check for overflow by comparing with LONG_MAX and get fix the header length calculation. *Florian Weimer , Alon Kantor (and others), Steve Henson* * Use proper error handling instead of 'assertions' in buffer overflow checks added in 0.9.6e. This prevents DoS (the assertions could call abort()). *Arne Ansper , Bodo Moeller* ### Changes between 0.9.6d and 0.9.6e [30 Jul 2002] * Add various sanity checks to asn1_get_length() to reject the ASN1 length bytes if they exceed sizeof(long), will appear negative or the content length exceeds the length of the supplied buffer. *Steve Henson, Adi Stav , James Yonan * * Fix cipher selection routines: ciphers without encryption had no flags for the cipher strength set and where therefore not handled correctly by the selection routines (PR #130). *Lutz Jaenicke* * Fix EVP_dsa_sha macro. *Nils Larsch* * New option SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS for disabling the SSL 3.0/TLS 1.0 CBC vulnerability countermeasure that was added in OpenSSL 0.9.6d. As the countermeasure turned out to be incompatible with some broken SSL implementations, the new option is part of SSL_OP_ALL. SSL_OP_ALL is usually employed when compatibility with weird SSL implementations is desired (e.g. '-bugs' option to 's_client' and 's_server'), so the new option is automatically set in many applications. *Bodo Moeller* * Changes in security patch: Changes marked "(CHATS)" were sponsored by the Defense Advanced Research Projects Agency (DARPA) and Air Force Research Laboratory, Air Force Materiel Command, USAF, under agreement number F30602-01-2-0537. * Add various sanity checks to asn1_get_length() to reject the ASN1 length bytes if they exceed sizeof(long), will appear negative or the content length exceeds the length of the supplied buffer. ([CVE-2002-0659]) *Steve Henson, Adi Stav , James Yonan * * Assertions for various potential buffer overflows, not known to happen in practice. *Ben Laurie (CHATS)* * Various temporary buffers to hold ASCII versions of integers were too small for 64 bit platforms. ([CVE-2002-0655]) *Matthew Byng-Maddick and Ben Laurie (CHATS)>* * Remote buffer overflow in SSL3 protocol - an attacker could supply an oversized session ID to a client. ([CVE-2002-0656]) *Ben Laurie (CHATS)* * Remote buffer overflow in SSL2 protocol - an attacker could supply an oversized client master key. ([CVE-2002-0656]) *Ben Laurie (CHATS)* ### Changes between 0.9.6c and 0.9.6d [9 May 2002] * Fix crypto/asn1/a_sign.c so that 'parameters' is omitted (not encoded as NULL) with id-dsa-with-sha1. *Nils Larsch ; problem pointed out by Bodo Moeller* * Check various `X509_...()` return values in `apps/req.c`. *Nils Larsch * * Fix BASE64 decode (EVP_DecodeUpdate) for data with CR/LF ended lines: an end-of-file condition would erroneously be flagged, when the CRLF was just at the end of a processed block. The bug was discovered when processing data through a buffering memory BIO handing the data to a BASE64-decoding BIO. Bug fund and patch submitted by Pavel Tsekov and Nedelcho Stanev. *Lutz Jaenicke* * Implement a countermeasure against a vulnerability recently found in CBC ciphersuites in SSL 3.0/TLS 1.0: Send an empty fragment before application data chunks to avoid the use of known IVs with data potentially chosen by the attacker. *Bodo Moeller* * Fix length checks in ssl3_get_client_hello(). *Bodo Moeller* * TLS/SSL library bugfix: use s->s3->in_read_app_data differently to prevent ssl3_read_internal() from incorrectly assuming that ssl3_read_bytes() found application data while handshake processing was enabled when in fact s->s3->in_read_app_data was merely automatically cleared during the initial handshake. *Bodo Moeller; problem pointed out by Arne Ansper * * Fix object definitions for Private and Enterprise: they were not recognized in their shortname (=lowercase) representation. Extend obj_dat.pl to issue an error when using undefined keywords instead of silently ignoring the problem (Svenning Sorensen ). *Lutz Jaenicke* * Fix DH_generate_parameters() so that it works for 'non-standard' generators, i.e. generators other than 2 and 5. (Previously, the code did not properly initialise the 'add' and 'rem' values to BN_generate_prime().) In the new general case, we do not insist that 'generator' is actually a primitive root: This requirement is rather pointless; a generator of the order-q subgroup is just as good, if not better. *Bodo Moeller* * Map new X509 verification errors to alerts. Discovered and submitted by Tom Wu . *Lutz Jaenicke* * Fix ssl3_pending() (ssl/s3_lib.c) to prevent SSL_pending() from returning non-zero before the data has been completely received when using non-blocking I/O. *Bodo Moeller; problem pointed out by John Hughes* * Some of the ciphers missed the strength entry (SSL_LOW etc). *Ben Laurie, Lutz Jaenicke* * Fix bug in SSL_clear(): bad sessions were not removed (found by Yoram Zahavi ). *Lutz Jaenicke* * Add information about CygWin 1.3 and on, and preserve proper configuration for the versions before that. *Corinna Vinschen and Richard Levitte* * Make removal from session cache (SSL_CTX_remove_session()) more robust: check whether we deal with a copy of a session and do not delete from the cache in this case. Problem reported by "Izhar Shoshani Levi" . *Lutz Jaenicke* * Do not store session data into the internal session cache, if it is never intended to be looked up (SSL_SESS_CACHE_NO_INTERNAL_LOOKUP flag is set). Proposed by Aslam . *Lutz Jaenicke* * Have ASN1_BIT_STRING_set_bit() really clear a bit when the requested value is 0. *Richard Levitte* * [In 0.9.6d-engine release:] Fix a crashbug and a logic bug in hwcrhk_load_pubkey(). *Toomas Kiisk via Richard Levitte* * Add the configuration target linux-s390x. *Neale Ferguson via Richard Levitte* * The earlier bugfix for the SSL3_ST_SW_HELLO_REQ_C case of ssl3_accept (ssl/s3_srvr.c) incorrectly used a local flag variable as an indication that a ClientHello message has been received. As the flag value will be lost between multiple invocations of ssl3_accept when using non-blocking I/O, the function may not be aware that a handshake has actually taken place, thus preventing a new session from being added to the session cache. To avoid this problem, we now set s->new_session to 2 instead of using a local variable. *Lutz Jaenicke, Bodo Moeller* * Bugfix: Return -1 from ssl3_get_server_done (ssl3/s3_clnt.c) if the SSL_R_LENGTH_MISMATCH error is detected. *Geoff Thorpe, Bodo Moeller* * New 'shared_ldflag' column in Configure platform table. *Richard Levitte* * Fix EVP_CIPHER_mode macro. *"Dan S. Camper" * * Fix ssl3_read_bytes (ssl/s3_pkt.c): To ignore messages of unknown type, we must throw them away by setting rr->length to 0. *D P Chang * ### Changes between 0.9.6b and 0.9.6c [21 dec 2001] * Fix BN_rand_range bug pointed out by Dominikus Scherkl . (The previous implementation worked incorrectly for those cases where range = `10..._2` and `3*range` is two bits longer than range.) *Bodo Moeller* * Only add signing time to PKCS7 structures if it is not already present. *Steve Henson* * Fix crypto/objects/objects.h: "ld-ce" should be "id-ce", OBJ_ld_ce should be OBJ_id_ce. Also some ip-pda OIDs in crypto/objects/objects.txt were incorrect (cf. RFC 3039). *Matt Cooper, Frederic Giudicelli, Bodo Moeller* * Release CRYPTO_LOCK_DYNLOCK when CRYPTO_destroy_dynlockid() returns early because it has nothing to do. *Andy Schneider * * [In 0.9.6c-engine release:] Fix mutex callback return values in crypto/engine/hw_ncipher.c. *Andy Schneider * * [In 0.9.6c-engine release:] Add support for Cryptographic Appliance's keyserver technology. (Use engine 'keyclient') *Cryptographic Appliances and Geoff Thorpe* * Add a configuration entry for OS/390 Unix. The C compiler 'c89' is called via tools/c89.sh because arguments have to be rearranged (all '-L' options must appear before the first object modules). *Richard Shapiro * * [In 0.9.6c-engine release:] Add support for Broadcom crypto accelerator cards, backported from 0.9.7. *Broadcom, Nalin Dahyabhai , Mark Cox* * [In 0.9.6c-engine release:] Add support for SureWare crypto accelerator cards from Baltimore Technologies. (Use engine 'sureware') *Baltimore Technologies and Mark Cox* * [In 0.9.6c-engine release:] Add support for crypto accelerator cards from Accelerated Encryption Processing, www.aep.ie. (Use engine 'aep') *AEP Inc. and Mark Cox* * Add a configuration entry for gcc on UnixWare. *Gary Benson * * Change ssl/s2_clnt.c and ssl/s2_srvr.c so that received handshake messages are stored in a single piece (fixed-length part and variable-length part combined) and fix various bugs found on the way. *Bodo Moeller* * Disable caching in BIO_gethostbyname(), directly use gethostbyname() instead. BIO_gethostbyname() does not know what timeouts are appropriate, so entries would stay in cache even when they have become invalid. *Bodo Moeller; problem pointed out by Rich Salz * * Change ssl23_get_client_hello (ssl/s23_srvr.c) behaviour when faced with a pathologically small ClientHello fragment that does not contain client_version: Instead of aborting with an error, simply choose the highest available protocol version (i.e., TLS 1.0 unless it is disabled). In practice, ClientHello messages are never sent like this, but this change gives us strictly correct behaviour at least for TLS. *Bodo Moeller* * Fix SSL handshake functions and SSL_clear() such that SSL_clear() never resets s->method to s->ctx->method when called from within one of the SSL handshake functions. *Bodo Moeller; problem pointed out by Niko Baric* * In ssl3_get_client_hello (ssl/s3_srvr.c), generate a fatal alert (sent using the client's version number) if client_version is smaller than the protocol version in use. Also change ssl23_get_client_hello (ssl/s23_srvr.c) to select TLS 1.0 if the client demanded SSL 3.0 but only TLS 1.0 is enabled; then the client will at least see that alert. *Bodo Moeller* * Fix ssl3_get_message (ssl/s3_both.c) to handle message fragmentation correctly. *Bodo Moeller* * Avoid infinite loop in ssl3_get_message (ssl/s3_both.c) if a client receives HelloRequest while in a handshake. *Bodo Moeller; bug noticed by Andy Schneider * * Bugfix in ssl3_accept (ssl/s3_srvr.c): Case SSL3_ST_SW_HELLO_REQ_C should end in 'break', not 'goto end' which circumvents various cleanups done in state SSL_ST_OK. But session related stuff must be disabled for SSL_ST_OK in the case that we just sent a HelloRequest. Also avoid some overhead by not calling ssl_init_wbio_buffer() before just sending a HelloRequest. *Bodo Moeller, Eric Rescorla * * Fix ssl/s3_enc.c, ssl/t1_enc.c and ssl/s3_pkt.c so that we don't reveal whether illegal block cipher padding was found or a MAC verification error occurred. (Neither SSLerr() codes nor alerts are directly visible to potential attackers, but the information may leak via logfiles.) Similar changes are not required for the SSL 2.0 implementation because the number of padding bytes is sent in clear for SSL 2.0, and the extra bytes are just ignored. However ssl/s2_pkt.c failed to verify that the purported number of padding bytes is in the legal range. *Bodo Moeller* * Add OpenUNIX-8 support including shared libraries (Boyd Lynn Gerber ). *Lutz Jaenicke* * Improve RSA_padding_check_PKCS1_OAEP() check again to avoid 'wristwatch attack' using huge encoding parameters (cf. James H. Manger's CRYPTO 2001 paper). Note that the RSA_PKCS1_OAEP_PADDING case of RSA_private_decrypt() does not use encoding parameters and hence was not vulnerable. *Bodo Moeller* * BN_sqr() bug fix. *Ulf Möller, reported by Jim Ellis * * Rabin-Miller test analyses assume uniformly distributed witnesses, so use BN_pseudo_rand_range() instead of using BN_pseudo_rand() followed by modular reduction. *Bodo Moeller; pointed out by Adam Young * * Add BN_pseudo_rand_range() with obvious functionality: BN_rand_range() equivalent based on BN_pseudo_rand() instead of BN_rand(). *Bodo Moeller* * s3_srvr.c: allow sending of large client certificate lists (> 16 kB). This function was broken, as the check for a new client hello message to handle SGC did not allow these large messages. (Tracked down by "Douglas E. Engert" .) *Lutz Jaenicke* * Add alert descriptions for TLSv1 to `SSL_alert_desc_string[_long]()`. *Lutz Jaenicke* * Fix buggy behaviour of BIO_get_num_renegotiates() and BIO_ctrl() for BIO_C_GET_WRITE_BUF_SIZE ("Stephen Hinton" ). *Lutz Jaenicke* * Rework the configuration and shared library support for Tru64 Unix. The configuration part makes use of modern compiler features and still retains old compiler behavior for those that run older versions of the OS. The shared library support part includes a variant that uses the RPATH feature, and is available through the special configuration target "alpha-cc-rpath", which will never be selected automatically. *Tim Mooney via Richard Levitte* * In ssl3_get_key_exchange (ssl/s3_clnt.c), call ssl3_get_message() with the same message size as in ssl3_get_certificate_request(). Otherwise, if no ServerKeyExchange message occurs, CertificateRequest messages might inadvertently be reject as too long. *Petr Lampa * * Enhanced support for IA-64 Unix platforms (well, Linux and HP-UX). *Andy Polyakov* * Modified SSL library such that the verify_callback that has been set specifically for an SSL object with SSL_set_verify() is actually being used. Before the change, a verify_callback set with this function was ignored and the verify_callback() set in the SSL_CTX at the time of the call was used. New function X509_STORE_CTX_set_verify_cb() introduced to allow the necessary settings. *Lutz Jaenicke* * Initialize static variable in crypto/dsa/dsa_lib.c and crypto/dh/dh_lib.c explicitly to NULL, as at least on Solaris 8 this seems not always to be done automatically (in contradiction to the requirements of the C standard). This made problems when used from OpenSSH. *Lutz Jaenicke* * In OpenSSL 0.9.6a and 0.9.6b, crypto/dh/dh_key.c ignored dh->length and always used BN_rand_range(priv_key, dh->p). BN_rand_range() is not necessary for Diffie-Hellman, and this specific range makes Diffie-Hellman unnecessarily inefficient if dh->length (recommended exponent length) is much smaller than the length of dh->p. We could use BN_rand_range() if the order of the subgroup was stored in the DH structure, but we only have dh->length. So switch back to BN_rand(priv_key, l, ...) where 'l' is dh->length if this is defined, or BN_num_bits(dh->p)-1 otherwise. *Bodo Moeller* * In RSA_eay_public_encrypt RSA_eay_private_decrypt RSA_eay_private_encrypt (signing) RSA_eay_public_decrypt (signature verification) (default implementations for RSA_public_encrypt, RSA_private_decrypt, RSA_private_encrypt, RSA_public_decrypt), always reject numbers >= n. *Bodo Moeller* * In crypto/rand/md_rand.c, use a new short-time lock CRYPTO_LOCK_RAND2 to synchronize access to 'locking_thread'. This is necessary on systems where access to 'locking_thread' (an 'unsigned long' variable) is not atomic. *Bodo Moeller* * In crypto/rand/md_rand.c, set 'locking_thread' to current thread's ID *before* setting the 'crypto_lock_rand' flag. The previous code had a race condition if 0 is a valid thread ID. *Travis Vitek * * Add support for shared libraries under Irix. *Albert Chin-A-Young * * Add configuration option to build on Linux on both big-endian and little-endian MIPS. *Ralf Baechle * * Add the possibility to create shared libraries on HP-UX. *Richard Levitte* ### Changes between 0.9.6a and 0.9.6b [9 Jul 2001] * Change ssleay_rand_bytes (crypto/rand/md_rand.c) to avoid a SSLeay/OpenSSL PRNG weakness pointed out by Markku-Juhani O. Saarinen : PRNG state recovery was possible based on the output of one PRNG request appropriately sized to gain knowledge on 'md' followed by enough consecutive 1-byte PRNG requests to traverse all of 'state'. 1. When updating 'md_local' (the current thread's copy of 'md') during PRNG output generation, hash all of the previous 'md_local' value, not just the half used for PRNG output. 2. Make the number of bytes from 'state' included into the hash independent from the number of PRNG bytes requested. The first measure alone would be sufficient to avoid Markku-Juhani's attack. (Actually it had never occurred to me that the half of 'md_local' used for chaining was the half from which PRNG output bytes were taken -- I had always assumed that the secret half would be used.) The second measure makes sure that additional data from 'state' is never mixed into 'md_local' in small portions; this heuristically further strengthens the PRNG. *Bodo Moeller* * Fix crypto/bn/asm/mips3.s. *Andy Polyakov* * When only the key is given to "enc", the IV is undefined. Print out an error message in this case. *Lutz Jaenicke* * Handle special case when X509_NAME is empty in X509 printing routines. *Steve Henson* * In dsa_do_verify (crypto/dsa/dsa_ossl.c), verify that r and s are positive and less than q. *Bodo Moeller* * Don't change `*pointer` in CRYPTO_add_lock() is add_lock_callback is used: it isn't thread safe and the add_lock_callback should handle that itself. *Paul Rose * * Verify that incoming data obeys the block size in ssl3_enc (ssl/s3_enc.c) and tls1_enc (ssl/t1_enc.c). *Bodo Moeller* * Fix OAEP check. *Ulf Möller, Bodo Möller* * The countermeasure against Bleichbacher's attack on PKCS #1 v1.5 RSA encryption was accidentally removed in s3_srvr.c in OpenSSL 0.9.5 when fixing the server behaviour for backwards-compatible 'client hello' messages. (Note that the attack is impractical against SSL 3.0 and TLS 1.0 anyway because length and version checking means that the probability of guessing a valid ciphertext is around 2^-40; see section 5 in Bleichenbacher's CRYPTO '98 paper.) Before 0.9.5, the countermeasure (hide the error by generating a random 'decryption result') did not work properly because ERR_clear_error() was missing, meaning that SSL_get_error() would detect the supposedly ignored error. Both problems are now fixed. *Bodo Moeller* * In crypto/bio/bf_buff.c, increase DEFAULT_BUFFER_SIZE to 4096 (previously it was 1024). *Bodo Moeller* * Fix for compatibility mode trust settings: ignore trust settings unless some valid trust or reject settings are present. *Steve Henson* * Fix for blowfish EVP: its a variable length cipher. *Steve Henson* * Fix various bugs related to DSA S/MIME verification. Handle missing parameters in DSA public key structures and return an error in the DSA routines if parameters are absent. *Steve Henson* * In versions up to 0.9.6, RAND_file_name() resorted to file ".rnd" in the current directory if neither $RANDFILE nor $HOME was set. RAND_file_name() in 0.9.6a returned NULL in this case. This has caused some confusion to Windows users who haven't defined $HOME. Thus RAND_file_name() is changed again: e_os.h can define a DEFAULT_HOME, which will be used if $HOME is not set. For Windows, we use "C:"; on other platforms, we still require environment variables. * Move 'if (!initialized) RAND_poll()' into regions protected by CRYPTO_LOCK_RAND. This is not strictly necessary, but avoids having multiple threads call RAND_poll() concurrently. *Bodo Moeller* * In crypto/rand/md_rand.c, replace 'add_do_not_lock' flag by a combination of a flag and a thread ID variable. Otherwise while one thread is in ssleay_rand_bytes (which sets the flag), *other* threads can enter ssleay_add_bytes without obeying the CRYPTO_LOCK_RAND lock (and may even illegally release the lock that they do not hold after the first thread unsets add_do_not_lock). *Bodo Moeller* * Change bctest again: '-x' expressions are not available in all versions of 'test'. *Bodo Moeller* ### Changes between 0.9.6 and 0.9.6a [5 Apr 2001] * Fix a couple of memory leaks in PKCS7_dataDecode() *Steve Henson, reported by Heyun Zheng * * Change Configure and Makefiles to provide EXE_EXT, which will contain the default extension for executables, if any. Also, make the perl scripts that use symlink() to test if it really exists and use "cp" if it doesn't. All this made OpenSSL compilable and installable in CygWin. *Richard Levitte* * Fix for asn1_GetSequence() for indefinite length constructed data. If SEQUENCE is length is indefinite just set c->slen to the total amount of data available. *Steve Henson, reported by shige@FreeBSD.org* *This change does not apply to 0.9.7.* * Change bctest to avoid here-documents inside command substitution (workaround for FreeBSD /bin/sh bug). For compatibility with Ultrix, avoid shell functions (introduced in the bctest version that searches along $PATH). *Bodo Moeller* * Rename 'des_encrypt' to 'des_encrypt1'. This avoids the clashes with des_encrypt() defined on some operating systems, like Solaris and UnixWare. *Richard Levitte* * Check the result of RSA-CRT (see D. Boneh, R. DeMillo, R. Lipton: On the Importance of Eliminating Errors in Cryptographic Computations, J. Cryptology 14 (2001) 2, 101-119, ). *Ulf Moeller* * MIPS assembler BIGNUM division bug fix. *Andy Polyakov* * Disabled incorrect Alpha assembler code. *Richard Levitte* * Fix PKCS#7 decode routines so they correctly update the length after reading an EOC for the EXPLICIT tag. *Steve Henson* *This change does not apply to 0.9.7.* * Fix bug in PKCS#12 key generation routines. This was triggered if a 3DES key was generated with a 0 initial byte. Include PKCS12_BROKEN_KEYGEN compilation option to retain the old (but broken) behaviour. *Steve Henson* * Enhance bctest to search for a working bc along $PATH and print it when found. *Tim Rice via Richard Levitte* * Fix memory leaks in err.c: free err_data string if necessary; don't write to the wrong index in ERR_set_error_data. *Bodo Moeller* * Implement ssl23_peek (analogous to ssl23_read), which previously did not exist. *Bodo Moeller* * Replace rdtsc with `_emit` statements for VC++ version 5. *Jeremy Cooper * * Make it possible to reuse SSLv2 sessions. *Richard Levitte* * In copy_email() check for >= 0 as a return value for X509_NAME_get_index_by_NID() since 0 is a valid index. *Steve Henson reported by Massimiliano Pala * * Avoid coredump with unsupported or invalid public keys by checking if X509_get_pubkey() fails in PKCS7_verify(). Fix memory leak when PKCS7_verify() fails with non detached data. *Steve Henson* * Don't use getenv in library functions when run as setuid/setgid. New function OPENSSL_issetugid(). *Ulf Moeller* * Avoid false positives in memory leak detection code (crypto/mem_dbg.c) due to incorrect handling of multi-threading: 1. Fix timing glitch in the MemCheck_off() portion of CRYPTO_mem_ctrl(). 2. Fix logical glitch in is_MemCheck_on() aka CRYPTO_is_mem_check_on(). 3. Count how many times MemCheck_off() has been called so that nested use can be treated correctly. This also avoids inband-signalling in the previous code (which relied on the assumption that thread ID 0 is impossible). *Bodo Moeller* * Add "-rand" option also to s_client and s_server. *Lutz Jaenicke* * Fix CPU detection on Irix 6.x. *Kurt Hockenbury and "Bruce W. Forsberg" * * Fix X509_NAME bug which produced incorrect encoding if X509_NAME was empty. *Steve Henson* *This change does not apply to 0.9.7.* * Use the cached encoding of an X509_NAME structure rather than copying it. This is apparently the reason for the libsafe "errors" but the code is actually correct. *Steve Henson* * Add new function BN_rand_range(), and fix DSA_sign_setup() to prevent Bleichenbacher's DSA attack. Extend BN_[pseudo_]rand: As before, top=1 forces the highest two bits to be set and top=0 forces the highest bit to be set; top=-1 is new and leaves the highest bit random. *Ulf Moeller, Bodo Moeller* * In the `NCONF_...`-based implementations for `CONF_...` queries (crypto/conf/conf_lib.c), if the input LHASH is NULL, avoid using a temporary CONF structure with the data component set to NULL (which gives segmentation faults in lh_retrieve). Instead, use NULL for the CONF pointer in CONF_get_string and CONF_get_number (which may use environment variables) and directly return NULL from CONF_get_section. *Bodo Moeller* * Fix potential buffer overrun for EBCDIC. *Ulf Moeller* * Tolerate nonRepudiation as being valid for S/MIME signing and certSign keyUsage if basicConstraints absent for a CA. *Steve Henson* * Make SMIME_write_PKCS7() write mail header values with a format that is more generally accepted (no spaces before the semicolon), since some programs can't parse those values properly otherwise. Also make sure BIO's that break lines after each write do not create invalid headers. *Richard Levitte* * Make the CRL encoding routines work with empty SEQUENCE OF. The macros previously used would not encode an empty SEQUENCE OF and break the signature. *Steve Henson* *This change does not apply to 0.9.7.* * Zero the premaster secret after deriving the master secret in DH ciphersuites. *Steve Henson* * Add some EVP_add_digest_alias registrations (as found in OpenSSL_add_all_digests()) to SSL_library_init() aka OpenSSL_add_ssl_algorithms(). This provides improved compatibility with peers using X.509 certificates with unconventional AlgorithmIdentifier OIDs. *Bodo Moeller* * Fix for Irix with NO_ASM. *"Bruce W. Forsberg" * * ./config script fixes. *Ulf Moeller, Richard Levitte* * Fix 'openssl passwd -1'. *Bodo Moeller* * Change PKCS12_key_gen_asc() so it can cope with non null terminated strings whose length is passed in the passlen parameter, for example from PEM callbacks. This was done by adding an extra length parameter to asc2uni(). *Steve Henson, reported by * * Fix C code generated by 'openssl dsaparam -C': If a BN_bin2bn call failed, free the DSA structure. *Bodo Moeller* * Fix to uni2asc() to cope with zero length Unicode strings. These are present in some PKCS#12 files. *Steve Henson* * Increase s2->wbuf allocation by one byte in ssl2_new (ssl/s2_lib.c). Otherwise do_ssl_write (ssl/s2_pkt.c) will write beyond buffer limits when writing a 32767 byte record. *Bodo Moeller; problem reported by Eric Day * * In `RSA_eay_public_{en,ed}crypt` and RSA_eay_mod_exp (rsa_eay.c), obtain lock CRYPTO_LOCK_RSA before setting `rsa->_method_mod_{n,p,q}`. (RSA objects have a reference count access to which is protected by CRYPTO_LOCK_RSA [see rsa_lib.c, s3_srvr.c, ssl_cert.c, ssl_rsa.c], so they are meant to be shared between threads.) *Bodo Moeller, Geoff Thorpe; original patch submitted by "Reddie, Steven" * * Fix a deadlock in CRYPTO_mem_leaks(). *Bodo Moeller* * Use better test patterns in bntest. *Ulf Möller* * rand_win.c fix for Borland C. *Ulf Möller* * BN_rshift bugfix for n == 0. *Bodo Moeller* * Add a 'bctest' script that checks for some known 'bc' bugs so that 'make test' does not abort just because 'bc' is broken. *Bodo Moeller* * Store verify_result within SSL_SESSION also for client side to avoid potential security hole. (Re-used sessions on the client side always resulted in verify_result==X509_V_OK, not using the original result of the server certificate verification.) *Lutz Jaenicke* * Fix ssl3_pending: If the record in s->s3->rrec is not of type SSL3_RT_APPLICATION_DATA, return 0. Similarly, change ssl2_pending to return 0 if SSL_in_init(s) is true. *Bodo Moeller* * Fix SSL_peek: Both ssl2_peek and ssl3_peek, which were totally broken in earlier releases, have been re-implemented by renaming the previous implementations of ssl2_read and ssl3_read to ssl2_read_internal and ssl3_read_internal, respectively, and adding 'peek' parameters to them. The new ssl[23]_{read,peek} functions are calls to ssl[23]_read_internal with the 'peek' flag set appropriately. A 'peek' parameter has also been added to ssl3_read_bytes, which does the actual work for ssl3_read_internal. *Bodo Moeller* * Initialise "ex_data" member of RSA/DSA/DH structures prior to calling the method-specific "init()" handler. Also clean up ex_data after calling the method-specific "finish()" handler. Previously, this was happening the other way round. *Geoff Thorpe* * Increase BN_CTX_NUM (the number of BIGNUMs in a BN_CTX) to 16. The previous value, 12, was not always sufficient for BN_mod_exp(). *Bodo Moeller* * Make sure that shared libraries get the internal name engine with the full version number and not just 0. This should mark the shared libraries as not backward compatible. Of course, this should be changed again when we can guarantee backward binary compatibility. *Richard Levitte* * Fix typo in get_cert_by_subject() in by_dir.c *Jean-Marc Desperrier * * Rework the system to generate shared libraries: - Make note of the expected extension for the shared libraries and if there is a need for symbolic links from for example libcrypto.so.0 to libcrypto.so.0.9.7. There is extended info in Configure for that. - Make as few rebuilds of the shared libraries as possible. - Still avoid linking the OpenSSL programs with the shared libraries. - When installing, install the shared libraries separately from the static ones. *Richard Levitte* * Fix SSL_CTX_set_read_ahead macro to actually use its argument. Copy SSL_CTX's read_ahead flag to SSL object directly in SSL_new and not in SSL_clear because the latter is also used by the accept/connect functions; previously, the settings made by SSL_set_read_ahead would be lost during the handshake. *Bodo Moeller; problems reported by Anders Gertz * * Correct util/mkdef.pl to be selective about disabled algorithms. Previously, it would create entries for disabled algorithms no matter what. *Richard Levitte* * Added several new manual pages for SSL_* function. *Lutz Jaenicke* ### Changes between 0.9.5a and 0.9.6 [24 Sep 2000] * In ssl23_get_client_hello, generate an error message when faced with an initial SSL 3.0/TLS record that is too small to contain the first two bytes of the ClientHello message, i.e. client_version. (Note that this is a pathologic case that probably has never happened in real life.) The previous approach was to use the version number from the record header as a substitute; but our protocol choice should not depend on that one because it is not authenticated by the Finished messages. *Bodo Moeller* * More robust randomness gathering functions for Windows. *Jeffrey Altman * * For compatibility reasons if the flag X509_V_FLAG_ISSUER_CHECK is not set then we don't setup the error code for issuer check errors to avoid possibly overwriting other errors which the callback does handle. If an application does set the flag then we assume it knows what it is doing and can handle the new informational codes appropriately. *Steve Henson* * Fix for a nasty bug in ASN1_TYPE handling. ASN1_TYPE is used for a general "ANY" type, as such it should be able to decode anything including tagged types. However it didn't check the class so it would wrongly interpret tagged types in the same way as their universal counterpart and unknown types were just rejected. Changed so that the tagged and unknown types are handled in the same way as a SEQUENCE: that is the encoding is stored intact. There is also a new type "V_ASN1_OTHER" which is used when the class is not universal, in this case we have no idea what the actual type is so we just lump them all together. *Steve Henson* * On VMS, stdout may very well lead to a file that is written to in a record-oriented fashion. That means that every write() will write a separate record, which will be read separately by the programs trying to read from it. This can be very confusing. The solution is to put a BIO filter in the way that will buffer text until a linefeed is reached, and then write everything a line at a time, so every record written will be an actual line, not chunks of lines and not (usually doesn't happen, but I've seen it once) several lines in one record. BIO_f_linebuffer() is the answer. Currently, it's a VMS-only method, because that's where it has been tested well enough. *Richard Levitte* * Remove 'optimized' squaring variant in BN_mod_mul_montgomery, it can return incorrect results. (Note: The buggy variant was not enabled in OpenSSL 0.9.5a, but it was in 0.9.6-beta[12].) *Bodo Moeller* * Disable the check for content being present when verifying detached signatures in pk7_smime.c. Some versions of Netscape (wrongly) include zero length content when signing messages. *Steve Henson* * New BIO_shutdown_wr macro, which invokes the BIO_C_SHUTDOWN_WR BIO_ctrl (for BIO pairs). *Bodo Möller* * Add DSO method for VMS. *Richard Levitte* * Bug fix: Montgomery multiplication could produce results with the wrong sign. *Ulf Möller* * Add RPM specification openssl.spec and modify it to build three packages. The default package contains applications, application documentation and run-time libraries. The devel package contains include files, static libraries and function documentation. The doc package contains the contents of the doc directory. The original openssl.spec was provided by Damien Miller . *Richard Levitte* * Add a large number of documentation files for many SSL routines. *Lutz Jaenicke * * Add a configuration entry for Sony News 4. *NAKAJI Hiroyuki * * Don't set the two most significant bits to one when generating a random number < q in the DSA library. *Ulf Möller* * New SSL API mode 'SSL_MODE_AUTO_RETRY'. This disables the default behaviour that SSL_read may result in SSL_ERROR_WANT_READ (even if the underlying transport is blocking) if a handshake took place. (The default behaviour is needed by applications such as s_client and s_server that use select() to determine when to use SSL_read; but for applications that know in advance when to expect data, it just makes things more complicated.) *Bodo Moeller* * Add RAND_egd_bytes(), which gives control over the number of bytes read from EGD. *Ben Laurie* * Add a few more EBCDIC conditionals that make `req` and `x509` work better on such systems. *Martin Kraemer * * Add two demo programs for PKCS12_parse() and PKCS12_create(). Update PKCS12_parse() so it copies the friendlyName and the keyid to the certificates aux info. *Steve Henson* * Fix bug in PKCS7_verify() which caused an infinite loop if there was more than one signature. *Sven Uszpelkat * * Major change in util/mkdef.pl to include extra information about each symbol, as well as presenting variables as well as functions. This change means that there's n more need to rebuild the .num files when some algorithms are excluded. *Richard Levitte* * Allow the verify time to be set by an application, rather than always using the current time. *Steve Henson* * Phase 2 verify code reorganisation. The certificate verify code now looks up an issuer certificate by a number of criteria: subject name, authority key id and key usage. It also verifies self signed certificates by the same criteria. The main comparison function is X509_check_issued() which performs these checks. Lot of changes were necessary in order to support this without completely rewriting the lookup code. Authority and subject key identifier are now cached. The LHASH 'certs' is X509_STORE has now been replaced by a STACK_OF(X509_OBJECT). This is mainly because an LHASH can't store or retrieve multiple objects with the same hash value. As a result various functions (which were all internal use only) have changed to handle the new X509_STORE structure. This will break anything that messed round with X509_STORE internally. The functions X509_STORE_add_cert() now checks for an exact match, rather than just subject name. The X509_STORE API doesn't directly support the retrieval of multiple certificates matching a given criteria, however this can be worked round by performing a lookup first (which will fill the cache with candidate certificates) and then examining the cache for matches. This is probably the best we can do without throwing out X509_LOOKUP entirely (maybe later...). The X509_VERIFY_CTX structure has been enhanced considerably. All certificate lookup operations now go via a get_issuer() callback. Although this currently uses an X509_STORE it can be replaced by custom lookups. This is a simple way to bypass the X509_STORE hackery necessary to make this work and makes it possible to use more efficient techniques in future. A very simple version which uses a simple STACK for its trusted certificate store is also provided using X509_STORE_CTX_trusted_stack(). The verify_cb() and verify() callbacks now have equivalents in the X509_STORE_CTX structure. X509_STORE_CTX also has a 'flags' field which can be used to customise the verify behaviour. *Steve Henson* * Add new PKCS#7 signing option PKCS7_NOSMIMECAP which excludes S/MIME capabilities. *Steve Henson* * When a certificate request is read in keep a copy of the original encoding of the signed data and use it when outputting again. Signatures then use the original encoding rather than a decoded, encoded version which may cause problems if the request is improperly encoded. *Steve Henson* * For consistency with other BIO_puts implementations, call buffer_write(b, ...) directly in buffer_puts instead of calling BIO_write(b, ...). In BIO_puts, increment b->num_write as in BIO_write. *Peter.Sylvester@EdelWeb.fr* * Fix BN_mul_word for the case where the word is 0. (We have to use BN_zero, we may not return a BIGNUM with an array consisting of words set to zero.) *Bodo Moeller* * Avoid calling abort() from within the library when problems are detected, except if preprocessor symbols have been defined (such as REF_CHECK, BN_DEBUG etc.). *Bodo Moeller* * New openssl application 'rsautl'. This utility can be used for low-level RSA operations. DER public key BIO/fp routines also added. *Steve Henson* * New Configure entry and patches for compiling on QNX 4. *Andreas Schneider * * A demo state-machine implementation was sponsored by Nuron () and is now available in demos/state_machine. *Ben Laurie* * New options added to the 'dgst' utility for signature generation and verification. *Steve Henson* * Unrecognized PKCS#7 content types are now handled via a catch all ASN1_TYPE structure. This allows unsupported types to be stored as a "blob" and an application can encode and decode it manually. *Steve Henson* * Fix various signed/unsigned issues to make a_strex.c compile under VC++. *Oscar Jacobsson * * ASN1 fixes. i2d_ASN1_OBJECT was not returning the correct length if passed a buffer. ASN1_INTEGER_to_BN failed if passed a NULL BN and its argument was negative. *Steve Henson, pointed out by Sven Heiberg * * Modification to PKCS#7 encoding routines to output definite length encoding. Since currently the whole structures are in memory there's not real point in using indefinite length constructed encoding. However if OpenSSL is compiled with the flag PKCS7_INDEFINITE_ENCODING the old form is used. *Steve Henson* * Added BIO_vprintf() and BIO_vsnprintf(). *Richard Levitte* * Added more prefixes to parse for in the strings written through a logging bio, to cover all the levels that are available through syslog. The prefixes are now: PANIC, EMERG, EMR => LOG_EMERG ALERT, ALR => LOG_ALERT CRIT, CRI => LOG_CRIT ERROR, ERR => LOG_ERR WARNING, WARN, WAR => LOG_WARNING NOTICE, NOTE, NOT => LOG_NOTICE INFO, INF => LOG_INFO DEBUG, DBG => LOG_DEBUG and as before, if none of those prefixes are present at the beginning of the string, LOG_ERR is chosen. On Win32, the `LOG_*` levels are mapped according to this: LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR => EVENTLOG_ERROR_TYPE LOG_WARNING => EVENTLOG_WARNING_TYPE LOG_NOTICE, LOG_INFO, LOG_DEBUG => EVENTLOG_INFORMATION_TYPE *Richard Levitte* * Made it possible to reconfigure with just the configuration argument "reconf" or "reconfigure". The command line arguments are stored in Makefile.ssl in the variable CONFIGURE_ARGS, and are retrieved from there when reconfiguring. *Richard Levitte* * MD4 implemented. *Assar Westerlund , Richard Levitte* * Add the arguments -CAfile and -CApath to the pkcs12 utility. *Richard Levitte* * The obj_dat.pl script was messing up the sorting of object names. The reason was that it compared the quoted version of strings as a result "OCSP" > "OCSP Signing" because " > SPACE. Changed script to store unquoted versions of names and add quotes on output. It was also omitting some names from the lookup table if they were given a default value (that is if SN is missing it is given the same value as LN and vice versa), these are now added on the grounds that if an object has a name we should be able to look it up. Finally added warning output when duplicate short or long names are found. *Steve Henson* * Changes needed for Tandem NSK. *Scott Uroff * * Fix SSL 2.0 rollback checking: Due to an off-by-one error in RSA_padding_check_SSLv23(), special padding was never detected and thus the SSL 3.0/TLS 1.0 countermeasure against protocol version rollback attacks was not effective. In s23_clnt.c, don't use special rollback-attack detection padding (RSA_SSLV23_PADDING) if SSL 2.0 is the only protocol enabled in the client; similarly, in s23_srvr.c, don't do the rollback check if SSL 2.0 is the only protocol enabled in the server. *Bodo Moeller* * Make it possible to get hexdumps of unprintable data with 'openssl asn1parse'. By implication, the functions ASN1_parse_dump() and BIO_dump_indent() are added. *Richard Levitte* * New functions ASN1_STRING_print_ex() and X509_NAME_print_ex() these print out strings and name structures based on various flags including RFC2253 support and proper handling of multibyte characters. Added options to the 'x509' utility to allow the various flags to be set. *Steve Henson* * Various fixes to use ASN1_TIME instead of ASN1_UTCTIME. Also change the functions X509_cmp_current_time() and X509_gmtime_adj() work with an ASN1_TIME structure, this will enable certificates using GeneralizedTime in validity dates to be checked. *Steve Henson* * Make the NEG_PUBKEY_BUG code (which tolerates invalid negative public key encodings) on by default, NO_NEG_PUBKEY_BUG can be set to disable it. *Steve Henson* * New function c2i_ASN1_OBJECT() which acts on ASN1_OBJECT content octets. An i2c_ASN1_OBJECT is unnecessary because the encoding can be trivially obtained from the structure. *Steve Henson* * crypto/err.c locking bugfix: Use write locks (`CRYPTO_w_[un]lock`), not read locks (`CRYPTO_r_[un]lock`). *Bodo Moeller* * A first attempt at creating official support for shared libraries through configuration. I've kept it so the default is static libraries only, and the OpenSSL programs are always statically linked for now, but there are preparations for dynamic linking in place. This has been tested on Linux and Tru64. *Richard Levitte* * Randomness polling function for Win9x, as described in: Peter Gutmann, Software Generation of Practically Strong Random Numbers. *Ulf Möller* * Fix so PRNG is seeded in req if using an already existing DSA key. *Steve Henson* * New options to smime application. -inform and -outform allow alternative formats for the S/MIME message including PEM and DER. The -content option allows the content to be specified separately. This should allow things like Netscape form signing output easier to verify. *Steve Henson* * Fix the ASN1 encoding of tags using the 'long form'. *Steve Henson* * New ASN1 functions, `i2c_*` and `c2i_*` for INTEGER and BIT STRING types. These convert content octets to and from the underlying type. The actual tag and length octets are already assumed to have been read in and checked. These are needed because all other string types have virtually identical handling apart from the tag. By having versions of the ASN1 functions that just operate on content octets IMPLICIT tagging can be handled properly. It also allows the ASN1_ENUMERATED code to be cut down because ASN1_ENUMERATED and ASN1_INTEGER are identical apart from the tag. *Steve Henson* * Change the handling of OID objects as follows: - New object identifiers are inserted in objects.txt, following the syntax given in [crypto/objects/README.md](crypto/objects/README.md). - objects.pl is used to process obj_mac.num and create a new obj_mac.h. - obj_dat.pl is used to create a new obj_dat.h, using the data in obj_mac.h. This is currently kind of a hack, and the perl code in objects.pl isn't very elegant, but it works as I intended. The simplest way to check that it worked correctly is to look in obj_dat.h and check the array nid_objs and make sure the objects haven't moved around (this is important!). Additions are OK, as well as consistent name changes. *Richard Levitte* * Add BSD-style MD5-based passwords to 'openssl passwd' (option '-1'). *Bodo Moeller* * Addition of the command line parameter '-rand file' to 'openssl req'. The given file adds to whatever has already been seeded into the random pool through the RANDFILE configuration file option or environment variable, or the default random state file. *Richard Levitte* * mkstack.pl now sorts each macro group into lexical order. Previously the output order depended on the order the files appeared in the directory, resulting in needless rewriting of safestack.h . *Steve Henson* * Patches to make OpenSSL compile under Win32 again. Mostly work arounds for the VC++ problem that it treats func() as func(void). Also stripped out the parts of mkdef.pl that added extra typesafe functions: these no longer exist. *Steve Henson* * Reorganisation of the stack code. The macros are now all collected in safestack.h . Each macro is defined in terms of a "stack macro" of the form `SKM_(type, a, b)`. The DEBUG_SAFESTACK is now handled in terms of function casts, this has the advantage of retaining type safety without the use of additional functions. If DEBUG_SAFESTACK is not defined then the non typesafe macros are used instead. Also modified the mkstack.pl script to handle the new form. Needs testing to see if which (if any) compilers it chokes and maybe make DEBUG_SAFESTACK the default if no major problems. Similar behaviour for ASN1_SET_OF and PKCS12_STACK_OF. *Steve Henson* * When some versions of IIS use the 'NET' form of private key the key derivation algorithm is different. Normally MD5(password) is used as a 128 bit RC4 key. In the modified case MD5(MD5(password) + "SGCKEYSALT") is used instead. Added some new functions i2d_RSA_NET(), d2i_RSA_NET() etc which are the same as the old Netscape_RSA functions except they have an additional 'sgckey' parameter which uses the modified algorithm. Also added an -sgckey command line option to the rsa utility. Thanks to Adrian Peck for posting details of the modified algorithm to openssl-dev. *Steve Henson* * The evp_local.h macros were using 'c.##kname' which resulted in invalid expansion on some systems (SCO 5.0.5 for example). Corrected to 'c.kname'. *Phillip Porch * * New X509_get1_email() and X509_REQ_get1_email() functions that return a STACK of email addresses from a certificate or request, these look in the subject name and the subject alternative name extensions and omit any duplicate addresses. *Steve Henson* * Re-implement BN_mod_exp2_mont using independent (and larger) windows. This makes DSA verification about 2 % faster. *Bodo Moeller* * Increase maximum window size in `BN_mod_exp_...` to 6 bits instead of 5 (meaning that now 2^5 values will be precomputed, which is only 4 KB plus overhead for 1024 bit moduli). This makes exponentiations about 0.5 % faster for 1024 bit exponents (as measured by "openssl speed rsa2048"). *Bodo Moeller* * Rename memory handling macros to avoid conflicts with other software: Malloc => OPENSSL_malloc Malloc_locked => OPENSSL_malloc_locked Realloc => OPENSSL_realloc Free => OPENSSL_free *Richard Levitte* * New function BN_mod_exp_mont_word for small bases (roughly 15% faster than BN_mod_exp_mont, i.e. 7% for a full DH exchange). *Bodo Moeller* * CygWin32 support. *John Jarvie * * The type-safe stack code has been rejigged. It is now only compiled in when OpenSSL is configured with the DEBUG_SAFESTACK option and by default all type-specific stack functions are "#define"d back to standard stack functions. This results in more streamlined output but retains the type-safety checking possibilities of the original approach. *Geoff Thorpe* * The STACK code has been cleaned up, and certain type declarations that didn't make a lot of sense have been brought in line. This has also involved a cleanup of sorts in safestack.h to more correctly map type-safe stack functions onto their plain stack counterparts. This work has also resulted in a variety of "const"ifications of lots of the code, especially `_cmp` operations which should normally be prototyped with "const" parameters anyway. *Geoff Thorpe* * When generating bytes for the first time in md_rand.c, 'stir the pool' by seeding with STATE_SIZE dummy bytes (with zero entropy count). (The PRNG state consists of two parts, the large pool 'state' and 'md', where all of 'md' is used each time the PRNG is used, but 'state' is used only indexed by a cyclic counter. As entropy may not be well distributed from the beginning, 'md' is important as a chaining variable. However, the output function chains only half of 'md', i.e. 80 bits. ssleay_rand_add, on the other hand, chains all of 'md', and seeding with STATE_SIZE dummy bytes will result in all of 'state' being rewritten, with the new values depending on virtually all of 'md'. This overcomes the 80 bit limitation.) *Bodo Moeller* * In ssl/s2_clnt.c and ssl/s3_clnt.c, call ERR_clear_error() when the handshake is continued after ssl_verify_cert_chain(); otherwise, if SSL_VERIFY_NONE is set, remaining error codes can lead to 'unexplainable' connection aborts later. *Bodo Moeller; problem tracked down by Lutz Jaenicke* * Major EVP API cipher revision. Add hooks for extra EVP features. This allows various cipher parameters to be set in the EVP interface. Support added for variable key length ciphers via the EVP_CIPHER_CTX_set_key_length() function and setting of RC2 and RC5 parameters. Modify EVP_OpenInit() and EVP_SealInit() to cope with variable key length ciphers. Remove lots of duplicated code from the EVP library. For example *every* cipher init() function handles the 'iv' in the same way according to the cipher mode. They also all do nothing if the 'key' parameter is NULL and for CFB and OFB modes they zero ctx->num. New functionality allows removal of S/MIME code RC2 hack. Most of the routines have the same form and so can be declared in terms of macros. By shifting this to the top level EVP_CipherInit() it can be removed from all individual ciphers. If the cipher wants to handle IVs or keys differently it can set the EVP_CIPH_CUSTOM_IV or EVP_CIPH_ALWAYS_CALL_INIT flags. Change lots of functions like EVP_EncryptUpdate() to now return a value: although software versions of the algorithms cannot fail any installed hardware versions can. *Steve Henson* * Implement SSL_OP_TLS_ROLLBACK_BUG: In ssl3_get_client_key_exchange, if this option is set, tolerate broken clients that send the negotiated protocol version number instead of the requested protocol version number. *Bodo Moeller* * Call dh_tmp_cb (set by `..._TMP_DH_CB`) with correct 'is_export' flag; i.e. non-zero for export ciphersuites, zero otherwise. Previous versions had this flag inverted, inconsistent with rsa_tmp_cb (..._TMP_RSA_CB). *Bodo Moeller; problem reported by Amit Chopra* * Add missing DSA library text string. Work around for some IIS key files with invalid SEQUENCE encoding. *Steve Henson* * Add a document (doc/standards.txt) that list all kinds of standards and so on that are implemented in OpenSSL. *Richard Levitte* * Enhance c_rehash script. Old version would mishandle certificates with the same subject name hash and wouldn't handle CRLs at all. Added -fingerprint option to crl utility, to support new c_rehash features. *Steve Henson* * Eliminate non-ANSI declarations in crypto.h and stack.h. *Ulf Möller* * Fix for SSL server purpose checking. Server checking was rejecting certificates which had extended key usage present but no ssl client purpose. *Steve Henson, reported by Rene Grosser * * Make PKCS#12 code work with no password. The PKCS#12 spec is a little unclear about how a blank password is handled. Since the password in encoded as a BMPString with terminating double NULL a zero length password would end up as just the double NULL. However no password at all is different and is handled differently in the PKCS#12 key generation code. NS treats a blank password as zero length. MSIE treats it as no password on export: but it will try both on import. We now do the same: PKCS12_parse() tries zero length and no password if the password is set to "" or NULL (NULL is now a valid password: it wasn't before) as does the pkcs12 application. *Steve Henson* * Bugfixes in `apps/x509.c`: Avoid a memory leak; and don't use perror when PEM_read_bio_X509_REQ fails, the error message must be obtained from the error queue. *Bodo Moeller* * Avoid 'thread_hash' memory leak in crypto/err/err.c by freeing it in ERR_remove_state if appropriate, and change ERR_get_state accordingly to avoid race conditions (this is necessary because thread_hash is no longer constant once set). *Bodo Moeller* * Bugfix for linux-elf makefile.one. *Ulf Möller* * RSA_get_default_method() will now cause a default RSA_METHOD to be chosen if one doesn't exist already. Previously this was only set during a call to RSA_new() or RSA_new_method(NULL) meaning it was possible for RSA_get_default_method() to return NULL. *Geoff Thorpe* * Added native name translation to the existing DSO code that will convert (if the flag to do so is set) filenames that are sufficiently small and have no path information into a canonical native form. Eg. "blah" converted to "libblah.so" or "blah.dll" etc. *Geoff Thorpe* * New function ERR_error_string_n(e, buf, len) which is like ERR_error_string(e, buf), but writes at most 'len' bytes including the 0 terminator. For ERR_error_string_n, 'buf' may not be NULL. *Damien Miller , Bodo Moeller* * CONF library reworked to become more general. A new CONF configuration file reader "class" is implemented as well as a new functions (`NCONF_*`, for "New CONF") to handle it. The now old `CONF_*` functions are still there, but are reimplemented to work in terms of the new functions. Also, a set of functions to handle the internal storage of the configuration data is provided to make it easier to write new configuration file reader "classes" (I can definitely see something reading a configuration file in XML format, for example), called `_CONF_*`, or "the configuration storage API"... The new configuration file reading functions are: NCONF_new, NCONF_free, NCONF_load, NCONF_load_fp, NCONF_load_bio, NCONF_get_section, NCONF_get_string, NCONF_get_numbre NCONF_default, NCONF_WIN32 NCONF_dump_fp, NCONF_dump_bio NCONF_default and NCONF_WIN32 are method (or "class") choosers, NCONF_new creates a new CONF object. This works in the same way as other interfaces in OpenSSL, like the BIO interface. `NCONF_dump_*` dump the internal storage of the configuration file, which is useful for debugging. All other functions take the same arguments as the old `CONF_*` functions with the exception of the first that must be a `CONF *` instead of a `LHASH *`. To make it easier to use the new classes with the old `CONF_*` functions, the function CONF_set_default_method is provided. *Richard Levitte* * Add '-tls1' option to 'openssl ciphers', which was already mentioned in the documentation but had not been implemented. (This option is not yet really useful because even the additional experimental TLS 1.0 ciphers are currently treated as SSL 3.0 ciphers.) *Bodo Moeller* * Initial DSO code added into libcrypto for letting OpenSSL (and OpenSSL-based applications) load shared libraries and bind to them in a portable way. *Geoff Thorpe, with contributions from Richard Levitte* ### Changes between 0.9.5 and 0.9.5a [1 Apr 2000] * Make sure _lrotl and _lrotr are only used with MSVC. * Use lock CRYPTO_LOCK_RAND correctly in ssleay_rand_status (the default implementation of RAND_status). * Rename openssl x509 option '-crlext', which was added in 0.9.5, to '-clrext' (= clear extensions), as intended and documented. *Bodo Moeller; inconsistency pointed out by Michael Attili * * Fix for HMAC. It wasn't zeroing the rest of the block if the key length was larger than the MD block size. *Steve Henson, pointed out by Yost William * * Modernise PKCS12_parse() so it uses STACK_OF(X509) for its ca argument fix a leak when the ca argument was passed as NULL. Stop X509_PUBKEY_set() using the passed key: if the passed key was a private key the result of X509_print(), for example, would be to print out all the private key components. *Steve Henson* * des_quad_cksum() byte order bug fix. *Ulf Möller, using the problem description in krb4-0.9.7, where the solution is attributed to Derrick J Brashear * * Fix so V_ASN1_APP_CHOOSE works again: however its use is strongly discouraged. *Steve Henson, pointed out by Brian Korver * * For easily testing in shell scripts whether some command 'openssl XXX' exists, the new pseudo-command 'openssl no-XXX' returns with exit code 0 iff no command of the given name is available. 'no-XXX' is printed in this case, 'XXX' otherwise. In both cases, the output goes to stdout and nothing is printed to stderr. Additional arguments are always ignored. Since for each cipher there is a command of the same name, the 'no-cipher' compilation switches can be tested this way. ('openssl no-XXX' is not able to detect pseudo-commands such as 'quit', 'list-XXX-commands', or 'no-XXX' itself.) *Bodo Moeller* * Update test suite so that 'make test' succeeds in 'no-rsa' configuration. *Bodo Moeller* * For SSL_[CTX_]set_tmp_dh, don't create a DH key if SSL_OP_SINGLE_DH_USE is set; it will be thrown away anyway because each handshake creates its own key. ssl_cert_dup, which is used by SSL_new, now copies DH keys in addition to parameters -- in previous versions (since OpenSSL 0.9.3) the 'default key' from SSL_CTX_set_tmp_dh would always be lost, meaning you effectively got SSL_OP_SINGLE_DH_USE when using this macro. *Bodo Moeller* * New s_client option -ign_eof: EOF at stdin is ignored, and 'Q' and 'R' lose their special meanings (quit/renegotiate). This is part of what -quiet does; unlike -quiet, -ign_eof does not suppress any output. *Richard Levitte* * Add compatibility options to the purpose and trust code. The purpose X509_PURPOSE_ANY is "any purpose" which automatically accepts a certificate or CA, this was the previous behaviour, with all the associated security issues. X509_TRUST_COMPAT is the old trust behaviour: only and automatically trust self signed roots in certificate store. A new trust setting X509_TRUST_DEFAULT is used to specify that a purpose has no associated trust setting and it should instead use the value in the default purpose. *Steve Henson* * Fix the PKCS#8 DSA private key code so it decodes keys again and fix a memory leak. *Steve Henson* * In util/mkerr.pl (which implements 'make errors'), preserve reason strings from the previous version of the .c file, as the default to have only downcase letters (and digits) in automatically generated reasons codes is not always appropriate. *Bodo Moeller* * In ERR_load_ERR_strings(), build an ERR_LIB_SYS error reason table using strerror. Previously, ERR_reason_error_string() returned library names as reason strings for SYSerr; but SYSerr is a special case where small numbers are errno values, not library numbers. *Bodo Moeller* * Add '-dsaparam' option to 'openssl dhparam' application. This converts DSA parameters into DH parameters. (When creating parameters, DSA_generate_parameters is used.) *Bodo Moeller* * Include 'length' (recommended exponent length) in C code generated by 'openssl dhparam -C'. *Bodo Moeller* * The second argument to set_label in perlasm was already being used so couldn't be used as a "file scope" flag. Moved to third argument which was free. *Steve Henson* * In PEM_ASN1_write_bio and some other functions, use RAND_pseudo_bytes instead of RAND_bytes for encryption IVs and salts. *Bodo Moeller* * Include RAND_status() into RAND_METHOD instead of implementing it only for md_rand.c Otherwise replacing the PRNG by calling RAND_set_rand_method would be impossible. *Bodo Moeller* * Don't let DSA_generate_key() enter an infinite loop if the random number generation fails. *Bodo Moeller* * New 'rand' application for creating pseudo-random output. *Bodo Moeller* * Added configuration support for Linux/IA64 *Rolf Haberrecker * * Assembler module support for Mingw32. *Ulf Möller* * Shared library support for HPUX (in shlib/). *Lutz Jaenicke and Anonymous* * Shared library support for Solaris gcc. *Lutz Behnke * ### Changes between 0.9.4 and 0.9.5 [28 Feb 2000] * PKCS7_encrypt() was adding text MIME headers twice because they were added manually and by SMIME_crlf_copy(). *Steve Henson* * In bntest.c don't call BN_rand with zero bits argument. *Steve Henson, pointed out by Andrew W. Gray * * BN_mul bugfix: In bn_mul_part_recursion() only the a>a[n] && b>b[n] case was implemented. This caused BN_div_recp() to fail occasionally. *Ulf Möller* * Add an optional second argument to the set_label() in the perl assembly language builder. If this argument exists and is set to 1 it signals that the assembler should use a symbol whose scope is the entire file, not just the current function. This is needed with MASM which uses the format label:: for this scope. *Steve Henson, pointed out by Peter Runestig * * Change the ASN1 types so they are typedefs by default. Before almost all types were #define'd to ASN1_STRING which was causing STACK_OF() problems: you couldn't declare STACK_OF(ASN1_UTF8STRING) for example. *Steve Henson* * Change names of new functions to the new get1/get0 naming convention: After 'get1', the caller owns a reference count and has to call `..._free`; 'get0' returns a pointer to some data structure without incrementing reference counters. (Some of the existing 'get' functions increment a reference counter, some don't.) Similarly, 'set1' and 'add1' functions increase reference counters or duplicate objects. *Steve Henson* * Allow for the possibility of temp RSA key generation failure: the code used to assume it always worked and crashed on failure. *Steve Henson* * Fix potential buffer overrun problem in BIO_printf(). *Ulf Möller, using public domain code by Patrick Powell; problem pointed out by David Sacerdote * * Support EGD . New functions RAND_egd() and RAND_status(). In the command line application, the EGD socket can be specified like a seed file using RANDFILE or -rand. *Ulf Möller* * Allow the string CERTIFICATE to be tolerated in PKCS#7 structures. Some CAs (e.g. Verisign) distribute certificates in this form. *Steve Henson* * Remove the SSL_ALLOW_ADH compile option and set the default cipher list to exclude them. This means that no special compilation option is needed to use anonymous DH: it just needs to be included in the cipher list. *Steve Henson* * Change the EVP_MD_CTX_type macro so its meaning consistent with EVP_MD_type. The old functionality is available in a new macro called EVP_MD_md(). Change code that uses it and update docs. *Steve Henson* * `..._ctrl` functions now have corresponding `..._callback_ctrl` functions where the `void *` argument is replaced by a function pointer argument. Previously `void *` was abused to point to functions, which works on many platforms, but is not correct. As these functions are usually called by macros defined in OpenSSL header files, most source code should work without changes. *Richard Levitte* * `` (which is created by Configure) now contains sections with information on -D... compiler switches used for compiling the library so that applications can see them. To enable one of these sections, a pre-processor symbol `OPENSSL_..._DEFINES` must be defined. E.g., #define OPENSSL_ALGORITHM_DEFINES #include defines all pertinent `NO_` symbols, such as NO_IDEA, NO_RSA, etc. *Richard Levitte, Ulf and Bodo Möller* * Bugfix: Tolerate fragmentation and interleaving in the SSL 3/TLS record layer. *Bodo Moeller* * Change the 'other' type in certificate aux info to a STACK_OF X509_ALGOR. Although not an AlgorithmIdentifier as such it has the required ASN1 format: arbitrary types determined by an OID. *Steve Henson* * Add some PEM_write_X509_REQ_NEW() functions and a command line argument to 'req'. This is not because the function is newer or better than others it just uses the work 'NEW' in the certificate request header lines. Some software needs this. *Steve Henson* * Reorganise password command line arguments: now passwords can be obtained from various sources. Delete the PEM_cb function and make it the default behaviour: i.e. if the callback is NULL and the usrdata argument is not NULL interpret it as a null terminated pass phrase. If usrdata and the callback are NULL then the pass phrase is prompted for as usual. *Steve Henson* * Add support for the Compaq Atalla crypto accelerator. If it is installed, the support is automatically enabled. The resulting binaries will autodetect the card and use it if present. *Ben Laurie and Compaq Inc.* * Work around for Netscape hang bug. This sends certificate request and server done in one record. Since this is perfectly legal in the SSL/TLS protocol it isn't a "bug" option and is on by default. See the bugs/SSLv3 entry for more info. *Steve Henson* * HP-UX tune-up: new unified configs, HP C compiler bug workaround. *Andy Polyakov* * Add -rand argument to smime and pkcs12 applications and read/write of seed file. *Steve Henson* * New 'passwd' tool for crypt(3) and apr1 password hashes. *Bodo Moeller* * Add command line password options to the remaining applications. *Steve Henson* * Bug fix for BN_div_recp() for numerators with an even number of bits. *Ulf Möller* * More tests in bntest.c, and changed test_bn output. *Ulf Möller* * ./config recognizes MacOS X now. *Andy Polyakov* * Bug fix for BN_div() when the first words of num and divisor are equal (it gave wrong results if `(rem=(n1-q*d0)&BN_MASK2) < d0)`. *Ulf Möller* * Add support for various broken PKCS#8 formats, and command line options to produce them. *Steve Henson* * New functions BN_CTX_start(), BN_CTX_get() and BT_CTX_end() to get temporary BIGNUMs from a BN_CTX. *Ulf Möller* * Correct return values in BN_mod_exp_mont() and BN_mod_exp2_mont() for p == 0. *Ulf Möller* * Change the `SSLeay_add_all_*()` functions to `OpenSSL_add_all_*()` and include a #define from the old name to the new. The original intent was that statically linked binaries could for example just call SSLeay_add_all_ciphers() to just add ciphers to the table and not link with digests. This never worked because SSLeay_add_all_digests() and SSLeay_add_all_ciphers() were in the same source file so calling one would link with the other. They are now in separate source files. *Steve Henson* * Add a new -notext option to 'ca' and a -pubkey option to 'spkac'. *Steve Henson* * Use a less unusual form of the Miller-Rabin primality test (it used a binary algorithm for exponentiation integrated into the Miller-Rabin loop, our standard modexp algorithms are faster). *Bodo Moeller* * Support for the EBCDIC character set completed. *Martin Kraemer * * Source code cleanups: use const where appropriate, eliminate casts, use `void *` instead of `char *` in lhash. *Ulf Möller* * Bugfix: ssl3_send_server_key_exchange was not restartable (the state was not changed to SSL3_ST_SW_KEY_EXCH_B, and because of this the server could overwrite ephemeral keys that the client has already seen). *Bodo Moeller* * Turn DSA_is_prime into a macro that calls BN_is_prime, using 50 iterations of the Rabin-Miller test. DSA_generate_parameters now uses BN_is_prime_fasttest (with 50 iterations of the Rabin-Miller test as required by the appendix to FIPS PUB 186[-1]) instead of DSA_is_prime. As BN_is_prime_fasttest includes trial division, DSA parameter generation becomes much faster. This implies a change for the callback functions in DSA_is_prime and DSA_generate_parameters: The callback function is called once for each positive witness in the Rabin-Miller test, not just occasionally in the inner loop; and the parameters to the callback function now provide an iteration count for the outer loop rather than for the current invocation of the inner loop. DSA_generate_parameters additionally can call the callback function with an 'iteration count' of -1, meaning that a candidate has passed the trial division test (when q is generated from an application-provided seed, trial division is skipped). *Bodo Moeller* * New function BN_is_prime_fasttest that optionally does trial division before starting the Rabin-Miller test and has an additional BN_CTX * argument (whereas BN_is_prime always has to allocate at least one BN_CTX). 'callback(1, -1, cb_arg)' is called when a number has passed the trial division stage. *Bodo Moeller* * Fix for bug in CRL encoding. The validity dates weren't being handled as ASN1_TIME. *Steve Henson* * New -pkcs12 option to CA.pl script to write out a PKCS#12 file. *Steve Henson* * New function BN_pseudo_rand(). *Ulf Möller* * Clean up BN_mod_mul_montgomery(): replace the broken (and unreadable) bignum version of BN_from_montgomery() with the working code from SSLeay 0.9.0 (the word based version is faster anyway), and clean up the comments. *Ulf Möller* * Avoid a race condition in s2_clnt.c (function get_server_hello) that made it impossible to use the same SSL_SESSION data structure in SSL2 clients in multiple threads. *Bodo Moeller* * The return value of RAND_load_file() no longer counts bytes obtained by stat(). RAND_load_file(..., -1) is new and uses the complete file to seed the PRNG (previously an explicit byte count was required). *Ulf Möller, Bodo Möller* * Clean up CRYPTO_EX_DATA functions, some of these didn't have prototypes used `char *` instead of `void *` and had casts all over the place. *Steve Henson* * Make BN_generate_prime() return NULL on error if ret!=NULL. *Ulf Möller* * Retain source code compatibility for BN_prime_checks macro: BN_is_prime(..., BN_prime_checks, ...) now uses BN_prime_checks_for_size to determine the appropriate number of Rabin-Miller iterations. *Ulf Möller* * Diffie-Hellman uses "safe" primes: DH_check() return code renamed to DH_CHECK_P_NOT_SAFE_PRIME. (Check if this is true? OpenPGP calls them "strong".) *Ulf Möller* * Merge the functionality of "dh" and "gendh" programs into a new program "dhparam". The old programs are retained for now but will handle DH keys (instead of parameters) in future. *Steve Henson* * Make the ciphers, s_server and s_client programs check the return values when a new cipher list is set. *Steve Henson* * Enhance the SSL/TLS cipher mechanism to correctly handle the TLS 56bit ciphers. Before when the 56bit ciphers were enabled the sorting was wrong. The syntax for the cipher sorting has been extended to support sorting by cipher-strength (using the strength_bits hard coded in the tables). The new command is `@STRENGTH` (see also `doc/apps/ciphers.pod`). Fix a bug in the cipher-command parser: when supplying a cipher command string with an "undefined" symbol (neither command nor alphanumeric *A-Za-z0-9*, ssl_set_cipher_list used to hang in an endless loop. Now an error is flagged. Due to the strength-sorting extension, the code of the ssl_create_cipher_list() function was completely rearranged. I hope that the readability was also increased :-) *Lutz Jaenicke * * Minor change to 'x509' utility. The -CAcreateserial option now uses 1 for the first serial number and places 2 in the serial number file. This avoids problems when the root CA is created with serial number zero and the first user certificate has the same issuer name and serial number as the root CA. *Steve Henson* * Fixes to X509_ATTRIBUTE utilities, change the 'req' program so it uses the new code. Add documentation for this stuff. *Steve Henson* * Changes to X509_ATTRIBUTE utilities. These have been renamed from `X509_*()` to `X509at_*()` on the grounds that they don't handle X509 structures and behave in an analogous way to the X509v3 functions: they shouldn't be called directly but wrapper functions should be used instead. So we also now have some wrapper functions that call the X509at functions when passed certificate requests. (TO DO: similar things can be done with PKCS#7 signed and unsigned attributes, PKCS#12 attributes and a few other things. Some of these need some d2i or i2d and print functionality because they handle more complex structures.) *Steve Henson* * Add missing #ifndefs that caused missing symbols when building libssl as a shared library without RSA. Use #ifndef NO_SSL2 instead of NO_RSA in `ssl/s2*.c`. *Kris Kennaway , modified by Ulf Möller* * Precautions against using the PRNG uninitialized: RAND_bytes() now has a return value which indicates the quality of the random data (1 = ok, 0 = not seeded). Also an error is recorded on the thread's error queue. New function RAND_pseudo_bytes() generates output that is guaranteed to be unique but not unpredictable. RAND_add is like RAND_seed, but takes an extra argument for an entropy estimate (RAND_seed always assumes full entropy). *Ulf Möller* * Do more iterations of Rabin-Miller probable prime test (specifically, 3 for 1024-bit primes, 6 for 512-bit primes, 12 for 256-bit primes instead of only 2 for all lengths; see BN_prime_checks_for_size definition in crypto/bn/bn_prime.c for the complete table). This guarantees a false-positive rate of at most 2^-80 for random input. *Bodo Moeller* * Rewrite ssl3_read_n (ssl/s3_pkt.c) avoiding a couple of bugs. *Bodo Moeller* * New function X509_CTX_rget_chain() (renamed to X509_CTX_get1_chain in the 0.9.5 release), this returns the chain from an X509_CTX structure with a dup of the stack and all the X509 reference counts upped: so the stack will exist after X509_CTX_cleanup() has been called. Modify pkcs12.c to use this. Also make SSL_SESSION_print() print out the verify return code. *Steve Henson* * Add manpage for the pkcs12 command. Also change the default behaviour so MAC iteration counts are used unless the new -nomaciter option is used. This improves file security and only older versions of MSIE (4.0 for example) need it. *Steve Henson* * Honor the no-xxx Configure options when creating .DEF files. *Ulf Möller* * Add PKCS#10 attributes to field table: challengePassword, unstructuredName and unstructuredAddress. These are taken from draft PKCS#9 v2.0 but are compatible with v1.2 provided no international characters are used. More changes to X509_ATTRIBUTE code: allow the setting of types based on strings. Remove the 'loc' parameter when adding attributes because these will be a SET OF encoding which is sorted in ASN1 order. *Steve Henson* * Initial changes to the 'req' utility to allow request generation automation. This will allow an application to just generate a template file containing all the field values and have req construct the request. Initial support for X509_ATTRIBUTE handling. Stacks of these are used all over the place including certificate requests and PKCS#7 structures. They are currently handled manually where necessary with some primitive wrappers for PKCS#7. The new functions behave in a manner analogous to the X509 extension functions: they allow attributes to be looked up by NID and added. Later something similar to the X509V3 code would be desirable to automatically handle the encoding, decoding and printing of the more complex types. The string types like challengePassword can be handled by the string table functions. Also modified the multi byte string table handling. Now there is a 'global mask' which masks out certain types. The table itself can use the flag STABLE_NO_MASK to ignore the mask setting: this is useful when for example there is only one permissible type (as in countryName) and using the mask might result in no valid types at all. *Steve Henson* * Clean up 'Finished' handling, and add functions SSL_get_finished and SSL_get_peer_finished to allow applications to obtain the latest Finished messages sent to the peer or expected from the peer, respectively. (SSL_get_peer_finished is usually the Finished message actually received from the peer, otherwise the protocol will be aborted.) As the Finished message are message digests of the complete handshake (with a total of 192 bits for TLS 1.0 and more for SSL 3.0), they can be used for external authentication procedures when the authentication provided by SSL/TLS is not desired or is not enough. *Bodo Moeller* * Enhanced support for Alpha Linux is added. Now ./config checks if the host supports BWX extension and if Compaq C is present on the $PATH. Just exploiting of the BWX extension results in 20-30% performance kick for some algorithms, e.g. DES and RC4 to mention a couple. Compaq C in turn generates ~20% faster code for MD5 and SHA1. *Andy Polyakov* * Add support for MS "fast SGC". This is arguably a violation of the SSL3/TLS protocol. Netscape SGC does two handshakes: the first with weak crypto and after checking the certificate is SGC a second one with strong crypto. MS SGC stops the first handshake after receiving the server certificate message and sends a second client hello. Since a server will typically do all the time consuming operations before expecting any further messages from the client (server key exchange is the most expensive) there is little difference between the two. To get OpenSSL to support MS SGC we have to permit a second client hello message after we have sent server done. In addition we have to reset the MAC if we do get this second client hello. *Steve Henson* * Add a function 'd2i_AutoPrivateKey()' this will automatically decide if a DER encoded private key is RSA or DSA traditional format. Changed d2i_PrivateKey_bio() to use it. This is only needed for the "traditional" format DER encoded private key. Newer code should use PKCS#8 format which has the key type encoded in the ASN1 structure. Added DER private key support to pkcs8 application. *Steve Henson* * SSL 3/TLS 1 servers now don't request certificates when an anonymous ciphersuites has been selected (as required by the SSL 3/TLS 1 specifications). Exception: When SSL_VERIFY_FAIL_IF_NO_PEER_CERT is set, we interpret this as a request to violate the specification (the worst that can happen is a handshake failure, and 'correct' behaviour would result in a handshake failure anyway). *Bodo Moeller* * In SSL_CTX_add_session, take into account that there might be multiple SSL_SESSION structures with the same session ID (e.g. when two threads concurrently obtain them from an external cache). The internal cache can handle only one SSL_SESSION with a given ID, so if there's a conflict, we now throw out the old one to achieve consistency. *Bodo Moeller* * Add OIDs for idea and blowfish in CBC mode. This will allow both to be used in PKCS#5 v2.0 and S/MIME. Also add checking to some routines that use cipher OIDs: some ciphers do not have OIDs defined and so they cannot be used for S/MIME and PKCS#5 v2.0 for example. *Steve Henson* * Simplify the trust setting structure and code. Now we just have two sequences of OIDs for trusted and rejected settings. These will typically have values the same as the extended key usage extension and any application specific purposes. The trust checking code now has a default behaviour: it will just check for an object with the same NID as the passed id. Functions can be provided to override either the default behaviour or the behaviour for a given id. SSL client, server and email already have functions in place for compatibility: they check the NID and also return "trusted" if the certificate is self signed. *Steve Henson* * Add d2i,i2d bio/fp functions for PrivateKey: these convert the traditional format into an EVP_PKEY structure. *Steve Henson* * Add a password callback function PEM_cb() which either prompts for a password if usr_data is NULL or otherwise assumes it is a null terminated password. Allow passwords to be passed on command line environment or config files in a few more utilities. *Steve Henson* * Add a bunch of DER and PEM functions to handle PKCS#8 format private keys. Add some short names for PKCS#8 PBE algorithms and allow them to be specified on the command line for the pkcs8 and pkcs12 utilities. Update documentation. *Steve Henson* * Support for ASN1 "NULL" type. This could be handled before by using ASN1_TYPE but there wasn't any function that would try to read a NULL and produce an error if it couldn't. For compatibility we also have ASN1_NULL_new() and ASN1_NULL_free() functions but these are faked and don't allocate anything because they don't need to. *Steve Henson* * Initial support for MacOS is now provided. Examine INSTALL.MacOS for details. *Andy Polyakov, Roy Woods * * Rebuild of the memory allocation routines used by OpenSSL code and possibly others as well. The purpose is to make an interface that provide hooks so anyone can build a separate set of allocation and deallocation routines to be used by OpenSSL, for example memory pool implementations, or something else, which was previously hard since Malloc(), Realloc() and Free() were defined as macros having the values malloc, realloc and free, respectively (except for Win32 compilations). The same is provided for memory debugging code. OpenSSL already comes with functionality to find memory leaks, but this gives people a chance to debug other memory problems. With these changes, a new set of functions and macros have appeared: CRYPTO_set_mem_debug_functions() [F] CRYPTO_get_mem_debug_functions() [F] CRYPTO_dbg_set_options() [F] CRYPTO_dbg_get_options() [F] CRYPTO_malloc_debug_init() [M] The memory debug functions are NULL by default, unless the library is compiled with CRYPTO_MDEBUG or friends is defined. If someone wants to debug memory anyway, CRYPTO_malloc_debug_init() (which gives the standard debugging functions that come with OpenSSL) or CRYPTO_set_mem_debug_functions() (tells OpenSSL to use functions provided by the library user) must be used. When the standard debugging functions are used, CRYPTO_dbg_set_options can be used to request additional information: CRYPTO_dbg_set_options(V_CYRPTO_MDEBUG_xxx) corresponds to setting the CRYPTO_MDEBUG_xxx macro when compiling the library. Also, things like CRYPTO_set_mem_functions will always give the expected result (the new set of functions is used for allocation and deallocation) at all times, regardless of platform and compiler options. To finish it up, some functions that were never use in any other way than through macros have a new API and new semantic: CRYPTO_dbg_malloc() CRYPTO_dbg_realloc() CRYPTO_dbg_free() All macros of value have retained their old syntax. *Richard Levitte and Bodo Moeller* * Some S/MIME fixes. The OID for SMIMECapabilities was wrong, the ordering of SMIMECapabilities wasn't in "strength order" and there was a missing NULL in the AlgorithmIdentifier for the SHA1 signature algorithm. *Steve Henson* * Some ASN1 types with illegal zero length encoding (INTEGER, ENUMERATED and OBJECT IDENTIFIER) choked the ASN1 routines. *Frans Heymans , modified by Steve Henson* * Merge in my S/MIME library for OpenSSL. This provides a simple S/MIME API on top of the PKCS#7 code, a MIME parser (with enough functionality to handle multipart/signed properly) and a utility called 'smime' to call all this stuff. This is based on code I originally wrote for Celo who have kindly allowed it to be included in OpenSSL. *Steve Henson* * Add variants des_set_key_checked and des_set_key_unchecked of des_set_key (aka des_key_sched). Global variable des_check_key decides which of these is called by des_set_key; this way des_check_key behaves as it always did, but applications and the library itself, which was buggy for des_check_key == 1, have a cleaner way to pick the version they need. *Bodo Moeller* * New function PKCS12_newpass() which changes the password of a PKCS12 structure. *Steve Henson* * Modify X509_TRUST and X509_PURPOSE so it also uses a static and dynamic mix. In both cases the ids can be used as an index into the table. Also modified the X509_TRUST_add() and X509_PURPOSE_add() functions so they accept a list of the field values and the application doesn't need to directly manipulate the X509_TRUST structure. *Steve Henson* * Modify the ASN1_STRING_TABLE stuff so it also uses bsearch and doesn't need initialising. *Steve Henson* * Modify the way the V3 extension code looks up extensions. This now works in a similar way to the object code: we have some "standard" extensions in a static table which is searched with OBJ_bsearch() and the application can add dynamic ones if needed. The file crypto/x509v3/ext_dat.h now has the info: this file needs to be updated whenever a new extension is added to the core code and kept in ext_nid order. There is a simple program 'tabtest.c' which checks this. New extensions are not added too often so this file can readily be maintained manually. There are two big advantages in doing things this way. The extensions can be looked up immediately and no longer need to be "added" using X509V3_add_standard_extensions(): this function now does nothing. Side note: I get *lots* of email saying the extension code doesn't work because people forget to call this function. Also no dynamic allocation is done unless new extensions are added: so if we don't add custom extensions there is no need to call X509V3_EXT_cleanup(). *Steve Henson* * Modify enc utility's salting as follows: make salting the default. Add a magic header, so unsalted files fail gracefully instead of just decrypting to garbage. This is because not salting is a big security hole, so people should be discouraged from doing it. *Ben Laurie* * Fixes and enhancements to the 'x509' utility. It allowed a message digest to be passed on the command line but it only used this parameter when signing a certificate. Modified so all relevant operations are affected by the digest parameter including the -fingerprint and -x509toreq options. Also -x509toreq choked if a DSA key was used because it didn't fix the digest. *Steve Henson* * Initial certificate chain verify code. Currently tests the untrusted certificates for consistency with the verify purpose (which is set when the X509_STORE_CTX structure is set up) and checks the pathlength. There is a NO_CHAIN_VERIFY compilation option to keep the old behaviour: this is because it will reject chains with invalid extensions whereas every previous version of OpenSSL and SSLeay made no checks at all. Trust code: checks the root CA for the relevant trust settings. Trust settings have an initial value consistent with the verify purpose: e.g. if the verify purpose is for SSL client use it expects the CA to be trusted for SSL client use. However the default value can be changed to permit custom trust settings: one example of this would be to only trust certificates from a specific "secure" set of CAs. Also added X509_STORE_CTX_new() and X509_STORE_CTX_free() functions which should be used for version portability: especially since the verify structure is likely to change more often now. SSL integration. Add purpose and trust to SSL_CTX and SSL and functions to set them. If not set then assume SSL clients will verify SSL servers and vice versa. Two new options to the verify program: -untrusted allows a set of untrusted certificates to be passed in and -purpose which sets the intended purpose of the certificate. If a purpose is set then the new chain verify code is used to check extension consistency. *Steve Henson* * Support for the authority information access extension. *Steve Henson* * Modify RSA and DSA PEM read routines to transparently handle PKCS#8 format private keys. New *_PUBKEY_* functions that handle public keys in a format compatible with certificate SubjectPublicKeyInfo structures. Unfortunately there were already functions called *_PublicKey_* which used various odd formats so these are retained for compatibility: however the DSA variants were never in a public release so they have been deleted. Changed dsa/rsa utilities to handle the new format: note no releases ever handled public keys so we should be OK. The primary motivation for this change is to avoid the same fiasco that dogs private keys: there are several incompatible private key formats some of which are standard and some OpenSSL specific and require various evil hacks to allow partial transparent handling and even then it doesn't work with DER formats. Given the option anything other than PKCS#8 should be dumped: but the other formats have to stay in the name of compatibility. With public keys and the benefit of hindsight one standard format is used which works with EVP_PKEY, RSA or DSA structures: though it clearly returns an error if you try to read the wrong kind of key. Added a -pubkey option to the 'x509' utility to output the public key. Also rename the `EVP_PKEY_get_*()` to `EVP_PKEY_rget_*()` (renamed to `EVP_PKEY_get1_*()` in the OpenSSL 0.9.5 release) and add `EVP_PKEY_rset_*()` functions (renamed to `EVP_PKEY_set1_*()`) that do the same as the `EVP_PKEY_assign_*()` except they up the reference count of the added key (they don't "swallow" the supplied key). *Steve Henson* * Fixes to crypto/x509/by_file.c the code to read in certificates and CRLs would fail if the file contained no certificates or no CRLs: added a new function to read in both types and return the number read: this means that if none are read it will be an error. The DER versions of the certificate and CRL reader would always fail because it isn't possible to mix certificates and CRLs in DER format without choking one or the other routine. Changed this to just read a certificate: this is the best we can do. Also modified the code in `apps/verify.c` to take notice of return codes: it was previously attempting to read in certificates from NULL pointers and ignoring any errors: this is one reason why the cert and CRL reader seemed to work. It doesn't check return codes from the default certificate routines: these may well fail if the certificates aren't installed. *Steve Henson* * Code to support otherName option in GeneralName. *Steve Henson* * First update to verify code. Change the verify utility so it warns if it is passed a self signed certificate: for consistency with the normal behaviour. X509_verify has been modified to it will now verify a self signed certificate if *exactly* the same certificate appears in the store: it was previously impossible to trust a single self signed certificate. This means that: openssl verify ss.pem now gives a warning about a self signed certificate but openssl verify -CAfile ss.pem ss.pem is OK. *Steve Henson* * For servers, store verify_result in SSL_SESSION data structure (and add it to external session representation). This is needed when client certificate verifications fails, but an application-provided verification callback (set by SSL_CTX_set_cert_verify_callback) allows accepting the session anyway (i.e. leaves x509_store_ctx->error != X509_V_OK but returns 1): When the session is reused, we have to set ssl->verify_result to the appropriate error code to avoid security holes. *Bodo Moeller, problem pointed out by Lutz Jaenicke* * Fix a bug in the new PKCS#7 code: it didn't consider the case in PKCS7_dataInit() where the signed PKCS7 structure didn't contain any existing data because it was being created. *Po-Cheng Chen , slightly modified by Steve Henson* * Add a salt to the key derivation routines in enc.c. This forms the first 8 bytes of the encrypted file. Also add a -S option to allow a salt to be input on the command line. *Steve Henson* * New function X509_cmp(). Oddly enough there wasn't a function to compare two certificates. We do this by working out the SHA1 hash and comparing that. X509_cmp() will be needed by the trust code. *Steve Henson* * SSL_get1_session() is like SSL_get_session(), but increments the reference count in the SSL_SESSION returned. *Geoff Thorpe * * Fix for 'req': it was adding a null to request attributes. Also change the X509_LOOKUP and X509_INFO code to handle certificate auxiliary information. *Steve Henson* * Add support for 40 and 64 bit RC2 and RC4 algorithms: document the 'enc' command. *Steve Henson* * Add the possibility to add extra information to the memory leak detecting output, to form tracebacks, showing from where each allocation was originated: CRYPTO_push_info("constant string") adds the string plus current file name and line number to a per-thread stack, CRYPTO_pop_info() does the obvious, CRYPTO_remove_all_info() is like calling CYRPTO_pop_info() until the stack is empty. Also updated memory leak detection code to be multi-thread-safe. *Richard Levitte* * Add options -text and -noout to pkcs7 utility and delete the encryption options which never did anything. Update docs. *Steve Henson* * Add options to some of the utilities to allow the pass phrase to be included on either the command line (not recommended on OSes like Unix) or read from the environment. Update the manpages and fix a few bugs. *Steve Henson* * Add a few manpages for some of the openssl commands. *Steve Henson* * Fix the -revoke option in ca. It was freeing up memory twice, leaking and not finding already revoked certificates. *Steve Henson* * Extensive changes to support certificate auxiliary information. This involves the use of X509_CERT_AUX structure and X509_AUX functions. An X509_AUX function such as PEM_read_X509_AUX() can still read in a certificate file in the usual way but it will also read in any additional "auxiliary information". By doing things this way a fair degree of compatibility can be retained: existing certificates can have this information added using the new 'x509' options. Current auxiliary information includes an "alias" and some trust settings. The trust settings will ultimately be used in enhanced certificate chain verification routines: currently a certificate can only be trusted if it is self signed and then it is trusted for all purposes. *Steve Henson* * Fix assembler for Alpha (tested only on DEC OSF not Linux or `*BSD`). The problem was that one of the replacement routines had not been working since SSLeay releases. For now the offending routine has been replaced with non-optimised assembler. Even so, this now gives around 95% performance improvement for 1024 bit RSA signs. *Mark Cox* * Hack to fix PKCS#7 decryption when used with some unorthodox RC2 handling. Most clients have the effective key size in bits equal to the key length in bits: so a 40 bit RC2 key uses a 40 bit (5 byte) key. A few however don't do this and instead use the size of the decrypted key to determine the RC2 key length and the AlgorithmIdentifier to determine the effective key length. In this case the effective key length can still be 40 bits but the key length can be 168 bits for example. This is fixed by manually forcing an RC2 key into the EVP_PKEY structure because the EVP code can't currently handle unusual RC2 key sizes: it always assumes the key length and effective key length are equal. *Steve Henson* * Add a bunch of functions that should simplify the creation of X509_NAME structures. Now you should be able to do: X509_NAME_add_entry_by_txt(nm, "CN", MBSTRING_ASC, "Steve", -1, -1, 0); and have it automatically work out the correct field type and fill in the structures. The more adventurous can try: X509_NAME_add_entry_by_txt(nm, field, MBSTRING_UTF8, str, -1, -1, 0); and it will (hopefully) work out the correct multibyte encoding. *Steve Henson* * Change the 'req' utility to use the new field handling and multibyte copy routines. Before the DN field creation was handled in an ad hoc way in req, ca, and x509 which was rather broken and didn't support BMPStrings or UTF8Strings. Since some software doesn't implement BMPStrings or UTF8Strings yet, they can be enabled using the config file using the dirstring_type option. See the new comment in the default openssl.cnf for more info. *Steve Henson* * Make crypto/rand/md_rand.c more robust: - Assure unique random numbers after fork(). - Make sure that concurrent threads access the global counter and md serializably so that we never lose entropy in them or use exactly the same state in multiple threads. Access to the large state is not always serializable because the additional locking could be a performance killer, and md should be large enough anyway. *Bodo Moeller* * New file `apps/app_rand.c` with commonly needed functionality for handling the random seed file. Use the random seed file in some applications that previously did not: ca, dsaparam -genkey (which also ignored its '-rand' option), s_client, s_server, x509 (when signing). Except on systems with /dev/urandom, it is crucial to have a random seed file at least for key creation, DSA signing, and for DH exchanges; for RSA signatures we could do without one. gendh and gendsa (unlike genrsa) used to read only the first byte of each file listed in the '-rand' option. The function as previously found in genrsa is now in app_rand.c and is used by all programs that support '-rand'. *Bodo Moeller* * In RAND_write_file, use mode 0600 for creating files; don't just chmod when it may be too late. *Bodo Moeller* * Report an error from X509_STORE_load_locations when X509_LOOKUP_load_file or X509_LOOKUP_add_dir failed. *Bill Perry* * New function ASN1_mbstring_copy() this copies a string in either ASCII, Unicode, Universal (4 bytes per character) or UTF8 format into an ASN1_STRING type. A mask of permissible types is passed and it chooses the "minimal" type to use or an error if not type is suitable. *Steve Henson* * Add function equivalents to the various macros in asn1.h. The old macros are retained with an `M_` prefix. Code inside the library can use the `M_` macros. External code (including the openssl utility) should *NOT* in order to be "shared library friendly". *Steve Henson* * Add various functions that can check a certificate's extensions to see if it usable for various purposes such as SSL client, server or S/MIME and CAs of these types. This is currently VERY EXPERIMENTAL but will ultimately be used for certificate chain verification. Also added a -purpose flag to x509 utility to print out all the purposes. *Steve Henson* * Add a CRYPTO_EX_DATA to X509 certificate structure and associated functions. *Steve Henson* * New `X509V3_{X509,CRL,REVOKED}_get_d2i()` functions. These will search for, obtain and decode and extension and obtain its critical flag. This allows all the necessary extension code to be handled in a single function call. *Steve Henson* * RC4 tune-up featuring 30-40% performance improvement on most RISC platforms. See crypto/rc4/rc4_enc.c for further details. *Andy Polyakov* * New -noout option to asn1parse. This causes no output to be produced its main use is when combined with -strparse and -out to extract data from a file (which may not be in ASN.1 format). *Steve Henson* * Fix for pkcs12 program. It was hashing an invalid certificate pointer when producing the local key id. *Richard Levitte * * New option -dhparam in s_server. This allows a DH parameter file to be stated explicitly. If it is not stated then it tries the first server certificate file. The previous behaviour hard coded the filename "server.pem". *Steve Henson* * Add -pubin and -pubout options to the rsa and dsa commands. These allow a public key to be input or output. For example: openssl rsa -in key.pem -pubout -out pubkey.pem Also added necessary DSA public key functions to handle this. *Steve Henson* * Fix so PKCS7_dataVerify() doesn't crash if no certificates are contained in the message. This was handled by allowing X509_find_by_issuer_and_serial() to tolerate a NULL passed to it. *Steve Henson, reported by Sampo Kellomaki * * Fix for bug in d2i_ASN1_bytes(): other ASN1 functions add an extra null to the end of the strings whereas this didn't. This would cause problems if strings read with d2i_ASN1_bytes() were later modified. *Steve Henson, reported by Arne Ansper * * Fix for base64 decode bug. When a base64 bio reads only one line of data and it contains EOF it will end up returning an error. This is caused by input 46 bytes long. The cause is due to the way base64 BIOs find the start of base64 encoded data. They do this by trying a trial decode on each line until they find one that works. When they do a flag is set and it starts again knowing it can pass all the data directly through the decoder. Unfortunately it doesn't reset the context it uses. This means that if EOF is reached an attempt is made to pass two EOFs through the context and this causes the resulting error. This can also cause other problems as well. As is usual with these problems it takes *ages* to find and the fix is trivial: move one line. *Steve Henson, reported by ian@uns.ns.ac.yu (Ivan Nejgebauer)* * Ugly workaround to get s_client and s_server working under Windows. The old code wouldn't work because it needed to select() on sockets and the tty (for keypresses and to see if data could be written). Win32 only supports select() on sockets so we select() with a 1s timeout on the sockets and then see if any characters are waiting to be read, if none are present then we retry, we also assume we can always write data to the tty. This isn't nice because the code then blocks until we've received a complete line of data and it is effectively polling the keyboard at 1s intervals: however it's quite a bit better than not working at all :-) A dedicated Windows application might handle this with an event loop for example. *Steve Henson* * Enhance RSA_METHOD structure. Now there are two extra methods, rsa_sign and rsa_verify. When the RSA_FLAGS_SIGN_VER option is set these functions will be called when RSA_sign() and RSA_verify() are used. This is useful if rsa_pub_dec() and rsa_priv_enc() equivalents are not available. For this to work properly RSA_public_decrypt() and RSA_private_encrypt() should *not* be used: RSA_sign() and RSA_verify() must be used instead. This necessitated the support of an extra signature type NID_md5_sha1 for SSL signatures and modifications to the SSL library to use it instead of calling RSA_public_decrypt() and RSA_private_encrypt(). *Steve Henson* * Add new -verify -CAfile and -CApath options to the crl program, these will lookup a CRL issuers certificate and verify the signature in a similar way to the verify program. Tidy up the crl program so it no longer accesses structures directly. Make the ASN1 CRL parsing a bit less strict. It will now permit CRL extensions even if it is not a V2 CRL: this will allow it to tolerate some broken CRLs. *Steve Henson* * Initialize all non-automatic variables each time one of the openssl sub-programs is started (this is necessary as they may be started multiple times from the "OpenSSL>" prompt). *Lennart Bang, Bodo Moeller* * Preliminary compilation option RSA_NULL which disables RSA crypto without removing all other RSA functionality (this is what NO_RSA does). This is so (for example) those in the US can disable those operations covered by the RSA patent while allowing storage and parsing of RSA keys and RSA key generation. *Steve Henson* * Non-copying interface to BIO pairs. (still largely untested) *Bodo Moeller* * New function ASN1_tag2str() to convert an ASN1 tag to a descriptive ASCII string. This was handled independently in various places before. *Steve Henson* * New functions UTF8_getc() and UTF8_putc() that parse and generate UTF8 strings a character at a time. *Steve Henson* * Use client_version from client hello to select the protocol (s23_srvr.c) and for RSA client key exchange verification (s3_srvr.c), as required by the SSL 3.0/TLS 1.0 specifications. *Bodo Moeller* * Add various utility functions to handle SPKACs, these were previously handled by poking round in the structure internals. Added new function NETSCAPE_SPKI_print() to print out SPKAC and a new utility 'spkac' to print, verify and generate SPKACs. Based on an original idea from Massimiliano Pala but extensively modified. *Steve Henson* * RIPEMD160 is operational on all platforms and is back in 'make test'. *Andy Polyakov* * Allow the config file extension section to be overwritten on the command line. Based on an original idea from Massimiliano Pala . The new option is called -extensions and can be applied to ca, req and x509. Also -reqexts to override the request extensions in req and -crlexts to override the crl extensions in ca. *Steve Henson* * Add new feature to the SPKAC handling in ca. Now you can include the same field multiple times by preceding it by "XXXX." for example: 1.OU="Unit name 1" 2.OU="Unit name 2" this is the same syntax as used in the req config file. *Steve Henson* * Allow certificate extensions to be added to certificate requests. These are specified in a 'req_extensions' option of the req section of the config file. They can be printed out with the -text option to req but are otherwise ignored at present. *Steve Henson* * Fix a horrible bug in enc_read() in crypto/evp/bio_enc.c: if the first data read consists of only the final block it would not decrypted because EVP_CipherUpdate() would correctly report zero bytes had been decrypted. A misplaced 'break' also meant the decrypted final block might not be copied until the next read. *Steve Henson* * Initial support for DH_METHOD. Again based on RSA_METHOD. Also added a few extra parameters to the DH structure: these will be useful if for example we want the value of 'q' or implement X9.42 DH. *Steve Henson* * Initial support for DSA_METHOD. This is based on the RSA_METHOD and provides hooks that allow the default DSA functions or functions on a "per key" basis to be replaced. This allows hardware acceleration and hardware key storage to be handled without major modification to the library. Also added low-level modexp hooks and CRYPTO_EX structure and associated functions. *Steve Henson* * Add a new flag to memory BIOs, BIO_FLAG_MEM_RDONLY. This marks the BIO as "read only": it can't be written to and the buffer it points to will not be freed. Reading from a read only BIO is much more efficient than a normal memory BIO. This was added because there are several times when an area of memory needs to be read from a BIO. The previous method was to create a memory BIO and write the data to it, this results in two copies of the data and an O(n^2) reading algorithm. There is a new function BIO_new_mem_buf() which creates a read only memory BIO from an area of memory. Also modified the PKCS#7 routines to use read only memory BIOs. *Steve Henson* * Bugfix: ssl23_get_client_hello did not work properly when called in state SSL23_ST_SR_CLNT_HELLO_B, i.e. when the first 7 bytes of a SSLv2-compatible client hello for SSLv3 or TLSv1 could be read, but a retry condition occurred while trying to read the rest. *Bodo Moeller* * The PKCS7_ENC_CONTENT_new() function was setting the content type as NID_pkcs7_encrypted by default: this was wrong since this should almost always be NID_pkcs7_data. Also modified the PKCS7_set_type() to handle the encrypted data type: this is a more sensible place to put it and it allows the PKCS#12 code to be tidied up that duplicated this functionality. *Steve Henson* * Changed obj_dat.pl script so it takes its input and output files on the command line. This should avoid shell escape redirection problems under Win32. *Steve Henson* * Initial support for certificate extension requests, these are included in things like Xenroll certificate requests. Included functions to allow extensions to be obtained and added. *Steve Henson* * -crlf option to s_client and s_server for sending newlines as CRLF (as required by many protocols). *Bodo Moeller* ### Changes between 0.9.3a and 0.9.4 [09 Aug 1999] * Install libRSAglue.a when OpenSSL is built with RSAref. *Ralf S. Engelschall* * A few more `#ifndef NO_FP_API / #endif` pairs for consistency. *Andrija Antonijevic * * Fix -startdate and -enddate (which was missing) arguments to 'ca' program. *Steve Henson* * New function DSA_dup_DH, which duplicates DSA parameters/keys as DH parameters/keys (q is lost during that conversion, but the resulting DH parameters contain its length). For 1024-bit p, DSA_generate_parameters followed by DSA_dup_DH is much faster than DH_generate_parameters (which creates parameters where `p = 2*q + 1`), and also the smaller q makes DH computations much more efficient (160-bit exponentiation instead of 1024-bit exponentiation); so this provides a convenient way to support DHE ciphersuites in SSL/TLS servers (see ssl/ssltest.c). It is of utter importance to use SSL_CTX_set_options(s_ctx, SSL_OP_SINGLE_DH_USE); or SSL_set_options(s_ctx, SSL_OP_SINGLE_DH_USE); when such DH parameters are used, because otherwise small subgroup attacks may become possible! *Bodo Moeller* * Avoid memory leak in i2d_DHparams. *Bodo Moeller* * Allow the -k option to be used more than once in the enc program: this allows the same encrypted message to be read by multiple recipients. *Steve Henson* * New function OBJ_obj2txt(buf, buf_len, a, no_name), this converts an ASN1_OBJECT to a text string. If the "no_name" parameter is set then it will always use the numerical form of the OID, even if it has a short or long name. *Steve Henson* * Added an extra RSA flag: RSA_FLAG_EXT_PKEY. Previously the rsa_mod_exp method only got called if p,q,dmp1,dmq1,iqmp components were present, otherwise bn_mod_exp was called. In the case of hardware keys for example no private key components need be present and it might store extra data in the RSA structure, which cannot be accessed from bn_mod_exp. By setting RSA_FLAG_EXT_PKEY rsa_mod_exp will always be called for private key operations. *Steve Henson* * Added support for SPARC Linux. *Andy Polyakov* * pem_password_cb function type incompatibly changed from typedef int pem_password_cb(char *buf, int size, int rwflag); to ....(char *buf, int size, int rwflag, void *userdata); so that applications can pass data to their callbacks: The `PEM[_ASN1]_{read,write}...` functions and macros now take an additional void * argument, which is just handed through whenever the password callback is called. *Damien Miller ; tiny changes by Bodo Moeller* New function SSL_CTX_set_default_passwd_cb_userdata. Compatibility note: As many C implementations push function arguments onto the stack in reverse order, the new library version is likely to interoperate with programs that have been compiled with the old pem_password_cb definition (PEM_whatever takes some data that happens to be on the stack as its last argument, and the callback just ignores this garbage); but there is no guarantee whatsoever that this will work. * The -DPLATFORM="\"$(PLATFORM)\"" definition and the similar -DCFLAGS=... (both in crypto/Makefile.ssl for use by crypto/cversion.c) caused problems not only on Windows, but also on some Unix platforms. To avoid problematic command lines, these definitions are now in an auto-generated file crypto/buildinf.h (created by crypto/Makefile.ssl for standard "make" builds, by util/mk1mf.pl for "mk1mf" builds). *Bodo Moeller* * MIPS III/IV assembler module is reimplemented. *Andy Polyakov* * More DES library cleanups: remove references to srand/rand and delete an unused file. *Ulf Möller* * Add support for the free Netwide assembler (NASM) under Win32, since not many people have MASM (ml) and it can be hard to obtain. This is currently experimental but it seems to work OK and pass all the tests. Check out INSTALL.W32 for info. *Steve Henson* * Fix memory leaks in s3_clnt.c: All non-anonymous SSL3/TLS1 connections without temporary keys kept an extra copy of the server key, and connections with temporary keys did not free everything in case of an error. *Bodo Moeller* * New function RSA_check_key and new openssl rsa option -check for verifying the consistency of RSA keys. *Ulf Moeller, Bodo Moeller* * Various changes to make Win32 compile work: 1. Casts to avoid "loss of data" warnings in p5_crpt2.c 2. Change unsigned int to int in b_dump.c to avoid "signed/unsigned comparison" warnings. 3. Add `sk__sort` to DEF file generator and do make update. *Steve Henson* * Add a debugging option to PKCS#5 v2 key generation function: when you #define DEBUG_PKCS5V2 passwords, salts, iteration counts and derived keys are printed to stderr. *Steve Henson* * Copy the flags in ASN1_STRING_dup(). *Roman E. Pavlov * * The x509 application mishandled signing requests containing DSA keys when the signing key was also DSA and the parameters didn't match. It was supposed to omit the parameters when they matched the signing key: the verifying software was then supposed to automatically use the CA's parameters if they were absent from the end user certificate. Omitting parameters is no longer recommended. The test was also the wrong way round! This was probably due to unusual behaviour in EVP_cmp_parameters() which returns 1 if the parameters match. This meant that parameters were omitted when they *didn't* match and the certificate was useless. Certificates signed with 'ca' didn't have this bug. *Steve Henson, reported by Doug Erickson * * Memory leak checking (-DCRYPTO_MDEBUG) had some problems. The interface is as follows: Applications can use CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON) aka MemCheck_start(), CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF) aka MemCheck_stop(); "off" is now the default. The library internally uses CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE) aka MemCheck_off(), CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE) aka MemCheck_on() to disable memory-checking temporarily. Some inconsistent states that previously were possible (and were even the default) are now avoided. -DCRYPTO_MDEBUG_TIME is new and additionally stores the current time with each memory chunk allocated; this is occasionally more helpful than just having a counter. -DCRYPTO_MDEBUG_THREAD is also new and adds the thread ID. -DCRYPTO_MDEBUG_ALL enables all of the above, plus any future extensions. *Bodo Moeller* * Introduce "mode" for SSL structures (with defaults in SSL_CTX), which largely parallels "options", but is for changing API behaviour, whereas "options" are about protocol behaviour. Initial "mode" flags are: SSL_MODE_ENABLE_PARTIAL_WRITE Allow SSL_write to report success when a single record has been written. SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER Don't insist that SSL_write retries use the same buffer location. (But all of the contents must be copied!) *Bodo Moeller* * Bugfix: SSL_set_options ignored its parameter, only SSL_CTX_set_options worked. * Fix problems with no-hmac etc. *Ulf Möller, pointed out by Brian Wellington * * New functions RSA_get_default_method(), RSA_set_method() and RSA_get_method(). These allows replacement of RSA_METHODs without having to mess around with the internals of an RSA structure. *Steve Henson* * Fix memory leaks in DSA_do_sign and DSA_is_prime. Also really enable memory leak checks in openssl.c and in some test programs. *Chad C. Mulligan, Bodo Moeller* * Fix a bug in d2i_ASN1_INTEGER() and i2d_ASN1_INTEGER() which can mess up the length of negative integers. This has now been simplified to just store the length when it is first determined and use it later, rather than trying to keep track of where data is copied and updating it to point to the end. *Steve Henson, reported by Brien Wheeler * * Add a new function PKCS7_signatureVerify. This allows the verification of a PKCS#7 signature but with the signing certificate passed to the function itself. This contrasts with PKCS7_dataVerify which assumes the certificate is present in the PKCS#7 structure. This isn't always the case: certificates can be omitted from a PKCS#7 structure and be distributed by "out of band" means (such as a certificate database). *Steve Henson* * Complete the `PEM_*` macros with DECLARE_PEM versions to replace the function prototypes in pem.h, also change util/mkdef.pl to add the necessary function names. *Steve Henson* * mk1mf.pl (used by Windows builds) did not properly read the options set by Configure in the top level Makefile, and Configure was not even able to write more than one option correctly. Fixed, now "no-idea no-rc5 -DCRYPTO_MDEBUG" etc. works as intended. *Bodo Moeller* * New functions CONF_load_bio() and CONF_load_fp() to allow a config file to be loaded from a BIO or FILE pointer. The BIO version will for example allow memory BIOs to contain config info. *Steve Henson* * New function "CRYPTO_num_locks" that returns CRYPTO_NUM_LOCKS. Whoever hopes to achieve shared-library compatibility across versions must use this, not the compile-time macro. (Exercise 0.9.4: Which is the minimum library version required by such programs?) Note: All this applies only to multi-threaded programs, others don't need locks. *Bodo Moeller* * Add missing case to s3_clnt.c state machine -- one of the new SSL tests through a BIO pair triggered the default case, i.e. SSLerr(...,SSL_R_UNKNOWN_STATE). *Bodo Moeller* * New "BIO pair" concept (crypto/bio/bss_bio.c) so that applications can use the SSL library even if none of the specific BIOs is appropriate. *Bodo Moeller* * Fix a bug in i2d_DSAPublicKey() which meant it returned the wrong value for the encoded length. *Jeon KyoungHo * * Add initial documentation of the X509V3 functions. *Steve Henson* * Add a new pair of functions PEM_write_PKCS8PrivateKey() and PEM_write_bio_PKCS8PrivateKey() that are equivalent to PEM_write_PrivateKey() and PEM_write_bio_PrivateKey() but use the more secure PKCS#8 private key format with a high iteration count. *Steve Henson* * Fix determination of Perl interpreter: A perl or perl5 *directory* in $PATH was also accepted as the interpreter. *Ralf S. Engelschall* * Fix demos/sign/sign.c: well there wasn't anything strictly speaking wrong with it but it was very old and did things like calling PEM_ASN1_read() directly and used MD5 for the hash not to mention some unusual formatting. *Steve Henson* * Fix demos/selfsign.c: it used obsolete and deleted functions, changed to use the new extension code. *Steve Henson* * Implement the PEM_read/PEM_write functions in crypto/pem/pem_all.c with macros. This should make it easier to change their form, add extra arguments etc. Fix a few PEM prototypes which didn't have cipher as a constant. *Steve Henson* * Add to configuration table a new entry that can specify an alternative name for unistd.h (for pre-POSIX systems); we need this for NeXTstep, according to Mark Crispin . *Bodo Moeller* * DES CBC did not update the IV. Weird. *Ben Laurie* lse des_cbc_encrypt does not update the IV, but des_ncbc_encrypt does. Changing the behaviour of the former might break existing programs -- where IV updating is needed, des_ncbc_encrypt can be used. ndif * When bntest is run from "make test" it drives bc to check its calculations, as well as internally checking them. If an internal check fails, it needs to cause bc to give a non-zero result or make test carries on without noticing the failure. Fixed. *Ben Laurie* * DES library cleanups. *Ulf Möller* * Add support for PKCS#5 v2.0 PBE algorithms. This will permit PKCS#8 to be used with any cipher unlike PKCS#5 v1.5 which can at most handle 64 bit ciphers. NOTE: although the key derivation function has been verified against some published test vectors it has not been extensively tested yet. Added a -v2 "cipher" option to pkcs8 application to allow the use of v2.0. *Steve Henson* * Instead of "mkdir -p", which is not fully portable, use new Perl script "util/mkdir-p.pl". *Bodo Moeller* * Rewrite the way password based encryption (PBE) is handled. It used to assume that the ASN1 AlgorithmIdentifier parameter was a PBEParameter structure. This was true for the PKCS#5 v1.5 and PKCS#12 PBE algorithms but doesn't apply to PKCS#5 v2.0 where it can be something else. Now the 'parameter' field of the AlgorithmIdentifier is passed to the underlying key generation function so it must do its own ASN1 parsing. This has also changed the EVP_PBE_CipherInit() function which now has a 'parameter' argument instead of literal salt and iteration count values and the function EVP_PBE_ALGOR_CipherInit() has been deleted. *Steve Henson* * Support for PKCS#5 v1.5 compatible password based encryption algorithms and PKCS#8 functionality. New 'pkcs8' application linked to openssl. Needed to change the PEM_STRING_EVP_PKEY value which was just "PRIVATE KEY" because this clashed with PKCS#8 unencrypted string. Since this value was just used as a "magic string" and not used directly its value doesn't matter. *Steve Henson* * Introduce some semblance of const correctness to BN. Shame C doesn't support mutable. *Ben Laurie* * "linux-sparc64" configuration (ultrapenguin). *Ray Miller * "linux-sparc" configuration. *Christian Forster * * config now generates no-xxx options for missing ciphers. *Ulf Möller* * Support the EBCDIC character set (work in progress). File ebcdic.c not yet included because it has a different license. *Martin Kraemer * * Support BS2000/OSD-POSIX. *Martin Kraemer * * Make callbacks for key generation use `void *` instead of `char *`. *Ben Laurie* * Make S/MIME samples compile (not yet tested). *Ben Laurie* * Additional typesafe stacks. *Ben Laurie* * New configuration variants "bsdi-elf-gcc" (BSD/OS 4.x). *Bodo Moeller* ### Changes between 0.9.3 and 0.9.3a [29 May 1999] * New configuration variant "sco5-gcc". * Updated some demos. *Sean O Riordain, Wade Scholine* * Add missing BIO_free at exit of pkcs12 application. *Wu Zhigang* * Fix memory leak in conf.c. *Steve Henson* * Updates for Win32 to assembler version of MD5. *Steve Henson* * Set #! path to perl in `apps/der_chop` to where we found it instead of using a fixed path. *Bodo Moeller* * SHA library changes for irix64-mips4-cc. *Andy Polyakov* * Improvements for VMS support. *Richard Levitte* ### Changes between 0.9.2b and 0.9.3 [24 May 1999] * Bignum library bug fix. IRIX 6 passes "make test" now! This also avoids the problems with SC4.2 and unpatched SC5. *Andy Polyakov * * New functions sk_num, sk_value and sk_set to replace the previous macros. These are required because of the typesafe stack would otherwise break existing code. If old code used a structure member which used to be STACK and is now STACK_OF (for example cert in a PKCS7_SIGNED structure) with sk_num or sk_value it would produce an error because the num, data members are not present in STACK_OF. Now it just produces a warning. sk_set replaces the old method of assigning a value to sk_value (e.g. sk_value(x, i) = y) which the library used in a few cases. Any code that does this will no longer work (and should use sk_set instead) but this could be regarded as a "questionable" behaviour anyway. *Steve Henson* * Fix most of the other PKCS#7 bugs. The "experimental" code can now correctly handle encrypted S/MIME data. *Steve Henson* * Change type of various DES function arguments from des_cblock (which means, in function argument declarations, pointer to char) to des_cblock * (meaning pointer to array with 8 char elements), which allows the compiler to do more typechecking; it was like that back in SSLeay, but with lots of ugly casts. Introduce new type const_des_cblock. *Bodo Moeller* * Reorganise the PKCS#7 library and get rid of some of the more obvious problems: find RecipientInfo structure that matches recipient certificate and initialise the ASN1 structures properly based on passed cipher. *Steve Henson* * Belatedly make the BN tests actually check the results. *Ben Laurie* * Fix the encoding and decoding of negative ASN1 INTEGERS and conversion to and from BNs: it was completely broken. New compilation option NEG_PUBKEY_BUG to allow for some broken certificates that encode public key elements as negative integers. *Steve Henson* * Reorganize and speed up MD5. *Andy Polyakov * * VMS support. *Richard Levitte * * New option -out to asn1parse to allow the parsed structure to be output to a file. This is most useful when combined with the -strparse option to examine the output of things like OCTET STRINGS. *Steve Henson* * Make SSL library a little more fool-proof by not requiring any longer that `SSL_set_{accept,connect}_state` be called before `SSL_{accept,connect}` may be used (`SSL_set_..._state` is omitted in many applications because usually everything *appeared* to work as intended anyway -- now it really works as intended). *Bodo Moeller* * Move openssl.cnf out of lib/. *Ulf Möller* * Fix various things to let OpenSSL even pass "egcc -pipe -O2 -Wall -Wshadow -Wpointer-arith -Wcast-align -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Winline" with EGCS 1.1.2+ *Ralf S. Engelschall* * Various fixes to the EVP and PKCS#7 code. It may now be able to handle PKCS#7 enveloped data properly. *Sebastian Akerman , modified by Steve* * Create a duplicate of the SSL_CTX's CERT in SSL_new instead of copying pointers. The cert_st handling is changed by this in various ways (and thus what used to be known as ctx->default_cert is now called ctx->cert, since we don't resort to `s->ctx->[default_]cert` any longer when s->cert does not give us what we need). ssl_cert_instantiate becomes obsolete by this change. As soon as we've got the new code right (possibly it already is?), we have solved a couple of bugs of the earlier code where s->cert was used as if it could not have been shared with other SSL structures. Note that using the SSL API in certain dirty ways now will result in different behaviour than observed with earlier library versions: Changing settings for an `SSL_CTX *ctx` after having done s = SSL_new(ctx) does not influence s as it used to. In order to clean up things more thoroughly, inside SSL_SESSION we don't use CERT any longer, but a new structure SESS_CERT that holds per-session data (if available); currently, this is the peer's certificate chain and, for clients, the server's certificate and temporary key. CERT holds only those values that can have meaningful defaults in an SSL_CTX. *Bodo Moeller* * New function X509V3_EXT_i2d() to create an X509_EXTENSION structure from the internal representation. Various PKCS#7 fixes: remove some evil casts and set the enc_dig_alg field properly based on the signing key type. *Steve Henson* * Allow PKCS#12 password to be set from the command line or the environment. Let 'ca' get its config file name from the environment variables "OPENSSL_CONF" or "SSLEAY_CONF" (for consistency with 'req' and 'x509'). *Steve Henson* * Allow certificate policies extension to use an IA5STRING for the organization field. This is contrary to the PKIX definition but VeriSign uses it and IE5 only recognises this form. Document 'x509' extension option. *Steve Henson* * Add PEDANTIC compiler flag to allow compilation with gcc -pedantic, without disallowing inline assembler and the like for non-pedantic builds. *Ben Laurie* * Support Borland C++ builder. *Janez Jere , modified by Ulf Möller* * Support Mingw32. *Ulf Möller* * SHA-1 cleanups and performance enhancements. *Andy Polyakov * * Sparc v8plus assembler for the bignum library. *Andy Polyakov * * Accept any -xxx and +xxx compiler options in Configure. *Ulf Möller* * Update HPUX configuration. *Anonymous* * Add missing `sk__unshift()` function to safestack.h *Ralf S. Engelschall* * New function SSL_CTX_use_certificate_chain_file that sets the "extra_cert"s in addition to the certificate. (This makes sense only for "PEM" format files, as chains as a whole are not DER-encoded.) *Bodo Moeller* * Support verify_depth from the SSL API. x509_vfy.c had what can be considered an off-by-one-error: Its depth (which was not part of the external interface) was actually counting the number of certificates in a chain; now it really counts the depth. *Bodo Moeller* * Bugfix in crypto/x509/x509_cmp.c: The SSLerr macro was used instead of X509err, which often resulted in confusing error messages since the error codes are not globally unique (e.g. an alleged error in ssl3_accept when a certificate didn't match the private key). * New function SSL_CTX_set_session_id_context that allows to set a default value (so that you don't need SSL_set_session_id_context for each connection using the SSL_CTX). *Bodo Moeller* * OAEP decoding bug fix. *Ulf Möller* * Support INSTALL_PREFIX for package builders, as proposed by David Harris. *Bodo Moeller* * New Configure options "threads" and "no-threads". For systems where the proper compiler options are known (currently Solaris and Linux), "threads" is the default. *Bodo Moeller* * New script util/mklink.pl as a faster substitute for util/mklink.sh. *Bodo Moeller* * Install various scripts to $(OPENSSLDIR)/misc, not to $(INSTALLTOP)/bin -- they shouldn't clutter directories such as /usr/local/bin. *Bodo Moeller* * "make linux-shared" to build shared libraries. *Niels Poppe * * New Configure option `no-` (rsa, idea, rc5, ...). *Ulf Möller* * Add the PKCS#12 API documentation to openssl.txt. Preliminary support for extension adding in x509 utility. *Steve Henson* * Remove NOPROTO sections and error code comments. *Ulf Möller* * Partial rewrite of the DEF file generator to now parse the ANSI prototypes. *Steve Henson* * New Configure options --prefix=DIR and --openssldir=DIR. *Ulf Möller* * Complete rewrite of the error code script(s). It is all now handled by one script at the top level which handles error code gathering, header rewriting and C source file generation. It should be much better than the old method: it now uses a modified version of Ulf's parser to read the ANSI prototypes in all header files (thus the old K&R definitions aren't needed for error creation any more) and do a better job of translating function codes into names. The old 'ASN1 error code embedded in a comment' is no longer necessary and it doesn't use .err files which have now been deleted. Also the error code call doesn't have to appear all on one line (which resulted in some large lines...). *Steve Henson* * Change #include filenames from `` to ``. *Bodo Moeller* * Change behaviour of ssl2_read when facing length-0 packets: Don't return 0 (which usually indicates a closed connection), but continue reading. *Bodo Moeller* * Fix some race conditions. *Bodo Moeller* * Add support for CRL distribution points extension. Add Certificate Policies and CRL distribution points documentation. *Steve Henson* * Move the autogenerated header file parts to crypto/opensslconf.h. *Ulf Möller* * Fix new 56-bit DES export ciphersuites: they were using 7 bytes instead of 8 of keying material. Merlin has also confirmed interop with this fix between OpenSSL and Baltimore C/SSL 2.0 and J/SSL 2.0. *Merlin Hughes * * Fix lots of warnings. *Richard Levitte * * In add_cert_dir() in crypto/x509/by_dir.c, break out of the loop if the directory spec didn't end with a LIST_SEPARATOR_CHAR. *Richard Levitte * * Fix problems with sizeof(long) == 8. *Andy Polyakov * * Change functions to ANSI C. *Ulf Möller* * Fix typos in error codes. *Martin Kraemer , Ulf Möller* * Remove defunct assembler files from Configure. *Ulf Möller* * SPARC v8 assembler BIGNUM implementation. *Andy Polyakov * * Support for Certificate Policies extension: both print and set. Various additions to support the r2i method this uses. *Steve Henson* * A lot of constification, and fix a bug in X509_NAME_oneline() that could return a const string when you are expecting an allocated buffer. *Ben Laurie* * Add support for ASN1 types UTF8String and VISIBLESTRING, also the CHOICE types DirectoryString and DisplayText. *Steve Henson* * Add code to allow r2i extensions to access the configuration database, add an LHASH database driver and add several ctx helper functions. *Steve Henson* * Fix an evil bug in bn_expand2() which caused various BN functions to fail when they extended the size of a BIGNUM. *Steve Henson* * Various utility functions to handle SXNet extension. Modify mkdef.pl to support typesafe stack. *Steve Henson* * Fix typo in SSL_[gs]et_options(). *Nils Frostberg * * Delete various functions and files that belonged to the (now obsolete) old X509V3 handling code. *Steve Henson* * New Configure option "rsaref". *Ulf Möller* * Don't auto-generate pem.h. *Bodo Moeller* * Introduce type-safe ASN.1 SETs. *Ben Laurie* * Convert various additional casted stacks to type-safe STACK_OF() variants. *Ben Laurie, Ralf S. Engelschall, Steve Henson* * Introduce type-safe STACKs. This will almost certainly break lots of code that links with OpenSSL (well at least cause lots of warnings), but fear not: the conversion is trivial, and it eliminates loads of evil casts. A few STACKed things have been converted already. Feel free to convert more. In the fullness of time, I'll do away with the STACK type altogether. *Ben Laurie* * Add `openssl ca -revoke ` facility which revokes a certificate specified in `` by updating the entry in the index.txt file. This way one no longer has to edit the index.txt file manually for revoking a certificate. The -revoke option does the gory details now. *Massimiliano Pala , Ralf S. Engelschall* * Fix `openssl crl -noout -text` combination where `-noout` killed the `-text` option at all and this way the `-noout -text` combination was inconsistent in `openssl crl` with the friends in `openssl x509|rsa|dsa`. *Ralf S. Engelschall* * Make sure a corresponding plain text error message exists for the X509_V_ERR_CERT_REVOKED/23 error number which can occur when a verify callback function determined that a certificate was revoked. *Ralf S. Engelschall* * Bugfix: In test/testenc, don't test `openssl ` for ciphers that were excluded, e.g. by -DNO_IDEA. Also, test all available ciphers including rc5, which was forgotten until now. In order to let the testing shell script know which algorithms are available, a new (up to now undocumented) command `openssl list-cipher-commands` is used. *Bodo Moeller* * Bugfix: s_client occasionally would sleep in select() when it should have checked SSL_pending() first. *Bodo Moeller* * New functions DSA_do_sign and DSA_do_verify to provide access to the raw DSA values prior to ASN.1 encoding. *Ulf Möller* * Tweaks to Configure *Niels Poppe * * Add support for PKCS#5 v2.0 ASN1 PBES2 structures. No other support, yet... *Steve Henson* * New variables $(RANLIB) and $(PERL) in the Makefiles. *Ulf Möller* * New config option to avoid instructions that are illegal on the 80386. The default code is faster, but requires at least a 486. *Ulf Möller* * Got rid of old SSL2_CLIENT_VERSION (inconsistently used) and SSL2_SERVER_VERSION (not used at all) macros, which are now the same as SSL2_VERSION anyway. *Bodo Moeller* * New "-showcerts" option for s_client. *Bodo Moeller* * Still more PKCS#12 integration. Add pkcs12 application to openssl application. Various cleanups and fixes. *Steve Henson* * More PKCS#12 integration. Add new pkcs12 directory with Makefile.ssl and modify error routines to work internally. Add error codes and PBE init to library startup routines. *Steve Henson* * Further PKCS#12 integration. Added password based encryption, PKCS#8 and packing functions to asn1 and evp. Changed function names and error codes along the way. *Steve Henson* * PKCS12 integration: and so it begins... First of several patches to slowly integrate PKCS#12 functionality into OpenSSL. Add PKCS#12 objects to objects.h *Steve Henson* * Add a new 'indent' option to some X509V3 extension code. Initial ASN1 and display support for Thawte strong extranet extension. *Steve Henson* * Add LinuxPPC support. *Jeff Dubrule * * Get rid of redundant BN file bn_mulw.c, and rename bn_div64 to bn_div_words in alpha.s. *Hannes Reinecke and Ben Laurie* * Make sure the RSA OAEP test is skipped under -DRSAref because OAEP isn't supported when OpenSSL is built with RSAref. *Ulf Moeller * * Move definitions of IS_SET/IS_SEQUENCE inside crypto/asn1/asn1.h so they no longer are missing under -DNOPROTO. *Soren S. Jorvang * ### Changes between 0.9.1c and 0.9.2b [22 Mar 1999] * Make SSL_get_peer_cert_chain() work in servers. Unfortunately, it still doesn't work when the session is reused. Coming soon! *Ben Laurie* * Fix a security hole, that allows sessions to be reused in the wrong context thus bypassing client cert protection! All software that uses client certs and session caches in multiple contexts NEEDS PATCHING to allow session reuse! A fuller solution is in the works. *Ben Laurie, problem pointed out by Holger Reif, Bodo Moeller (and ???)* * Some more source tree cleanups (removed obsolete files crypto/bf/asm/bf586.pl, test/test.txt and crypto/sha/asm/f.s; changed permission on "config" script to be executable) and a fix for the INSTALL document. *Ulf Moeller * * Remove some legacy and erroneous uses of malloc, free instead of Malloc, Free. *Lennart Bang , with minor changes by Steve* * Make rsa_oaep_test return non-zero on error. *Ulf Moeller * * Add support for native Solaris shared libraries. Configure solaris-sparc-sc4-pic, make, then run shlib/solaris-sc4.sh. It'd be nice if someone would make that last step automatic. *Matthias Loepfe * * ctx_size was not built with the right compiler during "make links". Fixed. *Ben Laurie* * Change the meaning of 'ALL' in the cipher list. It now means "everything except NULL ciphers". This means the default cipher list will no longer enable NULL ciphers. They need to be specifically enabled e.g. with the string "DEFAULT:eNULL". *Steve Henson* * Fix to RSA private encryption routines: if p < q then it would occasionally produce an invalid result. This will only happen with externally generated keys because OpenSSL (and SSLeay) ensure p > q. *Steve Henson* * Be less restrictive and allow also `perl util/perlpath.pl /path/to/bin/perl` in addition to `perl util/perlpath.pl /path/to/bin`, because this way one can also use an interpreter named `perl5` (which is usually the name of Perl 5.xxx on platforms where an Perl 4.x is still installed as `perl`). *Matthias Loepfe * * Let util/clean-depend.pl work also with older Perl 5.00x versions. *Matthias Loepfe * * Fix Makefile.org so CC,CFLAG etc are passed to 'make links' add advapi32.lib to Win32 build and change the pem test comparison to fc.exe (thanks to Ulrich Kroener for the suggestion). Fix misplaced ASNI prototypes and declarations in evp.h and crypto/des/ede_cbcm_enc.c. *Steve Henson* * DES quad checksum was broken on big-endian architectures. Fixed. *Ben Laurie* * Comment out two functions in bio.h that aren't implemented. Fix up the Win32 test batch file so it (might) work again. The Win32 test batch file is horrible: I feel ill.... *Steve Henson* * Move various #ifdefs around so NO_SYSLOG, NO_DIRENT etc are now selected in e_os.h. Audit of header files to check ANSI and non ANSI sections: 10 functions were absent from non ANSI section and not exported from Windows DLLs. Fixed up libeay.num for new functions. *Steve Henson* * Make `openssl version` output lines consistent. *Ralf S. Engelschall* * Fix Win32 symbol export lists for BIO functions: Added BIO_get_ex_new_index, BIO_get_ex_num, BIO_get_ex_data and BIO_set_ex_data to ms/libeay{16,32}.def. *Ralf S. Engelschall* * Second round of fixing the OpenSSL perl/ stuff. It now at least compiled fine under Unix and passes some trivial tests I've now added. But the whole stuff is horribly incomplete, so a README.1ST with a disclaimer was added to make sure no one expects that this stuff really works in the OpenSSL 0.9.2 release. Additionally I've started to clean the XS sources up and fixed a few little bugs and inconsistencies in OpenSSL.{pm,xs} and openssl_bio.xs. *Ralf S. Engelschall* * Fix the generation of two part addresses in perl. *Kenji Miyake , integrated by Ben Laurie* * Add config entry for Linux on MIPS. *John Tobey * * Make links whenever Configure is run, unless we are on Windoze. *Ben Laurie* * Permit extensions to be added to CRLs using crl_section in openssl.cnf. Currently only issuerAltName and AuthorityKeyIdentifier make any sense in CRLs. *Steve Henson* * Add a useful kludge to allow package maintainers to specify compiler and other platforms details on the command line without having to patch the Configure script every time: One now can use `perl Configure :
`, i.e. platform ids are allowed to have details appended to them (separated by colons). This is treated as there would be a static pre-configured entry in Configure's %table under key `` with value `
` and `perl Configure ` is called. So, when you want to perform a quick test-compile under FreeBSD 3.1 with pgcc and without assembler stuff you can use `perl Configure "FreeBSD-elf:pgcc:-O6:::"` now, which overrides the FreeBSD-elf entry on-the-fly. *Ralf S. Engelschall* * Disable new TLS1 ciphersuites by default: they aren't official yet. *Ben Laurie* * Allow DSO flags like -fpic, -fPIC, -KPIC etc. to be specified on the `perl Configure ...` command line. This way one can compile OpenSSL libraries with Position Independent Code (PIC) which is needed for linking it into DSOs. *Ralf S. Engelschall* * Remarkably, export ciphers were totally broken and no-one had noticed! Fixed. *Ben Laurie* * Cleaned up the LICENSE document: The official contact for any license questions now is the OpenSSL core team under openssl-core@openssl.org. And add a paragraph about the dual-license situation to make sure people recognize that _BOTH_ the OpenSSL license _AND_ the SSLeay license apply to the OpenSSL toolkit. *Ralf S. Engelschall* * General source tree makefile cleanups: Made `making xxx in yyy...` display consistent in the source tree and replaced `/bin/rm` by `rm`. Additionally cleaned up the `make links` target: Remove unnecessary semicolons, subsequent redundant removes, inline point.sh into mklink.sh to speed processing and no longer clutter the display with confusing stuff. Instead only the actually done links are displayed. *Ralf S. Engelschall* * Permit null encryption ciphersuites, used for authentication only. It used to be necessary to set the preprocessor define SSL_ALLOW_ENULL to do this. It is now necessary to set SSL_FORBID_ENULL to prevent the use of null encryption. *Ben Laurie* * Add a bunch of fixes to the PKCS#7 stuff. It used to sometimes reorder signed attributes when verifying signatures (this would break them), the detached data encoding was wrong and public keys obtained using X509_get_pubkey() weren't freed. *Steve Henson* * Add text documentation for the BUFFER functions. Also added a work around to a Win95 console bug. This was triggered by the password read stuff: the last character typed gets carried over to the next fread(). If you were generating a new cert request using 'req' for example then the last character of the passphrase would be CR which would then enter the first field as blank. *Steve Henson* * Added the new 'Includes OpenSSL Cryptography Software' button as doc/openssl_button.{gif,html} which is similar in style to the old SSLeay button and can be used by applications based on OpenSSL to show the relationship to the OpenSSL project. *Ralf S. Engelschall* * Remove confusing variables in function signatures in files ssl/ssl_lib.c and ssl/ssl.h. *Lennart Bong * * Don't install bss_file.c under PREFIX/include/ *Lennart Bong * * Get the Win32 compile working again. Modify mkdef.pl so it can handle functions that return function pointers and has support for NT specific stuff. Fix mk1mf.pl and VC-32.pl to support NT differences also. Various #ifdef WIN32 and WINNTs sprinkled about the place and some changes from unsigned to signed types: this was killing the Win32 compile. *Steve Henson* * Add new certificate file to stack functions, SSL_add_dir_cert_subjects_to_stack() and SSL_add_file_cert_subjects_to_stack(). These largely supplant SSL_load_client_CA_file(), and can be used to add multiple certs easily to a stack (usually this is then handed to SSL_CTX_set_client_CA_list()). This means that Apache-SSL and similar packages don't have to mess around to add as many CAs as they want to the preferred list. *Ben Laurie* * Experiment with doxygen documentation. Currently only partially applied to ssl/ssl_lib.c. See , and run doxygen with openssl.doxy as the configuration file. *Ben Laurie* * Get rid of remaining C++-style comments which strict C compilers hate. *Ralf S. Engelschall, pointed out by Carlos Amengual* * Changed BN_RECURSION in bn_mont.c to BN_RECURSION_MONT so it is not compiled in by default: it has problems with large keys. *Steve Henson* * Add a bunch of SSL_xxx() functions for configuring the temporary RSA and DH private keys and/or callback functions which directly correspond to their SSL_CTX_xxx() counterparts but work on a per-connection basis. This is needed for applications which have to configure certificates on a per-connection basis (e.g. Apache+mod_ssl) instead of a per-context basis (e.g. s_server). For the RSA certificate situation is makes no difference, but for the DSA certificate situation this fixes the "no shared cipher" problem where the OpenSSL cipher selection procedure failed because the temporary keys were not overtaken from the context and the API provided no way to reconfigure them. The new functions now let applications reconfigure the stuff and they are in detail: SSL_need_tmp_RSA, SSL_set_tmp_rsa, SSL_set_tmp_dh, SSL_set_tmp_rsa_callback and SSL_set_tmp_dh_callback. Additionally a new non-public-API function ssl_cert_instantiate() is used as a helper function and also to reduce code redundancy inside ssl_rsa.c. *Ralf S. Engelschall* * Move s_server -dcert and -dkey options out of the undocumented feature area because they are useful for the DSA situation and should be recognized by the users. *Ralf S. Engelschall* * Fix the cipher decision scheme for export ciphers: the export bits are *not* within SSL_MKEY_MASK or SSL_AUTH_MASK, they are within SSL_EXP_MASK. So, the original variable has to be used instead of the already masked variable. *Richard Levitte * * Fix `port` variable from `int` to `unsigned int` in crypto/bio/b_sock.c *Richard Levitte * * Change type of another md_len variable in pk7_doit.c:PKCS7_dataFinal() from `int` to `unsigned int` because it is a length and initialized by EVP_DigestFinal() which expects an `unsigned int *`. *Richard Levitte * * Don't hard-code path to Perl interpreter on shebang line of Configure script. Instead use the usual Shell->Perl transition trick. *Ralf S. Engelschall* * Make `openssl x509 -noout -modulus`' functional also for DSA certificates (in addition to RSA certificates) to match the behaviour of `openssl dsa -noout -modulus` as it's already the case for `openssl rsa -noout -modulus`. For RSA the -modulus is the real "modulus" while for DSA currently the public key is printed (a decision which was already done by `openssl dsa -modulus` in the past) which serves a similar purpose. Additionally the NO_RSA no longer completely removes the whole -modulus option; it now only avoids using the RSA stuff. Same applies to NO_DSA now, too. *Ralf S. Engelschall* * Add Arne Ansper's reliable BIO - this is an encrypted, block-digested BIO. See the source (crypto/evp/bio_ok.c) for more info. *Arne Ansper * * Dump the old yucky req code that tried (and failed) to allow raw OIDs to be added. Now both 'req' and 'ca' can use new objects defined in the config file. *Steve Henson* * Add cool BIO that does syslog (or event log on NT). *Arne Ansper , integrated by Ben Laurie* * Add support for new TLS ciphersuites, TLS_RSA_EXPORT56_WITH_RC4_56_MD5, TLS_RSA_EXPORT56_WITH_RC2_CBC_56_MD5 and TLS_RSA_EXPORT56_WITH_DES_CBC_SHA, as specified in "56-bit Export Cipher Suites For TLS", draft-ietf-tls-56-bit-ciphersuites-00.txt. *Ben Laurie* * Add preliminary config info for new extension code. *Steve Henson* * Make RSA_NO_PADDING really use no padding. *Ulf Moeller * * Generate errors when private/public key check is done. *Ben Laurie* * Overhaul for 'crl' utility. New function X509_CRL_print. Partial support for some CRL extensions and new objects added. *Steve Henson* * Really fix the ASN1 IMPLICIT bug this time... Partial support for private key usage extension and fuller support for authority key id. *Steve Henson* * Add OAEP encryption for the OpenSSL crypto library. OAEP is the improved padding method for RSA, which is recommended for new applications in PKCS #1 v2.0 (RFC 2437, October 1998). OAEP (Optimal Asymmetric Encryption Padding) has better theoretical foundations than the ad-hoc padding used in PKCS #1 v1.5. It is secure against Bleichbacher's attack on RSA. *Ulf Moeller , reformatted, corrected and integrated by Ben Laurie* * Updates to the new SSL compression code *Eric A. Young, (from changes to C2Net SSLeay, integrated by Mark Cox)* * Fix so that the version number in the master secret, when passed via RSA, checks that if TLS was proposed, but we roll back to SSLv3 (because the server will not accept higher), that the version number is 0x03,0x01, not 0x03,0x00 *Eric A. Young, (from changes to C2Net SSLeay, integrated by Mark Cox)* * Run extensive memory leak checks on SSL commands. Fixed *lots* of memory leaks in `ssl/` relating to new `X509_get_pubkey()` behaviour. Also fixes in `apps/` and an unrelated leak in `crypto/dsa/dsa_vrf.c`. *Steve Henson* * Support for RAW extensions where an arbitrary extension can be created by including its DER encoding. See `apps/openssl.cnf` for an example. *Steve Henson* * Make sure latest Perl versions don't interpret some generated C array code as Perl array code in the crypto/err/err_genc.pl script. *Lars Weber <3weber@informatik.uni-hamburg.de>* * Modify ms/do_ms.bat to not generate assembly language makefiles since not many people have the assembler. Various Win32 compilation fixes and update to the INSTALL.W32 file with (hopefully) more accurate Win32 build instructions. *Steve Henson* * Modify configure script 'Configure' to automatically create crypto/date.h file under Win32 and also build pem.h from pem.org. New script util/mkfiles.pl to create the MINFO file on environments that can't do a 'make files': perl util/mkfiles.pl >MINFO should work. *Steve Henson* * Major rework of DES function declarations, in the pursuit of correctness and purity. As a result, many evil casts evaporated, and some weirdness, too. You may find this causes warnings in your code. Zapping your evil casts will probably fix them. Mostly. *Ben Laurie* * Fix for a typo in asn1.h. Bug fix to object creation script obj_dat.pl. It considered a zero in an object definition to mean "end of object": none of the objects in objects.h have any zeros so it wasn't spotted. *Steve Henson, reported by Erwann ABALEA * * Add support for Triple DES Cipher Block Chaining with Output Feedback Masking (CBCM). In the absence of test vectors, the best I have been able to do is check that the decrypt undoes the encrypt, so far. Send me test vectors if you have them. *Ben Laurie* * Correct calculation of key length for export ciphers (too much space was allocated for null ciphers). This has not been tested! *Ben Laurie* * Modifications to the mkdef.pl for Win32 DEF file creation. The usage message is now correct (it understands "crypto" and "ssl" on its command line). There is also now an "update" option. This will update the util/ssleay.num and util/libeay.num files with any new functions. If you do a: perl util/mkdef.pl crypto ssl update it will update them. *Steve Henson* * Overhauled the Perl interface: - ported BN stuff to OpenSSL's different BN library - made the perl/ source tree CVS-aware - renamed the package from SSLeay to OpenSSL (the files still contain their history because I've copied them in the repository) - removed obsolete files (the test scripts will be replaced by better Test::Harness variants in the future) *Ralf S. Engelschall* * First cut for a very conservative source tree cleanup: 1. merge various obsolete readme texts into doc/ssleay.txt where we collect the old documents and readme texts. 2. remove the first part of files where I'm already sure that we no longer need them because of three reasons: either they are just temporary files which were left by Eric or they are preserved original files where I've verified that the diff is also available in the CVS via "cvs diff -rSSLeay_0_8_1b" or they were renamed (as it was definitely the case for the crypto/md/ stuff). *Ralf S. Engelschall* * More extension code. Incomplete support for subject and issuer alt name, issuer and authority key id. Change the i2v function parameters and add an extra 'crl' parameter in the X509V3_CTX structure: guess what that's for :-) Fix to ASN1 macro which messed up IMPLICIT tag and add f_enum.c which adds a2i, i2a for ENUMERATED. *Steve Henson* * Preliminary support for ENUMERATED type. This is largely copied from the INTEGER code. *Steve Henson* * Add new function, EVP_MD_CTX_copy() to replace frequent use of memcpy. *Eric A. Young, (from changes to C2Net SSLeay, integrated by Mark Cox)* * Make sure `make rehash` target really finds the `openssl` program. *Ralf S. Engelschall, Matthias Loepfe * * Squeeze another 7% of speed out of MD5 assembler, at least on a P2. I'd like to hear about it if this slows down other processors. *Ben Laurie* * Add CygWin32 platform information to Configure script. *Alan Batie * * Fixed ms/32all.bat script: `no_asm` -> `no-asm` *Rainer W. Gerling * * New program nseq to manipulate netscape certificate sequences *Steve Henson* * Modify crl2pkcs7 so it supports multiple -certfile arguments. Fix a few typos. *Steve Henson* * Fixes to BN code. Previously the default was to define BN_RECURSION but the BN code had some problems that would cause failures when doing certificate verification and some other functions. *Eric A. Young, (from changes to C2Net SSLeay, integrated by Mark Cox)* * Add ASN1 and PEM code to support netscape certificate sequences. *Steve Henson* * Add ASN1 and PEM code to support netscape certificate sequences. *Steve Henson* * Add several PKIX and private extended key usage OIDs. *Steve Henson* * Modify the 'ca' program to handle the new extension code. Modify openssl.cnf for new extension format, add comments. *Steve Henson* * More X509 V3 changes. Fix typo in v3_bitstr.c. Add support to 'req' and add a sample to openssl.cnf so req -x509 now adds appropriate CA extensions. *Steve Henson* * Continued X509 V3 changes. Add to other makefiles, integrate with the error code, add initial support to X509_print() and x509 application. *Steve Henson* * Takes a deep breath and start adding X509 V3 extension support code. Add files in crypto/x509v3. Move original stuff to crypto/x509v3/old. All this stuff is currently isolated and isn't even compiled yet. *Steve Henson* * Continuing patches for GeneralizedTime. Fix up certificate and CRL ASN1 to use ASN1_TIME and modify print routines to use ASN1_TIME_print. Removed the versions check from X509 routines when loading extensions: this allows certain broken certificates that don't set the version properly to be processed. *Steve Henson* * Deal with irritating shit to do with dependencies, in YAAHW (Yet Another Ad Hoc Way) - Makefile.ssls now all contain local dependencies, which can still be regenerated with "make depend". *Ben Laurie* * Spelling mistake in C version of CAST-128. *Ben Laurie, reported by Jeremy Hylton * * Changes to the error generation code. The perl script err-code.pl now reads in the old error codes and retains the old numbers, only adding new ones if necessary. It also only changes the .err files if new codes are added. The makefiles have been modified to only insert errors when needed (to avoid needlessly modifying header files). This is done by only inserting errors if the .err file is newer than the auto generated C file. To rebuild all the error codes from scratch (the old behaviour) either modify crypto/Makefile.ssl to pass the -regen flag to err_code.pl or delete all the .err files. *Steve Henson* * CAST-128 was incorrectly implemented for short keys. The C version has been fixed, but is untested. The assembler versions are also fixed, but new assembler HAS NOT BEEN GENERATED FOR WIN32 - the Makefile needs fixing to regenerate it if needed. *Ben Laurie, reported (with fix for C version) by Jun-ichiro itojun Hagino * * File was opened incorrectly in randfile.c. *Ulf Möller * * Beginning of support for GeneralizedTime. d2i, i2d, check and print functions. Also ASN1_TIME suite which is a CHOICE of UTCTime or GeneralizedTime. ASN1_TIME is the proper type used in certificates et al: it's just almost always a UTCTime. Note this patch adds new error codes so do a "make errors" if there are problems. *Steve Henson* * Correct Linux 1 recognition in config. *Ulf Möller * * Remove pointless MD5 hash when using DSA keys in ca. *Anonymous * * Generate an error if given an empty string as a cert directory. Also generate an error if handed NULL (previously returned 0 to indicate an error, but didn't set one). *Ben Laurie, reported by Anonymous * * Add prototypes to SSL methods. Make SSL_write's buffer const, at last. *Ben Laurie* * Fix the dummy function BN_ref_mod_exp() in rsaref.c to have the correct parameters. This was causing a warning which killed off the Win32 compile. *Steve Henson* * Remove C++ style comments from crypto/bn/bn_local.h. *Neil Costigan * * The function OBJ_txt2nid was broken. It was supposed to return a nid based on a text string, looking up short and long names and finally "dot" format. The "dot" format stuff didn't work. Added new function OBJ_txt2obj to do the same but return an ASN1_OBJECT and rewrote OBJ_txt2nid to use it. OBJ_txt2obj can also return objects even if the OID is not part of the table. *Steve Henson* * Add prototypes to X509 lookup/verify methods, fixing a bug in X509_LOOKUP_by_alias(). *Ben Laurie* * Sort openssl functions by name. *Ben Laurie* * Get the `gendsa` command working and add it to the `list` command. Remove encryption from sample DSA keys (in case anyone is interested the password was "1234"). *Steve Henson* * Make *all* `*_free` functions accept a NULL pointer. *Frans Heymans * * If a DH key is generated in s3_srvr.c, don't blow it by trying to use NULL pointers. *Anonymous * * s_server should send the CAfile as acceptable CAs, not its own cert. *Bodo Moeller <3moeller@informatik.uni-hamburg.de>* * Don't blow it for numeric `-newkey` arguments to `apps/req`. *Bodo Moeller <3moeller@informatik.uni-hamburg.de>* * Temp key "for export" tests were wrong in s3_srvr.c. *Anonymous * * Add prototype for temp key callback functions SSL_CTX_set_tmp_{rsa,dh}_callback(). *Ben Laurie* * Make DH_free() tolerate being passed a NULL pointer (like RSA_free() and DSA_free()). Make X509_PUBKEY_set() check for errors in d2i_PublicKey(). *Steve Henson* * X509_name_add_entry() freed the wrong thing after an error. *Arne Ansper * * rsa_eay.c would attempt to free a NULL context. *Arne Ansper * * BIO_s_socket() had a broken should_retry() on Windoze. *Arne Ansper * * BIO_f_buffer() didn't pass on BIO_CTRL_FLUSH. *Arne Ansper * * Make sure the already existing X509_STORE->depth variable is initialized in X509_STORE_new(), but document the fact that this variable is still unused in the certificate verification process. *Ralf S. Engelschall* * Fix the various library and `apps/` files to free up pkeys obtained from X509_PUBKEY_get() et al. Also allow x509.c to handle netscape extensions. *Steve Henson* * Fix reference counting in X509_PUBKEY_get(). This makes demos/maurice/example2.c work, amongst others, probably. *Steve Henson and Ben Laurie* * First cut of a cleanup for `apps/`. First the `ssleay` program is now named `openssl` and second, the shortcut symlinks for the `openssl ` are no longer created. This way we have a single and consistent command line interface `openssl `, similar to `cvs `. *Ralf S. Engelschall, Paul Sutton and Ben Laurie* * ca.c: move test for DSA keys inside #ifndef NO_DSA. Make pubkey BIT STRING wrapper always have zero unused bits. *Steve Henson* * Add CA.pl, perl version of CA.sh, add extended key usage OID. *Steve Henson* * Make the top-level INSTALL documentation easier to understand. *Paul Sutton* * Makefiles updated to exit if an error occurs in a sub-directory make (including if user presses ^C) [Paul Sutton] * Make Montgomery context stuff explicit in RSA data structure. *Ben Laurie* * Fix build order of pem and err to allow for generated pem.h. *Ben Laurie* * Fix renumbering bug in X509_NAME_delete_entry(). *Ben Laurie* * Enhanced the err-ins.pl script so it makes the error library number global and can add a library name. This is needed for external ASN1 and other error libraries. *Steve Henson* * Fixed sk_insert which never worked properly. *Steve Henson* * Fix ASN1 macros so they can handle indefinite length constructed EXPLICIT tags. Some non standard certificates use these: they can now be read in. *Steve Henson* * Merged the various old/obsolete SSLeay documentation files (doc/xxx.doc) into a single doc/ssleay.txt bundle. This way the information is still preserved but no longer messes up this directory. Now it's new room for the new set of documentation files. *Ralf S. Engelschall* * SETs were incorrectly DER encoded. This was a major pain, because they shared code with SEQUENCEs, which aren't coded the same. This means that almost everything to do with SETs or SEQUENCEs has either changed name or number of arguments. *Ben Laurie, based on a partial fix by GP Jayan * * Fix test data to work with the above. *Ben Laurie* * Fix the RSA header declarations that hid a bug I fixed in 0.9.0b but was already fixed by Eric for 0.9.1 it seems. *Ben Laurie - pointed out by Ulf Möller * * Autodetect FreeBSD3. *Ben Laurie* * Fix various bugs in Configure. This affects the following platforms: nextstep ncr-scde unixware-2.0 unixware-2.0-pentium sco5-cc. *Ben Laurie* * Eliminate generated files from CVS. Reorder tests to regenerate files before they are needed. *Ben Laurie* * Generate Makefile.ssl from Makefile.org (to keep CVS happy). *Ben Laurie* ### Changes between 0.9.1b and 0.9.1c [23-Dec-1998] * Added OPENSSL_VERSION_NUMBER to crypto/crypto.h and changed SSLeay to OpenSSL in version strings. *Ralf S. Engelschall* * Some fixups to the top-level documents. *Paul Sutton* * Fixed the nasty bug where rsaref.h was not found under compile-time because the symlink to include/ was missing. *Ralf S. Engelschall* * Incorporated the popular no-RSA/DSA-only patches which allow to compile an RSA-free SSLeay. *Andrew Cooke / Interrader Ldt., Ralf S. Engelschall* * Fixed nasty rehash problem under `make -f Makefile.ssl links` when "ssleay" is still not found. *Ralf S. Engelschall* * Added more platforms to Configure: Cray T3E, HPUX 11, *Ralf S. Engelschall, Beckmann * * Updated the README file. *Ralf S. Engelschall* * Added various .cvsignore files in the CVS repository subdirs to make a "cvs update" really silent. *Ralf S. Engelschall* * Recompiled the error-definition header files and added missing symbols to the Win32 linker tables. *Ralf S. Engelschall* * Cleaned up the top-level documents; o new files: CHANGES and LICENSE o merged VERSION, HISTORY* and README* files a CHANGES.SSLeay o merged COPYRIGHT into LICENSE o removed obsolete TODO file o renamed MICROSOFT to INSTALL.W32 *Ralf S. Engelschall* * Removed dummy files from the 0.9.1b source tree: crypto/asn1/x crypto/bio/cd crypto/bio/fg crypto/bio/grep crypto/bio/vi crypto/bn/asm/......add.c crypto/bn/asm/a.out crypto/dsa/f crypto/md5/f crypto/pem/gmon.out crypto/perlasm/f crypto/pkcs7/build crypto/rsa/f crypto/sha/asm/f crypto/threads/f ms/zzz ssl/f ssl/f.mak test/f util/f.mak util/pl/f util/pl/f.mak crypto/bf/bf_locl.old apps/f *Ralf S. Engelschall* * Added various platform portability fixes. *Mark J. Cox* * The Genesis of the OpenSSL rpject: We start with the latest (unreleased) SSLeay version 0.9.1b which Eric A. Young and Tim J. Hudson created while they were working for C2Net until summer 1998. *The OpenSSL Project* ### Changes between 0.9.0b and 0.9.1b [not released] * Updated a few CA certificates under certs/ *Eric A. Young* * Changed some BIGNUM api stuff. *Eric A. Young* * Various platform ports: OpenBSD, Ultrix, IRIX 64bit, NetBSD, DGUX x86, Linux Alpha, etc. *Eric A. Young* * New COMP library [crypto/comp/] for SSL Record Layer Compression: RLE (dummy implemented) and ZLIB (really implemented when ZLIB is available). *Eric A. Young* * Add -strparse option to asn1pars program which parses nested binary structures *Dr Stephen Henson * * Added "oid_file" to ssleay.cnf for "ca" and "req" programs. *Eric A. Young* * DSA fix for "ca" program. *Eric A. Young* * Added "-genkey" option to "dsaparam" program. *Eric A. Young* * Added RIPE MD160 (rmd160) message digest. *Eric A. Young* * Added -a (all) option to "ssleay version" command. *Eric A. Young* * Added PLATFORM define which is the id given to Configure. *Eric A. Young* * Added MemCheck_XXXX functions to crypto/mem.c for memory checking. *Eric A. Young* * Extended the ASN.1 parser routines. *Eric A. Young* * Extended BIO routines to support REUSEADDR, seek, tell, etc. *Eric A. Young* * Added a BN_CTX to the BN library. *Eric A. Young* * Fixed the weak key values in DES library *Eric A. Young* * Changed API in EVP library for cipher aliases. *Eric A. Young* * Added support for RC2/64bit cipher. *Eric A. Young* * Converted the lhash library to the crypto/mem.c functions. *Eric A. Young* * Added more recognized ASN.1 object ids. *Eric A. Young* * Added more RSA padding checks for SSL/TLS. *Eric A. Young* * Added BIO proxy/filter functionality. *Eric A. Young* * Added extra_certs to SSL_CTX which can be used send extra CA certificates to the client in the CA cert chain sending process. It can be configured with SSL_CTX_add_extra_chain_cert(). *Eric A. Young* * Now Fortezza is denied in the authentication phase because this is key exchange mechanism is not supported by SSLeay at all. *Eric A. Young* * Additional PKCS1 checks. *Eric A. Young* * Support the string "TLSv1" for all TLS v1 ciphers. *Eric A. Young* * Added function SSL_get_ex_data_X509_STORE_CTX_idx() which gives the ex_data index of the SSL context in the X509_STORE_CTX ex_data. *Eric A. Young* * Fixed a few memory leaks. *Eric A. Young* * Fixed various code and comment typos. *Eric A. Young* * A minor bug in ssl/s3_clnt.c where there would always be 4 0 bytes sent in the client random. *Edward Bishop * +[CVE-2023-5363]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-5363 [CVE-2023-4807]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-4807 [CVE-2023-3817]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-3817 [CVE-2023-3446]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-3446 [CVE-2023-2975]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-2975 [RFC 2578 (STD 58), section 3.5]: https://datatracker.ietf.org/doc/html/rfc2578#section-3.5 [CVE-2023-2650]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-2650 [CVE-2023-1255]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-1255 [CVE-2023-0466]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-0466 [CVE-2023-0465]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-0465 [CVE-2023-0464]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-0464 [CVE-2023-0401]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-0401 [CVE-2023-0286]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-0286 [CVE-2023-0217]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-0217 [CVE-2023-0216]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-0216 [CVE-2023-0215]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-0215 [CVE-2022-4450]: https://www.openssl.org/news/vulnerabilities.html#CVE-2022-4450 [CVE-2022-4304]: https://www.openssl.org/news/vulnerabilities.html#CVE-2022-4304 [CVE-2022-4203]: https://www.openssl.org/news/vulnerabilities.html#CVE-2022-4203 [CVE-2022-3996]: https://www.openssl.org/news/vulnerabilities.html#CVE-2022-3996 [CVE-2022-2274]: https://www.openssl.org/news/vulnerabilities.html#CVE-2022-2274 [CVE-2022-2097]: https://www.openssl.org/news/vulnerabilities.html#CVE-2022-2097 [CVE-2020-1971]: https://www.openssl.org/news/vulnerabilities.html#CVE-2020-1971 [CVE-2020-1967]: https://www.openssl.org/news/vulnerabilities.html#CVE-2020-1967 [CVE-2019-1563]: https://www.openssl.org/news/vulnerabilities.html#CVE-2019-1563 [CVE-2019-1559]: https://www.openssl.org/news/vulnerabilities.html#CVE-2019-1559 [CVE-2019-1552]: https://www.openssl.org/news/vulnerabilities.html#CVE-2019-1552 [CVE-2019-1551]: https://www.openssl.org/news/vulnerabilities.html#CVE-2019-1551 [CVE-2019-1549]: https://www.openssl.org/news/vulnerabilities.html#CVE-2019-1549 [CVE-2019-1547]: https://www.openssl.org/news/vulnerabilities.html#CVE-2019-1547 [CVE-2019-1543]: https://www.openssl.org/news/vulnerabilities.html#CVE-2019-1543 [CVE-2018-5407]: https://www.openssl.org/news/vulnerabilities.html#CVE-2018-5407 [CVE-2018-0739]: https://www.openssl.org/news/vulnerabilities.html#CVE-2018-0739 [CVE-2018-0737]: https://www.openssl.org/news/vulnerabilities.html#CVE-2018-0737 [CVE-2018-0735]: https://www.openssl.org/news/vulnerabilities.html#CVE-2018-0735 [CVE-2018-0734]: https://www.openssl.org/news/vulnerabilities.html#CVE-2018-0734 [CVE-2018-0733]: https://www.openssl.org/news/vulnerabilities.html#CVE-2018-0733 [CVE-2018-0732]: https://www.openssl.org/news/vulnerabilities.html#CVE-2018-0732 [CVE-2017-3738]: https://www.openssl.org/news/vulnerabilities.html#CVE-2017-3738 [CVE-2017-3737]: https://www.openssl.org/news/vulnerabilities.html#CVE-2017-3737 [CVE-2017-3736]: https://www.openssl.org/news/vulnerabilities.html#CVE-2017-3736 [CVE-2017-3735]: https://www.openssl.org/news/vulnerabilities.html#CVE-2017-3735 [CVE-2017-3733]: https://www.openssl.org/news/vulnerabilities.html#CVE-2017-3733 [CVE-2017-3732]: https://www.openssl.org/news/vulnerabilities.html#CVE-2017-3732 [CVE-2017-3731]: https://www.openssl.org/news/vulnerabilities.html#CVE-2017-3731 [CVE-2017-3730]: https://www.openssl.org/news/vulnerabilities.html#CVE-2017-3730 [CVE-2016-7055]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-7055 [CVE-2016-7054]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-7054 [CVE-2016-7053]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-7053 [CVE-2016-7052]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-7052 [CVE-2016-6309]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-6309 [CVE-2016-6308]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-6308 [CVE-2016-6307]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-6307 [CVE-2016-6306]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-6306 [CVE-2016-6305]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-6305 [CVE-2016-6304]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-6304 [CVE-2016-6303]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-6303 [CVE-2016-6302]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-6302 [CVE-2016-2183]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-2183 [CVE-2016-2182]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-2182 [CVE-2016-2181]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-2181 [CVE-2016-2180]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-2180 [CVE-2016-2179]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-2179 [CVE-2016-2178]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-2178 [CVE-2016-2177]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-2177 [CVE-2016-2176]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-2176 [CVE-2016-2109]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-2109 [CVE-2016-2107]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-2107 [CVE-2016-2106]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-2106 [CVE-2016-2105]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-2105 [CVE-2016-0800]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-0800 [CVE-2016-0799]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-0799 [CVE-2016-0798]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-0798 [CVE-2016-0797]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-0797 [CVE-2016-0705]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-0705 [CVE-2016-0702]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-0702 [CVE-2016-0701]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-0701 [CVE-2015-3197]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-3197 [CVE-2015-3196]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-3196 [CVE-2015-3195]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-3195 [CVE-2015-3194]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-3194 [CVE-2015-3193]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-3193 [CVE-2015-1793]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-1793 [CVE-2015-1792]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-1792 [CVE-2015-1791]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-1791 [CVE-2015-1790]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-1790 [CVE-2015-1789]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-1789 [CVE-2015-1788]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-1788 [CVE-2015-1787]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-1787 [CVE-2015-0293]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-0293 [CVE-2015-0291]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-0291 [CVE-2015-0290]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-0290 [CVE-2015-0289]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-0289 [CVE-2015-0288]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-0288 [CVE-2015-0287]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-0287 [CVE-2015-0286]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-0286 [CVE-2015-0285]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-0285 [CVE-2015-0209]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-0209 [CVE-2015-0208]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-0208 [CVE-2015-0207]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-0207 [CVE-2015-0206]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-0206 [CVE-2015-0205]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-0205 [CVE-2015-0204]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-0204 [CVE-2014-8275]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-8275 [CVE-2014-5139]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-5139 [CVE-2014-3572]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3572 [CVE-2014-3571]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3571 [CVE-2014-3570]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3570 [CVE-2014-3569]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3569 [CVE-2014-3568]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3568 [CVE-2014-3567]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3567 [CVE-2014-3566]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3566 [CVE-2014-3513]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3513 [CVE-2014-3512]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3512 [CVE-2014-3511]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3511 [CVE-2014-3510]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3510 [CVE-2014-3509]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3509 [CVE-2014-3508]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3508 [CVE-2014-3507]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3507 [CVE-2014-3506]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3506 [CVE-2014-3505]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3505 [CVE-2014-3470]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3470 [CVE-2014-0224]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-0224 [CVE-2014-0221]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-0221 [CVE-2014-0195]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-0195 [CVE-2014-0160]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-0160 [CVE-2014-0076]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-0076 [CVE-2013-6450]: https://www.openssl.org/news/vulnerabilities.html#CVE-2013-6450 [CVE-2013-4353]: https://www.openssl.org/news/vulnerabilities.html#CVE-2013-4353 [CVE-2013-0169]: https://www.openssl.org/news/vulnerabilities.html#CVE-2013-0169 [CVE-2013-0166]: https://www.openssl.org/news/vulnerabilities.html#CVE-2013-0166 [CVE-2012-2686]: https://www.openssl.org/news/vulnerabilities.html#CVE-2012-2686 [CVE-2012-2333]: https://www.openssl.org/news/vulnerabilities.html#CVE-2012-2333 [CVE-2012-2110]: https://www.openssl.org/news/vulnerabilities.html#CVE-2012-2110 [CVE-2012-0884]: https://www.openssl.org/news/vulnerabilities.html#CVE-2012-0884 [CVE-2012-0050]: https://www.openssl.org/news/vulnerabilities.html#CVE-2012-0050 [CVE-2012-0027]: https://www.openssl.org/news/vulnerabilities.html#CVE-2012-0027 [CVE-2011-4619]: https://www.openssl.org/news/vulnerabilities.html#CVE-2011-4619 [CVE-2011-4577]: https://www.openssl.org/news/vulnerabilities.html#CVE-2011-4577 [CVE-2011-4576]: https://www.openssl.org/news/vulnerabilities.html#CVE-2011-4576 [CVE-2011-4109]: https://www.openssl.org/news/vulnerabilities.html#CVE-2011-4109 [CVE-2011-4108]: https://www.openssl.org/news/vulnerabilities.html#CVE-2011-4108 [CVE-2011-3210]: https://www.openssl.org/news/vulnerabilities.html#CVE-2011-3210 [CVE-2011-3207]: https://www.openssl.org/news/vulnerabilities.html#CVE-2011-3207 [CVE-2011-0014]: https://www.openssl.org/news/vulnerabilities.html#CVE-2011-0014 [CVE-2010-4252]: https://www.openssl.org/news/vulnerabilities.html#CVE-2010-4252 [CVE-2010-4180]: https://www.openssl.org/news/vulnerabilities.html#CVE-2010-4180 [CVE-2010-3864]: https://www.openssl.org/news/vulnerabilities.html#CVE-2010-3864 [CVE-2010-1633]: https://www.openssl.org/news/vulnerabilities.html#CVE-2010-1633 [CVE-2010-0740]: https://www.openssl.org/news/vulnerabilities.html#CVE-2010-0740 [CVE-2010-0433]: https://www.openssl.org/news/vulnerabilities.html#CVE-2010-0433 [CVE-2009-4355]: https://www.openssl.org/news/vulnerabilities.html#CVE-2009-4355 [CVE-2009-3555]: https://www.openssl.org/news/vulnerabilities.html#CVE-2009-3555 [CVE-2009-3245]: https://www.openssl.org/news/vulnerabilities.html#CVE-2009-3245 [CVE-2009-1386]: https://www.openssl.org/news/vulnerabilities.html#CVE-2009-1386 [CVE-2009-1379]: https://www.openssl.org/news/vulnerabilities.html#CVE-2009-1379 [CVE-2009-1378]: https://www.openssl.org/news/vulnerabilities.html#CVE-2009-1378 [CVE-2009-1377]: https://www.openssl.org/news/vulnerabilities.html#CVE-2009-1377 [CVE-2009-0789]: https://www.openssl.org/news/vulnerabilities.html#CVE-2009-0789 [CVE-2009-0591]: https://www.openssl.org/news/vulnerabilities.html#CVE-2009-0591 [CVE-2009-0590]: https://www.openssl.org/news/vulnerabilities.html#CVE-2009-0590 [CVE-2008-5077]: https://www.openssl.org/news/vulnerabilities.html#CVE-2008-5077 [CVE-2008-1678]: https://www.openssl.org/news/vulnerabilities.html#CVE-2008-1678 [CVE-2008-1672]: https://www.openssl.org/news/vulnerabilities.html#CVE-2008-1672 [CVE-2008-0891]: https://www.openssl.org/news/vulnerabilities.html#CVE-2008-0891 [CVE-2007-5135]: https://www.openssl.org/news/vulnerabilities.html#CVE-2007-5135 [CVE-2007-4995]: https://www.openssl.org/news/vulnerabilities.html#CVE-2007-4995 [CVE-2006-4343]: https://www.openssl.org/news/vulnerabilities.html#CVE-2006-4343 [CVE-2006-4339]: https://www.openssl.org/news/vulnerabilities.html#CVE-2006-4339 [CVE-2006-3738]: https://www.openssl.org/news/vulnerabilities.html#CVE-2006-3738 [CVE-2006-2940]: https://www.openssl.org/news/vulnerabilities.html#CVE-2006-2940 [CVE-2006-2937]: https://www.openssl.org/news/vulnerabilities.html#CVE-2006-2937 [CVE-2005-2969]: https://www.openssl.org/news/vulnerabilities.html#CVE-2005-2969 [CVE-2004-0112]: https://www.openssl.org/news/vulnerabilities.html#CVE-2004-0112 [CVE-2004-0079]: https://www.openssl.org/news/vulnerabilities.html#CVE-2004-0079 [CVE-2003-0851]: https://www.openssl.org/news/vulnerabilities.html#CVE-2003-0851 [CVE-2003-0545]: https://www.openssl.org/news/vulnerabilities.html#CVE-2003-0545 [CVE-2003-0544]: https://www.openssl.org/news/vulnerabilities.html#CVE-2003-0544 [CVE-2003-0543]: https://www.openssl.org/news/vulnerabilities.html#CVE-2003-0543 [CVE-2003-0078]: https://www.openssl.org/news/vulnerabilities.html#CVE-2003-0078 [CVE-2002-0659]: https://www.openssl.org/news/vulnerabilities.html#CVE-2002-0659 [CVE-2002-0657]: https://www.openssl.org/news/vulnerabilities.html#CVE-2002-0657 [CVE-2002-0656]: https://www.openssl.org/news/vulnerabilities.html#CVE-2002-0656 [CVE-2002-0655]: https://www.openssl.org/news/vulnerabilities.html#CVE-2002-0655 diff --git a/crypto/openssl/INSTALL.md b/crypto/openssl/INSTALL.md index ad4a51026d7c..fef408e9d1e3 100644 --- a/crypto/openssl/INSTALL.md +++ b/crypto/openssl/INSTALL.md @@ -1,1825 +1,1825 @@ Build and Install ================= This document describes installation on all supported operating -systems (the Unix/Linux family, including macOS), OpenVMS, -and Windows). +systems: the Unix/Linux family (including macOS), OpenVMS, +and Windows. Table of Contents ================= - [Prerequisites](#prerequisites) - [Notational Conventions](#notational-conventions) - [Quick Installation Guide](#quick-installation-guide) - [Building OpenSSL](#building-openssl) - [Installing OpenSSL](#installing-openssl) - [Configuration Options](#configuration-options) - [API Level](#api-level) - [Cross Compile Prefix](#cross-compile-prefix) - [Build Type](#build-type) - [Directories](#directories) - [Compiler Warnings](#compiler-warnings) - [ZLib Flags](#zlib-flags) - [Seeding the Random Generator](#seeding-the-random-generator) - [Setting the FIPS HMAC key](#setting-the-FIPS-HMAC-key) - [Enable and Disable Features](#enable-and-disable-features) - [Displaying configuration data](#displaying-configuration-data) - [Installation Steps in Detail](#installation-steps-in-detail) - [Configure](#configure-openssl) - [Build](#build-openssl) - [Test](#test-openssl) - [Install](#install-openssl) - [Advanced Build Options](#advanced-build-options) - [Environment Variables](#environment-variables) - [Makefile Targets](#makefile-targets) - [Running Selected Tests](#running-selected-tests) - [Troubleshooting](#troubleshooting) - [Configuration Problems](#configuration-problems) - [Build Failures](#build-failures) - [Test Failures](#test-failures) - [Notes](#notes) - [Notes on multi-threading](#notes-on-multi-threading) - [Notes on shared libraries](#notes-on-shared-libraries) - [Notes on random number generation](#notes-on-random-number-generation) - [Notes on assembler modules compilation](#notes-on-assembler-modules-compilation) Prerequisites ============= To install OpenSSL, you will need: * A "make" implementation * Perl 5 with core modules (please read [NOTES-PERL.md](NOTES-PERL.md)) * The Perl module `Text::Template` (please read [NOTES-PERL.md](NOTES-PERL.md)) * an ANSI C compiler * a development environment in the form of development libraries and C header files * a supported operating system For additional platform specific requirements, solutions to specific issues and other details, please read one of these: * [Notes for UNIX-like platforms](NOTES-UNIX.md) * [Notes for Android platforms](NOTES-ANDROID.md) * [Notes for Windows platforms](NOTES-WINDOWS.md) * [Notes for the DOS platform with DJGPP](NOTES-DJGPP.md) * [Notes for the OpenVMS platform](NOTES-VMS.md) * [Notes on Perl](NOTES-PERL.md) * [Notes on Valgrind](NOTES-VALGRIND.md) Notational conventions ====================== Throughout this document, we use the following conventions. Commands -------- Any line starting with a dollar sign is a command line. $ command The dollar sign indicates the shell prompt and is not to be entered as part of the command. Choices ------- Several words in curly braces separated by pipe characters indicate a **mandatory choice**, to be replaced with one of the given words. For example, the line $ echo { WORD1 | WORD2 | WORD3 } represents one of the following three commands $ echo WORD1 - or - $ echo WORD2 - or - $ echo WORD3 One or several words in square brackets separated by pipe characters denote an **optional choice**. It is similar to the mandatory choice, but it can also be omitted entirely. So the line $ echo [ WORD1 | WORD2 | WORD3 ] represents one of the four commands $ echo WORD1 - or - $ echo WORD2 - or - $ echo WORD3 - or - $ echo Arguments --------- **Mandatory arguments** are enclosed in double curly braces. A simple example would be $ type {{ filename }} which is to be understood to use the command `type` on some file name determined by the user. **Optional Arguments** are enclosed in double square brackets. [[ options ]] Note that the notation assumes spaces around `{`, `}`, `[`, `]`, `{{`, `}}` and `[[`, `]]`. This is to differentiate from OpenVMS directory specifications, which also use [ and ], but without spaces. Quick Installation Guide ======================== If you just want to get OpenSSL installed without bothering too much about the details, here is the short version of how to build and install OpenSSL. If any of the following steps fails, please consult the [Installation in Detail](#installation-steps-in-detail) section below. Building OpenSSL ---------------- Use the following commands to configure, build and test OpenSSL. The testing is optional, but recommended if you intend to install OpenSSL for production use. ### Unix / Linux / macOS $ ./Configure $ make $ make test ### OpenVMS Use the following commands to build OpenSSL: $ perl Configure $ mms $ mms test ### Windows If you are using Visual Studio, open a Developer Command Prompt and issue the following commands to build OpenSSL. $ perl Configure $ nmake $ nmake test As mentioned in the [Choices](#choices) section, you need to pick one of the four Configure targets in the first command. Most likely you will be using the `VC-WIN64A` target for 64bit Windows binaries (AMD64) or `VC-WIN32` for 32bit Windows binaries (X86). The other two options are `VC-WIN64I` (Intel IA64, Itanium) and `VC-CE` (Windows CE) are rather uncommon nowadays. Installing OpenSSL ------------------ The following commands will install OpenSSL to a default system location. **Danger Zone:** even if you are impatient, please read the following two paragraphs carefully before you install OpenSSL. For security reasons the default system location is by default not writable for unprivileged users. So for the final installation step administrative privileges are required. The default system location and the procedure to obtain administrative privileges depends on the operating system. It is recommended to compile and test OpenSSL with normal user privileges and use administrative privileges only for the final installation step. On some platforms OpenSSL is preinstalled as part of the Operating System. In this case it is highly recommended not to overwrite the system versions, because other applications or libraries might depend on it. To avoid breaking other applications, install your copy of OpenSSL to a [different location](#installing-to-a-different-location) which is not in the global search path for system libraries. Finally, if you plan on using the FIPS module, you need to read the [Post-installation Notes](#post-installation-notes) further down. ### Unix / Linux / macOS Depending on your distribution, you need to run the following command as root user or prepend `sudo` to the command: $ make install By default, OpenSSL will be installed to /usr/local More precisely, the files will be installed into the subdirectories /usr/local/bin /usr/local/lib /usr/local/include ... depending on the file type, as it is custom on Unix-like operating systems. ### OpenVMS Use the following command to install OpenSSL. $ mms install By default, OpenSSL will be installed to SYS$COMMON:[OPENSSL] ### Windows If you are using Visual Studio, open the Developer Command Prompt _elevated_ and issue the following command. $ nmake install The easiest way to elevate the Command Prompt is to press and hold down both the `` and `` keys while clicking the menu item in the task menu. The default installation location is C:\Program Files\OpenSSL for native binaries, or C:\Program Files (x86)\OpenSSL for 32bit binaries on 64bit Windows (WOW64). #### Installing to a different location To install OpenSSL to a different location (for example into your home directory for testing purposes) run `Configure` as shown in the following examples. The options `--prefix` and `--openssldir` are explained in further detail in [Directories](#directories) below, and the values used here are mere examples. On Unix: $ ./Configure --prefix=/opt/openssl --openssldir=/usr/local/ssl On OpenVMS: $ perl Configure --prefix=PROGRAM:[INSTALLS] --openssldir=SYS$MANAGER:[OPENSSL] Note: if you do add options to the configuration command, please make sure you've read more than just this Quick Start, such as relevant `NOTES-*` files, the options outline below, as configuration options may change the outcome in otherwise unexpected ways. Configuration Options ===================== There are several options to `./Configure` to customize the build (note that for Windows, the defaults for `--prefix` and `--openssldir` depend on what configuration is used and what Windows implementation OpenSSL is built on. For more information, see the [Notes for Windows platforms](NOTES-WINDOWS.md). API Level --------- --api=x.y[.z] Build the OpenSSL libraries to support the API for the specified version. If [no-deprecated](#no-deprecated) is also given, don't build with support for deprecated APIs in or below the specified version number. For example, adding --api=1.1.0 no-deprecated will remove support for all APIs that were deprecated in OpenSSL version 1.1.0 or below. This is a rather specialized option for developers. If you just intend to remove all deprecated APIs up to the current version entirely, just specify [no-deprecated](#no-deprecated). If `--api` isn't given, it defaults to the current (minor) OpenSSL version. Cross Compile Prefix -------------------- --cross-compile-prefix= The `` to include in front of commands for your toolchain. It is likely to have to end with dash, e.g. `a-b-c-` would invoke GNU compiler as `a-b-c-gcc`, etc. Unfortunately cross-compiling is too case-specific to put together one-size-fits-all instructions. You might have to pass more flags or set up environment variables to actually make it work. Android and iOS cases are discussed in corresponding `Configurations/15-*.conf` files. But there are cases when this option alone is sufficient. For example to build the mingw64 target on Linux `--cross-compile-prefix=x86_64-w64-mingw32-` works. Naturally provided that mingw packages are installed. Today Debian and Ubuntu users have option to install a number of prepackaged cross-compilers along with corresponding run-time and development packages for "alien" hardware. To give another example `--cross-compile-prefix=mipsel-linux-gnu-` suffices in such case. For cross compilation, you must [configure manually](#manual-configuration). Also, note that `--openssldir` refers to target's file system, not one you are building on. Build Type ---------- --debug Build OpenSSL with debugging symbols and zero optimization level. --release Build OpenSSL without debugging symbols. This is the default. Directories ----------- ### libdir --libdir=DIR The name of the directory under the top of the installation directory tree (see the `--prefix` option) where libraries will be installed. By default this is `lib`. Note that on Windows only static libraries (`*.lib`) will be stored in this location. Shared libraries (`*.dll`) will always be installed to the `bin` directory. Some build targets have a multilib postfix set in the build configuration. For these targets the default libdir is `lib`. Please use `--libdir=lib` to override the libdir if adding the postfix is undesirable. ### openssldir --openssldir=DIR Directory for OpenSSL configuration files, and also the default certificate and key store. Defaults are: Unix: /usr/local/ssl Windows: C:\Program Files\Common Files\SSL OpenVMS: SYS$COMMON:[OPENSSL-COMMON] For 32bit Windows applications on Windows 64bit (WOW64), always replace `C:\Program Files` by `C:\Program Files (x86)`. ### prefix --prefix=DIR The top of the installation directory tree. Defaults are: Unix: /usr/local Windows: C:\Program Files\OpenSSL OpenVMS: SYS$COMMON:[OPENSSL] Compiler Warnings ----------------- --strict-warnings This is a developer flag that switches on various compiler options recommended for OpenSSL development. It only works when using gcc or clang as the compiler. If you are developing a patch for OpenSSL then it is recommended that you use this option where possible. ZLib Flags ---------- ### with-zlib-include --with-zlib-include=DIR The directory for the location of the zlib include file. This option is only necessary if [zlib](#zlib) is used and the include file is not already on the system include path. ### with-zlib-lib --with-zlib-lib=LIB **On Unix**: this is the directory containing the zlib library. If not provided the system library path will be used. **On Windows:** this is the filename of the zlib library (with or without a path). This flag must be provided if the [zlib-dynamic](#zlib-dynamic) option is not also used. If `zlib-dynamic` is used then this flag is optional and defaults to `ZLIB1` if not provided. **On VMS:** this is the filename of the zlib library (with or without a path). This flag is optional and if not provided then `GNV$LIBZSHR`, `GNV$LIBZSHR32` or `GNV$LIBZSHR64` is used by default depending on the pointer size chosen. Seeding the Random Generator ---------------------------- --with-rand-seed=seed1[,seed2,...] A comma separated list of seeding methods which will be tried by OpenSSL in order to obtain random input (a.k.a "entropy") for seeding its cryptographically secure random number generator (CSPRNG). The current seeding methods are: ### os Use a trusted operating system entropy source. This is the default method if such an entropy source exists. ### getrandom Use the [getrandom(2)][man-getrandom] or equivalent system call. [man-getrandom]: http://man7.org/linux/man-pages/man2/getrandom.2.html ### devrandom Use the first device from the `DEVRANDOM` list which can be opened to read random bytes. The `DEVRANDOM` preprocessor constant expands to "/dev/urandom","/dev/random","/dev/srandom" on most unix-ish operating systems. ### egd Check for an entropy generating daemon. This source is ignored by the FIPS provider. ### rdcpu Use the `RDSEED` or `RDRAND` command if provided by the CPU. ### librandom Use librandom (not implemented yet). This source is ignored by the FIPS provider. ### none Disable automatic seeding. This is the default on some operating systems where no suitable entropy source exists, or no support for it is implemented yet. This option is ignored by the FIPS provider. For more information, see the section [Notes on random number generation][rng] at the end of this document. [rng]: #notes-on-random-number-generation Setting the FIPS HMAC key ------------------------- --fips-key=value As part of its self-test validation, the FIPS module must verify itself by performing a SHA-256 HMAC computation on itself. The default key is the SHA256 value of "the holy handgrenade of antioch" and is sufficient for meeting the FIPS requirements. To change the key to a different value, use this flag. The value should be a hex string no more than 64 characters. Enable and Disable Features --------------------------- Feature options always come in pairs, an option to enable feature `xxxx`, and an option to disable it: [ enable-xxxx | no-xxxx ] Whether a feature is enabled or disabled by default, depends on the feature. In the following list, always the non-default variant is documented: if feature `xxxx` is disabled by default then `enable-xxxx` is documented and if feature `xxxx` is enabled by default then `no-xxxx` is documented. ### no-afalgeng Don't build the AFALG engine. This option will be forced on a platform that does not support AFALG. ### enable-ktls Build with Kernel TLS support. This option will enable the use of the Kernel TLS data-path, which can improve performance and allow for the use of sendfile and splice system calls on TLS sockets. The Kernel may use TLS accelerators if any are available on the system. This option will be forced off on systems that do not support the Kernel TLS data-path. ### enable-asan Build with the Address sanitiser. This is a developer option only. It may not work on all platforms and should never be used in production environments. It will only work when used with gcc or clang and should be used in conjunction with the [no-shared](#no-shared) option. ### enable-acvp-tests Build support for Automated Cryptographic Validation Protocol (ACVP) tests. This is required for FIPS validation purposes. Certain ACVP tests require access to algorithm internals that are not normally accessible. Additional information related to ACVP can be found at . ### no-asm Do not use assembler code. This should be viewed as debugging/troubleshooting option rather than for production use. On some platforms a small amount of assembler code may still be used even with this option. ### no-async Do not build support for async operations. ### no-autoalginit Don't automatically load all supported ciphers and digests. Typically OpenSSL will make available all of its supported ciphers and digests. For a statically linked application this may be undesirable if small executable size is an objective. This only affects libcrypto. Ciphers and digests will have to be loaded manually using `EVP_add_cipher()` and `EVP_add_digest()` if this option is used. This option will force a non-shared build. ### no-autoerrinit Don't automatically load all libcrypto/libssl error strings. Typically OpenSSL will automatically load human readable error strings. For a statically linked application this may be undesirable if small executable size is an objective. ### no-autoload-config Don't automatically load the default `openssl.cnf` file. Typically OpenSSL will automatically load a system config file which configures default SSL options. ### enable-buildtest-c++ While testing, generate C++ buildtest files that simply check that the public OpenSSL header files are usable standalone with C++. Enabling this option demands extra care. For any compiler flag given directly as configuration option, you must ensure that it's valid for both the C and the C++ compiler. If not, the C++ build test will most likely break. As an alternative, you can use the language specific variables, `CFLAGS` and `CXXFLAGS`. ### --banner=text Use the specified text instead of the default banner at the end of configuration. ### --w On platforms where the choice of 32-bit or 64-bit architecture is not explicitly specified, `Configure` will print a warning message and wait for a few seconds to let you interrupt the configuration. Using this flag skips the wait. ### no-bulk Build only some minimal set of features. This is a developer option used internally for CI build tests of the project. ### no-cached-fetch Never cache algorithms when they are fetched from a provider. Normally, a provider indicates if the algorithms it supplies can be cached or not. Using this option will reduce run-time memory usage but it also introduces a significant performance penalty. This option is primarily designed to help with detecting incorrect reference counting. ### no-capieng Don't build the CAPI engine. This option will be forced if on a platform that does not support CAPI. ### no-cmp Don't build support for Certificate Management Protocol (CMP) and Certificate Request Message Format (CRMF). ### no-cms Don't build support for Cryptographic Message Syntax (CMS). ### no-comp Don't build support for SSL/TLS compression. If this option is enabled (the default), then compression will only work if the zlib or `zlib-dynamic` options are also chosen. ### enable-crypto-mdebug This now only enables the `failed-malloc` feature. ### enable-crypto-mdebug-backtrace This is a no-op; the project uses the compiler's address/leak sanitizer instead. ### no-ct Don't build support for Certificate Transparency (CT). ### no-deprecated Don't build with support for deprecated APIs up until and including the version given with `--api` (or the current version, if `--api` wasn't specified). ### no-dgram Don't build support for datagram based BIOs. Selecting this option will also force the disabling of DTLS. ### no-dso Don't build support for loading Dynamic Shared Objects (DSO) ### enable-devcryptoeng Build the `/dev/crypto` engine. This option is automatically selected on the BSD platform, in which case it can be disabled with `no-devcryptoeng`. ### no-dynamic-engine Don't build the dynamically loaded engines. This only has an effect in a shared build. ### no-ec Don't build support for Elliptic Curves. ### no-ec2m Don't build support for binary Elliptic Curves ### enable-ec_nistp_64_gcc_128 Enable support for optimised implementations of some commonly used NIST elliptic curves. This option is only supported on platforms: - with little-endian storage of non-byte types - that tolerate misaligned memory references - where the compiler: - supports the non-standard type `__uint128_t` - defines the built-in macro `__SIZEOF_INT128__` ### enable-egd Build support for gathering entropy from the Entropy Gathering Daemon (EGD). ### no-engine Don't build support for loading engines. ### no-err Don't compile in any error strings. ### enable-external-tests Enable building of integration with external test suites. This is a developer option and may not work on all platforms. The following external test suites are currently supported: - GOST engine test suite - Python PYCA/Cryptography test suite - krb5 test suite See the file [test/README-external.md](test/README-external.md) for further details. ### no-filenames Don't compile in filename and line number information (e.g. for errors and memory allocation). ### enable-fips Build (and install) the FIPS provider ### no-fips-securitychecks Don't perform FIPS module run-time checks related to enforcement of security parameters such as minimum security strength of keys. ### enable-fuzz-libfuzzer, enable-fuzz-afl Build with support for fuzzing using either libfuzzer or AFL. These are developer options only. They may not work on all platforms and should never be used in production environments. See the file [fuzz/README.md](fuzz/README.md) for further details. ### no-gost Don't build support for GOST based ciphersuites. Note that if this feature is enabled then GOST ciphersuites are only available if the GOST algorithms are also available through loading an externally supplied engine. ### no-legacy Don't build the legacy provider. Disabling this also disables the legacy algorithms: MD2 (already disabled by default). ### no-makedepend Don't generate dependencies. ### no-module Don't build any dynamically loadable engines. This also implies `no-dynamic-engine`. ### no-multiblock Don't build support for writing multiple records in one go in libssl Note: this is a different capability to the pipelining functionality. ### no-nextprotoneg Don't build support for the Next Protocol Negotiation (NPN) TLS extension. ### no-ocsp Don't build support for Online Certificate Status Protocol (OCSP). ### no-padlockeng Don't build the padlock engine. ### no-hw-padlock As synonym for `no-padlockeng`. Deprecated and should not be used. ### no-pic Don't build with support for Position Independent Code. ### no-pinshared Don't pin the shared libraries. By default OpenSSL will attempt to stay in memory until the process exits. This is so that libcrypto and libssl can be properly cleaned up automatically via an `atexit()` handler. The handler is registered by libcrypto and cleans up both libraries. On some platforms the `atexit()` handler will run on unload of libcrypto (if it has been dynamically loaded) rather than at process exit. This option can be used to stop OpenSSL from attempting to stay in memory until the process exits. This could lead to crashes if either libcrypto or libssl have already been unloaded at the point that the atexit handler is invoked, e.g. on a platform which calls `atexit()` on unload of the library, and libssl is unloaded before libcrypto then a crash is likely to happen. Note that shared library pinning is not automatically disabled for static builds, i.e., `no-shared` does not imply `no-pinshared`. This may come as a surprise when linking libcrypto statically into a shared third-party library, because in this case the shared library will be pinned. To prevent this behaviour, you need to configure the static build using `no-shared` and `no-pinshared` together. Applications can suppress running of the `atexit()` handler at run time by using the `OPENSSL_INIT_NO_ATEXIT` option to `OPENSSL_init_crypto()`. See the man page for it for further details. ### no-posix-io Don't use POSIX IO capabilities. ### no-psk Don't build support for Pre-Shared Key based ciphersuites. ### no-rdrand Don't use hardware RDRAND capabilities. ### no-rfc3779 Don't build support for RFC3779, "X.509 Extensions for IP Addresses and AS Identifiers". ### sctp Build support for Stream Control Transmission Protocol (SCTP). ### no-shared Do not create shared libraries, only static ones. See [Notes on shared libraries](#notes-on-shared-libraries) below. ### no-sock Don't build support for socket BIOs. ### no-srp Don't build support for Secure Remote Password (SRP) protocol or SRP based ciphersuites. ### no-srtp Don't build Secure Real-Time Transport Protocol (SRTP) support. ### no-sse2 Exclude SSE2 code paths from 32-bit x86 assembly modules. Normally SSE2 extension is detected at run-time, but the decision whether or not the machine code will be executed is taken solely on CPU capability vector. This means that if you happen to run OS kernel which does not support SSE2 extension on Intel P4 processor, then your application might be exposed to "illegal instruction" exception. There might be a way to enable support in kernel, e.g. FreeBSD kernel can be compiled with `CPU_ENABLE_SSE`, and there is a way to disengage SSE2 code paths upon application start-up, but if you aim for wider "audience" running such kernel, consider `no-sse2`. Both the `386` and `no-asm` options imply `no-sse2`. ### no-ssl-trace Don't build with SSL Trace capabilities. This removes the `-trace` option from `s_client` and `s_server`, and omits the `SSL_trace()` function from libssl. Disabling `ssl-trace` may provide a small reduction in libssl binary size. ### no-static-engine Don't build the statically linked engines. This only has an impact when not built "shared". ### no-stdio Don't use anything from the C header file `stdio.h` that makes use of the `FILE` type. Only libcrypto and libssl can be built in this way. Using this option will suppress building the command line applications. Additionally, since the OpenSSL tests also use the command line applications, the tests will also be skipped. ### no-tests Don't build test programs or run any tests. ### no-threads Don't build with support for multi-threaded applications. ### threads Build with support for multi-threaded applications. Most platforms will enable this by default. However, if on a platform where this is not the case then this will usually require additional system-dependent options! See [Notes on multi-threading](#notes-on-multi-threading) below. ### enable-trace Build with support for the integrated tracing api. See manual pages OSSL_trace_set_channel(3) and OSSL_trace_enabled(3) for details. ### no-ts Don't build Time Stamping (TS) Authority support. ### enable-ubsan Build with the Undefined Behaviour sanitiser (UBSAN). This is a developer option only. It may not work on all platforms and should never be used in production environments. It will only work when used with gcc or clang and should be used in conjunction with the `-DPEDANTIC` option (or the `--strict-warnings` option). ### no-ui-console Don't build with the User Interface (UI) console method The User Interface console method enables text based console prompts. ### enable-unit-test Enable additional unit test APIs. This should not typically be used in production deployments. ### no-uplink Don't build support for UPLINK interface. ### enable-weak-ssl-ciphers Build support for SSL/TLS ciphers that are considered "weak" Enabling this includes for example the RC4 based ciphersuites. ### zlib Build with support for zlib compression/decompression. ### zlib-dynamic Like the zlib option, but has OpenSSL load the zlib library dynamically when needed. This is only supported on systems where loading of shared libraries is supported. ### 386 In 32-bit x86 builds, use the 80386 instruction set only in assembly modules The default x86 code is more efficient, but requires at least an 486 processor. Note: This doesn't affect compiler generated code, so this option needs to be accompanied by a corresponding compiler-specific option. ### no-{protocol} no-{ssl|ssl3|tls|tls1|tls1_1|tls1_2|tls1_3|dtls|dtls1|dtls1_2} Don't build support for negotiating the specified SSL/TLS protocol. If `no-tls` is selected then all of `tls1`, `tls1_1`, `tls1_2` and `tls1_3` are disabled. Similarly `no-dtls` will disable `dtls1` and `dtls1_2`. The `no-ssl` option is synonymous with `no-ssl3`. Note this only affects version negotiation. OpenSSL will still provide the methods for applications to explicitly select the individual protocol versions. ### no-{protocol}-method no-{ssl3|tls1|tls1_1|tls1_2|dtls1|dtls1_2}-method Analogous to `no-{protocol}` but in addition do not build the methods for applications to explicitly select individual protocol versions. Note that there is no `no-tls1_3-method` option because there is no application method for TLSv1.3. Using individual protocol methods directly is deprecated. Applications should use `TLS_method()` instead. ### enable-{algorithm} enable-{md2|rc5} Build with support for the specified algorithm. ### no-{algorithm} no-{aria|bf|blake2|camellia|cast|chacha|cmac| des|dh|dsa|ecdh|ecdsa|idea|md4|mdc2|ocb| poly1305|rc2|rc4|rmd160|scrypt|seed| siphash|siv|sm2|sm3|sm4|whirlpool} Build without support for the specified algorithm. The `ripemd` algorithm is deprecated and if used is synonymous with `rmd160`. ### Compiler-specific options -Dxxx, -Ixxx, -Wp, -lxxx, -Lxxx, -Wl, -rpath, -R, -framework, -static These system specific options will be recognised and passed through to the compiler to allow you to define preprocessor symbols, specify additional libraries, library directories or other compiler options. It might be worth noting that some compilers generate code specifically for processor the compiler currently executes on. This is not necessarily what you might have in mind, since it might be unsuitable for execution on other, typically older, processor. Consult your compiler documentation. Take note of the [Environment Variables](#environment-variables) documentation below and how these flags interact with those variables. -xxx, +xxx, /xxx Additional options that are not otherwise recognised are passed through as they are to the compiler as well. Unix-style options beginning with a `-` or `+` and Windows-style options beginning with a `/` are recognized. Again, consult your compiler documentation. If the option contains arguments separated by spaces, then the URL-style notation `%20` can be used for the space character in order to avoid having to quote the option. For example, `-opt%20arg` gets expanded to `-opt arg`. In fact, any ASCII character can be encoded as %xx using its hexadecimal encoding. Take note of the [Environment Variables](#environment-variables) documentation below and how these flags interact with those variables. ### Environment Variables VAR=value Assign the given value to the environment variable `VAR` for `Configure`. These work just like normal environment variable assignments, but are supported on all platforms and are confined to the configuration scripts only. These assignments override the corresponding value in the inherited environment, if there is one. The following variables are used as "`make` variables" and can be used as an alternative to giving preprocessor, compiler and linker options directly as configuration. The following variables are supported: AR The static library archiver. ARFLAGS Flags for the static library archiver. AS The assembler compiler. ASFLAGS Flags for the assembler compiler. CC The C compiler. CFLAGS Flags for the C compiler. CXX The C++ compiler. CXXFLAGS Flags for the C++ compiler. CPP The C/C++ preprocessor. CPPFLAGS Flags for the C/C++ preprocessor. CPPDEFINES List of CPP macro definitions, separated by a platform specific character (':' or space for Unix, ';' for Windows, ',' for VMS). This can be used instead of using -D (or what corresponds to that on your compiler) in CPPFLAGS. CPPINCLUDES List of CPP inclusion directories, separated the same way as for CPPDEFINES. This can be used instead of -I (or what corresponds to that on your compiler) in CPPFLAGS. HASHBANGPERL Perl invocation to be inserted after '#!' in public perl scripts (only relevant on Unix). LD The program linker (not used on Unix, $(CC) is used there). LDFLAGS Flags for the shared library, DSO and program linker. LDLIBS Extra libraries to use when linking. Takes the form of a space separated list of library specifications on Unix and Windows, and as a comma separated list of libraries on VMS. RANLIB The library archive indexer. RC The Windows resource compiler. RCFLAGS Flags for the Windows resource compiler. RM The command to remove files and directories. These cannot be mixed with compiling/linking flags given on the command line. In other words, something like this isn't permitted. $ ./Configure -DFOO CPPFLAGS=-DBAR -DCOOKIE Backward compatibility note: To be compatible with older configuration scripts, the environment variables are ignored if compiling/linking flags are given on the command line, except for the following: AR, CC, CXX, CROSS_COMPILE, HASHBANGPERL, PERL, RANLIB, RC, and WINDRES For example, the following command will not see `-DBAR`: $ CPPFLAGS=-DBAR ./Configure -DCOOKIE However, the following will see both set variables: $ CC=gcc CROSS_COMPILE=x86_64-w64-mingw32- ./Configure -DCOOKIE If `CC` is set, it is advisable to also set `CXX` to ensure both the C and C++ compiler are in the same "family". This becomes relevant with `enable-external-tests` and `enable-buildtest-c++`. ### Reconfigure reconf reconfigure Reconfigure from earlier data. This fetches the previous command line options and environment from data saved in `configdata.pm` and runs the configuration process again, using these options and environment. Note: NO other option is permitted together with `reconf`. Note: The original configuration saves away values for ALL environment variables that were used, and if they weren't defined, they are still saved away with information that they weren't originally defined. This information takes precedence over environment variables that are defined when reconfiguring. Displaying configuration data ----------------------------- The configuration script itself will say very little, and finishes by creating `configdata.pm`. This perl module can be loaded by other scripts to find all the configuration data, and it can also be used as a script to display all sorts of configuration data in a human readable form. For more information, please do: $ ./configdata.pm --help # Unix or $ perl configdata.pm --help # Windows and VMS Installation Steps in Detail ============================ Configure OpenSSL ----------------- ### Automatic Configuration In previous version, the `config` script determined the platform type and compiler and then called `Configure`. Starting with this release, they are the same. #### Unix / Linux / macOS $ ./Configure [[ options ]] #### OpenVMS $ perl Configure [[ options ]] #### Windows $ perl Configure [[ options ]] ### Manual Configuration OpenSSL knows about a range of different operating system, hardware and compiler combinations. To see the ones it knows about, run $ ./Configure LIST # Unix or $ perl Configure LIST # All other platforms For the remainder of this text, the Unix form will be used in all examples. Please use the appropriate form for your platform. Pick a suitable name from the list that matches your system. For most operating systems there is a choice between using cc or gcc. When you have identified your system (and if necessary compiler) use this name as the argument to `Configure`. For example, a `linux-elf` user would run: $ ./Configure linux-elf [[ options ]] ### Creating your own Configuration If your system isn't listed, you will have to create a configuration file named `Configurations/{{ something }}.conf` and add the correct configuration for your system. See the available configs as examples and read [Configurations/README.md](Configurations/README.md) and [Configurations/README-design.md](Configurations/README-design.md) for more information. The generic configurations `cc` or `gcc` should usually work on 32 bit Unix-like systems. `Configure` creates a build file (`Makefile` on Unix, `makefile` on Windows and `descrip.mms` on OpenVMS) from a suitable template in `Configurations/`, and defines various macros in `include/openssl/configuration.h` (generated from `include/openssl/configuration.h.in`. If none of the generated build files suit your purpose, it's possible to write your own build file template and give its name through the environment variable `BUILDFILE`. For example, Ninja build files could be supported by writing `Configurations/build.ninja.tmpl` and then configure with `BUILDFILE` set like this (Unix syntax shown, you'll have to adapt for other platforms): $ BUILDFILE=build.ninja perl Configure [options...] ### Out of Tree Builds OpenSSL can be configured to build in a build directory separate from the source code directory. It's done by placing yourself in some other directory and invoking the configuration commands from there. #### Unix example $ mkdir /var/tmp/openssl-build $ cd /var/tmp/openssl-build $ /PATH/TO/OPENSSL/SOURCE/Configure [[ options ]] #### OpenVMS example $ set default sys$login: $ create/dir [.tmp.openssl-build] $ set default [.tmp.openssl-build] $ perl D:[PATH.TO.OPENSSL.SOURCE]Configure [[ options ]] #### Windows example $ C: $ mkdir \temp-openssl $ cd \temp-openssl $ perl d:\PATH\TO\OPENSSL\SOURCE\Configure [[ options ]] Paths can be relative just as well as absolute. `Configure` will do its best to translate them to relative paths whenever possible. Build OpenSSL ------------- Build OpenSSL by running: $ make # Unix $ mms ! (or mmk) OpenVMS $ nmake # Windows This will build the OpenSSL libraries (`libcrypto.a` and `libssl.a` on Unix, corresponding on other platforms) and the OpenSSL binary (`openssl`). The libraries will be built in the top-level directory, and the binary will be in the `apps/` subdirectory. If the build fails, take a look at the [Build Failures](#build-failures) subsection of the [Troubleshooting](#troubleshooting) section. Test OpenSSL ------------ After a successful build, and before installing, the libraries should be tested. Run: $ make test # Unix $ mms test ! OpenVMS $ nmake test # Windows **Warning:** you MUST run the tests from an unprivileged account (or disable your privileges temporarily if your platform allows it). See [test/README.md](test/README.md) for further details how run tests. See [test/README-dev.md](test/README-dev.md) for guidelines on adding tests. Install OpenSSL --------------- If everything tests ok, install OpenSSL with $ make install # Unix $ mms install ! OpenVMS $ nmake install # Windows Note that in order to perform the install step above you need to have appropriate permissions to write to the installation directory. The above commands will install all the software components in this directory tree under `` (the directory given with `--prefix` or its default): ### Unix / Linux / macOS bin/ Contains the openssl binary and a few other utility scripts. include/openssl Contains the header files needed if you want to build your own programs that use libcrypto or libssl. lib Contains the OpenSSL library files. lib/engines Contains the OpenSSL dynamically loadable engines. share/man/man1 Contains the OpenSSL command line man-pages. share/man/man3 Contains the OpenSSL library calls man-pages. share/man/man5 Contains the OpenSSL configuration format man-pages. share/man/man7 Contains the OpenSSL other misc man-pages. share/doc/openssl/html/man1 share/doc/openssl/html/man3 share/doc/openssl/html/man5 share/doc/openssl/html/man7 Contains the HTML rendition of the man-pages. ### OpenVMS 'arch' is replaced with the architecture name, `ALPHA` or `IA64`, 'sover' is replaced with the shared library version (`0101` for 1.1), and 'pz' is replaced with the pointer size OpenSSL was built with: [.EXE.'arch'] Contains the openssl binary. [.EXE] Contains a few utility scripts. [.include.openssl] Contains the header files needed if you want to build your own programs that use libcrypto or libssl. [.LIB.'arch'] Contains the OpenSSL library files. [.ENGINES'sover''pz'.'arch'] Contains the OpenSSL dynamically loadable engines. [.SYS$STARTUP] Contains startup, login and shutdown scripts. These define appropriate logical names and command symbols. [.SYSTEST] Contains the installation verification procedure. [.HTML] Contains the HTML rendition of the manual pages. ### Additional Directories Additionally, install will add the following directories under OPENSSLDIR (the directory given with `--openssldir` or its default) for you convenience: certs Initially empty, this is the default location for certificate files. private Initially empty, this is the default location for private key files. misc Various scripts. The installation directory should be appropriately protected to ensure unprivileged users cannot make changes to OpenSSL binaries or files, or install engines. If you already have a pre-installed version of OpenSSL as part of your Operating System it is recommended that you do not overwrite the system version and instead install to somewhere else. Package builders who want to configure the library for standard locations, but have the package installed somewhere else so that it can easily be packaged, can use $ make DESTDIR=/tmp/package-root install # Unix $ mms/macro="DESTDIR=TMP:[PACKAGE-ROOT]" install ! OpenVMS The specified destination directory will be prepended to all installation target paths. Compatibility issues with previous OpenSSL versions --------------------------------------------------- ### COMPILING existing applications Starting with version 1.1.0, OpenSSL hides a number of structures that were previously open. This includes all internal libssl structures and a number of EVP types. Accessor functions have been added to allow controlled access to the structures' data. This means that some software needs to be rewritten to adapt to the new ways of doing things. This often amounts to allocating an instance of a structure explicitly where you could previously allocate them on the stack as automatic variables, and using the provided accessor functions where you would previously access a structure's field directly. Some APIs have changed as well. However, older APIs have been preserved when possible. Post-installation Notes ----------------------- With the default OpenSSL installation comes a FIPS provider module, which needs some post-installation attention, without which it will not be usable. This involves using the following command: $ openssl fipsinstall See the openssl-fipsinstall(1) manual for details and examples. Advanced Build Options ====================== Environment Variables --------------------- A number of environment variables can be used to provide additional control over the build process. Typically these should be defined prior to running `Configure`. Not all environment variables are relevant to all platforms. AR The name of the ar executable to use. BUILDFILE Use a different build file name than the platform default ("Makefile" on Unix-like platforms, "makefile" on native Windows, "descrip.mms" on OpenVMS). This requires that there is a corresponding build file template. See [Configurations/README.md](Configurations/README.md) for further information. CC The compiler to use. Configure will attempt to pick a default compiler for your platform but this choice can be overridden using this variable. Set it to the compiler executable you wish to use, e.g. gcc or clang. CROSS_COMPILE This environment variable has the same meaning as for the "--cross-compile-prefix" Configure flag described above. If both are set then the Configure flag takes precedence. HASHBANGPERL The command string for the Perl executable to insert in the #! line of perl scripts that will be publicly installed. Default: /usr/bin/env perl Note: the value of this variable is added to the same scripts on all platforms, but it's only relevant on Unix-like platforms. KERNEL_BITS This can be the value `32` or `64` to specify the architecture when it is not "obvious" to the configuration. It should generally not be necessary to specify this environment variable. NM The name of the nm executable to use. OPENSSL_LOCAL_CONFIG_DIR OpenSSL comes with a database of information about how it should be built on different platforms as well as build file templates for those platforms. The database is comprised of ".conf" files in the Configurations directory. The build file templates reside there as well as ".tmpl" files. See the file [Configurations/README.md](Configurations/README.md) for further information about the format of ".conf" files as well as information on the ".tmpl" files. In addition to the standard ".conf" and ".tmpl" files, it is possible to create your own ".conf" and ".tmpl" files and store them locally, outside the OpenSSL source tree. This environment variable can be set to the directory where these files are held and will be considered by Configure before it looks in the standard directories. PERL The name of the Perl executable to use when building OpenSSL. Only needed if builing should use a different Perl executable than what is used to run the Configure script. RANLIB The name of the ranlib executable to use. RC The name of the rc executable to use. The default will be as defined for the target platform in the ".conf" file. If not defined then "windres" will be used. The WINDRES environment variable is synonymous to this. If both are defined then RC takes precedence. WINDRES See RC. Makefile Targets ---------------- The `Configure` script generates a Makefile in a format relevant to the specific platform. The Makefiles provide a number of targets that can be used. Not all targets may be available on all platforms. Only the most common targets are described here. Examine the Makefiles themselves for the full list. all The target to build all the software components and documentation. build_sw Build all the software components. THIS IS THE DEFAULT TARGET. build_docs Build all documentation components. clean Remove all build artefacts and return the directory to a "clean" state. depend Rebuild the dependencies in the Makefiles. This is a legacy option that no longer needs to be used since OpenSSL 1.1.0. install Install all OpenSSL components. install_sw Only install the OpenSSL software components. install_docs Only install the OpenSSL documentation components. install_man_docs Only install the OpenSSL man pages (Unix only). install_html_docs Only install the OpenSSL HTML documentation. install_fips Install the FIPS provider module configuration file. list-tests Prints a list of all the self test names. test Build and run the OpenSSL self tests. uninstall Uninstall all OpenSSL components. reconfigure reconf Re-run the configuration process, as exactly as the last time as possible. update This is a developer option. If you are developing a patch for OpenSSL you may need to use this if you want to update automatically generated files; add new error codes or add new (or change the visibility of) public API functions. (Unix only). Running Selected Tests ---------------------- You can specify a set of tests to be performed using the `make` variable `TESTS`. See the section [Running Selected Tests of test/README.md](test/README.md#running-selected-tests). Troubleshooting =============== Configuration Problems ---------------------- ### Selecting the correct target The `./Configure` script tries hard to guess your operating system, but in some cases it does not succeed. You will see a message like the following: $ ./Configure Operating system: x86-whatever-minix This system (minix) is not supported. See file INSTALL.md for details. Even if the automatic target selection by the `./Configure` script fails, chances are that you still might find a suitable target in the `Configurations` directory, which you can supply to the `./Configure` command, possibly after some adjustment. The `Configurations/` directory contains a lot of examples of such targets. The main configuration file is [10-main.conf], which contains all targets that are officially supported by the OpenSSL team. Other configuration files contain targets contributed by other OpenSSL users. The list of targets can be found in a Perl list `my %targets = ( ... )`. my %targets = ( ... "target-name" => { inherit_from => [ "base-target" ], CC => "...", cflags => add("..."), asm_arch => '...', perlasm_scheme => "...", }, ... ) If you call `./Configure` without arguments, it will give you a list of all known targets. Using `grep`, you can lookup the target definition in the `Configurations/` directory. For example the `android-x86_64` can be found in [Configurations/15-android.conf](Configurations/15-android.conf). The directory contains two README files, which explain the general syntax and design of the configuration files. - [Configurations/README.md](Configurations/README.md) - [Configurations/README-design.md](Configurations/README-design.md) If you need further help, try to search the [openssl-users] mailing list or the [GitHub Issues] for existing solutions. If you don't find anything, you can [raise an issue] to ask a question yourself. More about our support resources can be found in the [SUPPORT] file. ### Configuration Errors If the `./Configure` or `./Configure` command fails with an error message, read the error message carefully and try to figure out whether you made a mistake (e.g., by providing a wrong option), or whether the script is working incorrectly. If you think you encountered a bug, please [raise an issue] on GitHub to file a bug report. Along with a short description of the bug, please provide the complete configure command line and the relevant output including the error message. Note: To make the output readable, pleace add a 'code fence' (three backquotes ` ``` ` on a separate line) before and after your output: ``` ./Configure [your arguments...] [output...] ``` Build Failures -------------- If the build fails, look carefully at the output. Try to locate and understand the error message. It might be that the compiler is already telling you exactly what you need to do to fix your problem. There may be reasons for the failure that aren't problems in OpenSSL itself, for example if the compiler reports missing standard or third party headers. If the build succeeded previously, but fails after a source or configuration change, it might be helpful to clean the build tree before attempting another build. Use this command: $ make clean # Unix $ mms clean ! (or mmk) OpenVMS $ nmake clean # Windows Assembler error messages can sometimes be sidestepped by using the `no-asm` configuration option. See also [notes](#notes-on-assembler-modules-compilation). Compiling parts of OpenSSL with gcc and others with the system compiler will result in unresolved symbols on some systems. If you are still having problems, try to search the [openssl-users] mailing list or the [GitHub Issues] for existing solutions. If you think you encountered an OpenSSL bug, please [raise an issue] to file a bug report. Please take the time to review the existing issues first; maybe the bug was already reported or has already been fixed. Test Failures ------------- If some tests fail, look at the output. There may be reasons for the failure that isn't a problem in OpenSSL itself (like an OS malfunction or a Perl issue). You may want increased verbosity, that can be accomplished as described in section [Test Failures of test/README.md](test/README.md#test-failures). You may also want to selectively specify which test(s) to perform. This can be done using the `make` variable `TESTS` as described in section [Running Selected Tests of test/README.md](test/README.md#running-selected-tests). If you find a problem with OpenSSL itself, try removing any compiler optimization flags from the `CFLAGS` line in the Makefile and run `make clean; make` or corresponding. To report a bug please open an issue on GitHub, at . Notes ===== Notes on multi-threading ------------------------ For some systems, the OpenSSL `Configure` script knows what compiler options are needed to generate a library that is suitable for multi-threaded applications. On these systems, support for multi-threading is enabled by default; use the `no-threads` option to disable (this should never be necessary). On other systems, to enable support for multi-threading, you will have to specify at least two options: `threads`, and a system-dependent option. (The latter is `-D_REENTRANT` on various systems.) The default in this case, obviously, is not to include support for multi-threading (but you can still use `no-threads` to suppress an annoying warning message from the `Configure` script.) OpenSSL provides built-in support for two threading models: pthreads (found on most UNIX/Linux systems), and Windows threads. No other threading models are supported. If your platform does not provide pthreads or Windows threads then you should use `Configure` with the `no-threads` option. For pthreads, all locks are non-recursive. In addition, in a debug build, the mutex attribute `PTHREAD_MUTEX_ERRORCHECK` is used. If this is not available on your platform, you might have to add `-DOPENSSL_NO_MUTEX_ERRORCHECK` to your `Configure` invocation. (On Linux `PTHREAD_MUTEX_ERRORCHECK` is an enum value, so a built-in ifdef test cannot be used.) Notes on shared libraries ------------------------- For most systems the OpenSSL `Configure` script knows what is needed to build shared libraries for libcrypto and libssl. On these systems the shared libraries will be created by default. This can be suppressed and only static libraries created by using the `no-shared` option. On systems where OpenSSL does not know how to build shared libraries the `no-shared` option will be forced and only static libraries will be created. Shared libraries are named a little differently on different platforms. One way or another, they all have the major OpenSSL version number as part of the file name, i.e. for OpenSSL 1.1.x, `1.1` is somehow part of the name. On most POSIX platforms, shared libraries are named `libcrypto.so.1.1` and `libssl.so.1.1`. on Cygwin, shared libraries are named `cygcrypto-1.1.dll` and `cygssl-1.1.dll` with import libraries `libcrypto.dll.a` and `libssl.dll.a`. On Windows build with MSVC or using MingW, shared libraries are named `libcrypto-1_1.dll` and `libssl-1_1.dll` for 32-bit Windows, `libcrypto-1_1-x64.dll` and `libssl-1_1-x64.dll` for 64-bit x86_64 Windows, and `libcrypto-1_1-ia64.dll` and `libssl-1_1-ia64.dll` for IA64 Windows. With MSVC, the import libraries are named `libcrypto.lib` and `libssl.lib`, while with MingW, they are named `libcrypto.dll.a` and `libssl.dll.a`. On VMS, shareable images (VMS speak for shared libraries) are named `ossl$libcrypto0101_shr.exe` and `ossl$libssl0101_shr.exe`. However, when OpenSSL is specifically built for 32-bit pointers, the shareable images are named `ossl$libcrypto0101_shr32.exe` and `ossl$libssl0101_shr32.exe` instead, and when built for 64-bit pointers, they are named `ossl$libcrypto0101_shr64.exe` and `ossl$libssl0101_shr64.exe`. Notes on random number generation --------------------------------- Availability of cryptographically secure random numbers is required for secret key generation. OpenSSL provides several options to seed the internal CSPRNG. If not properly seeded, the internal CSPRNG will refuse to deliver random bytes and a "PRNG not seeded error" will occur. The seeding method can be configured using the `--with-rand-seed` option, which can be used to specify a comma separated list of seed methods. However, in most cases OpenSSL will choose a suitable default method, so it is not necessary to explicitly provide this option. Note also that not all methods are available on all platforms. The FIPS provider will silently ignore seed sources that were not validated. I) On operating systems which provide a suitable randomness source (in form of a system call or system device), OpenSSL will use the optimal available method to seed the CSPRNG from the operating system's randomness sources. This corresponds to the option `--with-rand-seed=os`. II) On systems without such a suitable randomness source, automatic seeding and reseeding is disabled (`--with-rand-seed=none`) and it may be necessary to install additional support software to obtain a random seed and reseed the CSPRNG manually. Please check out the manual pages for `RAND_add()`, `RAND_bytes()`, `RAND_egd()`, and the FAQ for more information. Notes on assembler modules compilation -------------------------------------- Compilation of some code paths in assembler modules might depend on whether the current assembler version supports certain ISA extensions or not. Code paths that use the AES-NI, PCLMULQDQ, SSSE3, and SHA extensions are always assembled. Apart from that, the minimum requirements for the assembler versions are shown in the table below: | ISA extension | GNU as | nasm | llvm | |---------------|--------|--------|---------| | AVX | 2.19 | 2.09 | 3.0 | | AVX2 | 2.22 | 2.10 | 3.1 | | ADCX/ADOX | 2.23 | 2.10 | 3.3 | | AVX512 | 2.25 | 2.11.8 | 3.6 (*) | | AVX512IFMA | 2.26 | 2.11.8 | 6.0 (*) | | VAES | 2.30 | 2.13.3 | 6.0 (*) | --- (*) Even though AVX512 support was implemented in llvm 3.6, prior to version 7.0 an explicit -march flag was apparently required to compile assembly modules. But then the compiler generates processor-specific code, which in turn contradicts the idea of performing dispatch at run-time, which is facilitated by the special variable `OPENSSL_ia32cap`. For versions older than 7.0, it is possible to work around the problem by forcing the build procedure to use the following script: #!/bin/sh exec clang -no-integrated-as "$@" instead of the real clang. In which case it doesn't matter what clang version is used, as it is the version of the GNU assembler that will be checked. --- [openssl-users]: [SUPPORT]: ./SUPPORT.md [GitHub Issues]: [raise an issue]: [10-main.conf]: Configurations/10-main.conf diff --git a/crypto/openssl/NEWS.md b/crypto/openssl/NEWS.md index f7ca47baff87..8f0d973e057b 100644 --- a/crypto/openssl/NEWS.md +++ b/crypto/openssl/NEWS.md @@ -1,1618 +1,1624 @@ NEWS ==== This file gives a brief overview of the major changes between each OpenSSL release. For more details please read the CHANGES file. OpenSSL Releases ---------------- - [OpenSSL 3.0](#openssl-30) - [OpenSSL 1.1.1](#openssl-111) - [OpenSSL 1.1.0](#openssl-110) - [OpenSSL 1.0.2](#openssl-102) - [OpenSSL 1.0.1](#openssl-101) - [OpenSSL 1.0.0](#openssl-100) - [OpenSSL 0.9.x](#openssl-09x) OpenSSL 3.0 ----------- +### Major changes between OpenSSL 3.0.11 and OpenSSL 3.0.12 [24 Oct 2023] + + * Mitigate incorrect resize handling for symmetric cipher keys and IVs. + ([CVE-2023-5363]) + ### Major changes between OpenSSL 3.0.10 and OpenSSL 3.0.11 [19 Sep 2023] * Fix POLY1305 MAC implementation corrupting XMM registers on Windows ([CVE-2023-4807]) ### Major changes between OpenSSL 3.0.9 and OpenSSL 3.0.10 [1 Aug 2023] * Fix excessive time spent checking DH q parameter value ([CVE-2023-3817]) * Fix DH_check() excessive time with over sized modulus ([CVE-2023-3446]) * Do not ignore empty associated data entries with AES-SIV ([CVE-2023-2975]) ### Major changes between OpenSSL 3.0.8 and OpenSSL 3.0.9 [30 May 2023] * Mitigate for very slow `OBJ_obj2txt()` performance with gigantic OBJECT IDENTIFIER sub-identities. ([CVE-2023-2650]) * Fixed buffer overread in AES-XTS decryption on ARM 64 bit platforms ([CVE-2023-1255]) * Fixed documentation of X509_VERIFY_PARAM_add0_policy() ([CVE-2023-0466]) * Fixed handling of invalid certificate policies in leaf certificates ([CVE-2023-0465]) * Limited the number of nodes created in a policy tree ([CVE-2023-0464]) ### Major changes between OpenSSL 3.0.7 and OpenSSL 3.0.8 [7 Feb 2023] * Fixed NULL dereference during PKCS7 data verification ([CVE-2023-0401]) * Fixed X.400 address type confusion in X.509 GeneralName ([CVE-2023-0286]) * Fixed NULL dereference validating DSA public key ([CVE-2023-0217]) * Fixed Invalid pointer dereference in d2i_PKCS7 functions ([CVE-2023-0216]) * Fixed Use-after-free following BIO_new_NDEF ([CVE-2023-0215]) * Fixed Double free after calling PEM_read_bio_ex ([CVE-2022-4450]) * Fixed Timing Oracle in RSA Decryption ([CVE-2022-4304]) * Fixed X.509 Name Constraints Read Buffer Overflow ([CVE-2022-4203]) * Fixed X.509 Policy Constraints Double Locking ([CVE-2022-3996]) ### Major changes between OpenSSL 3.0.6 and OpenSSL 3.0.7 [1 Nov 2022] * Added RIPEMD160 to the default provider. * Fixed regressions introduced in 3.0.6 version. * Fixed two buffer overflows in punycode decoding functions. ([CVE-2022-3786]) and ([CVE-2022-3602]) ### Major changes between OpenSSL 3.0.5 and OpenSSL 3.0.6 [11 Oct 2022] * Fix for custom ciphers to prevent accidental use of NULL encryption ([CVE-2022-3358]) ### Major changes between OpenSSL 3.0.4 and OpenSSL 3.0.5 [5 Jul 2022] * Fixed heap memory corruption with RSA private key operation ([CVE-2022-2274]) * Fixed AES OCB failure to encrypt some bytes on 32-bit x86 platforms ([CVE-2022-2097]) ### Major changes between OpenSSL 3.0.3 and OpenSSL 3.0.4 [21 Jun 2022] * Fixed additional bugs in the c_rehash script which was not properly sanitising shell metacharacters to prevent command injection ([CVE-2022-2068]) ### Major changes between OpenSSL 3.0.2 and OpenSSL 3.0.3 [3 May 2022] * Fixed a bug in the c_rehash script which was not properly sanitising shell metacharacters to prevent command injection ([CVE-2022-1292]) * Fixed a bug in the function `OCSP_basic_verify` that verifies the signer certificate on an OCSP response ([CVE-2022-1343]) * Fixed a bug where the RC4-MD5 ciphersuite incorrectly used the AAD data as the MAC key ([CVE-2022-1434]) * Fix a bug in the OPENSSL_LH_flush() function that breaks reuse of the memory occuppied by the removed hash table entries ([CVE-2022-1473]) ### Major changes between OpenSSL 3.0.1 and OpenSSL 3.0.2 [15 Mar 2022] * Fixed a bug in the BN_mod_sqrt() function that can cause it to loop forever for non-prime moduli ([CVE-2022-0778]) ### Major changes between OpenSSL 3.0.0 and OpenSSL 3.0.1 [14 Dec 2021] * Fixed invalid handling of X509_verify_cert() internal errors in libssl ([CVE-2021-4044]) * Allow fetching an operation from the provider that owns an unexportable key as a fallback if that is still allowed by the property query. ### Major changes between OpenSSL 1.1.1 and OpenSSL 3.0.0 [7 sep 2021] * Enhanced 'openssl list' with many new options. * Added migration guide to man7. * Implemented support for fully "pluggable" TLSv1.3 groups. * Added suport for Kernel TLS (KTLS). * Changed the license to the Apache License v2.0. * Moved all variations of the EVP ciphers CAST5, BF, IDEA, SEED, RC2, RC4, RC5, and DES to the legacy provider. * Moved the EVP digests MD2, MD4, MDC2, WHIRLPOOL and RIPEMD-160 to the legacy provider. * Added convenience functions for generating asymmetric key pairs. * Deprecated the `OCSP_REQ_CTX` type and functions. * Deprecated the `EC_KEY` and `EC_KEY_METHOD` types and functions. * Deprecated the `RSA` and `RSA_METHOD` types and functions. * Deprecated the `DSA` and `DSA_METHOD` types and functions. * Deprecated the `DH` and `DH_METHOD` types and functions. * Deprecated the `ERR_load_` functions. * Remove the `RAND_DRBG` API. * Deprecated the `ENGINE` API. * Added `OSSL_LIB_CTX`, a libcrypto library context. * Added various `_ex` functions to the OpenSSL API that support using a non-default `OSSL_LIB_CTX`. * Interactive mode is removed from the 'openssl' program. * The X25519, X448, Ed25519, Ed448, SHAKE128 and SHAKE256 algorithms are included in the FIPS provider. * X509 certificates signed using SHA1 are no longer allowed at security level 1 or higher. The default security level for TLS is 1, so certificates signed using SHA1 are by default no longer trusted to authenticate servers or clients. * enable-crypto-mdebug and enable-crypto-mdebug-backtrace were mostly disabled; the project uses address sanitize/leak-detect instead. * Added a Certificate Management Protocol (CMP, RFC 4210) implementation also covering CRMF (RFC 4211) and HTTP transfer (RFC 6712). It is part of the crypto lib and adds a 'cmp' app with a demo configuration. All widely used CMP features are supported for both clients and servers. * Added a proper HTTP client supporting GET with optional redirection, POST, arbitrary request and response content types, TLS, persistent connections, connections via HTTP(s) proxies, connections and exchange via user-defined BIOs (allowing implicit connections), and timeout checks. * Added util/check-format.pl for checking adherence to the coding guidelines. * Added OSSL_ENCODER, a generic encoder API. * Added OSSL_DECODER, a generic decoder API. * Added OSSL_PARAM_BLD, an easier to use API to OSSL_PARAM. * Added error raising macros, ERR_raise() and ERR_raise_data(). * Deprecated ERR_put_error(), ERR_get_error_line(), ERR_get_error_line_data(), ERR_peek_error_line_data(), ERR_peek_last_error_line_data() and ERR_func_error_string(). * Added OSSL_PROVIDER_available(), to check provider availibility. * Added 'openssl mac' that uses the EVP_MAC API. * Added 'openssl kdf' that uses the EVP_KDF API. * Add OPENSSL_info() and 'openssl info' to get built-in data. * Add support for enabling instrumentation through trace and debug output. * Changed our version number scheme and set the next major release to 3.0.0 * Added EVP_MAC, an EVP layer MAC API, and a generic EVP_PKEY to EVP_MAC bridge. Supported MACs are: BLAKE2, CMAC, GMAC, HMAC, KMAC, POLY1305 and SIPHASH. * Removed the heartbeat message in DTLS feature. * Added EVP_KDF, an EVP layer KDF and PRF API, and a generic EVP_PKEY to EVP_KDF bridge. Supported KDFs are: HKDF, KBKDF, KRB5 KDF, PBKDF2, PKCS12 KDF, SCRYPT, SSH KDF, SSKDF, TLS1 PRF, X9.42 KDF and X9.63 KDF. * All of the low-level MD2, MD4, MD5, MDC2, RIPEMD160, SHA1, SHA224, SHA256, SHA384, SHA512 and Whirlpool digest functions have been deprecated. * All of the low-level AES, Blowfish, Camellia, CAST, DES, IDEA, RC2, RC4, RC5 and SEED cipher functions have been deprecated. * All of the low-level DH, DSA, ECDH, ECDSA and RSA public key functions have been deprecated. * SSL 3, TLS 1.0, TLS 1.1, and DTLS 1.0 only work at security level 0, except when RSA key exchange without SHA1 is used. * Added providers, a new pluggability concept that will replace the ENGINE API and ENGINE implementations. OpenSSL 1.1.1 ------------- ### Major changes between OpenSSL 1.1.1k and OpenSSL 1.1.1l [24 Aug 2021] * Fixed an SM2 Decryption Buffer Overflow ([CVE-2021-3711]) * Fixed various read buffer overruns processing ASN.1 strings ([CVE-2021-3712]) ### Major changes between OpenSSL 1.1.1j and OpenSSL 1.1.1k [25 Mar 2021] * Fixed a problem with verifying a certificate chain when using the X509_V_FLAG_X509_STRICT flag ([CVE-2021-3450]) * Fixed an issue where an OpenSSL TLS server may crash if sent a maliciously crafted renegotiation ClientHello message from a client ([CVE-2021-3449]) ### Major changes between OpenSSL 1.1.1i and OpenSSL 1.1.1j [16 Feb 2021] * Fixed a NULL pointer deref in the X509_issuer_and_serial_hash() function ([CVE-2021-23841]) * Fixed the RSA_padding_check_SSLv23() function and the RSA_SSLV23_PADDING padding mode to correctly check for rollback attacks * Fixed an overflow in the EVP_CipherUpdate, EVP_EncryptUpdate and EVP_DecryptUpdate functions ([CVE-2021-23840]) * Fixed SRP_Calc_client_key so that it runs in constant time ### Major changes between OpenSSL 1.1.1h and OpenSSL 1.1.1i [8 Dec 2020] * Fixed NULL pointer deref in GENERAL_NAME_cmp ([CVE-2020-1971]) ### Major changes between OpenSSL 1.1.1g and OpenSSL 1.1.1h [22 Sep 2020] * Disallow explicit curve parameters in verifications chains when X509_V_FLAG_X509_STRICT is used * Enable 'MinProtocol' and 'MaxProtocol' to configure both TLS and DTLS contexts * Oracle Developer Studio will start reporting deprecation warnings ### Major changes between OpenSSL 1.1.1f and OpenSSL 1.1.1g [21 Apr 2020] * Fixed segmentation fault in SSL_check_chain() ([CVE-2020-1967]) ### Major changes between OpenSSL 1.1.1e and OpenSSL 1.1.1f [31 Mar 2020] * Revert the unexpected EOF reporting via SSL_ERROR_SSL ### Major changes between OpenSSL 1.1.1d and OpenSSL 1.1.1e [17 Mar 2020] * Fixed an overflow bug in the x64_64 Montgomery squaring procedure used in exponentiation with 512-bit moduli ([CVE-2019-1551]) ### Major changes between OpenSSL 1.1.1c and OpenSSL 1.1.1d [10 Sep 2019] * Fixed a fork protection issue ([CVE-2019-1549]) * Fixed a padding oracle in PKCS7_dataDecode and CMS_decrypt_set1_pkey ([CVE-2019-1563]) * For built-in EC curves, ensure an EC_GROUP built from the curve name is used even when parsing explicit parameters * Compute ECC cofactors if not provided during EC_GROUP construction ([CVE-2019-1547]) * Early start up entropy quality from the DEVRANDOM seed source has been improved for older Linux systems * Correct the extended master secret constant on EBCDIC systems * Use Windows installation paths in the mingw builds ([CVE-2019-1552]) * Changed DH_check to accept parameters with order q and 2q subgroups * Significantly reduce secure memory usage by the randomness pools * Revert the DEVRANDOM_WAIT feature for Linux systems ### Major changes between OpenSSL 1.1.1b and OpenSSL 1.1.1c [28 May 2019] * Prevent over long nonces in ChaCha20-Poly1305 ([CVE-2019-1543]) ### Major changes between OpenSSL 1.1.1a and OpenSSL 1.1.1b [26 Feb 2019] * Change the info callback signals for the start and end of a post-handshake message exchange in TLSv1.3. * Fix a bug in DTLS over SCTP. This breaks interoperability with older versions of OpenSSL like OpenSSL 1.1.0 and OpenSSL 1.0.2. ### Major changes between OpenSSL 1.1.1 and OpenSSL 1.1.1a [20 Nov 2018] * Timing vulnerability in DSA signature generation ([CVE-2018-0734]) * Timing vulnerability in ECDSA signature generation ([CVE-2018-0735]) ### Major changes between OpenSSL 1.1.0i and OpenSSL 1.1.1 [11 Sep 2018] * Support for TLSv1.3 added. The TLSv1.3 implementation includes: * Fully compliant implementation of RFC8446 (TLSv1.3) on by default * Early data (0-RTT) * Post-handshake authentication and key update * Middlebox Compatibility Mode * TLSv1.3 PSKs * Support for all five RFC8446 ciphersuites * RSA-PSS signature algorithms (backported to TLSv1.2) * Configurable session ticket support * Stateless server support * Rewrite of the packet construction code for "safer" packet handling * Rewrite of the extension handling code For further important information, see the [TLS1.3 page]( https://wiki.openssl.org/index.php/TLS1.3) in the OpenSSL Wiki. * Complete rewrite of the OpenSSL random number generator to introduce the following capabilities * The default RAND method now utilizes an AES-CTR DRBG according to NIST standard SP 800-90Ar1. * Support for multiple DRBG instances with seed chaining. * There is a public and private DRBG instance. * The DRBG instances are fork-safe. * Keep all global DRBG instances on the secure heap if it is enabled. * The public and private DRBG instance are per thread for lock free operation * Support for various new cryptographic algorithms including: * SHA3 * SHA512/224 and SHA512/256 * EdDSA (both Ed25519 and Ed448) including X509 and TLS support * X448 (adding to the existing X25519 support in 1.1.0) * Multi-prime RSA * SM2 * SM3 * SM4 * SipHash * ARIA (including TLS support) * Significant Side-Channel attack security improvements * Add a new ClientHello callback to provide the ability to adjust the SSL object at an early stage. * Add 'Maximum Fragment Length' TLS extension negotiation and support * A new STORE module, which implements a uniform and URI based reader of stores that can contain keys, certificates, CRLs and numerous other objects. * Move the display of configuration data to configdata.pm. * Allow GNU style "make variables" to be used with Configure. * Claim the namespaces OSSL and OPENSSL, represented as symbol prefixes * Rewrite of devcrypto engine OpenSSL 1.1.0 ------------- ### Major changes between OpenSSL 1.1.0k and OpenSSL 1.1.0l [10 Sep 2019] * Fixed a padding oracle in PKCS7_dataDecode and CMS_decrypt_set1_pkey ([CVE-2019-1563]) * For built-in EC curves, ensure an EC_GROUP built from the curve name is used even when parsing explicit parameters * Compute ECC cofactors if not provided during EC_GROUP construction ([CVE-2019-1547]) * Use Windows installation paths in the mingw builds ([CVE-2019-1552]) ### Major changes between OpenSSL 1.1.0j and OpenSSL 1.1.0k [28 May 2019] * Prevent over long nonces in ChaCha20-Poly1305 ([CVE-2019-1543]) ### Major changes between OpenSSL 1.1.0i and OpenSSL 1.1.0j [20 Nov 2018] * Timing vulnerability in DSA signature generation ([CVE-2018-0734]) * Timing vulnerability in ECDSA signature generation ([CVE-2018-0735]) ### Major changes between OpenSSL 1.1.0h and OpenSSL 1.1.0i [14 Aug 2018] * Client DoS due to large DH parameter ([CVE-2018-0732]) * Cache timing vulnerability in RSA Key Generation ([CVE-2018-0737]) ### Major changes between OpenSSL 1.1.0g and OpenSSL 1.1.0h [27 Mar 2018] * Constructed ASN.1 types with a recursive definition could exceed the stack ([CVE-2018-0739]) * Incorrect CRYPTO_memcmp on HP-UX PA-RISC ([CVE-2018-0733]) * rsaz_1024_mul_avx2 overflow bug on x86_64 ([CVE-2017-3738]) ### Major changes between OpenSSL 1.1.0f and OpenSSL 1.1.0g [2 Nov 2017] * bn_sqrx8x_internal carry bug on x86_64 ([CVE-2017-3736]) * Malformed X.509 IPAddressFamily could cause OOB read ([CVE-2017-3735]) ### Major changes between OpenSSL 1.1.0e and OpenSSL 1.1.0f [25 May 2017] * config now recognises 64-bit mingw and chooses mingw64 instead of mingw ### Major changes between OpenSSL 1.1.0d and OpenSSL 1.1.0e [16 Feb 2017] * Encrypt-Then-Mac renegotiation crash ([CVE-2017-3733]) ### Major changes between OpenSSL 1.1.0c and OpenSSL 1.1.0d [26 Jan 2017] * Truncated packet could crash via OOB read ([CVE-2017-3731]) * Bad (EC)DHE parameters cause a client crash ([CVE-2017-3730]) * BN_mod_exp may produce incorrect results on x86_64 ([CVE-2017-3732]) ### Major changes between OpenSSL 1.1.0b and OpenSSL 1.1.0c [10 Nov 2016] * ChaCha20/Poly1305 heap-buffer-overflow ([CVE-2016-7054]) * CMS Null dereference ([CVE-2016-7053]) * Montgomery multiplication may produce incorrect results ([CVE-2016-7055]) ### Major changes between OpenSSL 1.1.0a and OpenSSL 1.1.0b [26 Sep 2016] * Fix Use After Free for large message sizes ([CVE-2016-6309]) ### Major changes between OpenSSL 1.1.0 and OpenSSL 1.1.0a [22 Sep 2016] * OCSP Status Request extension unbounded memory growth ([CVE-2016-6304]) * SSL_peek() hang on empty record ([CVE-2016-6305]) * Excessive allocation of memory in tls_get_message_header() ([CVE-2016-6307]) * Excessive allocation of memory in dtls1_preprocess_fragment() ([CVE-2016-6308]) ### Major changes between OpenSSL 1.0.2h and OpenSSL 1.1.0 [25 Aug 2016] * Copyright text was shrunk to a boilerplate that points to the license * "shared" builds are now the default when possible * Added support for "pipelining" * Added the AFALG engine * New threading API implemented * Support for ChaCha20 and Poly1305 added to libcrypto and libssl * Support for extended master secret * CCM ciphersuites * Reworked test suite, now based on perl, Test::Harness and Test::More * *Most* libcrypto and libssl public structures were made opaque, including: BIGNUM and associated types, EC_KEY and EC_KEY_METHOD, DH and DH_METHOD, DSA and DSA_METHOD, RSA and RSA_METHOD, BIO and BIO_METHOD, EVP_MD_CTX, EVP_MD, EVP_CIPHER_CTX, EVP_CIPHER, EVP_PKEY and associated types, HMAC_CTX, X509, X509_CRL, X509_OBJECT, X509_STORE_CTX, X509_STORE, X509_LOOKUP, X509_LOOKUP_METHOD * libssl internal structures made opaque * SSLv2 support removed * Kerberos ciphersuite support removed * RC4 removed from DEFAULT ciphersuites in libssl * 40 and 56 bit cipher support removed from libssl * All public header files moved to include/openssl, no more symlinking * SSL/TLS state machine, version negotiation and record layer rewritten * EC revision: now operations use new EC_KEY_METHOD. * Support for OCB mode added to libcrypto * Support for asynchronous crypto operations added to libcrypto and libssl * Deprecated interfaces can now be disabled at build time either relative to the latest release via the "no-deprecated" Configure argument, or via the "--api=1.1.0|1.0.0|0.9.8" option. * Application software can be compiled with -DOPENSSL_API_COMPAT=version to ensure that features deprecated in that version are not exposed. * Support for RFC6698/RFC7671 DANE TLSA peer authentication * Change of Configure to use --prefix as the main installation directory location rather than --openssldir. The latter becomes the directory for certs, private key and openssl.cnf exclusively. * Reworked BIO networking library, with full support for IPv6. * New "unified" build system * New security levels * Support for scrypt algorithm * Support for X25519 * Extended SSL_CONF support using configuration files * KDF algorithm support. Implement TLS PRF as a KDF. * Support for Certificate Transparency * HKDF support. OpenSSL 1.0.2 ------------- ### Major changes between OpenSSL 1.0.2s and OpenSSL 1.0.2t [10 Sep 2019] * Fixed a padding oracle in PKCS7_dataDecode and CMS_decrypt_set1_pkey ([CVE-2019-1563]) * For built-in EC curves, ensure an EC_GROUP built from the curve name is used even when parsing explicit parameters * Compute ECC cofactors if not provided during EC_GROUP construction ([CVE-2019-1547]) * Document issue with installation paths in diverse Windows builds ([CVE-2019-1552]) ### Major changes between OpenSSL 1.0.2r and OpenSSL 1.0.2s [28 May 2019] * None ### Major changes between OpenSSL 1.0.2q and OpenSSL 1.0.2r [26 Feb 2019] * 0-byte record padding oracle ([CVE-2019-1559]) ### Major changes between OpenSSL 1.0.2p and OpenSSL 1.0.2q [20 Nov 2018] * Microarchitecture timing vulnerability in ECC scalar multiplication ([CVE-2018-5407]) * Timing vulnerability in DSA signature generation ([CVE-2018-0734]) ### Major changes between OpenSSL 1.0.2o and OpenSSL 1.0.2p [14 Aug 2018] * Client DoS due to large DH parameter ([CVE-2018-0732]) * Cache timing vulnerability in RSA Key Generation ([CVE-2018-0737]) ### Major changes between OpenSSL 1.0.2n and OpenSSL 1.0.2o [27 Mar 2018] * Constructed ASN.1 types with a recursive definition could exceed the stack ([CVE-2018-0739]) ### Major changes between OpenSSL 1.0.2m and OpenSSL 1.0.2n [7 Dec 2017] * Read/write after SSL object in error state ([CVE-2017-3737]) * rsaz_1024_mul_avx2 overflow bug on x86_64 ([CVE-2017-3738]) ### Major changes between OpenSSL 1.0.2l and OpenSSL 1.0.2m [2 Nov 2017] * bn_sqrx8x_internal carry bug on x86_64 ([CVE-2017-3736]) * Malformed X.509 IPAddressFamily could cause OOB read ([CVE-2017-3735]) ### Major changes between OpenSSL 1.0.2k and OpenSSL 1.0.2l [25 May 2017] * config now recognises 64-bit mingw and chooses mingw64 instead of mingw ### Major changes between OpenSSL 1.0.2j and OpenSSL 1.0.2k [26 Jan 2017] * Truncated packet could crash via OOB read ([CVE-2017-3731]) * BN_mod_exp may produce incorrect results on x86_64 ([CVE-2017-3732]) * Montgomery multiplication may produce incorrect results ([CVE-2016-7055]) ### Major changes between OpenSSL 1.0.2i and OpenSSL 1.0.2j [26 Sep 2016] * Missing CRL sanity check ([CVE-2016-7052]) ### Major changes between OpenSSL 1.0.2h and OpenSSL 1.0.2i [22 Sep 2016] * OCSP Status Request extension unbounded memory growth ([CVE-2016-6304]) * SWEET32 Mitigation ([CVE-2016-2183]) * OOB write in MDC2_Update() ([CVE-2016-6303]) * Malformed SHA512 ticket DoS ([CVE-2016-6302]) * OOB write in BN_bn2dec() ([CVE-2016-2182]) * OOB read in TS_OBJ_print_bio() ([CVE-2016-2180]) * Pointer arithmetic undefined behaviour ([CVE-2016-2177]) * Constant time flag not preserved in DSA signing ([CVE-2016-2178]) * DTLS buffered message DoS ([CVE-2016-2179]) * DTLS replay protection DoS ([CVE-2016-2181]) * Certificate message OOB reads ([CVE-2016-6306]) ### Major changes between OpenSSL 1.0.2g and OpenSSL 1.0.2h [3 May 2016] * Prevent padding oracle in AES-NI CBC MAC check ([CVE-2016-2107]) * Fix EVP_EncodeUpdate overflow ([CVE-2016-2105]) * Fix EVP_EncryptUpdate overflow ([CVE-2016-2106]) * Prevent ASN.1 BIO excessive memory allocation ([CVE-2016-2109]) * EBCDIC overread ([CVE-2016-2176]) * Modify behavior of ALPN to invoke callback after SNI/servername callback, such that updates to the SSL_CTX affect ALPN. * Remove LOW from the DEFAULT cipher list. This removes singles DES from the default. * Only remove the SSLv2 methods with the no-ssl2-method option. ### Major changes between OpenSSL 1.0.2f and OpenSSL 1.0.2g [1 Mar 2016] * Disable weak ciphers in SSLv3 and up in default builds of OpenSSL. * Disable SSLv2 default build, default negotiation and weak ciphers ([CVE-2016-0800]) * Fix a double-free in DSA code ([CVE-2016-0705]) * Disable SRP fake user seed to address a server memory leak ([CVE-2016-0798]) * Fix BN_hex2bn/BN_dec2bn NULL pointer deref/heap corruption ([CVE-2016-0797]) * Fix memory issues in BIO_*printf functions ([CVE-2016-0799]) * Fix side channel attack on modular exponentiation ([CVE-2016-0702]) ### Major changes between OpenSSL 1.0.2e and OpenSSL 1.0.2f [28 Jan 2016] * DH small subgroups ([CVE-2016-0701]) * SSLv2 doesn't block disabled ciphers ([CVE-2015-3197]) ### Major changes between OpenSSL 1.0.2d and OpenSSL 1.0.2e [3 Dec 2015] * BN_mod_exp may produce incorrect results on x86_64 ([CVE-2015-3193]) * Certificate verify crash with missing PSS parameter ([CVE-2015-3194]) * X509_ATTRIBUTE memory leak ([CVE-2015-3195]) * Rewrite EVP_DecodeUpdate (base64 decoding) to fix several bugs * In DSA_generate_parameters_ex, if the provided seed is too short, return an error ### Major changes between OpenSSL 1.0.2c and OpenSSL 1.0.2d [9 Jul 2015] * Alternate chains certificate forgery ([CVE-2015-1793]) * Race condition handling PSK identify hint ([CVE-2015-3196]) ### Major changes between OpenSSL 1.0.2b and OpenSSL 1.0.2c [12 Jun 2015] * Fix HMAC ABI incompatibility ### Major changes between OpenSSL 1.0.2a and OpenSSL 1.0.2b [11 Jun 2015] * Malformed ECParameters causes infinite loop ([CVE-2015-1788]) * Exploitable out-of-bounds read in X509_cmp_time ([CVE-2015-1789]) * PKCS7 crash with missing EnvelopedContent ([CVE-2015-1790]) * CMS verify infinite loop with unknown hash function ([CVE-2015-1792]) * Race condition handling NewSessionTicket ([CVE-2015-1791]) ### Major changes between OpenSSL 1.0.2 and OpenSSL 1.0.2a [19 Mar 2015] * OpenSSL 1.0.2 ClientHello sigalgs DoS fix ([CVE-2015-0291]) * Multiblock corrupted pointer fix ([CVE-2015-0290]) * Segmentation fault in DTLSv1_listen fix ([CVE-2015-0207]) * Segmentation fault in ASN1_TYPE_cmp fix ([CVE-2015-0286]) * Segmentation fault for invalid PSS parameters fix ([CVE-2015-0208]) * ASN.1 structure reuse memory corruption fix ([CVE-2015-0287]) * PKCS7 NULL pointer dereferences fix ([CVE-2015-0289]) * DoS via reachable assert in SSLv2 servers fix ([CVE-2015-0293]) * Empty CKE with client auth and DHE fix ([CVE-2015-1787]) * Handshake with unseeded PRNG fix ([CVE-2015-0285]) * Use After Free following d2i_ECPrivatekey error fix ([CVE-2015-0209]) * X509_to_X509_REQ NULL pointer deref fix ([CVE-2015-0288]) * Removed the export ciphers from the DEFAULT ciphers ### Major changes between OpenSSL 1.0.1l and OpenSSL 1.0.2 [22 Jan 2015] * Suite B support for TLS 1.2 and DTLS 1.2 * Support for DTLS 1.2 * TLS automatic EC curve selection. * API to set TLS supported signature algorithms and curves * SSL_CONF configuration API. * TLS Brainpool support. * ALPN support. * CMS support for RSA-PSS, RSA-OAEP, ECDH and X9.42 DH. OpenSSL 1.0.1 ------------- ### Major changes between OpenSSL 1.0.1t and OpenSSL 1.0.1u [22 Sep 2016] * OCSP Status Request extension unbounded memory growth ([CVE-2016-6304]) * SWEET32 Mitigation ([CVE-2016-2183]) * OOB write in MDC2_Update() ([CVE-2016-6303]) * Malformed SHA512 ticket DoS ([CVE-2016-6302]) * OOB write in BN_bn2dec() ([CVE-2016-2182]) * OOB read in TS_OBJ_print_bio() ([CVE-2016-2180]) * Pointer arithmetic undefined behaviour ([CVE-2016-2177]) * Constant time flag not preserved in DSA signing ([CVE-2016-2178]) * DTLS buffered message DoS ([CVE-2016-2179]) * DTLS replay protection DoS ([CVE-2016-2181]) * Certificate message OOB reads ([CVE-2016-6306]) ### Major changes between OpenSSL 1.0.1s and OpenSSL 1.0.1t [3 May 2016] * Prevent padding oracle in AES-NI CBC MAC check ([CVE-2016-2107]) * Fix EVP_EncodeUpdate overflow ([CVE-2016-2105]) * Fix EVP_EncryptUpdate overflow ([CVE-2016-2106]) * Prevent ASN.1 BIO excessive memory allocation ([CVE-2016-2109]) * EBCDIC overread ([CVE-2016-2176]) * Modify behavior of ALPN to invoke callback after SNI/servername callback, such that updates to the SSL_CTX affect ALPN. * Remove LOW from the DEFAULT cipher list. This removes singles DES from the default. * Only remove the SSLv2 methods with the no-ssl2-method option. ### Major changes between OpenSSL 1.0.1r and OpenSSL 1.0.1s [1 Mar 2016] * Disable weak ciphers in SSLv3 and up in default builds of OpenSSL. * Disable SSLv2 default build, default negotiation and weak ciphers ([CVE-2016-0800]) * Fix a double-free in DSA code ([CVE-2016-0705]) * Disable SRP fake user seed to address a server memory leak ([CVE-2016-0798]) * Fix BN_hex2bn/BN_dec2bn NULL pointer deref/heap corruption ([CVE-2016-0797]) * Fix memory issues in BIO_*printf functions ([CVE-2016-0799]) * Fix side channel attack on modular exponentiation ([CVE-2016-0702]) ### Major changes between OpenSSL 1.0.1q and OpenSSL 1.0.1r [28 Jan 2016] * Protection for DH small subgroup attacks * SSLv2 doesn't block disabled ciphers ([CVE-2015-3197]) ### Major changes between OpenSSL 1.0.1p and OpenSSL 1.0.1q [3 Dec 2015] * Certificate verify crash with missing PSS parameter ([CVE-2015-3194]) * X509_ATTRIBUTE memory leak ([CVE-2015-3195]) * Rewrite EVP_DecodeUpdate (base64 decoding) to fix several bugs * In DSA_generate_parameters_ex, if the provided seed is too short, return an error ### Major changes between OpenSSL 1.0.1o and OpenSSL 1.0.1p [9 Jul 2015] * Alternate chains certificate forgery ([CVE-2015-1793]) * Race condition handling PSK identify hint ([CVE-2015-3196]) ### Major changes between OpenSSL 1.0.1n and OpenSSL 1.0.1o [12 Jun 2015] * Fix HMAC ABI incompatibility ### Major changes between OpenSSL 1.0.1m and OpenSSL 1.0.1n [11 Jun 2015] * Malformed ECParameters causes infinite loop ([CVE-2015-1788]) * Exploitable out-of-bounds read in X509_cmp_time ([CVE-2015-1789]) * PKCS7 crash with missing EnvelopedContent ([CVE-2015-1790]) * CMS verify infinite loop with unknown hash function ([CVE-2015-1792]) * Race condition handling NewSessionTicket ([CVE-2015-1791]) ### Major changes between OpenSSL 1.0.1l and OpenSSL 1.0.1m [19 Mar 2015] * Segmentation fault in ASN1_TYPE_cmp fix ([CVE-2015-0286]) * ASN.1 structure reuse memory corruption fix ([CVE-2015-0287]) * PKCS7 NULL pointer dereferences fix ([CVE-2015-0289]) * DoS via reachable assert in SSLv2 servers fix ([CVE-2015-0293]) * Use After Free following d2i_ECPrivatekey error fix ([CVE-2015-0209]) * X509_to_X509_REQ NULL pointer deref fix ([CVE-2015-0288]) * Removed the export ciphers from the DEFAULT ciphers ### Major changes between OpenSSL 1.0.1k and OpenSSL 1.0.1l [15 Jan 2015] * Build fixes for the Windows and OpenVMS platforms ### Major changes between OpenSSL 1.0.1j and OpenSSL 1.0.1k [8 Jan 2015] * Fix for [CVE-2014-3571] * Fix for [CVE-2015-0206] * Fix for [CVE-2014-3569] * Fix for [CVE-2014-3572] * Fix for [CVE-2015-0204] * Fix for [CVE-2015-0205] * Fix for [CVE-2014-8275] * Fix for [CVE-2014-3570] ### Major changes between OpenSSL 1.0.1i and OpenSSL 1.0.1j [15 Oct 2014] * Fix for [CVE-2014-3513] * Fix for [CVE-2014-3567] * Mitigation for [CVE-2014-3566] (SSL protocol vulnerability) * Fix for [CVE-2014-3568] ### Major changes between OpenSSL 1.0.1h and OpenSSL 1.0.1i [6 Aug 2014] * Fix for [CVE-2014-3512] * Fix for [CVE-2014-3511] * Fix for [CVE-2014-3510] * Fix for [CVE-2014-3507] * Fix for [CVE-2014-3506] * Fix for [CVE-2014-3505] * Fix for [CVE-2014-3509] * Fix for [CVE-2014-5139] * Fix for [CVE-2014-3508] ### Major changes between OpenSSL 1.0.1g and OpenSSL 1.0.1h [5 Jun 2014] * Fix for [CVE-2014-0224] * Fix for [CVE-2014-0221] * Fix for [CVE-2014-0198] * Fix for [CVE-2014-0195] * Fix for [CVE-2014-3470] * Fix for [CVE-2010-5298] ### Major changes between OpenSSL 1.0.1f and OpenSSL 1.0.1g [7 Apr 2014] * Fix for [CVE-2014-0160] * Add TLS padding extension workaround for broken servers. * Fix for [CVE-2014-0076] ### Major changes between OpenSSL 1.0.1e and OpenSSL 1.0.1f [6 Jan 2014] * Don't include gmt_unix_time in TLS server and client random values * Fix for TLS record tampering bug ([CVE-2013-4353]) * Fix for TLS version checking bug ([CVE-2013-6449]) * Fix for DTLS retransmission bug ([CVE-2013-6450]) ### Major changes between OpenSSL 1.0.1d and OpenSSL 1.0.1e [11 Feb 2013] * Corrected fix for ([CVE-2013-0169]) ### Major changes between OpenSSL 1.0.1c and OpenSSL 1.0.1d [4 Feb 2013] * Fix renegotiation in TLS 1.1, 1.2 by using the correct TLS version. * Include the fips configuration module. * Fix OCSP bad key DoS attack ([CVE-2013-0166]) * Fix for SSL/TLS/DTLS CBC plaintext recovery attack ([CVE-2013-0169]) * Fix for TLS AESNI record handling flaw ([CVE-2012-2686]) ### Major changes between OpenSSL 1.0.1b and OpenSSL 1.0.1c [10 May 2012] * Fix TLS/DTLS record length checking bug ([CVE-2012-2333]) * Don't attempt to use non-FIPS composite ciphers in FIPS mode. ### Major changes between OpenSSL 1.0.1a and OpenSSL 1.0.1b [26 Apr 2012] * Fix compilation error on non-x86 platforms. * Make FIPS capable OpenSSL ciphers work in non-FIPS mode. * Fix SSL_OP_NO_TLSv1_1 clash with SSL_OP_ALL in OpenSSL 1.0.0 ### Major changes between OpenSSL 1.0.1 and OpenSSL 1.0.1a [19 Apr 2012] * Fix for ASN1 overflow bug ([CVE-2012-2110]) * Workarounds for some servers that hang on long client hellos. * Fix SEGV in AES code. ### Major changes between OpenSSL 1.0.0h and OpenSSL 1.0.1 [14 Mar 2012] * TLS/DTLS heartbeat support. * SCTP support. * RFC 5705 TLS key material exporter. * RFC 5764 DTLS-SRTP negotiation. * Next Protocol Negotiation. * PSS signatures in certificates, requests and CRLs. * Support for password based recipient info for CMS. * Support TLS v1.2 and TLS v1.1. * Preliminary FIPS capability for unvalidated 2.0 FIPS module. * SRP support. OpenSSL 1.0.0 ------------- ### Major changes between OpenSSL 1.0.0s and OpenSSL 1.0.0t [3 Dec 2015] * X509_ATTRIBUTE memory leak (([CVE-2015-3195])) * Race condition handling PSK identify hint ([CVE-2015-3196]) ### Major changes between OpenSSL 1.0.0r and OpenSSL 1.0.0s [11 Jun 2015] * Malformed ECParameters causes infinite loop ([CVE-2015-1788]) * Exploitable out-of-bounds read in X509_cmp_time ([CVE-2015-1789]) * PKCS7 crash with missing EnvelopedContent ([CVE-2015-1790]) * CMS verify infinite loop with unknown hash function ([CVE-2015-1792]) * Race condition handling NewSessionTicket ([CVE-2015-1791]) ### Major changes between OpenSSL 1.0.0q and OpenSSL 1.0.0r [19 Mar 2015] * Segmentation fault in ASN1_TYPE_cmp fix ([CVE-2015-0286]) * ASN.1 structure reuse memory corruption fix ([CVE-2015-0287]) * PKCS7 NULL pointer dereferences fix ([CVE-2015-0289]) * DoS via reachable assert in SSLv2 servers fix ([CVE-2015-0293]) * Use After Free following d2i_ECPrivatekey error fix ([CVE-2015-0209]) * X509_to_X509_REQ NULL pointer deref fix ([CVE-2015-0288]) * Removed the export ciphers from the DEFAULT ciphers ### Major changes between OpenSSL 1.0.0p and OpenSSL 1.0.0q [15 Jan 2015] * Build fixes for the Windows and OpenVMS platforms ### Major changes between OpenSSL 1.0.0o and OpenSSL 1.0.0p [8 Jan 2015] * Fix for [CVE-2014-3571] * Fix for [CVE-2015-0206] * Fix for [CVE-2014-3569] * Fix for [CVE-2014-3572] * Fix for [CVE-2015-0204] * Fix for [CVE-2015-0205] * Fix for [CVE-2014-8275] * Fix for [CVE-2014-3570] ### Major changes between OpenSSL 1.0.0n and OpenSSL 1.0.0o [15 Oct 2014] * Fix for [CVE-2014-3513] * Fix for [CVE-2014-3567] * Mitigation for [CVE-2014-3566] (SSL protocol vulnerability) * Fix for [CVE-2014-3568] ### Major changes between OpenSSL 1.0.0m and OpenSSL 1.0.0n [6 Aug 2014] * Fix for [CVE-2014-3510] * Fix for [CVE-2014-3507] * Fix for [CVE-2014-3506] * Fix for [CVE-2014-3505] * Fix for [CVE-2014-3509] * Fix for [CVE-2014-3508] Known issues in OpenSSL 1.0.0m: * EAP-FAST and other applications using tls_session_secret_cb won't resume sessions. Fixed in 1.0.0n-dev * Compilation failure of s3_pkt.c on some platforms due to missing `` include. Fixed in 1.0.0n-dev ### Major changes between OpenSSL 1.0.0l and OpenSSL 1.0.0m [5 Jun 2014] * Fix for [CVE-2014-0224] * Fix for [CVE-2014-0221] * Fix for [CVE-2014-0198] * Fix for [CVE-2014-0195] * Fix for [CVE-2014-3470] * Fix for [CVE-2014-0076] * Fix for [CVE-2010-5298] ### Major changes between OpenSSL 1.0.0k and OpenSSL 1.0.0l [6 Jan 2014] * Fix for DTLS retransmission bug ([CVE-2013-6450]) ### Major changes between OpenSSL 1.0.0j and OpenSSL 1.0.0k [5 Feb 2013] * Fix for SSL/TLS/DTLS CBC plaintext recovery attack ([CVE-2013-0169]) * Fix OCSP bad key DoS attack ([CVE-2013-0166]) ### Major changes between OpenSSL 1.0.0i and OpenSSL 1.0.0j [10 May 2012] * Fix DTLS record length checking bug ([CVE-2012-2333]) ### Major changes between OpenSSL 1.0.0h and OpenSSL 1.0.0i [19 Apr 2012] * Fix for ASN1 overflow bug ([CVE-2012-2110]) ### Major changes between OpenSSL 1.0.0g and OpenSSL 1.0.0h [12 Mar 2012] * Fix for CMS/PKCS#7 MMA ([CVE-2012-0884]) * Corrected fix for ([CVE-2011-4619]) * Various DTLS fixes. ### Major changes between OpenSSL 1.0.0f and OpenSSL 1.0.0g [18 Jan 2012] * Fix for DTLS DoS issue ([CVE-2012-0050]) ### Major changes between OpenSSL 1.0.0e and OpenSSL 1.0.0f [4 Jan 2012] * Fix for DTLS plaintext recovery attack ([CVE-2011-4108]) * Clear block padding bytes of SSL 3.0 records ([CVE-2011-4576]) * Only allow one SGC handshake restart for SSL/TLS ([CVE-2011-4619]) * Check parameters are not NULL in GOST ENGINE ([CVE-2012-0027]) * Check for malformed RFC3779 data ([CVE-2011-4577]) ### Major changes between OpenSSL 1.0.0d and OpenSSL 1.0.0e [6 Sep 2011] * Fix for CRL vulnerability issue ([CVE-2011-3207]) * Fix for ECDH crashes ([CVE-2011-3210]) * Protection against EC timing attacks. * Support ECDH ciphersuites for certificates using SHA2 algorithms. * Various DTLS fixes. ### Major changes between OpenSSL 1.0.0c and OpenSSL 1.0.0d [8 Feb 2011] * Fix for security issue ([CVE-2011-0014]) ### Major changes between OpenSSL 1.0.0b and OpenSSL 1.0.0c [2 Dec 2010] * Fix for security issue ([CVE-2010-4180]) * Fix for ([CVE-2010-4252]) * Fix mishandling of absent EC point format extension. * Fix various platform compilation issues. * Corrected fix for security issue ([CVE-2010-3864]). ### Major changes between OpenSSL 1.0.0a and OpenSSL 1.0.0b [16 Nov 2010] * Fix for security issue ([CVE-2010-3864]). * Fix for ([CVE-2010-2939]) * Fix WIN32 build system for GOST ENGINE. ### Major changes between OpenSSL 1.0.0 and OpenSSL 1.0.0a [1 Jun 2010] * Fix for security issue ([CVE-2010-1633]). * GOST MAC and CFB fixes. ### Major changes between OpenSSL 0.9.8n and OpenSSL 1.0.0 [29 Mar 2010] * RFC3280 path validation: sufficient to process PKITS tests. * Integrated support for PVK files and keyblobs. * Change default private key format to PKCS#8. * CMS support: able to process all examples in RFC4134 * Streaming ASN1 encode support for PKCS#7 and CMS. * Multiple signer and signer add support for PKCS#7 and CMS. * ASN1 printing support. * Whirlpool hash algorithm added. * RFC3161 time stamp support. * New generalised public key API supporting ENGINE based algorithms. * New generalised public key API utilities. * New ENGINE supporting GOST algorithms. * SSL/TLS GOST ciphersuite support. * PKCS#7 and CMS GOST support. * RFC4279 PSK ciphersuite support. * Supported points format extension for ECC ciphersuites. * ecdsa-with-SHA224/256/384/512 signature types. * dsa-with-SHA224 and dsa-with-SHA256 signature types. * Opaque PRF Input TLS extension support. * Updated time routines to avoid OS limitations. OpenSSL 0.9.x ------------- ### Major changes between OpenSSL 0.9.8m and OpenSSL 0.9.8n [24 Mar 2010] * CFB cipher definition fixes. * Fix security issues [CVE-2010-0740] and [CVE-2010-0433]. ### Major changes between OpenSSL 0.9.8l and OpenSSL 0.9.8m [25 Feb 2010] * Cipher definition fixes. * Workaround for slow RAND_poll() on some WIN32 versions. * Remove MD2 from algorithm tables. * SPKAC handling fixes. * Support for RFC5746 TLS renegotiation extension. * Compression memory leak fixed. * Compression session resumption fixed. * Ticket and SNI coexistence fixes. * Many fixes to DTLS handling. ### Major changes between OpenSSL 0.9.8k and OpenSSL 0.9.8l [5 Nov 2009] * Temporary work around for [CVE-2009-3555]: disable renegotiation. ### Major changes between OpenSSL 0.9.8j and OpenSSL 0.9.8k [25 Mar 2009] * Fix various build issues. * Fix security issues [CVE-2009-0590], [CVE-2009-0591], [CVE-2009-0789] ### Major changes between OpenSSL 0.9.8i and OpenSSL 0.9.8j [7 Jan 2009] * Fix security issue ([CVE-2008-5077]) * Merge FIPS 140-2 branch code. ### Major changes between OpenSSL 0.9.8g and OpenSSL 0.9.8h [28 May 2008] * CryptoAPI ENGINE support. * Various precautionary measures. * Fix for bugs affecting certificate request creation. * Support for local machine keyset attribute in PKCS#12 files. ### Major changes between OpenSSL 0.9.8f and OpenSSL 0.9.8g [19 Oct 2007] * Backport of CMS functionality to 0.9.8. * Fixes for bugs introduced with 0.9.8f. ### Major changes between OpenSSL 0.9.8e and OpenSSL 0.9.8f [11 Oct 2007] * Add gcc 4.2 support. * Add support for AES and SSE2 assembly language optimization for VC++ build. * Support for RFC4507bis and server name extensions if explicitly selected at compile time. * DTLS improvements. * RFC4507bis support. * TLS Extensions support. ### Major changes between OpenSSL 0.9.8d and OpenSSL 0.9.8e [23 Feb 2007] * Various ciphersuite selection fixes. * RFC3779 support. ### Major changes between OpenSSL 0.9.8c and OpenSSL 0.9.8d [28 Sep 2006] * Introduce limits to prevent malicious key DoS ([CVE-2006-2940]) * Fix security issues [CVE-2006-2937], [CVE-2006-3737], [CVE-2006-4343] * Changes to ciphersuite selection algorithm ### Major changes between OpenSSL 0.9.8b and OpenSSL 0.9.8c [5 Sep 2006] * Fix Daniel Bleichenbacher forged signature attack, [CVE-2006-4339] * New cipher Camellia ### Major changes between OpenSSL 0.9.8a and OpenSSL 0.9.8b [4 May 2006] * Cipher string fixes. * Fixes for VC++ 2005. * Updated ECC cipher suite support. * New functions EVP_CIPHER_CTX_new() and EVP_CIPHER_CTX_free(). * Zlib compression usage fixes. * Built in dynamic engine compilation support on Win32. * Fixes auto dynamic engine loading in Win32. ### Major changes between OpenSSL 0.9.8 and OpenSSL 0.9.8a [11 Oct 2005] * Fix potential SSL 2.0 rollback ([CVE-2005-2969]) * Extended Windows CE support ### Major changes between OpenSSL 0.9.7g and OpenSSL 0.9.8 [5 Jul 2005] * Major work on the BIGNUM library for higher efficiency and to make operations more streamlined and less contradictory. This is the result of a major audit of the BIGNUM library. * Addition of BIGNUM functions for fields GF(2^m) and NIST curves, to support the Elliptic Crypto functions. * Major work on Elliptic Crypto; ECDH and ECDSA added, including the use through EVP, X509 and ENGINE. * New ASN.1 mini-compiler that's usable through the OpenSSL configuration file. * Added support for ASN.1 indefinite length constructed encoding. * New PKCS#12 'medium level' API to manipulate PKCS#12 files. * Complete rework of shared library construction and linking programs with shared or static libraries, through a separate Makefile.shared. * Rework of the passing of parameters from one Makefile to another. * Changed ENGINE framework to load dynamic engine modules automatically from specifically given directories. * New structure and ASN.1 functions for CertificatePair. * Changed the ZLIB compression method to be stateful. * Changed the key-generation and primality testing "progress" mechanism to take a structure that contains the ticker function and an argument. * New engine module: GMP (performs private key exponentiation). * New engine module: VIA PadLOck ACE extension in VIA C3 Nehemiah processors. * Added support for IPv6 addresses in certificate extensions. See RFC 1884, section 2.2. * Added support for certificate policy mappings, policy constraints and name constraints. * Added support for multi-valued AVAs in the OpenSSL configuration file. * Added support for multiple certificates with the same subject in the 'openssl ca' index file. * Make it possible to create self-signed certificates using 'openssl ca -selfsign'. * Make it possible to generate a serial number file with 'openssl ca -create_serial'. * New binary search functions with extended functionality. * New BUF functions. * New STORE structure and library to provide an interface to all sorts of data repositories. Supports storage of public and private keys, certificates, CRLs, numbers and arbitrary blobs. This library is unfortunately unfinished and unused within OpenSSL. * New control functions for the error stack. * Changed the PKCS#7 library to support one-pass S/MIME processing. * Added the possibility to compile without old deprecated functionality with the OPENSSL_NO_DEPRECATED macro or the 'no-deprecated' argument to the config and Configure scripts. * Constification of all ASN.1 conversion functions, and other affected functions. * Improved platform support for PowerPC. * New FIPS 180-2 algorithms (SHA-224, -256, -384 and -512). * New X509_VERIFY_PARAM structure to support parameterisation of X.509 path validation. * Major overhaul of RC4 performance on Intel P4, IA-64 and AMD64. * Changed the Configure script to have some algorithms disabled by default. Those can be explicitly enabled with the new argument form 'enable-xxx'. * Change the default digest in 'openssl' commands from MD5 to SHA-1. * Added support for DTLS. * New BIGNUM blinding. * Added support for the RSA-PSS encryption scheme * Added support for the RSA X.931 padding. * Added support for BSD sockets on NetWare. * Added support for files larger than 2GB. * Added initial support for Win64. * Added alternate pkg-config files. ### Major changes between OpenSSL 0.9.7l and OpenSSL 0.9.7m [23 Feb 2007] * FIPS 1.1.1 module linking. * Various ciphersuite selection fixes. ### Major changes between OpenSSL 0.9.7k and OpenSSL 0.9.7l [28 Sep 2006] * Introduce limits to prevent malicious key DoS ([CVE-2006-2940]) * Fix security issues [CVE-2006-2937], [CVE-2006-3737], [CVE-2006-4343] ### Major changes between OpenSSL 0.9.7j and OpenSSL 0.9.7k [5 Sep 2006] * Fix Daniel Bleichenbacher forged signature attack, [CVE-2006-4339] ### Major changes between OpenSSL 0.9.7i and OpenSSL 0.9.7j [4 May 2006] * Visual C++ 2005 fixes. * Update Windows build system for FIPS. ### Major changes between OpenSSL 0.9.7h and OpenSSL 0.9.7i [14 Oct 2005] * Give EVP_MAX_MD_SIZE its old value, except for a FIPS build. ### Major changes between OpenSSL 0.9.7g and OpenSSL 0.9.7h [11 Oct 2005] * Fix SSL 2.0 Rollback ([CVE-2005-2969]) * Allow use of fixed-length exponent on DSA signing * Default fixed-window RSA, DSA, DH private-key operations ### Major changes between OpenSSL 0.9.7f and OpenSSL 0.9.7g [11 Apr 2005] * More compilation issues fixed. * Adaptation to more modern Kerberos API. * Enhanced or corrected configuration for Solaris64, Mingw and Cygwin. * Enhanced x86_64 assembler BIGNUM module. * More constification. * Added processing of proxy certificates (RFC 3820). ### Major changes between OpenSSL 0.9.7e and OpenSSL 0.9.7f [22 Mar 2005] * Several compilation issues fixed. * Many memory allocation failure checks added. * Improved comparison of X509 Name type. * Mandatory basic checks on certificates. * Performance improvements. ### Major changes between OpenSSL 0.9.7d and OpenSSL 0.9.7e [25 Oct 2004] * Fix race condition in CRL checking code. * Fixes to PKCS#7 (S/MIME) code. ### Major changes between OpenSSL 0.9.7c and OpenSSL 0.9.7d [17 Mar 2004] * Security: Fix Kerberos ciphersuite SSL/TLS handshaking bug * Security: Fix null-pointer assignment in do_change_cipher_spec() * Allow multiple active certificates with same subject in CA index * Multiple X509 verification fixes * Speed up HMAC and other operations ### Major changes between OpenSSL 0.9.7b and OpenSSL 0.9.7c [30 Sep 2003] * Security: fix various ASN1 parsing bugs. * New -ignore_err option to OCSP utility. * Various interop and bug fixes in S/MIME code. * SSL/TLS protocol fix for unrequested client certificates. ### Major changes between OpenSSL 0.9.7a and OpenSSL 0.9.7b [10 Apr 2003] * Security: counter the Klima-Pokorny-Rosa extension of Bleichbacher's attack * Security: make RSA blinding default. * Configuration: Irix fixes, AIX fixes, better mingw support. * Support for new platforms: linux-ia64-ecc. * Build: shared library support fixes. * ASN.1: treat domainComponent correctly. * Documentation: fixes and additions. ### Major changes between OpenSSL 0.9.7 and OpenSSL 0.9.7a [19 Feb 2003] * Security: Important security related bugfixes. * Enhanced compatibility with MIT Kerberos. * Can be built without the ENGINE framework. * IA32 assembler enhancements. * Support for new platforms: FreeBSD/IA64 and FreeBSD/Sparc64. * Configuration: the no-err option now works properly. * SSL/TLS: now handles manual certificate chain building. * SSL/TLS: certain session ID malfunctions corrected. ### Major changes between OpenSSL 0.9.6 and OpenSSL 0.9.7 [30 Dec 2002] * New library section OCSP. * Complete rewrite of ASN1 code. * CRL checking in verify code and openssl utility. * Extension copying in 'ca' utility. * Flexible display options in 'ca' utility. * Provisional support for international characters with UTF8. * Support for external crypto devices ('engine') is no longer a separate distribution. * New elliptic curve library section. * New AES (Rijndael) library section. * Support for new platforms: Windows CE, Tandem OSS, A/UX, AIX 64-bit, Linux x86_64, Linux 64-bit on Sparc v9 * Extended support for some platforms: VxWorks * Enhanced support for shared libraries. * Now only builds PIC code when shared library support is requested. * Support for pkg-config. * Lots of new manuals. * Makes symbolic links to or copies of manuals to cover all described functions. * Change DES API to clean up the namespace (some applications link also against libdes providing similar functions having the same name). Provide macros for backward compatibility (will be removed in the future). * Unify handling of cryptographic algorithms (software and engine) to be available via EVP routines for asymmetric and symmetric ciphers. * NCONF: new configuration handling routines. * Change API to use more 'const' modifiers to improve error checking and help optimizers. * Finally remove references to RSAref. * Reworked parts of the BIGNUM code. * Support for new engines: Broadcom ubsec, Accelerated Encryption Processing, IBM 4758. * A few new engines added in the demos area. * Extended and corrected OID (object identifier) table. * PRNG: query at more locations for a random device, automatic query for EGD style random sources at several locations. * SSL/TLS: allow optional cipher choice according to server's preference. * SSL/TLS: allow server to explicitly set new session ids. * SSL/TLS: support Kerberos cipher suites (RFC2712). Only supports MIT Kerberos for now. * SSL/TLS: allow more precise control of renegotiations and sessions. * SSL/TLS: add callback to retrieve SSL/TLS messages. * SSL/TLS: support AES cipher suites (RFC3268). ### Major changes between OpenSSL 0.9.6j and OpenSSL 0.9.6k [30 Sep 2003] * Security: fix various ASN1 parsing bugs. * SSL/TLS protocol fix for unrequested client certificates. ### Major changes between OpenSSL 0.9.6i and OpenSSL 0.9.6j [10 Apr 2003] * Security: counter the Klima-Pokorny-Rosa extension of Bleichbacher's attack * Security: make RSA blinding default. * Build: shared library support fixes. ### Major changes between OpenSSL 0.9.6h and OpenSSL 0.9.6i [19 Feb 2003] * Important security related bugfixes. ### Major changes between OpenSSL 0.9.6g and OpenSSL 0.9.6h [5 Dec 2002] * New configuration targets for Tandem OSS and A/UX. * New OIDs for Microsoft attributes. * Better handling of SSL session caching. * Better comparison of distinguished names. * Better handling of shared libraries in a mixed GNU/non-GNU environment. * Support assembler code with Borland C. * Fixes for length problems. * Fixes for uninitialised variables. * Fixes for memory leaks, some unusual crashes and some race conditions. * Fixes for smaller building problems. * Updates of manuals, FAQ and other instructive documents. ### Major changes between OpenSSL 0.9.6f and OpenSSL 0.9.6g [9 Aug 2002] * Important building fixes on Unix. ### Major changes between OpenSSL 0.9.6e and OpenSSL 0.9.6f [8 Aug 2002] * Various important bugfixes. ### Major changes between OpenSSL 0.9.6d and OpenSSL 0.9.6e [30 Jul 2002] * Important security related bugfixes. * Various SSL/TLS library bugfixes. ### Major changes between OpenSSL 0.9.6c and OpenSSL 0.9.6d [9 May 2002] * Various SSL/TLS library bugfixes. * Fix DH parameter generation for 'non-standard' generators. ### Major changes between OpenSSL 0.9.6b and OpenSSL 0.9.6c [21 Dec 2001] * Various SSL/TLS library bugfixes. * BIGNUM library fixes. * RSA OAEP and random number generation fixes. * Object identifiers corrected and added. * Add assembler BN routines for IA64. * Add support for OS/390 Unix, UnixWare with gcc, OpenUNIX 8, MIPS Linux; shared library support for Irix, HP-UX. * Add crypto accelerator support for AEP, Baltimore SureWare, Broadcom and Cryptographic Appliance's keyserver [in 0.9.6c-engine release]. ### Major changes between OpenSSL 0.9.6a and OpenSSL 0.9.6b [9 Jul 2001] * Security fix: PRNG improvements. * Security fix: RSA OAEP check. * Security fix: Reinsert and fix countermeasure to Bleichbacher's attack. * MIPS bug fix in BIGNUM. * Bug fix in "openssl enc". * Bug fix in X.509 printing routine. * Bug fix in DSA verification routine and DSA S/MIME verification. * Bug fix to make PRNG thread-safe. * Bug fix in RAND_file_name(). * Bug fix in compatibility mode trust settings. * Bug fix in blowfish EVP. * Increase default size for BIO buffering filter. * Compatibility fixes in some scripts. ### Major changes between OpenSSL 0.9.6 and OpenSSL 0.9.6a [5 Apr 2001] * Security fix: change behavior of OpenSSL to avoid using environment variables when running as root. * Security fix: check the result of RSA-CRT to reduce the possibility of deducing the private key from an incorrectly calculated signature. * Security fix: prevent Bleichenbacher's DSA attack. * Security fix: Zero the premaster secret after deriving the master secret in DH ciphersuites. * Reimplement SSL_peek(), which had various problems. * Compatibility fix: the function des_encrypt() renamed to des_encrypt1() to avoid clashes with some Unixen libc. * Bug fixes for Win32, HP/UX and Irix. * Bug fixes in BIGNUM, SSL, PKCS#7, PKCS#12, X.509, CONF and memory checking routines. * Bug fixes for RSA operations in threaded environments. * Bug fixes in misc. openssl applications. * Remove a few potential memory leaks. * Add tighter checks of BIGNUM routines. * Shared library support has been reworked for generality. * More documentation. * New function BN_rand_range(). * Add "-rand" option to openssl s_client and s_server. ### Major changes between OpenSSL 0.9.5a and OpenSSL 0.9.6 [10 Oct 2000] * Some documentation for BIO and SSL libraries. * Enhanced chain verification using key identifiers. * New sign and verify options to 'dgst' application. * Support for DER and PEM encoded messages in 'smime' application. * New 'rsautl' application, low-level RSA utility. * MD4 now included. * Bugfix for SSL rollback padding check. * Support for external crypto devices [1]. * Enhanced EVP interface. [1] The support for external crypto devices is currently a separate distribution. See the file README-Engine.md. ### Major changes between OpenSSL 0.9.5 and OpenSSL 0.9.5a [1 Apr 2000] * Bug fixes for Win32, SuSE Linux, NeXTSTEP and FreeBSD 2.2.8 * Shared library support for HPUX and Solaris-gcc * Support of Linux/IA64 * Assembler support for Mingw32 * New 'rand' application * New way to check for existence of algorithms from scripts ### Major changes between OpenSSL 0.9.4 and OpenSSL 0.9.5 [25 May 2000] * S/MIME support in new 'smime' command * Documentation for the OpenSSL command line application * Automation of 'req' application * Fixes to make s_client, s_server work under Windows * Support for multiple fieldnames in SPKACs * New SPKAC command line utility and associated library functions * Options to allow passwords to be obtained from various sources * New public key PEM format and options to handle it * Many other fixes and enhancements to command line utilities * Usable certificate chain verification * Certificate purpose checking * Certificate trust settings * Support of authority information access extension * Extensions in certificate requests * Simplified X509 name and attribute routines * Initial (incomplete) support for international character sets * New DH_METHOD, DSA_METHOD and enhanced RSA_METHOD * Read only memory BIOs and simplified creation function * TLS/SSL protocol bugfixes: Accept TLS 'client hello' in SSL 3.0 record; allow fragmentation and interleaving of handshake and other data * TLS/SSL code now "tolerates" MS SGC * Work around for Netscape client certificate hang bug * RSA_NULL option that removes RSA patent code but keeps other RSA functionality * Memory leak detection now allows applications to add extra information via a per-thread stack * PRNG robustness improved * EGD support * BIGNUM library bug fixes * Faster DSA parameter generation * Enhanced support for Alpha Linux * Experimental macOS support ### Major changes between OpenSSL 0.9.3 and OpenSSL 0.9.4 [9 Aug 1999] * Transparent support for PKCS#8 format private keys: these are used by several software packages and are more secure than the standard form * PKCS#5 v2.0 implementation * Password callbacks have a new void * argument for application data * Avoid various memory leaks * New pipe-like BIO that allows using the SSL library when actual I/O must be handled by the application (BIO pair) ### Major changes between OpenSSL 0.9.2b and OpenSSL 0.9.3 [24 May 1999] * Lots of enhancements and cleanups to the Configuration mechanism * RSA OEAP related fixes * Added "openssl ca -revoke" option for revoking a certificate * Source cleanups: const correctness, type-safe stacks and ASN.1 SETs * Source tree cleanups: removed lots of obsolete files * Thawte SXNet, certificate policies and CRL distribution points extension support * Preliminary (experimental) S/MIME support * Support for ASN.1 UTF8String and VisibleString * Full integration of PKCS#12 code * Sparc assembler bignum implementation, optimized hash functions * Option to disable selected ciphers ### Major changes between OpenSSL 0.9.1c and OpenSSL 0.9.2b [22 Mar 1999] * Fixed a security hole related to session resumption * Fixed RSA encryption routines for the p < q case * "ALL" in cipher lists now means "everything except NULL ciphers" * Support for Triple-DES CBCM cipher * Support of Optimal Asymmetric Encryption Padding (OAEP) for RSA * First support for new TLSv1 ciphers * Added a few new BIOs (syslog BIO, reliable BIO) * Extended support for DSA certificate/keys. * Extended support for Certificate Signing Requests (CSR) * Initial support for X.509v3 extensions * Extended support for compression inside the SSL record layer * Overhauled Win32 builds * Cleanups and fixes to the Big Number (BN) library * Support for ASN.1 GeneralizedTime * Splitted ASN.1 SETs from SEQUENCEs * ASN1 and PEM support for Netscape Certificate Sequences * Overhauled Perl interface * Lots of source tree cleanups. * Lots of memory leak fixes. * Lots of bug fixes. ### Major changes between SSLeay 0.9.0b and OpenSSL 0.9.1c [23 Dec 1998] * Integration of the popular NO_RSA/NO_DSA patches * Initial support for compression inside the SSL record layer * Added BIO proxy and filtering functionality * Extended Big Number (BN) library * Added RIPE MD160 message digest * Added support for RC2/64bit cipher * Extended ASN.1 parser routines * Adjustments of the source tree for CVS * Support for various new platforms +[CVE-2023-5363]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-5363 [CVE-2023-4807]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-4807 [CVE-2023-3817]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-3817 [CVE-2023-3446]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-3446 [CVE-2023-2975]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-2975 [CVE-2023-2650]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-2650 [CVE-2023-1255]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-1255 [CVE-2023-0466]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-0466 [CVE-2023-0465]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-0465 [CVE-2023-0464]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-0464 [CVE-2023-0401]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-0401 [CVE-2023-0286]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-0286 [CVE-2023-0217]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-0217 [CVE-2023-0216]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-0216 [CVE-2023-0215]: https://www.openssl.org/news/vulnerabilities.html#CVE-2023-0215 [CVE-2022-4450]: https://www.openssl.org/news/vulnerabilities.html#CVE-2022-4450 [CVE-2022-4304]: https://www.openssl.org/news/vulnerabilities.html#CVE-2022-4304 [CVE-2022-4203]: https://www.openssl.org/news/vulnerabilities.html#CVE-2022-4203 [CVE-2022-3996]: https://www.openssl.org/news/vulnerabilities.html#CVE-2022-3996 [CVE-2022-2274]: https://www.openssl.org/news/vulnerabilities.html#CVE-2022-2274 [CVE-2022-2097]: https://www.openssl.org/news/vulnerabilities.html#CVE-2022-2097 [CVE-2020-1971]: https://www.openssl.org/news/vulnerabilities.html#CVE-2020-1971 [CVE-2020-1967]: https://www.openssl.org/news/vulnerabilities.html#CVE-2020-1967 [CVE-2019-1563]: https://www.openssl.org/news/vulnerabilities.html#CVE-2019-1563 [CVE-2019-1559]: https://www.openssl.org/news/vulnerabilities.html#CVE-2019-1559 [CVE-2019-1552]: https://www.openssl.org/news/vulnerabilities.html#CVE-2019-1552 [CVE-2019-1551]: https://www.openssl.org/news/vulnerabilities.html#CVE-2019-1551 [CVE-2019-1549]: https://www.openssl.org/news/vulnerabilities.html#CVE-2019-1549 [CVE-2019-1547]: https://www.openssl.org/news/vulnerabilities.html#CVE-2019-1547 [CVE-2019-1543]: https://www.openssl.org/news/vulnerabilities.html#CVE-2019-1543 [CVE-2018-5407]: https://www.openssl.org/news/vulnerabilities.html#CVE-2018-5407 [CVE-2018-0739]: https://www.openssl.org/news/vulnerabilities.html#CVE-2018-0739 [CVE-2018-0737]: https://www.openssl.org/news/vulnerabilities.html#CVE-2018-0737 [CVE-2018-0735]: https://www.openssl.org/news/vulnerabilities.html#CVE-2018-0735 [CVE-2018-0734]: https://www.openssl.org/news/vulnerabilities.html#CVE-2018-0734 [CVE-2018-0733]: https://www.openssl.org/news/vulnerabilities.html#CVE-2018-0733 [CVE-2018-0732]: https://www.openssl.org/news/vulnerabilities.html#CVE-2018-0732 [CVE-2017-3738]: https://www.openssl.org/news/vulnerabilities.html#CVE-2017-3738 [CVE-2017-3737]: https://www.openssl.org/news/vulnerabilities.html#CVE-2017-3737 [CVE-2017-3736]: https://www.openssl.org/news/vulnerabilities.html#CVE-2017-3736 [CVE-2017-3735]: https://www.openssl.org/news/vulnerabilities.html#CVE-2017-3735 [CVE-2017-3733]: https://www.openssl.org/news/vulnerabilities.html#CVE-2017-3733 [CVE-2017-3732]: https://www.openssl.org/news/vulnerabilities.html#CVE-2017-3732 [CVE-2017-3731]: https://www.openssl.org/news/vulnerabilities.html#CVE-2017-3731 [CVE-2017-3730]: https://www.openssl.org/news/vulnerabilities.html#CVE-2017-3730 [CVE-2016-7055]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-7055 [CVE-2016-7054]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-7054 [CVE-2016-7053]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-7053 [CVE-2016-7052]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-7052 [CVE-2016-6309]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-6309 [CVE-2016-6308]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-6308 [CVE-2016-6307]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-6307 [CVE-2016-6306]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-6306 [CVE-2016-6305]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-6305 [CVE-2016-6304]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-6304 [CVE-2016-6303]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-6303 [CVE-2016-6302]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-6302 [CVE-2016-2183]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-2183 [CVE-2016-2182]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-2182 [CVE-2016-2181]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-2181 [CVE-2016-2180]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-2180 [CVE-2016-2179]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-2179 [CVE-2016-2178]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-2178 [CVE-2016-2177]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-2177 [CVE-2016-2176]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-2176 [CVE-2016-2109]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-2109 [CVE-2016-2107]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-2107 [CVE-2016-2106]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-2106 [CVE-2016-2105]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-2105 [CVE-2016-0800]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-0800 [CVE-2016-0799]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-0799 [CVE-2016-0798]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-0798 [CVE-2016-0797]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-0797 [CVE-2016-0705]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-0705 [CVE-2016-0702]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-0702 [CVE-2016-0701]: https://www.openssl.org/news/vulnerabilities.html#CVE-2016-0701 [CVE-2015-3197]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-3197 [CVE-2015-3196]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-3196 [CVE-2015-3195]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-3195 [CVE-2015-3194]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-3194 [CVE-2015-3193]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-3193 [CVE-2015-1793]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-1793 [CVE-2015-1792]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-1792 [CVE-2015-1791]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-1791 [CVE-2015-1790]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-1790 [CVE-2015-1789]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-1789 [CVE-2015-1788]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-1788 [CVE-2015-1787]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-1787 [CVE-2015-0293]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-0293 [CVE-2015-0291]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-0291 [CVE-2015-0290]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-0290 [CVE-2015-0289]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-0289 [CVE-2015-0288]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-0288 [CVE-2015-0287]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-0287 [CVE-2015-0286]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-0286 [CVE-2015-0285]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-0285 [CVE-2015-0209]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-0209 [CVE-2015-0208]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-0208 [CVE-2015-0207]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-0207 [CVE-2015-0206]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-0206 [CVE-2015-0205]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-0205 [CVE-2015-0204]: https://www.openssl.org/news/vulnerabilities.html#CVE-2015-0204 [CVE-2014-8275]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-8275 [CVE-2014-5139]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-5139 [CVE-2014-3572]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3572 [CVE-2014-3571]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3571 [CVE-2014-3570]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3570 [CVE-2014-3569]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3569 [CVE-2014-3568]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3568 [CVE-2014-3567]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3567 [CVE-2014-3566]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3566 [CVE-2014-3513]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3513 [CVE-2014-3512]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3512 [CVE-2014-3511]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3511 [CVE-2014-3510]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3510 [CVE-2014-3509]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3509 [CVE-2014-3508]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3508 [CVE-2014-3507]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3507 [CVE-2014-3506]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3506 [CVE-2014-3505]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3505 [CVE-2014-3470]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-3470 [CVE-2014-0224]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-0224 [CVE-2014-0221]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-0221 [CVE-2014-0198]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-0198 [CVE-2014-0195]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-0195 [CVE-2014-0160]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-0160 [CVE-2014-0076]: https://www.openssl.org/news/vulnerabilities.html#CVE-2014-0076 [CVE-2013-6450]: https://www.openssl.org/news/vulnerabilities.html#CVE-2013-6450 [CVE-2013-6449]: https://www.openssl.org/news/vulnerabilities.html#CVE-2013-6449 [CVE-2013-4353]: https://www.openssl.org/news/vulnerabilities.html#CVE-2013-4353 [CVE-2013-0169]: https://www.openssl.org/news/vulnerabilities.html#CVE-2013-0169 [CVE-2013-0166]: https://www.openssl.org/news/vulnerabilities.html#CVE-2013-0166 [CVE-2012-2686]: https://www.openssl.org/news/vulnerabilities.html#CVE-2012-2686 [CVE-2012-2333]: https://www.openssl.org/news/vulnerabilities.html#CVE-2012-2333 [CVE-2012-2110]: https://www.openssl.org/news/vulnerabilities.html#CVE-2012-2110 [CVE-2012-0884]: https://www.openssl.org/news/vulnerabilities.html#CVE-2012-0884 [CVE-2012-0050]: https://www.openssl.org/news/vulnerabilities.html#CVE-2012-0050 [CVE-2012-0027]: https://www.openssl.org/news/vulnerabilities.html#CVE-2012-0027 [CVE-2011-4619]: https://www.openssl.org/news/vulnerabilities.html#CVE-2011-4619 [CVE-2011-4577]: https://www.openssl.org/news/vulnerabilities.html#CVE-2011-4577 [CVE-2011-4576]: https://www.openssl.org/news/vulnerabilities.html#CVE-2011-4576 [CVE-2011-4108]: https://www.openssl.org/news/vulnerabilities.html#CVE-2011-4108 [CVE-2011-3210]: https://www.openssl.org/news/vulnerabilities.html#CVE-2011-3210 [CVE-2011-3207]: https://www.openssl.org/news/vulnerabilities.html#CVE-2011-3207 [CVE-2011-0014]: https://www.openssl.org/news/vulnerabilities.html#CVE-2011-0014 [CVE-2010-5298]: https://www.openssl.org/news/vulnerabilities.html#CVE-2010-5298 [CVE-2010-4252]: https://www.openssl.org/news/vulnerabilities.html#CVE-2010-4252 [CVE-2010-4180]: https://www.openssl.org/news/vulnerabilities.html#CVE-2010-4180 [CVE-2010-3864]: https://www.openssl.org/news/vulnerabilities.html#CVE-2010-3864 [CVE-2010-2939]: https://www.openssl.org/news/vulnerabilities.html#CVE-2010-2939 [CVE-2010-1633]: https://www.openssl.org/news/vulnerabilities.html#CVE-2010-1633 [CVE-2010-0740]: https://www.openssl.org/news/vulnerabilities.html#CVE-2010-0740 [CVE-2010-0433]: https://www.openssl.org/news/vulnerabilities.html#CVE-2010-0433 [CVE-2009-3555]: https://www.openssl.org/news/vulnerabilities.html#CVE-2009-3555 [CVE-2009-0789]: https://www.openssl.org/news/vulnerabilities.html#CVE-2009-0789 [CVE-2009-0591]: https://www.openssl.org/news/vulnerabilities.html#CVE-2009-0591 [CVE-2009-0590]: https://www.openssl.org/news/vulnerabilities.html#CVE-2009-0590 [CVE-2008-5077]: https://www.openssl.org/news/vulnerabilities.html#CVE-2008-5077 [CVE-2006-4343]: https://www.openssl.org/news/vulnerabilities.html#CVE-2006-4343 [CVE-2006-4339]: https://www.openssl.org/news/vulnerabilities.html#CVE-2006-4339 [CVE-2006-3737]: https://www.openssl.org/news/vulnerabilities.html#CVE-2006-3737 [CVE-2006-2940]: https://www.openssl.org/news/vulnerabilities.html#CVE-2006-2940 [CVE-2006-2937]: https://www.openssl.org/news/vulnerabilities.html#CVE-2006-2937 [CVE-2005-2969]: https://www.openssl.org/news/vulnerabilities.html#CVE-2005-2969 diff --git a/crypto/openssl/VERSION.dat b/crypto/openssl/VERSION.dat index c4157a86274d..9d9448118e6d 100644 --- a/crypto/openssl/VERSION.dat +++ b/crypto/openssl/VERSION.dat @@ -1,7 +1,7 @@ MAJOR=3 MINOR=0 -PATCH=11 +PATCH=12 PRE_RELEASE_TAG= BUILD_METADATA= -RELEASE_DATE="19 Sep 2023" +RELEASE_DATE="24 Oct 2023" SHLIB_VERSION=3 diff --git a/crypto/openssl/apps/dgst.c b/crypto/openssl/apps/dgst.c index e12389197de4..3f02af0d5738 100644 --- a/crypto/openssl/apps/dgst.c +++ b/crypto/openssl/apps/dgst.c @@ -1,655 +1,657 @@ /* * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ #include #include #include #include "apps.h" #include "progs.h" #include #include #include #include #include #include #include #include #undef BUFSIZE #define BUFSIZE 1024*8 int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout, int xoflen, EVP_PKEY *key, unsigned char *sigin, int siglen, const char *sig_name, const char *md_name, const char *file); static void show_digests(const OBJ_NAME *name, void *bio_); struct doall_dgst_digests { BIO *bio; int n; }; typedef enum OPTION_choice { OPT_COMMON, OPT_LIST, OPT_C, OPT_R, OPT_OUT, OPT_SIGN, OPT_PASSIN, OPT_VERIFY, OPT_PRVERIFY, OPT_SIGNATURE, OPT_KEYFORM, OPT_ENGINE, OPT_ENGINE_IMPL, OPT_HEX, OPT_BINARY, OPT_DEBUG, OPT_FIPS_FINGERPRINT, OPT_HMAC, OPT_MAC, OPT_SIGOPT, OPT_MACOPT, OPT_XOFLEN, OPT_DIGEST, OPT_R_ENUM, OPT_PROV_ENUM } OPTION_CHOICE; const OPTIONS dgst_options[] = { {OPT_HELP_STR, 1, '-', "Usage: %s [options] [file...]\n"}, OPT_SECTION("General"), {"help", OPT_HELP, '-', "Display this summary"}, {"list", OPT_LIST, '-', "List digests"}, #ifndef OPENSSL_NO_ENGINE {"engine", OPT_ENGINE, 's', "Use engine e, possibly a hardware device"}, {"engine_impl", OPT_ENGINE_IMPL, '-', "Also use engine given by -engine for digest operations"}, #endif {"passin", OPT_PASSIN, 's', "Input file pass phrase source"}, OPT_SECTION("Output"), {"c", OPT_C, '-', "Print the digest with separating colons"}, {"r", OPT_R, '-', "Print the digest in coreutils format"}, {"out", OPT_OUT, '>', "Output to filename rather than stdout"}, {"keyform", OPT_KEYFORM, 'f', "Key file format (ENGINE, other values ignored)"}, {"hex", OPT_HEX, '-', "Print as hex dump"}, {"binary", OPT_BINARY, '-', "Print in binary form"}, {"xoflen", OPT_XOFLEN, 'p', "Output length for XOF algorithms. To obtain the maximum security strength set this to 32 (or greater) for SHAKE128, and 64 (or greater) for SHAKE256"}, {"d", OPT_DEBUG, '-', "Print debug info"}, {"debug", OPT_DEBUG, '-', "Print debug info"}, OPT_SECTION("Signing"), {"sign", OPT_SIGN, 's', "Sign digest using private key"}, {"verify", OPT_VERIFY, 's', "Verify a signature using public key"}, {"prverify", OPT_PRVERIFY, 's', "Verify a signature using private key"}, {"sigopt", OPT_SIGOPT, 's', "Signature parameter in n:v form"}, {"signature", OPT_SIGNATURE, '<', "File with signature to verify"}, {"hmac", OPT_HMAC, 's', "Create hashed MAC with key"}, {"mac", OPT_MAC, 's', "Create MAC (not necessarily HMAC)"}, {"macopt", OPT_MACOPT, 's', "MAC algorithm parameters in n:v form or key"}, {"", OPT_DIGEST, '-', "Any supported digest"}, {"fips-fingerprint", OPT_FIPS_FINGERPRINT, '-', "Compute HMAC with the key used in OpenSSL-FIPS fingerprint"}, OPT_R_OPTIONS, OPT_PROV_OPTIONS, OPT_PARAMETERS(), {"file", 0, 0, "Files to digest (optional; default is stdin)"}, {NULL} }; int dgst_main(int argc, char **argv) { BIO *in = NULL, *inp, *bmd = NULL, *out = NULL; ENGINE *e = NULL, *impl = NULL; EVP_PKEY *sigkey = NULL; STACK_OF(OPENSSL_STRING) *sigopts = NULL, *macopts = NULL; char *hmac_key = NULL; char *mac_name = NULL, *digestname = NULL; char *passinarg = NULL, *passin = NULL; EVP_MD *md = NULL; const char *outfile = NULL, *keyfile = NULL, *prog = NULL; const char *sigfile = NULL; const char *md_name = NULL; OPTION_CHOICE o; int separator = 0, debug = 0, keyform = FORMAT_UNDEF, siglen = 0; int i, ret = EXIT_FAILURE, out_bin = -1, want_pub = 0, do_verify = 0; int xoflen = 0; unsigned char *buf = NULL, *sigbuf = NULL; int engine_impl = 0; struct doall_dgst_digests dec; buf = app_malloc(BUFSIZE, "I/O buffer"); md = (EVP_MD *)EVP_get_digestbyname(argv[0]); if (md != NULL) digestname = argv[0]; prog = opt_init(argc, argv, dgst_options); while ((o = opt_next()) != OPT_EOF) { switch (o) { case OPT_EOF: case OPT_ERR: opthelp: BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); goto end; case OPT_HELP: opt_help(dgst_options); ret = EXIT_SUCCESS; goto end; case OPT_LIST: BIO_printf(bio_out, "Supported digests:\n"); dec.bio = bio_out; dec.n = 0; OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_MD_METH, show_digests, &dec); BIO_printf(bio_out, "\n"); ret = EXIT_SUCCESS; goto end; case OPT_C: separator = 1; break; case OPT_R: separator = 2; break; case OPT_R_CASES: if (!opt_rand(o)) goto end; break; case OPT_OUT: outfile = opt_arg(); break; case OPT_SIGN: keyfile = opt_arg(); break; case OPT_PASSIN: passinarg = opt_arg(); break; case OPT_VERIFY: keyfile = opt_arg(); want_pub = do_verify = 1; break; case OPT_PRVERIFY: keyfile = opt_arg(); do_verify = 1; break; case OPT_SIGNATURE: sigfile = opt_arg(); break; case OPT_KEYFORM: if (!opt_format(opt_arg(), OPT_FMT_ANY, &keyform)) goto opthelp; break; case OPT_ENGINE: e = setup_engine(opt_arg(), 0); break; case OPT_ENGINE_IMPL: engine_impl = 1; break; case OPT_HEX: out_bin = 0; break; case OPT_BINARY: out_bin = 1; break; case OPT_XOFLEN: xoflen = atoi(opt_arg()); break; case OPT_DEBUG: debug = 1; break; case OPT_FIPS_FINGERPRINT: hmac_key = "etaonrishdlcupfm"; break; case OPT_HMAC: hmac_key = opt_arg(); break; case OPT_MAC: mac_name = opt_arg(); break; case OPT_SIGOPT: if (!sigopts) sigopts = sk_OPENSSL_STRING_new_null(); if (!sigopts || !sk_OPENSSL_STRING_push(sigopts, opt_arg())) goto opthelp; break; case OPT_MACOPT: if (!macopts) macopts = sk_OPENSSL_STRING_new_null(); if (!macopts || !sk_OPENSSL_STRING_push(macopts, opt_arg())) goto opthelp; break; case OPT_DIGEST: digestname = opt_unknown(); break; case OPT_PROV_CASES: if (!opt_provider(o)) goto end; break; } } /* Remaining args are files to digest. */ argc = opt_num_rest(); argv = opt_rest(); if (keyfile != NULL && argc > 1) { BIO_printf(bio_err, "%s: Can only sign or verify one file.\n", prog); goto end; } if (!app_RAND_load()) goto end; if (digestname != NULL) { if (!opt_md(digestname, &md)) goto opthelp; } if (do_verify && sigfile == NULL) { BIO_printf(bio_err, "No signature to verify: use the -signature option\n"); goto end; } if (engine_impl) impl = e; in = BIO_new(BIO_s_file()); bmd = BIO_new(BIO_f_md()); if (in == NULL || bmd == NULL) goto end; if (debug) { BIO_set_callback_ex(in, BIO_debug_callback_ex); /* needed for windows 3.1 */ BIO_set_callback_arg(in, (char *)bio_err); } if (!app_passwd(passinarg, NULL, &passin, NULL)) { BIO_printf(bio_err, "Error getting password\n"); goto end; } if (out_bin == -1) { if (keyfile != NULL) out_bin = 1; else out_bin = 0; } out = bio_open_default(outfile, 'w', out_bin ? FORMAT_BINARY : FORMAT_TEXT); if (out == NULL) goto end; if ((!(mac_name == NULL) + !(keyfile == NULL) + !(hmac_key == NULL)) > 1) { BIO_printf(bio_err, "MAC and signing key cannot both be specified\n"); goto end; } if (keyfile != NULL) { int type; if (want_pub) sigkey = load_pubkey(keyfile, keyform, 0, NULL, e, "public key"); else sigkey = load_key(keyfile, keyform, 0, passin, e, "private key"); if (sigkey == NULL) { /* * load_[pub]key() has already printed an appropriate message */ goto end; } type = EVP_PKEY_get_id(sigkey); if (type == EVP_PKEY_ED25519 || type == EVP_PKEY_ED448) { /* * We implement PureEdDSA for these which doesn't have a separate * digest, and only supports one shot. */ BIO_printf(bio_err, "Key type not supported for this operation\n"); goto end; } } if (mac_name != NULL) { EVP_PKEY_CTX *mac_ctx = NULL; if (!init_gen_str(&mac_ctx, mac_name, impl, 0, NULL, NULL)) goto end; if (macopts != NULL) { for (i = 0; i < sk_OPENSSL_STRING_num(macopts); i++) { char *macopt = sk_OPENSSL_STRING_value(macopts, i); if (pkey_ctrl_string(mac_ctx, macopt) <= 0) { EVP_PKEY_CTX_free(mac_ctx); BIO_printf(bio_err, "MAC parameter error \"%s\"\n", macopt); goto end; } } } sigkey = app_keygen(mac_ctx, mac_name, 0, 0 /* not verbose */); /* Verbose output would make external-tests gost-engine fail */ EVP_PKEY_CTX_free(mac_ctx); + if (sigkey == NULL) + goto end; } if (hmac_key != NULL) { if (md == NULL) { md = (EVP_MD *)EVP_sha256(); digestname = SN_sha256; } sigkey = EVP_PKEY_new_raw_private_key(EVP_PKEY_HMAC, impl, (unsigned char *)hmac_key, strlen(hmac_key)); if (sigkey == NULL) goto end; } if (sigkey != NULL) { EVP_MD_CTX *mctx = NULL; EVP_PKEY_CTX *pctx = NULL; int res; if (BIO_get_md_ctx(bmd, &mctx) <= 0) { BIO_printf(bio_err, "Error getting context\n"); goto end; } if (do_verify) if (impl == NULL) res = EVP_DigestVerifyInit_ex(mctx, &pctx, digestname, app_get0_libctx(), app_get0_propq(), sigkey, NULL); else res = EVP_DigestVerifyInit(mctx, &pctx, md, impl, sigkey); else if (impl == NULL) res = EVP_DigestSignInit_ex(mctx, &pctx, digestname, app_get0_libctx(), app_get0_propq(), sigkey, NULL); else res = EVP_DigestSignInit(mctx, &pctx, md, impl, sigkey); if (res == 0) { BIO_printf(bio_err, "Error setting context\n"); goto end; } if (sigopts != NULL) { for (i = 0; i < sk_OPENSSL_STRING_num(sigopts); i++) { char *sigopt = sk_OPENSSL_STRING_value(sigopts, i); if (pkey_ctrl_string(pctx, sigopt) <= 0) { BIO_printf(bio_err, "Signature parameter error \"%s\"\n", sigopt); goto end; } } } } /* we use md as a filter, reading from 'in' */ else { EVP_MD_CTX *mctx = NULL; if (BIO_get_md_ctx(bmd, &mctx) <= 0) { BIO_printf(bio_err, "Error getting context\n"); goto end; } if (md == NULL) md = (EVP_MD *)EVP_sha256(); if (!EVP_DigestInit_ex(mctx, md, impl)) { BIO_printf(bio_err, "Error setting digest\n"); goto end; } } if (sigfile != NULL && sigkey != NULL) { BIO *sigbio = BIO_new_file(sigfile, "rb"); if (sigbio == NULL) { BIO_printf(bio_err, "Error opening signature file %s\n", sigfile); goto end; } siglen = EVP_PKEY_get_size(sigkey); sigbuf = app_malloc(siglen, "signature buffer"); siglen = BIO_read(sigbio, sigbuf, siglen); BIO_free(sigbio); if (siglen <= 0) { BIO_printf(bio_err, "Error reading signature file %s\n", sigfile); goto end; } } inp = BIO_push(bmd, in); if (md == NULL) { EVP_MD_CTX *tctx; BIO_get_md_ctx(bmd, &tctx); md = EVP_MD_CTX_get1_md(tctx); } if (md != NULL) md_name = EVP_MD_get0_name(md); if (xoflen > 0) { if (!(EVP_MD_get_flags(md) & EVP_MD_FLAG_XOF)) { BIO_printf(bio_err, "Length can only be specified for XOF\n"); goto end; } /* * Signing using XOF is not supported by any algorithms currently since * each algorithm only calls EVP_DigestFinal_ex() in their sign_final * and verify_final methods. */ if (sigkey != NULL) { BIO_printf(bio_err, "Signing key cannot be specified for XOF\n"); goto end; } } if (argc == 0) { BIO_set_fp(in, stdin, BIO_NOCLOSE); ret = do_fp(out, buf, inp, separator, out_bin, xoflen, sigkey, sigbuf, siglen, NULL, md_name, "stdin"); } else { const char *sig_name = NULL; if (out_bin == 0) { if (sigkey != NULL) sig_name = EVP_PKEY_get0_type_name(sigkey); } ret = EXIT_SUCCESS; for (i = 0; i < argc; i++) { if (BIO_read_filename(in, argv[i]) <= 0) { perror(argv[i]); ret = EXIT_FAILURE; continue; } else { if (do_fp(out, buf, inp, separator, out_bin, xoflen, sigkey, sigbuf, siglen, sig_name, md_name, argv[i])) ret = EXIT_FAILURE; } (void)BIO_reset(bmd); } } end: if (ret != EXIT_SUCCESS) ERR_print_errors(bio_err); OPENSSL_clear_free(buf, BUFSIZE); BIO_free(in); OPENSSL_free(passin); BIO_free_all(out); EVP_MD_free(md); EVP_PKEY_free(sigkey); sk_OPENSSL_STRING_free(sigopts); sk_OPENSSL_STRING_free(macopts); OPENSSL_free(sigbuf); BIO_free(bmd); release_engine(e); return ret; } static void show_digests(const OBJ_NAME *name, void *arg) { struct doall_dgst_digests *dec = (struct doall_dgst_digests *)arg; const EVP_MD *md = NULL; /* Filter out signed digests (a.k.a signature algorithms) */ if (strstr(name->name, "rsa") != NULL || strstr(name->name, "RSA") != NULL) return; if (!islower((unsigned char)*name->name)) return; /* Filter out message digests that we cannot use */ md = EVP_MD_fetch(app_get0_libctx(), name->name, app_get0_propq()); if (md == NULL) { md = EVP_get_digestbyname(name->name); if (md == NULL) return; } BIO_printf(dec->bio, "-%-25s", name->name); if (++dec->n == 3) { BIO_printf(dec->bio, "\n"); dec->n = 0; } else { BIO_printf(dec->bio, " "); } } /* * The newline_escape_filename function performs newline escaping for any * filename that contains a newline. This function also takes a pointer * to backslash. The backslash pointer is a flag to indicating whether a newline * is present in the filename. If a newline is present, the backslash flag is * set and the output format will contain a backslash at the beginning of the * digest output. This output format is to replicate the output format found * in the '*sum' checksum programs. This aims to preserve backward * compatibility. */ static const char *newline_escape_filename(const char *file, int * backslash) { size_t i, e = 0, length = strlen(file), newline_count = 0, mem_len = 0; char *file_cpy = NULL; for (i = 0; i < length; i++) if (file[i] == '\n') newline_count++; mem_len = length + newline_count + 1; file_cpy = app_malloc(mem_len, file); i = 0; while(e < length) { const char c = file[e]; if (c == '\n') { file_cpy[i++] = '\\'; file_cpy[i++] = 'n'; *backslash = 1; } else { file_cpy[i++] = c; } e++; } file_cpy[i] = '\0'; return (const char*)file_cpy; } int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout, int xoflen, EVP_PKEY *key, unsigned char *sigin, int siglen, const char *sig_name, const char *md_name, const char *file) { size_t len = BUFSIZE; int i, backslash = 0, ret = EXIT_FAILURE; unsigned char *allocated_buf = NULL; while (BIO_pending(bp) || !BIO_eof(bp)) { i = BIO_read(bp, (char *)buf, BUFSIZE); if (i < 0) { BIO_printf(bio_err, "Read error in %s\n", file); goto end; } if (i == 0) break; } if (sigin != NULL) { EVP_MD_CTX *ctx; BIO_get_md_ctx(bp, &ctx); i = EVP_DigestVerifyFinal(ctx, sigin, (unsigned int)siglen); if (i > 0) { BIO_printf(out, "Verified OK\n"); } else if (i == 0) { BIO_printf(out, "Verification failure\n"); goto end; } else { BIO_printf(bio_err, "Error verifying data\n"); goto end; } ret = EXIT_SUCCESS; goto end; } if (key != NULL) { EVP_MD_CTX *ctx; size_t tmplen; BIO_get_md_ctx(bp, &ctx); if (!EVP_DigestSignFinal(ctx, NULL, &tmplen)) { BIO_printf(bio_err, "Error getting maximum length of signed data\n"); goto end; } if (tmplen > BUFSIZE) { len = tmplen; allocated_buf = app_malloc(len, "Signature buffer"); buf = allocated_buf; } if (!EVP_DigestSignFinal(ctx, buf, &len)) { BIO_printf(bio_err, "Error signing data\n"); goto end; } } else if (xoflen > 0) { EVP_MD_CTX *ctx; len = xoflen; if (len > BUFSIZE) { allocated_buf = app_malloc(len, "Digest buffer"); buf = allocated_buf; } BIO_get_md_ctx(bp, &ctx); if (!EVP_DigestFinalXOF(ctx, buf, len)) { BIO_printf(bio_err, "Error Digesting Data\n"); goto end; } } else { len = BIO_gets(bp, (char *)buf, BUFSIZE); if ((int)len < 0) goto end; } if (binout) { BIO_write(out, buf, len); } else if (sep == 2) { file = newline_escape_filename(file, &backslash); if (backslash == 1) BIO_puts(out, "\\"); for (i = 0; i < (int)len; i++) BIO_printf(out, "%02x", buf[i]); BIO_printf(out, " *%s\n", file); OPENSSL_free((char *)file); } else { if (sig_name != NULL) { BIO_puts(out, sig_name); if (md_name != NULL) BIO_printf(out, "-%s", md_name); BIO_printf(out, "(%s)= ", file); } else if (md_name != NULL) { BIO_printf(out, "%s(%s)= ", md_name, file); } else { BIO_printf(out, "(%s)= ", file); } for (i = 0; i < (int)len; i++) { if (sep && (i != 0)) BIO_printf(out, ":"); BIO_printf(out, "%02x", buf[i]); } BIO_printf(out, "\n"); } ret = EXIT_SUCCESS; end: if (allocated_buf != NULL) OPENSSL_clear_free(allocated_buf, len); return ret; } diff --git a/crypto/openssl/apps/dhparam.c b/crypto/openssl/apps/dhparam.c index 43906cea5649..2a54dca9d8b5 100644 --- a/crypto/openssl/apps/dhparam.c +++ b/crypto/openssl/apps/dhparam.c @@ -1,416 +1,418 @@ /* - * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ #include #include #include #include #include #include "apps.h" #include "progs.h" #include #include #include #include #include #include #include #include #include #include #include #include #define DEFBITS 2048 static EVP_PKEY *dsa_to_dh(EVP_PKEY *dh); static int gendh_cb(EVP_PKEY_CTX *ctx); typedef enum OPTION_choice { OPT_COMMON, OPT_INFORM, OPT_OUTFORM, OPT_IN, OPT_OUT, OPT_ENGINE, OPT_CHECK, OPT_TEXT, OPT_NOOUT, OPT_DSAPARAM, OPT_2, OPT_3, OPT_5, OPT_R_ENUM, OPT_PROV_ENUM } OPTION_CHOICE; const OPTIONS dhparam_options[] = { {OPT_HELP_STR, 1, '-', "Usage: %s [options] [numbits]\n"}, OPT_SECTION("General"), {"help", OPT_HELP, '-', "Display this summary"}, {"check", OPT_CHECK, '-', "Check the DH parameters"}, #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_DEPRECATED_3_0) {"dsaparam", OPT_DSAPARAM, '-', "Read or generate DSA parameters, convert to DH"}, #endif #ifndef OPENSSL_NO_ENGINE {"engine", OPT_ENGINE, 's', "Use engine e, possibly a hardware device"}, #endif OPT_SECTION("Input"), {"in", OPT_IN, '<', "Input file"}, {"inform", OPT_INFORM, 'F', "Input format, DER or PEM"}, OPT_SECTION("Output"), {"out", OPT_OUT, '>', "Output file"}, {"outform", OPT_OUTFORM, 'F', "Output format, DER or PEM"}, {"text", OPT_TEXT, '-', "Print a text form of the DH parameters"}, {"noout", OPT_NOOUT, '-', "Don't output any DH parameters"}, {"2", OPT_2, '-', "Generate parameters using 2 as the generator value"}, {"3", OPT_3, '-', "Generate parameters using 3 as the generator value"}, {"5", OPT_5, '-', "Generate parameters using 5 as the generator value"}, OPT_R_OPTIONS, OPT_PROV_OPTIONS, OPT_PARAMETERS(), {"numbits", 0, 0, "Number of bits if generating parameters (optional)"}, {NULL} }; int dhparam_main(int argc, char **argv) { BIO *in = NULL, *out = NULL; EVP_PKEY *pkey = NULL, *tmppkey = NULL; EVP_PKEY_CTX *ctx = NULL; char *infile = NULL, *outfile = NULL, *prog; ENGINE *e = NULL; int dsaparam = 0; int text = 0, ret = 1, num = 0, g = 0; int informat = FORMAT_PEM, outformat = FORMAT_PEM, check = 0, noout = 0; OPTION_CHOICE o; prog = opt_init(argc, argv, dhparam_options); while ((o = opt_next()) != OPT_EOF) { switch (o) { case OPT_EOF: case OPT_ERR: opthelp: BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); goto end; case OPT_HELP: opt_help(dhparam_options); ret = 0; goto end; case OPT_INFORM: if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &informat)) goto opthelp; break; case OPT_OUTFORM: if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &outformat)) goto opthelp; break; case OPT_IN: infile = opt_arg(); break; case OPT_OUT: outfile = opt_arg(); break; case OPT_ENGINE: e = setup_engine(opt_arg(), 0); break; case OPT_CHECK: check = 1; break; case OPT_TEXT: text = 1; break; case OPT_DSAPARAM: dsaparam = 1; break; case OPT_2: g = 2; break; case OPT_3: g = 3; break; case OPT_5: g = 5; break; case OPT_NOOUT: noout = 1; break; case OPT_R_CASES: if (!opt_rand(o)) goto end; break; case OPT_PROV_CASES: if (!opt_provider(o)) goto end; break; } } /* One optional argument, bitsize to generate. */ argc = opt_num_rest(); argv = opt_rest(); if (argc == 1) { if (!opt_int(argv[0], &num) || num <= 0) goto opthelp; } else if (argc != 0) { goto opthelp; } if (!app_RAND_load()) goto end; if (g && !num) num = DEFBITS; if (dsaparam && g) { BIO_printf(bio_err, "Error, generator may not be chosen for DSA parameters\n"); goto end; } out = bio_open_default(outfile, 'w', outformat); if (out == NULL) goto end; /* DH parameters */ if (num && !g) g = 2; if (num) { const char *alg = dsaparam ? "DSA" : "DH"; if (infile != NULL) { BIO_printf(bio_err, "Warning, input file %s ignored\n", infile); } ctx = EVP_PKEY_CTX_new_from_name(app_get0_libctx(), alg, app_get0_propq()); if (ctx == NULL) { BIO_printf(bio_err, "Error, %s param generation context allocation failed\n", alg); goto end; } EVP_PKEY_CTX_set_cb(ctx, gendh_cb); EVP_PKEY_CTX_set_app_data(ctx, bio_err); BIO_printf(bio_err, "Generating %s parameters, %d bit long %sprime\n", alg, num, dsaparam ? "" : "safe "); if (EVP_PKEY_paramgen_init(ctx) <= 0) { BIO_printf(bio_err, "Error, unable to initialise %s parameters\n", alg); goto end; } if (dsaparam) { if (EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, num) <= 0) { BIO_printf(bio_err, "Error, unable to set DSA prime length\n"); goto end; } } else { if (EVP_PKEY_CTX_set_dh_paramgen_prime_len(ctx, num) <= 0) { BIO_printf(bio_err, "Error, unable to set DH prime length\n"); goto end; } if (EVP_PKEY_CTX_set_dh_paramgen_generator(ctx, g) <= 0) { BIO_printf(bio_err, "Error, unable to set generator\n"); goto end; } } tmppkey = app_paramgen(ctx, alg); + if (tmppkey == NULL) + goto end; EVP_PKEY_CTX_free(ctx); ctx = NULL; if (dsaparam) { pkey = dsa_to_dh(tmppkey); if (pkey == NULL) goto end; EVP_PKEY_free(tmppkey); } else { pkey = tmppkey; } tmppkey = NULL; } else { OSSL_DECODER_CTX *decoderctx = NULL; const char *keytype = "DH"; int done; in = bio_open_default(infile, 'r', informat); if (in == NULL) goto end; do { /* * We assume we're done unless we explicitly want to retry and set * this to 0 below. */ done = 1; /* * We set NULL for the keytype to allow any key type. We don't know * if we're going to get DH or DHX (or DSA in the event of dsaparam). * We check that we got one of those key types afterwards. */ decoderctx = OSSL_DECODER_CTX_new_for_pkey(&tmppkey, (informat == FORMAT_ASN1) ? "DER" : "PEM", NULL, (informat == FORMAT_ASN1) ? keytype : NULL, OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS, NULL, NULL); if (decoderctx != NULL && !OSSL_DECODER_from_bio(decoderctx, in) && informat == FORMAT_ASN1 && strcmp(keytype, "DH") == 0) { /* * When reading DER we explicitly state the expected keytype * because, unlike PEM, there is no header to declare what * the contents of the DER file are. The decoders just try * and guess. Unfortunately with DHX key types they may guess * wrong and think we have a DSA keytype. Therefore we try * both DH and DHX sequentially. */ keytype = "DHX"; /* * BIO_reset() returns 0 for success for file BIOs only!!! * This won't work for stdin (and never has done) */ if (BIO_reset(in) == 0) done = 0; } OSSL_DECODER_CTX_free(decoderctx); } while (!done); if (tmppkey == NULL) { BIO_printf(bio_err, "Error, unable to load parameters\n"); goto end; } if (dsaparam) { if (!EVP_PKEY_is_a(tmppkey, "DSA")) { BIO_printf(bio_err, "Error, unable to load DSA parameters\n"); goto end; } pkey = dsa_to_dh(tmppkey); if (pkey == NULL) goto end; } else { if (!EVP_PKEY_is_a(tmppkey, "DH") && !EVP_PKEY_is_a(tmppkey, "DHX")) { BIO_printf(bio_err, "Error, unable to load DH parameters\n"); goto end; } pkey = tmppkey; tmppkey = NULL; } } if (text) EVP_PKEY_print_params(out, pkey, 4, NULL); if (check) { ctx = EVP_PKEY_CTX_new_from_pkey(app_get0_libctx(), pkey, app_get0_propq()); if (ctx == NULL) { BIO_printf(bio_err, "Error, failed to check DH parameters\n"); goto end; } if (EVP_PKEY_param_check(ctx) <= 0) { BIO_printf(bio_err, "Error, invalid parameters generated\n"); goto end; } BIO_printf(bio_err, "DH parameters appear to be ok.\n"); } if (!noout) { OSSL_ENCODER_CTX *ectx = OSSL_ENCODER_CTX_new_for_pkey(pkey, OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS, outformat == FORMAT_ASN1 ? "DER" : "PEM", NULL, NULL); if (ectx == NULL || !OSSL_ENCODER_to_bio(ectx, out)) { OSSL_ENCODER_CTX_free(ectx); BIO_printf(bio_err, "Error, unable to write DH parameters\n"); goto end; } OSSL_ENCODER_CTX_free(ectx); } ret = 0; end: if (ret != 0) ERR_print_errors(bio_err); BIO_free(in); BIO_free_all(out); EVP_PKEY_free(pkey); EVP_PKEY_free(tmppkey); EVP_PKEY_CTX_free(ctx); release_engine(e); return ret; } /* * Historically we had the low level call DSA_dup_DH() to do this. * That is now deprecated with no replacement. Since we still need to do this * for backwards compatibility reasons, we do it "manually". */ static EVP_PKEY *dsa_to_dh(EVP_PKEY *dh) { OSSL_PARAM_BLD *tmpl = NULL; OSSL_PARAM *params = NULL; BIGNUM *bn_p = NULL, *bn_q = NULL, *bn_g = NULL; EVP_PKEY_CTX *ctx = NULL; EVP_PKEY *pkey = NULL; if (!EVP_PKEY_get_bn_param(dh, OSSL_PKEY_PARAM_FFC_P, &bn_p) || !EVP_PKEY_get_bn_param(dh, OSSL_PKEY_PARAM_FFC_Q, &bn_q) || !EVP_PKEY_get_bn_param(dh, OSSL_PKEY_PARAM_FFC_G, &bn_g)) { BIO_printf(bio_err, "Error, failed to set DH parameters\n"); goto err; } if ((tmpl = OSSL_PARAM_BLD_new()) == NULL || !OSSL_PARAM_BLD_push_BN(tmpl, OSSL_PKEY_PARAM_FFC_P, bn_p) || !OSSL_PARAM_BLD_push_BN(tmpl, OSSL_PKEY_PARAM_FFC_Q, bn_q) || !OSSL_PARAM_BLD_push_BN(tmpl, OSSL_PKEY_PARAM_FFC_G, bn_g) || (params = OSSL_PARAM_BLD_to_param(tmpl)) == NULL) { BIO_printf(bio_err, "Error, failed to set DH parameters\n"); goto err; } ctx = EVP_PKEY_CTX_new_from_name(app_get0_libctx(), "DHX", app_get0_propq()); if (ctx == NULL || EVP_PKEY_fromdata_init(ctx) <= 0 || EVP_PKEY_fromdata(ctx, &pkey, EVP_PKEY_KEY_PARAMETERS, params) <= 0) { BIO_printf(bio_err, "Error, failed to set DH parameters\n"); goto err; } err: EVP_PKEY_CTX_free(ctx); OSSL_PARAM_free(params); OSSL_PARAM_BLD_free(tmpl); BN_free(bn_p); BN_free(bn_q); BN_free(bn_g); return pkey; } static int gendh_cb(EVP_PKEY_CTX *ctx) { int p = EVP_PKEY_CTX_get_keygen_info(ctx, 0); BIO *b = EVP_PKEY_CTX_get_app_data(ctx); static const char symbols[] = ".+*\n"; char c = (p >= 0 && (size_t)p < sizeof(symbols) - 1) ? symbols[p] : '?'; BIO_write(b, &c, 1); (void)BIO_flush(b); return 1; } diff --git a/crypto/openssl/apps/dsaparam.c b/crypto/openssl/apps/dsaparam.c index b5555282be6e..ca91beb5b893 100644 --- a/crypto/openssl/apps/dsaparam.c +++ b/crypto/openssl/apps/dsaparam.c @@ -1,256 +1,258 @@ /* - * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ #include #include #include #include "apps.h" #include #include #include "apps.h" #include "progs.h" #include #include #include #include #include #include static int verbose = 0; static int gendsa_cb(EVP_PKEY_CTX *ctx); typedef enum OPTION_choice { OPT_COMMON, OPT_INFORM, OPT_OUTFORM, OPT_IN, OPT_OUT, OPT_TEXT, OPT_NOOUT, OPT_GENKEY, OPT_ENGINE, OPT_VERBOSE, OPT_R_ENUM, OPT_PROV_ENUM } OPTION_CHOICE; const OPTIONS dsaparam_options[] = { {OPT_HELP_STR, 1, '-', "Usage: %s [options] [numbits]\n"}, OPT_SECTION("General"), {"help", OPT_HELP, '-', "Display this summary"}, #ifndef OPENSSL_NO_ENGINE {"engine", OPT_ENGINE, 's', "Use engine e, possibly a hardware device"}, #endif OPT_SECTION("Input"), {"in", OPT_IN, '<', "Input file"}, {"inform", OPT_INFORM, 'F', "Input format - DER or PEM"}, OPT_SECTION("Output"), {"out", OPT_OUT, '>', "Output file"}, {"outform", OPT_OUTFORM, 'F', "Output format - DER or PEM"}, {"text", OPT_TEXT, '-', "Print as text"}, {"noout", OPT_NOOUT, '-', "No output"}, {"verbose", OPT_VERBOSE, '-', "Verbose output"}, {"genkey", OPT_GENKEY, '-', "Generate a DSA key"}, OPT_R_OPTIONS, OPT_PROV_OPTIONS, OPT_PARAMETERS(), {"numbits", 0, 0, "Number of bits if generating parameters (optional)"}, {NULL} }; int dsaparam_main(int argc, char **argv) { ENGINE *e = NULL; BIO *out = NULL; EVP_PKEY *params = NULL, *pkey = NULL; EVP_PKEY_CTX *ctx = NULL; int numbits = -1, num = 0, genkey = 0; int informat = FORMAT_UNDEF, outformat = FORMAT_PEM, noout = 0; int ret = 1, i, text = 0, private = 0; char *infile = NULL, *outfile = NULL, *prog; OPTION_CHOICE o; prog = opt_init(argc, argv, dsaparam_options); while ((o = opt_next()) != OPT_EOF) { switch (o) { case OPT_EOF: case OPT_ERR: opthelp: BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); goto end; case OPT_HELP: opt_help(dsaparam_options); ret = 0; goto end; case OPT_INFORM: if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &informat)) goto opthelp; break; case OPT_IN: infile = opt_arg(); break; case OPT_OUTFORM: if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &outformat)) goto opthelp; break; case OPT_OUT: outfile = opt_arg(); break; case OPT_ENGINE: e = setup_engine(opt_arg(), 0); break; case OPT_TEXT: text = 1; break; case OPT_GENKEY: genkey = 1; break; case OPT_R_CASES: if (!opt_rand(o)) goto end; break; case OPT_PROV_CASES: if (!opt_provider(o)) goto end; break; case OPT_NOOUT: noout = 1; break; case OPT_VERBOSE: verbose = 1; break; } } /* Optional arg is bitsize. */ argc = opt_num_rest(); argv = opt_rest(); if (argc == 1) { if (!opt_int(argv[0], &num) || num < 0) goto opthelp; } else if (argc != 0) { goto opthelp; } if (!app_RAND_load()) goto end; /* generate a key */ numbits = num; private = genkey ? 1 : 0; out = bio_open_owner(outfile, outformat, private); if (out == NULL) goto end; ctx = EVP_PKEY_CTX_new_from_name(app_get0_libctx(), "DSA", app_get0_propq()); if (ctx == NULL) { BIO_printf(bio_err, "Error, DSA parameter generation context allocation failed\n"); goto end; } if (numbits > 0) { if (numbits > OPENSSL_DSA_MAX_MODULUS_BITS) BIO_printf(bio_err, "Warning: It is not recommended to use more than %d bit for DSA keys.\n" " Your key size is %d! Larger key size may behave not as expected.\n", OPENSSL_DSA_MAX_MODULUS_BITS, numbits); EVP_PKEY_CTX_set_cb(ctx, gendsa_cb); EVP_PKEY_CTX_set_app_data(ctx, bio_err); if (verbose) { BIO_printf(bio_err, "Generating DSA parameters, %d bit long prime\n", num); BIO_printf(bio_err, "This could take some time\n"); } if (EVP_PKEY_paramgen_init(ctx) <= 0) { BIO_printf(bio_err, "Error, DSA key generation paramgen init failed\n"); goto end; } if (EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, num) <= 0) { BIO_printf(bio_err, "Error, DSA key generation setting bit length failed\n"); goto end; } params = app_paramgen(ctx, "DSA"); } else { params = load_keyparams(infile, informat, 1, "DSA", "DSA parameters"); } if (params == NULL) { /* Error message should already have been displayed */ goto end; } if (text) { EVP_PKEY_print_params(out, params, 0, NULL); } if (outformat == FORMAT_ASN1 && genkey) noout = 1; if (!noout) { if (outformat == FORMAT_ASN1) i = i2d_KeyParams_bio(out, params); else i = PEM_write_bio_Parameters(out, params); if (!i) { BIO_printf(bio_err, "Error, unable to write DSA parameters\n"); goto end; } } if (genkey) { EVP_PKEY_CTX_free(ctx); ctx = EVP_PKEY_CTX_new_from_pkey(app_get0_libctx(), params, app_get0_propq()); if (ctx == NULL) { BIO_printf(bio_err, "Error, DSA key generation context allocation failed\n"); goto end; } if (EVP_PKEY_keygen_init(ctx) <= 0) { BIO_printf(bio_err, "Error, unable to initialise for key generation\n"); goto end; } pkey = app_keygen(ctx, "DSA", numbits, verbose); + if (pkey == NULL) + goto end; assert(private); if (outformat == FORMAT_ASN1) i = i2d_PrivateKey_bio(out, pkey); else i = PEM_write_bio_PrivateKey(out, pkey, NULL, NULL, 0, NULL, NULL); } ret = 0; end: if (ret != 0) ERR_print_errors(bio_err); BIO_free_all(out); EVP_PKEY_CTX_free(ctx); EVP_PKEY_free(pkey); EVP_PKEY_free(params); release_engine(e); return ret; } static int gendsa_cb(EVP_PKEY_CTX *ctx) { static const char symbols[] = ".+*\n"; int p; char c; BIO *b; if (!verbose) return 1; b = EVP_PKEY_CTX_get_app_data(ctx); p = EVP_PKEY_CTX_get_keygen_info(ctx, 0); c = (p >= 0 && (size_t)p < sizeof(symbols) - 1) ? symbols[p] : '?'; BIO_write(b, &c, 1); (void)BIO_flush(b); return 1; } diff --git a/crypto/openssl/apps/enc.c b/crypto/openssl/apps/enc.c index b3bf4cc2592d..c275046cf57a 100644 --- a/crypto/openssl/apps/enc.c +++ b/crypto/openssl/apps/enc.c @@ -1,705 +1,708 @@ /* * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ #include #include #include #include #include "apps.h" #include "progs.h" #include #include #include #include #include #include #include #ifndef OPENSSL_NO_COMP # include #endif #include #undef SIZE #undef BSIZE #define SIZE (512) #define BSIZE (8*1024) #define PBKDF2_ITER_DEFAULT 10000 #define STR(a) XSTR(a) #define XSTR(a) #a static int set_hex(const char *in, unsigned char *out, int size); static void show_ciphers(const OBJ_NAME *name, void *bio_); struct doall_enc_ciphers { BIO *bio; int n; }; typedef enum OPTION_choice { OPT_COMMON, OPT_LIST, OPT_E, OPT_IN, OPT_OUT, OPT_PASS, OPT_ENGINE, OPT_D, OPT_P, OPT_V, OPT_NOPAD, OPT_SALT, OPT_NOSALT, OPT_DEBUG, OPT_UPPER_P, OPT_UPPER_A, OPT_A, OPT_Z, OPT_BUFSIZE, OPT_K, OPT_KFILE, OPT_UPPER_K, OPT_NONE, OPT_UPPER_S, OPT_IV, OPT_MD, OPT_ITER, OPT_PBKDF2, OPT_CIPHER, OPT_R_ENUM, OPT_PROV_ENUM } OPTION_CHOICE; const OPTIONS enc_options[] = { OPT_SECTION("General"), {"help", OPT_HELP, '-', "Display this summary"}, {"list", OPT_LIST, '-', "List ciphers"}, #ifndef OPENSSL_NO_DEPRECATED_3_0 {"ciphers", OPT_LIST, '-', "Alias for -list"}, #endif {"e", OPT_E, '-', "Encrypt"}, {"d", OPT_D, '-', "Decrypt"}, {"p", OPT_P, '-', "Print the iv/key"}, {"P", OPT_UPPER_P, '-', "Print the iv/key and exit"}, #ifndef OPENSSL_NO_ENGINE {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"}, #endif OPT_SECTION("Input"), {"in", OPT_IN, '<', "Input file"}, {"k", OPT_K, 's', "Passphrase"}, {"kfile", OPT_KFILE, '<', "Read passphrase from file"}, OPT_SECTION("Output"), {"out", OPT_OUT, '>', "Output file"}, {"pass", OPT_PASS, 's', "Passphrase source"}, {"v", OPT_V, '-', "Verbose output"}, {"a", OPT_A, '-', "Base64 encode/decode, depending on encryption flag"}, {"base64", OPT_A, '-', "Same as option -a"}, {"A", OPT_UPPER_A, '-', "Used with -[base64|a] to specify base64 buffer as a single line"}, OPT_SECTION("Encryption"), {"nopad", OPT_NOPAD, '-', "Disable standard block padding"}, {"salt", OPT_SALT, '-', "Use salt in the KDF (default)"}, {"nosalt", OPT_NOSALT, '-', "Do not use salt in the KDF"}, {"debug", OPT_DEBUG, '-', "Print debug info"}, {"bufsize", OPT_BUFSIZE, 's', "Buffer size"}, {"K", OPT_UPPER_K, 's', "Raw key, in hex"}, {"S", OPT_UPPER_S, 's', "Salt, in hex"}, {"iv", OPT_IV, 's', "IV in hex"}, {"md", OPT_MD, 's', "Use specified digest to create a key from the passphrase"}, {"iter", OPT_ITER, 'p', "Specify the iteration count and force the use of PBKDF2"}, {OPT_MORE_STR, 0, 0, "Default: " STR(PBKDF2_ITER_DEFAULT)}, {"pbkdf2", OPT_PBKDF2, '-', "Use password-based key derivation function 2 (PBKDF2)"}, {OPT_MORE_STR, 0, 0, "Use -iter to change the iteration count from " STR(PBKDF2_ITER_DEFAULT)}, {"none", OPT_NONE, '-', "Don't encrypt"}, #ifdef ZLIB {"z", OPT_Z, '-', "Compress or decompress encrypted data using zlib"}, #endif {"", OPT_CIPHER, '-', "Any supported cipher"}, OPT_R_OPTIONS, OPT_PROV_OPTIONS, {NULL} }; int enc_main(int argc, char **argv) { static char buf[128]; static const char magic[] = "Salted__"; ENGINE *e = NULL; BIO *in = NULL, *out = NULL, *b64 = NULL, *benc = NULL, *rbio = NULL, *wbio = NULL; EVP_CIPHER_CTX *ctx = NULL; EVP_CIPHER *cipher = NULL; EVP_MD *dgst = NULL; const char *digestname = NULL; char *hkey = NULL, *hiv = NULL, *hsalt = NULL, *p; char *infile = NULL, *outfile = NULL, *prog; char *str = NULL, *passarg = NULL, *pass = NULL, *strbuf = NULL; const char *ciphername = NULL; char mbuf[sizeof(magic) - 1]; OPTION_CHOICE o; int bsize = BSIZE, verbose = 0, debug = 0, olb64 = 0, nosalt = 0; int enc = 1, printkey = 0, i, k; int base64 = 0, informat = FORMAT_BINARY, outformat = FORMAT_BINARY; int ret = 1, inl, nopad = 0; unsigned char key[EVP_MAX_KEY_LENGTH], iv[EVP_MAX_IV_LENGTH]; unsigned char *buff = NULL, salt[PKCS5_SALT_LEN]; int pbkdf2 = 0; int iter = 0; long n; struct doall_enc_ciphers dec; #ifdef ZLIB int do_zlib = 0; BIO *bzl = NULL; #endif /* first check the command name */ if (strcmp(argv[0], "base64") == 0) base64 = 1; #ifdef ZLIB else if (strcmp(argv[0], "zlib") == 0) do_zlib = 1; #endif else if (strcmp(argv[0], "enc") != 0) ciphername = argv[0]; prog = opt_init(argc, argv, enc_options); while ((o = opt_next()) != OPT_EOF) { switch (o) { case OPT_EOF: case OPT_ERR: opthelp: BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); goto end; case OPT_HELP: opt_help(enc_options); ret = 0; goto end; case OPT_LIST: BIO_printf(bio_out, "Supported ciphers:\n"); dec.bio = bio_out; dec.n = 0; OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_CIPHER_METH, show_ciphers, &dec); BIO_printf(bio_out, "\n"); ret = 0; goto end; case OPT_E: enc = 1; break; case OPT_IN: infile = opt_arg(); break; case OPT_OUT: outfile = opt_arg(); break; case OPT_PASS: passarg = opt_arg(); break; case OPT_ENGINE: e = setup_engine(opt_arg(), 0); break; case OPT_D: enc = 0; break; case OPT_P: printkey = 1; break; case OPT_V: verbose = 1; break; case OPT_NOPAD: nopad = 1; break; case OPT_SALT: nosalt = 0; break; case OPT_NOSALT: nosalt = 1; break; case OPT_DEBUG: debug = 1; break; case OPT_UPPER_P: printkey = 2; break; case OPT_UPPER_A: olb64 = 1; break; case OPT_A: base64 = 1; break; case OPT_Z: #ifdef ZLIB do_zlib = 1; #endif break; case OPT_BUFSIZE: p = opt_arg(); i = (int)strlen(p) - 1; k = i >= 1 && p[i] == 'k'; if (k) p[i] = '\0'; if (!opt_long(opt_arg(), &n) || n < 0 || (k && n >= LONG_MAX / 1024)) goto opthelp; if (k) n *= 1024; bsize = (int)n; break; case OPT_K: str = opt_arg(); break; case OPT_KFILE: in = bio_open_default(opt_arg(), 'r', FORMAT_TEXT); if (in == NULL) goto opthelp; i = BIO_gets(in, buf, sizeof(buf)); BIO_free(in); in = NULL; if (i <= 0) { BIO_printf(bio_err, "%s Can't read key from %s\n", prog, opt_arg()); goto opthelp; } while (--i > 0 && (buf[i] == '\r' || buf[i] == '\n')) buf[i] = '\0'; if (i <= 0) { BIO_printf(bio_err, "%s: zero length password\n", prog); goto opthelp; } str = buf; break; case OPT_UPPER_K: hkey = opt_arg(); break; case OPT_UPPER_S: hsalt = opt_arg(); break; case OPT_IV: hiv = opt_arg(); break; case OPT_MD: digestname = opt_arg(); break; case OPT_CIPHER: ciphername = opt_unknown(); break; case OPT_ITER: iter = opt_int_arg(); pbkdf2 = 1; break; case OPT_PBKDF2: pbkdf2 = 1; if (iter == 0) /* do not overwrite a chosen value */ iter = PBKDF2_ITER_DEFAULT; break; case OPT_NONE: cipher = NULL; break; case OPT_R_CASES: if (!opt_rand(o)) goto end; break; case OPT_PROV_CASES: if (!opt_provider(o)) goto end; break; } } /* No extra arguments. */ argc = opt_num_rest(); if (argc != 0) goto opthelp; if (!app_RAND_load()) goto end; /* Get the cipher name, either from progname (if set) or flag. */ if (ciphername != NULL) { if (!opt_cipher(ciphername, &cipher)) goto opthelp; } if (digestname != NULL) { if (!opt_md(digestname, &dgst)) goto opthelp; } if (dgst == NULL) dgst = (EVP_MD *)EVP_sha256(); if (iter == 0) iter = 1; /* It must be large enough for a base64 encoded line */ if (base64 && bsize < 80) bsize = 80; if (verbose) BIO_printf(bio_err, "bufsize=%d\n", bsize); #ifdef ZLIB if (!do_zlib) #endif if (base64) { if (enc) outformat = FORMAT_BASE64; else informat = FORMAT_BASE64; } strbuf = app_malloc(SIZE, "strbuf"); buff = app_malloc(EVP_ENCODE_LENGTH(bsize), "evp buffer"); if (infile == NULL) { in = dup_bio_in(informat); } else { in = bio_open_default(infile, 'r', informat); } if (in == NULL) goto end; if (str == NULL && passarg != NULL) { if (!app_passwd(passarg, NULL, &pass, NULL)) { BIO_printf(bio_err, "Error getting password\n"); goto end; } str = pass; } if ((str == NULL) && (cipher != NULL) && (hkey == NULL)) { if (1) { #ifndef OPENSSL_NO_UI_CONSOLE for (;;) { char prompt[200]; BIO_snprintf(prompt, sizeof(prompt), "enter %s %s password:", EVP_CIPHER_get0_name(cipher), (enc) ? "encryption" : "decryption"); strbuf[0] = '\0'; i = EVP_read_pw_string((char *)strbuf, SIZE, prompt, enc); if (i == 0) { if (strbuf[0] == '\0') { ret = 1; goto end; } str = strbuf; break; } if (i < 0) { BIO_printf(bio_err, "bad password read\n"); goto end; } } } else { #endif BIO_printf(bio_err, "password required\n"); goto end; } } out = bio_open_default(outfile, 'w', outformat); if (out == NULL) goto end; if (debug) { BIO_set_callback_ex(in, BIO_debug_callback_ex); BIO_set_callback_ex(out, BIO_debug_callback_ex); BIO_set_callback_arg(in, (char *)bio_err); BIO_set_callback_arg(out, (char *)bio_err); } rbio = in; wbio = out; #ifdef ZLIB if (do_zlib) { if ((bzl = BIO_new(BIO_f_zlib())) == NULL) goto end; if (debug) { BIO_set_callback_ex(bzl, BIO_debug_callback_ex); BIO_set_callback_arg(bzl, (char *)bio_err); } if (enc) wbio = BIO_push(bzl, wbio); else rbio = BIO_push(bzl, rbio); } #endif if (base64) { if ((b64 = BIO_new(BIO_f_base64())) == NULL) goto end; if (debug) { BIO_set_callback_ex(b64, BIO_debug_callback_ex); BIO_set_callback_arg(b64, (char *)bio_err); } if (olb64) BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); if (enc) wbio = BIO_push(b64, wbio); else rbio = BIO_push(b64, rbio); } if (cipher != NULL) { if (str != NULL) { /* a passphrase is available */ /* * Salt handling: if encrypting generate a salt if not supplied, * and write to output BIO. If decrypting use salt from input BIO * if not given with args */ unsigned char *sptr; size_t str_len = strlen(str); if (nosalt) { sptr = NULL; } else { if (hsalt != NULL && !set_hex(hsalt, salt, sizeof(salt))) { BIO_printf(bio_err, "invalid hex salt value\n"); goto end; } if (enc) { /* encryption */ if (hsalt == NULL) { if (RAND_bytes(salt, sizeof(salt)) <= 0) { BIO_printf(bio_err, "RAND_bytes failed\n"); goto end; } /* * If -P option then don't bother writing. * If salt is given, shouldn't either ? */ if ((printkey != 2) && (BIO_write(wbio, magic, sizeof(magic) - 1) != sizeof(magic) - 1 || BIO_write(wbio, (char *)salt, sizeof(salt)) != sizeof(salt))) { BIO_printf(bio_err, "error writing output file\n"); goto end; } } } else { /* decryption */ if (hsalt == NULL) { if (BIO_read(rbio, mbuf, sizeof(mbuf)) != sizeof(mbuf)) { BIO_printf(bio_err, "error reading input file\n"); goto end; } if (memcmp(mbuf, magic, sizeof(mbuf)) == 0) { /* file IS salted */ if (BIO_read(rbio, salt, sizeof(salt)) != sizeof(salt)) { BIO_printf(bio_err, "error reading input file\n"); goto end; } } else { /* file is NOT salted, NO salt available */ BIO_printf(bio_err, "bad magic number\n"); goto end; } } } sptr = salt; } if (pbkdf2 == 1) { /* * derive key and default iv * concatenated into a temporary buffer */ unsigned char tmpkeyiv[EVP_MAX_KEY_LENGTH + EVP_MAX_IV_LENGTH]; int iklen = EVP_CIPHER_get_key_length(cipher); int ivlen = EVP_CIPHER_get_iv_length(cipher); /* not needed if HASH_UPDATE() is fixed : */ int islen = (sptr != NULL ? sizeof(salt) : 0); if (!PKCS5_PBKDF2_HMAC(str, str_len, sptr, islen, iter, dgst, iklen+ivlen, tmpkeyiv)) { BIO_printf(bio_err, "PKCS5_PBKDF2_HMAC failed\n"); goto end; } /* split and move data back to global buffer */ memcpy(key, tmpkeyiv, iklen); memcpy(iv, tmpkeyiv+iklen, ivlen); } else { BIO_printf(bio_err, "*** WARNING : " "deprecated key derivation used.\n" "Using -iter or -pbkdf2 would be better.\n"); if (!EVP_BytesToKey(cipher, dgst, sptr, (unsigned char *)str, str_len, 1, key, iv)) { BIO_printf(bio_err, "EVP_BytesToKey failed\n"); goto end; } } /* * zero the complete buffer or the string passed from the command * line. */ if (str == strbuf) OPENSSL_cleanse(str, SIZE); else OPENSSL_cleanse(str, str_len); } if (hiv != NULL) { int siz = EVP_CIPHER_get_iv_length(cipher); if (siz == 0) { BIO_printf(bio_err, "warning: iv not used by this cipher\n"); } else if (!set_hex(hiv, iv, siz)) { BIO_printf(bio_err, "invalid hex iv value\n"); goto end; } } if ((hiv == NULL) && (str == NULL) && EVP_CIPHER_get_iv_length(cipher) != 0) { /* * No IV was explicitly set and no IV was generated. * Hence the IV is undefined, making correct decryption impossible. */ BIO_printf(bio_err, "iv undefined\n"); goto end; } if (hkey != NULL) { if (!set_hex(hkey, key, EVP_CIPHER_get_key_length(cipher))) { BIO_printf(bio_err, "invalid hex key value\n"); goto end; } /* wiping secret data as we no longer need it */ cleanse(hkey); } if ((benc = BIO_new(BIO_f_cipher())) == NULL) goto end; /* * Since we may be changing parameters work on the encryption context * rather than calling BIO_set_cipher(). */ BIO_get_cipher_ctx(benc, &ctx); if (!EVP_CipherInit_ex(ctx, cipher, e, NULL, NULL, enc)) { BIO_printf(bio_err, "Error setting cipher %s\n", EVP_CIPHER_get0_name(cipher)); ERR_print_errors(bio_err); goto end; } if (nopad) EVP_CIPHER_CTX_set_padding(ctx, 0); if (!EVP_CipherInit_ex(ctx, NULL, NULL, key, iv, enc)) { BIO_printf(bio_err, "Error setting cipher %s\n", EVP_CIPHER_get0_name(cipher)); ERR_print_errors(bio_err); goto end; } if (debug) { BIO_set_callback_ex(benc, BIO_debug_callback_ex); BIO_set_callback_arg(benc, (char *)bio_err); } if (printkey) { if (!nosalt) { printf("salt="); for (i = 0; i < (int)sizeof(salt); i++) printf("%02X", salt[i]); printf("\n"); } if (EVP_CIPHER_get_key_length(cipher) > 0) { printf("key="); for (i = 0; i < EVP_CIPHER_get_key_length(cipher); i++) printf("%02X", key[i]); printf("\n"); } if (EVP_CIPHER_get_iv_length(cipher) > 0) { printf("iv ="); for (i = 0; i < EVP_CIPHER_get_iv_length(cipher); i++) printf("%02X", iv[i]); printf("\n"); } if (printkey == 2) { ret = 0; goto end; } } } /* Only encrypt/decrypt as we write the file */ if (benc != NULL) wbio = BIO_push(benc, wbio); while (BIO_pending(rbio) || !BIO_eof(rbio)) { inl = BIO_read(rbio, (char *)buff, bsize); if (inl <= 0) break; if (BIO_write(wbio, (char *)buff, inl) != inl) { BIO_printf(bio_err, "error writing output file\n"); goto end; } } if (!BIO_flush(wbio)) { - BIO_printf(bio_err, "bad decrypt\n"); + if (enc) + BIO_printf(bio_err, "bad encrypt\n"); + else + BIO_printf(bio_err, "bad decrypt\n"); goto end; } ret = 0; if (verbose) { BIO_printf(bio_err, "bytes read : %8ju\n", BIO_number_read(in)); BIO_printf(bio_err, "bytes written: %8ju\n", BIO_number_written(out)); } end: ERR_print_errors(bio_err); OPENSSL_free(strbuf); OPENSSL_free(buff); BIO_free(in); BIO_free_all(out); BIO_free(benc); BIO_free(b64); EVP_MD_free(dgst); EVP_CIPHER_free(cipher); #ifdef ZLIB BIO_free(bzl); #endif release_engine(e); OPENSSL_free(pass); return ret; } static void show_ciphers(const OBJ_NAME *name, void *arg) { struct doall_enc_ciphers *dec = (struct doall_enc_ciphers *)arg; const EVP_CIPHER *cipher; if (!islower((unsigned char)*name->name)) return; /* Filter out ciphers that we cannot use */ cipher = EVP_get_cipherbyname(name->name); if (cipher == NULL || (EVP_CIPHER_get_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER) != 0 || EVP_CIPHER_get_mode(cipher) == EVP_CIPH_XTS_MODE) return; BIO_printf(dec->bio, "-%-25s", name->name); if (++dec->n == 3) { BIO_printf(dec->bio, "\n"); dec->n = 0; } else BIO_printf(dec->bio, " "); } static int set_hex(const char *in, unsigned char *out, int size) { int i, n; unsigned char j; i = size * 2; n = strlen(in); if (n > i) { BIO_printf(bio_err, "hex string is too long, ignoring excess\n"); n = i; /* ignore exceeding part */ } else if (n < i) { BIO_printf(bio_err, "hex string is too short, padding with zero bytes to length\n"); } memset(out, 0, size); for (i = 0; i < n; i++) { j = (unsigned char)*in++; if (!isxdigit(j)) { BIO_printf(bio_err, "non-hex digit\n"); return 0; } j = (unsigned char)OPENSSL_hexchar2int(j); if (i & 1) out[i / 2] |= j; else out[i / 2] = (j << 4); } return 1; } diff --git a/crypto/openssl/apps/gendsa.c b/crypto/openssl/apps/gendsa.c index 27feb793fed2..8aefca65566c 100644 --- a/crypto/openssl/apps/gendsa.c +++ b/crypto/openssl/apps/gendsa.c @@ -1,168 +1,170 @@ /* - * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ #include #include #include #include #include #include "apps.h" #include "progs.h" #include #include #include #include #include #include typedef enum OPTION_choice { OPT_COMMON, OPT_OUT, OPT_PASSOUT, OPT_ENGINE, OPT_CIPHER, OPT_VERBOSE, OPT_R_ENUM, OPT_PROV_ENUM } OPTION_CHOICE; const OPTIONS gendsa_options[] = { {OPT_HELP_STR, 1, '-', "Usage: %s [options] dsaparam-file\n"}, OPT_SECTION("General"), {"help", OPT_HELP, '-', "Display this summary"}, #ifndef OPENSSL_NO_ENGINE {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"}, #endif OPT_SECTION("Output"), {"out", OPT_OUT, '>', "Output the key to the specified file"}, {"passout", OPT_PASSOUT, 's', "Output file pass phrase source"}, OPT_R_OPTIONS, OPT_PROV_OPTIONS, {"", OPT_CIPHER, '-', "Encrypt the output with any supported cipher"}, {"verbose", OPT_VERBOSE, '-', "Verbose output"}, OPT_PARAMETERS(), {"dsaparam-file", 0, 0, "File containing DSA parameters"}, {NULL} }; int gendsa_main(int argc, char **argv) { ENGINE *e = NULL; BIO *out = NULL, *in = NULL; EVP_PKEY *pkey = NULL; EVP_PKEY_CTX *ctx = NULL; EVP_CIPHER *enc = NULL; char *dsaparams = NULL, *ciphername = NULL; char *outfile = NULL, *passoutarg = NULL, *passout = NULL, *prog; OPTION_CHOICE o; int ret = 1, private = 0, verbose = 0, nbits; prog = opt_init(argc, argv, gendsa_options); while ((o = opt_next()) != OPT_EOF) { switch (o) { case OPT_EOF: case OPT_ERR: opthelp: BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); goto end; case OPT_HELP: ret = 0; opt_help(gendsa_options); goto end; case OPT_OUT: outfile = opt_arg(); break; case OPT_PASSOUT: passoutarg = opt_arg(); break; case OPT_ENGINE: e = setup_engine(opt_arg(), 0); break; case OPT_R_CASES: if (!opt_rand(o)) goto end; break; case OPT_PROV_CASES: if (!opt_provider(o)) goto end; break; case OPT_CIPHER: ciphername = opt_unknown(); break; case OPT_VERBOSE: verbose = 1; break; } } /* One argument, the params file. */ argc = opt_num_rest(); argv = opt_rest(); if (argc != 1) goto opthelp; dsaparams = argv[0]; if (!app_RAND_load()) goto end; if (ciphername != NULL) { if (!opt_cipher(ciphername, &enc)) goto end; } private = 1; if (!app_passwd(NULL, passoutarg, NULL, &passout)) { BIO_printf(bio_err, "Error getting password\n"); goto end; } pkey = load_keyparams(dsaparams, FORMAT_UNDEF, 1, "DSA", "DSA parameters"); out = bio_open_owner(outfile, FORMAT_PEM, private); if (out == NULL) goto end2; nbits = EVP_PKEY_get_bits(pkey); if (nbits > OPENSSL_DSA_MAX_MODULUS_BITS) BIO_printf(bio_err, "Warning: It is not recommended to use more than %d bit for DSA keys.\n" " Your key size is %d! Larger key size may behave not as expected.\n", OPENSSL_DSA_MAX_MODULUS_BITS, EVP_PKEY_get_bits(pkey)); ctx = EVP_PKEY_CTX_new_from_pkey(app_get0_libctx(), pkey, app_get0_propq()); if (ctx == NULL) { BIO_printf(bio_err, "unable to create PKEY context\n"); goto end; } EVP_PKEY_free(pkey); pkey = NULL; if (EVP_PKEY_keygen_init(ctx) <= 0) { BIO_printf(bio_err, "unable to set up for key generation\n"); goto end; } pkey = app_keygen(ctx, "DSA", nbits, verbose); + if (pkey == NULL) + goto end; assert(private); if (!PEM_write_bio_PrivateKey(out, pkey, enc, NULL, 0, NULL, passout)) { BIO_printf(bio_err, "unable to output generated key\n"); goto end; } ret = 0; end: if (ret != 0) ERR_print_errors(bio_err); end2: BIO_free(in); BIO_free_all(out); EVP_PKEY_free(pkey); EVP_PKEY_CTX_free(ctx); EVP_CIPHER_free(enc); release_engine(e); OPENSSL_free(passout); return ret; } diff --git a/crypto/openssl/apps/genpkey.c b/crypto/openssl/apps/genpkey.c index d00754eeaca0..705e5c76b47d 100644 --- a/crypto/openssl/apps/genpkey.c +++ b/crypto/openssl/apps/genpkey.c @@ -1,342 +1,344 @@ /* - * Copyright 2006-2021 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2006-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ #include #include #include "apps.h" #include "progs.h" #include #include #include static int quiet; static int init_keygen_file(EVP_PKEY_CTX **pctx, const char *file, ENGINE *e, OSSL_LIB_CTX *libctx, const char *propq); static int genpkey_cb(EVP_PKEY_CTX *ctx); typedef enum OPTION_choice { OPT_COMMON, OPT_ENGINE, OPT_OUTFORM, OPT_OUT, OPT_PASS, OPT_PARAMFILE, OPT_ALGORITHM, OPT_PKEYOPT, OPT_GENPARAM, OPT_TEXT, OPT_CIPHER, OPT_QUIET, OPT_CONFIG, OPT_PROV_ENUM } OPTION_CHOICE; const OPTIONS genpkey_options[] = { OPT_SECTION("General"), {"help", OPT_HELP, '-', "Display this summary"}, #ifndef OPENSSL_NO_ENGINE {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"}, #endif {"paramfile", OPT_PARAMFILE, '<', "Parameters file"}, {"algorithm", OPT_ALGORITHM, 's', "The public key algorithm"}, {"quiet", OPT_QUIET, '-', "Do not output status while generating keys"}, {"pkeyopt", OPT_PKEYOPT, 's', "Set the public key algorithm option as opt:value"}, OPT_CONFIG_OPTION, OPT_SECTION("Output"), {"out", OPT_OUT, '>', "Output file"}, {"outform", OPT_OUTFORM, 'F', "output format (DER or PEM)"}, {"pass", OPT_PASS, 's', "Output file pass phrase source"}, {"genparam", OPT_GENPARAM, '-', "Generate parameters, not key"}, {"text", OPT_TEXT, '-', "Print the in text"}, {"", OPT_CIPHER, '-', "Cipher to use to encrypt the key"}, OPT_PROV_OPTIONS, /* This is deliberately last. */ {OPT_HELP_STR, 1, 1, "Order of options may be important! See the documentation.\n"}, {NULL} }; int genpkey_main(int argc, char **argv) { CONF *conf = NULL; BIO *in = NULL, *out = NULL; ENGINE *e = NULL; EVP_PKEY *pkey = NULL; EVP_PKEY_CTX *ctx = NULL; char *outfile = NULL, *passarg = NULL, *pass = NULL, *prog, *p; const char *ciphername = NULL, *paramfile = NULL, *algname = NULL; EVP_CIPHER *cipher = NULL; OPTION_CHOICE o; int outformat = FORMAT_PEM, text = 0, ret = 1, rv, do_param = 0; int private = 0, i; OSSL_LIB_CTX *libctx = app_get0_libctx(); STACK_OF(OPENSSL_STRING) *keyopt = NULL; prog = opt_init(argc, argv, genpkey_options); keyopt = sk_OPENSSL_STRING_new_null(); if (keyopt == NULL) goto end; while ((o = opt_next()) != OPT_EOF) { switch (o) { case OPT_EOF: case OPT_ERR: opthelp: BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); goto end; case OPT_HELP: ret = 0; opt_help(genpkey_options); goto end; case OPT_OUTFORM: if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &outformat)) goto opthelp; break; case OPT_OUT: outfile = opt_arg(); break; case OPT_PASS: passarg = opt_arg(); break; case OPT_ENGINE: e = setup_engine(opt_arg(), 0); break; case OPT_PARAMFILE: if (do_param == 1) goto opthelp; paramfile = opt_arg(); break; case OPT_ALGORITHM: algname = opt_arg(); break; case OPT_PKEYOPT: if (!sk_OPENSSL_STRING_push(keyopt, opt_arg())) goto end; break; case OPT_QUIET: quiet = 1; break; case OPT_GENPARAM: do_param = 1; break; case OPT_TEXT: text = 1; break; case OPT_CIPHER: ciphername = opt_unknown(); break; case OPT_CONFIG: conf = app_load_config_modules(opt_arg()); if (conf == NULL) goto end; break; case OPT_PROV_CASES: if (!opt_provider(o)) goto end; break; } } /* No extra arguments. */ argc = opt_num_rest(); if (argc != 0) goto opthelp; /* Fetch cipher, etc. */ if (paramfile != NULL) { if (!init_keygen_file(&ctx, paramfile, e, libctx, app_get0_propq())) goto end; } if (algname != NULL) { if (!init_gen_str(&ctx, algname, e, do_param, libctx, app_get0_propq())) goto end; } if (ctx == NULL) goto opthelp; for (i = 0; i < sk_OPENSSL_STRING_num(keyopt); i++) { p = sk_OPENSSL_STRING_value(keyopt, i); if (pkey_ctrl_string(ctx, p) <= 0) { BIO_printf(bio_err, "%s: Error setting %s parameter:\n", prog, p); ERR_print_errors(bio_err); goto end; } } if (ciphername != NULL) if (!opt_cipher(ciphername, &cipher) || do_param == 1) goto opthelp; private = do_param ? 0 : 1; if (!app_passwd(passarg, NULL, &pass, NULL)) { BIO_puts(bio_err, "Error getting password\n"); goto end; } out = bio_open_owner(outfile, outformat, private); if (out == NULL) goto end; EVP_PKEY_CTX_set_cb(ctx, genpkey_cb); EVP_PKEY_CTX_set_app_data(ctx, bio_err); pkey = do_param ? app_paramgen(ctx, algname) : app_keygen(ctx, algname, 0, 0 /* not verbose */); + if (pkey == NULL) + goto end; if (do_param) { rv = PEM_write_bio_Parameters(out, pkey); } else if (outformat == FORMAT_PEM) { assert(private); rv = PEM_write_bio_PrivateKey(out, pkey, cipher, NULL, 0, NULL, pass); } else if (outformat == FORMAT_ASN1) { assert(private); rv = i2d_PrivateKey_bio(out, pkey); } else { BIO_printf(bio_err, "Bad format specified for key\n"); goto end; } ret = 0; if (rv <= 0) { BIO_puts(bio_err, "Error writing key\n"); ret = 1; } if (text) { if (do_param) rv = EVP_PKEY_print_params(out, pkey, 0, NULL); else rv = EVP_PKEY_print_private(out, pkey, 0, NULL); if (rv <= 0) { BIO_puts(bio_err, "Error printing key\n"); ret = 1; } } end: sk_OPENSSL_STRING_free(keyopt); if (ret != 0) ERR_print_errors(bio_err); EVP_PKEY_free(pkey); EVP_PKEY_CTX_free(ctx); EVP_CIPHER_free(cipher); BIO_free_all(out); BIO_free(in); release_engine(e); OPENSSL_free(pass); NCONF_free(conf); return ret; } static int init_keygen_file(EVP_PKEY_CTX **pctx, const char *file, ENGINE *e, OSSL_LIB_CTX *libctx, const char *propq) { BIO *pbio; EVP_PKEY *pkey = NULL; EVP_PKEY_CTX *ctx = NULL; if (*pctx) { BIO_puts(bio_err, "Parameters already set!\n"); return 0; } pbio = BIO_new_file(file, "r"); if (pbio == NULL) { BIO_printf(bio_err, "Can't open parameter file %s\n", file); return 0; } pkey = PEM_read_bio_Parameters_ex(pbio, NULL, libctx, propq); BIO_free(pbio); if (pkey == NULL) { BIO_printf(bio_err, "Error reading parameter file %s\n", file); return 0; } if (e != NULL) ctx = EVP_PKEY_CTX_new(pkey, e); else ctx = EVP_PKEY_CTX_new_from_pkey(libctx, pkey, propq); if (ctx == NULL) goto err; if (EVP_PKEY_keygen_init(ctx) <= 0) goto err; EVP_PKEY_free(pkey); *pctx = ctx; return 1; err: BIO_puts(bio_err, "Error initializing context\n"); ERR_print_errors(bio_err); EVP_PKEY_CTX_free(ctx); EVP_PKEY_free(pkey); return 0; } int init_gen_str(EVP_PKEY_CTX **pctx, const char *algname, ENGINE *e, int do_param, OSSL_LIB_CTX *libctx, const char *propq) { EVP_PKEY_CTX *ctx = NULL; int pkey_id; if (*pctx) { BIO_puts(bio_err, "Algorithm already set!\n"); return 0; } pkey_id = get_legacy_pkey_id(libctx, algname, e); if (pkey_id != NID_undef) ctx = EVP_PKEY_CTX_new_id(pkey_id, e); else ctx = EVP_PKEY_CTX_new_from_name(libctx, algname, propq); if (ctx == NULL) goto err; if (do_param) { if (EVP_PKEY_paramgen_init(ctx) <= 0) goto err; } else { if (EVP_PKEY_keygen_init(ctx) <= 0) goto err; } *pctx = ctx; return 1; err: BIO_printf(bio_err, "Error initializing %s context\n", algname); ERR_print_errors(bio_err); EVP_PKEY_CTX_free(ctx); return 0; } static int genpkey_cb(EVP_PKEY_CTX *ctx) { char c = '*'; BIO *b = EVP_PKEY_CTX_get_app_data(ctx); if (quiet) return 1; switch (EVP_PKEY_CTX_get_keygen_info(ctx, 0)) { case 0: c = '.'; break; case 1: c = '+'; break; case 3: c = '\n'; break; } BIO_write(b, &c, 1); (void)BIO_flush(b); return 1; } diff --git a/crypto/openssl/apps/genrsa.c b/crypto/openssl/apps/genrsa.c index 4436b7fa1745..6a683517a15f 100644 --- a/crypto/openssl/apps/genrsa.c +++ b/crypto/openssl/apps/genrsa.c @@ -1,269 +1,271 @@ /* - * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ #include #include #include #include #include #include "apps.h" #include "progs.h" #include #include #include #include #include #include #include #include #define DEFBITS 2048 #define DEFPRIMES 2 static int verbose = 0; static int genrsa_cb(EVP_PKEY_CTX *ctx); typedef enum OPTION_choice { OPT_COMMON, #ifndef OPENSSL_NO_DEPRECATED_3_0 OPT_3, #endif OPT_F4, OPT_ENGINE, OPT_OUT, OPT_PASSOUT, OPT_CIPHER, OPT_PRIMES, OPT_VERBOSE, OPT_R_ENUM, OPT_PROV_ENUM, OPT_TRADITIONAL } OPTION_CHOICE; const OPTIONS genrsa_options[] = { {OPT_HELP_STR, 1, '-', "Usage: %s [options] numbits\n"}, OPT_SECTION("General"), {"help", OPT_HELP, '-', "Display this summary"}, #ifndef OPENSSL_NO_ENGINE {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"}, #endif OPT_SECTION("Input"), #ifndef OPENSSL_NO_DEPRECATED_3_0 {"3", OPT_3, '-', "(deprecated) Use 3 for the E value"}, #endif {"F4", OPT_F4, '-', "Use the Fermat number F4 (0x10001) for the E value"}, {"f4", OPT_F4, '-', "Use the Fermat number F4 (0x10001) for the E value"}, OPT_SECTION("Output"), {"out", OPT_OUT, '>', "Output the key to specified file"}, {"passout", OPT_PASSOUT, 's', "Output file pass phrase source"}, {"primes", OPT_PRIMES, 'p', "Specify number of primes"}, {"verbose", OPT_VERBOSE, '-', "Verbose output"}, {"traditional", OPT_TRADITIONAL, '-', "Use traditional format for private keys"}, {"", OPT_CIPHER, '-', "Encrypt the output with any supported cipher"}, OPT_R_OPTIONS, OPT_PROV_OPTIONS, OPT_PARAMETERS(), {"numbits", 0, 0, "Size of key in bits"}, {NULL} }; int genrsa_main(int argc, char **argv) { BN_GENCB *cb = BN_GENCB_new(); ENGINE *eng = NULL; BIGNUM *bn = BN_new(); BIO *out = NULL; EVP_PKEY *pkey = NULL; EVP_PKEY_CTX *ctx = NULL; EVP_CIPHER *enc = NULL; int ret = 1, num = DEFBITS, private = 0, primes = DEFPRIMES; unsigned long f4 = RSA_F4; char *outfile = NULL, *passoutarg = NULL, *passout = NULL; char *prog, *hexe, *dece, *ciphername = NULL; OPTION_CHOICE o; int traditional = 0; if (bn == NULL || cb == NULL) goto end; prog = opt_init(argc, argv, genrsa_options); while ((o = opt_next()) != OPT_EOF) { switch (o) { case OPT_EOF: case OPT_ERR: opthelp: BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); goto end; case OPT_HELP: ret = 0; opt_help(genrsa_options); goto end; #ifndef OPENSSL_NO_DEPRECATED_3_0 case OPT_3: f4 = RSA_3; break; #endif case OPT_F4: f4 = RSA_F4; break; case OPT_OUT: outfile = opt_arg(); break; case OPT_ENGINE: eng = setup_engine(opt_arg(), 0); break; case OPT_R_CASES: if (!opt_rand(o)) goto end; break; case OPT_PROV_CASES: if (!opt_provider(o)) goto end; break; case OPT_PASSOUT: passoutarg = opt_arg(); break; case OPT_CIPHER: ciphername = opt_unknown(); break; case OPT_PRIMES: primes = opt_int_arg(); break; case OPT_VERBOSE: verbose = 1; break; case OPT_TRADITIONAL: traditional = 1; break; } } /* One optional argument, the bitsize. */ argc = opt_num_rest(); argv = opt_rest(); if (argc == 1) { if (!opt_int(argv[0], &num) || num <= 0) goto end; if (num > OPENSSL_RSA_MAX_MODULUS_BITS) BIO_printf(bio_err, "Warning: It is not recommended to use more than %d bit for RSA keys.\n" " Your key size is %d! Larger key size may behave not as expected.\n", OPENSSL_RSA_MAX_MODULUS_BITS, num); } else if (argc > 0) { BIO_printf(bio_err, "Extra arguments given.\n"); goto opthelp; } if (!app_RAND_load()) goto end; private = 1; if (ciphername != NULL) { if (!opt_cipher(ciphername, &enc)) goto end; } if (!app_passwd(NULL, passoutarg, NULL, &passout)) { BIO_printf(bio_err, "Error getting password\n"); goto end; } out = bio_open_owner(outfile, FORMAT_PEM, private); if (out == NULL) goto end; if (!init_gen_str(&ctx, "RSA", eng, 0, app_get0_libctx(), app_get0_propq())) goto end; EVP_PKEY_CTX_set_cb(ctx, genrsa_cb); EVP_PKEY_CTX_set_app_data(ctx, bio_err); if (EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, num) <= 0) { BIO_printf(bio_err, "Error setting RSA length\n"); goto end; } if (!BN_set_word(bn, f4)) { BIO_printf(bio_err, "Error allocating RSA public exponent\n"); goto end; } if (EVP_PKEY_CTX_set1_rsa_keygen_pubexp(ctx, bn) <= 0) { BIO_printf(bio_err, "Error setting RSA public exponent\n"); goto end; } if (EVP_PKEY_CTX_set_rsa_keygen_primes(ctx, primes) <= 0) { BIO_printf(bio_err, "Error setting number of primes\n"); goto end; } pkey = app_keygen(ctx, "RSA", num, verbose); + if (pkey == NULL) + goto end; if (verbose) { BIGNUM *e = NULL; /* Every RSA key has an 'e' */ EVP_PKEY_get_bn_param(pkey, "e", &e); if (e == NULL) { BIO_printf(bio_err, "Error cannot access RSA e\n"); goto end; } hexe = BN_bn2hex(e); dece = BN_bn2dec(e); if (hexe && dece) { BIO_printf(bio_err, "e is %s (0x%s)\n", dece, hexe); } OPENSSL_free(hexe); OPENSSL_free(dece); BN_free(e); } if (traditional) { if (!PEM_write_bio_PrivateKey_traditional(out, pkey, enc, NULL, 0, NULL, passout)) goto end; } else { if (!PEM_write_bio_PrivateKey(out, pkey, enc, NULL, 0, NULL, passout)) goto end; } ret = 0; end: BN_free(bn); BN_GENCB_free(cb); EVP_PKEY_CTX_free(ctx); EVP_PKEY_free(pkey); EVP_CIPHER_free(enc); BIO_free_all(out); release_engine(eng); OPENSSL_free(passout); if (ret != 0) ERR_print_errors(bio_err); return ret; } static int genrsa_cb(EVP_PKEY_CTX *ctx) { char c = '*'; BIO *b = EVP_PKEY_CTX_get_app_data(ctx); int p = EVP_PKEY_CTX_get_keygen_info(ctx, 0); if (!verbose) return 1; if (p == 0) c = '.'; if (p == 1) c = '+'; if (p == 2) c = '*'; if (p == 3) c = '\n'; BIO_write(b, &c, 1); (void)BIO_flush(b); return 1; } diff --git a/crypto/openssl/apps/lib/apps.c b/crypto/openssl/apps/lib/apps.c index 572f6a3f8f28..a632b0cff2bf 100644 --- a/crypto/openssl/apps/lib/apps.c +++ b/crypto/openssl/apps/lib/apps.c @@ -1,3396 +1,3400 @@ /* * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ #if !defined(_POSIX_C_SOURCE) && defined(OPENSSL_SYS_VMS) /* * On VMS, you need to define this to get the declaration of fileno(). The * value 2 is to make sure no function defined in POSIX-2 is left undefined. */ # define _POSIX_C_SOURCE 2 #endif #ifndef OPENSSL_NO_ENGINE /* We need to use some deprecated APIs */ # define OPENSSL_SUPPRESS_DEPRECATED # include #endif #include #include #include #include #ifndef OPENSSL_NO_POSIX_IO # include # include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "s_apps.h" #include "apps.h" #ifdef _WIN32 static int WIN32_rename(const char *from, const char *to); # define rename(from,to) WIN32_rename((from),(to)) #endif #if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) # include #endif #if defined(OPENSSL_SYS_MSDOS) && !defined(_WIN32) || defined(__BORLANDC__) # define _kbhit kbhit #endif static BIO *bio_open_default_(const char *filename, char mode, int format, int quiet); #define PASS_SOURCE_SIZE_MAX 4 DEFINE_STACK_OF(CONF) typedef struct { const char *name; unsigned long flag; unsigned long mask; } NAME_EX_TBL; static int set_table_opts(unsigned long *flags, const char *arg, const NAME_EX_TBL * in_tbl); static int set_multi_opts(unsigned long *flags, const char *arg, const NAME_EX_TBL * in_tbl); static int load_key_certs_crls_suppress(const char *uri, int format, int maybe_stdin, const char *pass, const char *desc, EVP_PKEY **ppkey, EVP_PKEY **ppubkey, EVP_PKEY **pparams, X509 **pcert, STACK_OF(X509) **pcerts, X509_CRL **pcrl, STACK_OF(X509_CRL) **pcrls, int suppress_decode_errors); int app_init(long mesgwin); int chopup_args(ARGS *arg, char *buf) { int quoted; char c = '\0', *p = NULL; arg->argc = 0; if (arg->size == 0) { arg->size = 20; arg->argv = app_malloc(sizeof(*arg->argv) * arg->size, "argv space"); } for (p = buf;;) { /* Skip whitespace. */ while (*p && isspace(_UC(*p))) p++; if (*p == '\0') break; /* The start of something good :-) */ if (arg->argc >= arg->size) { char **tmp; arg->size += 20; tmp = OPENSSL_realloc(arg->argv, sizeof(*arg->argv) * arg->size); if (tmp == NULL) return 0; arg->argv = tmp; } quoted = *p == '\'' || *p == '"'; if (quoted) c = *p++; arg->argv[arg->argc++] = p; /* now look for the end of this */ if (quoted) { while (*p && *p != c) p++; *p++ = '\0'; } else { while (*p && !isspace(_UC(*p))) p++; if (*p) *p++ = '\0'; } } arg->argv[arg->argc] = NULL; return 1; } #ifndef APP_INIT int app_init(long mesgwin) { return 1; } #endif int ctx_set_verify_locations(SSL_CTX *ctx, const char *CAfile, int noCAfile, const char *CApath, int noCApath, const char *CAstore, int noCAstore) { if (CAfile == NULL && CApath == NULL && CAstore == NULL) { if (!noCAfile && SSL_CTX_set_default_verify_file(ctx) <= 0) return 0; if (!noCApath && SSL_CTX_set_default_verify_dir(ctx) <= 0) return 0; if (!noCAstore && SSL_CTX_set_default_verify_store(ctx) <= 0) return 0; return 1; } if (CAfile != NULL && !SSL_CTX_load_verify_file(ctx, CAfile)) return 0; if (CApath != NULL && !SSL_CTX_load_verify_dir(ctx, CApath)) return 0; if (CAstore != NULL && !SSL_CTX_load_verify_store(ctx, CAstore)) return 0; return 1; } #ifndef OPENSSL_NO_CT int ctx_set_ctlog_list_file(SSL_CTX *ctx, const char *path) { if (path == NULL) return SSL_CTX_set_default_ctlog_list_file(ctx); return SSL_CTX_set_ctlog_list_file(ctx, path); } #endif static unsigned long nmflag = 0; static char nmflag_set = 0; int set_nameopt(const char *arg) { int ret = set_name_ex(&nmflag, arg); if (ret) nmflag_set = 1; return ret; } unsigned long get_nameopt(void) { return (nmflag_set) ? nmflag : XN_FLAG_ONELINE; } void dump_cert_text(BIO *out, X509 *x) { print_name(out, "subject=", X509_get_subject_name(x)); print_name(out, "issuer=", X509_get_issuer_name(x)); } int wrap_password_callback(char *buf, int bufsiz, int verify, void *userdata) { return password_callback(buf, bufsiz, verify, (PW_CB_DATA *)userdata); } static char *app_get_pass(const char *arg, int keepbio); char *get_passwd(const char *pass, const char *desc) { char *result = NULL; if (desc == NULL) desc = ""; if (!app_passwd(pass, NULL, &result, NULL)) BIO_printf(bio_err, "Error getting password for %s\n", desc); if (pass != NULL && result == NULL) { BIO_printf(bio_err, "Trying plain input string (better precede with 'pass:')\n"); result = OPENSSL_strdup(pass); if (result == NULL) BIO_printf(bio_err, "Out of memory getting password for %s\n", desc); } return result; } int app_passwd(const char *arg1, const char *arg2, char **pass1, char **pass2) { int same = arg1 != NULL && arg2 != NULL && strcmp(arg1, arg2) == 0; if (arg1 != NULL) { *pass1 = app_get_pass(arg1, same); if (*pass1 == NULL) return 0; } else if (pass1 != NULL) { *pass1 = NULL; } if (arg2 != NULL) { *pass2 = app_get_pass(arg2, same ? 2 : 0); if (*pass2 == NULL) return 0; } else if (pass2 != NULL) { *pass2 = NULL; } return 1; } static char *app_get_pass(const char *arg, int keepbio) { static BIO *pwdbio = NULL; char *tmp, tpass[APP_PASS_LEN]; int i; /* PASS_SOURCE_SIZE_MAX = max number of chars before ':' in below strings */ if (strncmp(arg, "pass:", 5) == 0) return OPENSSL_strdup(arg + 5); if (strncmp(arg, "env:", 4) == 0) { tmp = getenv(arg + 4); if (tmp == NULL) { BIO_printf(bio_err, "No environment variable %s\n", arg + 4); return NULL; } return OPENSSL_strdup(tmp); } if (!keepbio || pwdbio == NULL) { if (strncmp(arg, "file:", 5) == 0) { pwdbio = BIO_new_file(arg + 5, "r"); if (pwdbio == NULL) { BIO_printf(bio_err, "Can't open file %s\n", arg + 5); return NULL; } #if !defined(_WIN32) /* * Under _WIN32, which covers even Win64 and CE, file * descriptors referenced by BIO_s_fd are not inherited * by child process and therefore below is not an option. * It could have been an option if bss_fd.c was operating * on real Windows descriptors, such as those obtained * with CreateFile. */ } else if (strncmp(arg, "fd:", 3) == 0) { BIO *btmp; i = atoi(arg + 3); if (i >= 0) pwdbio = BIO_new_fd(i, BIO_NOCLOSE); if ((i < 0) || pwdbio == NULL) { BIO_printf(bio_err, "Can't access file descriptor %s\n", arg + 3); return NULL; } /* * Can't do BIO_gets on an fd BIO so add a buffering BIO */ btmp = BIO_new(BIO_f_buffer()); if (btmp == NULL) { BIO_free_all(pwdbio); pwdbio = NULL; BIO_printf(bio_err, "Out of memory\n"); return NULL; } pwdbio = BIO_push(btmp, pwdbio); #endif } else if (strcmp(arg, "stdin") == 0) { unbuffer(stdin); pwdbio = dup_bio_in(FORMAT_TEXT); if (pwdbio == NULL) { BIO_printf(bio_err, "Can't open BIO for stdin\n"); return NULL; } } else { /* argument syntax error; do not reveal too much about arg */ tmp = strchr(arg, ':'); if (tmp == NULL || tmp - arg > PASS_SOURCE_SIZE_MAX) BIO_printf(bio_err, "Invalid password argument, missing ':' within the first %d chars\n", PASS_SOURCE_SIZE_MAX + 1); else BIO_printf(bio_err, "Invalid password argument, starting with \"%.*s\"\n", (int)(tmp - arg + 1), arg); return NULL; } } i = BIO_gets(pwdbio, tpass, APP_PASS_LEN); if (keepbio != 1) { BIO_free_all(pwdbio); pwdbio = NULL; } if (i <= 0) { BIO_printf(bio_err, "Error reading password from BIO\n"); return NULL; } tmp = strchr(tpass, '\n'); if (tmp != NULL) *tmp = 0; return OPENSSL_strdup(tpass); } CONF *app_load_config_bio(BIO *in, const char *filename) { long errorline = -1; CONF *conf; int i; conf = NCONF_new_ex(app_get0_libctx(), NULL); i = NCONF_load_bio(conf, in, &errorline); if (i > 0) return conf; if (errorline <= 0) { BIO_printf(bio_err, "%s: Can't load ", opt_getprog()); } else { BIO_printf(bio_err, "%s: Error on line %ld of ", opt_getprog(), errorline); } if (filename != NULL) BIO_printf(bio_err, "config file \"%s\"\n", filename); else BIO_printf(bio_err, "config input"); NCONF_free(conf); return NULL; } CONF *app_load_config_verbose(const char *filename, int verbose) { if (verbose) { if (*filename == '\0') BIO_printf(bio_err, "No configuration used\n"); else BIO_printf(bio_err, "Using configuration from %s\n", filename); } return app_load_config_internal(filename, 0); } CONF *app_load_config_internal(const char *filename, int quiet) { BIO *in; CONF *conf; if (filename == NULL || *filename != '\0') { if ((in = bio_open_default_(filename, 'r', FORMAT_TEXT, quiet)) == NULL) return NULL; conf = app_load_config_bio(in, filename); BIO_free(in); } else { /* Return empty config if filename is empty string. */ conf = NCONF_new_ex(app_get0_libctx(), NULL); } return conf; } int app_load_modules(const CONF *config) { CONF *to_free = NULL; if (config == NULL) config = to_free = app_load_config_quiet(default_config_file); if (config == NULL) return 1; if (CONF_modules_load(config, NULL, 0) <= 0) { BIO_printf(bio_err, "Error configuring OpenSSL modules\n"); ERR_print_errors(bio_err); NCONF_free(to_free); return 0; } NCONF_free(to_free); return 1; } int add_oid_section(CONF *conf) { char *p; STACK_OF(CONF_VALUE) *sktmp; CONF_VALUE *cnf; int i; if ((p = NCONF_get_string(conf, NULL, "oid_section")) == NULL) { ERR_clear_error(); return 1; } if ((sktmp = NCONF_get_section(conf, p)) == NULL) { BIO_printf(bio_err, "problem loading oid section %s\n", p); return 0; } for (i = 0; i < sk_CONF_VALUE_num(sktmp); i++) { cnf = sk_CONF_VALUE_value(sktmp, i); if (OBJ_create(cnf->value, cnf->name, cnf->name) == NID_undef) { BIO_printf(bio_err, "problem creating object %s=%s\n", cnf->name, cnf->value); return 0; } } return 1; } CONF *app_load_config_modules(const char *configfile) { CONF *conf = NULL; if (configfile != NULL) { if ((conf = app_load_config_verbose(configfile, 1)) == NULL) return NULL; if (configfile != default_config_file && !app_load_modules(conf)) { NCONF_free(conf); conf = NULL; } } return conf; } #define IS_HTTP(uri) ((uri) != NULL \ && strncmp(uri, OSSL_HTTP_PREFIX, strlen(OSSL_HTTP_PREFIX)) == 0) #define IS_HTTPS(uri) ((uri) != NULL \ && strncmp(uri, OSSL_HTTPS_PREFIX, strlen(OSSL_HTTPS_PREFIX)) == 0) X509 *load_cert_pass(const char *uri, int format, int maybe_stdin, const char *pass, const char *desc) { X509 *cert = NULL; if (desc == NULL) desc = "certificate"; if (IS_HTTPS(uri)) BIO_printf(bio_err, "Loading %s over HTTPS is unsupported\n", desc); else if (IS_HTTP(uri)) cert = X509_load_http(uri, NULL, NULL, 0 /* timeout */); else (void)load_key_certs_crls(uri, format, maybe_stdin, pass, desc, NULL, NULL, NULL, &cert, NULL, NULL, NULL); if (cert == NULL) { BIO_printf(bio_err, "Unable to load %s\n", desc); ERR_print_errors(bio_err); } return cert; } X509_CRL *load_crl(const char *uri, int format, int maybe_stdin, const char *desc) { X509_CRL *crl = NULL; if (desc == NULL) desc = "CRL"; if (IS_HTTPS(uri)) BIO_printf(bio_err, "Loading %s over HTTPS is unsupported\n", desc); else if (IS_HTTP(uri)) crl = X509_CRL_load_http(uri, NULL, NULL, 0 /* timeout */); else (void)load_key_certs_crls(uri, format, maybe_stdin, NULL, desc, NULL, NULL, NULL, NULL, NULL, &crl, NULL); if (crl == NULL) { BIO_printf(bio_err, "Unable to load %s\n", desc); ERR_print_errors(bio_err); } return crl; } X509_REQ *load_csr(const char *file, int format, const char *desc) { X509_REQ *req = NULL; BIO *in; if (format == FORMAT_UNDEF) format = FORMAT_PEM; if (desc == NULL) desc = "CSR"; in = bio_open_default(file, 'r', format); if (in == NULL) goto end; if (format == FORMAT_ASN1) req = d2i_X509_REQ_bio(in, NULL); else if (format == FORMAT_PEM) req = PEM_read_bio_X509_REQ(in, NULL, NULL, NULL); else print_format_error(format, OPT_FMT_PEMDER); end: if (req == NULL) { BIO_printf(bio_err, "Unable to load %s\n", desc); ERR_print_errors(bio_err); } BIO_free(in); return req; } void cleanse(char *str) { if (str != NULL) OPENSSL_cleanse(str, strlen(str)); } void clear_free(char *str) { if (str != NULL) OPENSSL_clear_free(str, strlen(str)); } EVP_PKEY *load_key(const char *uri, int format, int may_stdin, const char *pass, ENGINE *e, const char *desc) { EVP_PKEY *pkey = NULL; char *allocated_uri = NULL; if (desc == NULL) desc = "private key"; if (format == FORMAT_ENGINE) { uri = allocated_uri = make_engine_uri(e, uri, desc); } (void)load_key_certs_crls(uri, format, may_stdin, pass, desc, &pkey, NULL, NULL, NULL, NULL, NULL, NULL); OPENSSL_free(allocated_uri); return pkey; } EVP_PKEY *load_pubkey(const char *uri, int format, int maybe_stdin, const char *pass, ENGINE *e, const char *desc) { EVP_PKEY *pkey = NULL; char *allocated_uri = NULL; if (desc == NULL) desc = "public key"; if (format == FORMAT_ENGINE) { uri = allocated_uri = make_engine_uri(e, uri, desc); } (void)load_key_certs_crls(uri, format, maybe_stdin, pass, desc, NULL, &pkey, NULL, NULL, NULL, NULL, NULL); OPENSSL_free(allocated_uri); return pkey; } EVP_PKEY *load_keyparams_suppress(const char *uri, int format, int maybe_stdin, const char *keytype, const char *desc, int suppress_decode_errors) { EVP_PKEY *params = NULL; if (desc == NULL) desc = "key parameters"; (void)load_key_certs_crls_suppress(uri, format, maybe_stdin, NULL, desc, NULL, NULL, ¶ms, NULL, NULL, NULL, NULL, suppress_decode_errors); if (params != NULL && keytype != NULL && !EVP_PKEY_is_a(params, keytype)) { if (!suppress_decode_errors) { BIO_printf(bio_err, "Unable to load %s from %s (unexpected parameters type)\n", desc, uri); ERR_print_errors(bio_err); } EVP_PKEY_free(params); params = NULL; } return params; } EVP_PKEY *load_keyparams(const char *uri, int format, int maybe_stdin, const char *keytype, const char *desc) { return load_keyparams_suppress(uri, format, maybe_stdin, keytype, desc, 0); } void app_bail_out(char *fmt, ...) { va_list args; va_start(args, fmt); BIO_vprintf(bio_err, fmt, args); va_end(args); ERR_print_errors(bio_err); exit(EXIT_FAILURE); } void *app_malloc(size_t sz, const char *what) { void *vp = OPENSSL_malloc(sz); if (vp == NULL) app_bail_out("%s: Could not allocate %zu bytes for %s\n", opt_getprog(), sz, what); return vp; } char *next_item(char *opt) /* in list separated by comma and/or space */ { /* advance to separator (comma or whitespace), if any */ while (*opt != ',' && !isspace(_UC(*opt)) && *opt != '\0') opt++; if (*opt != '\0') { /* terminate current item */ *opt++ = '\0'; /* skip over any whitespace after separator */ while (isspace(_UC(*opt))) opt++; } return *opt == '\0' ? NULL : opt; /* NULL indicates end of input */ } static void warn_cert_msg(const char *uri, X509 *cert, const char *msg) { char *subj = X509_NAME_oneline(X509_get_subject_name(cert), NULL, 0); BIO_printf(bio_err, "Warning: certificate from '%s' with subject '%s' %s\n", uri, subj, msg); OPENSSL_free(subj); } static void warn_cert(const char *uri, X509 *cert, int warn_EE, X509_VERIFY_PARAM *vpm) { uint32_t ex_flags = X509_get_extension_flags(cert); int res = X509_cmp_timeframe(vpm, X509_get0_notBefore(cert), X509_get0_notAfter(cert)); if (res != 0) warn_cert_msg(uri, cert, res > 0 ? "has expired" : "not yet valid"); if (warn_EE && (ex_flags & EXFLAG_V1) == 0 && (ex_flags & EXFLAG_CA) == 0) warn_cert_msg(uri, cert, "is not a CA cert"); } static void warn_certs(const char *uri, STACK_OF(X509) *certs, int warn_EE, X509_VERIFY_PARAM *vpm) { int i; for (i = 0; i < sk_X509_num(certs); i++) warn_cert(uri, sk_X509_value(certs, i), warn_EE, vpm); } int load_cert_certs(const char *uri, X509 **pcert, STACK_OF(X509) **pcerts, int exclude_http, const char *pass, const char *desc, X509_VERIFY_PARAM *vpm) { int ret = 0; char *pass_string; if (exclude_http && (OPENSSL_strncasecmp(uri, "http://", 7) == 0 || OPENSSL_strncasecmp(uri, "https://", 8) == 0)) { BIO_printf(bio_err, "error: HTTP retrieval not allowed for %s\n", desc); return ret; } pass_string = get_passwd(pass, desc); ret = load_key_certs_crls(uri, FORMAT_UNDEF, 0, pass_string, desc, NULL, NULL, NULL, pcert, pcerts, NULL, NULL); clear_free(pass_string); if (ret) { if (pcert != NULL) warn_cert(uri, *pcert, 0, vpm); if (pcerts != NULL) warn_certs(uri, *pcerts, 1, vpm); } else { if (pcerts != NULL) { sk_X509_pop_free(*pcerts, X509_free); *pcerts = NULL; } } return ret; } STACK_OF(X509) *load_certs_multifile(char *files, const char *pass, const char *desc, X509_VERIFY_PARAM *vpm) { STACK_OF(X509) *certs = NULL; STACK_OF(X509) *result = sk_X509_new_null(); if (files == NULL) goto err; if (result == NULL) goto oom; while (files != NULL) { char *next = next_item(files); if (!load_cert_certs(files, NULL, &certs, 0, pass, desc, vpm)) goto err; if (!X509_add_certs(result, certs, X509_ADD_FLAG_UP_REF | X509_ADD_FLAG_NO_DUP)) goto oom; sk_X509_pop_free(certs, X509_free); certs = NULL; files = next; } return result; oom: BIO_printf(bio_err, "out of memory\n"); err: sk_X509_pop_free(certs, X509_free); sk_X509_pop_free(result, X509_free); return NULL; } static X509_STORE *sk_X509_to_store(X509_STORE *store /* may be NULL */, const STACK_OF(X509) *certs /* may NULL */) { int i; if (store == NULL) store = X509_STORE_new(); if (store == NULL) return NULL; for (i = 0; i < sk_X509_num(certs); i++) { if (!X509_STORE_add_cert(store, sk_X509_value(certs, i))) { X509_STORE_free(store); return NULL; } } return store; } /* * Create cert store structure with certificates read from given file(s). * Returns pointer to created X509_STORE on success, NULL on error. */ X509_STORE *load_certstore(char *input, const char *pass, const char *desc, X509_VERIFY_PARAM *vpm) { X509_STORE *store = NULL; STACK_OF(X509) *certs = NULL; while (input != NULL) { char *next = next_item(input); int ok; if (!load_cert_certs(input, NULL, &certs, 1, pass, desc, vpm)) { X509_STORE_free(store); return NULL; } ok = (store = sk_X509_to_store(store, certs)) != NULL; sk_X509_pop_free(certs, X509_free); certs = NULL; if (!ok) return NULL; input = next; } return store; } /* * Initialize or extend, if *certs != NULL, a certificate stack. * The caller is responsible for freeing *certs if its value is left not NULL. */ int load_certs(const char *uri, int maybe_stdin, STACK_OF(X509) **certs, const char *pass, const char *desc) { int was_NULL = *certs == NULL; int ret = load_key_certs_crls(uri, FORMAT_UNDEF, maybe_stdin, pass, desc, NULL, NULL, NULL, NULL, certs, NULL, NULL); if (!ret && was_NULL) { sk_X509_pop_free(*certs, X509_free); *certs = NULL; } return ret; } /* * Initialize or extend, if *crls != NULL, a certificate stack. * The caller is responsible for freeing *crls if its value is left not NULL. */ int load_crls(const char *uri, STACK_OF(X509_CRL) **crls, const char *pass, const char *desc) { int was_NULL = *crls == NULL; int ret = load_key_certs_crls(uri, FORMAT_UNDEF, 0, pass, desc, NULL, NULL, NULL, NULL, NULL, NULL, crls); if (!ret && was_NULL) { sk_X509_CRL_pop_free(*crls, X509_CRL_free); *crls = NULL; } return ret; } static const char *format2string(int format) { switch(format) { case FORMAT_PEM: return "PEM"; case FORMAT_ASN1: return "DER"; } return NULL; } /* Set type expectation, but clear it if objects of different types expected. */ #define SET_EXPECT(expect, val) ((expect) = (expect) < 0 ? (val) : ((expect) == (val) ? (val) : 0)) /* * Load those types of credentials for which the result pointer is not NULL. * Reads from stdio if uri is NULL and maybe_stdin is nonzero. * For non-NULL ppkey, pcert, and pcrl the first suitable value found is loaded. * If pcerts is non-NULL and *pcerts == NULL then a new cert list is allocated. * If pcerts is non-NULL then all available certificates are appended to *pcerts * except any certificate assigned to *pcert. * If pcrls is non-NULL and *pcrls == NULL then a new list of CRLs is allocated. * If pcrls is non-NULL then all available CRLs are appended to *pcerts * except any CRL assigned to *pcrl. * In any case (also on error) the caller is responsible for freeing all members * of *pcerts and *pcrls (as far as they are not NULL). */ static int load_key_certs_crls_suppress(const char *uri, int format, int maybe_stdin, const char *pass, const char *desc, EVP_PKEY **ppkey, EVP_PKEY **ppubkey, EVP_PKEY **pparams, X509 **pcert, STACK_OF(X509) **pcerts, X509_CRL **pcrl, STACK_OF(X509_CRL) **pcrls, int suppress_decode_errors) { PW_CB_DATA uidata; OSSL_STORE_CTX *ctx = NULL; OSSL_LIB_CTX *libctx = app_get0_libctx(); const char *propq = app_get0_propq(); int ncerts = 0; int ncrls = 0; const char *failed = ppkey != NULL ? "key" : ppubkey != NULL ? "public key" : pparams != NULL ? "params" : pcert != NULL ? "cert" : pcrl != NULL ? "CRL" : pcerts != NULL ? "certs" : pcrls != NULL ? "CRLs" : NULL; int cnt_expectations = 0; int expect = -1; const char *input_type; OSSL_PARAM itp[2]; const OSSL_PARAM *params = NULL; if (ppkey != NULL) { *ppkey = NULL; cnt_expectations++; SET_EXPECT(expect, OSSL_STORE_INFO_PKEY); } if (ppubkey != NULL) { *ppubkey = NULL; cnt_expectations++; SET_EXPECT(expect, OSSL_STORE_INFO_PUBKEY); } if (pparams != NULL) { *pparams = NULL; cnt_expectations++; SET_EXPECT(expect, OSSL_STORE_INFO_PARAMS); } if (pcert != NULL) { *pcert = NULL; cnt_expectations++; SET_EXPECT(expect, OSSL_STORE_INFO_CERT); } if (pcerts != NULL) { if (*pcerts == NULL && (*pcerts = sk_X509_new_null()) == NULL) { BIO_printf(bio_err, "Out of memory loading"); goto end; } cnt_expectations++; SET_EXPECT(expect, OSSL_STORE_INFO_CERT); } if (pcrl != NULL) { *pcrl = NULL; cnt_expectations++; SET_EXPECT(expect, OSSL_STORE_INFO_CRL); } if (pcrls != NULL) { if (*pcrls == NULL && (*pcrls = sk_X509_CRL_new_null()) == NULL) { BIO_printf(bio_err, "Out of memory loading"); goto end; } cnt_expectations++; SET_EXPECT(expect, OSSL_STORE_INFO_CRL); } if (cnt_expectations == 0) { BIO_printf(bio_err, "Internal error: nothing to load from %s\n", uri != NULL ? uri : ""); return 0; } uidata.password = pass; uidata.prompt_info = uri; if ((input_type = format2string(format)) != NULL) { itp[0] = OSSL_PARAM_construct_utf8_string(OSSL_STORE_PARAM_INPUT_TYPE, (char *)input_type, 0); itp[1] = OSSL_PARAM_construct_end(); params = itp; } if (uri == NULL) { BIO *bio; if (!maybe_stdin) { BIO_printf(bio_err, "No filename or uri specified for loading\n"); goto end; } uri = ""; unbuffer(stdin); bio = BIO_new_fp(stdin, 0); if (bio != NULL) { ctx = OSSL_STORE_attach(bio, "file", libctx, propq, get_ui_method(), &uidata, params, NULL, NULL); BIO_free(bio); } } else { ctx = OSSL_STORE_open_ex(uri, libctx, propq, get_ui_method(), &uidata, params, NULL, NULL); } - if (ctx == NULL) + if (ctx == NULL) { + BIO_printf(bio_err, "Could not open file or uri for loading"); goto end; - if (expect > 0 && !OSSL_STORE_expect(ctx, expect)) + } + if (expect > 0 && !OSSL_STORE_expect(ctx, expect)) { + BIO_printf(bio_err, "Internal error trying to load"); goto end; + } failed = NULL; while (cnt_expectations > 0 && !OSSL_STORE_eof(ctx)) { OSSL_STORE_INFO *info = OSSL_STORE_load(ctx); int type, ok = 1; /* * This can happen (for example) if we attempt to load a file with * multiple different types of things in it - but the thing we just * tried to load wasn't one of the ones we wanted, e.g. if we're trying * to load a certificate but the file has both the private key and the * certificate in it. We just retry until eof. */ if (info == NULL) { continue; } type = OSSL_STORE_INFO_get_type(info); switch (type) { case OSSL_STORE_INFO_PKEY: if (ppkey != NULL && *ppkey == NULL) { ok = (*ppkey = OSSL_STORE_INFO_get1_PKEY(info)) != NULL; cnt_expectations -= ok; } /* * An EVP_PKEY with private parts also holds the public parts, * so if the caller asked for a public key, and we got a private * key, we can still pass it back. */ if (ok && ppubkey != NULL && *ppubkey == NULL) { ok = ((*ppubkey = OSSL_STORE_INFO_get1_PKEY(info)) != NULL); cnt_expectations -= ok; } break; case OSSL_STORE_INFO_PUBKEY: if (ppubkey != NULL && *ppubkey == NULL) { ok = ((*ppubkey = OSSL_STORE_INFO_get1_PUBKEY(info)) != NULL); cnt_expectations -= ok; } break; case OSSL_STORE_INFO_PARAMS: if (pparams != NULL && *pparams == NULL) { ok = ((*pparams = OSSL_STORE_INFO_get1_PARAMS(info)) != NULL); cnt_expectations -= ok; } break; case OSSL_STORE_INFO_CERT: if (pcert != NULL && *pcert == NULL) { ok = (*pcert = OSSL_STORE_INFO_get1_CERT(info)) != NULL; cnt_expectations -= ok; } else if (pcerts != NULL) ok = X509_add_cert(*pcerts, OSSL_STORE_INFO_get1_CERT(info), X509_ADD_FLAG_DEFAULT); ncerts += ok; break; case OSSL_STORE_INFO_CRL: if (pcrl != NULL && *pcrl == NULL) { ok = (*pcrl = OSSL_STORE_INFO_get1_CRL(info)) != NULL; cnt_expectations -= ok; } else if (pcrls != NULL) ok = sk_X509_CRL_push(*pcrls, OSSL_STORE_INFO_get1_CRL(info)); ncrls += ok; break; default: /* skip any other type */ break; } OSSL_STORE_INFO_free(info); if (!ok) { failed = info == NULL ? NULL : OSSL_STORE_INFO_type_string(type); BIO_printf(bio_err, "Error reading"); break; } } end: OSSL_STORE_close(ctx); if (failed == NULL) { int any = 0; if ((ppkey != NULL && *ppkey == NULL) || (ppubkey != NULL && *ppubkey == NULL)) { failed = "key"; } else if (pparams != NULL && *pparams == NULL) { failed = "params"; } else if ((pcert != NULL || pcerts != NULL) && ncerts == 0) { if (pcert == NULL) any = 1; failed = "cert"; } else if ((pcrl != NULL || pcrls != NULL) && ncrls == 0) { if (pcrl == NULL) any = 1; failed = "CRL"; } if (!suppress_decode_errors) { if (failed != NULL) BIO_printf(bio_err, "Could not read"); if (any) BIO_printf(bio_err, " any"); } } if (!suppress_decode_errors && failed != NULL) { if (desc != NULL && strstr(desc, failed) != NULL) { BIO_printf(bio_err, " %s", desc); } else { BIO_printf(bio_err, " %s", failed); if (desc != NULL) BIO_printf(bio_err, " of %s", desc); } if (uri != NULL) BIO_printf(bio_err, " from %s", uri); BIO_printf(bio_err, "\n"); ERR_print_errors(bio_err); } if (suppress_decode_errors || failed == NULL) /* clear any spurious errors */ ERR_clear_error(); return failed == NULL; } int load_key_certs_crls(const char *uri, int format, int maybe_stdin, const char *pass, const char *desc, EVP_PKEY **ppkey, EVP_PKEY **ppubkey, EVP_PKEY **pparams, X509 **pcert, STACK_OF(X509) **pcerts, X509_CRL **pcrl, STACK_OF(X509_CRL) **pcrls) { return load_key_certs_crls_suppress(uri, format, maybe_stdin, pass, desc, ppkey, ppubkey, pparams, pcert, pcerts, pcrl, pcrls, 0); } #define X509V3_EXT_UNKNOWN_MASK (0xfL << 16) /* Return error for unknown extensions */ #define X509V3_EXT_DEFAULT 0 /* Print error for unknown extensions */ #define X509V3_EXT_ERROR_UNKNOWN (1L << 16) /* ASN1 parse unknown extensions */ #define X509V3_EXT_PARSE_UNKNOWN (2L << 16) /* BIO_dump unknown extensions */ #define X509V3_EXT_DUMP_UNKNOWN (3L << 16) #define X509_FLAG_CA (X509_FLAG_NO_ISSUER | X509_FLAG_NO_PUBKEY | \ X509_FLAG_NO_HEADER | X509_FLAG_NO_VERSION) int set_cert_ex(unsigned long *flags, const char *arg) { static const NAME_EX_TBL cert_tbl[] = { {"compatible", X509_FLAG_COMPAT, 0xffffffffl}, {"ca_default", X509_FLAG_CA, 0xffffffffl}, {"no_header", X509_FLAG_NO_HEADER, 0}, {"no_version", X509_FLAG_NO_VERSION, 0}, {"no_serial", X509_FLAG_NO_SERIAL, 0}, {"no_signame", X509_FLAG_NO_SIGNAME, 0}, {"no_validity", X509_FLAG_NO_VALIDITY, 0}, {"no_subject", X509_FLAG_NO_SUBJECT, 0}, {"no_issuer", X509_FLAG_NO_ISSUER, 0}, {"no_pubkey", X509_FLAG_NO_PUBKEY, 0}, {"no_extensions", X509_FLAG_NO_EXTENSIONS, 0}, {"no_sigdump", X509_FLAG_NO_SIGDUMP, 0}, {"no_aux", X509_FLAG_NO_AUX, 0}, {"no_attributes", X509_FLAG_NO_ATTRIBUTES, 0}, {"ext_default", X509V3_EXT_DEFAULT, X509V3_EXT_UNKNOWN_MASK}, {"ext_error", X509V3_EXT_ERROR_UNKNOWN, X509V3_EXT_UNKNOWN_MASK}, {"ext_parse", X509V3_EXT_PARSE_UNKNOWN, X509V3_EXT_UNKNOWN_MASK}, {"ext_dump", X509V3_EXT_DUMP_UNKNOWN, X509V3_EXT_UNKNOWN_MASK}, {NULL, 0, 0} }; return set_multi_opts(flags, arg, cert_tbl); } int set_name_ex(unsigned long *flags, const char *arg) { static const NAME_EX_TBL ex_tbl[] = { {"esc_2253", ASN1_STRFLGS_ESC_2253, 0}, {"esc_2254", ASN1_STRFLGS_ESC_2254, 0}, {"esc_ctrl", ASN1_STRFLGS_ESC_CTRL, 0}, {"esc_msb", ASN1_STRFLGS_ESC_MSB, 0}, {"use_quote", ASN1_STRFLGS_ESC_QUOTE, 0}, {"utf8", ASN1_STRFLGS_UTF8_CONVERT, 0}, {"ignore_type", ASN1_STRFLGS_IGNORE_TYPE, 0}, {"show_type", ASN1_STRFLGS_SHOW_TYPE, 0}, {"dump_all", ASN1_STRFLGS_DUMP_ALL, 0}, {"dump_nostr", ASN1_STRFLGS_DUMP_UNKNOWN, 0}, {"dump_der", ASN1_STRFLGS_DUMP_DER, 0}, {"compat", XN_FLAG_COMPAT, 0xffffffffL}, {"sep_comma_plus", XN_FLAG_SEP_COMMA_PLUS, XN_FLAG_SEP_MASK}, {"sep_comma_plus_space", XN_FLAG_SEP_CPLUS_SPC, XN_FLAG_SEP_MASK}, {"sep_semi_plus_space", XN_FLAG_SEP_SPLUS_SPC, XN_FLAG_SEP_MASK}, {"sep_multiline", XN_FLAG_SEP_MULTILINE, XN_FLAG_SEP_MASK}, {"dn_rev", XN_FLAG_DN_REV, 0}, {"nofname", XN_FLAG_FN_NONE, XN_FLAG_FN_MASK}, {"sname", XN_FLAG_FN_SN, XN_FLAG_FN_MASK}, {"lname", XN_FLAG_FN_LN, XN_FLAG_FN_MASK}, {"align", XN_FLAG_FN_ALIGN, 0}, {"oid", XN_FLAG_FN_OID, XN_FLAG_FN_MASK}, {"space_eq", XN_FLAG_SPC_EQ, 0}, {"dump_unknown", XN_FLAG_DUMP_UNKNOWN_FIELDS, 0}, {"RFC2253", XN_FLAG_RFC2253, 0xffffffffL}, {"oneline", XN_FLAG_ONELINE, 0xffffffffL}, {"multiline", XN_FLAG_MULTILINE, 0xffffffffL}, {"ca_default", XN_FLAG_MULTILINE, 0xffffffffL}, {NULL, 0, 0} }; if (set_multi_opts(flags, arg, ex_tbl) == 0) return 0; if (*flags != XN_FLAG_COMPAT && (*flags & XN_FLAG_SEP_MASK) == 0) *flags |= XN_FLAG_SEP_CPLUS_SPC; return 1; } int set_dateopt(unsigned long *dateopt, const char *arg) { if (OPENSSL_strcasecmp(arg, "rfc_822") == 0) *dateopt = ASN1_DTFLGS_RFC822; else if (OPENSSL_strcasecmp(arg, "iso_8601") == 0) *dateopt = ASN1_DTFLGS_ISO8601; else return 0; return 1; } int set_ext_copy(int *copy_type, const char *arg) { if (OPENSSL_strcasecmp(arg, "none") == 0) *copy_type = EXT_COPY_NONE; else if (OPENSSL_strcasecmp(arg, "copy") == 0) *copy_type = EXT_COPY_ADD; else if (OPENSSL_strcasecmp(arg, "copyall") == 0) *copy_type = EXT_COPY_ALL; else return 0; return 1; } int copy_extensions(X509 *x, X509_REQ *req, int copy_type) { STACK_OF(X509_EXTENSION) *exts; int i, ret = 0; if (x == NULL || req == NULL) return 0; if (copy_type == EXT_COPY_NONE) return 1; exts = X509_REQ_get_extensions(req); for (i = 0; i < sk_X509_EXTENSION_num(exts); i++) { X509_EXTENSION *ext = sk_X509_EXTENSION_value(exts, i); ASN1_OBJECT *obj = X509_EXTENSION_get_object(ext); int idx = X509_get_ext_by_OBJ(x, obj, -1); /* Does extension exist in target? */ if (idx != -1) { /* If normal copy don't override existing extension */ if (copy_type == EXT_COPY_ADD) continue; /* Delete all extensions of same type */ do { X509_EXTENSION_free(X509_delete_ext(x, idx)); idx = X509_get_ext_by_OBJ(x, obj, -1); } while (idx != -1); } if (!X509_add_ext(x, ext, -1)) goto end; } ret = 1; end: sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free); return ret; } static int set_multi_opts(unsigned long *flags, const char *arg, const NAME_EX_TBL * in_tbl) { STACK_OF(CONF_VALUE) *vals; CONF_VALUE *val; int i, ret = 1; if (!arg) return 0; vals = X509V3_parse_list(arg); for (i = 0; i < sk_CONF_VALUE_num(vals); i++) { val = sk_CONF_VALUE_value(vals, i); if (!set_table_opts(flags, val->name, in_tbl)) ret = 0; } sk_CONF_VALUE_pop_free(vals, X509V3_conf_free); return ret; } static int set_table_opts(unsigned long *flags, const char *arg, const NAME_EX_TBL * in_tbl) { char c; const NAME_EX_TBL *ptbl; c = arg[0]; if (c == '-') { c = 0; arg++; } else if (c == '+') { c = 1; arg++; } else { c = 1; } for (ptbl = in_tbl; ptbl->name; ptbl++) { if (OPENSSL_strcasecmp(arg, ptbl->name) == 0) { *flags &= ~ptbl->mask; if (c) *flags |= ptbl->flag; else *flags &= ~ptbl->flag; return 1; } } return 0; } void print_name(BIO *out, const char *title, const X509_NAME *nm) { char *buf; char mline = 0; int indent = 0; unsigned long lflags = get_nameopt(); if (out == NULL) return; if (title != NULL) BIO_puts(out, title); if ((lflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) { mline = 1; indent = 4; } if (lflags == XN_FLAG_COMPAT) { buf = X509_NAME_oneline(nm, 0, 0); BIO_puts(out, buf); BIO_puts(out, "\n"); OPENSSL_free(buf); } else { if (mline) BIO_puts(out, "\n"); X509_NAME_print_ex(out, nm, indent, lflags); BIO_puts(out, "\n"); } } void print_bignum_var(BIO *out, const BIGNUM *in, const char *var, int len, unsigned char *buffer) { BIO_printf(out, " static unsigned char %s_%d[] = {", var, len); if (BN_is_zero(in)) { BIO_printf(out, "\n 0x00"); } else { int i, l; l = BN_bn2bin(in, buffer); for (i = 0; i < l; i++) { BIO_printf(out, (i % 10) == 0 ? "\n " : " "); if (i < l - 1) BIO_printf(out, "0x%02X,", buffer[i]); else BIO_printf(out, "0x%02X", buffer[i]); } } BIO_printf(out, "\n };\n"); } void print_array(BIO *out, const char* title, int len, const unsigned char* d) { int i; BIO_printf(out, "unsigned char %s[%d] = {", title, len); for (i = 0; i < len; i++) { if ((i % 10) == 0) BIO_printf(out, "\n "); if (i < len - 1) BIO_printf(out, "0x%02X, ", d[i]); else BIO_printf(out, "0x%02X", d[i]); } BIO_printf(out, "\n};\n"); } X509_STORE *setup_verify(const char *CAfile, int noCAfile, const char *CApath, int noCApath, const char *CAstore, int noCAstore) { X509_STORE *store = X509_STORE_new(); X509_LOOKUP *lookup; OSSL_LIB_CTX *libctx = app_get0_libctx(); const char *propq = app_get0_propq(); if (store == NULL) goto end; if (CAfile != NULL || !noCAfile) { lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()); if (lookup == NULL) goto end; if (CAfile != NULL) { if (X509_LOOKUP_load_file_ex(lookup, CAfile, X509_FILETYPE_PEM, libctx, propq) <= 0) { BIO_printf(bio_err, "Error loading file %s\n", CAfile); goto end; } } else { X509_LOOKUP_load_file_ex(lookup, NULL, X509_FILETYPE_DEFAULT, libctx, propq); } } if (CApath != NULL || !noCApath) { lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir()); if (lookup == NULL) goto end; if (CApath != NULL) { if (X509_LOOKUP_add_dir(lookup, CApath, X509_FILETYPE_PEM) <= 0) { BIO_printf(bio_err, "Error loading directory %s\n", CApath); goto end; } } else { X509_LOOKUP_add_dir(lookup, NULL, X509_FILETYPE_DEFAULT); } } if (CAstore != NULL || !noCAstore) { lookup = X509_STORE_add_lookup(store, X509_LOOKUP_store()); if (lookup == NULL) goto end; if (!X509_LOOKUP_add_store_ex(lookup, CAstore, libctx, propq)) { if (CAstore != NULL) BIO_printf(bio_err, "Error loading store URI %s\n", CAstore); goto end; } } ERR_clear_error(); return store; end: ERR_print_errors(bio_err); X509_STORE_free(store); return NULL; } static unsigned long index_serial_hash(const OPENSSL_CSTRING *a) { const char *n; n = a[DB_serial]; while (*n == '0') n++; return OPENSSL_LH_strhash(n); } static int index_serial_cmp(const OPENSSL_CSTRING *a, const OPENSSL_CSTRING *b) { const char *aa, *bb; for (aa = a[DB_serial]; *aa == '0'; aa++) ; for (bb = b[DB_serial]; *bb == '0'; bb++) ; return strcmp(aa, bb); } static int index_name_qual(char **a) { return (a[0][0] == 'V'); } static unsigned long index_name_hash(const OPENSSL_CSTRING *a) { return OPENSSL_LH_strhash(a[DB_name]); } int index_name_cmp(const OPENSSL_CSTRING *a, const OPENSSL_CSTRING *b) { return strcmp(a[DB_name], b[DB_name]); } static IMPLEMENT_LHASH_HASH_FN(index_serial, OPENSSL_CSTRING) static IMPLEMENT_LHASH_COMP_FN(index_serial, OPENSSL_CSTRING) static IMPLEMENT_LHASH_HASH_FN(index_name, OPENSSL_CSTRING) static IMPLEMENT_LHASH_COMP_FN(index_name, OPENSSL_CSTRING) #undef BSIZE #define BSIZE 256 BIGNUM *load_serial(const char *serialfile, int *exists, int create, ASN1_INTEGER **retai) { BIO *in = NULL; BIGNUM *ret = NULL; char buf[1024]; ASN1_INTEGER *ai = NULL; ai = ASN1_INTEGER_new(); if (ai == NULL) goto err; in = BIO_new_file(serialfile, "r"); if (exists != NULL) *exists = in != NULL; if (in == NULL) { if (!create) { perror(serialfile); goto err; } ERR_clear_error(); ret = BN_new(); if (ret == NULL) { BIO_printf(bio_err, "Out of memory\n"); } else if (!rand_serial(ret, ai)) { BIO_printf(bio_err, "Error creating random number to store in %s\n", serialfile); BN_free(ret); ret = NULL; } } else { if (!a2i_ASN1_INTEGER(in, ai, buf, 1024)) { BIO_printf(bio_err, "Unable to load number from %s\n", serialfile); goto err; } ret = ASN1_INTEGER_to_BN(ai, NULL); if (ret == NULL) { BIO_printf(bio_err, "Error converting number from bin to BIGNUM\n"); goto err; } } if (ret != NULL && retai != NULL) { *retai = ai; ai = NULL; } err: if (ret == NULL) ERR_print_errors(bio_err); BIO_free(in); ASN1_INTEGER_free(ai); return ret; } int save_serial(const char *serialfile, const char *suffix, const BIGNUM *serial, ASN1_INTEGER **retai) { char buf[1][BSIZE]; BIO *out = NULL; int ret = 0; ASN1_INTEGER *ai = NULL; int j; if (suffix == NULL) j = strlen(serialfile); else j = strlen(serialfile) + strlen(suffix) + 1; if (j >= BSIZE) { BIO_printf(bio_err, "File name too long\n"); goto err; } if (suffix == NULL) OPENSSL_strlcpy(buf[0], serialfile, BSIZE); else { #ifndef OPENSSL_SYS_VMS j = BIO_snprintf(buf[0], sizeof(buf[0]), "%s.%s", serialfile, suffix); #else j = BIO_snprintf(buf[0], sizeof(buf[0]), "%s-%s", serialfile, suffix); #endif } out = BIO_new_file(buf[0], "w"); if (out == NULL) { goto err; } if ((ai = BN_to_ASN1_INTEGER(serial, NULL)) == NULL) { BIO_printf(bio_err, "error converting serial to ASN.1 format\n"); goto err; } i2a_ASN1_INTEGER(out, ai); BIO_puts(out, "\n"); ret = 1; if (retai) { *retai = ai; ai = NULL; } err: if (!ret) ERR_print_errors(bio_err); BIO_free_all(out); ASN1_INTEGER_free(ai); return ret; } int rotate_serial(const char *serialfile, const char *new_suffix, const char *old_suffix) { char buf[2][BSIZE]; int i, j; i = strlen(serialfile) + strlen(old_suffix); j = strlen(serialfile) + strlen(new_suffix); if (i > j) j = i; if (j + 1 >= BSIZE) { BIO_printf(bio_err, "File name too long\n"); goto err; } #ifndef OPENSSL_SYS_VMS j = BIO_snprintf(buf[0], sizeof(buf[0]), "%s.%s", serialfile, new_suffix); j = BIO_snprintf(buf[1], sizeof(buf[1]), "%s.%s", serialfile, old_suffix); #else j = BIO_snprintf(buf[0], sizeof(buf[0]), "%s-%s", serialfile, new_suffix); j = BIO_snprintf(buf[1], sizeof(buf[1]), "%s-%s", serialfile, old_suffix); #endif if (rename(serialfile, buf[1]) < 0 && errno != ENOENT #ifdef ENOTDIR && errno != ENOTDIR #endif ) { BIO_printf(bio_err, "Unable to rename %s to %s\n", serialfile, buf[1]); perror("reason"); goto err; } if (rename(buf[0], serialfile) < 0) { BIO_printf(bio_err, "Unable to rename %s to %s\n", buf[0], serialfile); perror("reason"); rename(buf[1], serialfile); goto err; } return 1; err: ERR_print_errors(bio_err); return 0; } int rand_serial(BIGNUM *b, ASN1_INTEGER *ai) { BIGNUM *btmp; int ret = 0; btmp = b == NULL ? BN_new() : b; if (btmp == NULL) return 0; if (!BN_rand(btmp, SERIAL_RAND_BITS, BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY)) goto error; if (ai && !BN_to_ASN1_INTEGER(btmp, ai)) goto error; ret = 1; error: if (btmp != b) BN_free(btmp); return ret; } CA_DB *load_index(const char *dbfile, DB_ATTR *db_attr) { CA_DB *retdb = NULL; TXT_DB *tmpdb = NULL; BIO *in; CONF *dbattr_conf = NULL; char buf[BSIZE]; #ifndef OPENSSL_NO_POSIX_IO FILE *dbfp; struct stat dbst; #endif in = BIO_new_file(dbfile, "r"); if (in == NULL) goto err; #ifndef OPENSSL_NO_POSIX_IO BIO_get_fp(in, &dbfp); if (fstat(fileno(dbfp), &dbst) == -1) { ERR_raise_data(ERR_LIB_SYS, errno, "calling fstat(%s)", dbfile); goto err; } #endif if ((tmpdb = TXT_DB_read(in, DB_NUMBER)) == NULL) goto err; #ifndef OPENSSL_SYS_VMS BIO_snprintf(buf, sizeof(buf), "%s.attr", dbfile); #else BIO_snprintf(buf, sizeof(buf), "%s-attr", dbfile); #endif dbattr_conf = app_load_config_quiet(buf); retdb = app_malloc(sizeof(*retdb), "new DB"); retdb->db = tmpdb; tmpdb = NULL; if (db_attr) retdb->attributes = *db_attr; else { retdb->attributes.unique_subject = 1; } if (dbattr_conf) { char *p = NCONF_get_string(dbattr_conf, NULL, "unique_subject"); if (p) { retdb->attributes.unique_subject = parse_yesno(p, 1); } else { ERR_clear_error(); } } retdb->dbfname = OPENSSL_strdup(dbfile); #ifndef OPENSSL_NO_POSIX_IO retdb->dbst = dbst; #endif err: ERR_print_errors(bio_err); NCONF_free(dbattr_conf); TXT_DB_free(tmpdb); BIO_free_all(in); return retdb; } /* * Returns > 0 on success, <= 0 on error */ int index_index(CA_DB *db) { if (!TXT_DB_create_index(db->db, DB_serial, NULL, LHASH_HASH_FN(index_serial), LHASH_COMP_FN(index_serial))) { BIO_printf(bio_err, "Error creating serial number index:(%ld,%ld,%ld)\n", db->db->error, db->db->arg1, db->db->arg2); goto err; } if (db->attributes.unique_subject && !TXT_DB_create_index(db->db, DB_name, index_name_qual, LHASH_HASH_FN(index_name), LHASH_COMP_FN(index_name))) { BIO_printf(bio_err, "Error creating name index:(%ld,%ld,%ld)\n", db->db->error, db->db->arg1, db->db->arg2); goto err; } return 1; err: ERR_print_errors(bio_err); return 0; } int save_index(const char *dbfile, const char *suffix, CA_DB *db) { char buf[3][BSIZE]; BIO *out; int j; j = strlen(dbfile) + strlen(suffix); if (j + 6 >= BSIZE) { BIO_printf(bio_err, "File name too long\n"); goto err; } #ifndef OPENSSL_SYS_VMS j = BIO_snprintf(buf[2], sizeof(buf[2]), "%s.attr", dbfile); j = BIO_snprintf(buf[1], sizeof(buf[1]), "%s.attr.%s", dbfile, suffix); j = BIO_snprintf(buf[0], sizeof(buf[0]), "%s.%s", dbfile, suffix); #else j = BIO_snprintf(buf[2], sizeof(buf[2]), "%s-attr", dbfile); j = BIO_snprintf(buf[1], sizeof(buf[1]), "%s-attr-%s", dbfile, suffix); j = BIO_snprintf(buf[0], sizeof(buf[0]), "%s-%s", dbfile, suffix); #endif out = BIO_new_file(buf[0], "w"); if (out == NULL) { perror(dbfile); BIO_printf(bio_err, "Unable to open '%s'\n", dbfile); goto err; } j = TXT_DB_write(out, db->db); BIO_free(out); if (j <= 0) goto err; out = BIO_new_file(buf[1], "w"); if (out == NULL) { perror(buf[2]); BIO_printf(bio_err, "Unable to open '%s'\n", buf[2]); goto err; } BIO_printf(out, "unique_subject = %s\n", db->attributes.unique_subject ? "yes" : "no"); BIO_free(out); return 1; err: ERR_print_errors(bio_err); return 0; } int rotate_index(const char *dbfile, const char *new_suffix, const char *old_suffix) { char buf[5][BSIZE]; int i, j; i = strlen(dbfile) + strlen(old_suffix); j = strlen(dbfile) + strlen(new_suffix); if (i > j) j = i; if (j + 6 >= BSIZE) { BIO_printf(bio_err, "File name too long\n"); goto err; } #ifndef OPENSSL_SYS_VMS j = BIO_snprintf(buf[4], sizeof(buf[4]), "%s.attr", dbfile); j = BIO_snprintf(buf[3], sizeof(buf[3]), "%s.attr.%s", dbfile, old_suffix); j = BIO_snprintf(buf[2], sizeof(buf[2]), "%s.attr.%s", dbfile, new_suffix); j = BIO_snprintf(buf[1], sizeof(buf[1]), "%s.%s", dbfile, old_suffix); j = BIO_snprintf(buf[0], sizeof(buf[0]), "%s.%s", dbfile, new_suffix); #else j = BIO_snprintf(buf[4], sizeof(buf[4]), "%s-attr", dbfile); j = BIO_snprintf(buf[3], sizeof(buf[3]), "%s-attr-%s", dbfile, old_suffix); j = BIO_snprintf(buf[2], sizeof(buf[2]), "%s-attr-%s", dbfile, new_suffix); j = BIO_snprintf(buf[1], sizeof(buf[1]), "%s-%s", dbfile, old_suffix); j = BIO_snprintf(buf[0], sizeof(buf[0]), "%s-%s", dbfile, new_suffix); #endif if (rename(dbfile, buf[1]) < 0 && errno != ENOENT #ifdef ENOTDIR && errno != ENOTDIR #endif ) { BIO_printf(bio_err, "Unable to rename %s to %s\n", dbfile, buf[1]); perror("reason"); goto err; } if (rename(buf[0], dbfile) < 0) { BIO_printf(bio_err, "Unable to rename %s to %s\n", buf[0], dbfile); perror("reason"); rename(buf[1], dbfile); goto err; } if (rename(buf[4], buf[3]) < 0 && errno != ENOENT #ifdef ENOTDIR && errno != ENOTDIR #endif ) { BIO_printf(bio_err, "Unable to rename %s to %s\n", buf[4], buf[3]); perror("reason"); rename(dbfile, buf[0]); rename(buf[1], dbfile); goto err; } if (rename(buf[2], buf[4]) < 0) { BIO_printf(bio_err, "Unable to rename %s to %s\n", buf[2], buf[4]); perror("reason"); rename(buf[3], buf[4]); rename(dbfile, buf[0]); rename(buf[1], dbfile); goto err; } return 1; err: ERR_print_errors(bio_err); return 0; } void free_index(CA_DB *db) { if (db) { TXT_DB_free(db->db); OPENSSL_free(db->dbfname); OPENSSL_free(db); } } int parse_yesno(const char *str, int def) { if (str) { switch (*str) { case 'f': /* false */ case 'F': /* FALSE */ case 'n': /* no */ case 'N': /* NO */ case '0': /* 0 */ return 0; case 't': /* true */ case 'T': /* TRUE */ case 'y': /* yes */ case 'Y': /* YES */ case '1': /* 1 */ return 1; } } return def; } /* * name is expected to be in the format /type0=value0/type1=value1/type2=... * where + can be used instead of / to form multi-valued RDNs if canmulti * and characters may be escaped by \ */ X509_NAME *parse_name(const char *cp, int chtype, int canmulti, const char *desc) { int nextismulti = 0; char *work; X509_NAME *n; if (*cp++ != '/') { BIO_printf(bio_err, "%s: %s name is expected to be in the format " "/type0=value0/type1=value1/type2=... where characters may " "be escaped by \\. This name is not in that format: '%s'\n", opt_getprog(), desc, --cp); return NULL; } n = X509_NAME_new(); if (n == NULL) { BIO_printf(bio_err, "%s: Out of memory\n", opt_getprog()); return NULL; } work = OPENSSL_strdup(cp); if (work == NULL) { BIO_printf(bio_err, "%s: Error copying %s name input\n", opt_getprog(), desc); goto err; } while (*cp != '\0') { char *bp = work; char *typestr = bp; unsigned char *valstr; int nid; int ismulti = nextismulti; nextismulti = 0; /* Collect the type */ while (*cp != '\0' && *cp != '=') *bp++ = *cp++; *bp++ = '\0'; if (*cp == '\0') { BIO_printf(bio_err, "%s: Missing '=' after RDN type string '%s' in %s name string\n", opt_getprog(), typestr, desc); goto err; } ++cp; /* Collect the value. */ valstr = (unsigned char *)bp; for (; *cp != '\0' && *cp != '/'; *bp++ = *cp++) { /* unescaped '+' symbol string signals further member of multiRDN */ if (canmulti && *cp == '+') { nextismulti = 1; break; } if (*cp == '\\' && *++cp == '\0') { BIO_printf(bio_err, "%s: Escape character at end of %s name string\n", opt_getprog(), desc); goto err; } } *bp++ = '\0'; /* If not at EOS (must be + or /), move forward. */ if (*cp != '\0') ++cp; /* Parse */ nid = OBJ_txt2nid(typestr); if (nid == NID_undef) { BIO_printf(bio_err, "%s warning: Skipping unknown %s name attribute \"%s\"\n", opt_getprog(), desc, typestr); if (ismulti) BIO_printf(bio_err, "%s hint: a '+' in a value string needs be escaped using '\\' else a new member of a multi-valued RDN is expected\n", opt_getprog()); continue; } if (*valstr == '\0') { BIO_printf(bio_err, "%s warning: No value provided for %s name attribute \"%s\", skipped\n", opt_getprog(), desc, typestr); continue; } if (!X509_NAME_add_entry_by_NID(n, nid, chtype, valstr, strlen((char *)valstr), -1, ismulti ? -1 : 0)) { ERR_print_errors(bio_err); BIO_printf(bio_err, "%s: Error adding %s name attribute \"/%s=%s\"\n", opt_getprog(), desc, typestr ,valstr); goto err; } } OPENSSL_free(work); return n; err: X509_NAME_free(n); OPENSSL_free(work); return NULL; } /* * Read whole contents of a BIO into an allocated memory buffer and return * it. */ int bio_to_mem(unsigned char **out, int maxlen, BIO *in) { BIO *mem; int len, ret; unsigned char tbuf[1024]; mem = BIO_new(BIO_s_mem()); if (mem == NULL) return -1; for (;;) { if ((maxlen != -1) && maxlen < 1024) len = maxlen; else len = 1024; len = BIO_read(in, tbuf, len); if (len < 0) { BIO_free(mem); return -1; } if (len == 0) break; if (BIO_write(mem, tbuf, len) != len) { BIO_free(mem); return -1; } if (maxlen != -1) maxlen -= len; if (maxlen == 0) break; } ret = BIO_get_mem_data(mem, (char **)out); BIO_set_flags(mem, BIO_FLAGS_MEM_RDONLY); BIO_free(mem); return ret; } int pkey_ctrl_string(EVP_PKEY_CTX *ctx, const char *value) { int rv = 0; char *stmp, *vtmp = NULL; stmp = OPENSSL_strdup(value); if (stmp == NULL) return -1; vtmp = strchr(stmp, ':'); if (vtmp == NULL) goto err; *vtmp = 0; vtmp++; rv = EVP_PKEY_CTX_ctrl_str(ctx, stmp, vtmp); err: OPENSSL_free(stmp); return rv; } static void nodes_print(const char *name, STACK_OF(X509_POLICY_NODE) *nodes) { X509_POLICY_NODE *node; int i; BIO_printf(bio_err, "%s Policies:", name); if (nodes) { BIO_puts(bio_err, "\n"); for (i = 0; i < sk_X509_POLICY_NODE_num(nodes); i++) { node = sk_X509_POLICY_NODE_value(nodes, i); X509_POLICY_NODE_print(bio_err, node, 2); } } else { BIO_puts(bio_err, " \n"); } } void policies_print(X509_STORE_CTX *ctx) { X509_POLICY_TREE *tree; int explicit_policy; tree = X509_STORE_CTX_get0_policy_tree(ctx); explicit_policy = X509_STORE_CTX_get_explicit_policy(ctx); BIO_printf(bio_err, "Require explicit Policy: %s\n", explicit_policy ? "True" : "False"); nodes_print("Authority", X509_policy_tree_get0_policies(tree)); nodes_print("User", X509_policy_tree_get0_user_policies(tree)); } /*- * next_protos_parse parses a comma separated list of strings into a string * in a format suitable for passing to SSL_CTX_set_next_protos_advertised. * outlen: (output) set to the length of the resulting buffer on success. * err: (maybe NULL) on failure, an error message line is written to this BIO. * in: a NUL terminated string like "abc,def,ghi" * * returns: a malloc'd buffer or NULL on failure. */ unsigned char *next_protos_parse(size_t *outlen, const char *in) { size_t len; unsigned char *out; size_t i, start = 0; size_t skipped = 0; len = strlen(in); if (len == 0 || len >= 65535) return NULL; out = app_malloc(len + 1, "NPN buffer"); for (i = 0; i <= len; ++i) { if (i == len || in[i] == ',') { /* * Zero-length ALPN elements are invalid on the wire, we could be * strict and reject the entire string, but just ignoring extra * commas seems harmless and more friendly. * * Every comma we skip in this way puts the input buffer another * byte ahead of the output buffer, so all stores into the output * buffer need to be decremented by the number commas skipped. */ if (i == start) { ++start; ++skipped; continue; } if (i - start > 255) { OPENSSL_free(out); return NULL; } out[start-skipped] = (unsigned char)(i - start); start = i + 1; } else { out[i + 1 - skipped] = in[i]; } } if (len <= skipped) { OPENSSL_free(out); return NULL; } *outlen = len + 1 - skipped; return out; } void print_cert_checks(BIO *bio, X509 *x, const char *checkhost, const char *checkemail, const char *checkip) { if (x == NULL) return; if (checkhost) { BIO_printf(bio, "Hostname %s does%s match certificate\n", checkhost, X509_check_host(x, checkhost, 0, 0, NULL) == 1 ? "" : " NOT"); } if (checkemail) { BIO_printf(bio, "Email %s does%s match certificate\n", checkemail, X509_check_email(x, checkemail, 0, 0) ? "" : " NOT"); } if (checkip) { BIO_printf(bio, "IP %s does%s match certificate\n", checkip, X509_check_ip_asc(x, checkip, 0) ? "" : " NOT"); } } static int do_pkey_ctx_init(EVP_PKEY_CTX *pkctx, STACK_OF(OPENSSL_STRING) *opts) { int i; if (opts == NULL) return 1; for (i = 0; i < sk_OPENSSL_STRING_num(opts); i++) { char *opt = sk_OPENSSL_STRING_value(opts, i); if (pkey_ctrl_string(pkctx, opt) <= 0) { BIO_printf(bio_err, "parameter error \"%s\"\n", opt); ERR_print_errors(bio_err); return 0; } } return 1; } static int do_x509_init(X509 *x, STACK_OF(OPENSSL_STRING) *opts) { int i; if (opts == NULL) return 1; for (i = 0; i < sk_OPENSSL_STRING_num(opts); i++) { char *opt = sk_OPENSSL_STRING_value(opts, i); if (x509_ctrl_string(x, opt) <= 0) { BIO_printf(bio_err, "parameter error \"%s\"\n", opt); ERR_print_errors(bio_err); return 0; } } return 1; } static int do_x509_req_init(X509_REQ *x, STACK_OF(OPENSSL_STRING) *opts) { int i; if (opts == NULL) return 1; for (i = 0; i < sk_OPENSSL_STRING_num(opts); i++) { char *opt = sk_OPENSSL_STRING_value(opts, i); if (x509_req_ctrl_string(x, opt) <= 0) { BIO_printf(bio_err, "parameter error \"%s\"\n", opt); ERR_print_errors(bio_err); return 0; } } return 1; } static int do_sign_init(EVP_MD_CTX *ctx, EVP_PKEY *pkey, const char *md, STACK_OF(OPENSSL_STRING) *sigopts) { EVP_PKEY_CTX *pkctx = NULL; char def_md[80]; if (ctx == NULL) return 0; /* * EVP_PKEY_get_default_digest_name() returns 2 if the digest is mandatory * for this algorithm. */ if (EVP_PKEY_get_default_digest_name(pkey, def_md, sizeof(def_md)) == 2 && strcmp(def_md, "UNDEF") == 0) { /* The signing algorithm requires there to be no digest */ md = NULL; } return EVP_DigestSignInit_ex(ctx, &pkctx, md, app_get0_libctx(), app_get0_propq(), pkey, NULL) && do_pkey_ctx_init(pkctx, sigopts); } static int adapt_keyid_ext(X509 *cert, X509V3_CTX *ext_ctx, const char *name, const char *value, int add_default) { const STACK_OF(X509_EXTENSION) *exts = X509_get0_extensions(cert); X509_EXTENSION *new_ext = X509V3_EXT_nconf(NULL, ext_ctx, name, value); int idx, rv = 0; if (new_ext == NULL) return rv; idx = X509v3_get_ext_by_OBJ(exts, X509_EXTENSION_get_object(new_ext), -1); if (idx >= 0) { X509_EXTENSION *found_ext = X509v3_get_ext(exts, idx); ASN1_OCTET_STRING *data = X509_EXTENSION_get_data(found_ext); int disabled = ASN1_STRING_length(data) <= 2; /* config said "none" */ if (disabled) { X509_delete_ext(cert, idx); X509_EXTENSION_free(found_ext); } /* else keep existing key identifier, which might be outdated */ rv = 1; } else { rv = !add_default || X509_add_ext(cert, new_ext, -1); } X509_EXTENSION_free(new_ext); return rv; } /* Ensure RFC 5280 compliance, adapt keyIDs as needed, and sign the cert info */ int do_X509_sign(X509 *cert, EVP_PKEY *pkey, const char *md, STACK_OF(OPENSSL_STRING) *sigopts, X509V3_CTX *ext_ctx) { const STACK_OF(X509_EXTENSION) *exts = X509_get0_extensions(cert); EVP_MD_CTX *mctx = EVP_MD_CTX_new(); int self_sign; int rv = 0; if (sk_X509_EXTENSION_num(exts /* may be NULL */) > 0) { /* Prevent X509_V_ERR_EXTENSIONS_REQUIRE_VERSION_3 */ if (!X509_set_version(cert, X509_VERSION_3)) goto end; /* * Add default SKID before such that default AKID can make use of it * in case the certificate is self-signed */ /* Prevent X509_V_ERR_MISSING_SUBJECT_KEY_IDENTIFIER */ if (!adapt_keyid_ext(cert, ext_ctx, "subjectKeyIdentifier", "hash", 1)) goto end; /* Prevent X509_V_ERR_MISSING_AUTHORITY_KEY_IDENTIFIER */ ERR_set_mark(); self_sign = X509_check_private_key(cert, pkey); ERR_pop_to_mark(); if (!adapt_keyid_ext(cert, ext_ctx, "authorityKeyIdentifier", "keyid, issuer", !self_sign)) goto end; } if (mctx != NULL && do_sign_init(mctx, pkey, md, sigopts) > 0) rv = (X509_sign_ctx(cert, mctx) > 0); end: EVP_MD_CTX_free(mctx); return rv; } /* Sign the certificate request info */ int do_X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const char *md, STACK_OF(OPENSSL_STRING) *sigopts) { int rv = 0; EVP_MD_CTX *mctx = EVP_MD_CTX_new(); if (do_sign_init(mctx, pkey, md, sigopts) > 0) rv = (X509_REQ_sign_ctx(x, mctx) > 0); EVP_MD_CTX_free(mctx); return rv; } /* Sign the CRL info */ int do_X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const char *md, STACK_OF(OPENSSL_STRING) *sigopts) { int rv = 0; EVP_MD_CTX *mctx = EVP_MD_CTX_new(); if (do_sign_init(mctx, pkey, md, sigopts) > 0) rv = (X509_CRL_sign_ctx(x, mctx) > 0); EVP_MD_CTX_free(mctx); return rv; } /* * do_X509_verify returns 1 if the signature is valid, * 0 if the signature check fails, or -1 if error occurs. */ int do_X509_verify(X509 *x, EVP_PKEY *pkey, STACK_OF(OPENSSL_STRING) *vfyopts) { int rv = 0; if (do_x509_init(x, vfyopts) > 0) rv = X509_verify(x, pkey); else rv = -1; return rv; } /* * do_X509_REQ_verify returns 1 if the signature is valid, * 0 if the signature check fails, or -1 if error occurs. */ int do_X509_REQ_verify(X509_REQ *x, EVP_PKEY *pkey, STACK_OF(OPENSSL_STRING) *vfyopts) { int rv = 0; if (do_x509_req_init(x, vfyopts) > 0) rv = X509_REQ_verify_ex(x, pkey, app_get0_libctx(), app_get0_propq()); else rv = -1; return rv; } /* Get first http URL from a DIST_POINT structure */ static const char *get_dp_url(DIST_POINT *dp) { GENERAL_NAMES *gens; GENERAL_NAME *gen; int i, gtype; ASN1_STRING *uri; if (!dp->distpoint || dp->distpoint->type != 0) return NULL; gens = dp->distpoint->name.fullname; for (i = 0; i < sk_GENERAL_NAME_num(gens); i++) { gen = sk_GENERAL_NAME_value(gens, i); uri = GENERAL_NAME_get0_value(gen, >ype); if (gtype == GEN_URI && ASN1_STRING_length(uri) > 6) { const char *uptr = (const char *)ASN1_STRING_get0_data(uri); if (IS_HTTP(uptr)) /* can/should not use HTTPS here */ return uptr; } } return NULL; } /* * Look through a CRLDP structure and attempt to find an http URL to * downloads a CRL from. */ static X509_CRL *load_crl_crldp(STACK_OF(DIST_POINT) *crldp) { int i; const char *urlptr = NULL; for (i = 0; i < sk_DIST_POINT_num(crldp); i++) { DIST_POINT *dp = sk_DIST_POINT_value(crldp, i); urlptr = get_dp_url(dp); if (urlptr != NULL) return load_crl(urlptr, FORMAT_UNDEF, 0, "CRL via CDP"); } return NULL; } /* * Example of downloading CRLs from CRLDP: * not usable for real world as it always downloads and doesn't cache anything. */ static STACK_OF(X509_CRL) *crls_http_cb(const X509_STORE_CTX *ctx, const X509_NAME *nm) { X509 *x; STACK_OF(X509_CRL) *crls = NULL; X509_CRL *crl; STACK_OF(DIST_POINT) *crldp; crls = sk_X509_CRL_new_null(); if (!crls) return NULL; x = X509_STORE_CTX_get_current_cert(ctx); crldp = X509_get_ext_d2i(x, NID_crl_distribution_points, NULL, NULL); crl = load_crl_crldp(crldp); sk_DIST_POINT_pop_free(crldp, DIST_POINT_free); if (!crl) { sk_X509_CRL_free(crls); return NULL; } sk_X509_CRL_push(crls, crl); /* Try to download delta CRL */ crldp = X509_get_ext_d2i(x, NID_freshest_crl, NULL, NULL); crl = load_crl_crldp(crldp); sk_DIST_POINT_pop_free(crldp, DIST_POINT_free); if (crl) sk_X509_CRL_push(crls, crl); return crls; } void store_setup_crl_download(X509_STORE *st) { X509_STORE_set_lookup_crls_cb(st, crls_http_cb); } #ifndef OPENSSL_NO_SOCK static const char *tls_error_hint(void) { unsigned long err = ERR_peek_error(); if (ERR_GET_LIB(err) != ERR_LIB_SSL) err = ERR_peek_last_error(); if (ERR_GET_LIB(err) != ERR_LIB_SSL) return NULL; switch (ERR_GET_REASON(err)) { case SSL_R_WRONG_VERSION_NUMBER: return "The server does not support (a suitable version of) TLS"; case SSL_R_UNKNOWN_PROTOCOL: return "The server does not support HTTPS"; case SSL_R_CERTIFICATE_VERIFY_FAILED: return "Cannot authenticate server via its TLS certificate, likely due to mismatch with our trusted TLS certs or missing revocation status"; case SSL_AD_REASON_OFFSET + TLS1_AD_UNKNOWN_CA: return "Server did not accept our TLS certificate, likely due to mismatch with server's trust anchor or missing revocation status"; case SSL_AD_REASON_OFFSET + SSL3_AD_HANDSHAKE_FAILURE: return "TLS handshake failure. Possibly the server requires our TLS certificate but did not receive it"; default: /* no error or no hint available for error */ return NULL; } } /* HTTP callback function that supports TLS connection also via HTTPS proxy */ BIO *app_http_tls_cb(BIO *bio, void *arg, int connect, int detail) { APP_HTTP_TLS_INFO *info = (APP_HTTP_TLS_INFO *)arg; SSL_CTX *ssl_ctx = info->ssl_ctx; if (ssl_ctx == NULL) /* not using TLS */ return bio; if (connect) { SSL *ssl; BIO *sbio = NULL; X509_STORE *ts = SSL_CTX_get_cert_store(ssl_ctx); X509_VERIFY_PARAM *vpm = X509_STORE_get0_param(ts); const char *host = vpm == NULL ? NULL : X509_VERIFY_PARAM_get0_host(vpm, 0 /* first hostname */); /* adapt after fixing callback design flaw, see #17088 */ if ((info->use_proxy && !OSSL_HTTP_proxy_connect(bio, info->server, info->port, NULL, NULL, /* no proxy credentials */ info->timeout, bio_err, opt_getprog())) || (sbio = BIO_new(BIO_f_ssl())) == NULL) { return NULL; } if (ssl_ctx == NULL || (ssl = SSL_new(ssl_ctx)) == NULL) { BIO_free(sbio); return NULL; } if (vpm != NULL) SSL_set_tlsext_host_name(ssl, host /* may be NULL */); SSL_set_connect_state(ssl); BIO_set_ssl(sbio, ssl, BIO_CLOSE); bio = BIO_push(sbio, bio); } if (!connect) { const char *hint; BIO *cbio; if (!detail) { /* disconnecting after error */ hint = tls_error_hint(); if (hint != NULL) ERR_add_error_data(2, " : ", hint); } if (ssl_ctx != NULL) { (void)ERR_set_mark(); BIO_ssl_shutdown(bio); cbio = BIO_pop(bio); /* connect+HTTP BIO */ BIO_free(bio); /* SSL BIO */ (void)ERR_pop_to_mark(); /* hide SSL_R_READ_BIO_NOT_SET etc. */ bio = cbio; } } return bio; } void APP_HTTP_TLS_INFO_free(APP_HTTP_TLS_INFO *info) { if (info != NULL) { SSL_CTX_free(info->ssl_ctx); OPENSSL_free(info); } } ASN1_VALUE *app_http_get_asn1(const char *url, const char *proxy, const char *no_proxy, SSL_CTX *ssl_ctx, const STACK_OF(CONF_VALUE) *headers, long timeout, const char *expected_content_type, const ASN1_ITEM *it) { APP_HTTP_TLS_INFO info; char *server; char *port; int use_ssl; BIO *mem; ASN1_VALUE *resp = NULL; if (url == NULL || it == NULL) { ERR_raise(ERR_LIB_HTTP, ERR_R_PASSED_NULL_PARAMETER); return NULL; } if (!OSSL_HTTP_parse_url(url, &use_ssl, NULL /* userinfo */, &server, &port, NULL /* port_num, */, NULL, NULL, NULL)) return NULL; if (use_ssl && ssl_ctx == NULL) { ERR_raise_data(ERR_LIB_HTTP, ERR_R_PASSED_NULL_PARAMETER, "missing SSL_CTX"); goto end; } if (!use_ssl && ssl_ctx != NULL) { ERR_raise_data(ERR_LIB_HTTP, ERR_R_PASSED_INVALID_ARGUMENT, "SSL_CTX given but use_ssl == 0"); goto end; } info.server = server; info.port = port; info.use_proxy = /* workaround for callback design flaw, see #17088 */ OSSL_HTTP_adapt_proxy(proxy, no_proxy, server, use_ssl) != NULL; info.timeout = timeout; info.ssl_ctx = ssl_ctx; mem = OSSL_HTTP_get(url, proxy, no_proxy, NULL /* bio */, NULL /* rbio */, app_http_tls_cb, &info, 0 /* buf_size */, headers, expected_content_type, 1 /* expect_asn1 */, OSSL_HTTP_DEFAULT_MAX_RESP_LEN, timeout); resp = ASN1_item_d2i_bio(it, mem, NULL); BIO_free(mem); end: OPENSSL_free(server); OPENSSL_free(port); return resp; } ASN1_VALUE *app_http_post_asn1(const char *host, const char *port, const char *path, const char *proxy, const char *no_proxy, SSL_CTX *ssl_ctx, const STACK_OF(CONF_VALUE) *headers, const char *content_type, ASN1_VALUE *req, const ASN1_ITEM *req_it, const char *expected_content_type, long timeout, const ASN1_ITEM *rsp_it) { int use_ssl = ssl_ctx != NULL; APP_HTTP_TLS_INFO info; BIO *rsp, *req_mem = ASN1_item_i2d_mem_bio(req_it, req); ASN1_VALUE *res; if (req_mem == NULL) return NULL; info.server = host; info.port = port; info.use_proxy = /* workaround for callback design flaw, see #17088 */ OSSL_HTTP_adapt_proxy(proxy, no_proxy, host, use_ssl) != NULL; info.timeout = timeout; info.ssl_ctx = ssl_ctx; rsp = OSSL_HTTP_transfer(NULL, host, port, path, use_ssl, proxy, no_proxy, NULL /* bio */, NULL /* rbio */, app_http_tls_cb, &info, 0 /* buf_size */, headers, content_type, req_mem, expected_content_type, 1 /* expect_asn1 */, OSSL_HTTP_DEFAULT_MAX_RESP_LEN, timeout, 0 /* keep_alive */); BIO_free(req_mem); res = ASN1_item_d2i_bio(rsp_it, rsp, NULL); BIO_free(rsp); return res; } #endif /* * Platform-specific sections */ #if defined(_WIN32) # ifdef fileno # undef fileno # define fileno(a) (int)_fileno(a) # endif # include # include static int WIN32_rename(const char *from, const char *to) { TCHAR *tfrom = NULL, *tto; DWORD err; int ret = 0; if (sizeof(TCHAR) == 1) { tfrom = (TCHAR *)from; tto = (TCHAR *)to; } else { /* UNICODE path */ size_t i, flen = strlen(from) + 1, tlen = strlen(to) + 1; tfrom = malloc(sizeof(*tfrom) * (flen + tlen)); if (tfrom == NULL) goto err; tto = tfrom + flen; # if !defined(_WIN32_WCE) || _WIN32_WCE>=101 if (!MultiByteToWideChar(CP_ACP, 0, from, flen, (WCHAR *)tfrom, flen)) # endif for (i = 0; i < flen; i++) tfrom[i] = (TCHAR)from[i]; # if !defined(_WIN32_WCE) || _WIN32_WCE>=101 if (!MultiByteToWideChar(CP_ACP, 0, to, tlen, (WCHAR *)tto, tlen)) # endif for (i = 0; i < tlen; i++) tto[i] = (TCHAR)to[i]; } if (MoveFile(tfrom, tto)) goto ok; err = GetLastError(); if (err == ERROR_ALREADY_EXISTS || err == ERROR_FILE_EXISTS) { if (DeleteFile(tto) && MoveFile(tfrom, tto)) goto ok; err = GetLastError(); } if (err == ERROR_FILE_NOT_FOUND || err == ERROR_PATH_NOT_FOUND) errno = ENOENT; else if (err == ERROR_ACCESS_DENIED) errno = EACCES; else errno = EINVAL; /* we could map more codes... */ err: ret = -1; ok: if (tfrom != NULL && tfrom != (TCHAR *)from) free(tfrom); return ret; } #endif /* app_tminterval section */ #if defined(_WIN32) double app_tminterval(int stop, int usertime) { FILETIME now; double ret = 0; static ULARGE_INTEGER tmstart; static int warning = 1; # ifdef _WIN32_WINNT static HANDLE proc = NULL; if (proc == NULL) { if (check_winnt()) proc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId()); if (proc == NULL) proc = (HANDLE) - 1; } if (usertime && proc != (HANDLE) - 1) { FILETIME junk; GetProcessTimes(proc, &junk, &junk, &junk, &now); } else # endif { SYSTEMTIME systime; if (usertime && warning) { BIO_printf(bio_err, "To get meaningful results, run " "this program on idle system.\n"); warning = 0; } GetSystemTime(&systime); SystemTimeToFileTime(&systime, &now); } if (stop == TM_START) { tmstart.u.LowPart = now.dwLowDateTime; tmstart.u.HighPart = now.dwHighDateTime; } else { ULARGE_INTEGER tmstop; tmstop.u.LowPart = now.dwLowDateTime; tmstop.u.HighPart = now.dwHighDateTime; ret = (__int64)(tmstop.QuadPart - tmstart.QuadPart) * 1e-7; } return ret; } #elif defined(OPENSSL_SYS_VXWORKS) # include double app_tminterval(int stop, int usertime) { double ret = 0; # ifdef CLOCK_REALTIME static struct timespec tmstart; struct timespec now; # else static unsigned long tmstart; unsigned long now; # endif static int warning = 1; if (usertime && warning) { BIO_printf(bio_err, "To get meaningful results, run " "this program on idle system.\n"); warning = 0; } # ifdef CLOCK_REALTIME clock_gettime(CLOCK_REALTIME, &now); if (stop == TM_START) tmstart = now; else ret = ((now.tv_sec + now.tv_nsec * 1e-9) - (tmstart.tv_sec + tmstart.tv_nsec * 1e-9)); # else now = tickGet(); if (stop == TM_START) tmstart = now; else ret = (now - tmstart) / (double)sysClkRateGet(); # endif return ret; } #elif defined(_SC_CLK_TCK) /* by means of unistd.h */ # include double app_tminterval(int stop, int usertime) { double ret = 0; struct tms rus; clock_t now = times(&rus); static clock_t tmstart; if (usertime) now = rus.tms_utime; if (stop == TM_START) { tmstart = now; } else { long int tck = sysconf(_SC_CLK_TCK); ret = (now - tmstart) / (double)tck; } return ret; } #else # include # include double app_tminterval(int stop, int usertime) { double ret = 0; struct rusage rus; struct timeval now; static struct timeval tmstart; if (usertime) getrusage(RUSAGE_SELF, &rus), now = rus.ru_utime; else gettimeofday(&now, NULL); if (stop == TM_START) tmstart = now; else ret = ((now.tv_sec + now.tv_usec * 1e-6) - (tmstart.tv_sec + tmstart.tv_usec * 1e-6)); return ret; } #endif int app_access(const char* name, int flag) { #ifdef _WIN32 return _access(name, flag); #else return access(name, flag); #endif } int app_isdir(const char *name) { return opt_isdir(name); } /* raw_read|write section */ #if defined(__VMS) # include "vms_term_sock.h" static int stdin_sock = -1; static void close_stdin_sock(void) { TerminalSocket (TERM_SOCK_DELETE, &stdin_sock); } int fileno_stdin(void) { if (stdin_sock == -1) { TerminalSocket(TERM_SOCK_CREATE, &stdin_sock); atexit(close_stdin_sock); } return stdin_sock; } #else int fileno_stdin(void) { return fileno(stdin); } #endif int fileno_stdout(void) { return fileno(stdout); } #if defined(_WIN32) && defined(STD_INPUT_HANDLE) int raw_read_stdin(void *buf, int siz) { DWORD n; if (ReadFile(GetStdHandle(STD_INPUT_HANDLE), buf, siz, &n, NULL)) return n; else return -1; } #elif defined(__VMS) # include int raw_read_stdin(void *buf, int siz) { return recv(fileno_stdin(), buf, siz, 0); } #else # if defined(__TANDEM) # if defined(OPENSSL_TANDEM_FLOSS) # include # endif # endif int raw_read_stdin(void *buf, int siz) { return read(fileno_stdin(), buf, siz); } #endif #if defined(_WIN32) && defined(STD_OUTPUT_HANDLE) int raw_write_stdout(const void *buf, int siz) { DWORD n; if (WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), buf, siz, &n, NULL)) return n; else return -1; } #elif defined(OPENSSL_SYS_TANDEM) && defined(OPENSSL_THREADS) && defined(_SPT_MODEL_) # if defined(__TANDEM) # if defined(OPENSSL_TANDEM_FLOSS) # include # endif # endif int raw_write_stdout(const void *buf,int siz) { return write(fileno(stdout),(void*)buf,siz); } #else # if defined(__TANDEM) # if defined(OPENSSL_TANDEM_FLOSS) # include # endif # endif int raw_write_stdout(const void *buf, int siz) { return write(fileno_stdout(), buf, siz); } #endif /* * Centralized handling of input and output files with format specification * The format is meant to show what the input and output is supposed to be, * and is therefore a show of intent more than anything else. However, it * does impact behavior on some platforms, such as differentiating between * text and binary input/output on non-Unix platforms */ BIO *dup_bio_in(int format) { return BIO_new_fp(stdin, BIO_NOCLOSE | (FMT_istext(format) ? BIO_FP_TEXT : 0)); } BIO *dup_bio_out(int format) { BIO *b = BIO_new_fp(stdout, BIO_NOCLOSE | (FMT_istext(format) ? BIO_FP_TEXT : 0)); void *prefix = NULL; if (b == NULL) return NULL; #ifdef OPENSSL_SYS_VMS if (FMT_istext(format)) b = BIO_push(BIO_new(BIO_f_linebuffer()), b); #endif if (FMT_istext(format) && (prefix = getenv("HARNESS_OSSL_PREFIX")) != NULL) { b = BIO_push(BIO_new(BIO_f_prefix()), b); BIO_set_prefix(b, prefix); } return b; } BIO *dup_bio_err(int format) { BIO *b = BIO_new_fp(stderr, BIO_NOCLOSE | (FMT_istext(format) ? BIO_FP_TEXT : 0)); #ifdef OPENSSL_SYS_VMS if (b != NULL && FMT_istext(format)) b = BIO_push(BIO_new(BIO_f_linebuffer()), b); #endif return b; } void unbuffer(FILE *fp) { /* * On VMS, setbuf() will only take 32-bit pointers, and a compilation * with /POINTER_SIZE=64 will give off a MAYLOSEDATA2 warning here. * However, we trust that the C RTL will never give us a FILE pointer * above the first 4 GB of memory, so we simply turn off the warning * temporarily. */ #if defined(OPENSSL_SYS_VMS) && defined(__DECC) # pragma environment save # pragma message disable maylosedata2 #endif setbuf(fp, NULL); #if defined(OPENSSL_SYS_VMS) && defined(__DECC) # pragma environment restore #endif } static const char *modestr(char mode, int format) { OPENSSL_assert(mode == 'a' || mode == 'r' || mode == 'w'); switch (mode) { case 'a': return FMT_istext(format) ? "a" : "ab"; case 'r': return FMT_istext(format) ? "r" : "rb"; case 'w': return FMT_istext(format) ? "w" : "wb"; } /* The assert above should make sure we never reach this point */ return NULL; } static const char *modeverb(char mode) { switch (mode) { case 'a': return "appending"; case 'r': return "reading"; case 'w': return "writing"; } return "(doing something)"; } /* * Open a file for writing, owner-read-only. */ BIO *bio_open_owner(const char *filename, int format, int private) { FILE *fp = NULL; BIO *b = NULL; int textmode, bflags; #ifndef OPENSSL_NO_POSIX_IO int fd = -1, mode; #endif if (!private || filename == NULL || strcmp(filename, "-") == 0) return bio_open_default(filename, 'w', format); textmode = FMT_istext(format); #ifndef OPENSSL_NO_POSIX_IO mode = O_WRONLY; # ifdef O_CREAT mode |= O_CREAT; # endif # ifdef O_TRUNC mode |= O_TRUNC; # endif if (!textmode) { # ifdef O_BINARY mode |= O_BINARY; # elif defined(_O_BINARY) mode |= _O_BINARY; # endif } # ifdef OPENSSL_SYS_VMS /* VMS doesn't have O_BINARY, it just doesn't make sense. But, * it still needs to know that we're going binary, or fdopen() * will fail with "invalid argument"... so we tell VMS what the * context is. */ if (!textmode) fd = open(filename, mode, 0600, "ctx=bin"); else # endif fd = open(filename, mode, 0600); if (fd < 0) goto err; fp = fdopen(fd, modestr('w', format)); #else /* OPENSSL_NO_POSIX_IO */ /* Have stdio but not Posix IO, do the best we can */ fp = fopen(filename, modestr('w', format)); #endif /* OPENSSL_NO_POSIX_IO */ if (fp == NULL) goto err; bflags = BIO_CLOSE; if (textmode) bflags |= BIO_FP_TEXT; b = BIO_new_fp(fp, bflags); if (b != NULL) return b; err: BIO_printf(bio_err, "%s: Can't open \"%s\" for writing, %s\n", opt_getprog(), filename, strerror(errno)); ERR_print_errors(bio_err); /* If we have fp, then fdopen took over fd, so don't close both. */ if (fp != NULL) fclose(fp); #ifndef OPENSSL_NO_POSIX_IO else if (fd >= 0) close(fd); #endif return NULL; } static BIO *bio_open_default_(const char *filename, char mode, int format, int quiet) { BIO *ret; if (filename == NULL || strcmp(filename, "-") == 0) { ret = mode == 'r' ? dup_bio_in(format) : dup_bio_out(format); if (quiet) { ERR_clear_error(); return ret; } if (ret != NULL) return ret; BIO_printf(bio_err, "Can't open %s, %s\n", mode == 'r' ? "stdin" : "stdout", strerror(errno)); } else { ret = BIO_new_file(filename, modestr(mode, format)); if (quiet) { ERR_clear_error(); return ret; } if (ret != NULL) return ret; BIO_printf(bio_err, "Can't open \"%s\" for %s, %s\n", filename, modeverb(mode), strerror(errno)); } ERR_print_errors(bio_err); return NULL; } BIO *bio_open_default(const char *filename, char mode, int format) { return bio_open_default_(filename, mode, format, 0); } BIO *bio_open_default_quiet(const char *filename, char mode, int format) { return bio_open_default_(filename, mode, format, 1); } void wait_for_async(SSL *s) { /* On Windows select only works for sockets, so we simply don't wait */ #ifndef OPENSSL_SYS_WINDOWS int width = 0; fd_set asyncfds; OSSL_ASYNC_FD *fds; size_t numfds; size_t i; if (!SSL_get_all_async_fds(s, NULL, &numfds)) return; if (numfds == 0) return; fds = app_malloc(sizeof(OSSL_ASYNC_FD) * numfds, "allocate async fds"); if (!SSL_get_all_async_fds(s, fds, &numfds)) { OPENSSL_free(fds); return; } FD_ZERO(&asyncfds); for (i = 0; i < numfds; i++) { if (width <= (int)fds[i]) width = (int)fds[i] + 1; openssl_fdset((int)fds[i], &asyncfds); } select(width, (void *)&asyncfds, NULL, NULL, NULL); OPENSSL_free(fds); #endif } /* if OPENSSL_SYS_WINDOWS is defined then so is OPENSSL_SYS_MSDOS */ #if defined(OPENSSL_SYS_MSDOS) int has_stdin_waiting(void) { # if defined(OPENSSL_SYS_WINDOWS) HANDLE inhand = GetStdHandle(STD_INPUT_HANDLE); DWORD events = 0; INPUT_RECORD inputrec; DWORD insize = 1; BOOL peeked; if (inhand == INVALID_HANDLE_VALUE) { return 0; } peeked = PeekConsoleInput(inhand, &inputrec, insize, &events); if (!peeked) { /* Probably redirected input? _kbhit() does not work in this case */ if (!feof(stdin)) { return 1; } return 0; } # endif return _kbhit(); } #endif /* Corrupt a signature by modifying final byte */ void corrupt_signature(const ASN1_STRING *signature) { unsigned char *s = signature->data; s[signature->length - 1] ^= 0x1; } int set_cert_times(X509 *x, const char *startdate, const char *enddate, int days) { if (startdate == NULL || strcmp(startdate, "today") == 0) { if (X509_gmtime_adj(X509_getm_notBefore(x), 0) == NULL) return 0; } else { if (!ASN1_TIME_set_string_X509(X509_getm_notBefore(x), startdate)) return 0; } if (enddate == NULL) { if (X509_time_adj_ex(X509_getm_notAfter(x), days, 0, NULL) == NULL) return 0; } else if (!ASN1_TIME_set_string_X509(X509_getm_notAfter(x), enddate)) { return 0; } return 1; } int set_crl_lastupdate(X509_CRL *crl, const char *lastupdate) { int ret = 0; ASN1_TIME *tm = ASN1_TIME_new(); if (tm == NULL) goto end; if (lastupdate == NULL) { if (X509_gmtime_adj(tm, 0) == NULL) goto end; } else { if (!ASN1_TIME_set_string_X509(tm, lastupdate)) goto end; } if (!X509_CRL_set1_lastUpdate(crl, tm)) goto end; ret = 1; end: ASN1_TIME_free(tm); return ret; } int set_crl_nextupdate(X509_CRL *crl, const char *nextupdate, long days, long hours, long secs) { int ret = 0; ASN1_TIME *tm = ASN1_TIME_new(); if (tm == NULL) goto end; if (nextupdate == NULL) { if (X509_time_adj_ex(tm, days, hours * 60 * 60 + secs, NULL) == NULL) goto end; } else { if (!ASN1_TIME_set_string_X509(tm, nextupdate)) goto end; } if (!X509_CRL_set1_nextUpdate(crl, tm)) goto end; ret = 1; end: ASN1_TIME_free(tm); return ret; } void make_uppercase(char *string) { int i; for (i = 0; string[i] != '\0'; i++) string[i] = toupper((unsigned char)string[i]); } /* This function is defined here due to visibility of bio_err */ int opt_printf_stderr(const char *fmt, ...) { va_list ap; int ret; va_start(ap, fmt); ret = BIO_vprintf(bio_err, fmt, ap); va_end(ap); return ret; } OSSL_PARAM *app_params_new_from_opts(STACK_OF(OPENSSL_STRING) *opts, const OSSL_PARAM *paramdefs) { OSSL_PARAM *params = NULL; size_t sz = (size_t)sk_OPENSSL_STRING_num(opts); size_t params_n; char *opt = "", *stmp, *vtmp = NULL; int found = 1; if (opts == NULL) return NULL; params = OPENSSL_zalloc(sizeof(OSSL_PARAM) * (sz + 1)); if (params == NULL) return NULL; for (params_n = 0; params_n < sz; params_n++) { opt = sk_OPENSSL_STRING_value(opts, (int)params_n); if ((stmp = OPENSSL_strdup(opt)) == NULL || (vtmp = strchr(stmp, ':')) == NULL) goto err; /* Replace ':' with 0 to terminate the string pointed to by stmp */ *vtmp = 0; /* Skip over the separator so that vmtp points to the value */ vtmp++; if (!OSSL_PARAM_allocate_from_text(¶ms[params_n], paramdefs, stmp, vtmp, strlen(vtmp), &found)) goto err; OPENSSL_free(stmp); } params[params_n] = OSSL_PARAM_construct_end(); return params; err: OPENSSL_free(stmp); BIO_printf(bio_err, "Parameter %s '%s'\n", found ? "error" : "unknown", opt); ERR_print_errors(bio_err); app_params_free(params); return NULL; } void app_params_free(OSSL_PARAM *params) { int i; if (params != NULL) { for (i = 0; params[i].key != NULL; ++i) OPENSSL_free(params[i].data); OPENSSL_free(params); } } EVP_PKEY *app_keygen(EVP_PKEY_CTX *ctx, const char *alg, int bits, int verbose) { EVP_PKEY *res = NULL; if (verbose && alg != NULL) { BIO_printf(bio_err, "Generating %s key", alg); if (bits > 0) BIO_printf(bio_err, " with %d bits\n", bits); else BIO_printf(bio_err, "\n"); } if (!RAND_status()) BIO_printf(bio_err, "Warning: generating random key material may take a long time\n" "if the system has a poor entropy source\n"); if (EVP_PKEY_keygen(ctx, &res) <= 0) - app_bail_out("%s: Error generating %s key\n", opt_getprog(), - alg != NULL ? alg : "asymmetric"); + BIO_printf(bio_err, "%s: Error generating %s key\n", opt_getprog(), + alg != NULL ? alg : "asymmetric"); return res; } EVP_PKEY *app_paramgen(EVP_PKEY_CTX *ctx, const char *alg) { EVP_PKEY *res = NULL; if (!RAND_status()) BIO_printf(bio_err, "Warning: generating random key parameters may take a long time\n" "if the system has a poor entropy source\n"); if (EVP_PKEY_paramgen(ctx, &res) <= 0) - app_bail_out("%s: Generating %s key parameters failed\n", - opt_getprog(), alg != NULL ? alg : "asymmetric"); + BIO_printf(bio_err, "%s: Generating %s key parameters failed\n", + opt_getprog(), alg != NULL ? alg : "asymmetric"); return res; } /* * Return non-zero if the legacy path is still an option. * This decision is based on the global command line operations and the * behaviour thus far. */ int opt_legacy_okay(void) { int provider_options = opt_provider_option_given(); int libctx = app_get0_libctx() != NULL || app_get0_propq() != NULL; /* * Having a provider option specified or a custom library context or * property query, is a sure sign we're not using legacy. */ if (provider_options || libctx) return 0; return 1; } diff --git a/crypto/openssl/apps/req.c b/crypto/openssl/apps/req.c index 926f0796bc8f..41191803aef4 100644 --- a/crypto/openssl/apps/req.c +++ b/crypto/openssl/apps/req.c @@ -1,1684 +1,1686 @@ /* * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ #include #include #include #include #include #include "apps.h" #include "progs.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef OPENSSL_NO_DSA # include #endif #define BITS "default_bits" #define KEYFILE "default_keyfile" #define PROMPT "prompt" #define DISTINGUISHED_NAME "distinguished_name" #define ATTRIBUTES "attributes" #define V3_EXTENSIONS "x509_extensions" #define REQ_EXTENSIONS "req_extensions" #define STRING_MASK "string_mask" #define UTF8_IN "utf8" #define DEFAULT_KEY_LENGTH 2048 #define MIN_KEY_LENGTH 512 #define DEFAULT_DAYS 30 /* default cert validity period in days */ #define UNSET_DAYS -2 /* -1 may be used for testing expiration checks */ #define EXT_COPY_UNSET -1 static int make_REQ(X509_REQ *req, EVP_PKEY *pkey, X509_NAME *fsubj, int mutlirdn, int attribs, unsigned long chtype); static int prompt_info(X509_REQ *req, STACK_OF(CONF_VALUE) *dn_sk, const char *dn_sect, STACK_OF(CONF_VALUE) *attr_sk, const char *attr_sect, int attribs, unsigned long chtype); static int auto_info(X509_REQ *req, STACK_OF(CONF_VALUE) *sk, STACK_OF(CONF_VALUE) *attr, int attribs, unsigned long chtype); static int add_attribute_object(X509_REQ *req, char *text, const char *def, char *value, int nid, int n_min, int n_max, unsigned long chtype); static int add_DN_object(X509_NAME *n, char *text, const char *def, char *value, int nid, int n_min, int n_max, unsigned long chtype, int mval); static int genpkey_cb(EVP_PKEY_CTX *ctx); static int build_data(char *text, const char *def, char *value, int n_min, int n_max, char *buf, const int buf_size, const char *desc1, const char *desc2); static int req_check_len(int len, int n_min, int n_max); static int check_end(const char *str, const char *end); static int join(char buf[], size_t buf_size, const char *name, const char *tail, const char *desc); static EVP_PKEY_CTX *set_keygen_ctx(const char *gstr, char **pkeytype, long *pkeylen, ENGINE *keygen_engine); static const char *section = "req"; static CONF *req_conf = NULL; static CONF *addext_conf = NULL; static int batch = 0; typedef enum OPTION_choice { OPT_COMMON, OPT_INFORM, OPT_OUTFORM, OPT_ENGINE, OPT_KEYGEN_ENGINE, OPT_KEY, OPT_PUBKEY, OPT_NEW, OPT_CONFIG, OPT_KEYFORM, OPT_IN, OPT_OUT, OPT_KEYOUT, OPT_PASSIN, OPT_PASSOUT, OPT_NEWKEY, OPT_PKEYOPT, OPT_SIGOPT, OPT_VFYOPT, OPT_BATCH, OPT_NEWHDR, OPT_MODULUS, OPT_VERIFY, OPT_NOENC, OPT_NODES, OPT_NOOUT, OPT_VERBOSE, OPT_UTF8, OPT_NAMEOPT, OPT_REQOPT, OPT_SUBJ, OPT_SUBJECT, OPT_TEXT, OPT_X509, OPT_CA, OPT_CAKEY, OPT_MULTIVALUE_RDN, OPT_DAYS, OPT_SET_SERIAL, OPT_COPY_EXTENSIONS, OPT_ADDEXT, OPT_EXTENSIONS, OPT_REQEXTS, OPT_PRECERT, OPT_MD, OPT_SECTION, OPT_R_ENUM, OPT_PROV_ENUM } OPTION_CHOICE; const OPTIONS req_options[] = { OPT_SECTION("General"), {"help", OPT_HELP, '-', "Display this summary"}, #ifndef OPENSSL_NO_ENGINE {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"}, {"keygen_engine", OPT_KEYGEN_ENGINE, 's', "Specify engine to be used for key generation operations"}, #endif {"in", OPT_IN, '<', "X.509 request input file (default stdin)"}, {"inform", OPT_INFORM, 'F', "Input format - DER or PEM"}, {"verify", OPT_VERIFY, '-', "Verify self-signature on the request"}, OPT_SECTION("Certificate"), {"new", OPT_NEW, '-', "New request"}, {"config", OPT_CONFIG, '<', "Request template file"}, {"section", OPT_SECTION, 's', "Config section to use (default \"req\")"}, {"utf8", OPT_UTF8, '-', "Input characters are UTF8 (default ASCII)"}, {"nameopt", OPT_NAMEOPT, 's', "Certificate subject/issuer name printing options"}, {"reqopt", OPT_REQOPT, 's', "Various request text options"}, {"text", OPT_TEXT, '-', "Text form of request"}, {"x509", OPT_X509, '-', "Output an X.509 certificate structure instead of a cert request"}, {"CA", OPT_CA, '<', "Issuer cert to use for signing a cert, implies -x509"}, {"CAkey", OPT_CAKEY, 's', "Issuer private key to use with -CA; default is -CA arg"}, {OPT_MORE_STR, 1, 1, "(Required by some CA's)"}, {"subj", OPT_SUBJ, 's', "Set or modify subject of request or cert"}, {"subject", OPT_SUBJECT, '-', "Print the subject of the output request or cert"}, {"multivalue-rdn", OPT_MULTIVALUE_RDN, '-', "Deprecated; multi-valued RDNs support is always on."}, {"days", OPT_DAYS, 'p', "Number of days cert is valid for"}, {"set_serial", OPT_SET_SERIAL, 's', "Serial number to use"}, {"copy_extensions", OPT_COPY_EXTENSIONS, 's', "copy extensions from request when using -x509"}, {"addext", OPT_ADDEXT, 's', "Additional cert extension key=value pair (may be given more than once)"}, {"extensions", OPT_EXTENSIONS, 's', "Cert extension section (override value in config file)"}, {"reqexts", OPT_REQEXTS, 's', "Request extension section (override value in config file)"}, {"precert", OPT_PRECERT, '-', "Add a poison extension to the generated cert (implies -new)"}, OPT_SECTION("Keys and Signing"), {"key", OPT_KEY, 's', "Key for signing, and to include unless -in given"}, {"keyform", OPT_KEYFORM, 'f', "Key file format (ENGINE, other values ignored)"}, {"pubkey", OPT_PUBKEY, '-', "Output public key"}, {"keyout", OPT_KEYOUT, '>', "File to write private key to"}, {"passin", OPT_PASSIN, 's', "Private key and certificate password source"}, {"passout", OPT_PASSOUT, 's', "Output file pass phrase source"}, {"newkey", OPT_NEWKEY, 's', "Generate new key with [:] or [:] or param:"}, {"pkeyopt", OPT_PKEYOPT, 's', "Public key options as opt:value"}, {"sigopt", OPT_SIGOPT, 's', "Signature parameter in n:v form"}, {"vfyopt", OPT_VFYOPT, 's', "Verification parameter in n:v form"}, {"", OPT_MD, '-', "Any supported digest"}, OPT_SECTION("Output"), {"out", OPT_OUT, '>', "Output file"}, {"outform", OPT_OUTFORM, 'F', "Output format - DER or PEM"}, {"batch", OPT_BATCH, '-', "Do not ask anything during request generation"}, {"verbose", OPT_VERBOSE, '-', "Verbose output"}, {"noenc", OPT_NOENC, '-', "Don't encrypt private keys"}, {"nodes", OPT_NODES, '-', "Don't encrypt private keys; deprecated"}, {"noout", OPT_NOOUT, '-', "Do not output REQ"}, {"newhdr", OPT_NEWHDR, '-', "Output \"NEW\" in the header lines"}, {"modulus", OPT_MODULUS, '-', "RSA modulus"}, OPT_R_OPTIONS, OPT_PROV_OPTIONS, {NULL} }; /* * An LHASH of strings, where each string is an extension name. */ static unsigned long ext_name_hash(const OPENSSL_STRING *a) { return OPENSSL_LH_strhash((const char *)a); } static int ext_name_cmp(const OPENSSL_STRING *a, const OPENSSL_STRING *b) { return strcmp((const char *)a, (const char *)b); } static void exts_cleanup(OPENSSL_STRING *x) { OPENSSL_free((char *)x); } /* * Is the |kv| key already duplicated? This is remarkably tricky to get right. * Return 0 if unique, -1 on runtime error; 1 if found or a syntax error. */ static int duplicated(LHASH_OF(OPENSSL_STRING) *addexts, char *kv) { char *p; size_t off; /* Check syntax. */ /* Skip leading whitespace, make a copy. */ while (*kv && isspace(_UC(*kv))) if (*++kv == '\0') return 1; if ((p = strchr(kv, '=')) == NULL) return 1; off = p - kv; if ((kv = OPENSSL_strdup(kv)) == NULL) return -1; /* Skip trailing space before the equal sign. */ for (p = kv + off; p > kv; --p) if (!isspace(_UC(p[-1]))) break; if (p == kv) { OPENSSL_free(kv); return 1; } *p = '\0'; /* Finally have a clean "key"; see if it's there [by attempt to add it]. */ p = (char *)lh_OPENSSL_STRING_insert(addexts, (OPENSSL_STRING *)kv); if (p != NULL) { OPENSSL_free(p); return 1; } else if (lh_OPENSSL_STRING_error(addexts)) { OPENSSL_free(kv); return -1; } return 0; } int req_main(int argc, char **argv) { ASN1_INTEGER *serial = NULL; BIO *out = NULL; ENGINE *e = NULL, *gen_eng = NULL; EVP_PKEY *pkey = NULL, *CAkey = NULL; EVP_PKEY_CTX *genctx = NULL; STACK_OF(OPENSSL_STRING) *pkeyopts = NULL, *sigopts = NULL, *vfyopts = NULL; LHASH_OF(OPENSSL_STRING) *addexts = NULL; X509 *new_x509 = NULL, *CAcert = NULL; X509_REQ *req = NULL; EVP_CIPHER *cipher = NULL; EVP_MD *md = NULL; int ext_copy = EXT_COPY_UNSET; BIO *addext_bio = NULL; char *extensions = NULL; const char *infile = NULL, *CAfile = NULL, *CAkeyfile = NULL; char *outfile = NULL, *keyfile = NULL, *digest = NULL; char *keyalgstr = NULL, *p, *prog, *passargin = NULL, *passargout = NULL; char *passin = NULL, *passout = NULL; char *nofree_passin = NULL, *nofree_passout = NULL; char *req_exts = NULL, *subj = NULL; X509_NAME *fsubj = NULL; char *template = default_config_file, *keyout = NULL; const char *keyalg = NULL; OPTION_CHOICE o; int days = UNSET_DAYS; int ret = 1, gen_x509 = 0, i = 0, newreq = 0, verbose = 0; int informat = FORMAT_UNDEF, outformat = FORMAT_PEM, keyform = FORMAT_UNDEF; int modulus = 0, multirdn = 1, verify = 0, noout = 0, text = 0; int noenc = 0, newhdr = 0, subject = 0, pubkey = 0, precert = 0; long newkey_len = -1; unsigned long chtype = MBSTRING_ASC, reqflag = 0; #ifndef OPENSSL_NO_DES cipher = (EVP_CIPHER *)EVP_des_ede3_cbc(); #endif prog = opt_init(argc, argv, req_options); while ((o = opt_next()) != OPT_EOF) { switch (o) { case OPT_EOF: case OPT_ERR: opthelp: BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); goto end; case OPT_HELP: opt_help(req_options); ret = 0; goto end; case OPT_INFORM: if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &informat)) goto opthelp; break; case OPT_OUTFORM: if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &outformat)) goto opthelp; break; case OPT_ENGINE: e = setup_engine(opt_arg(), 0); break; case OPT_KEYGEN_ENGINE: #ifndef OPENSSL_NO_ENGINE gen_eng = setup_engine(opt_arg(), 0); if (gen_eng == NULL) { BIO_printf(bio_err, "Can't find keygen engine %s\n", *argv); goto opthelp; } #endif break; case OPT_KEY: keyfile = opt_arg(); break; case OPT_PUBKEY: pubkey = 1; break; case OPT_NEW: newreq = 1; break; case OPT_CONFIG: template = opt_arg(); break; case OPT_SECTION: section = opt_arg(); break; case OPT_KEYFORM: if (!opt_format(opt_arg(), OPT_FMT_ANY, &keyform)) goto opthelp; break; case OPT_IN: infile = opt_arg(); break; case OPT_OUT: outfile = opt_arg(); break; case OPT_KEYOUT: keyout = opt_arg(); break; case OPT_PASSIN: passargin = opt_arg(); break; case OPT_PASSOUT: passargout = opt_arg(); break; case OPT_R_CASES: if (!opt_rand(o)) goto end; break; case OPT_PROV_CASES: if (!opt_provider(o)) goto end; break; case OPT_NEWKEY: keyalg = opt_arg(); newreq = 1; break; case OPT_PKEYOPT: if (pkeyopts == NULL) pkeyopts = sk_OPENSSL_STRING_new_null(); if (pkeyopts == NULL || !sk_OPENSSL_STRING_push(pkeyopts, opt_arg())) goto opthelp; break; case OPT_SIGOPT: if (!sigopts) sigopts = sk_OPENSSL_STRING_new_null(); if (!sigopts || !sk_OPENSSL_STRING_push(sigopts, opt_arg())) goto opthelp; break; case OPT_VFYOPT: if (!vfyopts) vfyopts = sk_OPENSSL_STRING_new_null(); if (!vfyopts || !sk_OPENSSL_STRING_push(vfyopts, opt_arg())) goto opthelp; break; case OPT_BATCH: batch = 1; break; case OPT_NEWHDR: newhdr = 1; break; case OPT_MODULUS: modulus = 1; break; case OPT_VERIFY: verify = 1; break; case OPT_NODES: case OPT_NOENC: noenc = 1; break; case OPT_NOOUT: noout = 1; break; case OPT_VERBOSE: verbose = 1; break; case OPT_UTF8: chtype = MBSTRING_UTF8; break; case OPT_NAMEOPT: if (!set_nameopt(opt_arg())) goto opthelp; break; case OPT_REQOPT: if (!set_cert_ex(&reqflag, opt_arg())) goto opthelp; break; case OPT_TEXT: text = 1; break; case OPT_X509: gen_x509 = 1; break; case OPT_CA: CAfile = opt_arg(); gen_x509 = 1; break; case OPT_CAKEY: CAkeyfile = opt_arg(); break; case OPT_DAYS: days = atoi(opt_arg()); if (days < -1) { BIO_printf(bio_err, "%s: -days parameter arg must be >= -1\n", prog); goto end; } break; case OPT_SET_SERIAL: if (serial != NULL) { BIO_printf(bio_err, "Serial number supplied twice\n"); goto opthelp; } serial = s2i_ASN1_INTEGER(NULL, opt_arg()); if (serial == NULL) goto opthelp; break; case OPT_SUBJECT: subject = 1; break; case OPT_SUBJ: subj = opt_arg(); break; case OPT_MULTIVALUE_RDN: /* obsolete */ break; case OPT_COPY_EXTENSIONS: if (!set_ext_copy(&ext_copy, opt_arg())) { BIO_printf(bio_err, "Invalid extension copy option: \"%s\"\n", opt_arg()); goto end; } break; case OPT_ADDEXT: p = opt_arg(); if (addexts == NULL) { addexts = lh_OPENSSL_STRING_new(ext_name_hash, ext_name_cmp); addext_bio = BIO_new(BIO_s_mem()); if (addexts == NULL || addext_bio == NULL) goto end; } i = duplicated(addexts, p); if (i == 1) { BIO_printf(bio_err, "Duplicate extension: %s\n", p); goto opthelp; } if (i < 0 || BIO_printf(addext_bio, "%s\n", p) < 0) goto end; break; case OPT_EXTENSIONS: extensions = opt_arg(); break; case OPT_REQEXTS: req_exts = opt_arg(); break; case OPT_PRECERT: newreq = precert = 1; break; case OPT_MD: digest = opt_unknown(); break; } } /* No extra arguments. */ argc = opt_num_rest(); if (argc != 0) goto opthelp; if (!app_RAND_load()) goto end; if (!gen_x509) { if (days != UNSET_DAYS) BIO_printf(bio_err, "Ignoring -days without -x509; not generating a certificate\n"); if (ext_copy == EXT_COPY_NONE) BIO_printf(bio_err, "Ignoring -copy_extensions 'none' when -x509 is not given\n"); } if (gen_x509 && infile == NULL) newreq = 1; if (!app_passwd(passargin, passargout, &passin, &passout)) { BIO_printf(bio_err, "Error getting passwords\n"); goto end; } if ((req_conf = app_load_config_verbose(template, verbose)) == NULL) goto end; if (addext_bio != NULL) { if (verbose) BIO_printf(bio_err, "Using additional configuration from -addext options\n"); if ((addext_conf = app_load_config_bio(addext_bio, NULL)) == NULL) goto end; } if (template != default_config_file && !app_load_modules(req_conf)) goto end; if (req_conf != NULL) { p = NCONF_get_string(req_conf, NULL, "oid_file"); if (p == NULL) ERR_clear_error(); if (p != NULL) { BIO *oid_bio = BIO_new_file(p, "r"); if (oid_bio == NULL) { if (verbose) BIO_printf(bio_err, "Problems opening '%s' for extra OIDs\n", p); } else { OBJ_create_objects(oid_bio); BIO_free(oid_bio); } } } if (!add_oid_section(req_conf)) goto end; /* Check that any specified digest is fetchable */ if (digest != NULL) { if (!opt_md(digest, &md)) { ERR_clear_error(); goto opthelp; } EVP_MD_free(md); } else { /* No digest specified, default to configuration */ p = NCONF_get_string(req_conf, section, "default_md"); if (p == NULL) ERR_clear_error(); else digest = p; } if (extensions == NULL) { extensions = NCONF_get_string(req_conf, section, V3_EXTENSIONS); if (extensions == NULL) ERR_clear_error(); } if (extensions != NULL) { /* Check syntax of file */ X509V3_CTX ctx; X509V3_set_ctx_test(&ctx); X509V3_set_nconf(&ctx, req_conf); if (!X509V3_EXT_add_nconf(req_conf, &ctx, extensions, NULL)) { BIO_printf(bio_err, "Error checking x509 extension section %s\n", extensions); goto end; } } if (addext_conf != NULL) { /* Check syntax of command line extensions */ X509V3_CTX ctx; X509V3_set_ctx_test(&ctx); X509V3_set_nconf(&ctx, addext_conf); if (!X509V3_EXT_add_nconf(addext_conf, &ctx, "default", NULL)) { BIO_printf(bio_err, "Error checking extensions defined using -addext\n"); goto end; } } if (passin == NULL) { passin = nofree_passin = NCONF_get_string(req_conf, section, "input_password"); if (passin == NULL) ERR_clear_error(); } if (passout == NULL) { passout = nofree_passout = NCONF_get_string(req_conf, section, "output_password"); if (passout == NULL) ERR_clear_error(); } p = NCONF_get_string(req_conf, section, STRING_MASK); if (p == NULL) ERR_clear_error(); if (p != NULL && !ASN1_STRING_set_default_mask_asc(p)) { BIO_printf(bio_err, "Invalid global string mask setting %s\n", p); goto end; } if (chtype != MBSTRING_UTF8) { p = NCONF_get_string(req_conf, section, UTF8_IN); if (p == NULL) ERR_clear_error(); else if (strcmp(p, "yes") == 0) chtype = MBSTRING_UTF8; } if (req_exts == NULL) { req_exts = NCONF_get_string(req_conf, section, REQ_EXTENSIONS); if (req_exts == NULL) ERR_clear_error(); } if (req_exts != NULL) { /* Check syntax of file */ X509V3_CTX ctx; X509V3_set_ctx_test(&ctx); X509V3_set_nconf(&ctx, req_conf); if (!X509V3_EXT_add_nconf(req_conf, &ctx, req_exts, NULL)) { BIO_printf(bio_err, "Error checking request extension section %s\n", req_exts); goto end; } } if (keyfile != NULL) { pkey = load_key(keyfile, keyform, 0, passin, e, "private key"); if (pkey == NULL) goto end; app_RAND_load_conf(req_conf, section); } if (newreq && pkey == NULL) { app_RAND_load_conf(req_conf, section); if (!NCONF_get_number(req_conf, section, BITS, &newkey_len)) { ERR_clear_error(); newkey_len = DEFAULT_KEY_LENGTH; } genctx = set_keygen_ctx(keyalg, &keyalgstr, &newkey_len, gen_eng); if (genctx == NULL) goto end; if (newkey_len < MIN_KEY_LENGTH && (EVP_PKEY_CTX_is_a(genctx, "RSA") || EVP_PKEY_CTX_is_a(genctx, "RSA-PSS") || EVP_PKEY_CTX_is_a(genctx, "DSA"))) { BIO_printf(bio_err, "Private key length too short, needs to be at least %d bits, not %ld.\n", MIN_KEY_LENGTH, newkey_len); goto end; } if (newkey_len > OPENSSL_RSA_MAX_MODULUS_BITS && (EVP_PKEY_CTX_is_a(genctx, "RSA") || EVP_PKEY_CTX_is_a(genctx, "RSA-PSS"))) BIO_printf(bio_err, "Warning: It is not recommended to use more than %d bit for RSA keys.\n" " Your key size is %ld! Larger key size may behave not as expected.\n", OPENSSL_RSA_MAX_MODULUS_BITS, newkey_len); #ifndef OPENSSL_NO_DSA if (EVP_PKEY_CTX_is_a(genctx, "DSA") && newkey_len > OPENSSL_DSA_MAX_MODULUS_BITS) BIO_printf(bio_err, "Warning: It is not recommended to use more than %d bit for DSA keys.\n" " Your key size is %ld! Larger key size may behave not as expected.\n", OPENSSL_DSA_MAX_MODULUS_BITS, newkey_len); #endif if (pkeyopts != NULL) { char *genopt; for (i = 0; i < sk_OPENSSL_STRING_num(pkeyopts); i++) { genopt = sk_OPENSSL_STRING_value(pkeyopts, i); if (pkey_ctrl_string(genctx, genopt) <= 0) { BIO_printf(bio_err, "Key parameter error \"%s\"\n", genopt); goto end; } } } EVP_PKEY_CTX_set_cb(genctx, genpkey_cb); EVP_PKEY_CTX_set_app_data(genctx, bio_err); pkey = app_keygen(genctx, keyalgstr, newkey_len, verbose); + if (pkey == NULL) + goto end; EVP_PKEY_CTX_free(genctx); genctx = NULL; } if (keyout == NULL && keyfile == NULL) { keyout = NCONF_get_string(req_conf, section, KEYFILE); if (keyout == NULL) ERR_clear_error(); } if (pkey != NULL && (keyfile == NULL || keyout != NULL)) { if (verbose) { BIO_printf(bio_err, "Writing private key to "); if (keyout == NULL) BIO_printf(bio_err, "stdout\n"); else BIO_printf(bio_err, "'%s'\n", keyout); } out = bio_open_owner(keyout, outformat, newreq); if (out == NULL) goto end; p = NCONF_get_string(req_conf, section, "encrypt_rsa_key"); if (p == NULL) { ERR_clear_error(); p = NCONF_get_string(req_conf, section, "encrypt_key"); if (p == NULL) ERR_clear_error(); } if ((p != NULL) && (strcmp(p, "no") == 0)) cipher = NULL; if (noenc) cipher = NULL; i = 0; loop: if (!PEM_write_bio_PrivateKey(out, pkey, cipher, NULL, 0, NULL, passout)) { if ((ERR_GET_REASON(ERR_peek_error()) == PEM_R_PROBLEMS_GETTING_PASSWORD) && (i < 3)) { ERR_clear_error(); i++; goto loop; } goto end; } BIO_free(out); out = NULL; BIO_printf(bio_err, "-----\n"); } /* * subj is expected to be in the format /type0=value0/type1=value1/type2=... * where characters may be escaped by \ */ if (subj != NULL && (fsubj = parse_name(subj, chtype, multirdn, "subject")) == NULL) goto end; if (!newreq) { req = load_csr(infile /* if NULL, reads from stdin */, informat, "X509 request"); if (req == NULL) goto end; } if (CAkeyfile == NULL) CAkeyfile = CAfile; if (CAkeyfile != NULL) { if (CAfile == NULL) { BIO_printf(bio_err, "Warning: Ignoring -CAkey option since no -CA option is given\n"); } else { if ((CAkey = load_key(CAkeyfile, FORMAT_UNDEF, 0, passin, e, CAkeyfile != CAfile ? "issuer private key from -CAkey arg" : "issuer private key from -CA arg")) == NULL) goto end; } } if (CAfile != NULL) { if ((CAcert = load_cert_pass(CAfile, FORMAT_UNDEF, 1, passin, "issuer cert from -CA arg")) == NULL) goto end; if (!X509_check_private_key(CAcert, CAkey)) { BIO_printf(bio_err, "Issuer CA certificate and key do not match\n"); goto end; } } if (newreq || gen_x509) { if (CAcert == NULL && pkey == NULL) { BIO_printf(bio_err, "Must provide a signature key using -key or" " provide -CA / -CAkey\n"); goto end; } if (req == NULL) { req = X509_REQ_new_ex(app_get0_libctx(), app_get0_propq()); if (req == NULL) { goto end; } if (!make_REQ(req, pkey, fsubj, multirdn, !gen_x509, chtype)){ BIO_printf(bio_err, "Error making certificate request\n"); goto end; } /* Note that -x509 can take over -key and -subj option values. */ } if (gen_x509) { EVP_PKEY *pub_key = X509_REQ_get0_pubkey(req); EVP_PKEY *issuer_key = CAcert != NULL ? CAkey : pkey; X509V3_CTX ext_ctx; X509_NAME *issuer = CAcert != NULL ? X509_get_subject_name(CAcert) : X509_REQ_get_subject_name(req); X509_NAME *n_subj = fsubj != NULL ? fsubj : X509_REQ_get_subject_name(req); if ((new_x509 = X509_new_ex(app_get0_libctx(), app_get0_propq())) == NULL) goto end; if (serial != NULL) { if (!X509_set_serialNumber(new_x509, serial)) goto end; } else { if (!rand_serial(NULL, X509_get_serialNumber(new_x509))) goto end; } if (!X509_set_issuer_name(new_x509, issuer)) goto end; if (days == UNSET_DAYS) { days = DEFAULT_DAYS; } if (!set_cert_times(new_x509, NULL, NULL, days)) goto end; if (!X509_set_subject_name(new_x509, n_subj)) goto end; if (!pub_key || !X509_set_pubkey(new_x509, pub_key)) goto end; if (ext_copy == EXT_COPY_UNSET) { if (infile != NULL) BIO_printf(bio_err, "Warning: No -copy_extensions given; ignoring any extensions in the request\n"); } else if (!copy_extensions(new_x509, req, ext_copy)) { BIO_printf(bio_err, "Error copying extensions from request\n"); goto end; } /* Set up V3 context struct */ X509V3_set_ctx(&ext_ctx, CAcert != NULL ? CAcert : new_x509, new_x509, NULL, NULL, X509V3_CTX_REPLACE); /* prepare fallback for AKID, but only if issuer cert == new_x509 */ if (CAcert == NULL) { if (!X509V3_set_issuer_pkey(&ext_ctx, issuer_key)) goto end; ERR_set_mark(); if (!X509_check_private_key(new_x509, issuer_key)) BIO_printf(bio_err, "Warning: Signature key and public key of cert do not match\n"); ERR_pop_to_mark(); } X509V3_set_nconf(&ext_ctx, req_conf); /* Add extensions */ if (extensions != NULL && !X509V3_EXT_add_nconf(req_conf, &ext_ctx, extensions, new_x509)) { BIO_printf(bio_err, "Error adding x509 extensions from section %s\n", extensions); goto end; } if (addext_conf != NULL && !X509V3_EXT_add_nconf(addext_conf, &ext_ctx, "default", new_x509)) { BIO_printf(bio_err, "Error adding extensions defined via -addext\n"); goto end; } /* If a pre-cert was requested, we need to add a poison extension */ if (precert) { if (X509_add1_ext_i2d(new_x509, NID_ct_precert_poison, NULL, 1, 0) != 1) { BIO_printf(bio_err, "Error adding poison extension\n"); goto end; } } i = do_X509_sign(new_x509, issuer_key, digest, sigopts, &ext_ctx); if (!i) goto end; } else { X509V3_CTX ext_ctx; /* Set up V3 context struct */ X509V3_set_ctx(&ext_ctx, NULL, NULL, req, NULL, 0); X509V3_set_nconf(&ext_ctx, req_conf); /* Add extensions */ if (req_exts != NULL && !X509V3_EXT_REQ_add_nconf(req_conf, &ext_ctx, req_exts, req)) { BIO_printf(bio_err, "Error adding request extensions from section %s\n", req_exts); goto end; } if (addext_conf != NULL && !X509V3_EXT_REQ_add_nconf(addext_conf, &ext_ctx, "default", req)) { BIO_printf(bio_err, "Error adding extensions defined via -addext\n"); goto end; } i = do_X509_REQ_sign(req, pkey, digest, sigopts); if (!i) goto end; } } if (subj != NULL && !newreq && !gen_x509) { if (verbose) { BIO_printf(out, "Modifying subject of certificate request\n"); print_name(out, "Old subject=", X509_REQ_get_subject_name(req)); } if (!X509_REQ_set_subject_name(req, fsubj)) { BIO_printf(bio_err, "Error modifying subject of certificate request\n"); goto end; } if (verbose) { print_name(out, "New subject=", X509_REQ_get_subject_name(req)); } } if (verify) { EVP_PKEY *tpubkey = pkey; if (tpubkey == NULL) { tpubkey = X509_REQ_get0_pubkey(req); if (tpubkey == NULL) goto end; } i = do_X509_REQ_verify(req, tpubkey, vfyopts); if (i < 0) goto end; if (i == 0) BIO_printf(bio_err, "Certificate request self-signature verify failure\n"); else /* i > 0 */ BIO_printf(bio_err, "Certificate request self-signature verify OK\n"); } if (noout && !text && !modulus && !subject && !pubkey) { ret = 0; goto end; } out = bio_open_default(outfile, keyout != NULL && outfile != NULL && strcmp(keyout, outfile) == 0 ? 'a' : 'w', outformat); if (out == NULL) goto end; if (pubkey) { EVP_PKEY *tpubkey = X509_REQ_get0_pubkey(req); if (tpubkey == NULL) { BIO_printf(bio_err, "Error getting public key\n"); goto end; } PEM_write_bio_PUBKEY(out, tpubkey); } if (text) { if (gen_x509) ret = X509_print_ex(out, new_x509, get_nameopt(), reqflag); else ret = X509_REQ_print_ex(out, req, get_nameopt(), reqflag); if (ret == 0) { if (gen_x509) BIO_printf(bio_err, "Error printing certificate\n"); else BIO_printf(bio_err, "Error printing certificate request\n"); goto end; } } if (subject) { print_name(out, "subject=", gen_x509 ? X509_get_subject_name(new_x509) : X509_REQ_get_subject_name(req)); } if (modulus) { EVP_PKEY *tpubkey; if (gen_x509) tpubkey = X509_get0_pubkey(new_x509); else tpubkey = X509_REQ_get0_pubkey(req); if (tpubkey == NULL) { BIO_puts(bio_err, "Modulus is unavailable\n"); goto end; } BIO_puts(out, "Modulus="); if (EVP_PKEY_is_a(tpubkey, "RSA") || EVP_PKEY_is_a(tpubkey, "RSA-PSS")) { BIGNUM *n = NULL; if (!EVP_PKEY_get_bn_param(tpubkey, "n", &n)) goto end; BN_print(out, n); BN_free(n); } else { BIO_puts(out, "Wrong Algorithm type"); } BIO_puts(out, "\n"); } if (!noout && !gen_x509) { if (outformat == FORMAT_ASN1) i = i2d_X509_REQ_bio(out, req); else if (newhdr) i = PEM_write_bio_X509_REQ_NEW(out, req); else i = PEM_write_bio_X509_REQ(out, req); if (!i) { BIO_printf(bio_err, "Unable to write certificate request\n"); goto end; } } if (!noout && gen_x509 && new_x509 != NULL) { if (outformat == FORMAT_ASN1) i = i2d_X509_bio(out, new_x509); else i = PEM_write_bio_X509(out, new_x509); if (!i) { BIO_printf(bio_err, "Unable to write X509 certificate\n"); goto end; } } ret = 0; end: if (ret) { ERR_print_errors(bio_err); } NCONF_free(req_conf); NCONF_free(addext_conf); BIO_free(addext_bio); BIO_free_all(out); EVP_PKEY_free(pkey); EVP_PKEY_CTX_free(genctx); sk_OPENSSL_STRING_free(pkeyopts); sk_OPENSSL_STRING_free(sigopts); sk_OPENSSL_STRING_free(vfyopts); lh_OPENSSL_STRING_doall(addexts, exts_cleanup); lh_OPENSSL_STRING_free(addexts); #ifndef OPENSSL_NO_ENGINE release_engine(gen_eng); #endif OPENSSL_free(keyalgstr); X509_REQ_free(req); X509_NAME_free(fsubj); X509_free(new_x509); X509_free(CAcert); EVP_PKEY_free(CAkey); ASN1_INTEGER_free(serial); release_engine(e); if (passin != nofree_passin) OPENSSL_free(passin); if (passout != nofree_passout) OPENSSL_free(passout); return ret; } static int make_REQ(X509_REQ *req, EVP_PKEY *pkey, X509_NAME *fsubj, int multirdn, int attribs, unsigned long chtype) { int ret = 0, i; char no_prompt = 0; STACK_OF(CONF_VALUE) *dn_sk = NULL, *attr_sk = NULL; char *tmp, *dn_sect, *attr_sect; tmp = NCONF_get_string(req_conf, section, PROMPT); if (tmp == NULL) ERR_clear_error(); if ((tmp != NULL) && strcmp(tmp, "no") == 0) no_prompt = 1; dn_sect = NCONF_get_string(req_conf, section, DISTINGUISHED_NAME); if (dn_sect == NULL) { ERR_clear_error(); } else { dn_sk = NCONF_get_section(req_conf, dn_sect); if (dn_sk == NULL) { BIO_printf(bio_err, "Unable to get '%s' section\n", dn_sect); goto err; } } attr_sect = NCONF_get_string(req_conf, section, ATTRIBUTES); if (attr_sect == NULL) { ERR_clear_error(); } else { attr_sk = NCONF_get_section(req_conf, attr_sect); if (attr_sk == NULL) { BIO_printf(bio_err, "Unable to get '%s' section\n", attr_sect); goto err; } } /* so far there is only version 1 */ if (!X509_REQ_set_version(req, X509_REQ_VERSION_1)) goto err; if (fsubj != NULL) i = X509_REQ_set_subject_name(req, fsubj); else if (no_prompt) i = auto_info(req, dn_sk, attr_sk, attribs, chtype); else i = prompt_info(req, dn_sk, dn_sect, attr_sk, attr_sect, attribs, chtype); if (!i) goto err; if (!X509_REQ_set_pubkey(req, pkey)) goto err; ret = 1; err: return ret; } static int prompt_info(X509_REQ *req, STACK_OF(CONF_VALUE) *dn_sk, const char *dn_sect, STACK_OF(CONF_VALUE) *attr_sk, const char *attr_sect, int attribs, unsigned long chtype) { int i; char *p, *q; char buf[100]; int nid, mval; long n_min, n_max; char *type, *value; const char *def; CONF_VALUE *v; X509_NAME *subj = X509_REQ_get_subject_name(req); if (!batch) { BIO_printf(bio_err, "You are about to be asked to enter information that will be incorporated\n"); BIO_printf(bio_err, "into your certificate request.\n"); BIO_printf(bio_err, "What you are about to enter is what is called a Distinguished Name or a DN.\n"); BIO_printf(bio_err, "There are quite a few fields but you can leave some blank\n"); BIO_printf(bio_err, "For some fields there will be a default value,\n"); BIO_printf(bio_err, "If you enter '.', the field will be left blank.\n"); BIO_printf(bio_err, "-----\n"); } if (sk_CONF_VALUE_num(dn_sk)) { i = -1; start: for (;;) { i++; if (sk_CONF_VALUE_num(dn_sk) <= i) break; v = sk_CONF_VALUE_value(dn_sk, i); p = q = NULL; type = v->name; if (!check_end(type, "_min") || !check_end(type, "_max") || !check_end(type, "_default") || !check_end(type, "_value")) continue; /* * Skip past any leading X. X: X, etc to allow for multiple * instances */ for (p = v->name; *p; p++) if ((*p == ':') || (*p == ',') || (*p == '.')) { p++; if (*p) type = p; break; } if (*type == '+') { mval = -1; type++; } else { mval = 0; } /* If OBJ not recognised ignore it */ if ((nid = OBJ_txt2nid(type)) == NID_undef) goto start; if (!join(buf, sizeof(buf), v->name, "_default", "Name")) return 0; if ((def = NCONF_get_string(req_conf, dn_sect, buf)) == NULL) { ERR_clear_error(); def = ""; } if (!join(buf, sizeof(buf), v->name, "_value", "Name")) return 0; if ((value = NCONF_get_string(req_conf, dn_sect, buf)) == NULL) { ERR_clear_error(); value = NULL; } if (!join(buf, sizeof(buf), v->name, "_min", "Name")) return 0; if (!NCONF_get_number(req_conf, dn_sect, buf, &n_min)) { ERR_clear_error(); n_min = -1; } if (!join(buf, sizeof(buf), v->name, "_max", "Name")) return 0; if (!NCONF_get_number(req_conf, dn_sect, buf, &n_max)) { ERR_clear_error(); n_max = -1; } if (!add_DN_object(subj, v->value, def, value, nid, n_min, n_max, chtype, mval)) return 0; } if (X509_NAME_entry_count(subj) == 0) { BIO_printf(bio_err, "Error: No objects specified in config file\n"); return 0; } if (attribs) { if ((attr_sk != NULL) && (sk_CONF_VALUE_num(attr_sk) > 0) && (!batch)) { BIO_printf(bio_err, "\nPlease enter the following 'extra' attributes\n"); BIO_printf(bio_err, "to be sent with your certificate request\n"); } i = -1; start2: for (;;) { i++; if ((attr_sk == NULL) || (sk_CONF_VALUE_num(attr_sk) <= i)) break; v = sk_CONF_VALUE_value(attr_sk, i); type = v->name; if ((nid = OBJ_txt2nid(type)) == NID_undef) goto start2; if (!join(buf, sizeof(buf), type, "_default", "Name")) return 0; if ((def = NCONF_get_string(req_conf, attr_sect, buf)) == NULL) { ERR_clear_error(); def = ""; } if (!join(buf, sizeof(buf), type, "_value", "Name")) return 0; if ((value = NCONF_get_string(req_conf, attr_sect, buf)) == NULL) { ERR_clear_error(); value = NULL; } if (!join(buf, sizeof(buf), type, "_min", "Name")) return 0; if (!NCONF_get_number(req_conf, attr_sect, buf, &n_min)) { ERR_clear_error(); n_min = -1; } if (!join(buf, sizeof(buf), type, "_max", "Name")) return 0; if (!NCONF_get_number(req_conf, attr_sect, buf, &n_max)) { ERR_clear_error(); n_max = -1; } if (!add_attribute_object(req, v->value, def, value, nid, n_min, n_max, chtype)) return 0; } } } else { BIO_printf(bio_err, "No template, please set one up.\n"); return 0; } return 1; } static int auto_info(X509_REQ *req, STACK_OF(CONF_VALUE) *dn_sk, STACK_OF(CONF_VALUE) *attr_sk, int attribs, unsigned long chtype) { int i, spec_char, plus_char; char *p, *q; char *type; CONF_VALUE *v; X509_NAME *subj; subj = X509_REQ_get_subject_name(req); for (i = 0; i < sk_CONF_VALUE_num(dn_sk); i++) { int mval; v = sk_CONF_VALUE_value(dn_sk, i); p = q = NULL; type = v->name; /* * Skip past any leading X. X: X, etc to allow for multiple instances */ for (p = v->name; *p; p++) { #ifndef CHARSET_EBCDIC spec_char = (*p == ':' || *p == ',' || *p == '.'); #else spec_char = (*p == os_toascii[':'] || *p == os_toascii[','] || *p == os_toascii['.']); #endif if (spec_char) { p++; if (*p) type = p; break; } } #ifndef CHARSET_EBCDIC plus_char = (*type == '+'); #else plus_char = (*type == os_toascii['+']); #endif if (plus_char) { type++; mval = -1; } else { mval = 0; } if (!X509_NAME_add_entry_by_txt(subj, type, chtype, (unsigned char *)v->value, -1, -1, mval)) return 0; } if (!X509_NAME_entry_count(subj)) { BIO_printf(bio_err, "Error: No objects specified in config file\n"); return 0; } if (attribs) { for (i = 0; i < sk_CONF_VALUE_num(attr_sk); i++) { v = sk_CONF_VALUE_value(attr_sk, i); if (!X509_REQ_add1_attr_by_txt(req, v->name, chtype, (unsigned char *)v->value, -1)) return 0; } } return 1; } static int add_DN_object(X509_NAME *n, char *text, const char *def, char *value, int nid, int n_min, int n_max, unsigned long chtype, int mval) { int ret = 0; char buf[1024]; ret = build_data(text, def, value, n_min, n_max, buf, sizeof(buf), "DN value", "DN default"); if ((ret == 0) || (ret == 1)) return ret; ret = 1; if (!X509_NAME_add_entry_by_NID(n, nid, chtype, (unsigned char *)buf, -1, -1, mval)) ret = 0; return ret; } static int add_attribute_object(X509_REQ *req, char *text, const char *def, char *value, int nid, int n_min, int n_max, unsigned long chtype) { int ret = 0; char buf[1024]; ret = build_data(text, def, value, n_min, n_max, buf, sizeof(buf), "Attribute value", "Attribute default"); if ((ret == 0) || (ret == 1)) return ret; ret = 1; if (!X509_REQ_add1_attr_by_NID(req, nid, chtype, (unsigned char *)buf, -1)) { BIO_printf(bio_err, "Error adding attribute\n"); ret = 0; } return ret; } static int build_data(char *text, const char *def, char *value, int n_min, int n_max, char *buf, const int buf_size, const char *desc1, const char *desc2) { int i; start: if (!batch) BIO_printf(bio_err, "%s [%s]:", text, def); (void)BIO_flush(bio_err); if (value != NULL) { if (!join(buf, buf_size, value, "\n", desc1)) return 0; BIO_printf(bio_err, "%s\n", value); } else { buf[0] = '\0'; if (!batch) { if (!fgets(buf, buf_size, stdin)) return 0; } else { buf[0] = '\n'; buf[1] = '\0'; } } if (buf[0] == '\0') return 0; if (buf[0] == '\n') { if ((def == NULL) || (def[0] == '\0')) return 1; if (!join(buf, buf_size, def, "\n", desc2)) return 0; } else if ((buf[0] == '.') && (buf[1] == '\n')) { return 1; } i = strlen(buf); if (buf[i - 1] != '\n') { BIO_printf(bio_err, "Missing newline at end of input\n"); return 0; } buf[--i] = '\0'; #ifdef CHARSET_EBCDIC ebcdic2ascii(buf, buf, i); #endif if (!req_check_len(i, n_min, n_max)) { if (batch || value) return 0; goto start; } return 2; } static int req_check_len(int len, int n_min, int n_max) { if (n_min > 0 && len < n_min) { BIO_printf(bio_err, "String too short, must be at least %d bytes long\n", n_min); return 0; } if (n_max >= 0 && len > n_max) { BIO_printf(bio_err, "String too long, must be at most %d bytes long\n", n_max); return 0; } return 1; } /* Check if the end of a string matches 'end' */ static int check_end(const char *str, const char *end) { size_t elen, slen; const char *tmp; elen = strlen(end); slen = strlen(str); if (elen > slen) return 1; tmp = str + slen - elen; return strcmp(tmp, end); } /* * Merge the two strings together into the result buffer checking for * overflow and producing an error message if there is. */ static int join(char buf[], size_t buf_size, const char *name, const char *tail, const char *desc) { const size_t name_len = strlen(name), tail_len = strlen(tail); if (name_len + tail_len + 1 > buf_size) { BIO_printf(bio_err, "%s '%s' too long\n", desc, name); return 0; } memcpy(buf, name, name_len); memcpy(buf + name_len, tail, tail_len + 1); return 1; } static EVP_PKEY_CTX *set_keygen_ctx(const char *gstr, char **pkeytype, long *pkeylen, ENGINE *keygen_engine) { EVP_PKEY_CTX *gctx = NULL; EVP_PKEY *param = NULL; long keylen = -1; BIO *pbio = NULL; const char *keytype = NULL; size_t keytypelen = 0; int expect_paramfile = 0; const char *paramfile = NULL; /* Treat the first part of gstr, and only that */ if (gstr == NULL) { /* * Special case: when no string given, default to RSA and the * key length given by |*pkeylen|. */ keytype = "RSA"; keylen = *pkeylen; } else if (gstr[0] >= '0' && gstr[0] <= '9') { /* Special case: only keylength given from string, so default to RSA */ keytype = "RSA"; /* The second part treatment will do the rest */ } else { const char *p = strchr(gstr, ':'); int len; if (p != NULL) len = p - gstr; else len = strlen(gstr); if (strncmp(gstr, "param", len) == 0) { expect_paramfile = 1; if (p == NULL) { BIO_printf(bio_err, "Parameter file requested but no path given: %s\n", gstr); return NULL; } } else { keytype = gstr; keytypelen = len; } if (p != NULL) gstr = gstr + len + 1; else gstr = NULL; } /* Treat the second part of gstr, if there is one */ if (gstr != NULL) { /* If the second part starts with a digit, we assume it's a size */ if (!expect_paramfile && gstr[0] >= '0' && gstr[0] <= '9') keylen = atol(gstr); else paramfile = gstr; } if (paramfile != NULL) { pbio = BIO_new_file(paramfile, "r"); if (pbio == NULL) { BIO_printf(bio_err, "Cannot open parameter file %s\n", paramfile); return NULL; } param = PEM_read_bio_Parameters(pbio, NULL); if (param == NULL) { X509 *x; (void)BIO_reset(pbio); x = PEM_read_bio_X509(pbio, NULL, NULL, NULL); if (x != NULL) { param = X509_get_pubkey(x); X509_free(x); } } BIO_free(pbio); if (param == NULL) { BIO_printf(bio_err, "Error reading parameter file %s\n", paramfile); return NULL; } if (keytype == NULL) { keytype = EVP_PKEY_get0_type_name(param); if (keytype == NULL) { EVP_PKEY_free(param); BIO_puts(bio_err, "Unable to determine key type\n"); return NULL; } } } if (keytypelen > 0) *pkeytype = OPENSSL_strndup(keytype, keytypelen); else *pkeytype = OPENSSL_strdup(keytype); if (*pkeytype == NULL) { BIO_printf(bio_err, "Out of memory\n"); EVP_PKEY_free(param); return NULL; } if (keylen >= 0) *pkeylen = keylen; if (param != NULL) { if (!EVP_PKEY_is_a(param, *pkeytype)) { BIO_printf(bio_err, "Key type does not match parameters\n"); EVP_PKEY_free(param); return NULL; } if (keygen_engine != NULL) gctx = EVP_PKEY_CTX_new(param, keygen_engine); else gctx = EVP_PKEY_CTX_new_from_pkey(app_get0_libctx(), param, app_get0_propq()); *pkeylen = EVP_PKEY_get_bits(param); EVP_PKEY_free(param); } else { if (keygen_engine != NULL) { int pkey_id = get_legacy_pkey_id(app_get0_libctx(), *pkeytype, keygen_engine); if (pkey_id != NID_undef) gctx = EVP_PKEY_CTX_new_id(pkey_id, keygen_engine); } else { gctx = EVP_PKEY_CTX_new_from_name(app_get0_libctx(), *pkeytype, app_get0_propq()); } } if (gctx == NULL) { BIO_puts(bio_err, "Error allocating keygen context\n"); return NULL; } if (EVP_PKEY_keygen_init(gctx) <= 0) { BIO_puts(bio_err, "Error initializing keygen context\n"); EVP_PKEY_CTX_free(gctx); return NULL; } if (keylen == -1 && (EVP_PKEY_CTX_is_a(gctx, "RSA") || EVP_PKEY_CTX_is_a(gctx, "RSA-PSS"))) keylen = *pkeylen; if (keylen != -1) { OSSL_PARAM params[] = { OSSL_PARAM_END, OSSL_PARAM_END }; size_t bits = keylen; params[0] = OSSL_PARAM_construct_size_t(OSSL_PKEY_PARAM_BITS, &bits); if (EVP_PKEY_CTX_set_params(gctx, params) <= 0) { BIO_puts(bio_err, "Error setting keysize\n"); EVP_PKEY_CTX_free(gctx); return NULL; } } return gctx; } static int genpkey_cb(EVP_PKEY_CTX *ctx) { char c = '*'; BIO *b = EVP_PKEY_CTX_get_app_data(ctx); int p; p = EVP_PKEY_CTX_get_keygen_info(ctx, 0); if (p == 0) c = '.'; if (p == 1) c = '+'; if (p == 2) c = '*'; if (p == 3) c = '\n'; BIO_write(b, &c, 1); (void)BIO_flush(b); return 1; } diff --git a/crypto/openssl/apps/speed.c b/crypto/openssl/apps/speed.c index f30435704d19..1113d775b8ab 100644 --- a/crypto/openssl/apps/speed.c +++ b/crypto/openssl/apps/speed.c @@ -1,3749 +1,3750 @@ /* * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ #undef SECONDS #define SECONDS 3 #define PKEY_SECONDS 10 #define RSA_SECONDS PKEY_SECONDS #define DSA_SECONDS PKEY_SECONDS #define ECDSA_SECONDS PKEY_SECONDS #define ECDH_SECONDS PKEY_SECONDS #define EdDSA_SECONDS PKEY_SECONDS #define SM2_SECONDS PKEY_SECONDS #define FFDH_SECONDS PKEY_SECONDS /* We need to use some deprecated APIs */ #define OPENSSL_SUPPRESS_DEPRECATED #include #include #include #include #include "apps.h" #include "progs.h" #include "internal/numbers.h" #include #include #include #include #include #include #include #if !defined(OPENSSL_SYS_MSDOS) # include #endif #if defined(__TANDEM) # if defined(OPENSSL_TANDEM_FLOSS) # include # endif #endif #if defined(_WIN32) # include #endif #include #include #include "./testrsa.h" #ifndef OPENSSL_NO_DH # include #endif #include #include #include "./testdsa.h" #include #ifndef HAVE_FORK # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_VXWORKS) # define HAVE_FORK 0 # else # define HAVE_FORK 1 # include # endif #endif #if HAVE_FORK # undef NO_FORK #else # define NO_FORK #endif #define MAX_MISALIGNMENT 63 #define MAX_ECDH_SIZE 256 #define MISALIGN 64 #define MAX_FFDH_SIZE 1024 #ifndef RSA_DEFAULT_PRIME_NUM # define RSA_DEFAULT_PRIME_NUM 2 #endif typedef struct openssl_speed_sec_st { int sym; int rsa; int dsa; int ecdsa; int ecdh; int eddsa; int sm2; int ffdh; } openssl_speed_sec_t; static volatile int run = 0; static int mr = 0; /* machine-readeable output format to merge fork results */ static int usertime = 1; static double Time_F(int s); static void print_message(const char *s, long num, int length, int tm); static void pkey_print_message(const char *str, const char *str2, long num, unsigned int bits, int sec); static void print_result(int alg, int run_no, int count, double time_used); #ifndef NO_FORK static int do_multi(int multi, int size_num); #endif static const int lengths_list[] = { 16, 64, 256, 1024, 8 * 1024, 16 * 1024 }; #define SIZE_NUM OSSL_NELEM(lengths_list) static const int *lengths = lengths_list; static const int aead_lengths_list[] = { 2, 31, 136, 1024, 8 * 1024, 16 * 1024 }; #define START 0 #define STOP 1 #ifdef SIGALRM static void alarmed(int sig) { signal(SIGALRM, alarmed); run = 0; } static double Time_F(int s) { double ret = app_tminterval(s, usertime); if (s == STOP) alarm(0); return ret; } #elif defined(_WIN32) # define SIGALRM -1 static unsigned int lapse; static volatile unsigned int schlock; static void alarm_win32(unsigned int secs) { lapse = secs * 1000; } # define alarm alarm_win32 static DWORD WINAPI sleepy(VOID * arg) { schlock = 1; Sleep(lapse); run = 0; return 0; } static double Time_F(int s) { double ret; static HANDLE thr; if (s == START) { schlock = 0; thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL); if (thr == NULL) { DWORD err = GetLastError(); BIO_printf(bio_err, "unable to CreateThread (%lu)", err); ExitProcess(err); } while (!schlock) Sleep(0); /* scheduler spinlock */ ret = app_tminterval(s, usertime); } else { ret = app_tminterval(s, usertime); if (run) TerminateThread(thr, 0); CloseHandle(thr); } return ret; } #else # error "SIGALRM not defined and the platform is not Windows" #endif static void multiblock_speed(const EVP_CIPHER *evp_cipher, int lengths_single, const openssl_speed_sec_t *seconds); static int opt_found(const char *name, unsigned int *result, const OPT_PAIR pairs[], unsigned int nbelem) { unsigned int idx; for (idx = 0; idx < nbelem; ++idx, pairs++) if (strcmp(name, pairs->name) == 0) { *result = pairs->retval; return 1; } return 0; } #define opt_found(value, pairs, result)\ opt_found(value, result, pairs, OSSL_NELEM(pairs)) typedef enum OPTION_choice { OPT_COMMON, OPT_ELAPSED, OPT_EVP, OPT_HMAC, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI, OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS, OPT_R_ENUM, OPT_PROV_ENUM, OPT_PRIMES, OPT_SECONDS, OPT_BYTES, OPT_AEAD, OPT_CMAC } OPTION_CHOICE; const OPTIONS speed_options[] = { {OPT_HELP_STR, 1, '-', "Usage: %s [options] [algorithm...]\n"}, OPT_SECTION("General"), {"help", OPT_HELP, '-', "Display this summary"}, {"mb", OPT_MB, '-', "Enable (tls1>=1) multi-block mode on EVP-named cipher"}, {"mr", OPT_MR, '-', "Produce machine readable output"}, #ifndef NO_FORK {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"}, #endif #ifndef OPENSSL_NO_ASYNC {"async_jobs", OPT_ASYNCJOBS, 'p', "Enable async mode and start specified number of jobs"}, #endif #ifndef OPENSSL_NO_ENGINE {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"}, #endif {"primes", OPT_PRIMES, 'p', "Specify number of primes (for RSA only)"}, OPT_SECTION("Selection"), {"evp", OPT_EVP, 's', "Use EVP-named cipher or digest"}, {"hmac", OPT_HMAC, 's', "HMAC using EVP-named digest"}, {"cmac", OPT_CMAC, 's', "CMAC using EVP-named cipher"}, {"decrypt", OPT_DECRYPT, '-', "Time decryption instead of encryption (only EVP)"}, {"aead", OPT_AEAD, '-', "Benchmark EVP-named AEAD cipher in TLS-like sequence"}, OPT_SECTION("Timing"), {"elapsed", OPT_ELAPSED, '-', "Use wall-clock time instead of CPU user time as divisor"}, {"seconds", OPT_SECONDS, 'p', "Run benchmarks for specified amount of seconds"}, {"bytes", OPT_BYTES, 'p', "Run [non-PKI] benchmarks on custom-sized buffer"}, {"misalign", OPT_MISALIGN, 'p', "Use specified offset to mis-align buffers"}, OPT_R_OPTIONS, OPT_PROV_OPTIONS, OPT_PARAMETERS(), {"algorithm", 0, 0, "Algorithm(s) to test (optional; otherwise tests all)"}, {NULL} }; enum { D_MD2, D_MDC2, D_MD4, D_MD5, D_SHA1, D_RMD160, D_SHA256, D_SHA512, D_WHIRLPOOL, D_HMAC, D_CBC_DES, D_EDE3_DES, D_RC4, D_CBC_IDEA, D_CBC_SEED, D_CBC_RC2, D_CBC_RC5, D_CBC_BF, D_CBC_CAST, D_CBC_128_AES, D_CBC_192_AES, D_CBC_256_AES, D_CBC_128_CML, D_CBC_192_CML, D_CBC_256_CML, D_EVP, D_GHASH, D_RAND, D_EVP_CMAC, ALGOR_NUM }; /* name of algorithms to test. MUST BE KEEP IN SYNC with above enum ! */ static const char *names[ALGOR_NUM] = { "md2", "mdc2", "md4", "md5", "sha1", "rmd160", "sha256", "sha512", "whirlpool", "hmac(md5)", "des-cbc", "des-ede3", "rc4", "idea-cbc", "seed-cbc", "rc2-cbc", "rc5-cbc", "blowfish", "cast-cbc", "aes-128-cbc", "aes-192-cbc", "aes-256-cbc", "camellia-128-cbc", "camellia-192-cbc", "camellia-256-cbc", "evp", "ghash", "rand", "cmac" }; /* list of configured algorithm (remaining), with some few alias */ static const OPT_PAIR doit_choices[] = { {"md2", D_MD2}, {"mdc2", D_MDC2}, {"md4", D_MD4}, {"md5", D_MD5}, {"hmac", D_HMAC}, {"sha1", D_SHA1}, {"sha256", D_SHA256}, {"sha512", D_SHA512}, {"whirlpool", D_WHIRLPOOL}, {"ripemd", D_RMD160}, {"rmd160", D_RMD160}, {"ripemd160", D_RMD160}, {"rc4", D_RC4}, {"des-cbc", D_CBC_DES}, {"des-ede3", D_EDE3_DES}, {"aes-128-cbc", D_CBC_128_AES}, {"aes-192-cbc", D_CBC_192_AES}, {"aes-256-cbc", D_CBC_256_AES}, {"camellia-128-cbc", D_CBC_128_CML}, {"camellia-192-cbc", D_CBC_192_CML}, {"camellia-256-cbc", D_CBC_256_CML}, {"rc2-cbc", D_CBC_RC2}, {"rc2", D_CBC_RC2}, {"rc5-cbc", D_CBC_RC5}, {"rc5", D_CBC_RC5}, {"idea-cbc", D_CBC_IDEA}, {"idea", D_CBC_IDEA}, {"seed-cbc", D_CBC_SEED}, {"seed", D_CBC_SEED}, {"bf-cbc", D_CBC_BF}, {"blowfish", D_CBC_BF}, {"bf", D_CBC_BF}, {"cast-cbc", D_CBC_CAST}, {"cast", D_CBC_CAST}, {"cast5", D_CBC_CAST}, {"ghash", D_GHASH}, {"rand", D_RAND} }; static double results[ALGOR_NUM][SIZE_NUM]; enum { R_DSA_512, R_DSA_1024, R_DSA_2048, DSA_NUM }; static const OPT_PAIR dsa_choices[DSA_NUM] = { {"dsa512", R_DSA_512}, {"dsa1024", R_DSA_1024}, {"dsa2048", R_DSA_2048} }; static double dsa_results[DSA_NUM][2]; /* 2 ops: sign then verify */ enum { R_RSA_512, R_RSA_1024, R_RSA_2048, R_RSA_3072, R_RSA_4096, R_RSA_7680, R_RSA_15360, RSA_NUM }; static const OPT_PAIR rsa_choices[RSA_NUM] = { {"rsa512", R_RSA_512}, {"rsa1024", R_RSA_1024}, {"rsa2048", R_RSA_2048}, {"rsa3072", R_RSA_3072}, {"rsa4096", R_RSA_4096}, {"rsa7680", R_RSA_7680}, {"rsa15360", R_RSA_15360} }; static double rsa_results[RSA_NUM][2]; /* 2 ops: sign then verify */ #ifndef OPENSSL_NO_DH enum ff_params_t { R_FFDH_2048, R_FFDH_3072, R_FFDH_4096, R_FFDH_6144, R_FFDH_8192, FFDH_NUM }; static const OPT_PAIR ffdh_choices[FFDH_NUM] = { {"ffdh2048", R_FFDH_2048}, {"ffdh3072", R_FFDH_3072}, {"ffdh4096", R_FFDH_4096}, {"ffdh6144", R_FFDH_6144}, {"ffdh8192", R_FFDH_8192}, }; static double ffdh_results[FFDH_NUM][1]; /* 1 op: derivation */ #endif /* OPENSSL_NO_DH */ enum ec_curves_t { R_EC_P160, R_EC_P192, R_EC_P224, R_EC_P256, R_EC_P384, R_EC_P521, #ifndef OPENSSL_NO_EC2M R_EC_K163, R_EC_K233, R_EC_K283, R_EC_K409, R_EC_K571, R_EC_B163, R_EC_B233, R_EC_B283, R_EC_B409, R_EC_B571, #endif R_EC_BRP256R1, R_EC_BRP256T1, R_EC_BRP384R1, R_EC_BRP384T1, R_EC_BRP512R1, R_EC_BRP512T1, ECDSA_NUM }; /* list of ecdsa curves */ static const OPT_PAIR ecdsa_choices[ECDSA_NUM] = { {"ecdsap160", R_EC_P160}, {"ecdsap192", R_EC_P192}, {"ecdsap224", R_EC_P224}, {"ecdsap256", R_EC_P256}, {"ecdsap384", R_EC_P384}, {"ecdsap521", R_EC_P521}, #ifndef OPENSSL_NO_EC2M {"ecdsak163", R_EC_K163}, {"ecdsak233", R_EC_K233}, {"ecdsak283", R_EC_K283}, {"ecdsak409", R_EC_K409}, {"ecdsak571", R_EC_K571}, {"ecdsab163", R_EC_B163}, {"ecdsab233", R_EC_B233}, {"ecdsab283", R_EC_B283}, {"ecdsab409", R_EC_B409}, {"ecdsab571", R_EC_B571}, #endif {"ecdsabrp256r1", R_EC_BRP256R1}, {"ecdsabrp256t1", R_EC_BRP256T1}, {"ecdsabrp384r1", R_EC_BRP384R1}, {"ecdsabrp384t1", R_EC_BRP384T1}, {"ecdsabrp512r1", R_EC_BRP512R1}, {"ecdsabrp512t1", R_EC_BRP512T1} }; enum { R_EC_X25519 = ECDSA_NUM, R_EC_X448, EC_NUM }; /* list of ecdh curves, extension of |ecdsa_choices| list above */ static const OPT_PAIR ecdh_choices[EC_NUM] = { {"ecdhp160", R_EC_P160}, {"ecdhp192", R_EC_P192}, {"ecdhp224", R_EC_P224}, {"ecdhp256", R_EC_P256}, {"ecdhp384", R_EC_P384}, {"ecdhp521", R_EC_P521}, #ifndef OPENSSL_NO_EC2M {"ecdhk163", R_EC_K163}, {"ecdhk233", R_EC_K233}, {"ecdhk283", R_EC_K283}, {"ecdhk409", R_EC_K409}, {"ecdhk571", R_EC_K571}, {"ecdhb163", R_EC_B163}, {"ecdhb233", R_EC_B233}, {"ecdhb283", R_EC_B283}, {"ecdhb409", R_EC_B409}, {"ecdhb571", R_EC_B571}, #endif {"ecdhbrp256r1", R_EC_BRP256R1}, {"ecdhbrp256t1", R_EC_BRP256T1}, {"ecdhbrp384r1", R_EC_BRP384R1}, {"ecdhbrp384t1", R_EC_BRP384T1}, {"ecdhbrp512r1", R_EC_BRP512R1}, {"ecdhbrp512t1", R_EC_BRP512T1}, {"ecdhx25519", R_EC_X25519}, {"ecdhx448", R_EC_X448} }; static double ecdh_results[EC_NUM][1]; /* 1 op: derivation */ static double ecdsa_results[ECDSA_NUM][2]; /* 2 ops: sign then verify */ enum { R_EC_Ed25519, R_EC_Ed448, EdDSA_NUM }; static const OPT_PAIR eddsa_choices[EdDSA_NUM] = { {"ed25519", R_EC_Ed25519}, {"ed448", R_EC_Ed448} }; static double eddsa_results[EdDSA_NUM][2]; /* 2 ops: sign then verify */ #ifndef OPENSSL_NO_SM2 enum { R_EC_CURVESM2, SM2_NUM }; static const OPT_PAIR sm2_choices[SM2_NUM] = { {"curveSM2", R_EC_CURVESM2} }; # define SM2_ID "TLSv1.3+GM+Cipher+Suite" # define SM2_ID_LEN sizeof("TLSv1.3+GM+Cipher+Suite") - 1 static double sm2_results[SM2_NUM][2]; /* 2 ops: sign then verify */ #endif /* OPENSSL_NO_SM2 */ #define COND(unused_cond) (run && count < INT_MAX) #define COUNT(d) (count) typedef struct loopargs_st { ASYNC_JOB *inprogress_job; ASYNC_WAIT_CTX *wait_ctx; unsigned char *buf; unsigned char *buf2; unsigned char *buf_malloc; unsigned char *buf2_malloc; unsigned char *key; size_t buflen; size_t sigsize; EVP_PKEY_CTX *rsa_sign_ctx[RSA_NUM]; EVP_PKEY_CTX *rsa_verify_ctx[RSA_NUM]; EVP_PKEY_CTX *dsa_sign_ctx[DSA_NUM]; EVP_PKEY_CTX *dsa_verify_ctx[DSA_NUM]; EVP_PKEY_CTX *ecdsa_sign_ctx[ECDSA_NUM]; EVP_PKEY_CTX *ecdsa_verify_ctx[ECDSA_NUM]; EVP_PKEY_CTX *ecdh_ctx[EC_NUM]; EVP_MD_CTX *eddsa_ctx[EdDSA_NUM]; EVP_MD_CTX *eddsa_ctx2[EdDSA_NUM]; #ifndef OPENSSL_NO_SM2 EVP_MD_CTX *sm2_ctx[SM2_NUM]; EVP_MD_CTX *sm2_vfy_ctx[SM2_NUM]; EVP_PKEY *sm2_pkey[SM2_NUM]; #endif unsigned char *secret_a; unsigned char *secret_b; size_t outlen[EC_NUM]; #ifndef OPENSSL_NO_DH EVP_PKEY_CTX *ffdh_ctx[FFDH_NUM]; unsigned char *secret_ff_a; unsigned char *secret_ff_b; #endif EVP_CIPHER_CTX *ctx; EVP_MAC_CTX *mctx; } loopargs_t; static int run_benchmark(int async_jobs, int (*loop_function) (void *), loopargs_t * loopargs); static unsigned int testnum; /* Nb of iterations to do per algorithm and key-size */ static long c[ALGOR_NUM][SIZE_NUM]; static char *evp_mac_mdname = "md5"; static char *evp_hmac_name = NULL; static const char *evp_md_name = NULL; static char *evp_mac_ciphername = "aes-128-cbc"; static char *evp_cmac_name = NULL; static int have_md(const char *name) { int ret = 0; EVP_MD *md = NULL; if (opt_md_silent(name, &md)) { EVP_MD_CTX *ctx = EVP_MD_CTX_new(); if (ctx != NULL && EVP_DigestInit(ctx, md) > 0) ret = 1; EVP_MD_CTX_free(ctx); EVP_MD_free(md); } return ret; } static int have_cipher(const char *name) { int ret = 0; EVP_CIPHER *cipher = NULL; if (opt_cipher_silent(name, &cipher)) { EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); if (ctx != NULL && EVP_CipherInit_ex(ctx, cipher, NULL, NULL, NULL, 1) > 0) ret = 1; EVP_CIPHER_CTX_free(ctx); EVP_CIPHER_free(cipher); } return ret; } static int EVP_Digest_loop(const char *mdname, int algindex, void *args) { loopargs_t *tempargs = *(loopargs_t **) args; unsigned char *buf = tempargs->buf; unsigned char digest[EVP_MAX_MD_SIZE]; int count; EVP_MD *md = NULL; if (!opt_md_silent(mdname, &md)) return -1; for (count = 0; COND(c[algindex][testnum]); count++) { if (!EVP_Digest(buf, (size_t)lengths[testnum], digest, NULL, md, NULL)) { count = -1; break; } } EVP_MD_free(md); return count; } static int EVP_Digest_md_loop(void *args) { return EVP_Digest_loop(evp_md_name, D_EVP, args); } static int EVP_Digest_MD2_loop(void *args) { return EVP_Digest_loop("md2", D_MD2, args); } static int EVP_Digest_MDC2_loop(void *args) { return EVP_Digest_loop("mdc2", D_MDC2, args); } static int EVP_Digest_MD4_loop(void *args) { return EVP_Digest_loop("md4", D_MD4, args); } static int MD5_loop(void *args) { return EVP_Digest_loop("md5", D_MD5, args); } static int EVP_MAC_loop(int algindex, void *args) { loopargs_t *tempargs = *(loopargs_t **) args; unsigned char *buf = tempargs->buf; EVP_MAC_CTX *mctx = tempargs->mctx; unsigned char mac[EVP_MAX_MD_SIZE]; int count; for (count = 0; COND(c[algindex][testnum]); count++) { size_t outl; if (!EVP_MAC_init(mctx, NULL, 0, NULL) || !EVP_MAC_update(mctx, buf, lengths[testnum]) || !EVP_MAC_final(mctx, mac, &outl, sizeof(mac))) return -1; } return count; } static int HMAC_loop(void *args) { return EVP_MAC_loop(D_HMAC, args); } static int CMAC_loop(void *args) { return EVP_MAC_loop(D_EVP_CMAC, args); } static int SHA1_loop(void *args) { return EVP_Digest_loop("sha1", D_SHA1, args); } static int SHA256_loop(void *args) { return EVP_Digest_loop("sha256", D_SHA256, args); } static int SHA512_loop(void *args) { return EVP_Digest_loop("sha512", D_SHA512, args); } static int WHIRLPOOL_loop(void *args) { return EVP_Digest_loop("whirlpool", D_WHIRLPOOL, args); } static int EVP_Digest_RMD160_loop(void *args) { return EVP_Digest_loop("ripemd160", D_RMD160, args); } static int algindex; static int EVP_Cipher_loop(void *args) { loopargs_t *tempargs = *(loopargs_t **) args; unsigned char *buf = tempargs->buf; int count; if (tempargs->ctx == NULL) return -1; for (count = 0; COND(c[algindex][testnum]); count++) if (EVP_Cipher(tempargs->ctx, buf, buf, (size_t)lengths[testnum]) <= 0) return -1; return count; } static int GHASH_loop(void *args) { loopargs_t *tempargs = *(loopargs_t **) args; unsigned char *buf = tempargs->buf; EVP_MAC_CTX *mctx = tempargs->mctx; int count; /* just do the update in the loop to be comparable with 1.1.1 */ for (count = 0; COND(c[D_GHASH][testnum]); count++) { if (!EVP_MAC_update(mctx, buf, lengths[testnum])) return -1; } return count; } #define MAX_BLOCK_SIZE 128 static unsigned char iv[2 * MAX_BLOCK_SIZE / 8]; static EVP_CIPHER_CTX *init_evp_cipher_ctx(const char *ciphername, const unsigned char *key, int keylen) { EVP_CIPHER_CTX *ctx = NULL; EVP_CIPHER *cipher = NULL; if (!opt_cipher_silent(ciphername, &cipher)) return NULL; if ((ctx = EVP_CIPHER_CTX_new()) == NULL) goto end; if (!EVP_CipherInit_ex(ctx, cipher, NULL, NULL, NULL, 1)) { EVP_CIPHER_CTX_free(ctx); ctx = NULL; goto end; } if (EVP_CIPHER_CTX_set_key_length(ctx, keylen) <= 0) { EVP_CIPHER_CTX_free(ctx); ctx = NULL; goto end; } if (!EVP_CipherInit_ex(ctx, NULL, NULL, key, iv, 1)) { EVP_CIPHER_CTX_free(ctx); ctx = NULL; goto end; } end: EVP_CIPHER_free(cipher); return ctx; } static int RAND_bytes_loop(void *args) { loopargs_t *tempargs = *(loopargs_t **) args; unsigned char *buf = tempargs->buf; int count; for (count = 0; COND(c[D_RAND][testnum]); count++) RAND_bytes(buf, lengths[testnum]); return count; } static int decrypt = 0; static int EVP_Update_loop(void *args) { loopargs_t *tempargs = *(loopargs_t **) args; unsigned char *buf = tempargs->buf; EVP_CIPHER_CTX *ctx = tempargs->ctx; int outl, count, rc; if (decrypt) { for (count = 0; COND(c[D_EVP][testnum]); count++) { rc = EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]); if (rc != 1) { /* reset iv in case of counter overflow */ EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv, -1); } } } else { for (count = 0; COND(c[D_EVP][testnum]); count++) { rc = EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]); if (rc != 1) { /* reset iv in case of counter overflow */ EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv, -1); } } } if (decrypt) EVP_DecryptFinal_ex(ctx, buf, &outl); else EVP_EncryptFinal_ex(ctx, buf, &outl); return count; } /* * CCM does not support streaming. For the purpose of performance measurement, * each message is encrypted using the same (key,iv)-pair. Do not use this * code in your application. */ static int EVP_Update_loop_ccm(void *args) { loopargs_t *tempargs = *(loopargs_t **) args; unsigned char *buf = tempargs->buf; EVP_CIPHER_CTX *ctx = tempargs->ctx; int outl, count; unsigned char tag[12]; if (decrypt) { for (count = 0; COND(c[D_EVP][testnum]); count++) { (void)EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, sizeof(tag), tag); /* reset iv */ (void)EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv); /* counter is reset on every update */ (void)EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]); } } else { for (count = 0; COND(c[D_EVP][testnum]); count++) { /* restore iv length field */ (void)EVP_EncryptUpdate(ctx, NULL, &outl, NULL, lengths[testnum]); /* counter is reset on every update */ (void)EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]); } } if (decrypt) (void)EVP_DecryptFinal_ex(ctx, buf, &outl); else (void)EVP_EncryptFinal_ex(ctx, buf, &outl); return count; } /* * To make AEAD benchmarking more relevant perform TLS-like operations, * 13-byte AAD followed by payload. But don't use TLS-formatted AAD, as * payload length is not actually limited by 16KB... */ static int EVP_Update_loop_aead(void *args) { loopargs_t *tempargs = *(loopargs_t **) args; unsigned char *buf = tempargs->buf; EVP_CIPHER_CTX *ctx = tempargs->ctx; int outl, count; unsigned char aad[13] = { 0xcc }; unsigned char faketag[16] = { 0xcc }; if (decrypt) { for (count = 0; COND(c[D_EVP][testnum]); count++) { (void)EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv); (void)EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, sizeof(faketag), faketag); (void)EVP_DecryptUpdate(ctx, NULL, &outl, aad, sizeof(aad)); (void)EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]); (void)EVP_DecryptFinal_ex(ctx, buf + outl, &outl); } } else { for (count = 0; COND(c[D_EVP][testnum]); count++) { (void)EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv); (void)EVP_EncryptUpdate(ctx, NULL, &outl, aad, sizeof(aad)); (void)EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]); (void)EVP_EncryptFinal_ex(ctx, buf + outl, &outl); } } return count; } static long rsa_c[RSA_NUM][2]; /* # RSA iteration test */ static int RSA_sign_loop(void *args) { loopargs_t *tempargs = *(loopargs_t **) args; unsigned char *buf = tempargs->buf; unsigned char *buf2 = tempargs->buf2; size_t *rsa_num = &tempargs->sigsize; EVP_PKEY_CTX **rsa_sign_ctx = tempargs->rsa_sign_ctx; int ret, count; for (count = 0; COND(rsa_c[testnum][0]); count++) { *rsa_num = tempargs->buflen; ret = EVP_PKEY_sign(rsa_sign_ctx[testnum], buf2, rsa_num, buf, 36); if (ret <= 0) { BIO_printf(bio_err, "RSA sign failure\n"); ERR_print_errors(bio_err); count = -1; break; } } return count; } static int RSA_verify_loop(void *args) { loopargs_t *tempargs = *(loopargs_t **) args; unsigned char *buf = tempargs->buf; unsigned char *buf2 = tempargs->buf2; size_t rsa_num = tempargs->sigsize; EVP_PKEY_CTX **rsa_verify_ctx = tempargs->rsa_verify_ctx; int ret, count; for (count = 0; COND(rsa_c[testnum][1]); count++) { ret = EVP_PKEY_verify(rsa_verify_ctx[testnum], buf2, rsa_num, buf, 36); if (ret <= 0) { BIO_printf(bio_err, "RSA verify failure\n"); ERR_print_errors(bio_err); count = -1; break; } } return count; } #ifndef OPENSSL_NO_DH static long ffdh_c[FFDH_NUM][1]; static int FFDH_derive_key_loop(void *args) { loopargs_t *tempargs = *(loopargs_t **) args; EVP_PKEY_CTX *ffdh_ctx = tempargs->ffdh_ctx[testnum]; unsigned char *derived_secret = tempargs->secret_ff_a; int count; for (count = 0; COND(ffdh_c[testnum][0]); count++) { /* outlen can be overwritten with a too small value (no padding used) */ size_t outlen = MAX_FFDH_SIZE; EVP_PKEY_derive(ffdh_ctx, derived_secret, &outlen); } return count; } #endif /* OPENSSL_NO_DH */ static long dsa_c[DSA_NUM][2]; static int DSA_sign_loop(void *args) { loopargs_t *tempargs = *(loopargs_t **) args; unsigned char *buf = tempargs->buf; unsigned char *buf2 = tempargs->buf2; size_t *dsa_num = &tempargs->sigsize; EVP_PKEY_CTX **dsa_sign_ctx = tempargs->dsa_sign_ctx; int ret, count; for (count = 0; COND(dsa_c[testnum][0]); count++) { *dsa_num = tempargs->buflen; ret = EVP_PKEY_sign(dsa_sign_ctx[testnum], buf2, dsa_num, buf, 20); if (ret <= 0) { BIO_printf(bio_err, "DSA sign failure\n"); ERR_print_errors(bio_err); count = -1; break; } } return count; } static int DSA_verify_loop(void *args) { loopargs_t *tempargs = *(loopargs_t **) args; unsigned char *buf = tempargs->buf; unsigned char *buf2 = tempargs->buf2; size_t dsa_num = tempargs->sigsize; EVP_PKEY_CTX **dsa_verify_ctx = tempargs->dsa_verify_ctx; int ret, count; for (count = 0; COND(dsa_c[testnum][1]); count++) { ret = EVP_PKEY_verify(dsa_verify_ctx[testnum], buf2, dsa_num, buf, 20); if (ret <= 0) { BIO_printf(bio_err, "DSA verify failure\n"); ERR_print_errors(bio_err); count = -1; break; } } return count; } static long ecdsa_c[ECDSA_NUM][2]; static int ECDSA_sign_loop(void *args) { loopargs_t *tempargs = *(loopargs_t **) args; unsigned char *buf = tempargs->buf; unsigned char *buf2 = tempargs->buf2; size_t *ecdsa_num = &tempargs->sigsize; EVP_PKEY_CTX **ecdsa_sign_ctx = tempargs->ecdsa_sign_ctx; int ret, count; for (count = 0; COND(ecdsa_c[testnum][0]); count++) { *ecdsa_num = tempargs->buflen; ret = EVP_PKEY_sign(ecdsa_sign_ctx[testnum], buf2, ecdsa_num, buf, 20); if (ret <= 0) { BIO_printf(bio_err, "ECDSA sign failure\n"); ERR_print_errors(bio_err); count = -1; break; } } return count; } static int ECDSA_verify_loop(void *args) { loopargs_t *tempargs = *(loopargs_t **) args; unsigned char *buf = tempargs->buf; unsigned char *buf2 = tempargs->buf2; size_t ecdsa_num = tempargs->sigsize; EVP_PKEY_CTX **ecdsa_verify_ctx = tempargs->ecdsa_verify_ctx; int ret, count; for (count = 0; COND(ecdsa_c[testnum][1]); count++) { ret = EVP_PKEY_verify(ecdsa_verify_ctx[testnum], buf2, ecdsa_num, buf, 20); if (ret <= 0) { BIO_printf(bio_err, "ECDSA verify failure\n"); ERR_print_errors(bio_err); count = -1; break; } } return count; } /* ******************************************************************** */ static long ecdh_c[EC_NUM][1]; static int ECDH_EVP_derive_key_loop(void *args) { loopargs_t *tempargs = *(loopargs_t **) args; EVP_PKEY_CTX *ctx = tempargs->ecdh_ctx[testnum]; unsigned char *derived_secret = tempargs->secret_a; int count; size_t *outlen = &(tempargs->outlen[testnum]); for (count = 0; COND(ecdh_c[testnum][0]); count++) EVP_PKEY_derive(ctx, derived_secret, outlen); return count; } static long eddsa_c[EdDSA_NUM][2]; static int EdDSA_sign_loop(void *args) { loopargs_t *tempargs = *(loopargs_t **) args; unsigned char *buf = tempargs->buf; EVP_MD_CTX **edctx = tempargs->eddsa_ctx; unsigned char *eddsasig = tempargs->buf2; size_t *eddsasigsize = &tempargs->sigsize; int ret, count; for (count = 0; COND(eddsa_c[testnum][0]); count++) { ret = EVP_DigestSignInit(edctx[testnum], NULL, NULL, NULL, NULL); if (ret == 0) { BIO_printf(bio_err, "EdDSA sign init failure\n"); ERR_print_errors(bio_err); count = -1; break; } ret = EVP_DigestSign(edctx[testnum], eddsasig, eddsasigsize, buf, 20); if (ret == 0) { BIO_printf(bio_err, "EdDSA sign failure\n"); ERR_print_errors(bio_err); count = -1; break; } } return count; } static int EdDSA_verify_loop(void *args) { loopargs_t *tempargs = *(loopargs_t **) args; unsigned char *buf = tempargs->buf; EVP_MD_CTX **edctx = tempargs->eddsa_ctx2; unsigned char *eddsasig = tempargs->buf2; size_t eddsasigsize = tempargs->sigsize; int ret, count; for (count = 0; COND(eddsa_c[testnum][1]); count++) { ret = EVP_DigestVerifyInit(edctx[testnum], NULL, NULL, NULL, NULL); if (ret == 0) { BIO_printf(bio_err, "EdDSA verify init failure\n"); ERR_print_errors(bio_err); count = -1; break; } ret = EVP_DigestVerify(edctx[testnum], eddsasig, eddsasigsize, buf, 20); if (ret != 1) { BIO_printf(bio_err, "EdDSA verify failure\n"); ERR_print_errors(bio_err); count = -1; break; } } return count; } #ifndef OPENSSL_NO_SM2 static long sm2_c[SM2_NUM][2]; static int SM2_sign_loop(void *args) { loopargs_t *tempargs = *(loopargs_t **) args; unsigned char *buf = tempargs->buf; EVP_MD_CTX **sm2ctx = tempargs->sm2_ctx; unsigned char *sm2sig = tempargs->buf2; size_t sm2sigsize; int ret, count; EVP_PKEY **sm2_pkey = tempargs->sm2_pkey; const size_t max_size = EVP_PKEY_get_size(sm2_pkey[testnum]); for (count = 0; COND(sm2_c[testnum][0]); count++) { sm2sigsize = max_size; if (!EVP_DigestSignInit(sm2ctx[testnum], NULL, EVP_sm3(), NULL, sm2_pkey[testnum])) { BIO_printf(bio_err, "SM2 init sign failure\n"); ERR_print_errors(bio_err); count = -1; break; } ret = EVP_DigestSign(sm2ctx[testnum], sm2sig, &sm2sigsize, buf, 20); if (ret == 0) { BIO_printf(bio_err, "SM2 sign failure\n"); ERR_print_errors(bio_err); count = -1; break; } /* update the latest returned size and always use the fixed buffer size */ tempargs->sigsize = sm2sigsize; } return count; } static int SM2_verify_loop(void *args) { loopargs_t *tempargs = *(loopargs_t **) args; unsigned char *buf = tempargs->buf; EVP_MD_CTX **sm2ctx = tempargs->sm2_vfy_ctx; unsigned char *sm2sig = tempargs->buf2; size_t sm2sigsize = tempargs->sigsize; int ret, count; EVP_PKEY **sm2_pkey = tempargs->sm2_pkey; for (count = 0; COND(sm2_c[testnum][1]); count++) { if (!EVP_DigestVerifyInit(sm2ctx[testnum], NULL, EVP_sm3(), NULL, sm2_pkey[testnum])) { BIO_printf(bio_err, "SM2 verify init failure\n"); ERR_print_errors(bio_err); count = -1; break; } ret = EVP_DigestVerify(sm2ctx[testnum], sm2sig, sm2sigsize, buf, 20); if (ret != 1) { BIO_printf(bio_err, "SM2 verify failure\n"); ERR_print_errors(bio_err); count = -1; break; } } return count; } #endif /* OPENSSL_NO_SM2 */ static int run_benchmark(int async_jobs, int (*loop_function) (void *), loopargs_t * loopargs) { int job_op_count = 0; int total_op_count = 0; int num_inprogress = 0; int error = 0, i = 0, ret = 0; OSSL_ASYNC_FD job_fd = 0; size_t num_job_fds = 0; if (async_jobs == 0) { return loop_function((void *)&loopargs); } for (i = 0; i < async_jobs && !error; i++) { loopargs_t *looparg_item = loopargs + i; /* Copy pointer content (looparg_t item address) into async context */ ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx, &job_op_count, loop_function, (void *)&looparg_item, sizeof(looparg_item)); switch (ret) { case ASYNC_PAUSE: ++num_inprogress; break; case ASYNC_FINISH: if (job_op_count == -1) { error = 1; } else { total_op_count += job_op_count; } break; case ASYNC_NO_JOBS: case ASYNC_ERR: BIO_printf(bio_err, "Failure in the job\n"); ERR_print_errors(bio_err); error = 1; break; } } while (num_inprogress > 0) { #if defined(OPENSSL_SYS_WINDOWS) DWORD avail = 0; #elif defined(OPENSSL_SYS_UNIX) int select_result = 0; OSSL_ASYNC_FD max_fd = 0; fd_set waitfdset; FD_ZERO(&waitfdset); for (i = 0; i < async_jobs && num_inprogress > 0; i++) { if (loopargs[i].inprogress_job == NULL) continue; if (!ASYNC_WAIT_CTX_get_all_fds (loopargs[i].wait_ctx, NULL, &num_job_fds) || num_job_fds > 1) { BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n"); ERR_print_errors(bio_err); error = 1; break; } ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds); FD_SET(job_fd, &waitfdset); if (job_fd > max_fd) max_fd = job_fd; } if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) { BIO_printf(bio_err, "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). " "Decrease the value of async_jobs\n", max_fd, FD_SETSIZE); ERR_print_errors(bio_err); error = 1; break; } select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL); if (select_result == -1 && errno == EINTR) continue; if (select_result == -1) { BIO_printf(bio_err, "Failure in the select\n"); ERR_print_errors(bio_err); error = 1; break; } if (select_result == 0) continue; #endif for (i = 0; i < async_jobs; i++) { if (loopargs[i].inprogress_job == NULL) continue; if (!ASYNC_WAIT_CTX_get_all_fds (loopargs[i].wait_ctx, NULL, &num_job_fds) || num_job_fds > 1) { BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n"); ERR_print_errors(bio_err); error = 1; break; } ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds); #if defined(OPENSSL_SYS_UNIX) if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset)) continue; #elif defined(OPENSSL_SYS_WINDOWS) if (num_job_fds == 1 && !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL) && avail > 0) continue; #endif ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx, &job_op_count, loop_function, (void *)(loopargs + i), sizeof(loopargs_t)); switch (ret) { case ASYNC_PAUSE: break; case ASYNC_FINISH: if (job_op_count == -1) { error = 1; } else { total_op_count += job_op_count; } --num_inprogress; loopargs[i].inprogress_job = NULL; break; case ASYNC_NO_JOBS: case ASYNC_ERR: --num_inprogress; loopargs[i].inprogress_job = NULL; BIO_printf(bio_err, "Failure in the job\n"); ERR_print_errors(bio_err); error = 1; break; } } } return error ? -1 : total_op_count; } typedef struct ec_curve_st { const char *name; unsigned int nid; unsigned int bits; size_t sigsize; /* only used for EdDSA curves */ } EC_CURVE; static EVP_PKEY *get_ecdsa(const EC_CURVE *curve) { EVP_PKEY_CTX *kctx = NULL; EVP_PKEY *key = NULL; /* Ensure that the error queue is empty */ if (ERR_peek_error()) { BIO_printf(bio_err, "WARNING: the error queue contains previous unhandled errors.\n"); ERR_print_errors(bio_err); } /* * Let's try to create a ctx directly from the NID: this works for * curves like Curve25519 that are not implemented through the low * level EC interface. * If this fails we try creating a EVP_PKEY_EC generic param ctx, * then we set the curve by NID before deriving the actual keygen * ctx for that specific curve. */ kctx = EVP_PKEY_CTX_new_id(curve->nid, NULL); if (kctx == NULL) { EVP_PKEY_CTX *pctx = NULL; EVP_PKEY *params = NULL; /* * If we reach this code EVP_PKEY_CTX_new_id() failed and a * "int_ctx_new:unsupported algorithm" error was added to the * error queue. * We remove it from the error queue as we are handling it. */ unsigned long error = ERR_peek_error(); if (error == ERR_peek_last_error() /* oldest and latest errors match */ /* check that the error origin matches */ && ERR_GET_LIB(error) == ERR_LIB_EVP && (ERR_GET_REASON(error) == EVP_R_UNSUPPORTED_ALGORITHM || ERR_GET_REASON(error) == ERR_R_UNSUPPORTED)) ERR_get_error(); /* pop error from queue */ if (ERR_peek_error()) { BIO_printf(bio_err, "Unhandled error in the error queue during EC key setup.\n"); ERR_print_errors(bio_err); return NULL; } /* Create the context for parameter generation */ if ((pctx = EVP_PKEY_CTX_new_from_name(NULL, "EC", NULL)) == NULL || EVP_PKEY_paramgen_init(pctx) <= 0 || EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx, curve->nid) <= 0 || EVP_PKEY_paramgen(pctx, ¶ms) <= 0) { BIO_printf(bio_err, "EC params init failure.\n"); ERR_print_errors(bio_err); EVP_PKEY_CTX_free(pctx); return NULL; } EVP_PKEY_CTX_free(pctx); /* Create the context for the key generation */ kctx = EVP_PKEY_CTX_new(params, NULL); EVP_PKEY_free(params); } if (kctx == NULL || EVP_PKEY_keygen_init(kctx) <= 0 || EVP_PKEY_keygen(kctx, &key) <= 0) { BIO_printf(bio_err, "EC key generation failure.\n"); ERR_print_errors(bio_err); key = NULL; } EVP_PKEY_CTX_free(kctx); return key; } #define stop_it(do_it, test_num)\ memset(do_it + test_num, 0, OSSL_NELEM(do_it) - test_num); int speed_main(int argc, char **argv) { ENGINE *e = NULL; loopargs_t *loopargs = NULL; const char *prog; const char *engine_id = NULL; EVP_CIPHER *evp_cipher = NULL; EVP_MAC *mac = NULL; double d = 0.0; OPTION_CHOICE o; int async_init = 0, multiblock = 0, pr_header = 0; uint8_t doit[ALGOR_NUM] = { 0 }; int ret = 1, misalign = 0, lengths_single = 0, aead = 0; long count = 0; unsigned int size_num = SIZE_NUM; unsigned int i, k, loopargs_len = 0, async_jobs = 0; int keylen; int buflen; BIGNUM *bn = NULL; EVP_PKEY_CTX *genctx = NULL; #ifndef NO_FORK int multi = 0; #endif long op_count = 1; openssl_speed_sec_t seconds = { SECONDS, RSA_SECONDS, DSA_SECONDS, ECDSA_SECONDS, ECDH_SECONDS, EdDSA_SECONDS, SM2_SECONDS, FFDH_SECONDS }; static const unsigned char key32[32] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56 }; static const unsigned char deskey[] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, /* key1 */ 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, /* key2 */ 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 /* key3 */ }; static const struct { const unsigned char *data; unsigned int length; unsigned int bits; } rsa_keys[] = { { test512, sizeof(test512), 512 }, { test1024, sizeof(test1024), 1024 }, { test2048, sizeof(test2048), 2048 }, { test3072, sizeof(test3072), 3072 }, { test4096, sizeof(test4096), 4096 }, { test7680, sizeof(test7680), 7680 }, { test15360, sizeof(test15360), 15360 } }; uint8_t rsa_doit[RSA_NUM] = { 0 }; int primes = RSA_DEFAULT_PRIME_NUM; #ifndef OPENSSL_NO_DH typedef struct ffdh_params_st { const char *name; unsigned int nid; unsigned int bits; } FFDH_PARAMS; static const FFDH_PARAMS ffdh_params[FFDH_NUM] = { {"ffdh2048", NID_ffdhe2048, 2048}, {"ffdh3072", NID_ffdhe3072, 3072}, {"ffdh4096", NID_ffdhe4096, 4096}, {"ffdh6144", NID_ffdhe6144, 6144}, {"ffdh8192", NID_ffdhe8192, 8192} }; uint8_t ffdh_doit[FFDH_NUM] = { 0 }; #endif /* OPENSSL_NO_DH */ static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 }; uint8_t dsa_doit[DSA_NUM] = { 0 }; /* * We only test over the following curves as they are representative, To * add tests over more curves, simply add the curve NID and curve name to * the following arrays and increase the |ecdh_choices| and |ecdsa_choices| * lists accordingly. */ static const EC_CURVE ec_curves[EC_NUM] = { /* Prime Curves */ {"secp160r1", NID_secp160r1, 160}, {"nistp192", NID_X9_62_prime192v1, 192}, {"nistp224", NID_secp224r1, 224}, {"nistp256", NID_X9_62_prime256v1, 256}, {"nistp384", NID_secp384r1, 384}, {"nistp521", NID_secp521r1, 521}, #ifndef OPENSSL_NO_EC2M /* Binary Curves */ {"nistk163", NID_sect163k1, 163}, {"nistk233", NID_sect233k1, 233}, {"nistk283", NID_sect283k1, 283}, {"nistk409", NID_sect409k1, 409}, {"nistk571", NID_sect571k1, 571}, {"nistb163", NID_sect163r2, 163}, {"nistb233", NID_sect233r1, 233}, {"nistb283", NID_sect283r1, 283}, {"nistb409", NID_sect409r1, 409}, {"nistb571", NID_sect571r1, 571}, #endif {"brainpoolP256r1", NID_brainpoolP256r1, 256}, {"brainpoolP256t1", NID_brainpoolP256t1, 256}, {"brainpoolP384r1", NID_brainpoolP384r1, 384}, {"brainpoolP384t1", NID_brainpoolP384t1, 384}, {"brainpoolP512r1", NID_brainpoolP512r1, 512}, {"brainpoolP512t1", NID_brainpoolP512t1, 512}, /* Other and ECDH only ones */ {"X25519", NID_X25519, 253}, {"X448", NID_X448, 448} }; static const EC_CURVE ed_curves[EdDSA_NUM] = { /* EdDSA */ {"Ed25519", NID_ED25519, 253, 64}, {"Ed448", NID_ED448, 456, 114} }; #ifndef OPENSSL_NO_SM2 static const EC_CURVE sm2_curves[SM2_NUM] = { /* SM2 */ {"CurveSM2", NID_sm2, 256} }; uint8_t sm2_doit[SM2_NUM] = { 0 }; #endif uint8_t ecdsa_doit[ECDSA_NUM] = { 0 }; uint8_t ecdh_doit[EC_NUM] = { 0 }; uint8_t eddsa_doit[EdDSA_NUM] = { 0 }; /* checks declarated curves against choices list. */ OPENSSL_assert(ed_curves[EdDSA_NUM - 1].nid == NID_ED448); OPENSSL_assert(strcmp(eddsa_choices[EdDSA_NUM - 1].name, "ed448") == 0); OPENSSL_assert(ec_curves[EC_NUM - 1].nid == NID_X448); OPENSSL_assert(strcmp(ecdh_choices[EC_NUM - 1].name, "ecdhx448") == 0); OPENSSL_assert(ec_curves[ECDSA_NUM - 1].nid == NID_brainpoolP512t1); OPENSSL_assert(strcmp(ecdsa_choices[ECDSA_NUM - 1].name, "ecdsabrp512t1") == 0); #ifndef OPENSSL_NO_SM2 OPENSSL_assert(sm2_curves[SM2_NUM - 1].nid == NID_sm2); OPENSSL_assert(strcmp(sm2_choices[SM2_NUM - 1].name, "curveSM2") == 0); #endif prog = opt_init(argc, argv, speed_options); while ((o = opt_next()) != OPT_EOF) { switch (o) { case OPT_EOF: case OPT_ERR: opterr: BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); goto end; case OPT_HELP: opt_help(speed_options); ret = 0; goto end; case OPT_ELAPSED: usertime = 0; break; case OPT_EVP: if (doit[D_EVP]) { BIO_printf(bio_err, "%s: -evp option cannot be used more than once\n", prog); goto opterr; } ERR_set_mark(); if (!opt_cipher_silent(opt_arg(), &evp_cipher)) { if (have_md(opt_arg())) evp_md_name = opt_arg(); } if (evp_cipher == NULL && evp_md_name == NULL) { ERR_clear_last_mark(); BIO_printf(bio_err, "%s: %s is an unknown cipher or digest\n", prog, opt_arg()); goto end; } ERR_pop_to_mark(); doit[D_EVP] = 1; break; case OPT_HMAC: if (!have_md(opt_arg())) { BIO_printf(bio_err, "%s: %s is an unknown digest\n", prog, opt_arg()); goto end; } evp_mac_mdname = opt_arg(); doit[D_HMAC] = 1; break; case OPT_CMAC: if (!have_cipher(opt_arg())) { BIO_printf(bio_err, "%s: %s is an unknown cipher\n", prog, opt_arg()); goto end; } evp_mac_ciphername = opt_arg(); doit[D_EVP_CMAC] = 1; break; case OPT_DECRYPT: decrypt = 1; break; case OPT_ENGINE: /* * In a forked execution, an engine might need to be * initialised by each child process, not by the parent. * So store the name here and run setup_engine() later on. */ engine_id = opt_arg(); break; case OPT_MULTI: #ifndef NO_FORK multi = atoi(opt_arg()); if ((size_t)multi >= SIZE_MAX / sizeof(int)) { BIO_printf(bio_err, "%s: multi argument too large\n", prog); return 0; } #endif break; case OPT_ASYNCJOBS: #ifndef OPENSSL_NO_ASYNC async_jobs = atoi(opt_arg()); if (!ASYNC_is_capable()) { BIO_printf(bio_err, "%s: async_jobs specified but async not supported\n", prog); goto opterr; } if (async_jobs > 99999) { BIO_printf(bio_err, "%s: too many async_jobs\n", prog); goto opterr; } #endif break; case OPT_MISALIGN: misalign = opt_int_arg(); if (misalign > MISALIGN) { BIO_printf(bio_err, "%s: Maximum offset is %d\n", prog, MISALIGN); goto opterr; } break; case OPT_MR: mr = 1; break; case OPT_MB: multiblock = 1; #ifdef OPENSSL_NO_MULTIBLOCK BIO_printf(bio_err, "%s: -mb specified but multi-block support is disabled\n", prog); goto end; #endif break; case OPT_R_CASES: if (!opt_rand(o)) goto end; break; case OPT_PROV_CASES: if (!opt_provider(o)) goto end; break; case OPT_PRIMES: primes = opt_int_arg(); break; case OPT_SECONDS: seconds.sym = seconds.rsa = seconds.dsa = seconds.ecdsa = seconds.ecdh = seconds.eddsa = seconds.sm2 = seconds.ffdh = atoi(opt_arg()); break; case OPT_BYTES: lengths_single = atoi(opt_arg()); lengths = &lengths_single; size_num = 1; break; case OPT_AEAD: aead = 1; break; } } /* Remaining arguments are algorithms. */ argc = opt_num_rest(); argv = opt_rest(); if (!app_RAND_load()) goto end; for (; *argv; argv++) { const char *algo = *argv; if (opt_found(algo, doit_choices, &i)) { doit[i] = 1; continue; } if (strcmp(algo, "des") == 0) { doit[D_CBC_DES] = doit[D_EDE3_DES] = 1; continue; } if (strcmp(algo, "sha") == 0) { doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1; continue; } #ifndef OPENSSL_NO_DEPRECATED_3_0 if (strcmp(algo, "openssl") == 0) /* just for compatibility */ continue; #endif if (strncmp(algo, "rsa", 3) == 0) { if (algo[3] == '\0') { memset(rsa_doit, 1, sizeof(rsa_doit)); continue; } if (opt_found(algo, rsa_choices, &i)) { rsa_doit[i] = 1; continue; } } #ifndef OPENSSL_NO_DH if (strncmp(algo, "ffdh", 4) == 0) { if (algo[4] == '\0') { memset(ffdh_doit, 1, sizeof(ffdh_doit)); continue; } if (opt_found(algo, ffdh_choices, &i)) { ffdh_doit[i] = 2; continue; } } #endif if (strncmp(algo, "dsa", 3) == 0) { if (algo[3] == '\0') { memset(dsa_doit, 1, sizeof(dsa_doit)); continue; } if (opt_found(algo, dsa_choices, &i)) { dsa_doit[i] = 2; continue; } } if (strcmp(algo, "aes") == 0) { doit[D_CBC_128_AES] = doit[D_CBC_192_AES] = doit[D_CBC_256_AES] = 1; continue; } if (strcmp(algo, "camellia") == 0) { doit[D_CBC_128_CML] = doit[D_CBC_192_CML] = doit[D_CBC_256_CML] = 1; continue; } if (strncmp(algo, "ecdsa", 5) == 0) { if (algo[5] == '\0') { memset(ecdsa_doit, 1, sizeof(ecdsa_doit)); continue; } if (opt_found(algo, ecdsa_choices, &i)) { ecdsa_doit[i] = 2; continue; } } if (strncmp(algo, "ecdh", 4) == 0) { if (algo[4] == '\0') { memset(ecdh_doit, 1, sizeof(ecdh_doit)); continue; } if (opt_found(algo, ecdh_choices, &i)) { ecdh_doit[i] = 2; continue; } } if (strcmp(algo, "eddsa") == 0) { memset(eddsa_doit, 1, sizeof(eddsa_doit)); continue; } if (opt_found(algo, eddsa_choices, &i)) { eddsa_doit[i] = 2; continue; } #ifndef OPENSSL_NO_SM2 if (strcmp(algo, "sm2") == 0) { memset(sm2_doit, 1, sizeof(sm2_doit)); continue; } if (opt_found(algo, sm2_choices, &i)) { sm2_doit[i] = 2; continue; } #endif BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, algo); goto end; } /* Sanity checks */ if (aead) { if (evp_cipher == NULL) { BIO_printf(bio_err, "-aead can be used only with an AEAD cipher\n"); goto end; } else if (!(EVP_CIPHER_get_flags(evp_cipher) & EVP_CIPH_FLAG_AEAD_CIPHER)) { BIO_printf(bio_err, "%s is not an AEAD cipher\n", EVP_CIPHER_get0_name(evp_cipher)); goto end; } } if (multiblock) { if (evp_cipher == NULL) { BIO_printf(bio_err, "-mb can be used only with a multi-block" " capable cipher\n"); goto end; } else if (!(EVP_CIPHER_get_flags(evp_cipher) & EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) { BIO_printf(bio_err, "%s is not a multi-block capable\n", EVP_CIPHER_get0_name(evp_cipher)); goto end; } else if (async_jobs > 0) { BIO_printf(bio_err, "Async mode is not supported with -mb"); goto end; } } /* Initialize the job pool if async mode is enabled */ if (async_jobs > 0) { async_init = ASYNC_init_thread(async_jobs, async_jobs); if (!async_init) { BIO_printf(bio_err, "Error creating the ASYNC job pool\n"); goto end; } } loopargs_len = (async_jobs == 0 ? 1 : async_jobs); loopargs = app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs"); memset(loopargs, 0, loopargs_len * sizeof(loopargs_t)); for (i = 0; i < loopargs_len; i++) { if (async_jobs > 0) { loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new(); if (loopargs[i].wait_ctx == NULL) { BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n"); goto end; } } buflen = lengths[size_num - 1]; if (buflen < 36) /* size of random vector in RSA benchmark */ buflen = 36; if (INT_MAX - (MAX_MISALIGNMENT + 1) < buflen) { BIO_printf(bio_err, "Error: buffer size too large\n"); goto end; } buflen += MAX_MISALIGNMENT + 1; loopargs[i].buf_malloc = app_malloc(buflen, "input buffer"); loopargs[i].buf2_malloc = app_malloc(buflen, "input buffer"); memset(loopargs[i].buf_malloc, 0, buflen); memset(loopargs[i].buf2_malloc, 0, buflen); /* Align the start of buffers on a 64 byte boundary */ loopargs[i].buf = loopargs[i].buf_malloc + misalign; loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign; loopargs[i].buflen = buflen - misalign; loopargs[i].sigsize = buflen - misalign; loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a"); loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b"); #ifndef OPENSSL_NO_DH loopargs[i].secret_ff_a = app_malloc(MAX_FFDH_SIZE, "FFDH secret a"); loopargs[i].secret_ff_b = app_malloc(MAX_FFDH_SIZE, "FFDH secret b"); #endif } #ifndef NO_FORK if (multi && do_multi(multi, size_num)) goto show_res; #endif /* Initialize the engine after the fork */ e = setup_engine(engine_id, 0); /* No parameters; turn on everything. */ if (argc == 0 && !doit[D_EVP] && !doit[D_HMAC] && !doit[D_EVP_CMAC]) { memset(doit, 1, sizeof(doit)); doit[D_EVP] = doit[D_EVP_CMAC] = 0; ERR_set_mark(); for (i = D_MD2; i <= D_WHIRLPOOL; i++) { if (!have_md(names[i])) doit[i] = 0; } for (i = D_CBC_DES; i <= D_CBC_256_CML; i++) { if (!have_cipher(names[i])) doit[i] = 0; } if ((mac = EVP_MAC_fetch(app_get0_libctx(), "GMAC", app_get0_propq())) != NULL) { EVP_MAC_free(mac); mac = NULL; } else { doit[D_GHASH] = 0; } if ((mac = EVP_MAC_fetch(app_get0_libctx(), "HMAC", app_get0_propq())) != NULL) { EVP_MAC_free(mac); mac = NULL; } else { doit[D_HMAC] = 0; } ERR_pop_to_mark(); memset(rsa_doit, 1, sizeof(rsa_doit)); #ifndef OPENSSL_NO_DH memset(ffdh_doit, 1, sizeof(ffdh_doit)); #endif memset(dsa_doit, 1, sizeof(dsa_doit)); memset(ecdsa_doit, 1, sizeof(ecdsa_doit)); memset(ecdh_doit, 1, sizeof(ecdh_doit)); memset(eddsa_doit, 1, sizeof(eddsa_doit)); #ifndef OPENSSL_NO_SM2 memset(sm2_doit, 1, sizeof(sm2_doit)); #endif } for (i = 0; i < ALGOR_NUM; i++) if (doit[i]) pr_header++; if (usertime == 0 && !mr) BIO_printf(bio_err, "You have chosen to measure elapsed time " "instead of user CPU time.\n"); #if SIGALRM > 0 signal(SIGALRM, alarmed); #endif if (doit[D_MD2]) { for (testnum = 0; testnum < size_num; testnum++) { print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum], seconds.sym); Time_F(START); count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs); d = Time_F(STOP); print_result(D_MD2, testnum, count, d); if (count < 0) break; } } if (doit[D_MDC2]) { for (testnum = 0; testnum < size_num; testnum++) { print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum], seconds.sym); Time_F(START); count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs); d = Time_F(STOP); print_result(D_MDC2, testnum, count, d); if (count < 0) break; } } if (doit[D_MD4]) { for (testnum = 0; testnum < size_num; testnum++) { print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum], seconds.sym); Time_F(START); count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs); d = Time_F(STOP); print_result(D_MD4, testnum, count, d); if (count < 0) break; } } if (doit[D_MD5]) { for (testnum = 0; testnum < size_num; testnum++) { print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum], seconds.sym); Time_F(START); count = run_benchmark(async_jobs, MD5_loop, loopargs); d = Time_F(STOP); print_result(D_MD5, testnum, count, d); if (count < 0) break; } } if (doit[D_SHA1]) { for (testnum = 0; testnum < size_num; testnum++) { print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum], seconds.sym); Time_F(START); count = run_benchmark(async_jobs, SHA1_loop, loopargs); d = Time_F(STOP); print_result(D_SHA1, testnum, count, d); if (count < 0) break; } } if (doit[D_SHA256]) { for (testnum = 0; testnum < size_num; testnum++) { print_message(names[D_SHA256], c[D_SHA256][testnum], lengths[testnum], seconds.sym); Time_F(START); count = run_benchmark(async_jobs, SHA256_loop, loopargs); d = Time_F(STOP); print_result(D_SHA256, testnum, count, d); if (count < 0) break; } } if (doit[D_SHA512]) { for (testnum = 0; testnum < size_num; testnum++) { print_message(names[D_SHA512], c[D_SHA512][testnum], lengths[testnum], seconds.sym); Time_F(START); count = run_benchmark(async_jobs, SHA512_loop, loopargs); d = Time_F(STOP); print_result(D_SHA512, testnum, count, d); if (count < 0) break; } } if (doit[D_WHIRLPOOL]) { for (testnum = 0; testnum < size_num; testnum++) { print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum], lengths[testnum], seconds.sym); Time_F(START); count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs); d = Time_F(STOP); print_result(D_WHIRLPOOL, testnum, count, d); if (count < 0) break; } } if (doit[D_RMD160]) { for (testnum = 0; testnum < size_num; testnum++) { print_message(names[D_RMD160], c[D_RMD160][testnum], lengths[testnum], seconds.sym); Time_F(START); count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs); d = Time_F(STOP); print_result(D_RMD160, testnum, count, d); if (count < 0) break; } } if (doit[D_HMAC]) { static const char hmac_key[] = "This is a key..."; int len = strlen(hmac_key); OSSL_PARAM params[3]; mac = EVP_MAC_fetch(app_get0_libctx(), "HMAC", app_get0_propq()); if (mac == NULL || evp_mac_mdname == NULL) goto end; evp_hmac_name = app_malloc(sizeof("hmac()") + strlen(evp_mac_mdname), "HMAC name"); sprintf(evp_hmac_name, "hmac(%s)", evp_mac_mdname); names[D_HMAC] = evp_hmac_name; params[0] = OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_DIGEST, evp_mac_mdname, 0); params[1] = OSSL_PARAM_construct_octet_string(OSSL_MAC_PARAM_KEY, (char *)hmac_key, len); params[2] = OSSL_PARAM_construct_end(); for (i = 0; i < loopargs_len; i++) { loopargs[i].mctx = EVP_MAC_CTX_new(mac); if (loopargs[i].mctx == NULL) goto end; if (!EVP_MAC_CTX_set_params(loopargs[i].mctx, params)) goto skip_hmac; /* Digest not found */ } for (testnum = 0; testnum < size_num; testnum++) { print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum], seconds.sym); Time_F(START); count = run_benchmark(async_jobs, HMAC_loop, loopargs); d = Time_F(STOP); print_result(D_HMAC, testnum, count, d); if (count < 0) break; } for (i = 0; i < loopargs_len; i++) EVP_MAC_CTX_free(loopargs[i].mctx); EVP_MAC_free(mac); mac = NULL; } skip_hmac: if (doit[D_CBC_DES]) { int st = 1; for (i = 0; st && i < loopargs_len; i++) { loopargs[i].ctx = init_evp_cipher_ctx("des-cbc", deskey, sizeof(deskey) / 3); st = loopargs[i].ctx != NULL; } algindex = D_CBC_DES; for (testnum = 0; st && testnum < size_num; testnum++) { print_message(names[D_CBC_DES], c[D_CBC_DES][testnum], lengths[testnum], seconds.sym); Time_F(START); count = run_benchmark(async_jobs, EVP_Cipher_loop, loopargs); d = Time_F(STOP); print_result(D_CBC_DES, testnum, count, d); } for (i = 0; i < loopargs_len; i++) EVP_CIPHER_CTX_free(loopargs[i].ctx); } if (doit[D_EDE3_DES]) { int st = 1; for (i = 0; st && i < loopargs_len; i++) { loopargs[i].ctx = init_evp_cipher_ctx("des-ede3-cbc", deskey, sizeof(deskey)); st = loopargs[i].ctx != NULL; } algindex = D_EDE3_DES; for (testnum = 0; st && testnum < size_num; testnum++) { print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum], lengths[testnum], seconds.sym); Time_F(START); count = run_benchmark(async_jobs, EVP_Cipher_loop, loopargs); d = Time_F(STOP); print_result(D_EDE3_DES, testnum, count, d); } for (i = 0; i < loopargs_len; i++) EVP_CIPHER_CTX_free(loopargs[i].ctx); } for (k = 0; k < 3; k++) { algindex = D_CBC_128_AES + k; if (doit[algindex]) { int st = 1; keylen = 16 + k * 8; for (i = 0; st && i < loopargs_len; i++) { loopargs[i].ctx = init_evp_cipher_ctx(names[algindex], key32, keylen); st = loopargs[i].ctx != NULL; } for (testnum = 0; st && testnum < size_num; testnum++) { print_message(names[algindex], c[algindex][testnum], lengths[testnum], seconds.sym); Time_F(START); count = run_benchmark(async_jobs, EVP_Cipher_loop, loopargs); d = Time_F(STOP); print_result(algindex, testnum, count, d); } for (i = 0; i < loopargs_len; i++) EVP_CIPHER_CTX_free(loopargs[i].ctx); } } for (k = 0; k < 3; k++) { algindex = D_CBC_128_CML + k; if (doit[algindex]) { int st = 1; keylen = 16 + k * 8; for (i = 0; st && i < loopargs_len; i++) { loopargs[i].ctx = init_evp_cipher_ctx(names[algindex], key32, keylen); st = loopargs[i].ctx != NULL; } for (testnum = 0; st && testnum < size_num; testnum++) { print_message(names[algindex], c[algindex][testnum], lengths[testnum], seconds.sym); Time_F(START); count = run_benchmark(async_jobs, EVP_Cipher_loop, loopargs); d = Time_F(STOP); print_result(algindex, testnum, count, d); } for (i = 0; i < loopargs_len; i++) EVP_CIPHER_CTX_free(loopargs[i].ctx); } } for (algindex = D_RC4; algindex <= D_CBC_CAST; algindex++) { if (doit[algindex]) { int st = 1; keylen = 16; for (i = 0; st && i < loopargs_len; i++) { loopargs[i].ctx = init_evp_cipher_ctx(names[algindex], key32, keylen); st = loopargs[i].ctx != NULL; } for (testnum = 0; st && testnum < size_num; testnum++) { print_message(names[algindex], c[algindex][testnum], lengths[testnum], seconds.sym); Time_F(START); count = run_benchmark(async_jobs, EVP_Cipher_loop, loopargs); d = Time_F(STOP); print_result(algindex, testnum, count, d); } for (i = 0; i < loopargs_len; i++) EVP_CIPHER_CTX_free(loopargs[i].ctx); } } if (doit[D_GHASH]) { static const char gmac_iv[] = "0123456789ab"; OSSL_PARAM params[3]; mac = EVP_MAC_fetch(app_get0_libctx(), "GMAC", app_get0_propq()); if (mac == NULL) goto end; params[0] = OSSL_PARAM_construct_utf8_string(OSSL_ALG_PARAM_CIPHER, "aes-128-gcm", 0); params[1] = OSSL_PARAM_construct_octet_string(OSSL_MAC_PARAM_IV, (char *)gmac_iv, sizeof(gmac_iv) - 1); params[2] = OSSL_PARAM_construct_end(); for (i = 0; i < loopargs_len; i++) { loopargs[i].mctx = EVP_MAC_CTX_new(mac); if (loopargs[i].mctx == NULL) goto end; if (!EVP_MAC_init(loopargs[i].mctx, key32, 16, params)) goto end; } for (testnum = 0; testnum < size_num; testnum++) { print_message(names[D_GHASH], c[D_GHASH][testnum], lengths[testnum], seconds.sym); Time_F(START); count = run_benchmark(async_jobs, GHASH_loop, loopargs); d = Time_F(STOP); print_result(D_GHASH, testnum, count, d); if (count < 0) break; } for (i = 0; i < loopargs_len; i++) EVP_MAC_CTX_free(loopargs[i].mctx); EVP_MAC_free(mac); mac = NULL; } if (doit[D_RAND]) { for (testnum = 0; testnum < size_num; testnum++) { print_message(names[D_RAND], c[D_RAND][testnum], lengths[testnum], seconds.sym); Time_F(START); count = run_benchmark(async_jobs, RAND_bytes_loop, loopargs); d = Time_F(STOP); print_result(D_RAND, testnum, count, d); } } if (doit[D_EVP]) { if (evp_cipher != NULL) { int (*loopfunc) (void *) = EVP_Update_loop; if (multiblock && (EVP_CIPHER_get_flags(evp_cipher) & EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) { multiblock_speed(evp_cipher, lengths_single, &seconds); ret = 0; goto end; } names[D_EVP] = EVP_CIPHER_get0_name(evp_cipher); if (EVP_CIPHER_get_mode(evp_cipher) == EVP_CIPH_CCM_MODE) { loopfunc = EVP_Update_loop_ccm; } else if (aead && (EVP_CIPHER_get_flags(evp_cipher) & EVP_CIPH_FLAG_AEAD_CIPHER)) { loopfunc = EVP_Update_loop_aead; if (lengths == lengths_list) { lengths = aead_lengths_list; size_num = OSSL_NELEM(aead_lengths_list); } } for (testnum = 0; testnum < size_num; testnum++) { print_message(names[D_EVP], c[D_EVP][testnum], lengths[testnum], seconds.sym); for (k = 0; k < loopargs_len; k++) { loopargs[k].ctx = EVP_CIPHER_CTX_new(); if (loopargs[k].ctx == NULL) { BIO_printf(bio_err, "\nEVP_CIPHER_CTX_new failure\n"); exit(1); } if (!EVP_CipherInit_ex(loopargs[k].ctx, evp_cipher, NULL, NULL, iv, decrypt ? 0 : 1)) { BIO_printf(bio_err, "\nEVP_CipherInit_ex failure\n"); ERR_print_errors(bio_err); exit(1); } EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0); keylen = EVP_CIPHER_CTX_get_key_length(loopargs[k].ctx); loopargs[k].key = app_malloc(keylen, "evp_cipher key"); EVP_CIPHER_CTX_rand_key(loopargs[k].ctx, loopargs[k].key); if (!EVP_CipherInit_ex(loopargs[k].ctx, NULL, NULL, loopargs[k].key, NULL, -1)) { BIO_printf(bio_err, "\nEVP_CipherInit_ex failure\n"); ERR_print_errors(bio_err); exit(1); } OPENSSL_clear_free(loopargs[k].key, keylen); /* SIV mode only allows for a single Update operation */ if (EVP_CIPHER_get_mode(evp_cipher) == EVP_CIPH_SIV_MODE) (void)EVP_CIPHER_CTX_ctrl(loopargs[k].ctx, EVP_CTRL_SET_SPEED, 1, NULL); } Time_F(START); count = run_benchmark(async_jobs, loopfunc, loopargs); d = Time_F(STOP); for (k = 0; k < loopargs_len; k++) EVP_CIPHER_CTX_free(loopargs[k].ctx); print_result(D_EVP, testnum, count, d); } } else if (evp_md_name != NULL) { names[D_EVP] = evp_md_name; for (testnum = 0; testnum < size_num; testnum++) { print_message(names[D_EVP], c[D_EVP][testnum], lengths[testnum], seconds.sym); Time_F(START); count = run_benchmark(async_jobs, EVP_Digest_md_loop, loopargs); d = Time_F(STOP); print_result(D_EVP, testnum, count, d); if (count < 0) break; } } } if (doit[D_EVP_CMAC]) { OSSL_PARAM params[3]; EVP_CIPHER *cipher = NULL; mac = EVP_MAC_fetch(app_get0_libctx(), "CMAC", app_get0_propq()); if (mac == NULL || evp_mac_ciphername == NULL) goto end; if (!opt_cipher(evp_mac_ciphername, &cipher)) goto end; keylen = EVP_CIPHER_get_key_length(cipher); EVP_CIPHER_free(cipher); if (keylen <= 0 || keylen > (int)sizeof(key32)) { BIO_printf(bio_err, "\nRequested CMAC cipher with unsupported key length.\n"); goto end; } evp_cmac_name = app_malloc(sizeof("cmac()") + strlen(evp_mac_ciphername), "CMAC name"); sprintf(evp_cmac_name, "cmac(%s)", evp_mac_ciphername); names[D_EVP_CMAC] = evp_cmac_name; params[0] = OSSL_PARAM_construct_utf8_string(OSSL_ALG_PARAM_CIPHER, evp_mac_ciphername, 0); params[1] = OSSL_PARAM_construct_octet_string(OSSL_MAC_PARAM_KEY, (char *)key32, keylen); params[2] = OSSL_PARAM_construct_end(); for (i = 0; i < loopargs_len; i++) { loopargs[i].mctx = EVP_MAC_CTX_new(mac); if (loopargs[i].mctx == NULL) goto end; if (!EVP_MAC_CTX_set_params(loopargs[i].mctx, params)) goto end; } for (testnum = 0; testnum < size_num; testnum++) { print_message(names[D_EVP_CMAC], c[D_EVP_CMAC][testnum], lengths[testnum], seconds.sym); Time_F(START); count = run_benchmark(async_jobs, CMAC_loop, loopargs); d = Time_F(STOP); print_result(D_EVP_CMAC, testnum, count, d); if (count < 0) break; } for (i = 0; i < loopargs_len; i++) EVP_MAC_CTX_free(loopargs[i].mctx); EVP_MAC_free(mac); mac = NULL; } for (i = 0; i < loopargs_len; i++) if (RAND_bytes(loopargs[i].buf, 36) <= 0) goto end; for (testnum = 0; testnum < RSA_NUM; testnum++) { EVP_PKEY *rsa_key = NULL; int st = 0; if (!rsa_doit[testnum]) continue; if (primes > RSA_DEFAULT_PRIME_NUM) { /* we haven't set keys yet, generate multi-prime RSA keys */ bn = BN_new(); st = bn != NULL && BN_set_word(bn, RSA_F4) && init_gen_str(&genctx, "RSA", NULL, 0, NULL, NULL) && EVP_PKEY_CTX_set_rsa_keygen_bits(genctx, rsa_keys[testnum].bits) > 0 && EVP_PKEY_CTX_set1_rsa_keygen_pubexp(genctx, bn) > 0 && EVP_PKEY_CTX_set_rsa_keygen_primes(genctx, primes) > 0 && EVP_PKEY_keygen(genctx, &rsa_key); BN_free(bn); bn = NULL; EVP_PKEY_CTX_free(genctx); genctx = NULL; } else { const unsigned char *p = rsa_keys[testnum].data; st = (rsa_key = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &p, rsa_keys[testnum].length)) != NULL; } for (i = 0; st && i < loopargs_len; i++) { loopargs[i].rsa_sign_ctx[testnum] = EVP_PKEY_CTX_new(rsa_key, NULL); loopargs[i].sigsize = loopargs[i].buflen; if (loopargs[i].rsa_sign_ctx[testnum] == NULL || EVP_PKEY_sign_init(loopargs[i].rsa_sign_ctx[testnum]) <= 0 || EVP_PKEY_sign(loopargs[i].rsa_sign_ctx[testnum], loopargs[i].buf2, &loopargs[i].sigsize, loopargs[i].buf, 36) <= 0) st = 0; } if (!st) { BIO_printf(bio_err, "RSA sign setup failure. No RSA sign will be done.\n"); ERR_print_errors(bio_err); op_count = 1; } else { pkey_print_message("private", "rsa", rsa_c[testnum][0], rsa_keys[testnum].bits, seconds.rsa); /* RSA_blinding_on(rsa_key[testnum],NULL); */ Time_F(START); count = run_benchmark(async_jobs, RSA_sign_loop, loopargs); d = Time_F(STOP); BIO_printf(bio_err, mr ? "+R1:%ld:%d:%.2f\n" : "%ld %u bits private RSA's in %.2fs\n", count, rsa_keys[testnum].bits, d); rsa_results[testnum][0] = (double)count / d; op_count = count; } for (i = 0; st && i < loopargs_len; i++) { loopargs[i].rsa_verify_ctx[testnum] = EVP_PKEY_CTX_new(rsa_key, NULL); if (loopargs[i].rsa_verify_ctx[testnum] == NULL || EVP_PKEY_verify_init(loopargs[i].rsa_verify_ctx[testnum]) <= 0 || EVP_PKEY_verify(loopargs[i].rsa_verify_ctx[testnum], loopargs[i].buf2, loopargs[i].sigsize, loopargs[i].buf, 36) <= 0) st = 0; } if (!st) { BIO_printf(bio_err, "RSA verify setup failure. No RSA verify will be done.\n"); ERR_print_errors(bio_err); rsa_doit[testnum] = 0; } else { pkey_print_message("public", "rsa", rsa_c[testnum][1], rsa_keys[testnum].bits, seconds.rsa); Time_F(START); count = run_benchmark(async_jobs, RSA_verify_loop, loopargs); d = Time_F(STOP); BIO_printf(bio_err, mr ? "+R2:%ld:%d:%.2f\n" : "%ld %u bits public RSA's in %.2fs\n", count, rsa_keys[testnum].bits, d); rsa_results[testnum][1] = (double)count / d; } if (op_count <= 1) { /* if longer than 10s, don't do any more */ stop_it(rsa_doit, testnum); } EVP_PKEY_free(rsa_key); } for (testnum = 0; testnum < DSA_NUM; testnum++) { EVP_PKEY *dsa_key = NULL; int st; if (!dsa_doit[testnum]) continue; st = (dsa_key = get_dsa(dsa_bits[testnum])) != NULL; for (i = 0; st && i < loopargs_len; i++) { loopargs[i].dsa_sign_ctx[testnum] = EVP_PKEY_CTX_new(dsa_key, NULL); loopargs[i].sigsize = loopargs[i].buflen; if (loopargs[i].dsa_sign_ctx[testnum] == NULL || EVP_PKEY_sign_init(loopargs[i].dsa_sign_ctx[testnum]) <= 0 || EVP_PKEY_sign(loopargs[i].dsa_sign_ctx[testnum], loopargs[i].buf2, &loopargs[i].sigsize, loopargs[i].buf, 20) <= 0) st = 0; } if (!st) { BIO_printf(bio_err, "DSA sign setup failure. No DSA sign will be done.\n"); ERR_print_errors(bio_err); op_count = 1; } else { pkey_print_message("sign", "dsa", dsa_c[testnum][0], dsa_bits[testnum], seconds.dsa); Time_F(START); count = run_benchmark(async_jobs, DSA_sign_loop, loopargs); d = Time_F(STOP); BIO_printf(bio_err, mr ? "+R3:%ld:%u:%.2f\n" : "%ld %u bits DSA signs in %.2fs\n", count, dsa_bits[testnum], d); dsa_results[testnum][0] = (double)count / d; op_count = count; } for (i = 0; st && i < loopargs_len; i++) { loopargs[i].dsa_verify_ctx[testnum] = EVP_PKEY_CTX_new(dsa_key, NULL); if (loopargs[i].dsa_verify_ctx[testnum] == NULL || EVP_PKEY_verify_init(loopargs[i].dsa_verify_ctx[testnum]) <= 0 || EVP_PKEY_verify(loopargs[i].dsa_verify_ctx[testnum], loopargs[i].buf2, loopargs[i].sigsize, loopargs[i].buf, 36) <= 0) st = 0; } if (!st) { BIO_printf(bio_err, "DSA verify setup failure. No DSA verify will be done.\n"); ERR_print_errors(bio_err); dsa_doit[testnum] = 0; } else { pkey_print_message("verify", "dsa", dsa_c[testnum][1], dsa_bits[testnum], seconds.dsa); Time_F(START); count = run_benchmark(async_jobs, DSA_verify_loop, loopargs); d = Time_F(STOP); BIO_printf(bio_err, mr ? "+R4:%ld:%u:%.2f\n" : "%ld %u bits DSA verify in %.2fs\n", count, dsa_bits[testnum], d); dsa_results[testnum][1] = (double)count / d; } if (op_count <= 1) { /* if longer than 10s, don't do any more */ stop_it(dsa_doit, testnum); } EVP_PKEY_free(dsa_key); } for (testnum = 0; testnum < ECDSA_NUM; testnum++) { EVP_PKEY *ecdsa_key = NULL; int st; if (!ecdsa_doit[testnum]) continue; st = (ecdsa_key = get_ecdsa(&ec_curves[testnum])) != NULL; for (i = 0; st && i < loopargs_len; i++) { loopargs[i].ecdsa_sign_ctx[testnum] = EVP_PKEY_CTX_new(ecdsa_key, NULL); loopargs[i].sigsize = loopargs[i].buflen; if (loopargs[i].ecdsa_sign_ctx[testnum] == NULL || EVP_PKEY_sign_init(loopargs[i].ecdsa_sign_ctx[testnum]) <= 0 || EVP_PKEY_sign(loopargs[i].ecdsa_sign_ctx[testnum], loopargs[i].buf2, &loopargs[i].sigsize, loopargs[i].buf, 20) <= 0) st = 0; } if (!st) { BIO_printf(bio_err, "ECDSA sign setup failure. No ECDSA sign will be done.\n"); ERR_print_errors(bio_err); op_count = 1; } else { pkey_print_message("sign", "ecdsa", ecdsa_c[testnum][0], ec_curves[testnum].bits, seconds.ecdsa); Time_F(START); count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs); d = Time_F(STOP); BIO_printf(bio_err, mr ? "+R5:%ld:%u:%.2f\n" : "%ld %u bits ECDSA signs in %.2fs\n", count, ec_curves[testnum].bits, d); ecdsa_results[testnum][0] = (double)count / d; op_count = count; } for (i = 0; st && i < loopargs_len; i++) { loopargs[i].ecdsa_verify_ctx[testnum] = EVP_PKEY_CTX_new(ecdsa_key, NULL); if (loopargs[i].ecdsa_verify_ctx[testnum] == NULL || EVP_PKEY_verify_init(loopargs[i].ecdsa_verify_ctx[testnum]) <= 0 || EVP_PKEY_verify(loopargs[i].ecdsa_verify_ctx[testnum], loopargs[i].buf2, loopargs[i].sigsize, loopargs[i].buf, 20) <= 0) st = 0; } if (!st) { BIO_printf(bio_err, "ECDSA verify setup failure. No ECDSA verify will be done.\n"); ERR_print_errors(bio_err); ecdsa_doit[testnum] = 0; } else { pkey_print_message("verify", "ecdsa", ecdsa_c[testnum][1], ec_curves[testnum].bits, seconds.ecdsa); Time_F(START); count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs); d = Time_F(STOP); BIO_printf(bio_err, mr ? "+R6:%ld:%u:%.2f\n" : "%ld %u bits ECDSA verify in %.2fs\n", count, ec_curves[testnum].bits, d); ecdsa_results[testnum][1] = (double)count / d; } if (op_count <= 1) { /* if longer than 10s, don't do any more */ stop_it(ecdsa_doit, testnum); } } for (testnum = 0; testnum < EC_NUM; testnum++) { int ecdh_checks = 1; if (!ecdh_doit[testnum]) continue; for (i = 0; i < loopargs_len; i++) { EVP_PKEY_CTX *test_ctx = NULL; EVP_PKEY_CTX *ctx = NULL; EVP_PKEY *key_A = NULL; EVP_PKEY *key_B = NULL; size_t outlen; size_t test_outlen; if ((key_A = get_ecdsa(&ec_curves[testnum])) == NULL /* generate secret key A */ || (key_B = get_ecdsa(&ec_curves[testnum])) == NULL /* generate secret key B */ || (ctx = EVP_PKEY_CTX_new(key_A, NULL)) == NULL /* derivation ctx from skeyA */ || EVP_PKEY_derive_init(ctx) <= 0 /* init derivation ctx */ || EVP_PKEY_derive_set_peer(ctx, key_B) <= 0 /* set peer pubkey in ctx */ || EVP_PKEY_derive(ctx, NULL, &outlen) <= 0 /* determine max length */ || outlen == 0 /* ensure outlen is a valid size */ || outlen > MAX_ECDH_SIZE /* avoid buffer overflow */) { ecdh_checks = 0; BIO_printf(bio_err, "ECDH key generation failure.\n"); ERR_print_errors(bio_err); op_count = 1; break; } /* * Here we perform a test run, comparing the output of a*B and b*A; * we try this here and assume that further EVP_PKEY_derive calls * never fail, so we can skip checks in the actually benchmarked * code, for maximum performance. */ if ((test_ctx = EVP_PKEY_CTX_new(key_B, NULL)) == NULL /* test ctx from skeyB */ || EVP_PKEY_derive_init(test_ctx) <= 0 /* init derivation test_ctx */ || EVP_PKEY_derive_set_peer(test_ctx, key_A) <= 0 /* set peer pubkey in test_ctx */ || EVP_PKEY_derive(test_ctx, NULL, &test_outlen) <= 0 /* determine max length */ || EVP_PKEY_derive(ctx, loopargs[i].secret_a, &outlen) <= 0 /* compute a*B */ || EVP_PKEY_derive(test_ctx, loopargs[i].secret_b, &test_outlen) <= 0 /* compute b*A */ || test_outlen != outlen /* compare output length */) { ecdh_checks = 0; BIO_printf(bio_err, "ECDH computation failure.\n"); ERR_print_errors(bio_err); op_count = 1; break; } /* Compare the computation results: CRYPTO_memcmp() returns 0 if equal */ if (CRYPTO_memcmp(loopargs[i].secret_a, loopargs[i].secret_b, outlen)) { ecdh_checks = 0; BIO_printf(bio_err, "ECDH computations don't match.\n"); ERR_print_errors(bio_err); op_count = 1; break; } loopargs[i].ecdh_ctx[testnum] = ctx; loopargs[i].outlen[testnum] = outlen; EVP_PKEY_free(key_A); EVP_PKEY_free(key_B); EVP_PKEY_CTX_free(test_ctx); test_ctx = NULL; } if (ecdh_checks != 0) { pkey_print_message("", "ecdh", ecdh_c[testnum][0], ec_curves[testnum].bits, seconds.ecdh); Time_F(START); count = run_benchmark(async_jobs, ECDH_EVP_derive_key_loop, loopargs); d = Time_F(STOP); BIO_printf(bio_err, mr ? "+R7:%ld:%d:%.2f\n" : "%ld %u-bits ECDH ops in %.2fs\n", count, ec_curves[testnum].bits, d); ecdh_results[testnum][0] = (double)count / d; op_count = count; } if (op_count <= 1) { /* if longer than 10s, don't do any more */ stop_it(ecdh_doit, testnum); } } for (testnum = 0; testnum < EdDSA_NUM; testnum++) { int st = 1; EVP_PKEY *ed_pkey = NULL; EVP_PKEY_CTX *ed_pctx = NULL; if (!eddsa_doit[testnum]) continue; /* Ignore Curve */ for (i = 0; i < loopargs_len; i++) { loopargs[i].eddsa_ctx[testnum] = EVP_MD_CTX_new(); if (loopargs[i].eddsa_ctx[testnum] == NULL) { st = 0; break; } loopargs[i].eddsa_ctx2[testnum] = EVP_MD_CTX_new(); if (loopargs[i].eddsa_ctx2[testnum] == NULL) { st = 0; break; } if ((ed_pctx = EVP_PKEY_CTX_new_id(ed_curves[testnum].nid, NULL)) == NULL || EVP_PKEY_keygen_init(ed_pctx) <= 0 || EVP_PKEY_keygen(ed_pctx, &ed_pkey) <= 0) { st = 0; EVP_PKEY_CTX_free(ed_pctx); break; } EVP_PKEY_CTX_free(ed_pctx); if (!EVP_DigestSignInit(loopargs[i].eddsa_ctx[testnum], NULL, NULL, NULL, ed_pkey)) { st = 0; EVP_PKEY_free(ed_pkey); break; } if (!EVP_DigestVerifyInit(loopargs[i].eddsa_ctx2[testnum], NULL, NULL, NULL, ed_pkey)) { st = 0; EVP_PKEY_free(ed_pkey); break; } EVP_PKEY_free(ed_pkey); ed_pkey = NULL; } if (st == 0) { BIO_printf(bio_err, "EdDSA failure.\n"); ERR_print_errors(bio_err); op_count = 1; } else { for (i = 0; i < loopargs_len; i++) { /* Perform EdDSA signature test */ loopargs[i].sigsize = ed_curves[testnum].sigsize; st = EVP_DigestSign(loopargs[i].eddsa_ctx[testnum], loopargs[i].buf2, &loopargs[i].sigsize, loopargs[i].buf, 20); if (st == 0) break; } if (st == 0) { BIO_printf(bio_err, "EdDSA sign failure. No EdDSA sign will be done.\n"); ERR_print_errors(bio_err); op_count = 1; } else { pkey_print_message("sign", ed_curves[testnum].name, eddsa_c[testnum][0], ed_curves[testnum].bits, seconds.eddsa); Time_F(START); count = run_benchmark(async_jobs, EdDSA_sign_loop, loopargs); d = Time_F(STOP); BIO_printf(bio_err, mr ? "+R8:%ld:%u:%s:%.2f\n" : "%ld %u bits %s signs in %.2fs \n", count, ed_curves[testnum].bits, ed_curves[testnum].name, d); eddsa_results[testnum][0] = (double)count / d; op_count = count; } /* Perform EdDSA verification test */ for (i = 0; i < loopargs_len; i++) { st = EVP_DigestVerify(loopargs[i].eddsa_ctx2[testnum], loopargs[i].buf2, loopargs[i].sigsize, loopargs[i].buf, 20); if (st != 1) break; } if (st != 1) { BIO_printf(bio_err, "EdDSA verify failure. No EdDSA verify will be done.\n"); ERR_print_errors(bio_err); eddsa_doit[testnum] = 0; } else { pkey_print_message("verify", ed_curves[testnum].name, eddsa_c[testnum][1], ed_curves[testnum].bits, seconds.eddsa); Time_F(START); count = run_benchmark(async_jobs, EdDSA_verify_loop, loopargs); d = Time_F(STOP); BIO_printf(bio_err, mr ? "+R9:%ld:%u:%s:%.2f\n" : "%ld %u bits %s verify in %.2fs\n", count, ed_curves[testnum].bits, ed_curves[testnum].name, d); eddsa_results[testnum][1] = (double)count / d; } if (op_count <= 1) { /* if longer than 10s, don't do any more */ stop_it(eddsa_doit, testnum); } } } #ifndef OPENSSL_NO_SM2 for (testnum = 0; testnum < SM2_NUM; testnum++) { int st = 1; EVP_PKEY *sm2_pkey = NULL; if (!sm2_doit[testnum]) continue; /* Ignore Curve */ /* Init signing and verification */ for (i = 0; i < loopargs_len; i++) { EVP_PKEY_CTX *sm2_pctx = NULL; EVP_PKEY_CTX *sm2_vfy_pctx = NULL; EVP_PKEY_CTX *pctx = NULL; st = 0; loopargs[i].sm2_ctx[testnum] = EVP_MD_CTX_new(); loopargs[i].sm2_vfy_ctx[testnum] = EVP_MD_CTX_new(); if (loopargs[i].sm2_ctx[testnum] == NULL || loopargs[i].sm2_vfy_ctx[testnum] == NULL) break; sm2_pkey = NULL; st = !((pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_SM2, NULL)) == NULL || EVP_PKEY_keygen_init(pctx) <= 0 || EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx, sm2_curves[testnum].nid) <= 0 || EVP_PKEY_keygen(pctx, &sm2_pkey) <= 0); EVP_PKEY_CTX_free(pctx); if (st == 0) break; st = 0; /* set back to zero */ /* attach it sooner to rely on main final cleanup */ loopargs[i].sm2_pkey[testnum] = sm2_pkey; loopargs[i].sigsize = EVP_PKEY_get_size(sm2_pkey); sm2_pctx = EVP_PKEY_CTX_new(sm2_pkey, NULL); sm2_vfy_pctx = EVP_PKEY_CTX_new(sm2_pkey, NULL); if (sm2_pctx == NULL || sm2_vfy_pctx == NULL) { EVP_PKEY_CTX_free(sm2_vfy_pctx); break; } /* attach them directly to respective ctx */ EVP_MD_CTX_set_pkey_ctx(loopargs[i].sm2_ctx[testnum], sm2_pctx); EVP_MD_CTX_set_pkey_ctx(loopargs[i].sm2_vfy_ctx[testnum], sm2_vfy_pctx); /* * No need to allow user to set an explicit ID here, just use * the one defined in the 'draft-yang-tls-tl13-sm-suites' I-D. */ if (EVP_PKEY_CTX_set1_id(sm2_pctx, SM2_ID, SM2_ID_LEN) != 1 || EVP_PKEY_CTX_set1_id(sm2_vfy_pctx, SM2_ID, SM2_ID_LEN) != 1) break; if (!EVP_DigestSignInit(loopargs[i].sm2_ctx[testnum], NULL, EVP_sm3(), NULL, sm2_pkey)) break; if (!EVP_DigestVerifyInit(loopargs[i].sm2_vfy_ctx[testnum], NULL, EVP_sm3(), NULL, sm2_pkey)) break; st = 1; /* mark loop as succeeded */ } if (st == 0) { BIO_printf(bio_err, "SM2 init failure.\n"); ERR_print_errors(bio_err); op_count = 1; } else { for (i = 0; i < loopargs_len; i++) { /* Perform SM2 signature test */ st = EVP_DigestSign(loopargs[i].sm2_ctx[testnum], loopargs[i].buf2, &loopargs[i].sigsize, loopargs[i].buf, 20); if (st == 0) break; } if (st == 0) { BIO_printf(bio_err, "SM2 sign failure. No SM2 sign will be done.\n"); ERR_print_errors(bio_err); op_count = 1; } else { pkey_print_message("sign", sm2_curves[testnum].name, sm2_c[testnum][0], sm2_curves[testnum].bits, seconds.sm2); Time_F(START); count = run_benchmark(async_jobs, SM2_sign_loop, loopargs); d = Time_F(STOP); BIO_printf(bio_err, mr ? "+R10:%ld:%u:%s:%.2f\n" : "%ld %u bits %s signs in %.2fs \n", count, sm2_curves[testnum].bits, sm2_curves[testnum].name, d); sm2_results[testnum][0] = (double)count / d; op_count = count; } /* Perform SM2 verification test */ for (i = 0; i < loopargs_len; i++) { st = EVP_DigestVerify(loopargs[i].sm2_vfy_ctx[testnum], loopargs[i].buf2, loopargs[i].sigsize, loopargs[i].buf, 20); if (st != 1) break; } if (st != 1) { BIO_printf(bio_err, "SM2 verify failure. No SM2 verify will be done.\n"); ERR_print_errors(bio_err); sm2_doit[testnum] = 0; } else { pkey_print_message("verify", sm2_curves[testnum].name, sm2_c[testnum][1], sm2_curves[testnum].bits, seconds.sm2); Time_F(START); count = run_benchmark(async_jobs, SM2_verify_loop, loopargs); d = Time_F(STOP); BIO_printf(bio_err, mr ? "+R11:%ld:%u:%s:%.2f\n" : "%ld %u bits %s verify in %.2fs\n", count, sm2_curves[testnum].bits, sm2_curves[testnum].name, d); sm2_results[testnum][1] = (double)count / d; } if (op_count <= 1) { /* if longer than 10s, don't do any more */ for (testnum++; testnum < SM2_NUM; testnum++) sm2_doit[testnum] = 0; } } } #endif /* OPENSSL_NO_SM2 */ #ifndef OPENSSL_NO_DH for (testnum = 0; testnum < FFDH_NUM; testnum++) { int ffdh_checks = 1; if (!ffdh_doit[testnum]) continue; for (i = 0; i < loopargs_len; i++) { EVP_PKEY *pkey_A = NULL; EVP_PKEY *pkey_B = NULL; EVP_PKEY_CTX *ffdh_ctx = NULL; EVP_PKEY_CTX *test_ctx = NULL; size_t secret_size; size_t test_out; /* Ensure that the error queue is empty */ if (ERR_peek_error()) { BIO_printf(bio_err, "WARNING: the error queue contains previous unhandled errors.\n"); ERR_print_errors(bio_err); } pkey_A = EVP_PKEY_new(); if (!pkey_A) { BIO_printf(bio_err, "Error while initialising EVP_PKEY (out of memory?).\n"); ERR_print_errors(bio_err); op_count = 1; ffdh_checks = 0; break; } pkey_B = EVP_PKEY_new(); if (!pkey_B) { BIO_printf(bio_err, "Error while initialising EVP_PKEY (out of memory?).\n"); ERR_print_errors(bio_err); op_count = 1; ffdh_checks = 0; break; } ffdh_ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_DH, NULL); if (!ffdh_ctx) { BIO_printf(bio_err, "Error while allocating EVP_PKEY_CTX.\n"); ERR_print_errors(bio_err); op_count = 1; ffdh_checks = 0; break; } if (EVP_PKEY_keygen_init(ffdh_ctx) <= 0) { BIO_printf(bio_err, "Error while initialising EVP_PKEY_CTX.\n"); ERR_print_errors(bio_err); op_count = 1; ffdh_checks = 0; break; } if (EVP_PKEY_CTX_set_dh_nid(ffdh_ctx, ffdh_params[testnum].nid) <= 0) { BIO_printf(bio_err, "Error setting DH key size for keygen.\n"); ERR_print_errors(bio_err); op_count = 1; ffdh_checks = 0; break; } if (EVP_PKEY_keygen(ffdh_ctx, &pkey_A) <= 0 || EVP_PKEY_keygen(ffdh_ctx, &pkey_B) <= 0) { BIO_printf(bio_err, "FFDH key generation failure.\n"); ERR_print_errors(bio_err); op_count = 1; ffdh_checks = 0; break; } EVP_PKEY_CTX_free(ffdh_ctx); /* * check if the derivation works correctly both ways so that * we know if future derive calls will fail, and we can skip * error checking in benchmarked code */ ffdh_ctx = EVP_PKEY_CTX_new(pkey_A, NULL); if (ffdh_ctx == NULL) { BIO_printf(bio_err, "Error while allocating EVP_PKEY_CTX.\n"); ERR_print_errors(bio_err); op_count = 1; ffdh_checks = 0; break; } if (EVP_PKEY_derive_init(ffdh_ctx) <= 0) { BIO_printf(bio_err, "FFDH derivation context init failure.\n"); ERR_print_errors(bio_err); op_count = 1; ffdh_checks = 0; break; } if (EVP_PKEY_derive_set_peer(ffdh_ctx, pkey_B) <= 0) { BIO_printf(bio_err, "Assigning peer key for derivation failed.\n"); ERR_print_errors(bio_err); op_count = 1; ffdh_checks = 0; break; } if (EVP_PKEY_derive(ffdh_ctx, NULL, &secret_size) <= 0) { BIO_printf(bio_err, "Checking size of shared secret failed.\n"); ERR_print_errors(bio_err); op_count = 1; ffdh_checks = 0; break; } if (secret_size > MAX_FFDH_SIZE) { BIO_printf(bio_err, "Assertion failure: shared secret too large.\n"); op_count = 1; ffdh_checks = 0; break; } if (EVP_PKEY_derive(ffdh_ctx, loopargs[i].secret_ff_a, &secret_size) <= 0) { BIO_printf(bio_err, "Shared secret derive failure.\n"); ERR_print_errors(bio_err); op_count = 1; ffdh_checks = 0; break; } /* Now check from side B */ test_ctx = EVP_PKEY_CTX_new(pkey_B, NULL); if (!test_ctx) { BIO_printf(bio_err, "Error while allocating EVP_PKEY_CTX.\n"); ERR_print_errors(bio_err); op_count = 1; ffdh_checks = 0; break; } if (EVP_PKEY_derive_init(test_ctx) <= 0 || EVP_PKEY_derive_set_peer(test_ctx, pkey_A) <= 0 || EVP_PKEY_derive(test_ctx, NULL, &test_out) <= 0 || EVP_PKEY_derive(test_ctx, loopargs[i].secret_ff_b, &test_out) <= 0 || test_out != secret_size) { BIO_printf(bio_err, "FFDH computation failure.\n"); op_count = 1; ffdh_checks = 0; break; } /* compare the computed secrets */ if (CRYPTO_memcmp(loopargs[i].secret_ff_a, loopargs[i].secret_ff_b, secret_size)) { BIO_printf(bio_err, "FFDH computations don't match.\n"); ERR_print_errors(bio_err); op_count = 1; ffdh_checks = 0; break; } loopargs[i].ffdh_ctx[testnum] = ffdh_ctx; EVP_PKEY_free(pkey_A); pkey_A = NULL; EVP_PKEY_free(pkey_B); pkey_B = NULL; EVP_PKEY_CTX_free(test_ctx); test_ctx = NULL; } if (ffdh_checks != 0) { pkey_print_message("", "ffdh", ffdh_c[testnum][0], ffdh_params[testnum].bits, seconds.ffdh); Time_F(START); count = run_benchmark(async_jobs, FFDH_derive_key_loop, loopargs); d = Time_F(STOP); BIO_printf(bio_err, mr ? "+R12:%ld:%d:%.2f\n" : "%ld %u-bits FFDH ops in %.2fs\n", count, ffdh_params[testnum].bits, d); ffdh_results[testnum][0] = (double)count / d; op_count = count; } if (op_count <= 1) { /* if longer than 10s, don't do any more */ stop_it(ffdh_doit, testnum); } } #endif /* OPENSSL_NO_DH */ #ifndef NO_FORK show_res: #endif if (!mr) { printf("version: %s\n", OpenSSL_version(OPENSSL_FULL_VERSION_STRING)); printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON)); printf("options: %s\n", BN_options()); printf("%s\n", OpenSSL_version(OPENSSL_CFLAGS)); printf("%s\n", OpenSSL_version(OPENSSL_CPU_INFO)); } if (pr_header) { if (mr) { printf("+H"); } else { printf("The 'numbers' are in 1000s of bytes per second processed.\n"); printf("type "); } for (testnum = 0; testnum < size_num; testnum++) printf(mr ? ":%d" : "%7d bytes", lengths[testnum]); printf("\n"); } for (k = 0; k < ALGOR_NUM; k++) { const char *alg_name = names[k]; if (!doit[k]) continue; if (k == D_EVP) { if (evp_cipher == NULL) alg_name = evp_md_name; else if ((alg_name = EVP_CIPHER_get0_name(evp_cipher)) == NULL) app_bail_out("failed to get name of cipher '%s'\n", evp_cipher); } if (mr) printf("+F:%u:%s", k, alg_name); else printf("%-13s", alg_name); for (testnum = 0; testnum < size_num; testnum++) { if (results[k][testnum] > 10000 && !mr) printf(" %11.2fk", results[k][testnum] / 1e3); else printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]); } printf("\n"); } testnum = 1; for (k = 0; k < RSA_NUM; k++) { if (!rsa_doit[k]) continue; if (testnum && !mr) { printf("%18ssign verify sign/s verify/s\n", " "); testnum = 0; } if (mr) printf("+F2:%u:%u:%f:%f\n", k, rsa_keys[k].bits, rsa_results[k][0], rsa_results[k][1]); else printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n", rsa_keys[k].bits, 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1], rsa_results[k][0], rsa_results[k][1]); } testnum = 1; for (k = 0; k < DSA_NUM; k++) { if (!dsa_doit[k]) continue; if (testnum && !mr) { printf("%18ssign verify sign/s verify/s\n", " "); testnum = 0; } if (mr) printf("+F3:%u:%u:%f:%f\n", k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]); else printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n", dsa_bits[k], 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1], dsa_results[k][0], dsa_results[k][1]); } testnum = 1; for (k = 0; k < OSSL_NELEM(ecdsa_doit); k++) { if (!ecdsa_doit[k]) continue; if (testnum && !mr) { printf("%30ssign verify sign/s verify/s\n", " "); testnum = 0; } if (mr) printf("+F4:%u:%u:%f:%f\n", k, ec_curves[k].bits, ecdsa_results[k][0], ecdsa_results[k][1]); else printf("%4u bits ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n", ec_curves[k].bits, ec_curves[k].name, 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1], ecdsa_results[k][0], ecdsa_results[k][1]); } testnum = 1; for (k = 0; k < EC_NUM; k++) { if (!ecdh_doit[k]) continue; if (testnum && !mr) { printf("%30sop op/s\n", " "); testnum = 0; } if (mr) printf("+F5:%u:%u:%f:%f\n", k, ec_curves[k].bits, ecdh_results[k][0], 1.0 / ecdh_results[k][0]); else printf("%4u bits ecdh (%s) %8.4fs %8.1f\n", ec_curves[k].bits, ec_curves[k].name, 1.0 / ecdh_results[k][0], ecdh_results[k][0]); } testnum = 1; for (k = 0; k < OSSL_NELEM(eddsa_doit); k++) { if (!eddsa_doit[k]) continue; if (testnum && !mr) { printf("%30ssign verify sign/s verify/s\n", " "); testnum = 0; } if (mr) printf("+F6:%u:%u:%s:%f:%f\n", k, ed_curves[k].bits, ed_curves[k].name, eddsa_results[k][0], eddsa_results[k][1]); else printf("%4u bits EdDSA (%s) %8.4fs %8.4fs %8.1f %8.1f\n", ed_curves[k].bits, ed_curves[k].name, 1.0 / eddsa_results[k][0], 1.0 / eddsa_results[k][1], eddsa_results[k][0], eddsa_results[k][1]); } #ifndef OPENSSL_NO_SM2 testnum = 1; for (k = 0; k < OSSL_NELEM(sm2_doit); k++) { if (!sm2_doit[k]) continue; if (testnum && !mr) { printf("%30ssign verify sign/s verify/s\n", " "); testnum = 0; } if (mr) printf("+F7:%u:%u:%s:%f:%f\n", k, sm2_curves[k].bits, sm2_curves[k].name, sm2_results[k][0], sm2_results[k][1]); else printf("%4u bits SM2 (%s) %8.4fs %8.4fs %8.1f %8.1f\n", sm2_curves[k].bits, sm2_curves[k].name, 1.0 / sm2_results[k][0], 1.0 / sm2_results[k][1], sm2_results[k][0], sm2_results[k][1]); } #endif #ifndef OPENSSL_NO_DH testnum = 1; for (k = 0; k < FFDH_NUM; k++) { if (!ffdh_doit[k]) continue; if (testnum && !mr) { printf("%23sop op/s\n", " "); testnum = 0; } if (mr) printf("+F8:%u:%u:%f:%f\n", k, ffdh_params[k].bits, ffdh_results[k][0], 1.0 / ffdh_results[k][0]); else printf("%4u bits ffdh %8.4fs %8.1f\n", ffdh_params[k].bits, 1.0 / ffdh_results[k][0], ffdh_results[k][0]); } #endif /* OPENSSL_NO_DH */ ret = 0; end: ERR_print_errors(bio_err); for (i = 0; i < loopargs_len; i++) { OPENSSL_free(loopargs[i].buf_malloc); OPENSSL_free(loopargs[i].buf2_malloc); BN_free(bn); EVP_PKEY_CTX_free(genctx); for (k = 0; k < RSA_NUM; k++) { EVP_PKEY_CTX_free(loopargs[i].rsa_sign_ctx[k]); EVP_PKEY_CTX_free(loopargs[i].rsa_verify_ctx[k]); } #ifndef OPENSSL_NO_DH OPENSSL_free(loopargs[i].secret_ff_a); OPENSSL_free(loopargs[i].secret_ff_b); for (k = 0; k < FFDH_NUM; k++) EVP_PKEY_CTX_free(loopargs[i].ffdh_ctx[k]); #endif for (k = 0; k < DSA_NUM; k++) { EVP_PKEY_CTX_free(loopargs[i].dsa_sign_ctx[k]); EVP_PKEY_CTX_free(loopargs[i].dsa_verify_ctx[k]); } for (k = 0; k < ECDSA_NUM; k++) { EVP_PKEY_CTX_free(loopargs[i].ecdsa_sign_ctx[k]); EVP_PKEY_CTX_free(loopargs[i].ecdsa_verify_ctx[k]); } for (k = 0; k < EC_NUM; k++) EVP_PKEY_CTX_free(loopargs[i].ecdh_ctx[k]); for (k = 0; k < EdDSA_NUM; k++) { EVP_MD_CTX_free(loopargs[i].eddsa_ctx[k]); EVP_MD_CTX_free(loopargs[i].eddsa_ctx2[k]); } #ifndef OPENSSL_NO_SM2 for (k = 0; k < SM2_NUM; k++) { EVP_PKEY_CTX *pctx = NULL; /* free signing ctx */ if (loopargs[i].sm2_ctx[k] != NULL && (pctx = EVP_MD_CTX_get_pkey_ctx(loopargs[i].sm2_ctx[k])) != NULL) EVP_PKEY_CTX_free(pctx); EVP_MD_CTX_free(loopargs[i].sm2_ctx[k]); /* free verification ctx */ if (loopargs[i].sm2_vfy_ctx[k] != NULL && (pctx = EVP_MD_CTX_get_pkey_ctx(loopargs[i].sm2_vfy_ctx[k])) != NULL) EVP_PKEY_CTX_free(pctx); EVP_MD_CTX_free(loopargs[i].sm2_vfy_ctx[k]); /* free pkey */ EVP_PKEY_free(loopargs[i].sm2_pkey[k]); } #endif OPENSSL_free(loopargs[i].secret_a); OPENSSL_free(loopargs[i].secret_b); } OPENSSL_free(evp_hmac_name); OPENSSL_free(evp_cmac_name); if (async_jobs > 0) { for (i = 0; i < loopargs_len; i++) ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx); } if (async_init) { ASYNC_cleanup_thread(); } OPENSSL_free(loopargs); release_engine(e); EVP_CIPHER_free(evp_cipher); EVP_MAC_free(mac); return ret; } static void print_message(const char *s, long num, int length, int tm) { BIO_printf(bio_err, mr ? "+DT:%s:%d:%d\n" : "Doing %s for %ds on %d size blocks: ", s, tm, length); (void)BIO_flush(bio_err); run = 1; alarm(tm); } static void pkey_print_message(const char *str, const char *str2, long num, unsigned int bits, int tm) { BIO_printf(bio_err, mr ? "+DTP:%d:%s:%s:%d\n" : "Doing %u bits %s %s's for %ds: ", bits, str, str2, tm); (void)BIO_flush(bio_err); run = 1; alarm(tm); } static void print_result(int alg, int run_no, int count, double time_used) { if (count == -1) { BIO_printf(bio_err, "%s error!\n", names[alg]); ERR_print_errors(bio_err); return; } BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n" : "%d %s's in %.2fs\n", count, names[alg], time_used); results[alg][run_no] = ((double)count) / time_used * lengths[run_no]; } #ifndef NO_FORK static char *sstrsep(char **string, const char *delim) { char isdelim[256]; char *token = *string; if (**string == 0) return NULL; memset(isdelim, 0, sizeof(isdelim)); isdelim[0] = 1; while (*delim) { isdelim[(unsigned char)(*delim)] = 1; delim++; } while (!isdelim[(unsigned char)(**string)]) (*string)++; if (**string) { **string = 0; (*string)++; } return token; } static int do_multi(int multi, int size_num) { int n; int fd[2]; int *fds; int status; static char sep[] = ":"; fds = app_malloc(sizeof(*fds) * multi, "fd buffer for do_multi"); for (n = 0; n < multi; ++n) { if (pipe(fd) == -1) { BIO_printf(bio_err, "pipe failure\n"); exit(1); } fflush(stdout); (void)BIO_flush(bio_err); if (fork()) { close(fd[1]); fds[n] = fd[0]; } else { close(fd[0]); close(1); if (dup(fd[1]) == -1) { BIO_printf(bio_err, "dup failed\n"); exit(1); } close(fd[1]); mr = 1; usertime = 0; OPENSSL_free(fds); return 0; } printf("Forked child %d\n", n); } /* for now, assume the pipe is long enough to take all the output */ for (n = 0; n < multi; ++n) { FILE *f; char buf[1024]; char *p; if ((f = fdopen(fds[n], "r")) == NULL) { BIO_printf(bio_err, "fdopen failure with 0x%x\n", errno); OPENSSL_free(fds); return 1; } while (fgets(buf, sizeof(buf), f)) { p = strchr(buf, '\n'); if (p) *p = '\0'; if (buf[0] != '+') { BIO_printf(bio_err, "Don't understand line '%s' from child %d\n", buf, n); continue; } printf("Got: %s from %d\n", buf, n); if (strncmp(buf, "+F:", 3) == 0) { int alg; int j; p = buf + 3; alg = atoi(sstrsep(&p, sep)); sstrsep(&p, sep); for (j = 0; j < size_num; ++j) results[alg][j] += atof(sstrsep(&p, sep)); } else if (strncmp(buf, "+F2:", 4) == 0) { int k; double d; p = buf + 4; k = atoi(sstrsep(&p, sep)); sstrsep(&p, sep); d = atof(sstrsep(&p, sep)); rsa_results[k][0] += d; d = atof(sstrsep(&p, sep)); rsa_results[k][1] += d; } else if (strncmp(buf, "+F3:", 4) == 0) { int k; double d; p = buf + 4; k = atoi(sstrsep(&p, sep)); sstrsep(&p, sep); d = atof(sstrsep(&p, sep)); dsa_results[k][0] += d; d = atof(sstrsep(&p, sep)); dsa_results[k][1] += d; } else if (strncmp(buf, "+F4:", 4) == 0) { int k; double d; p = buf + 4; k = atoi(sstrsep(&p, sep)); sstrsep(&p, sep); d = atof(sstrsep(&p, sep)); ecdsa_results[k][0] += d; d = atof(sstrsep(&p, sep)); ecdsa_results[k][1] += d; } else if (strncmp(buf, "+F5:", 4) == 0) { int k; double d; p = buf + 4; k = atoi(sstrsep(&p, sep)); sstrsep(&p, sep); d = atof(sstrsep(&p, sep)); ecdh_results[k][0] += d; } else if (strncmp(buf, "+F6:", 4) == 0) { int k; double d; p = buf + 4; k = atoi(sstrsep(&p, sep)); sstrsep(&p, sep); sstrsep(&p, sep); d = atof(sstrsep(&p, sep)); eddsa_results[k][0] += d; d = atof(sstrsep(&p, sep)); eddsa_results[k][1] += d; # ifndef OPENSSL_NO_SM2 } else if (strncmp(buf, "+F7:", 4) == 0) { int k; double d; p = buf + 4; k = atoi(sstrsep(&p, sep)); sstrsep(&p, sep); sstrsep(&p, sep); d = atof(sstrsep(&p, sep)); sm2_results[k][0] += d; d = atof(sstrsep(&p, sep)); sm2_results[k][1] += d; # endif /* OPENSSL_NO_SM2 */ # ifndef OPENSSL_NO_DH } else if (strncmp(buf, "+F8:", 4) == 0) { int k; double d; p = buf + 4; k = atoi(sstrsep(&p, sep)); sstrsep(&p, sep); d = atof(sstrsep(&p, sep)); ffdh_results[k][0] += d; # endif /* OPENSSL_NO_DH */ } else if (strncmp(buf, "+H:", 3) == 0) { ; } else { BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf, n); } } fclose(f); } OPENSSL_free(fds); for (n = 0; n < multi; ++n) { while (wait(&status) == -1) if (errno != EINTR) { BIO_printf(bio_err, "Waitng for child failed with 0x%x\n", errno); return 1; } if (WIFEXITED(status) && WEXITSTATUS(status)) { BIO_printf(bio_err, "Child exited with %d\n", WEXITSTATUS(status)); } else if (WIFSIGNALED(status)) { BIO_printf(bio_err, "Child terminated by signal %d\n", WTERMSIG(status)); } } return 1; } #endif static void multiblock_speed(const EVP_CIPHER *evp_cipher, int lengths_single, const openssl_speed_sec_t *seconds) { static const int mblengths_list[] = { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 }; const int *mblengths = mblengths_list; int j, count, keylen, num = OSSL_NELEM(mblengths_list); const char *alg_name; unsigned char *inp = NULL, *out = NULL, *key, no_key[32], no_iv[16]; EVP_CIPHER_CTX *ctx = NULL; double d = 0.0; if (lengths_single) { mblengths = &lengths_single; num = 1; } inp = app_malloc(mblengths[num - 1], "multiblock input buffer"); out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer"); if ((ctx = EVP_CIPHER_CTX_new()) == NULL) app_bail_out("failed to allocate cipher context\n"); if (!EVP_EncryptInit_ex(ctx, evp_cipher, NULL, NULL, no_iv)) app_bail_out("failed to initialise cipher context\n"); if ((keylen = EVP_CIPHER_CTX_get_key_length(ctx)) < 0) { BIO_printf(bio_err, "Impossible negative key length: %d\n", keylen); goto err; } key = app_malloc(keylen, "evp_cipher key"); if (EVP_CIPHER_CTX_rand_key(ctx, key) <= 0) app_bail_out("failed to generate random cipher key\n"); if (!EVP_EncryptInit_ex(ctx, NULL, NULL, key, NULL)) app_bail_out("failed to set cipher key\n"); OPENSSL_clear_free(key, keylen); if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key), no_key) <= 0) app_bail_out("failed to set AEAD key\n"); if ((alg_name = EVP_CIPHER_get0_name(evp_cipher)) == NULL) app_bail_out("failed to get cipher name\n"); for (j = 0; j < num; j++) { print_message(alg_name, 0, mblengths[j], seconds->sym); Time_F(START); for (count = 0; run && count < INT_MAX; count++) { unsigned char aad[EVP_AEAD_TLS1_AAD_LEN]; EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param; size_t len = mblengths[j]; int packlen; memset(aad, 0, 8); /* avoid uninitialized values */ aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */ aad[9] = 3; /* version */ aad[10] = 2; aad[11] = 0; /* length */ aad[12] = 0; mb_param.out = NULL; mb_param.inp = aad; mb_param.len = len; mb_param.interleave = 8; packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD, sizeof(mb_param), &mb_param); if (packlen > 0) { mb_param.out = out; mb_param.inp = inp; mb_param.len = len; (void)EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT, sizeof(mb_param), &mb_param); } else { int pad; - RAND_bytes(out, 16); + if (RAND_bytes(inp, 16) <= 0) + app_bail_out("error setting random bytes\n"); len += 16; aad[11] = (unsigned char)(len >> 8); aad[12] = (unsigned char)(len); pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD, EVP_AEAD_TLS1_AAD_LEN, aad); EVP_Cipher(ctx, out, inp, len + pad); } } d = Time_F(STOP); BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n" : "%d %s's in %.2fs\n", count, "evp", d); results[D_EVP][j] = ((double)count) / d * mblengths[j]; } if (mr) { fprintf(stdout, "+H"); for (j = 0; j < num; j++) fprintf(stdout, ":%d", mblengths[j]); fprintf(stdout, "\n"); fprintf(stdout, "+F:%d:%s", D_EVP, alg_name); for (j = 0; j < num; j++) fprintf(stdout, ":%.2f", results[D_EVP][j]); fprintf(stdout, "\n"); } else { fprintf(stdout, "The 'numbers' are in 1000s of bytes per second processed.\n"); fprintf(stdout, "type "); for (j = 0; j < num; j++) fprintf(stdout, "%7d bytes", mblengths[j]); fprintf(stdout, "\n"); fprintf(stdout, "%-24s", alg_name); for (j = 0; j < num; j++) { if (results[D_EVP][j] > 10000) fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3); else fprintf(stdout, " %11.2f ", results[D_EVP][j]); } fprintf(stdout, "\n"); } err: OPENSSL_free(inp); OPENSSL_free(out); EVP_CIPHER_CTX_free(ctx); } diff --git a/crypto/openssl/crypto/aes/asm/aesv8-armx.pl b/crypto/openssl/crypto/aes/asm/aesv8-armx.pl index 544dc7e8effe..d0e0be6187bd 100755 --- a/crypto/openssl/crypto/aes/asm/aesv8-armx.pl +++ b/crypto/openssl/crypto/aes/asm/aesv8-armx.pl @@ -1,3736 +1,3739 @@ #! /usr/bin/env perl # Copyright 2014-2023 The OpenSSL Project Authors. All Rights Reserved. # # Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy # in the file LICENSE in the source distribution or at # https://www.openssl.org/source/license.html # # ==================================================================== # Written by Andy Polyakov for the OpenSSL # project. The module is, however, dual licensed under OpenSSL and # CRYPTOGAMS licenses depending on where you obtain it. For further # details see http://www.openssl.org/~appro/cryptogams/. # ==================================================================== # # This module implements support for ARMv8 AES instructions. The # module is endian-agnostic in sense that it supports both big- and # little-endian cases. As does it support both 32- and 64-bit modes # of operation. Latter is achieved by limiting amount of utilized # registers to 16, which implies additional NEON load and integer # instructions. This has no effect on mighty Apple A7, where results # are literally equal to the theoretical estimates based on AES # instruction latencies and issue rates. On Cortex-A53, an in-order # execution core, this costs up to 10-15%, which is partially # compensated by implementing dedicated code path for 128-bit # CBC encrypt case. On Cortex-A57 parallelizable mode performance # seems to be limited by sheer amount of NEON instructions... # # April 2019 # # Key to performance of parallelize-able modes is round instruction # interleaving. But which factor to use? There is optimal one for # each combination of instruction latency and issue rate, beyond # which increasing interleave factor doesn't pay off. While on cons # side we have code size increase and resource waste on platforms for # which interleave factor is too high. In other words you want it to # be just right. So far interleave factor of 3x was serving well all # platforms. But for ThunderX2 optimal interleave factor was measured # to be 5x... # # Performance in cycles per byte processed with 128-bit key: # # CBC enc CBC dec CTR # Apple A7 2.39 1.20 1.20 # Cortex-A53 1.32 1.17/1.29(**) 1.36/1.46 # Cortex-A57(*) 1.95 0.82/0.85 0.89/0.93 # Cortex-A72 1.33 0.85/0.88 0.92/0.96 # Denver 1.96 0.65/0.86 0.76/0.80 # Mongoose 1.33 1.23/1.20 1.30/1.20 # Kryo 1.26 0.87/0.94 1.00/1.00 # ThunderX2 5.95 1.25 1.30 # # (*) original 3.64/1.34/1.32 results were for r0p0 revision # and are still same even for updated module; # (**) numbers after slash are for 32-bit code, which is 3x- # interleaved; # $output is the last argument if it looks like a file (it has an extension) # $flavour is the first argument if it doesn't look like a file $output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef; $flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef; $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1; ( $xlate="${dir}arm-xlate.pl" and -f $xlate ) or ( $xlate="${dir}../../perlasm/arm-xlate.pl" and -f $xlate) or die "can't locate arm-xlate.pl"; open OUT,"| \"$^X\" $xlate $flavour \"$output\"" or die "can't call $xlate: $!"; *STDOUT=*OUT; $prefix="aes_v8"; $_byte = ($flavour =~ /win/ ? "DCB" : ".byte"); $code=<<___; #include "arm_arch.h" #if __ARM_MAX_ARCH__>=7 ___ $code.=".arch armv8-a+crypto\n.text\n" if ($flavour =~ /64/); $code.=<<___ if ($flavour !~ /64/); .arch armv7-a // don't confuse not-so-latest binutils with argv8 :-) .fpu neon #ifdef __thumb2__ .syntax unified .thumb # define INST(a,b,c,d) $_byte c,d|0xc,a,b #else .code 32 # define INST(a,b,c,d) $_byte a,b,c,d #endif .text ___ # Assembler mnemonics are an eclectic mix of 32- and 64-bit syntax, # NEON is mostly 32-bit mnemonics, integer - mostly 64. Goal is to # maintain both 32- and 64-bit codes within single module and # transliterate common code to either flavour with regex vodoo. # {{{ my ($inp,$bits,$out,$ptr,$rounds)=("x0","w1","x2","x3","w12"); my ($zero,$rcon,$mask,$in0,$in1,$tmp,$key)= $flavour=~/64/? map("q$_",(0..6)) : map("q$_",(0..3,8..10)); $code.=<<___; .align 5 .Lrcon: .long 0x01,0x01,0x01,0x01 .long 0x0c0f0e0d,0x0c0f0e0d,0x0c0f0e0d,0x0c0f0e0d // rotate-n-splat .long 0x1b,0x1b,0x1b,0x1b .globl ${prefix}_set_encrypt_key .type ${prefix}_set_encrypt_key,%function .align 5 ${prefix}_set_encrypt_key: .Lenc_key: ___ $code.=<<___ if ($flavour =~ /64/); stp x29,x30,[sp,#-16]! add x29,sp,#0 ___ $code.=<<___; mov $ptr,#-1 cmp $inp,#0 b.eq .Lenc_key_abort cmp $out,#0 b.eq .Lenc_key_abort mov $ptr,#-2 cmp $bits,#128 b.lt .Lenc_key_abort cmp $bits,#256 b.gt .Lenc_key_abort tst $bits,#0x3f b.ne .Lenc_key_abort adr $ptr,.Lrcon cmp $bits,#192 veor $zero,$zero,$zero vld1.8 {$in0},[$inp],#16 mov $bits,#8 // reuse $bits vld1.32 {$rcon,$mask},[$ptr],#32 b.lt .Loop128 b.eq .L192 b .L256 .align 4 .Loop128: vtbl.8 $key,{$in0},$mask vext.8 $tmp,$zero,$in0,#12 vst1.32 {$in0},[$out],#16 aese $key,$zero subs $bits,$bits,#1 veor $in0,$in0,$tmp vext.8 $tmp,$zero,$tmp,#12 veor $in0,$in0,$tmp vext.8 $tmp,$zero,$tmp,#12 veor $key,$key,$rcon veor $in0,$in0,$tmp vshl.u8 $rcon,$rcon,#1 veor $in0,$in0,$key b.ne .Loop128 vld1.32 {$rcon},[$ptr] vtbl.8 $key,{$in0},$mask vext.8 $tmp,$zero,$in0,#12 vst1.32 {$in0},[$out],#16 aese $key,$zero veor $in0,$in0,$tmp vext.8 $tmp,$zero,$tmp,#12 veor $in0,$in0,$tmp vext.8 $tmp,$zero,$tmp,#12 veor $key,$key,$rcon veor $in0,$in0,$tmp vshl.u8 $rcon,$rcon,#1 veor $in0,$in0,$key vtbl.8 $key,{$in0},$mask vext.8 $tmp,$zero,$in0,#12 vst1.32 {$in0},[$out],#16 aese $key,$zero veor $in0,$in0,$tmp vext.8 $tmp,$zero,$tmp,#12 veor $in0,$in0,$tmp vext.8 $tmp,$zero,$tmp,#12 veor $key,$key,$rcon veor $in0,$in0,$tmp veor $in0,$in0,$key vst1.32 {$in0},[$out] add $out,$out,#0x50 mov $rounds,#10 b .Ldone .align 4 .L192: vld1.8 {$in1},[$inp],#8 vmov.i8 $key,#8 // borrow $key vst1.32 {$in0},[$out],#16 vsub.i8 $mask,$mask,$key // adjust the mask .Loop192: vtbl.8 $key,{$in1},$mask vext.8 $tmp,$zero,$in0,#12 #ifdef __ARMEB__ vst1.32 {$in1},[$out],#16 sub $out,$out,#8 #else vst1.32 {$in1},[$out],#8 #endif aese $key,$zero subs $bits,$bits,#1 veor $in0,$in0,$tmp vext.8 $tmp,$zero,$tmp,#12 veor $in0,$in0,$tmp vext.8 $tmp,$zero,$tmp,#12 veor $in0,$in0,$tmp vdup.32 $tmp,${in0}[3] veor $tmp,$tmp,$in1 veor $key,$key,$rcon vext.8 $in1,$zero,$in1,#12 vshl.u8 $rcon,$rcon,#1 veor $in1,$in1,$tmp veor $in0,$in0,$key veor $in1,$in1,$key vst1.32 {$in0},[$out],#16 b.ne .Loop192 mov $rounds,#12 add $out,$out,#0x20 b .Ldone .align 4 .L256: vld1.8 {$in1},[$inp] mov $bits,#7 mov $rounds,#14 vst1.32 {$in0},[$out],#16 .Loop256: vtbl.8 $key,{$in1},$mask vext.8 $tmp,$zero,$in0,#12 vst1.32 {$in1},[$out],#16 aese $key,$zero subs $bits,$bits,#1 veor $in0,$in0,$tmp vext.8 $tmp,$zero,$tmp,#12 veor $in0,$in0,$tmp vext.8 $tmp,$zero,$tmp,#12 veor $key,$key,$rcon veor $in0,$in0,$tmp vshl.u8 $rcon,$rcon,#1 veor $in0,$in0,$key vst1.32 {$in0},[$out],#16 b.eq .Ldone vdup.32 $key,${in0}[3] // just splat vext.8 $tmp,$zero,$in1,#12 aese $key,$zero veor $in1,$in1,$tmp vext.8 $tmp,$zero,$tmp,#12 veor $in1,$in1,$tmp vext.8 $tmp,$zero,$tmp,#12 veor $in1,$in1,$tmp veor $in1,$in1,$key b .Loop256 .Ldone: str $rounds,[$out] mov $ptr,#0 .Lenc_key_abort: mov x0,$ptr // return value `"ldr x29,[sp],#16" if ($flavour =~ /64/)` ret .size ${prefix}_set_encrypt_key,.-${prefix}_set_encrypt_key .globl ${prefix}_set_decrypt_key .type ${prefix}_set_decrypt_key,%function .align 5 ${prefix}_set_decrypt_key: ___ $code.=<<___ if ($flavour =~ /64/); .inst 0xd503233f // paciasp stp x29,x30,[sp,#-16]! add x29,sp,#0 ___ $code.=<<___ if ($flavour !~ /64/); stmdb sp!,{r4,lr} ___ $code.=<<___; bl .Lenc_key cmp x0,#0 b.ne .Ldec_key_abort sub $out,$out,#240 // restore original $out mov x4,#-16 add $inp,$out,x12,lsl#4 // end of key schedule vld1.32 {v0.16b},[$out] vld1.32 {v1.16b},[$inp] vst1.32 {v0.16b},[$inp],x4 vst1.32 {v1.16b},[$out],#16 .Loop_imc: vld1.32 {v0.16b},[$out] vld1.32 {v1.16b},[$inp] aesimc v0.16b,v0.16b aesimc v1.16b,v1.16b vst1.32 {v0.16b},[$inp],x4 vst1.32 {v1.16b},[$out],#16 cmp $inp,$out b.hi .Loop_imc vld1.32 {v0.16b},[$out] aesimc v0.16b,v0.16b vst1.32 {v0.16b},[$inp] eor x0,x0,x0 // return value .Ldec_key_abort: ___ $code.=<<___ if ($flavour !~ /64/); ldmia sp!,{r4,pc} ___ $code.=<<___ if ($flavour =~ /64/); ldp x29,x30,[sp],#16 .inst 0xd50323bf // autiasp ret ___ $code.=<<___; .size ${prefix}_set_decrypt_key,.-${prefix}_set_decrypt_key ___ }}} {{{ sub gen_block () { my $dir = shift; my ($e,$mc) = $dir eq "en" ? ("e","mc") : ("d","imc"); my ($inp,$out,$key)=map("x$_",(0..2)); my $rounds="w3"; my ($rndkey0,$rndkey1,$inout)=map("q$_",(0..3)); $code.=<<___; .globl ${prefix}_${dir}crypt .type ${prefix}_${dir}crypt,%function .align 5 ${prefix}_${dir}crypt: ldr $rounds,[$key,#240] vld1.32 {$rndkey0},[$key],#16 vld1.8 {$inout},[$inp] sub $rounds,$rounds,#2 vld1.32 {$rndkey1},[$key],#16 .Loop_${dir}c: aes$e $inout,$rndkey0 aes$mc $inout,$inout vld1.32 {$rndkey0},[$key],#16 subs $rounds,$rounds,#2 aes$e $inout,$rndkey1 aes$mc $inout,$inout vld1.32 {$rndkey1},[$key],#16 b.gt .Loop_${dir}c aes$e $inout,$rndkey0 aes$mc $inout,$inout vld1.32 {$rndkey0},[$key] aes$e $inout,$rndkey1 veor $inout,$inout,$rndkey0 vst1.8 {$inout},[$out] ret .size ${prefix}_${dir}crypt,.-${prefix}_${dir}crypt ___ } &gen_block("en"); &gen_block("de"); }}} # Performance in cycles per byte. # Processed with AES-ECB different key size. # It shows the value before and after optimization as below: # (before/after): # # AES-128-ECB AES-192-ECB AES-256-ECB # Cortex-A57 1.85/0.82 2.16/0.96 2.47/1.10 # Cortex-A72 1.64/0.85 1.82/0.99 2.13/1.14 # Optimization is implemented by loop unrolling and interleaving. # Commonly, we choose the unrolling factor as 5, if the input # data size smaller than 5 blocks, but not smaller than 3 blocks, # choose 3 as the unrolling factor. # If the input data size dsize >= 5*16 bytes, then take 5 blocks # as one iteration, every loop the left size lsize -= 5*16. # If 5*16 > lsize >= 3*16 bytes, take 3 blocks as one iteration, # every loop lsize -=3*16. # If lsize < 3*16 bytes, treat them as the tail, interleave the # two blocks AES instructions. # There is one special case, if the original input data size dsize # = 16 bytes, we will treat it seperately to improve the # performance: one independent code block without LR, FP load and # store, just looks like what the original ECB implementation does. {{{ my ($inp,$out,$len,$key)=map("x$_",(0..3)); my ($enc,$rounds,$cnt,$key_,$step)=("w4","w5","w6","x7","x8"); my ($dat0,$dat1,$in0,$in1,$tmp0,$tmp1,$tmp2,$rndlast)=map("q$_",(0..7)); my ($dat,$tmp,$rndzero_n_last)=($dat0,$tmp0,$tmp1); ### q7 last round key ### q10-q15 q7 Last 7 round keys ### q8-q9 preloaded round keys except last 7 keys for big size ### q5, q6, q8-q9 preloaded round keys except last 7 keys for only 16 byte { my ($dat2,$in2,$tmp2)=map("q$_",(10,11,9)); my ($dat3,$in3,$tmp3); # used only in 64-bit mode my ($dat4,$in4,$tmp4); if ($flavour =~ /64/) { ($dat2,$dat3,$dat4,$in2,$in3,$in4,$tmp3,$tmp4)=map("q$_",(16..23)); } $code.=<<___; .globl ${prefix}_ecb_encrypt .type ${prefix}_ecb_encrypt,%function .align 5 ${prefix}_ecb_encrypt: ___ $code.=<<___ if ($flavour =~ /64/); subs $len,$len,#16 // Original input data size bigger than 16, jump to big size processing. b.ne .Lecb_big_size vld1.8 {$dat0},[$inp] cmp $enc,#0 // en- or decrypting? ldr $rounds,[$key,#240] vld1.32 {q5-q6},[$key],#32 // load key schedule... b.eq .Lecb_small_dec aese $dat0,q5 aesmc $dat0,$dat0 vld1.32 {q8-q9},[$key],#32 // load key schedule... aese $dat0,q6 aesmc $dat0,$dat0 subs $rounds,$rounds,#10 // if rounds==10, jump to aes-128-ecb processing b.eq .Lecb_128_enc .Lecb_round_loop: aese $dat0,q8 aesmc $dat0,$dat0 vld1.32 {q8},[$key],#16 // load key schedule... aese $dat0,q9 aesmc $dat0,$dat0 vld1.32 {q9},[$key],#16 // load key schedule... subs $rounds,$rounds,#2 // bias b.gt .Lecb_round_loop .Lecb_128_enc: vld1.32 {q10-q11},[$key],#32 // load key schedule... aese $dat0,q8 aesmc $dat0,$dat0 aese $dat0,q9 aesmc $dat0,$dat0 vld1.32 {q12-q13},[$key],#32 // load key schedule... aese $dat0,q10 aesmc $dat0,$dat0 aese $dat0,q11 aesmc $dat0,$dat0 vld1.32 {q14-q15},[$key],#32 // load key schedule... aese $dat0,q12 aesmc $dat0,$dat0 aese $dat0,q13 aesmc $dat0,$dat0 vld1.32 {$rndlast},[$key] aese $dat0,q14 aesmc $dat0,$dat0 aese $dat0,q15 veor $dat0,$dat0,$rndlast vst1.8 {$dat0},[$out] b .Lecb_Final_abort .Lecb_small_dec: aesd $dat0,q5 aesimc $dat0,$dat0 vld1.32 {q8-q9},[$key],#32 // load key schedule... aesd $dat0,q6 aesimc $dat0,$dat0 subs $rounds,$rounds,#10 // bias b.eq .Lecb_128_dec .Lecb_dec_round_loop: aesd $dat0,q8 aesimc $dat0,$dat0 vld1.32 {q8},[$key],#16 // load key schedule... aesd $dat0,q9 aesimc $dat0,$dat0 vld1.32 {q9},[$key],#16 // load key schedule... subs $rounds,$rounds,#2 // bias b.gt .Lecb_dec_round_loop .Lecb_128_dec: vld1.32 {q10-q11},[$key],#32 // load key schedule... aesd $dat0,q8 aesimc $dat0,$dat0 aesd $dat0,q9 aesimc $dat0,$dat0 vld1.32 {q12-q13},[$key],#32 // load key schedule... aesd $dat0,q10 aesimc $dat0,$dat0 aesd $dat0,q11 aesimc $dat0,$dat0 vld1.32 {q14-q15},[$key],#32 // load key schedule... aesd $dat0,q12 aesimc $dat0,$dat0 aesd $dat0,q13 aesimc $dat0,$dat0 vld1.32 {$rndlast},[$key] aesd $dat0,q14 aesimc $dat0,$dat0 aesd $dat0,q15 veor $dat0,$dat0,$rndlast vst1.8 {$dat0},[$out] b .Lecb_Final_abort .Lecb_big_size: ___ $code.=<<___ if ($flavour =~ /64/); stp x29,x30,[sp,#-16]! add x29,sp,#0 ___ $code.=<<___ if ($flavour !~ /64/); mov ip,sp stmdb sp!,{r4-r8,lr} vstmdb sp!,{d8-d15} @ ABI specification says so ldmia ip,{r4-r5} @ load remaining args subs $len,$len,#16 ___ $code.=<<___; mov $step,#16 b.lo .Lecb_done cclr $step,eq cmp $enc,#0 // en- or decrypting? ldr $rounds,[$key,#240] and $len,$len,#-16 vld1.8 {$dat},[$inp],$step vld1.32 {q8-q9},[$key] // load key schedule... sub $rounds,$rounds,#6 add $key_,$key,x5,lsl#4 // pointer to last 7 round keys sub $rounds,$rounds,#2 vld1.32 {q10-q11},[$key_],#32 vld1.32 {q12-q13},[$key_],#32 vld1.32 {q14-q15},[$key_],#32 vld1.32 {$rndlast},[$key_] add $key_,$key,#32 mov $cnt,$rounds b.eq .Lecb_dec vld1.8 {$dat1},[$inp],#16 subs $len,$len,#32 // bias add $cnt,$rounds,#2 vorr $in1,$dat1,$dat1 vorr $dat2,$dat1,$dat1 vorr $dat1,$dat,$dat b.lo .Lecb_enc_tail vorr $dat1,$in1,$in1 vld1.8 {$dat2},[$inp],#16 ___ $code.=<<___ if ($flavour =~ /64/); cmp $len,#32 b.lo .Loop3x_ecb_enc vld1.8 {$dat3},[$inp],#16 vld1.8 {$dat4},[$inp],#16 sub $len,$len,#32 // bias mov $cnt,$rounds .Loop5x_ecb_enc: aese $dat0,q8 aesmc $dat0,$dat0 aese $dat1,q8 aesmc $dat1,$dat1 aese $dat2,q8 aesmc $dat2,$dat2 aese $dat3,q8 aesmc $dat3,$dat3 aese $dat4,q8 aesmc $dat4,$dat4 vld1.32 {q8},[$key_],#16 subs $cnt,$cnt,#2 aese $dat0,q9 aesmc $dat0,$dat0 aese $dat1,q9 aesmc $dat1,$dat1 aese $dat2,q9 aesmc $dat2,$dat2 aese $dat3,q9 aesmc $dat3,$dat3 aese $dat4,q9 aesmc $dat4,$dat4 vld1.32 {q9},[$key_],#16 b.gt .Loop5x_ecb_enc aese $dat0,q8 aesmc $dat0,$dat0 aese $dat1,q8 aesmc $dat1,$dat1 aese $dat2,q8 aesmc $dat2,$dat2 aese $dat3,q8 aesmc $dat3,$dat3 aese $dat4,q8 aesmc $dat4,$dat4 cmp $len,#0x40 // because .Lecb_enc_tail4x sub $len,$len,#0x50 aese $dat0,q9 aesmc $dat0,$dat0 aese $dat1,q9 aesmc $dat1,$dat1 aese $dat2,q9 aesmc $dat2,$dat2 aese $dat3,q9 aesmc $dat3,$dat3 aese $dat4,q9 aesmc $dat4,$dat4 csel x6,xzr,$len,gt // borrow x6, $cnt, "gt" is not typo mov $key_,$key aese $dat0,q10 aesmc $dat0,$dat0 aese $dat1,q10 aesmc $dat1,$dat1 aese $dat2,q10 aesmc $dat2,$dat2 aese $dat3,q10 aesmc $dat3,$dat3 aese $dat4,q10 aesmc $dat4,$dat4 add $inp,$inp,x6 // $inp is adjusted in such way that // at exit from the loop $dat1-$dat4 // are loaded with last "words" add x6,$len,#0x60 // because .Lecb_enc_tail4x aese $dat0,q11 aesmc $dat0,$dat0 aese $dat1,q11 aesmc $dat1,$dat1 aese $dat2,q11 aesmc $dat2,$dat2 aese $dat3,q11 aesmc $dat3,$dat3 aese $dat4,q11 aesmc $dat4,$dat4 aese $dat0,q12 aesmc $dat0,$dat0 aese $dat1,q12 aesmc $dat1,$dat1 aese $dat2,q12 aesmc $dat2,$dat2 aese $dat3,q12 aesmc $dat3,$dat3 aese $dat4,q12 aesmc $dat4,$dat4 aese $dat0,q13 aesmc $dat0,$dat0 aese $dat1,q13 aesmc $dat1,$dat1 aese $dat2,q13 aesmc $dat2,$dat2 aese $dat3,q13 aesmc $dat3,$dat3 aese $dat4,q13 aesmc $dat4,$dat4 aese $dat0,q14 aesmc $dat0,$dat0 aese $dat1,q14 aesmc $dat1,$dat1 aese $dat2,q14 aesmc $dat2,$dat2 aese $dat3,q14 aesmc $dat3,$dat3 aese $dat4,q14 aesmc $dat4,$dat4 aese $dat0,q15 vld1.8 {$in0},[$inp],#16 aese $dat1,q15 vld1.8 {$in1},[$inp],#16 aese $dat2,q15 vld1.8 {$in2},[$inp],#16 aese $dat3,q15 vld1.8 {$in3},[$inp],#16 aese $dat4,q15 vld1.8 {$in4},[$inp],#16 cbz x6,.Lecb_enc_tail4x vld1.32 {q8},[$key_],#16 // re-pre-load rndkey[0] veor $tmp0,$rndlast,$dat0 vorr $dat0,$in0,$in0 veor $tmp1,$rndlast,$dat1 vorr $dat1,$in1,$in1 veor $tmp2,$rndlast,$dat2 vorr $dat2,$in2,$in2 veor $tmp3,$rndlast,$dat3 vorr $dat3,$in3,$in3 veor $tmp4,$rndlast,$dat4 vst1.8 {$tmp0},[$out],#16 vorr $dat4,$in4,$in4 vst1.8 {$tmp1},[$out],#16 mov $cnt,$rounds vst1.8 {$tmp2},[$out],#16 vld1.32 {q9},[$key_],#16 // re-pre-load rndkey[1] vst1.8 {$tmp3},[$out],#16 vst1.8 {$tmp4},[$out],#16 b.hs .Loop5x_ecb_enc add $len,$len,#0x50 cbz $len,.Lecb_done add $cnt,$rounds,#2 subs $len,$len,#0x30 vorr $dat0,$in2,$in2 vorr $dat1,$in3,$in3 vorr $dat2,$in4,$in4 b.lo .Lecb_enc_tail b .Loop3x_ecb_enc .align 4 .Lecb_enc_tail4x: veor $tmp1,$rndlast,$dat1 veor $tmp2,$rndlast,$dat2 veor $tmp3,$rndlast,$dat3 veor $tmp4,$rndlast,$dat4 vst1.8 {$tmp1},[$out],#16 vst1.8 {$tmp2},[$out],#16 vst1.8 {$tmp3},[$out],#16 vst1.8 {$tmp4},[$out],#16 b .Lecb_done .align 4 ___ $code.=<<___; .Loop3x_ecb_enc: aese $dat0,q8 aesmc $dat0,$dat0 aese $dat1,q8 aesmc $dat1,$dat1 aese $dat2,q8 aesmc $dat2,$dat2 vld1.32 {q8},[$key_],#16 subs $cnt,$cnt,#2 aese $dat0,q9 aesmc $dat0,$dat0 aese $dat1,q9 aesmc $dat1,$dat1 aese $dat2,q9 aesmc $dat2,$dat2 vld1.32 {q9},[$key_],#16 b.gt .Loop3x_ecb_enc aese $dat0,q8 aesmc $dat0,$dat0 aese $dat1,q8 aesmc $dat1,$dat1 aese $dat2,q8 aesmc $dat2,$dat2 subs $len,$len,#0x30 mov.lo x6,$len // x6, $cnt, is zero at this point aese $dat0,q9 aesmc $dat0,$dat0 aese $dat1,q9 aesmc $dat1,$dat1 aese $dat2,q9 aesmc $dat2,$dat2 add $inp,$inp,x6 // $inp is adjusted in such way that // at exit from the loop $dat1-$dat2 // are loaded with last "words" mov $key_,$key aese $dat0,q12 aesmc $dat0,$dat0 aese $dat1,q12 aesmc $dat1,$dat1 aese $dat2,q12 aesmc $dat2,$dat2 vld1.8 {$in0},[$inp],#16 aese $dat0,q13 aesmc $dat0,$dat0 aese $dat1,q13 aesmc $dat1,$dat1 aese $dat2,q13 aesmc $dat2,$dat2 vld1.8 {$in1},[$inp],#16 aese $dat0,q14 aesmc $dat0,$dat0 aese $dat1,q14 aesmc $dat1,$dat1 aese $dat2,q14 aesmc $dat2,$dat2 vld1.8 {$in2},[$inp],#16 aese $dat0,q15 aese $dat1,q15 aese $dat2,q15 vld1.32 {q8},[$key_],#16 // re-pre-load rndkey[0] add $cnt,$rounds,#2 veor $tmp0,$rndlast,$dat0 veor $tmp1,$rndlast,$dat1 veor $dat2,$dat2,$rndlast vld1.32 {q9},[$key_],#16 // re-pre-load rndkey[1] vst1.8 {$tmp0},[$out],#16 vorr $dat0,$in0,$in0 vst1.8 {$tmp1},[$out],#16 vorr $dat1,$in1,$in1 vst1.8 {$dat2},[$out],#16 vorr $dat2,$in2,$in2 b.hs .Loop3x_ecb_enc cmn $len,#0x30 b.eq .Lecb_done nop .Lecb_enc_tail: aese $dat1,q8 aesmc $dat1,$dat1 aese $dat2,q8 aesmc $dat2,$dat2 vld1.32 {q8},[$key_],#16 subs $cnt,$cnt,#2 aese $dat1,q9 aesmc $dat1,$dat1 aese $dat2,q9 aesmc $dat2,$dat2 vld1.32 {q9},[$key_],#16 b.gt .Lecb_enc_tail aese $dat1,q8 aesmc $dat1,$dat1 aese $dat2,q8 aesmc $dat2,$dat2 aese $dat1,q9 aesmc $dat1,$dat1 aese $dat2,q9 aesmc $dat2,$dat2 aese $dat1,q12 aesmc $dat1,$dat1 aese $dat2,q12 aesmc $dat2,$dat2 cmn $len,#0x20 aese $dat1,q13 aesmc $dat1,$dat1 aese $dat2,q13 aesmc $dat2,$dat2 aese $dat1,q14 aesmc $dat1,$dat1 aese $dat2,q14 aesmc $dat2,$dat2 aese $dat1,q15 aese $dat2,q15 b.eq .Lecb_enc_one veor $tmp1,$rndlast,$dat1 veor $tmp2,$rndlast,$dat2 vst1.8 {$tmp1},[$out],#16 vst1.8 {$tmp2},[$out],#16 b .Lecb_done .Lecb_enc_one: veor $tmp1,$rndlast,$dat2 vst1.8 {$tmp1},[$out],#16 b .Lecb_done ___ $code.=<<___; .align 5 .Lecb_dec: vld1.8 {$dat1},[$inp],#16 subs $len,$len,#32 // bias add $cnt,$rounds,#2 vorr $in1,$dat1,$dat1 vorr $dat2,$dat1,$dat1 vorr $dat1,$dat,$dat b.lo .Lecb_dec_tail vorr $dat1,$in1,$in1 vld1.8 {$dat2},[$inp],#16 ___ $code.=<<___ if ($flavour =~ /64/); cmp $len,#32 b.lo .Loop3x_ecb_dec vld1.8 {$dat3},[$inp],#16 vld1.8 {$dat4},[$inp],#16 sub $len,$len,#32 // bias mov $cnt,$rounds .Loop5x_ecb_dec: aesd $dat0,q8 aesimc $dat0,$dat0 aesd $dat1,q8 aesimc $dat1,$dat1 aesd $dat2,q8 aesimc $dat2,$dat2 aesd $dat3,q8 aesimc $dat3,$dat3 aesd $dat4,q8 aesimc $dat4,$dat4 vld1.32 {q8},[$key_],#16 subs $cnt,$cnt,#2 aesd $dat0,q9 aesimc $dat0,$dat0 aesd $dat1,q9 aesimc $dat1,$dat1 aesd $dat2,q9 aesimc $dat2,$dat2 aesd $dat3,q9 aesimc $dat3,$dat3 aesd $dat4,q9 aesimc $dat4,$dat4 vld1.32 {q9},[$key_],#16 b.gt .Loop5x_ecb_dec aesd $dat0,q8 aesimc $dat0,$dat0 aesd $dat1,q8 aesimc $dat1,$dat1 aesd $dat2,q8 aesimc $dat2,$dat2 aesd $dat3,q8 aesimc $dat3,$dat3 aesd $dat4,q8 aesimc $dat4,$dat4 cmp $len,#0x40 // because .Lecb_tail4x sub $len,$len,#0x50 aesd $dat0,q9 aesimc $dat0,$dat0 aesd $dat1,q9 aesimc $dat1,$dat1 aesd $dat2,q9 aesimc $dat2,$dat2 aesd $dat3,q9 aesimc $dat3,$dat3 aesd $dat4,q9 aesimc $dat4,$dat4 csel x6,xzr,$len,gt // borrow x6, $cnt, "gt" is not typo mov $key_,$key aesd $dat0,q10 aesimc $dat0,$dat0 aesd $dat1,q10 aesimc $dat1,$dat1 aesd $dat2,q10 aesimc $dat2,$dat2 aesd $dat3,q10 aesimc $dat3,$dat3 aesd $dat4,q10 aesimc $dat4,$dat4 add $inp,$inp,x6 // $inp is adjusted in such way that // at exit from the loop $dat1-$dat4 // are loaded with last "words" add x6,$len,#0x60 // because .Lecb_tail4x aesd $dat0,q11 aesimc $dat0,$dat0 aesd $dat1,q11 aesimc $dat1,$dat1 aesd $dat2,q11 aesimc $dat2,$dat2 aesd $dat3,q11 aesimc $dat3,$dat3 aesd $dat4,q11 aesimc $dat4,$dat4 aesd $dat0,q12 aesimc $dat0,$dat0 aesd $dat1,q12 aesimc $dat1,$dat1 aesd $dat2,q12 aesimc $dat2,$dat2 aesd $dat3,q12 aesimc $dat3,$dat3 aesd $dat4,q12 aesimc $dat4,$dat4 aesd $dat0,q13 aesimc $dat0,$dat0 aesd $dat1,q13 aesimc $dat1,$dat1 aesd $dat2,q13 aesimc $dat2,$dat2 aesd $dat3,q13 aesimc $dat3,$dat3 aesd $dat4,q13 aesimc $dat4,$dat4 aesd $dat0,q14 aesimc $dat0,$dat0 aesd $dat1,q14 aesimc $dat1,$dat1 aesd $dat2,q14 aesimc $dat2,$dat2 aesd $dat3,q14 aesimc $dat3,$dat3 aesd $dat4,q14 aesimc $dat4,$dat4 aesd $dat0,q15 vld1.8 {$in0},[$inp],#16 aesd $dat1,q15 vld1.8 {$in1},[$inp],#16 aesd $dat2,q15 vld1.8 {$in2},[$inp],#16 aesd $dat3,q15 vld1.8 {$in3},[$inp],#16 aesd $dat4,q15 vld1.8 {$in4},[$inp],#16 cbz x6,.Lecb_tail4x vld1.32 {q8},[$key_],#16 // re-pre-load rndkey[0] veor $tmp0,$rndlast,$dat0 vorr $dat0,$in0,$in0 veor $tmp1,$rndlast,$dat1 vorr $dat1,$in1,$in1 veor $tmp2,$rndlast,$dat2 vorr $dat2,$in2,$in2 veor $tmp3,$rndlast,$dat3 vorr $dat3,$in3,$in3 veor $tmp4,$rndlast,$dat4 vst1.8 {$tmp0},[$out],#16 vorr $dat4,$in4,$in4 vst1.8 {$tmp1},[$out],#16 mov $cnt,$rounds vst1.8 {$tmp2},[$out],#16 vld1.32 {q9},[$key_],#16 // re-pre-load rndkey[1] vst1.8 {$tmp3},[$out],#16 vst1.8 {$tmp4},[$out],#16 b.hs .Loop5x_ecb_dec add $len,$len,#0x50 cbz $len,.Lecb_done add $cnt,$rounds,#2 subs $len,$len,#0x30 vorr $dat0,$in2,$in2 vorr $dat1,$in3,$in3 vorr $dat2,$in4,$in4 b.lo .Lecb_dec_tail b .Loop3x_ecb_dec .align 4 .Lecb_tail4x: veor $tmp1,$rndlast,$dat1 veor $tmp2,$rndlast,$dat2 veor $tmp3,$rndlast,$dat3 veor $tmp4,$rndlast,$dat4 vst1.8 {$tmp1},[$out],#16 vst1.8 {$tmp2},[$out],#16 vst1.8 {$tmp3},[$out],#16 vst1.8 {$tmp4},[$out],#16 b .Lecb_done .align 4 ___ $code.=<<___; .Loop3x_ecb_dec: aesd $dat0,q8 aesimc $dat0,$dat0 aesd $dat1,q8 aesimc $dat1,$dat1 aesd $dat2,q8 aesimc $dat2,$dat2 vld1.32 {q8},[$key_],#16 subs $cnt,$cnt,#2 aesd $dat0,q9 aesimc $dat0,$dat0 aesd $dat1,q9 aesimc $dat1,$dat1 aesd $dat2,q9 aesimc $dat2,$dat2 vld1.32 {q9},[$key_],#16 b.gt .Loop3x_ecb_dec aesd $dat0,q8 aesimc $dat0,$dat0 aesd $dat1,q8 aesimc $dat1,$dat1 aesd $dat2,q8 aesimc $dat2,$dat2 subs $len,$len,#0x30 mov.lo x6,$len // x6, $cnt, is zero at this point aesd $dat0,q9 aesimc $dat0,$dat0 aesd $dat1,q9 aesimc $dat1,$dat1 aesd $dat2,q9 aesimc $dat2,$dat2 add $inp,$inp,x6 // $inp is adjusted in such way that // at exit from the loop $dat1-$dat2 // are loaded with last "words" mov $key_,$key aesd $dat0,q12 aesimc $dat0,$dat0 aesd $dat1,q12 aesimc $dat1,$dat1 aesd $dat2,q12 aesimc $dat2,$dat2 vld1.8 {$in0},[$inp],#16 aesd $dat0,q13 aesimc $dat0,$dat0 aesd $dat1,q13 aesimc $dat1,$dat1 aesd $dat2,q13 aesimc $dat2,$dat2 vld1.8 {$in1},[$inp],#16 aesd $dat0,q14 aesimc $dat0,$dat0 aesd $dat1,q14 aesimc $dat1,$dat1 aesd $dat2,q14 aesimc $dat2,$dat2 vld1.8 {$in2},[$inp],#16 aesd $dat0,q15 aesd $dat1,q15 aesd $dat2,q15 vld1.32 {q8},[$key_],#16 // re-pre-load rndkey[0] add $cnt,$rounds,#2 veor $tmp0,$rndlast,$dat0 veor $tmp1,$rndlast,$dat1 veor $dat2,$dat2,$rndlast vld1.32 {q9},[$key_],#16 // re-pre-load rndkey[1] vst1.8 {$tmp0},[$out],#16 vorr $dat0,$in0,$in0 vst1.8 {$tmp1},[$out],#16 vorr $dat1,$in1,$in1 vst1.8 {$dat2},[$out],#16 vorr $dat2,$in2,$in2 b.hs .Loop3x_ecb_dec cmn $len,#0x30 b.eq .Lecb_done nop .Lecb_dec_tail: aesd $dat1,q8 aesimc $dat1,$dat1 aesd $dat2,q8 aesimc $dat2,$dat2 vld1.32 {q8},[$key_],#16 subs $cnt,$cnt,#2 aesd $dat1,q9 aesimc $dat1,$dat1 aesd $dat2,q9 aesimc $dat2,$dat2 vld1.32 {q9},[$key_],#16 b.gt .Lecb_dec_tail aesd $dat1,q8 aesimc $dat1,$dat1 aesd $dat2,q8 aesimc $dat2,$dat2 aesd $dat1,q9 aesimc $dat1,$dat1 aesd $dat2,q9 aesimc $dat2,$dat2 aesd $dat1,q12 aesimc $dat1,$dat1 aesd $dat2,q12 aesimc $dat2,$dat2 cmn $len,#0x20 aesd $dat1,q13 aesimc $dat1,$dat1 aesd $dat2,q13 aesimc $dat2,$dat2 aesd $dat1,q14 aesimc $dat1,$dat1 aesd $dat2,q14 aesimc $dat2,$dat2 aesd $dat1,q15 aesd $dat2,q15 b.eq .Lecb_dec_one veor $tmp1,$rndlast,$dat1 veor $tmp2,$rndlast,$dat2 vst1.8 {$tmp1},[$out],#16 vst1.8 {$tmp2},[$out],#16 b .Lecb_done .Lecb_dec_one: veor $tmp1,$rndlast,$dat2 vst1.8 {$tmp1},[$out],#16 .Lecb_done: ___ } $code.=<<___ if ($flavour !~ /64/); vldmia sp!,{d8-d15} ldmia sp!,{r4-r8,pc} ___ $code.=<<___ if ($flavour =~ /64/); ldr x29,[sp],#16 ___ $code.=<<___ if ($flavour =~ /64/); .Lecb_Final_abort: ret ___ $code.=<<___; .size ${prefix}_ecb_encrypt,.-${prefix}_ecb_encrypt ___ }}} {{{ my ($inp,$out,$len,$key,$ivp)=map("x$_",(0..4)); my $enc="w5"; my ($rounds,$cnt,$key_,$step,$step1)=($enc,"w6","x7","x8","x12"); my ($dat0,$dat1,$in0,$in1,$tmp0,$tmp1,$ivec,$rndlast)=map("q$_",(0..7)); my ($dat,$tmp,$rndzero_n_last)=($dat0,$tmp0,$tmp1); my ($key4,$key5,$key6,$key7)=("x6","x12","x14",$key); ### q8-q15 preloaded key schedule $code.=<<___; .globl ${prefix}_cbc_encrypt .type ${prefix}_cbc_encrypt,%function .align 5 ${prefix}_cbc_encrypt: ___ $code.=<<___ if ($flavour =~ /64/); stp x29,x30,[sp,#-16]! add x29,sp,#0 ___ $code.=<<___ if ($flavour !~ /64/); mov ip,sp stmdb sp!,{r4-r8,lr} vstmdb sp!,{d8-d15} @ ABI specification says so ldmia ip,{r4-r5} @ load remaining args ___ $code.=<<___; subs $len,$len,#16 mov $step,#16 b.lo .Lcbc_abort cclr $step,eq cmp $enc,#0 // en- or decrypting? ldr $rounds,[$key,#240] and $len,$len,#-16 vld1.8 {$ivec},[$ivp] vld1.8 {$dat},[$inp],$step vld1.32 {q8-q9},[$key] // load key schedule... sub $rounds,$rounds,#6 add $key_,$key,x5,lsl#4 // pointer to last 7 round keys sub $rounds,$rounds,#2 vld1.32 {q10-q11},[$key_],#32 vld1.32 {q12-q13},[$key_],#32 vld1.32 {q14-q15},[$key_],#32 vld1.32 {$rndlast},[$key_] add $key_,$key,#32 mov $cnt,$rounds b.eq .Lcbc_dec cmp $rounds,#2 veor $dat,$dat,$ivec veor $rndzero_n_last,q8,$rndlast b.eq .Lcbc_enc128 vld1.32 {$in0-$in1},[$key_] add $key_,$key,#16 add $key4,$key,#16*4 add $key5,$key,#16*5 aese $dat,q8 aesmc $dat,$dat add $key6,$key,#16*6 add $key7,$key,#16*7 b .Lenter_cbc_enc .align 4 .Loop_cbc_enc: aese $dat,q8 aesmc $dat,$dat vst1.8 {$ivec},[$out],#16 .Lenter_cbc_enc: aese $dat,q9 aesmc $dat,$dat aese $dat,$in0 aesmc $dat,$dat vld1.32 {q8},[$key4] cmp $rounds,#4 aese $dat,$in1 aesmc $dat,$dat vld1.32 {q9},[$key5] b.eq .Lcbc_enc192 aese $dat,q8 aesmc $dat,$dat vld1.32 {q8},[$key6] aese $dat,q9 aesmc $dat,$dat vld1.32 {q9},[$key7] nop .Lcbc_enc192: aese $dat,q8 aesmc $dat,$dat subs $len,$len,#16 aese $dat,q9 aesmc $dat,$dat cclr $step,eq aese $dat,q10 aesmc $dat,$dat aese $dat,q11 aesmc $dat,$dat vld1.8 {q8},[$inp],$step aese $dat,q12 aesmc $dat,$dat veor q8,q8,$rndzero_n_last aese $dat,q13 aesmc $dat,$dat vld1.32 {q9},[$key_] // re-pre-load rndkey[1] aese $dat,q14 aesmc $dat,$dat aese $dat,q15 veor $ivec,$dat,$rndlast b.hs .Loop_cbc_enc vst1.8 {$ivec},[$out],#16 b .Lcbc_done .align 5 .Lcbc_enc128: vld1.32 {$in0-$in1},[$key_] aese $dat,q8 aesmc $dat,$dat b .Lenter_cbc_enc128 .Loop_cbc_enc128: aese $dat,q8 aesmc $dat,$dat vst1.8 {$ivec},[$out],#16 .Lenter_cbc_enc128: aese $dat,q9 aesmc $dat,$dat subs $len,$len,#16 aese $dat,$in0 aesmc $dat,$dat cclr $step,eq aese $dat,$in1 aesmc $dat,$dat aese $dat,q10 aesmc $dat,$dat aese $dat,q11 aesmc $dat,$dat vld1.8 {q8},[$inp],$step aese $dat,q12 aesmc $dat,$dat aese $dat,q13 aesmc $dat,$dat aese $dat,q14 aesmc $dat,$dat veor q8,q8,$rndzero_n_last aese $dat,q15 veor $ivec,$dat,$rndlast b.hs .Loop_cbc_enc128 vst1.8 {$ivec},[$out],#16 b .Lcbc_done ___ { my ($dat2,$in2,$tmp2)=map("q$_",(10,11,9)); my ($dat3,$in3,$tmp3); # used only in 64-bit mode my ($dat4,$in4,$tmp4); if ($flavour =~ /64/) { ($dat2,$dat3,$dat4,$in2,$in3,$in4,$tmp3,$tmp4)=map("q$_",(16..23)); } $code.=<<___; .align 5 .Lcbc_dec: vld1.8 {$dat2},[$inp],#16 subs $len,$len,#32 // bias add $cnt,$rounds,#2 vorr $in1,$dat,$dat vorr $dat1,$dat,$dat vorr $in2,$dat2,$dat2 b.lo .Lcbc_dec_tail vorr $dat1,$dat2,$dat2 vld1.8 {$dat2},[$inp],#16 vorr $in0,$dat,$dat vorr $in1,$dat1,$dat1 vorr $in2,$dat2,$dat2 ___ $code.=<<___ if ($flavour =~ /64/); cmp $len,#32 b.lo .Loop3x_cbc_dec vld1.8 {$dat3},[$inp],#16 vld1.8 {$dat4},[$inp],#16 sub $len,$len,#32 // bias mov $cnt,$rounds vorr $in3,$dat3,$dat3 vorr $in4,$dat4,$dat4 .Loop5x_cbc_dec: aesd $dat0,q8 aesimc $dat0,$dat0 aesd $dat1,q8 aesimc $dat1,$dat1 aesd $dat2,q8 aesimc $dat2,$dat2 aesd $dat3,q8 aesimc $dat3,$dat3 aesd $dat4,q8 aesimc $dat4,$dat4 vld1.32 {q8},[$key_],#16 subs $cnt,$cnt,#2 aesd $dat0,q9 aesimc $dat0,$dat0 aesd $dat1,q9 aesimc $dat1,$dat1 aesd $dat2,q9 aesimc $dat2,$dat2 aesd $dat3,q9 aesimc $dat3,$dat3 aesd $dat4,q9 aesimc $dat4,$dat4 vld1.32 {q9},[$key_],#16 b.gt .Loop5x_cbc_dec aesd $dat0,q8 aesimc $dat0,$dat0 aesd $dat1,q8 aesimc $dat1,$dat1 aesd $dat2,q8 aesimc $dat2,$dat2 aesd $dat3,q8 aesimc $dat3,$dat3 aesd $dat4,q8 aesimc $dat4,$dat4 cmp $len,#0x40 // because .Lcbc_tail4x sub $len,$len,#0x50 aesd $dat0,q9 aesimc $dat0,$dat0 aesd $dat1,q9 aesimc $dat1,$dat1 aesd $dat2,q9 aesimc $dat2,$dat2 aesd $dat3,q9 aesimc $dat3,$dat3 aesd $dat4,q9 aesimc $dat4,$dat4 csel x6,xzr,$len,gt // borrow x6, $cnt, "gt" is not typo mov $key_,$key aesd $dat0,q10 aesimc $dat0,$dat0 aesd $dat1,q10 aesimc $dat1,$dat1 aesd $dat2,q10 aesimc $dat2,$dat2 aesd $dat3,q10 aesimc $dat3,$dat3 aesd $dat4,q10 aesimc $dat4,$dat4 add $inp,$inp,x6 // $inp is adjusted in such way that // at exit from the loop $dat1-$dat4 // are loaded with last "words" add x6,$len,#0x60 // because .Lcbc_tail4x aesd $dat0,q11 aesimc $dat0,$dat0 aesd $dat1,q11 aesimc $dat1,$dat1 aesd $dat2,q11 aesimc $dat2,$dat2 aesd $dat3,q11 aesimc $dat3,$dat3 aesd $dat4,q11 aesimc $dat4,$dat4 aesd $dat0,q12 aesimc $dat0,$dat0 aesd $dat1,q12 aesimc $dat1,$dat1 aesd $dat2,q12 aesimc $dat2,$dat2 aesd $dat3,q12 aesimc $dat3,$dat3 aesd $dat4,q12 aesimc $dat4,$dat4 aesd $dat0,q13 aesimc $dat0,$dat0 aesd $dat1,q13 aesimc $dat1,$dat1 aesd $dat2,q13 aesimc $dat2,$dat2 aesd $dat3,q13 aesimc $dat3,$dat3 aesd $dat4,q13 aesimc $dat4,$dat4 aesd $dat0,q14 aesimc $dat0,$dat0 aesd $dat1,q14 aesimc $dat1,$dat1 aesd $dat2,q14 aesimc $dat2,$dat2 aesd $dat3,q14 aesimc $dat3,$dat3 aesd $dat4,q14 aesimc $dat4,$dat4 veor $tmp0,$ivec,$rndlast aesd $dat0,q15 veor $tmp1,$in0,$rndlast vld1.8 {$in0},[$inp],#16 aesd $dat1,q15 veor $tmp2,$in1,$rndlast vld1.8 {$in1},[$inp],#16 aesd $dat2,q15 veor $tmp3,$in2,$rndlast vld1.8 {$in2},[$inp],#16 aesd $dat3,q15 veor $tmp4,$in3,$rndlast vld1.8 {$in3},[$inp],#16 aesd $dat4,q15 vorr $ivec,$in4,$in4 vld1.8 {$in4},[$inp],#16 cbz x6,.Lcbc_tail4x vld1.32 {q8},[$key_],#16 // re-pre-load rndkey[0] veor $tmp0,$tmp0,$dat0 vorr $dat0,$in0,$in0 veor $tmp1,$tmp1,$dat1 vorr $dat1,$in1,$in1 veor $tmp2,$tmp2,$dat2 vorr $dat2,$in2,$in2 veor $tmp3,$tmp3,$dat3 vorr $dat3,$in3,$in3 veor $tmp4,$tmp4,$dat4 vst1.8 {$tmp0},[$out],#16 vorr $dat4,$in4,$in4 vst1.8 {$tmp1},[$out],#16 mov $cnt,$rounds vst1.8 {$tmp2},[$out],#16 vld1.32 {q9},[$key_],#16 // re-pre-load rndkey[1] vst1.8 {$tmp3},[$out],#16 vst1.8 {$tmp4},[$out],#16 b.hs .Loop5x_cbc_dec add $len,$len,#0x50 cbz $len,.Lcbc_done add $cnt,$rounds,#2 subs $len,$len,#0x30 vorr $dat0,$in2,$in2 vorr $in0,$in2,$in2 vorr $dat1,$in3,$in3 vorr $in1,$in3,$in3 vorr $dat2,$in4,$in4 vorr $in2,$in4,$in4 b.lo .Lcbc_dec_tail b .Loop3x_cbc_dec .align 4 .Lcbc_tail4x: veor $tmp1,$tmp0,$dat1 veor $tmp2,$tmp2,$dat2 veor $tmp3,$tmp3,$dat3 veor $tmp4,$tmp4,$dat4 vst1.8 {$tmp1},[$out],#16 vst1.8 {$tmp2},[$out],#16 vst1.8 {$tmp3},[$out],#16 vst1.8 {$tmp4},[$out],#16 b .Lcbc_done .align 4 ___ $code.=<<___; .Loop3x_cbc_dec: aesd $dat0,q8 aesimc $dat0,$dat0 aesd $dat1,q8 aesimc $dat1,$dat1 aesd $dat2,q8 aesimc $dat2,$dat2 vld1.32 {q8},[$key_],#16 subs $cnt,$cnt,#2 aesd $dat0,q9 aesimc $dat0,$dat0 aesd $dat1,q9 aesimc $dat1,$dat1 aesd $dat2,q9 aesimc $dat2,$dat2 vld1.32 {q9},[$key_],#16 b.gt .Loop3x_cbc_dec aesd $dat0,q8 aesimc $dat0,$dat0 aesd $dat1,q8 aesimc $dat1,$dat1 aesd $dat2,q8 aesimc $dat2,$dat2 veor $tmp0,$ivec,$rndlast subs $len,$len,#0x30 veor $tmp1,$in0,$rndlast mov.lo x6,$len // x6, $cnt, is zero at this point aesd $dat0,q9 aesimc $dat0,$dat0 aesd $dat1,q9 aesimc $dat1,$dat1 aesd $dat2,q9 aesimc $dat2,$dat2 veor $tmp2,$in1,$rndlast add $inp,$inp,x6 // $inp is adjusted in such way that // at exit from the loop $dat1-$dat2 // are loaded with last "words" vorr $ivec,$in2,$in2 mov $key_,$key aesd $dat0,q12 aesimc $dat0,$dat0 aesd $dat1,q12 aesimc $dat1,$dat1 aesd $dat2,q12 aesimc $dat2,$dat2 vld1.8 {$in0},[$inp],#16 aesd $dat0,q13 aesimc $dat0,$dat0 aesd $dat1,q13 aesimc $dat1,$dat1 aesd $dat2,q13 aesimc $dat2,$dat2 vld1.8 {$in1},[$inp],#16 aesd $dat0,q14 aesimc $dat0,$dat0 aesd $dat1,q14 aesimc $dat1,$dat1 aesd $dat2,q14 aesimc $dat2,$dat2 vld1.8 {$in2},[$inp],#16 aesd $dat0,q15 aesd $dat1,q15 aesd $dat2,q15 vld1.32 {q8},[$key_],#16 // re-pre-load rndkey[0] add $cnt,$rounds,#2 veor $tmp0,$tmp0,$dat0 veor $tmp1,$tmp1,$dat1 veor $dat2,$dat2,$tmp2 vld1.32 {q9},[$key_],#16 // re-pre-load rndkey[1] vst1.8 {$tmp0},[$out],#16 vorr $dat0,$in0,$in0 vst1.8 {$tmp1},[$out],#16 vorr $dat1,$in1,$in1 vst1.8 {$dat2},[$out],#16 vorr $dat2,$in2,$in2 b.hs .Loop3x_cbc_dec cmn $len,#0x30 b.eq .Lcbc_done nop .Lcbc_dec_tail: aesd $dat1,q8 aesimc $dat1,$dat1 aesd $dat2,q8 aesimc $dat2,$dat2 vld1.32 {q8},[$key_],#16 subs $cnt,$cnt,#2 aesd $dat1,q9 aesimc $dat1,$dat1 aesd $dat2,q9 aesimc $dat2,$dat2 vld1.32 {q9},[$key_],#16 b.gt .Lcbc_dec_tail aesd $dat1,q8 aesimc $dat1,$dat1 aesd $dat2,q8 aesimc $dat2,$dat2 aesd $dat1,q9 aesimc $dat1,$dat1 aesd $dat2,q9 aesimc $dat2,$dat2 aesd $dat1,q12 aesimc $dat1,$dat1 aesd $dat2,q12 aesimc $dat2,$dat2 cmn $len,#0x20 aesd $dat1,q13 aesimc $dat1,$dat1 aesd $dat2,q13 aesimc $dat2,$dat2 veor $tmp1,$ivec,$rndlast aesd $dat1,q14 aesimc $dat1,$dat1 aesd $dat2,q14 aesimc $dat2,$dat2 veor $tmp2,$in1,$rndlast aesd $dat1,q15 aesd $dat2,q15 b.eq .Lcbc_dec_one veor $tmp1,$tmp1,$dat1 veor $tmp2,$tmp2,$dat2 vorr $ivec,$in2,$in2 vst1.8 {$tmp1},[$out],#16 vst1.8 {$tmp2},[$out],#16 b .Lcbc_done .Lcbc_dec_one: veor $tmp1,$tmp1,$dat2 vorr $ivec,$in2,$in2 vst1.8 {$tmp1},[$out],#16 .Lcbc_done: vst1.8 {$ivec},[$ivp] .Lcbc_abort: ___ } $code.=<<___ if ($flavour !~ /64/); vldmia sp!,{d8-d15} ldmia sp!,{r4-r8,pc} ___ $code.=<<___ if ($flavour =~ /64/); ldr x29,[sp],#16 ret ___ $code.=<<___; .size ${prefix}_cbc_encrypt,.-${prefix}_cbc_encrypt ___ }}} {{{ my ($inp,$out,$len,$key,$ivp)=map("x$_",(0..4)); my ($rounds,$cnt,$key_)=("w5","w6","x7"); my ($ctr,$tctr0,$tctr1,$tctr2)=map("w$_",(8..10,12)); my $step="x12"; # aliases with $tctr2 my ($dat0,$dat1,$in0,$in1,$tmp0,$tmp1,$ivec,$rndlast)=map("q$_",(0..7)); my ($dat2,$in2,$tmp2)=map("q$_",(10,11,9)); # used only in 64-bit mode... my ($dat3,$dat4,$in3,$in4)=map("q$_",(16..23)); my ($dat,$tmp)=($dat0,$tmp0); ### q8-q15 preloaded key schedule $code.=<<___; .globl ${prefix}_ctr32_encrypt_blocks .type ${prefix}_ctr32_encrypt_blocks,%function .align 5 ${prefix}_ctr32_encrypt_blocks: ___ $code.=<<___ if ($flavour =~ /64/); stp x29,x30,[sp,#-16]! add x29,sp,#0 ___ $code.=<<___ if ($flavour !~ /64/); mov ip,sp stmdb sp!,{r4-r10,lr} vstmdb sp!,{d8-d15} @ ABI specification says so ldr r4, [ip] @ load remaining arg ___ $code.=<<___; ldr $rounds,[$key,#240] ldr $ctr, [$ivp, #12] #ifdef __ARMEB__ vld1.8 {$dat0},[$ivp] #else vld1.32 {$dat0},[$ivp] #endif vld1.32 {q8-q9},[$key] // load key schedule... sub $rounds,$rounds,#4 mov $step,#16 cmp $len,#2 add $key_,$key,x5,lsl#4 // pointer to last 5 round keys sub $rounds,$rounds,#2 vld1.32 {q12-q13},[$key_],#32 vld1.32 {q14-q15},[$key_],#32 vld1.32 {$rndlast},[$key_] add $key_,$key,#32 mov $cnt,$rounds cclr $step,lo #ifndef __ARMEB__ rev $ctr, $ctr #endif ___ $code.=<<___ if ($flavour =~ /64/); vorr $dat1,$dat0,$dat0 add $tctr1, $ctr, #1 vorr $dat2,$dat0,$dat0 add $ctr, $ctr, #2 vorr $ivec,$dat0,$dat0 rev $tctr1, $tctr1 vmov.32 ${dat1}[3],$tctr1 b.ls .Lctr32_tail rev $tctr2, $ctr sub $len,$len,#3 // bias vmov.32 ${dat2}[3],$tctr2 ___ $code.=<<___ if ($flavour !~ /64/); add $tctr1, $ctr, #1 vorr $ivec,$dat0,$dat0 rev $tctr1, $tctr1 vmov.32 ${ivec}[3],$tctr1 add $ctr, $ctr, #2 vorr $dat1,$ivec,$ivec b.ls .Lctr32_tail rev $tctr2, $ctr vmov.32 ${ivec}[3],$tctr2 sub $len,$len,#3 // bias vorr $dat2,$ivec,$ivec ___ $code.=<<___ if ($flavour =~ /64/); cmp $len,#32 b.lo .Loop3x_ctr32 add w13,$ctr,#1 add w14,$ctr,#2 vorr $dat3,$dat0,$dat0 rev w13,w13 vorr $dat4,$dat0,$dat0 rev w14,w14 vmov.32 ${dat3}[3],w13 sub $len,$len,#2 // bias vmov.32 ${dat4}[3],w14 add $ctr,$ctr,#2 b .Loop5x_ctr32 .align 4 .Loop5x_ctr32: aese $dat0,q8 aesmc $dat0,$dat0 aese $dat1,q8 aesmc $dat1,$dat1 aese $dat2,q8 aesmc $dat2,$dat2 aese $dat3,q8 aesmc $dat3,$dat3 aese $dat4,q8 aesmc $dat4,$dat4 vld1.32 {q8},[$key_],#16 subs $cnt,$cnt,#2 aese $dat0,q9 aesmc $dat0,$dat0 aese $dat1,q9 aesmc $dat1,$dat1 aese $dat2,q9 aesmc $dat2,$dat2 aese $dat3,q9 aesmc $dat3,$dat3 aese $dat4,q9 aesmc $dat4,$dat4 vld1.32 {q9},[$key_],#16 b.gt .Loop5x_ctr32 mov $key_,$key aese $dat0,q8 aesmc $dat0,$dat0 aese $dat1,q8 aesmc $dat1,$dat1 aese $dat2,q8 aesmc $dat2,$dat2 aese $dat3,q8 aesmc $dat3,$dat3 aese $dat4,q8 aesmc $dat4,$dat4 vld1.32 {q8},[$key_],#16 // re-pre-load rndkey[0] aese $dat0,q9 aesmc $dat0,$dat0 aese $dat1,q9 aesmc $dat1,$dat1 aese $dat2,q9 aesmc $dat2,$dat2 aese $dat3,q9 aesmc $dat3,$dat3 aese $dat4,q9 aesmc $dat4,$dat4 vld1.32 {q9},[$key_],#16 // re-pre-load rndkey[1] aese $dat0,q12 aesmc $dat0,$dat0 add $tctr0,$ctr,#1 add $tctr1,$ctr,#2 aese $dat1,q12 aesmc $dat1,$dat1 add $tctr2,$ctr,#3 add w13,$ctr,#4 aese $dat2,q12 aesmc $dat2,$dat2 add w14,$ctr,#5 rev $tctr0,$tctr0 aese $dat3,q12 aesmc $dat3,$dat3 rev $tctr1,$tctr1 rev $tctr2,$tctr2 aese $dat4,q12 aesmc $dat4,$dat4 rev w13,w13 rev w14,w14 aese $dat0,q13 aesmc $dat0,$dat0 aese $dat1,q13 aesmc $dat1,$dat1 aese $dat2,q13 aesmc $dat2,$dat2 aese $dat3,q13 aesmc $dat3,$dat3 aese $dat4,q13 aesmc $dat4,$dat4 aese $dat0,q14 aesmc $dat0,$dat0 vld1.8 {$in0},[$inp],#16 aese $dat1,q14 aesmc $dat1,$dat1 vld1.8 {$in1},[$inp],#16 aese $dat2,q14 aesmc $dat2,$dat2 vld1.8 {$in2},[$inp],#16 aese $dat3,q14 aesmc $dat3,$dat3 vld1.8 {$in3},[$inp],#16 aese $dat4,q14 aesmc $dat4,$dat4 vld1.8 {$in4},[$inp],#16 aese $dat0,q15 veor $in0,$in0,$rndlast aese $dat1,q15 veor $in1,$in1,$rndlast aese $dat2,q15 veor $in2,$in2,$rndlast aese $dat3,q15 veor $in3,$in3,$rndlast aese $dat4,q15 veor $in4,$in4,$rndlast veor $in0,$in0,$dat0 vorr $dat0,$ivec,$ivec veor $in1,$in1,$dat1 vorr $dat1,$ivec,$ivec veor $in2,$in2,$dat2 vorr $dat2,$ivec,$ivec veor $in3,$in3,$dat3 vorr $dat3,$ivec,$ivec veor $in4,$in4,$dat4 vorr $dat4,$ivec,$ivec vst1.8 {$in0},[$out],#16 vmov.32 ${dat0}[3],$tctr0 vst1.8 {$in1},[$out],#16 vmov.32 ${dat1}[3],$tctr1 vst1.8 {$in2},[$out],#16 vmov.32 ${dat2}[3],$tctr2 vst1.8 {$in3},[$out],#16 vmov.32 ${dat3}[3],w13 vst1.8 {$in4},[$out],#16 vmov.32 ${dat4}[3],w14 mov $cnt,$rounds cbz $len,.Lctr32_done add $ctr,$ctr,#5 subs $len,$len,#5 b.hs .Loop5x_ctr32 add $len,$len,#5 sub $ctr,$ctr,#5 cmp $len,#2 mov $step,#16 cclr $step,lo b.ls .Lctr32_tail sub $len,$len,#3 // bias add $ctr,$ctr,#3 ___ $code.=<<___; b .Loop3x_ctr32 .align 4 .Loop3x_ctr32: aese $dat0,q8 aesmc $dat0,$dat0 aese $dat1,q8 aesmc $dat1,$dat1 aese $dat2,q8 aesmc $dat2,$dat2 vld1.32 {q8},[$key_],#16 subs $cnt,$cnt,#2 aese $dat0,q9 aesmc $dat0,$dat0 aese $dat1,q9 aesmc $dat1,$dat1 aese $dat2,q9 aesmc $dat2,$dat2 vld1.32 {q9},[$key_],#16 b.gt .Loop3x_ctr32 aese $dat0,q8 aesmc $tmp0,$dat0 aese $dat1,q8 aesmc $tmp1,$dat1 vld1.8 {$in0},[$inp],#16 ___ $code.=<<___ if ($flavour =~ /64/); vorr $dat0,$ivec,$ivec ___ $code.=<<___ if ($flavour !~ /64/); add $tctr0,$ctr,#1 ___ $code.=<<___; aese $dat2,q8 aesmc $dat2,$dat2 vld1.8 {$in1},[$inp],#16 ___ $code.=<<___ if ($flavour =~ /64/); vorr $dat1,$ivec,$ivec ___ $code.=<<___ if ($flavour !~ /64/); rev $tctr0,$tctr0 ___ $code.=<<___; aese $tmp0,q9 aesmc $tmp0,$tmp0 aese $tmp1,q9 aesmc $tmp1,$tmp1 vld1.8 {$in2},[$inp],#16 mov $key_,$key aese $dat2,q9 aesmc $tmp2,$dat2 ___ $code.=<<___ if ($flavour =~ /64/); vorr $dat2,$ivec,$ivec add $tctr0,$ctr,#1 ___ $code.=<<___; aese $tmp0,q12 aesmc $tmp0,$tmp0 aese $tmp1,q12 aesmc $tmp1,$tmp1 veor $in0,$in0,$rndlast add $tctr1,$ctr,#2 aese $tmp2,q12 aesmc $tmp2,$tmp2 veor $in1,$in1,$rndlast add $ctr,$ctr,#3 aese $tmp0,q13 aesmc $tmp0,$tmp0 aese $tmp1,q13 aesmc $tmp1,$tmp1 veor $in2,$in2,$rndlast ___ $code.=<<___ if ($flavour =~ /64/); rev $tctr0,$tctr0 aese $tmp2,q13 aesmc $tmp2,$tmp2 vmov.32 ${dat0}[3], $tctr0 ___ $code.=<<___ if ($flavour !~ /64/); vmov.32 ${ivec}[3], $tctr0 aese $tmp2,q13 aesmc $tmp2,$tmp2 vorr $dat0,$ivec,$ivec ___ $code.=<<___; rev $tctr1,$tctr1 aese $tmp0,q14 aesmc $tmp0,$tmp0 ___ $code.=<<___ if ($flavour !~ /64/); vmov.32 ${ivec}[3], $tctr1 rev $tctr2,$ctr ___ $code.=<<___; aese $tmp1,q14 aesmc $tmp1,$tmp1 ___ $code.=<<___ if ($flavour =~ /64/); vmov.32 ${dat1}[3], $tctr1 rev $tctr2,$ctr aese $tmp2,q14 aesmc $tmp2,$tmp2 vmov.32 ${dat2}[3], $tctr2 ___ $code.=<<___ if ($flavour !~ /64/); vorr $dat1,$ivec,$ivec vmov.32 ${ivec}[3], $tctr2 aese $tmp2,q14 aesmc $tmp2,$tmp2 vorr $dat2,$ivec,$ivec ___ $code.=<<___; subs $len,$len,#3 aese $tmp0,q15 aese $tmp1,q15 aese $tmp2,q15 veor $in0,$in0,$tmp0 vld1.32 {q8},[$key_],#16 // re-pre-load rndkey[0] vst1.8 {$in0},[$out],#16 veor $in1,$in1,$tmp1 mov $cnt,$rounds vst1.8 {$in1},[$out],#16 veor $in2,$in2,$tmp2 vld1.32 {q9},[$key_],#16 // re-pre-load rndkey[1] vst1.8 {$in2},[$out],#16 b.hs .Loop3x_ctr32 adds $len,$len,#3 b.eq .Lctr32_done cmp $len,#1 mov $step,#16 cclr $step,eq .Lctr32_tail: aese $dat0,q8 aesmc $dat0,$dat0 aese $dat1,q8 aesmc $dat1,$dat1 vld1.32 {q8},[$key_],#16 subs $cnt,$cnt,#2 aese $dat0,q9 aesmc $dat0,$dat0 aese $dat1,q9 aesmc $dat1,$dat1 vld1.32 {q9},[$key_],#16 b.gt .Lctr32_tail aese $dat0,q8 aesmc $dat0,$dat0 aese $dat1,q8 aesmc $dat1,$dat1 aese $dat0,q9 aesmc $dat0,$dat0 aese $dat1,q9 aesmc $dat1,$dat1 vld1.8 {$in0},[$inp],$step aese $dat0,q12 aesmc $dat0,$dat0 aese $dat1,q12 aesmc $dat1,$dat1 vld1.8 {$in1},[$inp] aese $dat0,q13 aesmc $dat0,$dat0 aese $dat1,q13 aesmc $dat1,$dat1 veor $in0,$in0,$rndlast aese $dat0,q14 aesmc $dat0,$dat0 aese $dat1,q14 aesmc $dat1,$dat1 veor $in1,$in1,$rndlast aese $dat0,q15 aese $dat1,q15 cmp $len,#1 veor $in0,$in0,$dat0 veor $in1,$in1,$dat1 vst1.8 {$in0},[$out],#16 b.eq .Lctr32_done vst1.8 {$in1},[$out] .Lctr32_done: ___ $code.=<<___ if ($flavour !~ /64/); vldmia sp!,{d8-d15} ldmia sp!,{r4-r10,pc} ___ $code.=<<___ if ($flavour =~ /64/); ldr x29,[sp],#16 ret ___ $code.=<<___; .size ${prefix}_ctr32_encrypt_blocks,.-${prefix}_ctr32_encrypt_blocks ___ }}} # Performance in cycles per byte. # Processed with AES-XTS different key size. # It shows the value before and after optimization as below: # (before/after): # # AES-128-XTS AES-256-XTS # Cortex-A57 3.36/1.09 4.02/1.37 # Cortex-A72 3.03/1.02 3.28/1.33 # Optimization is implemented by loop unrolling and interleaving. # Commonly, we choose the unrolling factor as 5, if the input # data size smaller than 5 blocks, but not smaller than 3 blocks, # choose 3 as the unrolling factor. # If the input data size dsize >= 5*16 bytes, then take 5 blocks # as one iteration, every loop the left size lsize -= 5*16. # If lsize < 5*16 bytes, treat them as the tail. Note: left 4*16 bytes # will be processed specially, which be integrated into the 5*16 bytes # loop to improve the efficiency. # There is one special case, if the original input data size dsize # = 16 bytes, we will treat it seperately to improve the # performance: one independent code block without LR, FP load and # store. # Encryption will process the (length -tailcnt) bytes as mentioned # previously, then encrypt the composite block as last second # cipher block. # Decryption will process the (length -tailcnt -1) bytes as mentioned # previously, then decrypt the last second cipher block to get the # last plain block(tail), decrypt the composite block as last second # plain text block. {{{ my ($inp,$out,$len,$key1,$key2,$ivp)=map("x$_",(0..5)); my ($rounds0,$rounds,$key_,$step,$ivl,$ivh)=("w5","w6","x7","x8","x9","x10"); my ($tmpoutp,$loutp,$l2outp,$tmpinp)=("x13","w14","w15","x20"); my ($tailcnt,$midnum,$midnumx,$constnum,$constnumx)=("x21","w22","x22","w19","x19"); my ($xoffset,$tmpmx,$tmpmw)=("x6","x11","w11"); my ($dat0,$dat1,$in0,$in1,$tmp0,$tmp1,$tmp2,$rndlast)=map("q$_",(0..7)); my ($iv0,$iv1,$iv2,$iv3,$iv4)=("v6.16b","v8.16b","v9.16b","v10.16b","v11.16b"); my ($ivd00,$ivd01,$ivd20,$ivd21)=("d6","v6.d[1]","d9","v9.d[1]"); my ($ivd10,$ivd11,$ivd30,$ivd31,$ivd40,$ivd41)=("d8","v8.d[1]","d10","v10.d[1]","d11","v11.d[1]"); my ($tmpin)=("v26.16b"); my ($dat,$tmp,$rndzero_n_last)=($dat0,$tmp0,$tmp1); # q7 last round key # q10-q15, q7 Last 7 round keys # q8-q9 preloaded round keys except last 7 keys for big size # q20, q21, q8-q9 preloaded round keys except last 7 keys for only 16 byte my ($dat2,$in2,$tmp2)=map("q$_",(10,11,9)); my ($dat3,$in3,$tmp3); # used only in 64-bit mode my ($dat4,$in4,$tmp4); if ($flavour =~ /64/) { ($dat2,$dat3,$dat4,$in2,$in3,$in4,$tmp3,$tmp4)=map("q$_",(16..23)); } $code.=<<___ if ($flavour =~ /64/); .globl ${prefix}_xts_encrypt .type ${prefix}_xts_encrypt,%function .align 5 ${prefix}_xts_encrypt: ___ $code.=<<___ if ($flavour =~ /64/); cmp $len,#16 // Original input data size bigger than 16, jump to big size processing. b.ne .Lxts_enc_big_size // Encrypt the iv with key2, as the first XEX iv. ldr $rounds,[$key2,#240] vld1.32 {$dat},[$key2],#16 vld1.8 {$iv0},[$ivp] sub $rounds,$rounds,#2 vld1.32 {$dat1},[$key2],#16 .Loop_enc_iv_enc: aese $iv0,$dat aesmc $iv0,$iv0 vld1.32 {$dat},[$key2],#16 subs $rounds,$rounds,#2 aese $iv0,$dat1 aesmc $iv0,$iv0 vld1.32 {$dat1},[$key2],#16 b.gt .Loop_enc_iv_enc aese $iv0,$dat aesmc $iv0,$iv0 vld1.32 {$dat},[$key2] aese $iv0,$dat1 veor $iv0,$iv0,$dat vld1.8 {$dat0},[$inp] veor $dat0,$iv0,$dat0 ldr $rounds,[$key1,#240] vld1.32 {q20-q21},[$key1],#32 // load key schedule... aese $dat0,q20 aesmc $dat0,$dat0 vld1.32 {q8-q9},[$key1],#32 // load key schedule... aese $dat0,q21 aesmc $dat0,$dat0 subs $rounds,$rounds,#10 // if rounds==10, jump to aes-128-xts processing b.eq .Lxts_128_enc .Lxts_enc_round_loop: aese $dat0,q8 aesmc $dat0,$dat0 vld1.32 {q8},[$key1],#16 // load key schedule... aese $dat0,q9 aesmc $dat0,$dat0 vld1.32 {q9},[$key1],#16 // load key schedule... subs $rounds,$rounds,#2 // bias b.gt .Lxts_enc_round_loop .Lxts_128_enc: vld1.32 {q10-q11},[$key1],#32 // load key schedule... aese $dat0,q8 aesmc $dat0,$dat0 aese $dat0,q9 aesmc $dat0,$dat0 vld1.32 {q12-q13},[$key1],#32 // load key schedule... aese $dat0,q10 aesmc $dat0,$dat0 aese $dat0,q11 aesmc $dat0,$dat0 vld1.32 {q14-q15},[$key1],#32 // load key schedule... aese $dat0,q12 aesmc $dat0,$dat0 aese $dat0,q13 aesmc $dat0,$dat0 vld1.32 {$rndlast},[$key1] aese $dat0,q14 aesmc $dat0,$dat0 aese $dat0,q15 veor $dat0,$dat0,$rndlast veor $dat0,$dat0,$iv0 vst1.8 {$dat0},[$out] b .Lxts_enc_final_abort .align 4 .Lxts_enc_big_size: ___ $code.=<<___ if ($flavour =~ /64/); stp $constnumx,$tmpinp,[sp,#-64]! stp $tailcnt,$midnumx,[sp,#48] stp $ivd10,$ivd20,[sp,#32] stp $ivd30,$ivd40,[sp,#16] // tailcnt store the tail value of length%16. and $tailcnt,$len,#0xf and $len,$len,#-16 subs $len,$len,#16 mov $step,#16 b.lo .Lxts_abort csel $step,xzr,$step,eq // Firstly, encrypt the iv with key2, as the first iv of XEX. ldr $rounds,[$key2,#240] vld1.32 {$dat},[$key2],#16 vld1.8 {$iv0},[$ivp] sub $rounds,$rounds,#2 vld1.32 {$dat1},[$key2],#16 .Loop_iv_enc: aese $iv0,$dat aesmc $iv0,$iv0 vld1.32 {$dat},[$key2],#16 subs $rounds,$rounds,#2 aese $iv0,$dat1 aesmc $iv0,$iv0 vld1.32 {$dat1},[$key2],#16 b.gt .Loop_iv_enc aese $iv0,$dat aesmc $iv0,$iv0 vld1.32 {$dat},[$key2] aese $iv0,$dat1 veor $iv0,$iv0,$dat // The iv for second block // $ivl- iv(low), $ivh - iv(high) // the five ivs stored into, $iv0,$iv1,$iv2,$iv3,$iv4 fmov $ivl,$ivd00 fmov $ivh,$ivd01 mov $constnum,#0x87 extr $midnumx,$ivh,$ivh,#32 extr $ivh,$ivh,$ivl,#63 and $tmpmw,$constnum,$midnum,asr#31 eor $ivl,$tmpmx,$ivl,lsl#1 fmov $ivd10,$ivl fmov $ivd11,$ivh ldr $rounds0,[$key1,#240] // next starting point vld1.8 {$dat},[$inp],$step vld1.32 {q8-q9},[$key1] // load key schedule... sub $rounds0,$rounds0,#6 add $key_,$key1,$ivp,lsl#4 // pointer to last 7 round keys sub $rounds0,$rounds0,#2 vld1.32 {q10-q11},[$key_],#32 vld1.32 {q12-q13},[$key_],#32 vld1.32 {q14-q15},[$key_],#32 vld1.32 {$rndlast},[$key_] add $key_,$key1,#32 mov $rounds,$rounds0 // Encryption .Lxts_enc: vld1.8 {$dat2},[$inp],#16 subs $len,$len,#32 // bias add $rounds,$rounds0,#2 vorr $in1,$dat,$dat vorr $dat1,$dat,$dat vorr $in3,$dat,$dat vorr $in2,$dat2,$dat2 vorr $in4,$dat2,$dat2 b.lo .Lxts_inner_enc_tail veor $dat,$dat,$iv0 // before encryption, xor with iv veor $dat2,$dat2,$iv1 // The iv for third block extr $midnumx,$ivh,$ivh,#32 extr $ivh,$ivh,$ivl,#63 and $tmpmw,$constnum,$midnum,asr#31 eor $ivl,$tmpmx,$ivl,lsl#1 fmov $ivd20,$ivl fmov $ivd21,$ivh vorr $dat1,$dat2,$dat2 vld1.8 {$dat2},[$inp],#16 vorr $in0,$dat,$dat vorr $in1,$dat1,$dat1 veor $in2,$dat2,$iv2 // the third block veor $dat2,$dat2,$iv2 cmp $len,#32 b.lo .Lxts_outer_enc_tail // The iv for fourth block extr $midnumx,$ivh,$ivh,#32 extr $ivh,$ivh,$ivl,#63 and $tmpmw,$constnum,$midnum,asr#31 eor $ivl,$tmpmx,$ivl,lsl#1 fmov $ivd30,$ivl fmov $ivd31,$ivh vld1.8 {$dat3},[$inp],#16 // The iv for fifth block extr $midnumx,$ivh,$ivh,#32 extr $ivh,$ivh,$ivl,#63 and $tmpmw,$constnum,$midnum,asr#31 eor $ivl,$tmpmx,$ivl,lsl#1 fmov $ivd40,$ivl fmov $ivd41,$ivh vld1.8 {$dat4},[$inp],#16 veor $dat3,$dat3,$iv3 // the fourth block veor $dat4,$dat4,$iv4 sub $len,$len,#32 // bias mov $rounds,$rounds0 b .Loop5x_xts_enc .align 4 .Loop5x_xts_enc: aese $dat0,q8 aesmc $dat0,$dat0 aese $dat1,q8 aesmc $dat1,$dat1 aese $dat2,q8 aesmc $dat2,$dat2 aese $dat3,q8 aesmc $dat3,$dat3 aese $dat4,q8 aesmc $dat4,$dat4 vld1.32 {q8},[$key_],#16 subs $rounds,$rounds,#2 aese $dat0,q9 aesmc $dat0,$dat0 aese $dat1,q9 aesmc $dat1,$dat1 aese $dat2,q9 aesmc $dat2,$dat2 aese $dat3,q9 aesmc $dat3,$dat3 aese $dat4,q9 aesmc $dat4,$dat4 vld1.32 {q9},[$key_],#16 b.gt .Loop5x_xts_enc aese $dat0,q8 aesmc $dat0,$dat0 aese $dat1,q8 aesmc $dat1,$dat1 aese $dat2,q8 aesmc $dat2,$dat2 aese $dat3,q8 aesmc $dat3,$dat3 aese $dat4,q8 aesmc $dat4,$dat4 subs $len,$len,#0x50 // because .Lxts_enc_tail4x aese $dat0,q9 aesmc $dat0,$dat0 aese $dat1,q9 aesmc $dat1,$dat1 aese $dat2,q9 aesmc $dat2,$dat2 aese $dat3,q9 aesmc $dat3,$dat3 aese $dat4,q9 aesmc $dat4,$dat4 csel $xoffset,xzr,$len,gt // borrow x6, w6, "gt" is not typo mov $key_,$key1 aese $dat0,q10 aesmc $dat0,$dat0 aese $dat1,q10 aesmc $dat1,$dat1 aese $dat2,q10 aesmc $dat2,$dat2 aese $dat3,q10 aesmc $dat3,$dat3 aese $dat4,q10 aesmc $dat4,$dat4 add $inp,$inp,$xoffset // x0 is adjusted in such way that // at exit from the loop v1.16b-v26.16b // are loaded with last "words" add $xoffset,$len,#0x60 // because .Lxts_enc_tail4x aese $dat0,q11 aesmc $dat0,$dat0 aese $dat1,q11 aesmc $dat1,$dat1 aese $dat2,q11 aesmc $dat2,$dat2 aese $dat3,q11 aesmc $dat3,$dat3 aese $dat4,q11 aesmc $dat4,$dat4 aese $dat0,q12 aesmc $dat0,$dat0 aese $dat1,q12 aesmc $dat1,$dat1 aese $dat2,q12 aesmc $dat2,$dat2 aese $dat3,q12 aesmc $dat3,$dat3 aese $dat4,q12 aesmc $dat4,$dat4 aese $dat0,q13 aesmc $dat0,$dat0 aese $dat1,q13 aesmc $dat1,$dat1 aese $dat2,q13 aesmc $dat2,$dat2 aese $dat3,q13 aesmc $dat3,$dat3 aese $dat4,q13 aesmc $dat4,$dat4 aese $dat0,q14 aesmc $dat0,$dat0 aese $dat1,q14 aesmc $dat1,$dat1 aese $dat2,q14 aesmc $dat2,$dat2 aese $dat3,q14 aesmc $dat3,$dat3 aese $dat4,q14 aesmc $dat4,$dat4 veor $tmp0,$rndlast,$iv0 aese $dat0,q15 // The iv for first block of one iteration extr $midnumx,$ivh,$ivh,#32 extr $ivh,$ivh,$ivl,#63 and $tmpmw,$constnum,$midnum,asr#31 eor $ivl,$tmpmx,$ivl,lsl#1 fmov $ivd00,$ivl fmov $ivd01,$ivh veor $tmp1,$rndlast,$iv1 vld1.8 {$in0},[$inp],#16 aese $dat1,q15 // The iv for second block extr $midnumx,$ivh,$ivh,#32 extr $ivh,$ivh,$ivl,#63 and $tmpmw,$constnum,$midnum,asr#31 eor $ivl,$tmpmx,$ivl,lsl#1 fmov $ivd10,$ivl fmov $ivd11,$ivh veor $tmp2,$rndlast,$iv2 vld1.8 {$in1},[$inp],#16 aese $dat2,q15 // The iv for third block extr $midnumx,$ivh,$ivh,#32 extr $ivh,$ivh,$ivl,#63 and $tmpmw,$constnum,$midnum,asr#31 eor $ivl,$tmpmx,$ivl,lsl#1 fmov $ivd20,$ivl fmov $ivd21,$ivh veor $tmp3,$rndlast,$iv3 vld1.8 {$in2},[$inp],#16 aese $dat3,q15 // The iv for fourth block extr $midnumx,$ivh,$ivh,#32 extr $ivh,$ivh,$ivl,#63 and $tmpmw,$constnum,$midnum,asr#31 eor $ivl,$tmpmx,$ivl,lsl#1 fmov $ivd30,$ivl fmov $ivd31,$ivh veor $tmp4,$rndlast,$iv4 vld1.8 {$in3},[$inp],#16 aese $dat4,q15 // The iv for fifth block extr $midnumx,$ivh,$ivh,#32 extr $ivh,$ivh,$ivl,#63 and $tmpmw,$constnum,$midnum,asr #31 eor $ivl,$tmpmx,$ivl,lsl #1 fmov $ivd40,$ivl fmov $ivd41,$ivh vld1.8 {$in4},[$inp],#16 cbz $xoffset,.Lxts_enc_tail4x vld1.32 {q8},[$key_],#16 // re-pre-load rndkey[0] veor $tmp0,$tmp0,$dat0 veor $dat0,$in0,$iv0 veor $tmp1,$tmp1,$dat1 veor $dat1,$in1,$iv1 veor $tmp2,$tmp2,$dat2 veor $dat2,$in2,$iv2 veor $tmp3,$tmp3,$dat3 veor $dat3,$in3,$iv3 veor $tmp4,$tmp4,$dat4 vst1.8 {$tmp0},[$out],#16 veor $dat4,$in4,$iv4 vst1.8 {$tmp1},[$out],#16 mov $rounds,$rounds0 vst1.8 {$tmp2},[$out],#16 vld1.32 {q9},[$key_],#16 // re-pre-load rndkey[1] vst1.8 {$tmp3},[$out],#16 vst1.8 {$tmp4},[$out],#16 b.hs .Loop5x_xts_enc // If left 4 blocks, borrow the five block's processing. cmn $len,#0x10 b.ne .Loop5x_enc_after vorr $iv4,$iv3,$iv3 vorr $iv3,$iv2,$iv2 vorr $iv2,$iv1,$iv1 vorr $iv1,$iv0,$iv0 fmov $ivl,$ivd40 fmov $ivh,$ivd41 veor $dat0,$iv0,$in0 veor $dat1,$iv1,$in1 veor $dat2,$in2,$iv2 veor $dat3,$in3,$iv3 veor $dat4,$in4,$iv4 b.eq .Loop5x_xts_enc .Loop5x_enc_after: add $len,$len,#0x50 cbz $len,.Lxts_enc_done add $rounds,$rounds0,#2 subs $len,$len,#0x30 b.lo .Lxts_inner_enc_tail veor $dat0,$iv0,$in2 veor $dat1,$iv1,$in3 veor $dat2,$in4,$iv2 b .Lxts_outer_enc_tail .align 4 .Lxts_enc_tail4x: add $inp,$inp,#16 veor $tmp1,$dat1,$tmp1 vst1.8 {$tmp1},[$out],#16 veor $tmp2,$dat2,$tmp2 vst1.8 {$tmp2},[$out],#16 veor $tmp3,$dat3,$tmp3 veor $tmp4,$dat4,$tmp4 vst1.8 {$tmp3-$tmp4},[$out],#32 b .Lxts_enc_done .align 4 .Lxts_outer_enc_tail: aese $dat0,q8 aesmc $dat0,$dat0 aese $dat1,q8 aesmc $dat1,$dat1 aese $dat2,q8 aesmc $dat2,$dat2 vld1.32 {q8},[$key_],#16 subs $rounds,$rounds,#2 aese $dat0,q9 aesmc $dat0,$dat0 aese $dat1,q9 aesmc $dat1,$dat1 aese $dat2,q9 aesmc $dat2,$dat2 vld1.32 {q9},[$key_],#16 b.gt .Lxts_outer_enc_tail aese $dat0,q8 aesmc $dat0,$dat0 aese $dat1,q8 aesmc $dat1,$dat1 aese $dat2,q8 aesmc $dat2,$dat2 veor $tmp0,$iv0,$rndlast subs $len,$len,#0x30 // The iv for first block fmov $ivl,$ivd20 fmov $ivh,$ivd21 //mov $constnum,#0x87 extr $midnumx,$ivh,$ivh,#32 extr $ivh,$ivh,$ivl,#63 and $tmpmw,$constnum,$midnum,asr#31 eor $ivl,$tmpmx,$ivl,lsl#1 fmov $ivd00,$ivl fmov $ivd01,$ivh veor $tmp1,$iv1,$rndlast csel $xoffset,$len,$xoffset,lo // x6, w6, is zero at this point aese $dat0,q9 aesmc $dat0,$dat0 aese $dat1,q9 aesmc $dat1,$dat1 aese $dat2,q9 aesmc $dat2,$dat2 veor $tmp2,$iv2,$rndlast add $xoffset,$xoffset,#0x20 add $inp,$inp,$xoffset mov $key_,$key1 aese $dat0,q12 aesmc $dat0,$dat0 aese $dat1,q12 aesmc $dat1,$dat1 aese $dat2,q12 aesmc $dat2,$dat2 aese $dat0,q13 aesmc $dat0,$dat0 aese $dat1,q13 aesmc $dat1,$dat1 aese $dat2,q13 aesmc $dat2,$dat2 aese $dat0,q14 aesmc $dat0,$dat0 aese $dat1,q14 aesmc $dat1,$dat1 aese $dat2,q14 aesmc $dat2,$dat2 aese $dat0,q15 aese $dat1,q15 aese $dat2,q15 vld1.8 {$in2},[$inp],#16 add $rounds,$rounds0,#2 vld1.32 {q8},[$key_],#16 // re-pre-load rndkey[0] veor $tmp0,$tmp0,$dat0 veor $tmp1,$tmp1,$dat1 veor $dat2,$dat2,$tmp2 vld1.32 {q9},[$key_],#16 // re-pre-load rndkey[1] vst1.8 {$tmp0},[$out],#16 vst1.8 {$tmp1},[$out],#16 vst1.8 {$dat2},[$out],#16 cmn $len,#0x30 b.eq .Lxts_enc_done .Lxts_encxor_one: vorr $in3,$in1,$in1 vorr $in4,$in2,$in2 nop .Lxts_inner_enc_tail: cmn $len,#0x10 veor $dat1,$in3,$iv0 veor $dat2,$in4,$iv1 b.eq .Lxts_enc_tail_loop veor $dat2,$in4,$iv0 .Lxts_enc_tail_loop: aese $dat1,q8 aesmc $dat1,$dat1 aese $dat2,q8 aesmc $dat2,$dat2 vld1.32 {q8},[$key_],#16 subs $rounds,$rounds,#2 aese $dat1,q9 aesmc $dat1,$dat1 aese $dat2,q9 aesmc $dat2,$dat2 vld1.32 {q9},[$key_],#16 b.gt .Lxts_enc_tail_loop aese $dat1,q8 aesmc $dat1,$dat1 aese $dat2,q8 aesmc $dat2,$dat2 aese $dat1,q9 aesmc $dat1,$dat1 aese $dat2,q9 aesmc $dat2,$dat2 aese $dat1,q12 aesmc $dat1,$dat1 aese $dat2,q12 aesmc $dat2,$dat2 cmn $len,#0x20 aese $dat1,q13 aesmc $dat1,$dat1 aese $dat2,q13 aesmc $dat2,$dat2 veor $tmp1,$iv0,$rndlast aese $dat1,q14 aesmc $dat1,$dat1 aese $dat2,q14 aesmc $dat2,$dat2 veor $tmp2,$iv1,$rndlast aese $dat1,q15 aese $dat2,q15 b.eq .Lxts_enc_one veor $tmp1,$tmp1,$dat1 vst1.8 {$tmp1},[$out],#16 veor $tmp2,$tmp2,$dat2 vorr $iv0,$iv1,$iv1 vst1.8 {$tmp2},[$out],#16 fmov $ivl,$ivd10 fmov $ivh,$ivd11 mov $constnum,#0x87 extr $midnumx,$ivh,$ivh,#32 extr $ivh,$ivh,$ivl,#63 and $tmpmw,$constnum,$midnum,asr #31 eor $ivl,$tmpmx,$ivl,lsl #1 fmov $ivd00,$ivl fmov $ivd01,$ivh b .Lxts_enc_done .Lxts_enc_one: veor $tmp1,$tmp1,$dat2 vorr $iv0,$iv0,$iv0 vst1.8 {$tmp1},[$out],#16 fmov $ivl,$ivd00 fmov $ivh,$ivd01 mov $constnum,#0x87 extr $midnumx,$ivh,$ivh,#32 extr $ivh,$ivh,$ivl,#63 and $tmpmw,$constnum,$midnum,asr #31 eor $ivl,$tmpmx,$ivl,lsl #1 fmov $ivd00,$ivl fmov $ivd01,$ivh b .Lxts_enc_done .align 5 .Lxts_enc_done: // Process the tail block with cipher stealing. tst $tailcnt,#0xf b.eq .Lxts_abort mov $tmpinp,$inp mov $tmpoutp,$out sub $out,$out,#16 .composite_enc_loop: subs $tailcnt,$tailcnt,#1 ldrb $l2outp,[$out,$tailcnt] ldrb $loutp,[$tmpinp,$tailcnt] strb $l2outp,[$tmpoutp,$tailcnt] strb $loutp,[$out,$tailcnt] b.gt .composite_enc_loop .Lxts_enc_load_done: vld1.8 {$tmpin},[$out] veor $tmpin,$tmpin,$iv0 // Encrypt the composite block to get the last second encrypted text block ldr $rounds,[$key1,#240] // load key schedule... vld1.32 {$dat},[$key1],#16 sub $rounds,$rounds,#2 vld1.32 {$dat1},[$key1],#16 // load key schedule... .Loop_final_enc: aese $tmpin,$dat0 aesmc $tmpin,$tmpin vld1.32 {$dat0},[$key1],#16 subs $rounds,$rounds,#2 aese $tmpin,$dat1 aesmc $tmpin,$tmpin vld1.32 {$dat1},[$key1],#16 b.gt .Loop_final_enc aese $tmpin,$dat0 aesmc $tmpin,$tmpin vld1.32 {$dat0},[$key1] aese $tmpin,$dat1 veor $tmpin,$tmpin,$dat0 veor $tmpin,$tmpin,$iv0 vst1.8 {$tmpin},[$out] .Lxts_abort: ldp $tailcnt,$midnumx,[sp,#48] ldp $ivd10,$ivd20,[sp,#32] ldp $ivd30,$ivd40,[sp,#16] ldp $constnumx,$tmpinp,[sp],#64 .Lxts_enc_final_abort: ret .size ${prefix}_xts_encrypt,.-${prefix}_xts_encrypt ___ }}} {{{ my ($inp,$out,$len,$key1,$key2,$ivp)=map("x$_",(0..5)); my ($rounds0,$rounds,$key_,$step,$ivl,$ivh)=("w5","w6","x7","x8","x9","x10"); my ($tmpoutp,$loutp,$l2outp,$tmpinp)=("x13","w14","w15","x20"); my ($tailcnt,$midnum,$midnumx,$constnum,$constnumx)=("x21","w22","x22","w19","x19"); my ($xoffset,$tmpmx,$tmpmw)=("x6","x11","w11"); my ($dat0,$dat1,$in0,$in1,$tmp0,$tmp1,$tmp2,$rndlast)=map("q$_",(0..7)); my ($iv0,$iv1,$iv2,$iv3,$iv4,$tmpin)=("v6.16b","v8.16b","v9.16b","v10.16b","v11.16b","v26.16b"); my ($ivd00,$ivd01,$ivd20,$ivd21)=("d6","v6.d[1]","d9","v9.d[1]"); my ($ivd10,$ivd11,$ivd30,$ivd31,$ivd40,$ivd41)=("d8","v8.d[1]","d10","v10.d[1]","d11","v11.d[1]"); my ($dat,$tmp,$rndzero_n_last)=($dat0,$tmp0,$tmp1); # q7 last round key # q10-q15, q7 Last 7 round keys # q8-q9 preloaded round keys except last 7 keys for big size # q20, q21, q8-q9 preloaded round keys except last 7 keys for only 16 byte { my ($dat2,$in2,$tmp2)=map("q$_",(10,11,9)); my ($dat3,$in3,$tmp3); # used only in 64-bit mode my ($dat4,$in4,$tmp4); if ($flavour =~ /64/) { ($dat2,$dat3,$dat4,$in2,$in3,$in4,$tmp3,$tmp4)=map("q$_",(16..23)); } $code.=<<___ if ($flavour =~ /64/); .globl ${prefix}_xts_decrypt .type ${prefix}_xts_decrypt,%function .align 5 ${prefix}_xts_decrypt: ___ $code.=<<___ if ($flavour =~ /64/); cmp $len,#16 // Original input data size bigger than 16, jump to big size processing. b.ne .Lxts_dec_big_size // Encrypt the iv with key2, as the first XEX iv. ldr $rounds,[$key2,#240] vld1.32 {$dat},[$key2],#16 vld1.8 {$iv0},[$ivp] sub $rounds,$rounds,#2 vld1.32 {$dat1},[$key2],#16 .Loop_dec_small_iv_enc: aese $iv0,$dat aesmc $iv0,$iv0 vld1.32 {$dat},[$key2],#16 subs $rounds,$rounds,#2 aese $iv0,$dat1 aesmc $iv0,$iv0 vld1.32 {$dat1},[$key2],#16 b.gt .Loop_dec_small_iv_enc aese $iv0,$dat aesmc $iv0,$iv0 vld1.32 {$dat},[$key2] aese $iv0,$dat1 veor $iv0,$iv0,$dat vld1.8 {$dat0},[$inp] veor $dat0,$iv0,$dat0 ldr $rounds,[$key1,#240] vld1.32 {q20-q21},[$key1],#32 // load key schedule... aesd $dat0,q20 aesimc $dat0,$dat0 vld1.32 {q8-q9},[$key1],#32 // load key schedule... aesd $dat0,q21 aesimc $dat0,$dat0 subs $rounds,$rounds,#10 // bias b.eq .Lxts_128_dec .Lxts_dec_round_loop: aesd $dat0,q8 aesimc $dat0,$dat0 vld1.32 {q8},[$key1],#16 // load key schedule... aesd $dat0,q9 aesimc $dat0,$dat0 vld1.32 {q9},[$key1],#16 // load key schedule... subs $rounds,$rounds,#2 // bias b.gt .Lxts_dec_round_loop .Lxts_128_dec: vld1.32 {q10-q11},[$key1],#32 // load key schedule... aesd $dat0,q8 aesimc $dat0,$dat0 aesd $dat0,q9 aesimc $dat0,$dat0 vld1.32 {q12-q13},[$key1],#32 // load key schedule... aesd $dat0,q10 aesimc $dat0,$dat0 aesd $dat0,q11 aesimc $dat0,$dat0 vld1.32 {q14-q15},[$key1],#32 // load key schedule... aesd $dat0,q12 aesimc $dat0,$dat0 aesd $dat0,q13 aesimc $dat0,$dat0 vld1.32 {$rndlast},[$key1] aesd $dat0,q14 aesimc $dat0,$dat0 aesd $dat0,q15 veor $dat0,$dat0,$rndlast veor $dat0,$iv0,$dat0 vst1.8 {$dat0},[$out] b .Lxts_dec_final_abort .Lxts_dec_big_size: ___ $code.=<<___ if ($flavour =~ /64/); stp $constnumx,$tmpinp,[sp,#-64]! stp $tailcnt,$midnumx,[sp,#48] stp $ivd10,$ivd20,[sp,#32] stp $ivd30,$ivd40,[sp,#16] and $tailcnt,$len,#0xf and $len,$len,#-16 subs $len,$len,#16 mov $step,#16 b.lo .Lxts_dec_abort // Encrypt the iv with key2, as the first XEX iv ldr $rounds,[$key2,#240] vld1.32 {$dat},[$key2],#16 vld1.8 {$iv0},[$ivp] sub $rounds,$rounds,#2 vld1.32 {$dat1},[$key2],#16 .Loop_dec_iv_enc: aese $iv0,$dat aesmc $iv0,$iv0 vld1.32 {$dat},[$key2],#16 subs $rounds,$rounds,#2 aese $iv0,$dat1 aesmc $iv0,$iv0 vld1.32 {$dat1},[$key2],#16 b.gt .Loop_dec_iv_enc aese $iv0,$dat aesmc $iv0,$iv0 vld1.32 {$dat},[$key2] aese $iv0,$dat1 veor $iv0,$iv0,$dat // The iv for second block // $ivl- iv(low), $ivh - iv(high) // the five ivs stored into, $iv0,$iv1,$iv2,$iv3,$iv4 fmov $ivl,$ivd00 fmov $ivh,$ivd01 mov $constnum,#0x87 extr $midnumx,$ivh,$ivh,#32 extr $ivh,$ivh,$ivl,#63 and $tmpmw,$constnum,$midnum,asr #31 eor $ivl,$tmpmx,$ivl,lsl #1 fmov $ivd10,$ivl fmov $ivd11,$ivh ldr $rounds0,[$key1,#240] // load rounds number // The iv for third block extr $midnumx,$ivh,$ivh,#32 extr $ivh,$ivh,$ivl,#63 and $tmpmw,$constnum,$midnum,asr #31 eor $ivl,$tmpmx,$ivl,lsl #1 fmov $ivd20,$ivl fmov $ivd21,$ivh vld1.32 {q8-q9},[$key1] // load key schedule... sub $rounds0,$rounds0,#6 add $key_,$key1,$ivp,lsl#4 // pointer to last 7 round keys sub $rounds0,$rounds0,#2 vld1.32 {q10-q11},[$key_],#32 // load key schedule... vld1.32 {q12-q13},[$key_],#32 vld1.32 {q14-q15},[$key_],#32 vld1.32 {$rndlast},[$key_] // The iv for fourth block extr $midnumx,$ivh,$ivh,#32 extr $ivh,$ivh,$ivl,#63 and $tmpmw,$constnum,$midnum,asr #31 eor $ivl,$tmpmx,$ivl,lsl #1 fmov $ivd30,$ivl fmov $ivd31,$ivh add $key_,$key1,#32 mov $rounds,$rounds0 b .Lxts_dec // Decryption .align 5 .Lxts_dec: tst $tailcnt,#0xf b.eq .Lxts_dec_begin subs $len,$len,#16 csel $step,xzr,$step,eq vld1.8 {$dat},[$inp],#16 b.lo .Lxts_done sub $inp,$inp,#16 .Lxts_dec_begin: vld1.8 {$dat},[$inp],$step subs $len,$len,#32 // bias add $rounds,$rounds0,#2 vorr $in1,$dat,$dat vorr $dat1,$dat,$dat vorr $in3,$dat,$dat vld1.8 {$dat2},[$inp],#16 vorr $in2,$dat2,$dat2 vorr $in4,$dat2,$dat2 b.lo .Lxts_inner_dec_tail veor $dat,$dat,$iv0 // before decryt, xor with iv veor $dat2,$dat2,$iv1 vorr $dat1,$dat2,$dat2 vld1.8 {$dat2},[$inp],#16 vorr $in0,$dat,$dat vorr $in1,$dat1,$dat1 veor $in2,$dat2,$iv2 // third block xox with third iv veor $dat2,$dat2,$iv2 cmp $len,#32 b.lo .Lxts_outer_dec_tail vld1.8 {$dat3},[$inp],#16 // The iv for fifth block extr $midnumx,$ivh,$ivh,#32 extr $ivh,$ivh,$ivl,#63 and $tmpmw,$constnum,$midnum,asr #31 eor $ivl,$tmpmx,$ivl,lsl #1 fmov $ivd40,$ivl fmov $ivd41,$ivh vld1.8 {$dat4},[$inp],#16 veor $dat3,$dat3,$iv3 // the fourth block veor $dat4,$dat4,$iv4 sub $len,$len,#32 // bias mov $rounds,$rounds0 b .Loop5x_xts_dec .align 4 .Loop5x_xts_dec: aesd $dat0,q8 aesimc $dat0,$dat0 aesd $dat1,q8 aesimc $dat1,$dat1 aesd $dat2,q8 aesimc $dat2,$dat2 aesd $dat3,q8 aesimc $dat3,$dat3 aesd $dat4,q8 aesimc $dat4,$dat4 vld1.32 {q8},[$key_],#16 // load key schedule... subs $rounds,$rounds,#2 aesd $dat0,q9 aesimc $dat0,$dat0 aesd $dat1,q9 aesimc $dat1,$dat1 aesd $dat2,q9 aesimc $dat2,$dat2 aesd $dat3,q9 aesimc $dat3,$dat3 aesd $dat4,q9 aesimc $dat4,$dat4 vld1.32 {q9},[$key_],#16 // load key schedule... b.gt .Loop5x_xts_dec aesd $dat0,q8 aesimc $dat0,$dat0 aesd $dat1,q8 aesimc $dat1,$dat1 aesd $dat2,q8 aesimc $dat2,$dat2 aesd $dat3,q8 aesimc $dat3,$dat3 aesd $dat4,q8 aesimc $dat4,$dat4 subs $len,$len,#0x50 // because .Lxts_dec_tail4x aesd $dat0,q9 aesimc $dat0,$dat aesd $dat1,q9 aesimc $dat1,$dat1 aesd $dat2,q9 aesimc $dat2,$dat2 aesd $dat3,q9 aesimc $dat3,$dat3 aesd $dat4,q9 aesimc $dat4,$dat4 csel $xoffset,xzr,$len,gt // borrow x6, w6, "gt" is not typo mov $key_,$key1 aesd $dat0,q10 aesimc $dat0,$dat0 aesd $dat1,q10 aesimc $dat1,$dat1 aesd $dat2,q10 aesimc $dat2,$dat2 aesd $dat3,q10 aesimc $dat3,$dat3 aesd $dat4,q10 aesimc $dat4,$dat4 add $inp,$inp,$xoffset // x0 is adjusted in such way that // at exit from the loop v1.16b-v26.16b // are loaded with last "words" add $xoffset,$len,#0x60 // because .Lxts_dec_tail4x aesd $dat0,q11 aesimc $dat0,$dat0 aesd $dat1,q11 aesimc $dat1,$dat1 aesd $dat2,q11 aesimc $dat2,$dat2 aesd $dat3,q11 aesimc $dat3,$dat3 aesd $dat4,q11 aesimc $dat4,$dat4 aesd $dat0,q12 aesimc $dat0,$dat0 aesd $dat1,q12 aesimc $dat1,$dat1 aesd $dat2,q12 aesimc $dat2,$dat2 aesd $dat3,q12 aesimc $dat3,$dat3 aesd $dat4,q12 aesimc $dat4,$dat4 aesd $dat0,q13 aesimc $dat0,$dat0 aesd $dat1,q13 aesimc $dat1,$dat1 aesd $dat2,q13 aesimc $dat2,$dat2 aesd $dat3,q13 aesimc $dat3,$dat3 aesd $dat4,q13 aesimc $dat4,$dat4 aesd $dat0,q14 aesimc $dat0,$dat0 aesd $dat1,q14 aesimc $dat1,$dat1 aesd $dat2,q14 aesimc $dat2,$dat2 aesd $dat3,q14 aesimc $dat3,$dat3 aesd $dat4,q14 aesimc $dat4,$dat4 veor $tmp0,$rndlast,$iv0 aesd $dat0,q15 // The iv for first block of next iteration. extr $midnumx,$ivh,$ivh,#32 extr $ivh,$ivh,$ivl,#63 and $tmpmw,$constnum,$midnum,asr #31 eor $ivl,$tmpmx,$ivl,lsl #1 fmov $ivd00,$ivl fmov $ivd01,$ivh veor $tmp1,$rndlast,$iv1 vld1.8 {$in0},[$inp],#16 aesd $dat1,q15 // The iv for second block extr $midnumx,$ivh,$ivh,#32 extr $ivh,$ivh,$ivl,#63 and $tmpmw,$constnum,$midnum,asr #31 eor $ivl,$tmpmx,$ivl,lsl #1 fmov $ivd10,$ivl fmov $ivd11,$ivh veor $tmp2,$rndlast,$iv2 vld1.8 {$in1},[$inp],#16 aesd $dat2,q15 // The iv for third block extr $midnumx,$ivh,$ivh,#32 extr $ivh,$ivh,$ivl,#63 and $tmpmw,$constnum,$midnum,asr #31 eor $ivl,$tmpmx,$ivl,lsl #1 fmov $ivd20,$ivl fmov $ivd21,$ivh veor $tmp3,$rndlast,$iv3 vld1.8 {$in2},[$inp],#16 aesd $dat3,q15 // The iv for fourth block extr $midnumx,$ivh,$ivh,#32 extr $ivh,$ivh,$ivl,#63 and $tmpmw,$constnum,$midnum,asr #31 eor $ivl,$tmpmx,$ivl,lsl #1 fmov $ivd30,$ivl fmov $ivd31,$ivh veor $tmp4,$rndlast,$iv4 vld1.8 {$in3},[$inp],#16 aesd $dat4,q15 // The iv for fifth block extr $midnumx,$ivh,$ivh,#32 extr $ivh,$ivh,$ivl,#63 and $tmpmw,$constnum,$midnum,asr #31 eor $ivl,$tmpmx,$ivl,lsl #1 fmov $ivd40,$ivl fmov $ivd41,$ivh vld1.8 {$in4},[$inp],#16 cbz $xoffset,.Lxts_dec_tail4x vld1.32 {q8},[$key_],#16 // re-pre-load rndkey[0] veor $tmp0,$tmp0,$dat0 veor $dat0,$in0,$iv0 veor $tmp1,$tmp1,$dat1 veor $dat1,$in1,$iv1 veor $tmp2,$tmp2,$dat2 veor $dat2,$in2,$iv2 veor $tmp3,$tmp3,$dat3 veor $dat3,$in3,$iv3 veor $tmp4,$tmp4,$dat4 vst1.8 {$tmp0},[$out],#16 veor $dat4,$in4,$iv4 vst1.8 {$tmp1},[$out],#16 mov $rounds,$rounds0 vst1.8 {$tmp2},[$out],#16 vld1.32 {q9},[$key_],#16 // re-pre-load rndkey[1] vst1.8 {$tmp3},[$out],#16 vst1.8 {$tmp4},[$out],#16 b.hs .Loop5x_xts_dec cmn $len,#0x10 b.ne .Loop5x_dec_after // If x2($len) equal to -0x10, the left blocks is 4. // After specially processing, utilize the five blocks processing again. // It will use the following IVs: $iv0,$iv0,$iv1,$iv2,$iv3. vorr $iv4,$iv3,$iv3 vorr $iv3,$iv2,$iv2 vorr $iv2,$iv1,$iv1 vorr $iv1,$iv0,$iv0 fmov $ivl,$ivd40 fmov $ivh,$ivd41 veor $dat0,$iv0,$in0 veor $dat1,$iv1,$in1 veor $dat2,$in2,$iv2 veor $dat3,$in3,$iv3 veor $dat4,$in4,$iv4 b.eq .Loop5x_xts_dec .Loop5x_dec_after: add $len,$len,#0x50 cbz $len,.Lxts_done add $rounds,$rounds0,#2 subs $len,$len,#0x30 b.lo .Lxts_inner_dec_tail veor $dat0,$iv0,$in2 veor $dat1,$iv1,$in3 veor $dat2,$in4,$iv2 b .Lxts_outer_dec_tail .align 4 .Lxts_dec_tail4x: add $inp,$inp,#16 tst $tailcnt,#0xf veor $tmp1,$dat1,$tmp0 vst1.8 {$tmp1},[$out],#16 veor $tmp2,$dat2,$tmp2 vst1.8 {$tmp2},[$out],#16 veor $tmp3,$dat3,$tmp3 veor $tmp4,$dat4,$tmp4 vst1.8 {$tmp3-$tmp4},[$out],#32 b.eq .Lxts_dec_abort vld1.8 {$dat0},[$inp],#16 b .Lxts_done .align 4 .Lxts_outer_dec_tail: aesd $dat0,q8 aesimc $dat0,$dat0 aesd $dat1,q8 aesimc $dat1,$dat1 aesd $dat2,q8 aesimc $dat2,$dat2 vld1.32 {q8},[$key_],#16 subs $rounds,$rounds,#2 aesd $dat0,q9 aesimc $dat0,$dat0 aesd $dat1,q9 aesimc $dat1,$dat1 aesd $dat2,q9 aesimc $dat2,$dat2 vld1.32 {q9},[$key_],#16 b.gt .Lxts_outer_dec_tail aesd $dat0,q8 aesimc $dat0,$dat0 aesd $dat1,q8 aesimc $dat1,$dat1 aesd $dat2,q8 aesimc $dat2,$dat2 veor $tmp0,$iv0,$rndlast subs $len,$len,#0x30 // The iv for first block fmov $ivl,$ivd20 fmov $ivh,$ivd21 mov $constnum,#0x87 extr $midnumx,$ivh,$ivh,#32 extr $ivh,$ivh,$ivl,#63 and $tmpmw,$constnum,$midnum,asr #31 eor $ivl,$tmpmx,$ivl,lsl #1 fmov $ivd00,$ivl fmov $ivd01,$ivh veor $tmp1,$iv1,$rndlast csel $xoffset,$len,$xoffset,lo // x6, w6, is zero at this point aesd $dat0,q9 aesimc $dat0,$dat0 aesd $dat1,q9 aesimc $dat1,$dat1 aesd $dat2,q9 aesimc $dat2,$dat2 veor $tmp2,$iv2,$rndlast // The iv for second block extr $midnumx,$ivh,$ivh,#32 extr $ivh,$ivh,$ivl,#63 and $tmpmw,$constnum,$midnum,asr #31 eor $ivl,$tmpmx,$ivl,lsl #1 fmov $ivd10,$ivl fmov $ivd11,$ivh add $xoffset,$xoffset,#0x20 add $inp,$inp,$xoffset // $inp is adjusted to the last data mov $key_,$key1 // The iv for third block extr $midnumx,$ivh,$ivh,#32 extr $ivh,$ivh,$ivl,#63 and $tmpmw,$constnum,$midnum,asr #31 eor $ivl,$tmpmx,$ivl,lsl #1 fmov $ivd20,$ivl fmov $ivd21,$ivh aesd $dat0,q12 aesimc $dat0,$dat0 aesd $dat1,q12 aesimc $dat1,$dat1 aesd $dat2,q12 aesimc $dat2,$dat2 aesd $dat0,q13 aesimc $dat0,$dat0 aesd $dat1,q13 aesimc $dat1,$dat1 aesd $dat2,q13 aesimc $dat2,$dat2 aesd $dat0,q14 aesimc $dat0,$dat0 aesd $dat1,q14 aesimc $dat1,$dat1 aesd $dat2,q14 aesimc $dat2,$dat2 vld1.8 {$in2},[$inp],#16 aesd $dat0,q15 aesd $dat1,q15 aesd $dat2,q15 vld1.32 {q8},[$key_],#16 // re-pre-load rndkey[0] add $rounds,$rounds0,#2 veor $tmp0,$tmp0,$dat0 veor $tmp1,$tmp1,$dat1 veor $dat2,$dat2,$tmp2 vld1.32 {q9},[$key_],#16 // re-pre-load rndkey[1] vst1.8 {$tmp0},[$out],#16 vst1.8 {$tmp1},[$out],#16 vst1.8 {$dat2},[$out],#16 cmn $len,#0x30 add $len,$len,#0x30 b.eq .Lxts_done sub $len,$len,#0x30 vorr $in3,$in1,$in1 vorr $in4,$in2,$in2 nop .Lxts_inner_dec_tail: // $len == -0x10 means two blocks left. cmn $len,#0x10 veor $dat1,$in3,$iv0 veor $dat2,$in4,$iv1 b.eq .Lxts_dec_tail_loop veor $dat2,$in4,$iv0 .Lxts_dec_tail_loop: aesd $dat1,q8 aesimc $dat1,$dat1 aesd $dat2,q8 aesimc $dat2,$dat2 vld1.32 {q8},[$key_],#16 subs $rounds,$rounds,#2 aesd $dat1,q9 aesimc $dat1,$dat1 aesd $dat2,q9 aesimc $dat2,$dat2 vld1.32 {q9},[$key_],#16 b.gt .Lxts_dec_tail_loop aesd $dat1,q8 aesimc $dat1,$dat1 aesd $dat2,q8 aesimc $dat2,$dat2 aesd $dat1,q9 aesimc $dat1,$dat1 aesd $dat2,q9 aesimc $dat2,$dat2 aesd $dat1,q12 aesimc $dat1,$dat1 aesd $dat2,q12 aesimc $dat2,$dat2 cmn $len,#0x20 aesd $dat1,q13 aesimc $dat1,$dat1 aesd $dat2,q13 aesimc $dat2,$dat2 veor $tmp1,$iv0,$rndlast aesd $dat1,q14 aesimc $dat1,$dat1 aesd $dat2,q14 aesimc $dat2,$dat2 veor $tmp2,$iv1,$rndlast aesd $dat1,q15 aesd $dat2,q15 b.eq .Lxts_dec_one veor $tmp1,$tmp1,$dat1 veor $tmp2,$tmp2,$dat2 vorr $iv0,$iv2,$iv2 vorr $iv1,$iv3,$iv3 vst1.8 {$tmp1},[$out],#16 vst1.8 {$tmp2},[$out],#16 add $len,$len,#16 b .Lxts_done .Lxts_dec_one: veor $tmp1,$tmp1,$dat2 vorr $iv0,$iv1,$iv1 vorr $iv1,$iv2,$iv2 vst1.8 {$tmp1},[$out],#16 add $len,$len,#32 .Lxts_done: tst $tailcnt,#0xf b.eq .Lxts_dec_abort // Processing the last two blocks with cipher stealing. mov x7,x3 cbnz x2,.Lxts_dec_1st_done vld1.8 {$dat0},[$inp],#16 // Decrypt the last secod block to get the last plain text block .Lxts_dec_1st_done: eor $tmpin,$dat0,$iv1 ldr $rounds,[$key1,#240] vld1.32 {$dat0},[$key1],#16 sub $rounds,$rounds,#2 vld1.32 {$dat1},[$key1],#16 .Loop_final_2nd_dec: aesd $tmpin,$dat0 aesimc $tmpin,$tmpin vld1.32 {$dat0},[$key1],#16 // load key schedule... subs $rounds,$rounds,#2 aesd $tmpin,$dat1 aesimc $tmpin,$tmpin vld1.32 {$dat1},[$key1],#16 // load key schedule... b.gt .Loop_final_2nd_dec aesd $tmpin,$dat0 aesimc $tmpin,$tmpin vld1.32 {$dat0},[$key1] aesd $tmpin,$dat1 veor $tmpin,$tmpin,$dat0 veor $tmpin,$tmpin,$iv1 vst1.8 {$tmpin},[$out] mov $tmpinp,$inp add $tmpoutp,$out,#16 // Composite the tailcnt "16 byte not aligned block" into the last second plain blocks // to get the last encrypted block. .composite_dec_loop: subs $tailcnt,$tailcnt,#1 ldrb $l2outp,[$out,$tailcnt] ldrb $loutp,[$tmpinp,$tailcnt] strb $l2outp,[$tmpoutp,$tailcnt] strb $loutp,[$out,$tailcnt] b.gt .composite_dec_loop .Lxts_dec_load_done: vld1.8 {$tmpin},[$out] veor $tmpin,$tmpin,$iv0 // Decrypt the composite block to get the last second plain text block ldr $rounds,[$key_,#240] vld1.32 {$dat},[$key_],#16 sub $rounds,$rounds,#2 vld1.32 {$dat1},[$key_],#16 .Loop_final_dec: aesd $tmpin,$dat0 aesimc $tmpin,$tmpin vld1.32 {$dat0},[$key_],#16 // load key schedule... subs $rounds,$rounds,#2 aesd $tmpin,$dat1 aesimc $tmpin,$tmpin vld1.32 {$dat1},[$key_],#16 // load key schedule... b.gt .Loop_final_dec aesd $tmpin,$dat0 aesimc $tmpin,$tmpin vld1.32 {$dat0},[$key_] aesd $tmpin,$dat1 veor $tmpin,$tmpin,$dat0 veor $tmpin,$tmpin,$iv0 vst1.8 {$tmpin},[$out] .Lxts_dec_abort: ldp $tailcnt,$midnumx,[sp,#48] ldp $ivd10,$ivd20,[sp,#32] ldp $ivd30,$ivd40,[sp,#16] ldp $constnumx,$tmpinp,[sp],#64 .Lxts_dec_final_abort: ret .size ${prefix}_xts_decrypt,.-${prefix}_xts_decrypt ___ } }}} $code.=<<___; #endif ___ ######################################## if ($flavour =~ /64/) { ######## 64-bit code my %opcode = ( "aesd" => 0x4e285800, "aese" => 0x4e284800, "aesimc"=> 0x4e287800, "aesmc" => 0x4e286800 ); local *unaes = sub { my ($mnemonic,$arg)=@_; $arg =~ m/[qv]([0-9]+)[^,]*,\s*[qv]([0-9]+)/o && sprintf ".inst\t0x%08x\t//%s %s", $opcode{$mnemonic}|$1|($2<<5), $mnemonic,$arg; }; foreach(split("\n",$code)) { s/\`([^\`]*)\`/eval($1)/geo; s/\bq([0-9]+)\b/"v".($1<8?$1:$1+8).".16b"/geo; # old->new registers s/@\s/\/\//o; # old->new style commentary #s/[v]?(aes\w+)\s+([qv].*)/unaes($1,$2)/geo or s/cclr\s+([wx])([^,]+),\s*([a-z]+)/csel $1$2,$1zr,$1$2,$3/o or s/mov\.([a-z]+)\s+([wx][0-9]+),\s*([wx][0-9]+)/csel $2,$3,$2,$1/o or s/vmov\.i8/movi/o or # fix up legacy mnemonics s/vext\.8/ext/o or s/vrev32\.8/rev32/o or s/vtst\.8/cmtst/o or s/vshr/ushr/o or s/^(\s+)v/$1/o or # strip off v prefix s/\bbx\s+lr\b/ret/o; # fix up remaining legacy suffixes s/\.[ui]?8//o; m/\],#8/o and s/\.16b/\.8b/go; s/\.[ui]?32//o and s/\.16b/\.4s/go; s/\.[ui]?64//o and s/\.16b/\.2d/go; s/\.[42]([sd])\[([0-3])\]/\.$1\[$2\]/o; + # Switch preprocessor checks to aarch64 versions. + s/__ARME([BL])__/__AARCH64E$1__/go; + print $_,"\n"; } } else { ######## 32-bit code my %opcode = ( "aesd" => 0xf3b00340, "aese" => 0xf3b00300, "aesimc"=> 0xf3b003c0, "aesmc" => 0xf3b00380 ); local *unaes = sub { my ($mnemonic,$arg)=@_; if ($arg =~ m/[qv]([0-9]+)[^,]*,\s*[qv]([0-9]+)/o) { my $word = $opcode{$mnemonic}|(($1&7)<<13)|(($1&8)<<19) |(($2&7)<<1) |(($2&8)<<2); # since ARMv7 instructions are always encoded little-endian. # correct solution is to use .inst directive, but older # assemblers don't implement it:-( sprintf "INST(0x%02x,0x%02x,0x%02x,0x%02x)\t@ %s %s", $word&0xff,($word>>8)&0xff, ($word>>16)&0xff,($word>>24)&0xff, $mnemonic,$arg; } }; sub unvtbl { my $arg=shift; $arg =~ m/q([0-9]+),\s*\{q([0-9]+)\},\s*q([0-9]+)/o && sprintf "vtbl.8 d%d,{q%d},d%d\n\t". "vtbl.8 d%d,{q%d},d%d", 2*$1,$2,2*$3, 2*$1+1,$2,2*$3+1; } sub unvdup32 { my $arg=shift; $arg =~ m/q([0-9]+),\s*q([0-9]+)\[([0-3])\]/o && sprintf "vdup.32 q%d,d%d[%d]",$1,2*$2+($3>>1),$3&1; } sub unvmov32 { my $arg=shift; $arg =~ m/q([0-9]+)\[([0-3])\],(.*)/o && sprintf "vmov.32 d%d[%d],%s",2*$1+($2>>1),$2&1,$3; } foreach(split("\n",$code)) { s/\`([^\`]*)\`/eval($1)/geo; s/\b[wx]([0-9]+)\b/r$1/go; # new->old registers s/\bv([0-9])\.[12468]+[bsd]\b/q$1/go; # new->old registers s/\/\/\s?/@ /o; # new->old style commentary # fix up remaining new-style suffixes s/\{q([0-9]+)\},\s*\[(.+)\],#8/sprintf "{d%d},[$2]!",2*$1/eo or s/\],#[0-9]+/]!/o; s/[v]?(aes\w+)\s+([qv].*)/unaes($1,$2)/geo or s/cclr\s+([^,]+),\s*([a-z]+)/mov.$2 $1,#0/o or s/vtbl\.8\s+(.*)/unvtbl($1)/geo or s/vdup\.32\s+(.*)/unvdup32($1)/geo or s/vmov\.32\s+(.*)/unvmov32($1)/geo or s/^(\s+)b\./$1b/o or s/^(\s+)ret/$1bx\tlr/o; if (s/^(\s+)mov\.([a-z]+)/$1mov$2/) { print " it $2\n"; } print $_,"\n"; } } close STDOUT or die "error closing STDOUT: $!"; diff --git a/crypto/openssl/crypto/arm_arch.h b/crypto/openssl/crypto/arm_arch.h index 45d7e1556475..ec4a087fede2 100644 --- a/crypto/openssl/crypto/arm_arch.h +++ b/crypto/openssl/crypto/arm_arch.h @@ -1,129 +1,124 @@ /* - * Copyright 2011-2022 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2011-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ #ifndef OSSL_CRYPTO_ARM_ARCH_H # define OSSL_CRYPTO_ARM_ARCH_H # if !defined(__ARM_ARCH__) # if defined(__CC_ARM) # define __ARM_ARCH__ __TARGET_ARCH_ARM # if defined(__BIG_ENDIAN) # define __ARMEB__ # else # define __ARMEL__ # endif # elif defined(__GNUC__) # if defined(__aarch64__) # define __ARM_ARCH__ 8 -# if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ -# define __ARMEB__ -# else -# define __ARMEL__ -# endif /* * Why doesn't gcc define __ARM_ARCH__? Instead it defines * bunch of below macros. See all_architectures[] table in * gcc/config/arm/arm.c. On a side note it defines * __ARMEL__/__ARMEB__ for little-/big-endian. */ # elif defined(__ARM_ARCH) # define __ARM_ARCH__ __ARM_ARCH # elif defined(__ARM_ARCH_8A__) # define __ARM_ARCH__ 8 # elif defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || \ defined(__ARM_ARCH_7R__)|| defined(__ARM_ARCH_7M__) || \ defined(__ARM_ARCH_7EM__) # define __ARM_ARCH__ 7 # elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || \ defined(__ARM_ARCH_6K__)|| defined(__ARM_ARCH_6M__) || \ defined(__ARM_ARCH_6Z__)|| defined(__ARM_ARCH_6ZK__) || \ defined(__ARM_ARCH_6T2__) # define __ARM_ARCH__ 6 # elif defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) || \ defined(__ARM_ARCH_5E__)|| defined(__ARM_ARCH_5TE__) || \ defined(__ARM_ARCH_5TEJ__) # define __ARM_ARCH__ 5 # elif defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) # define __ARM_ARCH__ 4 # else # error "unsupported ARM architecture" # endif # endif # endif # if !defined(__ARM_MAX_ARCH__) # define __ARM_MAX_ARCH__ __ARM_ARCH__ # endif # if __ARM_MAX_ARCH__<__ARM_ARCH__ # error "__ARM_MAX_ARCH__ can't be less than __ARM_ARCH__" # elif __ARM_MAX_ARCH__!=__ARM_ARCH__ # if __ARM_ARCH__<7 && __ARM_MAX_ARCH__>=7 && defined(__ARMEB__) # error "can't build universal big-endian binary" # endif # endif # ifndef __ASSEMBLER__ extern unsigned int OPENSSL_armcap_P; extern unsigned int OPENSSL_arm_midr; extern unsigned int OPENSSL_armv8_rsa_neonized; # endif # define ARMV7_NEON (1<<0) # define ARMV7_TICK (1<<1) # define ARMV8_AES (1<<2) # define ARMV8_SHA1 (1<<3) # define ARMV8_SHA256 (1<<4) # define ARMV8_PMULL (1<<5) # define ARMV8_SHA512 (1<<6) # define ARMV8_CPUID (1<<7) /* * MIDR_EL1 system register * * 63___ _ ___32_31___ _ ___24_23_____20_19_____16_15__ _ __4_3_______0 * | | | | | | | * |RES0 | Implementer | Variant | Arch | PartNum |Revision| * |____ _ _____|_____ _ _____|_________|_______ _|____ _ ___|________| * */ # define ARM_CPU_IMP_ARM 0x41 # define ARM_CPU_PART_CORTEX_A72 0xD08 # define ARM_CPU_PART_N1 0xD0C # define MIDR_PARTNUM_SHIFT 4 # define MIDR_PARTNUM_MASK (0xfffU << MIDR_PARTNUM_SHIFT) # define MIDR_PARTNUM(midr) \ (((midr) & MIDR_PARTNUM_MASK) >> MIDR_PARTNUM_SHIFT) # define MIDR_IMPLEMENTER_SHIFT 24 # define MIDR_IMPLEMENTER_MASK (0xffU << MIDR_IMPLEMENTER_SHIFT) # define MIDR_IMPLEMENTER(midr) \ (((midr) & MIDR_IMPLEMENTER_MASK) >> MIDR_IMPLEMENTER_SHIFT) # define MIDR_ARCHITECTURE_SHIFT 16 # define MIDR_ARCHITECTURE_MASK (0xfU << MIDR_ARCHITECTURE_SHIFT) # define MIDR_ARCHITECTURE(midr) \ (((midr) & MIDR_ARCHITECTURE_MASK) >> MIDR_ARCHITECTURE_SHIFT) # define MIDR_CPU_MODEL_MASK \ (MIDR_IMPLEMENTER_MASK | \ MIDR_PARTNUM_MASK | \ MIDR_ARCHITECTURE_MASK) # define MIDR_CPU_MODEL(imp, partnum) \ (((imp) << MIDR_IMPLEMENTER_SHIFT) | \ (0xfU << MIDR_ARCHITECTURE_SHIFT) | \ ((partnum) << MIDR_PARTNUM_SHIFT)) # define MIDR_IS_CPU_MODEL(midr, imp, partnum) \ (((midr) & MIDR_CPU_MODEL_MASK) == MIDR_CPU_MODEL(imp, partnum)) #endif diff --git a/crypto/openssl/crypto/bn/bn_gcd.c b/crypto/openssl/crypto/bn/bn_gcd.c index 59d024f674eb..cd0b0151ec7e 100644 --- a/crypto/openssl/crypto/bn/bn_gcd.c +++ b/crypto/openssl/crypto/bn/bn_gcd.c @@ -1,647 +1,647 @@ /* - * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ #include "internal/cryptlib.h" #include "bn_local.h" /* * bn_mod_inverse_no_branch is a special version of BN_mod_inverse. It does * not contain branches that may leak sensitive information. * * This is a static function, we ensure all callers in this file pass valid * arguments: all passed pointers here are non-NULL. */ static ossl_inline BIGNUM *bn_mod_inverse_no_branch(BIGNUM *in, const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx, int *pnoinv) { BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL; BIGNUM *ret = NULL; int sign; bn_check_top(a); bn_check_top(n); BN_CTX_start(ctx); A = BN_CTX_get(ctx); B = BN_CTX_get(ctx); X = BN_CTX_get(ctx); D = BN_CTX_get(ctx); M = BN_CTX_get(ctx); Y = BN_CTX_get(ctx); T = BN_CTX_get(ctx); if (T == NULL) goto err; if (in == NULL) R = BN_new(); else R = in; if (R == NULL) goto err; if (!BN_one(X)) goto err; BN_zero(Y); if (BN_copy(B, a) == NULL) goto err; if (BN_copy(A, n) == NULL) goto err; A->neg = 0; if (B->neg || (BN_ucmp(B, A) >= 0)) { /* * Turn BN_FLG_CONSTTIME flag on, so that when BN_div is invoked, * BN_div_no_branch will be called eventually. */ { BIGNUM local_B; bn_init(&local_B); BN_with_flags(&local_B, B, BN_FLG_CONSTTIME); if (!BN_nnmod(B, &local_B, A, ctx)) goto err; /* Ensure local_B goes out of scope before any further use of B */ } } sign = -1; /*- * From B = a mod |n|, A = |n| it follows that * * 0 <= B < A, * -sign*X*a == B (mod |n|), * sign*Y*a == A (mod |n|). */ while (!BN_is_zero(B)) { BIGNUM *tmp; /*- * 0 < B < A, * (*) -sign*X*a == B (mod |n|), * sign*Y*a == A (mod |n|) */ /* * Turn BN_FLG_CONSTTIME flag on, so that when BN_div is invoked, * BN_div_no_branch will be called eventually. */ { BIGNUM local_A; bn_init(&local_A); BN_with_flags(&local_A, A, BN_FLG_CONSTTIME); /* (D, M) := (A/B, A%B) ... */ if (!BN_div(D, M, &local_A, B, ctx)) goto err; /* Ensure local_A goes out of scope before any further use of A */ } /*- * Now * A = D*B + M; * thus we have * (**) sign*Y*a == D*B + M (mod |n|). */ tmp = A; /* keep the BIGNUM object, the value does not * matter */ /* (A, B) := (B, A mod B) ... */ A = B; B = M; /* ... so we have 0 <= B < A again */ /*- * Since the former M is now B and the former B is now A, * (**) translates into * sign*Y*a == D*A + B (mod |n|), * i.e. * sign*Y*a - D*A == B (mod |n|). * Similarly, (*) translates into * -sign*X*a == A (mod |n|). * * Thus, * sign*Y*a + D*sign*X*a == B (mod |n|), * i.e. * sign*(Y + D*X)*a == B (mod |n|). * * So if we set (X, Y, sign) := (Y + D*X, X, -sign), we arrive back at * -sign*X*a == B (mod |n|), * sign*Y*a == A (mod |n|). * Note that X and Y stay non-negative all the time. */ if (!BN_mul(tmp, D, X, ctx)) goto err; if (!BN_add(tmp, tmp, Y)) goto err; M = Y; /* keep the BIGNUM object, the value does not * matter */ Y = X; X = tmp; sign = -sign; } /*- * The while loop (Euclid's algorithm) ends when * A == gcd(a,n); * we have * sign*Y*a == A (mod |n|), * where Y is non-negative. */ if (sign < 0) { if (!BN_sub(Y, n, Y)) goto err; } /* Now Y*a == A (mod |n|). */ if (BN_is_one(A)) { /* Y*a == 1 (mod |n|) */ if (!Y->neg && BN_ucmp(Y, n) < 0) { if (!BN_copy(R, Y)) goto err; } else { if (!BN_nnmod(R, Y, n, ctx)) goto err; } } else { *pnoinv = 1; /* caller sets the BN_R_NO_INVERSE error */ goto err; } ret = R; *pnoinv = 0; err: if ((ret == NULL) && (in == NULL)) BN_free(R); BN_CTX_end(ctx); bn_check_top(ret); return ret; } /* * This is an internal function, we assume all callers pass valid arguments: * all pointers passed here are assumed non-NULL. */ BIGNUM *int_bn_mod_inverse(BIGNUM *in, const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx, int *pnoinv) { BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL; BIGNUM *ret = NULL; int sign; /* This is invalid input so we don't worry about constant time here */ if (BN_abs_is_word(n, 1) || BN_is_zero(n)) { *pnoinv = 1; return NULL; } *pnoinv = 0; if ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0)) { return bn_mod_inverse_no_branch(in, a, n, ctx, pnoinv); } bn_check_top(a); bn_check_top(n); BN_CTX_start(ctx); A = BN_CTX_get(ctx); B = BN_CTX_get(ctx); X = BN_CTX_get(ctx); D = BN_CTX_get(ctx); M = BN_CTX_get(ctx); Y = BN_CTX_get(ctx); T = BN_CTX_get(ctx); if (T == NULL) goto err; if (in == NULL) R = BN_new(); else R = in; if (R == NULL) goto err; if (!BN_one(X)) goto err; BN_zero(Y); if (BN_copy(B, a) == NULL) goto err; if (BN_copy(A, n) == NULL) goto err; A->neg = 0; if (B->neg || (BN_ucmp(B, A) >= 0)) { if (!BN_nnmod(B, B, A, ctx)) goto err; } sign = -1; /*- * From B = a mod |n|, A = |n| it follows that * * 0 <= B < A, * -sign*X*a == B (mod |n|), * sign*Y*a == A (mod |n|). */ if (BN_is_odd(n) && (BN_num_bits(n) <= 2048)) { /* * Binary inversion algorithm; requires odd modulus. This is faster * than the general algorithm if the modulus is sufficiently small * (about 400 .. 500 bits on 32-bit systems, but much more on 64-bit * systems) */ int shift; while (!BN_is_zero(B)) { /*- * 0 < B < |n|, * 0 < A <= |n|, * (1) -sign*X*a == B (mod |n|), * (2) sign*Y*a == A (mod |n|) */ /* * Now divide B by the maximum possible power of two in the * integers, and divide X by the same value mod |n|. When we're * done, (1) still holds. */ shift = 0; while (!BN_is_bit_set(B, shift)) { /* note that 0 < B */ shift++; if (BN_is_odd(X)) { if (!BN_uadd(X, X, n)) goto err; } /* * now X is even, so we can easily divide it by two */ if (!BN_rshift1(X, X)) goto err; } if (shift > 0) { if (!BN_rshift(B, B, shift)) goto err; } /* * Same for A and Y. Afterwards, (2) still holds. */ shift = 0; while (!BN_is_bit_set(A, shift)) { /* note that 0 < A */ shift++; if (BN_is_odd(Y)) { if (!BN_uadd(Y, Y, n)) goto err; } /* now Y is even */ if (!BN_rshift1(Y, Y)) goto err; } if (shift > 0) { if (!BN_rshift(A, A, shift)) goto err; } /*- * We still have (1) and (2). * Both A and B are odd. * The following computations ensure that * * 0 <= B < |n|, * 0 < A < |n|, * (1) -sign*X*a == B (mod |n|), * (2) sign*Y*a == A (mod |n|), * * and that either A or B is even in the next iteration. */ if (BN_ucmp(B, A) >= 0) { /* -sign*(X + Y)*a == B - A (mod |n|) */ if (!BN_uadd(X, X, Y)) goto err; /* * NB: we could use BN_mod_add_quick(X, X, Y, n), but that * actually makes the algorithm slower */ if (!BN_usub(B, B, A)) goto err; } else { /* sign*(X + Y)*a == A - B (mod |n|) */ if (!BN_uadd(Y, Y, X)) goto err; /* * as above, BN_mod_add_quick(Y, Y, X, n) would slow things down */ if (!BN_usub(A, A, B)) goto err; } } } else { /* general inversion algorithm */ while (!BN_is_zero(B)) { BIGNUM *tmp; /*- * 0 < B < A, * (*) -sign*X*a == B (mod |n|), * sign*Y*a == A (mod |n|) */ /* (D, M) := (A/B, A%B) ... */ if (BN_num_bits(A) == BN_num_bits(B)) { if (!BN_one(D)) goto err; if (!BN_sub(M, A, B)) goto err; } else if (BN_num_bits(A) == BN_num_bits(B) + 1) { /* A/B is 1, 2, or 3 */ if (!BN_lshift1(T, B)) goto err; if (BN_ucmp(A, T) < 0) { /* A < 2*B, so D=1 */ if (!BN_one(D)) goto err; if (!BN_sub(M, A, B)) goto err; } else { /* A >= 2*B, so D=2 or D=3 */ if (!BN_sub(M, A, T)) goto err; if (!BN_add(D, T, B)) goto err; /* use D (:= 3*B) as temp */ if (BN_ucmp(A, D) < 0) { /* A < 3*B, so D=2 */ if (!BN_set_word(D, 2)) goto err; /* * M (= A - 2*B) already has the correct value */ } else { /* only D=3 remains */ if (!BN_set_word(D, 3)) goto err; /* * currently M = A - 2*B, but we need M = A - 3*B */ if (!BN_sub(M, M, B)) goto err; } } } else { if (!BN_div(D, M, A, B, ctx)) goto err; } /*- * Now * A = D*B + M; * thus we have * (**) sign*Y*a == D*B + M (mod |n|). */ tmp = A; /* keep the BIGNUM object, the value does not matter */ /* (A, B) := (B, A mod B) ... */ A = B; B = M; /* ... so we have 0 <= B < A again */ /*- * Since the former M is now B and the former B is now A, * (**) translates into * sign*Y*a == D*A + B (mod |n|), * i.e. * sign*Y*a - D*A == B (mod |n|). * Similarly, (*) translates into * -sign*X*a == A (mod |n|). * * Thus, * sign*Y*a + D*sign*X*a == B (mod |n|), * i.e. * sign*(Y + D*X)*a == B (mod |n|). * * So if we set (X, Y, sign) := (Y + D*X, X, -sign), we arrive back at * -sign*X*a == B (mod |n|), * sign*Y*a == A (mod |n|). * Note that X and Y stay non-negative all the time. */ /* * most of the time D is very small, so we can optimize tmp := D*X+Y */ if (BN_is_one(D)) { if (!BN_add(tmp, X, Y)) goto err; } else { if (BN_is_word(D, 2)) { if (!BN_lshift1(tmp, X)) goto err; } else if (BN_is_word(D, 4)) { if (!BN_lshift(tmp, X, 2)) goto err; } else if (D->top == 1) { if (!BN_copy(tmp, X)) goto err; if (!BN_mul_word(tmp, D->d[0])) goto err; } else { if (!BN_mul(tmp, D, X, ctx)) goto err; } if (!BN_add(tmp, tmp, Y)) goto err; } M = Y; /* keep the BIGNUM object, the value does not matter */ Y = X; X = tmp; sign = -sign; } } /*- * The while loop (Euclid's algorithm) ends when * A == gcd(a,n); * we have * sign*Y*a == A (mod |n|), * where Y is non-negative. */ if (sign < 0) { if (!BN_sub(Y, n, Y)) goto err; } /* Now Y*a == A (mod |n|). */ if (BN_is_one(A)) { /* Y*a == 1 (mod |n|) */ if (!Y->neg && BN_ucmp(Y, n) < 0) { if (!BN_copy(R, Y)) goto err; } else { if (!BN_nnmod(R, Y, n, ctx)) goto err; } } else { *pnoinv = 1; goto err; } ret = R; err: if ((ret == NULL) && (in == NULL)) BN_free(R); BN_CTX_end(ctx); bn_check_top(ret); return ret; } /* solves ax == 1 (mod n) */ BIGNUM *BN_mod_inverse(BIGNUM *in, const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx) { BN_CTX *new_ctx = NULL; BIGNUM *rv; int noinv = 0; if (ctx == NULL) { ctx = new_ctx = BN_CTX_new_ex(NULL); if (ctx == NULL) { ERR_raise(ERR_LIB_BN, ERR_R_MALLOC_FAILURE); return NULL; } } rv = int_bn_mod_inverse(in, a, n, ctx, &noinv); if (noinv) ERR_raise(ERR_LIB_BN, BN_R_NO_INVERSE); BN_CTX_free(new_ctx); return rv; } /*- * This function is based on the constant-time GCD work by Bernstein and Yang: * https://eprint.iacr.org/2019/266 * Generalized fast GCD function to allow even inputs. * The algorithm first finds the shared powers of 2 between * the inputs, and removes them, reducing at least one of the * inputs to an odd value. Then it proceeds to calculate the GCD. * Before returning the resulting GCD, we take care of adding * back the powers of two removed at the beginning. * Note 1: we assume the bit length of both inputs is public information, * since access to top potentially leaks this information. */ int BN_gcd(BIGNUM *r, const BIGNUM *in_a, const BIGNUM *in_b, BN_CTX *ctx) { BIGNUM *g, *temp = NULL; BN_ULONG mask = 0; int i, j, top, rlen, glen, m, bit = 1, delta = 1, cond = 0, shifts = 0, ret = 0; /* Note 2: zero input corner cases are not constant-time since they are * handled immediately. An attacker can run an attack under this * assumption without the need of side-channel information. */ if (BN_is_zero(in_b)) { ret = BN_copy(r, in_a) != NULL; r->neg = 0; return ret; } if (BN_is_zero(in_a)) { ret = BN_copy(r, in_b) != NULL; r->neg = 0; return ret; } bn_check_top(in_a); bn_check_top(in_b); BN_CTX_start(ctx); temp = BN_CTX_get(ctx); g = BN_CTX_get(ctx); /* make r != 0, g != 0 even, so BN_rshift is not a potential nop */ if (g == NULL || !BN_lshift1(g, in_b) || !BN_lshift1(r, in_a)) goto err; /* find shared powers of two, i.e. "shifts" >= 1 */ for (i = 0; i < r->dmax && i < g->dmax; i++) { mask = ~(r->d[i] | g->d[i]); for (j = 0; j < BN_BITS2; j++) { bit &= mask; shifts += bit; mask >>= 1; } } /* subtract shared powers of two; shifts >= 1 */ if (!BN_rshift(r, r, shifts) || !BN_rshift(g, g, shifts)) goto err; /* expand to biggest nword, with room for a possible extra word */ top = 1 + ((r->top >= g->top) ? r->top : g->top); if (bn_wexpand(r, top) == NULL || bn_wexpand(g, top) == NULL || bn_wexpand(temp, top) == NULL) goto err; /* re arrange inputs s.t. r is odd */ BN_consttime_swap((~r->d[0]) & 1, r, g, top); /* compute the number of iterations */ rlen = BN_num_bits(r); glen = BN_num_bits(g); m = 4 + 3 * ((rlen >= glen) ? rlen : glen); for (i = 0; i < m; i++) { /* conditionally flip signs if delta is positive and g is odd */ - cond = (-delta >> (8 * sizeof(delta) - 1)) & g->d[0] & 1 + cond = ((unsigned int)-delta >> (8 * sizeof(delta) - 1)) & g->d[0] & 1 /* make sure g->top > 0 (i.e. if top == 0 then g == 0 always) */ - & (~((g->top - 1) >> (sizeof(g->top) * 8 - 1))); + & (~((unsigned int)(g->top - 1) >> (sizeof(g->top) * 8 - 1))); delta = (-cond & -delta) | ((cond - 1) & delta); r->neg ^= cond; /* swap */ BN_consttime_swap(cond, r, g, top); /* elimination step */ delta++; if (!BN_add(temp, g, r)) goto err; BN_consttime_swap(g->d[0] & 1 /* g is odd */ /* make sure g->top > 0 (i.e. if top == 0 then g == 0 always) */ - & (~((g->top - 1) >> (sizeof(g->top) * 8 - 1))), + & (~((unsigned int)(g->top - 1) >> (sizeof(g->top) * 8 - 1))), g, temp, top); if (!BN_rshift1(g, g)) goto err; } /* remove possible negative sign */ r->neg = 0; /* add powers of 2 removed, then correct the artificial shift */ if (!BN_lshift(r, r, shifts) || !BN_rshift1(r, r)) goto err; ret = 1; err: BN_CTX_end(ctx); bn_check_top(r); return ret; } diff --git a/crypto/openssl/crypto/build.info b/crypto/openssl/crypto/build.info index b90390ae864c..c04db5591120 100644 --- a/crypto/openssl/crypto/build.info +++ b/crypto/openssl/crypto/build.info @@ -1,138 +1,136 @@ # Note that these directories are filtered in Configure. Look for %skipdir # there for further explanations. SUBDIRS=objects buffer bio stack lhash rand evp asn1 pem x509 conf \ txt_db pkcs7 pkcs12 ui kdf store property \ md2 md4 md5 sha mdc2 hmac ripemd whrlpool poly1305 \ siphash sm3 des aes rc2 rc4 rc5 idea aria bf cast camellia \ seed sm4 chacha modes bn ec rsa dsa dh sm2 dso engine \ err comp http ocsp cms ts srp cmac ct async ess crmf cmp encode_decode \ ffc LIBS=../libcrypto $UPLINKSRC= $UPLINKDEF= IF[{- !$disabled{uplink} -}] $UPLINKSRC_common=../ms/uplink.c $UPLINKSRC_x86=$UPLINKSRC_common uplink-x86.S $UPLINKSRC_x86_64=$UPLINKSRC_common uplink-x86_64.s $UPLINKSRC_ia64=$UPLINKSRC_common uplink-ia64.s IF[$UPLINKSRC_{- $target{uplink_arch} -}] $UPLINKSRC=$UPLINKSRC_{- $target{uplink_arch} -} $UPLINKDEF=OPENSSL_USE_APPLINK ENDIF ENDIF $CPUIDASM=mem_clr.c $CPUIDDEF= IF[{- !$disabled{asm} && $config{processor} ne '386' -}] $CPUIDASM_x86=x86cpuid.S $CPUIDASM_x86_64=x86_64cpuid.s $CPUIDASM_ia64=ia64cpuid.s $CPUIDASM_sparcv9=sparcv9cap.c sparccpuid.S $CPUIDASM_alpha=alphacpuid.s $CPUIDASM_s390x=s390xcap.c s390xcpuid.S $CPUIDASM_armv4=armcap.c armv4cpuid.S $CPUIDASM_aarch64=armcap.c arm64cpuid.S $CPUIDASM_parisc11=pariscid.s $CPUIDASM_parisc20_64=$CPUIDASM_parisc11 $CPUIDASM_ppc32=ppccpuid.s ppccap.c $CPUIDASM_ppc64=$CPUIDASM_ppc32 $CPUIDASM_c64xplus=c64xpluscpuid.s # Now that we have defined all the arch specific variables, use the # appropriate one, and define the appropriate macros IF[$CPUIDASM_{- $target{asm_arch} -}] $CPUIDASM=$CPUIDASM_{- $target{asm_arch} -} $CPUIDDEF=OPENSSL_CPUID_OBJ ENDIF ENDIF # CPUID support. We need to add that explicitly in every shared library and # provider module that uses it. ctype.c is included here because the CPUID # uses functions from there to parse magic environment variables. $CPUID_COMMON=$CPUIDASM cpuid.c ctype.c INCLUDE[cpuid.o]=.. SOURCE[../libcrypto]=$CPUID_COMMON DEFINE[../libcrypto]=$CPUIDDEF SOURCE[../providers/libfips.a]=$CPUID_COMMON DEFINE[../providers/libfips.a]=$CPUIDDEF # We only need to include the CPUID stuff in the legacy provider when it's a # separate module and it's dynamically linked with libcrypto. Otherwise, it # already gets everything that the static libcrypto.a has, and doesn't need it # added again. IF[{- !$disabled{module} && !$disabled{shared} -}] SOURCE[../providers/liblegacy.a]=$CPUID_COMMON DEFINE[../providers/liblegacy.a]=$CPUIDDEF ENDIF # Implementations are now spread across several libraries, so the CPUID define # need to be applied to all affected libraries and modules. DEFINE[../providers/libcommon.a]=$CPUIDDEF DEFINE[../providers/libdefault.a]=$CPUIDDEF # The Core $CORE_COMMON=provider_core.c provider_predefined.c \ core_fetch.c core_algorithm.c core_namemap.c self_test_core.c SOURCE[../libcrypto]=$CORE_COMMON provider_conf.c SOURCE[../providers/libfips.a]=$CORE_COMMON # Central utilities $UTIL_COMMON=\ cryptlib.c params.c params_from_text.c bsearch.c ex_data.c o_str.c \ threads_pthread.c threads_win.c threads_none.c initthread.c \ context.c sparse_array.c asn1_dsa.c packet.c param_build.c \ param_build_set.c der_writer.c threads_lib.c params_dup.c -SHARED_SOURCE[../libssl]=sparse_array.c - SOURCE[../libcrypto]=$UTIL_COMMON \ mem.c mem_sec.c \ cversion.c info.c cpt_err.c ebcdic.c uid.c o_time.c o_dir.c \ o_fopen.c getenv.c o_init.c init.c trace.c provider.c provider_child.c \ punycode.c passphrase.c SOURCE[../providers/libfips.a]=$UTIL_COMMON SOURCE[../libcrypto]=$UPLINKSRC DEFINE[../libcrypto]=$UPLINKDEF DEPEND[info.o]=buildinf.h DEPEND[cversion.o]=buildinf.h GENERATE[buildinf.h]=../util/mkbuildinf.pl "$(CC) $(LIB_CFLAGS) $(CPPFLAGS_Q)" "$(PLATFORM)" GENERATE[uplink-x86.S]=../ms/uplink-x86.pl GENERATE[uplink-x86_64.s]=../ms/uplink-x86_64.pl GENERATE[uplink-ia64.s]=../ms/uplink-ia64.pl GENERATE[x86cpuid.S]=x86cpuid.pl DEPEND[x86cpuid.s]=perlasm/x86asm.pl GENERATE[x86_64cpuid.s]=x86_64cpuid.pl GENERATE[ia64cpuid.s]=ia64cpuid.S GENERATE[ppccpuid.s]=ppccpuid.pl GENERATE[pariscid.s]=pariscid.pl GENERATE[alphacpuid.s]=alphacpuid.pl GENERATE[arm64cpuid.S]=arm64cpuid.pl INCLUDE[arm64cpuid.o]=. GENERATE[armv4cpuid.S]=armv4cpuid.pl INCLUDE[armv4cpuid.o]=. GENERATE[s390xcpuid.S]=s390xcpuid.pl INCLUDE[s390xcpuid.o]=. IF[{- $config{target} =~ /^(?:Cygwin|mingw|VC-|BC-)/ -}] SHARED_SOURCE[../libcrypto]=dllmain.c ENDIF diff --git a/crypto/openssl/crypto/cms/cms_enc.c b/crypto/openssl/crypto/cms/cms_enc.c index f7007c12319e..ae88df33a7f0 100644 --- a/crypto/openssl/crypto/cms/cms_enc.c +++ b/crypto/openssl/crypto/cms/cms_enc.c @@ -1,258 +1,259 @@ /* - * Copyright 2008-2022 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2008-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ #include "internal/cryptlib.h" #include #include #include #include #include #include #include "crypto/evp.h" +#include "crypto/asn1.h" #include "cms_local.h" /* CMS EncryptedData Utilities */ /* Return BIO based on EncryptedContentInfo and key */ BIO *ossl_cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec, const CMS_CTX *cms_ctx) { BIO *b; EVP_CIPHER_CTX *ctx; EVP_CIPHER *fetched_ciph = NULL; const EVP_CIPHER *cipher = NULL; X509_ALGOR *calg = ec->contentEncryptionAlgorithm; evp_cipher_aead_asn1_params aparams; unsigned char iv[EVP_MAX_IV_LENGTH], *piv = NULL; unsigned char *tkey = NULL; int len; int ivlen = 0; size_t tkeylen = 0; int ok = 0; int enc, keep_key = 0; OSSL_LIB_CTX *libctx = ossl_cms_ctx_get0_libctx(cms_ctx); const char *propq = ossl_cms_ctx_get0_propq(cms_ctx); enc = ec->cipher ? 1 : 0; b = BIO_new(BIO_f_cipher()); if (b == NULL) { ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); return NULL; } BIO_get_cipher_ctx(b, &ctx); (void)ERR_set_mark(); if (enc) { cipher = ec->cipher; /* * If not keeping key set cipher to NULL so subsequent calls decrypt. */ if (ec->key != NULL) ec->cipher = NULL; } else { cipher = EVP_get_cipherbyobj(calg->algorithm); } if (cipher != NULL) { fetched_ciph = EVP_CIPHER_fetch(libctx, EVP_CIPHER_get0_name(cipher), propq); if (fetched_ciph != NULL) cipher = fetched_ciph; } if (cipher == NULL) { (void)ERR_clear_last_mark(); ERR_raise(ERR_LIB_CMS, CMS_R_UNKNOWN_CIPHER); goto err; } (void)ERR_pop_to_mark(); if (EVP_CipherInit_ex(ctx, cipher, NULL, NULL, NULL, enc) <= 0) { ERR_raise(ERR_LIB_CMS, CMS_R_CIPHER_INITIALISATION_ERROR); goto err; } if (enc) { calg->algorithm = OBJ_nid2obj(EVP_CIPHER_CTX_get_type(ctx)); - if (calg->algorithm == NULL) { + if (calg->algorithm == NULL || calg->algorithm->nid == NID_undef) { ERR_raise(ERR_LIB_CMS, CMS_R_UNSUPPORTED_CONTENT_ENCRYPTION_ALGORITHM); goto err; } /* Generate a random IV if we need one */ ivlen = EVP_CIPHER_CTX_get_iv_length(ctx); if (ivlen < 0) { ERR_raise(ERR_LIB_CMS, ERR_R_EVP_LIB); goto err; } if (ivlen > 0) { if (RAND_bytes_ex(libctx, iv, ivlen, 0) <= 0) goto err; piv = iv; } } else { if (evp_cipher_asn1_to_param_ex(ctx, calg->parameter, &aparams) <= 0) { ERR_raise(ERR_LIB_CMS, CMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR); goto err; } if ((EVP_CIPHER_get_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER)) { piv = aparams.iv; if (ec->taglen > 0 && EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, ec->taglen, ec->tag) <= 0) { ERR_raise(ERR_LIB_CMS, CMS_R_CIPHER_AEAD_SET_TAG_ERROR); goto err; } } } len = EVP_CIPHER_CTX_get_key_length(ctx); if (len <= 0) goto err; tkeylen = (size_t)len; /* Generate random session key */ if (!enc || !ec->key) { tkey = OPENSSL_malloc(tkeylen); if (tkey == NULL) { ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); goto err; } if (EVP_CIPHER_CTX_rand_key(ctx, tkey) <= 0) goto err; } if (!ec->key) { ec->key = tkey; ec->keylen = tkeylen; tkey = NULL; if (enc) keep_key = 1; else ERR_clear_error(); } if (ec->keylen != tkeylen) { /* If necessary set key length */ if (EVP_CIPHER_CTX_set_key_length(ctx, ec->keylen) <= 0) { /* * Only reveal failure if debugging so we don't leak information * which may be useful in MMA. */ if (enc || ec->debug) { ERR_raise(ERR_LIB_CMS, CMS_R_INVALID_KEY_LENGTH); goto err; } else { /* Use random key */ OPENSSL_clear_free(ec->key, ec->keylen); ec->key = tkey; ec->keylen = tkeylen; tkey = NULL; ERR_clear_error(); } } } if (EVP_CipherInit_ex(ctx, NULL, NULL, ec->key, piv, enc) <= 0) { ERR_raise(ERR_LIB_CMS, CMS_R_CIPHER_INITIALISATION_ERROR); goto err; } if (enc) { calg->parameter = ASN1_TYPE_new(); if (calg->parameter == NULL) { ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); goto err; } if ((EVP_CIPHER_get_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER)) { memcpy(aparams.iv, piv, ivlen); aparams.iv_len = ivlen; aparams.tag_len = EVP_CIPHER_CTX_get_tag_length(ctx); if (aparams.tag_len <= 0) goto err; } if (evp_cipher_param_to_asn1_ex(ctx, calg->parameter, &aparams) <= 0) { ERR_raise(ERR_LIB_CMS, CMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR); goto err; } /* If parameter type not set omit parameter */ if (calg->parameter->type == V_ASN1_UNDEF) { ASN1_TYPE_free(calg->parameter); calg->parameter = NULL; } } ok = 1; err: EVP_CIPHER_free(fetched_ciph); if (!keep_key || !ok) { OPENSSL_clear_free(ec->key, ec->keylen); ec->key = NULL; } OPENSSL_clear_free(tkey, tkeylen); if (ok) return b; BIO_free(b); return NULL; } int ossl_cms_EncryptedContent_init(CMS_EncryptedContentInfo *ec, const EVP_CIPHER *cipher, const unsigned char *key, size_t keylen, const CMS_CTX *cms_ctx) { ec->cipher = cipher; if (key) { if ((ec->key = OPENSSL_malloc(keylen)) == NULL) { ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); return 0; } memcpy(ec->key, key, keylen); } ec->keylen = keylen; if (cipher != NULL) ec->contentType = OBJ_nid2obj(NID_pkcs7_data); return 1; } int CMS_EncryptedData_set1_key(CMS_ContentInfo *cms, const EVP_CIPHER *ciph, const unsigned char *key, size_t keylen) { CMS_EncryptedContentInfo *ec; if (!key || !keylen) { ERR_raise(ERR_LIB_CMS, CMS_R_NO_KEY); return 0; } if (ciph) { cms->d.encryptedData = M_ASN1_new_of(CMS_EncryptedData); if (!cms->d.encryptedData) { ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); return 0; } cms->contentType = OBJ_nid2obj(NID_pkcs7_encrypted); cms->d.encryptedData->version = 0; } else if (OBJ_obj2nid(cms->contentType) != NID_pkcs7_encrypted) { ERR_raise(ERR_LIB_CMS, CMS_R_NOT_ENCRYPTED_DATA); return 0; } ec = cms->d.encryptedData->encryptedContentInfo; return ossl_cms_EncryptedContent_init(ec, ciph, key, keylen, ossl_cms_get0_cmsctx(cms)); } BIO *ossl_cms_EncryptedData_init_bio(const CMS_ContentInfo *cms) { CMS_EncryptedData *enc = cms->d.encryptedData; if (enc->encryptedContentInfo->cipher && enc->unprotectedAttrs) enc->version = 2; return ossl_cms_EncryptedContent_init_bio(enc->encryptedContentInfo, ossl_cms_get0_cmsctx(cms)); } diff --git a/crypto/openssl/crypto/cms/cms_err.c b/crypto/openssl/crypto/cms/cms_err.c index dcbea201c8e5..4bd6a0dc1bf1 100644 --- a/crypto/openssl/crypto/cms/cms_err.c +++ b/crypto/openssl/crypto/cms/cms_err.c @@ -1,178 +1,180 @@ /* * Generated by util/mkerr.pl DO NOT EDIT - * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ #include #include #include "crypto/cmserr.h" #ifndef OPENSSL_NO_CMS # ifndef OPENSSL_NO_ERR static const ERR_STRING_DATA CMS_str_reasons[] = { {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_ADD_SIGNER_ERROR), "add signer error"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_ATTRIBUTE_ERROR), "attribute error"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_CERTIFICATE_ALREADY_PRESENT), "certificate already present"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_CERTIFICATE_HAS_NO_KEYID), "certificate has no keyid"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_CERTIFICATE_VERIFY_ERROR), "certificate verify error"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_CIPHER_AEAD_SET_TAG_ERROR), "cipher aead set tag error"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_CIPHER_GET_TAG), "cipher get tag"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_CIPHER_INITIALISATION_ERROR), "cipher initialisation error"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR), "cipher parameter initialisation error"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_CMS_DATAFINAL_ERROR), "cms datafinal error"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_CMS_LIB), "cms lib"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_CONTENTIDENTIFIER_MISMATCH), "contentidentifier mismatch"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_CONTENT_NOT_FOUND), "content not found"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_CONTENT_TYPE_MISMATCH), "content type mismatch"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_CONTENT_TYPE_NOT_COMPRESSED_DATA), "content type not compressed data"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_CONTENT_TYPE_NOT_ENVELOPED_DATA), "content type not enveloped data"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_CONTENT_TYPE_NOT_SIGNED_DATA), "content type not signed data"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_CONTENT_VERIFY_ERROR), "content verify error"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_CTRL_ERROR), "ctrl error"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_CTRL_FAILURE), "ctrl failure"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_DECODE_ERROR), "decode error"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_DECRYPT_ERROR), "decrypt error"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_ERROR_GETTING_PUBLIC_KEY), "error getting public key"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_ERROR_READING_MESSAGEDIGEST_ATTRIBUTE), "error reading messagedigest attribute"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_ERROR_SETTING_KEY), "error setting key"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_ERROR_SETTING_RECIPIENTINFO), "error setting recipientinfo"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_ESS_SIGNING_CERTID_MISMATCH_ERROR), "ess signing certid mismatch error"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_INVALID_ENCRYPTED_KEY_LENGTH), "invalid encrypted key length"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_INVALID_KEY_ENCRYPTION_PARAMETER), "invalid key encryption parameter"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_INVALID_KEY_LENGTH), "invalid key length"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_INVALID_LABEL), "invalid label"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_INVALID_OAEP_PARAMETERS), "invalid oaep parameters"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_KDF_PARAMETER_ERROR), "kdf parameter error"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_MD_BIO_INIT_ERROR), "md bio init error"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_MESSAGEDIGEST_ATTRIBUTE_WRONG_LENGTH), "messagedigest attribute wrong length"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_MESSAGEDIGEST_WRONG_LENGTH), "messagedigest wrong length"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_MSGSIGDIGEST_ERROR), "msgsigdigest error"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_MSGSIGDIGEST_VERIFICATION_FAILURE), "msgsigdigest verification failure"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_MSGSIGDIGEST_WRONG_LENGTH), "msgsigdigest wrong length"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_NEED_ONE_SIGNER), "need one signer"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_NOT_A_SIGNED_RECEIPT), "not a signed receipt"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_NOT_ENCRYPTED_DATA), "not encrypted data"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_NOT_KEK), "not kek"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_NOT_KEY_AGREEMENT), "not key agreement"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_NOT_KEY_TRANSPORT), "not key transport"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_NOT_PWRI), "not pwri"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE), "not supported for this key type"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_NO_CIPHER), "no cipher"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_NO_CONTENT), "no content"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_NO_CONTENT_TYPE), "no content type"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_NO_DEFAULT_DIGEST), "no default digest"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_NO_DIGEST_SET), "no digest set"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_NO_KEY), "no key"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_NO_KEY_OR_CERT), "no key or cert"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_NO_MATCHING_DIGEST), "no matching digest"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_NO_MATCHING_RECIPIENT), "no matching recipient"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_NO_MATCHING_SIGNATURE), "no matching signature"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_NO_MSGSIGDIGEST), "no msgsigdigest"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_NO_PASSWORD), "no password"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_NO_PRIVATE_KEY), "no private key"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_NO_PUBLIC_KEY), "no public key"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_NO_RECEIPT_REQUEST), "no receipt request"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_NO_SIGNERS), "no signers"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_PEER_KEY_ERROR), "peer key error"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE), "private key does not match certificate"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_RECEIPT_DECODE_ERROR), "receipt decode error"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_RECIPIENT_ERROR), "recipient error"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_SHARED_INFO_ERROR), "shared info error"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_SIGNER_CERTIFICATE_NOT_FOUND), "signer certificate not found"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_SIGNFINAL_ERROR), "signfinal error"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_SMIME_TEXT_ERROR), "smime text error"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_STORE_INIT_ERROR), "store init error"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_TYPE_NOT_COMPRESSED_DATA), "type not compressed data"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_TYPE_NOT_DATA), "type not data"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_TYPE_NOT_DIGESTED_DATA), "type not digested data"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_TYPE_NOT_ENCRYPTED_DATA), "type not encrypted data"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_TYPE_NOT_ENVELOPED_DATA), "type not enveloped data"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_UNABLE_TO_FINALIZE_CONTEXT), "unable to finalize context"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_UNKNOWN_CIPHER), "unknown cipher"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_UNKNOWN_DIGEST_ALGORITHM), "unknown digest algorithm"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_UNKNOWN_ID), "unknown id"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM), "unsupported compression algorithm"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_UNSUPPORTED_CONTENT_ENCRYPTION_ALGORITHM), "unsupported content encryption algorithm"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_UNSUPPORTED_CONTENT_TYPE), "unsupported content type"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_UNSUPPORTED_ENCRYPTION_TYPE), "unsupported encryption type"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_UNSUPPORTED_KEK_ALGORITHM), "unsupported kek algorithm"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_UNSUPPORTED_KEY_ENCRYPTION_ALGORITHM), "unsupported key encryption algorithm"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_UNSUPPORTED_LABEL_SOURCE), "unsupported label source"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_UNSUPPORTED_RECIPIENTINFO_TYPE), "unsupported recipientinfo type"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_UNSUPPORTED_RECIPIENT_TYPE), "unsupported recipient type"}, + {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_UNSUPPORTED_SIGNATURE_ALGORITHM), + "unsupported signature algorithm"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_UNSUPPORTED_TYPE), "unsupported type"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_UNWRAP_ERROR), "unwrap error"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_UNWRAP_FAILURE), "unwrap failure"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_VERIFICATION_FAILURE), "verification failure"}, {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_WRAP_ERROR), "wrap error"}, {0, NULL} }; # endif int ossl_err_load_CMS_strings(void) { # ifndef OPENSSL_NO_ERR if (ERR_reason_error_string(CMS_str_reasons[0].error) == NULL) ERR_load_strings_const(CMS_str_reasons); # endif return 1; } #else NON_EMPTY_TRANSLATION_UNIT #endif diff --git a/crypto/openssl/crypto/cms/cms_sd.c b/crypto/openssl/crypto/cms/cms_sd.c index 53c8e378f318..2093657a2a4a 100644 --- a/crypto/openssl/crypto/cms/cms_sd.c +++ b/crypto/openssl/crypto/cms/cms_sd.c @@ -1,1091 +1,1099 @@ /* * Copyright 2008-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ #include "internal/cryptlib.h" #include #include #include #include #include #include #include #include "internal/sizes.h" #include "crypto/asn1.h" #include "crypto/evp.h" #include "crypto/ess.h" #include "crypto/x509.h" /* for ossl_x509_add_cert_new() */ #include "cms_local.h" /* CMS SignedData Utilities */ static CMS_SignedData *cms_get0_signed(CMS_ContentInfo *cms) { if (OBJ_obj2nid(cms->contentType) != NID_pkcs7_signed) { ERR_raise(ERR_LIB_CMS, CMS_R_CONTENT_TYPE_NOT_SIGNED_DATA); return NULL; } return cms->d.signedData; } static CMS_SignedData *cms_signed_data_init(CMS_ContentInfo *cms) { if (cms->d.other == NULL) { cms->d.signedData = M_ASN1_new_of(CMS_SignedData); if (!cms->d.signedData) { ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); return NULL; } cms->d.signedData->version = 1; cms->d.signedData->encapContentInfo->eContentType = OBJ_nid2obj(NID_pkcs7_data); cms->d.signedData->encapContentInfo->partial = 1; ASN1_OBJECT_free(cms->contentType); cms->contentType = OBJ_nid2obj(NID_pkcs7_signed); return cms->d.signedData; } return cms_get0_signed(cms); } /* Just initialise SignedData e.g. for certs only structure */ int CMS_SignedData_init(CMS_ContentInfo *cms) { if (cms_signed_data_init(cms)) return 1; else return 0; } /* Check structures and fixup version numbers (if necessary) */ static void cms_sd_set_version(CMS_SignedData *sd) { int i; CMS_CertificateChoices *cch; CMS_RevocationInfoChoice *rch; CMS_SignerInfo *si; for (i = 0; i < sk_CMS_CertificateChoices_num(sd->certificates); i++) { cch = sk_CMS_CertificateChoices_value(sd->certificates, i); if (cch->type == CMS_CERTCHOICE_OTHER) { if (sd->version < 5) sd->version = 5; } else if (cch->type == CMS_CERTCHOICE_V2ACERT) { if (sd->version < 4) sd->version = 4; } else if (cch->type == CMS_CERTCHOICE_V1ACERT) { if (sd->version < 3) sd->version = 3; } } for (i = 0; i < sk_CMS_RevocationInfoChoice_num(sd->crls); i++) { rch = sk_CMS_RevocationInfoChoice_value(sd->crls, i); if (rch->type == CMS_REVCHOICE_OTHER) { if (sd->version < 5) sd->version = 5; } } if ((OBJ_obj2nid(sd->encapContentInfo->eContentType) != NID_pkcs7_data) && (sd->version < 3)) sd->version = 3; for (i = 0; i < sk_CMS_SignerInfo_num(sd->signerInfos); i++) { si = sk_CMS_SignerInfo_value(sd->signerInfos, i); if (si->sid->type == CMS_SIGNERINFO_KEYIDENTIFIER) { if (si->version < 3) si->version = 3; if (sd->version < 3) sd->version = 3; } else if (si->version < 1) si->version = 1; } if (sd->version < 1) sd->version = 1; } /* * RFC 5652 Section 11.1 Content Type * The content-type attribute within signed-data MUST * 1) be present if there are signed attributes * 2) match the content type in the signed-data, * 3) be a signed attribute. * 4) not have more than one copy of the attribute. * * Note that since the CMS_SignerInfo_sign() always adds the "signing time" * attribute, the content type attribute MUST be added also. * Assumptions: This assumes that the attribute does not already exist. */ static int cms_set_si_contentType_attr(CMS_ContentInfo *cms, CMS_SignerInfo *si) { ASN1_OBJECT *ctype = cms->d.signedData->encapContentInfo->eContentType; /* Add the contentType attribute */ return CMS_signed_add1_attr_by_NID(si, NID_pkcs9_contentType, V_ASN1_OBJECT, ctype, -1) > 0; } /* Copy an existing messageDigest value */ static int cms_copy_messageDigest(CMS_ContentInfo *cms, CMS_SignerInfo *si) { STACK_OF(CMS_SignerInfo) *sinfos; CMS_SignerInfo *sitmp; int i; sinfos = CMS_get0_SignerInfos(cms); for (i = 0; i < sk_CMS_SignerInfo_num(sinfos); i++) { ASN1_OCTET_STRING *messageDigest; sitmp = sk_CMS_SignerInfo_value(sinfos, i); if (sitmp == si) continue; if (CMS_signed_get_attr_count(sitmp) < 0) continue; if (OBJ_cmp(si->digestAlgorithm->algorithm, sitmp->digestAlgorithm->algorithm)) continue; messageDigest = CMS_signed_get0_data_by_OBJ(sitmp, OBJ_nid2obj (NID_pkcs9_messageDigest), -3, V_ASN1_OCTET_STRING); if (!messageDigest) { ERR_raise(ERR_LIB_CMS, CMS_R_ERROR_READING_MESSAGEDIGEST_ATTRIBUTE); return 0; } if (CMS_signed_add1_attr_by_NID(si, NID_pkcs9_messageDigest, V_ASN1_OCTET_STRING, messageDigest, -1)) return 1; else return 0; } ERR_raise(ERR_LIB_CMS, CMS_R_NO_MATCHING_DIGEST); return 0; } int ossl_cms_set1_SignerIdentifier(CMS_SignerIdentifier *sid, X509 *cert, int type, const CMS_CTX *ctx) { switch (type) { case CMS_SIGNERINFO_ISSUER_SERIAL: if (!ossl_cms_set1_ias(&sid->d.issuerAndSerialNumber, cert)) return 0; break; case CMS_SIGNERINFO_KEYIDENTIFIER: if (!ossl_cms_set1_keyid(&sid->d.subjectKeyIdentifier, cert)) return 0; break; default: ERR_raise(ERR_LIB_CMS, CMS_R_UNKNOWN_ID); return 0; } sid->type = type; return 1; } int ossl_cms_SignerIdentifier_get0_signer_id(CMS_SignerIdentifier *sid, ASN1_OCTET_STRING **keyid, X509_NAME **issuer, ASN1_INTEGER **sno) { if (sid->type == CMS_SIGNERINFO_ISSUER_SERIAL) { if (issuer) *issuer = sid->d.issuerAndSerialNumber->issuer; if (sno) *sno = sid->d.issuerAndSerialNumber->serialNumber; } else if (sid->type == CMS_SIGNERINFO_KEYIDENTIFIER) { if (keyid) *keyid = sid->d.subjectKeyIdentifier; } else return 0; return 1; } int ossl_cms_SignerIdentifier_cert_cmp(CMS_SignerIdentifier *sid, X509 *cert) { if (sid->type == CMS_SIGNERINFO_ISSUER_SERIAL) return ossl_cms_ias_cert_cmp(sid->d.issuerAndSerialNumber, cert); else if (sid->type == CMS_SIGNERINFO_KEYIDENTIFIER) return ossl_cms_keyid_cert_cmp(sid->d.subjectKeyIdentifier, cert); else return -1; } static int cms_sd_asn1_ctrl(CMS_SignerInfo *si, int cmd) { EVP_PKEY *pkey = si->pkey; int i; if (EVP_PKEY_is_a(pkey, "DSA") || EVP_PKEY_is_a(pkey, "EC")) return ossl_cms_ecdsa_dsa_sign(si, cmd) > 0; else if (EVP_PKEY_is_a(pkey, "RSA") || EVP_PKEY_is_a(pkey, "RSA-PSS")) return ossl_cms_rsa_sign(si, cmd) > 0; /* Something else? We'll give engines etc a chance to handle this */ if (pkey->ameth == NULL || pkey->ameth->pkey_ctrl == NULL) return 1; i = pkey->ameth->pkey_ctrl(pkey, ASN1_PKEY_CTRL_CMS_SIGN, cmd, si); if (i == -2) { ERR_raise(ERR_LIB_CMS, CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE); return 0; } if (i <= 0) { ERR_raise(ERR_LIB_CMS, CMS_R_CTRL_FAILURE); return 0; } return 1; } /* Add SigningCertificate signed attribute to the signer info. */ static int ossl_cms_add1_signing_cert(CMS_SignerInfo *si, const ESS_SIGNING_CERT *sc) { ASN1_STRING *seq = NULL; unsigned char *p, *pp = NULL; int ret, len = i2d_ESS_SIGNING_CERT(sc, NULL); if (len <= 0 || (pp = OPENSSL_malloc(len)) == NULL) return 0; p = pp; i2d_ESS_SIGNING_CERT(sc, &p); if (!(seq = ASN1_STRING_new()) || !ASN1_STRING_set(seq, pp, len)) { ASN1_STRING_free(seq); OPENSSL_free(pp); return 0; } OPENSSL_free(pp); ret = CMS_signed_add1_attr_by_NID(si, NID_id_smime_aa_signingCertificate, V_ASN1_SEQUENCE, seq, -1); ASN1_STRING_free(seq); return ret; } /* Add SigningCertificateV2 signed attribute to the signer info. */ static int ossl_cms_add1_signing_cert_v2(CMS_SignerInfo *si, const ESS_SIGNING_CERT_V2 *sc) { ASN1_STRING *seq = NULL; unsigned char *p, *pp = NULL; int ret, len = i2d_ESS_SIGNING_CERT_V2(sc, NULL); if (len <= 0 || (pp = OPENSSL_malloc(len)) == NULL) return 0; p = pp; i2d_ESS_SIGNING_CERT_V2(sc, &p); if (!(seq = ASN1_STRING_new()) || !ASN1_STRING_set(seq, pp, len)) { ASN1_STRING_free(seq); OPENSSL_free(pp); return 0; } OPENSSL_free(pp); ret = CMS_signed_add1_attr_by_NID(si, NID_id_smime_aa_signingCertificateV2, V_ASN1_SEQUENCE, seq, -1); ASN1_STRING_free(seq); return ret; } CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms, X509 *signer, EVP_PKEY *pk, const EVP_MD *md, unsigned int flags) { CMS_SignedData *sd; CMS_SignerInfo *si = NULL; X509_ALGOR *alg; int i, type; const CMS_CTX *ctx = ossl_cms_get0_cmsctx(cms); if (!X509_check_private_key(signer, pk)) { ERR_raise(ERR_LIB_CMS, CMS_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE); return NULL; } sd = cms_signed_data_init(cms); if (!sd) goto err; si = M_ASN1_new_of(CMS_SignerInfo); if (!si) goto merr; /* Call for side-effect of computing hash and caching extensions */ X509_check_purpose(signer, -1, -1); X509_up_ref(signer); EVP_PKEY_up_ref(pk); si->cms_ctx = ctx; si->pkey = pk; si->signer = signer; si->mctx = EVP_MD_CTX_new(); si->pctx = NULL; if (si->mctx == NULL) { ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); goto err; } if (flags & CMS_USE_KEYID) { si->version = 3; if (sd->version < 3) sd->version = 3; type = CMS_SIGNERINFO_KEYIDENTIFIER; } else { type = CMS_SIGNERINFO_ISSUER_SERIAL; si->version = 1; } if (!ossl_cms_set1_SignerIdentifier(si->sid, signer, type, ctx)) goto err; if (md == NULL) { int def_nid; - if (EVP_PKEY_get_default_digest_nid(pk, &def_nid) <= 0) + + if (EVP_PKEY_get_default_digest_nid(pk, &def_nid) <= 0) { + ERR_raise_data(ERR_LIB_CMS, CMS_R_NO_DEFAULT_DIGEST, + "pkey nid=%d", EVP_PKEY_get_id(pk)); goto err; + } md = EVP_get_digestbynid(def_nid); if (md == NULL) { - ERR_raise(ERR_LIB_CMS, CMS_R_NO_DEFAULT_DIGEST); + ERR_raise_data(ERR_LIB_CMS, CMS_R_NO_DEFAULT_DIGEST, + "default md nid=%d", def_nid); goto err; } } if (!md) { ERR_raise(ERR_LIB_CMS, CMS_R_NO_DIGEST_SET); goto err; } if (md == NULL) { ERR_raise(ERR_LIB_CMS, CMS_R_NO_DIGEST_SET); goto err; } X509_ALGOR_set_md(si->digestAlgorithm, md); /* See if digest is present in digestAlgorithms */ for (i = 0; i < sk_X509_ALGOR_num(sd->digestAlgorithms); i++) { const ASN1_OBJECT *aoid; char name[OSSL_MAX_NAME_SIZE]; alg = sk_X509_ALGOR_value(sd->digestAlgorithms, i); X509_ALGOR_get0(&aoid, NULL, NULL, alg); OBJ_obj2txt(name, sizeof(name), aoid, 0); if (EVP_MD_is_a(md, name)) break; } if (i == sk_X509_ALGOR_num(sd->digestAlgorithms)) { alg = X509_ALGOR_new(); if (alg == NULL) goto merr; X509_ALGOR_set_md(alg, md); if (!sk_X509_ALGOR_push(sd->digestAlgorithms, alg)) { X509_ALGOR_free(alg); goto merr; } } - if (!(flags & CMS_KEY_PARAM) && !cms_sd_asn1_ctrl(si, 0)) + if (!(flags & CMS_KEY_PARAM) && !cms_sd_asn1_ctrl(si, 0)) { + ERR_raise_data(ERR_LIB_CMS, CMS_R_UNSUPPORTED_SIGNATURE_ALGORITHM, + "pkey nid=%d", EVP_PKEY_get_id(pk)); goto err; + } if (!(flags & CMS_NOATTR)) { /* * Initialize signed attributes structure so other attributes * such as signing time etc are added later even if we add none here. */ if (!si->signedAttrs) { si->signedAttrs = sk_X509_ATTRIBUTE_new_null(); if (!si->signedAttrs) goto merr; } if (!(flags & CMS_NOSMIMECAP)) { STACK_OF(X509_ALGOR) *smcap = NULL; i = CMS_add_standard_smimecap(&smcap); if (i) i = CMS_add_smimecap(si, smcap); sk_X509_ALGOR_pop_free(smcap, X509_ALGOR_free); if (!i) goto merr; } if (flags & CMS_CADES) { ESS_SIGNING_CERT *sc = NULL; ESS_SIGNING_CERT_V2 *sc2 = NULL; int add_sc; if (md == NULL || EVP_MD_is_a(md, SN_sha1)) { if ((sc = OSSL_ESS_signing_cert_new_init(signer, NULL, 1)) == NULL) goto err; add_sc = ossl_cms_add1_signing_cert(si, sc); ESS_SIGNING_CERT_free(sc); } else { if ((sc2 = OSSL_ESS_signing_cert_v2_new_init(md, signer, NULL, 1)) == NULL) goto err; add_sc = ossl_cms_add1_signing_cert_v2(si, sc2); ESS_SIGNING_CERT_V2_free(sc2); } if (!add_sc) goto err; } if (flags & CMS_REUSE_DIGEST) { if (!cms_copy_messageDigest(cms, si)) goto err; if (!cms_set_si_contentType_attr(cms, si)) goto err; if (!(flags & (CMS_PARTIAL | CMS_KEY_PARAM)) && !CMS_SignerInfo_sign(si)) goto err; } } if (!(flags & CMS_NOCERTS)) { /* NB ignore -1 return for duplicate cert */ if (!CMS_add1_cert(cms, signer)) goto merr; } if (flags & CMS_KEY_PARAM) { if (flags & CMS_NOATTR) { si->pctx = EVP_PKEY_CTX_new_from_pkey(ossl_cms_ctx_get0_libctx(ctx), si->pkey, ossl_cms_ctx_get0_propq(ctx)); if (si->pctx == NULL) goto err; if (EVP_PKEY_sign_init(si->pctx) <= 0) goto err; if (EVP_PKEY_CTX_set_signature_md(si->pctx, md) <= 0) goto err; } else if (EVP_DigestSignInit_ex(si->mctx, &si->pctx, EVP_MD_get0_name(md), ossl_cms_ctx_get0_libctx(ctx), ossl_cms_ctx_get0_propq(ctx), pk, NULL) <= 0) { goto err; } } if (!sd->signerInfos) sd->signerInfos = sk_CMS_SignerInfo_new_null(); if (!sd->signerInfos || !sk_CMS_SignerInfo_push(sd->signerInfos, si)) goto merr; return si; merr: ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); err: M_ASN1_free_of(si, CMS_SignerInfo); return NULL; } void ossl_cms_SignerInfos_set_cmsctx(CMS_ContentInfo *cms) { int i; CMS_SignerInfo *si; STACK_OF(CMS_SignerInfo) *sinfos; const CMS_CTX *ctx = ossl_cms_get0_cmsctx(cms); ERR_set_mark(); sinfos = CMS_get0_SignerInfos(cms); ERR_pop_to_mark(); /* removes error in case sinfos == NULL */ for (i = 0; i < sk_CMS_SignerInfo_num(sinfos); i++) { si = sk_CMS_SignerInfo_value(sinfos, i); if (si != NULL) si->cms_ctx = ctx; } } static int cms_add1_signingTime(CMS_SignerInfo *si, ASN1_TIME *t) { ASN1_TIME *tt; int r = 0; if (t != NULL) tt = t; else tt = X509_gmtime_adj(NULL, 0); if (tt == NULL) goto merr; if (CMS_signed_add1_attr_by_NID(si, NID_pkcs9_signingTime, tt->type, tt, -1) <= 0) goto merr; r = 1; merr: if (t == NULL) ASN1_TIME_free(tt); if (!r) ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); return r; } EVP_PKEY_CTX *CMS_SignerInfo_get0_pkey_ctx(CMS_SignerInfo *si) { return si->pctx; } EVP_MD_CTX *CMS_SignerInfo_get0_md_ctx(CMS_SignerInfo *si) { return si->mctx; } STACK_OF(CMS_SignerInfo) *CMS_get0_SignerInfos(CMS_ContentInfo *cms) { CMS_SignedData *sd = cms_get0_signed(cms); return sd != NULL ? sd->signerInfos : NULL; } STACK_OF(X509) *CMS_get0_signers(CMS_ContentInfo *cms) { STACK_OF(X509) *signers = NULL; STACK_OF(CMS_SignerInfo) *sinfos; CMS_SignerInfo *si; int i; sinfos = CMS_get0_SignerInfos(cms); for (i = 0; i < sk_CMS_SignerInfo_num(sinfos); i++) { si = sk_CMS_SignerInfo_value(sinfos, i); if (si->signer != NULL) { if (!ossl_x509_add_cert_new(&signers, si->signer, X509_ADD_FLAG_DEFAULT)) { sk_X509_free(signers); return NULL; } } } return signers; } void CMS_SignerInfo_set1_signer_cert(CMS_SignerInfo *si, X509 *signer) { if (signer != NULL) { X509_up_ref(signer); EVP_PKEY_free(si->pkey); si->pkey = X509_get_pubkey(signer); } X509_free(si->signer); si->signer = signer; } int CMS_SignerInfo_get0_signer_id(CMS_SignerInfo *si, ASN1_OCTET_STRING **keyid, X509_NAME **issuer, ASN1_INTEGER **sno) { return ossl_cms_SignerIdentifier_get0_signer_id(si->sid, keyid, issuer, sno); } int CMS_SignerInfo_cert_cmp(CMS_SignerInfo *si, X509 *cert) { return ossl_cms_SignerIdentifier_cert_cmp(si->sid, cert); } int CMS_set1_signers_certs(CMS_ContentInfo *cms, STACK_OF(X509) *scerts, unsigned int flags) { CMS_SignedData *sd; CMS_SignerInfo *si; CMS_CertificateChoices *cch; STACK_OF(CMS_CertificateChoices) *certs; X509 *x; int i, j; int ret = 0; sd = cms_get0_signed(cms); if (sd == NULL) return -1; certs = sd->certificates; for (i = 0; i < sk_CMS_SignerInfo_num(sd->signerInfos); i++) { si = sk_CMS_SignerInfo_value(sd->signerInfos, i); if (si->signer != NULL) continue; for (j = 0; j < sk_X509_num(scerts); j++) { x = sk_X509_value(scerts, j); if (CMS_SignerInfo_cert_cmp(si, x) == 0) { CMS_SignerInfo_set1_signer_cert(si, x); ret++; break; } } if (si->signer != NULL || (flags & CMS_NOINTERN)) continue; for (j = 0; j < sk_CMS_CertificateChoices_num(certs); j++) { cch = sk_CMS_CertificateChoices_value(certs, j); if (cch->type != 0) continue; x = cch->d.certificate; if (CMS_SignerInfo_cert_cmp(si, x) == 0) { CMS_SignerInfo_set1_signer_cert(si, x); ret++; break; } } } return ret; } void CMS_SignerInfo_get0_algs(CMS_SignerInfo *si, EVP_PKEY **pk, X509 **signer, X509_ALGOR **pdig, X509_ALGOR **psig) { if (pk != NULL) *pk = si->pkey; if (signer != NULL) *signer = si->signer; if (pdig != NULL) *pdig = si->digestAlgorithm; if (psig != NULL) *psig = si->signatureAlgorithm; } ASN1_OCTET_STRING *CMS_SignerInfo_get0_signature(CMS_SignerInfo *si) { return si->signature; } static int cms_SignerInfo_content_sign(CMS_ContentInfo *cms, CMS_SignerInfo *si, BIO *chain) { EVP_MD_CTX *mctx = EVP_MD_CTX_new(); int r = 0; EVP_PKEY_CTX *pctx = NULL; const CMS_CTX *ctx = ossl_cms_get0_cmsctx(cms); if (mctx == NULL) { ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); return 0; } if (si->pkey == NULL) { ERR_raise(ERR_LIB_CMS, CMS_R_NO_PRIVATE_KEY); goto err; } if (!ossl_cms_DigestAlgorithm_find_ctx(mctx, chain, si->digestAlgorithm)) goto err; /* Set SignerInfo algorithm details if we used custom parameter */ if (si->pctx && !cms_sd_asn1_ctrl(si, 0)) goto err; /* * If any signed attributes calculate and add messageDigest attribute */ if (CMS_signed_get_attr_count(si) >= 0) { unsigned char md[EVP_MAX_MD_SIZE]; unsigned int mdlen; if (!EVP_DigestFinal_ex(mctx, md, &mdlen)) goto err; if (!CMS_signed_add1_attr_by_NID(si, NID_pkcs9_messageDigest, V_ASN1_OCTET_STRING, md, mdlen)) goto err; /* Copy content type across */ if (!cms_set_si_contentType_attr(cms, si)) goto err; if (!CMS_SignerInfo_sign(si)) goto err; } else if (si->pctx) { unsigned char *sig; size_t siglen; unsigned char md[EVP_MAX_MD_SIZE]; unsigned int mdlen; pctx = si->pctx; if (!EVP_DigestFinal_ex(mctx, md, &mdlen)) goto err; siglen = EVP_PKEY_get_size(si->pkey); sig = OPENSSL_malloc(siglen); if (sig == NULL) { ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); goto err; } if (EVP_PKEY_sign(pctx, sig, &siglen, md, mdlen) <= 0) { OPENSSL_free(sig); goto err; } ASN1_STRING_set0(si->signature, sig, siglen); } else { unsigned char *sig; unsigned int siglen; sig = OPENSSL_malloc(EVP_PKEY_get_size(si->pkey)); if (sig == NULL) { ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); goto err; } if (!EVP_SignFinal_ex(mctx, sig, &siglen, si->pkey, ossl_cms_ctx_get0_libctx(ctx), ossl_cms_ctx_get0_propq(ctx))) { ERR_raise(ERR_LIB_CMS, CMS_R_SIGNFINAL_ERROR); OPENSSL_free(sig); goto err; } ASN1_STRING_set0(si->signature, sig, siglen); } r = 1; err: EVP_MD_CTX_free(mctx); EVP_PKEY_CTX_free(pctx); return r; } int ossl_cms_SignedData_final(CMS_ContentInfo *cms, BIO *chain) { STACK_OF(CMS_SignerInfo) *sinfos; CMS_SignerInfo *si; int i; sinfos = CMS_get0_SignerInfos(cms); for (i = 0; i < sk_CMS_SignerInfo_num(sinfos); i++) { si = sk_CMS_SignerInfo_value(sinfos, i); if (!cms_SignerInfo_content_sign(cms, si, chain)) return 0; } cms->d.signedData->encapContentInfo->partial = 0; return 1; } int CMS_SignerInfo_sign(CMS_SignerInfo *si) { EVP_MD_CTX *mctx = si->mctx; EVP_PKEY_CTX *pctx = NULL; unsigned char *abuf = NULL; int alen; size_t siglen; const CMS_CTX *ctx = si->cms_ctx; char md_name[OSSL_MAX_NAME_SIZE]; if (OBJ_obj2txt(md_name, sizeof(md_name), si->digestAlgorithm->algorithm, 0) <= 0) return 0; if (CMS_signed_get_attr_by_NID(si, NID_pkcs9_signingTime, -1) < 0) { if (!cms_add1_signingTime(si, NULL)) goto err; } if (!ossl_cms_si_check_attributes(si)) goto err; if (si->pctx) pctx = si->pctx; else { EVP_MD_CTX_reset(mctx); if (EVP_DigestSignInit_ex(mctx, &pctx, md_name, ossl_cms_ctx_get0_libctx(ctx), ossl_cms_ctx_get0_propq(ctx), si->pkey, NULL) <= 0) goto err; si->pctx = pctx; } alen = ASN1_item_i2d((ASN1_VALUE *)si->signedAttrs, &abuf, ASN1_ITEM_rptr(CMS_Attributes_Sign)); if (!abuf) goto err; if (EVP_DigestSignUpdate(mctx, abuf, alen) <= 0) goto err; if (EVP_DigestSignFinal(mctx, NULL, &siglen) <= 0) goto err; OPENSSL_free(abuf); abuf = OPENSSL_malloc(siglen); if (abuf == NULL) goto err; if (EVP_DigestSignFinal(mctx, abuf, &siglen) <= 0) goto err; EVP_MD_CTX_reset(mctx); ASN1_STRING_set0(si->signature, abuf, siglen); return 1; err: OPENSSL_free(abuf); EVP_MD_CTX_reset(mctx); return 0; } int CMS_SignerInfo_verify(CMS_SignerInfo *si) { EVP_MD_CTX *mctx = NULL; unsigned char *abuf = NULL; int alen, r = -1; char name[OSSL_MAX_NAME_SIZE]; const EVP_MD *md; EVP_MD *fetched_md = NULL; const CMS_CTX *ctx = si->cms_ctx; OSSL_LIB_CTX *libctx = ossl_cms_ctx_get0_libctx(ctx); const char *propq = ossl_cms_ctx_get0_propq(ctx); if (si->pkey == NULL) { ERR_raise(ERR_LIB_CMS, CMS_R_NO_PUBLIC_KEY); return -1; } if (!ossl_cms_si_check_attributes(si)) return -1; OBJ_obj2txt(name, sizeof(name), si->digestAlgorithm->algorithm, 0); (void)ERR_set_mark(); fetched_md = EVP_MD_fetch(libctx, name, propq); if (fetched_md != NULL) md = fetched_md; else md = EVP_get_digestbyobj(si->digestAlgorithm->algorithm); if (md == NULL) { (void)ERR_clear_last_mark(); ERR_raise(ERR_LIB_CMS, CMS_R_UNKNOWN_DIGEST_ALGORITHM); return -1; } (void)ERR_pop_to_mark(); if (si->mctx == NULL && (si->mctx = EVP_MD_CTX_new()) == NULL) { ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); goto err; } mctx = si->mctx; if (EVP_DigestVerifyInit_ex(mctx, &si->pctx, EVP_MD_get0_name(md), libctx, propq, si->pkey, NULL) <= 0) goto err; if (!cms_sd_asn1_ctrl(si, 1)) goto err; alen = ASN1_item_i2d((ASN1_VALUE *)si->signedAttrs, &abuf, ASN1_ITEM_rptr(CMS_Attributes_Verify)); if (abuf == NULL || alen < 0) goto err; r = EVP_DigestVerifyUpdate(mctx, abuf, alen); OPENSSL_free(abuf); if (r <= 0) { r = -1; goto err; } r = EVP_DigestVerifyFinal(mctx, si->signature->data, si->signature->length); if (r <= 0) ERR_raise(ERR_LIB_CMS, CMS_R_VERIFICATION_FAILURE); err: EVP_MD_free(fetched_md); EVP_MD_CTX_reset(mctx); return r; } /* Create a chain of digest BIOs from a CMS ContentInfo */ BIO *ossl_cms_SignedData_init_bio(CMS_ContentInfo *cms) { int i; CMS_SignedData *sd; BIO *chain = NULL; sd = cms_get0_signed(cms); if (sd == NULL) return NULL; if (cms->d.signedData->encapContentInfo->partial) cms_sd_set_version(sd); for (i = 0; i < sk_X509_ALGOR_num(sd->digestAlgorithms); i++) { X509_ALGOR *digestAlgorithm; BIO *mdbio; digestAlgorithm = sk_X509_ALGOR_value(sd->digestAlgorithms, i); mdbio = ossl_cms_DigestAlgorithm_init_bio(digestAlgorithm, ossl_cms_get0_cmsctx(cms)); if (mdbio == NULL) goto err; if (chain != NULL) BIO_push(chain, mdbio); else chain = mdbio; } return chain; err: BIO_free_all(chain); return NULL; } int CMS_SignerInfo_verify_content(CMS_SignerInfo *si, BIO *chain) { ASN1_OCTET_STRING *os = NULL; EVP_MD_CTX *mctx = EVP_MD_CTX_new(); EVP_PKEY_CTX *pkctx = NULL; int r = -1; unsigned char mval[EVP_MAX_MD_SIZE]; unsigned int mlen; if (mctx == NULL) { ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); goto err; } /* If we have any signed attributes look for messageDigest value */ if (CMS_signed_get_attr_count(si) >= 0) { os = CMS_signed_get0_data_by_OBJ(si, OBJ_nid2obj(NID_pkcs9_messageDigest), -3, V_ASN1_OCTET_STRING); if (os == NULL) { ERR_raise(ERR_LIB_CMS, CMS_R_ERROR_READING_MESSAGEDIGEST_ATTRIBUTE); goto err; } } if (!ossl_cms_DigestAlgorithm_find_ctx(mctx, chain, si->digestAlgorithm)) goto err; if (EVP_DigestFinal_ex(mctx, mval, &mlen) <= 0) { ERR_raise(ERR_LIB_CMS, CMS_R_UNABLE_TO_FINALIZE_CONTEXT); goto err; } /* If messageDigest found compare it */ if (os != NULL) { if (mlen != (unsigned int)os->length) { ERR_raise(ERR_LIB_CMS, CMS_R_MESSAGEDIGEST_ATTRIBUTE_WRONG_LENGTH); goto err; } if (memcmp(mval, os->data, mlen)) { ERR_raise(ERR_LIB_CMS, CMS_R_VERIFICATION_FAILURE); r = 0; } else r = 1; } else { const EVP_MD *md = EVP_MD_CTX_get0_md(mctx); const CMS_CTX *ctx = si->cms_ctx; pkctx = EVP_PKEY_CTX_new_from_pkey(ossl_cms_ctx_get0_libctx(ctx), si->pkey, ossl_cms_ctx_get0_propq(ctx)); if (pkctx == NULL) goto err; if (EVP_PKEY_verify_init(pkctx) <= 0) goto err; if (EVP_PKEY_CTX_set_signature_md(pkctx, md) <= 0) goto err; si->pctx = pkctx; if (!cms_sd_asn1_ctrl(si, 1)) goto err; r = EVP_PKEY_verify(pkctx, si->signature->data, si->signature->length, mval, mlen); if (r <= 0) { ERR_raise(ERR_LIB_CMS, CMS_R_VERIFICATION_FAILURE); r = 0; } } err: EVP_PKEY_CTX_free(pkctx); EVP_MD_CTX_free(mctx); return r; } int CMS_add_smimecap(CMS_SignerInfo *si, STACK_OF(X509_ALGOR) *algs) { unsigned char *smder = NULL; int smderlen, r; smderlen = i2d_X509_ALGORS(algs, &smder); if (smderlen <= 0) return 0; r = CMS_signed_add1_attr_by_NID(si, NID_SMIMECapabilities, V_ASN1_SEQUENCE, smder, smderlen); OPENSSL_free(smder); return r; } int CMS_add_simple_smimecap(STACK_OF(X509_ALGOR) **algs, int algnid, int keysize) { X509_ALGOR *alg; ASN1_INTEGER *key = NULL; if (keysize > 0) { key = ASN1_INTEGER_new(); if (key == NULL || !ASN1_INTEGER_set(key, keysize)) { ASN1_INTEGER_free(key); return 0; } } alg = X509_ALGOR_new(); if (alg == NULL) { ASN1_INTEGER_free(key); return 0; } X509_ALGOR_set0(alg, OBJ_nid2obj(algnid), key ? V_ASN1_INTEGER : V_ASN1_UNDEF, key); if (*algs == NULL) *algs = sk_X509_ALGOR_new_null(); if (*algs == NULL || !sk_X509_ALGOR_push(*algs, alg)) { X509_ALGOR_free(alg); return 0; } return 1; } /* Check to see if a cipher exists and if so add S/MIME capabilities */ static int cms_add_cipher_smcap(STACK_OF(X509_ALGOR) **sk, int nid, int arg) { if (EVP_get_cipherbynid(nid)) return CMS_add_simple_smimecap(sk, nid, arg); return 1; } static int cms_add_digest_smcap(STACK_OF(X509_ALGOR) **sk, int nid, int arg) { if (EVP_get_digestbynid(nid)) return CMS_add_simple_smimecap(sk, nid, arg); return 1; } int CMS_add_standard_smimecap(STACK_OF(X509_ALGOR) **smcap) { if (!cms_add_cipher_smcap(smcap, NID_aes_256_cbc, -1) || !cms_add_digest_smcap(smcap, NID_id_GostR3411_2012_256, -1) || !cms_add_digest_smcap(smcap, NID_id_GostR3411_2012_512, -1) || !cms_add_digest_smcap(smcap, NID_id_GostR3411_94, -1) || !cms_add_cipher_smcap(smcap, NID_id_Gost28147_89, -1) || !cms_add_cipher_smcap(smcap, NID_aes_192_cbc, -1) || !cms_add_cipher_smcap(smcap, NID_aes_128_cbc, -1) || !cms_add_cipher_smcap(smcap, NID_des_ede3_cbc, -1) || !cms_add_cipher_smcap(smcap, NID_rc2_cbc, 128) || !cms_add_cipher_smcap(smcap, NID_rc2_cbc, 64) || !cms_add_cipher_smcap(smcap, NID_des_cbc, -1) || !cms_add_cipher_smcap(smcap, NID_rc2_cbc, 40)) return 0; return 1; } diff --git a/crypto/openssl/crypto/dh/dh_check.c b/crypto/openssl/crypto/dh/dh_check.c index f4173e21371e..7ba2beae7fd6 100644 --- a/crypto/openssl/crypto/dh/dh_check.c +++ b/crypto/openssl/crypto/dh/dh_check.c @@ -1,347 +1,348 @@ /* * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ /* * DH low level APIs are deprecated for public use, but still ok for * internal use. */ #include "internal/deprecated.h" #include #include "internal/cryptlib.h" #include #include "dh_local.h" #include "crypto/dh.h" /*- * Check that p and g are suitable enough * * p is odd * 1 < g < p - 1 */ int DH_check_params_ex(const DH *dh) { int errflags = 0; if (!DH_check_params(dh, &errflags)) return 0; if ((errflags & DH_CHECK_P_NOT_PRIME) != 0) ERR_raise(ERR_LIB_DH, DH_R_CHECK_P_NOT_PRIME); if ((errflags & DH_NOT_SUITABLE_GENERATOR) != 0) ERR_raise(ERR_LIB_DH, DH_R_NOT_SUITABLE_GENERATOR); if ((errflags & DH_MODULUS_TOO_SMALL) != 0) ERR_raise(ERR_LIB_DH, DH_R_MODULUS_TOO_SMALL); if ((errflags & DH_MODULUS_TOO_LARGE) != 0) ERR_raise(ERR_LIB_DH, DH_R_MODULUS_TOO_LARGE); return errflags == 0; } #ifdef FIPS_MODULE int DH_check_params(const DH *dh, int *ret) { int nid; *ret = 0; /* * SP800-56A R3 Section 5.5.2 Assurances of Domain Parameter Validity * (1a) The domain parameters correspond to any approved safe prime group. */ nid = DH_get_nid((DH *)dh); if (nid != NID_undef) return 1; /* * OR * (2b) FFC domain params conform to FIPS-186-4 explicit domain param * validity tests. */ return ossl_ffc_params_FIPS186_4_validate(dh->libctx, &dh->params, FFC_PARAM_TYPE_DH, ret, NULL); } #else int DH_check_params(const DH *dh, int *ret) { int ok = 0; BIGNUM *tmp = NULL; BN_CTX *ctx = NULL; *ret = 0; ctx = BN_CTX_new_ex(dh->libctx); if (ctx == NULL) goto err; BN_CTX_start(ctx); tmp = BN_CTX_get(ctx); if (tmp == NULL) goto err; if (!BN_is_odd(dh->params.p)) *ret |= DH_CHECK_P_NOT_PRIME; if (BN_is_negative(dh->params.g) || BN_is_zero(dh->params.g) || BN_is_one(dh->params.g)) *ret |= DH_NOT_SUITABLE_GENERATOR; if (BN_copy(tmp, dh->params.p) == NULL || !BN_sub_word(tmp, 1)) goto err; if (BN_cmp(dh->params.g, tmp) >= 0) *ret |= DH_NOT_SUITABLE_GENERATOR; if (BN_num_bits(dh->params.p) < DH_MIN_MODULUS_BITS) *ret |= DH_MODULUS_TOO_SMALL; if (BN_num_bits(dh->params.p) > OPENSSL_DH_MAX_MODULUS_BITS) *ret |= DH_MODULUS_TOO_LARGE; ok = 1; err: BN_CTX_end(ctx); BN_CTX_free(ctx); return ok; } #endif /* FIPS_MODULE */ /*- * Check that p is a safe prime and * g is a suitable generator. */ int DH_check_ex(const DH *dh) { int errflags = 0; if (!DH_check(dh, &errflags)) return 0; if ((errflags & DH_NOT_SUITABLE_GENERATOR) != 0) ERR_raise(ERR_LIB_DH, DH_R_NOT_SUITABLE_GENERATOR); if ((errflags & DH_CHECK_Q_NOT_PRIME) != 0) ERR_raise(ERR_LIB_DH, DH_R_CHECK_Q_NOT_PRIME); if ((errflags & DH_CHECK_INVALID_Q_VALUE) != 0) ERR_raise(ERR_LIB_DH, DH_R_CHECK_INVALID_Q_VALUE); if ((errflags & DH_CHECK_INVALID_J_VALUE) != 0) ERR_raise(ERR_LIB_DH, DH_R_CHECK_INVALID_J_VALUE); if ((errflags & DH_UNABLE_TO_CHECK_GENERATOR) != 0) ERR_raise(ERR_LIB_DH, DH_R_UNABLE_TO_CHECK_GENERATOR); if ((errflags & DH_CHECK_P_NOT_PRIME) != 0) ERR_raise(ERR_LIB_DH, DH_R_CHECK_P_NOT_PRIME); if ((errflags & DH_CHECK_P_NOT_SAFE_PRIME) != 0) ERR_raise(ERR_LIB_DH, DH_R_CHECK_P_NOT_SAFE_PRIME); if ((errflags & DH_MODULUS_TOO_SMALL) != 0) ERR_raise(ERR_LIB_DH, DH_R_MODULUS_TOO_SMALL); if ((errflags & DH_MODULUS_TOO_LARGE) != 0) ERR_raise(ERR_LIB_DH, DH_R_MODULUS_TOO_LARGE); return errflags == 0; } /* Note: according to documentation - this only checks the params */ int DH_check(const DH *dh, int *ret) { #ifdef FIPS_MODULE return DH_check_params(dh, ret); #else int ok = 0, r, q_good = 0; BN_CTX *ctx = NULL; BIGNUM *t1 = NULL, *t2 = NULL; int nid = DH_get_nid((DH *)dh); *ret = 0; if (nid != NID_undef) return 1; /* Don't do any checks at all with an excessively large modulus */ if (BN_num_bits(dh->params.p) > OPENSSL_DH_CHECK_MAX_MODULUS_BITS) { ERR_raise(ERR_LIB_DH, DH_R_MODULUS_TOO_LARGE); *ret = DH_MODULUS_TOO_LARGE | DH_CHECK_P_NOT_PRIME; return 0; } if (!DH_check_params(dh, ret)) return 0; ctx = BN_CTX_new_ex(dh->libctx); if (ctx == NULL) goto err; BN_CTX_start(ctx); t1 = BN_CTX_get(ctx); t2 = BN_CTX_get(ctx); if (t2 == NULL) goto err; if (dh->params.q != NULL) { if (BN_ucmp(dh->params.p, dh->params.q) > 0) q_good = 1; else *ret |= DH_CHECK_INVALID_Q_VALUE; } if (q_good) { if (BN_cmp(dh->params.g, BN_value_one()) <= 0) *ret |= DH_NOT_SUITABLE_GENERATOR; else if (BN_cmp(dh->params.g, dh->params.p) >= 0) *ret |= DH_NOT_SUITABLE_GENERATOR; else { /* Check g^q == 1 mod p */ if (!BN_mod_exp(t1, dh->params.g, dh->params.q, dh->params.p, ctx)) goto err; if (!BN_is_one(t1)) *ret |= DH_NOT_SUITABLE_GENERATOR; } r = BN_check_prime(dh->params.q, ctx, NULL); if (r < 0) goto err; if (!r) *ret |= DH_CHECK_Q_NOT_PRIME; /* Check p == 1 mod q i.e. q divides p - 1 */ if (!BN_div(t1, t2, dh->params.p, dh->params.q, ctx)) goto err; if (!BN_is_one(t2)) *ret |= DH_CHECK_INVALID_Q_VALUE; if (dh->params.j != NULL && BN_cmp(dh->params.j, t1)) *ret |= DH_CHECK_INVALID_J_VALUE; } r = BN_check_prime(dh->params.p, ctx, NULL); if (r < 0) goto err; if (!r) *ret |= DH_CHECK_P_NOT_PRIME; else if (dh->params.q == NULL) { if (!BN_rshift1(t1, dh->params.p)) goto err; r = BN_check_prime(t1, ctx, NULL); if (r < 0) goto err; if (!r) *ret |= DH_CHECK_P_NOT_SAFE_PRIME; } ok = 1; err: BN_CTX_end(ctx); BN_CTX_free(ctx); return ok; #endif /* FIPS_MODULE */ } int DH_check_pub_key_ex(const DH *dh, const BIGNUM *pub_key) { int errflags = 0; if (!DH_check_pub_key(dh, pub_key, &errflags)) return 0; if ((errflags & DH_CHECK_PUBKEY_TOO_SMALL) != 0) ERR_raise(ERR_LIB_DH, DH_R_CHECK_PUBKEY_TOO_SMALL); if ((errflags & DH_CHECK_PUBKEY_TOO_LARGE) != 0) ERR_raise(ERR_LIB_DH, DH_R_CHECK_PUBKEY_TOO_LARGE); if ((errflags & DH_CHECK_PUBKEY_INVALID) != 0) ERR_raise(ERR_LIB_DH, DH_R_CHECK_PUBKEY_INVALID); return errflags == 0; } /* * See SP800-56Ar3 Section 5.6.2.3.1 : FFC Full public key validation. */ int DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *ret) { return ossl_ffc_validate_public_key(&dh->params, pub_key, ret); } /* * See SP800-56Ar3 Section 5.6.2.3.1 : FFC Partial public key validation. * To only be used with ephemeral FFC public keys generated using the approved * safe-prime groups. */ int ossl_dh_check_pub_key_partial(const DH *dh, const BIGNUM *pub_key, int *ret) { - return ossl_ffc_validate_public_key_partial(&dh->params, pub_key, ret); + return ossl_ffc_validate_public_key_partial(&dh->params, pub_key, ret) + && *ret == 0; } int ossl_dh_check_priv_key(const DH *dh, const BIGNUM *priv_key, int *ret) { int ok = 0; BIGNUM *two_powN = NULL, *upper; *ret = 0; two_powN = BN_new(); if (two_powN == NULL) return 0; if (dh->params.q != NULL) { upper = dh->params.q; #ifndef FIPS_MODULE } else if (dh->params.p != NULL) { /* * We do not have q so we just check the key is within some * reasonable range, or the number of bits is equal to dh->length. */ int length = dh->length; if (length == 0) { length = BN_num_bits(dh->params.p) - 1; if (BN_num_bits(priv_key) <= length && BN_num_bits(priv_key) > 1) ok = 1; } else if (BN_num_bits(priv_key) == length) { ok = 1; } goto end; #endif } else { goto end; } /* Is it from an approved Safe prime group ?*/ if (DH_get_nid((DH *)dh) != NID_undef && dh->length != 0) { if (!BN_lshift(two_powN, BN_value_one(), dh->length)) goto end; if (BN_cmp(two_powN, dh->params.q) < 0) upper = two_powN; } if (!ossl_ffc_validate_private_key(upper, priv_key, ret)) goto end; ok = 1; end: BN_free(two_powN); return ok; } /* * FFC pairwise check from SP800-56A R3. * Section 5.6.2.1.4 Owner Assurance of Pair-wise Consistency */ int ossl_dh_check_pairwise(const DH *dh) { int ret = 0; BN_CTX *ctx = NULL; BIGNUM *pub_key = NULL; if (dh->params.p == NULL || dh->params.g == NULL || dh->priv_key == NULL || dh->pub_key == NULL) return 0; ctx = BN_CTX_new_ex(dh->libctx); if (ctx == NULL) goto err; pub_key = BN_new(); if (pub_key == NULL) goto err; /* recalculate the public key = (g ^ priv) mod p */ if (!ossl_dh_generate_public_key(ctx, dh, dh->priv_key, pub_key)) goto err; /* check it matches the existing pubic_key */ ret = BN_cmp(pub_key, dh->pub_key) == 0; err: BN_free(pub_key); BN_CTX_free(ctx); return ret; } diff --git a/crypto/openssl/crypto/dh/dh_key.c b/crypto/openssl/crypto/dh/dh_key.c index 4e9705beef73..d84ea99241b9 100644 --- a/crypto/openssl/crypto/dh/dh_key.c +++ b/crypto/openssl/crypto/dh/dh_key.c @@ -1,442 +1,441 @@ /* - * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ /* * DH low level APIs are deprecated for public use, but still ok for * internal use. */ #include "internal/deprecated.h" #include #include "internal/cryptlib.h" #include "dh_local.h" #include "crypto/bn.h" #include "crypto/dh.h" #include "crypto/security_bits.h" #ifdef FIPS_MODULE # define MIN_STRENGTH 112 #else # define MIN_STRENGTH 80 #endif static int generate_key(DH *dh); static int dh_bn_mod_exp(const DH *dh, BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); static int dh_init(DH *dh); static int dh_finish(DH *dh); /* * See SP800-56Ar3 Section 5.7.1.1 * Finite Field Cryptography Diffie-Hellman (FFC DH) Primitive */ int ossl_dh_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) { BN_CTX *ctx = NULL; BN_MONT_CTX *mont = NULL; BIGNUM *z = NULL, *pminus1; int ret = -1; if (BN_num_bits(dh->params.p) > OPENSSL_DH_MAX_MODULUS_BITS) { ERR_raise(ERR_LIB_DH, DH_R_MODULUS_TOO_LARGE); goto err; } if (BN_num_bits(dh->params.p) < DH_MIN_MODULUS_BITS) { ERR_raise(ERR_LIB_DH, DH_R_MODULUS_TOO_SMALL); return 0; } ctx = BN_CTX_new_ex(dh->libctx); if (ctx == NULL) goto err; BN_CTX_start(ctx); pminus1 = BN_CTX_get(ctx); z = BN_CTX_get(ctx); if (z == NULL) goto err; if (dh->priv_key == NULL) { ERR_raise(ERR_LIB_DH, DH_R_NO_PRIVATE_VALUE); goto err; } if (dh->flags & DH_FLAG_CACHE_MONT_P) { mont = BN_MONT_CTX_set_locked(&dh->method_mont_p, dh->lock, dh->params.p, ctx); BN_set_flags(dh->priv_key, BN_FLG_CONSTTIME); if (!mont) goto err; } /* (Step 1) Z = pub_key^priv_key mod p */ if (!dh->meth->bn_mod_exp(dh, z, pub_key, dh->priv_key, dh->params.p, ctx, mont)) { ERR_raise(ERR_LIB_DH, ERR_R_BN_LIB); goto err; } /* (Step 2) Error if z <= 1 or z = p - 1 */ if (BN_copy(pminus1, dh->params.p) == NULL || !BN_sub_word(pminus1, 1) || BN_cmp(z, BN_value_one()) <= 0 || BN_cmp(z, pminus1) == 0) { ERR_raise(ERR_LIB_DH, DH_R_INVALID_SECRET); goto err; } /* return the padded key, i.e. same number of bytes as the modulus */ ret = BN_bn2binpad(z, key, BN_num_bytes(dh->params.p)); err: BN_clear(z); /* (Step 2) destroy intermediate values */ BN_CTX_end(ctx); BN_CTX_free(ctx); return ret; } /*- * NB: This function is inherently not constant time due to the * RFC 5246 (8.1.2) padding style that strips leading zero bytes. */ int DH_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) { int ret = 0, i; volatile size_t npad = 0, mask = 1; /* compute the key; ret is constant unless compute_key is external */ #ifdef FIPS_MODULE ret = ossl_dh_compute_key(key, pub_key, dh); #else ret = dh->meth->compute_key(key, pub_key, dh); #endif if (ret <= 0) return ret; /* count leading zero bytes, yet still touch all bytes */ for (i = 0; i < ret; i++) { mask &= !key[i]; npad += mask; } /* unpad key */ ret -= npad; /* key-dependent memory access, potentially leaking npad / ret */ memmove(key, key + npad, ret); /* key-dependent memory access, potentially leaking npad / ret */ memset(key + ret, 0, npad); return ret; } int DH_compute_key_padded(unsigned char *key, const BIGNUM *pub_key, DH *dh) { int rv, pad; /* rv is constant unless compute_key is external */ #ifdef FIPS_MODULE rv = ossl_dh_compute_key(key, pub_key, dh); #else rv = dh->meth->compute_key(key, pub_key, dh); #endif if (rv <= 0) return rv; pad = BN_num_bytes(dh->params.p) - rv; /* pad is constant (zero) unless compute_key is external */ if (pad > 0) { memmove(key + pad, key, rv); memset(key, 0, pad); } return rv + pad; } static DH_METHOD dh_ossl = { "OpenSSL DH Method", generate_key, ossl_dh_compute_key, dh_bn_mod_exp, dh_init, dh_finish, DH_FLAG_FIPS_METHOD, NULL, NULL }; static const DH_METHOD *default_DH_method = &dh_ossl; const DH_METHOD *DH_OpenSSL(void) { return &dh_ossl; } const DH_METHOD *DH_get_default_method(void) { return default_DH_method; } static int dh_bn_mod_exp(const DH *dh, BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) { return BN_mod_exp_mont(r, a, p, m, ctx, m_ctx); } static int dh_init(DH *dh) { dh->flags |= DH_FLAG_CACHE_MONT_P; - ossl_ffc_params_init(&dh->params); dh->dirty_cnt++; return 1; } static int dh_finish(DH *dh) { BN_MONT_CTX_free(dh->method_mont_p); return 1; } #ifndef FIPS_MODULE void DH_set_default_method(const DH_METHOD *meth) { default_DH_method = meth; } #endif /* FIPS_MODULE */ int DH_generate_key(DH *dh) { #ifdef FIPS_MODULE return generate_key(dh); #else return dh->meth->generate_key(dh); #endif } int ossl_dh_generate_public_key(BN_CTX *ctx, const DH *dh, const BIGNUM *priv_key, BIGNUM *pub_key) { int ret = 0; BIGNUM *prk = BN_new(); BN_MONT_CTX *mont = NULL; if (prk == NULL) return 0; if (dh->flags & DH_FLAG_CACHE_MONT_P) { /* * We take the input DH as const, but we lie, because in some cases we * want to get a hold of its Montgomery context. * * We cast to remove the const qualifier in this case, it should be * fine... */ BN_MONT_CTX **pmont = (BN_MONT_CTX **)&dh->method_mont_p; mont = BN_MONT_CTX_set_locked(pmont, dh->lock, dh->params.p, ctx); if (mont == NULL) goto err; } BN_with_flags(prk, priv_key, BN_FLG_CONSTTIME); /* pub_key = g^priv_key mod p */ if (!dh->meth->bn_mod_exp(dh, pub_key, dh->params.g, prk, dh->params.p, ctx, mont)) goto err; ret = 1; err: BN_clear_free(prk); return ret; } static int generate_key(DH *dh) { int ok = 0; int generate_new_key = 0; #ifndef FIPS_MODULE unsigned l; #endif BN_CTX *ctx = NULL; BIGNUM *pub_key = NULL, *priv_key = NULL; if (BN_num_bits(dh->params.p) > OPENSSL_DH_MAX_MODULUS_BITS) { ERR_raise(ERR_LIB_DH, DH_R_MODULUS_TOO_LARGE); return 0; } if (BN_num_bits(dh->params.p) < DH_MIN_MODULUS_BITS) { ERR_raise(ERR_LIB_DH, DH_R_MODULUS_TOO_SMALL); return 0; } ctx = BN_CTX_new_ex(dh->libctx); if (ctx == NULL) goto err; if (dh->priv_key == NULL) { priv_key = BN_secure_new(); if (priv_key == NULL) goto err; generate_new_key = 1; } else { priv_key = dh->priv_key; } if (dh->pub_key == NULL) { pub_key = BN_new(); if (pub_key == NULL) goto err; } else { pub_key = dh->pub_key; } if (generate_new_key) { /* Is it an approved safe prime ?*/ if (DH_get_nid(dh) != NID_undef) { int max_strength = ossl_ifc_ffc_compute_security_bits(BN_num_bits(dh->params.p)); if (dh->params.q == NULL || dh->length > BN_num_bits(dh->params.q)) goto err; /* dh->length = maximum bit length of generated private key */ if (!ossl_ffc_generate_private_key(ctx, &dh->params, dh->length, max_strength, priv_key)) goto err; } else { #ifdef FIPS_MODULE if (dh->params.q == NULL) goto err; #else if (dh->params.q == NULL) { /* secret exponent length, must satisfy 2^(l-1) <= p */ if (dh->length != 0 && dh->length >= BN_num_bits(dh->params.p)) goto err; l = dh->length ? dh->length : BN_num_bits(dh->params.p) - 1; if (!BN_priv_rand_ex(priv_key, l, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY, 0, ctx)) goto err; /* * We handle just one known case where g is a quadratic non-residue: * for g = 2: p % 8 == 3 */ if (BN_is_word(dh->params.g, DH_GENERATOR_2) && !BN_is_bit_set(dh->params.p, 2)) { /* clear bit 0, since it won't be a secret anyway */ if (!BN_clear_bit(priv_key, 0)) goto err; } } else #endif { /* Do a partial check for invalid p, q, g */ if (!ossl_ffc_params_simple_validate(dh->libctx, &dh->params, FFC_PARAM_TYPE_DH, NULL)) goto err; /* * For FFC FIPS 186-4 keygen * security strength s = 112, * Max Private key size N = len(q) */ if (!ossl_ffc_generate_private_key(ctx, &dh->params, BN_num_bits(dh->params.q), MIN_STRENGTH, priv_key)) goto err; } } } if (!ossl_dh_generate_public_key(ctx, dh, priv_key, pub_key)) goto err; dh->pub_key = pub_key; dh->priv_key = priv_key; dh->dirty_cnt++; ok = 1; err: if (ok != 1) ERR_raise(ERR_LIB_DH, ERR_R_BN_LIB); if (pub_key != dh->pub_key) BN_free(pub_key); if (priv_key != dh->priv_key) BN_free(priv_key); BN_CTX_free(ctx); return ok; } int ossl_dh_buf2key(DH *dh, const unsigned char *buf, size_t len) { int err_reason = DH_R_BN_ERROR; BIGNUM *pubkey = NULL; const BIGNUM *p; int ret; if ((pubkey = BN_bin2bn(buf, len, NULL)) == NULL) goto err; DH_get0_pqg(dh, &p, NULL, NULL); if (p == NULL || BN_num_bytes(p) == 0) { err_reason = DH_R_NO_PARAMETERS_SET; goto err; } /* Prevent small subgroup attacks per RFC 8446 Section 4.2.8.1 */ if (!ossl_dh_check_pub_key_partial(dh, pubkey, &ret)) { err_reason = DH_R_INVALID_PUBKEY; goto err; } if (DH_set0_key(dh, pubkey, NULL) != 1) goto err; return 1; err: ERR_raise(ERR_LIB_DH, err_reason); BN_free(pubkey); return 0; } size_t ossl_dh_key2buf(const DH *dh, unsigned char **pbuf_out, size_t size, int alloc) { const BIGNUM *pubkey; unsigned char *pbuf = NULL; const BIGNUM *p; int p_size; DH_get0_pqg(dh, &p, NULL, NULL); DH_get0_key(dh, &pubkey, NULL); if (p == NULL || pubkey == NULL || (p_size = BN_num_bytes(p)) == 0 || BN_num_bytes(pubkey) == 0) { ERR_raise(ERR_LIB_DH, DH_R_INVALID_PUBKEY); return 0; } if (pbuf_out != NULL && (alloc || *pbuf_out != NULL)) { if (!alloc) { if (size >= (size_t)p_size) pbuf = *pbuf_out; } else { pbuf = OPENSSL_malloc(p_size); } if (pbuf == NULL) { ERR_raise(ERR_LIB_DH, ERR_R_MALLOC_FAILURE); return 0; } /* * As per Section 4.2.8.1 of RFC 8446 left pad public * key with zeros to the size of p */ if (BN_bn2binpad(pubkey, pbuf, p_size) < 0) { if (alloc) OPENSSL_free(pbuf); ERR_raise(ERR_LIB_DH, DH_R_BN_ERROR); return 0; } *pbuf_out = pbuf; } return p_size; } diff --git a/crypto/openssl/crypto/dh/dh_lib.c b/crypto/openssl/crypto/dh/dh_lib.c index 29cda5d7bfa8..5577413e1e0c 100644 --- a/crypto/openssl/crypto/dh/dh_lib.c +++ b/crypto/openssl/crypto/dh/dh_lib.c @@ -1,330 +1,332 @@ /* - * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ /* * DH low level APIs are deprecated for public use, but still ok for * internal use. */ #include "internal/deprecated.h" #include #include #ifndef FIPS_MODULE # include #endif #include #include #include "internal/cryptlib.h" #include "internal/refcount.h" #include "crypto/evp.h" #include "crypto/dh.h" #include "dh_local.h" static DH *dh_new_intern(ENGINE *engine, OSSL_LIB_CTX *libctx); #ifndef FIPS_MODULE int DH_set_method(DH *dh, const DH_METHOD *meth) { /* * NB: The caller is specifically setting a method, so it's not up to us * to deal with which ENGINE it comes from. */ const DH_METHOD *mtmp; mtmp = dh->meth; if (mtmp->finish) mtmp->finish(dh); #ifndef OPENSSL_NO_ENGINE ENGINE_finish(dh->engine); dh->engine = NULL; #endif dh->meth = meth; if (meth->init) meth->init(dh); return 1; } const DH_METHOD *ossl_dh_get_method(const DH *dh) { return dh->meth; } # ifndef OPENSSL_NO_DEPRECATED_3_0 DH *DH_new(void) { return dh_new_intern(NULL, NULL); } # endif DH *DH_new_method(ENGINE *engine) { return dh_new_intern(engine, NULL); } #endif /* !FIPS_MODULE */ DH *ossl_dh_new_ex(OSSL_LIB_CTX *libctx) { return dh_new_intern(NULL, libctx); } static DH *dh_new_intern(ENGINE *engine, OSSL_LIB_CTX *libctx) { DH *ret = OPENSSL_zalloc(sizeof(*ret)); if (ret == NULL) { ERR_raise(ERR_LIB_DH, ERR_R_MALLOC_FAILURE); return NULL; } ret->references = 1; ret->lock = CRYPTO_THREAD_lock_new(); if (ret->lock == NULL) { ERR_raise(ERR_LIB_DH, ERR_R_MALLOC_FAILURE); OPENSSL_free(ret); return NULL; } ret->libctx = libctx; ret->meth = DH_get_default_method(); #if !defined(FIPS_MODULE) && !defined(OPENSSL_NO_ENGINE) ret->flags = ret->meth->flags; /* early default init */ if (engine) { if (!ENGINE_init(engine)) { ERR_raise(ERR_LIB_DH, ERR_R_ENGINE_LIB); goto err; } ret->engine = engine; } else ret->engine = ENGINE_get_default_DH(); if (ret->engine) { ret->meth = ENGINE_get_DH(ret->engine); if (ret->meth == NULL) { ERR_raise(ERR_LIB_DH, ERR_R_ENGINE_LIB); goto err; } } #endif ret->flags = ret->meth->flags; #ifndef FIPS_MODULE if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data)) goto err; #endif /* FIPS_MODULE */ + ossl_ffc_params_init(&ret->params); + if ((ret->meth->init != NULL) && !ret->meth->init(ret)) { ERR_raise(ERR_LIB_DH, ERR_R_INIT_FAIL); goto err; } return ret; err: DH_free(ret); return NULL; } void DH_free(DH *r) { int i; if (r == NULL) return; CRYPTO_DOWN_REF(&r->references, &i, r->lock); REF_PRINT_COUNT("DH", r); if (i > 0) return; REF_ASSERT_ISNT(i < 0); if (r->meth != NULL && r->meth->finish != NULL) r->meth->finish(r); #if !defined(FIPS_MODULE) # if !defined(OPENSSL_NO_ENGINE) ENGINE_finish(r->engine); # endif CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DH, r, &r->ex_data); #endif CRYPTO_THREAD_lock_free(r->lock); ossl_ffc_params_cleanup(&r->params); BN_clear_free(r->pub_key); BN_clear_free(r->priv_key); OPENSSL_free(r); } int DH_up_ref(DH *r) { int i; if (CRYPTO_UP_REF(&r->references, &i, r->lock) <= 0) return 0; REF_PRINT_COUNT("DH", r); REF_ASSERT_ISNT(i < 2); return ((i > 1) ? 1 : 0); } void ossl_dh_set0_libctx(DH *d, OSSL_LIB_CTX *libctx) { d->libctx = libctx; } #ifndef FIPS_MODULE int DH_set_ex_data(DH *d, int idx, void *arg) { return CRYPTO_set_ex_data(&d->ex_data, idx, arg); } void *DH_get_ex_data(const DH *d, int idx) { return CRYPTO_get_ex_data(&d->ex_data, idx); } #endif int DH_bits(const DH *dh) { if (dh->params.p != NULL) return BN_num_bits(dh->params.p); return -1; } int DH_size(const DH *dh) { if (dh->params.p != NULL) return BN_num_bytes(dh->params.p); return -1; } int DH_security_bits(const DH *dh) { int N; if (dh->params.q != NULL) N = BN_num_bits(dh->params.q); else if (dh->length) N = dh->length; else N = -1; if (dh->params.p != NULL) return BN_security_bits(BN_num_bits(dh->params.p), N); return -1; } void DH_get0_pqg(const DH *dh, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g) { ossl_ffc_params_get0_pqg(&dh->params, p, q, g); } int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g) { /* * If the fields p and g in dh are NULL, the corresponding input * parameters MUST be non-NULL. q may remain NULL. */ if ((dh->params.p == NULL && p == NULL) || (dh->params.g == NULL && g == NULL)) return 0; ossl_ffc_params_set0_pqg(&dh->params, p, q, g); ossl_dh_cache_named_group(dh); dh->dirty_cnt++; return 1; } long DH_get_length(const DH *dh) { return dh->length; } int DH_set_length(DH *dh, long length) { dh->length = length; dh->dirty_cnt++; return 1; } void DH_get0_key(const DH *dh, const BIGNUM **pub_key, const BIGNUM **priv_key) { if (pub_key != NULL) *pub_key = dh->pub_key; if (priv_key != NULL) *priv_key = dh->priv_key; } int DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key) { if (pub_key != NULL) { BN_clear_free(dh->pub_key); dh->pub_key = pub_key; } if (priv_key != NULL) { BN_clear_free(dh->priv_key); dh->priv_key = priv_key; } dh->dirty_cnt++; return 1; } const BIGNUM *DH_get0_p(const DH *dh) { return dh->params.p; } const BIGNUM *DH_get0_q(const DH *dh) { return dh->params.q; } const BIGNUM *DH_get0_g(const DH *dh) { return dh->params.g; } const BIGNUM *DH_get0_priv_key(const DH *dh) { return dh->priv_key; } const BIGNUM *DH_get0_pub_key(const DH *dh) { return dh->pub_key; } void DH_clear_flags(DH *dh, int flags) { dh->flags &= ~flags; } int DH_test_flags(const DH *dh, int flags) { return dh->flags & flags; } void DH_set_flags(DH *dh, int flags) { dh->flags |= flags; } #ifndef FIPS_MODULE ENGINE *DH_get0_engine(DH *dh) { return dh->engine; } #endif /*FIPS_MODULE */ FFC_PARAMS *ossl_dh_get0_params(DH *dh) { return &dh->params; } int ossl_dh_get0_nid(const DH *dh) { return dh->params.nid; } diff --git a/crypto/openssl/crypto/dsa/dsa_check.c b/crypto/openssl/crypto/dsa/dsa_check.c index 7ee914a477ec..fb0e9129a295 100644 --- a/crypto/openssl/crypto/dsa/dsa_check.c +++ b/crypto/openssl/crypto/dsa/dsa_check.c @@ -1,95 +1,97 @@ /* - * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ /* * DSA low level APIs are deprecated for public use, but still ok for * internal use. */ #include "internal/deprecated.h" #include #include "internal/cryptlib.h" #include #include "dsa_local.h" #include "crypto/dsa.h" int ossl_dsa_check_params(const DSA *dsa, int checktype, int *ret) { if (checktype == OSSL_KEYMGMT_VALIDATE_QUICK_CHECK) return ossl_ffc_params_simple_validate(dsa->libctx, &dsa->params, FFC_PARAM_TYPE_DSA, ret); else /* * Do full FFC domain params validation according to FIPS-186-4 * - always in FIPS_MODULE * - only if possible (i.e., seed is set) in default provider */ return ossl_ffc_params_full_validate(dsa->libctx, &dsa->params, FFC_PARAM_TYPE_DSA, ret); } /* * See SP800-56Ar3 Section 5.6.2.3.1 : FFC Full public key validation. */ int ossl_dsa_check_pub_key(const DSA *dsa, const BIGNUM *pub_key, int *ret) { - return ossl_ffc_validate_public_key(&dsa->params, pub_key, ret); + return ossl_ffc_validate_public_key(&dsa->params, pub_key, ret) + && *ret == 0; } /* * See SP800-56Ar3 Section 5.6.2.3.1 : FFC Partial public key validation. * To only be used with ephemeral FFC public keys generated using the approved * safe-prime groups. */ int ossl_dsa_check_pub_key_partial(const DSA *dsa, const BIGNUM *pub_key, int *ret) { - return ossl_ffc_validate_public_key_partial(&dsa->params, pub_key, ret); + return ossl_ffc_validate_public_key_partial(&dsa->params, pub_key, ret) + && *ret == 0; } int ossl_dsa_check_priv_key(const DSA *dsa, const BIGNUM *priv_key, int *ret) { *ret = 0; return (dsa->params.q != NULL && ossl_ffc_validate_private_key(dsa->params.q, priv_key, ret)); } /* * FFC pairwise check from SP800-56A R3. * Section 5.6.2.1.4 Owner Assurance of Pair-wise Consistency */ int ossl_dsa_check_pairwise(const DSA *dsa) { int ret = 0; BN_CTX *ctx = NULL; BIGNUM *pub_key = NULL; if (dsa->params.p == NULL || dsa->params.g == NULL || dsa->priv_key == NULL || dsa->pub_key == NULL) return 0; ctx = BN_CTX_new_ex(dsa->libctx); if (ctx == NULL) goto err; pub_key = BN_new(); if (pub_key == NULL) goto err; /* recalculate the public key = (g ^ priv) mod p */ if (!ossl_dsa_generate_public_key(ctx, dsa, dsa->priv_key, pub_key)) goto err; /* check it matches the existing pubic_key */ ret = BN_cmp(pub_key, dsa->pub_key) == 0; err: BN_free(pub_key); BN_CTX_free(ctx); return ret; } diff --git a/crypto/openssl/crypto/dsa/dsa_lib.c b/crypto/openssl/crypto/dsa/dsa_lib.c index ccc701659217..2ae3f8e36b26 100644 --- a/crypto/openssl/crypto/dsa/dsa_lib.c +++ b/crypto/openssl/crypto/dsa/dsa_lib.c @@ -1,362 +1,364 @@ /* - * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ /* * DSA low level APIs are deprecated for public use, but still ok for * internal use. */ #include "internal/deprecated.h" #include #ifndef FIPS_MODULE # include #endif #include "internal/cryptlib.h" #include "internal/refcount.h" #include "crypto/dsa.h" #include "crypto/dh.h" /* required by DSA_dup_DH() */ #include "dsa_local.h" static DSA *dsa_new_intern(ENGINE *engine, OSSL_LIB_CTX *libctx); #ifndef FIPS_MODULE int DSA_set_ex_data(DSA *d, int idx, void *arg) { return CRYPTO_set_ex_data(&d->ex_data, idx, arg); } void *DSA_get_ex_data(const DSA *d, int idx) { return CRYPTO_get_ex_data(&d->ex_data, idx); } # ifndef OPENSSL_NO_DH DH *DSA_dup_DH(const DSA *r) { /* * DSA has p, q, g, optional pub_key, optional priv_key. * DH has p, optional length, g, optional pub_key, * optional priv_key, optional q. */ DH *ret = NULL; BIGNUM *pub_key = NULL, *priv_key = NULL; if (r == NULL) goto err; ret = DH_new(); if (ret == NULL) goto err; if (!ossl_ffc_params_copy(ossl_dh_get0_params(ret), &r->params)) goto err; if (r->pub_key != NULL) { pub_key = BN_dup(r->pub_key); if (pub_key == NULL) goto err; if (r->priv_key != NULL) { priv_key = BN_dup(r->priv_key); if (priv_key == NULL) goto err; } if (!DH_set0_key(ret, pub_key, priv_key)) goto err; } else if (r->priv_key != NULL) { /* Shouldn't happen */ goto err; } return ret; err: BN_free(pub_key); BN_free(priv_key); DH_free(ret); return NULL; } # endif /* OPENSSL_NO_DH */ void DSA_clear_flags(DSA *d, int flags) { d->flags &= ~flags; } int DSA_test_flags(const DSA *d, int flags) { return d->flags & flags; } void DSA_set_flags(DSA *d, int flags) { d->flags |= flags; } ENGINE *DSA_get0_engine(DSA *d) { return d->engine; } int DSA_set_method(DSA *dsa, const DSA_METHOD *meth) { /* * NB: The caller is specifically setting a method, so it's not up to us * to deal with which ENGINE it comes from. */ const DSA_METHOD *mtmp; mtmp = dsa->meth; if (mtmp->finish) mtmp->finish(dsa); #ifndef OPENSSL_NO_ENGINE ENGINE_finish(dsa->engine); dsa->engine = NULL; #endif dsa->meth = meth; if (meth->init) meth->init(dsa); return 1; } #endif /* FIPS_MODULE */ const DSA_METHOD *DSA_get_method(DSA *d) { return d->meth; } static DSA *dsa_new_intern(ENGINE *engine, OSSL_LIB_CTX *libctx) { DSA *ret = OPENSSL_zalloc(sizeof(*ret)); if (ret == NULL) { ERR_raise(ERR_LIB_DSA, ERR_R_MALLOC_FAILURE); return NULL; } ret->references = 1; ret->lock = CRYPTO_THREAD_lock_new(); if (ret->lock == NULL) { ERR_raise(ERR_LIB_DSA, ERR_R_MALLOC_FAILURE); OPENSSL_free(ret); return NULL; } ret->libctx = libctx; ret->meth = DSA_get_default_method(); #if !defined(FIPS_MODULE) && !defined(OPENSSL_NO_ENGINE) ret->flags = ret->meth->flags & ~DSA_FLAG_NON_FIPS_ALLOW; /* early default init */ if (engine) { if (!ENGINE_init(engine)) { ERR_raise(ERR_LIB_DSA, ERR_R_ENGINE_LIB); goto err; } ret->engine = engine; } else ret->engine = ENGINE_get_default_DSA(); if (ret->engine) { ret->meth = ENGINE_get_DSA(ret->engine); if (ret->meth == NULL) { ERR_raise(ERR_LIB_DSA, ERR_R_ENGINE_LIB); goto err; } } #endif ret->flags = ret->meth->flags & ~DSA_FLAG_NON_FIPS_ALLOW; #ifndef FIPS_MODULE if (!ossl_crypto_new_ex_data_ex(libctx, CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data)) goto err; #endif + ossl_ffc_params_init(&ret->params); + if ((ret->meth->init != NULL) && !ret->meth->init(ret)) { ERR_raise(ERR_LIB_DSA, ERR_R_INIT_FAIL); goto err; } return ret; err: DSA_free(ret); return NULL; } DSA *DSA_new_method(ENGINE *engine) { return dsa_new_intern(engine, NULL); } DSA *ossl_dsa_new(OSSL_LIB_CTX *libctx) { return dsa_new_intern(NULL, libctx); } #ifndef FIPS_MODULE DSA *DSA_new(void) { return dsa_new_intern(NULL, NULL); } #endif void DSA_free(DSA *r) { int i; if (r == NULL) return; CRYPTO_DOWN_REF(&r->references, &i, r->lock); REF_PRINT_COUNT("DSA", r); if (i > 0) return; REF_ASSERT_ISNT(i < 0); if (r->meth != NULL && r->meth->finish != NULL) r->meth->finish(r); #if !defined(FIPS_MODULE) && !defined(OPENSSL_NO_ENGINE) ENGINE_finish(r->engine); #endif #ifndef FIPS_MODULE CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, r, &r->ex_data); #endif CRYPTO_THREAD_lock_free(r->lock); ossl_ffc_params_cleanup(&r->params); BN_clear_free(r->pub_key); BN_clear_free(r->priv_key); OPENSSL_free(r); } int DSA_up_ref(DSA *r) { int i; if (CRYPTO_UP_REF(&r->references, &i, r->lock) <= 0) return 0; REF_PRINT_COUNT("DSA", r); REF_ASSERT_ISNT(i < 2); return ((i > 1) ? 1 : 0); } void ossl_dsa_set0_libctx(DSA *d, OSSL_LIB_CTX *libctx) { d->libctx = libctx; } void DSA_get0_pqg(const DSA *d, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g) { ossl_ffc_params_get0_pqg(&d->params, p, q, g); } int DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g) { /* If the fields p, q and g in d are NULL, the corresponding input * parameters MUST be non-NULL. */ if ((d->params.p == NULL && p == NULL) || (d->params.q == NULL && q == NULL) || (d->params.g == NULL && g == NULL)) return 0; ossl_ffc_params_set0_pqg(&d->params, p, q, g); d->dirty_cnt++; return 1; } const BIGNUM *DSA_get0_p(const DSA *d) { return d->params.p; } const BIGNUM *DSA_get0_q(const DSA *d) { return d->params.q; } const BIGNUM *DSA_get0_g(const DSA *d) { return d->params.g; } const BIGNUM *DSA_get0_pub_key(const DSA *d) { return d->pub_key; } const BIGNUM *DSA_get0_priv_key(const DSA *d) { return d->priv_key; } void DSA_get0_key(const DSA *d, const BIGNUM **pub_key, const BIGNUM **priv_key) { if (pub_key != NULL) *pub_key = d->pub_key; if (priv_key != NULL) *priv_key = d->priv_key; } int DSA_set0_key(DSA *d, BIGNUM *pub_key, BIGNUM *priv_key) { if (pub_key != NULL) { BN_free(d->pub_key); d->pub_key = pub_key; } if (priv_key != NULL) { BN_free(d->priv_key); d->priv_key = priv_key; } d->dirty_cnt++; return 1; } int DSA_security_bits(const DSA *d) { if (d->params.p != NULL && d->params.q != NULL) return BN_security_bits(BN_num_bits(d->params.p), BN_num_bits(d->params.q)); return -1; } int DSA_bits(const DSA *dsa) { if (dsa->params.p != NULL) return BN_num_bits(dsa->params.p); return -1; } FFC_PARAMS *ossl_dsa_get0_params(DSA *dsa) { return &dsa->params; } int ossl_dsa_ffc_params_fromdata(DSA *dsa, const OSSL_PARAM params[]) { int ret; FFC_PARAMS *ffc; if (dsa == NULL) return 0; ffc = ossl_dsa_get0_params(dsa); if (ffc == NULL) return 0; ret = ossl_ffc_params_fromdata(ffc, params); if (ret) dsa->dirty_cnt++; return ret; } diff --git a/crypto/openssl/crypto/dsa/dsa_ossl.c b/crypto/openssl/crypto/dsa/dsa_ossl.c index 62f7c70149f4..8fd66a950e37 100644 --- a/crypto/openssl/crypto/dsa/dsa_ossl.c +++ b/crypto/openssl/crypto/dsa/dsa_ossl.c @@ -1,481 +1,480 @@ /* * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ /* * DSA low level APIs are deprecated for public use, but still ok for * internal use. */ #include "internal/deprecated.h" #include #include "internal/cryptlib.h" #include "crypto/bn.h" #include #include #include "dsa_local.h" #include #define MIN_DSA_SIGN_QBITS 128 #define MAX_DSA_SIGN_RETRIES 8 static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa); static int dsa_sign_setup_no_digest(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp); static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp, const unsigned char *dgst, int dlen); static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, DSA *dsa); static int dsa_init(DSA *dsa); static int dsa_finish(DSA *dsa); static BIGNUM *dsa_mod_inverse_fermat(const BIGNUM *k, const BIGNUM *q, BN_CTX *ctx); static DSA_METHOD openssl_dsa_meth = { "OpenSSL DSA method", dsa_do_sign, dsa_sign_setup_no_digest, dsa_do_verify, NULL, /* dsa_mod_exp, */ NULL, /* dsa_bn_mod_exp, */ dsa_init, dsa_finish, DSA_FLAG_FIPS_METHOD, NULL, NULL, NULL }; static const DSA_METHOD *default_DSA_method = &openssl_dsa_meth; #ifndef FIPS_MODULE void DSA_set_default_method(const DSA_METHOD *meth) { default_DSA_method = meth; } #endif /* FIPS_MODULE */ const DSA_METHOD *DSA_get_default_method(void) { return default_DSA_method; } const DSA_METHOD *DSA_OpenSSL(void) { return &openssl_dsa_meth; } DSA_SIG *ossl_dsa_do_sign_int(const unsigned char *dgst, int dlen, DSA *dsa) { BIGNUM *kinv = NULL; BIGNUM *m, *blind, *blindm, *tmp; BN_CTX *ctx = NULL; int reason = ERR_R_BN_LIB; DSA_SIG *ret = NULL; int rv = 0; int retries = 0; if (dsa->params.p == NULL || dsa->params.q == NULL || dsa->params.g == NULL) { reason = DSA_R_MISSING_PARAMETERS; goto err; } if (dsa->priv_key == NULL) { reason = DSA_R_MISSING_PRIVATE_KEY; goto err; } ret = DSA_SIG_new(); if (ret == NULL) goto err; ret->r = BN_new(); ret->s = BN_new(); if (ret->r == NULL || ret->s == NULL) goto err; ctx = BN_CTX_new_ex(dsa->libctx); if (ctx == NULL) goto err; m = BN_CTX_get(ctx); blind = BN_CTX_get(ctx); blindm = BN_CTX_get(ctx); tmp = BN_CTX_get(ctx); if (tmp == NULL) goto err; redo: if (!dsa_sign_setup(dsa, ctx, &kinv, &ret->r, dgst, dlen)) goto err; if (dlen > BN_num_bytes(dsa->params.q)) /* * if the digest length is greater than the size of q use the * BN_num_bits(dsa->q) leftmost bits of the digest, see fips 186-3, * 4.2 */ dlen = BN_num_bytes(dsa->params.q); if (BN_bin2bn(dgst, dlen, m) == NULL) goto err; /* * The normal signature calculation is: * * s := k^-1 * (m + r * priv_key) mod q * * We will blind this to protect against side channel attacks * * s := blind^-1 * k^-1 * (blind * m + blind * r * priv_key) mod q */ /* * Generate a blinding value * The size of q is tested in dsa_sign_setup() so there should not be an infinite loop here. */ do { if (!BN_priv_rand_ex(blind, BN_num_bits(dsa->params.q) - 1, BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY, 0, ctx)) goto err; } while (BN_is_zero(blind)); BN_set_flags(blind, BN_FLG_CONSTTIME); BN_set_flags(blindm, BN_FLG_CONSTTIME); BN_set_flags(tmp, BN_FLG_CONSTTIME); /* tmp := blind * priv_key * r mod q */ if (!BN_mod_mul(tmp, blind, dsa->priv_key, dsa->params.q, ctx)) goto err; if (!BN_mod_mul(tmp, tmp, ret->r, dsa->params.q, ctx)) goto err; /* blindm := blind * m mod q */ if (!BN_mod_mul(blindm, blind, m, dsa->params.q, ctx)) goto err; /* s : = (blind * priv_key * r) + (blind * m) mod q */ if (!BN_mod_add_quick(ret->s, tmp, blindm, dsa->params.q)) goto err; /* s := s * k^-1 mod q */ if (!BN_mod_mul(ret->s, ret->s, kinv, dsa->params.q, ctx)) goto err; /* s:= s * blind^-1 mod q */ if (BN_mod_inverse(blind, blind, dsa->params.q, ctx) == NULL) goto err; if (!BN_mod_mul(ret->s, ret->s, blind, dsa->params.q, ctx)) goto err; /* * Redo if r or s is zero as required by FIPS 186-4: Section 4.6 * This is very unlikely. * Limit the retries so there is no possibility of an infinite * loop for bad domain parameter values. */ if (BN_is_zero(ret->r) || BN_is_zero(ret->s)) { if (retries++ > MAX_DSA_SIGN_RETRIES) { reason = DSA_R_TOO_MANY_RETRIES; goto err; } goto redo; } rv = 1; err: if (rv == 0) { ERR_raise(ERR_LIB_DSA, reason); DSA_SIG_free(ret); ret = NULL; } BN_CTX_free(ctx); BN_clear_free(kinv); return ret; } static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) { return ossl_dsa_do_sign_int(dgst, dlen, dsa); } static int dsa_sign_setup_no_digest(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp) { return dsa_sign_setup(dsa, ctx_in, kinvp, rp, NULL, 0); } static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp, const unsigned char *dgst, int dlen) { BN_CTX *ctx = NULL; BIGNUM *k, *kinv = NULL, *r = *rp; BIGNUM *l; int ret = 0; int q_bits, q_words; if (!dsa->params.p || !dsa->params.q || !dsa->params.g) { ERR_raise(ERR_LIB_DSA, DSA_R_MISSING_PARAMETERS); return 0; } /* Reject obviously invalid parameters */ if (BN_is_zero(dsa->params.p) || BN_is_zero(dsa->params.q) || BN_is_zero(dsa->params.g) || BN_is_negative(dsa->params.p) || BN_is_negative(dsa->params.q) || BN_is_negative(dsa->params.g)) { ERR_raise(ERR_LIB_DSA, DSA_R_INVALID_PARAMETERS); return 0; } if (dsa->priv_key == NULL) { ERR_raise(ERR_LIB_DSA, DSA_R_MISSING_PRIVATE_KEY); return 0; } k = BN_new(); l = BN_new(); if (k == NULL || l == NULL) goto err; if (ctx_in == NULL) { /* if you don't pass in ctx_in you get a default libctx */ if ((ctx = BN_CTX_new_ex(NULL)) == NULL) goto err; } else ctx = ctx_in; /* Preallocate space */ q_bits = BN_num_bits(dsa->params.q); q_words = bn_get_top(dsa->params.q); if (q_bits < MIN_DSA_SIGN_QBITS || !bn_wexpand(k, q_words + 2) || !bn_wexpand(l, q_words + 2)) goto err; /* Get random k */ do { if (dgst != NULL) { /* * We calculate k from SHA512(private_key + H(message) + random). * This protects the private key from a weak PRNG. */ if (!BN_generate_dsa_nonce(k, dsa->params.q, dsa->priv_key, dgst, dlen, ctx)) goto err; } else if (!BN_priv_rand_range_ex(k, dsa->params.q, 0, ctx)) goto err; } while (BN_is_zero(k)); BN_set_flags(k, BN_FLG_CONSTTIME); BN_set_flags(l, BN_FLG_CONSTTIME); if (dsa->flags & DSA_FLAG_CACHE_MONT_P) { if (!BN_MONT_CTX_set_locked(&dsa->method_mont_p, dsa->lock, dsa->params.p, ctx)) goto err; } /* Compute r = (g^k mod p) mod q */ /* * We do not want timing information to leak the length of k, so we * compute G^k using an equivalent scalar of fixed bit-length. * * We unconditionally perform both of these additions to prevent a * small timing information leakage. We then choose the sum that is * one bit longer than the modulus. * * There are some concerns about the efficacy of doing this. More * specifically refer to the discussion starting with: * https://github.com/openssl/openssl/pull/7486#discussion_r228323705 * The fix is to rework BN so these gymnastics aren't required. */ if (!BN_add(l, k, dsa->params.q) || !BN_add(k, l, dsa->params.q)) goto err; BN_consttime_swap(BN_is_bit_set(l, q_bits), k, l, q_words + 2); if ((dsa)->meth->bn_mod_exp != NULL) { if (!dsa->meth->bn_mod_exp(dsa, r, dsa->params.g, k, dsa->params.p, ctx, dsa->method_mont_p)) goto err; } else { if (!BN_mod_exp_mont(r, dsa->params.g, k, dsa->params.p, ctx, dsa->method_mont_p)) goto err; } if (!BN_mod(r, r, dsa->params.q, ctx)) goto err; /* Compute part of 's = inv(k) (m + xr) mod q' */ if ((kinv = dsa_mod_inverse_fermat(k, dsa->params.q, ctx)) == NULL) goto err; BN_clear_free(*kinvp); *kinvp = kinv; kinv = NULL; ret = 1; err: if (!ret) ERR_raise(ERR_LIB_DSA, ERR_R_BN_LIB); if (ctx != ctx_in) BN_CTX_free(ctx); BN_clear_free(k); BN_clear_free(l); return ret; } static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, DSA *dsa) { BN_CTX *ctx; BIGNUM *u1, *u2, *t1; BN_MONT_CTX *mont = NULL; const BIGNUM *r, *s; int ret = -1, i; if (dsa->params.p == NULL || dsa->params.q == NULL || dsa->params.g == NULL) { ERR_raise(ERR_LIB_DSA, DSA_R_MISSING_PARAMETERS); return -1; } i = BN_num_bits(dsa->params.q); /* fips 186-3 allows only different sizes for q */ if (i != 160 && i != 224 && i != 256) { ERR_raise(ERR_LIB_DSA, DSA_R_BAD_Q_VALUE); return -1; } if (BN_num_bits(dsa->params.p) > OPENSSL_DSA_MAX_MODULUS_BITS) { ERR_raise(ERR_LIB_DSA, DSA_R_MODULUS_TOO_LARGE); return -1; } u1 = BN_new(); u2 = BN_new(); t1 = BN_new(); ctx = BN_CTX_new_ex(NULL); /* verify does not need a libctx */ if (u1 == NULL || u2 == NULL || t1 == NULL || ctx == NULL) goto err; DSA_SIG_get0(sig, &r, &s); if (BN_is_zero(r) || BN_is_negative(r) || BN_ucmp(r, dsa->params.q) >= 0) { ret = 0; goto err; } if (BN_is_zero(s) || BN_is_negative(s) || BN_ucmp(s, dsa->params.q) >= 0) { ret = 0; goto err; } /* * Calculate W = inv(S) mod Q save W in u2 */ if ((BN_mod_inverse(u2, s, dsa->params.q, ctx)) == NULL) goto err; /* save M in u1 */ if (dgst_len > (i >> 3)) /* * if the digest length is greater than the size of q use the * BN_num_bits(dsa->q) leftmost bits of the digest, see fips 186-3, * 4.2 */ dgst_len = (i >> 3); if (BN_bin2bn(dgst, dgst_len, u1) == NULL) goto err; /* u1 = M * w mod q */ if (!BN_mod_mul(u1, u1, u2, dsa->params.q, ctx)) goto err; /* u2 = r * w mod q */ if (!BN_mod_mul(u2, r, u2, dsa->params.q, ctx)) goto err; if (dsa->flags & DSA_FLAG_CACHE_MONT_P) { mont = BN_MONT_CTX_set_locked(&dsa->method_mont_p, dsa->lock, dsa->params.p, ctx); if (!mont) goto err; } if (dsa->meth->dsa_mod_exp != NULL) { if (!dsa->meth->dsa_mod_exp(dsa, t1, dsa->params.g, u1, dsa->pub_key, u2, dsa->params.p, ctx, mont)) goto err; } else { if (!BN_mod_exp2_mont(t1, dsa->params.g, u1, dsa->pub_key, u2, dsa->params.p, ctx, mont)) goto err; } /* let u1 = u1 mod q */ if (!BN_mod(u1, t1, dsa->params.q, ctx)) goto err; /* * V is now in u1. If the signature is correct, it will be equal to R. */ ret = (BN_ucmp(u1, r) == 0); err: if (ret < 0) ERR_raise(ERR_LIB_DSA, ERR_R_BN_LIB); BN_CTX_free(ctx); BN_free(u1); BN_free(u2); BN_free(t1); return ret; } static int dsa_init(DSA *dsa) { dsa->flags |= DSA_FLAG_CACHE_MONT_P; - ossl_ffc_params_init(&dsa->params); dsa->dirty_cnt++; return 1; } static int dsa_finish(DSA *dsa) { BN_MONT_CTX_free(dsa->method_mont_p); return 1; } /* * Compute the inverse of k modulo q. * Since q is prime, Fermat's Little Theorem applies, which reduces this to * mod-exp operation. Both the exponent and modulus are public information * so a mod-exp that doesn't leak the base is sufficient. A newly allocated * BIGNUM is returned which the caller must free. */ static BIGNUM *dsa_mod_inverse_fermat(const BIGNUM *k, const BIGNUM *q, BN_CTX *ctx) { BIGNUM *res = NULL; BIGNUM *r, *e; if ((r = BN_new()) == NULL) return NULL; BN_CTX_start(ctx); if ((e = BN_CTX_get(ctx)) != NULL && BN_set_word(r, 2) && BN_sub(e, q, r) && BN_mod_exp_mont(r, k, e, q, ctx, NULL)) res = r; else BN_free(r); BN_CTX_end(ctx); return res; } diff --git a/crypto/openssl/crypto/engine/eng_pkey.c b/crypto/openssl/crypto/engine/eng_pkey.c index 6e6d6df35b2b..f84fcde46016 100644 --- a/crypto/openssl/crypto/engine/eng_pkey.c +++ b/crypto/openssl/crypto/engine/eng_pkey.c @@ -1,138 +1,180 @@ /* - * Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2001-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ /* We need to use some engine deprecated APIs */ #define OPENSSL_SUPPRESS_DEPRECATED #include "eng_local.h" /* Basic get/set stuff */ int ENGINE_set_load_privkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpriv_f) { e->load_privkey = loadpriv_f; return 1; } int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f) { e->load_pubkey = loadpub_f; return 1; } int ENGINE_set_load_ssl_client_cert_function(ENGINE *e, ENGINE_SSL_CLIENT_CERT_PTR loadssl_f) { e->load_ssl_client_cert = loadssl_f; return 1; } ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e) { return e->load_privkey; } ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e) { return e->load_pubkey; } ENGINE_SSL_CLIENT_CERT_PTR ENGINE_get_ssl_client_cert_function(const ENGINE *e) { return e->load_ssl_client_cert; } /* API functions to load public/private keys */ EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id, UI_METHOD *ui_method, void *callback_data) { EVP_PKEY *pkey; if (e == NULL) { ERR_raise(ERR_LIB_ENGINE, ERR_R_PASSED_NULL_PARAMETER); return NULL; } if (!CRYPTO_THREAD_write_lock(global_engine_lock)) return NULL; if (e->funct_ref == 0) { CRYPTO_THREAD_unlock(global_engine_lock); ERR_raise(ERR_LIB_ENGINE, ENGINE_R_NOT_INITIALISED); return NULL; } CRYPTO_THREAD_unlock(global_engine_lock); if (!e->load_privkey) { ERR_raise(ERR_LIB_ENGINE, ENGINE_R_NO_LOAD_FUNCTION); return NULL; } pkey = e->load_privkey(e, key_id, ui_method, callback_data); if (pkey == NULL) { ERR_raise(ERR_LIB_ENGINE, ENGINE_R_FAILED_LOADING_PRIVATE_KEY); return NULL; } + /* We enforce check for legacy key */ + switch (EVP_PKEY_get_id(pkey)) { + case EVP_PKEY_RSA: + { + RSA *rsa = EVP_PKEY_get1_RSA(pkey); + EVP_PKEY_set1_RSA(pkey, rsa); + RSA_free(rsa); + } + break; +# ifndef OPENSSL_NO_EC + case EVP_PKEY_SM2: + case EVP_PKEY_EC: + { + EC_KEY *ec = EVP_PKEY_get1_EC_KEY(pkey); + EVP_PKEY_set1_EC_KEY(pkey, ec); + EC_KEY_free(ec); + } + break; +# endif +# ifndef OPENSSL_NO_DSA + case EVP_PKEY_DSA: + { + DSA *dsa = EVP_PKEY_get1_DSA(pkey); + EVP_PKEY_set1_DSA(pkey, dsa); + DSA_free(dsa); + } + break; +#endif +# ifndef OPENSSL_NO_DH + case EVP_PKEY_DH: + { + DH *dh = EVP_PKEY_get1_DH(pkey); + EVP_PKEY_set1_DH(pkey, dh); + DH_free(dh); + } + break; +#endif + default: + /*Do nothing */ + break; + } + return pkey; } EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id, UI_METHOD *ui_method, void *callback_data) { EVP_PKEY *pkey; if (e == NULL) { ERR_raise(ERR_LIB_ENGINE, ERR_R_PASSED_NULL_PARAMETER); return NULL; } if (!CRYPTO_THREAD_write_lock(global_engine_lock)) return NULL; if (e->funct_ref == 0) { CRYPTO_THREAD_unlock(global_engine_lock); ERR_raise(ERR_LIB_ENGINE, ENGINE_R_NOT_INITIALISED); return NULL; } CRYPTO_THREAD_unlock(global_engine_lock); if (!e->load_pubkey) { ERR_raise(ERR_LIB_ENGINE, ENGINE_R_NO_LOAD_FUNCTION); return NULL; } pkey = e->load_pubkey(e, key_id, ui_method, callback_data); if (pkey == NULL) { ERR_raise(ERR_LIB_ENGINE, ENGINE_R_FAILED_LOADING_PUBLIC_KEY); return NULL; } return pkey; } int ENGINE_load_ssl_client_cert(ENGINE *e, SSL *s, STACK_OF(X509_NAME) *ca_dn, X509 **pcert, EVP_PKEY **ppkey, STACK_OF(X509) **pother, UI_METHOD *ui_method, void *callback_data) { if (e == NULL) { ERR_raise(ERR_LIB_ENGINE, ERR_R_PASSED_NULL_PARAMETER); return 0; } if (!CRYPTO_THREAD_write_lock(global_engine_lock)) return 0; if (e->funct_ref == 0) { CRYPTO_THREAD_unlock(global_engine_lock); ERR_raise(ERR_LIB_ENGINE, ENGINE_R_NOT_INITIALISED); return 0; } CRYPTO_THREAD_unlock(global_engine_lock); if (!e->load_ssl_client_cert) { ERR_raise(ERR_LIB_ENGINE, ENGINE_R_NO_LOAD_FUNCTION); return 0; } return e->load_ssl_client_cert(e, s, ca_dn, pcert, ppkey, pother, ui_method, callback_data); } diff --git a/crypto/openssl/crypto/engine/eng_table.c b/crypto/openssl/crypto/engine/eng_table.c index 3138a1526002..9dc3144bbfd7 100644 --- a/crypto/openssl/crypto/engine/eng_table.c +++ b/crypto/openssl/crypto/engine/eng_table.c @@ -1,313 +1,314 @@ /* * Copyright 2001-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ #include "internal/cryptlib.h" #include #include #include #include "eng_local.h" /* The type of the items in the table */ struct st_engine_pile { /* The 'nid' of this algorithm/mode */ int nid; /* ENGINEs that implement this algorithm/mode. */ STACK_OF(ENGINE) *sk; /* The default ENGINE to perform this algorithm/mode. */ ENGINE *funct; /* * Zero if 'sk' is newer than the cached 'funct', non-zero otherwise */ int uptodate; }; /* The type exposed in eng_local.h */ struct st_engine_table { LHASH_OF(ENGINE_PILE) piles; }; /* ENGINE_TABLE */ typedef struct st_engine_pile_doall { engine_table_doall_cb *cb; void *arg; } ENGINE_PILE_DOALL; /* Global flags (ENGINE_TABLE_FLAG_***). */ static unsigned int table_flags = 0; /* API function manipulating 'table_flags' */ unsigned int ENGINE_get_table_flags(void) { return table_flags; } void ENGINE_set_table_flags(unsigned int flags) { table_flags = flags; } /* Internal functions for the "piles" hash table */ static unsigned long engine_pile_hash(const ENGINE_PILE *c) { return c->nid; } static int engine_pile_cmp(const ENGINE_PILE *a, const ENGINE_PILE *b) { return a->nid - b->nid; } static int int_table_check(ENGINE_TABLE **t, int create) { LHASH_OF(ENGINE_PILE) *lh; if (*t) return 1; if (!create) return 0; if ((lh = lh_ENGINE_PILE_new(engine_pile_hash, engine_pile_cmp)) == NULL) return 0; *t = (ENGINE_TABLE *)lh; return 1; } /* * Privately exposed (via eng_local.h) functions for adding and/or removing * ENGINEs from the implementation table */ int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup, ENGINE *e, const int *nids, int num_nids, int setdefault) { int ret = 0, added = 0; ENGINE_PILE tmplate, *fnd; if (!CRYPTO_THREAD_write_lock(global_engine_lock)) return 0; if (!(*table)) added = 1; if (!int_table_check(table, 1)) goto end; /* The cleanup callback needs to be added */ if (added && !engine_cleanup_add_first(cleanup)) { lh_ENGINE_PILE_free(&(*table)->piles); *table = NULL; + goto end; } while (num_nids--) { tmplate.nid = *nids; fnd = lh_ENGINE_PILE_retrieve(&(*table)->piles, &tmplate); if (!fnd) { fnd = OPENSSL_malloc(sizeof(*fnd)); if (fnd == NULL) goto end; fnd->uptodate = 1; fnd->nid = *nids; fnd->sk = sk_ENGINE_new_null(); if (!fnd->sk) { OPENSSL_free(fnd); goto end; } fnd->funct = NULL; (void)lh_ENGINE_PILE_insert(&(*table)->piles, fnd); if (lh_ENGINE_PILE_retrieve(&(*table)->piles, &tmplate) != fnd) { sk_ENGINE_free(fnd->sk); OPENSSL_free(fnd); goto end; } } /* A registration shouldn't add duplicate entries */ (void)sk_ENGINE_delete_ptr(fnd->sk, e); /* * if 'setdefault', this ENGINE goes to the head of the list */ if (!sk_ENGINE_push(fnd->sk, e)) goto end; /* "touch" this ENGINE_PILE */ fnd->uptodate = 0; if (setdefault) { if (!engine_unlocked_init(e)) { ERR_raise(ERR_LIB_ENGINE, ENGINE_R_INIT_FAILED); goto end; } if (fnd->funct) engine_unlocked_finish(fnd->funct, 0); fnd->funct = e; fnd->uptodate = 1; } nids++; } ret = 1; end: CRYPTO_THREAD_unlock(global_engine_lock); return ret; } static void int_unregister_cb(ENGINE_PILE *pile, ENGINE *e) { int n; /* Iterate the 'c->sk' stack removing any occurrence of 'e' */ while ((n = sk_ENGINE_find(pile->sk, e)) >= 0) { (void)sk_ENGINE_delete(pile->sk, n); pile->uptodate = 0; } if (pile->funct == e) { engine_unlocked_finish(e, 0); pile->funct = NULL; } } IMPLEMENT_LHASH_DOALL_ARG(ENGINE_PILE, ENGINE); void engine_table_unregister(ENGINE_TABLE **table, ENGINE *e) { if (!CRYPTO_THREAD_write_lock(global_engine_lock)) /* Can't return a value. :( */ return; if (int_table_check(table, 0)) lh_ENGINE_PILE_doall_ENGINE(&(*table)->piles, int_unregister_cb, e); CRYPTO_THREAD_unlock(global_engine_lock); } static void int_cleanup_cb_doall(ENGINE_PILE *p) { if (p == NULL) return; sk_ENGINE_free(p->sk); if (p->funct) engine_unlocked_finish(p->funct, 0); OPENSSL_free(p); } void engine_table_cleanup(ENGINE_TABLE **table) { if (!CRYPTO_THREAD_write_lock(global_engine_lock)) return; if (*table) { lh_ENGINE_PILE_doall(&(*table)->piles, int_cleanup_cb_doall); lh_ENGINE_PILE_free(&(*table)->piles); *table = NULL; } CRYPTO_THREAD_unlock(global_engine_lock); } /* return a functional reference for a given 'nid' */ ENGINE *ossl_engine_table_select(ENGINE_TABLE **table, int nid, const char *f, int l) { ENGINE *ret = NULL; ENGINE_PILE tmplate, *fnd = NULL; int initres, loop = 0; #ifndef OPENSSL_NO_AUTOLOAD_CONFIG /* Load the config before trying to check if engines are available */ OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL); #endif if (!(*table)) { OSSL_TRACE3(ENGINE_TABLE, "%s:%d, nid=%d, nothing registered!\n", f, l, nid); return NULL; } ERR_set_mark(); if (!CRYPTO_THREAD_write_lock(global_engine_lock)) goto end; /* * Check again inside the lock otherwise we could race against cleanup * operations. But don't worry about a debug printout */ if (!int_table_check(table, 0)) goto end; tmplate.nid = nid; fnd = lh_ENGINE_PILE_retrieve(&(*table)->piles, &tmplate); if (!fnd) goto end; if (fnd->funct && engine_unlocked_init(fnd->funct)) { OSSL_TRACE4(ENGINE_TABLE, "%s:%d, nid=%d, using ENGINE '%s' cached\n", f, l, nid, fnd->funct->id); ret = fnd->funct; goto end; } if (fnd->uptodate) { ret = fnd->funct; goto end; } trynext: ret = sk_ENGINE_value(fnd->sk, loop++); if (!ret) { OSSL_TRACE3(ENGINE_TABLE, "%s:%d, nid=%d, " "no registered implementations would initialise\n", f, l, nid); goto end; } /* Try to initialise the ENGINE? */ if ((ret->funct_ref > 0) || !(table_flags & ENGINE_TABLE_FLAG_NOINIT)) initres = engine_unlocked_init(ret); else initres = 0; if (initres) { /* Update 'funct' */ if ((fnd->funct != ret) && engine_unlocked_init(ret)) { /* If there was a previous default we release it. */ if (fnd->funct) engine_unlocked_finish(fnd->funct, 0); fnd->funct = ret; OSSL_TRACE4(ENGINE_TABLE, "%s:%d, nid=%d, setting default to '%s'\n", f, l, nid, ret->id); } OSSL_TRACE4(ENGINE_TABLE, "%s:%d, nid=%d, using newly initialised '%s'\n", f, l, nid, ret->id); goto end; } goto trynext; end: /* * If it failed, it is unlikely to succeed again until some future * registrations have taken place. In all cases, we cache. */ if (fnd) fnd->uptodate = 1; if (ret) OSSL_TRACE4(ENGINE_TABLE, "%s:%d, nid=%d, caching ENGINE '%s'\n", f, l, nid, ret->id); else OSSL_TRACE3(ENGINE_TABLE, "%s:%d, nid=%d, caching 'no matching ENGINE'\n", f, l, nid); CRYPTO_THREAD_unlock(global_engine_lock); /* * Whatever happened, any failed init()s are not failures in this * context, so clear our error state. */ ERR_pop_to_mark(); return ret; } /* Table enumeration */ static void int_dall(const ENGINE_PILE *pile, ENGINE_PILE_DOALL *dall) { dall->cb(pile->nid, pile->sk, pile->funct, dall->arg); } IMPLEMENT_LHASH_DOALL_ARG_CONST(ENGINE_PILE, ENGINE_PILE_DOALL); void engine_table_doall(ENGINE_TABLE *table, engine_table_doall_cb *cb, void *arg) { ENGINE_PILE_DOALL dall; dall.cb = cb; dall.arg = arg; if (table) lh_ENGINE_PILE_doall_ENGINE_PILE_DOALL(&table->piles, int_dall, &dall); } diff --git a/crypto/openssl/crypto/err/openssl.txt b/crypto/openssl/crypto/err/openssl.txt index a6f61ca3b02f..e51504b7abd5 100644 --- a/crypto/openssl/crypto/err/openssl.txt +++ b/crypto/openssl/crypto/err/openssl.txt @@ -1,1712 +1,1713 @@ # Copyright 1999-2023 The OpenSSL Project Authors. All Rights Reserved. # # Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy # in the file LICENSE in the source distribution or at # https://www.openssl.org/source/license.html #Reason codes ASN1_R_ADDING_OBJECT:171:adding object ASN1_R_ASN1_PARSE_ERROR:203:asn1 parse error ASN1_R_ASN1_SIG_PARSE_ERROR:204:asn1 sig parse error ASN1_R_AUX_ERROR:100:aux error ASN1_R_BAD_OBJECT_HEADER:102:bad object header ASN1_R_BAD_TEMPLATE:230:bad template ASN1_R_BMPSTRING_IS_WRONG_LENGTH:214:bmpstring is wrong length ASN1_R_BN_LIB:105:bn lib ASN1_R_BOOLEAN_IS_WRONG_LENGTH:106:boolean is wrong length ASN1_R_BUFFER_TOO_SMALL:107:buffer too small ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER:108:cipher has no object identifier ASN1_R_CONTEXT_NOT_INITIALISED:217:context not initialised ASN1_R_DATA_IS_WRONG:109:data is wrong ASN1_R_DECODE_ERROR:110:decode error ASN1_R_DEPTH_EXCEEDED:174:depth exceeded ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED:198:digest and key type not supported ASN1_R_ENCODE_ERROR:112:encode error ASN1_R_ERROR_GETTING_TIME:173:error getting time ASN1_R_ERROR_LOADING_SECTION:172:error loading section ASN1_R_ERROR_SETTING_CIPHER_PARAMS:114:error setting cipher params ASN1_R_EXPECTING_AN_INTEGER:115:expecting an integer ASN1_R_EXPECTING_AN_OBJECT:116:expecting an object ASN1_R_EXPLICIT_LENGTH_MISMATCH:119:explicit length mismatch ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED:120:explicit tag not constructed ASN1_R_FIELD_MISSING:121:field missing ASN1_R_FIRST_NUM_TOO_LARGE:122:first num too large ASN1_R_HEADER_TOO_LONG:123:header too long ASN1_R_ILLEGAL_BITSTRING_FORMAT:175:illegal bitstring format ASN1_R_ILLEGAL_BOOLEAN:176:illegal boolean ASN1_R_ILLEGAL_CHARACTERS:124:illegal characters ASN1_R_ILLEGAL_FORMAT:177:illegal format ASN1_R_ILLEGAL_HEX:178:illegal hex ASN1_R_ILLEGAL_IMPLICIT_TAG:179:illegal implicit tag ASN1_R_ILLEGAL_INTEGER:180:illegal integer ASN1_R_ILLEGAL_NEGATIVE_VALUE:226:illegal negative value ASN1_R_ILLEGAL_NESTED_TAGGING:181:illegal nested tagging ASN1_R_ILLEGAL_NULL:125:illegal null ASN1_R_ILLEGAL_NULL_VALUE:182:illegal null value ASN1_R_ILLEGAL_OBJECT:183:illegal object ASN1_R_ILLEGAL_OPTIONAL_ANY:126:illegal optional any ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE:170:illegal options on item template ASN1_R_ILLEGAL_PADDING:221:illegal padding ASN1_R_ILLEGAL_TAGGED_ANY:127:illegal tagged any ASN1_R_ILLEGAL_TIME_VALUE:184:illegal time value ASN1_R_ILLEGAL_ZERO_CONTENT:222:illegal zero content ASN1_R_INTEGER_NOT_ASCII_FORMAT:185:integer not ascii format ASN1_R_INTEGER_TOO_LARGE_FOR_LONG:128:integer too large for long ASN1_R_INVALID_BIT_STRING_BITS_LEFT:220:invalid bit string bits left ASN1_R_INVALID_BMPSTRING_LENGTH:129:invalid bmpstring length ASN1_R_INVALID_DIGIT:130:invalid digit ASN1_R_INVALID_MIME_TYPE:205:invalid mime type ASN1_R_INVALID_MODIFIER:186:invalid modifier ASN1_R_INVALID_NUMBER:187:invalid number ASN1_R_INVALID_OBJECT_ENCODING:216:invalid object encoding ASN1_R_INVALID_SCRYPT_PARAMETERS:227:invalid scrypt parameters ASN1_R_INVALID_SEPARATOR:131:invalid separator ASN1_R_INVALID_STRING_TABLE_VALUE:218:invalid string table value ASN1_R_INVALID_UNIVERSALSTRING_LENGTH:133:invalid universalstring length ASN1_R_INVALID_UTF8STRING:134:invalid utf8string ASN1_R_INVALID_VALUE:219:invalid value ASN1_R_LENGTH_TOO_LONG:231:length too long ASN1_R_LIST_ERROR:188:list error ASN1_R_MIME_NO_CONTENT_TYPE:206:mime no content type ASN1_R_MIME_PARSE_ERROR:207:mime parse error ASN1_R_MIME_SIG_PARSE_ERROR:208:mime sig parse error ASN1_R_MISSING_EOC:137:missing eoc ASN1_R_MISSING_SECOND_NUMBER:138:missing second number ASN1_R_MISSING_VALUE:189:missing value ASN1_R_MSTRING_NOT_UNIVERSAL:139:mstring not universal ASN1_R_MSTRING_WRONG_TAG:140:mstring wrong tag ASN1_R_NESTED_ASN1_STRING:197:nested asn1 string ASN1_R_NESTED_TOO_DEEP:201:nested too deep ASN1_R_NON_HEX_CHARACTERS:141:non hex characters ASN1_R_NOT_ASCII_FORMAT:190:not ascii format ASN1_R_NOT_ENOUGH_DATA:142:not enough data ASN1_R_NO_CONTENT_TYPE:209:no content type ASN1_R_NO_MATCHING_CHOICE_TYPE:143:no matching choice type ASN1_R_NO_MULTIPART_BODY_FAILURE:210:no multipart body failure ASN1_R_NO_MULTIPART_BOUNDARY:211:no multipart boundary ASN1_R_NO_SIG_CONTENT_TYPE:212:no sig content type ASN1_R_NULL_IS_WRONG_LENGTH:144:null is wrong length ASN1_R_OBJECT_NOT_ASCII_FORMAT:191:object not ascii format ASN1_R_ODD_NUMBER_OF_CHARS:145:odd number of chars ASN1_R_SECOND_NUMBER_TOO_LARGE:147:second number too large ASN1_R_SEQUENCE_LENGTH_MISMATCH:148:sequence length mismatch ASN1_R_SEQUENCE_NOT_CONSTRUCTED:149:sequence not constructed ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG:192:sequence or set needs config ASN1_R_SHORT_LINE:150:short line ASN1_R_SIG_INVALID_MIME_TYPE:213:sig invalid mime type ASN1_R_STREAMING_NOT_SUPPORTED:202:streaming not supported ASN1_R_STRING_TOO_LONG:151:string too long ASN1_R_STRING_TOO_SHORT:152:string too short ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD:154:\ the asn1 object identifier is not known for this md ASN1_R_TIME_NOT_ASCII_FORMAT:193:time not ascii format ASN1_R_TOO_LARGE:223:too large ASN1_R_TOO_LONG:155:too long ASN1_R_TOO_SMALL:224:too small ASN1_R_TYPE_NOT_CONSTRUCTED:156:type not constructed ASN1_R_TYPE_NOT_PRIMITIVE:195:type not primitive ASN1_R_UNEXPECTED_EOC:159:unexpected eoc ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH:215:universalstring is wrong length ASN1_R_UNKNOWN_DIGEST:229:unknown digest ASN1_R_UNKNOWN_FORMAT:160:unknown format ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM:161:unknown message digest algorithm ASN1_R_UNKNOWN_OBJECT_TYPE:162:unknown object type ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE:163:unknown public key type ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM:199:unknown signature algorithm ASN1_R_UNKNOWN_TAG:194:unknown tag ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE:164:unsupported any defined by type ASN1_R_UNSUPPORTED_CIPHER:228:unsupported cipher ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE:167:unsupported public key type ASN1_R_UNSUPPORTED_TYPE:196:unsupported type ASN1_R_WRONG_INTEGER_TYPE:225:wrong integer type ASN1_R_WRONG_PUBLIC_KEY_TYPE:200:wrong public key type ASN1_R_WRONG_TAG:168:wrong tag ASYNC_R_FAILED_TO_SET_POOL:101:failed to set pool ASYNC_R_FAILED_TO_SWAP_CONTEXT:102:failed to swap context ASYNC_R_INIT_FAILED:105:init failed ASYNC_R_INVALID_POOL_SIZE:103:invalid pool size BIO_R_ACCEPT_ERROR:100:accept error BIO_R_ADDRINFO_ADDR_IS_NOT_AF_INET:141:addrinfo addr is not af inet BIO_R_AMBIGUOUS_HOST_OR_SERVICE:129:ambiguous host or service BIO_R_BAD_FOPEN_MODE:101:bad fopen mode BIO_R_BROKEN_PIPE:124:broken pipe BIO_R_CONNECT_ERROR:103:connect error BIO_R_CONNECT_TIMEOUT:147:connect timeout BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET:107:gethostbyname addr is not af inet BIO_R_GETSOCKNAME_ERROR:132:getsockname error BIO_R_GETSOCKNAME_TRUNCATED_ADDRESS:133:getsockname truncated address BIO_R_GETTING_SOCKTYPE:134:getting socktype BIO_R_INVALID_ARGUMENT:125:invalid argument BIO_R_INVALID_SOCKET:135:invalid socket BIO_R_IN_USE:123:in use BIO_R_LENGTH_TOO_LONG:102:length too long BIO_R_LISTEN_V6_ONLY:136:listen v6 only BIO_R_LOOKUP_RETURNED_NOTHING:142:lookup returned nothing BIO_R_MALFORMED_HOST_OR_SERVICE:130:malformed host or service BIO_R_NBIO_CONNECT_ERROR:110:nbio connect error BIO_R_NO_ACCEPT_ADDR_OR_SERVICE_SPECIFIED:143:\ no accept addr or service specified BIO_R_NO_HOSTNAME_OR_SERVICE_SPECIFIED:144:no hostname or service specified BIO_R_NO_PORT_DEFINED:113:no port defined BIO_R_NO_SUCH_FILE:128:no such file BIO_R_TRANSFER_ERROR:104:transfer error BIO_R_TRANSFER_TIMEOUT:105:transfer timeout BIO_R_UNABLE_TO_BIND_SOCKET:117:unable to bind socket BIO_R_UNABLE_TO_CREATE_SOCKET:118:unable to create socket BIO_R_UNABLE_TO_KEEPALIVE:137:unable to keepalive BIO_R_UNABLE_TO_LISTEN_SOCKET:119:unable to listen socket BIO_R_UNABLE_TO_NODELAY:138:unable to nodelay BIO_R_UNABLE_TO_REUSEADDR:139:unable to reuseaddr BIO_R_UNAVAILABLE_IP_FAMILY:145:unavailable ip family BIO_R_UNINITIALIZED:120:uninitialized BIO_R_UNKNOWN_INFO_TYPE:140:unknown info type BIO_R_UNSUPPORTED_IP_FAMILY:146:unsupported ip family BIO_R_UNSUPPORTED_METHOD:121:unsupported method BIO_R_UNSUPPORTED_PROTOCOL_FAMILY:131:unsupported protocol family BIO_R_WRITE_TO_READ_ONLY_BIO:126:write to read only BIO BIO_R_WSASTARTUP:122:WSAStartup BN_R_ARG2_LT_ARG3:100:arg2 lt arg3 BN_R_BAD_RECIPROCAL:101:bad reciprocal BN_R_BIGNUM_TOO_LONG:114:bignum too long BN_R_BITS_TOO_SMALL:118:bits too small BN_R_CALLED_WITH_EVEN_MODULUS:102:called with even modulus BN_R_DIV_BY_ZERO:103:div by zero BN_R_ENCODING_ERROR:104:encoding error BN_R_EXPAND_ON_STATIC_BIGNUM_DATA:105:expand on static bignum data BN_R_INPUT_NOT_REDUCED:110:input not reduced BN_R_INVALID_LENGTH:106:invalid length BN_R_INVALID_RANGE:115:invalid range BN_R_INVALID_SHIFT:119:invalid shift BN_R_NOT_A_SQUARE:111:not a square BN_R_NOT_INITIALIZED:107:not initialized BN_R_NO_INVERSE:108:no inverse BN_R_NO_PRIME_CANDIDATE:121:no prime candidate BN_R_NO_SOLUTION:116:no solution BN_R_NO_SUITABLE_DIGEST:120:no suitable digest BN_R_PRIVATE_KEY_TOO_LARGE:117:private key too large BN_R_P_IS_NOT_PRIME:112:p is not prime BN_R_TOO_MANY_ITERATIONS:113:too many iterations BN_R_TOO_MANY_TEMPORARY_VARIABLES:109:too many temporary variables CMP_R_ALGORITHM_NOT_SUPPORTED:139:algorithm not supported CMP_R_BAD_CHECKAFTER_IN_POLLREP:167:bad checkafter in pollrep CMP_R_BAD_REQUEST_ID:108:bad request id CMP_R_CERTHASH_UNMATCHED:156:certhash unmatched CMP_R_CERTID_NOT_FOUND:109:certid not found CMP_R_CERTIFICATE_NOT_ACCEPTED:169:certificate not accepted CMP_R_CERTIFICATE_NOT_FOUND:112:certificate not found CMP_R_CERTREQMSG_NOT_FOUND:157:certreqmsg not found CMP_R_CERTRESPONSE_NOT_FOUND:113:certresponse not found CMP_R_CERT_AND_KEY_DO_NOT_MATCH:114:cert and key do not match CMP_R_CHECKAFTER_OUT_OF_RANGE:181:checkafter out of range CMP_R_ENCOUNTERED_KEYUPDATEWARNING:176:encountered keyupdatewarning CMP_R_ENCOUNTERED_WAITING:162:encountered waiting CMP_R_ERROR_CALCULATING_PROTECTION:115:error calculating protection CMP_R_ERROR_CREATING_CERTCONF:116:error creating certconf CMP_R_ERROR_CREATING_CERTREP:117:error creating certrep CMP_R_ERROR_CREATING_CERTREQ:163:error creating certreq CMP_R_ERROR_CREATING_ERROR:118:error creating error CMP_R_ERROR_CREATING_GENM:119:error creating genm CMP_R_ERROR_CREATING_GENP:120:error creating genp CMP_R_ERROR_CREATING_PKICONF:122:error creating pkiconf CMP_R_ERROR_CREATING_POLLREP:123:error creating pollrep CMP_R_ERROR_CREATING_POLLREQ:124:error creating pollreq CMP_R_ERROR_CREATING_RP:125:error creating rp CMP_R_ERROR_CREATING_RR:126:error creating rr CMP_R_ERROR_PARSING_PKISTATUS:107:error parsing pkistatus CMP_R_ERROR_PROCESSING_MESSAGE:158:error processing message CMP_R_ERROR_PROTECTING_MESSAGE:127:error protecting message CMP_R_ERROR_SETTING_CERTHASH:128:error setting certhash CMP_R_ERROR_UNEXPECTED_CERTCONF:160:error unexpected certconf CMP_R_ERROR_VALIDATING_PROTECTION:140:error validating protection CMP_R_ERROR_VALIDATING_SIGNATURE:171:error validating signature CMP_R_FAILED_BUILDING_OWN_CHAIN:164:failed building own chain CMP_R_FAILED_EXTRACTING_PUBKEY:141:failed extracting pubkey CMP_R_FAILURE_OBTAINING_RANDOM:110:failure obtaining random CMP_R_FAIL_INFO_OUT_OF_RANGE:129:fail info out of range CMP_R_INVALID_ARGS:100:invalid args CMP_R_INVALID_OPTION:174:invalid option CMP_R_MISSING_CERTID:165:missing certid CMP_R_MISSING_KEY_INPUT_FOR_CREATING_PROTECTION:130:\ missing key input for creating protection CMP_R_MISSING_KEY_USAGE_DIGITALSIGNATURE:142:missing key usage digitalsignature CMP_R_MISSING_P10CSR:121:missing p10csr CMP_R_MISSING_PBM_SECRET:166:missing pbm secret CMP_R_MISSING_PRIVATE_KEY:131:missing private key CMP_R_MISSING_PRIVATE_KEY_FOR_POPO:190:missing private key for popo CMP_R_MISSING_PROTECTION:143:missing protection CMP_R_MISSING_PUBLIC_KEY:183:missing public key CMP_R_MISSING_REFERENCE_CERT:168:missing reference cert CMP_R_MISSING_SECRET:178:missing secret CMP_R_MISSING_SENDER_IDENTIFICATION:111:missing sender identification CMP_R_MISSING_TRUST_ANCHOR:179:missing trust anchor CMP_R_MISSING_TRUST_STORE:144:missing trust store CMP_R_MULTIPLE_REQUESTS_NOT_SUPPORTED:161:multiple requests not supported CMP_R_MULTIPLE_RESPONSES_NOT_SUPPORTED:170:multiple responses not supported CMP_R_MULTIPLE_SAN_SOURCES:102:multiple san sources CMP_R_NO_STDIO:194:no stdio CMP_R_NO_SUITABLE_SENDER_CERT:145:no suitable sender cert CMP_R_NULL_ARGUMENT:103:null argument CMP_R_PKIBODY_ERROR:146:pkibody error CMP_R_PKISTATUSINFO_NOT_FOUND:132:pkistatusinfo not found CMP_R_POLLING_FAILED:172:polling failed CMP_R_POTENTIALLY_INVALID_CERTIFICATE:147:potentially invalid certificate CMP_R_RECEIVED_ERROR:180:received error CMP_R_RECIPNONCE_UNMATCHED:148:recipnonce unmatched CMP_R_REQUEST_NOT_ACCEPTED:149:request not accepted CMP_R_REQUEST_REJECTED_BY_SERVER:182:request rejected by server CMP_R_SENDER_GENERALNAME_TYPE_NOT_SUPPORTED:150:\ sender generalname type not supported CMP_R_SRVCERT_DOES_NOT_VALIDATE_MSG:151:srvcert does not validate msg CMP_R_TOTAL_TIMEOUT:184:total timeout CMP_R_TRANSACTIONID_UNMATCHED:152:transactionid unmatched CMP_R_TRANSFER_ERROR:159:transfer error CMP_R_UNEXPECTED_PKIBODY:133:unexpected pkibody CMP_R_UNEXPECTED_PKISTATUS:185:unexpected pkistatus CMP_R_UNEXPECTED_PVNO:153:unexpected pvno CMP_R_UNKNOWN_ALGORITHM_ID:134:unknown algorithm id CMP_R_UNKNOWN_CERT_TYPE:135:unknown cert type CMP_R_UNKNOWN_PKISTATUS:186:unknown pkistatus CMP_R_UNSUPPORTED_ALGORITHM:136:unsupported algorithm CMP_R_UNSUPPORTED_KEY_TYPE:137:unsupported key type CMP_R_UNSUPPORTED_PROTECTION_ALG_DHBASEDMAC:154:\ unsupported protection alg dhbasedmac CMP_R_VALUE_TOO_LARGE:175:value too large CMP_R_VALUE_TOO_SMALL:177:value too small CMP_R_WRONG_ALGORITHM_OID:138:wrong algorithm oid CMP_R_WRONG_CERTID:189:wrong certid CMP_R_WRONG_CERTID_IN_RP:187:wrong certid in rp CMP_R_WRONG_PBM_VALUE:155:wrong pbm value CMP_R_WRONG_RP_COMPONENT_COUNT:188:wrong rp component count CMP_R_WRONG_SERIAL_IN_RP:173:wrong serial in rp CMS_R_ADD_SIGNER_ERROR:99:add signer error CMS_R_ATTRIBUTE_ERROR:161:attribute error CMS_R_CERTIFICATE_ALREADY_PRESENT:175:certificate already present CMS_R_CERTIFICATE_HAS_NO_KEYID:160:certificate has no keyid CMS_R_CERTIFICATE_VERIFY_ERROR:100:certificate verify error CMS_R_CIPHER_AEAD_SET_TAG_ERROR:184:cipher aead set tag error CMS_R_CIPHER_GET_TAG:185:cipher get tag CMS_R_CIPHER_INITIALISATION_ERROR:101:cipher initialisation error CMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR:102:\ cipher parameter initialisation error CMS_R_CMS_DATAFINAL_ERROR:103:cms datafinal error CMS_R_CMS_LIB:104:cms lib CMS_R_CONTENTIDENTIFIER_MISMATCH:170:contentidentifier mismatch CMS_R_CONTENT_NOT_FOUND:105:content not found CMS_R_CONTENT_TYPE_MISMATCH:171:content type mismatch CMS_R_CONTENT_TYPE_NOT_COMPRESSED_DATA:106:content type not compressed data CMS_R_CONTENT_TYPE_NOT_ENVELOPED_DATA:107:content type not enveloped data CMS_R_CONTENT_TYPE_NOT_SIGNED_DATA:108:content type not signed data CMS_R_CONTENT_VERIFY_ERROR:109:content verify error CMS_R_CTRL_ERROR:110:ctrl error CMS_R_CTRL_FAILURE:111:ctrl failure CMS_R_DECODE_ERROR:187:decode error CMS_R_DECRYPT_ERROR:112:decrypt error CMS_R_ERROR_GETTING_PUBLIC_KEY:113:error getting public key CMS_R_ERROR_READING_MESSAGEDIGEST_ATTRIBUTE:114:\ error reading messagedigest attribute CMS_R_ERROR_SETTING_KEY:115:error setting key CMS_R_ERROR_SETTING_RECIPIENTINFO:116:error setting recipientinfo CMS_R_ESS_SIGNING_CERTID_MISMATCH_ERROR:183:ess signing certid mismatch error CMS_R_INVALID_ENCRYPTED_KEY_LENGTH:117:invalid encrypted key length CMS_R_INVALID_KEY_ENCRYPTION_PARAMETER:176:invalid key encryption parameter CMS_R_INVALID_KEY_LENGTH:118:invalid key length CMS_R_INVALID_LABEL:190:invalid label CMS_R_INVALID_OAEP_PARAMETERS:191:invalid oaep parameters CMS_R_KDF_PARAMETER_ERROR:186:kdf parameter error CMS_R_MD_BIO_INIT_ERROR:119:md bio init error CMS_R_MESSAGEDIGEST_ATTRIBUTE_WRONG_LENGTH:120:\ messagedigest attribute wrong length CMS_R_MESSAGEDIGEST_WRONG_LENGTH:121:messagedigest wrong length CMS_R_MSGSIGDIGEST_ERROR:172:msgsigdigest error CMS_R_MSGSIGDIGEST_VERIFICATION_FAILURE:162:msgsigdigest verification failure CMS_R_MSGSIGDIGEST_WRONG_LENGTH:163:msgsigdigest wrong length CMS_R_NEED_ONE_SIGNER:164:need one signer CMS_R_NOT_A_SIGNED_RECEIPT:165:not a signed receipt CMS_R_NOT_ENCRYPTED_DATA:122:not encrypted data CMS_R_NOT_KEK:123:not kek CMS_R_NOT_KEY_AGREEMENT:181:not key agreement CMS_R_NOT_KEY_TRANSPORT:124:not key transport CMS_R_NOT_PWRI:177:not pwri CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE:125:not supported for this key type CMS_R_NO_CIPHER:126:no cipher CMS_R_NO_CONTENT:127:no content CMS_R_NO_CONTENT_TYPE:173:no content type CMS_R_NO_DEFAULT_DIGEST:128:no default digest CMS_R_NO_DIGEST_SET:129:no digest set CMS_R_NO_KEY:130:no key CMS_R_NO_KEY_OR_CERT:174:no key or cert CMS_R_NO_MATCHING_DIGEST:131:no matching digest CMS_R_NO_MATCHING_RECIPIENT:132:no matching recipient CMS_R_NO_MATCHING_SIGNATURE:166:no matching signature CMS_R_NO_MSGSIGDIGEST:167:no msgsigdigest CMS_R_NO_PASSWORD:178:no password CMS_R_NO_PRIVATE_KEY:133:no private key CMS_R_NO_PUBLIC_KEY:134:no public key CMS_R_NO_RECEIPT_REQUEST:168:no receipt request CMS_R_NO_SIGNERS:135:no signers CMS_R_PEER_KEY_ERROR:188:peer key error CMS_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE:136:\ private key does not match certificate CMS_R_RECEIPT_DECODE_ERROR:169:receipt decode error CMS_R_RECIPIENT_ERROR:137:recipient error CMS_R_SHARED_INFO_ERROR:189:shared info error CMS_R_SIGNER_CERTIFICATE_NOT_FOUND:138:signer certificate not found CMS_R_SIGNFINAL_ERROR:139:signfinal error CMS_R_SMIME_TEXT_ERROR:140:smime text error CMS_R_STORE_INIT_ERROR:141:store init error CMS_R_TYPE_NOT_COMPRESSED_DATA:142:type not compressed data CMS_R_TYPE_NOT_DATA:143:type not data CMS_R_TYPE_NOT_DIGESTED_DATA:144:type not digested data CMS_R_TYPE_NOT_ENCRYPTED_DATA:145:type not encrypted data CMS_R_TYPE_NOT_ENVELOPED_DATA:146:type not enveloped data CMS_R_UNABLE_TO_FINALIZE_CONTEXT:147:unable to finalize context CMS_R_UNKNOWN_CIPHER:148:unknown cipher CMS_R_UNKNOWN_DIGEST_ALGORITHM:149:unknown digest algorithm CMS_R_UNKNOWN_ID:150:unknown id CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM:151:unsupported compression algorithm CMS_R_UNSUPPORTED_CONTENT_ENCRYPTION_ALGORITHM:194:\ unsupported content encryption algorithm CMS_R_UNSUPPORTED_CONTENT_TYPE:152:unsupported content type CMS_R_UNSUPPORTED_ENCRYPTION_TYPE:192:unsupported encryption type CMS_R_UNSUPPORTED_KEK_ALGORITHM:153:unsupported kek algorithm CMS_R_UNSUPPORTED_KEY_ENCRYPTION_ALGORITHM:179:\ unsupported key encryption algorithm CMS_R_UNSUPPORTED_LABEL_SOURCE:193:unsupported label source CMS_R_UNSUPPORTED_RECIPIENTINFO_TYPE:155:unsupported recipientinfo type CMS_R_UNSUPPORTED_RECIPIENT_TYPE:154:unsupported recipient type +CMS_R_UNSUPPORTED_SIGNATURE_ALGORITHM:195:unsupported signature algorithm CMS_R_UNSUPPORTED_TYPE:156:unsupported type CMS_R_UNWRAP_ERROR:157:unwrap error CMS_R_UNWRAP_FAILURE:180:unwrap failure CMS_R_VERIFICATION_FAILURE:158:verification failure CMS_R_WRAP_ERROR:159:wrap error COMP_R_ZLIB_DEFLATE_ERROR:99:zlib deflate error COMP_R_ZLIB_INFLATE_ERROR:100:zlib inflate error COMP_R_ZLIB_NOT_SUPPORTED:101:zlib not supported CONF_R_ERROR_LOADING_DSO:110:error loading dso CONF_R_INVALID_PRAGMA:122:invalid pragma CONF_R_LIST_CANNOT_BE_NULL:115:list cannot be null CONF_R_MANDATORY_BRACES_IN_VARIABLE_EXPANSION:123:\ mandatory braces in variable expansion CONF_R_MISSING_CLOSE_SQUARE_BRACKET:100:missing close square bracket CONF_R_MISSING_EQUAL_SIGN:101:missing equal sign CONF_R_MISSING_INIT_FUNCTION:112:missing init function CONF_R_MODULE_INITIALIZATION_ERROR:109:module initialization error CONF_R_NO_CLOSE_BRACE:102:no close brace CONF_R_NO_CONF:105:no conf CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE:106:no conf or environment variable CONF_R_NO_SECTION:107:no section CONF_R_NO_SUCH_FILE:114:no such file CONF_R_NO_VALUE:108:no value CONF_R_NUMBER_TOO_LARGE:121:number too large CONF_R_OPENSSL_CONF_REFERENCES_MISSING_SECTION:124:\ openssl conf references missing section CONF_R_RECURSIVE_DIRECTORY_INCLUDE:111:recursive directory include CONF_R_RELATIVE_PATH:125:relative path CONF_R_SSL_COMMAND_SECTION_EMPTY:117:ssl command section empty CONF_R_SSL_COMMAND_SECTION_NOT_FOUND:118:ssl command section not found CONF_R_SSL_SECTION_EMPTY:119:ssl section empty CONF_R_SSL_SECTION_NOT_FOUND:120:ssl section not found CONF_R_UNABLE_TO_CREATE_NEW_SECTION:103:unable to create new section CONF_R_UNKNOWN_MODULE_NAME:113:unknown module name CONF_R_VARIABLE_EXPANSION_TOO_LONG:116:variable expansion too long CONF_R_VARIABLE_HAS_NO_VALUE:104:variable has no value CRMF_R_BAD_PBM_ITERATIONCOUNT:100:bad pbm iterationcount CRMF_R_CRMFERROR:102:crmferror CRMF_R_ERROR:103:error CRMF_R_ERROR_DECODING_CERTIFICATE:104:error decoding certificate CRMF_R_ERROR_DECRYPTING_CERTIFICATE:105:error decrypting certificate CRMF_R_ERROR_DECRYPTING_SYMMETRIC_KEY:106:error decrypting symmetric key CRMF_R_FAILURE_OBTAINING_RANDOM:107:failure obtaining random CRMF_R_ITERATIONCOUNT_BELOW_100:108:iterationcount below 100 CRMF_R_MALFORMED_IV:101:malformed iv CRMF_R_NULL_ARGUMENT:109:null argument CRMF_R_POPOSKINPUT_NOT_SUPPORTED:113:poposkinput not supported CRMF_R_POPO_INCONSISTENT_PUBLIC_KEY:117:popo inconsistent public key CRMF_R_POPO_MISSING:121:popo missing CRMF_R_POPO_MISSING_PUBLIC_KEY:118:popo missing public key CRMF_R_POPO_MISSING_SUBJECT:119:popo missing subject CRMF_R_POPO_RAVERIFIED_NOT_ACCEPTED:120:popo raverified not accepted CRMF_R_SETTING_MAC_ALGOR_FAILURE:110:setting mac algor failure CRMF_R_SETTING_OWF_ALGOR_FAILURE:111:setting owf algor failure CRMF_R_UNSUPPORTED_ALGORITHM:112:unsupported algorithm CRMF_R_UNSUPPORTED_CIPHER:114:unsupported cipher CRMF_R_UNSUPPORTED_METHOD_FOR_CREATING_POPO:115:\ unsupported method for creating popo CRMF_R_UNSUPPORTED_POPO_METHOD:116:unsupported popo method CRYPTO_R_BAD_ALGORITHM_NAME:117:bad algorithm name CRYPTO_R_CONFLICTING_NAMES:118:conflicting names CRYPTO_R_HEX_STRING_TOO_SHORT:121:hex string too short CRYPTO_R_ILLEGAL_HEX_DIGIT:102:illegal hex digit CRYPTO_R_INSUFFICIENT_DATA_SPACE:106:insufficient data space CRYPTO_R_INSUFFICIENT_PARAM_SIZE:107:insufficient param size CRYPTO_R_INSUFFICIENT_SECURE_DATA_SPACE:108:insufficient secure data space CRYPTO_R_INVALID_NEGATIVE_VALUE:122:invalid negative value CRYPTO_R_INVALID_NULL_ARGUMENT:109:invalid null argument CRYPTO_R_INVALID_OSSL_PARAM_TYPE:110:invalid ossl param type CRYPTO_R_ODD_NUMBER_OF_DIGITS:103:odd number of digits CRYPTO_R_PROVIDER_ALREADY_EXISTS:104:provider already exists CRYPTO_R_PROVIDER_SECTION_ERROR:105:provider section error CRYPTO_R_RANDOM_SECTION_ERROR:119:random section error CRYPTO_R_SECURE_MALLOC_FAILURE:111:secure malloc failure CRYPTO_R_STRING_TOO_LONG:112:string too long CRYPTO_R_TOO_MANY_BYTES:113:too many bytes CRYPTO_R_TOO_MANY_RECORDS:114:too many records CRYPTO_R_TOO_SMALL_BUFFER:116:too small buffer CRYPTO_R_UNKNOWN_NAME_IN_RANDOM_SECTION:120:unknown name in random section CRYPTO_R_ZERO_LENGTH_NUMBER:115:zero length number CT_R_BASE64_DECODE_ERROR:108:base64 decode error CT_R_INVALID_LOG_ID_LENGTH:100:invalid log id length CT_R_LOG_CONF_INVALID:109:log conf invalid CT_R_LOG_CONF_INVALID_KEY:110:log conf invalid key CT_R_LOG_CONF_MISSING_DESCRIPTION:111:log conf missing description CT_R_LOG_CONF_MISSING_KEY:112:log conf missing key CT_R_LOG_KEY_INVALID:113:log key invalid CT_R_SCT_FUTURE_TIMESTAMP:116:sct future timestamp CT_R_SCT_INVALID:104:sct invalid CT_R_SCT_INVALID_SIGNATURE:107:sct invalid signature CT_R_SCT_LIST_INVALID:105:sct list invalid CT_R_SCT_LOG_ID_MISMATCH:114:sct log id mismatch CT_R_SCT_NOT_SET:106:sct not set CT_R_SCT_UNSUPPORTED_VERSION:115:sct unsupported version CT_R_UNRECOGNIZED_SIGNATURE_NID:101:unrecognized signature nid CT_R_UNSUPPORTED_ENTRY_TYPE:102:unsupported entry type CT_R_UNSUPPORTED_VERSION:103:unsupported version DH_R_BAD_FFC_PARAMETERS:127:bad ffc parameters DH_R_BAD_GENERATOR:101:bad generator DH_R_BN_DECODE_ERROR:109:bn decode error DH_R_BN_ERROR:106:bn error DH_R_CHECK_INVALID_J_VALUE:115:check invalid j value DH_R_CHECK_INVALID_Q_VALUE:116:check invalid q value DH_R_CHECK_PUBKEY_INVALID:122:check pubkey invalid DH_R_CHECK_PUBKEY_TOO_LARGE:123:check pubkey too large DH_R_CHECK_PUBKEY_TOO_SMALL:124:check pubkey too small DH_R_CHECK_P_NOT_PRIME:117:check p not prime DH_R_CHECK_P_NOT_SAFE_PRIME:118:check p not safe prime DH_R_CHECK_Q_NOT_PRIME:119:check q not prime DH_R_DECODE_ERROR:104:decode error DH_R_INVALID_PARAMETER_NAME:110:invalid parameter name DH_R_INVALID_PARAMETER_NID:114:invalid parameter nid DH_R_INVALID_PUBKEY:102:invalid public key DH_R_INVALID_SECRET:128:invalid secret DH_R_KDF_PARAMETER_ERROR:112:kdf parameter error DH_R_KEYS_NOT_SET:108:keys not set DH_R_MISSING_PUBKEY:125:missing pubkey DH_R_MODULUS_TOO_LARGE:103:modulus too large DH_R_MODULUS_TOO_SMALL:126:modulus too small DH_R_NOT_SUITABLE_GENERATOR:120:not suitable generator DH_R_NO_PARAMETERS_SET:107:no parameters set DH_R_NO_PRIVATE_VALUE:100:no private value DH_R_PARAMETER_ENCODING_ERROR:105:parameter encoding error DH_R_PEER_KEY_ERROR:111:peer key error DH_R_SHARED_INFO_ERROR:113:shared info error DH_R_UNABLE_TO_CHECK_GENERATOR:121:unable to check generator DSA_R_BAD_FFC_PARAMETERS:114:bad ffc parameters DSA_R_BAD_Q_VALUE:102:bad q value DSA_R_BN_DECODE_ERROR:108:bn decode error DSA_R_BN_ERROR:109:bn error DSA_R_DECODE_ERROR:104:decode error DSA_R_INVALID_DIGEST_TYPE:106:invalid digest type DSA_R_INVALID_PARAMETERS:112:invalid parameters DSA_R_MISSING_PARAMETERS:101:missing parameters DSA_R_MISSING_PRIVATE_KEY:111:missing private key DSA_R_MODULUS_TOO_LARGE:103:modulus too large DSA_R_NO_PARAMETERS_SET:107:no parameters set DSA_R_PARAMETER_ENCODING_ERROR:105:parameter encoding error DSA_R_P_NOT_PRIME:115:p not prime DSA_R_Q_NOT_PRIME:113:q not prime DSA_R_SEED_LEN_SMALL:110:seed_len is less than the length of q DSA_R_TOO_MANY_RETRIES:116:too many retries DSO_R_CTRL_FAILED:100:control command failed DSO_R_DSO_ALREADY_LOADED:110:dso already loaded DSO_R_EMPTY_FILE_STRUCTURE:113:empty file structure DSO_R_FAILURE:114:failure DSO_R_FILENAME_TOO_BIG:101:filename too big DSO_R_FINISH_FAILED:102:cleanup method function failed DSO_R_INCORRECT_FILE_SYNTAX:115:incorrect file syntax DSO_R_LOAD_FAILED:103:could not load the shared library DSO_R_NAME_TRANSLATION_FAILED:109:name translation failed DSO_R_NO_FILENAME:111:no filename DSO_R_NULL_HANDLE:104:a null shared library handle was used DSO_R_SET_FILENAME_FAILED:112:set filename failed DSO_R_STACK_ERROR:105:the meth_data stack is corrupt DSO_R_SYM_FAILURE:106:could not bind to the requested symbol name DSO_R_UNLOAD_FAILED:107:could not unload the shared library DSO_R_UNSUPPORTED:108:functionality not supported EC_R_ASN1_ERROR:115:asn1 error EC_R_BAD_SIGNATURE:156:bad signature EC_R_BIGNUM_OUT_OF_RANGE:144:bignum out of range EC_R_BUFFER_TOO_SMALL:100:buffer too small EC_R_CANNOT_INVERT:165:cannot invert EC_R_COORDINATES_OUT_OF_RANGE:146:coordinates out of range EC_R_CURVE_DOES_NOT_SUPPORT_ECDH:160:curve does not support ecdh EC_R_CURVE_DOES_NOT_SUPPORT_ECDSA:170:curve does not support ecdsa EC_R_CURVE_DOES_NOT_SUPPORT_SIGNING:159:curve does not support signing EC_R_DECODE_ERROR:142:decode error EC_R_DISCRIMINANT_IS_ZERO:118:discriminant is zero EC_R_EC_GROUP_NEW_BY_NAME_FAILURE:119:ec group new by name failure EC_R_EXPLICIT_PARAMS_NOT_SUPPORTED:127:explicit params not supported EC_R_FAILED_MAKING_PUBLIC_KEY:166:failed making public key EC_R_FIELD_TOO_LARGE:143:field too large EC_R_GF2M_NOT_SUPPORTED:147:gf2m not supported EC_R_GROUP2PKPARAMETERS_FAILURE:120:group2pkparameters failure EC_R_I2D_ECPKPARAMETERS_FAILURE:121:i2d ecpkparameters failure EC_R_INCOMPATIBLE_OBJECTS:101:incompatible objects EC_R_INVALID_A:168:invalid a EC_R_INVALID_ARGUMENT:112:invalid argument EC_R_INVALID_B:169:invalid b EC_R_INVALID_COFACTOR:171:invalid cofactor EC_R_INVALID_COMPRESSED_POINT:110:invalid compressed point EC_R_INVALID_COMPRESSION_BIT:109:invalid compression bit EC_R_INVALID_CURVE:141:invalid curve EC_R_INVALID_DIGEST:151:invalid digest EC_R_INVALID_DIGEST_TYPE:138:invalid digest type EC_R_INVALID_ENCODING:102:invalid encoding EC_R_INVALID_FIELD:103:invalid field EC_R_INVALID_FORM:104:invalid form EC_R_INVALID_GENERATOR:173:invalid generator EC_R_INVALID_GROUP_ORDER:122:invalid group order EC_R_INVALID_KEY:116:invalid key EC_R_INVALID_LENGTH:117:invalid length EC_R_INVALID_NAMED_GROUP_CONVERSION:174:invalid named group conversion EC_R_INVALID_OUTPUT_LENGTH:161:invalid output length EC_R_INVALID_P:172:invalid p EC_R_INVALID_PEER_KEY:133:invalid peer key EC_R_INVALID_PENTANOMIAL_BASIS:132:invalid pentanomial basis EC_R_INVALID_PRIVATE_KEY:123:invalid private key EC_R_INVALID_SEED:175:invalid seed EC_R_INVALID_TRINOMIAL_BASIS:137:invalid trinomial basis EC_R_KDF_PARAMETER_ERROR:148:kdf parameter error EC_R_KEYS_NOT_SET:140:keys not set EC_R_LADDER_POST_FAILURE:136:ladder post failure EC_R_LADDER_PRE_FAILURE:153:ladder pre failure EC_R_LADDER_STEP_FAILURE:162:ladder step failure EC_R_MISSING_OID:167:missing OID EC_R_MISSING_PARAMETERS:124:missing parameters EC_R_MISSING_PRIVATE_KEY:125:missing private key EC_R_NEED_NEW_SETUP_VALUES:157:need new setup values EC_R_NOT_A_NIST_PRIME:135:not a NIST prime EC_R_NOT_IMPLEMENTED:126:not implemented EC_R_NOT_INITIALIZED:111:not initialized EC_R_NO_PARAMETERS_SET:139:no parameters set EC_R_NO_PRIVATE_VALUE:154:no private value EC_R_OPERATION_NOT_SUPPORTED:152:operation not supported EC_R_PASSED_NULL_PARAMETER:134:passed null parameter EC_R_PEER_KEY_ERROR:149:peer key error EC_R_POINT_ARITHMETIC_FAILURE:155:point arithmetic failure EC_R_POINT_AT_INFINITY:106:point at infinity EC_R_POINT_COORDINATES_BLIND_FAILURE:163:point coordinates blind failure EC_R_POINT_IS_NOT_ON_CURVE:107:point is not on curve EC_R_RANDOM_NUMBER_GENERATION_FAILED:158:random number generation failed EC_R_SHARED_INFO_ERROR:150:shared info error EC_R_SLOT_FULL:108:slot full EC_R_TOO_MANY_RETRIES:176:too many retries EC_R_UNDEFINED_GENERATOR:113:undefined generator EC_R_UNDEFINED_ORDER:128:undefined order EC_R_UNKNOWN_COFACTOR:164:unknown cofactor EC_R_UNKNOWN_GROUP:129:unknown group EC_R_UNKNOWN_ORDER:114:unknown order EC_R_UNSUPPORTED_FIELD:131:unsupported field EC_R_WRONG_CURVE_PARAMETERS:145:wrong curve parameters EC_R_WRONG_ORDER:130:wrong order ENGINE_R_ALREADY_LOADED:100:already loaded ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER:133:argument is not a number ENGINE_R_CMD_NOT_EXECUTABLE:134:cmd not executable ENGINE_R_COMMAND_TAKES_INPUT:135:command takes input ENGINE_R_COMMAND_TAKES_NO_INPUT:136:command takes no input ENGINE_R_CONFLICTING_ENGINE_ID:103:conflicting engine id ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED:119:ctrl command not implemented ENGINE_R_DSO_FAILURE:104:DSO failure ENGINE_R_DSO_NOT_FOUND:132:dso not found ENGINE_R_ENGINES_SECTION_ERROR:148:engines section error ENGINE_R_ENGINE_CONFIGURATION_ERROR:102:engine configuration error ENGINE_R_ENGINE_IS_NOT_IN_LIST:105:engine is not in the list ENGINE_R_ENGINE_SECTION_ERROR:149:engine section error ENGINE_R_FAILED_LOADING_PRIVATE_KEY:128:failed loading private key ENGINE_R_FAILED_LOADING_PUBLIC_KEY:129:failed loading public key ENGINE_R_FINISH_FAILED:106:finish failed ENGINE_R_ID_OR_NAME_MISSING:108:'id' or 'name' missing ENGINE_R_INIT_FAILED:109:init failed ENGINE_R_INTERNAL_LIST_ERROR:110:internal list error ENGINE_R_INVALID_ARGUMENT:143:invalid argument ENGINE_R_INVALID_CMD_NAME:137:invalid cmd name ENGINE_R_INVALID_CMD_NUMBER:138:invalid cmd number ENGINE_R_INVALID_INIT_VALUE:151:invalid init value ENGINE_R_INVALID_STRING:150:invalid string ENGINE_R_NOT_INITIALISED:117:not initialised ENGINE_R_NOT_LOADED:112:not loaded ENGINE_R_NO_CONTROL_FUNCTION:120:no control function ENGINE_R_NO_INDEX:144:no index ENGINE_R_NO_LOAD_FUNCTION:125:no load function ENGINE_R_NO_REFERENCE:130:no reference ENGINE_R_NO_SUCH_ENGINE:116:no such engine ENGINE_R_UNIMPLEMENTED_CIPHER:146:unimplemented cipher ENGINE_R_UNIMPLEMENTED_DIGEST:147:unimplemented digest ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD:101:unimplemented public key method ENGINE_R_VERSION_INCOMPATIBILITY:145:version incompatibility ESS_R_EMPTY_ESS_CERT_ID_LIST:107:empty ess cert id list ESS_R_ESS_CERT_DIGEST_ERROR:103:ess cert digest error ESS_R_ESS_CERT_ID_NOT_FOUND:104:ess cert id not found ESS_R_ESS_CERT_ID_WRONG_ORDER:105:ess cert id wrong order ESS_R_ESS_DIGEST_ALG_UNKNOWN:106:ess digest alg unknown ESS_R_ESS_SIGNING_CERTIFICATE_ERROR:102:ess signing certificate error ESS_R_ESS_SIGNING_CERT_ADD_ERROR:100:ess signing cert add error ESS_R_ESS_SIGNING_CERT_V2_ADD_ERROR:101:ess signing cert v2 add error ESS_R_MISSING_SIGNING_CERTIFICATE_ATTRIBUTE:108:\ missing signing certificate attribute EVP_R_AES_KEY_SETUP_FAILED:143:aes key setup failed EVP_R_ARIA_KEY_SETUP_FAILED:176:aria key setup failed EVP_R_BAD_ALGORITHM_NAME:200:bad algorithm name EVP_R_BAD_DECRYPT:100:bad decrypt EVP_R_BAD_KEY_LENGTH:195:bad key length EVP_R_BUFFER_TOO_SMALL:155:buffer too small EVP_R_CACHE_CONSTANTS_FAILED:225:cache constants failed EVP_R_CAMELLIA_KEY_SETUP_FAILED:157:camellia key setup failed EVP_R_CANNOT_GET_PARAMETERS:197:cannot get parameters EVP_R_CANNOT_SET_PARAMETERS:198:cannot set parameters EVP_R_CIPHER_NOT_GCM_MODE:184:cipher not gcm mode EVP_R_CIPHER_PARAMETER_ERROR:122:cipher parameter error EVP_R_COMMAND_NOT_SUPPORTED:147:command not supported EVP_R_CONFLICTING_ALGORITHM_NAME:201:conflicting algorithm name EVP_R_COPY_ERROR:173:copy error EVP_R_CTRL_NOT_IMPLEMENTED:132:ctrl not implemented EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED:133:ctrl operation not implemented EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH:138:data not multiple of block length EVP_R_DECODE_ERROR:114:decode error EVP_R_DEFAULT_QUERY_PARSE_ERROR:210:default query parse error EVP_R_DIFFERENT_KEY_TYPES:101:different key types EVP_R_DIFFERENT_PARAMETERS:153:different parameters EVP_R_ERROR_LOADING_SECTION:165:error loading section EVP_R_EXPECTING_AN_HMAC_KEY:174:expecting an hmac key EVP_R_EXPECTING_AN_RSA_KEY:127:expecting an rsa key EVP_R_EXPECTING_A_DH_KEY:128:expecting a dh key EVP_R_EXPECTING_A_DSA_KEY:129:expecting a dsa key EVP_R_EXPECTING_A_ECX_KEY:219:expecting an ecx key EVP_R_EXPECTING_A_EC_KEY:142:expecting an ec key EVP_R_EXPECTING_A_POLY1305_KEY:164:expecting a poly1305 key EVP_R_EXPECTING_A_SIPHASH_KEY:175:expecting a siphash key EVP_R_FINAL_ERROR:188:final error EVP_R_GENERATE_ERROR:214:generate error EVP_R_GET_RAW_KEY_FAILED:182:get raw key failed EVP_R_ILLEGAL_SCRYPT_PARAMETERS:171:illegal scrypt parameters EVP_R_INACCESSIBLE_DOMAIN_PARAMETERS:204:inaccessible domain parameters EVP_R_INACCESSIBLE_KEY:203:inaccessible key EVP_R_INITIALIZATION_ERROR:134:initialization error EVP_R_INPUT_NOT_INITIALIZED:111:input not initialized EVP_R_INVALID_CUSTOM_LENGTH:185:invalid custom length EVP_R_INVALID_DIGEST:152:invalid digest EVP_R_INVALID_IV_LENGTH:194:invalid iv length EVP_R_INVALID_KEY:163:invalid key EVP_R_INVALID_KEY_LENGTH:130:invalid key length EVP_R_INVALID_LENGTH:221:invalid length EVP_R_INVALID_NULL_ALGORITHM:218:invalid null algorithm EVP_R_INVALID_OPERATION:148:invalid operation EVP_R_INVALID_PROVIDER_FUNCTIONS:193:invalid provider functions EVP_R_INVALID_SALT_LENGTH:186:invalid salt length EVP_R_INVALID_SECRET_LENGTH:223:invalid secret length EVP_R_INVALID_SEED_LENGTH:220:invalid seed length EVP_R_INVALID_VALUE:222:invalid value EVP_R_KEYMGMT_EXPORT_FAILURE:205:keymgmt export failure EVP_R_KEY_SETUP_FAILED:180:key setup failed EVP_R_LOCKING_NOT_SUPPORTED:213:locking not supported EVP_R_MEMORY_LIMIT_EXCEEDED:172:memory limit exceeded EVP_R_MESSAGE_DIGEST_IS_NULL:159:message digest is null EVP_R_METHOD_NOT_SUPPORTED:144:method not supported EVP_R_MISSING_PARAMETERS:103:missing parameters EVP_R_NOT_ABLE_TO_COPY_CTX:190:not able to copy ctx EVP_R_NOT_XOF_OR_INVALID_LENGTH:178:not XOF or invalid length EVP_R_NO_CIPHER_SET:131:no cipher set EVP_R_NO_DEFAULT_DIGEST:158:no default digest EVP_R_NO_DIGEST_SET:139:no digest set EVP_R_NO_IMPORT_FUNCTION:206:no import function EVP_R_NO_KEYMGMT_AVAILABLE:199:no keymgmt available EVP_R_NO_KEYMGMT_PRESENT:196:no keymgmt present EVP_R_NO_KEY_SET:154:no key set EVP_R_NO_OPERATION_SET:149:no operation set EVP_R_NULL_MAC_PKEY_CTX:208:null mac pkey ctx EVP_R_ONLY_ONESHOT_SUPPORTED:177:only oneshot supported EVP_R_OPERATION_NOT_INITIALIZED:151:operation not initialized EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE:150:\ operation not supported for this keytype EVP_R_OUTPUT_WOULD_OVERFLOW:202:output would overflow EVP_R_PARAMETER_TOO_LARGE:187:parameter too large EVP_R_PARTIALLY_OVERLAPPING:162:partially overlapping buffers EVP_R_PBKDF2_ERROR:181:pbkdf2 error EVP_R_PKEY_APPLICATION_ASN1_METHOD_ALREADY_REGISTERED:179:\ pkey application asn1 method already registered EVP_R_PRIVATE_KEY_DECODE_ERROR:145:private key decode error EVP_R_PRIVATE_KEY_ENCODE_ERROR:146:private key encode error EVP_R_PUBLIC_KEY_NOT_RSA:106:public key not rsa EVP_R_SETTING_XOF_FAILED:227:setting xof failed EVP_R_SET_DEFAULT_PROPERTY_FAILURE:209:set default property failure EVP_R_TOO_MANY_RECORDS:183:too many records EVP_R_UNABLE_TO_ENABLE_LOCKING:212:unable to enable locking EVP_R_UNABLE_TO_GET_MAXIMUM_REQUEST_SIZE:215:unable to get maximum request size EVP_R_UNABLE_TO_GET_RANDOM_STRENGTH:216:unable to get random strength EVP_R_UNABLE_TO_LOCK_CONTEXT:211:unable to lock context EVP_R_UNABLE_TO_SET_CALLBACKS:217:unable to set callbacks EVP_R_UNKNOWN_CIPHER:160:unknown cipher EVP_R_UNKNOWN_DIGEST:161:unknown digest EVP_R_UNKNOWN_KEY_TYPE:207:unknown key type EVP_R_UNKNOWN_OPTION:169:unknown option EVP_R_UNKNOWN_PBE_ALGORITHM:121:unknown pbe algorithm EVP_R_UNSUPPORTED_ALGORITHM:156:unsupported algorithm EVP_R_UNSUPPORTED_CIPHER:107:unsupported cipher EVP_R_UNSUPPORTED_KEYLENGTH:123:unsupported keylength EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION:124:\ unsupported key derivation function EVP_R_UNSUPPORTED_KEY_SIZE:108:unsupported key size EVP_R_UNSUPPORTED_KEY_TYPE:224:unsupported key type EVP_R_UNSUPPORTED_NUMBER_OF_ROUNDS:135:unsupported number of rounds EVP_R_UNSUPPORTED_PRF:125:unsupported prf EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM:118:unsupported private key algorithm EVP_R_UNSUPPORTED_SALT_TYPE:126:unsupported salt type EVP_R_UPDATE_ERROR:189:update error EVP_R_WRAP_MODE_NOT_ALLOWED:170:wrap mode not allowed EVP_R_WRONG_FINAL_BLOCK_LENGTH:109:wrong final block length EVP_R_XTS_DATA_UNIT_IS_TOO_LARGE:191:xts data unit is too large EVP_R_XTS_DUPLICATED_KEYS:192:xts duplicated keys HTTP_R_ASN1_LEN_EXCEEDS_MAX_RESP_LEN:108:asn1 len exceeds max resp len HTTP_R_CONNECT_FAILURE:100:connect failure HTTP_R_ERROR_PARSING_ASN1_LENGTH:109:error parsing asn1 length HTTP_R_ERROR_PARSING_CONTENT_LENGTH:119:error parsing content length HTTP_R_ERROR_PARSING_URL:101:error parsing url HTTP_R_ERROR_RECEIVING:103:error receiving HTTP_R_ERROR_SENDING:102:error sending HTTP_R_FAILED_READING_DATA:128:failed reading data HTTP_R_HEADER_PARSE_ERROR:126:header parse error HTTP_R_INCONSISTENT_CONTENT_LENGTH:120:inconsistent content length HTTP_R_INVALID_PORT_NUMBER:123:invalid port number HTTP_R_INVALID_URL_PATH:125:invalid url path HTTP_R_INVALID_URL_SCHEME:124:invalid url scheme HTTP_R_MAX_RESP_LEN_EXCEEDED:117:max resp len exceeded HTTP_R_MISSING_ASN1_ENCODING:110:missing asn1 encoding HTTP_R_MISSING_CONTENT_TYPE:121:missing content type HTTP_R_MISSING_REDIRECT_LOCATION:111:missing redirect location HTTP_R_RECEIVED_ERROR:105:received error HTTP_R_RECEIVED_WRONG_HTTP_VERSION:106:received wrong http version HTTP_R_REDIRECTION_FROM_HTTPS_TO_HTTP:112:redirection from https to http HTTP_R_REDIRECTION_NOT_ENABLED:116:redirection not enabled HTTP_R_RESPONSE_LINE_TOO_LONG:113:response line too long HTTP_R_RESPONSE_PARSE_ERROR:104:response parse error HTTP_R_RETRY_TIMEOUT:129:retry timeout HTTP_R_SERVER_CANCELED_CONNECTION:127:server canceled connection HTTP_R_SOCK_NOT_SUPPORTED:122:sock not supported HTTP_R_STATUS_CODE_UNSUPPORTED:114:status code unsupported HTTP_R_TLS_NOT_ENABLED:107:tls not enabled HTTP_R_TOO_MANY_REDIRECTIONS:115:too many redirections HTTP_R_UNEXPECTED_CONTENT_TYPE:118:unexpected content type OBJ_R_OID_EXISTS:102:oid exists OBJ_R_UNKNOWN_NID:101:unknown nid OBJ_R_UNKNOWN_OBJECT_NAME:103:unknown object name OCSP_R_CERTIFICATE_VERIFY_ERROR:101:certificate verify error OCSP_R_DIGEST_ERR:102:digest err OCSP_R_DIGEST_NAME_ERR:106:digest name err OCSP_R_DIGEST_SIZE_ERR:107:digest size err OCSP_R_ERROR_IN_NEXTUPDATE_FIELD:122:error in nextupdate field OCSP_R_ERROR_IN_THISUPDATE_FIELD:123:error in thisupdate field OCSP_R_MISSING_OCSPSIGNING_USAGE:103:missing ocspsigning usage OCSP_R_NEXTUPDATE_BEFORE_THISUPDATE:124:nextupdate before thisupdate OCSP_R_NOT_BASIC_RESPONSE:104:not basic response OCSP_R_NO_CERTIFICATES_IN_CHAIN:105:no certificates in chain OCSP_R_NO_RESPONSE_DATA:108:no response data OCSP_R_NO_REVOKED_TIME:109:no revoked time OCSP_R_NO_SIGNER_KEY:130:no signer key OCSP_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE:110:\ private key does not match certificate OCSP_R_REQUEST_NOT_SIGNED:128:request not signed OCSP_R_RESPONSE_CONTAINS_NO_REVOCATION_DATA:111:\ response contains no revocation data OCSP_R_ROOT_CA_NOT_TRUSTED:112:root ca not trusted OCSP_R_SIGNATURE_FAILURE:117:signature failure OCSP_R_SIGNER_CERTIFICATE_NOT_FOUND:118:signer certificate not found OCSP_R_STATUS_EXPIRED:125:status expired OCSP_R_STATUS_NOT_YET_VALID:126:status not yet valid OCSP_R_STATUS_TOO_OLD:127:status too old OCSP_R_UNKNOWN_MESSAGE_DIGEST:119:unknown message digest OCSP_R_UNKNOWN_NID:120:unknown nid OCSP_R_UNSUPPORTED_REQUESTORNAME_TYPE:129:unsupported requestorname type OSSL_DECODER_R_COULD_NOT_DECODE_OBJECT:101:could not decode object OSSL_DECODER_R_DECODER_NOT_FOUND:102:decoder not found OSSL_DECODER_R_MISSING_GET_PARAMS:100:missing get params OSSL_ENCODER_R_ENCODER_NOT_FOUND:101:encoder not found OSSL_ENCODER_R_INCORRECT_PROPERTY_QUERY:100:incorrect property query OSSL_ENCODER_R_MISSING_GET_PARAMS:102:missing get params OSSL_STORE_R_AMBIGUOUS_CONTENT_TYPE:107:ambiguous content type OSSL_STORE_R_BAD_PASSWORD_READ:115:bad password read OSSL_STORE_R_ERROR_VERIFYING_PKCS12_MAC:113:error verifying pkcs12 mac OSSL_STORE_R_FINGERPRINT_SIZE_DOES_NOT_MATCH_DIGEST:121:\ fingerprint size does not match digest OSSL_STORE_R_INVALID_SCHEME:106:invalid scheme OSSL_STORE_R_IS_NOT_A:112:is not a OSSL_STORE_R_LOADER_INCOMPLETE:116:loader incomplete OSSL_STORE_R_LOADING_STARTED:117:loading started OSSL_STORE_R_NOT_A_CERTIFICATE:100:not a certificate OSSL_STORE_R_NOT_A_CRL:101:not a crl OSSL_STORE_R_NOT_A_NAME:103:not a name OSSL_STORE_R_NOT_A_PRIVATE_KEY:102:not a private key OSSL_STORE_R_NOT_A_PUBLIC_KEY:122:not a public key OSSL_STORE_R_NOT_PARAMETERS:104:not parameters OSSL_STORE_R_NO_LOADERS_FOUND:123:no loaders found OSSL_STORE_R_PASSPHRASE_CALLBACK_ERROR:114:passphrase callback error OSSL_STORE_R_PATH_MUST_BE_ABSOLUTE:108:path must be absolute OSSL_STORE_R_SEARCH_ONLY_SUPPORTED_FOR_DIRECTORIES:119:\ search only supported for directories OSSL_STORE_R_UI_PROCESS_INTERRUPTED_OR_CANCELLED:109:\ ui process interrupted or cancelled OSSL_STORE_R_UNREGISTERED_SCHEME:105:unregistered scheme OSSL_STORE_R_UNSUPPORTED_CONTENT_TYPE:110:unsupported content type OSSL_STORE_R_UNSUPPORTED_OPERATION:118:unsupported operation OSSL_STORE_R_UNSUPPORTED_SEARCH_TYPE:120:unsupported search type OSSL_STORE_R_URI_AUTHORITY_UNSUPPORTED:111:uri authority unsupported PEM_R_BAD_BASE64_DECODE:100:bad base64 decode PEM_R_BAD_DECRYPT:101:bad decrypt PEM_R_BAD_END_LINE:102:bad end line PEM_R_BAD_IV_CHARS:103:bad iv chars PEM_R_BAD_MAGIC_NUMBER:116:bad magic number PEM_R_BAD_PASSWORD_READ:104:bad password read PEM_R_BAD_VERSION_NUMBER:117:bad version number PEM_R_BIO_WRITE_FAILURE:118:bio write failure PEM_R_CIPHER_IS_NULL:127:cipher is null PEM_R_ERROR_CONVERTING_PRIVATE_KEY:115:error converting private key PEM_R_EXPECTING_DSS_KEY_BLOB:131:expecting dss key blob PEM_R_EXPECTING_PRIVATE_KEY_BLOB:119:expecting private key blob PEM_R_EXPECTING_PUBLIC_KEY_BLOB:120:expecting public key blob PEM_R_EXPECTING_RSA_KEY_BLOB:132:expecting rsa key blob PEM_R_HEADER_TOO_LONG:128:header too long PEM_R_INCONSISTENT_HEADER:121:inconsistent header PEM_R_KEYBLOB_HEADER_PARSE_ERROR:122:keyblob header parse error PEM_R_KEYBLOB_TOO_SHORT:123:keyblob too short PEM_R_MISSING_DEK_IV:129:missing dek iv PEM_R_NOT_DEK_INFO:105:not dek info PEM_R_NOT_ENCRYPTED:106:not encrypted PEM_R_NOT_PROC_TYPE:107:not proc type PEM_R_NO_START_LINE:108:no start line PEM_R_PROBLEMS_GETTING_PASSWORD:109:problems getting password PEM_R_PVK_DATA_TOO_SHORT:124:pvk data too short PEM_R_PVK_TOO_SHORT:125:pvk too short PEM_R_READ_KEY:111:read key PEM_R_SHORT_HEADER:112:short header PEM_R_UNEXPECTED_DEK_IV:130:unexpected dek iv PEM_R_UNSUPPORTED_CIPHER:113:unsupported cipher PEM_R_UNSUPPORTED_ENCRYPTION:114:unsupported encryption PEM_R_UNSUPPORTED_KEY_COMPONENTS:126:unsupported key components PEM_R_UNSUPPORTED_PUBLIC_KEY_TYPE:110:unsupported public key type PKCS12_R_CANT_PACK_STRUCTURE:100:cant pack structure PKCS12_R_CONTENT_TYPE_NOT_DATA:121:content type not data PKCS12_R_DECODE_ERROR:101:decode error PKCS12_R_ENCODE_ERROR:102:encode error PKCS12_R_ENCRYPT_ERROR:103:encrypt error PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE:120:error setting encrypted data type PKCS12_R_INVALID_NULL_ARGUMENT:104:invalid null argument PKCS12_R_INVALID_NULL_PKCS12_POINTER:105:invalid null pkcs12 pointer PKCS12_R_INVALID_TYPE:112:invalid type PKCS12_R_IV_GEN_ERROR:106:iv gen error PKCS12_R_KEY_GEN_ERROR:107:key gen error PKCS12_R_MAC_ABSENT:108:mac absent PKCS12_R_MAC_GENERATION_ERROR:109:mac generation error PKCS12_R_MAC_SETUP_ERROR:110:mac setup error PKCS12_R_MAC_STRING_SET_ERROR:111:mac string set error PKCS12_R_MAC_VERIFY_FAILURE:113:mac verify failure PKCS12_R_PARSE_ERROR:114:parse error PKCS12_R_PKCS12_CIPHERFINAL_ERROR:116:pkcs12 cipherfinal error PKCS12_R_UNKNOWN_DIGEST_ALGORITHM:118:unknown digest algorithm PKCS12_R_UNSUPPORTED_PKCS12_MODE:119:unsupported pkcs12 mode PKCS7_R_CERTIFICATE_VERIFY_ERROR:117:certificate verify error PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER:144:cipher has no object identifier PKCS7_R_CIPHER_NOT_INITIALIZED:116:cipher not initialized PKCS7_R_CONTENT_AND_DATA_PRESENT:118:content and data present PKCS7_R_CTRL_ERROR:152:ctrl error PKCS7_R_DECRYPT_ERROR:119:decrypt error PKCS7_R_DIGEST_FAILURE:101:digest failure PKCS7_R_ENCRYPTION_CTRL_FAILURE:149:encryption ctrl failure PKCS7_R_ENCRYPTION_NOT_SUPPORTED_FOR_THIS_KEY_TYPE:150:\ encryption not supported for this key type PKCS7_R_ERROR_ADDING_RECIPIENT:120:error adding recipient PKCS7_R_ERROR_SETTING_CIPHER:121:error setting cipher PKCS7_R_INVALID_NULL_POINTER:143:invalid null pointer PKCS7_R_INVALID_SIGNED_DATA_TYPE:155:invalid signed data type PKCS7_R_NO_CONTENT:122:no content PKCS7_R_NO_DEFAULT_DIGEST:151:no default digest PKCS7_R_NO_MATCHING_DIGEST_TYPE_FOUND:154:no matching digest type found PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE:115:no recipient matches certificate PKCS7_R_NO_SIGNATURES_ON_DATA:123:no signatures on data PKCS7_R_NO_SIGNERS:142:no signers PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE:104:\ operation not supported on this type PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR:124:pkcs7 add signature error PKCS7_R_PKCS7_ADD_SIGNER_ERROR:153:pkcs7 add signer error PKCS7_R_PKCS7_DATASIGN:145:pkcs7 datasign PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE:127:\ private key does not match certificate PKCS7_R_SIGNATURE_FAILURE:105:signature failure PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND:128:signer certificate not found PKCS7_R_SIGNING_CTRL_FAILURE:147:signing ctrl failure PKCS7_R_SIGNING_NOT_SUPPORTED_FOR_THIS_KEY_TYPE:148:\ signing not supported for this key type PKCS7_R_SMIME_TEXT_ERROR:129:smime text error PKCS7_R_UNABLE_TO_FIND_CERTIFICATE:106:unable to find certificate PKCS7_R_UNABLE_TO_FIND_MEM_BIO:107:unable to find mem bio PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST:108:unable to find message digest PKCS7_R_UNKNOWN_DIGEST_TYPE:109:unknown digest type PKCS7_R_UNKNOWN_OPERATION:110:unknown operation PKCS7_R_UNSUPPORTED_CIPHER_TYPE:111:unsupported cipher type PKCS7_R_UNSUPPORTED_CONTENT_TYPE:112:unsupported content type PKCS7_R_WRONG_CONTENT_TYPE:113:wrong content type PKCS7_R_WRONG_PKCS7_TYPE:114:wrong pkcs7 type PROP_R_NAME_TOO_LONG:100:name too long PROP_R_NOT_AN_ASCII_CHARACTER:101:not an ascii character PROP_R_NOT_AN_HEXADECIMAL_DIGIT:102:not an hexadecimal digit PROP_R_NOT_AN_IDENTIFIER:103:not an identifier PROP_R_NOT_AN_OCTAL_DIGIT:104:not an octal digit PROP_R_NOT_A_DECIMAL_DIGIT:105:not a decimal digit PROP_R_NO_MATCHING_STRING_DELIMITER:106:no matching string delimiter PROP_R_NO_VALUE:107:no value PROP_R_PARSE_FAILED:108:parse failed PROP_R_STRING_TOO_LONG:109:string too long PROP_R_TRAILING_CHARACTERS:110:trailing characters PROV_R_ADDITIONAL_INPUT_TOO_LONG:184:additional input too long PROV_R_ALGORITHM_MISMATCH:173:algorithm mismatch PROV_R_ALREADY_INSTANTIATED:185:already instantiated PROV_R_BAD_DECRYPT:100:bad decrypt PROV_R_BAD_ENCODING:141:bad encoding PROV_R_BAD_LENGTH:142:bad length PROV_R_BAD_TLS_CLIENT_VERSION:161:bad tls client version PROV_R_BN_ERROR:160:bn error PROV_R_CIPHER_OPERATION_FAILED:102:cipher operation failed PROV_R_DERIVATION_FUNCTION_INIT_FAILED:205:derivation function init failed PROV_R_DIGEST_NOT_ALLOWED:174:digest not allowed PROV_R_ENTROPY_SOURCE_STRENGTH_TOO_WEAK:186:entropy source strength too weak PROV_R_ERROR_INSTANTIATING_DRBG:188:error instantiating drbg PROV_R_ERROR_RETRIEVING_ENTROPY:189:error retrieving entropy PROV_R_ERROR_RETRIEVING_NONCE:190:error retrieving nonce PROV_R_FAILED_DURING_DERIVATION:164:failed during derivation PROV_R_FAILED_TO_CREATE_LOCK:180:failed to create lock PROV_R_FAILED_TO_DECRYPT:162:failed to decrypt PROV_R_FAILED_TO_GENERATE_KEY:121:failed to generate key PROV_R_FAILED_TO_GET_PARAMETER:103:failed to get parameter PROV_R_FAILED_TO_SET_PARAMETER:104:failed to set parameter PROV_R_FAILED_TO_SIGN:175:failed to sign PROV_R_FIPS_MODULE_CONDITIONAL_ERROR:227:fips module conditional error PROV_R_FIPS_MODULE_ENTERING_ERROR_STATE:224:fips module entering error state PROV_R_FIPS_MODULE_IN_ERROR_STATE:225:fips module in error state PROV_R_GENERATE_ERROR:191:generate error PROV_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE:165:\ illegal or unsupported padding mode PROV_R_INDICATOR_INTEGRITY_FAILURE:210:indicator integrity failure PROV_R_INSUFFICIENT_DRBG_STRENGTH:181:insufficient drbg strength PROV_R_INVALID_AAD:108:invalid aad PROV_R_INVALID_CONFIG_DATA:211:invalid config data PROV_R_INVALID_CONSTANT_LENGTH:157:invalid constant length PROV_R_INVALID_CURVE:176:invalid curve PROV_R_INVALID_CUSTOM_LENGTH:111:invalid custom length PROV_R_INVALID_DATA:115:invalid data PROV_R_INVALID_DIGEST:122:invalid digest PROV_R_INVALID_DIGEST_LENGTH:166:invalid digest length PROV_R_INVALID_DIGEST_SIZE:218:invalid digest size PROV_R_INVALID_INPUT_LENGTH:230:invalid input length PROV_R_INVALID_ITERATION_COUNT:123:invalid iteration count PROV_R_INVALID_IV_LENGTH:109:invalid iv length PROV_R_INVALID_KEY:158:invalid key PROV_R_INVALID_KEY_LENGTH:105:invalid key length PROV_R_INVALID_MAC:151:invalid mac PROV_R_INVALID_MGF1_MD:167:invalid mgf1 md PROV_R_INVALID_MODE:125:invalid mode PROV_R_INVALID_OUTPUT_LENGTH:217:invalid output length PROV_R_INVALID_PADDING_MODE:168:invalid padding mode PROV_R_INVALID_PUBINFO:198:invalid pubinfo PROV_R_INVALID_SALT_LENGTH:112:invalid salt length PROV_R_INVALID_SEED_LENGTH:154:invalid seed length PROV_R_INVALID_SIGNATURE_SIZE:179:invalid signature size PROV_R_INVALID_STATE:212:invalid state PROV_R_INVALID_TAG:110:invalid tag PROV_R_INVALID_TAG_LENGTH:118:invalid tag length PROV_R_INVALID_UKM_LENGTH:200:invalid ukm length PROV_R_INVALID_X931_DIGEST:170:invalid x931 digest PROV_R_IN_ERROR_STATE:192:in error state PROV_R_KEY_SETUP_FAILED:101:key setup failed PROV_R_KEY_SIZE_TOO_SMALL:171:key size too small PROV_R_LENGTH_TOO_LARGE:202:length too large PROV_R_MISMATCHING_DOMAIN_PARAMETERS:203:mismatching domain parameters PROV_R_MISSING_CEK_ALG:144:missing cek alg PROV_R_MISSING_CIPHER:155:missing cipher PROV_R_MISSING_CONFIG_DATA:213:missing config data PROV_R_MISSING_CONSTANT:156:missing constant PROV_R_MISSING_KEY:128:missing key PROV_R_MISSING_MAC:150:missing mac PROV_R_MISSING_MESSAGE_DIGEST:129:missing message digest PROV_R_MISSING_OID:209:missing OID PROV_R_MISSING_PASS:130:missing pass PROV_R_MISSING_SALT:131:missing salt PROV_R_MISSING_SECRET:132:missing secret PROV_R_MISSING_SEED:140:missing seed PROV_R_MISSING_SESSION_ID:133:missing session id PROV_R_MISSING_TYPE:134:missing type PROV_R_MISSING_XCGHASH:135:missing xcghash PROV_R_MODULE_INTEGRITY_FAILURE:214:module integrity failure PROV_R_NOT_A_PRIVATE_KEY:221:not a private key PROV_R_NOT_A_PUBLIC_KEY:220:not a public key PROV_R_NOT_INSTANTIATED:193:not instantiated PROV_R_NOT_PARAMETERS:226:not parameters PROV_R_NOT_SUPPORTED:136:not supported PROV_R_NOT_XOF_OR_INVALID_LENGTH:113:not xof or invalid length PROV_R_NO_KEY_SET:114:no key set PROV_R_NO_PARAMETERS_SET:177:no parameters set PROV_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE:178:\ operation not supported for this keytype PROV_R_OUTPUT_BUFFER_TOO_SMALL:106:output buffer too small PROV_R_PARENT_CANNOT_GENERATE_RANDOM_NUMBERS:228:\ parent cannot generate random numbers PROV_R_PARENT_CANNOT_SUPPLY_ENTROPY_SEED:187:parent cannot supply entropy seed PROV_R_PARENT_LOCKING_NOT_ENABLED:182:parent locking not enabled PROV_R_PARENT_STRENGTH_TOO_WEAK:194:parent strength too weak PROV_R_PATH_MUST_BE_ABSOLUTE:219:path must be absolute PROV_R_PERSONALISATION_STRING_TOO_LONG:195:personalisation string too long PROV_R_PSS_SALTLEN_TOO_SMALL:172:pss saltlen too small PROV_R_REQUEST_TOO_LARGE_FOR_DRBG:196:request too large for drbg PROV_R_REQUIRE_CTR_MODE_CIPHER:206:require ctr mode cipher PROV_R_RESEED_ERROR:197:reseed error PROV_R_SEARCH_ONLY_SUPPORTED_FOR_DIRECTORIES:222:\ search only supported for directories PROV_R_SEED_SOURCES_MUST_NOT_HAVE_A_PARENT:229:\ seed sources must not have a parent PROV_R_SELF_TEST_KAT_FAILURE:215:self test kat failure PROV_R_SELF_TEST_POST_FAILURE:216:self test post failure PROV_R_TAG_NOT_NEEDED:120:tag not needed PROV_R_TAG_NOT_SET:119:tag not set PROV_R_TOO_MANY_RECORDS:126:too many records PROV_R_UNABLE_TO_FIND_CIPHERS:207:unable to find ciphers PROV_R_UNABLE_TO_GET_PARENT_STRENGTH:199:unable to get parent strength PROV_R_UNABLE_TO_GET_PASSPHRASE:159:unable to get passphrase PROV_R_UNABLE_TO_INITIALISE_CIPHERS:208:unable to initialise ciphers PROV_R_UNABLE_TO_LOAD_SHA256:147:unable to load sha256 PROV_R_UNABLE_TO_LOCK_PARENT:201:unable to lock parent PROV_R_UNABLE_TO_RESEED:204:unable to reseed PROV_R_UNSUPPORTED_CEK_ALG:145:unsupported cek alg PROV_R_UNSUPPORTED_KEY_SIZE:153:unsupported key size PROV_R_UNSUPPORTED_MAC_TYPE:137:unsupported mac type PROV_R_UNSUPPORTED_NUMBER_OF_ROUNDS:152:unsupported number of rounds PROV_R_URI_AUTHORITY_UNSUPPORTED:223:uri authority unsupported PROV_R_VALUE_ERROR:138:value error PROV_R_WRONG_FINAL_BLOCK_LENGTH:107:wrong final block length PROV_R_WRONG_OUTPUT_BUFFER_SIZE:139:wrong output buffer size PROV_R_XOF_DIGESTS_NOT_ALLOWED:183:xof digests not allowed PROV_R_XTS_DATA_UNIT_IS_TOO_LARGE:148:xts data unit is too large PROV_R_XTS_DUPLICATED_KEYS:149:xts duplicated keys RAND_R_ADDITIONAL_INPUT_TOO_LONG:102:additional input too long RAND_R_ALREADY_INSTANTIATED:103:already instantiated RAND_R_ARGUMENT_OUT_OF_RANGE:105:argument out of range RAND_R_CANNOT_OPEN_FILE:121:Cannot open file RAND_R_DRBG_ALREADY_INITIALIZED:129:drbg already initialized RAND_R_DRBG_NOT_INITIALISED:104:drbg not initialised RAND_R_ENTROPY_INPUT_TOO_LONG:106:entropy input too long RAND_R_ENTROPY_OUT_OF_RANGE:124:entropy out of range RAND_R_ERROR_ENTROPY_POOL_WAS_IGNORED:127:error entropy pool was ignored RAND_R_ERROR_INITIALISING_DRBG:107:error initialising drbg RAND_R_ERROR_INSTANTIATING_DRBG:108:error instantiating drbg RAND_R_ERROR_RETRIEVING_ADDITIONAL_INPUT:109:error retrieving additional input RAND_R_ERROR_RETRIEVING_ENTROPY:110:error retrieving entropy RAND_R_ERROR_RETRIEVING_NONCE:111:error retrieving nonce RAND_R_FAILED_TO_CREATE_LOCK:126:failed to create lock RAND_R_FUNC_NOT_IMPLEMENTED:101:Function not implemented RAND_R_FWRITE_ERROR:123:Error writing file RAND_R_GENERATE_ERROR:112:generate error RAND_R_INSUFFICIENT_DRBG_STRENGTH:139:insufficient drbg strength RAND_R_INTERNAL_ERROR:113:internal error RAND_R_IN_ERROR_STATE:114:in error state RAND_R_NOT_A_REGULAR_FILE:122:Not a regular file RAND_R_NOT_INSTANTIATED:115:not instantiated RAND_R_NO_DRBG_IMPLEMENTATION_SELECTED:128:no drbg implementation selected RAND_R_PARENT_LOCKING_NOT_ENABLED:130:parent locking not enabled RAND_R_PARENT_STRENGTH_TOO_WEAK:131:parent strength too weak RAND_R_PERSONALISATION_STRING_TOO_LONG:116:personalisation string too long RAND_R_PREDICTION_RESISTANCE_NOT_SUPPORTED:133:\ prediction resistance not supported RAND_R_PRNG_NOT_SEEDED:100:PRNG not seeded RAND_R_RANDOM_POOL_OVERFLOW:125:random pool overflow RAND_R_RANDOM_POOL_UNDERFLOW:134:random pool underflow RAND_R_REQUEST_TOO_LARGE_FOR_DRBG:117:request too large for drbg RAND_R_RESEED_ERROR:118:reseed error RAND_R_SELFTEST_FAILURE:119:selftest failure RAND_R_TOO_LITTLE_NONCE_REQUESTED:135:too little nonce requested RAND_R_TOO_MUCH_NONCE_REQUESTED:136:too much nonce requested RAND_R_UNABLE_TO_CREATE_DRBG:143:unable to create drbg RAND_R_UNABLE_TO_FETCH_DRBG:144:unable to fetch drbg RAND_R_UNABLE_TO_GET_PARENT_RESEED_PROP_COUNTER:141:\ unable to get parent reseed prop counter RAND_R_UNABLE_TO_GET_PARENT_STRENGTH:138:unable to get parent strength RAND_R_UNABLE_TO_LOCK_PARENT:140:unable to lock parent RAND_R_UNSUPPORTED_DRBG_FLAGS:132:unsupported drbg flags RAND_R_UNSUPPORTED_DRBG_TYPE:120:unsupported drbg type RSA_R_ALGORITHM_MISMATCH:100:algorithm mismatch RSA_R_BAD_E_VALUE:101:bad e value RSA_R_BAD_FIXED_HEADER_DECRYPT:102:bad fixed header decrypt RSA_R_BAD_PAD_BYTE_COUNT:103:bad pad byte count RSA_R_BAD_SIGNATURE:104:bad signature RSA_R_BLOCK_TYPE_IS_NOT_01:106:block type is not 01 RSA_R_BLOCK_TYPE_IS_NOT_02:107:block type is not 02 RSA_R_DATA_GREATER_THAN_MOD_LEN:108:data greater than mod len RSA_R_DATA_TOO_LARGE:109:data too large RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE:110:data too large for key size RSA_R_DATA_TOO_LARGE_FOR_MODULUS:132:data too large for modulus RSA_R_DATA_TOO_SMALL:111:data too small RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE:122:data too small for key size RSA_R_DIGEST_DOES_NOT_MATCH:158:digest does not match RSA_R_DIGEST_NOT_ALLOWED:145:digest not allowed RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY:112:digest too big for rsa key RSA_R_DMP1_NOT_CONGRUENT_TO_D:124:dmp1 not congruent to d RSA_R_DMQ1_NOT_CONGRUENT_TO_D:125:dmq1 not congruent to d RSA_R_D_E_NOT_CONGRUENT_TO_1:123:d e not congruent to 1 RSA_R_FIRST_OCTET_INVALID:133:first octet invalid RSA_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE:144:\ illegal or unsupported padding mode RSA_R_INVALID_DIGEST:157:invalid digest RSA_R_INVALID_DIGEST_LENGTH:143:invalid digest length RSA_R_INVALID_HEADER:137:invalid header RSA_R_INVALID_KEYPAIR:171:invalid keypair RSA_R_INVALID_KEY_LENGTH:173:invalid key length RSA_R_INVALID_LABEL:160:invalid label RSA_R_INVALID_LENGTH:181:invalid length RSA_R_INVALID_MESSAGE_LENGTH:131:invalid message length RSA_R_INVALID_MGF1_MD:156:invalid mgf1 md RSA_R_INVALID_MODULUS:174:invalid modulus RSA_R_INVALID_MULTI_PRIME_KEY:167:invalid multi prime key RSA_R_INVALID_OAEP_PARAMETERS:161:invalid oaep parameters RSA_R_INVALID_PADDING:138:invalid padding RSA_R_INVALID_PADDING_MODE:141:invalid padding mode RSA_R_INVALID_PSS_PARAMETERS:149:invalid pss parameters RSA_R_INVALID_PSS_SALTLEN:146:invalid pss saltlen RSA_R_INVALID_REQUEST:175:invalid request RSA_R_INVALID_SALT_LENGTH:150:invalid salt length RSA_R_INVALID_STRENGTH:176:invalid strength RSA_R_INVALID_TRAILER:139:invalid trailer RSA_R_INVALID_X931_DIGEST:142:invalid x931 digest RSA_R_IQMP_NOT_INVERSE_OF_Q:126:iqmp not inverse of q RSA_R_KEY_PRIME_NUM_INVALID:165:key prime num invalid RSA_R_KEY_SIZE_TOO_SMALL:120:key size too small RSA_R_LAST_OCTET_INVALID:134:last octet invalid RSA_R_MGF1_DIGEST_NOT_ALLOWED:152:mgf1 digest not allowed RSA_R_MISSING_PRIVATE_KEY:179:missing private key RSA_R_MODULUS_TOO_LARGE:105:modulus too large RSA_R_MP_COEFFICIENT_NOT_INVERSE_OF_R:168:mp coefficient not inverse of r RSA_R_MP_EXPONENT_NOT_CONGRUENT_TO_D:169:mp exponent not congruent to d RSA_R_MP_R_NOT_PRIME:170:mp r not prime RSA_R_NO_PUBLIC_EXPONENT:140:no public exponent RSA_R_NULL_BEFORE_BLOCK_MISSING:113:null before block missing RSA_R_N_DOES_NOT_EQUAL_PRODUCT_OF_PRIMES:172:n does not equal product of primes RSA_R_N_DOES_NOT_EQUAL_P_Q:127:n does not equal p q RSA_R_OAEP_DECODING_ERROR:121:oaep decoding error RSA_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE:148:\ operation not supported for this keytype RSA_R_PADDING_CHECK_FAILED:114:padding check failed RSA_R_PAIRWISE_TEST_FAILURE:177:pairwise test failure RSA_R_PKCS_DECODING_ERROR:159:pkcs decoding error RSA_R_PSS_SALTLEN_TOO_SMALL:164:pss saltlen too small RSA_R_PUB_EXPONENT_OUT_OF_RANGE:178:pub exponent out of range RSA_R_P_NOT_PRIME:128:p not prime RSA_R_Q_NOT_PRIME:129:q not prime RSA_R_RANDOMNESS_SOURCE_STRENGTH_INSUFFICIENT:180:\ randomness source strength insufficient RSA_R_RSA_OPERATIONS_NOT_SUPPORTED:130:rsa operations not supported RSA_R_SLEN_CHECK_FAILED:136:salt length check failed RSA_R_SLEN_RECOVERY_FAILED:135:salt length recovery failed RSA_R_SSLV3_ROLLBACK_ATTACK:115:sslv3 rollback attack RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD:116:\ the asn1 object identifier is not known for this md RSA_R_UNKNOWN_ALGORITHM_TYPE:117:unknown algorithm type RSA_R_UNKNOWN_DIGEST:166:unknown digest RSA_R_UNKNOWN_MASK_DIGEST:151:unknown mask digest RSA_R_UNKNOWN_PADDING_TYPE:118:unknown padding type RSA_R_UNSUPPORTED_ENCRYPTION_TYPE:162:unsupported encryption type RSA_R_UNSUPPORTED_LABEL_SOURCE:163:unsupported label source RSA_R_UNSUPPORTED_MASK_ALGORITHM:153:unsupported mask algorithm RSA_R_UNSUPPORTED_MASK_PARAMETER:154:unsupported mask parameter RSA_R_UNSUPPORTED_SIGNATURE_TYPE:155:unsupported signature type RSA_R_VALUE_MISSING:147:value missing RSA_R_WRONG_SIGNATURE_LENGTH:119:wrong signature length SM2_R_ASN1_ERROR:100:asn1 error SM2_R_BAD_SIGNATURE:101:bad signature SM2_R_BUFFER_TOO_SMALL:107:buffer too small SM2_R_DIST_ID_TOO_LARGE:110:dist id too large SM2_R_ID_NOT_SET:112:id not set SM2_R_ID_TOO_LARGE:111:id too large SM2_R_INVALID_CURVE:108:invalid curve SM2_R_INVALID_DIGEST:102:invalid digest SM2_R_INVALID_DIGEST_TYPE:103:invalid digest type SM2_R_INVALID_ENCODING:104:invalid encoding SM2_R_INVALID_FIELD:105:invalid field SM2_R_INVALID_PRIVATE_KEY:113:invalid private key SM2_R_NO_PARAMETERS_SET:109:no parameters set SM2_R_USER_ID_TOO_LARGE:106:user id too large SSL_R_APPLICATION_DATA_AFTER_CLOSE_NOTIFY:291:\ application data after close notify SSL_R_APP_DATA_IN_HANDSHAKE:100:app data in handshake SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT:272:\ attempt to reuse session in different context SSL_R_AT_LEAST_TLS_1_2_NEEDED_IN_SUITEB_MODE:158:\ at least (D)TLS 1.2 needed in Suite B mode SSL_R_BAD_CHANGE_CIPHER_SPEC:103:bad change cipher spec SSL_R_BAD_CIPHER:186:bad cipher SSL_R_BAD_DATA:390:bad data SSL_R_BAD_DATA_RETURNED_BY_CALLBACK:106:bad data returned by callback SSL_R_BAD_DECOMPRESSION:107:bad decompression SSL_R_BAD_DH_VALUE:102:bad dh value SSL_R_BAD_DIGEST_LENGTH:111:bad digest length SSL_R_BAD_EARLY_DATA:233:bad early data SSL_R_BAD_ECC_CERT:304:bad ecc cert SSL_R_BAD_ECPOINT:306:bad ecpoint SSL_R_BAD_EXTENSION:110:bad extension SSL_R_BAD_HANDSHAKE_LENGTH:332:bad handshake length SSL_R_BAD_HANDSHAKE_STATE:236:bad handshake state SSL_R_BAD_HELLO_REQUEST:105:bad hello request SSL_R_BAD_HRR_VERSION:263:bad hrr version SSL_R_BAD_KEY_SHARE:108:bad key share SSL_R_BAD_KEY_UPDATE:122:bad key update SSL_R_BAD_LEGACY_VERSION:292:bad legacy version SSL_R_BAD_LENGTH:271:bad length SSL_R_BAD_PACKET:240:bad packet SSL_R_BAD_PACKET_LENGTH:115:bad packet length SSL_R_BAD_PROTOCOL_VERSION_NUMBER:116:bad protocol version number SSL_R_BAD_PSK:219:bad psk SSL_R_BAD_PSK_IDENTITY:114:bad psk identity SSL_R_BAD_RECORD_TYPE:443:bad record type SSL_R_BAD_RSA_ENCRYPT:119:bad rsa encrypt SSL_R_BAD_SIGNATURE:123:bad signature SSL_R_BAD_SRP_A_LENGTH:347:bad srp a length SSL_R_BAD_SRP_PARAMETERS:371:bad srp parameters SSL_R_BAD_SRTP_MKI_VALUE:352:bad srtp mki value SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST:353:bad srtp protection profile list SSL_R_BAD_SSL_FILETYPE:124:bad ssl filetype SSL_R_BAD_VALUE:384:bad value SSL_R_BAD_WRITE_RETRY:127:bad write retry SSL_R_BINDER_DOES_NOT_VERIFY:253:binder does not verify SSL_R_BIO_NOT_SET:128:bio not set SSL_R_BLOCK_CIPHER_PAD_IS_WRONG:129:block cipher pad is wrong SSL_R_BN_LIB:130:bn lib SSL_R_CALLBACK_FAILED:234:callback failed SSL_R_CANNOT_CHANGE_CIPHER:109:cannot change cipher SSL_R_CANNOT_GET_GROUP_NAME:299:cannot get group name SSL_R_CA_DN_LENGTH_MISMATCH:131:ca dn length mismatch SSL_R_CA_KEY_TOO_SMALL:397:ca key too small SSL_R_CA_MD_TOO_WEAK:398:ca md too weak SSL_R_CCS_RECEIVED_EARLY:133:ccs received early SSL_R_CERTIFICATE_VERIFY_FAILED:134:certificate verify failed SSL_R_CERT_CB_ERROR:377:cert cb error SSL_R_CERT_LENGTH_MISMATCH:135:cert length mismatch SSL_R_CIPHERSUITE_DIGEST_HAS_CHANGED:218:ciphersuite digest has changed SSL_R_CIPHER_CODE_WRONG_LENGTH:137:cipher code wrong length SSL_R_CLIENTHELLO_TLSEXT:226:clienthello tlsext SSL_R_COMPRESSED_LENGTH_TOO_LONG:140:compressed length too long SSL_R_COMPRESSION_DISABLED:343:compression disabled SSL_R_COMPRESSION_FAILURE:141:compression failure SSL_R_COMPRESSION_ID_NOT_WITHIN_PRIVATE_RANGE:307:\ compression id not within private range SSL_R_COMPRESSION_LIBRARY_ERROR:142:compression library error SSL_R_CONNECTION_TYPE_NOT_SET:144:connection type not set SSL_R_CONTEXT_NOT_DANE_ENABLED:167:context not dane enabled SSL_R_COOKIE_GEN_CALLBACK_FAILURE:400:cookie gen callback failure SSL_R_COOKIE_MISMATCH:308:cookie mismatch SSL_R_COPY_PARAMETERS_FAILED:296:copy parameters failed SSL_R_CUSTOM_EXT_HANDLER_ALREADY_INSTALLED:206:\ custom ext handler already installed SSL_R_DANE_ALREADY_ENABLED:172:dane already enabled SSL_R_DANE_CANNOT_OVERRIDE_MTYPE_FULL:173:dane cannot override mtype full SSL_R_DANE_NOT_ENABLED:175:dane not enabled SSL_R_DANE_TLSA_BAD_CERTIFICATE:180:dane tlsa bad certificate SSL_R_DANE_TLSA_BAD_CERTIFICATE_USAGE:184:dane tlsa bad certificate usage SSL_R_DANE_TLSA_BAD_DATA_LENGTH:189:dane tlsa bad data length SSL_R_DANE_TLSA_BAD_DIGEST_LENGTH:192:dane tlsa bad digest length SSL_R_DANE_TLSA_BAD_MATCHING_TYPE:200:dane tlsa bad matching type SSL_R_DANE_TLSA_BAD_PUBLIC_KEY:201:dane tlsa bad public key SSL_R_DANE_TLSA_BAD_SELECTOR:202:dane tlsa bad selector SSL_R_DANE_TLSA_NULL_DATA:203:dane tlsa null data SSL_R_DATA_BETWEEN_CCS_AND_FINISHED:145:data between ccs and finished SSL_R_DATA_LENGTH_TOO_LONG:146:data length too long SSL_R_DECRYPTION_FAILED:147:decryption failed SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC:281:\ decryption failed or bad record mac SSL_R_DH_KEY_TOO_SMALL:394:dh key too small SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG:148:dh public value length is wrong SSL_R_DIGEST_CHECK_FAILED:149:digest check failed SSL_R_DTLS_MESSAGE_TOO_BIG:334:dtls message too big SSL_R_DUPLICATE_COMPRESSION_ID:309:duplicate compression id SSL_R_ECC_CERT_NOT_FOR_SIGNING:318:ecc cert not for signing SSL_R_ECDH_REQUIRED_FOR_SUITEB_MODE:374:ecdh required for suiteb mode SSL_R_EE_KEY_TOO_SMALL:399:ee key too small SSL_R_EMPTY_SRTP_PROTECTION_PROFILE_LIST:354:empty srtp protection profile list SSL_R_ENCRYPTED_LENGTH_TOO_LONG:150:encrypted length too long SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST:151:error in received cipher list SSL_R_ERROR_SETTING_TLSA_BASE_DOMAIN:204:error setting tlsa base domain SSL_R_EXCEEDS_MAX_FRAGMENT_SIZE:194:exceeds max fragment size SSL_R_EXCESSIVE_MESSAGE_SIZE:152:excessive message size SSL_R_EXTENSION_NOT_RECEIVED:279:extension not received SSL_R_EXTRA_DATA_IN_MESSAGE:153:extra data in message SSL_R_EXT_LENGTH_MISMATCH:163:ext length mismatch SSL_R_FAILED_TO_INIT_ASYNC:405:failed to init async SSL_R_FRAGMENTED_CLIENT_HELLO:401:fragmented client hello SSL_R_GOT_A_FIN_BEFORE_A_CCS:154:got a fin before a ccs SSL_R_HTTPS_PROXY_REQUEST:155:https proxy request SSL_R_HTTP_REQUEST:156:http request SSL_R_ILLEGAL_POINT_COMPRESSION:162:illegal point compression SSL_R_ILLEGAL_SUITEB_DIGEST:380:illegal Suite B digest SSL_R_INAPPROPRIATE_FALLBACK:373:inappropriate fallback SSL_R_INCONSISTENT_COMPRESSION:340:inconsistent compression SSL_R_INCONSISTENT_EARLY_DATA_ALPN:222:inconsistent early data alpn SSL_R_INCONSISTENT_EARLY_DATA_SNI:231:inconsistent early data sni SSL_R_INCONSISTENT_EXTMS:104:inconsistent extms SSL_R_INSUFFICIENT_SECURITY:241:insufficient security SSL_R_INVALID_ALERT:205:invalid alert SSL_R_INVALID_CCS_MESSAGE:260:invalid ccs message SSL_R_INVALID_CERTIFICATE_OR_ALG:238:invalid certificate or alg SSL_R_INVALID_COMMAND:280:invalid command SSL_R_INVALID_COMPRESSION_ALGORITHM:341:invalid compression algorithm SSL_R_INVALID_CONFIG:283:invalid config SSL_R_INVALID_CONFIGURATION_NAME:113:invalid configuration name SSL_R_INVALID_CONTEXT:282:invalid context SSL_R_INVALID_CT_VALIDATION_TYPE:212:invalid ct validation type SSL_R_INVALID_KEY_UPDATE_TYPE:120:invalid key update type SSL_R_INVALID_MAX_EARLY_DATA:174:invalid max early data SSL_R_INVALID_NULL_CMD_NAME:385:invalid null cmd name SSL_R_INVALID_SEQUENCE_NUMBER:402:invalid sequence number SSL_R_INVALID_SERVERINFO_DATA:388:invalid serverinfo data SSL_R_INVALID_SESSION_ID:999:invalid session id SSL_R_INVALID_SRP_USERNAME:357:invalid srp username SSL_R_INVALID_STATUS_RESPONSE:328:invalid status response SSL_R_INVALID_TICKET_KEYS_LENGTH:325:invalid ticket keys length SSL_R_LEGACY_SIGALG_DISALLOWED_OR_UNSUPPORTED:333:\ legacy sigalg disallowed or unsupported SSL_R_LENGTH_MISMATCH:159:length mismatch SSL_R_LENGTH_TOO_LONG:404:length too long SSL_R_LENGTH_TOO_SHORT:160:length too short SSL_R_LIBRARY_BUG:274:library bug SSL_R_LIBRARY_HAS_NO_CIPHERS:161:library has no ciphers SSL_R_MISSING_DSA_SIGNING_CERT:165:missing dsa signing cert SSL_R_MISSING_ECDSA_SIGNING_CERT:381:missing ecdsa signing cert SSL_R_MISSING_FATAL:256:missing fatal SSL_R_MISSING_PARAMETERS:290:missing parameters SSL_R_MISSING_PSK_KEX_MODES_EXTENSION:310:missing psk kex modes extension SSL_R_MISSING_RSA_CERTIFICATE:168:missing rsa certificate SSL_R_MISSING_RSA_ENCRYPTING_CERT:169:missing rsa encrypting cert SSL_R_MISSING_RSA_SIGNING_CERT:170:missing rsa signing cert SSL_R_MISSING_SIGALGS_EXTENSION:112:missing sigalgs extension SSL_R_MISSING_SIGNING_CERT:221:missing signing cert SSL_R_MISSING_SRP_PARAM:358:can't find SRP server param SSL_R_MISSING_SUPPORTED_GROUPS_EXTENSION:209:missing supported groups extension SSL_R_MISSING_TMP_DH_KEY:171:missing tmp dh key SSL_R_MISSING_TMP_ECDH_KEY:311:missing tmp ecdh key SSL_R_MIXED_HANDSHAKE_AND_NON_HANDSHAKE_DATA:293:\ mixed handshake and non handshake data SSL_R_NOT_ON_RECORD_BOUNDARY:182:not on record boundary SSL_R_NOT_REPLACING_CERTIFICATE:289:not replacing certificate SSL_R_NOT_SERVER:284:not server SSL_R_NO_APPLICATION_PROTOCOL:235:no application protocol SSL_R_NO_CERTIFICATES_RETURNED:176:no certificates returned SSL_R_NO_CERTIFICATE_ASSIGNED:177:no certificate assigned SSL_R_NO_CERTIFICATE_SET:179:no certificate set SSL_R_NO_CHANGE_FOLLOWING_HRR:214:no change following hrr SSL_R_NO_CIPHERS_AVAILABLE:181:no ciphers available SSL_R_NO_CIPHERS_SPECIFIED:183:no ciphers specified SSL_R_NO_CIPHER_MATCH:185:no cipher match SSL_R_NO_CLIENT_CERT_METHOD:331:no client cert method SSL_R_NO_COMPRESSION_SPECIFIED:187:no compression specified SSL_R_NO_COOKIE_CALLBACK_SET:287:no cookie callback set SSL_R_NO_GOST_CERTIFICATE_SENT_BY_PEER:330:\ Peer haven't sent GOST certificate, required for selected ciphersuite SSL_R_NO_METHOD_SPECIFIED:188:no method specified SSL_R_NO_PEM_EXTENSIONS:389:no pem extensions SSL_R_NO_PRIVATE_KEY_ASSIGNED:190:no private key assigned SSL_R_NO_PROTOCOLS_AVAILABLE:191:no protocols available SSL_R_NO_RENEGOTIATION:339:no renegotiation SSL_R_NO_REQUIRED_DIGEST:324:no required digest SSL_R_NO_SHARED_CIPHER:193:no shared cipher SSL_R_NO_SHARED_GROUPS:410:no shared groups SSL_R_NO_SHARED_SIGNATURE_ALGORITHMS:376:no shared signature algorithms SSL_R_NO_SRTP_PROFILES:359:no srtp profiles SSL_R_NO_SUITABLE_DIGEST_ALGORITHM:297:no suitable digest algorithm SSL_R_NO_SUITABLE_GROUPS:295:no suitable groups SSL_R_NO_SUITABLE_KEY_SHARE:101:no suitable key share SSL_R_NO_SUITABLE_SIGNATURE_ALGORITHM:118:no suitable signature algorithm SSL_R_NO_VALID_SCTS:216:no valid scts SSL_R_NO_VERIFY_COOKIE_CALLBACK:403:no verify cookie callback SSL_R_NULL_SSL_CTX:195:null ssl ctx SSL_R_NULL_SSL_METHOD_PASSED:196:null ssl method passed SSL_R_OCSP_CALLBACK_FAILURE:305:ocsp callback failure SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED:197:old session cipher not returned SSL_R_OLD_SESSION_COMPRESSION_ALGORITHM_NOT_RETURNED:344:\ old session compression algorithm not returned SSL_R_OVERFLOW_ERROR:237:overflow error SSL_R_PACKET_LENGTH_TOO_LONG:198:packet length too long SSL_R_PARSE_TLSEXT:227:parse tlsext SSL_R_PATH_TOO_LONG:270:path too long SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE:199:peer did not return a certificate SSL_R_PEM_NAME_BAD_PREFIX:391:pem name bad prefix SSL_R_PEM_NAME_TOO_SHORT:392:pem name too short SSL_R_PIPELINE_FAILURE:406:pipeline failure SSL_R_POST_HANDSHAKE_AUTH_ENCODING_ERR:278:post handshake auth encoding err SSL_R_PRIVATE_KEY_MISMATCH:288:private key mismatch SSL_R_PROTOCOL_IS_SHUTDOWN:207:protocol is shutdown SSL_R_PSK_IDENTITY_NOT_FOUND:223:psk identity not found SSL_R_PSK_NO_CLIENT_CB:224:psk no client cb SSL_R_PSK_NO_SERVER_CB:225:psk no server cb SSL_R_READ_BIO_NOT_SET:211:read bio not set SSL_R_READ_TIMEOUT_EXPIRED:312:read timeout expired SSL_R_RECORD_LENGTH_MISMATCH:213:record length mismatch SSL_R_RECORD_TOO_SMALL:298:record too small SSL_R_RENEGOTIATE_EXT_TOO_LONG:335:renegotiate ext too long SSL_R_RENEGOTIATION_ENCODING_ERR:336:renegotiation encoding err SSL_R_RENEGOTIATION_MISMATCH:337:renegotiation mismatch SSL_R_REQUEST_PENDING:285:request pending SSL_R_REQUEST_SENT:286:request sent SSL_R_REQUIRED_CIPHER_MISSING:215:required cipher missing SSL_R_REQUIRED_COMPRESSION_ALGORITHM_MISSING:342:\ required compression algorithm missing SSL_R_SCSV_RECEIVED_WHEN_RENEGOTIATING:345:scsv received when renegotiating SSL_R_SCT_VERIFICATION_FAILED:208:sct verification failed SSL_R_SERVERHELLO_TLSEXT:275:serverhello tlsext SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED:277:session id context uninitialized SSL_R_SHUTDOWN_WHILE_IN_INIT:407:shutdown while in init SSL_R_SIGNATURE_ALGORITHMS_ERROR:360:signature algorithms error SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE:220:\ signature for non signing certificate SSL_R_SRP_A_CALC:361:error with the srp params SSL_R_SRTP_COULD_NOT_ALLOCATE_PROFILES:362:srtp could not allocate profiles SSL_R_SRTP_PROTECTION_PROFILE_LIST_TOO_LONG:363:\ srtp protection profile list too long SSL_R_SRTP_UNKNOWN_PROTECTION_PROFILE:364:srtp unknown protection profile SSL_R_SSL3_EXT_INVALID_MAX_FRAGMENT_LENGTH:232:\ ssl3 ext invalid max fragment length SSL_R_SSL3_EXT_INVALID_SERVERNAME:319:ssl3 ext invalid servername SSL_R_SSL3_EXT_INVALID_SERVERNAME_TYPE:320:ssl3 ext invalid servername type SSL_R_SSL3_SESSION_ID_TOO_LONG:300:ssl3 session id too long SSL_R_SSL_COMMAND_SECTION_EMPTY:117:ssl command section empty SSL_R_SSL_COMMAND_SECTION_NOT_FOUND:125:ssl command section not found SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION:228:ssl ctx has no default ssl version SSL_R_SSL_HANDSHAKE_FAILURE:229:ssl handshake failure SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS:230:ssl library has no ciphers SSL_R_SSL_NEGATIVE_LENGTH:372:ssl negative length SSL_R_SSL_SECTION_EMPTY:126:ssl section empty SSL_R_SSL_SECTION_NOT_FOUND:136:ssl section not found SSL_R_SSL_SESSION_ID_CALLBACK_FAILED:301:ssl session id callback failed SSL_R_SSL_SESSION_ID_CONFLICT:302:ssl session id conflict SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG:273:ssl session id context too long SSL_R_SSL_SESSION_ID_HAS_BAD_LENGTH:303:ssl session id has bad length SSL_R_SSL_SESSION_ID_TOO_LONG:408:ssl session id too long SSL_R_SSL_SESSION_VERSION_MISMATCH:210:ssl session version mismatch SSL_R_STILL_IN_INIT:121:still in init SSL_R_TLS_ILLEGAL_EXPORTER_LABEL:367:tls illegal exporter label SSL_R_TLS_INVALID_ECPOINTFORMAT_LIST:157:tls invalid ecpointformat list SSL_R_TOO_MANY_KEY_UPDATES:132:too many key updates SSL_R_TOO_MANY_WARN_ALERTS:409:too many warn alerts SSL_R_TOO_MUCH_EARLY_DATA:164:too much early data SSL_R_UNABLE_TO_FIND_ECDH_PARAMETERS:314:unable to find ecdh parameters SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS:239:\ unable to find public key parameters SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES:242:unable to load ssl3 md5 routines SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES:243:unable to load ssl3 sha1 routines SSL_R_UNEXPECTED_CCS_MESSAGE:262:unexpected ccs message SSL_R_UNEXPECTED_END_OF_EARLY_DATA:178:unexpected end of early data SSL_R_UNEXPECTED_EOF_WHILE_READING:294:unexpected eof while reading SSL_R_UNEXPECTED_MESSAGE:244:unexpected message SSL_R_UNEXPECTED_RECORD:245:unexpected record SSL_R_UNINITIALIZED:276:uninitialized SSL_R_UNKNOWN_ALERT_TYPE:246:unknown alert type SSL_R_UNKNOWN_CERTIFICATE_TYPE:247:unknown certificate type SSL_R_UNKNOWN_CIPHER_RETURNED:248:unknown cipher returned SSL_R_UNKNOWN_CIPHER_TYPE:249:unknown cipher type SSL_R_UNKNOWN_CMD_NAME:386:unknown cmd name SSL_R_UNKNOWN_COMMAND:139:unknown command SSL_R_UNKNOWN_DIGEST:368:unknown digest SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE:250:unknown key exchange type SSL_R_UNKNOWN_PKEY_TYPE:251:unknown pkey type SSL_R_UNKNOWN_PROTOCOL:252:unknown protocol SSL_R_UNKNOWN_SSL_VERSION:254:unknown ssl version SSL_R_UNKNOWN_STATE:255:unknown state SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED:338:\ unsafe legacy renegotiation disabled SSL_R_UNSOLICITED_EXTENSION:217:unsolicited extension SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM:257:unsupported compression algorithm SSL_R_UNSUPPORTED_ELLIPTIC_CURVE:315:unsupported elliptic curve SSL_R_UNSUPPORTED_PROTOCOL:258:unsupported protocol SSL_R_UNSUPPORTED_SSL_VERSION:259:unsupported ssl version SSL_R_UNSUPPORTED_STATUS_TYPE:329:unsupported status type SSL_R_USE_SRTP_NOT_NEGOTIATED:369:use srtp not negotiated SSL_R_VERSION_TOO_HIGH:166:version too high SSL_R_VERSION_TOO_LOW:396:version too low SSL_R_WRONG_CERTIFICATE_TYPE:383:wrong certificate type SSL_R_WRONG_CIPHER_RETURNED:261:wrong cipher returned SSL_R_WRONG_CURVE:378:wrong curve SSL_R_WRONG_SIGNATURE_LENGTH:264:wrong signature length SSL_R_WRONG_SIGNATURE_SIZE:265:wrong signature size SSL_R_WRONG_SIGNATURE_TYPE:370:wrong signature type SSL_R_WRONG_SSL_VERSION:266:wrong ssl version SSL_R_WRONG_VERSION_NUMBER:267:wrong version number SSL_R_X509_LIB:268:x509 lib SSL_R_X509_VERIFICATION_SETUP_PROBLEMS:269:x509 verification setup problems TS_R_BAD_PKCS7_TYPE:132:bad pkcs7 type TS_R_BAD_TYPE:133:bad type TS_R_CANNOT_LOAD_CERT:137:cannot load certificate TS_R_CANNOT_LOAD_KEY:138:cannot load private key TS_R_CERTIFICATE_VERIFY_ERROR:100:certificate verify error TS_R_COULD_NOT_SET_ENGINE:127:could not set engine TS_R_COULD_NOT_SET_TIME:115:could not set time TS_R_DETACHED_CONTENT:134:detached content TS_R_ESS_ADD_SIGNING_CERT_ERROR:116:ess add signing cert error TS_R_ESS_ADD_SIGNING_CERT_V2_ERROR:139:ess add signing cert v2 error TS_R_ESS_SIGNING_CERTIFICATE_ERROR:101:ess signing certificate error TS_R_INVALID_NULL_POINTER:102:invalid null pointer TS_R_INVALID_SIGNER_CERTIFICATE_PURPOSE:117:invalid signer certificate purpose TS_R_MESSAGE_IMPRINT_MISMATCH:103:message imprint mismatch TS_R_NONCE_MISMATCH:104:nonce mismatch TS_R_NONCE_NOT_RETURNED:105:nonce not returned TS_R_NO_CONTENT:106:no content TS_R_NO_TIME_STAMP_TOKEN:107:no time stamp token TS_R_PKCS7_ADD_SIGNATURE_ERROR:118:pkcs7 add signature error TS_R_PKCS7_ADD_SIGNED_ATTR_ERROR:119:pkcs7 add signed attr error TS_R_PKCS7_TO_TS_TST_INFO_FAILED:129:pkcs7 to ts tst info failed TS_R_POLICY_MISMATCH:108:policy mismatch TS_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE:120:\ private key does not match certificate TS_R_RESPONSE_SETUP_ERROR:121:response setup error TS_R_SIGNATURE_FAILURE:109:signature failure TS_R_THERE_MUST_BE_ONE_SIGNER:110:there must be one signer TS_R_TIME_SYSCALL_ERROR:122:time syscall error TS_R_TOKEN_NOT_PRESENT:130:token not present TS_R_TOKEN_PRESENT:131:token present TS_R_TSA_NAME_MISMATCH:111:tsa name mismatch TS_R_TSA_UNTRUSTED:112:tsa untrusted TS_R_TST_INFO_SETUP_ERROR:123:tst info setup error TS_R_TS_DATASIGN:124:ts datasign TS_R_UNACCEPTABLE_POLICY:125:unacceptable policy TS_R_UNSUPPORTED_MD_ALGORITHM:126:unsupported md algorithm TS_R_UNSUPPORTED_VERSION:113:unsupported version TS_R_VAR_BAD_VALUE:135:var bad value TS_R_VAR_LOOKUP_FAILURE:136:cannot find config variable TS_R_WRONG_CONTENT_TYPE:114:wrong content type UI_R_COMMON_OK_AND_CANCEL_CHARACTERS:104:common ok and cancel characters UI_R_INDEX_TOO_LARGE:102:index too large UI_R_INDEX_TOO_SMALL:103:index too small UI_R_NO_RESULT_BUFFER:105:no result buffer UI_R_PROCESSING_ERROR:107:processing error UI_R_RESULT_TOO_LARGE:100:result too large UI_R_RESULT_TOO_SMALL:101:result too small UI_R_SYSASSIGN_ERROR:109:sys$assign error UI_R_SYSDASSGN_ERROR:110:sys$dassgn error UI_R_SYSQIOW_ERROR:111:sys$qiow error UI_R_UNKNOWN_CONTROL_COMMAND:106:unknown control command UI_R_UNKNOWN_TTYGET_ERRNO_VALUE:108:unknown ttyget errno value UI_R_USER_DATA_DUPLICATION_UNSUPPORTED:112:user data duplication unsupported X509V3_R_BAD_IP_ADDRESS:118:bad ip address X509V3_R_BAD_OBJECT:119:bad object X509V3_R_BN_DEC2BN_ERROR:100:bn dec2bn error X509V3_R_BN_TO_ASN1_INTEGER_ERROR:101:bn to asn1 integer error X509V3_R_DIRNAME_ERROR:149:dirname error X509V3_R_DISTPOINT_ALREADY_SET:160:distpoint already set X509V3_R_DUPLICATE_ZONE_ID:133:duplicate zone id X509V3_R_EMPTY_KEY_USAGE:169:empty key usage X509V3_R_ERROR_CONVERTING_ZONE:131:error converting zone X509V3_R_ERROR_CREATING_EXTENSION:144:error creating extension X509V3_R_ERROR_IN_EXTENSION:128:error in extension X509V3_R_EXPECTED_A_SECTION_NAME:137:expected a section name X509V3_R_EXTENSION_EXISTS:145:extension exists X509V3_R_EXTENSION_NAME_ERROR:115:extension name error X509V3_R_EXTENSION_NOT_FOUND:102:extension not found X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED:103:extension setting not supported X509V3_R_EXTENSION_VALUE_ERROR:116:extension value error X509V3_R_ILLEGAL_EMPTY_EXTENSION:151:illegal empty extension X509V3_R_INCORRECT_POLICY_SYNTAX_TAG:152:incorrect policy syntax tag X509V3_R_INVALID_ASNUMBER:162:invalid asnumber X509V3_R_INVALID_ASRANGE:163:invalid asrange X509V3_R_INVALID_BOOLEAN_STRING:104:invalid boolean string X509V3_R_INVALID_CERTIFICATE:158:invalid certificate X509V3_R_INVALID_EMPTY_NAME:108:invalid empty name X509V3_R_INVALID_EXTENSION_STRING:105:invalid extension string X509V3_R_INVALID_INHERITANCE:165:invalid inheritance X509V3_R_INVALID_IPADDRESS:166:invalid ipaddress X509V3_R_INVALID_MULTIPLE_RDNS:161:invalid multiple rdns X509V3_R_INVALID_NAME:106:invalid name X509V3_R_INVALID_NULL_ARGUMENT:107:invalid null argument X509V3_R_INVALID_NULL_VALUE:109:invalid null value X509V3_R_INVALID_NUMBER:140:invalid number X509V3_R_INVALID_NUMBERS:141:invalid numbers X509V3_R_INVALID_OBJECT_IDENTIFIER:110:invalid object identifier X509V3_R_INVALID_OPTION:138:invalid option X509V3_R_INVALID_POLICY_IDENTIFIER:134:invalid policy identifier X509V3_R_INVALID_PROXY_POLICY_SETTING:153:invalid proxy policy setting X509V3_R_INVALID_PURPOSE:146:invalid purpose X509V3_R_INVALID_SAFI:164:invalid safi X509V3_R_INVALID_SECTION:135:invalid section X509V3_R_INVALID_SYNTAX:143:invalid syntax X509V3_R_ISSUER_DECODE_ERROR:126:issuer decode error X509V3_R_MISSING_VALUE:124:missing value X509V3_R_NEED_ORGANIZATION_AND_NUMBERS:142:need organization and numbers X509V3_R_NEGATIVE_PATHLEN:168:negative pathlen X509V3_R_NO_CONFIG_DATABASE:136:no config database X509V3_R_NO_ISSUER_CERTIFICATE:121:no issuer certificate X509V3_R_NO_ISSUER_DETAILS:127:no issuer details X509V3_R_NO_POLICY_IDENTIFIER:139:no policy identifier X509V3_R_NO_PROXY_CERT_POLICY_LANGUAGE_DEFINED:154:\ no proxy cert policy language defined X509V3_R_NO_PUBLIC_KEY:114:no public key X509V3_R_NO_SUBJECT_DETAILS:125:no subject details X509V3_R_OPERATION_NOT_DEFINED:148:operation not defined X509V3_R_OTHERNAME_ERROR:147:othername error X509V3_R_POLICY_LANGUAGE_ALREADY_DEFINED:155:policy language already defined X509V3_R_POLICY_PATH_LENGTH:156:policy path length X509V3_R_POLICY_PATH_LENGTH_ALREADY_DEFINED:157:\ policy path length already defined X509V3_R_POLICY_WHEN_PROXY_LANGUAGE_REQUIRES_NO_POLICY:159:\ policy when proxy language requires no policy X509V3_R_SECTION_NOT_FOUND:150:section not found X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS:122:unable to get issuer details X509V3_R_UNABLE_TO_GET_ISSUER_KEYID:123:unable to get issuer keyid X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT:111:unknown bit string argument X509V3_R_UNKNOWN_EXTENSION:129:unknown extension X509V3_R_UNKNOWN_EXTENSION_NAME:130:unknown extension name X509V3_R_UNKNOWN_OPTION:120:unknown option X509V3_R_UNSUPPORTED_OPTION:117:unsupported option X509V3_R_UNSUPPORTED_TYPE:167:unsupported type X509V3_R_USER_TOO_LONG:132:user too long X509_R_AKID_MISMATCH:110:akid mismatch X509_R_BAD_SELECTOR:133:bad selector X509_R_BAD_X509_FILETYPE:100:bad x509 filetype X509_R_BASE64_DECODE_ERROR:118:base64 decode error X509_R_CANT_CHECK_DH_KEY:114:cant check dh key X509_R_CERTIFICATE_VERIFICATION_FAILED:139:certificate verification failed X509_R_CERT_ALREADY_IN_HASH_TABLE:101:cert already in hash table X509_R_CRL_ALREADY_DELTA:127:crl already delta X509_R_CRL_VERIFY_FAILURE:131:crl verify failure X509_R_DUPLICATE_ATTRIBUTE:140:duplicate attribute X509_R_ERROR_GETTING_MD_BY_NID:141:error getting md by nid X509_R_ERROR_USING_SIGINF_SET:142:error using siginf set X509_R_IDP_MISMATCH:128:idp mismatch X509_R_INVALID_ATTRIBUTES:138:invalid attributes X509_R_INVALID_DIRECTORY:113:invalid directory X509_R_INVALID_DISTPOINT:143:invalid distpoint X509_R_INVALID_FIELD_NAME:119:invalid field name X509_R_INVALID_TRUST:123:invalid trust X509_R_ISSUER_MISMATCH:129:issuer mismatch X509_R_KEY_TYPE_MISMATCH:115:key type mismatch X509_R_KEY_VALUES_MISMATCH:116:key values mismatch X509_R_LOADING_CERT_DIR:103:loading cert dir X509_R_LOADING_DEFAULTS:104:loading defaults X509_R_METHOD_NOT_SUPPORTED:124:method not supported X509_R_NAME_TOO_LONG:134:name too long X509_R_NEWER_CRL_NOT_NEWER:132:newer crl not newer X509_R_NO_CERTIFICATE_FOUND:135:no certificate found X509_R_NO_CERTIFICATE_OR_CRL_FOUND:136:no certificate or crl found X509_R_NO_CERT_SET_FOR_US_TO_VERIFY:105:no cert set for us to verify X509_R_NO_CRL_FOUND:137:no crl found X509_R_NO_CRL_NUMBER:130:no crl number X509_R_PUBLIC_KEY_DECODE_ERROR:125:public key decode error X509_R_PUBLIC_KEY_ENCODE_ERROR:126:public key encode error X509_R_SHOULD_RETRY:106:should retry X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN:107:unable to find parameters in chain X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY:108:unable to get certs public key X509_R_UNKNOWN_KEY_TYPE:117:unknown key type X509_R_UNKNOWN_NID:109:unknown nid X509_R_UNKNOWN_PURPOSE_ID:121:unknown purpose id X509_R_UNKNOWN_SIGID_ALGS:144:unknown sigid algs X509_R_UNKNOWN_TRUST_ID:120:unknown trust id X509_R_UNSUPPORTED_ALGORITHM:111:unsupported algorithm X509_R_WRONG_LOOKUP_TYPE:112:wrong lookup type X509_R_WRONG_TYPE:122:wrong type diff --git a/crypto/openssl/crypto/evp/evp_enc.c b/crypto/openssl/crypto/evp/evp_enc.c index b178d1086473..4e6f83e3d0a9 100644 --- a/crypto/openssl/crypto/evp/evp_enc.c +++ b/crypto/openssl/crypto/evp/evp_enc.c @@ -1,1677 +1,1718 @@ /* - * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ /* We need to use some engine deprecated APIs */ #define OPENSSL_SUPPRESS_DEPRECATED #include #include #include #include #include #include #ifndef FIPS_MODULE # include #endif #include #include #include "internal/cryptlib.h" #include "internal/provider.h" #include "internal/core.h" #include "crypto/evp.h" #include "evp_local.h" int EVP_CIPHER_CTX_reset(EVP_CIPHER_CTX *ctx) { if (ctx == NULL) return 1; if (ctx->cipher == NULL || ctx->cipher->prov == NULL) goto legacy; if (ctx->algctx != NULL) { if (ctx->cipher->freectx != NULL) ctx->cipher->freectx(ctx->algctx); ctx->algctx = NULL; } if (ctx->fetched_cipher != NULL) EVP_CIPHER_free(ctx->fetched_cipher); memset(ctx, 0, sizeof(*ctx)); ctx->iv_len = -1; return 1; /* Remove legacy code below when legacy support is removed. */ legacy: if (ctx->cipher != NULL) { if (ctx->cipher->cleanup && !ctx->cipher->cleanup(ctx)) return 0; /* Cleanse cipher context data */ if (ctx->cipher_data && ctx->cipher->ctx_size) OPENSSL_cleanse(ctx->cipher_data, ctx->cipher->ctx_size); } OPENSSL_free(ctx->cipher_data); #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) ENGINE_finish(ctx->engine); #endif memset(ctx, 0, sizeof(*ctx)); ctx->iv_len = -1; return 1; } EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void) { return OPENSSL_zalloc(sizeof(EVP_CIPHER_CTX)); } void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx) { if (ctx == NULL) return; EVP_CIPHER_CTX_reset(ctx); OPENSSL_free(ctx); } static int evp_cipher_init_internal(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, const unsigned char *key, const unsigned char *iv, int enc, const OSSL_PARAM params[]) { int n; #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) ENGINE *tmpimpl = NULL; #endif ctx->iv_len = -1; /* * enc == 1 means we are encrypting. * enc == 0 means we are decrypting. * enc == -1 means, use the previously initialised value for encrypt/decrypt */ if (enc == -1) { enc = ctx->encrypt; } else { if (enc) enc = 1; ctx->encrypt = enc; } if (cipher == NULL && ctx->cipher == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_NO_CIPHER_SET); return 0; } /* Code below to be removed when legacy support is dropped. */ #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) /* * Whether it's nice or not, "Inits" can be used on "Final"'d contexts so * this context may already have an ENGINE! Try to avoid releasing the * previous handle, re-querying for an ENGINE, and having a * reinitialisation, when it may all be unnecessary. */ if (ctx->engine && ctx->cipher && (cipher == NULL || cipher->nid == ctx->cipher->nid)) goto skip_to_init; if (cipher != NULL && impl == NULL) { /* Ask if an ENGINE is reserved for this job */ tmpimpl = ENGINE_get_cipher_engine(cipher->nid); } #endif /* * If there are engines involved then we should use legacy handling for now. */ if (ctx->engine != NULL #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) || tmpimpl != NULL #endif || impl != NULL || (cipher != NULL && cipher->origin == EVP_ORIG_METH) || (cipher == NULL && ctx->cipher != NULL && ctx->cipher->origin == EVP_ORIG_METH)) { if (ctx->cipher == ctx->fetched_cipher) ctx->cipher = NULL; EVP_CIPHER_free(ctx->fetched_cipher); ctx->fetched_cipher = NULL; goto legacy; } /* * Ensure a context left lying around from last time is cleared * (legacy code) */ if (cipher != NULL && ctx->cipher != NULL) { if (ctx->cipher->cleanup != NULL && !ctx->cipher->cleanup(ctx)) return 0; OPENSSL_clear_free(ctx->cipher_data, ctx->cipher->ctx_size); ctx->cipher_data = NULL; } /* Start of non-legacy code below */ /* Ensure a context left lying around from last time is cleared */ if (cipher != NULL && ctx->cipher != NULL) { unsigned long flags = ctx->flags; EVP_CIPHER_CTX_reset(ctx); /* Restore encrypt and flags */ ctx->encrypt = enc; ctx->flags = flags; } if (cipher == NULL) cipher = ctx->cipher; if (cipher->prov == NULL) { #ifdef FIPS_MODULE /* We only do explicit fetches inside the FIPS module */ ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR); return 0; #else EVP_CIPHER *provciph = EVP_CIPHER_fetch(NULL, cipher->nid == NID_undef ? "NULL" : OBJ_nid2sn(cipher->nid), ""); if (provciph == NULL) return 0; cipher = provciph; EVP_CIPHER_free(ctx->fetched_cipher); ctx->fetched_cipher = provciph; #endif } - if (cipher->prov != NULL) { + if (!ossl_assert(cipher->prov != NULL)) { + ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR); + return 0; + } + + if (cipher != ctx->fetched_cipher) { if (!EVP_CIPHER_up_ref((EVP_CIPHER *)cipher)) { ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR); return 0; } EVP_CIPHER_free(ctx->fetched_cipher); ctx->fetched_cipher = (EVP_CIPHER *)cipher; } ctx->cipher = cipher; if (ctx->algctx == NULL) { ctx->algctx = ctx->cipher->newctx(ossl_provider_ctx(cipher->prov)); if (ctx->algctx == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR); return 0; } } if ((ctx->flags & EVP_CIPH_NO_PADDING) != 0) { /* * If this ctx was already set up for no padding then we need to tell * the new cipher about it. */ if (!EVP_CIPHER_CTX_set_padding(ctx, 0)) return 0; } +#ifndef FIPS_MODULE + /* + * Fix for CVE-2023-5363 + * Passing in a size as part of the init call takes effect late + * so, force such to occur before the initialisation. + * + * The FIPS provider's internal library context is used in a manner + * such that this is not an issue. + */ + if (params != NULL) { + OSSL_PARAM param_lens[3] = { OSSL_PARAM_END, OSSL_PARAM_END, + OSSL_PARAM_END }; + OSSL_PARAM *q = param_lens; + const OSSL_PARAM *p; + + p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_KEYLEN); + if (p != NULL) + memcpy(q++, p, sizeof(*q)); + + /* + * Note that OSSL_CIPHER_PARAM_AEAD_IVLEN is a synomym for + * OSSL_CIPHER_PARAM_IVLEN so both are covered here. + */ + p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_IVLEN); + if (p != NULL) + memcpy(q++, p, sizeof(*q)); + + if (q != param_lens) { + if (!EVP_CIPHER_CTX_set_params(ctx, param_lens)) { + ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_LENGTH); + return 0; + } + } + } +#endif + if (enc) { if (ctx->cipher->einit == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR); return 0; } return ctx->cipher->einit(ctx->algctx, key, key == NULL ? 0 : EVP_CIPHER_CTX_get_key_length(ctx), iv, iv == NULL ? 0 : EVP_CIPHER_CTX_get_iv_length(ctx), params); } if (ctx->cipher->dinit == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR); return 0; } return ctx->cipher->dinit(ctx->algctx, key, key == NULL ? 0 : EVP_CIPHER_CTX_get_key_length(ctx), iv, iv == NULL ? 0 : EVP_CIPHER_CTX_get_iv_length(ctx), params); /* Code below to be removed when legacy support is dropped. */ legacy: if (cipher != NULL) { /* * Ensure a context left lying around from last time is cleared (we * previously attempted to avoid this if the same ENGINE and * EVP_CIPHER could be used). */ if (ctx->cipher) { unsigned long flags = ctx->flags; EVP_CIPHER_CTX_reset(ctx); /* Restore encrypt and flags */ ctx->encrypt = enc; ctx->flags = flags; } #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) if (impl != NULL) { if (!ENGINE_init(impl)) { ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR); return 0; } } else { impl = tmpimpl; } if (impl != NULL) { /* There's an ENGINE for this job ... (apparently) */ const EVP_CIPHER *c = ENGINE_get_cipher(impl, cipher->nid); if (c == NULL) { /* * One positive side-effect of US's export control history, * is that we should at least be able to avoid using US * misspellings of "initialisation"? */ ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR); return 0; } /* We'll use the ENGINE's private cipher definition */ cipher = c; /* * Store the ENGINE functional reference so we know 'cipher' came * from an ENGINE and we need to release it when done. */ ctx->engine = impl; } else { ctx->engine = NULL; } #endif ctx->cipher = cipher; if (ctx->cipher->ctx_size) { ctx->cipher_data = OPENSSL_zalloc(ctx->cipher->ctx_size); if (ctx->cipher_data == NULL) { ctx->cipher = NULL; ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE); return 0; } } else { ctx->cipher_data = NULL; } ctx->key_len = cipher->key_len; /* Preserve wrap enable flag, zero everything else */ ctx->flags &= EVP_CIPHER_CTX_FLAG_WRAP_ALLOW; if (ctx->cipher->flags & EVP_CIPH_CTRL_INIT) { if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_INIT, 0, NULL) <= 0) { ctx->cipher = NULL; ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR); return 0; } } } #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) skip_to_init: #endif if (ctx->cipher == NULL) return 0; /* we assume block size is a power of 2 in *cryptUpdate */ OPENSSL_assert(ctx->cipher->block_size == 1 || ctx->cipher->block_size == 8 || ctx->cipher->block_size == 16); if (!(ctx->flags & EVP_CIPHER_CTX_FLAG_WRAP_ALLOW) && EVP_CIPHER_CTX_get_mode(ctx) == EVP_CIPH_WRAP_MODE) { ERR_raise(ERR_LIB_EVP, EVP_R_WRAP_MODE_NOT_ALLOWED); return 0; } if ((EVP_CIPHER_get_flags(EVP_CIPHER_CTX_get0_cipher(ctx)) & EVP_CIPH_CUSTOM_IV) == 0) { switch (EVP_CIPHER_CTX_get_mode(ctx)) { case EVP_CIPH_STREAM_CIPHER: case EVP_CIPH_ECB_MODE: break; case EVP_CIPH_CFB_MODE: case EVP_CIPH_OFB_MODE: ctx->num = 0; /* fall-through */ case EVP_CIPH_CBC_MODE: n = EVP_CIPHER_CTX_get_iv_length(ctx); if (n < 0 || n > (int)sizeof(ctx->iv)) { ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_IV_LENGTH); return 0; } if (iv != NULL) memcpy(ctx->oiv, iv, n); memcpy(ctx->iv, ctx->oiv, n); break; case EVP_CIPH_CTR_MODE: ctx->num = 0; /* Don't reuse IV for CTR mode */ if (iv != NULL) { n = EVP_CIPHER_CTX_get_iv_length(ctx); if (n <= 0 || n > (int)sizeof(ctx->iv)) { ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_IV_LENGTH); return 0; } memcpy(ctx->iv, iv, n); } break; default: return 0; } } if (key != NULL || (ctx->cipher->flags & EVP_CIPH_ALWAYS_CALL_INIT)) { if (!ctx->cipher->init(ctx, key, iv, enc)) return 0; } ctx->buf_len = 0; ctx->final_used = 0; ctx->block_mask = ctx->cipher->block_size - 1; return 1; } int EVP_CipherInit_ex2(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, const unsigned char *key, const unsigned char *iv, int enc, const OSSL_PARAM params[]) { return evp_cipher_init_internal(ctx, cipher, NULL, key, iv, enc, params); } int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, const unsigned char *key, const unsigned char *iv, int enc) { if (cipher != NULL) EVP_CIPHER_CTX_reset(ctx); return evp_cipher_init_internal(ctx, cipher, NULL, key, iv, enc, NULL); } int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, const unsigned char *key, const unsigned char *iv, int enc) { return evp_cipher_init_internal(ctx, cipher, impl, key, iv, enc, NULL); } int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, const unsigned char *in, int inl) { if (ctx->encrypt) return EVP_EncryptUpdate(ctx, out, outl, in, inl); else return EVP_DecryptUpdate(ctx, out, outl, in, inl); } int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) { if (ctx->encrypt) return EVP_EncryptFinal_ex(ctx, out, outl); else return EVP_DecryptFinal_ex(ctx, out, outl); } int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) { if (ctx->encrypt) return EVP_EncryptFinal(ctx, out, outl); else return EVP_DecryptFinal(ctx, out, outl); } int EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, const unsigned char *key, const unsigned char *iv) { return EVP_CipherInit(ctx, cipher, key, iv, 1); } int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, const unsigned char *key, const unsigned char *iv) { return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 1); } int EVP_EncryptInit_ex2(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, const unsigned char *key, const unsigned char *iv, const OSSL_PARAM params[]) { return EVP_CipherInit_ex2(ctx, cipher, key, iv, 1, params); } int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, const unsigned char *key, const unsigned char *iv) { return EVP_CipherInit(ctx, cipher, key, iv, 0); } int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, const unsigned char *key, const unsigned char *iv) { return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 0); } int EVP_DecryptInit_ex2(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, const unsigned char *key, const unsigned char *iv, const OSSL_PARAM params[]) { return EVP_CipherInit_ex2(ctx, cipher, key, iv, 0, params); } /* * According to the letter of standard difference between pointers * is specified to be valid only within same object. This makes * it formally challenging to determine if input and output buffers * are not partially overlapping with standard pointer arithmetic. */ #ifdef PTRDIFF_T # undef PTRDIFF_T #endif #if defined(OPENSSL_SYS_VMS) && __INITIAL_POINTER_SIZE==64 /* * Then we have VMS that distinguishes itself by adhering to * sizeof(size_t)==4 even in 64-bit builds, which means that * difference between two pointers might be truncated to 32 bits. * In the context one can even wonder how comparison for * equality is implemented. To be on the safe side we adhere to * PTRDIFF_T even for comparison for equality. */ # define PTRDIFF_T uint64_t #else # define PTRDIFF_T size_t #endif int ossl_is_partially_overlapping(const void *ptr1, const void *ptr2, int len) { PTRDIFF_T diff = (PTRDIFF_T)ptr1-(PTRDIFF_T)ptr2; /* * Check for partially overlapping buffers. [Binary logical * operations are used instead of boolean to minimize number * of conditional branches.] */ int overlapped = (len > 0) & (diff != 0) & ((diff < (PTRDIFF_T)len) | (diff > (0 - (PTRDIFF_T)len))); return overlapped; } static int evp_EncryptDecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, const unsigned char *in, int inl) { int i, j, bl, cmpl = inl; if (EVP_CIPHER_CTX_test_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS)) cmpl = (cmpl + 7) / 8; bl = ctx->cipher->block_size; if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) { /* If block size > 1 then the cipher will have to do this check */ if (bl == 1 && ossl_is_partially_overlapping(out, in, cmpl)) { ERR_raise(ERR_LIB_EVP, EVP_R_PARTIALLY_OVERLAPPING); return 0; } i = ctx->cipher->do_cipher(ctx, out, in, inl); if (i < 0) return 0; else *outl = i; return 1; } if (inl <= 0) { *outl = 0; return inl == 0; } if (ossl_is_partially_overlapping(out + ctx->buf_len, in, cmpl)) { ERR_raise(ERR_LIB_EVP, EVP_R_PARTIALLY_OVERLAPPING); return 0; } if (ctx->buf_len == 0 && (inl & (ctx->block_mask)) == 0) { if (ctx->cipher->do_cipher(ctx, out, in, inl)) { *outl = inl; return 1; } else { *outl = 0; return 0; } } i = ctx->buf_len; OPENSSL_assert(bl <= (int)sizeof(ctx->buf)); if (i != 0) { if (bl - i > inl) { memcpy(&(ctx->buf[i]), in, inl); ctx->buf_len += inl; *outl = 0; return 1; } else { j = bl - i; /* * Once we've processed the first j bytes from in, the amount of * data left that is a multiple of the block length is: * (inl - j) & ~(bl - 1) * We must ensure that this amount of data, plus the one block that * we process from ctx->buf does not exceed INT_MAX */ if (((inl - j) & ~(bl - 1)) > INT_MAX - bl) { ERR_raise(ERR_LIB_EVP, EVP_R_OUTPUT_WOULD_OVERFLOW); return 0; } memcpy(&(ctx->buf[i]), in, j); inl -= j; in += j; if (!ctx->cipher->do_cipher(ctx, out, ctx->buf, bl)) return 0; out += bl; *outl = bl; } } else *outl = 0; i = inl & (bl - 1); inl -= i; if (inl > 0) { if (!ctx->cipher->do_cipher(ctx, out, in, inl)) return 0; *outl += inl; } if (i != 0) memcpy(ctx->buf, &(in[inl]), i); ctx->buf_len = i; return 1; } int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, const unsigned char *in, int inl) { int ret; size_t soutl, inl_ = (size_t)inl; int blocksize; if (outl != NULL) { *outl = 0; } else { ERR_raise(ERR_LIB_EVP, ERR_R_PASSED_NULL_PARAMETER); return 0; } /* Prevent accidental use of decryption context when encrypting */ if (!ctx->encrypt) { ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_OPERATION); return 0; } if (ctx->cipher == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_NO_CIPHER_SET); return 0; } if (ctx->cipher->prov == NULL) goto legacy; blocksize = ctx->cipher->block_size; if (ctx->cipher->cupdate == NULL || blocksize < 1) { ERR_raise(ERR_LIB_EVP, EVP_R_UPDATE_ERROR); return 0; } ret = ctx->cipher->cupdate(ctx->algctx, out, &soutl, inl_ + (size_t)(blocksize == 1 ? 0 : blocksize), in, inl_); if (ret) { if (soutl > INT_MAX) { ERR_raise(ERR_LIB_EVP, EVP_R_UPDATE_ERROR); return 0; } *outl = soutl; } return ret; /* Code below to be removed when legacy support is dropped. */ legacy: return evp_EncryptDecryptUpdate(ctx, out, outl, in, inl); } int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) { int ret; ret = EVP_EncryptFinal_ex(ctx, out, outl); return ret; } int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) { int n, ret; unsigned int i, b, bl; size_t soutl; int blocksize; if (outl != NULL) { *outl = 0; } else { ERR_raise(ERR_LIB_EVP, ERR_R_PASSED_NULL_PARAMETER); return 0; } /* Prevent accidental use of decryption context when encrypting */ if (!ctx->encrypt) { ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_OPERATION); return 0; } if (ctx->cipher == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_NO_CIPHER_SET); return 0; } if (ctx->cipher->prov == NULL) goto legacy; blocksize = EVP_CIPHER_CTX_get_block_size(ctx); if (blocksize < 1 || ctx->cipher->cfinal == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_FINAL_ERROR); return 0; } ret = ctx->cipher->cfinal(ctx->algctx, out, &soutl, blocksize == 1 ? 0 : blocksize); if (ret) { if (soutl > INT_MAX) { ERR_raise(ERR_LIB_EVP, EVP_R_FINAL_ERROR); return 0; } *outl = soutl; } return ret; /* Code below to be removed when legacy support is dropped. */ legacy: if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) { ret = ctx->cipher->do_cipher(ctx, out, NULL, 0); if (ret < 0) return 0; else *outl = ret; return 1; } b = ctx->cipher->block_size; OPENSSL_assert(b <= sizeof(ctx->buf)); if (b == 1) { *outl = 0; return 1; } bl = ctx->buf_len; if (ctx->flags & EVP_CIPH_NO_PADDING) { if (bl) { ERR_raise(ERR_LIB_EVP, EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH); return 0; } *outl = 0; return 1; } n = b - bl; for (i = bl; i < b; i++) ctx->buf[i] = n; ret = ctx->cipher->do_cipher(ctx, out, ctx->buf, b); if (ret) *outl = b; return ret; } int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, const unsigned char *in, int inl) { int fix_len, cmpl = inl, ret; unsigned int b; size_t soutl, inl_ = (size_t)inl; int blocksize; if (outl != NULL) { *outl = 0; } else { ERR_raise(ERR_LIB_EVP, ERR_R_PASSED_NULL_PARAMETER); return 0; } /* Prevent accidental use of encryption context when decrypting */ if (ctx->encrypt) { ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_OPERATION); return 0; } if (ctx->cipher == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_NO_CIPHER_SET); return 0; } if (ctx->cipher->prov == NULL) goto legacy; blocksize = EVP_CIPHER_CTX_get_block_size(ctx); if (ctx->cipher->cupdate == NULL || blocksize < 1) { ERR_raise(ERR_LIB_EVP, EVP_R_UPDATE_ERROR); return 0; } ret = ctx->cipher->cupdate(ctx->algctx, out, &soutl, inl_ + (size_t)(blocksize == 1 ? 0 : blocksize), in, inl_); if (ret) { if (soutl > INT_MAX) { ERR_raise(ERR_LIB_EVP, EVP_R_UPDATE_ERROR); return 0; } *outl = soutl; } return ret; /* Code below to be removed when legacy support is dropped. */ legacy: b = ctx->cipher->block_size; if (EVP_CIPHER_CTX_test_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS)) cmpl = (cmpl + 7) / 8; if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) { if (b == 1 && ossl_is_partially_overlapping(out, in, cmpl)) { ERR_raise(ERR_LIB_EVP, EVP_R_PARTIALLY_OVERLAPPING); return 0; } fix_len = ctx->cipher->do_cipher(ctx, out, in, inl); if (fix_len < 0) { *outl = 0; return 0; } else *outl = fix_len; return 1; } if (inl <= 0) { *outl = 0; return inl == 0; } if (ctx->flags & EVP_CIPH_NO_PADDING) return evp_EncryptDecryptUpdate(ctx, out, outl, in, inl); OPENSSL_assert(b <= sizeof(ctx->final)); if (ctx->final_used) { /* see comment about PTRDIFF_T comparison above */ if (((PTRDIFF_T)out == (PTRDIFF_T)in) || ossl_is_partially_overlapping(out, in, b)) { ERR_raise(ERR_LIB_EVP, EVP_R_PARTIALLY_OVERLAPPING); return 0; } /* * final_used is only ever set if buf_len is 0. Therefore the maximum * length output we will ever see from evp_EncryptDecryptUpdate is * the maximum multiple of the block length that is <= inl, or just: * inl & ~(b - 1) * Since final_used has been set then the final output length is: * (inl & ~(b - 1)) + b * This must never exceed INT_MAX */ if ((inl & ~(b - 1)) > INT_MAX - b) { ERR_raise(ERR_LIB_EVP, EVP_R_OUTPUT_WOULD_OVERFLOW); return 0; } memcpy(out, ctx->final, b); out += b; fix_len = 1; } else fix_len = 0; if (!evp_EncryptDecryptUpdate(ctx, out, outl, in, inl)) return 0; /* * if we have 'decrypted' a multiple of block size, make sure we have a * copy of this last block */ if (b > 1 && !ctx->buf_len) { *outl -= b; ctx->final_used = 1; memcpy(ctx->final, &out[*outl], b); } else ctx->final_used = 0; if (fix_len) *outl += b; return 1; } int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) { int ret; ret = EVP_DecryptFinal_ex(ctx, out, outl); return ret; } int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) { int i, n; unsigned int b; size_t soutl; int ret; int blocksize; if (outl != NULL) { *outl = 0; } else { ERR_raise(ERR_LIB_EVP, ERR_R_PASSED_NULL_PARAMETER); return 0; } /* Prevent accidental use of encryption context when decrypting */ if (ctx->encrypt) { ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_OPERATION); return 0; } if (ctx->cipher == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_NO_CIPHER_SET); return 0; } if (ctx->cipher->prov == NULL) goto legacy; blocksize = EVP_CIPHER_CTX_get_block_size(ctx); if (blocksize < 1 || ctx->cipher->cfinal == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_FINAL_ERROR); return 0; } ret = ctx->cipher->cfinal(ctx->algctx, out, &soutl, blocksize == 1 ? 0 : blocksize); if (ret) { if (soutl > INT_MAX) { ERR_raise(ERR_LIB_EVP, EVP_R_FINAL_ERROR); return 0; } *outl = soutl; } return ret; /* Code below to be removed when legacy support is dropped. */ legacy: *outl = 0; if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) { i = ctx->cipher->do_cipher(ctx, out, NULL, 0); if (i < 0) return 0; else *outl = i; return 1; } b = ctx->cipher->block_size; if (ctx->flags & EVP_CIPH_NO_PADDING) { if (ctx->buf_len) { ERR_raise(ERR_LIB_EVP, EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH); return 0; } *outl = 0; return 1; } if (b > 1) { if (ctx->buf_len || !ctx->final_used) { ERR_raise(ERR_LIB_EVP, EVP_R_WRONG_FINAL_BLOCK_LENGTH); return 0; } OPENSSL_assert(b <= sizeof(ctx->final)); /* * The following assumes that the ciphertext has been authenticated. * Otherwise it provides a padding oracle. */ n = ctx->final[b - 1]; if (n == 0 || n > (int)b) { ERR_raise(ERR_LIB_EVP, EVP_R_BAD_DECRYPT); return 0; } for (i = 0; i < n; i++) { if (ctx->final[--b] != n) { ERR_raise(ERR_LIB_EVP, EVP_R_BAD_DECRYPT); return 0; } } n = ctx->cipher->block_size - n; for (i = 0; i < n; i++) out[i] = ctx->final[i]; *outl = n; } else *outl = 0; return 1; } int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *c, int keylen) { if (c->cipher->prov != NULL) { int ok; OSSL_PARAM params[2] = { OSSL_PARAM_END, OSSL_PARAM_END }; size_t len = keylen; if (EVP_CIPHER_CTX_get_key_length(c) == keylen) return 1; /* Check the cipher actually understands this parameter */ if (OSSL_PARAM_locate_const(EVP_CIPHER_settable_ctx_params(c->cipher), OSSL_CIPHER_PARAM_KEYLEN) == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_KEY_LENGTH); return 0; } params[0] = OSSL_PARAM_construct_size_t(OSSL_CIPHER_PARAM_KEYLEN, &len); ok = evp_do_ciph_ctx_setparams(c->cipher, c->algctx, params); return ok > 0 ? 1 : 0; } /* Code below to be removed when legacy support is dropped. */ /* * Note there have never been any built-in ciphers that define this flag * since it was first introduced. */ if (c->cipher->flags & EVP_CIPH_CUSTOM_KEY_LENGTH) return EVP_CIPHER_CTX_ctrl(c, EVP_CTRL_SET_KEY_LENGTH, keylen, NULL); if (EVP_CIPHER_CTX_get_key_length(c) == keylen) return 1; if ((keylen > 0) && (c->cipher->flags & EVP_CIPH_VARIABLE_LENGTH)) { c->key_len = keylen; return 1; } ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_KEY_LENGTH); return 0; } int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *ctx, int pad) { int ok; OSSL_PARAM params[2] = { OSSL_PARAM_END, OSSL_PARAM_END }; unsigned int pd = pad; if (pad) ctx->flags &= ~EVP_CIPH_NO_PADDING; else ctx->flags |= EVP_CIPH_NO_PADDING; if (ctx->cipher != NULL && ctx->cipher->prov == NULL) return 1; params[0] = OSSL_PARAM_construct_uint(OSSL_CIPHER_PARAM_PADDING, &pd); ok = evp_do_ciph_ctx_setparams(ctx->cipher, ctx->algctx, params); return ok != 0; } int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr) { int ret = EVP_CTRL_RET_UNSUPPORTED; int set_params = 1; size_t sz = arg; unsigned int i; OSSL_PARAM params[4] = { OSSL_PARAM_END, OSSL_PARAM_END, OSSL_PARAM_END, OSSL_PARAM_END }; if (ctx == NULL || ctx->cipher == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_NO_CIPHER_SET); return 0; } if (ctx->cipher->prov == NULL) goto legacy; switch (type) { case EVP_CTRL_SET_KEY_LENGTH: params[0] = OSSL_PARAM_construct_size_t(OSSL_CIPHER_PARAM_KEYLEN, &sz); break; case EVP_CTRL_RAND_KEY: /* Used by DES */ set_params = 0; params[0] = OSSL_PARAM_construct_octet_string(OSSL_CIPHER_PARAM_RANDOM_KEY, ptr, sz); break; case EVP_CTRL_INIT: /* * EVP_CTRL_INIT is purely legacy, no provider counterpart. * As a matter of fact, this should be dead code, but some caller * might still do a direct control call with this command, so... * Legacy methods return 1 except for exceptional circumstances, so * we do the same here to not be disruptive. */ return 1; case EVP_CTRL_SET_PIPELINE_OUTPUT_BUFS: /* Used by DASYNC */ default: goto end; case EVP_CTRL_AEAD_SET_IVLEN: if (arg < 0) return 0; params[0] = OSSL_PARAM_construct_size_t(OSSL_CIPHER_PARAM_IVLEN, &sz); ctx->iv_len = -1; break; case EVP_CTRL_CCM_SET_L: if (arg < 2 || arg > 8) return 0; sz = 15 - arg; params[0] = OSSL_PARAM_construct_size_t(OSSL_CIPHER_PARAM_IVLEN, &sz); ctx->iv_len = -1; break; case EVP_CTRL_AEAD_SET_IV_FIXED: params[0] = OSSL_PARAM_construct_octet_string( OSSL_CIPHER_PARAM_AEAD_TLS1_IV_FIXED, ptr, sz); break; case EVP_CTRL_GCM_IV_GEN: set_params = 0; if (arg < 0) sz = 0; /* special case that uses the iv length */ params[0] = OSSL_PARAM_construct_octet_string( OSSL_CIPHER_PARAM_AEAD_TLS1_GET_IV_GEN, ptr, sz); break; case EVP_CTRL_GCM_SET_IV_INV: if (arg < 0) return 0; params[0] = OSSL_PARAM_construct_octet_string( OSSL_CIPHER_PARAM_AEAD_TLS1_SET_IV_INV, ptr, sz); break; case EVP_CTRL_GET_RC5_ROUNDS: set_params = 0; /* Fall thru */ case EVP_CTRL_SET_RC5_ROUNDS: if (arg < 0) return 0; i = (unsigned int)arg; params[0] = OSSL_PARAM_construct_uint(OSSL_CIPHER_PARAM_ROUNDS, &i); break; case EVP_CTRL_SET_SPEED: if (arg < 0) return 0; i = (unsigned int)arg; params[0] = OSSL_PARAM_construct_uint(OSSL_CIPHER_PARAM_SPEED, &i); break; case EVP_CTRL_AEAD_GET_TAG: set_params = 0; /* Fall thru */ case EVP_CTRL_AEAD_SET_TAG: params[0] = OSSL_PARAM_construct_octet_string(OSSL_CIPHER_PARAM_AEAD_TAG, ptr, sz); break; case EVP_CTRL_AEAD_TLS1_AAD: /* This one does a set and a get - since it returns a size */ params[0] = OSSL_PARAM_construct_octet_string(OSSL_CIPHER_PARAM_AEAD_TLS1_AAD, ptr, sz); ret = evp_do_ciph_ctx_setparams(ctx->cipher, ctx->algctx, params); if (ret <= 0) goto end; params[0] = OSSL_PARAM_construct_size_t(OSSL_CIPHER_PARAM_AEAD_TLS1_AAD_PAD, &sz); ret = evp_do_ciph_ctx_getparams(ctx->cipher, ctx->algctx, params); if (ret <= 0) goto end; return sz; #ifndef OPENSSL_NO_RC2 case EVP_CTRL_GET_RC2_KEY_BITS: set_params = 0; /* Fall thru */ case EVP_CTRL_SET_RC2_KEY_BITS: params[0] = OSSL_PARAM_construct_size_t(OSSL_CIPHER_PARAM_RC2_KEYBITS, &sz); break; #endif /* OPENSSL_NO_RC2 */ #if !defined(OPENSSL_NO_MULTIBLOCK) case EVP_CTRL_TLS1_1_MULTIBLOCK_MAX_BUFSIZE: params[0] = OSSL_PARAM_construct_size_t( OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_MAX_SEND_FRAGMENT, &sz); ret = evp_do_ciph_ctx_setparams(ctx->cipher, ctx->algctx, params); if (ret <= 0) return 0; params[0] = OSSL_PARAM_construct_size_t( OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_MAX_BUFSIZE, &sz); params[1] = OSSL_PARAM_construct_end(); ret = evp_do_ciph_ctx_getparams(ctx->cipher, ctx->algctx, params); if (ret <= 0) return 0; return sz; case EVP_CTRL_TLS1_1_MULTIBLOCK_AAD: { EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM *p = (EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM *)ptr; if (arg < (int)sizeof(EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM)) return 0; params[0] = OSSL_PARAM_construct_octet_string( OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_AAD, (void*)p->inp, p->len); params[1] = OSSL_PARAM_construct_uint( OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_INTERLEAVE, &p->interleave); ret = evp_do_ciph_ctx_setparams(ctx->cipher, ctx->algctx, params); if (ret <= 0) return ret; /* Retrieve the return values changed by the set */ params[0] = OSSL_PARAM_construct_size_t( OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_AAD_PACKLEN, &sz); params[1] = OSSL_PARAM_construct_uint( OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_INTERLEAVE, &p->interleave); params[2] = OSSL_PARAM_construct_end(); ret = evp_do_ciph_ctx_getparams(ctx->cipher, ctx->algctx, params); if (ret <= 0) return 0; return sz; } case EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT: { EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM *p = (EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM *)ptr; params[0] = OSSL_PARAM_construct_octet_string( OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_ENC, p->out, p->len); params[1] = OSSL_PARAM_construct_octet_string( OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_ENC_IN, (void*)p->inp, p->len); params[2] = OSSL_PARAM_construct_uint( OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_INTERLEAVE, &p->interleave); ret = evp_do_ciph_ctx_setparams(ctx->cipher, ctx->algctx, params); if (ret <= 0) return ret; params[0] = OSSL_PARAM_construct_size_t( OSSL_CIPHER_PARAM_TLS1_MULTIBLOCK_ENC_LEN, &sz); params[1] = OSSL_PARAM_construct_end(); ret = evp_do_ciph_ctx_getparams(ctx->cipher, ctx->algctx, params); if (ret <= 0) return 0; return sz; } #endif /* OPENSSL_NO_MULTIBLOCK */ case EVP_CTRL_AEAD_SET_MAC_KEY: if (arg < 0) return -1; params[0] = OSSL_PARAM_construct_octet_string( OSSL_CIPHER_PARAM_AEAD_MAC_KEY, ptr, sz); break; } if (set_params) ret = evp_do_ciph_ctx_setparams(ctx->cipher, ctx->algctx, params); else ret = evp_do_ciph_ctx_getparams(ctx->cipher, ctx->algctx, params); goto end; /* Code below to be removed when legacy support is dropped. */ legacy: if (ctx->cipher->ctrl == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_CTRL_NOT_IMPLEMENTED); return 0; } ret = ctx->cipher->ctrl(ctx, type, arg, ptr); end: if (ret == EVP_CTRL_RET_UNSUPPORTED) { ERR_raise(ERR_LIB_EVP, EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED); return 0; } return ret; } int EVP_CIPHER_get_params(EVP_CIPHER *cipher, OSSL_PARAM params[]) { if (cipher != NULL && cipher->get_params != NULL) return cipher->get_params(params); return 0; } int EVP_CIPHER_CTX_set_params(EVP_CIPHER_CTX *ctx, const OSSL_PARAM params[]) { if (ctx->cipher != NULL && ctx->cipher->set_ctx_params != NULL) { ctx->iv_len = -1; return ctx->cipher->set_ctx_params(ctx->algctx, params); } return 0; } int EVP_CIPHER_CTX_get_params(EVP_CIPHER_CTX *ctx, OSSL_PARAM params[]) { if (ctx->cipher != NULL && ctx->cipher->get_ctx_params != NULL) return ctx->cipher->get_ctx_params(ctx->algctx, params); return 0; } const OSSL_PARAM *EVP_CIPHER_gettable_params(const EVP_CIPHER *cipher) { if (cipher != NULL && cipher->gettable_params != NULL) return cipher->gettable_params( ossl_provider_ctx(EVP_CIPHER_get0_provider(cipher))); return NULL; } const OSSL_PARAM *EVP_CIPHER_settable_ctx_params(const EVP_CIPHER *cipher) { void *provctx; if (cipher != NULL && cipher->settable_ctx_params != NULL) { provctx = ossl_provider_ctx(EVP_CIPHER_get0_provider(cipher)); return cipher->settable_ctx_params(NULL, provctx); } return NULL; } const OSSL_PARAM *EVP_CIPHER_gettable_ctx_params(const EVP_CIPHER *cipher) { void *provctx; if (cipher != NULL && cipher->gettable_ctx_params != NULL) { provctx = ossl_provider_ctx(EVP_CIPHER_get0_provider(cipher)); return cipher->gettable_ctx_params(NULL, provctx); } return NULL; } const OSSL_PARAM *EVP_CIPHER_CTX_settable_params(EVP_CIPHER_CTX *cctx) { void *alg; if (cctx != NULL && cctx->cipher->settable_ctx_params != NULL) { alg = ossl_provider_ctx(EVP_CIPHER_get0_provider(cctx->cipher)); return cctx->cipher->settable_ctx_params(cctx->algctx, alg); } return NULL; } const OSSL_PARAM *EVP_CIPHER_CTX_gettable_params(EVP_CIPHER_CTX *cctx) { void *provctx; if (cctx != NULL && cctx->cipher->gettable_ctx_params != NULL) { provctx = ossl_provider_ctx(EVP_CIPHER_get0_provider(cctx->cipher)); return cctx->cipher->gettable_ctx_params(cctx->algctx, provctx); } return NULL; } #ifndef FIPS_MODULE static OSSL_LIB_CTX *EVP_CIPHER_CTX_get_libctx(EVP_CIPHER_CTX *ctx) { const EVP_CIPHER *cipher = ctx->cipher; const OSSL_PROVIDER *prov; if (cipher == NULL) return NULL; prov = EVP_CIPHER_get0_provider(cipher); return ossl_provider_libctx(prov); } #endif int EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key) { if (ctx->cipher->flags & EVP_CIPH_RAND_KEY) return EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_RAND_KEY, 0, key); #ifdef FIPS_MODULE return 0; #else { int kl; OSSL_LIB_CTX *libctx = EVP_CIPHER_CTX_get_libctx(ctx); kl = EVP_CIPHER_CTX_get_key_length(ctx); if (kl <= 0 || RAND_priv_bytes_ex(libctx, key, kl, 0) <= 0) return 0; return 1; } #endif /* FIPS_MODULE */ } int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in) { if ((in == NULL) || (in->cipher == NULL)) { ERR_raise(ERR_LIB_EVP, EVP_R_INPUT_NOT_INITIALIZED); return 0; } if (in->cipher->prov == NULL) goto legacy; if (in->cipher->dupctx == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_NOT_ABLE_TO_COPY_CTX); return 0; } EVP_CIPHER_CTX_reset(out); *out = *in; out->algctx = NULL; if (in->fetched_cipher != NULL && !EVP_CIPHER_up_ref(in->fetched_cipher)) { out->fetched_cipher = NULL; return 0; } out->algctx = in->cipher->dupctx(in->algctx); if (out->algctx == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_NOT_ABLE_TO_COPY_CTX); return 0; } return 1; /* Code below to be removed when legacy support is dropped. */ legacy: #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) /* Make sure it's safe to copy a cipher context using an ENGINE */ if (in->engine && !ENGINE_init(in->engine)) { ERR_raise(ERR_LIB_EVP, ERR_R_ENGINE_LIB); return 0; } #endif EVP_CIPHER_CTX_reset(out); memcpy(out, in, sizeof(*out)); if (in->cipher_data && in->cipher->ctx_size) { out->cipher_data = OPENSSL_malloc(in->cipher->ctx_size); if (out->cipher_data == NULL) { out->cipher = NULL; ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE); return 0; } memcpy(out->cipher_data, in->cipher_data, in->cipher->ctx_size); } if (in->cipher->flags & EVP_CIPH_CUSTOM_COPY) if (!in->cipher->ctrl((EVP_CIPHER_CTX *)in, EVP_CTRL_COPY, 0, out)) { out->cipher = NULL; ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR); return 0; } return 1; } EVP_CIPHER *evp_cipher_new(void) { EVP_CIPHER *cipher = OPENSSL_zalloc(sizeof(EVP_CIPHER)); if (cipher != NULL) { cipher->lock = CRYPTO_THREAD_lock_new(); if (cipher->lock == NULL) { OPENSSL_free(cipher); return NULL; } cipher->refcnt = 1; } return cipher; } /* * FIPS module note: since internal fetches will be entirely * provider based, we know that none of its code depends on legacy * NIDs or any functionality that use them. */ #ifndef FIPS_MODULE /* After removal of legacy support get rid of the need for legacy NIDs */ static void set_legacy_nid(const char *name, void *vlegacy_nid) { int nid; int *legacy_nid = vlegacy_nid; /* * We use lowest level function to get the associated method, because * higher level functions such as EVP_get_cipherbyname() have changed * to look at providers too. */ const void *legacy_method = OBJ_NAME_get(name, OBJ_NAME_TYPE_CIPHER_METH); if (*legacy_nid == -1) /* We found a clash already */ return; if (legacy_method == NULL) return; nid = EVP_CIPHER_get_nid(legacy_method); if (*legacy_nid != NID_undef && *legacy_nid != nid) { *legacy_nid = -1; return; } *legacy_nid = nid; } #endif static void *evp_cipher_from_algorithm(const int name_id, const OSSL_ALGORITHM *algodef, OSSL_PROVIDER *prov) { const OSSL_DISPATCH *fns = algodef->implementation; EVP_CIPHER *cipher = NULL; int fnciphcnt = 0, fnctxcnt = 0; if ((cipher = evp_cipher_new()) == NULL) { ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE); return NULL; } #ifndef FIPS_MODULE cipher->nid = NID_undef; if (!evp_names_do_all(prov, name_id, set_legacy_nid, &cipher->nid) || cipher->nid == -1) { ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR); EVP_CIPHER_free(cipher); return NULL; } #endif cipher->name_id = name_id; if ((cipher->type_name = ossl_algorithm_get1_first_name(algodef)) == NULL) { EVP_CIPHER_free(cipher); return NULL; } cipher->description = algodef->algorithm_description; for (; fns->function_id != 0; fns++) { switch (fns->function_id) { case OSSL_FUNC_CIPHER_NEWCTX: if (cipher->newctx != NULL) break; cipher->newctx = OSSL_FUNC_cipher_newctx(fns); fnctxcnt++; break; case OSSL_FUNC_CIPHER_ENCRYPT_INIT: if (cipher->einit != NULL) break; cipher->einit = OSSL_FUNC_cipher_encrypt_init(fns); fnciphcnt++; break; case OSSL_FUNC_CIPHER_DECRYPT_INIT: if (cipher->dinit != NULL) break; cipher->dinit = OSSL_FUNC_cipher_decrypt_init(fns); fnciphcnt++; break; case OSSL_FUNC_CIPHER_UPDATE: if (cipher->cupdate != NULL) break; cipher->cupdate = OSSL_FUNC_cipher_update(fns); fnciphcnt++; break; case OSSL_FUNC_CIPHER_FINAL: if (cipher->cfinal != NULL) break; cipher->cfinal = OSSL_FUNC_cipher_final(fns); fnciphcnt++; break; case OSSL_FUNC_CIPHER_CIPHER: if (cipher->ccipher != NULL) break; cipher->ccipher = OSSL_FUNC_cipher_cipher(fns); break; case OSSL_FUNC_CIPHER_FREECTX: if (cipher->freectx != NULL) break; cipher->freectx = OSSL_FUNC_cipher_freectx(fns); fnctxcnt++; break; case OSSL_FUNC_CIPHER_DUPCTX: if (cipher->dupctx != NULL) break; cipher->dupctx = OSSL_FUNC_cipher_dupctx(fns); break; case OSSL_FUNC_CIPHER_GET_PARAMS: if (cipher->get_params != NULL) break; cipher->get_params = OSSL_FUNC_cipher_get_params(fns); break; case OSSL_FUNC_CIPHER_GET_CTX_PARAMS: if (cipher->get_ctx_params != NULL) break; cipher->get_ctx_params = OSSL_FUNC_cipher_get_ctx_params(fns); break; case OSSL_FUNC_CIPHER_SET_CTX_PARAMS: if (cipher->set_ctx_params != NULL) break; cipher->set_ctx_params = OSSL_FUNC_cipher_set_ctx_params(fns); break; case OSSL_FUNC_CIPHER_GETTABLE_PARAMS: if (cipher->gettable_params != NULL) break; cipher->gettable_params = OSSL_FUNC_cipher_gettable_params(fns); break; case OSSL_FUNC_CIPHER_GETTABLE_CTX_PARAMS: if (cipher->gettable_ctx_params != NULL) break; cipher->gettable_ctx_params = OSSL_FUNC_cipher_gettable_ctx_params(fns); break; case OSSL_FUNC_CIPHER_SETTABLE_CTX_PARAMS: if (cipher->settable_ctx_params != NULL) break; cipher->settable_ctx_params = OSSL_FUNC_cipher_settable_ctx_params(fns); break; } } if ((fnciphcnt != 0 && fnciphcnt != 3 && fnciphcnt != 4) || (fnciphcnt == 0 && cipher->ccipher == NULL) || fnctxcnt != 2) { /* * In order to be a consistent set of functions we must have at least * a complete set of "encrypt" functions, or a complete set of "decrypt" * functions, or a single "cipher" function. In all cases we need both * the "newctx" and "freectx" functions. */ EVP_CIPHER_free(cipher); ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_PROVIDER_FUNCTIONS); return NULL; } cipher->prov = prov; if (prov != NULL) ossl_provider_up_ref(prov); if (!evp_cipher_cache_constants(cipher)) { EVP_CIPHER_free(cipher); ERR_raise(ERR_LIB_EVP, EVP_R_CACHE_CONSTANTS_FAILED); cipher = NULL; } return cipher; } static int evp_cipher_up_ref(void *cipher) { return EVP_CIPHER_up_ref(cipher); } static void evp_cipher_free(void *cipher) { EVP_CIPHER_free(cipher); } EVP_CIPHER *EVP_CIPHER_fetch(OSSL_LIB_CTX *ctx, const char *algorithm, const char *properties) { EVP_CIPHER *cipher = evp_generic_fetch(ctx, OSSL_OP_CIPHER, algorithm, properties, evp_cipher_from_algorithm, evp_cipher_up_ref, evp_cipher_free); return cipher; } int EVP_CIPHER_up_ref(EVP_CIPHER *cipher) { int ref = 0; if (cipher->origin == EVP_ORIG_DYNAMIC) CRYPTO_UP_REF(&cipher->refcnt, &ref, cipher->lock); return 1; } void evp_cipher_free_int(EVP_CIPHER *cipher) { OPENSSL_free(cipher->type_name); ossl_provider_free(cipher->prov); CRYPTO_THREAD_lock_free(cipher->lock); OPENSSL_free(cipher); } void EVP_CIPHER_free(EVP_CIPHER *cipher) { int i; if (cipher == NULL || cipher->origin != EVP_ORIG_DYNAMIC) return; CRYPTO_DOWN_REF(&cipher->refcnt, &i, cipher->lock); if (i > 0) return; evp_cipher_free_int(cipher); } void EVP_CIPHER_do_all_provided(OSSL_LIB_CTX *libctx, void (*fn)(EVP_CIPHER *mac, void *arg), void *arg) { evp_generic_do_all(libctx, OSSL_OP_CIPHER, (void (*)(void *, void *))fn, arg, evp_cipher_from_algorithm, evp_cipher_up_ref, evp_cipher_free); } diff --git a/crypto/openssl/crypto/evp/legacy_sha.c b/crypto/openssl/crypto/evp/legacy_sha.c index 3859286eeb20..ca9a3264978a 100644 --- a/crypto/openssl/crypto/evp/legacy_sha.c +++ b/crypto/openssl/crypto/evp/legacy_sha.c @@ -1,228 +1,232 @@ /* - * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ /* * All SHA low level APIs are deprecated for public use, but still ok for * internal use. */ #include "internal/deprecated.h" #include /* diverse SHA macros */ #include "internal/sha3.h" /* KECCAK1600_WIDTH */ #include "crypto/evp.h" /* Used by legacy methods */ #include "crypto/sha.h" #include "legacy_meth.h" #include "evp_local.h" /*- * LEGACY methods for SHA. * These only remain to support engines that can get these methods. * Hardware support for SHA3 has been removed from these legacy cases. */ #define IMPLEMENT_LEGACY_EVP_MD_METH_SHA3(nm, fn, tag) \ static int nm##_init(EVP_MD_CTX *ctx) \ { \ return fn##_init(EVP_MD_CTX_get0_md_data(ctx), tag, ctx->digest->md_size * 8); \ } \ static int nm##_update(EVP_MD_CTX *ctx, const void *data, size_t count) \ { \ return fn##_update(EVP_MD_CTX_get0_md_data(ctx), data, count); \ } \ static int nm##_final(EVP_MD_CTX *ctx, unsigned char *md) \ { \ return fn##_final(md, EVP_MD_CTX_get0_md_data(ctx)); \ } #define IMPLEMENT_LEGACY_EVP_MD_METH_SHAKE(nm, fn, tag) \ static int nm##_init(EVP_MD_CTX *ctx) \ { \ return fn##_init(EVP_MD_CTX_get0_md_data(ctx), tag, ctx->digest->md_size * 8); \ } \ #define sha512_224_Init sha512_224_init #define sha512_256_Init sha512_256_init #define sha512_224_Update SHA512_Update #define sha512_224_Final SHA512_Final #define sha512_256_Update SHA512_Update #define sha512_256_Final SHA512_Final IMPLEMENT_LEGACY_EVP_MD_METH(sha1, SHA1) IMPLEMENT_LEGACY_EVP_MD_METH(sha224, SHA224) IMPLEMENT_LEGACY_EVP_MD_METH(sha256, SHA256) IMPLEMENT_LEGACY_EVP_MD_METH(sha384, SHA384) IMPLEMENT_LEGACY_EVP_MD_METH(sha512, SHA512) IMPLEMENT_LEGACY_EVP_MD_METH(sha512_224_int, sha512_224) IMPLEMENT_LEGACY_EVP_MD_METH(sha512_256_int, sha512_256) IMPLEMENT_LEGACY_EVP_MD_METH_SHA3(sha3_int, ossl_sha3, '\x06') IMPLEMENT_LEGACY_EVP_MD_METH_SHAKE(shake, ossl_sha3, '\x1f') static int sha1_int_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void *p2) { return ossl_sha1_ctrl(ctx != NULL ? EVP_MD_CTX_get0_md_data(ctx) : NULL, cmd, p1, p2); } static int shake_ctrl(EVP_MD_CTX *evp_ctx, int cmd, int p1, void *p2) { - KECCAK1600_CTX *ctx = evp_ctx->md_data; + KECCAK1600_CTX *ctx; + + if (evp_ctx == NULL) + return 0; + ctx = evp_ctx->md_data; switch (cmd) { case EVP_MD_CTRL_XOF_LEN: ctx->md_size = p1; return 1; default: return 0; } } static const EVP_MD sha1_md = { NID_sha1, NID_sha1WithRSAEncryption, SHA_DIGEST_LENGTH, EVP_MD_FLAG_DIGALGID_ABSENT, EVP_ORIG_GLOBAL, LEGACY_EVP_MD_METH_TABLE(sha1_init, sha1_update, sha1_final, sha1_int_ctrl, SHA_CBLOCK), }; const EVP_MD *EVP_sha1(void) { return &sha1_md; } static const EVP_MD sha224_md = { NID_sha224, NID_sha224WithRSAEncryption, SHA224_DIGEST_LENGTH, EVP_MD_FLAG_DIGALGID_ABSENT, EVP_ORIG_GLOBAL, LEGACY_EVP_MD_METH_TABLE(sha224_init, sha224_update, sha224_final, NULL, SHA256_CBLOCK), }; const EVP_MD *EVP_sha224(void) { return &sha224_md; } static const EVP_MD sha256_md = { NID_sha256, NID_sha256WithRSAEncryption, SHA256_DIGEST_LENGTH, EVP_MD_FLAG_DIGALGID_ABSENT, EVP_ORIG_GLOBAL, LEGACY_EVP_MD_METH_TABLE(sha256_init, sha256_update, sha256_final, NULL, SHA256_CBLOCK), }; const EVP_MD *EVP_sha256(void) { return &sha256_md; } static const EVP_MD sha512_224_md = { NID_sha512_224, NID_sha512_224WithRSAEncryption, SHA224_DIGEST_LENGTH, EVP_MD_FLAG_DIGALGID_ABSENT, EVP_ORIG_GLOBAL, LEGACY_EVP_MD_METH_TABLE(sha512_224_int_init, sha512_224_int_update, sha512_224_int_final, NULL, SHA512_CBLOCK), }; const EVP_MD *EVP_sha512_224(void) { return &sha512_224_md; } static const EVP_MD sha512_256_md = { NID_sha512_256, NID_sha512_256WithRSAEncryption, SHA256_DIGEST_LENGTH, EVP_MD_FLAG_DIGALGID_ABSENT, EVP_ORIG_GLOBAL, LEGACY_EVP_MD_METH_TABLE(sha512_256_int_init, sha512_256_int_update, sha512_256_int_final, NULL, SHA512_CBLOCK), }; const EVP_MD *EVP_sha512_256(void) { return &sha512_256_md; } static const EVP_MD sha384_md = { NID_sha384, NID_sha384WithRSAEncryption, SHA384_DIGEST_LENGTH, EVP_MD_FLAG_DIGALGID_ABSENT, EVP_ORIG_GLOBAL, LEGACY_EVP_MD_METH_TABLE(sha384_init, sha384_update, sha384_final, NULL, SHA512_CBLOCK), }; const EVP_MD *EVP_sha384(void) { return &sha384_md; } static const EVP_MD sha512_md = { NID_sha512, NID_sha512WithRSAEncryption, SHA512_DIGEST_LENGTH, EVP_MD_FLAG_DIGALGID_ABSENT, EVP_ORIG_GLOBAL, LEGACY_EVP_MD_METH_TABLE(sha512_init, sha512_update, sha512_final, NULL, SHA512_CBLOCK), }; const EVP_MD *EVP_sha512(void) { return &sha512_md; } #define EVP_MD_SHA3(bitlen) \ const EVP_MD *EVP_sha3_##bitlen(void) \ { \ static const EVP_MD sha3_##bitlen##_md = { \ NID_sha3_##bitlen, \ NID_RSA_SHA3_##bitlen, \ bitlen / 8, \ EVP_MD_FLAG_DIGALGID_ABSENT, \ EVP_ORIG_GLOBAL, \ LEGACY_EVP_MD_METH_TABLE(sha3_int_init, sha3_int_update, \ sha3_int_final, NULL, \ (KECCAK1600_WIDTH - bitlen * 2) / 8), \ }; \ return &sha3_##bitlen##_md; \ } #define EVP_MD_SHAKE(bitlen) \ const EVP_MD *EVP_shake##bitlen(void) \ { \ static const EVP_MD shake##bitlen##_md = { \ NID_shake##bitlen, \ 0, \ bitlen / 8, \ EVP_MD_FLAG_XOF, \ EVP_ORIG_GLOBAL, \ LEGACY_EVP_MD_METH_TABLE(shake_init, sha3_int_update, sha3_int_final, \ shake_ctrl, (KECCAK1600_WIDTH - bitlen * 2) / 8), \ }; \ return &shake##bitlen##_md; \ } EVP_MD_SHA3(224) EVP_MD_SHA3(256) EVP_MD_SHA3(384) EVP_MD_SHA3(512) EVP_MD_SHAKE(128) EVP_MD_SHAKE(256) diff --git a/crypto/openssl/crypto/evp/p_lib.c b/crypto/openssl/crypto/evp/p_lib.c index 59a7a867ecbb..04b148a91218 100644 --- a/crypto/openssl/crypto/evp/p_lib.c +++ b/crypto/openssl/crypto/evp/p_lib.c @@ -1,2476 +1,2476 @@ /* * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ /* * DSA low level APIs are deprecated for public use, but still ok for * internal use. */ #include "internal/deprecated.h" #include #include #include "internal/cryptlib.h" #include "internal/refcount.h" #include "internal/namemap.h" #include #include #include #include #include #include #include #include #include #ifndef FIPS_MODULE # include #endif #include #include #include #include #include "internal/numbers.h" /* includes SIZE_MAX */ #include "internal/ffc.h" #include "crypto/evp.h" #include "crypto/dh.h" #include "crypto/dsa.h" #include "crypto/ec.h" #include "crypto/ecx.h" #include "crypto/rsa.h" #ifndef FIPS_MODULE # include "crypto/asn1.h" # include "crypto/x509.h" #endif #include "internal/provider.h" #include "evp_local.h" static int pkey_set_type(EVP_PKEY *pkey, ENGINE *e, int type, const char *str, int len, EVP_KEYMGMT *keymgmt); static void evp_pkey_free_it(EVP_PKEY *key); #ifndef FIPS_MODULE /* The type of parameters selected in key parameter functions */ # define SELECT_PARAMETERS OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS int EVP_PKEY_get_bits(const EVP_PKEY *pkey) { int size = 0; if (pkey != NULL) { size = pkey->cache.bits; if (pkey->ameth != NULL && pkey->ameth->pkey_bits != NULL) size = pkey->ameth->pkey_bits(pkey); } return size < 0 ? 0 : size; } int EVP_PKEY_get_security_bits(const EVP_PKEY *pkey) { int size = 0; if (pkey != NULL) { size = pkey->cache.security_bits; if (pkey->ameth != NULL && pkey->ameth->pkey_security_bits != NULL) size = pkey->ameth->pkey_security_bits(pkey); } return size < 0 ? 0 : size; } int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode) { # ifndef OPENSSL_NO_DSA if (pkey->type == EVP_PKEY_DSA) { int ret = pkey->save_parameters; if (mode >= 0) pkey->save_parameters = mode; return ret; } # endif # ifndef OPENSSL_NO_EC if (pkey->type == EVP_PKEY_EC) { int ret = pkey->save_parameters; if (mode >= 0) pkey->save_parameters = mode; return ret; } # endif return 0; } int EVP_PKEY_set_ex_data(EVP_PKEY *key, int idx, void *arg) { return CRYPTO_set_ex_data(&key->ex_data, idx, arg); } void *EVP_PKEY_get_ex_data(const EVP_PKEY *key, int idx) { return CRYPTO_get_ex_data(&key->ex_data, idx); } int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from) { /* * Clean up legacy stuff from this function when legacy support is gone. */ EVP_PKEY *downgraded_from = NULL; int ok = 0; /* * If |to| is a legacy key and |from| isn't, we must make a downgraded * copy of |from|. If that fails, this function fails. */ if (evp_pkey_is_legacy(to) && evp_pkey_is_provided(from)) { if (!evp_pkey_copy_downgraded(&downgraded_from, from)) goto end; from = downgraded_from; } /* * Make sure |to| is typed. Content is less important at this early * stage. * * 1. If |to| is untyped, assign |from|'s key type to it. * 2. If |to| contains a legacy key, compare its |type| to |from|'s. * (|from| was already downgraded above) * * If |to| is a provided key, there's nothing more to do here, functions * like evp_keymgmt_util_copy() and evp_pkey_export_to_provider() called * further down help us find out if they are the same or not. */ if (evp_pkey_is_blank(to)) { if (evp_pkey_is_legacy(from)) { if (EVP_PKEY_set_type(to, from->type) == 0) goto end; } else { if (EVP_PKEY_set_type_by_keymgmt(to, from->keymgmt) == 0) goto end; } } else if (evp_pkey_is_legacy(to)) { if (to->type != from->type) { ERR_raise(ERR_LIB_EVP, EVP_R_DIFFERENT_KEY_TYPES); goto end; } } if (EVP_PKEY_missing_parameters(from)) { ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_PARAMETERS); goto end; } if (!EVP_PKEY_missing_parameters(to)) { if (EVP_PKEY_parameters_eq(to, from) == 1) ok = 1; else ERR_raise(ERR_LIB_EVP, EVP_R_DIFFERENT_PARAMETERS); goto end; } /* For purely provided keys, we just call the keymgmt utility */ if (to->keymgmt != NULL && from->keymgmt != NULL) { ok = evp_keymgmt_util_copy(to, (EVP_PKEY *)from, SELECT_PARAMETERS); goto end; } /* * If |to| is provided, we know that |from| is legacy at this point. * Try exporting |from| to |to|'s keymgmt, then use evp_keymgmt_dup() * to copy the appropriate data to |to|'s keydata. * We cannot override existing data so do it only if there is no keydata * in |to| yet. */ if (to->keymgmt != NULL && to->keydata == NULL) { EVP_KEYMGMT *to_keymgmt = to->keymgmt; void *from_keydata = evp_pkey_export_to_provider((EVP_PKEY *)from, NULL, &to_keymgmt, NULL); /* * If we get a NULL, it could be an internal error, or it could be * that there's a key mismatch. We're pretending the latter... */ if (from_keydata == NULL) ERR_raise(ERR_LIB_EVP, EVP_R_DIFFERENT_KEY_TYPES); else ok = (to->keydata = evp_keymgmt_dup(to->keymgmt, from_keydata, SELECT_PARAMETERS)) != NULL; goto end; } /* Both keys are legacy */ if (from->ameth != NULL && from->ameth->param_copy != NULL) ok = from->ameth->param_copy(to, from); end: EVP_PKEY_free(downgraded_from); return ok; } int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey) { if (pkey != NULL) { if (pkey->keymgmt != NULL) return !evp_keymgmt_util_has((EVP_PKEY *)pkey, SELECT_PARAMETERS); else if (pkey->ameth != NULL && pkey->ameth->param_missing != NULL) return pkey->ameth->param_missing(pkey); } return 0; } /* * This function is called for any mixture of keys except pure legacy pair. * When legacy keys are gone, we replace a call to this functions with * a call to evp_keymgmt_util_match(). */ static int evp_pkey_cmp_any(const EVP_PKEY *a, const EVP_PKEY *b, int selection) { EVP_KEYMGMT *keymgmt1 = NULL, *keymgmt2 = NULL; void *keydata1 = NULL, *keydata2 = NULL, *tmp_keydata = NULL; /* If none of them are provided, this function shouldn't have been called */ if (!ossl_assert(evp_pkey_is_provided(a) || evp_pkey_is_provided(b))) return -2; /* For purely provided keys, we just call the keymgmt utility */ if (evp_pkey_is_provided(a) && evp_pkey_is_provided(b)) return evp_keymgmt_util_match((EVP_PKEY *)a, (EVP_PKEY *)b, selection); /* * At this point, one of them is provided, the other not. This allows * us to compare types using legacy NIDs. */ if (evp_pkey_is_legacy(a) && !EVP_KEYMGMT_is_a(b->keymgmt, OBJ_nid2sn(a->type))) return -1; /* not the same key type */ if (evp_pkey_is_legacy(b) && !EVP_KEYMGMT_is_a(a->keymgmt, OBJ_nid2sn(b->type))) return -1; /* not the same key type */ /* * We've determined that they both are the same keytype, so the next * step is to do a bit of cross export to ensure we have keydata for * both keys in the same keymgmt. */ keymgmt1 = a->keymgmt; keydata1 = a->keydata; keymgmt2 = b->keymgmt; keydata2 = b->keydata; if (keymgmt2 != NULL && keymgmt2->match != NULL) { tmp_keydata = evp_pkey_export_to_provider((EVP_PKEY *)a, NULL, &keymgmt2, NULL); if (tmp_keydata != NULL) { keymgmt1 = keymgmt2; keydata1 = tmp_keydata; } } if (tmp_keydata == NULL && keymgmt1 != NULL && keymgmt1->match != NULL) { tmp_keydata = evp_pkey_export_to_provider((EVP_PKEY *)b, NULL, &keymgmt1, NULL); if (tmp_keydata != NULL) { keymgmt2 = keymgmt1; keydata2 = tmp_keydata; } } /* If we still don't have matching keymgmt implementations, we give up */ if (keymgmt1 != keymgmt2) return -2; /* If the keymgmt implementations are NULL, the export failed */ if (keymgmt1 == NULL) return -2; return evp_keymgmt_match(keymgmt1, keydata1, keydata2, selection); } # ifndef OPENSSL_NO_DEPRECATED_3_0 int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b) { return EVP_PKEY_parameters_eq(a, b); } #endif int EVP_PKEY_parameters_eq(const EVP_PKEY *a, const EVP_PKEY *b) { /* * This will just call evp_keymgmt_util_match when legacy support * is gone. */ if (a->keymgmt != NULL || b->keymgmt != NULL) return evp_pkey_cmp_any(a, b, SELECT_PARAMETERS); /* All legacy keys */ if (a->type != b->type) return -1; if (a->ameth != NULL && a->ameth->param_cmp != NULL) return a->ameth->param_cmp(a, b); return -2; } # ifndef OPENSSL_NO_DEPRECATED_3_0 int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b) { return EVP_PKEY_eq(a, b); } #endif int EVP_PKEY_eq(const EVP_PKEY *a, const EVP_PKEY *b) { /* * This will just call evp_keymgmt_util_match when legacy support * is gone. */ /* Trivial shortcuts */ if (a == b) return 1; if (a == NULL || b == NULL) return 0; if (a->keymgmt != NULL || b->keymgmt != NULL) { int selection = SELECT_PARAMETERS; if (evp_keymgmt_util_has((EVP_PKEY *)a, OSSL_KEYMGMT_SELECT_PUBLIC_KEY) && evp_keymgmt_util_has((EVP_PKEY *)b, OSSL_KEYMGMT_SELECT_PUBLIC_KEY)) selection |= OSSL_KEYMGMT_SELECT_PUBLIC_KEY; else selection |= OSSL_KEYMGMT_SELECT_KEYPAIR; return evp_pkey_cmp_any(a, b, selection); } /* All legacy keys */ if (a->type != b->type) return -1; if (a->ameth != NULL) { int ret; /* Compare parameters if the algorithm has them */ if (a->ameth->param_cmp != NULL) { ret = a->ameth->param_cmp(a, b); if (ret <= 0) return ret; } if (a->ameth->pub_cmp != NULL) return a->ameth->pub_cmp(a, b); } return -2; } static EVP_PKEY *new_raw_key_int(OSSL_LIB_CTX *libctx, const char *strtype, const char *propq, int nidtype, ENGINE *e, const unsigned char *key, size_t len, int key_is_priv) { EVP_PKEY *pkey = NULL; EVP_PKEY_CTX *ctx = NULL; const EVP_PKEY_ASN1_METHOD *ameth = NULL; int result = 0; # ifndef OPENSSL_NO_ENGINE /* Check if there is an Engine for this type */ if (e == NULL) { ENGINE *tmpe = NULL; if (strtype != NULL) ameth = EVP_PKEY_asn1_find_str(&tmpe, strtype, -1); else if (nidtype != EVP_PKEY_NONE) ameth = EVP_PKEY_asn1_find(&tmpe, nidtype); /* If tmpe is NULL then no engine is claiming to support this type */ if (tmpe == NULL) ameth = NULL; ENGINE_finish(tmpe); } # endif if (e == NULL && ameth == NULL) { /* * No engine is claiming to support this type, so lets see if we have * a provider. */ ctx = EVP_PKEY_CTX_new_from_name(libctx, strtype != NULL ? strtype : OBJ_nid2sn(nidtype), propq); if (ctx == NULL) goto err; /* May fail if no provider available */ ERR_set_mark(); if (EVP_PKEY_fromdata_init(ctx) == 1) { OSSL_PARAM params[] = { OSSL_PARAM_END, OSSL_PARAM_END }; ERR_clear_last_mark(); params[0] = OSSL_PARAM_construct_octet_string( key_is_priv ? OSSL_PKEY_PARAM_PRIV_KEY : OSSL_PKEY_PARAM_PUB_KEY, (void *)key, len); if (EVP_PKEY_fromdata(ctx, &pkey, EVP_PKEY_KEYPAIR, params) != 1) { ERR_raise(ERR_LIB_EVP, EVP_R_KEY_SETUP_FAILED); goto err; } EVP_PKEY_CTX_free(ctx); return pkey; } ERR_pop_to_mark(); /* else not supported so fallback to legacy */ } /* Legacy code path */ pkey = EVP_PKEY_new(); if (pkey == NULL) { ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE); goto err; } if (!pkey_set_type(pkey, e, nidtype, strtype, -1, NULL)) { /* EVPerr already called */ goto err; } if (!ossl_assert(pkey->ameth != NULL)) goto err; if (key_is_priv) { if (pkey->ameth->set_priv_key == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); goto err; } if (!pkey->ameth->set_priv_key(pkey, key, len)) { ERR_raise(ERR_LIB_EVP, EVP_R_KEY_SETUP_FAILED); goto err; } } else { if (pkey->ameth->set_pub_key == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); goto err; } if (!pkey->ameth->set_pub_key(pkey, key, len)) { ERR_raise(ERR_LIB_EVP, EVP_R_KEY_SETUP_FAILED); goto err; } } result = 1; err: if (!result) { EVP_PKEY_free(pkey); pkey = NULL; } EVP_PKEY_CTX_free(ctx); return pkey; } EVP_PKEY *EVP_PKEY_new_raw_private_key_ex(OSSL_LIB_CTX *libctx, const char *keytype, const char *propq, const unsigned char *priv, size_t len) { return new_raw_key_int(libctx, keytype, propq, EVP_PKEY_NONE, NULL, priv, len, 1); } EVP_PKEY *EVP_PKEY_new_raw_private_key(int type, ENGINE *e, const unsigned char *priv, size_t len) { return new_raw_key_int(NULL, NULL, NULL, type, e, priv, len, 1); } EVP_PKEY *EVP_PKEY_new_raw_public_key_ex(OSSL_LIB_CTX *libctx, const char *keytype, const char *propq, const unsigned char *pub, size_t len) { return new_raw_key_int(libctx, keytype, propq, EVP_PKEY_NONE, NULL, pub, len, 0); } EVP_PKEY *EVP_PKEY_new_raw_public_key(int type, ENGINE *e, const unsigned char *pub, size_t len) { return new_raw_key_int(NULL, NULL, NULL, type, e, pub, len, 0); } struct raw_key_details_st { unsigned char **key; size_t *len; int selection; }; static OSSL_CALLBACK get_raw_key_details; static int get_raw_key_details(const OSSL_PARAM params[], void *arg) { const OSSL_PARAM *p = NULL; struct raw_key_details_st *raw_key = arg; if (raw_key->selection == OSSL_KEYMGMT_SELECT_PRIVATE_KEY) { if ((p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PRIV_KEY)) != NULL) return OSSL_PARAM_get_octet_string(p, (void **)raw_key->key, raw_key->key == NULL ? 0 : *raw_key->len, raw_key->len); } else if (raw_key->selection == OSSL_KEYMGMT_SELECT_PUBLIC_KEY) { if ((p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PUB_KEY)) != NULL) return OSSL_PARAM_get_octet_string(p, (void **)raw_key->key, raw_key->key == NULL ? 0 : *raw_key->len, raw_key->len); } return 0; } int EVP_PKEY_get_raw_private_key(const EVP_PKEY *pkey, unsigned char *priv, size_t *len) { if (pkey->keymgmt != NULL) { struct raw_key_details_st raw_key; raw_key.key = priv == NULL ? NULL : &priv; raw_key.len = len; raw_key.selection = OSSL_KEYMGMT_SELECT_PRIVATE_KEY; return evp_keymgmt_util_export(pkey, OSSL_KEYMGMT_SELECT_PRIVATE_KEY, get_raw_key_details, &raw_key); } if (pkey->ameth == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); return 0; } if (pkey->ameth->get_priv_key == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); return 0; } if (!pkey->ameth->get_priv_key(pkey, priv, len)) { ERR_raise(ERR_LIB_EVP, EVP_R_GET_RAW_KEY_FAILED); return 0; } return 1; } int EVP_PKEY_get_raw_public_key(const EVP_PKEY *pkey, unsigned char *pub, size_t *len) { if (pkey->keymgmt != NULL) { struct raw_key_details_st raw_key; raw_key.key = pub == NULL ? NULL : &pub; raw_key.len = len; raw_key.selection = OSSL_KEYMGMT_SELECT_PUBLIC_KEY; return evp_keymgmt_util_export(pkey, OSSL_KEYMGMT_SELECT_PUBLIC_KEY, get_raw_key_details, &raw_key); } if (pkey->ameth == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); return 0; } if (pkey->ameth->get_pub_key == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); return 0; } if (!pkey->ameth->get_pub_key(pkey, pub, len)) { ERR_raise(ERR_LIB_EVP, EVP_R_GET_RAW_KEY_FAILED); return 0; } return 1; } static EVP_PKEY *new_cmac_key_int(const unsigned char *priv, size_t len, const char *cipher_name, const EVP_CIPHER *cipher, OSSL_LIB_CTX *libctx, const char *propq, ENGINE *e) { # ifndef OPENSSL_NO_CMAC # ifndef OPENSSL_NO_ENGINE const char *engine_id = e != NULL ? ENGINE_get_id(e) : NULL; # endif OSSL_PARAM params[5], *p = params; EVP_PKEY *pkey = NULL; EVP_PKEY_CTX *ctx; if (cipher != NULL) cipher_name = EVP_CIPHER_get0_name(cipher); if (cipher_name == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_KEY_SETUP_FAILED); return NULL; } ctx = EVP_PKEY_CTX_new_from_name(libctx, "CMAC", propq); if (ctx == NULL) goto err; if (EVP_PKEY_fromdata_init(ctx) <= 0) { ERR_raise(ERR_LIB_EVP, EVP_R_KEY_SETUP_FAILED); goto err; } *p++ = OSSL_PARAM_construct_octet_string(OSSL_PKEY_PARAM_PRIV_KEY, (void *)priv, len); *p++ = OSSL_PARAM_construct_utf8_string(OSSL_PKEY_PARAM_CIPHER, (char *)cipher_name, 0); if (propq != NULL) *p++ = OSSL_PARAM_construct_utf8_string(OSSL_PKEY_PARAM_PROPERTIES, (char *)propq, 0); # ifndef OPENSSL_NO_ENGINE if (engine_id != NULL) *p++ = OSSL_PARAM_construct_utf8_string(OSSL_PKEY_PARAM_ENGINE, (char *)engine_id, 0); # endif *p = OSSL_PARAM_construct_end(); if (EVP_PKEY_fromdata(ctx, &pkey, EVP_PKEY_KEYPAIR, params) <= 0) { ERR_raise(ERR_LIB_EVP, EVP_R_KEY_SETUP_FAILED); goto err; } err: EVP_PKEY_CTX_free(ctx); return pkey; # else ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); return NULL; # endif } EVP_PKEY *EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv, size_t len, const EVP_CIPHER *cipher) { return new_cmac_key_int(priv, len, NULL, cipher, NULL, NULL, e); } int EVP_PKEY_set_type(EVP_PKEY *pkey, int type) { return pkey_set_type(pkey, NULL, type, NULL, -1, NULL); } int EVP_PKEY_set_type_str(EVP_PKEY *pkey, const char *str, int len) { return pkey_set_type(pkey, NULL, EVP_PKEY_NONE, str, len, NULL); } # ifndef OPENSSL_NO_ENGINE int EVP_PKEY_set1_engine(EVP_PKEY *pkey, ENGINE *e) { if (e != NULL) { if (!ENGINE_init(e)) { ERR_raise(ERR_LIB_EVP, ERR_R_ENGINE_LIB); return 0; } if (ENGINE_get_pkey_meth(e, pkey->type) == NULL) { ENGINE_finish(e); ERR_raise(ERR_LIB_EVP, EVP_R_UNSUPPORTED_ALGORITHM); return 0; } } ENGINE_finish(pkey->pmeth_engine); pkey->pmeth_engine = e; return 1; } ENGINE *EVP_PKEY_get0_engine(const EVP_PKEY *pkey) { return pkey->engine; } # endif # ifndef OPENSSL_NO_DEPRECATED_3_0 static void detect_foreign_key(EVP_PKEY *pkey) { switch (pkey->type) { case EVP_PKEY_RSA: case EVP_PKEY_RSA_PSS: pkey->foreign = pkey->pkey.rsa != NULL && ossl_rsa_is_foreign(pkey->pkey.rsa); break; # ifndef OPENSSL_NO_EC case EVP_PKEY_SM2: break; case EVP_PKEY_EC: pkey->foreign = pkey->pkey.ec != NULL && ossl_ec_key_is_foreign(pkey->pkey.ec); break; # endif # ifndef OPENSSL_NO_DSA case EVP_PKEY_DSA: pkey->foreign = pkey->pkey.dsa != NULL && ossl_dsa_is_foreign(pkey->pkey.dsa); break; #endif # ifndef OPENSSL_NO_DH case EVP_PKEY_DH: pkey->foreign = pkey->pkey.dh != NULL && ossl_dh_is_foreign(pkey->pkey.dh); break; #endif default: pkey->foreign = 0; break; } } int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key) { # ifndef OPENSSL_NO_EC int pktype; pktype = EVP_PKEY_type(type); if ((key != NULL) && (pktype == EVP_PKEY_EC || pktype == EVP_PKEY_SM2)) { const EC_GROUP *group = EC_KEY_get0_group(key); if (group != NULL) { int curve = EC_GROUP_get_curve_name(group); /* * Regardless of what is requested the SM2 curve must be SM2 type, * and non SM2 curves are EC type. */ if (curve == NID_sm2 && pktype == EVP_PKEY_EC) type = EVP_PKEY_SM2; else if(curve != NID_sm2 && pktype == EVP_PKEY_SM2) type = EVP_PKEY_EC; } } # endif if (pkey == NULL || !EVP_PKEY_set_type(pkey, type)) return 0; pkey->pkey.ptr = key; detect_foreign_key(pkey); return (key != NULL); } # endif void *EVP_PKEY_get0(const EVP_PKEY *pkey) { if (pkey == NULL) return NULL; if (!evp_pkey_is_provided(pkey)) return pkey->pkey.ptr; return NULL; } const unsigned char *EVP_PKEY_get0_hmac(const EVP_PKEY *pkey, size_t *len) { const ASN1_OCTET_STRING *os = NULL; if (pkey->type != EVP_PKEY_HMAC) { ERR_raise(ERR_LIB_EVP, EVP_R_EXPECTING_AN_HMAC_KEY); return NULL; } os = evp_pkey_get_legacy((EVP_PKEY *)pkey); if (os != NULL) { *len = os->length; return os->data; } return NULL; } # ifndef OPENSSL_NO_POLY1305 const unsigned char *EVP_PKEY_get0_poly1305(const EVP_PKEY *pkey, size_t *len) { const ASN1_OCTET_STRING *os = NULL; if (pkey->type != EVP_PKEY_POLY1305) { ERR_raise(ERR_LIB_EVP, EVP_R_EXPECTING_A_POLY1305_KEY); return NULL; } os = evp_pkey_get_legacy((EVP_PKEY *)pkey); if (os != NULL) { *len = os->length; return os->data; } return NULL; } # endif # ifndef OPENSSL_NO_SIPHASH const unsigned char *EVP_PKEY_get0_siphash(const EVP_PKEY *pkey, size_t *len) { const ASN1_OCTET_STRING *os = NULL; if (pkey->type != EVP_PKEY_SIPHASH) { ERR_raise(ERR_LIB_EVP, EVP_R_EXPECTING_A_SIPHASH_KEY); return NULL; } os = evp_pkey_get_legacy((EVP_PKEY *)pkey); if (os != NULL) { *len = os->length; return os->data; } return NULL; } # endif # ifndef OPENSSL_NO_DSA static DSA *evp_pkey_get0_DSA_int(const EVP_PKEY *pkey) { if (pkey->type != EVP_PKEY_DSA) { ERR_raise(ERR_LIB_EVP, EVP_R_EXPECTING_A_DSA_KEY); return NULL; } return evp_pkey_get_legacy((EVP_PKEY *)pkey); } const DSA *EVP_PKEY_get0_DSA(const EVP_PKEY *pkey) { return evp_pkey_get0_DSA_int(pkey); } int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key) { int ret = EVP_PKEY_assign_DSA(pkey, key); if (ret) DSA_up_ref(key); return ret; } DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey) { DSA *ret = evp_pkey_get0_DSA_int(pkey); if (ret != NULL) DSA_up_ref(ret); return ret; } # endif /* OPENSSL_NO_DSA */ # ifndef OPENSSL_NO_EC static const ECX_KEY *evp_pkey_get0_ECX_KEY(const EVP_PKEY *pkey, int type) { if (EVP_PKEY_get_base_id(pkey) != type) { ERR_raise(ERR_LIB_EVP, EVP_R_EXPECTING_A_ECX_KEY); return NULL; } return evp_pkey_get_legacy((EVP_PKEY *)pkey); } static ECX_KEY *evp_pkey_get1_ECX_KEY(EVP_PKEY *pkey, int type) { ECX_KEY *ret = (ECX_KEY *)evp_pkey_get0_ECX_KEY(pkey, type); if (ret != NULL && !ossl_ecx_key_up_ref(ret)) ret = NULL; return ret; } # define IMPLEMENT_ECX_VARIANT(NAME) \ ECX_KEY *ossl_evp_pkey_get1_##NAME(EVP_PKEY *pkey) \ { \ return evp_pkey_get1_ECX_KEY(pkey, EVP_PKEY_##NAME); \ } IMPLEMENT_ECX_VARIANT(X25519) IMPLEMENT_ECX_VARIANT(X448) IMPLEMENT_ECX_VARIANT(ED25519) IMPLEMENT_ECX_VARIANT(ED448) # endif # if !defined(OPENSSL_NO_DH) && !defined(OPENSSL_NO_DEPRECATED_3_0) int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *dhkey) { int ret, type; /* * ossl_dh_is_named_safe_prime_group() returns 1 for named safe prime groups * related to ffdhe and modp (which cache q = (p - 1) / 2), * and returns 0 for all other dh parameter generation types including * RFC5114 named groups. * * The EVP_PKEY_DH type is used for dh parameter generation types: * - named safe prime groups related to ffdhe and modp * - safe prime generator * * The type EVP_PKEY_DHX is used for dh parameter generation types * - fips186-4 and fips186-2 * - rfc5114 named groups. * * The EVP_PKEY_DH type is used to save PKCS#3 data than can be stored * without a q value. * The EVP_PKEY_DHX type is used to save X9.42 data that requires the * q value to be stored. */ if (ossl_dh_is_named_safe_prime_group(dhkey)) type = EVP_PKEY_DH; else type = DH_get0_q(dhkey) == NULL ? EVP_PKEY_DH : EVP_PKEY_DHX; ret = EVP_PKEY_assign(pkey, type, dhkey); if (ret) DH_up_ref(dhkey); return ret; } DH *evp_pkey_get0_DH_int(const EVP_PKEY *pkey) { if (pkey->type != EVP_PKEY_DH && pkey->type != EVP_PKEY_DHX) { ERR_raise(ERR_LIB_EVP, EVP_R_EXPECTING_A_DH_KEY); return NULL; } return evp_pkey_get_legacy((EVP_PKEY *)pkey); } const DH *EVP_PKEY_get0_DH(const EVP_PKEY *pkey) { return evp_pkey_get0_DH_int(pkey); } DH *EVP_PKEY_get1_DH(EVP_PKEY *pkey) { DH *ret = evp_pkey_get0_DH_int(pkey); if (ret != NULL) DH_up_ref(ret); return ret; } # endif int EVP_PKEY_type(int type) { int ret; const EVP_PKEY_ASN1_METHOD *ameth; ENGINE *e; ameth = EVP_PKEY_asn1_find(&e, type); if (ameth) ret = ameth->pkey_id; else ret = NID_undef; # ifndef OPENSSL_NO_ENGINE ENGINE_finish(e); # endif return ret; } int EVP_PKEY_get_id(const EVP_PKEY *pkey) { return pkey->type; } int EVP_PKEY_get_base_id(const EVP_PKEY *pkey) { return EVP_PKEY_type(pkey->type); } /* * These hard coded cases are pure hackery to get around the fact * that names in crypto/objects/objects.txt are a mess. There is * no "EC", and "RSA" leads to the NID for 2.5.8.1.1, an OID that's * fallen out in favor of { pkcs-1 1 }, i.e. 1.2.840.113549.1.1.1, * the NID of which is used for EVP_PKEY_RSA. Strangely enough, * "DSA" is accurate... but still, better be safe and hard-code * names that we know. * On a similar topic, EVP_PKEY_type(EVP_PKEY_SM2) will result in * EVP_PKEY_EC, because of aliasing. * This should be cleaned away along with all other #legacy support. */ static const OSSL_ITEM standard_name2type[] = { { EVP_PKEY_RSA, "RSA" }, { EVP_PKEY_RSA_PSS, "RSA-PSS" }, { EVP_PKEY_EC, "EC" }, { EVP_PKEY_ED25519, "ED25519" }, { EVP_PKEY_ED448, "ED448" }, { EVP_PKEY_X25519, "X25519" }, { EVP_PKEY_X448, "X448" }, { EVP_PKEY_SM2, "SM2" }, { EVP_PKEY_DH, "DH" }, { EVP_PKEY_DHX, "X9.42 DH" }, { EVP_PKEY_DHX, "DHX" }, { EVP_PKEY_DSA, "DSA" }, }; int evp_pkey_name2type(const char *name) { int type; size_t i; for (i = 0; i < OSSL_NELEM(standard_name2type); i++) { if (OPENSSL_strcasecmp(name, standard_name2type[i].ptr) == 0) return (int)standard_name2type[i].id; } if ((type = EVP_PKEY_type(OBJ_sn2nid(name))) != NID_undef) return type; return EVP_PKEY_type(OBJ_ln2nid(name)); } const char *evp_pkey_type2name(int type) { size_t i; for (i = 0; i < OSSL_NELEM(standard_name2type); i++) { if (type == (int)standard_name2type[i].id) return standard_name2type[i].ptr; } return OBJ_nid2sn(type); } int EVP_PKEY_is_a(const EVP_PKEY *pkey, const char *name) { if (pkey == NULL) return 0; if (pkey->keymgmt == NULL) return pkey->type == evp_pkey_name2type(name); return EVP_KEYMGMT_is_a(pkey->keymgmt, name); } int EVP_PKEY_type_names_do_all(const EVP_PKEY *pkey, void (*fn)(const char *name, void *data), void *data) { if (!evp_pkey_is_typed(pkey)) return 0; if (!evp_pkey_is_provided(pkey)) { const char *name = OBJ_nid2sn(EVP_PKEY_get_id(pkey)); fn(name, data); return 1; } return EVP_KEYMGMT_names_do_all(pkey->keymgmt, fn, data); } int EVP_PKEY_can_sign(const EVP_PKEY *pkey) { if (pkey->keymgmt == NULL) { switch (EVP_PKEY_get_base_id(pkey)) { case EVP_PKEY_RSA: case EVP_PKEY_RSA_PSS: return 1; # ifndef OPENSSL_NO_DSA case EVP_PKEY_DSA: return 1; # endif # ifndef OPENSSL_NO_EC case EVP_PKEY_ED25519: case EVP_PKEY_ED448: return 1; case EVP_PKEY_EC: /* Including SM2 */ return EC_KEY_can_sign(pkey->pkey.ec); # endif default: break; } } else { const OSSL_PROVIDER *prov = EVP_KEYMGMT_get0_provider(pkey->keymgmt); OSSL_LIB_CTX *libctx = ossl_provider_libctx(prov); const char *supported_sig = pkey->keymgmt->query_operation_name != NULL ? pkey->keymgmt->query_operation_name(OSSL_OP_SIGNATURE) : EVP_KEYMGMT_get0_name(pkey->keymgmt); EVP_SIGNATURE *signature = NULL; signature = EVP_SIGNATURE_fetch(libctx, supported_sig, NULL); if (signature != NULL) { EVP_SIGNATURE_free(signature); return 1; } } return 0; } static int print_reset_indent(BIO **out, int pop_f_prefix, long saved_indent) { BIO_set_indent(*out, saved_indent); if (pop_f_prefix) { BIO *next = BIO_pop(*out); BIO_free(*out); *out = next; } return 1; } static int print_set_indent(BIO **out, int *pop_f_prefix, long *saved_indent, long indent) { *pop_f_prefix = 0; *saved_indent = 0; if (indent > 0) { long i = BIO_get_indent(*out); *saved_indent = (i < 0 ? 0 : i); if (BIO_set_indent(*out, indent) <= 0) { BIO *prefbio = BIO_new(BIO_f_prefix()); if (prefbio == NULL) return 0; *out = BIO_push(prefbio, *out); *pop_f_prefix = 1; } if (BIO_set_indent(*out, indent) <= 0) { print_reset_indent(out, *pop_f_prefix, *saved_indent); return 0; } } return 1; } static int unsup_alg(BIO *out, const EVP_PKEY *pkey, int indent, const char *kstr) { return BIO_indent(out, indent, 128) && BIO_printf(out, "%s algorithm \"%s\" unsupported\n", kstr, OBJ_nid2ln(pkey->type)) > 0; } static int print_pkey(const EVP_PKEY *pkey, BIO *out, int indent, int selection /* For provided encoding */, const char *propquery /* For provided encoding */, int (*legacy_print)(BIO *out, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx), ASN1_PCTX *legacy_pctx /* For legacy print */) { int pop_f_prefix; long saved_indent; OSSL_ENCODER_CTX *ctx = NULL; int ret = -2; /* default to unsupported */ if (!print_set_indent(&out, &pop_f_prefix, &saved_indent, indent)) return 0; ctx = OSSL_ENCODER_CTX_new_for_pkey(pkey, selection, "TEXT", NULL, propquery); if (OSSL_ENCODER_CTX_get_num_encoders(ctx) != 0) ret = OSSL_ENCODER_to_bio(ctx, out); OSSL_ENCODER_CTX_free(ctx); if (ret != -2) goto end; /* legacy fallback */ if (legacy_print != NULL) ret = legacy_print(out, pkey, 0, legacy_pctx); else ret = unsup_alg(out, pkey, 0, "Public Key"); end: print_reset_indent(&out, pop_f_prefix, saved_indent); return ret; } int EVP_PKEY_print_public(BIO *out, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx) { return print_pkey(pkey, out, indent, EVP_PKEY_PUBLIC_KEY, NULL, (pkey->ameth != NULL ? pkey->ameth->pub_print : NULL), pctx); } int EVP_PKEY_print_private(BIO *out, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx) { - return print_pkey(pkey, out, indent, EVP_PKEY_KEYPAIR, NULL, + return print_pkey(pkey, out, indent, EVP_PKEY_PRIVATE_KEY, NULL, (pkey->ameth != NULL ? pkey->ameth->priv_print : NULL), pctx); } int EVP_PKEY_print_params(BIO *out, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx) { return print_pkey(pkey, out, indent, EVP_PKEY_KEY_PARAMETERS, NULL, (pkey->ameth != NULL ? pkey->ameth->param_print : NULL), pctx); } # ifndef OPENSSL_NO_STDIO int EVP_PKEY_print_public_fp(FILE *fp, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx) { int ret; BIO *b = BIO_new_fp(fp, BIO_NOCLOSE); if (b == NULL) return 0; ret = EVP_PKEY_print_public(b, pkey, indent, pctx); BIO_free(b); return ret; } int EVP_PKEY_print_private_fp(FILE *fp, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx) { int ret; BIO *b = BIO_new_fp(fp, BIO_NOCLOSE); if (b == NULL) return 0; ret = EVP_PKEY_print_private(b, pkey, indent, pctx); BIO_free(b); return ret; } int EVP_PKEY_print_params_fp(FILE *fp, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx) { int ret; BIO *b = BIO_new_fp(fp, BIO_NOCLOSE); if (b == NULL) return 0; ret = EVP_PKEY_print_params(b, pkey, indent, pctx); BIO_free(b); return ret; } # endif static void mdname2nid(const char *mdname, void *data) { int *nid = (int *)data; if (*nid != NID_undef) return; *nid = OBJ_sn2nid(mdname); if (*nid == NID_undef) *nid = OBJ_ln2nid(mdname); } static int legacy_asn1_ctrl_to_param(EVP_PKEY *pkey, int op, int arg1, void *arg2) { if (pkey->keymgmt == NULL) return 0; switch (op) { case ASN1_PKEY_CTRL_DEFAULT_MD_NID: { char mdname[80] = ""; int rv = EVP_PKEY_get_default_digest_name(pkey, mdname, sizeof(mdname)); if (rv > 0) { int mdnum; OSSL_LIB_CTX *libctx = ossl_provider_libctx(pkey->keymgmt->prov); /* Make sure the MD is in the namemap if available */ EVP_MD *md; OSSL_NAMEMAP *namemap; int nid = NID_undef; (void)ERR_set_mark(); md = EVP_MD_fetch(libctx, mdname, NULL); (void)ERR_pop_to_mark(); namemap = ossl_namemap_stored(libctx); /* * The only reason to fetch the MD was to make sure it is in the * namemap. We can immediately free it. */ EVP_MD_free(md); mdnum = ossl_namemap_name2num(namemap, mdname); if (mdnum == 0) return 0; /* * We have the namemap number - now we need to find the * associated nid */ if (!ossl_namemap_doall_names(namemap, mdnum, mdname2nid, &nid)) return 0; *(int *)arg2 = nid; } return rv; } default: return -2; } } static int evp_pkey_asn1_ctrl(EVP_PKEY *pkey, int op, int arg1, void *arg2) { if (pkey->ameth == NULL) return legacy_asn1_ctrl_to_param(pkey, op, arg1, arg2); if (pkey->ameth->pkey_ctrl == NULL) return -2; return pkey->ameth->pkey_ctrl(pkey, op, arg1, arg2); } int EVP_PKEY_get_default_digest_nid(EVP_PKEY *pkey, int *pnid) { if (pkey == NULL) return 0; return evp_pkey_asn1_ctrl(pkey, ASN1_PKEY_CTRL_DEFAULT_MD_NID, 0, pnid); } int EVP_PKEY_get_default_digest_name(EVP_PKEY *pkey, char *mdname, size_t mdname_sz) { if (pkey->ameth == NULL) return evp_keymgmt_util_get_deflt_digest_name(pkey->keymgmt, pkey->keydata, mdname, mdname_sz); { int nid = NID_undef; int rv = EVP_PKEY_get_default_digest_nid(pkey, &nid); const char *name = rv > 0 ? OBJ_nid2sn(nid) : NULL; if (rv > 0) OPENSSL_strlcpy(mdname, name, mdname_sz); return rv; } } int EVP_PKEY_get_group_name(const EVP_PKEY *pkey, char *gname, size_t gname_sz, size_t *gname_len) { return EVP_PKEY_get_utf8_string_param(pkey, OSSL_PKEY_PARAM_GROUP_NAME, gname, gname_sz, gname_len); } int EVP_PKEY_digestsign_supports_digest(EVP_PKEY *pkey, OSSL_LIB_CTX *libctx, const char *name, const char *propq) { int rv; EVP_MD_CTX *ctx = NULL; if ((ctx = EVP_MD_CTX_new()) == NULL) return -1; ERR_set_mark(); rv = EVP_DigestSignInit_ex(ctx, NULL, name, libctx, propq, pkey, NULL); ERR_pop_to_mark(); EVP_MD_CTX_free(ctx); return rv; } int EVP_PKEY_set1_encoded_public_key(EVP_PKEY *pkey, const unsigned char *pub, size_t publen) { if (pkey == NULL) return 0; if (evp_pkey_is_provided(pkey)) return EVP_PKEY_set_octet_string_param(pkey, OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY, (unsigned char *)pub, publen); if (publen > INT_MAX) return 0; /* Historically this function was EVP_PKEY_set1_tls_encodedpoint */ if (evp_pkey_asn1_ctrl(pkey, ASN1_PKEY_CTRL_SET1_TLS_ENCPT, publen, (void *)pub) <= 0) return 0; return 1; } size_t EVP_PKEY_get1_encoded_public_key(EVP_PKEY *pkey, unsigned char **ppub) { int rv; if (pkey == NULL) return 0; if (evp_pkey_is_provided(pkey)) { size_t return_size = OSSL_PARAM_UNMODIFIED; unsigned char *buf; /* * We know that this is going to fail, but it will give us a size * to allocate. */ EVP_PKEY_get_octet_string_param(pkey, OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY, NULL, 0, &return_size); if (return_size == OSSL_PARAM_UNMODIFIED) return 0; *ppub = NULL; buf = OPENSSL_malloc(return_size); if (buf == NULL) return 0; if (!EVP_PKEY_get_octet_string_param(pkey, OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY, buf, return_size, NULL)) { OPENSSL_free(buf); return 0; } *ppub = buf; return return_size; } rv = evp_pkey_asn1_ctrl(pkey, ASN1_PKEY_CTRL_GET1_TLS_ENCPT, 0, ppub); if (rv <= 0) return 0; return rv; } #endif /* FIPS_MODULE */ /*- All methods below can also be used in FIPS_MODULE */ EVP_PKEY *EVP_PKEY_new(void) { EVP_PKEY *ret = OPENSSL_zalloc(sizeof(*ret)); if (ret == NULL) { ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE); return NULL; } ret->type = EVP_PKEY_NONE; ret->save_type = EVP_PKEY_NONE; ret->references = 1; ret->lock = CRYPTO_THREAD_lock_new(); if (ret->lock == NULL) { EVPerr(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE); goto err; } #ifndef FIPS_MODULE ret->save_parameters = 1; if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_EVP_PKEY, ret, &ret->ex_data)) { ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE); goto err; } #endif return ret; err: CRYPTO_THREAD_lock_free(ret->lock); OPENSSL_free(ret); return NULL; } /* * Setup a public key management method. * * For legacy keys, either |type| or |str| is expected to have the type * information. In this case, the setup consists of finding an ASN1 method * and potentially an ENGINE, and setting those fields in |pkey|. * * For provider side keys, |keymgmt| is expected to be non-NULL. In this * case, the setup consists of setting the |keymgmt| field in |pkey|. * * If pkey is NULL just return 1 or 0 if the key management method exists. */ static int pkey_set_type(EVP_PKEY *pkey, ENGINE *e, int type, const char *str, int len, EVP_KEYMGMT *keymgmt) { #ifndef FIPS_MODULE const EVP_PKEY_ASN1_METHOD *ameth = NULL; ENGINE **eptr = (e == NULL) ? &e : NULL; #endif /* * The setups can't set both legacy and provider side methods. * It is forbidden */ if (!ossl_assert(type == EVP_PKEY_NONE || keymgmt == NULL) || !ossl_assert(e == NULL || keymgmt == NULL)) { ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR); return 0; } if (pkey != NULL) { int free_it = 0; #ifndef FIPS_MODULE free_it = free_it || pkey->pkey.ptr != NULL; #endif free_it = free_it || pkey->keydata != NULL; if (free_it) evp_pkey_free_it(pkey); #ifndef FIPS_MODULE /* * If key type matches and a method exists then this lookup has * succeeded once so just indicate success. */ if (pkey->type != EVP_PKEY_NONE && type == pkey->save_type && pkey->ameth != NULL) return 1; # ifndef OPENSSL_NO_ENGINE /* If we have ENGINEs release them */ ENGINE_finish(pkey->engine); pkey->engine = NULL; ENGINE_finish(pkey->pmeth_engine); pkey->pmeth_engine = NULL; # endif #endif } #ifndef FIPS_MODULE if (str != NULL) ameth = EVP_PKEY_asn1_find_str(eptr, str, len); else if (type != EVP_PKEY_NONE) ameth = EVP_PKEY_asn1_find(eptr, type); # ifndef OPENSSL_NO_ENGINE if (pkey == NULL && eptr != NULL) ENGINE_finish(e); # endif #endif { int check = 1; #ifndef FIPS_MODULE check = check && ameth == NULL; #endif check = check && keymgmt == NULL; if (check) { ERR_raise(ERR_LIB_EVP, EVP_R_UNSUPPORTED_ALGORITHM); return 0; } } if (pkey != NULL) { if (keymgmt != NULL && !EVP_KEYMGMT_up_ref(keymgmt)) { ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR); return 0; } pkey->keymgmt = keymgmt; pkey->save_type = type; pkey->type = type; #ifndef FIPS_MODULE /* * If the internal "origin" key is provider side, don't save |ameth|. * The main reason is that |ameth| is one factor to detect that the * internal "origin" key is a legacy one. */ if (keymgmt == NULL) pkey->ameth = ameth; /* * The EVP_PKEY_ASN1_METHOD |pkey_id| retains its legacy key purpose * for any key type that has a legacy implementation, regardless of * if the internal key is a legacy or a provider side one. When * there is no legacy implementation for the key, the type becomes * EVP_PKEY_KEYMGMT, which indicates that one should be cautious * with functions that expect legacy internal keys. */ if (ameth != NULL) { if (type == EVP_PKEY_NONE) pkey->type = ameth->pkey_id; } else { pkey->type = EVP_PKEY_KEYMGMT; } # ifndef OPENSSL_NO_ENGINE if (eptr == NULL && e != NULL && !ENGINE_init(e)) { ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR); return 0; } # endif pkey->engine = e; #endif } return 1; } #ifndef FIPS_MODULE static void find_ameth(const char *name, void *data) { const char **str = data; /* * The error messages from pkey_set_type() are uninteresting here, * and misleading. */ ERR_set_mark(); if (pkey_set_type(NULL, NULL, EVP_PKEY_NONE, name, strlen(name), NULL)) { if (str[0] == NULL) str[0] = name; else if (str[1] == NULL) str[1] = name; } ERR_pop_to_mark(); } #endif int EVP_PKEY_set_type_by_keymgmt(EVP_PKEY *pkey, EVP_KEYMGMT *keymgmt) { #ifndef FIPS_MODULE # define EVP_PKEY_TYPE_STR str[0] # define EVP_PKEY_TYPE_STRLEN (str[0] == NULL ? -1 : (int)strlen(str[0])) /* * Find at most two strings that have an associated EVP_PKEY_ASN1_METHOD * Ideally, only one should be found. If two (or more) are found, the * match is ambiguous. This should never happen, but... */ const char *str[2] = { NULL, NULL }; if (!EVP_KEYMGMT_names_do_all(keymgmt, find_ameth, &str) || str[1] != NULL) { ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR); return 0; } #else # define EVP_PKEY_TYPE_STR NULL # define EVP_PKEY_TYPE_STRLEN -1 #endif return pkey_set_type(pkey, NULL, EVP_PKEY_NONE, EVP_PKEY_TYPE_STR, EVP_PKEY_TYPE_STRLEN, keymgmt); #undef EVP_PKEY_TYPE_STR #undef EVP_PKEY_TYPE_STRLEN } int EVP_PKEY_up_ref(EVP_PKEY *pkey) { int i; if (CRYPTO_UP_REF(&pkey->references, &i, pkey->lock) <= 0) return 0; REF_PRINT_COUNT("EVP_PKEY", pkey); REF_ASSERT_ISNT(i < 2); return ((i > 1) ? 1 : 0); } #ifndef FIPS_MODULE EVP_PKEY *EVP_PKEY_dup(EVP_PKEY *pkey) { EVP_PKEY *dup_pk; if (pkey == NULL) { ERR_raise(ERR_LIB_EVP, ERR_R_PASSED_NULL_PARAMETER); return NULL; } if ((dup_pk = EVP_PKEY_new()) == NULL) return NULL; if (evp_pkey_is_blank(pkey)) goto done; if (evp_pkey_is_provided(pkey)) { if (!evp_keymgmt_util_copy(dup_pk, pkey, OSSL_KEYMGMT_SELECT_ALL)) goto err; goto done; } if (evp_pkey_is_legacy(pkey)) { const EVP_PKEY_ASN1_METHOD *ameth = pkey->ameth; if (ameth == NULL || ameth->copy == NULL) { if (pkey->pkey.ptr == NULL /* empty key, just set type */ && EVP_PKEY_set_type(dup_pk, pkey->type) != 0) goto done; ERR_raise(ERR_LIB_EVP, EVP_R_UNSUPPORTED_KEY_TYPE); goto err; } if (!ameth->copy(dup_pk, pkey)) goto err; goto done; } goto err; done: /* copy auxiliary data */ if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_EVP_PKEY, &dup_pk->ex_data, &pkey->ex_data)) goto err; if (pkey->attributes != NULL) { if ((dup_pk->attributes = ossl_x509at_dup(pkey->attributes)) == NULL) goto err; } return dup_pk; err: EVP_PKEY_free(dup_pk); return NULL; } void evp_pkey_free_legacy(EVP_PKEY *x) { const EVP_PKEY_ASN1_METHOD *ameth = x->ameth; ENGINE *tmpe = NULL; if (ameth == NULL && x->legacy_cache_pkey.ptr != NULL) ameth = EVP_PKEY_asn1_find(&tmpe, x->type); if (ameth != NULL) { if (x->legacy_cache_pkey.ptr != NULL) { /* * We should never have both a legacy origin key, and a key in the * legacy cache. */ assert(x->pkey.ptr == NULL); /* * For the purposes of freeing we make the legacy cache look like * a legacy origin key. */ x->pkey = x->legacy_cache_pkey; x->legacy_cache_pkey.ptr = NULL; } if (ameth->pkey_free != NULL) ameth->pkey_free(x); x->pkey.ptr = NULL; } # ifndef OPENSSL_NO_ENGINE ENGINE_finish(tmpe); ENGINE_finish(x->engine); x->engine = NULL; ENGINE_finish(x->pmeth_engine); x->pmeth_engine = NULL; # endif } #endif /* FIPS_MODULE */ static void evp_pkey_free_it(EVP_PKEY *x) { /* internal function; x is never NULL */ evp_keymgmt_util_clear_operation_cache(x, 1); #ifndef FIPS_MODULE evp_pkey_free_legacy(x); #endif if (x->keymgmt != NULL) { evp_keymgmt_freedata(x->keymgmt, x->keydata); EVP_KEYMGMT_free(x->keymgmt); x->keymgmt = NULL; x->keydata = NULL; } x->type = EVP_PKEY_NONE; } void EVP_PKEY_free(EVP_PKEY *x) { int i; if (x == NULL) return; CRYPTO_DOWN_REF(&x->references, &i, x->lock); REF_PRINT_COUNT("EVP_PKEY", x); if (i > 0) return; REF_ASSERT_ISNT(i < 0); evp_pkey_free_it(x); #ifndef FIPS_MODULE CRYPTO_free_ex_data(CRYPTO_EX_INDEX_EVP_PKEY, x, &x->ex_data); #endif CRYPTO_THREAD_lock_free(x->lock); #ifndef FIPS_MODULE sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free); #endif OPENSSL_free(x); } int EVP_PKEY_get_size(const EVP_PKEY *pkey) { int size = 0; if (pkey != NULL) { size = pkey->cache.size; #ifndef FIPS_MODULE if (pkey->ameth != NULL && pkey->ameth->pkey_size != NULL) size = pkey->ameth->pkey_size(pkey); #endif } return size < 0 ? 0 : size; } const char *EVP_PKEY_get0_description(const EVP_PKEY *pkey) { if (!evp_pkey_is_assigned(pkey)) return NULL; if (evp_pkey_is_provided(pkey) && pkey->keymgmt->description != NULL) return pkey->keymgmt->description; #ifndef FIPS_MODULE if (pkey->ameth != NULL) return pkey->ameth->info; #endif return NULL; } void *evp_pkey_export_to_provider(EVP_PKEY *pk, OSSL_LIB_CTX *libctx, EVP_KEYMGMT **keymgmt, const char *propquery) { EVP_KEYMGMT *allocated_keymgmt = NULL; EVP_KEYMGMT *tmp_keymgmt = NULL; int selection = OSSL_KEYMGMT_SELECT_ALL; void *keydata = NULL; int check; if (pk == NULL) return NULL; /* No key data => nothing to export */ check = 1; #ifndef FIPS_MODULE check = check && pk->pkey.ptr == NULL; #endif check = check && pk->keydata == NULL; if (check) return NULL; #ifndef FIPS_MODULE if (pk->pkey.ptr != NULL) { /* * If the legacy key doesn't have an dirty counter or export function, * give up */ if (pk->ameth->dirty_cnt == NULL || pk->ameth->export_to == NULL) return NULL; } #endif if (keymgmt != NULL) { tmp_keymgmt = *keymgmt; *keymgmt = NULL; } /* * If no keymgmt was given or found, get a default keymgmt. We do so by * letting EVP_PKEY_CTX_new_from_pkey() do it for us, then we steal it. */ if (tmp_keymgmt == NULL) { EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new_from_pkey(libctx, pk, propquery); if (ctx == NULL) goto end; allocated_keymgmt = tmp_keymgmt = ctx->keymgmt; ctx->keymgmt = NULL; EVP_PKEY_CTX_free(ctx); } /* If there's still no keymgmt to be had, give up */ if (tmp_keymgmt == NULL) goto end; #ifndef FIPS_MODULE if (pk->pkey.ptr != NULL) { OP_CACHE_ELEM *op; /* * If the legacy "origin" hasn't changed since last time, we try * to find our keymgmt in the operation cache. If it has changed, * |i| remains zero, and we will clear the cache further down. */ if (pk->ameth->dirty_cnt(pk) == pk->dirty_cnt_copy) { if (!CRYPTO_THREAD_read_lock(pk->lock)) goto end; op = evp_keymgmt_util_find_operation_cache(pk, tmp_keymgmt, selection); /* * If |tmp_keymgmt| is present in the operation cache, it means * that export doesn't need to be redone. In that case, we take * token copies of the cached pointers, to have token success * values to return. */ if (op != NULL && op->keymgmt != NULL) { keydata = op->keydata; CRYPTO_THREAD_unlock(pk->lock); goto end; } CRYPTO_THREAD_unlock(pk->lock); } /* Make sure that the keymgmt key type matches the legacy NID */ if (!EVP_KEYMGMT_is_a(tmp_keymgmt, OBJ_nid2sn(pk->type))) goto end; if ((keydata = evp_keymgmt_newdata(tmp_keymgmt)) == NULL) goto end; if (!pk->ameth->export_to(pk, keydata, tmp_keymgmt->import, libctx, propquery)) { evp_keymgmt_freedata(tmp_keymgmt, keydata); keydata = NULL; goto end; } /* * If the dirty counter changed since last time, then clear the * operation cache. In that case, we know that |i| is zero. Just * in case this is a re-export, we increment then decrement the * keymgmt reference counter. */ if (!EVP_KEYMGMT_up_ref(tmp_keymgmt)) { /* refcnt++ */ evp_keymgmt_freedata(tmp_keymgmt, keydata); keydata = NULL; goto end; } if (!CRYPTO_THREAD_write_lock(pk->lock)) goto end; if (pk->ameth->dirty_cnt(pk) != pk->dirty_cnt_copy && !evp_keymgmt_util_clear_operation_cache(pk, 0)) { CRYPTO_THREAD_unlock(pk->lock); evp_keymgmt_freedata(tmp_keymgmt, keydata); keydata = NULL; EVP_KEYMGMT_free(tmp_keymgmt); goto end; } EVP_KEYMGMT_free(tmp_keymgmt); /* refcnt-- */ /* Check to make sure some other thread didn't get there first */ op = evp_keymgmt_util_find_operation_cache(pk, tmp_keymgmt, selection); if (op != NULL && op->keymgmt != NULL) { void *tmp_keydata = op->keydata; CRYPTO_THREAD_unlock(pk->lock); evp_keymgmt_freedata(tmp_keymgmt, keydata); keydata = tmp_keydata; goto end; } /* Add the new export to the operation cache */ if (!evp_keymgmt_util_cache_keydata(pk, tmp_keymgmt, keydata, selection)) { CRYPTO_THREAD_unlock(pk->lock); evp_keymgmt_freedata(tmp_keymgmt, keydata); keydata = NULL; goto end; } /* Synchronize the dirty count */ pk->dirty_cnt_copy = pk->ameth->dirty_cnt(pk); CRYPTO_THREAD_unlock(pk->lock); goto end; } #endif /* FIPS_MODULE */ keydata = evp_keymgmt_util_export_to_provider(pk, tmp_keymgmt, selection); end: /* * If nothing was exported, |tmp_keymgmt| might point at a freed * EVP_KEYMGMT, so we clear it to be safe. It shouldn't be useful for * the caller either way in that case. */ if (keydata == NULL) tmp_keymgmt = NULL; if (keymgmt != NULL && tmp_keymgmt != NULL) { *keymgmt = tmp_keymgmt; allocated_keymgmt = NULL; } EVP_KEYMGMT_free(allocated_keymgmt); return keydata; } #ifndef FIPS_MODULE int evp_pkey_copy_downgraded(EVP_PKEY **dest, const EVP_PKEY *src) { EVP_PKEY *allocpkey = NULL; if (!ossl_assert(dest != NULL)) return 0; if (evp_pkey_is_assigned(src) && evp_pkey_is_provided(src)) { EVP_KEYMGMT *keymgmt = src->keymgmt; void *keydata = src->keydata; int type = src->type; const char *keytype = NULL; keytype = EVP_KEYMGMT_get0_name(keymgmt); /* * If the type is EVP_PKEY_NONE, then we have a problem somewhere * else in our code. If it's not one of the well known EVP_PKEY_xxx * values, it should at least be EVP_PKEY_KEYMGMT at this point. * The check is kept as a safety measure. */ if (!ossl_assert(type != EVP_PKEY_NONE)) { ERR_raise_data(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR, "keymgmt key type = %s but legacy type = EVP_PKEY_NONE", keytype); return 0; } /* Prefer the legacy key type name for error reporting */ if (type != EVP_PKEY_KEYMGMT) keytype = OBJ_nid2sn(type); /* Make sure we have a clean slate to copy into */ if (*dest == NULL) { allocpkey = *dest = EVP_PKEY_new(); if (*dest == NULL) { ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE); return 0; } } else { evp_pkey_free_it(*dest); } if (EVP_PKEY_set_type(*dest, type)) { /* If the key is typed but empty, we're done */ if (keydata == NULL) return 1; if ((*dest)->ameth->import_from == NULL) { ERR_raise_data(ERR_LIB_EVP, EVP_R_NO_IMPORT_FUNCTION, "key type = %s", keytype); } else { /* * We perform the export in the same libctx as the keymgmt * that we are using. */ OSSL_LIB_CTX *libctx = ossl_provider_libctx(keymgmt->prov); EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_from_pkey(libctx, *dest, NULL); if (pctx == NULL) ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE); if (pctx != NULL && evp_keymgmt_export(keymgmt, keydata, OSSL_KEYMGMT_SELECT_ALL, (*dest)->ameth->import_from, pctx)) { /* Synchronize the dirty count */ (*dest)->dirty_cnt_copy = (*dest)->ameth->dirty_cnt(*dest); EVP_PKEY_CTX_free(pctx); return 1; } EVP_PKEY_CTX_free(pctx); } ERR_raise_data(ERR_LIB_EVP, EVP_R_KEYMGMT_EXPORT_FAILURE, "key type = %s", keytype); } } if (allocpkey != NULL) { EVP_PKEY_free(allocpkey); *dest = NULL; } return 0; } void *evp_pkey_get_legacy(EVP_PKEY *pk) { EVP_PKEY *tmp_copy = NULL; void *ret = NULL; if (!ossl_assert(pk != NULL)) return NULL; /* * If this isn't an assigned provider side key, we just use any existing * origin legacy key. */ if (!evp_pkey_is_assigned(pk)) return NULL; if (!evp_pkey_is_provided(pk)) return pk->pkey.ptr; if (!CRYPTO_THREAD_read_lock(pk->lock)) return NULL; ret = pk->legacy_cache_pkey.ptr; if (!CRYPTO_THREAD_unlock(pk->lock)) return NULL; if (ret != NULL) return ret; if (!evp_pkey_copy_downgraded(&tmp_copy, pk)) goto err; if (!CRYPTO_THREAD_write_lock(pk->lock)) goto err; /* Check again in case some other thread has updated it in the meantime */ ret = pk->legacy_cache_pkey.ptr; if (ret == NULL) { /* Steal the legacy key reference from the temporary copy */ ret = pk->legacy_cache_pkey.ptr = tmp_copy->pkey.ptr; tmp_copy->pkey.ptr = NULL; } if (!CRYPTO_THREAD_unlock(pk->lock)) { ret = NULL; goto err; } err: EVP_PKEY_free(tmp_copy); return ret; } #endif /* FIPS_MODULE */ int EVP_PKEY_get_bn_param(const EVP_PKEY *pkey, const char *key_name, BIGNUM **bn) { int ret = 0; OSSL_PARAM params[2]; unsigned char buffer[2048]; unsigned char *buf = NULL; size_t buf_sz = 0; if (key_name == NULL || bn == NULL) return 0; memset(buffer, 0, sizeof(buffer)); params[0] = OSSL_PARAM_construct_BN(key_name, buffer, sizeof(buffer)); params[1] = OSSL_PARAM_construct_end(); if (!EVP_PKEY_get_params(pkey, params)) { if (!OSSL_PARAM_modified(params) || params[0].return_size == 0) return 0; buf_sz = params[0].return_size; /* * If it failed because the buffer was too small then allocate the * required buffer size and retry. */ buf = OPENSSL_zalloc(buf_sz); if (buf == NULL) return 0; params[0].data = buf; params[0].data_size = buf_sz; if (!EVP_PKEY_get_params(pkey, params)) goto err; } /* Fail if the param was not found */ if (!OSSL_PARAM_modified(params)) goto err; ret = OSSL_PARAM_get_BN(params, bn); err: if (buf != NULL) { if (OSSL_PARAM_modified(params)) OPENSSL_clear_free(buf, buf_sz); else OPENSSL_free(buf); } else if (OSSL_PARAM_modified(params)) { OPENSSL_cleanse(buffer, params[0].data_size); } return ret; } int EVP_PKEY_get_octet_string_param(const EVP_PKEY *pkey, const char *key_name, unsigned char *buf, size_t max_buf_sz, size_t *out_len) { OSSL_PARAM params[2]; int ret1 = 0, ret2 = 0; if (key_name == NULL) return 0; params[0] = OSSL_PARAM_construct_octet_string(key_name, buf, max_buf_sz); params[1] = OSSL_PARAM_construct_end(); if ((ret1 = EVP_PKEY_get_params(pkey, params))) ret2 = OSSL_PARAM_modified(params); if (ret2 && out_len != NULL) *out_len = params[0].return_size; return ret1 && ret2; } int EVP_PKEY_get_utf8_string_param(const EVP_PKEY *pkey, const char *key_name, char *str, size_t max_buf_sz, size_t *out_len) { OSSL_PARAM params[2]; int ret1 = 0, ret2 = 0; if (key_name == NULL) return 0; params[0] = OSSL_PARAM_construct_utf8_string(key_name, str, max_buf_sz); params[1] = OSSL_PARAM_construct_end(); if ((ret1 = EVP_PKEY_get_params(pkey, params))) ret2 = OSSL_PARAM_modified(params); if (ret2 && out_len != NULL) *out_len = params[0].return_size; if (ret2 && params[0].return_size == max_buf_sz) /* There was no space for a NUL byte */ return 0; /* Add a terminating NUL byte for good measure */ if (ret2 && str != NULL) str[params[0].return_size] = '\0'; return ret1 && ret2; } int EVP_PKEY_get_int_param(const EVP_PKEY *pkey, const char *key_name, int *out) { OSSL_PARAM params[2]; if (key_name == NULL) return 0; params[0] = OSSL_PARAM_construct_int(key_name, out); params[1] = OSSL_PARAM_construct_end(); return EVP_PKEY_get_params(pkey, params) && OSSL_PARAM_modified(params); } int EVP_PKEY_get_size_t_param(const EVP_PKEY *pkey, const char *key_name, size_t *out) { OSSL_PARAM params[2]; if (key_name == NULL) return 0; params[0] = OSSL_PARAM_construct_size_t(key_name, out); params[1] = OSSL_PARAM_construct_end(); return EVP_PKEY_get_params(pkey, params) && OSSL_PARAM_modified(params); } int EVP_PKEY_set_int_param(EVP_PKEY *pkey, const char *key_name, int in) { OSSL_PARAM params[2]; if (key_name == NULL) return 0; params[0] = OSSL_PARAM_construct_int(key_name, &in); params[1] = OSSL_PARAM_construct_end(); return EVP_PKEY_set_params(pkey, params); } int EVP_PKEY_set_size_t_param(EVP_PKEY *pkey, const char *key_name, size_t in) { OSSL_PARAM params[2]; if (key_name == NULL) return 0; params[0] = OSSL_PARAM_construct_size_t(key_name, &in); params[1] = OSSL_PARAM_construct_end(); return EVP_PKEY_set_params(pkey, params); } int EVP_PKEY_set_bn_param(EVP_PKEY *pkey, const char *key_name, const BIGNUM *bn) { OSSL_PARAM params[2]; unsigned char buffer[2048]; int bsize = 0; if (key_name == NULL || bn == NULL || pkey == NULL || !evp_pkey_is_assigned(pkey)) return 0; bsize = BN_num_bytes(bn); if (!ossl_assert(bsize <= (int)sizeof(buffer))) return 0; if (BN_bn2nativepad(bn, buffer, bsize) < 0) return 0; params[0] = OSSL_PARAM_construct_BN(key_name, buffer, bsize); params[1] = OSSL_PARAM_construct_end(); return EVP_PKEY_set_params(pkey, params); } int EVP_PKEY_set_utf8_string_param(EVP_PKEY *pkey, const char *key_name, const char *str) { OSSL_PARAM params[2]; if (key_name == NULL) return 0; params[0] = OSSL_PARAM_construct_utf8_string(key_name, (char *)str, 0); params[1] = OSSL_PARAM_construct_end(); return EVP_PKEY_set_params(pkey, params); } int EVP_PKEY_set_octet_string_param(EVP_PKEY *pkey, const char *key_name, const unsigned char *buf, size_t bsize) { OSSL_PARAM params[2]; if (key_name == NULL) return 0; params[0] = OSSL_PARAM_construct_octet_string(key_name, (unsigned char *)buf, bsize); params[1] = OSSL_PARAM_construct_end(); return EVP_PKEY_set_params(pkey, params); } const OSSL_PARAM *EVP_PKEY_settable_params(const EVP_PKEY *pkey) { return (pkey != NULL && evp_pkey_is_provided(pkey)) ? EVP_KEYMGMT_settable_params(pkey->keymgmt) : NULL; } int EVP_PKEY_set_params(EVP_PKEY *pkey, OSSL_PARAM params[]) { if (pkey != NULL) { if (evp_pkey_is_provided(pkey)) { pkey->dirty_cnt++; return evp_keymgmt_set_params(pkey->keymgmt, pkey->keydata, params); } #ifndef FIPS_MODULE /* * We will hopefully never find the need to set individual data in * EVP_PKEYs with a legacy internal key, but we can't be entirely * sure. This bit of code can be enabled if we find the need. If * not, it can safely be removed when #legacy support is removed. */ # if 0 else if (evp_pkey_is_legacy(pkey)) { return evp_pkey_set_params_to_ctrl(pkey, params); } # endif #endif } ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_KEY); return 0; } const OSSL_PARAM *EVP_PKEY_gettable_params(const EVP_PKEY *pkey) { return (pkey != NULL && evp_pkey_is_provided(pkey)) ? EVP_KEYMGMT_gettable_params(pkey->keymgmt) : NULL; } int EVP_PKEY_get_params(const EVP_PKEY *pkey, OSSL_PARAM params[]) { if (pkey != NULL) { if (evp_pkey_is_provided(pkey)) return evp_keymgmt_get_params(pkey->keymgmt, pkey->keydata, params) > 0; #ifndef FIPS_MODULE else if (evp_pkey_is_legacy(pkey)) return evp_pkey_get_params_to_ctrl(pkey, params) > 0; #endif } ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_KEY); return 0; } #ifndef FIPS_MODULE int EVP_PKEY_get_ec_point_conv_form(const EVP_PKEY *pkey) { char name[80]; size_t name_len; if (pkey == NULL) return 0; if (pkey->keymgmt == NULL || pkey->keydata == NULL) { # ifndef OPENSSL_NO_EC /* Might work through the legacy route */ const EC_KEY *ec = EVP_PKEY_get0_EC_KEY(pkey); if (ec == NULL) return 0; return EC_KEY_get_conv_form(ec); # else return 0; # endif } if (!EVP_PKEY_get_utf8_string_param(pkey, OSSL_PKEY_PARAM_EC_POINT_CONVERSION_FORMAT, name, sizeof(name), &name_len)) return 0; if (strcmp(name, "uncompressed") == 0) return POINT_CONVERSION_UNCOMPRESSED; if (strcmp(name, "compressed") == 0) return POINT_CONVERSION_COMPRESSED; if (strcmp(name, "hybrid") == 0) return POINT_CONVERSION_HYBRID; return 0; } int EVP_PKEY_get_field_type(const EVP_PKEY *pkey) { char fstr[80]; size_t fstrlen; if (pkey == NULL) return 0; if (pkey->keymgmt == NULL || pkey->keydata == NULL) { # ifndef OPENSSL_NO_EC /* Might work through the legacy route */ const EC_KEY *ec = EVP_PKEY_get0_EC_KEY(pkey); const EC_GROUP *grp; if (ec == NULL) return 0; grp = EC_KEY_get0_group(ec); if (grp == NULL) return 0; return EC_GROUP_get_field_type(grp); # else return 0; # endif } if (!EVP_PKEY_get_utf8_string_param(pkey, OSSL_PKEY_PARAM_EC_FIELD_TYPE, fstr, sizeof(fstr), &fstrlen)) return 0; if (strcmp(fstr, SN_X9_62_prime_field) == 0) return NID_X9_62_prime_field; else if (strcmp(fstr, SN_X9_62_characteristic_two_field)) return NID_X9_62_characteristic_two_field; return 0; } #endif diff --git a/crypto/openssl/crypto/evp/pmeth_lib.c b/crypto/openssl/crypto/evp/pmeth_lib.c index ce6e1a1ccbd5..ba1971ce461d 100644 --- a/crypto/openssl/crypto/evp/pmeth_lib.c +++ b/crypto/openssl/crypto/evp/pmeth_lib.c @@ -1,2068 +1,2069 @@ /* * Copyright 2006-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ /* * Low level key APIs (DH etc) are deprecated for public use, but still ok for * internal use. */ #include "internal/deprecated.h" #include #include #ifndef FIPS_MODULE # include #endif #include #include #include #include #include #include "internal/cryptlib.h" #ifndef FIPS_MODULE # include "crypto/asn1.h" #endif #include "crypto/evp.h" #include "crypto/dh.h" #include "crypto/ec.h" #include "internal/ffc.h" #include "internal/numbers.h" #include "internal/provider.h" #include "evp_local.h" #ifndef FIPS_MODULE static int evp_pkey_ctx_store_cached_data(EVP_PKEY_CTX *ctx, int keytype, int optype, int cmd, const char *name, const void *data, size_t data_len); static void evp_pkey_ctx_free_cached_data(EVP_PKEY_CTX *ctx, int cmd, const char *name); static void evp_pkey_ctx_free_all_cached_data(EVP_PKEY_CTX *ctx); typedef const EVP_PKEY_METHOD *(*pmeth_fn)(void); typedef int sk_cmp_fn_type(const char *const *a, const char *const *b); static STACK_OF(EVP_PKEY_METHOD) *app_pkey_methods = NULL; /* This array needs to be in order of NIDs */ static pmeth_fn standard_methods[] = { ossl_rsa_pkey_method, # ifndef OPENSSL_NO_DH ossl_dh_pkey_method, # endif # ifndef OPENSSL_NO_DSA ossl_dsa_pkey_method, # endif # ifndef OPENSSL_NO_EC ossl_ec_pkey_method, # endif ossl_rsa_pss_pkey_method, # ifndef OPENSSL_NO_DH ossl_dhx_pkey_method, # endif # ifndef OPENSSL_NO_EC ossl_ecx25519_pkey_method, ossl_ecx448_pkey_method, # endif # ifndef OPENSSL_NO_EC ossl_ed25519_pkey_method, ossl_ed448_pkey_method, # endif }; DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, pmeth_fn, pmeth_func); static int pmeth_func_cmp(const EVP_PKEY_METHOD *const *a, pmeth_fn const *b) { return ((*a)->pkey_id - ((**b)())->pkey_id); } IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, pmeth_fn, pmeth_func); static int pmeth_cmp(const EVP_PKEY_METHOD *const *a, const EVP_PKEY_METHOD *const *b) { return ((*a)->pkey_id - (*b)->pkey_id); } static const EVP_PKEY_METHOD *evp_pkey_meth_find_added_by_application(int type) { if (app_pkey_methods != NULL) { int idx; EVP_PKEY_METHOD tmp; tmp.pkey_id = type; idx = sk_EVP_PKEY_METHOD_find(app_pkey_methods, &tmp); if (idx >= 0) return sk_EVP_PKEY_METHOD_value(app_pkey_methods, idx); } return NULL; } const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type) { pmeth_fn *ret; EVP_PKEY_METHOD tmp; const EVP_PKEY_METHOD *t; if ((t = evp_pkey_meth_find_added_by_application(type)) != NULL) return t; tmp.pkey_id = type; t = &tmp; ret = OBJ_bsearch_pmeth_func(&t, standard_methods, OSSL_NELEM(standard_methods)); if (ret == NULL || *ret == NULL) return NULL; return (**ret)(); } EVP_PKEY_METHOD *EVP_PKEY_meth_new(int id, int flags) { EVP_PKEY_METHOD *pmeth; pmeth = OPENSSL_zalloc(sizeof(*pmeth)); if (pmeth == NULL) { ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE); return NULL; } pmeth->pkey_id = id; pmeth->flags = flags | EVP_PKEY_FLAG_DYNAMIC; return pmeth; } static void help_get_legacy_alg_type_from_keymgmt(const char *keytype, void *arg) { int *type = arg; if (*type == NID_undef) *type = evp_pkey_name2type(keytype); } static int get_legacy_alg_type_from_keymgmt(const EVP_KEYMGMT *keymgmt) { int type = NID_undef; EVP_KEYMGMT_names_do_all(keymgmt, help_get_legacy_alg_type_from_keymgmt, &type); return type; } #endif /* FIPS_MODULE */ int evp_pkey_ctx_state(const EVP_PKEY_CTX *ctx) { if (ctx->operation == EVP_PKEY_OP_UNDEFINED) return EVP_PKEY_STATE_UNKNOWN; if ((EVP_PKEY_CTX_IS_DERIVE_OP(ctx) && ctx->op.kex.algctx != NULL) || (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx) && ctx->op.sig.algctx != NULL) || (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx) && ctx->op.ciph.algctx != NULL) || (EVP_PKEY_CTX_IS_GEN_OP(ctx) && ctx->op.keymgmt.genctx != NULL) || (EVP_PKEY_CTX_IS_KEM_OP(ctx) && ctx->op.encap.algctx != NULL)) return EVP_PKEY_STATE_PROVIDER; return EVP_PKEY_STATE_LEGACY; } static EVP_PKEY_CTX *int_ctx_new(OSSL_LIB_CTX *libctx, EVP_PKEY *pkey, ENGINE *e, const char *keytype, const char *propquery, int id) { EVP_PKEY_CTX *ret = NULL; const EVP_PKEY_METHOD *pmeth = NULL, *app_pmeth = NULL; EVP_KEYMGMT *keymgmt = NULL; /* Code below to be removed when legacy support is dropped. */ /* BEGIN legacy */ if (id == -1) { if (pkey != NULL && !evp_pkey_is_provided(pkey)) { id = pkey->type; } else { if (pkey != NULL) { /* Must be provided if we get here */ keytype = EVP_KEYMGMT_get0_name(pkey->keymgmt); } #ifndef FIPS_MODULE if (keytype != NULL) { id = evp_pkey_name2type(keytype); if (id == NID_undef) id = -1; } #endif } } /* If no ID was found here, we can only resort to find a keymgmt */ if (id == -1) { #ifndef FIPS_MODULE /* Using engine with a key without id will not work */ if (e != NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_UNSUPPORTED_ALGORITHM); return NULL; } #endif goto common; } #ifndef FIPS_MODULE /* * Here, we extract what information we can for the purpose of * supporting usage with implementations from providers, to make * for a smooth transition from legacy stuff to provider based stuff. * * If an engine is given, this is entirely legacy, and we should not * pretend anything else, so we clear the name. */ if (e != NULL) keytype = NULL; if (e == NULL && (pkey == NULL || pkey->foreign == 0)) keytype = OBJ_nid2sn(id); # ifndef OPENSSL_NO_ENGINE if (e == NULL && pkey != NULL) e = pkey->pmeth_engine != NULL ? pkey->pmeth_engine : pkey->engine; /* Try to find an ENGINE which implements this method */ if (e != NULL) { if (!ENGINE_init(e)) { ERR_raise(ERR_LIB_EVP, ERR_R_ENGINE_LIB); return NULL; } } else { e = ENGINE_get_pkey_meth_engine(id); } /* * If an ENGINE handled this method look it up. Otherwise use internal * tables. */ if (e != NULL) pmeth = ENGINE_get_pkey_meth(e, id); - else if (pkey != NULL && pkey->foreign) + else +# endif /* OPENSSL_NO_ENGINE */ + if (pkey != NULL && pkey->foreign) pmeth = EVP_PKEY_meth_find(id); else -# endif app_pmeth = pmeth = evp_pkey_meth_find_added_by_application(id); /* END legacy */ #endif /* FIPS_MODULE */ common: /* * If there's no engine and no app supplied pmeth and there's a name, we try * fetching a provider implementation. */ if (e == NULL && app_pmeth == NULL && keytype != NULL) { /* * If |pkey| is given and is provided, we take a reference to its * keymgmt. Otherwise, we fetch one for the keytype we got. This * is to ensure that operation init functions can access what they * need through this single pointer. */ if (pkey != NULL && pkey->keymgmt != NULL) { if (!EVP_KEYMGMT_up_ref(pkey->keymgmt)) ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR); else keymgmt = pkey->keymgmt; } else { keymgmt = EVP_KEYMGMT_fetch(libctx, keytype, propquery); } if (keymgmt == NULL) return NULL; /* EVP_KEYMGMT_fetch() recorded an error */ #ifndef FIPS_MODULE /* * Chase down the legacy NID, as that might be needed for diverse * purposes, such as ensure that EVP_PKEY_type() can return sensible * values. We go through all keymgmt names, because the keytype * that's passed to this function doesn't necessarily translate * directly. */ if (keymgmt != NULL) { int tmp_id = get_legacy_alg_type_from_keymgmt(keymgmt); if (tmp_id != NID_undef) { if (id == -1) { id = tmp_id; } else { /* * It really really shouldn't differ. If it still does, * something is very wrong. */ if (!ossl_assert(id == tmp_id)) { ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR); EVP_KEYMGMT_free(keymgmt); return NULL; } } } } #endif } if (pmeth == NULL && keymgmt == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_UNSUPPORTED_ALGORITHM); } else { ret = OPENSSL_zalloc(sizeof(*ret)); if (ret == NULL) ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE); } #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) if ((ret == NULL || pmeth == NULL) && e != NULL) ENGINE_finish(e); #endif if (ret == NULL) { EVP_KEYMGMT_free(keymgmt); return NULL; } if (propquery != NULL) { ret->propquery = OPENSSL_strdup(propquery); if (ret->propquery == NULL) { OPENSSL_free(ret); EVP_KEYMGMT_free(keymgmt); return NULL; } } ret->libctx = libctx; ret->keytype = keytype; ret->keymgmt = keymgmt; ret->legacy_keytype = id; ret->engine = e; ret->pmeth = pmeth; ret->operation = EVP_PKEY_OP_UNDEFINED; ret->pkey = pkey; if (pkey != NULL) EVP_PKEY_up_ref(pkey); if (pmeth != NULL && pmeth->init != NULL) { if (pmeth->init(ret) <= 0) { ret->pmeth = NULL; EVP_PKEY_CTX_free(ret); return NULL; } } return ret; } /*- All methods below can also be used in FIPS_MODULE */ EVP_PKEY_CTX *EVP_PKEY_CTX_new_from_name(OSSL_LIB_CTX *libctx, const char *name, const char *propquery) { return int_ctx_new(libctx, NULL, NULL, name, propquery, -1); } EVP_PKEY_CTX *EVP_PKEY_CTX_new_from_pkey(OSSL_LIB_CTX *libctx, EVP_PKEY *pkey, const char *propquery) { return int_ctx_new(libctx, pkey, NULL, NULL, propquery, -1); } void evp_pkey_ctx_free_old_ops(EVP_PKEY_CTX *ctx) { if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)) { if (ctx->op.sig.algctx != NULL && ctx->op.sig.signature != NULL) ctx->op.sig.signature->freectx(ctx->op.sig.algctx); EVP_SIGNATURE_free(ctx->op.sig.signature); ctx->op.sig.algctx = NULL; ctx->op.sig.signature = NULL; } else if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx)) { if (ctx->op.kex.algctx != NULL && ctx->op.kex.exchange != NULL) ctx->op.kex.exchange->freectx(ctx->op.kex.algctx); EVP_KEYEXCH_free(ctx->op.kex.exchange); ctx->op.kex.algctx = NULL; ctx->op.kex.exchange = NULL; } else if (EVP_PKEY_CTX_IS_KEM_OP(ctx)) { if (ctx->op.encap.algctx != NULL && ctx->op.encap.kem != NULL) ctx->op.encap.kem->freectx(ctx->op.encap.algctx); EVP_KEM_free(ctx->op.encap.kem); ctx->op.encap.algctx = NULL; ctx->op.encap.kem = NULL; } else if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)) { if (ctx->op.ciph.algctx != NULL && ctx->op.ciph.cipher != NULL) ctx->op.ciph.cipher->freectx(ctx->op.ciph.algctx); EVP_ASYM_CIPHER_free(ctx->op.ciph.cipher); ctx->op.ciph.algctx = NULL; ctx->op.ciph.cipher = NULL; } else if (EVP_PKEY_CTX_IS_GEN_OP(ctx)) { if (ctx->op.keymgmt.genctx != NULL && ctx->keymgmt != NULL) evp_keymgmt_gen_cleanup(ctx->keymgmt, ctx->op.keymgmt.genctx); } } void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx) { if (ctx == NULL) return; if (ctx->pmeth && ctx->pmeth->cleanup) ctx->pmeth->cleanup(ctx); evp_pkey_ctx_free_old_ops(ctx); #ifndef FIPS_MODULE evp_pkey_ctx_free_all_cached_data(ctx); #endif EVP_KEYMGMT_free(ctx->keymgmt); OPENSSL_free(ctx->propquery); EVP_PKEY_free(ctx->pkey); EVP_PKEY_free(ctx->peerkey); #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) ENGINE_finish(ctx->engine); #endif BN_free(ctx->rsa_pubexp); OPENSSL_free(ctx); } #ifndef FIPS_MODULE void EVP_PKEY_meth_get0_info(int *ppkey_id, int *pflags, const EVP_PKEY_METHOD *meth) { if (ppkey_id) *ppkey_id = meth->pkey_id; if (pflags) *pflags = meth->flags; } void EVP_PKEY_meth_copy(EVP_PKEY_METHOD *dst, const EVP_PKEY_METHOD *src) { int pkey_id = dst->pkey_id; int flags = dst->flags; *dst = *src; /* We only copy the function pointers so restore the other values */ dst->pkey_id = pkey_id; dst->flags = flags; } void EVP_PKEY_meth_free(EVP_PKEY_METHOD *pmeth) { if (pmeth && (pmeth->flags & EVP_PKEY_FLAG_DYNAMIC)) OPENSSL_free(pmeth); } EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e) { return int_ctx_new(NULL, pkey, e, NULL, NULL, -1); } EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id, ENGINE *e) { return int_ctx_new(NULL, NULL, e, NULL, NULL, id); } EVP_PKEY_CTX *EVP_PKEY_CTX_dup(const EVP_PKEY_CTX *pctx) { EVP_PKEY_CTX *rctx; # ifndef OPENSSL_NO_ENGINE /* Make sure it's safe to copy a pkey context using an ENGINE */ if (pctx->engine && !ENGINE_init(pctx->engine)) { ERR_raise(ERR_LIB_EVP, ERR_R_ENGINE_LIB); return 0; } # endif rctx = OPENSSL_zalloc(sizeof(*rctx)); if (rctx == NULL) { ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE); return NULL; } if (pctx->pkey != NULL) EVP_PKEY_up_ref(pctx->pkey); rctx->pkey = pctx->pkey; rctx->operation = pctx->operation; rctx->libctx = pctx->libctx; rctx->keytype = pctx->keytype; rctx->propquery = NULL; if (pctx->propquery != NULL) { rctx->propquery = OPENSSL_strdup(pctx->propquery); if (rctx->propquery == NULL) goto err; } rctx->legacy_keytype = pctx->legacy_keytype; if (EVP_PKEY_CTX_IS_DERIVE_OP(pctx)) { if (pctx->op.kex.exchange != NULL) { rctx->op.kex.exchange = pctx->op.kex.exchange; if (!EVP_KEYEXCH_up_ref(rctx->op.kex.exchange)) goto err; } if (pctx->op.kex.algctx != NULL) { if (!ossl_assert(pctx->op.kex.exchange != NULL)) goto err; if (pctx->op.kex.exchange->dupctx != NULL) rctx->op.kex.algctx = pctx->op.kex.exchange->dupctx(pctx->op.kex.algctx); if (rctx->op.kex.algctx == NULL) { EVP_KEYEXCH_free(rctx->op.kex.exchange); rctx->op.kex.exchange = NULL; goto err; } return rctx; } } else if (EVP_PKEY_CTX_IS_SIGNATURE_OP(pctx)) { if (pctx->op.sig.signature != NULL) { rctx->op.sig.signature = pctx->op.sig.signature; if (!EVP_SIGNATURE_up_ref(rctx->op.sig.signature)) goto err; } if (pctx->op.sig.algctx != NULL) { if (!ossl_assert(pctx->op.sig.signature != NULL)) goto err; if (pctx->op.sig.signature->dupctx != NULL) rctx->op.sig.algctx = pctx->op.sig.signature->dupctx(pctx->op.sig.algctx); if (rctx->op.sig.algctx == NULL) { EVP_SIGNATURE_free(rctx->op.sig.signature); rctx->op.sig.signature = NULL; goto err; } return rctx; } } else if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(pctx)) { if (pctx->op.ciph.cipher != NULL) { rctx->op.ciph.cipher = pctx->op.ciph.cipher; if (!EVP_ASYM_CIPHER_up_ref(rctx->op.ciph.cipher)) goto err; } if (pctx->op.ciph.algctx != NULL) { if (!ossl_assert(pctx->op.ciph.cipher != NULL)) goto err; if (pctx->op.ciph.cipher->dupctx != NULL) rctx->op.ciph.algctx = pctx->op.ciph.cipher->dupctx(pctx->op.ciph.algctx); if (rctx->op.ciph.algctx == NULL) { EVP_ASYM_CIPHER_free(rctx->op.ciph.cipher); rctx->op.ciph.cipher = NULL; goto err; } return rctx; } } else if (EVP_PKEY_CTX_IS_KEM_OP(pctx)) { if (pctx->op.encap.kem != NULL) { rctx->op.encap.kem = pctx->op.encap.kem; if (!EVP_KEM_up_ref(rctx->op.encap.kem)) goto err; } if (pctx->op.encap.algctx != NULL) { if (!ossl_assert(pctx->op.encap.kem != NULL)) goto err; if (pctx->op.encap.kem->dupctx != NULL) rctx->op.encap.algctx = pctx->op.encap.kem->dupctx(pctx->op.encap.algctx); if (rctx->op.encap.algctx == NULL) { EVP_KEM_free(rctx->op.encap.kem); rctx->op.encap.kem = NULL; goto err; } return rctx; } } else if (EVP_PKEY_CTX_IS_GEN_OP(pctx)) { /* Not supported - This would need a gen_dupctx() to work */ goto err; } rctx->pmeth = pctx->pmeth; # ifndef OPENSSL_NO_ENGINE rctx->engine = pctx->engine; # endif if (pctx->peerkey != NULL) EVP_PKEY_up_ref(pctx->peerkey); rctx->peerkey = pctx->peerkey; if (pctx->pmeth == NULL) { if (rctx->operation == EVP_PKEY_OP_UNDEFINED) { EVP_KEYMGMT *tmp_keymgmt = pctx->keymgmt; void *provkey; provkey = evp_pkey_export_to_provider(pctx->pkey, pctx->libctx, &tmp_keymgmt, pctx->propquery); if (provkey == NULL) goto err; if (!EVP_KEYMGMT_up_ref(tmp_keymgmt)) goto err; EVP_KEYMGMT_free(rctx->keymgmt); rctx->keymgmt = tmp_keymgmt; return rctx; } } else if (pctx->pmeth->copy(rctx, pctx) > 0) { return rctx; } err: rctx->pmeth = NULL; EVP_PKEY_CTX_free(rctx); return NULL; } int EVP_PKEY_meth_add0(const EVP_PKEY_METHOD *pmeth) { if (app_pkey_methods == NULL) { app_pkey_methods = sk_EVP_PKEY_METHOD_new(pmeth_cmp); if (app_pkey_methods == NULL){ ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE); return 0; } } if (!sk_EVP_PKEY_METHOD_push(app_pkey_methods, pmeth)) { ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE); return 0; } sk_EVP_PKEY_METHOD_sort(app_pkey_methods); return 1; } void evp_app_cleanup_int(void) { if (app_pkey_methods != NULL) sk_EVP_PKEY_METHOD_pop_free(app_pkey_methods, EVP_PKEY_meth_free); } int EVP_PKEY_meth_remove(const EVP_PKEY_METHOD *pmeth) { const EVP_PKEY_METHOD *ret; ret = sk_EVP_PKEY_METHOD_delete_ptr(app_pkey_methods, pmeth); return ret == NULL ? 0 : 1; } size_t EVP_PKEY_meth_get_count(void) { size_t rv = OSSL_NELEM(standard_methods); if (app_pkey_methods) rv += sk_EVP_PKEY_METHOD_num(app_pkey_methods); return rv; } const EVP_PKEY_METHOD *EVP_PKEY_meth_get0(size_t idx) { if (idx < OSSL_NELEM(standard_methods)) return (standard_methods[idx])(); if (app_pkey_methods == NULL) return NULL; idx -= OSSL_NELEM(standard_methods); if (idx >= (size_t)sk_EVP_PKEY_METHOD_num(app_pkey_methods)) return NULL; return sk_EVP_PKEY_METHOD_value(app_pkey_methods, idx); } #endif int EVP_PKEY_CTX_is_a(EVP_PKEY_CTX *ctx, const char *keytype) { #ifndef FIPS_MODULE if (evp_pkey_ctx_is_legacy(ctx)) return (ctx->pmeth->pkey_id == evp_pkey_name2type(keytype)); #endif return EVP_KEYMGMT_is_a(ctx->keymgmt, keytype); } int EVP_PKEY_CTX_set_params(EVP_PKEY_CTX *ctx, const OSSL_PARAM *params) { switch (evp_pkey_ctx_state(ctx)) { case EVP_PKEY_STATE_PROVIDER: if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx) && ctx->op.kex.exchange != NULL && ctx->op.kex.exchange->set_ctx_params != NULL) return ctx->op.kex.exchange->set_ctx_params(ctx->op.kex.algctx, params); if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx) && ctx->op.sig.signature != NULL && ctx->op.sig.signature->set_ctx_params != NULL) return ctx->op.sig.signature->set_ctx_params(ctx->op.sig.algctx, params); if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx) && ctx->op.ciph.cipher != NULL && ctx->op.ciph.cipher->set_ctx_params != NULL) return ctx->op.ciph.cipher->set_ctx_params(ctx->op.ciph.algctx, params); if (EVP_PKEY_CTX_IS_GEN_OP(ctx) && ctx->keymgmt != NULL && ctx->keymgmt->gen_set_params != NULL) return evp_keymgmt_gen_set_params(ctx->keymgmt, ctx->op.keymgmt.genctx, params); if (EVP_PKEY_CTX_IS_KEM_OP(ctx) && ctx->op.encap.kem != NULL && ctx->op.encap.kem->set_ctx_params != NULL) return ctx->op.encap.kem->set_ctx_params(ctx->op.encap.algctx, params); break; #ifndef FIPS_MODULE case EVP_PKEY_STATE_UNKNOWN: case EVP_PKEY_STATE_LEGACY: return evp_pkey_ctx_set_params_to_ctrl(ctx, params); #endif } return 0; } int EVP_PKEY_CTX_get_params(EVP_PKEY_CTX *ctx, OSSL_PARAM *params) { switch (evp_pkey_ctx_state(ctx)) { case EVP_PKEY_STATE_PROVIDER: if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx) && ctx->op.kex.exchange != NULL && ctx->op.kex.exchange->get_ctx_params != NULL) return ctx->op.kex.exchange->get_ctx_params(ctx->op.kex.algctx, params); if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx) && ctx->op.sig.signature != NULL && ctx->op.sig.signature->get_ctx_params != NULL) return ctx->op.sig.signature->get_ctx_params(ctx->op.sig.algctx, params); if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx) && ctx->op.ciph.cipher != NULL && ctx->op.ciph.cipher->get_ctx_params != NULL) return ctx->op.ciph.cipher->get_ctx_params(ctx->op.ciph.algctx, params); if (EVP_PKEY_CTX_IS_KEM_OP(ctx) && ctx->op.encap.kem != NULL && ctx->op.encap.kem->get_ctx_params != NULL) return ctx->op.encap.kem->get_ctx_params(ctx->op.encap.algctx, params); break; #ifndef FIPS_MODULE case EVP_PKEY_STATE_UNKNOWN: case EVP_PKEY_STATE_LEGACY: return evp_pkey_ctx_get_params_to_ctrl(ctx, params); #endif } return 0; } #ifndef FIPS_MODULE const OSSL_PARAM *EVP_PKEY_CTX_gettable_params(const EVP_PKEY_CTX *ctx) { void *provctx; if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx) && ctx->op.kex.exchange != NULL && ctx->op.kex.exchange->gettable_ctx_params != NULL) { provctx = ossl_provider_ctx(EVP_KEYEXCH_get0_provider(ctx->op.kex.exchange)); return ctx->op.kex.exchange->gettable_ctx_params(ctx->op.kex.algctx, provctx); } if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx) && ctx->op.sig.signature != NULL && ctx->op.sig.signature->gettable_ctx_params != NULL) { provctx = ossl_provider_ctx( EVP_SIGNATURE_get0_provider(ctx->op.sig.signature)); return ctx->op.sig.signature->gettable_ctx_params(ctx->op.sig.algctx, provctx); } if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx) && ctx->op.ciph.cipher != NULL && ctx->op.ciph.cipher->gettable_ctx_params != NULL) { provctx = ossl_provider_ctx( EVP_ASYM_CIPHER_get0_provider(ctx->op.ciph.cipher)); return ctx->op.ciph.cipher->gettable_ctx_params(ctx->op.ciph.algctx, provctx); } if (EVP_PKEY_CTX_IS_KEM_OP(ctx) && ctx->op.encap.kem != NULL && ctx->op.encap.kem->gettable_ctx_params != NULL) { provctx = ossl_provider_ctx(EVP_KEM_get0_provider(ctx->op.encap.kem)); return ctx->op.encap.kem->gettable_ctx_params(ctx->op.encap.algctx, provctx); } return NULL; } const OSSL_PARAM *EVP_PKEY_CTX_settable_params(const EVP_PKEY_CTX *ctx) { void *provctx; if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx) && ctx->op.kex.exchange != NULL && ctx->op.kex.exchange->settable_ctx_params != NULL) { provctx = ossl_provider_ctx(EVP_KEYEXCH_get0_provider(ctx->op.kex.exchange)); return ctx->op.kex.exchange->settable_ctx_params(ctx->op.kex.algctx, provctx); } if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx) && ctx->op.sig.signature != NULL && ctx->op.sig.signature->settable_ctx_params != NULL) { provctx = ossl_provider_ctx( EVP_SIGNATURE_get0_provider(ctx->op.sig.signature)); return ctx->op.sig.signature->settable_ctx_params(ctx->op.sig.algctx, provctx); } if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx) && ctx->op.ciph.cipher != NULL && ctx->op.ciph.cipher->settable_ctx_params != NULL) { provctx = ossl_provider_ctx( EVP_ASYM_CIPHER_get0_provider(ctx->op.ciph.cipher)); return ctx->op.ciph.cipher->settable_ctx_params(ctx->op.ciph.algctx, provctx); } if (EVP_PKEY_CTX_IS_GEN_OP(ctx) && ctx->keymgmt != NULL && ctx->keymgmt->gen_settable_params != NULL) { provctx = ossl_provider_ctx(EVP_KEYMGMT_get0_provider(ctx->keymgmt)); return ctx->keymgmt->gen_settable_params(ctx->op.keymgmt.genctx, provctx); } if (EVP_PKEY_CTX_IS_KEM_OP(ctx) && ctx->op.encap.kem != NULL && ctx->op.encap.kem->settable_ctx_params != NULL) { provctx = ossl_provider_ctx(EVP_KEM_get0_provider(ctx->op.encap.kem)); return ctx->op.encap.kem->settable_ctx_params(ctx->op.encap.algctx, provctx); } return NULL; } /* * Internal helpers for stricter EVP_PKEY_CTX_{set,get}_params(). * * Return 1 on success, 0 or negative for errors. * * In particular they return -2 if any of the params is not supported. * * They are not available in FIPS_MODULE as they depend on * - EVP_PKEY_CTX_{get,set}_params() * - EVP_PKEY_CTX_{gettable,settable}_params() * */ int evp_pkey_ctx_set_params_strict(EVP_PKEY_CTX *ctx, OSSL_PARAM *params) { if (ctx == NULL || params == NULL) return 0; /* * We only check for provider side EVP_PKEY_CTX. For #legacy, we * depend on the translation that happens in EVP_PKEY_CTX_set_params() * call, and that the resulting ctrl call will return -2 if it doesn't * known the ctrl command number. */ if (evp_pkey_ctx_is_provided(ctx)) { const OSSL_PARAM *settable = EVP_PKEY_CTX_settable_params(ctx); const OSSL_PARAM *p; for (p = params; p->key != NULL; p++) { /* Check the ctx actually understands this parameter */ if (OSSL_PARAM_locate_const(settable, p->key) == NULL ) return -2; } } return EVP_PKEY_CTX_set_params(ctx, params); } int evp_pkey_ctx_get_params_strict(EVP_PKEY_CTX *ctx, OSSL_PARAM *params) { if (ctx == NULL || params == NULL) return 0; /* * We only check for provider side EVP_PKEY_CTX. For #legacy, we * depend on the translation that happens in EVP_PKEY_CTX_get_params() * call, and that the resulting ctrl call will return -2 if it doesn't * known the ctrl command number. */ if (evp_pkey_ctx_is_provided(ctx)) { const OSSL_PARAM *gettable = EVP_PKEY_CTX_gettable_params(ctx); const OSSL_PARAM *p; for (p = params; p->key != NULL; p++ ) { /* Check the ctx actually understands this parameter */ if (OSSL_PARAM_locate_const(gettable, p->key) == NULL ) return -2; } } return EVP_PKEY_CTX_get_params(ctx, params); } int EVP_PKEY_CTX_get_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD **md) { OSSL_PARAM sig_md_params[2], *p = sig_md_params; /* 80 should be big enough */ char name[80] = ""; const EVP_MD *tmp; if (ctx == NULL || !EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)) { ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); /* Uses the same return values as EVP_PKEY_CTX_ctrl */ return -2; } if (ctx->op.sig.algctx == NULL) return EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_TYPE_SIG, EVP_PKEY_CTRL_GET_MD, 0, (void *)(md)); *p++ = OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, name, sizeof(name)); *p = OSSL_PARAM_construct_end(); if (!EVP_PKEY_CTX_get_params(ctx, sig_md_params)) return 0; tmp = evp_get_digestbyname_ex(ctx->libctx, name); if (tmp == NULL) return 0; *md = tmp; return 1; } static int evp_pkey_ctx_set_md(EVP_PKEY_CTX *ctx, const EVP_MD *md, int fallback, const char *param, int op, int ctrl) { OSSL_PARAM md_params[2], *p = md_params; const char *name; if (ctx == NULL || (ctx->operation & op) == 0) { ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); /* Uses the same return values as EVP_PKEY_CTX_ctrl */ return -2; } if (fallback) return EVP_PKEY_CTX_ctrl(ctx, -1, op, ctrl, 0, (void *)(md)); if (md == NULL) { name = ""; } else { name = EVP_MD_get0_name(md); } *p++ = OSSL_PARAM_construct_utf8_string(param, /* * Cast away the const. This is read * only so should be safe */ (char *)name, 0); *p = OSSL_PARAM_construct_end(); return EVP_PKEY_CTX_set_params(ctx, md_params); } int EVP_PKEY_CTX_set_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD *md) { return evp_pkey_ctx_set_md(ctx, md, ctx->op.sig.algctx == NULL, OSSL_SIGNATURE_PARAM_DIGEST, EVP_PKEY_OP_TYPE_SIG, EVP_PKEY_CTRL_MD); } int EVP_PKEY_CTX_set_tls1_prf_md(EVP_PKEY_CTX *ctx, const EVP_MD *md) { return evp_pkey_ctx_set_md(ctx, md, ctx->op.kex.algctx == NULL, OSSL_KDF_PARAM_DIGEST, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_TLS_MD); } static int evp_pkey_ctx_set1_octet_string(EVP_PKEY_CTX *ctx, int fallback, const char *param, int op, int ctrl, const unsigned char *data, int datalen) { OSSL_PARAM octet_string_params[2], *p = octet_string_params; if (ctx == NULL || (ctx->operation & op) == 0) { ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); /* Uses the same return values as EVP_PKEY_CTX_ctrl */ return -2; } /* Code below to be removed when legacy support is dropped. */ if (fallback) return EVP_PKEY_CTX_ctrl(ctx, -1, op, ctrl, datalen, (void *)(data)); /* end of legacy support */ if (datalen < 0) { ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_LENGTH); return 0; } *p++ = OSSL_PARAM_construct_octet_string(param, /* * Cast away the const. This is read * only so should be safe */ (unsigned char *)data, (size_t)datalen); *p = OSSL_PARAM_construct_end(); return EVP_PKEY_CTX_set_params(ctx, octet_string_params); } int EVP_PKEY_CTX_set1_tls1_prf_secret(EVP_PKEY_CTX *ctx, const unsigned char *sec, int seclen) { return evp_pkey_ctx_set1_octet_string(ctx, ctx->op.kex.algctx == NULL, OSSL_KDF_PARAM_SECRET, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_TLS_SECRET, sec, seclen); } int EVP_PKEY_CTX_add1_tls1_prf_seed(EVP_PKEY_CTX *ctx, const unsigned char *seed, int seedlen) { return evp_pkey_ctx_set1_octet_string(ctx, ctx->op.kex.algctx == NULL, OSSL_KDF_PARAM_SEED, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_TLS_SEED, seed, seedlen); } int EVP_PKEY_CTX_set_hkdf_md(EVP_PKEY_CTX *ctx, const EVP_MD *md) { return evp_pkey_ctx_set_md(ctx, md, ctx->op.kex.algctx == NULL, OSSL_KDF_PARAM_DIGEST, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_HKDF_MD); } int EVP_PKEY_CTX_set1_hkdf_salt(EVP_PKEY_CTX *ctx, const unsigned char *salt, int saltlen) { return evp_pkey_ctx_set1_octet_string(ctx, ctx->op.kex.algctx == NULL, OSSL_KDF_PARAM_SALT, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_HKDF_SALT, salt, saltlen); } int EVP_PKEY_CTX_set1_hkdf_key(EVP_PKEY_CTX *ctx, const unsigned char *key, int keylen) { return evp_pkey_ctx_set1_octet_string(ctx, ctx->op.kex.algctx == NULL, OSSL_KDF_PARAM_KEY, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_HKDF_KEY, key, keylen); } int EVP_PKEY_CTX_add1_hkdf_info(EVP_PKEY_CTX *ctx, const unsigned char *info, int infolen) { return evp_pkey_ctx_set1_octet_string(ctx, ctx->op.kex.algctx == NULL, OSSL_KDF_PARAM_INFO, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_HKDF_INFO, info, infolen); } int EVP_PKEY_CTX_set_hkdf_mode(EVP_PKEY_CTX *ctx, int mode) { OSSL_PARAM int_params[2], *p = int_params; if (ctx == NULL || !EVP_PKEY_CTX_IS_DERIVE_OP(ctx)) { ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); /* Uses the same return values as EVP_PKEY_CTX_ctrl */ return -2; } /* Code below to be removed when legacy support is dropped. */ if (ctx->op.kex.algctx == NULL) return EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_HKDF_MODE, mode, NULL); /* end of legacy support */ if (mode < 0) { ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_VALUE); return 0; } *p++ = OSSL_PARAM_construct_int(OSSL_KDF_PARAM_MODE, &mode); *p = OSSL_PARAM_construct_end(); return EVP_PKEY_CTX_set_params(ctx, int_params); } int EVP_PKEY_CTX_set1_pbe_pass(EVP_PKEY_CTX *ctx, const char *pass, int passlen) { return evp_pkey_ctx_set1_octet_string(ctx, ctx->op.kex.algctx == NULL, OSSL_KDF_PARAM_PASSWORD, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_PASS, (const unsigned char *)pass, passlen); } int EVP_PKEY_CTX_set1_scrypt_salt(EVP_PKEY_CTX *ctx, const unsigned char *salt, int saltlen) { return evp_pkey_ctx_set1_octet_string(ctx, ctx->op.kex.algctx == NULL, OSSL_KDF_PARAM_SALT, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_SCRYPT_SALT, salt, saltlen); } static int evp_pkey_ctx_set_uint64(EVP_PKEY_CTX *ctx, const char *param, int op, int ctrl, uint64_t val) { OSSL_PARAM uint64_params[2], *p = uint64_params; if (ctx == NULL || !EVP_PKEY_CTX_IS_DERIVE_OP(ctx)) { ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); /* Uses the same return values as EVP_PKEY_CTX_ctrl */ return -2; } /* Code below to be removed when legacy support is dropped. */ if (ctx->op.kex.algctx == NULL) return EVP_PKEY_CTX_ctrl_uint64(ctx, -1, op, ctrl, val); /* end of legacy support */ *p++ = OSSL_PARAM_construct_uint64(param, &val); *p = OSSL_PARAM_construct_end(); return EVP_PKEY_CTX_set_params(ctx, uint64_params); } int EVP_PKEY_CTX_set_scrypt_N(EVP_PKEY_CTX *ctx, uint64_t n) { return evp_pkey_ctx_set_uint64(ctx, OSSL_KDF_PARAM_SCRYPT_N, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_SCRYPT_N, n); } int EVP_PKEY_CTX_set_scrypt_r(EVP_PKEY_CTX *ctx, uint64_t r) { return evp_pkey_ctx_set_uint64(ctx, OSSL_KDF_PARAM_SCRYPT_R, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_SCRYPT_R, r); } int EVP_PKEY_CTX_set_scrypt_p(EVP_PKEY_CTX *ctx, uint64_t p) { return evp_pkey_ctx_set_uint64(ctx, OSSL_KDF_PARAM_SCRYPT_P, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_SCRYPT_P, p); } int EVP_PKEY_CTX_set_scrypt_maxmem_bytes(EVP_PKEY_CTX *ctx, uint64_t maxmem_bytes) { return evp_pkey_ctx_set_uint64(ctx, OSSL_KDF_PARAM_SCRYPT_MAXMEM, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_SCRYPT_MAXMEM_BYTES, maxmem_bytes); } int EVP_PKEY_CTX_set_mac_key(EVP_PKEY_CTX *ctx, const unsigned char *key, int keylen) { return evp_pkey_ctx_set1_octet_string(ctx, ctx->op.keymgmt.genctx == NULL, OSSL_PKEY_PARAM_PRIV_KEY, EVP_PKEY_OP_KEYGEN, EVP_PKEY_CTRL_SET_MAC_KEY, key, keylen); } int EVP_PKEY_CTX_set_kem_op(EVP_PKEY_CTX *ctx, const char *op) { OSSL_PARAM params[2], *p = params; if (ctx == NULL || op == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_VALUE); return 0; } if (!EVP_PKEY_CTX_IS_KEM_OP(ctx)) { ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); return -2; } *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KEM_PARAM_OPERATION, (char *)op, 0); *p = OSSL_PARAM_construct_end(); return EVP_PKEY_CTX_set_params(ctx, params); } int evp_pkey_ctx_set1_id_prov(EVP_PKEY_CTX *ctx, const void *id, int len) { OSSL_PARAM params[2], *p = params; int ret; if (!EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)) { ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); /* Uses the same return values as EVP_PKEY_CTX_ctrl */ return -2; } *p++ = OSSL_PARAM_construct_octet_string(OSSL_PKEY_PARAM_DIST_ID, /* * Cast away the const. This is * read only so should be safe */ (void *)id, (size_t)len); *p++ = OSSL_PARAM_construct_end(); ret = evp_pkey_ctx_set_params_strict(ctx, params); if (ret == -2) ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); return ret; } int EVP_PKEY_CTX_set1_id(EVP_PKEY_CTX *ctx, const void *id, int len) { return EVP_PKEY_CTX_ctrl(ctx, -1, -1, EVP_PKEY_CTRL_SET1_ID, (int)len, (void*)(id)); } static int get1_id_data(EVP_PKEY_CTX *ctx, void *id, size_t *id_len) { int ret; void *tmp_id = NULL; OSSL_PARAM params[2], *p = params; if (!EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)) { ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); /* Uses the same return values as EVP_PKEY_CTX_ctrl */ return -2; } *p++ = OSSL_PARAM_construct_octet_ptr(OSSL_PKEY_PARAM_DIST_ID, &tmp_id, 0); *p++ = OSSL_PARAM_construct_end(); ret = evp_pkey_ctx_get_params_strict(ctx, params); if (ret == -2) { ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); } else if (ret > 0) { size_t tmp_id_len = params[0].return_size; if (id != NULL) memcpy(id, tmp_id, tmp_id_len); if (id_len != NULL) *id_len = tmp_id_len; } return ret; } int evp_pkey_ctx_get1_id_prov(EVP_PKEY_CTX *ctx, void *id) { return get1_id_data(ctx, id, NULL); } int evp_pkey_ctx_get1_id_len_prov(EVP_PKEY_CTX *ctx, size_t *id_len) { return get1_id_data(ctx, NULL, id_len); } int EVP_PKEY_CTX_get1_id(EVP_PKEY_CTX *ctx, void *id) { return EVP_PKEY_CTX_ctrl(ctx, -1, -1, EVP_PKEY_CTRL_GET1_ID, 0, (void*)id); } int EVP_PKEY_CTX_get1_id_len(EVP_PKEY_CTX *ctx, size_t *id_len) { return EVP_PKEY_CTX_ctrl(ctx, -1, -1, EVP_PKEY_CTRL_GET1_ID_LEN, 0, (void*)id_len); } static int evp_pkey_ctx_ctrl_int(EVP_PKEY_CTX *ctx, int keytype, int optype, int cmd, int p1, void *p2) { int ret = 0; /* * If the method has a |digest_custom| function, we can relax the * operation type check, since this can be called before the operation * is initialized. */ if (ctx->pmeth == NULL || ctx->pmeth->digest_custom == NULL) { if (ctx->operation == EVP_PKEY_OP_UNDEFINED) { ERR_raise(ERR_LIB_EVP, EVP_R_NO_OPERATION_SET); return -1; } if ((optype != -1) && !(ctx->operation & optype)) { ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_OPERATION); return -1; } } switch (evp_pkey_ctx_state(ctx)) { case EVP_PKEY_STATE_PROVIDER: return evp_pkey_ctx_ctrl_to_param(ctx, keytype, optype, cmd, p1, p2); case EVP_PKEY_STATE_UNKNOWN: case EVP_PKEY_STATE_LEGACY: if (ctx->pmeth == NULL || ctx->pmeth->ctrl == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); return -2; } if ((keytype != -1) && (ctx->pmeth->pkey_id != keytype)) return -1; ret = ctx->pmeth->ctrl(ctx, cmd, p1, p2); if (ret == -2) ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); break; } return ret; } int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype, int cmd, int p1, void *p2) { int ret = 0; if (ctx == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); return -2; } /* If unsupported, we don't want that reported here */ ERR_set_mark(); ret = evp_pkey_ctx_store_cached_data(ctx, keytype, optype, cmd, NULL, p2, p1); if (ret == -2) { ERR_pop_to_mark(); } else { ERR_clear_last_mark(); /* * If there was an error, there was an error. * If the operation isn't initialized yet, we also return, as * the saved values will be used then anyway. */ if (ret < 1 || ctx->operation == EVP_PKEY_OP_UNDEFINED) return ret; } return evp_pkey_ctx_ctrl_int(ctx, keytype, optype, cmd, p1, p2); } int EVP_PKEY_CTX_ctrl_uint64(EVP_PKEY_CTX *ctx, int keytype, int optype, int cmd, uint64_t value) { return EVP_PKEY_CTX_ctrl(ctx, keytype, optype, cmd, 0, &value); } static int evp_pkey_ctx_ctrl_str_int(EVP_PKEY_CTX *ctx, const char *name, const char *value) { int ret = 0; if (ctx == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); return -2; } switch (evp_pkey_ctx_state(ctx)) { case EVP_PKEY_STATE_PROVIDER: return evp_pkey_ctx_ctrl_str_to_param(ctx, name, value); case EVP_PKEY_STATE_UNKNOWN: case EVP_PKEY_STATE_LEGACY: if (ctx == NULL || ctx->pmeth == NULL || ctx->pmeth->ctrl_str == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); return -2; } if (strcmp(name, "digest") == 0) ret = EVP_PKEY_CTX_md(ctx, EVP_PKEY_OP_TYPE_SIG | EVP_PKEY_OP_TYPE_CRYPT, EVP_PKEY_CTRL_MD, value); else ret = ctx->pmeth->ctrl_str(ctx, name, value); break; } return ret; } int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, const char *name, const char *value) { int ret = 0; /* If unsupported, we don't want that reported here */ ERR_set_mark(); ret = evp_pkey_ctx_store_cached_data(ctx, -1, -1, -1, name, value, strlen(value) + 1); if (ret == -2) { ERR_pop_to_mark(); } else { ERR_clear_last_mark(); /* * If there was an error, there was an error. * If the operation isn't initialized yet, we also return, as * the saved values will be used then anyway. */ if (ret < 1 || ctx->operation == EVP_PKEY_OP_UNDEFINED) return ret; } return evp_pkey_ctx_ctrl_str_int(ctx, name, value); } static int decode_cmd(int cmd, const char *name) { if (cmd == -1) { /* * The consequence of the assertion not being true is that this * function will return -1, which will cause the calling functions * to signal that the command is unsupported... in non-debug mode. */ if (ossl_assert(name != NULL)) if (strcmp(name, "distid") == 0 || strcmp(name, "hexdistid") == 0) cmd = EVP_PKEY_CTRL_SET1_ID; } return cmd; } static int evp_pkey_ctx_store_cached_data(EVP_PKEY_CTX *ctx, int keytype, int optype, int cmd, const char *name, const void *data, size_t data_len) { /* * Check that it's one of the supported commands. The ctrl commands * number cases here must correspond to the cases in the bottom switch * in this function. */ switch (cmd = decode_cmd(cmd, name)) { case EVP_PKEY_CTRL_SET1_ID: break; default: ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); return -2; } if (keytype != -1) { switch (evp_pkey_ctx_state(ctx)) { case EVP_PKEY_STATE_PROVIDER: if (ctx->keymgmt == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); return -2; } if (!EVP_KEYMGMT_is_a(ctx->keymgmt, evp_pkey_type2name(keytype))) { ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_OPERATION); return -1; } break; case EVP_PKEY_STATE_UNKNOWN: case EVP_PKEY_STATE_LEGACY: if (ctx->pmeth == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); return -2; } if (EVP_PKEY_type(ctx->pmeth->pkey_id) != EVP_PKEY_type(keytype)) { ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_OPERATION); return -1; } break; } } if (optype != -1 && (ctx->operation & optype) == 0) { ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_OPERATION); return -1; } switch (cmd) { case EVP_PKEY_CTRL_SET1_ID: evp_pkey_ctx_free_cached_data(ctx, cmd, name); if (name != NULL) { ctx->cached_parameters.dist_id_name = OPENSSL_strdup(name); if (ctx->cached_parameters.dist_id_name == NULL) { ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE); return 0; } } if (data_len > 0) { ctx->cached_parameters.dist_id = OPENSSL_memdup(data, data_len); if (ctx->cached_parameters.dist_id == NULL) { ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE); return 0; } } ctx->cached_parameters.dist_id_set = 1; ctx->cached_parameters.dist_id_len = data_len; break; } return 1; } static void evp_pkey_ctx_free_cached_data(EVP_PKEY_CTX *ctx, int cmd, const char *name) { cmd = decode_cmd(cmd, name); switch (cmd) { case EVP_PKEY_CTRL_SET1_ID: OPENSSL_free(ctx->cached_parameters.dist_id); OPENSSL_free(ctx->cached_parameters.dist_id_name); ctx->cached_parameters.dist_id = NULL; ctx->cached_parameters.dist_id_name = NULL; break; } } static void evp_pkey_ctx_free_all_cached_data(EVP_PKEY_CTX *ctx) { evp_pkey_ctx_free_cached_data(ctx, EVP_PKEY_CTRL_SET1_ID, NULL); } int evp_pkey_ctx_use_cached_data(EVP_PKEY_CTX *ctx) { int ret = 1; if (ret && ctx->cached_parameters.dist_id_set) { const char *name = ctx->cached_parameters.dist_id_name; const void *val = ctx->cached_parameters.dist_id; size_t len = ctx->cached_parameters.dist_id_len; if (name != NULL) ret = evp_pkey_ctx_ctrl_str_int(ctx, name, val); else ret = evp_pkey_ctx_ctrl_int(ctx, -1, ctx->operation, EVP_PKEY_CTRL_SET1_ID, (int)len, (void *)val); } return ret; } OSSL_LIB_CTX *EVP_PKEY_CTX_get0_libctx(EVP_PKEY_CTX *ctx) { return ctx->libctx; } const char *EVP_PKEY_CTX_get0_propq(const EVP_PKEY_CTX *ctx) { return ctx->propquery; } const OSSL_PROVIDER *EVP_PKEY_CTX_get0_provider(const EVP_PKEY_CTX *ctx) { if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)) { if (ctx->op.sig.signature != NULL) return EVP_SIGNATURE_get0_provider(ctx->op.sig.signature); } else if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx)) { if (ctx->op.kex.exchange != NULL) return EVP_KEYEXCH_get0_provider(ctx->op.kex.exchange); } else if (EVP_PKEY_CTX_IS_KEM_OP(ctx)) { if (ctx->op.encap.kem != NULL) return EVP_KEM_get0_provider(ctx->op.encap.kem); } else if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)) { if (ctx->op.ciph.cipher != NULL) return EVP_ASYM_CIPHER_get0_provider(ctx->op.ciph.cipher); } else if (EVP_PKEY_CTX_IS_GEN_OP(ctx)) { if (ctx->keymgmt != NULL) return EVP_KEYMGMT_get0_provider(ctx->keymgmt); } return NULL; } /* Utility functions to send a string of hex string to a ctrl */ int EVP_PKEY_CTX_str2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *str) { size_t len; len = strlen(str); if (len > INT_MAX) return -1; return ctx->pmeth->ctrl(ctx, cmd, len, (void *)str); } int EVP_PKEY_CTX_hex2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *hex) { unsigned char *bin; long binlen; int rv = -1; bin = OPENSSL_hexstr2buf(hex, &binlen); if (bin == NULL) return 0; if (binlen <= INT_MAX) rv = ctx->pmeth->ctrl(ctx, cmd, binlen, bin); OPENSSL_free(bin); return rv; } /* Pass a message digest to a ctrl */ int EVP_PKEY_CTX_md(EVP_PKEY_CTX *ctx, int optype, int cmd, const char *md) { const EVP_MD *m; if (md == NULL || (m = EVP_get_digestbyname(md)) == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_DIGEST); return 0; } return EVP_PKEY_CTX_ctrl(ctx, -1, optype, cmd, 0, (void *)m); } int EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX *ctx) { return ctx->operation; } void EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX *ctx, int *dat, int datlen) { ctx->keygen_info = dat; ctx->keygen_info_count = datlen; } void EVP_PKEY_CTX_set_data(EVP_PKEY_CTX *ctx, void *data) { ctx->data = data; } void *EVP_PKEY_CTX_get_data(const EVP_PKEY_CTX *ctx) { return ctx->data; } EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx) { return ctx->pkey; } EVP_PKEY *EVP_PKEY_CTX_get0_peerkey(EVP_PKEY_CTX *ctx) { return ctx->peerkey; } void EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX *ctx, void *data) { ctx->app_data = data; } void *EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX *ctx) { return ctx->app_data; } void EVP_PKEY_meth_set_init(EVP_PKEY_METHOD *pmeth, int (*init) (EVP_PKEY_CTX *ctx)) { pmeth->init = init; } void EVP_PKEY_meth_set_copy(EVP_PKEY_METHOD *pmeth, int (*copy) (EVP_PKEY_CTX *dst, const EVP_PKEY_CTX *src)) { pmeth->copy = copy; } void EVP_PKEY_meth_set_cleanup(EVP_PKEY_METHOD *pmeth, void (*cleanup) (EVP_PKEY_CTX *ctx)) { pmeth->cleanup = cleanup; } void EVP_PKEY_meth_set_paramgen(EVP_PKEY_METHOD *pmeth, int (*paramgen_init) (EVP_PKEY_CTX *ctx), int (*paramgen) (EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)) { pmeth->paramgen_init = paramgen_init; pmeth->paramgen = paramgen; } void EVP_PKEY_meth_set_keygen(EVP_PKEY_METHOD *pmeth, int (*keygen_init) (EVP_PKEY_CTX *ctx), int (*keygen) (EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)) { pmeth->keygen_init = keygen_init; pmeth->keygen = keygen; } void EVP_PKEY_meth_set_sign(EVP_PKEY_METHOD *pmeth, int (*sign_init) (EVP_PKEY_CTX *ctx), int (*sign) (EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, const unsigned char *tbs, size_t tbslen)) { pmeth->sign_init = sign_init; pmeth->sign = sign; } void EVP_PKEY_meth_set_verify(EVP_PKEY_METHOD *pmeth, int (*verify_init) (EVP_PKEY_CTX *ctx), int (*verify) (EVP_PKEY_CTX *ctx, const unsigned char *sig, size_t siglen, const unsigned char *tbs, size_t tbslen)) { pmeth->verify_init = verify_init; pmeth->verify = verify; } void EVP_PKEY_meth_set_verify_recover(EVP_PKEY_METHOD *pmeth, int (*verify_recover_init) (EVP_PKEY_CTX *ctx), int (*verify_recover) (EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, const unsigned char *tbs, size_t tbslen)) { pmeth->verify_recover_init = verify_recover_init; pmeth->verify_recover = verify_recover; } void EVP_PKEY_meth_set_signctx(EVP_PKEY_METHOD *pmeth, int (*signctx_init) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx), int (*signctx) (EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, EVP_MD_CTX *mctx)) { pmeth->signctx_init = signctx_init; pmeth->signctx = signctx; } void EVP_PKEY_meth_set_verifyctx(EVP_PKEY_METHOD *pmeth, int (*verifyctx_init) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx), int (*verifyctx) (EVP_PKEY_CTX *ctx, const unsigned char *sig, int siglen, EVP_MD_CTX *mctx)) { pmeth->verifyctx_init = verifyctx_init; pmeth->verifyctx = verifyctx; } void EVP_PKEY_meth_set_encrypt(EVP_PKEY_METHOD *pmeth, int (*encrypt_init) (EVP_PKEY_CTX *ctx), int (*encryptfn) (EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen, const unsigned char *in, size_t inlen)) { pmeth->encrypt_init = encrypt_init; pmeth->encrypt = encryptfn; } void EVP_PKEY_meth_set_decrypt(EVP_PKEY_METHOD *pmeth, int (*decrypt_init) (EVP_PKEY_CTX *ctx), int (*decrypt) (EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen, const unsigned char *in, size_t inlen)) { pmeth->decrypt_init = decrypt_init; pmeth->decrypt = decrypt; } void EVP_PKEY_meth_set_derive(EVP_PKEY_METHOD *pmeth, int (*derive_init) (EVP_PKEY_CTX *ctx), int (*derive) (EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen)) { pmeth->derive_init = derive_init; pmeth->derive = derive; } void EVP_PKEY_meth_set_ctrl(EVP_PKEY_METHOD *pmeth, int (*ctrl) (EVP_PKEY_CTX *ctx, int type, int p1, void *p2), int (*ctrl_str) (EVP_PKEY_CTX *ctx, const char *type, const char *value)) { pmeth->ctrl = ctrl; pmeth->ctrl_str = ctrl_str; } void EVP_PKEY_meth_set_digestsign(EVP_PKEY_METHOD *pmeth, int (*digestsign) (EVP_MD_CTX *ctx, unsigned char *sig, size_t *siglen, const unsigned char *tbs, size_t tbslen)) { pmeth->digestsign = digestsign; } void EVP_PKEY_meth_set_digestverify(EVP_PKEY_METHOD *pmeth, int (*digestverify) (EVP_MD_CTX *ctx, const unsigned char *sig, size_t siglen, const unsigned char *tbs, size_t tbslen)) { pmeth->digestverify = digestverify; } void EVP_PKEY_meth_set_check(EVP_PKEY_METHOD *pmeth, int (*check) (EVP_PKEY *pkey)) { pmeth->check = check; } void EVP_PKEY_meth_set_public_check(EVP_PKEY_METHOD *pmeth, int (*check) (EVP_PKEY *pkey)) { pmeth->public_check = check; } void EVP_PKEY_meth_set_param_check(EVP_PKEY_METHOD *pmeth, int (*check) (EVP_PKEY *pkey)) { pmeth->param_check = check; } void EVP_PKEY_meth_set_digest_custom(EVP_PKEY_METHOD *pmeth, int (*digest_custom) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx)) { pmeth->digest_custom = digest_custom; } void EVP_PKEY_meth_get_init(const EVP_PKEY_METHOD *pmeth, int (**pinit) (EVP_PKEY_CTX *ctx)) { *pinit = pmeth->init; } void EVP_PKEY_meth_get_copy(const EVP_PKEY_METHOD *pmeth, int (**pcopy) (EVP_PKEY_CTX *dst, const EVP_PKEY_CTX *src)) { *pcopy = pmeth->copy; } void EVP_PKEY_meth_get_cleanup(const EVP_PKEY_METHOD *pmeth, void (**pcleanup) (EVP_PKEY_CTX *ctx)) { *pcleanup = pmeth->cleanup; } void EVP_PKEY_meth_get_paramgen(const EVP_PKEY_METHOD *pmeth, int (**pparamgen_init) (EVP_PKEY_CTX *ctx), int (**pparamgen) (EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)) { if (pparamgen_init) *pparamgen_init = pmeth->paramgen_init; if (pparamgen) *pparamgen = pmeth->paramgen; } void EVP_PKEY_meth_get_keygen(const EVP_PKEY_METHOD *pmeth, int (**pkeygen_init) (EVP_PKEY_CTX *ctx), int (**pkeygen) (EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)) { if (pkeygen_init) *pkeygen_init = pmeth->keygen_init; if (pkeygen) *pkeygen = pmeth->keygen; } void EVP_PKEY_meth_get_sign(const EVP_PKEY_METHOD *pmeth, int (**psign_init) (EVP_PKEY_CTX *ctx), int (**psign) (EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, const unsigned char *tbs, size_t tbslen)) { if (psign_init) *psign_init = pmeth->sign_init; if (psign) *psign = pmeth->sign; } void EVP_PKEY_meth_get_verify(const EVP_PKEY_METHOD *pmeth, int (**pverify_init) (EVP_PKEY_CTX *ctx), int (**pverify) (EVP_PKEY_CTX *ctx, const unsigned char *sig, size_t siglen, const unsigned char *tbs, size_t tbslen)) { if (pverify_init) *pverify_init = pmeth->verify_init; if (pverify) *pverify = pmeth->verify; } void EVP_PKEY_meth_get_verify_recover(const EVP_PKEY_METHOD *pmeth, int (**pverify_recover_init) (EVP_PKEY_CTX *ctx), int (**pverify_recover) (EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, const unsigned char *tbs, size_t tbslen)) { if (pverify_recover_init) *pverify_recover_init = pmeth->verify_recover_init; if (pverify_recover) *pverify_recover = pmeth->verify_recover; } void EVP_PKEY_meth_get_signctx(const EVP_PKEY_METHOD *pmeth, int (**psignctx_init) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx), int (**psignctx) (EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, EVP_MD_CTX *mctx)) { if (psignctx_init) *psignctx_init = pmeth->signctx_init; if (psignctx) *psignctx = pmeth->signctx; } void EVP_PKEY_meth_get_verifyctx(const EVP_PKEY_METHOD *pmeth, int (**pverifyctx_init) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx), int (**pverifyctx) (EVP_PKEY_CTX *ctx, const unsigned char *sig, int siglen, EVP_MD_CTX *mctx)) { if (pverifyctx_init) *pverifyctx_init = pmeth->verifyctx_init; if (pverifyctx) *pverifyctx = pmeth->verifyctx; } void EVP_PKEY_meth_get_encrypt(const EVP_PKEY_METHOD *pmeth, int (**pencrypt_init) (EVP_PKEY_CTX *ctx), int (**pencryptfn) (EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen, const unsigned char *in, size_t inlen)) { if (pencrypt_init) *pencrypt_init = pmeth->encrypt_init; if (pencryptfn) *pencryptfn = pmeth->encrypt; } void EVP_PKEY_meth_get_decrypt(const EVP_PKEY_METHOD *pmeth, int (**pdecrypt_init) (EVP_PKEY_CTX *ctx), int (**pdecrypt) (EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen, const unsigned char *in, size_t inlen)) { if (pdecrypt_init) *pdecrypt_init = pmeth->decrypt_init; if (pdecrypt) *pdecrypt = pmeth->decrypt; } void EVP_PKEY_meth_get_derive(const EVP_PKEY_METHOD *pmeth, int (**pderive_init) (EVP_PKEY_CTX *ctx), int (**pderive) (EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen)) { if (pderive_init) *pderive_init = pmeth->derive_init; if (pderive) *pderive = pmeth->derive; } void EVP_PKEY_meth_get_ctrl(const EVP_PKEY_METHOD *pmeth, int (**pctrl) (EVP_PKEY_CTX *ctx, int type, int p1, void *p2), int (**pctrl_str) (EVP_PKEY_CTX *ctx, const char *type, const char *value)) { if (pctrl) *pctrl = pmeth->ctrl; if (pctrl_str) *pctrl_str = pmeth->ctrl_str; } void EVP_PKEY_meth_get_digestsign(const EVP_PKEY_METHOD *pmeth, int (**digestsign) (EVP_MD_CTX *ctx, unsigned char *sig, size_t *siglen, const unsigned char *tbs, size_t tbslen)) { if (digestsign) *digestsign = pmeth->digestsign; } void EVP_PKEY_meth_get_digestverify(const EVP_PKEY_METHOD *pmeth, int (**digestverify) (EVP_MD_CTX *ctx, const unsigned char *sig, size_t siglen, const unsigned char *tbs, size_t tbslen)) { if (digestverify) *digestverify = pmeth->digestverify; } void EVP_PKEY_meth_get_check(const EVP_PKEY_METHOD *pmeth, int (**pcheck) (EVP_PKEY *pkey)) { if (pcheck != NULL) *pcheck = pmeth->check; } void EVP_PKEY_meth_get_public_check(const EVP_PKEY_METHOD *pmeth, int (**pcheck) (EVP_PKEY *pkey)) { if (pcheck != NULL) *pcheck = pmeth->public_check; } void EVP_PKEY_meth_get_param_check(const EVP_PKEY_METHOD *pmeth, int (**pcheck) (EVP_PKEY *pkey)) { if (pcheck != NULL) *pcheck = pmeth->param_check; } void EVP_PKEY_meth_get_digest_custom(const EVP_PKEY_METHOD *pmeth, int (**pdigest_custom) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx)) { if (pdigest_custom != NULL) *pdigest_custom = pmeth->digest_custom; } #endif /* FIPS_MODULE */ diff --git a/crypto/openssl/crypto/ex_data.c b/crypto/openssl/crypto/ex_data.c index 40223f06e4ec..13b928899456 100644 --- a/crypto/openssl/crypto/ex_data.c +++ b/crypto/openssl/crypto/ex_data.c @@ -1,504 +1,506 @@ /* - * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ #include #include "crypto/cryptlib.h" #include "internal/thread_once.h" int ossl_do_ex_data_init(OSSL_LIB_CTX *ctx) { OSSL_EX_DATA_GLOBAL *global = ossl_lib_ctx_get_ex_data_global(ctx); if (global == NULL) return 0; global->ex_data_lock = CRYPTO_THREAD_lock_new(); return global->ex_data_lock != NULL; } /* * Return the EX_CALLBACKS from the |ex_data| array that corresponds to * a given class. On success, *holds the lock.* * The |global| parameter is assumed to be non null (checked by the caller). */ static EX_CALLBACKS *get_and_lock(OSSL_EX_DATA_GLOBAL *global, int class_index) { EX_CALLBACKS *ip; if (class_index < 0 || class_index >= CRYPTO_EX_INDEX__COUNT) { ERR_raise(ERR_LIB_CRYPTO, ERR_R_PASSED_INVALID_ARGUMENT); return NULL; } if (global->ex_data_lock == NULL) { /* * If we get here, someone (who?) cleaned up the lock, so just * treat it as an error. */ return NULL; } if (!CRYPTO_THREAD_write_lock(global->ex_data_lock)) return NULL; ip = &global->ex_data[class_index]; return ip; } static void cleanup_cb(EX_CALLBACK *funcs) { OPENSSL_free(funcs); } /* * Release all "ex_data" state to prevent memory leaks. This can't be made * thread-safe without overhauling a lot of stuff, and shouldn't really be * called under potential race-conditions anyway (it's for program shutdown * after all). */ void ossl_crypto_cleanup_all_ex_data_int(OSSL_LIB_CTX *ctx) { int i; OSSL_EX_DATA_GLOBAL *global = ossl_lib_ctx_get_ex_data_global(ctx); if (global == NULL) return; for (i = 0; i < CRYPTO_EX_INDEX__COUNT; ++i) { EX_CALLBACKS *ip = &global->ex_data[i]; sk_EX_CALLBACK_pop_free(ip->meth, cleanup_cb); ip->meth = NULL; } CRYPTO_THREAD_lock_free(global->ex_data_lock); global->ex_data_lock = NULL; } /* * Unregister a new index by replacing the callbacks with no-ops. * Any in-use instances are leaked. */ static void dummy_new(void *parent, void *ptr, CRYPTO_EX_DATA *ad, int idx, long argl, void *argp) { } static void dummy_free(void *parent, void *ptr, CRYPTO_EX_DATA *ad, int idx, long argl, void *argp) { } static int dummy_dup(CRYPTO_EX_DATA *to, const CRYPTO_EX_DATA *from, void **from_d, int idx, long argl, void *argp) { return 1; } int ossl_crypto_free_ex_index_ex(OSSL_LIB_CTX *ctx, int class_index, int idx) { EX_CALLBACKS *ip; EX_CALLBACK *a; int toret = 0; OSSL_EX_DATA_GLOBAL *global = ossl_lib_ctx_get_ex_data_global(ctx); if (global == NULL) return 0; ip = get_and_lock(global, class_index); if (ip == NULL) return 0; if (idx < 0 || idx >= sk_EX_CALLBACK_num(ip->meth)) goto err; a = sk_EX_CALLBACK_value(ip->meth, idx); if (a == NULL) goto err; a->new_func = dummy_new; a->dup_func = dummy_dup; a->free_func = dummy_free; toret = 1; err: CRYPTO_THREAD_unlock(global->ex_data_lock); return toret; } int CRYPTO_free_ex_index(int class_index, int idx) { return ossl_crypto_free_ex_index_ex(NULL, class_index, idx); } /* * Register a new index. */ int ossl_crypto_get_ex_new_index_ex(OSSL_LIB_CTX *ctx, int class_index, long argl, void *argp, CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func, int priority) { int toret = -1; EX_CALLBACK *a; EX_CALLBACKS *ip; OSSL_EX_DATA_GLOBAL *global = ossl_lib_ctx_get_ex_data_global(ctx); if (global == NULL) return -1; ip = get_and_lock(global, class_index); if (ip == NULL) return -1; if (ip->meth == NULL) { ip->meth = sk_EX_CALLBACK_new_null(); /* We push an initial value on the stack because the SSL * "app_data" routines use ex_data index zero. See RT 3710. */ if (ip->meth == NULL || !sk_EX_CALLBACK_push(ip->meth, NULL)) { + sk_EX_CALLBACK_free(ip->meth); + ip->meth = NULL; ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE); goto err; } } a = (EX_CALLBACK *)OPENSSL_malloc(sizeof(*a)); if (a == NULL) { ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE); goto err; } a->argl = argl; a->argp = argp; a->new_func = new_func; a->dup_func = dup_func; a->free_func = free_func; a->priority = priority; if (!sk_EX_CALLBACK_push(ip->meth, NULL)) { ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE); OPENSSL_free(a); goto err; } toret = sk_EX_CALLBACK_num(ip->meth) - 1; (void)sk_EX_CALLBACK_set(ip->meth, toret, a); err: CRYPTO_THREAD_unlock(global->ex_data_lock); return toret; } int CRYPTO_get_ex_new_index(int class_index, long argl, void *argp, CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) { return ossl_crypto_get_ex_new_index_ex(NULL, class_index, argl, argp, new_func, dup_func, free_func, 0); } /* * Initialise a new CRYPTO_EX_DATA for use in a particular class - including * calling new() callbacks for each index in the class used by this variable * Thread-safe by copying a class's array of "EX_CALLBACK" entries * in the lock, then using them outside the lock. Note this only applies * to the global "ex_data" state (ie. class definitions), not 'ad' itself. */ int ossl_crypto_new_ex_data_ex(OSSL_LIB_CTX *ctx, int class_index, void *obj, CRYPTO_EX_DATA *ad) { int mx, i; void *ptr; EX_CALLBACK **storage = NULL; EX_CALLBACK *stack[10]; EX_CALLBACKS *ip; OSSL_EX_DATA_GLOBAL *global = ossl_lib_ctx_get_ex_data_global(ctx); if (global == NULL) return 0; ip = get_and_lock(global, class_index); if (ip == NULL) return 0; ad->ctx = ctx; ad->sk = NULL; mx = sk_EX_CALLBACK_num(ip->meth); if (mx > 0) { if (mx < (int)OSSL_NELEM(stack)) storage = stack; else storage = OPENSSL_malloc(sizeof(*storage) * mx); if (storage != NULL) for (i = 0; i < mx; i++) storage[i] = sk_EX_CALLBACK_value(ip->meth, i); } CRYPTO_THREAD_unlock(global->ex_data_lock); if (mx > 0 && storage == NULL) { ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE); return 0; } for (i = 0; i < mx; i++) { if (storage[i] != NULL && storage[i]->new_func != NULL) { ptr = CRYPTO_get_ex_data(ad, i); storage[i]->new_func(obj, ptr, ad, i, storage[i]->argl, storage[i]->argp); } } if (storage != stack) OPENSSL_free(storage); return 1; } int CRYPTO_new_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad) { return ossl_crypto_new_ex_data_ex(NULL, class_index, obj, ad); } /* * Duplicate a CRYPTO_EX_DATA variable - including calling dup() callbacks * for each index in the class used by this variable */ int CRYPTO_dup_ex_data(int class_index, CRYPTO_EX_DATA *to, const CRYPTO_EX_DATA *from) { int mx, j, i; void *ptr; EX_CALLBACK *stack[10]; EX_CALLBACK **storage = NULL; EX_CALLBACKS *ip; int toret = 0; OSSL_EX_DATA_GLOBAL *global; to->ctx = from->ctx; if (from->sk == NULL) /* Nothing to copy over */ return 1; global = ossl_lib_ctx_get_ex_data_global(from->ctx); if (global == NULL) return 0; ip = get_and_lock(global, class_index); if (ip == NULL) return 0; mx = sk_EX_CALLBACK_num(ip->meth); j = sk_void_num(from->sk); if (j < mx) mx = j; if (mx > 0) { if (mx < (int)OSSL_NELEM(stack)) storage = stack; else storage = OPENSSL_malloc(sizeof(*storage) * mx); if (storage != NULL) for (i = 0; i < mx; i++) storage[i] = sk_EX_CALLBACK_value(ip->meth, i); } CRYPTO_THREAD_unlock(global->ex_data_lock); if (mx == 0) return 1; if (storage == NULL) { ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE); return 0; } /* * Make sure the ex_data stack is at least |mx| elements long to avoid * issues in the for loop that follows; so go get the |mx|'th element * (if it does not exist CRYPTO_get_ex_data() returns NULL), and assign * to itself. This is normally a no-op; but ensures the stack is the * proper size */ if (!CRYPTO_set_ex_data(to, mx - 1, CRYPTO_get_ex_data(to, mx - 1))) goto err; for (i = 0; i < mx; i++) { ptr = CRYPTO_get_ex_data(from, i); if (storage[i] != NULL && storage[i]->dup_func != NULL) if (!storage[i]->dup_func(to, from, &ptr, i, storage[i]->argl, storage[i]->argp)) goto err; CRYPTO_set_ex_data(to, i, ptr); } toret = 1; err: if (storage != stack) OPENSSL_free(storage); return toret; } struct ex_callback_entry { const EX_CALLBACK *excb; int index; }; static int ex_callback_compare(const void *a, const void *b) { const struct ex_callback_entry *ap = (const struct ex_callback_entry *)a; const struct ex_callback_entry *bp = (const struct ex_callback_entry *)b; if (ap->excb == bp->excb) return 0; if (ap->excb == NULL) return 1; if (bp->excb == NULL) return -1; if (ap->excb->priority == bp->excb->priority) return 0; return ap->excb->priority > bp->excb->priority ? -1 : 1; } /* * Cleanup a CRYPTO_EX_DATA variable - including calling free() callbacks for * each index in the class used by this variable */ void CRYPTO_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad) { int mx, i; EX_CALLBACKS *ip; void *ptr; const EX_CALLBACK *f; struct ex_callback_entry stack[10]; struct ex_callback_entry *storage = NULL; OSSL_EX_DATA_GLOBAL *global = ossl_lib_ctx_get_ex_data_global(ad->ctx); if (global == NULL) goto err; ip = get_and_lock(global, class_index); if (ip == NULL) goto err; mx = sk_EX_CALLBACK_num(ip->meth); if (mx > 0) { if (mx < (int)OSSL_NELEM(stack)) storage = stack; else storage = OPENSSL_malloc(sizeof(*storage) * mx); if (storage != NULL) for (i = 0; i < mx; i++) { storage[i].excb = sk_EX_CALLBACK_value(ip->meth, i); storage[i].index = i; } } CRYPTO_THREAD_unlock(global->ex_data_lock); if (storage != NULL) { /* Sort according to priority. High priority first */ qsort(storage, mx, sizeof(*storage), ex_callback_compare); for (i = 0; i < mx; i++) { f = storage[i].excb; if (f != NULL && f->free_func != NULL) { ptr = CRYPTO_get_ex_data(ad, storage[i].index); f->free_func(obj, ptr, ad, storage[i].index, f->argl, f->argp); } } } if (storage != stack) OPENSSL_free(storage); err: sk_void_free(ad->sk); ad->sk = NULL; ad->ctx = NULL; } /* * Allocate a given CRYPTO_EX_DATA item using the class specific allocation * function */ int CRYPTO_alloc_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad, int idx) { void *curval; curval = CRYPTO_get_ex_data(ad, idx); /* Already there, no need to allocate */ if (curval != NULL) return 1; return ossl_crypto_alloc_ex_data_intern(class_index, obj, ad, idx); } int ossl_crypto_alloc_ex_data_intern(int class_index, void *obj, CRYPTO_EX_DATA *ad, int idx) { EX_CALLBACK *f; EX_CALLBACKS *ip; OSSL_EX_DATA_GLOBAL *global; global = ossl_lib_ctx_get_ex_data_global(ad->ctx); if (global == NULL) return 0; ip = get_and_lock(global, class_index); if (ip == NULL) return 0; f = sk_EX_CALLBACK_value(ip->meth, idx); CRYPTO_THREAD_unlock(global->ex_data_lock); /* * This should end up calling CRYPTO_set_ex_data(), which allocates * everything necessary to support placing the new data in the right spot. */ if (f->new_func == NULL) return 0; f->new_func(obj, NULL, ad, idx, f->argl, f->argp); return 1; } /* * For a given CRYPTO_EX_DATA variable, set the value corresponding to a * particular index in the class used by this variable */ int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val) { int i; if (ad->sk == NULL) { if ((ad->sk = sk_void_new_null()) == NULL) { ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE); return 0; } } for (i = sk_void_num(ad->sk); i <= idx; ++i) { if (!sk_void_push(ad->sk, NULL)) { ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE); return 0; } } if (sk_void_set(ad->sk, idx, val) != val) { /* Probably the index is out of bounds */ ERR_raise(ERR_LIB_CRYPTO, ERR_R_PASSED_INVALID_ARGUMENT); return 0; } return 1; } /* * For a given CRYPTO_EX_DATA_ variable, get the value corresponding to a * particular index in the class used by this variable */ void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx) { if (ad->sk == NULL || idx >= sk_void_num(ad->sk)) return NULL; return sk_void_value(ad->sk, idx); } OSSL_LIB_CTX *ossl_crypto_ex_data_get_ossl_lib_ctx(const CRYPTO_EX_DATA *ad) { return ad->ctx; } diff --git a/crypto/openssl/crypto/ffc/ffc_key_validate.c b/crypto/openssl/crypto/ffc/ffc_key_validate.c index 342789621d6d..a4a2a58e9a7f 100644 --- a/crypto/openssl/crypto/ffc/ffc_key_validate.c +++ b/crypto/openssl/crypto/ffc/ffc_key_validate.c @@ -1,130 +1,124 @@ /* * Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ #include "internal/ffc.h" /* * See SP800-56Ar3 Section 5.6.2.3.1 : FFC Partial public key validation. * To only be used with ephemeral FFC public keys generated using the approved * safe-prime groups. (Checks that the public key is in the range [2, p - 1] * * ret contains 0 on success, or error flags (see FFC_ERROR_PUBKEY_TOO_SMALL) */ int ossl_ffc_validate_public_key_partial(const FFC_PARAMS *params, const BIGNUM *pub_key, int *ret) { int ok = 0; BIGNUM *tmp = NULL; BN_CTX *ctx = NULL; *ret = 0; if (params == NULL || pub_key == NULL || params->p == NULL) { *ret = FFC_ERROR_PASSED_NULL_PARAM; - return 0; + return 1; } ctx = BN_CTX_new_ex(NULL); if (ctx == NULL) goto err; BN_CTX_start(ctx); tmp = BN_CTX_get(ctx); /* Step(1): Verify pub_key >= 2 */ if (tmp == NULL || !BN_set_word(tmp, 1)) goto err; - if (BN_cmp(pub_key, tmp) <= 0) { + if (BN_cmp(pub_key, tmp) <= 0) *ret |= FFC_ERROR_PUBKEY_TOO_SMALL; - goto err; - } /* Step(1): Verify pub_key <= p-2 */ if (BN_copy(tmp, params->p) == NULL || !BN_sub_word(tmp, 1)) goto err; - if (BN_cmp(pub_key, tmp) >= 0) { + if (BN_cmp(pub_key, tmp) >= 0) *ret |= FFC_ERROR_PUBKEY_TOO_LARGE; - goto err; - } ok = 1; err: if (ctx != NULL) { BN_CTX_end(ctx); BN_CTX_free(ctx); } return ok; } /* * See SP800-56Ar3 Section 5.6.2.3.1 : FFC Full public key validation. */ int ossl_ffc_validate_public_key(const FFC_PARAMS *params, const BIGNUM *pub_key, int *ret) { int ok = 0; BIGNUM *tmp = NULL; BN_CTX *ctx = NULL; if (!ossl_ffc_validate_public_key_partial(params, pub_key, ret)) return 0; - if (params->q != NULL) { + if (*ret == 0 && params->q != NULL) { ctx = BN_CTX_new_ex(NULL); if (ctx == NULL) goto err; BN_CTX_start(ctx); tmp = BN_CTX_get(ctx); /* Check pub_key^q == 1 mod p */ if (tmp == NULL || !BN_mod_exp(tmp, pub_key, params->q, params->p, ctx)) goto err; - if (!BN_is_one(tmp)) { + if (!BN_is_one(tmp)) *ret |= FFC_ERROR_PUBKEY_INVALID; - goto err; - } } ok = 1; err: if (ctx != NULL) { BN_CTX_end(ctx); BN_CTX_free(ctx); } return ok; } /* * See SP800-56Ar3 Section 5.6.2.1.2: Owner assurance of Private key validity. * Verifies priv_key is in the range [1..upper-1]. The passed in value of upper * is normally params->q but can be 2^N for approved safe prime groups. * Note: This assumes that the domain parameters are valid. */ int ossl_ffc_validate_private_key(const BIGNUM *upper, const BIGNUM *priv, int *ret) { int ok = 0; *ret = 0; if (priv == NULL || upper == NULL) { *ret = FFC_ERROR_PASSED_NULL_PARAM; goto err; } if (BN_cmp(priv, BN_value_one()) < 0) { *ret |= FFC_ERROR_PRIVKEY_TOO_SMALL; goto err; } if (BN_cmp(priv, upper) >= 0) { *ret |= FFC_ERROR_PRIVKEY_TOO_LARGE; goto err; } ok = 1; err: return ok; } diff --git a/crypto/openssl/crypto/lhash/lhash.c b/crypto/openssl/crypto/lhash/lhash.c index 1cd988f01fc7..a01cfa725e38 100644 --- a/crypto/openssl/crypto/lhash/lhash.c +++ b/crypto/openssl/crypto/lhash/lhash.c @@ -1,387 +1,387 @@ /* - * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ #include #include #include #include #include #include #include "crypto/ctype.h" #include "crypto/lhash.h" #include "lhash_local.h" /* * A hashing implementation that appears to be based on the linear hashing * algorithm: * https://en.wikipedia.org/wiki/Linear_hashing * * Litwin, Witold (1980), "Linear hashing: A new tool for file and table * addressing", Proc. 6th Conference on Very Large Databases: 212-223 * https://hackthology.com/pdfs/Litwin-1980-Linear_Hashing.pdf * * From the Wikipedia article "Linear hashing is used in the BDB Berkeley * database system, which in turn is used by many software systems such as * OpenLDAP, using a C implementation derived from the CACM article and first * published on the Usenet in 1988 by Esmond Pitt." * * The CACM paper is available here: * https://pdfs.semanticscholar.org/ff4d/1c5deca6269cc316bfd952172284dbf610ee.pdf */ #undef MIN_NODES #define MIN_NODES 16 #define UP_LOAD (2*LH_LOAD_MULT) /* load times 256 (default 2) */ #define DOWN_LOAD (LH_LOAD_MULT) /* load times 256 (default 1) */ static int expand(OPENSSL_LHASH *lh); static void contract(OPENSSL_LHASH *lh); static OPENSSL_LH_NODE **getrn(OPENSSL_LHASH *lh, const void *data, unsigned long *rhash); OPENSSL_LHASH *OPENSSL_LH_new(OPENSSL_LH_HASHFUNC h, OPENSSL_LH_COMPFUNC c) { OPENSSL_LHASH *ret; if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) { /* * Do not set the error code, because the ERR code uses LHASH * and we want to avoid possible endless error loop. * ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE); */ return NULL; } if ((ret->b = OPENSSL_zalloc(sizeof(*ret->b) * MIN_NODES)) == NULL) goto err; ret->comp = ((c == NULL) ? (OPENSSL_LH_COMPFUNC)strcmp : c); ret->hash = ((h == NULL) ? (OPENSSL_LH_HASHFUNC)OPENSSL_LH_strhash : h); ret->num_nodes = MIN_NODES / 2; ret->num_alloc_nodes = MIN_NODES; ret->pmax = MIN_NODES / 2; ret->up_load = UP_LOAD; ret->down_load = DOWN_LOAD; return ret; err: OPENSSL_free(ret->b); OPENSSL_free(ret); return NULL; } void OPENSSL_LH_free(OPENSSL_LHASH *lh) { if (lh == NULL) return; OPENSSL_LH_flush(lh); OPENSSL_free(lh->b); OPENSSL_free(lh); } void OPENSSL_LH_flush(OPENSSL_LHASH *lh) { unsigned int i; OPENSSL_LH_NODE *n, *nn; if (lh == NULL) return; for (i = 0; i < lh->num_nodes; i++) { n = lh->b[i]; while (n != NULL) { nn = n->next; OPENSSL_free(n); n = nn; } lh->b[i] = NULL; } lh->num_items = 0; } void *OPENSSL_LH_insert(OPENSSL_LHASH *lh, void *data) { unsigned long hash; OPENSSL_LH_NODE *nn, **rn; void *ret; lh->error = 0; if ((lh->up_load <= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)) && !expand(lh)) return NULL; /* 'lh->error++' already done in 'expand' */ rn = getrn(lh, data, &hash); if (*rn == NULL) { if ((nn = OPENSSL_malloc(sizeof(*nn))) == NULL) { lh->error++; return NULL; } nn->data = data; nn->next = NULL; nn->hash = hash; *rn = nn; ret = NULL; lh->num_items++; } else { /* replace same key */ ret = (*rn)->data; (*rn)->data = data; } return ret; } void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data) { unsigned long hash; OPENSSL_LH_NODE *nn, **rn; void *ret; lh->error = 0; rn = getrn(lh, data, &hash); if (*rn == NULL) { return NULL; } else { nn = *rn; *rn = nn->next; ret = nn->data; OPENSSL_free(nn); } lh->num_items--; if ((lh->num_nodes > MIN_NODES) && (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes))) contract(lh); return ret; } void *OPENSSL_LH_retrieve(OPENSSL_LHASH *lh, const void *data) { unsigned long hash; OPENSSL_LH_NODE **rn; if (lh->error != 0) lh->error = 0; rn = getrn(lh, data, &hash); return *rn == NULL ? NULL : (*rn)->data; } static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg, OPENSSL_LH_DOALL_FUNC func, OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg) { int i; OPENSSL_LH_NODE *a, *n; if (lh == NULL) return; /* * reverse the order so we search from 'top to bottom' We were having * memory leaks otherwise */ for (i = lh->num_nodes - 1; i >= 0; i--) { a = lh->b[i]; while (a != NULL) { n = a->next; if (use_arg) func_arg(a->data, arg); else func(a->data); a = n; } } } void OPENSSL_LH_doall(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNC func) { doall_util_fn(lh, 0, func, (OPENSSL_LH_DOALL_FUNCARG)0, NULL); } void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void *arg) { doall_util_fn(lh, 1, (OPENSSL_LH_DOALL_FUNC)0, func, arg); } static int expand(OPENSSL_LHASH *lh) { OPENSSL_LH_NODE **n, **n1, **n2, *np; unsigned int p, pmax, nni, j; unsigned long hash; nni = lh->num_alloc_nodes; p = lh->p; pmax = lh->pmax; if (p + 1 >= pmax) { j = nni * 2; n = OPENSSL_realloc(lh->b, sizeof(OPENSSL_LH_NODE *) * j); if (n == NULL) { lh->error++; return 0; } lh->b = n; memset(n + nni, 0, sizeof(*n) * (j - nni)); lh->pmax = nni; lh->num_alloc_nodes = j; lh->p = 0; } else { lh->p++; } lh->num_nodes++; n1 = &(lh->b[p]); n2 = &(lh->b[p + pmax]); *n2 = NULL; for (np = *n1; np != NULL;) { hash = np->hash; if ((hash % nni) != p) { /* move it */ *n1 = (*n1)->next; np->next = *n2; *n2 = np; } else n1 = &((*n1)->next); np = *n1; } return 1; } static void contract(OPENSSL_LHASH *lh) { OPENSSL_LH_NODE **n, *n1, *np; np = lh->b[lh->p + lh->pmax - 1]; lh->b[lh->p + lh->pmax - 1] = NULL; /* 24/07-92 - eay - weird but :-( */ if (lh->p == 0) { n = OPENSSL_realloc(lh->b, (unsigned int)(sizeof(OPENSSL_LH_NODE *) * lh->pmax)); if (n == NULL) { /* fputs("realloc error in lhash",stderr); */ lh->error++; - return; + } else { + lh->b = n; } lh->num_alloc_nodes /= 2; lh->pmax /= 2; lh->p = lh->pmax - 1; - lh->b = n; } else lh->p--; lh->num_nodes--; n1 = lh->b[(int)lh->p]; if (n1 == NULL) lh->b[(int)lh->p] = np; else { while (n1->next != NULL) n1 = n1->next; n1->next = np; } } static OPENSSL_LH_NODE **getrn(OPENSSL_LHASH *lh, const void *data, unsigned long *rhash) { OPENSSL_LH_NODE **ret, *n1; unsigned long hash, nn; OPENSSL_LH_COMPFUNC cf; hash = (*(lh->hash)) (data); *rhash = hash; nn = hash % lh->pmax; if (nn < lh->p) nn = hash % lh->num_alloc_nodes; cf = lh->comp; ret = &(lh->b[(int)nn]); for (n1 = *ret; n1 != NULL; n1 = n1->next) { if (n1->hash != hash) { ret = &(n1->next); continue; } if (cf(n1->data, data) == 0) break; ret = &(n1->next); } return ret; } /* * The following hash seems to work very well on normal text strings no * collisions on /usr/dict/words and it distributes on %2^n quite well, not * as good as MD5, but still good. */ unsigned long OPENSSL_LH_strhash(const char *c) { unsigned long ret = 0; long n; unsigned long v; int r; if ((c == NULL) || (*c == '\0')) return ret; n = 0x100; while (*c) { v = n | (*c); n += 0x100; r = (int)((v >> 2) ^ v) & 0x0f; /* cast to uint64_t to avoid 32 bit shift of 32 bit value */ ret = (ret << r) | (unsigned long)((uint64_t)ret >> (32 - r)); ret &= 0xFFFFFFFFL; ret ^= v * v; c++; } return (ret >> 16) ^ ret; } unsigned long ossl_lh_strcasehash(const char *c) { unsigned long ret = 0; long n; unsigned long v; int r; if (c == NULL || *c == '\0') return ret; for (n = 0x100; *c != '\0'; n += 0x100) { v = n | ossl_tolower(*c); r = (int)((v >> 2) ^ v) & 0x0f; /* cast to uint64_t to avoid 32 bit shift of 32 bit value */ ret = (ret << r) | (unsigned long)((uint64_t)ret >> (32 - r)); ret &= 0xFFFFFFFFL; ret ^= v * v; c++; } return (ret >> 16) ^ ret; } unsigned long OPENSSL_LH_num_items(const OPENSSL_LHASH *lh) { return lh ? lh->num_items : 0; } unsigned long OPENSSL_LH_get_down_load(const OPENSSL_LHASH *lh) { return lh->down_load; } void OPENSSL_LH_set_down_load(OPENSSL_LHASH *lh, unsigned long down_load) { lh->down_load = down_load; } int OPENSSL_LH_error(OPENSSL_LHASH *lh) { return lh->error; } diff --git a/crypto/openssl/crypto/mem.c b/crypto/openssl/crypto/mem.c index bc9dc111676f..34128616e270 100644 --- a/crypto/openssl/crypto/mem.c +++ b/crypto/openssl/crypto/mem.c @@ -1,336 +1,342 @@ /* * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ #include "e_os.h" #include "internal/cryptlib.h" #include "crypto/cryptlib.h" #include #include #include #include /* * the following pointers may be changed as long as 'allow_customize' is set */ static int allow_customize = 1; static CRYPTO_malloc_fn malloc_impl = CRYPTO_malloc; static CRYPTO_realloc_fn realloc_impl = CRYPTO_realloc; static CRYPTO_free_fn free_impl = CRYPTO_free; #if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODULE) # include "internal/tsan_assist.h" # ifdef TSAN_REQUIRES_LOCKING # define INCREMENT(x) /* empty */ # define LOAD(x) 0 # else /* TSAN_REQUIRES_LOCKING */ static TSAN_QUALIFIER int malloc_count; static TSAN_QUALIFIER int realloc_count; static TSAN_QUALIFIER int free_count; # define INCREMENT(x) tsan_counter(&(x)) # define LOAD(x) tsan_load(&x) # endif /* TSAN_REQUIRES_LOCKING */ static char *md_failstring; static long md_count; static int md_fail_percent = 0; static int md_tracefd = -1; static void parseit(void); static int shouldfail(void); # define FAILTEST() if (shouldfail()) return NULL #else # define INCREMENT(x) /* empty */ # define FAILTEST() /* empty */ #endif int CRYPTO_set_mem_functions(CRYPTO_malloc_fn malloc_fn, CRYPTO_realloc_fn realloc_fn, CRYPTO_free_fn free_fn) { if (!allow_customize) return 0; if (malloc_fn != NULL) malloc_impl = malloc_fn; if (realloc_fn != NULL) realloc_impl = realloc_fn; if (free_fn != NULL) free_impl = free_fn; return 1; } void CRYPTO_get_mem_functions(CRYPTO_malloc_fn *malloc_fn, CRYPTO_realloc_fn *realloc_fn, CRYPTO_free_fn *free_fn) { if (malloc_fn != NULL) *malloc_fn = malloc_impl; if (realloc_fn != NULL) *realloc_fn = realloc_impl; if (free_fn != NULL) *free_fn = free_impl; } #if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODULE) void CRYPTO_get_alloc_counts(int *mcount, int *rcount, int *fcount) { if (mcount != NULL) *mcount = LOAD(malloc_count); if (rcount != NULL) *rcount = LOAD(realloc_count); if (fcount != NULL) *fcount = LOAD(free_count); } /* * Parse a "malloc failure spec" string. This likes like a set of fields * separated by semicolons. Each field has a count and an optional failure * percentage. For example: * 100@0;100@25;0@0 * or 100;100@25;0 * This means 100 mallocs succeed, then next 100 fail 25% of the time, and * all remaining (count is zero) succeed. + * The failure percentge can have 2 digits after the comma. For example: + * 0@0.01 + * This means 0.01% of all allocations will fail. */ static void parseit(void) { char *semi = strchr(md_failstring, ';'); char *atsign; if (semi != NULL) *semi++ = '\0'; /* Get the count (atol will stop at the @ if there), and percentage */ md_count = atol(md_failstring); atsign = strchr(md_failstring, '@'); - md_fail_percent = atsign == NULL ? 0 : atoi(atsign + 1); + md_fail_percent = atsign == NULL ? 0 : (int)(atof(atsign + 1) * 100 + 0.5); if (semi != NULL) md_failstring = semi; } /* - * Windows doesn't have random(), but it has rand() + * Windows doesn't have random() and srandom(), but it has rand() and srand(). * Some rand() implementations aren't good, but we're not * dealing with secure randomness here. */ # ifdef _WIN32 # define random() rand() +# define srandom(seed) srand(seed) # endif /* * See if the current malloc should fail. */ static int shouldfail(void) { - int roll = (int)(random() % 100); + int roll = (int)(random() % 10000); int shoulditfail = roll < md_fail_percent; # ifndef _WIN32 /* suppressed on Windows as POSIX-like file descriptors are non-inheritable */ int len; char buff[80]; if (md_tracefd > 0) { BIO_snprintf(buff, sizeof(buff), "%c C%ld %%%d R%d\n", shoulditfail ? '-' : '+', md_count, md_fail_percent, roll); len = strlen(buff); if (write(md_tracefd, buff, len) != len) perror("shouldfail write failed"); } # endif if (md_count) { /* If we used up this one, go to the next. */ if (--md_count == 0) parseit(); } return shoulditfail; } void ossl_malloc_setup_failures(void) { const char *cp = getenv("OPENSSL_MALLOC_FAILURES"); if (cp != NULL && (md_failstring = strdup(cp)) != NULL) parseit(); if ((cp = getenv("OPENSSL_MALLOC_FD")) != NULL) md_tracefd = atoi(cp); + if ((cp = getenv("OPENSSL_MALLOC_SEED")) != NULL) + srandom(atoi(cp)); } #endif void *CRYPTO_malloc(size_t num, const char *file, int line) { INCREMENT(malloc_count); if (malloc_impl != CRYPTO_malloc) return malloc_impl(num, file, line); if (num == 0) return NULL; FAILTEST(); if (allow_customize) { /* * Disallow customization after the first allocation. We only set this * if necessary to avoid a store to the same cache line on every * allocation. */ allow_customize = 0; } return malloc(num); } void *CRYPTO_zalloc(size_t num, const char *file, int line) { void *ret; ret = CRYPTO_malloc(num, file, line); if (ret != NULL) memset(ret, 0, num); return ret; } void *CRYPTO_realloc(void *str, size_t num, const char *file, int line) { INCREMENT(realloc_count); if (realloc_impl != CRYPTO_realloc) return realloc_impl(str, num, file, line); if (str == NULL) return CRYPTO_malloc(num, file, line); if (num == 0) { CRYPTO_free(str, file, line); return NULL; } FAILTEST(); return realloc(str, num); } void *CRYPTO_clear_realloc(void *str, size_t old_len, size_t num, const char *file, int line) { void *ret = NULL; if (str == NULL) return CRYPTO_malloc(num, file, line); if (num == 0) { CRYPTO_clear_free(str, old_len, file, line); return NULL; } /* Can't shrink the buffer since memcpy below copies |old_len| bytes. */ if (num < old_len) { OPENSSL_cleanse((char*)str + num, old_len - num); return str; } ret = CRYPTO_malloc(num, file, line); if (ret != NULL) { memcpy(ret, str, old_len); CRYPTO_clear_free(str, old_len, file, line); } return ret; } void CRYPTO_free(void *str, const char *file, int line) { INCREMENT(free_count); if (free_impl != CRYPTO_free) { free_impl(str, file, line); return; } free(str); } void CRYPTO_clear_free(void *str, size_t num, const char *file, int line) { if (str == NULL) return; if (num) OPENSSL_cleanse(str, num); CRYPTO_free(str, file, line); } #if !defined(OPENSSL_NO_CRYPTO_MDEBUG) # ifndef OPENSSL_NO_DEPRECATED_3_0 int CRYPTO_mem_ctrl(int mode) { (void)mode; return -1; } int CRYPTO_set_mem_debug(int flag) { (void)flag; return -1; } int CRYPTO_mem_debug_push(const char *info, const char *file, int line) { (void)info; (void)file; (void)line; return 0; } int CRYPTO_mem_debug_pop(void) { return 0; } void CRYPTO_mem_debug_malloc(void *addr, size_t num, int flag, const char *file, int line) { (void)addr; (void)num; (void)flag; (void)file; (void)line; } void CRYPTO_mem_debug_realloc(void *addr1, void *addr2, size_t num, int flag, const char *file, int line) { (void)addr1; (void)addr2; (void)num; (void)flag; (void)file; (void)line; } void CRYPTO_mem_debug_free(void *addr, int flag, const char *file, int line) { (void)addr; (void)flag; (void)file; (void)line; } int CRYPTO_mem_leaks(BIO *b) { (void)b; return -1; } # ifndef OPENSSL_NO_STDIO int CRYPTO_mem_leaks_fp(FILE *fp) { (void)fp; return -1; } # endif int CRYPTO_mem_leaks_cb(int (*cb)(const char *str, size_t len, void *u), void *u) { (void)cb; (void)u; return -1; } # endif #endif diff --git a/crypto/openssl/crypto/modes/asm/ghashv8-armx.pl b/crypto/openssl/crypto/modes/asm/ghashv8-armx.pl index b1d35d25b5b1..b3d94041729e 100644 --- a/crypto/openssl/crypto/modes/asm/ghashv8-armx.pl +++ b/crypto/openssl/crypto/modes/asm/ghashv8-armx.pl @@ -1,797 +1,800 @@ #! /usr/bin/env perl -# Copyright 2014-2020 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 2014-2023 The OpenSSL Project Authors. All Rights Reserved. # # Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy # in the file LICENSE in the source distribution or at # https://www.openssl.org/source/license.html # # ==================================================================== # Written by Andy Polyakov for the OpenSSL # project. The module is, however, dual licensed under OpenSSL and # CRYPTOGAMS licenses depending on where you obtain it. For further # details see http://www.openssl.org/~appro/cryptogams/. # ==================================================================== # # GHASH for ARMv8 Crypto Extension, 64-bit polynomial multiplication. # # June 2014 # # Initial version was developed in tight cooperation with Ard # Biesheuvel of Linaro from bits-n-pieces from other assembly modules. # Just like aesv8-armx.pl this module supports both AArch32 and # AArch64 execution modes. # # July 2014 # # Implement 2x aggregated reduction [see ghash-x86.pl for background # information]. # # November 2017 # # AArch64 register bank to "accommodate" 4x aggregated reduction and # improve performance by 20-70% depending on processor. # # Current performance in cycles per processed byte: # # 64-bit PMULL 32-bit PMULL 32-bit NEON(*) # Apple A7 0.58 0.92 5.62 # Cortex-A53 0.85 1.01 8.39 # Cortex-A57 0.73 1.17 7.61 # Denver 0.51 0.65 6.02 # Mongoose 0.65 1.10 8.06 # Kryo 0.76 1.16 8.00 # ThunderX2 1.05 # # (*) presented for reference/comparison purposes; # $output is the last argument if it looks like a file (it has an extension) # $flavour is the first argument if it doesn't look like a file $output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef; $flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef; $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1; ( $xlate="${dir}arm-xlate.pl" and -f $xlate ) or ( $xlate="${dir}../../perlasm/arm-xlate.pl" and -f $xlate) or die "can't locate arm-xlate.pl"; open OUT,"| \"$^X\" $xlate $flavour \"$output\"" or die "can't call $xlate: $!"; *STDOUT=*OUT; $Xi="x0"; # argument block $Htbl="x1"; $inp="x2"; $len="x3"; $inc="x12"; { my ($Xl,$Xm,$Xh,$IN)=map("q$_",(0..3)); my ($t0,$t1,$t2,$xC2,$H,$Hhl,$H2)=map("q$_",(8..14)); my $_byte = ($flavour =~ /win/ ? "DCB" : ".byte"); $code=<<___; #include "arm_arch.h" #if __ARM_MAX_ARCH__>=7 ___ $code.=".arch armv8-a+crypto\n.text\n" if ($flavour =~ /64/); $code.=<<___ if ($flavour !~ /64/); .fpu neon #ifdef __thumb2__ .syntax unified .thumb # define INST(a,b,c,d) $_byte c,0xef,a,b #else .code 32 # define INST(a,b,c,d) $_byte a,b,c,0xf2 #endif .text ___ ################################################################################ # void gcm_init_v8(u128 Htable[16],const u64 H[2]); # # input: 128-bit H - secret parameter E(K,0^128) # output: precomputed table filled with degrees of twisted H; # H is twisted to handle reverse bitness of GHASH; # only few of 16 slots of Htable[16] are used; # data is opaque to outside world (which allows to # optimize the code independently); # $code.=<<___; .global gcm_init_v8 .type gcm_init_v8,%function .align 4 gcm_init_v8: vld1.64 {$t1},[x1] @ load input H vmov.i8 $xC2,#0xe1 vshl.i64 $xC2,$xC2,#57 @ 0xc2.0 vext.8 $IN,$t1,$t1,#8 vshr.u64 $t2,$xC2,#63 vdup.32 $t1,${t1}[1] vext.8 $t0,$t2,$xC2,#8 @ t0=0xc2....01 vshr.u64 $t2,$IN,#63 vshr.s32 $t1,$t1,#31 @ broadcast carry bit vand $t2,$t2,$t0 vshl.i64 $IN,$IN,#1 vext.8 $t2,$t2,$t2,#8 vand $t0,$t0,$t1 vorr $IN,$IN,$t2 @ H<<<=1 veor $H,$IN,$t0 @ twisted H vst1.64 {$H},[x0],#16 @ store Htable[0] @ calculate H^2 vext.8 $t0,$H,$H,#8 @ Karatsuba pre-processing vpmull.p64 $Xl,$H,$H veor $t0,$t0,$H vpmull2.p64 $Xh,$H,$H vpmull.p64 $Xm,$t0,$t0 vext.8 $t1,$Xl,$Xh,#8 @ Karatsuba post-processing veor $t2,$Xl,$Xh veor $Xm,$Xm,$t1 veor $Xm,$Xm,$t2 vpmull.p64 $t2,$Xl,$xC2 @ 1st phase vmov $Xh#lo,$Xm#hi @ Xh|Xm - 256-bit result vmov $Xm#hi,$Xl#lo @ Xm is rotated Xl veor $Xl,$Xm,$t2 vext.8 $t2,$Xl,$Xl,#8 @ 2nd phase vpmull.p64 $Xl,$Xl,$xC2 veor $t2,$t2,$Xh veor $H2,$Xl,$t2 vext.8 $t1,$H2,$H2,#8 @ Karatsuba pre-processing veor $t1,$t1,$H2 vext.8 $Hhl,$t0,$t1,#8 @ pack Karatsuba pre-processed vst1.64 {$Hhl-$H2},[x0],#32 @ store Htable[1..2] ___ if ($flavour =~ /64/) { my ($t3,$Yl,$Ym,$Yh) = map("q$_",(4..7)); $code.=<<___; @ calculate H^3 and H^4 vpmull.p64 $Xl,$H, $H2 vpmull.p64 $Yl,$H2,$H2 vpmull2.p64 $Xh,$H, $H2 vpmull2.p64 $Yh,$H2,$H2 vpmull.p64 $Xm,$t0,$t1 vpmull.p64 $Ym,$t1,$t1 vext.8 $t0,$Xl,$Xh,#8 @ Karatsuba post-processing vext.8 $t1,$Yl,$Yh,#8 veor $t2,$Xl,$Xh veor $Xm,$Xm,$t0 veor $t3,$Yl,$Yh veor $Ym,$Ym,$t1 veor $Xm,$Xm,$t2 vpmull.p64 $t2,$Xl,$xC2 @ 1st phase veor $Ym,$Ym,$t3 vpmull.p64 $t3,$Yl,$xC2 vmov $Xh#lo,$Xm#hi @ Xh|Xm - 256-bit result vmov $Yh#lo,$Ym#hi vmov $Xm#hi,$Xl#lo @ Xm is rotated Xl vmov $Ym#hi,$Yl#lo veor $Xl,$Xm,$t2 veor $Yl,$Ym,$t3 vext.8 $t2,$Xl,$Xl,#8 @ 2nd phase vext.8 $t3,$Yl,$Yl,#8 vpmull.p64 $Xl,$Xl,$xC2 vpmull.p64 $Yl,$Yl,$xC2 veor $t2,$t2,$Xh veor $t3,$t3,$Yh veor $H, $Xl,$t2 @ H^3 veor $H2,$Yl,$t3 @ H^4 vext.8 $t0,$H, $H,#8 @ Karatsuba pre-processing vext.8 $t1,$H2,$H2,#8 veor $t0,$t0,$H veor $t1,$t1,$H2 vext.8 $Hhl,$t0,$t1,#8 @ pack Karatsuba pre-processed vst1.64 {$H-$H2},[x0] @ store Htable[3..5] ___ } $code.=<<___; ret .size gcm_init_v8,.-gcm_init_v8 ___ ################################################################################ # void gcm_gmult_v8(u64 Xi[2],const u128 Htable[16]); # # input: Xi - current hash value; # Htable - table precomputed in gcm_init_v8; # output: Xi - next hash value Xi; # $code.=<<___; .global gcm_gmult_v8 .type gcm_gmult_v8,%function .align 4 gcm_gmult_v8: vld1.64 {$t1},[$Xi] @ load Xi vmov.i8 $xC2,#0xe1 vld1.64 {$H-$Hhl},[$Htbl] @ load twisted H, ... vshl.u64 $xC2,$xC2,#57 #ifndef __ARMEB__ vrev64.8 $t1,$t1 #endif vext.8 $IN,$t1,$t1,#8 vpmull.p64 $Xl,$H,$IN @ H.lo·Xi.lo veor $t1,$t1,$IN @ Karatsuba pre-processing vpmull2.p64 $Xh,$H,$IN @ H.hi·Xi.hi vpmull.p64 $Xm,$Hhl,$t1 @ (H.lo+H.hi)·(Xi.lo+Xi.hi) vext.8 $t1,$Xl,$Xh,#8 @ Karatsuba post-processing veor $t2,$Xl,$Xh veor $Xm,$Xm,$t1 veor $Xm,$Xm,$t2 vpmull.p64 $t2,$Xl,$xC2 @ 1st phase of reduction vmov $Xh#lo,$Xm#hi @ Xh|Xm - 256-bit result vmov $Xm#hi,$Xl#lo @ Xm is rotated Xl veor $Xl,$Xm,$t2 vext.8 $t2,$Xl,$Xl,#8 @ 2nd phase of reduction vpmull.p64 $Xl,$Xl,$xC2 veor $t2,$t2,$Xh veor $Xl,$Xl,$t2 #ifndef __ARMEB__ vrev64.8 $Xl,$Xl #endif vext.8 $Xl,$Xl,$Xl,#8 vst1.64 {$Xl},[$Xi] @ write out Xi ret .size gcm_gmult_v8,.-gcm_gmult_v8 ___ ################################################################################ # void gcm_ghash_v8(u64 Xi[2],const u128 Htable[16],const u8 *inp,size_t len); # # input: table precomputed in gcm_init_v8; # current hash value Xi; # pointer to input data; # length of input data in bytes, but divisible by block size; # output: next hash value Xi; # $code.=<<___; .global gcm_ghash_v8 .type gcm_ghash_v8,%function .align 4 gcm_ghash_v8: ___ $code.=<<___ if ($flavour =~ /64/); cmp $len,#64 b.hs .Lgcm_ghash_v8_4x ___ $code.=<<___ if ($flavour !~ /64/); vstmdb sp!,{d8-d15} @ 32-bit ABI says so ___ $code.=<<___; vld1.64 {$Xl},[$Xi] @ load [rotated] Xi @ "[rotated]" means that @ loaded value would have @ to be rotated in order to @ make it appear as in @ algorithm specification subs $len,$len,#32 @ see if $len is 32 or larger mov $inc,#16 @ $inc is used as post- @ increment for input pointer; @ as loop is modulo-scheduled @ $inc is zeroed just in time @ to preclude overstepping @ inp[len], which means that @ last block[s] are actually @ loaded twice, but last @ copy is not processed vld1.64 {$H-$Hhl},[$Htbl],#32 @ load twisted H, ..., H^2 vmov.i8 $xC2,#0xe1 vld1.64 {$H2},[$Htbl] cclr $inc,eq @ is it time to zero $inc? vext.8 $Xl,$Xl,$Xl,#8 @ rotate Xi vld1.64 {$t0},[$inp],#16 @ load [rotated] I[0] vshl.u64 $xC2,$xC2,#57 @ compose 0xc2.0 constant #ifndef __ARMEB__ vrev64.8 $t0,$t0 vrev64.8 $Xl,$Xl #endif vext.8 $IN,$t0,$t0,#8 @ rotate I[0] b.lo .Lodd_tail_v8 @ $len was less than 32 ___ { my ($Xln,$Xmn,$Xhn,$In) = map("q$_",(4..7)); ####### # Xi+2 =[H*(Ii+1 + Xi+1)] mod P = # [(H*Ii+1) + (H*Xi+1)] mod P = # [(H*Ii+1) + H^2*(Ii+Xi)] mod P # $code.=<<___; vld1.64 {$t1},[$inp],$inc @ load [rotated] I[1] #ifndef __ARMEB__ vrev64.8 $t1,$t1 #endif vext.8 $In,$t1,$t1,#8 veor $IN,$IN,$Xl @ I[i]^=Xi vpmull.p64 $Xln,$H,$In @ H·Ii+1 veor $t1,$t1,$In @ Karatsuba pre-processing vpmull2.p64 $Xhn,$H,$In b .Loop_mod2x_v8 .align 4 .Loop_mod2x_v8: vext.8 $t2,$IN,$IN,#8 subs $len,$len,#32 @ is there more data? vpmull.p64 $Xl,$H2,$IN @ H^2.lo·Xi.lo cclr $inc,lo @ is it time to zero $inc? vpmull.p64 $Xmn,$Hhl,$t1 veor $t2,$t2,$IN @ Karatsuba pre-processing vpmull2.p64 $Xh,$H2,$IN @ H^2.hi·Xi.hi veor $Xl,$Xl,$Xln @ accumulate vpmull2.p64 $Xm,$Hhl,$t2 @ (H^2.lo+H^2.hi)·(Xi.lo+Xi.hi) vld1.64 {$t0},[$inp],$inc @ load [rotated] I[i+2] veor $Xh,$Xh,$Xhn cclr $inc,eq @ is it time to zero $inc? veor $Xm,$Xm,$Xmn vext.8 $t1,$Xl,$Xh,#8 @ Karatsuba post-processing veor $t2,$Xl,$Xh veor $Xm,$Xm,$t1 vld1.64 {$t1},[$inp],$inc @ load [rotated] I[i+3] #ifndef __ARMEB__ vrev64.8 $t0,$t0 #endif veor $Xm,$Xm,$t2 vpmull.p64 $t2,$Xl,$xC2 @ 1st phase of reduction #ifndef __ARMEB__ vrev64.8 $t1,$t1 #endif vmov $Xh#lo,$Xm#hi @ Xh|Xm - 256-bit result vmov $Xm#hi,$Xl#lo @ Xm is rotated Xl vext.8 $In,$t1,$t1,#8 vext.8 $IN,$t0,$t0,#8 veor $Xl,$Xm,$t2 vpmull.p64 $Xln,$H,$In @ H·Ii+1 veor $IN,$IN,$Xh @ accumulate $IN early vext.8 $t2,$Xl,$Xl,#8 @ 2nd phase of reduction vpmull.p64 $Xl,$Xl,$xC2 veor $IN,$IN,$t2 veor $t1,$t1,$In @ Karatsuba pre-processing veor $IN,$IN,$Xl vpmull2.p64 $Xhn,$H,$In b.hs .Loop_mod2x_v8 @ there was at least 32 more bytes veor $Xh,$Xh,$t2 vext.8 $IN,$t0,$t0,#8 @ re-construct $IN adds $len,$len,#32 @ re-construct $len veor $Xl,$Xl,$Xh @ re-construct $Xl b.eq .Ldone_v8 @ is $len zero? ___ } $code.=<<___; .Lodd_tail_v8: vext.8 $t2,$Xl,$Xl,#8 veor $IN,$IN,$Xl @ inp^=Xi veor $t1,$t0,$t2 @ $t1 is rotated inp^Xi vpmull.p64 $Xl,$H,$IN @ H.lo·Xi.lo veor $t1,$t1,$IN @ Karatsuba pre-processing vpmull2.p64 $Xh,$H,$IN @ H.hi·Xi.hi vpmull.p64 $Xm,$Hhl,$t1 @ (H.lo+H.hi)·(Xi.lo+Xi.hi) vext.8 $t1,$Xl,$Xh,#8 @ Karatsuba post-processing veor $t2,$Xl,$Xh veor $Xm,$Xm,$t1 veor $Xm,$Xm,$t2 vpmull.p64 $t2,$Xl,$xC2 @ 1st phase of reduction vmov $Xh#lo,$Xm#hi @ Xh|Xm - 256-bit result vmov $Xm#hi,$Xl#lo @ Xm is rotated Xl veor $Xl,$Xm,$t2 vext.8 $t2,$Xl,$Xl,#8 @ 2nd phase of reduction vpmull.p64 $Xl,$Xl,$xC2 veor $t2,$t2,$Xh veor $Xl,$Xl,$t2 .Ldone_v8: #ifndef __ARMEB__ vrev64.8 $Xl,$Xl #endif vext.8 $Xl,$Xl,$Xl,#8 vst1.64 {$Xl},[$Xi] @ write out Xi ___ $code.=<<___ if ($flavour !~ /64/); vldmia sp!,{d8-d15} @ 32-bit ABI says so ___ $code.=<<___; ret .size gcm_ghash_v8,.-gcm_ghash_v8 ___ if ($flavour =~ /64/) { # 4x subroutine my ($I0,$j1,$j2,$j3, $I1,$I2,$I3,$H3,$H34,$H4,$Yl,$Ym,$Yh) = map("q$_",(4..7,15..23)); $code.=<<___; .type gcm_ghash_v8_4x,%function .align 4 gcm_ghash_v8_4x: .Lgcm_ghash_v8_4x: vld1.64 {$Xl},[$Xi] @ load [rotated] Xi vld1.64 {$H-$H2},[$Htbl],#48 @ load twisted H, ..., H^2 vmov.i8 $xC2,#0xe1 vld1.64 {$H3-$H4},[$Htbl] @ load twisted H^3, ..., H^4 vshl.u64 $xC2,$xC2,#57 @ compose 0xc2.0 constant vld1.64 {$I0-$j3},[$inp],#64 #ifndef __ARMEB__ vrev64.8 $Xl,$Xl vrev64.8 $j1,$j1 vrev64.8 $j2,$j2 vrev64.8 $j3,$j3 vrev64.8 $I0,$I0 #endif vext.8 $I3,$j3,$j3,#8 vext.8 $I2,$j2,$j2,#8 vext.8 $I1,$j1,$j1,#8 vpmull.p64 $Yl,$H,$I3 @ H·Ii+3 veor $j3,$j3,$I3 vpmull2.p64 $Yh,$H,$I3 vpmull.p64 $Ym,$Hhl,$j3 vpmull.p64 $t0,$H2,$I2 @ H^2·Ii+2 veor $j2,$j2,$I2 vpmull2.p64 $I2,$H2,$I2 vpmull2.p64 $j2,$Hhl,$j2 veor $Yl,$Yl,$t0 veor $Yh,$Yh,$I2 veor $Ym,$Ym,$j2 vpmull.p64 $j3,$H3,$I1 @ H^3·Ii+1 veor $j1,$j1,$I1 vpmull2.p64 $I1,$H3,$I1 vpmull.p64 $j1,$H34,$j1 veor $Yl,$Yl,$j3 veor $Yh,$Yh,$I1 veor $Ym,$Ym,$j1 subs $len,$len,#128 b.lo .Ltail4x b .Loop4x .align 4 .Loop4x: veor $t0,$I0,$Xl vld1.64 {$I0-$j3},[$inp],#64 vext.8 $IN,$t0,$t0,#8 #ifndef __ARMEB__ vrev64.8 $j1,$j1 vrev64.8 $j2,$j2 vrev64.8 $j3,$j3 vrev64.8 $I0,$I0 #endif vpmull.p64 $Xl,$H4,$IN @ H^4·(Xi+Ii) veor $t0,$t0,$IN vpmull2.p64 $Xh,$H4,$IN vext.8 $I3,$j3,$j3,#8 vpmull2.p64 $Xm,$H34,$t0 veor $Xl,$Xl,$Yl veor $Xh,$Xh,$Yh vext.8 $I2,$j2,$j2,#8 veor $Xm,$Xm,$Ym vext.8 $I1,$j1,$j1,#8 vext.8 $t1,$Xl,$Xh,#8 @ Karatsuba post-processing veor $t2,$Xl,$Xh vpmull.p64 $Yl,$H,$I3 @ H·Ii+3 veor $j3,$j3,$I3 veor $Xm,$Xm,$t1 vpmull2.p64 $Yh,$H,$I3 veor $Xm,$Xm,$t2 vpmull.p64 $Ym,$Hhl,$j3 vpmull.p64 $t2,$Xl,$xC2 @ 1st phase of reduction vmov $Xh#lo,$Xm#hi @ Xh|Xm - 256-bit result vmov $Xm#hi,$Xl#lo @ Xm is rotated Xl vpmull.p64 $t0,$H2,$I2 @ H^2·Ii+2 veor $j2,$j2,$I2 vpmull2.p64 $I2,$H2,$I2 veor $Xl,$Xm,$t2 vpmull2.p64 $j2,$Hhl,$j2 veor $Yl,$Yl,$t0 veor $Yh,$Yh,$I2 veor $Ym,$Ym,$j2 vext.8 $t2,$Xl,$Xl,#8 @ 2nd phase of reduction vpmull.p64 $Xl,$Xl,$xC2 vpmull.p64 $j3,$H3,$I1 @ H^3·Ii+1 veor $j1,$j1,$I1 veor $t2,$t2,$Xh vpmull2.p64 $I1,$H3,$I1 vpmull.p64 $j1,$H34,$j1 veor $Xl,$Xl,$t2 veor $Yl,$Yl,$j3 veor $Yh,$Yh,$I1 vext.8 $Xl,$Xl,$Xl,#8 veor $Ym,$Ym,$j1 subs $len,$len,#64 b.hs .Loop4x .Ltail4x: veor $t0,$I0,$Xl vext.8 $IN,$t0,$t0,#8 vpmull.p64 $Xl,$H4,$IN @ H^4·(Xi+Ii) veor $t0,$t0,$IN vpmull2.p64 $Xh,$H4,$IN vpmull2.p64 $Xm,$H34,$t0 veor $Xl,$Xl,$Yl veor $Xh,$Xh,$Yh veor $Xm,$Xm,$Ym adds $len,$len,#64 b.eq .Ldone4x cmp $len,#32 b.lo .Lone b.eq .Ltwo .Lthree: vext.8 $t1,$Xl,$Xh,#8 @ Karatsuba post-processing veor $t2,$Xl,$Xh veor $Xm,$Xm,$t1 vld1.64 {$I0-$j2},[$inp] veor $Xm,$Xm,$t2 #ifndef __ARMEB__ vrev64.8 $j1,$j1 vrev64.8 $j2,$j2 vrev64.8 $I0,$I0 #endif vpmull.p64 $t2,$Xl,$xC2 @ 1st phase of reduction vmov $Xh#lo,$Xm#hi @ Xh|Xm - 256-bit result vmov $Xm#hi,$Xl#lo @ Xm is rotated Xl vext.8 $I2,$j2,$j2,#8 vext.8 $I1,$j1,$j1,#8 veor $Xl,$Xm,$t2 vpmull.p64 $Yl,$H,$I2 @ H·Ii+2 veor $j2,$j2,$I2 vext.8 $t2,$Xl,$Xl,#8 @ 2nd phase of reduction vpmull.p64 $Xl,$Xl,$xC2 veor $t2,$t2,$Xh vpmull2.p64 $Yh,$H,$I2 vpmull.p64 $Ym,$Hhl,$j2 veor $Xl,$Xl,$t2 vpmull.p64 $j3,$H2,$I1 @ H^2·Ii+1 veor $j1,$j1,$I1 vext.8 $Xl,$Xl,$Xl,#8 vpmull2.p64 $I1,$H2,$I1 veor $t0,$I0,$Xl vpmull2.p64 $j1,$Hhl,$j1 vext.8 $IN,$t0,$t0,#8 veor $Yl,$Yl,$j3 veor $Yh,$Yh,$I1 veor $Ym,$Ym,$j1 vpmull.p64 $Xl,$H3,$IN @ H^3·(Xi+Ii) veor $t0,$t0,$IN vpmull2.p64 $Xh,$H3,$IN vpmull.p64 $Xm,$H34,$t0 veor $Xl,$Xl,$Yl veor $Xh,$Xh,$Yh veor $Xm,$Xm,$Ym b .Ldone4x .align 4 .Ltwo: vext.8 $t1,$Xl,$Xh,#8 @ Karatsuba post-processing veor $t2,$Xl,$Xh veor $Xm,$Xm,$t1 vld1.64 {$I0-$j1},[$inp] veor $Xm,$Xm,$t2 #ifndef __ARMEB__ vrev64.8 $j1,$j1 vrev64.8 $I0,$I0 #endif vpmull.p64 $t2,$Xl,$xC2 @ 1st phase of reduction vmov $Xh#lo,$Xm#hi @ Xh|Xm - 256-bit result vmov $Xm#hi,$Xl#lo @ Xm is rotated Xl vext.8 $I1,$j1,$j1,#8 veor $Xl,$Xm,$t2 vext.8 $t2,$Xl,$Xl,#8 @ 2nd phase of reduction vpmull.p64 $Xl,$Xl,$xC2 veor $t2,$t2,$Xh veor $Xl,$Xl,$t2 vext.8 $Xl,$Xl,$Xl,#8 vpmull.p64 $Yl,$H,$I1 @ H·Ii+1 veor $j1,$j1,$I1 veor $t0,$I0,$Xl vext.8 $IN,$t0,$t0,#8 vpmull2.p64 $Yh,$H,$I1 vpmull.p64 $Ym,$Hhl,$j1 vpmull.p64 $Xl,$H2,$IN @ H^2·(Xi+Ii) veor $t0,$t0,$IN vpmull2.p64 $Xh,$H2,$IN vpmull2.p64 $Xm,$Hhl,$t0 veor $Xl,$Xl,$Yl veor $Xh,$Xh,$Yh veor $Xm,$Xm,$Ym b .Ldone4x .align 4 .Lone: vext.8 $t1,$Xl,$Xh,#8 @ Karatsuba post-processing veor $t2,$Xl,$Xh veor $Xm,$Xm,$t1 vld1.64 {$I0},[$inp] veor $Xm,$Xm,$t2 #ifndef __ARMEB__ vrev64.8 $I0,$I0 #endif vpmull.p64 $t2,$Xl,$xC2 @ 1st phase of reduction vmov $Xh#lo,$Xm#hi @ Xh|Xm - 256-bit result vmov $Xm#hi,$Xl#lo @ Xm is rotated Xl veor $Xl,$Xm,$t2 vext.8 $t2,$Xl,$Xl,#8 @ 2nd phase of reduction vpmull.p64 $Xl,$Xl,$xC2 veor $t2,$t2,$Xh veor $Xl,$Xl,$t2 vext.8 $Xl,$Xl,$Xl,#8 veor $t0,$I0,$Xl vext.8 $IN,$t0,$t0,#8 vpmull.p64 $Xl,$H,$IN veor $t0,$t0,$IN vpmull2.p64 $Xh,$H,$IN vpmull.p64 $Xm,$Hhl,$t0 .Ldone4x: vext.8 $t1,$Xl,$Xh,#8 @ Karatsuba post-processing veor $t2,$Xl,$Xh veor $Xm,$Xm,$t1 veor $Xm,$Xm,$t2 vpmull.p64 $t2,$Xl,$xC2 @ 1st phase of reduction vmov $Xh#lo,$Xm#hi @ Xh|Xm - 256-bit result vmov $Xm#hi,$Xl#lo @ Xm is rotated Xl veor $Xl,$Xm,$t2 vext.8 $t2,$Xl,$Xl,#8 @ 2nd phase of reduction vpmull.p64 $Xl,$Xl,$xC2 veor $t2,$t2,$Xh veor $Xl,$Xl,$t2 vext.8 $Xl,$Xl,$Xl,#8 #ifndef __ARMEB__ vrev64.8 $Xl,$Xl #endif vst1.64 {$Xl},[$Xi] @ write out Xi ret .size gcm_ghash_v8_4x,.-gcm_ghash_v8_4x ___ } } $code.=<<___; .asciz "GHASH for ARMv8, CRYPTOGAMS by " .align 2 #endif ___ if ($flavour =~ /64/) { ######## 64-bit code sub unvmov { my $arg=shift; $arg =~ m/q([0-9]+)#(lo|hi),\s*q([0-9]+)#(lo|hi)/o && sprintf "ins v%d.d[%d],v%d.d[%d]",$1<8?$1:$1+8,($2 eq "lo")?0:1, $3<8?$3:$3+8,($4 eq "lo")?0:1; } foreach(split("\n",$code)) { s/cclr\s+([wx])([^,]+),\s*([a-z]+)/csel $1$2,$1zr,$1$2,$3/o or s/vmov\.i8/movi/o or # fix up legacy mnemonics s/vmov\s+(.*)/unvmov($1)/geo or s/vext\.8/ext/o or s/vshr\.s/sshr\.s/o or s/vshr/ushr/o or s/^(\s+)v/$1/o or # strip off v prefix s/\bbx\s+lr\b/ret/o; s/\bq([0-9]+)\b/"v".($1<8?$1:$1+8).".16b"/geo; # old->new registers s/@\s/\/\//o; # old->new style commentary # fix up remaining legacy suffixes s/\.[ui]?8(\s)/$1/o; s/\.[uis]?32//o and s/\.16b/\.4s/go; m/\.p64/o and s/\.16b/\.1q/o; # 1st pmull argument m/l\.p64/o and s/\.16b/\.1d/go; # 2nd and 3rd pmull arguments s/\.[uisp]?64//o and s/\.16b/\.2d/go; s/\.[42]([sd])\[([0-3])\]/\.$1\[$2\]/o; + # Switch preprocessor checks to aarch64 versions. + s/__ARME([BL])__/__AARCH64E$1__/go; + print $_,"\n"; } } else { ######## 32-bit code sub unvdup32 { my $arg=shift; $arg =~ m/q([0-9]+),\s*q([0-9]+)\[([0-3])\]/o && sprintf "vdup.32 q%d,d%d[%d]",$1,2*$2+($3>>1),$3&1; } sub unvpmullp64 { my ($mnemonic,$arg)=@_; if ($arg =~ m/q([0-9]+),\s*q([0-9]+),\s*q([0-9]+)/o) { my $word = 0xf2a00e00|(($1&7)<<13)|(($1&8)<<19) |(($2&7)<<17)|(($2&8)<<4) |(($3&7)<<1) |(($3&8)<<2); $word |= 0x00010001 if ($mnemonic =~ "2"); # since ARMv7 instructions are always encoded little-endian. # correct solution is to use .inst directive, but older # assemblers don't implement it:-( sprintf "INST(0x%02x,0x%02x,0x%02x,0x%02x)\t@ %s %s", $word&0xff,($word>>8)&0xff, ($word>>16)&0xff,($word>>24)&0xff, $mnemonic,$arg; } } foreach(split("\n",$code)) { s/\b[wx]([0-9]+)\b/r$1/go; # new->old registers s/\bv([0-9])\.[12468]+[bsd]\b/q$1/go; # new->old registers s/\/\/\s?/@ /o; # new->old style commentary # fix up remaining new-style suffixes s/\],#[0-9]+/]!/o; s/cclr\s+([^,]+),\s*([a-z]+)/mov.$2 $1,#0/o or s/vdup\.32\s+(.*)/unvdup32($1)/geo or s/v?(pmull2?)\.p64\s+(.*)/unvpmullp64($1,$2)/geo or s/\bq([0-9]+)#(lo|hi)/sprintf "d%d",2*$1+($2 eq "hi")/geo or s/^(\s+)b\./$1b/o or s/^(\s+)ret/$1bx\tlr/o; if (s/^(\s+)mov\.([a-z]+)/$1mov$2/) { print " it $2\n"; } print $_,"\n"; } } close STDOUT or die "error closing STDOUT: $!"; # enforce flush diff --git a/crypto/openssl/crypto/objects/obj_dat.c b/crypto/openssl/crypto/objects/obj_dat.c index 1a52000e6e9d..85d30eb58ae0 100644 --- a/crypto/openssl/crypto/objects/obj_dat.c +++ b/crypto/openssl/crypto/objects/obj_dat.c @@ -1,763 +1,764 @@ /* * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ #include #include "crypto/ctype.h" #include #include "internal/cryptlib.h" #include #include #include "crypto/objects.h" #include #include "crypto/asn1.h" #include "obj_local.h" /* obj_dat.h is generated from objects.h by obj_dat.pl */ #include "obj_dat.h" DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, sn); DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, ln); DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, obj); #define ADDED_DATA 0 #define ADDED_SNAME 1 #define ADDED_LNAME 2 #define ADDED_NID 3 struct added_obj_st { int type; ASN1_OBJECT *obj; }; static int new_nid = NUM_NID; static LHASH_OF(ADDED_OBJ) *added = NULL; static int sn_cmp(const ASN1_OBJECT *const *a, const unsigned int *b) { return strcmp((*a)->sn, nid_objs[*b].sn); } IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, sn); static int ln_cmp(const ASN1_OBJECT *const *a, const unsigned int *b) { return strcmp((*a)->ln, nid_objs[*b].ln); } IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, ln); static unsigned long added_obj_hash(const ADDED_OBJ *ca) { const ASN1_OBJECT *a; int i; unsigned long ret = 0; unsigned char *p; a = ca->obj; switch (ca->type) { case ADDED_DATA: ret = a->length << 20L; p = (unsigned char *)a->data; for (i = 0; i < a->length; i++) ret ^= p[i] << ((i * 3) % 24); break; case ADDED_SNAME: ret = OPENSSL_LH_strhash(a->sn); break; case ADDED_LNAME: ret = OPENSSL_LH_strhash(a->ln); break; case ADDED_NID: ret = a->nid; break; default: /* abort(); */ return 0; } ret &= 0x3fffffffL; ret |= ((unsigned long)ca->type) << 30L; return ret; } static int added_obj_cmp(const ADDED_OBJ *ca, const ADDED_OBJ *cb) { ASN1_OBJECT *a, *b; int i; i = ca->type - cb->type; if (i) return i; a = ca->obj; b = cb->obj; switch (ca->type) { case ADDED_DATA: i = (a->length - b->length); if (i) return i; return memcmp(a->data, b->data, (size_t)a->length); case ADDED_SNAME: if (a->sn == NULL) return -1; else if (b->sn == NULL) return 1; else return strcmp(a->sn, b->sn); case ADDED_LNAME: if (a->ln == NULL) return -1; else if (b->ln == NULL) return 1; else return strcmp(a->ln, b->ln); case ADDED_NID: return a->nid - b->nid; default: /* abort(); */ return 0; } } static int init_added(void) { if (added != NULL) return 1; added = lh_ADDED_OBJ_new(added_obj_hash, added_obj_cmp); return added != NULL; } static void cleanup1_doall(ADDED_OBJ *a) { a->obj->nid = 0; a->obj->flags |= ASN1_OBJECT_FLAG_DYNAMIC | ASN1_OBJECT_FLAG_DYNAMIC_STRINGS | ASN1_OBJECT_FLAG_DYNAMIC_DATA; } static void cleanup2_doall(ADDED_OBJ *a) { a->obj->nid++; } static void cleanup3_doall(ADDED_OBJ *a) { if (--a->obj->nid == 0) ASN1_OBJECT_free(a->obj); OPENSSL_free(a); } void ossl_obj_cleanup_int(void) { if (added == NULL) return; lh_ADDED_OBJ_set_down_load(added, 0); lh_ADDED_OBJ_doall(added, cleanup1_doall); /* zero counters */ lh_ADDED_OBJ_doall(added, cleanup2_doall); /* set counters */ lh_ADDED_OBJ_doall(added, cleanup3_doall); /* free objects */ lh_ADDED_OBJ_free(added); added = NULL; } int OBJ_new_nid(int num) { int i; i = new_nid; new_nid += num; return i; } int OBJ_add_object(const ASN1_OBJECT *obj) { ASN1_OBJECT *o; ADDED_OBJ *ao[4] = { NULL, NULL, NULL, NULL }, *aop; int i; if (added == NULL) if (!init_added()) return 0; if ((o = OBJ_dup(obj)) == NULL) goto err; if ((ao[ADDED_NID] = OPENSSL_malloc(sizeof(*ao[0]))) == NULL) goto err2; if ((o->length != 0) && (obj->data != NULL)) if ((ao[ADDED_DATA] = OPENSSL_malloc(sizeof(*ao[0]))) == NULL) goto err2; if (o->sn != NULL) if ((ao[ADDED_SNAME] = OPENSSL_malloc(sizeof(*ao[0]))) == NULL) goto err2; if (o->ln != NULL) if ((ao[ADDED_LNAME] = OPENSSL_malloc(sizeof(*ao[0]))) == NULL) goto err2; for (i = ADDED_DATA; i <= ADDED_NID; i++) { if (ao[i] != NULL) { ao[i]->type = i; ao[i]->obj = o; aop = lh_ADDED_OBJ_insert(added, ao[i]); /* memory leak, but should not normally matter */ OPENSSL_free(aop); } } o->flags &= ~(ASN1_OBJECT_FLAG_DYNAMIC | ASN1_OBJECT_FLAG_DYNAMIC_STRINGS | ASN1_OBJECT_FLAG_DYNAMIC_DATA); return o->nid; err2: ERR_raise(ERR_LIB_OBJ, ERR_R_MALLOC_FAILURE); err: for (i = ADDED_DATA; i <= ADDED_NID; i++) OPENSSL_free(ao[i]); ASN1_OBJECT_free(o); return NID_undef; } ASN1_OBJECT *OBJ_nid2obj(int n) { ADDED_OBJ ad, *adp; ASN1_OBJECT ob; if ((n >= 0) && (n < NUM_NID)) { if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) { ERR_raise(ERR_LIB_OBJ, OBJ_R_UNKNOWN_NID); return NULL; } return (ASN1_OBJECT *)&(nid_objs[n]); } /* Make sure we've loaded config before checking for any "added" objects */ OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL); if (added == NULL) return NULL; ad.type = ADDED_NID; ad.obj = &ob; ob.nid = n; adp = lh_ADDED_OBJ_retrieve(added, &ad); if (adp != NULL) return adp->obj; ERR_raise(ERR_LIB_OBJ, OBJ_R_UNKNOWN_NID); return NULL; } const char *OBJ_nid2sn(int n) { ADDED_OBJ ad, *adp; ASN1_OBJECT ob; if ((n >= 0) && (n < NUM_NID)) { if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) { ERR_raise(ERR_LIB_OBJ, OBJ_R_UNKNOWN_NID); return NULL; } return nid_objs[n].sn; } /* Make sure we've loaded config before checking for any "added" objects */ OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL); if (added == NULL) return NULL; ad.type = ADDED_NID; ad.obj = &ob; ob.nid = n; adp = lh_ADDED_OBJ_retrieve(added, &ad); if (adp != NULL) return adp->obj->sn; ERR_raise(ERR_LIB_OBJ, OBJ_R_UNKNOWN_NID); return NULL; } const char *OBJ_nid2ln(int n) { ADDED_OBJ ad, *adp; ASN1_OBJECT ob; if ((n >= 0) && (n < NUM_NID)) { if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) { ERR_raise(ERR_LIB_OBJ, OBJ_R_UNKNOWN_NID); return NULL; } return nid_objs[n].ln; } /* Make sure we've loaded config before checking for any "added" objects */ OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL); if (added == NULL) return NULL; ad.type = ADDED_NID; ad.obj = &ob; ob.nid = n; adp = lh_ADDED_OBJ_retrieve(added, &ad); if (adp != NULL) return adp->obj->ln; ERR_raise(ERR_LIB_OBJ, OBJ_R_UNKNOWN_NID); return NULL; } static int obj_cmp(const ASN1_OBJECT *const *ap, const unsigned int *bp) { int j; const ASN1_OBJECT *a = *ap; const ASN1_OBJECT *b = &nid_objs[*bp]; j = (a->length - b->length); if (j) return j; if (a->length == 0) return 0; return memcmp(a->data, b->data, a->length); } IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, obj); int OBJ_obj2nid(const ASN1_OBJECT *a) { const unsigned int *op; ADDED_OBJ ad, *adp; if (a == NULL) return NID_undef; if (a->nid != 0) return a->nid; if (a->length == 0) return NID_undef; /* Make sure we've loaded config before checking for any "added" objects */ OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL); if (added != NULL) { ad.type = ADDED_DATA; ad.obj = (ASN1_OBJECT *)a; /* XXX: ugly but harmless */ adp = lh_ADDED_OBJ_retrieve(added, &ad); if (adp != NULL) return adp->obj->nid; } op = OBJ_bsearch_obj(&a, obj_objs, NUM_OBJ); if (op == NULL) return NID_undef; return nid_objs[*op].nid; } /* * Convert an object name into an ASN1_OBJECT if "noname" is not set then * search for short and long names first. This will convert the "dotted" form * into an object: unlike OBJ_txt2nid it can be used with any objects, not * just registered ones. */ ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name) { int nid = NID_undef; ASN1_OBJECT *op; unsigned char *buf; unsigned char *p; const unsigned char *cp; int i, j; if (!no_name) { if (((nid = OBJ_sn2nid(s)) != NID_undef) || ((nid = OBJ_ln2nid(s)) != NID_undef)) return OBJ_nid2obj(nid); if (!ossl_isdigit(*s)) { ERR_raise(ERR_LIB_OBJ, OBJ_R_UNKNOWN_OBJECT_NAME); return NULL; } } /* Work out size of content octets */ i = a2d_ASN1_OBJECT(NULL, 0, s, -1); if (i <= 0) { /* Don't clear the error */ /* * ERR_clear_error(); */ return NULL; } /* Work out total size */ j = ASN1_object_size(0, i, V_ASN1_OBJECT); if (j < 0) return NULL; if ((buf = OPENSSL_malloc(j)) == NULL) { ERR_raise(ERR_LIB_OBJ, ERR_R_MALLOC_FAILURE); return NULL; } p = buf; /* Write out tag+length */ ASN1_put_object(&p, 0, i, V_ASN1_OBJECT, V_ASN1_UNIVERSAL); /* Write out contents */ a2d_ASN1_OBJECT(p, i, s, -1); cp = buf; op = d2i_ASN1_OBJECT(NULL, &cp, j); OPENSSL_free(buf); return op; } int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name) { int i, n = 0, len, nid, first, use_bn; BIGNUM *bl; unsigned long l; const unsigned char *p; char tbuf[DECIMAL_SIZE(i) + DECIMAL_SIZE(l) + 2]; /* Ensure that, at every state, |buf| is NUL-terminated. */ if (buf && buf_len > 0) buf[0] = '\0'; if ((a == NULL) || (a->data == NULL)) return 0; if (!no_name && (nid = OBJ_obj2nid(a)) != NID_undef) { const char *s; s = OBJ_nid2ln(nid); if (s == NULL) s = OBJ_nid2sn(nid); if (s) { if (buf) OPENSSL_strlcpy(buf, s, buf_len); n = strlen(s); return n; } } len = a->length; p = a->data; first = 1; bl = NULL; /* * RFC 2578 (STD 58) says this about OBJECT IDENTIFIERs: * * > 3.5. OBJECT IDENTIFIER values * > * > An OBJECT IDENTIFIER value is an ordered list of non-negative * > numbers. For the SMIv2, each number in the list is referred to as a * > sub-identifier, there are at most 128 sub-identifiers in a value, * > and each sub-identifier has a maximum value of 2^32-1 (4294967295 * > decimal). * * So a legitimate OID according to this RFC is at most (32 * 128 / 7), * i.e. 586 bytes long. * * Ref: https://datatracker.ietf.org/doc/html/rfc2578#section-3.5 */ if (len > 586) goto err; while (len > 0) { l = 0; use_bn = 0; for (;;) { unsigned char c = *p++; len--; if ((len == 0) && (c & 0x80)) goto err; if (use_bn) { if (!BN_add_word(bl, c & 0x7f)) goto err; } else l |= c & 0x7f; if (!(c & 0x80)) break; if (!use_bn && (l > (ULONG_MAX >> 7L))) { if (bl == NULL && (bl = BN_new()) == NULL) goto err; if (!BN_set_word(bl, l)) goto err; use_bn = 1; } if (use_bn) { if (!BN_lshift(bl, bl, 7)) goto err; } else l <<= 7L; } if (first) { first = 0; if (l >= 80) { i = 2; if (use_bn) { if (!BN_sub_word(bl, 80)) goto err; } else l -= 80; } else { i = (int)(l / 40); l -= (long)(i * 40); } if (buf && (buf_len > 1)) { *buf++ = i + '0'; *buf = '\0'; buf_len--; } n++; } if (use_bn) { char *bndec; bndec = BN_bn2dec(bl); if (!bndec) goto err; i = strlen(bndec); if (buf) { if (buf_len > 1) { *buf++ = '.'; *buf = '\0'; buf_len--; } OPENSSL_strlcpy(buf, bndec, buf_len); if (i > buf_len) { buf += buf_len; buf_len = 0; } else { buf += i; buf_len -= i; } } n++; n += i; OPENSSL_free(bndec); } else { BIO_snprintf(tbuf, sizeof(tbuf), ".%lu", l); i = strlen(tbuf); if (buf && (buf_len > 0)) { OPENSSL_strlcpy(buf, tbuf, buf_len); if (i > buf_len) { buf += buf_len; buf_len = 0; } else { buf += i; buf_len -= i; } } n += i; l = 0; } } BN_free(bl); return n; err: BN_free(bl); return -1; } int OBJ_txt2nid(const char *s) { ASN1_OBJECT *obj; int nid; obj = OBJ_txt2obj(s, 0); nid = OBJ_obj2nid(obj); ASN1_OBJECT_free(obj); return nid; } int OBJ_ln2nid(const char *s) { ASN1_OBJECT o; const ASN1_OBJECT *oo = &o; ADDED_OBJ ad, *adp; const unsigned int *op; /* Make sure we've loaded config before checking for any "added" objects */ OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL); o.ln = s; if (added != NULL) { ad.type = ADDED_LNAME; ad.obj = &o; adp = lh_ADDED_OBJ_retrieve(added, &ad); if (adp != NULL) return adp->obj->nid; } op = OBJ_bsearch_ln(&oo, ln_objs, NUM_LN); if (op == NULL) return NID_undef; return nid_objs[*op].nid; } int OBJ_sn2nid(const char *s) { ASN1_OBJECT o; const ASN1_OBJECT *oo = &o; ADDED_OBJ ad, *adp; const unsigned int *op; /* Make sure we've loaded config before checking for any "added" objects */ OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL); o.sn = s; if (added != NULL) { ad.type = ADDED_SNAME; ad.obj = &o; adp = lh_ADDED_OBJ_retrieve(added, &ad); if (adp != NULL) return adp->obj->nid; } op = OBJ_bsearch_sn(&oo, sn_objs, NUM_SN); if (op == NULL) return NID_undef; return nid_objs[*op].nid; } const void *OBJ_bsearch_(const void *key, const void *base, int num, int size, int (*cmp) (const void *, const void *)) { return OBJ_bsearch_ex_(key, base, num, size, cmp, 0); } const void *OBJ_bsearch_ex_(const void *key, const void *base, int num, int size, int (*cmp) (const void *, const void *), int flags) { const char *p = ossl_bsearch(key, base, num, size, cmp, flags); #ifdef CHARSET_EBCDIC /* * THIS IS A KLUDGE - Because the *_obj is sorted in ASCII order, and I * don't have perl (yet), we revert to a *LINEAR* search when the object * wasn't found in the binary search. */ if (p == NULL) { const char *base_ = base; int l, h, i = 0, c = 0; + char *p1; for (i = 0; i < num; ++i) { - p = &(base_[i * size]); - c = (*cmp) (key, p); + p1 = &(base_[i * size]); + c = (*cmp) (key, p1); if (c == 0 || (c < 0 && (flags & OBJ_BSEARCH_VALUE_ON_NOMATCH))) - return p; + return p1; } } #endif return p; } /* * Parse a BIO sink to create some extra oid's objects. * Line format: */ int OBJ_create_objects(BIO *in) { char buf[512]; int i, num = 0; char *o, *s, *l = NULL; for (;;) { s = o = NULL; i = BIO_gets(in, buf, 512); if (i <= 0) return num; buf[i - 1] = '\0'; if (!ossl_isalnum(buf[0])) return num; o = s = buf; while (ossl_isdigit(*s) || *s == '.') s++; if (*s != '\0') { *(s++) = '\0'; while (ossl_isspace(*s)) s++; if (*s == '\0') { s = NULL; } else { l = s; while (*l != '\0' && !ossl_isspace(*l)) l++; if (*l != '\0') { *(l++) = '\0'; while (ossl_isspace(*l)) l++; if (*l == '\0') { l = NULL; } } else { l = NULL; } } } else { s = NULL; } if (*o == '\0') return num; if (!OBJ_create(o, s, l)) return num; num++; } } int OBJ_create(const char *oid, const char *sn, const char *ln) { ASN1_OBJECT *tmpoid = NULL; int ok = 0; /* Check to see if short or long name already present */ if ((sn != NULL && OBJ_sn2nid(sn) != NID_undef) || (ln != NULL && OBJ_ln2nid(ln) != NID_undef)) { ERR_raise(ERR_LIB_OBJ, OBJ_R_OID_EXISTS); return 0; } /* Convert numerical OID string to an ASN1_OBJECT structure */ tmpoid = OBJ_txt2obj(oid, 1); if (tmpoid == NULL) return 0; /* If NID is not NID_undef then object already exists */ if (OBJ_obj2nid(tmpoid) != NID_undef) { ERR_raise(ERR_LIB_OBJ, OBJ_R_OID_EXISTS); goto err; } tmpoid->nid = OBJ_new_nid(1); if (tmpoid->nid == NID_undef) goto err; tmpoid->sn = (char *)sn; tmpoid->ln = (char *)ln; ok = OBJ_add_object(tmpoid); tmpoid->sn = NULL; tmpoid->ln = NULL; err: ASN1_OBJECT_free(tmpoid); return ok; } size_t OBJ_length(const ASN1_OBJECT *obj) { if (obj == NULL) return 0; return obj->length; } const unsigned char *OBJ_get0_data(const ASN1_OBJECT *obj) { if (obj == NULL) return NULL; return obj->data; } diff --git a/crypto/openssl/crypto/param_build_set.c b/crypto/openssl/crypto/param_build_set.c index 8b570ded96eb..5de06cc7ed68 100644 --- a/crypto/openssl/crypto/param_build_set.c +++ b/crypto/openssl/crypto/param_build_set.c @@ -1,121 +1,122 @@ /* - * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2020-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ /* * Key Management utility functions to share functionality between the export() * and get_params() methods. * export() uses OSSL_PARAM_BLD, and get_params() used the OSSL_PARAM[] to * fill in parameter data for the same key and data fields. */ #include #include "internal/param_build_set.h" DEFINE_SPECIAL_STACK_OF_CONST(BIGNUM_const, BIGNUM) int ossl_param_build_set_int(OSSL_PARAM_BLD *bld, OSSL_PARAM *p, const char *key, int num) { if (bld != NULL) return OSSL_PARAM_BLD_push_int(bld, key, num); p = OSSL_PARAM_locate(p, key); if (p != NULL) return OSSL_PARAM_set_int(p, num); return 1; } int ossl_param_build_set_long(OSSL_PARAM_BLD *bld, OSSL_PARAM *p, const char *key, long num) { if (bld != NULL) return OSSL_PARAM_BLD_push_long(bld, key, num); p = OSSL_PARAM_locate(p, key); if (p != NULL) return OSSL_PARAM_set_long(p, num); return 1; } int ossl_param_build_set_utf8_string(OSSL_PARAM_BLD *bld, OSSL_PARAM *p, const char *key, const char *buf) { if (bld != NULL) return OSSL_PARAM_BLD_push_utf8_string(bld, key, buf, 0); p = OSSL_PARAM_locate(p, key); if (p != NULL) return OSSL_PARAM_set_utf8_string(p, buf); return 1; } int ossl_param_build_set_octet_string(OSSL_PARAM_BLD *bld, OSSL_PARAM *p, const char *key, const unsigned char *data, size_t data_len) { if (bld != NULL) return OSSL_PARAM_BLD_push_octet_string(bld, key, data, data_len); p = OSSL_PARAM_locate(p, key); if (p != NULL) return OSSL_PARAM_set_octet_string(p, data, data_len); return 1; } int ossl_param_build_set_bn_pad(OSSL_PARAM_BLD *bld, OSSL_PARAM *p, const char *key, const BIGNUM *bn, size_t sz) { if (bld != NULL) return OSSL_PARAM_BLD_push_BN_pad(bld, key, bn, sz); p = OSSL_PARAM_locate(p, key); if (p != NULL) { if (sz > p->data_size) return 0; p->data_size = sz; return OSSL_PARAM_set_BN(p, bn); } return 1; } int ossl_param_build_set_bn(OSSL_PARAM_BLD *bld, OSSL_PARAM *p, const char *key, const BIGNUM *bn) { if (bld != NULL) return OSSL_PARAM_BLD_push_BN(bld, key, bn); p = OSSL_PARAM_locate(p, key); if (p != NULL) return OSSL_PARAM_set_BN(p, bn) > 0; return 1; } int ossl_param_build_set_multi_key_bn(OSSL_PARAM_BLD *bld, OSSL_PARAM *params, const char *names[], STACK_OF(BIGNUM_const) *stk) { int i, sz = sk_BIGNUM_const_num(stk); OSSL_PARAM *p; - + const BIGNUM *bn; if (bld != NULL) { for (i = 0; i < sz && names[i] != NULL; ++i) { - if (!OSSL_PARAM_BLD_push_BN(bld, names[i], - sk_BIGNUM_const_value(stk, i))) + bn = sk_BIGNUM_const_value(stk, i); + if (bn != NULL && !OSSL_PARAM_BLD_push_BN(bld, names[i], bn)) return 0; } return 1; } for (i = 0; i < sz && names[i] != NULL; ++i) { + bn = sk_BIGNUM_const_value(stk, i); p = OSSL_PARAM_locate(params, names[i]); - if (p != NULL) { - if (!OSSL_PARAM_set_BN(p, sk_BIGNUM_const_value(stk, i))) + if (p != NULL && bn != NULL) { + if (!OSSL_PARAM_set_BN(p, bn)) return 0; } } return 1; } diff --git a/crypto/openssl/crypto/poly1305/asm/poly1305-armv8.pl b/crypto/openssl/crypto/poly1305/asm/poly1305-armv8.pl index 113a2151b6fa..dc39f4053fe6 100755 --- a/crypto/openssl/crypto/poly1305/asm/poly1305-armv8.pl +++ b/crypto/openssl/crypto/poly1305/asm/poly1305-armv8.pl @@ -1,947 +1,947 @@ #! /usr/bin/env perl -# Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 2016-2023 The OpenSSL Project Authors. All Rights Reserved. # # Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy # in the file LICENSE in the source distribution or at # https://www.openssl.org/source/license.html # # ==================================================================== # Written by Andy Polyakov for the OpenSSL # project. The module is, however, dual licensed under OpenSSL and # CRYPTOGAMS licenses depending on where you obtain it. For further # details see http://www.openssl.org/~appro/cryptogams/. # ==================================================================== # # This module implements Poly1305 hash for ARMv8. # # June 2015 # # Numbers are cycles per processed byte with poly1305_blocks alone. # # IALU/gcc-4.9 NEON # # Apple A7 1.86/+5% 0.72 # Cortex-A53 2.69/+58% 1.47 # Cortex-A57 2.70/+7% 1.14 # Denver 1.64/+50% 1.18(*) # X-Gene 2.13/+68% 2.27 # Mongoose 1.77/+75% 1.12 # Kryo 2.70/+55% 1.13 # ThunderX2 1.17/+95% 1.36 # # (*) estimate based on resources availability is less than 1.0, # i.e. measured result is worse than expected, presumably binary # translator is not almighty; # $output is the last argument if it looks like a file (it has an extension) # $flavour is the first argument if it doesn't look like a file $output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef; $flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef; $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1; ( $xlate="${dir}arm-xlate.pl" and -f $xlate ) or ( $xlate="${dir}../../perlasm/arm-xlate.pl" and -f $xlate) or die "can't locate arm-xlate.pl"; open OUT,"| \"$^X\" $xlate $flavour \"$output\"" or die "can't call $xlate: $!"; *STDOUT=*OUT; my ($ctx,$inp,$len,$padbit) = map("x$_",(0..3)); my ($mac,$nonce)=($inp,$len); my ($h0,$h1,$h2,$r0,$r1,$s1,$t0,$t1,$d0,$d1,$d2) = map("x$_",(4..14)); $code.=<<___; #include "arm_arch.h" .text // forward "declarations" are required for Apple .extern OPENSSL_armcap_P .hidden OPENSSL_armcap_P .globl poly1305_init .hidden poly1305_init .globl poly1305_blocks .hidden poly1305_blocks .globl poly1305_emit .hidden poly1305_emit .type poly1305_init,%function .align 5 poly1305_init: cmp $inp,xzr stp xzr,xzr,[$ctx] // zero hash value stp xzr,xzr,[$ctx,#16] // [along with is_base2_26] csel x0,xzr,x0,eq b.eq .Lno_key adrp x17,OPENSSL_armcap_P ldr w17,[x17,#:lo12:OPENSSL_armcap_P] ldp $r0,$r1,[$inp] // load key mov $s1,#0xfffffffc0fffffff movk $s1,#0x0fff,lsl#48 -#ifdef __ARMEB__ +#ifdef __AARCH64EB__ rev $r0,$r0 // flip bytes rev $r1,$r1 #endif and $r0,$r0,$s1 // &=0ffffffc0fffffff and $s1,$s1,#-4 and $r1,$r1,$s1 // &=0ffffffc0ffffffc stp $r0,$r1,[$ctx,#32] // save key value tst w17,#ARMV7_NEON adr $d0,.Lpoly1305_blocks adr $r0,.Lpoly1305_blocks_neon adr $d1,.Lpoly1305_emit adr $r1,.Lpoly1305_emit_neon csel $d0,$d0,$r0,eq csel $d1,$d1,$r1,eq #ifdef __ILP32__ stp w12,w13,[$len] #else stp $d0,$d1,[$len] #endif mov x0,#1 .Lno_key: ret .size poly1305_init,.-poly1305_init .type poly1305_blocks,%function .align 5 poly1305_blocks: .Lpoly1305_blocks: ands $len,$len,#-16 b.eq .Lno_data ldp $h0,$h1,[$ctx] // load hash value ldp $r0,$r1,[$ctx,#32] // load key value ldr $h2,[$ctx,#16] add $s1,$r1,$r1,lsr#2 // s1 = r1 + (r1 >> 2) b .Loop .align 5 .Loop: ldp $t0,$t1,[$inp],#16 // load input sub $len,$len,#16 -#ifdef __ARMEB__ +#ifdef __AARCH64EB__ rev $t0,$t0 rev $t1,$t1 #endif adds $h0,$h0,$t0 // accumulate input adcs $h1,$h1,$t1 mul $d0,$h0,$r0 // h0*r0 adc $h2,$h2,$padbit umulh $d1,$h0,$r0 mul $t0,$h1,$s1 // h1*5*r1 umulh $t1,$h1,$s1 adds $d0,$d0,$t0 mul $t0,$h0,$r1 // h0*r1 adc $d1,$d1,$t1 umulh $d2,$h0,$r1 adds $d1,$d1,$t0 mul $t0,$h1,$r0 // h1*r0 adc $d2,$d2,xzr umulh $t1,$h1,$r0 adds $d1,$d1,$t0 mul $t0,$h2,$s1 // h2*5*r1 adc $d2,$d2,$t1 mul $t1,$h2,$r0 // h2*r0 adds $d1,$d1,$t0 adc $d2,$d2,$t1 and $t0,$d2,#-4 // final reduction and $h2,$d2,#3 add $t0,$t0,$d2,lsr#2 adds $h0,$d0,$t0 adcs $h1,$d1,xzr adc $h2,$h2,xzr cbnz $len,.Loop stp $h0,$h1,[$ctx] // store hash value str $h2,[$ctx,#16] .Lno_data: ret .size poly1305_blocks,.-poly1305_blocks .type poly1305_emit,%function .align 5 poly1305_emit: .Lpoly1305_emit: ldp $h0,$h1,[$ctx] // load hash base 2^64 ldr $h2,[$ctx,#16] ldp $t0,$t1,[$nonce] // load nonce adds $d0,$h0,#5 // compare to modulus adcs $d1,$h1,xzr adc $d2,$h2,xzr tst $d2,#-4 // see if it's carried/borrowed csel $h0,$h0,$d0,eq csel $h1,$h1,$d1,eq -#ifdef __ARMEB__ +#ifdef __AARCH64EB__ ror $t0,$t0,#32 // flip nonce words ror $t1,$t1,#32 #endif adds $h0,$h0,$t0 // accumulate nonce adc $h1,$h1,$t1 -#ifdef __ARMEB__ +#ifdef __AARCH64EB__ rev $h0,$h0 // flip output bytes rev $h1,$h1 #endif stp $h0,$h1,[$mac] // write result ret .size poly1305_emit,.-poly1305_emit ___ my ($R0,$R1,$S1,$R2,$S2,$R3,$S3,$R4,$S4) = map("v$_.4s",(0..8)); my ($IN01_0,$IN01_1,$IN01_2,$IN01_3,$IN01_4) = map("v$_.2s",(9..13)); my ($IN23_0,$IN23_1,$IN23_2,$IN23_3,$IN23_4) = map("v$_.2s",(14..18)); my ($ACC0,$ACC1,$ACC2,$ACC3,$ACC4) = map("v$_.2d",(19..23)); my ($H0,$H1,$H2,$H3,$H4) = map("v$_.2s",(24..28)); my ($T0,$T1,$MASK) = map("v$_",(29..31)); my ($in2,$zeros)=("x16","x17"); my $is_base2_26 = $zeros; # borrow $code.=<<___; .type poly1305_mult,%function .align 5 poly1305_mult: mul $d0,$h0,$r0 // h0*r0 umulh $d1,$h0,$r0 mul $t0,$h1,$s1 // h1*5*r1 umulh $t1,$h1,$s1 adds $d0,$d0,$t0 mul $t0,$h0,$r1 // h0*r1 adc $d1,$d1,$t1 umulh $d2,$h0,$r1 adds $d1,$d1,$t0 mul $t0,$h1,$r0 // h1*r0 adc $d2,$d2,xzr umulh $t1,$h1,$r0 adds $d1,$d1,$t0 mul $t0,$h2,$s1 // h2*5*r1 adc $d2,$d2,$t1 mul $t1,$h2,$r0 // h2*r0 adds $d1,$d1,$t0 adc $d2,$d2,$t1 and $t0,$d2,#-4 // final reduction and $h2,$d2,#3 add $t0,$t0,$d2,lsr#2 adds $h0,$d0,$t0 adcs $h1,$d1,xzr adc $h2,$h2,xzr ret .size poly1305_mult,.-poly1305_mult .type poly1305_splat,%function .align 5 poly1305_splat: and x12,$h0,#0x03ffffff // base 2^64 -> base 2^26 ubfx x13,$h0,#26,#26 extr x14,$h1,$h0,#52 and x14,x14,#0x03ffffff ubfx x15,$h1,#14,#26 extr x16,$h2,$h1,#40 str w12,[$ctx,#16*0] // r0 add w12,w13,w13,lsl#2 // r1*5 str w13,[$ctx,#16*1] // r1 add w13,w14,w14,lsl#2 // r2*5 str w12,[$ctx,#16*2] // s1 str w14,[$ctx,#16*3] // r2 add w14,w15,w15,lsl#2 // r3*5 str w13,[$ctx,#16*4] // s2 str w15,[$ctx,#16*5] // r3 add w15,w16,w16,lsl#2 // r4*5 str w14,[$ctx,#16*6] // s3 str w16,[$ctx,#16*7] // r4 str w15,[$ctx,#16*8] // s4 ret .size poly1305_splat,.-poly1305_splat .type poly1305_blocks_neon,%function .align 5 poly1305_blocks_neon: .Lpoly1305_blocks_neon: ldr $is_base2_26,[$ctx,#24] cmp $len,#128 b.hs .Lblocks_neon cbz $is_base2_26,.Lpoly1305_blocks .Lblocks_neon: .inst 0xd503233f // paciasp stp x29,x30,[sp,#-80]! add x29,sp,#0 ands $len,$len,#-16 b.eq .Lno_data_neon cbz $is_base2_26,.Lbase2_64_neon ldp w10,w11,[$ctx] // load hash value base 2^26 ldp w12,w13,[$ctx,#8] ldr w14,[$ctx,#16] tst $len,#31 b.eq .Leven_neon ldp $r0,$r1,[$ctx,#32] // load key value add $h0,x10,x11,lsl#26 // base 2^26 -> base 2^64 lsr $h1,x12,#12 adds $h0,$h0,x12,lsl#52 add $h1,$h1,x13,lsl#14 adc $h1,$h1,xzr lsr $h2,x14,#24 adds $h1,$h1,x14,lsl#40 adc $d2,$h2,xzr // can be partially reduced... ldp $d0,$d1,[$inp],#16 // load input sub $len,$len,#16 add $s1,$r1,$r1,lsr#2 // s1 = r1 + (r1 >> 2) and $t0,$d2,#-4 // ... so reduce and $h2,$d2,#3 add $t0,$t0,$d2,lsr#2 adds $h0,$h0,$t0 adcs $h1,$h1,xzr adc $h2,$h2,xzr -#ifdef __ARMEB__ +#ifdef __AARCH64EB__ rev $d0,$d0 rev $d1,$d1 #endif adds $h0,$h0,$d0 // accumulate input adcs $h1,$h1,$d1 adc $h2,$h2,$padbit bl poly1305_mult ldr x30,[sp,#8] cbz $padbit,.Lstore_base2_64_neon and x10,$h0,#0x03ffffff // base 2^64 -> base 2^26 ubfx x11,$h0,#26,#26 extr x12,$h1,$h0,#52 and x12,x12,#0x03ffffff ubfx x13,$h1,#14,#26 extr x14,$h2,$h1,#40 cbnz $len,.Leven_neon stp w10,w11,[$ctx] // store hash value base 2^26 stp w12,w13,[$ctx,#8] str w14,[$ctx,#16] b .Lno_data_neon .align 4 .Lstore_base2_64_neon: stp $h0,$h1,[$ctx] // store hash value base 2^64 stp $h2,xzr,[$ctx,#16] // note that is_base2_26 is zeroed b .Lno_data_neon .align 4 .Lbase2_64_neon: ldp $r0,$r1,[$ctx,#32] // load key value ldp $h0,$h1,[$ctx] // load hash value base 2^64 ldr $h2,[$ctx,#16] tst $len,#31 b.eq .Linit_neon ldp $d0,$d1,[$inp],#16 // load input sub $len,$len,#16 add $s1,$r1,$r1,lsr#2 // s1 = r1 + (r1 >> 2) -#ifdef __ARMEB__ +#ifdef __AARCH64EB__ rev $d0,$d0 rev $d1,$d1 #endif adds $h0,$h0,$d0 // accumulate input adcs $h1,$h1,$d1 adc $h2,$h2,$padbit bl poly1305_mult .Linit_neon: and x10,$h0,#0x03ffffff // base 2^64 -> base 2^26 ubfx x11,$h0,#26,#26 extr x12,$h1,$h0,#52 and x12,x12,#0x03ffffff ubfx x13,$h1,#14,#26 extr x14,$h2,$h1,#40 stp d8,d9,[sp,#16] // meet ABI requirements stp d10,d11,[sp,#32] stp d12,d13,[sp,#48] stp d14,d15,[sp,#64] fmov ${H0},x10 fmov ${H1},x11 fmov ${H2},x12 fmov ${H3},x13 fmov ${H4},x14 ////////////////////////////////// initialize r^n table mov $h0,$r0 // r^1 add $s1,$r1,$r1,lsr#2 // s1 = r1 + (r1 >> 2) mov $h1,$r1 mov $h2,xzr add $ctx,$ctx,#48+12 bl poly1305_splat bl poly1305_mult // r^2 sub $ctx,$ctx,#4 bl poly1305_splat bl poly1305_mult // r^3 sub $ctx,$ctx,#4 bl poly1305_splat bl poly1305_mult // r^4 sub $ctx,$ctx,#4 bl poly1305_splat ldr x30,[sp,#8] add $in2,$inp,#32 adr $zeros,.Lzeros subs $len,$len,#64 csel $in2,$zeros,$in2,lo mov x4,#1 stur x4,[$ctx,#-24] // set is_base2_26 sub $ctx,$ctx,#48 // restore original $ctx b .Ldo_neon .align 4 .Leven_neon: add $in2,$inp,#32 adr $zeros,.Lzeros subs $len,$len,#64 csel $in2,$zeros,$in2,lo stp d8,d9,[sp,#16] // meet ABI requirements stp d10,d11,[sp,#32] stp d12,d13,[sp,#48] stp d14,d15,[sp,#64] fmov ${H0},x10 fmov ${H1},x11 fmov ${H2},x12 fmov ${H3},x13 fmov ${H4},x14 .Ldo_neon: ldp x8,x12,[$in2],#16 // inp[2:3] (or zero) ldp x9,x13,[$in2],#48 lsl $padbit,$padbit,#24 add x15,$ctx,#48 -#ifdef __ARMEB__ +#ifdef __AARCH64EB__ rev x8,x8 rev x12,x12 rev x9,x9 rev x13,x13 #endif and x4,x8,#0x03ffffff // base 2^64 -> base 2^26 and x5,x9,#0x03ffffff ubfx x6,x8,#26,#26 ubfx x7,x9,#26,#26 add x4,x4,x5,lsl#32 // bfi x4,x5,#32,#32 extr x8,x12,x8,#52 extr x9,x13,x9,#52 add x6,x6,x7,lsl#32 // bfi x6,x7,#32,#32 fmov $IN23_0,x4 and x8,x8,#0x03ffffff and x9,x9,#0x03ffffff ubfx x10,x12,#14,#26 ubfx x11,x13,#14,#26 add x12,$padbit,x12,lsr#40 add x13,$padbit,x13,lsr#40 add x8,x8,x9,lsl#32 // bfi x8,x9,#32,#32 fmov $IN23_1,x6 add x10,x10,x11,lsl#32 // bfi x10,x11,#32,#32 add x12,x12,x13,lsl#32 // bfi x12,x13,#32,#32 fmov $IN23_2,x8 fmov $IN23_3,x10 fmov $IN23_4,x12 ldp x8,x12,[$inp],#16 // inp[0:1] ldp x9,x13,[$inp],#48 ld1 {$R0,$R1,$S1,$R2},[x15],#64 ld1 {$S2,$R3,$S3,$R4},[x15],#64 ld1 {$S4},[x15] -#ifdef __ARMEB__ +#ifdef __AARCH64EB__ rev x8,x8 rev x12,x12 rev x9,x9 rev x13,x13 #endif and x4,x8,#0x03ffffff // base 2^64 -> base 2^26 and x5,x9,#0x03ffffff ubfx x6,x8,#26,#26 ubfx x7,x9,#26,#26 add x4,x4,x5,lsl#32 // bfi x4,x5,#32,#32 extr x8,x12,x8,#52 extr x9,x13,x9,#52 add x6,x6,x7,lsl#32 // bfi x6,x7,#32,#32 fmov $IN01_0,x4 and x8,x8,#0x03ffffff and x9,x9,#0x03ffffff ubfx x10,x12,#14,#26 ubfx x11,x13,#14,#26 add x12,$padbit,x12,lsr#40 add x13,$padbit,x13,lsr#40 add x8,x8,x9,lsl#32 // bfi x8,x9,#32,#32 fmov $IN01_1,x6 add x10,x10,x11,lsl#32 // bfi x10,x11,#32,#32 add x12,x12,x13,lsl#32 // bfi x12,x13,#32,#32 movi $MASK.2d,#-1 fmov $IN01_2,x8 fmov $IN01_3,x10 fmov $IN01_4,x12 ushr $MASK.2d,$MASK.2d,#38 b.ls .Lskip_loop .align 4 .Loop_neon: //////////////////////////////////////////////////////////////// // ((inp[0]*r^4+inp[2]*r^2+inp[4])*r^4+inp[6]*r^2 // ((inp[1]*r^4+inp[3]*r^2+inp[5])*r^3+inp[7]*r // \___________________/ // ((inp[0]*r^4+inp[2]*r^2+inp[4])*r^4+inp[6]*r^2+inp[8])*r^2 // ((inp[1]*r^4+inp[3]*r^2+inp[5])*r^4+inp[7]*r^2+inp[9])*r // \___________________/ \____________________/ // // Note that we start with inp[2:3]*r^2. This is because it // doesn't depend on reduction in previous iteration. //////////////////////////////////////////////////////////////// // d4 = h0*r4 + h1*r3 + h2*r2 + h3*r1 + h4*r0 // d3 = h0*r3 + h1*r2 + h2*r1 + h3*r0 + h4*5*r4 // d2 = h0*r2 + h1*r1 + h2*r0 + h3*5*r4 + h4*5*r3 // d1 = h0*r1 + h1*r0 + h2*5*r4 + h3*5*r3 + h4*5*r2 // d0 = h0*r0 + h1*5*r4 + h2*5*r3 + h3*5*r2 + h4*5*r1 subs $len,$len,#64 umull $ACC4,$IN23_0,${R4}[2] csel $in2,$zeros,$in2,lo umull $ACC3,$IN23_0,${R3}[2] umull $ACC2,$IN23_0,${R2}[2] ldp x8,x12,[$in2],#16 // inp[2:3] (or zero) umull $ACC1,$IN23_0,${R1}[2] ldp x9,x13,[$in2],#48 umull $ACC0,$IN23_0,${R0}[2] -#ifdef __ARMEB__ +#ifdef __AARCH64EB__ rev x8,x8 rev x12,x12 rev x9,x9 rev x13,x13 #endif umlal $ACC4,$IN23_1,${R3}[2] and x4,x8,#0x03ffffff // base 2^64 -> base 2^26 umlal $ACC3,$IN23_1,${R2}[2] and x5,x9,#0x03ffffff umlal $ACC2,$IN23_1,${R1}[2] ubfx x6,x8,#26,#26 umlal $ACC1,$IN23_1,${R0}[2] ubfx x7,x9,#26,#26 umlal $ACC0,$IN23_1,${S4}[2] add x4,x4,x5,lsl#32 // bfi x4,x5,#32,#32 umlal $ACC4,$IN23_2,${R2}[2] extr x8,x12,x8,#52 umlal $ACC3,$IN23_2,${R1}[2] extr x9,x13,x9,#52 umlal $ACC2,$IN23_2,${R0}[2] add x6,x6,x7,lsl#32 // bfi x6,x7,#32,#32 umlal $ACC1,$IN23_2,${S4}[2] fmov $IN23_0,x4 umlal $ACC0,$IN23_2,${S3}[2] and x8,x8,#0x03ffffff umlal $ACC4,$IN23_3,${R1}[2] and x9,x9,#0x03ffffff umlal $ACC3,$IN23_3,${R0}[2] ubfx x10,x12,#14,#26 umlal $ACC2,$IN23_3,${S4}[2] ubfx x11,x13,#14,#26 umlal $ACC1,$IN23_3,${S3}[2] add x8,x8,x9,lsl#32 // bfi x8,x9,#32,#32 umlal $ACC0,$IN23_3,${S2}[2] fmov $IN23_1,x6 add $IN01_2,$IN01_2,$H2 add x12,$padbit,x12,lsr#40 umlal $ACC4,$IN23_4,${R0}[2] add x13,$padbit,x13,lsr#40 umlal $ACC3,$IN23_4,${S4}[2] add x10,x10,x11,lsl#32 // bfi x10,x11,#32,#32 umlal $ACC2,$IN23_4,${S3}[2] add x12,x12,x13,lsl#32 // bfi x12,x13,#32,#32 umlal $ACC1,$IN23_4,${S2}[2] fmov $IN23_2,x8 umlal $ACC0,$IN23_4,${S1}[2] fmov $IN23_3,x10 //////////////////////////////////////////////////////////////// // (hash+inp[0:1])*r^4 and accumulate add $IN01_0,$IN01_0,$H0 fmov $IN23_4,x12 umlal $ACC3,$IN01_2,${R1}[0] ldp x8,x12,[$inp],#16 // inp[0:1] umlal $ACC0,$IN01_2,${S3}[0] ldp x9,x13,[$inp],#48 umlal $ACC4,$IN01_2,${R2}[0] umlal $ACC1,$IN01_2,${S4}[0] umlal $ACC2,$IN01_2,${R0}[0] -#ifdef __ARMEB__ +#ifdef __AARCH64EB__ rev x8,x8 rev x12,x12 rev x9,x9 rev x13,x13 #endif add $IN01_1,$IN01_1,$H1 umlal $ACC3,$IN01_0,${R3}[0] umlal $ACC4,$IN01_0,${R4}[0] and x4,x8,#0x03ffffff // base 2^64 -> base 2^26 umlal $ACC2,$IN01_0,${R2}[0] and x5,x9,#0x03ffffff umlal $ACC0,$IN01_0,${R0}[0] ubfx x6,x8,#26,#26 umlal $ACC1,$IN01_0,${R1}[0] ubfx x7,x9,#26,#26 add $IN01_3,$IN01_3,$H3 add x4,x4,x5,lsl#32 // bfi x4,x5,#32,#32 umlal $ACC3,$IN01_1,${R2}[0] extr x8,x12,x8,#52 umlal $ACC4,$IN01_1,${R3}[0] extr x9,x13,x9,#52 umlal $ACC0,$IN01_1,${S4}[0] add x6,x6,x7,lsl#32 // bfi x6,x7,#32,#32 umlal $ACC2,$IN01_1,${R1}[0] fmov $IN01_0,x4 umlal $ACC1,$IN01_1,${R0}[0] and x8,x8,#0x03ffffff add $IN01_4,$IN01_4,$H4 and x9,x9,#0x03ffffff umlal $ACC3,$IN01_3,${R0}[0] ubfx x10,x12,#14,#26 umlal $ACC0,$IN01_3,${S2}[0] ubfx x11,x13,#14,#26 umlal $ACC4,$IN01_3,${R1}[0] add x8,x8,x9,lsl#32 // bfi x8,x9,#32,#32 umlal $ACC1,$IN01_3,${S3}[0] fmov $IN01_1,x6 umlal $ACC2,$IN01_3,${S4}[0] add x12,$padbit,x12,lsr#40 umlal $ACC3,$IN01_4,${S4}[0] add x13,$padbit,x13,lsr#40 umlal $ACC0,$IN01_4,${S1}[0] add x10,x10,x11,lsl#32 // bfi x10,x11,#32,#32 umlal $ACC4,$IN01_4,${R0}[0] add x12,x12,x13,lsl#32 // bfi x12,x13,#32,#32 umlal $ACC1,$IN01_4,${S2}[0] fmov $IN01_2,x8 umlal $ACC2,$IN01_4,${S3}[0] fmov $IN01_3,x10 fmov $IN01_4,x12 ///////////////////////////////////////////////////////////////// // lazy reduction as discussed in "NEON crypto" by D.J. Bernstein // and P. Schwabe // // [see discussion in poly1305-armv4 module] ushr $T0.2d,$ACC3,#26 xtn $H3,$ACC3 ushr $T1.2d,$ACC0,#26 and $ACC0,$ACC0,$MASK.2d add $ACC4,$ACC4,$T0.2d // h3 -> h4 bic $H3,#0xfc,lsl#24 // &=0x03ffffff add $ACC1,$ACC1,$T1.2d // h0 -> h1 ushr $T0.2d,$ACC4,#26 xtn $H4,$ACC4 ushr $T1.2d,$ACC1,#26 xtn $H1,$ACC1 bic $H4,#0xfc,lsl#24 add $ACC2,$ACC2,$T1.2d // h1 -> h2 add $ACC0,$ACC0,$T0.2d shl $T0.2d,$T0.2d,#2 shrn $T1.2s,$ACC2,#26 xtn $H2,$ACC2 add $ACC0,$ACC0,$T0.2d // h4 -> h0 bic $H1,#0xfc,lsl#24 add $H3,$H3,$T1.2s // h2 -> h3 bic $H2,#0xfc,lsl#24 shrn $T0.2s,$ACC0,#26 xtn $H0,$ACC0 ushr $T1.2s,$H3,#26 bic $H3,#0xfc,lsl#24 bic $H0,#0xfc,lsl#24 add $H1,$H1,$T0.2s // h0 -> h1 add $H4,$H4,$T1.2s // h3 -> h4 b.hi .Loop_neon .Lskip_loop: dup $IN23_2,${IN23_2}[0] add $IN01_2,$IN01_2,$H2 //////////////////////////////////////////////////////////////// // multiply (inp[0:1]+hash) or inp[2:3] by r^2:r^1 adds $len,$len,#32 b.ne .Long_tail dup $IN23_2,${IN01_2}[0] add $IN23_0,$IN01_0,$H0 add $IN23_3,$IN01_3,$H3 add $IN23_1,$IN01_1,$H1 add $IN23_4,$IN01_4,$H4 .Long_tail: dup $IN23_0,${IN23_0}[0] umull2 $ACC0,$IN23_2,${S3} umull2 $ACC3,$IN23_2,${R1} umull2 $ACC4,$IN23_2,${R2} umull2 $ACC2,$IN23_2,${R0} umull2 $ACC1,$IN23_2,${S4} dup $IN23_1,${IN23_1}[0] umlal2 $ACC0,$IN23_0,${R0} umlal2 $ACC2,$IN23_0,${R2} umlal2 $ACC3,$IN23_0,${R3} umlal2 $ACC4,$IN23_0,${R4} umlal2 $ACC1,$IN23_0,${R1} dup $IN23_3,${IN23_3}[0] umlal2 $ACC0,$IN23_1,${S4} umlal2 $ACC3,$IN23_1,${R2} umlal2 $ACC2,$IN23_1,${R1} umlal2 $ACC4,$IN23_1,${R3} umlal2 $ACC1,$IN23_1,${R0} dup $IN23_4,${IN23_4}[0] umlal2 $ACC3,$IN23_3,${R0} umlal2 $ACC4,$IN23_3,${R1} umlal2 $ACC0,$IN23_3,${S2} umlal2 $ACC1,$IN23_3,${S3} umlal2 $ACC2,$IN23_3,${S4} umlal2 $ACC3,$IN23_4,${S4} umlal2 $ACC0,$IN23_4,${S1} umlal2 $ACC4,$IN23_4,${R0} umlal2 $ACC1,$IN23_4,${S2} umlal2 $ACC2,$IN23_4,${S3} b.eq .Lshort_tail //////////////////////////////////////////////////////////////// // (hash+inp[0:1])*r^4:r^3 and accumulate add $IN01_0,$IN01_0,$H0 umlal $ACC3,$IN01_2,${R1} umlal $ACC0,$IN01_2,${S3} umlal $ACC4,$IN01_2,${R2} umlal $ACC1,$IN01_2,${S4} umlal $ACC2,$IN01_2,${R0} add $IN01_1,$IN01_1,$H1 umlal $ACC3,$IN01_0,${R3} umlal $ACC0,$IN01_0,${R0} umlal $ACC4,$IN01_0,${R4} umlal $ACC1,$IN01_0,${R1} umlal $ACC2,$IN01_0,${R2} add $IN01_3,$IN01_3,$H3 umlal $ACC3,$IN01_1,${R2} umlal $ACC0,$IN01_1,${S4} umlal $ACC4,$IN01_1,${R3} umlal $ACC1,$IN01_1,${R0} umlal $ACC2,$IN01_1,${R1} add $IN01_4,$IN01_4,$H4 umlal $ACC3,$IN01_3,${R0} umlal $ACC0,$IN01_3,${S2} umlal $ACC4,$IN01_3,${R1} umlal $ACC1,$IN01_3,${S3} umlal $ACC2,$IN01_3,${S4} umlal $ACC3,$IN01_4,${S4} umlal $ACC0,$IN01_4,${S1} umlal $ACC4,$IN01_4,${R0} umlal $ACC1,$IN01_4,${S2} umlal $ACC2,$IN01_4,${S3} .Lshort_tail: //////////////////////////////////////////////////////////////// // horizontal add addp $ACC3,$ACC3,$ACC3 ldp d8,d9,[sp,#16] // meet ABI requirements addp $ACC0,$ACC0,$ACC0 ldp d10,d11,[sp,#32] addp $ACC4,$ACC4,$ACC4 ldp d12,d13,[sp,#48] addp $ACC1,$ACC1,$ACC1 ldp d14,d15,[sp,#64] addp $ACC2,$ACC2,$ACC2 //////////////////////////////////////////////////////////////// // lazy reduction, but without narrowing ushr $T0.2d,$ACC3,#26 and $ACC3,$ACC3,$MASK.2d ushr $T1.2d,$ACC0,#26 and $ACC0,$ACC0,$MASK.2d add $ACC4,$ACC4,$T0.2d // h3 -> h4 add $ACC1,$ACC1,$T1.2d // h0 -> h1 ushr $T0.2d,$ACC4,#26 and $ACC4,$ACC4,$MASK.2d ushr $T1.2d,$ACC1,#26 and $ACC1,$ACC1,$MASK.2d add $ACC2,$ACC2,$T1.2d // h1 -> h2 add $ACC0,$ACC0,$T0.2d shl $T0.2d,$T0.2d,#2 ushr $T1.2d,$ACC2,#26 and $ACC2,$ACC2,$MASK.2d add $ACC0,$ACC0,$T0.2d // h4 -> h0 add $ACC3,$ACC3,$T1.2d // h2 -> h3 ushr $T0.2d,$ACC0,#26 and $ACC0,$ACC0,$MASK.2d ushr $T1.2d,$ACC3,#26 and $ACC3,$ACC3,$MASK.2d add $ACC1,$ACC1,$T0.2d // h0 -> h1 add $ACC4,$ACC4,$T1.2d // h3 -> h4 //////////////////////////////////////////////////////////////// // write the result, can be partially reduced st4 {$ACC0,$ACC1,$ACC2,$ACC3}[0],[$ctx],#16 st1 {$ACC4}[0],[$ctx] .Lno_data_neon: ldr x29,[sp],#80 .inst 0xd50323bf // autiasp ret .size poly1305_blocks_neon,.-poly1305_blocks_neon .type poly1305_emit_neon,%function .align 5 poly1305_emit_neon: .Lpoly1305_emit_neon: ldr $is_base2_26,[$ctx,#24] cbz $is_base2_26,poly1305_emit ldp w10,w11,[$ctx] // load hash value base 2^26 ldp w12,w13,[$ctx,#8] ldr w14,[$ctx,#16] add $h0,x10,x11,lsl#26 // base 2^26 -> base 2^64 lsr $h1,x12,#12 adds $h0,$h0,x12,lsl#52 add $h1,$h1,x13,lsl#14 adc $h1,$h1,xzr lsr $h2,x14,#24 adds $h1,$h1,x14,lsl#40 adc $h2,$h2,xzr // can be partially reduced... ldp $t0,$t1,[$nonce] // load nonce and $d0,$h2,#-4 // ... so reduce add $d0,$d0,$h2,lsr#2 and $h2,$h2,#3 adds $h0,$h0,$d0 adcs $h1,$h1,xzr adc $h2,$h2,xzr adds $d0,$h0,#5 // compare to modulus adcs $d1,$h1,xzr adc $d2,$h2,xzr tst $d2,#-4 // see if it's carried/borrowed csel $h0,$h0,$d0,eq csel $h1,$h1,$d1,eq -#ifdef __ARMEB__ +#ifdef __AARCH64EB__ ror $t0,$t0,#32 // flip nonce words ror $t1,$t1,#32 #endif adds $h0,$h0,$t0 // accumulate nonce adc $h1,$h1,$t1 -#ifdef __ARMEB__ +#ifdef __AARCH64EB__ rev $h0,$h0 // flip output bytes rev $h1,$h1 #endif stp $h0,$h1,[$mac] // write result ret .size poly1305_emit_neon,.-poly1305_emit_neon .align 5 .Lzeros: .long 0,0,0,0,0,0,0,0 .asciz "Poly1305 for ARMv8, CRYPTOGAMS by " .align 2 ___ foreach (split("\n",$code)) { s/\b(shrn\s+v[0-9]+)\.[24]d/$1.2s/ or s/\b(fmov\s+)v([0-9]+)[^,]*,\s*x([0-9]+)/$1d$2,x$3/ or (m/\bdup\b/ and (s/\.[24]s/.2d/g or 1)) or (m/\b(eor|and)/ and (s/\.[248][sdh]/.16b/g or 1)) or (m/\bum(ul|la)l\b/ and (s/\.4s/.2s/g or 1)) or (m/\bum(ul|la)l2\b/ and (s/\.2s/.4s/g or 1)) or (m/\bst[1-4]\s+{[^}]+}\[/ and (s/\.[24]d/.s/g or 1)); s/\.[124]([sd])\[/.$1\[/; print $_,"\n"; } close STDOUT or die "error closing STDOUT: $!"; diff --git a/crypto/openssl/crypto/property/property_parse.c b/crypto/openssl/crypto/property/property_parse.c index ca2bd33381bf..e3a4998df11f 100644 --- a/crypto/openssl/crypto/property/property_parse.c +++ b/crypto/openssl/crypto/property/property_parse.c @@ -1,706 +1,732 @@ /* - * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved. * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ #include #include #include #include #include "internal/propertyerr.h" #include "internal/property.h" #include "crypto/ctype.h" #include "internal/nelem.h" #include "property_local.h" #include "e_os.h" DEFINE_STACK_OF(OSSL_PROPERTY_DEFINITION) static const char *skip_space(const char *s) { while (ossl_isspace(*s)) s++; return s; } static int match_ch(const char *t[], char m) { const char *s = *t; if (*s == m) { *t = skip_space(s + 1); return 1; } return 0; } #define MATCH(s, m) match(s, m, sizeof(m) - 1) static int match(const char *t[], const char m[], size_t m_len) { const char *s = *t; if (OPENSSL_strncasecmp(s, m, m_len) == 0) { *t = skip_space(s + m_len); return 1; } return 0; } static int parse_name(OSSL_LIB_CTX *ctx, const char *t[], int create, OSSL_PROPERTY_IDX *idx) { char name[100]; int err = 0; size_t i = 0; const char *s = *t; int user_name = 0; for (;;) { if (!ossl_isalpha(*s)) { ERR_raise_data(ERR_LIB_PROP, PROP_R_NOT_AN_IDENTIFIER, "HERE-->%s", *t); return 0; } do { if (i < sizeof(name) - 1) name[i++] = ossl_tolower(*s); else err = 1; } while (*++s == '_' || ossl_isalnum(*s)); if (*s != '.') break; user_name = 1; if (i < sizeof(name) - 1) name[i++] = *s; else err = 1; s++; } name[i] = '\0'; if (err) { ERR_raise_data(ERR_LIB_PROP, PROP_R_NAME_TOO_LONG, "HERE-->%s", *t); return 0; } *t = skip_space(s); *idx = ossl_property_name(ctx, name, user_name && create); return 1; } static int parse_number(const char *t[], OSSL_PROPERTY_DEFINITION *res) { const char *s = *t; int64_t v = 0; if (!ossl_isdigit(*s)) return 0; do { v = v * 10 + (*s++ - '0'); } while (ossl_isdigit(*s)); if (!ossl_isspace(*s) && *s != '\0' && *s != ',') { ERR_raise_data(ERR_LIB_PROP, PROP_R_NOT_A_DECIMAL_DIGIT, "HERE-->%s", *t); return 0; } *t = skip_space(s); res->type = OSSL_PROPERTY_TYPE_NUMBER; res->v.int_val = v; return 1; } static int parse_hex(const char *t[], OSSL_PROPERTY_DEFINITION *res) { const char *s = *t; int64_t v = 0; if (!ossl_isxdigit(*s)) return 0; do { v <<= 4; if (ossl_isdigit(*s)) v += *s - '0'; else v += ossl_tolower(*s) - 'a'; } while (ossl_isxdigit(*++s)); if (!ossl_isspace(*s) && *s != '\0' && *s != ',') { ERR_raise_data(ERR_LIB_PROP, PROP_R_NOT_AN_HEXADECIMAL_DIGIT, "HERE-->%s", *t); return 0; } *t = skip_space(s); res->type = OSSL_PROPERTY_TYPE_NUMBER; res->v.int_val = v; return 1; } static int parse_oct(const char *t[], OSSL_PROPERTY_DEFINITION *res) { const char *s = *t; int64_t v = 0; if (*s == '9' || *s == '8' || !ossl_isdigit(*s)) return 0; do { v = (v << 3) + (*s - '0'); } while (ossl_isdigit(*++s) && *s != '9' && *s != '8'); if (!ossl_isspace(*s) && *s != '\0' && *s != ',') { ERR_raise_data(ERR_LIB_PROP, PROP_R_NOT_AN_OCTAL_DIGIT, "HERE-->%s", *t); return 0; } *t = skip_space(s); res->type = OSSL_PROPERTY_TYPE_NUMBER; res->v.int_val = v; return 1; } static int parse_string(OSSL_LIB_CTX *ctx, const char *t[], char delim, OSSL_PROPERTY_DEFINITION *res, const int create) { char v[1000]; const char *s = *t; size_t i = 0; int err = 0; while (*s != '\0' && *s != delim) { if (i < sizeof(v) - 1) v[i++] = *s; else err = 1; s++; } if (*s == '\0') { ERR_raise_data(ERR_LIB_PROP, PROP_R_NO_MATCHING_STRING_DELIMITER, "HERE-->%c%s", delim, *t); return 0; } v[i] = '\0'; if (err) { ERR_raise_data(ERR_LIB_PROP, PROP_R_STRING_TOO_LONG, "HERE-->%s", *t); } else { res->v.str_val = ossl_property_value(ctx, v, create); } *t = skip_space(s + 1); res->type = OSSL_PROPERTY_TYPE_STRING; return !err; } static int parse_unquoted(OSSL_LIB_CTX *ctx, const char *t[], OSSL_PROPERTY_DEFINITION *res, const int create) { char v[1000]; const char *s = *t; size_t i = 0; int err = 0; if (*s == '\0' || *s == ',') return 0; while (ossl_isprint(*s) && !ossl_isspace(*s) && *s != ',') { if (i < sizeof(v) - 1) v[i++] = ossl_tolower(*s); else err = 1; s++; } if (!ossl_isspace(*s) && *s != '\0' && *s != ',') { ERR_raise_data(ERR_LIB_PROP, PROP_R_NOT_AN_ASCII_CHARACTER, "HERE-->%s", s); return 0; } v[i] = 0; if (err) ERR_raise_data(ERR_LIB_PROP, PROP_R_STRING_TOO_LONG, "HERE-->%s", *t); else if ((res->v.str_val = ossl_property_value(ctx, v, create)) == 0) err = 1; *t = skip_space(s); res->type = OSSL_PROPERTY_TYPE_STRING; return !err; } static int parse_value(OSSL_LIB_CTX *ctx, const char *t[], OSSL_PROPERTY_DEFINITION *res, int create) { const char *s = *t; int r = 0; if (*s == '"' || *s == '\'') { s++; r = parse_string(ctx, &s, s[-1], res, create); } else if (*s == '+') { s++; r = parse_number(&s, res); } else if (*s == '-') { s++; r = parse_number(&s, res); res->v.int_val = -res->v.int_val; } else if (*s == '0' && s[1] == 'x') { s += 2; r = parse_hex(&s, res); } else if (*s == '0' && ossl_isdigit(s[1])) { s++; r = parse_oct(&s, res); } else if (ossl_isdigit(*s)) { return parse_number(t, res); } else if (ossl_isalpha(*s)) return parse_unquoted(ctx, t, res, create); if (r) *t = s; return r; } static int pd_compare(const OSSL_PROPERTY_DEFINITION *const *p1, const OSSL_PROPERTY_DEFINITION *const *p2) { const OSSL_PROPERTY_DEFINITION *pd1 = *p1; const OSSL_PROPERTY_DEFINITION *pd2 = *p2; if (pd1->name_idx < pd2->name_idx) return -1; if (pd1->name_idx > pd2->name_idx) return 1; return 0; } static void pd_free(OSSL_PROPERTY_DEFINITION *pd) { OPENSSL_free(pd); } /* * Convert a stack of property definitions and queries into a fixed array. * The items are sorted for efficient query. The stack is not freed. * This function also checks for duplicated names and returns an error if * any exist. */ static OSSL_PROPERTY_LIST * stack_to_property_list(OSSL_LIB_CTX *ctx, STACK_OF(OSSL_PROPERTY_DEFINITION) *sk) { const int n = sk_OSSL_PROPERTY_DEFINITION_num(sk); OSSL_PROPERTY_LIST *r; OSSL_PROPERTY_IDX prev_name_idx = 0; int i; r = OPENSSL_malloc(sizeof(*r) + (n <= 0 ? 0 : n - 1) * sizeof(r->properties[0])); if (r != NULL) { sk_OSSL_PROPERTY_DEFINITION_sort(sk); r->has_optional = 0; for (i = 0; i < n; i++) { r->properties[i] = *sk_OSSL_PROPERTY_DEFINITION_value(sk, i); r->has_optional |= r->properties[i].optional; /* Check for duplicated names */ if (i > 0 && r->properties[i].name_idx == prev_name_idx) { OPENSSL_free(r); ERR_raise_data(ERR_LIB_PROP, PROP_R_PARSE_FAILED, "Duplicated name `%s'", ossl_property_name_str(ctx, prev_name_idx)); return NULL; } prev_name_idx = r->properties[i].name_idx; } r->num_properties = n; } return r; } OSSL_PROPERTY_LIST *ossl_parse_property(OSSL_LIB_CTX *ctx, const char *defn) { OSSL_PROPERTY_DEFINITION *prop = NULL; OSSL_PROPERTY_LIST *res = NULL; STACK_OF(OSSL_PROPERTY_DEFINITION) *sk; const char *s = defn; int done; if (s == NULL || (sk = sk_OSSL_PROPERTY_DEFINITION_new(&pd_compare)) == NULL) return NULL; s = skip_space(s); done = *s == '\0'; while (!done) { const char *start = s; prop = OPENSSL_malloc(sizeof(*prop)); if (prop == NULL) goto err; memset(&prop->v, 0, sizeof(prop->v)); prop->optional = 0; if (!parse_name(ctx, &s, 1, &prop->name_idx)) goto err; prop->oper = OSSL_PROPERTY_OPER_EQ; if (prop->name_idx == 0) { ERR_raise_data(ERR_LIB_PROP, PROP_R_PARSE_FAILED, "Unknown name HERE-->%s", start); goto err; } if (match_ch(&s, '=')) { if (!parse_value(ctx, &s, prop, 1)) { ERR_raise_data(ERR_LIB_PROP, PROP_R_NO_VALUE, "HERE-->%s", start); goto err; } } else { /* A name alone means a true Boolean */ prop->type = OSSL_PROPERTY_TYPE_STRING; prop->v.str_val = OSSL_PROPERTY_TRUE; } if (!sk_OSSL_PROPERTY_DEFINITION_push(sk, prop)) goto err; prop = NULL; done = !match_ch(&s, ','); } if (*s != '\0') { ERR_raise_data(ERR_LIB_PROP, PROP_R_TRAILING_CHARACTERS, "HERE-->%s", s); goto err; } res = stack_to_property_list(ctx, sk); err: OPENSSL_free(prop); sk_OSSL_PROPERTY_DEFINITION_pop_free(sk, &pd_free); return res; } OSSL_PROPERTY_LIST *ossl_parse_query(OSSL_LIB_CTX *ctx, const char *s, int create_values) { STACK_OF(OSSL_PROPERTY_DEFINITION) *sk; OSSL_PROPERTY_LIST *res = NULL; OSSL_PROPERTY_DEFINITION *prop = NULL; int done; if (s == NULL || (sk = sk_OSSL_PROPERTY_DEFINITION_new(&pd_compare)) == NULL) return NULL; s = skip_space(s); done = *s == '\0'; while (!done) { prop = OPENSSL_malloc(sizeof(*prop)); if (prop == NULL) goto err; memset(&prop->v, 0, sizeof(prop->v)); if (match_ch(&s, '-')) { prop->oper = OSSL_PROPERTY_OVERRIDE; prop->optional = 0; if (!parse_name(ctx, &s, 1, &prop->name_idx)) goto err; goto skip_value; } prop->optional = match_ch(&s, '?'); if (!parse_name(ctx, &s, 1, &prop->name_idx)) goto err; if (match_ch(&s, '=')) { prop->oper = OSSL_PROPERTY_OPER_EQ; } else if (MATCH(&s, "!=")) { prop->oper = OSSL_PROPERTY_OPER_NE; } else { /* A name alone is a Boolean comparison for true */ prop->oper = OSSL_PROPERTY_OPER_EQ; prop->type = OSSL_PROPERTY_TYPE_STRING; prop->v.str_val = OSSL_PROPERTY_TRUE; goto skip_value; } if (!parse_value(ctx, &s, prop, create_values)) prop->type = OSSL_PROPERTY_TYPE_VALUE_UNDEFINED; skip_value: if (!sk_OSSL_PROPERTY_DEFINITION_push(sk, prop)) goto err; prop = NULL; done = !match_ch(&s, ','); } if (*s != '\0') { ERR_raise_data(ERR_LIB_PROP, PROP_R_TRAILING_CHARACTERS, "HERE-->%s", s); goto err; } res = stack_to_property_list(ctx, sk); err: OPENSSL_free(prop); sk_OSSL_PROPERTY_DEFINITION_pop_free(sk, &pd_free); return res; } /* * Compare a query against a definition. * Return the number of clauses matched or -1 if a mandatory clause is false. */ int ossl_property_match_count(const OSSL_PROPERTY_LIST *query, const OSSL_PROPERTY_LIST *defn) { const OSSL_PROPERTY_DEFINITION *const q = query->properties; const OSSL_PROPERTY_DEFINITION *const d = defn->properties; int i = 0, j = 0, matches = 0; OSSL_PROPERTY_OPER oper; while (i < query->num_properties) { if ((oper = q[i].oper) == OSSL_PROPERTY_OVERRIDE) { i++; continue; } if (j < defn->num_properties) { if (q[i].name_idx > d[j].name_idx) { /* skip defn, not in query */ j++; continue; } if (q[i].name_idx == d[j].name_idx) { /* both in defn and query */ const int eq = q[i].type == d[j].type && memcmp(&q[i].v, &d[j].v, sizeof(q[i].v)) == 0; if ((eq && oper == OSSL_PROPERTY_OPER_EQ) || (!eq && oper == OSSL_PROPERTY_OPER_NE)) matches++; else if (!q[i].optional) return -1; i++; j++; continue; } } /* * Handle the cases of a missing value and a query with no corresponding * definition. The former fails for any comparison except inequality, * the latter is treated as a comparison against the Boolean false. */ if (q[i].type == OSSL_PROPERTY_TYPE_VALUE_UNDEFINED) { if (oper == OSSL_PROPERTY_OPER_NE) matches++; else if (!q[i].optional) return -1; } else if (q[i].type != OSSL_PROPERTY_TYPE_STRING || (oper == OSSL_PROPERTY_OPER_EQ && q[i].v.str_val != OSSL_PROPERTY_FALSE) || (oper == OSSL_PROPERTY_OPER_NE && q[i].v.str_val == OSSL_PROPERTY_FALSE)) { if (!q[i].optional) return -1; } else { matches++; } i++; } return matches; } void ossl_property_free(OSSL_PROPERTY_LIST *p) { OPENSSL_free(p); } /* * Merge two property lists. * If there is a common name, the one from the first list is used. */ OSSL_PROPERTY_LIST *ossl_property_merge(const OSSL_PROPERTY_LIST *a, const OSSL_PROPERTY_LIST *b) { const OSSL_PROPERTY_DEFINITION *const ap = a->properties; const OSSL_PROPERTY_DEFINITION *const bp = b->properties; const OSSL_PROPERTY_DEFINITION *copy; OSSL_PROPERTY_LIST *r; int i, j, n; const int t = a->num_properties + b->num_properties; r = OPENSSL_malloc(sizeof(*r) + (t == 0 ? 0 : t - 1) * sizeof(r->properties[0])); if (r == NULL) return NULL; r->has_optional = 0; for (i = j = n = 0; i < a->num_properties || j < b->num_properties; n++) { if (i >= a->num_properties) { copy = &bp[j++]; } else if (j >= b->num_properties) { copy = &ap[i++]; } else if (ap[i].name_idx <= bp[j].name_idx) { if (ap[i].name_idx == bp[j].name_idx) j++; copy = &ap[i++]; } else { copy = &bp[j++]; } memcpy(r->properties + n, copy, sizeof(r->properties[0])); r->has_optional |= copy->optional; } r->num_properties = n; if (n != t) r = OPENSSL_realloc(r, sizeof(*r) + (n - 1) * sizeof(r->properties[0])); return r; } int ossl_property_parse_init(OSSL_LIB_CTX *ctx) { static const char *const predefined_names[] = { "provider", /* Name of provider (default, legacy, fips) */ "version", /* Version number of this provider */ "fips", /* FIPS validated or FIPS supporting algorithm */ "output", /* Output type for encoders */ "input", /* Input type for decoders */ "structure", /* Structure name for encoders and decoders */ }; size_t i; for (i = 0; i < OSSL_NELEM(predefined_names); i++) if (ossl_property_name(ctx, predefined_names[i], 1) == 0) goto err; /* * Pre-populate the two Boolean values. We must do them before any other * values and in this order so that we get the same index as the global * OSSL_PROPERTY_TRUE and OSSL_PROPERTY_FALSE values */ if ((ossl_property_value(ctx, "yes", 1) != OSSL_PROPERTY_TRUE) || (ossl_property_value(ctx, "no", 1) != OSSL_PROPERTY_FALSE)) goto err; return 1; err: return 0; } static void put_char(char ch, char **buf, size_t *remain, size_t *needed) { if (*remain == 0) { ++*needed; return; } if (*remain == 1) **buf = '\0'; else **buf = ch; ++*buf; ++*needed; --*remain; } static void put_str(const char *str, char **buf, size_t *remain, size_t *needed) { - size_t olen, len; + size_t olen, len, i; + char quote = '\0'; + int quotes; len = olen = strlen(str); *needed += len; - if (*remain == 0) + /* + * Check to see if we need quotes or not. + * Characters that are legal in a PropertyName don't need quoting. + * We simply assume all others require quotes. + */ + for (i = 0; i < len; i++) + if (!ossl_isalnum(str[i]) && str[i] != '.' && str[i] != '_') { + /* Default to single quotes ... */ + if (quote == '\0') + quote = '\''; + /* ... but use double quotes if a single is present */ + if (str[i] == '\'') + quote = '"'; + } + + quotes = quote != '\0'; + if (*remain == 0) { + *needed += 2 * quotes; return; + } - if (*remain < len + 1) + if (quotes) + put_char(quote, buf, remain, needed); + + if (*remain < len + 1 + quotes) len = *remain - 1; if (len > 0) { memcpy(*buf, str, len); *buf += len; *remain -= len; } + if (quotes) + put_char(quote, buf, remain, needed); + if (len < olen && *remain == 1) { **buf = '\0'; ++*buf; --*remain; } } static void put_num(int64_t val, char **buf, size_t *remain, size_t *needed) { int64_t tmpval = val; size_t len = 1; if (tmpval < 0) { len++; tmpval = -tmpval; } for (; tmpval > 9; len++, tmpval /= 10); *needed += len; if (*remain == 0) return; BIO_snprintf(*buf, *remain, "%lld", (long long int)val); if (*remain < len) { *buf += *remain; *remain = 0; } else { *buf += len; *remain -= len; } } size_t ossl_property_list_to_string(OSSL_LIB_CTX *ctx, const OSSL_PROPERTY_LIST *list, char *buf, size_t bufsize) { int i; const OSSL_PROPERTY_DEFINITION *prop = NULL; size_t needed = 0; const char *val; if (list == NULL) { if (bufsize > 0) *buf = '\0'; return 1; } if (list->num_properties != 0) prop = &list->properties[list->num_properties - 1]; for (i = 0; i < list->num_properties; i++, prop--) { /* Skip invalid names */ if (prop->name_idx == 0) continue; if (needed > 0) put_char(',', &buf, &bufsize, &needed); if (prop->optional) put_char('?', &buf, &bufsize, &needed); else if (prop->oper == OSSL_PROPERTY_OVERRIDE) put_char('-', &buf, &bufsize, &needed); val = ossl_property_name_str(ctx, prop->name_idx); if (val == NULL) return 0; put_str(val, &buf, &bufsize, &needed); switch (prop->oper) { case OSSL_PROPERTY_OPER_NE: put_char('!', &buf, &bufsize, &needed); /* fall through */ case OSSL_PROPERTY_OPER_EQ: put_char('=', &buf, &bufsize, &needed); /* put value */ switch (prop->type) { case OSSL_PROPERTY_TYPE_STRING: val = ossl_property_value_str(ctx, prop->v.str_val); if (val == NULL) return 0; put_str(val, &buf, &bufsize, &needed); break; case OSSL_PROPERTY_TYPE_NUMBER: put_num(prop->v.int_val, &buf, &bufsize, &needed); break; default: return 0; } break; default: /* do nothing */ break; } } put_char('\0', &buf, &bufsize, &needed); return needed; } diff --git a/crypto/openssl/crypto/rsa/rsa_backend.c b/crypto/openssl/crypto/rsa/rsa_backend.c index 58187fa2ef59..f9d1cb361d77 100644 --- a/crypto/openssl/crypto/rsa/rsa_backend.c +++ b/crypto/openssl/crypto/rsa/rsa_backend.c @@ -1,595 +1,583 @@ /* - * Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2020-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ /* * RSA low level APIs are deprecated for public use, but still ok for * internal use. */ #include "internal/deprecated.h" #include #include #include #include #include #ifndef FIPS_MODULE # include # include "crypto/asn1.h" #endif #include "internal/sizes.h" #include "internal/param_build_set.h" #include "crypto/rsa.h" #include "rsa_local.h" /* * The intention with the "backend" source file is to offer backend support * for legacy backends (EVP_PKEY_ASN1_METHOD and EVP_PKEY_METHOD) and provider * implementations alike. */ DEFINE_STACK_OF(BIGNUM) static int collect_numbers(STACK_OF(BIGNUM) *numbers, const OSSL_PARAM params[], const char *names[]) { const OSSL_PARAM *p = NULL; int i; if (numbers == NULL) return 0; for (i = 0; names[i] != NULL; i++){ p = OSSL_PARAM_locate_const(params, names[i]); if (p != NULL) { BIGNUM *tmp = NULL; if (!OSSL_PARAM_get_BN(p, &tmp)) return 0; if (sk_BIGNUM_push(numbers, tmp) == 0) { BN_clear_free(tmp); return 0; } } } return 1; } int ossl_rsa_fromdata(RSA *rsa, const OSSL_PARAM params[], int include_private) { const OSSL_PARAM *param_n, *param_e, *param_d = NULL; BIGNUM *n = NULL, *e = NULL, *d = NULL; STACK_OF(BIGNUM) *factors = NULL, *exps = NULL, *coeffs = NULL; int is_private = 0; if (rsa == NULL) return 0; param_n = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_N); param_e = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_E); if (include_private) param_d = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_D); if ((param_n != NULL && !OSSL_PARAM_get_BN(param_n, &n)) || (param_e != NULL && !OSSL_PARAM_get_BN(param_e, &e)) || (param_d != NULL && !OSSL_PARAM_get_BN(param_d, &d))) goto err; is_private = (d != NULL); if (!RSA_set0_key(rsa, n, e, d)) goto err; n = e = d = NULL; if (is_private) { if (!collect_numbers(factors = sk_BIGNUM_new_null(), params, ossl_rsa_mp_factor_names) || !collect_numbers(exps = sk_BIGNUM_new_null(), params, ossl_rsa_mp_exp_names) || !collect_numbers(coeffs = sk_BIGNUM_new_null(), params, ossl_rsa_mp_coeff_names)) goto err; /* It's ok if this private key just has n, e and d */ if (sk_BIGNUM_num(factors) != 0 && !ossl_rsa_set0_all_params(rsa, factors, exps, coeffs)) goto err; } sk_BIGNUM_free(factors); sk_BIGNUM_free(exps); sk_BIGNUM_free(coeffs); return 1; err: BN_free(n); BN_free(e); BN_free(d); sk_BIGNUM_pop_free(factors, BN_free); sk_BIGNUM_pop_free(exps, BN_free); sk_BIGNUM_pop_free(coeffs, BN_free); return 0; } DEFINE_SPECIAL_STACK_OF_CONST(BIGNUM_const, BIGNUM) int ossl_rsa_todata(RSA *rsa, OSSL_PARAM_BLD *bld, OSSL_PARAM params[], int include_private) { int ret = 0; const BIGNUM *rsa_d = NULL, *rsa_n = NULL, *rsa_e = NULL; STACK_OF(BIGNUM_const) *factors = sk_BIGNUM_const_new_null(); STACK_OF(BIGNUM_const) *exps = sk_BIGNUM_const_new_null(); STACK_OF(BIGNUM_const) *coeffs = sk_BIGNUM_const_new_null(); if (rsa == NULL || factors == NULL || exps == NULL || coeffs == NULL) goto err; RSA_get0_key(rsa, &rsa_n, &rsa_e, &rsa_d); ossl_rsa_get0_all_params(rsa, factors, exps, coeffs); if (!ossl_param_build_set_bn(bld, params, OSSL_PKEY_PARAM_RSA_N, rsa_n) || !ossl_param_build_set_bn(bld, params, OSSL_PKEY_PARAM_RSA_E, rsa_e)) goto err; /* Check private key data integrity */ if (include_private && rsa_d != NULL) { - int numprimes = sk_BIGNUM_const_num(factors); - int numexps = sk_BIGNUM_const_num(exps); - int numcoeffs = sk_BIGNUM_const_num(coeffs); - - /* - * It's permissible to have zero primes, i.e. no CRT params. - * Otherwise, there must be at least two, as many exponents, - * and one coefficient less. - */ - if (numprimes != 0 - && (numprimes < 2 || numexps < 2 || numcoeffs < 1)) - goto err; if (!ossl_param_build_set_bn(bld, params, OSSL_PKEY_PARAM_RSA_D, rsa_d) || !ossl_param_build_set_multi_key_bn(bld, params, ossl_rsa_mp_factor_names, factors) || !ossl_param_build_set_multi_key_bn(bld, params, ossl_rsa_mp_exp_names, exps) || !ossl_param_build_set_multi_key_bn(bld, params, ossl_rsa_mp_coeff_names, coeffs)) goto err; } #if defined(FIPS_MODULE) && !defined(OPENSSL_NO_ACVP_TESTS) /* The acvp test results are not meant for export so check for bld == NULL */ if (bld == NULL) ossl_rsa_acvp_test_get_params(rsa, params); #endif ret = 1; err: sk_BIGNUM_const_free(factors); sk_BIGNUM_const_free(exps); sk_BIGNUM_const_free(coeffs); return ret; } int ossl_rsa_pss_params_30_todata(const RSA_PSS_PARAMS_30 *pss, OSSL_PARAM_BLD *bld, OSSL_PARAM params[]) { if (!ossl_rsa_pss_params_30_is_unrestricted(pss)) { int hashalg_nid = ossl_rsa_pss_params_30_hashalg(pss); int maskgenalg_nid = ossl_rsa_pss_params_30_maskgenalg(pss); int maskgenhashalg_nid = ossl_rsa_pss_params_30_maskgenhashalg(pss); int saltlen = ossl_rsa_pss_params_30_saltlen(pss); int default_hashalg_nid = ossl_rsa_pss_params_30_hashalg(NULL); int default_maskgenalg_nid = ossl_rsa_pss_params_30_maskgenalg(NULL); int default_maskgenhashalg_nid = ossl_rsa_pss_params_30_maskgenhashalg(NULL); const char *mdname = (hashalg_nid == default_hashalg_nid ? NULL : ossl_rsa_oaeppss_nid2name(hashalg_nid)); const char *mgfname = (maskgenalg_nid == default_maskgenalg_nid ? NULL : ossl_rsa_oaeppss_nid2name(maskgenalg_nid)); const char *mgf1mdname = (maskgenhashalg_nid == default_maskgenhashalg_nid ? NULL : ossl_rsa_oaeppss_nid2name(maskgenhashalg_nid)); const char *key_md = OSSL_PKEY_PARAM_RSA_DIGEST; const char *key_mgf = OSSL_PKEY_PARAM_RSA_MASKGENFUNC; const char *key_mgf1_md = OSSL_PKEY_PARAM_RSA_MGF1_DIGEST; const char *key_saltlen = OSSL_PKEY_PARAM_RSA_PSS_SALTLEN; /* * To ensure that the key isn't seen as unrestricted by the recipient, * we make sure that at least one PSS-related parameter is passed, even * if it has a default value; saltlen. */ if ((mdname != NULL && !ossl_param_build_set_utf8_string(bld, params, key_md, mdname)) || (mgfname != NULL && !ossl_param_build_set_utf8_string(bld, params, key_mgf, mgfname)) || (mgf1mdname != NULL && !ossl_param_build_set_utf8_string(bld, params, key_mgf1_md, mgf1mdname)) || (!ossl_param_build_set_int(bld, params, key_saltlen, saltlen))) return 0; } return 1; } int ossl_rsa_pss_params_30_fromdata(RSA_PSS_PARAMS_30 *pss_params, int *defaults_set, const OSSL_PARAM params[], OSSL_LIB_CTX *libctx) { const OSSL_PARAM *param_md, *param_mgf, *param_mgf1md, *param_saltlen; const OSSL_PARAM *param_propq; const char *propq = NULL; EVP_MD *md = NULL, *mgf1md = NULL; int saltlen; int ret = 0; if (pss_params == NULL) return 0; param_propq = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_DIGEST_PROPS); param_md = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_DIGEST); param_mgf = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_MASKGENFUNC); param_mgf1md = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_MGF1_DIGEST); param_saltlen = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_PSS_SALTLEN); if (param_propq != NULL) { if (param_propq->data_type == OSSL_PARAM_UTF8_STRING) propq = param_propq->data; } /* * If we get any of the parameters, we know we have at least some * restrictions, so we start by setting default values, and let each * parameter override their specific restriction data. */ if (!*defaults_set && (param_md != NULL || param_mgf != NULL || param_mgf1md != NULL || param_saltlen != NULL)) { if (!ossl_rsa_pss_params_30_set_defaults(pss_params)) return 0; *defaults_set = 1; } if (param_mgf != NULL) { int default_maskgenalg_nid = ossl_rsa_pss_params_30_maskgenalg(NULL); const char *mgfname = NULL; if (param_mgf->data_type == OSSL_PARAM_UTF8_STRING) mgfname = param_mgf->data; else if (!OSSL_PARAM_get_utf8_ptr(param_mgf, &mgfname)) return 0; if (OPENSSL_strcasecmp(param_mgf->data, ossl_rsa_mgf_nid2name(default_maskgenalg_nid)) != 0) return 0; } /* * We're only interested in the NIDs that correspond to the MDs, so the * exact propquery is unimportant in the EVP_MD_fetch() calls below. */ if (param_md != NULL) { const char *mdname = NULL; if (param_md->data_type == OSSL_PARAM_UTF8_STRING) mdname = param_md->data; else if (!OSSL_PARAM_get_utf8_ptr(param_mgf, &mdname)) goto err; if ((md = EVP_MD_fetch(libctx, mdname, propq)) == NULL || !ossl_rsa_pss_params_30_set_hashalg(pss_params, ossl_rsa_oaeppss_md2nid(md))) goto err; } if (param_mgf1md != NULL) { const char *mgf1mdname = NULL; if (param_mgf1md->data_type == OSSL_PARAM_UTF8_STRING) mgf1mdname = param_mgf1md->data; else if (!OSSL_PARAM_get_utf8_ptr(param_mgf, &mgf1mdname)) goto err; if ((mgf1md = EVP_MD_fetch(libctx, mgf1mdname, propq)) == NULL || !ossl_rsa_pss_params_30_set_maskgenhashalg( pss_params, ossl_rsa_oaeppss_md2nid(mgf1md))) goto err; } if (param_saltlen != NULL) { if (!OSSL_PARAM_get_int(param_saltlen, &saltlen) || !ossl_rsa_pss_params_30_set_saltlen(pss_params, saltlen)) goto err; } ret = 1; err: EVP_MD_free(md); EVP_MD_free(mgf1md); return ret; } int ossl_rsa_is_foreign(const RSA *rsa) { #ifndef FIPS_MODULE if (rsa->engine != NULL || RSA_get_method(rsa) != RSA_PKCS1_OpenSSL()) return 1; #endif return 0; } static ossl_inline int rsa_bn_dup_check(BIGNUM **out, const BIGNUM *f) { if (f != NULL && (*out = BN_dup(f)) == NULL) return 0; return 1; } RSA *ossl_rsa_dup(const RSA *rsa, int selection) { RSA *dupkey = NULL; #ifndef FIPS_MODULE int pnum, i; #endif /* Do not try to duplicate foreign RSA keys */ if (ossl_rsa_is_foreign(rsa)) return NULL; if ((dupkey = ossl_rsa_new_with_ctx(rsa->libctx)) == NULL) return NULL; /* public key */ if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) { if (!rsa_bn_dup_check(&dupkey->n, rsa->n)) goto err; if (!rsa_bn_dup_check(&dupkey->e, rsa->e)) goto err; } if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) { /* private key */ if (!rsa_bn_dup_check(&dupkey->d, rsa->d)) goto err; /* factors and crt params */ if (!rsa_bn_dup_check(&dupkey->p, rsa->p)) goto err; if (!rsa_bn_dup_check(&dupkey->q, rsa->q)) goto err; if (!rsa_bn_dup_check(&dupkey->dmp1, rsa->dmp1)) goto err; if (!rsa_bn_dup_check(&dupkey->dmq1, rsa->dmq1)) goto err; if (!rsa_bn_dup_check(&dupkey->iqmp, rsa->iqmp)) goto err; } dupkey->version = rsa->version; dupkey->flags = rsa->flags; /* we always copy the PSS parameters regardless of selection */ dupkey->pss_params = rsa->pss_params; #ifndef FIPS_MODULE /* multiprime */ if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0 && (pnum = sk_RSA_PRIME_INFO_num(rsa->prime_infos)) > 0) { dupkey->prime_infos = sk_RSA_PRIME_INFO_new_reserve(NULL, pnum); if (dupkey->prime_infos == NULL) goto err; for (i = 0; i < pnum; i++) { const RSA_PRIME_INFO *pinfo = NULL; RSA_PRIME_INFO *duppinfo = NULL; if ((duppinfo = OPENSSL_zalloc(sizeof(*duppinfo))) == NULL) { ERR_raise(ERR_LIB_RSA, ERR_R_MALLOC_FAILURE); goto err; } /* push first so cleanup in error case works */ (void)sk_RSA_PRIME_INFO_push(dupkey->prime_infos, duppinfo); pinfo = sk_RSA_PRIME_INFO_value(rsa->prime_infos, i); if (!rsa_bn_dup_check(&duppinfo->r, pinfo->r)) goto err; if (!rsa_bn_dup_check(&duppinfo->d, pinfo->d)) goto err; if (!rsa_bn_dup_check(&duppinfo->t, pinfo->t)) goto err; } if (!ossl_rsa_multip_calc_product(dupkey)) goto err; } if (rsa->pss != NULL) { dupkey->pss = RSA_PSS_PARAMS_dup(rsa->pss); if (rsa->pss->maskGenAlgorithm != NULL && dupkey->pss->maskGenAlgorithm == NULL) { dupkey->pss->maskHash = ossl_x509_algor_mgf1_decode(rsa->pss->maskGenAlgorithm); if (dupkey->pss->maskHash == NULL) goto err; } } if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_RSA, &dupkey->ex_data, &rsa->ex_data)) goto err; #endif return dupkey; err: RSA_free(dupkey); return NULL; } #ifndef FIPS_MODULE RSA_PSS_PARAMS *ossl_rsa_pss_decode(const X509_ALGOR *alg) { RSA_PSS_PARAMS *pss; pss = ASN1_TYPE_unpack_sequence(ASN1_ITEM_rptr(RSA_PSS_PARAMS), alg->parameter); if (pss == NULL) return NULL; if (pss->maskGenAlgorithm != NULL) { pss->maskHash = ossl_x509_algor_mgf1_decode(pss->maskGenAlgorithm); if (pss->maskHash == NULL) { RSA_PSS_PARAMS_free(pss); return NULL; } } return pss; } static int ossl_rsa_sync_to_pss_params_30(RSA *rsa) { const RSA_PSS_PARAMS *legacy_pss = NULL; RSA_PSS_PARAMS_30 *pss = NULL; if (rsa != NULL && (legacy_pss = RSA_get0_pss_params(rsa)) != NULL && (pss = ossl_rsa_get0_pss_params_30(rsa)) != NULL) { const EVP_MD *md = NULL, *mgf1md = NULL; int md_nid, mgf1md_nid, saltlen, trailerField; RSA_PSS_PARAMS_30 pss_params; /* * We don't care about the validity of the fields here, we just * want to synchronise values. Verifying here makes it impossible * to even read a key with invalid values, making it hard to test * a bad situation. * * Other routines use ossl_rsa_pss_get_param(), so the values will * be checked, eventually. */ if (!ossl_rsa_pss_get_param_unverified(legacy_pss, &md, &mgf1md, &saltlen, &trailerField)) return 0; md_nid = EVP_MD_get_type(md); mgf1md_nid = EVP_MD_get_type(mgf1md); if (!ossl_rsa_pss_params_30_set_defaults(&pss_params) || !ossl_rsa_pss_params_30_set_hashalg(&pss_params, md_nid) || !ossl_rsa_pss_params_30_set_maskgenhashalg(&pss_params, mgf1md_nid) || !ossl_rsa_pss_params_30_set_saltlen(&pss_params, saltlen) || !ossl_rsa_pss_params_30_set_trailerfield(&pss_params, trailerField)) return 0; *pss = pss_params; } return 1; } int ossl_rsa_pss_get_param_unverified(const RSA_PSS_PARAMS *pss, const EVP_MD **pmd, const EVP_MD **pmgf1md, int *psaltlen, int *ptrailerField) { RSA_PSS_PARAMS_30 pss_params; /* Get the defaults from the ONE place */ (void)ossl_rsa_pss_params_30_set_defaults(&pss_params); if (pss == NULL) return 0; *pmd = ossl_x509_algor_get_md(pss->hashAlgorithm); if (*pmd == NULL) return 0; *pmgf1md = ossl_x509_algor_get_md(pss->maskHash); if (*pmgf1md == NULL) return 0; if (pss->saltLength) *psaltlen = ASN1_INTEGER_get(pss->saltLength); else *psaltlen = ossl_rsa_pss_params_30_saltlen(&pss_params); if (pss->trailerField) *ptrailerField = ASN1_INTEGER_get(pss->trailerField); else *ptrailerField = ossl_rsa_pss_params_30_trailerfield(&pss_params);; return 1; } int ossl_rsa_param_decode(RSA *rsa, const X509_ALGOR *alg) { RSA_PSS_PARAMS *pss; const ASN1_OBJECT *algoid; const void *algp; int algptype; X509_ALGOR_get0(&algoid, &algptype, &algp, alg); if (OBJ_obj2nid(algoid) != EVP_PKEY_RSA_PSS) return 1; if (algptype == V_ASN1_UNDEF) return 1; if (algptype != V_ASN1_SEQUENCE) { ERR_raise(ERR_LIB_RSA, RSA_R_INVALID_PSS_PARAMETERS); return 0; } if ((pss = ossl_rsa_pss_decode(alg)) == NULL || !ossl_rsa_set0_pss_params(rsa, pss)) { RSA_PSS_PARAMS_free(pss); return 0; } if (!ossl_rsa_sync_to_pss_params_30(rsa)) return 0; return 1; } RSA *ossl_rsa_key_from_pkcs8(const PKCS8_PRIV_KEY_INFO *p8inf, OSSL_LIB_CTX *libctx, const char *propq) { const unsigned char *p; RSA *rsa; int pklen; const X509_ALGOR *alg; if (!PKCS8_pkey_get0(NULL, &p, &pklen, &alg, p8inf)) return 0; rsa = d2i_RSAPrivateKey(NULL, &p, pklen); if (rsa == NULL) { ERR_raise(ERR_LIB_RSA, ERR_R_RSA_LIB); return NULL; } if (!ossl_rsa_param_decode(rsa, alg)) { RSA_free(rsa); return NULL; } RSA_clear_flags(rsa, RSA_FLAG_TYPE_MASK); switch (OBJ_obj2nid(alg->algorithm)) { case EVP_PKEY_RSA: RSA_set_flags(rsa, RSA_FLAG_TYPE_RSA); break; case EVP_PKEY_RSA_PSS: RSA_set_flags(rsa, RSA_FLAG_TYPE_RSASSAPSS); break; default: /* Leave the type bits zero */ break; } return rsa; } #endif diff --git a/crypto/openssl/crypto/rsa/rsa_lib.c b/crypto/openssl/crypto/rsa/rsa_lib.c index 449097b8b27a..71a17a92349d 100644 --- a/crypto/openssl/crypto/rsa/rsa_lib.c +++ b/crypto/openssl/crypto/rsa/rsa_lib.c @@ -1,1282 +1,1296 @@ /* - * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ /* * RSA low level APIs are deprecated for public use, but still ok for * internal use. */ #include "internal/deprecated.h" #include #include #ifndef FIPS_MODULE # include #endif #include #include #include "internal/cryptlib.h" #include "internal/refcount.h" #include "crypto/bn.h" #include "crypto/evp.h" #include "crypto/rsa.h" #include "crypto/security_bits.h" #include "rsa_local.h" static RSA *rsa_new_intern(ENGINE *engine, OSSL_LIB_CTX *libctx); #ifndef FIPS_MODULE RSA *RSA_new(void) { return rsa_new_intern(NULL, NULL); } const RSA_METHOD *RSA_get_method(const RSA *rsa) { return rsa->meth; } int RSA_set_method(RSA *rsa, const RSA_METHOD *meth) { /* * NB: The caller is specifically setting a method, so it's not up to us * to deal with which ENGINE it comes from. */ const RSA_METHOD *mtmp; mtmp = rsa->meth; if (mtmp->finish) mtmp->finish(rsa); #ifndef OPENSSL_NO_ENGINE ENGINE_finish(rsa->engine); rsa->engine = NULL; #endif rsa->meth = meth; if (meth->init) meth->init(rsa); return 1; } RSA *RSA_new_method(ENGINE *engine) { return rsa_new_intern(engine, NULL); } #endif RSA *ossl_rsa_new_with_ctx(OSSL_LIB_CTX *libctx) { return rsa_new_intern(NULL, libctx); } static RSA *rsa_new_intern(ENGINE *engine, OSSL_LIB_CTX *libctx) { RSA *ret = OPENSSL_zalloc(sizeof(*ret)); if (ret == NULL) { ERR_raise(ERR_LIB_RSA, ERR_R_MALLOC_FAILURE); return NULL; } ret->references = 1; ret->lock = CRYPTO_THREAD_lock_new(); if (ret->lock == NULL) { ERR_raise(ERR_LIB_RSA, ERR_R_MALLOC_FAILURE); OPENSSL_free(ret); return NULL; } ret->libctx = libctx; ret->meth = RSA_get_default_method(); #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) ret->flags = ret->meth->flags & ~RSA_FLAG_NON_FIPS_ALLOW; if (engine) { if (!ENGINE_init(engine)) { ERR_raise(ERR_LIB_RSA, ERR_R_ENGINE_LIB); goto err; } ret->engine = engine; } else { ret->engine = ENGINE_get_default_RSA(); } if (ret->engine) { ret->meth = ENGINE_get_RSA(ret->engine); if (ret->meth == NULL) { ERR_raise(ERR_LIB_RSA, ERR_R_ENGINE_LIB); goto err; } } #endif ret->flags = ret->meth->flags & ~RSA_FLAG_NON_FIPS_ALLOW; #ifndef FIPS_MODULE if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data)) { goto err; } #endif if ((ret->meth->init != NULL) && !ret->meth->init(ret)) { ERR_raise(ERR_LIB_RSA, ERR_R_INIT_FAIL); goto err; } return ret; err: RSA_free(ret); return NULL; } void RSA_free(RSA *r) { int i; if (r == NULL) return; CRYPTO_DOWN_REF(&r->references, &i, r->lock); REF_PRINT_COUNT("RSA", r); if (i > 0) return; REF_ASSERT_ISNT(i < 0); if (r->meth != NULL && r->meth->finish != NULL) r->meth->finish(r); #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) ENGINE_finish(r->engine); #endif #ifndef FIPS_MODULE CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, r, &r->ex_data); #endif CRYPTO_THREAD_lock_free(r->lock); BN_free(r->n); BN_free(r->e); BN_clear_free(r->d); BN_clear_free(r->p); BN_clear_free(r->q); BN_clear_free(r->dmp1); BN_clear_free(r->dmq1); BN_clear_free(r->iqmp); #if defined(FIPS_MODULE) && !defined(OPENSSL_NO_ACVP_TESTS) ossl_rsa_acvp_test_free(r->acvp_test); #endif #ifndef FIPS_MODULE RSA_PSS_PARAMS_free(r->pss); sk_RSA_PRIME_INFO_pop_free(r->prime_infos, ossl_rsa_multip_info_free); #endif BN_BLINDING_free(r->blinding); BN_BLINDING_free(r->mt_blinding); OPENSSL_free(r); } int RSA_up_ref(RSA *r) { int i; if (CRYPTO_UP_REF(&r->references, &i, r->lock) <= 0) return 0; REF_PRINT_COUNT("RSA", r); REF_ASSERT_ISNT(i < 2); return i > 1 ? 1 : 0; } OSSL_LIB_CTX *ossl_rsa_get0_libctx(RSA *r) { return r->libctx; } void ossl_rsa_set0_libctx(RSA *r, OSSL_LIB_CTX *libctx) { r->libctx = libctx; } #ifndef FIPS_MODULE int RSA_set_ex_data(RSA *r, int idx, void *arg) { return CRYPTO_set_ex_data(&r->ex_data, idx, arg); } void *RSA_get_ex_data(const RSA *r, int idx) { return CRYPTO_get_ex_data(&r->ex_data, idx); } #endif /* * Define a scaling constant for our fixed point arithmetic. * This value must be a power of two because the base two logarithm code * makes this assumption. The exponent must also be a multiple of three so * that the scale factor has an exact cube root. Finally, the scale factor * should not be so large that a multiplication of two scaled numbers * overflows a 64 bit unsigned integer. */ static const unsigned int scale = 1 << 18; static const unsigned int cbrt_scale = 1 << (2 * 18 / 3); /* Define some constants, none exceed 32 bits */ static const unsigned int log_2 = 0x02c5c8; /* scale * log(2) */ static const unsigned int log_e = 0x05c551; /* scale * log2(M_E) */ static const unsigned int c1_923 = 0x07b126; /* scale * 1.923 */ static const unsigned int c4_690 = 0x12c28f; /* scale * 4.690 */ /* * Multiply two scaled integers together and rescale the result. */ static ossl_inline uint64_t mul2(uint64_t a, uint64_t b) { return a * b / scale; } /* * Calculate the cube root of a 64 bit scaled integer. * Although the cube root of a 64 bit number does fit into a 32 bit unsigned * integer, this is not guaranteed after scaling, so this function has a * 64 bit return. This uses the shifting nth root algorithm with some * algebraic simplifications. */ static uint64_t icbrt64(uint64_t x) { uint64_t r = 0; uint64_t b; int s; for (s = 63; s >= 0; s -= 3) { r <<= 1; b = 3 * r * (r + 1) + 1; if ((x >> s) >= b) { x -= b << s; r++; } } return r * cbrt_scale; } /* * Calculate the natural logarithm of a 64 bit scaled integer. * This is done by calculating a base two logarithm and scaling. * The maximum logarithm (base 2) is 64 and this reduces base e, so * a 32 bit result should not overflow. The argument passed must be * greater than unity so we don't need to handle negative results. */ static uint32_t ilog_e(uint64_t v) { uint32_t i, r = 0; /* * Scale down the value into the range 1 .. 2. * * If fractional numbers need to be processed, another loop needs * to go here that checks v < scale and if so multiplies it by 2 and * reduces r by scale. This also means making r signed. */ while (v >= 2 * scale) { v >>= 1; r += scale; } for (i = scale / 2; i != 0; i /= 2) { v = mul2(v, v); if (v >= 2 * scale) { v >>= 1; r += i; } } r = (r * (uint64_t)scale) / log_e; return r; } /* * NIST SP 800-56B rev 2 Appendix D: Maximum Security Strength Estimates for IFC * Modulus Lengths. * * Note that this formula is also referred to in SP800-56A rev3 Appendix D: * for FFC safe prime groups for modp and ffdhe. * After Table 25 and Table 26 it refers to * "The maximum security strength estimates were calculated using the formula in * Section 7.5 of the FIPS 140 IG and rounded to the nearest multiple of eight * bits". * * The formula is: * * E = \frac{1.923 \sqrt[3]{nBits \cdot log_e(2)} * \cdot(log_e(nBits \cdot log_e(2))^{2/3} - 4.69}{log_e(2)} * The two cube roots are merged together here. */ uint16_t ossl_ifc_ffc_compute_security_bits(int n) { uint64_t x; uint32_t lx; uint16_t y, cap; /* * Look for common values as listed in standards. * These values are not exactly equal to the results from the formulae in * the standards but are defined to be canonical. */ switch (n) { case 2048: /* SP 800-56B rev 2 Appendix D and FIPS 140-2 IG 7.5 */ return 112; case 3072: /* SP 800-56B rev 2 Appendix D and FIPS 140-2 IG 7.5 */ return 128; case 4096: /* SP 800-56B rev 2 Appendix D */ return 152; case 6144: /* SP 800-56B rev 2 Appendix D */ return 176; case 7680: /* FIPS 140-2 IG 7.5 */ return 192; case 8192: /* SP 800-56B rev 2 Appendix D */ return 200; case 15360: /* FIPS 140-2 IG 7.5 */ return 256; } /* * The first incorrect result (i.e. not accurate or off by one low) occurs * for n = 699668. The true value here is 1200. Instead of using this n * as the check threshold, the smallest n such that the correct result is * 1200 is used instead. */ if (n >= 687737) return 1200; if (n < 8) return 0; /* * To ensure that the output is non-decreasing with respect to n, * a cap needs to be applied to the two values where the function over * estimates the strength (according to the above fast path). */ if (n <= 7680) cap = 192; else if (n <= 15360) cap = 256; else cap = 1200; x = n * (uint64_t)log_2; lx = ilog_e(x); y = (uint16_t)((mul2(c1_923, icbrt64(mul2(mul2(x, lx), lx))) - c4_690) / log_2); y = (y + 4) & ~7; if (y > cap) y = cap; return y; } int RSA_security_bits(const RSA *rsa) { int bits = BN_num_bits(rsa->n); #ifndef FIPS_MODULE if (rsa->version == RSA_ASN1_VERSION_MULTI) { /* This ought to mean that we have private key at hand. */ int ex_primes = sk_RSA_PRIME_INFO_num(rsa->prime_infos); if (ex_primes <= 0 || (ex_primes + 2) > ossl_rsa_multip_cap(bits)) return 0; } #endif return ossl_ifc_ffc_compute_security_bits(bits); } int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d) { /* If the fields n and e in r are NULL, the corresponding input * parameters MUST be non-NULL for n and e. d may be * left NULL (in case only the public key is used). */ if ((r->n == NULL && n == NULL) || (r->e == NULL && e == NULL)) return 0; if (n != NULL) { BN_free(r->n); r->n = n; } if (e != NULL) { BN_free(r->e); r->e = e; } if (d != NULL) { BN_clear_free(r->d); r->d = d; BN_set_flags(r->d, BN_FLG_CONSTTIME); } r->dirty_cnt++; return 1; } int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q) { /* If the fields p and q in r are NULL, the corresponding input * parameters MUST be non-NULL. */ if ((r->p == NULL && p == NULL) || (r->q == NULL && q == NULL)) return 0; if (p != NULL) { BN_clear_free(r->p); r->p = p; BN_set_flags(r->p, BN_FLG_CONSTTIME); } if (q != NULL) { BN_clear_free(r->q); r->q = q; BN_set_flags(r->q, BN_FLG_CONSTTIME); } r->dirty_cnt++; return 1; } int RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp) { /* If the fields dmp1, dmq1 and iqmp in r are NULL, the corresponding input * parameters MUST be non-NULL. */ if ((r->dmp1 == NULL && dmp1 == NULL) || (r->dmq1 == NULL && dmq1 == NULL) || (r->iqmp == NULL && iqmp == NULL)) return 0; if (dmp1 != NULL) { BN_clear_free(r->dmp1); r->dmp1 = dmp1; BN_set_flags(r->dmp1, BN_FLG_CONSTTIME); } if (dmq1 != NULL) { BN_clear_free(r->dmq1); r->dmq1 = dmq1; BN_set_flags(r->dmq1, BN_FLG_CONSTTIME); } if (iqmp != NULL) { BN_clear_free(r->iqmp); r->iqmp = iqmp; BN_set_flags(r->iqmp, BN_FLG_CONSTTIME); } r->dirty_cnt++; return 1; } #ifndef FIPS_MODULE /* * Is it better to export RSA_PRIME_INFO structure * and related functions to let user pass a triplet? */ int RSA_set0_multi_prime_params(RSA *r, BIGNUM *primes[], BIGNUM *exps[], BIGNUM *coeffs[], int pnum) { STACK_OF(RSA_PRIME_INFO) *prime_infos, *old = NULL; RSA_PRIME_INFO *pinfo; int i; if (primes == NULL || exps == NULL || coeffs == NULL || pnum == 0) return 0; prime_infos = sk_RSA_PRIME_INFO_new_reserve(NULL, pnum); if (prime_infos == NULL) return 0; if (r->prime_infos != NULL) old = r->prime_infos; for (i = 0; i < pnum; i++) { pinfo = ossl_rsa_multip_info_new(); if (pinfo == NULL) goto err; if (primes[i] != NULL && exps[i] != NULL && coeffs[i] != NULL) { BN_clear_free(pinfo->r); BN_clear_free(pinfo->d); BN_clear_free(pinfo->t); pinfo->r = primes[i]; pinfo->d = exps[i]; pinfo->t = coeffs[i]; BN_set_flags(pinfo->r, BN_FLG_CONSTTIME); BN_set_flags(pinfo->d, BN_FLG_CONSTTIME); BN_set_flags(pinfo->t, BN_FLG_CONSTTIME); } else { ossl_rsa_multip_info_free(pinfo); goto err; } (void)sk_RSA_PRIME_INFO_push(prime_infos, pinfo); } r->prime_infos = prime_infos; if (!ossl_rsa_multip_calc_product(r)) { r->prime_infos = old; goto err; } if (old != NULL) { /* * This is hard to deal with, since the old infos could * also be set by this function and r, d, t should not * be freed in that case. So currently, stay consistent * with other *set0* functions: just free it... */ sk_RSA_PRIME_INFO_pop_free(old, ossl_rsa_multip_info_free); } r->version = RSA_ASN1_VERSION_MULTI; r->dirty_cnt++; return 1; err: /* r, d, t should not be freed */ sk_RSA_PRIME_INFO_pop_free(prime_infos, ossl_rsa_multip_info_free_ex); return 0; } #endif void RSA_get0_key(const RSA *r, const BIGNUM **n, const BIGNUM **e, const BIGNUM **d) { if (n != NULL) *n = r->n; if (e != NULL) *e = r->e; if (d != NULL) *d = r->d; } void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q) { if (p != NULL) *p = r->p; if (q != NULL) *q = r->q; } #ifndef FIPS_MODULE int RSA_get_multi_prime_extra_count(const RSA *r) { int pnum; pnum = sk_RSA_PRIME_INFO_num(r->prime_infos); if (pnum <= 0) pnum = 0; return pnum; } int RSA_get0_multi_prime_factors(const RSA *r, const BIGNUM *primes[]) { int pnum, i; RSA_PRIME_INFO *pinfo; if ((pnum = RSA_get_multi_prime_extra_count(r)) == 0) return 0; /* * return other primes * it's caller's responsibility to allocate oth_primes[pnum] */ for (i = 0; i < pnum; i++) { pinfo = sk_RSA_PRIME_INFO_value(r->prime_infos, i); primes[i] = pinfo->r; } return 1; } #endif void RSA_get0_crt_params(const RSA *r, const BIGNUM **dmp1, const BIGNUM **dmq1, const BIGNUM **iqmp) { if (dmp1 != NULL) *dmp1 = r->dmp1; if (dmq1 != NULL) *dmq1 = r->dmq1; if (iqmp != NULL) *iqmp = r->iqmp; } #ifndef FIPS_MODULE int RSA_get0_multi_prime_crt_params(const RSA *r, const BIGNUM *exps[], const BIGNUM *coeffs[]) { int pnum; if ((pnum = RSA_get_multi_prime_extra_count(r)) == 0) return 0; /* return other primes */ if (exps != NULL || coeffs != NULL) { RSA_PRIME_INFO *pinfo; int i; /* it's the user's job to guarantee the buffer length */ for (i = 0; i < pnum; i++) { pinfo = sk_RSA_PRIME_INFO_value(r->prime_infos, i); if (exps != NULL) exps[i] = pinfo->d; if (coeffs != NULL) coeffs[i] = pinfo->t; } } return 1; } #endif const BIGNUM *RSA_get0_n(const RSA *r) { return r->n; } const BIGNUM *RSA_get0_e(const RSA *r) { return r->e; } const BIGNUM *RSA_get0_d(const RSA *r) { return r->d; } const BIGNUM *RSA_get0_p(const RSA *r) { return r->p; } const BIGNUM *RSA_get0_q(const RSA *r) { return r->q; } const BIGNUM *RSA_get0_dmp1(const RSA *r) { return r->dmp1; } const BIGNUM *RSA_get0_dmq1(const RSA *r) { return r->dmq1; } const BIGNUM *RSA_get0_iqmp(const RSA *r) { return r->iqmp; } const RSA_PSS_PARAMS *RSA_get0_pss_params(const RSA *r) { #ifdef FIPS_MODULE return NULL; #else return r->pss; #endif } /* Internal */ int ossl_rsa_set0_pss_params(RSA *r, RSA_PSS_PARAMS *pss) { #ifdef FIPS_MODULE return 0; #else RSA_PSS_PARAMS_free(r->pss); r->pss = pss; return 1; #endif } /* Internal */ RSA_PSS_PARAMS_30 *ossl_rsa_get0_pss_params_30(RSA *r) { return &r->pss_params; } void RSA_clear_flags(RSA *r, int flags) { r->flags &= ~flags; } int RSA_test_flags(const RSA *r, int flags) { return r->flags & flags; } void RSA_set_flags(RSA *r, int flags) { r->flags |= flags; } int RSA_get_version(RSA *r) { /* { two-prime(0), multi(1) } */ return r->version; } #ifndef FIPS_MODULE ENGINE *RSA_get0_engine(const RSA *r) { return r->engine; } int RSA_pkey_ctx_ctrl(EVP_PKEY_CTX *ctx, int optype, int cmd, int p1, void *p2) { /* If key type not RSA or RSA-PSS return error */ if (ctx != NULL && ctx->pmeth != NULL && ctx->pmeth->pkey_id != EVP_PKEY_RSA && ctx->pmeth->pkey_id != EVP_PKEY_RSA_PSS) return -1; return EVP_PKEY_CTX_ctrl(ctx, -1, optype, cmd, p1, p2); } #endif DEFINE_STACK_OF(BIGNUM) int ossl_rsa_set0_all_params(RSA *r, const STACK_OF(BIGNUM) *primes, const STACK_OF(BIGNUM) *exps, const STACK_OF(BIGNUM) *coeffs) { #ifndef FIPS_MODULE STACK_OF(RSA_PRIME_INFO) *prime_infos, *old_infos = NULL; #endif int pnum; if (primes == NULL || exps == NULL || coeffs == NULL) return 0; pnum = sk_BIGNUM_num(primes); - if (pnum < 2 - || pnum != sk_BIGNUM_num(exps) - || pnum != sk_BIGNUM_num(coeffs) + 1) + if (pnum < 2) return 0; if (!RSA_set0_factors(r, sk_BIGNUM_value(primes, 0), - sk_BIGNUM_value(primes, 1)) - || !RSA_set0_crt_params(r, sk_BIGNUM_value(exps, 0), - sk_BIGNUM_value(exps, 1), - sk_BIGNUM_value(coeffs, 0))) + sk_BIGNUM_value(primes, 1))) return 0; + if (pnum == sk_BIGNUM_num(exps) + && pnum == sk_BIGNUM_num(coeffs) + 1) { + + if (!RSA_set0_crt_params(r, sk_BIGNUM_value(exps, 0), + sk_BIGNUM_value(exps, 1), + sk_BIGNUM_value(coeffs, 0))) + return 0; + } + #ifndef FIPS_MODULE old_infos = r->prime_infos; #endif if (pnum > 2) { #ifndef FIPS_MODULE int i; prime_infos = sk_RSA_PRIME_INFO_new_reserve(NULL, pnum); if (prime_infos == NULL) return 0; for (i = 2; i < pnum; i++) { BIGNUM *prime = sk_BIGNUM_value(primes, i); BIGNUM *exp = sk_BIGNUM_value(exps, i); BIGNUM *coeff = sk_BIGNUM_value(coeffs, i - 1); RSA_PRIME_INFO *pinfo = NULL; if (!ossl_assert(prime != NULL && exp != NULL && coeff != NULL)) goto err; /* Using ossl_rsa_multip_info_new() is wasteful, so allocate directly */ if ((pinfo = OPENSSL_zalloc(sizeof(*pinfo))) == NULL) { ERR_raise(ERR_LIB_RSA, ERR_R_MALLOC_FAILURE); goto err; } pinfo->r = prime; pinfo->d = exp; pinfo->t = coeff; BN_set_flags(pinfo->r, BN_FLG_CONSTTIME); BN_set_flags(pinfo->d, BN_FLG_CONSTTIME); BN_set_flags(pinfo->t, BN_FLG_CONSTTIME); (void)sk_RSA_PRIME_INFO_push(prime_infos, pinfo); } r->prime_infos = prime_infos; if (!ossl_rsa_multip_calc_product(r)) { r->prime_infos = old_infos; goto err; } #else return 0; #endif } #ifndef FIPS_MODULE if (old_infos != NULL) { /* * This is hard to deal with, since the old infos could * also be set by this function and r, d, t should not * be freed in that case. So currently, stay consistent * with other *set0* functions: just free it... */ sk_RSA_PRIME_INFO_pop_free(old_infos, ossl_rsa_multip_info_free); } #endif r->version = pnum > 2 ? RSA_ASN1_VERSION_MULTI : RSA_ASN1_VERSION_DEFAULT; r->dirty_cnt++; return 1; #ifndef FIPS_MODULE err: /* r, d, t should not be freed */ sk_RSA_PRIME_INFO_pop_free(prime_infos, ossl_rsa_multip_info_free_ex); return 0; #endif } DEFINE_SPECIAL_STACK_OF_CONST(BIGNUM_const, BIGNUM) int ossl_rsa_get0_all_params(RSA *r, STACK_OF(BIGNUM_const) *primes, STACK_OF(BIGNUM_const) *exps, STACK_OF(BIGNUM_const) *coeffs) { #ifndef FIPS_MODULE RSA_PRIME_INFO *pinfo; int i, pnum; #endif if (r == NULL) return 0; /* If |p| is NULL, there are no CRT parameters */ if (RSA_get0_p(r) == NULL) return 1; sk_BIGNUM_const_push(primes, RSA_get0_p(r)); sk_BIGNUM_const_push(primes, RSA_get0_q(r)); sk_BIGNUM_const_push(exps, RSA_get0_dmp1(r)); sk_BIGNUM_const_push(exps, RSA_get0_dmq1(r)); sk_BIGNUM_const_push(coeffs, RSA_get0_iqmp(r)); #ifndef FIPS_MODULE pnum = RSA_get_multi_prime_extra_count(r); for (i = 0; i < pnum; i++) { pinfo = sk_RSA_PRIME_INFO_value(r->prime_infos, i); sk_BIGNUM_const_push(primes, pinfo->r); sk_BIGNUM_const_push(exps, pinfo->d); sk_BIGNUM_const_push(coeffs, pinfo->t); } #endif return 1; } #ifndef FIPS_MODULE /* Helpers to set or get diverse hash algorithm names */ static int int_set_rsa_md_name(EVP_PKEY_CTX *ctx, /* For checks */ int keytype, int optype, /* For EVP_PKEY_CTX_set_params() */ const char *mdkey, const char *mdname, const char *propkey, const char *mdprops) { OSSL_PARAM params[3], *p = params; if (ctx == NULL || mdname == NULL || (ctx->operation & optype) == 0) { ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); /* Uses the same return values as EVP_PKEY_CTX_ctrl */ return -2; } /* If key type not RSA return error */ switch (keytype) { case -1: if (!EVP_PKEY_CTX_is_a(ctx, "RSA") && !EVP_PKEY_CTX_is_a(ctx, "RSA-PSS")) return -1; break; default: if (!EVP_PKEY_CTX_is_a(ctx, evp_pkey_type2name(keytype))) return -1; break; } /* Cast away the const. This is read only so should be safe */ *p++ = OSSL_PARAM_construct_utf8_string(mdkey, (char *)mdname, 0); if (evp_pkey_ctx_is_provided(ctx) && mdprops != NULL) { /* Cast away the const. This is read only so should be safe */ *p++ = OSSL_PARAM_construct_utf8_string(propkey, (char *)mdprops, 0); } *p++ = OSSL_PARAM_construct_end(); return evp_pkey_ctx_set_params_strict(ctx, params); } /* Helpers to set or get diverse hash algorithm names */ static int int_get_rsa_md_name(EVP_PKEY_CTX *ctx, /* For checks */ int keytype, int optype, /* For EVP_PKEY_CTX_get_params() */ const char *mdkey, char *mdname, size_t mdnamesize) { OSSL_PARAM params[2], *p = params; if (ctx == NULL || mdname == NULL || (ctx->operation & optype) == 0) { ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); /* Uses the same return values as EVP_PKEY_CTX_ctrl */ return -2; } /* If key type not RSA return error */ switch (keytype) { case -1: if (!EVP_PKEY_CTX_is_a(ctx, "RSA") && !EVP_PKEY_CTX_is_a(ctx, "RSA-PSS")) return -1; break; default: if (!EVP_PKEY_CTX_is_a(ctx, evp_pkey_type2name(keytype))) return -1; break; } /* Cast away the const. This is read only so should be safe */ *p++ = OSSL_PARAM_construct_utf8_string(mdkey, (char *)mdname, mdnamesize); *p++ = OSSL_PARAM_construct_end(); return evp_pkey_ctx_get_params_strict(ctx, params); } /* * This one is currently implemented as an EVP_PKEY_CTX_ctrl() wrapper, * simply because that's easier. */ int EVP_PKEY_CTX_set_rsa_padding(EVP_PKEY_CTX *ctx, int pad_mode) { return RSA_pkey_ctx_ctrl(ctx, -1, EVP_PKEY_CTRL_RSA_PADDING, pad_mode, NULL); } /* * This one is currently implemented as an EVP_PKEY_CTX_ctrl() wrapper, * simply because that's easier. */ int EVP_PKEY_CTX_get_rsa_padding(EVP_PKEY_CTX *ctx, int *pad_mode) { return RSA_pkey_ctx_ctrl(ctx, -1, EVP_PKEY_CTRL_GET_RSA_PADDING, 0, pad_mode); } /* * This one is currently implemented as an EVP_PKEY_CTX_ctrl() wrapper, * simply because that's easier. */ int EVP_PKEY_CTX_set_rsa_pss_keygen_md(EVP_PKEY_CTX *ctx, const EVP_MD *md) { return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA_PSS, EVP_PKEY_OP_KEYGEN, EVP_PKEY_CTRL_MD, 0, (void *)(md)); } int EVP_PKEY_CTX_set_rsa_pss_keygen_md_name(EVP_PKEY_CTX *ctx, const char *mdname, const char *mdprops) { return int_set_rsa_md_name(ctx, EVP_PKEY_RSA_PSS, EVP_PKEY_OP_KEYGEN, OSSL_PKEY_PARAM_RSA_DIGEST, mdname, OSSL_PKEY_PARAM_RSA_DIGEST_PROPS, mdprops); } /* * This one is currently implemented as an EVP_PKEY_CTX_ctrl() wrapper, * simply because that's easier. */ int EVP_PKEY_CTX_set_rsa_oaep_md(EVP_PKEY_CTX *ctx, const EVP_MD *md) { return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, EVP_PKEY_CTRL_RSA_OAEP_MD, 0, (void *)(md)); } int EVP_PKEY_CTX_set_rsa_oaep_md_name(EVP_PKEY_CTX *ctx, const char *mdname, const char *mdprops) { return int_set_rsa_md_name(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST, mdname, OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST_PROPS, mdprops); } int EVP_PKEY_CTX_get_rsa_oaep_md_name(EVP_PKEY_CTX *ctx, char *name, size_t namesize) { return int_get_rsa_md_name(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST, name, namesize); } /* * This one is currently implemented as an EVP_PKEY_CTX_ctrl() wrapper, * simply because that's easier. */ int EVP_PKEY_CTX_get_rsa_oaep_md(EVP_PKEY_CTX *ctx, const EVP_MD **md) { return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, EVP_PKEY_CTRL_GET_RSA_OAEP_MD, 0, (void *)md); } /* * This one is currently implemented as an EVP_PKEY_CTX_ctrl() wrapper, * simply because that's easier. */ int EVP_PKEY_CTX_set_rsa_mgf1_md(EVP_PKEY_CTX *ctx, const EVP_MD *md) { return RSA_pkey_ctx_ctrl(ctx, EVP_PKEY_OP_TYPE_SIG | EVP_PKEY_OP_TYPE_CRYPT, EVP_PKEY_CTRL_RSA_MGF1_MD, 0, (void *)(md)); } int EVP_PKEY_CTX_set_rsa_mgf1_md_name(EVP_PKEY_CTX *ctx, const char *mdname, const char *mdprops) { return int_set_rsa_md_name(ctx, -1, EVP_PKEY_OP_TYPE_CRYPT | EVP_PKEY_OP_TYPE_SIG, OSSL_PKEY_PARAM_MGF1_DIGEST, mdname, OSSL_PKEY_PARAM_MGF1_PROPERTIES, mdprops); } int EVP_PKEY_CTX_get_rsa_mgf1_md_name(EVP_PKEY_CTX *ctx, char *name, size_t namesize) { return int_get_rsa_md_name(ctx, -1, EVP_PKEY_OP_TYPE_CRYPT | EVP_PKEY_OP_TYPE_SIG, OSSL_PKEY_PARAM_MGF1_DIGEST, name, namesize); } /* * This one is currently implemented as an EVP_PKEY_CTX_ctrl() wrapper, * simply because that's easier. */ int EVP_PKEY_CTX_set_rsa_pss_keygen_mgf1_md(EVP_PKEY_CTX *ctx, const EVP_MD *md) { return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA_PSS, EVP_PKEY_OP_KEYGEN, EVP_PKEY_CTRL_RSA_MGF1_MD, 0, (void *)(md)); } int EVP_PKEY_CTX_set_rsa_pss_keygen_mgf1_md_name(EVP_PKEY_CTX *ctx, const char *mdname) { return int_set_rsa_md_name(ctx, EVP_PKEY_RSA_PSS, EVP_PKEY_OP_KEYGEN, OSSL_PKEY_PARAM_MGF1_DIGEST, mdname, NULL, NULL); } /* * This one is currently implemented as an EVP_PKEY_CTX_ctrl() wrapper, * simply because that's easier. */ int EVP_PKEY_CTX_get_rsa_mgf1_md(EVP_PKEY_CTX *ctx, const EVP_MD **md) { return RSA_pkey_ctx_ctrl(ctx, EVP_PKEY_OP_TYPE_SIG | EVP_PKEY_OP_TYPE_CRYPT, EVP_PKEY_CTRL_GET_RSA_MGF1_MD, 0, (void *)(md)); } int EVP_PKEY_CTX_set0_rsa_oaep_label(EVP_PKEY_CTX *ctx, void *label, int llen) { OSSL_PARAM rsa_params[2], *p = rsa_params; + const char *empty = ""; + /* + * Needed as we swap label with empty if it is NULL, and label is + * freed at the end of this function. + */ + void *plabel = label; int ret; if (ctx == NULL || !EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)) { ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); /* Uses the same return values as EVP_PKEY_CTX_ctrl */ return -2; } /* If key type not RSA return error */ if (!EVP_PKEY_CTX_is_a(ctx, "RSA")) return -1; + /* Accept NULL for backward compatibility */ + if (label == NULL && llen == 0) + plabel = (void *)empty; + /* Cast away the const. This is read only so should be safe */ *p++ = OSSL_PARAM_construct_octet_string(OSSL_ASYM_CIPHER_PARAM_OAEP_LABEL, - (void *)label, (size_t)llen); + (void *)plabel, (size_t)llen); *p++ = OSSL_PARAM_construct_end(); ret = evp_pkey_ctx_set_params_strict(ctx, rsa_params); if (ret <= 0) return ret; /* Ownership is supposed to be transfered to the callee. */ OPENSSL_free(label); return 1; } int EVP_PKEY_CTX_get0_rsa_oaep_label(EVP_PKEY_CTX *ctx, unsigned char **label) { OSSL_PARAM rsa_params[2], *p = rsa_params; size_t labellen; if (ctx == NULL || !EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)) { ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); /* Uses the same return values as EVP_PKEY_CTX_ctrl */ return -2; } /* If key type not RSA return error */ if (!EVP_PKEY_CTX_is_a(ctx, "RSA")) return -1; *p++ = OSSL_PARAM_construct_octet_ptr(OSSL_ASYM_CIPHER_PARAM_OAEP_LABEL, (void **)label, 0); *p++ = OSSL_PARAM_construct_end(); if (!EVP_PKEY_CTX_get_params(ctx, rsa_params)) return -1; labellen = rsa_params[0].return_size; if (labellen > INT_MAX) return -1; return (int)labellen; } /* * This one is currently implemented as an EVP_PKEY_CTX_ctrl() wrapper, * simply because that's easier. */ int EVP_PKEY_CTX_set_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, int saltlen) { /* * For some reason, the optype was set to this: * * EVP_PKEY_OP_SIGN|EVP_PKEY_OP_VERIFY * * However, we do use RSA-PSS with the whole gamut of diverse signature * and verification operations, so the optype gets upgraded to this: * * EVP_PKEY_OP_TYPE_SIG */ return RSA_pkey_ctx_ctrl(ctx, EVP_PKEY_OP_TYPE_SIG, EVP_PKEY_CTRL_RSA_PSS_SALTLEN, saltlen, NULL); } /* * This one is currently implemented as an EVP_PKEY_CTX_ctrl() wrapper, * simply because that's easier. */ int EVP_PKEY_CTX_get_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, int *saltlen) { /* * Because of circumstances, the optype is updated from: * * EVP_PKEY_OP_SIGN|EVP_PKEY_OP_VERIFY * * to: * * EVP_PKEY_OP_TYPE_SIG */ return RSA_pkey_ctx_ctrl(ctx, EVP_PKEY_OP_TYPE_SIG, EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN, 0, saltlen); } int EVP_PKEY_CTX_set_rsa_pss_keygen_saltlen(EVP_PKEY_CTX *ctx, int saltlen) { OSSL_PARAM pad_params[2], *p = pad_params; if (ctx == NULL || !EVP_PKEY_CTX_IS_GEN_OP(ctx)) { ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); /* Uses the same return values as EVP_PKEY_CTX_ctrl */ return -2; } if (!EVP_PKEY_CTX_is_a(ctx, "RSA-PSS")) return -1; *p++ = OSSL_PARAM_construct_int(OSSL_SIGNATURE_PARAM_PSS_SALTLEN, &saltlen); *p++ = OSSL_PARAM_construct_end(); return evp_pkey_ctx_set_params_strict(ctx, pad_params); } int EVP_PKEY_CTX_set_rsa_keygen_bits(EVP_PKEY_CTX *ctx, int bits) { OSSL_PARAM params[2], *p = params; size_t bits2 = bits; if (ctx == NULL || !EVP_PKEY_CTX_IS_GEN_OP(ctx)) { ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); /* Uses the same return values as EVP_PKEY_CTX_ctrl */ return -2; } /* If key type not RSA return error */ if (!EVP_PKEY_CTX_is_a(ctx, "RSA") && !EVP_PKEY_CTX_is_a(ctx, "RSA-PSS")) return -1; *p++ = OSSL_PARAM_construct_size_t(OSSL_PKEY_PARAM_RSA_BITS, &bits2); *p++ = OSSL_PARAM_construct_end(); return evp_pkey_ctx_set_params_strict(ctx, params); } int EVP_PKEY_CTX_set_rsa_keygen_pubexp(EVP_PKEY_CTX *ctx, BIGNUM *pubexp) { int ret = RSA_pkey_ctx_ctrl(ctx, EVP_PKEY_OP_KEYGEN, EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP, 0, pubexp); /* * Satisfy memory semantics for pre-3.0 callers of * EVP_PKEY_CTX_set_rsa_keygen_pubexp(): their expectation is that input * pubexp BIGNUM becomes managed by the EVP_PKEY_CTX on success. */ if (ret > 0 && evp_pkey_ctx_is_provided(ctx)) { BN_free(ctx->rsa_pubexp); ctx->rsa_pubexp = pubexp; } return ret; } int EVP_PKEY_CTX_set1_rsa_keygen_pubexp(EVP_PKEY_CTX *ctx, BIGNUM *pubexp) { int ret = 0; /* * When we're dealing with a provider, there's no need to duplicate * pubexp, as it gets copied when transforming to an OSSL_PARAM anyway. */ if (evp_pkey_ctx_is_legacy(ctx)) { pubexp = BN_dup(pubexp); if (pubexp == NULL) return 0; } ret = EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_KEYGEN, EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP, 0, pubexp); if (evp_pkey_ctx_is_legacy(ctx) && ret <= 0) BN_free(pubexp); return ret; } int EVP_PKEY_CTX_set_rsa_keygen_primes(EVP_PKEY_CTX *ctx, int primes) { OSSL_PARAM params[2], *p = params; size_t primes2 = primes; if (ctx == NULL || !EVP_PKEY_CTX_IS_GEN_OP(ctx)) { ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); /* Uses the same return values as EVP_PKEY_CTX_ctrl */ return -2; } /* If key type not RSA return error */ if (!EVP_PKEY_CTX_is_a(ctx, "RSA") && !EVP_PKEY_CTX_is_a(ctx, "RSA-PSS")) return -1; *p++ = OSSL_PARAM_construct_size_t(OSSL_PKEY_PARAM_RSA_PRIMES, &primes2); *p++ = OSSL_PARAM_construct_end(); return evp_pkey_ctx_set_params_strict(ctx, params); } #endif diff --git a/crypto/openssl/doc/man3/CMS_add1_signer.pod b/crypto/openssl/doc/man3/CMS_add1_signer.pod index 800085b7b86a..d606a02cc1fd 100644 --- a/crypto/openssl/doc/man3/CMS_add1_signer.pod +++ b/crypto/openssl/doc/man3/CMS_add1_signer.pod @@ -1,107 +1,109 @@ =pod =head1 NAME CMS_add1_signer, CMS_SignerInfo_sign - add a signer to a CMS_ContentInfo signed data structure =head1 SYNOPSIS #include CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms, X509 *signcert, EVP_PKEY *pkey, const EVP_MD *md, unsigned int flags); int CMS_SignerInfo_sign(CMS_SignerInfo *si); =head1 DESCRIPTION CMS_add1_signer() adds a signer with certificate B and private key B using message digest B to CMS_ContentInfo SignedData structure B. The CMS_ContentInfo structure should be obtained from an initial call to CMS_sign() with the flag B set or in the case or re-signing a valid CMS_ContentInfo SignedData structure. If the B parameter is B then the default digest for the public key algorithm will be used. Unless the B flag is set the returned CMS_ContentInfo structure is not complete and must be finalized either by streaming (if applicable) or a call to CMS_final(). -The CMS_SignerInfo_sign() function will explicitly sign a CMS_SignerInfo -structure, its main use is when B and B flags +The CMS_SignerInfo_sign() function explicitly signs a CMS_SignerInfo +structure, its main use is when the B and B flags are both set. =head1 NOTES The main purpose of CMS_add1_signer() is to provide finer control over a CMS signed data structure where the simpler CMS_sign() function defaults are not appropriate. For example if multiple signers or non default digest algorithms are needed. New attributes can also be added using the returned CMS_SignerInfo structure and the CMS attribute utility functions or the CMS signed receipt request functions. Any of the following flags (ored together) can be passed in the B parameter. If B is set then an attempt is made to copy the content digest value from the CMS_ContentInfo structure: to add a signer to an existing structure. An error occurs if a matching digest value cannot be found to copy. The returned CMS_ContentInfo structure will be valid and finalized when this flag is set. If B is set in addition to B then the CMS_SignerInfo structure will not be finalized so additional attributes can be added. In this case an explicit call to CMS_SignerInfo_sign() is needed to finalize it. If B is set the signer's certificate will not be included in the CMS_ContentInfo structure, the signer's certificate must still be supplied in the B parameter though. This can reduce the size of the signature if the signers certificate can be obtained by other means: for example a previously signed message. The SignedData structure includes several CMS signedAttributes including the signing time, the CMS content type and the supported list of ciphers in an SMIMECapabilities attribute. If B is set then no signedAttributes will be used. If B is set then just the SMIMECapabilities are omitted. OpenSSL will by default identify signing certificates using issuer name and serial number. If B is set it will use the subject key identifier value instead. An error occurs if the signing certificate does not have a subject key identifier extension. If present the SMIMECapabilities attribute indicates support for the following algorithms in preference order: 256 bit AES, Gost R3411-94, Gost 28147-89, 192 bit AES, 128 bit AES, triple DES, 128 bit RC2, 64 bit RC2, DES and 40 bit RC2. If any of these algorithms is not available then it will not be included: for example the GOST algorithms will not be included if the GOST ENGINE is not loaded. CMS_add1_signer() returns an internal pointer to the CMS_SignerInfo structure just added, this can be used to set additional attributes before it is finalized. =head1 RETURN VALUES CMS_add1_signer() returns an internal pointer to the CMS_SignerInfo structure just added or NULL if an error occurs. +CMS_SignerInfo_sign() returns 1 on success, 0 on failure. + =head1 SEE ALSO L, L, L, =head1 COPYRIGHT -Copyright 2014-2016 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2014-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/DH_generate_parameters.pod b/crypto/openssl/doc/man3/DH_generate_parameters.pod index 1098a161ea63..9c1dff7aedd9 100644 --- a/crypto/openssl/doc/man3/DH_generate_parameters.pod +++ b/crypto/openssl/doc/man3/DH_generate_parameters.pod @@ -1,170 +1,174 @@ =pod =head1 NAME DH_generate_parameters_ex, DH_generate_parameters, DH_check, DH_check_params, DH_check_ex, DH_check_params_ex, DH_check_pub_key_ex - generate and check Diffie-Hellman parameters =head1 SYNOPSIS #include The following functions have been deprecated since OpenSSL 3.0, and can be hidden entirely by defining B with a suitable version value, see L: int DH_generate_parameters_ex(DH *dh, int prime_len, int generator, BN_GENCB *cb); int DH_check(DH *dh, int *codes); int DH_check_params(DH *dh, int *codes); int DH_check_ex(const DH *dh); int DH_check_params_ex(const DH *dh); int DH_check_pub_key_ex(const DH *dh, const BIGNUM *pub_key); The following functions have been deprecated since OpenSSL 0.9.8, and can be hidden entirely by defining B with a suitable version value, see L: DH *DH_generate_parameters(int prime_len, int generator, void (*callback)(int, int, void *), void *cb_arg); =head1 DESCRIPTION All of the functions described on this page are deprecated. Applications should instead use L, L, L and L. DH_generate_parameters_ex() generates Diffie-Hellman parameters that can be shared among a group of users, and stores them in the provided B structure. The pseudo-random number generator must be seeded before calling it. The parameters generated by DH_generate_parameters_ex() should not be used in signature schemes. B is the length in bits of the safe prime to be generated. B is a small number E 1, typically 2 or 5. A callback function may be used to provide feedback about the progress of the key generation. If B is not B, it will be called as described in L while a random prime number is generated, and when a prime has been found, B is called. See L for information on the BN_GENCB_call() function. DH_generate_parameters() is similar to DH_generate_prime_ex() but expects an old-style callback function; see L for information on the old-style callback. DH_check_params() confirms that the B

and B are likely enough to be valid. This is a lightweight check, if a more thorough check is needed, use DH_check(). The value of B<*codes> is updated with any problems found. If B<*codes> is zero then no problems were found, otherwise the following bits may be set: =over 4 =item DH_CHECK_P_NOT_PRIME The parameter B

has been determined to not being an odd prime. Note that the lack of this bit doesn't guarantee that B

is a prime. =item DH_NOT_SUITABLE_GENERATOR The generator B is not suitable. Note that the lack of this bit doesn't guarantee that B is suitable, unless B

is known to be a strong prime. =item DH_MODULUS_TOO_SMALL The modulus is too small. =item DH_MODULUS_TOO_LARGE The modulus is too large. =back DH_check() confirms that the Diffie-Hellman parameters B are valid. The value of B<*codes> is updated with any problems found. If B<*codes> is zero then no problems were found, otherwise the following bits may be set: =over 4 =item DH_CHECK_P_NOT_PRIME The parameter B

is not prime. =item DH_CHECK_P_NOT_SAFE_PRIME The parameter B

is not a safe prime and no B value is present. =item DH_UNABLE_TO_CHECK_GENERATOR The generator B cannot be checked for suitability. =item DH_NOT_SUITABLE_GENERATOR The generator B is not suitable. =item DH_CHECK_Q_NOT_PRIME The parameter B is not prime. =item DH_CHECK_INVALID_Q_VALUE The parameter B is invalid. =item DH_CHECK_INVALID_J_VALUE The parameter B is invalid. =back +If 0 is returned or B<*codes> is set to a nonzero value the supplied +parameters should not be used for Diffie-Hellman operations otherwise +the security properties of the key exchange are not guaranteed. + DH_check_ex(), DH_check_params() and DH_check_pub_key_ex() are similar to DH_check() and DH_check_params() respectively, but the error reasons are added to the thread's error queue instead of provided as return values from the function. =head1 RETURN VALUES DH_generate_parameters_ex(), DH_check() and DH_check_params() return 1 if the check could be performed, 0 otherwise. DH_generate_parameters() returns a pointer to the DH structure or NULL if the parameter generation fails. DH_check_ex(), DH_check_params() and DH_check_pub_key_ex() return 1 if the check is successful, 0 for failed. The error codes can be obtained by L. =head1 SEE ALSO L, L, L, L =head1 HISTORY All of these functions were deprecated in OpenSSL 3.0. DH_generate_parameters() was deprecated in OpenSSL 0.9.8; use DH_generate_parameters_ex() instead. =head1 COPYRIGHT -Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2000-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/DSA_generate_parameters.pod b/crypto/openssl/doc/man3/DSA_generate_parameters.pod index 415c4c8b82ce..a10dc9ba2759 100644 --- a/crypto/openssl/doc/man3/DSA_generate_parameters.pod +++ b/crypto/openssl/doc/man3/DSA_generate_parameters.pod @@ -1,136 +1,136 @@ =pod =head1 NAME DSA_generate_parameters_ex, DSA_generate_parameters - generate DSA parameters =head1 SYNOPSIS #include The following functions have been deprecated since OpenSSL 3.0, and can be hidden entirely by defining B with a suitable version value, see L: int DSA_generate_parameters_ex(DSA *dsa, int bits, const unsigned char *seed, int seed_len, int *counter_ret, unsigned long *h_ret, BN_GENCB *cb); The following functions have been deprecated since OpenSSL 0.9.8, and can be hidden entirely by defining B with a suitable version value, see L: DSA *DSA_generate_parameters(int bits, unsigned char *seed, int seed_len, int *counter_ret, unsigned long *h_ret, void (*callback)(int, int, void *), void *cb_arg); =head1 DESCRIPTION All of the functions described on this page are deprecated. Applications should instead use L and L as described in L. DSA_generate_parameters_ex() generates primes p and q and a generator g for use in the DSA and stores the result in B. B is the length of the prime p to be generated. For lengths under 2048 bits, the length of q is 160 bits; for lengths greater than or equal to 2048 bits, the length of q is set to 256 bits. If B is NULL, the primes will be generated at random. If B is less than the length of q, an error is returned. DSA_generate_parameters_ex() places the iteration count in *B and a counter used for finding a generator in *B, unless these are B. A callback function may be used to provide feedback about the progress of the key generation. If B is not B, it will be called as shown below. For information on the BN_GENCB structure and the BN_GENCB_call function discussed below, refer to L. -DSA_generate_prime() is similar to DSA_generate_prime_ex() but +DSA_generate_parameters() is similar to DSA_generate_parameters_ex() but expects an old-style callback function; see L for information on the old-style callback. =over 2 =item * When a candidate for q is generated, B is called (m is 0 for the first candidate). =item * When a candidate for q has passed a test by trial division, B is called. While a candidate for q is tested by Miller-Rabin primality tests, B is called in the outer loop (once for each witness that confirms that the candidate may be prime); i is the loop counter (starting at 0). =item * When a prime q has been found, B and B are called. =item * Before a candidate for p (other than the first) is generated and tested, B is called. =item * When a candidate for p has passed the test by trial division, B is called. While it is tested by the Miller-Rabin primality test, B is called in the outer loop (once for each witness that confirms that the candidate may be prime). i is the loop counter (starting at 0). =item * When p has been found, B is called. =item * When the generator has been found, B is called. =back =head1 RETURN VALUES DSA_generate_parameters_ex() returns a 1 on success, or 0 otherwise. The error codes can be obtained by L. DSA_generate_parameters() returns a pointer to the DSA structure or B if the parameter generation fails. =head1 BUGS Seed lengths greater than 20 are not supported. =head1 SEE ALSO L, L, L, L, L =head1 HISTORY DSA_generate_parameters_ex() was deprecated in OpenSSL 3.0. DSA_generate_parameters() was deprecated in OpenSSL 0.9.8; use DSA_generate_parameters_ex() instead. =head1 COPYRIGHT -Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2000-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/EVP_aes_128_gcm.pod b/crypto/openssl/doc/man3/EVP_aes_128_gcm.pod index 09cae9912950..485705ea7889 100644 --- a/crypto/openssl/doc/man3/EVP_aes_128_gcm.pod +++ b/crypto/openssl/doc/man3/EVP_aes_128_gcm.pod @@ -1,201 +1,195 @@ =pod =head1 NAME EVP_aes_128_cbc, EVP_aes_192_cbc, EVP_aes_256_cbc, EVP_aes_128_cfb, EVP_aes_192_cfb, EVP_aes_256_cfb, EVP_aes_128_cfb1, EVP_aes_192_cfb1, EVP_aes_256_cfb1, EVP_aes_128_cfb8, EVP_aes_192_cfb8, EVP_aes_256_cfb8, EVP_aes_128_cfb128, EVP_aes_192_cfb128, EVP_aes_256_cfb128, EVP_aes_128_ctr, EVP_aes_192_ctr, EVP_aes_256_ctr, EVP_aes_128_ecb, EVP_aes_192_ecb, EVP_aes_256_ecb, EVP_aes_128_ofb, EVP_aes_192_ofb, EVP_aes_256_ofb, EVP_aes_128_cbc_hmac_sha1, EVP_aes_256_cbc_hmac_sha1, EVP_aes_128_cbc_hmac_sha256, EVP_aes_256_cbc_hmac_sha256, EVP_aes_128_ccm, EVP_aes_192_ccm, EVP_aes_256_ccm, EVP_aes_128_gcm, EVP_aes_192_gcm, EVP_aes_256_gcm, EVP_aes_128_ocb, EVP_aes_192_ocb, EVP_aes_256_ocb, EVP_aes_128_wrap, EVP_aes_192_wrap, EVP_aes_256_wrap, EVP_aes_128_wrap_pad, EVP_aes_192_wrap_pad, EVP_aes_256_wrap_pad, EVP_aes_128_xts, EVP_aes_256_xts - EVP AES cipher =head1 SYNOPSIS =for openssl generic #include const EVP_CIPHER *EVP_ciphername(void) I is used a placeholder for any of the described cipher functions, such as I. =head1 DESCRIPTION The AES encryption algorithm for EVP. =over 4 =item EVP_aes_128_cbc(), EVP_aes_192_cbc(), EVP_aes_256_cbc(), EVP_aes_128_cfb(), EVP_aes_192_cfb(), EVP_aes_256_cfb(), EVP_aes_128_cfb1(), EVP_aes_192_cfb1(), EVP_aes_256_cfb1(), EVP_aes_128_cfb8(), EVP_aes_192_cfb8(), EVP_aes_256_cfb8(), EVP_aes_128_cfb128(), EVP_aes_192_cfb128(), EVP_aes_256_cfb128(), EVP_aes_128_ctr(), EVP_aes_192_ctr(), EVP_aes_256_ctr(), EVP_aes_128_ecb(), EVP_aes_192_ecb(), EVP_aes_256_ecb(), EVP_aes_128_ofb(), EVP_aes_192_ofb(), EVP_aes_256_ofb() AES for 128, 192 and 256 bit keys in the following modes: CBC, CFB with 128-bit shift, CFB with 1-bit shift, CFB with 8-bit shift, CTR, ECB, and OFB. =item EVP_aes_128_cbc_hmac_sha1(), EVP_aes_256_cbc_hmac_sha1() Authenticated encryption with AES in CBC mode using SHA-1 as HMAC, with keys of 128 and 256 bits length respectively. The authentication tag is 160 bits long. WARNING: this is not intended for usage outside of TLS and requires calling of some undocumented ctrl functions. These ciphers do not conform to the EVP AEAD interface. =item EVP_aes_128_cbc_hmac_sha256(), EVP_aes_256_cbc_hmac_sha256() Authenticated encryption with AES in CBC mode using SHA256 (SHA-2, 256-bits) as HMAC, with keys of 128 and 256 bits length respectively. The authentication tag is 256 bits long. WARNING: this is not intended for usage outside of TLS and requires calling of some undocumented ctrl functions. These ciphers do not conform to the EVP AEAD interface. =item EVP_aes_128_ccm(), EVP_aes_192_ccm(), EVP_aes_256_ccm(), EVP_aes_128_gcm(), EVP_aes_192_gcm(), EVP_aes_256_gcm(), EVP_aes_128_ocb(), EVP_aes_192_ocb(), EVP_aes_256_ocb() AES for 128, 192 and 256 bit keys in CBC-MAC Mode (CCM), Galois Counter Mode (GCM) and OCB Mode respectively. These ciphers require additional control operations to function correctly, see the L section for details. =item EVP_aes_128_wrap(), EVP_aes_192_wrap(), EVP_aes_256_wrap(), EVP_aes_128_wrap_pad(), -EVP_aes_128_wrap(), -EVP_aes_192_wrap(), -EVP_aes_256_wrap(), EVP_aes_192_wrap_pad(), -EVP_aes_128_wrap(), -EVP_aes_192_wrap(), -EVP_aes_256_wrap(), EVP_aes_256_wrap_pad() AES key wrap with 128, 192 and 256 bit keys, as according to RFC 3394 section 2.2.1 ("wrap") and RFC 5649 section 4.1 ("wrap with padding") respectively. =item EVP_aes_128_xts(), EVP_aes_256_xts() AES XTS mode (XTS-AES) is standardized in IEEE Std. 1619-2007 and described in NIST SP 800-38E. The XTS (XEX-based tweaked-codebook mode with ciphertext stealing) mode was designed by Prof. Phillip Rogaway of University of California, Davis, intended for encrypting data on a storage device. XTS-AES provides confidentiality but not authentication of data. It also requires a key of double-length for protection of a certain key size. In particular, XTS-AES-128 (B) takes input of a 256-bit key to achieve AES 128-bit security, and XTS-AES-256 (B) takes input of a 512-bit key to achieve AES 256-bit security. The XTS implementation in OpenSSL does not support streaming. That is there must only be one L call per L call (and similarly with the "Decrypt" functions). The I parameter to L or L is the XTS "tweak" value. =back =head1 NOTES Developers should be aware of the negative performance implications of calling these functions multiple times and should consider using -L instead. +L with L instead. See L for further information. =head1 RETURN VALUES These functions return an B structure that contains the implementation of the symmetric cipher. See L for details of the B structure. =head1 SEE ALSO L, L, L =head1 COPYRIGHT Copyright 2017-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/EVP_aria_128_gcm.pod b/crypto/openssl/doc/man3/EVP_aria_128_gcm.pod index 92913652630d..91aa75ec3871 100644 --- a/crypto/openssl/doc/man3/EVP_aria_128_gcm.pod +++ b/crypto/openssl/doc/man3/EVP_aria_128_gcm.pod @@ -1,124 +1,124 @@ =pod =head1 NAME EVP_aria_128_cbc, EVP_aria_192_cbc, EVP_aria_256_cbc, EVP_aria_128_cfb, EVP_aria_192_cfb, EVP_aria_256_cfb, EVP_aria_128_cfb1, EVP_aria_192_cfb1, EVP_aria_256_cfb1, EVP_aria_128_cfb8, EVP_aria_192_cfb8, EVP_aria_256_cfb8, EVP_aria_128_cfb128, EVP_aria_192_cfb128, EVP_aria_256_cfb128, EVP_aria_128_ctr, EVP_aria_192_ctr, EVP_aria_256_ctr, EVP_aria_128_ecb, EVP_aria_192_ecb, EVP_aria_256_ecb, EVP_aria_128_ofb, EVP_aria_192_ofb, EVP_aria_256_ofb, EVP_aria_128_ccm, EVP_aria_192_ccm, EVP_aria_256_ccm, EVP_aria_128_gcm, EVP_aria_192_gcm, EVP_aria_256_gcm, - EVP ARIA cipher =head1 SYNOPSIS =for openssl generic #include const EVP_CIPHER *EVP_ciphername(void) I is used a placeholder for any of the described cipher functions, such as I. =head1 DESCRIPTION The ARIA encryption algorithm for EVP. =over 4 =item EVP_aria_128_cbc(), EVP_aria_192_cbc(), EVP_aria_256_cbc(), EVP_aria_128_cfb(), EVP_aria_192_cfb(), EVP_aria_256_cfb(), EVP_aria_128_cfb1(), EVP_aria_192_cfb1(), EVP_aria_256_cfb1(), EVP_aria_128_cfb8(), EVP_aria_192_cfb8(), EVP_aria_256_cfb8(), EVP_aria_128_cfb128(), EVP_aria_192_cfb128(), EVP_aria_256_cfb128(), EVP_aria_128_ctr(), EVP_aria_192_ctr(), EVP_aria_256_ctr(), EVP_aria_128_ecb(), EVP_aria_192_ecb(), EVP_aria_256_ecb(), EVP_aria_128_ofb(), EVP_aria_192_ofb(), EVP_aria_256_ofb() ARIA for 128, 192 and 256 bit keys in the following modes: CBC, CFB with 128-bit shift, CFB with 1-bit shift, CFB with 8-bit shift, CTR, ECB and OFB. =item EVP_aria_128_ccm(), EVP_aria_192_ccm(), EVP_aria_256_ccm(), EVP_aria_128_gcm(), EVP_aria_192_gcm(), EVP_aria_256_gcm(), ARIA for 128, 192 and 256 bit keys in CBC-MAC Mode (CCM) and Galois Counter Mode (GCM). These ciphers require additional control operations to function correctly, see the L section for details. =back =head1 NOTES Developers should be aware of the negative performance implications of calling these functions multiple times and should consider using -L instead. +L with L instead. See L for further information. =head1 RETURN VALUES These functions return an B structure that contains the implementation of the symmetric cipher. See L for details of the B structure. =head1 SEE ALSO L, L, L =head1 COPYRIGHT Copyright 2017-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/EVP_bf_cbc.pod b/crypto/openssl/doc/man3/EVP_bf_cbc.pod index 4df98f4bdf47..11a909207ac9 100644 --- a/crypto/openssl/doc/man3/EVP_bf_cbc.pod +++ b/crypto/openssl/doc/man3/EVP_bf_cbc.pod @@ -1,68 +1,68 @@ =pod =head1 NAME EVP_bf_cbc, EVP_bf_cfb, EVP_bf_cfb64, EVP_bf_ecb, EVP_bf_ofb - EVP Blowfish cipher =head1 SYNOPSIS #include const EVP_CIPHER *EVP_bf_cbc(void); const EVP_CIPHER *EVP_bf_cfb(void); const EVP_CIPHER *EVP_bf_cfb64(void); const EVP_CIPHER *EVP_bf_ecb(void); const EVP_CIPHER *EVP_bf_ofb(void); =head1 DESCRIPTION The Blowfish encryption algorithm for EVP. This is a variable key length cipher. =over 4 =item EVP_bf_cbc(), EVP_bf_cfb(), EVP_bf_cfb64(), EVP_bf_ecb(), EVP_bf_ofb() Blowfish encryption algorithm in CBC, CFB, ECB and OFB modes respectively. =back =head1 NOTES Developers should be aware of the negative performance implications of calling these functions multiple times and should consider using -L instead. +L with L instead. See L for further information. =head1 RETURN VALUES These functions return an B structure that contains the implementation of the symmetric cipher. See L for details of the B structure. =head1 SEE ALSO L, L, L =head1 COPYRIGHT Copyright 2017-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/EVP_blake2b512.pod b/crypto/openssl/doc/man3/EVP_blake2b512.pod index 98e1899f6a93..55bd9f3bce77 100644 --- a/crypto/openssl/doc/man3/EVP_blake2b512.pod +++ b/crypto/openssl/doc/man3/EVP_blake2b512.pod @@ -1,70 +1,70 @@ =pod =head1 NAME EVP_blake2b512, EVP_blake2s256 - BLAKE2 For EVP =head1 SYNOPSIS #include const EVP_MD *EVP_blake2b512(void); const EVP_MD *EVP_blake2s256(void); =head1 DESCRIPTION BLAKE2 is an improved version of BLAKE, which was submitted to the NIST SHA-3 algorithm competition. The BLAKE2s and BLAKE2b algorithms are described in RFC 7693. =over 4 =item EVP_blake2s256() The BLAKE2s algorithm that produces a 256-bit output from a given input. =item EVP_blake2b512() The BLAKE2b algorithm that produces a 512-bit output from a given input. =back =head1 NOTES Developers should be aware of the negative performance implications of calling these functions multiple times and should consider using -L instead. +L with L instead. See L for further information. While the BLAKE2b and BLAKE2s algorithms supports a variable length digest, this implementation outputs a digest of a fixed length (the maximum length supported), which is 512-bits for BLAKE2b and 256-bits for BLAKE2s. =head1 RETURN VALUES These functions return a B structure that contains the implementation of the message digest. See L for details of the B structure. =head1 CONFORMING TO RFC 7693. =head1 SEE ALSO L, L =head1 COPYRIGHT Copyright 2017-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/EVP_camellia_128_ecb.pod b/crypto/openssl/doc/man3/EVP_camellia_128_ecb.pod index a6b597156a77..cb6e12e2122b 100644 --- a/crypto/openssl/doc/man3/EVP_camellia_128_ecb.pod +++ b/crypto/openssl/doc/man3/EVP_camellia_128_ecb.pod @@ -1,107 +1,107 @@ =pod =head1 NAME EVP_camellia_128_cbc, EVP_camellia_192_cbc, EVP_camellia_256_cbc, EVP_camellia_128_cfb, EVP_camellia_192_cfb, EVP_camellia_256_cfb, EVP_camellia_128_cfb1, EVP_camellia_192_cfb1, EVP_camellia_256_cfb1, EVP_camellia_128_cfb8, EVP_camellia_192_cfb8, EVP_camellia_256_cfb8, EVP_camellia_128_cfb128, EVP_camellia_192_cfb128, EVP_camellia_256_cfb128, EVP_camellia_128_ctr, EVP_camellia_192_ctr, EVP_camellia_256_ctr, EVP_camellia_128_ecb, EVP_camellia_192_ecb, EVP_camellia_256_ecb, EVP_camellia_128_ofb, EVP_camellia_192_ofb, EVP_camellia_256_ofb - EVP Camellia cipher =head1 SYNOPSIS =for openssl generic #include const EVP_CIPHER *EVP_ciphername(void) I is used a placeholder for any of the described cipher functions, such as I. =head1 DESCRIPTION The Camellia encryption algorithm for EVP. =over 4 =item EVP_camellia_128_cbc(), EVP_camellia_192_cbc(), EVP_camellia_256_cbc(), EVP_camellia_128_cfb(), EVP_camellia_192_cfb(), EVP_camellia_256_cfb(), EVP_camellia_128_cfb1(), EVP_camellia_192_cfb1(), EVP_camellia_256_cfb1(), EVP_camellia_128_cfb8(), EVP_camellia_192_cfb8(), EVP_camellia_256_cfb8(), EVP_camellia_128_cfb128(), EVP_camellia_192_cfb128(), EVP_camellia_256_cfb128(), EVP_camellia_128_ctr(), EVP_camellia_192_ctr(), EVP_camellia_256_ctr(), EVP_camellia_128_ecb(), EVP_camellia_192_ecb(), EVP_camellia_256_ecb(), EVP_camellia_128_ofb(), EVP_camellia_192_ofb(), EVP_camellia_256_ofb() Camellia for 128, 192 and 256 bit keys in the following modes: CBC, CFB with 128-bit shift, CFB with 1-bit shift, CFB with 8-bit shift, CTR, ECB and OFB. =back =head1 NOTES Developers should be aware of the negative performance implications of calling these functions multiple times and should consider using -L instead. +L with L instead. See L for further information. =head1 RETURN VALUES These functions return an B structure that contains the implementation of the symmetric cipher. See L for details of the B structure. =head1 SEE ALSO L, L, L =head1 COPYRIGHT Copyright 2017-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/EVP_cast5_cbc.pod b/crypto/openssl/doc/man3/EVP_cast5_cbc.pod index 85ff2ad01488..7fef0598151d 100644 --- a/crypto/openssl/doc/man3/EVP_cast5_cbc.pod +++ b/crypto/openssl/doc/man3/EVP_cast5_cbc.pod @@ -1,68 +1,68 @@ =pod =head1 NAME EVP_cast5_cbc, EVP_cast5_cfb, EVP_cast5_cfb64, EVP_cast5_ecb, EVP_cast5_ofb - EVP CAST cipher =head1 SYNOPSIS #include const EVP_CIPHER *EVP_cast5_cbc(void); const EVP_CIPHER *EVP_cast5_cfb(void); const EVP_CIPHER *EVP_cast5_cfb64(void); const EVP_CIPHER *EVP_cast5_ecb(void); const EVP_CIPHER *EVP_cast5_ofb(void); =head1 DESCRIPTION The CAST encryption algorithm for EVP. This is a variable key length cipher. =over 4 =item EVP_cast5_cbc(), EVP_cast5_ecb(), EVP_cast5_cfb(), EVP_cast5_cfb64(), EVP_cast5_ofb() CAST encryption algorithm in CBC, ECB, CFB and OFB modes respectively. =back =head1 NOTES Developers should be aware of the negative performance implications of calling these functions multiple times and should consider using -L instead. +L with L instead. See L for further information. =head1 RETURN VALUES These functions return an B structure that contains the implementation of the symmetric cipher. See L for details of the B structure. =head1 SEE ALSO L, L, L =head1 COPYRIGHT Copyright 2017-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/EVP_chacha20.pod b/crypto/openssl/doc/man3/EVP_chacha20.pod index 683faa326e14..7e80c8de40c9 100644 --- a/crypto/openssl/doc/man3/EVP_chacha20.pod +++ b/crypto/openssl/doc/man3/EVP_chacha20.pod @@ -1,75 +1,75 @@ =pod =head1 NAME EVP_chacha20, EVP_chacha20_poly1305 - EVP ChaCha20 stream cipher =head1 SYNOPSIS #include const EVP_CIPHER *EVP_chacha20(void); const EVP_CIPHER *EVP_chacha20_poly1305(void); =head1 DESCRIPTION The ChaCha20 stream cipher for EVP. =over 4 =item EVP_chacha20() The ChaCha20 stream cipher. The key length is 256 bits, the IV is 128 bits long. The first 64 bits consists of a counter in little-endian order followed by a 64 bit nonce. For example a nonce of: 0000000000000002 With an initial counter of 42 (2a in hex) would be expressed as: 2a000000000000000000000000000002 =item EVP_chacha20_poly1305() Authenticated encryption with ChaCha20-Poly1305. Like EVP_chacha20(), the key is 256 bits and the IV is 96 bits. This supports additional authenticated data (AAD) and produces a 128-bit authentication tag. See the L section for more information. =back =head1 NOTES Developers should be aware of the negative performance implications of calling these functions multiple times and should consider using -L instead. +L with L instead. See L for further information. L uses a 32 bit counter and a 96 bit nonce for the IV. =head1 RETURN VALUES These functions return an B structure that contains the implementation of the symmetric cipher. See L for details of the B structure. =head1 SEE ALSO L, L, L =head1 COPYRIGHT Copyright 2017-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/EVP_des_cbc.pod b/crypto/openssl/doc/man3/EVP_des_cbc.pod index 501216cd6d77..442be8993a29 100644 --- a/crypto/openssl/doc/man3/EVP_des_cbc.pod +++ b/crypto/openssl/doc/man3/EVP_des_cbc.pod @@ -1,117 +1,117 @@ =pod =head1 NAME EVP_des_cbc, EVP_des_cfb, EVP_des_cfb1, EVP_des_cfb8, EVP_des_cfb64, EVP_des_ecb, EVP_des_ofb, EVP_des_ede, EVP_des_ede_cbc, EVP_des_ede_cfb, EVP_des_ede_cfb64, EVP_des_ede_ecb, EVP_des_ede_ofb, EVP_des_ede3, EVP_des_ede3_cbc, EVP_des_ede3_cfb, EVP_des_ede3_cfb1, EVP_des_ede3_cfb8, EVP_des_ede3_cfb64, EVP_des_ede3_ecb, EVP_des_ede3_ofb, EVP_des_ede3_wrap - EVP DES cipher =head1 SYNOPSIS =for openssl generic #include const EVP_CIPHER *EVP_ciphername(void) I is used a placeholder for any of the described cipher functions, such as I. =head1 DESCRIPTION The DES encryption algorithm for EVP. =over 4 =item EVP_des_cbc(), EVP_des_ecb(), EVP_des_cfb(), EVP_des_cfb1(), EVP_des_cfb8(), EVP_des_cfb64(), EVP_des_ofb() DES in CBC, ECB, CFB with 64-bit shift, CFB with 1-bit shift, CFB with 8-bit shift and OFB modes. None of these algorithms are provided by the OpenSSL default provider. To use them it is necessary to load either the OpenSSL legacy provider or another implementation. =item EVP_des_ede(), EVP_des_ede_cbc(), EVP_des_ede_cfb(), EVP_des_ede_cfb64(), EVP_des_ede_ecb(), EVP_des_ede_ofb() Two key triple DES in ECB, CBC, CFB with 64-bit shift and OFB modes. =item EVP_des_ede3(), EVP_des_ede3_cbc(), EVP_des_ede3_cfb(), EVP_des_ede3_cfb1(), EVP_des_ede3_cfb8(), EVP_des_ede3_cfb64(), EVP_des_ede3_ecb(), EVP_des_ede3_ofb() Three-key triple DES in ECB, CBC, CFB with 64-bit shift, CFB with 1-bit shift, CFB with 8-bit shift and OFB modes. =item EVP_des_ede3_wrap() Triple-DES key wrap according to RFC 3217 Section 3. =back =head1 NOTES Developers should be aware of the negative performance implications of calling these functions multiple times and should consider using -L instead. +L with L instead. See L for further information. =head1 RETURN VALUES These functions return an B structure that contains the implementation of the symmetric cipher. See L for details of the B structure. =head1 SEE ALSO L, L, L =head1 COPYRIGHT Copyright 2017-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/EVP_desx_cbc.pod b/crypto/openssl/doc/man3/EVP_desx_cbc.pod index fae827192ee9..c22c0de47900 100644 --- a/crypto/openssl/doc/man3/EVP_desx_cbc.pod +++ b/crypto/openssl/doc/man3/EVP_desx_cbc.pod @@ -1,59 +1,59 @@ =pod =head1 NAME EVP_desx_cbc - EVP DES-X cipher =head1 SYNOPSIS #include const EVP_CIPHER *EVP_desx_cbc(void); =head1 DESCRIPTION The DES-X encryption algorithm for EVP. All modes below use a key length of 128 bits and acts on blocks of 128-bits. =over 4 =item EVP_desx_cbc() The DES-X algorithm in CBC mode. This algorithm is not provided by the OpenSSL default provider. To use it is necessary to load either the OpenSSL legacy provider or another implementation. =back Developers should be aware of the negative performance implications of calling this function multiple times and should consider using -L instead. +L with L instead. See L for further information. =head1 RETURN VALUES These functions return an B structure that contains the implementation of the symmetric cipher. See L for details of the B structure. =head1 SEE ALSO L, L, L =head1 COPYRIGHT Copyright 2017-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/EVP_idea_cbc.pod b/crypto/openssl/doc/man3/EVP_idea_cbc.pod index 5a9adaedc446..a36aae0bc999 100644 --- a/crypto/openssl/doc/man3/EVP_idea_cbc.pod +++ b/crypto/openssl/doc/man3/EVP_idea_cbc.pod @@ -1,66 +1,66 @@ =pod =head1 NAME EVP_idea_cbc, EVP_idea_cfb, EVP_idea_cfb64, EVP_idea_ecb, EVP_idea_ofb - EVP IDEA cipher =head1 SYNOPSIS #include const EVP_CIPHER *EVP_idea_cbc(void); const EVP_CIPHER *EVP_idea_cfb(void); const EVP_CIPHER *EVP_idea_cfb64(void); const EVP_CIPHER *EVP_idea_ecb(void); const EVP_CIPHER *EVP_idea_ofb(void); =head1 DESCRIPTION The IDEA encryption algorithm for EVP. =over 4 =item EVP_idea_cbc(), EVP_idea_cfb(), EVP_idea_cfb64(), EVP_idea_ecb(), EVP_idea_ofb() The IDEA encryption algorithm in CBC, CFB, ECB and OFB modes respectively. =back =head1 NOTES Developers should be aware of the negative performance implications of calling these functions multiple times and should consider using -L instead. +L with L instead. See L for further information. =head1 RETURN VALUES These functions return an B structure that contains the implementation of the symmetric cipher. See L for details of the B structure. =head1 SEE ALSO L, L, L =head1 COPYRIGHT Copyright 2017-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/EVP_md2.pod b/crypto/openssl/doc/man3/EVP_md2.pod index 0b473887e01b..a6f3a010deb5 100644 --- a/crypto/openssl/doc/man3/EVP_md2.pod +++ b/crypto/openssl/doc/man3/EVP_md2.pod @@ -1,60 +1,60 @@ =pod =head1 NAME EVP_md2 - MD2 For EVP =head1 SYNOPSIS #include const EVP_MD *EVP_md2(void); =head1 DESCRIPTION MD2 is a cryptographic hash function standardized in RFC 1319 and designed by Ronald Rivest. This implementation is only available with the legacy provider. =over 4 =item EVP_md2() The MD2 algorithm which produces a 128-bit output from a given input. =back =head1 NOTES Developers should be aware of the negative performance implications of calling this function multiple times and should consider using -L instead. +L with L instead. See L for further information. =head1 RETURN VALUES These functions return a B structure that contains the implementation of the message digest. See L for details of the B structure. =head1 CONFORMING TO IETF RFC 1319. =head1 SEE ALSO L, L, L =head1 COPYRIGHT Copyright 2017-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/EVP_md4.pod b/crypto/openssl/doc/man3/EVP_md4.pod index baaff9e4eaa2..a4e1a7d0a6e9 100644 --- a/crypto/openssl/doc/man3/EVP_md4.pod +++ b/crypto/openssl/doc/man3/EVP_md4.pod @@ -1,61 +1,61 @@ =pod =head1 NAME EVP_md4 - MD4 For EVP =head1 SYNOPSIS #include const EVP_MD *EVP_md4(void); =head1 DESCRIPTION MD4 is a cryptographic hash function standardized in RFC 1320 and designed by Ronald Rivest, first published in 1990. This implementation is only available with the legacy provider. =over 4 =item EVP_md4() The MD4 algorithm which produces a 128-bit output from a given input. =back =head1 NOTES Developers should be aware of the negative performance implications of calling this function multiple times and should consider using -L instead. +L with L instead. See L for further information. =head1 RETURN VALUES These functions return a B structure that contains the implementation of the message digest. See L for details of the B structure. =head1 CONFORMING TO IETF RFC 1320. =head1 SEE ALSO L, L, L =head1 COPYRIGHT Copyright 2017-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/EVP_md5.pod b/crypto/openssl/doc/man3/EVP_md5.pod index 752fdd1f6c37..42370fb3d0a3 100644 --- a/crypto/openssl/doc/man3/EVP_md5.pod +++ b/crypto/openssl/doc/man3/EVP_md5.pod @@ -1,71 +1,71 @@ =pod =head1 NAME EVP_md5, EVP_md5_sha1 - MD5 For EVP =head1 SYNOPSIS #include const EVP_MD *EVP_md5(void); const EVP_MD *EVP_md5_sha1(void); =head1 DESCRIPTION MD5 is a cryptographic hash function standardized in RFC 1321 and designed by Ronald Rivest. The CMU Software Engineering Institute considers MD5 unsuitable for further use since its security has been severely compromised. =over 4 =item EVP_md5() The MD5 algorithm which produces a 128-bit output from a given input. =item EVP_md5_sha1() A hash algorithm of SSL v3 that combines MD5 with SHA-1 as described in RFC 6101. WARNING: this algorithm is not intended for non-SSL usage. =back =head1 NOTES Developers should be aware of the negative performance implications of calling these functions multiple times and should consider using -L instead. +L with L or L instead. See L for further information. =head1 RETURN VALUES These functions return a B structure that contains the implementation of the message digest. See L for details of the B structure. =head1 CONFORMING TO IETF RFC 1321. =head1 SEE ALSO L, L =head1 COPYRIGHT Copyright 2017-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/EVP_mdc2.pod b/crypto/openssl/doc/man3/EVP_mdc2.pod index e9de6f3c560a..3681bd06a63c 100644 --- a/crypto/openssl/doc/man3/EVP_mdc2.pod +++ b/crypto/openssl/doc/man3/EVP_mdc2.pod @@ -1,62 +1,62 @@ =pod =head1 NAME EVP_mdc2 - MDC-2 For EVP =head1 SYNOPSIS #include const EVP_MD *EVP_mdc2(void); =head1 DESCRIPTION MDC-2 (Modification Detection Code 2 or Meyer-Schilling) is a cryptographic hash function based on a block cipher. This implementation is only available with the legacy provider. =over 4 =item EVP_mdc2() The MDC-2DES algorithm of using MDC-2 with the DES block cipher. It produces a 128-bit output from a given input. =back =head1 NOTES Developers should be aware of the negative performance implications of calling this function multiple times and should consider using -L instead. +L with L instead. See L for further information. =head1 RETURN VALUES These functions return a B structure that contains the implementation of the message digest. See L for details of the B structure. =head1 CONFORMING TO ISO/IEC 10118-2:2000 Hash-Function 2, with DES as the underlying block cipher. =head1 SEE ALSO L, L, L =head1 COPYRIGHT Copyright 2017-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/EVP_rc2_cbc.pod b/crypto/openssl/doc/man3/EVP_rc2_cbc.pod index bf4a13ba45c1..17f6f4b3e254 100644 --- a/crypto/openssl/doc/man3/EVP_rc2_cbc.pod +++ b/crypto/openssl/doc/man3/EVP_rc2_cbc.pod @@ -1,83 +1,83 @@ =pod =head1 NAME EVP_rc2_cbc, EVP_rc2_cfb, EVP_rc2_cfb64, EVP_rc2_ecb, EVP_rc2_ofb, EVP_rc2_40_cbc, EVP_rc2_64_cbc - EVP RC2 cipher =head1 SYNOPSIS #include const EVP_CIPHER *EVP_rc2_cbc(void); const EVP_CIPHER *EVP_rc2_cfb(void); const EVP_CIPHER *EVP_rc2_cfb64(void); const EVP_CIPHER *EVP_rc2_ecb(void); const EVP_CIPHER *EVP_rc2_ofb(void); const EVP_CIPHER *EVP_rc2_40_cbc(void); const EVP_CIPHER *EVP_rc2_64_cbc(void); =head1 DESCRIPTION The RC2 encryption algorithm for EVP. =over 4 =item EVP_rc2_cbc(), EVP_rc2_cfb(), EVP_rc2_cfb64(), EVP_rc2_ecb(), EVP_rc2_ofb() RC2 encryption algorithm in CBC, CFB, ECB and OFB modes respectively. This is a variable key length cipher with an additional parameter called "effective key bits" or "effective key length". By default both are set to 128 bits. =item EVP_rc2_40_cbc(), EVP_rc2_64_cbc() RC2 algorithm in CBC mode with a default key length and effective key length of 40 and 64 bits. WARNING: these functions are obsolete. Their usage should be replaced with the EVP_rc2_cbc(), EVP_CIPHER_CTX_set_key_length() and EVP_CIPHER_CTX_ctrl() functions to set the key length and effective key length. =back =head1 NOTES Developers should be aware of the negative performance implications of calling these functions multiple times and should consider using -L instead. +L with L instead. See L for further information. =head1 RETURN VALUES These functions return an B structure that contains the implementation of the symmetric cipher. See L for details of the B structure. =head1 SEE ALSO L, L, L =head1 COPYRIGHT Copyright 2017-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/EVP_rc4.pod b/crypto/openssl/doc/man3/EVP_rc4.pod index f22e88a65214..0311ef278ca1 100644 --- a/crypto/openssl/doc/man3/EVP_rc4.pod +++ b/crypto/openssl/doc/man3/EVP_rc4.pod @@ -1,74 +1,74 @@ =pod =head1 NAME EVP_rc4, EVP_rc4_40, EVP_rc4_hmac_md5 - EVP RC4 stream cipher =head1 SYNOPSIS #include const EVP_CIPHER *EVP_rc4(void); const EVP_CIPHER *EVP_rc4_40(void); const EVP_CIPHER *EVP_rc4_hmac_md5(void); =head1 DESCRIPTION The RC4 stream cipher for EVP. =over 4 =item EVP_rc4() RC4 stream cipher. This is a variable key length cipher with a default key length of 128 bits. =item EVP_rc4_40() RC4 stream cipher with 40 bit key length. WARNING: this function is obsolete. Its usage should be replaced with the EVP_rc4() and the EVP_CIPHER_CTX_set_key_length() functions. =item EVP_rc4_hmac_md5() Authenticated encryption with the RC4 stream cipher with MD5 as HMAC. WARNING: this is not intended for usage outside of TLS and requires calling of some undocumented ctrl functions. These ciphers do not conform to the EVP AEAD interface. =back =head1 NOTES Developers should be aware of the negative performance implications of calling these functions multiple times and should consider using -L instead. +L with L instead. See L for further information. =head1 RETURN VALUES These functions return an B structure that contains the implementation of the symmetric cipher. See L for details of the B structure. =head1 SEE ALSO L, L, L =head1 COPYRIGHT Copyright 2017-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/EVP_rc5_32_12_16_cbc.pod b/crypto/openssl/doc/man3/EVP_rc5_32_12_16_cbc.pod index c177b1845196..69fc2f2cc656 100644 --- a/crypto/openssl/doc/man3/EVP_rc5_32_12_16_cbc.pod +++ b/crypto/openssl/doc/man3/EVP_rc5_32_12_16_cbc.pod @@ -1,88 +1,88 @@ =pod =head1 NAME EVP_rc5_32_12_16_cbc, EVP_rc5_32_12_16_cfb, EVP_rc5_32_12_16_cfb64, EVP_rc5_32_12_16_ecb, EVP_rc5_32_12_16_ofb - EVP RC5 cipher =head1 SYNOPSIS #include const EVP_CIPHER *EVP_rc5_32_12_16_cbc(void); const EVP_CIPHER *EVP_rc5_32_12_16_cfb(void); const EVP_CIPHER *EVP_rc5_32_12_16_cfb64(void); const EVP_CIPHER *EVP_rc5_32_12_16_ecb(void); const EVP_CIPHER *EVP_rc5_32_12_16_ofb(void); =head1 DESCRIPTION The RC5 encryption algorithm for EVP. =over 4 =item EVP_rc5_32_12_16_cbc(), EVP_rc5_32_12_16_cfb(), EVP_rc5_32_12_16_cfb64(), EVP_rc5_32_12_16_ecb(), EVP_rc5_32_12_16_ofb() RC5 encryption algorithm in CBC, CFB, ECB and OFB modes respectively. This is a variable key length cipher with an additional "number of rounds" parameter. By default the key length is set to 128 bits and 12 rounds. Alternative key lengths can be set using L. The maximum key length is 2040 bits. The following rc5 specific Is are supported (see L). =over 4 =item EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_SET_RC5_ROUNDS, rounds, NULL) Sets the number of rounds to B. This must be one of RC5_8_ROUNDS, RC5_12_ROUNDS or RC5_16_ROUNDS. =item EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GET_RC5_ROUNDS, 0, &rounds) Stores the number of rounds currently configured in B<*rounds> where B<*rounds> is an int. =back =back =head1 NOTES Developers should be aware of the negative performance implications of calling these functions multiple times and should consider using -L instead. +L with L instead. See L for further information. =head1 RETURN VALUES These functions return an B structure that contains the implementation of the symmetric cipher. See L for details of the B structure. =head1 SEE ALSO L, L, L =head1 COPYRIGHT Copyright 2017-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/EVP_ripemd160.pod b/crypto/openssl/doc/man3/EVP_ripemd160.pod index 6ad2d3e01869..5b96fd09f850 100644 --- a/crypto/openssl/doc/man3/EVP_ripemd160.pod +++ b/crypto/openssl/doc/man3/EVP_ripemd160.pod @@ -1,61 +1,61 @@ =pod =head1 NAME EVP_ripemd160 - RIPEMD160 For EVP =head1 SYNOPSIS #include const EVP_MD *EVP_ripemd160(void); =head1 DESCRIPTION RIPEMD-160 is a cryptographic hash function first published in 1996 belonging to the RIPEMD family (RACE Integrity Primitives Evaluation Message Digest). This implementation is only available with the legacy provider. =over 4 =item EVP_ripemd160() The RIPEMD-160 algorithm which produces a 160-bit output from a given input. =back =head1 NOTES Developers should be aware of the negative performance implications of calling this function multiple times and should consider using -L instead. +L with L instead. See L for further information. =head1 RETURN VALUES These functions return a B structure that contains the implementation of the message digest. See L for details of the B structure. =head1 CONFORMING TO ISO/IEC 10118-3:2016 Dedicated Hash-Function 1 (RIPEMD-160). =head1 SEE ALSO L, L, L =head1 COPYRIGHT Copyright 2017-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/EVP_seed_cbc.pod b/crypto/openssl/doc/man3/EVP_seed_cbc.pod index 010607e57405..2c821d07c399 100644 --- a/crypto/openssl/doc/man3/EVP_seed_cbc.pod +++ b/crypto/openssl/doc/man3/EVP_seed_cbc.pod @@ -1,68 +1,68 @@ =pod =head1 NAME EVP_seed_cbc, EVP_seed_cfb, EVP_seed_cfb128, EVP_seed_ecb, EVP_seed_ofb - EVP SEED cipher =head1 SYNOPSIS #include const EVP_CIPHER *EVP_seed_cbc(void); const EVP_CIPHER *EVP_seed_cfb(void); const EVP_CIPHER *EVP_seed_cfb128(void); const EVP_CIPHER *EVP_seed_ecb(void); const EVP_CIPHER *EVP_seed_ofb(void); =head1 DESCRIPTION The SEED encryption algorithm for EVP. All modes below use a key length of 128 bits and acts on blocks of 128-bits. =over 4 =item EVP_seed_cbc(), EVP_seed_cfb(), EVP_seed_cfb128(), EVP_seed_ecb(), EVP_seed_ofb() The SEED encryption algorithm in CBC, CFB, ECB and OFB modes respectively. =back =head1 NOTES Developers should be aware of the negative performance implications of calling these functions multiple times and should consider using -L instead. +L with L instead. See L for further information. =head1 RETURN VALUES These functions return an B structure that contains the implementation of the symmetric cipher. See L for details of the B structure. =head1 SEE ALSO L, L, L =head1 COPYRIGHT Copyright 2017-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/EVP_sha1.pod b/crypto/openssl/doc/man3/EVP_sha1.pod index 264ddd1addb7..6fc8f07b066a 100644 --- a/crypto/openssl/doc/man3/EVP_sha1.pod +++ b/crypto/openssl/doc/man3/EVP_sha1.pod @@ -1,60 +1,60 @@ =pod =head1 NAME EVP_sha1 - SHA-1 For EVP =head1 SYNOPSIS #include const EVP_MD *EVP_sha1(void); =head1 DESCRIPTION SHA-1 (Secure Hash Algorithm 1) is a cryptographic hash function standardized in NIST FIPS 180-4. The algorithm was designed by the United States National Security Agency and initially published in 1995. =over 4 =item EVP_sha1() The SHA-1 algorithm which produces a 160-bit output from a given input. =back =head1 NOTES Developers should be aware of the negative performance implications of calling this function multiple times and should consider using -L instead. +L with L instead. See L for further information. =head1 RETURN VALUES These functions return a B structure that contains the implementation of the message digest. See L for details of the B structure. =head1 CONFORMING TO NIST FIPS 180-4. =head1 SEE ALSO L, L =head1 COPYRIGHT Copyright 2017-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/EVP_sha224.pod b/crypto/openssl/doc/man3/EVP_sha224.pod index 7a50cf9b6c3f..be09e49ee393 100644 --- a/crypto/openssl/doc/man3/EVP_sha224.pod +++ b/crypto/openssl/doc/man3/EVP_sha224.pod @@ -1,80 +1,80 @@ =pod =head1 NAME EVP_sha224, EVP_sha256, EVP_sha512_224, EVP_sha512_256, EVP_sha384, EVP_sha512 - SHA-2 For EVP =head1 SYNOPSIS #include const EVP_MD *EVP_sha224(void); const EVP_MD *EVP_sha256(void); const EVP_MD *EVP_sha512_224(void); const EVP_MD *EVP_sha512_256(void); const EVP_MD *EVP_sha384(void); const EVP_MD *EVP_sha512(void); =head1 DESCRIPTION SHA-2 (Secure Hash Algorithm 2) is a family of cryptographic hash functions standardized in NIST FIPS 180-4, first published in 2001. =over 4 =item EVP_sha224(), EVP_sha256(), EVP_sha512_224, EVP_sha512_256, EVP_sha384(), EVP_sha512() The SHA-2 SHA-224, SHA-256, SHA-512/224, SHA512/256, SHA-384 and SHA-512 algorithms, which generate 224, 256, 224, 256, 384 and 512 bits respectively of output from a given input. The two algorithms: SHA-512/224 and SHA512/256 are truncated forms of the SHA-512 algorithm. They are distinct from SHA-224 and SHA-256 even though their outputs are of the same size. =back =head1 NOTES Developers should be aware of the negative performance implications of calling these functions multiple times and should consider using -L instead. +L with Linstead. See L for further information. =head1 RETURN VALUES These functions return a B structure that contains the implementation of the message digest. See L for details of the B structure. =head1 CONFORMING TO NIST FIPS 180-4. =head1 SEE ALSO L, L =head1 COPYRIGHT Copyright 2017-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/EVP_sha3_224.pod b/crypto/openssl/doc/man3/EVP_sha3_224.pod index 5bb9ae1b89e5..93c0d0b9fb1e 100644 --- a/crypto/openssl/doc/man3/EVP_sha3_224.pod +++ b/crypto/openssl/doc/man3/EVP_sha3_224.pod @@ -1,85 +1,85 @@ =pod =head1 NAME EVP_sha3_224, EVP_sha3_256, EVP_sha3_384, EVP_sha3_512, EVP_shake128, EVP_shake256 - SHA-3 For EVP =head1 SYNOPSIS #include const EVP_MD *EVP_sha3_224(void); const EVP_MD *EVP_sha3_256(void); const EVP_MD *EVP_sha3_384(void); const EVP_MD *EVP_sha3_512(void); const EVP_MD *EVP_shake128(void); const EVP_MD *EVP_shake256(void); =head1 DESCRIPTION SHA-3 (Secure Hash Algorithm 3) is a family of cryptographic hash functions standardized in NIST FIPS 202, first published in 2015. It is based on the Keccak algorithm. =over 4 =item EVP_sha3_224(), EVP_sha3_256(), EVP_sha3_384(), EVP_sha3_512() The SHA-3 SHA-3-224, SHA-3-256, SHA-3-384, and SHA-3-512 algorithms respectively. They produce 224, 256, 384 and 512 bits of output from a given input. =item EVP_shake128(), EVP_shake256() The SHAKE-128 and SHAKE-256 Extendable Output Functions (XOF) that can generate a variable hash length. Specifically, B provides an overall security of 128 bits, while B provides that of 256 bits. =back =head1 NOTES Developers should be aware of the negative performance implications of calling these functions multiple times and should consider using -L instead. +L with L or L instead. See L for further information. =head1 RETURN VALUES These functions return a B structure that contains the implementation of the message digest. See L for details of the B structure. =head1 CONFORMING TO NIST FIPS 202. =head1 SEE ALSO L, L =head1 COPYRIGHT Copyright 2017-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/EVP_sm3.pod b/crypto/openssl/doc/man3/EVP_sm3.pod index 4e8112dc0afe..65be55e88dba 100644 --- a/crypto/openssl/doc/man3/EVP_sm3.pod +++ b/crypto/openssl/doc/man3/EVP_sm3.pod @@ -1,60 +1,60 @@ =pod =head1 NAME EVP_sm3 - SM3 for EVP =head1 SYNOPSIS #include const EVP_MD *EVP_sm3(void); =head1 DESCRIPTION SM3 is a cryptographic hash function with a 256-bit output, defined in GB/T 32905-2016. =over 4 =item EVP_sm3() The SM3 hash function. =back =head1 NOTES Developers should be aware of the negative performance implications of calling this function multiple times and should consider using -L instead. +L with L instead. See L for further information. =head1 RETURN VALUES These functions return a B structure that contains the implementation of the message digest. See L for details of the B structure. =head1 CONFORMING TO GB/T 32905-2016 and GM/T 0004-2012. =head1 SEE ALSO L, L =head1 COPYRIGHT Copyright 2017-2023 The OpenSSL Project Authors. All Rights Reserved. Copyright 2017 Ribose Inc. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/EVP_sm4_cbc.pod b/crypto/openssl/doc/man3/EVP_sm4_cbc.pod index b67ade549968..48be7a31ad75 100644 --- a/crypto/openssl/doc/man3/EVP_sm4_cbc.pod +++ b/crypto/openssl/doc/man3/EVP_sm4_cbc.pod @@ -1,74 +1,74 @@ =pod =head1 NAME EVP_sm4_cbc, EVP_sm4_ecb, EVP_sm4_cfb, EVP_sm4_cfb128, EVP_sm4_ofb, EVP_sm4_ctr - EVP SM4 cipher =head1 SYNOPSIS #include const EVP_CIPHER *EVP_sm4_cbc(void); const EVP_CIPHER *EVP_sm4_ecb(void); const EVP_CIPHER *EVP_sm4_cfb(void); const EVP_CIPHER *EVP_sm4_cfb128(void); const EVP_CIPHER *EVP_sm4_ofb(void); const EVP_CIPHER *EVP_sm4_ctr(void); =head1 DESCRIPTION The SM4 blockcipher (GB/T 32907-2016) for EVP. All modes below use a key length of 128 bits and acts on blocks of 128 bits. =over 4 =item EVP_sm4_cbc(), EVP_sm4_ecb(), EVP_sm4_cfb(), EVP_sm4_cfb128(), EVP_sm4_ofb(), EVP_sm4_ctr() The SM4 blockcipher with a 128-bit key in CBC, ECB, CFB, OFB and CTR modes respectively. =back =head1 NOTES Developers should be aware of the negative performance implications of calling these functions multiple times and should consider using -L instead. +L with L instead. See L for further information. =head1 RETURN VALUES These functions return a B structure that contains the implementation of the symmetric cipher. See L for details of the B structure. =head1 SEE ALSO L, L, L =head1 COPYRIGHT Copyright 2017-2023 The OpenSSL Project Authors. All Rights Reserved. Copyright 2017 Ribose Inc. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/EVP_whirlpool.pod b/crypto/openssl/doc/man3/EVP_whirlpool.pod index a9826e290a42..c5d465b16f0c 100644 --- a/crypto/openssl/doc/man3/EVP_whirlpool.pod +++ b/crypto/openssl/doc/man3/EVP_whirlpool.pod @@ -1,62 +1,62 @@ =pod =head1 NAME EVP_whirlpool - WHIRLPOOL For EVP =head1 SYNOPSIS #include const EVP_MD *EVP_whirlpool(void); =head1 DESCRIPTION WHIRLPOOL is a cryptographic hash function standardized in ISO/IEC 10118-3:2004 designed by Vincent Rijmen and Paulo S. L. M. Barreto. This implementation is only available with the legacy provider. =over 4 =item EVP_whirlpool() The WHIRLPOOL algorithm that produces a message digest of 512-bits from a given input. =back =head1 NOTES Developers should be aware of the negative performance implications of calling this function multiple times and should consider using -L instead. +L with L instead. See L for further information. =head1 RETURN VALUES These functions return a B structure that contains the implementation of the message digest. See L for details of the B structure. =head1 CONFORMING TO ISO/IEC 10118-3:2004. =head1 SEE ALSO L, L, L =head1 COPYRIGHT Copyright 2017-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/PKCS5_PBKDF2_HMAC.pod b/crypto/openssl/doc/man3/PKCS5_PBKDF2_HMAC.pod index 0984e993daef..8b5feff9192c 100644 --- a/crypto/openssl/doc/man3/PKCS5_PBKDF2_HMAC.pod +++ b/crypto/openssl/doc/man3/PKCS5_PBKDF2_HMAC.pod @@ -1,76 +1,77 @@ =pod =head1 NAME PKCS5_PBKDF2_HMAC, PKCS5_PBKDF2_HMAC_SHA1 - password based derivation routines with salt and iteration count =head1 SYNOPSIS #include int PKCS5_PBKDF2_HMAC(const char *pass, int passlen, const unsigned char *salt, int saltlen, int iter, const EVP_MD *digest, int keylen, unsigned char *out); int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen, const unsigned char *salt, int saltlen, int iter, int keylen, unsigned char *out); =head1 DESCRIPTION PKCS5_PBKDF2_HMAC() derives a key from a password using a salt and iteration count as specified in RFC 2898. B is the password used in the derivation of length B. B is an optional parameter and can be NULL. If B is -1, then the function will calculate the length of B using strlen(). B is the salt used in the derivation of length B. If the B is NULL, then B must be 0. The function will not attempt to calculate the length of the B because it is not assumed to be NULL terminated. B is the iteration count and its value should be greater than or equal to 1. RFC 2898 suggests an iteration count of at least 1000. Any -B less than 1 is treated as a single iteration. +B value less than 1 is invalid; such values will result in failure +and raise the PROV_R_INVALID_ITERATION_COUNT error. B is the message digest function used in the derivation. PKCS5_PBKDF2_HMAC_SHA1() calls PKCS5_PBKDF2_HMAC() with EVP_sha1(). The derived key will be written to B. The size of the B buffer is specified via B. =head1 NOTES A typical application of this function is to derive keying material for an encryption algorithm from a password in the B, a salt in B, and an iteration count. Increasing the B parameter slows down the algorithm which makes it harder for an attacker to perform a brute force attack using a large number of candidate passwords. These functions make no assumption regarding the given password. It will simply be treated as a byte sequence. =head1 RETURN VALUES PKCS5_PBKDF2_HMAC() and PBKCS5_PBKDF2_HMAC_SHA1() return 1 on success or 0 on error. =head1 SEE ALSO L, L, L, L =head1 COPYRIGHT -Copyright 2014-2021 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2014-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/SSL_CONF_CTX_set_ssl_ctx.pod b/crypto/openssl/doc/man3/SSL_CONF_CTX_set_ssl_ctx.pod index 06cc1e4ec539..3913ea939007 100644 --- a/crypto/openssl/doc/man3/SSL_CONF_CTX_set_ssl_ctx.pod +++ b/crypto/openssl/doc/man3/SSL_CONF_CTX_set_ssl_ctx.pod @@ -1,57 +1,65 @@ =pod =head1 NAME +SSL_CONF_CTX_finish, SSL_CONF_CTX_set_ssl_ctx, SSL_CONF_CTX_set_ssl - set context to configure =head1 SYNOPSIS #include void SSL_CONF_CTX_set_ssl_ctx(SSL_CONF_CTX *cctx, SSL_CTX *ctx); void SSL_CONF_CTX_set_ssl(SSL_CONF_CTX *cctx, SSL *ssl); + int SSL_CONF_CTX_finish(SSL_CONF_CTX *cctx); =head1 DESCRIPTION SSL_CONF_CTX_set_ssl_ctx() sets the context associated with B to the B structure B. Any previous B or B associated with B is cleared. Subsequent calls to SSL_CONF_cmd() will be sent to B. SSL_CONF_CTX_set_ssl() sets the context associated with B to the B structure B. Any previous B or B associated with B is cleared. Subsequent calls to SSL_CONF_cmd() will be sent to B. +The function SSL_CONF_CTX_finish() must be called after all configuration +operations have been completed. It is used to finalise any operations +or to process defaults. + =head1 NOTES The context need not be set or it can be set to B in which case only syntax checking of commands is performed, where possible. =head1 RETURN VALUES SSL_CONF_CTX_set_ssl_ctx() and SSL_CTX_set_ssl() do not return a value. +SSL_CONF_CTX_finish() returns 1 for success and 0 for failure. + =head1 SEE ALSO L, L, L, L, L, L =head1 HISTORY These functions were added in OpenSSL 1.0.2. =head1 COPYRIGHT -Copyright 2012-2016 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2012-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/SSL_CTX_set_info_callback.pod b/crypto/openssl/doc/man3/SSL_CTX_set_info_callback.pod index 9cee64207384..c1c6a67f85a7 100644 --- a/crypto/openssl/doc/man3/SSL_CTX_set_info_callback.pod +++ b/crypto/openssl/doc/man3/SSL_CTX_set_info_callback.pod @@ -1,166 +1,170 @@ =pod =head1 NAME SSL_CTX_set_info_callback, SSL_CTX_get_info_callback, SSL_set_info_callback, SSL_get_info_callback - handle information callback for SSL connections =head1 SYNOPSIS #include - void SSL_CTX_set_info_callback(SSL_CTX *ctx, void (*callback)()); - void (*SSL_CTX_get_info_callback(const SSL_CTX *ctx))(); + void SSL_CTX_set_info_callback(SSL_CTX *ctx, + void (*callback) (const SSL *ssl, int type, int val)); - void SSL_set_info_callback(SSL *ssl, void (*callback)()); - void (*SSL_get_info_callback(const SSL *ssl))(); + void (*SSL_CTX_get_info_callback(SSL_CTX *ctx)) (const SSL *ssl, int type, int val); + + void SSL_set_info_callback(SSL *ssl, + void (*callback) (const SSL *ssl, int type, int val)); + + void (*SSL_get_info_callback(const SSL *ssl)) (const SSL *ssl, int type, int val); =head1 DESCRIPTION SSL_CTX_set_info_callback() sets the B function, that can be used to obtain state information for SSL objects created from B during connection setup and use. The setting for B is overridden from the setting for a specific SSL object, if specified. When B is NULL, no callback function is used. SSL_set_info_callback() sets the B function, that can be used to obtain state information for B during connection setup and use. When B is NULL, the callback setting currently valid for B is used. SSL_CTX_get_info_callback() returns a pointer to the currently set information callback function for B. SSL_get_info_callback() returns a pointer to the currently set information callback function for B. =head1 NOTES When setting up a connection and during use, it is possible to obtain state information from the SSL/TLS engine. When set, an information callback function is called whenever a significant event occurs such as: the state changes, an alert appears, or an error occurs. The callback function is called as B. The B argument specifies information about where (in which context) the callback function was called. If B is 0, an error condition occurred. If an alert is handled, SSL_CB_ALERT is set and B specifies the alert information. B is a bit-mask made up of the following bits: =over 4 =item SSL_CB_LOOP Callback has been called to indicate state change or some other significant state machine event. This may mean that the callback gets invoked more than once per state in some situations. =item SSL_CB_EXIT Callback has been called to indicate exit of a handshake function. This will happen after the end of a handshake, but may happen at other times too such as on error or when IO might otherwise block and nonblocking is being used. =item SSL_CB_READ Callback has been called during read operation. =item SSL_CB_WRITE Callback has been called during write operation. =item SSL_CB_ALERT Callback has been called due to an alert being sent or received. =item SSL_CB_READ_ALERT (SSL_CB_ALERT|SSL_CB_READ) =item SSL_CB_WRITE_ALERT (SSL_CB_ALERT|SSL_CB_WRITE) =item SSL_CB_ACCEPT_LOOP (SSL_ST_ACCEPT|SSL_CB_LOOP) =item SSL_CB_ACCEPT_EXIT (SSL_ST_ACCEPT|SSL_CB_EXIT) =item SSL_CB_CONNECT_LOOP (SSL_ST_CONNECT|SSL_CB_LOOP) =item SSL_CB_CONNECT_EXIT (SSL_ST_CONNECT|SSL_CB_EXIT) =item SSL_CB_HANDSHAKE_START Callback has been called because a new handshake is started. It also occurs when resuming a handshake following a pause to handle early data. =item SSL_CB_HANDSHAKE_DONE Callback has been called because a handshake is finished. It also occurs if the handshake is paused to allow the exchange of early data. =back The current state information can be obtained using the L family of functions. The B information can be evaluated using the L family of functions. =head1 RETURN VALUES SSL_set_info_callback() does not provide diagnostic information. SSL_get_info_callback() returns the current setting. =head1 EXAMPLES The following example callback function prints state strings, information about alerts being handled and error messages to the B BIO. - void apps_ssl_info_callback(SSL *s, int where, int ret) + void apps_ssl_info_callback(const SSL *s, int where, int ret) { const char *str; int w = where & ~SSL_ST_MASK; if (w & SSL_ST_CONNECT) str = "SSL_connect"; else if (w & SSL_ST_ACCEPT) str = "SSL_accept"; else str = "undefined"; if (where & SSL_CB_LOOP) { BIO_printf(bio_err, "%s:%s\n", str, SSL_state_string_long(s)); } else if (where & SSL_CB_ALERT) { str = (where & SSL_CB_READ) ? "read" : "write"; BIO_printf(bio_err, "SSL3 alert %s:%s:%s\n", str, SSL_alert_type_string_long(ret), SSL_alert_desc_string_long(ret)); } else if (where & SSL_CB_EXIT) { if (ret == 0) { BIO_printf(bio_err, "%s:failed in %s\n", str, SSL_state_string_long(s)); } else if (ret < 0) { BIO_printf(bio_err, "%s:error in %s\n", str, SSL_state_string_long(s)); } } } =head1 SEE ALSO L, L, L =head1 COPYRIGHT -Copyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2001-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/d2i_PKCS8PrivateKey_bio.pod b/crypto/openssl/doc/man3/d2i_PKCS8PrivateKey_bio.pod index 5b5371b70f19..51d8aa8cfb47 100644 --- a/crypto/openssl/doc/man3/d2i_PKCS8PrivateKey_bio.pod +++ b/crypto/openssl/doc/man3/d2i_PKCS8PrivateKey_bio.pod @@ -1,74 +1,74 @@ =pod =head1 NAME d2i_PKCS8PrivateKey_bio, d2i_PKCS8PrivateKey_fp, i2d_PKCS8PrivateKey_bio, i2d_PKCS8PrivateKey_fp, i2d_PKCS8PrivateKey_nid_bio, i2d_PKCS8PrivateKey_nid_fp - PKCS#8 format private key functions =head1 SYNOPSIS - #include + #include EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u); EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u); int i2d_PKCS8PrivateKey_bio(BIO *bp, const EVP_PKEY *x, const EVP_CIPHER *enc, char *kstr, int klen, pem_password_cb *cb, void *u); int i2d_PKCS8PrivateKey_fp(FILE *fp, const EVP_PKEY *x, const EVP_CIPHER *enc, char *kstr, int klen, pem_password_cb *cb, void *u); int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, const EVP_PKEY *x, int nid, char *kstr, int klen, pem_password_cb *cb, void *u); int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, const EVP_PKEY *x, int nid, char *kstr, int klen, pem_password_cb *cb, void *u); =head1 DESCRIPTION The PKCS#8 functions encode and decode private keys in PKCS#8 format using both PKCS#5 v1.5 and PKCS#5 v2.0 password based encryption algorithms. Other than the use of DER as opposed to PEM these functions are identical to the corresponding B function as described in L. =head1 NOTES These functions are currently the only way to store encrypted private keys using DER format. Currently all the functions use BIOs or FILE pointers, there are no functions which work directly on memory: this can be readily worked around by converting the buffers to memory BIOs, see L for details. These functions make no assumption regarding the pass phrase received from the password callback. It will simply be treated as a byte sequence. =head1 RETURN VALUES d2i_PKCS8PrivateKey_bio() and d2i_PKCS8PrivateKey_fp() return a valid B structure or NULL if an error occurred. i2d_PKCS8PrivateKey_bio(), i2d_PKCS8PrivateKey_fp(), i2d_PKCS8PrivateKey_nid_bio() and i2d_PKCS8PrivateKey_nid_fp() return 1 on success or 0 on error. =head1 SEE ALSO L, L =head1 COPYRIGHT -Copyright 2002-2018 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2002-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/doc/man3/d2i_X509.pod b/crypto/openssl/doc/man3/d2i_X509.pod index 9226ef77c394..00efb6035816 100644 --- a/crypto/openssl/doc/man3/d2i_X509.pod +++ b/crypto/openssl/doc/man3/d2i_X509.pod @@ -1,607 +1,625 @@ =pod =begin comment Any keypair function here that gets deprecated should be moved to d2i_RSAPrivateKey.pod. =end comment =head1 NAME d2i_ACCESS_DESCRIPTION, d2i_ADMISSIONS, d2i_ADMISSION_SYNTAX, d2i_ASIdOrRange, d2i_ASIdentifierChoice, d2i_ASIdentifiers, d2i_ASN1_BIT_STRING, d2i_ASN1_BMPSTRING, d2i_ASN1_ENUMERATED, d2i_ASN1_GENERALIZEDTIME, d2i_ASN1_GENERALSTRING, d2i_ASN1_IA5STRING, d2i_ASN1_INTEGER, d2i_ASN1_NULL, d2i_ASN1_OBJECT, d2i_ASN1_OCTET_STRING, d2i_ASN1_PRINTABLE, d2i_ASN1_PRINTABLESTRING, d2i_ASN1_SEQUENCE_ANY, d2i_ASN1_SET_ANY, d2i_ASN1_T61STRING, d2i_ASN1_TIME, d2i_ASN1_TYPE, d2i_ASN1_UINTEGER, d2i_ASN1_UNIVERSALSTRING, d2i_ASN1_UTCTIME, d2i_ASN1_UTF8STRING, d2i_ASN1_VISIBLESTRING, d2i_ASRange, d2i_AUTHORITY_INFO_ACCESS, d2i_AUTHORITY_KEYID, d2i_BASIC_CONSTRAINTS, d2i_CERTIFICATEPOLICIES, d2i_CMS_ContentInfo, d2i_CMS_ReceiptRequest, d2i_CMS_bio, d2i_CRL_DIST_POINTS, d2i_DHxparams, d2i_DIRECTORYSTRING, d2i_DISPLAYTEXT, d2i_DIST_POINT, d2i_DIST_POINT_NAME, d2i_DSA_SIG, d2i_ECDSA_SIG, d2i_ECPKParameters, d2i_EDIPARTYNAME, d2i_ESS_CERT_ID, d2i_ESS_CERT_ID_V2, d2i_ESS_ISSUER_SERIAL, d2i_ESS_SIGNING_CERT, d2i_ESS_SIGNING_CERT_V2, d2i_EXTENDED_KEY_USAGE, d2i_GENERAL_NAME, d2i_GENERAL_NAMES, d2i_IPAddressChoice, d2i_IPAddressFamily, d2i_IPAddressOrRange, d2i_IPAddressRange, d2i_ISSUER_SIGN_TOOL, d2i_ISSUING_DIST_POINT, d2i_NAMING_AUTHORITY, d2i_NETSCAPE_CERT_SEQUENCE, d2i_NETSCAPE_SPKAC, d2i_NETSCAPE_SPKI, d2i_NOTICEREF, d2i_OCSP_BASICRESP, d2i_OCSP_CERTID, d2i_OCSP_CERTSTATUS, d2i_OCSP_CRLID, d2i_OCSP_ONEREQ, d2i_OCSP_REQINFO, d2i_OCSP_REQUEST, d2i_OCSP_RESPBYTES, d2i_OCSP_RESPDATA, d2i_OCSP_RESPID, d2i_OCSP_RESPONSE, d2i_OCSP_REVOKEDINFO, d2i_OCSP_SERVICELOC, d2i_OCSP_SIGNATURE, d2i_OCSP_SINGLERESP, d2i_OSSL_CMP_MSG, d2i_OSSL_CMP_PKIHEADER, d2i_OSSL_CMP_PKISI, d2i_OSSL_CRMF_CERTID, d2i_OSSL_CRMF_CERTTEMPLATE, d2i_OSSL_CRMF_ENCRYPTEDVALUE, d2i_OSSL_CRMF_MSG, d2i_OSSL_CRMF_MSGS, d2i_OSSL_CRMF_PBMPARAMETER, d2i_OSSL_CRMF_PKIPUBLICATIONINFO, d2i_OSSL_CRMF_SINGLEPUBINFO, d2i_OTHERNAME, d2i_PBE2PARAM, d2i_PBEPARAM, d2i_PBKDF2PARAM, d2i_PKCS12, d2i_PKCS12_BAGS, d2i_PKCS12_MAC_DATA, d2i_PKCS12_SAFEBAG, d2i_PKCS12_bio, d2i_PKCS12_fp, d2i_PKCS7, d2i_PKCS7_DIGEST, d2i_PKCS7_ENCRYPT, d2i_PKCS7_ENC_CONTENT, d2i_PKCS7_ENVELOPE, d2i_PKCS7_ISSUER_AND_SERIAL, d2i_PKCS7_RECIP_INFO, d2i_PKCS7_SIGNED, d2i_PKCS7_SIGNER_INFO, d2i_PKCS7_SIGN_ENVELOPE, d2i_PKCS7_bio, d2i_PKCS7_fp, d2i_PKCS8_PRIV_KEY_INFO, d2i_PKCS8_PRIV_KEY_INFO_bio, d2i_PKCS8_PRIV_KEY_INFO_fp, d2i_PKCS8_bio, d2i_PKCS8_fp, d2i_PKEY_USAGE_PERIOD, d2i_POLICYINFO, d2i_POLICYQUALINFO, d2i_PROFESSION_INFO, d2i_PROXY_CERT_INFO_EXTENSION, d2i_PROXY_POLICY, d2i_RSA_OAEP_PARAMS, d2i_RSA_PSS_PARAMS, d2i_SCRYPT_PARAMS, d2i_SCT_LIST, d2i_SXNET, d2i_SXNETID, d2i_TS_ACCURACY, d2i_TS_MSG_IMPRINT, d2i_TS_MSG_IMPRINT_bio, d2i_TS_MSG_IMPRINT_fp, d2i_TS_REQ, d2i_TS_REQ_bio, d2i_TS_REQ_fp, d2i_TS_RESP, d2i_TS_RESP_bio, d2i_TS_RESP_fp, d2i_TS_STATUS_INFO, d2i_TS_TST_INFO, d2i_TS_TST_INFO_bio, d2i_TS_TST_INFO_fp, d2i_USERNOTICE, d2i_X509, d2i_X509_bio, d2i_X509_fp, d2i_X509_ALGOR, d2i_X509_ALGORS, d2i_X509_ATTRIBUTE, d2i_X509_CERT_AUX, d2i_X509_CINF, d2i_X509_CRL, d2i_X509_CRL_INFO, d2i_X509_CRL_bio, d2i_X509_CRL_fp, d2i_X509_EXTENSION, d2i_X509_EXTENSIONS, d2i_X509_NAME, d2i_X509_NAME_ENTRY, d2i_X509_PUBKEY, d2i_X509_PUBKEY_bio, d2i_X509_PUBKEY_fp, d2i_X509_REQ, d2i_X509_REQ_INFO, d2i_X509_REQ_bio, d2i_X509_REQ_fp, d2i_X509_REVOKED, d2i_X509_SIG, d2i_X509_VAL, i2d_ACCESS_DESCRIPTION, i2d_ADMISSIONS, i2d_ADMISSION_SYNTAX, i2d_ASIdOrRange, i2d_ASIdentifierChoice, i2d_ASIdentifiers, i2d_ASN1_BIT_STRING, i2d_ASN1_BMPSTRING, i2d_ASN1_ENUMERATED, i2d_ASN1_GENERALIZEDTIME, i2d_ASN1_GENERALSTRING, i2d_ASN1_IA5STRING, i2d_ASN1_INTEGER, i2d_ASN1_NULL, i2d_ASN1_OBJECT, i2d_ASN1_OCTET_STRING, i2d_ASN1_PRINTABLE, i2d_ASN1_PRINTABLESTRING, i2d_ASN1_SEQUENCE_ANY, i2d_ASN1_SET_ANY, i2d_ASN1_T61STRING, i2d_ASN1_TIME, i2d_ASN1_TYPE, i2d_ASN1_UNIVERSALSTRING, i2d_ASN1_UTCTIME, i2d_ASN1_UTF8STRING, i2d_ASN1_VISIBLESTRING, i2d_ASN1_bio_stream, i2d_ASRange, i2d_AUTHORITY_INFO_ACCESS, i2d_AUTHORITY_KEYID, i2d_BASIC_CONSTRAINTS, i2d_CERTIFICATEPOLICIES, i2d_CMS_ContentInfo, i2d_CMS_ReceiptRequest, i2d_CMS_bio, i2d_CRL_DIST_POINTS, i2d_DHxparams, i2d_DIRECTORYSTRING, i2d_DISPLAYTEXT, i2d_DIST_POINT, i2d_DIST_POINT_NAME, i2d_DSA_SIG, i2d_ECDSA_SIG, i2d_ECPKParameters, i2d_EDIPARTYNAME, i2d_ESS_CERT_ID, i2d_ESS_CERT_ID_V2, i2d_ESS_ISSUER_SERIAL, i2d_ESS_SIGNING_CERT, i2d_ESS_SIGNING_CERT_V2, i2d_EXTENDED_KEY_USAGE, i2d_GENERAL_NAME, i2d_GENERAL_NAMES, i2d_IPAddressChoice, i2d_IPAddressFamily, i2d_IPAddressOrRange, i2d_IPAddressRange, i2d_ISSUER_SIGN_TOOL, i2d_ISSUING_DIST_POINT, i2d_NAMING_AUTHORITY, i2d_NETSCAPE_CERT_SEQUENCE, i2d_NETSCAPE_SPKAC, i2d_NETSCAPE_SPKI, i2d_NOTICEREF, i2d_OCSP_BASICRESP, i2d_OCSP_CERTID, i2d_OCSP_CERTSTATUS, i2d_OCSP_CRLID, i2d_OCSP_ONEREQ, i2d_OCSP_REQINFO, i2d_OCSP_REQUEST, i2d_OCSP_RESPBYTES, i2d_OCSP_RESPDATA, i2d_OCSP_RESPID, i2d_OCSP_RESPONSE, i2d_OCSP_REVOKEDINFO, i2d_OCSP_SERVICELOC, i2d_OCSP_SIGNATURE, i2d_OCSP_SINGLERESP, i2d_OSSL_CMP_MSG, i2d_OSSL_CMP_PKIHEADER, i2d_OSSL_CMP_PKISI, i2d_OSSL_CRMF_CERTID, i2d_OSSL_CRMF_CERTTEMPLATE, i2d_OSSL_CRMF_ENCRYPTEDVALUE, i2d_OSSL_CRMF_MSG, i2d_OSSL_CRMF_MSGS, i2d_OSSL_CRMF_PBMPARAMETER, i2d_OSSL_CRMF_PKIPUBLICATIONINFO, i2d_OSSL_CRMF_SINGLEPUBINFO, i2d_OTHERNAME, i2d_PBE2PARAM, i2d_PBEPARAM, i2d_PBKDF2PARAM, i2d_PKCS12, i2d_PKCS12_BAGS, i2d_PKCS12_MAC_DATA, i2d_PKCS12_SAFEBAG, i2d_PKCS12_bio, i2d_PKCS12_fp, i2d_PKCS7, i2d_PKCS7_DIGEST, i2d_PKCS7_ENCRYPT, i2d_PKCS7_ENC_CONTENT, i2d_PKCS7_ENVELOPE, i2d_PKCS7_ISSUER_AND_SERIAL, i2d_PKCS7_NDEF, i2d_PKCS7_RECIP_INFO, i2d_PKCS7_SIGNED, i2d_PKCS7_SIGNER_INFO, i2d_PKCS7_SIGN_ENVELOPE, i2d_PKCS7_bio, i2d_PKCS7_fp, i2d_PKCS8PrivateKeyInfo_bio, i2d_PKCS8PrivateKeyInfo_fp, i2d_PKCS8_PRIV_KEY_INFO, i2d_PKCS8_PRIV_KEY_INFO_bio, i2d_PKCS8_PRIV_KEY_INFO_fp, i2d_PKCS8_bio, i2d_PKCS8_fp, i2d_PKEY_USAGE_PERIOD, i2d_POLICYINFO, i2d_POLICYQUALINFO, i2d_PROFESSION_INFO, i2d_PROXY_CERT_INFO_EXTENSION, i2d_PROXY_POLICY, i2d_RSA_OAEP_PARAMS, i2d_RSA_PSS_PARAMS, i2d_SCRYPT_PARAMS, i2d_SCT_LIST, i2d_SXNET, i2d_SXNETID, i2d_TS_ACCURACY, i2d_TS_MSG_IMPRINT, i2d_TS_MSG_IMPRINT_bio, i2d_TS_MSG_IMPRINT_fp, i2d_TS_REQ, i2d_TS_REQ_bio, i2d_TS_REQ_fp, i2d_TS_RESP, i2d_TS_RESP_bio, i2d_TS_RESP_fp, i2d_TS_STATUS_INFO, i2d_TS_TST_INFO, i2d_TS_TST_INFO_bio, i2d_TS_TST_INFO_fp, i2d_USERNOTICE, i2d_X509, i2d_X509_bio, i2d_X509_fp, i2d_X509_ALGOR, i2d_X509_ALGORS, i2d_X509_ATTRIBUTE, i2d_X509_CERT_AUX, i2d_X509_CINF, i2d_X509_CRL, i2d_X509_CRL_INFO, i2d_X509_CRL_bio, i2d_X509_CRL_fp, i2d_X509_EXTENSION, i2d_X509_EXTENSIONS, i2d_X509_NAME, i2d_X509_NAME_ENTRY, i2d_X509_PUBKEY, i2d_X509_PUBKEY_bio, i2d_X509_PUBKEY_fp, i2d_X509_REQ, i2d_X509_REQ_INFO, i2d_X509_REQ_bio, i2d_X509_REQ_fp, i2d_X509_REVOKED, i2d_X509_SIG, i2d_X509_VAL, - convert objects from/to ASN.1/DER representation =head1 SYNOPSIS =for openssl generic TYPE *d2i_TYPE(TYPE **a, const unsigned char **ppin, long length); TYPE *d2i_TYPE_bio(BIO *bp, TYPE **a); TYPE *d2i_TYPE_fp(FILE *fp, TYPE **a); int i2d_TYPE(const TYPE *a, unsigned char **ppout); int i2d_TYPE(TYPE *a, unsigned char **ppout); int i2d_TYPE_fp(FILE *fp, const TYPE *a); int i2d_TYPE_fp(FILE *fp, TYPE *a); int i2d_TYPE_bio(BIO *bp, const TYPE *a); int i2d_TYPE_bio(BIO *bp, TYPE *a); =head1 DESCRIPTION In the description here, B> is used a placeholder for any of the OpenSSL datatypes, such as B. The function parameters I and I are generally either both named I in the headers, or I and I. These functions convert OpenSSL objects to and from their ASN.1/DER encoding. Unlike the C structures which can have pointers to sub-objects within, the DER is a serialized encoding, suitable for sending over the network, writing to a file, and so on. B>() attempts to decode I bytes at I<*ppin>. If successful a pointer to the B> structure is returned and I<*ppin> is incremented to the byte following the parsed data. If I is not NULL then a pointer to the returned structure is also written to I<*a>. If an error occurred then NULL is returned. On a successful return, if I<*a> is not NULL then it is assumed that I<*a> -contains a valid B> structure and an attempt is made to reuse it. This -"reuse" capability is present for historical compatibility but its use is -B (see BUGS below, and the discussion in the RETURN -VALUES section). +contains a valid B> structure and an attempt is made to reuse it. +For B> structures where it matters it is possible to set up a library +context on the decoded structure this way (see the B section). +However using the "reuse" capability for other purposes is B (see B below, and the discussion in the B +section). B_bio>() is similar to B>() except it attempts to parse data from BIO I. B_fp>() is similar to B>() except it attempts to parse data from FILE pointer I. B>() encodes the structure pointed to by I into DER format. If I is not NULL, it writes the DER encoded data to the buffer at I<*ppout>, and increments it to point after the data just written. If the return value is negative an error occurred, otherwise it returns the length of the encoded data. If I<*ppout> is NULL memory will be allocated for a buffer and the encoded data written to it. In this case I<*ppout> is not incremented and it points to the start of the data just written. B_bio>() is similar to B>() except it writes the encoding of the structure I to BIO I and it returns 1 for success and 0 for failure. B_fp>() is similar to B>() except it writes the encoding of the structure I to FILE pointer I and it returns 1 for success and 0 for failure. These routines do not encrypt private keys and therefore offer no security; use L or similar for writing to files. =head1 NOTES The letters B and B in B>() stand for "internal" (that is, an internal C structure) and "DER" respectively. So B>() converts from internal to DER. The functions can also understand B forms. The actual TYPE structure passed to B>() must be a valid populated B> structure -- it B simply be fed with an empty structure such as that returned by TYPE_new(). The encoded data is in binary form and may contain embedded zeros. Therefore, any FILE pointers or BIOs should be opened in binary mode. Functions such as strlen() will B return the correct length of the encoded structure. The ways that I<*ppin> and I<*ppout> are incremented after the operation can trap the unwary. See the B section for some common errors. The reason for this-auto increment behaviour is to reflect a typical usage of ASN1 functions: after one structure is encoded or decoded another will be processed after it. The following points about the data types might be useful: =over 4 =item B Represents an ASN1 OBJECT IDENTIFIER. =item B Represents a PKCS#3 DH parameters structure. =item B Represents an ANSI X9.42 DH parameters structure. =item B Represents an ECDSA signature. =item B Represents an B structure as used in IETF RFC 6960 and elsewhere. =item B Represents a B type as used for subject and issuer names in IETF RFC 6960 and elsewhere. =item B Represents a PKCS#10 certificate request. =item B Represents the B structure defined in PKCS#1 and PKCS#7. =back =head1 RETURN VALUES B>(), B_bio>() and B_fp>() return a valid B> structure or NULL if an error occurs. If the "reuse" capability has been used with a valid structure being passed in via I, then the object is freed in the event of error and I<*a> is set to NULL. B>() returns the number of bytes successfully encoded or a negative value if an error occurs. B_bio>() and B_fp>() return 1 for success and 0 if an error occurs. =head1 EXAMPLES Allocate and encode the DER encoding of an X509 structure: int len; unsigned char *buf; buf = NULL; len = i2d_X509(x, &buf); if (len < 0) /* error */ Attempt to decode a buffer: X509 *x; unsigned char *buf; const unsigned char *p; int len; /* Set up buf and len to point to the input buffer. */ p = buf; x = d2i_X509(NULL, &p, len); if (x == NULL) /* error */ Alternative technique: X509 *x; unsigned char *buf; const unsigned char *p; int len; /* Set up buf and len to point to the input buffer. */ p = buf; x = NULL; if (d2i_X509(&x, &p, len) == NULL) /* error */ +Setting up a library context and property query: + + X509 *x; + unsigned char *buf; + const unsigned char *p; + int len; + OSSL_LIB_CTX *libctx = ....; + const char *propq = ....; + + /* Set up buf and len to point to the input buffer. */ + p = buf; + x = X509_new_ex(libctx, propq); + + if (d2i_X509(&x, &p, len) == NULL) + /* error, x was freed and NULL assigned to it (see RETURN VALUES) */ + =head1 WARNINGS Using a temporary variable is mandatory. A common mistake is to attempt to use a buffer directly as follows: int len; unsigned char *buf; len = i2d_X509(x, NULL); buf = OPENSSL_malloc(len); ... i2d_X509(x, &buf); ... OPENSSL_free(buf); This code will result in I apparently containing garbage because it was incremented after the call to point after the data just written. Also I will no longer contain the pointer allocated by OPENSSL_malloc() and the subsequent call to OPENSSL_free() is likely to crash. Another trap to avoid is misuse of the I argument to B>(): X509 *x; if (d2i_X509(&x, &p, len) == NULL) /* error */ This will probably crash somewhere in d2i_X509(). The reason for this is that the variable I is uninitialized and an attempt will be made to interpret its (invalid) value as an B structure, typically causing a segmentation violation. If I is set to NULL first then this will not happen. =head1 BUGS In some versions of OpenSSL the "reuse" behaviour of B>() when I<*a> is valid is broken and some parts of the reused structure may persist if they are not present in the new one. Additionally, in versions of OpenSSL prior to 1.1.0, when the "reuse" behaviour is used and an error occurs the behaviour is inconsistent. Some functions behaved as described here, while some did not free I<*a> on error and did not set I<*a> to NULL. As a result of the above issues the "reuse" behaviour is strongly discouraged. B>() will not return an error in many versions of OpenSSL, if mandatory fields are not initialized due to a programming error then the encoded structure may contain invalid data or omit the fields entirely and will not be parsed by B>(). This may be fixed in future so code should not assume that B>() will always succeed. Any function which encodes a structure (B>(), B_bio>() or B_fp>()) may return a stale encoding if the structure has been modified after deserialization or previous serialization. This is because some objects cache the encoding for efficiency reasons. =head1 COPYRIGHT Copyright 1998-2023 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut diff --git a/crypto/openssl/include/openssl/cmserr.h b/crypto/openssl/include/openssl/cmserr.h index d48c2a4ab89f..f2d7708f10c8 100644 --- a/crypto/openssl/include/openssl/cmserr.h +++ b/crypto/openssl/include/openssl/cmserr.h @@ -1,123 +1,124 @@ /* * Generated by util/mkerr.pl DO NOT EDIT - * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ #ifndef OPENSSL_CMSERR_H # define OPENSSL_CMSERR_H # pragma once # include # include # include # ifndef OPENSSL_NO_CMS /* * CMS reason codes. */ # define CMS_R_ADD_SIGNER_ERROR 99 # define CMS_R_ATTRIBUTE_ERROR 161 # define CMS_R_CERTIFICATE_ALREADY_PRESENT 175 # define CMS_R_CERTIFICATE_HAS_NO_KEYID 160 # define CMS_R_CERTIFICATE_VERIFY_ERROR 100 # define CMS_R_CIPHER_AEAD_SET_TAG_ERROR 184 # define CMS_R_CIPHER_GET_TAG 185 # define CMS_R_CIPHER_INITIALISATION_ERROR 101 # define CMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR 102 # define CMS_R_CMS_DATAFINAL_ERROR 103 # define CMS_R_CMS_LIB 104 # define CMS_R_CONTENTIDENTIFIER_MISMATCH 170 # define CMS_R_CONTENT_NOT_FOUND 105 # define CMS_R_CONTENT_TYPE_MISMATCH 171 # define CMS_R_CONTENT_TYPE_NOT_COMPRESSED_DATA 106 # define CMS_R_CONTENT_TYPE_NOT_ENVELOPED_DATA 107 # define CMS_R_CONTENT_TYPE_NOT_SIGNED_DATA 108 # define CMS_R_CONTENT_VERIFY_ERROR 109 # define CMS_R_CTRL_ERROR 110 # define CMS_R_CTRL_FAILURE 111 # define CMS_R_DECODE_ERROR 187 # define CMS_R_DECRYPT_ERROR 112 # define CMS_R_ERROR_GETTING_PUBLIC_KEY 113 # define CMS_R_ERROR_READING_MESSAGEDIGEST_ATTRIBUTE 114 # define CMS_R_ERROR_SETTING_KEY 115 # define CMS_R_ERROR_SETTING_RECIPIENTINFO 116 # define CMS_R_ESS_SIGNING_CERTID_MISMATCH_ERROR 183 # define CMS_R_INVALID_ENCRYPTED_KEY_LENGTH 117 # define CMS_R_INVALID_KEY_ENCRYPTION_PARAMETER 176 # define CMS_R_INVALID_KEY_LENGTH 118 # define CMS_R_INVALID_LABEL 190 # define CMS_R_INVALID_OAEP_PARAMETERS 191 # define CMS_R_KDF_PARAMETER_ERROR 186 # define CMS_R_MD_BIO_INIT_ERROR 119 # define CMS_R_MESSAGEDIGEST_ATTRIBUTE_WRONG_LENGTH 120 # define CMS_R_MESSAGEDIGEST_WRONG_LENGTH 121 # define CMS_R_MSGSIGDIGEST_ERROR 172 # define CMS_R_MSGSIGDIGEST_VERIFICATION_FAILURE 162 # define CMS_R_MSGSIGDIGEST_WRONG_LENGTH 163 # define CMS_R_NEED_ONE_SIGNER 164 # define CMS_R_NOT_A_SIGNED_RECEIPT 165 # define CMS_R_NOT_ENCRYPTED_DATA 122 # define CMS_R_NOT_KEK 123 # define CMS_R_NOT_KEY_AGREEMENT 181 # define CMS_R_NOT_KEY_TRANSPORT 124 # define CMS_R_NOT_PWRI 177 # define CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE 125 # define CMS_R_NO_CIPHER 126 # define CMS_R_NO_CONTENT 127 # define CMS_R_NO_CONTENT_TYPE 173 # define CMS_R_NO_DEFAULT_DIGEST 128 # define CMS_R_NO_DIGEST_SET 129 # define CMS_R_NO_KEY 130 # define CMS_R_NO_KEY_OR_CERT 174 # define CMS_R_NO_MATCHING_DIGEST 131 # define CMS_R_NO_MATCHING_RECIPIENT 132 # define CMS_R_NO_MATCHING_SIGNATURE 166 # define CMS_R_NO_MSGSIGDIGEST 167 # define CMS_R_NO_PASSWORD 178 # define CMS_R_NO_PRIVATE_KEY 133 # define CMS_R_NO_PUBLIC_KEY 134 # define CMS_R_NO_RECEIPT_REQUEST 168 # define CMS_R_NO_SIGNERS 135 # define CMS_R_PEER_KEY_ERROR 188 # define CMS_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE 136 # define CMS_R_RECEIPT_DECODE_ERROR 169 # define CMS_R_RECIPIENT_ERROR 137 # define CMS_R_SHARED_INFO_ERROR 189 # define CMS_R_SIGNER_CERTIFICATE_NOT_FOUND 138 # define CMS_R_SIGNFINAL_ERROR 139 # define CMS_R_SMIME_TEXT_ERROR 140 # define CMS_R_STORE_INIT_ERROR 141 # define CMS_R_TYPE_NOT_COMPRESSED_DATA 142 # define CMS_R_TYPE_NOT_DATA 143 # define CMS_R_TYPE_NOT_DIGESTED_DATA 144 # define CMS_R_TYPE_NOT_ENCRYPTED_DATA 145 # define CMS_R_TYPE_NOT_ENVELOPED_DATA 146 # define CMS_R_UNABLE_TO_FINALIZE_CONTEXT 147 # define CMS_R_UNKNOWN_CIPHER 148 # define CMS_R_UNKNOWN_DIGEST_ALGORITHM 149 # define CMS_R_UNKNOWN_ID 150 # define CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM 151 # define CMS_R_UNSUPPORTED_CONTENT_ENCRYPTION_ALGORITHM 194 # define CMS_R_UNSUPPORTED_CONTENT_TYPE 152 # define CMS_R_UNSUPPORTED_ENCRYPTION_TYPE 192 # define CMS_R_UNSUPPORTED_KEK_ALGORITHM 153 # define CMS_R_UNSUPPORTED_KEY_ENCRYPTION_ALGORITHM 179 # define CMS_R_UNSUPPORTED_LABEL_SOURCE 193 # define CMS_R_UNSUPPORTED_RECIPIENTINFO_TYPE 155 # define CMS_R_UNSUPPORTED_RECIPIENT_TYPE 154 +# define CMS_R_UNSUPPORTED_SIGNATURE_ALGORITHM 195 # define CMS_R_UNSUPPORTED_TYPE 156 # define CMS_R_UNWRAP_ERROR 157 # define CMS_R_UNWRAP_FAILURE 180 # define CMS_R_VERIFICATION_FAILURE 158 # define CMS_R_WRAP_ERROR 159 # endif #endif diff --git a/crypto/openssl/include/openssl/evp.h b/crypto/openssl/include/openssl/evp.h index 49e8e1df7865..e64072f96562 100644 --- a/crypto/openssl/include/openssl/evp.h +++ b/crypto/openssl/include/openssl/evp.h @@ -1,2170 +1,2172 @@ /* - * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ #ifndef OPENSSL_EVP_H # define OPENSSL_EVP_H # pragma once # include # ifndef OPENSSL_NO_DEPRECATED_3_0 # define HEADER_ENVELOPE_H # endif # include # ifndef OPENSSL_NO_STDIO # include # endif # include # include # include # include # include # include # include # include # define EVP_MAX_MD_SIZE 64/* longest known is SHA512 */ # define EVP_MAX_KEY_LENGTH 64 # define EVP_MAX_IV_LENGTH 16 # define EVP_MAX_BLOCK_LENGTH 32 # define PKCS5_SALT_LEN 8 /* Default PKCS#5 iteration count */ # define PKCS5_DEFAULT_ITER 2048 # include # ifndef OPENSSL_NO_DEPRECATED_3_0 # define EVP_PK_RSA 0x0001 # define EVP_PK_DSA 0x0002 # define EVP_PK_DH 0x0004 # define EVP_PK_EC 0x0008 # define EVP_PKT_SIGN 0x0010 # define EVP_PKT_ENC 0x0020 # define EVP_PKT_EXCH 0x0040 # define EVP_PKS_RSA 0x0100 # define EVP_PKS_DSA 0x0200 # define EVP_PKS_EC 0x0400 # endif # define EVP_PKEY_NONE NID_undef # define EVP_PKEY_RSA NID_rsaEncryption # define EVP_PKEY_RSA2 NID_rsa # define EVP_PKEY_RSA_PSS NID_rsassaPss # define EVP_PKEY_DSA NID_dsa # define EVP_PKEY_DSA1 NID_dsa_2 # define EVP_PKEY_DSA2 NID_dsaWithSHA # define EVP_PKEY_DSA3 NID_dsaWithSHA1 # define EVP_PKEY_DSA4 NID_dsaWithSHA1_2 # define EVP_PKEY_DH NID_dhKeyAgreement # define EVP_PKEY_DHX NID_dhpublicnumber # define EVP_PKEY_EC NID_X9_62_id_ecPublicKey # define EVP_PKEY_SM2 NID_sm2 # define EVP_PKEY_HMAC NID_hmac # define EVP_PKEY_CMAC NID_cmac # define EVP_PKEY_SCRYPT NID_id_scrypt # define EVP_PKEY_TLS1_PRF NID_tls1_prf # define EVP_PKEY_HKDF NID_hkdf # define EVP_PKEY_POLY1305 NID_poly1305 # define EVP_PKEY_SIPHASH NID_siphash # define EVP_PKEY_X25519 NID_X25519 # define EVP_PKEY_ED25519 NID_ED25519 # define EVP_PKEY_X448 NID_X448 # define EVP_PKEY_ED448 NID_ED448 /* Special indicator that the object is uniquely provider side */ # define EVP_PKEY_KEYMGMT -1 /* Easy to use macros for EVP_PKEY related selections */ # define EVP_PKEY_KEY_PARAMETERS \ ( OSSL_KEYMGMT_SELECT_ALL_PARAMETERS ) +# define EVP_PKEY_PRIVATE_KEY \ + ( EVP_PKEY_KEY_PARAMETERS | OSSL_KEYMGMT_SELECT_PRIVATE_KEY ) # define EVP_PKEY_PUBLIC_KEY \ ( EVP_PKEY_KEY_PARAMETERS | OSSL_KEYMGMT_SELECT_PUBLIC_KEY ) # define EVP_PKEY_KEYPAIR \ ( EVP_PKEY_PUBLIC_KEY | OSSL_KEYMGMT_SELECT_PRIVATE_KEY ) #ifdef __cplusplus extern "C" { #endif int EVP_set_default_properties(OSSL_LIB_CTX *libctx, const char *propq); int EVP_default_properties_is_fips_enabled(OSSL_LIB_CTX *libctx); int EVP_default_properties_enable_fips(OSSL_LIB_CTX *libctx, int enable); # define EVP_PKEY_MO_SIGN 0x0001 # define EVP_PKEY_MO_VERIFY 0x0002 # define EVP_PKEY_MO_ENCRYPT 0x0004 # define EVP_PKEY_MO_DECRYPT 0x0008 # ifndef EVP_MD # ifndef OPENSSL_NO_DEPRECATED_3_0 OSSL_DEPRECATEDIN_3_0 EVP_MD *EVP_MD_meth_new(int md_type, int pkey_type); OSSL_DEPRECATEDIN_3_0 EVP_MD *EVP_MD_meth_dup(const EVP_MD *md); OSSL_DEPRECATEDIN_3_0 void EVP_MD_meth_free(EVP_MD *md); OSSL_DEPRECATEDIN_3_0 int EVP_MD_meth_set_input_blocksize(EVP_MD *md, int blocksize); OSSL_DEPRECATEDIN_3_0 int EVP_MD_meth_set_result_size(EVP_MD *md, int resultsize); OSSL_DEPRECATEDIN_3_0 int EVP_MD_meth_set_app_datasize(EVP_MD *md, int datasize); OSSL_DEPRECATEDIN_3_0 int EVP_MD_meth_set_flags(EVP_MD *md, unsigned long flags); OSSL_DEPRECATEDIN_3_0 int EVP_MD_meth_set_init(EVP_MD *md, int (*init)(EVP_MD_CTX *ctx)); OSSL_DEPRECATEDIN_3_0 int EVP_MD_meth_set_update(EVP_MD *md, int (*update)(EVP_MD_CTX *ctx, const void *data, size_t count)); OSSL_DEPRECATEDIN_3_0 int EVP_MD_meth_set_final(EVP_MD *md, int (*final)(EVP_MD_CTX *ctx, unsigned char *md)); OSSL_DEPRECATEDIN_3_0 int EVP_MD_meth_set_copy(EVP_MD *md, int (*copy)(EVP_MD_CTX *to, const EVP_MD_CTX *from)); OSSL_DEPRECATEDIN_3_0 int EVP_MD_meth_set_cleanup(EVP_MD *md, int (*cleanup)(EVP_MD_CTX *ctx)); OSSL_DEPRECATEDIN_3_0 int EVP_MD_meth_set_ctrl(EVP_MD *md, int (*ctrl)(EVP_MD_CTX *ctx, int cmd, int p1, void *p2)); OSSL_DEPRECATEDIN_3_0 int EVP_MD_meth_get_input_blocksize(const EVP_MD *md); OSSL_DEPRECATEDIN_3_0 int EVP_MD_meth_get_result_size(const EVP_MD *md); OSSL_DEPRECATEDIN_3_0 int EVP_MD_meth_get_app_datasize(const EVP_MD *md); OSSL_DEPRECATEDIN_3_0 unsigned long EVP_MD_meth_get_flags(const EVP_MD *md); OSSL_DEPRECATEDIN_3_0 int (*EVP_MD_meth_get_init(const EVP_MD *md))(EVP_MD_CTX *ctx); OSSL_DEPRECATEDIN_3_0 int (*EVP_MD_meth_get_update(const EVP_MD *md))(EVP_MD_CTX *ctx, const void *data, size_t count); OSSL_DEPRECATEDIN_3_0 int (*EVP_MD_meth_get_final(const EVP_MD *md))(EVP_MD_CTX *ctx, unsigned char *md); OSSL_DEPRECATEDIN_3_0 int (*EVP_MD_meth_get_copy(const EVP_MD *md))(EVP_MD_CTX *to, const EVP_MD_CTX *from); OSSL_DEPRECATEDIN_3_0 int (*EVP_MD_meth_get_cleanup(const EVP_MD *md))(EVP_MD_CTX *ctx); OSSL_DEPRECATEDIN_3_0 int (*EVP_MD_meth_get_ctrl(const EVP_MD *md))(EVP_MD_CTX *ctx, int cmd, int p1, void *p2); # endif /* digest can only handle a single block */ # define EVP_MD_FLAG_ONESHOT 0x0001 /* digest is extensible-output function, XOF */ # define EVP_MD_FLAG_XOF 0x0002 /* DigestAlgorithmIdentifier flags... */ # define EVP_MD_FLAG_DIGALGID_MASK 0x0018 /* NULL or absent parameter accepted. Use NULL */ # define EVP_MD_FLAG_DIGALGID_NULL 0x0000 /* NULL or absent parameter accepted. Use NULL for PKCS#1 otherwise absent */ # define EVP_MD_FLAG_DIGALGID_ABSENT 0x0008 /* Custom handling via ctrl */ # define EVP_MD_FLAG_DIGALGID_CUSTOM 0x0018 /* Note if suitable for use in FIPS mode */ # define EVP_MD_FLAG_FIPS 0x0400 /* Digest ctrls */ # define EVP_MD_CTRL_DIGALGID 0x1 # define EVP_MD_CTRL_MICALG 0x2 # define EVP_MD_CTRL_XOF_LEN 0x3 # define EVP_MD_CTRL_TLSTREE 0x4 /* Minimum Algorithm specific ctrl value */ # define EVP_MD_CTRL_ALG_CTRL 0x1000 # endif /* !EVP_MD */ /* values for EVP_MD_CTX flags */ # define EVP_MD_CTX_FLAG_ONESHOT 0x0001/* digest update will be * called once only */ # define EVP_MD_CTX_FLAG_CLEANED 0x0002/* context has already been * cleaned */ # define EVP_MD_CTX_FLAG_REUSE 0x0004/* Don't free up ctx->md_data * in EVP_MD_CTX_reset */ /* * FIPS and pad options are ignored in 1.0.0, definitions are here so we * don't accidentally reuse the values for other purposes. */ /* This flag has no effect from openssl-3.0 onwards */ # define EVP_MD_CTX_FLAG_NON_FIPS_ALLOW 0x0008 /* * The following PAD options are also currently ignored in 1.0.0, digest * parameters are handled through EVP_DigestSign*() and EVP_DigestVerify*() * instead. */ # define EVP_MD_CTX_FLAG_PAD_MASK 0xF0/* RSA mode to use */ # define EVP_MD_CTX_FLAG_PAD_PKCS1 0x00/* PKCS#1 v1.5 mode */ # define EVP_MD_CTX_FLAG_PAD_X931 0x10/* X9.31 mode */ # define EVP_MD_CTX_FLAG_PAD_PSS 0x20/* PSS mode */ # define EVP_MD_CTX_FLAG_NO_INIT 0x0100/* Don't initialize md_data */ /* * Some functions such as EVP_DigestSign only finalise copies of internal * contexts so additional data can be included after the finalisation call. * This is inefficient if this functionality is not required: it is disabled * if the following flag is set. */ # define EVP_MD_CTX_FLAG_FINALISE 0x0200 /* NOTE: 0x0400 is reserved for internal usage */ # ifndef OPENSSL_NO_DEPRECATED_3_0 OSSL_DEPRECATEDIN_3_0 EVP_CIPHER *EVP_CIPHER_meth_new(int cipher_type, int block_size, int key_len); OSSL_DEPRECATEDIN_3_0 EVP_CIPHER *EVP_CIPHER_meth_dup(const EVP_CIPHER *cipher); OSSL_DEPRECATEDIN_3_0 void EVP_CIPHER_meth_free(EVP_CIPHER *cipher); OSSL_DEPRECATEDIN_3_0 int EVP_CIPHER_meth_set_iv_length(EVP_CIPHER *cipher, int iv_len); OSSL_DEPRECATEDIN_3_0 int EVP_CIPHER_meth_set_flags(EVP_CIPHER *cipher, unsigned long flags); OSSL_DEPRECATEDIN_3_0 int EVP_CIPHER_meth_set_impl_ctx_size(EVP_CIPHER *cipher, int ctx_size); OSSL_DEPRECATEDIN_3_0 int EVP_CIPHER_meth_set_init(EVP_CIPHER *cipher, int (*init) (EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc)); OSSL_DEPRECATEDIN_3_0 int EVP_CIPHER_meth_set_do_cipher(EVP_CIPHER *cipher, int (*do_cipher) (EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl)); OSSL_DEPRECATEDIN_3_0 int EVP_CIPHER_meth_set_cleanup(EVP_CIPHER *cipher, int (*cleanup) (EVP_CIPHER_CTX *)); OSSL_DEPRECATEDIN_3_0 int EVP_CIPHER_meth_set_set_asn1_params(EVP_CIPHER *cipher, int (*set_asn1_parameters) (EVP_CIPHER_CTX *, ASN1_TYPE *)); OSSL_DEPRECATEDIN_3_0 int EVP_CIPHER_meth_set_get_asn1_params(EVP_CIPHER *cipher, int (*get_asn1_parameters) (EVP_CIPHER_CTX *, ASN1_TYPE *)); OSSL_DEPRECATEDIN_3_0 int EVP_CIPHER_meth_set_ctrl(EVP_CIPHER *cipher, int (*ctrl) (EVP_CIPHER_CTX *, int type, int arg, void *ptr)); OSSL_DEPRECATEDIN_3_0 int (*EVP_CIPHER_meth_get_init(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc); OSSL_DEPRECATEDIN_3_0 int (*EVP_CIPHER_meth_get_do_cipher(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl); OSSL_DEPRECATEDIN_3_0 int (*EVP_CIPHER_meth_get_cleanup(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *); OSSL_DEPRECATEDIN_3_0 int (*EVP_CIPHER_meth_get_set_asn1_params(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *, ASN1_TYPE *); OSSL_DEPRECATEDIN_3_0 int (*EVP_CIPHER_meth_get_get_asn1_params(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *, ASN1_TYPE *); OSSL_DEPRECATEDIN_3_0 int (*EVP_CIPHER_meth_get_ctrl(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *, int type, int arg, void *ptr); # endif /* Values for cipher flags */ /* Modes for ciphers */ # define EVP_CIPH_STREAM_CIPHER 0x0 # define EVP_CIPH_ECB_MODE 0x1 # define EVP_CIPH_CBC_MODE 0x2 # define EVP_CIPH_CFB_MODE 0x3 # define EVP_CIPH_OFB_MODE 0x4 # define EVP_CIPH_CTR_MODE 0x5 # define EVP_CIPH_GCM_MODE 0x6 # define EVP_CIPH_CCM_MODE 0x7 # define EVP_CIPH_XTS_MODE 0x10001 # define EVP_CIPH_WRAP_MODE 0x10002 # define EVP_CIPH_OCB_MODE 0x10003 # define EVP_CIPH_SIV_MODE 0x10004 # define EVP_CIPH_MODE 0xF0007 /* Set if variable length cipher */ # define EVP_CIPH_VARIABLE_LENGTH 0x8 /* Set if the iv handling should be done by the cipher itself */ # define EVP_CIPH_CUSTOM_IV 0x10 /* Set if the cipher's init() function should be called if key is NULL */ # define EVP_CIPH_ALWAYS_CALL_INIT 0x20 /* Call ctrl() to init cipher parameters */ # define EVP_CIPH_CTRL_INIT 0x40 /* Don't use standard key length function */ # define EVP_CIPH_CUSTOM_KEY_LENGTH 0x80 /* Don't use standard block padding */ # define EVP_CIPH_NO_PADDING 0x100 /* cipher handles random key generation */ # define EVP_CIPH_RAND_KEY 0x200 /* cipher has its own additional copying logic */ # define EVP_CIPH_CUSTOM_COPY 0x400 /* Don't use standard iv length function */ # define EVP_CIPH_CUSTOM_IV_LENGTH 0x800 /* Legacy and no longer relevant: Allow use default ASN1 get/set iv */ # define EVP_CIPH_FLAG_DEFAULT_ASN1 0 /* Free: 0x1000 */ /* Buffer length in bits not bytes: CFB1 mode only */ # define EVP_CIPH_FLAG_LENGTH_BITS 0x2000 /* Deprecated FIPS flag: was 0x4000 */ # define EVP_CIPH_FLAG_FIPS 0 /* Deprecated FIPS flag: was 0x8000 */ # define EVP_CIPH_FLAG_NON_FIPS_ALLOW 0 /* * Cipher handles any and all padding logic as well as finalisation. */ # define EVP_CIPH_FLAG_CTS 0x4000 # define EVP_CIPH_FLAG_CUSTOM_CIPHER 0x100000 # define EVP_CIPH_FLAG_AEAD_CIPHER 0x200000 # define EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK 0x400000 /* Cipher can handle pipeline operations */ # define EVP_CIPH_FLAG_PIPELINE 0X800000 /* For provider implementations that handle ASN1 get/set param themselves */ # define EVP_CIPH_FLAG_CUSTOM_ASN1 0x1000000 /* For ciphers generating unprotected CMS attributes */ # define EVP_CIPH_FLAG_CIPHER_WITH_MAC 0x2000000 /* For supplementary wrap cipher support */ # define EVP_CIPH_FLAG_GET_WRAP_CIPHER 0x4000000 # define EVP_CIPH_FLAG_INVERSE_CIPHER 0x8000000 /* * Cipher context flag to indicate we can handle wrap mode: if allowed in * older applications it could overflow buffers. */ # define EVP_CIPHER_CTX_FLAG_WRAP_ALLOW 0x1 /* ctrl() values */ # define EVP_CTRL_INIT 0x0 # define EVP_CTRL_SET_KEY_LENGTH 0x1 # define EVP_CTRL_GET_RC2_KEY_BITS 0x2 # define EVP_CTRL_SET_RC2_KEY_BITS 0x3 # define EVP_CTRL_GET_RC5_ROUNDS 0x4 # define EVP_CTRL_SET_RC5_ROUNDS 0x5 # define EVP_CTRL_RAND_KEY 0x6 # define EVP_CTRL_PBE_PRF_NID 0x7 # define EVP_CTRL_COPY 0x8 # define EVP_CTRL_AEAD_SET_IVLEN 0x9 # define EVP_CTRL_AEAD_GET_TAG 0x10 # define EVP_CTRL_AEAD_SET_TAG 0x11 # define EVP_CTRL_AEAD_SET_IV_FIXED 0x12 # define EVP_CTRL_GCM_SET_IVLEN EVP_CTRL_AEAD_SET_IVLEN # define EVP_CTRL_GCM_GET_TAG EVP_CTRL_AEAD_GET_TAG # define EVP_CTRL_GCM_SET_TAG EVP_CTRL_AEAD_SET_TAG # define EVP_CTRL_GCM_SET_IV_FIXED EVP_CTRL_AEAD_SET_IV_FIXED # define EVP_CTRL_GCM_IV_GEN 0x13 # define EVP_CTRL_CCM_SET_IVLEN EVP_CTRL_AEAD_SET_IVLEN # define EVP_CTRL_CCM_GET_TAG EVP_CTRL_AEAD_GET_TAG # define EVP_CTRL_CCM_SET_TAG EVP_CTRL_AEAD_SET_TAG # define EVP_CTRL_CCM_SET_IV_FIXED EVP_CTRL_AEAD_SET_IV_FIXED # define EVP_CTRL_CCM_SET_L 0x14 # define EVP_CTRL_CCM_SET_MSGLEN 0x15 /* * AEAD cipher deduces payload length and returns number of bytes required to * store MAC and eventual padding. Subsequent call to EVP_Cipher even * appends/verifies MAC. */ # define EVP_CTRL_AEAD_TLS1_AAD 0x16 /* Used by composite AEAD ciphers, no-op in GCM, CCM... */ # define EVP_CTRL_AEAD_SET_MAC_KEY 0x17 /* Set the GCM invocation field, decrypt only */ # define EVP_CTRL_GCM_SET_IV_INV 0x18 # define EVP_CTRL_TLS1_1_MULTIBLOCK_AAD 0x19 # define EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT 0x1a # define EVP_CTRL_TLS1_1_MULTIBLOCK_DECRYPT 0x1b # define EVP_CTRL_TLS1_1_MULTIBLOCK_MAX_BUFSIZE 0x1c # define EVP_CTRL_SSL3_MASTER_SECRET 0x1d /* EVP_CTRL_SET_SBOX takes the char * specifying S-boxes */ # define EVP_CTRL_SET_SBOX 0x1e /* * EVP_CTRL_SBOX_USED takes a 'size_t' and 'char *', pointing at a * pre-allocated buffer with specified size */ # define EVP_CTRL_SBOX_USED 0x1f /* EVP_CTRL_KEY_MESH takes 'size_t' number of bytes to mesh the key after, * 0 switches meshing off */ # define EVP_CTRL_KEY_MESH 0x20 /* EVP_CTRL_BLOCK_PADDING_MODE takes the padding mode */ # define EVP_CTRL_BLOCK_PADDING_MODE 0x21 /* Set the output buffers to use for a pipelined operation */ # define EVP_CTRL_SET_PIPELINE_OUTPUT_BUFS 0x22 /* Set the input buffers to use for a pipelined operation */ # define EVP_CTRL_SET_PIPELINE_INPUT_BUFS 0x23 /* Set the input buffer lengths to use for a pipelined operation */ # define EVP_CTRL_SET_PIPELINE_INPUT_LENS 0x24 /* Get the IV length used by the cipher */ # define EVP_CTRL_GET_IVLEN 0x25 /* 0x26 is unused */ /* Tell the cipher it's doing a speed test (SIV disallows multiple ops) */ # define EVP_CTRL_SET_SPEED 0x27 /* Get the unprotectedAttrs from cipher ctx */ # define EVP_CTRL_PROCESS_UNPROTECTED 0x28 /* Get the supplementary wrap cipher */ #define EVP_CTRL_GET_WRAP_CIPHER 0x29 /* TLSTREE key diversification */ #define EVP_CTRL_TLSTREE 0x2A /* Padding modes */ #define EVP_PADDING_PKCS7 1 #define EVP_PADDING_ISO7816_4 2 #define EVP_PADDING_ANSI923 3 #define EVP_PADDING_ISO10126 4 #define EVP_PADDING_ZERO 5 /* RFC 5246 defines additional data to be 13 bytes in length */ # define EVP_AEAD_TLS1_AAD_LEN 13 typedef struct { unsigned char *out; const unsigned char *inp; size_t len; unsigned int interleave; } EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM; /* GCM TLS constants */ /* Length of fixed part of IV derived from PRF */ # define EVP_GCM_TLS_FIXED_IV_LEN 4 /* Length of explicit part of IV part of TLS records */ # define EVP_GCM_TLS_EXPLICIT_IV_LEN 8 /* Length of tag for TLS */ # define EVP_GCM_TLS_TAG_LEN 16 /* CCM TLS constants */ /* Length of fixed part of IV derived from PRF */ # define EVP_CCM_TLS_FIXED_IV_LEN 4 /* Length of explicit part of IV part of TLS records */ # define EVP_CCM_TLS_EXPLICIT_IV_LEN 8 /* Total length of CCM IV length for TLS */ # define EVP_CCM_TLS_IV_LEN 12 /* Length of tag for TLS */ # define EVP_CCM_TLS_TAG_LEN 16 /* Length of CCM8 tag for TLS */ # define EVP_CCM8_TLS_TAG_LEN 8 /* Length of tag for TLS */ # define EVP_CHACHAPOLY_TLS_TAG_LEN 16 typedef struct evp_cipher_info_st { const EVP_CIPHER *cipher; unsigned char iv[EVP_MAX_IV_LENGTH]; } EVP_CIPHER_INFO; /* Password based encryption function */ typedef int (EVP_PBE_KEYGEN) (EVP_CIPHER_CTX *ctx, const char *pass, int passlen, ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md, int en_de); typedef int (EVP_PBE_KEYGEN_EX) (EVP_CIPHER_CTX *ctx, const char *pass, int passlen, ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md, int en_de, OSSL_LIB_CTX *libctx, const char *propq); # ifndef OPENSSL_NO_DEPRECATED_3_0 # define EVP_PKEY_assign_RSA(pkey,rsa) EVP_PKEY_assign((pkey),EVP_PKEY_RSA,\ (rsa)) # endif # ifndef OPENSSL_NO_DSA # define EVP_PKEY_assign_DSA(pkey,dsa) EVP_PKEY_assign((pkey),EVP_PKEY_DSA,\ (dsa)) # endif # if !defined(OPENSSL_NO_DH) && !defined(OPENSSL_NO_DEPRECATED_3_0) # define EVP_PKEY_assign_DH(pkey,dh) EVP_PKEY_assign((pkey),EVP_PKEY_DH,(dh)) # endif # ifndef OPENSSL_NO_DEPRECATED_3_0 # ifndef OPENSSL_NO_EC # define EVP_PKEY_assign_EC_KEY(pkey,eckey) \ EVP_PKEY_assign((pkey), EVP_PKEY_EC, (eckey)) # endif # endif # ifndef OPENSSL_NO_SIPHASH # define EVP_PKEY_assign_SIPHASH(pkey,shkey) EVP_PKEY_assign((pkey),\ EVP_PKEY_SIPHASH,(shkey)) # endif # ifndef OPENSSL_NO_POLY1305 # define EVP_PKEY_assign_POLY1305(pkey,polykey) EVP_PKEY_assign((pkey),\ EVP_PKEY_POLY1305,(polykey)) # endif /* Add some extra combinations */ # define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a)) # define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a)) # define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a)) # define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a)) int EVP_MD_get_type(const EVP_MD *md); # define EVP_MD_type EVP_MD_get_type # define EVP_MD_nid EVP_MD_get_type const char *EVP_MD_get0_name(const EVP_MD *md); # define EVP_MD_name EVP_MD_get0_name const char *EVP_MD_get0_description(const EVP_MD *md); int EVP_MD_is_a(const EVP_MD *md, const char *name); int EVP_MD_names_do_all(const EVP_MD *md, void (*fn)(const char *name, void *data), void *data); const OSSL_PROVIDER *EVP_MD_get0_provider(const EVP_MD *md); int EVP_MD_get_pkey_type(const EVP_MD *md); # define EVP_MD_pkey_type EVP_MD_get_pkey_type int EVP_MD_get_size(const EVP_MD *md); # define EVP_MD_size EVP_MD_get_size int EVP_MD_get_block_size(const EVP_MD *md); # define EVP_MD_block_size EVP_MD_get_block_size unsigned long EVP_MD_get_flags(const EVP_MD *md); # define EVP_MD_flags EVP_MD_get_flags const EVP_MD *EVP_MD_CTX_get0_md(const EVP_MD_CTX *ctx); EVP_MD *EVP_MD_CTX_get1_md(EVP_MD_CTX *ctx); # ifndef OPENSSL_NO_DEPRECATED_3_0 OSSL_DEPRECATEDIN_3_0 const EVP_MD *EVP_MD_CTX_md(const EVP_MD_CTX *ctx); OSSL_DEPRECATEDIN_3_0 int (*EVP_MD_CTX_update_fn(EVP_MD_CTX *ctx))(EVP_MD_CTX *ctx, const void *data, size_t count); OSSL_DEPRECATEDIN_3_0 void EVP_MD_CTX_set_update_fn(EVP_MD_CTX *ctx, int (*update) (EVP_MD_CTX *ctx, const void *data, size_t count)); # endif # define EVP_MD_CTX_get0_name(e) EVP_MD_get0_name(EVP_MD_CTX_get0_md(e)) # define EVP_MD_CTX_get_size(e) EVP_MD_get_size(EVP_MD_CTX_get0_md(e)) # define EVP_MD_CTX_size EVP_MD_CTX_get_size # define EVP_MD_CTX_get_block_size(e) EVP_MD_get_block_size(EVP_MD_CTX_get0_md(e)) # define EVP_MD_CTX_block_size EVP_MD_CTX_get_block_size # define EVP_MD_CTX_get_type(e) EVP_MD_get_type(EVP_MD_CTX_get0_md(e)) # define EVP_MD_CTX_type EVP_MD_CTX_get_type EVP_PKEY_CTX *EVP_MD_CTX_get_pkey_ctx(const EVP_MD_CTX *ctx); # define EVP_MD_CTX_pkey_ctx EVP_MD_CTX_get_pkey_ctx void EVP_MD_CTX_set_pkey_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pctx); void *EVP_MD_CTX_get0_md_data(const EVP_MD_CTX *ctx); # define EVP_MD_CTX_md_data EVP_MD_CTX_get0_md_data int EVP_CIPHER_get_nid(const EVP_CIPHER *cipher); # define EVP_CIPHER_nid EVP_CIPHER_get_nid const char *EVP_CIPHER_get0_name(const EVP_CIPHER *cipher); # define EVP_CIPHER_name EVP_CIPHER_get0_name const char *EVP_CIPHER_get0_description(const EVP_CIPHER *cipher); int EVP_CIPHER_is_a(const EVP_CIPHER *cipher, const char *name); int EVP_CIPHER_names_do_all(const EVP_CIPHER *cipher, void (*fn)(const char *name, void *data), void *data); const OSSL_PROVIDER *EVP_CIPHER_get0_provider(const EVP_CIPHER *cipher); int EVP_CIPHER_get_block_size(const EVP_CIPHER *cipher); # define EVP_CIPHER_block_size EVP_CIPHER_get_block_size # ifndef OPENSSL_NO_DEPRECATED_3_0 OSSL_DEPRECATEDIN_3_0 int EVP_CIPHER_impl_ctx_size(const EVP_CIPHER *cipher); # endif int EVP_CIPHER_get_key_length(const EVP_CIPHER *cipher); # define EVP_CIPHER_key_length EVP_CIPHER_get_key_length int EVP_CIPHER_get_iv_length(const EVP_CIPHER *cipher); # define EVP_CIPHER_iv_length EVP_CIPHER_get_iv_length unsigned long EVP_CIPHER_get_flags(const EVP_CIPHER *cipher); # define EVP_CIPHER_flags EVP_CIPHER_get_flags int EVP_CIPHER_get_mode(const EVP_CIPHER *cipher); # define EVP_CIPHER_mode EVP_CIPHER_get_mode int EVP_CIPHER_get_type(const EVP_CIPHER *cipher); # define EVP_CIPHER_type EVP_CIPHER_get_type EVP_CIPHER *EVP_CIPHER_fetch(OSSL_LIB_CTX *ctx, const char *algorithm, const char *properties); int EVP_CIPHER_up_ref(EVP_CIPHER *cipher); void EVP_CIPHER_free(EVP_CIPHER *cipher); const EVP_CIPHER *EVP_CIPHER_CTX_get0_cipher(const EVP_CIPHER_CTX *ctx); EVP_CIPHER *EVP_CIPHER_CTX_get1_cipher(EVP_CIPHER_CTX *ctx); int EVP_CIPHER_CTX_is_encrypting(const EVP_CIPHER_CTX *ctx); # define EVP_CIPHER_CTX_encrypting EVP_CIPHER_CTX_is_encrypting int EVP_CIPHER_CTX_get_nid(const EVP_CIPHER_CTX *ctx); # define EVP_CIPHER_CTX_nid EVP_CIPHER_CTX_get_nid int EVP_CIPHER_CTX_get_block_size(const EVP_CIPHER_CTX *ctx); # define EVP_CIPHER_CTX_block_size EVP_CIPHER_CTX_get_block_size int EVP_CIPHER_CTX_get_key_length(const EVP_CIPHER_CTX *ctx); # define EVP_CIPHER_CTX_key_length EVP_CIPHER_CTX_get_key_length int EVP_CIPHER_CTX_get_iv_length(const EVP_CIPHER_CTX *ctx); # define EVP_CIPHER_CTX_iv_length EVP_CIPHER_CTX_get_iv_length int EVP_CIPHER_CTX_get_tag_length(const EVP_CIPHER_CTX *ctx); # define EVP_CIPHER_CTX_tag_length EVP_CIPHER_CTX_get_tag_length # ifndef OPENSSL_NO_DEPRECATED_3_0 const EVP_CIPHER *EVP_CIPHER_CTX_cipher(const EVP_CIPHER_CTX *ctx); OSSL_DEPRECATEDIN_3_0 const unsigned char *EVP_CIPHER_CTX_iv(const EVP_CIPHER_CTX *ctx); OSSL_DEPRECATEDIN_3_0 const unsigned char *EVP_CIPHER_CTX_original_iv(const EVP_CIPHER_CTX *ctx); OSSL_DEPRECATEDIN_3_0 unsigned char *EVP_CIPHER_CTX_iv_noconst(EVP_CIPHER_CTX *ctx); # endif int EVP_CIPHER_CTX_get_updated_iv(EVP_CIPHER_CTX *ctx, void *buf, size_t len); int EVP_CIPHER_CTX_get_original_iv(EVP_CIPHER_CTX *ctx, void *buf, size_t len); # ifndef OPENSSL_NO_DEPRECATED_3_0 OSSL_DEPRECATEDIN_3_0 unsigned char *EVP_CIPHER_CTX_buf_noconst(EVP_CIPHER_CTX *ctx); # endif int EVP_CIPHER_CTX_get_num(const EVP_CIPHER_CTX *ctx); # define EVP_CIPHER_CTX_num EVP_CIPHER_CTX_get_num int EVP_CIPHER_CTX_set_num(EVP_CIPHER_CTX *ctx, int num); int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in); void *EVP_CIPHER_CTX_get_app_data(const EVP_CIPHER_CTX *ctx); void EVP_CIPHER_CTX_set_app_data(EVP_CIPHER_CTX *ctx, void *data); void *EVP_CIPHER_CTX_get_cipher_data(const EVP_CIPHER_CTX *ctx); void *EVP_CIPHER_CTX_set_cipher_data(EVP_CIPHER_CTX *ctx, void *cipher_data); # define EVP_CIPHER_CTX_get0_name(c) EVP_CIPHER_get0_name(EVP_CIPHER_CTX_get0_cipher(c)) # define EVP_CIPHER_CTX_get_type(c) EVP_CIPHER_get_type(EVP_CIPHER_CTX_get0_cipher(c)) # define EVP_CIPHER_CTX_type EVP_CIPHER_CTX_get_type # ifndef OPENSSL_NO_DEPRECATED_1_1_0 # define EVP_CIPHER_CTX_flags(c) EVP_CIPHER_get_flags(EVP_CIPHER_CTX_get0_cipher(c)) # endif # define EVP_CIPHER_CTX_get_mode(c) EVP_CIPHER_get_mode(EVP_CIPHER_CTX_get0_cipher(c)) # define EVP_CIPHER_CTX_mode EVP_CIPHER_CTX_get_mode # define EVP_ENCODE_LENGTH(l) ((((l)+2)/3*4)+((l)/48+1)*2+80) # define EVP_DECODE_LENGTH(l) (((l)+3)/4*3+80) # define EVP_SignInit_ex(a,b,c) EVP_DigestInit_ex(a,b,c) # define EVP_SignInit(a,b) EVP_DigestInit(a,b) # define EVP_SignUpdate(a,b,c) EVP_DigestUpdate(a,b,c) # define EVP_VerifyInit_ex(a,b,c) EVP_DigestInit_ex(a,b,c) # define EVP_VerifyInit(a,b) EVP_DigestInit(a,b) # define EVP_VerifyUpdate(a,b,c) EVP_DigestUpdate(a,b,c) # define EVP_OpenUpdate(a,b,c,d,e) EVP_DecryptUpdate(a,b,c,d,e) # define EVP_SealUpdate(a,b,c,d,e) EVP_EncryptUpdate(a,b,c,d,e) # ifdef CONST_STRICT void BIO_set_md(BIO *, const EVP_MD *md); # else # define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,0,(void *)(md)) # endif # define BIO_get_md(b,mdp) BIO_ctrl(b,BIO_C_GET_MD,0,(mdp)) # define BIO_get_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_GET_MD_CTX,0,(mdcp)) # define BIO_set_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_SET_MD_CTX,0,(mdcp)) # define BIO_get_cipher_status(b) BIO_ctrl(b,BIO_C_GET_CIPHER_STATUS,0,NULL) # define BIO_get_cipher_ctx(b,c_pp) BIO_ctrl(b,BIO_C_GET_CIPHER_CTX,0,(c_pp)) /*__owur*/ int EVP_Cipher(EVP_CIPHER_CTX *c, unsigned char *out, const unsigned char *in, unsigned int inl); # define EVP_add_cipher_alias(n,alias) \ OBJ_NAME_add((alias),OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS,(n)) # define EVP_add_digest_alias(n,alias) \ OBJ_NAME_add((alias),OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,(n)) # define EVP_delete_cipher_alias(alias) \ OBJ_NAME_remove(alias,OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS); # define EVP_delete_digest_alias(alias) \ OBJ_NAME_remove(alias,OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS); int EVP_MD_get_params(const EVP_MD *digest, OSSL_PARAM params[]); int EVP_MD_CTX_set_params(EVP_MD_CTX *ctx, const OSSL_PARAM params[]); int EVP_MD_CTX_get_params(EVP_MD_CTX *ctx, OSSL_PARAM params[]); const OSSL_PARAM *EVP_MD_gettable_params(const EVP_MD *digest); const OSSL_PARAM *EVP_MD_settable_ctx_params(const EVP_MD *md); const OSSL_PARAM *EVP_MD_gettable_ctx_params(const EVP_MD *md); const OSSL_PARAM *EVP_MD_CTX_settable_params(EVP_MD_CTX *ctx); const OSSL_PARAM *EVP_MD_CTX_gettable_params(EVP_MD_CTX *ctx); int EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void *p2); EVP_MD_CTX *EVP_MD_CTX_new(void); int EVP_MD_CTX_reset(EVP_MD_CTX *ctx); void EVP_MD_CTX_free(EVP_MD_CTX *ctx); # define EVP_MD_CTX_create() EVP_MD_CTX_new() # define EVP_MD_CTX_init(ctx) EVP_MD_CTX_reset((ctx)) # define EVP_MD_CTX_destroy(ctx) EVP_MD_CTX_free((ctx)) __owur int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in); void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags); void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags); int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags); __owur int EVP_DigestInit_ex2(EVP_MD_CTX *ctx, const EVP_MD *type, const OSSL_PARAM params[]); __owur int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl); __owur int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt); __owur int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s); __owur int EVP_Digest(const void *data, size_t count, unsigned char *md, unsigned int *size, const EVP_MD *type, ENGINE *impl); __owur int EVP_Q_digest(OSSL_LIB_CTX *libctx, const char *name, const char *propq, const void *data, size_t datalen, unsigned char *md, size_t *mdlen); __owur int EVP_MD_CTX_copy(EVP_MD_CTX *out, const EVP_MD_CTX *in); __owur int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type); __owur int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s); __owur int EVP_DigestFinalXOF(EVP_MD_CTX *ctx, unsigned char *md, size_t len); __owur EVP_MD *EVP_MD_fetch(OSSL_LIB_CTX *ctx, const char *algorithm, const char *properties); int EVP_MD_up_ref(EVP_MD *md); void EVP_MD_free(EVP_MD *md); int EVP_read_pw_string(char *buf, int length, const char *prompt, int verify); int EVP_read_pw_string_min(char *buf, int minlen, int maxlen, const char *prompt, int verify); void EVP_set_pw_prompt(const char *prompt); char *EVP_get_pw_prompt(void); __owur int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md, const unsigned char *salt, const unsigned char *data, int datal, int count, unsigned char *key, unsigned char *iv); void EVP_CIPHER_CTX_set_flags(EVP_CIPHER_CTX *ctx, int flags); void EVP_CIPHER_CTX_clear_flags(EVP_CIPHER_CTX *ctx, int flags); int EVP_CIPHER_CTX_test_flags(const EVP_CIPHER_CTX *ctx, int flags); __owur int EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, const unsigned char *key, const unsigned char *iv); /*__owur*/ int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, const unsigned char *key, const unsigned char *iv); __owur int EVP_EncryptInit_ex2(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, const unsigned char *key, const unsigned char *iv, const OSSL_PARAM params[]); /*__owur*/ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, const unsigned char *in, int inl); /*__owur*/ int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); /*__owur*/ int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); __owur int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, const unsigned char *key, const unsigned char *iv); /*__owur*/ int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, const unsigned char *key, const unsigned char *iv); __owur int EVP_DecryptInit_ex2(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, const unsigned char *key, const unsigned char *iv, const OSSL_PARAM params[]); /*__owur*/ int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, const unsigned char *in, int inl); __owur int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); /*__owur*/ int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); __owur int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, const unsigned char *key, const unsigned char *iv, int enc); /*__owur*/ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, const unsigned char *key, const unsigned char *iv, int enc); __owur int EVP_CipherInit_ex2(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, const unsigned char *key, const unsigned char *iv, int enc, const OSSL_PARAM params[]); __owur int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, const unsigned char *in, int inl); __owur int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); __owur int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); __owur int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s, EVP_PKEY *pkey); __owur int EVP_SignFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s, EVP_PKEY *pkey, OSSL_LIB_CTX *libctx, const char *propq); __owur int EVP_DigestSign(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen, const unsigned char *tbs, size_t tbslen); __owur int EVP_VerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sigbuf, unsigned int siglen, EVP_PKEY *pkey); __owur int EVP_VerifyFinal_ex(EVP_MD_CTX *ctx, const unsigned char *sigbuf, unsigned int siglen, EVP_PKEY *pkey, OSSL_LIB_CTX *libctx, const char *propq); __owur int EVP_DigestVerify(EVP_MD_CTX *ctx, const unsigned char *sigret, size_t siglen, const unsigned char *tbs, size_t tbslen); int EVP_DigestSignInit_ex(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const char *mdname, OSSL_LIB_CTX *libctx, const char *props, EVP_PKEY *pkey, const OSSL_PARAM params[]); /*__owur*/ int EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey); int EVP_DigestSignUpdate(EVP_MD_CTX *ctx, const void *data, size_t dsize); __owur int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen); int EVP_DigestVerifyInit_ex(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const char *mdname, OSSL_LIB_CTX *libctx, const char *props, EVP_PKEY *pkey, const OSSL_PARAM params[]); __owur int EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey); int EVP_DigestVerifyUpdate(EVP_MD_CTX *ctx, const void *data, size_t dsize); __owur int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig, size_t siglen); __owur int EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, const unsigned char *ek, int ekl, const unsigned char *iv, EVP_PKEY *priv); __owur int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); __owur int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, unsigned char **ek, int *ekl, unsigned char *iv, EVP_PKEY **pubk, int npubk); __owur int EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); EVP_ENCODE_CTX *EVP_ENCODE_CTX_new(void); void EVP_ENCODE_CTX_free(EVP_ENCODE_CTX *ctx); int EVP_ENCODE_CTX_copy(EVP_ENCODE_CTX *dctx, const EVP_ENCODE_CTX *sctx); int EVP_ENCODE_CTX_num(EVP_ENCODE_CTX *ctx); void EVP_EncodeInit(EVP_ENCODE_CTX *ctx); int EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, const unsigned char *in, int inl); void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl); int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int n); void EVP_DecodeInit(EVP_ENCODE_CTX *ctx); int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, const unsigned char *in, int inl); int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl); int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n); # ifndef OPENSSL_NO_DEPRECATED_1_1_0 # define EVP_CIPHER_CTX_init(c) EVP_CIPHER_CTX_reset(c) # define EVP_CIPHER_CTX_cleanup(c) EVP_CIPHER_CTX_reset(c) # endif EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void); int EVP_CIPHER_CTX_reset(EVP_CIPHER_CTX *c); void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *c); int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *x, int keylen); int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *c, int pad); int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr); int EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key); int EVP_CIPHER_get_params(EVP_CIPHER *cipher, OSSL_PARAM params[]); int EVP_CIPHER_CTX_set_params(EVP_CIPHER_CTX *ctx, const OSSL_PARAM params[]); int EVP_CIPHER_CTX_get_params(EVP_CIPHER_CTX *ctx, OSSL_PARAM params[]); const OSSL_PARAM *EVP_CIPHER_gettable_params(const EVP_CIPHER *cipher); const OSSL_PARAM *EVP_CIPHER_settable_ctx_params(const EVP_CIPHER *cipher); const OSSL_PARAM *EVP_CIPHER_gettable_ctx_params(const EVP_CIPHER *cipher); const OSSL_PARAM *EVP_CIPHER_CTX_settable_params(EVP_CIPHER_CTX *ctx); const OSSL_PARAM *EVP_CIPHER_CTX_gettable_params(EVP_CIPHER_CTX *ctx); const BIO_METHOD *BIO_f_md(void); const BIO_METHOD *BIO_f_base64(void); const BIO_METHOD *BIO_f_cipher(void); const BIO_METHOD *BIO_f_reliable(void); __owur int BIO_set_cipher(BIO *b, const EVP_CIPHER *c, const unsigned char *k, const unsigned char *i, int enc); const EVP_MD *EVP_md_null(void); # ifndef OPENSSL_NO_MD2 const EVP_MD *EVP_md2(void); # endif # ifndef OPENSSL_NO_MD4 const EVP_MD *EVP_md4(void); # endif # ifndef OPENSSL_NO_MD5 const EVP_MD *EVP_md5(void); const EVP_MD *EVP_md5_sha1(void); # endif # ifndef OPENSSL_NO_BLAKE2 const EVP_MD *EVP_blake2b512(void); const EVP_MD *EVP_blake2s256(void); # endif const EVP_MD *EVP_sha1(void); const EVP_MD *EVP_sha224(void); const EVP_MD *EVP_sha256(void); const EVP_MD *EVP_sha384(void); const EVP_MD *EVP_sha512(void); const EVP_MD *EVP_sha512_224(void); const EVP_MD *EVP_sha512_256(void); const EVP_MD *EVP_sha3_224(void); const EVP_MD *EVP_sha3_256(void); const EVP_MD *EVP_sha3_384(void); const EVP_MD *EVP_sha3_512(void); const EVP_MD *EVP_shake128(void); const EVP_MD *EVP_shake256(void); # ifndef OPENSSL_NO_MDC2 const EVP_MD *EVP_mdc2(void); # endif # ifndef OPENSSL_NO_RMD160 const EVP_MD *EVP_ripemd160(void); # endif # ifndef OPENSSL_NO_WHIRLPOOL const EVP_MD *EVP_whirlpool(void); # endif # ifndef OPENSSL_NO_SM3 const EVP_MD *EVP_sm3(void); # endif const EVP_CIPHER *EVP_enc_null(void); /* does nothing :-) */ # ifndef OPENSSL_NO_DES const EVP_CIPHER *EVP_des_ecb(void); const EVP_CIPHER *EVP_des_ede(void); const EVP_CIPHER *EVP_des_ede3(void); const EVP_CIPHER *EVP_des_ede_ecb(void); const EVP_CIPHER *EVP_des_ede3_ecb(void); const EVP_CIPHER *EVP_des_cfb64(void); # define EVP_des_cfb EVP_des_cfb64 const EVP_CIPHER *EVP_des_cfb1(void); const EVP_CIPHER *EVP_des_cfb8(void); const EVP_CIPHER *EVP_des_ede_cfb64(void); # define EVP_des_ede_cfb EVP_des_ede_cfb64 const EVP_CIPHER *EVP_des_ede3_cfb64(void); # define EVP_des_ede3_cfb EVP_des_ede3_cfb64 const EVP_CIPHER *EVP_des_ede3_cfb1(void); const EVP_CIPHER *EVP_des_ede3_cfb8(void); const EVP_CIPHER *EVP_des_ofb(void); const EVP_CIPHER *EVP_des_ede_ofb(void); const EVP_CIPHER *EVP_des_ede3_ofb(void); const EVP_CIPHER *EVP_des_cbc(void); const EVP_CIPHER *EVP_des_ede_cbc(void); const EVP_CIPHER *EVP_des_ede3_cbc(void); const EVP_CIPHER *EVP_desx_cbc(void); const EVP_CIPHER *EVP_des_ede3_wrap(void); /* * This should now be supported through the dev_crypto ENGINE. But also, why * are rc4 and md5 declarations made here inside a "NO_DES" precompiler * branch? */ # endif # ifndef OPENSSL_NO_RC4 const EVP_CIPHER *EVP_rc4(void); const EVP_CIPHER *EVP_rc4_40(void); # ifndef OPENSSL_NO_MD5 const EVP_CIPHER *EVP_rc4_hmac_md5(void); # endif # endif # ifndef OPENSSL_NO_IDEA const EVP_CIPHER *EVP_idea_ecb(void); const EVP_CIPHER *EVP_idea_cfb64(void); # define EVP_idea_cfb EVP_idea_cfb64 const EVP_CIPHER *EVP_idea_ofb(void); const EVP_CIPHER *EVP_idea_cbc(void); # endif # ifndef OPENSSL_NO_RC2 const EVP_CIPHER *EVP_rc2_ecb(void); const EVP_CIPHER *EVP_rc2_cbc(void); const EVP_CIPHER *EVP_rc2_40_cbc(void); const EVP_CIPHER *EVP_rc2_64_cbc(void); const EVP_CIPHER *EVP_rc2_cfb64(void); # define EVP_rc2_cfb EVP_rc2_cfb64 const EVP_CIPHER *EVP_rc2_ofb(void); # endif # ifndef OPENSSL_NO_BF const EVP_CIPHER *EVP_bf_ecb(void); const EVP_CIPHER *EVP_bf_cbc(void); const EVP_CIPHER *EVP_bf_cfb64(void); # define EVP_bf_cfb EVP_bf_cfb64 const EVP_CIPHER *EVP_bf_ofb(void); # endif # ifndef OPENSSL_NO_CAST const EVP_CIPHER *EVP_cast5_ecb(void); const EVP_CIPHER *EVP_cast5_cbc(void); const EVP_CIPHER *EVP_cast5_cfb64(void); # define EVP_cast5_cfb EVP_cast5_cfb64 const EVP_CIPHER *EVP_cast5_ofb(void); # endif # ifndef OPENSSL_NO_RC5 const EVP_CIPHER *EVP_rc5_32_12_16_cbc(void); const EVP_CIPHER *EVP_rc5_32_12_16_ecb(void); const EVP_CIPHER *EVP_rc5_32_12_16_cfb64(void); # define EVP_rc5_32_12_16_cfb EVP_rc5_32_12_16_cfb64 const EVP_CIPHER *EVP_rc5_32_12_16_ofb(void); # endif const EVP_CIPHER *EVP_aes_128_ecb(void); const EVP_CIPHER *EVP_aes_128_cbc(void); const EVP_CIPHER *EVP_aes_128_cfb1(void); const EVP_CIPHER *EVP_aes_128_cfb8(void); const EVP_CIPHER *EVP_aes_128_cfb128(void); # define EVP_aes_128_cfb EVP_aes_128_cfb128 const EVP_CIPHER *EVP_aes_128_ofb(void); const EVP_CIPHER *EVP_aes_128_ctr(void); const EVP_CIPHER *EVP_aes_128_ccm(void); const EVP_CIPHER *EVP_aes_128_gcm(void); const EVP_CIPHER *EVP_aes_128_xts(void); const EVP_CIPHER *EVP_aes_128_wrap(void); const EVP_CIPHER *EVP_aes_128_wrap_pad(void); # ifndef OPENSSL_NO_OCB const EVP_CIPHER *EVP_aes_128_ocb(void); # endif const EVP_CIPHER *EVP_aes_192_ecb(void); const EVP_CIPHER *EVP_aes_192_cbc(void); const EVP_CIPHER *EVP_aes_192_cfb1(void); const EVP_CIPHER *EVP_aes_192_cfb8(void); const EVP_CIPHER *EVP_aes_192_cfb128(void); # define EVP_aes_192_cfb EVP_aes_192_cfb128 const EVP_CIPHER *EVP_aes_192_ofb(void); const EVP_CIPHER *EVP_aes_192_ctr(void); const EVP_CIPHER *EVP_aes_192_ccm(void); const EVP_CIPHER *EVP_aes_192_gcm(void); const EVP_CIPHER *EVP_aes_192_wrap(void); const EVP_CIPHER *EVP_aes_192_wrap_pad(void); # ifndef OPENSSL_NO_OCB const EVP_CIPHER *EVP_aes_192_ocb(void); # endif const EVP_CIPHER *EVP_aes_256_ecb(void); const EVP_CIPHER *EVP_aes_256_cbc(void); const EVP_CIPHER *EVP_aes_256_cfb1(void); const EVP_CIPHER *EVP_aes_256_cfb8(void); const EVP_CIPHER *EVP_aes_256_cfb128(void); # define EVP_aes_256_cfb EVP_aes_256_cfb128 const EVP_CIPHER *EVP_aes_256_ofb(void); const EVP_CIPHER *EVP_aes_256_ctr(void); const EVP_CIPHER *EVP_aes_256_ccm(void); const EVP_CIPHER *EVP_aes_256_gcm(void); const EVP_CIPHER *EVP_aes_256_xts(void); const EVP_CIPHER *EVP_aes_256_wrap(void); const EVP_CIPHER *EVP_aes_256_wrap_pad(void); # ifndef OPENSSL_NO_OCB const EVP_CIPHER *EVP_aes_256_ocb(void); # endif const EVP_CIPHER *EVP_aes_128_cbc_hmac_sha1(void); const EVP_CIPHER *EVP_aes_256_cbc_hmac_sha1(void); const EVP_CIPHER *EVP_aes_128_cbc_hmac_sha256(void); const EVP_CIPHER *EVP_aes_256_cbc_hmac_sha256(void); # ifndef OPENSSL_NO_ARIA const EVP_CIPHER *EVP_aria_128_ecb(void); const EVP_CIPHER *EVP_aria_128_cbc(void); const EVP_CIPHER *EVP_aria_128_cfb1(void); const EVP_CIPHER *EVP_aria_128_cfb8(void); const EVP_CIPHER *EVP_aria_128_cfb128(void); # define EVP_aria_128_cfb EVP_aria_128_cfb128 const EVP_CIPHER *EVP_aria_128_ctr(void); const EVP_CIPHER *EVP_aria_128_ofb(void); const EVP_CIPHER *EVP_aria_128_gcm(void); const EVP_CIPHER *EVP_aria_128_ccm(void); const EVP_CIPHER *EVP_aria_192_ecb(void); const EVP_CIPHER *EVP_aria_192_cbc(void); const EVP_CIPHER *EVP_aria_192_cfb1(void); const EVP_CIPHER *EVP_aria_192_cfb8(void); const EVP_CIPHER *EVP_aria_192_cfb128(void); # define EVP_aria_192_cfb EVP_aria_192_cfb128 const EVP_CIPHER *EVP_aria_192_ctr(void); const EVP_CIPHER *EVP_aria_192_ofb(void); const EVP_CIPHER *EVP_aria_192_gcm(void); const EVP_CIPHER *EVP_aria_192_ccm(void); const EVP_CIPHER *EVP_aria_256_ecb(void); const EVP_CIPHER *EVP_aria_256_cbc(void); const EVP_CIPHER *EVP_aria_256_cfb1(void); const EVP_CIPHER *EVP_aria_256_cfb8(void); const EVP_CIPHER *EVP_aria_256_cfb128(void); # define EVP_aria_256_cfb EVP_aria_256_cfb128 const EVP_CIPHER *EVP_aria_256_ctr(void); const EVP_CIPHER *EVP_aria_256_ofb(void); const EVP_CIPHER *EVP_aria_256_gcm(void); const EVP_CIPHER *EVP_aria_256_ccm(void); # endif # ifndef OPENSSL_NO_CAMELLIA const EVP_CIPHER *EVP_camellia_128_ecb(void); const EVP_CIPHER *EVP_camellia_128_cbc(void); const EVP_CIPHER *EVP_camellia_128_cfb1(void); const EVP_CIPHER *EVP_camellia_128_cfb8(void); const EVP_CIPHER *EVP_camellia_128_cfb128(void); # define EVP_camellia_128_cfb EVP_camellia_128_cfb128 const EVP_CIPHER *EVP_camellia_128_ofb(void); const EVP_CIPHER *EVP_camellia_128_ctr(void); const EVP_CIPHER *EVP_camellia_192_ecb(void); const EVP_CIPHER *EVP_camellia_192_cbc(void); const EVP_CIPHER *EVP_camellia_192_cfb1(void); const EVP_CIPHER *EVP_camellia_192_cfb8(void); const EVP_CIPHER *EVP_camellia_192_cfb128(void); # define EVP_camellia_192_cfb EVP_camellia_192_cfb128 const EVP_CIPHER *EVP_camellia_192_ofb(void); const EVP_CIPHER *EVP_camellia_192_ctr(void); const EVP_CIPHER *EVP_camellia_256_ecb(void); const EVP_CIPHER *EVP_camellia_256_cbc(void); const EVP_CIPHER *EVP_camellia_256_cfb1(void); const EVP_CIPHER *EVP_camellia_256_cfb8(void); const EVP_CIPHER *EVP_camellia_256_cfb128(void); # define EVP_camellia_256_cfb EVP_camellia_256_cfb128 const EVP_CIPHER *EVP_camellia_256_ofb(void); const EVP_CIPHER *EVP_camellia_256_ctr(void); # endif # ifndef OPENSSL_NO_CHACHA const EVP_CIPHER *EVP_chacha20(void); # ifndef OPENSSL_NO_POLY1305 const EVP_CIPHER *EVP_chacha20_poly1305(void); # endif # endif # ifndef OPENSSL_NO_SEED const EVP_CIPHER *EVP_seed_ecb(void); const EVP_CIPHER *EVP_seed_cbc(void); const EVP_CIPHER *EVP_seed_cfb128(void); # define EVP_seed_cfb EVP_seed_cfb128 const EVP_CIPHER *EVP_seed_ofb(void); # endif # ifndef OPENSSL_NO_SM4 const EVP_CIPHER *EVP_sm4_ecb(void); const EVP_CIPHER *EVP_sm4_cbc(void); const EVP_CIPHER *EVP_sm4_cfb128(void); # define EVP_sm4_cfb EVP_sm4_cfb128 const EVP_CIPHER *EVP_sm4_ofb(void); const EVP_CIPHER *EVP_sm4_ctr(void); # endif # ifndef OPENSSL_NO_DEPRECATED_1_1_0 # define OPENSSL_add_all_algorithms_conf() \ OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS \ | OPENSSL_INIT_ADD_ALL_DIGESTS \ | OPENSSL_INIT_LOAD_CONFIG, NULL) # define OPENSSL_add_all_algorithms_noconf() \ OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS \ | OPENSSL_INIT_ADD_ALL_DIGESTS, NULL) # ifdef OPENSSL_LOAD_CONF # define OpenSSL_add_all_algorithms() OPENSSL_add_all_algorithms_conf() # else # define OpenSSL_add_all_algorithms() OPENSSL_add_all_algorithms_noconf() # endif # define OpenSSL_add_all_ciphers() \ OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS, NULL) # define OpenSSL_add_all_digests() \ OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_DIGESTS, NULL) # define EVP_cleanup() while(0) continue # endif int EVP_add_cipher(const EVP_CIPHER *cipher); int EVP_add_digest(const EVP_MD *digest); const EVP_CIPHER *EVP_get_cipherbyname(const char *name); const EVP_MD *EVP_get_digestbyname(const char *name); void EVP_CIPHER_do_all(void (*fn) (const EVP_CIPHER *ciph, const char *from, const char *to, void *x), void *arg); void EVP_CIPHER_do_all_sorted(void (*fn) (const EVP_CIPHER *ciph, const char *from, const char *to, void *x), void *arg); void EVP_CIPHER_do_all_provided(OSSL_LIB_CTX *libctx, void (*fn)(EVP_CIPHER *cipher, void *arg), void *arg); void EVP_MD_do_all(void (*fn) (const EVP_MD *ciph, const char *from, const char *to, void *x), void *arg); void EVP_MD_do_all_sorted(void (*fn) (const EVP_MD *ciph, const char *from, const char *to, void *x), void *arg); void EVP_MD_do_all_provided(OSSL_LIB_CTX *libctx, void (*fn)(EVP_MD *md, void *arg), void *arg); /* MAC stuff */ EVP_MAC *EVP_MAC_fetch(OSSL_LIB_CTX *libctx, const char *algorithm, const char *properties); int EVP_MAC_up_ref(EVP_MAC *mac); void EVP_MAC_free(EVP_MAC *mac); const char *EVP_MAC_get0_name(const EVP_MAC *mac); const char *EVP_MAC_get0_description(const EVP_MAC *mac); int EVP_MAC_is_a(const EVP_MAC *mac, const char *name); const OSSL_PROVIDER *EVP_MAC_get0_provider(const EVP_MAC *mac); int EVP_MAC_get_params(EVP_MAC *mac, OSSL_PARAM params[]); EVP_MAC_CTX *EVP_MAC_CTX_new(EVP_MAC *mac); void EVP_MAC_CTX_free(EVP_MAC_CTX *ctx); EVP_MAC_CTX *EVP_MAC_CTX_dup(const EVP_MAC_CTX *src); EVP_MAC *EVP_MAC_CTX_get0_mac(EVP_MAC_CTX *ctx); int EVP_MAC_CTX_get_params(EVP_MAC_CTX *ctx, OSSL_PARAM params[]); int EVP_MAC_CTX_set_params(EVP_MAC_CTX *ctx, const OSSL_PARAM params[]); size_t EVP_MAC_CTX_get_mac_size(EVP_MAC_CTX *ctx); size_t EVP_MAC_CTX_get_block_size(EVP_MAC_CTX *ctx); unsigned char *EVP_Q_mac(OSSL_LIB_CTX *libctx, const char *name, const char *propq, const char *subalg, const OSSL_PARAM *params, const void *key, size_t keylen, const unsigned char *data, size_t datalen, unsigned char *out, size_t outsize, size_t *outlen); int EVP_MAC_init(EVP_MAC_CTX *ctx, const unsigned char *key, size_t keylen, const OSSL_PARAM params[]); int EVP_MAC_update(EVP_MAC_CTX *ctx, const unsigned char *data, size_t datalen); int EVP_MAC_final(EVP_MAC_CTX *ctx, unsigned char *out, size_t *outl, size_t outsize); int EVP_MAC_finalXOF(EVP_MAC_CTX *ctx, unsigned char *out, size_t outsize); const OSSL_PARAM *EVP_MAC_gettable_params(const EVP_MAC *mac); const OSSL_PARAM *EVP_MAC_gettable_ctx_params(const EVP_MAC *mac); const OSSL_PARAM *EVP_MAC_settable_ctx_params(const EVP_MAC *mac); const OSSL_PARAM *EVP_MAC_CTX_gettable_params(EVP_MAC_CTX *ctx); const OSSL_PARAM *EVP_MAC_CTX_settable_params(EVP_MAC_CTX *ctx); void EVP_MAC_do_all_provided(OSSL_LIB_CTX *libctx, void (*fn)(EVP_MAC *mac, void *arg), void *arg); int EVP_MAC_names_do_all(const EVP_MAC *mac, void (*fn)(const char *name, void *data), void *data); /* RAND stuff */ EVP_RAND *EVP_RAND_fetch(OSSL_LIB_CTX *libctx, const char *algorithm, const char *properties); int EVP_RAND_up_ref(EVP_RAND *rand); void EVP_RAND_free(EVP_RAND *rand); const char *EVP_RAND_get0_name(const EVP_RAND *rand); const char *EVP_RAND_get0_description(const EVP_RAND *md); int EVP_RAND_is_a(const EVP_RAND *rand, const char *name); const OSSL_PROVIDER *EVP_RAND_get0_provider(const EVP_RAND *rand); int EVP_RAND_get_params(EVP_RAND *rand, OSSL_PARAM params[]); EVP_RAND_CTX *EVP_RAND_CTX_new(EVP_RAND *rand, EVP_RAND_CTX *parent); void EVP_RAND_CTX_free(EVP_RAND_CTX *ctx); EVP_RAND *EVP_RAND_CTX_get0_rand(EVP_RAND_CTX *ctx); int EVP_RAND_CTX_get_params(EVP_RAND_CTX *ctx, OSSL_PARAM params[]); int EVP_RAND_CTX_set_params(EVP_RAND_CTX *ctx, const OSSL_PARAM params[]); const OSSL_PARAM *EVP_RAND_gettable_params(const EVP_RAND *rand); const OSSL_PARAM *EVP_RAND_gettable_ctx_params(const EVP_RAND *rand); const OSSL_PARAM *EVP_RAND_settable_ctx_params(const EVP_RAND *rand); const OSSL_PARAM *EVP_RAND_CTX_gettable_params(EVP_RAND_CTX *ctx); const OSSL_PARAM *EVP_RAND_CTX_settable_params(EVP_RAND_CTX *ctx); void EVP_RAND_do_all_provided(OSSL_LIB_CTX *libctx, void (*fn)(EVP_RAND *rand, void *arg), void *arg); int EVP_RAND_names_do_all(const EVP_RAND *rand, void (*fn)(const char *name, void *data), void *data); __owur int EVP_RAND_instantiate(EVP_RAND_CTX *ctx, unsigned int strength, int prediction_resistance, const unsigned char *pstr, size_t pstr_len, const OSSL_PARAM params[]); int EVP_RAND_uninstantiate(EVP_RAND_CTX *ctx); __owur int EVP_RAND_generate(EVP_RAND_CTX *ctx, unsigned char *out, size_t outlen, unsigned int strength, int prediction_resistance, const unsigned char *addin, size_t addin_len); int EVP_RAND_reseed(EVP_RAND_CTX *ctx, int prediction_resistance, const unsigned char *ent, size_t ent_len, const unsigned char *addin, size_t addin_len); __owur int EVP_RAND_nonce(EVP_RAND_CTX *ctx, unsigned char *out, size_t outlen); __owur int EVP_RAND_enable_locking(EVP_RAND_CTX *ctx); int EVP_RAND_verify_zeroization(EVP_RAND_CTX *ctx); unsigned int EVP_RAND_get_strength(EVP_RAND_CTX *ctx); int EVP_RAND_get_state(EVP_RAND_CTX *ctx); # define EVP_RAND_STATE_UNINITIALISED 0 # define EVP_RAND_STATE_READY 1 # define EVP_RAND_STATE_ERROR 2 /* PKEY stuff */ # ifndef OPENSSL_NO_DEPRECATED_3_0 OSSL_DEPRECATEDIN_3_0 int EVP_PKEY_decrypt_old(unsigned char *dec_key, const unsigned char *enc_key, int enc_key_len, EVP_PKEY *private_key); OSSL_DEPRECATEDIN_3_0 int EVP_PKEY_encrypt_old(unsigned char *enc_key, const unsigned char *key, int key_len, EVP_PKEY *pub_key); # endif int EVP_PKEY_is_a(const EVP_PKEY *pkey, const char *name); int EVP_PKEY_type_names_do_all(const EVP_PKEY *pkey, void (*fn)(const char *name, void *data), void *data); int EVP_PKEY_type(int type); int EVP_PKEY_get_id(const EVP_PKEY *pkey); # define EVP_PKEY_id EVP_PKEY_get_id int EVP_PKEY_get_base_id(const EVP_PKEY *pkey); # define EVP_PKEY_base_id EVP_PKEY_get_base_id int EVP_PKEY_get_bits(const EVP_PKEY *pkey); # define EVP_PKEY_bits EVP_PKEY_get_bits int EVP_PKEY_get_security_bits(const EVP_PKEY *pkey); # define EVP_PKEY_security_bits EVP_PKEY_get_security_bits int EVP_PKEY_get_size(const EVP_PKEY *pkey); # define EVP_PKEY_size EVP_PKEY_get_size int EVP_PKEY_can_sign(const EVP_PKEY *pkey); int EVP_PKEY_set_type(EVP_PKEY *pkey, int type); int EVP_PKEY_set_type_str(EVP_PKEY *pkey, const char *str, int len); int EVP_PKEY_set_type_by_keymgmt(EVP_PKEY *pkey, EVP_KEYMGMT *keymgmt); # ifndef OPENSSL_NO_DEPRECATED_3_0 # ifndef OPENSSL_NO_ENGINE OSSL_DEPRECATEDIN_3_0 int EVP_PKEY_set1_engine(EVP_PKEY *pkey, ENGINE *e); OSSL_DEPRECATEDIN_3_0 ENGINE *EVP_PKEY_get0_engine(const EVP_PKEY *pkey); # endif OSSL_DEPRECATEDIN_3_0 int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key); OSSL_DEPRECATEDIN_3_0 void *EVP_PKEY_get0(const EVP_PKEY *pkey); OSSL_DEPRECATEDIN_3_0 const unsigned char *EVP_PKEY_get0_hmac(const EVP_PKEY *pkey, size_t *len); # ifndef OPENSSL_NO_POLY1305 OSSL_DEPRECATEDIN_3_0 const unsigned char *EVP_PKEY_get0_poly1305(const EVP_PKEY *pkey, size_t *len); # endif # ifndef OPENSSL_NO_SIPHASH OSSL_DEPRECATEDIN_3_0 const unsigned char *EVP_PKEY_get0_siphash(const EVP_PKEY *pkey, size_t *len); # endif struct rsa_st; OSSL_DEPRECATEDIN_3_0 int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, struct rsa_st *key); OSSL_DEPRECATEDIN_3_0 const struct rsa_st *EVP_PKEY_get0_RSA(const EVP_PKEY *pkey); OSSL_DEPRECATEDIN_3_0 struct rsa_st *EVP_PKEY_get1_RSA(EVP_PKEY *pkey); # ifndef OPENSSL_NO_DSA struct dsa_st; OSSL_DEPRECATEDIN_3_0 int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, struct dsa_st *key); OSSL_DEPRECATEDIN_3_0 const struct dsa_st *EVP_PKEY_get0_DSA(const EVP_PKEY *pkey); OSSL_DEPRECATEDIN_3_0 struct dsa_st *EVP_PKEY_get1_DSA(EVP_PKEY *pkey); # endif # ifndef OPENSSL_NO_DH struct dh_st; OSSL_DEPRECATEDIN_3_0 int EVP_PKEY_set1_DH(EVP_PKEY *pkey, struct dh_st *key); OSSL_DEPRECATEDIN_3_0 const struct dh_st *EVP_PKEY_get0_DH(const EVP_PKEY *pkey); OSSL_DEPRECATEDIN_3_0 struct dh_st *EVP_PKEY_get1_DH(EVP_PKEY *pkey); # endif # ifndef OPENSSL_NO_EC struct ec_key_st; OSSL_DEPRECATEDIN_3_0 int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, struct ec_key_st *key); OSSL_DEPRECATEDIN_3_0 const struct ec_key_st *EVP_PKEY_get0_EC_KEY(const EVP_PKEY *pkey); OSSL_DEPRECATEDIN_3_0 struct ec_key_st *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey); # endif # endif /* OPENSSL_NO_DEPRECATED_3_0 */ EVP_PKEY *EVP_PKEY_new(void); int EVP_PKEY_up_ref(EVP_PKEY *pkey); EVP_PKEY *EVP_PKEY_dup(EVP_PKEY *pkey); void EVP_PKEY_free(EVP_PKEY *pkey); const char *EVP_PKEY_get0_description(const EVP_PKEY *pkey); const OSSL_PROVIDER *EVP_PKEY_get0_provider(const EVP_PKEY *key); EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, long length); int i2d_PublicKey(const EVP_PKEY *a, unsigned char **pp); EVP_PKEY *d2i_PrivateKey_ex(int type, EVP_PKEY **a, const unsigned char **pp, long length, OSSL_LIB_CTX *libctx, const char *propq); EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, long length); EVP_PKEY *d2i_AutoPrivateKey_ex(EVP_PKEY **a, const unsigned char **pp, long length, OSSL_LIB_CTX *libctx, const char *propq); EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp, long length); int i2d_PrivateKey(const EVP_PKEY *a, unsigned char **pp); int i2d_KeyParams(const EVP_PKEY *a, unsigned char **pp); EVP_PKEY *d2i_KeyParams(int type, EVP_PKEY **a, const unsigned char **pp, long length); int i2d_KeyParams_bio(BIO *bp, const EVP_PKEY *pkey); EVP_PKEY *d2i_KeyParams_bio(int type, EVP_PKEY **a, BIO *in); int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from); int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey); int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode); int EVP_PKEY_parameters_eq(const EVP_PKEY *a, const EVP_PKEY *b); int EVP_PKEY_eq(const EVP_PKEY *a, const EVP_PKEY *b); # ifndef OPENSSL_NO_DEPRECATED_3_0 OSSL_DEPRECATEDIN_3_0 int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b); OSSL_DEPRECATEDIN_3_0 int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b); # endif int EVP_PKEY_print_public(BIO *out, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx); int EVP_PKEY_print_private(BIO *out, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx); int EVP_PKEY_print_params(BIO *out, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx); # ifndef OPENSSL_NO_STDIO int EVP_PKEY_print_public_fp(FILE *fp, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx); int EVP_PKEY_print_private_fp(FILE *fp, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx); int EVP_PKEY_print_params_fp(FILE *fp, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx); # endif int EVP_PKEY_get_default_digest_nid(EVP_PKEY *pkey, int *pnid); int EVP_PKEY_get_default_digest_name(EVP_PKEY *pkey, char *mdname, size_t mdname_sz); int EVP_PKEY_digestsign_supports_digest(EVP_PKEY *pkey, OSSL_LIB_CTX *libctx, const char *name, const char *propq); # ifndef OPENSSL_NO_DEPRECATED_3_0 /* * For backwards compatibility. Use EVP_PKEY_set1_encoded_public_key in * preference */ # define EVP_PKEY_set1_tls_encodedpoint(pkey, pt, ptlen) \ EVP_PKEY_set1_encoded_public_key((pkey), (pt), (ptlen)) # endif int EVP_PKEY_set1_encoded_public_key(EVP_PKEY *pkey, const unsigned char *pub, size_t publen); # ifndef OPENSSL_NO_DEPRECATED_3_0 /* * For backwards compatibility. Use EVP_PKEY_get1_encoded_public_key in * preference */ # define EVP_PKEY_get1_tls_encodedpoint(pkey, ppt) \ EVP_PKEY_get1_encoded_public_key((pkey), (ppt)) # endif size_t EVP_PKEY_get1_encoded_public_key(EVP_PKEY *pkey, unsigned char **ppub); /* calls methods */ int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type); int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type); /* These are used by EVP_CIPHER methods */ int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type); int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type); /* PKCS5 password based encryption */ int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md, int en_de); int PKCS5_PBE_keyivgen_ex(EVP_CIPHER_CTX *cctx, const char *pass, int passlen, ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md, int en_de, OSSL_LIB_CTX *libctx, const char *propq); int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen, const unsigned char *salt, int saltlen, int iter, int keylen, unsigned char *out); int PKCS5_PBKDF2_HMAC(const char *pass, int passlen, const unsigned char *salt, int saltlen, int iter, const EVP_MD *digest, int keylen, unsigned char *out); int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md, int en_de); int PKCS5_v2_PBE_keyivgen_ex(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md, int en_de, OSSL_LIB_CTX *libctx, const char *propq); #ifndef OPENSSL_NO_SCRYPT int EVP_PBE_scrypt(const char *pass, size_t passlen, const unsigned char *salt, size_t saltlen, uint64_t N, uint64_t r, uint64_t p, uint64_t maxmem, unsigned char *key, size_t keylen); int EVP_PBE_scrypt_ex(const char *pass, size_t passlen, const unsigned char *salt, size_t saltlen, uint64_t N, uint64_t r, uint64_t p, uint64_t maxmem, unsigned char *key, size_t keylen, OSSL_LIB_CTX *ctx, const char *propq); int PKCS5_v2_scrypt_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, ASN1_TYPE *param, const EVP_CIPHER *c, const EVP_MD *md, int en_de); int PKCS5_v2_scrypt_keyivgen_ex(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, ASN1_TYPE *param, const EVP_CIPHER *c, const EVP_MD *md, int en_de, OSSL_LIB_CTX *libctx, const char *propq); #endif void PKCS5_PBE_add(void); int EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen, ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de); int EVP_PBE_CipherInit_ex(ASN1_OBJECT *pbe_obj, const char *pass, int passlen, ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de, OSSL_LIB_CTX *libctx, const char *propq); /* PBE type */ /* Can appear as the outermost AlgorithmIdentifier */ # define EVP_PBE_TYPE_OUTER 0x0 /* Is an PRF type OID */ # define EVP_PBE_TYPE_PRF 0x1 /* Is a PKCS#5 v2.0 KDF */ # define EVP_PBE_TYPE_KDF 0x2 int EVP_PBE_alg_add_type(int pbe_type, int pbe_nid, int cipher_nid, int md_nid, EVP_PBE_KEYGEN *keygen); int EVP_PBE_alg_add(int nid, const EVP_CIPHER *cipher, const EVP_MD *md, EVP_PBE_KEYGEN *keygen); int EVP_PBE_find(int type, int pbe_nid, int *pcnid, int *pmnid, EVP_PBE_KEYGEN **pkeygen); int EVP_PBE_find_ex(int type, int pbe_nid, int *pcnid, int *pmnid, EVP_PBE_KEYGEN **pkeygen, EVP_PBE_KEYGEN_EX **pkeygen_ex); void EVP_PBE_cleanup(void); int EVP_PBE_get(int *ptype, int *ppbe_nid, size_t num); # define ASN1_PKEY_ALIAS 0x1 # define ASN1_PKEY_DYNAMIC 0x2 # define ASN1_PKEY_SIGPARAM_NULL 0x4 # define ASN1_PKEY_CTRL_PKCS7_SIGN 0x1 # define ASN1_PKEY_CTRL_PKCS7_ENCRYPT 0x2 # define ASN1_PKEY_CTRL_DEFAULT_MD_NID 0x3 # define ASN1_PKEY_CTRL_CMS_SIGN 0x5 # define ASN1_PKEY_CTRL_CMS_ENVELOPE 0x7 # define ASN1_PKEY_CTRL_CMS_RI_TYPE 0x8 # define ASN1_PKEY_CTRL_SET1_TLS_ENCPT 0x9 # define ASN1_PKEY_CTRL_GET1_TLS_ENCPT 0xa # define ASN1_PKEY_CTRL_CMS_IS_RI_TYPE_SUPPORTED 0xb int EVP_PKEY_asn1_get_count(void); const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx); const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **pe, int type); const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe, const char *str, int len); int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth); int EVP_PKEY_asn1_add_alias(int to, int from); int EVP_PKEY_asn1_get0_info(int *ppkey_id, int *pkey_base_id, int *ppkey_flags, const char **pinfo, const char **ppem_str, const EVP_PKEY_ASN1_METHOD *ameth); const EVP_PKEY_ASN1_METHOD *EVP_PKEY_get0_asn1(const EVP_PKEY *pkey); EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_new(int id, int flags, const char *pem_str, const char *info); void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst, const EVP_PKEY_ASN1_METHOD *src); void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth); void EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth, int (*pub_decode) (EVP_PKEY *pk, const X509_PUBKEY *pub), int (*pub_encode) (X509_PUBKEY *pub, const EVP_PKEY *pk), int (*pub_cmp) (const EVP_PKEY *a, const EVP_PKEY *b), int (*pub_print) (BIO *out, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx), int (*pkey_size) (const EVP_PKEY *pk), int (*pkey_bits) (const EVP_PKEY *pk)); void EVP_PKEY_asn1_set_private(EVP_PKEY_ASN1_METHOD *ameth, int (*priv_decode) (EVP_PKEY *pk, const PKCS8_PRIV_KEY_INFO *p8inf), int (*priv_encode) (PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk), int (*priv_print) (BIO *out, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx)); void EVP_PKEY_asn1_set_param(EVP_PKEY_ASN1_METHOD *ameth, int (*param_decode) (EVP_PKEY *pkey, const unsigned char **pder, int derlen), int (*param_encode) (const EVP_PKEY *pkey, unsigned char **pder), int (*param_missing) (const EVP_PKEY *pk), int (*param_copy) (EVP_PKEY *to, const EVP_PKEY *from), int (*param_cmp) (const EVP_PKEY *a, const EVP_PKEY *b), int (*param_print) (BIO *out, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx)); void EVP_PKEY_asn1_set_free(EVP_PKEY_ASN1_METHOD *ameth, void (*pkey_free) (EVP_PKEY *pkey)); void EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD *ameth, int (*pkey_ctrl) (EVP_PKEY *pkey, int op, long arg1, void *arg2)); void EVP_PKEY_asn1_set_item(EVP_PKEY_ASN1_METHOD *ameth, int (*item_verify) (EVP_MD_CTX *ctx, const ASN1_ITEM *it, const void *data, const X509_ALGOR *a, const ASN1_BIT_STRING *sig, EVP_PKEY *pkey), int (*item_sign) (EVP_MD_CTX *ctx, const ASN1_ITEM *it, const void *data, X509_ALGOR *alg1, X509_ALGOR *alg2, ASN1_BIT_STRING *sig)); void EVP_PKEY_asn1_set_siginf(EVP_PKEY_ASN1_METHOD *ameth, int (*siginf_set) (X509_SIG_INFO *siginf, const X509_ALGOR *alg, const ASN1_STRING *sig)); void EVP_PKEY_asn1_set_check(EVP_PKEY_ASN1_METHOD *ameth, int (*pkey_check) (const EVP_PKEY *pk)); void EVP_PKEY_asn1_set_public_check(EVP_PKEY_ASN1_METHOD *ameth, int (*pkey_pub_check) (const EVP_PKEY *pk)); void EVP_PKEY_asn1_set_param_check(EVP_PKEY_ASN1_METHOD *ameth, int (*pkey_param_check) (const EVP_PKEY *pk)); void EVP_PKEY_asn1_set_set_priv_key(EVP_PKEY_ASN1_METHOD *ameth, int (*set_priv_key) (EVP_PKEY *pk, const unsigned char *priv, size_t len)); void EVP_PKEY_asn1_set_set_pub_key(EVP_PKEY_ASN1_METHOD *ameth, int (*set_pub_key) (EVP_PKEY *pk, const unsigned char *pub, size_t len)); void EVP_PKEY_asn1_set_get_priv_key(EVP_PKEY_ASN1_METHOD *ameth, int (*get_priv_key) (const EVP_PKEY *pk, unsigned char *priv, size_t *len)); void EVP_PKEY_asn1_set_get_pub_key(EVP_PKEY_ASN1_METHOD *ameth, int (*get_pub_key) (const EVP_PKEY *pk, unsigned char *pub, size_t *len)); void EVP_PKEY_asn1_set_security_bits(EVP_PKEY_ASN1_METHOD *ameth, int (*pkey_security_bits) (const EVP_PKEY *pk)); int EVP_PKEY_CTX_get_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD **md); int EVP_PKEY_CTX_set_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD *md); int EVP_PKEY_CTX_set1_id(EVP_PKEY_CTX *ctx, const void *id, int len); int EVP_PKEY_CTX_get1_id(EVP_PKEY_CTX *ctx, void *id); int EVP_PKEY_CTX_get1_id_len(EVP_PKEY_CTX *ctx, size_t *id_len); int EVP_PKEY_CTX_set_kem_op(EVP_PKEY_CTX *ctx, const char *op); const char *EVP_PKEY_get0_type_name(const EVP_PKEY *key); # define EVP_PKEY_OP_UNDEFINED 0 # define EVP_PKEY_OP_PARAMGEN (1<<1) # define EVP_PKEY_OP_KEYGEN (1<<2) # define EVP_PKEY_OP_FROMDATA (1<<3) # define EVP_PKEY_OP_SIGN (1<<4) # define EVP_PKEY_OP_VERIFY (1<<5) # define EVP_PKEY_OP_VERIFYRECOVER (1<<6) # define EVP_PKEY_OP_SIGNCTX (1<<7) # define EVP_PKEY_OP_VERIFYCTX (1<<8) # define EVP_PKEY_OP_ENCRYPT (1<<9) # define EVP_PKEY_OP_DECRYPT (1<<10) # define EVP_PKEY_OP_DERIVE (1<<11) # define EVP_PKEY_OP_ENCAPSULATE (1<<12) # define EVP_PKEY_OP_DECAPSULATE (1<<13) # define EVP_PKEY_OP_TYPE_SIG \ (EVP_PKEY_OP_SIGN | EVP_PKEY_OP_VERIFY | EVP_PKEY_OP_VERIFYRECOVER \ | EVP_PKEY_OP_SIGNCTX | EVP_PKEY_OP_VERIFYCTX) # define EVP_PKEY_OP_TYPE_CRYPT \ (EVP_PKEY_OP_ENCRYPT | EVP_PKEY_OP_DECRYPT) # define EVP_PKEY_OP_TYPE_NOGEN \ (EVP_PKEY_OP_TYPE_SIG | EVP_PKEY_OP_TYPE_CRYPT | EVP_PKEY_OP_DERIVE) # define EVP_PKEY_OP_TYPE_GEN \ (EVP_PKEY_OP_PARAMGEN | EVP_PKEY_OP_KEYGEN) int EVP_PKEY_CTX_set_mac_key(EVP_PKEY_CTX *ctx, const unsigned char *key, int keylen); # define EVP_PKEY_CTRL_MD 1 # define EVP_PKEY_CTRL_PEER_KEY 2 # define EVP_PKEY_CTRL_SET_MAC_KEY 6 # define EVP_PKEY_CTRL_DIGESTINIT 7 /* Used by GOST key encryption in TLS */ # define EVP_PKEY_CTRL_SET_IV 8 # ifndef OPENSSL_NO_DEPRECATED_3_0 # define EVP_PKEY_CTRL_PKCS7_ENCRYPT 3 # define EVP_PKEY_CTRL_PKCS7_DECRYPT 4 # define EVP_PKEY_CTRL_PKCS7_SIGN 5 # define EVP_PKEY_CTRL_CMS_ENCRYPT 9 # define EVP_PKEY_CTRL_CMS_DECRYPT 10 # define EVP_PKEY_CTRL_CMS_SIGN 11 # endif # define EVP_PKEY_CTRL_CIPHER 12 # define EVP_PKEY_CTRL_GET_MD 13 # define EVP_PKEY_CTRL_SET_DIGEST_SIZE 14 # define EVP_PKEY_CTRL_SET1_ID 15 # define EVP_PKEY_CTRL_GET1_ID 16 # define EVP_PKEY_CTRL_GET1_ID_LEN 17 # define EVP_PKEY_ALG_CTRL 0x1000 # define EVP_PKEY_FLAG_AUTOARGLEN 2 /* * Method handles all operations: don't assume any digest related defaults. */ # define EVP_PKEY_FLAG_SIGCTX_CUSTOM 4 # ifndef OPENSSL_NO_DEPRECATED_3_0 OSSL_DEPRECATEDIN_3_0 const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type); OSSL_DEPRECATEDIN_3_0 EVP_PKEY_METHOD *EVP_PKEY_meth_new(int id, int flags); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get0_info(int *ppkey_id, int *pflags, const EVP_PKEY_METHOD *meth); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_copy(EVP_PKEY_METHOD *dst, const EVP_PKEY_METHOD *src); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_free(EVP_PKEY_METHOD *pmeth); OSSL_DEPRECATEDIN_3_0 int EVP_PKEY_meth_add0(const EVP_PKEY_METHOD *pmeth); OSSL_DEPRECATEDIN_3_0 int EVP_PKEY_meth_remove(const EVP_PKEY_METHOD *pmeth); OSSL_DEPRECATEDIN_3_0 size_t EVP_PKEY_meth_get_count(void); OSSL_DEPRECATEDIN_3_0 const EVP_PKEY_METHOD *EVP_PKEY_meth_get0(size_t idx); # endif EVP_KEYMGMT *EVP_KEYMGMT_fetch(OSSL_LIB_CTX *ctx, const char *algorithm, const char *properties); int EVP_KEYMGMT_up_ref(EVP_KEYMGMT *keymgmt); void EVP_KEYMGMT_free(EVP_KEYMGMT *keymgmt); const OSSL_PROVIDER *EVP_KEYMGMT_get0_provider(const EVP_KEYMGMT *keymgmt); const char *EVP_KEYMGMT_get0_name(const EVP_KEYMGMT *keymgmt); const char *EVP_KEYMGMT_get0_description(const EVP_KEYMGMT *keymgmt); int EVP_KEYMGMT_is_a(const EVP_KEYMGMT *keymgmt, const char *name); void EVP_KEYMGMT_do_all_provided(OSSL_LIB_CTX *libctx, void (*fn)(EVP_KEYMGMT *keymgmt, void *arg), void *arg); int EVP_KEYMGMT_names_do_all(const EVP_KEYMGMT *keymgmt, void (*fn)(const char *name, void *data), void *data); const OSSL_PARAM *EVP_KEYMGMT_gettable_params(const EVP_KEYMGMT *keymgmt); const OSSL_PARAM *EVP_KEYMGMT_settable_params(const EVP_KEYMGMT *keymgmt); const OSSL_PARAM *EVP_KEYMGMT_gen_settable_params(const EVP_KEYMGMT *keymgmt); EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e); EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id, ENGINE *e); EVP_PKEY_CTX *EVP_PKEY_CTX_new_from_name(OSSL_LIB_CTX *libctx, const char *name, const char *propquery); EVP_PKEY_CTX *EVP_PKEY_CTX_new_from_pkey(OSSL_LIB_CTX *libctx, EVP_PKEY *pkey, const char *propquery); EVP_PKEY_CTX *EVP_PKEY_CTX_dup(const EVP_PKEY_CTX *ctx); void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx); int EVP_PKEY_CTX_is_a(EVP_PKEY_CTX *ctx, const char *keytype); int EVP_PKEY_CTX_get_params(EVP_PKEY_CTX *ctx, OSSL_PARAM *params); const OSSL_PARAM *EVP_PKEY_CTX_gettable_params(const EVP_PKEY_CTX *ctx); int EVP_PKEY_CTX_set_params(EVP_PKEY_CTX *ctx, const OSSL_PARAM *params); const OSSL_PARAM *EVP_PKEY_CTX_settable_params(const EVP_PKEY_CTX *ctx); int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype, int cmd, int p1, void *p2); int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, const char *value); int EVP_PKEY_CTX_ctrl_uint64(EVP_PKEY_CTX *ctx, int keytype, int optype, int cmd, uint64_t value); int EVP_PKEY_CTX_str2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *str); int EVP_PKEY_CTX_hex2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *hex); int EVP_PKEY_CTX_md(EVP_PKEY_CTX *ctx, int optype, int cmd, const char *md); int EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX *ctx); void EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX *ctx, int *dat, int datlen); EVP_PKEY *EVP_PKEY_new_mac_key(int type, ENGINE *e, const unsigned char *key, int keylen); EVP_PKEY *EVP_PKEY_new_raw_private_key_ex(OSSL_LIB_CTX *libctx, const char *keytype, const char *propq, const unsigned char *priv, size_t len); EVP_PKEY *EVP_PKEY_new_raw_private_key(int type, ENGINE *e, const unsigned char *priv, size_t len); EVP_PKEY *EVP_PKEY_new_raw_public_key_ex(OSSL_LIB_CTX *libctx, const char *keytype, const char *propq, const unsigned char *pub, size_t len); EVP_PKEY *EVP_PKEY_new_raw_public_key(int type, ENGINE *e, const unsigned char *pub, size_t len); int EVP_PKEY_get_raw_private_key(const EVP_PKEY *pkey, unsigned char *priv, size_t *len); int EVP_PKEY_get_raw_public_key(const EVP_PKEY *pkey, unsigned char *pub, size_t *len); # ifndef OPENSSL_NO_DEPRECATED_3_0 OSSL_DEPRECATEDIN_3_0 EVP_PKEY *EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv, size_t len, const EVP_CIPHER *cipher); # endif void EVP_PKEY_CTX_set_data(EVP_PKEY_CTX *ctx, void *data); void *EVP_PKEY_CTX_get_data(const EVP_PKEY_CTX *ctx); EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx); EVP_PKEY *EVP_PKEY_CTX_get0_peerkey(EVP_PKEY_CTX *ctx); void EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX *ctx, void *data); void *EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX *ctx); void EVP_SIGNATURE_free(EVP_SIGNATURE *signature); int EVP_SIGNATURE_up_ref(EVP_SIGNATURE *signature); OSSL_PROVIDER *EVP_SIGNATURE_get0_provider(const EVP_SIGNATURE *signature); EVP_SIGNATURE *EVP_SIGNATURE_fetch(OSSL_LIB_CTX *ctx, const char *algorithm, const char *properties); int EVP_SIGNATURE_is_a(const EVP_SIGNATURE *signature, const char *name); const char *EVP_SIGNATURE_get0_name(const EVP_SIGNATURE *signature); const char *EVP_SIGNATURE_get0_description(const EVP_SIGNATURE *signature); void EVP_SIGNATURE_do_all_provided(OSSL_LIB_CTX *libctx, void (*fn)(EVP_SIGNATURE *signature, void *data), void *data); int EVP_SIGNATURE_names_do_all(const EVP_SIGNATURE *signature, void (*fn)(const char *name, void *data), void *data); const OSSL_PARAM *EVP_SIGNATURE_gettable_ctx_params(const EVP_SIGNATURE *sig); const OSSL_PARAM *EVP_SIGNATURE_settable_ctx_params(const EVP_SIGNATURE *sig); void EVP_ASYM_CIPHER_free(EVP_ASYM_CIPHER *cipher); int EVP_ASYM_CIPHER_up_ref(EVP_ASYM_CIPHER *cipher); OSSL_PROVIDER *EVP_ASYM_CIPHER_get0_provider(const EVP_ASYM_CIPHER *cipher); EVP_ASYM_CIPHER *EVP_ASYM_CIPHER_fetch(OSSL_LIB_CTX *ctx, const char *algorithm, const char *properties); int EVP_ASYM_CIPHER_is_a(const EVP_ASYM_CIPHER *cipher, const char *name); const char *EVP_ASYM_CIPHER_get0_name(const EVP_ASYM_CIPHER *cipher); const char *EVP_ASYM_CIPHER_get0_description(const EVP_ASYM_CIPHER *cipher); void EVP_ASYM_CIPHER_do_all_provided(OSSL_LIB_CTX *libctx, void (*fn)(EVP_ASYM_CIPHER *cipher, void *arg), void *arg); int EVP_ASYM_CIPHER_names_do_all(const EVP_ASYM_CIPHER *cipher, void (*fn)(const char *name, void *data), void *data); const OSSL_PARAM *EVP_ASYM_CIPHER_gettable_ctx_params(const EVP_ASYM_CIPHER *ciph); const OSSL_PARAM *EVP_ASYM_CIPHER_settable_ctx_params(const EVP_ASYM_CIPHER *ciph); void EVP_KEM_free(EVP_KEM *wrap); int EVP_KEM_up_ref(EVP_KEM *wrap); OSSL_PROVIDER *EVP_KEM_get0_provider(const EVP_KEM *wrap); EVP_KEM *EVP_KEM_fetch(OSSL_LIB_CTX *ctx, const char *algorithm, const char *properties); int EVP_KEM_is_a(const EVP_KEM *wrap, const char *name); const char *EVP_KEM_get0_name(const EVP_KEM *wrap); const char *EVP_KEM_get0_description(const EVP_KEM *wrap); void EVP_KEM_do_all_provided(OSSL_LIB_CTX *libctx, void (*fn)(EVP_KEM *wrap, void *arg), void *arg); int EVP_KEM_names_do_all(const EVP_KEM *wrap, void (*fn)(const char *name, void *data), void *data); const OSSL_PARAM *EVP_KEM_gettable_ctx_params(const EVP_KEM *kem); const OSSL_PARAM *EVP_KEM_settable_ctx_params(const EVP_KEM *kem); int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx); int EVP_PKEY_sign_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]); int EVP_PKEY_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, const unsigned char *tbs, size_t tbslen); int EVP_PKEY_verify_init(EVP_PKEY_CTX *ctx); int EVP_PKEY_verify_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]); int EVP_PKEY_verify(EVP_PKEY_CTX *ctx, const unsigned char *sig, size_t siglen, const unsigned char *tbs, size_t tbslen); int EVP_PKEY_verify_recover_init(EVP_PKEY_CTX *ctx); int EVP_PKEY_verify_recover_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]); int EVP_PKEY_verify_recover(EVP_PKEY_CTX *ctx, unsigned char *rout, size_t *routlen, const unsigned char *sig, size_t siglen); int EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx); int EVP_PKEY_encrypt_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]); int EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen, const unsigned char *in, size_t inlen); int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx); int EVP_PKEY_decrypt_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]); int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen, const unsigned char *in, size_t inlen); int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx); int EVP_PKEY_derive_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]); int EVP_PKEY_derive_set_peer_ex(EVP_PKEY_CTX *ctx, EVP_PKEY *peer, int validate_peer); int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer); int EVP_PKEY_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen); int EVP_PKEY_encapsulate_init(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]); int EVP_PKEY_encapsulate(EVP_PKEY_CTX *ctx, unsigned char *wrappedkey, size_t *wrappedkeylen, unsigned char *genkey, size_t *genkeylen); int EVP_PKEY_decapsulate_init(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]); int EVP_PKEY_decapsulate(EVP_PKEY_CTX *ctx, unsigned char *unwrapped, size_t *unwrappedlen, const unsigned char *wrapped, size_t wrappedlen); typedef int EVP_PKEY_gen_cb(EVP_PKEY_CTX *ctx); int EVP_PKEY_fromdata_init(EVP_PKEY_CTX *ctx); int EVP_PKEY_fromdata(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey, int selection, OSSL_PARAM param[]); const OSSL_PARAM *EVP_PKEY_fromdata_settable(EVP_PKEY_CTX *ctx, int selection); int EVP_PKEY_todata(const EVP_PKEY *pkey, int selection, OSSL_PARAM **params); int EVP_PKEY_export(const EVP_PKEY *pkey, int selection, OSSL_CALLBACK *export_cb, void *export_cbarg); const OSSL_PARAM *EVP_PKEY_gettable_params(const EVP_PKEY *pkey); int EVP_PKEY_get_params(const EVP_PKEY *pkey, OSSL_PARAM params[]); int EVP_PKEY_get_int_param(const EVP_PKEY *pkey, const char *key_name, int *out); int EVP_PKEY_get_size_t_param(const EVP_PKEY *pkey, const char *key_name, size_t *out); int EVP_PKEY_get_bn_param(const EVP_PKEY *pkey, const char *key_name, BIGNUM **bn); int EVP_PKEY_get_utf8_string_param(const EVP_PKEY *pkey, const char *key_name, char *str, size_t max_buf_sz, size_t *out_sz); int EVP_PKEY_get_octet_string_param(const EVP_PKEY *pkey, const char *key_name, unsigned char *buf, size_t max_buf_sz, size_t *out_sz); const OSSL_PARAM *EVP_PKEY_settable_params(const EVP_PKEY *pkey); int EVP_PKEY_set_params(EVP_PKEY *pkey, OSSL_PARAM params[]); int EVP_PKEY_set_int_param(EVP_PKEY *pkey, const char *key_name, int in); int EVP_PKEY_set_size_t_param(EVP_PKEY *pkey, const char *key_name, size_t in); int EVP_PKEY_set_bn_param(EVP_PKEY *pkey, const char *key_name, const BIGNUM *bn); int EVP_PKEY_set_utf8_string_param(EVP_PKEY *pkey, const char *key_name, const char *str); int EVP_PKEY_set_octet_string_param(EVP_PKEY *pkey, const char *key_name, const unsigned char *buf, size_t bsize); int EVP_PKEY_get_ec_point_conv_form(const EVP_PKEY *pkey); int EVP_PKEY_get_field_type(const EVP_PKEY *pkey); EVP_PKEY *EVP_PKEY_Q_keygen(OSSL_LIB_CTX *libctx, const char *propq, const char *type, ...); int EVP_PKEY_paramgen_init(EVP_PKEY_CTX *ctx); int EVP_PKEY_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey); int EVP_PKEY_keygen_init(EVP_PKEY_CTX *ctx); int EVP_PKEY_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey); int EVP_PKEY_generate(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey); int EVP_PKEY_check(EVP_PKEY_CTX *ctx); int EVP_PKEY_public_check(EVP_PKEY_CTX *ctx); int EVP_PKEY_public_check_quick(EVP_PKEY_CTX *ctx); int EVP_PKEY_param_check(EVP_PKEY_CTX *ctx); int EVP_PKEY_param_check_quick(EVP_PKEY_CTX *ctx); int EVP_PKEY_private_check(EVP_PKEY_CTX *ctx); int EVP_PKEY_pairwise_check(EVP_PKEY_CTX *ctx); # define EVP_PKEY_get_ex_new_index(l, p, newf, dupf, freef) \ CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_EVP_PKEY, l, p, newf, dupf, freef) int EVP_PKEY_set_ex_data(EVP_PKEY *key, int idx, void *arg); void *EVP_PKEY_get_ex_data(const EVP_PKEY *key, int idx); void EVP_PKEY_CTX_set_cb(EVP_PKEY_CTX *ctx, EVP_PKEY_gen_cb *cb); EVP_PKEY_gen_cb *EVP_PKEY_CTX_get_cb(EVP_PKEY_CTX *ctx); int EVP_PKEY_CTX_get_keygen_info(EVP_PKEY_CTX *ctx, int idx); # ifndef OPENSSL_NO_DEPRECATED_3_0 OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_init(EVP_PKEY_METHOD *pmeth, int (*init) (EVP_PKEY_CTX *ctx)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_copy (EVP_PKEY_METHOD *pmeth, int (*copy) (EVP_PKEY_CTX *dst, const EVP_PKEY_CTX *src)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_cleanup (EVP_PKEY_METHOD *pmeth, void (*cleanup) (EVP_PKEY_CTX *ctx)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_paramgen (EVP_PKEY_METHOD *pmeth, int (*paramgen_init) (EVP_PKEY_CTX *ctx), int (*paramgen) (EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_keygen (EVP_PKEY_METHOD *pmeth, int (*keygen_init) (EVP_PKEY_CTX *ctx), int (*keygen) (EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_sign (EVP_PKEY_METHOD *pmeth, int (*sign_init) (EVP_PKEY_CTX *ctx), int (*sign) (EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, const unsigned char *tbs, size_t tbslen)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_verify (EVP_PKEY_METHOD *pmeth, int (*verify_init) (EVP_PKEY_CTX *ctx), int (*verify) (EVP_PKEY_CTX *ctx, const unsigned char *sig, size_t siglen, const unsigned char *tbs, size_t tbslen)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_verify_recover (EVP_PKEY_METHOD *pmeth, int (*verify_recover_init) (EVP_PKEY_CTX *ctx), int (*verify_recover) (EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, const unsigned char *tbs, size_t tbslen)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_signctx (EVP_PKEY_METHOD *pmeth, int (*signctx_init) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx), int (*signctx) (EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, EVP_MD_CTX *mctx)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_verifyctx (EVP_PKEY_METHOD *pmeth, int (*verifyctx_init) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx), int (*verifyctx) (EVP_PKEY_CTX *ctx, const unsigned char *sig, int siglen, EVP_MD_CTX *mctx)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_encrypt (EVP_PKEY_METHOD *pmeth, int (*encrypt_init) (EVP_PKEY_CTX *ctx), int (*encryptfn) (EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen, const unsigned char *in, size_t inlen)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_decrypt (EVP_PKEY_METHOD *pmeth, int (*decrypt_init) (EVP_PKEY_CTX *ctx), int (*decrypt) (EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen, const unsigned char *in, size_t inlen)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_derive (EVP_PKEY_METHOD *pmeth, int (*derive_init) (EVP_PKEY_CTX *ctx), int (*derive) (EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_ctrl (EVP_PKEY_METHOD *pmeth, int (*ctrl) (EVP_PKEY_CTX *ctx, int type, int p1, void *p2), int (*ctrl_str) (EVP_PKEY_CTX *ctx, const char *type, const char *value)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_digestsign (EVP_PKEY_METHOD *pmeth, int (*digestsign) (EVP_MD_CTX *ctx, unsigned char *sig, size_t *siglen, const unsigned char *tbs, size_t tbslen)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_digestverify (EVP_PKEY_METHOD *pmeth, int (*digestverify) (EVP_MD_CTX *ctx, const unsigned char *sig, size_t siglen, const unsigned char *tbs, size_t tbslen)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_check (EVP_PKEY_METHOD *pmeth, int (*check) (EVP_PKEY *pkey)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_public_check (EVP_PKEY_METHOD *pmeth, int (*check) (EVP_PKEY *pkey)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_param_check (EVP_PKEY_METHOD *pmeth, int (*check) (EVP_PKEY *pkey)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_digest_custom (EVP_PKEY_METHOD *pmeth, int (*digest_custom) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_init (const EVP_PKEY_METHOD *pmeth, int (**pinit) (EVP_PKEY_CTX *ctx)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_copy (const EVP_PKEY_METHOD *pmeth, int (**pcopy) (EVP_PKEY_CTX *dst, const EVP_PKEY_CTX *src)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_cleanup (const EVP_PKEY_METHOD *pmeth, void (**pcleanup) (EVP_PKEY_CTX *ctx)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_paramgen (const EVP_PKEY_METHOD *pmeth, int (**pparamgen_init) (EVP_PKEY_CTX *ctx), int (**pparamgen) (EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_keygen (const EVP_PKEY_METHOD *pmeth, int (**pkeygen_init) (EVP_PKEY_CTX *ctx), int (**pkeygen) (EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_sign (const EVP_PKEY_METHOD *pmeth, int (**psign_init) (EVP_PKEY_CTX *ctx), int (**psign) (EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, const unsigned char *tbs, size_t tbslen)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_verify (const EVP_PKEY_METHOD *pmeth, int (**pverify_init) (EVP_PKEY_CTX *ctx), int (**pverify) (EVP_PKEY_CTX *ctx, const unsigned char *sig, size_t siglen, const unsigned char *tbs, size_t tbslen)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_verify_recover (const EVP_PKEY_METHOD *pmeth, int (**pverify_recover_init) (EVP_PKEY_CTX *ctx), int (**pverify_recover) (EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, const unsigned char *tbs, size_t tbslen)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_signctx (const EVP_PKEY_METHOD *pmeth, int (**psignctx_init) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx), int (**psignctx) (EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, EVP_MD_CTX *mctx)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_verifyctx (const EVP_PKEY_METHOD *pmeth, int (**pverifyctx_init) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx), int (**pverifyctx) (EVP_PKEY_CTX *ctx, const unsigned char *sig, int siglen, EVP_MD_CTX *mctx)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_encrypt (const EVP_PKEY_METHOD *pmeth, int (**pencrypt_init) (EVP_PKEY_CTX *ctx), int (**pencryptfn) (EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen, const unsigned char *in, size_t inlen)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_decrypt (const EVP_PKEY_METHOD *pmeth, int (**pdecrypt_init) (EVP_PKEY_CTX *ctx), int (**pdecrypt) (EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen, const unsigned char *in, size_t inlen)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_derive (const EVP_PKEY_METHOD *pmeth, int (**pderive_init) (EVP_PKEY_CTX *ctx), int (**pderive) (EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_ctrl (const EVP_PKEY_METHOD *pmeth, int (**pctrl) (EVP_PKEY_CTX *ctx, int type, int p1, void *p2), int (**pctrl_str) (EVP_PKEY_CTX *ctx, const char *type, const char *value)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_digestsign (const EVP_PKEY_METHOD *pmeth, int (**digestsign) (EVP_MD_CTX *ctx, unsigned char *sig, size_t *siglen, const unsigned char *tbs, size_t tbslen)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_digestverify (const EVP_PKEY_METHOD *pmeth, int (**digestverify) (EVP_MD_CTX *ctx, const unsigned char *sig, size_t siglen, const unsigned char *tbs, size_t tbslen)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_check (const EVP_PKEY_METHOD *pmeth, int (**pcheck) (EVP_PKEY *pkey)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_public_check (const EVP_PKEY_METHOD *pmeth, int (**pcheck) (EVP_PKEY *pkey)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_param_check (const EVP_PKEY_METHOD *pmeth, int (**pcheck) (EVP_PKEY *pkey)); OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_digest_custom (const EVP_PKEY_METHOD *pmeth, int (**pdigest_custom) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx)); # endif void EVP_KEYEXCH_free(EVP_KEYEXCH *exchange); int EVP_KEYEXCH_up_ref(EVP_KEYEXCH *exchange); EVP_KEYEXCH *EVP_KEYEXCH_fetch(OSSL_LIB_CTX *ctx, const char *algorithm, const char *properties); OSSL_PROVIDER *EVP_KEYEXCH_get0_provider(const EVP_KEYEXCH *exchange); int EVP_KEYEXCH_is_a(const EVP_KEYEXCH *keyexch, const char *name); const char *EVP_KEYEXCH_get0_name(const EVP_KEYEXCH *keyexch); const char *EVP_KEYEXCH_get0_description(const EVP_KEYEXCH *keyexch); void EVP_KEYEXCH_do_all_provided(OSSL_LIB_CTX *libctx, void (*fn)(EVP_KEYEXCH *keyexch, void *data), void *data); int EVP_KEYEXCH_names_do_all(const EVP_KEYEXCH *keyexch, void (*fn)(const char *name, void *data), void *data); const OSSL_PARAM *EVP_KEYEXCH_gettable_ctx_params(const EVP_KEYEXCH *keyexch); const OSSL_PARAM *EVP_KEYEXCH_settable_ctx_params(const EVP_KEYEXCH *keyexch); void EVP_add_alg_module(void); int EVP_PKEY_CTX_set_group_name(EVP_PKEY_CTX *ctx, const char *name); int EVP_PKEY_CTX_get_group_name(EVP_PKEY_CTX *ctx, char *name, size_t namelen); int EVP_PKEY_get_group_name(const EVP_PKEY *pkey, char *name, size_t name_sz, size_t *gname_len); OSSL_LIB_CTX *EVP_PKEY_CTX_get0_libctx(EVP_PKEY_CTX *ctx); const char *EVP_PKEY_CTX_get0_propq(const EVP_PKEY_CTX *ctx); const OSSL_PROVIDER *EVP_PKEY_CTX_get0_provider(const EVP_PKEY_CTX *ctx); # ifdef __cplusplus } # endif #endif diff --git a/crypto/openssl/include/openssl/opensslv.h b/crypto/openssl/include/openssl/opensslv.h index 0bf61ce6a9d7..73590b76ca70 100644 --- a/crypto/openssl/include/openssl/opensslv.h +++ b/crypto/openssl/include/openssl/opensslv.h @@ -1,114 +1,114 @@ /* * WARNING: do not edit! * Generated by Makefile from include/openssl/opensslv.h.in * * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ #ifndef OPENSSL_OPENSSLV_H # define OPENSSL_OPENSSLV_H # pragma once # ifdef __cplusplus extern "C" { # endif /* * SECTION 1: VERSION DATA. These will change for each release */ /* * Base version macros * * These macros express version number MAJOR.MINOR.PATCH exactly */ # define OPENSSL_VERSION_MAJOR 3 # define OPENSSL_VERSION_MINOR 0 -# define OPENSSL_VERSION_PATCH 11 +# define OPENSSL_VERSION_PATCH 12 /* * Additional version information * * These are also part of the new version scheme, but aren't part * of the version number itself. */ /* Could be: #define OPENSSL_VERSION_PRE_RELEASE "-alpha.1" */ # define OPENSSL_VERSION_PRE_RELEASE "" /* Could be: #define OPENSSL_VERSION_BUILD_METADATA "+fips" */ /* Could be: #define OPENSSL_VERSION_BUILD_METADATA "+vendor.1" */ # define OPENSSL_VERSION_BUILD_METADATA "" /* * Note: The OpenSSL Project will never define OPENSSL_VERSION_BUILD_METADATA * to be anything but the empty string. Its use is entirely reserved for * others */ /* * Shared library version * * This is strictly to express ABI version, which may or may not * be related to the API version expressed with the macros above. * This is defined in free form. */ # define OPENSSL_SHLIB_VERSION 3 /* * SECTION 2: USEFUL MACROS */ /* For checking general API compatibility when preprocessing */ # define OPENSSL_VERSION_PREREQ(maj,min) \ ((OPENSSL_VERSION_MAJOR << 16) + OPENSSL_VERSION_MINOR >= ((maj) << 16) + (min)) /* * Macros to get the version in easily digested string form, both the short * "MAJOR.MINOR.PATCH" variant (where MAJOR, MINOR and PATCH are replaced * with the values from the corresponding OPENSSL_VERSION_ macros) and the * longer variant with OPENSSL_VERSION_PRE_RELEASE_STR and * OPENSSL_VERSION_BUILD_METADATA_STR appended. */ -# define OPENSSL_VERSION_STR "3.0.11" -# define OPENSSL_FULL_VERSION_STR "3.0.11" +# define OPENSSL_VERSION_STR "3.0.12" +# define OPENSSL_FULL_VERSION_STR "3.0.12" /* * SECTION 3: ADDITIONAL METADATA * * These strings are defined separately to allow them to be parsable. */ -# define OPENSSL_RELEASE_DATE "19 Sep 2023" +# define OPENSSL_RELEASE_DATE "24 Oct 2023" /* * SECTION 4: BACKWARD COMPATIBILITY */ -# define OPENSSL_VERSION_TEXT "OpenSSL 3.0.11 19 Sep 2023" +# define OPENSSL_VERSION_TEXT "OpenSSL 3.0.12 24 Oct 2023" /* Synthesize OPENSSL_VERSION_NUMBER with the layout 0xMNN00PPSL */ # ifdef OPENSSL_VERSION_PRE_RELEASE # define _OPENSSL_VERSION_PRE_RELEASE 0x0L # else # define _OPENSSL_VERSION_PRE_RELEASE 0xfL # endif # define OPENSSL_VERSION_NUMBER \ ( (OPENSSL_VERSION_MAJOR<<28) \ |(OPENSSL_VERSION_MINOR<<20) \ |(OPENSSL_VERSION_PATCH<<4) \ |_OPENSSL_VERSION_PRE_RELEASE ) # ifdef __cplusplus } # endif # include # ifndef OPENSSL_NO_DEPRECATED_3_0 # define HEADER_OPENSSLV_H # endif #endif /* OPENSSL_OPENSSLV_H */ diff --git a/crypto/openssl/include/openssl/pkcs7.h.in b/crypto/openssl/include/openssl/pkcs7.h.in index f5c55a3fbe57..006b38b60411 100644 --- a/crypto/openssl/include/openssl/pkcs7.h.in +++ b/crypto/openssl/include/openssl/pkcs7.h.in @@ -1,356 +1,356 @@ /* * {- join("\n * ", @autowarntext) -} * - * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ {- use OpenSSL::stackhash qw(generate_stack_macros); -} #ifndef OPENSSL_PKCS7_H # define OPENSSL_PKCS7_H # pragma once # include # ifndef OPENSSL_NO_DEPRECATED_3_0 # define HEADER_PKCS7_H # endif # include # include # include # include # include # include #ifdef __cplusplus extern "C" { #endif /*- Encryption_ID DES-CBC Digest_ID MD5 Digest_Encryption_ID rsaEncryption Key_Encryption_ID rsaEncryption */ typedef struct PKCS7_CTX_st { OSSL_LIB_CTX *libctx; char *propq; } PKCS7_CTX; typedef struct pkcs7_issuer_and_serial_st { X509_NAME *issuer; ASN1_INTEGER *serial; } PKCS7_ISSUER_AND_SERIAL; typedef struct pkcs7_signer_info_st { ASN1_INTEGER *version; /* version 1 */ PKCS7_ISSUER_AND_SERIAL *issuer_and_serial; X509_ALGOR *digest_alg; STACK_OF(X509_ATTRIBUTE) *auth_attr; /* [ 0 ] */ - X509_ALGOR *digest_enc_alg; - ASN1_OCTET_STRING *enc_digest; + X509_ALGOR *digest_enc_alg; /* confusing name, actually used for signing */ + ASN1_OCTET_STRING *enc_digest; /* confusing name, actually signature */ STACK_OF(X509_ATTRIBUTE) *unauth_attr; /* [ 1 ] */ /* The private key to sign with */ EVP_PKEY *pkey; const PKCS7_CTX *ctx; } PKCS7_SIGNER_INFO; {- generate_stack_macros("PKCS7_SIGNER_INFO"); -} typedef struct pkcs7_recip_info_st { ASN1_INTEGER *version; /* version 0 */ PKCS7_ISSUER_AND_SERIAL *issuer_and_serial; X509_ALGOR *key_enc_algor; ASN1_OCTET_STRING *enc_key; X509 *cert; /* get the pub-key from this */ const PKCS7_CTX *ctx; } PKCS7_RECIP_INFO; {- generate_stack_macros("PKCS7_RECIP_INFO"); -} typedef struct pkcs7_signed_st { ASN1_INTEGER *version; /* version 1 */ STACK_OF(X509_ALGOR) *md_algs; /* md used */ STACK_OF(X509) *cert; /* [ 0 ] */ STACK_OF(X509_CRL) *crl; /* [ 1 ] */ STACK_OF(PKCS7_SIGNER_INFO) *signer_info; struct pkcs7_st *contents; } PKCS7_SIGNED; /* * The above structure is very very similar to PKCS7_SIGN_ENVELOPE. How about * merging the two */ typedef struct pkcs7_enc_content_st { ASN1_OBJECT *content_type; X509_ALGOR *algorithm; ASN1_OCTET_STRING *enc_data; /* [ 0 ] */ const EVP_CIPHER *cipher; const PKCS7_CTX *ctx; } PKCS7_ENC_CONTENT; typedef struct pkcs7_enveloped_st { ASN1_INTEGER *version; /* version 0 */ STACK_OF(PKCS7_RECIP_INFO) *recipientinfo; PKCS7_ENC_CONTENT *enc_data; } PKCS7_ENVELOPE; typedef struct pkcs7_signedandenveloped_st { ASN1_INTEGER *version; /* version 1 */ STACK_OF(X509_ALGOR) *md_algs; /* md used */ STACK_OF(X509) *cert; /* [ 0 ] */ STACK_OF(X509_CRL) *crl; /* [ 1 ] */ STACK_OF(PKCS7_SIGNER_INFO) *signer_info; PKCS7_ENC_CONTENT *enc_data; STACK_OF(PKCS7_RECIP_INFO) *recipientinfo; } PKCS7_SIGN_ENVELOPE; typedef struct pkcs7_digest_st { ASN1_INTEGER *version; /* version 0 */ X509_ALGOR *md; /* md used */ struct pkcs7_st *contents; ASN1_OCTET_STRING *digest; } PKCS7_DIGEST; typedef struct pkcs7_encrypted_st { ASN1_INTEGER *version; /* version 0 */ PKCS7_ENC_CONTENT *enc_data; } PKCS7_ENCRYPT; typedef struct pkcs7_st { /* * The following is non NULL if it contains ASN1 encoding of this * structure */ unsigned char *asn1; long length; # define PKCS7_S_HEADER 0 # define PKCS7_S_BODY 1 # define PKCS7_S_TAIL 2 int state; /* used during processing */ int detached; ASN1_OBJECT *type; /* content as defined by the type */ /* * all encryption/message digests are applied to the 'contents', leaving * out the 'type' field. */ union { char *ptr; /* NID_pkcs7_data */ ASN1_OCTET_STRING *data; /* NID_pkcs7_signed */ PKCS7_SIGNED *sign; /* NID_pkcs7_enveloped */ PKCS7_ENVELOPE *enveloped; /* NID_pkcs7_signedAndEnveloped */ PKCS7_SIGN_ENVELOPE *signed_and_enveloped; /* NID_pkcs7_digest */ PKCS7_DIGEST *digest; /* NID_pkcs7_encrypted */ PKCS7_ENCRYPT *encrypted; /* Anything else */ ASN1_TYPE *other; } d; PKCS7_CTX ctx; } PKCS7; {- generate_stack_macros("PKCS7"); -} # define PKCS7_OP_SET_DETACHED_SIGNATURE 1 # define PKCS7_OP_GET_DETACHED_SIGNATURE 2 # define PKCS7_get_signed_attributes(si) ((si)->auth_attr) # define PKCS7_get_attributes(si) ((si)->unauth_attr) # define PKCS7_type_is_signed(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_signed) # define PKCS7_type_is_encrypted(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_encrypted) # define PKCS7_type_is_enveloped(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_enveloped) # define PKCS7_type_is_signedAndEnveloped(a) \ (OBJ_obj2nid((a)->type) == NID_pkcs7_signedAndEnveloped) # define PKCS7_type_is_data(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_data) # define PKCS7_type_is_digest(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_digest) # define PKCS7_set_detached(p,v) \ PKCS7_ctrl(p,PKCS7_OP_SET_DETACHED_SIGNATURE,v,NULL) # define PKCS7_get_detached(p) \ PKCS7_ctrl(p,PKCS7_OP_GET_DETACHED_SIGNATURE,0,NULL) # define PKCS7_is_detached(p7) (PKCS7_type_is_signed(p7) && PKCS7_get_detached(p7)) /* S/MIME related flags */ # define PKCS7_TEXT 0x1 # define PKCS7_NOCERTS 0x2 # define PKCS7_NOSIGS 0x4 # define PKCS7_NOCHAIN 0x8 # define PKCS7_NOINTERN 0x10 # define PKCS7_NOVERIFY 0x20 # define PKCS7_DETACHED 0x40 # define PKCS7_BINARY 0x80 # define PKCS7_NOATTR 0x100 # define PKCS7_NOSMIMECAP 0x200 # define PKCS7_NOOLDMIMETYPE 0x400 # define PKCS7_CRLFEOL 0x800 # define PKCS7_STREAM 0x1000 # define PKCS7_NOCRL 0x2000 # define PKCS7_PARTIAL 0x4000 # define PKCS7_REUSE_DIGEST 0x8000 # define PKCS7_NO_DUAL_CONTENT 0x10000 /* Flags: for compatibility with older code */ # define SMIME_TEXT PKCS7_TEXT # define SMIME_NOCERTS PKCS7_NOCERTS # define SMIME_NOSIGS PKCS7_NOSIGS # define SMIME_NOCHAIN PKCS7_NOCHAIN # define SMIME_NOINTERN PKCS7_NOINTERN # define SMIME_NOVERIFY PKCS7_NOVERIFY # define SMIME_DETACHED PKCS7_DETACHED # define SMIME_BINARY PKCS7_BINARY # define SMIME_NOATTR PKCS7_NOATTR /* CRLF ASCII canonicalisation */ # define SMIME_ASCIICRLF 0x80000 DECLARE_ASN1_FUNCTIONS(PKCS7_ISSUER_AND_SERIAL) int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data, const EVP_MD *type, unsigned char *md, unsigned int *len); # ifndef OPENSSL_NO_STDIO PKCS7 *d2i_PKCS7_fp(FILE *fp, PKCS7 **p7); int i2d_PKCS7_fp(FILE *fp, const PKCS7 *p7); # endif DECLARE_ASN1_DUP_FUNCTION(PKCS7) PKCS7 *d2i_PKCS7_bio(BIO *bp, PKCS7 **p7); int i2d_PKCS7_bio(BIO *bp, const PKCS7 *p7); int i2d_PKCS7_bio_stream(BIO *out, PKCS7 *p7, BIO *in, int flags); int PEM_write_bio_PKCS7_stream(BIO *out, PKCS7 *p7, BIO *in, int flags); DECLARE_ASN1_FUNCTIONS(PKCS7_SIGNER_INFO) DECLARE_ASN1_FUNCTIONS(PKCS7_RECIP_INFO) DECLARE_ASN1_FUNCTIONS(PKCS7_SIGNED) DECLARE_ASN1_FUNCTIONS(PKCS7_ENC_CONTENT) DECLARE_ASN1_FUNCTIONS(PKCS7_ENVELOPE) DECLARE_ASN1_FUNCTIONS(PKCS7_SIGN_ENVELOPE) DECLARE_ASN1_FUNCTIONS(PKCS7_DIGEST) DECLARE_ASN1_FUNCTIONS(PKCS7_ENCRYPT) DECLARE_ASN1_FUNCTIONS(PKCS7) PKCS7 *PKCS7_new_ex(OSSL_LIB_CTX *libctx, const char *propq); DECLARE_ASN1_ITEM(PKCS7_ATTR_SIGN) DECLARE_ASN1_ITEM(PKCS7_ATTR_VERIFY) DECLARE_ASN1_NDEF_FUNCTION(PKCS7) DECLARE_ASN1_PRINT_FUNCTION(PKCS7) long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg); int PKCS7_type_is_other(PKCS7 *p7); int PKCS7_set_type(PKCS7 *p7, int type); int PKCS7_set0_type_other(PKCS7 *p7, int type, ASN1_TYPE *other); int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data); int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey, const EVP_MD *dgst); int PKCS7_SIGNER_INFO_sign(PKCS7_SIGNER_INFO *si); int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *p7i); int PKCS7_add_certificate(PKCS7 *p7, X509 *x509); int PKCS7_add_crl(PKCS7 *p7, X509_CRL *x509); int PKCS7_content_new(PKCS7 *p7, int nid); int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si); int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si, X509 *x509); BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio); int PKCS7_dataFinal(PKCS7 *p7, BIO *bio); BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert); PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509, EVP_PKEY *pkey, const EVP_MD *dgst); X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si); int PKCS7_set_digest(PKCS7 *p7, const EVP_MD *md); STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7); PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509); void PKCS7_SIGNER_INFO_get0_algs(PKCS7_SIGNER_INFO *si, EVP_PKEY **pk, X509_ALGOR **pdig, X509_ALGOR **psig); void PKCS7_RECIP_INFO_get0_alg(PKCS7_RECIP_INFO *ri, X509_ALGOR **penc); int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri); int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509); int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher); int PKCS7_stream(unsigned char ***boundary, PKCS7 *p7); PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx); ASN1_OCTET_STRING *PKCS7_get_octet_string(PKCS7 *p7); ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk); int PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int type, void *data); int PKCS7_add_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int atrtype, void *value); ASN1_TYPE *PKCS7_get_attribute(const PKCS7_SIGNER_INFO *si, int nid); ASN1_TYPE *PKCS7_get_signed_attribute(const PKCS7_SIGNER_INFO *si, int nid); int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si, STACK_OF(X509_ATTRIBUTE) *sk); int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si, STACK_OF(X509_ATTRIBUTE) *sk); PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, BIO *data, int flags); PKCS7 *PKCS7_sign_ex(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, BIO *data, int flags, OSSL_LIB_CTX *libctx, const char *propq); PKCS7_SIGNER_INFO *PKCS7_sign_add_signer(PKCS7 *p7, X509 *signcert, EVP_PKEY *pkey, const EVP_MD *md, int flags); int PKCS7_final(PKCS7 *p7, BIO *data, int flags); int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, BIO *indata, BIO *out, int flags); STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags); PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher, int flags); PKCS7 *PKCS7_encrypt_ex(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher, int flags, OSSL_LIB_CTX *libctx, const char *propq); int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags); int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si, STACK_OF(X509_ALGOR) *cap); STACK_OF(X509_ALGOR) *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si); int PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg); int PKCS7_add_attrib_content_type(PKCS7_SIGNER_INFO *si, ASN1_OBJECT *coid); int PKCS7_add0_attrib_signing_time(PKCS7_SIGNER_INFO *si, ASN1_TIME *t); int PKCS7_add1_attrib_digest(PKCS7_SIGNER_INFO *si, const unsigned char *md, int mdlen); int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags); PKCS7 *SMIME_read_PKCS7_ex(BIO *bio, BIO **bcont, PKCS7 **p7); PKCS7 *SMIME_read_PKCS7(BIO *bio, BIO **bcont); BIO *BIO_new_PKCS7(BIO *out, PKCS7 *p7); # ifdef __cplusplus } # endif #endif diff --git a/crypto/openssl/providers/fips-sources.checksums b/crypto/openssl/providers/fips-sources.checksums index f55fa914be7f..fa977f5a9838 100644 --- a/crypto/openssl/providers/fips-sources.checksums +++ b/crypto/openssl/providers/fips-sources.checksums @@ -1,595 +1,595 @@ 0e22ea0cf34ef3871e30df0bc302dc29352d38001d1622ddb78a27a374b6aee8 crypto/aes/aes_cbc.c c049a936d74100fcced225f575d46662792a6a0039777d2d4df0cf61eff90a68 crypto/aes/aes_core.c 3fac41ce96acb9189eac2d5571425c3ff33a34c884ae7e275e1fd3068b5fc662 crypto/aes/aes_ecb.c c1e674d08683a25bc053f6233f73a0d0b3a90aafe591ff57b702c7da1582e4a5 crypto/aes/aes_local.h a2466f18da5847c7d9fbced17524633c10ce024671a72f53f9c9c55b9b9923dd crypto/aes/aes_misc.c 6979c133f76f4623e62e6e970deae70fa025e713a72b71aead5a048d49e47f6f crypto/aes/asm/aes-586.pl 92be9ff608331a432e95247a8f4fb9e46897d0cb76f2b6db809b61d44287964a crypto/aes/asm/aes-armv4.pl 953897f86e2de9fa27ef411155ab3aed133af94885f1507e76449c142da78656 crypto/aes/asm/aes-c64xplus.pl 00196f01f5218ad731e6a058d406078f7228a9756d9d73f51c0d0c2a68f885af crypto/aes/asm/aes-ia64.S 88b6f8396cd9d86004743d5c3b0f72b7b8c3d5a2b00b0bbb761ba91ae5a7cdc8 crypto/aes/asm/aes-mips.pl 7ff9c96ef3d591d45d776fa4b244601ea0d9328e289aeab1e1b92436ce7d02ad crypto/aes/asm/aes-parisc.pl f1244cdeadcb4e48f35bc5df19d4cfaf07e0086ad951b84f07ff6966501faa5b crypto/aes/asm/aes-ppc.pl ecbfe826f4c514810c3ee20e265f4f621149694c298554b2682e5de4f029f14f crypto/aes/asm/aes-s390x.pl ee4e8cacef972942d2a89c1a83c984df9cad87c61a54383403c5c4864c403ba1 crypto/aes/asm/aes-sparcv9.pl 2b3b9ac56bf54334d053857a24bdb08592151e8a7a60b89b8195846b7f8ee7b5 crypto/aes/asm/aes-x86_64.pl c56c324667b67d726e040d70379efba5b270e2937f403c1b5979018b836903c7 crypto/aes/asm/aesfx-sparcv9.pl 14359dc32b7f4e5c08227fb9ac8f9232c1287399463b233fec4a2ab0c19f68d1 crypto/aes/asm/aesni-mb-x86_64.pl 2fe016e8098d1c959b6199ce98e91dfed9a3a543d6b068daf88d4c4c402701ec crypto/aes/asm/aesni-sha1-x86_64.pl 1d3acabadedb88d1327eeb76201ea9b3f4814f44898018ffae6c73e3f400b89b crypto/aes/asm/aesni-sha256-x86_64.pl 4ff74d4e629a88ef5a9e3d3f5b340fc0a4793d16d7cc7f1b70da62512a856248 crypto/aes/asm/aesni-x86.pl c7c6694480bb5319690f94826139a93f5c460ebea6dba101b520a76cb956ec93 crypto/aes/asm/aesni-x86_64.pl f3a8f3c960c0f47aaa8fc2633d18b14e7c7feeccc536b0115a08bc58333122b6 crypto/aes/asm/aesp8-ppc.pl e397a5781893e97dd90a5a52049633be12a43f379ec5751bca2a6350c39444c8 crypto/aes/asm/aest4-sparcv9.pl -a097f9d71de7cefa8e93629033ff1986fb01128623ec051d9b5afef55c0e5ebb crypto/aes/asm/aesv8-armx.pl +e3955352a92d56905d63e68937e4758f13190a14a10a3dcb1e5c641c49913c0c crypto/aes/asm/aesv8-armx.pl 5e8005fdb6641df465bdda20c3476f7176e6bcd63d5073044a0c02a327c7f172 crypto/aes/asm/bsaes-armv7.pl 0726a2c4c15c27a12b2f7d5e16863df4a1b1daa7b7d9b728f621b2b224d290e6 crypto/aes/asm/bsaes-x86_64.pl 1ff94d6bf6c8ae4809f64657eb89260fe3cb22137f649d3c73f72cb190258196 crypto/aes/asm/vpaes-armv8.pl c3541865cd02d81101cdbab4877ed82772e6980d2c677b9008b38fa1b26d36d4 crypto/aes/asm/vpaes-ppc.pl 3ec24185750a995377516bc2fb2eae8b1c52094c6fff093bff591837fc12d6c3 crypto/aes/asm/vpaes-x86.pl 060bb6620f50af9afecdf97df051b45b9a50be9daf343dfec1cbb29693ce00a4 crypto/aes/asm/vpaes-x86_64.pl 2bc67270155e2d6c7da87d9070e005ee79cea18311004907edfd6a078003532a crypto/alphacpuid.pl 0255a480b78bdcc71f76676f496962a9828eb900f53b7be13be96ae3f67fe6db crypto/arm64cpuid.pl e0daf54f72dd8fd1bc537d93f34e2a6a887a9ed6027bb33e15a327ef5ff37a42 crypto/armcap.c a43f2c1eef16146943745f684f2add7d186924932a47abf7fb0760cba02804e6 crypto/armv4cpuid.pl 16739d54200fb81ca7835b5814f965022a2ab41589c7787e2697e3ea72d4fafa crypto/asn1_dsa.c 819c9fd2b0cae9aab81c3cbd1815c2e22949d75f132f649b5883812d0bbaa39a crypto/bn/asm/alpha-mont.pl 0070595128b250b9ebdebe48ce53d2d27ca16ec4f7c6c8bd169ab2e4a913b2d1 crypto/bn/asm/armv4-gf2m.pl 8c1c53a725b8a4f92b8a353bfeeb393be94198df41c912e3270f9e654417b250 crypto/bn/asm/armv4-mont.pl 8d6192337fedb0012764229d600634f8357c3b74fd38bcbfe8b86ddc6ca96ea2 crypto/bn/asm/armv8-mont.pl cb4ad7b7461fcb8e2a0d52881158d0211b79544842d4eae36fc566869a2d62c8 crypto/bn/asm/bn-586.pl 636da7e2a66272a81f9c99e90b36c6f132ad6236c739e8b9f2e7315f30b72edd crypto/bn/asm/c64xplus-gf2m.pl c86664fb974362ee52a454c83c2c4b23fd5b7d64b3c9e23ef1e0dfd130a46ee5 crypto/bn/asm/co-586.pl 199b9b100f194a2a128c14f2a71be5a04d50d069666d90ca5b69baee1318ccb7 crypto/bn/asm/ia64-mont.pl a511aafbf76647a0c83705d4491c898a5584d300aa449fa6166c8803372946eb crypto/bn/asm/ia64.S 687c5d6606fdfd0e242005972d15db74a9cbac2b8a9a54a56fcb1e99d3880ff3 crypto/bn/asm/mips-mont.pl 8aca83d2ec45a40af15e59cff1ac2dc33737a3d25f0a0b74d401fa778a5c5eb8 crypto/bn/asm/mips.pl b27ec5181e387e812925bb26823b830f49d7a6e4971b6d11ea583f5632a1504b crypto/bn/asm/parisc-mont.pl 9973523b361db963eea4938a7a8a3adc692e1a4e1aec4fa1f1e57dc93da37921 crypto/bn/asm/ppc-mont.pl 59cd27e1e10c4984b7fb684b27f491e7634473b1bcff197a07e0ca653124aa9a crypto/bn/asm/ppc.pl e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 crypto/bn/asm/ppc64-mont-fixed.pl a25be64867ab837d93855af232e2bfa71b85b2c6f00e35e620fdc5618187fb6f crypto/bn/asm/ppc64-mont.pl 231579e532443665020d4d522d9f11713d9c5d5c814b95b434b0f65452e16de4 crypto/bn/asm/rsaz-avx2.pl 1657600d320ea549b527b2d878a7658533d60d26eeb38f42ea470fc612f9bb53 crypto/bn/asm/rsaz-avx512.pl 31e84dc905b13e38850071528d3abbfcaf8910bbc8b46f38d19c2b386a5f838e crypto/bn/asm/rsaz-x86_64.pl 30fedf48dfc5fec1c2044b6c226dd9fc42a92522cc589797a23a79d452bdd2cf crypto/bn/asm/s390x-gf2m.pl 590388d69d7ac3a0e9af4014792f4f0fdb9552719e8fb48ebc7e5dfca2a491d4 crypto/bn/asm/s390x-mont.pl aa02597f3dc09cfbc190aedb75711859ba0f3efff87067ebfba1ec78ebee40d7 crypto/bn/asm/s390x.S 2f7cbc2c3d93b1bbc4953dda38b9ae0ab3a0a8331a0418d94d9b286183736c9e crypto/bn/asm/sparct4-mont.pl ca21a9ccbc54e19fb7c2e6cdf286ce7cb08b0fba960c777c6edce5c57ccc2101 crypto/bn/asm/sparcv8.S fbc93c8dbbecefe66086f58fe9719ed87b13b2cdc61454a10e841228296fecef crypto/bn/asm/sparcv8plus.S 127832c1e3d298aad805236776488f5f8836b6a0fdbce3f6b42678163df3909f crypto/bn/asm/sparcv9-gf2m.pl 1622f04a8918724ac0e8804baf285fdafa0eeaaecc36c7facd459d0ff13a8cac crypto/bn/asm/sparcv9-mont.pl b69083f78b4b4f7097de4462d16649532fb82c453a82cdd9cc1393122661d6e2 crypto/bn/asm/sparcv9a-mont.pl d404375a21d33396824a3da212d6646d4f3150dd141ee4b4a250aefae3482efb crypto/bn/asm/via-mont.pl d24f3e97239c8eed5efc721521b025b7256c15e67a54ea6b5c4cf8f7cd0f89ea crypto/bn/asm/vis3-mont.pl 89278854f44d95be916516609ce6f79dcd346bab52574b9b6336a9952aa94bee crypto/bn/asm/x86-gf2m.pl 90d4ae234c08267adce9ed38d56e0edc223f7480cb9605f5d7399d0b3914c6be crypto/bn/asm/x86-mont.pl d444ca73875e97e0ea88b20e4c02f2fcf3850e8b9311e3b67a2d04fe2796d543 crypto/bn/asm/x86_64-gcc.c 709ddee92e9222ee0ed27bfb90db556e85e2d302e4a9131afa25fdc14c4d858f crypto/bn/asm/x86_64-gf2m.pl da7f7780d27eed164797e5334cd45b35d9c113e86afaca051463aef9a8fd787c crypto/bn/asm/x86_64-mont.pl 259fb8d7f40c0dba46920b1f169d5b37de03b0fda645463d19e3ae2b56de851d crypto/bn/asm/x86_64-mont5.pl 0ea8185a037a2951bb3d1e590bbbdeac305176d5e618f3e43a04c09733a9de34 crypto/bn/bn_add.c 759c2b9df808b3562fe8b0c7778dbadbf35f261e14fc2d5090d18c35b4181760 crypto/bn/bn_asm.c 14bd5a35c05fcf454854b92fb30b356d7ac618c1eb699dd798f6ad2936d1f5ee crypto/bn/bn_blind.c 7b761d541e3b7f6a3f2b14a09b2b3836a079a845cf67a54db4853e3fd38277c6 crypto/bn/bn_const.c 58b587e20404efa408b31a88ba9c357059ced709bea78c07deb91df7b687db81 crypto/bn/bn_conv.c 2893b6d03d4850d09c15959941b0759bbb50d8c20e873bed088e7cde4e15a65a crypto/bn/bn_ctx.c d94295953ab91469fe2b9da2a542b8ea11ac38551ecde8f8202b7f645c2dea16 crypto/bn/bn_dh.c 74b63a4515894592b7241fb30b91b21510beaa3d397809e3d74bc9a73e879d18 crypto/bn/bn_div.c a29b8b7fa8460f11e50f880e3c3c9e0755b93889bcbb5476206c4d938a9c5735 crypto/bn/bn_exp.c ec2b6e3af6df473a23e7f1a8522f2554cb0eb5d34e3282458c4a66d242278434 crypto/bn/bn_exp2.c -1abab2cc5466b005b939d156e7d8664a4d42a191c9040dbb83941269d6844f0c crypto/bn/bn_gcd.c +baba7c8ae95af6aa36bc9f4be3a2eed33d500451e568ca4bfc6bc7cb48d4f7ea crypto/bn/bn_gcd.c 4d6cc7ed36978247a191df1eea0120f8ee97b639ba228793dabe5a8355a1a609 crypto/bn/bn_gf2m.c 081e8a6abc23599307dab3b1a92113a65e0bf8717cbc40c970c7469350bc4581 crypto/bn/bn_intern.c 602ed46fbfe12c899dfb7d9d99ff0dbfff96b454fce3cd02817f3e2488dd9192 crypto/bn/bn_kron.c bf73a1788a92142963177fb698bc518af9981bbf0ad9784701fbb2462ca10607 crypto/bn/bn_lib.c d5beb9fbac2ff5dc3ccbdfa4d1aabca7225c778cff4e3b05b6d6c63e182637f5 crypto/bn/bn_local.h 07247dc2ccc55f3be525baed92fd20031bbaa80fd0bc56155e80ee0da3fc943d crypto/bn/bn_mod.c f60f3d49b183b04bcdf9b82f7c961b8c1bcb00e68a2c1166fe9edd95a783356e crypto/bn/bn_mont.c 2da73a76b746a47d8cf8ec8b3e0708c2a34e810abde4b4f1241a49e7f5bb2b60 crypto/bn/bn_mpi.c 76982b18b0803d59b33168b260677e7412970757d3b9513de5c80025290f211d crypto/bn/bn_mul.c 1f65ad369352d51af1a75eccf598cb497b400ebd86252f5ca8aac54bbb3cc7bd crypto/bn/bn_nist.c c6760a724d696b7209f0a71f8483fabcf4f081f7e93e2628284c32ef78f69365 crypto/bn/bn_prime.c c56ad3073108a0de21c5820a48beae2bccdbf5aa8075ec21738878222eb9adc3 crypto/bn/bn_prime.h 628419eabdb88b265823e43a7a1c88fdfecef79771180836f6089050dc9eadb1 crypto/bn/bn_rand.c 4df8f204c8a06de2b4395be613ca0b9943613c523586e2005876d5c7bb891c75 crypto/bn/bn_recp.c a5c5c9f99961a5a7f22a3dcdce964c8a330f822be17f08652223a20fed747d0a crypto/bn/bn_rsa_fips186_4.c 704b0b4723e5c9e9bae5f3e35f9ae8ae8dca3383929e954de9e5169845abfdb2 crypto/bn/bn_shift.c 622e90766b29e0d25f46474429aebda8eba2246835b9e85dc26da7cdbd49334f crypto/bn/bn_sqr.c 42c8ce944c889abcfcf089d0ad2744b7587696d8d7785efa91b3f7ec53dc062a crypto/bn/bn_sqrt.c 24e62baa56e02f2db6454e10168b7c7fa7638db9221b9acda1803d43f38f36e0 crypto/bn/bn_word.c be27115efd36f0077a3ec26b1ff1f586b0b8969ba05d8ffa34b2ff4badf227bf crypto/bn/rsaz_exp.c c4d64da1cdc732ea918fccd6a7bb2746b03365dd26f7ba1e74e08c307ca4c58e crypto/bn/rsaz_exp.h 5b82cb8dbf3087c2e671871cb0a92e4039223a51af533a2ee996f3bfd47453a7 crypto/bn/rsaz_exp_x2.c 834db8ff36006e5cb53e09ca6c44290124bd23692f4341ea6563b66fcade4cea crypto/bsearch.c c39334b70e1394e43f378ae8d31b6e6dc125e4d9181e6536d38e649c4eaadb75 crypto/buffer/buffer.c 5f43844b5d8665de9ab895f93599150a327d73ec2674bbf7d7c512d30163022d crypto/c64xpluscpuid.pl 0e1a41a2d81b5765bca3df448f60bf1fad91e485fe89dd65a7300ffc419e316d crypto/cmac/cmac.c ff9be205d6d7ff00b0e64508f0eb8d9ec0415fbabc0948d26e308212b3f7b2d8 crypto/context.c c309d81ea991ddf5be4337afad2fd132169f7443c76f863349d3f3c82f3374e4 crypto/core_algorithm.c f0fd9eb38bf7f196bbb4d26ce8fdf86d0a4f9db219157e66b2c0ffefb4f42005 crypto/core_fetch.c 799c84d224639c6760c5c28e0e287500a973ca6d0c3d7c1bdcd61b0da4018b3c crypto/core_namemap.c 469e2f53b5f76cd487a60d3d4c44c8fc3a6c4d08405597ba664661ba485508d3 crypto/cpuid.c 71f0fff881eb4c5505fb17662f0ea4bbff24c6858c045a013ad8f786b07da5c4 crypto/cryptlib.c 66dbfc58916709d5a6913777346083247942a8d9458ee9b2bf443f0ea4988d64 crypto/ctype.c 51e56541daea6d4a26d5bae2ea458414063bf08b045bab8df370f6695903e0a5 crypto/der_writer.c fea3ba4225df97aee90690adf387625b746d8edfdc5af2357ee65151a3d236ac crypto/des/des_enc.c 4971cdc016ee262d81e31f96c1617a33a63c0d90139e440c2ff32a368ee07bbd crypto/des/des_local.h eeef5722ad56bf1af2ff71681bcc8b8525bc7077e973c98cee920ce9bcc66c81 crypto/des/ecb3_enc.c 04d4cc355200b57f1e7d265a2cebdf094df1eb6e96621b533adddc3d60d31fbe crypto/des/fcrypt_b.c 499513b3ad386fe694c4e04b3c8a9fd4c4e18fc44bb6c4f94d6bf2d9362a3a5a crypto/des/ncbc_enc.c 61926e30dd940616e80936d1c94c5f522daf0d475fb3a40a9e589e78f322901e crypto/des/set_key.c 8344811b14d151f6cd40a7bc45c8f4a1106252b119c1d5e6a589a023f39b107d crypto/des/spr.h 816472a54c273906d0a2b58650e0b9d28cc2c8023d120f0d77160f1fe34c4ca3 crypto/dh/dh_backend.c -d2d0569bea2598bd405f23b60e5283a6ce353f1145a25ff8f28cf15711743156 crypto/dh/dh_check.c +fcbfe5acb73e1b4094efec56a754b803d2c1a53644c78cf6a73ae868e3f3886d crypto/dh/dh_check.c 7838e9a35870b0fbcba0aff2f52a2439f64d026e9922bce6e5978c2f22c51120 crypto/dh/dh_gen.c 6b17861887b2535159b9e6ca4f927767dad3e71b6e8be50055bc784f78e92d64 crypto/dh/dh_group_params.c a5cf5cb464b40f1bc5457dc2a6f2c5ec0f050196603cd2ba7037a23ab64adbf7 crypto/dh/dh_kdf.c -0afa7dd237f9b21b0cfb0de10505facd57eb07ded905d888d43a1de2356d4002 crypto/dh/dh_key.c -b0046b2c4e1d74ff4e93f2486a00f63728909b8a75cbdd29b9100e607f97995c crypto/dh/dh_lib.c +9e61a0b5017d835b348b15e93760c42d8d899ffae4251455c7b3085cfd25294c crypto/dh/dh_key.c +92345c259ea2a8c09e6d6b069d0942bd6ca4642231580f3e8148ae7a832a1115 crypto/dh/dh_lib.c 8300775d88db0a1aa26a77eb49d6c4f7252e7fee69e1440de4c40edadc9da044 crypto/dh/dh_local.h bbcf4fc3067ac462a27d7277973180b7dc140df9262a686c7fbe4318ca01f7b8 crypto/dsa/dsa_backend.c -b9c5992089203123c3fae46e39bb4d05e19854087bca7a30ad1f82a3505deec7 crypto/dsa/dsa_check.c +d7e0d87494e3b3f0898a56785a219e87a2ce14416393ec32d8c0b5f539c7bdbf crypto/dsa/dsa_check.c ae727bf6319eb57e682de35d75ea357921987953b3688365c710e7fba51c7c58 crypto/dsa/dsa_gen.c b1de1624e590dbf76f76953802ff162cc8de7c5e2eaba897313c866424d6902b crypto/dsa/dsa_key.c -9e436a2e0867920c3a5ac58bc14300cad4ab2c4c8fe5e40b355dfd21bfdfe146 crypto/dsa/dsa_lib.c +9f4837c5abe53613a2dc1c5db81d073d4f42bd28b6a2d1e93a2b350d8e25d52a crypto/dsa/dsa_lib.c f4d52d3897219786c6046bf76abb2f174655c584caa50272bf5d281720df5022 crypto/dsa/dsa_local.h -38062c6eebdb2f88fa0c6592837a96a49de2ae520d3ad483a3e02921c8adb094 crypto/dsa/dsa_ossl.c +c5c252f205482a71efeabe226d51a1c541a6ba2dfa9b8b8a70901087a9dc1667 crypto/dsa/dsa_ossl.c d612fd05ff98816ba6cf37f84c0e31443ad9d840ed587a7ab2066027da390325 crypto/dsa/dsa_sign.c 53fa10cc87ac63e35df661882852dc46ae68e6fee83b842f1aeefe00b8900ee1 crypto/dsa/dsa_vrf.c d9722ad8c6b6e209865a921f3cda831d09bf54a55cacd1edd9802edb6559190a crypto/ec/asm/ecp_nistp521-ppc64.pl 78ad06b88fcc8689a3a846b82f9ee01546e5734acd1bccf2494e523b71dc74d1 crypto/ec/asm/ecp_nistz256-armv4.pl 4617351d2de4d0b2abfd358c58050cee00702d0b4c1acca09312ec870e351c7d crypto/ec/asm/ecp_nistz256-armv8.pl 3715ddd921425f3018741037f01455ed26a840ace08691a800708170a66cf4d2 crypto/ec/asm/ecp_nistz256-ppc64.pl cfe7e75a2fddc87a7251684469a8808b9da82b2f5725eafad5806920f89932bd crypto/ec/asm/ecp_nistz256-sparcv9.pl 922725c4761cfa567af6ed9ecab04f2c7729ae2595f2fc0fa46dc67879dc87b0 crypto/ec/asm/ecp_nistz256-x86.pl ac327475c7ec828d11aa05628b4e3b81ec3b1400f30fe7bec01daf3cf71f2dc9 crypto/ec/asm/ecp_nistz256-x86_64.pl cc727533130f5f1a29229929b3d4e8454585d647be25d6344f3c6a0240998368 crypto/ec/asm/x25519-ppc64.pl ee897e230964511baa0d1bf95fb938312407a40a88ebe01476879c2763e5f732 crypto/ec/asm/x25519-x86_64.pl 340336e01aa04fcde9bfd56536f90c9bc0ad56a002b6cfa321a1e421f1e93ceb crypto/ec/curve25519.c 9a95ec8366154bb20aeb24f4767a8cbb9953ca0380708eb2f39caca6078cd59e crypto/ec/curve448/arch_32/f_impl32.c 063dac1e4a9573c47532123e9e03e3532a7473cc3e146521ba9ec6f486ddf3b1 crypto/ec/curve448/arch_64/arch_intrinsics.h 43423b7ee85a5c740c1d81499ee06f4a17732c7731a598e7429d5e402ee77cf4 crypto/ec/curve448/arch_64/f_impl.h 1689097ae10e4982a8cbe50c2f6eddb03c83436f331f0b67edb98d6b58adc962 crypto/ec/curve448/arch_64/f_impl64.c 9b408ec0d43f3b6d714ef5963147e2c2abaddc88633db7dd759193d3c56ed727 crypto/ec/curve448/curve448.c 3c12d90e3fdd59b5d32d63186f1a6f15c75eb73f5035b844a2054356a9459780 crypto/ec/curve448/curve448_local.h 178fb9863c33174b633c2e7607160b1bedb506d66cc06d53382d87431441f306 crypto/ec/curve448/curve448_tables.c f30e13bba5a136ab9ba5225c98b9b94c2cd73fb3aef60f9dcde3cd471cfa1ca4 crypto/ec/curve448/curve448utils.h 4a45e7828831fbe9f282f933cda54b12cd393ec9bffe5c0ace8e4d1c4d5d6358 crypto/ec/curve448/ed448.h a1211ed3991af967c728b9f6d0774b9ea098d43cef0631ff88984a2580d2ac4f crypto/ec/curve448/eddsa.c 450946e1cccb81e45e5601b6154e2311666b06e294aab926369995af06d1a328 crypto/ec/curve448/f_generic.c f6447921a0031fa5beddedd298e82096fb3fdb189b712fab328b61f6beae0c23 crypto/ec/curve448/field.h 2ad8331e893b5db33198e27603891587686c0dfdab29706dc52a7097c5d6f219 crypto/ec/curve448/point_448.h 1ff6e467d72530c71d21c310180d04a24f0a9cb41168fba94b43309ecdda3888 crypto/ec/curve448/scalar.c 3052a044afae2e91b677542fc8b34b3ec9d033e0c6562b0d43098cfb34ab3c9d crypto/ec/curve448/word.h ae1637d89287c9d22a34bdc0d67f6e01262a2f8dcef9b61369dba8c334f5a80d crypto/ec/ec2_oct.c 6bbbf570ce31f5b579f7e03ec9f8a774663c7c1eb5e475bd31f8fee94a021ffc crypto/ec/ec2_smpl.c 2a71bd8dbe4f427c117d990581709a4ddce07fa8e530794b5a9574fef7c48a0c crypto/ec/ec_asn1.c 69b1b3acb4295f5fff961b339e8ace913176ca63fcedf4af0da4c27171f24f94 crypto/ec/ec_backend.c 86e2becf9b3870979e2abefa1bd318e1a31820d275e2b50e03b17fc287abb20a crypto/ec/ec_check.c 265f911b9d4aada326a2d52cd8a589b556935c8b641598dcd36c6f85d29ce655 crypto/ec/ec_curve.c 8cfd0dcfb5acbf6105691a2d5e2826dba1ff3906707bc9dd6ff9bffcc306468f crypto/ec/ec_cvt.c 95ce53663ab8a1d05bd6f4999f30113e1edce771fb6d218a772fe02de7bdaf4d crypto/ec/ec_key.c 7e40fc646863e0675bbb90f075b809f61bdf0600d8095c8366858d9533ab7700 crypto/ec/ec_kmeth.c bbd6f618c3dfe425ce0ba1c6710fe59418130e06351881162a590475e6438c44 crypto/ec/ec_lib.c a8a4690e42b4af60aad822aa8b16196df337906af53ea4db926707f7b596ff27 crypto/ec/ec_local.h fa901b996eb0e460359cd470843bdb03af7a77a2f1136c5e1d30daef70f3e4d2 crypto/ec/ec_mult.c 129c6b42417bfcf582f4a959cfd65433e6f85b158274f4fa38f9c62615ac9166 crypto/ec/ec_oct.c c7fba2f2c33f67dafa23caef8c3abd12f5336274a9a07d412b83be0366969ee6 crypto/ec/ecdh_kdf.c b2cf8f052a5716137da7b0e857ed7a5df5fb513b6d14534199a05e32f2b5a866 crypto/ec/ecdh_ossl.c 099f7836a31643c58bda3829090ea81fe3d5acaa4c6f7b145d8355a4293d0ccc crypto/ec/ecdsa_ossl.c b6baa42b16e8df69a12e0ab101033100cddc808ec2682ba1574373e6ec86ae93 crypto/ec/ecdsa_sign.c f686cea8c8a3259d95c1e6142813d9da47b6d624c62f26c7e4a16d5607cddb35 crypto/ec/ecdsa_vrf.c 141cfc1459214555b623517a054a9e8d5e4065a11301237b7247be2c6f397a0a crypto/ec/ecp_mont.c 13b30f34aeeb0c98747239bfe91b5f0f14e91b2c1f11db62ebb5950c7219daa0 crypto/ec/ecp_nist.c f288c23b6f83740956886b2303c64d5a3098c98b530859c3bb4b698c01c1643b crypto/ec/ecp_nistz256.c 51cb98e7e9c241e33261589f0d74103238baaa850e333c61ff1da360e127518a crypto/ec/ecp_oct.c b4b7c683279454ba41438f50a015cb63ef056ccb9be0168918dfbae00313dc68 crypto/ec/ecp_smpl.c 2096e13aa2fbcb0d4b10faca3e3f5359cf66098b0397a6d74c6fca14f5dee659 crypto/ec/ecx_backend.c 5ee19c357c318b2948ff5d9118a626a6207af2b2eade7d8536051d4a522668d3 crypto/ec/ecx_backend.h 22c44f561ab42d1bd7fd3a3c538ebaba375a704f98056b035e7949d73963c580 crypto/ec/ecx_key.c 28abc295dad8888b5482eb61d31cd78dd80545ecb67dc6f9446a36deb8c40a5e crypto/evp/asymcipher.c 0e75a058dcbbb62cfe39fec6c4a85385dc1a8fce794e4278ce6cebb29763b82b crypto/evp/dh_support.c 1af3872164b4a4757bc7896a24b4d2f8eb2cfb4cba0d872a93db69975693e0a6 crypto/evp/digest.c 838277f228cd3025cf95a9cd435e5606ad1fb5d207bbb057aa29892e6a657c55 crypto/evp/ec_support.c -1c3d1b1f800b1f1f5adb1fdbdd67cdf37ca7ea93b264d1468c72a63c140873ce crypto/evp/evp_enc.c +61df3942752307b7006f09d7628348a0cc9e5555469a3a8862349067a52824b7 crypto/evp/evp_enc.c 7f10367f9b6191c4a8c01784130d26b2d778485a41cdac5fa17c9a1c4096f132 crypto/evp/evp_fetch.c ebe32b2895f7f9767710674352c8949efe93b4bbb5e7b71c27bb5d1822339b46 crypto/evp/evp_lib.c 78f07bf50b6999611a4e9414ab3a20b219b0ab29ca2bd05002d6919a3f67b8eb crypto/evp/evp_local.h 117e679d49d2ae87e49d3c942ff0ce768959e8b9713f84a99025cabba462ccd5 crypto/evp/evp_rand.c 2a128617ec0178e9eeacbe41d75a5530755f41ea524cd124607543cf73456a0c crypto/evp/evp_utils.c ca8c6cfd30efd53f2e5d1f19bcf09a3a3d0dff6d8947c3943d07a3f4b354aa86 crypto/evp/exchange.c 9e25042581b73e295c059c6217f3ecf809134d518eb79b1b67f34e3ca9145677 crypto/evp/kdf_lib.c 1d72f5506984df1df8606e8c7045f041cf517223e2e1b50c4da8ba8bf1c6c186 crypto/evp/kdf_meth.c 5179624b8e03615dc9caedc9ec16d094fa081495613dd552d71c2c39475bcd83 crypto/evp/kem.c 5016dd7ef8b4cf7e9ea8465c18d1daa4c8808cb589261cf236058ee75bc868d7 crypto/evp/keymgmt_lib.c 46ffdc73f8a7fc314dc8988f2751a6e9f9784719f4f162dc4be2450b65b55261 crypto/evp/keymgmt_meth.c e1a052839b8b70dca20dbac1282d61abd1c415bf4fb6afb56b811e8770d8a2e1 crypto/evp/m_sigver.c 4290c95f63b43688a8da57690d122add5161a6811f9753da1444d28f46739961 crypto/evp/mac_lib.c e7e8eb5683cd3fbd409df888020dc353b65ac291361829cc4131d5bc86c9fcb3 crypto/evp/mac_meth.c 546d83abecf8973e2d872102a03bde5a46552909fa9e7d1402e1464a27453801 crypto/evp/p_lib.c 3b4228b92eebd04616ecc3ee58684095313dd5ffd1b43cf698a7d6c202cb4622 crypto/evp/pmeth_check.c 1f0e9e94e9b0ad322956521b438b78d44cfcd8eb974e8921d05f9e21ba1c05cf crypto/evp/pmeth_gn.c 76511fba789089a50ef87774817a5482c33633a76a94ecf7b6e8eb915585575d crypto/evp/pmeth_lib.c 4b2dbddf0f9ceed34c3822347138be754fb194febca1c21c46bcc3a5cce33674 crypto/evp/signature.c -b06cb8fd4bd95aae1f66e1e145269c82169257f1a60ef0f78f80a3d4c5131fac crypto/ex_data.c +f2acfb82aac20251d05a9c252cc6c282bd44e43feac4ac2e0faf68b9a38aef57 crypto/ex_data.c 1c8389c5d49616d491978f0f2b2a54ba82d805ec41c8f75c67853216953cf46a crypto/ffc/ffc_backend.c a12af33e605315cdddd6d759e70cd9632f0f33682b9aa7103ed1ecd354fc7e55 crypto/ffc/ffc_dh.c 854378f57707e31ad02cca6eec94369f91f327288d3665713e249c12f7b13211 crypto/ffc/ffc_key_generate.c -2695c9c8ad9193a8c1ab53d5d09712d50d12c91eb8d62e8a15cbc78f327afe84 crypto/ffc/ffc_key_validate.c +4e973d956d4ec2087994de8e963be1a512da1441f22e6e7b9cd7ee536e3ff834 crypto/ffc/ffc_key_validate.c 8b72d5a7452b2c15aec6d20027053a83f7df89d49a3b6cfedd77e2b1a29e9fc1 crypto/ffc/ffc_params.c 1a1d227f9a0f427d2ec93bc646c726c9cd49a84a343b4aff0c9c744fa6df05a9 crypto/ffc/ffc_params_generate.c 73dac805abab36cd9df53a421221c71d06a366a4ce479fa788be777f11b47159 crypto/ffc/ffc_params_validate.c 0a4fc92e408b0562cf95c480df93a9907a318a2c92356642903a5d50ed04fd88 crypto/hmac/hmac.c 0395c1b0834f2f4a0ca1756385f4dc1a4ef6fb925b2db3743df7f57256c5166f crypto/hmac/hmac_local.h 0e2d6129504d15ffaf5baa63158ccec0e4b6193a8275333956d8f868ef35127e crypto/ia64cpuid.S f897493b50f4e9dd4cacb2a7accda6683c10ece602641874cdff1dac7128a751 crypto/initthread.c -5482c47c266523129980302426d25839fda662f1544f4b684707e6b272a952c9 crypto/lhash/lhash.c +7290d8d7ec31a98b17618f218d4f27b393501c7606c814a43db8af1975ad1d10 crypto/lhash/lhash.c 5d49ce00fc06df1b64cbc139ef45c71e0faf08a33f966bc608c82d574521a49e crypto/lhash/lhash_local.h f866aafae928db1b439ac950dc90744a2397dfe222672fe68b3798396190c8b0 crypto/mem_clr.c e14f48d4112c0efe3826b4aa390cc24045a85298cc551ec7f3f36ac4236d7d81 crypto/modes/asm/aes-gcm-armv8_64.pl 1d686af304f94743038f916125effcb51790c025f3165d8d37b526bbeee781f0 crypto/modes/asm/aesni-gcm-x86_64.pl c2e874a8deb418b5d8c935b2e256370566a5150e040c9fa008cdb5b463c26904 crypto/modes/asm/ghash-alpha.pl 6bc7d63569c73d7020ede481f2de05221ac92403c7cc11e7263ada7644f6aa9b crypto/modes/asm/ghash-armv4.pl 097975df63370de7ebea012d17de14fc1f361fb83acf03b432a99ae7d5bceb24 crypto/modes/asm/ghash-c64xplus.pl fdde3bc48b37790c6e0006014da71e7a831bbb4fdbfcda2d01dbe0ceb0ba88fa crypto/modes/asm/ghash-ia64.pl e472d73d06933667a51a0af973479993eed333c71b43af03095450acb36dbeb4 crypto/modes/asm/ghash-parisc.pl 6fb4332ac88113a20915ad4de1931ef88b0114b5379b16e1d967820e1229fbb0 crypto/modes/asm/ghash-s390x.pl 6af1a05981e1d41e4dea51e58938360e3abc4a4f58e179908242466d032b1a8a crypto/modes/asm/ghash-sparcv9.pl 26f55a57e77f774d17dfba93d757f78edfa3a03f68a71ffa37ccf3bfc468b1e2 crypto/modes/asm/ghash-x86.pl 72744131007d2389c09665a59a862f5f6bb61b64bd3456e9b400985cb56586b8 crypto/modes/asm/ghash-x86_64.pl a4e9f2e496bd9362b17a1b5989aa4682647cefcff6117f0607122a9e11a9dfd9 crypto/modes/asm/ghashp8-ppc.pl -0029b5beb1d4cd4c5ad47164c23f3e7c9d1eaff66ef54af025ee26795b11a1c7 crypto/modes/asm/ghashv8-armx.pl +69a13f423ca74c22543900c14aef4a848e3bc75504b65d2f51c6903aebcc17a7 crypto/modes/asm/ghashv8-armx.pl 65112dfe63cd59487e7bdb1706b44acfcf48ecede12cc3ae51daa5b661f41f06 crypto/modes/cbc128.c 1611e73dc1e01b5c2201f51756a7405b7673aa0bb872e2957d1ec80c3530486f crypto/modes/ccm128.c d8c2f256532a4b94db6d03aea5cb609cccc938069f644b2fc77c5015648d148d crypto/modes/cfb128.c af1c034152d82b29cb7c938c8516cfd136b62bac0908c1d40eb50790d23b288c crypto/modes/ctr128.c 2413852b46ee90bcbb711c0d4fb79fc6b0cac1f837b4df4896a0003935d4211a crypto/modes/gcm128.c bdf25257b15eca206be4d950d2dd807ca5f058f91f54edbd7a0d312ed83eef8e crypto/modes/ofb128.c e55a816c356b2d526bc6e40c8b81afa02576e4d44c7d7b6bbe444fb8b01aad41 crypto/modes/wrap128.c 608a04f387be2a509b4d4ad414b7015ab833e56b85020e692e193160f36883a2 crypto/modes/xts128.c 8aa2504f84a0637b5122f0c963c9d82773ba248bad972ab92be7169995d162b5 crypto/o_str.c 8ddbbdf43131c10dcd4428aef0eff2b1e98b0410accada0fad41a4925868beef crypto/packet.c a20bfd927d69737c86ca95d3cf636afa8cefd8fe23412d1a3897644a0da21211 crypto/param_build.c -c2fe815fb3fd5efe9a6544cae55f9469063a0f6fb728361737b927f6182ae0bb crypto/param_build_set.c +2a0f272dd553b698e8c6fa57962694ebd6064cb03fe26a60df529205568d315d crypto/param_build_set.c 0e4a5388a92fabbe5a540176c0b4c5ce258b78dc9168ecc2e805352a06aaf0ba crypto/params.c 4fda13f6af05d80b0ab89ec4f5813c274a21a9b4565be958a02d006236cef05c crypto/params_dup.c a0097ff2da8955fe15ba204cb54f3fd48a06f846e2b9826f507b26acf65715c3 crypto/params_from_text.c 97cb7414dc2f165d5849ee3b46cdfff0afb067729435d9c01a747e0ca41e230c crypto/ppccap.c 3ca43596a7528dec8ff9d1a3cd0d68b62640f84b1d6a8b5e4842cfd0be1133ad crypto/ppccpuid.pl b4d34272a0bd1fbe6562022bf7ea6259b6a5a021a48222d415be47ef5ef2a905 crypto/property/defn_cache.c 3c4ade2fed4605e374d85ec1134a98da34e7124f89f44b81a754e8cfe81f14ba crypto/property/property.c 66da4f28d408133fb544b14aeb9ad4913e7c5c67e2826e53f0dc5bf4d8fada26 crypto/property/property_local.h -921305e62749aec22da4843738bee3448b61e7e30d5309beddc7141ad07a8004 crypto/property/property_parse.c +099407e68e705f1458b701b9336f633565fc0843355fedf1ec83794349548a51 crypto/property/property_parse.c a7cefda6a117550e2c76e0f307565ce1e11640b11ba10c80e469a837fd1212a3 crypto/property/property_query.c 065698c8d88a5facc0cbc02a3bd0c642c94687a8c5dd79901c942138b406067d crypto/property/property_string.c 0ba5d0297837940c972224c97cbbf3ea4a723c1eed9ce1112538c9bb26208639 crypto/provider_core.c d0af10d4091b2032aac1b7db80f8c2e14fa7176592716b25b9437ab6b53c0a89 crypto/provider_local.h 5ba2e1c74ddcd0453d02e32612299d1eef18eff8493a7606c15d0dc3738ad1d9 crypto/provider_predefined.c a5a4472636b8b0095ad8d4acd37e275ad79da1a67ecff7b7b5c3e46c9ebc65b7 crypto/rand/rand_lib.c fd03b9bb2c23470fa40880ed3bf9847bb17d50592101a78c0ad7a0f121209788 crypto/rand/rand_local.h f0c8792a99132e0b9c027cfa7370f45594a115934cdc9e8f23bdd64abecaf7fd crypto/rsa/rsa_acvp_test_params.c -9e7dd6fc91d3266d4aa4f0f41b7986381122b7d98114e63ebf04c5ee298b5fda crypto/rsa/rsa_backend.c +5834d7c518ad53ea0dd3db811c0e51568c81cc6c117012030101d29003d0725c crypto/rsa/rsa_backend.c 38a102cd1da1f6ca5a46e6a22f018237964336274385f5c70cbedcaa6997647e crypto/rsa/rsa_chk.c e32cfa04221a2a3ea33f7bcb93ee51b84cbeba97e94c1fbf6e420b24f97fc9ce crypto/rsa/rsa_crpt.c e995da1c2e5007bd7f5907f369fe45ed15f4e657143a85078c755bd5e6863d0b crypto/rsa/rsa_gen.c -74ed75d1d8e0844800504a137bfd81c3dbcb6c4bd58b5d5fe9d0a362092b6e88 crypto/rsa/rsa_lib.c +f2222f270e57559537d3da8abbeb1390bc5376b73dae59d536af6e73eb48bba0 crypto/rsa/rsa_lib.c a65e85be5269d8cb88e86b3413c978fa8994419a671092cbf104ff1a08fda23b crypto/rsa/rsa_local.h cf0b75cd54b61b9b9a290ef18d0ddce9fb26a029a54eb3f720d9b25188440f00 crypto/rsa/rsa_mp_names.c 5c60f6e05db82e13178d805deb1947b8eee4a905e6e77523d3b288da70a46bb5 crypto/rsa/rsa_none.c 33de2accc3af530fd0a4758eb83d5e1d994bf49bac4512b01387dbae656e1a7d crypto/rsa/rsa_oaep.c e05fcad237b7e4e7842ad6e142789fe25d060247283c337c78703be6ecc31ed9 crypto/rsa/rsa_ossl.c be3f39c1fcb777d6c0122061f9ef735d10a6bee95d67fcc1ca6ae2a664022d2b crypto/rsa/rsa_pk1.c 174a42e156be48927fe6d6bf0d95575619b8e643a99761275bff933bc3449722 crypto/rsa/rsa_pss.c bf6d300b7e7e9e512a47c5bd1f8713806ae3033a140d83dfae4a16ad58d11170 crypto/rsa/rsa_schemes.c f01af62704dbf9457e2669c3e7c1d4d740f0388faa49df93611b987a8aa2bf11 crypto/rsa/rsa_sign.c 740c022caff3b2487c5838b581cdddcc7de2ceabb504aad72dc0dd70a67bf7cf crypto/rsa/rsa_sp800_56b_check.c 3aba73dacebb046faf8d09dc279149b52c629004b524ec33e6d81c8ad0bc31a8 crypto/rsa/rsa_sp800_56b_gen.c 1c1c2aeeb18bf1d69e8f134315b7e50d8f43d30eb1aa5bf42983eec9136a2fdc crypto/rsa/rsa_x931.c 0acbebed48f6242d595c21e3c1ad69da0daa960d62062e8970209deda144f337 crypto/s390xcap.c 22205848cfb55116ebf999dced8331b575886a609ce29e6886e6267b2310c337 crypto/s390xcpuid.pl 5fa59240ca885cbc0c1cd026934b226d44fc9c3fdf0c2e7e3a7bd7f4963ca2e5 crypto/self_test_core.c 05c533fde7fdba0c76103e97d881b7224c8427451b453e2f6413552996063e31 crypto/sha/asm/keccak1600-armv4.pl ca3b2b654f9a8c4bc2fa2538c1f19d17acd4a6b9e0df6a4b81df04efa697e67e crypto/sha/asm/keccak1600-armv8.pl 12b7acce2fba0bc0e1ca07842ec84be6a022f141c86e077abb42c864af1d8d9c crypto/sha/asm/keccak1600-avx2.pl faf0cccb685d5abc807e08db194f847c67b940da2fc3c235c210dc31d73a5334 crypto/sha/asm/keccak1600-avx512.pl be1e7dd9998e3f31cfa6e1b17bc198aeec584a8b76820e38f71d51b05f8a9f2a crypto/sha/asm/keccak1600-avx512vl.pl 33bdcc6f7668460c3bdf779633e43bfad62b937042a73acb007b462fc5b0a034 crypto/sha/asm/keccak1600-c64x.pl 09fc831dd39bd90a701e9b16d9e9987cc215252a22e1e0355f5da6c495fca35a crypto/sha/asm/keccak1600-mmx.pl ce4a58129e5ee3ac4c9dfec5ecc010440570ebf7bf869e3e9977f2121a64b27a crypto/sha/asm/keccak1600-ppc64.pl a859fc8cb073b2d0012a93f3155a75fb6eb677441462b0de4f8cf8df1445e970 crypto/sha/asm/keccak1600-s390x.pl 618dcd4891b4064d3b8aa6dcd74bea7ef55f4962a64957b05a05448f6e3e0f17 crypto/sha/asm/keccak1600-x86_64.pl 831b8b02ab25d78ba6300ce960d96c13439bfba5844e13061e19c4e25cbacc3d crypto/sha/asm/keccak1600p8-ppc.pl 75d832db9bf0e98e7a5c522169060a6dd276c5118cfb297fc3f1111f55cd4007 crypto/sha/asm/sha1-586.pl c96e87d4f5311cd73bbdf499acc03418588be12426d878e157dd67e0099e0219 crypto/sha/asm/sha1-alpha.pl 4ba6d1c7f12fe76bf39babea966f0a4b7f8769e0c0510cbfc2c46a65dd62d45c crypto/sha/asm/sha1-armv4-large.pl efc69cb0d867b7fac6b3fa8985c343d1f984d552bc8e75bbbbace0adf9ee5f15 crypto/sha/asm/sha1-armv8.pl 11d332b4e058e9fa418d6633316d2e9f9bf520a08b2d933e877bdf38b2edefcf crypto/sha/asm/sha1-c64xplus.pl 32ff0e701a7b8f25bcfe8477b20795de54f536527bd87d3ce694fd9aaae356d4 crypto/sha/asm/sha1-ia64.pl 471c27efca685b2a82ad7fefe329ca54172df9f49b9785da6d706b913b75e693 crypto/sha/asm/sha1-mb-x86_64.pl 0f5c63cf09e950d1b488935ab3b5562e3e9d5cd1a563fb88a41e3dae90a35e6d crypto/sha/asm/sha1-mips.pl b5ffd7b6dbb04c05de7efa2945adb67ea845e7e61a3bf163a532f7b6acdf4267 crypto/sha/asm/sha1-parisc.pl 482cd23ca6ec38d6f62b90c68f9f20643579c50f2c0fbb0dab1c10a0e35efe77 crypto/sha/asm/sha1-ppc.pl 28cf69efd53d7a5a8c32e0f8db32c193f41b91faf44f5f59944334bc3f5aa337 crypto/sha/asm/sha1-s390x.pl 7fd355b412ddfa1c510e0ba3284f75b1c0d621b6db2ecb1d2a935d5cdb706628 crypto/sha/asm/sha1-sparcv9.pl 24554e68b0e7b7db7b635ff149549015f623ca0bcd9ae90439586a2076f6ae80 crypto/sha/asm/sha1-sparcv9a.pl 74d197cdd72400cabbff7e173f72c8976723081508b095dc995e8cd1abf3daa6 crypto/sha/asm/sha1-thumb.pl a59a86293e28f5600609dc8af2b39c5285580ae8636520990b000eeeb67bb889 crypto/sha/asm/sha1-x86_64.pl c099059ef107f548ea2c2bab64a4eb8c277070ce6d74c4d32bb9808dc19c5fa3 crypto/sha/asm/sha256-586.pl b9cee5c5a283f61f601d2dba68a7a76e7aba10bfafffc1a5c4987f9c0aa6f87d crypto/sha/asm/sha256-armv4.pl 93ddc97651ee3e779144a3c6b3e46a1bc4aa81e75cd7b9df068a2aef8743d25f crypto/sha/asm/sha256-c64xplus.pl 8be5c5d69733ecb16774aa8410b4bcb3623a9f060d2be103d8aa67bf6e4c5843 crypto/sha/asm/sha256-mb-x86_64.pl dd82e1311703abb019975fc7b61fb87d67e1ed916dddd065aced051e851114b9 crypto/sha/asm/sha512-586.pl 8d84164f3cfd53290c0c14bb5655510b7a9238857866328c0604d64b4e76fe21 crypto/sha/asm/sha512-armv4.pl dadacb6d66b160913bffb4e1a6c3e5f7be6509b26e2c099701d8d3fdb92c1be0 crypto/sha/asm/sha512-armv8.pl 6f548a088feae3b6faa179653ba449df9d3f5cda1e0561e5b5f120b32274d1eb crypto/sha/asm/sha512-c64xplus.pl 9fa54fbc34fd881f4b344374b9b4f8fb15b641424be7af9a31c71af89ae5d577 crypto/sha/asm/sha512-ia64.pl fb06844e7c3b014a58dccc8ec6020c71843cfdc5be08288bc7d204f0a840c474 crypto/sha/asm/sha512-mips.pl 11548f06d213947104a80898e000218ec0d6ff3f6913f6582de498476482ce9f crypto/sha/asm/sha512-parisc.pl 7c0c490ce6bb11a228853aecad5e164ce84e5bdabb8a6658ae7184782076c7d3 crypto/sha/asm/sha512-ppc.pl 38e0455fd6a2b93a7a5385379ca92bc6526585ca1eb4af365fac4c78f7285c72 crypto/sha/asm/sha512-s390x.pl 0611845c52091b0208dd41f22ddef9dd1e68d3d92fa4c4360738b840a6314de6 crypto/sha/asm/sha512-sparcv9.pl f64d16c1e5c3fa4a7969de494a8372127502171a517c14be7a1e3a43a7308699 crypto/sha/asm/sha512-x86_64.pl 8725cabb8d695c576619f19283b034074a3fa0f1c0be952a9dbe9793be15b907 crypto/sha/asm/sha512p8-ppc.pl 57f6cf54b1b5d2cac7a8f622b7b6bd1878f360fff3fa0f02352061c24162ebbb crypto/sha/keccak1600.c 306cacd3f86e5cacaca74c58ef862516515e5c0cafaff48636d537fd84f1c2fb crypto/sha/sha1dgst.c 4d8cf04f5806611e7586aab47fb28165ec1afb00168e2c9876bb36cb5c29bf8b crypto/sha/sha256.c 3d972a11be18bfbfcd45790028635d63548bfe0a2e45d2fc56b6051b759d22f0 crypto/sha/sha3.c 8038a5a97f826f519424db634be5b082b3f7eca3ccb89875ca40fa6bd7dfdcfd crypto/sha/sha512.c 6c6f0e6069ac98e407a5810b84deace2d1396d252c584703bcd154d1a015c3ea crypto/sha/sha_local.h 9ef5a01caccc2eb15f72e367d0424737040ac8018479bbbbce3d216c655765c2 crypto/sparccpuid.S 5056b14a55665ffa342a9a1bb32c1c36886add5d0819869193427f33cee028f7 crypto/sparcv9cap.c c50c584c55e56347bb43aca4b796b5344d70daece3061f586b79c871c21f5d1a crypto/sparse_array.c 8da78169fa8c09dc3c29c9bf1602b22e88c5eac4815e274ba1864c166e31584b crypto/stack/stack.c 7b4efa594d8d1f3ecbf4605cf54f72fb296a3b1d951bdc69e415aaa08f34e5c8 crypto/threads_lib.c a41ae93a755e2ec89b3cb5b4932e2b508fdda92ace2e025a2650a6da0e9e972c crypto/threads_none.c 3729e2bd36f945808b578e0d89fac0fcb3114e4fc9381614bcbd8a9869991716 crypto/threads_pthread.c 88423960f0414f6fd41fba4f4c67f9f7260c2741e4788adcd52493e895ec8027 crypto/threads_win.c fd6c27cf7c6b5449b17f2b725f4203c4c10207f1973db09fd41571efe5de08fd crypto/x86_64cpuid.pl bbec287bb9bf35379885f8f8998b7fd9e8fc22efee9e1b299109af0f33a7ee16 crypto/x86cpuid.pl 0a9c484f640d96e918921f57f592e82e99ccdbe35d3138d64b10c7af839e9a07 e_os.h 6f353dc7c8c4d8f24f7ffbf920668ccb224ebb5810805a7c80d96770cd858005 include/crypto/aes_platform.h 8c6f308c1ca774e6127e325c3b80511dbcdc99631f032694d8db53a5c02364ee include/crypto/asn1_dsa.h 8ce1b35c6924555ef316c7c51d6c27656869e6da7f513f45b7a7051579e3e54d include/crypto/bn.h 1c46818354d42bd1b1c4e5fdae9e019814936e775fd8c918ca49959c2a6416df include/crypto/bn_conf.h.in 7a43a4898fcc8446065e6c99249bcc14e475716e8c1d40d50408c0ab179520e6 include/crypto/bn_dh.h e69b2b20fb415e24b970941c84a62b752b5d0175bc68126e467f7cc970495504 include/crypto/cryptlib.h 6c72cfa9e59d276c1debcfd36a0aff277539b43d2272267147fad4165d72747c include/crypto/ctype.h 89693e0a7528a9574e1d2f80644b29e3b895d3684111dd07c18cc5bed28b45b7 include/crypto/des_platform.h daf508bb7ed5783f1c8c622f0c230e179244dd3f584e1223a19ab95930fbcb4f include/crypto/dh.h 20d99c9a740e4d7d67e23fa4ae4c6a39d114e486c66ad41b65d91a8244cd1dea include/crypto/dsa.h 2ea47c059e84ce9d14cc31f4faf45f64d631de9e2937aa1d7a83de5571c63574 include/crypto/ec.h edbfae8720502a4708983b60eac72aa04f031059f197ada31627cb5e72812858 include/crypto/ecx.h 9dab9af8b0a657fe5de46375b71aefcad7e98af272b69ed69c7c104e9e057414 include/crypto/evp.h bbe5e52d84e65449a13e42cd2d6adce59b8ed6e73d6950917aa77dc1f3f5dff6 include/crypto/lhash.h 162812058c69f65a824906193057cd3edeabc22f51a4220aea7cb9064379a9b6 include/crypto/md32_common.h f12bfc145290444bcc7bf408874bded348e742443c145b8b5bc70ae558d96c31 include/crypto/modes.h f326212c978576c5346c89ae0336c2428594494b54054f6045b1f1038bfbc004 include/crypto/rand.h 90930fc8788d6e04e57829346e0405293ac7a678c3cef23d0692c742e9586d09 include/crypto/rand_pool.h 306abf9d327a9e63fff2cdef730275abc4d2781254a032b1f370f3428eb5a2ef include/crypto/rsa.h 32f0149ab1d82fddbdfbbc44e3078b4a4cc6936d35187e0f8d02cc0bc19f2401 include/crypto/security_bits.h 0f743762f646656b5480648c05632575fe8acc7506460c63e0fcdf42cf20c08a include/crypto/sha.h 7676b02824b2d68df6bddeb251e9b8a8fa2e35a95dad9a7ebeca53f9ab8d2dad include/crypto/sparse_array.h 7ad02c7de77304c3b298deeb038ab2550cf8b2bce03021994477c6c43dbcf86e include/crypto/types.h 782a83d4e489fd865e2768a20bfa31e78c2071fd0ceeb9eb077276ae2bcc6590 include/internal/bio.h 92aacb3e49288f91b44f97e41933e88fe455706e1dd21a365683c2ab545db131 include/internal/constant_time.h c5bb97f654984130c8b44c09a52395bce0b22985d5dbc9c4d9377d86283f11f8 include/internal/core.h 0b572801dfb8a41cc239e3439f8097a0ad11bbdf5d54811d10ceba3175cf2f17 include/internal/cryptlib.h 9571cfd3d5666749084b354a6d65adee443deeb5713a58c098c7b03bc69dbc63 include/internal/deprecated.h 3325b895d15c0a6341f456a8d866a0f83e80fc8a31a01c34fcfd717715b33075 include/internal/der.h fd1722d6b79520ee4ac477280d5131eb1b744c3b422fd15f5e737ef966a97c3b include/internal/dso.h f144daebef828a5bd4416466257a50f06b894e0ce0adf1601aa381f34f25a9e7 include/internal/dsoerr.h 70d3e0d5a1bd8db58dcc57bea4d1c3ed816c735fe0e6b2f4b07073712d2dc5ef include/internal/endian.h 094b69aeb8f349cafa8865b577e253132088c25eabb61b910fab141e6f7d2929 include/internal/ffc.h 100053a1bad1a85a98c5b919cf81ace0ee147b2164732963e40474d7b5fbbb99 include/internal/namemap.h b02701592960eb4608bb83b297eed90184004828c7fc03ea81568062f347623d include/internal/nelem.h ae41a2fb41bf592bbb47e4855cf4efd9ef85fc11f910a7e195ceef78fb4321dc include/internal/numbers.h b89cca3b727d4526b459246de11e768a20333555bf3a9ed9a9b8beb2b565dc7f include/internal/packet.h dd7ddecf30bef3002313e6b776ce34d660931e783b2f6edacf64c7c6e729e688 include/internal/param_build_set.h d4ac19b28ea61f03383364cfad1e941cac44fc36787d80882c5b76ecc9d34e29 include/internal/property.h 727326afb3d33fdffdf26471e313f27892708318c0934089369e4b28267e2635 include/internal/propertyerr.h 6a899ef3e360c7144d84d3c3dbbd14aa457f5d38b83b13c0be7ec7f372076595 include/internal/provider.h 80d7d12b8b3d9945bde3991cb0d1413d120a58a04b17ac673549789e3f37b18a include/internal/refcount.h 11ee9893f7774c83fcfdee6e0ca593af3d28b779107883553facdbfdae3a68f5 include/internal/sha3.h 494ab5c802716bf38032986674fb094dde927a21752fe395d82e6044d81801d1 include/internal/sizes.h 24f41a1985fa305833c3f58030c494d2563d15fc922cdf3eeb6a7ea8c135a880 include/internal/symhacks.h 640cc6a2aae208073a7f495c08b4c5006a69e8ac1c2d9aaaafd56b0e74d5f859 include/internal/thread_once.h 415b725d7f949a6191ab7bb30b48931bafc01c7aa93607e529fabbc853a4ddc5 include/internal/tlsgroups.h fc0f9199487ef278b9fd317d1572db3e3fb95e182055f0e49c4d8faf78ed7dd2 include/internal/tsan_assist.h 2b38fb6e65d549aca3b2c76907daf67124f395251c0261dec26faa54da8d6d73 include/openssl/aes.h 98aa2fc5eae9ef2a36d3d0053212696d58893baa083fa1fcf720660fb4bc0a9f include/openssl/asn1.h.in d4733dcd490b3a2554eaf859d1ea964fe76f7d24f78e42be1094bdad6dee7429 include/openssl/asn1err.h 1550474ee05423896ec4abfb6346f1bc44c7be22329efac9ea25de10e81d549c include/openssl/asn1t.h.in 2cd8163cdc6c93386bc05e8ed983e5ca604d0bf9da65500cab736cfa8bc2b048 include/openssl/bio.h.in 0a26138aaded05cafe2326e11fdc19b28408e054cfe3dda40d45ef95ce8136b0 include/openssl/bioerr.h 7d1f9880976a926ba6e0cad08e8de6f326aae48d8350b499aa79127f63d4d108 include/openssl/bn.h 9ad8b04764797f5138f01f549ba18b44cf698ffc7fe795fef42c1822d84a6ff4 include/openssl/bnerr.h 93954e6c450716e158948d67f64736a451ea9473d02f3a908f3bc8a96cf049a5 include/openssl/buffer.h 9d48e6cab2ee98ae94d7113e4c65f000d97e125fdb3445642865ace3f34d06ac include/openssl/buffererr.h 8e772c24b051e59d2f65339f54584e3e44165a3eaf997d497faea764990130f5 include/openssl/cmac.h 55aa91482d327d1784484922389e8277bdcdff7a7df27e84200d5c908bd40454 include/openssl/conf.h.in f20c3c845129a129f5e0b1dae970d86a5c96ab49f2e3f6f364734521e9e1abe3 include/openssl/conferr.h 02a1baff7b71a298419c6c5dcb43eaa9cc13e9beeb88c03fb14854b4e84e8862 include/openssl/configuration.h.in 6b3810dac6c9d6f5ee36a10ad6d895a5e4553afdfb9641ce9b7dc5db7eef30b7 include/openssl/conftypes.h df5e60af861665675e4a00d40d15e36884f940e3379c7b45c9f717eaf1942697 include/openssl/core.h 00110e80b9b4f621c604ea99f05e7a75d3db4721fc2779224e6fa7e52f06e345 include/openssl/core_dispatch.h cbd9d7855ca3ba4240207fc025c22bbfef7411116446ff63511e336a0559bed0 include/openssl/core_names.h 194f96a30bdc4dab3f65693c09326ef53c54ebfd613c2513d8258a0aa35a6996 include/openssl/crypto.h.in 1d1697bd3e35920ff9eaec23c29472d727a7fc4d108150957f41f6f5ecf80f1a include/openssl/cryptoerr.h bbc82260cbcadd406091f39b9e3b5ea63146d9a4822623ead16fa12c43ab9fc6 include/openssl/cryptoerr_legacy.h fa3e6b6c2e6222424b9cd7005e3c5499a2334c831cd5d6a29256ce945be8cb1d include/openssl/des.h 75fba45d6fc66e3aaef216959327157613f08070935aae4a5260e740184f031f include/openssl/dh.h 836130f5a32bbdce51b97b34758ed1b03a9d06065c187418eaf323dca6adfc6d include/openssl/dherr.h 92ae2c907fd56859e3ae28a085071611be5c9245879305cdf8bad027219e64b6 include/openssl/dsa.h 276d1f6e111ba933bc708e6a0670047cbe0d0b67aabe31807abbbc231de4d8cf include/openssl/dsaerr.h 41bf49e64e1c341a8c17778147ddeba35e88dfd7ff131db6210e801ef25a8fd5 include/openssl/e_os2.h bc9ec2be442a4f49980ba2c63c8f0da701de1f6e23d7db35d781658f833dd7b9 include/openssl/ebcdic.h 33b6321d1c6b7b1621198346946401bb81472054aa236b03c6f22f247248d2ad include/openssl/ec.h 7aa8c5bee779af59d4733f6a50f7f6be39f1eb43409e5b3357440f9a7d0ca115 include/openssl/ecerr.h 61c76ee3f12ed0e42503a56421ca00f1cb9a0f4caa5f9c4421c374bcd45917d7 include/openssl/encoder.h 69dd983f45b8ccd551f084796519446552963a18c52b70470d978b597c81b2dc include/openssl/encodererr.h c6ee8f17d7252bdd0807a124dc6d50a95c32c04e17688b7c2e061998570b7028 include/openssl/err.h.in -12ec111c0e22581e0169be5e1838353a085fb51e3042ef59a7db1cee7da73c5b include/openssl/evp.h +b23bf3e2d0a60fe4d768afbe7aab48b47791e1274ae42b28895255119ae7f61d include/openssl/evp.h 5bd1b5dcd14067a1fe490d49df911002793c0b4f0bd4492cd8f71cfed7bf9f2a include/openssl/evperr.h 5381d96fe867a4ee0ebc09b9e3a262a0d7a27edc5f91dccfb010c7d713cd0820 include/openssl/fips_names.h b1d41beba560a41383f899a361b786e04f889106fb5960ec831b0af7996c9783 include/openssl/fipskey.h.in 47a088c98ad536ea99f2c6a9333e372507cb61b9bdffb930c586ed52f8f261eb include/openssl/hmac.h faab8accc9520269dd874126ae164a43526d5784e6280521c7ab3772c02b0a0c include/openssl/kdf.h c6db6926e90c9efd530a7bdb018be8c62f2c2b3c2f7b90228e9f73b8437dd785 include/openssl/lhash.h.in fd5c049ac6c3498750fa8f8dcbf88b2a31c02fa62dfe43a33d7b490fb86f61c8 include/openssl/macros.h 9184207c562fd1fa7bd3a4f1fadcb984130561279818f0cdfcf3e9c55be8a7d1 include/openssl/modes.h 7c71200e35f4cc1b4011a4bc14e521e4dc037b9b2d640a74bc30ef334b813de3 include/openssl/obj_mac.h 157797b450215f973eb10be96a04e58048ab9c131ad29427e80d0e37e230ed98 include/openssl/objects.h d25537af264684dff033dd8ae62b0348f868fcfec4aa51fa8f07bcfa4bd807ad include/openssl/objectserr.h fe6acd42c3e90db31aaafc2236a7d30ebfa53c4c07ea4d8265064c7fcb951970 include/openssl/opensslconf.h 1bf52d136e94f727a96651c1f48ad040482f35dae152519ccd585efd410b92f0 include/openssl/opensslv.h.in 767d9d7d5051c937a3ce8a268c702902fda93eeaa210a94dfde1f45c23277d20 include/openssl/param_build.h 30085f4d1b4934bb25ffe7aa9a30859966318a1b4d4dcea937c426e90e6e1984 include/openssl/params.h 097615b849375e2903967521f76c570512e5be47b8159fdbcd31e433f8a4cca7 include/openssl/prov_ssl.h bdadffba7b7b8294c9f7450ce2563ae31145ca0f196f5ce7b8c2f19ed7fba816 include/openssl/proverr.h b97e8ad49b38683817387596aefec0abd5f4d572643beef48be4f7acba26768d include/openssl/provider.h 7c9b5f479d9b22cfc8db0976dddfc2a1ee6e757b436e01a2b4d2744bcb6d81a5 include/openssl/rand.h 108966f56c82fedff53df76a4aa7861c82be4db1fd1ddafb59dc086ea155831c include/openssl/randerr.h c1015b77c444a3816d2ea7ad770f1c3b79a1e54887930af6dd662895701f3323 include/openssl/rsa.h 2f339ba2f22b8faa406692289a6e51fdbbb04b03f85cf3ca849835e58211ad23 include/openssl/rsaerr.h 6586f2187991731835353de0ffad0b6b57609b495e53d0f32644491ece629eb2 include/openssl/safestack.h.in af5cc56fb31161ccd87cf925f3d3f22119dfbca78bc39a2e2d65d78bfcf0f0c6 include/openssl/self_test.h 2964274ab32b1ba8578a06b06663db2eda4317ae806369271d889176bb5a7d04 include/openssl/sha.h c169a015d7be52b7b99dd41c418a48d97e52ad21687c39c512a83a7c3f3ddb70 include/openssl/stack.h 22d7584ad609e30e818b54dca1dfae8dea38913fffedd25cd540c550372fb9a6 include/openssl/symhacks.h 5e452bf61d802fdf7b6a65d1c8a1e3f72a7885e4bf2f521eca6443cea69f4ce5 include/openssl/trace.h 873d2ec2054ec24c52df4abe830cb2b9666fe4e75cc62b4de0f50ef9d20c5812 include/openssl/types.h c0a9551efccf43f3dd748d4fd8ec897ddaabbc629c00ec1ad76ce983e1195a13 providers/common/bio_prov.c 4546387d6642603c81ec4cd8d5fc4af8ba60ac7359eb6f31e7d24827031e68ad providers/common/capabilities.c f94b7435d4ec888ec30df1c611afa8b9eedbb59e905a2c7cb17cfc8c4b9b85b8 providers/common/der/der_digests_gen.c.in 424d7b2ece984a0904b80c73e541400c6e2d50a285c397dd323b440a4f2a8d8e providers/common/der/der_dsa_gen.c.in 27ff361a5fbfc97cd41690ab26639708961d0507b60912f55f5919649842c6ae providers/common/der/der_dsa_key.c 2529d253b3e45c33249461fdedb2c32b3c16a7a305fe4920f2a79e7b3f16ed3f providers/common/der/der_dsa_sig.c a81d36446eb8afa5c2318e24b86b52647059b4721ee52309b741e4ee78af29dd providers/common/der/der_ec_gen.c.in b8f2f94daeaf20c636c90e386284c246cfded0c8275411fa02fe68b534520b95 providers/common/der/der_ec_key.c 9104cd39dddd6e1a6e8f267656482131f4d0765e96fdced1f7344817a1c8ed7e providers/common/der/der_ec_sig.c 03a5620654438c58a8f971398e68922a3f33a519e2c92edb141d13ef4cbc4651 providers/common/der/der_ecx_gen.c.in f3b089fd3dcccc8e3ebfbbdbf87c47d58330f82bd0e2a1223da74977930cccf1 providers/common/der/der_ecx_key.c 5b3b0ae8da0fad1f7ba8b5fba2206210884728bf69a8aa00644036eb51953467 providers/common/der/der_rsa_gen.c.in 029aec80a45b477f7c8bd8d24d48e36de92f8056b421e9f128c336dc246dbc4e providers/common/der/der_rsa_key.c 7e8d579986f53eaf1875d677e5cf4adfd4ccf79db0275368f6cac580ab6007ca providers/common/der/der_rsa_sig.c 0b18bc007f296e16f6210956f5b6ab612b77d8a95170f12ae32764125901db6d providers/common/der/der_wrap_gen.c.in d447cd774869da68a2cc0bbb19c547ee6ed4858c7aee1f3d5bba7796f97823a9 providers/common/digest_to_nid.c 440c8ce0a4ca9f63157202bbfa26e12fec25847215fbae3416274124604ada6e providers/common/include/prov/bio.h 18ce379903b078446945da9116026da8639b4b0d81d357f86f9674a2a5cb94ef providers/common/include/prov/der_digests.h.in c0a020765feb7ededc7e6f20b2b140dca09f347cc72404a5c7971df82b2f9ad0 providers/common/include/prov/der_dsa.h.in 6024645ac9e165685b0a44a20feb342355eb06c07b7c7954508a125348570aea providers/common/include/prov/der_ec.h.in 5b6b7d8d12011c48195b7db8f65bc4bc4a48fb753763a3ce5006dc227b5139d7 providers/common/include/prov/der_ecx.h.in ce605f32413b09d33ce5795de9498a08183895c3347f33344f9ae5d31c29ccac providers/common/include/prov/der_rsa.h.in 6c1fa3f229c6f049c3ac152c4c265f3eb056d94221b82df95a15400649690e93 providers/common/include/prov/der_wrap.h.in 76087f04f4de6414c240f88807659fb2a04af914108f0c5f2515a4cb5482f655 providers/common/include/prov/proverr.h 83a57505d88a6a9cc4f7781c9f7f4af07668e7923502dfd6c5960bb492c1d24e providers/common/include/prov/provider_ctx.h 03fcfea9ed6e23d1df7ffd230af15f0f9b91a6aa635f77b9cbe52d5112168d09 providers/common/include/prov/provider_util.h e1ef8b2be828a54312d6561b37751a5b6e9d5ebdb6c3e63589728c3d8adca7dc providers/common/include/prov/providercommon.h 73d0e15963759fcb7c5c434bb214b50bc32f6066e90ac07fb53dad11c2fd1939 providers/common/include/prov/securitycheck.h 737cc1228106e555e9bab24e3c2438982e04e05b0d5b9ee6995d71df16c49143 providers/common/provider_ctx.c a8b73b10ab0100942dd2bc45f2fc9c9238b70bec0e49708ba113bc7479c8b92a providers/common/provider_err.c 9eae3e2cac89c7b63d091fdca1b6d80c5c5d52aa79c8ba4ce0158c5437ad62f3 providers/common/provider_seeding.c eec462d685dd3b4764b076a3c18ecd9dd254350a0b78ddc2f8a60587829e1ce3 providers/common/provider_util.c 5b94312727ca33e4f5c038f4caaae8417bf584cfde22df83d91f3c55c30c81ee providers/common/securitycheck.c 527eda471e26763a5fcf123b2d290234d5c836de7b8ef6eef2166ef439919d82 providers/common/securitycheck_fips.c abd5997bc33b681a4ab275978b92aebca0806a4a3f0c2f41dacf11b3b6f4e101 providers/fips/fips_entry.c 0f761a26c8fa6ad8d5a15c817afe1741352b21769b2164a2eb7dd50e1f6fe04f providers/fips/fipsprov.c 5d24ba30f9cc7ca48546fb85dc285bd68590f3a604a0bd471bcb0c2a61169591 providers/fips/self_test.c f822a03138e8b83ccaa910b89d72f31691da6778bf6638181f993ec7ae1167e3 providers/fips/self_test.h d3c95c9c6cc4e3b1a5e4b2bfb2ae735a4109d763bcda7b1e9b8f9eb253f79820 providers/fips/self_test_data.inc 629f619ad055723e42624230c08430a3ef53e17ab405dc0fd35499e9ca4e389c providers/fips/self_test_kats.c cd784a44a01a8a30a6be63381344a7f5432e74d40b02ea471c5b0dc943a7ac9d providers/implementations/asymciphers/rsa_enc.c 4db1826ecce8b60cb641bcd7a61430ec8cef73d2fe3cbc06aa33526afe1c954a providers/implementations/ciphers/cipher_aes.c f9d4b30e7110c90064b990c07430bb79061f4436b06ccaa981b25c306cfbfaa2 providers/implementations/ciphers/cipher_aes.h 89378cce6d31e8c2f221f9f29d0b17622624eb83e4ecec8465f7641f68352917 providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.c 7668e5c1cac474ad7b0f28aa78ca885edf44815fe4a606a6cd328b3c02fac25a providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.h 26e0f28523b416ba4067e471061f5a11fd76f5dc8bfe57ce37a137cf5667630b providers/implementations/ciphers/cipher_aes_cbc_hmac_sha1_hw.c 6d2ab2e059ef38fad342d4c65eebd533c08a2092bb174ff3566c6604e175c5a4 providers/implementations/ciphers/cipher_aes_cbc_hmac_sha256_hw.c 6d6bf36329af3b77f457898294be05fea3940a61cdaf0ed60cfb8d091a94186e providers/implementations/ciphers/cipher_aes_ccm.c 00f36bf48e522dbb5ec71df0ec13e387955fa3672e6ff90e8a412ae95c4a642f providers/implementations/ciphers/cipher_aes_ccm.h 6337b570e0dc4e98af07aa9704254d3ab958cf605584e250fbd76cd1d2a25ac7 providers/implementations/ciphers/cipher_aes_ccm_hw.c 302b3819ff9fdfed750185421616b248b0e1233d75b45a065490fe4762b42f55 providers/implementations/ciphers/cipher_aes_ccm_hw_aesni.inc a8eaca99a71521ff8ac4ffcf08315e59220f7e0b7f505ecddad04fadd021ec14 providers/implementations/ciphers/cipher_aes_cts.inc 710ee60704dd9dffa2a11e2e96596af1f7f84f915cedcedeec7292e0d978317a providers/implementations/ciphers/cipher_aes_gcm.c 79f5a732820d2512a7f4fc2a99ece7e6e2523a51e62561eb67a4b70d5538b0c4 providers/implementations/ciphers/cipher_aes_gcm.h ab298c5f89f3165fa11093fad8063b7bcbff0924b43fb3107148ae66d54adcb5 providers/implementations/ciphers/cipher_aes_gcm_hw.c 8ed4a100e4756c31c56147b4b0fab76a4c6e5292aa2f079045f37b5502fd41b9 providers/implementations/ciphers/cipher_aes_gcm_hw_aesni.inc 4c6f3a2818754a5aa7b6db36dae53e248504f9e82cc5af2ed68c723903d4f9d5 providers/implementations/ciphers/cipher_aes_hw.c 89de794c090192459d99d95bc4a422e7782e62192cd0fdb3bdef4128cfedee68 providers/implementations/ciphers/cipher_aes_hw_aesni.inc 0264d1ea3ece6f730b342586fb1fe00e3f0ff01e47d53f552864df986bf35573 providers/implementations/ciphers/cipher_aes_ocb.c 88138a1aff9705e608c0557653be92eb4de65b152555a2b79ec8b2a8fae73e8f providers/implementations/ciphers/cipher_aes_ocb.h 855869ab5a8d7a61a11674cfe5d503dfa67f59e7e393730835d1d8cf0ab85c70 providers/implementations/ciphers/cipher_aes_ocb_hw.c a872195161ac6c3a2cb59c3d15b212e34bb7596a41712258f5d0b5e771e25239 providers/implementations/ciphers/cipher_aes_wrp.c 527ff9277b92606517ee7af13225a9d5fcffbbc36eb18bce39f59d594cbe4931 providers/implementations/ciphers/cipher_aes_xts.c c4a2499b214d7cf786dafaaee5c8c6963b3d5d1c27c144eec4b460f839074a3b providers/implementations/ciphers/cipher_aes_xts.h 281157d1da4d7285d878978e6d42d0d33b3a6bc16e3bc5b6879e39093a7d70da providers/implementations/ciphers/cipher_aes_xts_fips.c f358c4121a8a223e2c6cf009fd28b8a195520279016462890214e8858880f632 providers/implementations/ciphers/cipher_aes_xts_hw.c 46ba8271917b53fd8fdf77aee19cc326a219c950b94e043d6d118dcac25ad7ad providers/implementations/ciphers/cipher_cts.c 74640ce402acc704af72e055fb7f27e6aa8efd417babc56f710478e571d8631c providers/implementations/ciphers/cipher_cts.h fcc3bb0637864252402aaa9d543209909df9a39611127f777b168bc888498dc0 providers/implementations/ciphers/cipher_tdes.c 77709f7fc3f7c08986cd4f0ebf2ef6e44bacb975c1483ef444b3cf5e5071f9d6 providers/implementations/ciphers/cipher_tdes.h 6fc41326c5f464f27b7d31c16d5ad7116d6244b99e242893f6c96d0c61f3639a providers/implementations/ciphers/cipher_tdes_common.c 50645122f08ef4891cd96cace833bd550be7f5278ab785515fd61fe8993c8c25 providers/implementations/ciphers/cipher_tdes_hw.c 6bb3c24bfd872e3b4c779b29e9f962348f6ae3effeb4f243c8ea66abefe8a4fa providers/implementations/ciphers/ciphercommon.c dd72ea861edf70b94197821ceb00e07165d550934a2e851d62afa5034b79f468 providers/implementations/ciphers/ciphercommon_block.c 4b4106f85e36eb2c07acc5a3ca5ccd77b736b3ac46cc4af786cf57405ecd54b2 providers/implementations/ciphers/ciphercommon_ccm.c 8b6828f188c2590c7d9c6cac13fa0eb6d38a522b0f2859e7c8a766580fa9b66e providers/implementations/ciphers/ciphercommon_ccm_hw.c 3b83f58d6ff1ae77de1ae8bee8a44ea2e5e4491c802b156fa77783ddebd44598 providers/implementations/ciphers/ciphercommon_gcm.c bb67eaa7a98494ca938726f9218213870fc97dd87b56bda950626cc794baf20b providers/implementations/ciphers/ciphercommon_gcm_hw.c 23fd89e3239e596c325a8c5d23eb1fe157a8d23aa4d90ed2c574bf06dfabd693 providers/implementations/ciphers/ciphercommon_hw.c c4b1cb143de15acc396ce2e03fdd165defd25ebc831de9cdfacf408ea883c666 providers/implementations/ciphers/ciphercommon_local.h 39b47b6ef9d71852964c26e07ef0e9b23f04c7493b1b16ba7c3dba7074b6b70d providers/implementations/digests/digestcommon.c 80551b53302d95faea257df3edbdbd02d48427ce42da2c4335f998456400d057 providers/implementations/digests/sha2_prov.c de342d04be6af69037922d5c97bdc40c0c27f6740636e72786a765d0d8ad9173 providers/implementations/digests/sha3_prov.c b5f94d597df72ca58486c59b2a70b4057d13f09528f861ed41a84b7125b54a82 providers/implementations/exchange/dh_exch.c 9c46dc0d859875fcc0bc3d61a7b610cd3520b1bf63718775c1124f54a1fe5f24 providers/implementations/exchange/ecdh_exch.c 9bf87b8429398a6465c7e9f749a33b84974303a458736b56f3359b30726d3969 providers/implementations/exchange/ecx_exch.c 0cc02005660c5c340660123decac838c59b7460ef1003d9d50edc604cfd8e375 providers/implementations/exchange/kdf_exch.c 31d3dba3d2e6b043b0d14a74caf6bf1a6c550471fb992a495ab7d3337081a526 providers/implementations/include/prov/ciphercommon.h 6dc876a1a785420e84210f085be6e4c7aca407ffb5433dbca4cd3f1c11bb7f06 providers/implementations/include/prov/ciphercommon_aead.h dd07797d61988fd4124cfb920616df672938da80649fac5977bfd061c981edc5 providers/implementations/include/prov/ciphercommon_ccm.h 0c1e99d70155402a790e4de65923228c8df8ad970741caccfe8b513837457d7f providers/implementations/include/prov/ciphercommon_gcm.h b9a61ce951c1904d8315b1bb26c0ab0aaadb47e71d4ead5df0a891608c728c4b providers/implementations/include/prov/digestcommon.h 3e2558c36298cdb4fdaebe5a0cfa1dbbc78e0f60a9012f3a34e711cafb09c7b5 providers/implementations/include/prov/implementations.h 5f09fc71874b00419d71646714f21ebbdcceda277463b6f77d3d3ea6946914e8 providers/implementations/include/prov/kdfexchange.h c95ce5498e724b9b3d58e3c2f4723e7e3e4beb07f9bea9422e43182cbadb43af providers/implementations/include/prov/macsignature.h 29d1a112b799e1f45fdf8bcee8361c2ed67428c250c1cdf408a9fbb7ebf4cce1 providers/implementations/include/prov/names.h 2187713b446d8b6d24ee986748b941ac3e24292c71e07ff9fb53a33021decdda providers/implementations/include/prov/seeding.h 4e71ffd329f1715d14b54e14036b4b2618deb2fd81675287ce5eeb6c76a31d54 providers/implementations/kdfs/hkdf.c a62e3af09f5af84dcf36f951ba4ac90ca1694adaf3747126186020b155f94186 providers/implementations/kdfs/kbkdf.c e0644e727aacfea4da3cf2c4d2602d7ef0626ebb760b6467432ffd54d5fbb24d providers/implementations/kdfs/pbkdf2.c c0778565abff112c0c5257329a7750ec4605e62f26cc36851fa1fbee6e03c70c providers/implementations/kdfs/pbkdf2.h abe2b0f3711eaa34846e155cffc9242e4051c45de896f747afd5ac9d87f637dc providers/implementations/kdfs/pbkdf2_fips.c 9cc42a4b0a8089e6d1be64637dbb9e41bd21ae5e3386022a27a8f29308ad25c9 providers/implementations/kdfs/sshkdf.c 8571556d77d10e8edc98212473a38f09632e3f19e9995dde89ee6c95f2e84ccf providers/implementations/kdfs/sskdf.c 589f6133799da80760e8bc3ab0191a341ab6d4d2706e92e6eb4a24b0250fefa6 providers/implementations/kdfs/tls1_prf.c 4d4a6d9a562d2dcfec941d3f113a544663b5ac2fbe4accd89ec70c1cc11751d0 providers/implementations/kdfs/x942kdf.c 6b6c776b12664164f3cb54c21df61e1c4477c7855d89431a16fb338cdae58d43 providers/implementations/kem/rsa_kem.c -9d5eb7e056e790b1b4292ec7af03fbf0b26e34625c70eb36643451965bcfc696 providers/implementations/keymgmt/dh_kmgmt.c +11a0d0fb88ed88e965f10b3a0ef6c880f60341df995128f57ad943053aaf15b2 providers/implementations/keymgmt/dh_kmgmt.c a329f57cb041cd03907e9d996fbc2f378ee116c7f8d7fbf1ea08b7a5df7e0304 providers/implementations/keymgmt/dsa_kmgmt.c 9bc88451d3ae110c7a108ee73d3b3b6bda801ec3494d2dfb9c9970b85c2d34fe providers/implementations/keymgmt/ec_kmgmt.c 258ae17bb2dd87ed1511a8eb3fe99eed9b77f5c2f757215ff6b3d0e8791fc251 providers/implementations/keymgmt/ec_kmgmt_imexport.inc 011c36aad6834729043f23eacab417732541ee23916d9afa5bb9164862be00bb providers/implementations/keymgmt/ecx_kmgmt.c 053a2be39a87f50b877ebdbbf799cf5faf8b2de33b04311d819d212ee1ea329b providers/implementations/keymgmt/kdf_legacy_kmgmt.c 1646b477fa231dd0f6c22444c99098f9b447cab0d39ff69b811262469d4dbe09 providers/implementations/keymgmt/mac_legacy_kmgmt.c 19f22fc70a6321441e56d5bd4aab3d01d52d17069d4e4b5cefce0f411ecece75 providers/implementations/keymgmt/rsa_kmgmt.c aeb42590728ca87b916b8a3d337351b1c82ee0747213e5ce740c2350b3db7185 providers/implementations/macs/cmac_prov.c e69aa06f8f3c6f5a26702b9f44a844b8589b99dc0ee590953a29e8b9ef10acbe providers/implementations/macs/gmac_prov.c 895c8dc7235b9ad5ff893be0293cbc245a5455e8850195ac7d446646e4ea71d0 providers/implementations/macs/hmac_prov.c -f75fbfe5348f93ad610da7d310f4e8fecf18c0549f27605da25d393c33e0edc2 providers/implementations/macs/kmac_prov.c +8640b63fd8325aaf8f7128d6cc448d9af448a65bf51a8978075467d33a67944e providers/implementations/macs/kmac_prov.c bf30274dd6b528ae913984775bd8f29c6c48c0ef06d464d0f738217727b7aa5c providers/implementations/rands/crngt.c 9d23df7f99beec7392c9d4ed813407050bc2d150098888fe802e2c9705fc33fa providers/implementations/rands/drbg.c bb5f8161a80d0d1a7ee919af2b167972b00afd62e326252ca6aa93101f315f19 providers/implementations/rands/drbg_ctr.c a05adc3f6d9d6f948e5ead75f0522ed3164cb5b2d301169242f3cb97c4a7fac3 providers/implementations/rands/drbg_hash.c 0876dfae991028c569631938946e458e6829cacf4cfb673d2b144ae50a3160bb providers/implementations/rands/drbg_hmac.c fc43558964bdf12442d3f6ab6cc3e6849f7adb42f4d0123a1279819befcf71cb providers/implementations/rands/drbg_local.h 04339b66c10017229ef368cb48077f58a252ebfda9ab12b9f919e4149b1036ed providers/implementations/rands/test_rng.c cafb9e6f54ad15889fcebddac6df61336bff7d78936f7de3bb5aab8aee5728d2 providers/implementations/signature/dsa_sig.c a30dc6308de0ca33406e7ce909f3bcf7580fb84d863b0976b275839f866258df providers/implementations/signature/ecdsa_sig.c 02e833a767afbe98247d6f09dfb1eb5a5cf7304a93f2c5427a9f6af9c8a3b549 providers/implementations/signature/eddsa_sig.c 3bb0f342b4cc1b4594ed0986adc47791c0a7b5c1ae7b1888c1fb5edb268a78d9 providers/implementations/signature/mac_legacy_sig.c 5b5e51acce1f6e86581de9ee870e64772f69562362b34079ac65c5d6fffaddef providers/implementations/signature/rsa_sig.c a14e901b02fe095713624db4080b3aa3ca685d43f9ebec03041f992240973346 ssl/record/tls_pad.c 3f2e01a98d9e3fda6cc5cb4b44dd43f6cae4ec34994e8f734d11b1e643e58636 ssl/s3_cbc.c diff --git a/crypto/openssl/providers/fips.checksum b/crypto/openssl/providers/fips.checksum index db5ddc6cb7c6..347a9614339e 100644 --- a/crypto/openssl/providers/fips.checksum +++ b/crypto/openssl/providers/fips.checksum @@ -1 +1 @@ -8d97c837eeb1288f74788f0e48cb0cbc8498d4cf7ddc25c89344df7d5309ffc8 providers/fips-sources.checksums +114b59f288ec2d6ddfcd26187f43cad614c6d4e4a7aba24410494f46f627671c providers/fips-sources.checksums diff --git a/crypto/openssl/providers/implementations/encode_decode/encode_key2text.c b/crypto/openssl/providers/implementations/encode_decode/encode_key2text.c index 7d983f5e51c6..3e75a9afb370 100644 --- a/crypto/openssl/providers/implementations/encode_decode/encode_key2text.c +++ b/crypto/openssl/providers/implementations/encode_decode/encode_key2text.c @@ -1,889 +1,876 @@ /* - * Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2020-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ /* * Low level APIs are deprecated for public use, but still ok for internal use. */ #include "internal/deprecated.h" #include #include #include #include #include #include #include #include #include "internal/ffc.h" #include "crypto/bn.h" /* bn_get_words() */ #include "crypto/dh.h" /* ossl_dh_get0_params() */ #include "crypto/dsa.h" /* ossl_dsa_get0_params() */ #include "crypto/ec.h" /* ossl_ec_key_get_libctx */ #include "crypto/ecx.h" /* ECX_KEY, etc... */ #include "crypto/rsa.h" /* RSA_PSS_PARAMS_30, etc... */ #include "prov/bio.h" #include "prov/implementations.h" #include "endecoder_local.h" DEFINE_SPECIAL_STACK_OF_CONST(BIGNUM_const, BIGNUM) # ifdef SIXTY_FOUR_BIT_LONG # define BN_FMTu "%lu" # define BN_FMTx "%lx" # endif # ifdef SIXTY_FOUR_BIT # define BN_FMTu "%llu" # define BN_FMTx "%llx" # endif # ifdef THIRTY_TWO_BIT # define BN_FMTu "%u" # define BN_FMTx "%x" # endif static int print_labeled_bignum(BIO *out, const char *label, const BIGNUM *bn) { int ret = 0, use_sep = 0; char *hex_str = NULL, *p; const char spaces[] = " "; const char *post_label_spc = " "; const char *neg = ""; int bytes; if (bn == NULL) return 0; if (label == NULL) { label = ""; post_label_spc = ""; } if (BN_is_zero(bn)) return BIO_printf(out, "%s%s0\n", label, post_label_spc); if (BN_num_bytes(bn) <= BN_BYTES) { BN_ULONG *words = bn_get_words(bn); if (BN_is_negative(bn)) neg = "-"; return BIO_printf(out, "%s%s%s" BN_FMTu " (%s0x" BN_FMTx ")\n", label, post_label_spc, neg, words[0], neg, words[0]); } hex_str = BN_bn2hex(bn); if (hex_str == NULL) return 0; p = hex_str; if (*p == '-') { ++p; neg = " (Negative)"; } if (BIO_printf(out, "%s%s\n", label, neg) <= 0) goto err; /* Keep track of how many bytes we have printed out so far */ bytes = 0; if (BIO_printf(out, "%s", spaces) <= 0) goto err; /* Add a leading 00 if the top bit is set */ if (*p >= '8') { if (BIO_printf(out, "%02x", 0) <= 0) goto err; ++bytes; use_sep = 1; } while (*p != '\0') { /* Do a newline after every 15 hex bytes + add the space indent */ if ((bytes % 15) == 0 && bytes > 0) { if (BIO_printf(out, ":\n%s", spaces) <= 0) goto err; use_sep = 0; /* The first byte on the next line doesnt have a : */ } if (BIO_printf(out, "%s%c%c", use_sep ? ":" : "", tolower(p[0]), tolower(p[1])) <= 0) goto err; ++bytes; p += 2; use_sep = 1; } if (BIO_printf(out, "\n") <= 0) goto err; ret = 1; err: OPENSSL_free(hex_str); return ret; } /* Number of octets per line */ #define LABELED_BUF_PRINT_WIDTH 15 #if !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_EC) static int print_labeled_buf(BIO *out, const char *label, const unsigned char *buf, size_t buflen) { size_t i; if (BIO_printf(out, "%s\n", label) <= 0) return 0; for (i = 0; i < buflen; i++) { if ((i % LABELED_BUF_PRINT_WIDTH) == 0) { if (i > 0 && BIO_printf(out, "\n") <= 0) return 0; if (BIO_printf(out, " ") <= 0) return 0; } if (BIO_printf(out, "%02x%s", buf[i], (i == buflen - 1) ? "" : ":") <= 0) return 0; } if (BIO_printf(out, "\n") <= 0) return 0; return 1; } #endif #if !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_DSA) static int ffc_params_to_text(BIO *out, const FFC_PARAMS *ffc) { if (ffc->nid != NID_undef) { #ifndef OPENSSL_NO_DH const DH_NAMED_GROUP *group = ossl_ffc_uid_to_dh_named_group(ffc->nid); const char *name = ossl_ffc_named_group_get_name(group); if (name == NULL) goto err; if (BIO_printf(out, "GROUP: %s\n", name) <= 0) goto err; return 1; #else /* How could this be? We should not have a nid in a no-dh build. */ goto err; #endif } if (!print_labeled_bignum(out, "P: ", ffc->p)) goto err; if (ffc->q != NULL) { if (!print_labeled_bignum(out, "Q: ", ffc->q)) goto err; } if (!print_labeled_bignum(out, "G: ", ffc->g)) goto err; if (ffc->j != NULL) { if (!print_labeled_bignum(out, "J: ", ffc->j)) goto err; } if (ffc->seed != NULL) { if (!print_labeled_buf(out, "SEED:", ffc->seed, ffc->seedlen)) goto err; } if (ffc->gindex != -1) { if (BIO_printf(out, "gindex: %d\n", ffc->gindex) <= 0) goto err; } if (ffc->pcounter != -1) { if (BIO_printf(out, "pcounter: %d\n", ffc->pcounter) <= 0) goto err; } if (ffc->h != 0) { if (BIO_printf(out, "h: %d\n", ffc->h) <= 0) goto err; } return 1; err: return 0; } #endif /* ---------------------------------------------------------------------- */ #ifndef OPENSSL_NO_DH static int dh_to_text(BIO *out, const void *key, int selection) { const DH *dh = key; const char *type_label = NULL; const BIGNUM *priv_key = NULL, *pub_key = NULL; const FFC_PARAMS *params = NULL; const BIGNUM *p = NULL; long length; if (out == NULL || dh == NULL) { ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_NULL_PARAMETER); return 0; } if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) type_label = "DH Private-Key"; else if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) type_label = "DH Public-Key"; else if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0) type_label = "DH Parameters"; if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) { priv_key = DH_get0_priv_key(dh); if (priv_key == NULL) { ERR_raise(ERR_LIB_PROV, PROV_R_NOT_A_PRIVATE_KEY); return 0; } } - if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) { + if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) { pub_key = DH_get0_pub_key(dh); if (pub_key == NULL) { ERR_raise(ERR_LIB_PROV, PROV_R_NOT_A_PUBLIC_KEY); return 0; } } if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0) { params = ossl_dh_get0_params((DH *)dh); if (params == NULL) { ERR_raise(ERR_LIB_PROV, PROV_R_NOT_PARAMETERS); return 0; } } p = DH_get0_p(dh); if (p == NULL) { ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY); return 0; } if (BIO_printf(out, "%s: (%d bit)\n", type_label, BN_num_bits(p)) <= 0) return 0; if (priv_key != NULL && !print_labeled_bignum(out, "private-key:", priv_key)) return 0; if (pub_key != NULL && !print_labeled_bignum(out, "public-key:", pub_key)) return 0; if (params != NULL && !ffc_params_to_text(out, params)) return 0; length = DH_get_length(dh); if (length > 0 && BIO_printf(out, "recommended-private-length: %ld bits\n", length) <= 0) return 0; return 1; } # define dh_input_type "DH" # define dhx_input_type "DHX" #endif /* ---------------------------------------------------------------------- */ #ifndef OPENSSL_NO_DSA static int dsa_to_text(BIO *out, const void *key, int selection) { const DSA *dsa = key; const char *type_label = NULL; const BIGNUM *priv_key = NULL, *pub_key = NULL; const FFC_PARAMS *params = NULL; const BIGNUM *p = NULL; if (out == NULL || dsa == NULL) { ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_NULL_PARAMETER); return 0; } if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) type_label = "Private-Key"; else if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) type_label = "Public-Key"; else if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0) type_label = "DSA-Parameters"; if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) { priv_key = DSA_get0_priv_key(dsa); if (priv_key == NULL) { ERR_raise(ERR_LIB_PROV, PROV_R_NOT_A_PRIVATE_KEY); return 0; } } - if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) { + if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) { pub_key = DSA_get0_pub_key(dsa); if (pub_key == NULL) { ERR_raise(ERR_LIB_PROV, PROV_R_NOT_A_PUBLIC_KEY); return 0; } } if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0) { params = ossl_dsa_get0_params((DSA *)dsa); if (params == NULL) { ERR_raise(ERR_LIB_PROV, PROV_R_NOT_PARAMETERS); return 0; } } p = DSA_get0_p(dsa); if (p == NULL) { ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY); return 0; } if (BIO_printf(out, "%s: (%d bit)\n", type_label, BN_num_bits(p)) <= 0) return 0; if (priv_key != NULL && !print_labeled_bignum(out, "priv:", priv_key)) return 0; if (pub_key != NULL && !print_labeled_bignum(out, "pub: ", pub_key)) return 0; if (params != NULL && !ffc_params_to_text(out, params)) return 0; return 1; } # define dsa_input_type "DSA" #endif /* ---------------------------------------------------------------------- */ #ifndef OPENSSL_NO_EC static int ec_param_explicit_curve_to_text(BIO *out, const EC_GROUP *group, BN_CTX *ctx) { const char *plabel = "Prime:"; BIGNUM *p = NULL, *a = NULL, *b = NULL; p = BN_CTX_get(ctx); a = BN_CTX_get(ctx); b = BN_CTX_get(ctx); if (b == NULL || !EC_GROUP_get_curve(group, p, a, b, ctx)) return 0; if (EC_GROUP_get_field_type(group) == NID_X9_62_characteristic_two_field) { int basis_type = EC_GROUP_get_basis_type(group); /* print the 'short name' of the base type OID */ if (basis_type == NID_undef || BIO_printf(out, "Basis Type: %s\n", OBJ_nid2sn(basis_type)) <= 0) return 0; plabel = "Polynomial:"; } return print_labeled_bignum(out, plabel, p) && print_labeled_bignum(out, "A: ", a) && print_labeled_bignum(out, "B: ", b); } static int ec_param_explicit_gen_to_text(BIO *out, const EC_GROUP *group, BN_CTX *ctx) { int ret; size_t buflen; point_conversion_form_t form; const EC_POINT *point = NULL; const char *glabel = NULL; unsigned char *buf = NULL; form = EC_GROUP_get_point_conversion_form(group); point = EC_GROUP_get0_generator(group); if (point == NULL) return 0; switch (form) { case POINT_CONVERSION_COMPRESSED: glabel = "Generator (compressed):"; break; case POINT_CONVERSION_UNCOMPRESSED: glabel = "Generator (uncompressed):"; break; case POINT_CONVERSION_HYBRID: glabel = "Generator (hybrid):"; break; default: return 0; } buflen = EC_POINT_point2buf(group, point, form, &buf, ctx); if (buflen == 0) return 0; ret = print_labeled_buf(out, glabel, buf, buflen); OPENSSL_clear_free(buf, buflen); return ret; } /* Print explicit parameters */ static int ec_param_explicit_to_text(BIO *out, const EC_GROUP *group, OSSL_LIB_CTX *libctx) { int ret = 0, tmp_nid; BN_CTX *ctx = NULL; const BIGNUM *order = NULL, *cofactor = NULL; const unsigned char *seed; size_t seed_len = 0; ctx = BN_CTX_new_ex(libctx); if (ctx == NULL) return 0; BN_CTX_start(ctx); tmp_nid = EC_GROUP_get_field_type(group); order = EC_GROUP_get0_order(group); if (order == NULL) goto err; seed = EC_GROUP_get0_seed(group); if (seed != NULL) seed_len = EC_GROUP_get_seed_len(group); cofactor = EC_GROUP_get0_cofactor(group); /* print the 'short name' of the field type */ if (BIO_printf(out, "Field Type: %s\n", OBJ_nid2sn(tmp_nid)) <= 0 || !ec_param_explicit_curve_to_text(out, group, ctx) || !ec_param_explicit_gen_to_text(out, group, ctx) || !print_labeled_bignum(out, "Order: ", order) || (cofactor != NULL && !print_labeled_bignum(out, "Cofactor: ", cofactor)) || (seed != NULL && !print_labeled_buf(out, "Seed:", seed, seed_len))) goto err; ret = 1; err: BN_CTX_end(ctx); BN_CTX_free(ctx); return ret; } static int ec_param_to_text(BIO *out, const EC_GROUP *group, OSSL_LIB_CTX *libctx) { if (EC_GROUP_get_asn1_flag(group) & OPENSSL_EC_NAMED_CURVE) { const char *curve_name; int curve_nid = EC_GROUP_get_curve_name(group); /* Explicit parameters */ if (curve_nid == NID_undef) return 0; if (BIO_printf(out, "%s: %s\n", "ASN1 OID", OBJ_nid2sn(curve_nid)) <= 0) return 0; curve_name = EC_curve_nid2nist(curve_nid); return (curve_name == NULL || BIO_printf(out, "%s: %s\n", "NIST CURVE", curve_name) > 0); } else { return ec_param_explicit_to_text(out, group, libctx); } } static int ec_to_text(BIO *out, const void *key, int selection) { const EC_KEY *ec = key; const char *type_label = NULL; unsigned char *priv = NULL, *pub = NULL; size_t priv_len = 0, pub_len = 0; const EC_GROUP *group; int ret = 0; if (out == NULL || ec == NULL) { ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_NULL_PARAMETER); return 0; } if ((group = EC_KEY_get0_group(ec)) == NULL) { ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY); return 0; } if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) type_label = "Private-Key"; else if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) type_label = "Public-Key"; else if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0) type_label = "EC-Parameters"; if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) { const BIGNUM *priv_key = EC_KEY_get0_private_key(ec); if (priv_key == NULL) { ERR_raise(ERR_LIB_PROV, PROV_R_NOT_A_PRIVATE_KEY); goto err; } priv_len = EC_KEY_priv2buf(ec, &priv); if (priv_len == 0) goto err; } - if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) { + if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) { const EC_POINT *pub_pt = EC_KEY_get0_public_key(ec); if (pub_pt == NULL) { ERR_raise(ERR_LIB_PROV, PROV_R_NOT_A_PUBLIC_KEY); goto err; } pub_len = EC_KEY_key2buf(ec, EC_KEY_get_conv_form(ec), &pub, NULL); if (pub_len == 0) goto err; } if (BIO_printf(out, "%s: (%d bit)\n", type_label, EC_GROUP_order_bits(group)) <= 0) goto err; if (priv != NULL && !print_labeled_buf(out, "priv:", priv, priv_len)) goto err; if (pub != NULL && !print_labeled_buf(out, "pub:", pub, pub_len)) goto err; if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0) ret = ec_param_to_text(out, group, ossl_ec_key_get_libctx(ec)); err: OPENSSL_clear_free(priv, priv_len); OPENSSL_free(pub); return ret; } # define ec_input_type "EC" # ifndef OPENSSL_NO_SM2 # define sm2_input_type "SM2" # endif #endif /* ---------------------------------------------------------------------- */ #ifndef OPENSSL_NO_EC static int ecx_to_text(BIO *out, const void *key, int selection) { const ECX_KEY *ecx = key; const char *type_label = NULL; if (out == NULL || ecx == NULL) { ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_NULL_PARAMETER); return 0; } + switch (ecx->type) { + case ECX_KEY_TYPE_X25519: + type_label = "X25519"; + break; + case ECX_KEY_TYPE_X448: + type_label = "X448"; + break; + case ECX_KEY_TYPE_ED25519: + type_label = "ED25519"; + break; + case ECX_KEY_TYPE_ED448: + type_label = "ED448"; + break; + } + if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) { if (ecx->privkey == NULL) { ERR_raise(ERR_LIB_PROV, PROV_R_NOT_A_PRIVATE_KEY); return 0; } - switch (ecx->type) { - case ECX_KEY_TYPE_X25519: - type_label = "X25519 Private-Key"; - break; - case ECX_KEY_TYPE_X448: - type_label = "X448 Private-Key"; - break; - case ECX_KEY_TYPE_ED25519: - type_label = "ED25519 Private-Key"; - break; - case ECX_KEY_TYPE_ED448: - type_label = "ED448 Private-Key"; - break; - } + if (BIO_printf(out, "%s Private-Key:\n", type_label) <= 0) + return 0; + if (!print_labeled_buf(out, "priv:", ecx->privkey, ecx->keylen)) + return 0; } else if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) { /* ecx->pubkey is an array, not a pointer... */ if (!ecx->haspubkey) { ERR_raise(ERR_LIB_PROV, PROV_R_NOT_A_PUBLIC_KEY); return 0; } - switch (ecx->type) { - case ECX_KEY_TYPE_X25519: - type_label = "X25519 Public-Key"; - break; - case ECX_KEY_TYPE_X448: - type_label = "X448 Public-Key"; - break; - case ECX_KEY_TYPE_ED25519: - type_label = "ED25519 Public-Key"; - break; - case ECX_KEY_TYPE_ED448: - type_label = "ED448 Public-Key"; - break; - } + if (BIO_printf(out, "%s Public-Key:\n", type_label) <= 0) + return 0; } - if (BIO_printf(out, "%s:\n", type_label) <= 0) - return 0; - if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0 - && !print_labeled_buf(out, "priv:", ecx->privkey, ecx->keylen)) - return 0; - if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0 - && !print_labeled_buf(out, "pub:", ecx->pubkey, ecx->keylen)) + if (!print_labeled_buf(out, "pub:", ecx->pubkey, ecx->keylen)) return 0; return 1; } # define ed25519_input_type "ED25519" # define ed448_input_type "ED448" # define x25519_input_type "X25519" # define x448_input_type "X448" #endif /* ---------------------------------------------------------------------- */ static int rsa_to_text(BIO *out, const void *key, int selection) { const RSA *rsa = key; const char *type_label = "RSA key"; const char *modulus_label = NULL; const char *exponent_label = NULL; const BIGNUM *rsa_d = NULL, *rsa_n = NULL, *rsa_e = NULL; STACK_OF(BIGNUM_const) *factors = NULL; STACK_OF(BIGNUM_const) *exps = NULL; STACK_OF(BIGNUM_const) *coeffs = NULL; int primes; const RSA_PSS_PARAMS_30 *pss_params = ossl_rsa_get0_pss_params_30((RSA *)rsa); int ret = 0; if (out == NULL || rsa == NULL) { ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_NULL_PARAMETER); goto err; } factors = sk_BIGNUM_const_new_null(); exps = sk_BIGNUM_const_new_null(); coeffs = sk_BIGNUM_const_new_null(); if (factors == NULL || exps == NULL || coeffs == NULL) { ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE); goto err; } if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) { type_label = "Private-Key"; modulus_label = "modulus:"; exponent_label = "publicExponent:"; } else if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) { type_label = "Public-Key"; modulus_label = "Modulus:"; exponent_label = "Exponent:"; } RSA_get0_key(rsa, &rsa_n, &rsa_e, &rsa_d); ossl_rsa_get0_all_params((RSA *)rsa, factors, exps, coeffs); primes = sk_BIGNUM_const_num(factors); if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) { if (BIO_printf(out, "%s: (%d bit, %d primes)\n", type_label, BN_num_bits(rsa_n), primes) <= 0) goto err; } else { if (BIO_printf(out, "%s: (%d bit)\n", type_label, BN_num_bits(rsa_n)) <= 0) goto err; } if (!print_labeled_bignum(out, modulus_label, rsa_n)) goto err; if (!print_labeled_bignum(out, exponent_label, rsa_e)) goto err; if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) { int i; if (!print_labeled_bignum(out, "privateExponent:", rsa_d)) goto err; if (!print_labeled_bignum(out, "prime1:", sk_BIGNUM_const_value(factors, 0))) goto err; if (!print_labeled_bignum(out, "prime2:", sk_BIGNUM_const_value(factors, 1))) goto err; if (!print_labeled_bignum(out, "exponent1:", sk_BIGNUM_const_value(exps, 0))) goto err; if (!print_labeled_bignum(out, "exponent2:", sk_BIGNUM_const_value(exps, 1))) goto err; if (!print_labeled_bignum(out, "coefficient:", sk_BIGNUM_const_value(coeffs, 0))) goto err; for (i = 2; i < sk_BIGNUM_const_num(factors); i++) { if (BIO_printf(out, "prime%d:", i + 1) <= 0) goto err; if (!print_labeled_bignum(out, NULL, sk_BIGNUM_const_value(factors, i))) goto err; if (BIO_printf(out, "exponent%d:", i + 1) <= 0) goto err; if (!print_labeled_bignum(out, NULL, sk_BIGNUM_const_value(exps, i))) goto err; if (BIO_printf(out, "coefficient%d:", i + 1) <= 0) goto err; if (!print_labeled_bignum(out, NULL, sk_BIGNUM_const_value(coeffs, i - 1))) goto err; } } if ((selection & OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS) != 0) { switch (RSA_test_flags(rsa, RSA_FLAG_TYPE_MASK)) { case RSA_FLAG_TYPE_RSA: if (!ossl_rsa_pss_params_30_is_unrestricted(pss_params)) { if (BIO_printf(out, "(INVALID PSS PARAMETERS)\n") <= 0) goto err; } break; case RSA_FLAG_TYPE_RSASSAPSS: if (ossl_rsa_pss_params_30_is_unrestricted(pss_params)) { if (BIO_printf(out, "No PSS parameter restrictions\n") <= 0) goto err; } else { int hashalg_nid = ossl_rsa_pss_params_30_hashalg(pss_params); int maskgenalg_nid = ossl_rsa_pss_params_30_maskgenalg(pss_params); int maskgenhashalg_nid = ossl_rsa_pss_params_30_maskgenhashalg(pss_params); int saltlen = ossl_rsa_pss_params_30_saltlen(pss_params); int trailerfield = ossl_rsa_pss_params_30_trailerfield(pss_params); if (BIO_printf(out, "PSS parameter restrictions:\n") <= 0) goto err; if (BIO_printf(out, " Hash Algorithm: %s%s\n", ossl_rsa_oaeppss_nid2name(hashalg_nid), (hashalg_nid == NID_sha1 ? " (default)" : "")) <= 0) goto err; if (BIO_printf(out, " Mask Algorithm: %s with %s%s\n", ossl_rsa_mgf_nid2name(maskgenalg_nid), ossl_rsa_oaeppss_nid2name(maskgenhashalg_nid), (maskgenalg_nid == NID_mgf1 && maskgenhashalg_nid == NID_sha1 ? " (default)" : "")) <= 0) goto err; if (BIO_printf(out, " Minimum Salt Length: %d%s\n", saltlen, (saltlen == 20 ? " (default)" : "")) <= 0) goto err; if (BIO_printf(out, " Trailer Field: 0x%x%s\n", trailerfield, (trailerfield == 1 ? " (default)" : "")) <= 0) goto err; } break; } } ret = 1; err: sk_BIGNUM_const_free(factors); sk_BIGNUM_const_free(exps); sk_BIGNUM_const_free(coeffs); return ret; } #define rsa_input_type "RSA" #define rsapss_input_type "RSA-PSS" /* ---------------------------------------------------------------------- */ static void *key2text_newctx(void *provctx) { return provctx; } static void key2text_freectx(ossl_unused void *vctx) { } static int key2text_encode(void *vctx, const void *key, int selection, OSSL_CORE_BIO *cout, int (*key2text)(BIO *out, const void *key, int selection), OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { BIO *out = ossl_bio_new_from_core_bio(vctx, cout); int ret; if (out == NULL) return 0; ret = key2text(out, key, selection); BIO_free(out); return ret; } #define MAKE_TEXT_ENCODER(impl, type) \ static OSSL_FUNC_encoder_import_object_fn \ impl##2text_import_object; \ static OSSL_FUNC_encoder_free_object_fn \ impl##2text_free_object; \ static OSSL_FUNC_encoder_encode_fn impl##2text_encode; \ \ static void *impl##2text_import_object(void *ctx, int selection, \ const OSSL_PARAM params[]) \ { \ return ossl_prov_import_key(ossl_##impl##_keymgmt_functions, \ ctx, selection, params); \ } \ static void impl##2text_free_object(void *key) \ { \ ossl_prov_free_key(ossl_##impl##_keymgmt_functions, key); \ } \ static int impl##2text_encode(void *vctx, OSSL_CORE_BIO *cout, \ const void *key, \ const OSSL_PARAM key_abstract[], \ int selection, \ OSSL_PASSPHRASE_CALLBACK *cb, \ void *cbarg) \ { \ /* We don't deal with abstract objects */ \ if (key_abstract != NULL) { \ ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_INVALID_ARGUMENT); \ return 0; \ } \ return key2text_encode(vctx, key, selection, cout, \ type##_to_text, cb, cbarg); \ } \ const OSSL_DISPATCH ossl_##impl##_to_text_encoder_functions[] = { \ { OSSL_FUNC_ENCODER_NEWCTX, \ (void (*)(void))key2text_newctx }, \ { OSSL_FUNC_ENCODER_FREECTX, \ (void (*)(void))key2text_freectx }, \ { OSSL_FUNC_ENCODER_IMPORT_OBJECT, \ (void (*)(void))impl##2text_import_object }, \ { OSSL_FUNC_ENCODER_FREE_OBJECT, \ (void (*)(void))impl##2text_free_object }, \ { OSSL_FUNC_ENCODER_ENCODE, \ (void (*)(void))impl##2text_encode }, \ { 0, NULL } \ } #ifndef OPENSSL_NO_DH MAKE_TEXT_ENCODER(dh, dh); MAKE_TEXT_ENCODER(dhx, dh); #endif #ifndef OPENSSL_NO_DSA MAKE_TEXT_ENCODER(dsa, dsa); #endif #ifndef OPENSSL_NO_EC MAKE_TEXT_ENCODER(ec, ec); # ifndef OPENSSL_NO_SM2 MAKE_TEXT_ENCODER(sm2, ec); # endif MAKE_TEXT_ENCODER(ed25519, ecx); MAKE_TEXT_ENCODER(ed448, ecx); MAKE_TEXT_ENCODER(x25519, ecx); MAKE_TEXT_ENCODER(x448, ecx); #endif MAKE_TEXT_ENCODER(rsa, rsa); MAKE_TEXT_ENCODER(rsapss, rsa); diff --git a/crypto/openssl/providers/implementations/keymgmt/dh_kmgmt.c b/crypto/openssl/providers/implementations/keymgmt/dh_kmgmt.c index 4ca9c1a3fad8..c14b9765d11b 100644 --- a/crypto/openssl/providers/implementations/keymgmt/dh_kmgmt.c +++ b/crypto/openssl/providers/implementations/keymgmt/dh_kmgmt.c @@ -1,884 +1,884 @@ /* * Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ /* * DH low level APIs are deprecated for public use, but still ok for * internal use. */ #include "internal/deprecated.h" #include /* strcmp */ #include #include #include #include #include "prov/implementations.h" #include "prov/providercommon.h" #include "prov/provider_ctx.h" #include "crypto/dh.h" #include "internal/sizes.h" static OSSL_FUNC_keymgmt_new_fn dh_newdata; static OSSL_FUNC_keymgmt_free_fn dh_freedata; static OSSL_FUNC_keymgmt_gen_init_fn dh_gen_init; static OSSL_FUNC_keymgmt_gen_init_fn dhx_gen_init; static OSSL_FUNC_keymgmt_gen_set_template_fn dh_gen_set_template; static OSSL_FUNC_keymgmt_gen_set_params_fn dh_gen_set_params; static OSSL_FUNC_keymgmt_gen_settable_params_fn dh_gen_settable_params; static OSSL_FUNC_keymgmt_gen_fn dh_gen; static OSSL_FUNC_keymgmt_gen_cleanup_fn dh_gen_cleanup; static OSSL_FUNC_keymgmt_load_fn dh_load; static OSSL_FUNC_keymgmt_get_params_fn dh_get_params; static OSSL_FUNC_keymgmt_gettable_params_fn dh_gettable_params; static OSSL_FUNC_keymgmt_set_params_fn dh_set_params; static OSSL_FUNC_keymgmt_settable_params_fn dh_settable_params; static OSSL_FUNC_keymgmt_has_fn dh_has; static OSSL_FUNC_keymgmt_match_fn dh_match; static OSSL_FUNC_keymgmt_validate_fn dh_validate; static OSSL_FUNC_keymgmt_import_fn dh_import; static OSSL_FUNC_keymgmt_import_types_fn dh_import_types; static OSSL_FUNC_keymgmt_export_fn dh_export; static OSSL_FUNC_keymgmt_export_types_fn dh_export_types; static OSSL_FUNC_keymgmt_dup_fn dh_dup; #define DH_POSSIBLE_SELECTIONS \ (OSSL_KEYMGMT_SELECT_KEYPAIR | OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) struct dh_gen_ctx { OSSL_LIB_CTX *libctx; FFC_PARAMS *ffc_params; int selection; /* All these parameters are used for parameter generation only */ /* If there is a group name then the remaining parameters are not needed */ int group_nid; size_t pbits; size_t qbits; unsigned char *seed; /* optional FIPS186-4 param for testing */ size_t seedlen; int gindex; /* optional FIPS186-4 generator index (ignored if -1) */ int gen_type; /* see dhtype2id */ int generator; /* Used by DH_PARAMGEN_TYPE_GENERATOR in non fips mode only */ int pcounter; int hindex; int priv_len; char *mdname; char *mdprops; OSSL_CALLBACK *cb; void *cbarg; int dh_type; }; static int dh_gen_type_name2id_w_default(const char *name, int type) { if (strcmp(name, "default") == 0) { #ifdef FIPS_MODULE if (type == DH_FLAG_TYPE_DHX) return DH_PARAMGEN_TYPE_FIPS_186_4; return DH_PARAMGEN_TYPE_GROUP; #else if (type == DH_FLAG_TYPE_DHX) return DH_PARAMGEN_TYPE_FIPS_186_2; return DH_PARAMGEN_TYPE_GENERATOR; #endif } return ossl_dh_gen_type_name2id(name, type); } static void *dh_newdata(void *provctx) { DH *dh = NULL; if (ossl_prov_is_running()) { dh = ossl_dh_new_ex(PROV_LIBCTX_OF(provctx)); if (dh != NULL) { DH_clear_flags(dh, DH_FLAG_TYPE_MASK); DH_set_flags(dh, DH_FLAG_TYPE_DH); } } return dh; } static void *dhx_newdata(void *provctx) { DH *dh = NULL; dh = ossl_dh_new_ex(PROV_LIBCTX_OF(provctx)); if (dh != NULL) { DH_clear_flags(dh, DH_FLAG_TYPE_MASK); DH_set_flags(dh, DH_FLAG_TYPE_DHX); } return dh; } static void dh_freedata(void *keydata) { DH_free(keydata); } static int dh_has(const void *keydata, int selection) { const DH *dh = keydata; int ok = 1; if (!ossl_prov_is_running() || dh == NULL) return 0; if ((selection & DH_POSSIBLE_SELECTIONS) == 0) return 1; /* the selection is not missing */ if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) ok = ok && (DH_get0_pub_key(dh) != NULL); if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) ok = ok && (DH_get0_priv_key(dh) != NULL); if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0) ok = ok && (DH_get0_p(dh) != NULL && DH_get0_g(dh) != NULL); return ok; } static int dh_match(const void *keydata1, const void *keydata2, int selection) { const DH *dh1 = keydata1; const DH *dh2 = keydata2; int ok = 1; if (!ossl_prov_is_running()) return 0; if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) { int key_checked = 0; if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) { const BIGNUM *pa = DH_get0_pub_key(dh1); const BIGNUM *pb = DH_get0_pub_key(dh2); if (pa != NULL && pb != NULL) { ok = ok && BN_cmp(pa, pb) == 0; key_checked = 1; } } if (!key_checked && (selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) { const BIGNUM *pa = DH_get0_priv_key(dh1); const BIGNUM *pb = DH_get0_priv_key(dh2); if (pa != NULL && pb != NULL) { ok = ok && BN_cmp(pa, pb) == 0; key_checked = 1; } } ok = ok && key_checked; } if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0) { FFC_PARAMS *dhparams1 = ossl_dh_get0_params((DH *)dh1); FFC_PARAMS *dhparams2 = ossl_dh_get0_params((DH *)dh2); ok = ok && ossl_ffc_params_cmp(dhparams1, dhparams2, 1); } return ok; } static int dh_import(void *keydata, int selection, const OSSL_PARAM params[]) { DH *dh = keydata; int ok = 1; if (!ossl_prov_is_running() || dh == NULL) return 0; if ((selection & DH_POSSIBLE_SELECTIONS) == 0) return 0; /* a key without parameters is meaningless */ ok = ok && ossl_dh_params_fromdata(dh, params); if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) { int include_private = selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY ? 1 : 0; ok = ok && ossl_dh_key_fromdata(dh, params, include_private); } return ok; } static int dh_export(void *keydata, int selection, OSSL_CALLBACK *param_cb, void *cbarg) { DH *dh = keydata; OSSL_PARAM_BLD *tmpl = NULL; OSSL_PARAM *params = NULL; int ok = 1; if (!ossl_prov_is_running() || dh == NULL) return 0; if ((selection & DH_POSSIBLE_SELECTIONS) == 0) return 0; tmpl = OSSL_PARAM_BLD_new(); if (tmpl == NULL) return 0; if ((selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0) ok = ok && ossl_dh_params_todata(dh, tmpl, NULL); if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) { int include_private = selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY ? 1 : 0; ok = ok && ossl_dh_key_todata(dh, tmpl, NULL, include_private); } if (!ok || (params = OSSL_PARAM_BLD_to_param(tmpl)) == NULL) { ok = 0; goto err; } ok = param_cb(params, cbarg); OSSL_PARAM_free(params); err: OSSL_PARAM_BLD_free(tmpl); return ok; } /* IMEXPORT = IMPORT + EXPORT */ # define DH_IMEXPORTABLE_PARAMETERS \ OSSL_PARAM_BN(OSSL_PKEY_PARAM_FFC_P, NULL, 0), \ OSSL_PARAM_BN(OSSL_PKEY_PARAM_FFC_Q, NULL, 0), \ OSSL_PARAM_BN(OSSL_PKEY_PARAM_FFC_G, NULL, 0), \ OSSL_PARAM_BN(OSSL_PKEY_PARAM_FFC_COFACTOR, NULL, 0), \ OSSL_PARAM_int(OSSL_PKEY_PARAM_FFC_GINDEX, NULL), \ OSSL_PARAM_int(OSSL_PKEY_PARAM_FFC_PCOUNTER, NULL), \ OSSL_PARAM_int(OSSL_PKEY_PARAM_FFC_H, NULL), \ OSSL_PARAM_int(OSSL_PKEY_PARAM_DH_PRIV_LEN, NULL), \ OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_FFC_SEED, NULL, 0), \ OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_GROUP_NAME, NULL, 0) # define DH_IMEXPORTABLE_PUBLIC_KEY \ OSSL_PARAM_BN(OSSL_PKEY_PARAM_PUB_KEY, NULL, 0) # define DH_IMEXPORTABLE_PRIVATE_KEY \ OSSL_PARAM_BN(OSSL_PKEY_PARAM_PRIV_KEY, NULL, 0) static const OSSL_PARAM dh_all_types[] = { DH_IMEXPORTABLE_PARAMETERS, DH_IMEXPORTABLE_PUBLIC_KEY, DH_IMEXPORTABLE_PRIVATE_KEY, OSSL_PARAM_END }; static const OSSL_PARAM dh_parameter_types[] = { DH_IMEXPORTABLE_PARAMETERS, OSSL_PARAM_END }; static const OSSL_PARAM dh_key_types[] = { DH_IMEXPORTABLE_PUBLIC_KEY, DH_IMEXPORTABLE_PRIVATE_KEY, OSSL_PARAM_END }; static const OSSL_PARAM *dh_types[] = { NULL, /* Index 0 = none of them */ dh_parameter_types, /* Index 1 = parameter types */ dh_key_types, /* Index 2 = key types */ dh_all_types /* Index 3 = 1 + 2 */ }; static const OSSL_PARAM *dh_imexport_types(int selection) { int type_select = 0; if ((selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0) type_select += 1; if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) type_select += 2; return dh_types[type_select]; } static const OSSL_PARAM *dh_import_types(int selection) { return dh_imexport_types(selection); } static const OSSL_PARAM *dh_export_types(int selection) { return dh_imexport_types(selection); } static ossl_inline int dh_get_params(void *key, OSSL_PARAM params[]) { DH *dh = key; OSSL_PARAM *p; if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_BITS)) != NULL && !OSSL_PARAM_set_int(p, DH_bits(dh))) return 0; if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_SECURITY_BITS)) != NULL && !OSSL_PARAM_set_int(p, DH_security_bits(dh))) return 0; if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_MAX_SIZE)) != NULL && !OSSL_PARAM_set_int(p, DH_size(dh))) return 0; if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY)) != NULL) { if (p->data_type != OSSL_PARAM_OCTET_STRING) return 0; p->return_size = ossl_dh_key2buf(dh, (unsigned char **)&p->data, p->data_size, 0); if (p->return_size == 0) return 0; } return ossl_dh_params_todata(dh, NULL, params) && ossl_dh_key_todata(dh, NULL, params, 1); } static const OSSL_PARAM dh_params[] = { OSSL_PARAM_int(OSSL_PKEY_PARAM_BITS, NULL), OSSL_PARAM_int(OSSL_PKEY_PARAM_SECURITY_BITS, NULL), OSSL_PARAM_int(OSSL_PKEY_PARAM_MAX_SIZE, NULL), OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY, NULL, 0), DH_IMEXPORTABLE_PARAMETERS, DH_IMEXPORTABLE_PUBLIC_KEY, DH_IMEXPORTABLE_PRIVATE_KEY, OSSL_PARAM_END }; static const OSSL_PARAM *dh_gettable_params(void *provctx) { return dh_params; } static const OSSL_PARAM dh_known_settable_params[] = { OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY, NULL, 0), OSSL_PARAM_END }; static const OSSL_PARAM *dh_settable_params(void *provctx) { return dh_known_settable_params; } static int dh_set_params(void *key, const OSSL_PARAM params[]) { DH *dh = key; const OSSL_PARAM *p; p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY); if (p != NULL && (p->data_type != OSSL_PARAM_OCTET_STRING || !ossl_dh_buf2key(dh, p->data, p->data_size))) return 0; return 1; } static int dh_validate_public(const DH *dh, int checktype) { const BIGNUM *pub_key = NULL; int res = 0; DH_get0_key(dh, &pub_key, NULL); if (pub_key == NULL) return 0; /* The partial test is only valid for named group's with q = (p - 1) / 2 */ if (checktype == OSSL_KEYMGMT_VALIDATE_QUICK_CHECK && ossl_dh_is_named_safe_prime_group(dh)) return ossl_dh_check_pub_key_partial(dh, pub_key, &res); - return DH_check_pub_key(dh, pub_key, &res); + return DH_check_pub_key_ex(dh, pub_key); } static int dh_validate_private(const DH *dh) { int status = 0; const BIGNUM *priv_key = NULL; DH_get0_key(dh, NULL, &priv_key); if (priv_key == NULL) return 0; return ossl_dh_check_priv_key(dh, priv_key, &status);; } static int dh_validate(const void *keydata, int selection, int checktype) { const DH *dh = keydata; int ok = 1; if (!ossl_prov_is_running()) return 0; if ((selection & DH_POSSIBLE_SELECTIONS) == 0) return 1; /* nothing to validate */ if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0) { /* * Both of these functions check parameters. DH_check_params_ex() * performs a lightweight check (e.g. it does not check that p is a * safe prime) */ if (checktype == OSSL_KEYMGMT_VALIDATE_QUICK_CHECK) ok = ok && DH_check_params_ex(dh); else ok = ok && DH_check_ex(dh); } if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) ok = ok && dh_validate_public(dh, checktype); if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) ok = ok && dh_validate_private(dh); if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) == OSSL_KEYMGMT_SELECT_KEYPAIR) ok = ok && ossl_dh_check_pairwise(dh); return ok; } static void *dh_gen_init_base(void *provctx, int selection, const OSSL_PARAM params[], int type) { OSSL_LIB_CTX *libctx = PROV_LIBCTX_OF(provctx); struct dh_gen_ctx *gctx = NULL; if (!ossl_prov_is_running()) return NULL; if ((selection & (OSSL_KEYMGMT_SELECT_KEYPAIR | OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS)) == 0) return NULL; if ((gctx = OPENSSL_zalloc(sizeof(*gctx))) != NULL) { gctx->selection = selection; gctx->libctx = libctx; gctx->pbits = 2048; gctx->qbits = 224; gctx->mdname = NULL; #ifdef FIPS_MODULE gctx->gen_type = (type == DH_FLAG_TYPE_DHX) ? DH_PARAMGEN_TYPE_FIPS_186_4 : DH_PARAMGEN_TYPE_GROUP; #else gctx->gen_type = (type == DH_FLAG_TYPE_DHX) ? DH_PARAMGEN_TYPE_FIPS_186_2 : DH_PARAMGEN_TYPE_GENERATOR; #endif gctx->gindex = -1; gctx->hindex = 0; gctx->pcounter = -1; gctx->generator = DH_GENERATOR_2; gctx->dh_type = type; } if (!dh_gen_set_params(gctx, params)) { OPENSSL_free(gctx); gctx = NULL; } return gctx; } static void *dh_gen_init(void *provctx, int selection, const OSSL_PARAM params[]) { return dh_gen_init_base(provctx, selection, params, DH_FLAG_TYPE_DH); } static void *dhx_gen_init(void *provctx, int selection, const OSSL_PARAM params[]) { return dh_gen_init_base(provctx, selection, params, DH_FLAG_TYPE_DHX); } static int dh_gen_set_template(void *genctx, void *templ) { struct dh_gen_ctx *gctx = genctx; DH *dh = templ; if (!ossl_prov_is_running() || gctx == NULL || dh == NULL) return 0; gctx->ffc_params = ossl_dh_get0_params(dh); return 1; } static int dh_set_gen_seed(struct dh_gen_ctx *gctx, unsigned char *seed, size_t seedlen) { OPENSSL_clear_free(gctx->seed, gctx->seedlen); gctx->seed = NULL; gctx->seedlen = 0; if (seed != NULL && seedlen > 0) { gctx->seed = OPENSSL_memdup(seed, seedlen); if (gctx->seed == NULL) return 0; gctx->seedlen = seedlen; } return 1; } static int dh_gen_common_set_params(void *genctx, const OSSL_PARAM params[]) { struct dh_gen_ctx *gctx = genctx; const OSSL_PARAM *p; if (gctx == NULL) return 0; if (params == NULL) return 1; p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_TYPE); if (p != NULL) { if (p->data_type != OSSL_PARAM_UTF8_STRING || ((gctx->gen_type = dh_gen_type_name2id_w_default(p->data, gctx->dh_type)) == -1)) { ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_INVALID_ARGUMENT); return 0; } } p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_GROUP_NAME); if (p != NULL) { const DH_NAMED_GROUP *group = NULL; if (p->data_type != OSSL_PARAM_UTF8_STRING || p->data == NULL || (group = ossl_ffc_name_to_dh_named_group(p->data)) == NULL || ((gctx->group_nid = ossl_ffc_named_group_get_uid(group)) == NID_undef)) { ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_INVALID_ARGUMENT); return 0; } } if ((p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_PBITS)) != NULL && !OSSL_PARAM_get_size_t(p, &gctx->pbits)) return 0; p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_DH_PRIV_LEN); if (p != NULL && !OSSL_PARAM_get_int(p, &gctx->priv_len)) return 0; return 1; } static const OSSL_PARAM *dh_gen_settable_params(ossl_unused void *genctx, ossl_unused void *provctx) { static const OSSL_PARAM dh_gen_settable[] = { OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_FFC_TYPE, NULL, 0), OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_GROUP_NAME, NULL, 0), OSSL_PARAM_int(OSSL_PKEY_PARAM_DH_PRIV_LEN, NULL), OSSL_PARAM_size_t(OSSL_PKEY_PARAM_FFC_PBITS, NULL), OSSL_PARAM_int(OSSL_PKEY_PARAM_DH_GENERATOR, NULL), OSSL_PARAM_END }; return dh_gen_settable; } static const OSSL_PARAM *dhx_gen_settable_params(ossl_unused void *genctx, ossl_unused void *provctx) { static const OSSL_PARAM dhx_gen_settable[] = { OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_FFC_TYPE, NULL, 0), OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_GROUP_NAME, NULL, 0), OSSL_PARAM_int(OSSL_PKEY_PARAM_DH_PRIV_LEN, NULL), OSSL_PARAM_size_t(OSSL_PKEY_PARAM_FFC_PBITS, NULL), OSSL_PARAM_size_t(OSSL_PKEY_PARAM_FFC_QBITS, NULL), OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_FFC_DIGEST, NULL, 0), OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_FFC_DIGEST_PROPS, NULL, 0), OSSL_PARAM_int(OSSL_PKEY_PARAM_FFC_GINDEX, NULL), OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_FFC_SEED, NULL, 0), OSSL_PARAM_int(OSSL_PKEY_PARAM_FFC_PCOUNTER, NULL), OSSL_PARAM_int(OSSL_PKEY_PARAM_FFC_H, NULL), OSSL_PARAM_END }; return dhx_gen_settable; } static int dhx_gen_set_params(void *genctx, const OSSL_PARAM params[]) { struct dh_gen_ctx *gctx = genctx; const OSSL_PARAM *p; if (!dh_gen_common_set_params(genctx, params)) return 0; /* Parameters related to fips186-4 and fips186-2 */ p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_GINDEX); if (p != NULL && !OSSL_PARAM_get_int(p, &gctx->gindex)) return 0; p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_PCOUNTER); if (p != NULL && !OSSL_PARAM_get_int(p, &gctx->pcounter)) return 0; p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_H); if (p != NULL && !OSSL_PARAM_get_int(p, &gctx->hindex)) return 0; p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_SEED); if (p != NULL && (p->data_type != OSSL_PARAM_OCTET_STRING || !dh_set_gen_seed(gctx, p->data, p->data_size))) return 0; if ((p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_QBITS)) != NULL && !OSSL_PARAM_get_size_t(p, &gctx->qbits)) return 0; p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_DIGEST); if (p != NULL) { if (p->data_type != OSSL_PARAM_UTF8_STRING) return 0; OPENSSL_free(gctx->mdname); gctx->mdname = OPENSSL_strdup(p->data); if (gctx->mdname == NULL) return 0; } p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_DIGEST_PROPS); if (p != NULL) { if (p->data_type != OSSL_PARAM_UTF8_STRING) return 0; OPENSSL_free(gctx->mdprops); gctx->mdprops = OPENSSL_strdup(p->data); if (gctx->mdprops == NULL) return 0; } /* Parameters that are not allowed for DHX */ p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_DH_GENERATOR); if (p != NULL) { ERR_raise(ERR_LIB_PROV, ERR_R_UNSUPPORTED); return 0; } return 1; } static int dh_gen_set_params(void *genctx, const OSSL_PARAM params[]) { struct dh_gen_ctx *gctx = genctx; const OSSL_PARAM *p; if (!dh_gen_common_set_params(genctx, params)) return 0; p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_DH_GENERATOR); if (p != NULL && !OSSL_PARAM_get_int(p, &gctx->generator)) return 0; /* Parameters that are not allowed for DH */ if (OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_GINDEX) != NULL || OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_PCOUNTER) != NULL || OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_H) != NULL || OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_SEED) != NULL || OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_QBITS) != NULL || OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_DIGEST) != NULL || OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_DIGEST_PROPS) != NULL) { ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_INVALID_ARGUMENT); return 0; } return 1; } static int dh_gencb(int p, int n, BN_GENCB *cb) { struct dh_gen_ctx *gctx = BN_GENCB_get_arg(cb); OSSL_PARAM params[] = { OSSL_PARAM_END, OSSL_PARAM_END, OSSL_PARAM_END }; params[0] = OSSL_PARAM_construct_int(OSSL_GEN_PARAM_POTENTIAL, &p); params[1] = OSSL_PARAM_construct_int(OSSL_GEN_PARAM_ITERATION, &n); return gctx->cb(params, gctx->cbarg); } static void *dh_gen(void *genctx, OSSL_CALLBACK *osslcb, void *cbarg) { int ret = 0; struct dh_gen_ctx *gctx = genctx; DH *dh = NULL; BN_GENCB *gencb = NULL; FFC_PARAMS *ffc; if (!ossl_prov_is_running() || gctx == NULL) return NULL; /* * If a group name is selected then the type is group regardless of what the * the user selected. This overrides rather than errors for backwards * compatibility. */ if (gctx->group_nid != NID_undef) gctx->gen_type = DH_PARAMGEN_TYPE_GROUP; /* For parameter generation - If there is a group name just create it */ if (gctx->gen_type == DH_PARAMGEN_TYPE_GROUP && gctx->ffc_params == NULL) { /* Select a named group if there is not one already */ if (gctx->group_nid == NID_undef) gctx->group_nid = ossl_dh_get_named_group_uid_from_size(gctx->pbits); if (gctx->group_nid == NID_undef) return NULL; dh = ossl_dh_new_by_nid_ex(gctx->libctx, gctx->group_nid); if (dh == NULL) return NULL; ffc = ossl_dh_get0_params(dh); } else { dh = ossl_dh_new_ex(gctx->libctx); if (dh == NULL) return NULL; ffc = ossl_dh_get0_params(dh); /* Copy the template value if one was passed */ if (gctx->ffc_params != NULL && !ossl_ffc_params_copy(ffc, gctx->ffc_params)) goto end; if (!ossl_ffc_params_set_seed(ffc, gctx->seed, gctx->seedlen)) goto end; if (gctx->gindex != -1) { ossl_ffc_params_set_gindex(ffc, gctx->gindex); if (gctx->pcounter != -1) ossl_ffc_params_set_pcounter(ffc, gctx->pcounter); } else if (gctx->hindex != 0) { ossl_ffc_params_set_h(ffc, gctx->hindex); } if (gctx->mdname != NULL) { if (!ossl_ffc_set_digest(ffc, gctx->mdname, gctx->mdprops)) goto end; } gctx->cb = osslcb; gctx->cbarg = cbarg; gencb = BN_GENCB_new(); if (gencb != NULL) BN_GENCB_set(gencb, dh_gencb, genctx); if ((gctx->selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0) { /* * NOTE: The old safe prime generator code is not used in fips mode, * (i.e internally it ignores the generator and chooses a named * group based on pbits. */ if (gctx->gen_type == DH_PARAMGEN_TYPE_GENERATOR) ret = DH_generate_parameters_ex(dh, gctx->pbits, gctx->generator, gencb); else ret = ossl_dh_generate_ffc_parameters(dh, gctx->gen_type, gctx->pbits, gctx->qbits, gencb); if (ret <= 0) goto end; } } if ((gctx->selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) { if (ffc->p == NULL || ffc->g == NULL) goto end; if (gctx->priv_len > 0) DH_set_length(dh, (long)gctx->priv_len); ossl_ffc_params_enable_flags(ffc, FFC_PARAM_FLAG_VALIDATE_LEGACY, gctx->gen_type == DH_PARAMGEN_TYPE_FIPS_186_2); if (DH_generate_key(dh) <= 0) goto end; } DH_clear_flags(dh, DH_FLAG_TYPE_MASK); DH_set_flags(dh, gctx->dh_type); ret = 1; end: if (ret <= 0) { DH_free(dh); dh = NULL; } BN_GENCB_free(gencb); return dh; } static void dh_gen_cleanup(void *genctx) { struct dh_gen_ctx *gctx = genctx; if (gctx == NULL) return; OPENSSL_free(gctx->mdname); OPENSSL_free(gctx->mdprops); OPENSSL_clear_free(gctx->seed, gctx->seedlen); OPENSSL_free(gctx); } static void *dh_load(const void *reference, size_t reference_sz) { DH *dh = NULL; if (ossl_prov_is_running() && reference_sz == sizeof(dh)) { /* The contents of the reference is the address to our object */ dh = *(DH **)reference; /* We grabbed, so we detach it */ *(DH **)reference = NULL; return dh; } return NULL; } static void *dh_dup(const void *keydata_from, int selection) { if (ossl_prov_is_running()) return ossl_dh_dup(keydata_from, selection); return NULL; } const OSSL_DISPATCH ossl_dh_keymgmt_functions[] = { { OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))dh_newdata }, { OSSL_FUNC_KEYMGMT_GEN_INIT, (void (*)(void))dh_gen_init }, { OSSL_FUNC_KEYMGMT_GEN_SET_TEMPLATE, (void (*)(void))dh_gen_set_template }, { OSSL_FUNC_KEYMGMT_GEN_SET_PARAMS, (void (*)(void))dh_gen_set_params }, { OSSL_FUNC_KEYMGMT_GEN_SETTABLE_PARAMS, (void (*)(void))dh_gen_settable_params }, { OSSL_FUNC_KEYMGMT_GEN, (void (*)(void))dh_gen }, { OSSL_FUNC_KEYMGMT_GEN_CLEANUP, (void (*)(void))dh_gen_cleanup }, { OSSL_FUNC_KEYMGMT_LOAD, (void (*)(void))dh_load }, { OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))dh_freedata }, { OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*) (void))dh_get_params }, { OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*) (void))dh_gettable_params }, { OSSL_FUNC_KEYMGMT_SET_PARAMS, (void (*) (void))dh_set_params }, { OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS, (void (*) (void))dh_settable_params }, { OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))dh_has }, { OSSL_FUNC_KEYMGMT_MATCH, (void (*)(void))dh_match }, { OSSL_FUNC_KEYMGMT_VALIDATE, (void (*)(void))dh_validate }, { OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))dh_import }, { OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))dh_import_types }, { OSSL_FUNC_KEYMGMT_EXPORT, (void (*)(void))dh_export }, { OSSL_FUNC_KEYMGMT_EXPORT_TYPES, (void (*)(void))dh_export_types }, { OSSL_FUNC_KEYMGMT_DUP, (void (*)(void))dh_dup }, { 0, NULL } }; /* For any DH key, we use the "DH" algorithms regardless of sub-type. */ static const char *dhx_query_operation_name(int operation_id) { return "DH"; } const OSSL_DISPATCH ossl_dhx_keymgmt_functions[] = { { OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))dhx_newdata }, { OSSL_FUNC_KEYMGMT_GEN_INIT, (void (*)(void))dhx_gen_init }, { OSSL_FUNC_KEYMGMT_GEN_SET_TEMPLATE, (void (*)(void))dh_gen_set_template }, { OSSL_FUNC_KEYMGMT_GEN_SET_PARAMS, (void (*)(void))dhx_gen_set_params }, { OSSL_FUNC_KEYMGMT_GEN_SETTABLE_PARAMS, (void (*)(void))dhx_gen_settable_params }, { OSSL_FUNC_KEYMGMT_GEN, (void (*)(void))dh_gen }, { OSSL_FUNC_KEYMGMT_GEN_CLEANUP, (void (*)(void))dh_gen_cleanup }, { OSSL_FUNC_KEYMGMT_LOAD, (void (*)(void))dh_load }, { OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))dh_freedata }, { OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*) (void))dh_get_params }, { OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*) (void))dh_gettable_params }, { OSSL_FUNC_KEYMGMT_SET_PARAMS, (void (*) (void))dh_set_params }, { OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS, (void (*) (void))dh_settable_params }, { OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))dh_has }, { OSSL_FUNC_KEYMGMT_MATCH, (void (*)(void))dh_match }, { OSSL_FUNC_KEYMGMT_VALIDATE, (void (*)(void))dh_validate }, { OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))dh_import }, { OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))dh_import_types }, { OSSL_FUNC_KEYMGMT_EXPORT, (void (*)(void))dh_export }, { OSSL_FUNC_KEYMGMT_EXPORT_TYPES, (void (*)(void))dh_export_types }, { OSSL_FUNC_KEYMGMT_QUERY_OPERATION_NAME, (void (*)(void))dhx_query_operation_name }, { OSSL_FUNC_KEYMGMT_DUP, (void (*)(void))dh_dup }, { 0, NULL } }; diff --git a/crypto/openssl/providers/implementations/macs/kmac_prov.c b/crypto/openssl/providers/implementations/macs/kmac_prov.c index b2f85398b4e2..99e7c60a74ce 100644 --- a/crypto/openssl/providers/implementations/macs/kmac_prov.c +++ b/crypto/openssl/providers/implementations/macs/kmac_prov.c @@ -1,627 +1,627 @@ /* - * Copyright 2018-2021 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2018-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ /* * See SP800-185 "Appendix A - KMAC, .... in Terms of Keccak[c]" * * Inputs are: * K = Key (len(K) < 2^2040 bits) * X = Input * L = Output length (0 <= L < 2^2040 bits) * S = Customization String Default="" (len(S) < 2^2040 bits) * * KMAC128(K, X, L, S) * { * newX = bytepad(encode_string(K), 168) || X || right_encode(L). * T = bytepad(encode_string("KMAC") || encode_string(S), 168). * return KECCAK[256](T || newX || 00, L). * } * * KMAC256(K, X, L, S) * { * newX = bytepad(encode_string(K), 136) || X || right_encode(L). * T = bytepad(encode_string("KMAC") || encode_string(S), 136). * return KECCAK[512](T || newX || 00, L). * } * * KMAC128XOF(K, X, L, S) * { * newX = bytepad(encode_string(K), 168) || X || right_encode(0). * T = bytepad(encode_string("KMAC") || encode_string(S), 168). * return KECCAK[256](T || newX || 00, L). * } * * KMAC256XOF(K, X, L, S) * { * newX = bytepad(encode_string(K), 136) || X || right_encode(0). * T = bytepad(encode_string("KMAC") || encode_string(S), 136). * return KECCAK[512](T || newX || 00, L). * } * */ #include #include #include #include #include #include #include #include #include "prov/implementations.h" #include "prov/provider_ctx.h" #include "prov/provider_util.h" #include "prov/providercommon.h" #include "internal/cryptlib.h" /* ossl_assert */ /* * Forward declaration of everything implemented here. This is not strictly * necessary for the compiler, but provides an assurance that the signatures * of the functions in the dispatch table are correct. */ static OSSL_FUNC_mac_newctx_fn kmac128_new; static OSSL_FUNC_mac_newctx_fn kmac256_new; static OSSL_FUNC_mac_dupctx_fn kmac_dup; static OSSL_FUNC_mac_freectx_fn kmac_free; static OSSL_FUNC_mac_gettable_ctx_params_fn kmac_gettable_ctx_params; static OSSL_FUNC_mac_get_ctx_params_fn kmac_get_ctx_params; static OSSL_FUNC_mac_settable_ctx_params_fn kmac_settable_ctx_params; static OSSL_FUNC_mac_set_ctx_params_fn kmac_set_ctx_params; static OSSL_FUNC_mac_init_fn kmac_init; static OSSL_FUNC_mac_update_fn kmac_update; static OSSL_FUNC_mac_final_fn kmac_final; #define KMAC_MAX_BLOCKSIZE ((1600 - 128 * 2) / 8) /* 168 */ /* * Length encoding will be a 1 byte size + length in bits (3 bytes max) * This gives a range of 0..0XFFFFFF bits = 2097151 bytes). */ #define KMAC_MAX_OUTPUT_LEN (0xFFFFFF / 8) #define KMAC_MAX_ENCODED_HEADER_LEN (1 + 3) /* * Restrict the maximum length of the customisation string. This must not * exceed 64 bits = 8k bytes. */ #define KMAC_MAX_CUSTOM 512 /* Maximum size of encoded custom string */ #define KMAC_MAX_CUSTOM_ENCODED (KMAC_MAX_CUSTOM + KMAC_MAX_ENCODED_HEADER_LEN) /* Maximum key size in bytes = 512 (4096 bits) */ #define KMAC_MAX_KEY 512 #define KMAC_MIN_KEY 4 /* * Maximum Encoded Key size will be padded to a multiple of the blocksize * i.e KMAC_MAX_KEY + KMAC_MAX_ENCODED_HEADER_LEN = 512 + 4 * Padded to a multiple of KMAC_MAX_BLOCKSIZE */ #define KMAC_MAX_KEY_ENCODED (KMAC_MAX_BLOCKSIZE * 4) /* Fixed value of encode_string("KMAC") */ static const unsigned char kmac_string[] = { 0x01, 0x20, 0x4B, 0x4D, 0x41, 0x43 }; #define KMAC_FLAG_XOF_MODE 1 struct kmac_data_st { void *provctx; EVP_MD_CTX *ctx; PROV_DIGEST digest; size_t out_len; size_t key_len; size_t custom_len; /* If xof_mode = 1 then we use right_encode(0) */ int xof_mode; /* key and custom are stored in encoded form */ unsigned char key[KMAC_MAX_KEY_ENCODED]; unsigned char custom[KMAC_MAX_CUSTOM_ENCODED]; }; static int encode_string(unsigned char *out, size_t out_max_len, size_t *out_len, const unsigned char *in, size_t in_len); static int right_encode(unsigned char *out, size_t out_max_len, size_t *out_len, size_t bits); static int bytepad(unsigned char *out, size_t *out_len, const unsigned char *in1, size_t in1_len, const unsigned char *in2, size_t in2_len, size_t w); static int kmac_bytepad_encode_key(unsigned char *out, size_t out_max_len, size_t *out_len, const unsigned char *in, size_t in_len, size_t w); static void kmac_free(void *vmacctx) { struct kmac_data_st *kctx = vmacctx; if (kctx != NULL) { EVP_MD_CTX_free(kctx->ctx); ossl_prov_digest_reset(&kctx->digest); OPENSSL_cleanse(kctx->key, kctx->key_len); OPENSSL_cleanse(kctx->custom, kctx->custom_len); OPENSSL_free(kctx); } } /* * We have KMAC implemented as a hash, which we can use instead of * reimplementing the EVP functionality with direct use of * keccak_mac_init() and friends. */ static struct kmac_data_st *kmac_new(void *provctx) { struct kmac_data_st *kctx; if (!ossl_prov_is_running()) return NULL; if ((kctx = OPENSSL_zalloc(sizeof(*kctx))) == NULL || (kctx->ctx = EVP_MD_CTX_new()) == NULL) { kmac_free(kctx); return NULL; } kctx->provctx = provctx; return kctx; } static void *kmac_fetch_new(void *provctx, const OSSL_PARAM *params) { struct kmac_data_st *kctx = kmac_new(provctx); if (kctx == NULL) return 0; if (!ossl_prov_digest_load_from_params(&kctx->digest, params, PROV_LIBCTX_OF(provctx))) { kmac_free(kctx); return 0; } kctx->out_len = EVP_MD_get_size(ossl_prov_digest_md(&kctx->digest)); return kctx; } static void *kmac128_new(void *provctx) { static const OSSL_PARAM kmac128_params[] = { OSSL_PARAM_utf8_string("digest", OSSL_DIGEST_NAME_KECCAK_KMAC128, sizeof(OSSL_DIGEST_NAME_KECCAK_KMAC128)), OSSL_PARAM_END }; return kmac_fetch_new(provctx, kmac128_params); } static void *kmac256_new(void *provctx) { static const OSSL_PARAM kmac256_params[] = { OSSL_PARAM_utf8_string("digest", OSSL_DIGEST_NAME_KECCAK_KMAC256, sizeof(OSSL_DIGEST_NAME_KECCAK_KMAC256)), OSSL_PARAM_END }; return kmac_fetch_new(provctx, kmac256_params); } static void *kmac_dup(void *vsrc) { struct kmac_data_st *src = vsrc; struct kmac_data_st *dst; if (!ossl_prov_is_running()) return NULL; dst = kmac_new(src->provctx); if (dst == NULL) return NULL; if (!EVP_MD_CTX_copy(dst->ctx, src->ctx) || !ossl_prov_digest_copy(&dst->digest, &src->digest)) { kmac_free(dst); return NULL; } dst->out_len = src->out_len; dst->key_len = src->key_len; dst->custom_len = src->custom_len; dst->xof_mode = src->xof_mode; memcpy(dst->key, src->key, src->key_len); memcpy(dst->custom, src->custom, dst->custom_len); return dst; } static int kmac_setkey(struct kmac_data_st *kctx, const unsigned char *key, size_t keylen) { const EVP_MD *digest = ossl_prov_digest_md(&kctx->digest); int w = EVP_MD_get_block_size(digest); if (keylen < KMAC_MIN_KEY || keylen > KMAC_MAX_KEY) { ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH); return 0; } - if (w < 0) { + if (w <= 0) { ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DIGEST_LENGTH); return 0; } if (!kmac_bytepad_encode_key(kctx->key, sizeof(kctx->key), &kctx->key_len, key, keylen, (size_t)w)) return 0; return 1; } /* * The init() assumes that any ctrl methods are set beforehand for * md, key and custom. Setting the fields afterwards will have no * effect on the output mac. */ static int kmac_init(void *vmacctx, const unsigned char *key, size_t keylen, const OSSL_PARAM params[]) { struct kmac_data_st *kctx = vmacctx; EVP_MD_CTX *ctx = kctx->ctx; unsigned char *out; size_t out_len, block_len; int res, t; if (!ossl_prov_is_running() || !kmac_set_ctx_params(kctx, params)) return 0; if (key != NULL) { if (!kmac_setkey(kctx, key, keylen)) return 0; } else if (kctx->key_len == 0) { /* Check key has been set */ ERR_raise(ERR_LIB_PROV, PROV_R_NO_KEY_SET); return 0; } if (!EVP_DigestInit_ex(kctx->ctx, ossl_prov_digest_md(&kctx->digest), NULL)) return 0; t = EVP_MD_get_block_size(ossl_prov_digest_md(&kctx->digest)); - if (t < 0) { + if (t <= 0) { ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DIGEST_LENGTH); return 0; } block_len = t; /* Set default custom string if it is not already set */ if (kctx->custom_len == 0) { const OSSL_PARAM cparams[] = { OSSL_PARAM_octet_string(OSSL_MAC_PARAM_CUSTOM, "", 0), OSSL_PARAM_END }; (void)kmac_set_ctx_params(kctx, cparams); } if (!bytepad(NULL, &out_len, kmac_string, sizeof(kmac_string), kctx->custom, kctx->custom_len, block_len)) { ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR); return 0; } out = OPENSSL_malloc(out_len); if (out == NULL) { ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE); return 0; } res = bytepad(out, NULL, kmac_string, sizeof(kmac_string), kctx->custom, kctx->custom_len, block_len) && EVP_DigestUpdate(ctx, out, out_len) && EVP_DigestUpdate(ctx, kctx->key, kctx->key_len); OPENSSL_free(out); return res; } static int kmac_update(void *vmacctx, const unsigned char *data, size_t datalen) { struct kmac_data_st *kctx = vmacctx; return EVP_DigestUpdate(kctx->ctx, data, datalen); } static int kmac_final(void *vmacctx, unsigned char *out, size_t *outl, size_t outsize) { struct kmac_data_st *kctx = vmacctx; EVP_MD_CTX *ctx = kctx->ctx; size_t lbits, len; unsigned char encoded_outlen[KMAC_MAX_ENCODED_HEADER_LEN]; int ok; if (!ossl_prov_is_running()) return 0; /* KMAC XOF mode sets the encoded length to 0 */ lbits = (kctx->xof_mode ? 0 : (kctx->out_len * 8)); ok = right_encode(encoded_outlen, sizeof(encoded_outlen), &len, lbits) && EVP_DigestUpdate(ctx, encoded_outlen, len) && EVP_DigestFinalXOF(ctx, out, kctx->out_len); *outl = kctx->out_len; return ok; } static const OSSL_PARAM known_gettable_ctx_params[] = { OSSL_PARAM_size_t(OSSL_MAC_PARAM_SIZE, NULL), OSSL_PARAM_size_t(OSSL_MAC_PARAM_BLOCK_SIZE, NULL), OSSL_PARAM_END }; static const OSSL_PARAM *kmac_gettable_ctx_params(ossl_unused void *ctx, ossl_unused void *provctx) { return known_gettable_ctx_params; } static int kmac_get_ctx_params(void *vmacctx, OSSL_PARAM params[]) { struct kmac_data_st *kctx = vmacctx; OSSL_PARAM *p; int sz; if ((p = OSSL_PARAM_locate(params, OSSL_MAC_PARAM_SIZE)) != NULL && !OSSL_PARAM_set_size_t(p, kctx->out_len)) return 0; if ((p = OSSL_PARAM_locate(params, OSSL_MAC_PARAM_BLOCK_SIZE)) != NULL) { sz = EVP_MD_block_size(ossl_prov_digest_md(&kctx->digest)); if (!OSSL_PARAM_set_int(p, sz)) return 0; } return 1; } static const OSSL_PARAM known_settable_ctx_params[] = { OSSL_PARAM_int(OSSL_MAC_PARAM_XOF, NULL), OSSL_PARAM_size_t(OSSL_MAC_PARAM_SIZE, NULL), OSSL_PARAM_octet_string(OSSL_MAC_PARAM_KEY, NULL, 0), OSSL_PARAM_octet_string(OSSL_MAC_PARAM_CUSTOM, NULL, 0), OSSL_PARAM_END }; static const OSSL_PARAM *kmac_settable_ctx_params(ossl_unused void *ctx, ossl_unused void *provctx) { return known_settable_ctx_params; } /* * The following params can be set any time before final(): * - "outlen" or "size": The requested output length. * - "xof": If set, this indicates that right_encoded(0) * is part of the digested data, otherwise it * uses right_encoded(requested output length). * * All other params should be set before init(). */ static int kmac_set_ctx_params(void *vmacctx, const OSSL_PARAM *params) { struct kmac_data_st *kctx = vmacctx; const OSSL_PARAM *p; if (params == NULL) return 1; if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_XOF)) != NULL && !OSSL_PARAM_get_int(p, &kctx->xof_mode)) return 0; if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_SIZE)) != NULL) { size_t sz = 0; if (!OSSL_PARAM_get_size_t(p, &sz)) return 0; if (sz > KMAC_MAX_OUTPUT_LEN) { ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_OUTPUT_LENGTH); return 0; } kctx->out_len = sz; } if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_KEY)) != NULL && !kmac_setkey(kctx, p->data, p->data_size)) return 0; if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_CUSTOM)) != NULL) { if (p->data_size > KMAC_MAX_CUSTOM) { ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_CUSTOM_LENGTH); return 0; } if (!encode_string(kctx->custom, sizeof(kctx->custom), &kctx->custom_len, p->data, p->data_size)) return 0; } return 1; } /* Encoding/Padding Methods. */ /* Returns the number of bytes required to store 'bits' into a byte array */ static unsigned int get_encode_size(size_t bits) { unsigned int cnt = 0, sz = sizeof(size_t); while (bits && (cnt < sz)) { ++cnt; bits >>= 8; } /* If bits is zero 1 byte is required */ if (cnt == 0) cnt = 1; return cnt; } /* * Convert an integer into bytes . The number of bytes is appended * to the end of the buffer. Returns an array of bytes 'out' of size * *out_len. * * e.g if bits = 32, out[2] = { 0x20, 0x01 } */ static int right_encode(unsigned char *out, size_t out_max_len, size_t *out_len, size_t bits) { unsigned int len = get_encode_size(bits); int i; if (len >= out_max_len) { ERR_raise(ERR_LIB_PROV, PROV_R_LENGTH_TOO_LARGE); return 0; } /* MSB's are at the start of the bytes array */ for (i = len - 1; i >= 0; --i) { out[i] = (unsigned char)(bits & 0xFF); bits >>= 8; } /* Tack the length onto the end */ out[len] = (unsigned char)len; /* The Returned length includes the tacked on byte */ *out_len = len + 1; return 1; } /* * Encodes a string with a left encoded length added. Note that the * in_len is converted to bits (*8). * * e.g- in="KMAC" gives out[6] = { 0x01, 0x20, 0x4B, 0x4D, 0x41, 0x43 } * len bits K M A C */ static int encode_string(unsigned char *out, size_t out_max_len, size_t *out_len, const unsigned char *in, size_t in_len) { if (in == NULL) { *out_len = 0; } else { size_t i, bits, len, sz; bits = 8 * in_len; len = get_encode_size(bits); sz = 1 + len + in_len; if (sz > out_max_len) { ERR_raise(ERR_LIB_PROV, PROV_R_LENGTH_TOO_LARGE); return 0; } out[0] = (unsigned char)len; for (i = len; i > 0; --i) { out[i] = (bits & 0xFF); bits >>= 8; } memcpy(out + len + 1, in, in_len); *out_len = sz; } return 1; } /* * Returns a zero padded encoding of the inputs in1 and an optional * in2 (can be NULL). The padded output must be a multiple of the blocksize 'w'. * The value of w is in bytes (< 256). * * The returned output is: * zero_padded(multiple of w, (left_encode(w) || in1 [|| in2]) */ static int bytepad(unsigned char *out, size_t *out_len, const unsigned char *in1, size_t in1_len, const unsigned char *in2, size_t in2_len, size_t w) { int len; unsigned char *p = out; int sz = w; if (out == NULL) { if (out_len == NULL) { ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_NULL_PARAMETER); return 0; } sz = 2 + in1_len + (in2 != NULL ? in2_len : 0); *out_len = (sz + w - 1) / w * w; return 1; } if (!ossl_assert(w <= 255)) return 0; /* Left encoded w */ *p++ = 1; *p++ = (unsigned char)w; /* || in1 */ memcpy(p, in1, in1_len); p += in1_len; /* [ || in2 ] */ if (in2 != NULL && in2_len > 0) { memcpy(p, in2, in2_len); p += in2_len; } /* Figure out the pad size (divisible by w) */ len = p - out; sz = (len + w - 1) / w * w; /* zero pad the end of the buffer */ if (sz != len) memset(p, 0, sz - len); if (out_len != NULL) *out_len = sz; return 1; } /* Returns out = bytepad(encode_string(in), w) */ static int kmac_bytepad_encode_key(unsigned char *out, size_t out_max_len, size_t *out_len, const unsigned char *in, size_t in_len, size_t w) { unsigned char tmp[KMAC_MAX_KEY + KMAC_MAX_ENCODED_HEADER_LEN]; size_t tmp_len; if (!encode_string(tmp, sizeof(tmp), &tmp_len, in, in_len)) return 0; if (!bytepad(NULL, out_len, tmp, tmp_len, NULL, 0, w)) return 0; if (!ossl_assert(*out_len <= out_max_len)) return 0; return bytepad(out, NULL, tmp, tmp_len, NULL, 0, w); } const OSSL_DISPATCH ossl_kmac128_functions[] = { { OSSL_FUNC_MAC_NEWCTX, (void (*)(void))kmac128_new }, { OSSL_FUNC_MAC_DUPCTX, (void (*)(void))kmac_dup }, { OSSL_FUNC_MAC_FREECTX, (void (*)(void))kmac_free }, { OSSL_FUNC_MAC_INIT, (void (*)(void))kmac_init }, { OSSL_FUNC_MAC_UPDATE, (void (*)(void))kmac_update }, { OSSL_FUNC_MAC_FINAL, (void (*)(void))kmac_final }, { OSSL_FUNC_MAC_GETTABLE_CTX_PARAMS, (void (*)(void))kmac_gettable_ctx_params }, { OSSL_FUNC_MAC_GET_CTX_PARAMS, (void (*)(void))kmac_get_ctx_params }, { OSSL_FUNC_MAC_SETTABLE_CTX_PARAMS, (void (*)(void))kmac_settable_ctx_params }, { OSSL_FUNC_MAC_SET_CTX_PARAMS, (void (*)(void))kmac_set_ctx_params }, { 0, NULL } }; const OSSL_DISPATCH ossl_kmac256_functions[] = { { OSSL_FUNC_MAC_NEWCTX, (void (*)(void))kmac256_new }, { OSSL_FUNC_MAC_DUPCTX, (void (*)(void))kmac_dup }, { OSSL_FUNC_MAC_FREECTX, (void (*)(void))kmac_free }, { OSSL_FUNC_MAC_INIT, (void (*)(void))kmac_init }, { OSSL_FUNC_MAC_UPDATE, (void (*)(void))kmac_update }, { OSSL_FUNC_MAC_FINAL, (void (*)(void))kmac_final }, { OSSL_FUNC_MAC_GETTABLE_CTX_PARAMS, (void (*)(void))kmac_gettable_ctx_params }, { OSSL_FUNC_MAC_GET_CTX_PARAMS, (void (*)(void))kmac_get_ctx_params }, { OSSL_FUNC_MAC_SETTABLE_CTX_PARAMS, (void (*)(void))kmac_settable_ctx_params }, { OSSL_FUNC_MAC_SET_CTX_PARAMS, (void (*)(void))kmac_set_ctx_params }, { 0, NULL } }; diff --git a/secure/lib/libcrypto/Makefile.inc b/secure/lib/libcrypto/Makefile.inc index 7b016d988a34..65925f972ba7 100644 --- a/secure/lib/libcrypto/Makefile.inc +++ b/secure/lib/libcrypto/Makefile.inc @@ -1,22 +1,22 @@ .include # OpenSSL version used for manual page generation -OPENSSL_VER= 3.0.11 -OPENSSL_DATE= 2023-09-19 +OPENSSL_VER= 3.0.12 +OPENSSL_DATE= 2023-10-24 LCRYPTO_SRC= ${SRCTOP}/crypto/openssl LCRYPTO_DOC= ${LCRYPTO_SRC}/doc CFLAGS+= -I${LCRYPTO_SRC} CFLAGS+= -I${LCRYPTO_SRC}/include CFLAGS+= -I${LCRYPTO_SRC}/providers/common/include CFLAGS+= -I${LCRYPTO_SRC}/providers/implementations/include .include "Makefile.common" .for pcfile in ${PCFILES} ${pcfile}: ${pcfile}.in sed -e 's,@openssl_ver@,${OPENSSL_VER},g' ${.ALLSRC} > ${.TARGET} .endfor CLEANFILES+= ${PCFILES} diff --git a/sys/crypto/openssl/aarch64/aesv8-armx.S b/sys/crypto/openssl/aarch64/aesv8-armx.S index d92a1d60c65c..7666667e4782 100644 --- a/sys/crypto/openssl/aarch64/aesv8-armx.S +++ b/sys/crypto/openssl/aarch64/aesv8-armx.S @@ -1,3181 +1,3181 @@ /* Do not modify. This file is auto-generated from aesv8-armx.pl. */ #include "arm_arch.h" #if __ARM_MAX_ARCH__>=7 .arch armv8-a+crypto .text .align 5 .Lrcon: .long 0x01,0x01,0x01,0x01 .long 0x0c0f0e0d,0x0c0f0e0d,0x0c0f0e0d,0x0c0f0e0d // rotate-n-splat .long 0x1b,0x1b,0x1b,0x1b .globl aes_v8_set_encrypt_key .type aes_v8_set_encrypt_key,%function .align 5 aes_v8_set_encrypt_key: .Lenc_key: stp x29,x30,[sp,#-16]! add x29,sp,#0 mov x3,#-1 cmp x0,#0 b.eq .Lenc_key_abort cmp x2,#0 b.eq .Lenc_key_abort mov x3,#-2 cmp w1,#128 b.lt .Lenc_key_abort cmp w1,#256 b.gt .Lenc_key_abort tst w1,#0x3f b.ne .Lenc_key_abort adr x3,.Lrcon cmp w1,#192 eor v0.16b,v0.16b,v0.16b ld1 {v3.16b},[x0],#16 mov w1,#8 // reuse w1 ld1 {v1.4s,v2.4s},[x3],#32 b.lt .Loop128 b.eq .L192 b .L256 .align 4 .Loop128: tbl v6.16b,{v3.16b},v2.16b ext v5.16b,v0.16b,v3.16b,#12 st1 {v3.4s},[x2],#16 aese v6.16b,v0.16b subs w1,w1,#1 eor v3.16b,v3.16b,v5.16b ext v5.16b,v0.16b,v5.16b,#12 eor v3.16b,v3.16b,v5.16b ext v5.16b,v0.16b,v5.16b,#12 eor v6.16b,v6.16b,v1.16b eor v3.16b,v3.16b,v5.16b shl v1.16b,v1.16b,#1 eor v3.16b,v3.16b,v6.16b b.ne .Loop128 ld1 {v1.4s},[x3] tbl v6.16b,{v3.16b},v2.16b ext v5.16b,v0.16b,v3.16b,#12 st1 {v3.4s},[x2],#16 aese v6.16b,v0.16b eor v3.16b,v3.16b,v5.16b ext v5.16b,v0.16b,v5.16b,#12 eor v3.16b,v3.16b,v5.16b ext v5.16b,v0.16b,v5.16b,#12 eor v6.16b,v6.16b,v1.16b eor v3.16b,v3.16b,v5.16b shl v1.16b,v1.16b,#1 eor v3.16b,v3.16b,v6.16b tbl v6.16b,{v3.16b},v2.16b ext v5.16b,v0.16b,v3.16b,#12 st1 {v3.4s},[x2],#16 aese v6.16b,v0.16b eor v3.16b,v3.16b,v5.16b ext v5.16b,v0.16b,v5.16b,#12 eor v3.16b,v3.16b,v5.16b ext v5.16b,v0.16b,v5.16b,#12 eor v6.16b,v6.16b,v1.16b eor v3.16b,v3.16b,v5.16b eor v3.16b,v3.16b,v6.16b st1 {v3.4s},[x2] add x2,x2,#0x50 mov w12,#10 b .Ldone .align 4 .L192: ld1 {v4.8b},[x0],#8 movi v6.16b,#8 // borrow v6.16b st1 {v3.4s},[x2],#16 sub v2.16b,v2.16b,v6.16b // adjust the mask .Loop192: tbl v6.16b,{v4.16b},v2.16b ext v5.16b,v0.16b,v3.16b,#12 -#ifdef __ARMEB__ +#ifdef __AARCH64EB__ st1 {v4.4s},[x2],#16 sub x2,x2,#8 #else st1 {v4.8b},[x2],#8 #endif aese v6.16b,v0.16b subs w1,w1,#1 eor v3.16b,v3.16b,v5.16b ext v5.16b,v0.16b,v5.16b,#12 eor v3.16b,v3.16b,v5.16b ext v5.16b,v0.16b,v5.16b,#12 eor v3.16b,v3.16b,v5.16b dup v5.4s,v3.s[3] eor v5.16b,v5.16b,v4.16b eor v6.16b,v6.16b,v1.16b ext v4.16b,v0.16b,v4.16b,#12 shl v1.16b,v1.16b,#1 eor v4.16b,v4.16b,v5.16b eor v3.16b,v3.16b,v6.16b eor v4.16b,v4.16b,v6.16b st1 {v3.4s},[x2],#16 b.ne .Loop192 mov w12,#12 add x2,x2,#0x20 b .Ldone .align 4 .L256: ld1 {v4.16b},[x0] mov w1,#7 mov w12,#14 st1 {v3.4s},[x2],#16 .Loop256: tbl v6.16b,{v4.16b},v2.16b ext v5.16b,v0.16b,v3.16b,#12 st1 {v4.4s},[x2],#16 aese v6.16b,v0.16b subs w1,w1,#1 eor v3.16b,v3.16b,v5.16b ext v5.16b,v0.16b,v5.16b,#12 eor v3.16b,v3.16b,v5.16b ext v5.16b,v0.16b,v5.16b,#12 eor v6.16b,v6.16b,v1.16b eor v3.16b,v3.16b,v5.16b shl v1.16b,v1.16b,#1 eor v3.16b,v3.16b,v6.16b st1 {v3.4s},[x2],#16 b.eq .Ldone dup v6.4s,v3.s[3] // just splat ext v5.16b,v0.16b,v4.16b,#12 aese v6.16b,v0.16b eor v4.16b,v4.16b,v5.16b ext v5.16b,v0.16b,v5.16b,#12 eor v4.16b,v4.16b,v5.16b ext v5.16b,v0.16b,v5.16b,#12 eor v4.16b,v4.16b,v5.16b eor v4.16b,v4.16b,v6.16b b .Loop256 .Ldone: str w12,[x2] mov x3,#0 .Lenc_key_abort: mov x0,x3 // return value ldr x29,[sp],#16 ret .size aes_v8_set_encrypt_key,.-aes_v8_set_encrypt_key .globl aes_v8_set_decrypt_key .type aes_v8_set_decrypt_key,%function .align 5 aes_v8_set_decrypt_key: .inst 0xd503233f // paciasp stp x29,x30,[sp,#-16]! add x29,sp,#0 bl .Lenc_key cmp x0,#0 b.ne .Ldec_key_abort sub x2,x2,#240 // restore original x2 mov x4,#-16 add x0,x2,x12,lsl#4 // end of key schedule ld1 {v0.4s},[x2] ld1 {v1.4s},[x0] st1 {v0.4s},[x0],x4 st1 {v1.4s},[x2],#16 .Loop_imc: ld1 {v0.4s},[x2] ld1 {v1.4s},[x0] aesimc v0.16b,v0.16b aesimc v1.16b,v1.16b st1 {v0.4s},[x0],x4 st1 {v1.4s},[x2],#16 cmp x0,x2 b.hi .Loop_imc ld1 {v0.4s},[x2] aesimc v0.16b,v0.16b st1 {v0.4s},[x0] eor x0,x0,x0 // return value .Ldec_key_abort: ldp x29,x30,[sp],#16 .inst 0xd50323bf // autiasp ret .size aes_v8_set_decrypt_key,.-aes_v8_set_decrypt_key .globl aes_v8_encrypt .type aes_v8_encrypt,%function .align 5 aes_v8_encrypt: ldr w3,[x2,#240] ld1 {v0.4s},[x2],#16 ld1 {v2.16b},[x0] sub w3,w3,#2 ld1 {v1.4s},[x2],#16 .Loop_enc: aese v2.16b,v0.16b aesmc v2.16b,v2.16b ld1 {v0.4s},[x2],#16 subs w3,w3,#2 aese v2.16b,v1.16b aesmc v2.16b,v2.16b ld1 {v1.4s},[x2],#16 b.gt .Loop_enc aese v2.16b,v0.16b aesmc v2.16b,v2.16b ld1 {v0.4s},[x2] aese v2.16b,v1.16b eor v2.16b,v2.16b,v0.16b st1 {v2.16b},[x1] ret .size aes_v8_encrypt,.-aes_v8_encrypt .globl aes_v8_decrypt .type aes_v8_decrypt,%function .align 5 aes_v8_decrypt: ldr w3,[x2,#240] ld1 {v0.4s},[x2],#16 ld1 {v2.16b},[x0] sub w3,w3,#2 ld1 {v1.4s},[x2],#16 .Loop_dec: aesd v2.16b,v0.16b aesimc v2.16b,v2.16b ld1 {v0.4s},[x2],#16 subs w3,w3,#2 aesd v2.16b,v1.16b aesimc v2.16b,v2.16b ld1 {v1.4s},[x2],#16 b.gt .Loop_dec aesd v2.16b,v0.16b aesimc v2.16b,v2.16b ld1 {v0.4s},[x2] aesd v2.16b,v1.16b eor v2.16b,v2.16b,v0.16b st1 {v2.16b},[x1] ret .size aes_v8_decrypt,.-aes_v8_decrypt .globl aes_v8_ecb_encrypt .type aes_v8_ecb_encrypt,%function .align 5 aes_v8_ecb_encrypt: subs x2,x2,#16 // Original input data size bigger than 16, jump to big size processing. b.ne .Lecb_big_size ld1 {v0.16b},[x0] cmp w4,#0 // en- or decrypting? ldr w5,[x3,#240] ld1 {v5.4s,v6.4s},[x3],#32 // load key schedule... b.eq .Lecb_small_dec aese v0.16b,v5.16b aesmc v0.16b,v0.16b ld1 {v16.4s,v17.4s},[x3],#32 // load key schedule... aese v0.16b,v6.16b aesmc v0.16b,v0.16b subs w5,w5,#10 // if rounds==10, jump to aes-128-ecb processing b.eq .Lecb_128_enc .Lecb_round_loop: aese v0.16b,v16.16b aesmc v0.16b,v0.16b ld1 {v16.4s},[x3],#16 // load key schedule... aese v0.16b,v17.16b aesmc v0.16b,v0.16b ld1 {v17.4s},[x3],#16 // load key schedule... subs w5,w5,#2 // bias b.gt .Lecb_round_loop .Lecb_128_enc: ld1 {v18.4s,v19.4s},[x3],#32 // load key schedule... aese v0.16b,v16.16b aesmc v0.16b,v0.16b aese v0.16b,v17.16b aesmc v0.16b,v0.16b ld1 {v20.4s,v21.4s},[x3],#32 // load key schedule... aese v0.16b,v18.16b aesmc v0.16b,v0.16b aese v0.16b,v19.16b aesmc v0.16b,v0.16b ld1 {v22.4s,v23.4s},[x3],#32 // load key schedule... aese v0.16b,v20.16b aesmc v0.16b,v0.16b aese v0.16b,v21.16b aesmc v0.16b,v0.16b ld1 {v7.4s},[x3] aese v0.16b,v22.16b aesmc v0.16b,v0.16b aese v0.16b,v23.16b eor v0.16b,v0.16b,v7.16b st1 {v0.16b},[x1] b .Lecb_Final_abort .Lecb_small_dec: aesd v0.16b,v5.16b aesimc v0.16b,v0.16b ld1 {v16.4s,v17.4s},[x3],#32 // load key schedule... aesd v0.16b,v6.16b aesimc v0.16b,v0.16b subs w5,w5,#10 // bias b.eq .Lecb_128_dec .Lecb_dec_round_loop: aesd v0.16b,v16.16b aesimc v0.16b,v0.16b ld1 {v16.4s},[x3],#16 // load key schedule... aesd v0.16b,v17.16b aesimc v0.16b,v0.16b ld1 {v17.4s},[x3],#16 // load key schedule... subs w5,w5,#2 // bias b.gt .Lecb_dec_round_loop .Lecb_128_dec: ld1 {v18.4s,v19.4s},[x3],#32 // load key schedule... aesd v0.16b,v16.16b aesimc v0.16b,v0.16b aesd v0.16b,v17.16b aesimc v0.16b,v0.16b ld1 {v20.4s,v21.4s},[x3],#32 // load key schedule... aesd v0.16b,v18.16b aesimc v0.16b,v0.16b aesd v0.16b,v19.16b aesimc v0.16b,v0.16b ld1 {v22.4s,v23.4s},[x3],#32 // load key schedule... aesd v0.16b,v20.16b aesimc v0.16b,v0.16b aesd v0.16b,v21.16b aesimc v0.16b,v0.16b ld1 {v7.4s},[x3] aesd v0.16b,v22.16b aesimc v0.16b,v0.16b aesd v0.16b,v23.16b eor v0.16b,v0.16b,v7.16b st1 {v0.16b},[x1] b .Lecb_Final_abort .Lecb_big_size: stp x29,x30,[sp,#-16]! add x29,sp,#0 mov x8,#16 b.lo .Lecb_done csel x8,xzr,x8,eq cmp w4,#0 // en- or decrypting? ldr w5,[x3,#240] and x2,x2,#-16 ld1 {v0.16b},[x0],x8 ld1 {v16.4s,v17.4s},[x3] // load key schedule... sub w5,w5,#6 add x7,x3,x5,lsl#4 // pointer to last 7 round keys sub w5,w5,#2 ld1 {v18.4s,v19.4s},[x7],#32 ld1 {v20.4s,v21.4s},[x7],#32 ld1 {v22.4s,v23.4s},[x7],#32 ld1 {v7.4s},[x7] add x7,x3,#32 mov w6,w5 b.eq .Lecb_dec ld1 {v1.16b},[x0],#16 subs x2,x2,#32 // bias add w6,w5,#2 orr v3.16b,v1.16b,v1.16b orr v24.16b,v1.16b,v1.16b orr v1.16b,v0.16b,v0.16b b.lo .Lecb_enc_tail orr v1.16b,v3.16b,v3.16b ld1 {v24.16b},[x0],#16 cmp x2,#32 b.lo .Loop3x_ecb_enc ld1 {v25.16b},[x0],#16 ld1 {v26.16b},[x0],#16 sub x2,x2,#32 // bias mov w6,w5 .Loop5x_ecb_enc: aese v0.16b,v16.16b aesmc v0.16b,v0.16b aese v1.16b,v16.16b aesmc v1.16b,v1.16b aese v24.16b,v16.16b aesmc v24.16b,v24.16b aese v25.16b,v16.16b aesmc v25.16b,v25.16b aese v26.16b,v16.16b aesmc v26.16b,v26.16b ld1 {v16.4s},[x7],#16 subs w6,w6,#2 aese v0.16b,v17.16b aesmc v0.16b,v0.16b aese v1.16b,v17.16b aesmc v1.16b,v1.16b aese v24.16b,v17.16b aesmc v24.16b,v24.16b aese v25.16b,v17.16b aesmc v25.16b,v25.16b aese v26.16b,v17.16b aesmc v26.16b,v26.16b ld1 {v17.4s},[x7],#16 b.gt .Loop5x_ecb_enc aese v0.16b,v16.16b aesmc v0.16b,v0.16b aese v1.16b,v16.16b aesmc v1.16b,v1.16b aese v24.16b,v16.16b aesmc v24.16b,v24.16b aese v25.16b,v16.16b aesmc v25.16b,v25.16b aese v26.16b,v16.16b aesmc v26.16b,v26.16b cmp x2,#0x40 // because .Lecb_enc_tail4x sub x2,x2,#0x50 aese v0.16b,v17.16b aesmc v0.16b,v0.16b aese v1.16b,v17.16b aesmc v1.16b,v1.16b aese v24.16b,v17.16b aesmc v24.16b,v24.16b aese v25.16b,v17.16b aesmc v25.16b,v25.16b aese v26.16b,v17.16b aesmc v26.16b,v26.16b csel x6,xzr,x2,gt // borrow x6, w6, "gt" is not typo mov x7,x3 aese v0.16b,v18.16b aesmc v0.16b,v0.16b aese v1.16b,v18.16b aesmc v1.16b,v1.16b aese v24.16b,v18.16b aesmc v24.16b,v24.16b aese v25.16b,v18.16b aesmc v25.16b,v25.16b aese v26.16b,v18.16b aesmc v26.16b,v26.16b add x0,x0,x6 // x0 is adjusted in such way that // at exit from the loop v1.16b-v26.16b // are loaded with last "words" add x6,x2,#0x60 // because .Lecb_enc_tail4x aese v0.16b,v19.16b aesmc v0.16b,v0.16b aese v1.16b,v19.16b aesmc v1.16b,v1.16b aese v24.16b,v19.16b aesmc v24.16b,v24.16b aese v25.16b,v19.16b aesmc v25.16b,v25.16b aese v26.16b,v19.16b aesmc v26.16b,v26.16b aese v0.16b,v20.16b aesmc v0.16b,v0.16b aese v1.16b,v20.16b aesmc v1.16b,v1.16b aese v24.16b,v20.16b aesmc v24.16b,v24.16b aese v25.16b,v20.16b aesmc v25.16b,v25.16b aese v26.16b,v20.16b aesmc v26.16b,v26.16b aese v0.16b,v21.16b aesmc v0.16b,v0.16b aese v1.16b,v21.16b aesmc v1.16b,v1.16b aese v24.16b,v21.16b aesmc v24.16b,v24.16b aese v25.16b,v21.16b aesmc v25.16b,v25.16b aese v26.16b,v21.16b aesmc v26.16b,v26.16b aese v0.16b,v22.16b aesmc v0.16b,v0.16b aese v1.16b,v22.16b aesmc v1.16b,v1.16b aese v24.16b,v22.16b aesmc v24.16b,v24.16b aese v25.16b,v22.16b aesmc v25.16b,v25.16b aese v26.16b,v22.16b aesmc v26.16b,v26.16b aese v0.16b,v23.16b ld1 {v2.16b},[x0],#16 aese v1.16b,v23.16b ld1 {v3.16b},[x0],#16 aese v24.16b,v23.16b ld1 {v27.16b},[x0],#16 aese v25.16b,v23.16b ld1 {v28.16b},[x0],#16 aese v26.16b,v23.16b ld1 {v29.16b},[x0],#16 cbz x6,.Lecb_enc_tail4x ld1 {v16.4s},[x7],#16 // re-pre-load rndkey[0] eor v4.16b,v7.16b,v0.16b orr v0.16b,v2.16b,v2.16b eor v5.16b,v7.16b,v1.16b orr v1.16b,v3.16b,v3.16b eor v17.16b,v7.16b,v24.16b orr v24.16b,v27.16b,v27.16b eor v30.16b,v7.16b,v25.16b orr v25.16b,v28.16b,v28.16b eor v31.16b,v7.16b,v26.16b st1 {v4.16b},[x1],#16 orr v26.16b,v29.16b,v29.16b st1 {v5.16b},[x1],#16 mov w6,w5 st1 {v17.16b},[x1],#16 ld1 {v17.4s},[x7],#16 // re-pre-load rndkey[1] st1 {v30.16b},[x1],#16 st1 {v31.16b},[x1],#16 b.hs .Loop5x_ecb_enc add x2,x2,#0x50 cbz x2,.Lecb_done add w6,w5,#2 subs x2,x2,#0x30 orr v0.16b,v27.16b,v27.16b orr v1.16b,v28.16b,v28.16b orr v24.16b,v29.16b,v29.16b b.lo .Lecb_enc_tail b .Loop3x_ecb_enc .align 4 .Lecb_enc_tail4x: eor v5.16b,v7.16b,v1.16b eor v17.16b,v7.16b,v24.16b eor v30.16b,v7.16b,v25.16b eor v31.16b,v7.16b,v26.16b st1 {v5.16b},[x1],#16 st1 {v17.16b},[x1],#16 st1 {v30.16b},[x1],#16 st1 {v31.16b},[x1],#16 b .Lecb_done .align 4 .Loop3x_ecb_enc: aese v0.16b,v16.16b aesmc v0.16b,v0.16b aese v1.16b,v16.16b aesmc v1.16b,v1.16b aese v24.16b,v16.16b aesmc v24.16b,v24.16b ld1 {v16.4s},[x7],#16 subs w6,w6,#2 aese v0.16b,v17.16b aesmc v0.16b,v0.16b aese v1.16b,v17.16b aesmc v1.16b,v1.16b aese v24.16b,v17.16b aesmc v24.16b,v24.16b ld1 {v17.4s},[x7],#16 b.gt .Loop3x_ecb_enc aese v0.16b,v16.16b aesmc v0.16b,v0.16b aese v1.16b,v16.16b aesmc v1.16b,v1.16b aese v24.16b,v16.16b aesmc v24.16b,v24.16b subs x2,x2,#0x30 csel x6,x2,x6,lo // x6, w6, is zero at this point aese v0.16b,v17.16b aesmc v0.16b,v0.16b aese v1.16b,v17.16b aesmc v1.16b,v1.16b aese v24.16b,v17.16b aesmc v24.16b,v24.16b add x0,x0,x6 // x0 is adjusted in such way that // at exit from the loop v1.16b-v24.16b // are loaded with last "words" mov x7,x3 aese v0.16b,v20.16b aesmc v0.16b,v0.16b aese v1.16b,v20.16b aesmc v1.16b,v1.16b aese v24.16b,v20.16b aesmc v24.16b,v24.16b ld1 {v2.16b},[x0],#16 aese v0.16b,v21.16b aesmc v0.16b,v0.16b aese v1.16b,v21.16b aesmc v1.16b,v1.16b aese v24.16b,v21.16b aesmc v24.16b,v24.16b ld1 {v3.16b},[x0],#16 aese v0.16b,v22.16b aesmc v0.16b,v0.16b aese v1.16b,v22.16b aesmc v1.16b,v1.16b aese v24.16b,v22.16b aesmc v24.16b,v24.16b ld1 {v27.16b},[x0],#16 aese v0.16b,v23.16b aese v1.16b,v23.16b aese v24.16b,v23.16b ld1 {v16.4s},[x7],#16 // re-pre-load rndkey[0] add w6,w5,#2 eor v4.16b,v7.16b,v0.16b eor v5.16b,v7.16b,v1.16b eor v24.16b,v24.16b,v7.16b ld1 {v17.4s},[x7],#16 // re-pre-load rndkey[1] st1 {v4.16b},[x1],#16 orr v0.16b,v2.16b,v2.16b st1 {v5.16b},[x1],#16 orr v1.16b,v3.16b,v3.16b st1 {v24.16b},[x1],#16 orr v24.16b,v27.16b,v27.16b b.hs .Loop3x_ecb_enc cmn x2,#0x30 b.eq .Lecb_done nop .Lecb_enc_tail: aese v1.16b,v16.16b aesmc v1.16b,v1.16b aese v24.16b,v16.16b aesmc v24.16b,v24.16b ld1 {v16.4s},[x7],#16 subs w6,w6,#2 aese v1.16b,v17.16b aesmc v1.16b,v1.16b aese v24.16b,v17.16b aesmc v24.16b,v24.16b ld1 {v17.4s},[x7],#16 b.gt .Lecb_enc_tail aese v1.16b,v16.16b aesmc v1.16b,v1.16b aese v24.16b,v16.16b aesmc v24.16b,v24.16b aese v1.16b,v17.16b aesmc v1.16b,v1.16b aese v24.16b,v17.16b aesmc v24.16b,v24.16b aese v1.16b,v20.16b aesmc v1.16b,v1.16b aese v24.16b,v20.16b aesmc v24.16b,v24.16b cmn x2,#0x20 aese v1.16b,v21.16b aesmc v1.16b,v1.16b aese v24.16b,v21.16b aesmc v24.16b,v24.16b aese v1.16b,v22.16b aesmc v1.16b,v1.16b aese v24.16b,v22.16b aesmc v24.16b,v24.16b aese v1.16b,v23.16b aese v24.16b,v23.16b b.eq .Lecb_enc_one eor v5.16b,v7.16b,v1.16b eor v17.16b,v7.16b,v24.16b st1 {v5.16b},[x1],#16 st1 {v17.16b},[x1],#16 b .Lecb_done .Lecb_enc_one: eor v5.16b,v7.16b,v24.16b st1 {v5.16b},[x1],#16 b .Lecb_done .align 5 .Lecb_dec: ld1 {v1.16b},[x0],#16 subs x2,x2,#32 // bias add w6,w5,#2 orr v3.16b,v1.16b,v1.16b orr v24.16b,v1.16b,v1.16b orr v1.16b,v0.16b,v0.16b b.lo .Lecb_dec_tail orr v1.16b,v3.16b,v3.16b ld1 {v24.16b},[x0],#16 cmp x2,#32 b.lo .Loop3x_ecb_dec ld1 {v25.16b},[x0],#16 ld1 {v26.16b},[x0],#16 sub x2,x2,#32 // bias mov w6,w5 .Loop5x_ecb_dec: aesd v0.16b,v16.16b aesimc v0.16b,v0.16b aesd v1.16b,v16.16b aesimc v1.16b,v1.16b aesd v24.16b,v16.16b aesimc v24.16b,v24.16b aesd v25.16b,v16.16b aesimc v25.16b,v25.16b aesd v26.16b,v16.16b aesimc v26.16b,v26.16b ld1 {v16.4s},[x7],#16 subs w6,w6,#2 aesd v0.16b,v17.16b aesimc v0.16b,v0.16b aesd v1.16b,v17.16b aesimc v1.16b,v1.16b aesd v24.16b,v17.16b aesimc v24.16b,v24.16b aesd v25.16b,v17.16b aesimc v25.16b,v25.16b aesd v26.16b,v17.16b aesimc v26.16b,v26.16b ld1 {v17.4s},[x7],#16 b.gt .Loop5x_ecb_dec aesd v0.16b,v16.16b aesimc v0.16b,v0.16b aesd v1.16b,v16.16b aesimc v1.16b,v1.16b aesd v24.16b,v16.16b aesimc v24.16b,v24.16b aesd v25.16b,v16.16b aesimc v25.16b,v25.16b aesd v26.16b,v16.16b aesimc v26.16b,v26.16b cmp x2,#0x40 // because .Lecb_tail4x sub x2,x2,#0x50 aesd v0.16b,v17.16b aesimc v0.16b,v0.16b aesd v1.16b,v17.16b aesimc v1.16b,v1.16b aesd v24.16b,v17.16b aesimc v24.16b,v24.16b aesd v25.16b,v17.16b aesimc v25.16b,v25.16b aesd v26.16b,v17.16b aesimc v26.16b,v26.16b csel x6,xzr,x2,gt // borrow x6, w6, "gt" is not typo mov x7,x3 aesd v0.16b,v18.16b aesimc v0.16b,v0.16b aesd v1.16b,v18.16b aesimc v1.16b,v1.16b aesd v24.16b,v18.16b aesimc v24.16b,v24.16b aesd v25.16b,v18.16b aesimc v25.16b,v25.16b aesd v26.16b,v18.16b aesimc v26.16b,v26.16b add x0,x0,x6 // x0 is adjusted in such way that // at exit from the loop v1.16b-v26.16b // are loaded with last "words" add x6,x2,#0x60 // because .Lecb_tail4x aesd v0.16b,v19.16b aesimc v0.16b,v0.16b aesd v1.16b,v19.16b aesimc v1.16b,v1.16b aesd v24.16b,v19.16b aesimc v24.16b,v24.16b aesd v25.16b,v19.16b aesimc v25.16b,v25.16b aesd v26.16b,v19.16b aesimc v26.16b,v26.16b aesd v0.16b,v20.16b aesimc v0.16b,v0.16b aesd v1.16b,v20.16b aesimc v1.16b,v1.16b aesd v24.16b,v20.16b aesimc v24.16b,v24.16b aesd v25.16b,v20.16b aesimc v25.16b,v25.16b aesd v26.16b,v20.16b aesimc v26.16b,v26.16b aesd v0.16b,v21.16b aesimc v0.16b,v0.16b aesd v1.16b,v21.16b aesimc v1.16b,v1.16b aesd v24.16b,v21.16b aesimc v24.16b,v24.16b aesd v25.16b,v21.16b aesimc v25.16b,v25.16b aesd v26.16b,v21.16b aesimc v26.16b,v26.16b aesd v0.16b,v22.16b aesimc v0.16b,v0.16b aesd v1.16b,v22.16b aesimc v1.16b,v1.16b aesd v24.16b,v22.16b aesimc v24.16b,v24.16b aesd v25.16b,v22.16b aesimc v25.16b,v25.16b aesd v26.16b,v22.16b aesimc v26.16b,v26.16b aesd v0.16b,v23.16b ld1 {v2.16b},[x0],#16 aesd v1.16b,v23.16b ld1 {v3.16b},[x0],#16 aesd v24.16b,v23.16b ld1 {v27.16b},[x0],#16 aesd v25.16b,v23.16b ld1 {v28.16b},[x0],#16 aesd v26.16b,v23.16b ld1 {v29.16b},[x0],#16 cbz x6,.Lecb_tail4x ld1 {v16.4s},[x7],#16 // re-pre-load rndkey[0] eor v4.16b,v7.16b,v0.16b orr v0.16b,v2.16b,v2.16b eor v5.16b,v7.16b,v1.16b orr v1.16b,v3.16b,v3.16b eor v17.16b,v7.16b,v24.16b orr v24.16b,v27.16b,v27.16b eor v30.16b,v7.16b,v25.16b orr v25.16b,v28.16b,v28.16b eor v31.16b,v7.16b,v26.16b st1 {v4.16b},[x1],#16 orr v26.16b,v29.16b,v29.16b st1 {v5.16b},[x1],#16 mov w6,w5 st1 {v17.16b},[x1],#16 ld1 {v17.4s},[x7],#16 // re-pre-load rndkey[1] st1 {v30.16b},[x1],#16 st1 {v31.16b},[x1],#16 b.hs .Loop5x_ecb_dec add x2,x2,#0x50 cbz x2,.Lecb_done add w6,w5,#2 subs x2,x2,#0x30 orr v0.16b,v27.16b,v27.16b orr v1.16b,v28.16b,v28.16b orr v24.16b,v29.16b,v29.16b b.lo .Lecb_dec_tail b .Loop3x_ecb_dec .align 4 .Lecb_tail4x: eor v5.16b,v7.16b,v1.16b eor v17.16b,v7.16b,v24.16b eor v30.16b,v7.16b,v25.16b eor v31.16b,v7.16b,v26.16b st1 {v5.16b},[x1],#16 st1 {v17.16b},[x1],#16 st1 {v30.16b},[x1],#16 st1 {v31.16b},[x1],#16 b .Lecb_done .align 4 .Loop3x_ecb_dec: aesd v0.16b,v16.16b aesimc v0.16b,v0.16b aesd v1.16b,v16.16b aesimc v1.16b,v1.16b aesd v24.16b,v16.16b aesimc v24.16b,v24.16b ld1 {v16.4s},[x7],#16 subs w6,w6,#2 aesd v0.16b,v17.16b aesimc v0.16b,v0.16b aesd v1.16b,v17.16b aesimc v1.16b,v1.16b aesd v24.16b,v17.16b aesimc v24.16b,v24.16b ld1 {v17.4s},[x7],#16 b.gt .Loop3x_ecb_dec aesd v0.16b,v16.16b aesimc v0.16b,v0.16b aesd v1.16b,v16.16b aesimc v1.16b,v1.16b aesd v24.16b,v16.16b aesimc v24.16b,v24.16b subs x2,x2,#0x30 csel x6,x2,x6,lo // x6, w6, is zero at this point aesd v0.16b,v17.16b aesimc v0.16b,v0.16b aesd v1.16b,v17.16b aesimc v1.16b,v1.16b aesd v24.16b,v17.16b aesimc v24.16b,v24.16b add x0,x0,x6 // x0 is adjusted in such way that // at exit from the loop v1.16b-v24.16b // are loaded with last "words" mov x7,x3 aesd v0.16b,v20.16b aesimc v0.16b,v0.16b aesd v1.16b,v20.16b aesimc v1.16b,v1.16b aesd v24.16b,v20.16b aesimc v24.16b,v24.16b ld1 {v2.16b},[x0],#16 aesd v0.16b,v21.16b aesimc v0.16b,v0.16b aesd v1.16b,v21.16b aesimc v1.16b,v1.16b aesd v24.16b,v21.16b aesimc v24.16b,v24.16b ld1 {v3.16b},[x0],#16 aesd v0.16b,v22.16b aesimc v0.16b,v0.16b aesd v1.16b,v22.16b aesimc v1.16b,v1.16b aesd v24.16b,v22.16b aesimc v24.16b,v24.16b ld1 {v27.16b},[x0],#16 aesd v0.16b,v23.16b aesd v1.16b,v23.16b aesd v24.16b,v23.16b ld1 {v16.4s},[x7],#16 // re-pre-load rndkey[0] add w6,w5,#2 eor v4.16b,v7.16b,v0.16b eor v5.16b,v7.16b,v1.16b eor v24.16b,v24.16b,v7.16b ld1 {v17.4s},[x7],#16 // re-pre-load rndkey[1] st1 {v4.16b},[x1],#16 orr v0.16b,v2.16b,v2.16b st1 {v5.16b},[x1],#16 orr v1.16b,v3.16b,v3.16b st1 {v24.16b},[x1],#16 orr v24.16b,v27.16b,v27.16b b.hs .Loop3x_ecb_dec cmn x2,#0x30 b.eq .Lecb_done nop .Lecb_dec_tail: aesd v1.16b,v16.16b aesimc v1.16b,v1.16b aesd v24.16b,v16.16b aesimc v24.16b,v24.16b ld1 {v16.4s},[x7],#16 subs w6,w6,#2 aesd v1.16b,v17.16b aesimc v1.16b,v1.16b aesd v24.16b,v17.16b aesimc v24.16b,v24.16b ld1 {v17.4s},[x7],#16 b.gt .Lecb_dec_tail aesd v1.16b,v16.16b aesimc v1.16b,v1.16b aesd v24.16b,v16.16b aesimc v24.16b,v24.16b aesd v1.16b,v17.16b aesimc v1.16b,v1.16b aesd v24.16b,v17.16b aesimc v24.16b,v24.16b aesd v1.16b,v20.16b aesimc v1.16b,v1.16b aesd v24.16b,v20.16b aesimc v24.16b,v24.16b cmn x2,#0x20 aesd v1.16b,v21.16b aesimc v1.16b,v1.16b aesd v24.16b,v21.16b aesimc v24.16b,v24.16b aesd v1.16b,v22.16b aesimc v1.16b,v1.16b aesd v24.16b,v22.16b aesimc v24.16b,v24.16b aesd v1.16b,v23.16b aesd v24.16b,v23.16b b.eq .Lecb_dec_one eor v5.16b,v7.16b,v1.16b eor v17.16b,v7.16b,v24.16b st1 {v5.16b},[x1],#16 st1 {v17.16b},[x1],#16 b .Lecb_done .Lecb_dec_one: eor v5.16b,v7.16b,v24.16b st1 {v5.16b},[x1],#16 .Lecb_done: ldr x29,[sp],#16 .Lecb_Final_abort: ret .size aes_v8_ecb_encrypt,.-aes_v8_ecb_encrypt .globl aes_v8_cbc_encrypt .type aes_v8_cbc_encrypt,%function .align 5 aes_v8_cbc_encrypt: stp x29,x30,[sp,#-16]! add x29,sp,#0 subs x2,x2,#16 mov x8,#16 b.lo .Lcbc_abort csel x8,xzr,x8,eq cmp w5,#0 // en- or decrypting? ldr w5,[x3,#240] and x2,x2,#-16 ld1 {v6.16b},[x4] ld1 {v0.16b},[x0],x8 ld1 {v16.4s,v17.4s},[x3] // load key schedule... sub w5,w5,#6 add x7,x3,x5,lsl#4 // pointer to last 7 round keys sub w5,w5,#2 ld1 {v18.4s,v19.4s},[x7],#32 ld1 {v20.4s,v21.4s},[x7],#32 ld1 {v22.4s,v23.4s},[x7],#32 ld1 {v7.4s},[x7] add x7,x3,#32 mov w6,w5 b.eq .Lcbc_dec cmp w5,#2 eor v0.16b,v0.16b,v6.16b eor v5.16b,v16.16b,v7.16b b.eq .Lcbc_enc128 ld1 {v2.4s,v3.4s},[x7] add x7,x3,#16 add x6,x3,#16*4 add x12,x3,#16*5 aese v0.16b,v16.16b aesmc v0.16b,v0.16b add x14,x3,#16*6 add x3,x3,#16*7 b .Lenter_cbc_enc .align 4 .Loop_cbc_enc: aese v0.16b,v16.16b aesmc v0.16b,v0.16b st1 {v6.16b},[x1],#16 .Lenter_cbc_enc: aese v0.16b,v17.16b aesmc v0.16b,v0.16b aese v0.16b,v2.16b aesmc v0.16b,v0.16b ld1 {v16.4s},[x6] cmp w5,#4 aese v0.16b,v3.16b aesmc v0.16b,v0.16b ld1 {v17.4s},[x12] b.eq .Lcbc_enc192 aese v0.16b,v16.16b aesmc v0.16b,v0.16b ld1 {v16.4s},[x14] aese v0.16b,v17.16b aesmc v0.16b,v0.16b ld1 {v17.4s},[x3] nop .Lcbc_enc192: aese v0.16b,v16.16b aesmc v0.16b,v0.16b subs x2,x2,#16 aese v0.16b,v17.16b aesmc v0.16b,v0.16b csel x8,xzr,x8,eq aese v0.16b,v18.16b aesmc v0.16b,v0.16b aese v0.16b,v19.16b aesmc v0.16b,v0.16b ld1 {v16.16b},[x0],x8 aese v0.16b,v20.16b aesmc v0.16b,v0.16b eor v16.16b,v16.16b,v5.16b aese v0.16b,v21.16b aesmc v0.16b,v0.16b ld1 {v17.4s},[x7] // re-pre-load rndkey[1] aese v0.16b,v22.16b aesmc v0.16b,v0.16b aese v0.16b,v23.16b eor v6.16b,v0.16b,v7.16b b.hs .Loop_cbc_enc st1 {v6.16b},[x1],#16 b .Lcbc_done .align 5 .Lcbc_enc128: ld1 {v2.4s,v3.4s},[x7] aese v0.16b,v16.16b aesmc v0.16b,v0.16b b .Lenter_cbc_enc128 .Loop_cbc_enc128: aese v0.16b,v16.16b aesmc v0.16b,v0.16b st1 {v6.16b},[x1],#16 .Lenter_cbc_enc128: aese v0.16b,v17.16b aesmc v0.16b,v0.16b subs x2,x2,#16 aese v0.16b,v2.16b aesmc v0.16b,v0.16b csel x8,xzr,x8,eq aese v0.16b,v3.16b aesmc v0.16b,v0.16b aese v0.16b,v18.16b aesmc v0.16b,v0.16b aese v0.16b,v19.16b aesmc v0.16b,v0.16b ld1 {v16.16b},[x0],x8 aese v0.16b,v20.16b aesmc v0.16b,v0.16b aese v0.16b,v21.16b aesmc v0.16b,v0.16b aese v0.16b,v22.16b aesmc v0.16b,v0.16b eor v16.16b,v16.16b,v5.16b aese v0.16b,v23.16b eor v6.16b,v0.16b,v7.16b b.hs .Loop_cbc_enc128 st1 {v6.16b},[x1],#16 b .Lcbc_done .align 5 .Lcbc_dec: ld1 {v24.16b},[x0],#16 subs x2,x2,#32 // bias add w6,w5,#2 orr v3.16b,v0.16b,v0.16b orr v1.16b,v0.16b,v0.16b orr v27.16b,v24.16b,v24.16b b.lo .Lcbc_dec_tail orr v1.16b,v24.16b,v24.16b ld1 {v24.16b},[x0],#16 orr v2.16b,v0.16b,v0.16b orr v3.16b,v1.16b,v1.16b orr v27.16b,v24.16b,v24.16b cmp x2,#32 b.lo .Loop3x_cbc_dec ld1 {v25.16b},[x0],#16 ld1 {v26.16b},[x0],#16 sub x2,x2,#32 // bias mov w6,w5 orr v28.16b,v25.16b,v25.16b orr v29.16b,v26.16b,v26.16b .Loop5x_cbc_dec: aesd v0.16b,v16.16b aesimc v0.16b,v0.16b aesd v1.16b,v16.16b aesimc v1.16b,v1.16b aesd v24.16b,v16.16b aesimc v24.16b,v24.16b aesd v25.16b,v16.16b aesimc v25.16b,v25.16b aesd v26.16b,v16.16b aesimc v26.16b,v26.16b ld1 {v16.4s},[x7],#16 subs w6,w6,#2 aesd v0.16b,v17.16b aesimc v0.16b,v0.16b aesd v1.16b,v17.16b aesimc v1.16b,v1.16b aesd v24.16b,v17.16b aesimc v24.16b,v24.16b aesd v25.16b,v17.16b aesimc v25.16b,v25.16b aesd v26.16b,v17.16b aesimc v26.16b,v26.16b ld1 {v17.4s},[x7],#16 b.gt .Loop5x_cbc_dec aesd v0.16b,v16.16b aesimc v0.16b,v0.16b aesd v1.16b,v16.16b aesimc v1.16b,v1.16b aesd v24.16b,v16.16b aesimc v24.16b,v24.16b aesd v25.16b,v16.16b aesimc v25.16b,v25.16b aesd v26.16b,v16.16b aesimc v26.16b,v26.16b cmp x2,#0x40 // because .Lcbc_tail4x sub x2,x2,#0x50 aesd v0.16b,v17.16b aesimc v0.16b,v0.16b aesd v1.16b,v17.16b aesimc v1.16b,v1.16b aesd v24.16b,v17.16b aesimc v24.16b,v24.16b aesd v25.16b,v17.16b aesimc v25.16b,v25.16b aesd v26.16b,v17.16b aesimc v26.16b,v26.16b csel x6,xzr,x2,gt // borrow x6, w6, "gt" is not typo mov x7,x3 aesd v0.16b,v18.16b aesimc v0.16b,v0.16b aesd v1.16b,v18.16b aesimc v1.16b,v1.16b aesd v24.16b,v18.16b aesimc v24.16b,v24.16b aesd v25.16b,v18.16b aesimc v25.16b,v25.16b aesd v26.16b,v18.16b aesimc v26.16b,v26.16b add x0,x0,x6 // x0 is adjusted in such way that // at exit from the loop v1.16b-v26.16b // are loaded with last "words" add x6,x2,#0x60 // because .Lcbc_tail4x aesd v0.16b,v19.16b aesimc v0.16b,v0.16b aesd v1.16b,v19.16b aesimc v1.16b,v1.16b aesd v24.16b,v19.16b aesimc v24.16b,v24.16b aesd v25.16b,v19.16b aesimc v25.16b,v25.16b aesd v26.16b,v19.16b aesimc v26.16b,v26.16b aesd v0.16b,v20.16b aesimc v0.16b,v0.16b aesd v1.16b,v20.16b aesimc v1.16b,v1.16b aesd v24.16b,v20.16b aesimc v24.16b,v24.16b aesd v25.16b,v20.16b aesimc v25.16b,v25.16b aesd v26.16b,v20.16b aesimc v26.16b,v26.16b aesd v0.16b,v21.16b aesimc v0.16b,v0.16b aesd v1.16b,v21.16b aesimc v1.16b,v1.16b aesd v24.16b,v21.16b aesimc v24.16b,v24.16b aesd v25.16b,v21.16b aesimc v25.16b,v25.16b aesd v26.16b,v21.16b aesimc v26.16b,v26.16b aesd v0.16b,v22.16b aesimc v0.16b,v0.16b aesd v1.16b,v22.16b aesimc v1.16b,v1.16b aesd v24.16b,v22.16b aesimc v24.16b,v24.16b aesd v25.16b,v22.16b aesimc v25.16b,v25.16b aesd v26.16b,v22.16b aesimc v26.16b,v26.16b eor v4.16b,v6.16b,v7.16b aesd v0.16b,v23.16b eor v5.16b,v2.16b,v7.16b ld1 {v2.16b},[x0],#16 aesd v1.16b,v23.16b eor v17.16b,v3.16b,v7.16b ld1 {v3.16b},[x0],#16 aesd v24.16b,v23.16b eor v30.16b,v27.16b,v7.16b ld1 {v27.16b},[x0],#16 aesd v25.16b,v23.16b eor v31.16b,v28.16b,v7.16b ld1 {v28.16b},[x0],#16 aesd v26.16b,v23.16b orr v6.16b,v29.16b,v29.16b ld1 {v29.16b},[x0],#16 cbz x6,.Lcbc_tail4x ld1 {v16.4s},[x7],#16 // re-pre-load rndkey[0] eor v4.16b,v4.16b,v0.16b orr v0.16b,v2.16b,v2.16b eor v5.16b,v5.16b,v1.16b orr v1.16b,v3.16b,v3.16b eor v17.16b,v17.16b,v24.16b orr v24.16b,v27.16b,v27.16b eor v30.16b,v30.16b,v25.16b orr v25.16b,v28.16b,v28.16b eor v31.16b,v31.16b,v26.16b st1 {v4.16b},[x1],#16 orr v26.16b,v29.16b,v29.16b st1 {v5.16b},[x1],#16 mov w6,w5 st1 {v17.16b},[x1],#16 ld1 {v17.4s},[x7],#16 // re-pre-load rndkey[1] st1 {v30.16b},[x1],#16 st1 {v31.16b},[x1],#16 b.hs .Loop5x_cbc_dec add x2,x2,#0x50 cbz x2,.Lcbc_done add w6,w5,#2 subs x2,x2,#0x30 orr v0.16b,v27.16b,v27.16b orr v2.16b,v27.16b,v27.16b orr v1.16b,v28.16b,v28.16b orr v3.16b,v28.16b,v28.16b orr v24.16b,v29.16b,v29.16b orr v27.16b,v29.16b,v29.16b b.lo .Lcbc_dec_tail b .Loop3x_cbc_dec .align 4 .Lcbc_tail4x: eor v5.16b,v4.16b,v1.16b eor v17.16b,v17.16b,v24.16b eor v30.16b,v30.16b,v25.16b eor v31.16b,v31.16b,v26.16b st1 {v5.16b},[x1],#16 st1 {v17.16b},[x1],#16 st1 {v30.16b},[x1],#16 st1 {v31.16b},[x1],#16 b .Lcbc_done .align 4 .Loop3x_cbc_dec: aesd v0.16b,v16.16b aesimc v0.16b,v0.16b aesd v1.16b,v16.16b aesimc v1.16b,v1.16b aesd v24.16b,v16.16b aesimc v24.16b,v24.16b ld1 {v16.4s},[x7],#16 subs w6,w6,#2 aesd v0.16b,v17.16b aesimc v0.16b,v0.16b aesd v1.16b,v17.16b aesimc v1.16b,v1.16b aesd v24.16b,v17.16b aesimc v24.16b,v24.16b ld1 {v17.4s},[x7],#16 b.gt .Loop3x_cbc_dec aesd v0.16b,v16.16b aesimc v0.16b,v0.16b aesd v1.16b,v16.16b aesimc v1.16b,v1.16b aesd v24.16b,v16.16b aesimc v24.16b,v24.16b eor v4.16b,v6.16b,v7.16b subs x2,x2,#0x30 eor v5.16b,v2.16b,v7.16b csel x6,x2,x6,lo // x6, w6, is zero at this point aesd v0.16b,v17.16b aesimc v0.16b,v0.16b aesd v1.16b,v17.16b aesimc v1.16b,v1.16b aesd v24.16b,v17.16b aesimc v24.16b,v24.16b eor v17.16b,v3.16b,v7.16b add x0,x0,x6 // x0 is adjusted in such way that // at exit from the loop v1.16b-v24.16b // are loaded with last "words" orr v6.16b,v27.16b,v27.16b mov x7,x3 aesd v0.16b,v20.16b aesimc v0.16b,v0.16b aesd v1.16b,v20.16b aesimc v1.16b,v1.16b aesd v24.16b,v20.16b aesimc v24.16b,v24.16b ld1 {v2.16b},[x0],#16 aesd v0.16b,v21.16b aesimc v0.16b,v0.16b aesd v1.16b,v21.16b aesimc v1.16b,v1.16b aesd v24.16b,v21.16b aesimc v24.16b,v24.16b ld1 {v3.16b},[x0],#16 aesd v0.16b,v22.16b aesimc v0.16b,v0.16b aesd v1.16b,v22.16b aesimc v1.16b,v1.16b aesd v24.16b,v22.16b aesimc v24.16b,v24.16b ld1 {v27.16b},[x0],#16 aesd v0.16b,v23.16b aesd v1.16b,v23.16b aesd v24.16b,v23.16b ld1 {v16.4s},[x7],#16 // re-pre-load rndkey[0] add w6,w5,#2 eor v4.16b,v4.16b,v0.16b eor v5.16b,v5.16b,v1.16b eor v24.16b,v24.16b,v17.16b ld1 {v17.4s},[x7],#16 // re-pre-load rndkey[1] st1 {v4.16b},[x1],#16 orr v0.16b,v2.16b,v2.16b st1 {v5.16b},[x1],#16 orr v1.16b,v3.16b,v3.16b st1 {v24.16b},[x1],#16 orr v24.16b,v27.16b,v27.16b b.hs .Loop3x_cbc_dec cmn x2,#0x30 b.eq .Lcbc_done nop .Lcbc_dec_tail: aesd v1.16b,v16.16b aesimc v1.16b,v1.16b aesd v24.16b,v16.16b aesimc v24.16b,v24.16b ld1 {v16.4s},[x7],#16 subs w6,w6,#2 aesd v1.16b,v17.16b aesimc v1.16b,v1.16b aesd v24.16b,v17.16b aesimc v24.16b,v24.16b ld1 {v17.4s},[x7],#16 b.gt .Lcbc_dec_tail aesd v1.16b,v16.16b aesimc v1.16b,v1.16b aesd v24.16b,v16.16b aesimc v24.16b,v24.16b aesd v1.16b,v17.16b aesimc v1.16b,v1.16b aesd v24.16b,v17.16b aesimc v24.16b,v24.16b aesd v1.16b,v20.16b aesimc v1.16b,v1.16b aesd v24.16b,v20.16b aesimc v24.16b,v24.16b cmn x2,#0x20 aesd v1.16b,v21.16b aesimc v1.16b,v1.16b aesd v24.16b,v21.16b aesimc v24.16b,v24.16b eor v5.16b,v6.16b,v7.16b aesd v1.16b,v22.16b aesimc v1.16b,v1.16b aesd v24.16b,v22.16b aesimc v24.16b,v24.16b eor v17.16b,v3.16b,v7.16b aesd v1.16b,v23.16b aesd v24.16b,v23.16b b.eq .Lcbc_dec_one eor v5.16b,v5.16b,v1.16b eor v17.16b,v17.16b,v24.16b orr v6.16b,v27.16b,v27.16b st1 {v5.16b},[x1],#16 st1 {v17.16b},[x1],#16 b .Lcbc_done .Lcbc_dec_one: eor v5.16b,v5.16b,v24.16b orr v6.16b,v27.16b,v27.16b st1 {v5.16b},[x1],#16 .Lcbc_done: st1 {v6.16b},[x4] .Lcbc_abort: ldr x29,[sp],#16 ret .size aes_v8_cbc_encrypt,.-aes_v8_cbc_encrypt .globl aes_v8_ctr32_encrypt_blocks .type aes_v8_ctr32_encrypt_blocks,%function .align 5 aes_v8_ctr32_encrypt_blocks: stp x29,x30,[sp,#-16]! add x29,sp,#0 ldr w5,[x3,#240] ldr w8, [x4, #12] -#ifdef __ARMEB__ +#ifdef __AARCH64EB__ ld1 {v0.16b},[x4] #else ld1 {v0.4s},[x4] #endif ld1 {v16.4s,v17.4s},[x3] // load key schedule... sub w5,w5,#4 mov x12,#16 cmp x2,#2 add x7,x3,x5,lsl#4 // pointer to last 5 round keys sub w5,w5,#2 ld1 {v20.4s,v21.4s},[x7],#32 ld1 {v22.4s,v23.4s},[x7],#32 ld1 {v7.4s},[x7] add x7,x3,#32 mov w6,w5 csel x12,xzr,x12,lo -#ifndef __ARMEB__ +#ifndef __AARCH64EB__ rev w8, w8 #endif orr v1.16b,v0.16b,v0.16b add w10, w8, #1 orr v18.16b,v0.16b,v0.16b add w8, w8, #2 orr v6.16b,v0.16b,v0.16b rev w10, w10 mov v1.s[3],w10 b.ls .Lctr32_tail rev w12, w8 sub x2,x2,#3 // bias mov v18.s[3],w12 cmp x2,#32 b.lo .Loop3x_ctr32 add w13,w8,#1 add w14,w8,#2 orr v24.16b,v0.16b,v0.16b rev w13,w13 orr v25.16b,v0.16b,v0.16b rev w14,w14 mov v24.s[3],w13 sub x2,x2,#2 // bias mov v25.s[3],w14 add w8,w8,#2 b .Loop5x_ctr32 .align 4 .Loop5x_ctr32: aese v0.16b,v16.16b aesmc v0.16b,v0.16b aese v1.16b,v16.16b aesmc v1.16b,v1.16b aese v18.16b,v16.16b aesmc v18.16b,v18.16b aese v24.16b,v16.16b aesmc v24.16b,v24.16b aese v25.16b,v16.16b aesmc v25.16b,v25.16b ld1 {v16.4s},[x7],#16 subs w6,w6,#2 aese v0.16b,v17.16b aesmc v0.16b,v0.16b aese v1.16b,v17.16b aesmc v1.16b,v1.16b aese v18.16b,v17.16b aesmc v18.16b,v18.16b aese v24.16b,v17.16b aesmc v24.16b,v24.16b aese v25.16b,v17.16b aesmc v25.16b,v25.16b ld1 {v17.4s},[x7],#16 b.gt .Loop5x_ctr32 mov x7,x3 aese v0.16b,v16.16b aesmc v0.16b,v0.16b aese v1.16b,v16.16b aesmc v1.16b,v1.16b aese v18.16b,v16.16b aesmc v18.16b,v18.16b aese v24.16b,v16.16b aesmc v24.16b,v24.16b aese v25.16b,v16.16b aesmc v25.16b,v25.16b ld1 {v16.4s},[x7],#16 // re-pre-load rndkey[0] aese v0.16b,v17.16b aesmc v0.16b,v0.16b aese v1.16b,v17.16b aesmc v1.16b,v1.16b aese v18.16b,v17.16b aesmc v18.16b,v18.16b aese v24.16b,v17.16b aesmc v24.16b,v24.16b aese v25.16b,v17.16b aesmc v25.16b,v25.16b ld1 {v17.4s},[x7],#16 // re-pre-load rndkey[1] aese v0.16b,v20.16b aesmc v0.16b,v0.16b add w9,w8,#1 add w10,w8,#2 aese v1.16b,v20.16b aesmc v1.16b,v1.16b add w12,w8,#3 add w13,w8,#4 aese v18.16b,v20.16b aesmc v18.16b,v18.16b add w14,w8,#5 rev w9,w9 aese v24.16b,v20.16b aesmc v24.16b,v24.16b rev w10,w10 rev w12,w12 aese v25.16b,v20.16b aesmc v25.16b,v25.16b rev w13,w13 rev w14,w14 aese v0.16b,v21.16b aesmc v0.16b,v0.16b aese v1.16b,v21.16b aesmc v1.16b,v1.16b aese v18.16b,v21.16b aesmc v18.16b,v18.16b aese v24.16b,v21.16b aesmc v24.16b,v24.16b aese v25.16b,v21.16b aesmc v25.16b,v25.16b aese v0.16b,v22.16b aesmc v0.16b,v0.16b ld1 {v2.16b},[x0],#16 aese v1.16b,v22.16b aesmc v1.16b,v1.16b ld1 {v3.16b},[x0],#16 aese v18.16b,v22.16b aesmc v18.16b,v18.16b ld1 {v19.16b},[x0],#16 aese v24.16b,v22.16b aesmc v24.16b,v24.16b ld1 {v26.16b},[x0],#16 aese v25.16b,v22.16b aesmc v25.16b,v25.16b ld1 {v27.16b},[x0],#16 aese v0.16b,v23.16b eor v2.16b,v2.16b,v7.16b aese v1.16b,v23.16b eor v3.16b,v3.16b,v7.16b aese v18.16b,v23.16b eor v19.16b,v19.16b,v7.16b aese v24.16b,v23.16b eor v26.16b,v26.16b,v7.16b aese v25.16b,v23.16b eor v27.16b,v27.16b,v7.16b eor v2.16b,v2.16b,v0.16b orr v0.16b,v6.16b,v6.16b eor v3.16b,v3.16b,v1.16b orr v1.16b,v6.16b,v6.16b eor v19.16b,v19.16b,v18.16b orr v18.16b,v6.16b,v6.16b eor v26.16b,v26.16b,v24.16b orr v24.16b,v6.16b,v6.16b eor v27.16b,v27.16b,v25.16b orr v25.16b,v6.16b,v6.16b st1 {v2.16b},[x1],#16 mov v0.s[3],w9 st1 {v3.16b},[x1],#16 mov v1.s[3],w10 st1 {v19.16b},[x1],#16 mov v18.s[3],w12 st1 {v26.16b},[x1],#16 mov v24.s[3],w13 st1 {v27.16b},[x1],#16 mov v25.s[3],w14 mov w6,w5 cbz x2,.Lctr32_done add w8,w8,#5 subs x2,x2,#5 b.hs .Loop5x_ctr32 add x2,x2,#5 sub w8,w8,#5 cmp x2,#2 mov x12,#16 csel x12,xzr,x12,lo b.ls .Lctr32_tail sub x2,x2,#3 // bias add w8,w8,#3 b .Loop3x_ctr32 .align 4 .Loop3x_ctr32: aese v0.16b,v16.16b aesmc v0.16b,v0.16b aese v1.16b,v16.16b aesmc v1.16b,v1.16b aese v18.16b,v16.16b aesmc v18.16b,v18.16b ld1 {v16.4s},[x7],#16 subs w6,w6,#2 aese v0.16b,v17.16b aesmc v0.16b,v0.16b aese v1.16b,v17.16b aesmc v1.16b,v1.16b aese v18.16b,v17.16b aesmc v18.16b,v18.16b ld1 {v17.4s},[x7],#16 b.gt .Loop3x_ctr32 aese v0.16b,v16.16b aesmc v4.16b,v0.16b aese v1.16b,v16.16b aesmc v5.16b,v1.16b ld1 {v2.16b},[x0],#16 orr v0.16b,v6.16b,v6.16b aese v18.16b,v16.16b aesmc v18.16b,v18.16b ld1 {v3.16b},[x0],#16 orr v1.16b,v6.16b,v6.16b aese v4.16b,v17.16b aesmc v4.16b,v4.16b aese v5.16b,v17.16b aesmc v5.16b,v5.16b ld1 {v19.16b},[x0],#16 mov x7,x3 aese v18.16b,v17.16b aesmc v17.16b,v18.16b orr v18.16b,v6.16b,v6.16b add w9,w8,#1 aese v4.16b,v20.16b aesmc v4.16b,v4.16b aese v5.16b,v20.16b aesmc v5.16b,v5.16b eor v2.16b,v2.16b,v7.16b add w10,w8,#2 aese v17.16b,v20.16b aesmc v17.16b,v17.16b eor v3.16b,v3.16b,v7.16b add w8,w8,#3 aese v4.16b,v21.16b aesmc v4.16b,v4.16b aese v5.16b,v21.16b aesmc v5.16b,v5.16b eor v19.16b,v19.16b,v7.16b rev w9,w9 aese v17.16b,v21.16b aesmc v17.16b,v17.16b mov v0.s[3], w9 rev w10,w10 aese v4.16b,v22.16b aesmc v4.16b,v4.16b aese v5.16b,v22.16b aesmc v5.16b,v5.16b mov v1.s[3], w10 rev w12,w8 aese v17.16b,v22.16b aesmc v17.16b,v17.16b mov v18.s[3], w12 subs x2,x2,#3 aese v4.16b,v23.16b aese v5.16b,v23.16b aese v17.16b,v23.16b eor v2.16b,v2.16b,v4.16b ld1 {v16.4s},[x7],#16 // re-pre-load rndkey[0] st1 {v2.16b},[x1],#16 eor v3.16b,v3.16b,v5.16b mov w6,w5 st1 {v3.16b},[x1],#16 eor v19.16b,v19.16b,v17.16b ld1 {v17.4s},[x7],#16 // re-pre-load rndkey[1] st1 {v19.16b},[x1],#16 b.hs .Loop3x_ctr32 adds x2,x2,#3 b.eq .Lctr32_done cmp x2,#1 mov x12,#16 csel x12,xzr,x12,eq .Lctr32_tail: aese v0.16b,v16.16b aesmc v0.16b,v0.16b aese v1.16b,v16.16b aesmc v1.16b,v1.16b ld1 {v16.4s},[x7],#16 subs w6,w6,#2 aese v0.16b,v17.16b aesmc v0.16b,v0.16b aese v1.16b,v17.16b aesmc v1.16b,v1.16b ld1 {v17.4s},[x7],#16 b.gt .Lctr32_tail aese v0.16b,v16.16b aesmc v0.16b,v0.16b aese v1.16b,v16.16b aesmc v1.16b,v1.16b aese v0.16b,v17.16b aesmc v0.16b,v0.16b aese v1.16b,v17.16b aesmc v1.16b,v1.16b ld1 {v2.16b},[x0],x12 aese v0.16b,v20.16b aesmc v0.16b,v0.16b aese v1.16b,v20.16b aesmc v1.16b,v1.16b ld1 {v3.16b},[x0] aese v0.16b,v21.16b aesmc v0.16b,v0.16b aese v1.16b,v21.16b aesmc v1.16b,v1.16b eor v2.16b,v2.16b,v7.16b aese v0.16b,v22.16b aesmc v0.16b,v0.16b aese v1.16b,v22.16b aesmc v1.16b,v1.16b eor v3.16b,v3.16b,v7.16b aese v0.16b,v23.16b aese v1.16b,v23.16b cmp x2,#1 eor v2.16b,v2.16b,v0.16b eor v3.16b,v3.16b,v1.16b st1 {v2.16b},[x1],#16 b.eq .Lctr32_done st1 {v3.16b},[x1] .Lctr32_done: ldr x29,[sp],#16 ret .size aes_v8_ctr32_encrypt_blocks,.-aes_v8_ctr32_encrypt_blocks .globl aes_v8_xts_encrypt .type aes_v8_xts_encrypt,%function .align 5 aes_v8_xts_encrypt: cmp x2,#16 // Original input data size bigger than 16, jump to big size processing. b.ne .Lxts_enc_big_size // Encrypt the iv with key2, as the first XEX iv. ldr w6,[x4,#240] ld1 {v0.4s},[x4],#16 ld1 {v6.16b},[x5] sub w6,w6,#2 ld1 {v1.4s},[x4],#16 .Loop_enc_iv_enc: aese v6.16b,v0.16b aesmc v6.16b,v6.16b ld1 {v0.4s},[x4],#16 subs w6,w6,#2 aese v6.16b,v1.16b aesmc v6.16b,v6.16b ld1 {v1.4s},[x4],#16 b.gt .Loop_enc_iv_enc aese v6.16b,v0.16b aesmc v6.16b,v6.16b ld1 {v0.4s},[x4] aese v6.16b,v1.16b eor v6.16b,v6.16b,v0.16b ld1 {v0.16b},[x0] eor v0.16b,v6.16b,v0.16b ldr w6,[x3,#240] ld1 {v28.4s,v29.4s},[x3],#32 // load key schedule... aese v0.16b,v28.16b aesmc v0.16b,v0.16b ld1 {v16.4s,v17.4s},[x3],#32 // load key schedule... aese v0.16b,v29.16b aesmc v0.16b,v0.16b subs w6,w6,#10 // if rounds==10, jump to aes-128-xts processing b.eq .Lxts_128_enc .Lxts_enc_round_loop: aese v0.16b,v16.16b aesmc v0.16b,v0.16b ld1 {v16.4s},[x3],#16 // load key schedule... aese v0.16b,v17.16b aesmc v0.16b,v0.16b ld1 {v17.4s},[x3],#16 // load key schedule... subs w6,w6,#2 // bias b.gt .Lxts_enc_round_loop .Lxts_128_enc: ld1 {v18.4s,v19.4s},[x3],#32 // load key schedule... aese v0.16b,v16.16b aesmc v0.16b,v0.16b aese v0.16b,v17.16b aesmc v0.16b,v0.16b ld1 {v20.4s,v21.4s},[x3],#32 // load key schedule... aese v0.16b,v18.16b aesmc v0.16b,v0.16b aese v0.16b,v19.16b aesmc v0.16b,v0.16b ld1 {v22.4s,v23.4s},[x3],#32 // load key schedule... aese v0.16b,v20.16b aesmc v0.16b,v0.16b aese v0.16b,v21.16b aesmc v0.16b,v0.16b ld1 {v7.4s},[x3] aese v0.16b,v22.16b aesmc v0.16b,v0.16b aese v0.16b,v23.16b eor v0.16b,v0.16b,v7.16b eor v0.16b,v0.16b,v6.16b st1 {v0.16b},[x1] b .Lxts_enc_final_abort .align 4 .Lxts_enc_big_size: stp x19,x20,[sp,#-64]! stp x21,x22,[sp,#48] stp d8,d9,[sp,#32] stp d10,d11,[sp,#16] // tailcnt store the tail value of length%16. and x21,x2,#0xf and x2,x2,#-16 subs x2,x2,#16 mov x8,#16 b.lo .Lxts_abort csel x8,xzr,x8,eq // Firstly, encrypt the iv with key2, as the first iv of XEX. ldr w6,[x4,#240] ld1 {v0.4s},[x4],#16 ld1 {v6.16b},[x5] sub w6,w6,#2 ld1 {v1.4s},[x4],#16 .Loop_iv_enc: aese v6.16b,v0.16b aesmc v6.16b,v6.16b ld1 {v0.4s},[x4],#16 subs w6,w6,#2 aese v6.16b,v1.16b aesmc v6.16b,v6.16b ld1 {v1.4s},[x4],#16 b.gt .Loop_iv_enc aese v6.16b,v0.16b aesmc v6.16b,v6.16b ld1 {v0.4s},[x4] aese v6.16b,v1.16b eor v6.16b,v6.16b,v0.16b // The iv for second block // x9- iv(low), x10 - iv(high) // the five ivs stored into, v6.16b,v8.16b,v9.16b,v10.16b,v11.16b fmov x9,d6 fmov x10,v6.d[1] mov w19,#0x87 extr x22,x10,x10,#32 extr x10,x10,x9,#63 and w11,w19,w22,asr#31 eor x9,x11,x9,lsl#1 fmov d8,x9 fmov v8.d[1],x10 ldr w5,[x3,#240] // next starting point ld1 {v0.16b},[x0],x8 ld1 {v16.4s,v17.4s},[x3] // load key schedule... sub w5,w5,#6 add x7,x3,x5,lsl#4 // pointer to last 7 round keys sub w5,w5,#2 ld1 {v18.4s,v19.4s},[x7],#32 ld1 {v20.4s,v21.4s},[x7],#32 ld1 {v22.4s,v23.4s},[x7],#32 ld1 {v7.4s},[x7] add x7,x3,#32 mov w6,w5 // Encryption .Lxts_enc: ld1 {v24.16b},[x0],#16 subs x2,x2,#32 // bias add w6,w5,#2 orr v3.16b,v0.16b,v0.16b orr v1.16b,v0.16b,v0.16b orr v28.16b,v0.16b,v0.16b orr v27.16b,v24.16b,v24.16b orr v29.16b,v24.16b,v24.16b b.lo .Lxts_inner_enc_tail eor v0.16b,v0.16b,v6.16b // before encryption, xor with iv eor v24.16b,v24.16b,v8.16b // The iv for third block extr x22,x10,x10,#32 extr x10,x10,x9,#63 and w11,w19,w22,asr#31 eor x9,x11,x9,lsl#1 fmov d9,x9 fmov v9.d[1],x10 orr v1.16b,v24.16b,v24.16b ld1 {v24.16b},[x0],#16 orr v2.16b,v0.16b,v0.16b orr v3.16b,v1.16b,v1.16b eor v27.16b,v24.16b,v9.16b // the third block eor v24.16b,v24.16b,v9.16b cmp x2,#32 b.lo .Lxts_outer_enc_tail // The iv for fourth block extr x22,x10,x10,#32 extr x10,x10,x9,#63 and w11,w19,w22,asr#31 eor x9,x11,x9,lsl#1 fmov d10,x9 fmov v10.d[1],x10 ld1 {v25.16b},[x0],#16 // The iv for fifth block extr x22,x10,x10,#32 extr x10,x10,x9,#63 and w11,w19,w22,asr#31 eor x9,x11,x9,lsl#1 fmov d11,x9 fmov v11.d[1],x10 ld1 {v26.16b},[x0],#16 eor v25.16b,v25.16b,v10.16b // the fourth block eor v26.16b,v26.16b,v11.16b sub x2,x2,#32 // bias mov w6,w5 b .Loop5x_xts_enc .align 4 .Loop5x_xts_enc: aese v0.16b,v16.16b aesmc v0.16b,v0.16b aese v1.16b,v16.16b aesmc v1.16b,v1.16b aese v24.16b,v16.16b aesmc v24.16b,v24.16b aese v25.16b,v16.16b aesmc v25.16b,v25.16b aese v26.16b,v16.16b aesmc v26.16b,v26.16b ld1 {v16.4s},[x7],#16 subs w6,w6,#2 aese v0.16b,v17.16b aesmc v0.16b,v0.16b aese v1.16b,v17.16b aesmc v1.16b,v1.16b aese v24.16b,v17.16b aesmc v24.16b,v24.16b aese v25.16b,v17.16b aesmc v25.16b,v25.16b aese v26.16b,v17.16b aesmc v26.16b,v26.16b ld1 {v17.4s},[x7],#16 b.gt .Loop5x_xts_enc aese v0.16b,v16.16b aesmc v0.16b,v0.16b aese v1.16b,v16.16b aesmc v1.16b,v1.16b aese v24.16b,v16.16b aesmc v24.16b,v24.16b aese v25.16b,v16.16b aesmc v25.16b,v25.16b aese v26.16b,v16.16b aesmc v26.16b,v26.16b subs x2,x2,#0x50 // because .Lxts_enc_tail4x aese v0.16b,v17.16b aesmc v0.16b,v0.16b aese v1.16b,v17.16b aesmc v1.16b,v1.16b aese v24.16b,v17.16b aesmc v24.16b,v24.16b aese v25.16b,v17.16b aesmc v25.16b,v25.16b aese v26.16b,v17.16b aesmc v26.16b,v26.16b csel x6,xzr,x2,gt // borrow x6, w6, "gt" is not typo mov x7,x3 aese v0.16b,v18.16b aesmc v0.16b,v0.16b aese v1.16b,v18.16b aesmc v1.16b,v1.16b aese v24.16b,v18.16b aesmc v24.16b,v24.16b aese v25.16b,v18.16b aesmc v25.16b,v25.16b aese v26.16b,v18.16b aesmc v26.16b,v26.16b add x0,x0,x6 // x0 is adjusted in such way that // at exit from the loop v1.16b-v26.16b // are loaded with last "words" add x6,x2,#0x60 // because .Lxts_enc_tail4x aese v0.16b,v19.16b aesmc v0.16b,v0.16b aese v1.16b,v19.16b aesmc v1.16b,v1.16b aese v24.16b,v19.16b aesmc v24.16b,v24.16b aese v25.16b,v19.16b aesmc v25.16b,v25.16b aese v26.16b,v19.16b aesmc v26.16b,v26.16b aese v0.16b,v20.16b aesmc v0.16b,v0.16b aese v1.16b,v20.16b aesmc v1.16b,v1.16b aese v24.16b,v20.16b aesmc v24.16b,v24.16b aese v25.16b,v20.16b aesmc v25.16b,v25.16b aese v26.16b,v20.16b aesmc v26.16b,v26.16b aese v0.16b,v21.16b aesmc v0.16b,v0.16b aese v1.16b,v21.16b aesmc v1.16b,v1.16b aese v24.16b,v21.16b aesmc v24.16b,v24.16b aese v25.16b,v21.16b aesmc v25.16b,v25.16b aese v26.16b,v21.16b aesmc v26.16b,v26.16b aese v0.16b,v22.16b aesmc v0.16b,v0.16b aese v1.16b,v22.16b aesmc v1.16b,v1.16b aese v24.16b,v22.16b aesmc v24.16b,v24.16b aese v25.16b,v22.16b aesmc v25.16b,v25.16b aese v26.16b,v22.16b aesmc v26.16b,v26.16b eor v4.16b,v7.16b,v6.16b aese v0.16b,v23.16b // The iv for first block of one iteration extr x22,x10,x10,#32 extr x10,x10,x9,#63 and w11,w19,w22,asr#31 eor x9,x11,x9,lsl#1 fmov d6,x9 fmov v6.d[1],x10 eor v5.16b,v7.16b,v8.16b ld1 {v2.16b},[x0],#16 aese v1.16b,v23.16b // The iv for second block extr x22,x10,x10,#32 extr x10,x10,x9,#63 and w11,w19,w22,asr#31 eor x9,x11,x9,lsl#1 fmov d8,x9 fmov v8.d[1],x10 eor v17.16b,v7.16b,v9.16b ld1 {v3.16b},[x0],#16 aese v24.16b,v23.16b // The iv for third block extr x22,x10,x10,#32 extr x10,x10,x9,#63 and w11,w19,w22,asr#31 eor x9,x11,x9,lsl#1 fmov d9,x9 fmov v9.d[1],x10 eor v30.16b,v7.16b,v10.16b ld1 {v27.16b},[x0],#16 aese v25.16b,v23.16b // The iv for fourth block extr x22,x10,x10,#32 extr x10,x10,x9,#63 and w11,w19,w22,asr#31 eor x9,x11,x9,lsl#1 fmov d10,x9 fmov v10.d[1],x10 eor v31.16b,v7.16b,v11.16b ld1 {v28.16b},[x0],#16 aese v26.16b,v23.16b // The iv for fifth block extr x22,x10,x10,#32 extr x10,x10,x9,#63 and w11,w19,w22,asr #31 eor x9,x11,x9,lsl #1 fmov d11,x9 fmov v11.d[1],x10 ld1 {v29.16b},[x0],#16 cbz x6,.Lxts_enc_tail4x ld1 {v16.4s},[x7],#16 // re-pre-load rndkey[0] eor v4.16b,v4.16b,v0.16b eor v0.16b,v2.16b,v6.16b eor v5.16b,v5.16b,v1.16b eor v1.16b,v3.16b,v8.16b eor v17.16b,v17.16b,v24.16b eor v24.16b,v27.16b,v9.16b eor v30.16b,v30.16b,v25.16b eor v25.16b,v28.16b,v10.16b eor v31.16b,v31.16b,v26.16b st1 {v4.16b},[x1],#16 eor v26.16b,v29.16b,v11.16b st1 {v5.16b},[x1],#16 mov w6,w5 st1 {v17.16b},[x1],#16 ld1 {v17.4s},[x7],#16 // re-pre-load rndkey[1] st1 {v30.16b},[x1],#16 st1 {v31.16b},[x1],#16 b.hs .Loop5x_xts_enc // If left 4 blocks, borrow the five block's processing. cmn x2,#0x10 b.ne .Loop5x_enc_after orr v11.16b,v10.16b,v10.16b orr v10.16b,v9.16b,v9.16b orr v9.16b,v8.16b,v8.16b orr v8.16b,v6.16b,v6.16b fmov x9,d11 fmov x10,v11.d[1] eor v0.16b,v6.16b,v2.16b eor v1.16b,v8.16b,v3.16b eor v24.16b,v27.16b,v9.16b eor v25.16b,v28.16b,v10.16b eor v26.16b,v29.16b,v11.16b b.eq .Loop5x_xts_enc .Loop5x_enc_after: add x2,x2,#0x50 cbz x2,.Lxts_enc_done add w6,w5,#2 subs x2,x2,#0x30 b.lo .Lxts_inner_enc_tail eor v0.16b,v6.16b,v27.16b eor v1.16b,v8.16b,v28.16b eor v24.16b,v29.16b,v9.16b b .Lxts_outer_enc_tail .align 4 .Lxts_enc_tail4x: add x0,x0,#16 eor v5.16b,v1.16b,v5.16b st1 {v5.16b},[x1],#16 eor v17.16b,v24.16b,v17.16b st1 {v17.16b},[x1],#16 eor v30.16b,v25.16b,v30.16b eor v31.16b,v26.16b,v31.16b st1 {v30.16b,v31.16b},[x1],#32 b .Lxts_enc_done .align 4 .Lxts_outer_enc_tail: aese v0.16b,v16.16b aesmc v0.16b,v0.16b aese v1.16b,v16.16b aesmc v1.16b,v1.16b aese v24.16b,v16.16b aesmc v24.16b,v24.16b ld1 {v16.4s},[x7],#16 subs w6,w6,#2 aese v0.16b,v17.16b aesmc v0.16b,v0.16b aese v1.16b,v17.16b aesmc v1.16b,v1.16b aese v24.16b,v17.16b aesmc v24.16b,v24.16b ld1 {v17.4s},[x7],#16 b.gt .Lxts_outer_enc_tail aese v0.16b,v16.16b aesmc v0.16b,v0.16b aese v1.16b,v16.16b aesmc v1.16b,v1.16b aese v24.16b,v16.16b aesmc v24.16b,v24.16b eor v4.16b,v6.16b,v7.16b subs x2,x2,#0x30 // The iv for first block fmov x9,d9 fmov x10,v9.d[1] //mov w19,#0x87 extr x22,x10,x10,#32 extr x10,x10,x9,#63 and w11,w19,w22,asr#31 eor x9,x11,x9,lsl#1 fmov d6,x9 fmov v6.d[1],x10 eor v5.16b,v8.16b,v7.16b csel x6,x2,x6,lo // x6, w6, is zero at this point aese v0.16b,v17.16b aesmc v0.16b,v0.16b aese v1.16b,v17.16b aesmc v1.16b,v1.16b aese v24.16b,v17.16b aesmc v24.16b,v24.16b eor v17.16b,v9.16b,v7.16b add x6,x6,#0x20 add x0,x0,x6 mov x7,x3 aese v0.16b,v20.16b aesmc v0.16b,v0.16b aese v1.16b,v20.16b aesmc v1.16b,v1.16b aese v24.16b,v20.16b aesmc v24.16b,v24.16b aese v0.16b,v21.16b aesmc v0.16b,v0.16b aese v1.16b,v21.16b aesmc v1.16b,v1.16b aese v24.16b,v21.16b aesmc v24.16b,v24.16b aese v0.16b,v22.16b aesmc v0.16b,v0.16b aese v1.16b,v22.16b aesmc v1.16b,v1.16b aese v24.16b,v22.16b aesmc v24.16b,v24.16b aese v0.16b,v23.16b aese v1.16b,v23.16b aese v24.16b,v23.16b ld1 {v27.16b},[x0],#16 add w6,w5,#2 ld1 {v16.4s},[x7],#16 // re-pre-load rndkey[0] eor v4.16b,v4.16b,v0.16b eor v5.16b,v5.16b,v1.16b eor v24.16b,v24.16b,v17.16b ld1 {v17.4s},[x7],#16 // re-pre-load rndkey[1] st1 {v4.16b},[x1],#16 st1 {v5.16b},[x1],#16 st1 {v24.16b},[x1],#16 cmn x2,#0x30 b.eq .Lxts_enc_done .Lxts_encxor_one: orr v28.16b,v3.16b,v3.16b orr v29.16b,v27.16b,v27.16b nop .Lxts_inner_enc_tail: cmn x2,#0x10 eor v1.16b,v28.16b,v6.16b eor v24.16b,v29.16b,v8.16b b.eq .Lxts_enc_tail_loop eor v24.16b,v29.16b,v6.16b .Lxts_enc_tail_loop: aese v1.16b,v16.16b aesmc v1.16b,v1.16b aese v24.16b,v16.16b aesmc v24.16b,v24.16b ld1 {v16.4s},[x7],#16 subs w6,w6,#2 aese v1.16b,v17.16b aesmc v1.16b,v1.16b aese v24.16b,v17.16b aesmc v24.16b,v24.16b ld1 {v17.4s},[x7],#16 b.gt .Lxts_enc_tail_loop aese v1.16b,v16.16b aesmc v1.16b,v1.16b aese v24.16b,v16.16b aesmc v24.16b,v24.16b aese v1.16b,v17.16b aesmc v1.16b,v1.16b aese v24.16b,v17.16b aesmc v24.16b,v24.16b aese v1.16b,v20.16b aesmc v1.16b,v1.16b aese v24.16b,v20.16b aesmc v24.16b,v24.16b cmn x2,#0x20 aese v1.16b,v21.16b aesmc v1.16b,v1.16b aese v24.16b,v21.16b aesmc v24.16b,v24.16b eor v5.16b,v6.16b,v7.16b aese v1.16b,v22.16b aesmc v1.16b,v1.16b aese v24.16b,v22.16b aesmc v24.16b,v24.16b eor v17.16b,v8.16b,v7.16b aese v1.16b,v23.16b aese v24.16b,v23.16b b.eq .Lxts_enc_one eor v5.16b,v5.16b,v1.16b st1 {v5.16b},[x1],#16 eor v17.16b,v17.16b,v24.16b orr v6.16b,v8.16b,v8.16b st1 {v17.16b},[x1],#16 fmov x9,d8 fmov x10,v8.d[1] mov w19,#0x87 extr x22,x10,x10,#32 extr x10,x10,x9,#63 and w11,w19,w22,asr #31 eor x9,x11,x9,lsl #1 fmov d6,x9 fmov v6.d[1],x10 b .Lxts_enc_done .Lxts_enc_one: eor v5.16b,v5.16b,v24.16b orr v6.16b,v6.16b,v6.16b st1 {v5.16b},[x1],#16 fmov x9,d6 fmov x10,v6.d[1] mov w19,#0x87 extr x22,x10,x10,#32 extr x10,x10,x9,#63 and w11,w19,w22,asr #31 eor x9,x11,x9,lsl #1 fmov d6,x9 fmov v6.d[1],x10 b .Lxts_enc_done .align 5 .Lxts_enc_done: // Process the tail block with cipher stealing. tst x21,#0xf b.eq .Lxts_abort mov x20,x0 mov x13,x1 sub x1,x1,#16 .composite_enc_loop: subs x21,x21,#1 ldrb w15,[x1,x21] ldrb w14,[x20,x21] strb w15,[x13,x21] strb w14,[x1,x21] b.gt .composite_enc_loop .Lxts_enc_load_done: ld1 {v26.16b},[x1] eor v26.16b,v26.16b,v6.16b // Encrypt the composite block to get the last second encrypted text block ldr w6,[x3,#240] // load key schedule... ld1 {v0.4s},[x3],#16 sub w6,w6,#2 ld1 {v1.4s},[x3],#16 // load key schedule... .Loop_final_enc: aese v26.16b,v0.16b aesmc v26.16b,v26.16b ld1 {v0.4s},[x3],#16 subs w6,w6,#2 aese v26.16b,v1.16b aesmc v26.16b,v26.16b ld1 {v1.4s},[x3],#16 b.gt .Loop_final_enc aese v26.16b,v0.16b aesmc v26.16b,v26.16b ld1 {v0.4s},[x3] aese v26.16b,v1.16b eor v26.16b,v26.16b,v0.16b eor v26.16b,v26.16b,v6.16b st1 {v26.16b},[x1] .Lxts_abort: ldp x21,x22,[sp,#48] ldp d8,d9,[sp,#32] ldp d10,d11,[sp,#16] ldp x19,x20,[sp],#64 .Lxts_enc_final_abort: ret .size aes_v8_xts_encrypt,.-aes_v8_xts_encrypt .globl aes_v8_xts_decrypt .type aes_v8_xts_decrypt,%function .align 5 aes_v8_xts_decrypt: cmp x2,#16 // Original input data size bigger than 16, jump to big size processing. b.ne .Lxts_dec_big_size // Encrypt the iv with key2, as the first XEX iv. ldr w6,[x4,#240] ld1 {v0.4s},[x4],#16 ld1 {v6.16b},[x5] sub w6,w6,#2 ld1 {v1.4s},[x4],#16 .Loop_dec_small_iv_enc: aese v6.16b,v0.16b aesmc v6.16b,v6.16b ld1 {v0.4s},[x4],#16 subs w6,w6,#2 aese v6.16b,v1.16b aesmc v6.16b,v6.16b ld1 {v1.4s},[x4],#16 b.gt .Loop_dec_small_iv_enc aese v6.16b,v0.16b aesmc v6.16b,v6.16b ld1 {v0.4s},[x4] aese v6.16b,v1.16b eor v6.16b,v6.16b,v0.16b ld1 {v0.16b},[x0] eor v0.16b,v6.16b,v0.16b ldr w6,[x3,#240] ld1 {v28.4s,v29.4s},[x3],#32 // load key schedule... aesd v0.16b,v28.16b aesimc v0.16b,v0.16b ld1 {v16.4s,v17.4s},[x3],#32 // load key schedule... aesd v0.16b,v29.16b aesimc v0.16b,v0.16b subs w6,w6,#10 // bias b.eq .Lxts_128_dec .Lxts_dec_round_loop: aesd v0.16b,v16.16b aesimc v0.16b,v0.16b ld1 {v16.4s},[x3],#16 // load key schedule... aesd v0.16b,v17.16b aesimc v0.16b,v0.16b ld1 {v17.4s},[x3],#16 // load key schedule... subs w6,w6,#2 // bias b.gt .Lxts_dec_round_loop .Lxts_128_dec: ld1 {v18.4s,v19.4s},[x3],#32 // load key schedule... aesd v0.16b,v16.16b aesimc v0.16b,v0.16b aesd v0.16b,v17.16b aesimc v0.16b,v0.16b ld1 {v20.4s,v21.4s},[x3],#32 // load key schedule... aesd v0.16b,v18.16b aesimc v0.16b,v0.16b aesd v0.16b,v19.16b aesimc v0.16b,v0.16b ld1 {v22.4s,v23.4s},[x3],#32 // load key schedule... aesd v0.16b,v20.16b aesimc v0.16b,v0.16b aesd v0.16b,v21.16b aesimc v0.16b,v0.16b ld1 {v7.4s},[x3] aesd v0.16b,v22.16b aesimc v0.16b,v0.16b aesd v0.16b,v23.16b eor v0.16b,v0.16b,v7.16b eor v0.16b,v6.16b,v0.16b st1 {v0.16b},[x1] b .Lxts_dec_final_abort .Lxts_dec_big_size: stp x19,x20,[sp,#-64]! stp x21,x22,[sp,#48] stp d8,d9,[sp,#32] stp d10,d11,[sp,#16] and x21,x2,#0xf and x2,x2,#-16 subs x2,x2,#16 mov x8,#16 b.lo .Lxts_dec_abort // Encrypt the iv with key2, as the first XEX iv ldr w6,[x4,#240] ld1 {v0.4s},[x4],#16 ld1 {v6.16b},[x5] sub w6,w6,#2 ld1 {v1.4s},[x4],#16 .Loop_dec_iv_enc: aese v6.16b,v0.16b aesmc v6.16b,v6.16b ld1 {v0.4s},[x4],#16 subs w6,w6,#2 aese v6.16b,v1.16b aesmc v6.16b,v6.16b ld1 {v1.4s},[x4],#16 b.gt .Loop_dec_iv_enc aese v6.16b,v0.16b aesmc v6.16b,v6.16b ld1 {v0.4s},[x4] aese v6.16b,v1.16b eor v6.16b,v6.16b,v0.16b // The iv for second block // x9- iv(low), x10 - iv(high) // the five ivs stored into, v6.16b,v8.16b,v9.16b,v10.16b,v11.16b fmov x9,d6 fmov x10,v6.d[1] mov w19,#0x87 extr x22,x10,x10,#32 extr x10,x10,x9,#63 and w11,w19,w22,asr #31 eor x9,x11,x9,lsl #1 fmov d8,x9 fmov v8.d[1],x10 ldr w5,[x3,#240] // load rounds number // The iv for third block extr x22,x10,x10,#32 extr x10,x10,x9,#63 and w11,w19,w22,asr #31 eor x9,x11,x9,lsl #1 fmov d9,x9 fmov v9.d[1],x10 ld1 {v16.4s,v17.4s},[x3] // load key schedule... sub w5,w5,#6 add x7,x3,x5,lsl#4 // pointer to last 7 round keys sub w5,w5,#2 ld1 {v18.4s,v19.4s},[x7],#32 // load key schedule... ld1 {v20.4s,v21.4s},[x7],#32 ld1 {v22.4s,v23.4s},[x7],#32 ld1 {v7.4s},[x7] // The iv for fourth block extr x22,x10,x10,#32 extr x10,x10,x9,#63 and w11,w19,w22,asr #31 eor x9,x11,x9,lsl #1 fmov d10,x9 fmov v10.d[1],x10 add x7,x3,#32 mov w6,w5 b .Lxts_dec // Decryption .align 5 .Lxts_dec: tst x21,#0xf b.eq .Lxts_dec_begin subs x2,x2,#16 csel x8,xzr,x8,eq ld1 {v0.16b},[x0],#16 b.lo .Lxts_done sub x0,x0,#16 .Lxts_dec_begin: ld1 {v0.16b},[x0],x8 subs x2,x2,#32 // bias add w6,w5,#2 orr v3.16b,v0.16b,v0.16b orr v1.16b,v0.16b,v0.16b orr v28.16b,v0.16b,v0.16b ld1 {v24.16b},[x0],#16 orr v27.16b,v24.16b,v24.16b orr v29.16b,v24.16b,v24.16b b.lo .Lxts_inner_dec_tail eor v0.16b,v0.16b,v6.16b // before decryt, xor with iv eor v24.16b,v24.16b,v8.16b orr v1.16b,v24.16b,v24.16b ld1 {v24.16b},[x0],#16 orr v2.16b,v0.16b,v0.16b orr v3.16b,v1.16b,v1.16b eor v27.16b,v24.16b,v9.16b // third block xox with third iv eor v24.16b,v24.16b,v9.16b cmp x2,#32 b.lo .Lxts_outer_dec_tail ld1 {v25.16b},[x0],#16 // The iv for fifth block extr x22,x10,x10,#32 extr x10,x10,x9,#63 and w11,w19,w22,asr #31 eor x9,x11,x9,lsl #1 fmov d11,x9 fmov v11.d[1],x10 ld1 {v26.16b},[x0],#16 eor v25.16b,v25.16b,v10.16b // the fourth block eor v26.16b,v26.16b,v11.16b sub x2,x2,#32 // bias mov w6,w5 b .Loop5x_xts_dec .align 4 .Loop5x_xts_dec: aesd v0.16b,v16.16b aesimc v0.16b,v0.16b aesd v1.16b,v16.16b aesimc v1.16b,v1.16b aesd v24.16b,v16.16b aesimc v24.16b,v24.16b aesd v25.16b,v16.16b aesimc v25.16b,v25.16b aesd v26.16b,v16.16b aesimc v26.16b,v26.16b ld1 {v16.4s},[x7],#16 // load key schedule... subs w6,w6,#2 aesd v0.16b,v17.16b aesimc v0.16b,v0.16b aesd v1.16b,v17.16b aesimc v1.16b,v1.16b aesd v24.16b,v17.16b aesimc v24.16b,v24.16b aesd v25.16b,v17.16b aesimc v25.16b,v25.16b aesd v26.16b,v17.16b aesimc v26.16b,v26.16b ld1 {v17.4s},[x7],#16 // load key schedule... b.gt .Loop5x_xts_dec aesd v0.16b,v16.16b aesimc v0.16b,v0.16b aesd v1.16b,v16.16b aesimc v1.16b,v1.16b aesd v24.16b,v16.16b aesimc v24.16b,v24.16b aesd v25.16b,v16.16b aesimc v25.16b,v25.16b aesd v26.16b,v16.16b aesimc v26.16b,v26.16b subs x2,x2,#0x50 // because .Lxts_dec_tail4x aesd v0.16b,v17.16b aesimc v0.16b,v0.16b aesd v1.16b,v17.16b aesimc v1.16b,v1.16b aesd v24.16b,v17.16b aesimc v24.16b,v24.16b aesd v25.16b,v17.16b aesimc v25.16b,v25.16b aesd v26.16b,v17.16b aesimc v26.16b,v26.16b csel x6,xzr,x2,gt // borrow x6, w6, "gt" is not typo mov x7,x3 aesd v0.16b,v18.16b aesimc v0.16b,v0.16b aesd v1.16b,v18.16b aesimc v1.16b,v1.16b aesd v24.16b,v18.16b aesimc v24.16b,v24.16b aesd v25.16b,v18.16b aesimc v25.16b,v25.16b aesd v26.16b,v18.16b aesimc v26.16b,v26.16b add x0,x0,x6 // x0 is adjusted in such way that // at exit from the loop v1.16b-v26.16b // are loaded with last "words" add x6,x2,#0x60 // because .Lxts_dec_tail4x aesd v0.16b,v19.16b aesimc v0.16b,v0.16b aesd v1.16b,v19.16b aesimc v1.16b,v1.16b aesd v24.16b,v19.16b aesimc v24.16b,v24.16b aesd v25.16b,v19.16b aesimc v25.16b,v25.16b aesd v26.16b,v19.16b aesimc v26.16b,v26.16b aesd v0.16b,v20.16b aesimc v0.16b,v0.16b aesd v1.16b,v20.16b aesimc v1.16b,v1.16b aesd v24.16b,v20.16b aesimc v24.16b,v24.16b aesd v25.16b,v20.16b aesimc v25.16b,v25.16b aesd v26.16b,v20.16b aesimc v26.16b,v26.16b aesd v0.16b,v21.16b aesimc v0.16b,v0.16b aesd v1.16b,v21.16b aesimc v1.16b,v1.16b aesd v24.16b,v21.16b aesimc v24.16b,v24.16b aesd v25.16b,v21.16b aesimc v25.16b,v25.16b aesd v26.16b,v21.16b aesimc v26.16b,v26.16b aesd v0.16b,v22.16b aesimc v0.16b,v0.16b aesd v1.16b,v22.16b aesimc v1.16b,v1.16b aesd v24.16b,v22.16b aesimc v24.16b,v24.16b aesd v25.16b,v22.16b aesimc v25.16b,v25.16b aesd v26.16b,v22.16b aesimc v26.16b,v26.16b eor v4.16b,v7.16b,v6.16b aesd v0.16b,v23.16b // The iv for first block of next iteration. extr x22,x10,x10,#32 extr x10,x10,x9,#63 and w11,w19,w22,asr #31 eor x9,x11,x9,lsl #1 fmov d6,x9 fmov v6.d[1],x10 eor v5.16b,v7.16b,v8.16b ld1 {v2.16b},[x0],#16 aesd v1.16b,v23.16b // The iv for second block extr x22,x10,x10,#32 extr x10,x10,x9,#63 and w11,w19,w22,asr #31 eor x9,x11,x9,lsl #1 fmov d8,x9 fmov v8.d[1],x10 eor v17.16b,v7.16b,v9.16b ld1 {v3.16b},[x0],#16 aesd v24.16b,v23.16b // The iv for third block extr x22,x10,x10,#32 extr x10,x10,x9,#63 and w11,w19,w22,asr #31 eor x9,x11,x9,lsl #1 fmov d9,x9 fmov v9.d[1],x10 eor v30.16b,v7.16b,v10.16b ld1 {v27.16b},[x0],#16 aesd v25.16b,v23.16b // The iv for fourth block extr x22,x10,x10,#32 extr x10,x10,x9,#63 and w11,w19,w22,asr #31 eor x9,x11,x9,lsl #1 fmov d10,x9 fmov v10.d[1],x10 eor v31.16b,v7.16b,v11.16b ld1 {v28.16b},[x0],#16 aesd v26.16b,v23.16b // The iv for fifth block extr x22,x10,x10,#32 extr x10,x10,x9,#63 and w11,w19,w22,asr #31 eor x9,x11,x9,lsl #1 fmov d11,x9 fmov v11.d[1],x10 ld1 {v29.16b},[x0],#16 cbz x6,.Lxts_dec_tail4x ld1 {v16.4s},[x7],#16 // re-pre-load rndkey[0] eor v4.16b,v4.16b,v0.16b eor v0.16b,v2.16b,v6.16b eor v5.16b,v5.16b,v1.16b eor v1.16b,v3.16b,v8.16b eor v17.16b,v17.16b,v24.16b eor v24.16b,v27.16b,v9.16b eor v30.16b,v30.16b,v25.16b eor v25.16b,v28.16b,v10.16b eor v31.16b,v31.16b,v26.16b st1 {v4.16b},[x1],#16 eor v26.16b,v29.16b,v11.16b st1 {v5.16b},[x1],#16 mov w6,w5 st1 {v17.16b},[x1],#16 ld1 {v17.4s},[x7],#16 // re-pre-load rndkey[1] st1 {v30.16b},[x1],#16 st1 {v31.16b},[x1],#16 b.hs .Loop5x_xts_dec cmn x2,#0x10 b.ne .Loop5x_dec_after // If x2(x2) equal to -0x10, the left blocks is 4. // After specially processing, utilize the five blocks processing again. // It will use the following IVs: v6.16b,v6.16b,v8.16b,v9.16b,v10.16b. orr v11.16b,v10.16b,v10.16b orr v10.16b,v9.16b,v9.16b orr v9.16b,v8.16b,v8.16b orr v8.16b,v6.16b,v6.16b fmov x9,d11 fmov x10,v11.d[1] eor v0.16b,v6.16b,v2.16b eor v1.16b,v8.16b,v3.16b eor v24.16b,v27.16b,v9.16b eor v25.16b,v28.16b,v10.16b eor v26.16b,v29.16b,v11.16b b.eq .Loop5x_xts_dec .Loop5x_dec_after: add x2,x2,#0x50 cbz x2,.Lxts_done add w6,w5,#2 subs x2,x2,#0x30 b.lo .Lxts_inner_dec_tail eor v0.16b,v6.16b,v27.16b eor v1.16b,v8.16b,v28.16b eor v24.16b,v29.16b,v9.16b b .Lxts_outer_dec_tail .align 4 .Lxts_dec_tail4x: add x0,x0,#16 tst x21,#0xf eor v5.16b,v1.16b,v4.16b st1 {v5.16b},[x1],#16 eor v17.16b,v24.16b,v17.16b st1 {v17.16b},[x1],#16 eor v30.16b,v25.16b,v30.16b eor v31.16b,v26.16b,v31.16b st1 {v30.16b,v31.16b},[x1],#32 b.eq .Lxts_dec_abort ld1 {v0.16b},[x0],#16 b .Lxts_done .align 4 .Lxts_outer_dec_tail: aesd v0.16b,v16.16b aesimc v0.16b,v0.16b aesd v1.16b,v16.16b aesimc v1.16b,v1.16b aesd v24.16b,v16.16b aesimc v24.16b,v24.16b ld1 {v16.4s},[x7],#16 subs w6,w6,#2 aesd v0.16b,v17.16b aesimc v0.16b,v0.16b aesd v1.16b,v17.16b aesimc v1.16b,v1.16b aesd v24.16b,v17.16b aesimc v24.16b,v24.16b ld1 {v17.4s},[x7],#16 b.gt .Lxts_outer_dec_tail aesd v0.16b,v16.16b aesimc v0.16b,v0.16b aesd v1.16b,v16.16b aesimc v1.16b,v1.16b aesd v24.16b,v16.16b aesimc v24.16b,v24.16b eor v4.16b,v6.16b,v7.16b subs x2,x2,#0x30 // The iv for first block fmov x9,d9 fmov x10,v9.d[1] mov w19,#0x87 extr x22,x10,x10,#32 extr x10,x10,x9,#63 and w11,w19,w22,asr #31 eor x9,x11,x9,lsl #1 fmov d6,x9 fmov v6.d[1],x10 eor v5.16b,v8.16b,v7.16b csel x6,x2,x6,lo // x6, w6, is zero at this point aesd v0.16b,v17.16b aesimc v0.16b,v0.16b aesd v1.16b,v17.16b aesimc v1.16b,v1.16b aesd v24.16b,v17.16b aesimc v24.16b,v24.16b eor v17.16b,v9.16b,v7.16b // The iv for second block extr x22,x10,x10,#32 extr x10,x10,x9,#63 and w11,w19,w22,asr #31 eor x9,x11,x9,lsl #1 fmov d8,x9 fmov v8.d[1],x10 add x6,x6,#0x20 add x0,x0,x6 // x0 is adjusted to the last data mov x7,x3 // The iv for third block extr x22,x10,x10,#32 extr x10,x10,x9,#63 and w11,w19,w22,asr #31 eor x9,x11,x9,lsl #1 fmov d9,x9 fmov v9.d[1],x10 aesd v0.16b,v20.16b aesimc v0.16b,v0.16b aesd v1.16b,v20.16b aesimc v1.16b,v1.16b aesd v24.16b,v20.16b aesimc v24.16b,v24.16b aesd v0.16b,v21.16b aesimc v0.16b,v0.16b aesd v1.16b,v21.16b aesimc v1.16b,v1.16b aesd v24.16b,v21.16b aesimc v24.16b,v24.16b aesd v0.16b,v22.16b aesimc v0.16b,v0.16b aesd v1.16b,v22.16b aesimc v1.16b,v1.16b aesd v24.16b,v22.16b aesimc v24.16b,v24.16b ld1 {v27.16b},[x0],#16 aesd v0.16b,v23.16b aesd v1.16b,v23.16b aesd v24.16b,v23.16b ld1 {v16.4s},[x7],#16 // re-pre-load rndkey[0] add w6,w5,#2 eor v4.16b,v4.16b,v0.16b eor v5.16b,v5.16b,v1.16b eor v24.16b,v24.16b,v17.16b ld1 {v17.4s},[x7],#16 // re-pre-load rndkey[1] st1 {v4.16b},[x1],#16 st1 {v5.16b},[x1],#16 st1 {v24.16b},[x1],#16 cmn x2,#0x30 add x2,x2,#0x30 b.eq .Lxts_done sub x2,x2,#0x30 orr v28.16b,v3.16b,v3.16b orr v29.16b,v27.16b,v27.16b nop .Lxts_inner_dec_tail: // x2 == -0x10 means two blocks left. cmn x2,#0x10 eor v1.16b,v28.16b,v6.16b eor v24.16b,v29.16b,v8.16b b.eq .Lxts_dec_tail_loop eor v24.16b,v29.16b,v6.16b .Lxts_dec_tail_loop: aesd v1.16b,v16.16b aesimc v1.16b,v1.16b aesd v24.16b,v16.16b aesimc v24.16b,v24.16b ld1 {v16.4s},[x7],#16 subs w6,w6,#2 aesd v1.16b,v17.16b aesimc v1.16b,v1.16b aesd v24.16b,v17.16b aesimc v24.16b,v24.16b ld1 {v17.4s},[x7],#16 b.gt .Lxts_dec_tail_loop aesd v1.16b,v16.16b aesimc v1.16b,v1.16b aesd v24.16b,v16.16b aesimc v24.16b,v24.16b aesd v1.16b,v17.16b aesimc v1.16b,v1.16b aesd v24.16b,v17.16b aesimc v24.16b,v24.16b aesd v1.16b,v20.16b aesimc v1.16b,v1.16b aesd v24.16b,v20.16b aesimc v24.16b,v24.16b cmn x2,#0x20 aesd v1.16b,v21.16b aesimc v1.16b,v1.16b aesd v24.16b,v21.16b aesimc v24.16b,v24.16b eor v5.16b,v6.16b,v7.16b aesd v1.16b,v22.16b aesimc v1.16b,v1.16b aesd v24.16b,v22.16b aesimc v24.16b,v24.16b eor v17.16b,v8.16b,v7.16b aesd v1.16b,v23.16b aesd v24.16b,v23.16b b.eq .Lxts_dec_one eor v5.16b,v5.16b,v1.16b eor v17.16b,v17.16b,v24.16b orr v6.16b,v9.16b,v9.16b orr v8.16b,v10.16b,v10.16b st1 {v5.16b},[x1],#16 st1 {v17.16b},[x1],#16 add x2,x2,#16 b .Lxts_done .Lxts_dec_one: eor v5.16b,v5.16b,v24.16b orr v6.16b,v8.16b,v8.16b orr v8.16b,v9.16b,v9.16b st1 {v5.16b},[x1],#16 add x2,x2,#32 .Lxts_done: tst x21,#0xf b.eq .Lxts_dec_abort // Processing the last two blocks with cipher stealing. mov x7,x3 cbnz x2,.Lxts_dec_1st_done ld1 {v0.16b},[x0],#16 // Decrypt the last secod block to get the last plain text block .Lxts_dec_1st_done: eor v26.16b,v0.16b,v8.16b ldr w6,[x3,#240] ld1 {v0.4s},[x3],#16 sub w6,w6,#2 ld1 {v1.4s},[x3],#16 .Loop_final_2nd_dec: aesd v26.16b,v0.16b aesimc v26.16b,v26.16b ld1 {v0.4s},[x3],#16 // load key schedule... subs w6,w6,#2 aesd v26.16b,v1.16b aesimc v26.16b,v26.16b ld1 {v1.4s},[x3],#16 // load key schedule... b.gt .Loop_final_2nd_dec aesd v26.16b,v0.16b aesimc v26.16b,v26.16b ld1 {v0.4s},[x3] aesd v26.16b,v1.16b eor v26.16b,v26.16b,v0.16b eor v26.16b,v26.16b,v8.16b st1 {v26.16b},[x1] mov x20,x0 add x13,x1,#16 // Composite the tailcnt "16 byte not aligned block" into the last second plain blocks // to get the last encrypted block. .composite_dec_loop: subs x21,x21,#1 ldrb w15,[x1,x21] ldrb w14,[x20,x21] strb w15,[x13,x21] strb w14,[x1,x21] b.gt .composite_dec_loop .Lxts_dec_load_done: ld1 {v26.16b},[x1] eor v26.16b,v26.16b,v6.16b // Decrypt the composite block to get the last second plain text block ldr w6,[x7,#240] ld1 {v0.4s},[x7],#16 sub w6,w6,#2 ld1 {v1.4s},[x7],#16 .Loop_final_dec: aesd v26.16b,v0.16b aesimc v26.16b,v26.16b ld1 {v0.4s},[x7],#16 // load key schedule... subs w6,w6,#2 aesd v26.16b,v1.16b aesimc v26.16b,v26.16b ld1 {v1.4s},[x7],#16 // load key schedule... b.gt .Loop_final_dec aesd v26.16b,v0.16b aesimc v26.16b,v26.16b ld1 {v0.4s},[x7] aesd v26.16b,v1.16b eor v26.16b,v26.16b,v0.16b eor v26.16b,v26.16b,v6.16b st1 {v26.16b},[x1] .Lxts_dec_abort: ldp x21,x22,[sp,#48] ldp d8,d9,[sp,#32] ldp d10,d11,[sp,#16] ldp x19,x20,[sp],#64 .Lxts_dec_final_abort: ret .size aes_v8_xts_decrypt,.-aes_v8_xts_decrypt #endif diff --git a/sys/crypto/openssl/aarch64/arm_arch.h b/sys/crypto/openssl/aarch64/arm_arch.h index 45d7e1556475..ec4a087fede2 100644 --- a/sys/crypto/openssl/aarch64/arm_arch.h +++ b/sys/crypto/openssl/aarch64/arm_arch.h @@ -1,129 +1,124 @@ /* - * Copyright 2011-2022 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2011-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ #ifndef OSSL_CRYPTO_ARM_ARCH_H # define OSSL_CRYPTO_ARM_ARCH_H # if !defined(__ARM_ARCH__) # if defined(__CC_ARM) # define __ARM_ARCH__ __TARGET_ARCH_ARM # if defined(__BIG_ENDIAN) # define __ARMEB__ # else # define __ARMEL__ # endif # elif defined(__GNUC__) # if defined(__aarch64__) # define __ARM_ARCH__ 8 -# if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ -# define __ARMEB__ -# else -# define __ARMEL__ -# endif /* * Why doesn't gcc define __ARM_ARCH__? Instead it defines * bunch of below macros. See all_architectures[] table in * gcc/config/arm/arm.c. On a side note it defines * __ARMEL__/__ARMEB__ for little-/big-endian. */ # elif defined(__ARM_ARCH) # define __ARM_ARCH__ __ARM_ARCH # elif defined(__ARM_ARCH_8A__) # define __ARM_ARCH__ 8 # elif defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || \ defined(__ARM_ARCH_7R__)|| defined(__ARM_ARCH_7M__) || \ defined(__ARM_ARCH_7EM__) # define __ARM_ARCH__ 7 # elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || \ defined(__ARM_ARCH_6K__)|| defined(__ARM_ARCH_6M__) || \ defined(__ARM_ARCH_6Z__)|| defined(__ARM_ARCH_6ZK__) || \ defined(__ARM_ARCH_6T2__) # define __ARM_ARCH__ 6 # elif defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) || \ defined(__ARM_ARCH_5E__)|| defined(__ARM_ARCH_5TE__) || \ defined(__ARM_ARCH_5TEJ__) # define __ARM_ARCH__ 5 # elif defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) # define __ARM_ARCH__ 4 # else # error "unsupported ARM architecture" # endif # endif # endif # if !defined(__ARM_MAX_ARCH__) # define __ARM_MAX_ARCH__ __ARM_ARCH__ # endif # if __ARM_MAX_ARCH__<__ARM_ARCH__ # error "__ARM_MAX_ARCH__ can't be less than __ARM_ARCH__" # elif __ARM_MAX_ARCH__!=__ARM_ARCH__ # if __ARM_ARCH__<7 && __ARM_MAX_ARCH__>=7 && defined(__ARMEB__) # error "can't build universal big-endian binary" # endif # endif # ifndef __ASSEMBLER__ extern unsigned int OPENSSL_armcap_P; extern unsigned int OPENSSL_arm_midr; extern unsigned int OPENSSL_armv8_rsa_neonized; # endif # define ARMV7_NEON (1<<0) # define ARMV7_TICK (1<<1) # define ARMV8_AES (1<<2) # define ARMV8_SHA1 (1<<3) # define ARMV8_SHA256 (1<<4) # define ARMV8_PMULL (1<<5) # define ARMV8_SHA512 (1<<6) # define ARMV8_CPUID (1<<7) /* * MIDR_EL1 system register * * 63___ _ ___32_31___ _ ___24_23_____20_19_____16_15__ _ __4_3_______0 * | | | | | | | * |RES0 | Implementer | Variant | Arch | PartNum |Revision| * |____ _ _____|_____ _ _____|_________|_______ _|____ _ ___|________| * */ # define ARM_CPU_IMP_ARM 0x41 # define ARM_CPU_PART_CORTEX_A72 0xD08 # define ARM_CPU_PART_N1 0xD0C # define MIDR_PARTNUM_SHIFT 4 # define MIDR_PARTNUM_MASK (0xfffU << MIDR_PARTNUM_SHIFT) # define MIDR_PARTNUM(midr) \ (((midr) & MIDR_PARTNUM_MASK) >> MIDR_PARTNUM_SHIFT) # define MIDR_IMPLEMENTER_SHIFT 24 # define MIDR_IMPLEMENTER_MASK (0xffU << MIDR_IMPLEMENTER_SHIFT) # define MIDR_IMPLEMENTER(midr) \ (((midr) & MIDR_IMPLEMENTER_MASK) >> MIDR_IMPLEMENTER_SHIFT) # define MIDR_ARCHITECTURE_SHIFT 16 # define MIDR_ARCHITECTURE_MASK (0xfU << MIDR_ARCHITECTURE_SHIFT) # define MIDR_ARCHITECTURE(midr) \ (((midr) & MIDR_ARCHITECTURE_MASK) >> MIDR_ARCHITECTURE_SHIFT) # define MIDR_CPU_MODEL_MASK \ (MIDR_IMPLEMENTER_MASK | \ MIDR_PARTNUM_MASK | \ MIDR_ARCHITECTURE_MASK) # define MIDR_CPU_MODEL(imp, partnum) \ (((imp) << MIDR_IMPLEMENTER_SHIFT) | \ (0xfU << MIDR_ARCHITECTURE_SHIFT) | \ ((partnum) << MIDR_PARTNUM_SHIFT)) # define MIDR_IS_CPU_MODEL(midr, imp, partnum) \ (((midr) & MIDR_CPU_MODEL_MASK) == MIDR_CPU_MODEL(imp, partnum)) #endif diff --git a/sys/crypto/openssl/aarch64/ghashv8-armx.S b/sys/crypto/openssl/aarch64/ghashv8-armx.S index fe5cd49a25aa..cb7aa9a3908b 100644 --- a/sys/crypto/openssl/aarch64/ghashv8-armx.S +++ b/sys/crypto/openssl/aarch64/ghashv8-armx.S @@ -1,553 +1,553 @@ /* Do not modify. This file is auto-generated from ghashv8-armx.pl. */ #include "arm_arch.h" #if __ARM_MAX_ARCH__>=7 .arch armv8-a+crypto .text .globl gcm_init_v8 .type gcm_init_v8,%function .align 4 gcm_init_v8: ld1 {v17.2d},[x1] //load input H movi v19.16b,#0xe1 shl v19.2d,v19.2d,#57 //0xc2.0 ext v3.16b,v17.16b,v17.16b,#8 ushr v18.2d,v19.2d,#63 dup v17.4s,v17.s[1] ext v16.16b,v18.16b,v19.16b,#8 //t0=0xc2....01 ushr v18.2d,v3.2d,#63 sshr v17.4s,v17.4s,#31 //broadcast carry bit and v18.16b,v18.16b,v16.16b shl v3.2d,v3.2d,#1 ext v18.16b,v18.16b,v18.16b,#8 and v16.16b,v16.16b,v17.16b orr v3.16b,v3.16b,v18.16b //H<<<=1 eor v20.16b,v3.16b,v16.16b //twisted H st1 {v20.2d},[x0],#16 //store Htable[0] //calculate H^2 ext v16.16b,v20.16b,v20.16b,#8 //Karatsuba pre-processing pmull v0.1q,v20.1d,v20.1d eor v16.16b,v16.16b,v20.16b pmull2 v2.1q,v20.2d,v20.2d pmull v1.1q,v16.1d,v16.1d ext v17.16b,v0.16b,v2.16b,#8 //Karatsuba post-processing eor v18.16b,v0.16b,v2.16b eor v1.16b,v1.16b,v17.16b eor v1.16b,v1.16b,v18.16b pmull v18.1q,v0.1d,v19.1d //1st phase ins v2.d[0],v1.d[1] ins v1.d[1],v0.d[0] eor v0.16b,v1.16b,v18.16b ext v18.16b,v0.16b,v0.16b,#8 //2nd phase pmull v0.1q,v0.1d,v19.1d eor v18.16b,v18.16b,v2.16b eor v22.16b,v0.16b,v18.16b ext v17.16b,v22.16b,v22.16b,#8 //Karatsuba pre-processing eor v17.16b,v17.16b,v22.16b ext v21.16b,v16.16b,v17.16b,#8 //pack Karatsuba pre-processed st1 {v21.2d,v22.2d},[x0],#32 //store Htable[1..2] //calculate H^3 and H^4 pmull v0.1q,v20.1d, v22.1d pmull v5.1q,v22.1d,v22.1d pmull2 v2.1q,v20.2d, v22.2d pmull2 v7.1q,v22.2d,v22.2d pmull v1.1q,v16.1d,v17.1d pmull v6.1q,v17.1d,v17.1d ext v16.16b,v0.16b,v2.16b,#8 //Karatsuba post-processing ext v17.16b,v5.16b,v7.16b,#8 eor v18.16b,v0.16b,v2.16b eor v1.16b,v1.16b,v16.16b eor v4.16b,v5.16b,v7.16b eor v6.16b,v6.16b,v17.16b eor v1.16b,v1.16b,v18.16b pmull v18.1q,v0.1d,v19.1d //1st phase eor v6.16b,v6.16b,v4.16b pmull v4.1q,v5.1d,v19.1d ins v2.d[0],v1.d[1] ins v7.d[0],v6.d[1] ins v1.d[1],v0.d[0] ins v6.d[1],v5.d[0] eor v0.16b,v1.16b,v18.16b eor v5.16b,v6.16b,v4.16b ext v18.16b,v0.16b,v0.16b,#8 //2nd phase ext v4.16b,v5.16b,v5.16b,#8 pmull v0.1q,v0.1d,v19.1d pmull v5.1q,v5.1d,v19.1d eor v18.16b,v18.16b,v2.16b eor v4.16b,v4.16b,v7.16b eor v20.16b, v0.16b,v18.16b //H^3 eor v22.16b,v5.16b,v4.16b //H^4 ext v16.16b,v20.16b, v20.16b,#8 //Karatsuba pre-processing ext v17.16b,v22.16b,v22.16b,#8 eor v16.16b,v16.16b,v20.16b eor v17.16b,v17.16b,v22.16b ext v21.16b,v16.16b,v17.16b,#8 //pack Karatsuba pre-processed st1 {v20.2d,v21.2d,v22.2d},[x0] //store Htable[3..5] ret .size gcm_init_v8,.-gcm_init_v8 .globl gcm_gmult_v8 .type gcm_gmult_v8,%function .align 4 gcm_gmult_v8: ld1 {v17.2d},[x0] //load Xi movi v19.16b,#0xe1 ld1 {v20.2d,v21.2d},[x1] //load twisted H, ... shl v19.2d,v19.2d,#57 -#ifndef __ARMEB__ +#ifndef __AARCH64EB__ rev64 v17.16b,v17.16b #endif ext v3.16b,v17.16b,v17.16b,#8 pmull v0.1q,v20.1d,v3.1d //H.lo·Xi.lo eor v17.16b,v17.16b,v3.16b //Karatsuba pre-processing pmull2 v2.1q,v20.2d,v3.2d //H.hi·Xi.hi pmull v1.1q,v21.1d,v17.1d //(H.lo+H.hi)·(Xi.lo+Xi.hi) ext v17.16b,v0.16b,v2.16b,#8 //Karatsuba post-processing eor v18.16b,v0.16b,v2.16b eor v1.16b,v1.16b,v17.16b eor v1.16b,v1.16b,v18.16b pmull v18.1q,v0.1d,v19.1d //1st phase of reduction ins v2.d[0],v1.d[1] ins v1.d[1],v0.d[0] eor v0.16b,v1.16b,v18.16b ext v18.16b,v0.16b,v0.16b,#8 //2nd phase of reduction pmull v0.1q,v0.1d,v19.1d eor v18.16b,v18.16b,v2.16b eor v0.16b,v0.16b,v18.16b -#ifndef __ARMEB__ +#ifndef __AARCH64EB__ rev64 v0.16b,v0.16b #endif ext v0.16b,v0.16b,v0.16b,#8 st1 {v0.2d},[x0] //write out Xi ret .size gcm_gmult_v8,.-gcm_gmult_v8 .globl gcm_ghash_v8 .type gcm_ghash_v8,%function .align 4 gcm_ghash_v8: cmp x3,#64 b.hs .Lgcm_ghash_v8_4x ld1 {v0.2d},[x0] //load [rotated] Xi //"[rotated]" means that //loaded value would have //to be rotated in order to //make it appear as in //algorithm specification subs x3,x3,#32 //see if x3 is 32 or larger mov x12,#16 //x12 is used as post- //increment for input pointer; //as loop is modulo-scheduled //x12 is zeroed just in time //to preclude overstepping //inp[len], which means that //last block[s] are actually //loaded twice, but last //copy is not processed ld1 {v20.2d,v21.2d},[x1],#32 //load twisted H, ..., H^2 movi v19.16b,#0xe1 ld1 {v22.2d},[x1] csel x12,xzr,x12,eq //is it time to zero x12? ext v0.16b,v0.16b,v0.16b,#8 //rotate Xi ld1 {v16.2d},[x2],#16 //load [rotated] I[0] shl v19.2d,v19.2d,#57 //compose 0xc2.0 constant -#ifndef __ARMEB__ +#ifndef __AARCH64EB__ rev64 v16.16b,v16.16b rev64 v0.16b,v0.16b #endif ext v3.16b,v16.16b,v16.16b,#8 //rotate I[0] b.lo .Lodd_tail_v8 //x3 was less than 32 ld1 {v17.2d},[x2],x12 //load [rotated] I[1] -#ifndef __ARMEB__ +#ifndef __AARCH64EB__ rev64 v17.16b,v17.16b #endif ext v7.16b,v17.16b,v17.16b,#8 eor v3.16b,v3.16b,v0.16b //I[i]^=Xi pmull v4.1q,v20.1d,v7.1d //H·Ii+1 eor v17.16b,v17.16b,v7.16b //Karatsuba pre-processing pmull2 v6.1q,v20.2d,v7.2d b .Loop_mod2x_v8 .align 4 .Loop_mod2x_v8: ext v18.16b,v3.16b,v3.16b,#8 subs x3,x3,#32 //is there more data? pmull v0.1q,v22.1d,v3.1d //H^2.lo·Xi.lo csel x12,xzr,x12,lo //is it time to zero x12? pmull v5.1q,v21.1d,v17.1d eor v18.16b,v18.16b,v3.16b //Karatsuba pre-processing pmull2 v2.1q,v22.2d,v3.2d //H^2.hi·Xi.hi eor v0.16b,v0.16b,v4.16b //accumulate pmull2 v1.1q,v21.2d,v18.2d //(H^2.lo+H^2.hi)·(Xi.lo+Xi.hi) ld1 {v16.2d},[x2],x12 //load [rotated] I[i+2] eor v2.16b,v2.16b,v6.16b csel x12,xzr,x12,eq //is it time to zero x12? eor v1.16b,v1.16b,v5.16b ext v17.16b,v0.16b,v2.16b,#8 //Karatsuba post-processing eor v18.16b,v0.16b,v2.16b eor v1.16b,v1.16b,v17.16b ld1 {v17.2d},[x2],x12 //load [rotated] I[i+3] -#ifndef __ARMEB__ +#ifndef __AARCH64EB__ rev64 v16.16b,v16.16b #endif eor v1.16b,v1.16b,v18.16b pmull v18.1q,v0.1d,v19.1d //1st phase of reduction -#ifndef __ARMEB__ +#ifndef __AARCH64EB__ rev64 v17.16b,v17.16b #endif ins v2.d[0],v1.d[1] ins v1.d[1],v0.d[0] ext v7.16b,v17.16b,v17.16b,#8 ext v3.16b,v16.16b,v16.16b,#8 eor v0.16b,v1.16b,v18.16b pmull v4.1q,v20.1d,v7.1d //H·Ii+1 eor v3.16b,v3.16b,v2.16b //accumulate v3.16b early ext v18.16b,v0.16b,v0.16b,#8 //2nd phase of reduction pmull v0.1q,v0.1d,v19.1d eor v3.16b,v3.16b,v18.16b eor v17.16b,v17.16b,v7.16b //Karatsuba pre-processing eor v3.16b,v3.16b,v0.16b pmull2 v6.1q,v20.2d,v7.2d b.hs .Loop_mod2x_v8 //there was at least 32 more bytes eor v2.16b,v2.16b,v18.16b ext v3.16b,v16.16b,v16.16b,#8 //re-construct v3.16b adds x3,x3,#32 //re-construct x3 eor v0.16b,v0.16b,v2.16b //re-construct v0.16b b.eq .Ldone_v8 //is x3 zero? .Lodd_tail_v8: ext v18.16b,v0.16b,v0.16b,#8 eor v3.16b,v3.16b,v0.16b //inp^=Xi eor v17.16b,v16.16b,v18.16b //v17.16b is rotated inp^Xi pmull v0.1q,v20.1d,v3.1d //H.lo·Xi.lo eor v17.16b,v17.16b,v3.16b //Karatsuba pre-processing pmull2 v2.1q,v20.2d,v3.2d //H.hi·Xi.hi pmull v1.1q,v21.1d,v17.1d //(H.lo+H.hi)·(Xi.lo+Xi.hi) ext v17.16b,v0.16b,v2.16b,#8 //Karatsuba post-processing eor v18.16b,v0.16b,v2.16b eor v1.16b,v1.16b,v17.16b eor v1.16b,v1.16b,v18.16b pmull v18.1q,v0.1d,v19.1d //1st phase of reduction ins v2.d[0],v1.d[1] ins v1.d[1],v0.d[0] eor v0.16b,v1.16b,v18.16b ext v18.16b,v0.16b,v0.16b,#8 //2nd phase of reduction pmull v0.1q,v0.1d,v19.1d eor v18.16b,v18.16b,v2.16b eor v0.16b,v0.16b,v18.16b .Ldone_v8: -#ifndef __ARMEB__ +#ifndef __AARCH64EB__ rev64 v0.16b,v0.16b #endif ext v0.16b,v0.16b,v0.16b,#8 st1 {v0.2d},[x0] //write out Xi ret .size gcm_ghash_v8,.-gcm_ghash_v8 .type gcm_ghash_v8_4x,%function .align 4 gcm_ghash_v8_4x: .Lgcm_ghash_v8_4x: ld1 {v0.2d},[x0] //load [rotated] Xi ld1 {v20.2d,v21.2d,v22.2d},[x1],#48 //load twisted H, ..., H^2 movi v19.16b,#0xe1 ld1 {v26.2d,v27.2d,v28.2d},[x1] //load twisted H^3, ..., H^4 shl v19.2d,v19.2d,#57 //compose 0xc2.0 constant ld1 {v4.2d,v5.2d,v6.2d,v7.2d},[x2],#64 -#ifndef __ARMEB__ +#ifndef __AARCH64EB__ rev64 v0.16b,v0.16b rev64 v5.16b,v5.16b rev64 v6.16b,v6.16b rev64 v7.16b,v7.16b rev64 v4.16b,v4.16b #endif ext v25.16b,v7.16b,v7.16b,#8 ext v24.16b,v6.16b,v6.16b,#8 ext v23.16b,v5.16b,v5.16b,#8 pmull v29.1q,v20.1d,v25.1d //H·Ii+3 eor v7.16b,v7.16b,v25.16b pmull2 v31.1q,v20.2d,v25.2d pmull v30.1q,v21.1d,v7.1d pmull v16.1q,v22.1d,v24.1d //H^2·Ii+2 eor v6.16b,v6.16b,v24.16b pmull2 v24.1q,v22.2d,v24.2d pmull2 v6.1q,v21.2d,v6.2d eor v29.16b,v29.16b,v16.16b eor v31.16b,v31.16b,v24.16b eor v30.16b,v30.16b,v6.16b pmull v7.1q,v26.1d,v23.1d //H^3·Ii+1 eor v5.16b,v5.16b,v23.16b pmull2 v23.1q,v26.2d,v23.2d pmull v5.1q,v27.1d,v5.1d eor v29.16b,v29.16b,v7.16b eor v31.16b,v31.16b,v23.16b eor v30.16b,v30.16b,v5.16b subs x3,x3,#128 b.lo .Ltail4x b .Loop4x .align 4 .Loop4x: eor v16.16b,v4.16b,v0.16b ld1 {v4.2d,v5.2d,v6.2d,v7.2d},[x2],#64 ext v3.16b,v16.16b,v16.16b,#8 -#ifndef __ARMEB__ +#ifndef __AARCH64EB__ rev64 v5.16b,v5.16b rev64 v6.16b,v6.16b rev64 v7.16b,v7.16b rev64 v4.16b,v4.16b #endif pmull v0.1q,v28.1d,v3.1d //H^4·(Xi+Ii) eor v16.16b,v16.16b,v3.16b pmull2 v2.1q,v28.2d,v3.2d ext v25.16b,v7.16b,v7.16b,#8 pmull2 v1.1q,v27.2d,v16.2d eor v0.16b,v0.16b,v29.16b eor v2.16b,v2.16b,v31.16b ext v24.16b,v6.16b,v6.16b,#8 eor v1.16b,v1.16b,v30.16b ext v23.16b,v5.16b,v5.16b,#8 ext v17.16b,v0.16b,v2.16b,#8 //Karatsuba post-processing eor v18.16b,v0.16b,v2.16b pmull v29.1q,v20.1d,v25.1d //H·Ii+3 eor v7.16b,v7.16b,v25.16b eor v1.16b,v1.16b,v17.16b pmull2 v31.1q,v20.2d,v25.2d eor v1.16b,v1.16b,v18.16b pmull v30.1q,v21.1d,v7.1d pmull v18.1q,v0.1d,v19.1d //1st phase of reduction ins v2.d[0],v1.d[1] ins v1.d[1],v0.d[0] pmull v16.1q,v22.1d,v24.1d //H^2·Ii+2 eor v6.16b,v6.16b,v24.16b pmull2 v24.1q,v22.2d,v24.2d eor v0.16b,v1.16b,v18.16b pmull2 v6.1q,v21.2d,v6.2d eor v29.16b,v29.16b,v16.16b eor v31.16b,v31.16b,v24.16b eor v30.16b,v30.16b,v6.16b ext v18.16b,v0.16b,v0.16b,#8 //2nd phase of reduction pmull v0.1q,v0.1d,v19.1d pmull v7.1q,v26.1d,v23.1d //H^3·Ii+1 eor v5.16b,v5.16b,v23.16b eor v18.16b,v18.16b,v2.16b pmull2 v23.1q,v26.2d,v23.2d pmull v5.1q,v27.1d,v5.1d eor v0.16b,v0.16b,v18.16b eor v29.16b,v29.16b,v7.16b eor v31.16b,v31.16b,v23.16b ext v0.16b,v0.16b,v0.16b,#8 eor v30.16b,v30.16b,v5.16b subs x3,x3,#64 b.hs .Loop4x .Ltail4x: eor v16.16b,v4.16b,v0.16b ext v3.16b,v16.16b,v16.16b,#8 pmull v0.1q,v28.1d,v3.1d //H^4·(Xi+Ii) eor v16.16b,v16.16b,v3.16b pmull2 v2.1q,v28.2d,v3.2d pmull2 v1.1q,v27.2d,v16.2d eor v0.16b,v0.16b,v29.16b eor v2.16b,v2.16b,v31.16b eor v1.16b,v1.16b,v30.16b adds x3,x3,#64 b.eq .Ldone4x cmp x3,#32 b.lo .Lone b.eq .Ltwo .Lthree: ext v17.16b,v0.16b,v2.16b,#8 //Karatsuba post-processing eor v18.16b,v0.16b,v2.16b eor v1.16b,v1.16b,v17.16b ld1 {v4.2d,v5.2d,v6.2d},[x2] eor v1.16b,v1.16b,v18.16b -#ifndef __ARMEB__ +#ifndef __AARCH64EB__ rev64 v5.16b,v5.16b rev64 v6.16b,v6.16b rev64 v4.16b,v4.16b #endif pmull v18.1q,v0.1d,v19.1d //1st phase of reduction ins v2.d[0],v1.d[1] ins v1.d[1],v0.d[0] ext v24.16b,v6.16b,v6.16b,#8 ext v23.16b,v5.16b,v5.16b,#8 eor v0.16b,v1.16b,v18.16b pmull v29.1q,v20.1d,v24.1d //H·Ii+2 eor v6.16b,v6.16b,v24.16b ext v18.16b,v0.16b,v0.16b,#8 //2nd phase of reduction pmull v0.1q,v0.1d,v19.1d eor v18.16b,v18.16b,v2.16b pmull2 v31.1q,v20.2d,v24.2d pmull v30.1q,v21.1d,v6.1d eor v0.16b,v0.16b,v18.16b pmull v7.1q,v22.1d,v23.1d //H^2·Ii+1 eor v5.16b,v5.16b,v23.16b ext v0.16b,v0.16b,v0.16b,#8 pmull2 v23.1q,v22.2d,v23.2d eor v16.16b,v4.16b,v0.16b pmull2 v5.1q,v21.2d,v5.2d ext v3.16b,v16.16b,v16.16b,#8 eor v29.16b,v29.16b,v7.16b eor v31.16b,v31.16b,v23.16b eor v30.16b,v30.16b,v5.16b pmull v0.1q,v26.1d,v3.1d //H^3·(Xi+Ii) eor v16.16b,v16.16b,v3.16b pmull2 v2.1q,v26.2d,v3.2d pmull v1.1q,v27.1d,v16.1d eor v0.16b,v0.16b,v29.16b eor v2.16b,v2.16b,v31.16b eor v1.16b,v1.16b,v30.16b b .Ldone4x .align 4 .Ltwo: ext v17.16b,v0.16b,v2.16b,#8 //Karatsuba post-processing eor v18.16b,v0.16b,v2.16b eor v1.16b,v1.16b,v17.16b ld1 {v4.2d,v5.2d},[x2] eor v1.16b,v1.16b,v18.16b -#ifndef __ARMEB__ +#ifndef __AARCH64EB__ rev64 v5.16b,v5.16b rev64 v4.16b,v4.16b #endif pmull v18.1q,v0.1d,v19.1d //1st phase of reduction ins v2.d[0],v1.d[1] ins v1.d[1],v0.d[0] ext v23.16b,v5.16b,v5.16b,#8 eor v0.16b,v1.16b,v18.16b ext v18.16b,v0.16b,v0.16b,#8 //2nd phase of reduction pmull v0.1q,v0.1d,v19.1d eor v18.16b,v18.16b,v2.16b eor v0.16b,v0.16b,v18.16b ext v0.16b,v0.16b,v0.16b,#8 pmull v29.1q,v20.1d,v23.1d //H·Ii+1 eor v5.16b,v5.16b,v23.16b eor v16.16b,v4.16b,v0.16b ext v3.16b,v16.16b,v16.16b,#8 pmull2 v31.1q,v20.2d,v23.2d pmull v30.1q,v21.1d,v5.1d pmull v0.1q,v22.1d,v3.1d //H^2·(Xi+Ii) eor v16.16b,v16.16b,v3.16b pmull2 v2.1q,v22.2d,v3.2d pmull2 v1.1q,v21.2d,v16.2d eor v0.16b,v0.16b,v29.16b eor v2.16b,v2.16b,v31.16b eor v1.16b,v1.16b,v30.16b b .Ldone4x .align 4 .Lone: ext v17.16b,v0.16b,v2.16b,#8 //Karatsuba post-processing eor v18.16b,v0.16b,v2.16b eor v1.16b,v1.16b,v17.16b ld1 {v4.2d},[x2] eor v1.16b,v1.16b,v18.16b -#ifndef __ARMEB__ +#ifndef __AARCH64EB__ rev64 v4.16b,v4.16b #endif pmull v18.1q,v0.1d,v19.1d //1st phase of reduction ins v2.d[0],v1.d[1] ins v1.d[1],v0.d[0] eor v0.16b,v1.16b,v18.16b ext v18.16b,v0.16b,v0.16b,#8 //2nd phase of reduction pmull v0.1q,v0.1d,v19.1d eor v18.16b,v18.16b,v2.16b eor v0.16b,v0.16b,v18.16b ext v0.16b,v0.16b,v0.16b,#8 eor v16.16b,v4.16b,v0.16b ext v3.16b,v16.16b,v16.16b,#8 pmull v0.1q,v20.1d,v3.1d eor v16.16b,v16.16b,v3.16b pmull2 v2.1q,v20.2d,v3.2d pmull v1.1q,v21.1d,v16.1d .Ldone4x: ext v17.16b,v0.16b,v2.16b,#8 //Karatsuba post-processing eor v18.16b,v0.16b,v2.16b eor v1.16b,v1.16b,v17.16b eor v1.16b,v1.16b,v18.16b pmull v18.1q,v0.1d,v19.1d //1st phase of reduction ins v2.d[0],v1.d[1] ins v1.d[1],v0.d[0] eor v0.16b,v1.16b,v18.16b ext v18.16b,v0.16b,v0.16b,#8 //2nd phase of reduction pmull v0.1q,v0.1d,v19.1d eor v18.16b,v18.16b,v2.16b eor v0.16b,v0.16b,v18.16b ext v0.16b,v0.16b,v0.16b,#8 -#ifndef __ARMEB__ +#ifndef __AARCH64EB__ rev64 v0.16b,v0.16b #endif st1 {v0.2d},[x0] //write out Xi ret .size gcm_ghash_v8_4x,.-gcm_ghash_v8_4x .byte 71,72,65,83,72,32,102,111,114,32,65,82,77,118,56,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0 .align 2 .align 2 #endif diff --git a/sys/crypto/openssl/aarch64/poly1305-armv8.S b/sys/crypto/openssl/aarch64/poly1305-armv8.S index 101e4fb40552..bf1daa3adaff 100644 --- a/sys/crypto/openssl/aarch64/poly1305-armv8.S +++ b/sys/crypto/openssl/aarch64/poly1305-armv8.S @@ -1,864 +1,864 @@ /* Do not modify. This file is auto-generated from poly1305-armv8.pl. */ #include "arm_arch.h" .text // forward "declarations" are required for Apple .hidden OPENSSL_armcap_P .globl poly1305_init .hidden poly1305_init .globl poly1305_blocks .hidden poly1305_blocks .globl poly1305_emit .hidden poly1305_emit .type poly1305_init,%function .align 5 poly1305_init: cmp x1,xzr stp xzr,xzr,[x0] // zero hash value stp xzr,xzr,[x0,#16] // [along with is_base2_26] csel x0,xzr,x0,eq b.eq .Lno_key adrp x17,OPENSSL_armcap_P ldr w17,[x17,#:lo12:OPENSSL_armcap_P] ldp x7,x8,[x1] // load key mov x9,#0xfffffffc0fffffff movk x9,#0x0fff,lsl#48 -#ifdef __ARMEB__ +#ifdef __AARCH64EB__ rev x7,x7 // flip bytes rev x8,x8 #endif and x7,x7,x9 // &=0ffffffc0fffffff and x9,x9,#-4 and x8,x8,x9 // &=0ffffffc0ffffffc stp x7,x8,[x0,#32] // save key value tst w17,#ARMV7_NEON adr x12,.Lpoly1305_blocks adr x7,.Lpoly1305_blocks_neon adr x13,.Lpoly1305_emit adr x8,.Lpoly1305_emit_neon csel x12,x12,x7,eq csel x13,x13,x8,eq #ifdef __ILP32__ stp w12,w13,[x2] #else stp x12,x13,[x2] #endif mov x0,#1 .Lno_key: ret .size poly1305_init,.-poly1305_init .type poly1305_blocks,%function .align 5 poly1305_blocks: .Lpoly1305_blocks: ands x2,x2,#-16 b.eq .Lno_data ldp x4,x5,[x0] // load hash value ldp x7,x8,[x0,#32] // load key value ldr x6,[x0,#16] add x9,x8,x8,lsr#2 // s1 = r1 + (r1 >> 2) b .Loop .align 5 .Loop: ldp x10,x11,[x1],#16 // load input sub x2,x2,#16 -#ifdef __ARMEB__ +#ifdef __AARCH64EB__ rev x10,x10 rev x11,x11 #endif adds x4,x4,x10 // accumulate input adcs x5,x5,x11 mul x12,x4,x7 // h0*r0 adc x6,x6,x3 umulh x13,x4,x7 mul x10,x5,x9 // h1*5*r1 umulh x11,x5,x9 adds x12,x12,x10 mul x10,x4,x8 // h0*r1 adc x13,x13,x11 umulh x14,x4,x8 adds x13,x13,x10 mul x10,x5,x7 // h1*r0 adc x14,x14,xzr umulh x11,x5,x7 adds x13,x13,x10 mul x10,x6,x9 // h2*5*r1 adc x14,x14,x11 mul x11,x6,x7 // h2*r0 adds x13,x13,x10 adc x14,x14,x11 and x10,x14,#-4 // final reduction and x6,x14,#3 add x10,x10,x14,lsr#2 adds x4,x12,x10 adcs x5,x13,xzr adc x6,x6,xzr cbnz x2,.Loop stp x4,x5,[x0] // store hash value str x6,[x0,#16] .Lno_data: ret .size poly1305_blocks,.-poly1305_blocks .type poly1305_emit,%function .align 5 poly1305_emit: .Lpoly1305_emit: ldp x4,x5,[x0] // load hash base 2^64 ldr x6,[x0,#16] ldp x10,x11,[x2] // load nonce adds x12,x4,#5 // compare to modulus adcs x13,x5,xzr adc x14,x6,xzr tst x14,#-4 // see if it's carried/borrowed csel x4,x4,x12,eq csel x5,x5,x13,eq -#ifdef __ARMEB__ +#ifdef __AARCH64EB__ ror x10,x10,#32 // flip nonce words ror x11,x11,#32 #endif adds x4,x4,x10 // accumulate nonce adc x5,x5,x11 -#ifdef __ARMEB__ +#ifdef __AARCH64EB__ rev x4,x4 // flip output bytes rev x5,x5 #endif stp x4,x5,[x1] // write result ret .size poly1305_emit,.-poly1305_emit .type poly1305_mult,%function .align 5 poly1305_mult: mul x12,x4,x7 // h0*r0 umulh x13,x4,x7 mul x10,x5,x9 // h1*5*r1 umulh x11,x5,x9 adds x12,x12,x10 mul x10,x4,x8 // h0*r1 adc x13,x13,x11 umulh x14,x4,x8 adds x13,x13,x10 mul x10,x5,x7 // h1*r0 adc x14,x14,xzr umulh x11,x5,x7 adds x13,x13,x10 mul x10,x6,x9 // h2*5*r1 adc x14,x14,x11 mul x11,x6,x7 // h2*r0 adds x13,x13,x10 adc x14,x14,x11 and x10,x14,#-4 // final reduction and x6,x14,#3 add x10,x10,x14,lsr#2 adds x4,x12,x10 adcs x5,x13,xzr adc x6,x6,xzr ret .size poly1305_mult,.-poly1305_mult .type poly1305_splat,%function .align 5 poly1305_splat: and x12,x4,#0x03ffffff // base 2^64 -> base 2^26 ubfx x13,x4,#26,#26 extr x14,x5,x4,#52 and x14,x14,#0x03ffffff ubfx x15,x5,#14,#26 extr x16,x6,x5,#40 str w12,[x0,#16*0] // r0 add w12,w13,w13,lsl#2 // r1*5 str w13,[x0,#16*1] // r1 add w13,w14,w14,lsl#2 // r2*5 str w12,[x0,#16*2] // s1 str w14,[x0,#16*3] // r2 add w14,w15,w15,lsl#2 // r3*5 str w13,[x0,#16*4] // s2 str w15,[x0,#16*5] // r3 add w15,w16,w16,lsl#2 // r4*5 str w14,[x0,#16*6] // s3 str w16,[x0,#16*7] // r4 str w15,[x0,#16*8] // s4 ret .size poly1305_splat,.-poly1305_splat .type poly1305_blocks_neon,%function .align 5 poly1305_blocks_neon: .Lpoly1305_blocks_neon: ldr x17,[x0,#24] cmp x2,#128 b.hs .Lblocks_neon cbz x17,.Lpoly1305_blocks .Lblocks_neon: .inst 0xd503233f // paciasp stp x29,x30,[sp,#-80]! add x29,sp,#0 ands x2,x2,#-16 b.eq .Lno_data_neon cbz x17,.Lbase2_64_neon ldp w10,w11,[x0] // load hash value base 2^26 ldp w12,w13,[x0,#8] ldr w14,[x0,#16] tst x2,#31 b.eq .Leven_neon ldp x7,x8,[x0,#32] // load key value add x4,x10,x11,lsl#26 // base 2^26 -> base 2^64 lsr x5,x12,#12 adds x4,x4,x12,lsl#52 add x5,x5,x13,lsl#14 adc x5,x5,xzr lsr x6,x14,#24 adds x5,x5,x14,lsl#40 adc x14,x6,xzr // can be partially reduced... ldp x12,x13,[x1],#16 // load input sub x2,x2,#16 add x9,x8,x8,lsr#2 // s1 = r1 + (r1 >> 2) and x10,x14,#-4 // ... so reduce and x6,x14,#3 add x10,x10,x14,lsr#2 adds x4,x4,x10 adcs x5,x5,xzr adc x6,x6,xzr -#ifdef __ARMEB__ +#ifdef __AARCH64EB__ rev x12,x12 rev x13,x13 #endif adds x4,x4,x12 // accumulate input adcs x5,x5,x13 adc x6,x6,x3 bl poly1305_mult ldr x30,[sp,#8] cbz x3,.Lstore_base2_64_neon and x10,x4,#0x03ffffff // base 2^64 -> base 2^26 ubfx x11,x4,#26,#26 extr x12,x5,x4,#52 and x12,x12,#0x03ffffff ubfx x13,x5,#14,#26 extr x14,x6,x5,#40 cbnz x2,.Leven_neon stp w10,w11,[x0] // store hash value base 2^26 stp w12,w13,[x0,#8] str w14,[x0,#16] b .Lno_data_neon .align 4 .Lstore_base2_64_neon: stp x4,x5,[x0] // store hash value base 2^64 stp x6,xzr,[x0,#16] // note that is_base2_26 is zeroed b .Lno_data_neon .align 4 .Lbase2_64_neon: ldp x7,x8,[x0,#32] // load key value ldp x4,x5,[x0] // load hash value base 2^64 ldr x6,[x0,#16] tst x2,#31 b.eq .Linit_neon ldp x12,x13,[x1],#16 // load input sub x2,x2,#16 add x9,x8,x8,lsr#2 // s1 = r1 + (r1 >> 2) -#ifdef __ARMEB__ +#ifdef __AARCH64EB__ rev x12,x12 rev x13,x13 #endif adds x4,x4,x12 // accumulate input adcs x5,x5,x13 adc x6,x6,x3 bl poly1305_mult .Linit_neon: and x10,x4,#0x03ffffff // base 2^64 -> base 2^26 ubfx x11,x4,#26,#26 extr x12,x5,x4,#52 and x12,x12,#0x03ffffff ubfx x13,x5,#14,#26 extr x14,x6,x5,#40 stp d8,d9,[sp,#16] // meet ABI requirements stp d10,d11,[sp,#32] stp d12,d13,[sp,#48] stp d14,d15,[sp,#64] fmov d24,x10 fmov d25,x11 fmov d26,x12 fmov d27,x13 fmov d28,x14 ////////////////////////////////// initialize r^n table mov x4,x7 // r^1 add x9,x8,x8,lsr#2 // s1 = r1 + (r1 >> 2) mov x5,x8 mov x6,xzr add x0,x0,#48+12 bl poly1305_splat bl poly1305_mult // r^2 sub x0,x0,#4 bl poly1305_splat bl poly1305_mult // r^3 sub x0,x0,#4 bl poly1305_splat bl poly1305_mult // r^4 sub x0,x0,#4 bl poly1305_splat ldr x30,[sp,#8] add x16,x1,#32 adr x17,.Lzeros subs x2,x2,#64 csel x16,x17,x16,lo mov x4,#1 stur x4,[x0,#-24] // set is_base2_26 sub x0,x0,#48 // restore original x0 b .Ldo_neon .align 4 .Leven_neon: add x16,x1,#32 adr x17,.Lzeros subs x2,x2,#64 csel x16,x17,x16,lo stp d8,d9,[sp,#16] // meet ABI requirements stp d10,d11,[sp,#32] stp d12,d13,[sp,#48] stp d14,d15,[sp,#64] fmov d24,x10 fmov d25,x11 fmov d26,x12 fmov d27,x13 fmov d28,x14 .Ldo_neon: ldp x8,x12,[x16],#16 // inp[2:3] (or zero) ldp x9,x13,[x16],#48 lsl x3,x3,#24 add x15,x0,#48 -#ifdef __ARMEB__ +#ifdef __AARCH64EB__ rev x8,x8 rev x12,x12 rev x9,x9 rev x13,x13 #endif and x4,x8,#0x03ffffff // base 2^64 -> base 2^26 and x5,x9,#0x03ffffff ubfx x6,x8,#26,#26 ubfx x7,x9,#26,#26 add x4,x4,x5,lsl#32 // bfi x4,x5,#32,#32 extr x8,x12,x8,#52 extr x9,x13,x9,#52 add x6,x6,x7,lsl#32 // bfi x6,x7,#32,#32 fmov d14,x4 and x8,x8,#0x03ffffff and x9,x9,#0x03ffffff ubfx x10,x12,#14,#26 ubfx x11,x13,#14,#26 add x12,x3,x12,lsr#40 add x13,x3,x13,lsr#40 add x8,x8,x9,lsl#32 // bfi x8,x9,#32,#32 fmov d15,x6 add x10,x10,x11,lsl#32 // bfi x10,x11,#32,#32 add x12,x12,x13,lsl#32 // bfi x12,x13,#32,#32 fmov d16,x8 fmov d17,x10 fmov d18,x12 ldp x8,x12,[x1],#16 // inp[0:1] ldp x9,x13,[x1],#48 ld1 {v0.4s,v1.4s,v2.4s,v3.4s},[x15],#64 ld1 {v4.4s,v5.4s,v6.4s,v7.4s},[x15],#64 ld1 {v8.4s},[x15] -#ifdef __ARMEB__ +#ifdef __AARCH64EB__ rev x8,x8 rev x12,x12 rev x9,x9 rev x13,x13 #endif and x4,x8,#0x03ffffff // base 2^64 -> base 2^26 and x5,x9,#0x03ffffff ubfx x6,x8,#26,#26 ubfx x7,x9,#26,#26 add x4,x4,x5,lsl#32 // bfi x4,x5,#32,#32 extr x8,x12,x8,#52 extr x9,x13,x9,#52 add x6,x6,x7,lsl#32 // bfi x6,x7,#32,#32 fmov d9,x4 and x8,x8,#0x03ffffff and x9,x9,#0x03ffffff ubfx x10,x12,#14,#26 ubfx x11,x13,#14,#26 add x12,x3,x12,lsr#40 add x13,x3,x13,lsr#40 add x8,x8,x9,lsl#32 // bfi x8,x9,#32,#32 fmov d10,x6 add x10,x10,x11,lsl#32 // bfi x10,x11,#32,#32 add x12,x12,x13,lsl#32 // bfi x12,x13,#32,#32 movi v31.2d,#-1 fmov d11,x8 fmov d12,x10 fmov d13,x12 ushr v31.2d,v31.2d,#38 b.ls .Lskip_loop .align 4 .Loop_neon: //////////////////////////////////////////////////////////////// // ((inp[0]*r^4+inp[2]*r^2+inp[4])*r^4+inp[6]*r^2 // ((inp[1]*r^4+inp[3]*r^2+inp[5])*r^3+inp[7]*r // ___________________/ // ((inp[0]*r^4+inp[2]*r^2+inp[4])*r^4+inp[6]*r^2+inp[8])*r^2 // ((inp[1]*r^4+inp[3]*r^2+inp[5])*r^4+inp[7]*r^2+inp[9])*r // ___________________/ ____________________/ // // Note that we start with inp[2:3]*r^2. This is because it // doesn't depend on reduction in previous iteration. //////////////////////////////////////////////////////////////// // d4 = h0*r4 + h1*r3 + h2*r2 + h3*r1 + h4*r0 // d3 = h0*r3 + h1*r2 + h2*r1 + h3*r0 + h4*5*r4 // d2 = h0*r2 + h1*r1 + h2*r0 + h3*5*r4 + h4*5*r3 // d1 = h0*r1 + h1*r0 + h2*5*r4 + h3*5*r3 + h4*5*r2 // d0 = h0*r0 + h1*5*r4 + h2*5*r3 + h3*5*r2 + h4*5*r1 subs x2,x2,#64 umull v23.2d,v14.2s,v7.s[2] csel x16,x17,x16,lo umull v22.2d,v14.2s,v5.s[2] umull v21.2d,v14.2s,v3.s[2] ldp x8,x12,[x16],#16 // inp[2:3] (or zero) umull v20.2d,v14.2s,v1.s[2] ldp x9,x13,[x16],#48 umull v19.2d,v14.2s,v0.s[2] -#ifdef __ARMEB__ +#ifdef __AARCH64EB__ rev x8,x8 rev x12,x12 rev x9,x9 rev x13,x13 #endif umlal v23.2d,v15.2s,v5.s[2] and x4,x8,#0x03ffffff // base 2^64 -> base 2^26 umlal v22.2d,v15.2s,v3.s[2] and x5,x9,#0x03ffffff umlal v21.2d,v15.2s,v1.s[2] ubfx x6,x8,#26,#26 umlal v20.2d,v15.2s,v0.s[2] ubfx x7,x9,#26,#26 umlal v19.2d,v15.2s,v8.s[2] add x4,x4,x5,lsl#32 // bfi x4,x5,#32,#32 umlal v23.2d,v16.2s,v3.s[2] extr x8,x12,x8,#52 umlal v22.2d,v16.2s,v1.s[2] extr x9,x13,x9,#52 umlal v21.2d,v16.2s,v0.s[2] add x6,x6,x7,lsl#32 // bfi x6,x7,#32,#32 umlal v20.2d,v16.2s,v8.s[2] fmov d14,x4 umlal v19.2d,v16.2s,v6.s[2] and x8,x8,#0x03ffffff umlal v23.2d,v17.2s,v1.s[2] and x9,x9,#0x03ffffff umlal v22.2d,v17.2s,v0.s[2] ubfx x10,x12,#14,#26 umlal v21.2d,v17.2s,v8.s[2] ubfx x11,x13,#14,#26 umlal v20.2d,v17.2s,v6.s[2] add x8,x8,x9,lsl#32 // bfi x8,x9,#32,#32 umlal v19.2d,v17.2s,v4.s[2] fmov d15,x6 add v11.2s,v11.2s,v26.2s add x12,x3,x12,lsr#40 umlal v23.2d,v18.2s,v0.s[2] add x13,x3,x13,lsr#40 umlal v22.2d,v18.2s,v8.s[2] add x10,x10,x11,lsl#32 // bfi x10,x11,#32,#32 umlal v21.2d,v18.2s,v6.s[2] add x12,x12,x13,lsl#32 // bfi x12,x13,#32,#32 umlal v20.2d,v18.2s,v4.s[2] fmov d16,x8 umlal v19.2d,v18.2s,v2.s[2] fmov d17,x10 //////////////////////////////////////////////////////////////// // (hash+inp[0:1])*r^4 and accumulate add v9.2s,v9.2s,v24.2s fmov d18,x12 umlal v22.2d,v11.2s,v1.s[0] ldp x8,x12,[x1],#16 // inp[0:1] umlal v19.2d,v11.2s,v6.s[0] ldp x9,x13,[x1],#48 umlal v23.2d,v11.2s,v3.s[0] umlal v20.2d,v11.2s,v8.s[0] umlal v21.2d,v11.2s,v0.s[0] -#ifdef __ARMEB__ +#ifdef __AARCH64EB__ rev x8,x8 rev x12,x12 rev x9,x9 rev x13,x13 #endif add v10.2s,v10.2s,v25.2s umlal v22.2d,v9.2s,v5.s[0] umlal v23.2d,v9.2s,v7.s[0] and x4,x8,#0x03ffffff // base 2^64 -> base 2^26 umlal v21.2d,v9.2s,v3.s[0] and x5,x9,#0x03ffffff umlal v19.2d,v9.2s,v0.s[0] ubfx x6,x8,#26,#26 umlal v20.2d,v9.2s,v1.s[0] ubfx x7,x9,#26,#26 add v12.2s,v12.2s,v27.2s add x4,x4,x5,lsl#32 // bfi x4,x5,#32,#32 umlal v22.2d,v10.2s,v3.s[0] extr x8,x12,x8,#52 umlal v23.2d,v10.2s,v5.s[0] extr x9,x13,x9,#52 umlal v19.2d,v10.2s,v8.s[0] add x6,x6,x7,lsl#32 // bfi x6,x7,#32,#32 umlal v21.2d,v10.2s,v1.s[0] fmov d9,x4 umlal v20.2d,v10.2s,v0.s[0] and x8,x8,#0x03ffffff add v13.2s,v13.2s,v28.2s and x9,x9,#0x03ffffff umlal v22.2d,v12.2s,v0.s[0] ubfx x10,x12,#14,#26 umlal v19.2d,v12.2s,v4.s[0] ubfx x11,x13,#14,#26 umlal v23.2d,v12.2s,v1.s[0] add x8,x8,x9,lsl#32 // bfi x8,x9,#32,#32 umlal v20.2d,v12.2s,v6.s[0] fmov d10,x6 umlal v21.2d,v12.2s,v8.s[0] add x12,x3,x12,lsr#40 umlal v22.2d,v13.2s,v8.s[0] add x13,x3,x13,lsr#40 umlal v19.2d,v13.2s,v2.s[0] add x10,x10,x11,lsl#32 // bfi x10,x11,#32,#32 umlal v23.2d,v13.2s,v0.s[0] add x12,x12,x13,lsl#32 // bfi x12,x13,#32,#32 umlal v20.2d,v13.2s,v4.s[0] fmov d11,x8 umlal v21.2d,v13.2s,v6.s[0] fmov d12,x10 fmov d13,x12 ///////////////////////////////////////////////////////////////// // lazy reduction as discussed in "NEON crypto" by D.J. Bernstein // and P. Schwabe // // [see discussion in poly1305-armv4 module] ushr v29.2d,v22.2d,#26 xtn v27.2s,v22.2d ushr v30.2d,v19.2d,#26 and v19.16b,v19.16b,v31.16b add v23.2d,v23.2d,v29.2d // h3 -> h4 bic v27.2s,#0xfc,lsl#24 // &=0x03ffffff add v20.2d,v20.2d,v30.2d // h0 -> h1 ushr v29.2d,v23.2d,#26 xtn v28.2s,v23.2d ushr v30.2d,v20.2d,#26 xtn v25.2s,v20.2d bic v28.2s,#0xfc,lsl#24 add v21.2d,v21.2d,v30.2d // h1 -> h2 add v19.2d,v19.2d,v29.2d shl v29.2d,v29.2d,#2 shrn v30.2s,v21.2d,#26 xtn v26.2s,v21.2d add v19.2d,v19.2d,v29.2d // h4 -> h0 bic v25.2s,#0xfc,lsl#24 add v27.2s,v27.2s,v30.2s // h2 -> h3 bic v26.2s,#0xfc,lsl#24 shrn v29.2s,v19.2d,#26 xtn v24.2s,v19.2d ushr v30.2s,v27.2s,#26 bic v27.2s,#0xfc,lsl#24 bic v24.2s,#0xfc,lsl#24 add v25.2s,v25.2s,v29.2s // h0 -> h1 add v28.2s,v28.2s,v30.2s // h3 -> h4 b.hi .Loop_neon .Lskip_loop: dup v16.2d,v16.d[0] add v11.2s,v11.2s,v26.2s //////////////////////////////////////////////////////////////// // multiply (inp[0:1]+hash) or inp[2:3] by r^2:r^1 adds x2,x2,#32 b.ne .Long_tail dup v16.2d,v11.d[0] add v14.2s,v9.2s,v24.2s add v17.2s,v12.2s,v27.2s add v15.2s,v10.2s,v25.2s add v18.2s,v13.2s,v28.2s .Long_tail: dup v14.2d,v14.d[0] umull2 v19.2d,v16.4s,v6.4s umull2 v22.2d,v16.4s,v1.4s umull2 v23.2d,v16.4s,v3.4s umull2 v21.2d,v16.4s,v0.4s umull2 v20.2d,v16.4s,v8.4s dup v15.2d,v15.d[0] umlal2 v19.2d,v14.4s,v0.4s umlal2 v21.2d,v14.4s,v3.4s umlal2 v22.2d,v14.4s,v5.4s umlal2 v23.2d,v14.4s,v7.4s umlal2 v20.2d,v14.4s,v1.4s dup v17.2d,v17.d[0] umlal2 v19.2d,v15.4s,v8.4s umlal2 v22.2d,v15.4s,v3.4s umlal2 v21.2d,v15.4s,v1.4s umlal2 v23.2d,v15.4s,v5.4s umlal2 v20.2d,v15.4s,v0.4s dup v18.2d,v18.d[0] umlal2 v22.2d,v17.4s,v0.4s umlal2 v23.2d,v17.4s,v1.4s umlal2 v19.2d,v17.4s,v4.4s umlal2 v20.2d,v17.4s,v6.4s umlal2 v21.2d,v17.4s,v8.4s umlal2 v22.2d,v18.4s,v8.4s umlal2 v19.2d,v18.4s,v2.4s umlal2 v23.2d,v18.4s,v0.4s umlal2 v20.2d,v18.4s,v4.4s umlal2 v21.2d,v18.4s,v6.4s b.eq .Lshort_tail //////////////////////////////////////////////////////////////// // (hash+inp[0:1])*r^4:r^3 and accumulate add v9.2s,v9.2s,v24.2s umlal v22.2d,v11.2s,v1.2s umlal v19.2d,v11.2s,v6.2s umlal v23.2d,v11.2s,v3.2s umlal v20.2d,v11.2s,v8.2s umlal v21.2d,v11.2s,v0.2s add v10.2s,v10.2s,v25.2s umlal v22.2d,v9.2s,v5.2s umlal v19.2d,v9.2s,v0.2s umlal v23.2d,v9.2s,v7.2s umlal v20.2d,v9.2s,v1.2s umlal v21.2d,v9.2s,v3.2s add v12.2s,v12.2s,v27.2s umlal v22.2d,v10.2s,v3.2s umlal v19.2d,v10.2s,v8.2s umlal v23.2d,v10.2s,v5.2s umlal v20.2d,v10.2s,v0.2s umlal v21.2d,v10.2s,v1.2s add v13.2s,v13.2s,v28.2s umlal v22.2d,v12.2s,v0.2s umlal v19.2d,v12.2s,v4.2s umlal v23.2d,v12.2s,v1.2s umlal v20.2d,v12.2s,v6.2s umlal v21.2d,v12.2s,v8.2s umlal v22.2d,v13.2s,v8.2s umlal v19.2d,v13.2s,v2.2s umlal v23.2d,v13.2s,v0.2s umlal v20.2d,v13.2s,v4.2s umlal v21.2d,v13.2s,v6.2s .Lshort_tail: //////////////////////////////////////////////////////////////// // horizontal add addp v22.2d,v22.2d,v22.2d ldp d8,d9,[sp,#16] // meet ABI requirements addp v19.2d,v19.2d,v19.2d ldp d10,d11,[sp,#32] addp v23.2d,v23.2d,v23.2d ldp d12,d13,[sp,#48] addp v20.2d,v20.2d,v20.2d ldp d14,d15,[sp,#64] addp v21.2d,v21.2d,v21.2d //////////////////////////////////////////////////////////////// // lazy reduction, but without narrowing ushr v29.2d,v22.2d,#26 and v22.16b,v22.16b,v31.16b ushr v30.2d,v19.2d,#26 and v19.16b,v19.16b,v31.16b add v23.2d,v23.2d,v29.2d // h3 -> h4 add v20.2d,v20.2d,v30.2d // h0 -> h1 ushr v29.2d,v23.2d,#26 and v23.16b,v23.16b,v31.16b ushr v30.2d,v20.2d,#26 and v20.16b,v20.16b,v31.16b add v21.2d,v21.2d,v30.2d // h1 -> h2 add v19.2d,v19.2d,v29.2d shl v29.2d,v29.2d,#2 ushr v30.2d,v21.2d,#26 and v21.16b,v21.16b,v31.16b add v19.2d,v19.2d,v29.2d // h4 -> h0 add v22.2d,v22.2d,v30.2d // h2 -> h3 ushr v29.2d,v19.2d,#26 and v19.16b,v19.16b,v31.16b ushr v30.2d,v22.2d,#26 and v22.16b,v22.16b,v31.16b add v20.2d,v20.2d,v29.2d // h0 -> h1 add v23.2d,v23.2d,v30.2d // h3 -> h4 //////////////////////////////////////////////////////////////// // write the result, can be partially reduced st4 {v19.s,v20.s,v21.s,v22.s}[0],[x0],#16 st1 {v23.s}[0],[x0] .Lno_data_neon: ldr x29,[sp],#80 .inst 0xd50323bf // autiasp ret .size poly1305_blocks_neon,.-poly1305_blocks_neon .type poly1305_emit_neon,%function .align 5 poly1305_emit_neon: .Lpoly1305_emit_neon: ldr x17,[x0,#24] cbz x17,poly1305_emit ldp w10,w11,[x0] // load hash value base 2^26 ldp w12,w13,[x0,#8] ldr w14,[x0,#16] add x4,x10,x11,lsl#26 // base 2^26 -> base 2^64 lsr x5,x12,#12 adds x4,x4,x12,lsl#52 add x5,x5,x13,lsl#14 adc x5,x5,xzr lsr x6,x14,#24 adds x5,x5,x14,lsl#40 adc x6,x6,xzr // can be partially reduced... ldp x10,x11,[x2] // load nonce and x12,x6,#-4 // ... so reduce add x12,x12,x6,lsr#2 and x6,x6,#3 adds x4,x4,x12 adcs x5,x5,xzr adc x6,x6,xzr adds x12,x4,#5 // compare to modulus adcs x13,x5,xzr adc x14,x6,xzr tst x14,#-4 // see if it's carried/borrowed csel x4,x4,x12,eq csel x5,x5,x13,eq -#ifdef __ARMEB__ +#ifdef __AARCH64EB__ ror x10,x10,#32 // flip nonce words ror x11,x11,#32 #endif adds x4,x4,x10 // accumulate nonce adc x5,x5,x11 -#ifdef __ARMEB__ +#ifdef __AARCH64EB__ rev x4,x4 // flip output bytes rev x5,x5 #endif stp x4,x5,[x1] // write result ret .size poly1305_emit_neon,.-poly1305_emit_neon .align 5 .Lzeros: .long 0,0,0,0,0,0,0,0 .byte 80,111,108,121,49,51,48,53,32,102,111,114,32,65,82,77,118,56,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0 .align 2 .align 2