libressl: Update to 3.2.2

This commit is contained in:
liushuyu 2020-10-23 20:51:08 -06:00
parent 7d01cb01cb
commit dcc6116424
No known key found for this signature in database
GPG Key ID: 23D1CE4534419437
479 changed files with 110004 additions and 12679 deletions

View File

@ -1,5 +1,14 @@
cmake_minimum_required (VERSION 2.8.8)
if(MSVC)
cmake_minimum_required (VERSION 3.16.4)
cmake_policy(SET CMP0091 NEW)
else()
cmake_minimum_required (VERSION 3.0)
endif()
project (LibreSSL C ASM)
include(CheckFunctionExists)
include(CheckSymbolExists)
include(CheckLibraryExists)
include(CheckIncludeFiles)
include(CheckTypeSize)
@ -8,8 +17,6 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ${CMAKE_MODULE_PATH})
include(cmake_export_symbol)
include(GNUInstallDirs)
project (LibreSSL C)
enable_testing()
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/ssl/VERSION SSL_VERSION)
@ -28,11 +35,18 @@ string(REPLACE ":" "." TLS_VERSION ${TLS_VERSION})
string(REGEX REPLACE "\\..*" "" TLS_MAJOR_VERSION ${TLS_VERSION})
option(LIBRESSL_SKIP_INSTALL "Skip installation" ${LIBRESSL_SKIP_INSTALL})
option(LIBRESSL_APPS "Build apps" ON)
option(LIBRESSL_TESTS "Build tests" ON)
option(ENABLE_ASM "Enable assembly" ON)
option(ENABLE_EXTRATESTS "Enable extra tests that may be unreliable on some platforms" OFF)
option(ENABLE_NC "Enable installing TLS-enabled nc(1)" OFF)
set(OPENSSLDIR ${OPENSSLDIR} CACHE PATH "Set the default openssl directory" FORCE)
option(USE_STATIC_MSVC_RUNTIMES "Use /MT instead of /MD in MSVC" OFF)
if(USE_STATIC_MSVC_RUNTIMES)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
if(NOT LIBRESSL_SKIP_INSTALL)
set( ENABLE_LIBRESSL_INSTALL ON )
endif(NOT LIBRESSL_SKIP_INSTALL)
@ -46,6 +60,7 @@ endif()
if(CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
add_definitions(-DHAVE_ATTRIBUTE__BOUNDED__)
add_definitions(-DHAVE_ATTRIBUTE__DEAD__)
endif()
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
@ -53,32 +68,37 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux")
add_definitions(-D_BSD_SOURCE)
add_definitions(-D_POSIX_SOURCE)
add_definitions(-D_GNU_SOURCE)
set(PLATFORM_LIBS ${PLATFORM_LIBS} pthread)
endif()
if(CMAKE_SYSTEM_NAME MATCHES "MINGW")
if(WIN32 OR (CMAKE_SYSTEM_NAME MATCHES "MINGW"))
set(BUILD_NC false)
add_definitions(-D_GNU_SOURCE)
add_definitions(-D_POSIX)
add_definitions(-D_POSIX_SOURCE)
add_definitions(-D__USE_MINGW_ANSI_STDIO)
endif()
if(WIN32)
set(BUILD_NC false)
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -Wall")
if(CMAKE_SYSTEM_NAME MATCHES "HP-UX")
if(CMAKE_C_COMPILER MATCHES "gcc")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=gnu99 -fno-strict-aliasing")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -fno-strict-aliasing")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mlp64")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O2 +DD64 +Otype_safety=off")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} +DD64 +Otype_safety=off")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=600 -D__STRICT_ALIGNMENT")
set(PLATFORM_LIBS ${PLATFORM_LIBS} pthread)
endif()
if(CMAKE_SYSTEM_NAME MATCHES "SunOS")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=gnu99 -fno-strict-aliasing")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -fno-strict-aliasing")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__EXTENSIONS__")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=600")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBSD_COMP")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fpic")
set(PLATFORM_LIBS ${PLATFORM_LIBS} nsl socket)
endif()
add_definitions(-DLIBRESSL_INTERNAL)
@ -98,7 +118,8 @@ if(WIN32)
add_definitions(-D_CRT_DEPRECATED_NO_WARNINGS)
add_definitions(-D_REENTRANT -D_POSIX_THREAD_SAFE_FUNCTIONS)
add_definitions(-DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0600)
add_definitions(-DCPPFLAGS -DOPENSSL_NO_SPEED -DNO_SYSLOG -DNO_CRYPT)
add_definitions(-DCPPFLAGS -DNO_SYSLOG -DNO_CRYPT)
set(PLATFORM_LIBS ${PLATFORM_LIBS} ws2_32)
endif()
if(MSVC)
@ -223,11 +244,31 @@ if(HAVE_GETENTROPY)
add_definitions(-DHAVE_GETENTROPY)
endif()
check_function_exists(getpagesize HAVE_GETPAGESIZE)
check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE)
if(HAVE_GETPAGESIZE)
add_definitions(-DHAVE_GETPAGESIZE)
endif()
check_function_exists(getprogname HAVE_GETPROGNAME)
if(HAVE_GETPROGNAME)
add_definitions(-DHAVE_GETPROGNAME)
endif()
check_function_exists(syslog_r HAVE_SYSLOG_R)
if(HAVE_SYSLOG_R)
add_definitions(-DHAVE_SYSLOG_R)
endif()
check_function_exists(syslog HAVE_SYSLOG)
if(HAVE_SYSLOG)
add_definitions(-DHAVE_SYSLOG)
endif()
check_symbol_exists(timespecsub sys/time.h HAVE_TIMESPECSUB)
if(HAVE_TIMESPECSUB)
add_definitions(-DHAVE_TIMESPECSUB)
endif()
check_function_exists(timingsafe_bcmp HAVE_TIMINGSAFE_BCMP)
if(HAVE_TIMINGSAFE_BCMP)
add_definitions(-DHAVE_TIMINGSAFE_BCMP)
@ -252,37 +293,33 @@ if(ENABLE_ASM)
if("${CMAKE_C_COMPILER_ABI}" STREQUAL "ELF")
if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "(x86_64|amd64)")
set(HOST_ASM_ELF_X86_64 true)
elseif("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "arm")
set(HOST_ASM_ELF_ARMV4 true)
elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i386")
set(HOST_ASM_ELF_X86_64 true)
endif()
elseif(APPLE AND "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
set(HOST_ASM_MACOSX_X86_64 true)
elseif(MSVC AND ("${CMAKE_GENERATOR}" MATCHES "Win64" OR "${CMAKE_GENERATOR_PLATFORM}" STREQUAL "x64"))
set(HOST_ASM_MASM_X86_64 true)
ENABLE_LANGUAGE(ASM_MASM)
elseif(CMAKE_SYSTEM_NAME MATCHES "MINGW" AND "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
set(HOST_ASM_MINGW64_X86_64 true)
endif()
endif()
set(OPENSSL_LIBS tls ssl crypto)
if(WIN32)
set(OPENSSL_LIBS ${OPENSSL_LIBS} ws2_32)
endif()
check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)
if(HAVE_CLOCK_GETTIME)
add_definitions(-DHAVE_CLOCK_GETTIME)
endif()
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
# Check if we need -lrt to get clock_gettime on Linux
check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME)
if (HAVE_CLOCK_GETTIME)
set(OPENSSL_LIBS ${OPENSSL_LIBS} rt)
set(PLATFORM_LIBS ${PLATFORM_LIBS} rt)
endif()
set(OPENSSL_LIBS ${OPENSSL_LIBS} pthread)
else()
# Otherwise, simply check if it exists
check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)
endif()
if(CMAKE_SYSTEM_NAME MATCHES "HP-UX")
set(OPENSSL_LIBS ${OPENSSL_LIBS} pthread)
endif()
if(CMAKE_SYSTEM_NAME MATCHES "SunOS")
set(OPENSSL_LIBS ${OPENSSL_LIBS} nsl socket)
if(HAVE_CLOCK_GETTIME)
add_definitions(-DHAVE_CLOCK_GETTIME)
endif()
check_type_size(time_t SIZEOF_TIME_T)
@ -294,7 +331,40 @@ if(SIZEOF_TIME_T STREQUAL "4")
endif()
add_definitions(-DSIZEOF_TIME_T=${SIZEOF_TIME_T})
set(OPENSSL_LIBS tls ssl crypto ${PLATFORM_LIBS})
add_subdirectory(crypto)
add_subdirectory(ssl)
if(LIBRESSL_APPS)
add_subdirectory(apps)
endif()
add_subdirectory(tls)
add_subdirectory(include)
if(NOT MSVC)
add_subdirectory(man)
endif()
# Tests require the openssl executable and are unavailable when building shared libraries
if(LIBRESSL_APPS AND LIBRESSL_TESTS)
add_subdirectory(tests)
endif()
if(NOT MSVC)
# Create pkgconfig files.
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix \${prefix})
set(libdir \${exec_prefix}/${CMAKE_INSTALL_LIBDIR})
set(includedir \${prefix}/include)
if(PLATFORM_LIBS)
string(REGEX REPLACE ";" " -l" PLATFORM_LDADD ";${PLATFORM_LIBS}")
endif()
file(STRINGS "VERSION" VERSION LIMIT_COUNT 1)
file(GLOB OPENSSL_PKGCONFIGS "*.pc.in")
foreach(file ${OPENSSL_PKGCONFIGS})
get_filename_component(filename ${file} NAME)
string(REPLACE ".in" "" new_file "${filename}")
configure_file(${filename} pkgconfig/${new_file} @ONLY)
endforeach()
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/pkgconfig
DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()

634
ChangeLog
View File

@ -28,6 +28,638 @@ history is also available from Git.
LibreSSL Portable Release Notes:
3.2.2 - Stable release
* This is the first stable release with the new TLSv1.3
implementation enabled by default for both client and server. The
OpenSSL 1.1 TLSv1.3 API is not yet available and will be provided
in an upcoming release.
* New X509 certificate chain validator that correctly handles
multiple paths through intermediate certificates. Loosely based on
Go's X509 validator.
* New name constraints verification implementation which passes the
bettertls.com certificate validation check suite.
* Improve the handling of BIO_read()/BIO_write() failures in the
TLSv1.3 stack.
* Start replacing the existing TLSv1.2 record layer.
* Define OPENSSL_NO_SSL_TRACE in opensslfeatures.h.
* Make SSL_CTX_get_ciphers(NULL) return NULL rather than crash.
* Send alert on ssl_get_prev_session() failure.
* Zero out variable on the stack to avoid leaving garbage in the tail
of short session IDs.
* Move state initialization from SSL_clear() to ssl3_clear() to ensure
that it gets correctly reinitialized across a SSL_set_ssl_method()
call.
* Avoid an out-of-bounds write in BN_rand().
* Fix numerous leaks in the UI_dup_* functions. Simplify and tidy up
the code in ui_lib.c.
* Correctly track selected ALPN length to avoid a potential segmentation
fault with SSL_get0_alpn_selected() when alpn_selected is NULL.
* Include machine/endian.h gost2814789.c in order to pick up the
__STRICT_ALIGNMENT define.
* Simplify SSL method lookups.
* Clean up and simplify SSL_get_ciphers(), SSL_set_session(),
SSL_set_ssl_method() and several internal functions.
* Correctly handle ssl_cert_dup() failure in SSL_set_SSL_CTX().
* Refactor dtls1_new(), dtls1_hm_fragment_new(),
dtls1_drain_fragments(), dtls1_clear_queues().
* Copy the session ID directly in ssl_get_prev_session() instead of
handing it through several functions for copying.
* Clean up and refactor ssl_get_prev_session(); simplify
tls_decrypt_ticket() and tls1_process_ticket() exit paths.
* Avoid memset() before memcpy() in CBS_add_bytes().
* Rewrite X509_INFO_{new,free}() more idiomatically.
* Remove unnecessary zeroing after recallocarray() in
ASN1_BIT_STRING_set_bit().
* Convert openssl(1) ocsp new option handling.
* Document SSL_set1_host(3), SSL_set_SSL_CTX(3).
* Document return value from EC_KEY_get0_public_key(3).
* Greatly expanded test coverage via the tlsfuzzer test scripts.
* Expanded test coverage via the bettertls certificate test suite.
* Test interoperability with the Botan TLS client.
* Make pthread_mutex static initialisation work on Windows.
* Get __STRICT_ALIGNMENT from machine/endian.h with portable build.
3.2.1 - Development release
* Propagate alerts from the read half of the TLSv1.3 record layer to I/O
functions.
* Send a record overflow alert for TLSv1.3 messages having overlong
plaintext or inner plaintext.
* Send an illegal parameter alert if a client sends an invalid DH key
share.
* Document PKCS7_final(3), PKCS7_add_attribute(3).
* Collapse x509v3 directory into x509.
* Improve TLSv1.3 client certificate selection to allow EC certificates
instead of only RSA certificates.
* Fail on receiving an invalid NID in X509_ATTRIBUTE_create() instead
of constructing a broken objects that may cause NULL pointer accesses.
* Add support for additional GOST curves from RFC 7836 and
draft-deremin-rfc4491-bis.
* Add OIDs for HMAC using the Streebog hash function.
* Allow GOST R 34.11-2012 in PBE/PBKDF2/PKCS#5.
* Enable GOST_SIG_FORMAT_RS_LE when verifying certificate signatures.
* Handle GOST in ssl_cert_dup().
* Stop sending GOST R 34.10-94 as a CertificateType.
* Use IANA allocated GOST ClientCertificateTypes.
* Add a custom copy handler for AES keywrap to fix a use-after-free.
* Enforce in the TLSv1.3 server that that ClientHello messages after
a HelloRetryRequest match the original ClientHello as per RFC 8446
section 4.1.2
* Document more PKCS7 attribute functions.
* Document PKCS7_get_signer_info(3).
* Document PEM_ASN1_read(3) and PEM_ASN1_read_bio(3).
* Document PEM_def_callback(3).
* Document EVP_read_pw_string_min(3).
* Merge documentation of X509_get0_serialNumber from OpenSSL 1.1.1.
* Document error handling of X509_PUBKEY_get0(3) and X509_PUBKEY_get(3)
* Document X509_get0_pubkey_bitstr(3).
* Fix an off-by-one in the CBC padding removal. From BoringSSL.
* Enforce restrictions on extensions present in the ClientHello as per
RFC 8446, section 9.2.
* Add new CMAC_Init(3) and ChaCha(3) manual pages.
* Fix SSL_shutdown behavior to match the legacy stack. The previous
behavior could cause a hang.
* Add initial support for openbsd/powerpc64.
* Make the message type available in the internal TLS extensions API
functions.
* Enable TLSv1.3 for the generic TLS_method().
* Convert openssl(1) s_client option handling.
* Document openssl(1) certhash.
* Convert openssl(1) verify option handling.
* Fix a longstanding bug in PEM_X509_INFO_read_bio(3) that could cause
use-after-free and double-free issues in calling programs.
* Document PEM_X509_INFO_read(3) and PEM_X509_INFO_read_bio(3).
* Handle SSL_MODE_AUTO_RETRY being changed during a TLSv1.3 session.
* Convert openssl(1) s_server option handling.
* Add minimal info callback support for TLSv1.3.
* Refactor, clean up and simplify some SSL3/DTLS1 record writing code.
* Correctly handle server requests for an OCSP response.
* Add the P-521 curve to the list of curves supported by default
in the client.
* Convert openssl(1) req option handling.
* Avoid calling freezero with a negative size if a server sends a
malformed plaintext of all zeroes.
* Send an unexpected message alert if no valid content type is found
in a TLSv1.3 record.
3.2.0 - Development release
* Enable TLS 1.3 server side in addition to client by default.
With this change TLS 1.3 is handled entirely on the new stack
and state machine, with fallback to the legacy stack and
state machine for older versions. Note that the OpenSSL TLS 1.3
API is not yet visible/available.
* Improve length checks in the TLS 1.3 record layer and provide
appropriate alerts for violations of record layer limits.
* Enforce that SNI hostnames received by the TLS server are correctly
formed as per RFC 5890 and RFC 6066, responding with illegal parameter
for a nonconformant host name.
* Support SSL_MODE_AUTO_RETRY in TLS 1.3 to allow the automatic
retry of handshake messages.
* Modify I/O behavior so that SSL_MODE_AUTO_RETRY is the default
similar to new OpenSSL releases.
* Modify openssl(1) to clear SSL_MODE_AUTO_RETRY appropriately in
various commands.
* Add tlsfuzzer based regression tests.
* Support sending certificate status requests from the TLS 1.3
client to request OCSP staples for leaf certificates.
* Support sending certificate status replies from the TLS 1.3 server
in order to send OCSP staples for leaf certificates.
* Send correct alerts when handling failed key share extensions
on the TLS 1.3 server.
* Various compatibility fixes for TLS 1.3 to 1.2 fallback for
switching from the new to legacy stacks.
* Support TLS 1.3 options in the openssl(1) command.
* Many alert cleanups in TLS 1.3 to provide expected alerts in failure
conditions.
* Modify "openssl x509" to display invalid certificate times as
invalid, and correctly deal with the failing return case from
X509_cmp_time so that a certificate with an invalid NotAfter does
not appear valid.
* Support sending dummy change_cipher_spec records for TLS 1.3 middlebox
compatibility.
* Ensure only PSS signatures are used with RSA in TLS 1.3.
* Ensure that TLS 1.3 clients advertise exactly the "null" compression
method in its legacy_compression_methods.
* Correct use of sockaddr_storage instead of sockaddr in openssl(1)
s_client, which could lead to using 14 bytes of stack garbage instead
of an IPv6 address in DTLS mode.
* Use non-expired certificates first when building a certificate chain.
3.1.4 - Interoperability and bug fixes for the TLSv1.3 client:
* Improve client certificate selection to allow EC certificates
instead of only RSA certificates.
* Do not error out if a TLSv1.3 server requests an OCSP response as
part of a certificate request.
* Fix SSL_shutdown behavior to match the legacy stack. The previous
behaviour could cause a hang.
* Fix a memory leak and add a missing error check in the handling of
the key update message.
* Fix a memory leak in tls13_record_layer_set_traffic_key.
* Avoid calling freezero with a negative size if a server sends a
malformed plaintext of all zeroes.
* Ensure that only PSS may be used with RSA in TLSv1.3 in order
to avoid using PKCS1-based signatures.
* Add the P-521 curve to the list of curves supported by default
in the client.
3.1.3 - Bug fix
* libcrypto may fail to build a valid certificate chain due to
expired untrusted issuer certificates.
3.1.2 - Bug fix
* A TLS client with peer verification disabled may crash when
contacting a server that sends an empty certificate list.
3.1.1 - Stable release
* Improved cipher suite handling to automatically include TLSv1.3
cipher suites when they are not explicitly referred to in the
cipher string.
* Improved handling of TLSv1.3 HelloRetryRequests, simplifying
state transitions and ensuring that the legacy session identifer
retains the same value across the handshake.
* Provided TLSv1.3 cipher suite aliases to match the names used
in RFC 8446.
* Improved TLSv1.3 client key share handling to allow the use of
any groups in our configured NID list.
* Fixed printing the serialNumber with X509_print_ex() fall back to
the colon separated hex bytes in case greater than int value.
* Fix to disallow setting the AES-GCM IV length to zero.
* Added -groups option to openssl(1) s_server subcommand.
* Fix to show TLSv1.3 extension types with openssl(1) -tlsextdebug.
* Improved portable builds to support the use of static MSVC runtimes.
* Fixed portable builds to avoid exporting a sleep() symbol.
3.1.0 - Development release
* Completed initial TLS 1.3 implementation with a completely new state
machine and record layer. TLS 1.3 is now enabled by default for the
client side, with the server side to be enabled in a future release.
Note that the OpenSSL TLS 1.3 API is not yet visible/available.
* Many more code cleanups, fixes, and improvements to memory handling
and protocol parsing.
* Added RSA-PSS and RSA-OAEP methods from OpenSSL 1.1.1.
* Ported Cryptographic Message Syntax (CMS) implementation from OpenSSL
1.1.1 and enabled by default.
* Improved compatibility by backporting functionality and documentation
from OpenSSL 1.1.1.
* Added many new additional crypto test vectors.
* Adjusted EVP_chacha20()'s behavior to match OpenSSL's semantics.
* Default CA bundle location is now configurable in portable builds.
* Added cms subcommand to openssl(1).
* Added -addext option to openssl(1) req subcommand.
3.0.2 - Stable release
* Use a valid curve when constructing an EC_KEY that looks like X25519.
The recent EC group cofactor change results in stricter validation,
which causes the EC_GROUP_set_generator() call to fail.
Issue reported and fix tested by rsadowski@
* Fixed a padding oracle in PKCS7_dataDecode and CMS_decrypt_set1_pkey.
(Note that the CMS code is currently disabled)
Port of Edlinger's Fix for CVE-2019-1563 from OpenSSL 1.1.1 (old license)
* Avoid a path traversal bug in s_server on Windows when run with the -WWW
or -HTTP options, due to incomplete path check logic.
Issue reported and fix tested by Jobert Abma
3.0.1 - Development release
* Ported Billy Brumley's fix for CVE-2019-1547 in OpenSSL 1.1.1. If a NULL
or zero cofactor is passed to EC_GROUP_set_generator(), try to compute
it using Hasse's bound. This works as long as the cofactor is small
enough.
* Fixed a memory leak in error paths for eckey_type2param().
* Initial work on supporting Cryptographic Message Syntax (CMS) in
libcrypto (not enabled).
* Various manual page improvements and additions.
* Added a CMake check for an existing uninstall target, facilitating
embedding LibreSSL in larger CMake projects, from Matthew Albrecht.
3.0.0 - Development release
* Completed the port of RSA_METHOD accessors from the OpenSSL 1.1 API.
* Documented undescribed options and removed unfunctional options
description in openssl(1) manual.
* A plethora of small fixes due to regular oss-fuzz testing.
* Various side channels in DSA and ECDSA were addressed. These are some of
the many issues found in an extensive systematic analysis of bignum usage
by Samuel Weiser, David Schrammel et al.
* Enabled openssl(1) speed subcommand on Windows platform.
* Enabled performance optimizations when building with Visual Studio on Windows.
* Fixed incorrect carry operation in 512 addition for Streebog.
* Fixed -modulus option with openssl(1) dsa subcommand.
* Fixed PVK format output issue with openssl(1) dsa and rsa subcommand.
2.9.2 - Bug fixes
* Fixed portable builds with older versions of MacOS,
Android targets < API 21, and Solaris 10
* Fixed SRTP profile advertisement for DTLS servers.
2.9.1 - Stable release
* Added support for XChaCha20 and XChaCha20-Poly1305.
* Added support for AES key wrap constructions via the EVP interface.
* Partial port of the OpenSSL EC_KEY_METHOD API for use by OpenSSH.
* Added pbkdf2 key derivation support to openssl(1)
* Removed SHA224 based handshake signatures from consideration for use in a TLS 1.2 handshake.
* Changed the default digest type of openssl(1) enc to to sha256.
* Changed the default digest type of openssl(1) dgst to sha256.
* Changed the default digest type of openssl(1) x509 -fingerprint to sha256.
* Changed the default digest type of openssl(1) crl -fingerprint to sha256.
* Improved Windows, Android, and ARM compatibility, including assembly
optimizations on Mingw-w64 targets.
2.9.0 - Development release
* Added the SM4 block cipher from the Chinese standard GB/T 32907-2016.
* Fixed warnings about clock_gettime on Windows Visual Studio builds.
* Fixed CMake builds on systems where getpagesize is defined as an
inline function.
* CRYPTO_LOCK is now automatically initialized, with the legacy
callbacks stubbed for compatibility.
* Added the SM3 hash function from the Chinese standard GB/T 32905-2016.
* Added more OPENSSL_NO_* macros for compatibility with OpenSSL.
* Added extensive interoperability tests between LibreSSL and OpenSSL
1.0 and 1.1.
* Added additional Wycheproof tests and related bug fixes.
* Simplified sigalgs option processing and handshake signing algorithm
* Added the ability to use the RSA PSS algorithm for handshake
signatures.
* Added bn_rand_interval() and use it in code needing ranges of random
bn values.
* Added functionality to derive early, handshake, and application
secrets as per RFC8446.
* Added handshake state machine from RFC8446.
* Removed some ASN.1 related code from libcrypto that had not been used
since around 2000.
* Unexported internal symbols and internalized more record layer structs.
* Added support for assembly optimizations on 32-bit ARM ELF targets.
* Improved protection against timing side channels in ECDSA signature
generation.
* Coordinate blinding was added to some elliptic curves. This is the
last bit of the work by Brumley et al. to protect against the
Portsmash vulnerability.
* Ensure transcript handshake is always freed with TLS 1.2.
2.8.2 - Stable release
* Added Wycheproof support for ECDH and ECDSA Web Crypto test vectors,
along with test harness fixes.
* Fixed memory leak in nc(1)
2.8.1 - Test and compatibility improvements
* Added Wycheproof support for ECDH, RSASSA-PSS, AES-GCM,
AES-CMAC, AES-CCM, AES-CBC-PKCS5, DSA, ChaCha20-Poly1305, ECDSA, and
X25519 test vectors. Applied appropriate fixes for errors uncovered
by tests.
* Simplified key exchange signature generation and verification.
* Fixed a one-byte buffer overrun in callers of EVP_read_pw_string
* Converted more code paths to use CBB/CBS. All handshake messages are
now created by CBB.
* Fixed various memory leaks found by Coverity.
* Simplified session ticket parsing and handling, inspired by
BoringSSL.
* Modified signature of CRYPTO_mem_leaks_* to return -1. This function
is a no-op in LibreSSL, so this function returns an error to not
indicate the (non-)existence of memory leaks.
* SSL_copy_session_id, PEM_Sign, EVP_EncodeUpdate, BIO_set_cipher,
X509_OBJECT_up_ref_count now return an int for error handling,
matching OpenSSL.
* Converted a number of #defines into proper functions, matching
OpenSSL's ABI.
* Added X509_get0_serialNumber from OpenSSL.
* Removed EVP_PKEY2PKCS8_broken and PKCS8_set_broken, while adding
PKCS8_pkey_add1_attr_by_NID and PKCS8_pkey_get0_attrs, matching
OpenSSL.
* Removed broken pkcs8 formats from openssl(1).
* Converted more functions in public API to use const arguments.
* Stopped handing AES-GCM in ssl_cipher_get_evp, since they use the
EVP_AEAD interface.
* Stopped using composite EVP_CIPHER AEADs.
* Added timing-safe compares for checking results of signature
verification. There are no known attacks, this is just inexpensive
prudence.
* Correctly clear the current cipher state, when changing cipher state.
This fixed an issue where renegotiation of cipher suites would fail
when switched from AEAD to non-AEAD or vice-versa.
Issue reported by Bernard Spil.
* Added more cipher tests to appstest.sh, including all TLSv1.2
ciphers.
* Added RSA_meth_get_finish() RSA_meth_set1_name() from OpenSSL.
* Added new EVP_CIPHER_CTX_(get|set)_iv() API that allows the IV to be
retrieved and set with appropriate validation.
2.8.0 - Bug fixes, security, and compatibility improvements
* Extensive documentation updates and additional API history.
* Fixed a pair of 20+ year-old bugs in X509_NAME_add_entry
* Tighten up checks for various X509_VERIFY_PARAM functions,
'poisoning' parameters so that an unverified certificate cannot be
used if it fails verification.
* Fixed a potential memory leak on failure in ASN1_item_digest
* Fixed a potential memory alignment crash in asn1_item_combine_free
* Removed unused SSL3_FLAGS_DELAY_CLIENT_FINISHED and
SSL3_FLAGS_POP_BUFFER flags in write path, simplifying IO paths.
* Removed SSL_OP_TLS_ROLLBACK_BUG buggy client workarounds.
* Made ENGINE_finish and ENGINE_free succeed on NULL and simplify callers
and matching OpenSSL behavior, rewrote ENGINE_* documentation.
* Added const annotations to many existing APIs from OpenSSL, making
interoperability easier for downstream applications.
* Fixed small timing side-channels in ecdsa_sign_setup and
dsa_sign_setup.
* Documented security pitfalls with BN_FLG_CONSTTIME and constant-time
operation of BN_* functions.
* Updated BN_clear to use explicit_bzero.
* Added a missing bounds check in c2i_ASN1_BIT_STRING.
* More CBS conversions, including simplifications to RSA key exchange,
and converted code to use dedicated buffers for secrets.
* Removed three remaining single DES cipher suites.
* Fixed a potential leak/incorrect return value in DSA signature
generation.
* Added a blinding value when generating DSA and ECDSA signatures, in
order to reduce the possibility of a side-channel attack leaking the
private key.
* Added ECC constant time scalar multiplication support.
From Billy Brumley and his team at Tampere University of Technology.
* Revised the implementation of RSASSA-PKCS1-v1_5 to match the
specification in RFC 8017. Based on an OpenSSL commit by David
Benjamin.
* Cleaned up BN_* implementations following changes made in OpenSSL by
Davide Galassi and others.
2.7.4 - Security fixes
* Avoid a timing side-channel leak when generating DSA and ECDSA
signatures. This is caused by an attempt to do fast modular
arithmetic, which introduces branches that leak information
regarding secret values. Issue identified and reported by Keegan
Ryan of NCC Group.
* Reject excessively large primes in DH key generation. Problem
reported by Guido Vranken to OpenSSL
(https://github.com/openssl/openssl/pull/6457) and based on his
diff.
2.7.3 - Bug fixes
* Removed incorrect NULL checks in DH_set0_key(). Reported by Ondrej
Sury
* Fixed an issue normalizing CPU architecture in the configure script,
which disabled assembly optimizations on platforms that get detected
as 'amd64', opposed to 'x86_64'
* Limited tls_config_clear_keys() to only clear private keys.
This was inadvertently clearing the keypair, which includes the OCSP
staple and pubkey hash - if an application called tls_configure()
followed by tls_config_clear_keys(), this would prevent OCSP staples
from working.
2.7.2 - Stable release
* Updated and added extensive new HISTORY sections to API manuals.
@ -904,7 +1536,7 @@ LibreSSL Portable Release Notes:
* Removed nonfunctional Netscape browser-hang workaround code.
* Simplfied and refactored SSL/DTLS handshake code.
* Simplified and refactored SSL/DTLS handshake code.
* Added SHA256 Camellia cipher suites for TLS 1.2 from RFC 5932.

227
FindLibreSSL.cmake Normal file
View File

@ -0,0 +1,227 @@
#[=======================================================================[
Copyright (c) 2019 John Norrbin <jlnorrbin@johnex.se>
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
FindLibreSSL
------------
Find the LibreSSL encryption library.
Optional Components
^^^^^^^^^^^^^^^^^^^
This module supports two optional components: SSL and TLS. Both
components have associated imported targets, as described below.
Imported Targets
^^^^^^^^^^^^^^^^
This module defines the following imported targets:
LibreSSL::Crypto
The LibreSSL crypto library, if found.
LibreSSL::SSL
The LibreSSL ssl library, if found. Requires and includes LibreSSL::Crypto automatically.
LibreSSL::TLS
The LibreSSL tls library, if found. Requires and includes LibreSSL::SSL and LibreSSL::Crypto automatically.
Result Variables
^^^^^^^^^^^^^^^^
This module will set the following variables in your project:
LIBRESSL_FOUND
System has the LibreSSL library. If no components are requested it only requires the crypto library.
LIBRESSL_INCLUDE_DIR
The LibreSSL include directory.
LIBRESSL_CRYPTO_LIBRARY
The LibreSSL crypto library.
LIBRESSL_SSL_LIBRARY
The LibreSSL SSL library.
LIBRESSL_TLS_LIBRARY
The LibreSSL TLS library.
LIBRESSL_LIBRARIES
All LibreSSL libraries.
LIBRESSL_VERSION
This is set to $major.$minor.$revision (e.g. 2.6.8).
Hints
^^^^^
Set LIBRESSL_ROOT_DIR to the root directory of an LibreSSL installation.
]=======================================================================]
INCLUDE(FindPackageHandleStandardArgs)
# Set Hints
set(_LIBRESSL_ROOT_HINTS
${LIBRESSL_ROOT_DIR}
ENV LIBRESSL_ROOT_DIR
)
# Set Paths
if (WIN32)
file(TO_CMAKE_PATH "$ENV{PROGRAMFILES}" _programfiles)
set(_LIBRESSL_ROOT_PATHS
"${_programfiles}/LibreSSL"
)
unset(_programfiles)
else()
set(_LIBRESSL_ROOT_PATHS
"/usr/local/"
)
endif()
# Combine
set(_LIBRESSL_ROOT_HINTS_AND_PATHS
HINTS ${_LIBRESSL_ROOT_HINTS}
PATHS ${_LIBRESSL_ROOT_PATHS}
)
# Find Include Path
find_path(LIBRESSL_INCLUDE_DIR
NAMES
tls.h
${_LIBRESSL_ROOT_HINTS_AND_PATHS}
PATH_SUFFIXES
include
)
# Find Crypto Library
find_library(LIBRESSL_CRYPTO_LIBRARY
NAMES
libcrypto
crypto
NAMES_PER_DIR
${_LIBRESSL_ROOT_HINTS_AND_PATHS}
PATH_SUFFIXES
lib
)
# Find SSL Library
find_library(LIBRESSL_SSL_LIBRARY
NAMES
libssl
ssl
NAMES_PER_DIR
${_LIBRESSL_ROOT_HINTS_AND_PATHS}
PATH_SUFFIXES
lib
)
# Find TLS Library
find_library(LIBRESSL_TLS_LIBRARY
NAMES
libtls
tls
NAMES_PER_DIR
${_LIBRESSL_ROOT_HINTS_AND_PATHS}
PATH_SUFFIXES
lib
)
# Set Libraries
set(LIBRESSL_LIBRARIES ${LIBRESSL_CRYPTO_LIBRARY} ${LIBRESSL_SSL_LIBRARY} ${LIBRESSL_TLS_LIBRARY})
# Mark Variables As Advanced
mark_as_advanced(LIBRESSL_INCLUDE_DIR LIBRESSL_LIBRARIES LIBRESSL_CRYPTO_LIBRARY LIBRESSL_SSL_LIBRARY LIBRESSL_TLS_LIBRARY)
# Find Version File
if(LIBRESSL_INCLUDE_DIR AND EXISTS "${LIBRESSL_INCLUDE_DIR}/openssl/opensslv.h")
# Get Version From File
file(STRINGS "${LIBRESSL_INCLUDE_DIR}/openssl/opensslv.h" OPENSSLV.H REGEX "#define LIBRESSL_VERSION_TEXT[ ]+\".*\"")
# Match Version String
string(REGEX REPLACE ".*\".*([0-9]+)\\.([0-9]+)\\.([0-9]+)\"" "\\1;\\2;\\3" LIBRESSL_VERSION_LIST "${OPENSSLV.H}")
# Split Parts
list(GET LIBRESSL_VERSION_LIST 0 LIBRESSL_VERSION_MAJOR)
list(GET LIBRESSL_VERSION_LIST 1 LIBRESSL_VERSION_MINOR)
list(GET LIBRESSL_VERSION_LIST 2 LIBRESSL_VERSION_REVISION)
# Set Version String
set(LIBRESSL_VERSION "${LIBRESSL_VERSION_MAJOR}.${LIBRESSL_VERSION_MINOR}.${LIBRESSL_VERSION_REVISION}")
endif()
# Set Find Package Arguments
find_package_handle_standard_args(LibreSSL
REQUIRED_VARS
LIBRESSL_CRYPTO_LIBRARY
LIBRESSL_INCLUDE_DIR
VERSION_VAR
LIBRESSL_VERSION
HANDLE_COMPONENTS
FAIL_MESSAGE
"Could NOT find LibreSSL, try setting the path to LibreSSL using the LIBRESSL_ROOT_DIR environment variable"
)
# LibreSSL Found
if(LIBRESSL_FOUND)
# Set LibreSSL::Crypto
if(NOT TARGET LibreSSL::Crypto AND EXISTS "${LIBRESSL_CRYPTO_LIBRARY}")
# Add Library
add_library(LibreSSL::Crypto UNKNOWN IMPORTED)
# Set Properties
set_target_properties(
LibreSSL::Crypto
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${LIBRESSL_INCLUDE_DIR}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${LIBRESSL_CRYPTO_LIBRARY}"
)
endif() # LibreSSL::Crypto
# Set LibreSSL::SSL
if(NOT TARGET LibreSSL::SSL AND EXISTS "${LIBRESSL_SSL_LIBRARY}")
# Add Library
add_library(LibreSSL::SSL UNKNOWN IMPORTED)
# Set Properties
set_target_properties(
LibreSSL::SSL
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${LIBRESSL_INCLUDE_DIR}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${LIBRESSL_SSL_LIBRARY}"
INTERFACE_LINK_LIBRARIES LibreSSL::Crypto
)
endif() # LibreSSL::SSL
# Set LibreSSL::TLS
if(NOT TARGET LibreSSL::TLS AND EXISTS "${LIBRESSL_TLS_LIBRARY}")
add_library(LibreSSL::TLS UNKNOWN IMPORTED)
set_target_properties(
LibreSSL::TLS
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${LIBRESSL_INCLUDE_DIR}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${LIBRESSL_TLS_LIBRARY}"
INTERFACE_LINK_LIBRARIES LibreSSL::SSL
)
endif() # LibreSSL::TLS
endif(LIBRESSL_FOUND)

View File

@ -1,21 +1,10 @@
Official repository is development, not release versions of LibreSSL, and needs external applications to prepare for
build.
![LibreSSL image](https://www.libressl.org/images/libressl.jpg)
## Official portable version of [LibreSSL](https://www.libressl.org) ##
Built from https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-2.7.2.tar.gz
Modifications:
- Removed tests/mandocs/pkgconfig/scripts/apps/cmake_uninstall from both filesystem and CMakeLists.txt
- Removed m4 configuration files + make build scripts
===
![LibreSSL image](http://www.libressl.org/images/libressl.jpg)
## Official portable version of [LibreSSL](http://www.libressl.org) ##
[![Build Status](https://travis-ci.org/libressl-portable/portable.svg?branch=master)](https://travis-ci.org/libressl-portable/portable)
[![Build Status](https://travis-ci.org/libressl-portable/portable.svg?branch=master)](https://travis-ci.org/libressl-portable/portable) [![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/libressl.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:libressl)
LibreSSL is a fork of [OpenSSL](https://www.openssl.org) 1.0.1g developed by the
[OpenBSD](http://www.openbsd.org) project. Our goal is to modernize the codebase,
[OpenBSD](https://www.openbsd.org) project. Our goal is to modernize the codebase,
improve security, and apply best practice development processes from OpenBSD.
## Compatibility with OpenSSL: ##
@ -37,7 +26,7 @@ the LibreSSL portable project attempts to provide working alternatives for
other operating systems, and assists with improving OS-native implementations
where possible.
At the time of this writing, LibreSSL is know to build and work on:
At the time of this writing, LibreSSL is known to build and work on:
* Linux (kernel 3.17 or later recommended)
* FreeBSD (tested with 9.2 and later)
@ -48,14 +37,14 @@ At the time of this writing, LibreSSL is know to build and work on:
* AIX (5.3 and later)
LibreSSL also supports the following Windows environments:
* Microsoft Windows (XP or higher, x86 and x64)
* Microsoft Windows (Vista or higher, x86 and x64)
* Wine (32-bit and 64-bit)
* Builds with Mingw-w64, Cygwin, and Visual Studio
Official release tarballs are available at your friendly neighborhood
OpenBSD mirror in directory
[LibreSSL](http://ftp.openbsd.org/pub/OpenBSD/LibreSSL/),
although we suggest that you use a [mirror](http://www.openbsd.org/ftp.html).
[LibreSSL](https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/),
although we suggest that you use a [mirror](https://www.openbsd.org/ftp.html).
The LibreSSL portable build framework is also
[mirrored](https://github.com/libressl-portable/portable) in Github.
@ -77,13 +66,13 @@ building. _Note: Your build will fail if you do not follow these instructions! I
1. Ensure you have the following packages installed:
automake, autoconf, git, libtool, perl
2. Run './autogen.sh' to prepare the source tree for building or
run './dist.sh' to prepare a tarball.
2. Run `./autogen.sh` to prepare the source tree for building or
run `./dist.sh` to prepare a tarball.
## Steps that apply to all builds ##
Once you have a source tree, either by downloaded using git and having
run the autogen.sh script above, or by downloading a release distribution from
run the `autogen.sh` script above, or by downloading a release distribution from
an OpenBSD mirror, run these commands to build and install the package on most
systems:
@ -117,7 +106,7 @@ ninja test
#### HP-UX (11i) ####
Set the UNIX_STD environment variable to '2003' before running 'configure'
Set the UNIX_STD environment variable to `2003` before running `configure`
in order to build with the HP C/aC++ compiler. See the "standards(5)" man
page for more details.
@ -145,7 +134,7 @@ directory and run:
cmake -G"Visual Studio 12 2013" ..
```
Replace "Visual Studion 12 2013" with whatever version of Visual Studio you
Replace "Visual Studio 12 2013" with whatever version of Visual Studio you
have installed. This will generate a LibreSSL.sln file that you can incorporate
into other projects or build by itself.
@ -154,9 +143,62 @@ into other projects or build by itself.
| Option Name | Default | Description
| ------------ | -----: | ------
| LIBRESSL_SKIP_INSTALL | OFF | allows skipping install() rules. Can be specified from command line using <br>```-DLIBRESSL_SKIP_INSTALL=ON``` |
| LIBRESSL_APPS | ON | allows skipping application builds. Apps are required to run tests |
| LIBRESSL_TESTS | ON | allows skipping of tests. Tests are only available in static builds |
| BUILD_SHARED_LIBS | OFF | CMake option for building shared libraries. |
| ENABLE_ASM | ON | builds assembly optimized rules. |
| ENABLE_EXTRATESTS | OFF | Enable extra tests that may be unreliable on some platforms |
| ENABLE_NC | OFF | Enable installing TLS-enabled nc(1) |
| ENABLE_VSTEST | OFF | Enable test on Visual Studio |
| OPENSSLDIR | Blank | Set the default openssl directory. Can be specified from command line using <br>```-DOPENSSLDIR=<dirname>``` |
# Using LibreSSL #
## CMake ##
Make a new folder in your project root (where your main CMakeLists.txt file is located) called CMake. Copy the FindLibreSSL.cmake file to that folder, and add the following line to your main CMakeLists.txt:
```cmake
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}")
```
After your **add_executable** or **add_library** line in your CMakeLists.txt file add the following:
```cmake
find_package(LibreSSL REQUIRED)
```
It will tell CMake to find LibreSSL and if found will let you use the following 3 interfaces in your CMakeLists.txt file:
* LibreSSL::Crypto
* LibreSSL::SSL
* LibreSSL::TLS
If you for example want to use the LibreSSL TLS library in your test program, include it like so (SSL and Cryto are required by TLS and included automatically too):
```cmake
target_link_libraries(test LibreSSL::TLS)
```
Full example:
```cmake
cmake_minimum_required(VERSION 3.10.0)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}")
project(test)
add_executable(test Main.cpp)
find_package(LibreSSL REQUIRED)
target_link_libraries(test LibreSSL::TLS)
```
#### Linux ####
Following the guide in the sections above to compile LibreSSL using make and running "sudo make install" will install LibreSSL to the /usr/local/ folder, and will found automatically by find_package. If your system installs it to another location or you have placed them yourself in a different location, you can set the CMake variable LIBRESSL_ROOT_DIR to the correct path, to help CMake find the library.
#### Windows ####
Placing the library files in C:/Program Files/LibreSSL/lib and the include files in C:/Program Files/LibreSSL/include should let CMake find them automatically, but it is recommended that you use CMake-GUI to set the paths. It is more convenient as you can have the files in any folder you choose.

View File

@ -1,2 +1,2 @@
2.7.2
3.2.2

View File

@ -1,21 +0,0 @@
if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
string(REGEX REPLACE "\n" ";" files "${files}")
foreach(file ${files})
message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
exec_program(
"@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
OUTPUT_VARIABLE rm_out
RETURN_VALUE rm_retval
)
if(NOT "${rm_retval}" STREQUAL 0)
message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
endif(NOT "${rm_retval}" STREQUAL 0)
else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
endforeach(file)

View File

@ -1,13 +1,27 @@
include_directories(
.
../include
../include/compat
asn1
bn
dsa
evp
modes
)
if(HOST_ASM_ELF_ARMV4)
set(
ASM_ARMV4_ELF_SRC
aes/aes-elf-armv4.S
bn/gf2m-elf-armv4.S
bn/mont-elf-armv4.S
sha/sha1-elf-armv4.S
sha/sha512-elf-armv4.S
sha/sha256-elf-armv4.S
modes/ghash-elf-armv4.S
armv4cpuid.S
armcap.c
)
add_definitions(-DAES_ASM)
add_definitions(-DOPENSSL_BN_ASM_MONT)
add_definitions(-DOPENSSL_BN_ASM_GF2m)
add_definitions(-DGHASH_ASM)
add_definitions(-DSHA1_ASM)
add_definitions(-DSHA256_ASM)
add_definitions(-DSHA512_ASM)
add_definitions(-DOPENSSL_CPUID_OBJ)
set_property(SOURCE ${ASM_ARMV4_ELF_SRC} PROPERTY LANGUAGE C)
set(CRYPTO_SRC ${CRYPTO_SRC} ${ASM_ARMV4_ELF_SRC})
endif()
if(HOST_ASM_ELF_X86_64)
set(
@ -91,14 +105,113 @@ if(HOST_ASM_MACOSX_X86_64)
add_definitions(-DOPENSSL_CPUID_OBJ)
set(CRYPTO_SRC ${CRYPTO_SRC} ${ASM_X86_64_MACOSX_SRC})
set_property(SOURCE ${ASM_X86_64_MACOSX_SRC} PROPERTY LANGUAGE C)
set_property(SOURCE ${ASM_X86_64_MACOSX_SRC} PROPERTY XCODE_EXPLICIT_FILE_TYPE "sourcecode.asm")
endif()
if((NOT HOST_ASM_ELF_X86_64) AND (NOT HOST_ASM_MACOSX_X86_64))
if(HOST_ASM_MASM_X86_64)
set(
ASM_X86_64_MASM_SRC
aes/aes-masm-x86_64.S
aes/bsaes-masm-x86_64.S
aes/vpaes-masm-x86_64.S
aes/aesni-masm-x86_64.S
aes/aesni-sha1-masm-x86_64.S
#bn/modexp512-masm-x86_64.S
#bn/mont-masm-x86_64.S
#bn/mont5-masm-x86_64.S
#bn/gf2m-masm-x86_64.S
camellia/cmll-masm-x86_64.S
md5/md5-masm-x86_64.S
modes/ghash-masm-x86_64.S
rc4/rc4-masm-x86_64.S
rc4/rc4-md5-masm-x86_64.S
sha/sha1-masm-x86_64.S
sha/sha256-masm-x86_64.S
sha/sha512-masm-x86_64.S
whrlpool/wp-masm-x86_64.S
cpuid-masm-x86_64.S
)
add_definitions(-DAES_ASM)
add_definitions(-DBSAES_ASM)
add_definitions(-DVPAES_ASM)
add_definitions(-DOPENSSL_IA32_SSE2)
#add_definitions(-DOPENSSL_BN_ASM_MONT)
#add_definitions(-DOPENSSL_BN_ASM_MONT5)
#add_definitions(-DOPENSSL_BN_ASM_GF2m)
add_definitions(-DMD5_ASM)
add_definitions(-DGHASH_ASM)
add_definitions(-DRSA_ASM)
add_definitions(-DSHA1_ASM)
add_definitions(-DSHA256_ASM)
add_definitions(-DSHA512_ASM)
add_definitions(-DWHIRLPOOL_ASM)
add_definitions(-DOPENSSL_CPUID_OBJ)
set(CRYPTO_SRC ${CRYPTO_SRC} ${ASM_X86_64_MASM_SRC})
set_property(SOURCE ${ASM_X86_64_MASM_SRC} PROPERTY LANGUAGE ASM_MASM)
endif()
if(HOST_ASM_MINGW64_X86_64)
set(
ASM_X86_64_MINGW64_SRC
aes/aes-mingw64-x86_64.S
aes/bsaes-mingw64-x86_64.S
aes/vpaes-mingw64-x86_64.S
aes/aesni-mingw64-x86_64.S
aes/aesni-sha1-mingw64-x86_64.S
#bn/modexp512-mingw64-x86_64.S
#bn/mont-mingw64-x86_64.S
#bn/mont5-mingw64-x86_64.S
#bn/gf2m-mingw64-x86_64.S
camellia/cmll-mingw64-x86_64.S
md5/md5-mingw64-x86_64.S
modes/ghash-mingw64-x86_64.S
rc4/rc4-mingw64-x86_64.S
rc4/rc4-md5-mingw64-x86_64.S
sha/sha1-mingw64-x86_64.S
sha/sha256-mingw64-x86_64.S
sha/sha512-mingw64-x86_64.S
whrlpool/wp-mingw64-x86_64.S
cpuid-mingw64-x86_64.S
)
add_definitions(-DAES_ASM)
add_definitions(-DBSAES_ASM)
add_definitions(-DVPAES_ASM)
add_definitions(-DOPENSSL_IA32_SSE2)
#add_definitions(-DOPENSSL_BN_ASM_MONT)
#add_definitions(-DOPENSSL_BN_ASM_MONT5)
#add_definitions(-DOPENSSL_BN_ASM_GF2m)
add_definitions(-DMD5_ASM)
add_definitions(-DGHASH_ASM)
add_definitions(-DRSA_ASM)
add_definitions(-DSHA1_ASM)
add_definitions(-DSHA256_ASM)
add_definitions(-DSHA512_ASM)
add_definitions(-DWHIRLPOOL_ASM)
add_definitions(-DOPENSSL_CPUID_OBJ)
set(CRYPTO_SRC ${CRYPTO_SRC} ${ASM_X86_64_MINGW64_SRC})
set_property(SOURCE ${ASM_X86_64_MINGW64_SRC} PROPERTY LANGUAGE C)
endif()
if((NOT HOST_ASM_ELF_X86_64) AND
(NOT HOST_ASM_MACOSX_X86_64) AND
(NOT HOST_ASM_MASM_X86_64) AND
(NOT HOST_ASM_MINGW64_X86_64) AND
(NOT HOST_ASM_ELF_ARMV4))
set(
CRYPTO_SRC
${CRYPTO_SRC}
aes/aes_core.c
)
endif()
if((NOT HOST_ASM_ELF_X86_64) AND
(NOT HOST_ASM_MACOSX_X86_64) AND
(NOT HOST_ASM_MASM_X86_64) AND
(NOT HOST_ASM_MINGW64_X86_64))
set(
CRYPTO_SRC
${CRYPTO_SRC}
aes/aes_cbc.c
aes/aes_core.c
camellia/camellia.c
camellia/cmll_cbc.c
rc4/rc4_enc.c
@ -130,7 +243,6 @@ set(
aes/aes_wrap.c
asn1/a_bitstr.c
asn1/a_bool.c
asn1/a_bytes.c
asn1/a_d2i_fp.c
asn1/a_digest.c
asn1/a_dup.c
@ -141,7 +253,6 @@ set(
asn1/a_object.c
asn1/a_octet.c
asn1/a_print.c
asn1/a_set.c
asn1/a_sign.c
asn1/a_strex.c
asn1/a_strnid.c
@ -273,6 +384,20 @@ set(
cmac/cm_ameth.c
cmac/cm_pmeth.c
cmac/cmac.c
cms/cms_asn1.c
cms/cms_att.c
cms/cms_cd.c
cms/cms_dd.c
cms/cms_enc.c
cms/cms_env.c
cms/cms_err.c
cms/cms_ess.c
cms/cms_io.c
cms/cms_kari.c
cms/cms_lib.c
cms/cms_pwri.c
cms/cms_sd.c
cms/cms_smime.c
comp/c_rle.c
comp/c_zlib.c
comp/comp_err.c
@ -346,6 +471,7 @@ set(
ec/ec_cvt.c
ec/ec_err.c
ec/ec_key.c
ec/ec_kmeth.c
ec/ec_lib.c
ec/ec_mult.c
ec/ec_oct.c
@ -356,6 +482,7 @@ set(
ec/ecp_nist.c
ec/ecp_oct.c
ec/ecp_smpl.c
ecdh/ecdh_kdf.c
ecdh/ech_err.c
ecdh/ech_key.c
ecdh/ech_lib.c
@ -384,6 +511,7 @@ set(
engine/tb_dsa.c
engine/tb_ecdh.c
engine/tb_ecdsa.c
engine/tb_eckey.c
engine/tb_pkmeth.c
engine/tb_rand.c
engine/tb_rsa.c
@ -412,6 +540,7 @@ set(
evp/e_rc2.c
evp/e_rc4.c
evp/e_rc4_hmac_md5.c
evp/e_sm4.c
evp/e_xcbc_d.c
evp/encode.c
evp/evp_aead.c
@ -434,6 +563,7 @@ set(
evp/m_sha1.c
evp/m_sigver.c
evp/m_streebog.c
evp/m_sm3.c
evp/m_wp.c
evp/names.c
evp/p5_crpt.c
@ -568,6 +698,8 @@ set(
sha/sha1dgst.c
sha/sha256.c
sha/sha512.c
sm3/sm3.c
sm4/sm4.c
stack/stack.c
ts/ts_asn1.c
ts/ts_conf.c
@ -588,20 +720,56 @@ set(
x509/by_dir.c
x509/by_file.c
x509/by_mem.c
x509/pcy_cache.c
x509/pcy_data.c
x509/pcy_lib.c
x509/pcy_map.c
x509/pcy_node.c
x509/pcy_tree.c
x509/x509_akey.c
x509/x509_akeya.c
x509/x509_alt.c
x509/x509_att.c
x509/x509_bcons.c
x509/x509_bitst.c
x509/x509_cmp.c
x509/x509_conf.c
x509/x509_constraints.c
x509/x509_cpols.c
x509/x509_crld.c
x509/x509_d2.c
x509/x509_def.c
x509/x509_enum.c
x509/x509_err.c
x509/x509_ext.c
x509/x509_extku.c
x509/x509_genn.c
x509/x509_ia5.c
x509/x509_info.c
x509/x509_int.c
x509/x509_issuer_cache.c
x509/x509_lib.c
x509/x509_lu.c
x509/x509_ncons.c
x509/x509_obj.c
x509/x509_ocsp.c
x509/x509_pci.c
x509/x509_pcia.c
x509/x509_pcons.c
x509/x509_pku.c
x509/x509_pmaps.c
x509/x509_prn.c
x509/x509_purp.c
x509/x509_r2x.c
x509/x509_req.c
x509/x509_set.c
x509/x509_skey.c
x509/x509_sxnet.c
x509/x509_trs.c
x509/x509_txt.c
x509/x509_utl.c
x509/x509_v3.c
x509/x509_verify.c
x509/x509_vfy.c
x509/x509_vpm.c
x509/x509cset.c
@ -610,49 +778,17 @@ set(
x509/x509spki.c
x509/x509type.c
x509/x_all.c
x509v3/pcy_cache.c
x509v3/pcy_data.c
x509v3/pcy_lib.c
x509v3/pcy_map.c
x509v3/pcy_node.c
x509v3/pcy_tree.c
x509v3/v3_akey.c
x509v3/v3_akeya.c
x509v3/v3_alt.c
x509v3/v3_bcons.c
x509v3/v3_bitst.c
x509v3/v3_conf.c
x509v3/v3_cpols.c
x509v3/v3_crld.c
x509v3/v3_enum.c
x509v3/v3_extku.c
x509v3/v3_genn.c
x509v3/v3_ia5.c
x509v3/v3_info.c
x509v3/v3_int.c
x509v3/v3_lib.c
x509v3/v3_ncons.c
x509v3/v3_ocsp.c
x509v3/v3_pci.c
x509v3/v3_pcia.c
x509v3/v3_pcons.c
x509v3/v3_pku.c
x509v3/v3_pmaps.c
x509v3/v3_prn.c
x509v3/v3_purp.c
x509v3/v3_skey.c
x509v3/v3_sxnet.c
x509v3/v3_utl.c
x509v3/v3err.c
)
if(UNIX)
set(CRYPTO_SRC ${CRYPTO_SRC} crypto_lock.c)
set(CRYPTO_SRC ${CRYPTO_SRC} bio/b_posix.c)
set(CRYPTO_SRC ${CRYPTO_SRC} bio/bss_log.c)
set(CRYPTO_SRC ${CRYPTO_SRC} ui/ui_openssl.c)
endif()
if(WIN32)
set(CRYPTO_SRC ${CRYPTO_SRC} compat/crypto_lock_win.c)
set(CRYPTO_SRC ${CRYPTO_SRC} bio/b_win.c)
set(CRYPTO_UNEXPORT ${CRYPTO_UNEXPORT} BIO_s_log)
set(CRYPTO_SRC ${CRYPTO_SRC} ui/ui_openssl_win.c)
@ -661,6 +797,7 @@ endif()
if(WIN32)
set(CRYPTO_SRC ${CRYPTO_SRC} compat/posix_win.c)
set(EXTRA_EXPORT ${EXTRA_EXPORT} gettimeofday)
set(EXTRA_EXPORT ${EXTRA_EXPORT} getuid)
set(EXTRA_EXPORT ${EXTRA_EXPORT} posix_perror)
set(EXTRA_EXPORT ${EXTRA_EXPORT} posix_fopen)
set(EXTRA_EXPORT ${EXTRA_EXPORT} posix_fgets)
@ -672,7 +809,6 @@ if(WIN32)
set(EXTRA_EXPORT ${EXTRA_EXPORT} posix_write)
set(EXTRA_EXPORT ${EXTRA_EXPORT} posix_getsockopt)
set(EXTRA_EXPORT ${EXTRA_EXPORT} posix_setsockopt)
set(EXTRA_EXPORT ${EXTRA_EXPORT} sleep)
endif()
if(NOT HAVE_ASPRINTF)
@ -690,6 +826,16 @@ if(NOT HAVE_GETPAGESIZE)
set(CRYPTO_SRC ${CRYPTO_SRC} compat/getpagesize.c)
endif()
if(NOT HAVE_GETPROGNAME)
if(WIN32)
set(CRYPTO_SRC ${CRYPTO_SRC} compat/getprogname_windows.c)
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(CRYPTO_SRC ${CRYPTO_SRC} compat/getprogname_linux.c)
else()
set(CRYPTO_SRC ${CRYPTO_SRC} compat/getprogname_unimpl.c)
endif()
endif()
if(NOT HAVE_REALLOCARRAY)
set(CRYPTO_SRC ${CRYPTO_SRC} compat/reallocarray.c)
set(EXTRA_EXPORT ${EXTRA_EXPORT} reallocarray)
@ -729,6 +875,10 @@ if(NOT HAVE_STRSEP)
set(EXTRA_EXPORT ${EXTRA_EXPORT} strsep)
endif()
if(NOT HAVE_SYSLOG_R)
set(CRYPTO_SRC ${CRYPTO_SRC} compat/syslog_r.c)
endif()
if(NOT HAVE_TIMEGM)
set(CRYPTO_SRC ${CRYPTO_SRC} compat/timegm.c)
set(EXTRA_EXPORT ${EXTRA_EXPORT} timegm)
@ -786,7 +936,12 @@ endif()
if(NOT ENABLE_ASM)
add_definitions(-DOPENSSL_NO_ASM)
else()
if(WIN32)
if(MSVC)
if((NOT "${CMAKE_GENERATOR}" MATCHES "Win64") AND
(NOT "${CMAKE_GENERATOR_PLATFORM}" STREQUAL "x64"))
add_definitions(-DOPENSSL_NO_ASM)
endif()
elseif(WIN32)
add_definitions(-DOPENSSL_NO_ASM)
endif()
endif()
@ -794,7 +949,11 @@ endif()
if(NOT "${OPENSSLDIR}" STREQUAL "")
add_definitions(-DOPENSSLDIR=\"${OPENSSLDIR}\")
else()
add_definitions(-DOPENSSLDIR=\"${CMAKE_INSTALL_PREFIX}/etc/ssl\")
if(WIN32)
add_definitions(-DOPENSSLDIR=\"C:/Windows/libressl/ssl\")
else()
add_definitions(-DOPENSSLDIR=\"${CMAKE_INSTALL_PREFIX}/etc/ssl\")
endif()
endif()
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/crypto.sym SYMS)
@ -810,18 +969,31 @@ if(EXTRA_EXPORT)
endif()
add_library(crypto ${CRYPTO_SRC})
if (BUILD_SHARED_LIBS)
export_symbol(crypto ${CMAKE_CURRENT_BINARY_DIR}/crypto_p.sym)
if (WIN32)
target_link_libraries(crypto Ws2_32.lib)
set(CRYPTO_POSTFIX -${CRYPTO_MAJOR_VERSION})
endif()
set_target_properties(crypto PROPERTIES
OUTPUT_NAME crypto${CRYPTO_POSTFIX}
ARCHIVE_OUTPUT_NAME crypto${CRYPTO_POSTFIX})
set_target_properties(crypto PROPERTIES VERSION
${CRYPTO_VERSION} SOVERSION ${CRYPTO_MAJOR_VERSION})
target_include_directories(crypto
PRIVATE
.
asn1
bn
dsa
ec
ecdh
ecdsa
evp
modes
../include/compat
PUBLIC
../include)
export_symbol(crypto ${CMAKE_CURRENT_BINARY_DIR}/crypto_p.sym)
target_link_libraries(crypto ${PLATFORM_LIBS})
if (WIN32)
set(CRYPTO_POSTFIX -${CRYPTO_MAJOR_VERSION})
endif()
set_target_properties(crypto PROPERTIES
OUTPUT_NAME crypto${CRYPTO_POSTFIX}
ARCHIVE_OUTPUT_NAME crypto${CRYPTO_POSTFIX})
set_target_properties(crypto PROPERTIES VERSION
${CRYPTO_VERSION} SOVERSION ${CRYPTO_MAJOR_VERSION})
if(ENABLE_LIBRESSL_INSTALL)
install(

View File

@ -1 +1 @@
43:1:0
46:1:0

1074
crypto/aes/aes-elf-armv4.S Normal file

File diff suppressed because it is too large Load Diff

2948
crypto/aes/aes-masm-x86_64.S Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* $OpenBSD: aes_wrap.c,v 1.10 2015/09/10 15:56:24 jsing Exp $ */
/* $OpenBSD: aes_wrap.c,v 1.12 2018/11/07 18:31:16 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project.
*/
@ -66,11 +66,12 @@ AES_wrap_key(AES_KEY *key, const unsigned char *iv, unsigned char *out,
{
unsigned char *A, B[16], *R;
unsigned int i, j, t;
if ((inlen & 0x7) || (inlen < 8))
if ((inlen & 0x7) || (inlen < 16))
return -1;
A = B;
t = 1;
memcpy(out + 8, in, inlen);
memmove(out + 8, in, inlen);
if (!iv)
iv = default_iv;
@ -100,15 +101,14 @@ AES_unwrap_key(AES_KEY *key, const unsigned char *iv, unsigned char *out,
{
unsigned char *A, B[16], *R;
unsigned int i, j, t;
if ((inlen & 0x7) || (inlen < 24))
return -1;
inlen -= 8;
if (inlen & 0x7)
return -1;
if (inlen < 8)
return -1;
A = B;
t = 6 * (inlen >> 3);
memcpy(A, in, 8);
memcpy(out, in + 8, inlen);
memmove(out, in + 8, inlen);
for (j = 0; j < 6; j++) {
R = out + inlen - 8;
for (i = 0; i < inlen; i += 8, t--, R -= 8) {

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

59
crypto/arm_arch.h Normal file
View File

@ -0,0 +1,59 @@
/* $OpenBSD: arm_arch.h,v 1.10 2019/07/02 19:31:28 patrick Exp $ */
#ifndef __ARM_ARCH_H__
#define __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__)
/*
* 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.
*/
# if 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(__ASSEMBLER__)
extern unsigned int OPENSSL_armcap_P;
#define ARMV7_NEON (1<<0)
#define ARMV8_AES (1<<1)
#define ARMV8_SHA1 (1<<2)
#define ARMV8_SHA256 (1<<3)
#define ARMV8_PMULL (1<<4)
#endif
#if defined(__OpenBSD__)
#define __STRICT_ALIGNMENT
#endif
#endif

88
crypto/armcap.c Normal file
View File

@ -0,0 +1,88 @@
/* $OpenBSD: armcap.c,v 1.8 2019/03/13 10:18:30 patrick Exp $ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <setjmp.h>
#include <signal.h>
#include <openssl/crypto.h>
#include "arm_arch.h"
unsigned int OPENSSL_armcap_P;
#if __ARM_ARCH__ >= 7
static sigset_t all_masked;
static sigjmp_buf ill_jmp;
static void ill_handler (int sig) { siglongjmp(ill_jmp, sig);
}
/*
* Following subroutines could have been inlined, but it's not all
* ARM compilers support inline assembler...
*/
void _armv7_neon_probe(void);
void _armv8_aes_probe(void);
void _armv8_sha1_probe(void);
void _armv8_sha256_probe(void);
void _armv8_pmull_probe(void);
#endif
#if defined(__GNUC__) && __GNUC__>=2
void OPENSSL_cpuid_setup(void) __attribute__((constructor));
#endif
void
OPENSSL_cpuid_setup(void)
{
#if __ARM_ARCH__ >= 7
struct sigaction ill_oact, ill_act;
sigset_t oset;
#endif
static int trigger = 0;
if (trigger)
return;
trigger = 1;
OPENSSL_armcap_P = 0;
#if __ARM_ARCH__ >= 7
sigfillset(&all_masked);
sigdelset(&all_masked, SIGILL);
sigdelset(&all_masked, SIGTRAP);
sigdelset(&all_masked, SIGFPE);
sigdelset(&all_masked, SIGBUS);
sigdelset(&all_masked, SIGSEGV);
memset(&ill_act, 0, sizeof(ill_act));
ill_act.sa_handler = ill_handler;
ill_act.sa_mask = all_masked;
sigprocmask(SIG_SETMASK, &ill_act.sa_mask, &oset);
sigaction(SIGILL, &ill_act, &ill_oact);
if (sigsetjmp(ill_jmp, 1) == 0) {
_armv7_neon_probe();
OPENSSL_armcap_P |= ARMV7_NEON;
if (sigsetjmp(ill_jmp, 1) == 0) {
_armv8_pmull_probe();
OPENSSL_armcap_P |= ARMV8_PMULL | ARMV8_AES;
} else if (sigsetjmp(ill_jmp, 1) == 0) {
_armv8_aes_probe();
OPENSSL_armcap_P |= ARMV8_AES;
}
if (sigsetjmp(ill_jmp, 1) == 0) {
_armv8_sha1_probe();
OPENSSL_armcap_P |= ARMV8_SHA1;
}
if (sigsetjmp(ill_jmp, 1) == 0) {
_armv8_sha256_probe();
OPENSSL_armcap_P |= ARMV8_SHA256;
}
}
sigaction (SIGILL, &ill_oact, NULL);
sigprocmask(SIG_SETMASK, &oset, NULL);
#endif
}

165
crypto/armv4cpuid.S Normal file
View File

@ -0,0 +1,165 @@
#include "arm_arch.h"
.text
#if defined(__thumb2__) && !defined(__APPLE__)
.syntax unified
.thumb
#else
.code 32
#undef __thumb2__
#endif
.align 5
.globl OPENSSL_atomic_add
.type OPENSSL_atomic_add,%function
OPENSSL_atomic_add:
#if __ARM_ARCH__>=6
.Ladd: ldrex r2,[r0]
add r3,r2,r1
strex r2,r3,[r0]
cmp r2,#0
bne .Ladd
mov r0,r3
bx lr
#else
stmdb sp!,{r4,r5,r6,lr}
ldr r2,.Lspinlock
adr r3,.Lspinlock
mov r4,r0
mov r5,r1
add r6,r3,r2 @ &spinlock
b .+8
.Lspin: bl sched_yield
mov r0,#-1
swp r0,r0,[r6]
cmp r0,#0
bne .Lspin
ldr r2,[r4]
add r2,r2,r5
str r2,[r4]
str r0,[r6] @ release spinlock
ldmia sp!,{r4,r5,r6,lr}
tst lr,#1
moveq pc,lr
.word 0xe12fff1e @ bx lr
#endif
.size OPENSSL_atomic_add,.-OPENSSL_atomic_add
#if __ARM_ARCH__>=7
.arch armv7-a
.fpu neon
.align 5
.globl _armv7_neon_probe
.type _armv7_neon_probe,%function
_armv7_neon_probe:
vorr q0,q0,q0
bx lr
.size _armv7_neon_probe,.-_armv7_neon_probe
.globl _armv8_aes_probe
.type _armv8_aes_probe,%function
_armv8_aes_probe:
#if defined(__thumb2__) && !defined(__APPLE__)
.byte 0xb0,0xff,0x00,0x03 @ aese.8 q0,q0
#else
.byte 0x00,0x03,0xb0,0xf3 @ aese.8 q0,q0
#endif
bx lr
.size _armv8_aes_probe,.-_armv8_aes_probe
.globl _armv8_sha1_probe
.type _armv8_sha1_probe,%function
_armv8_sha1_probe:
#if defined(__thumb2__) && !defined(__APPLE__)
.byte 0x00,0xef,0x40,0x0c @ sha1c.32 q0,q0,q0
#else
.byte 0x40,0x0c,0x00,0xf2 @ sha1c.32 q0,q0,q0
#endif
bx lr
.size _armv8_sha1_probe,.-_armv8_sha1_probe
.globl _armv8_sha256_probe
.type _armv8_sha256_probe,%function
_armv8_sha256_probe:
#if defined(__thumb2__) && !defined(__APPLE__)
.byte 0x00,0xff,0x40,0x0c @ sha256h.32 q0,q0,q0
#else
.byte 0x40,0x0c,0x00,0xf3 @ sha256h.32 q0,q0,q0
#endif
bx lr
.size _armv8_sha256_probe,.-_armv8_sha256_probe
.globl _armv8_pmull_probe
.type _armv8_pmull_probe,%function
_armv8_pmull_probe:
#if defined(__thumb2__) && !defined(__APPLE__)
.byte 0xa0,0xef,0x00,0x0e @ vmull.p64 q0,d0,d0
#else
.byte 0x00,0x0e,0xa0,0xf2 @ vmull.p64 q0,d0,d0
#endif
bx lr
.size _armv8_pmull_probe,.-_armv8_pmull_probe
#endif
.globl OPENSSL_wipe_cpu
.type OPENSSL_wipe_cpu,%function
OPENSSL_wipe_cpu:
#if __ARM_ARCH__>=7
ldr r0,.LOPENSSL_armcap
adr r1,.LOPENSSL_armcap
ldr r0,[r1,r0]
#ifdef __APPLE__
ldr r0,[r0]
#endif
#endif
eor r2,r2,r2
eor r3,r3,r3
eor ip,ip,ip
#if __ARM_ARCH__>=7
tst r0,#1
beq .Lwipe_done
veor q0, q0, q0
veor q1, q1, q1
veor q2, q2, q2
veor q3, q3, q3
veor q8, q8, q8
veor q9, q9, q9
veor q10, q10, q10
veor q11, q11, q11
veor q12, q12, q12
veor q13, q13, q13
veor q14, q14, q14
veor q15, q15, q15
.Lwipe_done:
#endif
mov r0,sp
#if __ARM_ARCH__>=5
bx lr
#else
tst lr,#1
moveq pc,lr
.word 0xe12fff1e @ bx lr
#endif
.size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu
.align 5
#if __ARM_ARCH__>=7
.LOPENSSL_armcap:
.word OPENSSL_armcap_P-.
#endif
#if __ARM_ARCH__>=6
.align 5
#else
.Lspinlock:
.word atomic_add_spinlock-.Lspinlock
.align 5
.data
.align 2
atomic_add_spinlock:
.word 0
#endif
.comm OPENSSL_armcap_P,4,4
.hidden OPENSSL_armcap_P

View File

@ -1,4 +1,4 @@
/* $OpenBSD: a_bitstr.c,v 1.24 2017/01/29 17:49:22 beck Exp $ */
/* $OpenBSD: a_bitstr.c,v 1.30 2020/09/03 17:19:27 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -118,10 +118,11 @@ i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp)
*(p++) = (unsigned char)bits;
d = a->data;
memcpy(p, d, len);
p += len;
if (len > 0)
p[-1]&=(0xff << bits);
if (len > 0) {
memcpy(p, d, len);
p += len;
p[-1] &= 0xff << bits;
}
*pp = p;
return (ret);
}
@ -135,29 +136,34 @@ c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, const unsigned char **pp, long len)
int i;
if (len < 1) {
i = ASN1_R_STRING_TOO_SHORT;
ASN1error(ASN1_R_STRING_TOO_SHORT);
goto err;
}
if ((a == NULL) || ((*a) == NULL)) {
if (a == NULL || *a == NULL) {
if ((ret = ASN1_BIT_STRING_new()) == NULL)
return (NULL);
} else
ret = (*a);
ret = *a;
p = *pp;
i = *(p++);
/* We do this to preserve the settings. If we modify
* the settings, via the _set_bit function, we will recalculate
* on output */
ret->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear */
ret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|(i&0x07)); /* set */
if (i > 7) {
ASN1error(ASN1_R_INVALID_BIT_STRING_BITS_LEFT);
goto err;
}
if (len-- > 1) /* using one because of the bits left byte */
{
s = malloc(len);
if (s == NULL) {
i = ERR_R_MALLOC_FAILURE;
/*
* We do this to preserve the settings. If we modify the settings,
* via the _set_bit function, we will recalculate on output.
*/
ret->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); /* clear */
ret->flags |= (ASN1_STRING_FLAG_BITS_LEFT | i); /* set */
/* using one because of the bits left byte */
if (len-- > 1) {
if ((s = malloc(len)) == NULL) {
ASN1error(ERR_R_MALLOC_FAILURE);
goto err;
}
memcpy(s, p, len);
@ -166,24 +172,25 @@ c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, const unsigned char **pp, long len)
} else
s = NULL;
ret->length = (int)len;
free(ret->data);
ret->data = s;
ret->length = (int)len;
ret->type = V_ASN1_BIT_STRING;
if (a != NULL)
(*a) = ret;
*a = ret;
*pp = p;
return (ret);
err:
ASN1error(i);
if ((ret != NULL) && ((a == NULL) || (*a != ret)))
err:
if (a == NULL || *a != ret)
ASN1_BIT_STRING_free(ret);
return (NULL);
}
/* These next 2 functions from Goetz Babin-Ebell <babinebell@trustcenter.de>
*/
int
ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
{
@ -204,13 +211,10 @@ ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
if ((a->length < (w + 1)) || (a->data == NULL)) {
if (!value)
return(1); /* Don't need to set */
c = OPENSSL_realloc_clean(a->data, a->length, w + 1);
if (c == NULL) {
if ((c = recallocarray(a->data, a->length, w + 1, 1)) == NULL) {
ASN1error(ERR_R_MALLOC_FAILURE);
return 0;
}
if (w + 1 - a->length > 0)
memset(c + a->length, 0, w + 1 - a->length);
a->data = c;
a->length = w + 1;
}
@ -222,7 +226,7 @@ ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
}
int
ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n)
ASN1_BIT_STRING_get_bit(const ASN1_BIT_STRING *a, int n)
{
int w, v;
@ -240,7 +244,8 @@ ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n)
* 'len' is the length of 'flags'.
*/
int
ASN1_BIT_STRING_check(ASN1_BIT_STRING *a, unsigned char *flags, int flags_len)
ASN1_BIT_STRING_check(const ASN1_BIT_STRING *a, const unsigned char *flags,
int flags_len)
{
int i, ok;

View File

@ -1,306 +0,0 @@
/* $OpenBSD: a_bytes.c,v 1.19 2017/01/29 17:49:22 beck Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
#include <stdio.h>
#include <string.h>
#include <openssl/asn1.h>
#include <openssl/buffer.h>
#include <openssl/err.h>
static int asn1_collate_primitive(ASN1_STRING *a, ASN1_const_CTX *c);
/* type is a 'bitmap' of acceptable string types.
*/
ASN1_STRING *
d2i_ASN1_type_bytes(ASN1_STRING **a, const unsigned char **pp,
long length, int type)
{
ASN1_STRING *ret = NULL;
const unsigned char *p;
unsigned char *s;
long len;
int inf, tag, xclass;
int i = 0;
p = *pp;
inf = ASN1_get_object(&p, &len, &tag, &xclass, length);
if (inf & 0x80)
goto err;
if (tag >= 32) {
i = ASN1_R_TAG_VALUE_TOO_HIGH;
goto err;
}
if (!(ASN1_tag2bit(tag) & type)) {
i = ASN1_R_WRONG_TYPE;
goto err;
}
/* If a bit-string, exit early */
if (tag == V_ASN1_BIT_STRING)
return (d2i_ASN1_BIT_STRING(a, pp, length));
if ((a == NULL) || ((*a) == NULL)) {
if ((ret = ASN1_STRING_new()) == NULL)
return (NULL);
} else
ret = (*a);
if (len != 0) {
s = malloc(len + 1);
if (s == NULL) {
i = ERR_R_MALLOC_FAILURE;
goto err;
}
memcpy(s, p, len);
s[len]='\0';
p += len;
} else
s = NULL;
free(ret->data);
ret->length = (int)len;
ret->data = s;
ret->type = tag;
if (a != NULL)
(*a) = ret;
*pp = p;
return (ret);
err:
ASN1error(i);
if (a == NULL || *a != ret)
ASN1_STRING_free(ret);
return (NULL);
}
int
i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass)
{
int ret, r, constructed;
unsigned char *p;
if (a == NULL)
return (0);
if (tag == V_ASN1_BIT_STRING)
return (i2d_ASN1_BIT_STRING(a, pp));
ret = a->length;
r = ASN1_object_size(0, ret, tag);
if (pp == NULL)
return (r);
p = *pp;
if ((tag == V_ASN1_SEQUENCE) || (tag == V_ASN1_SET))
constructed = 1;
else
constructed = 0;
ASN1_put_object(&p, constructed, ret, tag, xclass);
memcpy(p, a->data, a->length);
p += a->length;
*pp = p;
return (r);
}
ASN1_STRING *
d2i_ASN1_bytes(ASN1_STRING **a, const unsigned char **pp,
long length, int Ptag, int Pclass)
{
ASN1_STRING *ret = NULL;
const unsigned char *p;
unsigned char *s;
long len;
int inf, tag, xclass;
int i = 0;
if ((a == NULL) || ((*a) == NULL)) {
if ((ret = ASN1_STRING_new()) == NULL)
return (NULL);
} else
ret = (*a);
p= *pp;
inf = ASN1_get_object(&p, &len, &tag, &xclass, length);
if (inf & 0x80) {
i = ASN1_R_BAD_OBJECT_HEADER;
goto err;
}
if (tag != Ptag) {
i = ASN1_R_WRONG_TAG;
goto err;
}
if (inf & V_ASN1_CONSTRUCTED) {
ASN1_const_CTX c;
c.pp = pp;
c.p = p;
c.inf = inf;
c.slen = len;
c.tag = Ptag;
c.xclass = Pclass;
c.max = (length == 0) ? 0 : (p + length);
if (!asn1_collate_primitive(ret, &c))
goto err;
else {
p = c.p;
}
} else {
if (len != 0) {
if ((ret->length < len) || (ret->data == NULL)) {
free(ret->data);
ret->data = NULL;
s = malloc(len + 1);
if (s == NULL) {
i = ERR_R_MALLOC_FAILURE;
goto err;
}
} else
s = ret->data;
memcpy(s, p, len);
s[len] = '\0';
p += len;
} else {
s = NULL;
free(ret->data);
}
ret->length = (int)len;
ret->data = s;
ret->type = Ptag;
}
if (a != NULL)
(*a) = ret;
*pp = p;
return (ret);
err:
if (a == NULL || *a != ret)
ASN1_STRING_free(ret);
ASN1error(i);
return (NULL);
}
/* We are about to parse 0..n d2i_ASN1_bytes objects, we are to collapse
* them into the one structure that is then returned */
/* There have been a few bug fixes for this function from
* Paul Keogh <paul.keogh@sse.ie>, many thanks to him */
static int
asn1_collate_primitive(ASN1_STRING *a, ASN1_const_CTX *c)
{
ASN1_STRING *os = NULL;
BUF_MEM b;
int num;
b.length = 0;
b.max = 0;
b.data = NULL;
if (a == NULL) {
c->error = ERR_R_PASSED_NULL_PARAMETER;
goto err;
}
num = 0;
for (;;) {
if (c->inf & 1) {
c->eos = ASN1_const_check_infinite_end(&c->p,
(long)(c->max - c->p));
if (c->eos)
break;
} else {
if (c->slen <= 0)
break;
}
c->q = c->p;
if (d2i_ASN1_bytes(&os, &c->p, c->max - c->p, c->tag,
c->xclass) == NULL) {
c->error = ERR_R_ASN1_LIB;
goto err;
}
if (!BUF_MEM_grow_clean(&b, num + os->length)) {
c->error = ERR_R_BUF_LIB;
goto err;
}
memcpy(&(b.data[num]), os->data, os->length);
if (!(c->inf & 1))
c->slen -= (c->p - c->q);
num += os->length;
}
if (!asn1_const_Finish(c))
goto err;
a->length = num;
free(a->data);
a->data = (unsigned char *)b.data;
ASN1_STRING_free(os);
return (1);
err:
ASN1error(c->error);
ASN1_STRING_free(os);
free(b.data);
return (0);
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: a_digest.c,v 1.15 2014/07/11 08:44:47 jsing Exp $ */
/* $OpenBSD: a_digest.c,v 1.16 2018/04/06 09:19:36 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -77,8 +77,11 @@ ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn,
if (!str)
return (0);
if (!EVP_Digest(str, i, md, len, type, NULL))
return 0;
if (!EVP_Digest(str, i, md, len, type, NULL)) {
free(str);
return (0);
}
free(str);
return (1);
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: a_enum.c,v 1.18 2017/01/29 17:49:22 beck Exp $ */
/* $OpenBSD: a_enum.c,v 1.20 2019/04/28 05:05:56 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -56,6 +56,7 @@
* [including the GNU Public Licence.]
*/
#include <limits.h>
#include <stdio.h>
#include <openssl/asn1.h>
@ -104,10 +105,10 @@ ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
}
long
ASN1_ENUMERATED_get(ASN1_ENUMERATED *a)
ASN1_ENUMERATED_get(const ASN1_ENUMERATED *a)
{
int neg = 0, i;
long r = 0;
unsigned long r = 0;
if (a == NULL)
return (0L);
@ -128,13 +129,17 @@ ASN1_ENUMERATED_get(ASN1_ENUMERATED *a)
r <<= 8;
r |= (unsigned char)a->data[i];
}
if (r > LONG_MAX)
return -1;
if (neg)
r = -r;
return (r);
return -(long)r;
return (long)r;
}
ASN1_ENUMERATED *
BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
BN_to_ASN1_ENUMERATED(const BIGNUM *bn, ASN1_ENUMERATED *ai)
{
ASN1_ENUMERATED *ret;
int len, j;
@ -177,7 +182,7 @@ err:
}
BIGNUM *
ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn)
ASN1_ENUMERATED_to_BN(const ASN1_ENUMERATED *ai, BIGNUM *bn)
{
BIGNUM *ret;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: a_int.c,v 1.31 2017/01/29 17:49:22 beck Exp $ */
/* $OpenBSD: a_int.c,v 1.34 2019/04/28 05:03:56 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -56,6 +56,7 @@
* [including the GNU Public Licence.]
*/
#include <limits.h>
#include <stdio.h>
#include <string.h>
@ -63,9 +64,18 @@
#include <openssl/bn.h>
#include <openssl/err.h>
static int
ASN1_INTEGER_valid(const ASN1_INTEGER *a)
{
return (a != NULL && a->length >= 0);
}
ASN1_INTEGER *
ASN1_INTEGER_dup(const ASN1_INTEGER *x)
{
if (!ASN1_INTEGER_valid(x))
return NULL;
return ASN1_STRING_dup(x);
}
@ -123,8 +133,9 @@ i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp)
int pad = 0, ret, i, neg;
unsigned char *p, *n, pb = 0;
if (a == NULL)
return (0);
if (!ASN1_INTEGER_valid(a))
return 0;
neg = a->type & V_ASN1_NEG;
if (a->length == 0)
ret = 1;
@ -201,11 +212,24 @@ c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, long len)
} else
ret = (*a);
if (!ASN1_INTEGER_valid(ret)) {
/*
* XXX using i for an alert is confusing,
* we should call this al
*/
i = ERR_R_ASN1_LENGTH_MISMATCH;
goto err;
}
p = *pp;
pend = p + len;
/* We must malloc stuff, even for 0 bytes otherwise it
* signifies a missing NULL parameter. */
if (len < 0 || len > INT_MAX) {
i = ERR_R_ASN1_LENGTH_MISMATCH;
goto err;
}
s = malloc(len + 1);
if (s == NULL) {
i = ERR_R_MALLOC_FAILURE;
@ -294,6 +318,11 @@ d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, long length)
} else
ret = (*a);
if (!ASN1_INTEGER_valid(ret)) {
i = ERR_R_ASN1_LENGTH_MISMATCH;
goto err;
}
p = *pp;
inf = ASN1_get_object(&p, &len, &tag, &xclass, length);
if (inf & 0x80) {
@ -308,6 +337,10 @@ d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, long length)
/* We must malloc stuff, even for 0 bytes otherwise it
* signifies a missing NULL parameter. */
if (len < 0 || len > INT_MAX) {
i = ERR_R_ASN1_LENGTH_MISMATCH;
goto err;
}
s = malloc(len + 1);
if (s == NULL) {
i = ERR_R_MALLOC_FAILURE;
@ -375,11 +408,17 @@ ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
return (1);
}
/*
* XXX this particular API is a gibbering eidrich horror that makes it
* impossible to determine valid return cases from errors.. "a bit
* ugly" is preserved for posterity, unfortunately this is probably
* unfixable without changing public API
*/
long
ASN1_INTEGER_get(const ASN1_INTEGER *a)
{
int neg = 0, i;
long r = 0;
unsigned long r = 0;
if (a == NULL)
return (0L);
@ -389,6 +428,9 @@ ASN1_INTEGER_get(const ASN1_INTEGER *a)
else if (i != V_ASN1_INTEGER)
return -1;
if (!ASN1_INTEGER_valid(a))
return -1; /* XXX best effort */
if (a->length > (int)sizeof(long)) {
/* hmm... a bit ugly, return all ones */
return -1;
@ -400,9 +442,13 @@ ASN1_INTEGER_get(const ASN1_INTEGER *a)
r <<= 8;
r |= (unsigned char)a->data[i];
}
if (r > LONG_MAX)
return -1;
if (neg)
r = -r;
return (r);
return -(long)r;
return (long)r;
}
ASN1_INTEGER *
@ -419,6 +465,10 @@ BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai)
ASN1error(ERR_R_NESTED_ASN1_ERROR);
goto err;
}
if (!ASN1_INTEGER_valid(ret))
goto err;
if (BN_is_negative(bn))
ret->type = V_ASN1_NEG_INTEGER;
else
@ -453,6 +503,9 @@ ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn)
{
BIGNUM *ret;
if (!ASN1_INTEGER_valid(ai))
return (NULL);
if ((ret = BN_bin2bn(ai->data, ai->length, bn)) == NULL)
ASN1error(ASN1_R_BN_LIB);
else if (ai->type == V_ASN1_NEG_INTEGER)

View File

@ -1,4 +1,4 @@
/* $OpenBSD: a_object.c,v 1.30 2017/05/02 03:59:44 deraadt Exp $ */
/* $OpenBSD: a_object.c,v 1.31 2018/04/25 11:48:21 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -67,7 +67,7 @@
#include <openssl/objects.h>
int
i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp)
i2d_ASN1_OBJECT(const ASN1_OBJECT *a, unsigned char **pp)
{
unsigned char *p;
int objsize;
@ -213,13 +213,13 @@ err:
}
int
i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a)
i2t_ASN1_OBJECT(char *buf, int buf_len, const ASN1_OBJECT *a)
{
return OBJ_obj2txt(buf, buf_len, a, 0);
}
int
i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a)
i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *a)
{
char *tmp = NULL;
size_t tlen = 256;

View File

@ -1,236 +0,0 @@
/* $OpenBSD: a_set.c,v 1.18 2017/01/29 17:49:22 beck Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
#include <stdio.h>
#include <string.h>
#include <openssl/asn1_mac.h>
#include <openssl/err.h>
#ifndef NO_ASN1_OLD
typedef struct {
unsigned char *pbData;
int cbData;
} MYBLOB;
/* SetBlobCmp
* This function compares two elements of SET_OF block
*/
static int
SetBlobCmp(const void *elem1, const void *elem2)
{
const MYBLOB *b1 = (const MYBLOB *)elem1;
const MYBLOB *b2 = (const MYBLOB *)elem2;
int r;
r = memcmp(b1->pbData, b2->pbData,
b1->cbData < b2->cbData ? b1->cbData : b2->cbData);
if (r != 0)
return r;
return b1->cbData - b2->cbData;
}
/* int is_set: if TRUE, then sort the contents (i.e. it isn't a SEQUENCE) */
int
i2d_ASN1_SET(STACK_OF(OPENSSL_BLOCK) *a, unsigned char **pp, i2d_of_void *i2d,
int ex_tag, int ex_class, int is_set)
{
int ret = 0, r;
int i;
unsigned char *p;
unsigned char *pStart, *pTempMem;
MYBLOB *rgSetBlob;
int totSize;
if (a == NULL)
return 0;
for (i = sk_OPENSSL_BLOCK_num(a) - 1; i >= 0; i--)
ret += i2d(sk_OPENSSL_BLOCK_value(a, i), NULL);
r = ASN1_object_size(1, ret, ex_tag);
if (pp == NULL)
return r;
p = *pp;
ASN1_put_object(&p, 1, ret, ex_tag, ex_class);
/* Modified by gp@nsj.co.jp */
/* And then again by Ben */
/* And again by Steve */
if (!is_set || (sk_OPENSSL_BLOCK_num(a) < 2)) {
for (i = 0; i < sk_OPENSSL_BLOCK_num(a); i++)
i2d(sk_OPENSSL_BLOCK_value(a, i), &p);
*pp = p;
return r;
}
pStart = p; /* Catch the beg of Setblobs*/
/* In this array we will store the SET blobs */
rgSetBlob = reallocarray(NULL, sk_OPENSSL_BLOCK_num(a), sizeof(MYBLOB));
if (rgSetBlob == NULL) {
ASN1error(ERR_R_MALLOC_FAILURE);
return 0;
}
for (i = 0; i < sk_OPENSSL_BLOCK_num(a); i++) {
rgSetBlob[i].pbData = p; /* catch each set encode blob */
i2d(sk_OPENSSL_BLOCK_value(a, i), &p);
/* Length of this SetBlob */
rgSetBlob[i].cbData = p - rgSetBlob[i].pbData;
}
*pp = p;
totSize = p - pStart; /* This is the total size of all set blobs */
/* Now we have to sort the blobs. I am using a simple algo.
* Sort ptrs
* Copy to temp-mem
* Copy from temp-mem to user-mem
*/
qsort(rgSetBlob, sk_OPENSSL_BLOCK_num(a), sizeof(MYBLOB), SetBlobCmp);
if ((pTempMem = malloc(totSize)) == NULL) {
free(rgSetBlob);
ASN1error(ERR_R_MALLOC_FAILURE);
return 0;
}
/* Copy to temp mem */
p = pTempMem;
for (i = 0; i < sk_OPENSSL_BLOCK_num(a); ++i) {
memcpy(p, rgSetBlob[i].pbData, rgSetBlob[i].cbData);
p += rgSetBlob[i].cbData;
}
/* Copy back to user mem*/
memcpy(pStart, pTempMem, totSize);
free(pTempMem);
free(rgSetBlob);
return r;
}
STACK_OF(OPENSSL_BLOCK) *
d2i_ASN1_SET(STACK_OF(OPENSSL_BLOCK) **a, const unsigned char **pp, long length,
d2i_of_void *d2i, void (*free_func)(OPENSSL_BLOCK), int ex_tag,
int ex_class)
{
ASN1_const_CTX c;
STACK_OF(OPENSSL_BLOCK) *ret = NULL;
if (a == NULL || (*a) == NULL) {
if ((ret = sk_OPENSSL_BLOCK_new_null()) == NULL) {
ASN1error(ERR_R_MALLOC_FAILURE);
goto err;
}
} else
ret = *a;
c.p = *pp;
c.max = (length == 0) ? 0 : (c.p + length);
c.inf = ASN1_get_object(&c.p, &c.slen, &c.tag, &c.xclass, c.max - c.p);
if (c.inf & 0x80)
goto err;
if (ex_class != c.xclass) {
ASN1error(ASN1_R_BAD_CLASS);
goto err;
}
if (ex_tag != c.tag) {
ASN1error(ASN1_R_BAD_TAG);
goto err;
}
if (c.slen + c.p > c.max) {
ASN1error(ASN1_R_LENGTH_ERROR);
goto err;
}
/* check for infinite constructed - it can be as long
* as the amount of data passed to us */
if (c.inf == (V_ASN1_CONSTRUCTED + 1))
c.slen = length + *pp - c.p;
c.max = c.p + c.slen;
while (c.p < c.max) {
char *s;
if (M_ASN1_D2I_end_sequence())
break;
if ((s = d2i(NULL, &c.p, c.slen)) == NULL) {
ASN1error(ASN1_R_ERROR_PARSING_SET_ELEMENT);
asn1_add_error(*pp, (int)(c.p - *pp));
goto err;
}
if (!sk_OPENSSL_BLOCK_push(ret, s))
goto err;
}
if (a != NULL)
*a = ret;
*pp = c.p;
return ret;
err:
if (a == NULL || *a != ret) {
if (free_func != NULL)
sk_OPENSSL_BLOCK_pop_free(ret, free_func);
else
sk_OPENSSL_BLOCK_free(ret);
}
return NULL;
}
#endif

View File

@ -1,4 +1,4 @@
/* $OpenBSD: a_strex.c,v 1.25 2015/02/07 13:19:15 doug Exp $ */
/* $OpenBSD: a_strex.c,v 1.28 2018/05/19 10:46:28 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2000.
*/
@ -289,7 +289,7 @@ do_hex_dump(char_io *io_ch, void *arg, unsigned char *buf, int buflen)
*/
static int
do_dump(unsigned long lflags, char_io *io_ch, void *arg, ASN1_STRING *str)
do_dump(unsigned long lflags, char_io *io_ch, void *arg, const ASN1_STRING *str)
{
/* Placing the ASN1_STRING in a temp ASN1_TYPE allows
* the DER encoding to readily obtained
@ -346,7 +346,8 @@ static const signed char tag2nbyte[] = {
*/
static int
do_print_ex(char_io *io_ch, void *arg, unsigned long lflags, ASN1_STRING *str)
do_print_ex(char_io *io_ch, void *arg, unsigned long lflags,
const ASN1_STRING *str)
{
int outlen, len;
int type;
@ -439,7 +440,7 @@ do_indent(char_io *io_ch, void *arg, int indent)
#define FN_WIDTH_SN 10
static int
do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, int indent,
do_name_ex(char_io *io_ch, void *arg, const X509_NAME *n, int indent,
unsigned long flags)
{
int i, prev = -1, orflags, cnt;
@ -581,7 +582,8 @@ do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, int indent,
/* Wrappers round the main functions */
int
X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags)
X509_NAME_print_ex(BIO *out, const X509_NAME *nm, int indent,
unsigned long flags)
{
if (flags == XN_FLAG_COMPAT)
return X509_NAME_print(out, nm, indent);
@ -589,7 +591,8 @@ X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags)
}
int
X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags)
X509_NAME_print_ex_fp(FILE *fp, const X509_NAME *nm, int indent,
unsigned long flags)
{
if (flags == XN_FLAG_COMPAT) {
BIO *btmp;
@ -605,13 +608,13 @@ X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags)
}
int
ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags)
ASN1_STRING_print_ex(BIO *out, const ASN1_STRING *str, unsigned long flags)
{
return do_print_ex(send_bio_chars, out, flags, str);
}
int
ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags)
ASN1_STRING_print_ex_fp(FILE *fp, const ASN1_STRING *str, unsigned long flags)
{
return do_print_ex(send_fp_chars, fp, flags, str);
}
@ -621,7 +624,7 @@ ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags)
*/
int
ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in)
ASN1_STRING_to_UTF8(unsigned char **out, const ASN1_STRING *in)
{
ASN1_STRING stmp, *str = &stmp;
int mbflag, type, ret;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: a_time_tm.c,v 1.14 2017/08/28 17:42:47 jsing Exp $ */
/* $OpenBSD: a_time_tm.c,v 1.15 2018/04/25 11:48:21 tb Exp $ */
/*
* Copyright (c) 2015 Bob Beck <beck@openbsd.org>
*
@ -337,7 +337,7 @@ ASN1_TIME_adj(ASN1_TIME *s, time_t t, int offset_day, long offset_sec)
}
int
ASN1_TIME_check(ASN1_TIME *t)
ASN1_TIME_check(const ASN1_TIME *t)
{
if (t->type != V_ASN1_GENERALIZEDTIME && t->type != V_ASN1_UTCTIME)
return (0);
@ -345,7 +345,7 @@ ASN1_TIME_check(ASN1_TIME *t)
}
ASN1_GENERALIZEDTIME *
ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out)
ASN1_TIME_to_generalizedtime(const ASN1_TIME *t, ASN1_GENERALIZEDTIME **out)
{
ASN1_GENERALIZEDTIME *tmp = NULL;
struct tm tm;
@ -386,7 +386,7 @@ ASN1_TIME_set_string(ASN1_TIME *s, const char *str)
*/
int
ASN1_UTCTIME_check(ASN1_UTCTIME *d)
ASN1_UTCTIME_check(const ASN1_UTCTIME *d)
{
if (d->type != V_ASN1_UTCTIME)
return (0);
@ -442,7 +442,7 @@ ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t2)
*/
int
ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d)
ASN1_GENERALIZEDTIME_check(const ASN1_GENERALIZEDTIME *d)
{
if (d->type != V_ASN1_GENERALIZEDTIME)
return (0);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: a_type.c,v 1.19 2016/05/04 15:00:24 tedu Exp $ */
/* $OpenBSD: a_type.c,v 1.21 2019/10/24 16:36:10 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -62,7 +62,7 @@
#include <openssl/objects.h>
int
ASN1_TYPE_get(ASN1_TYPE *a)
ASN1_TYPE_get(const ASN1_TYPE *a)
{
if ((a->value.ptr != NULL) || (a->type == V_ASN1_NULL))
return (a->type);
@ -108,7 +108,7 @@ ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value)
/* Returns 0 if they are equal, != 0 otherwise. */
int
ASN1_TYPE_cmp(ASN1_TYPE *a, ASN1_TYPE *b)
ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b)
{
int result = -1;
@ -154,3 +154,34 @@ ASN1_TYPE_cmp(ASN1_TYPE *a, ASN1_TYPE *b)
return result;
}
ASN1_TYPE *
ASN1_TYPE_pack_sequence(const ASN1_ITEM *it, void *s, ASN1_TYPE **t)
{
ASN1_OCTET_STRING *oct;
ASN1_TYPE *rt;
if ((oct = ASN1_item_pack(s, it, NULL)) == NULL)
return NULL;
if (t != NULL && *t != NULL) {
rt = *t;
} else {
if ((rt = ASN1_TYPE_new()) == NULL) {
ASN1_OCTET_STRING_free(oct);
return NULL;
}
if (t != NULL)
*t = rt;
}
ASN1_TYPE_set(rt, V_ASN1_SEQUENCE, oct);
return rt;
}
void *
ASN1_TYPE_unpack_sequence(const ASN1_ITEM *it, const ASN1_TYPE *t)
{
if (t == NULL || t->type != V_ASN1_SEQUENCE || t->value.sequence == NULL)
return NULL;
return ASN1_item_unpack(t->value.sequence, it);
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: ameth_lib.c,v 1.16 2017/01/21 04:31:25 jsing Exp $ */
/* $OpenBSD: ameth_lib.c,v 1.21 2019/11/02 16:06:25 inoguchi Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2006.
*/
@ -71,6 +71,7 @@
#include "asn1_locl.h"
extern const EVP_PKEY_ASN1_METHOD rsa_asn1_meths[];
extern const EVP_PKEY_ASN1_METHOD rsa_pss_asn1_meth;
extern const EVP_PKEY_ASN1_METHOD dsa_asn1_meths[];
extern const EVP_PKEY_ASN1_METHOD dh_asn1_meth;
extern const EVP_PKEY_ASN1_METHOD eckey_asn1_meth;
@ -104,6 +105,9 @@ static const EVP_PKEY_ASN1_METHOD *standard_methods[] = {
#endif
&hmac_asn1_meth,
&cmac_asn1_meth,
#ifndef OPENSSL_NO_RSA
&rsa_pss_asn1_meth,
#endif
#ifndef OPENSSL_NO_GOST
&gostr01_asn1_meths[1],
&gostr01_asn1_meths[2],
@ -299,7 +303,7 @@ EVP_PKEY_asn1_get0_info(int *ppkey_id, int *ppkey_base_id, int *ppkey_flags,
}
const EVP_PKEY_ASN1_METHOD*
EVP_PKEY_get0_asn1(EVP_PKEY *pkey)
EVP_PKEY_get0_asn1(const EVP_PKEY *pkey)
{
return pkey->ameth;
}
@ -309,59 +313,26 @@ EVP_PKEY_asn1_new(int id, int flags, const char *pem_str, const char *info)
{
EVP_PKEY_ASN1_METHOD *ameth;
ameth = calloc(1, sizeof(EVP_PKEY_ASN1_METHOD));
if (!ameth)
if ((ameth = calloc(1, sizeof(EVP_PKEY_ASN1_METHOD))) == NULL)
return NULL;
ameth->pkey_id = id;
ameth->pkey_base_id = id;
ameth->pkey_flags = flags | ASN1_PKEY_DYNAMIC;
if (info) {
ameth->info = strdup(info);
if (!ameth->info)
if (info != NULL) {
if ((ameth->info = strdup(info)) == NULL)
goto err;
} else
ameth->info = NULL;
}
if (pem_str) {
ameth->pem_str = strdup(pem_str);
if (!ameth->pem_str)
if (pem_str != NULL) {
if ((ameth->pem_str = strdup(pem_str)) == NULL)
goto err;
} else
ameth->pem_str = NULL;
ameth->pub_decode = 0;
ameth->pub_encode = 0;
ameth->pub_cmp = 0;
ameth->pub_print = 0;
ameth->priv_decode = 0;
ameth->priv_encode = 0;
ameth->priv_print = 0;
ameth->old_priv_encode = 0;
ameth->old_priv_decode = 0;
ameth->item_verify = 0;
ameth->item_sign = 0;
ameth->pkey_size = 0;
ameth->pkey_bits = 0;
ameth->param_decode = 0;
ameth->param_encode = 0;
ameth->param_missing = 0;
ameth->param_copy = 0;
ameth->param_cmp = 0;
ameth->param_print = 0;
ameth->pkey_free = 0;
ameth->pkey_ctrl = 0;
}
return ameth;
err:
err:
EVP_PKEY_asn1_free(ameth);
return NULL;
}
@ -390,6 +361,7 @@ EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst, const EVP_PKEY_ASN1_METHOD *src)
dst->param_copy = src->param_copy;
dst->param_cmp = src->param_cmp;
dst->param_print = src->param_print;
dst->sig_print = src->sig_print;
dst->pkey_free = src->pkey_free;
dst->pkey_ctrl = src->pkey_ctrl;
@ -428,7 +400,7 @@ EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth,
void
EVP_PKEY_asn1_set_private(EVP_PKEY_ASN1_METHOD *ameth,
int (*priv_decode)(EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf),
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))

View File

@ -1,4 +1,4 @@
/* $OpenBSD: asn1_err.c,v 1.20 2017/01/29 17:49:22 beck Exp $ */
/* $OpenBSD: asn1_err.c,v 1.21 2018/03/29 02:29:24 inoguchi Exp $ */
/* ====================================================================
* Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved.
*
@ -150,6 +150,7 @@ static ERR_STRING_DATA ASN1_str_reasons[] = {
{ERR_REASON(ASN1_R_MSTRING_NOT_UNIVERSAL), "mstring not universal"},
{ERR_REASON(ASN1_R_MSTRING_WRONG_TAG) , "mstring wrong tag"},
{ERR_REASON(ASN1_R_NESTED_ASN1_STRING) , "nested asn1 string"},
{ERR_REASON(ASN1_R_NESTED_TOO_DEEP) , "nested too deep"},
{ERR_REASON(ASN1_R_NON_HEX_CHARACTERS) , "non hex characters"},
{ERR_REASON(ASN1_R_NOT_ASCII_FORMAT) , "not ascii format"},
{ERR_REASON(ASN1_R_NOT_ENOUGH_DATA) , "not enough data"},

View File

@ -1,4 +1,4 @@
/* $OpenBSD: asn1_gen.c,v 1.16 2017/01/29 17:49:22 beck Exp $ */
/* $OpenBSD: asn1_gen.c,v 1.17 2018/04/25 11:48:21 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2002.
*/
@ -121,7 +121,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype);
static int asn1_str2tag(const char *tagstr, int len);
ASN1_TYPE *
ASN1_generate_nconf(char *str, CONF *nconf)
ASN1_generate_nconf(const char *str, CONF *nconf)
{
X509V3_CTX cnf;
@ -133,7 +133,7 @@ ASN1_generate_nconf(char *str, CONF *nconf)
}
ASN1_TYPE *
ASN1_generate_v3(char *str, X509V3_CTX *cnf)
ASN1_generate_v3(const char *str, X509V3_CTX *cnf)
{
ASN1_TYPE *ret;
tag_exp_arg asn1_tags;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: asn1_lib.c,v 1.40 2018/02/14 16:46:04 jsing Exp $ */
/* $OpenBSD: asn1_lib.c,v 1.44 2018/11/17 09:34:11 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -98,7 +98,7 @@ ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,
{
int i, ret;
long l;
const unsigned char *p= *pp;
const unsigned char *p = *pp;
int tag, xclass, inf;
long max = omax;
@ -106,7 +106,7 @@ ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,
goto err;
ret = (*p & V_ASN1_CONSTRUCTED);
xclass = (*p & V_ASN1_PRIVATE);
i= *p & V_ASN1_PRIMITIVE_TAG;
i = *p & V_ASN1_PRIMITIVE_TAG;
if (i == V_ASN1_PRIMITIVE_TAG) { /* high-tag */
p++;
if (--max == 0)
@ -156,7 +156,7 @@ err:
static int
asn1_get_length(const unsigned char **pp, int *inf, long *rl, int max)
{
const unsigned char *p= *pp;
const unsigned char *p = *pp;
unsigned long ret = 0;
unsigned int i;
@ -168,7 +168,7 @@ asn1_get_length(const unsigned char **pp, int *inf, long *rl, int max)
p++;
} else {
*inf = 0;
i= *p & 0x7f;
i = *p & 0x7f;
if (*(p++) & 0x80) {
if (max < (int)i)
return (0);
@ -199,7 +199,7 @@ void
ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,
int xclass)
{
unsigned char *p= *pp;
unsigned char *p = *pp;
int i, ttag;
i = (constructed) ? V_ASN1_CONSTRUCTED : 0;
@ -240,7 +240,7 @@ ASN1_put_eoc(unsigned char **pp)
static void
asn1_put_length(unsigned char **pp, int length)
{
unsigned char *p= *pp;
unsigned char *p = *pp;
int i, l;
if (length <= 127)
@ -285,62 +285,6 @@ ASN1_object_size(int constructed, int length, int tag)
return (ret);
}
static int
_asn1_Finish(ASN1_const_CTX *c)
{
if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos)) {
if (!ASN1_const_check_infinite_end(&c->p, c->slen)) {
c->error = ERR_R_MISSING_ASN1_EOS;
return (0);
}
}
if (((c->slen != 0) && !(c->inf & 1)) ||
((c->slen < 0) && (c->inf & 1))) {
c->error = ERR_R_ASN1_LENGTH_MISMATCH;
return (0);
}
return (1);
}
int
asn1_Finish(ASN1_CTX *c)
{
return _asn1_Finish((ASN1_const_CTX *)c);
}
int
asn1_const_Finish(ASN1_const_CTX *c)
{
return _asn1_Finish(c);
}
int
asn1_GetSequence(ASN1_const_CTX *c, long *length)
{
const unsigned char *q;
q = c->p;
c->inf = ASN1_get_object(&(c->p), &(c->slen), &(c->tag), &(c->xclass),
*length);
if (c->inf & 0x80) {
c->error = ERR_R_BAD_GET_ASN1_OBJECT_CALL;
return (0);
}
if (c->tag != V_ASN1_SEQUENCE) {
c->error = ERR_R_EXPECTING_AN_ASN1_SEQUENCE;
return (0);
}
(*length) -= (c->p - q);
if (c->max && (*length < 0)) {
c->error = ERR_R_ASN1_LENGTH_MISMATCH;
return (0);
}
if (c->inf == (1|V_ASN1_CONSTRUCTED))
c->slen= *length+ *(c->pp) - c->p;
c->eos = 0;
return (1);
}
int
ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str)
{
@ -394,7 +338,7 @@ ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
if (data != NULL) {
memmove(str->data, data, len);
}
str->data[str->length]='\0';
str->data[str->length] = '\0';
return (1);
}
@ -474,7 +418,7 @@ ASN1_STRING_length_set(ASN1_STRING *x, int len)
}
int
ASN1_STRING_type(ASN1_STRING *x)
ASN1_STRING_type(const ASN1_STRING *x)
{
return (x->type);
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: asn1_locl.h,v 1.10 2017/08/27 01:39:26 beck Exp $ */
/* $OpenBSD: asn1_locl.h,v 1.12 2019/10/24 16:36:10 jsing Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2006.
*/
@ -60,6 +60,9 @@ __BEGIN_HIDDEN_DECLS
/* Internal ASN1 structures and functions: not for application use */
ASN1_TYPE *ASN1_TYPE_pack_sequence(const ASN1_ITEM *it, void *s, ASN1_TYPE **t);
void *ASN1_TYPE_unpack_sequence(const ASN1_ITEM *it, const ASN1_TYPE *t);
/* ASN1 print context structure */
struct asn1_pctx_st {
@ -86,7 +89,7 @@ struct evp_pkey_asn1_method_st {
int (*pub_print)(BIO *out, const EVP_PKEY *pkey, int indent,
ASN1_PCTX *pctx);
int (*priv_decode)(EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf);
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);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: asn1_par.c,v 1.25 2015/09/30 19:01:14 jsing Exp $ */
/* $OpenBSD: asn1_par.c,v 1.28 2020/01/09 11:27:21 inoguchi Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -123,6 +123,8 @@ asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offset,
int nl, hl, j, r;
ASN1_OBJECT *o = NULL;
ASN1_OCTET_STRING *os = NULL;
ASN1_INTEGER *ai = NULL;
ASN1_ENUMERATED *ae = NULL;
/* ASN1_BMPSTRING *bmp=NULL;*/
int dump_indent;
@ -130,6 +132,10 @@ asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offset,
p = *pp;
tot = p + length;
op = p - 1;
if (depth > 128) {
BIO_printf(bp, "Max depth exceeded\n");
goto end;
}
while ((p < tot) && (op < p)) {
op = p;
j = ASN1_get_object(&p, &len, &tag, &xclass, length);
@ -177,12 +183,14 @@ asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offset,
ret = 0;
goto end;
}
if ((r == 2) || (p >= tot))
if ((r == 2) || (p >= tot)) {
len = (long)(p - ep);
break;
}
}
} else
} else {
while (p < ep) {
r = asn1_parse2(bp, &p, (long)len,
r = asn1_parse2(bp, &p, (long)(ep - p),
offset + (p - *pp), depth + 1,
indent, dump);
if (r == 0) {
@ -190,6 +198,7 @@ asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offset,
goto end;
}
}
}
} else if (xclass != 0) {
p += len;
if (BIO_write(bp, "\n", 1) <= 0)
@ -289,23 +298,22 @@ asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offset,
ASN1_OCTET_STRING_free(os);
os = NULL;
} else if (tag == V_ASN1_INTEGER) {
ASN1_INTEGER *bs;
int i;
opp = op;
bs = d2i_ASN1_INTEGER(NULL, &opp, len + hl);
if (bs != NULL) {
ai = d2i_ASN1_INTEGER(NULL, &opp, len + hl);
if (ai != NULL) {
if (BIO_write(bp, ":", 1) <= 0)
goto end;
if (bs->type == V_ASN1_NEG_INTEGER)
if (ai->type == V_ASN1_NEG_INTEGER)
if (BIO_write(bp, "-", 1) <= 0)
goto end;
for (i = 0; i < bs->length; i++) {
for (i = 0; i < ai->length; i++) {
if (BIO_printf(bp, "%02X",
bs->data[i]) <= 0)
ai->data[i]) <= 0)
goto end;
}
if (bs->length == 0) {
if (ai->length == 0) {
if (BIO_write(bp, "00", 2) <= 0)
goto end;
}
@ -313,25 +321,25 @@ asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offset,
if (BIO_write(bp, "BAD INTEGER", 11) <= 0)
goto end;
}
ASN1_INTEGER_free(bs);
ASN1_INTEGER_free(ai);
ai = NULL;
} else if (tag == V_ASN1_ENUMERATED) {
ASN1_ENUMERATED *bs;
int i;
opp = op;
bs = d2i_ASN1_ENUMERATED(NULL, &opp, len + hl);
if (bs != NULL) {
ae = d2i_ASN1_ENUMERATED(NULL, &opp, len + hl);
if (ae != NULL) {
if (BIO_write(bp, ":", 1) <= 0)
goto end;
if (bs->type == V_ASN1_NEG_ENUMERATED)
if (ae->type == V_ASN1_NEG_ENUMERATED)
if (BIO_write(bp, "-", 1) <= 0)
goto end;
for (i = 0; i < bs->length; i++) {
for (i = 0; i < ae->length; i++) {
if (BIO_printf(bp, "%02X",
bs->data[i]) <= 0)
ae->data[i]) <= 0)
goto end;
}
if (bs->length == 0) {
if (ae->length == 0) {
if (BIO_write(bp, "00", 2) <= 0)
goto end;
}
@ -339,7 +347,8 @@ asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offset,
if (BIO_write(bp, "BAD ENUMERATED", 14) <= 0)
goto end;
}
ASN1_ENUMERATED_free(bs);
ASN1_ENUMERATED_free(ae);
ae = NULL;
} else if (len > 0 && dump) {
if (!nl) {
if (BIO_write(bp, "\n", 1) <= 0)
@ -370,6 +379,8 @@ end:
if (o != NULL)
ASN1_OBJECT_free(o);
ASN1_OCTET_STRING_free(os);
ASN1_INTEGER_free(ai);
ASN1_ENUMERATED_free(ae);
*pp = p;
return (ret);
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: asn_pack.c,v 1.16 2017/01/29 17:49:22 beck Exp $ */
/* $OpenBSD: asn_pack.c,v 1.18 2018/10/24 17:57:22 jsing Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 1999.
*/
@ -61,112 +61,7 @@
#include <openssl/asn1.h>
#include <openssl/err.h>
#ifndef NO_ASN1_OLD
/* ASN1 packing and unpacking functions */
/* Turn an ASN1 encoded SEQUENCE OF into a STACK of structures */
STACK_OF(OPENSSL_BLOCK) *
ASN1_seq_unpack(const unsigned char *buf, int len, d2i_of_void *d2i,
void (*free_func)(OPENSSL_BLOCK))
{
STACK_OF(OPENSSL_BLOCK) *sk;
const unsigned char *pbuf;
pbuf = buf;
if (!(sk = d2i_ASN1_SET(NULL, &pbuf, len, d2i, free_func,
V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL)))
ASN1error(ASN1_R_DECODE_ERROR);
return sk;
}
/* Turn a STACK structures into an ASN1 encoded SEQUENCE OF structure in a
* OPENSSL_malloc'ed buffer
*/
unsigned char *
ASN1_seq_pack(STACK_OF(OPENSSL_BLOCK) *safes, i2d_of_void *i2d,
unsigned char **buf, int *len)
{
int safelen;
unsigned char *safe, *p;
if (!(safelen = i2d_ASN1_SET(safes, NULL, i2d, V_ASN1_SEQUENCE,
V_ASN1_UNIVERSAL, IS_SEQUENCE))) {
ASN1error(ASN1_R_ENCODE_ERROR);
return NULL;
}
if (!(safe = malloc(safelen))) {
ASN1error(ERR_R_MALLOC_FAILURE);
return NULL;
}
p = safe;
i2d_ASN1_SET(safes, &p, i2d, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL,
IS_SEQUENCE);
if (len)
*len = safelen;
if (buf)
*buf = safe;
return safe;
}
/* Extract an ASN1 object from an ASN1_STRING */
void *
ASN1_unpack_string(ASN1_STRING *oct, d2i_of_void *d2i)
{
const unsigned char *p;
char *ret;
p = oct->data;
if (!(ret = d2i(NULL, &p, oct->length)))
ASN1error(ASN1_R_DECODE_ERROR);
return ret;
}
/* Pack an ASN1 object into an ASN1_STRING */
ASN1_STRING *
ASN1_pack_string(void *obj, i2d_of_void *i2d, ASN1_STRING **oct)
{
unsigned char *p;
ASN1_STRING *octmp;
if (!oct || !*oct) {
if (!(octmp = ASN1_STRING_new())) {
ASN1error(ERR_R_MALLOC_FAILURE);
return NULL;
}
} else
octmp = *oct;
if (!(octmp->length = i2d(obj, NULL))) {
ASN1error(ASN1_R_ENCODE_ERROR);
goto err;
}
if (!(p = malloc (octmp->length))) {
ASN1error(ERR_R_MALLOC_FAILURE);
goto err;
}
octmp->data = p;
i2d (obj, &p);
if (oct)
*oct = octmp;
return octmp;
err:
if (!oct || octmp != *oct) {
ASN1_STRING_free(octmp);
if (oct)
*oct = NULL;
}
return NULL;
}
#endif
/* ASN1_ITEM versions of the above */
/* Pack an ASN1 object into an ASN1_STRING. */
ASN1_STRING *
ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct)
{
@ -200,10 +95,9 @@ err:
return NULL;
}
/* Extract an ASN1 object from an ASN1_STRING */
/* Extract an ASN1 object from an ASN1_STRING. */
void *
ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it)
ASN1_item_unpack(const ASN1_STRING *oct, const ASN1_ITEM *it)
{
const unsigned char *p;
void *ret;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: bio_asn1.c,v 1.12 2015/12/23 01:46:33 mmcc Exp $ */
/* $OpenBSD: bio_asn1.c,v 1.13 2018/05/01 13:29:09 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project.
*/
@ -125,7 +125,7 @@ static int asn1_bio_setup_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx,
asn1_ps_func *setup, asn1_bio_state_t ex_state,
asn1_bio_state_t other_state);
static BIO_METHOD methods_asn1 = {
static const BIO_METHOD methods_asn1 = {
.type = BIO_TYPE_ASN1,
.name = "asn1",
.bwrite = asn1_bio_write,
@ -138,7 +138,7 @@ static BIO_METHOD methods_asn1 = {
.callback_ctrl = asn1_bio_callback_ctrl
};
BIO_METHOD *
const BIO_METHOD *
BIO_f_asn1(void)
{
return (&methods_asn1);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: d2i_pr.c,v 1.15 2017/01/29 17:49:22 beck Exp $ */
/* $OpenBSD: d2i_pr.c,v 1.17 2019/04/10 16:23:55 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -76,6 +76,7 @@
EVP_PKEY *
d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, long length)
{
const unsigned char *p = *pp;
EVP_PKEY *ret;
if ((a == NULL) || (*a == NULL)) {
@ -86,10 +87,8 @@ d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, long length)
} else {
ret = *a;
#ifndef OPENSSL_NO_ENGINE
if (ret->engine) {
ENGINE_finish(ret->engine);
ret->engine = NULL;
}
ENGINE_finish(ret->engine);
ret->engine = NULL;
#endif
}
@ -102,6 +101,7 @@ d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, long length)
!ret->ameth->old_priv_decode(ret, pp, length)) {
if (ret->ameth->priv_decode) {
PKCS8_PRIV_KEY_INFO *p8 = NULL;
*pp = p; /* XXX */
p8 = d2i_PKCS8_PRIV_KEY_INFO(NULL, pp, length);
if (!p8)
goto err;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: evp_asn1.c,v 1.20 2017/11/28 16:51:21 jsing Exp $ */
/* $OpenBSD: evp_asn1.c,v 1.23 2018/11/09 04:20:27 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -64,7 +64,7 @@
#include <openssl/err.h>
int
ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len)
ASN1_TYPE_set_octetstring(ASN1_TYPE *a, const unsigned char *data, int len)
{
ASN1_STRING *os;
@ -79,7 +79,7 @@ ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len)
}
int
ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data, int max_len)
ASN1_TYPE_get_octetstring(const ASN1_TYPE *a, unsigned char *data, int max_len)
{
int ret, num;
unsigned char *p;
@ -127,7 +127,7 @@ const ASN1_ITEM ASN1_INT_OCTETSTRING_it = {
};
int
ASN1_TYPE_set_int_octetstring(ASN1_TYPE *at, long num, unsigned char *data,
ASN1_TYPE_set_int_octetstring(ASN1_TYPE *at, long num, const unsigned char *data,
int len)
{
ASN1_int_octetstring *ios;
@ -137,12 +137,8 @@ ASN1_TYPE_set_int_octetstring(ASN1_TYPE *at, long num, unsigned char *data,
if ((ios = (ASN1_int_octetstring *)ASN1_item_new(
&ASN1_INT_OCTETSTRING_it)) == NULL)
goto err;
if ((ios->num = ASN1_INTEGER_new()) == NULL)
goto err;
if (!ASN1_INTEGER_set(ios->num, num))
goto err;
if ((ios->value = ASN1_OCTET_STRING_new()) == NULL)
goto err;
if (!ASN1_OCTET_STRING_set(ios->value, data, len))
goto err;
@ -162,7 +158,7 @@ ASN1_TYPE_set_int_octetstring(ASN1_TYPE *at, long num, unsigned char *data,
}
int
ASN1_TYPE_get_int_octetstring(ASN1_TYPE *at, long *num, unsigned char *data,
ASN1_TYPE_get_int_octetstring(const ASN1_TYPE *at, long *num, unsigned char *data,
int max_len)
{
ASN1_STRING *sp = at->value.sequence;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: f_enum.c,v 1.15 2017/01/29 17:49:22 beck Exp $ */
/* $OpenBSD: f_enum.c,v 1.16 2018/04/25 11:48:21 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -65,7 +65,7 @@
/* Based on a_int.c: equivalent ENUMERATED functions */
int
i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a)
i2a_ASN1_ENUMERATED(BIO *bp, const ASN1_ENUMERATED *a)
{
int i, n = 0;
static const char h[] = "0123456789ABCDEF";

View File

@ -1,4 +1,4 @@
/* $OpenBSD: f_int.c,v 1.18 2017/01/29 17:49:22 beck Exp $ */
/* $OpenBSD: f_int.c,v 1.20 2018/05/13 13:48:08 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -63,7 +63,7 @@
#include <openssl/err.h>
int
i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a)
i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a)
{
int i, n = 0;
static const char h[] = "0123456789ABCDEF";
@ -158,8 +158,7 @@ a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)
}
i /= 2;
if (num + i > slen) {
sp = OPENSSL_realloc_clean(s, slen, num + i);
if (sp == NULL) {
if ((sp = recallocarray(s, slen, num + i, 1)) == NULL) {
ASN1error(ERR_R_MALLOC_FAILURE);
goto err;
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: f_string.c,v 1.17 2017/01/29 17:49:22 beck Exp $ */
/* $OpenBSD: f_string.c,v 1.18 2018/04/25 11:48:21 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -63,7 +63,7 @@
#include <openssl/err.h>
int
i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type)
i2a_ASN1_STRING(BIO *bp, const ASN1_STRING *a, int type)
{
int i, n = 0;
static const char h[] = "0123456789ABCDEF";

View File

@ -1,4 +1,4 @@
/* $OpenBSD: n_pkey.c,v 1.31 2017/01/29 17:49:22 beck Exp $ */
/* $OpenBSD: n_pkey.c,v 1.32 2018/08/05 13:35:45 bcook Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -273,11 +273,11 @@ i2d_RSA_NET(const RSA *a, unsigned char **pp,
goto err;
}
enckey->enckey->digest->data = zz;
if (!ASN1_STRING_set(enckey->os, "private-key", -1)) {
ASN1error(ERR_R_MALLOC_FAILURE);
goto err;
}
enckey->enckey->digest->data = zz;
i2d_NETSCAPE_PKEY(pkey, &zz);
/* Wipe the private key encoding */

View File

@ -1,4 +1,4 @@
/* $OpenBSD: p8_pkey.c,v 1.17 2015/09/10 15:56:25 jsing Exp $ */
/* $OpenBSD: p8_pkey.c,v 1.19 2018/08/24 20:17:33 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 1999.
*/
@ -69,11 +69,8 @@ pkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
/* Since the structure must still be valid use ASN1_OP_FREE_PRE */
if (operation == ASN1_OP_FREE_PRE) {
PKCS8_PRIV_KEY_INFO *key = (PKCS8_PRIV_KEY_INFO *)*pval;
if (key->pkey != NULL &&
key->pkey->type == V_ASN1_OCTET_STRING &&
key->pkey->value.octet_string != NULL)
explicit_bzero(key->pkey->value.octet_string->data,
key->pkey->value.octet_string->length);
if (key->pkey != NULL)
explicit_bzero(key->pkey->data, key->pkey->length);
}
return 1;
}
@ -95,7 +92,7 @@ static const ASN1_TEMPLATE PKCS8_PRIV_KEY_INFO_seq_tt[] = {
{
.offset = offsetof(PKCS8_PRIV_KEY_INFO, pkey),
.field_name = "pkey",
.item = &ASN1_ANY_it,
.item = &ASN1_OCTET_STRING_it,
},
{
.flags = ASN1_TFLG_IMPLICIT | ASN1_TFLG_SET_OF | ASN1_TFLG_OPTIONAL,
@ -145,57 +142,45 @@ int
PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj, int version,
int ptype, void *pval, unsigned char *penc, int penclen)
{
unsigned char **ppenc = NULL;
if (version >= 0) {
if (!ASN1_INTEGER_set(priv->version, version))
return 0;
}
if (penc) {
int pmtype;
ASN1_OCTET_STRING *oct;
oct = ASN1_OCTET_STRING_new();
if (!oct)
return 0;
oct->data = penc;
ppenc = &oct->data;
oct->length = penclen;
if (priv->broken == PKCS8_NO_OCTET)
pmtype = V_ASN1_SEQUENCE;
else
pmtype = V_ASN1_OCTET_STRING;
ASN1_TYPE_set(priv->pkey, pmtype, oct);
}
if (!X509_ALGOR_set0(priv->pkeyalg, aobj, ptype, pval)) {
/* If call fails do not swallow 'enc' */
if (ppenc)
*ppenc = NULL;
if (!X509_ALGOR_set0(priv->pkeyalg, aobj, ptype, pval))
return 0;
}
if (penc != NULL)
ASN1_STRING_set0(priv->pkey, penc, penclen);
return 1;
}
int
PKCS8_pkey_get0(ASN1_OBJECT **ppkalg, const unsigned char **pk, int *ppklen,
X509_ALGOR **pa, PKCS8_PRIV_KEY_INFO *p8)
PKCS8_pkey_get0(const ASN1_OBJECT **ppkalg, const unsigned char **pk,
int *ppklen, const X509_ALGOR **pa, const PKCS8_PRIV_KEY_INFO *p8)
{
if (ppkalg)
if (ppkalg != NULL)
*ppkalg = p8->pkeyalg->algorithm;
if (p8->pkey->type == V_ASN1_OCTET_STRING) {
p8->broken = PKCS8_OK;
if (pk) {
*pk = p8->pkey->value.octet_string->data;
*ppklen = p8->pkey->value.octet_string->length;
}
} else if (p8->pkey->type == V_ASN1_SEQUENCE) {
p8->broken = PKCS8_NO_OCTET;
if (pk) {
*pk = p8->pkey->value.sequence->data;
*ppklen = p8->pkey->value.sequence->length;
}
} else
return 0;
if (pa)
if (pk != NULL) {
*pk = ASN1_STRING_data(p8->pkey);
*ppklen = ASN1_STRING_length(p8->pkey);
}
if (pa != NULL)
*pa = p8->pkeyalg;
return 1;
}
const STACK_OF(X509_ATTRIBUTE) *
PKCS8_pkey_get0_attrs(const PKCS8_PRIV_KEY_INFO *p8)
{
return p8->attributes;
}
int
PKCS8_pkey_add1_attr_by_NID(PKCS8_PRIV_KEY_INFO *p8, int nid, int type,
const unsigned char *bytes, int len)
{
if (X509at_add1_attr_by_NID(&p8->attributes, nid, type, bytes,
len) != NULL)
return 1;
return 0;
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: t_bitst.c,v 1.7 2014/07/11 08:44:47 jsing Exp $ */
/* $OpenBSD: t_bitst.c,v 1.8 2018/04/25 11:48:21 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 1999.
*/
@ -83,7 +83,7 @@ ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
}
int
ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value,
ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, const char *name, int value,
BIT_STRING_BITNAME *tbl)
{
int bitnum;
@ -99,7 +99,7 @@ ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value,
}
int
ASN1_BIT_STRING_num_asc(char *name, BIT_STRING_BITNAME *tbl)
ASN1_BIT_STRING_num_asc(const char *name, BIT_STRING_BITNAME *tbl)
{
BIT_STRING_BITNAME *bnam;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: t_crl.c,v 1.17 2017/01/29 17:49:22 beck Exp $ */
/* $OpenBSD: t_crl.c,v 1.18 2019/05/12 15:56:31 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 1999.
*/
@ -57,6 +57,7 @@
*/
#include <stdio.h>
#include <limits.h>
#include <openssl/bn.h>
#include <openssl/buffer.h>
@ -92,6 +93,8 @@ X509_CRL_print(BIO *out, X509_CRL *x)
BIO_printf(out, "Certificate Revocation List (CRL):\n");
l = X509_CRL_get_version(x);
if (l < 0 || l == LONG_MAX)
goto err;
BIO_printf(out, "%8sVersion %lu (0x%lx)\n", "", l + 1, l);
i = OBJ_obj2nid(x->sig_alg->algorithm);
if (X509_signature_print(out, x->sig_alg, NULL) == 0)

View File

@ -1,4 +1,4 @@
/* $OpenBSD: t_x509.c,v 1.28 2017/04/03 15:52:59 beck Exp $ */
/* $OpenBSD: t_x509.c,v 1.32 2020/04/10 07:05:24 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -145,8 +145,10 @@ X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag)
goto err;
bs = X509_get_serialNumber(x);
if (bs->length <= (int)sizeof(long)) {
l = -1;
if (bs->length <= (int)sizeof(long))
l = ASN1_INTEGER_get(bs);
if (l != -1) {
if (bs->type == V_ASN1_NEG_INTEGER) {
l = -l;
neg = "-";
@ -246,7 +248,8 @@ err:
return (ret);
}
int X509_ocspid_print (BIO *bp, X509 *x)
int
X509_ocspid_print(BIO *bp, X509 *x)
{
unsigned char *der = NULL;
unsigned char *dertmp;
@ -320,7 +323,7 @@ X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent)
}
int
X509_signature_print(BIO *bp, X509_ALGOR *sigalg, ASN1_STRING *sig)
X509_signature_print(BIO *bp, const X509_ALGOR *sigalg, const ASN1_STRING *sig)
{
int sig_nid;
if (BIO_puts(bp, " Signature Algorithm: ") <= 0)
@ -387,7 +390,7 @@ ASN1_TIME_print(BIO *bp, const ASN1_TIME *tm)
}
static const char *mon[12] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
@ -489,7 +492,7 @@ err:
}
int
X509_NAME_print(BIO *bp, X509_NAME *name, int obase)
X509_NAME_print(BIO *bp, const X509_NAME *name, int obase)
{
char *s, *c, *b;
int ret = 0, l, i;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: tasn_dec.c,v 1.34 2017/01/29 17:49:22 beck Exp $ */
/* $OpenBSD: tasn_dec.c,v 1.37 2019/04/01 15:48:04 jsing Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2000.
*/
@ -65,6 +65,12 @@
#include <openssl/buffer.h>
#include <openssl/err.h>
/* Constructed types with a recursive definition (such as can be found in PKCS7)
* could eventually exceed the stack given malicious input with excessive
* recursion. Therefore we limit the stack depth.
*/
#define ASN1_MAX_CONSTRUCTED_NEST 30
static int asn1_check_eoc(const unsigned char **in, long len);
static int asn1_find_end(const unsigned char **in, long len, char inf);
@ -78,9 +84,9 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
int expclass, char opt, ASN1_TLC *ctx);
static int asn1_template_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
long len, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx);
long len, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx, int depth);
static int asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in,
long len, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx);
long len, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx, int depth);
static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, const unsigned char **in,
long len, const ASN1_ITEM *it, int tag, int aclass, char opt,
ASN1_TLC *ctx);
@ -142,7 +148,7 @@ ASN1_template_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
ASN1_TLC c;
asn1_tlc_clear_nc(&c);
return asn1_template_ex_d2i(pval, in, len, tt, 0, &c);
return asn1_template_ex_d2i(pval, in, len, tt, 0, &c, 0);
}
@ -150,14 +156,15 @@ ASN1_template_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
* If 'opt' set and tag mismatch return -1 to handle OPTIONAL
*/
int
ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx)
static int
asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx,
int depth)
{
const ASN1_TEMPLATE *tt, *errtt = NULL;
const ASN1_EXTERN_FUNCS *ef;
const ASN1_AUX *aux = it->funcs;
ASN1_aux_cb *asn1_cb;
ASN1_aux_cb *asn1_cb = NULL;
const unsigned char *p = NULL, *q;
unsigned char oclass;
char seq_eoc, seq_nolen, cst, isopt;
@ -176,8 +183,11 @@ ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
if (aux && aux->asn1_cb)
asn1_cb = aux->asn1_cb;
else
asn1_cb = 0;
if (++depth > ASN1_MAX_CONSTRUCTED_NEST) {
ASN1error(ASN1_R_NESTED_TOO_DEEP);
goto err;
}
switch (it->itype) {
case ASN1_ITYPE_PRIMITIVE:
@ -193,7 +203,7 @@ ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
goto err;
}
return asn1_template_ex_d2i(pval, in, len,
it->templates, opt, ctx);
it->templates, opt, ctx, depth);
}
return asn1_d2i_ex_primitive(pval, in, len, it,
tag, aclass, opt, ctx);
@ -258,7 +268,8 @@ ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
/* We mark field as OPTIONAL so its absence
* can be recognised.
*/
ret = asn1_template_ex_d2i(pchptr, &p, len, tt, 1, ctx);
ret = asn1_template_ex_d2i(pchptr, &p, len, tt, 1, ctx,
depth);
/* If field not present, try the next one */
if (ret == -1)
continue;
@ -376,7 +387,7 @@ ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
* OPTIONAL */
ret = asn1_template_ex_d2i(pseqval, &p, len,
seqtt, isopt, ctx);
seqtt, isopt, ctx, depth);
if (!ret) {
errtt = seqtt;
goto err;
@ -448,13 +459,20 @@ err:
return 0;
}
int
ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx)
{
return asn1_item_ex_d2i(pval, in, len, it, tag, aclass, opt, ctx, 0);
}
/* Templates are handled with two separate functions.
* One handles any EXPLICIT tag and the other handles the rest.
*/
static int
asn1_template_ex_d2i(ASN1_VALUE **val, const unsigned char **in, long inlen,
const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx)
const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx, int depth)
{
int flags, aclass;
int ret;
@ -489,7 +507,7 @@ asn1_template_ex_d2i(ASN1_VALUE **val, const unsigned char **in, long inlen,
return 0;
}
/* We've found the field so it can't be OPTIONAL now */
ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx);
ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx, depth);
if (!ret) {
ASN1error(ERR_R_NESTED_ASN1_ERROR);
return 0;
@ -511,7 +529,8 @@ asn1_template_ex_d2i(ASN1_VALUE **val, const unsigned char **in, long inlen,
}
}
} else
return asn1_template_noexp_d2i(val, in, inlen, tt, opt, ctx);
return asn1_template_noexp_d2i(val, in, inlen, tt, opt, ctx,
depth);
*in = p;
return 1;
@ -523,7 +542,7 @@ err:
static int
asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in, long len,
const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx)
const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx, int depth)
{
int flags, aclass;
int ret;
@ -594,8 +613,8 @@ asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in, long len,
break;
}
skfield = NULL;
if (!ASN1_item_ex_d2i(&skfield, &p, len,
tt->item, -1, 0, 0, ctx)) {
if (!asn1_item_ex_d2i(&skfield, &p, len,
tt->item, -1, 0, 0, ctx, depth)) {
ASN1error(ERR_R_NESTED_ASN1_ERROR);
goto err;
}
@ -612,8 +631,8 @@ asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in, long len,
}
} else if (flags & ASN1_TFLG_IMPTAG) {
/* IMPLICIT tagging */
ret = ASN1_item_ex_d2i(val, &p, len,
tt->item, tt->tag, aclass, opt, ctx);
ret = asn1_item_ex_d2i(val, &p, len,
tt->item, tt->tag, aclass, opt, ctx, depth);
if (!ret) {
ASN1error(ERR_R_NESTED_ASN1_ERROR);
goto err;
@ -621,8 +640,8 @@ asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in, long len,
return -1;
} else {
/* Nothing special */
ret = ASN1_item_ex_d2i(val, &p, len, tt->item,
-1, tt->flags & ASN1_TFLG_COMBINE, opt, ctx);
ret = asn1_item_ex_d2i(val, &p, len, tt->item,
-1, tt->flags & ASN1_TFLG_COMBINE, opt, ctx, depth);
if (!ret) {
ASN1error(ERR_R_NESTED_ASN1_ERROR);
goto err;
@ -774,14 +793,17 @@ asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype,
ASN1_VALUE **opval = NULL;
ASN1_STRING *stmp;
ASN1_TYPE *typ = NULL;
int ret = 0;
const ASN1_PRIMITIVE_FUNCS *pf;
ASN1_INTEGER **tint;
int ret = 0;
pf = it->funcs;
if (it->funcs != NULL) {
const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;
if (pf && pf->prim_c2i)
if (pf->prim_c2i == NULL)
return 0;
return pf->prim_c2i(pval, cont, len, utype, free_cont, it);
}
/* If ANY type clear type and set pointer to internal value */
if (it->utype == V_ASN1_ANY) {
if (!*pval) {

View File

@ -1,4 +1,4 @@
/* $OpenBSD: tasn_enc.c,v 1.21 2016/12/30 16:04:34 jsing Exp $ */
/* $OpenBSD: tasn_enc.c,v 1.22 2019/04/01 15:48:04 jsing Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2000.
*/
@ -541,11 +541,14 @@ asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
const unsigned char *cont;
unsigned char c;
int len;
const ASN1_PRIMITIVE_FUNCS *pf;
pf = it->funcs;
if (pf && pf->prim_i2c)
if (it->funcs != NULL) {
const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;
if (pf->prim_i2c == NULL)
return -1;
return pf->prim_i2c(pval, cout, putype, it);
}
/* Should type be omitted? */
if ((it->itype != ASN1_ITYPE_PRIMITIVE) ||

View File

@ -1,4 +1,4 @@
/* $OpenBSD: tasn_fre.c,v 1.15 2016/12/30 16:04:34 jsing Exp $ */
/* $OpenBSD: tasn_fre.c,v 1.17 2019/04/01 15:48:04 jsing Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2000.
*/
@ -88,7 +88,10 @@ asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
ASN1_aux_cb *asn1_cb = NULL;
int i;
if (pval == NULL || *pval == NULL)
if (pval == NULL)
return;
/* For primitive types *pval may be something other than C pointer. */
if (it->itype != ASN1_ITYPE_PRIMITIVE && *pval == NULL)
return;
if (aux != NULL && aux->asn1_cb != NULL)
@ -190,14 +193,14 @@ void
ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
{
int utype;
if (it) {
const ASN1_PRIMITIVE_FUNCS *pf;
pf = it->funcs;
if (pf && pf->prim_free) {
pf->prim_free(pval, it);
return;
}
if (it != NULL && it->funcs != NULL) {
const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;
pf->prim_free(pval, it);
return;
}
/* Special case: if 'it' is NULL free contents of ASN1_TYPE */
if (!it) {
ASN1_TYPE *typ = (ASN1_TYPE *)*pval;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: tasn_new.c,v 1.17 2017/01/29 17:49:22 beck Exp $ */
/* $OpenBSD: tasn_new.c,v 1.18 2019/04/01 15:48:04 jsing Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2000.
*/
@ -306,10 +306,12 @@ ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
ASN1_STRING *str;
int utype;
if (it && it->funcs) {
if (it != NULL && it->funcs != NULL) {
const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;
if (pf->prim_new)
return pf->prim_new(pval, it);
if (pf->prim_new == NULL)
return 0;
return pf->prim_new(pval, it);
}
if (!it || (it->itype == ASN1_ITYPE_MSTRING))
@ -355,14 +357,17 @@ static void
asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
{
int utype;
if (it && it->funcs) {
if (it != NULL && it->funcs != NULL) {
const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;
if (pf->prim_clear)
pf->prim_clear(pval, it);
else
*pval = NULL;
return;
}
if (!it || (it->itype == ASN1_ITYPE_MSTRING))
utype = V_ASN1_UNDEF;
else

View File

@ -1,4 +1,4 @@
/* $OpenBSD: tasn_prn.c,v 1.16 2017/01/29 17:49:22 beck Exp $ */
/* $OpenBSD: tasn_prn.c,v 1.21 2020/03/24 10:46:38 inoguchi Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2000.
*/
@ -105,7 +105,7 @@ ASN1_PCTX_free(ASN1_PCTX *p)
}
unsigned long
ASN1_PCTX_get_flags(ASN1_PCTX *p)
ASN1_PCTX_get_flags(const ASN1_PCTX *p)
{
return p->flags;
}
@ -117,7 +117,7 @@ ASN1_PCTX_set_flags(ASN1_PCTX *p, unsigned long flags)
}
unsigned long
ASN1_PCTX_get_nm_flags(ASN1_PCTX *p)
ASN1_PCTX_get_nm_flags(const ASN1_PCTX *p)
{
return p->nm_flags;
}
@ -129,7 +129,7 @@ ASN1_PCTX_set_nm_flags(ASN1_PCTX *p, unsigned long flags)
}
unsigned long
ASN1_PCTX_get_cert_flags(ASN1_PCTX *p)
ASN1_PCTX_get_cert_flags(const ASN1_PCTX *p)
{
return p->cert_flags;
}
@ -141,7 +141,7 @@ ASN1_PCTX_set_cert_flags(ASN1_PCTX *p, unsigned long flags)
}
unsigned long
ASN1_PCTX_get_oid_flags(ASN1_PCTX *p)
ASN1_PCTX_get_oid_flags(const ASN1_PCTX *p)
{
return p->oid_flags;
}
@ -153,7 +153,7 @@ ASN1_PCTX_set_oid_flags(ASN1_PCTX *p, unsigned long flags)
}
unsigned long
ASN1_PCTX_get_str_flags(ASN1_PCTX *p)
ASN1_PCTX_get_str_flags(const ASN1_PCTX *p)
{
return p->str_flags;
}
@ -216,7 +216,8 @@ asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, const ASN1_ITEM *it,
} else
asn1_cb = NULL;
if (*fld == NULL) {
if ((it->itype != ASN1_ITYPE_PRIMITIVE ||
it->utype != V_ASN1_BOOLEAN) && *fld == NULL) {
if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_ABSENT) {
if (!nohdr &&
!asn1_print_fsname(out, indent, fname, sname, pctx))
@ -454,7 +455,8 @@ asn1_print_integer_ctx(BIO *out, ASN1_INTEGER *str, const ASN1_PCTX *pctx)
{
char *s;
int ret = 1;
s = i2s_ASN1_INTEGER(NULL, str);
if ((s = i2s_ASN1_INTEGER(NULL, str)) == NULL)
return 0;
if (BIO_puts(out, s) <= 0)
ret = 0;
free(s);
@ -500,18 +502,28 @@ asn1_primitive_print(BIO *out, ASN1_VALUE **fld, const ASN1_ITEM *it,
ASN1_STRING *str;
int ret = 1, needlf = 1;
const char *pname;
const ASN1_PRIMITIVE_FUNCS *pf;
pf = it->funcs;
if (!asn1_print_fsname(out, indent, fname, sname, pctx))
return 0;
if (pf && pf->prim_print)
if (it != NULL && it->funcs != NULL) {
const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;
if (pf->prim_print == NULL)
return 0;
return pf->prim_print(out, fld, it, indent, pctx);
str = (ASN1_STRING *)*fld;
if (it->itype == ASN1_ITYPE_MSTRING)
}
if (it->itype == ASN1_ITYPE_MSTRING) {
str = (ASN1_STRING *)*fld;
utype = str->type & ~V_ASN1_NEG;
else
} else {
utype = it->utype;
if (utype == V_ASN1_BOOLEAN)
str = NULL;
else
str = (ASN1_STRING *)*fld;
}
if (utype == V_ASN1_ANY) {
ASN1_TYPE *atype = (ASN1_TYPE *)*fld;
utype = atype->type;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: x_algor.c,v 1.21 2015/07/24 15:09:52 jsing Exp $ */
/* $OpenBSD: x_algor.c,v 1.22 2018/05/01 19:01:27 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2000.
*/
@ -176,8 +176,8 @@ X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval)
}
void
X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, void **ppval,
X509_ALGOR *algor)
X509_ALGOR_get0(const ASN1_OBJECT **paobj, int *pptype, const void **ppval,
const X509_ALGOR *algor)
{
if (paobj)
*paobj = algor->algorithm;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: x_attrib.c,v 1.13 2015/02/14 14:56:45 jsing Exp $ */
/* $OpenBSD: x_attrib.c,v 1.14 2020/06/04 21:21:03 schwarze Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -174,10 +174,13 @@ X509_ATTRIBUTE_create(int nid, int atrtype, void *value)
{
X509_ATTRIBUTE *ret = NULL;
ASN1_TYPE *val = NULL;
ASN1_OBJECT *oid;
if ((oid = OBJ_nid2obj(nid)) == NULL)
return (NULL);
if ((ret = X509_ATTRIBUTE_new()) == NULL)
return (NULL);
ret->object = OBJ_nid2obj(nid);
ret->object = oid;
ret->single = 0;
if ((ret->value.set = sk_ASN1_TYPE_new_null()) == NULL)
goto err;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: x_bignum.c,v 1.8 2015/07/25 17:07:17 jsing Exp $ */
/* $OpenBSD: x_bignum.c,v 1.10 2019/04/01 15:49:22 jsing Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2000.
*/
@ -75,15 +75,18 @@ static int bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype,
const ASN1_ITEM *it);
static int bn_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
int utype, char *free_cont, const ASN1_ITEM *it);
static int bn_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it,
int indent, const ASN1_PCTX *pctx);
static ASN1_PRIMITIVE_FUNCS bignum_pf = {
NULL,
0,
bn_new,
bn_free,
0,
bn_c2i,
bn_i2c
.app_data = NULL,
.flags = 0,
.prim_new = bn_new,
.prim_free = bn_free,
.prim_clear = NULL, /* XXX */
.prim_c2i = bn_c2i,
.prim_i2c = bn_i2c,
.prim_print = bn_print,
};
const ASN1_ITEM BIGNUM_it = {
@ -165,3 +168,17 @@ bn_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype,
}
return 1;
}
static int
bn_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it, int indent,
const ASN1_PCTX *pctx)
{
BIGNUM *bn = (BIGNUM *)*pval;
if (!BN_print(out, bn))
return 0;
if (BIO_printf(out, "\n") <= 0)
return 0;
return 1;
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: x_crl.c,v 1.30 2018/03/17 14:33:20 jsing Exp $ */
/* $OpenBSD: x_crl.c,v 1.34 2019/03/13 20:34:00 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -527,9 +527,7 @@ X509_CRL_dup(X509_CRL *x)
static int
X509_REVOKED_cmp(const X509_REVOKED * const *a, const X509_REVOKED * const *b)
{
return(ASN1_STRING_cmp(
(ASN1_STRING *)(*a)->serialNumber,
(ASN1_STRING *)(*b)->serialNumber));
return(ASN1_INTEGER_cmp((*a)->serialNumber, (*b)->serialNumber));
}
int
@ -675,6 +673,8 @@ X509_CRL_METHOD_new(int (*crl_init)(X509_CRL *crl),
void
X509_CRL_METHOD_free(X509_CRL_METHOD *m)
{
if (m == NULL)
return;
if (!(m->flags & X509_CRL_METHOD_DYNAMIC))
return;
free(m);
@ -704,18 +704,48 @@ X509_CRL_get0_extensions(const X509_CRL *crl)
return crl->crl->extensions;
}
long
X509_CRL_get_version(const X509_CRL *crl)
{
return ASN1_INTEGER_get(crl->crl->version);
}
const ASN1_TIME *
X509_CRL_get0_lastUpdate(const X509_CRL *crl)
{
return crl->crl->lastUpdate;
}
ASN1_TIME *
X509_CRL_get_lastUpdate(X509_CRL *crl)
{
return crl->crl->lastUpdate;
}
const ASN1_TIME *
X509_CRL_get0_nextUpdate(const X509_CRL *crl)
{
return crl->crl->nextUpdate;
}
ASN1_TIME *
X509_CRL_get_nextUpdate(X509_CRL *crl)
{
return crl->crl->nextUpdate;
}
X509_NAME *
X509_CRL_get_issuer(const X509_CRL *crl)
{
return crl->crl->issuer;
}
STACK_OF(X509_REVOKED) *
X509_CRL_get_REVOKED(X509_CRL *crl)
{
return crl->crl->revoked;
}
void
X509_CRL_get0_signature(const X509_CRL *crl, const ASN1_BIT_STRING **psig,
const X509_ALGOR **palg)

View File

@ -1,4 +1,4 @@
/* $OpenBSD: x_info.c,v 1.17 2017/01/29 17:49:22 beck Exp $ */
/* $OpenBSD: x_info.c,v 1.18 2020/09/03 17:29:05 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -60,48 +60,35 @@
#include <openssl/asn1.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/x509.h>
X509_INFO *
X509_INFO_new(void)
{
X509_INFO *ret = NULL;
X509_INFO *ret;
ret = malloc(sizeof(X509_INFO));
if (ret == NULL) {
if ((ret = calloc(1, sizeof(X509_INFO))) == NULL) {
ASN1error(ERR_R_MALLOC_FAILURE);
return (NULL);
}
ret->enc_cipher.cipher = NULL;
ret->enc_len = 0;
ret->enc_data = NULL;
ret->references = 1;
ret->x509 = NULL;
ret->crl = NULL;
ret->x_pkey = NULL;
return (ret);
return ret;
}
void
X509_INFO_free(X509_INFO *x)
{
int i;
if (x == NULL)
return;
i = CRYPTO_add(&x->references, -1, CRYPTO_LOCK_X509_INFO);
if (i > 0)
if (CRYPTO_add(&x->references, -1, CRYPTO_LOCK_X509_INFO) > 0)
return;
X509_free(x->x509);
if (x->crl != NULL)
X509_CRL_free(x->crl);
if (x->x_pkey != NULL)
X509_PKEY_free(x->x_pkey);
X509_CRL_free(x->crl);
X509_PKEY_free(x->x_pkey);
free(x->enc_data);
free(x);
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: x_long.c,v 1.11 2017/01/29 17:49:22 beck Exp $ */
/* $OpenBSD: x_long.c,v 1.16 2019/04/20 11:13:15 jsing Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2000.
*/
@ -63,26 +63,30 @@
#include <openssl/bn.h>
#include <openssl/err.h>
/* Custom primitive type for long handling. This converts between an ASN1_INTEGER
* and a long directly.
/*
* Custom primitive type for long handling. This converts between an
* ASN1_INTEGER and a long directly.
*/
static int long_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
static void long_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);
static int long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);
static int long_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it, int indent, const ASN1_PCTX *pctx);
static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype,
const ASN1_ITEM *it);
static int long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
int utype, char *free_cont, const ASN1_ITEM *it);
static int long_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it,
int indent, const ASN1_PCTX *pctx);
static ASN1_PRIMITIVE_FUNCS long_pf = {
NULL, 0,
long_new,
long_free,
long_free, /* Clear should set to initial value */
long_c2i,
long_i2c,
long_print
.app_data = NULL,
.flags = 0,
.prim_new = long_new,
.prim_free = long_free,
.prim_clear = long_free, /* Clear should set to initial value */
.prim_c2i = long_c2i,
.prim_i2c = long_i2c,
.prim_print = long_print,
};
const ASN1_ITEM LONG_it = {
@ -138,7 +142,7 @@ long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype,
* octet is set.
*/
if (ltmp < 0)
utmp = -ltmp - 1;
utmp = -(ltmp + 1);
else
utmp = ltmp;
clen = BN_num_bits_word(utmp);
@ -191,8 +195,8 @@ long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype,
}
ltmp = (long)utmp;
if (neg) {
ltmp++;
ltmp = -ltmp;
ltmp--;
}
if (ltmp == it->size) {
ASN1error(ASN1_R_INTEGER_TOO_LARGE_FOR_LONG);
@ -206,5 +210,8 @@ static int
long_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it, int indent,
const ASN1_PCTX *pctx)
{
return BIO_printf(out, "%ld\n", *(long *)pval);
if (BIO_printf(out, "%ld\n", *(long *)pval) <= 0)
return 0;
return 1;
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: x_x509a.c,v 1.14 2015/02/14 15:28:39 miod Exp $ */
/* $OpenBSD: x_x509a.c,v 1.15 2018/05/01 19:01:27 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 1999.
*/
@ -154,7 +154,7 @@ aux_get(X509 *x)
}
int
X509_alias_set1(X509 *x, unsigned char *name, int len)
X509_alias_set1(X509 *x, const unsigned char *name, int len)
{
X509_CERT_AUX *aux;
if (!name) {
@ -172,7 +172,7 @@ X509_alias_set1(X509 *x, unsigned char *name, int len)
}
int
X509_keyid_set1(X509 *x, unsigned char *id, int len)
X509_keyid_set1(X509 *x, const unsigned char *id, int len)
{
X509_CERT_AUX *aux;
if (!id) {
@ -210,7 +210,7 @@ X509_keyid_get0(X509 *x, int *len)
}
int
X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj)
X509_add1_trust_object(X509 *x, const ASN1_OBJECT *obj)
{
X509_CERT_AUX *aux;
ASN1_OBJECT *objtmp;
@ -232,7 +232,7 @@ err:
}
int
X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj)
X509_add1_reject_object(X509 *x, const ASN1_OBJECT *obj)
{
X509_CERT_AUX *aux;
ASN1_OBJECT *objtmp;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: b_print.c,v 1.25 2014/06/12 15:49:28 deraadt Exp $ */
/* $OpenBSD: b_print.c,v 1.26 2019/06/28 05:47:57 deraadt Exp $ */
/* Theo de Raadt places this file in the public domain. */
@ -49,13 +49,10 @@ BIO_vprintf(BIO *bio, const char *format, va_list args)
char *buf = NULL;
ret = vasprintf(&buf, format, args);
if (buf == NULL) {
ret = -1;
goto fail;
}
if (ret == -1)
return (ret);
BIO_write(bio, buf, ret);
free(buf);
fail:
return (ret);
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: bf_buff.c,v 1.24 2017/01/29 17:49:22 beck Exp $ */
/* $OpenBSD: bf_buff.c,v 1.25 2018/05/01 13:29:09 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -73,7 +73,7 @@ static int buffer_free(BIO *data);
static long buffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
#define DEFAULT_BUFFER_SIZE 4096
static BIO_METHOD methods_buffer = {
static const BIO_METHOD methods_buffer = {
.type = BIO_TYPE_BUFFER,
.name = "buffer",
.bwrite = buffer_write,
@ -86,7 +86,7 @@ static BIO_METHOD methods_buffer = {
.callback_ctrl = buffer_callback_ctrl
};
BIO_METHOD *
const BIO_METHOD *
BIO_f_buffer(void)
{
return (&methods_buffer);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: bf_nbio.c,v 1.19 2015/02/07 13:19:15 doug Exp $ */
/* $OpenBSD: bf_nbio.c,v 1.20 2018/05/01 13:29:09 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -80,7 +80,7 @@ typedef struct nbio_test_st {
int lwn;
} NBIO_TEST;
static BIO_METHOD methods_nbiof = {
static const BIO_METHOD methods_nbiof = {
.type = BIO_TYPE_NBIO_TEST,
.name = "non-blocking IO test filter",
.bwrite = nbiof_write,
@ -93,7 +93,7 @@ static BIO_METHOD methods_nbiof = {
.callback_ctrl = nbiof_callback_ctrl
};
BIO_METHOD *
const BIO_METHOD *
BIO_f_nbio_test(void)
{
return (&methods_nbiof);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: bf_null.c,v 1.11 2014/07/11 08:44:47 jsing Exp $ */
/* $OpenBSD: bf_null.c,v 1.12 2018/05/01 13:29:09 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -73,7 +73,7 @@ static int nullf_new(BIO *h);
static int nullf_free(BIO *data);
static long nullf_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
static BIO_METHOD methods_nullf = {
static const BIO_METHOD methods_nullf = {
.type = BIO_TYPE_NULL_FILTER,
.name = "NULL filter",
.bwrite = nullf_write,
@ -86,7 +86,7 @@ static BIO_METHOD methods_nullf = {
.callback_ctrl = nullf_callback_ctrl
};
BIO_METHOD *
const BIO_METHOD *
BIO_f_null(void)
{
return (&methods_nullf);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: bio_lib.c,v 1.27 2018/02/22 16:38:43 jsing Exp $ */
/* $OpenBSD: bio_lib.c,v 1.29 2019/04/14 17:39:03 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -79,7 +79,7 @@ BIO_get_new_index(void)
}
BIO *
BIO_new(BIO_METHOD *method)
BIO_new(const BIO_METHOD *method)
{
BIO *ret = NULL;
@ -96,7 +96,7 @@ BIO_new(BIO_METHOD *method)
}
int
BIO_set(BIO *bio, BIO_METHOD *method)
BIO_set(BIO *bio, const BIO_METHOD *method)
{
bio->method = method;
bio->callback = NULL;
@ -250,7 +250,13 @@ BIO_read(BIO *b, void *out, int outl)
int i;
long (*cb)(BIO *, int, const char *, int, long, long);
if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL)) {
if (b == NULL)
return (0);
if (out == NULL || outl <= 0)
return (0);
if (b->method == NULL || b->method->bread == NULL) {
BIOerror(BIO_R_UNSUPPORTED_METHOD);
return (-2);
}
@ -273,6 +279,7 @@ BIO_read(BIO *b, void *out, int outl)
if (cb != NULL)
i = (int)cb(b, BIO_CB_READ|BIO_CB_RETURN, out, outl,
0L, (long)i);
return (i);
}
@ -285,12 +292,15 @@ BIO_write(BIO *b, const void *in, int inl)
if (b == NULL)
return (0);
cb = b->callback;
if ((b->method == NULL) || (b->method->bwrite == NULL)) {
if (in == NULL || inl <= 0)
return (0);
if (b->method == NULL || b->method->bwrite == NULL) {
BIOerror(BIO_R_UNSUPPORTED_METHOD);
return (-2);
}
cb = b->callback;
if ((cb != NULL) &&
((i = (int)cb(b, BIO_CB_WRITE, in, inl, 0L, 1L)) <= 0))
return (i);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: bio_meth.c,v 1.5 2018/02/20 18:51:35 tb Exp $ */
/* $OpenBSD: bio_meth.c,v 1.6 2018/06/02 04:41:12 tb Exp $ */
/*
* Copyright (c) 2018 Theo Buehler <tb@openbsd.org>
*
@ -40,7 +40,7 @@ BIO_meth_free(BIO_METHOD *biom)
}
int
(*BIO_meth_get_write(BIO_METHOD *biom))(BIO *, const char *, int)
(*BIO_meth_get_write(const BIO_METHOD *biom))(BIO *, const char *, int)
{
return biom->bwrite;
}
@ -53,7 +53,7 @@ BIO_meth_set_write(BIO_METHOD *biom, int (*write)(BIO *, const char *, int))
}
int
(*BIO_meth_get_read(BIO_METHOD *biom))(BIO *, char *, int)
(*BIO_meth_get_read(const BIO_METHOD *biom))(BIO *, char *, int)
{
return biom->bread;
}
@ -66,7 +66,7 @@ BIO_meth_set_read(BIO_METHOD *biom, int (*read)(BIO *, char *, int))
}
int
(*BIO_meth_get_puts(BIO_METHOD *biom))(BIO *, const char *)
(*BIO_meth_get_puts(const BIO_METHOD *biom))(BIO *, const char *)
{
return biom->bputs;
}
@ -79,7 +79,7 @@ BIO_meth_set_puts(BIO_METHOD *biom, int (*puts)(BIO *, const char *))
}
int
(*BIO_meth_get_gets(BIO_METHOD *biom))(BIO *, char *, int)
(*BIO_meth_get_gets(const BIO_METHOD *biom))(BIO *, char *, int)
{
return biom->bgets;
}
@ -92,7 +92,7 @@ BIO_meth_set_gets(BIO_METHOD *biom, int (*gets)(BIO *, char *, int))
}
long
(*BIO_meth_get_ctrl(BIO_METHOD *biom))(BIO *, int, long, void *)
(*BIO_meth_get_ctrl(const BIO_METHOD *biom))(BIO *, int, long, void *)
{
return biom->ctrl;
}
@ -105,7 +105,7 @@ BIO_meth_set_ctrl(BIO_METHOD *biom, long (*ctrl)(BIO *, int, long, void *))
}
int
(*BIO_meth_get_create(BIO_METHOD *biom))(BIO *)
(*BIO_meth_get_create(const BIO_METHOD *biom))(BIO *)
{
return biom->create;
}
@ -118,7 +118,7 @@ BIO_meth_set_create(BIO_METHOD *biom, int (*create)(BIO *))
}
int
(*BIO_meth_get_destroy(BIO_METHOD *biom))(BIO *)
(*BIO_meth_get_destroy(const BIO_METHOD *biom))(BIO *)
{
return biom->destroy;
}
@ -131,7 +131,7 @@ BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy)(BIO *))
}
long
(*BIO_meth_get_callback_ctrl(BIO_METHOD *biom))(BIO *, int, BIO_info_cb *)
(*BIO_meth_get_callback_ctrl(const BIO_METHOD *biom))(BIO *, int, BIO_info_cb *)
{
return
(long (*)(BIO *, int, BIO_info_cb *))biom->callback_ctrl; /* XXX */

View File

@ -1,4 +1,4 @@
/* $OpenBSD: bss_acpt.c,v 1.27 2017/01/29 17:49:22 beck Exp $ */
/* $OpenBSD: bss_acpt.c,v 1.29 2018/05/12 18:51:59 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -100,7 +100,7 @@ static void BIO_ACCEPT_free(BIO_ACCEPT *a);
#define ACPT_S_GET_ACCEPT_SOCKET 2
#define ACPT_S_OK 3
static BIO_METHOD methods_acceptp = {
static const BIO_METHOD methods_acceptp = {
.type = BIO_TYPE_ACCEPT,
.name = "socket accept",
.bwrite = acpt_write,
@ -111,7 +111,7 @@ static BIO_METHOD methods_acceptp = {
.destroy = acpt_free
};
BIO_METHOD *
const BIO_METHOD *
BIO_s_accept(void)
{
return (&methods_acceptp);
@ -436,7 +436,7 @@ acpt_puts(BIO *bp, const char *str)
}
BIO *
BIO_new_accept(char *str)
BIO_new_accept(const char *str)
{
BIO *ret;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: bss_bio.c,v 1.23 2017/01/29 17:49:22 beck Exp $ */
/* $OpenBSD: bss_bio.c,v 1.24 2018/05/01 13:29:09 tb Exp $ */
/* ====================================================================
* Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved.
*
@ -94,7 +94,7 @@ static int bio_puts(BIO *bio, const char *str);
static int bio_make_pair(BIO *bio1, BIO *bio2);
static void bio_destroy_pair(BIO *bio);
static BIO_METHOD methods_biop = {
static const BIO_METHOD methods_biop = {
.type = BIO_TYPE_BIO,
.name = "BIO pair",
.bwrite = bio_write,
@ -105,7 +105,7 @@ static BIO_METHOD methods_biop = {
.destroy = bio_free
};
BIO_METHOD *
const BIO_METHOD *
BIO_s_bio(void)
{
return &methods_biop;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: bss_conn.c,v 1.33 2017/01/29 17:49:22 beck Exp $ */
/* $OpenBSD: bss_conn.c,v 1.35 2018/05/12 18:51:59 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -106,7 +106,7 @@ static void conn_close_socket(BIO *data);
BIO_CONNECT *BIO_CONNECT_new(void);
void BIO_CONNECT_free(BIO_CONNECT *a);
static BIO_METHOD methods_connectp = {
static const BIO_METHOD methods_connectp = {
.type = BIO_TYPE_CONNECT,
.name = "socket connect",
.bwrite = conn_write,
@ -319,7 +319,7 @@ BIO_CONNECT_free(BIO_CONNECT *a)
free(a);
}
BIO_METHOD *
const BIO_METHOD *
BIO_s_connect(void)
{
return (&methods_connectp);
@ -583,7 +583,7 @@ conn_puts(BIO *bp, const char *str)
}
BIO *
BIO_new_connect(char *str)
BIO_new_connect(const char *str)
{
BIO *ret;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: bss_dgram.c,v 1.41 2015/07/20 23:15:28 doug Exp $ */
/* $OpenBSD: bss_dgram.c,v 1.42 2018/05/12 17:47:53 tb Exp $ */
/*
* DTLS implementation written by Nagendra Modadugu
* (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
@ -86,7 +86,7 @@ static int dgram_clear(BIO *bio);
static int BIO_dgram_should_retry(int s);
static BIO_METHOD methods_dgramp = {
static const BIO_METHOD methods_dgramp = {
.type = BIO_TYPE_DGRAM,
.name = "datagram socket",
.bwrite = dgram_write,
@ -112,7 +112,7 @@ typedef struct bio_dgram_data_st {
} bio_dgram_data;
BIO_METHOD *
const BIO_METHOD *
BIO_s_datagram(void)
{
return (&methods_dgramp);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: bss_fd.c,v 1.18 2015/02/12 03:54:07 jsing Exp $ */
/* $OpenBSD: bss_fd.c,v 1.19 2018/05/01 13:29:09 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -74,7 +74,7 @@ static int fd_new(BIO *h);
static int fd_free(BIO *data);
int BIO_fd_should_retry(int s);
static BIO_METHOD methods_fdp = {
static const BIO_METHOD methods_fdp = {
.type = BIO_TYPE_FD,
.name = "file descriptor",
.bwrite = fd_write,
@ -86,7 +86,7 @@ static BIO_METHOD methods_fdp = {
.destroy = fd_free
};
BIO_METHOD *
const BIO_METHOD *
BIO_s_fd(void)
{
return (&methods_fdp);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: bss_file.c,v 1.32 2017/01/29 17:49:22 beck Exp $ */
/* $OpenBSD: bss_file.c,v 1.33 2018/05/30 00:23:04 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -98,7 +98,7 @@ static long file_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int file_new(BIO *h);
static int file_free(BIO *data);
static BIO_METHOD methods_filep = {
static const BIO_METHOD methods_filep = {
.type = BIO_TYPE_FILE,
.name = "FILE pointer",
.bwrite = file_write,
@ -148,7 +148,7 @@ BIO_new_fp(FILE *stream, int close_flag)
return (ret);
}
BIO_METHOD *
const BIO_METHOD *
BIO_s_file(void)
{
return (&methods_filep);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: bss_log.c,v 1.21 2014/07/11 08:44:47 jsing Exp $ */
/* $OpenBSD: bss_log.c,v 1.22 2018/05/01 13:29:10 tb Exp $ */
/* ====================================================================
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
*
@ -81,7 +81,7 @@ static void xopenlog(BIO* bp, char* name, int level);
static void xsyslog(BIO* bp, int priority, const char* string);
static void xcloselog(BIO* bp);
static BIO_METHOD methods_slg = {
static const BIO_METHOD methods_slg = {
.type = BIO_TYPE_MEM,
.name = "syslog",
.bwrite = slg_write,
@ -91,7 +91,7 @@ static BIO_METHOD methods_slg = {
.destroy = slg_free
};
BIO_METHOD *
const BIO_METHOD *
BIO_s_log(void)
{
return (&methods_slg);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: bss_mem.c,v 1.15 2017/01/29 17:49:22 beck Exp $ */
/* $OpenBSD: bss_mem.c,v 1.17 2018/05/12 18:51:59 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -72,7 +72,7 @@ static long mem_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int mem_new(BIO *h);
static int mem_free(BIO *data);
static BIO_METHOD mem_method = {
static const BIO_METHOD mem_method = {
.type = BIO_TYPE_MEM,
.name = "memory buffer",
.bwrite = mem_write,
@ -87,14 +87,14 @@ static BIO_METHOD mem_method = {
/* bio->num is used to hold the value to return on 'empty', if it is
* 0, should_retry is not set */
BIO_METHOD *
const BIO_METHOD *
BIO_s_mem(void)
{
return (&mem_method);
}
BIO *
BIO_new_mem_buf(void *buf, int len)
BIO_new_mem_buf(const void *buf, int len)
{
BIO *ret;
BUF_MEM *b;
@ -108,7 +108,7 @@ BIO_new_mem_buf(void *buf, int len)
if (!(ret = BIO_new(BIO_s_mem())))
return NULL;
b = (BUF_MEM *)ret->ptr;
b->data = buf;
b->data = (void *)buf; /* Trust in the BIO_FLAGS_MEM_RDONLY flag. */
b->length = sz;
b->max = sz;
ret->flags |= BIO_FLAGS_MEM_RDONLY;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: bss_null.c,v 1.10 2014/07/11 08:44:47 jsing Exp $ */
/* $OpenBSD: bss_null.c,v 1.11 2018/05/01 13:29:10 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -70,7 +70,7 @@ static long null_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int null_new(BIO *h);
static int null_free(BIO *data);
static BIO_METHOD null_method = {
static const BIO_METHOD null_method = {
.type = BIO_TYPE_NULL,
.name = "NULL",
.bwrite = null_write,
@ -82,7 +82,7 @@ static BIO_METHOD null_method = {
.destroy = null_free
};
BIO_METHOD *
const BIO_METHOD *
BIO_s_null(void)
{
return (&null_method);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: bss_sock.c,v 1.23 2014/07/11 08:44:47 jsing Exp $ */
/* $OpenBSD: bss_sock.c,v 1.24 2018/05/01 13:29:10 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -73,7 +73,7 @@ static int sock_new(BIO *h);
static int sock_free(BIO *data);
int BIO_sock_should_retry(int s);
static BIO_METHOD methods_sockp = {
static const BIO_METHOD methods_sockp = {
.type = BIO_TYPE_SOCKET,
.name = "socket",
.bwrite = sock_write,
@ -84,7 +84,7 @@ static BIO_METHOD methods_sockp = {
.destroy = sock_free
};
BIO_METHOD *
const BIO_METHOD *
BIO_s_socket(void)
{
return (&methods_sockp);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: bn_add.c,v 1.11 2017/01/29 17:49:22 beck Exp $ */
/* $OpenBSD: bn_add.c,v 1.13 2018/07/23 18:07:21 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -62,61 +62,51 @@
#include "bn_lcl.h"
/* r can == a or b */
int
BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
{
const BIGNUM *tmp;
int a_neg = a->neg, ret;
int ret, r_neg;
bn_check_top(a);
bn_check_top(b);
/* a + b a+b
* a + -b a-b
* -a + b b-a
* -a + -b -(a+b)
*/
if (a_neg ^ b->neg) {
/* only one is negative */
if (a_neg)
{ tmp = a;
a = b;
b = tmp;
}
if (a->neg == b->neg) {
r_neg = a->neg;
ret = BN_uadd(r, a, b);
} else {
int cmp = BN_ucmp(a, b);
/* we are now a - b */
if (BN_ucmp(a, b) < 0) {
if (!BN_usub(r, b, a))
return (0);
r->neg = 1;
if (cmp > 0) {
r_neg = a->neg;
ret = BN_usub(r, a, b);
} else if (cmp < 0) {
r_neg = b->neg;
ret = BN_usub(r, b, a);
} else {
if (!BN_usub(r, a, b))
return (0);
r->neg = 0;
r_neg = 0;
BN_zero(r);
ret = 1;
}
return (1);
}
ret = BN_uadd(r, a, b);
r->neg = a_neg;
r->neg = r_neg;
bn_check_top(r);
return ret;
}
/* unsigned add of b to a */
int
BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
{
int max, min, dif;
BN_ULONG *ap, *bp, *rp, carry, t1, t2;
const BIGNUM *tmp;
const BN_ULONG *ap, *bp;
BN_ULONG *rp, carry, t1, t2;
bn_check_top(a);
bn_check_top(b);
if (a->top < b->top) {
const BIGNUM *tmp;
tmp = a;
a = b;
b = tmp;
@ -137,41 +127,28 @@ BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
carry = bn_add_words(rp, ap, bp, min);
rp += min;
ap += min;
bp += min;
if (carry) {
while (dif) {
dif--;
t1 = *(ap++);
t2 = (t1 + 1) & BN_MASK2;
*(rp++) = t2;
if (t2) {
carry = 0;
break;
}
}
if (carry) {
/* carry != 0 => dif == 0 */
*rp = 1;
r->top++;
}
while (dif) {
dif--;
t1 = *(ap++);
t2 = (t1 + carry) & BN_MASK2;
*(rp++) = t2;
carry &= (t2 == 0);
}
if (dif && rp != ap)
while (dif--)
/* copy remaining words if ap != rp */
*(rp++) = *(ap++);
*rp = carry;
r->top += carry;
r->neg = 0;
bn_check_top(r);
return 1;
}
/* unsigned subtraction of b from a, a must be larger than b. */
int
BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
{
int max, min, dif;
BN_ULONG t1, t2, *ap, *bp, *rp;
int i, carry;
const BN_ULONG *ap, *bp;
BN_ULONG t1, t2, borrow, *rp;
bn_check_top(a);
bn_check_top(b);
@ -180,134 +157,67 @@ BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
min = b->top;
dif = max - min;
if (dif < 0) /* hmm... should not be happening */
{
if (dif < 0) {
BNerror(BN_R_ARG2_LT_ARG3);
return (0);
return 0;
}
if (bn_wexpand(r, max) == NULL)
return (0);
return 0;
ap = a->d;
bp = b->d;
rp = r->d;
#if 1
carry = 0;
for (i = min; i != 0; i--) {
t1= *(ap++);
t2= *(bp++);
if (carry) {
carry = (t1 <= t2);
t1 = (t1 - t2 - 1)&BN_MASK2;
} else {
carry = (t1 < t2);
t1 = (t1 - t2)&BN_MASK2;
}
*(rp++) = t1&BN_MASK2;
}
#else
carry = bn_sub_words(rp, ap, bp, min);
borrow = bn_sub_words(rp, ap, bp, min);
ap += min;
bp += min;
rp += min;
#endif
if (carry) /* subtracted */
{
if (!dif)
/* error: a < b */
return 0;
while (dif) {
dif--;
t1 = *(ap++);
t2 = (t1 - 1)&BN_MASK2;
*(rp++) = t2;
if (t1)
break;
}
while (dif) {
dif--;
t1 = *(ap++);
t2 = (t1 - borrow) & BN_MASK2;
*(rp++) = t2;
borrow &= (t1 == 0);
}
#if 0
memcpy(rp, ap, sizeof(*rp)*(max - i));
#else
if (rp != ap) {
for (;;) {
if (!dif--)
break;
rp[0] = ap[0];
if (!dif--)
break;
rp[1] = ap[1];
if (!dif--)
break;
rp[2] = ap[2];
if (!dif--)
break;
rp[3] = ap[3];
rp += 4;
ap += 4;
}
}
#endif
while (max > 0 && *--rp == 0)
max--;
r->top = max;
r->neg = 0;
bn_correct_top(r);
return (1);
return 1;
}
int
BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
{
int max;
int add = 0, neg = 0;
const BIGNUM *tmp;
int ret, r_neg;
bn_check_top(a);
bn_check_top(b);
/* a - b a-b
* a - -b a+b
* -a - b -(a+b)
* -a - -b b-a
*/
if (a->neg) {
if (b->neg) {
tmp = a;
a = b;
b = tmp;
if (a->neg != b->neg) {
r_neg = a->neg;
ret = BN_uadd(r, a, b);
} else {
int cmp = BN_ucmp(a, b);
if (cmp > 0) {
r_neg = a->neg;
ret = BN_usub(r, a, b);
} else if (cmp < 0) {
r_neg = !b->neg;
ret = BN_usub(r, b, a);
} else {
add = 1;
neg = 1;
}
} else {
if (b->neg) {
add = 1;
neg = 0;
r_neg = 0;
BN_zero(r);
ret = 1;
}
}
if (add) {
if (!BN_uadd(r, a, b))
return (0);
r->neg = neg;
return (1);
}
/* We are actually doing a - b :-) */
max = (a->top > b->top) ? a->top : b->top;
if (bn_wexpand(r, max) == NULL)
return (0);
if (BN_ucmp(a, b) < 0) {
if (!BN_usub(r, b, a))
return (0);
r->neg = 1;
} else {
if (!BN_usub(r, a, b))
return (0);
r->neg = 0;
}
r->neg = r_neg;
bn_check_top(r);
return (1);
return ret;
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: bn_ctx.c,v 1.15 2017/01/29 17:49:22 beck Exp $ */
/* $OpenBSD: bn_ctx.c,v 1.16 2019/08/20 10:59:09 schwarze Exp $ */
/* Written by Ulf Moeller for the OpenSSL project. */
/* ====================================================================
* Copyright (c) 1998-2004 The OpenSSL Project. All rights reserved.
@ -283,6 +283,9 @@ BN_CTX_start(BN_CTX *ctx)
void
BN_CTX_end(BN_CTX *ctx)
{
if (ctx == NULL)
return;
CTXDBG_ENTRY("BN_CTX_end", ctx);
if (ctx->err_stack)

View File

@ -89,7 +89,7 @@
q; \
})
# define REMAINDER_IS_ALREADY_CALCULATED
# elif defined(__x86_64)
# elif defined(__x86_64) && defined(_LP64)
/*
* Same story here, but it's 128-bit by 64-bit division. Wow!
* <appro@fy.chalmers.se>

View File

@ -1,4 +1,4 @@
/* $OpenBSD: bn_lcl.h,v 1.27 2017/01/25 06:15:44 beck Exp $ */
/* $OpenBSD: bn_lcl.h,v 1.30 2018/11/05 23:52:47 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -239,7 +239,7 @@ __BEGIN_HIDDEN_DECLS
: "r"(a), "r"(b)); \
ret; })
# endif /* compiler */
# elif defined(__x86_64) || defined(__x86_64__)
# elif (defined(__x86_64) || defined(__x86_64__)) && defined(_LP64)
# if defined(__GNUC__) && __GNUC__>=2
# define BN_UMULT_HIGH(a,b) ({ \
BN_ULONG ret,discard; \
@ -583,6 +583,7 @@ BN_ULONG bn_add_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, int
BN_ULONG bn_sub_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, int num);
int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom);
int bn_rand_interval(BIGNUM *rnd, const BIGNUM *lower_inc, const BIGNUM *upper_exc);
/* Explicitly const time / non-const time versions for internal use */
int BN_mod_exp_ct(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
@ -605,5 +606,8 @@ BIGNUM *BN_mod_inverse_nonct(BIGNUM *ret, const BIGNUM *a, const BIGNUM *n,
BN_CTX *ctx);
int BN_gcd_ct(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
int BN_gcd_nonct(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
int BN_swap_ct(BN_ULONG swap, BIGNUM *a, BIGNUM *b, size_t nwords);
__END_HIDDEN_DECLS
#endif

View File

@ -1,4 +1,4 @@
/* $OpenBSD: bn_lib.c,v 1.39 2018/02/20 17:13:14 jsing Exp $ */
/* $OpenBSD: bn_lib.c,v 1.47 2019/06/17 17:11:48 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -151,53 +151,23 @@ BN_value_one(void)
int
BN_num_bits_word(BN_ULONG l)
{
static const unsigned char bits[256] = {
0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
};
BN_ULONG x, mask;
int bits;
unsigned int shift;
#ifdef _LP64
if (l & 0xffffffff00000000L) {
if (l & 0xffff000000000000L) {
if (l & 0xff00000000000000L) {
return (bits[(int)(l >> 56)] + 56);
} else
return (bits[(int)(l >> 48)] + 48);
} else {
if (l & 0x0000ff0000000000L) {
return (bits[(int)(l >> 40)] + 40);
} else
return (bits[(int)(l >> 32)] + 32);
}
} else
#endif
{
if (l & 0xffff0000L) {
if (l & 0xff000000L)
return (bits[(int)(l >> 24L)] + 24);
else
return (bits[(int)(l >> 16L)] + 16);
} else {
if (l & 0xff00L)
return (bits[(int)(l >> 8)] + 8);
else
return (bits[(int)(l)]);
}
}
/* Constant time calculation of floor(log2(l)) + 1. */
bits = (l != 0);
shift = BN_BITS4; /* On _LP64 this is 32, otherwise 16. */
do {
x = l >> shift;
/* If x is 0, set mask to 0, otherwise set it to all 1s. */
mask = ((~x & (x - 1)) >> (BN_BITS2 - 1)) - 1;
bits += shift & mask;
/* If x is 0, leave l alone, otherwise set l = x. */
l ^= (x ^ l) & mask;
} while ((shift /= 2) != 0);
return bits;
}
int
@ -529,7 +499,7 @@ BN_clear(BIGNUM *a)
{
bn_check_top(a);
if (a->d != NULL)
memset(a->d, 0, a->dmax * sizeof(a->d[0]));
explicit_bzero(a->d, a->dmax * sizeof(a->d[0]));
a->top = 0;
a->neg = 0;
}
@ -578,6 +548,8 @@ BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
BN_ULONG l;
BIGNUM *bn = NULL;
if (len < 0)
return (NULL);
if (ret == NULL)
ret = bn = BN_new();
if (ret == NULL)
@ -837,8 +809,10 @@ bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b, int cl, int dl)
/*
* Constant-time conditional swap of a and b.
* a and b are swapped if condition is not 0. The code assumes that at most one bit of condition is set.
* nwords is the number of words to swap. The code assumes that at least nwords are allocated in both a and b,
* a and b are swapped if condition is not 0.
* The code assumes that at most one bit of condition is set.
* nwords is the number of words to swap.
* The code assumes that at least nwords are allocated in both a and b,
* and that no more than nwords are used by either a or b.
* a and b cannot be the same number
*/
@ -889,6 +863,57 @@ BN_consttime_swap(BN_ULONG condition, BIGNUM *a, BIGNUM *b, int nwords)
#undef BN_CONSTTIME_SWAP
}
/*
* Constant-time conditional swap of a and b.
* a and b are swapped if condition is not 0.
* nwords is the number of words to swap.
*/
int
BN_swap_ct(BN_ULONG condition, BIGNUM *a, BIGNUM *b, size_t nwords)
{
BN_ULONG t;
int i, words;
if (a == b)
return 1;
if (nwords > INT_MAX)
return 0;
words = (int)nwords;
if (bn_wexpand(a, words) == NULL || bn_wexpand(b, words) == NULL)
return 0;
if (a->top > words || b->top > words) {
BNerror(BN_R_INVALID_LENGTH);
return 0;
}
/* Set condition to 0 (if it was zero) or all 1s otherwise. */
condition = ((~condition & (condition - 1)) >> (BN_BITS2 - 1)) - 1;
/* swap top field */
t = (a->top ^ b->top) & condition;
a->top ^= t;
b->top ^= t;
/* swap neg field */
t = (a->neg ^ b->neg) & condition;
a->neg ^= t;
b->neg ^= t;
/* swap BN_FLG_CONSTTIME from flag field */
t = ((a->flags ^ b->flags) & BN_FLG_CONSTTIME) & condition;
a->flags ^= t;
b->flags ^= t;
/* swap the data */
for (i = 0; i < words; i++) {
t = (a->d[i] ^ b->d[i]) & condition;
a->d[i] ^= t;
b->d[i] ^= t;
}
return 1;
}
BN_GENCB *
BN_GENCB_new(void)
{

View File

@ -1,4 +1,4 @@
/* $OpenBSD: bn_rand.c,v 1.20 2017/05/02 03:59:44 deraadt Exp $ */
/* $OpenBSD: bn_rand.c,v 1.24 2020/09/12 17:16:36 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -129,6 +129,11 @@ bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)
return (0);
}
if (bits < 0 || (bits == 1 && top > 0)) {
BNerror(BN_R_BITS_TOO_SMALL);
return (0);
}
if (bits == 0) {
BN_zero(rnd);
return (1);
@ -166,18 +171,16 @@ bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)
}
#endif
if (top != -1) {
if (top) {
if (bit == 0) {
buf[0] = 1;
buf[1] |= 0x80;
} else {
buf[0] |= (3 << (bit - 1));
}
if (top > 0) {
if (bit == 0) {
buf[0] = 1;
buf[1] |= 0x80;
} else {
buf[0] |= (1 << bit);
buf[0] |= (3 << (bit - 1));
}
}
if (top == 0)
buf[0] |= (1 << bit);
buf[0] &= ~mask;
if (bottom) /* set bottom bit if requested */
buf[bytes - 1] |= 1;
@ -279,6 +282,33 @@ BN_rand_range(BIGNUM *r, const BIGNUM *range)
return bn_rand_range(0, r, range);
}
int
bn_rand_interval(BIGNUM *rnd, const BIGNUM *lower_inc, const BIGNUM *upper_exc)
{
BIGNUM *len = NULL;
int ret = 0;
if (BN_cmp(lower_inc, upper_exc) >= 0)
goto err;
if ((len = BN_new()) == NULL)
goto err;
if (!BN_sub(len, upper_exc, lower_inc))
goto err;
if (!bn_rand_range(0, rnd, len))
goto err;
if (!BN_add(rnd, rnd, lower_inc))
goto err;
ret = 1;
err:
BN_free(len);
return ret;
}
int
BN_pseudo_rand_range(BIGNUM *r, const BIGNUM *range)
{

View File

@ -1,4 +1,4 @@
/* $OpenBSD: bn_x931p.c,v 1.10 2017/01/25 06:15:44 beck Exp $ */
/* $OpenBSD: bn_x931p.c,v 1.11 2019/01/20 01:56:59 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2005.
*/
@ -71,7 +71,7 @@
static int
bn_x931_derive_pi(BIGNUM *pi, const BIGNUM *Xpi, BN_CTX *ctx, BN_GENCB *cb)
{
int i = 0;
int i = 0, is_prime;
if (!BN_copy(pi, Xpi))
return 0;
@ -81,7 +81,10 @@ bn_x931_derive_pi(BIGNUM *pi, const BIGNUM *Xpi, BN_CTX *ctx, BN_GENCB *cb)
i++;
BN_GENCB_call(cb, 0, i);
/* NB 27 MR is specificed in X9.31 */
if (BN_is_prime_fasttest_ex(pi, 27, ctx, 1, cb))
is_prime = BN_is_prime_fasttest_ex(pi, 27, ctx, 1, cb);
if (is_prime < 0)
return 0;
if (is_prime == 1)
break;
if (!BN_add_word(pi, 2))
return 0;
@ -173,13 +176,20 @@ BN_X931_derive_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2, const BIGNUM *Xp,
goto err;
if (!BN_gcd_ct(t, pm1, e, ctx))
goto err;
if (BN_is_one(t)
/* X9.31 specifies 8 MR and 1 Lucas test or any prime test
* offering similar or better guarantees 50 MR is considerably
* better.
*/
&& BN_is_prime_fasttest_ex(p, 50, ctx, 1, cb))
break;
if (BN_is_one(t)) {
int r;
/*
* X9.31 specifies 8 MR and 1 Lucas test or any prime
* test offering similar or better guarantees 50 MR
* is considerably better.
*/
r = BN_is_prime_fasttest_ex(p, 50, ctx, 1, cb);
if (r < 0)
goto err;
if (r == 1)
break;
}
if (!BN_add(p, p, p1p2))
goto err;
}

216
crypto/bn/gf2m-elf-armv4.S Normal file
View File

@ -0,0 +1,216 @@
#include "arm_arch.h"
.text
.code 32
#if __ARM_ARCH__>=7
.fpu neon
.type mul_1x1_neon,%function
.align 5
mul_1x1_neon:
vshl.u64 d2,d16,#8 @ q1-q3 are slided
vmull.p8 q0,d16,d17 @ a·bb
vshl.u64 d4,d16,#16
vmull.p8 q1,d2,d17 @ a<<8·bb
vshl.u64 d6,d16,#24
vmull.p8 q2,d4,d17 @ a<<16·bb
vshr.u64 d2,#8
vmull.p8 q3,d6,d17 @ a<<24·bb
vshl.u64 d3,#24
veor d0,d2
vshr.u64 d4,#16
veor d0,d3
vshl.u64 d5,#16
veor d0,d4
vshr.u64 d6,#24
veor d0,d5
vshl.u64 d7,#8
veor d0,d6
veor d0,d7
.word 0xe12fff1e
.size mul_1x1_neon,.-mul_1x1_neon
#endif
.type mul_1x1_ialu,%function
.align 5
mul_1x1_ialu:
mov r4,#0
bic r5,r1,#3<<30 @ a1=a&0x3fffffff
str r4,[sp,#0] @ tab[0]=0
add r6,r5,r5 @ a2=a1<<1
str r5,[sp,#4] @ tab[1]=a1
eor r7,r5,r6 @ a1^a2
str r6,[sp,#8] @ tab[2]=a2
mov r8,r5,lsl#2 @ a4=a1<<2
str r7,[sp,#12] @ tab[3]=a1^a2
eor r9,r5,r8 @ a1^a4
str r8,[sp,#16] @ tab[4]=a4
eor r4,r6,r8 @ a2^a4
str r9,[sp,#20] @ tab[5]=a1^a4
eor r7,r7,r8 @ a1^a2^a4
str r4,[sp,#24] @ tab[6]=a2^a4
and r8,r12,r0,lsl#2
str r7,[sp,#28] @ tab[7]=a1^a2^a4
and r9,r12,r0,lsr#1
ldr r5,[sp,r8] @ tab[b & 0x7]
and r8,r12,r0,lsr#4
ldr r7,[sp,r9] @ tab[b >> 3 & 0x7]
and r9,r12,r0,lsr#7
ldr r6,[sp,r8] @ tab[b >> 6 & 0x7]
eor r5,r5,r7,lsl#3 @ stall
mov r4,r7,lsr#29
ldr r7,[sp,r9] @ tab[b >> 9 & 0x7]
and r8,r12,r0,lsr#10
eor r5,r5,r6,lsl#6
eor r4,r4,r6,lsr#26
ldr r6,[sp,r8] @ tab[b >> 12 & 0x7]
and r9,r12,r0,lsr#13
eor r5,r5,r7,lsl#9
eor r4,r4,r7,lsr#23
ldr r7,[sp,r9] @ tab[b >> 15 & 0x7]
and r8,r12,r0,lsr#16
eor r5,r5,r6,lsl#12
eor r4,r4,r6,lsr#20
ldr r6,[sp,r8] @ tab[b >> 18 & 0x7]
and r9,r12,r0,lsr#19
eor r5,r5,r7,lsl#15
eor r4,r4,r7,lsr#17
ldr r7,[sp,r9] @ tab[b >> 21 & 0x7]
and r8,r12,r0,lsr#22
eor r5,r5,r6,lsl#18
eor r4,r4,r6,lsr#14
ldr r6,[sp,r8] @ tab[b >> 24 & 0x7]
and r9,r12,r0,lsr#25
eor r5,r5,r7,lsl#21
eor r4,r4,r7,lsr#11
ldr r7,[sp,r9] @ tab[b >> 27 & 0x7]
tst r1,#1<<30
and r8,r12,r0,lsr#28
eor r5,r5,r6,lsl#24
eor r4,r4,r6,lsr#8
ldr r6,[sp,r8] @ tab[b >> 30 ]
eorne r5,r5,r0,lsl#30
eorne r4,r4,r0,lsr#2
tst r1,#1<<31
eor r5,r5,r7,lsl#27
eor r4,r4,r7,lsr#5
eorne r5,r5,r0,lsl#31
eorne r4,r4,r0,lsr#1
eor r5,r5,r6,lsl#30
eor r4,r4,r6,lsr#2
mov pc,lr
.size mul_1x1_ialu,.-mul_1x1_ialu
.global bn_GF2m_mul_2x2
.type bn_GF2m_mul_2x2,%function
.align 5
bn_GF2m_mul_2x2:
#if __ARM_ARCH__>=7
ldr r12,.LOPENSSL_armcap
.Lpic: ldr r12,[pc,r12]
tst r12,#1
beq .Lialu
veor d18,d18
vmov d19,r3,r3 @ two copies of b1
vmov.32 d18[0],r1 @ a1
veor d20,d20
vld1.32 d21[],[sp,:32] @ two copies of b0
vmov.32 d20[0],r2 @ a0
mov r12,lr
vmov d16,d18
vmov d17,d19
bl mul_1x1_neon @ a1·b1
vmov d22,d0
vmov d16,d20
vmov d17,d21
bl mul_1x1_neon @ a0·b0
vmov d23,d0
veor d16,d20,d18
veor d17,d21,d19
veor d20,d23,d22
bl mul_1x1_neon @ (a0+a1)·(b0+b1)
veor d0,d20 @ (a0+a1)·(b0+b1)-a0·b0-a1·b1
vshl.u64 d1,d0,#32
vshr.u64 d0,d0,#32
veor d23,d1
veor d22,d0
vst1.32 {d23[0]},[r0,:32]!
vst1.32 {d23[1]},[r0,:32]!
vst1.32 {d22[0]},[r0,:32]!
vst1.32 {d22[1]},[r0,:32]
bx r12
.align 4
.Lialu:
#endif
stmdb sp!,{r4-r10,lr}
mov r10,r0 @ reassign 1st argument
mov r0,r3 @ r0=b1
ldr r3,[sp,#32] @ load b0
mov r12,#7<<2
sub sp,sp,#32 @ allocate tab[8]
bl mul_1x1_ialu @ a1·b1
str r5,[r10,#8]
str r4,[r10,#12]
eor r0,r0,r3 @ flip b0 and b1
eor r1,r1,r2 @ flip a0 and a1
eor r3,r3,r0
eor r2,r2,r1
eor r0,r0,r3
eor r1,r1,r2
bl mul_1x1_ialu @ a0·b0
str r5,[r10]
str r4,[r10,#4]
eor r1,r1,r2
eor r0,r0,r3
bl mul_1x1_ialu @ (a1+a0)·(b1+b0)
ldmia r10,{r6-r9}
eor r5,r5,r4
eor r4,r4,r7
eor r5,r5,r6
eor r4,r4,r8
eor r5,r5,r9
eor r4,r4,r9
str r4,[r10,#8]
eor r5,r5,r4
add sp,sp,#32 @ destroy tab[8]
str r5,[r10,#4]
#if __ARM_ARCH__>=5
ldmia sp!,{r4-r10,pc}
#else
ldmia sp!,{r4-r10,lr}
tst lr,#1
moveq pc,lr @ be binary compatible with V4, yet
.word 0xe12fff1e @ interoperable with Thumb ISA:-)
#endif
.size bn_GF2m_mul_2x2,.-bn_GF2m_mul_2x2
#if __ARM_ARCH__>=7
.align 5
.LOPENSSL_armcap:
.word OPENSSL_armcap_P-(.Lpic+8)
#endif
.asciz "GF(2^m) Multiplication for ARMv4/NEON, CRYPTOGAMS by <appro@openssl.org>"
.align 5
.comm OPENSSL_armcap_P,4,4
#if defined(HAVE_GNU_STACK)
.section .note.GNU-stack,"",%progbits
#endif

View File

@ -0,0 +1,469 @@
; 1 "crypto/bn/gf2m-masm-x86_64.S.tmp"
; 1 "<built-in>" 1
; 1 "<built-in>" 3
; 340 "<built-in>" 3
; 1 "<command line>" 1
; 1 "<built-in>" 2
; 1 "crypto/bn/gf2m-masm-x86_64.S.tmp" 2
OPTION DOTNAME
; 1 "./crypto/x86_arch.h" 1
; 16 "./crypto/x86_arch.h"
; 40 "./crypto/x86_arch.h"
; 3 "crypto/bn/gf2m-masm-x86_64.S.tmp" 2
.text$ SEGMENT ALIGN(64) 'CODE'
ALIGN 16
_mul_1x1 PROC PRIVATE
sub rsp,128+8
mov r9,-1
lea rsi,QWORD PTR[rax*1+rax]
shr r9,3
lea rdi,QWORD PTR[rax*4]
and r9,rax
lea r12,QWORD PTR[rax*8]
sar rax,63
lea r10,QWORD PTR[r9*1+r9]
sar rsi,63
lea r11,QWORD PTR[r9*4]
and rax,rbp
sar rdi,63
mov rdx,rax
shl rax,63
and rsi,rbp
shr rdx,1
mov rcx,rsi
shl rsi,62
and rdi,rbp
shr rcx,2
xor rax,rsi
mov rbx,rdi
shl rdi,61
xor rdx,rcx
shr rbx,3
xor rax,rdi
xor rdx,rbx
mov r13,r9
mov QWORD PTR[rsp],0
xor r13,r10
mov QWORD PTR[8+rsp],r9
mov r14,r11
mov QWORD PTR[16+rsp],r10
xor r14,r12
mov QWORD PTR[24+rsp],r13
xor r9,r11
mov QWORD PTR[32+rsp],r11
xor r10,r11
mov QWORD PTR[40+rsp],r9
xor r13,r11
mov QWORD PTR[48+rsp],r10
xor r9,r14
mov QWORD PTR[56+rsp],r13
xor r10,r14
mov QWORD PTR[64+rsp],r12
xor r13,r14
mov QWORD PTR[72+rsp],r9
xor r9,r11
mov QWORD PTR[80+rsp],r10
xor r10,r11
mov QWORD PTR[88+rsp],r13
xor r13,r11
mov QWORD PTR[96+rsp],r14
mov rsi,r8
mov QWORD PTR[104+rsp],r9
and rsi,rbp
mov QWORD PTR[112+rsp],r10
shr rbp,4
mov QWORD PTR[120+rsp],r13
mov rdi,r8
and rdi,rbp
shr rbp,4
movq xmm0,QWORD PTR[rsi*8+rsp]
mov rsi,r8
and rsi,rbp
shr rbp,4
mov rcx,QWORD PTR[rdi*8+rsp]
mov rdi,r8
mov rbx,rcx
shl rcx,4
and rdi,rbp
movq xmm1,QWORD PTR[rsi*8+rsp]
shr rbx,60
xor rax,rcx
pslldq xmm1,1
mov rsi,r8
shr rbp,4
xor rdx,rbx
and rsi,rbp
shr rbp,4
pxor xmm0,xmm1
mov rcx,QWORD PTR[rdi*8+rsp]
mov rdi,r8
mov rbx,rcx
shl rcx,12
and rdi,rbp
movq xmm1,QWORD PTR[rsi*8+rsp]
shr rbx,52
xor rax,rcx
pslldq xmm1,2
mov rsi,r8
shr rbp,4
xor rdx,rbx
and rsi,rbp
shr rbp,4
pxor xmm0,xmm1
mov rcx,QWORD PTR[rdi*8+rsp]
mov rdi,r8
mov rbx,rcx
shl rcx,20
and rdi,rbp
movq xmm1,QWORD PTR[rsi*8+rsp]
shr rbx,44
xor rax,rcx
pslldq xmm1,3
mov rsi,r8
shr rbp,4
xor rdx,rbx
and rsi,rbp
shr rbp,4
pxor xmm0,xmm1
mov rcx,QWORD PTR[rdi*8+rsp]
mov rdi,r8
mov rbx,rcx
shl rcx,28
and rdi,rbp
movq xmm1,QWORD PTR[rsi*8+rsp]
shr rbx,36
xor rax,rcx
pslldq xmm1,4
mov rsi,r8
shr rbp,4
xor rdx,rbx
and rsi,rbp
shr rbp,4
pxor xmm0,xmm1
mov rcx,QWORD PTR[rdi*8+rsp]
mov rdi,r8
mov rbx,rcx
shl rcx,36
and rdi,rbp
movq xmm1,QWORD PTR[rsi*8+rsp]
shr rbx,28
xor rax,rcx
pslldq xmm1,5
mov rsi,r8
shr rbp,4
xor rdx,rbx
and rsi,rbp
shr rbp,4
pxor xmm0,xmm1
mov rcx,QWORD PTR[rdi*8+rsp]
mov rdi,r8
mov rbx,rcx
shl rcx,44
and rdi,rbp
movq xmm1,QWORD PTR[rsi*8+rsp]
shr rbx,20
xor rax,rcx
pslldq xmm1,6
mov rsi,r8
shr rbp,4
xor rdx,rbx
and rsi,rbp
shr rbp,4
pxor xmm0,xmm1
mov rcx,QWORD PTR[rdi*8+rsp]
mov rdi,r8
mov rbx,rcx
shl rcx,52
and rdi,rbp
movq xmm1,QWORD PTR[rsi*8+rsp]
shr rbx,12
xor rax,rcx
pslldq xmm1,7
mov rsi,r8
shr rbp,4
xor rdx,rbx
and rsi,rbp
shr rbp,4
pxor xmm0,xmm1
mov rcx,QWORD PTR[rdi*8+rsp]
mov rbx,rcx
shl rcx,60
movd rsi,xmm0
shr rbx,4
xor rax,rcx
psrldq xmm0,8
xor rdx,rbx
movd rdi,xmm0
xor rax,rsi
xor rdx,rdi
add rsp,128+8
DB 0F3h,0C3h ;repret
$L$end_mul_1x1::
_mul_1x1 ENDP
EXTERN OPENSSL_ia32cap_P:NEAR
PUBLIC bn_GF2m_mul_2x2
ALIGN 16
bn_GF2m_mul_2x2 PROC PUBLIC
mov eax,DWORD PTR[((OPENSSL_ia32cap_P+4))]
bt eax,1
jnc $L$vanilla_mul_2x2
movd xmm0,rdx
movd xmm1,r9
movd xmm2,r8
movq xmm3,QWORD PTR[40+rsp]
movdqa xmm4,xmm0
movdqa xmm5,xmm1
DB 102,15,58,68,193,0
pxor xmm4,xmm2
pxor xmm5,xmm3
DB 102,15,58,68,211,0
DB 102,15,58,68,229,0
xorps xmm4,xmm0
xorps xmm4,xmm2
movdqa xmm5,xmm4
pslldq xmm4,8
psrldq xmm5,8
pxor xmm2,xmm4
pxor xmm0,xmm5
movdqu XMMWORD PTR[rcx],xmm2
movdqu XMMWORD PTR[16+rcx],xmm0
DB 0F3h,0C3h ;repret
ALIGN 16
$L$vanilla_mul_2x2::
lea rsp,QWORD PTR[((-136))+rsp]
mov r10,QWORD PTR[176+rsp]
mov QWORD PTR[120+rsp],rdi
mov QWORD PTR[128+rsp],rsi
mov QWORD PTR[80+rsp],r14
mov QWORD PTR[88+rsp],r13
mov QWORD PTR[96+rsp],r12
mov QWORD PTR[104+rsp],rbp
mov QWORD PTR[112+rsp],rbx
$L$body_mul_2x2::
mov QWORD PTR[32+rsp],rcx
mov QWORD PTR[40+rsp],rdx
mov QWORD PTR[48+rsp],r8
mov QWORD PTR[56+rsp],r9
mov QWORD PTR[64+rsp],r10
mov r8,0fh
mov rax,rdx
mov rbp,r9
call _mul_1x1
mov QWORD PTR[16+rsp],rax
mov QWORD PTR[24+rsp],rdx
mov rax,QWORD PTR[48+rsp]
mov rbp,QWORD PTR[64+rsp]
call _mul_1x1
mov QWORD PTR[rsp],rax
mov QWORD PTR[8+rsp],rdx
mov rax,QWORD PTR[40+rsp]
mov rbp,QWORD PTR[56+rsp]
xor rax,QWORD PTR[48+rsp]
xor rbp,QWORD PTR[64+rsp]
call _mul_1x1
mov rbx,QWORD PTR[rsp]
mov rcx,QWORD PTR[8+rsp]
mov rdi,QWORD PTR[16+rsp]
mov rsi,QWORD PTR[24+rsp]
mov rbp,QWORD PTR[32+rsp]
xor rax,rdx
xor rdx,rcx
xor rax,rbx
mov QWORD PTR[rbp],rbx
xor rdx,rdi
mov QWORD PTR[24+rbp],rsi
xor rax,rsi
xor rdx,rsi
xor rax,rdx
mov QWORD PTR[16+rbp],rdx
mov QWORD PTR[8+rbp],rax
mov r14,QWORD PTR[80+rsp]
mov r13,QWORD PTR[88+rsp]
mov r12,QWORD PTR[96+rsp]
mov rbp,QWORD PTR[104+rsp]
mov rbx,QWORD PTR[112+rsp]
mov rdi,QWORD PTR[120+rsp]
mov rsi,QWORD PTR[128+rsp]
lea rsp,QWORD PTR[136+rsp]
DB 0F3h,0C3h ;repret
$L$end_mul_2x2::
bn_GF2m_mul_2x2 ENDP
DB 71,70,40,50,94,109,41,32,77,117,108,116,105,112,108,105
DB 99,97,116,105,111,110,32,102,111,114,32,120,56,54,95,54
DB 52,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121
DB 32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46
DB 111,114,103,62,0
ALIGN 16
EXTERN __imp_RtlVirtualUnwind:NEAR
ALIGN 16
se_handler PROC PRIVATE
push rsi
push rdi
push rbx
push rbp
push r12
push r13
push r14
push r15
pushfq
sub rsp,64
mov rax,QWORD PTR[152+r8]
mov rbx,QWORD PTR[248+r8]
lea r10,QWORD PTR[$L$body_mul_2x2]
cmp rbx,r10
jb $L$in_prologue
mov r14,QWORD PTR[80+rax]
mov r13,QWORD PTR[88+rax]
mov r12,QWORD PTR[96+rax]
mov rbp,QWORD PTR[104+rax]
mov rbx,QWORD PTR[112+rax]
mov rdi,QWORD PTR[120+rax]
mov rsi,QWORD PTR[128+rax]
mov QWORD PTR[144+r8],rbx
mov QWORD PTR[160+r8],rbp
mov QWORD PTR[168+r8],rsi
mov QWORD PTR[176+r8],rdi
mov QWORD PTR[216+r8],r12
mov QWORD PTR[224+r8],r13
mov QWORD PTR[232+r8],r14
$L$in_prologue::
lea rax,QWORD PTR[136+rax]
mov QWORD PTR[152+r8],rax
mov rdi,QWORD PTR[40+r9]
mov rsi,r8
mov ecx,154
DD 0a548f3fch
mov rsi,r9
xor rcx,rcx
mov rdx,QWORD PTR[8+rsi]
mov r8,QWORD PTR[rsi]
mov r9,QWORD PTR[16+rsi]
mov r10,QWORD PTR[40+rsi]
lea r11,QWORD PTR[56+rsi]
lea r12,QWORD PTR[24+rsi]
mov QWORD PTR[32+rsp],r10
mov QWORD PTR[40+rsp],r11
mov QWORD PTR[48+rsp],r12
mov QWORD PTR[56+rsp],rcx
call QWORD PTR[__imp_RtlVirtualUnwind]
mov eax,1
add rsp,64
popfq
pop r15
pop r14
pop r13
pop r12
pop rbp
pop rbx
pop rdi
pop rsi
DB 0F3h,0C3h ;repret
se_handler ENDP
.text$ ENDS
.pdata SEGMENT READONLY ALIGN(4)
ALIGN 4
DD imagerel _mul_1x1
DD imagerel $L$end_mul_1x1
DD imagerel $L$SEH_info_1x1
DD imagerel $L$vanilla_mul_2x2
DD imagerel $L$end_mul_2x2
DD imagerel $L$SEH_info_2x2
.pdata ENDS
.xdata SEGMENT READONLY ALIGN(8)
ALIGN 8
$L$SEH_info_1x1::
DB 001h,007h,002h,000h
DB 007h,001h,011h,000h
$L$SEH_info_2x2::
DB 9,0,0,0
DD imagerel se_handler
.xdata ENDS
END

File diff suppressed because it is too large Load Diff

148
crypto/bn/mont-elf-armv4.S Normal file
View File

@ -0,0 +1,148 @@
.text
.global bn_mul_mont
.type bn_mul_mont,%function
.align 2
bn_mul_mont:
stmdb sp!,{r0,r2} @ sp points at argument block
ldr r0,[sp,#3*4] @ load num
cmp r0,#2
movlt r0,#0
addlt sp,sp,#2*4
blt .Labrt
stmdb sp!,{r4-r12,lr} @ save 10 registers
mov r0,r0,lsl#2 @ rescale r0 for byte count
sub sp,sp,r0 @ alloca(4*num)
sub sp,sp,#4 @ +extra dword
sub r0,r0,#4 @ "num=num-1"
add r4,r2,r0 @ &bp[num-1]
add r0,sp,r0 @ r0 to point at &tp[num-1]
ldr r8,[r0,#14*4] @ &n0
ldr r2,[r2] @ bp[0]
ldr r5,[r1],#4 @ ap[0],ap++
ldr r6,[r3],#4 @ np[0],np++
ldr r8,[r8] @ *n0
str r4,[r0,#15*4] @ save &bp[num]
umull r10,r11,r5,r2 @ ap[0]*bp[0]
str r8,[r0,#14*4] @ save n0 value
mul r8,r10,r8 @ "tp[0]"*n0
mov r12,#0
umlal r10,r12,r6,r8 @ np[0]*n0+"t[0]"
mov r4,sp
.L1st:
ldr r5,[r1],#4 @ ap[j],ap++
mov r10,r11
ldr r6,[r3],#4 @ np[j],np++
mov r11,#0
umlal r10,r11,r5,r2 @ ap[j]*bp[0]
mov r14,#0
umlal r12,r14,r6,r8 @ np[j]*n0
adds r12,r12,r10
str r12,[r4],#4 @ tp[j-1]=,tp++
adc r12,r14,#0
cmp r4,r0
bne .L1st
adds r12,r12,r11
ldr r4,[r0,#13*4] @ restore bp
mov r14,#0
ldr r8,[r0,#14*4] @ restore n0
adc r14,r14,#0
str r12,[r0] @ tp[num-1]=
str r14,[r0,#4] @ tp[num]=
.Louter:
sub r7,r0,sp @ "original" r0-1 value
sub r1,r1,r7 @ "rewind" ap to &ap[1]
ldr r2,[r4,#4]! @ *(++bp)
sub r3,r3,r7 @ "rewind" np to &np[1]
ldr r5,[r1,#-4] @ ap[0]
ldr r10,[sp] @ tp[0]
ldr r6,[r3,#-4] @ np[0]
ldr r7,[sp,#4] @ tp[1]
mov r11,#0
umlal r10,r11,r5,r2 @ ap[0]*bp[i]+tp[0]
str r4,[r0,#13*4] @ save bp
mul r8,r10,r8
mov r12,#0
umlal r10,r12,r6,r8 @ np[0]*n0+"tp[0]"
mov r4,sp
.Linner:
ldr r5,[r1],#4 @ ap[j],ap++
adds r10,r11,r7 @ +=tp[j]
ldr r6,[r3],#4 @ np[j],np++
mov r11,#0
umlal r10,r11,r5,r2 @ ap[j]*bp[i]
mov r14,#0
umlal r12,r14,r6,r8 @ np[j]*n0
adc r11,r11,#0
ldr r7,[r4,#8] @ tp[j+1]
adds r12,r12,r10
str r12,[r4],#4 @ tp[j-1]=,tp++
adc r12,r14,#0
cmp r4,r0
bne .Linner
adds r12,r12,r11
mov r14,#0
ldr r4,[r0,#13*4] @ restore bp
adc r14,r14,#0
ldr r8,[r0,#14*4] @ restore n0
adds r12,r12,r7
ldr r7,[r0,#15*4] @ restore &bp[num]
adc r14,r14,#0
str r12,[r0] @ tp[num-1]=
str r14,[r0,#4] @ tp[num]=
cmp r4,r7
bne .Louter
ldr r2,[r0,#12*4] @ pull rp
add r0,r0,#4 @ r0 to point at &tp[num]
sub r5,r0,sp @ "original" num value
mov r4,sp @ "rewind" r4
mov r1,r4 @ "borrow" r1
sub r3,r3,r5 @ "rewind" r3 to &np[0]
subs r7,r7,r7 @ "clear" carry flag
.Lsub: ldr r7,[r4],#4
ldr r6,[r3],#4
sbcs r7,r7,r6 @ tp[j]-np[j]
str r7,[r2],#4 @ rp[j]=
teq r4,r0 @ preserve carry
bne .Lsub
sbcs r14,r14,#0 @ upmost carry
mov r4,sp @ "rewind" r4
sub r2,r2,r5 @ "rewind" r2
and r1,r4,r14
bic r3,r2,r14
orr r1,r1,r3 @ ap=borrow?tp:rp
.Lcopy: ldr r7,[r1],#4 @ copy or in-place refresh
str sp,[r4],#4 @ zap tp
str r7,[r2],#4
cmp r4,r0
bne .Lcopy
add sp,r0,#4 @ skip over tp[num+1]
ldmia sp!,{r4-r12,lr} @ restore registers
add sp,sp,#2*4 @ skip over {r0,r2}
mov r0,#1
.Labrt: tst lr,#1
moveq pc,lr @ be binary compatible with V4, yet
.word 0xe12fff1e @ interoperable with Thumb ISA:-)
.size bn_mul_mont,.-bn_mul_mont
.asciz "Montgomery multiplication for ARMv4, CRYPTOGAMS by <appro@openssl.org>"
.align 2
#if defined(HAVE_GNU_STACK)
.section .note.GNU-stack,"",%progbits
#endif

1496
crypto/bn/mont-masm-x86_64.S Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* $OpenBSD: cast_lcl.h,v 1.11 2015/11/05 21:46:51 miod Exp $ */
/* $OpenBSD: cast_lcl.h,v 1.12 2020/01/26 11:49:21 inoguchi Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -145,7 +145,7 @@
*((c)++)=(unsigned char)(((l) )&0xff))
/* only invoked with 0 <= n <= 31 */
#define ROTL(a,n) ((((a)<<(n))&0xffffffffL)|((a)>>(32-(n))))
#define ROTL(a,n) ((((a)<<(n))&0xffffffffL)|((a)>>((32-(n))&31)))
#define C_M 0x3fc
#define C_0 22L

View File

@ -1,4 +1,4 @@
/* $OpenBSD: chacha-merged.c,v 1.8 2017/08/13 16:55:31 jsing Exp $ */
/* $OpenBSD: chacha-merged.c,v 1.9 2019/01/22 00:59:21 dlg Exp $ */
/*
chacha-merged.c version 20080118
D. J. Bernstein
@ -277,3 +277,49 @@ chacha_encrypt_bytes(chacha_ctx *x, const u8 *m, u8 *c, u32 bytes)
m += 64;
}
}
void
CRYPTO_hchacha_20(unsigned char subkey[32], const unsigned char key[32],
const unsigned char nonce[16])
{
uint32_t x[16];
int i;
x[0] = U8TO32_LITTLE(sigma + 0);
x[1] = U8TO32_LITTLE(sigma + 4);
x[2] = U8TO32_LITTLE(sigma + 8);
x[3] = U8TO32_LITTLE(sigma + 12);
x[4] = U8TO32_LITTLE(key + 0);
x[5] = U8TO32_LITTLE(key + 4);
x[6] = U8TO32_LITTLE(key + 8);
x[7] = U8TO32_LITTLE(key + 12);
x[8] = U8TO32_LITTLE(key + 16);
x[9] = U8TO32_LITTLE(key + 20);
x[10] = U8TO32_LITTLE(key + 24);
x[11] = U8TO32_LITTLE(key + 28);
x[12] = U8TO32_LITTLE(nonce + 0);
x[13] = U8TO32_LITTLE(nonce + 4);
x[14] = U8TO32_LITTLE(nonce + 8);
x[15] = U8TO32_LITTLE(nonce + 12);
for (i = 20; i > 0; i -= 2) {
QUARTERROUND(x[0], x[4], x[8], x[12])
QUARTERROUND(x[1], x[5], x[9], x[13])
QUARTERROUND(x[2], x[6], x[10], x[14])
QUARTERROUND(x[3], x[7], x[11], x[15])
QUARTERROUND(x[0], x[5], x[10], x[15])
QUARTERROUND(x[1], x[6], x[11], x[12])
QUARTERROUND(x[2], x[7], x[8], x[13])
QUARTERROUND(x[3], x[4], x[9], x[14])
}
U32TO8_LITTLE(subkey + 0, x[0]);
U32TO8_LITTLE(subkey + 4, x[1]);
U32TO8_LITTLE(subkey + 8, x[2]);
U32TO8_LITTLE(subkey + 12, x[3]);
U32TO8_LITTLE(subkey + 16, x[12]);
U32TO8_LITTLE(subkey + 20, x[13]);
U32TO8_LITTLE(subkey + 24, x[14]);
U32TO8_LITTLE(subkey + 28, x[15]);
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: chacha.c,v 1.7 2015/12/09 14:07:55 bcook Exp $ */
/* $OpenBSD: chacha.c,v 1.8 2019/01/22 00:59:21 dlg Exp $ */
/*
* Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
*
@ -75,3 +75,13 @@ CRYPTO_chacha_20(unsigned char *out, const unsigned char *in, size_t len,
chacha_encrypt_bytes(&ctx, in, out, (uint32_t)len);
}
void
CRYPTO_xchacha_20(unsigned char *out, const unsigned char *in, size_t len,
const unsigned char key[32], const unsigned char iv[24])
{
uint8_t subkey[32];
CRYPTO_hchacha_20(subkey, key, iv);
CRYPTO_chacha_20(out, in, len, subkey, iv + 16, 0);
}

1627
crypto/cms/cms_asn1.c Normal file

File diff suppressed because it is too large Load Diff

211
crypto/cms/cms_att.c Normal file
View File

@ -0,0 +1,211 @@
/* $OpenBSD: cms_att.c,v 1.9 2019/08/10 18:15:52 jsing Exp $ */
/*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project.
*/
/* ====================================================================
* Copyright (c) 2008 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*/
#include <openssl/asn1t.h>
#include <openssl/pem.h>
#include <openssl/x509v3.h>
#include <openssl/err.h>
#include <openssl/cms.h>
#include "cms_lcl.h"
/* CMS SignedData Attribute utilities */
int
CMS_signed_get_attr_count(const CMS_SignerInfo *si)
{
return X509at_get_attr_count(si->signedAttrs);
}
int
CMS_signed_get_attr_by_NID(const CMS_SignerInfo *si, int nid, int lastpos)
{
return X509at_get_attr_by_NID(si->signedAttrs, nid, lastpos);
}
int
CMS_signed_get_attr_by_OBJ(const CMS_SignerInfo *si, const ASN1_OBJECT *obj,
int lastpos)
{
return X509at_get_attr_by_OBJ(si->signedAttrs, obj, lastpos);
}
X509_ATTRIBUTE *
CMS_signed_get_attr(const CMS_SignerInfo *si, int loc)
{
return X509at_get_attr(si->signedAttrs, loc);
}
X509_ATTRIBUTE *
CMS_signed_delete_attr(CMS_SignerInfo *si, int loc)
{
return X509at_delete_attr(si->signedAttrs, loc);
}
int
CMS_signed_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr)
{
if (X509at_add1_attr(&si->signedAttrs, attr))
return 1;
return 0;
}
int
CMS_signed_add1_attr_by_OBJ(CMS_SignerInfo *si, const ASN1_OBJECT *obj, int type,
const void *bytes, int len)
{
if (X509at_add1_attr_by_OBJ(&si->signedAttrs, obj, type, bytes, len))
return 1;
return 0;
}
int
CMS_signed_add1_attr_by_NID(CMS_SignerInfo *si, int nid, int type,
const void *bytes, int len)
{
if (X509at_add1_attr_by_NID(&si->signedAttrs, nid, type, bytes, len))
return 1;
return 0;
}
int
CMS_signed_add1_attr_by_txt(CMS_SignerInfo *si, const char *attrname, int type,
const void *bytes, int len)
{
if (X509at_add1_attr_by_txt(&si->signedAttrs, attrname, type, bytes, len))
return 1;
return 0;
}
void *
CMS_signed_get0_data_by_OBJ(CMS_SignerInfo *si, const ASN1_OBJECT *oid,
int lastpos, int type)
{
return X509at_get0_data_by_OBJ(si->signedAttrs, oid, lastpos, type);
}
int
CMS_unsigned_get_attr_count(const CMS_SignerInfo *si)
{
return X509at_get_attr_count(si->unsignedAttrs);
}
int
CMS_unsigned_get_attr_by_NID(const CMS_SignerInfo *si, int nid, int lastpos)
{
return X509at_get_attr_by_NID(si->unsignedAttrs, nid, lastpos);
}
int
CMS_unsigned_get_attr_by_OBJ(const CMS_SignerInfo *si, const ASN1_OBJECT *obj,
int lastpos)
{
return X509at_get_attr_by_OBJ(si->unsignedAttrs, obj, lastpos);
}
X509_ATTRIBUTE *
CMS_unsigned_get_attr(const CMS_SignerInfo *si, int loc)
{
return X509at_get_attr(si->unsignedAttrs, loc);
}
X509_ATTRIBUTE *
CMS_unsigned_delete_attr(CMS_SignerInfo *si, int loc)
{
return X509at_delete_attr(si->unsignedAttrs, loc);
}
int
CMS_unsigned_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr)
{
if (X509at_add1_attr(&si->unsignedAttrs, attr))
return 1;
return 0;
}
int
CMS_unsigned_add1_attr_by_OBJ(CMS_SignerInfo *si, const ASN1_OBJECT *obj,
int type, const void *bytes, int len)
{
if (X509at_add1_attr_by_OBJ(&si->unsignedAttrs, obj, type, bytes, len))
return 1;
return 0;
}
int
CMS_unsigned_add1_attr_by_NID(CMS_SignerInfo *si, int nid, int type,
const void *bytes, int len)
{
if (X509at_add1_attr_by_NID(&si->unsignedAttrs, nid, type, bytes, len))
return 1;
return 0;
}
int
CMS_unsigned_add1_attr_by_txt(CMS_SignerInfo *si, const char *attrname,
int type, const void *bytes, int len)
{
if (X509at_add1_attr_by_txt(&si->unsignedAttrs, attrname, type,
bytes, len))
return 1;
return 0;
}
void *
CMS_unsigned_get0_data_by_OBJ(CMS_SignerInfo *si, ASN1_OBJECT *oid, int lastpos,
int type)
{
return X509at_get0_data_by_OBJ(si->unsignedAttrs, oid, lastpos, type);
}
/* Specific attribute cases */

128
crypto/cms/cms_cd.c Normal file
View File

@ -0,0 +1,128 @@
/* $OpenBSD: cms_cd.c,v 1.15 2019/08/11 11:04:18 jsing Exp $ */
/*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project.
*/
/* ====================================================================
* Copyright (c) 2008 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*/
#include "cryptlib.h"
#include <openssl/asn1t.h>
#include <openssl/pem.h>
#include <openssl/x509v3.h>
#include <openssl/err.h>
#include <openssl/cms.h>
#include <openssl/bio.h>
#include <openssl/comp.h>
#include "cms_lcl.h"
#ifdef ZLIB
/* CMS CompressedData Utilities */
CMS_ContentInfo *
cms_CompressedData_create(int comp_nid)
{
CMS_ContentInfo *cms;
CMS_CompressedData *cd;
/*
* Will need something cleverer if there is ever more than one
* compression algorithm or parameters have some meaning...
*/
if (comp_nid != NID_zlib_compression) {
CMSerror(CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM);
return NULL;
}
cms = CMS_ContentInfo_new();
if (cms == NULL)
return NULL;
cd = (CMS_CompressedData *)ASN1_item_new(&CMS_CompressedData_it);
if (cd == NULL)
goto err;
cms->contentType = OBJ_nid2obj(NID_id_smime_ct_compressedData);
cms->d.compressedData = cd;
cd->version = 0;
X509_ALGOR_set0(cd->compressionAlgorithm,
OBJ_nid2obj(NID_zlib_compression), V_ASN1_UNDEF, NULL);
cd->encapContentInfo->eContentType = OBJ_nid2obj(NID_pkcs7_data);
return cms;
err:
CMS_ContentInfo_free(cms);
return NULL;
}
BIO *
cms_CompressedData_init_bio(CMS_ContentInfo *cms)
{
CMS_CompressedData *cd;
const ASN1_OBJECT *compoid;
if (OBJ_obj2nid(cms->contentType) != NID_id_smime_ct_compressedData) {
CMSerror(CMS_R_CONTENT_TYPE_NOT_COMPRESSED_DATA);
return NULL;
}
cd = cms->d.compressedData;
X509_ALGOR_get0(&compoid, NULL, NULL, cd->compressionAlgorithm);
if (OBJ_obj2nid(compoid) != NID_zlib_compression) {
CMSerror(CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM);
return NULL;
}
return BIO_new(BIO_f_zlib());
}
#endif

Some files were not shown because too many files have changed in this diff Show More