SSH: Use OpenSSH tools

... instead of our own SSH library.

Advantages:
    - Full compatibility with OpenSSH behavior guaranteed.
    - Minimal maintenance effort.
    - Less code to build.
    - Big chunk of 3rd party sources can be removed from our repository.

One the downside, Windows users now need to install OpenSSH for
RemoteLinux support. Hoewever, people doing embedded development
probably have it installed anyway.

[ChangeLog] Switched SSH backend to OpenSSH

Fixes: QTCREATORBUG-15744
Fixes: QTCREATORBUG-15807
Fixes: QTCREATORBUG-19306
Fixes: QTCREATORBUG-20210
Change-Id: Ifcfefdd39401e45ba1f4aca35d2c5bf7046c7aab
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Christian Kandeler
2018-11-23 11:07:57 +01:00
parent 030d4d0108
commit d7178b88c4
609 changed files with 2054 additions and 91045 deletions

1
.gitignore vendored
View File

@@ -52,7 +52,6 @@ wrapper.sh
/src/plugins/**/*.json
/src/plugins/coreplugin/ide_version.h
/src/libs/qt-breakpad/bin
/src/libs/botan/build/
app_version.h
phony.c

View File

@@ -37,7 +37,6 @@ Prerequisites:
* LLVM/Clang 6.0.0 or later (optional, needed for the Clang Code Model, see the
section "Get LLVM/Clang for the Clang Code Model")
* CMake (only for manual builds of LLVM/Clang)
* Python 2.6 or later (needed for building the bundled Botan library)
* Qbs 1.7.x (optional, sources also contain Qbs itself)
The installed toolchains have to match the one Qt was compiled with.
@@ -389,54 +388,6 @@ we thank the authors who made this possible:
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
### Botan, a C++ crypto library. Version 1.10.2
Botan (http://botan.randombit.net/) is distributed under these terms::
Copyright (C) 1999-2011 Jack Lloyd
2001 Peter J Jones
2004-2007 Justin Karneges
2004 Vaclav Ovsik
2005 Matthew Gregan
2005-2006 Matt Johnston
2006 Luca Piccarreta
2007 Yves Jerschow
2007-2008 FlexSecure GmbH
2007-2008 Technische Universitat Darmstadt
2007-2008 Falko Strenzke
2007-2008 Martin Doering
2007 Manuel Hartl
2007 Christoph Ludwig
2007 Patrick Sona
2010 Olivier de Gaalon
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.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) "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(S) OR CONTRIBUTOR(S) 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 source code of Botan C++ crypto library can be found in
QtCreator/src/libs/3rdparty
### SQLite, in-process library that implements a SQL database engine
SQLite (https://www.sqlite.org) is in the Public Domain.

View File

@@ -90,61 +90,6 @@
Roberto Raggi <roberto.raggi@gmail.com>\br
QtCreator/src/shared/cplusplus\br\br
\li \b{Botan, a C++ crypto library. Version 1.8.8}\br
\list
\li Copyright (C) 1999-2004 The Botan Project. All rights
reserved.
\li Copyright (C) 1999-2009 Jack Lloyd
\li 2001 Peter J Jones
\li 2004-2007 Justin Karneges
\li 2005 Matthew Gregan
\li 2005-2006 Matt Johnston
\li 2006 Luca Piccarreta
\li 2007 Yves Jerschow
\li 2007-2008 FlexSecure GmbH
\li 2007-2008 Technische Universitat Darmstadt
\li 2007-2008 Falko Strenzke
\li 2007-2008 Martin Doering
\li 2007 Manuel Hartl
\li 2007 Christoph Ludwig
\li 2007 Patrick Sona
\endlist
\code
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.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) "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(S) OR CONTRIBUTOR(S) 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.
\endcode
The source code of Botan C++ crypto library can be found
here:
\list
\li QtCreator/src/libs/3rdparty
\li \l{https://code.qt.io/cgit/qt-creator/qt-creator.git/tree/src/libs/3rdparty}
\endlist
\li \b{ANGLE Library (Windows)}
Used on Windows to implement OpenGL ES on top of DirectX.

View File

@@ -69,7 +69,6 @@ Module {
property string export_data_base: project.ide_source_tree + "/share/qtcreator"
property bool testsEnabled: Environment.getEnv("TEST") || qbs.buildVariant === "debug"
property bool useSystemBotan: Environment.getEnv("USE_SYSTEM_BOTAN") === "1"
property stringList generalDefines: [
"QT_CREATOR",
'IDE_LIBRARY_BASENAME="' + libDirName + '"',

View File

@@ -1,86 +0,0 @@
/Makefile
CMakeLists.txt*
libbotan*.so.*
*.a
*.so
*.dylib
*.exp
*.lib
*.pdb
*.ilk
*.dll
*.exe
*.manifest
build
build.log
botan
botan-test
core.*
vgcore.*
# Text file backups (e.g. gedit, joe)
*~
\#*\#
.\#*
# Archive files
*.tgz
*.tar
# Logs
*.log
# Patch files
*.patch
*.diff
*.orig
*.rej
# Cache and temporary files
*.pyc
.DS_Store
*.swp
# ctags/etags files
/TAGS
/tags
# Amalgamation code
botan_all.h
botan_all_internal.h
botan_all.cpp
botan_all_*.cpp
# Coverage output
coverage.info
coverage.info.raw
coverage/
lcov-out/
/fuzzer_corpus
# Profiler outputs
cachegrind.*
callgrind.*
# Ignore stuff in the top level dir that shouldn't be checked in
/*.c
/*.cpp
/*.h
/*.py
/*.key
/*.pem
/*.der
/*.ber
/*.gpg
/*.pub
/*.crt
/*.txt
/*.rst
# Add back files from the toplevel
!/news.rst
!/readme.rst
!/configure.py
!/license.txt

View File

@@ -1 +0,0 @@
src/scripts/ci/travis.yml

File diff suppressed because it is too large Load Diff

View File

@@ -1,24 +0,0 @@
Copyright (C) 1999-2018 The Botan Authors
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.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER 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.

View File

@@ -1,121 +0,0 @@
Botan: Crypto and TLS for Modern C++
========================================
Botan (Japanese for peony flower) is a C++ cryptography library released under the
permissive `Simplified BSD <https://botan.randombit.net/license.txt>`_ license.
Botan's goal is to be the best option for cryptography in C++ by offering the
tools necessary to implement a range of practical systems, such as TLS protocol,
X.509 certificates, modern AEAD ciphers, PKCS#11 and TPM hardware support,
password hashing, and post quantum crypto schemes.
See the `documentation <https://botan.randombit.net/manual>`_ for more information.
A Python binding is included, and several other `language bindings
<https://github.com/randombit/botan/wiki/Language-Bindings>`_ are available.
Development is coordinated on `GitHub <https://github.com/randombit/botan>`_
and contributions are welcome. If you need help, please open an issue on
`GitHub <https://github.com/randombit/botan/issues>`_ or email the
`botan-devel mailing list <https://lists.randombit.net/mailman/listinfo/botan-devel/>`_.
New releases are announced on the `botan-announce mailing list
<https://lists.randombit.net/mailman/listinfo/botan-announce/>`_.
If you think you have found a security issue, see the `security page
<https://botan.randombit.net/security.html>`_ for contact information.
The latest release is
`2.8.0 <https://botan.randombit.net/releases/Botan-2.8.0.tgz>`_
`(sig) <https://botan.randombit.net/releases/Botan-2.8.0.tgz.asc>`_,
released on 2018-10-01.
All releases are signed with a `PGP key <https://botan.randombit.net/pgpkey.txt>`_.
See the `release notes <https://botan.randombit.net/news.html>`_ for
what is new. Botan is also available through most
`distributions <https://github.com/randombit/botan/wiki/Distros>`_
such as Fedora, Debian, Arch and Homebrew.
.. image:: https://travis-ci.org/randombit/botan.svg?branch=master
:target: https://travis-ci.org/randombit/botan
:alt: Travis CI status
.. image:: https://ci.appveyor.com/api/projects/status/n9f94dljd03j2lce/branch/master?svg=true
:target: https://ci.appveyor.com/project/randombit/botan/branch/master
:alt: AppVeyor CI status
.. image:: https://botan-ci.kullo.net/badge
:target: https://botan-ci.kullo.net/
:alt: Kullo CI status
.. image:: https://codecov.io/github/randombit/botan/coverage.svg?branch=master
:target: https://codecov.io/github/randombit/botan
:alt: Code coverage report
.. image:: https://scan.coverity.com/projects/624/badge.svg
:target: https://scan.coverity.com/projects/624
:alt: Coverity results
.. image:: https://bestpractices.coreinfrastructure.org/projects/531/badge
:target: https://bestpractices.coreinfrastructure.org/projects/531
:alt: CII Best Practices statement
Find Enclosed
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Transport Layer Security (TLS) Protocol
----------------------------------------
* TLS v1.0, v1.1, and v1.2. The broken SSLv3 protocol is no longer supported.
* DTLS v1.0 and v1.2 are adaptations of TLS to datagram operation.
* Supported extensions include session tickets, SNI, ALPN, OCSP stapling,
encrypt-then-mac CBC, and extended master secret.
* Supports authentication using preshared keys (PSK) or passwords (SRP)
* Supports record encryption with ChaCha20Poly1305, AES/OCB, AES/GCM, AES/CCM,
Camellia/GCM as well as legacy CBC ciphersuites.
* Key exchange using CECPQ1, ECDH, FFDHE, or RSA
Public Key Infrastructure
----------------------------------------
* X.509v3 certificates and CRL creation and handling
* PKIX certificate path validation, including name constraints.
* OCSP request creation and response handling
* PKCS #10 certificate request generation and processing
* SQL database backed certificate store
Public Key Cryptography
----------------------------------------
* RSA signatures and encryption
* DH and ECDH key agreement
* Signature schemes ECDSA, DSA, Ed25519, ECGDSA, ECKCDSA, SM2, GOST 34.10-2001
* Post-quantum signature scheme XMSS
* Post-quantum key agreement schemes McEliece and NewHope
* ElGamal encryption
* Padding schemes OAEP, PSS, PKCS #1 v1.5, X9.31
Ciphers, hashes, MACs, and checksums
----------------------------------------
* Authenticated cipher modes EAX, OCB, GCM, SIV, CCM, (X)ChaCha20Poly1305
* Cipher modes CTR, CBC, XTS, CFB, OFB
* Block ciphers AES, ARIA, Blowfish, Camellia, CAST-128, DES/3DES, GOST 28147,
IDEA, Lion, Noekeon, SEED, Serpent, SHACAL2, SM4, Threefish-512, Twofish, XTEA
* Stream ciphers (X)ChaCha20, (X)Salsa20, SHAKE-128, RC4
* Hash functions SHA-1, SHA-2, SHA-3, MD4, MD5, RIPEMD-160, BLAKE2b,
Skein-512, SM3, Tiger, Whirlpool, GOST 34.11
* Authentication codes HMAC, CMAC, Poly1305, SipHash, GMAC, X9.19 DES-MAC
* Non-cryptographic checksums Adler32, CRC24, CRC32
Other Useful Things
----------------------------------------
* Full C++ PKCS #11 API wrapper
* Interfaces for TPM v1.2 device access
* Simple compression API wrapping zlib, bzip2, and lzma libraries
* RNG wrappers for system RNG and hardware RNGs
* HMAC_DRBG and entropy collection system for userspace RNGs
* Password hashing schemes PBKDF2, Scrypt, bcrypt
* SRP-6a password authenticated key exchange
* Key derivation functions including HKDF, KDF2, SP 800-108, SP 800-56A, SP 800-56C
* HOTP and TOTP algorithms
* Format preserving encryption scheme FE1
* Threshold secret sharing
* NIST key wrapping

View File

@@ -1,7 +0,0 @@
endian little
wordsize 64
<aliases>
axp
alphaaxp
</aliases>

View File

@@ -1,20 +0,0 @@
endian little
family arm
<aliases>
arm
armeb
armel # For Debian
armhf # For Debian
evbarm # For NetBSD
armv7
armv7l
armv7-a
armv8l # For AlpineLinux
</aliases>
<isa_extensions>
neon
</isa_extensions>

View File

@@ -1,19 +0,0 @@
endian little
wordsize 64
family arm
<aliases>
aarch64
armv8
armv8-a
</aliases>
<isa_extensions>
neon
armv8crypto
armv8sm3
armv8sm4
armv8sha3
armv8sha512
</isa_extensions>

View File

@@ -1,8 +0,0 @@
<aliases>
hp-pa
parisc
parisc64
pa-risc
hp-parisc
hp-pa-risc
</aliases>

View File

@@ -1,6 +0,0 @@
wordsize 64
<aliases>
itanium
itanic
</aliases>

View File

@@ -1 +0,0 @@
wordsize 64

View File

@@ -1,6 +0,0 @@
endian big
<aliases>
680x0
68k
</aliases>

View File

@@ -1,6 +0,0 @@
<aliases>
mips
mipsbe # RedHat
mipsle # RedHat
mipsel # Debian
</aliases>

View File

@@ -1,5 +0,0 @@
wordsize 64
<aliases>
mips64el
</aliases>

View File

@@ -1,3 +0,0 @@
endian big
family ppc

View File

@@ -1,12 +0,0 @@
endian big
family ppc
<aliases>
powerpc
ppc
</aliases>
<isa_extensions>
altivec
</isa_extensions>

View File

@@ -1,15 +0,0 @@
endian big
family ppc
wordsize 64
<aliases>
powerpc64
ppc64le
ppc64el
</aliases>
<isa_extensions>
altivec
ppccrypto
</isa_extensions>

View File

@@ -1,2 +0,0 @@
family riscv
endian little

View File

@@ -1 +0,0 @@
endian big

View File

@@ -1,2 +0,0 @@
endian big
wordsize 64

View File

@@ -1,7 +0,0 @@
endian big
family sparc
<aliases>
sparc
</aliases>

View File

@@ -1,3 +0,0 @@
family sparc
wordsize 64
endian big

View File

@@ -1,4 +0,0 @@
<aliases>
sh4
</aliases>

View File

@@ -1,16 +0,0 @@
endian little
family x86
<isa_extensions>
aesni
avx2
bmi2
rdrand
rdseed
sha
sse2
sse41
sse42
ssse3
</isa_extensions>

View File

@@ -1,30 +0,0 @@
endian little
family x86
<aliases>
ia32
x86
ix86
80x86
i86pc # for Solaris
x86pc # for QNX
bepc # for Haiku
i686
i586
i386
</aliases>
<isa_extensions>
aesni
avx2
bmi2
rdrand
rdseed
sha
sse2
sse41
sse42
ssse3
</isa_extensions>

View File

@@ -1,25 +0,0 @@
endian little
wordsize 64
family x86
<aliases>
amd64
x86-64
em64t
x64
x86_amd64
</aliases>
<isa_extensions>
aesni
avx2
bmi2
rdrand
rdseed
sha
sse2
sse41
sse42
ssse3
</isa_extensions>

View File

@@ -1,51 +0,0 @@
toolsets = vs2013;
shared-library botan {
defines = "BOTAN_DLL=__declspec(dllexport)";
sources {
%{for lib_srcs}
%{i}
%{endfor}
}
}
program cli {
deps = botan;
sources {
%{for cli_srcs}
%{i}
%{endfor}
}
headers {
%{for cli_headers}
%{i}
%{endfor}
}
}
program tests {
deps = botan;
sources {
%{for test_srcs}
%{i}
%{endfor}
}
}
includedirs += build/include/;
includedirs += build/include/external;
%{for libs_used}
libs += "%{i}";
%{endfor}
archs = %{bakefile_arch};
vs2013.option.ClCompile.DisableSpecificWarnings = "4250;4251;4275";
vs2013.option.ClCompile.WarningLevel = Level4;
vs2013.option.ClCompile.ExceptionHandling = SyncCThrow;
vs2013.option.ClCompile.RuntimeTypeInfo = true;
if ( $(config) == Release ) {
vs2013.option.Configuration.WholeProgramOptimization = true;
}

View File

@@ -1,219 +0,0 @@
# Doxyfile 1.5.4
PROJECT_NAME = Botan
PROJECT_NUMBER = %{version}
PROJECT_BRIEF = Crypto&nbsp;and&nbsp;TLS&nbsp;for&nbsp;C&#43;&#43;11
OUTPUT_DIRECTORY = %{doc_output_dir}/doxygen
DOXYFILE_ENCODING = UTF-8
CREATE_SUBDIRS = NO
OUTPUT_LANGUAGE = English
BRIEF_MEMBER_DESC = YES
REPEAT_BRIEF = YES
ABBREVIATE_BRIEF =
ALWAYS_DETAILED_SEC = NO
INLINE_INHERITED_MEMB = YES
FULL_PATH_NAMES = YES
STRIP_FROM_PATH =
STRIP_FROM_INC_PATH =
SHORT_NAMES = NO
JAVADOC_AUTOBRIEF = NO
QT_AUTOBRIEF = NO
MULTILINE_CPP_IS_BRIEF = NO
INHERIT_DOCS = YES
SEPARATE_MEMBER_PAGES = NO
TAB_SIZE = 8
ALIASES =
OPTIMIZE_OUTPUT_FOR_C = NO
OPTIMIZE_OUTPUT_JAVA = NO
BUILTIN_STL_SUPPORT = NO
CPP_CLI_SUPPORT = NO
SIP_SUPPORT = NO
DISTRIBUTE_GROUP_DOC = NO
SUBGROUPING = YES
TYPEDEF_HIDES_STRUCT = NO
#---------------------------------------------------------------------------
# Build related configuration options
#---------------------------------------------------------------------------
# Set this to NO to get warnings about undocumented members/classes
EXTRACT_ALL = YES
EXTRACT_PRIVATE = NO
EXTRACT_STATIC = NO
EXTRACT_LOCAL_CLASSES = NO
EXTRACT_LOCAL_METHODS = NO
EXTRACT_ANON_NSPACES = NO
HIDE_UNDOC_MEMBERS = NO
HIDE_UNDOC_CLASSES = NO
HIDE_FRIEND_COMPOUNDS = NO
HIDE_IN_BODY_DOCS = NO
INTERNAL_DOCS = NO
CASE_SENSE_NAMES = YES
HIDE_SCOPE_NAMES = NO
SHOW_INCLUDE_FILES = YES
INLINE_INFO = YES
SORT_MEMBER_DOCS = YES
SORT_BRIEF_DOCS = YES
SORT_BY_SCOPE_NAME = NO
GENERATE_TODOLIST = YES
GENERATE_TESTLIST = YES
GENERATE_BUGLIST = YES
GENERATE_DEPRECATEDLIST= YES
ENABLED_SECTIONS =
MAX_INITIALIZER_LINES = 30
SHOW_USED_FILES = YES
FILE_VERSION_FILTER =
#---------------------------------------------------------------------------
# configuration options related to warning and progress messages
#---------------------------------------------------------------------------
QUIET = YES
WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES
WARN_IF_DOC_ERROR = YES
WARN_NO_PARAMDOC = YES
WARN_FORMAT = "$file:$line: $text"
WARN_LOGFILE =
%{if maintainer_mode}
WARN_AS_ERROR = YES
%{endif}
#---------------------------------------------------------------------------
# configuration options related to the input files
#---------------------------------------------------------------------------
INPUT = %{src_dir}/lib
INPUT_ENCODING = UTF-8
FILE_PATTERNS =
RECURSIVE = YES
EXCLUDE =
EXCLUDE_SYMLINKS = NO
EXCLUDE_PATTERNS = */wrap/*
EXCLUDE_SYMBOLS =
EXAMPLE_PATH =
EXAMPLE_PATTERNS =
EXAMPLE_RECURSIVE = NO
IMAGE_PATH =
INPUT_FILTER =
FILTER_PATTERNS =
FILTER_SOURCE_FILES = NO
#---------------------------------------------------------------------------
# configuration options related to source browsing
#---------------------------------------------------------------------------
SOURCE_BROWSER = YES
INLINE_SOURCES = YES
STRIP_CODE_COMMENTS = NO
REFERENCED_BY_RELATION = YES
REFERENCES_RELATION = YES
REFERENCES_LINK_SOURCE = YES
USE_HTAGS = NO
VERBATIM_HEADERS = YES
#---------------------------------------------------------------------------
# configuration options related to the alphabetical class index
#---------------------------------------------------------------------------
ALPHABETICAL_INDEX = YES
COLS_IN_ALPHA_INDEX = 5
IGNORE_PREFIX =
#---------------------------------------------------------------------------
# configuration options related to the HTML output
#---------------------------------------------------------------------------
GENERATE_HTML = YES
HTML_OUTPUT = .
HTML_FILE_EXTENSION = .html
HTML_HEADER =
HTML_FOOTER =
HTML_STYLESHEET =
GENERATE_HTMLHELP = NO
HTML_DYNAMIC_SECTIONS = NO
CHM_FILE =
HHC_LOCATION =
GENERATE_CHI = NO
BINARY_TOC = NO
TOC_EXPAND = NO
DISABLE_INDEX = NO
ENUM_VALUES_PER_LINE = 4
GENERATE_TREEVIEW = NO
TREEVIEW_WIDTH = 250
#---------------------------------------------------------------------------
# Configuration options related to other output formats
#---------------------------------------------------------------------------
GENERATE_LATEX = NO
GENERATE_MAN = NO
GENERATE_RTF = NO
GENERATE_XML = NO
#---------------------------------------------------------------------------
# Configuration options related to the preprocessor
#---------------------------------------------------------------------------
ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = YES
EXPAND_ONLY_PREDEF = NO
SEARCH_INCLUDES = YES
INCLUDE_PATH =
INCLUDE_FILE_PATTERNS =
PREDEFINED = BOTAN_HAS_AES_ARMV8 \
BOTAN_HAS_AES_NI \
BOTAN_HAS_AES_POWER8 \
BOTAN_HAS_AES_SSSE3 \
BOTAN_HAS_CHACHA_SSE2 \
BOTAN_HAS_CHACHA_AVX2 \
BOTAN_HAS_IDEA_SSE2 \
BOTAN_HAS_NOEKEON_SIMD \
BOTAN_HAS_SERPENT_SIMD \
BOTAN_HAS_SERPENT_AVX2 \
BOTAN_HAS_SHA1_SSE2 \
BOTAN_HAS_SHA2_32_X86 \
BOTAN_HAS_SHA2_32_X86_BMI2 \
BOTAN_HAS_SHACAL2_SIMD \
BOTAN_HAS_SHACAL2_X86 \
BOTAN_HAS_SM4_ARMV8 \
BOTAN_HAS_THREEFISH_512_AVX2 \
BOTAN_DEPRECATED(msg)= \
BOTAN_PUBLIC_API(maj,min)=
EXPAND_AS_DEFINED =
SKIP_FUNCTION_MACROS = YES
#---------------------------------------------------------------------------
# Configuration::additions related to external references
#---------------------------------------------------------------------------
TAGFILES =
GENERATE_TAGFILE =
ALLEXTERNALS = NO
EXTERNAL_GROUPS = YES
PERL_PATH = /usr/bin/perl
#---------------------------------------------------------------------------
# Configuration options related to the dot tool
#---------------------------------------------------------------------------
CLASS_DIAGRAMS = YES
MSCGEN_PATH =
HIDE_UNDOC_RELATIONS = YES
HAVE_DOT = NO
CLASS_GRAPH = YES
COLLABORATION_GRAPH = YES
GROUP_GRAPHS = YES
UML_LOOK = NO
TEMPLATE_RELATIONS = NO
INCLUDE_GRAPH = YES
INCLUDED_BY_GRAPH = YES
CALL_GRAPH = NO
CALLER_GRAPH = NO
GRAPHICAL_HIERARCHY = YES
DIRECTORY_GRAPH = YES
DOT_IMAGE_FORMAT = png
DOT_PATH =
DOTFILE_DIRS =
DOT_GRAPH_MAX_NODES = 50
MAX_DOT_GRAPH_DEPTH = 0
DOT_TRANSPARENT = YES
DOT_MULTI_TARGETS = NO
GENERATE_LEGEND = YES
DOT_CLEANUP = YES
#---------------------------------------------------------------------------
# Configuration::additions related to the search engine
#---------------------------------------------------------------------------
SEARCHENGINE = NO

View File

@@ -1,12 +0,0 @@
prefix=%{prefix}
exec_prefix=${prefix}
libdir=${prefix}/%{libdir}
includedir=${prefix}/include/botan-%{version_major}
Name: Botan
Description: Crypto and TLS for C++11
Version: %{version}
Libs: -L${libdir} -lbotan-%{version_major} %{cxx_abi_flags}
Libs.private: %{link_to}
Cflags: -I${includedir}

View File

@@ -1,262 +0,0 @@
#ifndef BOTAN_BUILD_CONFIG_H_
#define BOTAN_BUILD_CONFIG_H_
/*
* This file was automatically generated running
* '%{command_line}'
*
* Target
* - Compiler: %{cxx} %{cxx_abi_flags} %{cc_lang_flags} %{cc_compile_flags}
* - Arch: %{arch}
* - OS: %{os}
*/
#define BOTAN_VERSION_MAJOR %{version_major}
#define BOTAN_VERSION_MINOR %{version_minor}
#define BOTAN_VERSION_PATCH %{version_patch}
#define BOTAN_VERSION_DATESTAMP %{version_datestamp}
#define BOTAN_VERSION_RELEASE_TYPE "%{release_type}"
#define BOTAN_VERSION_VC_REVISION "%{version_vc_rev}"
#define BOTAN_DISTRIBUTION_INFO "%{distribution_info}"
/* How many bits per limb in a BigInt */
#define BOTAN_MP_WORD_BITS %{mp_bits}
%{if fuzzer_mode}
#define BOTAN_UNSAFE_FUZZER_MODE
%{endif}
%{if fuzzer_type}
#define BOTAN_FUZZER_IS_%{fuzzer_type}
%{endif}
#define BOTAN_INSTALL_PREFIX R"(%{prefix})"
#define BOTAN_INSTALL_HEADER_DIR "%{includedir}/botan-%{version_major}"
#define BOTAN_INSTALL_LIB_DIR "%{libdir}"
#define BOTAN_LIB_LINK "%{link_to}"
#define BOTAN_LINK_FLAGS "%{cxx_abi_flags}"
#ifndef BOTAN_DLL
#define BOTAN_DLL %{visibility_attribute}
#endif
/* Target identification and feature test macros */
#define BOTAN_TARGET_OS_IS_%{os_name|upper}
%{for os_features}
#define BOTAN_TARGET_OS_HAS_%{i|upper}
%{endfor}
#define BOTAN_BUILD_COMPILER_IS_%{cc_macro}
%{for sanitizer_types}
#define BOTAN_HAS_SANITIZER_%{i|upper}
%{endfor}
%{if test_mode}
#define BOTAN_TEST_MODE
%{endif}
#define BOTAN_TARGET_ARCH_IS_%{arch|upper}
%{if endian}
#define BOTAN_TARGET_CPU_IS_%{endian|upper}_ENDIAN
%{endif}
%{if cpu_family}
#define BOTAN_TARGET_CPU_IS_%{cpu_family|upper}_FAMILY
%{endif}
%{if cpu_is_64bit}
#define BOTAN_TARGET_CPU_HAS_NATIVE_64BIT
%{endif}
%{for cpu_features}
#define BOTAN_TARGET_SUPPORTS_%{i|upper}
%{endfor}
%{if with_valgrind}
#define BOTAN_HAS_VALGRIND
%{endif}
%{if with_openmp}
#define BOTAN_TARGET_HAS_OPENMP
%{endif}
%{if with_debug_asserts}
#define BOTAN_ENABLE_DEBUG_ASSERTS
%{endif}
%{if optimize_for_size}
#define BOTAN_OPTIMIZE_FOR_SIZE
%{endif}
/*
* Module availability definitions
*/
%{for module_defines}
#define BOTAN_HAS_%{i}
%{endfor}
/*
* Local/misc configuration options (if any) follow
*/
%{local_config}
/*
* Things you can edit (but probably shouldn't)
*/
#if !defined(BOTAN_DEPRECATED_PUBLIC_MEMBER_VARIABLES)
#if defined(BOTAN_NO_DEPRECATED)
#define BOTAN_DEPRECATED_PUBLIC_MEMBER_VARIABLES private
#else
#define BOTAN_DEPRECATED_PUBLIC_MEMBER_VARIABLES public
#endif
#endif
/* How much to allocate for a buffer of no particular size */
#define BOTAN_DEFAULT_BUFFER_SIZE 1024
/* Minimum and maximum sizes to allocate out of the mlock pool (bytes)
Default min is 16 as smaller values are easily bruteforceable and thus
likely not cryptographic keys.
*/
#define BOTAN_MLOCK_ALLOCATOR_MIN_ALLOCATION 16
#define BOTAN_MLOCK_ALLOCATOR_MAX_ALLOCATION 128
/*
* Total maximum amount of RAM (in KiB) we will lock into memory, even
* if the OS would let us lock more
*/
#define BOTAN_MLOCK_ALLOCATOR_MAX_LOCKED_KB 512
/*
* If enabled uses memset via volatile function pointer to zero memory,
* otherwise does a byte at a time write via a volatile pointer.
*/
#define BOTAN_USE_VOLATILE_MEMSET_FOR_ZERO 1
/*
* Normally blinding is performed by choosing a random starting point (plus
* its inverse, of a form appropriate to the algorithm being blinded), and
* then choosing new blinding operands by successive squaring of both
* values. This is much faster than computing a new starting point but
* introduces some possible corelation
*
* To avoid possible leakage problems in long-running processes, the blinder
* periodically reinitializes the sequence. This value specifies how often
* a new sequence should be started.
*/
#define BOTAN_BLINDING_REINIT_INTERVAL 64
/*
* Userspace RNGs like HMAC_DRBG will reseed after a specified number
* of outputs are generated. Set to zero to disable automatic reseeding.
*/
#define BOTAN_RNG_DEFAULT_RESEED_INTERVAL 1024
#define BOTAN_RNG_RESEED_POLL_BITS 256
#define BOTAN_RNG_AUTO_RESEED_TIMEOUT std::chrono::milliseconds(10)
#define BOTAN_RNG_RESEED_DEFAULT_TIMEOUT std::chrono::milliseconds(50)
/*
* Specifies (in order) the list of entropy sources that will be used
* to seed an in-memory RNG. The first in the default list: "rdseed"
* and "rdrand" do not count as contributing any entropy but are
* included as they are fast and help protect against a seriously
* broken system RNG.
*/
#define BOTAN_ENTROPY_DEFAULT_SOURCES \
{ "rdseed", "rdrand", "getentropy", "dev_random", \
"system_rng", "proc_walk", "system_stats" }
/* Multiplier on a block cipher's native parallelism */
#define BOTAN_BLOCK_CIPHER_PAR_MULT 4
/*
* These control the RNG used by the system RNG interface
*/
#define BOTAN_SYSTEM_RNG_DEVICE "/dev/urandom"
#define BOTAN_SYSTEM_RNG_POLL_DEVICES { "/dev/urandom", "/dev/random" }
/*
* This directory will be monitored by ProcWalking_EntropySource and
* the contents provided as entropy inputs to the RNG. May also be
* usefully set to something like "/sys", depending on the system being
* deployed to. Set to an empty string to disable.
*/
#define BOTAN_ENTROPY_PROC_FS_PATH "/proc"
/*
* These paramaters control how many bytes to read from the system
* PRNG, and how long to block if applicable. The timeout only applies
* to reading /dev/urandom and company.
*/
#define BOTAN_SYSTEM_RNG_POLL_REQUEST 64
#define BOTAN_SYSTEM_RNG_POLL_TIMEOUT_MS 20
/*
How many times to read from the RDRAND/RDSEED RNGs.
Each read generates 32 bits of output
*/
#define BOTAN_ENTROPY_INTEL_RNG_POLLS 32
// According to Intel, RDRAND is guaranteed to generate a random number within 10 retries on a working CPU
#define BOTAN_ENTROPY_RDRAND_RETRIES 10
/*
* RdSeed is not guaranteed to generate a random number within a specific number of retries
* Define the number of retries here
*/
#define BOTAN_ENTROPY_RDSEED_RETRIES 20
/*
* If no way of dynamically determining the cache line size for the
* system exists, this value is used as the default. Used by the side
* channel countermeasures rather than for alignment purposes, so it is
* better to be on the smaller side if the exact value cannot be
* determined. Typically 32 or 64 bytes on modern CPUs.
*/
#if !defined(BOTAN_TARGET_CPU_DEFAULT_CACHE_LINE_SIZE)
#define BOTAN_TARGET_CPU_DEFAULT_CACHE_LINE_SIZE 32
#endif
/**
* Controls how AutoSeeded_RNG is instantiated
*/
#if !defined(BOTAN_AUTO_RNG_HMAC)
#if defined(BOTAN_HAS_SHA2_64)
#define BOTAN_AUTO_RNG_HMAC "HMAC(SHA-384)"
#elif defined(BOTAN_HAS_SHA2_32)
#define BOTAN_AUTO_RNG_HMAC "HMAC(SHA-256)"
#elif defined(BOTAN_HAS_SHA3)
#define BOTAN_AUTO_RNG_HMAC "HMAC(SHA-3(256))"
#elif defined(BOTAN_HAS_SHA1)
#define BOTAN_AUTO_RNG_HMAC "HMAC(SHA-1)"
#endif
// Otherwise, no hash found: leave BOTAN_AUTO_RNG_HMAC undefined
#endif
// Check for a common build problem:
#if defined(BOTAN_TARGET_ARCH_IS_X86_64) && ((defined(_MSC_VER) && !defined(_WIN64)) || \
(defined(__clang__) && !defined(__x86_64__)) || \
(defined(__GNUG__) && !defined(__x86_64__)))
#error "Trying to compile Botan configured as x86_64 with non-x86_64 compiler."
#endif
#if defined(BOTAN_TARGET_ARCH_IS_X86_32) && ((defined(_MSC_VER) && defined(_WIN64)) || \
(defined(__clang__) && !defined(__i386__)) || \
(defined(__GNUG__) && !defined(__i386__)))
#error "Trying to compile Botan configured as x86_32 with non-x86_32 compiler."
#endif
#include <botan/compiler.h>
#endif

View File

@@ -1,82 +0,0 @@
macro_name CLANG
binary_name clang++
lang_flags "-std=c++11 -D_REENTRANT"
warning_flags "-Wall -Wextra -Wpedantic -Wshadow -Wstrict-aliasing -Wstrict-overflow=5 -Wcast-align -Wmissing-declarations -Wpointer-arith -Wcast-qual"
maintainer_warning_flags "-Wunreachable-code -Wdocumentation -Qunused-arguments -Werror -Wno-error=unused-parameter -Wno-error=unreachable-code"
optimization_flags "-O3"
sanitizer_optimization_flags "-O1 -fno-optimize-sibling-calls -fno-omit-frame-pointer"
size_optimization_flags "-Os"
add_sysroot_option "--sysroot="
<sanitizers>
default -> address,undefined
address -> "-fsanitize=address"
undefined -> "-fsanitize=undefined -fno-sanitize-recover=undefined"
coverage -> "-fsanitize-coverage=edge,indirect-calls,trace-pc-guard,trace-cmp,trace-gep"
memory -> "-fsanitize=memory"
</sanitizers>
shared_flags "-fPIC"
coverage_flags "--coverage"
stack_protector_flags "-fstack-protector"
visibility_build_flags "-fvisibility=hidden"
visibility_attribute '__attribute__((visibility("default")))'
<so_link_commands>
darwin -> "$(CXX) -dynamiclib -fPIC -install_name $(INSTALLED_LIB_DIR)/{soname_abi} -current_version {darwin_so_current_ver} -compatibility_version {darwin_so_compat_ver}"
# The default works for GNU ld and several other Unix linkers
default -> "$(CXX) -shared -fPIC -Wl,-soname,{soname_abi}"
</so_link_commands>
<binary_link_commands>
darwin -> "$(LINKER) -headerpad_max_install_names"
linux -> "$(LINKER) -Wl,-rpath=\$$ORIGIN"
freebsd -> "$(LINKER) -Wl,-rpath=\$$ORIGIN"
default -> "$(LINKER)"
llvm -> "llvm-link"
</binary_link_commands>
<isa_flags>
sse2 -> "-msse2"
ssse3 -> "-mssse3"
sse41 -> "-msse4.1"
sse42 -> "-msse4.2"
avx2 -> "-mavx2"
bmi2 -> "-mbmi -mbmi2"
aesni -> "-maes -mpclmul -mssse3"
rdrand -> "-mrdrnd"
rdseed -> "-mrdseed"
sha -> "-msha"
altivec -> "-maltivec"
arm64:armv8crypto -> ""
arm32:neon -> "-mfpu=neon"
arm64:neon -> ""
</isa_flags>
<cpu_flags>
llvm -> "-emit-llvm -fno-use-cxa-atexit"
</cpu_flags>
<mach_abi_linking>
all!haiku,darwin -> "-pthread"
openmp -> "-fopenmp"
x86_32 -> "-m32"
x86_64 -> "-m64"
ppc64 -> "-m64"
darwin -> "-stdlib=libc++"
ios -> "-stdlib=libc++"
netbsd -> "-D_NETBSD_SOURCE"
</mach_abi_linking>

View File

@@ -1,17 +0,0 @@
macro_name PATHSCALE
binary_name pathCC
optimization_flags "-O3"
lang_flags "-D_REENTRANT -ansi -Wno-long-long"
warning_flags "-W -Wall"
ar_command pathCC
ar_options "-ar -o"
shared_flags "-fPIC"
<so_link_commands>
default -> "$(CXX) -shared -fPIC -Wl,-soname,{soname_abi}"
</so_link_commands>

View File

@@ -1,103 +0,0 @@
macro_name GCC
binary_name g++
lang_flags "-std=c++11 -D_REENTRANT"
# This should only contain flags which are included in GCC 4.8
warning_flags "-Wall -Wextra -Wpedantic -Wstrict-aliasing -Wcast-align -Wmissing-declarations -Wpointer-arith -Wcast-qual -Wzero-as-null-pointer-constant -Wnon-virtual-dtor"
maintainer_warning_flags "-Wstrict-overflow=5 -Wold-style-cast -Wsuggest-override -Wshadow -Werror -Wno-error=strict-overflow"
optimization_flags "-O3"
sanitizer_optimization_flags "-O1 -fno-optimize-sibling-calls -fno-omit-frame-pointer"
size_optimization_flags "-Os"
shared_flags "-fPIC"
coverage_flags "--coverage"
stack_protector_flags "-fstack-protector"
add_sysroot_option "--sysroot="
<sanitizers>
default -> iterator,address
iterator -> "-D_GLIBCXX_DEBUG"
address -> "-fsanitize=address"
undefined -> "-fsanitize=undefined -fno-sanitize-recover=undefined"
</sanitizers>
visibility_build_flags "-fvisibility=hidden"
visibility_attribute '__attribute__((visibility("default")))'
<so_link_commands>
# The default works for GNU ld and several other Unix linkers
default -> "$(CXX) -shared -fPIC -Wl,-soname,{soname_abi}"
# Darwin, HP-UX and Solaris linkers use different syntax
darwin -> "$(CXX) -dynamiclib -fPIC -install_name $(INSTALLED_LIB_DIR)/{soname_abi}"
hpux -> "$(CXX) -shared -fPIC -Wl,+h,{soname_abi}"
solaris -> "$(CXX) -shared -fPIC -Wl,-h,{soname_abi}"
# AIX and OpenBSD don't use sonames at all
aix -> "$(CXX) -shared -fPIC"
openbsd -> "$(CXX) -shared -fPIC"
</so_link_commands>
<binary_link_commands>
linux -> "$(LINKER) -Wl,-rpath=\$$ORIGIN"
default -> "$(LINKER)"
</binary_link_commands>
<isa_flags>
sse2 -> "-msse2"
ssse3 -> "-mssse3"
sse41 -> "-msse4.1"
sse42 -> "-msse4.2"
avx2 -> "-mavx2"
bmi2 -> "-mbmi -mbmi2"
aesni -> "-maes -mpclmul -mssse3"
rdrand -> "-mrdrnd"
rdseed -> "-mrdseed"
sha -> "-msha"
altivec -> "-maltivec"
ppccrypto -> "-mcrypto"
arm64:armv8crypto -> ""
arm64:armv8sm3 -> "-march=armv8.2-a+sm4"
arm64:armv8sm4 -> "-march=armv8.2-a+sm4"
arm64:armv8sha512 -> "-march=armv8.2-a+sha3"
arm64:armv8sha3 -> "-march=armv8.2-a+sha3"
# For Aarch32 -mfpu=neon is required
# For Aarch64 NEON is enabled by default
arm32:neon -> "-mfpu=neon"
arm64:neon -> ""
</isa_flags>
<cpu_flags_no_debug>
x86_32 -> "-momit-leaf-frame-pointer"
x86_64 -> "-momit-leaf-frame-pointer"
</cpu_flags_no_debug>
# Flags set here are included at compile and link time
<mach_abi_linking>
all!haiku -> "-pthread"
openmp -> "-fopenmp"
mips64 -> "-mabi=64"
s390 -> "-m31"
s390x -> "-m64"
sparc32 -> "-m32 -mno-app-regs"
sparc64 -> "-m64 -mno-app-regs"
ppc64 -> "-m64"
x86_32 -> "-m32"
x86_64 -> "-m64"
x32 -> "-mx32"
netbsd -> "-D_NETBSD_SOURCE"
qnx -> "-fexceptions -D_QNX_SOURCE"
cygwin -> "-U__STRICT_ANSI__"
</mach_abi_linking>

View File

@@ -1,18 +0,0 @@
macro_name HP_ACC
binary_name aCC
lang_flags "-AA -ext +eh -z"
optimization_flags "+O2"
warning_flags "+w"
shared_flags "+Z"
<mach_abi_linking>
hppa1.0 -> "+DAportable"
hppa1.1 -> "+DA1.1"
hppa2.0 -> "+DA2.0W"
</mach_abi_linking>
<so_link_commands>
default -> "$(CXX) +Z -b -Wl,+h,{soname_abi}" # Documented in cc(1), but not CC(1) (?)
</so_link_commands>

View File

@@ -1,24 +0,0 @@
macro_name INTEL
binary_name icpc
optimization_flags "-O2"
size_optimization_flags "-Os"
lang_flags "-std=c++11"
warning_flags "-w1"
shared_flags "-fPIC"
<isa_flags>
sse2 -> "-msse2"
ssse3 -> "-mssse3"
sse41 -> "-msse4.1"
sse42 -> "-msse4.2"
avx2 -> "-march=core-avx2"
aesni -> "-march=corei7"
rdrand -> "-march=core-avx-i"
</isa_flags>
<so_link_commands>
default -> "$(CXX) -fPIC -shared -Wl,-soname,{soname_abi}"
</so_link_commands>

View File

@@ -1,66 +0,0 @@
macro_name MSVC
binary_name cl
linker_name link
output_to_object "/Fo"
output_to_exe "/OUT:"
add_include_dir_option "/I"
add_lib_dir_option "/LIBPATH:"
add_lib_option ""
compile_flags "/nologo /c"
optimization_flags "/O2 /Oi"
size_optimization_flags "/O1 /Os"
# for debug info in the object file:
#debug_info_flags "/Z7"
# for using a PDB file:
debug_info_flags "/Zi /FS"
preproc_flags "/nologo /EP"
lang_flags "/EHs /GR /D_ENABLE_EXTENDED_ALIGNED_STORAGE"
warning_flags "/W4 /wd4250 /wd4251 /wd4275"
visibility_build_flags "/DBOTAN_DLL=__declspec(dllexport)"
visibility_attribute "__declspec(dllimport)"
ar_command lib
ar_options "/nologo"
ar_output_to "/OUT:"
<isa_flags>
sse2 -> ""
ssse3 -> ""
sse41 -> ""
sse42 -> ""
x86_64:avx2 -> "/arch:AVX"
bmi2 -> ""
aesni -> ""
clmul -> ""
rdrand -> ""
rdseed -> ""
sha -> ""
</isa_flags>
<so_link_commands>
default -> "$(LINKER) /DLL"
default-debug -> "$(LINKER) /DLL /DEBUG"
</so_link_commands>
<binary_link_commands>
default -> "$(LINKER)"
default-debug -> "$(LINKER) /DEBUG"
</binary_link_commands>
<mach_abi_linking>
all -> "/bigobj"
# These can be overridden with --msvc-runtime option
rt -> "/MD"
rt-debug -> "/MDd"
</mach_abi_linking>

View File

@@ -1,11 +0,0 @@
macro_name PORTLAND_GROUP
binary_name pgCC
optimization_flags "-fast -Minline"
shared_flags "-fPIC"
<so_link_commands>
linux -> "$(CXX) -shared -fPIC -Wl,-soname,{soname_abi}"
solaris -> "$(CXX) -G -fPIC -Wl,-h,{soname_abi}"
</so_link_commands>

View File

@@ -1,39 +0,0 @@
macro_name SUN_STUDIO
binary_name CC
optimization_flags "-xO2"
shared_flags "-KPIC"
warning_flags "+w -erroff=truncwarn,wnoretvalue,wlessrestrictedthrow"
lang_flags "-std=c++11 +p -features=extensions"
ar_command CC
ar_options "-xar -o"
<so_link_commands>
default -> "$(CXX) -G -h{soname_abi}"
</so_link_commands>
<mach_abi_linking>
# Needed on some Linux distros
linux -> "-library=stlport4"
sparc64 -> "-m64 -xarch=sparc"
x86_64 -> "-m64"
</mach_abi_linking>
<isa_flags>
# Botan needs C++11, and that requires Sun Studio 12.4 or above.
# Sun Studio 12.4 supports upto -xarch=avx2, but the processor must support it
# AESNI requires -xarch=aes, and RDRAND requires -xarch=avx_i.
# https://docs.oracle.com/cd/E37069_01/html/E37074/bjapp.html#OSSCGbkazd
sse2 -> "-xarch=sse2"
ssse3 -> "-xarch=ssse3"
sse41 -> "-xarch=sse4.1"
sse42 -> "-xarch=sse4.2"
aesni -> "-xarch=aes"
avx -> "-xarch=avx"
rdrand -> "-xarch=avx_i"
avx2 -> "-xarch=avx2"
</isa_flags>

View File

@@ -1,24 +0,0 @@
macro_name XLC
binary_name xlC
optimization_flags "-O2"
lang_flags "-std=c++11"
visibility_build_flags "-fvisibility=hidden"
visibility_attribute '__attribute__((visibility("default")))'
<isa_flags>
altivec -> "-qaltivec"
</isa_flags>
<so_link_commands>
default -> "$(CXX) -qmkshrobj"
</so_link_commands>
<sanitizers>
default -> "-qcheck=all"
address -> "-qcheck=bounds:stackclobber:unset"
undefined -> "-qcheck=nullptr:divzero"
</sanitizers>

View File

@@ -1,73 +0,0 @@
cmake_minimum_required(VERSION 2.8.0)
project(botan)
if(POLICY CMP0042)
cmake_policy(SET CMP0042 NEW)
endif()
set(BOTAN_SOURCES
%{for lib_srcs}
"%{i}"
%{endfor}
)
set(BOTAN_CLI
%{for cli_srcs}
"%{i}"
%{endfor}
)
set(BOTAN_TESTS
%{for test_srcs}
"%{i}"
%{endfor}
)
%{for isa_build_info}
set_source_files_properties("%{src}" PROPERTIES COMPILE_FLAGS "%{isa_flags}")
%{endfor}
option(ENABLED_OPTIONAL_WARINIGS "If enabled more strict warning policy will be used" OFF)
option(ENABLED_LTO "If enabled link time optimization will be used" OFF)
set(COMPILER_FEATURES_RELEASE %{cc_lang_flags} %{cc_compile_opt_flags} %{cxx_abi_opt_flags})
set(COMPILER_FEATURES_DEBUG %{cc_lang_flags} %{cc_compile_debug_flags} %{cxx_abi_debug_flags})
set(COMPILER_FEATURES $<$<NOT:$<CONFIG:DEBUG>>:${COMPILER_FEATURES_RELEASE}> $<$<CONFIG:DEBUG>:${COMPILER_FEATURES_DEBUG}>)
set(SHARED_FEATURES %{cmake_shared_flags})
set(STATIC_FEATURES -DBOTAN_DLL=)
set(COMPILER_WARNINGS %{cc_warning_flags})
set(COMPILER_INCLUDE_DIRS build/include build/include/external)
if(ENABLED_LTO)
set(COMPILER_FEATURES ${COMPILER_FEATURES} -lto)
endif()
if(ENABLED_OPTIONAL_WARINIGS)
set(COMPILER_OPTIONAL_WARNINGS -Wsign-promo -Wctor-dtor-privacy -Wdeprecated -Winit-self -Wnon-virtual-dtor -Wunused-macros -Wold-style-cast -Wuninitialized)
endif()
add_library(${PROJECT_NAME} STATIC ${BOTAN_SOURCES})
target_link_libraries(${PROJECT_NAME} PUBLIC %{cmake_link_to})
target_compile_options(${PROJECT_NAME} PUBLIC ${COMPILER_WARNINGS} ${COMPILER_FEATURES} ${COMPILER_OPTIONAL_WARNINGS} PRIVATE ${STATIC_FEATURES})
target_include_directories(${PROJECT_NAME} PUBLIC ${COMPILER_INCLUDE_DIRS})
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME}-static)
add_library(${PROJECT_NAME}_shared SHARED ${BOTAN_SOURCES})
target_link_libraries(${PROJECT_NAME}_shared PUBLIC %{cmake_link_to})
target_compile_options(${PROJECT_NAME}_shared PUBLIC ${COMPILER_WARNINGS} ${COMPILER_FEATURES} ${COMPILER_OPTIONAL_WARNINGS} PRIVATE ${SHARED_FEATURES})
target_include_directories(${PROJECT_NAME}_shared PUBLIC ${COMPILER_INCLUDE_DIRS})
set_target_properties(${PROJECT_NAME}_shared PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
add_executable(${PROJECT_NAME}_cli ${BOTAN_CLI})
target_link_libraries(${PROJECT_NAME}_cli PRIVATE ${PROJECT_NAME}_shared )
set_target_properties(${PROJECT_NAME}_cli PROPERTIES OUTPUT_NAME ${PROJECT_NAME}-cli)
add_executable(${PROJECT_NAME}_tests ${BOTAN_TESTS})
target_link_libraries(${PROJECT_NAME}_tests PRIVATE ${PROJECT_NAME}_shared )
set_target_properties(${PROJECT_NAME}_tests PROPERTIES OUTPUT_NAME botan-test)
set(GLOBAL_CONFIGURATION_FILES configure.py .gitignore news.rst readme.rst)
file(GLOB_RECURSE CONFIGURATION_FILES src/configs/* )
file(GLOB_RECURSE DOCUMENTATION_FILES doc/* )
file(GLOB_RECURSE HEADER_FILES src/*.h )
file(GLOB_RECURSE INFO_FILES src/lib/*info.txt )
add_custom_target(CONFIGURATION_DUMMY SOURCES ${GLOBAL_CONFIGURATION_FILES} ${CONFIGURATION_FILES} ${DOCUMENTATION_FILES} ${INFO_FILES} ${HEADER_FILES})

View File

@@ -1,71 +0,0 @@
#if defined(__x86_64__) && defined(__ILP32__)
X32
#elif defined(__x86_64__) || defined(_M_X64)
X86_64
#elif defined(__i386__) || defined(__i386) || defined(_M_IX86)
X86_32
#elif defined(__aarch64__) || defined(__ARM_ARCH_ISA_A64)
ARM64
#elif defined(__arm__) || defined(_M_ARM) || defined(__ARM_ARCH_7A__)
ARM32
#elif defined(__powerpc64__) || defined(__ppc64__) || defined(_ARCH_PPC64)
PPC64
#elif defined(__powerpc__) || defined(__ppc__) || defined(_ARCH_PPC)
PPC32
#elif defined(__mips__) || defined(__mips)
#if defined(__LP64__) || defined(_LP64)
MIPS64
#else
MIPS32
#endif
#elif defined(__sparc__)
#if defined(__LP64__) || defined(_LP64)
SPARC64
#else
SPARC32
#endif
#elif defined(__alpha__)
ALPHA
#elif defined(__hppa__) || defined(__hppa)
HPPA
#elif defined(__ia64__)
IA64
#elif defined(__m68k__)
M68K
#elif defined(__sh__)
SH
#elif defined(__s390x__)
S390X
#elif defined(__s390__)
S390
#elif defined(__riscv)
#if defined(__LP64__)
RISCV64
#else
RISCV32
#endif
#else
UNKNOWN
#endif

View File

@@ -1,60 +0,0 @@
/*
* This file is preprocessed to produce output that is examined by
* configure.py to determine the compilers version number.
*/
#if defined(_MSC_VER)
/*
_MSC_VER Defined as an integer literal that encodes the major and
minor number elements of the compiler's version number. The major
number is the first element of the period-delimited version number
and the minor number is the second element. For example, if the
version number of the Visual C++ compiler is 17.00.51106.1, the
_MSC_VER macro evaluates to 1700.
https://msdn.microsoft.com/en-us/library/b0084kay.aspx
*/
MSVC _MSC_VER
#elif defined(__xlC__)
XLC __xlC__
#elif defined(__clang__) && defined(__apple_build_version__)
/*
Map Apple LLVM versions as used in XCode back to standard Clang.
This is not exact since the versions used in XCode are actually
forks of Clang and do not coorespond perfectly to standard Clang
releases. In addition we don't bother mapping very old versions
(anything before XCode 7 is treated like Clang 3.5, which is the
oldest version we support) and for "future" versions we simply
treat them as Clang 4.0, since we don't currenly rely on any
features not included in 4.0
*/
#if __clang_major__ >= 9
CLANG 4 0
#elif __clang_major__ == 8
CLANG 3 9
#elif __clang_major__ == 7 && __clang_minor__ == 3
CLANG 3 8
#elif __clang_major__ == 7
CLANG 3 7
#else
CLANG 3 5
#endif
#elif defined(__clang__)
CLANG __clang_major__ __clang_minor__
#elif defined(__GNUG__)
GCC __GNUC__ __GNUC_MINOR__
#else
UNKNOWN 0 0
#endif

View File

@@ -1,73 +0,0 @@
; A script for packaging botan with InnoSetup
[Setup]
AppName=Botan
AppVerName=Botan %{version}
AppPublisher=Jack Lloyd
AppPublisherURL=https://botan.randombit.net/
AppVersion=%{version}
VersionInfoCopyright=Copyright (C) 1999-2012 Jack Lloyd and others
VersionInfoVersion=%{version_major}.%{version_minor}.%{version_patch}.0
; Require at least Windows XP
MinVersion=5.1
ArchitecturesAllowed=%{innosetup_arch}
ArchitecturesInstallIn64BitMode=%{innosetup_arch}
DefaultDirName={pf}\botan
DefaultGroupName=botan
SolidCompression=yes
OutputDir=.
OutputBaseFilename=botan-%{version}-%{arch}
[Types]
Name: "user"; Description: "User"
Name: "devel"; Description: "Developer"
Name: "custom"; Description: "Custom"; Flags: iscustom
[Components]
name: "dll"; Description: "Runtime DLLs"; Types: user devel custom; Flags: fixed
name: "implib"; Description: "Import Library"; Types: devel
name: "includes"; Description: "Include Files"; Types: devel
name: "docs"; Description: "Developer Documentation"; Types: devel
[Files]
; DLL and license file is always included
Source: "..\doc\license.rst"; DestDir: "{app}"; Components: dll; AfterInstall: ConvertLineEndings
Source: "..\botan.dll"; DestDir: "{app}"; Components: dll
Source: "..\botan.dll.manifest"; DestDir: "{app}"; Components: dll; Flags: skipifsourcedoesntexist
Source: "include\botan\*"; DestDir: "{app}\include\botan"; Components: includes; AfterInstall: ConvertLineEndings
Source: "..\doc\*.rst"; DestDir: "{app}\doc"; Excludes: "license.rst"; Components: docs; AfterInstall: ConvertLineEndings
Source: "..\doc\examples\*.cpp"; DestDir: "{app}\doc\examples"; Components: docs; AfterInstall: ConvertLineEndings
Source: "..\botan.exp"; DestDir: "{app}"; Components: implib
Source: "..\botan.lib"; DestDir: "{app}"; Components: implib
[Code]
const
LF = #10;
CR = #13;
CRLF = CR + LF;
procedure ConvertLineEndings();
var
FilePath : String;
FileContents : String;
begin
FilePath := ExpandConstant(CurrentFileName)
if ExtractFileName(CurrentFileName) <> 'build.h' then
begin
LoadStringFromFile(FilePath, FileContents);
StringChangeEx(FileContents, LF, CRLF, False);
SaveStringToFile(FilePath, FileContents, False);
end;
end;

View File

@@ -1,132 +0,0 @@
# Paths to relevant programs
CXX = %{cxx}
LINKER = %{linker}
AR = %{ar_command}
PYTHON_EXE = %{python_exe}
# Compiler Flags
ABI_FLAGS = %{cc_sysroot} %{cxx_abi_flags}
LANG_FLAGS = %{cc_lang_flags}
CXXFLAGS = %{cc_compile_flags}
WARN_FLAGS = %{cc_warning_flags}
SO_OBJ_FLAGS = %{shared_flags}
LDFLAGS = %{ldflags}
EXE_LINK_CMD = %{exe_link_cmd}
POST_LINK_CMD = %{post_link_cmd}
LIB_LINKS_TO = %{link_to}
EXE_LINKS_TO = %{link_to_botan} $(LIB_LINKS_TO)
BUILD_FLAGS = $(ABI_FLAGS) $(LANG_FLAGS) $(CXXFLAGS) $(WARN_FLAGS)
SCRIPTS_DIR = %{scripts_dir}
INSTALLED_LIB_DIR = %{prefix}/%{libdir}
# The primary target
all: libs cli docs tests
# Executable targets
CLI = %{cli_exe}
TEST = %{test_exe}
LIBRARIES = %{library_targets}
cli: $(CLI)
tests: $(TEST)
libs: $(LIBRARIES)
docs: %{doc_stamp_file}
# Misc targets
%{if make_supports_phony}
.PHONY = all cli libs tests docs clean distclean install
%{endif}
%{doc_stamp_file}: %{doc_dir}/manual/*.rst
$(PYTHON_EXE) $(SCRIPTS_DIR)/build_docs.py --build-dir="%{build_dir}"
clean:
$(PYTHON_EXE) $(SCRIPTS_DIR)/cleanup.py --build-dir="%{build_dir}"
distclean:
$(PYTHON_EXE) $(SCRIPTS_DIR)/cleanup.py --build-dir="%{build_dir}" --distclean
install: libs cli docs
$(PYTHON_EXE) $(SCRIPTS_DIR)/install.py --prefix="%{prefix}" --build-dir="%{build_dir}" --bindir=%{bindir} --libdir=%{libdir} --docdir=%{docdir} --includedir=%{includedir}
# Object Files
LIBOBJS = %{join lib_objs}
CLIOBJS = %{join cli_objs}
TESTOBJS = %{join test_objs}
# Executable targets
$(CLI): $(LIBRARIES) $(CLIOBJS)
$(EXE_LINK_CMD) $(ABI_FLAGS) $(LDFLAGS) $(CLIOBJS) $(EXE_LINKS_TO) %{output_to_exe}$@
$(POST_LINK_CMD)
$(TEST): $(LIBRARIES) $(TESTOBJS)
$(EXE_LINK_CMD) $(ABI_FLAGS) $(LDFLAGS) $(TESTOBJS) $(EXE_LINKS_TO) %{output_to_exe}$@
$(POST_LINK_CMD)
%{if build_fuzzers}
FUZZERS = %{fuzzer_bin}
fuzzers: libs $(FUZZERS)
fuzzer_corpus:
git clone --depth=1 https://github.com/randombit/crypto-corpus.git fuzzer_corpus
fuzzer_corpus_zip: fuzzer_corpus
./src/scripts/create_corpus_zip.py fuzzer_corpus %{fuzzobj_dir}
%{endif}
# Library targets
%{if build_static_lib}
%{out_dir}/%{static_lib_name}: $(LIBOBJS)
$(AR) %{ar_options} %{ar_output_to}$@ $(LIBOBJS)
%{endif}
%{if build_shared_lib}
%{out_dir}/%{shared_lib_name}: $(LIBOBJS)
%{lib_link_cmd} $(ABI_FLAGS) $(LDFLAGS) $(LIBOBJS) $(LIB_LINKS_TO) %{output_to_exe}$@
%{endif}
%{if symlink_shared_lib}
cd %{out_dir} && ln -fs %{shared_lib_name} %{soname_base}
cd %{out_dir} && ln -fs %{shared_lib_name} %{soname_patch}
%{endif}
# Build Commands
%{for lib_build_info}
%{obj}: %{src}
$(CXX) $(SO_OBJ_FLAGS) $(BUILD_FLAGS) %{isa_flags} %{include_paths} %{dash_c} %{src} %{dash_o}$@
%{endfor}
%{for cli_build_info}
%{obj}: %{src}
$(CXX) $(BUILD_FLAGS) %{isa_flags} %{include_paths} %{dash_c} %{src} %{dash_o}$@
%{endfor}
%{for test_build_info}
%{obj}: %{src}
$(CXX) $(BUILD_FLAGS) %{isa_flags} %{include_paths} %{dash_c} %{src} %{dash_o}$@
%{endfor}
%{for fuzzer_build_info}
%{obj}: %{src}
$(CXX) $(BUILD_FLAGS) %{isa_flags} %{include_paths} %{dash_c} %{src} %{dash_o}$@
%{exe}: %{obj} $(LIBRARIES)
$(EXE_LINK_CMD) $(ABI_FLAGS) %{obj} $(EXE_LINKS_TO) %{fuzzer_lib} %{output_to_exe}$@
%{endfor}

View File

@@ -1,316 +0,0 @@
# Regenerate with ./src/scripts/oids.py oids > src/lib/asn1/oid_maps.cpp
# AND ./src/scripts/oids.py dn_ub > src/lib/x509/x509_dn_ub.cpp
# (if you modified something under [dn]
# AND ./src/scripts/oids.py pads > src/lib/pk_pad/padding.cpp
# (if you modified something under [signature]
# Public key types
[pubkey]
1.2.840.113549.1.1.1 = RSA
2.5.8.1.1 = RSA
1.2.840.10040.4.1 = DSA
1.2.840.10046.2.1 = DH
1.3.6.1.4.1.3029.1.2.1 = ElGamal
1.3.6.1.4.1.25258.1.3 = McEliece
1.3.101.110 = Curve25519
1.3.6.1.4.1.25258.1.5 = XMSS
1.3.101.112 = Ed25519
# X9.62 ecPublicKey, valid for ECDSA and ECDH (RFC 3279 sec 2.3.5)
1.2.840.10045.2.1 = ECDSA
1.3.132.1.12 = ECDH
1.2.156.10197.1.301.1 = SM2_Sig
1.2.156.10197.1.301.1 = SM2
1.2.156.10197.1.301.2 = SM2_Kex
1.2.156.10197.1.301.3 = SM2_Enc
# ecgPublicKey (see https://www.teletrust.de/projekte/oid/)
1.3.36.3.3.2.5.2.1 = ECGDSA
# EC-KCDSA mechanism (Elliptic Curve KCDSA)
1.0.14888.3.0.5 = ECKCDSA
1.2.643.2.2.19 = GOST-34.10
# OpenPGP (RFC4880bis)
1.3.6.1.4.1.11591.15.1 = OpenPGP.Ed25519
1.3.6.1.4.1.3029.1.5.1 = OpenPGP.Curve25519
[cipher]
# Cipher modes
1.3.14.3.2.7 = DES/CBC
1.2.840.113549.3.7 = TripleDES/CBC
1.2.840.113533.7.66.10 = CAST-128/CBC
2.16.840.1.101.3.4.1.2 = AES-128/CBC
2.16.840.1.101.3.4.1.22 = AES-192/CBC
2.16.840.1.101.3.4.1.42 = AES-256/CBC
1.2.410.200004.1.4 = SEED/CBC
1.2.156.10197.1.104.2 = SM4/CBC
1.2.840.113549.1.9.16.3.18 = ChaCha20Poly1305
2.16.840.1.101.3.4.1.6 = AES-128/GCM
2.16.840.1.101.3.4.1.26 = AES-192/GCM
2.16.840.1.101.3.4.1.46 = AES-256/GCM
2.16.840.1.101.3.4.1.7 = AES-128/CCM
2.16.840.1.101.3.4.1.27 = AES-192/CCM
2.16.840.1.101.3.4.1.47 = AES-256/CCM
1.2.392.200011.61.1.1.1.2 = Camellia-128/CBC
1.2.392.200011.61.1.1.1.3 = Camellia-192/CBC
1.2.392.200011.61.1.1.1.4 = Camellia-256/CBC
0.3.4401.5.3.1.9.6 = Camellia-128/GCM
0.3.4401.5.3.1.9.26 = Camellia-192/GCM
0.3.4401.5.3.1.9.46 = Camellia-256/GCM
1.2.156.10197.1.104.8 = SM4/GCM
1.3.6.1.4.1.25258.3.1 = Serpent/CBC
1.3.6.1.4.1.25258.3.2 = Threefish-512/CBC
1.3.6.1.4.1.25258.3.3 = Twofish/CBC
1.3.6.1.4.1.25258.3.101 = Serpent/GCM
1.3.6.1.4.1.25258.3.102 = Twofish/GCM
1.3.6.1.4.1.25258.3.2.1 = AES-128/OCB
1.3.6.1.4.1.25258.3.2.2 = AES-192/OCB
1.3.6.1.4.1.25258.3.2.3 = AES-256/OCB
1.3.6.1.4.1.25258.3.2.4 = Serpent/OCB
1.3.6.1.4.1.25258.3.2.5 = Twofish/OCB
1.3.6.1.4.1.25258.3.2.6 = Camellia-128/OCB
1.3.6.1.4.1.25258.3.2.7 = Camellia-192/OCB
1.3.6.1.4.1.25258.3.2.8 = Camellia-256/OCB
1.2.156.10197.1.104.100 = SM4/OCB
1.3.6.1.4.1.25258.3.4.1 = AES-128/SIV
1.3.6.1.4.1.25258.3.4.2 = AES-192/SIV
1.3.6.1.4.1.25258.3.4.3 = AES-256/SIV
1.3.6.1.4.1.25258.3.4.4 = Serpent/SIV
1.3.6.1.4.1.25258.3.4.5 = Twofish/SIV
1.3.6.1.4.1.25258.3.4.6 = Camellia-128/SIV
1.3.6.1.4.1.25258.3.4.7 = Camellia-192/SIV
1.3.6.1.4.1.25258.3.4.8 = Camellia-256/SIV
1.3.6.1.4.1.25258.3.4.9 = SM4/SIV
[hash]
# Hash functions
1.2.840.113549.2.5 = MD5
1.3.6.1.4.1.11591.12.2 = Tiger(24,3)
1.2.156.10197.1.401 = SM3
1.3.14.3.2.26 = SHA-160
1.3.36.3.2.1 = RIPEMD-160
# From NIST:
2.16.840.1.101.3.4.2.1 = SHA-256
2.16.840.1.101.3.4.2.2 = SHA-384
2.16.840.1.101.3.4.2.3 = SHA-512
2.16.840.1.101.3.4.2.4 = SHA-224
2.16.840.1.101.3.4.2.6 = SHA-512-256
2.16.840.1.101.3.4.2.7 = SHA-3(224)
2.16.840.1.101.3.4.2.8 = SHA-3(256)
2.16.840.1.101.3.4.2.9 = SHA-3(384)
2.16.840.1.101.3.4.2.10 = SHA-3(512)
2.16.840.1.101.3.4.2.11 = SHAKE-128
2.16.840.1.101.3.4.2.12 = SHAKE-256
1.2.643.7.1.1.2.2 = Streebog-256
1.2.643.7.1.1.2.3 = Streebog-512
[mac]
# MACs
1.2.840.113549.2.7 = HMAC(SHA-160)
1.2.840.113549.2.8 = HMAC(SHA-224)
1.2.840.113549.2.9 = HMAC(SHA-256)
1.2.840.113549.2.10 = HMAC(SHA-384)
1.2.840.113549.2.11 = HMAC(SHA-512)
1.2.840.113549.2.13 = HMAC(SHA-512-256)
[keywrap]
# Keywrap algorithms
1.2.840.113549.1.9.16.3.6 = KeyWrap.TripleDES
1.2.840.113533.7.66.15 = KeyWrap.CAST-128
2.16.840.1.101.3.4.1.5 = KeyWrap.AES-128
2.16.840.1.101.3.4.1.25 = KeyWrap.AES-192
2.16.840.1.101.3.4.1.45 = KeyWrap.AES-256
[compression]
1.2.840.113549.1.9.16.3.8 = Compression.Zlib
# Signature algos
[signature]
1.2.840.113549.1.1.4 = RSA/EMSA3(MD5)
1.2.840.113549.1.1.5 = RSA/EMSA3(SHA-160)
1.2.840.113549.1.1.8 = MGF1
1.2.840.113549.1.1.10 = RSA/EMSA4
1.2.840.113549.1.1.11 = RSA/EMSA3(SHA-256)
1.2.840.113549.1.1.12 = RSA/EMSA3(SHA-384)
1.2.840.113549.1.1.13 = RSA/EMSA3(SHA-512)
1.2.840.113549.1.1.14 = RSA/EMSA3(SHA-224)
1.2.840.113549.1.1.16 = RSA/EMSA3(SHA-512-256)
1.3.36.3.3.1.2 = RSA/EMSA3(RIPEMD-160)
1.2.156.10197.1.501 = SM2_Sig/SM3
1.2.156.10197.1.504 = RSA/EMSA3(SM3)
1.2.840.10040.4.3 = DSA/EMSA1(SHA-160)
2.16.840.1.101.3.4.3.1 = DSA/EMSA1(SHA-224)
2.16.840.1.101.3.4.3.2 = DSA/EMSA1(SHA-256)
2.16.840.1.101.3.4.3.3 = DSA/EMSA1(SHA-384)
2.16.840.1.101.3.4.3.4 = DSA/EMSA1(SHA-512)
2.16.840.1.101.3.4.3.5 = DSA/EMSA1(SHA-3(224))
2.16.840.1.101.3.4.3.6 = DSA/EMSA1(SHA-3(256))
2.16.840.1.101.3.4.3.7 = DSA/EMSA1(SHA-3(384))
2.16.840.1.101.3.4.3.8 = DSA/EMSA1(SHA-3(512))
2.16.840.1.101.3.4.3.9 = ECDSA/EMSA1(SHA-3(224))
2.16.840.1.101.3.4.3.10 = ECDSA/EMSA1(SHA-3(256))
2.16.840.1.101.3.4.3.11 = ECDSA/EMSA1(SHA-3(384))
2.16.840.1.101.3.4.3.12 = ECDSA/EMSA1(SHA-3(512))
2.16.840.1.101.3.4.3.13 = RSA/EMSA3(SHA-3(224))
2.16.840.1.101.3.4.3.14 = RSA/EMSA3(SHA-3(256))
2.16.840.1.101.3.4.3.15 = RSA/EMSA3(SHA-3(384))
2.16.840.1.101.3.4.3.16 = RSA/EMSA3(SHA-3(512))
1.2.840.10045.4.1 = ECDSA/EMSA1(SHA-160)
1.2.840.10045.4.3.1 = ECDSA/EMSA1(SHA-224)
1.2.840.10045.4.3.2 = ECDSA/EMSA1(SHA-256)
1.2.840.10045.4.3.3 = ECDSA/EMSA1(SHA-384)
1.2.840.10045.4.3.4 = ECDSA/EMSA1(SHA-512)
1.3.36.3.3.2.5.4.1 = ECGDSA/EMSA1(RIPEMD-160)
1.3.36.3.3.2.5.4.2 = ECGDSA/EMSA1(SHA-160)
1.3.36.3.3.2.5.4.3 = ECGDSA/EMSA1(SHA-224)
1.3.36.3.3.2.5.4.4 = ECGDSA/EMSA1(SHA-256)
1.3.36.3.3.2.5.4.5 = ECGDSA/EMSA1(SHA-384)
1.3.36.3.3.2.5.4.6 = ECGDSA/EMSA1(SHA-512)
1.2.410.200004.1.100.4.3 = ECKCDSA/EMSA1(SHA-1)
1.2.410.200004.1.100.4.4 = ECKCDSA/EMSA1(SHA-224)
1.2.410.200004.1.100.4.5 = ECKCDSA/EMSA1(SHA-256)
1.2.643.2.2.3 = GOST-34.10/EMSA1(GOST-R-34.11-94)
1.3.6.1.4.1.25258.1.6.1 = GOST-34.10/EMSA1(SHA-256)
# Encryption algos
[encryption]
1.2.840.113549.1.1.7 = RSA/OAEP
# DN with upper bounds from RFC 5280, Appendix A
[dn]
2.5.4.3 = X520.CommonName = 64
2.5.4.4 = X520.Surname = 40
2.5.4.5 = X520.SerialNumber = 64
2.5.4.6 = X520.Country = 3
2.5.4.7 = X520.Locality = 128
2.5.4.8 = X520.State = 128
2.5.4.10 = X520.Organization = 64
2.5.4.11 = X520.OrganizationalUnit = 64
2.5.4.12 = X520.Title = 64
# the following three types are naming attributes of type "X520name" and inherit its bound
2.5.4.42 = X520.GivenName = 32768
2.5.4.43 = X520.Initials = 32768
2.5.4.44 = X520.GenerationalQualifier = 32768
2.5.4.46 = X520.DNQualifier = 64
2.5.4.65 = X520.Pseudonym = 128
[pbe]
1.2.840.113549.1.5.12 = PKCS5.PBKDF2
1.2.840.113549.1.5.13 = PBES2
1.2.840.113549.1.5.13 = PBE-PKCS5v20
1.3.6.1.4.1.11591.4.11 = Scrypt
[pkcs9]
1.2.840.113549.1.9.1 = PKCS9.EmailAddress
1.2.840.113549.1.9.2 = PKCS9.UnstructuredName
1.2.840.113549.1.9.3 = PKCS9.ContentType
1.2.840.113549.1.9.4 = PKCS9.MessageDigest
1.2.840.113549.1.9.7 = PKCS9.ChallengePassword
1.2.840.113549.1.9.14 = PKCS9.ExtensionRequest
[pkix]
2.5.29.14 = X509v3.SubjectKeyIdentifier
2.5.29.15 = X509v3.KeyUsage
2.5.29.17 = X509v3.SubjectAlternativeName
2.5.29.18 = X509v3.IssuerAlternativeName
2.5.29.19 = X509v3.BasicConstraints
2.5.29.20 = X509v3.CRLNumber
2.5.29.21 = X509v3.ReasonCode
2.5.29.23 = X509v3.HoldInstructionCode
2.5.29.24 = X509v3.InvalidityDate
2.5.29.28 = X509v3.CRLIssuingDistributionPoint
2.5.29.30 = X509v3.NameConstraints
2.5.29.31 = X509v3.CRLDistributionPoints
2.5.29.32 = X509v3.CertificatePolicies
2.5.29.35 = X509v3.AuthorityKeyIdentifier
2.5.29.36 = X509v3.PolicyConstraints
2.5.29.37 = X509v3.ExtendedKeyUsage
1.3.6.1.5.5.7.1.1 = PKIX.AuthorityInformationAccess
2.5.29.32.0 = X509v3.AnyPolicy
1.3.6.1.5.5.7.3.1 = PKIX.ServerAuth
1.3.6.1.5.5.7.3.2 = PKIX.ClientAuth
1.3.6.1.5.5.7.3.3 = PKIX.CodeSigning
1.3.6.1.5.5.7.3.4 = PKIX.EmailProtection
1.3.6.1.5.5.7.3.5 = PKIX.IPsecEndSystem
1.3.6.1.5.5.7.3.6 = PKIX.IPsecTunnel
1.3.6.1.5.5.7.3.7 = PKIX.IPsecUser
1.3.6.1.5.5.7.3.8 = PKIX.TimeStamping
1.3.6.1.5.5.7.3.9 = PKIX.OCSPSigning
1.3.6.1.5.5.7.8.5 = PKIX.XMPPAddr
1.3.6.1.5.5.7.48.1 = PKIX.OCSP
1.3.6.1.5.5.7.48.1.1 = PKIX.OCSP.BasicResponse
1.3.6.1.5.5.7.48.2 = PKIX.CertificateAuthorityIssuers
1.3.6.1.4.1.311.20.2.2 = Microsoft SmartcardLogon
1.3.6.1.4.1.311.20.2.3 = Microsoft UPN
2.16.840.1.113730.1.13 = Certificate Comment
# ECC param sets
[ecc_param]
1.3.132.0.8 = secp160r1
1.3.132.0.9 = secp160k1
1.3.132.0.10 = secp256k1
1.3.132.0.30 = secp160r2
1.3.132.0.31 = secp192k1
1.3.132.0.32 = secp224k1
1.3.132.0.33 = secp224r1
1.3.132.0.34 = secp384r1
1.3.132.0.35 = secp521r1
1.3.6.1.4.1.8301.3.1.2.9.0.38 = secp521r1
1.2.840.10045.3.1.1 = secp192r1
1.2.840.10045.3.1.2 = x962_p192v2
1.2.840.10045.3.1.3 = x962_p192v3
1.2.840.10045.3.1.4 = x962_p239v1
1.2.840.10045.3.1.5 = x962_p239v2
1.2.840.10045.3.1.6 = x962_p239v3
1.2.840.10045.3.1.7 = secp256r1
1.2.156.10197.1.301 = sm2p256v1
1.3.36.3.3.2.8.1.1.1 = brainpool160r1
1.3.36.3.3.2.8.1.1.3 = brainpool192r1
1.3.36.3.3.2.8.1.1.5 = brainpool224r1
1.3.36.3.3.2.8.1.1.7 = brainpool256r1
1.3.36.3.3.2.8.1.1.9 = brainpool320r1
1.3.36.3.3.2.8.1.1.11 = brainpool384r1
1.3.36.3.3.2.8.1.1.13 = brainpool512r1
1.2.643.2.2.35.1 = gost_256A
1.2.643.2.2.36.0 = gost_256A
1.2.250.1.223.101.256.1 = frp256v1

View File

@@ -1,16 +0,0 @@
soname_suffix "so"
use_stack_protector no
<target_features>
posix1
posix_mlock
clock_gettime
dev_random
proc_fs
sockets
threads
filesystem
</target_features>

View File

@@ -1,18 +0,0 @@
soname_suffix "so"
<target_features>
posix1
posix_mlock
clock_gettime
dev_random
# getauxval is available in Android NDK for min API 18 and in Crystax NDK
# for all min API levels. Use --without-os-feature=getauxval to disable
getauxval
sockets
threads
filesystem
</target_features>

View File

@@ -1,18 +0,0 @@
program_suffix .exe
# Cygwin supports shared libs fine, but there are problems with making a Botan
# shared library when libraries it depends on are static-only (such as libz).
# So until I can figure out a work-around, it's disabled.
install_root c:\Botan
doc_dir docs
<target_features>
posix1
dev_random
sockets
threads
filesystem
</target_features>

View File

@@ -1,28 +0,0 @@
soname_pattern_base "lib{libname}.dylib"
soname_pattern_abi "lib{libname}.{abi_rev}.dylib"
soname_pattern_patch "lib{libname}.{abi_rev}.{version_minor}.{version_patch}.dylib"
# In order that these executables work from the build directory,
# we need to change the install names
so_post_link_command "install_name_tool -change '$(INSTALLED_LIB_DIR)/{soname_abi}' '@executable_path/{soname_abi}' $@"
doc_dir doc
<target_features>
posix1
posix_mlock
arc4random
dev_random
commoncrypto
sockets
threads
filesystem
</target_features>
<aliases>
macos
macosx
osx
</aliases>

View File

@@ -1,15 +0,0 @@
soname_suffix "so"
<target_features>
posix1
posix_mlock
clock_gettime
proc_fs
dev_random
arc4random
sockets
threads
filesystem
</target_features>

View File

@@ -1,14 +0,0 @@
soname_suffix "so"
<target_features>
posix1
posix_mlock
clock_gettime
dev_random
arc4random
sockets
threads
filesystem
</target_features>

View File

@@ -1,23 +0,0 @@
soname_suffix "so"
install_root /boot
header_dir develop/headers
lib_dir system/lib
doc_dir system/documentation
use_stack_protector no
<target_features>
posix1
clock_gettime
dev_random
sockets
threads
filesystem
</target_features>
<aliases>
beos
</aliases>

View File

@@ -1,18 +0,0 @@
# It is "sl" on HP-PA, but HP-UX on PA is EOL
soname_suffix "so"
<target_features>
posix1
posix_mlock
clock_gettime
dev_random
sockets
threads
filesystem
</target_features>
<aliases>
hp-ux
</aliases>

View File

@@ -1,17 +0,0 @@
soname_suffix "so"
<target_features>
posix1
posix_mlock
dev_random
clock_gettime
sockets
threads
filesystem
</target_features>
<aliases>
gnu
</aliases>

View File

@@ -1,4 +0,0 @@
<target_features>
posix1
dev_random
</target_features>

View File

@@ -1,20 +0,0 @@
soname_pattern_base "lib{libname}.{version_minor}.dylib"
soname_pattern_abi "lib{libname}.{version_minor}.{abi_rev}.dylib"
soname_pattern_patch "lib{libname}.{version_minor}.{abi_rev}.{version_patch}.dylib"
doc_dir doc
<target_features>
posix1
posix_mlock
arc4random
commoncrypto
sockets
threads
filesystem
</target_features>
<aliases>
</aliases>

View File

@@ -1,23 +0,0 @@
soname_suffix "so"
<target_features>
posix1
posix_mlock
dev_random
proc_fs
clock_gettime
getauxval
# not enabled by default as only available in newer kernel/glibc
#getrandom
sockets
threads
filesystem
</target_features>
<aliases>
linux-gnu
</aliases>

View File

@@ -1,9 +0,0 @@
obj_suffix bc
ar_command llvm-link
ar_options -o
<target_features>
filesystem
</target_features>

View File

@@ -1,24 +0,0 @@
program_suffix .exe
obj_suffix o
static_suffix a
install_root /mingw
header_dir include
lib_dir lib
doc_dir share/doc
<aliases>
msys
mingw32.*
</aliases>
<target_features>
win32
rtlgenrandom
virtual_lock
threads
filesystem
</target_features>

View File

@@ -1,5 +0,0 @@
<target_features>
threads
</target_features>

View File

@@ -1,14 +0,0 @@
soname_suffix "so"
<target_features>
posix1
posix_mlock
clock_gettime
dev_random
arc4random
sockets
threads
filesystem
</target_features>

View File

@@ -1,18 +0,0 @@
soname_pattern_base "lib{libname}.so"
soname_pattern_abi "lib{libname}.so.{abi_rev}.{version_minor}"
soname_pattern_patch "lib{libname}.so.{abi_rev}.{version_minor}"
<target_features>
posix1
posix_mlock
clock_gettime
dev_random
arc4random
getentropy
explicit_bzero
sockets
threads
filesystem
</target_features>

View File

@@ -1,12 +0,0 @@
soname_suffix "so"
<target_features>
posix1
posix_mlock
clock_gettime
dev_random
sockets
threads
filesystem
</target_features>

View File

@@ -1,18 +0,0 @@
soname_suffix "so"
<target_features>
posix1
posix_mlock
clock_gettime
dev_random
proc_fs
threads
sockets
filesystem
</target_features>
<aliases>
sunos
</aliases>

View File

@@ -1,23 +0,0 @@
# ?
program_suffix .exe
obj_suffix obj
static_suffix lib
install_root c:\\Botan
doc_dir docs
<target_features>
win32
winsock2
crypto_ng
rtlsecurezeromemory
threads
filesystem
</target_features>
<aliases>
winphone
</aliases>

View File

@@ -1,35 +0,0 @@
cli_exe_name botan-cli
program_suffix .exe
obj_suffix obj
static_suffix lib
lib_prefix ''
# For historical reasons? the library does not have the major number on Windows
# This should probably be fixed in a future major release.
library_name 'botan{suffix}'
soname_pattern_base "{libname}.dll"
install_root c:\\Botan
doc_dir docs
<target_features>
win32
winsock2
rtlgenrandom
rtlsecurezeromemory
virtual_lock
stl_filesystem_msvc
threads
filesystem
</target_features>
<aliases>
win32
MSWin32
</aliases>

View File

@@ -1,10 +0,0 @@
release_major = 2
release_minor = 8
release_patch = 0
release_so_abi_rev = 8
# These are set by the distribution script
release_vc_rev = 'git:a792728e8941b62761052f5e0d288ba13a016c77'
release_datestamp = 20181001
release_type = 'release'

View File

@@ -1,117 +0,0 @@
/*
* Algorithm Identifier
* (C) 1999-2007 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#include <botan/alg_id.h>
#include <botan/der_enc.h>
#include <botan/ber_dec.h>
#include <botan/oids.h>
namespace Botan {
/*
* Create an AlgorithmIdentifier
*/
AlgorithmIdentifier::AlgorithmIdentifier(const OID& alg_id,
const std::vector<uint8_t>& param) :
oid(alg_id),
parameters(param)
{}
/*
* Create an AlgorithmIdentifier
*/
AlgorithmIdentifier::AlgorithmIdentifier(const std::string& alg_id,
const std::vector<uint8_t>& param) :
oid(OIDS::lookup(alg_id)),
parameters(param)
{}
/*
* Create an AlgorithmIdentifier
*/
AlgorithmIdentifier::AlgorithmIdentifier(const OID& alg_id,
Encoding_Option option) :
oid(alg_id),
parameters()
{
const uint8_t DER_NULL[] = { 0x05, 0x00 };
if(option == USE_NULL_PARAM)
parameters.assign(DER_NULL, DER_NULL + 2);
}
/*
* Create an AlgorithmIdentifier
*/
AlgorithmIdentifier::AlgorithmIdentifier(const std::string& alg_id,
Encoding_Option option) :
oid(OIDS::lookup(alg_id)),
parameters()
{
const uint8_t DER_NULL[] = { 0x05, 0x00 };
if(option == USE_NULL_PARAM)
parameters.assign(DER_NULL, DER_NULL + 2);
}
/*
* Compare two AlgorithmIdentifiers
*/
namespace {
bool param_null_or_empty(const std::vector<uint8_t>& p)
{
if(p.size() == 2 && (p[0] == 0x05) && (p[1] == 0x00))
return true;
return p.empty();
}
}
bool operator==(const AlgorithmIdentifier& a1, const AlgorithmIdentifier& a2)
{
if(a1.get_oid() != a2.get_oid())
return false;
if(param_null_or_empty(a1.get_parameters()) &&
param_null_or_empty(a2.get_parameters()))
return true;
return (a1.get_parameters() == a2.get_parameters());
}
/*
* Compare two AlgorithmIdentifiers
*/
bool operator!=(const AlgorithmIdentifier& a1, const AlgorithmIdentifier& a2)
{
return !(a1 == a2);
}
/*
* DER encode an AlgorithmIdentifier
*/
void AlgorithmIdentifier::encode_into(DER_Encoder& codec) const
{
codec.start_cons(SEQUENCE)
.encode(get_oid())
.raw_bytes(get_parameters())
.end_cons();
}
/*
* Decode a BER encoded AlgorithmIdentifier
*/
void AlgorithmIdentifier::decode_from(BER_Decoder& codec)
{
codec.start_cons(SEQUENCE)
.decode(oid)
.raw_bytes(parameters)
.end_cons();
}
}

View File

@@ -1,59 +0,0 @@
/*
* Algorithm Identifier
* (C) 1999-2007 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#ifndef BOTAN_ALGORITHM_IDENTIFIER_H_
#define BOTAN_ALGORITHM_IDENTIFIER_H_
#include <botan/asn1_obj.h>
#include <botan/asn1_oid.h>
#include <string>
#include <vector>
namespace Botan {
/**
* Algorithm Identifier
*/
class BOTAN_PUBLIC_API(2,0) AlgorithmIdentifier final : public ASN1_Object
{
public:
enum Encoding_Option { USE_NULL_PARAM, USE_EMPTY_PARAM };
void encode_into(class DER_Encoder&) const override;
void decode_from(class BER_Decoder&) override;
AlgorithmIdentifier() = default;
AlgorithmIdentifier(const OID& oid, Encoding_Option enc);
AlgorithmIdentifier(const std::string& oid_name, Encoding_Option enc);
AlgorithmIdentifier(const OID& oid, const std::vector<uint8_t>& params);
AlgorithmIdentifier(const std::string& oid_name, const std::vector<uint8_t>& params);
const OID& get_oid() const { return oid; }
const std::vector<uint8_t>& get_parameters() const { return parameters; }
BOTAN_DEPRECATED_PUBLIC_MEMBER_VARIABLES:
/*
* These values are public for historical reasons, but in a future release
* they will be made private. Do not access them.
*/
OID oid;
std::vector<uint8_t> parameters;
};
/*
* Comparison Operations
*/
bool BOTAN_PUBLIC_API(2,0) operator==(const AlgorithmIdentifier&,
const AlgorithmIdentifier&);
bool BOTAN_PUBLIC_API(2,0) operator!=(const AlgorithmIdentifier&,
const AlgorithmIdentifier&);
}
#endif

View File

@@ -1,58 +0,0 @@
/*
* Attribute
* (C) 1999-2007 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#include <botan/asn1_attribute.h>
#include <botan/der_enc.h>
#include <botan/ber_dec.h>
#include <botan/oids.h>
namespace Botan {
/*
* Create an Attribute
*/
Attribute::Attribute(const OID& attr_oid, const std::vector<uint8_t>& attr_value) :
oid(attr_oid),
parameters(attr_value)
{}
/*
* Create an Attribute
*/
Attribute::Attribute(const std::string& attr_oid,
const std::vector<uint8_t>& attr_value) :
oid(OIDS::lookup(attr_oid)),
parameters(attr_value)
{}
/*
* DER encode a Attribute
*/
void Attribute::encode_into(DER_Encoder& codec) const
{
codec.start_cons(SEQUENCE)
.encode(oid)
.start_cons(SET)
.raw_bytes(parameters)
.end_cons()
.end_cons();
}
/*
* Decode a BER encoded Attribute
*/
void Attribute::decode_from(BER_Decoder& codec)
{
codec.start_cons(SEQUENCE)
.decode(oid)
.start_cons(SET)
.raw_bytes(parameters)
.end_cons()
.end_cons();
}
}

View File

@@ -1,45 +0,0 @@
/*
* ASN.1 Attribute
* (C) 1999-2007,2012 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#ifndef BOTAN_ASN1_ATTRIBUTE_H_
#define BOTAN_ASN1_ATTRIBUTE_H_
#include <botan/asn1_obj.h>
#include <botan/asn1_oid.h>
#include <vector>
namespace Botan {
/**
* Attribute
*/
class BOTAN_PUBLIC_API(2,0) Attribute final : public ASN1_Object
{
public:
void encode_into(class DER_Encoder& to) const override;
void decode_from(class BER_Decoder& from) override;
Attribute() = default;
Attribute(const OID&, const std::vector<uint8_t>&);
Attribute(const std::string&, const std::vector<uint8_t>&);
const OID& get_oid() const { return oid; }
const std::vector<uint8_t>& get_parameters() const { return parameters; }
BOTAN_DEPRECATED_PUBLIC_MEMBER_VARIABLES:
/*
* These values are public for historical reasons, but in a future release
* they will be made private. Do not access them.
*/
OID oid;
std::vector<uint8_t> parameters;
};
}
#endif

View File

@@ -1,235 +0,0 @@
/*
* ASN.1 Internals
* (C) 1999-2007,2018 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#include <botan/asn1_obj.h>
#include <botan/der_enc.h>
#include <botan/data_src.h>
#include <botan/internal/stl_util.h>
#include <sstream>
namespace Botan {
std::vector<uint8_t> ASN1_Object::BER_encode() const
{
std::vector<uint8_t> output;
DER_Encoder der(output);
this->encode_into(der);
return output;
}
/*
* Check a type invariant on BER data
*/
void BER_Object::assert_is_a(ASN1_Tag type_tag_, ASN1_Tag class_tag_,
const std::string& descr) const
{
if(this->is_a(type_tag_, class_tag_) == false)
{
std::stringstream msg;
msg << "Tag mismatch when decoding " << descr << " got ";
if(class_tag == NO_OBJECT && type_tag == NO_OBJECT)
{
msg << "EOF";
}
else
{
if(class_tag == UNIVERSAL || class_tag == CONSTRUCTED)
{
msg << asn1_tag_to_string(type_tag);
}
else
{
msg << std::to_string(type_tag);
}
msg << "/" << asn1_class_to_string(class_tag);
}
msg << " expected ";
if(class_tag_ == UNIVERSAL || class_tag_ == CONSTRUCTED)
{
msg << asn1_tag_to_string(type_tag_);
}
else
{
msg << std::to_string(type_tag_);
}
msg << "/" << asn1_class_to_string(class_tag_);
throw BER_Decoding_Error(msg.str());
}
}
bool BER_Object::is_a(ASN1_Tag type_tag_, ASN1_Tag class_tag_) const
{
return (type_tag == type_tag_ && class_tag == class_tag_);
}
bool BER_Object::is_a(int type_tag_, ASN1_Tag class_tag_) const
{
return is_a(ASN1_Tag(type_tag_), class_tag_);
}
void BER_Object::set_tagging(ASN1_Tag t, ASN1_Tag c)
{
type_tag = t;
class_tag = c;
}
std::string asn1_class_to_string(ASN1_Tag type)
{
switch(type)
{
case UNIVERSAL:
return "UNIVERSAL";
case CONSTRUCTED:
return "CONSTRUCTED";
case CONTEXT_SPECIFIC:
return "CONTEXT_SPECIFIC";
case APPLICATION:
return "APPLICATION";
case CONSTRUCTED | CONTEXT_SPECIFIC:
return "PRIVATE";
case Botan::NO_OBJECT:
return "NO_OBJECT";
default:
return "CLASS(" + std::to_string(static_cast<size_t>(type)) + ")";
}
}
std::string asn1_tag_to_string(ASN1_Tag type)
{
switch(type)
{
case Botan::SEQUENCE:
return "SEQUENCE";
case Botan::SET:
return "SET";
case Botan::PRINTABLE_STRING:
return "PRINTABLE STRING";
case Botan::NUMERIC_STRING:
return "NUMERIC STRING";
case Botan::IA5_STRING:
return "IA5 STRING";
case Botan::T61_STRING:
return "T61 STRING";
case Botan::UTF8_STRING:
return "UTF8 STRING";
case Botan::VISIBLE_STRING:
return "VISIBLE STRING";
case Botan::BMP_STRING:
return "BMP STRING";
case Botan::UTC_TIME:
return "UTC TIME";
case Botan::GENERALIZED_TIME:
return "GENERALIZED TIME";
case Botan::OCTET_STRING:
return "OCTET STRING";
case Botan::BIT_STRING:
return "BIT STRING";
case Botan::ENUMERATED:
return "ENUMERATED";
case Botan::INTEGER:
return "INTEGER";
case Botan::NULL_TAG:
return "NULL";
case Botan::OBJECT_ID:
return "OBJECT";
case Botan::BOOLEAN:
return "BOOLEAN";
case Botan::NO_OBJECT:
return "NO_OBJECT";
default:
return "TAG(" + std::to_string(static_cast<size_t>(type)) + ")";
}
}
/*
* BER Decoding Exceptions
*/
BER_Decoding_Error::BER_Decoding_Error(const std::string& str) :
Decoding_Error("BER: " + str) {}
BER_Bad_Tag::BER_Bad_Tag(const std::string& str, ASN1_Tag tag) :
BER_Decoding_Error(str + ": " + std::to_string(tag)) {}
BER_Bad_Tag::BER_Bad_Tag(const std::string& str,
ASN1_Tag tag1, ASN1_Tag tag2) :
BER_Decoding_Error(str + ": " + std::to_string(tag1) + "/" + std::to_string(tag2)) {}
namespace ASN1 {
/*
* Put some arbitrary bytes into a SEQUENCE
*/
std::vector<uint8_t> put_in_sequence(const std::vector<uint8_t>& contents)
{
return ASN1::put_in_sequence(contents.data(), contents.size());
}
std::vector<uint8_t> put_in_sequence(const uint8_t bits[], size_t len)
{
std::vector<uint8_t> output;
DER_Encoder(output)
.start_cons(SEQUENCE)
.raw_bytes(bits, len)
.end_cons();
return output;
}
/*
* Convert a BER object into a string object
*/
std::string to_string(const BER_Object& obj)
{
return std::string(cast_uint8_ptr_to_char(obj.bits()),
obj.length());
}
/*
* Do heuristic tests for BER data
*/
bool maybe_BER(DataSource& source)
{
uint8_t first_u8;
if(!source.peek_byte(first_u8))
{
BOTAN_ASSERT_EQUAL(source.read_byte(first_u8), 0, "Expected EOF");
throw Stream_IO_Error("ASN1::maybe_BER: Source was empty");
}
if(first_u8 == (SEQUENCE | CONSTRUCTED))
return true;
return false;
}
}
}

View File

@@ -1,191 +0,0 @@
/*
* ASN.1 Internals
* (C) 1999-2007,2018 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#ifndef BOTAN_ASN1_H_
#define BOTAN_ASN1_H_
#include <botan/secmem.h>
#include <botan/exceptn.h>
namespace Botan {
class BER_Decoder;
class DER_Encoder;
/**
* ASN.1 Type and Class Tags
*/
enum ASN1_Tag : uint32_t {
UNIVERSAL = 0x00,
APPLICATION = 0x40,
CONTEXT_SPECIFIC = 0x80,
CONSTRUCTED = 0x20,
PRIVATE = CONSTRUCTED | CONTEXT_SPECIFIC,
EOC = 0x00,
BOOLEAN = 0x01,
INTEGER = 0x02,
BIT_STRING = 0x03,
OCTET_STRING = 0x04,
NULL_TAG = 0x05,
OBJECT_ID = 0x06,
ENUMERATED = 0x0A,
SEQUENCE = 0x10,
SET = 0x11,
UTF8_STRING = 0x0C,
NUMERIC_STRING = 0x12,
PRINTABLE_STRING = 0x13,
T61_STRING = 0x14,
IA5_STRING = 0x16,
VISIBLE_STRING = 0x1A,
UNIVERSAL_STRING = 0x1C,
BMP_STRING = 0x1E,
UTC_TIME = 0x17,
GENERALIZED_TIME = 0x18,
UTC_OR_GENERALIZED_TIME = 0x19,
NO_OBJECT = 0xFF00,
DIRECTORY_STRING = 0xFF01
};
std::string BOTAN_UNSTABLE_API asn1_tag_to_string(ASN1_Tag type);
std::string BOTAN_UNSTABLE_API asn1_class_to_string(ASN1_Tag type);
/**
* Basic ASN.1 Object Interface
*/
class BOTAN_PUBLIC_API(2,0) ASN1_Object
{
public:
/**
* Encode whatever this object is into to
* @param to the DER_Encoder that will be written to
*/
virtual void encode_into(DER_Encoder& to) const = 0;
/**
* Decode whatever this object is from from
* @param from the BER_Decoder that will be read from
*/
virtual void decode_from(BER_Decoder& from) = 0;
/**
* Return the encoding of this object. This is a convenience
* method when just one object needs to be serialized. Use
* DER_Encoder for complicated encodings.
*/
std::vector<uint8_t> BER_encode() const;
ASN1_Object() = default;
ASN1_Object(const ASN1_Object&) = default;
ASN1_Object & operator=(const ASN1_Object&) = default;
virtual ~ASN1_Object() = default;
};
/**
* BER Encoded Object
*/
class BOTAN_PUBLIC_API(2,0) BER_Object final
{
public:
BER_Object() : type_tag(NO_OBJECT), class_tag(UNIVERSAL) {}
BER_Object(const BER_Object& other) = default;
BER_Object& operator=(const BER_Object& other) = default;
#if !defined(BOTAN_BUILD_COMPILER_IS_MSVC_2013)
BER_Object(BER_Object&& other) = default;
BER_Object& operator=(BER_Object&& other) = default;
#endif
bool is_set() const { return type_tag != NO_OBJECT; }
ASN1_Tag tagging() const { return ASN1_Tag(type() | get_class()); }
ASN1_Tag type() const { return type_tag; }
ASN1_Tag get_class() const { return class_tag; }
const uint8_t* bits() const { return value.data(); }
size_t length() const { return value.size(); }
void assert_is_a(ASN1_Tag type_tag, ASN1_Tag class_tag,
const std::string& descr = "object") const;
bool is_a(ASN1_Tag type_tag, ASN1_Tag class_tag) const;
bool is_a(int type_tag, ASN1_Tag class_tag) const;
BOTAN_DEPRECATED_PUBLIC_MEMBER_VARIABLES:
/*
* The following member variables are public for historical reasons, but
* will be made private in a future major release. Use the accessor
* functions above.
*/
ASN1_Tag type_tag, class_tag;
secure_vector<uint8_t> value;
private:
friend class BER_Decoder;
void set_tagging(ASN1_Tag type_tag, ASN1_Tag class_tag);
uint8_t* mutable_bits(size_t length)
{
value.resize(length);
return value.data();
}
};
/*
* ASN.1 Utility Functions
*/
class DataSource;
namespace ASN1 {
std::vector<uint8_t> put_in_sequence(const std::vector<uint8_t>& val);
std::vector<uint8_t> put_in_sequence(const uint8_t bits[], size_t len);
std::string to_string(const BER_Object& obj);
/**
* Heuristics tests; is this object possibly BER?
* @param src a data source that will be peeked at but not modified
*/
bool maybe_BER(DataSource& src);
}
/**
* General BER Decoding Error Exception
*/
class BOTAN_PUBLIC_API(2,0) BER_Decoding_Error : public Decoding_Error
{
public:
explicit BER_Decoding_Error(const std::string&);
};
/**
* Exception For Incorrect BER Taggings
*/
class BOTAN_PUBLIC_API(2,0) BER_Bad_Tag final : public BER_Decoding_Error
{
public:
BER_Bad_Tag(const std::string& msg, ASN1_Tag tag);
BER_Bad_Tag(const std::string& msg, ASN1_Tag tag1, ASN1_Tag tag2);
};
}
#endif

View File

@@ -1,199 +0,0 @@
/*
* ASN.1 OID
* (C) 1999-2007 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#include <botan/asn1_oid.h>
#include <botan/der_enc.h>
#include <botan/ber_dec.h>
#include <botan/internal/bit_ops.h>
#include <botan/parsing.h>
namespace Botan {
/*
* ASN.1 OID Constructor
*/
OID::OID(const std::string& oid_str)
{
if(!oid_str.empty())
{
try
{
m_id = parse_asn1_oid(oid_str);
}
catch(...)
{
throw Invalid_OID(oid_str);
}
if(m_id.size() < 2 || m_id[0] > 2)
throw Invalid_OID(oid_str);
if((m_id[0] == 0 || m_id[0] == 1) && m_id[1] > 39)
throw Invalid_OID(oid_str);
}
}
/*
* Clear the current OID
*/
void OID::clear()
{
m_id.clear();
}
/*
* Return this OID as a string
*/
std::string OID::to_string() const
{
std::string oid_str;
for(size_t i = 0; i != m_id.size(); ++i)
{
oid_str += std::to_string(m_id[i]);
if(i != m_id.size() - 1)
oid_str += ".";
}
return oid_str;
}
/*
* OID equality comparison
*/
bool OID::operator==(const OID& oid) const
{
if(m_id.size() != oid.m_id.size())
return false;
for(size_t i = 0; i != m_id.size(); ++i)
if(m_id[i] != oid.m_id[i])
return false;
return true;
}
/*
* Append another component to the OID
*/
OID& OID::operator+=(uint32_t component)
{
m_id.push_back(component);
return (*this);
}
/*
* Append another component to the OID
*/
OID operator+(const OID& oid, uint32_t component)
{
OID new_oid(oid);
new_oid += component;
return new_oid;
}
/*
* OID inequality comparison
*/
bool operator!=(const OID& a, const OID& b)
{
return !(a == b);
}
/*
* Compare two OIDs
*/
bool operator<(const OID& a, const OID& b)
{
const std::vector<uint32_t>& oid1 = a.get_id();
const std::vector<uint32_t>& oid2 = b.get_id();
if(oid1.size() < oid2.size())
return true;
if(oid1.size() > oid2.size())
return false;
for(size_t i = 0; i != oid1.size(); ++i)
{
if(oid1[i] < oid2[i])
return true;
if(oid1[i] > oid2[i])
return false;
}
return false;
}
/*
* DER encode an OBJECT IDENTIFIER
*/
void OID::encode_into(DER_Encoder& der) const
{
if(m_id.size() < 2)
throw Invalid_Argument("OID::encode_into: OID is invalid");
std::vector<uint8_t> encoding;
if(m_id[0] > 2 || m_id[1] >= 40)
throw Encoding_Error("Invalid OID prefix, cannot encode");
encoding.push_back(static_cast<uint8_t>(40 * m_id[0] + m_id[1]));
for(size_t i = 2; i != m_id.size(); ++i)
{
if(m_id[i] == 0)
encoding.push_back(0);
else
{
size_t blocks = high_bit(m_id[i]) + 6;
blocks = (blocks - (blocks % 7)) / 7;
BOTAN_ASSERT(blocks > 0, "Math works");
for(size_t j = 0; j != blocks - 1; ++j)
encoding.push_back(0x80 | ((m_id[i] >> 7*(blocks-j-1)) & 0x7F));
encoding.push_back(m_id[i] & 0x7F);
}
}
der.add_object(OBJECT_ID, UNIVERSAL, encoding);
}
/*
* Decode a BER encoded OBJECT IDENTIFIER
*/
void OID::decode_from(BER_Decoder& decoder)
{
BER_Object obj = decoder.get_next_object();
if(obj.tagging() != OBJECT_ID)
throw BER_Bad_Tag("Error decoding OID, unknown tag", obj.tagging());
const size_t length = obj.length();
const uint8_t* bits = obj.bits();
if(length < 2 && !(length == 1 && bits[0] == 0))
{
throw BER_Decoding_Error("OID encoding is too short");
}
clear();
m_id.push_back(bits[0] / 40);
m_id.push_back(bits[0] % 40);
size_t i = 0;
while(i != length - 1)
{
uint32_t component = 0;
while(i != length - 1)
{
++i;
if(component >> (32-7))
throw Decoding_Error("OID component overflow");
component = (component << 7) + (bits[i] & 0x7F);
if(!(bits[i] & 0x80))
break;
}
m_id.push_back(component);
}
}
}

View File

@@ -1,110 +0,0 @@
/*
* ASN.1 OID
* (C) 1999-2007 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#ifndef BOTAN_ASN1_OID_H_
#define BOTAN_ASN1_OID_H_
#include <botan/asn1_obj.h>
#include <string>
#include <vector>
namespace Botan {
/**
* This class represents ASN.1 object identifiers.
*/
class BOTAN_PUBLIC_API(2,0) OID final : public ASN1_Object
{
public:
void encode_into(class DER_Encoder&) const override;
void decode_from(class BER_Decoder&) override;
/**
* Find out whether this OID is empty
* @return true is no OID value is set
*/
bool empty() const { return m_id.empty(); }
/**
* Find out whether this OID has a value
* @return true is this OID has a value
*/
bool has_value() const { return (m_id.empty() == false); }
/**
* Get this OID as list (vector) of its components.
* @return vector representing this OID
*/
const std::vector<uint32_t>& get_id() const { return m_id; }
/**
* Get this OID as a string
* @return string representing this OID
*/
std::string as_string() const { return this->to_string(); }
/**
* Get this OID as a string
* @return string representing this OID
*/
std::string to_string() const;
/**
* Compare two OIDs.
* @return true if they are equal, false otherwise
*/
bool operator==(const OID&) const;
/**
* Reset this instance to an empty OID.
*/
void clear();
/**
* Add a component to this OID.
* @param new_comp the new component to add to the end of this OID
* @return reference to *this
*/
OID& operator+=(uint32_t new_comp);
/**
* Construct an OID from a string.
* @param str a string in the form "a.b.c" etc., where a,b,c are numbers
*/
OID(const std::string& str = "");
explicit OID(std::initializer_list<uint32_t> init) : m_id(init) {}
private:
std::vector<uint32_t> m_id;
};
/**
* Append another component onto the OID.
* @param oid the OID to add the new component to
* @param new_comp the new component to add
*/
OID BOTAN_PUBLIC_API(2,0) operator+(const OID& oid, uint32_t new_comp);
/**
* Compare two OIDs.
* @param a the first OID
* @param b the second OID
* @return true if a is not equal to b
*/
bool BOTAN_PUBLIC_API(2,0) operator!=(const OID& a, const OID& b);
/**
* Compare two OIDs.
* @param a the first OID
* @param b the second OID
* @return true if a is lexicographically smaller than b
*/
bool BOTAN_PUBLIC_API(2,0) operator<(const OID& a, const OID& b);
}
#endif

View File

@@ -1,329 +0,0 @@
/*
* (C) 2014,2015,2017 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#include <botan/asn1_print.h>
#include <botan/bigint.h>
#include <botan/hex.h>
#include <botan/der_enc.h>
#include <botan/ber_dec.h>
#include <botan/asn1_time.h>
#include <botan/asn1_str.h>
#include <botan/oids.h>
#include <iomanip>
#include <sstream>
#include <cctype>
namespace Botan {
namespace {
bool all_printable_chars(const uint8_t bits[], size_t bits_len)
{
for(size_t i = 0; i != bits_len; ++i)
{
int c = bits[i];
if(c > 127)
return false;
if((std::isalnum(c) || c == '.' || c == ':' || c == '/' || c == '-') == false)
return false;
}
return true;
}
/*
* Special hack to handle GeneralName [2] and [6] (DNS name and URI)
*/
bool possibly_a_general_name(const uint8_t bits[], size_t bits_len)
{
if(bits_len <= 2)
return false;
if(bits[0] != 0x82 && bits[0] != 0x86)
return false;
if(bits[1] != bits_len - 2)
return false;
if(all_printable_chars(bits + 2, bits_len - 2) == false)
return false;
return true;
}
}
std::string ASN1_Formatter::print(const uint8_t in[], size_t len) const
{
std::ostringstream output;
print_to_stream(output, in, len);
return output.str();
}
void ASN1_Formatter::print_to_stream(std::ostream& output,
const uint8_t in[],
size_t len) const
{
BER_Decoder dec(in, len);
decode(output, dec, 0);
}
void ASN1_Formatter::decode(std::ostream& output,
BER_Decoder& decoder,
size_t level) const
{
BER_Object obj = decoder.get_next_object();
const bool recurse_deeper = (m_max_depth == 0 || level < m_max_depth);
while(obj.is_set())
{
const ASN1_Tag type_tag = obj.type();
const ASN1_Tag class_tag = obj.get_class();
const size_t length = obj.length();
/* hack to insert the tag+length back in front of the stuff now
that we've gotten the type info */
std::vector<uint8_t> bits;
DER_Encoder(bits).add_object(type_tag, class_tag, obj.bits(), obj.length());
BER_Decoder data(bits);
if(class_tag & CONSTRUCTED)
{
BER_Decoder cons_info(obj.bits(), obj.length());
if(recurse_deeper)
{
output << format(type_tag, class_tag, level, length, "");
decode(output, cons_info, level + 1); // recurse
}
else
{
output << format(type_tag, class_tag, level, length,
format_bin(type_tag, class_tag, bits));
}
}
else if((class_tag & APPLICATION) || (class_tag & CONTEXT_SPECIFIC))
{
bool success_parsing_cs = false;
if(m_print_context_specific)
{
try
{
if(possibly_a_general_name(bits.data(), bits.size()))
{
output << format(type_tag, class_tag, level, level,
std::string(cast_uint8_ptr_to_char(&bits[2]), bits.size() - 2));
success_parsing_cs = true;
}
else if(recurse_deeper)
{
std::vector<uint8_t> inner_bits;
data.decode(inner_bits, type_tag);
BER_Decoder inner(inner_bits);
std::ostringstream inner_data;
decode(inner_data, inner, level + 1); // recurse
output << inner_data.str();
success_parsing_cs = true;
}
}
catch(...)
{
}
}
if(success_parsing_cs == false)
{
output << format(type_tag, class_tag, level, length,
format_bin(type_tag, class_tag, bits));
}
}
else if(type_tag == OBJECT_ID)
{
OID oid;
data.decode(oid);
std::string out = OIDS::lookup(oid);
if(out.empty())
{
out = oid.as_string();
}
else
{
out += " [" + oid.as_string() + "]";
}
output << format(type_tag, class_tag, level, length, out);
}
else if(type_tag == INTEGER || type_tag == ENUMERATED)
{
BigInt number;
if(type_tag == INTEGER)
{
data.decode(number);
}
else if(type_tag == ENUMERATED)
{
data.decode(number, ENUMERATED, class_tag);
}
std::vector<uint8_t> rep = BigInt::encode(number);
if(rep.empty()) // if zero
rep.resize(1);
output << format(type_tag, class_tag, level, length, hex_encode(rep));
}
else if(type_tag == BOOLEAN)
{
bool boolean;
data.decode(boolean);
output << format(type_tag, class_tag, level, length, (boolean ? "true" : "false"));
}
else if(type_tag == NULL_TAG)
{
output << format(type_tag, class_tag, level, length, "");
}
else if(type_tag == OCTET_STRING || type_tag == BIT_STRING)
{
std::vector<uint8_t> decoded_bits;
data.decode(decoded_bits, type_tag);
bool printing_octet_string_worked = false;
if(recurse_deeper)
{
try
{
BER_Decoder inner(decoded_bits);
std::ostringstream inner_data;
decode(inner_data, inner, level + 1); // recurse
output << format(type_tag, class_tag, level, length, "");
output << inner_data.str();
printing_octet_string_worked = true;
}
catch(...)
{
}
}
if(!printing_octet_string_worked)
{
output << format(type_tag, class_tag, level, length,
format_bin(type_tag, class_tag, decoded_bits));
}
}
else if(ASN1_String::is_string_type(type_tag))
{
ASN1_String str;
data.decode(str);
output << format(type_tag, class_tag, level, length, str.value());
}
else if(type_tag == UTC_TIME || type_tag == GENERALIZED_TIME)
{
X509_Time time;
data.decode(time);
output << format(type_tag, class_tag, level, length, time.readable_string());
}
else
{
output << "Unknown ASN.1 tag class=" << static_cast<int>(class_tag)
<< " type=" << static_cast<int>(type_tag) << "\n";
}
obj = decoder.get_next_object();
}
}
namespace {
std::string format_type(ASN1_Tag type_tag, ASN1_Tag class_tag)
{
if(class_tag == UNIVERSAL)
return asn1_tag_to_string(type_tag);
if(class_tag == CONSTRUCTED && (type_tag == SEQUENCE || type_tag == SET))
return asn1_tag_to_string(type_tag);
std::string name;
if(class_tag & CONSTRUCTED)
name += "cons ";
name += "[" + std::to_string(type_tag) + "]";
if(class_tag & APPLICATION)
{
name += " appl";
}
if(class_tag & CONTEXT_SPECIFIC)
{
name += " context";
}
return name;
}
}
std::string ASN1_Pretty_Printer::format(ASN1_Tag type_tag,
ASN1_Tag class_tag,
size_t level,
size_t length,
const std::string& value) const
{
bool should_skip = false;
if(value.length() > m_print_limit)
{
should_skip = true;
}
if((type_tag == OCTET_STRING || type_tag == BIT_STRING) &&
value.length() > m_print_binary_limit)
{
should_skip = true;
}
level += m_initial_level;
std::ostringstream oss;
oss << " d=" << std::setw(2) << level
<< ", l=" << std::setw(4) << length << ":"
<< std::string(level + 1, ' ') << format_type(type_tag, class_tag);
if(value != "" && !should_skip)
{
const size_t current_pos = static_cast<size_t>(oss.tellp());
const size_t spaces_to_align =
(current_pos >= m_value_column) ? 1 : (m_value_column - current_pos);
oss << std::string(spaces_to_align, ' ') << value;
}
oss << "\n";
return oss.str();
}
std::string ASN1_Pretty_Printer::format_bin(ASN1_Tag /*type_tag*/,
ASN1_Tag /*class_tag*/,
const std::vector<uint8_t>& vec) const
{
if(all_printable_chars(vec.data(), vec.size()))
{
return std::string(cast_uint8_ptr_to_char(vec.data()), vec.size());
}
else
return hex_encode(vec);
}
}

View File

@@ -1,125 +0,0 @@
/*
* (C) 2014,2015,2017 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#ifndef BOTAN_ASN1_PRINT_H_
#define BOTAN_ASN1_PRINT_H_
#include <botan/asn1_obj.h>
#include <string>
#include <vector>
#include <iosfwd>
namespace Botan {
class BER_Decoder;
/**
* Format ASN.1 data and call a virtual to format
*/
class BOTAN_PUBLIC_API(2,4) ASN1_Formatter
{
public:
virtual ~ASN1_Formatter() = default;
/**
* @param print_context_specific if true, try to parse nested context specific data.
* @param max_depth do not recurse more than this many times. If zero, recursion
* is unbounded.
*/
ASN1_Formatter(bool print_context_specific, size_t max_depth) :
m_print_context_specific(print_context_specific),
m_max_depth(max_depth)
{}
void print_to_stream(std::ostream& out,
const uint8_t in[],
size_t len) const;
std::string print(const uint8_t in[], size_t len) const;
template<typename Alloc>
std::string print(const std::vector<uint8_t, Alloc>& vec) const
{
return print(vec.data(), vec.size());
}
protected:
/**
* This is called for each element
*/
virtual std::string format(ASN1_Tag type_tag,
ASN1_Tag class_tag,
size_t level,
size_t length,
const std::string& value) const = 0;
/**
* This is called to format binary elements that we don't know how to
* convert to a string The result will be passed as value to format; the
* tags are included as a hint to aid decoding.
*/
virtual std::string format_bin(ASN1_Tag type_tag,
ASN1_Tag class_tag,
const std::vector<uint8_t>& vec) const = 0;
private:
void decode(std::ostream& output,
BER_Decoder& decoder,
size_t level) const;
const bool m_print_context_specific;
const size_t m_max_depth;
};
/**
* Format ASN.1 data into human readable output. The exact form of the output for
* any particular input is not guaranteed and may change from release to release.
*/
class BOTAN_PUBLIC_API(2,4) ASN1_Pretty_Printer final : public ASN1_Formatter
{
public:
/**
* @param print_limit strings larger than this are not printed
* @param print_binary_limit binary strings larger than this are not printed
* @param print_context_specific if true, try to parse nested context specific data.
* @param initial_level the initial depth (0 or 1 are the only reasonable values)
* @param value_column ASN.1 values are lined up at this column in output
* @param max_depth do not recurse more than this many times. If zero, recursion
* is unbounded.
*/
ASN1_Pretty_Printer(size_t print_limit = 4096,
size_t print_binary_limit = 2048,
bool print_context_specific = true,
size_t initial_level = 0,
size_t value_column = 60,
size_t max_depth = 64) :
ASN1_Formatter(print_context_specific, max_depth),
m_print_limit(print_limit),
m_print_binary_limit(print_binary_limit),
m_initial_level(initial_level),
m_value_column(value_column)
{}
private:
std::string format(ASN1_Tag type_tag,
ASN1_Tag class_tag,
size_t level,
size_t length,
const std::string& value) const override;
std::string format_bin(ASN1_Tag type_tag,
ASN1_Tag class_tag,
const std::vector<uint8_t>& vec) const override;
const size_t m_print_limit;
const size_t m_print_binary_limit;
const size_t m_initial_level;
const size_t m_value_column;
};
}
#endif

View File

@@ -1,153 +0,0 @@
/*
* Simple ASN.1 String Types
* (C) 1999-2007 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#include <botan/asn1_str.h>
#include <botan/der_enc.h>
#include <botan/ber_dec.h>
#include <botan/charset.h>
namespace Botan {
namespace {
/*
* Choose an encoding for the string
*/
ASN1_Tag choose_encoding(const std::string& str)
{
static const uint8_t IS_PRINTABLE[256] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00,
0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 };
for(size_t i = 0; i != str.size(); ++i)
{
if(!IS_PRINTABLE[static_cast<uint8_t>(str[i])])
{
return UTF8_STRING;
}
}
return PRINTABLE_STRING;
}
void assert_is_string_type(ASN1_Tag tag)
{
if(!ASN1_String::is_string_type(tag))
{
throw Invalid_Argument("ASN1_String: Unknown string type " +
std::to_string(tag));
}
}
}
//static
bool ASN1_String::is_string_type(ASN1_Tag tag)
{
return (tag == NUMERIC_STRING ||
tag == PRINTABLE_STRING ||
tag == VISIBLE_STRING ||
tag == T61_STRING ||
tag == IA5_STRING ||
tag == UTF8_STRING ||
tag == BMP_STRING ||
tag == UNIVERSAL_STRING);
}
/*
* Create an ASN1_String
*/
ASN1_String::ASN1_String(const std::string& str, ASN1_Tag t) : m_utf8_str(str), m_tag(t)
{
if(m_tag == DIRECTORY_STRING)
{
m_tag = choose_encoding(m_utf8_str);
}
assert_is_string_type(m_tag);
}
/*
* Create an ASN1_String
*/
ASN1_String::ASN1_String(const std::string& str) :
m_utf8_str(str),
m_tag(choose_encoding(m_utf8_str))
{}
/*
* Return this string in ISO 8859-1 encoding
*/
std::string ASN1_String::iso_8859() const
{
return utf8_to_latin1(m_utf8_str);
}
/*
* DER encode an ASN1_String
*/
void ASN1_String::encode_into(DER_Encoder& encoder) const
{
if(m_data.empty())
{
encoder.add_object(tagging(), UNIVERSAL, m_utf8_str);
}
else
{
// If this string was decoded, reserialize using original encoding
encoder.add_object(tagging(), UNIVERSAL, m_data.data(), m_data.size());
}
}
/*
* Decode a BER encoded ASN1_String
*/
void ASN1_String::decode_from(BER_Decoder& source)
{
BER_Object obj = source.get_next_object();
assert_is_string_type(obj.type());
m_tag = obj.type();
m_data.assign(obj.bits(), obj.bits() + obj.length());
if(m_tag == BMP_STRING)
{
m_utf8_str = ucs2_to_utf8(m_data.data(), m_data.size());
}
else if(m_tag == UNIVERSAL_STRING)
{
m_utf8_str = ucs4_to_utf8(m_data.data(), m_data.size());
}
else
{
// All other supported string types are UTF-8 or some subset thereof
m_utf8_str = ASN1::to_string(obj);
}
}
}

View File

@@ -1,55 +0,0 @@
/*
* ASN.1 string type
* (C) 1999-2010 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#ifndef BOTAN_ASN1_STRING_H_
#define BOTAN_ASN1_STRING_H_
#include <botan/asn1_obj.h>
namespace Botan {
/**
* ASN.1 string type
* This class normalizes all inputs to a UTF-8 std::string
*/
class BOTAN_PUBLIC_API(2,0) ASN1_String final : public ASN1_Object
{
public:
void encode_into(class DER_Encoder&) const override;
void decode_from(class BER_Decoder&) override;
ASN1_Tag tagging() const { return m_tag; }
const std::string& value() const { return m_utf8_str; }
size_t size() const { return value().size(); }
bool empty() const { return m_utf8_str.empty(); }
std::string BOTAN_DEPRECATED("Use value() to get UTF-8 string instead")
iso_8859() const;
/**
* Return true iff this is a tag for a known string type we can handle.
* This ignores string types that are not supported, eg teletexString
*/
static bool is_string_type(ASN1_Tag tag);
bool operator==(const ASN1_String& other) const
{ return value() == other.value(); }
explicit ASN1_String(const std::string& utf8 = "");
ASN1_String(const std::string& utf8, ASN1_Tag tag);
private:
std::vector<uint8_t> m_data;
std::string m_utf8_str;
ASN1_Tag m_tag;
};
}
#endif

View File

@@ -1,289 +0,0 @@
/*
* X.509 Time Types
* (C) 1999-2007 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#include <botan/asn1_time.h>
#include <botan/der_enc.h>
#include <botan/ber_dec.h>
#include <botan/exceptn.h>
#include <botan/parsing.h>
#include <botan/calendar.h>
#include <sstream>
#include <iomanip>
namespace Botan {
X509_Time::X509_Time(const std::chrono::system_clock::time_point& time)
{
calendar_point cal = calendar_value(time);
m_year = cal.get_year();
m_month = cal.get_month();
m_day = cal.get_day();
m_hour = cal.get_hour();
m_minute = cal.get_minutes();
m_second = cal.get_seconds();
m_tag = (m_year >= 2050) ? GENERALIZED_TIME : UTC_TIME;
}
X509_Time::X509_Time(const std::string& t_spec, ASN1_Tag tag)
{
set_to(t_spec, tag);
}
void X509_Time::encode_into(DER_Encoder& der) const
{
BOTAN_ARG_CHECK(m_tag == UTC_TIME || m_tag == GENERALIZED_TIME,
"X509_Time: Bad encoding tag");
der.add_object(m_tag, UNIVERSAL, to_string());
}
void X509_Time::decode_from(BER_Decoder& source)
{
BER_Object ber_time = source.get_next_object();
set_to(ASN1::to_string(ber_time), ber_time.type());
}
std::string X509_Time::to_string() const
{
if(time_is_set() == false)
throw Invalid_State("X509_Time::as_string: No time set");
uint32_t full_year = m_year;
if(m_tag == UTC_TIME)
{
if(m_year < 1950 || m_year >= 2050)
throw Encoding_Error("X509_Time: The time " + readable_string() +
" cannot be encoded as a UTCTime");
full_year = (m_year >= 2000) ? (m_year - 2000) : (m_year - 1900);
}
const uint64_t YEAR_FACTOR = 10000000000ULL;
const uint64_t MON_FACTOR = 100000000;
const uint64_t DAY_FACTOR = 1000000;
const uint64_t HOUR_FACTOR = 10000;
const uint64_t MIN_FACTOR = 100;
const uint64_t int_repr =
YEAR_FACTOR * full_year +
MON_FACTOR * m_month +
DAY_FACTOR * m_day +
HOUR_FACTOR * m_hour +
MIN_FACTOR * m_minute +
m_second;
std::string repr = std::to_string(int_repr) + "Z";
uint32_t desired_size = (m_tag == UTC_TIME) ? 13 : 15;
while(repr.size() < desired_size)
repr = "0" + repr;
return repr;
}
std::string X509_Time::readable_string() const
{
if(time_is_set() == false)
throw Invalid_State("X509_Time::readable_string: No time set");
// desired format: "%04d/%02d/%02d %02d:%02d:%02d UTC"
std::stringstream output;
output << std::setfill('0')
<< std::setw(4) << m_year << "/"
<< std::setw(2) << m_month << "/"
<< std::setw(2) << m_day
<< " "
<< std::setw(2) << m_hour << ":"
<< std::setw(2) << m_minute << ":"
<< std::setw(2) << m_second
<< " UTC";
return output.str();
}
bool X509_Time::time_is_set() const
{
return (m_year != 0);
}
int32_t X509_Time::cmp(const X509_Time& other) const
{
if(time_is_set() == false)
throw Invalid_State("X509_Time::cmp: No time set");
const int32_t EARLIER = -1, LATER = 1, SAME_TIME = 0;
if(m_year < other.m_year) return EARLIER;
if(m_year > other.m_year) return LATER;
if(m_month < other.m_month) return EARLIER;
if(m_month > other.m_month) return LATER;
if(m_day < other.m_day) return EARLIER;
if(m_day > other.m_day) return LATER;
if(m_hour < other.m_hour) return EARLIER;
if(m_hour > other.m_hour) return LATER;
if(m_minute < other.m_minute) return EARLIER;
if(m_minute > other.m_minute) return LATER;
if(m_second < other.m_second) return EARLIER;
if(m_second > other.m_second) return LATER;
return SAME_TIME;
}
void X509_Time::set_to(const std::string& t_spec, ASN1_Tag spec_tag)
{
if(spec_tag == UTC_OR_GENERALIZED_TIME)
{
try
{
set_to(t_spec, GENERALIZED_TIME);
return;
}
catch(Invalid_Argument&) {} // Not a generalized time. Continue
try
{
set_to(t_spec, UTC_TIME);
return;
}
catch(Invalid_Argument&) {} // Not a UTC time. Continue
throw Invalid_Argument("Time string could not be parsed as GeneralizedTime or UTCTime.");
}
BOTAN_ASSERT(spec_tag == UTC_TIME || spec_tag == GENERALIZED_TIME, "Invalid tag.");
BOTAN_ARG_CHECK(t_spec.size() > 0, "Time string must not be empty.");
BOTAN_ARG_CHECK(t_spec.back() == 'Z', "Botan does not support times with timezones other than Z");
if(spec_tag == GENERALIZED_TIME)
{
BOTAN_ARG_CHECK(t_spec.size() == 15, "Invalid GeneralizedTime string");
}
else if(spec_tag == UTC_TIME)
{
BOTAN_ARG_CHECK(t_spec.size() == 13, "Invalid UTCTime string");
}
const size_t YEAR_SIZE = (spec_tag == UTC_TIME) ? 2 : 4;
std::vector<std::string> params;
std::string current;
for(size_t j = 0; j != YEAR_SIZE; ++j)
current += t_spec[j];
params.push_back(current);
current.clear();
for(size_t j = YEAR_SIZE; j != t_spec.size() - 1; ++j)
{
current += t_spec[j];
if(current.size() == 2)
{
params.push_back(current);
current.clear();
}
}
m_year = to_u32bit(params[0]);
m_month = to_u32bit(params[1]);
m_day = to_u32bit(params[2]);
m_hour = to_u32bit(params[3]);
m_minute = to_u32bit(params[4]);
m_second = (params.size() == 6) ? to_u32bit(params[5]) : 0;
m_tag = spec_tag;
if(spec_tag == UTC_TIME)
{
if(m_year >= 50) m_year += 1900;
else m_year += 2000;
}
if(!passes_sanity_check())
throw Invalid_Argument("Time " + t_spec + " does not seem to be valid");
}
/*
* Do a general sanity check on the time
*/
bool X509_Time::passes_sanity_check() const
{
if(m_year < 1950 || m_year > 2200)
return false;
if(m_month == 0 || m_month > 12)
return false;
const uint32_t days_in_month[12] = { 31, 28+1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if(m_day == 0 || m_day > days_in_month[m_month-1])
return false;
if(m_month == 2 && m_day == 29)
{
if(m_year % 4 != 0)
return false; // not a leap year
if(m_year % 100 == 0 && m_year % 400 != 0)
return false;
}
if(m_hour >= 24 || m_minute >= 60 || m_second > 60)
return false;
if (m_tag == UTC_TIME)
{
/*
UTCTime limits the value of components such that leap seconds
are not covered. See "UNIVERSAL 23" in "Information technology
Abstract Syntax Notation One (ASN.1): Specification of basic notation"
http://www.itu.int/ITU-T/studygroups/com17/languages/
*/
if (m_hour > 23 || m_minute > 59 || m_second > 59)
{
return false;
}
}
return true;
}
std::chrono::system_clock::time_point X509_Time::to_std_timepoint() const
{
return calendar_point(m_year, m_month, m_day, m_hour, m_minute, m_second).to_std_timepoint();
}
uint64_t X509_Time::time_since_epoch() const
{
auto tp = this->to_std_timepoint();
return std::chrono::duration_cast<std::chrono::seconds>(tp.time_since_epoch()).count();
}
/*
* Compare two X509_Times for in various ways
*/
bool operator==(const X509_Time& t1, const X509_Time& t2)
{ return (t1.cmp(t2) == 0); }
bool operator!=(const X509_Time& t1, const X509_Time& t2)
{ return (t1.cmp(t2) != 0); }
bool operator<=(const X509_Time& t1, const X509_Time& t2)
{ return (t1.cmp(t2) <= 0); }
bool operator>=(const X509_Time& t1, const X509_Time& t2)
{ return (t1.cmp(t2) >= 0); }
bool operator<(const X509_Time& t1, const X509_Time& t2)
{ return (t1.cmp(t2) < 0); }
bool operator>(const X509_Time& t1, const X509_Time& t2)
{ return (t1.cmp(t2) > 0); }
}

View File

@@ -1,82 +0,0 @@
/*
* ASN.1 Time Representation
* (C) 1999-2007,2012 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#ifndef BOTAN_ASN1_TIME_H_
#define BOTAN_ASN1_TIME_H_
#include <botan/asn1_obj.h>
#include <chrono>
namespace Botan {
/**
* X.509 Time
*/
class BOTAN_PUBLIC_API(2,0) X509_Time final : public ASN1_Object
{
public:
/// DER encode a X509_Time
void encode_into(DER_Encoder&) const override;
// Decode a BER encoded X509_Time
void decode_from(BER_Decoder&) override;
/// Return an internal string representation of the time
std::string to_string() const;
/// Returns a human friendly string replesentation of no particular formatting
std::string readable_string() const;
/// Return if the time has been set somehow
bool time_is_set() const;
/// Compare this time against another
int32_t cmp(const X509_Time& other) const;
/// Create an invalid X509_Time
X509_Time() = default;
/// Create a X509_Time from a time point
explicit X509_Time(const std::chrono::system_clock::time_point& time);
/// Create an X509_Time from string
X509_Time(const std::string& t_spec, ASN1_Tag tag);
/// Returns a STL timepoint object
std::chrono::system_clock::time_point to_std_timepoint() const;
/// Return time since epoch
uint64_t time_since_epoch() const;
private:
void set_to(const std::string& t_spec, ASN1_Tag);
bool passes_sanity_check() const;
uint32_t m_year = 0;
uint32_t m_month = 0;
uint32_t m_day = 0;
uint32_t m_hour = 0;
uint32_t m_minute = 0;
uint32_t m_second = 0;
ASN1_Tag m_tag = NO_OBJECT;
};
/*
* Comparison Operations
*/
bool BOTAN_PUBLIC_API(2,0) operator==(const X509_Time&, const X509_Time&);
bool BOTAN_PUBLIC_API(2,0) operator!=(const X509_Time&, const X509_Time&);
bool BOTAN_PUBLIC_API(2,0) operator<=(const X509_Time&, const X509_Time&);
bool BOTAN_PUBLIC_API(2,0) operator>=(const X509_Time&, const X509_Time&);
bool BOTAN_PUBLIC_API(2,0) operator<(const X509_Time&, const X509_Time&);
bool BOTAN_PUBLIC_API(2,0) operator>(const X509_Time&, const X509_Time&);
typedef X509_Time ASN1_Time;
}
#endif

View File

@@ -1,549 +0,0 @@
/*
* BER Decoder
* (C) 1999-2008,2015,2017,2018 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#include <botan/ber_dec.h>
#include <botan/bigint.h>
#include <botan/loadstor.h>
#include <botan/internal/safeint.h>
namespace Botan {
namespace {
/*
* This value is somewhat arbitrary. OpenSSL allows up to 128 nested
* indefinite length sequences. If you increase this, also increase the
* limit in the test in test_asn1.cpp
*/
const size_t ALLOWED_EOC_NESTINGS = 16;
/*
* BER decode an ASN.1 type tag
*/
size_t decode_tag(DataSource* ber, ASN1_Tag& type_tag, ASN1_Tag& class_tag)
{
uint8_t b;
if(!ber->read_byte(b))
{
class_tag = type_tag = NO_OBJECT;
return 0;
}
if((b & 0x1F) != 0x1F)
{
type_tag = ASN1_Tag(b & 0x1F);
class_tag = ASN1_Tag(b & 0xE0);
return 1;
}
size_t tag_bytes = 1;
class_tag = ASN1_Tag(b & 0xE0);
size_t tag_buf = 0;
while(true)
{
if(!ber->read_byte(b))
throw BER_Decoding_Error("Long-form tag truncated");
if(tag_buf & 0xFF000000)
throw BER_Decoding_Error("Long-form tag overflowed 32 bits");
++tag_bytes;
tag_buf = (tag_buf << 7) | (b & 0x7F);
if((b & 0x80) == 0) break;
}
type_tag = ASN1_Tag(tag_buf);
return tag_bytes;
}
/*
* Find the EOC marker
*/
size_t find_eoc(DataSource* src, size_t allow_indef);
/*
* BER decode an ASN.1 length field
*/
size_t decode_length(DataSource* ber, size_t& field_size, size_t allow_indef)
{
uint8_t b;
if(!ber->read_byte(b))
throw BER_Decoding_Error("Length field not found");
field_size = 1;
if((b & 0x80) == 0)
return b;
field_size += (b & 0x7F);
if(field_size > 5)
throw BER_Decoding_Error("Length field is too large");
if(field_size == 1)
{
if(allow_indef == 0)
{
throw BER_Decoding_Error("Nested EOC markers too deep, rejecting to avoid stack exhaustion");
}
else
{
return find_eoc(ber, allow_indef - 1);
}
}
size_t length = 0;
for(size_t i = 0; i != field_size - 1; ++i)
{
if(get_byte(0, length) != 0)
throw BER_Decoding_Error("Field length overflow");
if(!ber->read_byte(b))
throw BER_Decoding_Error("Corrupted length field");
length = (length << 8) | b;
}
return length;
}
/*
* Find the EOC marker
*/
size_t find_eoc(DataSource* ber, size_t allow_indef)
{
secure_vector<uint8_t> buffer(BOTAN_DEFAULT_BUFFER_SIZE), data;
while(true)
{
const size_t got = ber->peek(buffer.data(), buffer.size(), data.size());
if(got == 0)
break;
data += std::make_pair(buffer.data(), got);
}
DataSource_Memory source(data);
data.clear();
size_t length = 0;
while(true)
{
ASN1_Tag type_tag, class_tag;
size_t tag_size = decode_tag(&source, type_tag, class_tag);
if(type_tag == NO_OBJECT)
break;
size_t length_size = 0;
size_t item_size = decode_length(&source, length_size, allow_indef);
source.discard_next(item_size);
length = BOTAN_CHECKED_ADD(length, item_size);
length = BOTAN_CHECKED_ADD(length, tag_size);
length = BOTAN_CHECKED_ADD(length, length_size);
if(type_tag == EOC && class_tag == UNIVERSAL)
break;
}
return length;
}
class DataSource_BERObject final : public DataSource
{
public:
size_t read(uint8_t out[], size_t length) override
{
BOTAN_ASSERT_NOMSG(m_offset <= m_obj.length());
const size_t got = std::min<size_t>(m_obj.length() - m_offset, length);
copy_mem(out, m_obj.bits() + m_offset, got);
m_offset += got;
return got;
}
size_t peek(uint8_t out[], size_t length, size_t peek_offset) const override
{
BOTAN_ASSERT_NOMSG(m_offset <= m_obj.length());
const size_t bytes_left = m_obj.length() - m_offset;
if(peek_offset >= bytes_left)
return 0;
const size_t got = std::min(bytes_left - peek_offset, length);
copy_mem(out, m_obj.bits() + peek_offset, got);
return got;
}
bool check_available(size_t n) override
{
BOTAN_ASSERT_NOMSG(m_offset <= m_obj.length());
return (n <= (m_obj.length() - m_offset));
}
bool end_of_data() const override
{
return get_bytes_read() == m_obj.length();
}
size_t get_bytes_read() const override { return m_offset; }
explicit DataSource_BERObject(BER_Object&& obj) : m_obj(std::move(obj)), m_offset(0) {}
private:
BER_Object m_obj;
size_t m_offset;
};
}
/*
* Check if more objects are there
*/
bool BER_Decoder::more_items() const
{
if(m_source->end_of_data() && !m_pushed.is_set())
return false;
return true;
}
/*
* Verify that no bytes remain in the source
*/
BER_Decoder& BER_Decoder::verify_end()
{
return verify_end("BER_Decoder::verify_end called, but data remains");
}
/*
* Verify that no bytes remain in the source
*/
BER_Decoder& BER_Decoder::verify_end(const std::string& err)
{
if(!m_source->end_of_data() || m_pushed.is_set())
throw Decoding_Error(err);
return (*this);
}
/*
* Discard all the bytes remaining in the source
*/
BER_Decoder& BER_Decoder::discard_remaining()
{
uint8_t buf;
while(m_source->read_byte(buf))
{}
return (*this);
}
/*
* Return the BER encoding of the next object
*/
BER_Object BER_Decoder::get_next_object()
{
BER_Object next;
if(m_pushed.is_set())
{
std::swap(next, m_pushed);
return next;
}
for(;;)
{
ASN1_Tag type_tag, class_tag;
decode_tag(m_source, type_tag, class_tag);
next.set_tagging(type_tag, class_tag);
if(next.is_set() == false) // no more objects
return next;
size_t field_size;
const size_t length = decode_length(m_source, field_size, ALLOWED_EOC_NESTINGS);
if(!m_source->check_available(length))
throw BER_Decoding_Error("Value truncated");
uint8_t* out = next.mutable_bits(length);
if(m_source->read(out, length) != length)
throw BER_Decoding_Error("Value truncated");
if(next.tagging() == EOC)
continue;
else
break;
}
return next;
}
/*
* Push a object back into the stream
*/
void BER_Decoder::push_back(const BER_Object& obj)
{
if(m_pushed.is_set())
throw Invalid_State("BER_Decoder: Only one push back is allowed");
m_pushed = obj;
}
void BER_Decoder::push_back(BER_Object&& obj)
{
if(m_pushed.is_set())
throw Invalid_State("BER_Decoder: Only one push back is allowed");
m_pushed = std::move(obj);
}
BER_Decoder BER_Decoder::start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag)
{
BER_Object obj = get_next_object();
obj.assert_is_a(type_tag, ASN1_Tag(class_tag | CONSTRUCTED));
return BER_Decoder(std::move(obj), this);
}
/*
* Finish decoding a CONSTRUCTED type
*/
BER_Decoder& BER_Decoder::end_cons()
{
if(!m_parent)
throw Invalid_State("BER_Decoder::end_cons called with null parent");
if(!m_source->end_of_data())
throw Decoding_Error("BER_Decoder::end_cons called with data left");
return (*m_parent);
}
BER_Decoder::BER_Decoder(BER_Object&& obj, BER_Decoder* parent)
{
m_data_src.reset(new DataSource_BERObject(std::move(obj)));
m_source = m_data_src.get();
m_parent = parent;
}
/*
* BER_Decoder Constructor
*/
BER_Decoder::BER_Decoder(DataSource& src)
{
m_source = &src;
}
/*
* BER_Decoder Constructor
*/
BER_Decoder::BER_Decoder(const uint8_t data[], size_t length)
{
m_data_src.reset(new DataSource_Memory(data, length));
m_source = m_data_src.get();
}
/*
* BER_Decoder Constructor
*/
BER_Decoder::BER_Decoder(const secure_vector<uint8_t>& data)
{
m_data_src.reset(new DataSource_Memory(data));
m_source = m_data_src.get();
}
/*
* BER_Decoder Constructor
*/
BER_Decoder::BER_Decoder(const std::vector<uint8_t>& data)
{
m_data_src.reset(new DataSource_Memory(data.data(), data.size()));
m_source = m_data_src.get();
}
/*
* BER_Decoder Copy Constructor
*/
BER_Decoder::BER_Decoder(const BER_Decoder& other)
{
m_source = other.m_source;
// take ownership
std::swap(m_data_src, other.m_data_src);
m_parent = other.m_parent;
}
/*
* Request for an object to decode itself
*/
BER_Decoder& BER_Decoder::decode(ASN1_Object& obj,
ASN1_Tag, ASN1_Tag)
{
obj.decode_from(*this);
return (*this);
}
/*
* Decode a BER encoded NULL
*/
BER_Decoder& BER_Decoder::decode_null()
{
BER_Object obj = get_next_object();
obj.assert_is_a(NULL_TAG, UNIVERSAL);
if(obj.length() > 0)
throw BER_Decoding_Error("NULL object had nonzero size");
return (*this);
}
BER_Decoder& BER_Decoder::decode_octet_string_bigint(BigInt& out)
{
secure_vector<uint8_t> out_vec;
decode(out_vec, OCTET_STRING);
out = BigInt::decode(out_vec.data(), out_vec.size());
return (*this);
}
/*
* Decode a BER encoded BOOLEAN
*/
BER_Decoder& BER_Decoder::decode(bool& out,
ASN1_Tag type_tag, ASN1_Tag class_tag)
{
BER_Object obj = get_next_object();
obj.assert_is_a(type_tag, class_tag);
if(obj.length() != 1)
throw BER_Decoding_Error("BER boolean value had invalid size");
out = (obj.bits()[0]) ? true : false;
return (*this);
}
/*
* Decode a small BER encoded INTEGER
*/
BER_Decoder& BER_Decoder::decode(size_t& out,
ASN1_Tag type_tag,
ASN1_Tag class_tag)
{
BigInt integer;
decode(integer, type_tag, class_tag);
if(integer.is_negative())
throw BER_Decoding_Error("Decoded small integer value was negative");
if(integer.bits() > 32)
throw BER_Decoding_Error("Decoded integer value larger than expected");
out = 0;
for(size_t i = 0; i != 4; ++i)
out = (out << 8) | integer.byte_at(3-i);
return (*this);
}
/*
* Decode a small BER encoded INTEGER
*/
uint64_t BER_Decoder::decode_constrained_integer(ASN1_Tag type_tag,
ASN1_Tag class_tag,
size_t T_bytes)
{
if(T_bytes > 8)
throw BER_Decoding_Error("Can't decode small integer over 8 bytes");
BigInt integer;
decode(integer, type_tag, class_tag);
if(integer.bits() > 8*T_bytes)
throw BER_Decoding_Error("Decoded integer value larger than expected");
uint64_t out = 0;
for(size_t i = 0; i != 8; ++i)
out = (out << 8) | integer.byte_at(7-i);
return out;
}
/*
* Decode a BER encoded INTEGER
*/
BER_Decoder& BER_Decoder::decode(BigInt& out,
ASN1_Tag type_tag,
ASN1_Tag class_tag)
{
BER_Object obj = get_next_object();
obj.assert_is_a(type_tag, class_tag);
if(obj.length() == 0)
{
out = 0;
}
else
{
const bool negative = (obj.bits()[0] & 0x80) ? true : false;
if(negative)
{
secure_vector<uint8_t> vec(obj.bits(), obj.bits() + obj.length());
for(size_t i = obj.length(); i > 0; --i)
if(vec[i-1]--)
break;
for(size_t i = 0; i != obj.length(); ++i)
vec[i] = ~vec[i];
out = BigInt(vec.data(), vec.size());
out.flip_sign();
}
else
{
out = BigInt(obj.bits(), obj.length());
}
}
return (*this);
}
namespace {
template<typename Alloc>
void asn1_decode_binary_string(std::vector<uint8_t, Alloc>& buffer,
const BER_Object& obj,
ASN1_Tag real_type,
ASN1_Tag type_tag,
ASN1_Tag class_tag)
{
obj.assert_is_a(type_tag, class_tag);
if(real_type == OCTET_STRING)
{
buffer.assign(obj.bits(), obj.bits() + obj.length());
}
else
{
if(obj.length() == 0)
throw BER_Decoding_Error("Invalid BIT STRING");
if(obj.bits()[0] >= 8)
throw BER_Decoding_Error("Bad number of unused bits in BIT STRING");
buffer.resize(obj.length() - 1);
if(obj.length() > 1)
copy_mem(buffer.data(), obj.bits() + 1, obj.length() - 1);
}
}
}
/*
* BER decode a BIT STRING or OCTET STRING
*/
BER_Decoder& BER_Decoder::decode(secure_vector<uint8_t>& buffer,
ASN1_Tag real_type,
ASN1_Tag type_tag, ASN1_Tag class_tag)
{
if(real_type != OCTET_STRING && real_type != BIT_STRING)
throw BER_Bad_Tag("Bad tag for {BIT,OCTET} STRING", real_type);
asn1_decode_binary_string(buffer, get_next_object(), real_type, type_tag, class_tag);
return (*this);
}
BER_Decoder& BER_Decoder::decode(std::vector<uint8_t>& buffer,
ASN1_Tag real_type,
ASN1_Tag type_tag, ASN1_Tag class_tag)
{
if(real_type != OCTET_STRING && real_type != BIT_STRING)
throw BER_Bad_Tag("Bad tag for {BIT,OCTET} STRING", real_type);
asn1_decode_binary_string(buffer, get_next_object(), real_type, type_tag, class_tag);
return (*this);
}
}

View File

@@ -1,418 +0,0 @@
/*
* BER Decoder
* (C) 1999-2010,2018 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#ifndef BOTAN_BER_DECODER_H_
#define BOTAN_BER_DECODER_H_
#include <botan/asn1_obj.h>
#include <botan/data_src.h>
namespace Botan {
class BigInt;
/**
* BER Decoding Object
*/
class BOTAN_PUBLIC_API(2,0) BER_Decoder final
{
public:
/**
* Set up to BER decode the data in buf of length len
*/
BER_Decoder(const uint8_t buf[], size_t len);
/**
* Set up to BER decode the data in vec
*/
explicit BER_Decoder(const secure_vector<uint8_t>& vec);
/**
* Set up to BER decode the data in vec
*/
explicit BER_Decoder(const std::vector<uint8_t>& vec);
/**
* Set up to BER decode the data in src
*/
explicit BER_Decoder(DataSource& src);
/**
* Set up to BER decode the data in obj
*/
BER_Decoder(const BER_Object& obj) :
BER_Decoder(obj.bits(), obj.length()) {}
/**
* Set up to BER decode the data in obj
*/
BER_Decoder(BER_Object&& obj) :
BER_Decoder(std::move(obj), nullptr) {}
BER_Decoder(const BER_Decoder& other);
BER_Decoder& operator=(const BER_Decoder&) = delete;
/**
* Get the next object in the data stream.
* If EOF, returns an object with type NO_OBJECT.
*/
BER_Object get_next_object();
BER_Decoder& get_next(BER_Object& ber)
{
ber = get_next_object();
return (*this);
}
/**
* Push an object back onto the stream. Throws if another
* object was previously pushed and has not been subsequently
* read out.
*/
void push_back(const BER_Object& obj);
/**
* Push an object back onto the stream. Throws if another
* object was previously pushed and has not been subsequently
* read out.
*/
void push_back(BER_Object&& obj);
/**
* Return true if there is at least one more item remaining
*/
bool more_items() const;
/**
* Verify the stream is concluded, throws otherwise.
* Returns (*this)
*/
BER_Decoder& verify_end();
/**
* Verify the stream is concluded, throws otherwise.
* Returns (*this)
*/
BER_Decoder& verify_end(const std::string& err_msg);
/**
* Discard any data that remains unread
* Returns (*this)
*/
BER_Decoder& discard_remaining();
/**
* Start decoding a constructed data (sequence or set)
*/
BER_Decoder start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag = UNIVERSAL);
/**
* Finish decoding a constructed data, throws if any data remains.
* Returns the parent of *this (ie the object on which start_cons was called).
*/
BER_Decoder& end_cons();
/**
* Get next object and copy value to POD type
* Asserts value length is equal to POD type sizeof.
* Asserts Type tag and optional Class tag according to parameters.
* Copy value to POD type (struct, union, C-style array, std::array, etc.).
* @param out POD type reference where to copy object value
* @param type_tag ASN1_Tag enum to assert type on object read
* @param class_tag ASN1_Tag enum to assert class on object read (default: CONTEXT_SPECIFIC)
* @return this reference
*/
template <typename T>
BER_Decoder& get_next_value(T &out,
ASN1_Tag type_tag,
ASN1_Tag class_tag = CONTEXT_SPECIFIC)
{
static_assert(std::is_pod<T>::value, "Type must be POD");
BER_Object obj = get_next_object();
obj.assert_is_a(type_tag, class_tag);
if (obj.length() != sizeof(T))
throw BER_Decoding_Error(
"Size mismatch. Object value size is " +
std::to_string(obj.length()) +
"; Output type size is " +
std::to_string(sizeof(T)));
copy_mem(reinterpret_cast<uint8_t*>(&out), obj.bits(), obj.length());
return (*this);
}
/*
* Save all the bytes remaining in the source
*/
template<typename Alloc>
BER_Decoder& raw_bytes(std::vector<uint8_t, Alloc>& out)
{
out.clear();
uint8_t buf;
while(m_source->read_byte(buf))
out.push_back(buf);
return (*this);
}
BER_Decoder& decode_null();
/**
* Decode a BER encoded BOOLEAN
*/
BER_Decoder& decode(bool& out)
{
return decode(out, BOOLEAN, UNIVERSAL);
}
/*
* Decode a small BER encoded INTEGER
*/
BER_Decoder& decode(size_t& out)
{
return decode(out, INTEGER, UNIVERSAL);
}
/*
* Decode a BER encoded INTEGER
*/
BER_Decoder& decode(BigInt& out)
{
return decode(out, INTEGER, UNIVERSAL);
}
std::vector<uint8_t> get_next_octet_string()
{
std::vector<uint8_t> out_vec;
decode(out_vec, OCTET_STRING);
return out_vec;
}
/*
* BER decode a BIT STRING or OCTET STRING
*/
template<typename Alloc>
BER_Decoder& decode(std::vector<uint8_t, Alloc>& out, ASN1_Tag real_type)
{
return decode(out, real_type, real_type, UNIVERSAL);
}
BER_Decoder& decode(bool& v,
ASN1_Tag type_tag,
ASN1_Tag class_tag = CONTEXT_SPECIFIC);
BER_Decoder& decode(size_t& v,
ASN1_Tag type_tag,
ASN1_Tag class_tag = CONTEXT_SPECIFIC);
BER_Decoder& decode(BigInt& v,
ASN1_Tag type_tag,
ASN1_Tag class_tag = CONTEXT_SPECIFIC);
BER_Decoder& decode(std::vector<uint8_t>& v,
ASN1_Tag real_type,
ASN1_Tag type_tag,
ASN1_Tag class_tag = CONTEXT_SPECIFIC);
BER_Decoder& decode(secure_vector<uint8_t>& v,
ASN1_Tag real_type,
ASN1_Tag type_tag,
ASN1_Tag class_tag = CONTEXT_SPECIFIC);
BER_Decoder& decode(class ASN1_Object& obj,
ASN1_Tag type_tag = NO_OBJECT,
ASN1_Tag class_tag = NO_OBJECT);
/**
* Decode an integer value which is typed as an octet string
*/
BER_Decoder& decode_octet_string_bigint(BigInt& b);
uint64_t decode_constrained_integer(ASN1_Tag type_tag,
ASN1_Tag class_tag,
size_t T_bytes);
template<typename T> BER_Decoder& decode_integer_type(T& out)
{
return decode_integer_type<T>(out, INTEGER, UNIVERSAL);
}
template<typename T>
BER_Decoder& decode_integer_type(T& out,
ASN1_Tag type_tag,
ASN1_Tag class_tag = CONTEXT_SPECIFIC)
{
out = static_cast<T>(decode_constrained_integer(type_tag, class_tag, sizeof(out)));
return (*this);
}
template<typename T>
BER_Decoder& decode_optional(T& out,
ASN1_Tag type_tag,
ASN1_Tag class_tag,
const T& default_value = T());
template<typename T>
BER_Decoder& decode_optional_implicit(
T& out,
ASN1_Tag type_tag,
ASN1_Tag class_tag,
ASN1_Tag real_type,
ASN1_Tag real_class,
const T& default_value = T());
template<typename T>
BER_Decoder& decode_list(std::vector<T>& out,
ASN1_Tag type_tag = SEQUENCE,
ASN1_Tag class_tag = UNIVERSAL);
template<typename T>
BER_Decoder& decode_and_check(const T& expected,
const std::string& error_msg)
{
T actual;
decode(actual);
if(actual != expected)
throw Decoding_Error(error_msg);
return (*this);
}
/*
* Decode an OPTIONAL string type
*/
template<typename Alloc>
BER_Decoder& decode_optional_string(std::vector<uint8_t, Alloc>& out,
ASN1_Tag real_type,
uint16_t type_no,
ASN1_Tag class_tag = CONTEXT_SPECIFIC)
{
BER_Object obj = get_next_object();
ASN1_Tag type_tag = static_cast<ASN1_Tag>(type_no);
if(obj.is_a(type_tag, class_tag))
{
if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC))
{
BER_Decoder(std::move(obj)).decode(out, real_type).verify_end();
}
else
{
push_back(std::move(obj));
decode(out, real_type, type_tag, class_tag);
}
}
else
{
out.clear();
push_back(std::move(obj));
}
return (*this);
}
private:
BER_Decoder(BER_Object&& obj, BER_Decoder* parent);
BER_Decoder* m_parent = nullptr;
BER_Object m_pushed;
// either m_data_src.get() or an unowned pointer
DataSource* m_source;
mutable std::unique_ptr<DataSource> m_data_src;
};
/*
* Decode an OPTIONAL or DEFAULT element
*/
template<typename T>
BER_Decoder& BER_Decoder::decode_optional(T& out,
ASN1_Tag type_tag,
ASN1_Tag class_tag,
const T& default_value)
{
BER_Object obj = get_next_object();
if(obj.is_a(type_tag, class_tag))
{
if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC))
{
BER_Decoder(std::move(obj)).decode(out).verify_end();
}
else
{
push_back(std::move(obj));
decode(out, type_tag, class_tag);
}
}
else
{
out = default_value;
push_back(std::move(obj));
}
return (*this);
}
/*
* Decode an OPTIONAL or DEFAULT element
*/
template<typename T>
BER_Decoder& BER_Decoder::decode_optional_implicit(
T& out,
ASN1_Tag type_tag,
ASN1_Tag class_tag,
ASN1_Tag real_type,
ASN1_Tag real_class,
const T& default_value)
{
BER_Object obj = get_next_object();
if(obj.is_a(type_tag, class_tag))
{
obj.set_tagging(real_type, real_class);
push_back(std::move(obj));
decode(out, real_type, real_class);
}
else
{
// Not what we wanted, push it back on the stream
out = default_value;
push_back(std::move(obj));
}
return (*this);
}
/*
* Decode a list of homogenously typed values
*/
template<typename T>
BER_Decoder& BER_Decoder::decode_list(std::vector<T>& vec,
ASN1_Tag type_tag,
ASN1_Tag class_tag)
{
BER_Decoder list = start_cons(type_tag, class_tag);
while(list.more_items())
{
T value;
list.decode(value);
vec.push_back(std::move(value));
}
list.end_cons();
return (*this);
}
}
#endif

View File

@@ -1,405 +0,0 @@
/*
* DER Encoder
* (C) 1999-2007,2018 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#include <botan/der_enc.h>
#include <botan/asn1_obj.h>
#include <botan/bigint.h>
#include <botan/loadstor.h>
#include <botan/internal/bit_ops.h>
#include <algorithm>
namespace Botan {
namespace {
/*
* DER encode an ASN.1 type tag
*/
void encode_tag(std::vector<uint8_t>& encoded_tag,
ASN1_Tag type_tag, ASN1_Tag class_tag)
{
if((class_tag | 0xE0) != 0xE0)
throw Encoding_Error("DER_Encoder: Invalid class tag " +
std::to_string(class_tag));
if(type_tag <= 30)
{
encoded_tag.push_back(static_cast<uint8_t>(type_tag | class_tag));
}
else
{
size_t blocks = high_bit(type_tag) + 6;
blocks = (blocks - (blocks % 7)) / 7;
BOTAN_ASSERT_NOMSG(blocks > 0);
encoded_tag.push_back(static_cast<uint8_t>(class_tag | 0x1F));
for(size_t i = 0; i != blocks - 1; ++i)
encoded_tag.push_back(0x80 | ((type_tag >> 7*(blocks-i-1)) & 0x7F));
encoded_tag.push_back(type_tag & 0x7F);
}
}
/*
* DER encode an ASN.1 length field
*/
void encode_length(std::vector<uint8_t>& encoded_length, size_t length)
{
if(length <= 127)
{
encoded_length.push_back(static_cast<uint8_t>(length));
}
else
{
const size_t bytes_needed = significant_bytes(length);
encoded_length.push_back(static_cast<uint8_t>(0x80 | bytes_needed));
for(size_t i = sizeof(length) - bytes_needed; i < sizeof(length); ++i)
encoded_length.push_back(get_byte(i, length));
}
}
}
DER_Encoder::DER_Encoder(secure_vector<uint8_t>& vec)
{
m_append_output = [&vec](const uint8_t b[], size_t l)
{
vec.insert(vec.end(), b, b + l);
};
}
DER_Encoder::DER_Encoder(std::vector<uint8_t>& vec)
{
m_append_output = [&vec](const uint8_t b[], size_t l)
{
vec.insert(vec.end(), b, b + l);
};
}
/*
* Push the encoded SEQUENCE/SET to the encoder stream
*/
void DER_Encoder::DER_Sequence::push_contents(DER_Encoder& der)
{
const ASN1_Tag real_class_tag = ASN1_Tag(m_class_tag | CONSTRUCTED);
if(m_type_tag == SET)
{
std::sort(m_set_contents.begin(), m_set_contents.end());
for(size_t i = 0; i != m_set_contents.size(); ++i)
m_contents += m_set_contents[i];
m_set_contents.clear();
}
der.add_object(m_type_tag, real_class_tag, m_contents.data(), m_contents.size());
m_contents.clear();
}
/*
* Add an encoded value to the SEQUENCE/SET
*/
void DER_Encoder::DER_Sequence::add_bytes(const uint8_t data[], size_t length)
{
if(m_type_tag == SET)
m_set_contents.push_back(secure_vector<uint8_t>(data, data + length));
else
m_contents += std::make_pair(data, length);
}
void DER_Encoder::DER_Sequence::add_bytes(const uint8_t hdr[], size_t hdr_len,
const uint8_t val[], size_t val_len)
{
if(m_type_tag == SET)
{
secure_vector<uint8_t> m;
m.reserve(hdr_len + val_len);
m += std::make_pair(hdr, hdr_len);
m += std::make_pair(val, val_len);
m_set_contents.push_back(std::move(m));
}
else
{
m_contents += std::make_pair(hdr, hdr_len);
m_contents += std::make_pair(val, val_len);
}
}
/*
* Return the type and class taggings
*/
ASN1_Tag DER_Encoder::DER_Sequence::tag_of() const
{
return ASN1_Tag(m_type_tag | m_class_tag);
}
/*
* DER_Sequence Constructor
*/
DER_Encoder::DER_Sequence::DER_Sequence(ASN1_Tag t1, ASN1_Tag t2) :
m_type_tag(t1), m_class_tag(t2)
{
}
/*
* Return the encoded contents
*/
secure_vector<uint8_t> DER_Encoder::get_contents()
{
if(m_subsequences.size() != 0)
throw Invalid_State("DER_Encoder: Sequence hasn't been marked done");
if(m_append_output)
throw Invalid_State("DER_Encoder Cannot get contents when using output vector");
secure_vector<uint8_t> output;
std::swap(output, m_default_outbuf);
return output;
}
std::vector<uint8_t> DER_Encoder::get_contents_unlocked()
{
if(m_subsequences.size() != 0)
throw Invalid_State("DER_Encoder: Sequence hasn't been marked done");
if(m_append_output)
throw Invalid_State("DER_Encoder Cannot get contents when using output vector");
std::vector<uint8_t> output(m_default_outbuf.begin(), m_default_outbuf.end());
m_default_outbuf.clear();
return output;
}
/*
* Start a new ASN.1 SEQUENCE/SET/EXPLICIT
*/
DER_Encoder& DER_Encoder::start_cons(ASN1_Tag type_tag,
ASN1_Tag class_tag)
{
m_subsequences.push_back(DER_Sequence(type_tag, class_tag));
return (*this);
}
/*
* Finish the current ASN.1 SEQUENCE/SET/EXPLICIT
*/
DER_Encoder& DER_Encoder::end_cons()
{
if(m_subsequences.empty())
throw Invalid_State("DER_Encoder::end_cons: No such sequence");
DER_Sequence last_seq = std::move(m_subsequences[m_subsequences.size()-1]);
m_subsequences.pop_back();
last_seq.push_contents(*this);
return (*this);
}
/*
* Start a new ASN.1 EXPLICIT encoding
*/
DER_Encoder& DER_Encoder::start_explicit(uint16_t type_no)
{
ASN1_Tag type_tag = static_cast<ASN1_Tag>(type_no);
// This would confuse DER_Sequence
if(type_tag == SET)
throw Internal_Error("DER_Encoder.start_explicit(SET) not supported");
return start_cons(type_tag, CONTEXT_SPECIFIC);
}
/*
* Finish the current ASN.1 EXPLICIT encoding
*/
DER_Encoder& DER_Encoder::end_explicit()
{
return end_cons();
}
/*
* Write raw bytes into the stream
*/
DER_Encoder& DER_Encoder::raw_bytes(const uint8_t bytes[], size_t length)
{
if(m_subsequences.size())
{
m_subsequences[m_subsequences.size()-1].add_bytes(bytes, length);
}
else if(m_append_output)
{
m_append_output(bytes, length);
}
else
{
m_default_outbuf += std::make_pair(bytes, length);
}
return (*this);
}
/*
* Write the encoding of the byte(s)
*/
DER_Encoder& DER_Encoder::add_object(ASN1_Tag type_tag, ASN1_Tag class_tag,
const uint8_t rep[], size_t length)
{
std::vector<uint8_t> hdr;
encode_tag(hdr, type_tag, class_tag);
encode_length(hdr, length);
if(m_subsequences.size())
{
m_subsequences[m_subsequences.size()-1].add_bytes(hdr.data(), hdr.size(), rep, length);
}
else if(m_append_output)
{
m_append_output(hdr.data(), hdr.size());
m_append_output(rep, length);
}
else
{
m_default_outbuf += hdr;
m_default_outbuf += std::make_pair(rep, length);
}
return (*this);
}
/*
* Encode a NULL object
*/
DER_Encoder& DER_Encoder::encode_null()
{
return add_object(NULL_TAG, UNIVERSAL, nullptr, 0);
}
/*
* DER encode a BOOLEAN
*/
DER_Encoder& DER_Encoder::encode(bool is_true)
{
return encode(is_true, BOOLEAN, UNIVERSAL);
}
/*
* DER encode a small INTEGER
*/
DER_Encoder& DER_Encoder::encode(size_t n)
{
return encode(BigInt(n), INTEGER, UNIVERSAL);
}
/*
* DER encode a small INTEGER
*/
DER_Encoder& DER_Encoder::encode(const BigInt& n)
{
return encode(n, INTEGER, UNIVERSAL);
}
/*
* Encode this object
*/
DER_Encoder& DER_Encoder::encode(const uint8_t bytes[], size_t length,
ASN1_Tag real_type)
{
return encode(bytes, length, real_type, real_type, UNIVERSAL);
}
/*
* DER encode a BOOLEAN
*/
DER_Encoder& DER_Encoder::encode(bool is_true,
ASN1_Tag type_tag, ASN1_Tag class_tag)
{
uint8_t val = is_true ? 0xFF : 0x00;
return add_object(type_tag, class_tag, &val, 1);
}
/*
* DER encode a small INTEGER
*/
DER_Encoder& DER_Encoder::encode(size_t n,
ASN1_Tag type_tag, ASN1_Tag class_tag)
{
return encode(BigInt(n), type_tag, class_tag);
}
/*
* DER encode an INTEGER
*/
DER_Encoder& DER_Encoder::encode(const BigInt& n,
ASN1_Tag type_tag, ASN1_Tag class_tag)
{
if(n == 0)
return add_object(type_tag, class_tag, 0);
const size_t extra_zero = (n.bits() % 8 == 0) ? 1 : 0;
secure_vector<uint8_t> contents(extra_zero + n.bytes());
BigInt::encode(&contents[extra_zero], n);
if(n < 0)
{
for(size_t i = 0; i != contents.size(); ++i)
contents[i] = ~contents[i];
for(size_t i = contents.size(); i > 0; --i)
if(++contents[i-1])
break;
}
return add_object(type_tag, class_tag, contents);
}
/*
* DER encode an OCTET STRING or BIT STRING
*/
DER_Encoder& DER_Encoder::encode(const uint8_t bytes[], size_t length,
ASN1_Tag real_type,
ASN1_Tag type_tag, ASN1_Tag class_tag)
{
if(real_type != OCTET_STRING && real_type != BIT_STRING)
throw Invalid_Argument("DER_Encoder: Invalid tag for byte/bit string");
if(real_type == BIT_STRING)
{
secure_vector<uint8_t> encoded;
encoded.push_back(0);
encoded += std::make_pair(bytes, length);
return add_object(type_tag, class_tag, encoded);
}
else
return add_object(type_tag, class_tag, bytes, length);
}
DER_Encoder& DER_Encoder::encode(const ASN1_Object& obj)
{
obj.encode_into(*this);
return (*this);
}
/*
* Write the encoding of the byte(s)
*/
DER_Encoder& DER_Encoder::add_object(ASN1_Tag type_tag, ASN1_Tag class_tag,
const std::string& rep_str)
{
const uint8_t* rep = cast_char_ptr_to_uint8(rep_str.data());
const size_t rep_len = rep_str.size();
return add_object(type_tag, class_tag, rep, rep_len);
}
/*
* Write the encoding of the byte
*/
DER_Encoder& DER_Encoder::add_object(ASN1_Tag type_tag,
ASN1_Tag class_tag, uint8_t rep)
{
return add_object(type_tag, class_tag, &rep, 1);
}
}

View File

@@ -1,221 +0,0 @@
/*
* DER Encoder
* (C) 1999-2007,2018 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#ifndef BOTAN_DER_ENCODER_H_
#define BOTAN_DER_ENCODER_H_
#include <botan/asn1_obj.h>
#include <vector>
#include <functional>
namespace Botan {
class BigInt;
class ASN1_Object;
/**
* General DER Encoding Object
*/
class BOTAN_PUBLIC_API(2,0) DER_Encoder final
{
public:
typedef std::function<void (const uint8_t[], size_t)> append_fn;
/**
* DER encode, writing to an internal buffer
* Use get_contents or get_contents_unlocked to read the results
* after all encoding is completed.
*/
DER_Encoder() = default;
/**
* DER encode, writing to @param vec
* If this constructor is used, get_contents* may not be called.
*/
DER_Encoder(secure_vector<uint8_t>& vec);
/**
* DER encode, writing to @param vec
* If this constructor is used, get_contents* may not be called.
*/
DER_Encoder(std::vector<uint8_t>& vec);
/**
* DER encode, calling append to write output
* If this constructor is used, get_contents* may not be called.
*/
DER_Encoder(append_fn append) : m_append_output(append) {}
secure_vector<uint8_t> get_contents();
std::vector<uint8_t> get_contents_unlocked();
DER_Encoder& start_cons(ASN1_Tag type_tag,
ASN1_Tag class_tag = UNIVERSAL);
DER_Encoder& end_cons();
DER_Encoder& start_explicit(uint16_t type_tag);
DER_Encoder& end_explicit();
/**
* Insert raw bytes directly into the output stream
*/
DER_Encoder& raw_bytes(const uint8_t val[], size_t len);
template<typename Alloc>
DER_Encoder& raw_bytes(const std::vector<uint8_t, Alloc>& val)
{
return raw_bytes(val.data(), val.size());
}
DER_Encoder& encode_null();
DER_Encoder& encode(bool b);
DER_Encoder& encode(size_t s);
DER_Encoder& encode(const BigInt& n);
DER_Encoder& encode(const uint8_t val[], size_t len, ASN1_Tag real_type);
template<typename Alloc>
DER_Encoder& encode(const std::vector<uint8_t, Alloc>& vec, ASN1_Tag real_type)
{
return encode(vec.data(), vec.size(), real_type);
}
DER_Encoder& encode(bool b,
ASN1_Tag type_tag,
ASN1_Tag class_tag = CONTEXT_SPECIFIC);
DER_Encoder& encode(size_t s,
ASN1_Tag type_tag,
ASN1_Tag class_tag = CONTEXT_SPECIFIC);
DER_Encoder& encode(const BigInt& n,
ASN1_Tag type_tag,
ASN1_Tag class_tag = CONTEXT_SPECIFIC);
DER_Encoder& encode(const uint8_t v[], size_t len,
ASN1_Tag real_type,
ASN1_Tag type_tag,
ASN1_Tag class_tag = CONTEXT_SPECIFIC);
template<typename Alloc>
DER_Encoder& encode(const std::vector<uint8_t, Alloc>& bytes,
ASN1_Tag real_type,
ASN1_Tag type_tag, ASN1_Tag class_tag)
{
return encode(bytes.data(), bytes.size(),
real_type, type_tag, class_tag);
}
template<typename T>
DER_Encoder& encode_optional(const T& value, const T& default_value)
{
if(value != default_value)
encode(value);
return (*this);
}
template<typename T>
DER_Encoder& encode_list(const std::vector<T>& values)
{
for(size_t i = 0; i != values.size(); ++i)
encode(values[i]);
return (*this);
}
/*
* Request for an object to encode itself to this stream
*/
DER_Encoder& encode(const ASN1_Object& obj);
/*
* Conditionally write some values to the stream
*/
DER_Encoder& encode_if(bool pred, DER_Encoder& enc)
{
if(pred)
return raw_bytes(enc.get_contents());
return (*this);
}
DER_Encoder& encode_if(bool pred, const ASN1_Object& obj)
{
if(pred)
encode(obj);
return (*this);
}
DER_Encoder& add_object(ASN1_Tag type_tag, ASN1_Tag class_tag,
const uint8_t rep[], size_t length);
DER_Encoder& add_object(ASN1_Tag type_tag, ASN1_Tag class_tag,
const std::vector<uint8_t>& rep)
{
return add_object(type_tag, class_tag, rep.data(), rep.size());
}
DER_Encoder& add_object(ASN1_Tag type_tag, ASN1_Tag class_tag,
const secure_vector<uint8_t>& rep)
{
return add_object(type_tag, class_tag, rep.data(), rep.size());
}
DER_Encoder& add_object(ASN1_Tag type_tag, ASN1_Tag class_tag,
const std::string& str);
DER_Encoder& add_object(ASN1_Tag type_tag, ASN1_Tag class_tag,
uint8_t val);
private:
class DER_Sequence final
{
public:
ASN1_Tag tag_of() const;
void push_contents(DER_Encoder& der);
void add_bytes(const uint8_t val[], size_t len);
void add_bytes(const uint8_t hdr[], size_t hdr_len,
const uint8_t val[], size_t val_len);
DER_Sequence(ASN1_Tag, ASN1_Tag);
DER_Sequence(DER_Sequence&& seq)
{
std::swap(m_type_tag, seq.m_type_tag);
std::swap(m_class_tag, seq.m_class_tag);
std::swap(m_contents, seq.m_contents);
std::swap(m_set_contents, seq.m_set_contents);
}
DER_Sequence& operator=(DER_Sequence&& seq)
{
std::swap(m_type_tag, seq.m_type_tag);
std::swap(m_class_tag, seq.m_class_tag);
std::swap(m_contents, seq.m_contents);
std::swap(m_set_contents, seq.m_set_contents);
return (*this);
}
DER_Sequence(const DER_Sequence& seq) = default;
DER_Sequence& operator=(const DER_Sequence& seq) = default;
private:
ASN1_Tag m_type_tag, m_class_tag;
secure_vector<uint8_t> m_contents;
std::vector< secure_vector<uint8_t> > m_set_contents;
};
append_fn m_append_output;
secure_vector<uint8_t> m_default_outbuf;
std::vector<DER_Sequence> m_subsequences;
};
}
#endif

View File

@@ -1,7 +0,0 @@
<defines>
ASN1 -> 20171109
</defines>
<requires>
bigint
</requires>

View File

@@ -1,479 +0,0 @@
/*
* OID maps
*
* This file was automatically generated by ./src/scripts/oids.py on 2018-08-23
*
* All manual edits to this file will be lost. Edit the script
* then regenerate this source file.
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#include <botan/oids.h>
#include <unordered_map>
namespace Botan {
std::unordered_map<std::string, std::string> OIDS::load_oid2str_map()
{
return std::unordered_map<std::string,std::string>{
{ "0.3.4401.5.3.1.9.26", "Camellia-192/GCM" },
{ "0.3.4401.5.3.1.9.46", "Camellia-256/GCM" },
{ "0.3.4401.5.3.1.9.6", "Camellia-128/GCM" },
{ "1.0.14888.3.0.5", "ECKCDSA" },
{ "1.2.156.10197.1.104.100", "SM4/OCB" },
{ "1.2.156.10197.1.104.2", "SM4/CBC" },
{ "1.2.156.10197.1.104.8", "SM4/GCM" },
{ "1.2.156.10197.1.301", "sm2p256v1" },
{ "1.2.156.10197.1.301.1", "SM2" },
{ "1.2.156.10197.1.301.2", "SM2_Kex" },
{ "1.2.156.10197.1.301.3", "SM2_Enc" },
{ "1.2.156.10197.1.401", "SM3" },
{ "1.2.156.10197.1.501", "SM2_Sig/SM3" },
{ "1.2.156.10197.1.504", "RSA/EMSA3(SM3)" },
{ "1.2.250.1.223.101.256.1", "frp256v1" },
{ "1.2.392.200011.61.1.1.1.2", "Camellia-128/CBC" },
{ "1.2.392.200011.61.1.1.1.3", "Camellia-192/CBC" },
{ "1.2.392.200011.61.1.1.1.4", "Camellia-256/CBC" },
{ "1.2.410.200004.1.100.4.3", "ECKCDSA/EMSA1(SHA-1)" },
{ "1.2.410.200004.1.100.4.4", "ECKCDSA/EMSA1(SHA-224)" },
{ "1.2.410.200004.1.100.4.5", "ECKCDSA/EMSA1(SHA-256)" },
{ "1.2.410.200004.1.4", "SEED/CBC" },
{ "1.2.643.2.2.19", "GOST-34.10" },
{ "1.2.643.2.2.3", "GOST-34.10/EMSA1(GOST-R-34.11-94)" },
{ "1.2.643.2.2.35.1", "gost_256A" },
{ "1.2.643.2.2.36.0", "gost_256A" },
{ "1.2.643.7.1.1.2.2", "Streebog-256" },
{ "1.2.643.7.1.1.2.3", "Streebog-512" },
{ "1.2.840.10040.4.1", "DSA" },
{ "1.2.840.10040.4.3", "DSA/EMSA1(SHA-160)" },
{ "1.2.840.10045.2.1", "ECDSA" },
{ "1.2.840.10045.3.1.1", "secp192r1" },
{ "1.2.840.10045.3.1.2", "x962_p192v2" },
{ "1.2.840.10045.3.1.3", "x962_p192v3" },
{ "1.2.840.10045.3.1.4", "x962_p239v1" },
{ "1.2.840.10045.3.1.5", "x962_p239v2" },
{ "1.2.840.10045.3.1.6", "x962_p239v3" },
{ "1.2.840.10045.3.1.7", "secp256r1" },
{ "1.2.840.10045.4.1", "ECDSA/EMSA1(SHA-160)" },
{ "1.2.840.10045.4.3.1", "ECDSA/EMSA1(SHA-224)" },
{ "1.2.840.10045.4.3.2", "ECDSA/EMSA1(SHA-256)" },
{ "1.2.840.10045.4.3.3", "ECDSA/EMSA1(SHA-384)" },
{ "1.2.840.10045.4.3.4", "ECDSA/EMSA1(SHA-512)" },
{ "1.2.840.10046.2.1", "DH" },
{ "1.2.840.113533.7.66.10", "CAST-128/CBC" },
{ "1.2.840.113533.7.66.15", "KeyWrap.CAST-128" },
{ "1.2.840.113549.1.1.1", "RSA" },
{ "1.2.840.113549.1.1.10", "RSA/EMSA4" },
{ "1.2.840.113549.1.1.11", "RSA/EMSA3(SHA-256)" },
{ "1.2.840.113549.1.1.12", "RSA/EMSA3(SHA-384)" },
{ "1.2.840.113549.1.1.13", "RSA/EMSA3(SHA-512)" },
{ "1.2.840.113549.1.1.14", "RSA/EMSA3(SHA-224)" },
{ "1.2.840.113549.1.1.16", "RSA/EMSA3(SHA-512-256)" },
{ "1.2.840.113549.1.1.4", "RSA/EMSA3(MD5)" },
{ "1.2.840.113549.1.1.5", "RSA/EMSA3(SHA-160)" },
{ "1.2.840.113549.1.1.7", "RSA/OAEP" },
{ "1.2.840.113549.1.1.8", "MGF1" },
{ "1.2.840.113549.1.5.12", "PKCS5.PBKDF2" },
{ "1.2.840.113549.1.5.13", "PBE-PKCS5v20" },
{ "1.2.840.113549.1.9.1", "PKCS9.EmailAddress" },
{ "1.2.840.113549.1.9.14", "PKCS9.ExtensionRequest" },
{ "1.2.840.113549.1.9.16.3.18", "ChaCha20Poly1305" },
{ "1.2.840.113549.1.9.16.3.6", "KeyWrap.TripleDES" },
{ "1.2.840.113549.1.9.16.3.8", "Compression.Zlib" },
{ "1.2.840.113549.1.9.2", "PKCS9.UnstructuredName" },
{ "1.2.840.113549.1.9.3", "PKCS9.ContentType" },
{ "1.2.840.113549.1.9.4", "PKCS9.MessageDigest" },
{ "1.2.840.113549.1.9.7", "PKCS9.ChallengePassword" },
{ "1.2.840.113549.2.10", "HMAC(SHA-384)" },
{ "1.2.840.113549.2.11", "HMAC(SHA-512)" },
{ "1.2.840.113549.2.13", "HMAC(SHA-512-256)" },
{ "1.2.840.113549.2.5", "MD5" },
{ "1.2.840.113549.2.7", "HMAC(SHA-160)" },
{ "1.2.840.113549.2.8", "HMAC(SHA-224)" },
{ "1.2.840.113549.2.9", "HMAC(SHA-256)" },
{ "1.2.840.113549.3.7", "TripleDES/CBC" },
{ "1.3.101.110", "Curve25519" },
{ "1.3.101.112", "Ed25519" },
{ "1.3.132.0.10", "secp256k1" },
{ "1.3.132.0.30", "secp160r2" },
{ "1.3.132.0.31", "secp192k1" },
{ "1.3.132.0.32", "secp224k1" },
{ "1.3.132.0.33", "secp224r1" },
{ "1.3.132.0.34", "secp384r1" },
{ "1.3.132.0.35", "secp521r1" },
{ "1.3.132.0.8", "secp160r1" },
{ "1.3.132.0.9", "secp160k1" },
{ "1.3.132.1.12", "ECDH" },
{ "1.3.14.3.2.26", "SHA-160" },
{ "1.3.14.3.2.7", "DES/CBC" },
{ "1.3.36.3.2.1", "RIPEMD-160" },
{ "1.3.36.3.3.1.2", "RSA/EMSA3(RIPEMD-160)" },
{ "1.3.36.3.3.2.5.2.1", "ECGDSA" },
{ "1.3.36.3.3.2.5.4.1", "ECGDSA/EMSA1(RIPEMD-160)" },
{ "1.3.36.3.3.2.5.4.2", "ECGDSA/EMSA1(SHA-160)" },
{ "1.3.36.3.3.2.5.4.3", "ECGDSA/EMSA1(SHA-224)" },
{ "1.3.36.3.3.2.5.4.4", "ECGDSA/EMSA1(SHA-256)" },
{ "1.3.36.3.3.2.5.4.5", "ECGDSA/EMSA1(SHA-384)" },
{ "1.3.36.3.3.2.5.4.6", "ECGDSA/EMSA1(SHA-512)" },
{ "1.3.36.3.3.2.8.1.1.1", "brainpool160r1" },
{ "1.3.36.3.3.2.8.1.1.11", "brainpool384r1" },
{ "1.3.36.3.3.2.8.1.1.13", "brainpool512r1" },
{ "1.3.36.3.3.2.8.1.1.3", "brainpool192r1" },
{ "1.3.36.3.3.2.8.1.1.5", "brainpool224r1" },
{ "1.3.36.3.3.2.8.1.1.7", "brainpool256r1" },
{ "1.3.36.3.3.2.8.1.1.9", "brainpool320r1" },
{ "1.3.6.1.4.1.11591.12.2", "Tiger(24,3)" },
{ "1.3.6.1.4.1.11591.15.1", "OpenPGP.Ed25519" },
{ "1.3.6.1.4.1.11591.4.11", "Scrypt" },
{ "1.3.6.1.4.1.25258.1.3", "McEliece" },
{ "1.3.6.1.4.1.25258.1.5", "XMSS" },
{ "1.3.6.1.4.1.25258.1.6.1", "GOST-34.10/EMSA1(SHA-256)" },
{ "1.3.6.1.4.1.25258.3.1", "Serpent/CBC" },
{ "1.3.6.1.4.1.25258.3.101", "Serpent/GCM" },
{ "1.3.6.1.4.1.25258.3.102", "Twofish/GCM" },
{ "1.3.6.1.4.1.25258.3.2", "Threefish-512/CBC" },
{ "1.3.6.1.4.1.25258.3.2.1", "AES-128/OCB" },
{ "1.3.6.1.4.1.25258.3.2.2", "AES-192/OCB" },
{ "1.3.6.1.4.1.25258.3.2.3", "AES-256/OCB" },
{ "1.3.6.1.4.1.25258.3.2.4", "Serpent/OCB" },
{ "1.3.6.1.4.1.25258.3.2.5", "Twofish/OCB" },
{ "1.3.6.1.4.1.25258.3.2.6", "Camellia-128/OCB" },
{ "1.3.6.1.4.1.25258.3.2.7", "Camellia-192/OCB" },
{ "1.3.6.1.4.1.25258.3.2.8", "Camellia-256/OCB" },
{ "1.3.6.1.4.1.25258.3.3", "Twofish/CBC" },
{ "1.3.6.1.4.1.25258.3.4.1", "AES-128/SIV" },
{ "1.3.6.1.4.1.25258.3.4.2", "AES-192/SIV" },
{ "1.3.6.1.4.1.25258.3.4.3", "AES-256/SIV" },
{ "1.3.6.1.4.1.25258.3.4.4", "Serpent/SIV" },
{ "1.3.6.1.4.1.25258.3.4.5", "Twofish/SIV" },
{ "1.3.6.1.4.1.25258.3.4.6", "Camellia-128/SIV" },
{ "1.3.6.1.4.1.25258.3.4.7", "Camellia-192/SIV" },
{ "1.3.6.1.4.1.25258.3.4.8", "Camellia-256/SIV" },
{ "1.3.6.1.4.1.25258.3.4.9", "SM4/SIV" },
{ "1.3.6.1.4.1.3029.1.2.1", "ElGamal" },
{ "1.3.6.1.4.1.3029.1.5.1", "OpenPGP.Curve25519" },
{ "1.3.6.1.4.1.311.20.2.2", "Microsoft SmartcardLogon" },
{ "1.3.6.1.4.1.311.20.2.3", "Microsoft UPN" },
{ "1.3.6.1.4.1.8301.3.1.2.9.0.38", "secp521r1" },
{ "1.3.6.1.5.5.7.1.1", "PKIX.AuthorityInformationAccess" },
{ "1.3.6.1.5.5.7.3.1", "PKIX.ServerAuth" },
{ "1.3.6.1.5.5.7.3.2", "PKIX.ClientAuth" },
{ "1.3.6.1.5.5.7.3.3", "PKIX.CodeSigning" },
{ "1.3.6.1.5.5.7.3.4", "PKIX.EmailProtection" },
{ "1.3.6.1.5.5.7.3.5", "PKIX.IPsecEndSystem" },
{ "1.3.6.1.5.5.7.3.6", "PKIX.IPsecTunnel" },
{ "1.3.6.1.5.5.7.3.7", "PKIX.IPsecUser" },
{ "1.3.6.1.5.5.7.3.8", "PKIX.TimeStamping" },
{ "1.3.6.1.5.5.7.3.9", "PKIX.OCSPSigning" },
{ "1.3.6.1.5.5.7.48.1", "PKIX.OCSP" },
{ "1.3.6.1.5.5.7.48.1.1", "PKIX.OCSP.BasicResponse" },
{ "1.3.6.1.5.5.7.48.2", "PKIX.CertificateAuthorityIssuers" },
{ "1.3.6.1.5.5.7.8.5", "PKIX.XMPPAddr" },
{ "2.16.840.1.101.3.4.1.2", "AES-128/CBC" },
{ "2.16.840.1.101.3.4.1.22", "AES-192/CBC" },
{ "2.16.840.1.101.3.4.1.25", "KeyWrap.AES-192" },
{ "2.16.840.1.101.3.4.1.26", "AES-192/GCM" },
{ "2.16.840.1.101.3.4.1.27", "AES-192/CCM" },
{ "2.16.840.1.101.3.4.1.42", "AES-256/CBC" },
{ "2.16.840.1.101.3.4.1.45", "KeyWrap.AES-256" },
{ "2.16.840.1.101.3.4.1.46", "AES-256/GCM" },
{ "2.16.840.1.101.3.4.1.47", "AES-256/CCM" },
{ "2.16.840.1.101.3.4.1.5", "KeyWrap.AES-128" },
{ "2.16.840.1.101.3.4.1.6", "AES-128/GCM" },
{ "2.16.840.1.101.3.4.1.7", "AES-128/CCM" },
{ "2.16.840.1.101.3.4.2.1", "SHA-256" },
{ "2.16.840.1.101.3.4.2.10", "SHA-3(512)" },
{ "2.16.840.1.101.3.4.2.11", "SHAKE-128" },
{ "2.16.840.1.101.3.4.2.12", "SHAKE-256" },
{ "2.16.840.1.101.3.4.2.2", "SHA-384" },
{ "2.16.840.1.101.3.4.2.3", "SHA-512" },
{ "2.16.840.1.101.3.4.2.4", "SHA-224" },
{ "2.16.840.1.101.3.4.2.6", "SHA-512-256" },
{ "2.16.840.1.101.3.4.2.7", "SHA-3(224)" },
{ "2.16.840.1.101.3.4.2.8", "SHA-3(256)" },
{ "2.16.840.1.101.3.4.2.9", "SHA-3(384)" },
{ "2.16.840.1.101.3.4.3.1", "DSA/EMSA1(SHA-224)" },
{ "2.16.840.1.101.3.4.3.10", "ECDSA/EMSA1(SHA-3(256))" },
{ "2.16.840.1.101.3.4.3.11", "ECDSA/EMSA1(SHA-3(384))" },
{ "2.16.840.1.101.3.4.3.12", "ECDSA/EMSA1(SHA-3(512))" },
{ "2.16.840.1.101.3.4.3.13", "RSA/EMSA3(SHA-3(224))" },
{ "2.16.840.1.101.3.4.3.14", "RSA/EMSA3(SHA-3(256))" },
{ "2.16.840.1.101.3.4.3.15", "RSA/EMSA3(SHA-3(384))" },
{ "2.16.840.1.101.3.4.3.16", "RSA/EMSA3(SHA-3(512))" },
{ "2.16.840.1.101.3.4.3.2", "DSA/EMSA1(SHA-256)" },
{ "2.16.840.1.101.3.4.3.3", "DSA/EMSA1(SHA-384)" },
{ "2.16.840.1.101.3.4.3.4", "DSA/EMSA1(SHA-512)" },
{ "2.16.840.1.101.3.4.3.5", "DSA/EMSA1(SHA-3(224))" },
{ "2.16.840.1.101.3.4.3.6", "DSA/EMSA1(SHA-3(256))" },
{ "2.16.840.1.101.3.4.3.7", "DSA/EMSA1(SHA-3(384))" },
{ "2.16.840.1.101.3.4.3.8", "DSA/EMSA1(SHA-3(512))" },
{ "2.16.840.1.101.3.4.3.9", "ECDSA/EMSA1(SHA-3(224))" },
{ "2.16.840.1.113730.1.13", "Certificate Comment" },
{ "2.5.29.14", "X509v3.SubjectKeyIdentifier" },
{ "2.5.29.15", "X509v3.KeyUsage" },
{ "2.5.29.17", "X509v3.SubjectAlternativeName" },
{ "2.5.29.18", "X509v3.IssuerAlternativeName" },
{ "2.5.29.19", "X509v3.BasicConstraints" },
{ "2.5.29.20", "X509v3.CRLNumber" },
{ "2.5.29.21", "X509v3.ReasonCode" },
{ "2.5.29.23", "X509v3.HoldInstructionCode" },
{ "2.5.29.24", "X509v3.InvalidityDate" },
{ "2.5.29.28", "X509v3.CRLIssuingDistributionPoint" },
{ "2.5.29.30", "X509v3.NameConstraints" },
{ "2.5.29.31", "X509v3.CRLDistributionPoints" },
{ "2.5.29.32", "X509v3.CertificatePolicies" },
{ "2.5.29.32.0", "X509v3.AnyPolicy" },
{ "2.5.29.35", "X509v3.AuthorityKeyIdentifier" },
{ "2.5.29.36", "X509v3.PolicyConstraints" },
{ "2.5.29.37", "X509v3.ExtendedKeyUsage" },
{ "2.5.4.10", "X520.Organization" },
{ "2.5.4.11", "X520.OrganizationalUnit" },
{ "2.5.4.12", "X520.Title" },
{ "2.5.4.3", "X520.CommonName" },
{ "2.5.4.4", "X520.Surname" },
{ "2.5.4.42", "X520.GivenName" },
{ "2.5.4.43", "X520.Initials" },
{ "2.5.4.44", "X520.GenerationalQualifier" },
{ "2.5.4.46", "X520.DNQualifier" },
{ "2.5.4.5", "X520.SerialNumber" },
{ "2.5.4.6", "X520.Country" },
{ "2.5.4.65", "X520.Pseudonym" },
{ "2.5.4.7", "X520.Locality" },
{ "2.5.4.8", "X520.State" },
{ "2.5.8.1.1", "RSA" }
};
}
std::unordered_map<std::string, OID> OIDS::load_str2oid_map()
{
return std::unordered_map<std::string,OID>{
{ "AES-128/CBC", OID({2,16,840,1,101,3,4,1,2}) },
{ "AES-128/CCM", OID({2,16,840,1,101,3,4,1,7}) },
{ "AES-128/GCM", OID({2,16,840,1,101,3,4,1,6}) },
{ "AES-128/OCB", OID({1,3,6,1,4,1,25258,3,2,1}) },
{ "AES-128/SIV", OID({1,3,6,1,4,1,25258,3,4,1}) },
{ "AES-192/CBC", OID({2,16,840,1,101,3,4,1,22}) },
{ "AES-192/CCM", OID({2,16,840,1,101,3,4,1,27}) },
{ "AES-192/GCM", OID({2,16,840,1,101,3,4,1,26}) },
{ "AES-192/OCB", OID({1,3,6,1,4,1,25258,3,2,2}) },
{ "AES-192/SIV", OID({1,3,6,1,4,1,25258,3,4,2}) },
{ "AES-256/CBC", OID({2,16,840,1,101,3,4,1,42}) },
{ "AES-256/CCM", OID({2,16,840,1,101,3,4,1,47}) },
{ "AES-256/GCM", OID({2,16,840,1,101,3,4,1,46}) },
{ "AES-256/OCB", OID({1,3,6,1,4,1,25258,3,2,3}) },
{ "AES-256/SIV", OID({1,3,6,1,4,1,25258,3,4,3}) },
{ "CAST-128/CBC", OID({1,2,840,113533,7,66,10}) },
{ "Camellia-128/CBC", OID({1,2,392,200011,61,1,1,1,2}) },
{ "Camellia-128/GCM", OID({0,3,4401,5,3,1,9,6}) },
{ "Camellia-128/OCB", OID({1,3,6,1,4,1,25258,3,2,6}) },
{ "Camellia-128/SIV", OID({1,3,6,1,4,1,25258,3,4,6}) },
{ "Camellia-192/CBC", OID({1,2,392,200011,61,1,1,1,3}) },
{ "Camellia-192/GCM", OID({0,3,4401,5,3,1,9,26}) },
{ "Camellia-192/OCB", OID({1,3,6,1,4,1,25258,3,2,7}) },
{ "Camellia-192/SIV", OID({1,3,6,1,4,1,25258,3,4,7}) },
{ "Camellia-256/CBC", OID({1,2,392,200011,61,1,1,1,4}) },
{ "Camellia-256/GCM", OID({0,3,4401,5,3,1,9,46}) },
{ "Camellia-256/OCB", OID({1,3,6,1,4,1,25258,3,2,8}) },
{ "Camellia-256/SIV", OID({1,3,6,1,4,1,25258,3,4,8}) },
{ "Certificate Comment", OID({2,16,840,1,113730,1,13}) },
{ "ChaCha20Poly1305", OID({1,2,840,113549,1,9,16,3,18}) },
{ "Compression.Zlib", OID({1,2,840,113549,1,9,16,3,8}) },
{ "Curve25519", OID({1,3,101,110}) },
{ "DES/CBC", OID({1,3,14,3,2,7}) },
{ "DH", OID({1,2,840,10046,2,1}) },
{ "DSA", OID({1,2,840,10040,4,1}) },
{ "DSA/EMSA1(SHA-160)", OID({1,2,840,10040,4,3}) },
{ "DSA/EMSA1(SHA-224)", OID({2,16,840,1,101,3,4,3,1}) },
{ "DSA/EMSA1(SHA-256)", OID({2,16,840,1,101,3,4,3,2}) },
{ "DSA/EMSA1(SHA-3(224))", OID({2,16,840,1,101,3,4,3,5}) },
{ "DSA/EMSA1(SHA-3(256))", OID({2,16,840,1,101,3,4,3,6}) },
{ "DSA/EMSA1(SHA-3(384))", OID({2,16,840,1,101,3,4,3,7}) },
{ "DSA/EMSA1(SHA-3(512))", OID({2,16,840,1,101,3,4,3,8}) },
{ "DSA/EMSA1(SHA-384)", OID({2,16,840,1,101,3,4,3,3}) },
{ "DSA/EMSA1(SHA-512)", OID({2,16,840,1,101,3,4,3,4}) },
{ "ECDH", OID({1,3,132,1,12}) },
{ "ECDSA", OID({1,2,840,10045,2,1}) },
{ "ECDSA/EMSA1(SHA-160)", OID({1,2,840,10045,4,1}) },
{ "ECDSA/EMSA1(SHA-224)", OID({1,2,840,10045,4,3,1}) },
{ "ECDSA/EMSA1(SHA-256)", OID({1,2,840,10045,4,3,2}) },
{ "ECDSA/EMSA1(SHA-3(224))", OID({2,16,840,1,101,3,4,3,9}) },
{ "ECDSA/EMSA1(SHA-3(256))", OID({2,16,840,1,101,3,4,3,10}) },
{ "ECDSA/EMSA1(SHA-3(384))", OID({2,16,840,1,101,3,4,3,11}) },
{ "ECDSA/EMSA1(SHA-3(512))", OID({2,16,840,1,101,3,4,3,12}) },
{ "ECDSA/EMSA1(SHA-384)", OID({1,2,840,10045,4,3,3}) },
{ "ECDSA/EMSA1(SHA-512)", OID({1,2,840,10045,4,3,4}) },
{ "ECGDSA", OID({1,3,36,3,3,2,5,2,1}) },
{ "ECGDSA/EMSA1(RIPEMD-160)", OID({1,3,36,3,3,2,5,4,1}) },
{ "ECGDSA/EMSA1(SHA-160)", OID({1,3,36,3,3,2,5,4,2}) },
{ "ECGDSA/EMSA1(SHA-224)", OID({1,3,36,3,3,2,5,4,3}) },
{ "ECGDSA/EMSA1(SHA-256)", OID({1,3,36,3,3,2,5,4,4}) },
{ "ECGDSA/EMSA1(SHA-384)", OID({1,3,36,3,3,2,5,4,5}) },
{ "ECGDSA/EMSA1(SHA-512)", OID({1,3,36,3,3,2,5,4,6}) },
{ "ECKCDSA", OID({1,0,14888,3,0,5}) },
{ "ECKCDSA/EMSA1(SHA-1)", OID({1,2,410,200004,1,100,4,3}) },
{ "ECKCDSA/EMSA1(SHA-224)", OID({1,2,410,200004,1,100,4,4}) },
{ "ECKCDSA/EMSA1(SHA-256)", OID({1,2,410,200004,1,100,4,5}) },
{ "Ed25519", OID({1,3,101,112}) },
{ "ElGamal", OID({1,3,6,1,4,1,3029,1,2,1}) },
{ "GOST-34.10", OID({1,2,643,2,2,19}) },
{ "GOST-34.10/EMSA1(GOST-R-34.11-94)", OID({1,2,643,2,2,3}) },
{ "GOST-34.10/EMSA1(SHA-256)", OID({1,3,6,1,4,1,25258,1,6,1}) },
{ "HMAC(SHA-160)", OID({1,2,840,113549,2,7}) },
{ "HMAC(SHA-224)", OID({1,2,840,113549,2,8}) },
{ "HMAC(SHA-256)", OID({1,2,840,113549,2,9}) },
{ "HMAC(SHA-384)", OID({1,2,840,113549,2,10}) },
{ "HMAC(SHA-512)", OID({1,2,840,113549,2,11}) },
{ "HMAC(SHA-512-256)", OID({1,2,840,113549,2,13}) },
{ "KeyWrap.AES-128", OID({2,16,840,1,101,3,4,1,5}) },
{ "KeyWrap.AES-192", OID({2,16,840,1,101,3,4,1,25}) },
{ "KeyWrap.AES-256", OID({2,16,840,1,101,3,4,1,45}) },
{ "KeyWrap.CAST-128", OID({1,2,840,113533,7,66,15}) },
{ "KeyWrap.TripleDES", OID({1,2,840,113549,1,9,16,3,6}) },
{ "MD5", OID({1,2,840,113549,2,5}) },
{ "MGF1", OID({1,2,840,113549,1,1,8}) },
{ "McEliece", OID({1,3,6,1,4,1,25258,1,3}) },
{ "Microsoft SmartcardLogon", OID({1,3,6,1,4,1,311,20,2,2}) },
{ "Microsoft UPN", OID({1,3,6,1,4,1,311,20,2,3}) },
{ "OpenPGP.Curve25519", OID({1,3,6,1,4,1,3029,1,5,1}) },
{ "OpenPGP.Ed25519", OID({1,3,6,1,4,1,11591,15,1}) },
{ "PBE-PKCS5v20", OID({1,2,840,113549,1,5,13}) },
{ "PBES2", OID({1,2,840,113549,1,5,13}) },
{ "PKCS5.PBKDF2", OID({1,2,840,113549,1,5,12}) },
{ "PKCS9.ChallengePassword", OID({1,2,840,113549,1,9,7}) },
{ "PKCS9.ContentType", OID({1,2,840,113549,1,9,3}) },
{ "PKCS9.EmailAddress", OID({1,2,840,113549,1,9,1}) },
{ "PKCS9.ExtensionRequest", OID({1,2,840,113549,1,9,14}) },
{ "PKCS9.MessageDigest", OID({1,2,840,113549,1,9,4}) },
{ "PKCS9.UnstructuredName", OID({1,2,840,113549,1,9,2}) },
{ "PKIX.AuthorityInformationAccess", OID({1,3,6,1,5,5,7,1,1}) },
{ "PKIX.CertificateAuthorityIssuers", OID({1,3,6,1,5,5,7,48,2}) },
{ "PKIX.ClientAuth", OID({1,3,6,1,5,5,7,3,2}) },
{ "PKIX.CodeSigning", OID({1,3,6,1,5,5,7,3,3}) },
{ "PKIX.EmailProtection", OID({1,3,6,1,5,5,7,3,4}) },
{ "PKIX.IPsecEndSystem", OID({1,3,6,1,5,5,7,3,5}) },
{ "PKIX.IPsecTunnel", OID({1,3,6,1,5,5,7,3,6}) },
{ "PKIX.IPsecUser", OID({1,3,6,1,5,5,7,3,7}) },
{ "PKIX.OCSP", OID({1,3,6,1,5,5,7,48,1}) },
{ "PKIX.OCSP.BasicResponse", OID({1,3,6,1,5,5,7,48,1,1}) },
{ "PKIX.OCSPSigning", OID({1,3,6,1,5,5,7,3,9}) },
{ "PKIX.ServerAuth", OID({1,3,6,1,5,5,7,3,1}) },
{ "PKIX.TimeStamping", OID({1,3,6,1,5,5,7,3,8}) },
{ "PKIX.XMPPAddr", OID({1,3,6,1,5,5,7,8,5}) },
{ "RIPEMD-160", OID({1,3,36,3,2,1}) },
{ "RSA", OID({1,2,840,113549,1,1,1}) },
{ "RSA/EMSA3(MD5)", OID({1,2,840,113549,1,1,4}) },
{ "RSA/EMSA3(RIPEMD-160)", OID({1,3,36,3,3,1,2}) },
{ "RSA/EMSA3(SHA-160)", OID({1,2,840,113549,1,1,5}) },
{ "RSA/EMSA3(SHA-224)", OID({1,2,840,113549,1,1,14}) },
{ "RSA/EMSA3(SHA-256)", OID({1,2,840,113549,1,1,11}) },
{ "RSA/EMSA3(SHA-3(224))", OID({2,16,840,1,101,3,4,3,13}) },
{ "RSA/EMSA3(SHA-3(256))", OID({2,16,840,1,101,3,4,3,14}) },
{ "RSA/EMSA3(SHA-3(384))", OID({2,16,840,1,101,3,4,3,15}) },
{ "RSA/EMSA3(SHA-3(512))", OID({2,16,840,1,101,3,4,3,16}) },
{ "RSA/EMSA3(SHA-384)", OID({1,2,840,113549,1,1,12}) },
{ "RSA/EMSA3(SHA-512)", OID({1,2,840,113549,1,1,13}) },
{ "RSA/EMSA3(SHA-512-256)", OID({1,2,840,113549,1,1,16}) },
{ "RSA/EMSA3(SM3)", OID({1,2,156,10197,1,504}) },
{ "RSA/EMSA4", OID({1,2,840,113549,1,1,10}) },
{ "RSA/OAEP", OID({1,2,840,113549,1,1,7}) },
{ "SEED/CBC", OID({1,2,410,200004,1,4}) },
{ "SHA-160", OID({1,3,14,3,2,26}) },
{ "SHA-224", OID({2,16,840,1,101,3,4,2,4}) },
{ "SHA-256", OID({2,16,840,1,101,3,4,2,1}) },
{ "SHA-3(224)", OID({2,16,840,1,101,3,4,2,7}) },
{ "SHA-3(256)", OID({2,16,840,1,101,3,4,2,8}) },
{ "SHA-3(384)", OID({2,16,840,1,101,3,4,2,9}) },
{ "SHA-3(512)", OID({2,16,840,1,101,3,4,2,10}) },
{ "SHA-384", OID({2,16,840,1,101,3,4,2,2}) },
{ "SHA-512", OID({2,16,840,1,101,3,4,2,3}) },
{ "SHA-512-256", OID({2,16,840,1,101,3,4,2,6}) },
{ "SHAKE-128", OID({2,16,840,1,101,3,4,2,11}) },
{ "SHAKE-256", OID({2,16,840,1,101,3,4,2,12}) },
{ "SM2", OID({1,2,156,10197,1,301,1}) },
{ "SM2_Enc", OID({1,2,156,10197,1,301,3}) },
{ "SM2_Kex", OID({1,2,156,10197,1,301,2}) },
{ "SM2_Sig", OID({1,2,156,10197,1,301,1}) },
{ "SM2_Sig/SM3", OID({1,2,156,10197,1,501}) },
{ "SM3", OID({1,2,156,10197,1,401}) },
{ "SM4/CBC", OID({1,2,156,10197,1,104,2}) },
{ "SM4/GCM", OID({1,2,156,10197,1,104,8}) },
{ "SM4/OCB", OID({1,2,156,10197,1,104,100}) },
{ "SM4/SIV", OID({1,3,6,1,4,1,25258,3,4,9}) },
{ "Scrypt", OID({1,3,6,1,4,1,11591,4,11}) },
{ "Serpent/CBC", OID({1,3,6,1,4,1,25258,3,1}) },
{ "Serpent/GCM", OID({1,3,6,1,4,1,25258,3,101}) },
{ "Serpent/OCB", OID({1,3,6,1,4,1,25258,3,2,4}) },
{ "Serpent/SIV", OID({1,3,6,1,4,1,25258,3,4,4}) },
{ "Streebog-256", OID({1,2,643,7,1,1,2,2}) },
{ "Streebog-512", OID({1,2,643,7,1,1,2,3}) },
{ "Threefish-512/CBC", OID({1,3,6,1,4,1,25258,3,2}) },
{ "Tiger(24,3)", OID({1,3,6,1,4,1,11591,12,2}) },
{ "TripleDES/CBC", OID({1,2,840,113549,3,7}) },
{ "Twofish/CBC", OID({1,3,6,1,4,1,25258,3,3}) },
{ "Twofish/GCM", OID({1,3,6,1,4,1,25258,3,102}) },
{ "Twofish/OCB", OID({1,3,6,1,4,1,25258,3,2,5}) },
{ "Twofish/SIV", OID({1,3,6,1,4,1,25258,3,4,5}) },
{ "X509v3.AnyPolicy", OID({2,5,29,32,0}) },
{ "X509v3.AuthorityKeyIdentifier", OID({2,5,29,35}) },
{ "X509v3.BasicConstraints", OID({2,5,29,19}) },
{ "X509v3.CRLDistributionPoints", OID({2,5,29,31}) },
{ "X509v3.CRLIssuingDistributionPoint", OID({2,5,29,28}) },
{ "X509v3.CRLNumber", OID({2,5,29,20}) },
{ "X509v3.CertificatePolicies", OID({2,5,29,32}) },
{ "X509v3.ExtendedKeyUsage", OID({2,5,29,37}) },
{ "X509v3.HoldInstructionCode", OID({2,5,29,23}) },
{ "X509v3.InvalidityDate", OID({2,5,29,24}) },
{ "X509v3.IssuerAlternativeName", OID({2,5,29,18}) },
{ "X509v3.KeyUsage", OID({2,5,29,15}) },
{ "X509v3.NameConstraints", OID({2,5,29,30}) },
{ "X509v3.PolicyConstraints", OID({2,5,29,36}) },
{ "X509v3.ReasonCode", OID({2,5,29,21}) },
{ "X509v3.SubjectAlternativeName", OID({2,5,29,17}) },
{ "X509v3.SubjectKeyIdentifier", OID({2,5,29,14}) },
{ "X520.CommonName", OID({2,5,4,3}) },
{ "X520.Country", OID({2,5,4,6}) },
{ "X520.DNQualifier", OID({2,5,4,46}) },
{ "X520.GenerationalQualifier", OID({2,5,4,44}) },
{ "X520.GivenName", OID({2,5,4,42}) },
{ "X520.Initials", OID({2,5,4,43}) },
{ "X520.Locality", OID({2,5,4,7}) },
{ "X520.Organization", OID({2,5,4,10}) },
{ "X520.OrganizationalUnit", OID({2,5,4,11}) },
{ "X520.Pseudonym", OID({2,5,4,65}) },
{ "X520.SerialNumber", OID({2,5,4,5}) },
{ "X520.State", OID({2,5,4,8}) },
{ "X520.Surname", OID({2,5,4,4}) },
{ "X520.Title", OID({2,5,4,12}) },
{ "XMSS", OID({1,3,6,1,4,1,25258,1,5}) },
{ "brainpool160r1", OID({1,3,36,3,3,2,8,1,1,1}) },
{ "brainpool192r1", OID({1,3,36,3,3,2,8,1,1,3}) },
{ "brainpool224r1", OID({1,3,36,3,3,2,8,1,1,5}) },
{ "brainpool256r1", OID({1,3,36,3,3,2,8,1,1,7}) },
{ "brainpool320r1", OID({1,3,36,3,3,2,8,1,1,9}) },
{ "brainpool384r1", OID({1,3,36,3,3,2,8,1,1,11}) },
{ "brainpool512r1", OID({1,3,36,3,3,2,8,1,1,13}) },
{ "frp256v1", OID({1,2,250,1,223,101,256,1}) },
{ "gost_256A", OID({1,2,643,2,2,35,1}) },
{ "secp160k1", OID({1,3,132,0,9}) },
{ "secp160r1", OID({1,3,132,0,8}) },
{ "secp160r2", OID({1,3,132,0,30}) },
{ "secp192k1", OID({1,3,132,0,31}) },
{ "secp192r1", OID({1,2,840,10045,3,1,1}) },
{ "secp224k1", OID({1,3,132,0,32}) },
{ "secp224r1", OID({1,3,132,0,33}) },
{ "secp256k1", OID({1,3,132,0,10}) },
{ "secp256r1", OID({1,2,840,10045,3,1,7}) },
{ "secp384r1", OID({1,3,132,0,34}) },
{ "secp521r1", OID({1,3,132,0,35}) },
{ "sm2p256v1", OID({1,2,156,10197,1,301}) },
{ "x962_p192v2", OID({1,2,840,10045,3,1,2}) },
{ "x962_p192v3", OID({1,2,840,10045,3,1,3}) },
{ "x962_p239v1", OID({1,2,840,10045,3,1,4}) },
{ "x962_p239v2", OID({1,2,840,10045,3,1,5}) },
{ "x962_p239v3", OID({1,2,840,10045,3,1,6}) }
};
}
}

View File

@@ -1,135 +0,0 @@
/*
* OID Registry
* (C) 1999-2008,2013 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#include <botan/oids.h>
#include <botan/mutex.h>
namespace Botan {
namespace OIDS {
namespace {
class OID_Map final
{
public:
void add_oid(const OID& oid, const std::string& str)
{
add_str2oid(oid, str);
add_oid2str(oid, str);
}
void add_str2oid(const OID& oid, const std::string& str)
{
lock_guard_type<mutex_type> lock(m_mutex);
auto i = m_str2oid.find(str);
if(i == m_str2oid.end())
m_str2oid.insert(std::make_pair(str, oid.as_string()));
}
void add_oid2str(const OID& oid, const std::string& str)
{
const std::string oid_str = oid.as_string();
lock_guard_type<mutex_type> lock(m_mutex);
auto i = m_oid2str.find(oid_str);
if(i == m_oid2str.end())
m_oid2str.insert(std::make_pair(oid_str, str));
}
std::string lookup(const OID& oid)
{
const std::string oid_str = oid.as_string();
lock_guard_type<mutex_type> lock(m_mutex);
auto i = m_oid2str.find(oid_str);
if(i != m_oid2str.end())
return i->second;
return "";
}
OID lookup(const std::string& str)
{
lock_guard_type<mutex_type> lock(m_mutex);
auto i = m_str2oid.find(str);
if(i != m_str2oid.end())
return i->second;
return OID();
}
bool have_oid(const std::string& str)
{
lock_guard_type<mutex_type> lock(m_mutex);
return m_str2oid.find(str) != m_str2oid.end();
}
static OID_Map& global_registry()
{
static OID_Map g_map;
return g_map;
}
private:
OID_Map()
{
m_str2oid = load_str2oid_map();
m_oid2str = load_oid2str_map();
}
mutex_type m_mutex;
std::unordered_map<std::string, OID> m_str2oid;
std::unordered_map<std::string, std::string> m_oid2str;
};
}
void add_oid(const OID& oid, const std::string& name)
{
OID_Map::global_registry().add_oid(oid, name);
}
void add_oidstr(const char* oidstr, const char* name)
{
add_oid(OID(oidstr), name);
}
void add_oid2str(const OID& oid, const std::string& name)
{
OID_Map::global_registry().add_oid2str(oid, name);
}
void add_str2oid(const OID& oid, const std::string& name)
{
OID_Map::global_registry().add_str2oid(oid, name);
}
std::string lookup(const OID& oid)
{
return OID_Map::global_registry().lookup(oid);
}
OID lookup(const std::string& name)
{
return OID_Map::global_registry().lookup(name);
}
bool have_oid(const std::string& name)
{
return OID_Map::global_registry().have_oid(name);
}
bool name_of(const OID& oid, const std::string& name)
{
return (oid == lookup(name));
}
}
}

View File

@@ -1,76 +0,0 @@
/*
* OID Registry
* (C) 1999-2007 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#ifndef BOTAN_OIDS_H_
#define BOTAN_OIDS_H_
#include <botan/asn1_oid.h>
#include <unordered_map>
namespace Botan {
namespace OIDS {
/**
* Register an OID to string mapping.
* @param oid the oid to register
* @param name the name to be associated with the oid
*/
BOTAN_UNSTABLE_API void add_oid(const OID& oid, const std::string& name);
BOTAN_UNSTABLE_API void add_oid2str(const OID& oid, const std::string& name);
BOTAN_UNSTABLE_API void add_str2oid(const OID& oid, const std::string& name);
BOTAN_UNSTABLE_API void add_oidstr(const char* oidstr, const char* name);
std::unordered_map<std::string, std::string> load_oid2str_map();
std::unordered_map<std::string, OID> load_str2oid_map();
/**
* Resolve an OID
* @param oid the OID to look up
* @return name associated with this OID
*/
BOTAN_PUBLIC_API(2,0) std::string lookup(const OID& oid);
/**
* Find the OID to a name. The lookup will be performed in the
* general OID section of the configuration.
* @param name the name to resolve
* @return OID associated with the specified name
*/
BOTAN_PUBLIC_API(2,0) OID lookup(const std::string& name);
inline std::string oid2str(const OID& oid)
{
return lookup(oid);
}
inline OID str2oid(const std::string& name)
{
return lookup(name);
}
/**
* See if an OID exists in the internal table.
* @param oid the oid to check for
* @return true if the oid is registered
*/
BOTAN_UNSTABLE_API bool have_oid(const std::string& oid);
/**
* Tests whether the specified OID stands for the specified name.
* @param oid the OID to check
* @param name the name to check
* @return true if the specified OID stands for the specified name
*/
BOTAN_UNSTABLE_API bool name_of(const OID& oid, const std::string& name);
}
}
#endif

View File

@@ -1,45 +0,0 @@
/*
* A vague catch all include file for Botan
* (C) 1999-2007 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#ifndef BOTAN_BOTAN_H_
#define BOTAN_BOTAN_H_
/*
* There is no real reason for this header to exist beyond historical
* reasons. The application should instead include the specific header
* files that define the interfaces it intends to use.
*
* This header file will be removed in Botan 3.x
*/
#if defined(__GNUC__)
#warning "botan/botan.h is deprecated"
#elif defined(_MSC_VER)
#pragma message ("botan/botan.h is deprecated")
#endif
#include <botan/lookup.h>
#include <botan/version.h>
#include <botan/parsing.h>
#include <botan/init.h>
#include <botan/rng.h>
#include <botan/secmem.h>
#if defined(BOTAN_HAS_AUTO_SEEDING_RNG)
#include <botan/auto_rng.h>
#endif
#if defined(BOTAN_HAS_FILTERS)
#include <botan/filters.h>
#endif
#if defined(BOTAN_HAS_PUBLIC_KEY_CRYPTO)
#include <botan/x509_key.h>
#include <botan/pkcs8.h>
#endif
#endif

View File

@@ -1,184 +0,0 @@
/*
* Buffered Computation
* (C) 1999-2007 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#ifndef BOTAN_BUFFERED_COMPUTATION_H_
#define BOTAN_BUFFERED_COMPUTATION_H_
#include <botan/secmem.h>
#include <botan/loadstor.h>
#include <string>
namespace Botan {
/**
* This class represents any kind of computation which uses an internal
* state, such as hash functions or MACs
*/
class BOTAN_PUBLIC_API(2,0) Buffered_Computation
{
public:
/**
* @return length of the output of this function in bytes
*/
virtual size_t output_length() const = 0;
/**
* Add new input to process.
* @param in the input to process as a byte array
* @param length of param in in bytes
*/
void update(const uint8_t in[], size_t length) { add_data(in, length); }
/**
* Add new input to process.
* @param in the input to process as a secure_vector
*/
void update(const secure_vector<uint8_t>& in)
{
add_data(in.data(), in.size());
}
/**
* Add new input to process.
* @param in the input to process as a std::vector
*/
void update(const std::vector<uint8_t>& in)
{
add_data(in.data(), in.size());
}
/**
* Add an integer in big-endian order
* @param in the value
*/
template<typename T> void update_be(const T in)
{
for(size_t i = 0; i != sizeof(T); ++i)
{
uint8_t b = get_byte(i, in);
add_data(&b, 1);
}
}
/**
* Add new input to process.
* @param str the input to process as a std::string. Will be interpreted
* as a byte array based on the strings encoding.
*/
void update(const std::string& str)
{
add_data(cast_char_ptr_to_uint8(str.data()), str.size());
}
/**
* Process a single byte.
* @param in the byte to process
*/
void update(uint8_t in) { add_data(&in, 1); }
/**
* Complete the computation and retrieve the
* final result.
* @param out The byte array to be filled with the result.
* Must be of length output_length()
*/
void final(uint8_t out[]) { final_result(out); }
/**
* Complete the computation and retrieve the
* final result.
* @return secure_vector holding the result
*/
secure_vector<uint8_t> final()
{
secure_vector<uint8_t> output(output_length());
final_result(output.data());
return output;
}
std::vector<uint8_t> final_stdvec()
{
std::vector<uint8_t> output(output_length());
final_result(output.data());
return output;
}
template<typename Alloc>
void final(std::vector<uint8_t, Alloc>& out)
{
out.resize(output_length());
final_result(out.data());
}
/**
* Update and finalize computation. Does the same as calling update()
* and final() consecutively.
* @param in the input to process as a byte array
* @param length the length of the byte array
* @result the result of the call to final()
*/
secure_vector<uint8_t> process(const uint8_t in[], size_t length)
{
add_data(in, length);
return final();
}
/**
* Update and finalize computation. Does the same as calling update()
* and final() consecutively.
* @param in the input to process
* @result the result of the call to final()
*/
secure_vector<uint8_t> process(const secure_vector<uint8_t>& in)
{
add_data(in.data(), in.size());
return final();
}
/**
* Update and finalize computation. Does the same as calling update()
* and final() consecutively.
* @param in the input to process
* @result the result of the call to final()
*/
secure_vector<uint8_t> process(const std::vector<uint8_t>& in)
{
add_data(in.data(), in.size());
return final();
}
/**
* Update and finalize computation. Does the same as calling update()
* and final() consecutively.
* @param in the input to process as a string
* @result the result of the call to final()
*/
secure_vector<uint8_t> process(const std::string& in)
{
update(in);
return final();
}
virtual ~Buffered_Computation() = default;
private:
/**
* Add more data to the computation
* @param input is an input buffer
* @param length is the length of input in bytes
*/
virtual void add_data(const uint8_t input[], size_t length) = 0;
/**
* Write the final output to out
* @param out is an output buffer of output_length()
*/
virtual void final_result(uint8_t out[]) = 0;
};
}
#endif

View File

@@ -1,17 +0,0 @@
<header:public>
botan.h
buf_comp.h
init.h
key_spec.h
lookup.h
secmem.h
scan_name.h
sym_algo.h
symkey.h
</header:public>
<requires>
hex
rng
utils
</requires>

View File

@@ -1,33 +0,0 @@
/*
* Library Initialization
* (C) 1999-2008,2015 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#ifndef BOTAN_LIBRARY_INITIALIZER_H_
#define BOTAN_LIBRARY_INITIALIZER_H_
#include <botan/types.h>
#include <string>
namespace Botan {
/*
* Previously botan had state whose lifetime had to be explicitly
* managed by the application. As of 1.11.14 this is no longer the
* case, and this class is no longer needed and kept only for backwards
* compatibility.
*/
class BOTAN_PUBLIC_API(2,0) BOTAN_DEPRECATED("LibraryInitializer is no longer required") LibraryInitializer final
{
public:
explicit LibraryInitializer(const std::string& /*ignored*/ = "") { }
static void initialize(const std::string& /*ignored*/ = "") {}
static void deinitialize() {}
};
}
#endif

View File

@@ -1,100 +0,0 @@
/*
* Symmetric Key Length Specification
* (C) 2010 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#ifndef BOTAN_KEY_LEN_SPECIFICATION_H_
#define BOTAN_KEY_LEN_SPECIFICATION_H_
#include <botan/types.h>
namespace Botan {
/**
* Represents the length requirements on an algorithm key
*/
class BOTAN_PUBLIC_API(2,0) Key_Length_Specification final
{
public:
/**
* Constructor for fixed length keys
* @param keylen the supported key length
*/
explicit Key_Length_Specification(size_t keylen) :
m_min_keylen(keylen),
m_max_keylen(keylen),
m_keylen_mod(1)
{
}
/**
* Constructor for variable length keys
* @param min_k the smallest supported key length
* @param max_k the largest supported key length
* @param k_mod the number of bytes the key must be a multiple of
*/
Key_Length_Specification(size_t min_k,
size_t max_k,
size_t k_mod = 1) :
m_min_keylen(min_k),
m_max_keylen(max_k ? max_k : min_k),
m_keylen_mod(k_mod)
{
}
/**
* @param length is a key length in bytes
* @return true iff this length is a valid length for this algo
*/
bool valid_keylength(size_t length) const
{
return ((length >= m_min_keylen) &&
(length <= m_max_keylen) &&
(length % m_keylen_mod == 0));
}
/**
* @return minimum key length in bytes
*/
size_t minimum_keylength() const
{
return m_min_keylen;
}
/**
* @return maximum key length in bytes
*/
size_t maximum_keylength() const
{
return m_max_keylen;
}
/**
* @return key length multiple in bytes
*/
size_t keylength_multiple() const
{
return m_keylen_mod;
}
/*
* Multiplies all length requirements with the given factor
* @param n the multiplication factor
* @return a key length specification multiplied by the factor
*/
Key_Length_Specification multiple(size_t n) const
{
return Key_Length_Specification(n * m_min_keylen,
n * m_max_keylen,
n * m_keylen_mod);
}
private:
size_t m_min_keylen, m_max_keylen, m_keylen_mod;
};
}
#endif

View File

@@ -1,177 +0,0 @@
/*
* Algorithm Lookup
* (C) 1999-2007,2015 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#ifndef BOTAN_LOOKUP_H_
#define BOTAN_LOOKUP_H_
#include <botan/build.h>
#include <botan/exceptn.h>
#include <string>
#include <vector>
#include <memory>
#if defined(BOTAN_HAS_BLOCK_CIPHER)
#include <botan/block_cipher.h>
#endif
#if defined(BOTAN_HAS_STREAM_CIPHER)
#include <botan/stream_cipher.h>
#endif
#if defined(BOTAN_HAS_HASH)
#include <botan/hash.h>
#endif
#if defined(BOTAN_HAS_MAC)
#include <botan/mac.h>
#endif
namespace Botan {
/*
* As of 1.11.26 this header is deprecated. Instead use the calls T::create and
* T::providers (as demonstrated in the implementation below).
*/
/*
* Get an algorithm object
* NOTE: these functions create and return new objects, letting the
* caller assume ownership of them
*/
#if defined(BOTAN_HAS_BLOCK_CIPHER)
/**
* Block cipher factory method.
*
* @param algo_spec the name of the desired block cipher
* @param provider the provider to use
* @return pointer to the block cipher object
*/
BOTAN_DEPRECATED("Use BlockCipher::create")
inline BlockCipher* get_block_cipher(const std::string& algo_spec,
const std::string& provider = "")
{
return BlockCipher::create(algo_spec, provider).release();
}
BOTAN_DEPRECATED("Use BlockCipher::create_or_throw")
inline std::unique_ptr<BlockCipher> make_block_cipher(const std::string& algo_spec,
const std::string& provider = "")
{
return BlockCipher::create_or_throw(algo_spec, provider);
}
BOTAN_DEPRECATED("Use BlockCipher::providers")
inline std::vector<std::string> get_block_cipher_providers(const std::string& algo_spec)
{
return BlockCipher::providers(algo_spec);
}
#endif
#if defined(BOTAN_HAS_STREAM_CIPHER)
/**
* Stream cipher factory method.
*
* @param algo_spec the name of the desired stream cipher
* @param provider the provider to use
* @return pointer to the stream cipher object
*/
BOTAN_DEPRECATED("Use StreamCipher::create")
inline StreamCipher* get_stream_cipher(const std::string& algo_spec,
const std::string& provider = "")
{
return StreamCipher::create(algo_spec, provider).release();
}
BOTAN_DEPRECATED("Use StreamCipher::create_or_throw")
inline std::unique_ptr<StreamCipher> make_stream_cipher(const std::string& algo_spec,
const std::string& provider = "")
{
return StreamCipher::create_or_throw(algo_spec, provider);
}
BOTAN_DEPRECATED("Use StreamCipher::providers")
inline std::vector<std::string> get_stream_cipher_providers(const std::string& algo_spec)
{
return StreamCipher::providers(algo_spec);
}
#endif
#if defined(BOTAN_HAS_HASH)
/**
* Hash function factory method.
*
* @param algo_spec the name of the desired hash function
* @param provider the provider to use
* @return pointer to the hash function object
*/
BOTAN_DEPRECATED("Use HashFunction::create")
inline HashFunction* get_hash_function(const std::string& algo_spec,
const std::string& provider = "")
{
return HashFunction::create(algo_spec, provider).release();
}
BOTAN_DEPRECATED("Use HashFunction::create_or_throw")
inline std::unique_ptr<HashFunction> make_hash_function(const std::string& algo_spec,
const std::string& provider = "")
{
return HashFunction::create_or_throw(algo_spec, provider);
}
BOTAN_DEPRECATED("Use HashFunction::create")
inline HashFunction* get_hash(const std::string& algo_spec,
const std::string& provider = "")
{
return HashFunction::create(algo_spec, provider).release();
}
BOTAN_DEPRECATED("Use HashFunction::providers")
inline std::vector<std::string> get_hash_function_providers(const std::string& algo_spec)
{
return HashFunction::providers(algo_spec);
}
#endif
#if defined(BOTAN_HAS_MAC)
/**
* MAC factory method.
*
* @param algo_spec the name of the desired MAC
* @param provider the provider to use
* @return pointer to the MAC object
*/
BOTAN_DEPRECATED("MessageAuthenticationCode::create")
inline MessageAuthenticationCode* get_mac(const std::string& algo_spec,
const std::string& provider = "")
{
return MessageAuthenticationCode::create(algo_spec, provider).release();
}
BOTAN_DEPRECATED("MessageAuthenticationCode::create_or_throw")
inline std::unique_ptr<MessageAuthenticationCode> make_message_auth(const std::string& algo_spec,
const std::string& provider = "")
{
return MessageAuthenticationCode::create(algo_spec, provider);
}
BOTAN_DEPRECATED("MessageAuthenticationCode::providers")
inline std::vector<std::string> get_mac_providers(const std::string& algo_spec)
{
return MessageAuthenticationCode::providers(algo_spec);
}
#endif
}
#endif

View File

@@ -1,144 +0,0 @@
/*
* SCAN Name Abstraction
* (C) 2008-2009,2015 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#include <botan/scan_name.h>
#include <botan/parsing.h>
#include <botan/exceptn.h>
namespace Botan {
namespace {
std::string make_arg(
const std::vector<std::pair<size_t, std::string> >& name, size_t start)
{
std::string output = name[start].second;
size_t level = name[start].first;
size_t paren_depth = 0;
for(size_t i = start + 1; i != name.size(); ++i)
{
if(name[i].first <= name[start].first)
break;
if(name[i].first > level)
{
output += "(" + name[i].second;
++paren_depth;
}
else if(name[i].first < level)
{
output += ")," + name[i].second;
--paren_depth;
}
else
{
if(output[output.size() - 1] != '(')
output += ",";
output += name[i].second;
}
level = name[i].first;
}
for(size_t i = 0; i != paren_depth; ++i)
output += ")";
return output;
}
}
SCAN_Name::SCAN_Name(const char* algo_spec) : SCAN_Name(std::string(algo_spec))
{
}
SCAN_Name::SCAN_Name(std::string algo_spec) : m_orig_algo_spec(algo_spec), m_alg_name(), m_args(), m_mode_info()
{
std::vector<std::pair<size_t, std::string> > name;
size_t level = 0;
std::pair<size_t, std::string> accum = std::make_pair(level, "");
const std::string decoding_error = "Bad SCAN name '" + algo_spec + "': ";
for(size_t i = 0; i != algo_spec.size(); ++i)
{
char c = algo_spec[i];
if(c == '/' || c == ',' || c == '(' || c == ')')
{
if(c == '(')
++level;
else if(c == ')')
{
if(level == 0)
throw Decoding_Error(decoding_error + "Mismatched parens");
--level;
}
if(c == '/' && level > 0)
accum.second.push_back(c);
else
{
if(accum.second != "")
name.push_back(accum);
accum = std::make_pair(level, "");
}
}
else
accum.second.push_back(c);
}
if(accum.second != "")
name.push_back(accum);
if(level != 0)
throw Decoding_Error(decoding_error + "Missing close paren");
if(name.size() == 0)
throw Decoding_Error(decoding_error + "Empty name");
m_alg_name = name[0].second;
bool in_modes = false;
for(size_t i = 1; i != name.size(); ++i)
{
if(name[i].first == 0)
{
m_mode_info.push_back(make_arg(name, i));
in_modes = true;
}
else if(name[i].first == 1 && !in_modes)
m_args.push_back(make_arg(name, i));
}
}
std::string SCAN_Name::arg(size_t i) const
{
if(i >= arg_count())
throw Invalid_Argument("SCAN_Name::arg " + std::to_string(i) +
" out of range for '" + as_string() + "'");
return m_args[i];
}
std::string SCAN_Name::arg(size_t i, const std::string& def_value) const
{
if(i >= arg_count())
return def_value;
return m_args[i];
}
size_t SCAN_Name::arg_as_integer(size_t i, size_t def_value) const
{
if(i >= arg_count())
return def_value;
return to_u32bit(m_args[i]);
}
}

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