├── Dockerfile ├── LICENSE ├── README.md ├── cmake ├── CMakeLists.txt ├── OsslCryptoEngine │ └── CMakeLists.txt ├── patches │ └── CMakeLists.txt ├── platform │ └── CMakeLists.txt ├── toolchain_arm.cmake └── tpm │ └── CMakeLists.txt ├── documents ├── 116 │ ├── TPM Rev 2.0 Part 1 - Architecture 01.16.pdf │ ├── TPM Rev 2.0 Part 1 - Architecture 01.16.txt │ ├── TPM Rev 2.0 Part 2 - Structures 01.16.pdf │ ├── TPM Rev 2.0 Part 2 - Structures 01.16.txt │ ├── TPM Rev 2.0 Part 2 - Structures 01.16.txt.patch │ ├── TPM Rev 2.0 Part 3 - Commands 01.16-code.pdf │ ├── TPM Rev 2.0 Part 3 - Commands 01.16-code.txt │ ├── TPM Rev 2.0 Part 4 - Supporting Routines 01.16-code.pdf │ ├── TPM Rev 2.0 Part 4 - Supporting Routines 01.16-code.txt │ └── TPM Rev 2.0 Part 4 - Supporting Routines 01.16-code.txt.patch └── 138 │ ├── TPM Rev 2.0 Part 1 - Architecture 01.38.txt │ ├── TPM Rev 2.0 Part 2 - Structures 01.38.txt │ ├── TPM Rev 2.0 Part 3 - Commands 01.38-code.txt │ ├── TPM Rev 2.0 Part 4 - Supporting Routines 01.38-code.txt │ ├── TPM-Rev-2.0-Part-1-Architecture-01.38.pdf │ ├── TPM-Rev-2.0-Part-2-Structures-01.38.pdf │ ├── TPM-Rev-2.0-Part-3-Commands-01.38-code.pdf │ └── TPM-Rev-2.0-Part-4-Supporting-Routines-01.38-code.pdf ├── lib ├── OpenSSL Copyright.txt ├── arm │ ├── README │ ├── libcrypto.a │ └── libssl.a ├── libeay32.lib ├── openssl │ ├── aes.h │ ├── asn1.h │ ├── asn1_mac.h │ ├── asn1t.h │ ├── bio.h │ ├── blowfish.h │ ├── bn.h │ ├── buffer.h │ ├── camellia.h │ ├── cast.h │ ├── cmac.h │ ├── cms.h │ ├── comp.h │ ├── conf.h │ ├── conf_api.h │ ├── crypto.h │ ├── des.h │ ├── des_old.h │ ├── dh.h │ ├── dsa.h │ ├── dso.h │ ├── dtls1.h │ ├── e_os2.h │ ├── ebcdic.h │ ├── ec.h │ ├── ec_lcl.h │ ├── ecdh.h │ ├── ecdsa.h │ ├── engine.h │ ├── err.h │ ├── evp.h │ ├── hmac.h │ ├── idea.h │ ├── krb5_asn.h │ ├── kssl.h │ ├── lhash.h │ ├── md4.h │ ├── md5.h │ ├── mdc2.h │ ├── modes.h │ ├── obj_mac.h │ ├── objects.h │ ├── ocsp.h │ ├── opensslconf.h │ ├── opensslv.h │ ├── ossl_typ.h │ ├── pem.h │ ├── pem2.h │ ├── pkcs12.h │ ├── pkcs7.h │ ├── pqueue.h │ ├── rand.h │ ├── rc2.h │ ├── rc4.h │ ├── ripemd.h │ ├── rsa.h │ ├── safestack.h │ ├── seed.h │ ├── sha.h │ ├── srp.h │ ├── srtp.h │ ├── ssl.h │ ├── ssl2.h │ ├── ssl23.h │ ├── ssl3.h │ ├── stack.h │ ├── symhacks.h │ ├── tls1.h │ ├── ts.h │ ├── txt_db.h │ ├── ui.h │ ├── ui_compat.h │ ├── whrlpool.h │ ├── x509.h │ ├── x509_vfy.h │ └── x509v3.h ├── x86-64 │ ├── libcrypto.a │ └── libssl.a └── x86 │ ├── libcrypto.a │ └── libssl.a ├── patches ├── 116 │ ├── CpriRSA.c.patch │ ├── CryptoEngine.h.patch │ ├── Entropy.c.patch │ ├── LocalityPlat.c.patch │ ├── NVMem.c.patch │ ├── NV_UndefineSpaceSpecial.c.patch │ ├── OsslCryptoEngine.h.patch │ ├── SessionProcess.c.patch │ ├── SessionProcess_fp.h.patch │ ├── TPMCmdp.c.patch │ ├── TPMCmds.c.patch │ ├── TcpServer.c.patch │ └── TpmBuildSwitches.h.patch └── 138 │ ├── CreateLoaded.c.patch │ ├── CryptSym.c.patch │ ├── Global.h.patch │ ├── Implementation.h.patch │ ├── Manufacture.c.patch │ ├── Platform_fp.h.patch │ ├── Simulator_fp.h.patch │ ├── TPMB.h.patch │ ├── TPMCmdp.c.patch │ ├── TPMCmds.c.patch │ ├── TPM_Types.h.patch │ ├── TcpServer.c.patch │ └── TpmTcpProtocol.h.patch └── scripts ├── README ├── main.py ├── modules ├── __init__.py ├── comment.py ├── constants.py ├── data_structures.py ├── extractors │ ├── __init__.py │ ├── commands_extractor.py │ ├── fodt │ │ ├── __init__.py │ │ ├── tpm2_part3_commands_fodt.py │ │ ├── tpm2_part4_spt_routines_annex_fodt.py │ │ ├── tpm2_part4_spt_routines_fodt.py │ │ ├── tpm2_part4_spt_routines_header_files_fodt.py │ │ ├── tpm2_partx_extraction_navigator_fodt.py │ │ ├── tpm2_partx_license_extractor_fodt.py │ │ └── tpm2_partx_table_extractor_fodt.py │ ├── license_extractor.py │ ├── pdf │ │ ├── __init__.py │ │ ├── tpm2_part3_commands_pdf.py │ │ ├── tpm2_part4_spt_routines_annex_pdf.py │ │ ├── tpm2_part4_spt_routines_header_files_pdf.py │ │ ├── tpm2_part4_spt_routines_pdf.py │ │ ├── tpm2_partx_extraction_navigator_pdf.py │ │ ├── tpm2_partx_license_extractor_pdf.py │ │ └── tpm2_partx_table_extractor_pdf.py │ ├── spt_routines_extractor.py │ └── table_extractor.py ├── file_handling.py ├── part2_structures │ ├── __init__.py │ ├── marshal │ │ ├── __init__.py │ │ ├── tpm2_partx_marshal.py │ │ ├── tpm2_partx_marshal_advanced_type.py │ │ ├── tpm2_partx_marshal_array.py │ │ ├── tpm2_partx_marshal_bits_table.py │ │ ├── tpm2_partx_marshal_interface_table.py │ │ ├── tpm2_partx_marshal_simple_type.py │ │ ├── tpm2_partx_marshal_structure_table.py │ │ ├── tpm2_partx_marshal_templates.py │ │ ├── tpm2_partx_marshal_union_table.py │ │ └── tpm2_partx_type_mapping.py │ ├── tpm2_part2_structures.py │ ├── tpm2_part2_structures_alg_ids.py │ └── tpm2_part2_structures_types.py ├── part3_commands │ ├── __init__.py │ ├── tpm2_part3_command_attributes_h.py │ ├── tpm2_part3_command_dispatcher.py │ ├── tpm2_part3_command_dispatcher_templates.py │ ├── tpm2_part3_commands.py │ ├── tpm2_part3_commands_fp.py │ ├── tpm2_part3_commands_h.py │ ├── tpm2_part3_commands_prototypes.py │ ├── tpm2_part3_commands_prototypes_templates.py │ ├── tpm2_part3_handle_process.py │ └── tpm2_part3_handle_process_templates.py ├── part4_spt_routines │ ├── __init__.py │ ├── tpm2_part4_spt_routines.py │ ├── tpm2_part4_spt_routines_annex.py │ ├── tpm2_part4_spt_routines_header_files.py │ └── tpm2_part4_spt_routines_prototypes.py ├── prototypes │ ├── __init__.py │ ├── tpm2_partx_prototype_component.py │ ├── tpm2_partx_prototype_file.py │ ├── tpm2_partx_prototype_functions.py │ └── tpm2_partx_prototype_modifiers.py └── utils.py └── settings.py /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu 2 | 3 | # install ubuntu packages 4 | RUN apt-get update 5 | RUN apt-get install -y cmake python-bs4 python-pip python-dev 6 | RUN pip install pyastyle 7 | 8 | # prepare working directory 9 | ADD . /usr/local/tpm 10 | WORKDIR /usr/local/tpm 11 | 12 | # change settings 13 | RUN echo 'SET = True' >> scripts/settings.py 14 | 15 | # prepare build 16 | RUN mkdir -p build 17 | WORKDIR /usr/local/tpm/build 18 | 19 | # extract source 20 | RUN cmake -G "Unix Makefiles" ../cmake -DCMAKE_BUILD_TYPE=Debug -DSPEC_VERSION=116 21 | 22 | # build 23 | RUN make 24 | 25 | # expose ports 26 | EXPOSE 2321 27 | EXPOSE 2322 28 | 29 | # cmd 30 | ENTRYPOINT ["/usr/local/tpm/build/Simulator"] 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Steffen Wagner 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | 8 | 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. 9 | 10 | 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. 11 | -------------------------------------------------------------------------------- /cmake/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | project(simulator) 4 | 5 | include_directories(../src/include 6 | ../src/platform/include 7 | ../src/platform/include/prototypes 8 | ../src/tpm/include 9 | ../src/tpm/include/prototypes 10 | ../src/simulator/include 11 | ../src/simulator/include/prototypes 12 | ../src/OsslCryptoEngine 13 | ../lib) 14 | 15 | FILE(GLOB sub-src ../src/*) 16 | set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${sub-src}") 17 | 18 | #set(VERSION "01.16" CACHE STRING "01.16") 19 | set(SPEC_VERSION "116" CACHE STRING "116") 20 | 21 | if (UNIX) 22 | string(ASCII 27 Esc) 23 | set(ColorReset "${Esc}[m") 24 | set(Red "${Esc}[31m") 25 | set(Green "${Esc}[32m") 26 | set(Yellow "${Esc}[33m") 27 | set(Blue "${Esc}[34m") 28 | set(Magenta "${Esc}[35m") 29 | set(Cyan "${Esc}[36m") 30 | set(White "${Esc}[37m") 31 | 32 | MESSAGE("${Green}Extracting source code for the TPM simulator version ${SPEC_VERSION} (this may take a while)${ColorReset}") 33 | execute_process(WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/../scripts 34 | COMMAND python main.py ${SPEC_VERSION} 35 | RESULT_VARIABLE ret_var) 36 | 37 | if (${ret_var}) 38 | if (${ret_var} EQUAL 1) 39 | MESSAGE(FATAL_ERROR "${Red}ERROR: Please update settings.py in the directory 'script'${ColorReset}") 40 | endif() 41 | if (${ret_var} GREATER 1) 42 | MESSAGE(FATAL_ERROR "${Red}FATAL ERROR: ${ret_var}${ColorReset}") 43 | endif() 44 | endif() 45 | MESSAGE("${Green}Extraction finished${ColorReset}\n") 46 | 47 | # PATCH FILES 48 | add_subdirectory(patches) 49 | 50 | endif() 51 | 52 | # BUILD LIBRARIES 53 | add_subdirectory(platform) 54 | 55 | #if (${SPEC_VERSION} LESS "138") 56 | MESSAGE("${Green}Creating OsslCryptoEngine for the TPM simulator version ${SPEC_VERSION}${ColorReset}") 57 | add_subdirectory(OsslCryptoEngine) 58 | #endif() 59 | 60 | add_subdirectory(tpm) 61 | 62 | # BUILD SIMULATOR 63 | file(GLOB SIMULATOR_SOURCE_FILES "../src/simulator/*.c") 64 | file(GLOB_RECURSE SIMULATOR_HEADER_FILES "../src/tpm/include/*.h") 65 | include_directories(../src/include ../src/tpm/include/prototypes) 66 | add_executable(Simulator ${SIMULATOR_SOURCE_FILES} ${SIMULATOR_HEADER_FILES}) 67 | 68 | add_dependencies(Simulator platform TPM) 69 | #if (${SPEC_VERSION} LESS "138") 70 | MESSAGE("${Green}Adding OsslCryptoEngine dependency for the TPM simulator version ${SPEC_VERSION}${ColorReset}") 71 | add_dependencies(Simulator CryptoEngine) 72 | #endif() 73 | 74 | 75 | 76 | 77 | if(WIN32) 78 | set(PLATFORM_LIB "${CMAKE_CURRENT_BINARY_DIR}/platform/Debug/platform.lib") 79 | 80 | if (${SPEC_VERSION} LESS "138") 81 | set(CRYPTOENGINE_LIB "${CMAKE_CURRENT_BINARY_DIR}/OsslCryptoEngine/Debug/CryptoEngine.lib") 82 | endif() 83 | 84 | set(TPM_LIB "${CMAKE_CURRENT_BINARY_DIR}/tpm/Debug/TPM.lib") 85 | endif() 86 | if (UNIX) 87 | set(PLATFORM_LIB "${CMAKE_CURRENT_BINARY_DIR}/platform/libplatform.so") 88 | 89 | # if (${SPEC_VERSION} LESS "138") 90 | set(CRYPTOENGINE_LIB "${CMAKE_CURRENT_BINARY_DIR}/OsslCryptoEngine/libCryptoEngine.so") 91 | # endif() 92 | 93 | set(TPM_LIB "${CMAKE_CURRENT_BINARY_DIR}/tpm/libTPM.so") 94 | endif() 95 | target_link_libraries(Simulator ${PLATFORM_LIB} ${CRYPTOENGINE_LIB} ${TPM_LIB}) 96 | 97 | 98 | if (WIN32) 99 | target_link_libraries(Simulator wsock32 ws2_32 Rpcrt4) 100 | endif() 101 | if (UNIX) 102 | target_link_libraries(Simulator pthread dl) 103 | endif() 104 | 105 | # INSTALLATION 106 | install (TARGETS Simulator DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/bin) 107 | if(WIN32) 108 | install (FILES "${CMAKE_CURRENT_BINARY_DIR}/platform/Debug/platform.dll" 109 | DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/bin) 110 | install (FILES "${CMAKE_CURRENT_BINARY_DIR}/OsslCryptoEngine/Debug/CryptoEngine.dll" 111 | DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/bin) 112 | install (FILES "${CMAKE_CURRENT_BINARY_DIR}/tpm/Debug/TPM.dll" 113 | DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/bin) 114 | endif() 115 | -------------------------------------------------------------------------------- /cmake/OsslCryptoEngine/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB SOURCE_FILES "../../src/OsslCryptoEngine/*.c") 2 | 3 | file(GLOB HEADER_FILES "../../lib/openssl/*.h") 4 | file(GLOB HEADER_FILES2 "../../src/include/*.h") 5 | 6 | include_directories(../../lib) 7 | 8 | add_library(CryptoEngine SHARED ${SOURCE_FILES} ${HEADER_FILES} ${HEADER_FILES2}) 9 | add_dependencies(CryptoEngine platform) 10 | 11 | if(CROSS OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm") 12 | target_link_libraries(CryptoEngine "${CMAKE_SOURCE_DIR}/../lib/arm/libcrypto.a") 13 | target_link_libraries(CryptoEngine "${CMAKE_SOURCE_DIR}/../lib/arm/libssl.a") 14 | else(CROSS OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm") 15 | if(WIN32) 16 | target_link_libraries(CryptoEngine "${CMAKE_SOURCE_DIR}/../lib/libeay32.lib") 17 | endif() 18 | if(UNIX) 19 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 20 | target_link_libraries(CryptoEngine "${CMAKE_SOURCE_DIR}/../lib/x86-64/libcrypto.a") 21 | target_link_libraries(CryptoEngine "${CMAKE_SOURCE_DIR}/../lib/x86-64/libssl.a") 22 | else(CMAKE_SIZEOF_VOID_P EQUAL 8) 23 | target_link_libraries(CryptoEngine "${CMAKE_SOURCE_DIR}/../lib/x86/libcrypto.a") 24 | target_link_libraries(CryptoEngine "${CMAKE_SOURCE_DIR}/../lib/x86/libssl.a") 25 | endif(CMAKE_SIZEOF_VOID_P EQUAL 8) 26 | endif() 27 | endif(CROSS OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm") 28 | 29 | if(WIN32) 30 | target_link_libraries(CryptoEngine 31 | "${CMAKE_CURRENT_BINARY_DIR}/../platform/Debug/platform.lib") 32 | endif() 33 | if(UNIX) 34 | target_link_libraries(CryptoEngine 35 | "${CMAKE_CURRENT_BINARY_DIR}/../platform/libplatform.so") 36 | endif() 37 | -------------------------------------------------------------------------------- /cmake/patches/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | MESSAGE("${Green}Patching files${ColorReset}\n") 2 | 3 | file(GLOB PATCH_FILES "../../patches/${SPEC_VERSION}/*.patch") 4 | 5 | FIND_PROGRAM(PATCH_BIN NAMES patch PATHS /usr/bin/ /bin) 6 | 7 | if(PATCH_BIN STREQUAL PATCH_BIN-NOTFOUND) 8 | MESSAGE(FATAL_ERROR "${Red}Error: patch binaries not found. Please install the patch package.${ColorReset}\n") 9 | else() 10 | MESSAGE(STATUS "${Green}Patch binaries found.${ColorReset}\n") 11 | endif() 12 | 13 | foreach(ITR ${PATCH_FILES}) 14 | MESSAGE("Attempting to apply patch file '${ITR}'") 15 | execute_process(WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/../src 16 | COMMAND patch -p1 -r - --no-backup-if-mismatch -s -N --ignore-whitespace 17 | INPUT_FILE ${ITR} 18 | RESULT_VARIABLE ret_var 19 | OUTPUT_VARIABLE out) 20 | if (${out} MATCHES ".*FAILED") 21 | MESSAGE(STATUS "${Red}Error in patch '${ITR}':${ColorReset}") 22 | MESSAGE(STATUS "${Red}${out}${ColorReset}") 23 | endif() 24 | MESSAGE("${Green}Patch file successfully applied${ColorReset}\n") 25 | endforeach() 26 | 27 | MESSAGE("${Green}Patching finished${ColorReset}\n") 28 | -------------------------------------------------------------------------------- /cmake/platform/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB SOURCE_FILES "../../src/platform/*.c") 2 | 3 | add_library(platform SHARED ${SOURCE_FILES}) -------------------------------------------------------------------------------- /cmake/toolchain_arm.cmake: -------------------------------------------------------------------------------- 1 | SET(CMAKE_SYSTEM_NAME Linux) 2 | #SET(CMAKE_SYSTEM_VERSION 1) 3 | #set(CMAKE_SYSTEM_PROCESSOR cross-arm) 4 | set(CROSS 1 BOOL) 5 | 6 | # specify the cross compiler 7 | SET(CMAKE_C_COMPILER /usr/bin/arm-linux-gnueabihf-gcc) 8 | #SET(CMAKE_CXX_COMPILER /usr/bin/arm-linux-gnueabihf-g++) 9 | 10 | # where is the target environment 11 | #SET(CMAKE_FIND_ROOT_PATH /opt/eldk-2007-01-19/ppc_74xx /home/alex/eldk-ppc74xx-inst) 12 | 13 | # search for programs in the build host directories 14 | #SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 15 | 16 | # for libraries and headers in the target directories 17 | #SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 18 | #SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 19 | -------------------------------------------------------------------------------- /cmake/tpm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB_RECURSE TPM_SOURCE_FILES "../../src/tpm/*.c") 2 | file(GLOB_RECURSE TPM_SOURCE_FILES2 "../../src/OsslCryptoEngine/*.c") 3 | file(GLOB_RECURSE TPM_HEADER_FILES "../../src/tpm/*.h") 4 | file(GLOB_RECURSE TPM_HEADER_FILES2 "../../src/include/*.h") 5 | 6 | SET(GCC_COMPILE_FLAGS "-DSPEC_VERSION=${SPEC_VERSION}") 7 | add_definitions(${GCC_COMPILE_FLAGS}) 8 | SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COMPILE_FLAGS}" ) 9 | 10 | list(REMOVE_ITEM TPM_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../src/tpm/include/CommandDispatchData.c) 11 | list(REMOVE_ITEM TPM_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../src/tpm/include/CommandAttributeData.c) 12 | if (${SPEC_VERSION} EQUAL "138") 13 | list(REMOVE_ITEM TPM_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../src/tpm/crypt/CryptDataEcc.c) 14 | endif() 15 | include_directories(../../src/tpm/include ../../src/tpm/include/prototypes) 16 | 17 | if (${SPEC_VERSION} LESS "138") 18 | add_library(TPM SHARED ${TPM_SOURCE_FILES} 19 | ${TPM_HEADER_FILES} ${TPM_HEADER_FILES2}) 20 | endif() 21 | if ((${SPEC_VERSION} GREATER "138") OR (${SPEC_VERSION} EQUAL "138")) 22 | add_library(TPM SHARED ${TPM_SOURCE_FILES} ${TPM_SOURCE_FILES2} 23 | ${TPM_HEADER_FILES} ${TPM_HEADER_FILES2}) 24 | endif() 25 | 26 | target_compile_options(TPM PRIVATE -DSPEC_VERSION=${SPEC_VERSION}) 27 | if (${SPEC_VERSION} LESS "138") 28 | add_dependencies(TPM CryptoEngine) 29 | endif() 30 | add_dependencies(TPM platform) 31 | 32 | if(WIN32) 33 | set(PLATFORM_LIB "${CMAKE_CURRENT_BINARY_DIR}/../platform/Debug/platform.lib") 34 | set(CRYPTOENGINE_LIB "${CMAKE_CURRENT_BINARY_DIR}/../OsslCryptoEngine/Debug/CryptoEngine.lib") 35 | endif() 36 | if(UNIX) 37 | set(PLATFORM_LIB "${CMAKE_CURRENT_BINARY_DIR}/../platform/libplatform.so") 38 | set(CRYPTOENGINE_LIB "${CMAKE_CURRENT_BINARY_DIR}/../OsslCryptoEngine/libCryptoEngine.so") 39 | set(TEST_LINKER_LIB "-ldl") 40 | endif() 41 | if (${SPEC_VERSION} LESS "138") 42 | target_link_libraries(TPM ${CRYPTOENGINE_LIB}) 43 | endif() 44 | target_link_libraries(TPM ${PLATFORM_LIB} ${TEST_LINKER_LIB}) 45 | if ((${SPEC_VERSION} GREATER "138") OR (${SPEC_VERSION} EQUAL "138")) 46 | if(UNIX) 47 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 48 | MESSAGE("Link x86-64 openssl to simulator: ${CMAKE_SOURCE_DIR}/../lib/x86-64") 49 | target_link_libraries(TPM "${CMAKE_SOURCE_DIR}/../lib/x86-64/libcrypto.a") 50 | target_link_libraries(TPM "${CMAKE_SOURCE_DIR}/../lib/x86-64/libssl.a") 51 | else(CMAKE_SIZEOF_VOID_P EQUAL 8) 52 | MESSAGE("Link x86 openssl to simulator: ${CMAKE_SOURCE_DIR}/../lib/x86") 53 | target_link_libraries(TPM "${CMAKE_SOURCE_DIR}/../lib/x86/libcrypto.a") 54 | target_link_libraries(TPM "${CMAKE_SOURCE_DIR}/../lib/x86/libssl.a") 55 | endif(CMAKE_SIZEOF_VOID_P EQUAL 8) 56 | endif() 57 | endif() 58 | 59 | -------------------------------------------------------------------------------- /documents/116/TPM Rev 2.0 Part 1 - Architecture 01.16.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwagnr/tpm2simulator/e45324eba268723d39856111e7933c5c76238481/documents/116/TPM Rev 2.0 Part 1 - Architecture 01.16.pdf -------------------------------------------------------------------------------- /documents/116/TPM Rev 2.0 Part 1 - Architecture 01.16.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwagnr/tpm2simulator/e45324eba268723d39856111e7933c5c76238481/documents/116/TPM Rev 2.0 Part 1 - Architecture 01.16.txt -------------------------------------------------------------------------------- /documents/116/TPM Rev 2.0 Part 2 - Structures 01.16.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwagnr/tpm2simulator/e45324eba268723d39856111e7933c5c76238481/documents/116/TPM Rev 2.0 Part 2 - Structures 01.16.pdf -------------------------------------------------------------------------------- /documents/116/TPM Rev 2.0 Part 3 - Commands 01.16-code.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwagnr/tpm2simulator/e45324eba268723d39856111e7933c5c76238481/documents/116/TPM Rev 2.0 Part 3 - Commands 01.16-code.pdf -------------------------------------------------------------------------------- /documents/116/TPM Rev 2.0 Part 3 - Commands 01.16-code.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwagnr/tpm2simulator/e45324eba268723d39856111e7933c5c76238481/documents/116/TPM Rev 2.0 Part 3 - Commands 01.16-code.txt -------------------------------------------------------------------------------- /documents/116/TPM Rev 2.0 Part 4 - Supporting Routines 01.16-code.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwagnr/tpm2simulator/e45324eba268723d39856111e7933c5c76238481/documents/116/TPM Rev 2.0 Part 4 - Supporting Routines 01.16-code.pdf -------------------------------------------------------------------------------- /documents/116/TPM Rev 2.0 Part 4 - Supporting Routines 01.16-code.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwagnr/tpm2simulator/e45324eba268723d39856111e7933c5c76238481/documents/116/TPM Rev 2.0 Part 4 - Supporting Routines 01.16-code.txt -------------------------------------------------------------------------------- /documents/116/TPM Rev 2.0 Part 4 - Supporting Routines 01.16-code.txt.patch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwagnr/tpm2simulator/e45324eba268723d39856111e7933c5c76238481/documents/116/TPM Rev 2.0 Part 4 - Supporting Routines 01.16-code.txt.patch -------------------------------------------------------------------------------- /documents/138/TPM Rev 2.0 Part 1 - Architecture 01.38.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwagnr/tpm2simulator/e45324eba268723d39856111e7933c5c76238481/documents/138/TPM Rev 2.0 Part 1 - Architecture 01.38.txt -------------------------------------------------------------------------------- /documents/138/TPM-Rev-2.0-Part-1-Architecture-01.38.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwagnr/tpm2simulator/e45324eba268723d39856111e7933c5c76238481/documents/138/TPM-Rev-2.0-Part-1-Architecture-01.38.pdf -------------------------------------------------------------------------------- /documents/138/TPM-Rev-2.0-Part-2-Structures-01.38.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwagnr/tpm2simulator/e45324eba268723d39856111e7933c5c76238481/documents/138/TPM-Rev-2.0-Part-2-Structures-01.38.pdf -------------------------------------------------------------------------------- /documents/138/TPM-Rev-2.0-Part-3-Commands-01.38-code.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwagnr/tpm2simulator/e45324eba268723d39856111e7933c5c76238481/documents/138/TPM-Rev-2.0-Part-3-Commands-01.38-code.pdf -------------------------------------------------------------------------------- /documents/138/TPM-Rev-2.0-Part-4-Supporting-Routines-01.38-code.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwagnr/tpm2simulator/e45324eba268723d39856111e7933c5c76238481/documents/138/TPM-Rev-2.0-Part-4-Supporting-Routines-01.38-code.pdf -------------------------------------------------------------------------------- /lib/OpenSSL Copyright.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Originally written by Bodo Moeller for the OpenSSL project. 3 | */ 4 | /* ==================================================================== 5 | * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in 16 | * the documentation and/or other materials provided with the 17 | * distribution. 18 | * 19 | * 3. All advertising materials mentioning features or use of this 20 | * software must display the following acknowledgment: 21 | * "This product includes software developed by the OpenSSL Project 22 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 23 | * 24 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 25 | * endorse or promote products derived from this software without 26 | * prior written permission. For written permission, please contact 27 | * openssl-core@openssl.org. 28 | * 29 | * 5. Products derived from this software may not be called "OpenSSL" 30 | * nor may "OpenSSL" appear in their names without prior written 31 | * permission of the OpenSSL Project. 32 | * 33 | * 6. Redistributions of any form whatsoever must retain the following 34 | * acknowledgment: 35 | * "This product includes software developed by the OpenSSL Project 36 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" 37 | * 38 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 39 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 40 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 41 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 42 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 43 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 44 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 45 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 46 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 47 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 48 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 49 | * OF THE POSSIBILITY OF SUCH DAMAGE. 50 | * ==================================================================== 51 | * 52 | * This product includes cryptographic software written by Eric Young 53 | * (eay@cryptsoft.com). This product includes software written by Tim 54 | * Hudson (tjh@cryptsoft.com). 55 | * 56 | */ 57 | /* ==================================================================== 58 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 59 | * 60 | * Portions of the attached software ("Contribution") are developed by 61 | * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project. 62 | * 63 | * The Contribution is licensed pursuant to the OpenSSL open source 64 | * license provided above. 65 | * 66 | * The elliptic curve binary polynomial software is originally written by 67 | * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories. 68 | * 69 | */ 70 | -------------------------------------------------------------------------------- /lib/arm/README: -------------------------------------------------------------------------------- 1 | Cross-compile libssl for ARM: 2 | ============================= 3 | 4 | 1) Clone openssl git repository: 5 | # git clone git://git.openssl.org/openssl.git 6 | 7 | 2) Configure openssl for ARM: 8 | # ./Configure linux-generic32 shared -DL_ENDIAN 9 | 10 | 3) Compile for ARM: 11 | # make CC=arm-linux-gnueabihf-gcc RANLIB=arm-linux-gnueabihf-ranlib LD=arm-linux-gnueabihf-ld MAKEDEPPROG=arm-linux-gnueabihf-gcc PROCESSOR=ARM 12 | -------------------------------------------------------------------------------- /lib/arm/libcrypto.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwagnr/tpm2simulator/e45324eba268723d39856111e7933c5c76238481/lib/arm/libcrypto.a -------------------------------------------------------------------------------- /lib/arm/libssl.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwagnr/tpm2simulator/e45324eba268723d39856111e7933c5c76238481/lib/arm/libssl.a -------------------------------------------------------------------------------- /lib/libeay32.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwagnr/tpm2simulator/e45324eba268723d39856111e7933c5c76238481/lib/libeay32.lib -------------------------------------------------------------------------------- /lib/openssl/cast.h: -------------------------------------------------------------------------------- 1 | /* crypto/cast/cast.h */ 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_CAST_H 60 | # define HEADER_CAST_H 61 | 62 | #ifdef __cplusplus 63 | extern "C" { 64 | #endif 65 | 66 | # include 67 | 68 | # ifdef OPENSSL_NO_CAST 69 | # error CAST is disabled. 70 | # endif 71 | 72 | # define CAST_ENCRYPT 1 73 | # define CAST_DECRYPT 0 74 | 75 | # define CAST_LONG unsigned int 76 | 77 | # define CAST_BLOCK 8 78 | # define CAST_KEY_LENGTH 16 79 | 80 | typedef struct cast_key_st { 81 | CAST_LONG data[32]; 82 | int short_key; /* Use reduced rounds for short key */ 83 | } CAST_KEY; 84 | 85 | # ifdef OPENSSL_FIPS 86 | void private_CAST_set_key(CAST_KEY *key, int len, const unsigned char *data); 87 | # endif 88 | void CAST_set_key(CAST_KEY *key, int len, const unsigned char *data); 89 | void CAST_ecb_encrypt(const unsigned char *in, unsigned char *out, 90 | const CAST_KEY *key, int enc); 91 | void CAST_encrypt(CAST_LONG *data, const CAST_KEY *key); 92 | void CAST_decrypt(CAST_LONG *data, const CAST_KEY *key); 93 | void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out, 94 | long length, const CAST_KEY *ks, unsigned char *iv, 95 | int enc); 96 | void CAST_cfb64_encrypt(const unsigned char *in, unsigned char *out, 97 | long length, const CAST_KEY *schedule, 98 | unsigned char *ivec, int *num, int enc); 99 | void CAST_ofb64_encrypt(const unsigned char *in, unsigned char *out, 100 | long length, const CAST_KEY *schedule, 101 | unsigned char *ivec, int *num); 102 | 103 | #ifdef __cplusplus 104 | } 105 | #endif 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /lib/openssl/cmac.h: -------------------------------------------------------------------------------- 1 | /* crypto/cmac/cmac.h */ 2 | /* 3 | * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 4 | * project. 5 | */ 6 | /* ==================================================================== 7 | * Copyright (c) 2010 The OpenSSL Project. All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in 18 | * the documentation and/or other materials provided with the 19 | * distribution. 20 | * 21 | * 3. All advertising materials mentioning features or use of this 22 | * software must display the following acknowledgment: 23 | * "This product includes software developed by the OpenSSL Project 24 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" 25 | * 26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 27 | * endorse or promote products derived from this software without 28 | * prior written permission. For written permission, please contact 29 | * licensing@OpenSSL.org. 30 | * 31 | * 5. Products derived from this software may not be called "OpenSSL" 32 | * nor may "OpenSSL" appear in their names without prior written 33 | * permission of the OpenSSL Project. 34 | * 35 | * 6. Redistributions of any form whatsoever must retain the following 36 | * acknowledgment: 37 | * "This product includes software developed by the OpenSSL Project 38 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" 39 | * 40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 51 | * OF THE POSSIBILITY OF SUCH DAMAGE. 52 | * ==================================================================== 53 | */ 54 | 55 | #ifndef HEADER_CMAC_H 56 | # define HEADER_CMAC_H 57 | 58 | #ifdef __cplusplus 59 | extern "C" { 60 | #endif 61 | 62 | # include 63 | 64 | /* Opaque */ 65 | typedef struct CMAC_CTX_st CMAC_CTX; 66 | 67 | CMAC_CTX *CMAC_CTX_new(void); 68 | void CMAC_CTX_cleanup(CMAC_CTX *ctx); 69 | void CMAC_CTX_free(CMAC_CTX *ctx); 70 | EVP_CIPHER_CTX *CMAC_CTX_get0_cipher_ctx(CMAC_CTX *ctx); 71 | int CMAC_CTX_copy(CMAC_CTX *out, const CMAC_CTX *in); 72 | 73 | int CMAC_Init(CMAC_CTX *ctx, const void *key, size_t keylen, 74 | const EVP_CIPHER *cipher, ENGINE *impl); 75 | int CMAC_Update(CMAC_CTX *ctx, const void *data, size_t dlen); 76 | int CMAC_Final(CMAC_CTX *ctx, unsigned char *out, size_t *poutlen); 77 | int CMAC_resume(CMAC_CTX *ctx); 78 | 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | #endif 83 | -------------------------------------------------------------------------------- /lib/openssl/comp.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef HEADER_COMP_H 3 | # define HEADER_COMP_H 4 | 5 | # include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | typedef struct comp_ctx_st COMP_CTX; 12 | 13 | typedef struct comp_method_st { 14 | int type; /* NID for compression library */ 15 | const char *name; /* A text string to identify the library */ 16 | int (*init) (COMP_CTX *ctx); 17 | void (*finish) (COMP_CTX *ctx); 18 | int (*compress) (COMP_CTX *ctx, 19 | unsigned char *out, unsigned int olen, 20 | unsigned char *in, unsigned int ilen); 21 | int (*expand) (COMP_CTX *ctx, 22 | unsigned char *out, unsigned int olen, 23 | unsigned char *in, unsigned int ilen); 24 | /* 25 | * The following two do NOTHING, but are kept for backward compatibility 26 | */ 27 | long (*ctrl) (void); 28 | long (*callback_ctrl) (void); 29 | } COMP_METHOD; 30 | 31 | struct comp_ctx_st { 32 | COMP_METHOD *meth; 33 | unsigned long compress_in; 34 | unsigned long compress_out; 35 | unsigned long expand_in; 36 | unsigned long expand_out; 37 | CRYPTO_EX_DATA ex_data; 38 | }; 39 | 40 | COMP_CTX *COMP_CTX_new(COMP_METHOD *meth); 41 | void COMP_CTX_free(COMP_CTX *ctx); 42 | int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen, 43 | unsigned char *in, int ilen); 44 | int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen, 45 | unsigned char *in, int ilen); 46 | COMP_METHOD *COMP_rle(void); 47 | COMP_METHOD *COMP_zlib(void); 48 | void COMP_zlib_cleanup(void); 49 | 50 | # ifdef HEADER_BIO_H 51 | # ifdef ZLIB 52 | BIO_METHOD *BIO_f_zlib(void); 53 | # endif 54 | # endif 55 | 56 | /* BEGIN ERROR CODES */ 57 | /* 58 | * The following lines are auto generated by the script mkerr.pl. Any changes 59 | * made after this point may be overwritten when the script is next run. 60 | */ 61 | void ERR_load_COMP_strings(void); 62 | 63 | /* Error codes for the COMP functions. */ 64 | 65 | /* Function codes. */ 66 | # define COMP_F_BIO_ZLIB_FLUSH 99 67 | # define COMP_F_BIO_ZLIB_NEW 100 68 | # define COMP_F_BIO_ZLIB_READ 101 69 | # define COMP_F_BIO_ZLIB_WRITE 102 70 | 71 | /* Reason codes. */ 72 | # define COMP_R_ZLIB_DEFLATE_ERROR 99 73 | # define COMP_R_ZLIB_INFLATE_ERROR 100 74 | # define COMP_R_ZLIB_NOT_SUPPORTED 101 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | #endif 80 | -------------------------------------------------------------------------------- /lib/openssl/conf_api.h: -------------------------------------------------------------------------------- 1 | /* conf_api.h */ 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_CONF_API_H 60 | # define HEADER_CONF_API_H 61 | 62 | # include 63 | # include 64 | 65 | #ifdef __cplusplus 66 | extern "C" { 67 | #endif 68 | 69 | /* Up until OpenSSL 0.9.5a, this was new_section */ 70 | CONF_VALUE *_CONF_new_section(CONF *conf, const char *section); 71 | /* Up until OpenSSL 0.9.5a, this was get_section */ 72 | CONF_VALUE *_CONF_get_section(const CONF *conf, const char *section); 73 | /* Up until OpenSSL 0.9.5a, this was CONF_get_section */ 74 | STACK_OF(CONF_VALUE) *_CONF_get_section_values(const CONF *conf, 75 | const char *section); 76 | 77 | int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value); 78 | char *_CONF_get_string(const CONF *conf, const char *section, 79 | const char *name); 80 | long _CONF_get_number(const CONF *conf, const char *section, 81 | const char *name); 82 | 83 | int _CONF_new_data(CONF *conf); 84 | void _CONF_free_data(CONF *conf); 85 | 86 | #ifdef __cplusplus 87 | } 88 | #endif 89 | #endif 90 | -------------------------------------------------------------------------------- /lib/openssl/ebcdic.h: -------------------------------------------------------------------------------- 1 | /* crypto/ebcdic.h */ 2 | 3 | #ifndef HEADER_EBCDIC_H 4 | # define HEADER_EBCDIC_H 5 | 6 | # include 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | /* Avoid name clashes with other applications */ 13 | # define os_toascii _openssl_os_toascii 14 | # define os_toebcdic _openssl_os_toebcdic 15 | # define ebcdic2ascii _openssl_ebcdic2ascii 16 | # define ascii2ebcdic _openssl_ascii2ebcdic 17 | 18 | extern const unsigned char os_toascii[256]; 19 | extern const unsigned char os_toebcdic[256]; 20 | void *ebcdic2ascii(void *dest, const void *srce, size_t count); 21 | void *ascii2ebcdic(void *dest, const void *srce, size_t count); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | #endif 27 | -------------------------------------------------------------------------------- /lib/openssl/hmac.h: -------------------------------------------------------------------------------- 1 | /* crypto/hmac/hmac.h */ 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | #ifndef HEADER_HMAC_H 59 | # define HEADER_HMAC_H 60 | 61 | # include 62 | 63 | # ifdef OPENSSL_NO_HMAC 64 | # error HMAC is disabled. 65 | # endif 66 | 67 | # include 68 | 69 | # define HMAC_MAX_MD_CBLOCK 128/* largest known is SHA512 */ 70 | 71 | #ifdef __cplusplus 72 | extern "C" { 73 | #endif 74 | 75 | typedef struct hmac_ctx_st { 76 | const EVP_MD *md; 77 | EVP_MD_CTX md_ctx; 78 | EVP_MD_CTX i_ctx; 79 | EVP_MD_CTX o_ctx; 80 | unsigned int key_length; 81 | unsigned char key[HMAC_MAX_MD_CBLOCK]; 82 | int key_init; 83 | } HMAC_CTX; 84 | 85 | # define HMAC_size(e) (EVP_MD_size((e)->md)) 86 | 87 | void HMAC_CTX_init(HMAC_CTX *ctx); 88 | void HMAC_CTX_cleanup(HMAC_CTX *ctx); 89 | 90 | /* deprecated */ 91 | # define HMAC_cleanup(ctx) HMAC_CTX_cleanup(ctx) 92 | 93 | /* deprecated */ 94 | int HMAC_Init(HMAC_CTX *ctx, const void *key, int len, const EVP_MD *md); 95 | int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, 96 | const EVP_MD *md, ENGINE *impl); 97 | int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len); 98 | int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len); 99 | unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len, 100 | const unsigned char *d, size_t n, unsigned char *md, 101 | unsigned int *md_len); 102 | int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx); 103 | 104 | void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags); 105 | 106 | #ifdef __cplusplus 107 | } 108 | #endif 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /lib/openssl/idea.h: -------------------------------------------------------------------------------- 1 | /* crypto/idea/idea.h */ 2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_IDEA_H 60 | # define HEADER_IDEA_H 61 | 62 | # include /* IDEA_INT, OPENSSL_NO_IDEA */ 63 | 64 | # ifdef OPENSSL_NO_IDEA 65 | # error IDEA is disabled. 66 | # endif 67 | 68 | # define IDEA_ENCRYPT 1 69 | # define IDEA_DECRYPT 0 70 | 71 | # define IDEA_BLOCK 8 72 | # define IDEA_KEY_LENGTH 16 73 | 74 | #ifdef __cplusplus 75 | extern "C" { 76 | #endif 77 | 78 | typedef struct idea_key_st { 79 | IDEA_INT data[9][6]; 80 | } IDEA_KEY_SCHEDULE; 81 | 82 | const char *idea_options(void); 83 | void idea_ecb_encrypt(const unsigned char *in, unsigned char *out, 84 | IDEA_KEY_SCHEDULE *ks); 85 | # ifdef OPENSSL_FIPS 86 | void private_idea_set_encrypt_key(const unsigned char *key, 87 | IDEA_KEY_SCHEDULE *ks); 88 | # endif 89 | void idea_set_encrypt_key(const unsigned char *key, IDEA_KEY_SCHEDULE *ks); 90 | void idea_set_decrypt_key(IDEA_KEY_SCHEDULE *ek, IDEA_KEY_SCHEDULE *dk); 91 | void idea_cbc_encrypt(const unsigned char *in, unsigned char *out, 92 | long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, 93 | int enc); 94 | void idea_cfb64_encrypt(const unsigned char *in, unsigned char *out, 95 | long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, 96 | int *num, int enc); 97 | void idea_ofb64_encrypt(const unsigned char *in, unsigned char *out, 98 | long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, 99 | int *num); 100 | void idea_encrypt(unsigned long *in, IDEA_KEY_SCHEDULE *ks); 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | 105 | #endif 106 | -------------------------------------------------------------------------------- /lib/openssl/md4.h: -------------------------------------------------------------------------------- 1 | /* crypto/md4/md4.h */ 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_MD4_H 60 | # define HEADER_MD4_H 61 | 62 | # include 63 | # include 64 | 65 | #ifdef __cplusplus 66 | extern "C" { 67 | #endif 68 | 69 | # ifdef OPENSSL_NO_MD4 70 | # error MD4 is disabled. 71 | # endif 72 | 73 | /*- 74 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 75 | * ! MD4_LONG has to be at least 32 bits wide. If it's wider, then ! 76 | * ! MD4_LONG_LOG2 has to be defined along. ! 77 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 78 | */ 79 | 80 | # if defined(__LP32__) 81 | # define MD4_LONG unsigned long 82 | # elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__) 83 | # define MD4_LONG unsigned long 84 | # define MD4_LONG_LOG2 3 85 | /* 86 | * _CRAY note. I could declare short, but I have no idea what impact 87 | * does it have on performance on none-T3E machines. I could declare 88 | * int, but at least on C90 sizeof(int) can be chosen at compile time. 89 | * So I've chosen long... 90 | * 91 | */ 92 | # else 93 | # define MD4_LONG unsigned int 94 | # endif 95 | 96 | # define MD4_CBLOCK 64 97 | # define MD4_LBLOCK (MD4_CBLOCK/4) 98 | # define MD4_DIGEST_LENGTH 16 99 | 100 | typedef struct MD4state_st { 101 | MD4_LONG A, B, C, D; 102 | MD4_LONG Nl, Nh; 103 | MD4_LONG data[MD4_LBLOCK]; 104 | unsigned int num; 105 | } MD4_CTX; 106 | 107 | # ifdef OPENSSL_FIPS 108 | int private_MD4_Init(MD4_CTX *c); 109 | # endif 110 | int MD4_Init(MD4_CTX *c); 111 | int MD4_Update(MD4_CTX *c, const void *data, size_t len); 112 | int MD4_Final(unsigned char *md, MD4_CTX *c); 113 | unsigned char *MD4(const unsigned char *d, size_t n, unsigned char *md); 114 | void MD4_Transform(MD4_CTX *c, const unsigned char *b); 115 | #ifdef __cplusplus 116 | } 117 | #endif 118 | 119 | #endif 120 | -------------------------------------------------------------------------------- /lib/openssl/md5.h: -------------------------------------------------------------------------------- 1 | /* crypto/md5/md5.h */ 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_MD5_H 60 | # define HEADER_MD5_H 61 | 62 | # include 63 | # include 64 | 65 | #ifdef __cplusplus 66 | extern "C" { 67 | #endif 68 | 69 | # ifdef OPENSSL_NO_MD5 70 | # error MD5 is disabled. 71 | # endif 72 | 73 | /* 74 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 75 | * ! MD5_LONG has to be at least 32 bits wide. If it's wider, then ! 76 | * ! MD5_LONG_LOG2 has to be defined along. ! 77 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 78 | */ 79 | 80 | # if defined(__LP32__) 81 | # define MD5_LONG unsigned long 82 | # elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__) 83 | # define MD5_LONG unsigned long 84 | # define MD5_LONG_LOG2 3 85 | /* 86 | * _CRAY note. I could declare short, but I have no idea what impact 87 | * does it have on performance on none-T3E machines. I could declare 88 | * int, but at least on C90 sizeof(int) can be chosen at compile time. 89 | * So I've chosen long... 90 | * 91 | */ 92 | # else 93 | # define MD5_LONG unsigned int 94 | # endif 95 | 96 | # define MD5_CBLOCK 64 97 | # define MD5_LBLOCK (MD5_CBLOCK/4) 98 | # define MD5_DIGEST_LENGTH 16 99 | 100 | typedef struct MD5state_st { 101 | MD5_LONG A, B, C, D; 102 | MD5_LONG Nl, Nh; 103 | MD5_LONG data[MD5_LBLOCK]; 104 | unsigned int num; 105 | } MD5_CTX; 106 | 107 | # ifdef OPENSSL_FIPS 108 | int private_MD5_Init(MD5_CTX *c); 109 | # endif 110 | int MD5_Init(MD5_CTX *c); 111 | int MD5_Update(MD5_CTX *c, const void *data, size_t len); 112 | int MD5_Final(unsigned char *md, MD5_CTX *c); 113 | unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md); 114 | void MD5_Transform(MD5_CTX *c, const unsigned char *b); 115 | #ifdef __cplusplus 116 | } 117 | #endif 118 | 119 | #endif 120 | -------------------------------------------------------------------------------- /lib/openssl/mdc2.h: -------------------------------------------------------------------------------- 1 | /* crypto/mdc2/mdc2.h */ 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_MDC2_H 60 | # define HEADER_MDC2_H 61 | 62 | # include 63 | 64 | #ifdef __cplusplus 65 | extern "C" { 66 | #endif 67 | 68 | # ifdef OPENSSL_NO_MDC2 69 | # error MDC2 is disabled. 70 | # endif 71 | 72 | # define MDC2_BLOCK 8 73 | # define MDC2_DIGEST_LENGTH 16 74 | 75 | typedef struct mdc2_ctx_st { 76 | unsigned int num; 77 | unsigned char data[MDC2_BLOCK]; 78 | DES_cblock h, hh; 79 | int pad_type; /* either 1 or 2, default 1 */ 80 | } MDC2_CTX; 81 | 82 | # ifdef OPENSSL_FIPS 83 | int private_MDC2_Init(MDC2_CTX *c); 84 | # endif 85 | int MDC2_Init(MDC2_CTX *c); 86 | int MDC2_Update(MDC2_CTX *c, const unsigned char *data, size_t len); 87 | int MDC2_Final(unsigned char *md, MDC2_CTX *c); 88 | unsigned char *MDC2(const unsigned char *d, size_t n, unsigned char *md); 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /lib/openssl/opensslv.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_OPENSSLV_H 2 | # define HEADER_OPENSSLV_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | /*- 9 | * Numeric release version identifier: 10 | * MNNFFPPS: major minor fix patch status 11 | * The status nibble has one of the values 0 for development, 1 to e for betas 12 | * 1 to 14, and f for release. The patch level is exactly that. 13 | * For example: 14 | * 0.9.3-dev 0x00903000 15 | * 0.9.3-beta1 0x00903001 16 | * 0.9.3-beta2-dev 0x00903002 17 | * 0.9.3-beta2 0x00903002 (same as ...beta2-dev) 18 | * 0.9.3 0x0090300f 19 | * 0.9.3a 0x0090301f 20 | * 0.9.4 0x0090400f 21 | * 1.2.3z 0x102031af 22 | * 23 | * For continuity reasons (because 0.9.5 is already out, and is coded 24 | * 0x00905100), between 0.9.5 and 0.9.6 the coding of the patch level 25 | * part is slightly different, by setting the highest bit. This means 26 | * that 0.9.5a looks like this: 0x0090581f. At 0.9.6, we can start 27 | * with 0x0090600S... 28 | * 29 | * (Prior to 0.9.3-dev a different scheme was used: 0.9.2b is 0x0922.) 30 | * (Prior to 0.9.5a beta1, a different scheme was used: MMNNFFRBB for 31 | * major minor fix final patch/beta) 32 | */ 33 | # define OPENSSL_VERSION_NUMBER 0x1000202fL 34 | # ifdef OPENSSL_FIPS 35 | # define OPENSSL_VERSION_TEXT "OpenSSL 1.0.2b-fips 11 Jun 2015" 36 | # else 37 | # define OPENSSL_VERSION_TEXT "OpenSSL 1.0.2b 11 Jun 2015" 38 | # endif 39 | # define OPENSSL_VERSION_PTEXT " part of " OPENSSL_VERSION_TEXT 40 | 41 | /*- 42 | * The macros below are to be used for shared library (.so, .dll, ...) 43 | * versioning. That kind of versioning works a bit differently between 44 | * operating systems. The most usual scheme is to set a major and a minor 45 | * number, and have the runtime loader check that the major number is equal 46 | * to what it was at application link time, while the minor number has to 47 | * be greater or equal to what it was at application link time. With this 48 | * scheme, the version number is usually part of the file name, like this: 49 | * 50 | * libcrypto.so.0.9 51 | * 52 | * Some unixen also make a softlink with the major verson number only: 53 | * 54 | * libcrypto.so.0 55 | * 56 | * On Tru64 and IRIX 6.x it works a little bit differently. There, the 57 | * shared library version is stored in the file, and is actually a series 58 | * of versions, separated by colons. The rightmost version present in the 59 | * library when linking an application is stored in the application to be 60 | * matched at run time. When the application is run, a check is done to 61 | * see if the library version stored in the application matches any of the 62 | * versions in the version string of the library itself. 63 | * This version string can be constructed in any way, depending on what 64 | * kind of matching is desired. However, to implement the same scheme as 65 | * the one used in the other unixen, all compatible versions, from lowest 66 | * to highest, should be part of the string. Consecutive builds would 67 | * give the following versions strings: 68 | * 69 | * 3.0 70 | * 3.0:3.1 71 | * 3.0:3.1:3.2 72 | * 4.0 73 | * 4.0:4.1 74 | * 75 | * Notice how version 4 is completely incompatible with version, and 76 | * therefore give the breach you can see. 77 | * 78 | * There may be other schemes as well that I haven't yet discovered. 79 | * 80 | * So, here's the way it works here: first of all, the library version 81 | * number doesn't need at all to match the overall OpenSSL version. 82 | * However, it's nice and more understandable if it actually does. 83 | * The current library version is stored in the macro SHLIB_VERSION_NUMBER, 84 | * which is just a piece of text in the format "M.m.e" (Major, minor, edit). 85 | * For the sake of Tru64, IRIX, and any other OS that behaves in similar ways, 86 | * we need to keep a history of version numbers, which is done in the 87 | * macro SHLIB_VERSION_HISTORY. The numbers are separated by colons and 88 | * should only keep the versions that are binary compatible with the current. 89 | */ 90 | # define SHLIB_VERSION_HISTORY "" 91 | # define SHLIB_VERSION_NUMBER "1.0.0" 92 | 93 | 94 | #ifdef __cplusplus 95 | } 96 | #endif 97 | #endif /* HEADER_OPENSSLV_H */ 98 | -------------------------------------------------------------------------------- /lib/openssl/pem2.h: -------------------------------------------------------------------------------- 1 | /* ==================================================================== 2 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * 3. All advertising materials mentioning features or use of this 17 | * software must display the following acknowledgment: 18 | * "This product includes software developed by the OpenSSL Project 19 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" 20 | * 21 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 22 | * endorse or promote products derived from this software without 23 | * prior written permission. For written permission, please contact 24 | * licensing@OpenSSL.org. 25 | * 26 | * 5. Products derived from this software may not be called "OpenSSL" 27 | * nor may "OpenSSL" appear in their names without prior written 28 | * permission of the OpenSSL Project. 29 | * 30 | * 6. Redistributions of any form whatsoever must retain the following 31 | * acknowledgment: 32 | * "This product includes software developed by the OpenSSL Project 33 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" 34 | * 35 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 36 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 37 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 38 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 39 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 41 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 42 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 43 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 44 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 45 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 46 | * OF THE POSSIBILITY OF SUCH DAMAGE. 47 | * ==================================================================== 48 | * 49 | * This product includes cryptographic software written by Eric Young 50 | * (eay@cryptsoft.com). This product includes software written by Tim 51 | * Hudson (tjh@cryptsoft.com). 52 | * 53 | */ 54 | 55 | /* 56 | * This header only exists to break a circular dependency between pem and err 57 | * Ben 30 Jan 1999. 58 | */ 59 | 60 | #ifdef __cplusplus 61 | extern "C" { 62 | #endif 63 | 64 | #ifndef HEADER_PEM_H 65 | void ERR_load_PEM_strings(void); 66 | #endif 67 | 68 | #ifdef __cplusplus 69 | } 70 | #endif 71 | -------------------------------------------------------------------------------- /lib/openssl/pqueue.h: -------------------------------------------------------------------------------- 1 | /* crypto/pqueue/pqueue.h */ 2 | /* 3 | * DTLS implementation written by Nagendra Modadugu 4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. 5 | */ 6 | /* ==================================================================== 7 | * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in 18 | * the documentation and/or other materials provided with the 19 | * distribution. 20 | * 21 | * 3. All advertising materials mentioning features or use of this 22 | * software must display the following acknowledgment: 23 | * "This product includes software developed by the OpenSSL Project 24 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" 25 | * 26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 27 | * endorse or promote products derived from this software without 28 | * prior written permission. For written permission, please contact 29 | * openssl-core@OpenSSL.org. 30 | * 31 | * 5. Products derived from this software may not be called "OpenSSL" 32 | * nor may "OpenSSL" appear in their names without prior written 33 | * permission of the OpenSSL Project. 34 | * 35 | * 6. Redistributions of any form whatsoever must retain the following 36 | * acknowledgment: 37 | * "This product includes software developed by the OpenSSL Project 38 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" 39 | * 40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 51 | * OF THE POSSIBILITY OF SUCH DAMAGE. 52 | * ==================================================================== 53 | * 54 | * This product includes cryptographic software written by Eric Young 55 | * (eay@cryptsoft.com). This product includes software written by Tim 56 | * Hudson (tjh@cryptsoft.com). 57 | * 58 | */ 59 | 60 | #ifndef HEADER_PQUEUE_H 61 | # define HEADER_PQUEUE_H 62 | 63 | # include 64 | # include 65 | # include 66 | 67 | #ifdef __cplusplus 68 | extern "C" { 69 | #endif 70 | typedef struct _pqueue *pqueue; 71 | 72 | typedef struct _pitem { 73 | unsigned char priority[8]; /* 64-bit value in big-endian encoding */ 74 | void *data; 75 | struct _pitem *next; 76 | } pitem; 77 | 78 | typedef struct _pitem *piterator; 79 | 80 | pitem *pitem_new(unsigned char *prio64be, void *data); 81 | void pitem_free(pitem *item); 82 | 83 | pqueue pqueue_new(void); 84 | void pqueue_free(pqueue pq); 85 | 86 | pitem *pqueue_insert(pqueue pq, pitem *item); 87 | pitem *pqueue_peek(pqueue pq); 88 | pitem *pqueue_pop(pqueue pq); 89 | pitem *pqueue_find(pqueue pq, unsigned char *prio64be); 90 | pitem *pqueue_iterator(pqueue pq); 91 | pitem *pqueue_next(piterator *iter); 92 | 93 | void pqueue_print(pqueue pq); 94 | int pqueue_size(pqueue pq); 95 | 96 | #ifdef __cplusplus 97 | } 98 | #endif 99 | #endif /* ! HEADER_PQUEUE_H */ 100 | -------------------------------------------------------------------------------- /lib/openssl/rc2.h: -------------------------------------------------------------------------------- 1 | /* crypto/rc2/rc2.h */ 2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_RC2_H 60 | # define HEADER_RC2_H 61 | 62 | # include /* OPENSSL_NO_RC2, RC2_INT */ 63 | # ifdef OPENSSL_NO_RC2 64 | # error RC2 is disabled. 65 | # endif 66 | 67 | # define RC2_ENCRYPT 1 68 | # define RC2_DECRYPT 0 69 | 70 | # define RC2_BLOCK 8 71 | # define RC2_KEY_LENGTH 16 72 | 73 | #ifdef __cplusplus 74 | extern "C" { 75 | #endif 76 | 77 | typedef struct rc2_key_st { 78 | RC2_INT data[64]; 79 | } RC2_KEY; 80 | 81 | # ifdef OPENSSL_FIPS 82 | void private_RC2_set_key(RC2_KEY *key, int len, const unsigned char *data, 83 | int bits); 84 | # endif 85 | void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data, int bits); 86 | void RC2_ecb_encrypt(const unsigned char *in, unsigned char *out, 87 | RC2_KEY *key, int enc); 88 | void RC2_encrypt(unsigned long *data, RC2_KEY *key); 89 | void RC2_decrypt(unsigned long *data, RC2_KEY *key); 90 | void RC2_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, 91 | RC2_KEY *ks, unsigned char *iv, int enc); 92 | void RC2_cfb64_encrypt(const unsigned char *in, unsigned char *out, 93 | long length, RC2_KEY *schedule, unsigned char *ivec, 94 | int *num, int enc); 95 | void RC2_ofb64_encrypt(const unsigned char *in, unsigned char *out, 96 | long length, RC2_KEY *schedule, unsigned char *ivec, 97 | int *num); 98 | 99 | #ifdef __cplusplus 100 | } 101 | #endif 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /lib/openssl/rc4.h: -------------------------------------------------------------------------------- 1 | /* crypto/rc4/rc4.h */ 2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_RC4_H 60 | # define HEADER_RC4_H 61 | 62 | # include /* OPENSSL_NO_RC4, RC4_INT */ 63 | # ifdef OPENSSL_NO_RC4 64 | # error RC4 is disabled. 65 | # endif 66 | 67 | # include 68 | 69 | #ifdef __cplusplus 70 | extern "C" { 71 | #endif 72 | 73 | typedef struct rc4_key_st { 74 | RC4_INT x, y; 75 | RC4_INT data[256]; 76 | } RC4_KEY; 77 | 78 | const char *RC4_options(void); 79 | void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data); 80 | void private_RC4_set_key(RC4_KEY *key, int len, const unsigned char *data); 81 | void RC4(RC4_KEY *key, size_t len, const unsigned char *indata, 82 | unsigned char *outdata); 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /lib/openssl/ripemd.h: -------------------------------------------------------------------------------- 1 | /* crypto/ripemd/ripemd.h */ 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_RIPEMD_H 60 | # define HEADER_RIPEMD_H 61 | 62 | # include 63 | # include 64 | 65 | #ifdef __cplusplus 66 | extern "C" { 67 | #endif 68 | 69 | # ifdef OPENSSL_NO_RIPEMD 70 | # error RIPEMD is disabled. 71 | # endif 72 | 73 | # if defined(__LP32__) 74 | # define RIPEMD160_LONG unsigned long 75 | # elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__) 76 | # define RIPEMD160_LONG unsigned long 77 | # define RIPEMD160_LONG_LOG2 3 78 | # else 79 | # define RIPEMD160_LONG unsigned int 80 | # endif 81 | 82 | # define RIPEMD160_CBLOCK 64 83 | # define RIPEMD160_LBLOCK (RIPEMD160_CBLOCK/4) 84 | # define RIPEMD160_DIGEST_LENGTH 20 85 | 86 | typedef struct RIPEMD160state_st { 87 | RIPEMD160_LONG A, B, C, D, E; 88 | RIPEMD160_LONG Nl, Nh; 89 | RIPEMD160_LONG data[RIPEMD160_LBLOCK]; 90 | unsigned int num; 91 | } RIPEMD160_CTX; 92 | 93 | # ifdef OPENSSL_FIPS 94 | int private_RIPEMD160_Init(RIPEMD160_CTX *c); 95 | # endif 96 | int RIPEMD160_Init(RIPEMD160_CTX *c); 97 | int RIPEMD160_Update(RIPEMD160_CTX *c, const void *data, size_t len); 98 | int RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c); 99 | unsigned char *RIPEMD160(const unsigned char *d, size_t n, unsigned char *md); 100 | void RIPEMD160_Transform(RIPEMD160_CTX *c, const unsigned char *b); 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | 105 | #endif 106 | -------------------------------------------------------------------------------- /lib/openssl/ssl23.h: -------------------------------------------------------------------------------- 1 | /* ssl/ssl23.h */ 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_SSL23_H 60 | # define HEADER_SSL23_H 61 | 62 | #ifdef __cplusplus 63 | extern "C" { 64 | #endif 65 | 66 | /* 67 | * client 68 | */ 69 | /* write to server */ 70 | # define SSL23_ST_CW_CLNT_HELLO_A (0x210|SSL_ST_CONNECT) 71 | # define SSL23_ST_CW_CLNT_HELLO_B (0x211|SSL_ST_CONNECT) 72 | /* read from server */ 73 | # define SSL23_ST_CR_SRVR_HELLO_A (0x220|SSL_ST_CONNECT) 74 | # define SSL23_ST_CR_SRVR_HELLO_B (0x221|SSL_ST_CONNECT) 75 | 76 | /* server */ 77 | /* read from client */ 78 | # define SSL23_ST_SR_CLNT_HELLO_A (0x210|SSL_ST_ACCEPT) 79 | # define SSL23_ST_SR_CLNT_HELLO_B (0x211|SSL_ST_ACCEPT) 80 | 81 | #ifdef __cplusplus 82 | } 83 | #endif 84 | #endif 85 | -------------------------------------------------------------------------------- /lib/openssl/stack.h: -------------------------------------------------------------------------------- 1 | /* crypto/stack/stack.h */ 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_STACK_H 60 | # define HEADER_STACK_H 61 | 62 | #ifdef __cplusplus 63 | extern "C" { 64 | #endif 65 | 66 | typedef struct stack_st { 67 | int num; 68 | char **data; 69 | int sorted; 70 | int num_alloc; 71 | int (*comp) (const void *, const void *); 72 | } _STACK; /* Use STACK_OF(...) instead */ 73 | 74 | # define M_sk_num(sk) ((sk) ? (sk)->num:-1) 75 | # define M_sk_value(sk,n) ((sk) ? (sk)->data[n] : NULL) 76 | 77 | int sk_num(const _STACK *); 78 | void *sk_value(const _STACK *, int); 79 | 80 | void *sk_set(_STACK *, int, void *); 81 | 82 | _STACK *sk_new(int (*cmp) (const void *, const void *)); 83 | _STACK *sk_new_null(void); 84 | void sk_free(_STACK *); 85 | void sk_pop_free(_STACK *st, void (*func) (void *)); 86 | _STACK *sk_deep_copy(_STACK *, void *(*)(void *), void (*)(void *)); 87 | int sk_insert(_STACK *sk, void *data, int where); 88 | void *sk_delete(_STACK *st, int loc); 89 | void *sk_delete_ptr(_STACK *st, void *p); 90 | int sk_find(_STACK *st, void *data); 91 | int sk_find_ex(_STACK *st, void *data); 92 | int sk_push(_STACK *st, void *data); 93 | int sk_unshift(_STACK *st, void *data); 94 | void *sk_shift(_STACK *st); 95 | void *sk_pop(_STACK *st); 96 | void sk_zero(_STACK *st); 97 | int (*sk_set_cmp_func(_STACK *sk, int (*c) (const void *, const void *))) 98 | (const void *, const void *); 99 | _STACK *sk_dup(_STACK *st); 100 | void sk_sort(_STACK *st); 101 | int sk_is_sorted(const _STACK *st); 102 | 103 | #ifdef __cplusplus 104 | } 105 | #endif 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /lib/openssl/txt_db.h: -------------------------------------------------------------------------------- 1 | /* crypto/txt_db/txt_db.h */ 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_TXT_DB_H 60 | # define HEADER_TXT_DB_H 61 | 62 | # include 63 | # ifndef OPENSSL_NO_BIO 64 | # include 65 | # endif 66 | # include 67 | # include 68 | 69 | # define DB_ERROR_OK 0 70 | # define DB_ERROR_MALLOC 1 71 | # define DB_ERROR_INDEX_CLASH 2 72 | # define DB_ERROR_INDEX_OUT_OF_RANGE 3 73 | # define DB_ERROR_NO_INDEX 4 74 | # define DB_ERROR_INSERT_INDEX_CLASH 5 75 | 76 | #ifdef __cplusplus 77 | extern "C" { 78 | #endif 79 | 80 | typedef OPENSSL_STRING *OPENSSL_PSTRING; 81 | DECLARE_SPECIAL_STACK_OF(OPENSSL_PSTRING, OPENSSL_STRING) 82 | 83 | typedef struct txt_db_st { 84 | int num_fields; 85 | STACK_OF(OPENSSL_PSTRING) *data; 86 | LHASH_OF(OPENSSL_STRING) **index; 87 | int (**qual) (OPENSSL_STRING *); 88 | long error; 89 | long arg1; 90 | long arg2; 91 | OPENSSL_STRING *arg_row; 92 | } TXT_DB; 93 | 94 | # ifndef OPENSSL_NO_BIO 95 | TXT_DB *TXT_DB_read(BIO *in, int num); 96 | long TXT_DB_write(BIO *out, TXT_DB *db); 97 | # else 98 | TXT_DB *TXT_DB_read(char *in, int num); 99 | long TXT_DB_write(char *out, TXT_DB *db); 100 | # endif 101 | int TXT_DB_create_index(TXT_DB *db, int field, int (*qual) (OPENSSL_STRING *), 102 | LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp); 103 | void TXT_DB_free(TXT_DB *db); 104 | OPENSSL_STRING *TXT_DB_get_by_index(TXT_DB *db, int idx, 105 | OPENSSL_STRING *value); 106 | int TXT_DB_insert(TXT_DB *db, OPENSSL_STRING *value); 107 | 108 | #ifdef __cplusplus 109 | } 110 | #endif 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /lib/openssl/ui_compat.h: -------------------------------------------------------------------------------- 1 | /* crypto/ui/ui.h -*- mode:C; c-file-style: "eay" -*- */ 2 | /* 3 | * Written by Richard Levitte (richard@levitte.org) for the OpenSSL project 4 | * 2001. 5 | */ 6 | /* ==================================================================== 7 | * Copyright (c) 2001 The OpenSSL Project. All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in 18 | * the documentation and/or other materials provided with the 19 | * distribution. 20 | * 21 | * 3. All advertising materials mentioning features or use of this 22 | * software must display the following acknowledgment: 23 | * "This product includes software developed by the OpenSSL Project 24 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 25 | * 26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 27 | * endorse or promote products derived from this software without 28 | * prior written permission. For written permission, please contact 29 | * openssl-core@openssl.org. 30 | * 31 | * 5. Products derived from this software may not be called "OpenSSL" 32 | * nor may "OpenSSL" appear in their names without prior written 33 | * permission of the OpenSSL Project. 34 | * 35 | * 6. Redistributions of any form whatsoever must retain the following 36 | * acknowledgment: 37 | * "This product includes software developed by the OpenSSL Project 38 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" 39 | * 40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 51 | * OF THE POSSIBILITY OF SUCH DAMAGE. 52 | * ==================================================================== 53 | * 54 | * This product includes cryptographic software written by Eric Young 55 | * (eay@cryptsoft.com). This product includes software written by Tim 56 | * Hudson (tjh@cryptsoft.com). 57 | * 58 | */ 59 | 60 | #ifndef HEADER_UI_COMPAT_H 61 | # define HEADER_UI_COMPAT_H 62 | 63 | # include 64 | # include 65 | 66 | #ifdef __cplusplus 67 | extern "C" { 68 | #endif 69 | 70 | /* 71 | * The following functions were previously part of the DES section, and are 72 | * provided here for backward compatibility reasons. 73 | */ 74 | 75 | # define des_read_pw_string(b,l,p,v) \ 76 | _ossl_old_des_read_pw_string((b),(l),(p),(v)) 77 | # define des_read_pw(b,bf,s,p,v) \ 78 | _ossl_old_des_read_pw((b),(bf),(s),(p),(v)) 79 | 80 | int _ossl_old_des_read_pw_string(char *buf, int length, const char *prompt, 81 | int verify); 82 | int _ossl_old_des_read_pw(char *buf, char *buff, int size, const char *prompt, 83 | int verify); 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | #endif 89 | -------------------------------------------------------------------------------- /lib/openssl/whrlpool.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_WHRLPOOL_H 2 | # define HEADER_WHRLPOOL_H 3 | 4 | # include 5 | # include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | # define WHIRLPOOL_DIGEST_LENGTH (512/8) 12 | # define WHIRLPOOL_BBLOCK 512 13 | # define WHIRLPOOL_COUNTER (256/8) 14 | 15 | typedef struct { 16 | union { 17 | unsigned char c[WHIRLPOOL_DIGEST_LENGTH]; 18 | /* double q is here to ensure 64-bit alignment */ 19 | double q[WHIRLPOOL_DIGEST_LENGTH / sizeof(double)]; 20 | } H; 21 | unsigned char data[WHIRLPOOL_BBLOCK / 8]; 22 | unsigned int bitoff; 23 | size_t bitlen[WHIRLPOOL_COUNTER / sizeof(size_t)]; 24 | } WHIRLPOOL_CTX; 25 | 26 | # ifndef OPENSSL_NO_WHIRLPOOL 27 | # ifdef OPENSSL_FIPS 28 | int private_WHIRLPOOL_Init(WHIRLPOOL_CTX *c); 29 | # endif 30 | int WHIRLPOOL_Init(WHIRLPOOL_CTX *c); 31 | int WHIRLPOOL_Update(WHIRLPOOL_CTX *c, const void *inp, size_t bytes); 32 | void WHIRLPOOL_BitUpdate(WHIRLPOOL_CTX *c, const void *inp, size_t bits); 33 | int WHIRLPOOL_Final(unsigned char *md, WHIRLPOOL_CTX *c); 34 | unsigned char *WHIRLPOOL(const void *inp, size_t bytes, unsigned char *md); 35 | # endif 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /lib/x86-64/libcrypto.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwagnr/tpm2simulator/e45324eba268723d39856111e7933c5c76238481/lib/x86-64/libcrypto.a -------------------------------------------------------------------------------- /lib/x86-64/libssl.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwagnr/tpm2simulator/e45324eba268723d39856111e7933c5c76238481/lib/x86-64/libssl.a -------------------------------------------------------------------------------- /lib/x86/libcrypto.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwagnr/tpm2simulator/e45324eba268723d39856111e7933c5c76238481/lib/x86/libcrypto.a -------------------------------------------------------------------------------- /lib/x86/libssl.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwagnr/tpm2simulator/e45324eba268723d39856111e7933c5c76238481/lib/x86/libssl.a -------------------------------------------------------------------------------- /patches/116/CpriRSA.c.patch: -------------------------------------------------------------------------------- 1 | diff --git a/OsslCryptoEngine/CpriRSA.c b/OsslCryptoEngine/CpriRSA.c 2 | index 91d3042..9edf589 100644 3 | --- a/OsslCryptoEngine/CpriRSA.c 4 | +++ b/OsslCryptoEngine/CpriRSA.c 5 | @@ -811,7 +811,7 @@ RSASSA_Encode( 6 | ) 7 | { 8 | BYTE *der; 9 | - INT32 derSize = _cpri__GetHashDER(hashAlg, &der); 10 | + INT32 derSize = _cpri__GetHashDER(hashAlg, (const BYTE **)&der); 11 | INT32 fillSize; 12 | 13 | pAssert(eOut != NULL && hIn != NULL); 14 | @@ -858,7 +858,7 @@ RSASSA_Decode( 15 | { 16 | BOOL fail = FALSE; 17 | BYTE *der; 18 | - INT32 derSize = _cpri__GetHashDER(hashAlg, &der); 19 | + INT32 derSize = _cpri__GetHashDER(hashAlg, (const BYTE **)&der); 20 | INT32 hashSize = _cpri__GetDigestSize(hashAlg); 21 | INT32 fillSize; 22 | 23 | -------------------------------------------------------------------------------- /patches/116/CryptoEngine.h.patch: -------------------------------------------------------------------------------- 1 | diff --git a/include/CryptoEngine.h b/include/CryptoEngine.h 2 | index 8c0f30e..c055453 100644 3 | --- a/include/CryptoEngine.h 4 | +++ b/include/CryptoEngine.h 5 | @@ -6,7 +6,7 @@ 6 | #include "TpmError.h" 7 | #include "swap.h" 8 | #include "Implementation.h" 9 | -#include "TPM_types.h" 10 | +#include "TPM_Types.h" 11 | //#include "TPMB.h" 12 | #include "bool.h" 13 | #include "Platform.h" 14 | -------------------------------------------------------------------------------- /patches/116/Entropy.c.patch: -------------------------------------------------------------------------------- 1 | diff --git a/platform/Entropy.c b/platform/Entropy.c 2 | index 888789c..f561ca8 100644 3 | --- a/platform/Entropy.c 4 | +++ b/platform/Entropy.c 5 | @@ -49,3 +49,19 @@ 6 | #include 7 | #include "TpmBuildSwitches.h" 8 | + 9 | +#if defined(_Win32) || defined(WIN32) 10 | +#else 11 | +// Quick and dirty 12 | +#include 13 | +int32_t rand_s(uint32_t* rndNum) { 14 | + FILE *fp; 15 | + if (fp = fopen("/dev/urandom", "r")) { 16 | + fread(rndNum, sizeof(char), 1, fp); 17 | + fclose(fp); 18 | + return 0; 19 | + } 20 | + return -1; 21 | +} 22 | +#endif 23 | + 24 | 25 | -------------------------------------------------------------------------------- /patches/116/LocalityPlat.c.patch: -------------------------------------------------------------------------------- 1 | diff --git a/platform/LocalityPlat.c b/platform/LocalityPlat.c 2 | index 5498183..247c24c 100644 3 | --- a/platform/LocalityPlat.c 4 | +++ b/platform/LocalityPlat.c 5 | @@ -42,2 +42,3 @@ 6 | #include "TpmError.h" 7 | +static int s_RsaKeyCacheEnabled = FALSE; 8 | -------------------------------------------------------------------------------- /patches/116/NVMem.c.patch: -------------------------------------------------------------------------------- 1 | diff --git a/platform/NVMem.c b/platform/NVMem.c 2 | index 5498183..247c24c 100644 3 | --- a/platform/NVMem.c 4 | +++ b/platform/NVMem.c 5 | @@ -43,8 +43,12 @@ _plat__NVEnable( 6 | if(s_NVFile != NULL) return 0; 7 | 8 | // Try to open an exist NVChip file for read/write 9 | +#if defined(_Win32) || defined(WIN32) 10 | if(0 != fopen_s(&s_NVFile, "NVChip", "r+b")) 11 | s_NVFile = NULL; 12 | +#else 13 | + s_NVFile = fopen("/tmp/NVChip", "r+b"); 14 | +#endif 15 | 16 | if(NULL != s_NVFile) 17 | { 18 | @@ -60,7 +64,11 @@ _plat__NVEnable( 19 | memset(s_NV, 0, NV_MEMORY_SIZE); 20 | 21 | // If NVChip file does not exist, try to create it for read/write 22 | +#if defined(_Win32) || defined(WIN32) 23 | fopen_s(&s_NVFile, "NVChip", "w+b"); 24 | +#else 25 | + s_NVFile = fopen("/tmp/NVChip", "w+b"); 26 | +#endif 27 | // Start initialize at the end of new file 28 | fseek(s_NVFile, 0, SEEK_END); 29 | // Write 0s to NVChip file 30 | -------------------------------------------------------------------------------- /patches/116/NV_UndefineSpaceSpecial.c.patch: -------------------------------------------------------------------------------- 1 | --- a/tpm/command/NVStorage/NV_UndefineSpaceSpecial0.c 2015-06-23 15:32:19.802147000 +0200 2 | +++ b/tpm/command/NVStorage/NV_UndefineSpaceSpecial.c 2015-06-24 10:12:37.279728706 +0200 3 | 4 | diff --git a/tpm/command/NVStorage/NV_UndefineSpaceSpecial.c b/tpm/command/NVStorage/NV_UndefineSpaceSpecial.c 5 | index 100644 6 | --- a/tpm/command/NVStorage/NV_UndefineSpaceSpecial.c 7 | +++ b/tpm/command/NVStorage/NV_UndefineSpaceSpecial.c 8 | @@ -1,3 +1,4 @@ 9 | #include "InternalRoutines.h" 10 | #include "NV_UndefineSpaceSpecial_fp.h" 11 | +#include "SessionProcess_fp.h" 12 | #ifdef TPM_CC_NV_UndefineSpaceSpecial // Conditional expansion of this file 13 | @@ -34,6 +34,7 @@ 14 | 15 | // Call implementation dependent internal routine to delete NV index 16 | NvDeleteEntity(in->nvIndex); 17 | + SessionRemoveAssociationToHandle(in->nvIndex); 18 | 19 | return TPM_RC_SUCCESS; 20 | } 21 | -------------------------------------------------------------------------------- /patches/116/OsslCryptoEngine.h.patch: -------------------------------------------------------------------------------- 1 | diff --git a/OsslCryptoEngine/OsslCryptoEngine.h b/OsslCryptoEngine/OsslCryptoEngine.h 2 | index 100644 3 | --- a/OsslCryptoEngine/OsslCryptoEngine.h 4 | +++ b/OsslCryptoEngine/OsslCryptoEngine.h 5 | @@ -6,7 +6,12 @@ 6 | #include 7 | #include 8 | #include 9 | +#if defined(_Win32) || defined(WIN32) 10 | #include 11 | +#else 12 | +#include 13 | +#include 14 | +#endif 15 | #define CRYPTO_ENGINE 16 | #include "CryptoEngine.h" 17 | #include "CpriMisc_fp.h" 18 | @@ -33,5 +34,12 @@ 19 | TPM_ALG_ID hashAlg; 20 | UINT16 keySizeInBits; 21 | } KDFa_CONTEXT; 22 | + 23 | +#if defined(_Win32) || defined(WIN32) 24 | +#else 25 | +#ifndef UNREFERENCED_PARAMETER 26 | +#define UNREFERENCED_PARAMETER(x) (x); 27 | +#endif 28 | +#endif 29 | #endif // _OSSL_CRYPTO_ENGINE_H 30 | 31 | -------------------------------------------------------------------------------- /patches/116/SessionProcess.c.patch: -------------------------------------------------------------------------------- 1 | diff --git a/tpm/main/SessionProcess.c b/tpm/main/SessionProcess.c 2 | index 100644 3 | --- a/tpm/main/SessionProcess.c 4 | +++ b/tpm/main/SessionProcess.c 5 | @@ -1965,2 +1965,16 @@ 6 | } 7 | 8 | +void 9 | +SessionRemoveAssociationToHandle( 10 | + TPM_HANDLE handle 11 | + ) 12 | +{ 13 | + UINT32 i; 14 | + for(i = 0; i < MAX_SESSION_NUM; i++) 15 | + { 16 | + if(s_associatedHandles[i] == handle) 17 | + { 18 | + s_associatedHandles[i] = TPM_RH_NULL; 19 | + } 20 | + } 21 | +} 22 | -------------------------------------------------------------------------------- /patches/116/SessionProcess_fp.h.patch: -------------------------------------------------------------------------------- 1 | diff --git a/tpm/include/prototypes/SessionProcess_fp.h b/tpm/include/prototypes/SessionProcess_fp.h 2 | index 100644 3 | --- a/tpm/include/prototypes/SessionProcess_fp.h 4 | +++ b/tpm/include/prototypes/SessionProcess_fp.h 5 | @@ -39,4 +39,8 @@ 6 | UINT32 *resSessionSize // OUT: response session area 7 | ); 8 | 9 | +void 10 | +SessionRemoveAssociationToHandle( 11 | + TPM_HANDLE handle 12 | + ); 13 | #endif // _SESSIONPROCESS_FP_H_ 14 | -------------------------------------------------------------------------------- /patches/116/TPMCmdp.c.patch: -------------------------------------------------------------------------------- 1 | diff --git a/simulator/TPMCmdp.c b/simulator/TPMCmdp.c 2 | index 100644 3 | --- a/simulator/TPMCmdp.c 4 | +++ b/simulator/TPMCmdp.c 5 | @@ -10,7 +10,15 @@ 6 | #include "DRTM_fp.h" 7 | #include "_TPM_Init_fp.h" 8 | #include "TpmFail_fp.h" 9 | + 10 | +// CHANGE START 11 | +#if defined(_Win32) || defined(WIN32) 12 | #include 13 | +#else 14 | +#define SOCKET int 15 | +#endif 16 | +// CHANGE END 17 | + 18 | #include "TpmTcpProtocol.h" 19 | static BOOL s_isPowerOn = FALSE; 20 | 21 | @@ -236,11 +244,14 @@ 22 | void 23 | ) 24 | { 25 | +#if defined(_Win32) || defined(WIN32) 26 | RPC_STATUS status; 27 | +#endif 28 | 29 | // Stop TPM 30 | TPM_TearDown(); 31 | 32 | +#if defined(_Win32) || defined(WIN32) 33 | status = RpcMgmtStopServerListening(NULL); 34 | if (status != RPC_S_OK) 35 | { 36 | @@ -254,5 +265,6 @@ 37 | printf_s("RpcServerUnregisterIf returned 0x%x\n", status); 38 | exit(status); 39 | } 40 | +#endif 41 | } 42 | 43 | -------------------------------------------------------------------------------- /patches/116/TPMCmds.c.patch: -------------------------------------------------------------------------------- 1 | diff --git a/simulator/TPMCmds.c b/simulator/TPMCmds.c 2 | index 100644 3 | --- a/simulator/TPMCmds.c 4 | +++ b/simulator/TPMCmds.c 5 | @@ -2,14 +2,36 @@ 6 | #include 7 | #include 8 | #include 9 | + 10 | +// CHANGE START 11 | +#if defined(_Win32) || defined(WIN32) 12 | #include 13 | #include 14 | +#else 15 | +#include "bool.h" 16 | +#include 17 | +#define SOCKET int 18 | +#include 19 | +#define __cdecl 20 | +#define fprintf_s fprintf 21 | +#endif 22 | +// CHANGE END 23 | + 24 | #include "string.h" 25 | #include "TpmTcpProtocol.h" 26 | + 27 | +// CHANGE START 28 | +#if defined(_Win32) || defined(WIN32) 29 | #include "..\tpm\include\TpmBuildSwitches.h" 30 | #include "..\tpm\include\prototypes\Manufacture_fp.h" 31 | +#else 32 | +#include "../tpm/include/TpmBuildSwitches.h" 33 | +#include "../tpm/include/prototypes/Manufacture_fp.h" 34 | +#endif 35 | +// CHANGE END 36 | + 37 | #define PURPOSE \ 38 | +"TPM Simulator for Windows and Linux.\n" 39 | -"TPM Reference Simulator.\nCopyright Microsoft 2010, 2011.\n" 40 | #define DEFAULT_TPM_PORT 2321 41 | void* MainPointer; 42 | int _plat__NVEnable(void* platParameters); 43 | -------------------------------------------------------------------------------- /patches/116/TpmBuildSwitches.h.patch: -------------------------------------------------------------------------------- 1 | diff --git a/tpm/include/TpmBuildSwitches.h b/tpm/include/TpmBuildSwitches.h 2 | index 100644 3 | --- a/tpm/include/TpmBuildSwitches.h 4 | +++ b/tpm/include/TpmBuildSwitches.h 5 | @@ -11,1 +11,5 @@ 6 | +#if defined(_Win32) || defined(WIN32) 7 | #define ALIGN_TO(boundary) __declspec(align(boundary)) 8 | +#else 9 | +#define ALIGN_TO(boundary) __attribute__ ((aligned (boundary))) 10 | +#endif 11 | @@ -43,2 +43,7 @@ 12 | +#if defined(_Win32) || defined(WIN32) 13 | #define LIB_EXPORT __declspec(dllexport) 14 | // #define LIB_EXPORT 15 | +#else 16 | +//#define LIB_EXPORT __declspec(dllexport) 17 | +#define LIB_EXPORT 18 | +#endif 19 | -------------------------------------------------------------------------------- /patches/138/CreateLoaded.c.patch: -------------------------------------------------------------------------------- 1 | diff --git a/tpm/command/Object/CreateLoaded.c b/tpm/command/Object/CreateLoaded.c 2 | index 2509a6a..b7f1d32 100644 3 | --- a/tpm/command/Object/CreateLoaded.c 4 | +++ b/tpm/command/Object/CreateLoaded.c 5 | @@ -159,6 +159,11 @@ TPM2_CreateLoaded( 6 | newObject->attributes.epsHierarchy = SET; 7 | // If so, use the primary seed and the digest of the template 8 | // to seed the DRBG 9 | + DRBG_InstantiateSeeded((DRBG_STATE *)rand, 10 | + &HierarchyGetPrimarySeed(in->parentHandle)->b, 11 | + PRIMARY_OBJECT_CREATION, 12 | + (TPM2B *)PublicMarshalAndComputeName(publicArea, &name), 13 | + &in->inSensitive.sensitive.data.b); 14 | } 15 | else 16 | // This is an ordinary object so use the normal random number generator 17 | -- 18 | 2.1.4 19 | -------------------------------------------------------------------------------- /patches/138/CryptSym.c.patch: -------------------------------------------------------------------------------- 1 | diff --git a/tpm/crypt/CryptSym.c b/tpm/crypt/CryptSym.c 2 | index 5660ec8..296fce6 100644 3 | --- a/tpm/crypt/CryptSym.c 4 | +++ b/tpm/crypt/CryptSym.c 5 | @@ -37,25 +37,6 @@ 6 | /******************************************************************************************************************/ 7 | 8 | #include "Tpm.h" 9 | -union tpmCryptKeySchedule_t { 10 | -#ifdef TPM_ALG_AES 11 | - tpmKeyScheduleAES AES; 12 | -#endif 13 | -#ifdef TPM_ALG_SM4 14 | - tpmKeyScheduleSM4 SM4; 15 | -#endif 16 | -#ifdef TPM_ALG_CAMELLIA 17 | - tpmKeyScheduleCAMELLIA CAMELLIA; 18 | -#endif 19 | -#ifdef TPM_ALG_TDES 20 | - tpmKeyScheduleTDES TDES[3]; 21 | -#endif 22 | -#if SYMMETRIC_ALIGNMENT == 8 23 | - uint64_t alignment; 24 | -#else 25 | - uint32_t alignment; 26 | -#endif 27 | -}; 28 | 29 | // Each block cipher within a library is expected to conform to the same calling conventions with three parameters 30 | // (keySchedule, in, and out) in the same order. That means that all algorithms would use the same order of the same 31 | -- 32 | 2.1.4 33 | 34 | -------------------------------------------------------------------------------- /patches/138/Global.h.patch: -------------------------------------------------------------------------------- 1 | diff --git a/tpm/include/Global.h b/tpm/include/Global.h 2 | index f096f61..836b56c 100644 3 | --- a/tpm/include/Global.h 4 | +++ b/tpm/include/Global.h 5 | @@ -39,7 +39,9 @@ 6 | #ifndef GLOBAL_H 7 | #define GLOBAL_H 8 | //#define SELF_TEST 9 | +#if defined(_Win32) || defined(WIN32) 10 | _REDUCE_WARNING_LEVEL_(2) 11 | +#endif 12 | #include 13 | //#include 14 | #include 15 | -- 16 | 2.1.4 17 | 18 | -------------------------------------------------------------------------------- /patches/138/Implementation.h.patch: -------------------------------------------------------------------------------- 1 | diff --git a/tpm/include/Implementation.h b/tpm/include/Implementation.h 2 | index 39a8277..2f7c3fe 100644 3 | --- a/tpm/include/Implementation.h 4 | +++ b/tpm/include/Implementation.h 5 | @@ -280,7 +280,7 @@ 6 | 7 | // From Vendor-Specific: Table 7 - Defines for Implementation Values 8 | #define FIELD_UPGRADE_IMPLEMENTED NO 9 | -#define RADIX_BITS 32 10 | +#define RADIX_BITS 64 11 | #define HASH_ALIGNMENT 4 12 | #define SYMMETRIC_ALIGNMENT 4 13 | #define HASH_LIB OSSL 14 | -- 15 | 2.1.4 16 | 17 | -------------------------------------------------------------------------------- /patches/138/Manufacture.c.patch: -------------------------------------------------------------------------------- 1 | diff --git a/tpm/support/Manufacture.c b/tpm/support/Manufacture.c 2 | index c446a14..ae977ca 100644 3 | --- a/tpm/support/Manufacture.c 4 | +++ b/tpm/support/Manufacture.c 5 | @@ -39,3 +39,2 @@ 6 | #define MANUFACTURE_C 7 | #include "Tpm.h" 8 | -#include "TpmSizeChecks_fp.h" 9 | @@ -54,11 +53,6 @@ TPM_Manufacture( 10 | ) 11 | { 12 | TPM_SU orderlyShutdown; 13 | -#ifdef RUNTIME_SIZE_CHECKS 14 | - // Call the function to verify the sizes of values that result from different 15 | - // compile options. 16 | - TpmSizeChecks(); 17 | -#endif 18 | // If TPM has been manufactured, return indication. 19 | if(!firstTime && g_manufactured) 20 | return 1; 21 | -- 22 | 2.1.4 23 | 24 | -------------------------------------------------------------------------------- /patches/138/Platform_fp.h.patch: -------------------------------------------------------------------------------- 1 | diff --git a/platform/include/prototypes/Platform_fp.h b/platform/include/prototypes/Platform_fp.h 2 | index 72e0db7..b5dfb33 100644 3 | --- a/platform/include/prototypes/Platform_fp.h 4 | +++ b/platform/include/prototypes/Platform_fp.h 5 | @@ -39,6 +39,8 @@ 6 | #ifndef _PLATFORM_FP_H_ 7 | #define _PLATFORM_FP_H_ 8 | 9 | +#include "BaseTypes.h" 10 | + 11 | // Check if the cancel flag is set 12 | 13 | // TRUE(1) if cancel flag is set 14 | -- 15 | 2.1.4 16 | 17 | -------------------------------------------------------------------------------- /patches/138/Simulator_fp.h.patch: -------------------------------------------------------------------------------- 1 | diff --git a/include/Simulator_fp.h b/include/Simulator_fp.h 2 | index 4cd013d..5c5b926 100644 3 | --- a/include/Simulator_fp.h 4 | +++ b/include/Simulator_fp.h 5 | @@ -39,6 +39,8 @@ 6 | #ifndef _SIMULATOR_FP_H_ 7 | #define _SIMULATOR_FP_H_ 8 | 9 | +#include "TPM_Types.h" 10 | + 11 | // This function processes incoming platform requests. 12 | BOOL 13 | PlatformServer( 14 | -- 15 | 2.1.4 16 | 17 | -------------------------------------------------------------------------------- /patches/138/TPMB.h.patch: -------------------------------------------------------------------------------- 1 | diff --git a/tpm/include/TPMB.h b/tpm/include/TPMB.h 2 | index 9e0a6b9..ed99150 100644 3 | --- a/tpm/include/TPMB.h 4 | +++ b/tpm/include/TPMB.h 5 | @@ -43,5 +43,2 @@ 6 | -typedef struct { 7 | - UINT16 size; 8 | - BYTE buffer[1]; 9 | -} TPM2B, *P2B; 10 | +typedef TPM2B *P2B; 11 | typedef const TPM2B *PC2B; 12 | -- 13 | 2.1.4 14 | 15 | -------------------------------------------------------------------------------- /patches/138/TPMCmdp.c.patch: -------------------------------------------------------------------------------- 1 | diff --git a/simulator/TPMCmdp.c b/simulator/TPMCmdp.c 2 | index 3cf0964..4e351ea 100644 3 | --- a/simulator/TPMCmdp.c 4 | +++ b/simulator/TPMCmdp.c 5 | @@ -40,8 +40,10 @@ 6 | #include 7 | #include 8 | #include "TpmBuildSwitches.h" 9 | +#if defined(_Win32) || defined(WIN32) 10 | #include 11 | #include 12 | +#endif 13 | #include "Platform_fp.h" 14 | #include "ExecCommand_fp.h" 15 | #include "Manufacture_fp.h" 16 | @@ -266,9 +268,12 @@ _rpc__Shutdown( 17 | void 18 | ) 19 | { 20 | +#if defined(_Win32) || defined(WIN32) 21 | RPC_STATUS status; 22 | +#endif 23 | // Stop TPM 24 | TPM_TearDown(); 25 | +#if defined(_Win32) || defined(WIN32) 26 | status = RpcMgmtStopServerListening(NULL); 27 | if(status != RPC_S_OK) 28 | { 29 | @@ -281,6 +286,7 @@ _rpc__Shutdown( 30 | printf("RpcServerUnregisterIf returned 0x%x\n", status); 31 | exit(status); 32 | } 33 | +#endif 34 | return; 35 | } 36 | 37 | -- 38 | 2.1.4 39 | 40 | -------------------------------------------------------------------------------- /patches/138/TPMCmds.c.patch: -------------------------------------------------------------------------------- 1 | diff --git a/simulator/TPMCmds.c b/simulator/TPMCmds.c 2 | index eb266d8..0a75b1d 100644 3 | --- a/simulator/TPMCmds.c 4 | +++ b/simulator/TPMCmds.c 5 | @@ -42,8 +42,10 @@ 6 | #include 7 | #include 8 | #include 9 | +#if defined(_Win32) || defined(WIN32) 10 | #include 11 | #include 12 | +#endif 13 | #include "TpmTcpProtocol.h" 14 | #include "Manufacture_fp.h" 15 | #include "Platform_fp.h" 16 | -- 17 | 2.1.4 18 | 19 | -------------------------------------------------------------------------------- /patches/138/TPM_Types.h.patch: -------------------------------------------------------------------------------- 1 | diff --git a/tpm/include/TPM_Types.h b/tpm/include/TPM_Types.h 2 | index 51fd892..13245d8 100644 3 | --- a/tpm/include/TPM_Types.h 4 | +++ b/tpm/include/TPM_Types.h 5 | @@ -40,6 +40,16 @@ 6 | #include "BaseTypes.h" // i.a. needed for UINT32 7 | #include "Implementation.h" // i.a. needed for TPM_ALG_ID 8 | #include "Capabilities.h" // i.a. needed for MAX_CAP_CC 9 | +#include "GpMacros.h" 10 | + 11 | +#if !defined(_Win32) && !defined(WIN32) 12 | +#define WINAPI 13 | +#define SOCKET int 14 | +#define HANDLE UINT32 15 | +#define DWORD unsigned long 16 | +#endif 17 | + 18 | +typedef void *LPVOID; 19 | 20 | // Table 2:3 - Definition of Base Types (TypedefTable) 21 | 22 | @@ -512,7 +522,7 @@ typedef union { 23 | unsigned Reserved_from_12 : 4; 24 | unsigned restricted : 1; 25 | unsigned decrypt : 1; 26 | - unsigned sign / encrypt : 1; 27 | + unsigned encrypt : 1; 28 | unsigned Reserved_from_19 : 13; 29 | }; 30 | UINT32 val; 31 | -- 32 | 2.1.4 33 | 34 | -------------------------------------------------------------------------------- /patches/138/TpmTcpProtocol.h.patch: -------------------------------------------------------------------------------- 1 | diff --git a/simulator/include/TpmTcpProtocol.h b/simulator/include/TpmTcpProtocol.h 2 | index 03a2382..7691702 100644 3 | --- a/simulator/include/TpmTcpProtocol.h 4 | +++ b/simulator/include/TpmTcpProtocol.h 5 | @@ -85,11 +85,5 @@ typedef struct out_buffer 6 | uint32_t BufferSize; 7 | _OUTPUT_BUFFER Buffer; 8 | } _OUT_BUFFER; 9 | -#ifndef WIN32 10 | -typedef unsigned long DWORD; 11 | -typedef void *LPVOID; 12 | -#undef WINAPI 13 | -typedef 14 | -#endif 15 | #endif 16 | 17 | -- 18 | 2.1.4 19 | 20 | -------------------------------------------------------------------------------- /scripts/README: -------------------------------------------------------------------------------- 1 | Cross-compilation: 2 | ==================== 3 | 4 | To cross-compile the TPM2 simulator one need to follow the following steps: 5 | 6 | 1) Create a build directory: 7 | # mkdir build && cd build 8 | 9 | 2) Setup Makefiles for cross-compilation: 10 | # cmake -DCMAKE_TOOLCHAIN_FILE=../toolchain_arm.cmake .. -G "Unix Makefiles" 11 | 12 | 3) Cross-compile the TPM2 simulator: 13 | # make 14 | 15 | 4) Copy the following files to the target (e.g. usbarmory): 16 | . ./Simulator 17 | . ./build/tpm/libTPM.so 18 | . ./build/platform/libplatform.so 19 | . ./build/OsslCryptoEngine/libCryptoEngine.so 20 | 21 | 22 | 23 | TPM2 Simulator execution: 24 | ========================= 25 | 26 | Host-side: 27 | ------------ 28 | Execute the TPM2 Simulator on the target platform (usbarmory): 29 | # ./Simulator 30 | 31 | 32 | Client-side: 33 | ------------ 34 | Execute the testing suite of the IBM TSS: 35 | # TPM_SERVER_NAME=10.0.0.1 ./reg.sh -a 36 | 37 | -------------------------------------------------------------------------------- /scripts/modules/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | -------------------------------------------------------------------------------- /scripts/modules/comment.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import textwrap as tw 4 | 5 | from modules import constants 6 | 7 | 8 | class Comment(object): 9 | """ Comment class: 10 | The class Comment wraps a string into a comment-compatible string. This 11 | means that a string is first splitted into lines of 'line_length' 12 | characters at maximum and that every line is prepended with a '// ' 13 | sequence 14 | """ 15 | 16 | indent = "// " 17 | table_subsequent_indent = "// " + 30 * " " 18 | line_length = 120 19 | 20 | # Initializes comment object 21 | def __init__(self): 22 | # initialize wrapper for simple text comments 23 | self.wrapper = tw.TextWrapper() 24 | self.wrapper.width = self.line_length 25 | self.wrapper.initial_indent = self.indent 26 | self.wrapper.subsequent_indent = self.indent 27 | 28 | # initialize wrapper for comments inside of xml tables 29 | self.table_wrapper = tw.TextWrapper() 30 | self.table_wrapper.width = self.line_length 31 | self.table_wrapper.initial_indent = self.indent 32 | self.table_wrapper.subsequent_indent = self.table_subsequent_indent 33 | 34 | # Performs simple comment wrapping of given string 35 | # Parameters: 36 | # str - string 37 | def wrap_comment(self, str): 38 | return self.wrapper.fill(str) 39 | 40 | # Generates comment from tables in xml format based on first two columns 41 | # Parameters: 42 | # table 43 | def extract_table(self, table): 44 | # Assuming that every table contains only two columns. 45 | 46 | comment = "" 47 | rows = table.find_all(constants.XML_TABLE_TABLE_ROW) 48 | 49 | # skip first row (table description) 50 | for i in range(1,len(rows)): 51 | unwrapped_comment = "" 52 | 53 | cells = rows[i].find_all(constants.XML_TABLE_TABLE_CELL) 54 | unwrapped_comment += '{:<29}'.format(cells[0].get_text()) # .encode("utf8")) 55 | unwrapped_comment += cells[1].get_text() 56 | 57 | comment += self.table_wrapper.fill(unwrapped_comment) 58 | comment += "\n" 59 | 60 | # comment += "\n" 61 | 62 | return comment 63 | 64 | # Generates comment from tables in text format based on first two columns 65 | # Parameters: 66 | # table 67 | def extract_table_pdf(self, table): 68 | # Assuming that every table contains only two columns. 69 | 70 | comment = "\n" 71 | 72 | # skip first row (table description) 73 | for i in range(1,len(table.rows)): 74 | unwrapped_comment = "" 75 | 76 | unwrapped_comment += '{:<29}'.format(table.rows[i][0]) # .encode("utf8")) 77 | unwrapped_comment += table.rows[i][1] 78 | 79 | comment += self.table_wrapper.fill(unwrapped_comment) 80 | comment += "\n" 81 | 82 | comment += "\n" 83 | 84 | return comment 85 | -------------------------------------------------------------------------------- /scripts/modules/constants.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Constants to help parse xml files 4 | 5 | PARSER = "lxml" 6 | 7 | UTF8 = "utf-8" 8 | 9 | INDENT = 40 10 | 11 | SRC_PATH = "../src/" 12 | 13 | TPM_PATH = "tpm/" 14 | TPM_INCLUDE_PATH = SRC_PATH + TPM_PATH + "include/" 15 | 16 | TPM20_PREFIX_TPM2_ = "TPM2_" 17 | TPM20_SPEC_SECTION_COMMANDS_AND_RESPONSE = "Command and Response" 18 | 19 | # XML TAG AND ATTRIBUTE NAMES 20 | 21 | XML_NS_TABLE = "table" 22 | XML_NS_TEXT = "text" 23 | 24 | XML_NS_SEPARATOR = ":" 25 | 26 | XML_TABLE_TABLE = XML_NS_TABLE + XML_NS_SEPARATOR + "table" 27 | XML_TABLE_NAME = XML_NS_TABLE + XML_NS_SEPARATOR + "name" 28 | XML_TABLE_TABLE_ROW = XML_NS_TABLE + XML_NS_SEPARATOR + "table-row" 29 | XML_TABLE_TABLE_CELL = XML_NS_TABLE + XML_NS_SEPARATOR + "table-cell" 30 | XML_TABLE_TABLE_STYLE_NAME = XML_NS_TABLE + XML_NS_SEPARATOR + "style-name" 31 | 32 | XML_TEXT_STYLE_NAME = XML_NS_TEXT + XML_NS_SEPARATOR + "style-name" 33 | XML_TEXT_OUTLINE_LEVEL = XML_NS_TEXT + XML_NS_SEPARATOR + "outline-level" 34 | XML_TEXT_LIST = XML_NS_TEXT + XML_NS_SEPARATOR + "list" 35 | XML_TEXT_H = XML_NS_TEXT + XML_NS_SEPARATOR + "h" 36 | XML_TEXT_P = XML_NS_TEXT + XML_NS_SEPARATOR + "p" 37 | XML_TEXT_S = XML_NS_TEXT + XML_NS_SEPARATOR + "s" 38 | XML_TEXT_C = XML_NS_TEXT + XML_NS_SEPARATOR + "c" 39 | XML_TEXT_SPAN = XML_NS_TEXT + XML_NS_SEPARATOR + "span" 40 | 41 | XML_PREFIX_CODE_ = "Code_" 42 | 43 | 44 | # From the TCG Algorithm Registry 45 | S_KEY_SIZES = { 46 | "TPM_ALG_AES": [128, 256], 47 | "TPM_ALG_SM4": [128], 48 | "TPM_ALG_CAMELLIA": [128], 49 | } 50 | RSA_KEY_SIZES_BITS = [1024, 2048] 51 | ECC_CURVES = ["TPM_ECC_BN_P256", "TPM_ECC_NIST_P256", "TPM_ECC_NIST_P384"] 52 | -------------------------------------------------------------------------------- /scripts/modules/data_structures.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from modules.comment import Comment 4 | 5 | 6 | # Internal representation of a code line from the specification 7 | class TPM2_Partx_CodeLine: 8 | string = "" 9 | 10 | def __init__(self, string): 11 | self.string = "" 12 | self.string = string 13 | 14 | 15 | # Internal representation of a comment line from the specification 16 | class TPM2_Partx_CommentLine: 17 | string = "" 18 | 19 | def __init__(self, string): 20 | self.string = "" 21 | self.string = string 22 | 23 | 24 | # Internal representation of a table from the specification 25 | class TPM2_Partx_Table: 26 | name = "" 27 | short_name = "" 28 | number = 0 29 | rows = [] 30 | table_type = None 31 | handles = [] 32 | 33 | def __init__(self, name, short_name, number, rows): 34 | self.name = name 35 | self.short_name = short_name 36 | self.number = number 37 | self.rows = rows 38 | 39 | def append(self, row): 40 | self.rows.append(row) 41 | 42 | 43 | # Internal representation of a file 44 | class TPM2_Partx_File: 45 | name = "" 46 | short_name = "" 47 | folder_name = "" 48 | file_name = "" 49 | 50 | elements = [] 51 | 52 | # only used if a command 53 | table_command = None 54 | table_response = None 55 | section_name = "" 56 | 57 | def __init__(self): 58 | self.name = "" 59 | self.short_name = "" 60 | self.file_name = "" 61 | self.folder_name = "" 62 | self.elements = [] 63 | self.table_command = None 64 | self.table_response = None 65 | self.section_name = "" 66 | 67 | # Appends element to the list of elements if it is an instance of an internal data structure 68 | def append(self, element): 69 | if not (isinstance(element, TPM2_Partx_CodeLine) or isinstance(element, TPM2_Partx_CommentLine) 70 | or isinstance(element, TPM2_Partx_Table)): 71 | raise AssertionError() 72 | else: 73 | self.elements.append(element) 74 | 75 | # Converts list of elements into a string 76 | def elements_to_string(self): 77 | s = "" 78 | comment = Comment() 79 | for element in self.elements: 80 | # simple comment: 81 | if isinstance(element, TPM2_Partx_CommentLine) and element.string is not None: 82 | s += comment.wrap_comment(element.string) + "\n" 83 | # table comment: 84 | elif isinstance(element, TPM2_Partx_Table): 85 | s += comment.extract_table_pdf(element) 86 | elif isinstance(element, TPM2_Partx_CodeLine): 87 | s += element.string + '\n' 88 | return s 89 | 90 | -------------------------------------------------------------------------------- /scripts/modules/extractors/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | -------------------------------------------------------------------------------- /scripts/modules/extractors/commands_extractor.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import settings 4 | 5 | 6 | class CommandsExtractor: 7 | """ 8 | """ 9 | 10 | def __init__(self): 11 | self.functions = [] 12 | 13 | # Extracts commands from given folder 14 | # Parameters: 15 | # commands 16 | # folders 17 | # Returns: 18 | # list of functions 19 | @staticmethod 20 | def extract(commands, folders): 21 | if settings.DATA_ORIGIN_PDF_TXT: 22 | # deferred import 23 | from modules.extractors.pdf.tpm2_part3_commands_pdf import CommandsExtractorPDF 24 | 25 | commands_extractor = CommandsExtractorPDF() 26 | return commands_extractor.extract_pdf(commands, folders) 27 | 28 | else: 29 | # deferred import 30 | from modules.extractors.fodt.tpm2_part3_commands_fodt import CommandsExtractorFODT 31 | 32 | commands_extractor = CommandsExtractorFODT() 33 | return commands_extractor.extract_fodt(commands, folders) 34 | 35 | 36 | -------------------------------------------------------------------------------- /scripts/modules/extractors/fodt/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | -------------------------------------------------------------------------------- /scripts/modules/extractors/fodt/tpm2_partx_extraction_navigator_fodt.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # custom stuff: 4 | from bs4 import Tag 5 | 6 | from modules import comment, constants 7 | 8 | 9 | class ExtractionNavigator(object): 10 | """ 11 | """ 12 | 13 | def __init__(self): 14 | self.COMMAND_PATH = constants.SRC_PATH + constants.TPM_PATH + "command/" 15 | self.comments = comment.Comment() 16 | self.functions = [] 17 | 18 | # The selector function mainly serves the purpose of finding the next tag, 19 | # whose string is a part of the code module (it will be interpreted as a 20 | # comment). Hence, the selector looks for valid tags including the 21 | # 'text:list', 'text:p', and 'table:table' tags. In case the tag is of type 22 | # 'text:p', the selector additionally looks for the text-style of type 23 | # 'Text_', representing an outlined comment within the code. 24 | @staticmethod 25 | def selector(tag): 26 | """ 27 | """ 28 | 29 | if isinstance(tag, Tag): 30 | if tag.name == constants.XML_TEXT_LIST: 31 | return True 32 | elif (tag.name == constants.XML_TEXT_P 33 | and tag.has_attr(constants.XML_TEXT_STYLE_NAME) 34 | and "Text_" in tag[constants.XML_TEXT_STYLE_NAME]): 35 | return True 36 | elif tag.name == constants.XML_TABLE_TABLE: 37 | return True 38 | 39 | return False 40 | 41 | # Extracts section according to given name 42 | # Parameters: 43 | # entry 44 | # name_section 45 | # name_folder 46 | def extract_section(self, entry, name_section, name_folder): 47 | # find correct section 48 | while isinstance(entry, Tag) and entry.get_text().strip() != name_section: 49 | entry = entry.find_next(constants.XML_TEXT_H, {constants.XML_TEXT_OUTLINE_LEVEL: '1'}) 50 | 51 | # couldn't find the right section 52 | if entry is None: 53 | return 54 | 55 | print("[+] Section name: {0}".format(entry.get_text().strip())) 56 | 57 | self.extract_function(entry, name_section, name_folder) 58 | 59 | # Function not implemented 60 | def extract_function(self, main_entry, name_section, name_folder): 61 | """ 62 | interface 'extract_function' must be implemented by the child class or mixin 63 | """ 64 | raise NotImplementedError("[-] 'extract_function' not yet implemented...") 65 | 66 | # Function not implemented 67 | def next_function(self, entry): 68 | """ 69 | interface 'next_function' must be implemented by the child class or mixin 70 | """ 71 | raise NotImplementedError("[-] 'next_function' not yet implemented...") 72 | 73 | # Function not implemented 74 | def next_entry(self, entry): 75 | """ 76 | interface 'next_entry' must be implemented by the child class or mixin 77 | """ 78 | raise NotImplementedError("[-] 'next_entry' not yet implemented...") 79 | 80 | # Extracts all functions from xml file 81 | # Parameters: 82 | # xml 83 | # folders 84 | # Returns: 85 | # list of functions 86 | def extract_fodt(self, xml, folders): 87 | 88 | entry = xml.find(constants.XML_TEXT_H, {constants.XML_TEXT_OUTLINE_LEVEL: '1'}) 89 | 90 | for section in folders: 91 | self.extract_section(entry, section, folders[section]) 92 | 93 | return self.functions 94 | 95 | -------------------------------------------------------------------------------- /scripts/modules/extractors/fodt/tpm2_partx_license_extractor_fodt.py: -------------------------------------------------------------------------------- 1 | from modules.extractors.license_extractor import LicenseExtractor 2 | from modules import constants 3 | 4 | 5 | class LicenseExtractorFODT(LicenseExtractor): 6 | paragraph_nr = 1 7 | 8 | # Formats paragraph from license to look like C code comment 9 | # Parameters: 10 | # text_p 11 | # Returns: 12 | # same paragraph looking like a C code comment block 13 | def format_text_p_fodt(self, text_p): 14 | text = text_p.get_text().strip() 15 | formatted_text = "" 16 | 17 | if "Licenses and Notices" in text: 18 | formatted_text = self.EMPTY_LINE + self.BEGIN + text 19 | formatted_text += self.indented_end(formatted_text) 20 | 21 | elif text_p.has_attr(constants.XML_TEXT_STYLE_NAME) and "P10" in text_p[constants.XML_TEXT_STYLE_NAME]: 22 | formatted_text = self.EMPTY_LINE + self.BEGIN + str(self.paragraph_nr) + ". " + text 23 | formatted_text += self.indented_end(formatted_text) 24 | self.paragraph_nr += 1 25 | 26 | else: # in this case the text might be longer than a normal line 27 | while len(text) > self.LENGTH - 5: 28 | idx = text[:self.LENGTH - 5].rfind(" ") 29 | line = text[:idx] 30 | formatted_line = self.BEGIN + " " + line.strip() 31 | formatted_text += formatted_line + self.indented_end(formatted_line) 32 | text = text[idx:] 33 | 34 | formatted_line = self.BEGIN + " " + text.strip() 35 | formatted_text += formatted_line + self.indented_end(formatted_line) 36 | 37 | return formatted_text 38 | 39 | # Extracts the license from any part of the specification 40 | # Parameters: 41 | # xml_file 42 | # Returns: 43 | # string containing license, looking like a C comment block 44 | def extract_license_fodt(self, xml_file): 45 | 46 | all_text_ps = xml_file.find_all(constants.XML_TEXT_P) 47 | text_p = None 48 | 49 | for one_text_p in all_text_ps: 50 | 51 | if "Licenses and Notices" in one_text_p.get_text(): 52 | text_p = one_text_p 53 | break 54 | 55 | if not text_p: # nothing found 56 | raise AssertionError("LICENSE TEXT NOT FOUND") 57 | 58 | self.content += self.format_text_p_fodt(text_p) 59 | 60 | while True: 61 | text_p = text_p.find_next(constants.XML_TEXT_P) 62 | 63 | if "CONTENTS" in text_p.get_text(): 64 | break 65 | 66 | self.content += self.format_text_p_fodt(text_p) 67 | 68 | self.content += self.EMPTY_LINE 69 | self.content += self.BORDER_LINE 70 | 71 | return self.content 72 | # end of method - extract_license_pdf(self, file): 73 | -------------------------------------------------------------------------------- /scripts/modules/extractors/license_extractor.py: -------------------------------------------------------------------------------- 1 | import settings 2 | 3 | 4 | class LicenseExtractor: 5 | 6 | LENGTH = 112 7 | 8 | EMPTY_LINE = "/*" + LENGTH * " " + "*/\n" 9 | BORDER_LINE = "/*" + LENGTH * "*" + "*/\n" 10 | BEGIN = "/* " 11 | END = "*/\n" 12 | 13 | def __init__(self): 14 | self.content = self.BORDER_LINE 15 | self.content += self.EMPTY_LINE 16 | 17 | # Indent the ending of the line 18 | # Parameters: 19 | # line 20 | # Returns 21 | # same line with indented ending 22 | def indented_end(self, line): 23 | length = len(line) 24 | while length > self.LENGTH + 2: 25 | length -= self.LENGTH + 5 26 | 27 | return (self.LENGTH + 2 - length) * " " + self.END 28 | 29 | # Extracts license from any part of the specification in either text or xml format 30 | # Parameters: 31 | # file - file descriptor 32 | # Returns: 33 | # string containing license formatted as comment block 34 | @staticmethod 35 | def extract_license(file): 36 | if settings.DATA_ORIGIN_PDF_TXT: 37 | # deferred import 38 | from modules.extractors.pdf.tpm2_partx_license_extractor_pdf import LicenseExtractorPDF 39 | 40 | license_extractor = LicenseExtractorPDF() 41 | return license_extractor.extract_license_pdf(file) 42 | 43 | else: 44 | # deferred import 45 | from modules.extractors.fodt.tpm2_partx_license_extractor_fodt import LicenseExtractorFODT 46 | 47 | license_extractor = LicenseExtractorFODT() 48 | return license_extractor.extract_license_fodt(file) 49 | -------------------------------------------------------------------------------- /scripts/modules/extractors/pdf/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | -------------------------------------------------------------------------------- /scripts/modules/extractors/pdf/tpm2_partx_extraction_navigator_pdf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from modules import comment, constants 4 | import re 5 | 6 | 7 | class ExtractionNavigator(object): 8 | """ 9 | """ 10 | 11 | def __init__(self): 12 | self.COMMAND_PATH = constants.SRC_PATH + constants.TPM_PATH + "command/" 13 | self.comments = comment.Comment() 14 | self.functions = [] 15 | 16 | # Extracts section according to given name 17 | # Parameters: 18 | # file 19 | # name_section 20 | # name_folder 21 | def extract_section(self, file, name_section, name_folder): 22 | # find correct section 23 | name = name_section.replace("(", "\(") 24 | name = name.replace(")", "\)") 25 | result = re.search("(\d{1,2})[ ]+" + name + "\n", file) 26 | if result: 27 | section_number = result.group(1) 28 | file.seek(result.start()) 29 | line = file.readline() 30 | print("[+] Section name: {0}".format(name_section)) 31 | else: 32 | print "Section '" + name_section + "' not found" 33 | return 34 | 35 | self.extract_function(file, section_number, name_folder) 36 | 37 | # Function not implemented 38 | def extract_function(self, file, section_number, name_folder): 39 | """ 40 | interface 'extract_function' must be implemented by the child class or mixin 41 | """ 42 | raise NotImplementedError("[-] 'extract_function' not yet implemented...") 43 | 44 | # Function not implemented 45 | def next_function(self, file, section_number, sub_section_number): 46 | """ 47 | interface 'next_function' must be implemented by the child class or mixin 48 | """ 49 | raise NotImplementedError("[-] 'next_function' not yet implemented...") 50 | 51 | # Function not implemented 52 | def next_entry(self, file, entry, section): 53 | """ 54 | interface 'next_entry' must be implemented by the child class or mixin 55 | """ 56 | raise NotImplementedError("[-] 'next_entry' not yet implemented...") 57 | 58 | # Extracts all functions from pdf file 59 | # Parameters: 60 | # file 61 | # folders 62 | # Returns: 63 | # list of functions 64 | def extract_pdf(self, file, folders): 65 | for section in folders: 66 | self.extract_section(file, section, folders[section]) 67 | return self.functions 68 | -------------------------------------------------------------------------------- /scripts/modules/extractors/pdf/tpm2_partx_license_extractor_pdf.py: -------------------------------------------------------------------------------- 1 | import re 2 | from modules.extractors.license_extractor import LicenseExtractor 3 | 4 | 5 | class LicenseExtractorPDF(LicenseExtractor): 6 | 7 | # Formats line from license to look like C code comment 8 | # Parameters: 9 | # line 10 | # Returns: 11 | # same line looking like a C code comment 12 | def format_line_pdf(self, line): 13 | 14 | result = re.search("^(1|2|3)\.", line) 15 | if "Licenses and Notices" in line or result: 16 | formatted_line = self.EMPTY_LINE + self.BEGIN + line 17 | else: 18 | formatted_line = self.BEGIN + " " + line 19 | 20 | return formatted_line + self.indented_end(formatted_line) 21 | 22 | # Extracts the license from any part of the specification by finding its title, and taking the content of that page 23 | # Parameters: 24 | # txt_file 25 | # Returns: 26 | # string containing license, looking like a C comment block 27 | def extract_license_pdf(self, txt_file): 28 | 29 | txt_file.seek(0) 30 | 31 | while True: 32 | 33 | line = txt_file.readline()[:-1] 34 | if "Licenses and Notices" in line: 35 | break 36 | 37 | if txt_file.tell() == txt_file.size(): # end of file 38 | raise AssertionError("LICENSE TEXT NOT FOUND") 39 | 40 | self.content += self.format_line_pdf(line.strip()) 41 | 42 | while True: 43 | line = txt_file.readline()[:-1] 44 | 45 | if "CONTENTS" in line: 46 | break 47 | 48 | if line.strip() == "": 49 | continue 50 | 51 | if line.startswith("Page") or line.startswith("Family"): 52 | for i in range(0, 4): 53 | line = txt_file.readline()[:-1] 54 | continue 55 | 56 | self.content += self.format_line_pdf(line.strip()) 57 | 58 | self.content += self.EMPTY_LINE 59 | self.content += self.BORDER_LINE 60 | 61 | return self.content 62 | # end of method - extract_license_pdf(self, file): 63 | -------------------------------------------------------------------------------- /scripts/modules/extractors/spt_routines_extractor.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import settings 4 | 5 | 6 | class SupportRoutinesExtractor: 7 | """ 8 | """ 9 | 10 | def __init__(self): 11 | pass 12 | 13 | # Extracts source code of header files from Part 4 (Spt Routines) of the specification 14 | # Parameters: 15 | # support_file - file descriptor 16 | # Returns: 17 | # string containing header file source code 18 | @staticmethod 19 | def extract_header_files(support_file, folders): 20 | if settings.DATA_ORIGIN_PDF_TXT: 21 | # deferred import 22 | from modules.extractors.pdf.tpm2_part4_spt_routines_header_files_pdf import SptRoutinesHeaderFilesPDF 23 | 24 | spt_routines_extractor = SptRoutinesHeaderFilesPDF() 25 | return spt_routines_extractor.extract_pdf(support_file, folders) 26 | 27 | else: 28 | # deferred import 29 | from modules.extractors.fodt.tpm2_part4_spt_routines_header_files_fodt import SptRoutinesHeaderFilesFODT 30 | 31 | spt_routines_extractor = SptRoutinesHeaderFilesFODT() 32 | return spt_routines_extractor.extract_fodt(support_file, folders) 33 | 34 | # Extracts source code of the support routines from Part 4 (Spt Routines) of the specification 35 | # Parameters: 36 | # support_file - file descriptor 37 | # Returns: 38 | # string containing support routine source code 39 | @staticmethod 40 | def extract_spt_routines(support_file, folders): 41 | if settings.DATA_ORIGIN_PDF_TXT: 42 | # deferred import 43 | from modules.extractors.pdf.tpm2_part4_spt_routines_pdf import SptRoutinesPDF 44 | 45 | spt_routines_extractor = SptRoutinesPDF() 46 | return spt_routines_extractor.extract_pdf(support_file, folders) 47 | 48 | else: 49 | # deferred import 50 | from modules.extractors.fodt.tpm2_part4_spt_routines_fodt import SptRoutinesFODT 51 | 52 | spt_routines_extractor = SptRoutinesFODT() 53 | return spt_routines_extractor.extract_fodt(support_file, folders) 54 | 55 | # Extracts source code from the annex of Part 4 (Spt Routines) of the specification 56 | # Parameters: 57 | # support_file - file descriptor 58 | # Returns: 59 | # string containing source code from the annex 60 | @staticmethod 61 | def extract_annex(support_file, folders): 62 | if settings.DATA_ORIGIN_PDF_TXT: 63 | # deferred import 64 | from modules.extractors.pdf.tpm2_part4_spt_routines_annex_pdf import SptRoutinesAnnexPDF 65 | 66 | spt_routines_extractor = SptRoutinesAnnexPDF() 67 | return spt_routines_extractor.extract_pdf(support_file, folders) 68 | 69 | else: 70 | # deferred import 71 | from modules.extractors.fodt.tpm2_part4_spt_routines_annex_fodt import SptRoutinesAnnexFODT 72 | 73 | spt_routines_extractor = SptRoutinesAnnexFODT() 74 | return spt_routines_extractor.extract_fodt(support_file, folders) 75 | -------------------------------------------------------------------------------- /scripts/modules/extractors/table_extractor.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import settings 4 | 5 | 6 | # Class contains methods to extract tables from any part of the specification 7 | class TableExtractor(object): 8 | """ 9 | """ 10 | 11 | def __init__(self): 12 | pass 13 | 14 | # Extracts all the tables from Part 2 (Structures) of the specification in either text or xml format 15 | # Parameters: 16 | # structures_file - file descriptor 17 | # Returns: 18 | # list of internal representations of all tables 19 | @staticmethod 20 | def extract_structure_tables(structures_file): 21 | if settings.DATA_ORIGIN_PDF_TXT: 22 | # deferred import 23 | from modules.extractors.pdf.tpm2_partx_table_extractor_pdf import TableExtractorPDF 24 | 25 | table_extractor = TableExtractorPDF() 26 | return table_extractor.extract_structure_tables_pdf(structures_file) 27 | 28 | else: 29 | # deferred import 30 | from modules.extractors.fodt.tpm2_partx_table_extractor_fodt import TableExtractorFODT 31 | 32 | table_extractor = TableExtractorFODT() 33 | return table_extractor.extract_structure_tables_fodt(structures_file) 34 | 35 | # Extracts command table with given name from Part 3 (Commands) of the specification in either text or xml format 36 | # Parameters: 37 | # commands_file - file descriptor 38 | # Returns: 39 | # command table with given name 40 | @staticmethod 41 | def extract_commands_table_command(commands_file, command_short_name): 42 | if settings.DATA_ORIGIN_PDF_TXT: 43 | # deferred import 44 | from modules.extractors.pdf.tpm2_partx_table_extractor_pdf import TableExtractorPDF 45 | 46 | table_extractor = TableExtractorPDF() 47 | return table_extractor.extract_commands_table_command_pdf(commands_file, command_short_name) 48 | 49 | else: 50 | # deferred import 51 | from modules.extractors.fodt.tpm2_partx_table_extractor_fodt import TableExtractorFODT 52 | 53 | table_extractor = TableExtractorFODT() 54 | return table_extractor.extract_commands_table_command_fodt(commands_file, command_short_name) 55 | 56 | # Extracts response table with given name from Part 3 (Commands) of the specification in either text or xml format 57 | # Parameters: 58 | # commands_file - file descriptor 59 | # Returns: 60 | # response table with given name 61 | @staticmethod 62 | def extract_commands_table_response(commands_file, command_short_name): 63 | if settings.DATA_ORIGIN_PDF_TXT: 64 | # deferred import 65 | from modules.extractors.pdf.tpm2_partx_table_extractor_pdf import TableExtractorPDF 66 | 67 | table_extractor = TableExtractorPDF() 68 | return table_extractor.extract_commands_table_response_pdf(commands_file, command_short_name) 69 | 70 | else: 71 | # deferred import 72 | from modules.extractors.fodt.tpm2_partx_table_extractor_fodt import TableExtractorFODT 73 | 74 | table_extractor = TableExtractorFODT() 75 | return table_extractor.extract_commands_table_response_fodt(commands_file, command_short_name) 76 | 77 | # Finds out table type from its name 78 | # Parameters: 79 | # table - internal representation of table to be classified 80 | # name - name of the table 81 | # Returns: 82 | # same table, with type correctly set 83 | @staticmethod 84 | def classify_table(table, name): 85 | if name.startswith("Definition") and name.endswith("Constants"): 86 | table.table_type = "EnumTable" 87 | 88 | elif name.startswith("Definition") and name.endswith("Values"): 89 | table.table_type = "EnumTable" 90 | 91 | elif name.startswith("Definition of") and "Types" in name: 92 | table.table_type = "TypedefTable" 93 | 94 | elif name.startswith("Definition") and name.endswith("Type"): 95 | table.table_type = "InterfaceTable" 96 | 97 | elif name.startswith("Definition") and name.endswith("Structure"): 98 | table.table_type = "StructureTable" 99 | 100 | elif name.startswith("Definition") and name.endswith("Bits"): 101 | table.table_type = "BitsTable" 102 | 103 | elif name.startswith("Definition") and name.endswith("Union"): 104 | table.table_type = "UnionTable" 105 | 106 | return table 107 | -------------------------------------------------------------------------------- /scripts/modules/file_handling.py: -------------------------------------------------------------------------------- 1 | import codecs 2 | import mmap 3 | 4 | from bs4 import BeautifulSoup 5 | import os 6 | import re 7 | from modules import constants 8 | 9 | 10 | class FileHandling(object): 11 | """ 12 | """ 13 | 14 | license = "" 15 | warn_pyastyle = False 16 | 17 | def __init__(self): 18 | pass 19 | 20 | # Assigns license string to the current file 21 | # Parameters: 22 | # string - contains license string 23 | @staticmethod 24 | def set_license(string): 25 | FileHandling.license = string 26 | 27 | # Opens file with the specified filename and returns its file descriptor. 28 | # Distinguishes between .txt files (opens them and maps them into memory with the exact content) 29 | # and .fodt files (opens them with BeautifulSoup, so they can be parsed for XML tags) 30 | # Parameters: 31 | # file_name - name of the file to be opened 32 | # Returns: 33 | # fd - file descriptor of opened file 34 | def get_fd(self, file_name): 35 | fd = None 36 | if file_name.endswith(".txt"): 37 | f = codecs.open(file_name, "r", constants.UTF8) 38 | fd = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) 39 | elif file_name.endswith(".fodt"): 40 | f = open(file_name) 41 | fd = BeautifulSoup(f, constants.PARSER) 42 | return fd 43 | 44 | # Creates file at specified path, and writes the content string into it, formatted with astyle 45 | # Parameters: 46 | # file_path - path of the file to be created 47 | # content - string to be written into created file 48 | @staticmethod 49 | def write_file(file_path, content): 50 | if not os.path.exists(os.path.dirname(file_path)): 51 | os.makedirs(os.path.dirname(file_path)) 52 | f = codecs.open(file_path, "w", constants.UTF8) 53 | 54 | try: 55 | import pyastyle 56 | 57 | content = re.sub("(?![ ]*\/)[ ]{2,}", " ", content) 58 | content = pyastyle.format(content, "") 59 | except ImportError: 60 | FileHandling.warn_pyastyle = True 61 | 62 | f.write(FileHandling.license) 63 | f.write("\n") 64 | f.write(content) 65 | f.close() 66 | return 67 | -------------------------------------------------------------------------------- /scripts/modules/part2_structures/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | -------------------------------------------------------------------------------- /scripts/modules/part2_structures/marshal/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | -------------------------------------------------------------------------------- /scripts/modules/part2_structures/marshal/tpm2_partx_marshal_advanced_type.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from modules.part2_structures.marshal.tpm2_partx_marshal_simple_type import SimpleMarshaller 4 | from modules.part2_structures.marshal import tpm2_partx_marshal_templates 5 | from textwrap import dedent 6 | 7 | 8 | class AdvancedMarshaller(SimpleMarshaller): 9 | 10 | def __init__(self): 11 | SimpleMarshaller.__init__(self) 12 | 13 | # Generate unmarshal function for advanced types 14 | # Parameters: values used to substitute fields of the template 15 | # Returns: 16 | # generated source code 17 | def create_unmarshal_code(self, mrshl_type, to_type, cases_list, rc_fail="TPM_RC_VALUE"): 18 | 19 | cases = "" 20 | for case in cases_list: 21 | cases += " case " + case + " :\n" 22 | 23 | cases = cases[12:] 24 | cases = cases[:-1] 25 | cases = dedent(cases) 26 | 27 | rc_fail = rc_fail.strip() 28 | 29 | template = tpm2_partx_marshal_templates.TYPE_Unmarshal_advanced 30 | code = template.safe_substitute(TYPE=mrshl_type, TO_TYPE=to_type, CASES=cases, RC_FAIL=rc_fail) 31 | 32 | return code 33 | -------------------------------------------------------------------------------- /scripts/modules/part2_structures/marshal/tpm2_partx_marshal_array.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from modules.part2_structures.marshal.tpm2_partx_marshal_simple_type import SimpleMarshaller 4 | from modules.part2_structures.marshal import tpm2_partx_marshal_templates 5 | 6 | 7 | class ArrayMarshaller(SimpleMarshaller): 8 | 9 | def __init__(self): 10 | SimpleMarshaller.__init__(self) 11 | 12 | # Generate unmarshal function for arrays 13 | # Parameters: 14 | # function - unmarshal type 15 | # bool_flag - boolean value to decide if additional parameters are needed tor the unmarshal function 16 | # Returns: 17 | # generated source code 18 | def create_unmarshal_code(self, function, bool_flag): 19 | 20 | flag1 = "" 21 | flag2 = "" 22 | 23 | if bool_flag: 24 | flag1 = ", BOOL allowNull" 25 | flag2 = ", allowNull" 26 | 27 | if "BYTE" in function: 28 | template = tpm2_partx_marshal_templates.BYTE_Array_Unmarshal 29 | else: 30 | template = tpm2_partx_marshal_templates.TYPE_Array_Unmarshal 31 | 32 | code = template.safe_substitute(TYPE=function, FLAG1=flag1, FLAG2=flag2) 33 | 34 | return code 35 | # end of method - create_unmarshal_code(self, function, bool_flag): 36 | 37 | # Generate marshal function for arrays 38 | # Parameters: 39 | # function - marshal type 40 | # Returns: 41 | # generated source code 42 | def create_marshal_code(self, function): 43 | 44 | if "BYTE" in function: 45 | template = tpm2_partx_marshal_templates.BYTE_Array_Marshal 46 | else: 47 | template = tpm2_partx_marshal_templates.TYPE_Array_Marshal 48 | 49 | code = template.safe_substitute(TYPE=function) 50 | 51 | return code 52 | # end of method - create_marshal_code(self, function): 53 | 54 | # Generate unmarshal function prototype for arrays 55 | # Parameters: 56 | # mrshl_type - unmarshal type 57 | # bool_flag - boolean value to decide if additional parameters are needed tor the unmarshal function 58 | # Returns: 59 | # generated source code 60 | @staticmethod 61 | def create_unmarshal_fp(mrshl_type, bool_flag=False): 62 | 63 | flag = "" 64 | 65 | if bool_flag: 66 | flag = ", BOOL allowNull" 67 | 68 | template = tpm2_partx_marshal_templates.TYPE_Array_Unmarshal_fp 69 | code = template.safe_substitute(TYPE=mrshl_type, FLAG=flag) 70 | 71 | return code 72 | 73 | # Generate marshal function prototype for arrays 74 | # Parameters: 75 | # mrshl_type - marshal type 76 | # Returns: 77 | # generated source code 78 | @staticmethod 79 | def create_marshal_fp(mrshl_type): 80 | template = tpm2_partx_marshal_templates.TYPE_Array_Marshal_fp 81 | code = template.safe_substitute(TYPE=mrshl_type) 82 | 83 | return code 84 | -------------------------------------------------------------------------------- /scripts/modules/part2_structures/marshal/tpm2_partx_marshal_bits_table.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from modules.part2_structures.marshal.tpm2_partx_marshal_simple_type import SimpleMarshaller 4 | from modules.part2_structures.marshal import tpm2_partx_marshal_templates 5 | import settings 6 | 7 | 8 | class BitsTableMarshaller(SimpleMarshaller): 9 | 10 | def __init__(self): 11 | SimpleMarshaller.__init__(self) 12 | 13 | # Generate unmarshal function for Bits tables 14 | # Parameters: values used to substitute fields of the template 15 | # Returns: 16 | # generated source code 17 | def create_unmarshal_code(self, mrshl_type, to_type, reserved, rc_fail="TPM_RC_VALUE"): 18 | 19 | reserved = reserved.lower() 20 | 21 | if settings.SPEC_VERSION_INT < 138: 22 | template = tpm2_partx_marshal_templates.TYPE_Unmarshal_bits_pre138 23 | else: 24 | template = tpm2_partx_marshal_templates.TYPE_Unmarshal_bits 25 | code = template.safe_substitute(TYPE=mrshl_type, TO_TYPE=to_type, RESERVED=reserved, RC_FAIL=rc_fail) 26 | 27 | return code 28 | -------------------------------------------------------------------------------- /scripts/modules/part2_structures/marshal/tpm2_partx_marshal_interface_table.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from string import Template 4 | from textwrap import dedent 5 | 6 | from modules.part2_structures.marshal.tpm2_partx_marshal_simple_type import SimpleMarshaller 7 | from modules.part2_structures.marshal import tpm2_partx_marshal_templates as MarshalTemplates 8 | 9 | 10 | class InterfaceTableMarshaller(SimpleMarshaller): 11 | 12 | def __init__(self): 13 | SimpleMarshaller.__init__(self) 14 | 15 | # Generate unmarshal function for InterfaceTables 16 | # Parameters: 17 | # mrshl_type, to_type - values used to substitute fields of the interface unmarshalling template 18 | # cases_list - list used to generate unmarshaling cases 19 | # alg_list, checks_list - lists used to create additional checks and conditions 20 | # cond, rc_fail - values used to substitute fields of interface condition template 21 | # Returns: 22 | # generated source code 23 | def create_unmarshal_code(self, mrshl_type, to_type, cases_list, alg_list, checks_list, cond=None, rc_fail="TPM_RC_VALUE"): 24 | 25 | # CASES 26 | cases_string = "" 27 | if cases_list and isinstance(cases_list[0], (int, long)): 28 | for case in cases_list: 29 | cases_string += " case " + str(case) + ":\n" 30 | 31 | elif cases_list: 32 | for case in cases_list: 33 | if "TPM_ALG_" in case: 34 | cases_string += MarshalTemplates.ifdef_case_template.safe_substitute(CASE=case) 35 | else: 36 | cases_string += " case " + case + ":\n" 37 | 38 | # ALGs 39 | algs_string = "" 40 | if alg_list: 41 | for alg in alg_list: 42 | alg_name = alg.name 43 | algs_string += MarshalTemplates.ifdef_case_template.safe_substitute(CASE=alg_name) 44 | 45 | # algs_string = algs_string[:-1] 46 | 47 | # CHECKS 48 | checks_string = "" 49 | if checks_list: 50 | checks_string = "if(" + MarshalTemplates.target_bounds_check_template.safe_substitute( 51 | LEFT_BOUNDARY=checks_list[0][0], RIGHT_BOUNDARY=checks_list[0][1]) 52 | 53 | for check in checks_list[1:]: 54 | checks_string += "\n" + 8 * " " + "&& " \ 55 | + MarshalTemplates.target_bounds_check_template.safe_substitute( 56 | LEFT_BOUNDARY=check[0], RIGHT_BOUNDARY=check[1]) 57 | 58 | checks_string += ")\n" 59 | 60 | if rc_fail: 61 | checks_string += 12 * " " + "rc = " + rc_fail + ";\n" 62 | 63 | checks_string = checks_string[:-1] 64 | checks_string = dedent(checks_string) 65 | 66 | condition = "" 67 | if cases_list and not checks_list: 68 | if cond: 69 | condition = MarshalTemplates.interface_condition_caseif_template.safe_substitute(COND=cond, RC_FAIL=rc_fail) 70 | 71 | template = MarshalTemplates.TYPE_Unmarshal_interface 72 | elif not cases_list and checks_list: 73 | if cond: 74 | condition = MarshalTemplates.interface_condition_if_template.safe_substitute(COND=cond, RC_FAIL=rc_fail) 75 | 76 | template = MarshalTemplates.TYPE_Unmarshal_interface2 77 | else: 78 | if cond: 79 | condition = MarshalTemplates.interface_condition_caseifnot_template.safe_substitute(COND=cond, RC_FAIL=rc_fail) 80 | 81 | template = MarshalTemplates.TYPE_Unmarshal_interface 82 | 83 | flag = "" 84 | if cond: 85 | flag = ", BOOL allowNull" 86 | 87 | code = template.safe_substitute( 88 | TYPE=mrshl_type, 89 | TO_TYPE=to_type, 90 | ALGS=algs_string + cases_string, 91 | CHECKS=checks_string, 92 | CONDITION=condition, 93 | FLAG=flag, 94 | RC_FAIL=rc_fail) 95 | 96 | return code 97 | -------------------------------------------------------------------------------- /scripts/modules/part2_structures/marshal/tpm2_partx_marshal_simple_type.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from modules.part2_structures.marshal import tpm2_partx_marshal_templates 4 | 5 | 6 | class SimpleMarshaller: 7 | 8 | def __init__(self): 9 | pass 10 | 11 | # Generate unmarshal function for simple types 12 | # Parameters: values used to substitute fields of the template 13 | # Returns: 14 | # generated source code 15 | def create_unmarshal_code(self, mrshl_type, size): 16 | return_string = tpm2_partx_marshal_templates.RETURN_SUCCESS 17 | template = tpm2_partx_marshal_templates.TYPE_Unmarshal_simple 18 | code = template.safe_substitute(TYPE=mrshl_type, SIZE=size, FLAG="", 19 | CODE=tpm2_partx_marshal_templates.Base_Type_Unmarshal_code.safe_substitute(TYPE=mrshl_type, SIZE=size), 20 | RETURN=return_string) 21 | return code 22 | 23 | # Generate unmarshal function prototype for simple types 24 | # Parameters: 25 | # mrshl_type - unmarshal function type 26 | # bool_flag - boolean value to decide if additional parameters are needed tor the unmarshal function 27 | # Returns: 28 | # generated source code 29 | @staticmethod 30 | def create_unmarshal_fp(mrshl_type, bool_flag=False): 31 | 32 | flag = "" 33 | if bool_flag: 34 | flag = ", BOOL allowNull" 35 | 36 | template = tpm2_partx_marshal_templates.TYPE_Unmarshal_simple_fp 37 | code = template.safe_substitute(TYPE=mrshl_type, FLAG=flag) 38 | return code 39 | 40 | # Generate unmarshal function prototype definition for simple types 41 | # Parameters: 42 | # mrshl_type - unmarshal function type 43 | # to_type - unmarshal function type to define to 44 | # Returns: 45 | # generated source code 46 | @staticmethod 47 | def create_unmarshal_fp_define(mrshl_type, to_type): 48 | template = tpm2_partx_marshal_templates.TYPE_Unmarshal_structure_fp_define 49 | code = template.safe_substitute(TYPE=mrshl_type, TO_TYPE=to_type, VAR="(target)", FLAG="") 50 | return code 51 | 52 | # Generate marshal function for simple types 53 | # Parameters: values used to substitute fields of the templates 54 | # Returns: 55 | # generated source code 56 | @staticmethod 57 | def create_marshal_code(mrshl_type, size): 58 | template = tpm2_partx_marshal_templates.TYPE_Marshal_simple 59 | code = template.safe_substitute(TYPE=mrshl_type, SIZE=size, 60 | CODE=tpm2_partx_marshal_templates.Base_Type_Marshal_code.safe_substitute(TYPE=mrshl_type, SIZE=size)) 61 | return code 62 | 63 | # Generate marshal function prototype for simple types 64 | # Parameters: 65 | # mrshl_type - marshal function type 66 | # Returns: 67 | # generated source code 68 | @staticmethod 69 | def create_marshal_fp(mrshl_type): 70 | template = tpm2_partx_marshal_templates.TYPE_Marshal_simple_fp 71 | code = template.safe_substitute(TYPE=mrshl_type) 72 | return code 73 | 74 | # Generate marshal function prototype definition for simple types 75 | # Parameters: 76 | # mrshl_type - marshal function type 77 | # to_type - marshal function type to define to 78 | # Returns: 79 | # generated source code 80 | @staticmethod 81 | def create_marshal_fp_define(mrshl_type, to_type): 82 | template = tpm2_partx_marshal_templates.TYPE_Marshal_simple_fp_define 83 | code = template.safe_substitute(TYPE=mrshl_type, TO_TYPE=to_type, VAR="(source)") 84 | return code 85 | -------------------------------------------------------------------------------- /scripts/modules/part2_structures/marshal/tpm2_partx_type_mapping.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | dictionary = dict() -------------------------------------------------------------------------------- /scripts/modules/part2_structures/tpm2_part2_structures_alg_ids.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from modules import utils 4 | 5 | 6 | # Class for internal representation of Algorithm IDs 7 | class AlgorithmID: 8 | name = "" 9 | short_name = "" 10 | value = "" 11 | type = "" 12 | dependence = "" 13 | 14 | # Initialises object with given parameters 15 | def __init__(self, name, value, alg_type, dependence): 16 | self.name = name 17 | self.short_name = utils.extract_alg_name(name) 18 | self.value = value 19 | self.type = alg_type 20 | self.dependence = dependence 21 | 22 | 23 | # Class containing mapping from algorithm types to list of corresponding algorithm IDs 24 | class AlgorithmIDs: 25 | 26 | def __init__(self): 27 | self.tpm_alg_ids = dict() 28 | 29 | # Extract list of algorithm IDs for each algorithm type 30 | # Parameters: 31 | # table - internal representation of the table to extract algorithm IDs from 32 | def extract(self, table): 33 | 34 | # initialization 35 | self.tpm_alg_ids['!ALG'] = [] 36 | self.tpm_alg_ids['!ALG.A'] = [] 37 | self.tpm_alg_ids['!ALG.AX'] = [] 38 | self.tpm_alg_ids['!ALG.AXN'] = [] 39 | self.tpm_alg_ids['!ALG.AE'] = [] 40 | self.tpm_alg_ids['!ALG.AEH'] = [] 41 | self.tpm_alg_ids['!ALG.AM'] = [] 42 | self.tpm_alg_ids['!ALG.AE.AX'] = [] 43 | self.tpm_alg_ids['!ALG.AO'] = [] 44 | self.tpm_alg_ids['!ALG.O'] = [] 45 | self.tpm_alg_ids['!ALG.S'] = [] 46 | self.tpm_alg_ids['!ALG.SE'] = [] 47 | self.tpm_alg_ids['!ALG.H'] = [] 48 | self.tpm_alg_ids['!ALG.HM'] = [] 49 | self.tpm_alg_ids['!ALG.X'] = [] 50 | self.tpm_alg_ids['!ALG.E'] = [] 51 | # tpm_alg_ids[algorithm type] = list of algorithm IDs 52 | 53 | for row in table.rows: 54 | alg_name = row[0] 55 | value = row[1] 56 | alg_type = row[2] 57 | dependence = row[3] 58 | 59 | if "A" in alg_type: 60 | self.tpm_alg_ids['!ALG.A'].append(AlgorithmID(alg_name, value, alg_type, dependence)) 61 | 62 | if alg_type == u'S': # do not change to: "S" in alg_type 63 | self.tpm_alg_ids['!ALG.S'].append(AlgorithmID(alg_name, value, alg_type, dependence)) 64 | 65 | if "S" in alg_type and "E" in alg_type: 66 | self.tpm_alg_ids['!ALG.SE'].append(AlgorithmID(alg_name, value, alg_type, dependence)) 67 | 68 | if "O" in alg_type: 69 | self.tpm_alg_ids['!ALG.O'].append(AlgorithmID(alg_name, value, alg_type, dependence)) 70 | 71 | if alg_type == u'H': # do not change to: "H" in alg_type 72 | if alg_name != u'TPM_ALG_SHA': 73 | self.tpm_alg_ids['!ALG.H'].append(AlgorithmID(alg_name, value, alg_type, dependence)) 74 | 75 | if "H" in alg_type and "M" in alg_type: 76 | self.tpm_alg_ids['!ALG.HM'].append(AlgorithmID(alg_name, value, alg_type, dependence)) 77 | 78 | if "X" in alg_type: 79 | self.tpm_alg_ids['!ALG.X'].append(AlgorithmID(alg_name, value, alg_type, dependence)) 80 | 81 | if "E" in alg_type: 82 | self.tpm_alg_ids['!ALG.E'].append(AlgorithmID(alg_name, value, alg_type, dependence)) 83 | 84 | if "A" in alg_type and "X" in alg_type and "N" not in alg_type: 85 | self.tpm_alg_ids['!ALG.AX'].append(AlgorithmID(alg_name, value, alg_type, dependence)) 86 | # self.tpm_alg_ids['!ALG.AE.AX'].append([alg_name, value, dependence]) 87 | 88 | if "A" in alg_type and "E" in alg_type and "H" not in alg_type: 89 | self.tpm_alg_ids['!ALG.AE'].append(AlgorithmID(alg_name, value, alg_type, dependence)) 90 | # self.tpm_alg_ids['!ALG.AE.AX'].append([alg_name, value, dependence]) 91 | 92 | if "A" in alg_type and "M" in alg_type: 93 | self.tpm_alg_ids['!ALG.AM'].append(AlgorithmID(alg_name, value, alg_type, dependence)) 94 | 95 | if "A" in alg_type and "O" in alg_type: 96 | self.tpm_alg_ids['!ALG.AO'].append(AlgorithmID(alg_name, value, alg_type, dependence)) 97 | 98 | if "A" in alg_type and "X" in alg_type and "N" in alg_type: 99 | self.tpm_alg_ids['!ALG.AXN'].append(AlgorithmID(alg_name, value, alg_type, dependence)) 100 | 101 | if "A" in alg_type and "E" in alg_type and "H" in alg_type: 102 | self.tpm_alg_ids['!ALG.AEH'].append(AlgorithmID(alg_name, value, alg_type, dependence)) 103 | # end of loop - for row in table.rows: 104 | 105 | return self.tpm_alg_ids 106 | # end of method - extract(self, table): (see Table 2:9 for reference) 107 | -------------------------------------------------------------------------------- /scripts/modules/part2_structures/tpm2_part2_structures_types.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from textwrap import dedent 4 | 5 | 6 | # Class containing header and footer for "BaseTypes.h" file 7 | class BaseTypes: 8 | 9 | def __init__(self): 10 | return 11 | 12 | ''' 13 | The following code is based on Part 4 (Section 'Header Files -> BaseTypes.h') 14 | ''' 15 | BASETYPE_HEADER = dedent("""\ 16 | #ifndef _BASETYPES_H 17 | #define _BASETYPES_H 18 | 19 | #include "stdint.h" 20 | 21 | // NULL definition 22 | #ifndef NULL 23 | #define NULL (0) 24 | #endif 25 | 26 | """) 27 | 28 | ''' 29 | The following code is based on Part 4 (Section 'Header Files -> BaseTypes.h') 30 | ''' 31 | BASETYPE_FOOTER = dedent("""\ 32 | typedef struct { 33 | UINT16 size; 34 | BYTE buffer[1]; 35 | } TPM2B; 36 | 37 | #endif 38 | """) 39 | 40 | 41 | # Class containing header and footer for "TPM_Types.h" file 42 | class TpmTypes: 43 | 44 | def __init__(self): 45 | return 46 | 47 | ''' 48 | The following code is a simple #ifndef for a header file with a three necessary includes 49 | ''' 50 | TPMTYPES_HEADER = dedent("""\ 51 | #ifndef _TPM_TYPES_H_ 52 | #define _TPM_TYPES_H_ 53 | 54 | #include "BaseTypes.h" // i.a. needed for UINT32 55 | #include "Implementation.h" // i.a. needed for TPM_ALG_ID 56 | #include "Capabilities.h" // i.a. needed for MAX_CAP_CC 57 | 58 | """) 59 | 60 | ''' 61 | The following code is the corresponding #endif for the previous #ifndef 62 | ''' 63 | TPMTYPES_FOOTER = dedent("""\ 64 | #endif // _TPM_TYPES_H_ 65 | """) 66 | -------------------------------------------------------------------------------- /scripts/modules/part3_commands/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | -------------------------------------------------------------------------------- /scripts/modules/part3_commands/tpm2_part3_command_attributes_h.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from textwrap import dedent 4 | 5 | from modules import constants 6 | from modules.file_handling import FileHandling 7 | 8 | 9 | class CommandAttributesHeaderFile: 10 | """ 11 | """ 12 | 13 | # Initializes command attributes header content with according defines 14 | def __init__(self): 15 | self.file_path = constants.SRC_PATH + constants.TPM_PATH + "include/CommandAttributes.h" 16 | self.header_name = "COMMAND_ATTRIBUTES_H" 17 | 18 | ''' 19 | The following template is based on CommandAttributeData.c (see Part 4) 20 | ''' 21 | self.content = dedent("""\ 22 | typedef UINT16 _ATTR_; 23 | 24 | #define NOT_IMPLEMENTED (_ATTR_)(0) 25 | #define ENCRYPT_2 (_ATTR_)(1 << 0) 26 | #define ENCRYPT_4 (_ATTR_)(1 << 1) 27 | #define DECRYPT_2 (_ATTR_)(1 << 2) 28 | #define DECRYPT_4 (_ATTR_)(1 << 3) 29 | #define HANDLE_1_USER (_ATTR_)(1 << 4) 30 | #define HANDLE_1_ADMIN (_ATTR_)(1 << 5) 31 | #define HANDLE_1_DUP (_ATTR_)(1 << 6) 32 | #define HANDLE_2_USER (_ATTR_)(1 << 7) 33 | #define PP_COMMAND (_ATTR_)(1 << 8) 34 | #define IS_IMPLEMENTED (_ATTR_)(1 << 9) 35 | #define NO_SESSIONS (_ATTR_)(1 << 10) 36 | #define NV_COMMAND (_ATTR_)(1 << 11) 37 | #define PP_REQUIRED (_ATTR_)(1 << 12) 38 | #define R_HANDLE (_ATTR_)(1 << 13) 39 | #define ALLOW_TRIAL (_ATTR_)(1 << 14) 40 | 41 | typedef _ATTR_ COMMAND_ATTRIBUTES; // fix for Global.h 42 | """) 43 | 44 | # Write contents into header file along with define guards (ifdefs) 45 | def write(self): 46 | ifndef = "#ifndef " + self.header_name + "\n" 47 | define = "#define " + self.header_name + "\n\n" 48 | endif = "#endif // " + self.header_name + "\n" 49 | 50 | self.content = ifndef + define + self.content + endif 51 | 52 | FileHandling.write_file(self.file_path, self.content) 53 | -------------------------------------------------------------------------------- /scripts/modules/part3_commands/tpm2_part3_commands.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from modules.extractors.commands_extractor import CommandsExtractor 4 | 5 | from modules.part3_commands.tpm2_part3_commands_prototypes import CommandPrototypeFile as PrototypeFile 6 | from modules.part3_commands.tpm2_part3_commands_h import CommandsHeaderFile 7 | from modules.part3_commands.tpm2_part3_command_attributes_h import CommandAttributesHeaderFile 8 | from modules.part3_commands.tpm2_part3_handle_process import HandleProcess 9 | from modules.part3_commands.tpm2_part3_command_dispatcher import CommandDispatcher 10 | 11 | from modules import constants 12 | from modules.file_handling import FileHandling 13 | from modules.extractors.license_extractor import LicenseExtractor 14 | 15 | import settings 16 | 17 | 18 | class Commands: 19 | """ 20 | """ 21 | 22 | def __init__(self): 23 | self.command_header_file = CommandsHeaderFile() 24 | 25 | self.command_dispatcher = CommandDispatcher() 26 | 27 | if settings.ENABLE_TABLE_DRIVEN_DISPATCHER: 28 | from modules.part3_commands.tpm2_part3_command_dispatch_data import CommandDispatchData 29 | self.command_dispatch_data = CommandDispatchData() 30 | 31 | self.list_of_tables_commands = [] 32 | 33 | self.COMMAND_PATH = constants.SRC_PATH + constants.TPM_PATH + "command/" 34 | 35 | self.current_section = "" 36 | 37 | # Creates HandleProcess.c file 38 | def create_handle_process(self): 39 | print "" 40 | print "Creating HandleProcess.c" 41 | p = HandleProcess() 42 | for command in self.list_of_tables_commands: 43 | print " * " + command.name 44 | p.create_handle_process_case_pdf(command.name, command.rows) 45 | p.write() 46 | 47 | # Handles commands 48 | # Parameter: 49 | # commands 50 | def handle_commands(self, commands): 51 | 52 | for command in commands: 53 | 54 | if command.table_command is not None: 55 | self.list_of_tables_commands.append(command.table_command) 56 | 57 | ################################################################### 58 | # PROTOTYPES (START) 59 | prototype_file = PrototypeFile(command.short_name) 60 | prototype_file.extract_structures_and_modifiers(command.short_name, 61 | command.table_command, 62 | command.table_response, 63 | self.command_dispatcher) 64 | prototype_file.extract_prototype_functions(command) 65 | prototype_file.write() 66 | # PROTOTYPES (END) 67 | ################################################################### 68 | 69 | file_content = command.elements_to_string() 70 | 71 | file_path = self.COMMAND_PATH + command.folder_name + "/" + command.file_name 72 | 73 | # correct file path for EC_Ephemeral.c 74 | if "EC_Ephemeral.c" in command.file_name: 75 | file_path = self.COMMAND_PATH + "Asymmetric/" + command.file_name 76 | 77 | FileHandling.write_file(file_path, file_content) 78 | 79 | # add prototype header file to Commands.h 80 | if command.name.startswith("TPM2_"): 81 | if command.section_name != self.current_section: 82 | self.command_header_file.append("\n\n") 83 | self.command_header_file.append("// " + command.section_name + "\n") 84 | self.current_section = command.section_name 85 | self.command_header_file.append("#include \"" + command.short_name + "_fp.h\"\n") 86 | 87 | self.command_header_file.write() 88 | 89 | self.command_dispatcher.write() 90 | 91 | if settings.ENABLE_TABLE_DRIVEN_DISPATCHER: 92 | self.command_dispatch_data.write() 93 | 94 | # create HandleProcess.c 95 | if settings.SPEC_VERSION_INT < 138: 96 | self.create_handle_process() 97 | 98 | # Extracts information from commands file 99 | # Parameters: 100 | # commands_file 101 | # folders 102 | def extract(self, commands_file, folders): 103 | # extract license text 104 | license_text = LicenseExtractor.extract_license(commands_file) 105 | FileHandling.set_license(license_text) 106 | 107 | # extract CommandAttributes.h 108 | self.command_attributes_header_file = CommandAttributesHeaderFile() 109 | self.command_attributes_header_file.write() 110 | 111 | commands = CommandsExtractor.extract(commands_file, folders) 112 | self.handle_commands(commands) 113 | 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /scripts/modules/part3_commands/tpm2_part3_commands_fp.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from modules import constants 4 | from modules.file_handling import FileHandling 5 | 6 | 7 | class CommandsPrototypeFile: 8 | """ 9 | """ 10 | 11 | def __init__(self): 12 | self.file_path = constants.SRC_PATH + constants.TPM_PATH + "include/prototypes/Commands_fp.h" 13 | self.header_name = "_COMMANDS_FP_H_" 14 | 15 | self.content = u'' # the content of the file 16 | self.file = None # the output file handle 17 | 18 | # Appends string to commands prototype file contents 19 | # Parameter: 20 | # content 21 | def append(self, content): 22 | self.content += content 23 | 24 | # Writes contents into commands prototype file 25 | def write(self): 26 | ifndef = "#ifndef " + self.header_name + "\n" 27 | define = "#define " + self.header_name + "\n\n" 28 | endif = "#endif // " + self.header_name + "\n" 29 | 30 | self.content = ifndef + define + self.content + endif 31 | 32 | FileHandling.write_file(self.file_path, self.content) 33 | -------------------------------------------------------------------------------- /scripts/modules/part3_commands/tpm2_part3_commands_h.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from modules import constants 4 | from modules.file_handling import FileHandling 5 | 6 | 7 | class CommandsHeaderFile: 8 | """ 9 | """ 10 | 11 | def __init__(self): 12 | self.file_path = constants.SRC_PATH + constants.TPM_PATH + "include/Commands.h" 13 | self.header_name = "_COMMANDS_H_" 14 | 15 | self.content = u'' # the content of the file 16 | self.file = None # the output file handle 17 | 18 | # Appends string to commands header file contents 19 | # Parameter: 20 | # content 21 | def append(self, content): 22 | self.content += content 23 | 24 | # Writes contents into commands header file 25 | def write(self): 26 | ifndef = "#ifndef " + self.header_name + "\n" 27 | define = "#define " + self.header_name + "\n\n" 28 | endif = "#endif // " + self.header_name + "\n" 29 | 30 | self.content = ifndef + define + self.content + endif 31 | 32 | FileHandling.write_file(self.file_path, self.content) 33 | -------------------------------------------------------------------------------- /scripts/modules/part3_commands/tpm2_part3_commands_prototypes_templates.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from string import Template 4 | 5 | # This file contains templates used in generating command prototypes 6 | 7 | command_prototype_template = Template("""\ 8 | ${COMMAND_IFDEF} 9 | #ifndef ${NAME} 10 | #define ${NAME} 11 | 12 | // Type definition for input structure 13 | ${STRUCTURE_IN} 14 | 15 | // Type definition for output structure 16 | ${STRUCTURE_OUT} 17 | 18 | // Definition of response code modifiers 19 | ${MODIFIERS} 20 | 21 | // Declaration of function prototypes 22 | ${FUNCTIONS} 23 | 24 | #endif // ${NAME} 25 | ${COMMAND_ENDIF} 26 | """) 27 | 28 | command_ifdef = Template("""#ifdef TPM_CC_${NAME} // Command must be defined\n""") 29 | 30 | command_endif = Template("""#endif // TPM_CC_${NAME}\n""") 31 | 32 | structure_member = Template("""\t${OLD_TYPE}\t\t${NEW_TYPE};\n""") 33 | 34 | structure_in = Template("""\ 35 | typedef struct { 36 | ${MEMBERS} 37 | } ${NAME}_In;""") 38 | 39 | structure_out = Template("""\ 40 | typedef struct { 41 | ${MEMBERS} 42 | } ${NAME}_Out;""") 43 | -------------------------------------------------------------------------------- /scripts/modules/part3_commands/tpm2_part3_handle_process.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import re 4 | from modules import constants 5 | from modules.part3_commands import tpm2_part3_handle_process_templates 6 | from modules.file_handling import FileHandling 7 | from modules import utils 8 | import settings 9 | 10 | 11 | class HandleProcess: 12 | """ 13 | """ 14 | 15 | def __init__(self): 16 | self.file = None 17 | self.file_path = constants.SRC_PATH + constants.TPM_PATH + "/main/HandleProcess.c" 18 | self.code = "" 19 | 20 | if settings.SPEC_VERSION == "01.16": 21 | self.command = "TPM_CC commandCode, " # cf. TPM Library Specification, Part 4 22 | self.selector = "commandCode" 23 | self.table_driven_dispatch_ifndef = "" 24 | self.table_driven_dispatch_endif = "" 25 | else: 26 | self.command = "COMMAND_INDEX commandIndex," # cf. TPM Library Specification, Part 4 27 | self.selector = "GetCommandCode(commandIndex)" 28 | self.table_driven_dispatch_ifndef = "\n#ifndef TABLE_DRIVEN_DISPATCH //%\n" 29 | self.table_driven_dispatch_endif = "\n#endif //% TABLE_DRIVEN_DISPATCH\n" 30 | 31 | # Generates inner code for HandleProcess file, using appropriate template 32 | # Parameters: 33 | # handle 34 | # num 35 | # Returns: 36 | # generated inner code 37 | @staticmethod 38 | def create_inner_code(handle, num): 39 | inner_code = "" 40 | bool_text = "" 41 | handle_with_false_flag = ["TPMI_DH_OBJECT", 42 | "TPMI_RH_ENDORSEMENT", 43 | "TPMI_DH_PCR", 44 | "TPMI_RH_HIERARCHY", 45 | "TPMI_DH_ENTITY"] 46 | 47 | res = re.search('(\w+(_DH_|_RH_)\w+)([\+]*)', handle) 48 | 49 | # plus found? 50 | if res and res.group(3) == "+": 51 | handle = res.group(1) 52 | bool_text = ", TRUE" 53 | elif res and handle in handle_with_false_flag: # see __init__ 54 | bool_text = ", FALSE" 55 | 56 | inner_code += "\n" 57 | inner_code += tpm2_part3_handle_process_templates.handle_process_template_inner.safe_substitute( 58 | HANDLE=handle, 59 | NUM=num, 60 | NUM2=num + 1, 61 | BOOL=bool_text) 62 | 63 | return inner_code 64 | 65 | # Generates outer code for HandleProcess file, using appropriate template 66 | # Parameters: 67 | # function_name 68 | # num 69 | # inner_code 70 | # Returns: 71 | # generated outer code 72 | @staticmethod 73 | def create_outer_code(function_name, num, inner_code): 74 | func = function_name.replace("TPM2_", "") 75 | return tpm2_part3_handle_process_templates.handle_process_template_outer.safe_substitute( 76 | FUNC=func, 77 | NUM_HANDLES=num, 78 | EXTENSION=inner_code) 79 | 80 | # Creates case handing for HandleProcess file using inner and outer code generation 81 | # Parameters: 82 | # funcname 83 | # handles 84 | def create_handle_process_case(self, funcname, handles=None): 85 | num = 0 86 | inner_code = "" 87 | 88 | for handle in handles: 89 | inner_code += self.create_inner_code(handle, num) 90 | num += 1 91 | 92 | self.code += self.create_outer_code(funcname, num, inner_code) 93 | 94 | return 95 | 96 | # Creates case handing for HandleProcess file using inner and outer code generation 97 | # Parameters: 98 | # funcname 99 | # rows 100 | def create_handle_process_case_pdf(self, funcname, rows): 101 | num = 0 102 | inner_code = "" 103 | 104 | for row in rows: 105 | 106 | if utils.is_handle(row): 107 | handle = row[0] 108 | inner_code += self.create_inner_code(handle, num) 109 | num += 1 110 | 111 | self.code += self.create_outer_code(funcname, num, inner_code) 112 | 113 | return 114 | 115 | # Write contents into HandleProcess file 116 | def write(self): 117 | self.code = tpm2_part3_handle_process_templates.handle_process_template.safe_substitute( 118 | COMMAND=self.command, 119 | SELECTOR=self.selector, 120 | TABLE_DRIVEN_DISPATCH_IFNDEF=self.table_driven_dispatch_ifndef, 121 | TABLE_DRIVEN_DISPATCH_ENDIF=self.table_driven_dispatch_endif, 122 | CASES=self.code) 123 | FileHandling.write_file(self.file_path, self.code) 124 | -------------------------------------------------------------------------------- /scripts/modules/part3_commands/tpm2_part3_handle_process_templates.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from string import Template 4 | from textwrap import dedent 5 | 6 | # This file contains templates used to generate HandleProcess file 7 | 8 | ''' 9 | The following template is based on Part 4 (Section ParseHandleBuffer()) 10 | ''' 11 | handle_process_template = Template(dedent("""\ 12 | #include "Tpm.h" 13 | #include "InternalRoutines.h" 14 | #include "HandleProcess_fp.h" 15 | ${TABLE_DRIVEN_DISPATCH_IFNDEF} 16 | TPM_RC 17 | ParseHandleBuffer( 18 | ${COMMAND} // IN: Command being processed 19 | BYTE **handleBufferStart, // IN/OUT: command buffer where handles 20 | // are located. Updated as handles 21 | // are unmarshaled 22 | INT32 *bufferRemainingSize, // IN/OUT: indicates the amount of data 23 | // left in the command buffer. 24 | // Updated as handles are 25 | // unmarshaled 26 | TPM_HANDLE handles[], // OUT: Array that receives the handles 27 | UINT32 *handleCount // OUT: Receives the count of handles 28 | ) 29 | { 30 | TPM_RC result; // The result (from the function definition) 31 | 32 | switch(${SELECTOR}) { // based on Part 3 (command tables). 33 | ${CASES} 34 | default: 35 | pAssert(FALSE); 36 | break; 37 | } 38 | return TPM_RC_SUCCESS; 39 | } 40 | 41 | ${TABLE_DRIVEN_DISPATCH_ENDIF} 42 | """)) 43 | 44 | """ 45 | Template variables: FUNC, NUM_HANDLES, EXTENSION 46 | 47 | The following template is based on Part 4 (Section ParseHandleBuffer()) 48 | "#if defined" is based on Part 4, Annex A, Implementation.h 49 | """ 50 | handle_process_template_outer = Template(""" 51 | #if defined CC_${FUNC} && CC_${FUNC} == YES 52 | case TPM_CC_${FUNC}: 53 | *handleCount = ${NUM_HANDLES}; ${EXTENSION} 54 | break; 55 | #endif // CC_${FUNC} 56 | """) 57 | 58 | """ 59 | Template variables: HANDLE, BOOL, NUM 60 | 61 | The following template is based on Part 4 (Section ParseHandleBuffer()) 62 | """ 63 | handle_process_template_inner = Template("""\ 64 | result = ${HANDLE}_Unmarshal(&handles[${NUM}], handleBufferStart, bufferRemainingSize${BOOL}); 65 | if(result != TPM_RC_SUCCESS) 66 | return result + TPM_RC_H + TPM_RC_${NUM2};\ 67 | """) -------------------------------------------------------------------------------- /scripts/modules/part4_spt_routines/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | -------------------------------------------------------------------------------- /scripts/modules/part4_spt_routines/tpm2_part4_spt_routines.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from modules.extractors.spt_routines_extractor import SupportRoutinesExtractor 4 | from modules.part4_spt_routines.tpm2_part4_spt_routines_prototypes import SupportRoutinesPrototypeFile as PrototypeFile 5 | from modules.extractors.fodt.tpm2_partx_extraction_navigator_fodt import ExtractionNavigator 6 | from modules import constants 7 | from modules.file_handling import FileHandling 8 | from modules.extractors.license_extractor import LicenseExtractor 9 | import settings 10 | 11 | class SptRoutines(ExtractionNavigator): 12 | """ 13 | """ 14 | 15 | # Creates appropriate file path for given filename 16 | # Parameters: 17 | # name_folder 18 | # name - name of the file 19 | # Returns: 20 | # file path of the given file name 21 | def set_file_path(self, name_folder, name): 22 | if name_folder is None: 23 | name_folder = "subsystem/" 24 | 25 | if "CommandAttributeData.c" in name: 26 | file_path = constants.SRC_PATH + constants.TPM_PATH + "include/" + name 27 | elif "Attest_spt.c" in name: 28 | file_path = self.COMMAND_PATH + "Attestation/" + name 29 | elif "Context_spt.c" in name: 30 | file_path = self.COMMAND_PATH + "Context/" + name 31 | elif "NV_spt.c" in name: 32 | file_path = self.COMMAND_PATH + "NVStorage/" + name 33 | elif "Object_spt.c" in name: 34 | file_path = self.COMMAND_PATH + "Object/" + name 35 | elif "Policy_spt.c" in name: 36 | file_path = self.COMMAND_PATH + "EA/" + name 37 | elif "EncryptDecrypt_spt.c" in name: 38 | file_path = self.COMMAND_PATH + "Symmetric/" + name 39 | elif "HandleProcess_fp.h" in name: 40 | file_path = constants.SRC_PATH + constants.TPM_PATH + "include/prototypes/" + name 41 | elif "CommandDispatcher_fp.h" in name: 42 | file_path = constants.SRC_PATH + constants.TPM_PATH + "include/prototypes/" + name 43 | else: 44 | file_path = constants.SRC_PATH + constants.TPM_PATH + name_folder + "/" + name 45 | 46 | return file_path 47 | 48 | # Handles support routines 49 | # Parameters: 50 | # spt_routines - list of support routines 51 | def handle_support_routines(self, spt_routines): 52 | 53 | for spt_routine in spt_routines: 54 | 55 | # create the prototype file if it needs to be created 56 | if spt_routine.name.endswith(".c"): 57 | prototype_file = PrototypeFile(spt_routine.short_name) 58 | prototype_file.extract_prototype_functions(spt_routine) 59 | 60 | if settings.SPEC_VERSION_INT >= 138 and "ExecuteCommand" in spt_routine.short_name: 61 | prototype_file.file_path = prototype_file.file_path.replace("ExecuteCommand", "ExecCommand") 62 | prototype_file.write() 63 | 64 | file_content = spt_routine.elements_to_string() 65 | 66 | # Set file path 67 | file_path = self.set_file_path(spt_routine.folder_name, spt_routine.file_name) 68 | 69 | if settings.SPEC_VERSION_INT >= 138 and spt_routine.name.endswith(".h"): 70 | file_path = constants.SRC_PATH + constants.TPM_PATH + "include/" + spt_routine.file_name 71 | 72 | # Write file 73 | FileHandling.write_file(file_path, file_content) 74 | 75 | # Extracts and handles information from part 4 of the specification and generates appropriate code 76 | # Parameters: 77 | # support_file 78 | # dict_sections_spt_routines_header_files 79 | def extract(self, support_file, dict_sections_spt_routines_header_files): 80 | # extract license text 81 | license_text = LicenseExtractor.extract_license(support_file) 82 | FileHandling.set_license(license_text) 83 | 84 | spt_routines = SupportRoutinesExtractor.extract_spt_routines(support_file, dict_sections_spt_routines_header_files) 85 | self.handle_support_routines(spt_routines) 86 | 87 | return None 88 | # end of method - extract(self, xml): 89 | -------------------------------------------------------------------------------- /scripts/modules/part4_spt_routines/tpm2_part4_spt_routines_annex.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import re 3 | 4 | from modules.extractors.spt_routines_extractor import SupportRoutinesExtractor 5 | from tpm2_part4_spt_routines_prototypes import SupportRoutinesPrototypeFile as PrototypeFile 6 | from modules import constants 7 | from modules.file_handling import FileHandling 8 | from modules.extractors.license_extractor import LicenseExtractor 9 | import settings 10 | 11 | class SptRoutinesAnnex: 12 | """ 13 | """ 14 | 15 | def __init__(self): 16 | pass 17 | 18 | # Creates appropriate file path for given filename 19 | # Parameters: 20 | # name_folder 21 | # name - name of the file 22 | # Returns: 23 | # file path of the given file name 24 | def set_file_path(self, name_folder, name): 25 | if ((name.endswith(".h") and not 26 | (name.startswith("Implementation") or 27 | name.startswith("TpmTcpProtocol") or 28 | name.startswith("OsslCryptoEngine"))) 29 | or "CpriDataEcc.c" in name 30 | or "CpriHashData.c" in name): 31 | file_path = constants.SRC_PATH + constants.TPM_PATH + "../include/" + name 32 | else: 33 | file_path = constants.SRC_PATH + constants.TPM_PATH + name_folder + "/" + name 34 | return file_path 35 | 36 | # Handles functions from the annex part of part 4 of the specification 37 | # Parameters: 38 | # functions - list of functions 39 | def handle_annex(self, functions): 40 | 41 | if settings.SPEC_VERSION_INT >= 138: 42 | prototype_file_simulator = PrototypeFile("Simulator") 43 | prototype_file_simulator.file_path = constants.SRC_PATH + "simulator/include/prototypes/Simulator_fp.h" 44 | 45 | for function in functions: 46 | 47 | ################################################################### 48 | # PROTOTYPES (START): check if proto files needs to be created 49 | if "../OsslCryptoEngine" in function.folder_name and function.name.endswith(".c"): 50 | prototype_file = PrototypeFile(function.short_name) 51 | prototype_file.extract_prototype_functions(function) 52 | prototype_file.write() 53 | 54 | if settings.SPEC_VERSION_INT >= 138 and "../simulator" in function.folder_name and function.name.endswith(".c"): 55 | prototype_file_simulator.extract_prototype_functions(function) 56 | # PROTOTYPES (END) 57 | ################################################################### 58 | 59 | file_content = function.elements_to_string() 60 | 61 | if function.name.strip().endswith("()"): 62 | function.name = function.name.strip().replace("()", "_fp.h") 63 | elif function.name.strip().endswith(")"): 64 | result = re.search('\((.*)\)', function.name.strip()) 65 | if result: 66 | function.name = result.group(1) 67 | 68 | # FIX for CpriHashData.c 69 | if "CpriHashData.c" in function.name: 70 | file_content = file_content.replace("#ifdef", "#ifdef ") 71 | # 72 | 73 | file_path = self.set_file_path(function.folder_name, function.name) 74 | 75 | if settings.SPEC_VERSION_INT >= 138: 76 | if "PlatformData.h" in function.name: 77 | file_path = constants.SRC_PATH + "platform/include/" + function.name 78 | if "Platform_fp.h" in function.name: 79 | file_path = constants.SRC_PATH + "platform/include/prototypes/" + function.name 80 | 81 | if "TpmTcpProtocol.h" in function.name: 82 | file_path = constants.SRC_PATH + "simulator/include/" + function.name 83 | 84 | if "TpmToOssl" in function.name and function.name.endswith(".h"): 85 | file_path = constants.SRC_PATH + "tpm/include/ossl/" + function.name 86 | 87 | FileHandling.write_file(file_path, file_content) 88 | 89 | if settings.SPEC_VERSION_INT >= 138: 90 | prototype_file_simulator.write() 91 | 92 | # Extracts and handles information from the annex part of part 4 of the specification and generates appropriate code 93 | # Parameters: 94 | # support_file 95 | # dict_sections_spt_routines_header_files 96 | def extract(self, support_file, dict_sections_spt_routines_header_files): 97 | # extract license text 98 | license_text = LicenseExtractor.extract_license(support_file) 99 | FileHandling.set_license(license_text) 100 | 101 | spt_routines_annex = SupportRoutinesExtractor.extract_annex(support_file, dict_sections_spt_routines_header_files) 102 | self.handle_annex(spt_routines_annex) 103 | 104 | return None 105 | # end of method - extract(...): 106 | -------------------------------------------------------------------------------- /scripts/modules/part4_spt_routines/tpm2_part4_spt_routines_header_files.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from modules.extractors.spt_routines_extractor import SupportRoutinesExtractor 4 | from modules import constants 5 | from modules.file_handling import FileHandling 6 | from modules.extractors.license_extractor import LicenseExtractor 7 | import settings 8 | import re 9 | 10 | class SptRoutinesHeaderFiles(): 11 | """ 12 | """ 13 | 14 | # Handles header files from the annex part of part 4 of the specification 15 | # Parameters: 16 | # spt_routines 17 | @staticmethod 18 | def handle_support_routines_header_files(spt_routines): 19 | 20 | for function in spt_routines: 21 | file_content = function.elements_to_string() 22 | 23 | ##################################################################### 24 | # Modification based on settings 25 | if "TpmBuildSwitches.h" in function.name and not settings.ENABLE_TABLE_DRIVEN_DISPATCHER: 26 | file_content = file_content.replace("#define TABLE_DRIVEN_DISPATCH", 27 | "// #define TABLE_DRIVEN_DISPATCH") 28 | 29 | if "VendorString.h" in function.name: 30 | file_content = re.sub(r"//[ ]*#define[ ]*MANUFACTURER[ ]*\"MSFT\"", 31 | '#define MANUFACTURER "' + str(settings.MANUFACTURER) + '"', file_content) 32 | file_content = re.sub(r"//[ ]*#define[ ]*VENDOR_STRING_1[ ]*\"DPA \"", 33 | '#define VENDOR_STRING_1 "' + str(settings.VENDOR_STRING_1) + '"', file_content) 34 | file_content = re.sub(r"//[ ]*#define[ ]*FIRMWARE_V1[ ]*\(.*?\)", 35 | '#define FIRMWARE_V1 "' + str(settings.FIRMWARE_V1) + '"', file_content) 36 | ##################################################################### 37 | 38 | file_path = constants.SRC_PATH + constants.TPM_PATH + function.folder_name + "/" + function.name 39 | 40 | # correct file path: save fiels to global include folder 41 | file_names = ["bits.h", "bool.h", "swap.h", "TpmError.h"] 42 | if function.name in file_names: 43 | file_path = constants.SRC_PATH + constants.TPM_PATH + "../include/" + function.name 44 | 45 | FileHandling.write_file(file_path, file_content) 46 | 47 | # Extracts and handles header files from part 4 of the specification and generates appropriate code 48 | # Parameters: 49 | # support_file 50 | # dict_sections_spt_routines_header_files 51 | def extract(self, support_file, dict_sections_spt_routines_header_files): 52 | # extract license text 53 | license_text = LicenseExtractor.extract_license(support_file) 54 | FileHandling.set_license(license_text) 55 | 56 | spt_routines = SupportRoutinesExtractor.extract_header_files(support_file, 57 | dict_sections_spt_routines_header_files) 58 | self.handle_support_routines_header_files(spt_routines) 59 | 60 | return None 61 | # end of method - extract(self, xml): 62 | 63 | 64 | -------------------------------------------------------------------------------- /scripts/modules/part4_spt_routines/tpm2_part4_spt_routines_prototypes.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import re 4 | 5 | from modules.prototypes.tpm2_partx_prototype_file import PrototypeFile 6 | from modules.file_handling import FileHandling 7 | from modules import data_structures 8 | from modules.part3_commands.tpm2_part3_commands_fp import CommandsPrototypeFile 9 | 10 | 11 | class SupportRoutinesPrototypeFile(PrototypeFile): 12 | 13 | # Extracts prototypes from support routine file 14 | # Parameters: 15 | # function 16 | def extract_prototype_functions(self, function): 17 | add_to_proto = True 18 | commands_fp = False 19 | 20 | iterator = iter(function.elements) 21 | for element in iterator: 22 | 23 | if not isinstance(element, data_structures.TPM2_Partx_CodeLine): 24 | continue 25 | 26 | code_line = element # element is CodeLine 27 | 28 | if code_line.string.startswith("//%"): 29 | self.functions.append(code_line.string.replace("//%", "") + '\n') 30 | continue 31 | 32 | if "//%" in code_line.string: 33 | self.functions.append(code_line.string + '\n') 34 | continue 35 | 36 | # skip static functions 37 | result = re.search("^[ ]*static|[ ]+s_", code_line.string) 38 | if result and "//%" not in code_line.string: 39 | if not code_line.string.endswith(";"): 40 | add_to_proto = False 41 | continue 42 | 43 | # skip typedefs 44 | result = re.search("^[ ]*typedef", code_line.string) 45 | if result and "//%" not in code_line.string: 46 | if "struct" in code_line.string or "union" in code_line.string: 47 | while not code_line.string.startswith("}"): 48 | element = next(iterator, None) 49 | code_line = element 50 | continue 51 | 52 | # skip includes 53 | result = re.search("(#([\s]*)(include|define|pragma|error)|FAIL)", code_line.string) 54 | if result and code_line.string.endswith("\\"): 55 | while code_line.string.endswith("\\"): 56 | element = next(iterator, None) 57 | code_line = element 58 | continue 59 | if result and "//%" not in code_line.string: 60 | continue 61 | 62 | result = re.search("^(const|extern).*?(;|{|=)", code_line.string) 63 | if result: 64 | while not code_line.string.endswith(";"): 65 | element = next(iterator, None) 66 | code_line = element 67 | continue 68 | 69 | result = re.search("^HASH_(DEF|IMPORT)", code_line.string) 70 | if result: 71 | continue 72 | 73 | if "CommandCapGetCCList" in code_line.string: 74 | commands_prototype_file = CommandsPrototypeFile() 75 | commands_prototype_file.append("TPMI_YES_NO\n") # previous line (return type) was skipped, add too 76 | commands_fp = True 77 | 78 | # bugfix: also drop lines if the {} is indented the wrong way 79 | if code_line.string.strip().startswith("case") or code_line.string.strip().startswith("if") or \ 80 | code_line.string.strip().startswith("else") or code_line.string.strip().startswith("for") or \ 81 | code_line.string.strip().startswith("return"): 82 | add_to_proto = False 83 | 84 | if add_to_proto: 85 | 86 | if code_line.string.strip() == "{": 87 | 88 | add_to_proto = False 89 | self.functions.content = self.functions.content[:-1] 90 | self.functions.append(';\n\n') 91 | if commands_fp: 92 | commands_prototype_file.content = commands_prototype_file.content[:-1] 93 | commands_prototype_file.append(';\n\n') 94 | commands_prototype_file.write() 95 | commands_fp = False 96 | 97 | else: 98 | 99 | self.functions.append(code_line.string.replace("//%", "") + "\n") 100 | 101 | if commands_fp: 102 | commands_prototype_file.append(code_line.string.replace("//%", "") + "\n") 103 | 104 | elif code_line.string == "}" or code_line.string == "};": 105 | add_to_proto = True 106 | commands_fp = False 107 | 108 | 109 | # Writes support routine prototype into file at file_path 110 | def write(self): 111 | ifndef = "#ifndef " + self.header_name_sup + "\n" 112 | define = "#define " + self.header_name_sup + "\n\n" 113 | endif = "#endif // " + self.header_name_sup + "\n" 114 | 115 | file_content = ifndef + define + self.functions.content + endif 116 | 117 | FileHandling.write_file(self.file_path, file_content) 118 | -------------------------------------------------------------------------------- /scripts/modules/prototypes/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwagnr/tpm2simulator/e45324eba268723d39856111e7933c5c76238481/scripts/modules/prototypes/__init__.py -------------------------------------------------------------------------------- /scripts/modules/prototypes/tpm2_partx_prototype_component.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | class PrototypeComponent: 5 | 6 | def __init__(self): 7 | self.content = u'' 8 | 9 | # Appends string to the string of contents 10 | # Parameters: 11 | # content - string to be added 12 | def append(self, content): 13 | self.content += content -------------------------------------------------------------------------------- /scripts/modules/prototypes/tpm2_partx_prototype_file.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from modules import constants 4 | from modules.prototypes.tpm2_partx_prototype_functions import PrototypeFunctions 5 | from modules.prototypes.tpm2_partx_prototype_component import PrototypeComponent as PrototypeStructure 6 | from modules.prototypes.tpm2_partx_prototype_modifiers import PrototypeModifiers 7 | 8 | 9 | class PrototypeFile: 10 | 11 | # Initializes prototype file object 12 | def __init__(self, name): 13 | if name is None or name is "": 14 | raise AssertionError 15 | self.name = name 16 | 17 | if self.name.startswith("Cpri") or self.name.startswith("MathFunctions") or self.name.startswith("RSAKeySieve"): 18 | self.file_path = constants.SRC_PATH + "include/" + self.name + "_fp.h" 19 | else: 20 | self.file_path = constants.SRC_PATH + constants.TPM_PATH + "include/prototypes/" + self.name + "_fp.h" 21 | 22 | self.header_name = "_" + self.name + "_H_" 23 | self.header_name_sup = "_" + self.name.upper().replace(".", "_") + "_FP_H_" 24 | 25 | self.functions = PrototypeFunctions() 26 | self.structure_in = PrototypeStructure() 27 | self.structure_out = PrototypeStructure() 28 | self.modifiers = PrototypeModifiers() 29 | 30 | self.file = None # the output file handle 31 | 32 | # Function is not implemented 33 | def extract_prototype_functions(self, text_p_text): 34 | raise NotImplementedError 35 | 36 | # Function is not implemented 37 | def write(self): 38 | raise NotImplementedError 39 | -------------------------------------------------------------------------------- /scripts/modules/prototypes/tpm2_partx_prototype_functions.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from modules.prototypes.tpm2_partx_prototype_component import PrototypeComponent 4 | 5 | 6 | class PrototypeFunctions(PrototypeComponent): 7 | 8 | # Initialises object 9 | def __init__(self): 10 | PrototypeComponent.__init__(self) 11 | self.content = u'' 12 | -------------------------------------------------------------------------------- /scripts/modules/prototypes/tpm2_partx_prototype_modifiers.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from modules.prototypes.tpm2_partx_prototype_component import PrototypeComponent 4 | 5 | 6 | class PrototypeModifiers(PrototypeComponent): 7 | 8 | # Initializes object 9 | def __init__(self): 10 | PrototypeComponent.__init__(self) 11 | self.content = u'' 12 | self.modifier_number = 1 13 | self.in_handle_section = True 14 | 15 | # Adds modifier handle 16 | # Parameters: 17 | # name 18 | # new_type 19 | def add_modifier_handle(self, name, new_type): 20 | self.append("#define RC_" + name + "_" + new_type + \ 21 | "\t\t(TPM_RC_H + TPM_RC_" + str(self.modifier_number) + ")\n") 22 | self.modifier_number += 1 23 | 24 | # Adds modifier handle parameter 25 | # Parameters: 26 | # name 27 | # new_type 28 | def add_modifier_param(self, name, new_type): 29 | if self.in_handle_section: 30 | self.in_handle_section = False 31 | self.modifier_number = 1 32 | 33 | self.append("#define RC_" + name + "_" + new_type + \ 34 | "\t\t(TPM_RC_P + TPM_RC_" + str(self.modifier_number) + ")\n") 35 | self.modifier_number += 1 36 | 37 | # Changes section type 38 | def replace_section_type(self): 39 | self.content = self.content.replace("TPM_RC_H", "TPM_RC_P") -------------------------------------------------------------------------------- /scripts/settings.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | SPEC_VERSION = "01.16" 4 | SPEC_VERSION_INT = 116 5 | SPEC_PATH = "../documents/116/" 6 | 7 | PUBLISHED_SPEC_VERSIONS = ["01.16", "01.38"] 8 | 9 | DATA_ORIGIN_PDF_TXT = (SPEC_VERSION in PUBLISHED_SPEC_VERSIONS) 10 | 11 | FILE_ENDING = ".txt" 12 | if not DATA_ORIGIN_PDF_TXT: 13 | FILE_ENDING = ".fodt" 14 | 15 | TPM20_SPEC_STRUCTURES = SPEC_PATH + "TPM Rev 2.0 Part 2 - Structures " + SPEC_VERSION + FILE_ENDING 16 | TPM20_SPEC_COMMANDS = SPEC_PATH + "TPM Rev 2.0 Part 3 - Commands " + SPEC_VERSION + "-code" + FILE_ENDING 17 | TPM20_SPEC_SUPPORTING_ROUTINES = SPEC_PATH + "TPM Rev 2.0 Part 4 - Supporting Routines " + SPEC_VERSION + "-code" + FILE_ENDING 18 | 19 | # not (yet) supported 20 | ENABLE_TABLE_DRIVEN_DISPATCHER = False 21 | 22 | 23 | def update_spec(version): 24 | global SPEC_VERSION, SPEC_VERSION_INT, SPEC_PATH 25 | global DATA_ORIGIN_PDF_TXT 26 | global ENABLE_TABLE_DRIVEN_DISPATCHER 27 | global TPM20_SPEC_STRUCTURES, TPM20_SPEC_COMMANDS, TPM20_SPEC_SUPPORTING_ROUTINES 28 | 29 | SPEC_VERSION = "0" + version[0] + "." + version[1:3] 30 | SPEC_VERSION_INT = int(version) 31 | SPEC_PATH = "../documents/" + version + "/" 32 | DATA_ORIGIN_PDF_TXT = (SPEC_VERSION in PUBLISHED_SPEC_VERSIONS) 33 | 34 | # not (yet) supported 35 | # if version > 116: 36 | # ENABLE_TABLE_DRIVEN_DISPATCHER = True 37 | 38 | if DATA_ORIGIN_PDF_TXT: 39 | FILE_ENDING = ".txt" 40 | else: 41 | FILE_ENDING = ".fodt" 42 | 43 | TPM20_SPEC_STRUCTURES = SPEC_PATH + "TPM Rev 2.0 Part 2 - Structures " + SPEC_VERSION + FILE_ENDING 44 | TPM20_SPEC_COMMANDS = SPEC_PATH + "TPM Rev 2.0 Part 3 - Commands " + SPEC_VERSION + "-code" + FILE_ENDING 45 | TPM20_SPEC_SUPPORTING_ROUTINES = SPEC_PATH + "TPM Rev 2.0 Part 4 - Supporting Routines " + SPEC_VERSION + "-code" + FILE_ENDING 46 | # end of function "update_spec(version)" 47 | 48 | 49 | ########################################################## 50 | # tpm/include/Vendor_String.h 51 | # --------------------------- 52 | MANUFACTURER = "StWa" # 4 characters 53 | VENDOR_STRING_1 = "AISE" # 4 characters 54 | FIRMWARE_V1 = "(0x20160601)" # "(0xYYYYMMDD)" 55 | ########################################################## 56 | 57 | 58 | ########################################################## 59 | # Change to "True" after setting the correct values above 60 | ########################################################## 61 | SET = False 62 | ########################################################## 63 | --------------------------------------------------------------------------------