fix source (???)
This commit is contained in:
33
externals/libressl/.gitignore
vendored
33
externals/libressl/.gitignore
vendored
@@ -1,33 +0,0 @@
|
||||
# Build directory
|
||||
[Bb]uild/
|
||||
doc-build/
|
||||
|
||||
# Project/editor files
|
||||
*.swp
|
||||
.idea/
|
||||
.vs/
|
||||
.vscode/
|
||||
|
||||
# *nix related
|
||||
# Common convention for backup or temporary files
|
||||
*~
|
||||
|
||||
# Visual Studio CMake settings
|
||||
CMakeSettings.json
|
||||
|
||||
# OSX global filetypes
|
||||
# Created by Finder or Spotlight in directories for various OS functionality (indexing, etc)
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
.Spotlight-V100
|
||||
.Trashes
|
||||
|
||||
# Windows global filetypes
|
||||
Thumbs.db
|
||||
|
||||
# Generated symbol files
|
||||
*.def
|
||||
*.ver
|
||||
crypto/crypto_p.sym
|
||||
|
||||
408
externals/libressl/CMakeLists.txt
vendored
408
externals/libressl/CMakeLists.txt
vendored
@@ -1,408 +0,0 @@
|
||||
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)
|
||||
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ${CMAKE_MODULE_PATH})
|
||||
include(cmake_export_symbol)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
enable_testing()
|
||||
|
||||
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/ssl/VERSION SSL_VERSION)
|
||||
string(STRIP ${SSL_VERSION} SSL_VERSION)
|
||||
string(REPLACE ":" "." SSL_VERSION ${SSL_VERSION})
|
||||
string(REGEX REPLACE "\\..*" "" SSL_MAJOR_VERSION ${SSL_VERSION})
|
||||
|
||||
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/crypto/VERSION CRYPTO_VERSION)
|
||||
string(STRIP ${CRYPTO_VERSION} CRYPTO_VERSION)
|
||||
string(REPLACE ":" "." CRYPTO_VERSION ${CRYPTO_VERSION})
|
||||
string(REGEX REPLACE "\\..*" "" CRYPTO_MAJOR_VERSION ${CRYPTO_VERSION})
|
||||
|
||||
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/tls/VERSION TLS_VERSION)
|
||||
string(STRIP ${TLS_VERSION} TLS_VERSION)
|
||||
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)
|
||||
|
||||
|
||||
set(BUILD_NC true)
|
||||
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
|
||||
add_definitions(-fno-common)
|
||||
endif()
|
||||
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
|
||||
add_definitions(-DHAVE_ATTRIBUTE__BOUNDED__)
|
||||
add_definitions(-DHAVE_ATTRIBUTE__DEAD__)
|
||||
endif()
|
||||
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
|
||||
add_definitions(-D_DEFAULT_SOURCE)
|
||||
add_definitions(-D_BSD_SOURCE)
|
||||
add_definitions(-D_POSIX_SOURCE)
|
||||
add_definitions(-D_GNU_SOURCE)
|
||||
set(PLATFORM_LIBS ${PLATFORM_LIBS} pthread)
|
||||
endif()
|
||||
|
||||
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()
|
||||
|
||||
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} -std=gnu99 -fno-strict-aliasing")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mlp64")
|
||||
else()
|
||||
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} -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} dl md nsl socket)
|
||||
endif()
|
||||
|
||||
add_definitions(-DLIBRESSL_INTERNAL)
|
||||
add_definitions(-DOPENSSL_NO_HW_PADLOCK)
|
||||
add_definitions(-D__BEGIN_HIDDEN_DECLS=)
|
||||
add_definitions(-D__END_HIDDEN_DECLS=)
|
||||
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE true)
|
||||
|
||||
if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
|
||||
add_definitions(-Wno-pointer-sign)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
add_definitions(-D_CRT_DEPRECATED_NO_WARNINGS)
|
||||
add_definitions(-D_REENTRANT -D_POSIX_THREAD_SAFE_FUNCTIONS)
|
||||
add_definitions(-DCPPFLAGS -DNO_SYSLOG -DNO_CRYPT)
|
||||
add_definitions(-DWIN32_LEAN_AND_MEAN)
|
||||
if(NOT CMAKE_SYSTEM_NAME MATCHES "WindowsStore")
|
||||
add_definitions(-D_WIN32_WINNT=0x0600)
|
||||
endif()
|
||||
set(PLATFORM_LIBS ${PLATFORM_LIBS} ws2_32 bcrypt)
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
add_definitions(-Dinline=__inline)
|
||||
message(STATUS "Using [${CMAKE_C_COMPILER_ID}] compiler")
|
||||
if(CMAKE_C_COMPILER_ID MATCHES "MSVC" OR CMAKE_C_COMPILER_ID MATCHES "Clang")
|
||||
set(MSVC_DISABLED_WARNINGS_LIST
|
||||
"C4018" # 'expression' : signed/unsigned mismatch
|
||||
"C4057" # 'operator' : 'identifier1' indirection to
|
||||
# slightly different base types from 'identifier2'
|
||||
"C4100" # 'identifier' : unreferenced formal parameter
|
||||
"C4127" # conditional expression is constant
|
||||
"C4146" # unary minus operator applied to unsigned type,
|
||||
# result still unsigned
|
||||
"C4244" # 'argument' : conversion from 'type1' to 'type2',
|
||||
# possible loss of data
|
||||
"C4245" # 'conversion' : conversion from 'type1' to 'type2',
|
||||
# signed/unsigned mismatch
|
||||
"C4267" # 'var' : conversion from 'size_t' to 'type',
|
||||
# possible loss of data
|
||||
"C4389" # 'operator' : signed/unsigned mismatch
|
||||
"C4706" # assignment within conditional expression
|
||||
"C4996" # The POSIX name for this item is deprecated.
|
||||
# Instead, use the ISO C and C++ conformant name
|
||||
)
|
||||
elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
|
||||
add_definitions(-D_CRT_SUPPRESS_RESTRICT)
|
||||
set(MSVC_DISABLED_WARNINGS_LIST
|
||||
"C111" # Unreachable statement
|
||||
"C128" # Unreachable loop
|
||||
"C167" # Unexplict casting unsigned to signed
|
||||
"C186" # Pointless comparison of unsigned int with zero
|
||||
"C188" # Enumerated type mixed with another type
|
||||
"C344" # Redeclared type
|
||||
"C556" # Unexplict casting signed to unsigned
|
||||
"C869" # Unreferenced parameters
|
||||
"C1786" # Deprecated functions
|
||||
"C2545" # Empty else statement
|
||||
"C2557" # Comparing signed to unsigned
|
||||
"C2722" # List init syntax is c++11 feature
|
||||
"C3280" # Declaration hides variable
|
||||
)
|
||||
endif()
|
||||
string(REPLACE "C" " -wd" MSVC_DISABLED_WARNINGS_STR
|
||||
${MSVC_DISABLED_WARNINGS_LIST})
|
||||
string(REGEX REPLACE "[/-]W[1234][ ]?" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -MP -W4 ${MSVC_DISABLED_WARNINGS_STR}")
|
||||
endif()
|
||||
|
||||
check_function_exists(asprintf HAVE_ASPRINTF)
|
||||
if(HAVE_ASPRINTF)
|
||||
add_definitions(-DHAVE_ASPRINTF)
|
||||
endif()
|
||||
|
||||
check_function_exists(reallocarray HAVE_REALLOCARRAY)
|
||||
if(HAVE_REALLOCARRAY)
|
||||
add_definitions(-DHAVE_REALLOCARRAY)
|
||||
endif()
|
||||
|
||||
check_function_exists(strcasecmp HAVE_STRCASECMP)
|
||||
if(HAVE_STRCASECMP)
|
||||
add_definitions(-DHAVE_STRCASECMP)
|
||||
endif()
|
||||
|
||||
check_function_exists(strlcat HAVE_STRLCAT)
|
||||
if(HAVE_STRLCAT)
|
||||
add_definitions(-DHAVE_STRLCAT)
|
||||
endif()
|
||||
|
||||
check_function_exists(strlcpy HAVE_STRLCPY)
|
||||
if(HAVE_STRLCPY)
|
||||
add_definitions(-DHAVE_STRLCPY)
|
||||
endif()
|
||||
|
||||
check_function_exists(strndup HAVE_STRNDUP)
|
||||
if(HAVE_STRNDUP)
|
||||
add_definitions(-DHAVE_STRNDUP)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
set(HAVE_STRNLEN true)
|
||||
add_definitions(-DHAVE_STRNLEN)
|
||||
else()
|
||||
check_function_exists(strnlen HAVE_STRNLEN)
|
||||
if(HAVE_STRNLEN)
|
||||
add_definitions(-DHAVE_STRNLEN)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
check_function_exists(strsep HAVE_STRSEP)
|
||||
if(HAVE_STRSEP)
|
||||
add_definitions(-DHAVE_STRSEP)
|
||||
endif()
|
||||
|
||||
check_function_exists(timegm HAVE_TIMEGM)
|
||||
if(HAVE_TIMEGM)
|
||||
add_definitions(-DHAVE_TIMEGM)
|
||||
endif()
|
||||
|
||||
check_function_exists(arc4random_buf HAVE_ARC4RANDOM_BUF)
|
||||
if(HAVE_ARC4RANDOM_BUF)
|
||||
add_definitions(-DHAVE_ARC4RANDOM_BUF)
|
||||
endif()
|
||||
|
||||
check_function_exists(arc4random_uniform HAVE_ARC4RANDOM_UNIFORM)
|
||||
if(HAVE_ARC4RANDOM_UNIFORM)
|
||||
add_definitions(-DHAVE_ARC4RANDOM_UNIFORM)
|
||||
endif()
|
||||
|
||||
check_function_exists(explicit_bzero HAVE_EXPLICIT_BZERO)
|
||||
if(HAVE_EXPLICIT_BZERO)
|
||||
add_definitions(-DHAVE_EXPLICIT_BZERO)
|
||||
endif()
|
||||
|
||||
check_function_exists(getauxval HAVE_GETAUXVAL)
|
||||
if(HAVE_GETAUXVAL)
|
||||
add_definitions(-DHAVE_GETAUXVAL)
|
||||
endif()
|
||||
|
||||
check_function_exists(getentropy HAVE_GETENTROPY)
|
||||
if(HAVE_GETENTROPY)
|
||||
add_definitions(-DHAVE_GETENTROPY)
|
||||
endif()
|
||||
|
||||
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)
|
||||
endif()
|
||||
|
||||
check_function_exists(timingsafe_memcmp HAVE_TIMINGSAFE_MEMCMP)
|
||||
if(HAVE_MEMCMP)
|
||||
add_definitions(-DHAVE_MEMCMP)
|
||||
endif()
|
||||
|
||||
check_function_exists(memmem HAVE_MEMMEM)
|
||||
if(HAVE_MEMMEM)
|
||||
add_definitions(-DHAVE_MEMMEM)
|
||||
endif()
|
||||
|
||||
check_include_files(endian.h HAVE_ENDIAN_H)
|
||||
if(HAVE_ENDIAN_H)
|
||||
add_definitions(-DHAVE_ENDIAN_H)
|
||||
endif()
|
||||
|
||||
check_include_files(err.h HAVE_ERR_H)
|
||||
if(HAVE_ERR_H)
|
||||
add_definitions(-DHAVE_ERR_H)
|
||||
endif()
|
||||
|
||||
check_include_files("sys/types.h;arpa/inet.h;netinet/ip.h" HAVE_NETINET_IP_H)
|
||||
if(HAVE_NETINET_IP_H)
|
||||
add_definitions(-DHAVE_NETINET_IP_H)
|
||||
endif()
|
||||
|
||||
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()
|
||||
add_definitions(-DHAVE_GNU_STACK)
|
||||
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()
|
||||
|
||||
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(PLATFORM_LIBS ${PLATFORM_LIBS} rt)
|
||||
endif()
|
||||
else()
|
||||
# Otherwise, simply check if it exists
|
||||
check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)
|
||||
endif()
|
||||
if(HAVE_CLOCK_GETTIME)
|
||||
add_definitions(-DHAVE_CLOCK_GETTIME)
|
||||
endif()
|
||||
|
||||
check_type_size(time_t SIZEOF_TIME_T)
|
||||
if(SIZEOF_TIME_T STREQUAL "4")
|
||||
set(SMALL_TIME_T true)
|
||||
add_definitions(-DSMALL_TIME_T)
|
||||
message(WARNING " ** Warning, this system is unable to represent times past 2038\n"
|
||||
" ** It will behave incorrectly when handling valid RFC5280 dates")
|
||||
endif()
|
||||
add_definitions(-DSIZEOF_TIME_T=${SIZEOF_TIME_T})
|
||||
|
||||
set(OPENSSL_LIBS ssl crypto ${PLATFORM_LIBS})
|
||||
set(LIBTLS_LIBS tls ${PLATFORM_LIBS})
|
||||
|
||||
# libraries for regression test
|
||||
if(BUILD_SHARED_LIBS)
|
||||
set(OPENSSL_TEST_LIBS ssl-static crypto-static ${PLATFORM_LIBS})
|
||||
set(LIBTLS_TEST_LIBS tls-static ${PLATFORM_LIBS})
|
||||
else()
|
||||
set(OPENSSL_TEST_LIBS ssl crypto ${PLATFORM_LIBS})
|
||||
set(LIBTLS_TEST_LIBS tls ${PLATFORM_LIBS})
|
||||
endif()
|
||||
|
||||
add_subdirectory(crypto)
|
||||
add_subdirectory(ssl)
|
||||
add_subdirectory(tls)
|
||||
add_subdirectory(include)
|
||||
|
||||
if (BUILD_APPLE_XCFRAMEWORK)
|
||||
# Create the super library from object libraries
|
||||
add_library(LibreSSL_xcframework
|
||||
$<TARGET_OBJECTS:crypto_obj> $<TARGET_OBJECTS:tls_obj> $<TARGET_OBJECTS:ssl_obj>)
|
||||
set_target_properties(LibreSSL_xcframework PROPERTIES
|
||||
OUTPUT_NAME ressl)
|
||||
|
||||
if(ENABLE_LIBRESSL_INSTALL)
|
||||
install(TARGETS LibreSSL_xcframework
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif(ENABLE_LIBRESSL_INSTALL)
|
||||
endif(BUILD_APPLE_XCFRAMEWORK)
|
||||
|
||||
if(ENABLE_LIBRESSL_INSTALL)
|
||||
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()
|
||||
endif(ENABLE_LIBRESSL_INSTALL)
|
||||
|
||||
if(NOT "${OPENSSLDIR}" STREQUAL "")
|
||||
set(CONF_DIR "${OPENSSLDIR}")
|
||||
else()
|
||||
set(CONF_DIR "${CMAKE_INSTALL_PREFIX}/etc/ssl")
|
||||
endif()
|
||||
|
||||
if(ENABLE_LIBRESSL_INSTALL)
|
||||
install(FILES cert.pem openssl.cnf x509v3.cnf DESTINATION ${CONF_DIR})
|
||||
install(DIRECTORY DESTINATION ${CONF_DIR}/certs)
|
||||
endif(ENABLE_LIBRESSL_INSTALL)
|
||||
133
externals/libressl/COPYING
vendored
133
externals/libressl/COPYING
vendored
@@ -1,133 +0,0 @@
|
||||
|
||||
LibReSSL files are retained under the copyright of the authors. New
|
||||
additions are ISC licensed as per OpenBSD's normal licensing policy,
|
||||
or are placed in the public domain.
|
||||
|
||||
The OpenSSL code is distributed under the terms of the original OpenSSL
|
||||
licenses which follow:
|
||||
|
||||
LICENSE ISSUES
|
||||
==============
|
||||
|
||||
The OpenSSL toolkit stays under a dual license, i.e. both the conditions of
|
||||
the OpenSSL License and the original SSLeay license apply to the toolkit.
|
||||
See below for the actual license texts. In case of any license issues
|
||||
related to OpenSSL please contact openssl-core@openssl.org.
|
||||
|
||||
OpenSSL License
|
||||
---------------
|
||||
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1998-2011 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
|
||||
* openssl-core@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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
Original SSLeay License
|
||||
-----------------------
|
||||
|
||||
/* 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.]
|
||||
*/
|
||||
|
||||
2444
externals/libressl/ChangeLog
vendored
2444
externals/libressl/ChangeLog
vendored
File diff suppressed because it is too large
Load Diff
227
externals/libressl/FindLibreSSL.cmake
vendored
227
externals/libressl/FindLibreSSL.cmake
vendored
@@ -1,227 +0,0 @@
|
||||
#[=======================================================================[
|
||||
|
||||
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)
|
||||
370
externals/libressl/INSTALL
vendored
370
externals/libressl/INSTALL
vendored
@@ -1,370 +0,0 @@
|
||||
Installation Instructions
|
||||
*************************
|
||||
|
||||
Copyright (C) 1994-1996, 1999-2002, 2004-2013 Free Software Foundation,
|
||||
Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved. This file is offered as-is,
|
||||
without warranty of any kind.
|
||||
|
||||
Basic Installation
|
||||
==================
|
||||
|
||||
Briefly, the shell command `./configure && make && make install'
|
||||
should configure, build, and install this package. The following
|
||||
more-detailed instructions are generic; see the `README' file for
|
||||
instructions specific to this package. Some packages provide this
|
||||
`INSTALL' file but do not implement all of the features documented
|
||||
below. The lack of an optional feature in a given package is not
|
||||
necessarily a bug. More recommendations for GNU packages can be found
|
||||
in *note Makefile Conventions: (standards)Makefile Conventions.
|
||||
|
||||
The `configure' shell script attempts to guess correct values for
|
||||
various system-dependent variables used during compilation. It uses
|
||||
those values to create a `Makefile' in each directory of the package.
|
||||
It may also create one or more `.h' files containing system-dependent
|
||||
definitions. Finally, it creates a shell script `config.status' that
|
||||
you can run in the future to recreate the current configuration, and a
|
||||
file `config.log' containing compiler output (useful mainly for
|
||||
debugging `configure').
|
||||
|
||||
It can also use an optional file (typically called `config.cache'
|
||||
and enabled with `--cache-file=config.cache' or simply `-C') that saves
|
||||
the results of its tests to speed up reconfiguring. Caching is
|
||||
disabled by default to prevent problems with accidental use of stale
|
||||
cache files.
|
||||
|
||||
If you need to do unusual things to compile the package, please try
|
||||
to figure out how `configure' could check whether to do them, and mail
|
||||
diffs or instructions to the address given in the `README' so they can
|
||||
be considered for the next release. If you are using the cache, and at
|
||||
some point `config.cache' contains results you don't want to keep, you
|
||||
may remove or edit it.
|
||||
|
||||
The file `configure.ac' (or `configure.in') is used to create
|
||||
`configure' by a program called `autoconf'. You need `configure.ac' if
|
||||
you want to change it or regenerate `configure' using a newer version
|
||||
of `autoconf'.
|
||||
|
||||
The simplest way to compile this package is:
|
||||
|
||||
1. `cd' to the directory containing the package's source code and type
|
||||
`./configure' to configure the package for your system.
|
||||
|
||||
Running `configure' might take a while. While running, it prints
|
||||
some messages telling which features it is checking for.
|
||||
|
||||
2. Type `make' to compile the package.
|
||||
|
||||
3. Optionally, type `make check' to run any self-tests that come with
|
||||
the package, generally using the just-built uninstalled binaries.
|
||||
|
||||
4. Type `make install' to install the programs and any data files and
|
||||
documentation. When installing into a prefix owned by root, it is
|
||||
recommended that the package be configured and built as a regular
|
||||
user, and only the `make install' phase executed with root
|
||||
privileges.
|
||||
|
||||
5. Optionally, type `make installcheck' to repeat any self-tests, but
|
||||
this time using the binaries in their final installed location.
|
||||
This target does not install anything. Running this target as a
|
||||
regular user, particularly if the prior `make install' required
|
||||
root privileges, verifies that the installation completed
|
||||
correctly.
|
||||
|
||||
6. You can remove the program binaries and object files from the
|
||||
source code directory by typing `make clean'. To also remove the
|
||||
files that `configure' created (so you can compile the package for
|
||||
a different kind of computer), type `make distclean'. There is
|
||||
also a `make maintainer-clean' target, but that is intended mainly
|
||||
for the package's developers. If you use it, you may have to get
|
||||
all sorts of other programs in order to regenerate files that came
|
||||
with the distribution.
|
||||
|
||||
7. Often, you can also type `make uninstall' to remove the installed
|
||||
files again. In practice, not all packages have tested that
|
||||
uninstallation works correctly, even though it is required by the
|
||||
GNU Coding Standards.
|
||||
|
||||
8. Some packages, particularly those that use Automake, provide `make
|
||||
distcheck', which can by used by developers to test that all other
|
||||
targets like `make install' and `make uninstall' work correctly.
|
||||
This target is generally not run by end users.
|
||||
|
||||
Compilers and Options
|
||||
=====================
|
||||
|
||||
Some systems require unusual options for compilation or linking that
|
||||
the `configure' script does not know about. Run `./configure --help'
|
||||
for details on some of the pertinent environment variables.
|
||||
|
||||
You can give `configure' initial values for configuration parameters
|
||||
by setting variables in the command line or in the environment. Here
|
||||
is an example:
|
||||
|
||||
./configure CC=c99 CFLAGS=-g LIBS=-lposix
|
||||
|
||||
*Note Defining Variables::, for more details.
|
||||
|
||||
Compiling For Multiple Architectures
|
||||
====================================
|
||||
|
||||
You can compile the package for more than one kind of computer at the
|
||||
same time, by placing the object files for each architecture in their
|
||||
own directory. To do this, you can use GNU `make'. `cd' to the
|
||||
directory where you want the object files and executables to go and run
|
||||
the `configure' script. `configure' automatically checks for the
|
||||
source code in the directory that `configure' is in and in `..'. This
|
||||
is known as a "VPATH" build.
|
||||
|
||||
With a non-GNU `make', it is safer to compile the package for one
|
||||
architecture at a time in the source code directory. After you have
|
||||
installed the package for one architecture, use `make distclean' before
|
||||
reconfiguring for another architecture.
|
||||
|
||||
On MacOS X 10.5 and later systems, you can create libraries and
|
||||
executables that work on multiple system types--known as "fat" or
|
||||
"universal" binaries--by specifying multiple `-arch' options to the
|
||||
compiler but only a single `-arch' option to the preprocessor. Like
|
||||
this:
|
||||
|
||||
./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
|
||||
CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
|
||||
CPP="gcc -E" CXXCPP="g++ -E"
|
||||
|
||||
This is not guaranteed to produce working output in all cases, you
|
||||
may have to build one architecture at a time and combine the results
|
||||
using the `lipo' tool if you have problems.
|
||||
|
||||
Installation Names
|
||||
==================
|
||||
|
||||
By default, `make install' installs the package's commands under
|
||||
`/usr/local/bin', include files under `/usr/local/include', etc. You
|
||||
can specify an installation prefix other than `/usr/local' by giving
|
||||
`configure' the option `--prefix=PREFIX', where PREFIX must be an
|
||||
absolute file name.
|
||||
|
||||
You can specify separate installation prefixes for
|
||||
architecture-specific files and architecture-independent files. If you
|
||||
pass the option `--exec-prefix=PREFIX' to `configure', the package uses
|
||||
PREFIX as the prefix for installing programs and libraries.
|
||||
Documentation and other data files still use the regular prefix.
|
||||
|
||||
In addition, if you use an unusual directory layout you can give
|
||||
options like `--bindir=DIR' to specify different values for particular
|
||||
kinds of files. Run `configure --help' for a list of the directories
|
||||
you can set and what kinds of files go in them. In general, the
|
||||
default for these options is expressed in terms of `${prefix}', so that
|
||||
specifying just `--prefix' will affect all of the other directory
|
||||
specifications that were not explicitly provided.
|
||||
|
||||
The most portable way to affect installation locations is to pass the
|
||||
correct locations to `configure'; however, many packages provide one or
|
||||
both of the following shortcuts of passing variable assignments to the
|
||||
`make install' command line to change installation locations without
|
||||
having to reconfigure or recompile.
|
||||
|
||||
The first method involves providing an override variable for each
|
||||
affected directory. For example, `make install
|
||||
prefix=/alternate/directory' will choose an alternate location for all
|
||||
directory configuration variables that were expressed in terms of
|
||||
`${prefix}'. Any directories that were specified during `configure',
|
||||
but not in terms of `${prefix}', must each be overridden at install
|
||||
time for the entire installation to be relocated. The approach of
|
||||
makefile variable overrides for each directory variable is required by
|
||||
the GNU Coding Standards, and ideally causes no recompilation.
|
||||
However, some platforms have known limitations with the semantics of
|
||||
shared libraries that end up requiring recompilation when using this
|
||||
method, particularly noticeable in packages that use GNU Libtool.
|
||||
|
||||
The second method involves providing the `DESTDIR' variable. For
|
||||
example, `make install DESTDIR=/alternate/directory' will prepend
|
||||
`/alternate/directory' before all installation names. The approach of
|
||||
`DESTDIR' overrides is not required by the GNU Coding Standards, and
|
||||
does not work on platforms that have drive letters. On the other hand,
|
||||
it does better at avoiding recompilation issues, and works well even
|
||||
when some directory options were not specified in terms of `${prefix}'
|
||||
at `configure' time.
|
||||
|
||||
Optional Features
|
||||
=================
|
||||
|
||||
If the package supports it, you can cause programs to be installed
|
||||
with an extra prefix or suffix on their names by giving `configure' the
|
||||
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
|
||||
|
||||
Some packages pay attention to `--enable-FEATURE' options to
|
||||
`configure', where FEATURE indicates an optional part of the package.
|
||||
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
|
||||
is something like `gnu-as' or `x' (for the X Window System). The
|
||||
`README' should mention any `--enable-' and `--with-' options that the
|
||||
package recognizes.
|
||||
|
||||
For packages that use the X Window System, `configure' can usually
|
||||
find the X include and library files automatically, but if it doesn't,
|
||||
you can use the `configure' options `--x-includes=DIR' and
|
||||
`--x-libraries=DIR' to specify their locations.
|
||||
|
||||
Some packages offer the ability to configure how verbose the
|
||||
execution of `make' will be. For these packages, running `./configure
|
||||
--enable-silent-rules' sets the default to minimal output, which can be
|
||||
overridden with `make V=1'; while running `./configure
|
||||
--disable-silent-rules' sets the default to verbose, which can be
|
||||
overridden with `make V=0'.
|
||||
|
||||
Particular systems
|
||||
==================
|
||||
|
||||
On HP-UX, the default C compiler is not ANSI C compatible. If GNU
|
||||
CC is not installed, it is recommended to use the following options in
|
||||
order to use an ANSI C compiler:
|
||||
|
||||
./configure CC="cc -Ae -D_XOPEN_SOURCE=500"
|
||||
|
||||
and if that doesn't work, install pre-built binaries of GCC for HP-UX.
|
||||
|
||||
HP-UX `make' updates targets which have the same time stamps as
|
||||
their prerequisites, which makes it generally unusable when shipped
|
||||
generated files such as `configure' are involved. Use GNU `make'
|
||||
instead.
|
||||
|
||||
On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot
|
||||
parse its `<wchar.h>' header file. The option `-nodtk' can be used as
|
||||
a workaround. If GNU CC is not installed, it is therefore recommended
|
||||
to try
|
||||
|
||||
./configure CC="cc"
|
||||
|
||||
and if that doesn't work, try
|
||||
|
||||
./configure CC="cc -nodtk"
|
||||
|
||||
On Solaris, don't put `/usr/ucb' early in your `PATH'. This
|
||||
directory contains several dysfunctional programs; working variants of
|
||||
these programs are available in `/usr/bin'. So, if you need `/usr/ucb'
|
||||
in your `PATH', put it _after_ `/usr/bin'.
|
||||
|
||||
On Haiku, software installed for all users goes in `/boot/common',
|
||||
not `/usr/local'. It is recommended to use the following options:
|
||||
|
||||
./configure --prefix=/boot/common
|
||||
|
||||
Specifying the System Type
|
||||
==========================
|
||||
|
||||
There may be some features `configure' cannot figure out
|
||||
automatically, but needs to determine by the type of machine the package
|
||||
will run on. Usually, assuming the package is built to be run on the
|
||||
_same_ architectures, `configure' can figure that out, but if it prints
|
||||
a message saying it cannot guess the machine type, give it the
|
||||
`--build=TYPE' option. TYPE can either be a short name for the system
|
||||
type, such as `sun4', or a canonical name which has the form:
|
||||
|
||||
CPU-COMPANY-SYSTEM
|
||||
|
||||
where SYSTEM can have one of these forms:
|
||||
|
||||
OS
|
||||
KERNEL-OS
|
||||
|
||||
See the file `config.sub' for the possible values of each field. If
|
||||
`config.sub' isn't included in this package, then this package doesn't
|
||||
need to know the machine type.
|
||||
|
||||
If you are _building_ compiler tools for cross-compiling, you should
|
||||
use the option `--target=TYPE' to select the type of system they will
|
||||
produce code for.
|
||||
|
||||
If you want to _use_ a cross compiler, that generates code for a
|
||||
platform different from the build platform, you should specify the
|
||||
"host" platform (i.e., that on which the generated programs will
|
||||
eventually be run) with `--host=TYPE'.
|
||||
|
||||
Sharing Defaults
|
||||
================
|
||||
|
||||
If you want to set default values for `configure' scripts to share,
|
||||
you can create a site shell script called `config.site' that gives
|
||||
default values for variables like `CC', `cache_file', and `prefix'.
|
||||
`configure' looks for `PREFIX/share/config.site' if it exists, then
|
||||
`PREFIX/etc/config.site' if it exists. Or, you can set the
|
||||
`CONFIG_SITE' environment variable to the location of the site script.
|
||||
A warning: not all `configure' scripts look for a site script.
|
||||
|
||||
Defining Variables
|
||||
==================
|
||||
|
||||
Variables not defined in a site shell script can be set in the
|
||||
environment passed to `configure'. However, some packages may run
|
||||
configure again during the build, and the customized values of these
|
||||
variables may be lost. In order to avoid this problem, you should set
|
||||
them in the `configure' command line, using `VAR=value'. For example:
|
||||
|
||||
./configure CC=/usr/local2/bin/gcc
|
||||
|
||||
causes the specified `gcc' to be used as the C compiler (unless it is
|
||||
overridden in the site shell script).
|
||||
|
||||
Unfortunately, this technique does not work for `CONFIG_SHELL' due to
|
||||
an Autoconf limitation. Until the limitation is lifted, you can use
|
||||
this workaround:
|
||||
|
||||
CONFIG_SHELL=/bin/bash ./configure CONFIG_SHELL=/bin/bash
|
||||
|
||||
`configure' Invocation
|
||||
======================
|
||||
|
||||
`configure' recognizes the following options to control how it
|
||||
operates.
|
||||
|
||||
`--help'
|
||||
`-h'
|
||||
Print a summary of all of the options to `configure', and exit.
|
||||
|
||||
`--help=short'
|
||||
`--help=recursive'
|
||||
Print a summary of the options unique to this package's
|
||||
`configure', and exit. The `short' variant lists options used
|
||||
only in the top level, while the `recursive' variant lists options
|
||||
also present in any nested packages.
|
||||
|
||||
`--version'
|
||||
`-V'
|
||||
Print the version of Autoconf used to generate the `configure'
|
||||
script, and exit.
|
||||
|
||||
`--cache-file=FILE'
|
||||
Enable the cache: use and save the results of the tests in FILE,
|
||||
traditionally `config.cache'. FILE defaults to `/dev/null' to
|
||||
disable caching.
|
||||
|
||||
`--config-cache'
|
||||
`-C'
|
||||
Alias for `--cache-file=config.cache'.
|
||||
|
||||
`--quiet'
|
||||
`--silent'
|
||||
`-q'
|
||||
Do not print messages saying which checks are being made. To
|
||||
suppress all normal output, redirect it to `/dev/null' (any error
|
||||
messages will still be shown).
|
||||
|
||||
`--srcdir=DIR'
|
||||
Look for the package's source code in directory DIR. Usually
|
||||
`configure' can determine that directory automatically.
|
||||
|
||||
`--prefix=DIR'
|
||||
Use DIR as the installation prefix. *note Installation Names::
|
||||
for more details, including other options available for fine-tuning
|
||||
the installation locations.
|
||||
|
||||
`--no-create'
|
||||
`-n'
|
||||
Run the configure checks, but stop before creating any output
|
||||
files.
|
||||
|
||||
`configure' also accepts some other, not widely useful, options. Run
|
||||
`configure --help' for more details.
|
||||
217
externals/libressl/README.md
vendored
217
externals/libressl/README.md
vendored
@@ -1,217 +0,0 @@
|
||||
Built from https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-3.5.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
|
||||
|
||||
===
|
||||
|
||||

|
||||
## Official portable version of [LibreSSL](https://www.libressl.org) ##
|
||||
|
||||
[](https://github.com/libressl-portable/portable/actions/workflows/linux_test.yml)
|
||||
[](https://github.com/libressl-portable/portable/actions/workflows/macos_test.yml)
|
||||
[](https://github.com/libressl-portable/portable/actions/workflows/android_test.yml)
|
||||
[](https://github.com/libressl-portable/portable/actions/workflows/cross_test.yml)
|
||||
[](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:libressl)
|
||||
[](https://github.com/libressl-portable/portable/actions/workflows/linux_test_asan.yml)
|
||||
|
||||
LibreSSL is a fork of [OpenSSL](https://www.openssl.org) 1.0.1g developed by the
|
||||
[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: ##
|
||||
|
||||
LibreSSL is API compatible with OpenSSL 1.0.1, but does not yet include all
|
||||
new APIs from OpenSSL 1.0.2 and later. LibreSSL also includes APIs not yet
|
||||
present in OpenSSL. The current common API subset is OpenSSL 1.0.1.
|
||||
|
||||
LibreSSL is not ABI compatible with any release of OpenSSL, or necessarily
|
||||
earlier releases of LibreSSL. You will need to relink your programs to
|
||||
LibreSSL in order to use it, just as in moving between major versions of OpenSSL.
|
||||
LibreSSL's installed library version numbers are incremented to account for
|
||||
ABI and API changes.
|
||||
|
||||
## Compatibility with other operating systems: ##
|
||||
|
||||
While primarily developed on and taking advantage of APIs available on OpenBSD,
|
||||
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 known to build and work on:
|
||||
|
||||
* Linux (kernel 3.17 or later recommended)
|
||||
* FreeBSD (tested with 9.2 and later)
|
||||
* NetBSD (7.0 or later recommended)
|
||||
* HP-UX (11i)
|
||||
* Solaris (11 and later preferred)
|
||||
* Mac OS X (tested with 10.8 and later)
|
||||
* AIX (5.3 and later)
|
||||
|
||||
LibreSSL also supports the following Windows environments:
|
||||
* Microsoft Windows (Windows 7 / Windows Server 2008r2 or later, x86 and x64)
|
||||
* Wine (32-bit and 64-bit)
|
||||
* Mingw-w64, Cygwin, and Visual Studio
|
||||
|
||||
Official release tarballs are available at your friendly neighborhood
|
||||
OpenBSD mirror in directory
|
||||
[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.
|
||||
|
||||
Please report bugs either to the public libressl@openbsd.org mailing list,
|
||||
or to the github
|
||||
[issue tracker](https://github.com/libressl-portable/portable/issues)
|
||||
|
||||
Severe vulnerabilities or bugs requiring coordination with OpenSSL can be
|
||||
sent to the core team at libressl-security@openbsd.org.
|
||||
|
||||
# Building LibreSSL #
|
||||
|
||||
## Prerequisites when building from a Git checkout ##
|
||||
|
||||
If you have checked this source using Git, or have downloaded a source tarball
|
||||
from Github, follow these initial steps to prepare the source tree for
|
||||
building. _Note: Your build will fail if you do not follow these instructions! If you cannot follow these instructions (e.g. Windows system using CMake) or cannot meet these prerequistes, please download an official release distribution from https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/ instead. Using official releases is strongly advised if you are not a developer._
|
||||
|
||||
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.
|
||||
|
||||
## 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
|
||||
an OpenBSD mirror, run these commands to build and install the package on most
|
||||
systems:
|
||||
|
||||
```sh
|
||||
./configure # see ./configure --help for configuration options
|
||||
make check # runs builtin unit tests
|
||||
make install # set DESTDIR= to install to an alternate location
|
||||
```
|
||||
|
||||
If you wish to use the CMake build system, use these commands:
|
||||
|
||||
```sh
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
make test
|
||||
```
|
||||
|
||||
For faster builds, you can use Ninja as well:
|
||||
|
||||
```sh
|
||||
mkdir build-ninja
|
||||
cd build-ninja
|
||||
cmake -G"Ninja" ..
|
||||
ninja
|
||||
ninja test
|
||||
```
|
||||
|
||||
### OS specific build information: ###
|
||||
|
||||
#### HP-UX (11i) ####
|
||||
|
||||
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.
|
||||
|
||||
```sh
|
||||
export UNIX_STD=2003
|
||||
./configure
|
||||
make
|
||||
```
|
||||
|
||||
#### Windows - Mingw-w64 ####
|
||||
|
||||
LibreSSL builds against relatively recent versions of Mingw-w64, not to be
|
||||
confused with the original mingw.org project. Mingw-w64 3.2 or later
|
||||
should work. See README.windows for more information
|
||||
|
||||
#### Windows - Visual Studio ####
|
||||
|
||||
LibreSSL builds using the CMake target "Visual Studio 12 2013" and newer. To
|
||||
generate a Visual Studio project, install CMake, enter the LibreSSL source
|
||||
directory and run:
|
||||
|
||||
```sh
|
||||
mkdir build-vs2013
|
||||
cd build-vs2013
|
||||
cmake -G"Visual Studio 12 2013" ..
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
#### Cmake - Additional Options ####
|
||||
|
||||
| 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) |
|
||||
| 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.
|
||||
65
externals/libressl/README.windows
vendored
65
externals/libressl/README.windows
vendored
@@ -1,65 +0,0 @@
|
||||
# Building
|
||||
|
||||
For Windows systems, LibreSSL supports the mingw-w64 toolchain, which can use
|
||||
GCC or Clang as the compiler. Contrary to its name, mingw-w64 supports both
|
||||
32-bit and 64-bit build environments. If your project already uses mingw-w64,
|
||||
then LibreSSL should integrate very nicely. Old versions of the mingw-w64
|
||||
toolchain, such as the one packaged with Ubuntu 12.04, may have trouble
|
||||
building LibreSSL. Please try it with a recent toolchain if you encounter
|
||||
troubles. Cygwin provides an easy method of installing the latest mingw-w64
|
||||
cross compilers on Windows.
|
||||
|
||||
To configure and build LibreSSL for a 32-bit system, use the following
|
||||
build steps:
|
||||
|
||||
CC=i686-w64-mingw32-gcc CPPFLAGS=-D__MINGW_USE_VC2005_COMPAT \
|
||||
./configure --host=i686-w64-mingw32
|
||||
make
|
||||
make check
|
||||
|
||||
For 64-bit builds, use these instead:
|
||||
|
||||
CC=x86_64-w64-mingw32-gcc ./configure --host=x86_64-w64-mingw32
|
||||
make
|
||||
make check
|
||||
|
||||
# Why the -D__MINGW_USE_VC2005_COMPAT flag on 32-bit systems?
|
||||
|
||||
An ABI change introduced with Microsoft Visual C++ 2005 (also known as
|
||||
Visual C++ 8.0) switched time_t from 32-bit to 64-bit. It is important to
|
||||
build LibreSSL with 64-bit time_t whenever possible, because 32-bit time_t
|
||||
is unable to represent times past 2038 (this is commonly known as the
|
||||
Y2K38 problem).
|
||||
|
||||
If LibreSSL is built with 32-bit time_t, when verifying a certificate whose
|
||||
expiry date is set past 19 January 2038, it will be unable to tell if the
|
||||
certificate has expired or not, and thus take the safe stance and reject it.
|
||||
|
||||
In order to avoid this, you need to build LibreSSL (and everything that links
|
||||
with it) with the -D__MINGW_USE_VC2005_COMPAT flag. This tells mingw-w64 to
|
||||
use the new ABI.
|
||||
|
||||
64-bit systems always have a 64-bit time_t and are not affected by this
|
||||
problem.
|
||||
|
||||
# Using Libressl with Visual Studio
|
||||
|
||||
A script for generating ready-to-use .DLL and static .LIB files is included in
|
||||
the source repository at
|
||||
https://github.com/libressl-portable/portable/blob/master/dist-win.sh
|
||||
|
||||
This script uses mingw-w64 to build LibreSSL and then uses Visual Studio tools
|
||||
to generate compatible library import files ready-to-use with Visual
|
||||
Studio projects. Static and dynamic libraries are included. The script uses
|
||||
cv2pdb to generate Visual Studio and windbg compatible debug files. cv2pdb is a
|
||||
tool developed for the D language and can be found here:
|
||||
https://github.com/rainers/cv2pdb
|
||||
|
||||
Pre-built Windows binaries are available with LibreSSL releases if you do not
|
||||
have a mingw-w64 build environment. Mingw-w64 code is largely, but not 100%,
|
||||
compatible with code built from Visual Studio. Notably, FILE * pointers cannot
|
||||
be shared between code built for Mingw-w64 and Visual Studio.
|
||||
|
||||
As of LibreSSL 2.2.2, Visual Studio Native builds can be produced using CMake.
|
||||
This produces ABI-compatible libraries for linking with native code generated
|
||||
by Visual Studio.
|
||||
2
externals/libressl/VERSION
vendored
2
externals/libressl/VERSION
vendored
@@ -1,2 +0,0 @@
|
||||
3.5.2
|
||||
|
||||
5950
externals/libressl/cert.pem
vendored
5950
externals/libressl/cert.pem
vendored
File diff suppressed because it is too large
Load Diff
56
externals/libressl/cmake_export_symbol.cmake
vendored
56
externals/libressl/cmake_export_symbol.cmake
vendored
@@ -1,56 +0,0 @@
|
||||
macro(export_symbol TARGET SYMBOLS_PATH)
|
||||
|
||||
set(FLAG "")
|
||||
get_filename_component(FILENAME ${SYMBOLS_PATH} NAME)
|
||||
|
||||
if(WIN32)
|
||||
string(REPLACE ".sym" ".def" DEF_FILENAME ${FILENAME})
|
||||
file(TO_CMAKE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${DEF_FILENAME}" DEF_PATH)
|
||||
file(WRITE ${DEF_PATH} "EXPORTS\n")
|
||||
file(READ ${SYMBOLS_PATH} SYMBOLS)
|
||||
file(APPEND ${DEF_PATH} "${SYMBOLS}")
|
||||
target_sources(${TARGET} PRIVATE ${DEF_PATH})
|
||||
|
||||
elseif(APPLE)
|
||||
file(READ ${SYMBOLS_PATH} SYMBOLS)
|
||||
string(REGEX REPLACE "\n$" "" SYMBOLS ${SYMBOLS})
|
||||
string(REPLACE "\n" "\n_" SYMBOLS ${SYMBOLS})
|
||||
string(REGEX REPLACE "(.)$" "\\1\\n" SYMBOLS ${SYMBOLS})
|
||||
string(REPLACE ".sym" ".exp" EXP_FILENAME ${FILENAME})
|
||||
file(TO_CMAKE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${EXP_FILENAME}" EXP_PATH)
|
||||
file(WRITE ${EXP_PATH} "_${SYMBOLS}")
|
||||
set(FLAG "-exported_symbols_list ${EXP_PATH}")
|
||||
set_target_properties(${TARGET} PROPERTIES LINK_FLAGS ${FLAG})
|
||||
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "HP-UX")
|
||||
file(READ ${SYMBOLS_PATH} SYMBOLS)
|
||||
string(REGEX REPLACE "\n$" "" SYMBOLS ${SYMBOLS})
|
||||
string(REPLACE "\n" "\n+e " SYMBOLS ${SYMBOLS})
|
||||
string(REPLACE ".sym" ".opt" OPT_FILENAME ${FILENAME})
|
||||
file(TO_CMAKE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${OPT_FILENAME}" OPT_PATH)
|
||||
file(WRITE ${OPT_PATH} "+e ${SYMBOLS}")
|
||||
set(FLAG "-Wl,-c,${OPT_PATH}")
|
||||
set_target_properties(${TARGET} PROPERTIES LINK_FLAGS ${FLAG})
|
||||
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "SunOS")
|
||||
file(READ ${SYMBOLS_PATH} SYMBOLS)
|
||||
string(REPLACE "\n" ";\n" SYMBOLS ${SYMBOLS})
|
||||
string(REPLACE ".sym" ".ver" VER_FILENAME ${FILENAME})
|
||||
file(TO_CMAKE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${VER_FILENAME}" VER_PATH)
|
||||
file(WRITE ${VER_PATH}
|
||||
"{\nglobal:\n${SYMBOLS}\nlocal:\n*;\n};\n")
|
||||
set(FLAG "-Wl,-M${VER_PATH}")
|
||||
set_target_properties(${TARGET} PROPERTIES LINK_FLAGS ${FLAG})
|
||||
|
||||
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
|
||||
file(READ ${SYMBOLS_PATH} SYMBOLS)
|
||||
string(REPLACE "\n" ";\n" SYMBOLS ${SYMBOLS})
|
||||
string(REPLACE ".sym" ".ver" VER_FILENAME ${FILENAME})
|
||||
file(TO_CMAKE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${VER_FILENAME}" VER_PATH)
|
||||
file(WRITE ${VER_PATH}
|
||||
"{\nglobal:\n${SYMBOLS}\nlocal:\n*;\n};\n")
|
||||
set(FLAG "-Wl,--version-script,\"${VER_PATH}\"")
|
||||
set_target_properties(${TARGET} PROPERTIES LINK_FLAGS ${FLAG})
|
||||
endif()
|
||||
|
||||
endmacro()
|
||||
1030
externals/libressl/crypto/CMakeLists.txt
vendored
1030
externals/libressl/crypto/CMakeLists.txt
vendored
File diff suppressed because it is too large
Load Diff
1
externals/libressl/crypto/VERSION
vendored
1
externals/libressl/crypto/VERSION
vendored
@@ -1 +0,0 @@
|
||||
49:0:0
|
||||
1074
externals/libressl/crypto/aes/aes-elf-armv4.S
vendored
1074
externals/libressl/crypto/aes/aes-elf-armv4.S
vendored
File diff suppressed because it is too large
Load Diff
2547
externals/libressl/crypto/aes/aes-elf-x86_64.S
vendored
2547
externals/libressl/crypto/aes/aes-elf-x86_64.S
vendored
File diff suppressed because it is too large
Load Diff
2544
externals/libressl/crypto/aes/aes-macosx-x86_64.S
vendored
2544
externals/libressl/crypto/aes/aes-macosx-x86_64.S
vendored
File diff suppressed because it is too large
Load Diff
2948
externals/libressl/crypto/aes/aes-masm-x86_64.S
vendored
2948
externals/libressl/crypto/aes/aes-masm-x86_64.S
vendored
File diff suppressed because it is too large
Load Diff
2861
externals/libressl/crypto/aes/aes-mingw64-x86_64.S
vendored
2861
externals/libressl/crypto/aes/aes-mingw64-x86_64.S
vendored
File diff suppressed because it is too large
Load Diff
65
externals/libressl/crypto/aes/aes_cbc.c
vendored
65
externals/libressl/crypto/aes/aes_cbc.c
vendored
@@ -1,65 +0,0 @@
|
||||
/* $OpenBSD: aes_cbc.c,v 1.12 2014/06/12 15:49:27 deraadt Exp $ */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1998-2002 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
|
||||
* openssl-core@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/aes.h>
|
||||
#include <openssl/modes.h>
|
||||
|
||||
void
|
||||
AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
||||
size_t len, const AES_KEY *key, unsigned char *ivec, const int enc)
|
||||
{
|
||||
if (enc)
|
||||
CRYPTO_cbc128_encrypt(in, out, len, key, ivec,
|
||||
(block128_f)AES_encrypt);
|
||||
else
|
||||
CRYPTO_cbc128_decrypt(in, out, len, key, ivec,
|
||||
(block128_f)AES_decrypt);
|
||||
}
|
||||
84
externals/libressl/crypto/aes/aes_cfb.c
vendored
84
externals/libressl/crypto/aes/aes_cfb.c
vendored
@@ -1,84 +0,0 @@
|
||||
/* $OpenBSD: aes_cfb.c,v 1.8 2014/06/12 15:49:27 deraadt Exp $ */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2002-2006 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
|
||||
* openssl-core@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/aes.h>
|
||||
#include <openssl/modes.h>
|
||||
|
||||
/* The input and output encrypted as though 128bit cfb mode is being
|
||||
* used. The extra state information to record how much of the
|
||||
* 128bit block we have used is contained in *num;
|
||||
*/
|
||||
|
||||
void
|
||||
AES_cfb128_encrypt(const unsigned char *in, unsigned char *out, size_t length,
|
||||
const AES_KEY *key, unsigned char *ivec, int *num, const int enc)
|
||||
{
|
||||
CRYPTO_cfb128_encrypt(in, out, length, key, ivec, num, enc,
|
||||
(block128_f)AES_encrypt);
|
||||
}
|
||||
|
||||
/* N.B. This expects the input to be packed, MS bit first */
|
||||
void
|
||||
AES_cfb1_encrypt(const unsigned char *in, unsigned char *out, size_t length,
|
||||
const AES_KEY *key, unsigned char *ivec, int *num, const int enc)
|
||||
{
|
||||
CRYPTO_cfb128_1_encrypt(in, out, length, key, ivec, num, enc,
|
||||
(block128_f)AES_encrypt);
|
||||
}
|
||||
|
||||
void
|
||||
AES_cfb8_encrypt(const unsigned char *in, unsigned char *out, size_t length,
|
||||
const AES_KEY *key, unsigned char *ivec, int *num, const int enc)
|
||||
{
|
||||
CRYPTO_cfb128_8_encrypt(in, out, length, key, ivec, num, enc,
|
||||
(block128_f)AES_encrypt);
|
||||
}
|
||||
|
||||
1374
externals/libressl/crypto/aes/aes_core.c
vendored
1374
externals/libressl/crypto/aes/aes_core.c
vendored
File diff suppressed because it is too large
Load Diff
62
externals/libressl/crypto/aes/aes_ctr.c
vendored
62
externals/libressl/crypto/aes/aes_ctr.c
vendored
@@ -1,62 +0,0 @@
|
||||
/* $OpenBSD: aes_ctr.c,v 1.9 2014/06/12 15:49:27 deraadt Exp $ */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1998-2002 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
|
||||
* openssl-core@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/aes.h>
|
||||
#include <openssl/modes.h>
|
||||
|
||||
void
|
||||
AES_ctr128_encrypt(const unsigned char *in, unsigned char *out,
|
||||
size_t length, const AES_KEY *key, unsigned char ivec[AES_BLOCK_SIZE],
|
||||
unsigned char ecount_buf[AES_BLOCK_SIZE], unsigned int *num)
|
||||
{
|
||||
CRYPTO_ctr128_encrypt(in, out, length, key, ivec, ecount_buf, num,
|
||||
(block128_f)AES_encrypt);
|
||||
}
|
||||
69
externals/libressl/crypto/aes/aes_ecb.c
vendored
69
externals/libressl/crypto/aes/aes_ecb.c
vendored
@@ -1,69 +0,0 @@
|
||||
/* $OpenBSD: aes_ecb.c,v 1.6 2015/02/10 09:46:30 miod Exp $ */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1998-2002 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
|
||||
* openssl-core@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.
|
||||
* ====================================================================
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AES_DEBUG
|
||||
# ifndef NDEBUG
|
||||
# define NDEBUG
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <openssl/aes.h>
|
||||
#include "aes_locl.h"
|
||||
|
||||
void
|
||||
AES_ecb_encrypt(const unsigned char *in, unsigned char *out,
|
||||
const AES_KEY *key, const int enc)
|
||||
{
|
||||
if (AES_ENCRYPT == enc)
|
||||
AES_encrypt(in, out, key);
|
||||
else
|
||||
AES_decrypt(in, out, key);
|
||||
}
|
||||
194
externals/libressl/crypto/aes/aes_ige.c
vendored
194
externals/libressl/crypto/aes/aes_ige.c
vendored
@@ -1,194 +0,0 @@
|
||||
/* $OpenBSD: aes_ige.c,v 1.8 2022/01/22 00:43:41 inoguchi Exp $ */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2006 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
|
||||
* openssl-core@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/aes.h>
|
||||
#include <openssl/crypto.h>
|
||||
|
||||
#include "aes_locl.h"
|
||||
|
||||
#define N_WORDS (AES_BLOCK_SIZE / sizeof(unsigned long))
|
||||
typedef struct {
|
||||
unsigned long data[N_WORDS];
|
||||
} aes_block_t;
|
||||
|
||||
/* XXX: probably some better way to do this */
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
#define UNALIGNED_MEMOPS_ARE_FAST 1
|
||||
#else
|
||||
#define UNALIGNED_MEMOPS_ARE_FAST 0
|
||||
#endif
|
||||
|
||||
#if UNALIGNED_MEMOPS_ARE_FAST
|
||||
#define load_block(d, s) (d) = *(const aes_block_t *)(s)
|
||||
#define store_block(d, s) *(aes_block_t *)(d) = (s)
|
||||
#else
|
||||
#define load_block(d, s) memcpy((d).data, (s), AES_BLOCK_SIZE)
|
||||
#define store_block(d, s) memcpy((d), (s).data, AES_BLOCK_SIZE)
|
||||
#endif
|
||||
|
||||
/* N.B. The IV for this mode is _twice_ the block size */
|
||||
|
||||
void
|
||||
AES_ige_encrypt(const unsigned char *in, unsigned char *out, size_t length,
|
||||
const AES_KEY *key, unsigned char *ivec, const int enc)
|
||||
{
|
||||
size_t n;
|
||||
size_t len;
|
||||
|
||||
OPENSSL_assert((length % AES_BLOCK_SIZE) == 0);
|
||||
|
||||
len = length / AES_BLOCK_SIZE;
|
||||
|
||||
if (AES_ENCRYPT == enc) {
|
||||
if (in != out && (UNALIGNED_MEMOPS_ARE_FAST ||
|
||||
((size_t)in|(size_t)out|(size_t)ivec) %
|
||||
sizeof(long) == 0)) {
|
||||
aes_block_t *ivp = (aes_block_t *)ivec;
|
||||
aes_block_t *iv2p = (aes_block_t *)(ivec + AES_BLOCK_SIZE);
|
||||
|
||||
while (len) {
|
||||
aes_block_t *inp = (aes_block_t *)in;
|
||||
aes_block_t *outp = (aes_block_t *)out;
|
||||
|
||||
for (n = 0; n < N_WORDS; ++n)
|
||||
outp->data[n] = inp->data[n] ^ ivp->data[n];
|
||||
AES_encrypt((unsigned char *)outp->data, (unsigned char *)outp->data, key);
|
||||
for (n = 0; n < N_WORDS; ++n)
|
||||
outp->data[n] ^= iv2p->data[n];
|
||||
ivp = outp;
|
||||
iv2p = inp;
|
||||
--len;
|
||||
in += AES_BLOCK_SIZE;
|
||||
out += AES_BLOCK_SIZE;
|
||||
}
|
||||
memmove(ivec, ivp->data, AES_BLOCK_SIZE);
|
||||
memmove(ivec + AES_BLOCK_SIZE, iv2p->data, AES_BLOCK_SIZE);
|
||||
} else {
|
||||
aes_block_t tmp, tmp2;
|
||||
aes_block_t iv;
|
||||
aes_block_t iv2;
|
||||
|
||||
load_block(iv, ivec);
|
||||
load_block(iv2, ivec + AES_BLOCK_SIZE);
|
||||
|
||||
while (len) {
|
||||
load_block(tmp, in);
|
||||
for (n = 0; n < N_WORDS; ++n)
|
||||
tmp2.data[n] = tmp.data[n] ^ iv.data[n];
|
||||
AES_encrypt((unsigned char *)tmp2.data,
|
||||
(unsigned char *)tmp2.data, key);
|
||||
for (n = 0; n < N_WORDS; ++n)
|
||||
tmp2.data[n] ^= iv2.data[n];
|
||||
store_block(out, tmp2);
|
||||
iv = tmp2;
|
||||
iv2 = tmp;
|
||||
--len;
|
||||
in += AES_BLOCK_SIZE;
|
||||
out += AES_BLOCK_SIZE;
|
||||
}
|
||||
memcpy(ivec, iv.data, AES_BLOCK_SIZE);
|
||||
memcpy(ivec + AES_BLOCK_SIZE, iv2.data, AES_BLOCK_SIZE);
|
||||
}
|
||||
} else {
|
||||
if (in != out && (UNALIGNED_MEMOPS_ARE_FAST ||
|
||||
((size_t)in|(size_t)out|(size_t)ivec) %
|
||||
sizeof(long) == 0)) {
|
||||
aes_block_t *ivp = (aes_block_t *)ivec;
|
||||
aes_block_t *iv2p = (aes_block_t *)(ivec + AES_BLOCK_SIZE);
|
||||
|
||||
while (len) {
|
||||
aes_block_t tmp;
|
||||
aes_block_t *inp = (aes_block_t *)in;
|
||||
aes_block_t *outp = (aes_block_t *)out;
|
||||
|
||||
for (n = 0; n < N_WORDS; ++n)
|
||||
tmp.data[n] = inp->data[n] ^ iv2p->data[n];
|
||||
AES_decrypt((unsigned char *)tmp.data,
|
||||
(unsigned char *)outp->data, key);
|
||||
for (n = 0; n < N_WORDS; ++n)
|
||||
outp->data[n] ^= ivp->data[n];
|
||||
ivp = inp;
|
||||
iv2p = outp;
|
||||
--len;
|
||||
in += AES_BLOCK_SIZE;
|
||||
out += AES_BLOCK_SIZE;
|
||||
}
|
||||
memmove(ivec, ivp->data, AES_BLOCK_SIZE);
|
||||
memmove(ivec + AES_BLOCK_SIZE, iv2p->data, AES_BLOCK_SIZE);
|
||||
} else {
|
||||
aes_block_t tmp, tmp2;
|
||||
aes_block_t iv;
|
||||
aes_block_t iv2;
|
||||
|
||||
load_block(iv, ivec);
|
||||
load_block(iv2, ivec + AES_BLOCK_SIZE);
|
||||
|
||||
while (len) {
|
||||
load_block(tmp, in);
|
||||
tmp2 = tmp;
|
||||
for (n = 0; n < N_WORDS; ++n)
|
||||
tmp.data[n] ^= iv2.data[n];
|
||||
AES_decrypt((unsigned char *)tmp.data,
|
||||
(unsigned char *)tmp.data, key);
|
||||
for (n = 0; n < N_WORDS; ++n)
|
||||
tmp.data[n] ^= iv.data[n];
|
||||
store_block(out, tmp);
|
||||
iv = tmp2;
|
||||
iv2 = tmp;
|
||||
--len;
|
||||
in += AES_BLOCK_SIZE;
|
||||
out += AES_BLOCK_SIZE;
|
||||
}
|
||||
memcpy(ivec, iv.data, AES_BLOCK_SIZE);
|
||||
memcpy(ivec + AES_BLOCK_SIZE, iv2.data, AES_BLOCK_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
83
externals/libressl/crypto/aes/aes_locl.h
vendored
83
externals/libressl/crypto/aes/aes_locl.h
vendored
@@ -1,83 +0,0 @@
|
||||
/* $OpenBSD: aes_locl.h,v 1.11 2016/12/21 15:49:29 jsing Exp $ */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1998-2002 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
|
||||
* openssl-core@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.
|
||||
* ====================================================================
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HEADER_AES_LOCL_H
|
||||
#define HEADER_AES_LOCL_H
|
||||
|
||||
#include <openssl/opensslconf.h>
|
||||
|
||||
#ifdef OPENSSL_NO_AES
|
||||
#error AES is disabled.
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
__BEGIN_HIDDEN_DECLS
|
||||
|
||||
#define GETU32(pt) (((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ ((u32)(pt)[2] << 8) ^ ((u32)(pt)[3]))
|
||||
#define PUTU32(ct, st) { (ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); (ct)[2] = (u8)((st) >> 8); (ct)[3] = (u8)(st); }
|
||||
|
||||
typedef unsigned int u32;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned char u8;
|
||||
|
||||
#define MAXKC (256/32)
|
||||
#define MAXKB (256/8)
|
||||
#define MAXNR 14
|
||||
|
||||
/* This controls loop-unrolling in aes_core.c */
|
||||
#undef FULL_UNROLL
|
||||
|
||||
__END_HIDDEN_DECLS
|
||||
|
||||
#endif /* !HEADER_AES_LOCL_H */
|
||||
65
externals/libressl/crypto/aes/aes_misc.c
vendored
65
externals/libressl/crypto/aes/aes_misc.c
vendored
@@ -1,65 +0,0 @@
|
||||
/* $OpenBSD: aes_misc.c,v 1.10 2014/07/09 11:10:50 bcook Exp $ */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1998-2002 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
|
||||
* openssl-core@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/opensslv.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/aes.h>
|
||||
#include "aes_locl.h"
|
||||
|
||||
const char *
|
||||
AES_options(void)
|
||||
{
|
||||
#ifdef FULL_UNROLL
|
||||
return "aes(full)";
|
||||
#else
|
||||
return "aes(partial)";
|
||||
#endif
|
||||
}
|
||||
61
externals/libressl/crypto/aes/aes_ofb.c
vendored
61
externals/libressl/crypto/aes/aes_ofb.c
vendored
@@ -1,61 +0,0 @@
|
||||
/* $OpenBSD: aes_ofb.c,v 1.6 2014/06/12 15:49:27 deraadt Exp $ */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2002-2006 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
|
||||
* openssl-core@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/aes.h>
|
||||
#include <openssl/modes.h>
|
||||
|
||||
void
|
||||
AES_ofb128_encrypt(const unsigned char *in, unsigned char *out, size_t length,
|
||||
const AES_KEY *key, unsigned char *ivec, int *num)
|
||||
{
|
||||
CRYPTO_ofb128_encrypt(in, out, length, key, ivec, num,
|
||||
(block128_f)AES_encrypt);
|
||||
}
|
||||
133
externals/libressl/crypto/aes/aes_wrap.c
vendored
133
externals/libressl/crypto/aes/aes_wrap.c
vendored
@@ -1,133 +0,0 @@
|
||||
/* $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.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* 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 <string.h>
|
||||
|
||||
#include <openssl/aes.h>
|
||||
#include <openssl/bio.h>
|
||||
|
||||
static const unsigned char default_iv[] = {
|
||||
0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6,
|
||||
};
|
||||
|
||||
int
|
||||
AES_wrap_key(AES_KEY *key, const unsigned char *iv, unsigned char *out,
|
||||
const unsigned char *in, unsigned int inlen)
|
||||
{
|
||||
unsigned char *A, B[16], *R;
|
||||
unsigned int i, j, t;
|
||||
|
||||
if ((inlen & 0x7) || (inlen < 16))
|
||||
return -1;
|
||||
A = B;
|
||||
t = 1;
|
||||
memmove(out + 8, in, inlen);
|
||||
if (!iv)
|
||||
iv = default_iv;
|
||||
|
||||
memcpy(A, iv, 8);
|
||||
|
||||
for (j = 0; j < 6; j++) {
|
||||
R = out + 8;
|
||||
for (i = 0; i < inlen; i += 8, t++, R += 8) {
|
||||
memcpy(B + 8, R, 8);
|
||||
AES_encrypt(B, B, key);
|
||||
A[7] ^= (unsigned char)(t & 0xff);
|
||||
if (t > 0xff) {
|
||||
A[6] ^= (unsigned char)((t >> 8) & 0xff);
|
||||
A[5] ^= (unsigned char)((t >> 16) & 0xff);
|
||||
A[4] ^= (unsigned char)((t >> 24) & 0xff);
|
||||
}
|
||||
memcpy(R, B + 8, 8);
|
||||
}
|
||||
}
|
||||
memcpy(out, A, 8);
|
||||
return inlen + 8;
|
||||
}
|
||||
|
||||
int
|
||||
AES_unwrap_key(AES_KEY *key, const unsigned char *iv, unsigned char *out,
|
||||
const unsigned char *in, unsigned int inlen)
|
||||
{
|
||||
unsigned char *A, B[16], *R;
|
||||
unsigned int i, j, t;
|
||||
|
||||
if ((inlen & 0x7) || (inlen < 24))
|
||||
return -1;
|
||||
inlen -= 8;
|
||||
A = B;
|
||||
t = 6 * (inlen >> 3);
|
||||
memcpy(A, in, 8);
|
||||
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) {
|
||||
A[7] ^= (unsigned char)(t & 0xff);
|
||||
if (t > 0xff) {
|
||||
A[6] ^= (unsigned char)((t >> 8) & 0xff);
|
||||
A[5] ^= (unsigned char)((t >> 16) & 0xff);
|
||||
A[4] ^= (unsigned char)((t >> 24) & 0xff);
|
||||
}
|
||||
memcpy(B + 8, R, 8);
|
||||
AES_decrypt(B, B, key);
|
||||
memcpy(R, B + 8, 8);
|
||||
}
|
||||
}
|
||||
if (!iv)
|
||||
iv = default_iv;
|
||||
if (memcmp(A, iv, 8)) {
|
||||
explicit_bzero(out, inlen);
|
||||
return 0;
|
||||
}
|
||||
return inlen;
|
||||
}
|
||||
2539
externals/libressl/crypto/aes/aesni-elf-x86_64.S
vendored
2539
externals/libressl/crypto/aes/aesni-elf-x86_64.S
vendored
File diff suppressed because it is too large
Load Diff
2536
externals/libressl/crypto/aes/aesni-macosx-x86_64.S
vendored
2536
externals/libressl/crypto/aes/aesni-macosx-x86_64.S
vendored
File diff suppressed because it is too large
Load Diff
3099
externals/libressl/crypto/aes/aesni-masm-x86_64.S
vendored
3099
externals/libressl/crypto/aes/aesni-masm-x86_64.S
vendored
File diff suppressed because it is too large
Load Diff
3008
externals/libressl/crypto/aes/aesni-mingw64-x86_64.S
vendored
3008
externals/libressl/crypto/aes/aesni-mingw64-x86_64.S
vendored
File diff suppressed because it is too large
Load Diff
1401
externals/libressl/crypto/aes/aesni-sha1-elf-x86_64.S
vendored
1401
externals/libressl/crypto/aes/aesni-sha1-elf-x86_64.S
vendored
File diff suppressed because it is too large
Load Diff
1398
externals/libressl/crypto/aes/aesni-sha1-macosx-x86_64.S
vendored
1398
externals/libressl/crypto/aes/aesni-sha1-macosx-x86_64.S
vendored
File diff suppressed because it is too large
Load Diff
1616
externals/libressl/crypto/aes/aesni-sha1-masm-x86_64.S
vendored
1616
externals/libressl/crypto/aes/aesni-sha1-masm-x86_64.S
vendored
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
2502
externals/libressl/crypto/aes/bsaes-elf-x86_64.S
vendored
2502
externals/libressl/crypto/aes/bsaes-elf-x86_64.S
vendored
File diff suppressed because it is too large
Load Diff
2499
externals/libressl/crypto/aes/bsaes-macosx-x86_64.S
vendored
2499
externals/libressl/crypto/aes/bsaes-macosx-x86_64.S
vendored
File diff suppressed because it is too large
Load Diff
2803
externals/libressl/crypto/aes/bsaes-masm-x86_64.S
vendored
2803
externals/libressl/crypto/aes/bsaes-masm-x86_64.S
vendored
File diff suppressed because it is too large
Load Diff
2725
externals/libressl/crypto/aes/bsaes-mingw64-x86_64.S
vendored
2725
externals/libressl/crypto/aes/bsaes-mingw64-x86_64.S
vendored
File diff suppressed because it is too large
Load Diff
832
externals/libressl/crypto/aes/vpaes-elf-x86_64.S
vendored
832
externals/libressl/crypto/aes/vpaes-elf-x86_64.S
vendored
@@ -1,832 +0,0 @@
|
||||
#include "x86_arch.h"
|
||||
.text
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.type _vpaes_encrypt_core,@function
|
||||
.align 16
|
||||
_vpaes_encrypt_core:
|
||||
movq %rdx,%r9
|
||||
movq $16,%r11
|
||||
movl 240(%rdx),%eax
|
||||
movdqa %xmm9,%xmm1
|
||||
movdqa .Lk_ipt(%rip),%xmm2
|
||||
pandn %xmm0,%xmm1
|
||||
movdqu (%r9),%xmm5
|
||||
psrld $4,%xmm1
|
||||
pand %xmm9,%xmm0
|
||||
.byte 102,15,56,0,208
|
||||
movdqa .Lk_ipt+16(%rip),%xmm0
|
||||
.byte 102,15,56,0,193
|
||||
pxor %xmm5,%xmm2
|
||||
pxor %xmm2,%xmm0
|
||||
addq $16,%r9
|
||||
leaq .Lk_mc_backward(%rip),%r10
|
||||
jmp .Lenc_entry
|
||||
|
||||
.align 16
|
||||
.Lenc_loop:
|
||||
|
||||
movdqa %xmm13,%xmm4
|
||||
.byte 102,15,56,0,226
|
||||
pxor %xmm5,%xmm4
|
||||
movdqa %xmm12,%xmm0
|
||||
.byte 102,15,56,0,195
|
||||
pxor %xmm4,%xmm0
|
||||
movdqa %xmm15,%xmm5
|
||||
.byte 102,15,56,0,234
|
||||
movdqa -64(%r11,%r10,1),%xmm1
|
||||
movdqa %xmm14,%xmm2
|
||||
.byte 102,15,56,0,211
|
||||
pxor %xmm5,%xmm2
|
||||
movdqa (%r11,%r10,1),%xmm4
|
||||
movdqa %xmm0,%xmm3
|
||||
.byte 102,15,56,0,193
|
||||
addq $16,%r9
|
||||
pxor %xmm2,%xmm0
|
||||
.byte 102,15,56,0,220
|
||||
addq $16,%r11
|
||||
pxor %xmm0,%xmm3
|
||||
.byte 102,15,56,0,193
|
||||
andq $48,%r11
|
||||
pxor %xmm3,%xmm0
|
||||
subq $1,%rax
|
||||
|
||||
.Lenc_entry:
|
||||
|
||||
movdqa %xmm9,%xmm1
|
||||
pandn %xmm0,%xmm1
|
||||
psrld $4,%xmm1
|
||||
pand %xmm9,%xmm0
|
||||
movdqa %xmm11,%xmm5
|
||||
.byte 102,15,56,0,232
|
||||
pxor %xmm1,%xmm0
|
||||
movdqa %xmm10,%xmm3
|
||||
.byte 102,15,56,0,217
|
||||
pxor %xmm5,%xmm3
|
||||
movdqa %xmm10,%xmm4
|
||||
.byte 102,15,56,0,224
|
||||
pxor %xmm5,%xmm4
|
||||
movdqa %xmm10,%xmm2
|
||||
.byte 102,15,56,0,211
|
||||
pxor %xmm0,%xmm2
|
||||
movdqa %xmm10,%xmm3
|
||||
movdqu (%r9),%xmm5
|
||||
.byte 102,15,56,0,220
|
||||
pxor %xmm1,%xmm3
|
||||
jnz .Lenc_loop
|
||||
|
||||
|
||||
movdqa -96(%r10),%xmm4
|
||||
movdqa -80(%r10),%xmm0
|
||||
.byte 102,15,56,0,226
|
||||
pxor %xmm5,%xmm4
|
||||
.byte 102,15,56,0,195
|
||||
movdqa 64(%r11,%r10,1),%xmm1
|
||||
pxor %xmm4,%xmm0
|
||||
.byte 102,15,56,0,193
|
||||
retq
|
||||
.size _vpaes_encrypt_core,.-_vpaes_encrypt_core
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.type _vpaes_decrypt_core,@function
|
||||
.align 16
|
||||
_vpaes_decrypt_core:
|
||||
movq %rdx,%r9
|
||||
movl 240(%rdx),%eax
|
||||
movdqa %xmm9,%xmm1
|
||||
movdqa .Lk_dipt(%rip),%xmm2
|
||||
pandn %xmm0,%xmm1
|
||||
movq %rax,%r11
|
||||
psrld $4,%xmm1
|
||||
movdqu (%r9),%xmm5
|
||||
shlq $4,%r11
|
||||
pand %xmm9,%xmm0
|
||||
.byte 102,15,56,0,208
|
||||
movdqa .Lk_dipt+16(%rip),%xmm0
|
||||
xorq $48,%r11
|
||||
leaq .Lk_dsbd(%rip),%r10
|
||||
.byte 102,15,56,0,193
|
||||
andq $48,%r11
|
||||
pxor %xmm5,%xmm2
|
||||
movdqa .Lk_mc_forward+48(%rip),%xmm5
|
||||
pxor %xmm2,%xmm0
|
||||
addq $16,%r9
|
||||
addq %r10,%r11
|
||||
jmp .Ldec_entry
|
||||
|
||||
.align 16
|
||||
.Ldec_loop:
|
||||
|
||||
|
||||
|
||||
movdqa -32(%r10),%xmm4
|
||||
.byte 102,15,56,0,226
|
||||
pxor %xmm0,%xmm4
|
||||
movdqa -16(%r10),%xmm0
|
||||
.byte 102,15,56,0,195
|
||||
pxor %xmm4,%xmm0
|
||||
addq $16,%r9
|
||||
|
||||
.byte 102,15,56,0,197
|
||||
movdqa 0(%r10),%xmm4
|
||||
.byte 102,15,56,0,226
|
||||
pxor %xmm0,%xmm4
|
||||
movdqa 16(%r10),%xmm0
|
||||
.byte 102,15,56,0,195
|
||||
pxor %xmm4,%xmm0
|
||||
subq $1,%rax
|
||||
|
||||
.byte 102,15,56,0,197
|
||||
movdqa 32(%r10),%xmm4
|
||||
.byte 102,15,56,0,226
|
||||
pxor %xmm0,%xmm4
|
||||
movdqa 48(%r10),%xmm0
|
||||
.byte 102,15,56,0,195
|
||||
pxor %xmm4,%xmm0
|
||||
|
||||
.byte 102,15,56,0,197
|
||||
movdqa 64(%r10),%xmm4
|
||||
.byte 102,15,56,0,226
|
||||
pxor %xmm0,%xmm4
|
||||
movdqa 80(%r10),%xmm0
|
||||
.byte 102,15,56,0,195
|
||||
pxor %xmm4,%xmm0
|
||||
|
||||
.byte 102,15,58,15,237,12
|
||||
|
||||
.Ldec_entry:
|
||||
|
||||
movdqa %xmm9,%xmm1
|
||||
pandn %xmm0,%xmm1
|
||||
psrld $4,%xmm1
|
||||
pand %xmm9,%xmm0
|
||||
movdqa %xmm11,%xmm2
|
||||
.byte 102,15,56,0,208
|
||||
pxor %xmm1,%xmm0
|
||||
movdqa %xmm10,%xmm3
|
||||
.byte 102,15,56,0,217
|
||||
pxor %xmm2,%xmm3
|
||||
movdqa %xmm10,%xmm4
|
||||
.byte 102,15,56,0,224
|
||||
pxor %xmm2,%xmm4
|
||||
movdqa %xmm10,%xmm2
|
||||
.byte 102,15,56,0,211
|
||||
pxor %xmm0,%xmm2
|
||||
movdqa %xmm10,%xmm3
|
||||
.byte 102,15,56,0,220
|
||||
pxor %xmm1,%xmm3
|
||||
movdqu (%r9),%xmm0
|
||||
jnz .Ldec_loop
|
||||
|
||||
|
||||
movdqa 96(%r10),%xmm4
|
||||
.byte 102,15,56,0,226
|
||||
pxor %xmm0,%xmm4
|
||||
movdqa 112(%r10),%xmm0
|
||||
movdqa -352(%r11),%xmm2
|
||||
.byte 102,15,56,0,195
|
||||
pxor %xmm4,%xmm0
|
||||
.byte 102,15,56,0,194
|
||||
retq
|
||||
.size _vpaes_decrypt_core,.-_vpaes_decrypt_core
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.type _vpaes_schedule_core,@function
|
||||
.align 16
|
||||
_vpaes_schedule_core:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
call _vpaes_preheat
|
||||
movdqa .Lk_rcon(%rip),%xmm8
|
||||
movdqu (%rdi),%xmm0
|
||||
|
||||
|
||||
movdqa %xmm0,%xmm3
|
||||
leaq .Lk_ipt(%rip),%r11
|
||||
call _vpaes_schedule_transform
|
||||
movdqa %xmm0,%xmm7
|
||||
|
||||
leaq .Lk_sr(%rip),%r10
|
||||
testq %rcx,%rcx
|
||||
jnz .Lschedule_am_decrypting
|
||||
|
||||
|
||||
movdqu %xmm0,(%rdx)
|
||||
jmp .Lschedule_go
|
||||
|
||||
.Lschedule_am_decrypting:
|
||||
|
||||
movdqa (%r8,%r10,1),%xmm1
|
||||
.byte 102,15,56,0,217
|
||||
movdqu %xmm3,(%rdx)
|
||||
xorq $48,%r8
|
||||
|
||||
.Lschedule_go:
|
||||
cmpl $192,%esi
|
||||
ja .Lschedule_256
|
||||
je .Lschedule_192
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.Lschedule_128:
|
||||
movl $10,%esi
|
||||
|
||||
.Loop_schedule_128:
|
||||
call _vpaes_schedule_round
|
||||
decq %rsi
|
||||
jz .Lschedule_mangle_last
|
||||
call _vpaes_schedule_mangle
|
||||
jmp .Loop_schedule_128
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.align 16
|
||||
.Lschedule_192:
|
||||
movdqu 8(%rdi),%xmm0
|
||||
call _vpaes_schedule_transform
|
||||
movdqa %xmm0,%xmm6
|
||||
pxor %xmm4,%xmm4
|
||||
movhlps %xmm4,%xmm6
|
||||
movl $4,%esi
|
||||
|
||||
.Loop_schedule_192:
|
||||
call _vpaes_schedule_round
|
||||
.byte 102,15,58,15,198,8
|
||||
call _vpaes_schedule_mangle
|
||||
call _vpaes_schedule_192_smear
|
||||
call _vpaes_schedule_mangle
|
||||
call _vpaes_schedule_round
|
||||
decq %rsi
|
||||
jz .Lschedule_mangle_last
|
||||
call _vpaes_schedule_mangle
|
||||
call _vpaes_schedule_192_smear
|
||||
jmp .Loop_schedule_192
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.align 16
|
||||
.Lschedule_256:
|
||||
movdqu 16(%rdi),%xmm0
|
||||
call _vpaes_schedule_transform
|
||||
movl $7,%esi
|
||||
|
||||
.Loop_schedule_256:
|
||||
call _vpaes_schedule_mangle
|
||||
movdqa %xmm0,%xmm6
|
||||
|
||||
|
||||
call _vpaes_schedule_round
|
||||
decq %rsi
|
||||
jz .Lschedule_mangle_last
|
||||
call _vpaes_schedule_mangle
|
||||
|
||||
|
||||
pshufd $255,%xmm0,%xmm0
|
||||
movdqa %xmm7,%xmm5
|
||||
movdqa %xmm6,%xmm7
|
||||
call _vpaes_schedule_low_round
|
||||
movdqa %xmm5,%xmm7
|
||||
|
||||
jmp .Loop_schedule_256
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.align 16
|
||||
.Lschedule_mangle_last:
|
||||
|
||||
leaq .Lk_deskew(%rip),%r11
|
||||
testq %rcx,%rcx
|
||||
jnz .Lschedule_mangle_last_dec
|
||||
|
||||
|
||||
movdqa (%r8,%r10,1),%xmm1
|
||||
.byte 102,15,56,0,193
|
||||
leaq .Lk_opt(%rip),%r11
|
||||
addq $32,%rdx
|
||||
|
||||
.Lschedule_mangle_last_dec:
|
||||
addq $-16,%rdx
|
||||
pxor .Lk_s63(%rip),%xmm0
|
||||
call _vpaes_schedule_transform
|
||||
movdqu %xmm0,(%rdx)
|
||||
|
||||
|
||||
pxor %xmm0,%xmm0
|
||||
pxor %xmm1,%xmm1
|
||||
pxor %xmm2,%xmm2
|
||||
pxor %xmm3,%xmm3
|
||||
pxor %xmm4,%xmm4
|
||||
pxor %xmm5,%xmm5
|
||||
pxor %xmm6,%xmm6
|
||||
pxor %xmm7,%xmm7
|
||||
retq
|
||||
.size _vpaes_schedule_core,.-_vpaes_schedule_core
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.type _vpaes_schedule_192_smear,@function
|
||||
.align 16
|
||||
_vpaes_schedule_192_smear:
|
||||
pshufd $128,%xmm6,%xmm0
|
||||
pxor %xmm0,%xmm6
|
||||
pshufd $254,%xmm7,%xmm0
|
||||
pxor %xmm0,%xmm6
|
||||
movdqa %xmm6,%xmm0
|
||||
pxor %xmm1,%xmm1
|
||||
movhlps %xmm1,%xmm6
|
||||
retq
|
||||
.size _vpaes_schedule_192_smear,.-_vpaes_schedule_192_smear
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.type _vpaes_schedule_round,@function
|
||||
.align 16
|
||||
_vpaes_schedule_round:
|
||||
|
||||
pxor %xmm1,%xmm1
|
||||
.byte 102,65,15,58,15,200,15
|
||||
.byte 102,69,15,58,15,192,15
|
||||
pxor %xmm1,%xmm7
|
||||
|
||||
|
||||
pshufd $255,%xmm0,%xmm0
|
||||
.byte 102,15,58,15,192,1
|
||||
|
||||
|
||||
|
||||
|
||||
_vpaes_schedule_low_round:
|
||||
|
||||
movdqa %xmm7,%xmm1
|
||||
pslldq $4,%xmm7
|
||||
pxor %xmm1,%xmm7
|
||||
movdqa %xmm7,%xmm1
|
||||
pslldq $8,%xmm7
|
||||
pxor %xmm1,%xmm7
|
||||
pxor .Lk_s63(%rip),%xmm7
|
||||
|
||||
|
||||
movdqa %xmm9,%xmm1
|
||||
pandn %xmm0,%xmm1
|
||||
psrld $4,%xmm1
|
||||
pand %xmm9,%xmm0
|
||||
movdqa %xmm11,%xmm2
|
||||
.byte 102,15,56,0,208
|
||||
pxor %xmm1,%xmm0
|
||||
movdqa %xmm10,%xmm3
|
||||
.byte 102,15,56,0,217
|
||||
pxor %xmm2,%xmm3
|
||||
movdqa %xmm10,%xmm4
|
||||
.byte 102,15,56,0,224
|
||||
pxor %xmm2,%xmm4
|
||||
movdqa %xmm10,%xmm2
|
||||
.byte 102,15,56,0,211
|
||||
pxor %xmm0,%xmm2
|
||||
movdqa %xmm10,%xmm3
|
||||
.byte 102,15,56,0,220
|
||||
pxor %xmm1,%xmm3
|
||||
movdqa %xmm13,%xmm4
|
||||
.byte 102,15,56,0,226
|
||||
movdqa %xmm12,%xmm0
|
||||
.byte 102,15,56,0,195
|
||||
pxor %xmm4,%xmm0
|
||||
|
||||
|
||||
pxor %xmm7,%xmm0
|
||||
movdqa %xmm0,%xmm7
|
||||
retq
|
||||
.size _vpaes_schedule_round,.-_vpaes_schedule_round
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.type _vpaes_schedule_transform,@function
|
||||
.align 16
|
||||
_vpaes_schedule_transform:
|
||||
movdqa %xmm9,%xmm1
|
||||
pandn %xmm0,%xmm1
|
||||
psrld $4,%xmm1
|
||||
pand %xmm9,%xmm0
|
||||
movdqa (%r11),%xmm2
|
||||
.byte 102,15,56,0,208
|
||||
movdqa 16(%r11),%xmm0
|
||||
.byte 102,15,56,0,193
|
||||
pxor %xmm2,%xmm0
|
||||
retq
|
||||
.size _vpaes_schedule_transform,.-_vpaes_schedule_transform
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.type _vpaes_schedule_mangle,@function
|
||||
.align 16
|
||||
_vpaes_schedule_mangle:
|
||||
movdqa %xmm0,%xmm4
|
||||
movdqa .Lk_mc_forward(%rip),%xmm5
|
||||
testq %rcx,%rcx
|
||||
jnz .Lschedule_mangle_dec
|
||||
|
||||
|
||||
addq $16,%rdx
|
||||
pxor .Lk_s63(%rip),%xmm4
|
||||
.byte 102,15,56,0,229
|
||||
movdqa %xmm4,%xmm3
|
||||
.byte 102,15,56,0,229
|
||||
pxor %xmm4,%xmm3
|
||||
.byte 102,15,56,0,229
|
||||
pxor %xmm4,%xmm3
|
||||
|
||||
jmp .Lschedule_mangle_both
|
||||
.align 16
|
||||
.Lschedule_mangle_dec:
|
||||
|
||||
leaq .Lk_dksd(%rip),%r11
|
||||
movdqa %xmm9,%xmm1
|
||||
pandn %xmm4,%xmm1
|
||||
psrld $4,%xmm1
|
||||
pand %xmm9,%xmm4
|
||||
|
||||
movdqa 0(%r11),%xmm2
|
||||
.byte 102,15,56,0,212
|
||||
movdqa 16(%r11),%xmm3
|
||||
.byte 102,15,56,0,217
|
||||
pxor %xmm2,%xmm3
|
||||
.byte 102,15,56,0,221
|
||||
|
||||
movdqa 32(%r11),%xmm2
|
||||
.byte 102,15,56,0,212
|
||||
pxor %xmm3,%xmm2
|
||||
movdqa 48(%r11),%xmm3
|
||||
.byte 102,15,56,0,217
|
||||
pxor %xmm2,%xmm3
|
||||
.byte 102,15,56,0,221
|
||||
|
||||
movdqa 64(%r11),%xmm2
|
||||
.byte 102,15,56,0,212
|
||||
pxor %xmm3,%xmm2
|
||||
movdqa 80(%r11),%xmm3
|
||||
.byte 102,15,56,0,217
|
||||
pxor %xmm2,%xmm3
|
||||
.byte 102,15,56,0,221
|
||||
|
||||
movdqa 96(%r11),%xmm2
|
||||
.byte 102,15,56,0,212
|
||||
pxor %xmm3,%xmm2
|
||||
movdqa 112(%r11),%xmm3
|
||||
.byte 102,15,56,0,217
|
||||
pxor %xmm2,%xmm3
|
||||
|
||||
addq $-16,%rdx
|
||||
|
||||
.Lschedule_mangle_both:
|
||||
movdqa (%r8,%r10,1),%xmm1
|
||||
.byte 102,15,56,0,217
|
||||
addq $-16,%r8
|
||||
andq $48,%r8
|
||||
movdqu %xmm3,(%rdx)
|
||||
retq
|
||||
.size _vpaes_schedule_mangle,.-_vpaes_schedule_mangle
|
||||
|
||||
|
||||
|
||||
|
||||
.globl vpaes_set_encrypt_key
|
||||
.type vpaes_set_encrypt_key,@function
|
||||
.align 16
|
||||
vpaes_set_encrypt_key:
|
||||
movl %esi,%eax
|
||||
shrl $5,%eax
|
||||
addl $5,%eax
|
||||
movl %eax,240(%rdx)
|
||||
|
||||
movl $0,%ecx
|
||||
movl $48,%r8d
|
||||
call _vpaes_schedule_core
|
||||
xorl %eax,%eax
|
||||
retq
|
||||
.size vpaes_set_encrypt_key,.-vpaes_set_encrypt_key
|
||||
|
||||
.globl vpaes_set_decrypt_key
|
||||
.type vpaes_set_decrypt_key,@function
|
||||
.align 16
|
||||
vpaes_set_decrypt_key:
|
||||
movl %esi,%eax
|
||||
shrl $5,%eax
|
||||
addl $5,%eax
|
||||
movl %eax,240(%rdx)
|
||||
shll $4,%eax
|
||||
leaq 16(%rdx,%rax,1),%rdx
|
||||
|
||||
movl $1,%ecx
|
||||
movl %esi,%r8d
|
||||
shrl $1,%r8d
|
||||
andl $32,%r8d
|
||||
xorl $32,%r8d
|
||||
call _vpaes_schedule_core
|
||||
xorl %eax,%eax
|
||||
retq
|
||||
.size vpaes_set_decrypt_key,.-vpaes_set_decrypt_key
|
||||
|
||||
.globl vpaes_encrypt
|
||||
.type vpaes_encrypt,@function
|
||||
.align 16
|
||||
vpaes_encrypt:
|
||||
movdqu (%rdi),%xmm0
|
||||
call _vpaes_preheat
|
||||
call _vpaes_encrypt_core
|
||||
movdqu %xmm0,(%rsi)
|
||||
retq
|
||||
.size vpaes_encrypt,.-vpaes_encrypt
|
||||
|
||||
.globl vpaes_decrypt
|
||||
.type vpaes_decrypt,@function
|
||||
.align 16
|
||||
vpaes_decrypt:
|
||||
movdqu (%rdi),%xmm0
|
||||
call _vpaes_preheat
|
||||
call _vpaes_decrypt_core
|
||||
movdqu %xmm0,(%rsi)
|
||||
retq
|
||||
.size vpaes_decrypt,.-vpaes_decrypt
|
||||
.globl vpaes_cbc_encrypt
|
||||
.type vpaes_cbc_encrypt,@function
|
||||
.align 16
|
||||
vpaes_cbc_encrypt:
|
||||
xchgq %rcx,%rdx
|
||||
subq $16,%rcx
|
||||
jc .Lcbc_abort
|
||||
movdqu (%r8),%xmm6
|
||||
subq %rdi,%rsi
|
||||
call _vpaes_preheat
|
||||
cmpl $0,%r9d
|
||||
je .Lcbc_dec_loop
|
||||
jmp .Lcbc_enc_loop
|
||||
.align 16
|
||||
.Lcbc_enc_loop:
|
||||
movdqu (%rdi),%xmm0
|
||||
pxor %xmm6,%xmm0
|
||||
call _vpaes_encrypt_core
|
||||
movdqa %xmm0,%xmm6
|
||||
movdqu %xmm0,(%rsi,%rdi,1)
|
||||
leaq 16(%rdi),%rdi
|
||||
subq $16,%rcx
|
||||
jnc .Lcbc_enc_loop
|
||||
jmp .Lcbc_done
|
||||
.align 16
|
||||
.Lcbc_dec_loop:
|
||||
movdqu (%rdi),%xmm0
|
||||
movdqa %xmm0,%xmm7
|
||||
call _vpaes_decrypt_core
|
||||
pxor %xmm6,%xmm0
|
||||
movdqa %xmm7,%xmm6
|
||||
movdqu %xmm0,(%rsi,%rdi,1)
|
||||
leaq 16(%rdi),%rdi
|
||||
subq $16,%rcx
|
||||
jnc .Lcbc_dec_loop
|
||||
.Lcbc_done:
|
||||
movdqu %xmm6,(%r8)
|
||||
.Lcbc_abort:
|
||||
retq
|
||||
.size vpaes_cbc_encrypt,.-vpaes_cbc_encrypt
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.type _vpaes_preheat,@function
|
||||
.align 16
|
||||
_vpaes_preheat:
|
||||
leaq .Lk_s0F(%rip),%r10
|
||||
movdqa -32(%r10),%xmm10
|
||||
movdqa -16(%r10),%xmm11
|
||||
movdqa 0(%r10),%xmm9
|
||||
movdqa 48(%r10),%xmm13
|
||||
movdqa 64(%r10),%xmm12
|
||||
movdqa 80(%r10),%xmm15
|
||||
movdqa 96(%r10),%xmm14
|
||||
retq
|
||||
.size _vpaes_preheat,.-_vpaes_preheat
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.type _vpaes_consts,@object
|
||||
.align 64
|
||||
_vpaes_consts:
|
||||
.Lk_inv:
|
||||
.quad 0x0E05060F0D080180, 0x040703090A0B0C02
|
||||
.quad 0x01040A060F0B0780, 0x030D0E0C02050809
|
||||
|
||||
.Lk_s0F:
|
||||
.quad 0x0F0F0F0F0F0F0F0F, 0x0F0F0F0F0F0F0F0F
|
||||
|
||||
.Lk_ipt:
|
||||
.quad 0xC2B2E8985A2A7000, 0xCABAE09052227808
|
||||
.quad 0x4C01307D317C4D00, 0xCD80B1FCB0FDCC81
|
||||
|
||||
.Lk_sb1:
|
||||
.quad 0xB19BE18FCB503E00, 0xA5DF7A6E142AF544
|
||||
.quad 0x3618D415FAE22300, 0x3BF7CCC10D2ED9EF
|
||||
.Lk_sb2:
|
||||
.quad 0xE27A93C60B712400, 0x5EB7E955BC982FCD
|
||||
.quad 0x69EB88400AE12900, 0xC2A163C8AB82234A
|
||||
.Lk_sbo:
|
||||
.quad 0xD0D26D176FBDC700, 0x15AABF7AC502A878
|
||||
.quad 0xCFE474A55FBB6A00, 0x8E1E90D1412B35FA
|
||||
|
||||
.Lk_mc_forward:
|
||||
.quad 0x0407060500030201, 0x0C0F0E0D080B0A09
|
||||
.quad 0x080B0A0904070605, 0x000302010C0F0E0D
|
||||
.quad 0x0C0F0E0D080B0A09, 0x0407060500030201
|
||||
.quad 0x000302010C0F0E0D, 0x080B0A0904070605
|
||||
|
||||
.Lk_mc_backward:
|
||||
.quad 0x0605040702010003, 0x0E0D0C0F0A09080B
|
||||
.quad 0x020100030E0D0C0F, 0x0A09080B06050407
|
||||
.quad 0x0E0D0C0F0A09080B, 0x0605040702010003
|
||||
.quad 0x0A09080B06050407, 0x020100030E0D0C0F
|
||||
|
||||
.Lk_sr:
|
||||
.quad 0x0706050403020100, 0x0F0E0D0C0B0A0908
|
||||
.quad 0x030E09040F0A0500, 0x0B06010C07020D08
|
||||
.quad 0x0F060D040B020900, 0x070E050C030A0108
|
||||
.quad 0x0B0E0104070A0D00, 0x0306090C0F020508
|
||||
|
||||
.Lk_rcon:
|
||||
.quad 0x1F8391B9AF9DEEB6, 0x702A98084D7C7D81
|
||||
|
||||
.Lk_s63:
|
||||
.quad 0x5B5B5B5B5B5B5B5B, 0x5B5B5B5B5B5B5B5B
|
||||
|
||||
.Lk_opt:
|
||||
.quad 0xFF9F4929D6B66000, 0xF7974121DEBE6808
|
||||
.quad 0x01EDBD5150BCEC00, 0xE10D5DB1B05C0CE0
|
||||
|
||||
.Lk_deskew:
|
||||
.quad 0x07E4A34047A4E300, 0x1DFEB95A5DBEF91A
|
||||
.quad 0x5F36B5DC83EA6900, 0x2841C2ABF49D1E77
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.Lk_dksd:
|
||||
.quad 0xFEB91A5DA3E44700, 0x0740E3A45A1DBEF9
|
||||
.quad 0x41C277F4B5368300, 0x5FDC69EAAB289D1E
|
||||
.Lk_dksb:
|
||||
.quad 0x9A4FCA1F8550D500, 0x03D653861CC94C99
|
||||
.quad 0x115BEDA7B6FC4A00, 0xD993256F7E3482C8
|
||||
.Lk_dkse:
|
||||
.quad 0xD5031CCA1FC9D600, 0x53859A4C994F5086
|
||||
.quad 0xA23196054FDC7BE8, 0xCD5EF96A20B31487
|
||||
.Lk_dks9:
|
||||
.quad 0xB6116FC87ED9A700, 0x4AED933482255BFC
|
||||
.quad 0x4576516227143300, 0x8BB89FACE9DAFDCE
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.Lk_dipt:
|
||||
.quad 0x0F505B040B545F00, 0x154A411E114E451A
|
||||
.quad 0x86E383E660056500, 0x12771772F491F194
|
||||
|
||||
.Lk_dsb9:
|
||||
.quad 0x851C03539A86D600, 0xCAD51F504F994CC9
|
||||
.quad 0xC03B1789ECD74900, 0x725E2C9EB2FBA565
|
||||
.Lk_dsbd:
|
||||
.quad 0x7D57CCDFE6B1A200, 0xF56E9B13882A4439
|
||||
.quad 0x3CE2FAF724C6CB00, 0x2931180D15DEEFD3
|
||||
.Lk_dsbb:
|
||||
.quad 0xD022649296B44200, 0x602646F6B0F2D404
|
||||
.quad 0xC19498A6CD596700, 0xF3FF0C3E3255AA6B
|
||||
.Lk_dsbe:
|
||||
.quad 0x46F2929626D4D000, 0x2242600464B4F6B0
|
||||
.quad 0x0C55A6CDFFAAC100, 0x9467F36B98593E32
|
||||
.Lk_dsbo:
|
||||
.quad 0x1387EA537EF94000, 0xC7AA6DB9D4943E2D
|
||||
.quad 0x12D7560F93441D00, 0xCA4B8159D8C58E9C
|
||||
.byte 86,101,99,116,111,114,32,80,101,114,109,117,116,97,116,105,111,110,32,65,69,83,32,102,111,114,32,120,56,54,95,54,52,47,83,83,83,69,51,44,32,77,105,107,101,32,72,97,109,98,117,114,103,32,40,83,116,97,110,102,111,114,100,32,85,110,105,118,101,114,115,105,116,121,41,0
|
||||
.align 64
|
||||
.size _vpaes_consts,.-_vpaes_consts
|
||||
#if defined(HAVE_GNU_STACK)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
829
externals/libressl/crypto/aes/vpaes-macosx-x86_64.S
vendored
829
externals/libressl/crypto/aes/vpaes-macosx-x86_64.S
vendored
@@ -1,829 +0,0 @@
|
||||
#include "x86_arch.h"
|
||||
.text
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.p2align 4
|
||||
_vpaes_encrypt_core:
|
||||
movq %rdx,%r9
|
||||
movq $16,%r11
|
||||
movl 240(%rdx),%eax
|
||||
movdqa %xmm9,%xmm1
|
||||
movdqa L$k_ipt(%rip),%xmm2
|
||||
pandn %xmm0,%xmm1
|
||||
movdqu (%r9),%xmm5
|
||||
psrld $4,%xmm1
|
||||
pand %xmm9,%xmm0
|
||||
.byte 102,15,56,0,208
|
||||
movdqa L$k_ipt+16(%rip),%xmm0
|
||||
.byte 102,15,56,0,193
|
||||
pxor %xmm5,%xmm2
|
||||
pxor %xmm2,%xmm0
|
||||
addq $16,%r9
|
||||
leaq L$k_mc_backward(%rip),%r10
|
||||
jmp L$enc_entry
|
||||
|
||||
.p2align 4
|
||||
L$enc_loop:
|
||||
|
||||
movdqa %xmm13,%xmm4
|
||||
.byte 102,15,56,0,226
|
||||
pxor %xmm5,%xmm4
|
||||
movdqa %xmm12,%xmm0
|
||||
.byte 102,15,56,0,195
|
||||
pxor %xmm4,%xmm0
|
||||
movdqa %xmm15,%xmm5
|
||||
.byte 102,15,56,0,234
|
||||
movdqa -64(%r11,%r10,1),%xmm1
|
||||
movdqa %xmm14,%xmm2
|
||||
.byte 102,15,56,0,211
|
||||
pxor %xmm5,%xmm2
|
||||
movdqa (%r11,%r10,1),%xmm4
|
||||
movdqa %xmm0,%xmm3
|
||||
.byte 102,15,56,0,193
|
||||
addq $16,%r9
|
||||
pxor %xmm2,%xmm0
|
||||
.byte 102,15,56,0,220
|
||||
addq $16,%r11
|
||||
pxor %xmm0,%xmm3
|
||||
.byte 102,15,56,0,193
|
||||
andq $48,%r11
|
||||
pxor %xmm3,%xmm0
|
||||
subq $1,%rax
|
||||
|
||||
L$enc_entry:
|
||||
|
||||
movdqa %xmm9,%xmm1
|
||||
pandn %xmm0,%xmm1
|
||||
psrld $4,%xmm1
|
||||
pand %xmm9,%xmm0
|
||||
movdqa %xmm11,%xmm5
|
||||
.byte 102,15,56,0,232
|
||||
pxor %xmm1,%xmm0
|
||||
movdqa %xmm10,%xmm3
|
||||
.byte 102,15,56,0,217
|
||||
pxor %xmm5,%xmm3
|
||||
movdqa %xmm10,%xmm4
|
||||
.byte 102,15,56,0,224
|
||||
pxor %xmm5,%xmm4
|
||||
movdqa %xmm10,%xmm2
|
||||
.byte 102,15,56,0,211
|
||||
pxor %xmm0,%xmm2
|
||||
movdqa %xmm10,%xmm3
|
||||
movdqu (%r9),%xmm5
|
||||
.byte 102,15,56,0,220
|
||||
pxor %xmm1,%xmm3
|
||||
jnz L$enc_loop
|
||||
|
||||
|
||||
movdqa -96(%r10),%xmm4
|
||||
movdqa -80(%r10),%xmm0
|
||||
.byte 102,15,56,0,226
|
||||
pxor %xmm5,%xmm4
|
||||
.byte 102,15,56,0,195
|
||||
movdqa 64(%r11,%r10,1),%xmm1
|
||||
pxor %xmm4,%xmm0
|
||||
.byte 102,15,56,0,193
|
||||
retq
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.p2align 4
|
||||
_vpaes_decrypt_core:
|
||||
movq %rdx,%r9
|
||||
movl 240(%rdx),%eax
|
||||
movdqa %xmm9,%xmm1
|
||||
movdqa L$k_dipt(%rip),%xmm2
|
||||
pandn %xmm0,%xmm1
|
||||
movq %rax,%r11
|
||||
psrld $4,%xmm1
|
||||
movdqu (%r9),%xmm5
|
||||
shlq $4,%r11
|
||||
pand %xmm9,%xmm0
|
||||
.byte 102,15,56,0,208
|
||||
movdqa L$k_dipt+16(%rip),%xmm0
|
||||
xorq $48,%r11
|
||||
leaq L$k_dsbd(%rip),%r10
|
||||
.byte 102,15,56,0,193
|
||||
andq $48,%r11
|
||||
pxor %xmm5,%xmm2
|
||||
movdqa L$k_mc_forward+48(%rip),%xmm5
|
||||
pxor %xmm2,%xmm0
|
||||
addq $16,%r9
|
||||
addq %r10,%r11
|
||||
jmp L$dec_entry
|
||||
|
||||
.p2align 4
|
||||
L$dec_loop:
|
||||
|
||||
|
||||
|
||||
movdqa -32(%r10),%xmm4
|
||||
.byte 102,15,56,0,226
|
||||
pxor %xmm0,%xmm4
|
||||
movdqa -16(%r10),%xmm0
|
||||
.byte 102,15,56,0,195
|
||||
pxor %xmm4,%xmm0
|
||||
addq $16,%r9
|
||||
|
||||
.byte 102,15,56,0,197
|
||||
movdqa 0(%r10),%xmm4
|
||||
.byte 102,15,56,0,226
|
||||
pxor %xmm0,%xmm4
|
||||
movdqa 16(%r10),%xmm0
|
||||
.byte 102,15,56,0,195
|
||||
pxor %xmm4,%xmm0
|
||||
subq $1,%rax
|
||||
|
||||
.byte 102,15,56,0,197
|
||||
movdqa 32(%r10),%xmm4
|
||||
.byte 102,15,56,0,226
|
||||
pxor %xmm0,%xmm4
|
||||
movdqa 48(%r10),%xmm0
|
||||
.byte 102,15,56,0,195
|
||||
pxor %xmm4,%xmm0
|
||||
|
||||
.byte 102,15,56,0,197
|
||||
movdqa 64(%r10),%xmm4
|
||||
.byte 102,15,56,0,226
|
||||
pxor %xmm0,%xmm4
|
||||
movdqa 80(%r10),%xmm0
|
||||
.byte 102,15,56,0,195
|
||||
pxor %xmm4,%xmm0
|
||||
|
||||
.byte 102,15,58,15,237,12
|
||||
|
||||
L$dec_entry:
|
||||
|
||||
movdqa %xmm9,%xmm1
|
||||
pandn %xmm0,%xmm1
|
||||
psrld $4,%xmm1
|
||||
pand %xmm9,%xmm0
|
||||
movdqa %xmm11,%xmm2
|
||||
.byte 102,15,56,0,208
|
||||
pxor %xmm1,%xmm0
|
||||
movdqa %xmm10,%xmm3
|
||||
.byte 102,15,56,0,217
|
||||
pxor %xmm2,%xmm3
|
||||
movdqa %xmm10,%xmm4
|
||||
.byte 102,15,56,0,224
|
||||
pxor %xmm2,%xmm4
|
||||
movdqa %xmm10,%xmm2
|
||||
.byte 102,15,56,0,211
|
||||
pxor %xmm0,%xmm2
|
||||
movdqa %xmm10,%xmm3
|
||||
.byte 102,15,56,0,220
|
||||
pxor %xmm1,%xmm3
|
||||
movdqu (%r9),%xmm0
|
||||
jnz L$dec_loop
|
||||
|
||||
|
||||
movdqa 96(%r10),%xmm4
|
||||
.byte 102,15,56,0,226
|
||||
pxor %xmm0,%xmm4
|
||||
movdqa 112(%r10),%xmm0
|
||||
movdqa -352(%r11),%xmm2
|
||||
.byte 102,15,56,0,195
|
||||
pxor %xmm4,%xmm0
|
||||
.byte 102,15,56,0,194
|
||||
retq
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.p2align 4
|
||||
_vpaes_schedule_core:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
call _vpaes_preheat
|
||||
movdqa L$k_rcon(%rip),%xmm8
|
||||
movdqu (%rdi),%xmm0
|
||||
|
||||
|
||||
movdqa %xmm0,%xmm3
|
||||
leaq L$k_ipt(%rip),%r11
|
||||
call _vpaes_schedule_transform
|
||||
movdqa %xmm0,%xmm7
|
||||
|
||||
leaq L$k_sr(%rip),%r10
|
||||
testq %rcx,%rcx
|
||||
jnz L$schedule_am_decrypting
|
||||
|
||||
|
||||
movdqu %xmm0,(%rdx)
|
||||
jmp L$schedule_go
|
||||
|
||||
L$schedule_am_decrypting:
|
||||
|
||||
movdqa (%r8,%r10,1),%xmm1
|
||||
.byte 102,15,56,0,217
|
||||
movdqu %xmm3,(%rdx)
|
||||
xorq $48,%r8
|
||||
|
||||
L$schedule_go:
|
||||
cmpl $192,%esi
|
||||
ja L$schedule_256
|
||||
je L$schedule_192
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
L$schedule_128:
|
||||
movl $10,%esi
|
||||
|
||||
L$oop_schedule_128:
|
||||
call _vpaes_schedule_round
|
||||
decq %rsi
|
||||
jz L$schedule_mangle_last
|
||||
call _vpaes_schedule_mangle
|
||||
jmp L$oop_schedule_128
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.p2align 4
|
||||
L$schedule_192:
|
||||
movdqu 8(%rdi),%xmm0
|
||||
call _vpaes_schedule_transform
|
||||
movdqa %xmm0,%xmm6
|
||||
pxor %xmm4,%xmm4
|
||||
movhlps %xmm4,%xmm6
|
||||
movl $4,%esi
|
||||
|
||||
L$oop_schedule_192:
|
||||
call _vpaes_schedule_round
|
||||
.byte 102,15,58,15,198,8
|
||||
call _vpaes_schedule_mangle
|
||||
call _vpaes_schedule_192_smear
|
||||
call _vpaes_schedule_mangle
|
||||
call _vpaes_schedule_round
|
||||
decq %rsi
|
||||
jz L$schedule_mangle_last
|
||||
call _vpaes_schedule_mangle
|
||||
call _vpaes_schedule_192_smear
|
||||
jmp L$oop_schedule_192
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.p2align 4
|
||||
L$schedule_256:
|
||||
movdqu 16(%rdi),%xmm0
|
||||
call _vpaes_schedule_transform
|
||||
movl $7,%esi
|
||||
|
||||
L$oop_schedule_256:
|
||||
call _vpaes_schedule_mangle
|
||||
movdqa %xmm0,%xmm6
|
||||
|
||||
|
||||
call _vpaes_schedule_round
|
||||
decq %rsi
|
||||
jz L$schedule_mangle_last
|
||||
call _vpaes_schedule_mangle
|
||||
|
||||
|
||||
pshufd $255,%xmm0,%xmm0
|
||||
movdqa %xmm7,%xmm5
|
||||
movdqa %xmm6,%xmm7
|
||||
call _vpaes_schedule_low_round
|
||||
movdqa %xmm5,%xmm7
|
||||
|
||||
jmp L$oop_schedule_256
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.p2align 4
|
||||
L$schedule_mangle_last:
|
||||
|
||||
leaq L$k_deskew(%rip),%r11
|
||||
testq %rcx,%rcx
|
||||
jnz L$schedule_mangle_last_dec
|
||||
|
||||
|
||||
movdqa (%r8,%r10,1),%xmm1
|
||||
.byte 102,15,56,0,193
|
||||
leaq L$k_opt(%rip),%r11
|
||||
addq $32,%rdx
|
||||
|
||||
L$schedule_mangle_last_dec:
|
||||
addq $-16,%rdx
|
||||
pxor L$k_s63(%rip),%xmm0
|
||||
call _vpaes_schedule_transform
|
||||
movdqu %xmm0,(%rdx)
|
||||
|
||||
|
||||
pxor %xmm0,%xmm0
|
||||
pxor %xmm1,%xmm1
|
||||
pxor %xmm2,%xmm2
|
||||
pxor %xmm3,%xmm3
|
||||
pxor %xmm4,%xmm4
|
||||
pxor %xmm5,%xmm5
|
||||
pxor %xmm6,%xmm6
|
||||
pxor %xmm7,%xmm7
|
||||
retq
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.p2align 4
|
||||
_vpaes_schedule_192_smear:
|
||||
pshufd $128,%xmm6,%xmm0
|
||||
pxor %xmm0,%xmm6
|
||||
pshufd $254,%xmm7,%xmm0
|
||||
pxor %xmm0,%xmm6
|
||||
movdqa %xmm6,%xmm0
|
||||
pxor %xmm1,%xmm1
|
||||
movhlps %xmm1,%xmm6
|
||||
retq
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.p2align 4
|
||||
_vpaes_schedule_round:
|
||||
|
||||
pxor %xmm1,%xmm1
|
||||
.byte 102,65,15,58,15,200,15
|
||||
.byte 102,69,15,58,15,192,15
|
||||
pxor %xmm1,%xmm7
|
||||
|
||||
|
||||
pshufd $255,%xmm0,%xmm0
|
||||
.byte 102,15,58,15,192,1
|
||||
|
||||
|
||||
|
||||
|
||||
_vpaes_schedule_low_round:
|
||||
|
||||
movdqa %xmm7,%xmm1
|
||||
pslldq $4,%xmm7
|
||||
pxor %xmm1,%xmm7
|
||||
movdqa %xmm7,%xmm1
|
||||
pslldq $8,%xmm7
|
||||
pxor %xmm1,%xmm7
|
||||
pxor L$k_s63(%rip),%xmm7
|
||||
|
||||
|
||||
movdqa %xmm9,%xmm1
|
||||
pandn %xmm0,%xmm1
|
||||
psrld $4,%xmm1
|
||||
pand %xmm9,%xmm0
|
||||
movdqa %xmm11,%xmm2
|
||||
.byte 102,15,56,0,208
|
||||
pxor %xmm1,%xmm0
|
||||
movdqa %xmm10,%xmm3
|
||||
.byte 102,15,56,0,217
|
||||
pxor %xmm2,%xmm3
|
||||
movdqa %xmm10,%xmm4
|
||||
.byte 102,15,56,0,224
|
||||
pxor %xmm2,%xmm4
|
||||
movdqa %xmm10,%xmm2
|
||||
.byte 102,15,56,0,211
|
||||
pxor %xmm0,%xmm2
|
||||
movdqa %xmm10,%xmm3
|
||||
.byte 102,15,56,0,220
|
||||
pxor %xmm1,%xmm3
|
||||
movdqa %xmm13,%xmm4
|
||||
.byte 102,15,56,0,226
|
||||
movdqa %xmm12,%xmm0
|
||||
.byte 102,15,56,0,195
|
||||
pxor %xmm4,%xmm0
|
||||
|
||||
|
||||
pxor %xmm7,%xmm0
|
||||
movdqa %xmm0,%xmm7
|
||||
retq
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.p2align 4
|
||||
_vpaes_schedule_transform:
|
||||
movdqa %xmm9,%xmm1
|
||||
pandn %xmm0,%xmm1
|
||||
psrld $4,%xmm1
|
||||
pand %xmm9,%xmm0
|
||||
movdqa (%r11),%xmm2
|
||||
.byte 102,15,56,0,208
|
||||
movdqa 16(%r11),%xmm0
|
||||
.byte 102,15,56,0,193
|
||||
pxor %xmm2,%xmm0
|
||||
retq
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.p2align 4
|
||||
_vpaes_schedule_mangle:
|
||||
movdqa %xmm0,%xmm4
|
||||
movdqa L$k_mc_forward(%rip),%xmm5
|
||||
testq %rcx,%rcx
|
||||
jnz L$schedule_mangle_dec
|
||||
|
||||
|
||||
addq $16,%rdx
|
||||
pxor L$k_s63(%rip),%xmm4
|
||||
.byte 102,15,56,0,229
|
||||
movdqa %xmm4,%xmm3
|
||||
.byte 102,15,56,0,229
|
||||
pxor %xmm4,%xmm3
|
||||
.byte 102,15,56,0,229
|
||||
pxor %xmm4,%xmm3
|
||||
|
||||
jmp L$schedule_mangle_both
|
||||
.p2align 4
|
||||
L$schedule_mangle_dec:
|
||||
|
||||
leaq L$k_dksd(%rip),%r11
|
||||
movdqa %xmm9,%xmm1
|
||||
pandn %xmm4,%xmm1
|
||||
psrld $4,%xmm1
|
||||
pand %xmm9,%xmm4
|
||||
|
||||
movdqa 0(%r11),%xmm2
|
||||
.byte 102,15,56,0,212
|
||||
movdqa 16(%r11),%xmm3
|
||||
.byte 102,15,56,0,217
|
||||
pxor %xmm2,%xmm3
|
||||
.byte 102,15,56,0,221
|
||||
|
||||
movdqa 32(%r11),%xmm2
|
||||
.byte 102,15,56,0,212
|
||||
pxor %xmm3,%xmm2
|
||||
movdqa 48(%r11),%xmm3
|
||||
.byte 102,15,56,0,217
|
||||
pxor %xmm2,%xmm3
|
||||
.byte 102,15,56,0,221
|
||||
|
||||
movdqa 64(%r11),%xmm2
|
||||
.byte 102,15,56,0,212
|
||||
pxor %xmm3,%xmm2
|
||||
movdqa 80(%r11),%xmm3
|
||||
.byte 102,15,56,0,217
|
||||
pxor %xmm2,%xmm3
|
||||
.byte 102,15,56,0,221
|
||||
|
||||
movdqa 96(%r11),%xmm2
|
||||
.byte 102,15,56,0,212
|
||||
pxor %xmm3,%xmm2
|
||||
movdqa 112(%r11),%xmm3
|
||||
.byte 102,15,56,0,217
|
||||
pxor %xmm2,%xmm3
|
||||
|
||||
addq $-16,%rdx
|
||||
|
||||
L$schedule_mangle_both:
|
||||
movdqa (%r8,%r10,1),%xmm1
|
||||
.byte 102,15,56,0,217
|
||||
addq $-16,%r8
|
||||
andq $48,%r8
|
||||
movdqu %xmm3,(%rdx)
|
||||
retq
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.globl _vpaes_set_encrypt_key
|
||||
|
||||
.p2align 4
|
||||
_vpaes_set_encrypt_key:
|
||||
movl %esi,%eax
|
||||
shrl $5,%eax
|
||||
addl $5,%eax
|
||||
movl %eax,240(%rdx)
|
||||
|
||||
movl $0,%ecx
|
||||
movl $48,%r8d
|
||||
call _vpaes_schedule_core
|
||||
xorl %eax,%eax
|
||||
retq
|
||||
|
||||
|
||||
.globl _vpaes_set_decrypt_key
|
||||
|
||||
.p2align 4
|
||||
_vpaes_set_decrypt_key:
|
||||
movl %esi,%eax
|
||||
shrl $5,%eax
|
||||
addl $5,%eax
|
||||
movl %eax,240(%rdx)
|
||||
shll $4,%eax
|
||||
leaq 16(%rdx,%rax,1),%rdx
|
||||
|
||||
movl $1,%ecx
|
||||
movl %esi,%r8d
|
||||
shrl $1,%r8d
|
||||
andl $32,%r8d
|
||||
xorl $32,%r8d
|
||||
call _vpaes_schedule_core
|
||||
xorl %eax,%eax
|
||||
retq
|
||||
|
||||
|
||||
.globl _vpaes_encrypt
|
||||
|
||||
.p2align 4
|
||||
_vpaes_encrypt:
|
||||
movdqu (%rdi),%xmm0
|
||||
call _vpaes_preheat
|
||||
call _vpaes_encrypt_core
|
||||
movdqu %xmm0,(%rsi)
|
||||
retq
|
||||
|
||||
|
||||
.globl _vpaes_decrypt
|
||||
|
||||
.p2align 4
|
||||
_vpaes_decrypt:
|
||||
movdqu (%rdi),%xmm0
|
||||
call _vpaes_preheat
|
||||
call _vpaes_decrypt_core
|
||||
movdqu %xmm0,(%rsi)
|
||||
retq
|
||||
|
||||
.globl _vpaes_cbc_encrypt
|
||||
|
||||
.p2align 4
|
||||
_vpaes_cbc_encrypt:
|
||||
xchgq %rcx,%rdx
|
||||
subq $16,%rcx
|
||||
jc L$cbc_abort
|
||||
movdqu (%r8),%xmm6
|
||||
subq %rdi,%rsi
|
||||
call _vpaes_preheat
|
||||
cmpl $0,%r9d
|
||||
je L$cbc_dec_loop
|
||||
jmp L$cbc_enc_loop
|
||||
.p2align 4
|
||||
L$cbc_enc_loop:
|
||||
movdqu (%rdi),%xmm0
|
||||
pxor %xmm6,%xmm0
|
||||
call _vpaes_encrypt_core
|
||||
movdqa %xmm0,%xmm6
|
||||
movdqu %xmm0,(%rsi,%rdi,1)
|
||||
leaq 16(%rdi),%rdi
|
||||
subq $16,%rcx
|
||||
jnc L$cbc_enc_loop
|
||||
jmp L$cbc_done
|
||||
.p2align 4
|
||||
L$cbc_dec_loop:
|
||||
movdqu (%rdi),%xmm0
|
||||
movdqa %xmm0,%xmm7
|
||||
call _vpaes_decrypt_core
|
||||
pxor %xmm6,%xmm0
|
||||
movdqa %xmm7,%xmm6
|
||||
movdqu %xmm0,(%rsi,%rdi,1)
|
||||
leaq 16(%rdi),%rdi
|
||||
subq $16,%rcx
|
||||
jnc L$cbc_dec_loop
|
||||
L$cbc_done:
|
||||
movdqu %xmm6,(%r8)
|
||||
L$cbc_abort:
|
||||
retq
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.p2align 4
|
||||
_vpaes_preheat:
|
||||
leaq L$k_s0F(%rip),%r10
|
||||
movdqa -32(%r10),%xmm10
|
||||
movdqa -16(%r10),%xmm11
|
||||
movdqa 0(%r10),%xmm9
|
||||
movdqa 48(%r10),%xmm13
|
||||
movdqa 64(%r10),%xmm12
|
||||
movdqa 80(%r10),%xmm15
|
||||
movdqa 96(%r10),%xmm14
|
||||
retq
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.p2align 6
|
||||
_vpaes_consts:
|
||||
L$k_inv:
|
||||
.quad 0x0E05060F0D080180, 0x040703090A0B0C02
|
||||
.quad 0x01040A060F0B0780, 0x030D0E0C02050809
|
||||
|
||||
L$k_s0F:
|
||||
.quad 0x0F0F0F0F0F0F0F0F, 0x0F0F0F0F0F0F0F0F
|
||||
|
||||
L$k_ipt:
|
||||
.quad 0xC2B2E8985A2A7000, 0xCABAE09052227808
|
||||
.quad 0x4C01307D317C4D00, 0xCD80B1FCB0FDCC81
|
||||
|
||||
L$k_sb1:
|
||||
.quad 0xB19BE18FCB503E00, 0xA5DF7A6E142AF544
|
||||
.quad 0x3618D415FAE22300, 0x3BF7CCC10D2ED9EF
|
||||
L$k_sb2:
|
||||
.quad 0xE27A93C60B712400, 0x5EB7E955BC982FCD
|
||||
.quad 0x69EB88400AE12900, 0xC2A163C8AB82234A
|
||||
L$k_sbo:
|
||||
.quad 0xD0D26D176FBDC700, 0x15AABF7AC502A878
|
||||
.quad 0xCFE474A55FBB6A00, 0x8E1E90D1412B35FA
|
||||
|
||||
L$k_mc_forward:
|
||||
.quad 0x0407060500030201, 0x0C0F0E0D080B0A09
|
||||
.quad 0x080B0A0904070605, 0x000302010C0F0E0D
|
||||
.quad 0x0C0F0E0D080B0A09, 0x0407060500030201
|
||||
.quad 0x000302010C0F0E0D, 0x080B0A0904070605
|
||||
|
||||
L$k_mc_backward:
|
||||
.quad 0x0605040702010003, 0x0E0D0C0F0A09080B
|
||||
.quad 0x020100030E0D0C0F, 0x0A09080B06050407
|
||||
.quad 0x0E0D0C0F0A09080B, 0x0605040702010003
|
||||
.quad 0x0A09080B06050407, 0x020100030E0D0C0F
|
||||
|
||||
L$k_sr:
|
||||
.quad 0x0706050403020100, 0x0F0E0D0C0B0A0908
|
||||
.quad 0x030E09040F0A0500, 0x0B06010C07020D08
|
||||
.quad 0x0F060D040B020900, 0x070E050C030A0108
|
||||
.quad 0x0B0E0104070A0D00, 0x0306090C0F020508
|
||||
|
||||
L$k_rcon:
|
||||
.quad 0x1F8391B9AF9DEEB6, 0x702A98084D7C7D81
|
||||
|
||||
L$k_s63:
|
||||
.quad 0x5B5B5B5B5B5B5B5B, 0x5B5B5B5B5B5B5B5B
|
||||
|
||||
L$k_opt:
|
||||
.quad 0xFF9F4929D6B66000, 0xF7974121DEBE6808
|
||||
.quad 0x01EDBD5150BCEC00, 0xE10D5DB1B05C0CE0
|
||||
|
||||
L$k_deskew:
|
||||
.quad 0x07E4A34047A4E300, 0x1DFEB95A5DBEF91A
|
||||
.quad 0x5F36B5DC83EA6900, 0x2841C2ABF49D1E77
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
L$k_dksd:
|
||||
.quad 0xFEB91A5DA3E44700, 0x0740E3A45A1DBEF9
|
||||
.quad 0x41C277F4B5368300, 0x5FDC69EAAB289D1E
|
||||
L$k_dksb:
|
||||
.quad 0x9A4FCA1F8550D500, 0x03D653861CC94C99
|
||||
.quad 0x115BEDA7B6FC4A00, 0xD993256F7E3482C8
|
||||
L$k_dkse:
|
||||
.quad 0xD5031CCA1FC9D600, 0x53859A4C994F5086
|
||||
.quad 0xA23196054FDC7BE8, 0xCD5EF96A20B31487
|
||||
L$k_dks9:
|
||||
.quad 0xB6116FC87ED9A700, 0x4AED933482255BFC
|
||||
.quad 0x4576516227143300, 0x8BB89FACE9DAFDCE
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
L$k_dipt:
|
||||
.quad 0x0F505B040B545F00, 0x154A411E114E451A
|
||||
.quad 0x86E383E660056500, 0x12771772F491F194
|
||||
|
||||
L$k_dsb9:
|
||||
.quad 0x851C03539A86D600, 0xCAD51F504F994CC9
|
||||
.quad 0xC03B1789ECD74900, 0x725E2C9EB2FBA565
|
||||
L$k_dsbd:
|
||||
.quad 0x7D57CCDFE6B1A200, 0xF56E9B13882A4439
|
||||
.quad 0x3CE2FAF724C6CB00, 0x2931180D15DEEFD3
|
||||
L$k_dsbb:
|
||||
.quad 0xD022649296B44200, 0x602646F6B0F2D404
|
||||
.quad 0xC19498A6CD596700, 0xF3FF0C3E3255AA6B
|
||||
L$k_dsbe:
|
||||
.quad 0x46F2929626D4D000, 0x2242600464B4F6B0
|
||||
.quad 0x0C55A6CDFFAAC100, 0x9467F36B98593E32
|
||||
L$k_dsbo:
|
||||
.quad 0x1387EA537EF94000, 0xC7AA6DB9D4943E2D
|
||||
.quad 0x12D7560F93441D00, 0xCA4B8159D8C58E9C
|
||||
.byte 86,101,99,116,111,114,32,80,101,114,109,117,116,97,116,105,111,110,32,65,69,83,32,102,111,114,32,120,56,54,95,54,52,47,83,83,83,69,51,44,32,77,105,107,101,32,72,97,109,98,117,114,103,32,40,83,116,97,110,102,111,114,100,32,85,110,105,118,101,114,115,105,116,121,41,0
|
||||
.p2align 6
|
||||
|
||||
1213
externals/libressl/crypto/aes/vpaes-masm-x86_64.S
vendored
1213
externals/libressl/crypto/aes/vpaes-masm-x86_64.S
vendored
File diff suppressed because it is too large
Load Diff
1125
externals/libressl/crypto/aes/vpaes-mingw64-x86_64.S
vendored
1125
externals/libressl/crypto/aes/vpaes-mingw64-x86_64.S
vendored
File diff suppressed because it is too large
Load Diff
59
externals/libressl/crypto/arm_arch.h
vendored
59
externals/libressl/crypto/arm_arch.h
vendored
@@ -1,59 +0,0 @@
|
||||
/* $OpenBSD: arm_arch.h,v 1.1 2022/03/23 15:13:31 tb 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
externals/libressl/crypto/armcap.c
vendored
88
externals/libressl/crypto/armcap.c
vendored
@@ -1,88 +0,0 @@
|
||||
/* $OpenBSD: armcap.c,v 1.1 2022/03/23 15:13:31 tb 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
externals/libressl/crypto/armv4cpuid.S
vendored
165
externals/libressl/crypto/armv4cpuid.S
vendored
@@ -1,165 +0,0 @@
|
||||
#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
|
||||
347
externals/libressl/crypto/asn1/a_bitstr.c
vendored
347
externals/libressl/crypto/asn1/a_bitstr.c
vendored
@@ -1,347 +0,0 @@
|
||||
/* $OpenBSD: a_bitstr.c,v 1.33 2021/12/25 08:52:44 jsing 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/asn1t.h>
|
||||
#include <openssl/conf.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
const ASN1_ITEM ASN1_BIT_STRING_it = {
|
||||
.itype = ASN1_ITYPE_PRIMITIVE,
|
||||
.utype = V_ASN1_BIT_STRING,
|
||||
.sname = "ASN1_BIT_STRING",
|
||||
};
|
||||
|
||||
ASN1_BIT_STRING *
|
||||
ASN1_BIT_STRING_new(void)
|
||||
{
|
||||
return (ASN1_BIT_STRING *)ASN1_item_new(&ASN1_BIT_STRING_it);
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_BIT_STRING_free(ASN1_BIT_STRING *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &ASN1_BIT_STRING_it);
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, unsigned char *d, int len)
|
||||
{
|
||||
return ASN1_STRING_set(x, d, len);
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
|
||||
{
|
||||
int w, v, iv;
|
||||
unsigned char *c;
|
||||
|
||||
w = n/8;
|
||||
v = 1 << (7 - (n & 0x07));
|
||||
iv = ~v;
|
||||
if (!value)
|
||||
v = 0;
|
||||
|
||||
if (a == NULL)
|
||||
return 0;
|
||||
|
||||
a->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); /* clear, set on write */
|
||||
|
||||
if ((a->length < (w + 1)) || (a->data == NULL)) {
|
||||
if (!value)
|
||||
return(1); /* Don't need to set */
|
||||
if ((c = recallocarray(a->data, a->length, w + 1, 1)) == NULL) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
a->data = c;
|
||||
a->length = w + 1;
|
||||
}
|
||||
a->data[w] = ((a->data[w]) & iv) | v;
|
||||
while ((a->length > 0) && (a->data[a->length - 1] == 0))
|
||||
a->length--;
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_BIT_STRING_get_bit(const ASN1_BIT_STRING *a, int n)
|
||||
{
|
||||
int w, v;
|
||||
|
||||
w = n / 8;
|
||||
v = 1 << (7 - (n & 0x07));
|
||||
if ((a == NULL) || (a->length < (w + 1)) || (a->data == NULL))
|
||||
return (0);
|
||||
return ((a->data[w] & v) != 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks if the given bit string contains only bits specified by
|
||||
* the flags vector. Returns 0 if there is at least one bit set in 'a'
|
||||
* which is not specified in 'flags', 1 otherwise.
|
||||
* 'len' is the length of 'flags'.
|
||||
*/
|
||||
int
|
||||
ASN1_BIT_STRING_check(const ASN1_BIT_STRING *a, const unsigned char *flags,
|
||||
int flags_len)
|
||||
{
|
||||
int i, ok;
|
||||
|
||||
/* Check if there is one bit set at all. */
|
||||
if (!a || !a->data)
|
||||
return 1;
|
||||
|
||||
/* Check each byte of the internal representation of the bit string. */
|
||||
ok = 1;
|
||||
for (i = 0; i < a->length && ok; ++i) {
|
||||
unsigned char mask = i < flags_len ? ~flags[i] : 0xff;
|
||||
/* We are done if there is an unneeded bit set. */
|
||||
ok = (a->data[i] & mask) == 0;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
|
||||
BIT_STRING_BITNAME *tbl, int indent)
|
||||
{
|
||||
BIT_STRING_BITNAME *bnam;
|
||||
char first = 1;
|
||||
|
||||
BIO_printf(out, "%*s", indent, "");
|
||||
for (bnam = tbl; bnam->lname; bnam++) {
|
||||
if (ASN1_BIT_STRING_get_bit(bs, bnam->bitnum)) {
|
||||
if (!first)
|
||||
BIO_puts(out, ", ");
|
||||
BIO_puts(out, bnam->lname);
|
||||
first = 0;
|
||||
}
|
||||
}
|
||||
BIO_puts(out, "\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, const char *name, int value,
|
||||
BIT_STRING_BITNAME *tbl)
|
||||
{
|
||||
int bitnum;
|
||||
|
||||
bitnum = ASN1_BIT_STRING_num_asc(name, tbl);
|
||||
if (bitnum < 0)
|
||||
return 0;
|
||||
if (bs) {
|
||||
if (!ASN1_BIT_STRING_set_bit(bs, bitnum, value))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_BIT_STRING_num_asc(const char *name, BIT_STRING_BITNAME *tbl)
|
||||
{
|
||||
BIT_STRING_BITNAME *bnam;
|
||||
|
||||
for (bnam = tbl; bnam->lname; bnam++) {
|
||||
if (!strcmp(bnam->sname, name) ||
|
||||
!strcmp(bnam->lname, name))
|
||||
return bnam->bitnum;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp)
|
||||
{
|
||||
int ret, j, bits, len;
|
||||
unsigned char *p, *d;
|
||||
|
||||
if (a == NULL)
|
||||
return (0);
|
||||
|
||||
len = a->length;
|
||||
|
||||
if (len > 0) {
|
||||
if (a->flags & ASN1_STRING_FLAG_BITS_LEFT) {
|
||||
bits = (int)a->flags & 0x07;
|
||||
} else {
|
||||
for (; len > 0; len--) {
|
||||
if (a->data[len - 1])
|
||||
break;
|
||||
}
|
||||
j = a->data[len - 1];
|
||||
if (j & 0x01)
|
||||
bits = 0;
|
||||
else if (j & 0x02)
|
||||
bits = 1;
|
||||
else if (j & 0x04)
|
||||
bits = 2;
|
||||
else if (j & 0x08)
|
||||
bits = 3;
|
||||
else if (j & 0x10)
|
||||
bits = 4;
|
||||
else if (j & 0x20)
|
||||
bits = 5;
|
||||
else if (j & 0x40)
|
||||
bits = 6;
|
||||
else if (j & 0x80)
|
||||
bits = 7;
|
||||
else
|
||||
bits = 0; /* should not happen */
|
||||
}
|
||||
} else
|
||||
bits = 0;
|
||||
|
||||
ret = 1 + len;
|
||||
if (pp == NULL)
|
||||
return (ret);
|
||||
|
||||
p= *pp;
|
||||
|
||||
*(p++) = (unsigned char)bits;
|
||||
d = a->data;
|
||||
if (len > 0) {
|
||||
memcpy(p, d, len);
|
||||
p += len;
|
||||
p[-1] &= 0xff << bits;
|
||||
}
|
||||
*pp = p;
|
||||
return (ret);
|
||||
}
|
||||
|
||||
ASN1_BIT_STRING *
|
||||
c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, const unsigned char **pp, long len)
|
||||
{
|
||||
ASN1_BIT_STRING *ret = NULL;
|
||||
const unsigned char *p;
|
||||
unsigned char *s;
|
||||
int i;
|
||||
|
||||
if (len < 1) {
|
||||
ASN1error(ASN1_R_STRING_TOO_SHORT);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (a == NULL || *a == NULL) {
|
||||
if ((ret = ASN1_BIT_STRING_new()) == NULL)
|
||||
return (NULL);
|
||||
} else
|
||||
ret = *a;
|
||||
|
||||
p = *pp;
|
||||
i = *(p++);
|
||||
if (i > 7) {
|
||||
ASN1error(ASN1_R_INVALID_BIT_STRING_BITS_LEFT);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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);
|
||||
s[len - 1] &= (0xff << i);
|
||||
p += len;
|
||||
} else
|
||||
s = NULL;
|
||||
|
||||
free(ret->data);
|
||||
ret->data = s;
|
||||
ret->length = (int)len;
|
||||
ret->type = V_ASN1_BIT_STRING;
|
||||
|
||||
if (a != NULL)
|
||||
*a = ret;
|
||||
|
||||
*pp = p;
|
||||
|
||||
return (ret);
|
||||
|
||||
err:
|
||||
if (a == NULL || *a != ret)
|
||||
ASN1_BIT_STRING_free(ret);
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_BIT_STRING_it);
|
||||
}
|
||||
|
||||
ASN1_BIT_STRING *
|
||||
d2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (ASN1_BIT_STRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&ASN1_BIT_STRING_it);
|
||||
}
|
||||
354
externals/libressl/crypto/asn1/a_enum.c
vendored
354
externals/libressl/crypto/asn1/a_enum.c
vendored
@@ -1,354 +0,0 @@
|
||||
/* $OpenBSD: a_enum.c,v 1.23 2021/12/25 13:17:48 jsing 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 <limits.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
/*
|
||||
* Code for ENUMERATED type: identical to INTEGER apart from a different tag.
|
||||
* for comments on encoding see a_int.c
|
||||
*/
|
||||
|
||||
const ASN1_ITEM ASN1_ENUMERATED_it = {
|
||||
.itype = ASN1_ITYPE_PRIMITIVE,
|
||||
.utype = V_ASN1_ENUMERATED,
|
||||
.sname = "ASN1_ENUMERATED",
|
||||
};
|
||||
|
||||
ASN1_ENUMERATED *
|
||||
ASN1_ENUMERATED_new(void)
|
||||
{
|
||||
return (ASN1_ENUMERATED *)ASN1_item_new(&ASN1_ENUMERATED_it);
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_ENUMERATED_free(ASN1_ENUMERATED *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &ASN1_ENUMERATED_it);
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
|
||||
{
|
||||
int j, k;
|
||||
unsigned int i;
|
||||
unsigned char buf[sizeof(long) + 1];
|
||||
long d;
|
||||
|
||||
a->type = V_ASN1_ENUMERATED;
|
||||
if (a->length < (int)(sizeof(long) + 1)) {
|
||||
free(a->data);
|
||||
a->data = calloc(1, sizeof(long) + 1);
|
||||
}
|
||||
if (a->data == NULL) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
return (0);
|
||||
}
|
||||
d = v;
|
||||
if (d < 0) {
|
||||
d = -d;
|
||||
a->type = V_ASN1_NEG_ENUMERATED;
|
||||
}
|
||||
|
||||
for (i = 0; i < sizeof(long); i++) {
|
||||
if (d == 0)
|
||||
break;
|
||||
buf[i] = (int)d & 0xff;
|
||||
d >>= 8;
|
||||
}
|
||||
j = 0;
|
||||
for (k = i - 1; k >= 0; k--)
|
||||
a->data[j++] = buf[k];
|
||||
a->length = j;
|
||||
return (1);
|
||||
}
|
||||
|
||||
long
|
||||
ASN1_ENUMERATED_get(const ASN1_ENUMERATED *a)
|
||||
{
|
||||
int neg = 0, i;
|
||||
unsigned long r = 0;
|
||||
|
||||
if (a == NULL)
|
||||
return (0L);
|
||||
i = a->type;
|
||||
if (i == V_ASN1_NEG_ENUMERATED)
|
||||
neg = 1;
|
||||
else if (i != V_ASN1_ENUMERATED)
|
||||
return -1;
|
||||
|
||||
if (a->length > (int)sizeof(long)) {
|
||||
/* hmm... a bit ugly */
|
||||
return -1;
|
||||
}
|
||||
if (a->data == NULL)
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < a->length; i++) {
|
||||
r <<= 8;
|
||||
r |= (unsigned char)a->data[i];
|
||||
}
|
||||
|
||||
if (r > LONG_MAX)
|
||||
return -1;
|
||||
|
||||
if (neg)
|
||||
return -(long)r;
|
||||
return (long)r;
|
||||
}
|
||||
|
||||
ASN1_ENUMERATED *
|
||||
BN_to_ASN1_ENUMERATED(const BIGNUM *bn, ASN1_ENUMERATED *ai)
|
||||
{
|
||||
ASN1_ENUMERATED *ret;
|
||||
int len, j;
|
||||
|
||||
if (ai == NULL)
|
||||
ret = ASN1_ENUMERATED_new();
|
||||
else
|
||||
ret = ai;
|
||||
if (ret == NULL) {
|
||||
ASN1error(ERR_R_NESTED_ASN1_ERROR);
|
||||
goto err;
|
||||
}
|
||||
if (BN_is_negative(bn))
|
||||
ret->type = V_ASN1_NEG_ENUMERATED;
|
||||
else
|
||||
ret->type = V_ASN1_ENUMERATED;
|
||||
j = BN_num_bits(bn);
|
||||
len = ((j == 0) ? 0 : ((j / 8) + 1));
|
||||
if (ret->length < len + 4) {
|
||||
unsigned char *new_data = realloc(ret->data, len + 4);
|
||||
if (!new_data) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
ret->data = new_data;
|
||||
}
|
||||
ret->length = BN_bn2bin(bn, ret->data);
|
||||
|
||||
/* Correct zero case */
|
||||
if (!ret->length) {
|
||||
ret->data[0] = 0;
|
||||
ret->length = 1;
|
||||
}
|
||||
return (ret);
|
||||
|
||||
err:
|
||||
if (ret != ai)
|
||||
ASN1_ENUMERATED_free(ret);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
BIGNUM *
|
||||
ASN1_ENUMERATED_to_BN(const ASN1_ENUMERATED *ai, BIGNUM *bn)
|
||||
{
|
||||
BIGNUM *ret;
|
||||
|
||||
if ((ret = BN_bin2bn(ai->data, ai->length, bn)) == NULL)
|
||||
ASN1error(ASN1_R_BN_LIB);
|
||||
else if (ai->type == V_ASN1_NEG_ENUMERATED)
|
||||
BN_set_negative(ret, 1);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/* Based on a_int.c: equivalent ENUMERATED functions */
|
||||
|
||||
int
|
||||
i2a_ASN1_ENUMERATED(BIO *bp, const ASN1_ENUMERATED *a)
|
||||
{
|
||||
int i, n = 0;
|
||||
static const char h[] = "0123456789ABCDEF";
|
||||
char buf[2];
|
||||
|
||||
if (a == NULL)
|
||||
return (0);
|
||||
|
||||
if (a->length == 0) {
|
||||
if (BIO_write(bp, "00", 2) != 2)
|
||||
goto err;
|
||||
n = 2;
|
||||
} else {
|
||||
for (i = 0; i < a->length; i++) {
|
||||
if ((i != 0) && (i % 35 == 0)) {
|
||||
if (BIO_write(bp, "\\\n", 2) != 2)
|
||||
goto err;
|
||||
n += 2;
|
||||
}
|
||||
buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f];
|
||||
buf[1] = h[((unsigned char)a->data[i]) & 0x0f];
|
||||
if (BIO_write(bp, buf, 2) != 2)
|
||||
goto err;
|
||||
n += 2;
|
||||
}
|
||||
}
|
||||
return (n);
|
||||
|
||||
err:
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int
|
||||
a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size)
|
||||
{
|
||||
int ret = 0;
|
||||
int i, j,k, m,n, again, bufsize;
|
||||
unsigned char *s = NULL, *sp;
|
||||
unsigned char *bufp;
|
||||
int first = 1;
|
||||
size_t num = 0, slen = 0;
|
||||
|
||||
bs->type = V_ASN1_ENUMERATED;
|
||||
|
||||
bufsize = BIO_gets(bp, buf, size);
|
||||
for (;;) {
|
||||
if (bufsize < 1)
|
||||
goto err_sl;
|
||||
i = bufsize;
|
||||
if (buf[i-1] == '\n')
|
||||
buf[--i] = '\0';
|
||||
if (i == 0)
|
||||
goto err_sl;
|
||||
if (buf[i-1] == '\r')
|
||||
buf[--i] = '\0';
|
||||
if (i == 0)
|
||||
goto err_sl;
|
||||
if (buf[i - 1] == '\\') {
|
||||
i--;
|
||||
again = 1;
|
||||
} else
|
||||
again = 0;
|
||||
buf[i] = '\0';
|
||||
if (i < 2)
|
||||
goto err_sl;
|
||||
|
||||
bufp = (unsigned char *)buf;
|
||||
if (first) {
|
||||
first = 0;
|
||||
if ((bufp[0] == '0') && (buf[1] == '0')) {
|
||||
bufp += 2;
|
||||
i -= 2;
|
||||
}
|
||||
}
|
||||
k = 0;
|
||||
if (i % 2 != 0) {
|
||||
ASN1error(ASN1_R_ODD_NUMBER_OF_CHARS);
|
||||
goto err;
|
||||
}
|
||||
i /= 2;
|
||||
if (num + i > slen) {
|
||||
sp = realloc(s, num + i);
|
||||
if (sp == NULL) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
s = sp;
|
||||
slen = num + i;
|
||||
}
|
||||
for (j = 0; j < i; j++, k += 2) {
|
||||
for (n = 0; n < 2; n++) {
|
||||
m = bufp[k + n];
|
||||
if ((m >= '0') && (m <= '9'))
|
||||
m -= '0';
|
||||
else if ((m >= 'a') && (m <= 'f'))
|
||||
m = m - 'a' + 10;
|
||||
else if ((m >= 'A') && (m <= 'F'))
|
||||
m = m - 'A' + 10;
|
||||
else {
|
||||
ASN1error(ASN1_R_NON_HEX_CHARACTERS);
|
||||
goto err;
|
||||
}
|
||||
s[num + j] <<= 4;
|
||||
s[num + j] |= m;
|
||||
}
|
||||
}
|
||||
num += i;
|
||||
if (again)
|
||||
bufsize = BIO_gets(bp, buf, size);
|
||||
else
|
||||
break;
|
||||
}
|
||||
bs->length = num;
|
||||
bs->data = s;
|
||||
return (1);
|
||||
|
||||
err_sl:
|
||||
ASN1error(ASN1_R_SHORT_LINE);
|
||||
err:
|
||||
free(s);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_ASN1_ENUMERATED(ASN1_ENUMERATED *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_ENUMERATED_it);
|
||||
}
|
||||
|
||||
ASN1_ENUMERATED *
|
||||
d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (ASN1_ENUMERATED *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&ASN1_ENUMERATED_it);
|
||||
}
|
||||
674
externals/libressl/crypto/asn1/a_int.c
vendored
674
externals/libressl/crypto/asn1/a_int.c
vendored
@@ -1,674 +0,0 @@
|
||||
/* $OpenBSD: a_int.c,v 1.38 2021/12/25 13:17:48 jsing 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 <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
const ASN1_ITEM ASN1_INTEGER_it = {
|
||||
.itype = ASN1_ITYPE_PRIMITIVE,
|
||||
.utype = V_ASN1_INTEGER,
|
||||
.sname = "ASN1_INTEGER",
|
||||
};
|
||||
|
||||
ASN1_INTEGER *
|
||||
ASN1_INTEGER_new(void)
|
||||
{
|
||||
return (ASN1_INTEGER *)ASN1_item_new(&ASN1_INTEGER_it);
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_INTEGER_free(ASN1_INTEGER *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &ASN1_INTEGER_it);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y)
|
||||
{
|
||||
int neg, ret;
|
||||
|
||||
/* Compare signs */
|
||||
neg = x->type & V_ASN1_NEG;
|
||||
if (neg != (y->type & V_ASN1_NEG)) {
|
||||
if (neg)
|
||||
return -1;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = ASN1_STRING_cmp(x, y);
|
||||
|
||||
if (neg)
|
||||
return -ret;
|
||||
else
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
|
||||
{
|
||||
int j, k;
|
||||
unsigned int i;
|
||||
unsigned char buf[sizeof(long) + 1];
|
||||
long d;
|
||||
|
||||
a->type = V_ASN1_INTEGER;
|
||||
/* XXX ssl/ssl_asn1.c:i2d_SSL_SESSION() depends upon this bound vae */
|
||||
if (a->length < (int)(sizeof(long) + 1)) {
|
||||
free(a->data);
|
||||
a->data = calloc(1, sizeof(long) + 1);
|
||||
}
|
||||
if (a->data == NULL) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
return (0);
|
||||
}
|
||||
d = v;
|
||||
if (d < 0) {
|
||||
d = -d;
|
||||
a->type = V_ASN1_NEG_INTEGER;
|
||||
}
|
||||
|
||||
for (i = 0; i < sizeof(long); i++) {
|
||||
if (d == 0)
|
||||
break;
|
||||
buf[i] = (int)d & 0xff;
|
||||
d >>= 8;
|
||||
}
|
||||
j = 0;
|
||||
for (k = i - 1; k >= 0; k--)
|
||||
a->data[j++] = buf[k];
|
||||
a->length = j;
|
||||
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;
|
||||
unsigned long r = 0;
|
||||
|
||||
if (a == NULL)
|
||||
return (0L);
|
||||
i = a->type;
|
||||
if (i == V_ASN1_NEG_INTEGER)
|
||||
neg = 1;
|
||||
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;
|
||||
}
|
||||
if (a->data == NULL)
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < a->length; i++) {
|
||||
r <<= 8;
|
||||
r |= (unsigned char)a->data[i];
|
||||
}
|
||||
|
||||
if (r > LONG_MAX)
|
||||
return -1;
|
||||
|
||||
if (neg)
|
||||
return -(long)r;
|
||||
return (long)r;
|
||||
}
|
||||
|
||||
ASN1_INTEGER *
|
||||
BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai)
|
||||
{
|
||||
ASN1_INTEGER *ret;
|
||||
int len, j;
|
||||
|
||||
if (ai == NULL)
|
||||
ret = ASN1_INTEGER_new();
|
||||
else
|
||||
ret = ai;
|
||||
if (ret == NULL) {
|
||||
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
|
||||
ret->type = V_ASN1_INTEGER;
|
||||
j = BN_num_bits(bn);
|
||||
len = ((j == 0) ? 0 : ((j / 8) + 1));
|
||||
if (ret->length < len + 4) {
|
||||
unsigned char *new_data = realloc(ret->data, len + 4);
|
||||
if (!new_data) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
ret->data = new_data;
|
||||
}
|
||||
ret->length = BN_bn2bin(bn, ret->data);
|
||||
|
||||
/* Correct zero case */
|
||||
if (!ret->length) {
|
||||
ret->data[0] = 0;
|
||||
ret->length = 1;
|
||||
}
|
||||
return (ret);
|
||||
|
||||
err:
|
||||
if (ret != ai)
|
||||
ASN1_INTEGER_free(ret);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
BIGNUM *
|
||||
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)
|
||||
BN_set_negative(ret, 1);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a)
|
||||
{
|
||||
int i, n = 0;
|
||||
static const char h[] = "0123456789ABCDEF";
|
||||
char buf[2];
|
||||
|
||||
if (a == NULL)
|
||||
return (0);
|
||||
|
||||
if (a->type & V_ASN1_NEG) {
|
||||
if (BIO_write(bp, "-", 1) != 1)
|
||||
goto err;
|
||||
n = 1;
|
||||
}
|
||||
|
||||
if (a->length == 0) {
|
||||
if (BIO_write(bp, "00", 2) != 2)
|
||||
goto err;
|
||||
n += 2;
|
||||
} else {
|
||||
for (i = 0; i < a->length; i++) {
|
||||
if ((i != 0) && (i % 35 == 0)) {
|
||||
if (BIO_write(bp, "\\\n", 2) != 2)
|
||||
goto err;
|
||||
n += 2;
|
||||
}
|
||||
buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f];
|
||||
buf[1] = h[((unsigned char)a->data[i]) & 0x0f];
|
||||
if (BIO_write(bp, buf, 2) != 2)
|
||||
goto err;
|
||||
n += 2;
|
||||
}
|
||||
}
|
||||
return (n);
|
||||
|
||||
err:
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int
|
||||
a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)
|
||||
{
|
||||
int ret = 0;
|
||||
int i, j,k, m,n, again, bufsize;
|
||||
unsigned char *s = NULL, *sp;
|
||||
unsigned char *bufp;
|
||||
int num = 0, slen = 0, first = 1;
|
||||
|
||||
bs->type = V_ASN1_INTEGER;
|
||||
|
||||
bufsize = BIO_gets(bp, buf, size);
|
||||
for (;;) {
|
||||
if (bufsize < 1)
|
||||
goto err_sl;
|
||||
i = bufsize;
|
||||
if (buf[i - 1] == '\n')
|
||||
buf[--i] = '\0';
|
||||
if (i == 0)
|
||||
goto err_sl;
|
||||
if (buf[i - 1] == '\r')
|
||||
buf[--i] = '\0';
|
||||
if (i == 0)
|
||||
goto err_sl;
|
||||
if (buf[i - 1] == '\\') {
|
||||
i--;
|
||||
again = 1;
|
||||
} else
|
||||
again = 0;
|
||||
buf[i] = '\0';
|
||||
if (i < 2)
|
||||
goto err_sl;
|
||||
|
||||
bufp = (unsigned char *)buf;
|
||||
if (first) {
|
||||
first = 0;
|
||||
if ((bufp[0] == '0') && (buf[1] == '0')) {
|
||||
bufp += 2;
|
||||
i -= 2;
|
||||
}
|
||||
}
|
||||
k = 0;
|
||||
if (i % 2 != 0) {
|
||||
ASN1error(ASN1_R_ODD_NUMBER_OF_CHARS);
|
||||
goto err;
|
||||
}
|
||||
i /= 2;
|
||||
if (num + i > slen) {
|
||||
if ((sp = recallocarray(s, slen, num + i, 1)) == NULL) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
s = sp;
|
||||
slen = num + i;
|
||||
}
|
||||
for (j = 0; j < i; j++, k += 2) {
|
||||
for (n = 0; n < 2; n++) {
|
||||
m = bufp[k + n];
|
||||
if ((m >= '0') && (m <= '9'))
|
||||
m -= '0';
|
||||
else if ((m >= 'a') && (m <= 'f'))
|
||||
m = m - 'a' + 10;
|
||||
else if ((m >= 'A') && (m <= 'F'))
|
||||
m = m - 'A' + 10;
|
||||
else {
|
||||
ASN1error(ASN1_R_NON_HEX_CHARACTERS);
|
||||
goto err;
|
||||
}
|
||||
s[num + j] <<= 4;
|
||||
s[num + j] |= m;
|
||||
}
|
||||
}
|
||||
num += i;
|
||||
if (again)
|
||||
bufsize = BIO_gets(bp, buf, size);
|
||||
else
|
||||
break;
|
||||
}
|
||||
bs->length = num;
|
||||
bs->data = s;
|
||||
return (1);
|
||||
|
||||
err_sl:
|
||||
ASN1error(ASN1_R_SHORT_LINE);
|
||||
err:
|
||||
free(s);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* This converts an ASN1 INTEGER into its content encoding.
|
||||
* The internal representation is an ASN1_STRING whose data is a big endian
|
||||
* representation of the value, ignoring the sign. The sign is determined by
|
||||
* the type: V_ASN1_INTEGER for positive and V_ASN1_NEG_INTEGER for negative.
|
||||
*
|
||||
* Positive integers are no problem: they are almost the same as the DER
|
||||
* encoding, except if the first byte is >= 0x80 we need to add a zero pad.
|
||||
*
|
||||
* Negative integers are a bit trickier...
|
||||
* The DER representation of negative integers is in 2s complement form.
|
||||
* The internal form is converted by complementing each octet and finally
|
||||
* adding one to the result. This can be done less messily with a little trick.
|
||||
* If the internal form has trailing zeroes then they will become FF by the
|
||||
* complement and 0 by the add one (due to carry) so just copy as many trailing
|
||||
* zeros to the destination as there are in the source. The carry will add one
|
||||
* to the last none zero octet: so complement this octet and add one and finally
|
||||
* complement any left over until you get to the start of the string.
|
||||
*
|
||||
* Padding is a little trickier too. If the first bytes is > 0x80 then we pad
|
||||
* with 0xff. However if the first byte is 0x80 and one of the following bytes
|
||||
* is non-zero we pad with 0xff. The reason for this distinction is that 0x80
|
||||
* followed by optional zeros isn't padded.
|
||||
*/
|
||||
|
||||
int
|
||||
i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp)
|
||||
{
|
||||
int pad = 0, ret, i, neg;
|
||||
unsigned char *p, *n, pb = 0;
|
||||
|
||||
if (!ASN1_INTEGER_valid(a))
|
||||
return 0;
|
||||
|
||||
neg = a->type & V_ASN1_NEG;
|
||||
if (a->length == 0)
|
||||
ret = 1;
|
||||
else {
|
||||
ret = a->length;
|
||||
i = a->data[0];
|
||||
if (!neg && (i > 127)) {
|
||||
pad = 1;
|
||||
pb = 0;
|
||||
} else if (neg) {
|
||||
if (i > 128) {
|
||||
pad = 1;
|
||||
pb = 0xFF;
|
||||
} else if (i == 128) {
|
||||
/*
|
||||
* Special case: if any other bytes non zero we pad:
|
||||
* otherwise we don't.
|
||||
*/
|
||||
for (i = 1; i < a->length; i++) if (a->data[i]) {
|
||||
pad = 1;
|
||||
pb = 0xFF;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ret += pad;
|
||||
}
|
||||
if (pp == NULL)
|
||||
return (ret);
|
||||
p= *pp;
|
||||
|
||||
if (pad)
|
||||
*(p++) = pb;
|
||||
if (a->length == 0)
|
||||
*(p++) = 0;
|
||||
else if (!neg)
|
||||
memcpy(p, a->data, a->length);
|
||||
else {
|
||||
/* Begin at the end of the encoding */
|
||||
n = a->data + a->length - 1;
|
||||
p += a->length - 1;
|
||||
i = a->length;
|
||||
/* Copy zeros to destination as long as source is zero */
|
||||
while (!*n) {
|
||||
*(p--) = 0;
|
||||
n--;
|
||||
i--;
|
||||
}
|
||||
/* Complement and increment next octet */
|
||||
*(p--) = ((*(n--)) ^ 0xff) + 1;
|
||||
i--;
|
||||
/* Complement any octets left */
|
||||
for (; i > 0; i--)
|
||||
*(p--) = *(n--) ^ 0xff;
|
||||
}
|
||||
|
||||
*pp += ret;
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/* Convert just ASN1 INTEGER content octets to ASN1_INTEGER structure */
|
||||
|
||||
ASN1_INTEGER *
|
||||
c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, long len)
|
||||
{
|
||||
ASN1_INTEGER *ret = NULL;
|
||||
const unsigned char *p, *pend;
|
||||
unsigned char *to, *s;
|
||||
int i;
|
||||
|
||||
if ((a == NULL) || ((*a) == NULL)) {
|
||||
if ((ret = ASN1_INTEGER_new()) == NULL)
|
||||
return (NULL);
|
||||
} 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;
|
||||
goto err;
|
||||
}
|
||||
to = s;
|
||||
if (!len) {
|
||||
/* Strictly speaking this is an illegal INTEGER but we
|
||||
* tolerate it.
|
||||
*/
|
||||
ret->type = V_ASN1_INTEGER;
|
||||
} else if (*p & 0x80) /* a negative number */ {
|
||||
ret->type = V_ASN1_NEG_INTEGER;
|
||||
if ((*p == 0xff) && (len != 1)) {
|
||||
p++;
|
||||
len--;
|
||||
}
|
||||
i = len;
|
||||
p += i - 1;
|
||||
to += i - 1;
|
||||
while((!*p) && i) {
|
||||
*(to--) = 0;
|
||||
i--;
|
||||
p--;
|
||||
}
|
||||
/* Special case: if all zeros then the number will be of
|
||||
* the form FF followed by n zero bytes: this corresponds to
|
||||
* 1 followed by n zero bytes. We've already written n zeros
|
||||
* so we just append an extra one and set the first byte to
|
||||
* a 1. This is treated separately because it is the only case
|
||||
* where the number of bytes is larger than len.
|
||||
*/
|
||||
if (!i) {
|
||||
*s = 1;
|
||||
s[len] = 0;
|
||||
len++;
|
||||
} else {
|
||||
*(to--) = (*(p--) ^ 0xff) + 1;
|
||||
i--;
|
||||
for (; i > 0; i--)
|
||||
*(to--) = *(p--) ^ 0xff;
|
||||
}
|
||||
} else {
|
||||
ret->type = V_ASN1_INTEGER;
|
||||
if ((*p == 0) && (len != 1)) {
|
||||
p++;
|
||||
len--;
|
||||
}
|
||||
memcpy(s, p, len);
|
||||
}
|
||||
|
||||
free(ret->data);
|
||||
ret->data = s;
|
||||
ret->length = (int)len;
|
||||
if (a != NULL)
|
||||
(*a) = ret;
|
||||
*pp = pend;
|
||||
return (ret);
|
||||
|
||||
err:
|
||||
ASN1error(i);
|
||||
if (a == NULL || *a != ret)
|
||||
ASN1_INTEGER_free(ret);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_INTEGER_it);
|
||||
}
|
||||
|
||||
ASN1_INTEGER *
|
||||
d2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (ASN1_INTEGER *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&ASN1_INTEGER_it);
|
||||
}
|
||||
|
||||
/* This is a version of d2i_ASN1_INTEGER that ignores the sign bit of
|
||||
* ASN1 integers: some broken software can encode a positive INTEGER
|
||||
* with its MSB set as negative (it doesn't add a padding zero).
|
||||
*/
|
||||
|
||||
ASN1_INTEGER *
|
||||
d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, long length)
|
||||
{
|
||||
ASN1_INTEGER *ret = NULL;
|
||||
const unsigned char *p;
|
||||
unsigned char *s;
|
||||
long len;
|
||||
int inf, tag, xclass;
|
||||
int i;
|
||||
|
||||
if ((a == NULL) || ((*a) == NULL)) {
|
||||
if ((ret = ASN1_INTEGER_new()) == NULL)
|
||||
return (NULL);
|
||||
} 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) {
|
||||
i = ASN1_R_BAD_OBJECT_HEADER;
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (tag != V_ASN1_INTEGER) {
|
||||
i = ASN1_R_EXPECTING_AN_INTEGER;
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
goto err;
|
||||
}
|
||||
ret->type = V_ASN1_INTEGER;
|
||||
if (len) {
|
||||
if ((*p == 0) && (len != 1)) {
|
||||
p++;
|
||||
len--;
|
||||
}
|
||||
memcpy(s, p, len);
|
||||
p += len;
|
||||
}
|
||||
|
||||
free(ret->data);
|
||||
ret->data = s;
|
||||
ret->length = (int)len;
|
||||
if (a != NULL)
|
||||
(*a) = ret;
|
||||
*pp = p;
|
||||
return (ret);
|
||||
|
||||
err:
|
||||
ASN1error(i);
|
||||
if (a == NULL || *a != ret)
|
||||
ASN1_INTEGER_free(ret);
|
||||
return (NULL);
|
||||
}
|
||||
447
externals/libressl/crypto/asn1/a_mbstr.c
vendored
447
externals/libressl/crypto/asn1/a_mbstr.c
vendored
@@ -1,447 +0,0 @@
|
||||
/* $OpenBSD: a_mbstr.c,v 1.24 2021/12/25 13:17:48 jsing Exp $ */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 1999.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#include "asn1_locl.h"
|
||||
|
||||
static int traverse_string(const unsigned char *p, int len, int inform,
|
||||
int (*rfunc)(unsigned long value, void *in), void *arg);
|
||||
static int in_utf8(unsigned long value, void *arg);
|
||||
static int out_utf8(unsigned long value, void *arg);
|
||||
static int type_str(unsigned long value, void *arg);
|
||||
static int cpy_asc(unsigned long value, void *arg);
|
||||
static int cpy_bmp(unsigned long value, void *arg);
|
||||
static int cpy_univ(unsigned long value, void *arg);
|
||||
static int cpy_utf8(unsigned long value, void *arg);
|
||||
static int is_printable(unsigned long value);
|
||||
|
||||
/* These functions take a string in UTF8, ASCII or multibyte form and
|
||||
* a mask of permissible ASN1 string types. It then works out the minimal
|
||||
* type (using the order Printable < IA5 < T61 < BMP < Universal < UTF8)
|
||||
* and creates a string of the correct type with the supplied data.
|
||||
* Yes this is horrible: it has to be :-(
|
||||
* The 'ncopy' form checks minimum and maximum size limits too.
|
||||
*/
|
||||
|
||||
int
|
||||
ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len,
|
||||
int inform, unsigned long mask)
|
||||
{
|
||||
return ASN1_mbstring_ncopy(out, in, len, inform, mask, 0, 0);
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
|
||||
int inform, unsigned long mask, long minsize, long maxsize)
|
||||
{
|
||||
int str_type;
|
||||
int ret;
|
||||
char free_out;
|
||||
int outform, outlen = 0;
|
||||
ASN1_STRING *dest;
|
||||
unsigned char *p;
|
||||
int nchar;
|
||||
int (*cpyfunc)(unsigned long, void *) = NULL;
|
||||
|
||||
if (len < 0)
|
||||
len = strlen((const char *)in);
|
||||
if (!mask)
|
||||
mask = DIRSTRING_TYPE;
|
||||
|
||||
/* First do a string check and work out the number of characters */
|
||||
switch (inform) {
|
||||
case MBSTRING_BMP:
|
||||
if (len & 1) {
|
||||
ASN1error(ASN1_R_INVALID_BMPSTRING_LENGTH);
|
||||
return -1;
|
||||
}
|
||||
nchar = len >> 1;
|
||||
break;
|
||||
|
||||
case MBSTRING_UNIV:
|
||||
if (len & 3) {
|
||||
ASN1error(ASN1_R_INVALID_UNIVERSALSTRING_LENGTH);
|
||||
return -1;
|
||||
}
|
||||
nchar = len >> 2;
|
||||
break;
|
||||
|
||||
case MBSTRING_UTF8:
|
||||
nchar = 0;
|
||||
/* This counts the characters and does utf8 syntax checking */
|
||||
ret = traverse_string(in, len, MBSTRING_UTF8, in_utf8, &nchar);
|
||||
if (ret < 0) {
|
||||
ASN1error(ASN1_R_INVALID_UTF8STRING);
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
||||
case MBSTRING_ASC:
|
||||
nchar = len;
|
||||
break;
|
||||
|
||||
default:
|
||||
ASN1error(ASN1_R_UNKNOWN_FORMAT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((minsize > 0) && (nchar < minsize)) {
|
||||
ASN1error(ASN1_R_STRING_TOO_SHORT);
|
||||
ERR_asprintf_error_data("minsize=%ld", minsize);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((maxsize > 0) && (nchar > maxsize)) {
|
||||
ASN1error(ASN1_R_STRING_TOO_LONG);
|
||||
ERR_asprintf_error_data("maxsize=%ld", maxsize);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Now work out minimal type (if any) */
|
||||
if (traverse_string(in, len, inform, type_str, &mask) < 0) {
|
||||
ASN1error(ASN1_R_ILLEGAL_CHARACTERS);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* Now work out output format and string type */
|
||||
outform = MBSTRING_ASC;
|
||||
if (mask & B_ASN1_PRINTABLESTRING)
|
||||
str_type = V_ASN1_PRINTABLESTRING;
|
||||
else if (mask & B_ASN1_IA5STRING)
|
||||
str_type = V_ASN1_IA5STRING;
|
||||
else if (mask & B_ASN1_T61STRING)
|
||||
str_type = V_ASN1_T61STRING;
|
||||
else if (mask & B_ASN1_BMPSTRING) {
|
||||
str_type = V_ASN1_BMPSTRING;
|
||||
outform = MBSTRING_BMP;
|
||||
} else if (mask & B_ASN1_UNIVERSALSTRING) {
|
||||
str_type = V_ASN1_UNIVERSALSTRING;
|
||||
outform = MBSTRING_UNIV;
|
||||
} else {
|
||||
str_type = V_ASN1_UTF8STRING;
|
||||
outform = MBSTRING_UTF8;
|
||||
}
|
||||
if (!out)
|
||||
return str_type;
|
||||
if (*out) {
|
||||
free_out = 0;
|
||||
dest = *out;
|
||||
if (dest->data) {
|
||||
dest->length = 0;
|
||||
free(dest->data);
|
||||
dest->data = NULL;
|
||||
}
|
||||
dest->type = str_type;
|
||||
} else {
|
||||
free_out = 1;
|
||||
dest = ASN1_STRING_type_new(str_type);
|
||||
if (!dest) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
return -1;
|
||||
}
|
||||
*out = dest;
|
||||
}
|
||||
/* If both the same type just copy across */
|
||||
if (inform == outform) {
|
||||
if (!ASN1_STRING_set(dest, in, len)) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
return str_type;
|
||||
}
|
||||
|
||||
/* Work out how much space the destination will need */
|
||||
switch (outform) {
|
||||
case MBSTRING_ASC:
|
||||
outlen = nchar;
|
||||
cpyfunc = cpy_asc;
|
||||
break;
|
||||
|
||||
case MBSTRING_BMP:
|
||||
outlen = nchar << 1;
|
||||
cpyfunc = cpy_bmp;
|
||||
break;
|
||||
|
||||
case MBSTRING_UNIV:
|
||||
outlen = nchar << 2;
|
||||
cpyfunc = cpy_univ;
|
||||
break;
|
||||
|
||||
case MBSTRING_UTF8:
|
||||
outlen = 0;
|
||||
if (traverse_string(in, len, inform, out_utf8, &outlen) < 0) {
|
||||
ASN1error(ASN1_R_ILLEGAL_CHARACTERS);
|
||||
goto err;
|
||||
}
|
||||
cpyfunc = cpy_utf8;
|
||||
break;
|
||||
}
|
||||
if (!(p = malloc(outlen + 1))) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
dest->length = outlen;
|
||||
dest->data = p;
|
||||
p[outlen] = 0;
|
||||
traverse_string(in, len, inform, cpyfunc, &p);
|
||||
return str_type;
|
||||
|
||||
err:
|
||||
if (free_out) {
|
||||
ASN1_STRING_free(dest);
|
||||
*out = NULL;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* This function traverses a string and passes the value of each character
|
||||
* to an optional function along with a void * argument.
|
||||
*/
|
||||
|
||||
static int
|
||||
traverse_string(const unsigned char *p, int len, int inform,
|
||||
int (*rfunc)(unsigned long value, void *in), void *arg)
|
||||
{
|
||||
unsigned long value;
|
||||
int ret;
|
||||
|
||||
while (len) {
|
||||
switch (inform) {
|
||||
case MBSTRING_ASC:
|
||||
value = *p++;
|
||||
len--;
|
||||
break;
|
||||
case MBSTRING_BMP:
|
||||
value = *p++ << 8;
|
||||
value |= *p++;
|
||||
/* BMP is explictly defined to not support surrogates */
|
||||
if (UNICODE_IS_SURROGATE(value))
|
||||
return -1;
|
||||
len -= 2;
|
||||
break;
|
||||
case MBSTRING_UNIV:
|
||||
value = (unsigned long)*p++ << 24;
|
||||
value |= *p++ << 16;
|
||||
value |= *p++ << 8;
|
||||
value |= *p++;
|
||||
if (value > UNICODE_MAX || UNICODE_IS_SURROGATE(value))
|
||||
return -1;
|
||||
len -= 4;
|
||||
break;
|
||||
default:
|
||||
ret = UTF8_getc(p, len, &value);
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
len -= ret;
|
||||
p += ret;
|
||||
break;
|
||||
}
|
||||
if (rfunc) {
|
||||
ret = rfunc(value, arg);
|
||||
if (ret <= 0)
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Various utility functions for traverse_string */
|
||||
|
||||
/* Just count number of characters */
|
||||
|
||||
static int
|
||||
in_utf8(unsigned long value, void *arg)
|
||||
{
|
||||
int *nchar;
|
||||
|
||||
nchar = arg;
|
||||
(*nchar)++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Determine size of output as a UTF8 String */
|
||||
|
||||
static int
|
||||
out_utf8(unsigned long value, void *arg)
|
||||
{
|
||||
int *outlen;
|
||||
int ret;
|
||||
|
||||
outlen = arg;
|
||||
ret = UTF8_putc(NULL, -1, value);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
*outlen += ret;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Determine the "type" of a string: check each character against a
|
||||
* supplied "mask".
|
||||
*/
|
||||
|
||||
static int
|
||||
type_str(unsigned long value, void *arg)
|
||||
{
|
||||
unsigned long types;
|
||||
|
||||
types = *((unsigned long *)arg);
|
||||
if ((types & B_ASN1_PRINTABLESTRING) && !is_printable(value))
|
||||
types &= ~B_ASN1_PRINTABLESTRING;
|
||||
if ((types & B_ASN1_IA5STRING) && (value > 127))
|
||||
types &= ~B_ASN1_IA5STRING;
|
||||
if ((types & B_ASN1_T61STRING) && (value > 0xff))
|
||||
types &= ~B_ASN1_T61STRING;
|
||||
if ((types & B_ASN1_BMPSTRING) && (value > 0xffff))
|
||||
types &= ~B_ASN1_BMPSTRING;
|
||||
if (!types)
|
||||
return -1;
|
||||
*((unsigned long *)arg) = types;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Copy one byte per character ASCII like strings */
|
||||
|
||||
static int
|
||||
cpy_asc(unsigned long value, void *arg)
|
||||
{
|
||||
unsigned char **p, *q;
|
||||
|
||||
p = arg;
|
||||
q = *p;
|
||||
*q = value;
|
||||
(*p)++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Copy two byte per character BMPStrings */
|
||||
|
||||
static int
|
||||
cpy_bmp(unsigned long value, void *arg)
|
||||
{
|
||||
unsigned char **p, *q;
|
||||
|
||||
p = arg;
|
||||
q = *p;
|
||||
*q++ = (value >> 8) & 0xff;
|
||||
*q = value & 0xff;
|
||||
*p += 2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Copy four byte per character UniversalStrings */
|
||||
|
||||
static int
|
||||
cpy_univ(unsigned long value, void *arg)
|
||||
{
|
||||
unsigned char **p, *q;
|
||||
|
||||
p = arg;
|
||||
q = *p;
|
||||
*q++ = (value >> 24) & 0xff;
|
||||
*q++ = (value >> 16) & 0xff;
|
||||
*q++ = (value >> 8) & 0xff;
|
||||
*q = value & 0xff;
|
||||
*p += 4;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Copy to a UTF8String */
|
||||
|
||||
static int
|
||||
cpy_utf8(unsigned long value, void *arg)
|
||||
{
|
||||
unsigned char **p;
|
||||
|
||||
int ret;
|
||||
p = arg;
|
||||
/* We already know there is enough room so pass 0xff as the length */
|
||||
ret = UTF8_putc(*p, 0xff, value);
|
||||
*p += ret;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Return 1 if the character is permitted in a PrintableString */
|
||||
static int
|
||||
is_printable(unsigned long value)
|
||||
{
|
||||
int ch;
|
||||
|
||||
if (value > 0x7f)
|
||||
return 0;
|
||||
ch = (int)value;
|
||||
|
||||
/* Note: we can't use 'isalnum' because certain accented
|
||||
* characters may count as alphanumeric in some environments.
|
||||
*/
|
||||
if ((ch >= 'a') && (ch <= 'z'))
|
||||
return 1;
|
||||
if ((ch >= 'A') && (ch <= 'Z'))
|
||||
return 1;
|
||||
if ((ch >= '0') && (ch <= '9'))
|
||||
return 1;
|
||||
if ((ch == ' ') || strchr("'()+,-./:=?", ch))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
660
externals/libressl/crypto/asn1/a_object.c
vendored
660
externals/libressl/crypto/asn1/a_object.c
vendored
@@ -1,660 +0,0 @@
|
||||
/* $OpenBSD: a_object.c,v 1.46 2022/04/10 12:42:33 inoguchi 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 <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/objects.h>
|
||||
|
||||
#include "asn1_locl.h"
|
||||
|
||||
const ASN1_ITEM ASN1_OBJECT_it = {
|
||||
.itype = ASN1_ITYPE_PRIMITIVE,
|
||||
.utype = V_ASN1_OBJECT,
|
||||
.sname = "ASN1_OBJECT",
|
||||
};
|
||||
|
||||
ASN1_OBJECT *
|
||||
ASN1_OBJECT_new(void)
|
||||
{
|
||||
ASN1_OBJECT *a;
|
||||
|
||||
if ((a = calloc(1, sizeof(ASN1_OBJECT))) == NULL) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
return (NULL);
|
||||
}
|
||||
a->flags = ASN1_OBJECT_FLAG_DYNAMIC;
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_OBJECT_free(ASN1_OBJECT *a)
|
||||
{
|
||||
if (a == NULL)
|
||||
return;
|
||||
if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) {
|
||||
free((void *)a->sn);
|
||||
free((void *)a->ln);
|
||||
a->sn = a->ln = NULL;
|
||||
}
|
||||
if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) {
|
||||
freezero((void *)a->data, a->length);
|
||||
a->data = NULL;
|
||||
a->length = 0;
|
||||
}
|
||||
if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC)
|
||||
free(a);
|
||||
}
|
||||
|
||||
ASN1_OBJECT *
|
||||
ASN1_OBJECT_create(int nid, unsigned char *data, int len,
|
||||
const char *sn, const char *ln)
|
||||
{
|
||||
ASN1_OBJECT o;
|
||||
|
||||
o.sn = sn;
|
||||
o.ln = ln;
|
||||
o.data = data;
|
||||
o.nid = nid;
|
||||
o.length = len;
|
||||
o.flags = ASN1_OBJECT_FLAG_DYNAMIC | ASN1_OBJECT_FLAG_DYNAMIC_STRINGS |
|
||||
ASN1_OBJECT_FLAG_DYNAMIC_DATA;
|
||||
return (OBJ_dup(&o));
|
||||
}
|
||||
|
||||
static int
|
||||
oid_add_arc(CBB *cbb, uint64_t arc)
|
||||
{
|
||||
int started = 0;
|
||||
uint8_t val;
|
||||
int i;
|
||||
|
||||
for (i = (sizeof(arc) * 8) / 7; i >= 0; i--) {
|
||||
val = (arc >> (i * 7)) & 0x7f;
|
||||
if (!started && i != 0 && val == 0)
|
||||
continue;
|
||||
if (i > 0)
|
||||
val |= 0x80;
|
||||
if (!CBB_add_u8(cbb, val))
|
||||
return 0;
|
||||
started = 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
oid_parse_arc(CBS *cbs, uint64_t *out_arc)
|
||||
{
|
||||
uint64_t arc = 0;
|
||||
uint8_t val;
|
||||
|
||||
do {
|
||||
if (!CBS_get_u8(cbs, &val))
|
||||
return 0;
|
||||
if (arc == 0 && val == 0x80)
|
||||
return 0;
|
||||
if (out_arc != NULL && arc > (UINT64_MAX >> 7))
|
||||
return 0;
|
||||
arc = (arc << 7) | (val & 0x7f);
|
||||
} while (val & 0x80);
|
||||
|
||||
if (out_arc != NULL)
|
||||
*out_arc = arc;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
oid_add_arc_txt(CBB *cbb, uint64_t arc, int first)
|
||||
{
|
||||
const char *fmt = ".%llu";
|
||||
char s[22]; /* Digits in decimal representation of 2^64-1, plus '.' and NUL. */
|
||||
int n;
|
||||
|
||||
if (first)
|
||||
fmt = "%llu";
|
||||
n = snprintf(s, sizeof(s), fmt, (unsigned long long)arc);
|
||||
if (n < 0 || (size_t)n >= sizeof(s))
|
||||
return 0;
|
||||
if (!CBB_add_bytes(cbb, s, n))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
oid_parse_arc_txt(CBS *cbs, uint64_t *out_arc, char *separator, int first)
|
||||
{
|
||||
uint64_t arc = 0;
|
||||
int digits = 0;
|
||||
uint8_t val;
|
||||
|
||||
if (!first) {
|
||||
if (!CBS_get_u8(cbs, &val))
|
||||
return 0;
|
||||
if ((*separator == 0 && val != '.' && val != ' ') ||
|
||||
(*separator != 0 && val != *separator)) {
|
||||
ASN1error(ASN1_R_INVALID_SEPARATOR);
|
||||
return 0;
|
||||
}
|
||||
*separator = val;
|
||||
}
|
||||
|
||||
while (CBS_len(cbs) > 0) {
|
||||
if (!CBS_peek_u8(cbs, &val))
|
||||
return 0;
|
||||
if (val == '.' || val == ' ')
|
||||
break;
|
||||
|
||||
if (!CBS_get_u8(cbs, &val))
|
||||
return 0;
|
||||
if (val < '0' || val > '9') {
|
||||
/* For the first arc we treat this as the separator. */
|
||||
if (first) {
|
||||
ASN1error(ASN1_R_INVALID_SEPARATOR);
|
||||
return 0;
|
||||
}
|
||||
ASN1error(ASN1_R_INVALID_DIGIT);
|
||||
return 0;
|
||||
}
|
||||
val -= '0';
|
||||
|
||||
if (digits > 0 && arc == 0 && val == 0) {
|
||||
ASN1error(ASN1_R_INVALID_NUMBER);
|
||||
return 0;
|
||||
}
|
||||
digits++;
|
||||
|
||||
if (arc > UINT64_MAX / 10) {
|
||||
ASN1error(ASN1_R_TOO_LONG);
|
||||
return 0;
|
||||
}
|
||||
arc = arc * 10 + val;
|
||||
}
|
||||
|
||||
if (digits < 1) {
|
||||
ASN1error(ASN1_R_INVALID_NUMBER);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*out_arc = arc;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
a2c_ASN1_OBJECT_internal(CBB *cbb, CBS *cbs)
|
||||
{
|
||||
uint64_t arc, si1, si2;
|
||||
char separator = 0;
|
||||
|
||||
if (!oid_parse_arc_txt(cbs, &si1, &separator, 1))
|
||||
return 0;
|
||||
|
||||
if (CBS_len(cbs) == 0) {
|
||||
ASN1error(ASN1_R_MISSING_SECOND_NUMBER);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!oid_parse_arc_txt(cbs, &si2, &separator, 0))
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* X.690 section 8.19 - the first two subidentifiers are encoded as
|
||||
* (x * 40) + y, with x being limited to [0,1,2]. The second
|
||||
* subidentifier cannot exceed 39 for x < 2.
|
||||
*/
|
||||
if (si1 > 2) {
|
||||
ASN1error(ASN1_R_FIRST_NUM_TOO_LARGE);
|
||||
return 0;
|
||||
}
|
||||
if ((si1 < 2 && si2 >= 40) || si2 > UINT64_MAX - si1 * 40) {
|
||||
ASN1error(ASN1_R_SECOND_NUMBER_TOO_LARGE);
|
||||
return 0;
|
||||
}
|
||||
arc = si1 * 40 + si2;
|
||||
|
||||
if (!oid_add_arc(cbb, arc))
|
||||
return 0;
|
||||
|
||||
while (CBS_len(cbs) > 0) {
|
||||
if (!oid_parse_arc_txt(cbs, &arc, &separator, 0))
|
||||
return 0;
|
||||
if (!oid_add_arc(cbb, arc))
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
c2a_ASN1_OBJECT(CBS *cbs, CBB *cbb)
|
||||
{
|
||||
uint64_t arc, si1, si2;
|
||||
|
||||
/*
|
||||
* X.690 section 8.19 - the first two subidentifiers are encoded as
|
||||
* (x * 40) + y, with x being limited to [0,1,2].
|
||||
*/
|
||||
if (!oid_parse_arc(cbs, &arc))
|
||||
return 0;
|
||||
if ((si1 = arc / 40) > 2)
|
||||
si1 = 2;
|
||||
si2 = arc - si1 * 40;
|
||||
|
||||
if (!oid_add_arc_txt(cbb, si1, 1))
|
||||
return 0;
|
||||
if (!oid_add_arc_txt(cbb, si2, 0))
|
||||
return 0;
|
||||
|
||||
while (CBS_len(cbs) > 0) {
|
||||
if (!oid_parse_arc(cbs, &arc))
|
||||
return 0;
|
||||
if (!oid_add_arc_txt(cbb, arc, 0))
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* NUL terminate. */
|
||||
if (!CBB_add_u8(cbb, 0))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
a2d_ASN1_OBJECT(unsigned char *out, int out_len, const char *in, int in_len)
|
||||
{
|
||||
uint8_t *data = NULL;
|
||||
size_t data_len;
|
||||
CBS cbs;
|
||||
CBB cbb;
|
||||
int ret = 0;
|
||||
|
||||
memset(&cbb, 0, sizeof(cbb));
|
||||
|
||||
if (in_len == -1)
|
||||
in_len = strlen(in);
|
||||
if (in_len <= 0)
|
||||
goto err;
|
||||
|
||||
CBS_init(&cbs, in, in_len);
|
||||
|
||||
if (!CBB_init(&cbb, 0))
|
||||
goto err;
|
||||
if (!a2c_ASN1_OBJECT_internal(&cbb, &cbs))
|
||||
goto err;
|
||||
if (!CBB_finish(&cbb, &data, &data_len))
|
||||
goto err;
|
||||
|
||||
if (data_len > INT_MAX)
|
||||
goto err;
|
||||
|
||||
if (out != NULL) {
|
||||
if (out_len <= 0 || (size_t)out_len < data_len) {
|
||||
ASN1error(ASN1_R_BUFFER_TOO_SMALL);
|
||||
goto err;
|
||||
}
|
||||
memcpy(out, data, data_len);
|
||||
}
|
||||
|
||||
ret = (int)data_len;
|
||||
|
||||
err:
|
||||
CBB_cleanup(&cbb);
|
||||
free(data);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
i2t_ASN1_OBJECT_oid(const ASN1_OBJECT *aobj, CBB *cbb)
|
||||
{
|
||||
CBS cbs;
|
||||
|
||||
CBS_init(&cbs, aobj->data, aobj->length);
|
||||
|
||||
return c2a_ASN1_OBJECT(&cbs, cbb);
|
||||
}
|
||||
|
||||
static int
|
||||
i2t_ASN1_OBJECT_name(const ASN1_OBJECT *aobj, CBB *cbb, const char **out_name)
|
||||
{
|
||||
const char *name;
|
||||
int nid;
|
||||
|
||||
*out_name = NULL;
|
||||
|
||||
if ((nid = OBJ_obj2nid(aobj)) == NID_undef)
|
||||
return 0;
|
||||
|
||||
if ((name = OBJ_nid2ln(nid)) == NULL)
|
||||
name = OBJ_nid2sn(nid);
|
||||
if (name == NULL)
|
||||
return 0;
|
||||
|
||||
*out_name = name;
|
||||
|
||||
if (!CBB_add_bytes(cbb, name, strlen(name)))
|
||||
return 0;
|
||||
|
||||
/* NUL terminate. */
|
||||
if (!CBB_add_u8(cbb, 0))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
i2t_ASN1_OBJECT_cbb(const ASN1_OBJECT *aobj, CBB *cbb, int no_name)
|
||||
{
|
||||
const char *name;
|
||||
|
||||
if (!no_name) {
|
||||
if (i2t_ASN1_OBJECT_name(aobj, cbb, &name))
|
||||
return 1;
|
||||
if (name != NULL)
|
||||
return 0;
|
||||
}
|
||||
return i2t_ASN1_OBJECT_oid(aobj, cbb);
|
||||
}
|
||||
|
||||
int
|
||||
i2t_ASN1_OBJECT_internal(const ASN1_OBJECT *aobj, char *buf, int buf_len, int no_name)
|
||||
{
|
||||
uint8_t *data = NULL;
|
||||
size_t data_len;
|
||||
CBB cbb;
|
||||
int ret = 0;
|
||||
|
||||
if (buf_len < 0)
|
||||
return 0;
|
||||
if (buf_len > 0)
|
||||
buf[0] = '\0';
|
||||
|
||||
if (!CBB_init(&cbb, 0))
|
||||
goto err;
|
||||
if (!i2t_ASN1_OBJECT_cbb(aobj, &cbb, no_name))
|
||||
goto err;
|
||||
if (!CBB_finish(&cbb, &data, &data_len))
|
||||
goto err;
|
||||
|
||||
ret = strlcpy(buf, data, buf_len);
|
||||
err:
|
||||
CBB_cleanup(&cbb);
|
||||
free(data);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
i2t_ASN1_OBJECT(char *buf, int buf_len, const ASN1_OBJECT *aobj)
|
||||
{
|
||||
return i2t_ASN1_OBJECT_internal(aobj, buf, buf_len, 0);
|
||||
}
|
||||
|
||||
ASN1_OBJECT *
|
||||
t2i_ASN1_OBJECT_internal(const char *oid)
|
||||
{
|
||||
ASN1_OBJECT *aobj = NULL;
|
||||
uint8_t *data = NULL;
|
||||
size_t data_len;
|
||||
CBB cbb;
|
||||
CBS cbs;
|
||||
|
||||
memset(&cbb, 0, sizeof(cbb));
|
||||
|
||||
CBS_init(&cbs, oid, strlen(oid));
|
||||
|
||||
if (!CBB_init(&cbb, 0))
|
||||
goto err;
|
||||
if (!a2c_ASN1_OBJECT_internal(&cbb, &cbs))
|
||||
goto err;
|
||||
if (!CBB_finish(&cbb, &data, &data_len))
|
||||
goto err;
|
||||
|
||||
if (data_len > INT_MAX)
|
||||
goto err;
|
||||
|
||||
if ((aobj = ASN1_OBJECT_new()) == NULL)
|
||||
goto err;
|
||||
|
||||
aobj->data = data;
|
||||
aobj->length = (int)data_len;
|
||||
aobj->flags |= ASN1_OBJECT_FLAG_DYNAMIC_DATA;
|
||||
data = NULL;
|
||||
|
||||
err:
|
||||
CBB_cleanup(&cbb);
|
||||
free(data);
|
||||
|
||||
return aobj;
|
||||
}
|
||||
|
||||
int
|
||||
i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *aobj)
|
||||
{
|
||||
uint8_t *data = NULL;
|
||||
size_t data_len;
|
||||
CBB cbb;
|
||||
int ret = -1;
|
||||
|
||||
if (aobj == NULL || aobj->data == NULL)
|
||||
return BIO_write(bp, "NULL", 4);
|
||||
|
||||
if (!CBB_init(&cbb, 0))
|
||||
goto err;
|
||||
if (!i2t_ASN1_OBJECT_cbb(aobj, &cbb, 0)) {
|
||||
ret = BIO_write(bp, "<INVALID>", 9);
|
||||
goto err;
|
||||
}
|
||||
if (!CBB_finish(&cbb, &data, &data_len))
|
||||
goto err;
|
||||
|
||||
ret = BIO_write(bp, data, strlen(data));
|
||||
|
||||
err:
|
||||
CBB_cleanup(&cbb);
|
||||
free(data);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
c2i_ASN1_OBJECT_cbs(ASN1_OBJECT **out_aobj, CBS *content)
|
||||
{
|
||||
ASN1_OBJECT *aobj = NULL;
|
||||
uint8_t *data = NULL;
|
||||
size_t data_len;
|
||||
CBS cbs;
|
||||
|
||||
if (out_aobj == NULL || *out_aobj != NULL)
|
||||
goto err;
|
||||
|
||||
/* Parse and validate OID encoding per X.690 8.19.2. */
|
||||
CBS_dup(content, &cbs);
|
||||
if (CBS_len(&cbs) == 0) {
|
||||
ASN1error(ASN1_R_INVALID_OBJECT_ENCODING);
|
||||
goto err;
|
||||
}
|
||||
while (CBS_len(&cbs) > 0) {
|
||||
if (!oid_parse_arc(&cbs, NULL)) {
|
||||
ASN1error(ASN1_R_INVALID_OBJECT_ENCODING);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
if (!CBS_stow(content, &data, &data_len))
|
||||
goto err;
|
||||
|
||||
if (data_len > INT_MAX)
|
||||
goto err;
|
||||
|
||||
if ((aobj = ASN1_OBJECT_new()) == NULL)
|
||||
goto err;
|
||||
|
||||
aobj->data = data;
|
||||
aobj->length = (int)data_len; /* XXX - change length to size_t. */
|
||||
aobj->flags |= ASN1_OBJECT_FLAG_DYNAMIC_DATA;
|
||||
|
||||
*out_aobj = aobj;
|
||||
|
||||
return 1;
|
||||
|
||||
err:
|
||||
ASN1_OBJECT_free(aobj);
|
||||
free(data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
ASN1_OBJECT *
|
||||
c2i_ASN1_OBJECT(ASN1_OBJECT **out_aobj, const unsigned char **pp, long len)
|
||||
{
|
||||
ASN1_OBJECT *aobj = NULL;
|
||||
CBS content;
|
||||
|
||||
if (out_aobj != NULL) {
|
||||
ASN1_OBJECT_free(*out_aobj);
|
||||
*out_aobj = NULL;
|
||||
}
|
||||
|
||||
if (len < 0) {
|
||||
ASN1error(ASN1_R_LENGTH_ERROR);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CBS_init(&content, *pp, len);
|
||||
|
||||
if (!c2i_ASN1_OBJECT_cbs(&aobj, &content))
|
||||
return NULL;
|
||||
|
||||
*pp = CBS_data(&content);
|
||||
|
||||
if (out_aobj != NULL)
|
||||
*out_aobj = aobj;
|
||||
|
||||
return aobj;
|
||||
}
|
||||
|
||||
int
|
||||
i2d_ASN1_OBJECT(const ASN1_OBJECT *a, unsigned char **pp)
|
||||
{
|
||||
unsigned char *p;
|
||||
int objsize;
|
||||
|
||||
if ((a == NULL) || (a->data == NULL))
|
||||
return (0);
|
||||
|
||||
objsize = ASN1_object_size(0, a->length, V_ASN1_OBJECT);
|
||||
if (pp == NULL)
|
||||
return objsize;
|
||||
|
||||
p = *pp;
|
||||
ASN1_put_object(&p, 0, a->length, V_ASN1_OBJECT, V_ASN1_UNIVERSAL);
|
||||
memcpy(p, a->data, a->length);
|
||||
p += a->length;
|
||||
|
||||
*pp = p;
|
||||
return (objsize);
|
||||
}
|
||||
|
||||
ASN1_OBJECT *
|
||||
d2i_ASN1_OBJECT(ASN1_OBJECT **out_aobj, const unsigned char **pp, long length)
|
||||
{
|
||||
ASN1_OBJECT *aobj = NULL;
|
||||
uint32_t tag_number;
|
||||
CBS cbs, content;
|
||||
|
||||
if (out_aobj != NULL) {
|
||||
ASN1_OBJECT_free(*out_aobj);
|
||||
*out_aobj = NULL;
|
||||
}
|
||||
|
||||
if (length < 0) {
|
||||
ASN1error(ASN1_R_LENGTH_ERROR);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CBS_init(&cbs, *pp, length);
|
||||
|
||||
if (!asn1_get_primitive(&cbs, 0, &tag_number, &content)) {
|
||||
ASN1error(ASN1_R_BAD_OBJECT_HEADER);
|
||||
return NULL;
|
||||
}
|
||||
if (tag_number != V_ASN1_OBJECT) {
|
||||
ASN1error(ASN1_R_EXPECTING_AN_OBJECT);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!c2i_ASN1_OBJECT_cbs(&aobj, &content))
|
||||
return NULL;
|
||||
|
||||
*pp = CBS_data(&content);
|
||||
|
||||
if (out_aobj != NULL)
|
||||
*out_aobj = aobj;
|
||||
|
||||
return aobj;
|
||||
}
|
||||
112
externals/libressl/crypto/asn1/a_octet.c
vendored
112
externals/libressl/crypto/asn1/a_octet.c
vendored
@@ -1,112 +0,0 @@
|
||||
/* $OpenBSD: a_octet.c,v 1.11 2021/12/25 08:52:44 jsing 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 <openssl/asn1.h>
|
||||
#include <openssl/asn1t.h>
|
||||
|
||||
const ASN1_ITEM ASN1_OCTET_STRING_it = {
|
||||
.itype = ASN1_ITYPE_PRIMITIVE,
|
||||
.utype = V_ASN1_OCTET_STRING,
|
||||
.sname = "ASN1_OCTET_STRING",
|
||||
};
|
||||
|
||||
ASN1_OCTET_STRING *
|
||||
ASN1_OCTET_STRING_new(void)
|
||||
{
|
||||
return (ASN1_OCTET_STRING *)ASN1_item_new(&ASN1_OCTET_STRING_it);
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_OCTET_STRING_free(ASN1_OCTET_STRING *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &ASN1_OCTET_STRING_it);
|
||||
}
|
||||
|
||||
|
||||
ASN1_OCTET_STRING *
|
||||
ASN1_OCTET_STRING_dup(const ASN1_OCTET_STRING *x)
|
||||
{
|
||||
return ASN1_STRING_dup(x);
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a, const ASN1_OCTET_STRING *b)
|
||||
{
|
||||
return ASN1_STRING_cmp(a, b);
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, const unsigned char *d, int len)
|
||||
{
|
||||
return ASN1_STRING_set(x, d, len);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_ASN1_OCTET_STRING(ASN1_OCTET_STRING *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_OCTET_STRING_it);
|
||||
}
|
||||
|
||||
ASN1_OCTET_STRING *
|
||||
d2i_ASN1_OCTET_STRING(ASN1_OCTET_STRING **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (ASN1_OCTET_STRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&ASN1_OCTET_STRING_it);
|
||||
}
|
||||
186
externals/libressl/crypto/asn1/a_pkey.c
vendored
186
externals/libressl/crypto/asn1/a_pkey.c
vendored
@@ -1,186 +0,0 @@
|
||||
/* $OpenBSD: a_pkey.c,v 1.3 2021/12/25 13:17:48 jsing 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 <openssl/opensslconf.h>
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
#include <openssl/engine.h>
|
||||
#endif
|
||||
|
||||
#include "asn1_locl.h"
|
||||
#include "evp_locl.h"
|
||||
|
||||
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)) {
|
||||
if ((ret = EVP_PKEY_new()) == NULL) {
|
||||
ASN1error(ERR_R_EVP_LIB);
|
||||
return (NULL);
|
||||
}
|
||||
} else {
|
||||
ret = *a;
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
ENGINE_finish(ret->engine);
|
||||
ret->engine = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!EVP_PKEY_set_type(ret, type)) {
|
||||
ASN1error(ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!ret->ameth->old_priv_decode ||
|
||||
!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;
|
||||
EVP_PKEY_free(ret);
|
||||
ret = EVP_PKCS82PKEY(p8);
|
||||
PKCS8_PRIV_KEY_INFO_free(p8);
|
||||
} else {
|
||||
ASN1error(ERR_R_ASN1_LIB);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
if (a != NULL)
|
||||
(*a) = ret;
|
||||
return (ret);
|
||||
|
||||
err:
|
||||
if (a == NULL || *a != ret)
|
||||
EVP_PKEY_free(ret);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp)
|
||||
{
|
||||
if (a->ameth && a->ameth->old_priv_encode) {
|
||||
return a->ameth->old_priv_encode(a, pp);
|
||||
}
|
||||
if (a->ameth && a->ameth->priv_encode) {
|
||||
PKCS8_PRIV_KEY_INFO *p8 = EVP_PKEY2PKCS8(a);
|
||||
int ret = i2d_PKCS8_PRIV_KEY_INFO(p8, pp);
|
||||
PKCS8_PRIV_KEY_INFO_free(p8);
|
||||
return ret;
|
||||
}
|
||||
ASN1error(ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* This works like d2i_PrivateKey() except it automatically works out the type */
|
||||
|
||||
EVP_PKEY *
|
||||
d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp, long length)
|
||||
{
|
||||
STACK_OF(ASN1_TYPE) *inkey;
|
||||
const unsigned char *p;
|
||||
int keytype;
|
||||
|
||||
p = *pp;
|
||||
/* Dirty trick: read in the ASN1 data into a STACK_OF(ASN1_TYPE):
|
||||
* by analyzing it we can determine the passed structure: this
|
||||
* assumes the input is surrounded by an ASN1 SEQUENCE.
|
||||
*/
|
||||
inkey = d2i_ASN1_SEQUENCE_ANY(NULL, &p, length);
|
||||
/* Since we only need to discern "traditional format" RSA and DSA
|
||||
* keys we can just count the elements.
|
||||
*/
|
||||
if (sk_ASN1_TYPE_num(inkey) == 6)
|
||||
keytype = EVP_PKEY_DSA;
|
||||
else if (sk_ASN1_TYPE_num(inkey) == 4)
|
||||
keytype = EVP_PKEY_EC;
|
||||
else if (sk_ASN1_TYPE_num(inkey) == 3) {
|
||||
/* This seems to be PKCS8, not traditional format */
|
||||
PKCS8_PRIV_KEY_INFO *p8 = d2i_PKCS8_PRIV_KEY_INFO(
|
||||
NULL, pp, length);
|
||||
EVP_PKEY *ret;
|
||||
|
||||
sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free);
|
||||
if (!p8) {
|
||||
ASN1error(ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
|
||||
return NULL;
|
||||
}
|
||||
ret = EVP_PKCS82PKEY(p8);
|
||||
PKCS8_PRIV_KEY_INFO_free(p8);
|
||||
if (a) {
|
||||
*a = ret;
|
||||
}
|
||||
return ret;
|
||||
} else
|
||||
keytype = EVP_PKEY_RSA;
|
||||
sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free);
|
||||
return d2i_PrivateKey(keytype, a, pp, length);
|
||||
}
|
||||
125
externals/libressl/crypto/asn1/a_print.c
vendored
125
externals/libressl/crypto/asn1/a_print.c
vendored
@@ -1,125 +0,0 @@
|
||||
/* $OpenBSD: a_print.c,v 1.11 2014/07/11 08:44:47 jsing 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 <openssl/asn1.h>
|
||||
|
||||
int
|
||||
ASN1_PRINTABLE_type(const unsigned char *s, int len)
|
||||
{
|
||||
int c;
|
||||
int ia5 = 0;
|
||||
int t61 = 0;
|
||||
|
||||
if (len <= 0)
|
||||
len = -1;
|
||||
if (s == NULL)
|
||||
return (V_ASN1_PRINTABLESTRING);
|
||||
|
||||
while ((*s) && (len-- != 0)) {
|
||||
c= *(s++);
|
||||
if (!(((c >= 'a') && (c <= 'z')) ||
|
||||
((c >= 'A') && (c <= 'Z')) ||
|
||||
(c == ' ') ||
|
||||
((c >= '0') && (c <= '9')) ||
|
||||
(c == ' ') || (c == '\'') ||
|
||||
(c == '(') || (c == ')') ||
|
||||
(c == '+') || (c == ',') ||
|
||||
(c == '-') || (c == '.') ||
|
||||
(c == '/') || (c == ':') ||
|
||||
(c == '=') || (c == '?')))
|
||||
ia5 = 1;
|
||||
if (c & 0x80)
|
||||
t61 = 1;
|
||||
}
|
||||
if (t61)
|
||||
return (V_ASN1_T61STRING);
|
||||
if (ia5)
|
||||
return (V_ASN1_IA5STRING);
|
||||
return (V_ASN1_PRINTABLESTRING);
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s)
|
||||
{
|
||||
int i;
|
||||
unsigned char *p;
|
||||
|
||||
if (s->type != V_ASN1_UNIVERSALSTRING)
|
||||
return (0);
|
||||
if ((s->length % 4) != 0)
|
||||
return (0);
|
||||
p = s->data;
|
||||
for (i = 0; i < s->length; i += 4) {
|
||||
if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0'))
|
||||
break;
|
||||
else
|
||||
p += 4;
|
||||
}
|
||||
if (i < s->length)
|
||||
return (0);
|
||||
p = s->data;
|
||||
for (i = 3; i < s->length; i += 4) {
|
||||
*(p++) = s->data[i];
|
||||
}
|
||||
*(p) = '\0';
|
||||
s->length /= 4;
|
||||
s->type = ASN1_PRINTABLE_type(s->data, s->length);
|
||||
return (1);
|
||||
}
|
||||
160
externals/libressl/crypto/asn1/a_pubkey.c
vendored
160
externals/libressl/crypto/asn1/a_pubkey.c
vendored
@@ -1,160 +0,0 @@
|
||||
/* $OpenBSD: a_pubkey.c,v 1.3 2021/12/25 13:17:48 jsing 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 <openssl/opensslconf.h>
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/objects.h>
|
||||
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
#include <openssl/dsa.h>
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_EC
|
||||
#include <openssl/ec.h>
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
#include <openssl/rsa.h>
|
||||
#endif
|
||||
|
||||
#include "evp_locl.h"
|
||||
|
||||
EVP_PKEY *
|
||||
d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, long length)
|
||||
{
|
||||
EVP_PKEY *ret;
|
||||
|
||||
if ((a == NULL) || (*a == NULL)) {
|
||||
if ((ret = EVP_PKEY_new()) == NULL) {
|
||||
ASN1error(ERR_R_EVP_LIB);
|
||||
return (NULL);
|
||||
}
|
||||
} else
|
||||
ret = *a;
|
||||
|
||||
if (!EVP_PKEY_set_type(ret, type)) {
|
||||
ASN1error(ERR_R_EVP_LIB);
|
||||
goto err;
|
||||
}
|
||||
|
||||
switch (EVP_PKEY_id(ret)) {
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
case EVP_PKEY_RSA:
|
||||
if ((ret->pkey.rsa = d2i_RSAPublicKey(NULL, pp, length)) ==
|
||||
NULL) {
|
||||
ASN1error(ERR_R_ASN1_LIB);
|
||||
goto err;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
case EVP_PKEY_DSA:
|
||||
if (!d2i_DSAPublicKey(&(ret->pkey.dsa), pp, length)) {
|
||||
ASN1error(ERR_R_ASN1_LIB);
|
||||
goto err;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_EC
|
||||
case EVP_PKEY_EC:
|
||||
if (!o2i_ECPublicKey(&(ret->pkey.ec), pp, length)) {
|
||||
ASN1error(ERR_R_ASN1_LIB);
|
||||
goto err;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
ASN1error(ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);
|
||||
goto err;
|
||||
/* break; */
|
||||
}
|
||||
if (a != NULL)
|
||||
(*a) = ret;
|
||||
return (ret);
|
||||
|
||||
err:
|
||||
if (a == NULL || *a != ret)
|
||||
EVP_PKEY_free(ret);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_PublicKey(EVP_PKEY *a, unsigned char **pp)
|
||||
{
|
||||
switch (a->type) {
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
case EVP_PKEY_RSA:
|
||||
return (i2d_RSAPublicKey(a->pkey.rsa, pp));
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
case EVP_PKEY_DSA:
|
||||
return (i2d_DSAPublicKey(a->pkey.dsa, pp));
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_EC
|
||||
case EVP_PKEY_EC:
|
||||
return (i2o_ECPublicKey(a->pkey.ec, pp));
|
||||
#endif
|
||||
default:
|
||||
ASN1error(ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
601
externals/libressl/crypto/asn1/a_strex.c
vendored
601
externals/libressl/crypto/asn1/a_strex.c
vendored
@@ -1,601 +0,0 @@
|
||||
/* $OpenBSD: a_strex.c,v 1.31 2021/12/25 12:11:57 jsing Exp $ */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 2000.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2000 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
#include "asn1_locl.h"
|
||||
|
||||
#include "charmap.h"
|
||||
|
||||
/* ASN1_STRING_print_ex() and X509_NAME_print_ex().
|
||||
* Enhanced string and name printing routines handling
|
||||
* multibyte characters, RFC2253 and a host of other
|
||||
* options.
|
||||
*/
|
||||
|
||||
#define CHARTYPE_BS_ESC (ASN1_STRFLGS_ESC_2253 | CHARTYPE_FIRST_ESC_2253 | CHARTYPE_LAST_ESC_2253)
|
||||
|
||||
#define ESC_FLAGS (ASN1_STRFLGS_ESC_2253 | \
|
||||
ASN1_STRFLGS_ESC_QUOTE | \
|
||||
ASN1_STRFLGS_ESC_CTRL | \
|
||||
ASN1_STRFLGS_ESC_MSB)
|
||||
|
||||
|
||||
/* Three IO functions for sending data to memory, a BIO and
|
||||
* and a FILE pointer.
|
||||
*/
|
||||
static int
|
||||
send_bio_chars(void *arg, const void *buf, int len)
|
||||
{
|
||||
if (!arg)
|
||||
return 1;
|
||||
if (BIO_write(arg, buf, len) != len)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
send_fp_chars(void *arg, const void *buf, int len)
|
||||
{
|
||||
if (!arg)
|
||||
return 1;
|
||||
if (fwrite(buf, 1, (size_t)len, arg) != (size_t)len)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
typedef int char_io(void *arg, const void *buf, int len);
|
||||
|
||||
/* This function handles display of
|
||||
* strings, one character at a time.
|
||||
* It is passed an unsigned long for each
|
||||
* character because it could come from 2 or even
|
||||
* 4 byte forms.
|
||||
*/
|
||||
|
||||
static int
|
||||
do_esc_char(unsigned long c, unsigned char flags, char *do_quotes,
|
||||
char_io *io_ch, void *arg)
|
||||
{
|
||||
unsigned char chflgs, chtmp;
|
||||
char tmphex[sizeof(long) * 2 + 3];
|
||||
|
||||
if (c > 0xffffffffL)
|
||||
return -1;
|
||||
if (c > 0xffff) {
|
||||
snprintf(tmphex, sizeof tmphex, "\\W%08lX", c);
|
||||
if (!io_ch(arg, tmphex, 10))
|
||||
return -1;
|
||||
return 10;
|
||||
}
|
||||
if (c > 0xff) {
|
||||
snprintf(tmphex, sizeof tmphex, "\\U%04lX", c);
|
||||
if (!io_ch(arg, tmphex, 6))
|
||||
return -1;
|
||||
return 6;
|
||||
}
|
||||
chtmp = (unsigned char)c;
|
||||
if (chtmp > 0x7f)
|
||||
chflgs = flags & ASN1_STRFLGS_ESC_MSB;
|
||||
else
|
||||
chflgs = char_type[chtmp] & flags;
|
||||
if (chflgs & CHARTYPE_BS_ESC) {
|
||||
/* If we don't escape with quotes, signal we need quotes */
|
||||
if (chflgs & ASN1_STRFLGS_ESC_QUOTE) {
|
||||
if (do_quotes)
|
||||
*do_quotes = 1;
|
||||
if (!io_ch(arg, &chtmp, 1))
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
if (!io_ch(arg, "\\", 1))
|
||||
return -1;
|
||||
if (!io_ch(arg, &chtmp, 1))
|
||||
return -1;
|
||||
return 2;
|
||||
}
|
||||
if (chflgs & (ASN1_STRFLGS_ESC_CTRL|ASN1_STRFLGS_ESC_MSB)) {
|
||||
snprintf(tmphex, sizeof tmphex, "\\%02X", chtmp);
|
||||
if (!io_ch(arg, tmphex, 3))
|
||||
return -1;
|
||||
return 3;
|
||||
}
|
||||
/* If we get this far and do any escaping at all must escape
|
||||
* the escape character itself: backslash.
|
||||
*/
|
||||
if (chtmp == '\\' && flags & ESC_FLAGS) {
|
||||
if (!io_ch(arg, "\\\\", 2))
|
||||
return -1;
|
||||
return 2;
|
||||
}
|
||||
if (!io_ch(arg, &chtmp, 1))
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define BUF_TYPE_WIDTH_MASK 0x7
|
||||
#define BUF_TYPE_CONVUTF8 0x8
|
||||
|
||||
/* This function sends each character in a buffer to
|
||||
* do_esc_char(). It interprets the content formats
|
||||
* and converts to or from UTF8 as appropriate.
|
||||
*/
|
||||
|
||||
static int
|
||||
do_buf(unsigned char *buf, int buflen, int type, unsigned char flags,
|
||||
char *quotes, char_io *io_ch, void *arg)
|
||||
{
|
||||
int i, outlen, len;
|
||||
unsigned char orflags, *p, *q;
|
||||
unsigned long c;
|
||||
|
||||
p = buf;
|
||||
q = buf + buflen;
|
||||
outlen = 0;
|
||||
while (p != q) {
|
||||
if (p == buf && flags & ASN1_STRFLGS_ESC_2253)
|
||||
orflags = CHARTYPE_FIRST_ESC_2253;
|
||||
else
|
||||
orflags = 0;
|
||||
switch (type & BUF_TYPE_WIDTH_MASK) {
|
||||
case 4:
|
||||
c = ((unsigned long)*p++) << 24;
|
||||
c |= ((unsigned long)*p++) << 16;
|
||||
c |= ((unsigned long)*p++) << 8;
|
||||
c |= *p++;
|
||||
if (c > UNICODE_MAX || UNICODE_IS_SURROGATE(c))
|
||||
return -1;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
c = ((unsigned long)*p++) << 8;
|
||||
c |= *p++;
|
||||
if (UNICODE_IS_SURROGATE(c))
|
||||
return -1;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
c = *p++;
|
||||
break;
|
||||
|
||||
case 0:
|
||||
i = UTF8_getc(p, q - p, &c);
|
||||
if (i < 0)
|
||||
return -1; /* Invalid UTF8String */
|
||||
p += i;
|
||||
break;
|
||||
default:
|
||||
return -1; /* invalid width */
|
||||
}
|
||||
if (p == q && flags & ASN1_STRFLGS_ESC_2253)
|
||||
orflags = CHARTYPE_LAST_ESC_2253;
|
||||
if (type & BUF_TYPE_CONVUTF8) {
|
||||
unsigned char utfbuf[6];
|
||||
int utflen;
|
||||
|
||||
utflen = UTF8_putc(utfbuf, sizeof utfbuf, c);
|
||||
if (utflen < 0)
|
||||
return -1;
|
||||
for (i = 0; i < utflen; i++) {
|
||||
/* We don't need to worry about setting orflags correctly
|
||||
* because if utflen==1 its value will be correct anyway
|
||||
* otherwise each character will be > 0x7f and so the
|
||||
* character will never be escaped on first and last.
|
||||
*/
|
||||
len = do_esc_char(utfbuf[i],
|
||||
(unsigned char)(flags | orflags), quotes,
|
||||
io_ch, arg);
|
||||
if (len < 0)
|
||||
return -1;
|
||||
outlen += len;
|
||||
}
|
||||
} else {
|
||||
len = do_esc_char(c, (unsigned char)(flags | orflags),
|
||||
quotes, io_ch, arg);
|
||||
if (len < 0)
|
||||
return -1;
|
||||
outlen += len;
|
||||
}
|
||||
}
|
||||
return outlen;
|
||||
}
|
||||
|
||||
/* This function hex dumps a buffer of characters */
|
||||
|
||||
static int
|
||||
do_hex_dump(char_io *io_ch, void *arg, unsigned char *buf, int buflen)
|
||||
{
|
||||
static const char hexdig[] = "0123456789ABCDEF";
|
||||
unsigned char *p, *q;
|
||||
char hextmp[2];
|
||||
if (arg) {
|
||||
p = buf;
|
||||
q = buf + buflen;
|
||||
while (p != q) {
|
||||
hextmp[0] = hexdig[*p >> 4];
|
||||
hextmp[1] = hexdig[*p & 0xf];
|
||||
if (!io_ch(arg, hextmp, 2))
|
||||
return -1;
|
||||
p++;
|
||||
}
|
||||
}
|
||||
return buflen << 1;
|
||||
}
|
||||
|
||||
/* "dump" a string. This is done when the type is unknown,
|
||||
* or the flags request it. We can either dump the content
|
||||
* octets or the entire DER encoding. This uses the RFC2253
|
||||
* #01234 format.
|
||||
*/
|
||||
|
||||
static int
|
||||
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
|
||||
*/
|
||||
ASN1_TYPE t;
|
||||
unsigned char *der_buf, *p;
|
||||
int outlen, der_len;
|
||||
|
||||
if (!io_ch(arg, "#", 1))
|
||||
return -1;
|
||||
/* If we don't dump DER encoding just dump content octets */
|
||||
if (!(lflags & ASN1_STRFLGS_DUMP_DER)) {
|
||||
outlen = do_hex_dump(io_ch, arg, str->data, str->length);
|
||||
if (outlen < 0)
|
||||
return -1;
|
||||
return outlen + 1;
|
||||
}
|
||||
t.type = str->type;
|
||||
t.value.ptr = (char *)str;
|
||||
der_len = i2d_ASN1_TYPE(&t, NULL);
|
||||
der_buf = malloc(der_len);
|
||||
if (!der_buf)
|
||||
return -1;
|
||||
p = der_buf;
|
||||
i2d_ASN1_TYPE(&t, &p);
|
||||
outlen = do_hex_dump(io_ch, arg, der_buf, der_len);
|
||||
free(der_buf);
|
||||
if (outlen < 0)
|
||||
return -1;
|
||||
return outlen + 1;
|
||||
}
|
||||
|
||||
/* This is the main function, print out an
|
||||
* ASN1_STRING taking note of various escape
|
||||
* and display options. Returns number of
|
||||
* characters written or -1 if an error
|
||||
* occurred.
|
||||
*/
|
||||
|
||||
static int
|
||||
do_print_ex(char_io *io_ch, void *arg, unsigned long lflags,
|
||||
const ASN1_STRING *str)
|
||||
{
|
||||
int outlen, len;
|
||||
int type;
|
||||
char quotes;
|
||||
unsigned char flags;
|
||||
|
||||
quotes = 0;
|
||||
/* Keep a copy of escape flags */
|
||||
flags = (unsigned char)(lflags & ESC_FLAGS);
|
||||
type = str->type;
|
||||
outlen = 0;
|
||||
|
||||
if (lflags & ASN1_STRFLGS_SHOW_TYPE) {
|
||||
const char *tagname;
|
||||
tagname = ASN1_tag2str(type);
|
||||
outlen += strlen(tagname);
|
||||
if (!io_ch(arg, tagname, outlen) || !io_ch(arg, ":", 1))
|
||||
return -1;
|
||||
outlen++;
|
||||
}
|
||||
|
||||
/* Decide what to do with type, either dump content or display it */
|
||||
|
||||
if (lflags & ASN1_STRFLGS_DUMP_ALL) {
|
||||
/* Dump everything. */
|
||||
type = -1;
|
||||
} else if (lflags & ASN1_STRFLGS_IGNORE_TYPE) {
|
||||
/* Ignore the string type. */
|
||||
type = 1;
|
||||
} else {
|
||||
/* Else determine width based on type. */
|
||||
type = asn1_tag2charwidth(type);
|
||||
if (type == -1 && !(lflags & ASN1_STRFLGS_DUMP_UNKNOWN))
|
||||
type = 1;
|
||||
}
|
||||
|
||||
if (type == -1) {
|
||||
len = do_dump(lflags, io_ch, arg, str);
|
||||
if (len < 0)
|
||||
return -1;
|
||||
outlen += len;
|
||||
return outlen;
|
||||
}
|
||||
|
||||
if (lflags & ASN1_STRFLGS_UTF8_CONVERT) {
|
||||
/* Note: if string is UTF8 and we want
|
||||
* to convert to UTF8 then we just interpret
|
||||
* it as 1 byte per character to avoid converting
|
||||
* twice.
|
||||
*/
|
||||
if (!type)
|
||||
type = 1;
|
||||
else
|
||||
type |= BUF_TYPE_CONVUTF8;
|
||||
}
|
||||
|
||||
len = do_buf(str->data, str->length, type, flags, "es, io_ch, NULL);
|
||||
if (len < 0)
|
||||
return -1;
|
||||
outlen += len;
|
||||
if (quotes)
|
||||
outlen += 2;
|
||||
if (!arg)
|
||||
return outlen;
|
||||
if (quotes && !io_ch(arg, "\"", 1))
|
||||
return -1;
|
||||
if (do_buf(str->data, str->length, type, flags, NULL, io_ch, arg) < 0)
|
||||
return -1;
|
||||
if (quotes && !io_ch(arg, "\"", 1))
|
||||
return -1;
|
||||
return outlen;
|
||||
}
|
||||
|
||||
/* Used for line indenting: print 'indent' spaces */
|
||||
|
||||
static int
|
||||
do_indent(char_io *io_ch, void *arg, int indent)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < indent; i++)
|
||||
if (!io_ch(arg, " ", 1))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define FN_WIDTH_LN 25
|
||||
#define FN_WIDTH_SN 10
|
||||
|
||||
static int
|
||||
do_name_ex(char_io *io_ch, void *arg, const X509_NAME *n, int indent,
|
||||
unsigned long flags)
|
||||
{
|
||||
int i, prev = -1, orflags, cnt;
|
||||
int fn_opt, fn_nid;
|
||||
ASN1_OBJECT *fn;
|
||||
ASN1_STRING *val;
|
||||
X509_NAME_ENTRY *ent;
|
||||
char objtmp[80];
|
||||
const char *objbuf;
|
||||
int outlen, len;
|
||||
char *sep_dn, *sep_mv, *sep_eq;
|
||||
int sep_dn_len, sep_mv_len, sep_eq_len;
|
||||
|
||||
if (indent < 0)
|
||||
indent = 0;
|
||||
outlen = indent;
|
||||
if (!do_indent(io_ch, arg, indent))
|
||||
return -1;
|
||||
|
||||
switch (flags & XN_FLAG_SEP_MASK) {
|
||||
case XN_FLAG_SEP_MULTILINE:
|
||||
sep_dn = "\n";
|
||||
sep_dn_len = 1;
|
||||
sep_mv = " + ";
|
||||
sep_mv_len = 3;
|
||||
break;
|
||||
|
||||
case XN_FLAG_SEP_COMMA_PLUS:
|
||||
sep_dn = ",";
|
||||
sep_dn_len = 1;
|
||||
sep_mv = "+";
|
||||
sep_mv_len = 1;
|
||||
indent = 0;
|
||||
break;
|
||||
|
||||
case XN_FLAG_SEP_CPLUS_SPC:
|
||||
sep_dn = ", ";
|
||||
sep_dn_len = 2;
|
||||
sep_mv = " + ";
|
||||
sep_mv_len = 3;
|
||||
indent = 0;
|
||||
break;
|
||||
|
||||
case XN_FLAG_SEP_SPLUS_SPC:
|
||||
sep_dn = "; ";
|
||||
sep_dn_len = 2;
|
||||
sep_mv = " + ";
|
||||
sep_mv_len = 3;
|
||||
indent = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (flags & XN_FLAG_SPC_EQ) {
|
||||
sep_eq = " = ";
|
||||
sep_eq_len = 3;
|
||||
} else {
|
||||
sep_eq = "=";
|
||||
sep_eq_len = 1;
|
||||
}
|
||||
|
||||
fn_opt = flags & XN_FLAG_FN_MASK;
|
||||
|
||||
cnt = X509_NAME_entry_count(n);
|
||||
for (i = 0; i < cnt; i++) {
|
||||
if (flags & XN_FLAG_DN_REV)
|
||||
ent = X509_NAME_get_entry(n, cnt - i - 1);
|
||||
else
|
||||
ent = X509_NAME_get_entry(n, i);
|
||||
if (prev != -1) {
|
||||
if (prev == X509_NAME_ENTRY_set(ent)) {
|
||||
if (!io_ch(arg, sep_mv, sep_mv_len))
|
||||
return -1;
|
||||
outlen += sep_mv_len;
|
||||
} else {
|
||||
if (!io_ch(arg, sep_dn, sep_dn_len))
|
||||
return -1;
|
||||
outlen += sep_dn_len;
|
||||
if (!do_indent(io_ch, arg, indent))
|
||||
return -1;
|
||||
outlen += indent;
|
||||
}
|
||||
}
|
||||
prev = X509_NAME_ENTRY_set(ent);
|
||||
fn = X509_NAME_ENTRY_get_object(ent);
|
||||
val = X509_NAME_ENTRY_get_data(ent);
|
||||
fn_nid = OBJ_obj2nid(fn);
|
||||
if (fn_opt != XN_FLAG_FN_NONE) {
|
||||
int objlen, fld_len;
|
||||
if ((fn_opt == XN_FLAG_FN_OID) ||
|
||||
(fn_nid == NID_undef)) {
|
||||
OBJ_obj2txt(objtmp, sizeof objtmp, fn, 1);
|
||||
fld_len = 0; /* XXX: what should this be? */
|
||||
objbuf = objtmp;
|
||||
} else {
|
||||
if (fn_opt == XN_FLAG_FN_SN) {
|
||||
fld_len = FN_WIDTH_SN;
|
||||
objbuf = OBJ_nid2sn(fn_nid);
|
||||
} else if (fn_opt == XN_FLAG_FN_LN) {
|
||||
fld_len = FN_WIDTH_LN;
|
||||
objbuf = OBJ_nid2ln(fn_nid);
|
||||
} else {
|
||||
fld_len = 0; /* XXX: what should this be? */
|
||||
objbuf = "";
|
||||
}
|
||||
}
|
||||
objlen = strlen(objbuf);
|
||||
if (!io_ch(arg, objbuf, objlen))
|
||||
return -1;
|
||||
if ((objlen < fld_len) && (flags & XN_FLAG_FN_ALIGN)) {
|
||||
if (!do_indent(io_ch, arg, fld_len - objlen))
|
||||
return -1;
|
||||
outlen += fld_len - objlen;
|
||||
}
|
||||
if (!io_ch(arg, sep_eq, sep_eq_len))
|
||||
return -1;
|
||||
outlen += objlen + sep_eq_len;
|
||||
}
|
||||
/* If the field name is unknown then fix up the DER dump
|
||||
* flag. We might want to limit this further so it will
|
||||
* DER dump on anything other than a few 'standard' fields.
|
||||
*/
|
||||
if ((fn_nid == NID_undef) &&
|
||||
(flags & XN_FLAG_DUMP_UNKNOWN_FIELDS))
|
||||
orflags = ASN1_STRFLGS_DUMP_ALL;
|
||||
else
|
||||
orflags = 0;
|
||||
|
||||
len = do_print_ex(io_ch, arg, flags | orflags, val);
|
||||
if (len < 0)
|
||||
return -1;
|
||||
outlen += len;
|
||||
}
|
||||
return outlen;
|
||||
}
|
||||
|
||||
/* Wrappers round the main functions */
|
||||
|
||||
int
|
||||
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);
|
||||
return do_name_ex(send_bio_chars, out, nm, indent, flags);
|
||||
}
|
||||
|
||||
int
|
||||
X509_NAME_print_ex_fp(FILE *fp, const X509_NAME *nm, int indent,
|
||||
unsigned long flags)
|
||||
{
|
||||
if (flags == XN_FLAG_COMPAT) {
|
||||
BIO *btmp;
|
||||
int ret;
|
||||
btmp = BIO_new_fp(fp, BIO_NOCLOSE);
|
||||
if (!btmp)
|
||||
return -1;
|
||||
ret = X509_NAME_print(btmp, nm, indent);
|
||||
BIO_free(btmp);
|
||||
return ret;
|
||||
}
|
||||
return do_name_ex(send_fp_chars, fp, nm, indent, flags);
|
||||
}
|
||||
|
||||
int
|
||||
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, const ASN1_STRING *str, unsigned long flags)
|
||||
{
|
||||
return do_print_ex(send_fp_chars, fp, flags, str);
|
||||
}
|
||||
423
externals/libressl/crypto/asn1/a_string.c
vendored
423
externals/libressl/crypto/asn1/a_string.c
vendored
@@ -1,423 +0,0 @@
|
||||
/* $OpenBSD: a_string.c,v 1.7 2022/03/17 17:17:58 jsing 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 <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#include "asn1_locl.h"
|
||||
|
||||
ASN1_STRING *
|
||||
ASN1_STRING_new(void)
|
||||
{
|
||||
return ASN1_STRING_type_new(V_ASN1_OCTET_STRING);
|
||||
}
|
||||
|
||||
ASN1_STRING *
|
||||
ASN1_STRING_type_new(int type)
|
||||
{
|
||||
ASN1_STRING *astr;
|
||||
|
||||
if ((astr = calloc(1, sizeof(ASN1_STRING))) == NULL) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
astr->type = type;
|
||||
|
||||
return astr;
|
||||
}
|
||||
|
||||
static void
|
||||
ASN1_STRING_clear(ASN1_STRING *astr)
|
||||
{
|
||||
if (!(astr->flags & ASN1_STRING_FLAG_NDEF))
|
||||
freezero(astr->data, astr->length);
|
||||
|
||||
astr->flags &= ~ASN1_STRING_FLAG_NDEF;
|
||||
astr->data = NULL;
|
||||
astr->length = 0;
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_STRING_free(ASN1_STRING *astr)
|
||||
{
|
||||
if (astr == NULL)
|
||||
return;
|
||||
|
||||
ASN1_STRING_clear(astr);
|
||||
|
||||
free(astr);
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b)
|
||||
{
|
||||
int cmp;
|
||||
|
||||
if (a == NULL || b == NULL)
|
||||
return -1;
|
||||
if ((cmp = (a->length - b->length)) != 0)
|
||||
return cmp;
|
||||
if ((cmp = memcmp(a->data, b->data, a->length)) != 0)
|
||||
return cmp;
|
||||
|
||||
return (a->type - b->type);
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *src)
|
||||
{
|
||||
if (src == NULL)
|
||||
return 0;
|
||||
|
||||
if (!ASN1_STRING_set(dst, src->data, src->length))
|
||||
return 0;
|
||||
|
||||
dst->type = src->type;
|
||||
dst->flags = src->flags & ~ASN1_STRING_FLAG_NDEF;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
ASN1_STRING *
|
||||
ASN1_STRING_dup(const ASN1_STRING *src)
|
||||
{
|
||||
ASN1_STRING *astr;
|
||||
|
||||
if (src == NULL)
|
||||
return NULL;
|
||||
|
||||
if ((astr = ASN1_STRING_new()) == NULL)
|
||||
return NULL;
|
||||
if (!ASN1_STRING_copy(astr, src)) {
|
||||
ASN1_STRING_free(astr);
|
||||
return NULL;
|
||||
}
|
||||
return astr;
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_STRING_set(ASN1_STRING *astr, const void *_data, int len)
|
||||
{
|
||||
const char *data = _data;
|
||||
|
||||
if (len == -1) {
|
||||
size_t slen;
|
||||
|
||||
if (data == NULL)
|
||||
return 0;
|
||||
|
||||
if ((slen = strlen(data)) > INT_MAX)
|
||||
return 0;
|
||||
|
||||
len = (int)slen;
|
||||
}
|
||||
|
||||
ASN1_STRING_clear(astr);
|
||||
|
||||
if (len < 0 || len >= INT_MAX)
|
||||
return 0;
|
||||
|
||||
if ((astr->data = calloc(1, len + 1)) == NULL) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
return (0);
|
||||
}
|
||||
astr->length = len;
|
||||
|
||||
if (data != NULL) {
|
||||
memcpy(astr->data, data, len);
|
||||
astr->data[len] = '\0';
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_STRING_set0(ASN1_STRING *astr, void *data, int len)
|
||||
{
|
||||
ASN1_STRING_clear(astr);
|
||||
|
||||
astr->data = data;
|
||||
astr->length = len;
|
||||
}
|
||||
|
||||
void
|
||||
asn1_add_error(const unsigned char *address, int offset)
|
||||
{
|
||||
ERR_asprintf_error_data("offset=%d", offset);
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_STRING_length(const ASN1_STRING *astr)
|
||||
{
|
||||
return astr->length;
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_STRING_length_set(ASN1_STRING *astr, int len)
|
||||
{
|
||||
/* This is dangerous and unfixable. */
|
||||
astr->length = len;
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_STRING_type(const ASN1_STRING *astr)
|
||||
{
|
||||
return astr->type;
|
||||
}
|
||||
|
||||
unsigned char *
|
||||
ASN1_STRING_data(ASN1_STRING *astr)
|
||||
{
|
||||
return astr->data;
|
||||
}
|
||||
|
||||
const unsigned char *
|
||||
ASN1_STRING_get0_data(const ASN1_STRING *astr)
|
||||
{
|
||||
return astr->data;
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_STRING_print(BIO *bp, const ASN1_STRING *astr)
|
||||
{
|
||||
int i, n;
|
||||
char buf[80];
|
||||
const char *p;
|
||||
|
||||
if (astr == NULL)
|
||||
return 0;
|
||||
|
||||
n = 0;
|
||||
p = (const char *)astr->data;
|
||||
for (i = 0; i < astr->length; i++) {
|
||||
if ((p[i] > '~') || ((p[i] < ' ') &&
|
||||
(p[i] != '\n') && (p[i] != '\r')))
|
||||
buf[n] = '.';
|
||||
else
|
||||
buf[n] = p[i];
|
||||
n++;
|
||||
if (n >= 80) {
|
||||
if (BIO_write(bp, buf, n) <= 0)
|
||||
return 0;
|
||||
n = 0;
|
||||
}
|
||||
}
|
||||
if (n > 0) {
|
||||
if (BIO_write(bp, buf, n) <= 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Utility function: convert any string type to UTF8, returns number of bytes
|
||||
* in output string or a negative error code
|
||||
*/
|
||||
int
|
||||
ASN1_STRING_to_UTF8(unsigned char **out, const ASN1_STRING *in)
|
||||
{
|
||||
ASN1_STRING stmp, *str = &stmp;
|
||||
int mbflag, ret;
|
||||
|
||||
if (in == NULL)
|
||||
return -1;
|
||||
|
||||
if ((mbflag = asn1_tag2charwidth(in->type)) == -1)
|
||||
return -1;
|
||||
|
||||
mbflag |= MBSTRING_FLAG;
|
||||
|
||||
stmp.data = NULL;
|
||||
stmp.length = 0;
|
||||
ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag,
|
||||
B_ASN1_UTF8STRING);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
*out = stmp.data;
|
||||
return stmp.length;
|
||||
}
|
||||
|
||||
int
|
||||
i2a_ASN1_STRING(BIO *bp, const ASN1_STRING *astr, int type)
|
||||
{
|
||||
int i, n = 0;
|
||||
static const char h[] = "0123456789ABCDEF";
|
||||
char buf[2];
|
||||
|
||||
if (astr == NULL)
|
||||
return 0;
|
||||
|
||||
if (astr->length == 0) {
|
||||
if (BIO_write(bp, "0", 1) != 1)
|
||||
goto err;
|
||||
n = 1;
|
||||
} else {
|
||||
for (i = 0; i < astr->length; i++) {
|
||||
if ((i != 0) && (i % 35 == 0)) {
|
||||
if (BIO_write(bp, "\\\n", 2) != 2)
|
||||
goto err;
|
||||
n += 2;
|
||||
}
|
||||
buf[0] = h[((unsigned char)astr->data[i] >> 4) & 0x0f];
|
||||
buf[1] = h[((unsigned char)astr->data[i]) & 0x0f];
|
||||
if (BIO_write(bp, buf, 2) != 2)
|
||||
goto err;
|
||||
n += 2;
|
||||
}
|
||||
}
|
||||
return n;
|
||||
|
||||
err:
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
a2i_ASN1_STRING(BIO *bp, ASN1_STRING *astr, char *buf, int size)
|
||||
{
|
||||
int ret = 0;
|
||||
int i, j, k, m, n, again, bufsize;
|
||||
unsigned char *s = NULL, *sp;
|
||||
unsigned char *bufp;
|
||||
int first = 1;
|
||||
size_t num = 0, slen = 0;
|
||||
|
||||
bufsize = BIO_gets(bp, buf, size);
|
||||
for (;;) {
|
||||
if (bufsize < 1) {
|
||||
if (first)
|
||||
break;
|
||||
else
|
||||
goto err_sl;
|
||||
}
|
||||
first = 0;
|
||||
|
||||
i = bufsize;
|
||||
if (buf[i-1] == '\n')
|
||||
buf[--i] = '\0';
|
||||
if (i == 0)
|
||||
goto err_sl;
|
||||
if (buf[i-1] == '\r')
|
||||
buf[--i] = '\0';
|
||||
if (i == 0)
|
||||
goto err_sl;
|
||||
if (buf[i - 1] == '\\') {
|
||||
i--;
|
||||
again = 1;
|
||||
} else
|
||||
again = 0;
|
||||
buf[i] = '\0';
|
||||
if (i < 2)
|
||||
goto err_sl;
|
||||
|
||||
bufp = (unsigned char *)buf;
|
||||
|
||||
k = 0;
|
||||
if (i % 2 != 0) {
|
||||
ASN1error(ASN1_R_ODD_NUMBER_OF_CHARS);
|
||||
goto err;
|
||||
}
|
||||
i /= 2;
|
||||
if (num + i > slen) {
|
||||
sp = realloc(s, num + i);
|
||||
if (sp == NULL) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
s = sp;
|
||||
slen = num + i;
|
||||
}
|
||||
for (j = 0; j < i; j++, k += 2) {
|
||||
for (n = 0; n < 2; n++) {
|
||||
m = bufp[k + n];
|
||||
if ((m >= '0') && (m <= '9'))
|
||||
m -= '0';
|
||||
else if ((m >= 'a') && (m <= 'f'))
|
||||
m = m - 'a' + 10;
|
||||
else if ((m >= 'A') && (m <= 'F'))
|
||||
m = m - 'A' + 10;
|
||||
else {
|
||||
ASN1error(ASN1_R_NON_HEX_CHARACTERS);
|
||||
goto err;
|
||||
}
|
||||
s[num + j] <<= 4;
|
||||
s[num + j] |= m;
|
||||
}
|
||||
}
|
||||
num += i;
|
||||
if (again)
|
||||
bufsize = BIO_gets(bp, buf, size);
|
||||
else
|
||||
break;
|
||||
}
|
||||
astr->length = num;
|
||||
astr->data = s;
|
||||
|
||||
return 1;
|
||||
|
||||
err_sl:
|
||||
ASN1error(ASN1_R_SHORT_LINE);
|
||||
err:
|
||||
free(s);
|
||||
|
||||
return ret;
|
||||
}
|
||||
342
externals/libressl/crypto/asn1/a_strnid.c
vendored
342
externals/libressl/crypto/asn1/a_strnid.c
vendored
@@ -1,342 +0,0 @@
|
||||
/* $OpenBSD: a_strnid.c,v 1.25 2021/12/13 17:55:53 schwarze Exp $ */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 1999.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/objects.h>
|
||||
|
||||
static STACK_OF(ASN1_STRING_TABLE) *stable = NULL;
|
||||
|
||||
static ASN1_STRING_TABLE *stable_get(int nid);
|
||||
static void st_free(ASN1_STRING_TABLE *tbl);
|
||||
static int sk_table_cmp(const ASN1_STRING_TABLE * const *a,
|
||||
const ASN1_STRING_TABLE * const *b);
|
||||
|
||||
|
||||
/*
|
||||
* This is the global mask for the mbstring functions: this is used to
|
||||
* mask out certain types (such as BMPString and UTF8String) because
|
||||
* certain software (e.g. Netscape) has problems with them.
|
||||
*/
|
||||
|
||||
static unsigned long global_mask = B_ASN1_UTF8STRING;
|
||||
|
||||
void
|
||||
ASN1_STRING_set_default_mask(unsigned long mask)
|
||||
{
|
||||
global_mask = mask;
|
||||
}
|
||||
|
||||
unsigned long
|
||||
ASN1_STRING_get_default_mask(void)
|
||||
{
|
||||
return global_mask;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function sets the default to various "flavours" of configuration
|
||||
* based on an ASCII string. Currently this is:
|
||||
* MASK:XXXX : a numerical mask value.
|
||||
* nobmp : Don't use BMPStrings (just Printable, T61).
|
||||
* pkix : PKIX recommendation in RFC2459.
|
||||
* utf8only : only use UTF8Strings (RFC2459 recommendation for 2004).
|
||||
* default: the default value, Printable, T61, BMP.
|
||||
*/
|
||||
|
||||
int
|
||||
ASN1_STRING_set_default_mask_asc(const char *p)
|
||||
{
|
||||
unsigned long mask;
|
||||
char *end;
|
||||
int save_errno;
|
||||
|
||||
if (strncmp(p, "MASK:", 5) == 0) {
|
||||
if (p[5] == '\0')
|
||||
return 0;
|
||||
save_errno = errno;
|
||||
errno = 0;
|
||||
mask = strtoul(p + 5, &end, 0);
|
||||
if (errno == ERANGE && mask == ULONG_MAX)
|
||||
return 0;
|
||||
errno = save_errno;
|
||||
if (*end != '\0')
|
||||
return 0;
|
||||
} else if (strcmp(p, "nombstr") == 0)
|
||||
mask = ~((unsigned long)(B_ASN1_BMPSTRING|B_ASN1_UTF8STRING));
|
||||
else if (strcmp(p, "pkix") == 0)
|
||||
mask = ~((unsigned long)B_ASN1_T61STRING);
|
||||
else if (strcmp(p, "utf8only") == 0)
|
||||
mask = B_ASN1_UTF8STRING;
|
||||
else if (strcmp(p, "default") == 0)
|
||||
mask = 0xFFFFFFFFL;
|
||||
else
|
||||
return 0;
|
||||
ASN1_STRING_set_default_mask(mask);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* The following function generates an ASN1_STRING based on limits in a table.
|
||||
* Frequently the types and length of an ASN1_STRING are restricted by a
|
||||
* corresponding OID. For example certificates and certificate requests.
|
||||
*/
|
||||
|
||||
ASN1_STRING *
|
||||
ASN1_STRING_set_by_NID(ASN1_STRING **out, const unsigned char *in, int inlen,
|
||||
int inform, int nid)
|
||||
{
|
||||
ASN1_STRING_TABLE *tbl;
|
||||
ASN1_STRING *str = NULL;
|
||||
unsigned long mask;
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
out = &str;
|
||||
tbl = ASN1_STRING_TABLE_get(nid);
|
||||
if (tbl != NULL) {
|
||||
mask = tbl->mask;
|
||||
if ((tbl->flags & STABLE_NO_MASK) == 0)
|
||||
mask &= global_mask;
|
||||
ret = ASN1_mbstring_ncopy(out, in, inlen, inform, mask,
|
||||
tbl->minsize, tbl->maxsize);
|
||||
} else
|
||||
ret = ASN1_mbstring_copy(out, in, inlen, inform,
|
||||
DIRSTRING_TYPE & global_mask);
|
||||
if (ret <= 0)
|
||||
return NULL;
|
||||
return *out;
|
||||
}
|
||||
|
||||
/*
|
||||
* Now the tables and helper functions for the string table:
|
||||
*/
|
||||
|
||||
/* size limits: this stuff is taken straight from RFC3280 */
|
||||
|
||||
#define ub_name 32768
|
||||
#define ub_common_name 64
|
||||
#define ub_locality_name 128
|
||||
#define ub_state_name 128
|
||||
#define ub_organization_name 64
|
||||
#define ub_organization_unit_name 64
|
||||
#define ub_title 64
|
||||
#define ub_email_address 128
|
||||
#define ub_serial_number 64
|
||||
|
||||
|
||||
/* This table must be kept in NID order */
|
||||
|
||||
static const ASN1_STRING_TABLE tbl_standard[] = {
|
||||
{NID_commonName, 1, ub_common_name, DIRSTRING_TYPE, 0},
|
||||
{NID_countryName, 2, 2, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
|
||||
{NID_localityName, 1, ub_locality_name, DIRSTRING_TYPE, 0},
|
||||
{NID_stateOrProvinceName, 1, ub_state_name, DIRSTRING_TYPE, 0},
|
||||
{NID_organizationName, 1, ub_organization_name, DIRSTRING_TYPE, 0},
|
||||
{NID_organizationalUnitName, 1, ub_organization_unit_name, DIRSTRING_TYPE, 0},
|
||||
{NID_pkcs9_emailAddress, 1, ub_email_address, B_ASN1_IA5STRING, STABLE_NO_MASK},
|
||||
{NID_pkcs9_unstructuredName, 1, -1, PKCS9STRING_TYPE, 0},
|
||||
{NID_pkcs9_challengePassword, 1, -1, PKCS9STRING_TYPE, 0},
|
||||
{NID_pkcs9_unstructuredAddress, 1, -1, DIRSTRING_TYPE, 0},
|
||||
{NID_givenName, 1, ub_name, DIRSTRING_TYPE, 0},
|
||||
{NID_surname, 1, ub_name, DIRSTRING_TYPE, 0},
|
||||
{NID_initials, 1, ub_name, DIRSTRING_TYPE, 0},
|
||||
{NID_serialNumber, 1, ub_serial_number, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
|
||||
{NID_friendlyName, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK},
|
||||
{NID_name, 1, ub_name, DIRSTRING_TYPE, 0},
|
||||
{NID_dnQualifier, -1, -1, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
|
||||
{NID_domainComponent, 1, -1, B_ASN1_IA5STRING, STABLE_NO_MASK},
|
||||
{NID_ms_csp_name, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK}
|
||||
};
|
||||
|
||||
static int
|
||||
sk_table_cmp(const ASN1_STRING_TABLE * const *a,
|
||||
const ASN1_STRING_TABLE * const *b)
|
||||
{
|
||||
return (*a)->nid - (*b)->nid;
|
||||
}
|
||||
|
||||
static int table_cmp_BSEARCH_CMP_FN(const void *, const void *);
|
||||
static int table_cmp(ASN1_STRING_TABLE const *, ASN1_STRING_TABLE const *);
|
||||
static ASN1_STRING_TABLE *OBJ_bsearch_table(ASN1_STRING_TABLE *key, ASN1_STRING_TABLE const *base, int num);
|
||||
|
||||
static int
|
||||
table_cmp(const ASN1_STRING_TABLE *a, const ASN1_STRING_TABLE *b)
|
||||
{
|
||||
return a->nid - b->nid;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
table_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_)
|
||||
{
|
||||
ASN1_STRING_TABLE const *a = a_;
|
||||
ASN1_STRING_TABLE const *b = b_;
|
||||
return table_cmp(a, b);
|
||||
}
|
||||
|
||||
static ASN1_STRING_TABLE *
|
||||
OBJ_bsearch_table(ASN1_STRING_TABLE *key, ASN1_STRING_TABLE const *base, int num)
|
||||
{
|
||||
return (ASN1_STRING_TABLE *)OBJ_bsearch_(key, base, num, sizeof(ASN1_STRING_TABLE),
|
||||
table_cmp_BSEARCH_CMP_FN);
|
||||
}
|
||||
|
||||
ASN1_STRING_TABLE *
|
||||
ASN1_STRING_TABLE_get(int nid)
|
||||
{
|
||||
int idx;
|
||||
ASN1_STRING_TABLE fnd;
|
||||
|
||||
fnd.nid = nid;
|
||||
if (stable != NULL) {
|
||||
idx = sk_ASN1_STRING_TABLE_find(stable, &fnd);
|
||||
if (idx >= 0)
|
||||
return sk_ASN1_STRING_TABLE_value(stable, idx);
|
||||
}
|
||||
return OBJ_bsearch_table(&fnd, tbl_standard,
|
||||
sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE));
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a string table pointer which can be modified: either directly
|
||||
* from table or a copy of an internal value added to the table.
|
||||
*/
|
||||
|
||||
static ASN1_STRING_TABLE *
|
||||
stable_get(int nid)
|
||||
{
|
||||
ASN1_STRING_TABLE *tmp, *rv;
|
||||
|
||||
/* Always need a string table so allocate one if NULL */
|
||||
if (stable == NULL) {
|
||||
stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp);
|
||||
if (stable == NULL)
|
||||
return NULL;
|
||||
}
|
||||
tmp = ASN1_STRING_TABLE_get(nid);
|
||||
if (tmp != NULL && (tmp->flags & STABLE_FLAGS_MALLOC) != 0)
|
||||
return tmp;
|
||||
|
||||
if ((rv = calloc(1, sizeof(*rv))) == NULL) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
if (!sk_ASN1_STRING_TABLE_push(stable, rv)) {
|
||||
free(rv);
|
||||
return NULL;
|
||||
}
|
||||
if (tmp != NULL) {
|
||||
rv->nid = tmp->nid;
|
||||
rv->minsize = tmp->minsize;
|
||||
rv->maxsize = tmp->maxsize;
|
||||
rv->mask = tmp->mask;
|
||||
rv->flags = tmp->flags | STABLE_FLAGS_MALLOC;
|
||||
} else {
|
||||
rv->nid = nid;
|
||||
rv->minsize = -1;
|
||||
rv->maxsize = -1;
|
||||
rv->flags = STABLE_FLAGS_MALLOC;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_STRING_TABLE_add(int nid, long minsize, long maxsize, unsigned long mask,
|
||||
unsigned long flags)
|
||||
{
|
||||
ASN1_STRING_TABLE *tmp;
|
||||
|
||||
if ((tmp = stable_get(nid)) == NULL) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
if (minsize >= 0)
|
||||
tmp->minsize = minsize;
|
||||
if (maxsize >= 0)
|
||||
tmp->maxsize = maxsize;
|
||||
if (mask != 0)
|
||||
tmp->mask = mask;
|
||||
if (flags != 0)
|
||||
tmp->flags = flags | STABLE_FLAGS_MALLOC;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_STRING_TABLE_cleanup(void)
|
||||
{
|
||||
STACK_OF(ASN1_STRING_TABLE) *tmp;
|
||||
|
||||
tmp = stable;
|
||||
if (tmp == NULL)
|
||||
return;
|
||||
stable = NULL;
|
||||
sk_ASN1_STRING_TABLE_pop_free(tmp, st_free);
|
||||
}
|
||||
|
||||
static void
|
||||
st_free(ASN1_STRING_TABLE *tbl)
|
||||
{
|
||||
if (tbl->flags & STABLE_FLAGS_MALLOC)
|
||||
free(tbl);
|
||||
}
|
||||
134
externals/libressl/crypto/asn1/a_time.c
vendored
134
externals/libressl/crypto/asn1/a_time.c
vendored
@@ -1,134 +0,0 @@
|
||||
/* $OpenBSD: a_time.c,v 1.33 2021/12/25 07:48:09 jsing Exp $ */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
/* This is an implementation of the ASN1 Time structure which is:
|
||||
* Time ::= CHOICE {
|
||||
* utcTime UTCTime,
|
||||
* generalTime GeneralizedTime }
|
||||
* written by Steve Henson.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#include "o_time.h"
|
||||
#include "asn1_locl.h"
|
||||
|
||||
const ASN1_ITEM ASN1_TIME_it = {
|
||||
.itype = ASN1_ITYPE_MSTRING,
|
||||
.utype = B_ASN1_TIME,
|
||||
.templates = NULL,
|
||||
.tcount = 0,
|
||||
.funcs = NULL,
|
||||
.size = sizeof(ASN1_STRING),
|
||||
.sname = "ASN1_TIME",
|
||||
};
|
||||
|
||||
ASN1_TIME *
|
||||
ASN1_TIME_new(void)
|
||||
{
|
||||
return (ASN1_TIME *)ASN1_item_new(&ASN1_TIME_it);
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_TIME_free(ASN1_TIME *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &ASN1_TIME_it);
|
||||
}
|
||||
|
||||
/* Public API in OpenSSL. Kept internal for now. */
|
||||
static int
|
||||
ASN1_TIME_to_tm(const ASN1_TIME *s, struct tm *tm)
|
||||
{
|
||||
time_t now;
|
||||
|
||||
if (s != NULL)
|
||||
return ASN1_time_parse(s->data, s->length, tm, 0) != -1;
|
||||
|
||||
time(&now);
|
||||
memset(tm, 0, sizeof(*tm));
|
||||
|
||||
return gmtime_r(&now, tm) != NULL;
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_TIME_diff(int *pday, int *psec, const ASN1_TIME *from, const ASN1_TIME *to)
|
||||
{
|
||||
struct tm tm_from, tm_to;
|
||||
|
||||
if (!ASN1_TIME_to_tm(from, &tm_from))
|
||||
return 0;
|
||||
if (!ASN1_TIME_to_tm(to, &tm_to))
|
||||
return 0;
|
||||
|
||||
return OPENSSL_gmtime_diff(pday, psec, &tm_from, &tm_to);
|
||||
}
|
||||
|
||||
ASN1_TIME *
|
||||
d2i_ASN1_TIME(ASN1_TIME **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (ASN1_TIME *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&ASN1_TIME_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_TIME_it);
|
||||
}
|
||||
472
externals/libressl/crypto/asn1/a_time_tm.c
vendored
472
externals/libressl/crypto/asn1/a_time_tm.c
vendored
@@ -1,472 +0,0 @@
|
||||
/* $OpenBSD: a_time_tm.c,v 1.19 2022/03/31 13:04:47 tb Exp $ */
|
||||
/*
|
||||
* Copyright (c) 2015 Bob Beck <beck@openbsd.org>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#include "o_time.h"
|
||||
|
||||
#define RFC5280 0
|
||||
#define GENTIME_LENGTH 15
|
||||
#define UTCTIME_LENGTH 13
|
||||
|
||||
int
|
||||
ASN1_time_tm_cmp(struct tm *tm1, struct tm *tm2)
|
||||
{
|
||||
if (tm1->tm_year < tm2->tm_year)
|
||||
return (-1);
|
||||
if (tm1->tm_year > tm2->tm_year)
|
||||
return (1);
|
||||
if (tm1->tm_mon < tm2->tm_mon)
|
||||
return (-1);
|
||||
if (tm1->tm_mon > tm2->tm_mon)
|
||||
return (1);
|
||||
if (tm1->tm_mday < tm2->tm_mday)
|
||||
return (-1);
|
||||
if (tm1->tm_mday > tm2->tm_mday)
|
||||
return (1);
|
||||
if (tm1->tm_hour < tm2->tm_hour)
|
||||
return (-1);
|
||||
if (tm1->tm_hour > tm2->tm_hour)
|
||||
return (1);
|
||||
if (tm1->tm_min < tm2->tm_min)
|
||||
return (-1);
|
||||
if (tm1->tm_min > tm2->tm_min)
|
||||
return (1);
|
||||
if (tm1->tm_sec < tm2->tm_sec)
|
||||
return (-1);
|
||||
if (tm1->tm_sec > tm2->tm_sec)
|
||||
return (1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_time_tm_clamp_notafter(struct tm *tm)
|
||||
{
|
||||
#ifdef SMALL_TIME_T
|
||||
struct tm broken_os_epoch_tm;
|
||||
time_t broken_os_epoch_time = INT_MAX;
|
||||
|
||||
if (gmtime_r(&broken_os_epoch_time, &broken_os_epoch_tm) == NULL)
|
||||
return 0;
|
||||
|
||||
if (ASN1_time_tm_cmp(tm, &broken_os_epoch_tm) == 1)
|
||||
memcpy(tm, &broken_os_epoch_tm, sizeof(*tm));
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Format a time as an RFC 5280 format Generalized time */
|
||||
char *
|
||||
gentime_string_from_tm(struct tm *tm)
|
||||
{
|
||||
char *ret = NULL;
|
||||
int year;
|
||||
|
||||
year = tm->tm_year + 1900;
|
||||
if (year < 0 || year > 9999)
|
||||
return (NULL);
|
||||
|
||||
if (asprintf(&ret, "%04u%02u%02u%02u%02u%02uZ", year,
|
||||
tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min,
|
||||
tm->tm_sec) == -1)
|
||||
ret = NULL;
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/* Format a time as an RFC 5280 format UTC time */
|
||||
char *
|
||||
utctime_string_from_tm(struct tm *tm)
|
||||
{
|
||||
char *ret = NULL;
|
||||
|
||||
if (tm->tm_year >= 150 || tm->tm_year < 50)
|
||||
return (NULL);
|
||||
|
||||
if (asprintf(&ret, "%02u%02u%02u%02u%02u%02uZ",
|
||||
tm->tm_year % 100, tm->tm_mon + 1, tm->tm_mday,
|
||||
tm->tm_hour, tm->tm_min, tm->tm_sec) == -1)
|
||||
ret = NULL;
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/* Format a time correctly for an X509 object as per RFC 5280 */
|
||||
char *
|
||||
rfc5280_string_from_tm(struct tm *tm)
|
||||
{
|
||||
char *ret = NULL;
|
||||
int year;
|
||||
|
||||
year = tm->tm_year + 1900;
|
||||
if (year < 1950 || year > 9999)
|
||||
return (NULL);
|
||||
|
||||
if (year < 2050)
|
||||
ret = utctime_string_from_tm(tm);
|
||||
else
|
||||
ret = gentime_string_from_tm(tm);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse an RFC 5280 format ASN.1 time string.
|
||||
*
|
||||
* mode must be:
|
||||
* 0 if we expect to parse a time as specified in RFC 5280 for an X509 object.
|
||||
* V_ASN1_UTCTIME if we wish to parse an RFC5280 format UTC time.
|
||||
* V_ASN1_GENERALIZEDTIME if we wish to parse an RFC5280 format Generalized time.
|
||||
*
|
||||
* Returns:
|
||||
* -1 if the string was invalid.
|
||||
* V_ASN1_UTCTIME if the string validated as a UTC time string.
|
||||
* V_ASN1_GENERALIZEDTIME if the string validated as a Generalized time string.
|
||||
*
|
||||
* Fills in *tm with the corresponding time if tm is non NULL.
|
||||
*/
|
||||
#define ATOI2(ar) ((ar) += 2, ((ar)[-2] - '0') * 10 + ((ar)[-1] - '0'))
|
||||
int
|
||||
ASN1_time_parse(const char *bytes, size_t len, struct tm *tm, int mode)
|
||||
{
|
||||
size_t i;
|
||||
int type = 0;
|
||||
struct tm ltm;
|
||||
struct tm *lt;
|
||||
const char *p;
|
||||
|
||||
if (bytes == NULL)
|
||||
return (-1);
|
||||
|
||||
/* Constrain to valid lengths. */
|
||||
if (len != UTCTIME_LENGTH && len != GENTIME_LENGTH)
|
||||
return (-1);
|
||||
|
||||
lt = tm;
|
||||
if (lt == NULL)
|
||||
lt = <m;
|
||||
memset(lt, 0, sizeof(*lt));
|
||||
|
||||
/* Timezone is required and must be GMT (Zulu). */
|
||||
if (bytes[len - 1] != 'Z')
|
||||
return (-1);
|
||||
|
||||
/* Make sure everything else is digits. */
|
||||
for (i = 0; i < len - 1; i++) {
|
||||
if (isdigit((unsigned char)bytes[i]))
|
||||
continue;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate and convert the time
|
||||
*/
|
||||
p = bytes;
|
||||
switch (len) {
|
||||
case GENTIME_LENGTH:
|
||||
if (mode == V_ASN1_UTCTIME)
|
||||
return (-1);
|
||||
lt->tm_year = (ATOI2(p) * 100) - 1900; /* cc */
|
||||
type = V_ASN1_GENERALIZEDTIME;
|
||||
/* FALLTHROUGH */
|
||||
case UTCTIME_LENGTH:
|
||||
if (type == 0) {
|
||||
if (mode == V_ASN1_GENERALIZEDTIME)
|
||||
return (-1);
|
||||
type = V_ASN1_UTCTIME;
|
||||
}
|
||||
lt->tm_year += ATOI2(p); /* yy */
|
||||
if (type == V_ASN1_UTCTIME) {
|
||||
if (lt->tm_year < 50)
|
||||
lt->tm_year += 100;
|
||||
}
|
||||
lt->tm_mon = ATOI2(p) - 1; /* mm */
|
||||
if (lt->tm_mon < 0 || lt->tm_mon > 11)
|
||||
return (-1);
|
||||
lt->tm_mday = ATOI2(p); /* dd */
|
||||
if (lt->tm_mday < 1 || lt->tm_mday > 31)
|
||||
return (-1);
|
||||
lt->tm_hour = ATOI2(p); /* HH */
|
||||
if (lt->tm_hour < 0 || lt->tm_hour > 23)
|
||||
return (-1);
|
||||
lt->tm_min = ATOI2(p); /* MM */
|
||||
if (lt->tm_min < 0 || lt->tm_min > 59)
|
||||
return (-1);
|
||||
lt->tm_sec = ATOI2(p); /* SS */
|
||||
/* Leap second 60 is not accepted. Reconsider later? */
|
||||
if (lt->tm_sec < 0 || lt->tm_sec > 59)
|
||||
return (-1);
|
||||
break;
|
||||
default:
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return (type);
|
||||
}
|
||||
|
||||
/*
|
||||
* ASN1_TIME generic functions.
|
||||
*/
|
||||
|
||||
static int
|
||||
ASN1_TIME_set_string_internal(ASN1_TIME *s, const char *str, int mode)
|
||||
{
|
||||
int type;
|
||||
char *tmp;
|
||||
|
||||
if ((type = ASN1_time_parse(str, strlen(str), NULL, mode)) == -1)
|
||||
return (0);
|
||||
if (mode != 0 && mode != type)
|
||||
return (0);
|
||||
|
||||
if (s == NULL)
|
||||
return (1);
|
||||
|
||||
if ((tmp = strdup(str)) == NULL)
|
||||
return (0);
|
||||
free(s->data);
|
||||
s->data = tmp;
|
||||
s->length = strlen(tmp);
|
||||
s->type = type;
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
static ASN1_TIME *
|
||||
ASN1_TIME_adj_internal(ASN1_TIME *s, time_t t, int offset_day, long offset_sec,
|
||||
int mode)
|
||||
{
|
||||
int allocated = 0;
|
||||
struct tm tm;
|
||||
size_t len;
|
||||
char *p;
|
||||
|
||||
if (gmtime_r(&t, &tm) == NULL)
|
||||
return (NULL);
|
||||
|
||||
if (offset_day || offset_sec) {
|
||||
if (!OPENSSL_gmtime_adj(&tm, offset_day, offset_sec))
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
switch (mode) {
|
||||
case V_ASN1_UTCTIME:
|
||||
p = utctime_string_from_tm(&tm);
|
||||
break;
|
||||
case V_ASN1_GENERALIZEDTIME:
|
||||
p = gentime_string_from_tm(&tm);
|
||||
break;
|
||||
case RFC5280:
|
||||
p = rfc5280_string_from_tm(&tm);
|
||||
break;
|
||||
default:
|
||||
return (NULL);
|
||||
}
|
||||
if (p == NULL) {
|
||||
ASN1error(ASN1_R_ILLEGAL_TIME_VALUE);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if (s == NULL) {
|
||||
if ((s = ASN1_TIME_new()) == NULL) {
|
||||
free(p);
|
||||
return (NULL);
|
||||
}
|
||||
allocated = 1;
|
||||
}
|
||||
|
||||
len = strlen(p);
|
||||
switch (len) {
|
||||
case GENTIME_LENGTH:
|
||||
s->type = V_ASN1_GENERALIZEDTIME;
|
||||
break;
|
||||
case UTCTIME_LENGTH:
|
||||
s->type = V_ASN1_UTCTIME;
|
||||
break;
|
||||
default:
|
||||
if (allocated)
|
||||
ASN1_TIME_free(s);
|
||||
free(p);
|
||||
return (NULL);
|
||||
}
|
||||
free(s->data);
|
||||
s->data = p;
|
||||
s->length = len;
|
||||
return (s);
|
||||
}
|
||||
|
||||
ASN1_TIME *
|
||||
ASN1_TIME_set(ASN1_TIME *s, time_t t)
|
||||
{
|
||||
return (ASN1_TIME_adj(s, t, 0, 0));
|
||||
}
|
||||
|
||||
ASN1_TIME *
|
||||
ASN1_TIME_set_tm(ASN1_TIME *s, struct tm *tm)
|
||||
{
|
||||
time_t t;
|
||||
|
||||
if ((t = timegm(tm)) == -1)
|
||||
return NULL;
|
||||
return (ASN1_TIME_adj(s, t, 0, 0));
|
||||
}
|
||||
|
||||
ASN1_TIME *
|
||||
ASN1_TIME_adj(ASN1_TIME *s, time_t t, int offset_day, long offset_sec)
|
||||
{
|
||||
return (ASN1_TIME_adj_internal(s, t, offset_day, offset_sec, RFC5280));
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_TIME_check(const ASN1_TIME *t)
|
||||
{
|
||||
if (t->type != V_ASN1_GENERALIZEDTIME && t->type != V_ASN1_UTCTIME)
|
||||
return (0);
|
||||
return (t->type == ASN1_time_parse(t->data, t->length, NULL, t->type));
|
||||
}
|
||||
|
||||
ASN1_GENERALIZEDTIME *
|
||||
ASN1_TIME_to_generalizedtime(const ASN1_TIME *t, ASN1_GENERALIZEDTIME **out)
|
||||
{
|
||||
ASN1_GENERALIZEDTIME *tmp = NULL;
|
||||
struct tm tm;
|
||||
char *str;
|
||||
|
||||
if (t->type != V_ASN1_GENERALIZEDTIME && t->type != V_ASN1_UTCTIME)
|
||||
return (NULL);
|
||||
|
||||
if (t->type != ASN1_time_parse(t->data, t->length, &tm, t->type))
|
||||
return (NULL);
|
||||
if ((str = gentime_string_from_tm(&tm)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
if (out != NULL)
|
||||
tmp = *out;
|
||||
if (tmp == NULL && (tmp = ASN1_GENERALIZEDTIME_new()) == NULL) {
|
||||
free(str);
|
||||
return (NULL);
|
||||
}
|
||||
if (out != NULL)
|
||||
*out = tmp;
|
||||
|
||||
free(tmp->data);
|
||||
tmp->data = str;
|
||||
tmp->length = strlen(str);
|
||||
return (tmp);
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_TIME_set_string(ASN1_TIME *s, const char *str)
|
||||
{
|
||||
return (ASN1_TIME_set_string_internal(s, str, 0));
|
||||
}
|
||||
|
||||
/*
|
||||
* ASN1_UTCTIME wrappers
|
||||
*/
|
||||
|
||||
int
|
||||
ASN1_UTCTIME_check(const ASN1_UTCTIME *d)
|
||||
{
|
||||
if (d->type != V_ASN1_UTCTIME)
|
||||
return (0);
|
||||
return (d->type == ASN1_time_parse(d->data, d->length, NULL, d->type));
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str)
|
||||
{
|
||||
if (s != NULL && s->type != V_ASN1_UTCTIME)
|
||||
return (0);
|
||||
return (ASN1_TIME_set_string_internal(s, str, V_ASN1_UTCTIME));
|
||||
}
|
||||
|
||||
ASN1_UTCTIME *
|
||||
ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t)
|
||||
{
|
||||
return (ASN1_UTCTIME_adj(s, t, 0, 0));
|
||||
}
|
||||
|
||||
ASN1_UTCTIME *
|
||||
ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t, int offset_day, long offset_sec)
|
||||
{
|
||||
return (ASN1_TIME_adj_internal(s, t, offset_day, offset_sec,
|
||||
V_ASN1_UTCTIME));
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t2)
|
||||
{
|
||||
struct tm tm1, tm2;
|
||||
|
||||
/*
|
||||
* This function has never handled failure conditions properly
|
||||
* and should be deprecated. The OpenSSL version used to
|
||||
* simply follow NULL pointers on failure. BoringSSL and
|
||||
* OpenSSL now make it return -2 on failure.
|
||||
*
|
||||
* The danger is that users of this function will not
|
||||
* differentiate the -2 failure case from t1 < t2.
|
||||
*/
|
||||
if (ASN1_time_parse(s->data, s->length, &tm1, V_ASN1_UTCTIME) == -1)
|
||||
return (-2); /* XXX */
|
||||
|
||||
if (gmtime_r(&t2, &tm2) == NULL)
|
||||
return (-2); /* XXX */
|
||||
|
||||
return ASN1_time_tm_cmp(&tm1, &tm2);
|
||||
}
|
||||
|
||||
/*
|
||||
* ASN1_GENERALIZEDTIME wrappers
|
||||
*/
|
||||
|
||||
int
|
||||
ASN1_GENERALIZEDTIME_check(const ASN1_GENERALIZEDTIME *d)
|
||||
{
|
||||
if (d->type != V_ASN1_GENERALIZEDTIME)
|
||||
return (0);
|
||||
return (d->type == ASN1_time_parse(d->data, d->length, NULL, d->type));
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str)
|
||||
{
|
||||
if (s != NULL && s->type != V_ASN1_GENERALIZEDTIME)
|
||||
return (0);
|
||||
return (ASN1_TIME_set_string_internal(s, str, V_ASN1_GENERALIZEDTIME));
|
||||
}
|
||||
|
||||
ASN1_GENERALIZEDTIME *
|
||||
ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s, time_t t)
|
||||
{
|
||||
return (ASN1_GENERALIZEDTIME_adj(s, t, 0, 0));
|
||||
}
|
||||
|
||||
ASN1_GENERALIZEDTIME *
|
||||
ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s, time_t t, int offset_day,
|
||||
long offset_sec)
|
||||
{
|
||||
return (ASN1_TIME_adj_internal(s, t, offset_day, offset_sec,
|
||||
V_ASN1_GENERALIZEDTIME));
|
||||
}
|
||||
342
externals/libressl/crypto/asn1/a_type.c
vendored
342
externals/libressl/crypto/asn1/a_type.c
vendored
@@ -1,342 +0,0 @@
|
||||
/* $OpenBSD: a_type.c,v 1.23 2021/12/25 12:19:16 jsing 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 <string.h>
|
||||
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/objects.h>
|
||||
|
||||
typedef struct {
|
||||
ASN1_INTEGER *num;
|
||||
ASN1_OCTET_STRING *value;
|
||||
} ASN1_int_octetstring;
|
||||
|
||||
static const ASN1_TEMPLATE ASN1_INT_OCTETSTRING_seq_tt[] = {
|
||||
{
|
||||
.offset = offsetof(ASN1_int_octetstring, num),
|
||||
.field_name = "num",
|
||||
.item = &ASN1_INTEGER_it,
|
||||
},
|
||||
{
|
||||
.offset = offsetof(ASN1_int_octetstring, value),
|
||||
.field_name = "value",
|
||||
.item = &ASN1_OCTET_STRING_it,
|
||||
},
|
||||
};
|
||||
|
||||
const ASN1_ITEM ASN1_INT_OCTETSTRING_it = {
|
||||
.itype = ASN1_ITYPE_SEQUENCE,
|
||||
.utype = V_ASN1_SEQUENCE,
|
||||
.templates = ASN1_INT_OCTETSTRING_seq_tt,
|
||||
.tcount = sizeof(ASN1_INT_OCTETSTRING_seq_tt) / sizeof(ASN1_TEMPLATE),
|
||||
.size = sizeof(ASN1_int_octetstring),
|
||||
.sname = "ASN1_INT_OCTETSTRING",
|
||||
};
|
||||
|
||||
ASN1_TYPE *
|
||||
ASN1_TYPE_new(void)
|
||||
{
|
||||
return (ASN1_TYPE *)ASN1_item_new(&ASN1_ANY_it);
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_TYPE_free(ASN1_TYPE *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &ASN1_ANY_it);
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_TYPE_get(const ASN1_TYPE *a)
|
||||
{
|
||||
if ((a->value.ptr != NULL) || (a->type == V_ASN1_NULL))
|
||||
return (a->type);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value)
|
||||
{
|
||||
if (a->value.ptr != NULL) {
|
||||
ASN1_TYPE **tmp_a = &a;
|
||||
ASN1_primitive_free((ASN1_VALUE **)tmp_a, NULL);
|
||||
}
|
||||
a->type = type;
|
||||
if (type == V_ASN1_BOOLEAN)
|
||||
a->value.boolean = value ? 0xff : 0;
|
||||
else
|
||||
a->value.ptr = value;
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value)
|
||||
{
|
||||
if (!value || (type == V_ASN1_BOOLEAN)) {
|
||||
void *p = (void *)value;
|
||||
ASN1_TYPE_set(a, type, p);
|
||||
} else if (type == V_ASN1_OBJECT) {
|
||||
ASN1_OBJECT *odup;
|
||||
odup = OBJ_dup(value);
|
||||
if (!odup)
|
||||
return 0;
|
||||
ASN1_TYPE_set(a, type, odup);
|
||||
} else {
|
||||
ASN1_STRING *sdup;
|
||||
sdup = ASN1_STRING_dup(value);
|
||||
if (!sdup)
|
||||
return 0;
|
||||
ASN1_TYPE_set(a, type, sdup);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Returns 0 if they are equal, != 0 otherwise. */
|
||||
int
|
||||
ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b)
|
||||
{
|
||||
int result = -1;
|
||||
|
||||
if (!a || !b || a->type != b->type)
|
||||
return -1;
|
||||
|
||||
switch (a->type) {
|
||||
case V_ASN1_OBJECT:
|
||||
result = OBJ_cmp(a->value.object, b->value.object);
|
||||
break;
|
||||
case V_ASN1_BOOLEAN:
|
||||
result = a->value.boolean - b->value.boolean;
|
||||
break;
|
||||
case V_ASN1_NULL:
|
||||
result = 0; /* They do not have content. */
|
||||
break;
|
||||
|
||||
case V_ASN1_INTEGER:
|
||||
case V_ASN1_ENUMERATED:
|
||||
case V_ASN1_BIT_STRING:
|
||||
case V_ASN1_OCTET_STRING:
|
||||
case V_ASN1_SEQUENCE:
|
||||
case V_ASN1_SET:
|
||||
case V_ASN1_NUMERICSTRING:
|
||||
case V_ASN1_PRINTABLESTRING:
|
||||
case V_ASN1_T61STRING:
|
||||
case V_ASN1_VIDEOTEXSTRING:
|
||||
case V_ASN1_IA5STRING:
|
||||
case V_ASN1_UTCTIME:
|
||||
case V_ASN1_GENERALIZEDTIME:
|
||||
case V_ASN1_GRAPHICSTRING:
|
||||
case V_ASN1_VISIBLESTRING:
|
||||
case V_ASN1_GENERALSTRING:
|
||||
case V_ASN1_UNIVERSALSTRING:
|
||||
case V_ASN1_BMPSTRING:
|
||||
case V_ASN1_UTF8STRING:
|
||||
case V_ASN1_OTHER:
|
||||
default:
|
||||
result = ASN1_STRING_cmp((ASN1_STRING *)a->value.ptr,
|
||||
(ASN1_STRING *)b->value.ptr);
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_TYPE_set_octetstring(ASN1_TYPE *a, const unsigned char *data, int len)
|
||||
{
|
||||
ASN1_STRING *os;
|
||||
|
||||
if ((os = ASN1_OCTET_STRING_new()) == NULL)
|
||||
return (0);
|
||||
if (!ASN1_STRING_set(os, data, len)) {
|
||||
ASN1_OCTET_STRING_free(os);
|
||||
return (0);
|
||||
}
|
||||
ASN1_TYPE_set(a, V_ASN1_OCTET_STRING, os);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_TYPE_get_octetstring(const ASN1_TYPE *a, unsigned char *data, int max_len)
|
||||
{
|
||||
int ret, num;
|
||||
unsigned char *p;
|
||||
|
||||
if ((a->type != V_ASN1_OCTET_STRING) ||
|
||||
(a->value.octet_string == NULL)) {
|
||||
ASN1error(ASN1_R_DATA_IS_WRONG);
|
||||
return (-1);
|
||||
}
|
||||
p = ASN1_STRING_data(a->value.octet_string);
|
||||
ret = ASN1_STRING_length(a->value.octet_string);
|
||||
if (ret < max_len)
|
||||
num = ret;
|
||||
else
|
||||
num = max_len;
|
||||
memcpy(data, p, num);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_TYPE_set_int_octetstring(ASN1_TYPE *at, long num, const unsigned char *data,
|
||||
int len)
|
||||
{
|
||||
ASN1_int_octetstring *ios;
|
||||
ASN1_STRING *sp = NULL;
|
||||
int ret = 0;
|
||||
|
||||
if ((ios = (ASN1_int_octetstring *)ASN1_item_new(
|
||||
&ASN1_INT_OCTETSTRING_it)) == NULL)
|
||||
goto err;
|
||||
if (!ASN1_INTEGER_set(ios->num, num))
|
||||
goto err;
|
||||
if (!ASN1_OCTET_STRING_set(ios->value, data, len))
|
||||
goto err;
|
||||
|
||||
if ((sp = ASN1_item_pack(ios, &ASN1_INT_OCTETSTRING_it, NULL)) == NULL)
|
||||
goto err;
|
||||
|
||||
ASN1_TYPE_set(at, V_ASN1_SEQUENCE, sp);
|
||||
sp = NULL;
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
ASN1_item_free((ASN1_VALUE *)ios, &ASN1_INT_OCTETSTRING_it);
|
||||
ASN1_STRING_free(sp);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_TYPE_get_int_octetstring(const ASN1_TYPE *at, long *num, unsigned char *data,
|
||||
int max_len)
|
||||
{
|
||||
ASN1_STRING *sp = at->value.sequence;
|
||||
ASN1_int_octetstring *ios = NULL;
|
||||
int ret = -1;
|
||||
int len;
|
||||
|
||||
if (at->type != V_ASN1_SEQUENCE || sp == NULL)
|
||||
goto err;
|
||||
|
||||
if ((ios = ASN1_item_unpack(sp, &ASN1_INT_OCTETSTRING_it)) == NULL)
|
||||
goto err;
|
||||
|
||||
if (num != NULL)
|
||||
*num = ASN1_INTEGER_get(ios->num);
|
||||
if (data != NULL) {
|
||||
len = ASN1_STRING_length(ios->value);
|
||||
if (len > max_len)
|
||||
len = max_len;
|
||||
memcpy(data, ASN1_STRING_data(ios->value), len);
|
||||
}
|
||||
|
||||
ret = ASN1_STRING_length(ios->value);
|
||||
|
||||
err:
|
||||
ASN1_item_free((ASN1_VALUE *)ios, &ASN1_INT_OCTETSTRING_it);
|
||||
|
||||
if (ret == -1)
|
||||
ASN1error(ASN1_R_DATA_IS_WRONG);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_ASN1_TYPE(ASN1_TYPE *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_ANY_it);
|
||||
}
|
||||
|
||||
ASN1_TYPE *
|
||||
d2i_ASN1_TYPE(ASN1_TYPE **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (ASN1_TYPE *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&ASN1_ANY_it);
|
||||
}
|
||||
199
externals/libressl/crypto/asn1/a_utf8.c
vendored
199
externals/libressl/crypto/asn1/a_utf8.c
vendored
@@ -1,199 +0,0 @@
|
||||
/* $OpenBSD: a_utf8.c,v 1.8 2014/07/11 08:44:47 jsing 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 <openssl/asn1.h>
|
||||
|
||||
#include "asn1_locl.h"
|
||||
|
||||
/* UTF8 utilities */
|
||||
|
||||
/*
|
||||
* This parses a UTF8 string one character at a time. It is passed a pointer
|
||||
* to the string and the length of the string. It sets 'value' to the value of
|
||||
* the current character. It returns the number of characters read or a
|
||||
* negative error code:
|
||||
* -1 = string too short
|
||||
* -2 = illegal character
|
||||
* -3 = subsequent characters not of the form 10xxxxxx
|
||||
* -4 = character encoded incorrectly (not minimal length).
|
||||
*/
|
||||
|
||||
int
|
||||
UTF8_getc(const unsigned char *str, int len, unsigned long *val)
|
||||
{
|
||||
const unsigned char *p;
|
||||
unsigned long value;
|
||||
int ret;
|
||||
if (len <= 0)
|
||||
return 0;
|
||||
p = str;
|
||||
|
||||
/* Check syntax and work out the encoded value (if correct) */
|
||||
if ((*p & 0x80) == 0) {
|
||||
value = *p++ & 0x7f;
|
||||
ret = 1;
|
||||
} else if ((*p & 0xe0) == 0xc0) {
|
||||
if (*p < 0xc2)
|
||||
return -2;
|
||||
if (len < 2)
|
||||
return -1;
|
||||
if ((p[1] & 0xc0) != 0x80)
|
||||
return -3;
|
||||
value = (*p++ & 0x1f) << 6;
|
||||
value |= *p++ & 0x3f;
|
||||
if (value < 0x80)
|
||||
return -4;
|
||||
ret = 2;
|
||||
} else if ((*p & 0xf0) == 0xe0) {
|
||||
if (len < 3)
|
||||
return -1;
|
||||
if (((p[1] & 0xc0) != 0x80) ||
|
||||
((p[2] & 0xc0) != 0x80))
|
||||
return -3;
|
||||
value = (*p++ & 0xf) << 12;
|
||||
value |= (*p++ & 0x3f) << 6;
|
||||
value |= *p++ & 0x3f;
|
||||
if (value < 0x800)
|
||||
return -4;
|
||||
/* surrogate pair code points are not valid */
|
||||
if (value >= 0xd800 && value < 0xe000)
|
||||
return -2;
|
||||
ret = 3;
|
||||
} else if ((*p & 0xf8) == 0xf0 && (*p < 0xf5)) {
|
||||
if (len < 4)
|
||||
return -1;
|
||||
if (((p[1] & 0xc0) != 0x80) ||
|
||||
((p[2] & 0xc0) != 0x80) ||
|
||||
((p[3] & 0xc0) != 0x80))
|
||||
return -3;
|
||||
value = ((unsigned long)(*p++ & 0x7)) << 18;
|
||||
value |= (*p++ & 0x3f) << 12;
|
||||
value |= (*p++ & 0x3f) << 6;
|
||||
value |= *p++ & 0x3f;
|
||||
if (value < 0x10000)
|
||||
return -4;
|
||||
if (value > UNICODE_MAX)
|
||||
return -2;
|
||||
ret = 4;
|
||||
} else
|
||||
return -2;
|
||||
*val = value;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* This takes a Unicode code point 'value' and writes its UTF-8 encoded form
|
||||
* in 'str' where 'str' is a buffer of at least length 'len'. If 'str'
|
||||
* is NULL, then nothing is written and just the return code is determined.
|
||||
|
||||
* Returns less than zero on error:
|
||||
* -1 if 'str' is not NULL and 'len' is too small
|
||||
* -2 if 'value' is an invalid character (surrogate or out-of-range)
|
||||
*
|
||||
* Otherwise, returns the number of bytes in 'value's encoded form
|
||||
* (i.e., the number of bytes written to 'str' when it's not NULL).
|
||||
*
|
||||
* It will need at most 4 characters.
|
||||
*/
|
||||
|
||||
int
|
||||
UTF8_putc(unsigned char *str, int len, unsigned long value)
|
||||
{
|
||||
if (value < 0x80) {
|
||||
if (str != NULL) {
|
||||
if (len < 1)
|
||||
return -1;
|
||||
str[0] = (unsigned char)value;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
if (value < 0x800) {
|
||||
if (str != NULL) {
|
||||
if (len < 2)
|
||||
return -1;
|
||||
str[0] = (unsigned char)(((value >> 6) & 0x1f) | 0xc0);
|
||||
str[1] = (unsigned char)((value & 0x3f) | 0x80);
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
if (value < 0x10000) {
|
||||
if (UNICODE_IS_SURROGATE(value))
|
||||
return -2;
|
||||
if (str != NULL) {
|
||||
if (len < 3)
|
||||
return -1;
|
||||
str[0] = (unsigned char)(((value >> 12) & 0xf) | 0xe0);
|
||||
str[1] = (unsigned char)(((value >> 6) & 0x3f) | 0x80);
|
||||
str[2] = (unsigned char)((value & 0x3f) | 0x80);
|
||||
}
|
||||
return 3;
|
||||
}
|
||||
if (value <= UNICODE_MAX) {
|
||||
if (str != NULL) {
|
||||
if (len < 4)
|
||||
return -1;
|
||||
str[0] = (unsigned char)(((value >> 18) & 0x7) | 0xf0);
|
||||
str[1] = (unsigned char)(((value >> 12) & 0x3f) | 0x80);
|
||||
str[2] = (unsigned char)(((value >> 6) & 0x3f) | 0x80);
|
||||
str[3] = (unsigned char)((value & 0x3f) | 0x80);
|
||||
}
|
||||
return 4;
|
||||
}
|
||||
return -2;
|
||||
}
|
||||
452
externals/libressl/crypto/asn1/ameth_lib.c
vendored
452
externals/libressl/crypto/asn1/ameth_lib.c
vendored
@@ -1,452 +0,0 @@
|
||||
/* $OpenBSD: ameth_lib.c,v 1.25 2022/01/10 12:10:26 tb Exp $ */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 2006.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2006 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/opensslconf.h>
|
||||
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
#include <openssl/engine.h>
|
||||
#endif
|
||||
|
||||
#include "asn1_locl.h"
|
||||
#include "evp_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;
|
||||
extern const EVP_PKEY_ASN1_METHOD gostr01_asn1_meths[];
|
||||
extern const EVP_PKEY_ASN1_METHOD gostimit_asn1_meth;
|
||||
extern const EVP_PKEY_ASN1_METHOD hmac_asn1_meth;
|
||||
extern const EVP_PKEY_ASN1_METHOD cmac_asn1_meth;
|
||||
|
||||
/* Keep this sorted in type order !! */
|
||||
static const EVP_PKEY_ASN1_METHOD *standard_methods[] = {
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
&rsa_asn1_meths[0],
|
||||
&rsa_asn1_meths[1],
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DH
|
||||
&dh_asn1_meth,
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
&dsa_asn1_meths[0],
|
||||
&dsa_asn1_meths[1],
|
||||
&dsa_asn1_meths[2],
|
||||
&dsa_asn1_meths[3],
|
||||
&dsa_asn1_meths[4],
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_EC
|
||||
&eckey_asn1_meth,
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_GOST
|
||||
&gostr01_asn1_meths[0],
|
||||
&gostimit_asn1_meth,
|
||||
#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],
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef int sk_cmp_fn_type(const char * const *a, const char * const *b);
|
||||
DECLARE_STACK_OF(EVP_PKEY_ASN1_METHOD)
|
||||
static STACK_OF(EVP_PKEY_ASN1_METHOD) *app_methods = NULL;
|
||||
|
||||
static int ameth_cmp_BSEARCH_CMP_FN(const void *, const void *);
|
||||
static int ameth_cmp(const EVP_PKEY_ASN1_METHOD * const *, const EVP_PKEY_ASN1_METHOD * const *);
|
||||
static const EVP_PKEY_ASN1_METHOD * *OBJ_bsearch_ameth(const EVP_PKEY_ASN1_METHOD * *key, const EVP_PKEY_ASN1_METHOD * const *base, int num);
|
||||
|
||||
static int
|
||||
ameth_cmp(const EVP_PKEY_ASN1_METHOD * const *a,
|
||||
const EVP_PKEY_ASN1_METHOD * const *b)
|
||||
{
|
||||
return ((*a)->pkey_id - (*b)->pkey_id);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
ameth_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_)
|
||||
{
|
||||
const EVP_PKEY_ASN1_METHOD * const *a = a_;
|
||||
const EVP_PKEY_ASN1_METHOD * const *b = b_;
|
||||
return ameth_cmp(a, b);
|
||||
}
|
||||
|
||||
static const EVP_PKEY_ASN1_METHOD * *
|
||||
OBJ_bsearch_ameth(const EVP_PKEY_ASN1_METHOD * *key, const EVP_PKEY_ASN1_METHOD * const *base, int num)
|
||||
{
|
||||
return (const EVP_PKEY_ASN1_METHOD * *)OBJ_bsearch_(key, base, num, sizeof(const EVP_PKEY_ASN1_METHOD *),
|
||||
ameth_cmp_BSEARCH_CMP_FN);
|
||||
}
|
||||
|
||||
int
|
||||
EVP_PKEY_asn1_get_count(void)
|
||||
{
|
||||
int num = sizeof(standard_methods) / sizeof(EVP_PKEY_ASN1_METHOD *);
|
||||
if (app_methods)
|
||||
num += sk_EVP_PKEY_ASN1_METHOD_num(app_methods);
|
||||
return num;
|
||||
}
|
||||
|
||||
const EVP_PKEY_ASN1_METHOD *
|
||||
EVP_PKEY_asn1_get0(int idx)
|
||||
{
|
||||
int num = sizeof(standard_methods) / sizeof(EVP_PKEY_ASN1_METHOD *);
|
||||
if (idx < 0)
|
||||
return NULL;
|
||||
if (idx < num)
|
||||
return standard_methods[idx];
|
||||
idx -= num;
|
||||
return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx);
|
||||
}
|
||||
|
||||
static const EVP_PKEY_ASN1_METHOD *
|
||||
pkey_asn1_find(int type)
|
||||
{
|
||||
EVP_PKEY_ASN1_METHOD tmp;
|
||||
const EVP_PKEY_ASN1_METHOD *t = &tmp, **ret;
|
||||
tmp.pkey_id = type;
|
||||
if (app_methods) {
|
||||
int idx;
|
||||
idx = sk_EVP_PKEY_ASN1_METHOD_find(app_methods, &tmp);
|
||||
if (idx >= 0)
|
||||
return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx);
|
||||
}
|
||||
ret = OBJ_bsearch_ameth(&t, standard_methods,
|
||||
sizeof(standard_methods) / sizeof(EVP_PKEY_ASN1_METHOD *));
|
||||
if (!ret || !*ret)
|
||||
return NULL;
|
||||
return *ret;
|
||||
}
|
||||
|
||||
/* Find an implementation of an ASN1 algorithm. If 'pe' is not NULL
|
||||
* also search through engines and set *pe to a functional reference
|
||||
* to the engine implementing 'type' or NULL if no engine implements
|
||||
* it.
|
||||
*/
|
||||
|
||||
const EVP_PKEY_ASN1_METHOD *
|
||||
EVP_PKEY_asn1_find(ENGINE **pe, int type)
|
||||
{
|
||||
const EVP_PKEY_ASN1_METHOD *t;
|
||||
|
||||
for (;;) {
|
||||
t = pkey_asn1_find(type);
|
||||
if (!t || !(t->pkey_flags & ASN1_PKEY_ALIAS))
|
||||
break;
|
||||
type = t->pkey_base_id;
|
||||
}
|
||||
if (pe) {
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
ENGINE *e;
|
||||
/* type will contain the final unaliased type */
|
||||
e = ENGINE_get_pkey_asn1_meth_engine(type);
|
||||
if (e) {
|
||||
*pe = e;
|
||||
return ENGINE_get_pkey_asn1_meth(e, type);
|
||||
}
|
||||
#endif
|
||||
*pe = NULL;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
const EVP_PKEY_ASN1_METHOD *
|
||||
EVP_PKEY_asn1_find_str(ENGINE **pe, const char *str, int len)
|
||||
{
|
||||
int i;
|
||||
const EVP_PKEY_ASN1_METHOD *ameth;
|
||||
if (len == -1)
|
||||
len = strlen(str);
|
||||
if (pe) {
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
ENGINE *e;
|
||||
ameth = ENGINE_pkey_asn1_find_str(&e, str, len);
|
||||
if (ameth) {
|
||||
/* Convert structural into
|
||||
* functional reference
|
||||
*/
|
||||
if (!ENGINE_init(e))
|
||||
ameth = NULL;
|
||||
ENGINE_free(e);
|
||||
*pe = e;
|
||||
return ameth;
|
||||
}
|
||||
#endif
|
||||
*pe = NULL;
|
||||
}
|
||||
for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
|
||||
ameth = EVP_PKEY_asn1_get0(i);
|
||||
if (ameth->pkey_flags & ASN1_PKEY_ALIAS)
|
||||
continue;
|
||||
if (((int)strlen(ameth->pem_str) == len) &&
|
||||
!strncasecmp(ameth->pem_str, str, len))
|
||||
return ameth;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth)
|
||||
{
|
||||
if (app_methods == NULL) {
|
||||
app_methods = sk_EVP_PKEY_ASN1_METHOD_new(ameth_cmp);
|
||||
if (!app_methods)
|
||||
return 0;
|
||||
}
|
||||
if (!sk_EVP_PKEY_ASN1_METHOD_push(app_methods, ameth))
|
||||
return 0;
|
||||
sk_EVP_PKEY_ASN1_METHOD_sort(app_methods);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
EVP_PKEY_asn1_add_alias(int to, int from)
|
||||
{
|
||||
EVP_PKEY_ASN1_METHOD *ameth;
|
||||
|
||||
ameth = EVP_PKEY_asn1_new(from, ASN1_PKEY_ALIAS, NULL, NULL);
|
||||
if (!ameth)
|
||||
return 0;
|
||||
ameth->pkey_base_id = to;
|
||||
if (!EVP_PKEY_asn1_add0(ameth)) {
|
||||
EVP_PKEY_asn1_free(ameth);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
EVP_PKEY_asn1_get0_info(int *ppkey_id, int *ppkey_base_id, int *ppkey_flags,
|
||||
const char **pinfo, const char **ppem_str,
|
||||
const EVP_PKEY_ASN1_METHOD *ameth)
|
||||
{
|
||||
if (!ameth)
|
||||
return 0;
|
||||
if (ppkey_id)
|
||||
*ppkey_id = ameth->pkey_id;
|
||||
if (ppkey_base_id)
|
||||
*ppkey_base_id = ameth->pkey_base_id;
|
||||
if (ppkey_flags)
|
||||
*ppkey_flags = ameth->pkey_flags;
|
||||
if (pinfo)
|
||||
*pinfo = ameth->info;
|
||||
if (ppem_str)
|
||||
*ppem_str = ameth->pem_str;
|
||||
return 1;
|
||||
}
|
||||
|
||||
const EVP_PKEY_ASN1_METHOD*
|
||||
EVP_PKEY_get0_asn1(const EVP_PKEY *pkey)
|
||||
{
|
||||
return pkey->ameth;
|
||||
}
|
||||
|
||||
EVP_PKEY_ASN1_METHOD*
|
||||
EVP_PKEY_asn1_new(int id, int flags, const char *pem_str, const char *info)
|
||||
{
|
||||
EVP_PKEY_ASN1_METHOD *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 != NULL) {
|
||||
if ((ameth->info = strdup(info)) == NULL)
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (pem_str != NULL) {
|
||||
if ((ameth->pem_str = strdup(pem_str)) == NULL)
|
||||
goto err;
|
||||
}
|
||||
|
||||
return ameth;
|
||||
|
||||
err:
|
||||
EVP_PKEY_asn1_free(ameth);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst, const EVP_PKEY_ASN1_METHOD *src)
|
||||
{
|
||||
EVP_PKEY_ASN1_METHOD preserve;
|
||||
|
||||
preserve.pkey_id = dst->pkey_id;
|
||||
preserve.pkey_base_id = dst->pkey_base_id;
|
||||
preserve.pkey_flags = dst->pkey_flags;
|
||||
preserve.pem_str = dst->pem_str;
|
||||
preserve.info = dst->info;
|
||||
|
||||
*dst = *src;
|
||||
|
||||
dst->pkey_id = preserve.pkey_id;
|
||||
dst->pkey_base_id = preserve.pkey_base_id;
|
||||
dst->pkey_flags = preserve.pkey_flags;
|
||||
dst->pem_str = preserve.pem_str;
|
||||
dst->info = preserve.info;
|
||||
}
|
||||
|
||||
void
|
||||
EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth)
|
||||
{
|
||||
if (ameth && (ameth->pkey_flags & ASN1_PKEY_DYNAMIC)) {
|
||||
free(ameth->pem_str);
|
||||
free(ameth->info);
|
||||
free(ameth);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth,
|
||||
int (*pub_decode)(EVP_PKEY *pk, X509_PUBKEY *pub),
|
||||
int (*pub_encode)(X509_PUBKEY *pub, const EVP_PKEY *pk),
|
||||
int (*pub_cmp)(const EVP_PKEY *a, const EVP_PKEY *b),
|
||||
int (*pub_print)(BIO *out, const EVP_PKEY *pkey, int indent,
|
||||
ASN1_PCTX *pctx),
|
||||
int (*pkey_size)(const EVP_PKEY *pk),
|
||||
int (*pkey_bits)(const EVP_PKEY *pk))
|
||||
{
|
||||
ameth->pub_decode = pub_decode;
|
||||
ameth->pub_encode = pub_encode;
|
||||
ameth->pub_cmp = pub_cmp;
|
||||
ameth->pub_print = pub_print;
|
||||
ameth->pkey_size = pkey_size;
|
||||
ameth->pkey_bits = pkey_bits;
|
||||
}
|
||||
|
||||
void
|
||||
EVP_PKEY_asn1_set_private(EVP_PKEY_ASN1_METHOD *ameth,
|
||||
int (*priv_decode)(EVP_PKEY *pk, const PKCS8_PRIV_KEY_INFO *p8inf),
|
||||
int (*priv_encode)(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk),
|
||||
int (*priv_print)(BIO *out, const EVP_PKEY *pkey, int indent,
|
||||
ASN1_PCTX *pctx))
|
||||
{
|
||||
ameth->priv_decode = priv_decode;
|
||||
ameth->priv_encode = priv_encode;
|
||||
ameth->priv_print = priv_print;
|
||||
}
|
||||
|
||||
void
|
||||
EVP_PKEY_asn1_set_param(EVP_PKEY_ASN1_METHOD *ameth,
|
||||
int (*param_decode)(EVP_PKEY *pkey, const unsigned char **pder, int derlen),
|
||||
int (*param_encode)(const EVP_PKEY *pkey, unsigned char **pder),
|
||||
int (*param_missing)(const EVP_PKEY *pk),
|
||||
int (*param_copy)(EVP_PKEY *to, const EVP_PKEY *from),
|
||||
int (*param_cmp)(const EVP_PKEY *a, const EVP_PKEY *b),
|
||||
int (*param_print)(BIO *out, const EVP_PKEY *pkey, int indent,
|
||||
ASN1_PCTX *pctx))
|
||||
{
|
||||
ameth->param_decode = param_decode;
|
||||
ameth->param_encode = param_encode;
|
||||
ameth->param_missing = param_missing;
|
||||
ameth->param_copy = param_copy;
|
||||
ameth->param_cmp = param_cmp;
|
||||
ameth->param_print = param_print;
|
||||
}
|
||||
|
||||
void
|
||||
EVP_PKEY_asn1_set_free(EVP_PKEY_ASN1_METHOD *ameth,
|
||||
void (*pkey_free)(EVP_PKEY *pkey))
|
||||
{
|
||||
ameth->pkey_free = pkey_free;
|
||||
}
|
||||
|
||||
void
|
||||
EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD *ameth,
|
||||
int (*pkey_ctrl)(EVP_PKEY *pkey, int op, long arg1, void *arg2))
|
||||
{
|
||||
ameth->pkey_ctrl = pkey_ctrl;
|
||||
}
|
||||
|
||||
void
|
||||
EVP_PKEY_asn1_set_check(EVP_PKEY_ASN1_METHOD *ameth,
|
||||
int (*pkey_check)(const EVP_PKEY *pk))
|
||||
{
|
||||
ameth->pkey_check = pkey_check;
|
||||
}
|
||||
|
||||
void
|
||||
EVP_PKEY_asn1_set_public_check(EVP_PKEY_ASN1_METHOD *ameth,
|
||||
int (*pkey_public_check)(const EVP_PKEY *pk))
|
||||
{
|
||||
ameth->pkey_public_check = pkey_public_check;
|
||||
}
|
||||
|
||||
void
|
||||
EVP_PKEY_asn1_set_param_check(EVP_PKEY_ASN1_METHOD *ameth,
|
||||
int (*pkey_param_check)(const EVP_PKEY *pk))
|
||||
{
|
||||
ameth->pkey_param_check = pkey_param_check;
|
||||
}
|
||||
215
externals/libressl/crypto/asn1/asn1_err.c
vendored
215
externals/libressl/crypto/asn1/asn1_err.c
vendored
@@ -1,215 +0,0 @@
|
||||
/* $OpenBSD: asn1_err.c,v 1.22 2020/12/08 15:06:42 tb Exp $ */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999-2011 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
|
||||
* openssl-core@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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
/* NOTE: this file was auto generated by the mkerr.pl script: any changes
|
||||
* made to it will be overwritten when the script next updates this file,
|
||||
* only reason strings will be preserved.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <openssl/opensslconf.h>
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
|
||||
#define ERR_FUNC(func) ERR_PACK(ERR_LIB_ASN1,func,0)
|
||||
#define ERR_REASON(reason) ERR_PACK(ERR_LIB_ASN1,0,reason)
|
||||
|
||||
static ERR_STRING_DATA ASN1_str_functs[] = {
|
||||
{ERR_FUNC(0xfff), "CRYPTO_internal"},
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
static ERR_STRING_DATA ASN1_str_reasons[] = {
|
||||
{ERR_REASON(ASN1_R_ADDING_OBJECT) , "adding object"},
|
||||
{ERR_REASON(ASN1_R_ASN1_PARSE_ERROR) , "asn1 parse error"},
|
||||
{ERR_REASON(ASN1_R_ASN1_SIG_PARSE_ERROR) , "asn1 sig parse error"},
|
||||
{ERR_REASON(ASN1_R_AUX_ERROR) , "aux error"},
|
||||
{ERR_REASON(ASN1_R_BAD_CLASS) , "bad class"},
|
||||
{ERR_REASON(ASN1_R_BAD_OBJECT_HEADER) , "bad object header"},
|
||||
{ERR_REASON(ASN1_R_BAD_PASSWORD_READ) , "bad password read"},
|
||||
{ERR_REASON(ASN1_R_BAD_TAG) , "bad tag"},
|
||||
{ERR_REASON(ASN1_R_BAD_TEMPLATE) , "bad template"},
|
||||
{ERR_REASON(ASN1_R_BMPSTRING_IS_WRONG_LENGTH), "bmpstring is wrong length"},
|
||||
{ERR_REASON(ASN1_R_BN_LIB) , "bn lib"},
|
||||
{ERR_REASON(ASN1_R_BOOLEAN_IS_WRONG_LENGTH), "boolean is wrong length"},
|
||||
{ERR_REASON(ASN1_R_BUFFER_TOO_SMALL) , "buffer too small"},
|
||||
{ERR_REASON(ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER), "cipher has no object identifier"},
|
||||
{ERR_REASON(ASN1_R_CONTEXT_NOT_INITIALISED), "context not initialised"},
|
||||
{ERR_REASON(ASN1_R_DATA_IS_WRONG) , "data is wrong"},
|
||||
{ERR_REASON(ASN1_R_DECODE_ERROR) , "decode error"},
|
||||
{ERR_REASON(ASN1_R_DECODING_ERROR) , "decoding error"},
|
||||
{ERR_REASON(ASN1_R_DEPTH_EXCEEDED) , "depth exceeded"},
|
||||
{ERR_REASON(ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED), "digest and key type not supported"},
|
||||
{ERR_REASON(ASN1_R_ENCODE_ERROR) , "encode error"},
|
||||
{ERR_REASON(ASN1_R_ERROR_GETTING_TIME) , "error getting time"},
|
||||
{ERR_REASON(ASN1_R_ERROR_LOADING_SECTION), "error loading section"},
|
||||
{ERR_REASON(ASN1_R_ERROR_PARSING_SET_ELEMENT), "error parsing set element"},
|
||||
{ERR_REASON(ASN1_R_ERROR_SETTING_CIPHER_PARAMS), "error setting cipher params"},
|
||||
{ERR_REASON(ASN1_R_EXPECTING_AN_INTEGER) , "expecting an integer"},
|
||||
{ERR_REASON(ASN1_R_EXPECTING_AN_OBJECT) , "expecting an object"},
|
||||
{ERR_REASON(ASN1_R_EXPECTING_A_BOOLEAN) , "expecting a boolean"},
|
||||
{ERR_REASON(ASN1_R_EXPECTING_A_TIME) , "expecting a time"},
|
||||
{ERR_REASON(ASN1_R_EXPLICIT_LENGTH_MISMATCH), "explicit length mismatch"},
|
||||
{ERR_REASON(ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED), "explicit tag not constructed"},
|
||||
{ERR_REASON(ASN1_R_FIELD_MISSING) , "field missing"},
|
||||
{ERR_REASON(ASN1_R_FIRST_NUM_TOO_LARGE) , "first num too large"},
|
||||
{ERR_REASON(ASN1_R_HEADER_TOO_LONG) , "header too long"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_BITSTRING_FORMAT), "illegal bitstring format"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_BOOLEAN) , "illegal boolean"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_CHARACTERS) , "illegal characters"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_FORMAT) , "illegal format"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_HEX) , "illegal hex"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_IMPLICIT_TAG) , "illegal implicit tag"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_INTEGER) , "illegal integer"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_NESTED_TAGGING), "illegal nested tagging"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_NULL) , "illegal null"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_NULL_VALUE) , "illegal null value"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_OBJECT) , "illegal object"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_OPTIONAL_ANY) , "illegal optional any"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE), "illegal options on item template"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_TAGGED_ANY) , "illegal tagged any"},
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_TIME_VALUE) , "illegal time value"},
|
||||
{ERR_REASON(ASN1_R_INTEGER_NOT_ASCII_FORMAT), "integer not ascii format"},
|
||||
{ERR_REASON(ASN1_R_INTEGER_TOO_LARGE_FOR_LONG), "integer too large for long"},
|
||||
{ERR_REASON(ASN1_R_INVALID_BIT_STRING_BITS_LEFT), "invalid bit string bits left"},
|
||||
{ERR_REASON(ASN1_R_INVALID_BMPSTRING_LENGTH), "invalid bmpstring length"},
|
||||
{ERR_REASON(ASN1_R_INVALID_DIGIT) , "invalid digit"},
|
||||
{ERR_REASON(ASN1_R_INVALID_MIME_TYPE) , "invalid mime type"},
|
||||
{ERR_REASON(ASN1_R_INVALID_MODIFIER) , "invalid modifier"},
|
||||
{ERR_REASON(ASN1_R_INVALID_NUMBER) , "invalid number"},
|
||||
{ERR_REASON(ASN1_R_INVALID_OBJECT_ENCODING), "invalid object encoding"},
|
||||
{ERR_REASON(ASN1_R_INVALID_SEPARATOR) , "invalid separator"},
|
||||
{ERR_REASON(ASN1_R_INVALID_TIME_FORMAT) , "invalid time format"},
|
||||
{ERR_REASON(ASN1_R_INVALID_UNIVERSALSTRING_LENGTH), "invalid universalstring length"},
|
||||
{ERR_REASON(ASN1_R_INVALID_UTF8STRING) , "invalid utf8string"},
|
||||
{ERR_REASON(ASN1_R_IV_TOO_LARGE) , "iv too large"},
|
||||
{ERR_REASON(ASN1_R_LENGTH_ERROR) , "length error"},
|
||||
{ERR_REASON(ASN1_R_LIST_ERROR) , "list error"},
|
||||
{ERR_REASON(ASN1_R_MIME_NO_CONTENT_TYPE) , "mime no content type"},
|
||||
{ERR_REASON(ASN1_R_MIME_PARSE_ERROR) , "mime parse error"},
|
||||
{ERR_REASON(ASN1_R_MIME_SIG_PARSE_ERROR) , "mime sig parse error"},
|
||||
{ERR_REASON(ASN1_R_MISSING_EOC) , "missing eoc"},
|
||||
{ERR_REASON(ASN1_R_MISSING_SECOND_NUMBER), "missing second number"},
|
||||
{ERR_REASON(ASN1_R_MISSING_VALUE) , "missing value"},
|
||||
{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"},
|
||||
{ERR_REASON(ASN1_R_NO_CONTENT_TYPE) , "no content type"},
|
||||
{ERR_REASON(ASN1_R_NO_DEFAULT_DIGEST) , "no default digest"},
|
||||
{ERR_REASON(ASN1_R_NO_MATCHING_CHOICE_TYPE), "no matching choice type"},
|
||||
{ERR_REASON(ASN1_R_NO_MULTIPART_BODY_FAILURE), "no multipart body failure"},
|
||||
{ERR_REASON(ASN1_R_NO_MULTIPART_BOUNDARY), "no multipart boundary"},
|
||||
{ERR_REASON(ASN1_R_NO_SIG_CONTENT_TYPE) , "no sig content type"},
|
||||
{ERR_REASON(ASN1_R_NULL_IS_WRONG_LENGTH) , "null is wrong length"},
|
||||
{ERR_REASON(ASN1_R_OBJECT_NOT_ASCII_FORMAT), "object not ascii format"},
|
||||
{ERR_REASON(ASN1_R_ODD_NUMBER_OF_CHARS) , "odd number of chars"},
|
||||
{ERR_REASON(ASN1_R_PRIVATE_KEY_HEADER_MISSING), "private key header missing"},
|
||||
{ERR_REASON(ASN1_R_SECOND_NUMBER_TOO_LARGE), "second number too large"},
|
||||
{ERR_REASON(ASN1_R_SEQUENCE_LENGTH_MISMATCH), "sequence length mismatch"},
|
||||
{ERR_REASON(ASN1_R_SEQUENCE_NOT_CONSTRUCTED), "sequence not constructed"},
|
||||
{ERR_REASON(ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG), "sequence or set needs config"},
|
||||
{ERR_REASON(ASN1_R_SHORT_LINE) , "short line"},
|
||||
{ERR_REASON(ASN1_R_SIG_INVALID_MIME_TYPE), "sig invalid mime type"},
|
||||
{ERR_REASON(ASN1_R_STREAMING_NOT_SUPPORTED), "streaming not supported"},
|
||||
{ERR_REASON(ASN1_R_STRING_TOO_LONG) , "string too long"},
|
||||
{ERR_REASON(ASN1_R_STRING_TOO_SHORT) , "string too short"},
|
||||
{ERR_REASON(ASN1_R_TAG_VALUE_TOO_HIGH) , "tag value too high"},
|
||||
{ERR_REASON(ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD), "the asn1 object identifier is not known for this md"},
|
||||
{ERR_REASON(ASN1_R_TIME_NOT_ASCII_FORMAT), "time not ascii format"},
|
||||
{ERR_REASON(ASN1_R_TOO_LONG) , "too long"},
|
||||
{ERR_REASON(ASN1_R_TYPE_NOT_CONSTRUCTED) , "type not constructed"},
|
||||
{ERR_REASON(ASN1_R_UNABLE_TO_DECODE_RSA_KEY), "unable to decode rsa key"},
|
||||
{ERR_REASON(ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY), "unable to decode rsa private key"},
|
||||
{ERR_REASON(ASN1_R_UNEXPECTED_EOC) , "unexpected eoc"},
|
||||
{ERR_REASON(ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH), "universalstring is wrong length"},
|
||||
{ERR_REASON(ASN1_R_UNKNOWN_FORMAT) , "unknown format"},
|
||||
{ERR_REASON(ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM), "unknown message digest algorithm"},
|
||||
{ERR_REASON(ASN1_R_UNKNOWN_OBJECT_TYPE) , "unknown object type"},
|
||||
{ERR_REASON(ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE), "unknown public key type"},
|
||||
{ERR_REASON(ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM), "unknown signature algorithm"},
|
||||
{ERR_REASON(ASN1_R_UNKNOWN_TAG) , "unknown tag"},
|
||||
{ERR_REASON(ASN1_R_UNKOWN_FORMAT) , "unknown format"},
|
||||
{ERR_REASON(ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE), "unsupported any defined by type"},
|
||||
{ERR_REASON(ASN1_R_UNSUPPORTED_CIPHER) , "unsupported cipher"},
|
||||
{ERR_REASON(ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM), "unsupported encryption algorithm"},
|
||||
{ERR_REASON(ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE), "unsupported public key type"},
|
||||
{ERR_REASON(ASN1_R_UNSUPPORTED_TYPE) , "unsupported type"},
|
||||
{ERR_REASON(ASN1_R_WRONG_PUBLIC_KEY_TYPE), "wrong public key type"},
|
||||
{ERR_REASON(ASN1_R_WRONG_TAG) , "wrong tag"},
|
||||
{ERR_REASON(ASN1_R_WRONG_TYPE) , "wrong type"},
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
void
|
||||
ERR_load_ASN1_strings(void)
|
||||
{
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
if (ERR_func_error_string(ASN1_str_functs[0].error) == NULL) {
|
||||
ERR_load_strings(0, ASN1_str_functs);
|
||||
ERR_load_strings(0, ASN1_str_reasons);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
801
externals/libressl/crypto/asn1/asn1_gen.c
vendored
801
externals/libressl/crypto/asn1/asn1_gen.c
vendored
@@ -1,801 +0,0 @@
|
||||
/* $OpenBSD: asn1_gen.c,v 1.18 2021/12/25 13:17:48 jsing Exp $ */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 2002.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2002 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
#define ASN1_GEN_FLAG 0x10000
|
||||
#define ASN1_GEN_FLAG_IMP (ASN1_GEN_FLAG|1)
|
||||
#define ASN1_GEN_FLAG_EXP (ASN1_GEN_FLAG|2)
|
||||
#define ASN1_GEN_FLAG_TAG (ASN1_GEN_FLAG|3)
|
||||
#define ASN1_GEN_FLAG_BITWRAP (ASN1_GEN_FLAG|4)
|
||||
#define ASN1_GEN_FLAG_OCTWRAP (ASN1_GEN_FLAG|5)
|
||||
#define ASN1_GEN_FLAG_SEQWRAP (ASN1_GEN_FLAG|6)
|
||||
#define ASN1_GEN_FLAG_SETWRAP (ASN1_GEN_FLAG|7)
|
||||
#define ASN1_GEN_FLAG_FORMAT (ASN1_GEN_FLAG|8)
|
||||
|
||||
#define ASN1_GEN_STR(str,val){str, sizeof(str) - 1, val}
|
||||
|
||||
#define ASN1_FLAG_EXP_MAX 20
|
||||
|
||||
/* Input formats */
|
||||
|
||||
/* ASCII: default */
|
||||
#define ASN1_GEN_FORMAT_ASCII 1
|
||||
/* UTF8 */
|
||||
#define ASN1_GEN_FORMAT_UTF8 2
|
||||
/* Hex */
|
||||
#define ASN1_GEN_FORMAT_HEX 3
|
||||
/* List of bits */
|
||||
#define ASN1_GEN_FORMAT_BITLIST 4
|
||||
|
||||
struct tag_name_st {
|
||||
const char *strnam;
|
||||
int len;
|
||||
int tag;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int exp_tag;
|
||||
int exp_class;
|
||||
int exp_constructed;
|
||||
int exp_pad;
|
||||
long exp_len;
|
||||
} tag_exp_type;
|
||||
|
||||
typedef struct {
|
||||
int imp_tag;
|
||||
int imp_class;
|
||||
int utype;
|
||||
int format;
|
||||
const char *str;
|
||||
tag_exp_type exp_list[ASN1_FLAG_EXP_MAX];
|
||||
int exp_count;
|
||||
} tag_exp_arg;
|
||||
|
||||
static int bitstr_cb(const char *elem, int len, void *bitstr);
|
||||
static int asn1_cb(const char *elem, int len, void *bitstr);
|
||||
static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class,
|
||||
int exp_constructed, int exp_pad, int imp_ok);
|
||||
static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass);
|
||||
static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf);
|
||||
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(const char *str, CONF *nconf)
|
||||
{
|
||||
X509V3_CTX cnf;
|
||||
|
||||
if (!nconf)
|
||||
return ASN1_generate_v3(str, NULL);
|
||||
|
||||
X509V3_set_nconf(&cnf, nconf);
|
||||
return ASN1_generate_v3(str, &cnf);
|
||||
}
|
||||
|
||||
ASN1_TYPE *
|
||||
ASN1_generate_v3(const char *str, X509V3_CTX *cnf)
|
||||
{
|
||||
ASN1_TYPE *ret;
|
||||
tag_exp_arg asn1_tags;
|
||||
tag_exp_type *etmp;
|
||||
|
||||
int i, len;
|
||||
|
||||
unsigned char *orig_der = NULL, *new_der = NULL;
|
||||
const unsigned char *cpy_start;
|
||||
unsigned char *p;
|
||||
const unsigned char *cp;
|
||||
int cpy_len;
|
||||
long hdr_len = 0;
|
||||
int hdr_constructed = 0, hdr_tag, hdr_class;
|
||||
int r;
|
||||
|
||||
asn1_tags.imp_tag = -1;
|
||||
asn1_tags.imp_class = -1;
|
||||
asn1_tags.format = ASN1_GEN_FORMAT_ASCII;
|
||||
asn1_tags.exp_count = 0;
|
||||
if (CONF_parse_list(str, ',', 1, asn1_cb, &asn1_tags) != 0)
|
||||
return NULL;
|
||||
|
||||
if ((asn1_tags.utype == V_ASN1_SEQUENCE) ||
|
||||
(asn1_tags.utype == V_ASN1_SET)) {
|
||||
if (!cnf) {
|
||||
ASN1error(ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG);
|
||||
return NULL;
|
||||
}
|
||||
ret = asn1_multi(asn1_tags.utype, asn1_tags.str, cnf);
|
||||
} else
|
||||
ret = asn1_str2type(asn1_tags.str, asn1_tags.format,
|
||||
asn1_tags.utype);
|
||||
|
||||
if (!ret)
|
||||
return NULL;
|
||||
|
||||
/* If no tagging return base type */
|
||||
if ((asn1_tags.imp_tag == -1) && (asn1_tags.exp_count == 0))
|
||||
return ret;
|
||||
|
||||
/* Generate the encoding */
|
||||
cpy_len = i2d_ASN1_TYPE(ret, &orig_der);
|
||||
ASN1_TYPE_free(ret);
|
||||
ret = NULL;
|
||||
/* Set point to start copying for modified encoding */
|
||||
cpy_start = orig_der;
|
||||
|
||||
/* Do we need IMPLICIT tagging? */
|
||||
if (asn1_tags.imp_tag != -1) {
|
||||
/* If IMPLICIT we will replace the underlying tag */
|
||||
/* Skip existing tag+len */
|
||||
r = ASN1_get_object(&cpy_start, &hdr_len, &hdr_tag,
|
||||
&hdr_class, cpy_len);
|
||||
if (r & 0x80)
|
||||
goto err;
|
||||
/* Update copy length */
|
||||
cpy_len -= cpy_start - orig_der;
|
||||
/* For IMPLICIT tagging the length should match the
|
||||
* original length and constructed flag should be
|
||||
* consistent.
|
||||
*/
|
||||
if (r & 0x1) {
|
||||
/* Indefinite length constructed */
|
||||
hdr_constructed = 2;
|
||||
hdr_len = 0;
|
||||
} else
|
||||
/* Just retain constructed flag */
|
||||
hdr_constructed = r & V_ASN1_CONSTRUCTED;
|
||||
/* Work out new length with IMPLICIT tag: ignore constructed
|
||||
* because it will mess up if indefinite length
|
||||
*/
|
||||
len = ASN1_object_size(0, hdr_len, asn1_tags.imp_tag);
|
||||
} else
|
||||
len = cpy_len;
|
||||
|
||||
/* Work out length in any EXPLICIT, starting from end */
|
||||
|
||||
for (i = 0, etmp = asn1_tags.exp_list + asn1_tags.exp_count - 1;
|
||||
i < asn1_tags.exp_count; i++, etmp--) {
|
||||
/* Content length: number of content octets + any padding */
|
||||
len += etmp->exp_pad;
|
||||
etmp->exp_len = len;
|
||||
/* Total object length: length including new header */
|
||||
len = ASN1_object_size(0, len, etmp->exp_tag);
|
||||
}
|
||||
|
||||
/* Allocate buffer for new encoding */
|
||||
|
||||
new_der = malloc(len);
|
||||
if (!new_der)
|
||||
goto err;
|
||||
|
||||
/* Generate tagged encoding */
|
||||
p = new_der;
|
||||
|
||||
/* Output explicit tags first */
|
||||
for (i = 0, etmp = asn1_tags.exp_list; i < asn1_tags.exp_count;
|
||||
i++, etmp++) {
|
||||
ASN1_put_object(&p, etmp->exp_constructed, etmp->exp_len,
|
||||
etmp->exp_tag, etmp->exp_class);
|
||||
if (etmp->exp_pad)
|
||||
*p++ = 0;
|
||||
}
|
||||
|
||||
/* If IMPLICIT, output tag */
|
||||
|
||||
if (asn1_tags.imp_tag != -1) {
|
||||
if (asn1_tags.imp_class == V_ASN1_UNIVERSAL &&
|
||||
(asn1_tags.imp_tag == V_ASN1_SEQUENCE ||
|
||||
asn1_tags.imp_tag == V_ASN1_SET))
|
||||
hdr_constructed = V_ASN1_CONSTRUCTED;
|
||||
ASN1_put_object(&p, hdr_constructed, hdr_len,
|
||||
asn1_tags.imp_tag, asn1_tags.imp_class);
|
||||
}
|
||||
|
||||
/* Copy across original encoding */
|
||||
memcpy(p, cpy_start, cpy_len);
|
||||
|
||||
cp = new_der;
|
||||
|
||||
/* Obtain new ASN1_TYPE structure */
|
||||
ret = d2i_ASN1_TYPE(NULL, &cp, len);
|
||||
|
||||
err:
|
||||
free(orig_der);
|
||||
free(new_der);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
asn1_cb(const char *elem, int len, void *bitstr)
|
||||
{
|
||||
tag_exp_arg *arg = bitstr;
|
||||
int i;
|
||||
int utype;
|
||||
int vlen = 0;
|
||||
const char *p, *vstart = NULL;
|
||||
|
||||
int tmp_tag, tmp_class;
|
||||
|
||||
for (i = 0, p = elem; i < len; p++, i++) {
|
||||
/* Look for the ':' in name value pairs */
|
||||
if (*p == ':') {
|
||||
vstart = p + 1;
|
||||
vlen = len - (vstart - elem);
|
||||
len = p - elem;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
utype = asn1_str2tag(elem, len);
|
||||
|
||||
if (utype == -1) {
|
||||
ASN1error(ASN1_R_UNKNOWN_TAG);
|
||||
ERR_asprintf_error_data("tag=%s", elem);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* If this is not a modifier mark end of string and exit */
|
||||
if (!(utype & ASN1_GEN_FLAG)) {
|
||||
arg->utype = utype;
|
||||
arg->str = vstart;
|
||||
/* If no value and not end of string, error */
|
||||
if (!vstart && elem[len]) {
|
||||
ASN1error(ASN1_R_MISSING_VALUE);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (utype) {
|
||||
|
||||
case ASN1_GEN_FLAG_IMP:
|
||||
/* Check for illegal multiple IMPLICIT tagging */
|
||||
if (arg->imp_tag != -1) {
|
||||
ASN1error(ASN1_R_ILLEGAL_NESTED_TAGGING);
|
||||
return -1;
|
||||
}
|
||||
if (!parse_tagging(vstart, vlen, &arg->imp_tag,
|
||||
&arg->imp_class))
|
||||
return -1;
|
||||
break;
|
||||
|
||||
case ASN1_GEN_FLAG_EXP:
|
||||
if (!parse_tagging(vstart, vlen, &tmp_tag, &tmp_class))
|
||||
return -1;
|
||||
if (!append_exp(arg, tmp_tag, tmp_class, 1, 0, 0))
|
||||
return -1;
|
||||
break;
|
||||
|
||||
case ASN1_GEN_FLAG_SEQWRAP:
|
||||
if (!append_exp(arg, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, 1, 0, 1))
|
||||
return -1;
|
||||
break;
|
||||
|
||||
case ASN1_GEN_FLAG_SETWRAP:
|
||||
if (!append_exp(arg, V_ASN1_SET, V_ASN1_UNIVERSAL, 1, 0, 1))
|
||||
return -1;
|
||||
break;
|
||||
|
||||
case ASN1_GEN_FLAG_BITWRAP:
|
||||
if (!append_exp(arg, V_ASN1_BIT_STRING, V_ASN1_UNIVERSAL, 0, 1, 1))
|
||||
return -1;
|
||||
break;
|
||||
|
||||
case ASN1_GEN_FLAG_OCTWRAP:
|
||||
if (!append_exp(arg, V_ASN1_OCTET_STRING, V_ASN1_UNIVERSAL, 0, 0, 1))
|
||||
return -1;
|
||||
break;
|
||||
|
||||
case ASN1_GEN_FLAG_FORMAT:
|
||||
if (vstart == NULL) {
|
||||
ASN1error(ASN1_R_ILLEGAL_FORMAT);
|
||||
return -1;
|
||||
}
|
||||
if (!strncmp(vstart, "ASCII", 5))
|
||||
arg->format = ASN1_GEN_FORMAT_ASCII;
|
||||
else if (!strncmp(vstart, "UTF8", 4))
|
||||
arg->format = ASN1_GEN_FORMAT_UTF8;
|
||||
else if (!strncmp(vstart, "HEX", 3))
|
||||
arg->format = ASN1_GEN_FORMAT_HEX;
|
||||
else if (!strncmp(vstart, "BITLIST", 7))
|
||||
arg->format = ASN1_GEN_FORMAT_BITLIST;
|
||||
else {
|
||||
ASN1error(ASN1_R_UNKOWN_FORMAT);
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass)
|
||||
{
|
||||
long tag_num;
|
||||
char *eptr;
|
||||
|
||||
if (!vstart)
|
||||
return 0;
|
||||
tag_num = strtoul(vstart, &eptr, 10);
|
||||
/* Check we haven't gone past max length: should be impossible */
|
||||
if (eptr && *eptr && (eptr > vstart + vlen))
|
||||
return 0;
|
||||
if (tag_num < 0) {
|
||||
ASN1error(ASN1_R_INVALID_NUMBER);
|
||||
return 0;
|
||||
}
|
||||
*ptag = tag_num;
|
||||
/* If we have non numeric characters, parse them */
|
||||
if (eptr)
|
||||
vlen -= eptr - vstart;
|
||||
else
|
||||
vlen = 0;
|
||||
if (vlen) {
|
||||
switch (*eptr) {
|
||||
|
||||
case 'U':
|
||||
*pclass = V_ASN1_UNIVERSAL;
|
||||
break;
|
||||
|
||||
case 'A':
|
||||
*pclass = V_ASN1_APPLICATION;
|
||||
break;
|
||||
|
||||
case 'P':
|
||||
*pclass = V_ASN1_PRIVATE;
|
||||
break;
|
||||
|
||||
case 'C':
|
||||
*pclass = V_ASN1_CONTEXT_SPECIFIC;
|
||||
break;
|
||||
|
||||
default:
|
||||
ASN1error(ASN1_R_INVALID_MODIFIER);
|
||||
ERR_asprintf_error_data("Char=%c", *eptr);
|
||||
return 0;
|
||||
break;
|
||||
|
||||
}
|
||||
} else
|
||||
*pclass = V_ASN1_CONTEXT_SPECIFIC;
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
/* Handle multiple types: SET and SEQUENCE */
|
||||
|
||||
static ASN1_TYPE *
|
||||
asn1_multi(int utype, const char *section, X509V3_CTX *cnf)
|
||||
{
|
||||
ASN1_TYPE *ret = NULL;
|
||||
STACK_OF(ASN1_TYPE) *sk = NULL;
|
||||
STACK_OF(CONF_VALUE) *sect = NULL;
|
||||
unsigned char *der = NULL;
|
||||
int derlen;
|
||||
int i;
|
||||
sk = sk_ASN1_TYPE_new_null();
|
||||
if (!sk)
|
||||
goto bad;
|
||||
if (section) {
|
||||
if (!cnf)
|
||||
goto bad;
|
||||
sect = X509V3_get_section(cnf, (char *)section);
|
||||
if (!sect)
|
||||
goto bad;
|
||||
for (i = 0; i < sk_CONF_VALUE_num(sect); i++) {
|
||||
ASN1_TYPE *typ = ASN1_generate_v3(
|
||||
sk_CONF_VALUE_value(sect, i)->value, cnf);
|
||||
if (!typ)
|
||||
goto bad;
|
||||
if (!sk_ASN1_TYPE_push(sk, typ))
|
||||
goto bad;
|
||||
}
|
||||
}
|
||||
|
||||
/* Now we has a STACK of the components, convert to the correct form */
|
||||
|
||||
if (utype == V_ASN1_SET)
|
||||
derlen = i2d_ASN1_SET_ANY(sk, &der);
|
||||
else
|
||||
derlen = i2d_ASN1_SEQUENCE_ANY(sk, &der);
|
||||
|
||||
if (derlen < 0)
|
||||
goto bad;
|
||||
|
||||
if (!(ret = ASN1_TYPE_new()))
|
||||
goto bad;
|
||||
|
||||
if (!(ret->value.asn1_string = ASN1_STRING_type_new(utype)))
|
||||
goto bad;
|
||||
|
||||
ret->type = utype;
|
||||
|
||||
ret->value.asn1_string->data = der;
|
||||
ret->value.asn1_string->length = derlen;
|
||||
|
||||
der = NULL;
|
||||
|
||||
bad:
|
||||
free(der);
|
||||
if (sk)
|
||||
sk_ASN1_TYPE_pop_free(sk, ASN1_TYPE_free);
|
||||
if (sect)
|
||||
X509V3_section_free(cnf, sect);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_constructed,
|
||||
int exp_pad, int imp_ok)
|
||||
{
|
||||
tag_exp_type *exp_tmp;
|
||||
|
||||
/* Can only have IMPLICIT if permitted */
|
||||
if ((arg->imp_tag != -1) && !imp_ok) {
|
||||
ASN1error(ASN1_R_ILLEGAL_IMPLICIT_TAG);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (arg->exp_count == ASN1_FLAG_EXP_MAX) {
|
||||
ASN1error(ASN1_R_DEPTH_EXCEEDED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
exp_tmp = &arg->exp_list[arg->exp_count++];
|
||||
|
||||
/* If IMPLICIT set tag to implicit value then
|
||||
* reset implicit tag since it has been used.
|
||||
*/
|
||||
if (arg->imp_tag != -1) {
|
||||
exp_tmp->exp_tag = arg->imp_tag;
|
||||
exp_tmp->exp_class = arg->imp_class;
|
||||
arg->imp_tag = -1;
|
||||
arg->imp_class = -1;
|
||||
} else {
|
||||
exp_tmp->exp_tag = exp_tag;
|
||||
exp_tmp->exp_class = exp_class;
|
||||
}
|
||||
exp_tmp->exp_constructed = exp_constructed;
|
||||
exp_tmp->exp_pad = exp_pad;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
asn1_str2tag(const char *tagstr, int len)
|
||||
{
|
||||
unsigned int i;
|
||||
static const struct tag_name_st *tntmp, tnst [] = {
|
||||
ASN1_GEN_STR("BOOL", V_ASN1_BOOLEAN),
|
||||
ASN1_GEN_STR("BOOLEAN", V_ASN1_BOOLEAN),
|
||||
ASN1_GEN_STR("NULL", V_ASN1_NULL),
|
||||
ASN1_GEN_STR("INT", V_ASN1_INTEGER),
|
||||
ASN1_GEN_STR("INTEGER", V_ASN1_INTEGER),
|
||||
ASN1_GEN_STR("ENUM", V_ASN1_ENUMERATED),
|
||||
ASN1_GEN_STR("ENUMERATED", V_ASN1_ENUMERATED),
|
||||
ASN1_GEN_STR("OID", V_ASN1_OBJECT),
|
||||
ASN1_GEN_STR("OBJECT", V_ASN1_OBJECT),
|
||||
ASN1_GEN_STR("UTCTIME", V_ASN1_UTCTIME),
|
||||
ASN1_GEN_STR("UTC", V_ASN1_UTCTIME),
|
||||
ASN1_GEN_STR("GENERALIZEDTIME", V_ASN1_GENERALIZEDTIME),
|
||||
ASN1_GEN_STR("GENTIME", V_ASN1_GENERALIZEDTIME),
|
||||
ASN1_GEN_STR("OCT", V_ASN1_OCTET_STRING),
|
||||
ASN1_GEN_STR("OCTETSTRING", V_ASN1_OCTET_STRING),
|
||||
ASN1_GEN_STR("BITSTR", V_ASN1_BIT_STRING),
|
||||
ASN1_GEN_STR("BITSTRING", V_ASN1_BIT_STRING),
|
||||
ASN1_GEN_STR("UNIVERSALSTRING", V_ASN1_UNIVERSALSTRING),
|
||||
ASN1_GEN_STR("UNIV", V_ASN1_UNIVERSALSTRING),
|
||||
ASN1_GEN_STR("IA5", V_ASN1_IA5STRING),
|
||||
ASN1_GEN_STR("IA5STRING", V_ASN1_IA5STRING),
|
||||
ASN1_GEN_STR("UTF8", V_ASN1_UTF8STRING),
|
||||
ASN1_GEN_STR("UTF8String", V_ASN1_UTF8STRING),
|
||||
ASN1_GEN_STR("BMP", V_ASN1_BMPSTRING),
|
||||
ASN1_GEN_STR("BMPSTRING", V_ASN1_BMPSTRING),
|
||||
ASN1_GEN_STR("VISIBLESTRING", V_ASN1_VISIBLESTRING),
|
||||
ASN1_GEN_STR("VISIBLE", V_ASN1_VISIBLESTRING),
|
||||
ASN1_GEN_STR("PRINTABLESTRING", V_ASN1_PRINTABLESTRING),
|
||||
ASN1_GEN_STR("PRINTABLE", V_ASN1_PRINTABLESTRING),
|
||||
ASN1_GEN_STR("T61", V_ASN1_T61STRING),
|
||||
ASN1_GEN_STR("T61STRING", V_ASN1_T61STRING),
|
||||
ASN1_GEN_STR("TELETEXSTRING", V_ASN1_T61STRING),
|
||||
ASN1_GEN_STR("GeneralString", V_ASN1_GENERALSTRING),
|
||||
ASN1_GEN_STR("GENSTR", V_ASN1_GENERALSTRING),
|
||||
ASN1_GEN_STR("NUMERIC", V_ASN1_NUMERICSTRING),
|
||||
ASN1_GEN_STR("NUMERICSTRING", V_ASN1_NUMERICSTRING),
|
||||
|
||||
/* Special cases */
|
||||
ASN1_GEN_STR("SEQUENCE", V_ASN1_SEQUENCE),
|
||||
ASN1_GEN_STR("SEQ", V_ASN1_SEQUENCE),
|
||||
ASN1_GEN_STR("SET", V_ASN1_SET),
|
||||
/* type modifiers */
|
||||
/* Explicit tag */
|
||||
ASN1_GEN_STR("EXP", ASN1_GEN_FLAG_EXP),
|
||||
ASN1_GEN_STR("EXPLICIT", ASN1_GEN_FLAG_EXP),
|
||||
/* Implicit tag */
|
||||
ASN1_GEN_STR("IMP", ASN1_GEN_FLAG_IMP),
|
||||
ASN1_GEN_STR("IMPLICIT", ASN1_GEN_FLAG_IMP),
|
||||
/* OCTET STRING wrapper */
|
||||
ASN1_GEN_STR("OCTWRAP", ASN1_GEN_FLAG_OCTWRAP),
|
||||
/* SEQUENCE wrapper */
|
||||
ASN1_GEN_STR("SEQWRAP", ASN1_GEN_FLAG_SEQWRAP),
|
||||
/* SET wrapper */
|
||||
ASN1_GEN_STR("SETWRAP", ASN1_GEN_FLAG_SETWRAP),
|
||||
/* BIT STRING wrapper */
|
||||
ASN1_GEN_STR("BITWRAP", ASN1_GEN_FLAG_BITWRAP),
|
||||
ASN1_GEN_STR("FORM", ASN1_GEN_FLAG_FORMAT),
|
||||
ASN1_GEN_STR("FORMAT", ASN1_GEN_FLAG_FORMAT),
|
||||
};
|
||||
|
||||
if (len == -1)
|
||||
len = strlen(tagstr);
|
||||
|
||||
tntmp = tnst;
|
||||
for (i = 0; i < sizeof(tnst) / sizeof(struct tag_name_st);
|
||||
i++, tntmp++) {
|
||||
if ((len == tntmp->len) && !strncmp(tntmp->strnam, tagstr, len))
|
||||
return tntmp->tag;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static ASN1_TYPE *
|
||||
asn1_str2type(const char *str, int format, int utype)
|
||||
{
|
||||
ASN1_TYPE *atmp = NULL;
|
||||
CONF_VALUE vtmp;
|
||||
unsigned char *rdata;
|
||||
long rdlen;
|
||||
int no_unused = 1;
|
||||
|
||||
if (!(atmp = ASN1_TYPE_new())) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!str)
|
||||
str = "";
|
||||
|
||||
switch (utype) {
|
||||
|
||||
case V_ASN1_NULL:
|
||||
if (str && *str) {
|
||||
ASN1error(ASN1_R_ILLEGAL_NULL_VALUE);
|
||||
goto bad_form;
|
||||
}
|
||||
break;
|
||||
|
||||
case V_ASN1_BOOLEAN:
|
||||
if (format != ASN1_GEN_FORMAT_ASCII) {
|
||||
ASN1error(ASN1_R_NOT_ASCII_FORMAT);
|
||||
goto bad_form;
|
||||
}
|
||||
vtmp.name = NULL;
|
||||
vtmp.section = NULL;
|
||||
vtmp.value = (char *)str;
|
||||
if (!X509V3_get_value_bool(&vtmp, &atmp->value.boolean)) {
|
||||
ASN1error(ASN1_R_ILLEGAL_BOOLEAN);
|
||||
goto bad_str;
|
||||
}
|
||||
break;
|
||||
|
||||
case V_ASN1_INTEGER:
|
||||
case V_ASN1_ENUMERATED:
|
||||
if (format != ASN1_GEN_FORMAT_ASCII) {
|
||||
ASN1error(ASN1_R_INTEGER_NOT_ASCII_FORMAT);
|
||||
goto bad_form;
|
||||
}
|
||||
if (!(atmp->value.integer =
|
||||
s2i_ASN1_INTEGER(NULL, (char *)str))) {
|
||||
ASN1error(ASN1_R_ILLEGAL_INTEGER);
|
||||
goto bad_str;
|
||||
}
|
||||
break;
|
||||
|
||||
case V_ASN1_OBJECT:
|
||||
if (format != ASN1_GEN_FORMAT_ASCII) {
|
||||
ASN1error(ASN1_R_OBJECT_NOT_ASCII_FORMAT);
|
||||
goto bad_form;
|
||||
}
|
||||
if (!(atmp->value.object = OBJ_txt2obj(str, 0))) {
|
||||
ASN1error(ASN1_R_ILLEGAL_OBJECT);
|
||||
goto bad_str;
|
||||
}
|
||||
break;
|
||||
|
||||
case V_ASN1_UTCTIME:
|
||||
case V_ASN1_GENERALIZEDTIME:
|
||||
if (format != ASN1_GEN_FORMAT_ASCII) {
|
||||
ASN1error(ASN1_R_TIME_NOT_ASCII_FORMAT);
|
||||
goto bad_form;
|
||||
}
|
||||
if (!(atmp->value.asn1_string = ASN1_STRING_new())) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
goto bad_str;
|
||||
}
|
||||
if (!ASN1_STRING_set(atmp->value.asn1_string, str, -1)) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
goto bad_str;
|
||||
}
|
||||
atmp->value.asn1_string->type = utype;
|
||||
if (!ASN1_TIME_check(atmp->value.asn1_string)) {
|
||||
ASN1error(ASN1_R_ILLEGAL_TIME_VALUE);
|
||||
goto bad_str;
|
||||
}
|
||||
break;
|
||||
|
||||
case V_ASN1_BMPSTRING:
|
||||
case V_ASN1_PRINTABLESTRING:
|
||||
case V_ASN1_IA5STRING:
|
||||
case V_ASN1_T61STRING:
|
||||
case V_ASN1_UTF8STRING:
|
||||
case V_ASN1_VISIBLESTRING:
|
||||
case V_ASN1_UNIVERSALSTRING:
|
||||
case V_ASN1_GENERALSTRING:
|
||||
case V_ASN1_NUMERICSTRING:
|
||||
|
||||
if (format == ASN1_GEN_FORMAT_ASCII)
|
||||
format = MBSTRING_ASC;
|
||||
else if (format == ASN1_GEN_FORMAT_UTF8)
|
||||
format = MBSTRING_UTF8;
|
||||
else {
|
||||
ASN1error(ASN1_R_ILLEGAL_FORMAT);
|
||||
goto bad_form;
|
||||
}
|
||||
|
||||
if (ASN1_mbstring_copy(&atmp->value.asn1_string,
|
||||
(unsigned char *)str, -1, format,
|
||||
ASN1_tag2bit(utype)) <= 0) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
goto bad_str;
|
||||
}
|
||||
break;
|
||||
|
||||
case V_ASN1_BIT_STRING:
|
||||
case V_ASN1_OCTET_STRING:
|
||||
if (!(atmp->value.asn1_string = ASN1_STRING_new())) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
goto bad_form;
|
||||
}
|
||||
|
||||
if (format == ASN1_GEN_FORMAT_HEX) {
|
||||
|
||||
if (!(rdata = string_to_hex((char *)str, &rdlen))) {
|
||||
ASN1error(ASN1_R_ILLEGAL_HEX);
|
||||
goto bad_str;
|
||||
}
|
||||
|
||||
atmp->value.asn1_string->data = rdata;
|
||||
atmp->value.asn1_string->length = rdlen;
|
||||
atmp->value.asn1_string->type = utype;
|
||||
|
||||
} else if (format == ASN1_GEN_FORMAT_ASCII) {
|
||||
if (ASN1_STRING_set(atmp->value.asn1_string, str,
|
||||
-1) == 0) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
goto bad_str;
|
||||
}
|
||||
} else if ((format == ASN1_GEN_FORMAT_BITLIST) &&
|
||||
(utype == V_ASN1_BIT_STRING)) {
|
||||
if (!CONF_parse_list(str, ',', 1, bitstr_cb,
|
||||
atmp->value.bit_string)) {
|
||||
ASN1error(ASN1_R_LIST_ERROR);
|
||||
goto bad_str;
|
||||
}
|
||||
no_unused = 0;
|
||||
|
||||
} else {
|
||||
ASN1error(ASN1_R_ILLEGAL_BITSTRING_FORMAT);
|
||||
goto bad_form;
|
||||
}
|
||||
|
||||
if ((utype == V_ASN1_BIT_STRING) && no_unused) {
|
||||
atmp->value.asn1_string->flags &=
|
||||
~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
|
||||
atmp->value.asn1_string->flags |=
|
||||
ASN1_STRING_FLAG_BITS_LEFT;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
ASN1error(ASN1_R_UNSUPPORTED_TYPE);
|
||||
goto bad_str;
|
||||
break;
|
||||
}
|
||||
|
||||
atmp->type = utype;
|
||||
return atmp;
|
||||
|
||||
bad_str:
|
||||
ERR_asprintf_error_data("string=%s", str);
|
||||
bad_form:
|
||||
ASN1_TYPE_free(atmp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
bitstr_cb(const char *elem, int len, void *bitstr)
|
||||
{
|
||||
long bitnum;
|
||||
char *eptr;
|
||||
|
||||
if (!elem)
|
||||
return 0;
|
||||
bitnum = strtoul(elem, &eptr, 10);
|
||||
if (eptr && *eptr && (eptr != elem + len))
|
||||
return 0;
|
||||
if (bitnum < 0) {
|
||||
ASN1error(ASN1_R_INVALID_NUMBER);
|
||||
return 0;
|
||||
}
|
||||
if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1)) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
639
externals/libressl/crypto/asn1/asn1_item.c
vendored
639
externals/libressl/crypto/asn1/asn1_item.c
vendored
@@ -1,639 +0,0 @@
|
||||
/* $OpenBSD: asn1_item.c,v 1.4 2022/01/14 08:38:05 tb 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.]
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1998-2003 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
|
||||
* openssl-core@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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
#include "asn1_locl.h"
|
||||
#include "evp_locl.h"
|
||||
|
||||
/*
|
||||
* ASN1_ITEM version of dup: this follows the model above except we don't need
|
||||
* to allocate the buffer. At some point this could be rewritten to directly dup
|
||||
* the underlying structure instead of doing and encode and decode.
|
||||
*/
|
||||
|
||||
int
|
||||
ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn,
|
||||
unsigned char *md, unsigned int *len)
|
||||
{
|
||||
int i;
|
||||
unsigned char *str = NULL;
|
||||
|
||||
i = ASN1_item_i2d(asn, &str, it);
|
||||
if (!str)
|
||||
return (0);
|
||||
|
||||
if (!EVP_Digest(str, i, md, len, type, NULL)) {
|
||||
free(str);
|
||||
return (0);
|
||||
}
|
||||
|
||||
free(str);
|
||||
return (1);
|
||||
}
|
||||
|
||||
void *
|
||||
ASN1_item_dup(const ASN1_ITEM *it, void *x)
|
||||
{
|
||||
unsigned char *b = NULL;
|
||||
const unsigned char *p;
|
||||
long i;
|
||||
void *ret;
|
||||
|
||||
if (x == NULL)
|
||||
return (NULL);
|
||||
|
||||
i = ASN1_item_i2d(x, &b, it);
|
||||
if (b == NULL) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
return (NULL);
|
||||
}
|
||||
p = b;
|
||||
ret = ASN1_item_d2i(NULL, &p, i, it);
|
||||
free(b);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/* Pack an ASN1 object into an ASN1_STRING. */
|
||||
ASN1_STRING *
|
||||
ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct)
|
||||
{
|
||||
ASN1_STRING *octmp;
|
||||
|
||||
if (!oct || !*oct) {
|
||||
if (!(octmp = ASN1_STRING_new ())) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
} else
|
||||
octmp = *oct;
|
||||
|
||||
free(octmp->data);
|
||||
octmp->data = NULL;
|
||||
|
||||
if (!(octmp->length = ASN1_item_i2d(obj, &octmp->data, it))) {
|
||||
ASN1error(ASN1_R_ENCODE_ERROR);
|
||||
goto err;
|
||||
}
|
||||
if (!octmp->data) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
if (oct)
|
||||
*oct = octmp;
|
||||
return octmp;
|
||||
err:
|
||||
if (!oct || octmp != *oct)
|
||||
ASN1_STRING_free(octmp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Extract an ASN1 object from an ASN1_STRING. */
|
||||
void *
|
||||
ASN1_item_unpack(const ASN1_STRING *oct, const ASN1_ITEM *it)
|
||||
{
|
||||
const unsigned char *p;
|
||||
void *ret;
|
||||
|
||||
p = oct->data;
|
||||
if (!(ret = ASN1_item_d2i(NULL, &p, oct->length, it)))
|
||||
ASN1error(ASN1_R_DECODE_ERROR);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2,
|
||||
ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey, const EVP_MD *type)
|
||||
{
|
||||
EVP_MD_CTX ctx;
|
||||
EVP_MD_CTX_init(&ctx);
|
||||
if (!EVP_DigestSignInit(&ctx, NULL, type, NULL, pkey)) {
|
||||
EVP_MD_CTX_cleanup(&ctx);
|
||||
return 0;
|
||||
}
|
||||
return ASN1_item_sign_ctx(it, algor1, algor2, signature, asn, &ctx);
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2,
|
||||
ASN1_BIT_STRING *signature, void *asn, EVP_MD_CTX *ctx)
|
||||
{
|
||||
const EVP_MD *type;
|
||||
EVP_PKEY *pkey;
|
||||
unsigned char *buf_in = NULL, *buf_out = NULL;
|
||||
size_t inl = 0, outl = 0, outll = 0;
|
||||
int signid, paramtype;
|
||||
int rv;
|
||||
|
||||
type = EVP_MD_CTX_md(ctx);
|
||||
pkey = EVP_PKEY_CTX_get0_pkey(ctx->pctx);
|
||||
|
||||
if (!type || !pkey) {
|
||||
ASN1error(ASN1_R_CONTEXT_NOT_INITIALISED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (pkey->ameth->item_sign) {
|
||||
rv = pkey->ameth->item_sign(ctx, it, asn, algor1, algor2,
|
||||
signature);
|
||||
if (rv == 1)
|
||||
outl = signature->length;
|
||||
/* Return value meanings:
|
||||
* <=0: error.
|
||||
* 1: method does everything.
|
||||
* 2: carry on as normal.
|
||||
* 3: ASN1 method sets algorithm identifiers: just sign.
|
||||
*/
|
||||
if (rv <= 0)
|
||||
ASN1error(ERR_R_EVP_LIB);
|
||||
if (rv <= 1)
|
||||
goto err;
|
||||
} else
|
||||
rv = 2;
|
||||
|
||||
if (rv == 2) {
|
||||
if (!pkey->ameth ||
|
||||
!OBJ_find_sigid_by_algs(&signid, EVP_MD_nid(type),
|
||||
pkey->ameth->pkey_id)) {
|
||||
ASN1error(ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (pkey->ameth->pkey_flags & ASN1_PKEY_SIGPARAM_NULL)
|
||||
paramtype = V_ASN1_NULL;
|
||||
else
|
||||
paramtype = V_ASN1_UNDEF;
|
||||
|
||||
if (algor1)
|
||||
X509_ALGOR_set0(algor1,
|
||||
OBJ_nid2obj(signid), paramtype, NULL);
|
||||
if (algor2)
|
||||
X509_ALGOR_set0(algor2,
|
||||
OBJ_nid2obj(signid), paramtype, NULL);
|
||||
|
||||
}
|
||||
|
||||
inl = ASN1_item_i2d(asn, &buf_in, it);
|
||||
outll = outl = EVP_PKEY_size(pkey);
|
||||
buf_out = malloc(outl);
|
||||
if ((buf_in == NULL) || (buf_out == NULL)) {
|
||||
outl = 0;
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!EVP_DigestSignUpdate(ctx, buf_in, inl) ||
|
||||
!EVP_DigestSignFinal(ctx, buf_out, &outl)) {
|
||||
outl = 0;
|
||||
ASN1error(ERR_R_EVP_LIB);
|
||||
goto err;
|
||||
}
|
||||
free(signature->data);
|
||||
signature->data = buf_out;
|
||||
buf_out = NULL;
|
||||
signature->length = outl;
|
||||
/* In the interests of compatibility, I'll make sure that
|
||||
* the bit string has a 'not-used bits' value of 0
|
||||
*/
|
||||
signature->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
|
||||
signature->flags |= ASN1_STRING_FLAG_BITS_LEFT;
|
||||
|
||||
err:
|
||||
EVP_MD_CTX_cleanup(ctx);
|
||||
freezero((char *)buf_in, inl);
|
||||
freezero((char *)buf_out, outll);
|
||||
return (outl);
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,
|
||||
ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey)
|
||||
{
|
||||
EVP_MD_CTX ctx;
|
||||
unsigned char *buf_in = NULL;
|
||||
int ret = -1, inl;
|
||||
|
||||
int mdnid, pknid;
|
||||
|
||||
if (!pkey) {
|
||||
ASN1error(ERR_R_PASSED_NULL_PARAMETER);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (signature->type == V_ASN1_BIT_STRING && signature->flags & 0x7)
|
||||
{
|
||||
ASN1error(ASN1_R_INVALID_BIT_STRING_BITS_LEFT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
EVP_MD_CTX_init(&ctx);
|
||||
|
||||
/* Convert signature OID into digest and public key OIDs */
|
||||
if (!OBJ_find_sigid_algs(OBJ_obj2nid(a->algorithm), &mdnid, &pknid)) {
|
||||
ASN1error(ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM);
|
||||
goto err;
|
||||
}
|
||||
if (mdnid == NID_undef) {
|
||||
if (!pkey->ameth || !pkey->ameth->item_verify) {
|
||||
ASN1error(ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM);
|
||||
goto err;
|
||||
}
|
||||
ret = pkey->ameth->item_verify(&ctx, it, asn, a,
|
||||
signature, pkey);
|
||||
/* Return value of 2 means carry on, anything else means we
|
||||
* exit straight away: either a fatal error of the underlying
|
||||
* verification routine handles all verification.
|
||||
*/
|
||||
if (ret != 2)
|
||||
goto err;
|
||||
ret = -1;
|
||||
} else {
|
||||
const EVP_MD *type;
|
||||
type = EVP_get_digestbynid(mdnid);
|
||||
if (type == NULL) {
|
||||
ASN1error(ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Check public key OID matches public key type */
|
||||
if (EVP_PKEY_type(pknid) != pkey->ameth->pkey_id) {
|
||||
ASN1error(ASN1_R_WRONG_PUBLIC_KEY_TYPE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!EVP_DigestVerifyInit(&ctx, NULL, type, NULL, pkey)) {
|
||||
ASN1error(ERR_R_EVP_LIB);
|
||||
ret = 0;
|
||||
goto err;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
inl = ASN1_item_i2d(asn, &buf_in, it);
|
||||
|
||||
if (buf_in == NULL) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!EVP_DigestVerifyUpdate(&ctx, buf_in, inl)) {
|
||||
ASN1error(ERR_R_EVP_LIB);
|
||||
ret = 0;
|
||||
goto err;
|
||||
}
|
||||
|
||||
freezero(buf_in, (unsigned int)inl);
|
||||
|
||||
if (EVP_DigestVerifyFinal(&ctx, signature->data,
|
||||
(size_t)signature->length) <= 0) {
|
||||
ASN1error(ERR_R_EVP_LIB);
|
||||
ret = 0;
|
||||
goto err;
|
||||
}
|
||||
/* we don't need to zero the 'ctx' because we just checked
|
||||
* public information */
|
||||
/* memset(&ctx,0,sizeof(ctx)); */
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
EVP_MD_CTX_cleanup(&ctx);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
#define HEADER_SIZE 8
|
||||
#define ASN1_CHUNK_INITIAL_SIZE (16 * 1024)
|
||||
int
|
||||
asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
|
||||
{
|
||||
BUF_MEM *b;
|
||||
unsigned char *p;
|
||||
const unsigned char *q;
|
||||
long slen;
|
||||
int i, inf, tag, xclass;
|
||||
size_t want = HEADER_SIZE;
|
||||
int eos = 0;
|
||||
size_t off = 0;
|
||||
size_t len = 0;
|
||||
|
||||
b = BUF_MEM_new();
|
||||
if (b == NULL) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ERR_clear_error();
|
||||
for (;;) {
|
||||
if (want >= (len - off)) {
|
||||
want -= (len - off);
|
||||
|
||||
if (len + want < len ||
|
||||
!BUF_MEM_grow_clean(b, len + want)) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
i = BIO_read(in, &(b->data[len]), want);
|
||||
if ((i < 0) && ((len - off) == 0)) {
|
||||
ASN1error(ASN1_R_NOT_ENOUGH_DATA);
|
||||
goto err;
|
||||
}
|
||||
if (i > 0) {
|
||||
if (len + i < len) {
|
||||
ASN1error(ASN1_R_TOO_LONG);
|
||||
goto err;
|
||||
}
|
||||
len += i;
|
||||
}
|
||||
}
|
||||
/* else data already loaded */
|
||||
|
||||
p = (unsigned char *) & (b->data[off]);
|
||||
q = p;
|
||||
inf = ASN1_get_object(&q, &slen, &tag, &xclass, len - off);
|
||||
if (inf & 0x80) {
|
||||
unsigned long e;
|
||||
|
||||
e = ERR_GET_REASON(ERR_peek_error());
|
||||
if (e != ASN1_R_TOO_LONG)
|
||||
goto err;
|
||||
else
|
||||
ERR_clear_error(); /* clear error */
|
||||
}
|
||||
i = q - p; /* header length */
|
||||
off += i; /* end of data */
|
||||
|
||||
if (inf & 1) {
|
||||
/* no data body so go round again */
|
||||
eos++;
|
||||
if (eos < 0) {
|
||||
ASN1error(ASN1_R_HEADER_TOO_LONG);
|
||||
goto err;
|
||||
}
|
||||
want = HEADER_SIZE;
|
||||
} else if (eos && slen == 0 && tag == V_ASN1_EOC) {
|
||||
/* eos value, so go back and read another header */
|
||||
eos--;
|
||||
if (eos <= 0)
|
||||
break;
|
||||
else
|
||||
want = HEADER_SIZE;
|
||||
} else {
|
||||
/* suck in slen bytes of data */
|
||||
want = slen;
|
||||
if (want > (len - off)) {
|
||||
size_t chunk_max = ASN1_CHUNK_INITIAL_SIZE;
|
||||
|
||||
want -= (len - off);
|
||||
if (want > INT_MAX /* BIO_read takes an int length */ ||
|
||||
len+want < len) {
|
||||
ASN1error(ASN1_R_TOO_LONG);
|
||||
goto err;
|
||||
}
|
||||
while (want > 0) {
|
||||
/*
|
||||
* Read content in chunks of increasing size
|
||||
* so we can return an error for EOF without
|
||||
* having to allocate the entire content length
|
||||
* in one go.
|
||||
*/
|
||||
size_t chunk = want > chunk_max ? chunk_max : want;
|
||||
|
||||
if (!BUF_MEM_grow_clean(b, len + chunk)) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
want -= chunk;
|
||||
while (chunk > 0) {
|
||||
i = BIO_read(in, &(b->data[len]), chunk);
|
||||
if (i <= 0) {
|
||||
ASN1error(ASN1_R_NOT_ENOUGH_DATA);
|
||||
goto err;
|
||||
}
|
||||
/*
|
||||
* This can't overflow because |len+want|
|
||||
* didn't overflow.
|
||||
*/
|
||||
len += i;
|
||||
chunk -= i;
|
||||
}
|
||||
if (chunk_max < INT_MAX/2)
|
||||
chunk_max *= 2;
|
||||
}
|
||||
}
|
||||
if (off + slen < off) {
|
||||
ASN1error(ASN1_R_TOO_LONG);
|
||||
goto err;
|
||||
}
|
||||
off += slen;
|
||||
if (eos <= 0) {
|
||||
break;
|
||||
} else
|
||||
want = HEADER_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
if (off > INT_MAX) {
|
||||
ASN1error(ASN1_R_TOO_LONG);
|
||||
goto err;
|
||||
}
|
||||
|
||||
*pb = b;
|
||||
return off;
|
||||
|
||||
err:
|
||||
if (b != NULL)
|
||||
BUF_MEM_free(b);
|
||||
return -1;
|
||||
}
|
||||
|
||||
void *
|
||||
ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x)
|
||||
{
|
||||
BUF_MEM *b = NULL;
|
||||
const unsigned char *p;
|
||||
void *ret = NULL;
|
||||
int len;
|
||||
|
||||
len = asn1_d2i_read_bio(in, &b);
|
||||
if (len < 0)
|
||||
goto err;
|
||||
|
||||
p = (const unsigned char *)b->data;
|
||||
ret = ASN1_item_d2i(x, &p, len, it);
|
||||
|
||||
err:
|
||||
if (b != NULL)
|
||||
BUF_MEM_free(b);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
void *
|
||||
ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x)
|
||||
{
|
||||
BIO *b;
|
||||
char *ret;
|
||||
|
||||
if ((b = BIO_new(BIO_s_file())) == NULL) {
|
||||
ASN1error(ERR_R_BUF_LIB);
|
||||
return (NULL);
|
||||
}
|
||||
BIO_set_fp(b, in, BIO_NOCLOSE);
|
||||
ret = ASN1_item_d2i_bio(it, b, x);
|
||||
BIO_free(b);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x)
|
||||
{
|
||||
unsigned char *b = NULL;
|
||||
int i, j = 0, n, ret = 1;
|
||||
|
||||
n = ASN1_item_i2d(x, &b, it);
|
||||
if (b == NULL) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
return (0);
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
i = BIO_write(out, &(b[j]), n);
|
||||
if (i == n)
|
||||
break;
|
||||
if (i <= 0) {
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
j += i;
|
||||
n -= i;
|
||||
}
|
||||
free(b);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x)
|
||||
{
|
||||
BIO *b;
|
||||
int ret;
|
||||
|
||||
if ((b = BIO_new(BIO_s_file())) == NULL) {
|
||||
ASN1error(ERR_R_BUF_LIB);
|
||||
return (0);
|
||||
}
|
||||
BIO_set_fp(b, out, BIO_NOCLOSE);
|
||||
ret = ASN1_item_i2d_bio(it, b, x);
|
||||
BIO_free(b);
|
||||
return (ret);
|
||||
}
|
||||
202
externals/libressl/crypto/asn1/asn1_lib.c
vendored
202
externals/libressl/crypto/asn1/asn1_lib.c
vendored
@@ -1,202 +0,0 @@
|
||||
/* $OpenBSD: asn1_lib.c,v 1.52 2022/03/26 14:47:58 jsing Exp $ */
|
||||
/*
|
||||
* Copyright (c) 2021 Joel Sing <jsing@openbsd.org>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "bytestring.h"
|
||||
|
||||
static int
|
||||
asn1_get_identifier_cbs(CBS *cbs, int der_mode, uint8_t *out_class,
|
||||
int *out_constructed, uint32_t *out_tag_number)
|
||||
{
|
||||
uint8_t tag_class, tag_val;
|
||||
int tag_constructed;
|
||||
uint32_t tag_number;
|
||||
|
||||
/*
|
||||
* Decode ASN.1 identifier octets - see ITU-T X.690 section 8.1.2.
|
||||
*/
|
||||
|
||||
*out_class = 0;
|
||||
*out_constructed = 0;
|
||||
*out_tag_number = 0;
|
||||
|
||||
if (!CBS_get_u8(cbs, &tag_val))
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* ASN.1 tag class, encoding (primitive or constructed) and tag number
|
||||
* are encoded in one or more identifier octets - the first octet
|
||||
* contains the 2 bit tag class, the 1 bit encoding type and 5 bits
|
||||
* of tag number.
|
||||
*
|
||||
* For tag numbers larger than 30 (0x1e) the 5 bit tag number in the
|
||||
* first octet is set to all ones (0x1f) - the tag number is then
|
||||
* encoded in subsequent octets - each of which have a one bit
|
||||
* continuation flag and 7 bits of tag number in big-endian form.
|
||||
* The encoding should not contain leading zeros but can for BER.
|
||||
*/
|
||||
tag_class = (tag_val >> 6) & 0x3;
|
||||
tag_constructed = (tag_val >> 5) & 0x1;
|
||||
tag_number = tag_val & 0x1f;
|
||||
|
||||
/* Long form. */
|
||||
if (tag_number == 0x1f) {
|
||||
tag_number = 0;
|
||||
do {
|
||||
if (!CBS_get_u8(cbs, &tag_val))
|
||||
return 0;
|
||||
if (der_mode && tag_number == 0 && tag_val == 0x80)
|
||||
return 0;
|
||||
if (tag_number > (UINT32_MAX >> 7))
|
||||
return 0;
|
||||
tag_number = tag_number << 7 | (tag_val & 0x7f);
|
||||
} while ((tag_val & 0x80) != 0);
|
||||
}
|
||||
|
||||
*out_class = tag_class;
|
||||
*out_constructed = tag_constructed;
|
||||
*out_tag_number = tag_number;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
asn1_get_length_cbs(CBS *cbs, int der_mode, int *out_indefinite,
|
||||
uint32_t *out_length)
|
||||
{
|
||||
uint8_t len_bytes;
|
||||
uint32_t length;
|
||||
uint8_t val;
|
||||
|
||||
/*
|
||||
* Decode ASN.1 length octets - see ITU-T X.690 section 8.1.3.
|
||||
*/
|
||||
|
||||
*out_length = 0;
|
||||
*out_indefinite = 0;
|
||||
|
||||
if (!CBS_get_u8(cbs, &val))
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* Short form - length is encoded in the lower 7 bits of a single byte.
|
||||
*/
|
||||
if (val < 0x80) {
|
||||
*out_length = val;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Indefinite length - content continues until an End of Content (EOC)
|
||||
* marker is reached. Must be used with constructed encoding.
|
||||
*/
|
||||
if (val == 0x80) {
|
||||
*out_indefinite = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Long form - the lower 7 bits of the first byte specifies the number
|
||||
* of bytes used to encode the length, the following bytes specify the
|
||||
* length in big-endian form. The encoding should not contain leading
|
||||
* zeros but can for BER. A length value of 0x7f is invalid.
|
||||
*/
|
||||
if ((len_bytes = val & 0x7f) == 0x7f)
|
||||
return 0;
|
||||
|
||||
length = 0;
|
||||
|
||||
while (len_bytes-- > 0) {
|
||||
if (!CBS_get_u8(cbs, &val))
|
||||
return 0;
|
||||
if (der_mode && length == 0 && val == 0)
|
||||
return 0;
|
||||
if (length > (UINT32_MAX >> 8))
|
||||
return 0;
|
||||
length = (length << 8) | val;
|
||||
}
|
||||
|
||||
*out_length = length;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
asn1_get_object_cbs(CBS *cbs, int der_mode, uint8_t *out_tag_class,
|
||||
int *out_constructed, uint32_t *out_tag_number, int *out_indefinite,
|
||||
uint32_t *out_length)
|
||||
{
|
||||
int constructed, indefinite;
|
||||
uint32_t tag_number, length;
|
||||
uint8_t tag_class;
|
||||
|
||||
*out_tag_class = 0;
|
||||
*out_constructed = 0;
|
||||
*out_tag_number = 0;
|
||||
*out_indefinite = 0;
|
||||
*out_length = 0;
|
||||
|
||||
if (!asn1_get_identifier_cbs(cbs, der_mode, &tag_class, &constructed,
|
||||
&tag_number))
|
||||
return 0;
|
||||
if (!asn1_get_length_cbs(cbs, der_mode, &indefinite, &length))
|
||||
return 0;
|
||||
|
||||
/* Indefinite length can only be used with constructed encoding. */
|
||||
if (indefinite && !constructed)
|
||||
return 0;
|
||||
|
||||
*out_tag_class = tag_class;
|
||||
*out_constructed = constructed;
|
||||
*out_tag_number = tag_number;
|
||||
*out_indefinite = indefinite;
|
||||
*out_length = length;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
asn1_get_primitive(CBS *cbs, int der_mode, uint32_t *out_tag_number,
|
||||
CBS *out_content)
|
||||
{
|
||||
int constructed, indefinite;
|
||||
uint32_t tag_number, length;
|
||||
uint8_t tag_class;
|
||||
|
||||
*out_tag_number = 0;
|
||||
|
||||
CBS_init(out_content, NULL, 0);
|
||||
|
||||
if (!asn1_get_identifier_cbs(cbs, der_mode, &tag_class, &constructed,
|
||||
&tag_number))
|
||||
return 0;
|
||||
if (!asn1_get_length_cbs(cbs, der_mode, &indefinite, &length))
|
||||
return 0;
|
||||
|
||||
/* A primitive is not constructed and has a definite length. */
|
||||
if (constructed || indefinite)
|
||||
return 0;
|
||||
|
||||
if (!CBS_get_bytes(cbs, out_content, length))
|
||||
return 0;
|
||||
|
||||
*out_tag_number = tag_number;
|
||||
|
||||
return 1;
|
||||
}
|
||||
208
externals/libressl/crypto/asn1/asn1_locl.h
vendored
208
externals/libressl/crypto/asn1/asn1_locl.h
vendored
@@ -1,208 +0,0 @@
|
||||
/* $OpenBSD: asn1_locl.h,v 1.24 2022/03/26 14:47:58 jsing Exp $ */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 2006.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2006 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include "bytestring.h"
|
||||
|
||||
__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);
|
||||
|
||||
/* These are used internally in the ASN1_OBJECT to keep track of
|
||||
* whether the names and data need to be free()ed */
|
||||
#define ASN1_OBJECT_FLAG_DYNAMIC 0x01 /* internal use */
|
||||
#define ASN1_OBJECT_FLAG_CRITICAL 0x02 /* critical x509v3 object id */
|
||||
#define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04 /* internal use */
|
||||
#define ASN1_OBJECT_FLAG_DYNAMIC_DATA 0x08 /* internal use */
|
||||
struct asn1_object_st {
|
||||
const char *sn, *ln;
|
||||
int nid;
|
||||
int length;
|
||||
const unsigned char *data; /* data remains const after init */
|
||||
int flags; /* Should we free this one */
|
||||
} /* ASN1_OBJECT */;
|
||||
|
||||
/* ASN1 print context structure */
|
||||
|
||||
struct asn1_pctx_st {
|
||||
unsigned long flags;
|
||||
unsigned long nm_flags;
|
||||
unsigned long cert_flags;
|
||||
unsigned long oid_flags;
|
||||
unsigned long str_flags;
|
||||
} /* ASN1_PCTX */;
|
||||
|
||||
/* ASN1 public key method structure */
|
||||
|
||||
struct evp_pkey_asn1_method_st {
|
||||
int pkey_id;
|
||||
int pkey_base_id;
|
||||
unsigned long pkey_flags;
|
||||
|
||||
char *pem_str;
|
||||
char *info;
|
||||
|
||||
int (*pub_decode)(EVP_PKEY *pk, X509_PUBKEY *pub);
|
||||
int (*pub_encode)(X509_PUBKEY *pub, const EVP_PKEY *pk);
|
||||
int (*pub_cmp)(const EVP_PKEY *a, const EVP_PKEY *b);
|
||||
int (*pub_print)(BIO *out, const EVP_PKEY *pkey, int indent,
|
||||
ASN1_PCTX *pctx);
|
||||
|
||||
int (*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);
|
||||
|
||||
int (*pkey_size)(const EVP_PKEY *pk);
|
||||
int (*pkey_bits)(const EVP_PKEY *pk);
|
||||
|
||||
int (*param_decode)(EVP_PKEY *pkey, const unsigned char **pder,
|
||||
int derlen);
|
||||
int (*param_encode)(const EVP_PKEY *pkey, unsigned char **pder);
|
||||
int (*param_missing)(const EVP_PKEY *pk);
|
||||
int (*param_copy)(EVP_PKEY *to, const EVP_PKEY *from);
|
||||
int (*param_cmp)(const EVP_PKEY *a, const EVP_PKEY *b);
|
||||
int (*param_print)(BIO *out, const EVP_PKEY *pkey, int indent,
|
||||
ASN1_PCTX *pctx);
|
||||
int (*sig_print)(BIO *out, const X509_ALGOR *sigalg,
|
||||
const ASN1_STRING *sig, int indent, ASN1_PCTX *pctx);
|
||||
|
||||
void (*pkey_free)(EVP_PKEY *pkey);
|
||||
int (*pkey_ctrl)(EVP_PKEY *pkey, int op, long arg1, void *arg2);
|
||||
|
||||
/* Legacy functions for old PEM */
|
||||
|
||||
int (*old_priv_decode)(EVP_PKEY *pkey, const unsigned char **pder,
|
||||
int derlen);
|
||||
int (*old_priv_encode)(const EVP_PKEY *pkey, unsigned char **pder);
|
||||
/* Custom ASN1 signature verification */
|
||||
int (*item_verify)(EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,
|
||||
X509_ALGOR *a, ASN1_BIT_STRING *sig, EVP_PKEY *pkey);
|
||||
int (*item_sign)(EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,
|
||||
X509_ALGOR *alg1, X509_ALGOR *alg2, ASN1_BIT_STRING *sig);
|
||||
|
||||
int (*pkey_check)(const EVP_PKEY *pk);
|
||||
int (*pkey_public_check)(const EVP_PKEY *pk);
|
||||
int (*pkey_param_check)(const EVP_PKEY *pk);
|
||||
} /* EVP_PKEY_ASN1_METHOD */;
|
||||
|
||||
/* Method to handle CRL access.
|
||||
* In general a CRL could be very large (several Mb) and can consume large
|
||||
* amounts of resources if stored in memory by multiple processes.
|
||||
* This method allows general CRL operations to be redirected to more
|
||||
* efficient callbacks: for example a CRL entry database.
|
||||
*/
|
||||
|
||||
#define X509_CRL_METHOD_DYNAMIC 1
|
||||
|
||||
struct x509_crl_method_st {
|
||||
int flags;
|
||||
int (*crl_init)(X509_CRL *crl);
|
||||
int (*crl_free)(X509_CRL *crl);
|
||||
int (*crl_lookup)(X509_CRL *crl, X509_REVOKED **ret,
|
||||
ASN1_INTEGER *ser, X509_NAME *issuer);
|
||||
int (*crl_verify)(X509_CRL *crl, EVP_PKEY *pk);
|
||||
};
|
||||
|
||||
int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it);
|
||||
|
||||
ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
|
||||
|
||||
const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int nullerr);
|
||||
|
||||
int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it);
|
||||
|
||||
void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, const ASN1_ITEM *it);
|
||||
|
||||
int i2d_ASN1_BOOLEAN(int a, unsigned char **pp);
|
||||
int d2i_ASN1_BOOLEAN(int *a, const unsigned char **pp, long length);
|
||||
|
||||
/*
|
||||
* Unicode codepoint constants
|
||||
*/
|
||||
#define UNICODE_MAX 0x10FFFF
|
||||
#define UNICODE_SURROGATE_MIN 0x00D800
|
||||
#define UNICODE_SURROGATE_MAX 0x00DFFF
|
||||
|
||||
#define UNICODE_IS_SURROGATE(x) \
|
||||
((x) >= UNICODE_SURROGATE_MIN && (x) <= UNICODE_SURROGATE_MAX)
|
||||
|
||||
int UTF8_getc(const unsigned char *str, int len, unsigned long *val);
|
||||
int UTF8_putc(unsigned char *str, int len, unsigned long value);
|
||||
|
||||
int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb);
|
||||
|
||||
int asn1_get_object_cbs(CBS *cbs, int der_mode, uint8_t *out_class,
|
||||
int *out_constructed, uint32_t *out_tag_number, int *out_indefinite,
|
||||
uint32_t *out_length);
|
||||
int asn1_get_primitive(CBS *cbs, int der_mode, uint32_t *out_tag_number,
|
||||
CBS *out_content);
|
||||
|
||||
int asn1_tag2charwidth(int tag);
|
||||
|
||||
int i2t_ASN1_OBJECT_internal(const ASN1_OBJECT *aobj, char *buf, int buf_len,
|
||||
int no_name);
|
||||
ASN1_OBJECT *t2i_ASN1_OBJECT_internal(const char *oid);
|
||||
|
||||
__END_HIDDEN_DECLS
|
||||
180
externals/libressl/crypto/asn1/asn1_old.c
vendored
180
externals/libressl/crypto/asn1/asn1_old.c
vendored
@@ -1,180 +0,0 @@
|
||||
/* $OpenBSD: asn1_old.c,v 1.2 2021/12/25 13:17:48 jsing 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 <limits.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#include "asn1_locl.h"
|
||||
|
||||
#ifndef NO_OLD_ASN1
|
||||
|
||||
void *
|
||||
ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x)
|
||||
{
|
||||
unsigned char *b, *p;
|
||||
const unsigned char *p2;
|
||||
int i;
|
||||
char *ret;
|
||||
|
||||
if (x == NULL)
|
||||
return (NULL);
|
||||
|
||||
i = i2d(x, NULL);
|
||||
b = malloc(i + 10);
|
||||
if (b == NULL) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
return (NULL);
|
||||
}
|
||||
p = b;
|
||||
i = i2d(x, &p);
|
||||
p2 = b;
|
||||
ret = d2i(NULL, &p2, i);
|
||||
free(b);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
void *
|
||||
ASN1_d2i_fp(void *(*xnew)(void), d2i_of_void *d2i, FILE *in, void **x)
|
||||
{
|
||||
BIO *b;
|
||||
void *ret;
|
||||
|
||||
if ((b = BIO_new(BIO_s_file())) == NULL) {
|
||||
ASN1error(ERR_R_BUF_LIB);
|
||||
return (NULL);
|
||||
}
|
||||
BIO_set_fp(b, in, BIO_NOCLOSE);
|
||||
ret = ASN1_d2i_bio(xnew, d2i, b, x);
|
||||
BIO_free(b);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
void *
|
||||
ASN1_d2i_bio(void *(*xnew)(void), d2i_of_void *d2i, BIO *in, void **x)
|
||||
{
|
||||
BUF_MEM *b = NULL;
|
||||
const unsigned char *p;
|
||||
void *ret = NULL;
|
||||
int len;
|
||||
|
||||
len = asn1_d2i_read_bio(in, &b);
|
||||
if (len < 0)
|
||||
goto err;
|
||||
|
||||
p = (unsigned char *)b->data;
|
||||
ret = d2i(x, &p, len);
|
||||
|
||||
err:
|
||||
if (b != NULL)
|
||||
BUF_MEM_free(b);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x)
|
||||
{
|
||||
BIO *b;
|
||||
int ret;
|
||||
|
||||
if ((b = BIO_new(BIO_s_file())) == NULL) {
|
||||
ASN1error(ERR_R_BUF_LIB);
|
||||
return (0);
|
||||
}
|
||||
BIO_set_fp(b, out, BIO_NOCLOSE);
|
||||
ret = ASN1_i2d_bio(i2d, b, x);
|
||||
BIO_free(b);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x)
|
||||
{
|
||||
char *b;
|
||||
unsigned char *p;
|
||||
int i, j = 0, n, ret = 1;
|
||||
|
||||
n = i2d(x, NULL);
|
||||
b = malloc(n);
|
||||
if (b == NULL) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
return (0);
|
||||
}
|
||||
|
||||
p = (unsigned char *)b;
|
||||
i2d(x, &p);
|
||||
|
||||
for (;;) {
|
||||
i = BIO_write(out, &(b[j]), n);
|
||||
if (i == n)
|
||||
break;
|
||||
if (i <= 0) {
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
j += i;
|
||||
n -= i;
|
||||
}
|
||||
free(b);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
#endif
|
||||
211
externals/libressl/crypto/asn1/asn1_old_lib.c
vendored
211
externals/libressl/crypto/asn1/asn1_old_lib.c
vendored
@@ -1,211 +0,0 @@
|
||||
/* $OpenBSD: asn1_old_lib.c,v 1.3 2022/01/14 07:57:17 tb 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 <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#include "asn1_locl.h"
|
||||
|
||||
static void asn1_put_length(unsigned char **pp, int length);
|
||||
|
||||
int
|
||||
ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,
|
||||
int *pclass, long omax)
|
||||
{
|
||||
int constructed, indefinite;
|
||||
uint32_t tag_number, length;
|
||||
uint8_t tag_class;
|
||||
CBS cbs;
|
||||
int ret = 0;
|
||||
|
||||
*pclass = 0;
|
||||
*ptag = 0;
|
||||
*plength = 0;
|
||||
|
||||
CBS_init(&cbs, *pp, omax);
|
||||
|
||||
if (!asn1_get_object_cbs(&cbs, 0, &tag_class, &constructed, &tag_number,
|
||||
&indefinite, &length)) {
|
||||
ASN1error(ASN1_R_HEADER_TOO_LONG);
|
||||
return 0x80;
|
||||
}
|
||||
|
||||
if (tag_number > INT_MAX) {
|
||||
ASN1error(ASN1_R_HEADER_TOO_LONG);
|
||||
return 0x80;
|
||||
}
|
||||
|
||||
/*
|
||||
* API insanity ahead... in this case we add an error to the stack and
|
||||
* signal an error by setting the 8th bit in the return value... but we
|
||||
* still provide all of the decoded data.
|
||||
*/
|
||||
if (length > CBS_len(&cbs)) {
|
||||
ASN1error(ASN1_R_TOO_LONG);
|
||||
ret = 0x80;
|
||||
}
|
||||
|
||||
*pclass = tag_class << 6;
|
||||
*ptag = tag_number;
|
||||
*plength = length;
|
||||
|
||||
*pp = CBS_data(&cbs);
|
||||
|
||||
if (constructed)
|
||||
ret |= 1 << 5;
|
||||
if (indefinite)
|
||||
ret |= 1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* class 0 is constructed
|
||||
* constructed == 2 for indefinite length constructed */
|
||||
void
|
||||
ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,
|
||||
int xclass)
|
||||
{
|
||||
unsigned char *p = *pp;
|
||||
int i, ttag;
|
||||
|
||||
i = (constructed) ? V_ASN1_CONSTRUCTED : 0;
|
||||
i |= (xclass & V_ASN1_PRIVATE);
|
||||
if (tag < 31)
|
||||
*(p++) = i | (tag & V_ASN1_PRIMITIVE_TAG);
|
||||
else {
|
||||
*(p++) = i | V_ASN1_PRIMITIVE_TAG;
|
||||
for(i = 0, ttag = tag; ttag > 0; i++)
|
||||
ttag >>= 7;
|
||||
ttag = i;
|
||||
while (i-- > 0) {
|
||||
p[i] = tag & 0x7f;
|
||||
if (i != (ttag - 1))
|
||||
p[i] |= 0x80;
|
||||
tag >>= 7;
|
||||
}
|
||||
p += ttag;
|
||||
}
|
||||
if (constructed == 2)
|
||||
*(p++) = 0x80;
|
||||
else
|
||||
asn1_put_length(&p, length);
|
||||
*pp = p;
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_put_eoc(unsigned char **pp)
|
||||
{
|
||||
unsigned char *p = *pp;
|
||||
|
||||
*p++ = 0;
|
||||
*p++ = 0;
|
||||
*pp = p;
|
||||
return 2;
|
||||
}
|
||||
|
||||
static void
|
||||
asn1_put_length(unsigned char **pp, int length)
|
||||
{
|
||||
unsigned char *p = *pp;
|
||||
|
||||
int i, l;
|
||||
if (length <= 127)
|
||||
*(p++) = (unsigned char)length;
|
||||
else {
|
||||
l = length;
|
||||
for (i = 0; l > 0; i++)
|
||||
l >>= 8;
|
||||
*(p++) = i | 0x80;
|
||||
l = i;
|
||||
while (i-- > 0) {
|
||||
p[i] = length & 0xff;
|
||||
length >>= 8;
|
||||
}
|
||||
p += l;
|
||||
}
|
||||
*pp = p;
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_object_size(int constructed, int length, int tag)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = length;
|
||||
ret++;
|
||||
if (tag >= 31) {
|
||||
while (tag > 0) {
|
||||
tag >>= 7;
|
||||
ret++;
|
||||
}
|
||||
}
|
||||
if (constructed == 2)
|
||||
return ret + 3;
|
||||
ret++;
|
||||
if (length > 127) {
|
||||
while (length > 0) {
|
||||
length >>= 8;
|
||||
ret++;
|
||||
}
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
384
externals/libressl/crypto/asn1/asn1_par.c
vendored
384
externals/libressl/crypto/asn1/asn1_par.c
vendored
@@ -1,384 +0,0 @@
|
||||
/* $OpenBSD: asn1_par.c,v 1.34 2022/02/12 03:07:24 jsing 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 <openssl/asn1.h>
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/objects.h>
|
||||
|
||||
static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed,
|
||||
int indent);
|
||||
static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
|
||||
int offset, int depth, int indent, int dump);
|
||||
|
||||
static int
|
||||
asn1_print_info(BIO *bp, int tag, int xclass, int constructed,
|
||||
int indent)
|
||||
{
|
||||
char str[128];
|
||||
const char *p;
|
||||
|
||||
if (constructed & V_ASN1_CONSTRUCTED)
|
||||
p="cons: ";
|
||||
else
|
||||
p="prim: ";
|
||||
if (BIO_write(bp, p, 6) < 6)
|
||||
goto err;
|
||||
if (!BIO_indent(bp, indent, 128))
|
||||
goto err;
|
||||
|
||||
p = str;
|
||||
if ((xclass & V_ASN1_PRIVATE) == V_ASN1_PRIVATE)
|
||||
snprintf(str, sizeof str, "priv [ %d ] ", tag);
|
||||
else if ((xclass & V_ASN1_CONTEXT_SPECIFIC) == V_ASN1_CONTEXT_SPECIFIC)
|
||||
snprintf(str, sizeof str, "cont [ %d ]", tag);
|
||||
else if ((xclass & V_ASN1_APPLICATION) == V_ASN1_APPLICATION)
|
||||
snprintf(str, sizeof str, "appl [ %d ]", tag);
|
||||
else if (tag > 30)
|
||||
snprintf(str, sizeof str, "<ASN1 %d>", tag);
|
||||
else
|
||||
p = ASN1_tag2str(tag);
|
||||
|
||||
if (BIO_printf(bp, "%-18s", p) <= 0)
|
||||
goto err;
|
||||
return (1);
|
||||
err:
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent)
|
||||
{
|
||||
return (asn1_parse2(bp, &pp, len, 0, 0, indent, 0));
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent, int dump)
|
||||
{
|
||||
return (asn1_parse2(bp, &pp, len, 0, 0, indent, dump));
|
||||
}
|
||||
|
||||
static int
|
||||
asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offset,
|
||||
int depth, int indent, int dump)
|
||||
{
|
||||
const unsigned char *p, *ep, *tot, *op, *opp;
|
||||
long len;
|
||||
int tag, xclass, ret = 0;
|
||||
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;
|
||||
|
||||
dump_indent = 6; /* Because we know BIO_dump_indent() */
|
||||
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);
|
||||
|
||||
if (j & 0x80) {
|
||||
if (BIO_write(bp, "Error in encoding\n", 18) <= 0)
|
||||
goto end;
|
||||
ret = 0;
|
||||
goto end;
|
||||
}
|
||||
hl = (p - op);
|
||||
length -= hl;
|
||||
/* if j == 0x21 it is a constructed indefinite length object */
|
||||
if (BIO_printf(bp, "%5ld:", (long)offset +
|
||||
(long)(op - *pp)) <= 0)
|
||||
goto end;
|
||||
|
||||
if (j != (V_ASN1_CONSTRUCTED | 1)) {
|
||||
if (BIO_printf(bp, "d=%-2d hl=%ld l=%4ld ",
|
||||
depth, (long)hl, len) <= 0)
|
||||
goto end;
|
||||
} else {
|
||||
if (BIO_printf(bp, "d=%-2d hl=%ld l=inf ",
|
||||
depth, (long)hl) <= 0)
|
||||
goto end;
|
||||
}
|
||||
if (!asn1_print_info(bp, tag, xclass, j, (indent) ? depth : 0))
|
||||
goto end;
|
||||
if (j & V_ASN1_CONSTRUCTED) {
|
||||
ep = p + len;
|
||||
if (BIO_write(bp, "\n", 1) <= 0)
|
||||
goto end;
|
||||
if (len > length) {
|
||||
BIO_printf(bp, "length is greater than %ld\n",
|
||||
length);
|
||||
ret = 0;
|
||||
goto end;
|
||||
}
|
||||
if ((j == 0x21) && (len == 0)) {
|
||||
for (;;) {
|
||||
r = asn1_parse2(bp, &p, (long)(tot - p),
|
||||
offset + (p - *pp), depth + 1,
|
||||
indent, dump);
|
||||
if (r == 0) {
|
||||
ret = 0;
|
||||
goto end;
|
||||
}
|
||||
if ((r == 2) || (p >= tot)) {
|
||||
len = (long)(p - ep);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
while (p < ep) {
|
||||
r = asn1_parse2(bp, &p, (long)(ep - p),
|
||||
offset + (p - *pp), depth + 1,
|
||||
indent, dump);
|
||||
if (r == 0) {
|
||||
ret = 0;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (xclass != 0) {
|
||||
p += len;
|
||||
if (BIO_write(bp, "\n", 1) <= 0)
|
||||
goto end;
|
||||
} else {
|
||||
nl = 0;
|
||||
if ((tag == V_ASN1_PRINTABLESTRING) ||
|
||||
(tag == V_ASN1_T61STRING) ||
|
||||
(tag == V_ASN1_IA5STRING) ||
|
||||
(tag == V_ASN1_VISIBLESTRING) ||
|
||||
(tag == V_ASN1_NUMERICSTRING) ||
|
||||
(tag == V_ASN1_UTF8STRING) ||
|
||||
(tag == V_ASN1_UTCTIME) ||
|
||||
(tag == V_ASN1_GENERALIZEDTIME)) {
|
||||
if (BIO_write(bp, ":", 1) <= 0)
|
||||
goto end;
|
||||
if ((len > 0) &&
|
||||
BIO_write(bp, (const char *)p, (int)len) !=
|
||||
(int)len)
|
||||
goto end;
|
||||
} else if (tag == V_ASN1_OBJECT) {
|
||||
opp = op;
|
||||
if (d2i_ASN1_OBJECT(&o, &opp, len + hl) !=
|
||||
NULL) {
|
||||
if (BIO_write(bp, ":", 1) <= 0)
|
||||
goto end;
|
||||
i2a_ASN1_OBJECT(bp, o);
|
||||
} else {
|
||||
if (BIO_write(bp, ":BAD OBJECT",
|
||||
11) <= 0)
|
||||
goto end;
|
||||
}
|
||||
} else if (tag == V_ASN1_BOOLEAN) {
|
||||
if (len == 1 && p < tot) {
|
||||
BIO_printf(bp, ":%u", p[0]);
|
||||
} else {
|
||||
if (BIO_write(bp, "Bad boolean\n",
|
||||
12) <= 0)
|
||||
goto end;
|
||||
}
|
||||
} else if (tag == V_ASN1_BMPSTRING) {
|
||||
/* do the BMP thang */
|
||||
} else if (tag == V_ASN1_OCTET_STRING) {
|
||||
int i, printable = 1;
|
||||
|
||||
opp = op;
|
||||
os = d2i_ASN1_OCTET_STRING(NULL, &opp, len + hl);
|
||||
if (os != NULL && os->length > 0) {
|
||||
opp = os->data;
|
||||
/* testing whether the octet string is
|
||||
* printable */
|
||||
for (i = 0; i < os->length; i++) {
|
||||
if (((opp[i] < ' ') &&
|
||||
(opp[i] != '\n') &&
|
||||
(opp[i] != '\r') &&
|
||||
(opp[i] != '\t')) ||
|
||||
(opp[i] > '~')) {
|
||||
printable = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (printable) {
|
||||
/* printable string */
|
||||
if (BIO_write(bp, ":", 1) <= 0)
|
||||
goto end;
|
||||
if (BIO_write(bp, (const char *)opp,
|
||||
os->length) <= 0)
|
||||
goto end;
|
||||
} else if (!dump) {
|
||||
/* not printable => print octet string
|
||||
* as hex dump */
|
||||
if (BIO_write(bp, "[HEX DUMP]:", 11) <= 0)
|
||||
goto end;
|
||||
for (i = 0; i < os->length; i++) {
|
||||
if (BIO_printf(bp,
|
||||
"%02X", opp[i]) <= 0)
|
||||
goto end;
|
||||
}
|
||||
} else {
|
||||
/* print the normal dump */
|
||||
if (!nl) {
|
||||
if (BIO_write(bp, "\n", 1) <= 0)
|
||||
goto end;
|
||||
}
|
||||
if (BIO_dump_indent(bp,
|
||||
(const char *)opp,
|
||||
((dump == -1 || dump >
|
||||
os->length) ? os->length : dump),
|
||||
dump_indent) <= 0)
|
||||
goto end;
|
||||
nl = 1;
|
||||
}
|
||||
}
|
||||
ASN1_OCTET_STRING_free(os);
|
||||
os = NULL;
|
||||
} else if (tag == V_ASN1_INTEGER) {
|
||||
int i;
|
||||
|
||||
opp = op;
|
||||
ai = d2i_ASN1_INTEGER(NULL, &opp, len + hl);
|
||||
if (ai != NULL) {
|
||||
if (BIO_write(bp, ":", 1) <= 0)
|
||||
goto end;
|
||||
if (ai->type == V_ASN1_NEG_INTEGER)
|
||||
if (BIO_write(bp, "-", 1) <= 0)
|
||||
goto end;
|
||||
for (i = 0; i < ai->length; i++) {
|
||||
if (BIO_printf(bp, "%02X",
|
||||
ai->data[i]) <= 0)
|
||||
goto end;
|
||||
}
|
||||
if (ai->length == 0) {
|
||||
if (BIO_write(bp, "00", 2) <= 0)
|
||||
goto end;
|
||||
}
|
||||
} else {
|
||||
if (BIO_write(bp, "BAD INTEGER", 11) <= 0)
|
||||
goto end;
|
||||
}
|
||||
ASN1_INTEGER_free(ai);
|
||||
ai = NULL;
|
||||
} else if (tag == V_ASN1_ENUMERATED) {
|
||||
int i;
|
||||
|
||||
opp = op;
|
||||
ae = d2i_ASN1_ENUMERATED(NULL, &opp, len + hl);
|
||||
if (ae != NULL) {
|
||||
if (BIO_write(bp, ":", 1) <= 0)
|
||||
goto end;
|
||||
if (ae->type == V_ASN1_NEG_ENUMERATED)
|
||||
if (BIO_write(bp, "-", 1) <= 0)
|
||||
goto end;
|
||||
for (i = 0; i < ae->length; i++) {
|
||||
if (BIO_printf(bp, "%02X",
|
||||
ae->data[i]) <= 0)
|
||||
goto end;
|
||||
}
|
||||
if (ae->length == 0) {
|
||||
if (BIO_write(bp, "00", 2) <= 0)
|
||||
goto end;
|
||||
}
|
||||
} else {
|
||||
if (BIO_write(bp, "BAD ENUMERATED", 14) <= 0)
|
||||
goto end;
|
||||
}
|
||||
ASN1_ENUMERATED_free(ae);
|
||||
ae = NULL;
|
||||
} else if (len > 0 && dump) {
|
||||
if (!nl) {
|
||||
if (BIO_write(bp, "\n", 1) <= 0)
|
||||
goto end;
|
||||
}
|
||||
if (BIO_dump_indent(bp, (const char *)p,
|
||||
((dump == -1 || dump > len) ? len : dump),
|
||||
dump_indent) <= 0)
|
||||
goto end;
|
||||
nl = 1;
|
||||
}
|
||||
|
||||
if (!nl) {
|
||||
if (BIO_write(bp, "\n", 1) <= 0)
|
||||
goto end;
|
||||
}
|
||||
p += len;
|
||||
if ((tag == V_ASN1_EOC) && (xclass == 0)) {
|
||||
ret = 2; /* End of sequence */
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
length -= len;
|
||||
}
|
||||
ret = 1;
|
||||
|
||||
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);
|
||||
}
|
||||
263
externals/libressl/crypto/asn1/asn1_types.c
vendored
263
externals/libressl/crypto/asn1/asn1_types.c
vendored
@@ -1,263 +0,0 @@
|
||||
/* $OpenBSD: asn1_types.c,v 1.1 2021/12/14 17:35:21 jsing Exp $ */
|
||||
/*
|
||||
* Copyright (c) 2021 Joel Sing <jsing@openbsd.org>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
struct asn1_type {
|
||||
const char *name;
|
||||
uint32_t bit_value;
|
||||
int char_width;
|
||||
};
|
||||
|
||||
/*
|
||||
* Universal class tag types - ITU X.680.
|
||||
*/
|
||||
static const struct asn1_type asn1_types[31] = {
|
||||
[0] = {
|
||||
/* Tag 0 (0x00) - Reserved for use by encoding rules */
|
||||
.name = "EOC",
|
||||
.bit_value = 0,
|
||||
.char_width = -1,
|
||||
},
|
||||
[1] = {
|
||||
/* Tag 1 (0x01) - Boolean */
|
||||
.name = "BOOLEAN",
|
||||
.bit_value = 0,
|
||||
.char_width = -1,
|
||||
},
|
||||
[2] = {
|
||||
/* Tag 2 (0x02) - Integer */
|
||||
.name = "INTEGER",
|
||||
.bit_value = 0,
|
||||
.char_width = -1,
|
||||
},
|
||||
[3] = {
|
||||
/* Tag 3 (0x03) - BitString */
|
||||
.name = "BIT STRING",
|
||||
.bit_value = B_ASN1_BIT_STRING,
|
||||
.char_width = -1,
|
||||
},
|
||||
[4] = {
|
||||
/* Tag 4 (0x04) - OctetString */
|
||||
.name = "OCTET STRING",
|
||||
.bit_value = B_ASN1_OCTET_STRING,
|
||||
.char_width = -1,
|
||||
},
|
||||
[5] = {
|
||||
/* Tag 5 (0x05) - Null */
|
||||
.name = "NULL",
|
||||
.bit_value = 0,
|
||||
.char_width = -1,
|
||||
},
|
||||
[6] = {
|
||||
/* Tag 6 (0x06) - Object Identifier */
|
||||
.name = "OBJECT",
|
||||
.bit_value = 0,
|
||||
.char_width = -1,
|
||||
},
|
||||
[7] = {
|
||||
/* Tag 7 (0x07) - Object Descriptor */
|
||||
.name = "OBJECT DESCRIPTOR",
|
||||
.bit_value = B_ASN1_UNKNOWN,
|
||||
.char_width = -1,
|
||||
},
|
||||
[8] = {
|
||||
/* Tag 8 (0x08) - External */
|
||||
.name = "EXTERNAL",
|
||||
.bit_value = B_ASN1_UNKNOWN,
|
||||
.char_width = -1,
|
||||
},
|
||||
[9] = {
|
||||
/* Tag 9 (0x09) - Real */
|
||||
.name = "REAL",
|
||||
.bit_value = B_ASN1_UNKNOWN,
|
||||
.char_width = -1,
|
||||
},
|
||||
[10] = {
|
||||
/* Tag 10 (0x0a) - Enumerated */
|
||||
.name = "ENUMERATED",
|
||||
.bit_value = B_ASN1_UNKNOWN,
|
||||
.char_width = -1,
|
||||
},
|
||||
[11] = {
|
||||
/* Tag 11 (0x0b) - Embedded PDV */
|
||||
.name = "<ASN1 11 EMBEDDED PDV>",
|
||||
.bit_value = B_ASN1_UNKNOWN,
|
||||
.char_width = -1,
|
||||
},
|
||||
[12] = {
|
||||
/* Tag 12 (0x0c) - UTF8String */
|
||||
.name = "UTF8STRING",
|
||||
.bit_value = B_ASN1_UTF8STRING,
|
||||
.char_width = 0,
|
||||
},
|
||||
[13] = {
|
||||
/* Tag 13 (0x0d) - Relative Object Identifier */
|
||||
.name = "<ASN1 13 RELATIVE OID>",
|
||||
.bit_value = B_ASN1_UNKNOWN,
|
||||
.char_width = -1,
|
||||
},
|
||||
[14] = {
|
||||
/* Tag 14 (0x0e) - Time */
|
||||
.name = "<ASN1 14 TIME>",
|
||||
.bit_value = B_ASN1_UNKNOWN,
|
||||
.char_width = -1,
|
||||
},
|
||||
[15] = {
|
||||
/* Tag 15 (0x0f) - Reserved */
|
||||
.name = "<ASN1 15 RESERVED>",
|
||||
.bit_value = B_ASN1_UNKNOWN,
|
||||
.char_width = -1,
|
||||
},
|
||||
[16] = {
|
||||
/* Tag 16 (0x10)- Sequence */
|
||||
.name = "SEQUENCE",
|
||||
.bit_value = B_ASN1_SEQUENCE,
|
||||
.char_width = -1,
|
||||
},
|
||||
[17] = {
|
||||
/* Tag 17 (0x11) - Set */
|
||||
.name = "SET",
|
||||
.bit_value = 0,
|
||||
.char_width = -1,
|
||||
},
|
||||
[18] = {
|
||||
/* Tag 18 (0x12) - NumericString */
|
||||
.name = "NUMERICSTRING",
|
||||
.bit_value = B_ASN1_NUMERICSTRING,
|
||||
.char_width = -1,
|
||||
},
|
||||
[19] = {
|
||||
/* Tag 19 (0x13) - PrintableString */
|
||||
.name = "PRINTABLESTRING",
|
||||
.bit_value = B_ASN1_PRINTABLESTRING,
|
||||
.char_width = 1,
|
||||
},
|
||||
[20] = {
|
||||
/* Tag 20 (0x14) - TeletexString (T61String) */
|
||||
.name = "T61STRING",
|
||||
.bit_value = B_ASN1_T61STRING,
|
||||
.char_width = 1,
|
||||
},
|
||||
[21] = {
|
||||
/* Tag 21 (0x15) - VideotexString */
|
||||
.name = "VIDEOTEXSTRING",
|
||||
.bit_value = B_ASN1_VIDEOTEXSTRING,
|
||||
.char_width = -1,
|
||||
},
|
||||
[22] = {
|
||||
/* Tag 22 (0x16) - IA5String */
|
||||
.name = "IA5STRING",
|
||||
.bit_value = B_ASN1_IA5STRING,
|
||||
.char_width = 1,
|
||||
},
|
||||
[23] = {
|
||||
/* Tag 23 (0x17) - UTCTime */
|
||||
.name = "UTCTIME",
|
||||
.bit_value = B_ASN1_UTCTIME,
|
||||
.char_width = 1,
|
||||
},
|
||||
[24] = {
|
||||
/* Tag 24 (0x18) - GeneralizedTime */
|
||||
.name = "GENERALIZEDTIME",
|
||||
.bit_value = B_ASN1_GENERALIZEDTIME,
|
||||
.char_width = 1,
|
||||
},
|
||||
[25] = {
|
||||
/* Tag 25 (0x19) - GraphicString */
|
||||
.name = "GRAPHICSTRING",
|
||||
.bit_value = B_ASN1_GRAPHICSTRING,
|
||||
.char_width = -1,
|
||||
},
|
||||
[26] = {
|
||||
/* Tag 26 (0x1a) - VisibleString (ISO646String) */
|
||||
.name = "VISIBLESTRING",
|
||||
.bit_value = B_ASN1_ISO64STRING,
|
||||
.char_width = 1,
|
||||
},
|
||||
[27] = {
|
||||
/* Tag 27 (0x1b) - GeneralString */
|
||||
.name = "GENERALSTRING",
|
||||
.bit_value = B_ASN1_GENERALSTRING,
|
||||
.char_width = -1,
|
||||
},
|
||||
[28] = {
|
||||
/* Tag 28 (0x1c) - UniversalString */
|
||||
.name = "UNIVERSALSTRING",
|
||||
.bit_value = B_ASN1_UNIVERSALSTRING,
|
||||
.char_width = 4,
|
||||
},
|
||||
[29] = {
|
||||
/* Tag 29 (0x1d) - Unallocated */
|
||||
.name = "<ASN1 29>",
|
||||
.bit_value = B_ASN1_UNKNOWN,
|
||||
.char_width = -1,
|
||||
},
|
||||
[30] = {
|
||||
/* Tag 30 (0x1e) - BMPString */
|
||||
.name = "BMPSTRING",
|
||||
.bit_value = B_ASN1_BMPSTRING,
|
||||
.char_width = 2,
|
||||
},
|
||||
};
|
||||
|
||||
static const struct asn1_type *
|
||||
asn1_type_by_tag(int tag)
|
||||
{
|
||||
if (tag < 0 || tag > 30)
|
||||
return NULL;
|
||||
|
||||
return &asn1_types[tag];
|
||||
}
|
||||
|
||||
int
|
||||
asn1_tag2charwidth(int tag)
|
||||
{
|
||||
const struct asn1_type *at;
|
||||
|
||||
if ((at = asn1_type_by_tag(tag)) != NULL)
|
||||
return at->char_width;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned long
|
||||
ASN1_tag2bit(int tag)
|
||||
{
|
||||
const struct asn1_type *at;
|
||||
|
||||
if ((at = asn1_type_by_tag(tag)) != NULL)
|
||||
return (unsigned long)at->bit_value;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *
|
||||
ASN1_tag2str(int tag)
|
||||
{
|
||||
const struct asn1_type *at;
|
||||
|
||||
if (tag == V_ASN1_NEG_INTEGER || tag == V_ASN1_NEG_ENUMERATED)
|
||||
tag &= ~V_ASN1_NEG;
|
||||
|
||||
if ((at = asn1_type_by_tag(tag)) != NULL)
|
||||
return at->name;
|
||||
|
||||
return "(unknown)";
|
||||
}
|
||||
1012
externals/libressl/crypto/asn1/asn_mime.c
vendored
1012
externals/libressl/crypto/asn1/asn_mime.c
vendored
File diff suppressed because it is too large
Load Diff
160
externals/libressl/crypto/asn1/asn_moid.c
vendored
160
externals/libressl/crypto/asn1/asn_moid.c
vendored
@@ -1,160 +0,0 @@
|
||||
/* $OpenBSD: asn_moid.c,v 1.14 2022/01/07 11:13:54 tb Exp $ */
|
||||
/* Written by Stephen Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 2001.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2001-2004 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/conf.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
#include "asn1_locl.h"
|
||||
|
||||
/* Simple ASN1 OID module: add all objects in a given section */
|
||||
|
||||
static int do_create(char *value, char *name);
|
||||
|
||||
static int
|
||||
oid_module_init(CONF_IMODULE *md, const CONF *cnf)
|
||||
{
|
||||
int i;
|
||||
const char *oid_section;
|
||||
STACK_OF(CONF_VALUE) *sktmp;
|
||||
CONF_VALUE *oval;
|
||||
|
||||
oid_section = CONF_imodule_get_value(md);
|
||||
if (!(sktmp = NCONF_get_section(cnf, oid_section))) {
|
||||
ASN1error(ASN1_R_ERROR_LOADING_SECTION);
|
||||
return 0;
|
||||
}
|
||||
for (i = 0; i < sk_CONF_VALUE_num(sktmp); i++) {
|
||||
oval = sk_CONF_VALUE_value(sktmp, i);
|
||||
if (!do_create(oval->value, oval->name)) {
|
||||
ASN1error(ASN1_R_ADDING_OBJECT);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
oid_module_finish(CONF_IMODULE *md)
|
||||
{
|
||||
OBJ_cleanup();
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_add_oid_module(void)
|
||||
{
|
||||
CONF_module_add("oid_section", oid_module_init, oid_module_finish);
|
||||
}
|
||||
|
||||
/* Create an OID based on a name value pair. Accept two formats.
|
||||
* shortname = 1.2.3.4
|
||||
* shortname = some long name, 1.2.3.4
|
||||
*/
|
||||
|
||||
static int
|
||||
do_create(char *value, char *name)
|
||||
{
|
||||
int nid;
|
||||
ASN1_OBJECT *oid;
|
||||
char *ln, *ostr, *p, *lntmp;
|
||||
|
||||
p = strrchr(value, ',');
|
||||
if (!p) {
|
||||
ln = name;
|
||||
ostr = value;
|
||||
} else {
|
||||
ln = NULL;
|
||||
ostr = p + 1;
|
||||
if (!*ostr)
|
||||
return 0;
|
||||
while (isspace((unsigned char)*ostr))
|
||||
ostr++;
|
||||
}
|
||||
|
||||
nid = OBJ_create(ostr, name, ln);
|
||||
|
||||
if (nid == NID_undef)
|
||||
return 0;
|
||||
|
||||
if (p) {
|
||||
ln = value;
|
||||
while (isspace((unsigned char)*ln))
|
||||
ln++;
|
||||
p--;
|
||||
while (isspace((unsigned char)*p)) {
|
||||
if (p == ln)
|
||||
return 0;
|
||||
p--;
|
||||
}
|
||||
p++;
|
||||
lntmp = malloc((p - ln) + 1);
|
||||
if (lntmp == NULL)
|
||||
return 0;
|
||||
memcpy(lntmp, ln, p - ln);
|
||||
lntmp[p - ln] = 0;
|
||||
oid = OBJ_nid2obj(nid);
|
||||
oid->ln = lntmp;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
485
externals/libressl/crypto/asn1/bio_asn1.c
vendored
485
externals/libressl/crypto/asn1/bio_asn1.c
vendored
@@ -1,485 +0,0 @@
|
||||
/* $OpenBSD: bio_asn1.c,v 1.17 2022/01/14 08:40:57 tb Exp $ */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2006 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
/* Experimental ASN1 BIO. When written through the data is converted
|
||||
* to an ASN1 string type: default is OCTET STRING. Additional functions
|
||||
* can be provided to add prefix and suffix data.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
#include "bio_local.h"
|
||||
|
||||
/* Must be large enough for biggest tag+length */
|
||||
#define DEFAULT_ASN1_BUF_SIZE 20
|
||||
|
||||
typedef enum {
|
||||
ASN1_STATE_START,
|
||||
ASN1_STATE_PRE_COPY,
|
||||
ASN1_STATE_HEADER,
|
||||
ASN1_STATE_HEADER_COPY,
|
||||
ASN1_STATE_DATA_COPY,
|
||||
ASN1_STATE_POST_COPY,
|
||||
ASN1_STATE_DONE
|
||||
} asn1_bio_state_t;
|
||||
|
||||
typedef struct BIO_ASN1_EX_FUNCS_st {
|
||||
asn1_ps_func *ex_func;
|
||||
asn1_ps_func *ex_free_func;
|
||||
} BIO_ASN1_EX_FUNCS;
|
||||
|
||||
typedef struct BIO_ASN1_BUF_CTX_t {
|
||||
/* Internal state */
|
||||
asn1_bio_state_t state;
|
||||
/* Internal buffer */
|
||||
unsigned char *buf;
|
||||
/* Size of buffer */
|
||||
int bufsize;
|
||||
/* Current position in buffer */
|
||||
int bufpos;
|
||||
/* Current buffer length */
|
||||
int buflen;
|
||||
/* Amount of data to copy */
|
||||
int copylen;
|
||||
/* Class and tag to use */
|
||||
int asn1_class, asn1_tag;
|
||||
asn1_ps_func *prefix, *prefix_free, *suffix, *suffix_free;
|
||||
/* Extra buffer for prefix and suffix data */
|
||||
unsigned char *ex_buf;
|
||||
int ex_len;
|
||||
int ex_pos;
|
||||
void *ex_arg;
|
||||
} BIO_ASN1_BUF_CTX;
|
||||
|
||||
|
||||
static int asn1_bio_write(BIO *h, const char *buf, int num);
|
||||
static int asn1_bio_read(BIO *h, char *buf, int size);
|
||||
static int asn1_bio_puts(BIO *h, const char *str);
|
||||
static int asn1_bio_gets(BIO *h, char *str, int size);
|
||||
static long asn1_bio_ctrl(BIO *h, int cmd, long arg1, void *arg2);
|
||||
static int asn1_bio_new(BIO *h);
|
||||
static int asn1_bio_free(BIO *data);
|
||||
static long asn1_bio_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp);
|
||||
|
||||
static int asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx,
|
||||
asn1_ps_func *cleanup, asn1_bio_state_t next);
|
||||
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 const BIO_METHOD methods_asn1 = {
|
||||
.type = BIO_TYPE_ASN1,
|
||||
.name = "asn1",
|
||||
.bwrite = asn1_bio_write,
|
||||
.bread = asn1_bio_read,
|
||||
.bputs = asn1_bio_puts,
|
||||
.bgets = asn1_bio_gets,
|
||||
.ctrl = asn1_bio_ctrl,
|
||||
.create = asn1_bio_new,
|
||||
.destroy = asn1_bio_free,
|
||||
.callback_ctrl = asn1_bio_callback_ctrl
|
||||
};
|
||||
|
||||
const BIO_METHOD *
|
||||
BIO_f_asn1(void)
|
||||
{
|
||||
return (&methods_asn1);
|
||||
}
|
||||
|
||||
static int
|
||||
asn1_bio_new(BIO *b)
|
||||
{
|
||||
BIO_ASN1_BUF_CTX *ctx;
|
||||
|
||||
if ((ctx = calloc(1, sizeof(*ctx))) == NULL)
|
||||
return 0;
|
||||
|
||||
if ((ctx->buf = malloc(DEFAULT_ASN1_BUF_SIZE)) == NULL) {
|
||||
free(ctx);
|
||||
return 0;
|
||||
}
|
||||
ctx->bufsize = DEFAULT_ASN1_BUF_SIZE;
|
||||
ctx->asn1_class = V_ASN1_UNIVERSAL;
|
||||
ctx->asn1_tag = V_ASN1_OCTET_STRING;
|
||||
ctx->state = ASN1_STATE_START;
|
||||
|
||||
b->init = 1;
|
||||
b->ptr = (char *)ctx;
|
||||
b->flags = 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
asn1_bio_free(BIO *b)
|
||||
{
|
||||
BIO_ASN1_BUF_CTX *ctx;
|
||||
|
||||
ctx = (BIO_ASN1_BUF_CTX *) b->ptr;
|
||||
if (ctx == NULL)
|
||||
return 0;
|
||||
free(ctx->buf);
|
||||
free(ctx);
|
||||
b->init = 0;
|
||||
b->ptr = NULL;
|
||||
b->flags = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
asn1_bio_write(BIO *b, const char *in , int inl)
|
||||
{
|
||||
BIO_ASN1_BUF_CTX *ctx;
|
||||
int wrmax, wrlen, ret, buflen;
|
||||
unsigned char *p;
|
||||
|
||||
if (!in || (inl < 0) || (b->next_bio == NULL))
|
||||
return 0;
|
||||
ctx = (BIO_ASN1_BUF_CTX *) b->ptr;
|
||||
if (ctx == NULL)
|
||||
return 0;
|
||||
|
||||
wrlen = 0;
|
||||
ret = -1;
|
||||
|
||||
for (;;) {
|
||||
switch (ctx->state) {
|
||||
|
||||
/* Setup prefix data, call it */
|
||||
case ASN1_STATE_START:
|
||||
if (!asn1_bio_setup_ex(b, ctx, ctx->prefix,
|
||||
ASN1_STATE_PRE_COPY, ASN1_STATE_HEADER))
|
||||
return 0;
|
||||
break;
|
||||
|
||||
/* Copy any pre data first */
|
||||
case ASN1_STATE_PRE_COPY:
|
||||
ret = asn1_bio_flush_ex(b, ctx, ctx->prefix_free,
|
||||
ASN1_STATE_HEADER);
|
||||
if (ret <= 0)
|
||||
goto done;
|
||||
break;
|
||||
|
||||
case ASN1_STATE_HEADER:
|
||||
buflen = ASN1_object_size(0, inl, ctx->asn1_tag) - inl;
|
||||
if (buflen <= 0 || buflen > ctx->bufsize)
|
||||
return -1;
|
||||
ctx->buflen = buflen;
|
||||
p = ctx->buf;
|
||||
ASN1_put_object(&p, 0, inl,
|
||||
ctx->asn1_tag, ctx->asn1_class);
|
||||
ctx->copylen = inl;
|
||||
ctx->state = ASN1_STATE_HEADER_COPY;
|
||||
break;
|
||||
|
||||
case ASN1_STATE_HEADER_COPY:
|
||||
ret = BIO_write(b->next_bio,
|
||||
ctx->buf + ctx->bufpos, ctx->buflen);
|
||||
if (ret <= 0)
|
||||
goto done;
|
||||
|
||||
ctx->buflen -= ret;
|
||||
if (ctx->buflen)
|
||||
ctx->bufpos += ret;
|
||||
else {
|
||||
ctx->bufpos = 0;
|
||||
ctx->state = ASN1_STATE_DATA_COPY;
|
||||
}
|
||||
break;
|
||||
|
||||
case ASN1_STATE_DATA_COPY:
|
||||
|
||||
if (inl > ctx->copylen)
|
||||
wrmax = ctx->copylen;
|
||||
else
|
||||
wrmax = inl;
|
||||
ret = BIO_write(b->next_bio, in, wrmax);
|
||||
if (ret <= 0)
|
||||
break;
|
||||
wrlen += ret;
|
||||
ctx->copylen -= ret;
|
||||
in += ret;
|
||||
inl -= ret;
|
||||
|
||||
if (ctx->copylen == 0)
|
||||
ctx->state = ASN1_STATE_HEADER;
|
||||
if (inl == 0)
|
||||
goto done;
|
||||
break;
|
||||
|
||||
default:
|
||||
BIO_clear_retry_flags(b);
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
done:
|
||||
BIO_clear_retry_flags(b);
|
||||
BIO_copy_next_retry(b);
|
||||
|
||||
return (wrlen > 0) ? wrlen : ret;
|
||||
}
|
||||
|
||||
static int
|
||||
asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, asn1_ps_func *cleanup,
|
||||
asn1_bio_state_t next)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (ctx->ex_len <= 0)
|
||||
return 1;
|
||||
for (;;) {
|
||||
ret = BIO_write(b->next_bio, ctx->ex_buf + ctx->ex_pos,
|
||||
ctx->ex_len);
|
||||
if (ret <= 0)
|
||||
break;
|
||||
ctx->ex_len -= ret;
|
||||
if (ctx->ex_len > 0)
|
||||
ctx->ex_pos += ret;
|
||||
else {
|
||||
if (cleanup)
|
||||
cleanup(b, &ctx->ex_buf, &ctx->ex_len,
|
||||
&ctx->ex_arg);
|
||||
ctx->state = next;
|
||||
ctx->ex_pos = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (setup && !setup(b, &ctx->ex_buf, &ctx->ex_len, &ctx->ex_arg)) {
|
||||
BIO_clear_retry_flags(b);
|
||||
return 0;
|
||||
}
|
||||
if (ctx->ex_len > 0)
|
||||
ctx->state = ex_state;
|
||||
else
|
||||
ctx->state = other_state;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
asn1_bio_read(BIO *b, char *in , int inl)
|
||||
{
|
||||
if (!b->next_bio)
|
||||
return 0;
|
||||
return BIO_read(b->next_bio, in , inl);
|
||||
}
|
||||
|
||||
static int
|
||||
asn1_bio_puts(BIO *b, const char *str)
|
||||
{
|
||||
return asn1_bio_write(b, str, strlen(str));
|
||||
}
|
||||
|
||||
static int
|
||||
asn1_bio_gets(BIO *b, char *str, int size)
|
||||
{
|
||||
if (!b->next_bio)
|
||||
return 0;
|
||||
return BIO_gets(b->next_bio, str , size);
|
||||
}
|
||||
|
||||
static long
|
||||
asn1_bio_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)
|
||||
{
|
||||
if (b->next_bio == NULL)
|
||||
return (0);
|
||||
return BIO_callback_ctrl(b->next_bio, cmd, fp);
|
||||
}
|
||||
|
||||
static long
|
||||
asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2)
|
||||
{
|
||||
BIO_ASN1_BUF_CTX *ctx;
|
||||
BIO_ASN1_EX_FUNCS *ex_func;
|
||||
long ret = 1;
|
||||
|
||||
ctx = (BIO_ASN1_BUF_CTX *) b->ptr;
|
||||
if (ctx == NULL)
|
||||
return 0;
|
||||
switch (cmd) {
|
||||
|
||||
case BIO_C_SET_PREFIX:
|
||||
ex_func = arg2;
|
||||
ctx->prefix = ex_func->ex_func;
|
||||
ctx->prefix_free = ex_func->ex_free_func;
|
||||
break;
|
||||
|
||||
case BIO_C_GET_PREFIX:
|
||||
ex_func = arg2;
|
||||
ex_func->ex_func = ctx->prefix;
|
||||
ex_func->ex_free_func = ctx->prefix_free;
|
||||
break;
|
||||
|
||||
case BIO_C_SET_SUFFIX:
|
||||
ex_func = arg2;
|
||||
ctx->suffix = ex_func->ex_func;
|
||||
ctx->suffix_free = ex_func->ex_free_func;
|
||||
break;
|
||||
|
||||
case BIO_C_GET_SUFFIX:
|
||||
ex_func = arg2;
|
||||
ex_func->ex_func = ctx->suffix;
|
||||
ex_func->ex_free_func = ctx->suffix_free;
|
||||
break;
|
||||
|
||||
case BIO_C_SET_EX_ARG:
|
||||
ctx->ex_arg = arg2;
|
||||
break;
|
||||
|
||||
case BIO_C_GET_EX_ARG:
|
||||
*(void **)arg2 = ctx->ex_arg;
|
||||
break;
|
||||
|
||||
case BIO_CTRL_FLUSH:
|
||||
if (!b->next_bio)
|
||||
return 0;
|
||||
|
||||
/* Call post function if possible */
|
||||
if (ctx->state == ASN1_STATE_HEADER) {
|
||||
if (!asn1_bio_setup_ex(b, ctx, ctx->suffix,
|
||||
ASN1_STATE_POST_COPY, ASN1_STATE_DONE))
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ctx->state == ASN1_STATE_POST_COPY) {
|
||||
ret = asn1_bio_flush_ex(b, ctx, ctx->suffix_free,
|
||||
ASN1_STATE_DONE);
|
||||
if (ret <= 0)
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (ctx->state == ASN1_STATE_DONE)
|
||||
return BIO_ctrl(b->next_bio, cmd, arg1, arg2);
|
||||
else {
|
||||
BIO_clear_retry_flags(b);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
if (!b->next_bio)
|
||||
return 0;
|
||||
return BIO_ctrl(b->next_bio, cmd, arg1, arg2);
|
||||
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
asn1_bio_set_ex(BIO *b, int cmd, asn1_ps_func *ex_func, asn1_ps_func
|
||||
*ex_free_func)
|
||||
{
|
||||
BIO_ASN1_EX_FUNCS extmp;
|
||||
|
||||
extmp.ex_func = ex_func;
|
||||
extmp.ex_free_func = ex_free_func;
|
||||
return BIO_ctrl(b, cmd, 0, &extmp);
|
||||
}
|
||||
|
||||
static int
|
||||
asn1_bio_get_ex(BIO *b, int cmd, asn1_ps_func **ex_func,
|
||||
asn1_ps_func **ex_free_func)
|
||||
{
|
||||
BIO_ASN1_EX_FUNCS extmp;
|
||||
int ret;
|
||||
|
||||
ret = BIO_ctrl(b, cmd, 0, &extmp);
|
||||
if (ret > 0) {
|
||||
*ex_func = extmp.ex_func;
|
||||
*ex_free_func = extmp.ex_free_func;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, asn1_ps_func *prefix_free)
|
||||
{
|
||||
return asn1_bio_set_ex(b, BIO_C_SET_PREFIX, prefix, prefix_free);
|
||||
}
|
||||
|
||||
int
|
||||
BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix, asn1_ps_func **pprefix_free)
|
||||
{
|
||||
return asn1_bio_get_ex(b, BIO_C_GET_PREFIX, pprefix, pprefix_free);
|
||||
}
|
||||
|
||||
int
|
||||
BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, asn1_ps_func *suffix_free)
|
||||
{
|
||||
return asn1_bio_set_ex(b, BIO_C_SET_SUFFIX, suffix, suffix_free);
|
||||
}
|
||||
|
||||
int
|
||||
BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix, asn1_ps_func **psuffix_free)
|
||||
{
|
||||
return asn1_bio_get_ex(b, BIO_C_GET_SUFFIX, psuffix, psuffix_free);
|
||||
}
|
||||
243
externals/libressl/crypto/asn1/bio_ndef.c
vendored
243
externals/libressl/crypto/asn1/bio_ndef.c
vendored
@@ -1,243 +0,0 @@
|
||||
/* $OpenBSD: bio_ndef.c,v 1.11 2021/12/25 13:17:48 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/asn1.h>
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* Experimental NDEF ASN1 BIO support routines */
|
||||
|
||||
/* The usage is quite simple, initialize an ASN1 structure,
|
||||
* get a BIO from it then any data written through the BIO
|
||||
* will end up translated to approptiate format on the fly.
|
||||
* The data is streamed out and does *not* need to be
|
||||
* all held in memory at once.
|
||||
*
|
||||
* When the BIO is flushed the output is finalized and any
|
||||
* signatures etc written out.
|
||||
*
|
||||
* The BIO is a 'proper' BIO and can handle non blocking I/O
|
||||
* correctly.
|
||||
*
|
||||
* The usage is simple. The implementation is *not*...
|
||||
*/
|
||||
|
||||
/* BIO support data stored in the ASN1 BIO ex_arg */
|
||||
|
||||
typedef struct ndef_aux_st {
|
||||
/* ASN1 structure this BIO refers to */
|
||||
ASN1_VALUE *val;
|
||||
const ASN1_ITEM *it;
|
||||
/* Top of the BIO chain */
|
||||
BIO *ndef_bio;
|
||||
/* Output BIO */
|
||||
BIO *out;
|
||||
/* Boundary where content is inserted */
|
||||
unsigned char **boundary;
|
||||
/* DER buffer start */
|
||||
unsigned char *derbuf;
|
||||
} NDEF_SUPPORT;
|
||||
|
||||
static int ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg);
|
||||
static int ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg);
|
||||
static int ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg);
|
||||
static int ndef_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg);
|
||||
|
||||
BIO *
|
||||
BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it)
|
||||
{
|
||||
NDEF_SUPPORT *ndef_aux = NULL;
|
||||
BIO *asn_bio = NULL;
|
||||
const ASN1_AUX *aux = it->funcs;
|
||||
ASN1_STREAM_ARG sarg;
|
||||
|
||||
if (!aux || !aux->asn1_cb) {
|
||||
ASN1error(ASN1_R_STREAMING_NOT_SUPPORTED);
|
||||
return NULL;
|
||||
}
|
||||
ndef_aux = malloc(sizeof(NDEF_SUPPORT));
|
||||
asn_bio = BIO_new(BIO_f_asn1());
|
||||
|
||||
/* ASN1 bio needs to be next to output BIO */
|
||||
|
||||
out = BIO_push(asn_bio, out);
|
||||
|
||||
if (!ndef_aux || !asn_bio || !out)
|
||||
goto err;
|
||||
|
||||
BIO_asn1_set_prefix(asn_bio, ndef_prefix, ndef_prefix_free);
|
||||
BIO_asn1_set_suffix(asn_bio, ndef_suffix, ndef_suffix_free);
|
||||
|
||||
/* Now let callback prepend any digest, cipher etc BIOs
|
||||
* ASN1 structure needs.
|
||||
*/
|
||||
|
||||
sarg.out = out;
|
||||
sarg.ndef_bio = NULL;
|
||||
sarg.boundary = NULL;
|
||||
|
||||
if (aux->asn1_cb(ASN1_OP_STREAM_PRE, &val, it, &sarg) <= 0)
|
||||
goto err;
|
||||
|
||||
ndef_aux->val = val;
|
||||
ndef_aux->it = it;
|
||||
ndef_aux->ndef_bio = sarg.ndef_bio;
|
||||
ndef_aux->boundary = sarg.boundary;
|
||||
ndef_aux->out = out;
|
||||
|
||||
BIO_ctrl(asn_bio, BIO_C_SET_EX_ARG, 0, ndef_aux);
|
||||
|
||||
return sarg.ndef_bio;
|
||||
|
||||
err:
|
||||
BIO_free(asn_bio);
|
||||
free(ndef_aux);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
|
||||
{
|
||||
NDEF_SUPPORT *ndef_aux;
|
||||
unsigned char *p;
|
||||
int derlen;
|
||||
|
||||
if (!parg)
|
||||
return 0;
|
||||
|
||||
ndef_aux = *(NDEF_SUPPORT **)parg;
|
||||
|
||||
derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it);
|
||||
p = malloc(derlen);
|
||||
ndef_aux->derbuf = p;
|
||||
*pbuf = p;
|
||||
derlen = ASN1_item_ndef_i2d(ndef_aux->val, &p, ndef_aux->it);
|
||||
|
||||
if (!*ndef_aux->boundary)
|
||||
return 0;
|
||||
|
||||
*plen = *ndef_aux->boundary - *pbuf;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg)
|
||||
{
|
||||
NDEF_SUPPORT *ndef_aux;
|
||||
|
||||
if (!parg)
|
||||
return 0;
|
||||
|
||||
ndef_aux = *(NDEF_SUPPORT **)parg;
|
||||
|
||||
free(ndef_aux->derbuf);
|
||||
|
||||
ndef_aux->derbuf = NULL;
|
||||
*pbuf = NULL;
|
||||
*plen = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
ndef_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg)
|
||||
{
|
||||
NDEF_SUPPORT **pndef_aux = (NDEF_SUPPORT **)parg;
|
||||
if (!ndef_prefix_free(b, pbuf, plen, parg))
|
||||
return 0;
|
||||
free(*pndef_aux);
|
||||
*pndef_aux = NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
|
||||
{
|
||||
NDEF_SUPPORT *ndef_aux;
|
||||
unsigned char *p;
|
||||
int derlen;
|
||||
const ASN1_AUX *aux;
|
||||
ASN1_STREAM_ARG sarg;
|
||||
|
||||
if (!parg)
|
||||
return 0;
|
||||
|
||||
ndef_aux = *(NDEF_SUPPORT **)parg;
|
||||
|
||||
aux = ndef_aux->it->funcs;
|
||||
|
||||
/* Finalize structures */
|
||||
sarg.ndef_bio = ndef_aux->ndef_bio;
|
||||
sarg.out = ndef_aux->out;
|
||||
sarg.boundary = ndef_aux->boundary;
|
||||
if (aux->asn1_cb(ASN1_OP_STREAM_POST,
|
||||
&ndef_aux->val, ndef_aux->it, &sarg) <= 0)
|
||||
return 0;
|
||||
|
||||
derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it);
|
||||
p = malloc(derlen);
|
||||
ndef_aux->derbuf = p;
|
||||
*pbuf = p;
|
||||
derlen = ASN1_item_ndef_i2d(ndef_aux->val, &p, ndef_aux->it);
|
||||
|
||||
if (!*ndef_aux->boundary)
|
||||
return 0;
|
||||
*pbuf = *ndef_aux->boundary;
|
||||
*plen = derlen - (*ndef_aux->boundary - ndef_aux->derbuf);
|
||||
|
||||
return 1;
|
||||
}
|
||||
19
externals/libressl/crypto/asn1/charmap.h
vendored
19
externals/libressl/crypto/asn1/charmap.h
vendored
@@ -1,19 +0,0 @@
|
||||
/* $OpenBSD: charmap.h,v 1.5 2016/12/21 15:49:29 jsing Exp $ */
|
||||
/* Auto generated with chartype.pl script.
|
||||
* Mask of various character properties
|
||||
*/
|
||||
|
||||
__BEGIN_HIDDEN_DECLS
|
||||
|
||||
static const unsigned char char_type[] = {
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
120, 0, 1, 40, 0, 0, 0, 16, 16, 16, 0, 25, 25, 16, 16, 16,
|
||||
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 9, 9, 16, 9, 16,
|
||||
0, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
||||
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 0, 1, 0, 0, 0,
|
||||
0, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
||||
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 0, 0, 0, 0, 2
|
||||
};
|
||||
|
||||
__END_HIDDEN_DECLS
|
||||
129
externals/libressl/crypto/asn1/nsseq.c
vendored
129
externals/libressl/crypto/asn1/nsseq.c
vendored
@@ -1,129 +0,0 @@
|
||||
/* $OpenBSD: nsseq.c,v 1.10 2015/02/11 04:00:39 jsing Exp $ */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 1999.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999-2005 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/objects.h>
|
||||
|
||||
static int
|
||||
nsseq_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
|
||||
{
|
||||
if (operation == ASN1_OP_NEW_POST) {
|
||||
NETSCAPE_CERT_SEQUENCE *nsseq;
|
||||
nsseq = (NETSCAPE_CERT_SEQUENCE *)*pval;
|
||||
nsseq->type = OBJ_nid2obj(NID_netscape_cert_sequence);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Netscape certificate sequence structure */
|
||||
|
||||
static const ASN1_AUX NETSCAPE_CERT_SEQUENCE_aux = {
|
||||
.asn1_cb = nsseq_cb,
|
||||
};
|
||||
static const ASN1_TEMPLATE NETSCAPE_CERT_SEQUENCE_seq_tt[] = {
|
||||
{
|
||||
.offset = offsetof(NETSCAPE_CERT_SEQUENCE, type),
|
||||
.field_name = "type",
|
||||
.item = &ASN1_OBJECT_it,
|
||||
},
|
||||
{
|
||||
.flags = ASN1_TFLG_EXPLICIT | ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_OPTIONAL,
|
||||
.offset = offsetof(NETSCAPE_CERT_SEQUENCE, certs),
|
||||
.field_name = "certs",
|
||||
.item = &X509_it,
|
||||
},
|
||||
};
|
||||
|
||||
const ASN1_ITEM NETSCAPE_CERT_SEQUENCE_it = {
|
||||
.itype = ASN1_ITYPE_SEQUENCE,
|
||||
.utype = V_ASN1_SEQUENCE,
|
||||
.templates = NETSCAPE_CERT_SEQUENCE_seq_tt,
|
||||
.tcount = sizeof(NETSCAPE_CERT_SEQUENCE_seq_tt) / sizeof(ASN1_TEMPLATE),
|
||||
.funcs = &NETSCAPE_CERT_SEQUENCE_aux,
|
||||
.size = sizeof(NETSCAPE_CERT_SEQUENCE),
|
||||
.sname = "NETSCAPE_CERT_SEQUENCE",
|
||||
};
|
||||
|
||||
|
||||
NETSCAPE_CERT_SEQUENCE *
|
||||
d2i_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (NETSCAPE_CERT_SEQUENCE *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&NETSCAPE_CERT_SEQUENCE_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &NETSCAPE_CERT_SEQUENCE_it);
|
||||
}
|
||||
|
||||
NETSCAPE_CERT_SEQUENCE *
|
||||
NETSCAPE_CERT_SEQUENCE_new(void)
|
||||
{
|
||||
return (NETSCAPE_CERT_SEQUENCE *)ASN1_item_new(&NETSCAPE_CERT_SEQUENCE_it);
|
||||
}
|
||||
|
||||
void
|
||||
NETSCAPE_CERT_SEQUENCE_free(NETSCAPE_CERT_SEQUENCE *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &NETSCAPE_CERT_SEQUENCE_it);
|
||||
}
|
||||
186
externals/libressl/crypto/asn1/p5_pbe.c
vendored
186
externals/libressl/crypto/asn1/p5_pbe.c
vendored
@@ -1,186 +0,0 @@
|
||||
/* $OpenBSD: p5_pbe.c,v 1.23 2021/12/25 13:17:48 jsing Exp $ */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 1999.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
/* PKCS#5 password based encryption structure */
|
||||
|
||||
static const ASN1_TEMPLATE PBEPARAM_seq_tt[] = {
|
||||
{
|
||||
.offset = offsetof(PBEPARAM, salt),
|
||||
.field_name = "salt",
|
||||
.item = &ASN1_OCTET_STRING_it,
|
||||
},
|
||||
{
|
||||
.offset = offsetof(PBEPARAM, iter),
|
||||
.field_name = "iter",
|
||||
.item = &ASN1_INTEGER_it,
|
||||
},
|
||||
};
|
||||
|
||||
const ASN1_ITEM PBEPARAM_it = {
|
||||
.itype = ASN1_ITYPE_SEQUENCE,
|
||||
.utype = V_ASN1_SEQUENCE,
|
||||
.templates = PBEPARAM_seq_tt,
|
||||
.tcount = sizeof(PBEPARAM_seq_tt) / sizeof(ASN1_TEMPLATE),
|
||||
.size = sizeof(PBEPARAM),
|
||||
.sname = "PBEPARAM",
|
||||
};
|
||||
|
||||
|
||||
PBEPARAM *
|
||||
d2i_PBEPARAM(PBEPARAM **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (PBEPARAM *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&PBEPARAM_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_PBEPARAM(PBEPARAM *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &PBEPARAM_it);
|
||||
}
|
||||
|
||||
PBEPARAM *
|
||||
PBEPARAM_new(void)
|
||||
{
|
||||
return (PBEPARAM *)ASN1_item_new(&PBEPARAM_it);
|
||||
}
|
||||
|
||||
void
|
||||
PBEPARAM_free(PBEPARAM *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &PBEPARAM_it);
|
||||
}
|
||||
|
||||
|
||||
/* Set an algorithm identifier for a PKCS#5 PBE algorithm */
|
||||
|
||||
int
|
||||
PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter,
|
||||
const unsigned char *salt, int saltlen)
|
||||
{
|
||||
PBEPARAM *pbe = NULL;
|
||||
ASN1_STRING *pbe_str = NULL;
|
||||
unsigned char *sstr;
|
||||
|
||||
pbe = PBEPARAM_new();
|
||||
if (!pbe) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
if (iter <= 0)
|
||||
iter = PKCS5_DEFAULT_ITER;
|
||||
if (!ASN1_INTEGER_set(pbe->iter, iter)) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
if (!saltlen)
|
||||
saltlen = PKCS5_SALT_LEN;
|
||||
if (!ASN1_STRING_set(pbe->salt, NULL, saltlen)) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
sstr = ASN1_STRING_data(pbe->salt);
|
||||
if (salt)
|
||||
memcpy(sstr, salt, saltlen);
|
||||
else
|
||||
arc4random_buf(sstr, saltlen);
|
||||
|
||||
if (!ASN1_item_pack(pbe, &PBEPARAM_it, &pbe_str)) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
PBEPARAM_free(pbe);
|
||||
pbe = NULL;
|
||||
|
||||
if (X509_ALGOR_set0(algor, OBJ_nid2obj(alg), V_ASN1_SEQUENCE, pbe_str))
|
||||
return 1;
|
||||
|
||||
err:
|
||||
if (pbe != NULL)
|
||||
PBEPARAM_free(pbe);
|
||||
ASN1_STRING_free(pbe_str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Return an algorithm identifier for a PKCS#5 PBE algorithm */
|
||||
|
||||
X509_ALGOR *
|
||||
PKCS5_pbe_set(int alg, int iter, const unsigned char *salt, int saltlen)
|
||||
{
|
||||
X509_ALGOR *ret;
|
||||
ret = X509_ALGOR_new();
|
||||
if (!ret) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (PKCS5_pbe_set0_algor(ret, alg, iter, salt, saltlen))
|
||||
return ret;
|
||||
|
||||
X509_ALGOR_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
374
externals/libressl/crypto/asn1/p5_pbev2.c
vendored
374
externals/libressl/crypto/asn1/p5_pbev2.c
vendored
@@ -1,374 +0,0 @@
|
||||
/* $OpenBSD: p5_pbev2.c,v 1.27 2021/12/25 13:17:48 jsing Exp $ */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 1999-2004.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
#include "evp_locl.h"
|
||||
|
||||
/* PKCS#5 v2.0 password based encryption structures */
|
||||
|
||||
static const ASN1_TEMPLATE PBE2PARAM_seq_tt[] = {
|
||||
{
|
||||
.offset = offsetof(PBE2PARAM, keyfunc),
|
||||
.field_name = "keyfunc",
|
||||
.item = &X509_ALGOR_it,
|
||||
},
|
||||
{
|
||||
.offset = offsetof(PBE2PARAM, encryption),
|
||||
.field_name = "encryption",
|
||||
.item = &X509_ALGOR_it,
|
||||
},
|
||||
};
|
||||
|
||||
const ASN1_ITEM PBE2PARAM_it = {
|
||||
.itype = ASN1_ITYPE_SEQUENCE,
|
||||
.utype = V_ASN1_SEQUENCE,
|
||||
.templates = PBE2PARAM_seq_tt,
|
||||
.tcount = sizeof(PBE2PARAM_seq_tt) / sizeof(ASN1_TEMPLATE),
|
||||
.size = sizeof(PBE2PARAM),
|
||||
.sname = "PBE2PARAM",
|
||||
};
|
||||
|
||||
|
||||
PBE2PARAM *
|
||||
d2i_PBE2PARAM(PBE2PARAM **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (PBE2PARAM *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&PBE2PARAM_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_PBE2PARAM(PBE2PARAM *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &PBE2PARAM_it);
|
||||
}
|
||||
|
||||
PBE2PARAM *
|
||||
PBE2PARAM_new(void)
|
||||
{
|
||||
return (PBE2PARAM *)ASN1_item_new(&PBE2PARAM_it);
|
||||
}
|
||||
|
||||
void
|
||||
PBE2PARAM_free(PBE2PARAM *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &PBE2PARAM_it);
|
||||
}
|
||||
|
||||
static const ASN1_TEMPLATE PBKDF2PARAM_seq_tt[] = {
|
||||
{
|
||||
.offset = offsetof(PBKDF2PARAM, salt),
|
||||
.field_name = "salt",
|
||||
.item = &ASN1_ANY_it,
|
||||
},
|
||||
{
|
||||
.offset = offsetof(PBKDF2PARAM, iter),
|
||||
.field_name = "iter",
|
||||
.item = &ASN1_INTEGER_it,
|
||||
},
|
||||
{
|
||||
.flags = ASN1_TFLG_OPTIONAL,
|
||||
.offset = offsetof(PBKDF2PARAM, keylength),
|
||||
.field_name = "keylength",
|
||||
.item = &ASN1_INTEGER_it,
|
||||
},
|
||||
{
|
||||
.flags = ASN1_TFLG_OPTIONAL,
|
||||
.offset = offsetof(PBKDF2PARAM, prf),
|
||||
.field_name = "prf",
|
||||
.item = &X509_ALGOR_it,
|
||||
},
|
||||
};
|
||||
|
||||
const ASN1_ITEM PBKDF2PARAM_it = {
|
||||
.itype = ASN1_ITYPE_SEQUENCE,
|
||||
.utype = V_ASN1_SEQUENCE,
|
||||
.templates = PBKDF2PARAM_seq_tt,
|
||||
.tcount = sizeof(PBKDF2PARAM_seq_tt) / sizeof(ASN1_TEMPLATE),
|
||||
.size = sizeof(PBKDF2PARAM),
|
||||
.sname = "PBKDF2PARAM",
|
||||
};
|
||||
|
||||
|
||||
PBKDF2PARAM *
|
||||
d2i_PBKDF2PARAM(PBKDF2PARAM **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (PBKDF2PARAM *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&PBKDF2PARAM_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_PBKDF2PARAM(PBKDF2PARAM *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &PBKDF2PARAM_it);
|
||||
}
|
||||
|
||||
PBKDF2PARAM *
|
||||
PBKDF2PARAM_new(void)
|
||||
{
|
||||
return (PBKDF2PARAM *)ASN1_item_new(&PBKDF2PARAM_it);
|
||||
}
|
||||
|
||||
void
|
||||
PBKDF2PARAM_free(PBKDF2PARAM *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &PBKDF2PARAM_it);
|
||||
}
|
||||
|
||||
/* Return an algorithm identifier for a PKCS#5 v2.0 PBE algorithm:
|
||||
* yes I know this is horrible!
|
||||
*
|
||||
* Extended version to allow application supplied PRF NID and IV.
|
||||
*/
|
||||
|
||||
X509_ALGOR *
|
||||
PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter, unsigned char *salt,
|
||||
int saltlen, unsigned char *aiv, int prf_nid)
|
||||
{
|
||||
X509_ALGOR *scheme = NULL, *kalg = NULL, *ret = NULL;
|
||||
int alg_nid, keylen;
|
||||
EVP_CIPHER_CTX ctx;
|
||||
unsigned char iv[EVP_MAX_IV_LENGTH];
|
||||
PBE2PARAM *pbe2 = NULL;
|
||||
ASN1_OBJECT *obj;
|
||||
|
||||
alg_nid = EVP_CIPHER_type(cipher);
|
||||
if (alg_nid == NID_undef) {
|
||||
ASN1error(ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER);
|
||||
goto err;
|
||||
}
|
||||
obj = OBJ_nid2obj(alg_nid);
|
||||
|
||||
if (!(pbe2 = PBE2PARAM_new()))
|
||||
goto merr;
|
||||
|
||||
/* Setup the AlgorithmIdentifier for the encryption scheme */
|
||||
scheme = pbe2->encryption;
|
||||
|
||||
scheme->algorithm = obj;
|
||||
if (!(scheme->parameter = ASN1_TYPE_new()))
|
||||
goto merr;
|
||||
|
||||
/* Create random IV */
|
||||
if (EVP_CIPHER_iv_length(cipher)) {
|
||||
if (aiv)
|
||||
memcpy(iv, aiv, EVP_CIPHER_iv_length(cipher));
|
||||
else
|
||||
arc4random_buf(iv, EVP_CIPHER_iv_length(cipher));
|
||||
}
|
||||
|
||||
EVP_CIPHER_CTX_init(&ctx);
|
||||
|
||||
/* Dummy cipherinit to just setup the IV, and PRF */
|
||||
if (!EVP_CipherInit_ex(&ctx, cipher, NULL, NULL, iv, 0))
|
||||
goto err;
|
||||
if (EVP_CIPHER_param_to_asn1(&ctx, scheme->parameter) < 0) {
|
||||
ASN1error(ASN1_R_ERROR_SETTING_CIPHER_PARAMS);
|
||||
EVP_CIPHER_CTX_cleanup(&ctx);
|
||||
goto err;
|
||||
}
|
||||
/* If prf NID unspecified see if cipher has a preference.
|
||||
* An error is OK here: just means use default PRF.
|
||||
*/
|
||||
if ((prf_nid == -1) &&
|
||||
EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_PBE_PRF_NID, 0, &prf_nid) <= 0) {
|
||||
ERR_clear_error();
|
||||
prf_nid = NID_hmacWithSHA1;
|
||||
}
|
||||
EVP_CIPHER_CTX_cleanup(&ctx);
|
||||
|
||||
/* If its RC2 then we'd better setup the key length */
|
||||
|
||||
if (alg_nid == NID_rc2_cbc)
|
||||
keylen = EVP_CIPHER_key_length(cipher);
|
||||
else
|
||||
keylen = -1;
|
||||
|
||||
/* Setup keyfunc */
|
||||
|
||||
X509_ALGOR_free(pbe2->keyfunc);
|
||||
|
||||
pbe2->keyfunc = PKCS5_pbkdf2_set(iter, salt, saltlen, prf_nid, keylen);
|
||||
|
||||
if (!pbe2->keyfunc)
|
||||
goto merr;
|
||||
|
||||
/* Now set up top level AlgorithmIdentifier */
|
||||
|
||||
if (!(ret = X509_ALGOR_new()))
|
||||
goto merr;
|
||||
if (!(ret->parameter = ASN1_TYPE_new()))
|
||||
goto merr;
|
||||
|
||||
ret->algorithm = OBJ_nid2obj(NID_pbes2);
|
||||
|
||||
/* Encode PBE2PARAM into parameter */
|
||||
|
||||
if (!ASN1_item_pack(pbe2, &PBE2PARAM_it,
|
||||
&ret->parameter->value.sequence)) goto merr;
|
||||
ret->parameter->type = V_ASN1_SEQUENCE;
|
||||
|
||||
PBE2PARAM_free(pbe2);
|
||||
pbe2 = NULL;
|
||||
|
||||
return ret;
|
||||
|
||||
merr:
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
|
||||
err:
|
||||
PBE2PARAM_free(pbe2);
|
||||
/* Note 'scheme' is freed as part of pbe2 */
|
||||
X509_ALGOR_free(kalg);
|
||||
X509_ALGOR_free(ret);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
X509_ALGOR *
|
||||
PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter, unsigned char *salt,
|
||||
int saltlen)
|
||||
{
|
||||
return PKCS5_pbe2_set_iv(cipher, iter, salt, saltlen, NULL, -1);
|
||||
}
|
||||
|
||||
X509_ALGOR *
|
||||
PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen, int prf_nid,
|
||||
int keylen)
|
||||
{
|
||||
X509_ALGOR *keyfunc = NULL;
|
||||
PBKDF2PARAM *kdf = NULL;
|
||||
ASN1_OCTET_STRING *osalt = NULL;
|
||||
|
||||
if (!(kdf = PBKDF2PARAM_new()))
|
||||
goto merr;
|
||||
if (!(osalt = ASN1_OCTET_STRING_new()))
|
||||
goto merr;
|
||||
|
||||
kdf->salt->value.octet_string = osalt;
|
||||
kdf->salt->type = V_ASN1_OCTET_STRING;
|
||||
|
||||
if (!saltlen)
|
||||
saltlen = PKCS5_SALT_LEN;
|
||||
if (!(osalt->data = malloc (saltlen)))
|
||||
goto merr;
|
||||
|
||||
osalt->length = saltlen;
|
||||
|
||||
if (salt)
|
||||
memcpy (osalt->data, salt, saltlen);
|
||||
else
|
||||
arc4random_buf(osalt->data, saltlen);
|
||||
|
||||
if (iter <= 0)
|
||||
iter = PKCS5_DEFAULT_ITER;
|
||||
|
||||
if (!ASN1_INTEGER_set(kdf->iter, iter))
|
||||
goto merr;
|
||||
|
||||
/* If have a key len set it up */
|
||||
|
||||
if (keylen > 0) {
|
||||
if (!(kdf->keylength = ASN1_INTEGER_new()))
|
||||
goto merr;
|
||||
if (!ASN1_INTEGER_set(kdf->keylength, keylen))
|
||||
goto merr;
|
||||
}
|
||||
|
||||
/* prf can stay NULL if we are using hmacWithSHA1 */
|
||||
if (prf_nid > 0 && prf_nid != NID_hmacWithSHA1) {
|
||||
kdf->prf = X509_ALGOR_new();
|
||||
if (!kdf->prf)
|
||||
goto merr;
|
||||
X509_ALGOR_set0(kdf->prf, OBJ_nid2obj(prf_nid),
|
||||
V_ASN1_NULL, NULL);
|
||||
}
|
||||
|
||||
/* Finally setup the keyfunc structure */
|
||||
|
||||
keyfunc = X509_ALGOR_new();
|
||||
if (!keyfunc)
|
||||
goto merr;
|
||||
|
||||
keyfunc->algorithm = OBJ_nid2obj(NID_id_pbkdf2);
|
||||
|
||||
/* Encode PBKDF2PARAM into parameter of pbe2 */
|
||||
|
||||
if (!(keyfunc->parameter = ASN1_TYPE_new()))
|
||||
goto merr;
|
||||
|
||||
if (!ASN1_item_pack(kdf, &PBKDF2PARAM_it,
|
||||
&keyfunc->parameter->value.sequence))
|
||||
goto merr;
|
||||
keyfunc->parameter->type = V_ASN1_SEQUENCE;
|
||||
|
||||
PBKDF2PARAM_free(kdf);
|
||||
return keyfunc;
|
||||
|
||||
merr:
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
PBKDF2PARAM_free(kdf);
|
||||
X509_ALGOR_free(keyfunc);
|
||||
return NULL;
|
||||
}
|
||||
188
externals/libressl/crypto/asn1/p8_pkey.c
vendored
188
externals/libressl/crypto/asn1/p8_pkey.c
vendored
@@ -1,188 +0,0 @@
|
||||
/* $OpenBSD: p8_pkey.c,v 1.20 2021/11/01 20:53:08 tb Exp $ */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 1999.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999-2005 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
#include "x509_lcl.h"
|
||||
|
||||
/* Minor tweak to operation: zero private key data */
|
||||
static int
|
||||
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)
|
||||
explicit_bzero(key->pkey->data, key->pkey->length);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const ASN1_AUX PKCS8_PRIV_KEY_INFO_aux = {
|
||||
.asn1_cb = pkey_cb,
|
||||
};
|
||||
static const ASN1_TEMPLATE PKCS8_PRIV_KEY_INFO_seq_tt[] = {
|
||||
{
|
||||
.offset = offsetof(PKCS8_PRIV_KEY_INFO, version),
|
||||
.field_name = "version",
|
||||
.item = &ASN1_INTEGER_it,
|
||||
},
|
||||
{
|
||||
.offset = offsetof(PKCS8_PRIV_KEY_INFO, pkeyalg),
|
||||
.field_name = "pkeyalg",
|
||||
.item = &X509_ALGOR_it,
|
||||
},
|
||||
{
|
||||
.offset = offsetof(PKCS8_PRIV_KEY_INFO, pkey),
|
||||
.field_name = "pkey",
|
||||
.item = &ASN1_OCTET_STRING_it,
|
||||
},
|
||||
{
|
||||
.flags = ASN1_TFLG_IMPLICIT | ASN1_TFLG_SET_OF | ASN1_TFLG_OPTIONAL,
|
||||
.offset = offsetof(PKCS8_PRIV_KEY_INFO, attributes),
|
||||
.field_name = "attributes",
|
||||
.item = &X509_ATTRIBUTE_it,
|
||||
},
|
||||
};
|
||||
|
||||
const ASN1_ITEM PKCS8_PRIV_KEY_INFO_it = {
|
||||
.itype = ASN1_ITYPE_SEQUENCE,
|
||||
.utype = V_ASN1_SEQUENCE,
|
||||
.templates = PKCS8_PRIV_KEY_INFO_seq_tt,
|
||||
.tcount = sizeof(PKCS8_PRIV_KEY_INFO_seq_tt) / sizeof(ASN1_TEMPLATE),
|
||||
.funcs = &PKCS8_PRIV_KEY_INFO_aux,
|
||||
.size = sizeof(PKCS8_PRIV_KEY_INFO),
|
||||
.sname = "PKCS8_PRIV_KEY_INFO",
|
||||
};
|
||||
|
||||
|
||||
PKCS8_PRIV_KEY_INFO *
|
||||
d2i_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (PKCS8_PRIV_KEY_INFO *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&PKCS8_PRIV_KEY_INFO_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &PKCS8_PRIV_KEY_INFO_it);
|
||||
}
|
||||
|
||||
PKCS8_PRIV_KEY_INFO *
|
||||
PKCS8_PRIV_KEY_INFO_new(void)
|
||||
{
|
||||
return (PKCS8_PRIV_KEY_INFO *)ASN1_item_new(&PKCS8_PRIV_KEY_INFO_it);
|
||||
}
|
||||
|
||||
void
|
||||
PKCS8_PRIV_KEY_INFO_free(PKCS8_PRIV_KEY_INFO *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &PKCS8_PRIV_KEY_INFO_it);
|
||||
}
|
||||
|
||||
int
|
||||
PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj, int version,
|
||||
int ptype, void *pval, unsigned char *penc, int penclen)
|
||||
{
|
||||
if (version >= 0) {
|
||||
if (!ASN1_INTEGER_set(priv->version, version))
|
||||
return 0;
|
||||
}
|
||||
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(const ASN1_OBJECT **ppkalg, const unsigned char **pk,
|
||||
int *ppklen, const X509_ALGOR **pa, const PKCS8_PRIV_KEY_INFO *p8)
|
||||
{
|
||||
if (ppkalg != NULL)
|
||||
*ppkalg = p8->pkeyalg->algorithm;
|
||||
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;
|
||||
}
|
||||
|
||||
145
externals/libressl/crypto/asn1/t_crl.c
vendored
145
externals/libressl/crypto/asn1/t_crl.c
vendored
@@ -1,145 +0,0 @@
|
||||
/* $OpenBSD: t_crl.c,v 1.20 2021/12/25 13:17:48 jsing Exp $ */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 1999.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
#include "x509_lcl.h"
|
||||
|
||||
int
|
||||
X509_CRL_print_fp(FILE *fp, X509_CRL *x)
|
||||
{
|
||||
BIO *b;
|
||||
int ret;
|
||||
|
||||
if ((b = BIO_new(BIO_s_file())) == NULL) {
|
||||
X509error(ERR_R_BUF_LIB);
|
||||
return (0);
|
||||
}
|
||||
BIO_set_fp(b, fp, BIO_NOCLOSE);
|
||||
ret = X509_CRL_print(b, x);
|
||||
BIO_free(b);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
X509_CRL_print(BIO *out, X509_CRL *x)
|
||||
{
|
||||
STACK_OF(X509_REVOKED) *rev;
|
||||
X509_REVOKED *r;
|
||||
long l;
|
||||
int i;
|
||||
char *p;
|
||||
|
||||
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)
|
||||
goto err;
|
||||
p = X509_NAME_oneline(X509_CRL_get_issuer(x), NULL, 0);
|
||||
if (p == NULL)
|
||||
goto err;
|
||||
BIO_printf(out, "%8sIssuer: %s\n", "", p);
|
||||
free(p);
|
||||
BIO_printf(out, "%8sLast Update: ", "");
|
||||
ASN1_TIME_print(out, X509_CRL_get_lastUpdate(x));
|
||||
BIO_printf(out, "\n%8sNext Update: ", "");
|
||||
if (X509_CRL_get_nextUpdate(x))
|
||||
ASN1_TIME_print(out, X509_CRL_get_nextUpdate(x));
|
||||
else
|
||||
BIO_printf(out, "NONE");
|
||||
BIO_printf(out, "\n");
|
||||
|
||||
X509V3_extensions_print(out, "CRL extensions",
|
||||
x->crl->extensions, 0, 8);
|
||||
|
||||
rev = X509_CRL_get_REVOKED(x);
|
||||
|
||||
if (sk_X509_REVOKED_num(rev) > 0)
|
||||
BIO_printf(out, "Revoked Certificates:\n");
|
||||
else
|
||||
BIO_printf(out, "No Revoked Certificates.\n");
|
||||
|
||||
for (i = 0; i < sk_X509_REVOKED_num(rev); i++) {
|
||||
r = sk_X509_REVOKED_value(rev, i);
|
||||
BIO_printf(out, " Serial Number: ");
|
||||
i2a_ASN1_INTEGER(out, r->serialNumber);
|
||||
BIO_printf(out, "\n Revocation Date: ");
|
||||
ASN1_TIME_print(out, r->revocationDate);
|
||||
BIO_printf(out, "\n");
|
||||
X509V3_extensions_print(out, "CRL entry extensions",
|
||||
r->extensions, 0, 8);
|
||||
}
|
||||
if (X509_signature_print(out, x->sig_alg, x->signature) == 0)
|
||||
goto err;
|
||||
|
||||
return 1;
|
||||
|
||||
err:
|
||||
return 0;
|
||||
}
|
||||
116
externals/libressl/crypto/asn1/t_pkey.c
vendored
116
externals/libressl/crypto/asn1/t_pkey.c
vendored
@@ -1,116 +0,0 @@
|
||||
/* $OpenBSD: t_pkey.c,v 1.17 2021/12/04 16:08:32 tb 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 <openssl/bn.h>
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/objects.h>
|
||||
|
||||
#include "bn_lcl.h"
|
||||
|
||||
int
|
||||
ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num,
|
||||
unsigned char *buf, int off)
|
||||
{
|
||||
int n, i;
|
||||
const char *neg;
|
||||
|
||||
if (num == NULL)
|
||||
return (1);
|
||||
neg = (BN_is_negative(num)) ? "-" : "";
|
||||
if (!BIO_indent(bp, off, 128))
|
||||
return 0;
|
||||
if (BN_is_zero(num)) {
|
||||
if (BIO_printf(bp, "%s 0\n", number) <= 0)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (BN_num_bytes(num) <= BN_BYTES) {
|
||||
if (BIO_printf(bp, "%s %s%lu (%s0x%lx)\n", number, neg,
|
||||
(unsigned long)num->d[0], neg,
|
||||
(unsigned long)num->d[0]) <= 0)
|
||||
return (0);
|
||||
} else {
|
||||
buf[0] = 0;
|
||||
if (BIO_printf(bp, "%s%s", number,
|
||||
(neg[0] == '-') ? " (Negative)" : "") <= 0)
|
||||
return (0);
|
||||
n = BN_bn2bin(num, &buf[1]);
|
||||
|
||||
if (buf[1] & 0x80)
|
||||
n++;
|
||||
else
|
||||
buf++;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
if ((i % 15) == 0) {
|
||||
if (BIO_puts(bp, "\n") <= 0 ||
|
||||
!BIO_indent(bp, off + 4, 128))
|
||||
return 0;
|
||||
}
|
||||
if (BIO_printf(bp, "%02x%s", buf[i],
|
||||
((i + 1) == n) ? "" : ":") <= 0)
|
||||
return (0);
|
||||
}
|
||||
if (BIO_write(bp, "\n", 1) <= 0)
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
269
externals/libressl/crypto/asn1/t_req.c
vendored
269
externals/libressl/crypto/asn1/t_req.c
vendored
@@ -1,269 +0,0 @@
|
||||
/* $OpenBSD: t_req.c,v 1.21 2021/12/25 13:17:48 jsing 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 <openssl/opensslconf.h>
|
||||
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
#include <openssl/dsa.h>
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
#include <openssl/rsa.h>
|
||||
#endif
|
||||
|
||||
#include "x509_lcl.h"
|
||||
|
||||
int
|
||||
X509_REQ_print_fp(FILE *fp, X509_REQ *x)
|
||||
{
|
||||
BIO *b;
|
||||
int ret;
|
||||
|
||||
if ((b = BIO_new(BIO_s_file())) == NULL) {
|
||||
X509error(ERR_R_BUF_LIB);
|
||||
return (0);
|
||||
}
|
||||
BIO_set_fp(b, fp, BIO_NOCLOSE);
|
||||
ret = X509_REQ_print(b, x);
|
||||
BIO_free(b);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags,
|
||||
unsigned long cflag)
|
||||
{
|
||||
unsigned long l;
|
||||
int i;
|
||||
const char *neg;
|
||||
X509_REQ_INFO *ri;
|
||||
EVP_PKEY *pkey;
|
||||
STACK_OF(X509_ATTRIBUTE) *sk;
|
||||
STACK_OF(X509_EXTENSION) *exts;
|
||||
char mlch = ' ';
|
||||
int nmindent = 0;
|
||||
|
||||
if ((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) {
|
||||
mlch = '\n';
|
||||
nmindent = 12;
|
||||
}
|
||||
|
||||
if (nmflags == X509_FLAG_COMPAT)
|
||||
nmindent = 16;
|
||||
|
||||
ri = x->req_info;
|
||||
if (!(cflag & X509_FLAG_NO_HEADER)) {
|
||||
if (BIO_write(bp, "Certificate Request:\n", 21) <= 0)
|
||||
goto err;
|
||||
if (BIO_write(bp, " Data:\n", 10) <= 0)
|
||||
|
||||
goto err;
|
||||
}
|
||||
if (!(cflag & X509_FLAG_NO_VERSION)) {
|
||||
neg = (ri->version->type == V_ASN1_NEG_INTEGER) ? "-" : "";
|
||||
l = 0;
|
||||
for (i = 0; i < ri->version->length; i++) {
|
||||
l <<= 8;
|
||||
l += ri->version->data[i];
|
||||
}
|
||||
if (BIO_printf(bp, "%8sVersion: %s%lu (%s0x%lx)\n", "", neg,
|
||||
l, neg, l) <= 0)
|
||||
goto err;
|
||||
}
|
||||
if (!(cflag & X509_FLAG_NO_SUBJECT)) {
|
||||
if (BIO_printf(bp, " Subject:%c", mlch) <= 0)
|
||||
goto err;
|
||||
if (X509_NAME_print_ex(bp, ri->subject, nmindent, nmflags) < 0)
|
||||
goto err;
|
||||
if (BIO_write(bp, "\n", 1) <= 0)
|
||||
goto err;
|
||||
}
|
||||
if (!(cflag & X509_FLAG_NO_PUBKEY)) {
|
||||
if (BIO_write(bp, " Subject Public Key Info:\n",
|
||||
33) <= 0)
|
||||
goto err;
|
||||
if (BIO_printf(bp, "%12sPublic Key Algorithm: ", "") <= 0)
|
||||
goto err;
|
||||
if (i2a_ASN1_OBJECT(bp, ri->pubkey->algor->algorithm) <= 0)
|
||||
goto err;
|
||||
if (BIO_puts(bp, "\n") <= 0)
|
||||
goto err;
|
||||
|
||||
pkey = X509_REQ_get_pubkey(x);
|
||||
if (pkey == NULL) {
|
||||
BIO_printf(bp, "%12sUnable to load Public Key\n", "");
|
||||
ERR_print_errors(bp);
|
||||
} else {
|
||||
EVP_PKEY_print_public(bp, pkey, 16, NULL);
|
||||
EVP_PKEY_free(pkey);
|
||||
}
|
||||
}
|
||||
|
||||
if (!(cflag & X509_FLAG_NO_ATTRIBUTES)) {
|
||||
/* may not be */
|
||||
if (BIO_printf(bp, "%8sAttributes:\n", "") <= 0)
|
||||
goto err;
|
||||
|
||||
sk = x->req_info->attributes;
|
||||
if (sk_X509_ATTRIBUTE_num(sk) == 0) {
|
||||
if (BIO_printf(bp, "%12sa0:00\n", "") <= 0)
|
||||
goto err;
|
||||
} else {
|
||||
for (i = 0; i < sk_X509_ATTRIBUTE_num(sk); i++) {
|
||||
ASN1_TYPE *at;
|
||||
X509_ATTRIBUTE *a;
|
||||
ASN1_BIT_STRING *bs = NULL;
|
||||
ASN1_TYPE *t;
|
||||
int j, type = 0, count = 1, ii = 0;
|
||||
|
||||
a = sk_X509_ATTRIBUTE_value(sk, i);
|
||||
if (X509_REQ_extension_nid(
|
||||
OBJ_obj2nid(a->object)))
|
||||
continue;
|
||||
if (BIO_printf(bp, "%12s", "") <= 0)
|
||||
goto err;
|
||||
if ((j = i2a_ASN1_OBJECT(bp, a->object)) > 0) {
|
||||
if (a->single) {
|
||||
t = a->value.single;
|
||||
type = t->type;
|
||||
bs = t->value.bit_string;
|
||||
} else {
|
||||
ii = 0;
|
||||
count = sk_ASN1_TYPE_num(
|
||||
a->value.set);
|
||||
get_next:
|
||||
at = sk_ASN1_TYPE_value(
|
||||
a->value.set, ii);
|
||||
type = at->type;
|
||||
bs = at->value.asn1_string;
|
||||
}
|
||||
}
|
||||
for (j = 25 - j; j > 0; j--)
|
||||
if (BIO_write(bp, " ", 1) != 1)
|
||||
goto err;
|
||||
if (BIO_puts(bp, ":") <= 0)
|
||||
goto err;
|
||||
if ((type == V_ASN1_PRINTABLESTRING) ||
|
||||
(type == V_ASN1_T61STRING) ||
|
||||
(type == V_ASN1_IA5STRING)) {
|
||||
if (BIO_write(bp, (char *)bs->data,
|
||||
bs->length) != bs->length)
|
||||
goto err;
|
||||
BIO_puts(bp, "\n");
|
||||
} else {
|
||||
BIO_puts(bp,
|
||||
"unable to print attribute\n");
|
||||
}
|
||||
if (++ii < count)
|
||||
goto get_next;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!(cflag & X509_FLAG_NO_EXTENSIONS)) {
|
||||
exts = X509_REQ_get_extensions(x);
|
||||
if (exts) {
|
||||
BIO_printf(bp, "%8sRequested Extensions:\n", "");
|
||||
for (i = 0; i < sk_X509_EXTENSION_num(exts); i++) {
|
||||
ASN1_OBJECT *obj;
|
||||
X509_EXTENSION *ex;
|
||||
int j;
|
||||
ex = sk_X509_EXTENSION_value(exts, i);
|
||||
if (BIO_printf(bp, "%12s", "") <= 0)
|
||||
goto err;
|
||||
obj = X509_EXTENSION_get_object(ex);
|
||||
i2a_ASN1_OBJECT(bp, obj);
|
||||
j = X509_EXTENSION_get_critical(ex);
|
||||
if (BIO_printf(bp, ": %s\n",
|
||||
j ? "critical" : "") <= 0)
|
||||
goto err;
|
||||
if (!X509V3_EXT_print(bp, ex, cflag, 16)) {
|
||||
BIO_printf(bp, "%16s", "");
|
||||
ASN1_STRING_print(bp, ex->value);
|
||||
}
|
||||
if (BIO_write(bp, "\n", 1) <= 0)
|
||||
goto err;
|
||||
}
|
||||
sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
|
||||
}
|
||||
}
|
||||
|
||||
if (!(cflag & X509_FLAG_NO_SIGDUMP)) {
|
||||
if (!X509_signature_print(bp, x->sig_alg, x->signature))
|
||||
goto err;
|
||||
}
|
||||
|
||||
return (1);
|
||||
|
||||
err:
|
||||
X509error(ERR_R_BUF_LIB);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
X509_REQ_print(BIO *bp, X509_REQ *x)
|
||||
{
|
||||
return X509_REQ_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT);
|
||||
}
|
||||
115
externals/libressl/crypto/asn1/t_spki.c
vendored
115
externals/libressl/crypto/asn1/t_spki.c
vendored
@@ -1,115 +0,0 @@
|
||||
/* $OpenBSD: t_spki.c,v 1.13 2021/11/01 20:53:08 tb Exp $ */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 1999.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <openssl/opensslconf.h>
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
#include <openssl/dsa.h>
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
#include <openssl/rsa.h>
|
||||
#endif
|
||||
|
||||
#include "x509_lcl.h"
|
||||
|
||||
/* Print out an SPKI */
|
||||
|
||||
int
|
||||
NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki)
|
||||
{
|
||||
EVP_PKEY *pkey;
|
||||
ASN1_IA5STRING *chal;
|
||||
int i, n;
|
||||
char *s;
|
||||
|
||||
BIO_printf(out, "Netscape SPKI:\n");
|
||||
i = OBJ_obj2nid(spki->spkac->pubkey->algor->algorithm);
|
||||
BIO_printf(out, " Public Key Algorithm: %s\n",
|
||||
(i == NID_undef) ? "UNKNOWN" : OBJ_nid2ln(i));
|
||||
pkey = X509_PUBKEY_get(spki->spkac->pubkey);
|
||||
if (!pkey)
|
||||
BIO_printf(out, " Unable to load public key\n");
|
||||
else {
|
||||
EVP_PKEY_print_public(out, pkey, 4, NULL);
|
||||
EVP_PKEY_free(pkey);
|
||||
}
|
||||
chal = spki->spkac->challenge;
|
||||
if (chal->length)
|
||||
BIO_printf(out, " Challenge String: %.*s\n", chal->length,
|
||||
chal->data);
|
||||
i = OBJ_obj2nid(spki->sig_algor->algorithm);
|
||||
BIO_printf(out, " Signature Algorithm: %s",
|
||||
(i == NID_undef) ? "UNKNOWN" : OBJ_nid2ln(i));
|
||||
|
||||
n = spki->signature->length;
|
||||
s = (char *)spki->signature->data;
|
||||
for (i = 0; i < n; i++) {
|
||||
if ((i % 18) == 0)
|
||||
BIO_write(out, "\n ", 7);
|
||||
BIO_printf(out, "%02x%s", (unsigned char)s[i],
|
||||
((i + 1) == n) ? "" : ":");
|
||||
}
|
||||
BIO_write(out, "\n", 1);
|
||||
return 1;
|
||||
}
|
||||
513
externals/libressl/crypto/asn1/t_x509.c
vendored
513
externals/libressl/crypto/asn1/t_x509.c
vendored
@@ -1,513 +0,0 @@
|
||||
/* $OpenBSD: t_x509.c,v 1.37 2021/12/25 13:17:48 jsing 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 <openssl/opensslconf.h>
|
||||
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
#include <openssl/dsa.h>
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_EC
|
||||
#include <openssl/ec.h>
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
#include <openssl/rsa.h>
|
||||
#endif
|
||||
|
||||
#include "asn1_locl.h"
|
||||
#include "x509_lcl.h"
|
||||
|
||||
int
|
||||
X509_print_fp(FILE *fp, X509 *x)
|
||||
{
|
||||
return X509_print_ex_fp(fp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT);
|
||||
}
|
||||
|
||||
int
|
||||
X509_print_ex_fp(FILE *fp, X509 *x, unsigned long nmflag, unsigned long cflag)
|
||||
{
|
||||
BIO *b;
|
||||
int ret;
|
||||
|
||||
if ((b = BIO_new(BIO_s_file())) == NULL) {
|
||||
X509error(ERR_R_BUF_LIB);
|
||||
return (0);
|
||||
}
|
||||
BIO_set_fp(b, fp, BIO_NOCLOSE);
|
||||
ret = X509_print_ex(b, x, nmflag, cflag);
|
||||
BIO_free(b);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
X509_print(BIO *bp, X509 *x)
|
||||
{
|
||||
return X509_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT);
|
||||
}
|
||||
|
||||
int
|
||||
X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag)
|
||||
{
|
||||
long l;
|
||||
int ret = 0, i;
|
||||
char *m = NULL, mlch = ' ';
|
||||
int nmindent = 0;
|
||||
X509_CINF *ci;
|
||||
ASN1_INTEGER *bs;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
const char *neg;
|
||||
|
||||
if ((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) {
|
||||
mlch = '\n';
|
||||
nmindent = 12;
|
||||
}
|
||||
|
||||
if (nmflags == X509_FLAG_COMPAT)
|
||||
nmindent = 16;
|
||||
|
||||
ci = x->cert_info;
|
||||
if (!(cflag & X509_FLAG_NO_HEADER)) {
|
||||
if (BIO_write(bp, "Certificate:\n", 13) <= 0)
|
||||
goto err;
|
||||
if (BIO_write(bp, " Data:\n", 10) <= 0)
|
||||
goto err;
|
||||
}
|
||||
if (!(cflag & X509_FLAG_NO_VERSION)) {
|
||||
l = X509_get_version(x);
|
||||
if (BIO_printf(bp, "%8sVersion: %lu (0x%lx)\n",
|
||||
"", l + 1, l) <= 0)
|
||||
goto err;
|
||||
}
|
||||
if (!(cflag & X509_FLAG_NO_SERIAL)) {
|
||||
if (BIO_write(bp, " Serial Number:", 22) <= 0)
|
||||
goto err;
|
||||
|
||||
bs = X509_get_serialNumber(x);
|
||||
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 = "-";
|
||||
} else
|
||||
neg = "";
|
||||
if (BIO_printf(bp, " %s%lu (%s0x%lx)\n",
|
||||
neg, l, neg, l) <= 0)
|
||||
goto err;
|
||||
} else {
|
||||
neg = (bs->type == V_ASN1_NEG_INTEGER) ?
|
||||
" (Negative)" : "";
|
||||
if (BIO_printf(bp, "\n%12s%s", "", neg) <= 0)
|
||||
goto err;
|
||||
for (i = 0; i < bs->length; i++) {
|
||||
if (BIO_printf(bp, "%02x%c", bs->data[i],
|
||||
((i + 1 == bs->length) ? '\n' : ':')) <= 0)
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!(cflag & X509_FLAG_NO_SIGNAME)) {
|
||||
if (X509_signature_print(bp, x->sig_alg, NULL) <= 0)
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!(cflag & X509_FLAG_NO_ISSUER)) {
|
||||
if (BIO_printf(bp, " Issuer:%c", mlch) <= 0)
|
||||
goto err;
|
||||
if (X509_NAME_print_ex(bp, X509_get_issuer_name(x),
|
||||
nmindent, nmflags) < (nmflags == X509_FLAG_COMPAT ? 1 : 0))
|
||||
goto err;
|
||||
if (BIO_write(bp, "\n", 1) <= 0)
|
||||
goto err;
|
||||
}
|
||||
if (!(cflag & X509_FLAG_NO_VALIDITY)) {
|
||||
if (BIO_write(bp, " Validity\n", 17) <= 0)
|
||||
goto err;
|
||||
if (BIO_write(bp, " Not Before: ", 24) <= 0)
|
||||
goto err;
|
||||
if (!ASN1_TIME_print(bp, X509_get_notBefore(x)))
|
||||
goto err;
|
||||
if (BIO_write(bp, "\n Not After : ", 25) <= 0)
|
||||
goto err;
|
||||
if (!ASN1_TIME_print(bp, X509_get_notAfter(x)))
|
||||
goto err;
|
||||
if (BIO_write(bp, "\n", 1) <= 0)
|
||||
goto err;
|
||||
}
|
||||
if (!(cflag & X509_FLAG_NO_SUBJECT)) {
|
||||
if (BIO_printf(bp, " Subject:%c", mlch) <= 0)
|
||||
goto err;
|
||||
if (X509_NAME_print_ex(bp, X509_get_subject_name(x),
|
||||
nmindent, nmflags) < (nmflags == X509_FLAG_COMPAT ? 1 : 0))
|
||||
goto err;
|
||||
if (BIO_write(bp, "\n", 1) <= 0)
|
||||
goto err;
|
||||
}
|
||||
if (!(cflag & X509_FLAG_NO_PUBKEY)) {
|
||||
if (BIO_write(bp, " Subject Public Key Info:\n",
|
||||
33) <= 0)
|
||||
goto err;
|
||||
if (BIO_printf(bp, "%12sPublic Key Algorithm: ", "") <= 0)
|
||||
goto err;
|
||||
if (i2a_ASN1_OBJECT(bp, ci->key->algor->algorithm) <= 0)
|
||||
goto err;
|
||||
if (BIO_puts(bp, "\n") <= 0)
|
||||
goto err;
|
||||
|
||||
pkey = X509_get_pubkey(x);
|
||||
if (pkey == NULL) {
|
||||
BIO_printf(bp, "%12sUnable to load Public Key\n", "");
|
||||
ERR_print_errors(bp);
|
||||
} else {
|
||||
EVP_PKEY_print_public(bp, pkey, 16, NULL);
|
||||
EVP_PKEY_free(pkey);
|
||||
}
|
||||
}
|
||||
|
||||
if (!(cflag & X509_FLAG_NO_EXTENSIONS))
|
||||
X509V3_extensions_print(bp, "X509v3 extensions",
|
||||
ci->extensions, cflag, 8);
|
||||
|
||||
if (!(cflag & X509_FLAG_NO_SIGDUMP)) {
|
||||
if (X509_signature_print(bp, x->sig_alg, x->signature) <= 0)
|
||||
goto err;
|
||||
}
|
||||
if (!(cflag & X509_FLAG_NO_AUX)) {
|
||||
if (!X509_CERT_AUX_print(bp, x->aux, 0))
|
||||
goto err;
|
||||
}
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
free(m);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
X509_ocspid_print(BIO *bp, X509 *x)
|
||||
{
|
||||
unsigned char *der = NULL;
|
||||
unsigned char *dertmp;
|
||||
int derlen;
|
||||
int i;
|
||||
unsigned char SHA1md[SHA_DIGEST_LENGTH];
|
||||
|
||||
/* display the hash of the subject as it would appear
|
||||
in OCSP requests */
|
||||
if (BIO_printf(bp, " Subject OCSP hash: ") <= 0)
|
||||
goto err;
|
||||
if ((derlen = i2d_X509_NAME(x->cert_info->subject, NULL)) <= 0)
|
||||
goto err;
|
||||
if ((der = dertmp = malloc(derlen)) == NULL)
|
||||
goto err;
|
||||
if (i2d_X509_NAME(x->cert_info->subject, &dertmp) <= 0)
|
||||
goto err;
|
||||
|
||||
if (!EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL))
|
||||
goto err;
|
||||
for (i = 0; i < SHA_DIGEST_LENGTH; i++) {
|
||||
if (BIO_printf(bp, "%02X", SHA1md[i]) <= 0)
|
||||
goto err;
|
||||
}
|
||||
free (der);
|
||||
der = NULL;
|
||||
|
||||
/* display the hash of the public key as it would appear
|
||||
in OCSP requests */
|
||||
if (BIO_printf(bp, "\n Public key OCSP hash: ") <= 0)
|
||||
goto err;
|
||||
|
||||
if (!EVP_Digest(x->cert_info->key->public_key->data,
|
||||
x->cert_info->key->public_key->length,
|
||||
SHA1md, NULL, EVP_sha1(), NULL))
|
||||
goto err;
|
||||
for (i = 0; i < SHA_DIGEST_LENGTH; i++) {
|
||||
if (BIO_printf(bp, "%02X", SHA1md[i]) <= 0)
|
||||
goto err;
|
||||
}
|
||||
BIO_printf(bp, "\n");
|
||||
|
||||
return (1);
|
||||
|
||||
err:
|
||||
free(der);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent)
|
||||
{
|
||||
const unsigned char *s;
|
||||
int i, n;
|
||||
|
||||
n = sig->length;
|
||||
s = sig->data;
|
||||
for (i = 0; i < n; i++) {
|
||||
if ((i % 18) == 0) {
|
||||
if (BIO_write(bp, "\n", 1) <= 0)
|
||||
return 0;
|
||||
if (BIO_indent(bp, indent, indent) <= 0)
|
||||
return 0;
|
||||
}
|
||||
if (BIO_printf(bp, "%02x%s", s[i],
|
||||
((i + 1) == n) ? "" : ":") <= 0)
|
||||
return 0;
|
||||
}
|
||||
if (BIO_write(bp, "\n", 1) != 1)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
X509_signature_print(BIO *bp, const X509_ALGOR *sigalg, const ASN1_STRING *sig)
|
||||
{
|
||||
int sig_nid;
|
||||
if (BIO_puts(bp, " Signature Algorithm: ") <= 0)
|
||||
return 0;
|
||||
if (i2a_ASN1_OBJECT(bp, sigalg->algorithm) <= 0)
|
||||
return 0;
|
||||
|
||||
sig_nid = OBJ_obj2nid(sigalg->algorithm);
|
||||
if (sig_nid != NID_undef) {
|
||||
int pkey_nid, dig_nid;
|
||||
const EVP_PKEY_ASN1_METHOD *ameth;
|
||||
if (OBJ_find_sigid_algs(sig_nid, &dig_nid, &pkey_nid)) {
|
||||
ameth = EVP_PKEY_asn1_find(NULL, pkey_nid);
|
||||
if (ameth && ameth->sig_print)
|
||||
return ameth->sig_print(bp, sigalg, sig, 9, 0);
|
||||
}
|
||||
}
|
||||
if (sig)
|
||||
return X509_signature_dump(bp, sig, 9);
|
||||
else if (BIO_puts(bp, "\n") <= 0)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_TIME_print(BIO *bp, const ASN1_TIME *tm)
|
||||
{
|
||||
if (tm->type == V_ASN1_UTCTIME)
|
||||
return ASN1_UTCTIME_print(bp, tm);
|
||||
if (tm->type == V_ASN1_GENERALIZEDTIME)
|
||||
return ASN1_GENERALIZEDTIME_print(bp, tm);
|
||||
BIO_write(bp, "Bad time value", 14);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static const char *mon[12] = {
|
||||
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
||||
};
|
||||
|
||||
int
|
||||
ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm)
|
||||
{
|
||||
char *v;
|
||||
int gmt = 0;
|
||||
int i;
|
||||
int y = 0, M = 0, d = 0, h = 0, m = 0, s = 0;
|
||||
char *f = "";
|
||||
int f_len = 0;
|
||||
|
||||
i = tm->length;
|
||||
v = (char *)tm->data;
|
||||
|
||||
if (i < 12)
|
||||
goto err;
|
||||
if (v[i-1] == 'Z')
|
||||
gmt = 1;
|
||||
for (i = 0; i < 12; i++)
|
||||
if ((v[i] > '9') || (v[i] < '0'))
|
||||
goto err;
|
||||
y = (v[0] - '0') * 1000 + (v[1] - '0') * 100 +
|
||||
(v[2] - '0') * 10 + (v[3] - '0');
|
||||
M = (v[4] - '0') * 10 + (v[5] - '0');
|
||||
if ((M > 12) || (M < 1))
|
||||
goto err;
|
||||
d = (v[6] - '0') * 10 + (v[7] - '0');
|
||||
h = (v[8] - '0') * 10 + (v[9] - '0');
|
||||
m = (v[10] - '0') * 10 + (v[11] - '0');
|
||||
if (tm->length >= 14 &&
|
||||
(v[12] >= '0') && (v[12] <= '9') &&
|
||||
(v[13] >= '0') && (v[13] <= '9')) {
|
||||
s = (v[12] - '0') * 10 + (v[13] - '0');
|
||||
/* Check for fractions of seconds. */
|
||||
if (tm->length >= 15 && v[14] == '.') {
|
||||
int l = tm->length;
|
||||
f = &v[14]; /* The decimal point. */
|
||||
f_len = 1;
|
||||
while (14 + f_len < l && f[f_len] >= '0' &&
|
||||
f[f_len] <= '9')
|
||||
++f_len;
|
||||
}
|
||||
}
|
||||
|
||||
if (BIO_printf(bp, "%s %2d %02d:%02d:%02d%.*s %d%s",
|
||||
mon[M - 1], d, h, m, s, f_len, f, y, (gmt) ? " GMT" : "") <= 0)
|
||||
return (0);
|
||||
else
|
||||
return (1);
|
||||
|
||||
err:
|
||||
BIO_write(bp, "Bad time value", 14);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_UTCTIME_print(BIO *bp, const ASN1_UTCTIME *tm)
|
||||
{
|
||||
const char *v;
|
||||
int gmt = 0;
|
||||
int i;
|
||||
int y = 0, M = 0, d = 0, h = 0, m = 0, s = 0;
|
||||
|
||||
i = tm->length;
|
||||
v = (const char *)tm->data;
|
||||
|
||||
if (i < 10)
|
||||
goto err;
|
||||
if (v[i-1] == 'Z')
|
||||
gmt = 1;
|
||||
for (i = 0; i < 10; i++)
|
||||
if ((v[i] > '9') || (v[i] < '0'))
|
||||
goto err;
|
||||
y = (v[0] - '0') * 10 + (v[1] - '0');
|
||||
if (y < 50)
|
||||
y += 100;
|
||||
M = (v[2] - '0') * 10 + (v[3] - '0');
|
||||
if ((M > 12) || (M < 1))
|
||||
goto err;
|
||||
d = (v[4] - '0') * 10 + (v[5] - '0');
|
||||
h = (v[6] - '0') * 10 + (v[7] - '0');
|
||||
m = (v[8] - '0') * 10 + (v[9] - '0');
|
||||
if (tm->length >=12 &&
|
||||
(v[10] >= '0') && (v[10] <= '9') &&
|
||||
(v[11] >= '0') && (v[11] <= '9'))
|
||||
s = (v[10] - '0') * 10 + (v[11] - '0');
|
||||
|
||||
if (BIO_printf(bp, "%s %2d %02d:%02d:%02d %d%s",
|
||||
mon[M - 1], d, h, m, s, y + 1900, (gmt) ? " GMT" : "") <= 0)
|
||||
return (0);
|
||||
else
|
||||
return (1);
|
||||
|
||||
err:
|
||||
BIO_write(bp, "Bad time value", 14);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
X509_NAME_print(BIO *bp, const X509_NAME *name, int obase)
|
||||
{
|
||||
char *s, *c, *b;
|
||||
int ret = 0, l, i;
|
||||
|
||||
l = 80 - 2 - obase;
|
||||
|
||||
b = X509_NAME_oneline(name, NULL, 0);
|
||||
if (b == NULL)
|
||||
return 0;
|
||||
if (*b == '\0') {
|
||||
free(b);
|
||||
return 1;
|
||||
}
|
||||
s = b + 1; /* skip the first slash */
|
||||
|
||||
c = s;
|
||||
for (;;) {
|
||||
if (((*s == '/') &&
|
||||
((s[1] >= 'A') && (s[1] <= 'Z') &&
|
||||
((s[2] == '=') || ((s[2] >= 'A') && (s[2] <= 'Z') &&
|
||||
(s[3] == '='))))) || (*s == '\0')) {
|
||||
i = s - c;
|
||||
if (BIO_write(bp, c, i) != i)
|
||||
goto err;
|
||||
c = s + 1; /* skip following slash */
|
||||
if (*s != '\0') {
|
||||
if (BIO_write(bp, ", ", 2) != 2)
|
||||
goto err;
|
||||
}
|
||||
l--;
|
||||
}
|
||||
if (*s == '\0')
|
||||
break;
|
||||
s++;
|
||||
l--;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
if (0) {
|
||||
err:
|
||||
X509error(ERR_R_BUF_LIB);
|
||||
}
|
||||
free(b);
|
||||
return (ret);
|
||||
}
|
||||
119
externals/libressl/crypto/asn1/t_x509a.c
vendored
119
externals/libressl/crypto/asn1/t_x509a.c
vendored
@@ -1,119 +0,0 @@
|
||||
/* $OpenBSD: t_x509a.c,v 1.10 2021/11/01 20:53:08 tb Exp $ */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 1999.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
#include "x509_lcl.h"
|
||||
|
||||
/* X509_CERT_AUX and string set routines */
|
||||
|
||||
int
|
||||
X509_CERT_AUX_print(BIO *out, X509_CERT_AUX *aux, int indent)
|
||||
{
|
||||
char oidstr[80], first;
|
||||
int i;
|
||||
if (!aux)
|
||||
return 1;
|
||||
if (aux->trust) {
|
||||
first = 1;
|
||||
BIO_printf(out, "%*sTrusted Uses:\n%*s",
|
||||
indent, "", indent + 2, "");
|
||||
for (i = 0; i < sk_ASN1_OBJECT_num(aux->trust); i++) {
|
||||
if (!first)
|
||||
BIO_puts(out, ", ");
|
||||
else
|
||||
first = 0;
|
||||
OBJ_obj2txt(oidstr, sizeof oidstr,
|
||||
sk_ASN1_OBJECT_value(aux->trust, i), 0);
|
||||
BIO_puts(out, oidstr);
|
||||
}
|
||||
BIO_puts(out, "\n");
|
||||
} else
|
||||
BIO_printf(out, "%*sNo Trusted Uses.\n", indent, "");
|
||||
if (aux->reject) {
|
||||
first = 1;
|
||||
BIO_printf(out, "%*sRejected Uses:\n%*s",
|
||||
indent, "", indent + 2, "");
|
||||
for (i = 0; i < sk_ASN1_OBJECT_num(aux->reject); i++) {
|
||||
if (!first)
|
||||
BIO_puts(out, ", ");
|
||||
else
|
||||
first = 0;
|
||||
OBJ_obj2txt(oidstr, sizeof oidstr,
|
||||
sk_ASN1_OBJECT_value(aux->reject, i), 0);
|
||||
BIO_puts(out, oidstr);
|
||||
}
|
||||
BIO_puts(out, "\n");
|
||||
} else
|
||||
BIO_printf(out, "%*sNo Rejected Uses.\n", indent, "");
|
||||
if (aux->alias)
|
||||
BIO_printf(out, "%*sAlias: %.*s\n", indent, "",
|
||||
aux->alias->length, aux->alias->data);
|
||||
if (aux->keyid) {
|
||||
BIO_printf(out, "%*sKey Id: ", indent, "");
|
||||
for (i = 0; i < aux->keyid->length; i++)
|
||||
BIO_printf(out, "%s%02X", i ? ":" : "",
|
||||
aux->keyid->data[i]);
|
||||
BIO_write(out, "\n", 1);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
1143
externals/libressl/crypto/asn1/tasn_dec.c
vendored
1143
externals/libressl/crypto/asn1/tasn_dec.c
vendored
File diff suppressed because it is too large
Load Diff
676
externals/libressl/crypto/asn1/tasn_enc.c
vendored
676
externals/libressl/crypto/asn1/tasn_enc.c
vendored
@@ -1,676 +0,0 @@
|
||||
/* $OpenBSD: tasn_enc.c,v 1.24 2022/01/07 11:13:54 tb Exp $ */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 2000.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2000-2004 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/objects.h>
|
||||
|
||||
#include "asn1_locl.h"
|
||||
|
||||
static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,
|
||||
const ASN1_ITEM *it, int tag, int aclass);
|
||||
static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
|
||||
int skcontlen, const ASN1_ITEM *item, int do_sort, int iclass);
|
||||
static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
|
||||
const ASN1_TEMPLATE *tt, int tag, int aclass);
|
||||
static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,
|
||||
const ASN1_ITEM *it, int flags);
|
||||
static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
|
||||
const ASN1_ITEM *it);
|
||||
|
||||
/* Top level i2d equivalents: the 'ndef' variant instructs the encoder
|
||||
* to use indefinite length constructed encoding, where appropriate
|
||||
*/
|
||||
|
||||
int
|
||||
ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)
|
||||
{
|
||||
return asn1_item_flags_i2d(val, out, it, ASN1_TFLG_NDEF);
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)
|
||||
{
|
||||
return asn1_item_flags_i2d(val, out, it, 0);
|
||||
}
|
||||
|
||||
/* Encode an ASN1 item, this is use by the
|
||||
* standard 'i2d' function. 'out' points to
|
||||
* a buffer to output the data to.
|
||||
*
|
||||
* The new i2d has one additional feature. If the output
|
||||
* buffer is NULL (i.e. *out == NULL) then a buffer is
|
||||
* allocated and populated with the encoding.
|
||||
*/
|
||||
|
||||
static int
|
||||
asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it,
|
||||
int flags)
|
||||
{
|
||||
if (out && !*out) {
|
||||
unsigned char *p, *buf;
|
||||
int len;
|
||||
len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags);
|
||||
if (len <= 0)
|
||||
return len;
|
||||
buf = malloc(len);
|
||||
if (!buf)
|
||||
return -1;
|
||||
p = buf;
|
||||
ASN1_item_ex_i2d(&val, &p, it, -1, flags);
|
||||
*out = buf;
|
||||
return len;
|
||||
}
|
||||
|
||||
return ASN1_item_ex_i2d(&val, out, it, -1, flags);
|
||||
}
|
||||
|
||||
/* Encode an item, taking care of IMPLICIT tagging (if any).
|
||||
* This function performs the normal item handling: it can be
|
||||
* used in external types.
|
||||
*/
|
||||
|
||||
int
|
||||
ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it,
|
||||
int tag, int aclass)
|
||||
{
|
||||
const ASN1_TEMPLATE *tt = NULL;
|
||||
int i, seqcontlen, seqlen, ndef = 1;
|
||||
const ASN1_EXTERN_FUNCS *ef;
|
||||
const ASN1_AUX *aux = it->funcs;
|
||||
ASN1_aux_cb *asn1_cb = NULL;
|
||||
|
||||
if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval)
|
||||
return 0;
|
||||
|
||||
if (aux && aux->asn1_cb)
|
||||
asn1_cb = aux->asn1_cb;
|
||||
|
||||
switch (it->itype) {
|
||||
|
||||
case ASN1_ITYPE_PRIMITIVE:
|
||||
if (it->templates)
|
||||
return asn1_template_ex_i2d(pval, out, it->templates,
|
||||
tag, aclass);
|
||||
return asn1_i2d_ex_primitive(pval, out, it, tag, aclass);
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_MSTRING:
|
||||
/*
|
||||
* It never makes sense for multi-strings to have implicit
|
||||
* tagging, so if tag != -1, then this looks like an error in
|
||||
* the template.
|
||||
*/
|
||||
if (tag != -1) {
|
||||
ASN1error(ASN1_R_BAD_TEMPLATE);
|
||||
return 0;
|
||||
}
|
||||
return asn1_i2d_ex_primitive(pval, out, it, -1, aclass);
|
||||
|
||||
case ASN1_ITYPE_CHOICE:
|
||||
/*
|
||||
* It never makes sense for CHOICE types to have implicit
|
||||
* tagging, so if tag != -1, then this looks like an error in
|
||||
* the template.
|
||||
*/
|
||||
if (tag != -1) {
|
||||
ASN1error(ASN1_R_BAD_TEMPLATE);
|
||||
return 0;
|
||||
}
|
||||
if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))
|
||||
return 0;
|
||||
i = asn1_get_choice_selector(pval, it);
|
||||
if ((i >= 0) && (i < it->tcount)) {
|
||||
ASN1_VALUE **pchval;
|
||||
const ASN1_TEMPLATE *chtt;
|
||||
chtt = it->templates + i;
|
||||
pchval = asn1_get_field_ptr(pval, chtt);
|
||||
return asn1_template_ex_i2d(pchval, out, chtt,
|
||||
-1, aclass);
|
||||
}
|
||||
/* Fixme: error condition if selector out of range */
|
||||
if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL))
|
||||
return 0;
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_EXTERN:
|
||||
/* If new style i2d it does all the work */
|
||||
ef = it->funcs;
|
||||
return ef->asn1_ex_i2d(pval, out, it, tag, aclass);
|
||||
|
||||
case ASN1_ITYPE_NDEF_SEQUENCE:
|
||||
/* Use indefinite length constructed if requested */
|
||||
if (aclass & ASN1_TFLG_NDEF)
|
||||
ndef = 2;
|
||||
/* fall through */
|
||||
|
||||
case ASN1_ITYPE_SEQUENCE:
|
||||
i = asn1_enc_restore(&seqcontlen, out, pval, it);
|
||||
/* An error occurred */
|
||||
if (i < 0)
|
||||
return 0;
|
||||
/* We have a valid cached encoding... */
|
||||
if (i > 0)
|
||||
return seqcontlen;
|
||||
/* Otherwise carry on */
|
||||
seqcontlen = 0;
|
||||
/* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */
|
||||
if (tag == -1) {
|
||||
tag = V_ASN1_SEQUENCE;
|
||||
/* Retain any other flags in aclass */
|
||||
aclass = (aclass & ~ASN1_TFLG_TAG_CLASS) |
|
||||
V_ASN1_UNIVERSAL;
|
||||
}
|
||||
if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))
|
||||
return 0;
|
||||
/* First work out sequence content length */
|
||||
for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
|
||||
const ASN1_TEMPLATE *seqtt;
|
||||
ASN1_VALUE **pseqval;
|
||||
seqtt = asn1_do_adb(pval, tt, 1);
|
||||
if (!seqtt)
|
||||
return 0;
|
||||
pseqval = asn1_get_field_ptr(pval, seqtt);
|
||||
/* FIXME: check for errors in enhanced version */
|
||||
seqcontlen += asn1_template_ex_i2d(pseqval, NULL, seqtt,
|
||||
-1, aclass);
|
||||
}
|
||||
|
||||
seqlen = ASN1_object_size(ndef, seqcontlen, tag);
|
||||
if (!out)
|
||||
return seqlen;
|
||||
/* Output SEQUENCE header */
|
||||
ASN1_put_object(out, ndef, seqcontlen, tag, aclass);
|
||||
for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
|
||||
const ASN1_TEMPLATE *seqtt;
|
||||
ASN1_VALUE **pseqval;
|
||||
seqtt = asn1_do_adb(pval, tt, 1);
|
||||
if (!seqtt)
|
||||
return 0;
|
||||
pseqval = asn1_get_field_ptr(pval, seqtt);
|
||||
/* FIXME: check for errors in enhanced version */
|
||||
asn1_template_ex_i2d(pseqval, out, seqtt, -1, aclass);
|
||||
}
|
||||
if (ndef == 2)
|
||||
ASN1_put_eoc(out);
|
||||
if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL))
|
||||
return 0;
|
||||
return seqlen;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out,
|
||||
const ASN1_TEMPLATE *tt)
|
||||
{
|
||||
return asn1_template_ex_i2d(pval, out, tt, -1, 0);
|
||||
}
|
||||
|
||||
static int
|
||||
asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
|
||||
const ASN1_TEMPLATE *tt, int tag, int iclass)
|
||||
{
|
||||
int i, ret, flags, ttag, tclass, ndef;
|
||||
flags = tt->flags;
|
||||
/* Work out tag and class to use: tagging may come
|
||||
* either from the template or the arguments, not both
|
||||
* because this would create ambiguity. Additionally
|
||||
* the iclass argument may contain some additional flags
|
||||
* which should be noted and passed down to other levels.
|
||||
*/
|
||||
if (flags & ASN1_TFLG_TAG_MASK) {
|
||||
/* Error if argument and template tagging */
|
||||
if (tag != -1)
|
||||
/* FIXME: error code here */
|
||||
return -1;
|
||||
/* Get tagging from template */
|
||||
ttag = tt->tag;
|
||||
tclass = flags & ASN1_TFLG_TAG_CLASS;
|
||||
} else if (tag != -1) {
|
||||
/* No template tagging, get from arguments */
|
||||
ttag = tag;
|
||||
tclass = iclass & ASN1_TFLG_TAG_CLASS;
|
||||
} else {
|
||||
ttag = -1;
|
||||
tclass = 0;
|
||||
}
|
||||
/*
|
||||
* Remove any class mask from iflag.
|
||||
*/
|
||||
iclass &= ~ASN1_TFLG_TAG_CLASS;
|
||||
|
||||
/* At this point 'ttag' contains the outer tag to use,
|
||||
* 'tclass' is the class and iclass is any flags passed
|
||||
* to this function.
|
||||
*/
|
||||
|
||||
/* if template and arguments require ndef, use it */
|
||||
if ((flags & ASN1_TFLG_NDEF) && (iclass & ASN1_TFLG_NDEF))
|
||||
ndef = 2;
|
||||
else
|
||||
ndef = 1;
|
||||
|
||||
if (flags & ASN1_TFLG_SK_MASK) {
|
||||
/* SET OF, SEQUENCE OF */
|
||||
STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;
|
||||
int isset, sktag, skaclass;
|
||||
int skcontlen, sklen;
|
||||
ASN1_VALUE *skitem;
|
||||
|
||||
if (!*pval)
|
||||
return 0;
|
||||
|
||||
if (flags & ASN1_TFLG_SET_OF) {
|
||||
isset = 1;
|
||||
/* 2 means we reorder */
|
||||
if (flags & ASN1_TFLG_SEQUENCE_OF)
|
||||
isset = 2;
|
||||
} else
|
||||
isset = 0;
|
||||
|
||||
/* Work out inner tag value: if EXPLICIT
|
||||
* or no tagging use underlying type.
|
||||
*/
|
||||
if ((ttag != -1) && !(flags & ASN1_TFLG_EXPTAG)) {
|
||||
sktag = ttag;
|
||||
skaclass = tclass;
|
||||
} else {
|
||||
skaclass = V_ASN1_UNIVERSAL;
|
||||
if (isset)
|
||||
sktag = V_ASN1_SET;
|
||||
else
|
||||
sktag = V_ASN1_SEQUENCE;
|
||||
}
|
||||
|
||||
/* Determine total length of items */
|
||||
skcontlen = 0;
|
||||
for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
|
||||
skitem = sk_ASN1_VALUE_value(sk, i);
|
||||
skcontlen += ASN1_item_ex_i2d(&skitem, NULL,
|
||||
tt->item, -1, iclass);
|
||||
}
|
||||
sklen = ASN1_object_size(ndef, skcontlen, sktag);
|
||||
/* If EXPLICIT need length of surrounding tag */
|
||||
if (flags & ASN1_TFLG_EXPTAG)
|
||||
ret = ASN1_object_size(ndef, sklen, ttag);
|
||||
else
|
||||
ret = sklen;
|
||||
|
||||
if (!out)
|
||||
return ret;
|
||||
|
||||
/* Now encode this lot... */
|
||||
/* EXPLICIT tag */
|
||||
if (flags & ASN1_TFLG_EXPTAG)
|
||||
ASN1_put_object(out, ndef, sklen, ttag, tclass);
|
||||
/* SET or SEQUENCE and IMPLICIT tag */
|
||||
ASN1_put_object(out, ndef, skcontlen, sktag, skaclass);
|
||||
/* And the stuff itself */
|
||||
asn1_set_seq_out(sk, out, skcontlen, tt->item,
|
||||
isset, iclass);
|
||||
if (ndef == 2) {
|
||||
ASN1_put_eoc(out);
|
||||
if (flags & ASN1_TFLG_EXPTAG)
|
||||
ASN1_put_eoc(out);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (flags & ASN1_TFLG_EXPTAG) {
|
||||
/* EXPLICIT tagging */
|
||||
/* Find length of tagged item */
|
||||
i = ASN1_item_ex_i2d(pval, NULL, tt->item,
|
||||
-1, iclass);
|
||||
if (!i)
|
||||
return 0;
|
||||
/* Find length of EXPLICIT tag */
|
||||
ret = ASN1_object_size(ndef, i, ttag);
|
||||
if (out) {
|
||||
/* Output tag and item */
|
||||
ASN1_put_object(out, ndef, i, ttag, tclass);
|
||||
ASN1_item_ex_i2d(pval, out, tt->item,
|
||||
-1, iclass);
|
||||
if (ndef == 2)
|
||||
ASN1_put_eoc(out);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Either normal or IMPLICIT tagging: combine class and flags */
|
||||
return ASN1_item_ex_i2d(pval, out, tt->item,
|
||||
ttag, tclass | iclass);
|
||||
}
|
||||
|
||||
/* Temporary structure used to hold DER encoding of items for SET OF */
|
||||
|
||||
typedef struct {
|
||||
unsigned char *data;
|
||||
int length;
|
||||
ASN1_VALUE *field;
|
||||
} DER_ENC;
|
||||
|
||||
static int
|
||||
der_cmp(const void *a, const void *b)
|
||||
{
|
||||
const DER_ENC *d1 = a, *d2 = b;
|
||||
int cmplen, i;
|
||||
|
||||
cmplen = (d1->length < d2->length) ? d1->length : d2->length;
|
||||
i = memcmp(d1->data, d2->data, cmplen);
|
||||
if (i)
|
||||
return i;
|
||||
return d1->length - d2->length;
|
||||
}
|
||||
|
||||
/* Output the content octets of SET OF or SEQUENCE OF */
|
||||
|
||||
static int
|
||||
asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, int skcontlen,
|
||||
const ASN1_ITEM *item, int do_sort, int iclass)
|
||||
{
|
||||
int i;
|
||||
ASN1_VALUE *skitem;
|
||||
unsigned char *tmpdat = NULL, *p = NULL;
|
||||
DER_ENC *derlst = NULL, *tder;
|
||||
|
||||
if (do_sort) {
|
||||
/* Don't need to sort less than 2 items */
|
||||
if (sk_ASN1_VALUE_num(sk) < 2)
|
||||
do_sort = 0;
|
||||
else {
|
||||
derlst = reallocarray(NULL, sk_ASN1_VALUE_num(sk),
|
||||
sizeof(*derlst));
|
||||
tmpdat = malloc(skcontlen);
|
||||
if (!derlst || !tmpdat) {
|
||||
free(derlst);
|
||||
free(tmpdat);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* If not sorting just output each item */
|
||||
if (!do_sort) {
|
||||
for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
|
||||
skitem = sk_ASN1_VALUE_value(sk, i);
|
||||
ASN1_item_ex_i2d(&skitem, out, item, -1, iclass);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
p = tmpdat;
|
||||
|
||||
/* Doing sort: build up a list of each member's DER encoding */
|
||||
for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) {
|
||||
skitem = sk_ASN1_VALUE_value(sk, i);
|
||||
tder->data = p;
|
||||
tder->length = ASN1_item_ex_i2d(&skitem, &p, item, -1, iclass);
|
||||
tder->field = skitem;
|
||||
}
|
||||
|
||||
/* Now sort them */
|
||||
qsort(derlst, sk_ASN1_VALUE_num(sk), sizeof(*derlst), der_cmp);
|
||||
/* Output sorted DER encoding */
|
||||
p = *out;
|
||||
for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) {
|
||||
memcpy(p, tder->data, tder->length);
|
||||
p += tder->length;
|
||||
}
|
||||
*out = p;
|
||||
/* If do_sort is 2 then reorder the STACK */
|
||||
if (do_sort == 2) {
|
||||
for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++)
|
||||
(void)sk_ASN1_VALUE_set(sk, i, tder->field);
|
||||
}
|
||||
free(derlst);
|
||||
free(tmpdat);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,
|
||||
const ASN1_ITEM *it, int tag, int aclass)
|
||||
{
|
||||
int len;
|
||||
int utype;
|
||||
int usetag;
|
||||
int ndef = 0;
|
||||
|
||||
utype = it->utype;
|
||||
|
||||
/* Get length of content octets and maybe find
|
||||
* out the underlying type.
|
||||
*/
|
||||
|
||||
len = asn1_ex_i2c(pval, NULL, &utype, it);
|
||||
|
||||
/* If SEQUENCE, SET or OTHER then header is
|
||||
* included in pseudo content octets so don't
|
||||
* include tag+length. We need to check here
|
||||
* because the call to asn1_ex_i2c() could change
|
||||
* utype.
|
||||
*/
|
||||
if ((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) ||
|
||||
(utype == V_ASN1_OTHER))
|
||||
usetag = 0;
|
||||
else
|
||||
usetag = 1;
|
||||
|
||||
/* -1 means omit type */
|
||||
if (len == -1)
|
||||
return 0;
|
||||
|
||||
/* -2 return is special meaning use ndef */
|
||||
if (len == -2) {
|
||||
ndef = 2;
|
||||
len = 0;
|
||||
}
|
||||
|
||||
/* If not implicitly tagged get tag from underlying type */
|
||||
if (tag == -1)
|
||||
tag = utype;
|
||||
|
||||
/* Output tag+length followed by content octets */
|
||||
if (out) {
|
||||
if (usetag)
|
||||
ASN1_put_object(out, ndef, len, tag, aclass);
|
||||
asn1_ex_i2c(pval, *out, &utype, it);
|
||||
if (ndef)
|
||||
ASN1_put_eoc(out);
|
||||
else
|
||||
*out += len;
|
||||
}
|
||||
|
||||
if (usetag)
|
||||
return ASN1_object_size(ndef, len, tag);
|
||||
return len;
|
||||
}
|
||||
|
||||
/* Produce content octets from a structure */
|
||||
|
||||
static int
|
||||
asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
|
||||
const ASN1_ITEM *it)
|
||||
{
|
||||
ASN1_BOOLEAN *tbool = NULL;
|
||||
ASN1_STRING *strtmp;
|
||||
ASN1_OBJECT *otmp;
|
||||
int utype;
|
||||
const unsigned char *cont;
|
||||
unsigned char c;
|
||||
int len;
|
||||
|
||||
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) ||
|
||||
(it->utype != V_ASN1_BOOLEAN)) {
|
||||
if (!*pval)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (it->itype == ASN1_ITYPE_MSTRING) {
|
||||
/* If MSTRING type set the underlying type */
|
||||
strtmp = (ASN1_STRING *)*pval;
|
||||
utype = strtmp->type;
|
||||
*putype = utype;
|
||||
} else if (it->utype == V_ASN1_ANY) {
|
||||
/* If ANY set type and pointer to value */
|
||||
ASN1_TYPE *typ;
|
||||
typ = (ASN1_TYPE *)*pval;
|
||||
utype = typ->type;
|
||||
*putype = utype;
|
||||
pval = &typ->value.asn1_value;
|
||||
} else
|
||||
utype = *putype;
|
||||
|
||||
switch (utype) {
|
||||
case V_ASN1_OBJECT:
|
||||
otmp = (ASN1_OBJECT *)*pval;
|
||||
cont = otmp->data;
|
||||
len = otmp->length;
|
||||
break;
|
||||
|
||||
case V_ASN1_NULL:
|
||||
cont = NULL;
|
||||
len = 0;
|
||||
break;
|
||||
|
||||
case V_ASN1_BOOLEAN:
|
||||
tbool = (ASN1_BOOLEAN *)pval;
|
||||
if (*tbool == -1)
|
||||
return -1;
|
||||
if (it->utype != V_ASN1_ANY) {
|
||||
/* Default handling if value == size field then omit */
|
||||
if (*tbool && (it->size > 0))
|
||||
return -1;
|
||||
if (!*tbool && !it->size)
|
||||
return -1;
|
||||
}
|
||||
c = (unsigned char)*tbool;
|
||||
cont = &c;
|
||||
len = 1;
|
||||
break;
|
||||
|
||||
case V_ASN1_BIT_STRING:
|
||||
return i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval,
|
||||
cout ? &cout : NULL);
|
||||
break;
|
||||
|
||||
case V_ASN1_INTEGER:
|
||||
case V_ASN1_ENUMERATED:
|
||||
/* These are all have the same content format
|
||||
* as ASN1_INTEGER
|
||||
*/
|
||||
return i2c_ASN1_INTEGER((ASN1_INTEGER *)*pval,
|
||||
cout ? &cout : NULL);
|
||||
break;
|
||||
|
||||
case V_ASN1_OCTET_STRING:
|
||||
case V_ASN1_NUMERICSTRING:
|
||||
case V_ASN1_PRINTABLESTRING:
|
||||
case V_ASN1_T61STRING:
|
||||
case V_ASN1_VIDEOTEXSTRING:
|
||||
case V_ASN1_IA5STRING:
|
||||
case V_ASN1_UTCTIME:
|
||||
case V_ASN1_GENERALIZEDTIME:
|
||||
case V_ASN1_GRAPHICSTRING:
|
||||
case V_ASN1_VISIBLESTRING:
|
||||
case V_ASN1_GENERALSTRING:
|
||||
case V_ASN1_UNIVERSALSTRING:
|
||||
case V_ASN1_BMPSTRING:
|
||||
case V_ASN1_UTF8STRING:
|
||||
case V_ASN1_SEQUENCE:
|
||||
case V_ASN1_SET:
|
||||
default:
|
||||
/* All based on ASN1_STRING and handled the same */
|
||||
strtmp = (ASN1_STRING *)*pval;
|
||||
/* Special handling for NDEF */
|
||||
if ((it->size == ASN1_TFLG_NDEF) &&
|
||||
(strtmp->flags & ASN1_STRING_FLAG_NDEF)) {
|
||||
if (cout) {
|
||||
strtmp->data = cout;
|
||||
strtmp->length = 0;
|
||||
}
|
||||
/* Special return code */
|
||||
return -2;
|
||||
}
|
||||
cont = strtmp->data;
|
||||
len = strtmp->length;
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
if (cout && len)
|
||||
memcpy(cout, cont, len);
|
||||
return len;
|
||||
}
|
||||
248
externals/libressl/crypto/asn1/tasn_fre.c
vendored
248
externals/libressl/crypto/asn1/tasn_fre.c
vendored
@@ -1,248 +0,0 @@
|
||||
/* $OpenBSD: tasn_fre.c,v 1.18 2022/01/07 12:24:17 tb Exp $ */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 2000.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2000 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stddef.h>
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/objects.h>
|
||||
|
||||
#include "asn1_locl.h"
|
||||
|
||||
static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||
int combine);
|
||||
|
||||
/* Free up an ASN1 structure */
|
||||
|
||||
void
|
||||
ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it)
|
||||
{
|
||||
asn1_item_combine_free(&val, it, 0);
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
||||
{
|
||||
asn1_item_combine_free(pval, it, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
|
||||
{
|
||||
const ASN1_TEMPLATE *tt = NULL, *seqtt;
|
||||
const ASN1_EXTERN_FUNCS *ef;
|
||||
const ASN1_AUX *aux = it->funcs;
|
||||
ASN1_aux_cb *asn1_cb = NULL;
|
||||
int i;
|
||||
|
||||
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)
|
||||
asn1_cb = aux->asn1_cb;
|
||||
|
||||
switch (it->itype) {
|
||||
case ASN1_ITYPE_PRIMITIVE:
|
||||
if (it->templates)
|
||||
ASN1_template_free(pval, it->templates);
|
||||
else
|
||||
ASN1_primitive_free(pval, it);
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_MSTRING:
|
||||
ASN1_primitive_free(pval, it);
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_CHOICE:
|
||||
if (asn1_cb) {
|
||||
i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL);
|
||||
if (i == 2)
|
||||
return;
|
||||
}
|
||||
i = asn1_get_choice_selector(pval, it);
|
||||
if ((i >= 0) && (i < it->tcount)) {
|
||||
ASN1_VALUE **pchval;
|
||||
tt = it->templates + i;
|
||||
pchval = asn1_get_field_ptr(pval, tt);
|
||||
ASN1_template_free(pchval, tt);
|
||||
}
|
||||
if (asn1_cb)
|
||||
asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL);
|
||||
if (!combine) {
|
||||
free(*pval);
|
||||
*pval = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_EXTERN:
|
||||
ef = it->funcs;
|
||||
if (ef && ef->asn1_ex_free)
|
||||
ef->asn1_ex_free(pval, it);
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_NDEF_SEQUENCE:
|
||||
case ASN1_ITYPE_SEQUENCE:
|
||||
if (asn1_do_lock(pval, -1, it) > 0)
|
||||
return;
|
||||
if (asn1_cb) {
|
||||
i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL);
|
||||
if (i == 2)
|
||||
return;
|
||||
}
|
||||
asn1_enc_free(pval, it);
|
||||
/* If we free up as normal we will invalidate any
|
||||
* ANY DEFINED BY field and we wont be able to
|
||||
* determine the type of the field it defines. So
|
||||
* free up in reverse order.
|
||||
*/
|
||||
tt = it->templates + it->tcount - 1;
|
||||
for (i = 0; i < it->tcount; tt--, i++) {
|
||||
ASN1_VALUE **pseqval;
|
||||
seqtt = asn1_do_adb(pval, tt, 0);
|
||||
if (!seqtt)
|
||||
continue;
|
||||
pseqval = asn1_get_field_ptr(pval, seqtt);
|
||||
ASN1_template_free(pseqval, seqtt);
|
||||
}
|
||||
if (asn1_cb)
|
||||
asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL);
|
||||
if (!combine) {
|
||||
free(*pval);
|
||||
*pval = NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
|
||||
{
|
||||
int i;
|
||||
if (tt->flags & ASN1_TFLG_SK_MASK) {
|
||||
STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;
|
||||
for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
|
||||
ASN1_VALUE *vtmp;
|
||||
vtmp = sk_ASN1_VALUE_value(sk, i);
|
||||
asn1_item_combine_free(&vtmp, tt->item,
|
||||
0);
|
||||
}
|
||||
sk_ASN1_VALUE_free(sk);
|
||||
*pval = NULL;
|
||||
} else
|
||||
asn1_item_combine_free(pval, tt->item,
|
||||
tt->flags & ASN1_TFLG_COMBINE);
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
||||
{
|
||||
int utype;
|
||||
|
||||
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;
|
||||
utype = typ->type;
|
||||
pval = &typ->value.asn1_value;
|
||||
if (!*pval)
|
||||
return;
|
||||
} else if (it->itype == ASN1_ITYPE_MSTRING) {
|
||||
utype = -1;
|
||||
if (!*pval)
|
||||
return;
|
||||
} else {
|
||||
utype = it->utype;
|
||||
if ((utype != V_ASN1_BOOLEAN) && !*pval)
|
||||
return;
|
||||
}
|
||||
|
||||
switch (utype) {
|
||||
case V_ASN1_OBJECT:
|
||||
ASN1_OBJECT_free((ASN1_OBJECT *)*pval);
|
||||
break;
|
||||
|
||||
case V_ASN1_BOOLEAN:
|
||||
if (it)
|
||||
*(ASN1_BOOLEAN *)pval = it->size;
|
||||
else
|
||||
*(ASN1_BOOLEAN *)pval = -1;
|
||||
return;
|
||||
|
||||
case V_ASN1_NULL:
|
||||
break;
|
||||
|
||||
case V_ASN1_ANY:
|
||||
ASN1_primitive_free(pval, NULL);
|
||||
free(*pval);
|
||||
break;
|
||||
|
||||
default:
|
||||
ASN1_STRING_free((ASN1_STRING *)*pval);
|
||||
break;
|
||||
}
|
||||
*pval = NULL;
|
||||
}
|
||||
349
externals/libressl/crypto/asn1/tasn_new.c
vendored
349
externals/libressl/crypto/asn1/tasn_new.c
vendored
@@ -1,349 +0,0 @@
|
||||
/* $OpenBSD: tasn_new.c,v 1.21 2022/01/07 12:24:17 tb Exp $ */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 2000.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2000-2004 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stddef.h>
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/asn1t.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "asn1_locl.h"
|
||||
|
||||
static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||
int combine);
|
||||
static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
|
||||
static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
|
||||
ASN1_VALUE *
|
||||
ASN1_item_new(const ASN1_ITEM *it)
|
||||
{
|
||||
ASN1_VALUE *ret = NULL;
|
||||
if (ASN1_item_ex_new(&ret, it) > 0)
|
||||
return ret;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Allocate an ASN1 structure */
|
||||
|
||||
int
|
||||
ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
||||
{
|
||||
return asn1_item_ex_combine_new(pval, it, 0);
|
||||
}
|
||||
|
||||
static int
|
||||
asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
|
||||
{
|
||||
const ASN1_TEMPLATE *tt = NULL;
|
||||
const ASN1_EXTERN_FUNCS *ef;
|
||||
const ASN1_AUX *aux = it->funcs;
|
||||
ASN1_aux_cb *asn1_cb = NULL;
|
||||
ASN1_VALUE **pseqval;
|
||||
int i;
|
||||
|
||||
if (aux != NULL && aux->asn1_cb != NULL)
|
||||
asn1_cb = aux->asn1_cb;
|
||||
|
||||
if (!combine)
|
||||
*pval = NULL;
|
||||
|
||||
|
||||
switch (it->itype) {
|
||||
case ASN1_ITYPE_EXTERN:
|
||||
ef = it->funcs;
|
||||
if (ef && ef->asn1_ex_new) {
|
||||
if (!ef->asn1_ex_new(pval, it))
|
||||
goto memerr;
|
||||
}
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_PRIMITIVE:
|
||||
if (it->templates) {
|
||||
if (!ASN1_template_new(pval, it->templates))
|
||||
goto memerr;
|
||||
} else if (!ASN1_primitive_new(pval, it))
|
||||
goto memerr;
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_MSTRING:
|
||||
if (!ASN1_primitive_new(pval, it))
|
||||
goto memerr;
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_CHOICE:
|
||||
if (asn1_cb) {
|
||||
i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL);
|
||||
if (!i)
|
||||
goto auxerr;
|
||||
if (i == 2) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (!combine) {
|
||||
*pval = calloc(1, it->size);
|
||||
if (!*pval)
|
||||
goto memerr;
|
||||
}
|
||||
asn1_set_choice_selector(pval, -1, it);
|
||||
if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL))
|
||||
goto auxerr;
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_NDEF_SEQUENCE:
|
||||
case ASN1_ITYPE_SEQUENCE:
|
||||
if (asn1_cb) {
|
||||
i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL);
|
||||
if (!i)
|
||||
goto auxerr;
|
||||
if (i == 2) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (!combine) {
|
||||
*pval = calloc(1, it->size);
|
||||
if (!*pval)
|
||||
goto memerr;
|
||||
asn1_do_lock(pval, 0, it);
|
||||
asn1_enc_init(pval, it);
|
||||
}
|
||||
for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
|
||||
pseqval = asn1_get_field_ptr(pval, tt);
|
||||
if (!ASN1_template_new(pseqval, tt))
|
||||
goto memerr;
|
||||
}
|
||||
if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL))
|
||||
goto auxerr;
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
|
||||
memerr:
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
|
||||
auxerr:
|
||||
ASN1error(ASN1_R_AUX_ERROR);
|
||||
ASN1_item_ex_free(pval, it);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
||||
{
|
||||
const ASN1_EXTERN_FUNCS *ef;
|
||||
|
||||
switch (it->itype) {
|
||||
case ASN1_ITYPE_EXTERN:
|
||||
ef = it->funcs;
|
||||
if (ef && ef->asn1_ex_clear)
|
||||
ef->asn1_ex_clear(pval, it);
|
||||
else
|
||||
*pval = NULL;
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_PRIMITIVE:
|
||||
if (it->templates)
|
||||
asn1_template_clear(pval, it->templates);
|
||||
else
|
||||
asn1_primitive_clear(pval, it);
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_MSTRING:
|
||||
asn1_primitive_clear(pval, it);
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_CHOICE:
|
||||
case ASN1_ITYPE_SEQUENCE:
|
||||
case ASN1_ITYPE_NDEF_SEQUENCE:
|
||||
*pval = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
|
||||
{
|
||||
const ASN1_ITEM *it = tt->item;
|
||||
int ret;
|
||||
|
||||
if (tt->flags & ASN1_TFLG_OPTIONAL) {
|
||||
asn1_template_clear(pval, tt);
|
||||
return 1;
|
||||
}
|
||||
/* If ANY DEFINED BY nothing to do */
|
||||
|
||||
if (tt->flags & ASN1_TFLG_ADB_MASK) {
|
||||
*pval = NULL;
|
||||
return 1;
|
||||
}
|
||||
/* If SET OF or SEQUENCE OF, its a STACK */
|
||||
if (tt->flags & ASN1_TFLG_SK_MASK) {
|
||||
STACK_OF(ASN1_VALUE) *skval;
|
||||
skval = sk_ASN1_VALUE_new_null();
|
||||
if (!skval) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
ret = 0;
|
||||
goto done;
|
||||
}
|
||||
*pval = (ASN1_VALUE *)skval;
|
||||
ret = 1;
|
||||
goto done;
|
||||
}
|
||||
/* Otherwise pass it back to the item routine */
|
||||
ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE);
|
||||
done:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
|
||||
{
|
||||
/* If ADB or STACK just NULL the field */
|
||||
if (tt->flags & (ASN1_TFLG_ADB_MASK|ASN1_TFLG_SK_MASK))
|
||||
*pval = NULL;
|
||||
else
|
||||
asn1_item_clear(pval, tt->item);
|
||||
}
|
||||
|
||||
|
||||
/* NB: could probably combine most of the real XXX_new() behaviour and junk
|
||||
* all the old functions.
|
||||
*/
|
||||
|
||||
int
|
||||
ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
||||
{
|
||||
ASN1_TYPE *typ;
|
||||
ASN1_STRING *str;
|
||||
int utype;
|
||||
|
||||
if (it != NULL && it->funcs != NULL) {
|
||||
const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;
|
||||
|
||||
if (pf->prim_new == NULL)
|
||||
return 0;
|
||||
return pf->prim_new(pval, it);
|
||||
}
|
||||
|
||||
if (!it || (it->itype == ASN1_ITYPE_MSTRING))
|
||||
utype = V_ASN1_UNDEF;
|
||||
else
|
||||
utype = it->utype;
|
||||
switch (utype) {
|
||||
case V_ASN1_OBJECT:
|
||||
*pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef);
|
||||
return 1;
|
||||
|
||||
case V_ASN1_BOOLEAN:
|
||||
*(ASN1_BOOLEAN *)pval = it->size;
|
||||
return 1;
|
||||
|
||||
case V_ASN1_NULL:
|
||||
*pval = (ASN1_VALUE *)1;
|
||||
return 1;
|
||||
|
||||
case V_ASN1_ANY:
|
||||
typ = malloc(sizeof(ASN1_TYPE));
|
||||
if (typ != NULL) {
|
||||
typ->value.ptr = NULL;
|
||||
typ->type = V_ASN1_UNDEF;
|
||||
}
|
||||
*pval = (ASN1_VALUE *)typ;
|
||||
break;
|
||||
|
||||
default:
|
||||
str = ASN1_STRING_type_new(utype);
|
||||
if (it != NULL && it->itype == ASN1_ITYPE_MSTRING &&
|
||||
str != NULL)
|
||||
str->flags |= ASN1_STRING_FLAG_MSTRING;
|
||||
*pval = (ASN1_VALUE *)str;
|
||||
break;
|
||||
}
|
||||
if (*pval)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
||||
{
|
||||
int utype;
|
||||
|
||||
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
|
||||
utype = it->utype;
|
||||
if (utype == V_ASN1_BOOLEAN)
|
||||
*(ASN1_BOOLEAN *)pval = it->size;
|
||||
else
|
||||
*pval = NULL;
|
||||
}
|
||||
604
externals/libressl/crypto/asn1/tasn_prn.c
vendored
604
externals/libressl/crypto/asn1/tasn_prn.c
vendored
@@ -1,604 +0,0 @@
|
||||
/* $OpenBSD: tasn_prn.c,v 1.22 2021/12/03 17:10:49 jsing Exp $ */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 2000.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2000,2005 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
#include "asn1_locl.h"
|
||||
|
||||
/* Print routines.
|
||||
*/
|
||||
|
||||
/* ASN1_PCTX routines */
|
||||
|
||||
ASN1_PCTX default_pctx = {
|
||||
ASN1_PCTX_FLAGS_SHOW_ABSENT, /* flags */
|
||||
0, /* nm_flags */
|
||||
0, /* cert_flags */
|
||||
0, /* oid_flags */
|
||||
0 /* str_flags */
|
||||
};
|
||||
|
||||
|
||||
ASN1_PCTX *
|
||||
ASN1_PCTX_new(void)
|
||||
{
|
||||
ASN1_PCTX *p;
|
||||
|
||||
if ((p = calloc(1, sizeof(ASN1_PCTX))) == NULL) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_PCTX_free(ASN1_PCTX *p)
|
||||
{
|
||||
free(p);
|
||||
}
|
||||
|
||||
unsigned long
|
||||
ASN1_PCTX_get_flags(const ASN1_PCTX *p)
|
||||
{
|
||||
return p->flags;
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_PCTX_set_flags(ASN1_PCTX *p, unsigned long flags)
|
||||
{
|
||||
p->flags = flags;
|
||||
}
|
||||
|
||||
unsigned long
|
||||
ASN1_PCTX_get_nm_flags(const ASN1_PCTX *p)
|
||||
{
|
||||
return p->nm_flags;
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_PCTX_set_nm_flags(ASN1_PCTX *p, unsigned long flags)
|
||||
{
|
||||
p->nm_flags = flags;
|
||||
}
|
||||
|
||||
unsigned long
|
||||
ASN1_PCTX_get_cert_flags(const ASN1_PCTX *p)
|
||||
{
|
||||
return p->cert_flags;
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_PCTX_set_cert_flags(ASN1_PCTX *p, unsigned long flags)
|
||||
{
|
||||
p->cert_flags = flags;
|
||||
}
|
||||
|
||||
unsigned long
|
||||
ASN1_PCTX_get_oid_flags(const ASN1_PCTX *p)
|
||||
{
|
||||
return p->oid_flags;
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_PCTX_set_oid_flags(ASN1_PCTX *p, unsigned long flags)
|
||||
{
|
||||
p->oid_flags = flags;
|
||||
}
|
||||
|
||||
unsigned long
|
||||
ASN1_PCTX_get_str_flags(const ASN1_PCTX *p)
|
||||
{
|
||||
return p->str_flags;
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags)
|
||||
{
|
||||
p->str_flags = flags;
|
||||
}
|
||||
|
||||
/* Main print routines */
|
||||
|
||||
static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
|
||||
const ASN1_ITEM *it, const char *fname, const char *sname, int nohdr,
|
||||
const ASN1_PCTX *pctx);
|
||||
|
||||
int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
|
||||
const ASN1_TEMPLATE *tt, const ASN1_PCTX *pctx);
|
||||
|
||||
static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld,
|
||||
const ASN1_ITEM *it, int indent, const char *fname, const char *sname,
|
||||
const ASN1_PCTX *pctx);
|
||||
|
||||
static int asn1_print_fsname(BIO *out, int indent, const char *fname,
|
||||
const char *sname, const ASN1_PCTX *pctx);
|
||||
|
||||
int
|
||||
ASN1_item_print(BIO *out, ASN1_VALUE *ifld, int indent, const ASN1_ITEM *it,
|
||||
const ASN1_PCTX *pctx)
|
||||
{
|
||||
const char *sname;
|
||||
|
||||
if (pctx == NULL)
|
||||
pctx = &default_pctx;
|
||||
if (pctx->flags & ASN1_PCTX_FLAGS_NO_STRUCT_NAME)
|
||||
sname = NULL;
|
||||
else
|
||||
sname = it->sname;
|
||||
return asn1_item_print_ctx(out, &ifld, indent, it, NULL, sname,
|
||||
0, pctx);
|
||||
}
|
||||
|
||||
static int
|
||||
asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, const ASN1_ITEM *it,
|
||||
const char *fname, const char *sname, int nohdr, const ASN1_PCTX *pctx)
|
||||
{
|
||||
const ASN1_TEMPLATE *tt;
|
||||
const ASN1_EXTERN_FUNCS *ef;
|
||||
ASN1_VALUE **tmpfld;
|
||||
const ASN1_AUX *aux = it->funcs;
|
||||
ASN1_aux_cb *asn1_cb;
|
||||
ASN1_PRINT_ARG parg;
|
||||
int i;
|
||||
|
||||
if (aux && aux->asn1_cb) {
|
||||
parg.out = out;
|
||||
parg.indent = indent;
|
||||
parg.pctx = pctx;
|
||||
asn1_cb = aux->asn1_cb;
|
||||
} else
|
||||
asn1_cb = 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))
|
||||
return 0;
|
||||
if (BIO_puts(out, "<ABSENT>\n") <= 0)
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
switch (it->itype) {
|
||||
case ASN1_ITYPE_PRIMITIVE:
|
||||
if (it->templates) {
|
||||
if (!asn1_template_print_ctx(out, fld, indent,
|
||||
it->templates, pctx))
|
||||
return 0;
|
||||
}
|
||||
/* fall thru */
|
||||
case ASN1_ITYPE_MSTRING:
|
||||
if (!asn1_primitive_print(out, fld, it,
|
||||
indent, fname, sname, pctx))
|
||||
return 0;
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_EXTERN:
|
||||
if (!nohdr &&
|
||||
!asn1_print_fsname(out, indent, fname, sname, pctx))
|
||||
return 0;
|
||||
/* Use new style print routine if possible */
|
||||
ef = it->funcs;
|
||||
if (ef && ef->asn1_ex_print) {
|
||||
i = ef->asn1_ex_print(out, fld, indent, "", pctx);
|
||||
if (!i)
|
||||
return 0;
|
||||
if ((i == 2) && (BIO_puts(out, "\n") <= 0))
|
||||
return 0;
|
||||
return 1;
|
||||
} else if (sname &&
|
||||
BIO_printf(out, ":EXTERNAL TYPE %s\n", sname) <= 0)
|
||||
return 0;
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_CHOICE:
|
||||
/* CHOICE type, get selector */
|
||||
i = asn1_get_choice_selector(fld, it);
|
||||
/* This should never happen... */
|
||||
if ((i < 0) || (i >= it->tcount)) {
|
||||
if (BIO_printf(out,
|
||||
"ERROR: selector [%d] invalid\n", i) <= 0)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
tt = it->templates + i;
|
||||
tmpfld = asn1_get_field_ptr(fld, tt);
|
||||
if (!asn1_template_print_ctx(out, tmpfld, indent, tt, pctx))
|
||||
return 0;
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_SEQUENCE:
|
||||
case ASN1_ITYPE_NDEF_SEQUENCE:
|
||||
if (!nohdr &&
|
||||
!asn1_print_fsname(out, indent, fname, sname, pctx))
|
||||
return 0;
|
||||
if (fname || sname) {
|
||||
if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) {
|
||||
if (BIO_puts(out, " {\n") <= 0)
|
||||
return 0;
|
||||
} else {
|
||||
if (BIO_puts(out, "\n") <= 0)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (asn1_cb) {
|
||||
i = asn1_cb(ASN1_OP_PRINT_PRE, fld, it, &parg);
|
||||
if (i == 0)
|
||||
return 0;
|
||||
if (i == 2)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Print each field entry */
|
||||
for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
|
||||
const ASN1_TEMPLATE *seqtt;
|
||||
|
||||
seqtt = asn1_do_adb(fld, tt, 1);
|
||||
if (seqtt == NULL)
|
||||
return 0;
|
||||
tmpfld = asn1_get_field_ptr(fld, seqtt);
|
||||
if (!asn1_template_print_ctx(out, tmpfld, indent + 2,
|
||||
seqtt, pctx))
|
||||
return 0;
|
||||
}
|
||||
if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) {
|
||||
if (BIO_printf(out, "%*s}\n", indent, "") < 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (asn1_cb) {
|
||||
i = asn1_cb(ASN1_OP_PRINT_POST, fld, it, &parg);
|
||||
if (i == 0)
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
BIO_printf(out, "Unprocessed type %d\n", it->itype);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
|
||||
const ASN1_TEMPLATE *tt, const ASN1_PCTX *pctx)
|
||||
{
|
||||
int i, flags;
|
||||
const char *sname, *fname;
|
||||
|
||||
flags = tt->flags;
|
||||
if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_FIELD_STRUCT_NAME)
|
||||
sname = tt->item->sname;
|
||||
else
|
||||
sname = NULL;
|
||||
if (pctx->flags & ASN1_PCTX_FLAGS_NO_FIELD_NAME)
|
||||
fname = NULL;
|
||||
else
|
||||
fname = tt->field_name;
|
||||
if (flags & ASN1_TFLG_SK_MASK) {
|
||||
char *tname;
|
||||
ASN1_VALUE *skitem;
|
||||
STACK_OF(ASN1_VALUE) *stack;
|
||||
|
||||
/* SET OF, SEQUENCE OF */
|
||||
if (fname) {
|
||||
if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SSOF) {
|
||||
if (flags & ASN1_TFLG_SET_OF)
|
||||
tname = "SET";
|
||||
else
|
||||
tname = "SEQUENCE";
|
||||
if (BIO_printf(out, "%*s%s OF %s {\n",
|
||||
indent, "", tname, tt->field_name) <= 0)
|
||||
return 0;
|
||||
} else if (BIO_printf(out, "%*s%s:\n", indent, "",
|
||||
fname) <= 0)
|
||||
return 0;
|
||||
}
|
||||
stack = (STACK_OF(ASN1_VALUE) *)*fld;
|
||||
for (i = 0; i < sk_ASN1_VALUE_num(stack); i++) {
|
||||
if ((i > 0) && (BIO_puts(out, "\n") <= 0))
|
||||
return 0;
|
||||
skitem = sk_ASN1_VALUE_value(stack, i);
|
||||
if (!asn1_item_print_ctx(out, &skitem, indent + 2,
|
||||
tt->item, NULL, NULL, 1, pctx))
|
||||
return 0;
|
||||
}
|
||||
if (!i && BIO_printf(out, "%*s<EMPTY>\n", indent + 2, "") <= 0)
|
||||
return 0;
|
||||
if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) {
|
||||
if (BIO_printf(out, "%*s}\n", indent, "") <= 0)
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return asn1_item_print_ctx(out, fld, indent, tt->item,
|
||||
fname, sname, 0, pctx);
|
||||
}
|
||||
|
||||
static int
|
||||
asn1_print_fsname(BIO *out, int indent, const char *fname, const char *sname,
|
||||
const ASN1_PCTX *pctx)
|
||||
{
|
||||
static char spaces[] = " ";
|
||||
const int nspaces = sizeof(spaces) - 1;
|
||||
|
||||
while (indent > nspaces) {
|
||||
if (BIO_write(out, spaces, nspaces) != nspaces)
|
||||
return 0;
|
||||
indent -= nspaces;
|
||||
}
|
||||
if (BIO_write(out, spaces, indent) != indent)
|
||||
return 0;
|
||||
if (pctx->flags & ASN1_PCTX_FLAGS_NO_STRUCT_NAME)
|
||||
sname = NULL;
|
||||
if (pctx->flags & ASN1_PCTX_FLAGS_NO_FIELD_NAME)
|
||||
fname = NULL;
|
||||
if (!sname && !fname)
|
||||
return 1;
|
||||
if (fname) {
|
||||
if (BIO_puts(out, fname) <= 0)
|
||||
return 0;
|
||||
}
|
||||
if (sname) {
|
||||
if (fname) {
|
||||
if (BIO_printf(out, " (%s)", sname) <= 0)
|
||||
return 0;
|
||||
} else {
|
||||
if (BIO_puts(out, sname) <= 0)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (BIO_write(out, ": ", 2) != 2)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
asn1_print_boolean_ctx(BIO *out, int boolval, const ASN1_PCTX *pctx)
|
||||
{
|
||||
const char *str;
|
||||
switch (boolval) {
|
||||
case -1:
|
||||
str = "BOOL ABSENT";
|
||||
break;
|
||||
|
||||
case 0:
|
||||
str = "FALSE";
|
||||
break;
|
||||
|
||||
default:
|
||||
str = "TRUE";
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (BIO_puts(out, str) <= 0)
|
||||
return 0;
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
static int
|
||||
asn1_print_integer_ctx(BIO *out, ASN1_INTEGER *str, const ASN1_PCTX *pctx)
|
||||
{
|
||||
char *s;
|
||||
int ret = 1;
|
||||
if ((s = i2s_ASN1_INTEGER(NULL, str)) == NULL)
|
||||
return 0;
|
||||
if (BIO_puts(out, s) <= 0)
|
||||
ret = 0;
|
||||
free(s);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
asn1_print_oid_ctx(BIO *out, const ASN1_OBJECT *oid, const ASN1_PCTX *pctx)
|
||||
{
|
||||
char objbuf[80];
|
||||
const char *ln;
|
||||
ln = OBJ_nid2ln(OBJ_obj2nid(oid));
|
||||
if (!ln)
|
||||
ln = "";
|
||||
OBJ_obj2txt(objbuf, sizeof objbuf, oid, 1);
|
||||
if (BIO_printf(out, "%s (%s)", ln, objbuf) <= 0)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
asn1_print_obstring_ctx(BIO *out, ASN1_STRING *str, int indent,
|
||||
const ASN1_PCTX *pctx)
|
||||
{
|
||||
if (str->type == V_ASN1_BIT_STRING) {
|
||||
if (BIO_printf(out, " (%ld unused bits)\n",
|
||||
str->flags & 0x7) <= 0)
|
||||
return 0;
|
||||
} else if (BIO_puts(out, "\n") <= 0)
|
||||
return 0;
|
||||
if ((str->length > 0) &&
|
||||
BIO_dump_indent(out, (char *)str->data, str->length,
|
||||
indent + 2) <= 0)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
asn1_primitive_print(BIO *out, ASN1_VALUE **fld, const ASN1_ITEM *it,
|
||||
int indent, const char *fname, const char *sname, const ASN1_PCTX *pctx)
|
||||
{
|
||||
long utype;
|
||||
ASN1_STRING *str;
|
||||
int ret = 1, needlf = 1;
|
||||
const char *pname;
|
||||
|
||||
if (!asn1_print_fsname(out, indent, fname, sname, pctx))
|
||||
return 0;
|
||||
|
||||
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);
|
||||
}
|
||||
if (it->itype == ASN1_ITYPE_MSTRING) {
|
||||
str = (ASN1_STRING *)*fld;
|
||||
utype = str->type & ~V_ASN1_NEG;
|
||||
} 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;
|
||||
fld = &atype->value.asn1_value;
|
||||
str = (ASN1_STRING *)*fld;
|
||||
if (pctx->flags & ASN1_PCTX_FLAGS_NO_ANY_TYPE)
|
||||
pname = NULL;
|
||||
else
|
||||
pname = ASN1_tag2str(utype);
|
||||
} else {
|
||||
if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_TYPE)
|
||||
pname = ASN1_tag2str(utype);
|
||||
else
|
||||
pname = NULL;
|
||||
}
|
||||
|
||||
if (utype == V_ASN1_NULL) {
|
||||
if (BIO_puts(out, "NULL\n") <= 0)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (pname) {
|
||||
if (BIO_puts(out, pname) <= 0)
|
||||
return 0;
|
||||
if (BIO_puts(out, ":") <= 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (utype) {
|
||||
case V_ASN1_BOOLEAN:
|
||||
{
|
||||
int boolval = *(int *)fld;
|
||||
if (boolval == -1)
|
||||
boolval = it->size;
|
||||
ret = asn1_print_boolean_ctx(out, boolval, pctx);
|
||||
}
|
||||
break;
|
||||
|
||||
case V_ASN1_INTEGER:
|
||||
case V_ASN1_ENUMERATED:
|
||||
ret = asn1_print_integer_ctx(out, str, pctx);
|
||||
break;
|
||||
|
||||
case V_ASN1_UTCTIME:
|
||||
ret = ASN1_UTCTIME_print(out, str);
|
||||
break;
|
||||
|
||||
case V_ASN1_GENERALIZEDTIME:
|
||||
ret = ASN1_GENERALIZEDTIME_print(out, str);
|
||||
break;
|
||||
|
||||
case V_ASN1_OBJECT:
|
||||
ret = asn1_print_oid_ctx(out, (const ASN1_OBJECT *)*fld, pctx);
|
||||
break;
|
||||
|
||||
case V_ASN1_OCTET_STRING:
|
||||
case V_ASN1_BIT_STRING:
|
||||
ret = asn1_print_obstring_ctx(out, str, indent, pctx);
|
||||
needlf = 0;
|
||||
break;
|
||||
|
||||
case V_ASN1_SEQUENCE:
|
||||
case V_ASN1_SET:
|
||||
case V_ASN1_OTHER:
|
||||
if (BIO_puts(out, "\n") <= 0)
|
||||
return 0;
|
||||
if (ASN1_parse_dump(out, str->data, str->length,
|
||||
indent, 0) <= 0)
|
||||
ret = 0;
|
||||
needlf = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = ASN1_STRING_print_ex(out, str, pctx->str_flags);
|
||||
}
|
||||
if (!ret)
|
||||
return 0;
|
||||
if (needlf && BIO_puts(out, "\n") <= 0)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
661
externals/libressl/crypto/asn1/tasn_typ.c
vendored
661
externals/libressl/crypto/asn1/tasn_typ.c
vendored
@@ -1,661 +0,0 @@
|
||||
/* $OpenBSD: tasn_typ.c,v 1.17 2021/12/26 15:20:21 tb Exp $ */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 2000.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2000 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/asn1t.h>
|
||||
|
||||
/* Declarations for string types */
|
||||
|
||||
const ASN1_ITEM ASN1_NULL_it = {
|
||||
.itype = ASN1_ITYPE_PRIMITIVE,
|
||||
.utype = V_ASN1_NULL,
|
||||
.sname = "ASN1_NULL",
|
||||
};
|
||||
|
||||
ASN1_NULL *
|
||||
d2i_ASN1_NULL(ASN1_NULL **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (ASN1_NULL *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&ASN1_NULL_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_ASN1_NULL(ASN1_NULL *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_NULL_it);
|
||||
}
|
||||
|
||||
ASN1_NULL *
|
||||
ASN1_NULL_new(void)
|
||||
{
|
||||
return (ASN1_NULL *)ASN1_item_new(&ASN1_NULL_it);
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_NULL_free(ASN1_NULL *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &ASN1_NULL_it);
|
||||
}
|
||||
|
||||
|
||||
const ASN1_ITEM ASN1_UTF8STRING_it = {
|
||||
.itype = ASN1_ITYPE_PRIMITIVE,
|
||||
.utype = V_ASN1_UTF8STRING,
|
||||
.sname = "ASN1_UTF8STRING",
|
||||
};
|
||||
|
||||
ASN1_UTF8STRING *
|
||||
d2i_ASN1_UTF8STRING(ASN1_UTF8STRING **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (ASN1_UTF8STRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&ASN1_UTF8STRING_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_ASN1_UTF8STRING(ASN1_UTF8STRING *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_UTF8STRING_it);
|
||||
}
|
||||
|
||||
ASN1_UTF8STRING *
|
||||
ASN1_UTF8STRING_new(void)
|
||||
{
|
||||
return (ASN1_UTF8STRING *)ASN1_item_new(&ASN1_UTF8STRING_it);
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_UTF8STRING_free(ASN1_UTF8STRING *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &ASN1_UTF8STRING_it);
|
||||
}
|
||||
|
||||
|
||||
const ASN1_ITEM ASN1_PRINTABLESTRING_it = {
|
||||
.itype = ASN1_ITYPE_PRIMITIVE,
|
||||
.utype = V_ASN1_PRINTABLESTRING,
|
||||
.sname = "ASN1_PRINTABLESTRING",
|
||||
};
|
||||
|
||||
ASN1_PRINTABLESTRING *
|
||||
d2i_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING **a, const unsigned char **in,
|
||||
long len)
|
||||
{
|
||||
return (ASN1_PRINTABLESTRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&ASN1_PRINTABLESTRING_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_PRINTABLESTRING_it);
|
||||
}
|
||||
|
||||
ASN1_PRINTABLESTRING *
|
||||
ASN1_PRINTABLESTRING_new(void)
|
||||
{
|
||||
return (ASN1_PRINTABLESTRING *)ASN1_item_new(&ASN1_PRINTABLESTRING_it);
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_PRINTABLESTRING_free(ASN1_PRINTABLESTRING *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &ASN1_PRINTABLESTRING_it);
|
||||
}
|
||||
|
||||
|
||||
const ASN1_ITEM ASN1_T61STRING_it = {
|
||||
.itype = ASN1_ITYPE_PRIMITIVE,
|
||||
.utype = V_ASN1_T61STRING,
|
||||
.sname = "ASN1_T61STRING",
|
||||
};
|
||||
|
||||
ASN1_T61STRING *
|
||||
d2i_ASN1_T61STRING(ASN1_T61STRING **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (ASN1_T61STRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&ASN1_T61STRING_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_ASN1_T61STRING(ASN1_T61STRING *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_T61STRING_it);
|
||||
}
|
||||
|
||||
ASN1_T61STRING *
|
||||
ASN1_T61STRING_new(void)
|
||||
{
|
||||
return (ASN1_T61STRING *)ASN1_item_new(&ASN1_T61STRING_it);
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_T61STRING_free(ASN1_T61STRING *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &ASN1_T61STRING_it);
|
||||
}
|
||||
|
||||
|
||||
const ASN1_ITEM ASN1_IA5STRING_it = {
|
||||
.itype = ASN1_ITYPE_PRIMITIVE,
|
||||
.utype = V_ASN1_IA5STRING,
|
||||
.sname = "ASN1_IA5STRING",
|
||||
};
|
||||
|
||||
ASN1_IA5STRING *
|
||||
d2i_ASN1_IA5STRING(ASN1_IA5STRING **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (ASN1_IA5STRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&ASN1_IA5STRING_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_ASN1_IA5STRING(ASN1_IA5STRING *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_IA5STRING_it);
|
||||
}
|
||||
|
||||
ASN1_IA5STRING *
|
||||
ASN1_IA5STRING_new(void)
|
||||
{
|
||||
return (ASN1_IA5STRING *)ASN1_item_new(&ASN1_IA5STRING_it);
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_IA5STRING_free(ASN1_IA5STRING *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &ASN1_IA5STRING_it);
|
||||
}
|
||||
|
||||
|
||||
const ASN1_ITEM ASN1_GENERALSTRING_it = {
|
||||
.itype = ASN1_ITYPE_PRIMITIVE,
|
||||
.utype = V_ASN1_GENERALSTRING,
|
||||
.sname = "ASN1_GENERALSTRING",
|
||||
};
|
||||
|
||||
ASN1_GENERALSTRING *
|
||||
d2i_ASN1_GENERALSTRING(ASN1_GENERALSTRING **a, const unsigned char **in,
|
||||
long len)
|
||||
{
|
||||
return (ASN1_GENERALSTRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&ASN1_GENERALSTRING_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_ASN1_GENERALSTRING(ASN1_GENERALSTRING *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_GENERALSTRING_it);
|
||||
}
|
||||
|
||||
ASN1_GENERALSTRING *
|
||||
ASN1_GENERALSTRING_new(void)
|
||||
{
|
||||
return (ASN1_GENERALSTRING *)ASN1_item_new(&ASN1_GENERALSTRING_it);
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_GENERALSTRING_free(ASN1_GENERALSTRING *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &ASN1_GENERALSTRING_it);
|
||||
}
|
||||
|
||||
|
||||
const ASN1_ITEM ASN1_UTCTIME_it = {
|
||||
.itype = ASN1_ITYPE_PRIMITIVE,
|
||||
.utype = V_ASN1_UTCTIME,
|
||||
.sname = "ASN1_UTCTIME",
|
||||
};
|
||||
|
||||
ASN1_UTCTIME *
|
||||
d2i_ASN1_UTCTIME(ASN1_UTCTIME **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (ASN1_UTCTIME *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&ASN1_UTCTIME_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_ASN1_UTCTIME(ASN1_UTCTIME *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_UTCTIME_it);
|
||||
}
|
||||
|
||||
ASN1_UTCTIME *
|
||||
ASN1_UTCTIME_new(void)
|
||||
{
|
||||
return (ASN1_UTCTIME *)ASN1_item_new(&ASN1_UTCTIME_it);
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_UTCTIME_free(ASN1_UTCTIME *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &ASN1_UTCTIME_it);
|
||||
}
|
||||
|
||||
|
||||
const ASN1_ITEM ASN1_GENERALIZEDTIME_it = {
|
||||
.itype = ASN1_ITYPE_PRIMITIVE,
|
||||
.utype = V_ASN1_GENERALIZEDTIME,
|
||||
.sname = "ASN1_GENERALIZEDTIME",
|
||||
};
|
||||
|
||||
ASN1_GENERALIZEDTIME *
|
||||
d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a, const unsigned char **in,
|
||||
long len)
|
||||
{
|
||||
return (ASN1_GENERALIZEDTIME *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&ASN1_GENERALIZEDTIME_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_GENERALIZEDTIME_it);
|
||||
}
|
||||
|
||||
ASN1_GENERALIZEDTIME *
|
||||
ASN1_GENERALIZEDTIME_new(void)
|
||||
{
|
||||
return (ASN1_GENERALIZEDTIME *)ASN1_item_new(&ASN1_GENERALIZEDTIME_it);
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_GENERALIZEDTIME_free(ASN1_GENERALIZEDTIME *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &ASN1_GENERALIZEDTIME_it);
|
||||
}
|
||||
|
||||
|
||||
const ASN1_ITEM ASN1_VISIBLESTRING_it = {
|
||||
.itype = ASN1_ITYPE_PRIMITIVE,
|
||||
.utype = V_ASN1_VISIBLESTRING,
|
||||
.sname = "ASN1_VISIBLESTRING",
|
||||
};
|
||||
|
||||
ASN1_VISIBLESTRING *
|
||||
d2i_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING **a, const unsigned char **in,
|
||||
long len)
|
||||
{
|
||||
return (ASN1_VISIBLESTRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&ASN1_VISIBLESTRING_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_VISIBLESTRING_it);
|
||||
}
|
||||
|
||||
ASN1_VISIBLESTRING *
|
||||
ASN1_VISIBLESTRING_new(void)
|
||||
{
|
||||
return (ASN1_VISIBLESTRING *)ASN1_item_new(&ASN1_VISIBLESTRING_it);
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_VISIBLESTRING_free(ASN1_VISIBLESTRING *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &ASN1_VISIBLESTRING_it);
|
||||
}
|
||||
|
||||
|
||||
const ASN1_ITEM ASN1_UNIVERSALSTRING_it = {
|
||||
.itype = ASN1_ITYPE_PRIMITIVE,
|
||||
.utype = V_ASN1_UNIVERSALSTRING,
|
||||
.sname = "ASN1_UNIVERSALSTRING",
|
||||
};
|
||||
|
||||
ASN1_UNIVERSALSTRING *
|
||||
d2i_ASN1_UNIVERSALSTRING(ASN1_UNIVERSALSTRING **a, const unsigned char **in,
|
||||
long len)
|
||||
{
|
||||
return (ASN1_UNIVERSALSTRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&ASN1_UNIVERSALSTRING_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_ASN1_UNIVERSALSTRING(ASN1_UNIVERSALSTRING *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_UNIVERSALSTRING_it);
|
||||
}
|
||||
|
||||
ASN1_UNIVERSALSTRING *
|
||||
ASN1_UNIVERSALSTRING_new(void)
|
||||
{
|
||||
return (ASN1_UNIVERSALSTRING *)ASN1_item_new(&ASN1_UNIVERSALSTRING_it);
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_UNIVERSALSTRING_free(ASN1_UNIVERSALSTRING *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &ASN1_UNIVERSALSTRING_it);
|
||||
}
|
||||
|
||||
|
||||
const ASN1_ITEM ASN1_BMPSTRING_it = {
|
||||
.itype = ASN1_ITYPE_PRIMITIVE,
|
||||
.utype = V_ASN1_BMPSTRING,
|
||||
.sname = "ASN1_BMPSTRING",
|
||||
};
|
||||
|
||||
ASN1_BMPSTRING *
|
||||
d2i_ASN1_BMPSTRING(ASN1_BMPSTRING **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (ASN1_BMPSTRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&ASN1_BMPSTRING_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_ASN1_BMPSTRING(ASN1_BMPSTRING *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_BMPSTRING_it);
|
||||
}
|
||||
|
||||
ASN1_BMPSTRING *
|
||||
ASN1_BMPSTRING_new(void)
|
||||
{
|
||||
return (ASN1_BMPSTRING *)ASN1_item_new(&ASN1_BMPSTRING_it);
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_BMPSTRING_free(ASN1_BMPSTRING *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &ASN1_BMPSTRING_it);
|
||||
}
|
||||
|
||||
const ASN1_ITEM ASN1_ANY_it = {
|
||||
.itype = ASN1_ITYPE_PRIMITIVE,
|
||||
.utype = V_ASN1_ANY,
|
||||
.sname = "ASN1_ANY",
|
||||
};
|
||||
|
||||
|
||||
/* Just swallow an ASN1_SEQUENCE in an ASN1_STRING */
|
||||
|
||||
const ASN1_ITEM ASN1_SEQUENCE_it = {
|
||||
.itype = ASN1_ITYPE_PRIMITIVE,
|
||||
.utype = V_ASN1_SEQUENCE,
|
||||
.sname = "ASN1_SEQUENCE",
|
||||
};
|
||||
|
||||
|
||||
/* Multistring types */
|
||||
|
||||
|
||||
const ASN1_ITEM ASN1_PRINTABLE_it = {
|
||||
.itype = ASN1_ITYPE_MSTRING,
|
||||
.utype = B_ASN1_PRINTABLE,
|
||||
.templates = NULL,
|
||||
.tcount = 0,
|
||||
.funcs = NULL,
|
||||
.size = sizeof(ASN1_STRING),
|
||||
.sname = "ASN1_PRINTABLE",
|
||||
};
|
||||
|
||||
ASN1_STRING *
|
||||
d2i_ASN1_PRINTABLE(ASN1_STRING **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (ASN1_STRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&ASN1_PRINTABLE_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_ASN1_PRINTABLE(ASN1_STRING *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_PRINTABLE_it);
|
||||
}
|
||||
|
||||
ASN1_STRING *
|
||||
ASN1_PRINTABLE_new(void)
|
||||
{
|
||||
return (ASN1_STRING *)ASN1_item_new(&ASN1_PRINTABLE_it);
|
||||
}
|
||||
|
||||
void
|
||||
ASN1_PRINTABLE_free(ASN1_STRING *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &ASN1_PRINTABLE_it);
|
||||
}
|
||||
|
||||
|
||||
const ASN1_ITEM DISPLAYTEXT_it = {
|
||||
.itype = ASN1_ITYPE_MSTRING,
|
||||
.utype = B_ASN1_DISPLAYTEXT,
|
||||
.templates = NULL,
|
||||
.tcount = 0,
|
||||
.funcs = NULL,
|
||||
.size = sizeof(ASN1_STRING),
|
||||
.sname = "DISPLAYTEXT",
|
||||
};
|
||||
|
||||
ASN1_STRING *
|
||||
d2i_DISPLAYTEXT(ASN1_STRING **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (ASN1_STRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&DISPLAYTEXT_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_DISPLAYTEXT(ASN1_STRING *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &DISPLAYTEXT_it);
|
||||
}
|
||||
|
||||
ASN1_STRING *
|
||||
DISPLAYTEXT_new(void)
|
||||
{
|
||||
return (ASN1_STRING *)ASN1_item_new(&DISPLAYTEXT_it);
|
||||
}
|
||||
|
||||
void
|
||||
DISPLAYTEXT_free(ASN1_STRING *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &DISPLAYTEXT_it);
|
||||
}
|
||||
|
||||
|
||||
const ASN1_ITEM DIRECTORYSTRING_it = {
|
||||
.itype = ASN1_ITYPE_MSTRING,
|
||||
.utype = B_ASN1_DIRECTORYSTRING,
|
||||
.templates = NULL,
|
||||
.tcount = 0,
|
||||
.funcs = NULL,
|
||||
.size = sizeof(ASN1_STRING),
|
||||
.sname = "DIRECTORYSTRING",
|
||||
};
|
||||
|
||||
ASN1_STRING *
|
||||
d2i_DIRECTORYSTRING(ASN1_STRING **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (ASN1_STRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&DIRECTORYSTRING_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_DIRECTORYSTRING(ASN1_STRING *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &DIRECTORYSTRING_it);
|
||||
}
|
||||
|
||||
ASN1_STRING *
|
||||
DIRECTORYSTRING_new(void)
|
||||
{
|
||||
return (ASN1_STRING *)ASN1_item_new(&DIRECTORYSTRING_it);
|
||||
}
|
||||
|
||||
void
|
||||
DIRECTORYSTRING_free(ASN1_STRING *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &DIRECTORYSTRING_it);
|
||||
}
|
||||
|
||||
/* Three separate BOOLEAN type: normal, DEFAULT TRUE and DEFAULT FALSE */
|
||||
|
||||
const ASN1_ITEM ASN1_BOOLEAN_it = {
|
||||
.itype = ASN1_ITYPE_PRIMITIVE,
|
||||
.utype = V_ASN1_BOOLEAN,
|
||||
.size = -1,
|
||||
.sname = "ASN1_BOOLEAN",
|
||||
};
|
||||
|
||||
int
|
||||
i2d_ASN1_BOOLEAN(int a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_ex_i2d((ASN1_VALUE **)&a, out,
|
||||
&ASN1_BOOLEAN_it, -1, 0);
|
||||
}
|
||||
|
||||
int
|
||||
d2i_ASN1_BOOLEAN(int *a, const unsigned char **in, long len)
|
||||
{
|
||||
ASN1_BOOLEAN abool;
|
||||
|
||||
if (ASN1_item_ex_d2i((ASN1_VALUE **)&abool, in, len, &ASN1_BOOLEAN_it,
|
||||
-1, 0, 0, NULL) <= 0)
|
||||
return -1;
|
||||
|
||||
if (a != NULL)
|
||||
*a = abool;
|
||||
|
||||
return abool;
|
||||
}
|
||||
|
||||
const ASN1_ITEM ASN1_TBOOLEAN_it = {
|
||||
.itype = ASN1_ITYPE_PRIMITIVE,
|
||||
.utype = V_ASN1_BOOLEAN,
|
||||
.size = 1,
|
||||
.sname = "ASN1_TBOOLEAN",
|
||||
};
|
||||
|
||||
const ASN1_ITEM ASN1_FBOOLEAN_it = {
|
||||
.itype = ASN1_ITYPE_PRIMITIVE,
|
||||
.utype = V_ASN1_BOOLEAN,
|
||||
.size = 0,
|
||||
.sname = "ASN1_FBOOLEAN",
|
||||
};
|
||||
|
||||
/* Special, OCTET STRING with indefinite length constructed support */
|
||||
|
||||
const ASN1_ITEM ASN1_OCTET_STRING_NDEF_it = {
|
||||
.itype = ASN1_ITYPE_PRIMITIVE,
|
||||
.utype = V_ASN1_OCTET_STRING,
|
||||
.size = ASN1_TFLG_NDEF,
|
||||
.sname = "ASN1_OCTET_STRING_NDEF",
|
||||
};
|
||||
|
||||
static const ASN1_TEMPLATE ASN1_SEQUENCE_ANY_item_tt = {
|
||||
.flags = ASN1_TFLG_SEQUENCE_OF,
|
||||
.tag = 0,
|
||||
.offset = 0,
|
||||
.field_name = "ASN1_SEQUENCE_ANY",
|
||||
.item = &ASN1_ANY_it,
|
||||
};
|
||||
|
||||
const ASN1_ITEM ASN1_SEQUENCE_ANY_it = {
|
||||
.itype = ASN1_ITYPE_PRIMITIVE,
|
||||
.utype = -1,
|
||||
.templates = &ASN1_SEQUENCE_ANY_item_tt,
|
||||
.tcount = 0,
|
||||
.funcs = NULL,
|
||||
.size = 0,
|
||||
.sname = "ASN1_SEQUENCE_ANY",
|
||||
};
|
||||
|
||||
static const ASN1_TEMPLATE ASN1_SET_ANY_item_tt = {
|
||||
.flags = ASN1_TFLG_SET_OF,
|
||||
.tag = 0,
|
||||
.offset = 0,
|
||||
.field_name = "ASN1_SET_ANY",
|
||||
.item = &ASN1_ANY_it,
|
||||
};
|
||||
|
||||
const ASN1_ITEM ASN1_SET_ANY_it = {
|
||||
.itype = ASN1_ITYPE_PRIMITIVE,
|
||||
.utype = -1,
|
||||
.templates = &ASN1_SET_ANY_item_tt,
|
||||
.tcount = 0,
|
||||
.funcs = NULL,
|
||||
.size = 0,
|
||||
.sname = "ASN1_SET_ANY",
|
||||
};
|
||||
|
||||
|
||||
ASN1_SEQUENCE_ANY *
|
||||
d2i_ASN1_SEQUENCE_ANY(ASN1_SEQUENCE_ANY **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (ASN1_SEQUENCE_ANY *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&ASN1_SEQUENCE_ANY_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_ASN1_SEQUENCE_ANY(const ASN1_SEQUENCE_ANY *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_SEQUENCE_ANY_it);
|
||||
}
|
||||
|
||||
ASN1_SEQUENCE_ANY *
|
||||
d2i_ASN1_SET_ANY(ASN1_SEQUENCE_ANY **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (ASN1_SEQUENCE_ANY *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&ASN1_SET_ANY_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_ASN1_SET_ANY(const ASN1_SEQUENCE_ANY *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_SET_ANY_it);
|
||||
}
|
||||
280
externals/libressl/crypto/asn1/tasn_utl.c
vendored
280
externals/libressl/crypto/asn1/tasn_utl.c
vendored
@@ -1,280 +0,0 @@
|
||||
/* $OpenBSD: tasn_utl.c,v 1.13 2021/12/25 13:17:48 jsing Exp $ */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 2000.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2000-2004 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
/* Utility functions for manipulating fields and offsets */
|
||||
|
||||
/* Add 'offset' to 'addr' */
|
||||
#define offset2ptr(addr, offset) (void *)(((char *) addr) + offset)
|
||||
|
||||
/* Given an ASN1_ITEM CHOICE type return
|
||||
* the selector value
|
||||
*/
|
||||
|
||||
int
|
||||
asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
||||
{
|
||||
int *sel = offset2ptr(*pval, it->utype);
|
||||
return *sel;
|
||||
}
|
||||
|
||||
/* Given an ASN1_ITEM CHOICE type set
|
||||
* the selector value, return old value.
|
||||
*/
|
||||
|
||||
int
|
||||
asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it)
|
||||
{
|
||||
int *sel, ret;
|
||||
sel = offset2ptr(*pval, it->utype);
|
||||
ret = *sel;
|
||||
*sel = value;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Do reference counting. The value 'op' decides what to do.
|
||||
* if it is +1 then the count is incremented. If op is 0 count is
|
||||
* set to 1. If op is -1 count is decremented and the return value
|
||||
* is the current refrence count or 0 if no reference count exists.
|
||||
*/
|
||||
|
||||
int
|
||||
asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it)
|
||||
{
|
||||
const ASN1_AUX *aux;
|
||||
int *lck, ret;
|
||||
|
||||
if ((it->itype != ASN1_ITYPE_SEQUENCE) &&
|
||||
(it->itype != ASN1_ITYPE_NDEF_SEQUENCE))
|
||||
return 0;
|
||||
aux = it->funcs;
|
||||
if (!aux || !(aux->flags & ASN1_AFLG_REFCOUNT))
|
||||
return 0;
|
||||
lck = offset2ptr(*pval, aux->ref_offset);
|
||||
if (op == 0) {
|
||||
*lck = 1;
|
||||
return 1;
|
||||
}
|
||||
ret = CRYPTO_add(lck, op, aux->ref_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ASN1_ENCODING *
|
||||
asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
||||
{
|
||||
const ASN1_AUX *aux;
|
||||
|
||||
if (!pval || !*pval)
|
||||
return NULL;
|
||||
aux = it->funcs;
|
||||
if (!aux || !(aux->flags & ASN1_AFLG_ENCODING))
|
||||
return NULL;
|
||||
return offset2ptr(*pval, aux->enc_offset);
|
||||
}
|
||||
|
||||
void
|
||||
asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
||||
{
|
||||
ASN1_ENCODING *enc;
|
||||
|
||||
enc = asn1_get_enc_ptr(pval, it);
|
||||
if (enc) {
|
||||
enc->enc = NULL;
|
||||
enc->len = 0;
|
||||
enc->modified = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
||||
{
|
||||
ASN1_ENCODING *enc;
|
||||
|
||||
enc = asn1_get_enc_ptr(pval, it);
|
||||
if (enc) {
|
||||
free(enc->enc);
|
||||
enc->enc = NULL;
|
||||
enc->len = 0;
|
||||
enc->modified = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen,
|
||||
const ASN1_ITEM *it)
|
||||
{
|
||||
ASN1_ENCODING *enc;
|
||||
|
||||
enc = asn1_get_enc_ptr(pval, it);
|
||||
if (!enc)
|
||||
return 1;
|
||||
|
||||
free(enc->enc);
|
||||
enc->enc = malloc(inlen);
|
||||
if (!enc->enc)
|
||||
return 0;
|
||||
memcpy(enc->enc, in, inlen);
|
||||
enc->len = inlen;
|
||||
enc->modified = 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval,
|
||||
const ASN1_ITEM *it)
|
||||
{
|
||||
ASN1_ENCODING *enc;
|
||||
|
||||
enc = asn1_get_enc_ptr(pval, it);
|
||||
if (!enc || enc->modified)
|
||||
return 0;
|
||||
if (out) {
|
||||
memcpy(*out, enc->enc, enc->len);
|
||||
*out += enc->len;
|
||||
}
|
||||
if (len)
|
||||
*len = enc->len;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Given an ASN1_TEMPLATE get a pointer to a field */
|
||||
ASN1_VALUE **
|
||||
asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
|
||||
{
|
||||
ASN1_VALUE **pvaltmp;
|
||||
|
||||
if (tt->flags & ASN1_TFLG_COMBINE)
|
||||
return pval;
|
||||
pvaltmp = offset2ptr(*pval, tt->offset);
|
||||
/* NOTE for BOOLEAN types the field is just a plain
|
||||
* int so we can't return int **, so settle for
|
||||
* (int *).
|
||||
*/
|
||||
return pvaltmp;
|
||||
}
|
||||
|
||||
/* Handle ANY DEFINED BY template, find the selector, look up
|
||||
* the relevant ASN1_TEMPLATE in the table and return it.
|
||||
*/
|
||||
|
||||
const ASN1_TEMPLATE *
|
||||
asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int nullerr)
|
||||
{
|
||||
const ASN1_ADB *adb;
|
||||
const ASN1_ADB_TABLE *atbl;
|
||||
long selector;
|
||||
ASN1_VALUE **sfld;
|
||||
int i;
|
||||
|
||||
if (!(tt->flags & ASN1_TFLG_ADB_MASK))
|
||||
return tt;
|
||||
|
||||
/* Else ANY DEFINED BY ... get the table */
|
||||
adb = (const ASN1_ADB *)tt->item;
|
||||
|
||||
/* Get the selector field */
|
||||
sfld = offset2ptr(*pval, adb->offset);
|
||||
|
||||
/* Check if NULL */
|
||||
if (!sfld) {
|
||||
if (!adb->null_tt)
|
||||
goto err;
|
||||
return adb->null_tt;
|
||||
}
|
||||
|
||||
/* Convert type to a long:
|
||||
* NB: don't check for NID_undef here because it
|
||||
* might be a legitimate value in the table
|
||||
*/
|
||||
if (tt->flags & ASN1_TFLG_ADB_OID)
|
||||
selector = OBJ_obj2nid((ASN1_OBJECT *)*sfld);
|
||||
else
|
||||
selector = ASN1_INTEGER_get((ASN1_INTEGER *)*sfld);
|
||||
|
||||
/* Try to find matching entry in table
|
||||
* Maybe should check application types first to
|
||||
* allow application override? Might also be useful
|
||||
* to have a flag which indicates table is sorted and
|
||||
* we can do a binary search. For now stick to a
|
||||
* linear search.
|
||||
*/
|
||||
|
||||
for (atbl = adb->tbl, i = 0; i < adb->tblcount; i++, atbl++)
|
||||
if (atbl->value == selector)
|
||||
return &atbl->tt;
|
||||
|
||||
/* FIXME: need to search application table too */
|
||||
|
||||
/* No match, return default type */
|
||||
if (!adb->default_tt)
|
||||
goto err;
|
||||
return adb->default_tt;
|
||||
|
||||
err:
|
||||
/* FIXME: should log the value or OID of unsupported type */
|
||||
if (nullerr)
|
||||
ASN1error(ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE);
|
||||
return NULL;
|
||||
}
|
||||
220
externals/libressl/crypto/asn1/x_algor.c
vendored
220
externals/libressl/crypto/asn1/x_algor.c
vendored
@@ -1,220 +0,0 @@
|
||||
/* $OpenBSD: x_algor.c,v 1.23 2021/12/12 14:27:20 tb Exp $ */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 2000.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2000 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/asn1t.h>
|
||||
|
||||
static const ASN1_TEMPLATE X509_ALGOR_seq_tt[] = {
|
||||
{
|
||||
.offset = offsetof(X509_ALGOR, algorithm),
|
||||
.field_name = "algorithm",
|
||||
.item = &ASN1_OBJECT_it,
|
||||
},
|
||||
{
|
||||
.flags = ASN1_TFLG_OPTIONAL,
|
||||
.offset = offsetof(X509_ALGOR, parameter),
|
||||
.field_name = "parameter",
|
||||
.item = &ASN1_ANY_it,
|
||||
},
|
||||
};
|
||||
|
||||
const ASN1_ITEM X509_ALGOR_it = {
|
||||
.itype = ASN1_ITYPE_SEQUENCE,
|
||||
.utype = V_ASN1_SEQUENCE,
|
||||
.templates = X509_ALGOR_seq_tt,
|
||||
.tcount = sizeof(X509_ALGOR_seq_tt) / sizeof(ASN1_TEMPLATE),
|
||||
.size = sizeof(X509_ALGOR),
|
||||
.sname = "X509_ALGOR",
|
||||
};
|
||||
|
||||
static const ASN1_TEMPLATE X509_ALGORS_item_tt = {
|
||||
.flags = ASN1_TFLG_SEQUENCE_OF,
|
||||
.tag = 0,
|
||||
.offset = 0,
|
||||
.field_name = "algorithms",
|
||||
.item = &X509_ALGOR_it,
|
||||
};
|
||||
|
||||
const ASN1_ITEM X509_ALGORS_it = {
|
||||
.itype = ASN1_ITYPE_PRIMITIVE,
|
||||
.utype = -1,
|
||||
.templates = &X509_ALGORS_item_tt,
|
||||
.tcount = 0,
|
||||
.funcs = NULL,
|
||||
.size = 0,
|
||||
.sname = "X509_ALGORS",
|
||||
};
|
||||
|
||||
|
||||
X509_ALGOR *
|
||||
d2i_X509_ALGOR(X509_ALGOR **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (X509_ALGOR *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&X509_ALGOR_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_X509_ALGOR(X509_ALGOR *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &X509_ALGOR_it);
|
||||
}
|
||||
|
||||
X509_ALGOR *
|
||||
X509_ALGOR_new(void)
|
||||
{
|
||||
return (X509_ALGOR *)ASN1_item_new(&X509_ALGOR_it);
|
||||
}
|
||||
|
||||
void
|
||||
X509_ALGOR_free(X509_ALGOR *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &X509_ALGOR_it);
|
||||
}
|
||||
|
||||
X509_ALGORS *
|
||||
d2i_X509_ALGORS(X509_ALGORS **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (X509_ALGORS *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&X509_ALGORS_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_X509_ALGORS(X509_ALGORS *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &X509_ALGORS_it);
|
||||
}
|
||||
|
||||
X509_ALGOR *
|
||||
X509_ALGOR_dup(X509_ALGOR *x)
|
||||
{
|
||||
return ASN1_item_dup(&X509_ALGOR_it, x);
|
||||
}
|
||||
|
||||
int
|
||||
X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval)
|
||||
{
|
||||
if (!alg)
|
||||
return 0;
|
||||
if (ptype != V_ASN1_UNDEF) {
|
||||
if (alg->parameter == NULL)
|
||||
alg->parameter = ASN1_TYPE_new();
|
||||
if (alg->parameter == NULL)
|
||||
return 0;
|
||||
}
|
||||
if (alg) {
|
||||
if (alg->algorithm)
|
||||
ASN1_OBJECT_free(alg->algorithm);
|
||||
alg->algorithm = aobj;
|
||||
}
|
||||
if (ptype == 0)
|
||||
return 1;
|
||||
if (ptype == V_ASN1_UNDEF) {
|
||||
if (alg->parameter) {
|
||||
ASN1_TYPE_free(alg->parameter);
|
||||
alg->parameter = NULL;
|
||||
}
|
||||
} else
|
||||
ASN1_TYPE_set(alg->parameter, ptype, pval);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
X509_ALGOR_get0(const ASN1_OBJECT **paobj, int *pptype, const void **ppval,
|
||||
const X509_ALGOR *algor)
|
||||
{
|
||||
if (paobj)
|
||||
*paobj = algor->algorithm;
|
||||
if (pptype) {
|
||||
if (algor->parameter == NULL) {
|
||||
*pptype = V_ASN1_UNDEF;
|
||||
return;
|
||||
} else
|
||||
*pptype = algor->parameter->type;
|
||||
if (ppval)
|
||||
*ppval = algor->parameter->value.ptr;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set up an X509_ALGOR DigestAlgorithmIdentifier from an EVP_MD */
|
||||
|
||||
void
|
||||
X509_ALGOR_set_md(X509_ALGOR *alg, const EVP_MD *md)
|
||||
{
|
||||
int param_type = V_ASN1_NULL;
|
||||
|
||||
if ((EVP_MD_flags(md) & EVP_MD_FLAG_DIGALGID_ABSENT) != 0)
|
||||
param_type = V_ASN1_UNDEF;
|
||||
|
||||
X509_ALGOR_set0(alg, OBJ_nid2obj(EVP_MD_type(md)), param_type, NULL);
|
||||
}
|
||||
|
||||
/* Returns 0 if they are equal, != 0 otherwise. */
|
||||
int
|
||||
X509_ALGOR_cmp(const X509_ALGOR *a, const X509_ALGOR *b)
|
||||
{
|
||||
int rv = OBJ_cmp(a->algorithm, b->algorithm);
|
||||
if (!rv) {
|
||||
if (!a->parameter && !b->parameter)
|
||||
rv = 0;
|
||||
else
|
||||
rv = ASN1_TYPE_cmp(a->parameter, b->parameter);
|
||||
}
|
||||
return(rv);
|
||||
}
|
||||
203
externals/libressl/crypto/asn1/x_attrib.c
vendored
203
externals/libressl/crypto/asn1/x_attrib.c
vendored
@@ -1,203 +0,0 @@
|
||||
/* $OpenBSD: x_attrib.c,v 1.16 2021/12/25 13:17:48 jsing 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 <openssl/asn1t.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
#include "x509_lcl.h"
|
||||
|
||||
/* X509_ATTRIBUTE: this has the following form:
|
||||
*
|
||||
* typedef struct x509_attributes_st
|
||||
* {
|
||||
* ASN1_OBJECT *object;
|
||||
* int single;
|
||||
* union {
|
||||
* char *ptr;
|
||||
* STACK_OF(ASN1_TYPE) *set;
|
||||
* ASN1_TYPE *single;
|
||||
* } value;
|
||||
* } X509_ATTRIBUTE;
|
||||
*
|
||||
* this needs some extra thought because the CHOICE type is
|
||||
* merged with the main structure and because the value can
|
||||
* be anything at all we *must* try the SET OF first because
|
||||
* the ASN1_ANY type will swallow anything including the whole
|
||||
* SET OF structure.
|
||||
*/
|
||||
|
||||
static const ASN1_TEMPLATE X509_ATTRIBUTE_SET_ch_tt[] = {
|
||||
{
|
||||
.flags = ASN1_TFLG_SET_OF,
|
||||
.tag = 0,
|
||||
.offset = offsetof(X509_ATTRIBUTE, value.set),
|
||||
.field_name = "value.set",
|
||||
.item = &ASN1_ANY_it,
|
||||
},
|
||||
{
|
||||
.flags = 0,
|
||||
.tag = 0,
|
||||
.offset = offsetof(X509_ATTRIBUTE, value.single),
|
||||
.field_name = "value.single",
|
||||
.item = &ASN1_ANY_it,
|
||||
},
|
||||
};
|
||||
|
||||
const ASN1_ITEM X509_ATTRIBUTE_SET_it = {
|
||||
.itype = ASN1_ITYPE_CHOICE,
|
||||
.utype = offsetof(X509_ATTRIBUTE, single),
|
||||
.templates = X509_ATTRIBUTE_SET_ch_tt,
|
||||
.tcount = sizeof(X509_ATTRIBUTE_SET_ch_tt) / sizeof(ASN1_TEMPLATE),
|
||||
.funcs = NULL,
|
||||
.size = sizeof(X509_ATTRIBUTE),
|
||||
.sname = "X509_ATTRIBUTE",
|
||||
};
|
||||
|
||||
static const ASN1_TEMPLATE X509_ATTRIBUTE_seq_tt[] = {
|
||||
{
|
||||
.flags = 0,
|
||||
.tag = 0,
|
||||
.offset = offsetof(X509_ATTRIBUTE, object),
|
||||
.field_name = "object",
|
||||
.item = &ASN1_OBJECT_it,
|
||||
},
|
||||
/* CHOICE type merged with parent */
|
||||
{
|
||||
.flags = 0 | ASN1_TFLG_COMBINE,
|
||||
.tag = 0,
|
||||
.offset = 0,
|
||||
.field_name = NULL,
|
||||
.item = &X509_ATTRIBUTE_SET_it,
|
||||
},
|
||||
};
|
||||
|
||||
const ASN1_ITEM X509_ATTRIBUTE_it = {
|
||||
.itype = ASN1_ITYPE_SEQUENCE,
|
||||
.utype = V_ASN1_SEQUENCE,
|
||||
.templates = X509_ATTRIBUTE_seq_tt,
|
||||
.tcount = sizeof(X509_ATTRIBUTE_seq_tt) / sizeof(ASN1_TEMPLATE),
|
||||
.funcs = NULL,
|
||||
.size = sizeof(X509_ATTRIBUTE),
|
||||
.sname = "X509_ATTRIBUTE",
|
||||
};
|
||||
|
||||
|
||||
X509_ATTRIBUTE *
|
||||
d2i_X509_ATTRIBUTE(X509_ATTRIBUTE **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (X509_ATTRIBUTE *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&X509_ATTRIBUTE_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_X509_ATTRIBUTE(X509_ATTRIBUTE *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &X509_ATTRIBUTE_it);
|
||||
}
|
||||
|
||||
X509_ATTRIBUTE *
|
||||
X509_ATTRIBUTE_new(void)
|
||||
{
|
||||
return (X509_ATTRIBUTE *)ASN1_item_new(&X509_ATTRIBUTE_it);
|
||||
}
|
||||
|
||||
void
|
||||
X509_ATTRIBUTE_free(X509_ATTRIBUTE *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &X509_ATTRIBUTE_it);
|
||||
}
|
||||
|
||||
X509_ATTRIBUTE *
|
||||
X509_ATTRIBUTE_dup(X509_ATTRIBUTE *x)
|
||||
{
|
||||
return ASN1_item_dup(&X509_ATTRIBUTE_it, x);
|
||||
}
|
||||
|
||||
X509_ATTRIBUTE *
|
||||
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 = oid;
|
||||
ret->single = 0;
|
||||
if ((ret->value.set = sk_ASN1_TYPE_new_null()) == NULL)
|
||||
goto err;
|
||||
if ((val = ASN1_TYPE_new()) == NULL)
|
||||
goto err;
|
||||
if (!sk_ASN1_TYPE_push(ret->value.set, val))
|
||||
goto err;
|
||||
|
||||
ASN1_TYPE_set(val, atrtype, value);
|
||||
return (ret);
|
||||
|
||||
err:
|
||||
if (ret != NULL)
|
||||
X509_ATTRIBUTE_free(ret);
|
||||
if (val != NULL)
|
||||
ASN1_TYPE_free(val);
|
||||
return (NULL);
|
||||
}
|
||||
184
externals/libressl/crypto/asn1/x_bignum.c
vendored
184
externals/libressl/crypto/asn1/x_bignum.c
vendored
@@ -1,184 +0,0 @@
|
||||
/* $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.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2000 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/bn.h>
|
||||
|
||||
/*
|
||||
* Custom primitive type for BIGNUM handling. This reads in an ASN1_INTEGER as a
|
||||
* BIGNUM directly. Currently it ignores the sign which isn't a problem since
|
||||
* all BIGNUMs used are non negative and anything that looks negative is
|
||||
* normally due to an encoding error.
|
||||
*/
|
||||
|
||||
static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
static void bn_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
|
||||
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 = {
|
||||
.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 = {
|
||||
.itype = ASN1_ITYPE_PRIMITIVE,
|
||||
.utype = V_ASN1_INTEGER,
|
||||
.templates = NULL,
|
||||
.tcount = 0,
|
||||
.funcs = &bignum_pf,
|
||||
.size = 0,
|
||||
.sname = "BIGNUM",
|
||||
};
|
||||
|
||||
const ASN1_ITEM CBIGNUM_it = {
|
||||
.itype = ASN1_ITYPE_PRIMITIVE,
|
||||
.utype = V_ASN1_INTEGER,
|
||||
.templates = NULL,
|
||||
.tcount = 0,
|
||||
.funcs = &bignum_pf,
|
||||
.size = 0,
|
||||
.sname = "BIGNUM",
|
||||
};
|
||||
|
||||
static int
|
||||
bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
||||
{
|
||||
*pval = (ASN1_VALUE *)BN_new();
|
||||
if (*pval)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
bn_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
||||
{
|
||||
if (*pval == NULL)
|
||||
return;
|
||||
BN_clear_free((BIGNUM *)*pval);
|
||||
*pval = NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it)
|
||||
{
|
||||
BIGNUM *bn;
|
||||
int pad, len;
|
||||
|
||||
if (*pval == NULL)
|
||||
return -1;
|
||||
bn = (BIGNUM *)*pval;
|
||||
/* If MSB set in an octet we need a padding byte */
|
||||
if (BN_num_bits(bn) & 0x7)
|
||||
pad = 0;
|
||||
else
|
||||
pad = 1;
|
||||
if (cont) {
|
||||
if (pad)
|
||||
*cont++ = 0;
|
||||
len = BN_bn2bin(bn, cont);
|
||||
} else
|
||||
len = BN_num_bytes(bn);
|
||||
return pad + len;
|
||||
}
|
||||
|
||||
static int
|
||||
bn_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype,
|
||||
char *free_cont, const ASN1_ITEM *it)
|
||||
{
|
||||
BIGNUM *bn;
|
||||
|
||||
if (*pval == NULL) {
|
||||
if (bn_new(pval, it) == 0)
|
||||
return 0;
|
||||
}
|
||||
bn = (BIGNUM *)*pval;
|
||||
if (!BN_bin2bn(cont, len, bn)) {
|
||||
bn_free(pval, it);
|
||||
return 0;
|
||||
}
|
||||
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;
|
||||
}
|
||||
757
externals/libressl/crypto/asn1/x_crl.c
vendored
757
externals/libressl/crypto/asn1/x_crl.c
vendored
@@ -1,757 +0,0 @@
|
||||
/* $OpenBSD: x_crl.c,v 1.37 2022/02/24 22:05:06 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 <openssl/opensslconf.h>
|
||||
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
#include "asn1_locl.h"
|
||||
#include "x509_lcl.h"
|
||||
|
||||
static int X509_REVOKED_cmp(const X509_REVOKED * const *a,
|
||||
const X509_REVOKED * const *b);
|
||||
static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp);
|
||||
|
||||
static const ASN1_TEMPLATE X509_REVOKED_seq_tt[] = {
|
||||
{
|
||||
.offset = offsetof(X509_REVOKED, serialNumber),
|
||||
.field_name = "serialNumber",
|
||||
.item = &ASN1_INTEGER_it,
|
||||
},
|
||||
{
|
||||
.offset = offsetof(X509_REVOKED, revocationDate),
|
||||
.field_name = "revocationDate",
|
||||
.item = &ASN1_TIME_it,
|
||||
},
|
||||
{
|
||||
.flags = ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_OPTIONAL,
|
||||
.offset = offsetof(X509_REVOKED, extensions),
|
||||
.field_name = "extensions",
|
||||
.item = &X509_EXTENSION_it,
|
||||
},
|
||||
};
|
||||
|
||||
const ASN1_ITEM X509_REVOKED_it = {
|
||||
.itype = ASN1_ITYPE_SEQUENCE,
|
||||
.utype = V_ASN1_SEQUENCE,
|
||||
.templates = X509_REVOKED_seq_tt,
|
||||
.tcount = sizeof(X509_REVOKED_seq_tt) / sizeof(ASN1_TEMPLATE),
|
||||
.size = sizeof(X509_REVOKED),
|
||||
.sname = "X509_REVOKED",
|
||||
};
|
||||
|
||||
static int def_crl_verify(X509_CRL *crl, EVP_PKEY *r);
|
||||
static int def_crl_lookup(X509_CRL *crl, X509_REVOKED **ret,
|
||||
ASN1_INTEGER *serial, X509_NAME *issuer);
|
||||
|
||||
static X509_CRL_METHOD int_crl_meth = {
|
||||
.crl_lookup = def_crl_lookup,
|
||||
.crl_verify = def_crl_verify
|
||||
};
|
||||
|
||||
static const X509_CRL_METHOD *default_crl_method = &int_crl_meth;
|
||||
|
||||
/* The X509_CRL_INFO structure needs a bit of customisation.
|
||||
* Since we cache the original encoding the signature wont be affected by
|
||||
* reordering of the revoked field.
|
||||
*/
|
||||
static int
|
||||
crl_inf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
|
||||
{
|
||||
X509_CRL_INFO *a = (X509_CRL_INFO *)*pval;
|
||||
|
||||
if (!a || !a->revoked)
|
||||
return 1;
|
||||
switch (operation) {
|
||||
/* Just set cmp function here. We don't sort because that
|
||||
* would affect the output of X509_CRL_print().
|
||||
*/
|
||||
case ASN1_OP_D2I_POST:
|
||||
(void)sk_X509_REVOKED_set_cmp_func(a->revoked, X509_REVOKED_cmp);
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static const ASN1_AUX X509_CRL_INFO_aux = {
|
||||
.flags = ASN1_AFLG_ENCODING,
|
||||
.asn1_cb = crl_inf_cb,
|
||||
.enc_offset = offsetof(X509_CRL_INFO, enc),
|
||||
};
|
||||
static const ASN1_TEMPLATE X509_CRL_INFO_seq_tt[] = {
|
||||
{
|
||||
.flags = ASN1_TFLG_OPTIONAL,
|
||||
.offset = offsetof(X509_CRL_INFO, version),
|
||||
.field_name = "version",
|
||||
.item = &ASN1_INTEGER_it,
|
||||
},
|
||||
{
|
||||
.offset = offsetof(X509_CRL_INFO, sig_alg),
|
||||
.field_name = "sig_alg",
|
||||
.item = &X509_ALGOR_it,
|
||||
},
|
||||
{
|
||||
.offset = offsetof(X509_CRL_INFO, issuer),
|
||||
.field_name = "issuer",
|
||||
.item = &X509_NAME_it,
|
||||
},
|
||||
{
|
||||
.offset = offsetof(X509_CRL_INFO, lastUpdate),
|
||||
.field_name = "lastUpdate",
|
||||
.item = &ASN1_TIME_it,
|
||||
},
|
||||
{
|
||||
.flags = ASN1_TFLG_OPTIONAL,
|
||||
.offset = offsetof(X509_CRL_INFO, nextUpdate),
|
||||
.field_name = "nextUpdate",
|
||||
.item = &ASN1_TIME_it,
|
||||
},
|
||||
{
|
||||
.flags = ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_OPTIONAL,
|
||||
.offset = offsetof(X509_CRL_INFO, revoked),
|
||||
.field_name = "revoked",
|
||||
.item = &X509_REVOKED_it,
|
||||
},
|
||||
{
|
||||
.flags = ASN1_TFLG_EXPLICIT | ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_OPTIONAL,
|
||||
.offset = offsetof(X509_CRL_INFO, extensions),
|
||||
.field_name = "extensions",
|
||||
.item = &X509_EXTENSION_it,
|
||||
},
|
||||
};
|
||||
|
||||
const ASN1_ITEM X509_CRL_INFO_it = {
|
||||
.itype = ASN1_ITYPE_SEQUENCE,
|
||||
.utype = V_ASN1_SEQUENCE,
|
||||
.templates = X509_CRL_INFO_seq_tt,
|
||||
.tcount = sizeof(X509_CRL_INFO_seq_tt) / sizeof(ASN1_TEMPLATE),
|
||||
.funcs = &X509_CRL_INFO_aux,
|
||||
.size = sizeof(X509_CRL_INFO),
|
||||
.sname = "X509_CRL_INFO",
|
||||
};
|
||||
|
||||
/* Set CRL entry issuer according to CRL certificate issuer extension.
|
||||
* Check for unhandled critical CRL entry extensions.
|
||||
*/
|
||||
|
||||
static int
|
||||
crl_set_issuers(X509_CRL *crl)
|
||||
{
|
||||
int i, j;
|
||||
GENERAL_NAMES *gens, *gtmp;
|
||||
STACK_OF(X509_REVOKED) *revoked;
|
||||
|
||||
revoked = X509_CRL_get_REVOKED(crl);
|
||||
|
||||
gens = NULL;
|
||||
for (i = 0; i < sk_X509_REVOKED_num(revoked); i++) {
|
||||
X509_REVOKED *rev = sk_X509_REVOKED_value(revoked, i);
|
||||
STACK_OF(X509_EXTENSION) *exts;
|
||||
ASN1_ENUMERATED *reason;
|
||||
X509_EXTENSION *ext;
|
||||
gtmp = X509_REVOKED_get_ext_d2i(rev, NID_certificate_issuer,
|
||||
&j, NULL);
|
||||
if (!gtmp && (j != -1)) {
|
||||
crl->flags |= EXFLAG_INVALID;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (gtmp) {
|
||||
gens = gtmp;
|
||||
if (!crl->issuers) {
|
||||
crl->issuers = sk_GENERAL_NAMES_new_null();
|
||||
if (!crl->issuers)
|
||||
return 0;
|
||||
}
|
||||
if (!sk_GENERAL_NAMES_push(crl->issuers, gtmp))
|
||||
return 0;
|
||||
}
|
||||
rev->issuer = gens;
|
||||
|
||||
reason = X509_REVOKED_get_ext_d2i(rev, NID_crl_reason,
|
||||
&j, NULL);
|
||||
if (!reason && (j != -1)) {
|
||||
crl->flags |= EXFLAG_INVALID;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (reason) {
|
||||
rev->reason = ASN1_ENUMERATED_get(reason);
|
||||
ASN1_ENUMERATED_free(reason);
|
||||
} else
|
||||
rev->reason = CRL_REASON_NONE;
|
||||
|
||||
/* Check for critical CRL entry extensions */
|
||||
|
||||
exts = rev->extensions;
|
||||
|
||||
for (j = 0; j < sk_X509_EXTENSION_num(exts); j++) {
|
||||
ext = sk_X509_EXTENSION_value(exts, j);
|
||||
if (ext->critical > 0) {
|
||||
if (OBJ_obj2nid(ext->object) ==
|
||||
NID_certificate_issuer)
|
||||
continue;
|
||||
crl->flags |= EXFLAG_CRITICAL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* The X509_CRL structure needs a bit of customisation. Cache some extensions
|
||||
* and hash of the whole CRL.
|
||||
*/
|
||||
static int
|
||||
crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
|
||||
{
|
||||
X509_CRL *crl = (X509_CRL *)*pval;
|
||||
STACK_OF(X509_EXTENSION) *exts;
|
||||
X509_EXTENSION *ext;
|
||||
int idx;
|
||||
int rc = 1;
|
||||
|
||||
switch (operation) {
|
||||
case ASN1_OP_NEW_POST:
|
||||
crl->idp = NULL;
|
||||
crl->akid = NULL;
|
||||
crl->flags = 0;
|
||||
crl->idp_flags = 0;
|
||||
crl->idp_reasons = CRLDP_ALL_REASONS;
|
||||
crl->meth = default_crl_method;
|
||||
crl->meth_data = NULL;
|
||||
crl->issuers = NULL;
|
||||
crl->crl_number = NULL;
|
||||
crl->base_crl_number = NULL;
|
||||
break;
|
||||
|
||||
case ASN1_OP_D2I_POST:
|
||||
X509_CRL_digest(crl, X509_CRL_HASH_EVP, crl->hash, NULL);
|
||||
crl->idp = X509_CRL_get_ext_d2i(crl,
|
||||
NID_issuing_distribution_point, NULL, NULL);
|
||||
if (crl->idp)
|
||||
setup_idp(crl, crl->idp);
|
||||
|
||||
crl->akid = X509_CRL_get_ext_d2i(crl,
|
||||
NID_authority_key_identifier, NULL, NULL);
|
||||
|
||||
crl->crl_number = X509_CRL_get_ext_d2i(crl,
|
||||
NID_crl_number, NULL, NULL);
|
||||
|
||||
crl->base_crl_number = X509_CRL_get_ext_d2i(crl,
|
||||
NID_delta_crl, NULL, NULL);
|
||||
/* Delta CRLs must have CRL number */
|
||||
if (crl->base_crl_number && !crl->crl_number)
|
||||
crl->flags |= EXFLAG_INVALID;
|
||||
|
||||
/* See if we have any unhandled critical CRL extensions and
|
||||
* indicate this in a flag. We only currently handle IDP,
|
||||
* AKID and deltas, so anything else critical sets the flag.
|
||||
*
|
||||
* This code accesses the X509_CRL structure directly:
|
||||
* applications shouldn't do this.
|
||||
*/
|
||||
|
||||
exts = crl->crl->extensions;
|
||||
|
||||
for (idx = 0; idx < sk_X509_EXTENSION_num(exts); idx++) {
|
||||
int nid;
|
||||
ext = sk_X509_EXTENSION_value(exts, idx);
|
||||
nid = OBJ_obj2nid(ext->object);
|
||||
if (nid == NID_freshest_crl)
|
||||
crl->flags |= EXFLAG_FRESHEST;
|
||||
if (ext->critical > 0) {
|
||||
/* We handle IDP, AKID and deltas */
|
||||
if (nid == NID_issuing_distribution_point ||
|
||||
nid == NID_authority_key_identifier ||
|
||||
nid == NID_delta_crl)
|
||||
break;
|
||||
crl->flags |= EXFLAG_CRITICAL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!crl_set_issuers(crl))
|
||||
return 0;
|
||||
|
||||
if (crl->meth->crl_init) {
|
||||
if (crl->meth->crl_init(crl) == 0)
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case ASN1_OP_FREE_POST:
|
||||
if (crl->meth->crl_free) {
|
||||
if (!crl->meth->crl_free(crl))
|
||||
rc = 0;
|
||||
}
|
||||
if (crl->akid)
|
||||
AUTHORITY_KEYID_free(crl->akid);
|
||||
if (crl->idp)
|
||||
ISSUING_DIST_POINT_free(crl->idp);
|
||||
ASN1_INTEGER_free(crl->crl_number);
|
||||
ASN1_INTEGER_free(crl->base_crl_number);
|
||||
sk_GENERAL_NAMES_pop_free(crl->issuers, GENERAL_NAMES_free);
|
||||
break;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Convert IDP into a more convenient form */
|
||||
|
||||
static void
|
||||
setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp)
|
||||
{
|
||||
int idp_only = 0;
|
||||
|
||||
/* Set various flags according to IDP */
|
||||
crl->idp_flags |= IDP_PRESENT;
|
||||
if (idp->onlyuser > 0) {
|
||||
idp_only++;
|
||||
crl->idp_flags |= IDP_ONLYUSER;
|
||||
}
|
||||
if (idp->onlyCA > 0) {
|
||||
idp_only++;
|
||||
crl->idp_flags |= IDP_ONLYCA;
|
||||
}
|
||||
if (idp->onlyattr > 0) {
|
||||
idp_only++;
|
||||
crl->idp_flags |= IDP_ONLYATTR;
|
||||
}
|
||||
|
||||
if (idp_only > 1)
|
||||
crl->idp_flags |= IDP_INVALID;
|
||||
|
||||
if (idp->indirectCRL > 0)
|
||||
crl->idp_flags |= IDP_INDIRECT;
|
||||
|
||||
if (idp->onlysomereasons) {
|
||||
crl->idp_flags |= IDP_REASONS;
|
||||
if (idp->onlysomereasons->length > 0)
|
||||
crl->idp_reasons = idp->onlysomereasons->data[0];
|
||||
if (idp->onlysomereasons->length > 1)
|
||||
crl->idp_reasons |=
|
||||
(idp->onlysomereasons->data[1] << 8);
|
||||
crl->idp_reasons &= CRLDP_ALL_REASONS;
|
||||
}
|
||||
|
||||
DIST_POINT_set_dpname(idp->distpoint, X509_CRL_get_issuer(crl));
|
||||
}
|
||||
|
||||
static const ASN1_AUX X509_CRL_aux = {
|
||||
.app_data = NULL,
|
||||
.flags = ASN1_AFLG_REFCOUNT,
|
||||
.ref_offset = offsetof(X509_CRL, references),
|
||||
.ref_lock = CRYPTO_LOCK_X509_CRL,
|
||||
.asn1_cb = crl_cb,
|
||||
};
|
||||
static const ASN1_TEMPLATE X509_CRL_seq_tt[] = {
|
||||
{
|
||||
.offset = offsetof(X509_CRL, crl),
|
||||
.field_name = "crl",
|
||||
.item = &X509_CRL_INFO_it,
|
||||
},
|
||||
{
|
||||
.offset = offsetof(X509_CRL, sig_alg),
|
||||
.field_name = "sig_alg",
|
||||
.item = &X509_ALGOR_it,
|
||||
},
|
||||
{
|
||||
.offset = offsetof(X509_CRL, signature),
|
||||
.field_name = "signature",
|
||||
.item = &ASN1_BIT_STRING_it,
|
||||
},
|
||||
};
|
||||
|
||||
const ASN1_ITEM X509_CRL_it = {
|
||||
.itype = ASN1_ITYPE_SEQUENCE,
|
||||
.utype = V_ASN1_SEQUENCE,
|
||||
.templates = X509_CRL_seq_tt,
|
||||
.tcount = sizeof(X509_CRL_seq_tt) / sizeof(ASN1_TEMPLATE),
|
||||
.funcs = &X509_CRL_aux,
|
||||
.size = sizeof(X509_CRL),
|
||||
.sname = "X509_CRL",
|
||||
};
|
||||
|
||||
|
||||
X509_REVOKED *
|
||||
d2i_X509_REVOKED(X509_REVOKED **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (X509_REVOKED *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&X509_REVOKED_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_X509_REVOKED(X509_REVOKED *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &X509_REVOKED_it);
|
||||
}
|
||||
|
||||
X509_REVOKED *
|
||||
X509_REVOKED_new(void)
|
||||
{
|
||||
return (X509_REVOKED *)ASN1_item_new(&X509_REVOKED_it);
|
||||
}
|
||||
|
||||
void
|
||||
X509_REVOKED_free(X509_REVOKED *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &X509_REVOKED_it);
|
||||
}
|
||||
|
||||
X509_REVOKED *
|
||||
X509_REVOKED_dup(X509_REVOKED *a)
|
||||
{
|
||||
return ASN1_item_dup(&X509_REVOKED_it, a);
|
||||
}
|
||||
|
||||
X509_CRL_INFO *
|
||||
d2i_X509_CRL_INFO(X509_CRL_INFO **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (X509_CRL_INFO *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&X509_CRL_INFO_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_X509_CRL_INFO(X509_CRL_INFO *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &X509_CRL_INFO_it);
|
||||
}
|
||||
|
||||
X509_CRL_INFO *
|
||||
X509_CRL_INFO_new(void)
|
||||
{
|
||||
return (X509_CRL_INFO *)ASN1_item_new(&X509_CRL_INFO_it);
|
||||
}
|
||||
|
||||
void
|
||||
X509_CRL_INFO_free(X509_CRL_INFO *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &X509_CRL_INFO_it);
|
||||
}
|
||||
|
||||
X509_CRL *
|
||||
d2i_X509_CRL(X509_CRL **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (X509_CRL *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&X509_CRL_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_X509_CRL(X509_CRL *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &X509_CRL_it);
|
||||
}
|
||||
|
||||
X509_CRL *
|
||||
X509_CRL_new(void)
|
||||
{
|
||||
return (X509_CRL *)ASN1_item_new(&X509_CRL_it);
|
||||
}
|
||||
|
||||
void
|
||||
X509_CRL_free(X509_CRL *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &X509_CRL_it);
|
||||
}
|
||||
|
||||
X509_CRL *
|
||||
X509_CRL_dup(X509_CRL *x)
|
||||
{
|
||||
return ASN1_item_dup(&X509_CRL_it, x);
|
||||
}
|
||||
|
||||
static int
|
||||
X509_REVOKED_cmp(const X509_REVOKED * const *a, const X509_REVOKED * const *b)
|
||||
{
|
||||
return(ASN1_INTEGER_cmp((*a)->serialNumber, (*b)->serialNumber));
|
||||
}
|
||||
|
||||
int
|
||||
X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev)
|
||||
{
|
||||
X509_CRL_INFO *inf;
|
||||
|
||||
inf = crl->crl;
|
||||
if (!inf->revoked)
|
||||
inf->revoked = sk_X509_REVOKED_new(X509_REVOKED_cmp);
|
||||
if (!inf->revoked || !sk_X509_REVOKED_push(inf->revoked, rev)) {
|
||||
ASN1error(ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
inf->enc.modified = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
X509_CRL_verify(X509_CRL *crl, EVP_PKEY *r)
|
||||
{
|
||||
if (crl->meth->crl_verify)
|
||||
return crl->meth->crl_verify(crl, r);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
X509_CRL_get0_by_serial(X509_CRL *crl, X509_REVOKED **ret,
|
||||
ASN1_INTEGER *serial)
|
||||
{
|
||||
if (crl->meth->crl_lookup)
|
||||
return crl->meth->crl_lookup(crl, ret, serial, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
X509_CRL_get0_by_cert(X509_CRL *crl, X509_REVOKED **ret, X509 *x)
|
||||
{
|
||||
if (crl->meth->crl_lookup)
|
||||
return crl->meth->crl_lookup(crl, ret,
|
||||
X509_get_serialNumber(x), X509_get_issuer_name(x));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
def_crl_verify(X509_CRL *crl, EVP_PKEY *r)
|
||||
{
|
||||
return(ASN1_item_verify(&X509_CRL_INFO_it,
|
||||
crl->sig_alg, crl->signature, crl->crl, r));
|
||||
}
|
||||
|
||||
static int
|
||||
crl_revoked_issuer_match(X509_CRL *crl, X509_NAME *nm, X509_REVOKED *rev)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!rev->issuer) {
|
||||
if (!nm)
|
||||
return 1;
|
||||
if (!X509_NAME_cmp(nm, X509_CRL_get_issuer(crl)))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!nm)
|
||||
nm = X509_CRL_get_issuer(crl);
|
||||
|
||||
for (i = 0; i < sk_GENERAL_NAME_num(rev->issuer); i++) {
|
||||
GENERAL_NAME *gen = sk_GENERAL_NAME_value(rev->issuer, i);
|
||||
if (gen->type != GEN_DIRNAME)
|
||||
continue;
|
||||
if (!X509_NAME_cmp(nm, gen->d.directoryName))
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
static int
|
||||
def_crl_lookup(X509_CRL *crl, X509_REVOKED **ret, ASN1_INTEGER *serial,
|
||||
X509_NAME *issuer)
|
||||
{
|
||||
X509_REVOKED rtmp, *rev;
|
||||
int idx;
|
||||
|
||||
rtmp.serialNumber = serial;
|
||||
/* Sort revoked into serial number order if not already sorted.
|
||||
* Do this under a lock to avoid race condition.
|
||||
*/
|
||||
if (!sk_X509_REVOKED_is_sorted(crl->crl->revoked)) {
|
||||
CRYPTO_w_lock(CRYPTO_LOCK_X509_CRL);
|
||||
sk_X509_REVOKED_sort(crl->crl->revoked);
|
||||
CRYPTO_w_unlock(CRYPTO_LOCK_X509_CRL);
|
||||
}
|
||||
idx = sk_X509_REVOKED_find(crl->crl->revoked, &rtmp);
|
||||
if (idx < 0)
|
||||
return 0;
|
||||
/* Need to look for matching name */
|
||||
for (; idx < sk_X509_REVOKED_num(crl->crl->revoked); idx++) {
|
||||
rev = sk_X509_REVOKED_value(crl->crl->revoked, idx);
|
||||
if (ASN1_INTEGER_cmp(rev->serialNumber, serial))
|
||||
return 0;
|
||||
if (crl_revoked_issuer_match(crl, issuer, rev)) {
|
||||
if (ret)
|
||||
*ret = rev;
|
||||
if (rev->reason == CRL_REASON_REMOVE_FROM_CRL)
|
||||
return 2;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
X509_CRL_set_default_method(const X509_CRL_METHOD *meth)
|
||||
{
|
||||
if (meth == NULL)
|
||||
default_crl_method = &int_crl_meth;
|
||||
else
|
||||
default_crl_method = meth;
|
||||
}
|
||||
|
||||
X509_CRL_METHOD *
|
||||
X509_CRL_METHOD_new(int (*crl_init)(X509_CRL *crl),
|
||||
int (*crl_free)(X509_CRL *crl),
|
||||
int (*crl_lookup)(X509_CRL *crl, X509_REVOKED **ret,
|
||||
ASN1_INTEGER *ser, X509_NAME *issuer),
|
||||
int (*crl_verify)(X509_CRL *crl, EVP_PKEY *pk))
|
||||
{
|
||||
X509_CRL_METHOD *m;
|
||||
|
||||
if ((m = calloc(1, sizeof(X509_CRL_METHOD))) == NULL)
|
||||
return NULL;
|
||||
|
||||
m->crl_init = crl_init;
|
||||
m->crl_free = crl_free;
|
||||
m->crl_lookup = crl_lookup;
|
||||
m->crl_verify = crl_verify;
|
||||
m->flags = X509_CRL_METHOD_DYNAMIC;
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
void
|
||||
X509_CRL_METHOD_free(X509_CRL_METHOD *m)
|
||||
{
|
||||
if (m == NULL)
|
||||
return;
|
||||
if (!(m->flags & X509_CRL_METHOD_DYNAMIC))
|
||||
return;
|
||||
free(m);
|
||||
}
|
||||
|
||||
void
|
||||
X509_CRL_set_meth_data(X509_CRL *crl, void *dat)
|
||||
{
|
||||
crl->meth_data = dat;
|
||||
}
|
||||
|
||||
void *
|
||||
X509_CRL_get_meth_data(X509_CRL *crl)
|
||||
{
|
||||
return crl->meth_data;
|
||||
}
|
||||
|
||||
int
|
||||
X509_CRL_get_signature_nid(const X509_CRL *crl)
|
||||
{
|
||||
return OBJ_obj2nid(crl->sig_alg->algorithm);
|
||||
}
|
||||
|
||||
const STACK_OF(X509_EXTENSION) *
|
||||
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)
|
||||
{
|
||||
if (psig != NULL)
|
||||
*psig = crl->signature;
|
||||
if (palg != NULL)
|
||||
*palg = crl->sig_alg;
|
||||
}
|
||||
155
externals/libressl/crypto/asn1/x_exten.c
vendored
155
externals/libressl/crypto/asn1/x_exten.c
vendored
@@ -1,155 +0,0 @@
|
||||
/* $OpenBSD: x_exten.c,v 1.17 2021/11/01 20:53:08 tb Exp $ */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 2000.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2000 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/asn1t.h>
|
||||
|
||||
#include "x509_lcl.h"
|
||||
|
||||
static const ASN1_TEMPLATE X509_EXTENSION_seq_tt[] = {
|
||||
{
|
||||
.offset = offsetof(X509_EXTENSION, object),
|
||||
.field_name = "object",
|
||||
.item = &ASN1_OBJECT_it,
|
||||
},
|
||||
{
|
||||
.flags = ASN1_TFLG_OPTIONAL,
|
||||
.offset = offsetof(X509_EXTENSION, critical),
|
||||
.field_name = "critical",
|
||||
.item = &ASN1_BOOLEAN_it,
|
||||
},
|
||||
{
|
||||
.offset = offsetof(X509_EXTENSION, value),
|
||||
.field_name = "value",
|
||||
.item = &ASN1_OCTET_STRING_it,
|
||||
},
|
||||
};
|
||||
|
||||
const ASN1_ITEM X509_EXTENSION_it = {
|
||||
.itype = ASN1_ITYPE_SEQUENCE,
|
||||
.utype = V_ASN1_SEQUENCE,
|
||||
.templates = X509_EXTENSION_seq_tt,
|
||||
.tcount = sizeof(X509_EXTENSION_seq_tt) / sizeof(ASN1_TEMPLATE),
|
||||
.size = sizeof(X509_EXTENSION),
|
||||
.sname = "X509_EXTENSION",
|
||||
};
|
||||
|
||||
static const ASN1_TEMPLATE X509_EXTENSIONS_item_tt = {
|
||||
.flags = ASN1_TFLG_SEQUENCE_OF,
|
||||
.tag = 0,
|
||||
.offset = 0,
|
||||
.field_name = "Extension",
|
||||
.item = &X509_EXTENSION_it,
|
||||
};
|
||||
|
||||
const ASN1_ITEM X509_EXTENSIONS_it = {
|
||||
.itype = ASN1_ITYPE_PRIMITIVE,
|
||||
.utype = -1,
|
||||
.templates = &X509_EXTENSIONS_item_tt,
|
||||
.tcount = 0,
|
||||
.funcs = NULL,
|
||||
.size = 0,
|
||||
.sname = "X509_EXTENSIONS",
|
||||
};
|
||||
|
||||
|
||||
X509_EXTENSION *
|
||||
d2i_X509_EXTENSION(X509_EXTENSION **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (X509_EXTENSION *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&X509_EXTENSION_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_X509_EXTENSION(X509_EXTENSION *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &X509_EXTENSION_it);
|
||||
}
|
||||
|
||||
X509_EXTENSION *
|
||||
X509_EXTENSION_new(void)
|
||||
{
|
||||
return (X509_EXTENSION *)ASN1_item_new(&X509_EXTENSION_it);
|
||||
}
|
||||
|
||||
void
|
||||
X509_EXTENSION_free(X509_EXTENSION *a)
|
||||
{
|
||||
ASN1_item_free((ASN1_VALUE *)a, &X509_EXTENSION_it);
|
||||
}
|
||||
|
||||
X509_EXTENSIONS *
|
||||
d2i_X509_EXTENSIONS(X509_EXTENSIONS **a, const unsigned char **in, long len)
|
||||
{
|
||||
return (X509_EXTENSIONS *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
|
||||
&X509_EXTENSIONS_it);
|
||||
}
|
||||
|
||||
int
|
||||
i2d_X509_EXTENSIONS(X509_EXTENSIONS *a, unsigned char **out)
|
||||
{
|
||||
return ASN1_item_i2d((ASN1_VALUE *)a, out, &X509_EXTENSIONS_it);
|
||||
}
|
||||
|
||||
X509_EXTENSION *
|
||||
X509_EXTENSION_dup(X509_EXTENSION *x)
|
||||
{
|
||||
return ASN1_item_dup(&X509_EXTENSION_it, x);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user